wip on getting pings to work
This commit is contained in:
@@ -85,7 +85,7 @@ class Core {
|
|||||||
|
|
||||||
log.info("initializing connection manager")
|
log.info("initializing connection manager")
|
||||||
ConnectionManager connectionManager = props.isLeaf() ?
|
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(TrustEvent.class, connectionManager)
|
||||||
eventBus.register(ConnectionEvent.class, connectionManager)
|
eventBus.register(ConnectionEvent.class, connectionManager)
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ abstract class Connection implements Closeable {
|
|||||||
writer.join()
|
writer.join()
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readLoop() {
|
protected void readLoop() {
|
||||||
try {
|
try {
|
||||||
while(running.get()) {
|
while(running.get()) {
|
||||||
read()
|
read()
|
||||||
@@ -84,7 +84,7 @@ abstract class Connection implements Closeable {
|
|||||||
|
|
||||||
protected abstract void read()
|
protected abstract void read()
|
||||||
|
|
||||||
private void writeLoop() {
|
protected void writeLoop() {
|
||||||
try {
|
try {
|
||||||
while(running.get()) {
|
while(running.get()) {
|
||||||
def message = messages.take()
|
def message = messages.take()
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.muwire.core.connection
|
package com.muwire.core.connection
|
||||||
|
|
||||||
import com.muwire.core.EventBus
|
import com.muwire.core.EventBus
|
||||||
|
import com.muwire.core.hostcache.HostCache
|
||||||
import com.muwire.core.trust.TrustEvent
|
import com.muwire.core.trust.TrustEvent
|
||||||
import com.muwire.core.trust.TrustLevel
|
import com.muwire.core.trust.TrustLevel
|
||||||
|
|
||||||
@@ -14,10 +15,13 @@ abstract class ConnectionManager {
|
|||||||
|
|
||||||
private final Timer timer
|
private final Timer timer
|
||||||
|
|
||||||
|
protected final HostCache hostCache
|
||||||
|
|
||||||
ConnectionManager() {}
|
ConnectionManager() {}
|
||||||
|
|
||||||
ConnectionManager(EventBus eventBus) {
|
ConnectionManager(EventBus eventBus, HostCache hostCache) {
|
||||||
this.eventBus = eventBus
|
this.eventBus = eventBus
|
||||||
|
this.hostCache = hostCache
|
||||||
this.timer = new Timer("connections-pinger",true)
|
this.timer = new Timer("connections-pinger",true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.muwire.core.connection
|
|||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
|
||||||
import com.muwire.core.EventBus
|
import com.muwire.core.EventBus
|
||||||
|
import com.muwire.core.hostcache.HostCache
|
||||||
|
|
||||||
import groovy.util.logging.Log
|
import groovy.util.logging.Log
|
||||||
import net.i2p.data.Destination
|
import net.i2p.data.Destination
|
||||||
@@ -14,8 +15,8 @@ class LeafConnectionManager extends ConnectionManager {
|
|||||||
|
|
||||||
final Map<Destination, UltrapeerConnection> connections = new ConcurrentHashMap()
|
final Map<Destination, UltrapeerConnection> connections = new ConcurrentHashMap()
|
||||||
|
|
||||||
public LeafConnectionManager(EventBus eventBus, int maxConnections) {
|
public LeafConnectionManager(EventBus eventBus, int maxConnections, HostCache hostCache) {
|
||||||
super(eventBus)
|
super(eventBus, hostCache)
|
||||||
this.maxConnections = maxConnections
|
this.maxConnections = maxConnections
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import java.util.Collection
|
|||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
|
||||||
import com.muwire.core.EventBus
|
import com.muwire.core.EventBus
|
||||||
|
import com.muwire.core.hostcache.HostCache
|
||||||
|
|
||||||
import groovy.util.logging.Log
|
import groovy.util.logging.Log
|
||||||
import net.i2p.data.Destination
|
import net.i2p.data.Destination
|
||||||
@@ -18,8 +19,8 @@ class UltrapeerConnectionManager extends ConnectionManager {
|
|||||||
|
|
||||||
UltrapeerConnectionManager() {}
|
UltrapeerConnectionManager() {}
|
||||||
|
|
||||||
public UltrapeerConnectionManager(EventBus eventBus, int maxPeers, int maxLeafs) {
|
public UltrapeerConnectionManager(EventBus eventBus, int maxPeers, int maxLeafs, HostCache hostCache) {
|
||||||
super(eventBus)
|
super(eventBus, hostCache)
|
||||||
this.maxPeers = maxPeers
|
this.maxPeers = maxPeers
|
||||||
this.maxLeafs = maxLeafs
|
this.maxLeafs = maxLeafs
|
||||||
}
|
}
|
||||||
@@ -64,7 +65,9 @@ class UltrapeerConnectionManager extends ConnectionManager {
|
|||||||
if (e.status != ConnectionAttemptStatus.SUCCESSFUL)
|
if (e.status != ConnectionAttemptStatus.SUCCESSFUL)
|
||||||
return
|
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
|
def map = e.leaf ? leafConnections : peerConnections
|
||||||
map.put(e.endpoint.destination, c)
|
map.put(e.endpoint.destination, c)
|
||||||
c.start()
|
c.start()
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ class CacheClient {
|
|||||||
private void respondToCrawler(I2PSession session, Destination from, def ping) {
|
private void respondToCrawler(I2PSession session, Destination from, def ping) {
|
||||||
log.info "responding to crawler 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)
|
Collections.shuffle(neighbors)
|
||||||
if (neighbors.size() > CRAWLER_RETURN)
|
if (neighbors.size() > CRAWLER_RETURN)
|
||||||
neighbors = neighbors[0..CRAWLER_RETURN - 1]
|
neighbors = neighbors[0..CRAWLER_RETURN - 1]
|
||||||
|
|||||||
Reference in New Issue
Block a user