Initialize i2p session first on startup. Prevent own destination from ending up in host cache
This commit is contained in:
@@ -38,28 +38,6 @@ class Core {
|
||||
props = new MuWireSettings(props)
|
||||
|
||||
|
||||
EventBus eventBus = new EventBus()
|
||||
|
||||
log.info("initializing trust service")
|
||||
File goodTrust = new File(home, "trust.good")
|
||||
File badTrust = new File(home, "trust.bad")
|
||||
TrustService trustService = new TrustService(goodTrust, badTrust, 5000)
|
||||
eventBus.register(TrustEvent.class, trustService)
|
||||
trustService.start()
|
||||
trustService.waitForLoad()
|
||||
|
||||
log.info("initializing host cache")
|
||||
File hostStorage = new File(home, "hosts.json")
|
||||
HostCache hostCache = new HostCache(trustService,hostStorage, 30000, props)
|
||||
eventBus.register(HostDiscoveredEvent.class, hostCache)
|
||||
eventBus.register(ConnectionEvent.class, hostCache)
|
||||
hostCache.start()
|
||||
hostCache.waitForLoad()
|
||||
|
||||
log.info("initializing connection manager")
|
||||
ConnectionManager connectionManager = props.isLeaf() ?
|
||||
new LeafConnectionManager(eventBus,3) : new UltrapeerConnectionManager(eventBus, 512, 512)
|
||||
eventBus.register(TrustEvent.class, connectionManager)
|
||||
|
||||
log.info("initializing I2P session")
|
||||
def i2pClient = new I2PClientFactory().createClient()
|
||||
@@ -72,15 +50,38 @@ class Core {
|
||||
}
|
||||
|
||||
def sysProps = System.getProperties().clone()
|
||||
sysProps["inbound.nickname"] = "MuWire"
|
||||
I2PSession i2pSession
|
||||
keyDat.withInputStream {
|
||||
sysProps["inbound.nickname"] = "MuWire"
|
||||
I2PSession i2pSession
|
||||
keyDat.withInputStream {
|
||||
i2pSession = i2pClient.createSession(it, sysProps)
|
||||
}
|
||||
|
||||
log.info("connecting i2p session")
|
||||
i2pSession.connect()
|
||||
|
||||
EventBus eventBus = new EventBus()
|
||||
|
||||
log.info("initializing trust service")
|
||||
File goodTrust = new File(home, "trust.good")
|
||||
File badTrust = new File(home, "trust.bad")
|
||||
TrustService trustService = new TrustService(goodTrust, badTrust, 5000)
|
||||
eventBus.register(TrustEvent.class, trustService)
|
||||
trustService.start()
|
||||
trustService.waitForLoad()
|
||||
|
||||
log.info("initializing host cache")
|
||||
File hostStorage = new File(home, "hosts.json")
|
||||
HostCache hostCache = new HostCache(trustService,hostStorage, 30000, props, i2pSession.getMyDestination())
|
||||
eventBus.register(HostDiscoveredEvent.class, hostCache)
|
||||
eventBus.register(ConnectionEvent.class, hostCache)
|
||||
hostCache.start()
|
||||
hostCache.waitForLoad()
|
||||
|
||||
log.info("initializing connection manager")
|
||||
ConnectionManager connectionManager = props.isLeaf() ?
|
||||
new LeafConnectionManager(eventBus,3) : new UltrapeerConnectionManager(eventBus, 512, 512)
|
||||
eventBus.register(TrustEvent.class, connectionManager)
|
||||
|
||||
log.info("initializing cache client")
|
||||
CacheClient cacheClient = new CacheClient(eventBus,hostCache, connectionManager, i2pSession, props, 10000)
|
||||
cacheClient.start()
|
||||
|
@@ -20,13 +20,16 @@ class HostCache extends Service {
|
||||
final int interval
|
||||
final Timer timer
|
||||
final MuWireSettings settings
|
||||
final Destination myself
|
||||
final Map<Destination, Host> hosts = new ConcurrentHashMap<>()
|
||||
|
||||
public HostCache(TrustService trustService, File storage, int interval, MuWireSettings settings) {
|
||||
public HostCache(TrustService trustService, File storage, int interval,
|
||||
MuWireSettings settings, Destination myself) {
|
||||
this.trustService = trustService
|
||||
this.storage = storage
|
||||
this.interval = interval
|
||||
this.settings = settings
|
||||
this.myself = myself
|
||||
this.timer = new Timer("host-persister",true)
|
||||
}
|
||||
|
||||
@@ -39,6 +42,8 @@ class HostCache extends Service {
|
||||
}
|
||||
|
||||
void onHostDiscoveredEvent(HostDiscoveredEvent e) {
|
||||
if (myself == e.destination)
|
||||
return
|
||||
if (hosts.containsKey(e.destination))
|
||||
return
|
||||
Host host = new Host(e.destination)
|
||||
@@ -93,6 +98,8 @@ class HostCache extends Service {
|
||||
private boolean allowHost(Host host) {
|
||||
if (host.isFailed())
|
||||
return false
|
||||
if (host.destination == myself)
|
||||
return false
|
||||
TrustLevel trust = trustService.getLevel(host.destination)
|
||||
switch(trust) {
|
||||
case TrustLevel.DISTRUSTED :
|
||||
|
@@ -15,6 +15,7 @@ import groovy.json.JsonOutput
|
||||
import groovy.json.JsonSlurper
|
||||
import groovy.mock.interceptor.MockFor
|
||||
import groovy.mock.interceptor.StubFor
|
||||
import net.i2p.data.Destination
|
||||
|
||||
class HostCacheTest {
|
||||
|
||||
@@ -50,7 +51,7 @@ class HostCacheTest {
|
||||
private void initMocks() {
|
||||
trust = trustMock.proxyInstance()
|
||||
settings = settingsMock.proxyInstance()
|
||||
cache = new HostCache(trust, persist, 100, settings)
|
||||
cache = new HostCache(trust, persist, 100, settings, new Destination())
|
||||
cache.start()
|
||||
Thread.sleep(150)
|
||||
}
|
||||
|
Reference in New Issue
Block a user