make connection events carry leaf status information

pull/4/head
Zlatin Balevsky 2018-07-26 18:11:08 +01:00
parent 063357120c
commit 351edcb20e
4 changed files with 17 additions and 4 deletions

View File

@ -97,7 +97,7 @@ class ConnectionAcceptor {
} catch (Exception ex) { } catch (Exception ex) {
log.log(Level.WARNING, "incoming connection failed",ex) log.log(Level.WARNING, "incoming connection failed",ex)
e.close() 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.write("OK".bytes)
e.outputStream.flush() e.outputStream.flush()
def wrapped = new Endpoint(e.destination, new InflaterInputStream(e.inputStream), new DeflaterOutputStream(e.outputStream)) 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 { } else {
log.info("rejecting connection, leaf:$leaf") log.info("rejecting connection, leaf:$leaf")
e.outputStream.write("REJECT".bytes) e.outputStream.write("REJECT".bytes)
@ -155,7 +155,7 @@ class ConnectionAcceptor {
} }
e.outputStream.flush() e.outputStream.flush()
e.close() 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))
} }
} }

View File

@ -8,6 +8,7 @@ class ConnectionEvent extends Event {
Endpoint endpoint Endpoint endpoint
boolean incoming boolean incoming
Boolean leaf // can be null if uknown
ConnectionAttemptStatus status ConnectionAttemptStatus status
} }

View File

@ -55,7 +55,7 @@ class HostCache extends Service {
} }
void onConnectionEvent(ConnectionEvent e) { void onConnectionEvent(ConnectionEvent e) {
if (e.incoming) if (e.incoming || e.leaf)
return return
Destination dest = e.endpoint.destination Destination dest = e.endpoint.destination
Host host = hosts.get(dest) Host host = hosts.get(dest)

View File

@ -113,6 +113,8 @@ class ConnectionAcceptorTest {
def event = connectionEvents[0] def event = connectionEvents[0]
assert event.endpoint.destination == destinations.dest1 assert event.endpoint.destination == destinations.dest1
assert event.status == ConnectionAttemptStatus.SUCCESSFUL assert event.status == ConnectionAttemptStatus.SUCCESSFUL
assert event.incoming == true
assert event.leaf == true
} }
@Test @Test
@ -149,6 +151,8 @@ class ConnectionAcceptorTest {
def event = connectionEvents[0] def event = connectionEvents[0]
assert event.endpoint.destination == destinations.dest1 assert event.endpoint.destination == destinations.dest1
assert event.status == ConnectionAttemptStatus.SUCCESSFUL assert event.status == ConnectionAttemptStatus.SUCCESSFUL
assert event.incoming == true
assert event.leaf == false
} }
@Test @Test
@ -183,6 +187,8 @@ class ConnectionAcceptorTest {
def event = connectionEvents[0] def event = connectionEvents[0]
assert event.endpoint.destination == destinations.dest1 assert event.endpoint.destination == destinations.dest1
assert event.status == ConnectionAttemptStatus.FAILED assert event.status == ConnectionAttemptStatus.FAILED
assert event.incoming == true
assert event.leaf == null
} }
@Test @Test
@ -217,6 +223,8 @@ class ConnectionAcceptorTest {
def event = connectionEvents[0] def event = connectionEvents[0]
assert event.endpoint.destination == destinations.dest1 assert event.endpoint.destination == destinations.dest1
assert event.status == ConnectionAttemptStatus.FAILED assert event.status == ConnectionAttemptStatus.FAILED
assert event.incoming == true
assert event.leaf == null
} }
@Test @Test
@ -257,6 +265,8 @@ class ConnectionAcceptorTest {
def event = connectionEvents[0] def event = connectionEvents[0]
assert event.endpoint.destination == destinations.dest1 assert event.endpoint.destination == destinations.dest1
assert event.status == ConnectionAttemptStatus.REJECTED assert event.status == ConnectionAttemptStatus.REJECTED
assert event.incoming == true
assert event.leaf == false
} }
@Test @Test
@ -297,6 +307,8 @@ class ConnectionAcceptorTest {
def event = connectionEvents[0] def event = connectionEvents[0]
assert event.endpoint.destination == destinations.dest1 assert event.endpoint.destination == destinations.dest1
assert event.status == ConnectionAttemptStatus.REJECTED assert event.status == ConnectionAttemptStatus.REJECTED
assert event.incoming == true
assert event.leaf == true
} }
@Test @Test