From b0b94304797ebd68df7fc675fb267930fa64fae2 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Wed, 25 Jul 2018 18:54:07 +0100 Subject: [PATCH] Change connection event to carry an endpoint --- .../core/connection/ConnectionEvent.groovy | 3 ++- .../muwire/core/hostcache/HostCache.groovy | 7 ++++--- .../core/hostcache/HostCacheTest.groovy | 19 +++++++++++-------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/connection/ConnectionEvent.groovy b/core/src/main/groovy/com/muwire/core/connection/ConnectionEvent.groovy index 8711657b..cd20d313 100644 --- a/core/src/main/groovy/com/muwire/core/connection/ConnectionEvent.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/ConnectionEvent.groovy @@ -6,7 +6,8 @@ import net.i2p.data.Destination class ConnectionEvent extends Event { - Destination destination + Endpoint endpoint + boolean incoming ConnectionAttemptStatus status } diff --git a/core/src/main/groovy/com/muwire/core/hostcache/HostCache.groovy b/core/src/main/groovy/com/muwire/core/hostcache/HostCache.groovy index 1fd9c852..f4763297 100644 --- a/core/src/main/groovy/com/muwire/core/hostcache/HostCache.groovy +++ b/core/src/main/groovy/com/muwire/core/hostcache/HostCache.groovy @@ -53,10 +53,11 @@ class HostCache extends Service { } void onConnectionEvent(ConnectionEvent e) { - Host host = hosts.get(e.destination) + Destination dest = e.endpoint.destination + Host host = hosts.get(dest) if (host == null) { - host = new Host(e.destination) - hosts.put(e.destination, host) + host = new Host(dest) + hosts.put(dest, host) } switch(e.status) { diff --git a/core/src/test/groovy/com/muwire/core/hostcache/HostCacheTest.groovy b/core/src/test/groovy/com/muwire/core/hostcache/HostCacheTest.groovy index 20c1c954..b17b5355 100644 --- a/core/src/test/groovy/com/muwire/core/hostcache/HostCacheTest.groovy +++ b/core/src/test/groovy/com/muwire/core/hostcache/HostCacheTest.groovy @@ -8,6 +8,7 @@ import com.muwire.core.Destinations import com.muwire.core.MuWireSettings import com.muwire.core.connection.ConnectionAttemptStatus import com.muwire.core.connection.ConnectionEvent +import com.muwire.core.connection.Endpoint import com.muwire.core.trust.TrustLevel import com.muwire.core.trust.TrustService @@ -143,9 +144,10 @@ class HostCacheTest { initMocks() cache.onHostDiscoveredEvent(new HostDiscoveredEvent(destination: destinations.dest1)) - cache.onConnectionEvent( new ConnectionEvent(destination: destinations.dest1, status: ConnectionAttemptStatus.FAILED)) - cache.onConnectionEvent( new ConnectionEvent(destination: destinations.dest1, status: ConnectionAttemptStatus.FAILED)) - cache.onConnectionEvent( new ConnectionEvent(destination: destinations.dest1, status: ConnectionAttemptStatus.FAILED)) + def endpoint = new Endpoint(destinations.dest1, null, null) + cache.onConnectionEvent( new ConnectionEvent(endpoint: endpoint, status: ConnectionAttemptStatus.FAILED)) + cache.onConnectionEvent( new ConnectionEvent(endpoint: endpoint, status: ConnectionAttemptStatus.FAILED)) + cache.onConnectionEvent( new ConnectionEvent(endpoint: endpoint, status: ConnectionAttemptStatus.FAILED)) assert cache.getHosts(5).size() == 0 } @@ -164,11 +166,12 @@ class HostCacheTest { initMocks() cache.onHostDiscoveredEvent(new HostDiscoveredEvent(destination: destinations.dest1)) - cache.onConnectionEvent( new ConnectionEvent(destination: destinations.dest1, status: ConnectionAttemptStatus.FAILED)) - cache.onConnectionEvent( new ConnectionEvent(destination: destinations.dest1, status: ConnectionAttemptStatus.FAILED)) - cache.onConnectionEvent( new ConnectionEvent(destination: destinations.dest1, status: ConnectionAttemptStatus.SUCCESSFUL)) - cache.onConnectionEvent( new ConnectionEvent(destination: destinations.dest1, status: ConnectionAttemptStatus.FAILED)) - cache.onConnectionEvent( new ConnectionEvent(destination: destinations.dest1, status: ConnectionAttemptStatus.FAILED)) + def endpoint = new Endpoint(destinations.dest1, null, null) + cache.onConnectionEvent( new ConnectionEvent(endpoint: endpoint, status: ConnectionAttemptStatus.FAILED)) + cache.onConnectionEvent( new ConnectionEvent(endpoint: endpoint, status: ConnectionAttemptStatus.FAILED)) + cache.onConnectionEvent( new ConnectionEvent(endpoint: endpoint, status: ConnectionAttemptStatus.FAILED)) + cache.onConnectionEvent( new ConnectionEvent(endpoint: endpoint, status: ConnectionAttemptStatus.SUCCESSFUL)) + cache.onConnectionEvent( new ConnectionEvent(endpoint: endpoint, status: ConnectionAttemptStatus.FAILED)) def rv = cache.getHosts(5) assert rv.size() == 1