mirror of https://github.com/zlatinb/muwire
make connection events carry leaf status information
parent
063357120c
commit
351edcb20e
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ class ConnectionEvent extends Event {
|
|||
|
||||
Endpoint endpoint
|
||||
boolean incoming
|
||||
Boolean leaf // can be null if uknown
|
||||
ConnectionAttemptStatus status
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue