package net.pterodactylus.sone.main import com.google.inject.* import freenet.client.* import freenet.client.async.ClientContext import freenet.client.async.USKManager import freenet.clients.http.* import freenet.node.* import freenet.pluginmanager.* import net.pterodactylus.sone.freenet.DefaultHighLevelSimpleClientCreator import net.pterodactylus.sone.freenet.HighLevelSimpleClientCreator import net.pterodactylus.sone.freenet.plugin.* import javax.inject.Provider import javax.inject.Singleton /** * Guice [Module] that supplies some objects that are in fact supplied by the Freenet node. */ class FreenetModule(private val pluginRespirator: PluginRespirator) : Module { override fun configure(binder: Binder): Unit = binder.run { bind(PluginRespiratorFacade::class.java).toProvider(Provider { FredPluginRespiratorFacade(pluginRespirator) }).`in`(Singleton::class.java) bind(PluginConnector::class.java).to(FredPluginConnector::class.java).`in`(Singleton::class.java) bind(Node::class.java).toProvider(Provider { pluginRespirator.node }) bind(HighLevelSimpleClient::class.java).toProvider(Provider { pluginRespirator.hlSimpleClient!! }) bind(ToadletContainer::class.java).toProvider(Provider { pluginRespirator.toadletContainer }) bind(PageMaker::class.java).toProvider(Provider { pluginRespirator.pageMaker }) } @Provides @Singleton fun getSessionManager() = pluginRespirator.getSessionManager("Sone")!! @Provides fun getNodeClientCore(node: Node): NodeClientCore = node.clientCore @Provides fun getHighLevelSimpleClientCreator(nodeClientCore: NodeClientCore): HighLevelSimpleClientCreator = DefaultHighLevelSimpleClientCreator(nodeClientCore) @Provides fun getClientContext(nodeClientCore: NodeClientCore): ClientContext = nodeClientCore.clientContext @Provides fun getUskManager(nodeClientCore: NodeClientCore): USKManager = nodeClientCore.uskManager }