diff --git a/core/src/main/groovy/com/muwire/core/Core.groovy b/core/src/main/groovy/com/muwire/core/Core.groovy index d9ff1bbd..f5d81e27 100644 --- a/core/src/main/groovy/com/muwire/core/Core.groovy +++ b/core/src/main/groovy/com/muwire/core/Core.groovy @@ -85,7 +85,7 @@ class Core { log.info("initializing connection manager") ConnectionManager connectionManager = props.isLeaf() ? - new LeafConnectionManager(eventBus,3) : new UltrapeerConnectionManager(eventBus, 512, 512) + new LeafConnectionManager(eventBus,3, hostCache) : new UltrapeerConnectionManager(eventBus, 512, 512, hostCache) eventBus.register(TrustEvent.class, connectionManager) eventBus.register(ConnectionEvent.class, connectionManager) diff --git a/core/src/main/groovy/com/muwire/core/connection/Connection.groovy b/core/src/main/groovy/com/muwire/core/connection/Connection.groovy index 23ea2001..6eaa649f 100644 --- a/core/src/main/groovy/com/muwire/core/connection/Connection.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/Connection.groovy @@ -69,7 +69,7 @@ abstract class Connection implements Closeable { writer.join() } - private void readLoop() { + protected void readLoop() { try { while(running.get()) { read() @@ -84,7 +84,7 @@ abstract class Connection implements Closeable { protected abstract void read() - private void writeLoop() { + protected void writeLoop() { try { while(running.get()) { def message = messages.take() diff --git a/core/src/main/groovy/com/muwire/core/connection/ConnectionManager.groovy b/core/src/main/groovy/com/muwire/core/connection/ConnectionManager.groovy index a0d9850b..c5abe973 100644 --- a/core/src/main/groovy/com/muwire/core/connection/ConnectionManager.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/ConnectionManager.groovy @@ -1,6 +1,7 @@ package com.muwire.core.connection import com.muwire.core.EventBus +import com.muwire.core.hostcache.HostCache import com.muwire.core.trust.TrustEvent import com.muwire.core.trust.TrustLevel @@ -14,10 +15,13 @@ abstract class ConnectionManager { private final Timer timer + protected final HostCache hostCache + ConnectionManager() {} - ConnectionManager(EventBus eventBus) { + ConnectionManager(EventBus eventBus, HostCache hostCache) { this.eventBus = eventBus + this.hostCache = hostCache this.timer = new Timer("connections-pinger",true) } diff --git a/core/src/main/groovy/com/muwire/core/connection/LeafConnectionManager.groovy b/core/src/main/groovy/com/muwire/core/connection/LeafConnectionManager.groovy index ad152142..4be9de32 100644 --- a/core/src/main/groovy/com/muwire/core/connection/LeafConnectionManager.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/LeafConnectionManager.groovy @@ -3,6 +3,7 @@ package com.muwire.core.connection import java.util.concurrent.ConcurrentHashMap import com.muwire.core.EventBus +import com.muwire.core.hostcache.HostCache import groovy.util.logging.Log import net.i2p.data.Destination @@ -13,9 +14,9 @@ class LeafConnectionManager extends ConnectionManager { final int maxConnections final Map connections = new ConcurrentHashMap() - - public LeafConnectionManager(EventBus eventBus, int maxConnections) { - super(eventBus) + + public LeafConnectionManager(EventBus eventBus, int maxConnections, HostCache hostCache) { + super(eventBus, hostCache) this.maxConnections = maxConnections } diff --git a/core/src/main/groovy/com/muwire/core/connection/UltrapeerConnectionManager.groovy b/core/src/main/groovy/com/muwire/core/connection/UltrapeerConnectionManager.groovy index 0065605c..2a4f5eea 100644 --- a/core/src/main/groovy/com/muwire/core/connection/UltrapeerConnectionManager.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/UltrapeerConnectionManager.groovy @@ -4,6 +4,7 @@ import java.util.Collection import java.util.concurrent.ConcurrentHashMap import com.muwire.core.EventBus +import com.muwire.core.hostcache.HostCache import groovy.util.logging.Log import net.i2p.data.Destination @@ -18,8 +19,8 @@ class UltrapeerConnectionManager extends ConnectionManager { UltrapeerConnectionManager() {} - public UltrapeerConnectionManager(EventBus eventBus, int maxPeers, int maxLeafs) { - super(eventBus) + public UltrapeerConnectionManager(EventBus eventBus, int maxPeers, int maxLeafs, HostCache hostCache) { + super(eventBus, hostCache) this.maxPeers = maxPeers this.maxLeafs = maxLeafs } @@ -64,7 +65,9 @@ class UltrapeerConnectionManager extends ConnectionManager { if (e.status != ConnectionAttemptStatus.SUCCESSFUL) return - Connection c = e.leaf ? new LeafConnection(eventBus, e.endpoint) : new PeerConnection(eventBus, e.endpoint, e.incoming) + Connection c = e.leaf ? + new LeafConnection(eventBus, e.endpoint, hostCache) : + new PeerConnection(eventBus, e.endpoint, e.incoming, hostCache) def map = e.leaf ? leafConnections : peerConnections map.put(e.endpoint.destination, c) c.start() diff --git a/core/src/main/groovy/com/muwire/core/hostcache/CacheClient.groovy b/core/src/main/groovy/com/muwire/core/hostcache/CacheClient.groovy index af6af092..ba143280 100644 --- a/core/src/main/groovy/com/muwire/core/hostcache/CacheClient.groovy +++ b/core/src/main/groovy/com/muwire/core/hostcache/CacheClient.groovy @@ -170,7 +170,7 @@ class CacheClient { private void respondToCrawler(I2PSession session, Destination from, def ping) { log.info "responding to crawler ping" - def neighbors = manager.getConnections().collect { c -> c.remoteSide.toBase64() } + def neighbors = manager.getConnections().collect { c -> c.endpoint.destination.toBase64() } Collections.shuffle(neighbors) if (neighbors.size() > CRAWLER_RETURN) neighbors = neighbors[0..CRAWLER_RETURN - 1]