diff --git a/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy b/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy new file mode 100644 index 00000000..984cf935 --- /dev/null +++ b/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy @@ -0,0 +1,64 @@ +package com.muwire.core.connection + +import java.util.concurrent.ExecutorService +import java.util.concurrent.Executors + +import com.muwire.core.EventBus +import com.muwire.core.MuWireSettings +import com.muwire.core.hostcache.HostCache + +class ConnectionAcceptor { + + final EventBus eventBus + final UltrapeerConnectionManager manager + final MuWireSettings settings + final I2PAcceptor acceptor + final HostCache hostCache + + final ExecutorService acceptorThread + final ExecutorService handshakerThreads + + ConnectionAcceptor(EventBus eventBus, UltrapeerConnectionManager manager, + MuWireSettings settings, I2PAcceptor acceptor, HostCache hostCache) { + this.eventBus = eventBus + this.manager = manager + this.settings = settings + this.acceptor = acceptor + this.hostCache = hostCache + + acceptorThread = Executors.newSingleThreadExecutor { r -> + def rv = new Thread(r) + rv.setDaemon(true) + rv.setName("acceptor") + rv + } + + handshakerThreads = Executors.newCachedThreadPool { r -> + def rv = new Thread(r) + rv.setDaemon(true) + rv.setName("acceptor-processor-${System.currentTimeMillis()}") + rv + } + } + + void start() { + acceptorThread.execute({acceptLoop()} as Runnable) + } + + void stop() { + acceptorThread.shutdownNow() + handshakerThreads.shutdownNow() + } + + private void acceptLoop() { + while(true) { + def incoming = acceptor.accept() + handshakerThreads.execute({processIncoming(incoming)} as Runnable) + } + } + + private void processIncoming(Endpoint e) { + + } + +} diff --git a/core/src/main/groovy/com/muwire/core/connection/I2PAcceptor.groovy b/core/src/main/groovy/com/muwire/core/connection/I2PAcceptor.groovy new file mode 100644 index 00000000..c3b15b7b --- /dev/null +++ b/core/src/main/groovy/com/muwire/core/connection/I2PAcceptor.groovy @@ -0,0 +1,19 @@ +package com.muwire.core.connection + +import net.i2p.client.streaming.I2PSocketManager + +class I2PAcceptor { + + final I2PSocketManager socketManager + + I2PAcceptor() {} + + I2PAcceptor(I2PSocketManager socketManager) { + this.socketManager = socketManager + } + + Endpoint accept() { + // TODO implement + null + } +}