From 351edcb20ee67a76a2a8d20eab851ee033015c5b Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Thu, 26 Jul 2018 18:11:08 +0100 Subject: [PATCH] make connection events carry leaf status information --- .../muwire/core/connection/ConnectionAcceptor.groovy | 6 +++--- .../muwire/core/connection/ConnectionEvent.groovy | 1 + .../com/muwire/core/hostcache/HostCache.groovy | 2 +- .../core/connection/ConnectionAcceptorTest.groovy | 12 ++++++++++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy b/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy index 80d720ef..4d250b90 100644 --- a/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy @@ -97,7 +97,7 @@ class ConnectionAcceptor { } catch (Exception ex) { log.log(Level.WARNING, "incoming connection failed",ex) e.close() - eventBus.publish new ConnectionEvent(endpoint: e, incoming: true, status: ConnectionAttemptStatus.FAILED) + eventBus.publish new ConnectionEvent(endpoint: e, incoming: true, leaf: null, status: ConnectionAttemptStatus.FAILED) } } @@ -140,7 +140,7 @@ class ConnectionAcceptor { e.outputStream.write("OK".bytes) e.outputStream.flush() def wrapped = new Endpoint(e.destination, new InflaterInputStream(e.inputStream), new DeflaterOutputStream(e.outputStream)) - eventBus.publish(new ConnectionEvent(endpoint: wrapped, incoming: true, status: ConnectionAttemptStatus.SUCCESSFUL)) + eventBus.publish(new ConnectionEvent(endpoint: wrapped, incoming: true, leaf: leaf, status: ConnectionAttemptStatus.SUCCESSFUL)) } else { log.info("rejecting connection, leaf:$leaf") e.outputStream.write("REJECT".bytes) @@ -155,7 +155,7 @@ class ConnectionAcceptor { } e.outputStream.flush() e.close() - eventBus.publish(new ConnectionEvent(endpoint: e, incoming: true, status: ConnectionAttemptStatus.REJECTED)) + eventBus.publish(new ConnectionEvent(endpoint: e, incoming: true, leaf: leaf, status: ConnectionAttemptStatus.REJECTED)) } } 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 cd20d313..5e1305cf 100644 --- a/core/src/main/groovy/com/muwire/core/connection/ConnectionEvent.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/ConnectionEvent.groovy @@ -8,6 +8,7 @@ class ConnectionEvent extends Event { Endpoint endpoint boolean incoming + Boolean leaf // can be null if uknown 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 27b27e97..eb79e401 100644 --- a/core/src/main/groovy/com/muwire/core/hostcache/HostCache.groovy +++ b/core/src/main/groovy/com/muwire/core/hostcache/HostCache.groovy @@ -55,7 +55,7 @@ class HostCache extends Service { } void onConnectionEvent(ConnectionEvent e) { - if (e.incoming) + if (e.incoming || e.leaf) return Destination dest = e.endpoint.destination Host host = hosts.get(dest) diff --git a/core/src/test/groovy/com/muwire/core/connection/ConnectionAcceptorTest.groovy b/core/src/test/groovy/com/muwire/core/connection/ConnectionAcceptorTest.groovy index 9cb231c3..73b1dc9d 100644 --- a/core/src/test/groovy/com/muwire/core/connection/ConnectionAcceptorTest.groovy +++ b/core/src/test/groovy/com/muwire/core/connection/ConnectionAcceptorTest.groovy @@ -113,6 +113,8 @@ class ConnectionAcceptorTest { def event = connectionEvents[0] assert event.endpoint.destination == destinations.dest1 assert event.status == ConnectionAttemptStatus.SUCCESSFUL + assert event.incoming == true + assert event.leaf == true } @Test @@ -149,6 +151,8 @@ class ConnectionAcceptorTest { def event = connectionEvents[0] assert event.endpoint.destination == destinations.dest1 assert event.status == ConnectionAttemptStatus.SUCCESSFUL + assert event.incoming == true + assert event.leaf == false } @Test @@ -183,6 +187,8 @@ class ConnectionAcceptorTest { def event = connectionEvents[0] assert event.endpoint.destination == destinations.dest1 assert event.status == ConnectionAttemptStatus.FAILED + assert event.incoming == true + assert event.leaf == null } @Test @@ -217,6 +223,8 @@ class ConnectionAcceptorTest { def event = connectionEvents[0] assert event.endpoint.destination == destinations.dest1 assert event.status == ConnectionAttemptStatus.FAILED + assert event.incoming == true + assert event.leaf == null } @Test @@ -257,6 +265,8 @@ class ConnectionAcceptorTest { def event = connectionEvents[0] assert event.endpoint.destination == destinations.dest1 assert event.status == ConnectionAttemptStatus.REJECTED + assert event.incoming == true + assert event.leaf == false } @Test @@ -297,6 +307,8 @@ class ConnectionAcceptorTest { def event = connectionEvents[0] assert event.endpoint.destination == destinations.dest1 assert event.status == ConnectionAttemptStatus.REJECTED + assert event.incoming == true + assert event.leaf == true } @Test