broker integration: add events for incoming connection status updates

e.g. for the listen() side of connections to tell when peers have
connected or disconnected.
This commit is contained in:
Jon Siwek 2015-02-09 15:48:42 -06:00
parent 0253f49a94
commit afc5767165
14 changed files with 182 additions and 90 deletions

View file

@ -0,0 +1,2 @@
Comm::incoming_connection_established, connector
Comm::incoming_connection_broken, connector

View file

@ -0,0 +1 @@
Comm::outgoing_connection_established, 127.0.0.1, 9999/tcp, listener

View file

@ -1,4 +1,4 @@
Comm::remote_connection_established, 127.0.0.1, 9999/tcp
Comm::outgoing_connection_established, 127.0.0.1, 9999/tcp
got event msg, pong, 0
got auto event msg, ping, 0
got event msg, pong, 1

View file

@ -1 +1 @@
Comm::remote_connection_established, 127.0.0.1, 9999/tcp
Comm::outgoing_connection_established, 127.0.0.1, 9999/tcp

View file

@ -1,4 +1,4 @@
Comm::remote_connection_established, 127.0.0.1, 9999/tcp
Comm::outgoing_connection_established, 127.0.0.1, 9999/tcp
got print msg, pong 0
got print msg, pong 1
got print msg, pong 2

View file

@ -81,9 +81,9 @@ event done()
terminate();
}
event Comm::remote_connection_established(peer_address: string,
peer_port: port,
peer_name: string)
event Comm::outgoing_connection_established(peer_address: string,
peer_port: port,
peer_name: string)
{
local myset: set[string] = {"a", "b", "c"};
local myvec: vector of string = {"alpha", "beta", "gamma"};

View file

@ -0,0 +1,55 @@
# @TEST_SERIALIZE: brokercomm
# @TEST_REQUIRES: grep -q ENABLE_BROKER $BUILD/CMakeCache.txt
# @TEST-EXEC: btest-bg-run recv "bro -b ../recv.bro >recv.out"
# @TEST-EXEC: btest-bg-run send "bro -b ../send.bro >send.out"
# @TEST-EXEC: btest-bg-wait 20
# @TEST-EXEC: btest-diff recv/recv.out
# @TEST-EXEC: btest-diff send/send.out
@TEST-START-FILE recv.bro
redef exit_only_after_terminate = T;
redef Comm::endpoint_name = "listener";
event bro_init()
{
Comm::enable();
Comm::listen(9999/tcp, "127.0.0.1");
}
event Comm::incoming_connection_established(peer_name: string)
{
print "Comm::incoming_connection_established", peer_name;;
}
event Comm::incoming_connection_broken(peer_name: string)
{
print "Comm::incoming_connection_broken", peer_name;;
terminate();
}
@TEST-END-FILE
@TEST-START-FILE send.bro
redef exit_only_after_terminate = T;
redef Comm::endpoint_name = "connector";
event bro_init()
{
Comm::enable();
Comm::connect("127.0.0.1", 9999/tcp, 1sec);
}
event Comm::outgoing_connection_established(peer_address: string,
peer_port: port,
peer_name: string)
{
print "Comm::outgoing_connection_established",
peer_address, peer_port, peer_name;;
terminate();
}
@TEST-END-FILE

View file

@ -55,11 +55,11 @@ event bro_init()
global event_count = 0;
event Comm::remote_connection_established(peer_address: string,
peer_port: port,
peer_name: string)
event Comm::outgoing_connection_established(peer_address: string,
peer_port: port,
peer_name: string)
{
print "Comm::remote_connection_established", peer_address, peer_port;
print "Comm::outgoing_connection_established", peer_address, peer_port;
local args = Comm::event_args(event_handler, "ping", event_count);
Comm::event("bro/event/hi", args);
++event_count;

View file

@ -77,11 +77,11 @@ event do_write()
}
}
event Comm::remote_connection_established(peer_address: string,
peer_port: port,
peer_name: string)
event Comm::outgoing_connection_established(peer_address: string,
peer_port: port,
peer_name: string)
{
print "Comm::remote_connection_established", peer_address, peer_port;
print "Comm::outgoing_connection_established", peer_address, peer_port;
event do_write();
}

View file

@ -46,11 +46,11 @@ event bro_init()
global n = 0;
event Comm::remote_connection_established(peer_address: string,
peer_port: port,
peer_name: string)
event Comm::outgoing_connection_established(peer_address: string,
peer_port: port,
peer_name: string)
{
print "Comm::remote_connection_established", peer_address, peer_port;
print "Comm::outgoing_connection_established", peer_address, peer_port;
Comm::print("bro/print/hi", fmt("ping %d", n));
++n;
}