mirror of https://github.com/zlatinb/muwire
skeleton of connection acceptor
parent
b3dd89dbe5
commit
511c68a203
|
@ -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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue