wip on getting pings to work

This commit is contained in:
Zlatin Balevsky
2018-07-27 12:13:07 +01:00
parent 8edd495430
commit 4e31f216a8
6 changed files with 19 additions and 11 deletions

View File

@@ -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)

View File

@@ -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()

View File

@@ -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)
}

View File

@@ -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<Destination, UltrapeerConnection> 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
}

View File

@@ -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()

View File

@@ -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]