mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 20:48:21 +00:00
Merge remote-tracking branch 'origin/topic/jsiwek/broker'
* origin/topic/jsiwek/broker: Fix build warnings, clarify broker requirements, update submodule. Rename comm/ directories to broker/ Rename broker-related namespaces. Improve remote logging via broker. Disable a stream's remote logging via broker if it fails. Improve some broker communication unit tests. Adapt to a broker API change. BIT-1319 #merged
This commit is contained in:
commit
057ddb22a9
118 changed files with 2160 additions and 2061 deletions
16
CHANGES
16
CHANGES
|
@ -1,4 +1,20 @@
|
|||
|
||||
2.3-526 | 2015-03-06 12:48:49 -0600
|
||||
|
||||
* Fix build warnings, clarify broker requirements, update submodule.
|
||||
(Jon Siwek)
|
||||
|
||||
* Rename comm/ directories to broker/ (Jon Siwek)
|
||||
|
||||
* Rename broker-related namespaces. (Jon Siwek)
|
||||
|
||||
* Improve remote logging via broker by only sending fields w/ &log.
|
||||
(Jon Siwek)
|
||||
|
||||
* Disable a stream's remote logging via broker if it fails. (Jon Siwek)
|
||||
|
||||
* Improve some broker communication unit tests. (Jon Siwek)
|
||||
|
||||
2.3-518 | 2015-03-04 13:13:50 -0800
|
||||
|
||||
* Add bytes_recvd to stats.log recording the number of bytes
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
2.3-518
|
||||
2.3-526
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 8cc208192b4b692a082e22c8dd89c44f69e824d7
|
||||
Subproject commit 694af9d9edd188a461cc762bfdb7b61688b93ada
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
.. _comm-framework:
|
||||
.. _brokercomm-framework:
|
||||
|
||||
======================================
|
||||
Broker-Enabled Communication Framework
|
||||
|
@ -11,8 +11,8 @@ Broker-Enabled Communication Framework
|
|||
<../components/broker/README.html>`_ to exchange information with
|
||||
other Bro processes. To enable it run Bro's ``configure`` script
|
||||
with the ``--enable-broker`` option. Note that a C++11 compatible
|
||||
compiler is required as well as the `C++ Actor Framework
|
||||
<http://actor-framework.org/>`_.
|
||||
compiler (e.g. GCC 4.8+ or Clang 3.3+) is required as well as the
|
||||
`C++ Actor Framework <http://actor-framework.org/>`_.
|
||||
|
||||
.. contents::
|
||||
|
||||
|
@ -20,37 +20,37 @@ Connecting to Peers
|
|||
===================
|
||||
|
||||
Communication via Broker must first be turned on via
|
||||
:bro:see:`Comm::enable`.
|
||||
:bro:see:`BrokerComm::enable`.
|
||||
|
||||
Bro can accept incoming connections by calling :bro:see:`Comm::listen`
|
||||
Bro can accept incoming connections by calling :bro:see:`BrokerComm::listen`
|
||||
and then monitor connection status updates via
|
||||
:bro:see:`Comm::incoming_connection_established` and
|
||||
:bro:see:`Comm::incoming_connection_broken`.
|
||||
:bro:see:`BrokerComm::incoming_connection_established` and
|
||||
:bro:see:`BrokerComm::incoming_connection_broken`.
|
||||
|
||||
.. btest-include:: ${DOC_ROOT}/frameworks/comm/connecting-listener.bro
|
||||
.. btest-include:: ${DOC_ROOT}/frameworks/broker/connecting-listener.bro
|
||||
|
||||
Bro can initiate outgoing connections by calling :bro:see:`Comm::connect`
|
||||
Bro can initiate outgoing connections by calling :bro:see:`BrokerComm::connect`
|
||||
and then monitor connection status updates via
|
||||
:bro:see:`Comm::outgoing_connection_established`,
|
||||
:bro:see:`Comm::outgoing_connection_broken`, and
|
||||
:bro:see:`Comm::outgoing_connection_incompatible`.
|
||||
:bro:see:`BrokerComm::outgoing_connection_established`,
|
||||
:bro:see:`BrokerComm::outgoing_connection_broken`, and
|
||||
:bro:see:`BrokerComm::outgoing_connection_incompatible`.
|
||||
|
||||
.. btest-include:: ${DOC_ROOT}/frameworks/comm/connecting-connector.bro
|
||||
.. btest-include:: ${DOC_ROOT}/frameworks/broker/connecting-connector.bro
|
||||
|
||||
Remote Printing
|
||||
===============
|
||||
|
||||
To receive remote print messages, first use
|
||||
:bro:see:`Comm::subscribe_to_prints` to advertise to peers a topic
|
||||
:bro:see:`BrokerComm::subscribe_to_prints` to advertise to peers a topic
|
||||
prefix of interest and then create an event handler for
|
||||
:bro:see:`Comm::print_handler` to handle any print messages that are
|
||||
:bro:see:`BrokerComm::print_handler` to handle any print messages that are
|
||||
received.
|
||||
|
||||
.. btest-include:: ${DOC_ROOT}/frameworks/comm/printing-listener.bro
|
||||
.. btest-include:: ${DOC_ROOT}/frameworks/broker/printing-listener.bro
|
||||
|
||||
To send remote print messages, just call :bro:see:`Comm::print`.
|
||||
To send remote print messages, just call :bro:see:`BrokerComm::print`.
|
||||
|
||||
.. btest-include:: ${DOC_ROOT}/frameworks/comm/printing-connector.bro
|
||||
.. btest-include:: ${DOC_ROOT}/frameworks/broker/printing-connector.bro
|
||||
|
||||
Notice that the subscriber only used the prefix "bro/print/", but is
|
||||
able to receive messages with full topics of "bro/print/hi",
|
||||
|
@ -72,18 +72,18 @@ Remote Events
|
|||
=============
|
||||
|
||||
Receiving remote events is similar to remote prints. Just use
|
||||
:bro:see:`Comm::subscribe_to_events` and possibly define any new events
|
||||
:bro:see:`BrokerComm::subscribe_to_events` and possibly define any new events
|
||||
along with handlers that peers may want to send.
|
||||
|
||||
.. btest-include:: ${DOC_ROOT}/frameworks/comm/events-listener.bro
|
||||
.. btest-include:: ${DOC_ROOT}/frameworks/broker/events-listener.bro
|
||||
|
||||
To send events, there are two choices. The first is to use call
|
||||
:bro:see:`Comm::event` directly. The second option is to use
|
||||
:bro:see:`Comm::auto_event` to make it so a particular event is
|
||||
:bro:see:`BrokerComm::event` directly. The second option is to use
|
||||
:bro:see:`BrokerComm::auto_event` to make it so a particular event is
|
||||
automatically sent to peers whenever it is called locally via the normal
|
||||
event invocation syntax.
|
||||
|
||||
.. btest-include:: ${DOC_ROOT}/frameworks/comm/events-connector.bro
|
||||
.. btest-include:: ${DOC_ROOT}/frameworks/broker/events-connector.bro
|
||||
|
||||
Again, the subscription model is prefix-based.
|
||||
|
||||
|
@ -105,20 +105,20 @@ parameter of the message.
|
|||
Remote Logging
|
||||
==============
|
||||
|
||||
.. btest-include:: ${DOC_ROOT}/frameworks/comm/testlog.bro
|
||||
.. btest-include:: ${DOC_ROOT}/frameworks/broker/testlog.bro
|
||||
|
||||
Use :bro:see:`Comm::subscribe_to_logs` to advertise interest in logs
|
||||
Use :bro:see:`BrokerComm::subscribe_to_logs` to advertise interest in logs
|
||||
written by peers. The topic names that Bro uses are implicitly of the
|
||||
form "bro/log/<stream-name>".
|
||||
|
||||
.. btest-include:: ${DOC_ROOT}/frameworks/comm/logs-listener.bro
|
||||
.. btest-include:: ${DOC_ROOT}/frameworks/broker/logs-listener.bro
|
||||
|
||||
To send remote logs either use :bro:see:`Log::enable_remote_logging` or
|
||||
:bro:see:`Comm::enable_remote_logs`. The former allows any log stream
|
||||
:bro:see:`BrokerComm::enable_remote_logs`. The former allows any log stream
|
||||
to be sent to peers while the later toggles remote logging for
|
||||
particular streams.
|
||||
|
||||
.. btest-include:: ${DOC_ROOT}/frameworks/comm/logs-connector.bro
|
||||
.. btest-include:: ${DOC_ROOT}/frameworks/broker/logs-connector.bro
|
||||
|
||||
Message Format
|
||||
--------------
|
||||
|
@ -140,23 +140,23 @@ Tuning Access Control
|
|||
By default, endpoints do not restrict the message topics that it sends
|
||||
to peers and do not restrict what message topics and data store
|
||||
identifiers get advertised to peers. These are the default
|
||||
:bro:see:`Comm::EndpointFlags` supplied to :bro:see:`Comm::enable`.
|
||||
:bro:see:`BrokerComm::EndpointFlags` supplied to :bro:see:`BrokerComm::enable`.
|
||||
|
||||
If not using the ``auto_publish`` flag, one can use the
|
||||
:bro:see:`Comm::publish_topic` and :bro:see:`Comm::unpublish_topic`
|
||||
:bro:see:`BrokerComm::publish_topic` and :bro:see:`BrokerComm::unpublish_topic`
|
||||
functions to manipulate the set of message topics (must match exactly)
|
||||
that are allowed to be sent to peer endpoints. These settings take
|
||||
precedence over the per-message ``peers`` flag supplied to functions
|
||||
that take a :bro:see:`Comm::SendFlags` such as :bro:see:`Comm::print`,
|
||||
:bro:see:`Comm::event`, :bro:see:`Comm::auto_event` or
|
||||
:bro:see:`Comm::enable_remote_logs`.
|
||||
that take a :bro:see:`BrokerComm::SendFlags` such as :bro:see:`BrokerComm::print`,
|
||||
:bro:see:`BrokerComm::event`, :bro:see:`BrokerComm::auto_event` or
|
||||
:bro:see:`BrokerComm::enable_remote_logs`.
|
||||
|
||||
If not using the ``auto_advertise`` flag, one can use the
|
||||
:bro:see:`Comm::advertise_topic` and :bro:see:`Comm::unadvertise_topic`
|
||||
:bro:see:`BrokerComm::advertise_topic` and :bro:see:`BrokerComm::unadvertise_topic`
|
||||
to manupulate the set of topic prefixes that are allowed to be
|
||||
advertised to peers. If an endpoint does not advertise a topic prefix,
|
||||
the only way a peers can send messages to it is via the ``unsolicited``
|
||||
flag of :bro:see:`Comm::SendFlags` and choosing a topic with a matching
|
||||
flag of :bro:see:`BrokerComm::SendFlags` and choosing a topic with a matching
|
||||
prefix (i.e. full topic may be longer than receivers prefix, just the
|
||||
prefix needs to match).
|
||||
|
||||
|
@ -189,13 +189,13 @@ Data stores also support expiration on a per-key basis either using an
|
|||
absolute point in time or a relative amount of time since the entry's
|
||||
last modification time.
|
||||
|
||||
.. btest-include:: ${DOC_ROOT}/frameworks/comm/stores-listener.bro
|
||||
.. btest-include:: ${DOC_ROOT}/frameworks/broker/stores-listener.bro
|
||||
|
||||
.. btest-include:: ${DOC_ROOT}/frameworks/comm/stores-connector.bro
|
||||
.. btest-include:: ${DOC_ROOT}/frameworks/broker/stores-connector.bro
|
||||
|
||||
In the above example, if a local copy of the store contents isn't
|
||||
needed, just replace the :bro:see:`Store::create_clone` call with
|
||||
:bro:see:`Store::create_frontend`. Queries will then be made against
|
||||
needed, just replace the :bro:see:`BrokerStore::create_clone` call with
|
||||
:bro:see:`BrokerStore::create_frontend`. Queries will then be made against
|
||||
the remote master store instead of the local clone.
|
||||
|
||||
Note that all queries are made within Bro's asynchrounous ``when``
|
|
@ -1,19 +1,19 @@
|
|||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef Comm::endpoint_name = "connector";
|
||||
redef BrokerComm::endpoint_name = "connector";
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::connect("127.0.0.1", broker_port, 1sec);
|
||||
BrokerComm::enable();
|
||||
BrokerComm::connect("127.0.0.1", broker_port, 1sec);
|
||||
}
|
||||
|
||||
event Comm::outgoing_connection_established(peer_address: string,
|
||||
event BrokerComm::outgoing_connection_established(peer_address: string,
|
||||
peer_port: port,
|
||||
peer_name: string)
|
||||
{
|
||||
print "Comm::outgoing_connection_established",
|
||||
print "BrokerComm::outgoing_connection_established",
|
||||
peer_address, peer_port, peer_name;
|
||||
terminate();
|
||||
}
|
21
doc/frameworks/broker/connecting-listener.bro
Normal file
21
doc/frameworks/broker/connecting-listener.bro
Normal file
|
@ -0,0 +1,21 @@
|
|||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef BrokerComm::endpoint_name = "listener";
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
BrokerComm::enable();
|
||||
BrokerComm::listen(broker_port, "127.0.0.1");
|
||||
}
|
||||
|
||||
event BrokerComm::incoming_connection_established(peer_name: string)
|
||||
{
|
||||
print "BrokerComm::incoming_connection_established", peer_name;
|
||||
}
|
||||
|
||||
event BrokerComm::incoming_connection_broken(peer_name: string)
|
||||
{
|
||||
print "BrokerComm::incoming_connection_broken", peer_name;
|
||||
terminate();
|
||||
}
|
31
doc/frameworks/broker/events-connector.bro
Normal file
31
doc/frameworks/broker/events-connector.bro
Normal file
|
@ -0,0 +1,31 @@
|
|||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef BrokerComm::endpoint_name = "connector";
|
||||
global my_event: event(msg: string, c: count);
|
||||
global my_auto_event: event(msg: string, c: count);
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
BrokerComm::enable();
|
||||
BrokerComm::connect("127.0.0.1", broker_port, 1sec);
|
||||
BrokerComm::auto_event("bro/event/my_auto_event", my_auto_event);
|
||||
}
|
||||
|
||||
event BrokerComm::outgoing_connection_established(peer_address: string,
|
||||
peer_port: port,
|
||||
peer_name: string)
|
||||
{
|
||||
print "BrokerComm::outgoing_connection_established",
|
||||
peer_address, peer_port, peer_name;
|
||||
BrokerComm::event("bro/event/my_event", BrokerComm::event_args(my_event, "hi", 0));
|
||||
event my_auto_event("stuff", 88);
|
||||
BrokerComm::event("bro/event/my_event", BrokerComm::event_args(my_event, "...", 1));
|
||||
event my_auto_event("more stuff", 51);
|
||||
BrokerComm::event("bro/event/my_event", BrokerComm::event_args(my_event, "bye", 2));
|
||||
}
|
||||
|
||||
event BrokerComm::outgoing_connection_broken(peer_address: string,
|
||||
peer_port: port)
|
||||
{
|
||||
terminate();
|
||||
}
|
|
@ -1,21 +1,21 @@
|
|||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef Comm::endpoint_name = "listener";
|
||||
redef BrokerComm::endpoint_name = "listener";
|
||||
global msg_count = 0;
|
||||
global my_event: event(msg: string, c: count);
|
||||
global my_auto_event: event(msg: string, c: count);
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::subscribe_to_events("bro/event/");
|
||||
Comm::listen(broker_port, "127.0.0.1");
|
||||
BrokerComm::enable();
|
||||
BrokerComm::subscribe_to_events("bro/event/");
|
||||
BrokerComm::listen(broker_port, "127.0.0.1");
|
||||
}
|
||||
|
||||
event Comm::incoming_connection_established(peer_name: string)
|
||||
event BrokerComm::incoming_connection_established(peer_name: string)
|
||||
{
|
||||
print "Comm::incoming_connection_established", peer_name;
|
||||
print "BrokerComm::incoming_connection_established", peer_name;
|
||||
}
|
||||
|
||||
event my_event(msg: string, c: count)
|
|
@ -2,16 +2,16 @@
|
|||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef Comm::endpoint_name = "connector";
|
||||
redef BrokerComm::endpoint_name = "connector";
|
||||
redef Log::enable_local_logging = F;
|
||||
redef Log::enable_remote_logging = F;
|
||||
global n = 0;
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::enable_remote_logs(Test::LOG);
|
||||
Comm::connect("127.0.0.1", broker_port, 1sec);
|
||||
BrokerComm::enable();
|
||||
BrokerComm::enable_remote_logs(Test::LOG);
|
||||
BrokerComm::connect("127.0.0.1", broker_port, 1sec);
|
||||
}
|
||||
|
||||
event do_write()
|
||||
|
@ -24,16 +24,16 @@ event do_write()
|
|||
event do_write();
|
||||
}
|
||||
|
||||
event Comm::outgoing_connection_established(peer_address: string,
|
||||
event BrokerComm::outgoing_connection_established(peer_address: string,
|
||||
peer_port: port,
|
||||
peer_name: string)
|
||||
{
|
||||
print "Comm::outgoing_connection_established",
|
||||
print "BrokerComm::outgoing_connection_established",
|
||||
peer_address, peer_port, peer_name;
|
||||
event do_write();
|
||||
}
|
||||
|
||||
event Comm::outgoing_connection_broken(peer_address: string,
|
||||
event BrokerComm::outgoing_connection_broken(peer_address: string,
|
||||
peer_port: port)
|
||||
{
|
||||
terminate();
|
25
doc/frameworks/broker/logs-listener.bro
Normal file
25
doc/frameworks/broker/logs-listener.bro
Normal file
|
@ -0,0 +1,25 @@
|
|||
@load ./testlog
|
||||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef BrokerComm::endpoint_name = "listener";
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
BrokerComm::enable();
|
||||
BrokerComm::subscribe_to_logs("bro/log/Test::LOG");
|
||||
BrokerComm::listen(broker_port, "127.0.0.1");
|
||||
}
|
||||
|
||||
event BrokerComm::incoming_connection_established(peer_name: string)
|
||||
{
|
||||
print "BrokerComm::incoming_connection_established", peer_name;
|
||||
}
|
||||
|
||||
event Test::log_test(rec: Test::Info)
|
||||
{
|
||||
print "wrote log", rec;
|
||||
|
||||
if ( rec$num == 5 )
|
||||
terminate();
|
||||
}
|
26
doc/frameworks/broker/printing-connector.bro
Normal file
26
doc/frameworks/broker/printing-connector.bro
Normal file
|
@ -0,0 +1,26 @@
|
|||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef BrokerComm::endpoint_name = "connector";
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
BrokerComm::enable();
|
||||
BrokerComm::connect("127.0.0.1", broker_port, 1sec);
|
||||
}
|
||||
|
||||
event BrokerComm::outgoing_connection_established(peer_address: string,
|
||||
peer_port: port,
|
||||
peer_name: string)
|
||||
{
|
||||
print "BrokerComm::outgoing_connection_established",
|
||||
peer_address, peer_port, peer_name;
|
||||
BrokerComm::print("bro/print/hi", "hello");
|
||||
BrokerComm::print("bro/print/stuff", "...");
|
||||
BrokerComm::print("bro/print/bye", "goodbye");
|
||||
}
|
||||
|
||||
event BrokerComm::outgoing_connection_broken(peer_address: string,
|
||||
peer_port: port)
|
||||
{
|
||||
terminate();
|
||||
}
|
26
doc/frameworks/broker/printing-listener.bro
Normal file
26
doc/frameworks/broker/printing-listener.bro
Normal file
|
@ -0,0 +1,26 @@
|
|||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef BrokerComm::endpoint_name = "listener";
|
||||
global msg_count = 0;
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
BrokerComm::enable();
|
||||
BrokerComm::subscribe_to_prints("bro/print/");
|
||||
BrokerComm::listen(broker_port, "127.0.0.1");
|
||||
}
|
||||
|
||||
event BrokerComm::incoming_connection_established(peer_name: string)
|
||||
{
|
||||
print "BrokerComm::incoming_connection_established", peer_name;
|
||||
}
|
||||
|
||||
event BrokerComm::print_handler(msg: string)
|
||||
{
|
||||
++msg_count;
|
||||
print "got print message", msg;
|
||||
|
||||
if ( msg_count == 3 )
|
||||
terminate();
|
||||
}
|
53
doc/frameworks/broker/stores-connector.bro
Normal file
53
doc/frameworks/broker/stores-connector.bro
Normal file
|
@ -0,0 +1,53 @@
|
|||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
global h: opaque of BrokerStore::Handle;
|
||||
|
||||
function dv(d: BrokerComm::Data): BrokerComm::DataVector
|
||||
{
|
||||
local rval: BrokerComm::DataVector;
|
||||
rval[0] = d;
|
||||
return rval;
|
||||
}
|
||||
|
||||
global ready: event();
|
||||
|
||||
event BrokerComm::outgoing_connection_broken(peer_address: string,
|
||||
peer_port: port)
|
||||
{
|
||||
terminate();
|
||||
}
|
||||
|
||||
event BrokerComm::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"};
|
||||
h = BrokerStore::create_master("mystore");
|
||||
BrokerStore::insert(h, BrokerComm::data("one"), BrokerComm::data(110));
|
||||
BrokerStore::insert(h, BrokerComm::data("two"), BrokerComm::data(223));
|
||||
BrokerStore::insert(h, BrokerComm::data("myset"), BrokerComm::data(myset));
|
||||
BrokerStore::insert(h, BrokerComm::data("myvec"), BrokerComm::data(myvec));
|
||||
BrokerStore::increment(h, BrokerComm::data("one"));
|
||||
BrokerStore::decrement(h, BrokerComm::data("two"));
|
||||
BrokerStore::add_to_set(h, BrokerComm::data("myset"), BrokerComm::data("d"));
|
||||
BrokerStore::remove_from_set(h, BrokerComm::data("myset"), BrokerComm::data("b"));
|
||||
BrokerStore::push_left(h, BrokerComm::data("myvec"), dv(BrokerComm::data("delta")));
|
||||
BrokerStore::push_right(h, BrokerComm::data("myvec"), dv(BrokerComm::data("omega")));
|
||||
|
||||
when ( local res = BrokerStore::size(h) )
|
||||
{
|
||||
print "master size", res;
|
||||
event ready();
|
||||
}
|
||||
timeout 10sec
|
||||
{ print "timeout"; }
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
BrokerComm::enable();
|
||||
BrokerComm::connect("127.0.0.1", broker_port, 1secs);
|
||||
BrokerComm::auto_event("bro/event/ready", ready);
|
||||
}
|
43
doc/frameworks/broker/stores-listener.bro
Normal file
43
doc/frameworks/broker/stores-listener.bro
Normal file
|
@ -0,0 +1,43 @@
|
|||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
global h: opaque of BrokerStore::Handle;
|
||||
global expected_key_count = 4;
|
||||
global key_count = 0;
|
||||
|
||||
function do_lookup(key: string)
|
||||
{
|
||||
when ( local res = BrokerStore::lookup(h, BrokerComm::data(key)) )
|
||||
{
|
||||
++key_count;
|
||||
print "lookup", key, res;
|
||||
|
||||
if ( key_count == expected_key_count )
|
||||
terminate();
|
||||
}
|
||||
timeout 10sec
|
||||
{ print "timeout", key; }
|
||||
}
|
||||
|
||||
event ready()
|
||||
{
|
||||
h = BrokerStore::create_clone("mystore");
|
||||
|
||||
when ( local res = BrokerStore::keys(h) )
|
||||
{
|
||||
print "clone keys", res;
|
||||
do_lookup(BrokerComm::refine_to_string(BrokerComm::vector_lookup(res$result, 0)));
|
||||
do_lookup(BrokerComm::refine_to_string(BrokerComm::vector_lookup(res$result, 1)));
|
||||
do_lookup(BrokerComm::refine_to_string(BrokerComm::vector_lookup(res$result, 2)));
|
||||
do_lookup(BrokerComm::refine_to_string(BrokerComm::vector_lookup(res$result, 3)));
|
||||
}
|
||||
timeout 10sec
|
||||
{ print "timeout"; }
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
BrokerComm::enable();
|
||||
BrokerComm::subscribe_to_events("bro/event/ready");
|
||||
BrokerComm::listen(broker_port, "127.0.0.1");
|
||||
}
|
|
@ -14,6 +14,6 @@ export {
|
|||
|
||||
event bro_init() &priority=5
|
||||
{
|
||||
Comm::enable();
|
||||
BrokerComm::enable();
|
||||
Log::create_stream(Test::LOG, [$columns=Test::Info, $ev=log_test]);
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef Comm::endpoint_name = "listener";
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::listen(broker_port, "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();
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef Comm::endpoint_name = "connector";
|
||||
global my_event: event(msg: string, c: count);
|
||||
global my_auto_event: event(msg: string, c: count);
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::connect("127.0.0.1", broker_port, 1sec);
|
||||
Comm::auto_event("bro/event/my_auto_event", my_auto_event);
|
||||
}
|
||||
|
||||
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;
|
||||
Comm::event("bro/event/my_event", Comm::event_args(my_event, "hi", 0));
|
||||
event my_auto_event("stuff", 88);
|
||||
Comm::event("bro/event/my_event", Comm::event_args(my_event, "...", 1));
|
||||
event my_auto_event("more stuff", 51);
|
||||
Comm::event("bro/event/my_event", Comm::event_args(my_event, "bye", 2));
|
||||
}
|
||||
|
||||
event Comm::outgoing_connection_broken(peer_address: string,
|
||||
peer_port: port)
|
||||
{
|
||||
terminate();
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
@load ./testlog
|
||||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef Comm::endpoint_name = "listener";
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::subscribe_to_logs("bro/log/Test::LOG");
|
||||
Comm::listen(broker_port, "127.0.0.1");
|
||||
}
|
||||
|
||||
event Comm::incoming_connection_established(peer_name: string)
|
||||
{
|
||||
print "Comm::incoming_connection_established", peer_name;
|
||||
}
|
||||
|
||||
event Test::log_test(rec: Test::Info)
|
||||
{
|
||||
print "wrote log", rec;
|
||||
|
||||
if ( rec$num == 5 )
|
||||
terminate();
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef Comm::endpoint_name = "connector";
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::connect("127.0.0.1", broker_port, 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;
|
||||
Comm::print("bro/print/hi", "hello");
|
||||
Comm::print("bro/print/stuff", "...");
|
||||
Comm::print("bro/print/bye", "goodbye");
|
||||
}
|
||||
|
||||
event Comm::outgoing_connection_broken(peer_address: string,
|
||||
peer_port: port)
|
||||
{
|
||||
terminate();
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef Comm::endpoint_name = "listener";
|
||||
global msg_count = 0;
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::subscribe_to_prints("bro/print/");
|
||||
Comm::listen(broker_port, "127.0.0.1");
|
||||
}
|
||||
|
||||
event Comm::incoming_connection_established(peer_name: string)
|
||||
{
|
||||
print "Comm::incoming_connection_established", peer_name;
|
||||
}
|
||||
|
||||
event Comm::print_handler(msg: string)
|
||||
{
|
||||
++msg_count;
|
||||
print "got print message", msg;
|
||||
|
||||
if ( msg_count == 3 )
|
||||
terminate();
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
global h: opaque of Store::Handle;
|
||||
|
||||
function dv(d: Comm::Data): Comm::DataVector
|
||||
{
|
||||
local rval: Comm::DataVector;
|
||||
rval[0] = d;
|
||||
return rval;
|
||||
}
|
||||
|
||||
global ready: event();
|
||||
|
||||
event Comm::outgoing_connection_broken(peer_address: string,
|
||||
peer_port: port)
|
||||
{
|
||||
terminate();
|
||||
}
|
||||
|
||||
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"};
|
||||
h = Store::create_master("mystore");
|
||||
Store::insert(h, Comm::data("one"), Comm::data(110));
|
||||
Store::insert(h, Comm::data("two"), Comm::data(223));
|
||||
Store::insert(h, Comm::data("myset"), Comm::data(myset));
|
||||
Store::insert(h, Comm::data("myvec"), Comm::data(myvec));
|
||||
Store::increment(h, Comm::data("one"));
|
||||
Store::decrement(h, Comm::data("two"));
|
||||
Store::add_to_set(h, Comm::data("myset"), Comm::data("d"));
|
||||
Store::remove_from_set(h, Comm::data("myset"), Comm::data("b"));
|
||||
Store::push_left(h, Comm::data("myvec"), dv(Comm::data("delta")));
|
||||
Store::push_right(h, Comm::data("myvec"), dv(Comm::data("omega")));
|
||||
|
||||
when ( local res = Store::size(h) )
|
||||
{
|
||||
print "master size", res;
|
||||
event ready();
|
||||
}
|
||||
timeout 10sec
|
||||
{ print "timeout"; }
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::connect("127.0.0.1", broker_port, 1secs);
|
||||
Comm::auto_event("bro/event/ready", ready);
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
global h: opaque of Store::Handle;
|
||||
global expected_key_count = 4;
|
||||
global key_count = 0;
|
||||
|
||||
function do_lookup(key: string)
|
||||
{
|
||||
when ( local res = Store::lookup(h, Comm::data(key)) )
|
||||
{
|
||||
++key_count;
|
||||
print "lookup", key, res;
|
||||
|
||||
if ( key_count == expected_key_count )
|
||||
terminate();
|
||||
}
|
||||
timeout 10sec
|
||||
{ print "timeout", key; }
|
||||
}
|
||||
|
||||
event ready()
|
||||
{
|
||||
h = Store::create_clone("mystore");
|
||||
|
||||
when ( local res = Store::keys(h) )
|
||||
{
|
||||
print "clone keys", res;
|
||||
do_lookup(Comm::refine_to_string(Comm::vector_lookup(res$result, 0)));
|
||||
do_lookup(Comm::refine_to_string(Comm::vector_lookup(res$result, 1)));
|
||||
do_lookup(Comm::refine_to_string(Comm::vector_lookup(res$result, 2)));
|
||||
do_lookup(Comm::refine_to_string(Comm::vector_lookup(res$result, 3)));
|
||||
}
|
||||
timeout 10sec
|
||||
{ print "timeout"; }
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::subscribe_to_events("bro/event/ready");
|
||||
Comm::listen(broker_port, "127.0.0.1");
|
||||
}
|
|
@ -14,4 +14,4 @@ Frameworks
|
|||
notice
|
||||
signatures
|
||||
sumstats
|
||||
comm
|
||||
broker
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
##! Various data structure definitions for use with Bro's communication system.
|
||||
|
||||
module Comm;
|
||||
module BrokerComm;
|
||||
|
||||
export {
|
||||
|
||||
## A name used to identify this endpoint to peers.
|
||||
## .. bro:see:: Comm::connect Comm::listen
|
||||
## .. bro:see:: BrokerComm::connect BrokerComm::listen
|
||||
const endpoint_name = "" &redef;
|
||||
|
||||
## Change communication behavior.
|
||||
|
@ -32,11 +32,11 @@ export {
|
|||
|
||||
## Opaque communication data.
|
||||
type Data: record {
|
||||
d: opaque of Comm::Data &optional;
|
||||
d: opaque of BrokerComm::Data &optional;
|
||||
};
|
||||
|
||||
## Opaque communication data.
|
||||
type DataVector: vector of Comm::Data;
|
||||
type DataVector: vector of BrokerComm::Data;
|
||||
|
||||
## Opaque event communication data.
|
||||
type EventArgs: record {
|
||||
|
@ -48,13 +48,13 @@ export {
|
|||
|
||||
## Opaque communication data used as a convenient way to wrap key-value
|
||||
## pairs that comprise table entries.
|
||||
type Comm::TableItem : record {
|
||||
key: Comm::Data;
|
||||
val: Comm::Data;
|
||||
type TableItem : record {
|
||||
key: BrokerComm::Data;
|
||||
val: BrokerComm::Data;
|
||||
};
|
||||
}
|
||||
|
||||
module Store;
|
||||
module BrokerStore;
|
||||
|
||||
export {
|
||||
|
||||
|
@ -76,11 +76,11 @@ export {
|
|||
## The result of a data store query.
|
||||
type QueryResult: record {
|
||||
## Whether the query completed or not.
|
||||
status: Store::QueryStatus;
|
||||
status: BrokerStore::QueryStatus;
|
||||
## The result of the query. Certain queries may use a particular
|
||||
## data type (e.g. querying store size always returns a count, but
|
||||
## a lookup may return various data types).
|
||||
result: Comm::Data;
|
||||
result: BrokerComm::Data;
|
||||
};
|
||||
|
||||
## Options to tune the SQLite storage backend.
|
|
@ -3360,7 +3360,7 @@ const bits_per_uid: count = 96 &redef;
|
|||
|
||||
# Load these frameworks here because they use fairly deep integration with
|
||||
# BiFs and script-land defined types.
|
||||
@load base/frameworks/comm
|
||||
@load base/frameworks/broker
|
||||
@load base/frameworks/logging
|
||||
@load base/frameworks/input
|
||||
@load base/frameworks/analyzer
|
||||
|
|
|
@ -162,11 +162,11 @@ add_subdirectory(logging)
|
|||
add_subdirectory(probabilistic)
|
||||
|
||||
if ( ENABLE_BROKER )
|
||||
add_subdirectory(comm)
|
||||
add_subdirectory(broker)
|
||||
else ()
|
||||
# Just to satisfy coverage unit tests until new Broker-based
|
||||
# communication is enabled by default.
|
||||
add_subdirectory(comm-dummy)
|
||||
add_subdirectory(broker-dummy)
|
||||
endif ()
|
||||
|
||||
set(bro_SUBDIRS
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
#include "NetVar.h"
|
||||
|
||||
#ifdef ENABLE_BROKER
|
||||
#include "comm/Manager.h"
|
||||
#include "comm/Data.h"
|
||||
#include "broker/Manager.h"
|
||||
#include "broker/Data.h"
|
||||
#endif
|
||||
|
||||
EventHandler::EventHandler(const char* arg_name)
|
||||
|
@ -96,7 +96,7 @@ void EventHandler::Call(val_list* vl, bool no_remote)
|
|||
|
||||
for ( auto i = 0; i < vl->length(); ++i )
|
||||
{
|
||||
auto opt_data = comm::val_to_data((*vl)[i]);
|
||||
auto opt_data = bro_broker::val_to_data((*vl)[i]);
|
||||
|
||||
if ( opt_data )
|
||||
msg.emplace_back(move(*opt_data));
|
||||
|
@ -116,9 +116,9 @@ void EventHandler::Call(val_list* vl, bool no_remote)
|
|||
it != auto_remote_send.end(); ++it )
|
||||
{
|
||||
if ( std::next(it) == auto_remote_send.end() )
|
||||
comm_mgr->Event(it->first, move(msg), it->second);
|
||||
broker_mgr->Event(it->first, move(msg), it->second);
|
||||
else
|
||||
comm_mgr->Event(it->first, msg, it->second);
|
||||
broker_mgr->Event(it->first, msg, it->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
#include "plugin/Manager.h"
|
||||
|
||||
#ifdef ENABLE_BROKER
|
||||
#include "comm/Manager.h"
|
||||
#include "broker/Manager.h"
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
|
@ -322,7 +322,7 @@ void net_run()
|
|||
bool communication_enabled = using_communication;
|
||||
|
||||
#ifdef ENABLE_BROKER
|
||||
communication_enabled |= comm_mgr->Enabled();
|
||||
communication_enabled |= broker_mgr->Enabled();
|
||||
#endif
|
||||
|
||||
if ( src )
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include "threading/Manager.h"
|
||||
|
||||
#ifdef ENABLE_BROKER
|
||||
#include "comm/Manager.h"
|
||||
#include "broker/Manager.h"
|
||||
#endif
|
||||
|
||||
int killed_by_inactivity = 0;
|
||||
|
@ -227,7 +227,7 @@ void ProfileLogger::Log()
|
|||
}
|
||||
|
||||
#ifdef ENABLE_BROKER
|
||||
auto cs = comm_mgr->ConsumeStatistics();
|
||||
auto cs = broker_mgr->ConsumeStatistics();
|
||||
|
||||
file->Write(fmt("%0.6f Comm: peers=%zu stores=%zu "
|
||||
"store_queries=%zu store_responses=%zu "
|
||||
|
|
|
@ -9,5 +9,5 @@ bif_target(data.bif)
|
|||
bif_target(messaging.bif)
|
||||
bif_target(store.bif)
|
||||
|
||||
bro_add_subdir_library(comm_dummy ${BIF_OUTPUT_CC})
|
||||
add_dependencies(bro_comm_dummy generate_outputs)
|
||||
bro_add_subdir_library(broker_dummy ${BIF_OUTPUT_CC})
|
||||
add_dependencies(bro_broker_dummy generate_outputs)
|
|
@ -24,5 +24,5 @@ bif_target(data.bif)
|
|||
bif_target(messaging.bif)
|
||||
bif_target(store.bif)
|
||||
|
||||
bro_add_subdir_library(comm ${comm_SRCS} ${BIF_OUTPUT_CC})
|
||||
add_dependencies(bro_comm generate_outputs)
|
||||
bro_add_subdir_library(brokercomm ${comm_SRCS} ${BIF_OUTPUT_CC})
|
||||
add_dependencies(bro_brokercomm generate_outputs)
|
|
@ -1,15 +1,15 @@
|
|||
#include "Data.h"
|
||||
#include "comm/data.bif.h"
|
||||
#include "broker/data.bif.h"
|
||||
#include <caf/binary_serializer.hpp>
|
||||
#include <caf/binary_deserializer.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
OpaqueType* comm::opaque_of_data_type;
|
||||
OpaqueType* comm::opaque_of_set_iterator;
|
||||
OpaqueType* comm::opaque_of_table_iterator;
|
||||
OpaqueType* comm::opaque_of_vector_iterator;
|
||||
OpaqueType* comm::opaque_of_record_iterator;
|
||||
OpaqueType* bro_broker::opaque_of_data_type;
|
||||
OpaqueType* bro_broker::opaque_of_set_iterator;
|
||||
OpaqueType* bro_broker::opaque_of_table_iterator;
|
||||
OpaqueType* bro_broker::opaque_of_vector_iterator;
|
||||
OpaqueType* bro_broker::opaque_of_record_iterator;
|
||||
|
||||
static broker::port::protocol to_broker_port_proto(TransportProto tp)
|
||||
{
|
||||
|
@ -26,7 +26,7 @@ static broker::port::protocol to_broker_port_proto(TransportProto tp)
|
|||
}
|
||||
}
|
||||
|
||||
TransportProto comm::to_bro_port_proto(broker::port::protocol tp)
|
||||
TransportProto bro_broker::to_bro_port_proto(broker::port::protocol tp)
|
||||
{
|
||||
switch ( tp ) {
|
||||
case broker::port::protocol::tcp:
|
||||
|
@ -45,6 +45,7 @@ struct val_converter {
|
|||
using result_type = Val*;
|
||||
|
||||
BroType* type;
|
||||
bool require_log_attr;
|
||||
|
||||
result_type operator()(bool a)
|
||||
{
|
||||
|
@ -134,7 +135,7 @@ struct val_converter {
|
|||
result_type operator()(broker::port& a)
|
||||
{
|
||||
if ( type->Tag() == TYPE_PORT )
|
||||
return new PortVal(a.number(), comm::to_bro_port_proto(a.type()));
|
||||
return new PortVal(a.number(), bro_broker::to_bro_port_proto(a.type()));
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -203,8 +204,8 @@ struct val_converter {
|
|||
|
||||
for ( auto i = 0u; i < indices->size(); ++i )
|
||||
{
|
||||
auto index_val = comm::data_to_val(move((*indices)[i]),
|
||||
(*expected_index_types)[i]);
|
||||
auto index_val = bro_broker::data_to_val(move((*indices)[i]),
|
||||
(*expected_index_types)[i]);
|
||||
|
||||
if ( ! index_val )
|
||||
{
|
||||
|
@ -256,8 +257,8 @@ struct val_converter {
|
|||
|
||||
for ( auto i = 0u; i < indices->size(); ++i )
|
||||
{
|
||||
auto index_val = comm::data_to_val(move((*indices)[i]),
|
||||
(*expected_index_types)[i]);
|
||||
auto index_val = bro_broker::data_to_val(move((*indices)[i]),
|
||||
(*expected_index_types)[i]);
|
||||
|
||||
if ( ! index_val )
|
||||
{
|
||||
|
@ -269,8 +270,8 @@ struct val_converter {
|
|||
list_val->Append(index_val);
|
||||
}
|
||||
|
||||
auto value_val = comm::data_to_val(move(item.second),
|
||||
tt->YieldType());
|
||||
auto value_val = bro_broker::data_to_val(move(item.second),
|
||||
tt->YieldType());
|
||||
|
||||
if ( ! value_val )
|
||||
{
|
||||
|
@ -296,7 +297,7 @@ struct val_converter {
|
|||
|
||||
for ( auto& item : a )
|
||||
{
|
||||
auto item_val = comm::data_to_val(move(item), vt->YieldType());
|
||||
auto item_val = bro_broker::data_to_val(move(item), vt->YieldType());
|
||||
|
||||
if ( ! item_val )
|
||||
{
|
||||
|
@ -316,22 +317,27 @@ struct val_converter {
|
|||
return nullptr;
|
||||
|
||||
auto rt = type->AsRecordType();
|
||||
|
||||
if ( a.fields.size() != static_cast<size_t>(rt->NumFields()) )
|
||||
return nullptr;
|
||||
|
||||
auto rval = new RecordVal(rt);
|
||||
|
||||
for ( auto i = 0u; i < a.fields.size(); ++i )
|
||||
for ( auto i = 0u; i < static_cast<size_t>(rt->NumFields()); ++i )
|
||||
{
|
||||
if ( require_log_attr && ! rt->FieldDecl(i)->FindAttr(ATTR_LOG) )
|
||||
continue;
|
||||
|
||||
if ( i >= a.fields.size() )
|
||||
{
|
||||
Unref(rval);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if ( ! a.fields[i] )
|
||||
{
|
||||
rval->Assign(i, nullptr);
|
||||
continue;
|
||||
}
|
||||
|
||||
auto item_val = comm::data_to_val(move(*a.fields[i]),
|
||||
rt->FieldType(i));
|
||||
auto item_val = bro_broker::data_to_val(move(*a.fields[i]),
|
||||
rt->FieldType(i));
|
||||
|
||||
if ( ! item_val )
|
||||
{
|
||||
|
@ -346,12 +352,12 @@ struct val_converter {
|
|||
}
|
||||
};
|
||||
|
||||
Val* comm::data_to_val(broker::data d, BroType* type)
|
||||
Val* bro_broker::data_to_val(broker::data d, BroType* type, bool require_log_attr)
|
||||
{
|
||||
return broker::visit(val_converter{type}, d);
|
||||
return broker::visit(val_converter{type, require_log_attr}, d);
|
||||
}
|
||||
|
||||
broker::util::optional<broker::data> comm::val_to_data(Val* v)
|
||||
broker::util::optional<broker::data> bro_broker::val_to_data(Val* v)
|
||||
{
|
||||
switch ( v->Type()->Tag() ) {
|
||||
case TYPE_BOOL:
|
||||
|
@ -533,7 +539,7 @@ broker::util::optional<broker::data> comm::val_to_data(Val* v)
|
|||
return {rval};
|
||||
}
|
||||
default:
|
||||
reporter->Error("unsupported Comm::Data type: %s",
|
||||
reporter->Error("unsupported BrokerComm::Data type: %s",
|
||||
type_name(v->Type()->Tag()));
|
||||
break;
|
||||
}
|
||||
|
@ -541,9 +547,9 @@ broker::util::optional<broker::data> comm::val_to_data(Val* v)
|
|||
return {};
|
||||
}
|
||||
|
||||
RecordVal* comm::make_data_val(Val* v)
|
||||
RecordVal* bro_broker::make_data_val(Val* v)
|
||||
{
|
||||
auto rval = new RecordVal(BifType::Record::Comm::Data);
|
||||
auto rval = new RecordVal(BifType::Record::BrokerComm::Data);
|
||||
auto data = val_to_data(v);
|
||||
|
||||
if ( data )
|
||||
|
@ -552,9 +558,9 @@ RecordVal* comm::make_data_val(Val* v)
|
|||
return rval;
|
||||
}
|
||||
|
||||
RecordVal* comm::make_data_val(broker::data d)
|
||||
RecordVal* bro_broker::make_data_val(broker::data d)
|
||||
{
|
||||
auto rval = new RecordVal(BifType::Record::Comm::Data);
|
||||
auto rval = new RecordVal(BifType::Record::BrokerComm::Data);
|
||||
rval->Assign(0, new DataVal(move(d)));
|
||||
return rval;
|
||||
}
|
||||
|
@ -564,114 +570,114 @@ struct data_type_getter {
|
|||
|
||||
result_type operator()(bool a)
|
||||
{
|
||||
return new EnumVal(BifEnum::Comm::BOOL,
|
||||
BifType::Enum::Comm::DataType);
|
||||
return new EnumVal(BifEnum::BrokerComm::BOOL,
|
||||
BifType::Enum::BrokerComm::DataType);
|
||||
}
|
||||
|
||||
result_type operator()(uint64_t a)
|
||||
{
|
||||
return new EnumVal(BifEnum::Comm::COUNT,
|
||||
BifType::Enum::Comm::DataType);
|
||||
return new EnumVal(BifEnum::BrokerComm::COUNT,
|
||||
BifType::Enum::BrokerComm::DataType);
|
||||
}
|
||||
|
||||
result_type operator()(int64_t a)
|
||||
{
|
||||
return new EnumVal(BifEnum::Comm::INT,
|
||||
BifType::Enum::Comm::DataType);
|
||||
return new EnumVal(BifEnum::BrokerComm::INT,
|
||||
BifType::Enum::BrokerComm::DataType);
|
||||
}
|
||||
|
||||
result_type operator()(double a)
|
||||
{
|
||||
return new EnumVal(BifEnum::Comm::DOUBLE,
|
||||
BifType::Enum::Comm::DataType);
|
||||
return new EnumVal(BifEnum::BrokerComm::DOUBLE,
|
||||
BifType::Enum::BrokerComm::DataType);
|
||||
}
|
||||
|
||||
result_type operator()(const std::string& a)
|
||||
{
|
||||
return new EnumVal(BifEnum::Comm::STRING,
|
||||
BifType::Enum::Comm::DataType);
|
||||
return new EnumVal(BifEnum::BrokerComm::STRING,
|
||||
BifType::Enum::BrokerComm::DataType);
|
||||
}
|
||||
|
||||
result_type operator()(const broker::address& a)
|
||||
{
|
||||
return new EnumVal(BifEnum::Comm::ADDR,
|
||||
BifType::Enum::Comm::DataType);
|
||||
return new EnumVal(BifEnum::BrokerComm::ADDR,
|
||||
BifType::Enum::BrokerComm::DataType);
|
||||
}
|
||||
|
||||
result_type operator()(const broker::subnet& a)
|
||||
{
|
||||
return new EnumVal(BifEnum::Comm::SUBNET,
|
||||
BifType::Enum::Comm::DataType);
|
||||
return new EnumVal(BifEnum::BrokerComm::SUBNET,
|
||||
BifType::Enum::BrokerComm::DataType);
|
||||
}
|
||||
|
||||
result_type operator()(const broker::port& a)
|
||||
{
|
||||
return new EnumVal(BifEnum::Comm::PORT,
|
||||
BifType::Enum::Comm::DataType);
|
||||
return new EnumVal(BifEnum::BrokerComm::PORT,
|
||||
BifType::Enum::BrokerComm::DataType);
|
||||
}
|
||||
|
||||
result_type operator()(const broker::time_point& a)
|
||||
{
|
||||
return new EnumVal(BifEnum::Comm::TIME,
|
||||
BifType::Enum::Comm::DataType);
|
||||
return new EnumVal(BifEnum::BrokerComm::TIME,
|
||||
BifType::Enum::BrokerComm::DataType);
|
||||
}
|
||||
|
||||
result_type operator()(const broker::time_duration& a)
|
||||
{
|
||||
return new EnumVal(BifEnum::Comm::INTERVAL,
|
||||
BifType::Enum::Comm::DataType);
|
||||
return new EnumVal(BifEnum::BrokerComm::INTERVAL,
|
||||
BifType::Enum::BrokerComm::DataType);
|
||||
}
|
||||
|
||||
result_type operator()(const broker::enum_value& a)
|
||||
{
|
||||
return new EnumVal(BifEnum::Comm::ENUM,
|
||||
BifType::Enum::Comm::DataType);
|
||||
return new EnumVal(BifEnum::BrokerComm::ENUM,
|
||||
BifType::Enum::BrokerComm::DataType);
|
||||
}
|
||||
|
||||
result_type operator()(const broker::set& a)
|
||||
{
|
||||
return new EnumVal(BifEnum::Comm::SET,
|
||||
BifType::Enum::Comm::DataType);
|
||||
return new EnumVal(BifEnum::BrokerComm::SET,
|
||||
BifType::Enum::BrokerComm::DataType);
|
||||
}
|
||||
|
||||
result_type operator()(const broker::table& a)
|
||||
{
|
||||
return new EnumVal(BifEnum::Comm::TABLE,
|
||||
BifType::Enum::Comm::DataType);
|
||||
return new EnumVal(BifEnum::BrokerComm::TABLE,
|
||||
BifType::Enum::BrokerComm::DataType);
|
||||
}
|
||||
|
||||
result_type operator()(const broker::vector& a)
|
||||
{
|
||||
return new EnumVal(BifEnum::Comm::VECTOR,
|
||||
BifType::Enum::Comm::DataType);
|
||||
return new EnumVal(BifEnum::BrokerComm::VECTOR,
|
||||
BifType::Enum::BrokerComm::DataType);
|
||||
}
|
||||
|
||||
result_type operator()(const broker::record& a)
|
||||
{
|
||||
return new EnumVal(BifEnum::Comm::RECORD,
|
||||
BifType::Enum::Comm::DataType);
|
||||
return new EnumVal(BifEnum::BrokerComm::RECORD,
|
||||
BifType::Enum::BrokerComm::DataType);
|
||||
}
|
||||
};
|
||||
|
||||
EnumVal* comm::get_data_type(RecordVal* v, Frame* frame)
|
||||
EnumVal* bro_broker::get_data_type(RecordVal* v, Frame* frame)
|
||||
{
|
||||
return broker::visit(data_type_getter{}, opaque_field_to_data(v, frame));
|
||||
}
|
||||
|
||||
broker::data& comm::opaque_field_to_data(RecordVal* v, Frame* f)
|
||||
broker::data& bro_broker::opaque_field_to_data(RecordVal* v, Frame* f)
|
||||
{
|
||||
Val* d = v->Lookup(0);
|
||||
|
||||
if ( ! d )
|
||||
reporter->RuntimeError(f->GetCall()->GetLocationInfo(),
|
||||
"Comm::Data's opaque field is not set");
|
||||
"BrokerComm::Data's opaque field is not set");
|
||||
|
||||
return static_cast<DataVal*>(d)->data;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(comm::DataVal, SER_COMM_DATA_VAL);
|
||||
IMPLEMENT_SERIAL(bro_broker::DataVal, SER_COMM_DATA_VAL);
|
||||
|
||||
bool comm::DataVal::DoSerialize(SerialInfo* info) const
|
||||
bool bro_broker::DataVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_COMM_DATA_VAL, OpaqueVal);
|
||||
|
||||
|
@ -685,7 +691,7 @@ bool comm::DataVal::DoSerialize(SerialInfo* info) const
|
|||
return true;
|
||||
}
|
||||
|
||||
bool comm::DataVal::DoUnserialize(UnserialInfo* info)
|
||||
bool bro_broker::DataVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(OpaqueVal);
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
#include "Frame.h"
|
||||
#include "Expr.h"
|
||||
|
||||
namespace comm {
|
||||
namespace bro_broker {
|
||||
|
||||
extern OpaqueType* opaque_of_data_type;
|
||||
extern OpaqueType* opaque_of_set_iterator;
|
||||
|
@ -21,25 +21,25 @@ extern OpaqueType* opaque_of_record_iterator;
|
|||
TransportProto to_bro_port_proto(broker::port::protocol tp);
|
||||
|
||||
/**
|
||||
* Create a Comm::Data value from a Bro value.
|
||||
* Create a BrokerComm::Data value from a Bro value.
|
||||
* @param v the Bro value to convert to a Broker data value.
|
||||
* @return a Comm::Data value, where the optional field is set if the conversion
|
||||
* @return a BrokerComm::Data value, where the optional field is set if the conversion
|
||||
* was possible, else it is unset.
|
||||
*/
|
||||
RecordVal* make_data_val(Val* v);
|
||||
|
||||
/**
|
||||
* Create a Comm::Data value from a Broker data value.
|
||||
* Create a BrokerComm::Data value from a Broker data value.
|
||||
* @param d the Broker value to wrap in an opaque type.
|
||||
* @return a Comm::Data value that wraps the Broker value.
|
||||
* @return a BrokerComm::Data value that wraps the Broker value.
|
||||
*/
|
||||
RecordVal* make_data_val(broker::data d);
|
||||
|
||||
/**
|
||||
* Get the type of Broker data that Comm::Data wraps.
|
||||
* @param v a Comm::Data value.
|
||||
* Get the type of Broker data that BrokerComm::Data wraps.
|
||||
* @param v a BrokerComm::Data value.
|
||||
* @param frame used to get location info upon error.
|
||||
* @return a Comm::DataType value.
|
||||
* @return a BrokerComm::DataType value.
|
||||
*/
|
||||
EnumVal* get_data_type(RecordVal* v, Frame* frame);
|
||||
|
||||
|
@ -54,10 +54,12 @@ broker::util::optional<broker::data> val_to_data(Val* v);
|
|||
* Convert a Broker data value to a Bro value.
|
||||
* @param d a Broker data value.
|
||||
* @param type the expected type of the value to return.
|
||||
* @param require_log_attr if true, skip over record fields that don't have the
|
||||
* &log attribute.
|
||||
* @return a pointer to a new Bro value or a nullptr if the conversion was not
|
||||
* possible.
|
||||
*/
|
||||
Val* data_to_val(broker::data d, BroType* type);
|
||||
Val* data_to_val(broker::data d, BroType* type, bool require_log_attr = false);
|
||||
|
||||
/**
|
||||
* A Bro value which wraps a Broker data value.
|
||||
|
@ -66,7 +68,7 @@ class DataVal : public OpaqueVal {
|
|||
public:
|
||||
|
||||
DataVal(broker::data arg_data)
|
||||
: OpaqueVal(comm::opaque_of_data_type), data(std::move(arg_data))
|
||||
: OpaqueVal(bro_broker::opaque_of_data_type), data(std::move(arg_data))
|
||||
{}
|
||||
|
||||
void ValDescribe(ODesc* d) const override
|
||||
|
@ -139,8 +141,8 @@ struct type_name_getter {
|
|||
};
|
||||
|
||||
/**
|
||||
* Retrieve Broker data value associated with a Comm::Data Bro value.
|
||||
* @param v a Comm::Data value.
|
||||
* Retrieve Broker data value associated with a BrokerComm::Data Bro value.
|
||||
* @param v a BrokerComm::Data value.
|
||||
* @param f used to get location information on error.
|
||||
* @return a reference to the wrapped Broker data value. A runtime interpreter
|
||||
* exception is thrown if the the optional opaque value of \a v is not set.
|
||||
|
@ -181,9 +183,9 @@ inline T& require_data_type(RecordVal* v, TypeTag tag, Frame* f)
|
|||
}
|
||||
|
||||
/**
|
||||
* Convert a Comm::Data Bro value to a Bro value of a given type.
|
||||
* Convert a BrokerComm::Data Bro value to a Bro value of a given type.
|
||||
* @tparam a type that a Broker data variant may contain.
|
||||
* @param v a Comm::Data value.
|
||||
* @param v a BrokerComm::Data value.
|
||||
* @param tag a Bro type to convert to.
|
||||
* @param f used to get location information on error.
|
||||
* A runtime interpret exception is thrown if trying to access a type which
|
||||
|
@ -201,7 +203,7 @@ class SetIterator : public OpaqueVal {
|
|||
public:
|
||||
|
||||
SetIterator(RecordVal* v, TypeTag tag, Frame* f)
|
||||
: OpaqueVal(comm::opaque_of_set_iterator),
|
||||
: OpaqueVal(bro_broker::opaque_of_set_iterator),
|
||||
dat(require_data_type<broker::set>(v, TYPE_TABLE, f)),
|
||||
it(dat.begin())
|
||||
{}
|
||||
|
@ -214,7 +216,7 @@ class TableIterator : public OpaqueVal {
|
|||
public:
|
||||
|
||||
TableIterator(RecordVal* v, TypeTag tag, Frame* f)
|
||||
: OpaqueVal(comm::opaque_of_table_iterator),
|
||||
: OpaqueVal(bro_broker::opaque_of_table_iterator),
|
||||
dat(require_data_type<broker::table>(v, TYPE_TABLE, f)),
|
||||
it(dat.begin())
|
||||
{}
|
||||
|
@ -227,7 +229,7 @@ class VectorIterator : public OpaqueVal {
|
|||
public:
|
||||
|
||||
VectorIterator(RecordVal* v, TypeTag tag, Frame* f)
|
||||
: OpaqueVal(comm::opaque_of_vector_iterator),
|
||||
: OpaqueVal(bro_broker::opaque_of_vector_iterator),
|
||||
dat(require_data_type<broker::vector>(v, TYPE_VECTOR, f)),
|
||||
it(dat.begin())
|
||||
{}
|
||||
|
@ -240,7 +242,7 @@ class RecordIterator : public OpaqueVal {
|
|||
public:
|
||||
|
||||
RecordIterator(RecordVal* v, TypeTag tag, Frame* f)
|
||||
: OpaqueVal(comm::opaque_of_record_iterator),
|
||||
: OpaqueVal(bro_broker::opaque_of_record_iterator),
|
||||
dat(require_data_type<broker::record>(v, TYPE_VECTOR, f)),
|
||||
it(dat.fields.begin())
|
||||
{}
|
||||
|
@ -249,6 +251,6 @@ public:
|
|||
decltype(broker::record::fields)::iterator it;
|
||||
};
|
||||
|
||||
} // namespace comm
|
||||
} // namespace bro_broker
|
||||
|
||||
#endif // BRO_COMM_DATA_H
|
|
@ -8,23 +8,23 @@
|
|||
#include "util.h"
|
||||
#include "Var.h"
|
||||
#include "Reporter.h"
|
||||
#include "comm/comm.bif.h"
|
||||
#include "comm/data.bif.h"
|
||||
#include "comm/messaging.bif.h"
|
||||
#include "comm/store.bif.h"
|
||||
#include "broker/comm.bif.h"
|
||||
#include "broker/data.bif.h"
|
||||
#include "broker/messaging.bif.h"
|
||||
#include "broker/store.bif.h"
|
||||
#include "logging/Manager.h"
|
||||
#include "DebugLogger.h"
|
||||
#include "iosource/Manager.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
VectorType* comm::Manager::vector_of_data_type;
|
||||
EnumType* comm::Manager::log_id_type;
|
||||
int comm::Manager::send_flags_self_idx;
|
||||
int comm::Manager::send_flags_peers_idx;
|
||||
int comm::Manager::send_flags_unsolicited_idx;
|
||||
VectorType* bro_broker::Manager::vector_of_data_type;
|
||||
EnumType* bro_broker::Manager::log_id_type;
|
||||
int bro_broker::Manager::send_flags_self_idx;
|
||||
int bro_broker::Manager::send_flags_peers_idx;
|
||||
int bro_broker::Manager::send_flags_unsolicited_idx;
|
||||
|
||||
comm::Manager::~Manager()
|
||||
bro_broker::Manager::~Manager()
|
||||
{
|
||||
for ( auto& s : data_stores )
|
||||
CloseStore(s.first.first, s.first.second);
|
||||
|
@ -59,25 +59,25 @@ static int endpoint_flags_to_int(Val* broker_endpoint_flags)
|
|||
return rval;
|
||||
}
|
||||
|
||||
bool comm::Manager::Enable(Val* broker_endpoint_flags)
|
||||
bool bro_broker::Manager::Enable(Val* broker_endpoint_flags)
|
||||
{
|
||||
if ( endpoint != nullptr )
|
||||
return true;
|
||||
|
||||
auto send_flags_type = internal_type("Comm::SendFlags")->AsRecordType();
|
||||
auto send_flags_type = internal_type("BrokerComm::SendFlags")->AsRecordType();
|
||||
send_flags_self_idx = require_field(send_flags_type, "self");
|
||||
send_flags_peers_idx = require_field(send_flags_type, "peers");
|
||||
send_flags_unsolicited_idx = require_field(send_flags_type, "unsolicited");
|
||||
|
||||
log_id_type = internal_type("Log::ID")->AsEnumType();
|
||||
|
||||
comm::opaque_of_data_type = new OpaqueType("Comm::Data");
|
||||
comm::opaque_of_set_iterator = new OpaqueType("Comm::SetIterator");
|
||||
comm::opaque_of_table_iterator = new OpaqueType("Comm::TableIterator");
|
||||
comm::opaque_of_vector_iterator = new OpaqueType("Comm::VectorIterator");
|
||||
comm::opaque_of_record_iterator = new OpaqueType("Comm::RecordIterator");
|
||||
comm::opaque_of_store_handle = new OpaqueType("Store::Handle");
|
||||
vector_of_data_type = new VectorType(internal_type("Comm::Data")->Ref());
|
||||
bro_broker::opaque_of_data_type = new OpaqueType("BrokerComm::Data");
|
||||
bro_broker::opaque_of_set_iterator = new OpaqueType("BrokerComm::SetIterator");
|
||||
bro_broker::opaque_of_table_iterator = new OpaqueType("BrokerComm::TableIterator");
|
||||
bro_broker::opaque_of_vector_iterator = new OpaqueType("BrokerComm::VectorIterator");
|
||||
bro_broker::opaque_of_record_iterator = new OpaqueType("BrokerComm::RecordIterator");
|
||||
bro_broker::opaque_of_store_handle = new OpaqueType("BrokerStore::Handle");
|
||||
vector_of_data_type = new VectorType(internal_type("BrokerComm::Data")->Ref());
|
||||
|
||||
auto res = broker::init();
|
||||
|
||||
|
@ -97,7 +97,7 @@ bool comm::Manager::Enable(Val* broker_endpoint_flags)
|
|||
}
|
||||
|
||||
const char* name;
|
||||
auto name_from_script = internal_val("Comm::endpoint_name")->AsString();
|
||||
auto name_from_script = internal_val("BrokerComm::endpoint_name")->AsString();
|
||||
|
||||
if ( name_from_script->Len() )
|
||||
name = name_from_script->CheckString();
|
||||
|
@ -117,7 +117,7 @@ bool comm::Manager::Enable(Val* broker_endpoint_flags)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool comm::Manager::SetEndpointFlags(Val* broker_endpoint_flags)
|
||||
bool bro_broker::Manager::SetEndpointFlags(Val* broker_endpoint_flags)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
return false;
|
||||
|
@ -127,7 +127,7 @@ bool comm::Manager::SetEndpointFlags(Val* broker_endpoint_flags)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool comm::Manager::Listen(uint16_t port, const char* addr, bool reuse_addr)
|
||||
bool bro_broker::Manager::Listen(uint16_t port, const char* addr, bool reuse_addr)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
return false;
|
||||
|
@ -144,7 +144,7 @@ bool comm::Manager::Listen(uint16_t port, const char* addr, bool reuse_addr)
|
|||
return rval;
|
||||
}
|
||||
|
||||
bool comm::Manager::Connect(string addr, uint16_t port,
|
||||
bool bro_broker::Manager::Connect(string addr, uint16_t port,
|
||||
chrono::duration<double> retry_interval)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
|
@ -159,7 +159,7 @@ bool comm::Manager::Connect(string addr, uint16_t port,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool comm::Manager::Disconnect(const string& addr, uint16_t port)
|
||||
bool bro_broker::Manager::Disconnect(const string& addr, uint16_t port)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
return false;
|
||||
|
@ -174,7 +174,7 @@ bool comm::Manager::Disconnect(const string& addr, uint16_t port)
|
|||
return rval;
|
||||
}
|
||||
|
||||
bool comm::Manager::Print(string topic, string msg, Val* flags)
|
||||
bool bro_broker::Manager::Print(string topic, string msg, Val* flags)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
return false;
|
||||
|
@ -184,7 +184,7 @@ bool comm::Manager::Print(string topic, string msg, Val* flags)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool comm::Manager::Event(std::string topic, broker::message msg, int flags)
|
||||
bool bro_broker::Manager::Event(std::string topic, broker::message msg, int flags)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
return false;
|
||||
|
@ -193,7 +193,8 @@ bool comm::Manager::Event(std::string topic, broker::message msg, int flags)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool comm::Manager::Log(EnumVal* stream, RecordVal* columns, int flags)
|
||||
bool bro_broker::Manager::Log(EnumVal* stream, RecordVal* columns, RecordType* info,
|
||||
int flags)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
return false;
|
||||
|
@ -207,23 +208,44 @@ bool comm::Manager::Log(EnumVal* stream, RecordVal* columns, int flags)
|
|||
return false;
|
||||
}
|
||||
|
||||
auto opt_column_data = val_to_data(columns);
|
||||
broker::record column_data;
|
||||
|
||||
if ( ! opt_column_data )
|
||||
for ( auto i = 0u; i < static_cast<size_t>(info->NumFields()); ++i )
|
||||
{
|
||||
reporter->Error("Failed to remotely log stream %s: unsupported types",
|
||||
stream_name);
|
||||
return false;
|
||||
if ( ! info->FieldDecl(i)->FindAttr(ATTR_LOG) )
|
||||
continue;
|
||||
|
||||
auto field_val = columns->LookupWithDefault(i);
|
||||
|
||||
if ( ! field_val )
|
||||
{
|
||||
column_data.fields.emplace_back(broker::record::field{});
|
||||
continue;
|
||||
}
|
||||
|
||||
auto opt_field_data = val_to_data(field_val);
|
||||
Unref(field_val);
|
||||
|
||||
if ( ! opt_field_data )
|
||||
{
|
||||
reporter->Error("Failed to remotely log stream %s: "
|
||||
"unsupported type '%s'",
|
||||
stream_name,
|
||||
type_name(info->FieldDecl(i)->type->Tag()));
|
||||
return false;
|
||||
}
|
||||
|
||||
column_data.fields.emplace_back(
|
||||
broker::record::field{move(*opt_field_data)});
|
||||
}
|
||||
|
||||
broker::message msg{broker::enum_value{stream_name},
|
||||
move(*opt_column_data)};
|
||||
broker::message msg{broker::enum_value{stream_name}, move(column_data)};
|
||||
std::string topic = std::string("bro/log/") + stream_name;
|
||||
endpoint->send(move(topic), move(msg), flags);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool comm::Manager::Event(std::string topic, RecordVal* args, Val* flags)
|
||||
bool bro_broker::Manager::Event(std::string topic, RecordVal* args, Val* flags)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
return false;
|
||||
|
@ -248,14 +270,14 @@ bool comm::Manager::Event(std::string topic, RecordVal* args, Val* flags)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool comm::Manager::AutoEvent(string topic, Val* event, Val* flags)
|
||||
bool bro_broker::Manager::AutoEvent(string topic, Val* event, Val* flags)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
return false;
|
||||
|
||||
if ( event->Type()->Tag() != TYPE_FUNC )
|
||||
{
|
||||
reporter->Error("Comm::auto_event must operate on an event");
|
||||
reporter->Error("BrokerComm::auto_event must operate on an event");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -263,7 +285,7 @@ bool comm::Manager::AutoEvent(string topic, Val* event, Val* flags)
|
|||
|
||||
if ( event_val->Flavor() != FUNC_FLAVOR_EVENT )
|
||||
{
|
||||
reporter->Error("Comm::auto_event must operate on an event");
|
||||
reporter->Error("BrokerComm::auto_event must operate on an event");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -271,7 +293,7 @@ bool comm::Manager::AutoEvent(string topic, Val* event, Val* flags)
|
|||
|
||||
if ( ! handler )
|
||||
{
|
||||
reporter->Error("Comm::auto_event failed to lookup event '%s'",
|
||||
reporter->Error("BrokerComm::auto_event failed to lookup event '%s'",
|
||||
event_val->Name());
|
||||
return false;
|
||||
}
|
||||
|
@ -280,14 +302,14 @@ bool comm::Manager::AutoEvent(string topic, Val* event, Val* flags)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool comm::Manager::AutoEventStop(const string& topic, Val* event)
|
||||
bool bro_broker::Manager::AutoEventStop(const string& topic, Val* event)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
return false;
|
||||
|
||||
if ( event->Type()->Tag() != TYPE_FUNC )
|
||||
{
|
||||
reporter->Error("Comm::auto_event_stop must operate on an event");
|
||||
reporter->Error("BrokerComm::auto_event_stop must operate on an event");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -295,7 +317,7 @@ bool comm::Manager::AutoEventStop(const string& topic, Val* event)
|
|||
|
||||
if ( event_val->Flavor() != FUNC_FLAVOR_EVENT )
|
||||
{
|
||||
reporter->Error("Comm::auto_event_stop must operate on an event");
|
||||
reporter->Error("BrokerComm::auto_event_stop must operate on an event");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -303,7 +325,7 @@ bool comm::Manager::AutoEventStop(const string& topic, Val* event)
|
|||
|
||||
if ( ! handler )
|
||||
{
|
||||
reporter->Error("Comm::auto_event_stop failed to lookup event '%s'",
|
||||
reporter->Error("BrokerComm::auto_event_stop failed to lookup event '%s'",
|
||||
event_val->Name());
|
||||
return false;
|
||||
}
|
||||
|
@ -313,12 +335,12 @@ bool comm::Manager::AutoEventStop(const string& topic, Val* event)
|
|||
return true;
|
||||
}
|
||||
|
||||
RecordVal* comm::Manager::MakeEventArgs(val_list* args)
|
||||
RecordVal* bro_broker::Manager::MakeEventArgs(val_list* args)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
return nullptr;
|
||||
|
||||
auto rval = new RecordVal(BifType::Record::Comm::EventArgs);
|
||||
auto rval = new RecordVal(BifType::Record::BrokerComm::EventArgs);
|
||||
auto arg_vec = new VectorVal(vector_of_data_type);
|
||||
rval->Assign(1, arg_vec);
|
||||
Func* func = 0;
|
||||
|
@ -333,7 +355,7 @@ RecordVal* comm::Manager::MakeEventArgs(val_list* args)
|
|||
|
||||
if ( arg_val->Type()->Tag() != TYPE_FUNC )
|
||||
{
|
||||
reporter->Error("1st param of Comm::event_args must be event");
|
||||
reporter->Error("1st param of BrokerComm::event_args must be event");
|
||||
return rval;
|
||||
}
|
||||
|
||||
|
@ -341,7 +363,7 @@ RecordVal* comm::Manager::MakeEventArgs(val_list* args)
|
|||
|
||||
if ( func->Flavor() != FUNC_FLAVOR_EVENT )
|
||||
{
|
||||
reporter->Error("1st param of Comm::event_args must be event");
|
||||
reporter->Error("1st param of BrokerComm::event_args must be event");
|
||||
return rval;
|
||||
}
|
||||
|
||||
|
@ -349,7 +371,7 @@ RecordVal* comm::Manager::MakeEventArgs(val_list* args)
|
|||
|
||||
if ( num_args != args->length() - 1 )
|
||||
{
|
||||
reporter->Error("bad # of Comm::event_args: got %d, expect %d",
|
||||
reporter->Error("bad # of BrokerComm::event_args: got %d, expect %d",
|
||||
args->length(), num_args + 1);
|
||||
return rval;
|
||||
}
|
||||
|
@ -363,7 +385,7 @@ RecordVal* comm::Manager::MakeEventArgs(val_list* args)
|
|||
if ( ! same_type((*args)[i]->Type(), expected_type) )
|
||||
{
|
||||
rval->Assign(0, 0);
|
||||
reporter->Error("Comm::event_args param %d type mismatch", i);
|
||||
reporter->Error("BrokerComm::event_args param %d type mismatch", i);
|
||||
return rval;
|
||||
}
|
||||
|
||||
|
@ -373,7 +395,7 @@ RecordVal* comm::Manager::MakeEventArgs(val_list* args)
|
|||
{
|
||||
Unref(data_val);
|
||||
rval->Assign(0, 0);
|
||||
reporter->Error("Comm::event_args unsupported event/params");
|
||||
reporter->Error("BrokerComm::event_args unsupported event/params");
|
||||
return rval;
|
||||
}
|
||||
|
||||
|
@ -383,7 +405,7 @@ RecordVal* comm::Manager::MakeEventArgs(val_list* args)
|
|||
return rval;
|
||||
}
|
||||
|
||||
bool comm::Manager::SubscribeToPrints(string topic_prefix)
|
||||
bool bro_broker::Manager::SubscribeToPrints(string topic_prefix)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
return false;
|
||||
|
@ -397,7 +419,7 @@ bool comm::Manager::SubscribeToPrints(string topic_prefix)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool comm::Manager::UnsubscribeToPrints(const string& topic_prefix)
|
||||
bool bro_broker::Manager::UnsubscribeToPrints(const string& topic_prefix)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
return false;
|
||||
|
@ -405,7 +427,7 @@ bool comm::Manager::UnsubscribeToPrints(const string& topic_prefix)
|
|||
return print_subscriptions.erase(topic_prefix);
|
||||
}
|
||||
|
||||
bool comm::Manager::SubscribeToEvents(string topic_prefix)
|
||||
bool bro_broker::Manager::SubscribeToEvents(string topic_prefix)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
return false;
|
||||
|
@ -419,7 +441,7 @@ bool comm::Manager::SubscribeToEvents(string topic_prefix)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool comm::Manager::UnsubscribeToEvents(const string& topic_prefix)
|
||||
bool bro_broker::Manager::UnsubscribeToEvents(const string& topic_prefix)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
return false;
|
||||
|
@ -427,7 +449,7 @@ bool comm::Manager::UnsubscribeToEvents(const string& topic_prefix)
|
|||
return event_subscriptions.erase(topic_prefix);
|
||||
}
|
||||
|
||||
bool comm::Manager::SubscribeToLogs(string topic_prefix)
|
||||
bool bro_broker::Manager::SubscribeToLogs(string topic_prefix)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
return false;
|
||||
|
@ -441,7 +463,7 @@ bool comm::Manager::SubscribeToLogs(string topic_prefix)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool comm::Manager::UnsubscribeToLogs(const string& topic_prefix)
|
||||
bool bro_broker::Manager::UnsubscribeToLogs(const string& topic_prefix)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
return false;
|
||||
|
@ -449,7 +471,7 @@ bool comm::Manager::UnsubscribeToLogs(const string& topic_prefix)
|
|||
return log_subscriptions.erase(topic_prefix);
|
||||
}
|
||||
|
||||
bool comm::Manager::PublishTopic(broker::topic t)
|
||||
bool bro_broker::Manager::PublishTopic(broker::topic t)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
return false;
|
||||
|
@ -458,7 +480,7 @@ bool comm::Manager::PublishTopic(broker::topic t)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool comm::Manager::UnpublishTopic(broker::topic t)
|
||||
bool bro_broker::Manager::UnpublishTopic(broker::topic t)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
return false;
|
||||
|
@ -467,7 +489,7 @@ bool comm::Manager::UnpublishTopic(broker::topic t)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool comm::Manager::AdvertiseTopic(broker::topic t)
|
||||
bool bro_broker::Manager::AdvertiseTopic(broker::topic t)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
return false;
|
||||
|
@ -476,7 +498,7 @@ bool comm::Manager::AdvertiseTopic(broker::topic t)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool comm::Manager::UnadvertiseTopic(broker::topic t)
|
||||
bool bro_broker::Manager::UnadvertiseTopic(broker::topic t)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
return false;
|
||||
|
@ -485,7 +507,7 @@ bool comm::Manager::UnadvertiseTopic(broker::topic t)
|
|||
return true;
|
||||
}
|
||||
|
||||
int comm::Manager::send_flags_to_int(Val* flags)
|
||||
int bro_broker::Manager::send_flags_to_int(Val* flags)
|
||||
{
|
||||
auto r = flags->AsRecordVal();
|
||||
int rval = 0;
|
||||
|
@ -508,7 +530,7 @@ int comm::Manager::send_flags_to_int(Val* flags)
|
|||
return rval;
|
||||
}
|
||||
|
||||
void comm::Manager::GetFds(iosource::FD_Set* read, iosource::FD_Set* write,
|
||||
void bro_broker::Manager::GetFds(iosource::FD_Set* read, iosource::FD_Set* write,
|
||||
iosource::FD_Set* except)
|
||||
{
|
||||
read->Insert(endpoint->outgoing_connection_status().fd());
|
||||
|
@ -529,7 +551,7 @@ void comm::Manager::GetFds(iosource::FD_Set* read, iosource::FD_Set* write,
|
|||
read->Insert(broker::report::default_queue->fd());
|
||||
}
|
||||
|
||||
double comm::Manager::NextTimestamp(double* local_network_time)
|
||||
double bro_broker::Manager::NextTimestamp(double* local_network_time)
|
||||
{
|
||||
// TODO: do something better?
|
||||
return timer_mgr->Time();
|
||||
|
@ -547,25 +569,25 @@ struct response_converter {
|
|||
case broker::store::query::tag::lookup:
|
||||
// A boolean result means the key doesn't exist (if it did, then
|
||||
// the result would contain the broker::data value, not a bool).
|
||||
return new RecordVal(BifType::Record::Comm::Data);
|
||||
return new RecordVal(BifType::Record::BrokerComm::Data);
|
||||
default:
|
||||
return comm::make_data_val(broker::data{d});
|
||||
return bro_broker::make_data_val(broker::data{d});
|
||||
}
|
||||
}
|
||||
|
||||
result_type operator()(uint64_t d)
|
||||
{
|
||||
return comm::make_data_val(broker::data{d});
|
||||
return bro_broker::make_data_val(broker::data{d});
|
||||
}
|
||||
|
||||
result_type operator()(broker::data& d)
|
||||
{
|
||||
return comm::make_data_val(move(d));
|
||||
return bro_broker::make_data_val(move(d));
|
||||
}
|
||||
|
||||
result_type operator()(std::vector<broker::data>& d)
|
||||
{
|
||||
return comm::make_data_val(broker::data{move(d)});
|
||||
return bro_broker::make_data_val(broker::data{move(d)});
|
||||
}
|
||||
|
||||
result_type operator()(broker::store::snapshot& d)
|
||||
|
@ -579,7 +601,7 @@ struct response_converter {
|
|||
table[move(key)] = move(val);
|
||||
}
|
||||
|
||||
return comm::make_data_val(broker::data{move(table)});
|
||||
return bro_broker::make_data_val(broker::data{move(table)});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -588,7 +610,7 @@ static RecordVal* response_to_val(broker::store::response r)
|
|||
return broker::visit(response_converter{r.request.type}, r.reply.value);
|
||||
}
|
||||
|
||||
void comm::Manager::Process()
|
||||
void bro_broker::Manager::Process()
|
||||
{
|
||||
bool idle = true;
|
||||
auto outgoing_connection_updates =
|
||||
|
@ -605,36 +627,36 @@ void comm::Manager::Process()
|
|||
|
||||
switch ( u.status ) {
|
||||
case broker::outgoing_connection_status::tag::established:
|
||||
if ( Comm::outgoing_connection_established )
|
||||
if ( BrokerComm::outgoing_connection_established )
|
||||
{
|
||||
val_list* vl = new val_list;
|
||||
vl->append(new StringVal(u.relation.remote_tuple().first));
|
||||
vl->append(new PortVal(u.relation.remote_tuple().second,
|
||||
TRANSPORT_TCP));
|
||||
vl->append(new StringVal(u.peer_name));
|
||||
mgr.QueueEvent(Comm::outgoing_connection_established, vl);
|
||||
mgr.QueueEvent(BrokerComm::outgoing_connection_established, vl);
|
||||
}
|
||||
break;
|
||||
|
||||
case broker::outgoing_connection_status::tag::disconnected:
|
||||
if ( Comm::outgoing_connection_broken )
|
||||
if ( BrokerComm::outgoing_connection_broken )
|
||||
{
|
||||
val_list* vl = new val_list;
|
||||
vl->append(new StringVal(u.relation.remote_tuple().first));
|
||||
vl->append(new PortVal(u.relation.remote_tuple().second,
|
||||
TRANSPORT_TCP));
|
||||
mgr.QueueEvent(Comm::outgoing_connection_broken, vl);
|
||||
mgr.QueueEvent(BrokerComm::outgoing_connection_broken, vl);
|
||||
}
|
||||
break;
|
||||
|
||||
case broker::outgoing_connection_status::tag::incompatible:
|
||||
if ( Comm::outgoing_connection_incompatible )
|
||||
if ( BrokerComm::outgoing_connection_incompatible )
|
||||
{
|
||||
val_list* vl = new val_list;
|
||||
vl->append(new StringVal(u.relation.remote_tuple().first));
|
||||
vl->append(new PortVal(u.relation.remote_tuple().second,
|
||||
TRANSPORT_TCP));
|
||||
mgr.QueueEvent(Comm::outgoing_connection_incompatible, vl);
|
||||
mgr.QueueEvent(BrokerComm::outgoing_connection_incompatible, vl);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -652,20 +674,20 @@ void comm::Manager::Process()
|
|||
|
||||
switch ( u.status ) {
|
||||
case broker::incoming_connection_status::tag::established:
|
||||
if ( Comm::incoming_connection_established )
|
||||
if ( BrokerComm::incoming_connection_established )
|
||||
{
|
||||
val_list* vl = new val_list;
|
||||
vl->append(new StringVal(u.peer_name));
|
||||
mgr.QueueEvent(Comm::incoming_connection_established, vl);
|
||||
mgr.QueueEvent(BrokerComm::incoming_connection_established, vl);
|
||||
}
|
||||
break;
|
||||
|
||||
case broker::incoming_connection_status::tag::disconnected:
|
||||
if ( Comm::incoming_connection_broken )
|
||||
if ( BrokerComm::incoming_connection_broken )
|
||||
{
|
||||
val_list* vl = new val_list;
|
||||
vl->append(new StringVal(u.peer_name));
|
||||
mgr.QueueEvent(Comm::incoming_connection_broken, vl);
|
||||
mgr.QueueEvent(BrokerComm::incoming_connection_broken, vl);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -687,7 +709,7 @@ void comm::Manager::Process()
|
|||
ps.second.received += print_messages.size();
|
||||
idle = false;
|
||||
|
||||
if ( ! Comm::print_handler )
|
||||
if ( ! BrokerComm::print_handler )
|
||||
continue;
|
||||
|
||||
for ( auto& pm : print_messages )
|
||||
|
@ -710,7 +732,7 @@ void comm::Manager::Process()
|
|||
|
||||
val_list* vl = new val_list;
|
||||
vl->append(new StringVal(move(*msg)));
|
||||
mgr.QueueEvent(Comm::print_handler, vl);
|
||||
mgr.QueueEvent(BrokerComm::print_handler, vl);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -837,7 +859,7 @@ void comm::Manager::Process()
|
|||
continue;
|
||||
}
|
||||
|
||||
auto columns = data_to_val(move(lm[1]), columns_type);
|
||||
auto columns = data_to_val(move(lm[1]), columns_type, true);
|
||||
|
||||
if ( ! columns )
|
||||
{
|
||||
|
@ -953,7 +975,7 @@ void comm::Manager::Process()
|
|||
SetIdle(idle);
|
||||
}
|
||||
|
||||
bool comm::Manager::AddStore(StoreHandleVal* handle)
|
||||
bool bro_broker::Manager::AddStore(StoreHandleVal* handle)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
return false;
|
||||
|
@ -971,9 +993,9 @@ bool comm::Manager::AddStore(StoreHandleVal* handle)
|
|||
return true;
|
||||
}
|
||||
|
||||
comm::StoreHandleVal*
|
||||
comm::Manager::LookupStore(const broker::store::identifier& id,
|
||||
comm::StoreType type)
|
||||
bro_broker::StoreHandleVal*
|
||||
bro_broker::Manager::LookupStore(const broker::store::identifier& id,
|
||||
bro_broker::StoreType type)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
return nullptr;
|
||||
|
@ -987,7 +1009,7 @@ comm::Manager::LookupStore(const broker::store::identifier& id,
|
|||
return it->second;
|
||||
}
|
||||
|
||||
bool comm::Manager::CloseStore(const broker::store::identifier& id,
|
||||
bool bro_broker::Manager::CloseStore(const broker::store::identifier& id,
|
||||
StoreType type)
|
||||
{
|
||||
if ( ! Enabled() )
|
||||
|
@ -1019,13 +1041,13 @@ bool comm::Manager::CloseStore(const broker::store::identifier& id,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool comm::Manager::TrackStoreQuery(StoreQueryCallback* cb)
|
||||
bool bro_broker::Manager::TrackStoreQuery(StoreQueryCallback* cb)
|
||||
{
|
||||
assert(Enabled());
|
||||
return pending_queries.insert(cb).second;
|
||||
}
|
||||
|
||||
comm::Stats comm::Manager::ConsumeStatistics()
|
||||
bro_broker::Stats bro_broker::Manager::ConsumeStatistics()
|
||||
{
|
||||
statistics.outgoing_peer_count = peers.size();
|
||||
statistics.data_store_count = data_stores.size();
|
|
@ -7,16 +7,16 @@
|
|||
#include <string>
|
||||
#include <map>
|
||||
#include <unordered_set>
|
||||
#include "comm/Store.h"
|
||||
#include "broker/Store.h"
|
||||
#include "Reporter.h"
|
||||
#include "iosource/IOSource.h"
|
||||
#include "Val.h"
|
||||
|
||||
namespace comm {
|
||||
namespace bro_broker {
|
||||
|
||||
/**
|
||||
* Communication statistics. Some are tracked in relation to last
|
||||
* sample (comm::Manager::ConsumeStatistics()).
|
||||
* sample (bro_broker::Manager::ConsumeStatistics()).
|
||||
*/
|
||||
struct Stats {
|
||||
// Number of outgoing peer connections (at time of sample).
|
||||
|
@ -58,20 +58,20 @@ public:
|
|||
/**
|
||||
* Enable use of communication.
|
||||
* @param flags used to tune the local Broker endpoint's behavior.
|
||||
* See the Comm::EndpointFlags record type.
|
||||
* See the BrokerComm::EndpointFlags record type.
|
||||
* @return true if communication is successfully initialized.
|
||||
*/
|
||||
bool Enable(Val* flags);
|
||||
|
||||
/**
|
||||
* Changes endpoint flags originally supplied to comm::Manager::Enable().
|
||||
* Changes endpoint flags originally supplied to bro_broker::Manager::Enable().
|
||||
* @param flags the new behavior flags to use.
|
||||
* @return true if flags were changed.
|
||||
*/
|
||||
bool SetEndpointFlags(Val* flags);
|
||||
|
||||
/**
|
||||
* @return true if comm::Manager::Enable() has previously been called and
|
||||
* @return true if bro_broker::Manager::Enable() has previously been called and
|
||||
* it succeeded.
|
||||
*/
|
||||
bool Enabled()
|
||||
|
@ -103,10 +103,10 @@ public:
|
|||
|
||||
/**
|
||||
* Remove a remote connection.
|
||||
* @param addr the address used in comm::Manager::Connect().
|
||||
* @param port the port used in comm::Manager::Connect().
|
||||
* @param addr the address used in bro_broker::Manager::Connect().
|
||||
* @param port the port used in bro_broker::Manager::Connect().
|
||||
* @return true if the arguments match a previously successful call to
|
||||
* comm::Manager::Connect().
|
||||
* bro_broker::Manager::Connect().
|
||||
*/
|
||||
bool Disconnect(const std::string& addr, uint16_t port);
|
||||
|
||||
|
@ -117,7 +117,7 @@ public:
|
|||
* of this topic name.
|
||||
* @param msg the string to send to peers.
|
||||
* @param flags tune the behavior of how the message is send.
|
||||
* See the Comm::SendFlags record type.
|
||||
* See the BrokerComm::SendFlags record type.
|
||||
* @return true if the message is sent successfully.
|
||||
*/
|
||||
bool Print(std::string topic, std::string msg, Val* flags);
|
||||
|
@ -130,7 +130,7 @@ public:
|
|||
* @param msg the event to send to peers, which is the name of the event
|
||||
* as a string followed by all of its arguments.
|
||||
* @param flags tune the behavior of how the message is send.
|
||||
* See the Comm::SendFlags record type.
|
||||
* See the BrokerComm::SendFlags record type.
|
||||
* @return true if the message is sent successfully.
|
||||
*/
|
||||
bool Event(std::string topic, broker::message msg, int flags);
|
||||
|
@ -141,9 +141,9 @@ public:
|
|||
* Peers advertise interest by registering a subscription to some prefix
|
||||
* of this topic name.
|
||||
* @param args the event and its arguments to send to peers. See the
|
||||
* Comm::EventArgs record type.
|
||||
* BrokerComm::EventArgs record type.
|
||||
* @param flags tune the behavior of how the message is send.
|
||||
* See the Comm::SendFlags record type.
|
||||
* See the BrokerComm::SendFlags record type.
|
||||
* @return true if the message is sent successfully.
|
||||
*/
|
||||
bool Event(std::string topic, RecordVal* args, Val* flags);
|
||||
|
@ -153,11 +153,13 @@ public:
|
|||
* implicitly "bro/log/<stream-name>".
|
||||
* @param stream_id the stream to which the log entry belongs.
|
||||
* @param columns the data which comprises the log entry.
|
||||
* @param info the record type corresponding to the log's columns.
|
||||
* @param flags tune the behavior of how the message is send.
|
||||
* See the Comm::SendFlags record type.
|
||||
* See the BrokerComm::SendFlags record type.
|
||||
* @return true if the message is sent successfully.
|
||||
*/
|
||||
bool Log(EnumVal* stream_id, RecordVal* columns, int flags);
|
||||
bool Log(EnumVal* stream_id, RecordVal* columns, RecordType* info,
|
||||
int flags);
|
||||
|
||||
/**
|
||||
* Automatically send an event to any interested peers whenever it is
|
||||
|
@ -167,15 +169,15 @@ public:
|
|||
* of this topic name.
|
||||
* @param event a Bro event value.
|
||||
* @param flags tune the behavior of how the message is send.
|
||||
* See the Comm::SendFlags record type.
|
||||
* See the BrokerComm::SendFlags record type.
|
||||
* @return true if automatic event sending is now enabled.
|
||||
*/
|
||||
bool AutoEvent(std::string topic, Val* event, Val* flags);
|
||||
|
||||
/**
|
||||
* Stop automatically sending an event to peers upon local dispatch.
|
||||
* @param topic a topic originally given to comm::Manager::AutoEvent().
|
||||
* @param event an event originally given to comm::Manager::AutoEvent().
|
||||
* @param topic a topic originally given to bro_broker::Manager::AutoEvent().
|
||||
* @param event an event originally given to bro_broker::Manager::AutoEvent().
|
||||
* @return true if automatic events will no occur for the topic/event pair.
|
||||
*/
|
||||
bool AutoEventStop(const std::string& topic, Val* event);
|
||||
|
@ -201,7 +203,7 @@ public:
|
|||
/**
|
||||
* Unregister interest in peer print messages.
|
||||
* @param topic_prefix a prefix previously supplied to a successful call
|
||||
* to comm::Manager::SubscribeToPrints().
|
||||
* to bro_broker::Manager::SubscribeToPrints().
|
||||
* @return true if interest in topic prefix is no longer advertised.
|
||||
*/
|
||||
bool UnsubscribeToPrints(const std::string& topic_prefix);
|
||||
|
@ -218,7 +220,7 @@ public:
|
|||
/**
|
||||
* Unregister interest in peer event messages.
|
||||
* @param topic_prefix a prefix previously supplied to a successful call
|
||||
* to comm::Manager::SubscribeToEvents().
|
||||
* to bro_broker::Manager::SubscribeToEvents().
|
||||
* @return true if interest in topic prefix is no longer advertised.
|
||||
*/
|
||||
bool UnsubscribeToEvents(const std::string& topic_prefix);
|
||||
|
@ -235,7 +237,7 @@ public:
|
|||
/**
|
||||
* Unregister interest in peer log messages.
|
||||
* @param topic_prefix a prefix previously supplied to a successful call
|
||||
* to comm::Manager::SubscribeToLogs().
|
||||
* to bro_broker::Manager::SubscribeToLogs().
|
||||
* @return true if interest in topic prefix is no longer advertised.
|
||||
*/
|
||||
bool UnsubscribeToLogs(const std::string& topic_prefix);
|
||||
|
@ -243,7 +245,7 @@ public:
|
|||
/**
|
||||
* Allow sending messages to peers if associated with the given topic.
|
||||
* This has no effect if auto publication behavior is enabled via the flags
|
||||
* supplied to comm::Manager::Enable() or comm::Manager::SetEndpointFlags().
|
||||
* supplied to bro_broker::Manager::Enable() or bro_broker::Manager::SetEndpointFlags().
|
||||
* @param t a topic to allow messages to be published under.
|
||||
* @return true if successful.
|
||||
*/
|
||||
|
@ -252,7 +254,7 @@ public:
|
|||
/**
|
||||
* Disallow sending messages to peers if associated with the given topic.
|
||||
* This has no effect if auto publication behavior is enabled via the flags
|
||||
* supplied to comm::Manager::Enable() or comm::Manager::SetEndpointFlags().
|
||||
* supplied to bro_broker::Manager::Enable() or bro_broker::Manager::SetEndpointFlags().
|
||||
* @param t a topic to disallow messages to be published under.
|
||||
* @return true if successful.
|
||||
*/
|
||||
|
@ -261,7 +263,7 @@ public:
|
|||
/**
|
||||
* Allow advertising interest in the given topic to peers.
|
||||
* This has no effect if auto advertise behavior is enabled via the flags
|
||||
* supplied to comm::Manager::Enable() or comm::Manager::SetEndpointFlags().
|
||||
* supplied to bro_broker::Manager::Enable() or bro_broker::Manager::SetEndpointFlags().
|
||||
* @param t a topic to allow advertising interest/subscription to peers.
|
||||
* @return true if successful.
|
||||
*/
|
||||
|
@ -270,7 +272,7 @@ public:
|
|||
/**
|
||||
* Disallow advertising interest in the given topic to peers.
|
||||
* This has no effect if auto advertise behavior is enabled via the flags
|
||||
* supplied to comm::Manager::Enable() or comm::Manager::SetEndpointFlags().
|
||||
* supplied to bro_broker::Manager::Enable() or bro_broker::Manager::SetEndpointFlags().
|
||||
* @param t a topic to disallow advertising interest/subscription to peers.
|
||||
* @return true if successful.
|
||||
*/
|
||||
|
@ -313,7 +315,7 @@ public:
|
|||
Stats ConsumeStatistics();
|
||||
|
||||
/**
|
||||
* Convert Comm::SendFlags to int flags for use with broker::send().
|
||||
* Convert BrokerComm::SendFlags to int flags for use with broker::send().
|
||||
*/
|
||||
static int send_flags_to_int(Val* flags);
|
||||
|
||||
|
@ -328,7 +330,7 @@ private:
|
|||
void Process() override;
|
||||
|
||||
const char* Tag() override
|
||||
{ return "Comm::Manager"; }
|
||||
{ return "BrokerComm::Manager"; }
|
||||
|
||||
broker::endpoint& Endpoint()
|
||||
{ return *endpoint; }
|
||||
|
@ -357,8 +359,8 @@ private:
|
|||
static int send_flags_unsolicited_idx;
|
||||
};
|
||||
|
||||
} // namespace comm
|
||||
} // namespace bro_broker
|
||||
|
||||
extern comm::Manager* comm_mgr;
|
||||
extern bro_broker::Manager* broker_mgr;
|
||||
|
||||
#endif // BRO_COMM_MANAGER_H
|
|
@ -1,5 +1,5 @@
|
|||
#include "Store.h"
|
||||
#include "comm/Manager.h"
|
||||
#include "broker/Manager.h"
|
||||
|
||||
#include <broker/store/master.hh>
|
||||
#include <broker/store/clone.hh>
|
||||
|
@ -10,16 +10,16 @@
|
|||
#include <rocksdb/db.h>
|
||||
#endif
|
||||
|
||||
OpaqueType* comm::opaque_of_store_handle;
|
||||
OpaqueType* bro_broker::opaque_of_store_handle;
|
||||
|
||||
comm::StoreHandleVal::StoreHandleVal(broker::store::identifier id,
|
||||
comm::StoreType arg_type,
|
||||
broker::util::optional<BifEnum::Store::BackendType> arg_back,
|
||||
bro_broker::StoreHandleVal::StoreHandleVal(broker::store::identifier id,
|
||||
bro_broker::StoreType arg_type,
|
||||
broker::util::optional<BifEnum::BrokerStore::BackendType> arg_back,
|
||||
RecordVal* backend_options, std::chrono::duration<double> resync)
|
||||
: OpaqueVal(opaque_of_store_handle),
|
||||
store(), store_type(arg_type), backend_type(arg_back)
|
||||
{
|
||||
using BifEnum::Store::BackendType;
|
||||
using BifEnum::BrokerStore::BackendType;
|
||||
std::unique_ptr<broker::store::backend> backend;
|
||||
|
||||
if ( backend_type )
|
||||
|
@ -73,14 +73,14 @@ comm::StoreHandleVal::StoreHandleVal(broker::store::identifier id,
|
|||
|
||||
switch ( store_type ) {
|
||||
case StoreType::FRONTEND:
|
||||
store = new broker::store::frontend(comm_mgr->Endpoint(), move(id));
|
||||
store = new broker::store::frontend(broker_mgr->Endpoint(), move(id));
|
||||
break;
|
||||
case StoreType::MASTER:
|
||||
store = new broker::store::master(comm_mgr->Endpoint(), move(id),
|
||||
store = new broker::store::master(broker_mgr->Endpoint(), move(id),
|
||||
move(backend));
|
||||
break;
|
||||
case StoreType::CLONE:
|
||||
store = new broker::store::clone(comm_mgr->Endpoint(), move(id), resync,
|
||||
store = new broker::store::clone(broker_mgr->Endpoint(), move(id), resync,
|
||||
move(backend));
|
||||
break;
|
||||
default:
|
||||
|
@ -89,9 +89,9 @@ comm::StoreHandleVal::StoreHandleVal(broker::store::identifier id,
|
|||
}
|
||||
}
|
||||
|
||||
void comm::StoreHandleVal::ValDescribe(ODesc* d) const
|
||||
void bro_broker::StoreHandleVal::ValDescribe(ODesc* d) const
|
||||
{
|
||||
using BifEnum::Store::BackendType;
|
||||
using BifEnum::BrokerStore::BackendType;
|
||||
d->Add("broker::store::");
|
||||
|
||||
switch ( store_type ) {
|
||||
|
@ -133,9 +133,9 @@ void comm::StoreHandleVal::ValDescribe(ODesc* d) const
|
|||
d->Add("}");
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(comm::StoreHandleVal, SER_COMM_STORE_HANDLE_VAL);
|
||||
IMPLEMENT_SERIAL(bro_broker::StoreHandleVal, SER_COMM_STORE_HANDLE_VAL);
|
||||
|
||||
bool comm::StoreHandleVal::DoSerialize(SerialInfo* info) const
|
||||
bool bro_broker::StoreHandleVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_COMM_STORE_HANDLE_VAL, OpaqueVal);
|
||||
|
||||
|
@ -156,7 +156,7 @@ bool comm::StoreHandleVal::DoSerialize(SerialInfo* info) const
|
|||
return true;
|
||||
}
|
||||
|
||||
bool comm::StoreHandleVal::DoUnserialize(UnserialInfo* info)
|
||||
bool bro_broker::StoreHandleVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(OpaqueVal);
|
||||
|
||||
|
@ -185,7 +185,7 @@ bool comm::StoreHandleVal::DoUnserialize(UnserialInfo* info)
|
|||
broker::store::identifier id(id_str, len);
|
||||
delete [] id_str;
|
||||
|
||||
auto handle = comm_mgr->LookupStore(id, static_cast<comm::StoreType>(type));
|
||||
auto handle = broker_mgr->LookupStore(id, static_cast<bro_broker::StoreType>(type));
|
||||
|
||||
if ( ! handle )
|
||||
{
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef BRO_COMM_STORE_H
|
||||
#define BRO_COMM_STORE_H
|
||||
|
||||
#include "comm/store.bif.h"
|
||||
#include "comm/data.bif.h"
|
||||
#include "broker/store.bif.h"
|
||||
#include "broker/data.bif.h"
|
||||
#include "Reporter.h"
|
||||
#include "Type.h"
|
||||
#include "Val.h"
|
||||
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include <broker/store/frontend.hh>
|
||||
|
||||
namespace comm {
|
||||
namespace bro_broker {
|
||||
|
||||
extern OpaqueType* opaque_of_store_handle;
|
||||
|
||||
|
@ -25,9 +25,9 @@ enum StoreType {
|
|||
};
|
||||
|
||||
/**
|
||||
* Create a Store::QueryStatus value.
|
||||
* Create a BrokerStore::QueryStatus value.
|
||||
* @param success whether the query status should be set to success or failure.
|
||||
* @return a Store::QueryStatus value.
|
||||
* @return a BrokerStore::QueryStatus value.
|
||||
*/
|
||||
inline EnumVal* query_status(bool success)
|
||||
{
|
||||
|
@ -37,34 +37,34 @@ inline EnumVal* query_status(bool success)
|
|||
|
||||
if ( ! store_query_status )
|
||||
{
|
||||
store_query_status = internal_type("Store::QueryStatus")->AsEnumType();
|
||||
success_val = store_query_status->Lookup("Store", "SUCCESS");
|
||||
failure_val = store_query_status->Lookup("Store", "FAILURE");
|
||||
store_query_status = internal_type("BrokerStore::QueryStatus")->AsEnumType();
|
||||
success_val = store_query_status->Lookup("BrokerStore", "SUCCESS");
|
||||
failure_val = store_query_status->Lookup("BrokerStore", "FAILURE");
|
||||
}
|
||||
|
||||
return new EnumVal(success ? success_val : failure_val, store_query_status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a Store::QueryResult value that has a Store::QueryStatus indicating
|
||||
* @return a BrokerStore::QueryResult value that has a BrokerStore::QueryStatus indicating
|
||||
* a failure.
|
||||
*/
|
||||
inline RecordVal* query_result()
|
||||
{
|
||||
auto rval = new RecordVal(BifType::Record::Store::QueryResult);
|
||||
auto rval = new RecordVal(BifType::Record::BrokerStore::QueryResult);
|
||||
rval->Assign(0, query_status(false));
|
||||
rval->Assign(1, new RecordVal(BifType::Record::Comm::Data));
|
||||
rval->Assign(1, new RecordVal(BifType::Record::BrokerComm::Data));
|
||||
return rval;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param data the result of the query.
|
||||
* @return a Store::QueryResult value that has a Store::QueryStatus indicating
|
||||
* @return a BrokerStore::QueryResult value that has a BrokerStore::QueryStatus indicating
|
||||
* a success.
|
||||
*/
|
||||
inline RecordVal* query_result(RecordVal* data)
|
||||
{
|
||||
auto rval = new RecordVal(BifType::Record::Store::QueryResult);
|
||||
auto rval = new RecordVal(BifType::Record::BrokerStore::QueryResult);
|
||||
rval->Assign(0, query_status(true));
|
||||
rval->Assign(1, data);
|
||||
return rval;
|
||||
|
@ -129,8 +129,8 @@ class StoreHandleVal : public OpaqueVal {
|
|||
public:
|
||||
|
||||
StoreHandleVal(broker::store::identifier id,
|
||||
comm::StoreType arg_type,
|
||||
broker::util::optional<BifEnum::Store::BackendType> arg_back,
|
||||
bro_broker::StoreType arg_type,
|
||||
broker::util::optional<BifEnum::BrokerStore::BackendType> arg_back,
|
||||
RecordVal* backend_options,
|
||||
std::chrono::duration<double> resync = std::chrono::seconds(1));
|
||||
|
||||
|
@ -139,8 +139,8 @@ public:
|
|||
DECLARE_SERIAL(StoreHandleVal);
|
||||
|
||||
broker::store::frontend* store;
|
||||
comm::StoreType store_type;
|
||||
broker::util::optional<BifEnum::Store::BackendType> backend_type;
|
||||
bro_broker::StoreType store_type;
|
||||
broker::util::optional<BifEnum::BrokerStore::BackendType> backend_type;
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -148,6 +148,6 @@ protected:
|
|||
{}
|
||||
};
|
||||
|
||||
} // namespace comm
|
||||
} // namespace bro_broker
|
||||
|
||||
#endif // BRO_COMM_STORE_H
|
|
@ -2,127 +2,127 @@
|
|||
##! General functions regarding Bro's broker communication mechanisms.
|
||||
|
||||
%%{
|
||||
#include "comm/Manager.h"
|
||||
#include "broker/Manager.h"
|
||||
%%}
|
||||
|
||||
module Comm;
|
||||
module BrokerComm;
|
||||
|
||||
type Comm::EndpointFlags: record;
|
||||
type BrokerComm::EndpointFlags: record;
|
||||
|
||||
## Enable use of communication.
|
||||
##
|
||||
## flags: used to tune the local Broker endpoint behavior.
|
||||
##
|
||||
## Returns: true if communication is successfully initialized.
|
||||
function Comm::enable%(flags: EndpointFlags &default = EndpointFlags()%): bool
|
||||
function BrokerComm::enable%(flags: EndpointFlags &default = EndpointFlags()%): bool
|
||||
%{
|
||||
return new Val(comm_mgr->Enable(flags), TYPE_BOOL);
|
||||
return new Val(broker_mgr->Enable(flags), TYPE_BOOL);
|
||||
%}
|
||||
|
||||
## Changes endpoint flags originally supplied to :bro:see:`Comm::enable`.
|
||||
## Changes endpoint flags originally supplied to :bro:see:`BrokerComm::enable`.
|
||||
##
|
||||
## flags: the new endpoint behavior flags to use.
|
||||
##
|
||||
## Returns: true of flags were changed.
|
||||
function Comm::set_endpoint_flags%(flags: EndpointFlags &default = EndpointFlags()%): bool
|
||||
function BrokerComm::set_endpoint_flags%(flags: EndpointFlags &default = EndpointFlags()%): bool
|
||||
%{
|
||||
return new Val(comm_mgr->SetEndpointFlags(flags), TYPE_BOOL);
|
||||
return new Val(broker_mgr->SetEndpointFlags(flags), TYPE_BOOL);
|
||||
%}
|
||||
|
||||
## Allow sending messages to peers if associated with the given topic.
|
||||
## This has no effect if auto publication behavior is enabled via the flags
|
||||
## supplied to :bro:see:`Comm::enable` or :bro:see:`Comm::set_endpoint_flags`.
|
||||
## supplied to :bro:see:`BrokerComm::enable` or :bro:see:`BrokerComm::set_endpoint_flags`.
|
||||
##
|
||||
## topic: a topic to allow messages to be published under.
|
||||
##
|
||||
## Returns: true if successful.
|
||||
function Comm::publish_topic%(topic: string%): bool
|
||||
function BrokerComm::publish_topic%(topic: string%): bool
|
||||
%{
|
||||
return new Val(comm_mgr->PublishTopic(topic->CheckString()), TYPE_BOOL);
|
||||
return new Val(broker_mgr->PublishTopic(topic->CheckString()), TYPE_BOOL);
|
||||
%}
|
||||
|
||||
## Disallow sending messages to peers if associated with the given topic.
|
||||
## This has no effect if auto publication behavior is enabled via the flags
|
||||
## supplied to :bro:see:`Comm::enable` or :bro:see:`Comm::set_endpoint_flags`.
|
||||
## supplied to :bro:see:`BrokerComm::enable` or :bro:see:`BrokerComm::set_endpoint_flags`.
|
||||
##
|
||||
## topic: a topic to disallow messages to be published under.
|
||||
##
|
||||
## Returns: true if successful.
|
||||
function Comm::unpublish_topic%(topic: string%): bool
|
||||
function BrokerComm::unpublish_topic%(topic: string%): bool
|
||||
%{
|
||||
return new Val(comm_mgr->UnpublishTopic(topic->CheckString()), TYPE_BOOL);
|
||||
return new Val(broker_mgr->UnpublishTopic(topic->CheckString()), TYPE_BOOL);
|
||||
%}
|
||||
|
||||
## Allow advertising interest in the given topic to peers.
|
||||
## This has no effect if auto advertise behavior is enabled via the flags
|
||||
## supplied to :bro:see:`Comm::enable` or :bro:see:`Comm::set_endpoint_flags`.
|
||||
## supplied to :bro:see:`BrokerComm::enable` or :bro:see:`BrokerComm::set_endpoint_flags`.
|
||||
##
|
||||
## topic: a topic to allow advertising interest/subscription to peers.
|
||||
##
|
||||
## Returns: true if successful.
|
||||
function Comm::advertise_topic%(topic: string%): bool
|
||||
function BrokerComm::advertise_topic%(topic: string%): bool
|
||||
%{
|
||||
return new Val(comm_mgr->AdvertiseTopic(topic->CheckString()), TYPE_BOOL);
|
||||
return new Val(broker_mgr->AdvertiseTopic(topic->CheckString()), TYPE_BOOL);
|
||||
%}
|
||||
|
||||
## Disallow advertising interest in the given topic to peers.
|
||||
## This has no effect if auto advertise behavior is enabled via the flags
|
||||
## supplied to :bro:see:`Comm::enable` or :bro:see:`Comm::set_endpoint_flags`.
|
||||
## supplied to :bro:see:`BrokerComm::enable` or :bro:see:`BrokerComm::set_endpoint_flags`.
|
||||
##
|
||||
## topic: a topic to disallow advertising interest/subscription to peers.
|
||||
##
|
||||
## Returns: true if successful.
|
||||
function Comm::unadvertise_topic%(topic: string%): bool
|
||||
function BrokerComm::unadvertise_topic%(topic: string%): bool
|
||||
%{
|
||||
return new Val(comm_mgr->UnadvertiseTopic(topic->CheckString()), TYPE_BOOL);
|
||||
return new Val(broker_mgr->UnadvertiseTopic(topic->CheckString()), TYPE_BOOL);
|
||||
%}
|
||||
|
||||
## Generated when a connection has been established due to a previous call
|
||||
## to :bro:see:`Comm::connect`.
|
||||
## to :bro:see:`BrokerComm::connect`.
|
||||
##
|
||||
## peer_address: the address used to connect to the peer.
|
||||
##
|
||||
## peer_port: the port used to connect to the peer.
|
||||
##
|
||||
## peer_name: the name by which the peer identified itself.
|
||||
event Comm::outgoing_connection_established%(peer_address: string,
|
||||
event BrokerComm::outgoing_connection_established%(peer_address: string,
|
||||
peer_port: port,
|
||||
peer_name: string%);
|
||||
|
||||
## Generated when a previously established connection becomes broken.
|
||||
## Reconnection will automatically be attempted at a frequency given
|
||||
## by the original call to :bro:see:`Comm::connect`.
|
||||
## by the original call to :bro:see:`BrokerComm::connect`.
|
||||
##
|
||||
## peer_address: the address used to connect to the peer.
|
||||
##
|
||||
## peer_port: the port used to connect to the peer.
|
||||
##
|
||||
## .. bro:see:: Comm::outgoing_connection_established
|
||||
event Comm::outgoing_connection_broken%(peer_address: string,
|
||||
## .. bro:see:: BrokerComm::outgoing_connection_established
|
||||
event BrokerComm::outgoing_connection_broken%(peer_address: string,
|
||||
peer_port: port%);
|
||||
|
||||
## Generated when a connection via :bro:see:`Comm::connect` has failed
|
||||
## Generated when a connection via :bro:see:`BrokerComm::connect` has failed
|
||||
## because the remote side is incompatible.
|
||||
##
|
||||
## peer_address: the address used to connect to the peer.
|
||||
##
|
||||
## peer_port: the port used to connect to the peer.
|
||||
event Comm::outgoing_connection_incompatible%(peer_address: string,
|
||||
event BrokerComm::outgoing_connection_incompatible%(peer_address: string,
|
||||
peer_port: port%);
|
||||
|
||||
## Generated when a peer has established a connection with this process
|
||||
## as a result of previously performing a :bro:see:`Comm::listen`.
|
||||
## as a result of previously performing a :bro:see:`BrokerComm::listen`.
|
||||
##
|
||||
## peer_name: the name by which the peer identified itself.
|
||||
event Comm::incoming_connection_established%(peer_name: string%);
|
||||
event BrokerComm::incoming_connection_established%(peer_name: string%);
|
||||
|
||||
## Generated when a peer that previously established a connection with this
|
||||
## process becomes disconnected.
|
||||
##
|
||||
## peer_name: the name by which the peer identified itself.
|
||||
##
|
||||
## .. bro:see:: Comm::incoming_connection_established
|
||||
event Comm::incoming_connection_broken%(peer_name: string%);
|
||||
## .. bro:see:: BrokerComm::incoming_connection_established
|
||||
event BrokerComm::incoming_connection_broken%(peer_name: string%);
|
||||
|
||||
## Listen for remote connections.
|
||||
##
|
||||
|
@ -135,8 +135,8 @@ event Comm::incoming_connection_broken%(peer_name: string%);
|
|||
##
|
||||
## Returns: true if the local endpoint is now listening for connections.
|
||||
##
|
||||
## .. bro:see:: Comm::incoming_connection_established
|
||||
function Comm::listen%(p: port, a: string &default = "",
|
||||
## .. bro:see:: BrokerComm::incoming_connection_established
|
||||
function BrokerComm::listen%(p: port, a: string &default = "",
|
||||
reuse: bool &default = T%): bool
|
||||
%{
|
||||
if ( ! p->IsTCP() )
|
||||
|
@ -145,7 +145,7 @@ function Comm::listen%(p: port, a: string &default = "",
|
|||
return new Val(false, TYPE_BOOL);
|
||||
}
|
||||
|
||||
auto rval = comm_mgr->Listen(p->Port(), a->Len() ? a->CheckString() : 0,
|
||||
auto rval = broker_mgr->Listen(p->Port(), a->Len() ? a->CheckString() : 0,
|
||||
reuse);
|
||||
return new Val(rval, TYPE_BOOL);
|
||||
%}
|
||||
|
@ -164,8 +164,8 @@ function Comm::listen%(p: port, a: string &default = "",
|
|||
## it's a new peer. The actual connection may not be established
|
||||
## a later point in time.
|
||||
##
|
||||
## .. bro:see:: Comm::outgoing_connection_established
|
||||
function Comm::connect%(a: string, p: port, retry: interval%): bool
|
||||
## .. bro:see:: BrokerComm::outgoing_connection_established
|
||||
function BrokerComm::connect%(a: string, p: port, retry: interval%): bool
|
||||
%{
|
||||
if ( ! p->IsTCP() )
|
||||
{
|
||||
|
@ -173,20 +173,20 @@ function Comm::connect%(a: string, p: port, retry: interval%): bool
|
|||
return new Val(false, TYPE_BOOL);
|
||||
}
|
||||
|
||||
auto rval = comm_mgr->Connect(a->CheckString(), p->Port(),
|
||||
auto rval = broker_mgr->Connect(a->CheckString(), p->Port(),
|
||||
std::chrono::duration<double>(retry));
|
||||
return new Val(rval, TYPE_BOOL);
|
||||
%}
|
||||
|
||||
## Remove a remote connection.
|
||||
##
|
||||
## a: the address used in previous successful call to :bro:see:`Comm::connect`.
|
||||
## a: the address used in previous successful call to :bro:see:`BrokerComm::connect`.
|
||||
##
|
||||
## p: the port used in previous successful call to :bro:see:`Comm::connect`.
|
||||
## p: the port used in previous successful call to :bro:see:`BrokerComm::connect`.
|
||||
##
|
||||
## Returns: true if the arguments match a previously successful call to
|
||||
## :bro:see:`Comm::connect`.
|
||||
function Comm::disconnect%(a: string, p: port%): bool
|
||||
## :bro:see:`BrokerComm::connect`.
|
||||
function BrokerComm::disconnect%(a: string, p: port%): bool
|
||||
%{
|
||||
if ( ! p->IsTCP() )
|
||||
{
|
||||
|
@ -194,6 +194,6 @@ function Comm::disconnect%(a: string, p: port%): bool
|
|||
return new Val(false, TYPE_BOOL);
|
||||
}
|
||||
|
||||
auto rval = comm_mgr->Disconnect(a->CheckString(), p->Port());
|
||||
auto rval = broker_mgr->Disconnect(a->CheckString(), p->Port());
|
||||
return new Val(rval, TYPE_BOOL);
|
||||
%}
|
|
@ -2,12 +2,12 @@
|
|||
##! Functions for inspecting and manipulating broker data.
|
||||
|
||||
%%{
|
||||
#include "comm/Data.h"
|
||||
#include "broker/Data.h"
|
||||
%%}
|
||||
|
||||
module Comm;
|
||||
module BrokerComm;
|
||||
|
||||
## Enumerates the possible types that :bro:see:`Comm::Data` may be in terms of
|
||||
## Enumerates the possible types that :bro:see:`BrokerComm::Data` may be in terms of
|
||||
## Bro data types.
|
||||
enum DataType %{
|
||||
BOOL,
|
||||
|
@ -27,9 +27,9 @@ enum DataType %{
|
|||
RECORD,
|
||||
%}
|
||||
|
||||
type Comm::Data: record;
|
||||
type BrokerComm::Data: record;
|
||||
|
||||
type Comm::TableItem: record;
|
||||
type BrokerComm::TableItem: record;
|
||||
|
||||
## Convert any Bro value in to communication data.
|
||||
##
|
||||
|
@ -38,9 +38,9 @@ type Comm::TableItem: record;
|
|||
## Returns: the converted communication data which may not set its only
|
||||
## opaque field of the the conversion was not possible (the Bro data
|
||||
## type does not support being converted to communicaiton data).
|
||||
function Comm::data%(d: any%): Comm::Data
|
||||
function BrokerComm::data%(d: any%): BrokerComm::Data
|
||||
%{
|
||||
return comm::make_data_val(d);
|
||||
return bro_broker::make_data_val(d);
|
||||
%}
|
||||
|
||||
## Retrieve the type of data associated with communication data.
|
||||
|
@ -48,153 +48,153 @@ function Comm::data%(d: any%): Comm::Data
|
|||
## d: the communication data.
|
||||
##
|
||||
## Returns: the data type associated with the communication data.
|
||||
function Comm::data_type%(d: Comm::Data%): Comm::DataType
|
||||
function BrokerComm::data_type%(d: BrokerComm::Data%): BrokerComm::DataType
|
||||
%{
|
||||
return comm::get_data_type(d->AsRecordVal(), frame);
|
||||
return bro_broker::get_data_type(d->AsRecordVal(), frame);
|
||||
%}
|
||||
|
||||
## Convert communication data with a type of :bro:see:`Comm::BOOL` to
|
||||
## Convert communication data with a type of :bro:see:`BrokerComm::BOOL` to
|
||||
## an actual Bro value.
|
||||
##
|
||||
## d: the communication data to convert.
|
||||
##
|
||||
## Returns: the value retrieved from the communication data.
|
||||
function Comm::refine_to_bool%(d: Comm::Data%): bool
|
||||
function BrokerComm::refine_to_bool%(d: BrokerComm::Data%): bool
|
||||
%{
|
||||
return comm::refine<bool>(d->AsRecordVal(), TYPE_BOOL, frame);
|
||||
return bro_broker::refine<bool>(d->AsRecordVal(), TYPE_BOOL, frame);
|
||||
%}
|
||||
|
||||
## Convert communication data with a type of :bro:see:`Comm::INT` to
|
||||
## Convert communication data with a type of :bro:see:`BrokerComm::INT` to
|
||||
## an actual Bro value.
|
||||
##
|
||||
## d: the communication data to convert.
|
||||
##
|
||||
## Returns: the value retrieved from the communication data.
|
||||
function Comm::refine_to_int%(d: Comm::Data%): int
|
||||
function BrokerComm::refine_to_int%(d: BrokerComm::Data%): int
|
||||
%{
|
||||
return comm::refine<int64_t>(d->AsRecordVal(), TYPE_INT, frame);
|
||||
return bro_broker::refine<int64_t>(d->AsRecordVal(), TYPE_INT, frame);
|
||||
%}
|
||||
|
||||
## Convert communication data with a type of :bro:see:`Comm::COUNT` to
|
||||
## Convert communication data with a type of :bro:see:`BrokerComm::COUNT` to
|
||||
## an actual Bro value.
|
||||
##
|
||||
## d: the communication data to convert.
|
||||
##
|
||||
## Returns: the value retrieved from the communication data.
|
||||
function Comm::refine_to_count%(d: Comm::Data%): count
|
||||
function BrokerComm::refine_to_count%(d: BrokerComm::Data%): count
|
||||
%{
|
||||
return comm::refine<uint64_t>(d->AsRecordVal(), TYPE_COUNT, frame);
|
||||
return bro_broker::refine<uint64_t>(d->AsRecordVal(), TYPE_COUNT, frame);
|
||||
%}
|
||||
|
||||
## Convert communication data with a type of :bro:see:`Comm::DOUBLE` to
|
||||
## Convert communication data with a type of :bro:see:`BrokerComm::DOUBLE` to
|
||||
## an actual Bro value.
|
||||
##
|
||||
## d: the communication data to convert.
|
||||
##
|
||||
## Returns: the value retrieved from the communication data.
|
||||
function Comm::refine_to_double%(d: Comm::Data%): double
|
||||
function BrokerComm::refine_to_double%(d: BrokerComm::Data%): double
|
||||
%{
|
||||
return comm::refine<double>(d->AsRecordVal(), TYPE_DOUBLE, frame);
|
||||
return bro_broker::refine<double>(d->AsRecordVal(), TYPE_DOUBLE, frame);
|
||||
%}
|
||||
|
||||
## Convert communication data with a type of :bro:see:`Comm::STRING` to
|
||||
## Convert communication data with a type of :bro:see:`BrokerComm::STRING` to
|
||||
## an actual Bro value.
|
||||
##
|
||||
## d: the communication data to convert.
|
||||
##
|
||||
## Returns: the value retrieved from the communication data.
|
||||
function Comm::refine_to_string%(d: Comm::Data%): string
|
||||
function BrokerComm::refine_to_string%(d: BrokerComm::Data%): string
|
||||
%{
|
||||
return new StringVal(comm::require_data_type<std::string>(d->AsRecordVal(),
|
||||
return new StringVal(bro_broker::require_data_type<std::string>(d->AsRecordVal(),
|
||||
TYPE_STRING,
|
||||
frame));
|
||||
%}
|
||||
|
||||
## Convert communication data with a type of :bro:see:`Comm::ADDR` to
|
||||
## Convert communication data with a type of :bro:see:`BrokerComm::ADDR` to
|
||||
## an actual Bro value.
|
||||
##
|
||||
## d: the communication data to convert.
|
||||
##
|
||||
## Returns: the value retrieved from the communication data.
|
||||
function Comm::refine_to_addr%(d: Comm::Data%): addr
|
||||
function BrokerComm::refine_to_addr%(d: BrokerComm::Data%): addr
|
||||
%{
|
||||
auto& a = comm::require_data_type<broker::address>(d->AsRecordVal(),
|
||||
auto& a = bro_broker::require_data_type<broker::address>(d->AsRecordVal(),
|
||||
TYPE_ADDR, frame);
|
||||
auto bits = reinterpret_cast<const in6_addr*>(&a.bytes());
|
||||
return new AddrVal(IPAddr(*bits));
|
||||
%}
|
||||
|
||||
## Convert communication data with a type of :bro:see:`Comm::SUBNET` to
|
||||
## Convert communication data with a type of :bro:see:`BrokerComm::SUBNET` to
|
||||
## an actual Bro value.
|
||||
##
|
||||
## d: the communication data to convert.
|
||||
##
|
||||
## Returns: the value retrieved from the communication data.
|
||||
function Comm::refine_to_subnet%(d: Comm::Data%): subnet
|
||||
function BrokerComm::refine_to_subnet%(d: BrokerComm::Data%): subnet
|
||||
%{
|
||||
auto& a = comm::require_data_type<broker::subnet>(d->AsRecordVal(),
|
||||
auto& a = bro_broker::require_data_type<broker::subnet>(d->AsRecordVal(),
|
||||
TYPE_SUBNET, frame);
|
||||
auto bits = reinterpret_cast<const in6_addr*>(&a.network().bytes());
|
||||
return new SubNetVal(IPPrefix(IPAddr(*bits), a.length()));
|
||||
%}
|
||||
|
||||
## Convert communication data with a type of :bro:see:`Comm::PORT` to
|
||||
## Convert communication data with a type of :bro:see:`BrokerComm::PORT` to
|
||||
## an actual Bro value.
|
||||
##
|
||||
## d: the communication data to convert.
|
||||
##
|
||||
## Returns: the value retrieved from the communication data.
|
||||
function Comm::refine_to_port%(d: Comm::Data%): port
|
||||
function BrokerComm::refine_to_port%(d: BrokerComm::Data%): port
|
||||
%{
|
||||
auto& a = comm::require_data_type<broker::port>(d->AsRecordVal(),
|
||||
auto& a = bro_broker::require_data_type<broker::port>(d->AsRecordVal(),
|
||||
TYPE_SUBNET, frame);
|
||||
return new PortVal(a.number(), comm::to_bro_port_proto(a.type()));
|
||||
return new PortVal(a.number(), bro_broker::to_bro_port_proto(a.type()));
|
||||
%}
|
||||
|
||||
## Convert communication data with a type of :bro:see:`Comm::TIME` to
|
||||
## Convert communication data with a type of :bro:see:`BrokerComm::TIME` to
|
||||
## an actual Bro value.
|
||||
##
|
||||
## d: the communication data to convert.
|
||||
##
|
||||
## Returns: the value retrieved from the communication data.
|
||||
function Comm::refine_to_time%(d: Comm::Data%): time
|
||||
function BrokerComm::refine_to_time%(d: BrokerComm::Data%): time
|
||||
%{
|
||||
auto v = comm::require_data_type<broker::time_point>(d->AsRecordVal(),
|
||||
auto v = bro_broker::require_data_type<broker::time_point>(d->AsRecordVal(),
|
||||
TYPE_TIME, frame).value;
|
||||
return new Val(v, TYPE_TIME);
|
||||
%}
|
||||
|
||||
## Convert communication data with a type of :bro:see:`Comm::INTERVAL` to
|
||||
## Convert communication data with a type of :bro:see:`BrokerComm::INTERVAL` to
|
||||
## an actual Bro value.
|
||||
##
|
||||
## d: the communication data to convert.
|
||||
##
|
||||
## Returns: the value retrieved from the communication data.
|
||||
function Comm::refine_to_interval%(d: Comm::Data%): interval
|
||||
function BrokerComm::refine_to_interval%(d: BrokerComm::Data%): interval
|
||||
%{
|
||||
auto v = comm::require_data_type<broker::time_duration>(d->AsRecordVal(),
|
||||
auto v = bro_broker::require_data_type<broker::time_duration>(d->AsRecordVal(),
|
||||
TYPE_TIME, frame).value;
|
||||
return new Val(v, TYPE_INTERVAL);
|
||||
%}
|
||||
|
||||
## Convert communication data with a type of :bro:see:`Comm::ENUM` to
|
||||
## Convert communication data with a type of :bro:see:`BrokerComm::ENUM` to
|
||||
## the name of the enum value. :bro:see:`lookup_ID` may be used to convert
|
||||
## the name to the actual enum value.
|
||||
##
|
||||
## d: the communication data to convert.
|
||||
##
|
||||
## Returns: the enum name retrieved from the communication data.
|
||||
function Comm::refine_to_enum_name%(d: Comm::Data%): string
|
||||
function BrokerComm::refine_to_enum_name%(d: BrokerComm::Data%): string
|
||||
%{
|
||||
auto& v = comm::require_data_type<broker::enum_value>(d->AsRecordVal(),
|
||||
auto& v = bro_broker::require_data_type<broker::enum_value>(d->AsRecordVal(),
|
||||
TYPE_ENUM, frame).name;
|
||||
return new StringVal(v);
|
||||
%}
|
||||
|
||||
## Create communication data of type "set".
|
||||
function Comm::set_create%(%): Comm::Data
|
||||
function BrokerComm::set_create%(%): BrokerComm::Data
|
||||
%{
|
||||
return comm::make_data_val(broker::set());
|
||||
return bro_broker::make_data_val(broker::set());
|
||||
%}
|
||||
|
||||
## Remove all elements within a set.
|
||||
|
@ -202,9 +202,9 @@ function Comm::set_create%(%): Comm::Data
|
|||
## s: the set to clear.
|
||||
##
|
||||
## Returns: always true.
|
||||
function Comm::set_clear%(s: Comm::Data%): bool
|
||||
function BrokerComm::set_clear%(s: BrokerComm::Data%): bool
|
||||
%{
|
||||
auto& v = comm::require_data_type<broker::set>(s->AsRecordVal(), TYPE_TABLE,
|
||||
auto& v = bro_broker::require_data_type<broker::set>(s->AsRecordVal(), TYPE_TABLE,
|
||||
frame);
|
||||
v.clear();
|
||||
return new Val(true, TYPE_BOOL);
|
||||
|
@ -215,9 +215,9 @@ function Comm::set_clear%(s: Comm::Data%): bool
|
|||
## s: the set to query.
|
||||
##
|
||||
## Returns: the number of elements in the set.
|
||||
function Comm::set_size%(s: Comm::Data%): count
|
||||
function BrokerComm::set_size%(s: BrokerComm::Data%): count
|
||||
%{
|
||||
auto& v = comm::require_data_type<broker::set>(s->AsRecordVal(), TYPE_TABLE,
|
||||
auto& v = bro_broker::require_data_type<broker::set>(s->AsRecordVal(), TYPE_TABLE,
|
||||
frame);
|
||||
return new Val(static_cast<uint64_t>(v.size()), TYPE_COUNT);
|
||||
%}
|
||||
|
@ -229,11 +229,11 @@ function Comm::set_size%(s: Comm::Data%): count
|
|||
## key: the element to check for existence.
|
||||
##
|
||||
## Returns: true if the key exists in the set.
|
||||
function Comm::set_contains%(s: Comm::Data, key: Comm::Data%): bool
|
||||
function BrokerComm::set_contains%(s: BrokerComm::Data, key: BrokerComm::Data%): bool
|
||||
%{
|
||||
auto& v = comm::require_data_type<broker::set>(s->AsRecordVal(), TYPE_TABLE,
|
||||
auto& v = bro_broker::require_data_type<broker::set>(s->AsRecordVal(), TYPE_TABLE,
|
||||
frame);
|
||||
auto& k = comm::opaque_field_to_data(key->AsRecordVal(), frame);
|
||||
auto& k = bro_broker::opaque_field_to_data(key->AsRecordVal(), frame);
|
||||
return new Val(v.find(k) != v.end(), TYPE_BOOL);
|
||||
%}
|
||||
|
||||
|
@ -244,11 +244,11 @@ function Comm::set_contains%(s: Comm::Data, key: Comm::Data%): bool
|
|||
## key: the element to insert.
|
||||
##
|
||||
## Returns: true if the key was inserted, or false if it already existed.
|
||||
function Comm::set_insert%(s: Comm::Data, key: Comm::Data%): bool
|
||||
function BrokerComm::set_insert%(s: BrokerComm::Data, key: BrokerComm::Data%): bool
|
||||
%{
|
||||
auto& v = comm::require_data_type<broker::set>(s->AsRecordVal(), TYPE_TABLE,
|
||||
auto& v = bro_broker::require_data_type<broker::set>(s->AsRecordVal(), TYPE_TABLE,
|
||||
frame);
|
||||
auto& k = comm::opaque_field_to_data(key->AsRecordVal(), frame);
|
||||
auto& k = bro_broker::opaque_field_to_data(key->AsRecordVal(), frame);
|
||||
return new Val(v.insert(k).second, TYPE_BOOL);
|
||||
%}
|
||||
|
||||
|
@ -259,11 +259,11 @@ function Comm::set_insert%(s: Comm::Data, key: Comm::Data%): bool
|
|||
## key: the element to remove.
|
||||
##
|
||||
## Returns: true if the element existed in the set and is now removed.
|
||||
function Comm::set_remove%(s: Comm::Data, key: Comm::Data%): bool
|
||||
function BrokerComm::set_remove%(s: BrokerComm::Data, key: BrokerComm::Data%): bool
|
||||
%{
|
||||
auto& v = comm::require_data_type<broker::set>(s->AsRecordVal(), TYPE_TABLE,
|
||||
auto& v = bro_broker::require_data_type<broker::set>(s->AsRecordVal(), TYPE_TABLE,
|
||||
frame);
|
||||
auto& k = comm::opaque_field_to_data(key->AsRecordVal(), frame);
|
||||
auto& k = bro_broker::opaque_field_to_data(key->AsRecordVal(), frame);
|
||||
return new Val(v.erase(k) > 0, TYPE_BOOL);
|
||||
%}
|
||||
|
||||
|
@ -273,9 +273,9 @@ function Comm::set_remove%(s: Comm::Data, key: Comm::Data%): bool
|
|||
## s: the set to iterate over.
|
||||
##
|
||||
## Returns: an iterator.
|
||||
function Comm::set_iterator%(s: Comm::Data%): opaque of Comm::SetIterator
|
||||
function BrokerComm::set_iterator%(s: BrokerComm::Data%): opaque of BrokerComm::SetIterator
|
||||
%{
|
||||
return new comm::SetIterator(s->AsRecordVal(), TYPE_TABLE, frame);
|
||||
return new bro_broker::SetIterator(s->AsRecordVal(), TYPE_TABLE, frame);
|
||||
%}
|
||||
|
||||
## Check if there are no more elements to iterate over.
|
||||
|
@ -284,9 +284,9 @@ function Comm::set_iterator%(s: Comm::Data%): opaque of Comm::SetIterator
|
|||
##
|
||||
## Returns: true if there are no more elements to iterator over, i.e.
|
||||
## the iterator is one-past-the-final-element.
|
||||
function Comm::set_iterator_last%(it: opaque of Comm::SetIterator%): bool
|
||||
function BrokerComm::set_iterator_last%(it: opaque of BrokerComm::SetIterator%): bool
|
||||
%{
|
||||
auto set_it = static_cast<comm::SetIterator*>(it);
|
||||
auto set_it = static_cast<bro_broker::SetIterator*>(it);
|
||||
return new Val(set_it->it == set_it->dat.end(), TYPE_BOOL);
|
||||
%}
|
||||
|
||||
|
@ -297,9 +297,9 @@ function Comm::set_iterator_last%(it: opaque of Comm::SetIterator%): bool
|
|||
## Returns: true if the iterator, after advancing, still references an element
|
||||
## in the collection. False if the iterator, after advancing, is
|
||||
## one-past-the-final-element.
|
||||
function Comm::set_iterator_next%(it: opaque of Comm::SetIterator%): bool
|
||||
function BrokerComm::set_iterator_next%(it: opaque of BrokerComm::SetIterator%): bool
|
||||
%{
|
||||
auto set_it = static_cast<comm::SetIterator*>(it);
|
||||
auto set_it = static_cast<bro_broker::SetIterator*>(it);
|
||||
|
||||
if ( set_it->it == set_it->dat.end() )
|
||||
return new Val(false, TYPE_BOOL);
|
||||
|
@ -313,10 +313,10 @@ function Comm::set_iterator_next%(it: opaque of Comm::SetIterator%): bool
|
|||
## it: an iterator.
|
||||
##
|
||||
## Returns: element in the collection that the iterator currently references.
|
||||
function Comm::set_iterator_value%(it: opaque of Comm::SetIterator%): Comm::Data
|
||||
function BrokerComm::set_iterator_value%(it: opaque of BrokerComm::SetIterator%): BrokerComm::Data
|
||||
%{
|
||||
auto set_it = static_cast<comm::SetIterator*>(it);
|
||||
auto rval = new RecordVal(BifType::Record::Comm::Data);
|
||||
auto set_it = static_cast<bro_broker::SetIterator*>(it);
|
||||
auto rval = new RecordVal(BifType::Record::BrokerComm::Data);
|
||||
|
||||
if ( set_it->it == set_it->dat.end() )
|
||||
{
|
||||
|
@ -326,14 +326,14 @@ function Comm::set_iterator_value%(it: opaque of Comm::SetIterator%): Comm::Data
|
|||
return rval;
|
||||
}
|
||||
|
||||
rval->Assign(0, new comm::DataVal(*set_it->it));
|
||||
rval->Assign(0, new bro_broker::DataVal(*set_it->it));
|
||||
return rval;
|
||||
%}
|
||||
|
||||
## Create communication data of type "table".
|
||||
function Comm::table_create%(%): Comm::Data
|
||||
function BrokerComm::table_create%(%): BrokerComm::Data
|
||||
%{
|
||||
return comm::make_data_val(broker::table());
|
||||
return bro_broker::make_data_val(broker::table());
|
||||
%}
|
||||
|
||||
## Remove all elements within a table.
|
||||
|
@ -341,9 +341,9 @@ function Comm::table_create%(%): Comm::Data
|
|||
## t: the table to clear.
|
||||
##
|
||||
## Returns: always true.
|
||||
function Comm::table_clear%(t: Comm::Data%): bool
|
||||
function BrokerComm::table_clear%(t: BrokerComm::Data%): bool
|
||||
%{
|
||||
auto& v = comm::require_data_type<broker::table>(t->AsRecordVal(),
|
||||
auto& v = bro_broker::require_data_type<broker::table>(t->AsRecordVal(),
|
||||
TYPE_TABLE, frame);
|
||||
v.clear();
|
||||
return new Val(true, TYPE_BOOL);
|
||||
|
@ -354,9 +354,9 @@ function Comm::table_clear%(t: Comm::Data%): bool
|
|||
## t: the table to query.
|
||||
##
|
||||
## Returns: the number of elements in the table.
|
||||
function Comm::table_size%(t: Comm::Data%): count
|
||||
function BrokerComm::table_size%(t: BrokerComm::Data%): count
|
||||
%{
|
||||
auto& v = comm::require_data_type<broker::table>(t->AsRecordVal(),
|
||||
auto& v = bro_broker::require_data_type<broker::table>(t->AsRecordVal(),
|
||||
TYPE_TABLE, frame);
|
||||
return new Val(static_cast<uint64_t>(v.size()), TYPE_COUNT);
|
||||
%}
|
||||
|
@ -368,11 +368,11 @@ function Comm::table_size%(t: Comm::Data%): count
|
|||
## key: the key to check for existence.
|
||||
##
|
||||
## Returns: true if the key exists in the set.
|
||||
function Comm::table_contains%(t: Comm::Data, key: Comm::Data%): bool
|
||||
function BrokerComm::table_contains%(t: BrokerComm::Data, key: BrokerComm::Data%): bool
|
||||
%{
|
||||
auto& v = comm::require_data_type<broker::table>(t->AsRecordVal(),
|
||||
auto& v = bro_broker::require_data_type<broker::table>(t->AsRecordVal(),
|
||||
TYPE_TABLE, frame);
|
||||
auto& k = comm::opaque_field_to_data(key->AsRecordVal(), frame);
|
||||
auto& k = bro_broker::opaque_field_to_data(key->AsRecordVal(), frame);
|
||||
return new Val(v.find(k) != v.end(), TYPE_BOOL);
|
||||
%}
|
||||
|
||||
|
@ -386,24 +386,24 @@ function Comm::table_contains%(t: Comm::Data, key: Comm::Data%): bool
|
|||
##
|
||||
## Returns: true if the key-value pair was inserted, or false if the key
|
||||
## already existed in the table.
|
||||
function Comm::table_insert%(t: Comm::Data, key: Comm::Data, val: Comm::Data%): Comm::Data
|
||||
function BrokerComm::table_insert%(t: BrokerComm::Data, key: BrokerComm::Data, val: BrokerComm::Data%): BrokerComm::Data
|
||||
%{
|
||||
auto& table = comm::require_data_type<broker::table>(t->AsRecordVal(),
|
||||
auto& table = bro_broker::require_data_type<broker::table>(t->AsRecordVal(),
|
||||
TYPE_TABLE, frame);
|
||||
auto& k = comm::opaque_field_to_data(key->AsRecordVal(), frame);
|
||||
auto& v = comm::opaque_field_to_data(val->AsRecordVal(), frame);
|
||||
auto& k = bro_broker::opaque_field_to_data(key->AsRecordVal(), frame);
|
||||
auto& v = bro_broker::opaque_field_to_data(val->AsRecordVal(), frame);
|
||||
|
||||
try
|
||||
{
|
||||
auto& prev = table.at(k);
|
||||
auto rval = comm::make_data_val(move(prev));
|
||||
auto rval = bro_broker::make_data_val(move(prev));
|
||||
prev = v;
|
||||
return rval;
|
||||
}
|
||||
catch (const std::out_of_range&)
|
||||
{
|
||||
table[k] = v;
|
||||
return new RecordVal(BifType::Record::Comm::Data);
|
||||
return new RecordVal(BifType::Record::BrokerComm::Data);
|
||||
}
|
||||
%}
|
||||
|
||||
|
@ -415,18 +415,18 @@ function Comm::table_insert%(t: Comm::Data, key: Comm::Data, val: Comm::Data%):
|
|||
##
|
||||
## Returns: the value associated with the key. If the key did not exist, then
|
||||
## the optional field of the returned record is not set.
|
||||
function Comm::table_remove%(t: Comm::Data, key: Comm::Data%): Comm::Data
|
||||
function BrokerComm::table_remove%(t: BrokerComm::Data, key: BrokerComm::Data%): BrokerComm::Data
|
||||
%{
|
||||
auto& table = comm::require_data_type<broker::table>(t->AsRecordVal(),
|
||||
auto& table = bro_broker::require_data_type<broker::table>(t->AsRecordVal(),
|
||||
TYPE_TABLE, frame);
|
||||
auto& k = comm::opaque_field_to_data(key->AsRecordVal(), frame);
|
||||
auto& k = bro_broker::opaque_field_to_data(key->AsRecordVal(), frame);
|
||||
auto it = table.find(k);
|
||||
|
||||
if ( it == table.end() )
|
||||
return new RecordVal(BifType::Record::Comm::Data);
|
||||
return new RecordVal(BifType::Record::BrokerComm::Data);
|
||||
else
|
||||
{
|
||||
auto rval = comm::make_data_val(move(it->second));
|
||||
auto rval = bro_broker::make_data_val(move(it->second));
|
||||
table.erase(it);
|
||||
return rval;
|
||||
}
|
||||
|
@ -440,17 +440,17 @@ function Comm::table_remove%(t: Comm::Data, key: Comm::Data%): Comm::Data
|
|||
##
|
||||
## Returns: the value associated with the key. If the key did not exist, then
|
||||
## the optional field of the returned record is not set.
|
||||
function Comm::table_lookup%(t: Comm::Data, key: Comm::Data%): Comm::Data
|
||||
function BrokerComm::table_lookup%(t: BrokerComm::Data, key: BrokerComm::Data%): BrokerComm::Data
|
||||
%{
|
||||
auto& table = comm::require_data_type<broker::table>(t->AsRecordVal(),
|
||||
auto& table = bro_broker::require_data_type<broker::table>(t->AsRecordVal(),
|
||||
TYPE_TABLE, frame);
|
||||
auto& k = comm::opaque_field_to_data(key->AsRecordVal(), frame);
|
||||
auto& k = bro_broker::opaque_field_to_data(key->AsRecordVal(), frame);
|
||||
auto it = table.find(k);
|
||||
|
||||
if ( it == table.end() )
|
||||
return new RecordVal(BifType::Record::Comm::Data);
|
||||
return new RecordVal(BifType::Record::BrokerComm::Data);
|
||||
else
|
||||
return comm::make_data_val(it->second);
|
||||
return bro_broker::make_data_val(it->second);
|
||||
%}
|
||||
|
||||
## Create an iterator for a table. Note that this makes a copy of the table
|
||||
|
@ -459,9 +459,9 @@ function Comm::table_lookup%(t: Comm::Data, key: Comm::Data%): Comm::Data
|
|||
## t: the table to iterate over.
|
||||
##
|
||||
## Returns: an iterator.
|
||||
function Comm::table_iterator%(t: Comm::Data%): opaque of Comm::TableIterator
|
||||
function BrokerComm::table_iterator%(t: BrokerComm::Data%): opaque of BrokerComm::TableIterator
|
||||
%{
|
||||
return new comm::TableIterator(t->AsRecordVal(), TYPE_TABLE, frame);
|
||||
return new bro_broker::TableIterator(t->AsRecordVal(), TYPE_TABLE, frame);
|
||||
%}
|
||||
|
||||
## Check if there are no more elements to iterate over.
|
||||
|
@ -470,9 +470,9 @@ function Comm::table_iterator%(t: Comm::Data%): opaque of Comm::TableIterator
|
|||
##
|
||||
## Returns: true if there are no more elements to iterator over, i.e.
|
||||
## the iterator is one-past-the-final-element.
|
||||
function Comm::table_iterator_last%(it: opaque of Comm::TableIterator%): bool
|
||||
function BrokerComm::table_iterator_last%(it: opaque of BrokerComm::TableIterator%): bool
|
||||
%{
|
||||
auto ti = static_cast<comm::TableIterator*>(it);
|
||||
auto ti = static_cast<bro_broker::TableIterator*>(it);
|
||||
return new Val(ti->it == ti->dat.end(), TYPE_BOOL);
|
||||
%}
|
||||
|
||||
|
@ -483,9 +483,9 @@ function Comm::table_iterator_last%(it: opaque of Comm::TableIterator%): bool
|
|||
## Returns: true if the iterator, after advancing, still references an element
|
||||
## in the collection. False if the iterator, after advancing, is
|
||||
## one-past-the-final-element.
|
||||
function Comm::table_iterator_next%(it: opaque of Comm::TableIterator%): bool
|
||||
function BrokerComm::table_iterator_next%(it: opaque of BrokerComm::TableIterator%): bool
|
||||
%{
|
||||
auto ti = static_cast<comm::TableIterator*>(it);
|
||||
auto ti = static_cast<bro_broker::TableIterator*>(it);
|
||||
|
||||
if ( ti->it == ti->dat.end() )
|
||||
return new Val(false, TYPE_BOOL);
|
||||
|
@ -499,12 +499,12 @@ function Comm::table_iterator_next%(it: opaque of Comm::TableIterator%): bool
|
|||
## it: an iterator.
|
||||
##
|
||||
## Returns: element in the collection that the iterator currently references.
|
||||
function Comm::table_iterator_value%(it: opaque of Comm::TableIterator%): Comm::TableItem
|
||||
function BrokerComm::table_iterator_value%(it: opaque of BrokerComm::TableIterator%): BrokerComm::TableItem
|
||||
%{
|
||||
auto ti = static_cast<comm::TableIterator*>(it);
|
||||
auto rval = new RecordVal(BifType::Record::Comm::TableItem);
|
||||
auto key_val = new RecordVal(BifType::Record::Comm::Data);
|
||||
auto val_val = new RecordVal(BifType::Record::Comm::Data);
|
||||
auto ti = static_cast<bro_broker::TableIterator*>(it);
|
||||
auto rval = new RecordVal(BifType::Record::BrokerComm::TableItem);
|
||||
auto key_val = new RecordVal(BifType::Record::BrokerComm::Data);
|
||||
auto val_val = new RecordVal(BifType::Record::BrokerComm::Data);
|
||||
rval->Assign(0, key_val);
|
||||
rval->Assign(1, val_val);
|
||||
|
||||
|
@ -516,15 +516,15 @@ function Comm::table_iterator_value%(it: opaque of Comm::TableIterator%): Comm::
|
|||
return rval;
|
||||
}
|
||||
|
||||
key_val->Assign(0, new comm::DataVal(ti->it->first));
|
||||
val_val->Assign(0, new comm::DataVal(ti->it->second));
|
||||
key_val->Assign(0, new bro_broker::DataVal(ti->it->first));
|
||||
val_val->Assign(0, new bro_broker::DataVal(ti->it->second));
|
||||
return rval;
|
||||
%}
|
||||
|
||||
## Create communication data of type "vector".
|
||||
function Comm::vector_create%(%): Comm::Data
|
||||
function BrokerComm::vector_create%(%): BrokerComm::Data
|
||||
%{
|
||||
return comm::make_data_val(broker::vector());
|
||||
return bro_broker::make_data_val(broker::vector());
|
||||
%}
|
||||
|
||||
## Remove all elements within a vector.
|
||||
|
@ -532,9 +532,9 @@ function Comm::vector_create%(%): Comm::Data
|
|||
## v: the vector to clear.
|
||||
##
|
||||
## Returns: always true.
|
||||
function Comm::vector_clear%(v: Comm::Data%): bool
|
||||
function BrokerComm::vector_clear%(v: BrokerComm::Data%): bool
|
||||
%{
|
||||
auto& vec = comm::require_data_type<broker::vector>(v->AsRecordVal(),
|
||||
auto& vec = bro_broker::require_data_type<broker::vector>(v->AsRecordVal(),
|
||||
TYPE_VECTOR, frame);
|
||||
vec.clear();
|
||||
return new Val(true, TYPE_BOOL);
|
||||
|
@ -545,9 +545,9 @@ function Comm::vector_clear%(v: Comm::Data%): bool
|
|||
## v: the vector to query.
|
||||
##
|
||||
## Returns: the number of elements in the vector.
|
||||
function Comm::vector_size%(v: Comm::Data%): count
|
||||
function BrokerComm::vector_size%(v: BrokerComm::Data%): count
|
||||
%{
|
||||
auto& vec = comm::require_data_type<broker::vector>(v->AsRecordVal(),
|
||||
auto& vec = bro_broker::require_data_type<broker::vector>(v->AsRecordVal(),
|
||||
TYPE_VECTOR, frame);
|
||||
return new Val(static_cast<uint64_t>(vec.size()), TYPE_COUNT);
|
||||
%}
|
||||
|
@ -563,11 +563,11 @@ function Comm::vector_size%(v: Comm::Data%): count
|
|||
## current size of the vector, the element is inserted at the end.
|
||||
##
|
||||
## Returns: always true.
|
||||
function Comm::vector_insert%(v: Comm::Data, d: Comm::Data, idx: count%): bool
|
||||
function BrokerComm::vector_insert%(v: BrokerComm::Data, d: BrokerComm::Data, idx: count%): bool
|
||||
%{
|
||||
auto& vec = comm::require_data_type<broker::vector>(v->AsRecordVal(),
|
||||
auto& vec = bro_broker::require_data_type<broker::vector>(v->AsRecordVal(),
|
||||
TYPE_VECTOR, frame);
|
||||
auto& item = comm::opaque_field_to_data(d->AsRecordVal(), frame);
|
||||
auto& item = bro_broker::opaque_field_to_data(d->AsRecordVal(), frame);
|
||||
idx = min(idx, static_cast<uint64_t>(vec.size()));
|
||||
vec.insert(vec.begin() + idx, item);
|
||||
return new Val(true, TYPE_BOOL);
|
||||
|
@ -583,16 +583,16 @@ function Comm::vector_insert%(v: Comm::Data, d: Comm::Data, idx: count%): bool
|
|||
##
|
||||
## Returns: the value that was just evicted. If the index was larger than any
|
||||
## valid index, the optional field of the returned record is not set.
|
||||
function Comm::vector_replace%(v: Comm::Data, d: Comm::Data, idx: count%): Comm::Data
|
||||
function BrokerComm::vector_replace%(v: BrokerComm::Data, d: BrokerComm::Data, idx: count%): BrokerComm::Data
|
||||
%{
|
||||
auto& vec = comm::require_data_type<broker::vector>(v->AsRecordVal(),
|
||||
auto& vec = bro_broker::require_data_type<broker::vector>(v->AsRecordVal(),
|
||||
TYPE_VECTOR, frame);
|
||||
auto& item = comm::opaque_field_to_data(d->AsRecordVal(), frame);
|
||||
auto& item = bro_broker::opaque_field_to_data(d->AsRecordVal(), frame);
|
||||
|
||||
if ( idx >= vec.size() )
|
||||
return new RecordVal(BifType::Record::Comm::Data);
|
||||
return new RecordVal(BifType::Record::BrokerComm::Data);
|
||||
|
||||
auto rval = comm::make_data_val(move(vec[idx]));
|
||||
auto rval = bro_broker::make_data_val(move(vec[idx]));
|
||||
vec[idx] = item;
|
||||
return rval;
|
||||
%}
|
||||
|
@ -605,15 +605,15 @@ function Comm::vector_replace%(v: Comm::Data, d: Comm::Data, idx: count%): Comm:
|
|||
##
|
||||
## Returns: the value that was just evicted. If the index was larger than any
|
||||
## valid index, the optional field of the returned record is not set.
|
||||
function Comm::vector_remove%(v: Comm::Data, idx: count%): Comm::Data
|
||||
function BrokerComm::vector_remove%(v: BrokerComm::Data, idx: count%): BrokerComm::Data
|
||||
%{
|
||||
auto& vec = comm::require_data_type<broker::vector>(v->AsRecordVal(),
|
||||
auto& vec = bro_broker::require_data_type<broker::vector>(v->AsRecordVal(),
|
||||
TYPE_VECTOR, frame);
|
||||
|
||||
if ( idx >= vec.size() )
|
||||
return new RecordVal(BifType::Record::Comm::Data);
|
||||
return new RecordVal(BifType::Record::BrokerComm::Data);
|
||||
|
||||
auto rval = comm::make_data_val(move(vec[idx]));
|
||||
auto rval = bro_broker::make_data_val(move(vec[idx]));
|
||||
vec.erase(vec.begin() + idx);
|
||||
return rval;
|
||||
%}
|
||||
|
@ -626,15 +626,15 @@ function Comm::vector_remove%(v: Comm::Data, idx: count%): Comm::Data
|
|||
##
|
||||
## Returns: the value at the index. If the index was larger than any
|
||||
## valid index, the optional field of the returned record is not set.
|
||||
function Comm::vector_lookup%(v: Comm::Data, idx: count%): Comm::Data
|
||||
function BrokerComm::vector_lookup%(v: BrokerComm::Data, idx: count%): BrokerComm::Data
|
||||
%{
|
||||
auto& vec = comm::require_data_type<broker::vector>(v->AsRecordVal(),
|
||||
auto& vec = bro_broker::require_data_type<broker::vector>(v->AsRecordVal(),
|
||||
TYPE_VECTOR, frame);
|
||||
|
||||
if ( idx >= vec.size() )
|
||||
return new RecordVal(BifType::Record::Comm::Data);
|
||||
return new RecordVal(BifType::Record::BrokerComm::Data);
|
||||
|
||||
return comm::make_data_val(vec[idx]);
|
||||
return bro_broker::make_data_val(vec[idx]);
|
||||
%}
|
||||
|
||||
## Create an iterator for a vector. Note that this makes a copy of the vector
|
||||
|
@ -643,9 +643,9 @@ function Comm::vector_lookup%(v: Comm::Data, idx: count%): Comm::Data
|
|||
## v: the vector to iterate over.
|
||||
##
|
||||
## Returns: an iterator.
|
||||
function Comm::vector_iterator%(v: Comm::Data%): opaque of Comm::VectorIterator
|
||||
function BrokerComm::vector_iterator%(v: BrokerComm::Data%): opaque of BrokerComm::VectorIterator
|
||||
%{
|
||||
return new comm::VectorIterator(v->AsRecordVal(), TYPE_VECTOR, frame);
|
||||
return new bro_broker::VectorIterator(v->AsRecordVal(), TYPE_VECTOR, frame);
|
||||
%}
|
||||
|
||||
## Check if there are no more elements to iterate over.
|
||||
|
@ -654,9 +654,9 @@ function Comm::vector_iterator%(v: Comm::Data%): opaque of Comm::VectorIterator
|
|||
##
|
||||
## Returns: true if there are no more elements to iterator over, i.e.
|
||||
## the iterator is one-past-the-final-element.
|
||||
function Comm::vector_iterator_last%(it: opaque of Comm::VectorIterator%): bool
|
||||
function BrokerComm::vector_iterator_last%(it: opaque of BrokerComm::VectorIterator%): bool
|
||||
%{
|
||||
auto vi = static_cast<comm::VectorIterator*>(it);
|
||||
auto vi = static_cast<bro_broker::VectorIterator*>(it);
|
||||
return new Val(vi->it == vi->dat.end(), TYPE_BOOL);
|
||||
%}
|
||||
|
||||
|
@ -667,9 +667,9 @@ function Comm::vector_iterator_last%(it: opaque of Comm::VectorIterator%): bool
|
|||
## Returns: true if the iterator, after advancing, still references an element
|
||||
## in the collection. False if the iterator, after advancing, is
|
||||
## one-past-the-final-element.
|
||||
function Comm::vector_iterator_next%(it: opaque of Comm::VectorIterator%): bool
|
||||
function BrokerComm::vector_iterator_next%(it: opaque of BrokerComm::VectorIterator%): bool
|
||||
%{
|
||||
auto vi = static_cast<comm::VectorIterator*>(it);
|
||||
auto vi = static_cast<bro_broker::VectorIterator*>(it);
|
||||
|
||||
if ( vi->it == vi->dat.end() )
|
||||
return new Val(false, TYPE_BOOL);
|
||||
|
@ -683,10 +683,10 @@ function Comm::vector_iterator_next%(it: opaque of Comm::VectorIterator%): bool
|
|||
## it: an iterator.
|
||||
##
|
||||
## Returns: element in the collection that the iterator currently references.
|
||||
function Comm::vector_iterator_value%(it: opaque of Comm::VectorIterator%): Comm::Data
|
||||
function BrokerComm::vector_iterator_value%(it: opaque of BrokerComm::VectorIterator%): BrokerComm::Data
|
||||
%{
|
||||
auto vi = static_cast<comm::VectorIterator*>(it);
|
||||
auto rval = new RecordVal(BifType::Record::Comm::Data);
|
||||
auto vi = static_cast<bro_broker::VectorIterator*>(it);
|
||||
auto rval = new RecordVal(BifType::Record::BrokerComm::Data);
|
||||
|
||||
if ( vi->it == vi->dat.end() )
|
||||
{
|
||||
|
@ -696,7 +696,7 @@ function Comm::vector_iterator_value%(it: opaque of Comm::VectorIterator%): Comm
|
|||
return rval;
|
||||
}
|
||||
|
||||
rval->Assign(0, new comm::DataVal(*vi->it));
|
||||
rval->Assign(0, new bro_broker::DataVal(*vi->it));
|
||||
return rval;
|
||||
%}
|
||||
|
||||
|
@ -705,9 +705,9 @@ function Comm::vector_iterator_value%(it: opaque of Comm::VectorIterator%): Comm
|
|||
## sz: the number of fields in the record.
|
||||
##
|
||||
## Returns: record data, with all fields uninitialized.
|
||||
function Comm::record_create%(sz: count%): Comm::Data
|
||||
function BrokerComm::record_create%(sz: count%): BrokerComm::Data
|
||||
%{
|
||||
return comm::make_data_val(broker::record(std::vector<broker::record::field>(sz)));
|
||||
return bro_broker::make_data_val(broker::record(std::vector<broker::record::field>(sz)));
|
||||
%}
|
||||
|
||||
## Get the number of fields within a record.
|
||||
|
@ -715,9 +715,9 @@ function Comm::record_create%(sz: count%): Comm::Data
|
|||
## r: the record to query.
|
||||
##
|
||||
## Returns: the number of fields in the record.
|
||||
function Comm::record_size%(r: Comm::Data%): count
|
||||
function BrokerComm::record_size%(r: BrokerComm::Data%): count
|
||||
%{
|
||||
auto& v = comm::require_data_type<broker::record>(r->AsRecordVal(),
|
||||
auto& v = bro_broker::require_data_type<broker::record>(r->AsRecordVal(),
|
||||
TYPE_RECORD, frame);
|
||||
return new Val(static_cast<uint64_t>(v.fields.size()), TYPE_COUNT);
|
||||
%}
|
||||
|
@ -731,11 +731,11 @@ function Comm::record_size%(r: Comm::Data%): count
|
|||
## idx: the index to replace.
|
||||
##
|
||||
## Returns: false if the index was larger than any valid index, else true.
|
||||
function Comm::record_assign%(r: Comm::Data, d: Comm::Data, idx: count%): bool
|
||||
function BrokerComm::record_assign%(r: BrokerComm::Data, d: BrokerComm::Data, idx: count%): bool
|
||||
%{
|
||||
auto& v = comm::require_data_type<broker::record>(r->AsRecordVal(),
|
||||
auto& v = bro_broker::require_data_type<broker::record>(r->AsRecordVal(),
|
||||
TYPE_RECORD, frame);
|
||||
auto& item = comm::opaque_field_to_data(d->AsRecordVal(), frame);
|
||||
auto& item = bro_broker::opaque_field_to_data(d->AsRecordVal(), frame);
|
||||
|
||||
if ( idx >= v.fields.size() )
|
||||
return new Val(false, TYPE_BOOL);
|
||||
|
@ -753,18 +753,18 @@ function Comm::record_assign%(r: Comm::Data, d: Comm::Data, idx: count%): bool
|
|||
## Returns: the value at the index. The optional field of the returned record
|
||||
## may not be set if the field of the record has no value or if the
|
||||
## the index was not valid.
|
||||
function Comm::record_lookup%(r: Comm::Data, idx: count%): Comm::Data
|
||||
function BrokerComm::record_lookup%(r: BrokerComm::Data, idx: count%): BrokerComm::Data
|
||||
%{
|
||||
auto& v = comm::require_data_type<broker::record>(r->AsRecordVal(),
|
||||
auto& v = bro_broker::require_data_type<broker::record>(r->AsRecordVal(),
|
||||
TYPE_RECORD, frame);
|
||||
|
||||
if ( idx >= v.size() )
|
||||
return new RecordVal(BifType::Record::Comm::Data);
|
||||
return new RecordVal(BifType::Record::BrokerComm::Data);
|
||||
|
||||
if ( ! v.fields[idx] )
|
||||
return new RecordVal(BifType::Record::Comm::Data);
|
||||
return new RecordVal(BifType::Record::BrokerComm::Data);
|
||||
|
||||
return comm::make_data_val(*v.fields[idx]);
|
||||
return bro_broker::make_data_val(*v.fields[idx]);
|
||||
%}
|
||||
|
||||
## Create an iterator for a record. Note that this makes a copy of the record
|
||||
|
@ -773,9 +773,9 @@ function Comm::record_lookup%(r: Comm::Data, idx: count%): Comm::Data
|
|||
## r: the record to iterate over.
|
||||
##
|
||||
## Returns: an iterator.
|
||||
function Comm::record_iterator%(r: Comm::Data%): opaque of Comm::RecordIterator
|
||||
function BrokerComm::record_iterator%(r: BrokerComm::Data%): opaque of BrokerComm::RecordIterator
|
||||
%{
|
||||
return new comm::RecordIterator(r->AsRecordVal(), TYPE_RECORD, frame);
|
||||
return new bro_broker::RecordIterator(r->AsRecordVal(), TYPE_RECORD, frame);
|
||||
%}
|
||||
|
||||
## Check if there are no more elements to iterate over.
|
||||
|
@ -784,9 +784,9 @@ function Comm::record_iterator%(r: Comm::Data%): opaque of Comm::RecordIterator
|
|||
##
|
||||
## Returns: true if there are no more elements to iterator over, i.e.
|
||||
## the iterator is one-past-the-final-element.
|
||||
function Comm::record_iterator_last%(it: opaque of Comm::RecordIterator%): bool
|
||||
function BrokerComm::record_iterator_last%(it: opaque of BrokerComm::RecordIterator%): bool
|
||||
%{
|
||||
auto ri = static_cast<comm::RecordIterator*>(it);
|
||||
auto ri = static_cast<bro_broker::RecordIterator*>(it);
|
||||
return new Val(ri->it == ri->dat.fields.end(), TYPE_BOOL);
|
||||
%}
|
||||
|
||||
|
@ -797,9 +797,9 @@ function Comm::record_iterator_last%(it: opaque of Comm::RecordIterator%): bool
|
|||
## Returns: true if the iterator, after advancing, still references an element
|
||||
## in the collection. False if the iterator, after advancing, is
|
||||
## one-past-the-final-element.
|
||||
function Comm::record_iterator_next%(it: opaque of Comm::RecordIterator%): bool
|
||||
function BrokerComm::record_iterator_next%(it: opaque of BrokerComm::RecordIterator%): bool
|
||||
%{
|
||||
auto ri = static_cast<comm::RecordIterator*>(it);
|
||||
auto ri = static_cast<bro_broker::RecordIterator*>(it);
|
||||
|
||||
if ( ri->it == ri->dat.fields.end() )
|
||||
return new Val(false, TYPE_BOOL);
|
||||
|
@ -813,10 +813,10 @@ function Comm::record_iterator_next%(it: opaque of Comm::RecordIterator%): bool
|
|||
## it: an iterator.
|
||||
##
|
||||
## Returns: element in the collection that the iterator currently references.
|
||||
function Comm::record_iterator_value%(it: opaque of Comm::RecordIterator%): Comm::Data
|
||||
function BrokerComm::record_iterator_value%(it: opaque of BrokerComm::RecordIterator%): BrokerComm::Data
|
||||
%{
|
||||
auto ri = static_cast<comm::RecordIterator*>(it);
|
||||
auto rval = new RecordVal(BifType::Record::Comm::Data);
|
||||
auto ri = static_cast<bro_broker::RecordIterator*>(it);
|
||||
auto rval = new RecordVal(BifType::Record::BrokerComm::Data);
|
||||
|
||||
if ( ri->it == ri->dat.fields.end() )
|
||||
{
|
||||
|
@ -829,6 +829,6 @@ function Comm::record_iterator_value%(it: opaque of Comm::RecordIterator%): Comm
|
|||
if ( ! *ri->it )
|
||||
return rval; // field isn't set
|
||||
|
||||
rval->Assign(0, new comm::DataVal(**ri->it));
|
||||
rval->Assign(0, new bro_broker::DataVal(**ri->it));
|
||||
return rval;
|
||||
%}
|
|
@ -2,22 +2,22 @@
|
|||
##! Functions for peering and various messaging patterns (e.g. print/log/event).
|
||||
|
||||
%%{
|
||||
#include "comm/Manager.h"
|
||||
#include "broker/Manager.h"
|
||||
#include "logging/Manager.h"
|
||||
%%}
|
||||
|
||||
module Comm;
|
||||
module BrokerComm;
|
||||
|
||||
type Comm::SendFlags: record;
|
||||
type BrokerComm::SendFlags: record;
|
||||
|
||||
type Comm::EventArgs: record;
|
||||
type BrokerComm::EventArgs: record;
|
||||
|
||||
## Used to handle remote print messages from peers that call
|
||||
## :bro:see:`Comm::print`.
|
||||
event Comm::print_handler%(msg: string%);
|
||||
## :bro:see:`BrokerComm::print`.
|
||||
event BrokerComm::print_handler%(msg: string%);
|
||||
|
||||
## Print a simple message to any interested peers. The receiver can use
|
||||
## :bro:see:`Comm::print_handler` to handle messages.
|
||||
## :bro:see:`BrokerComm::print_handler` to handle messages.
|
||||
##
|
||||
## topic: a topic associated with the printed message.
|
||||
##
|
||||
|
@ -26,50 +26,50 @@ event Comm::print_handler%(msg: string%);
|
|||
## flags: tune the behavior of how the message is sent.
|
||||
##
|
||||
## Returns: true if the message is sent.
|
||||
function Comm::print%(topic: string, msg: string,
|
||||
function BrokerComm::print%(topic: string, msg: string,
|
||||
flags: SendFlags &default = SendFlags()%): bool
|
||||
%{
|
||||
auto rval = comm_mgr->Print(topic->CheckString(), msg->CheckString(),
|
||||
auto rval = broker_mgr->Print(topic->CheckString(), msg->CheckString(),
|
||||
flags);
|
||||
return new Val(rval, TYPE_BOOL);
|
||||
%}
|
||||
|
||||
## Register interest in all peer print messages that use a certain topic prefix.
|
||||
## use :bro:see:`Comm::print_handler` to handle received messages.
|
||||
## use :bro:see:`BrokerComm::print_handler` to handle received messages.
|
||||
##
|
||||
## topic_prefix: a prefix to match against remote message topics.
|
||||
## e.g. an empty prefix matches everything and "a" matches
|
||||
## "alice" and "amy" but not "bob".
|
||||
##
|
||||
## Returns: true if it's a new print subscription and it is now registered.
|
||||
function Comm::subscribe_to_prints%(topic_prefix: string%): bool
|
||||
function BrokerComm::subscribe_to_prints%(topic_prefix: string%): bool
|
||||
%{
|
||||
auto rval = comm_mgr->SubscribeToPrints(topic_prefix->CheckString());
|
||||
auto rval = broker_mgr->SubscribeToPrints(topic_prefix->CheckString());
|
||||
return new Val(rval, TYPE_BOOL);
|
||||
%}
|
||||
|
||||
## Unregister interest in all peer print messages that use a topic prefix.
|
||||
##
|
||||
## topic_prefix: a prefix previously supplied to a successful call to
|
||||
## :bro:see:`Comm::subscribe_to_prints`.
|
||||
## :bro:see:`BrokerComm::subscribe_to_prints`.
|
||||
##
|
||||
## Returns: true if interest in the topic prefix is no longer advertised.
|
||||
function Comm::unsubscribe_to_prints%(topic_prefix: string%): bool
|
||||
function BrokerComm::unsubscribe_to_prints%(topic_prefix: string%): bool
|
||||
%{
|
||||
auto rval = comm_mgr->UnsubscribeToPrints(topic_prefix->CheckString());
|
||||
auto rval = broker_mgr->UnsubscribeToPrints(topic_prefix->CheckString());
|
||||
return new Val(rval, TYPE_BOOL);
|
||||
%}
|
||||
|
||||
## Create a data structure that may be used to send a remote event via
|
||||
## :bro:see:`Comm::event`.
|
||||
## :bro:see:`BrokerComm::event`.
|
||||
##
|
||||
## args: an event, followed by a list of argument values that may be used
|
||||
## to call it.
|
||||
##
|
||||
## Returns: opaque communication data that may be used to send a remote event.
|
||||
function Comm::event_args%(...%): Comm::EventArgs
|
||||
function BrokerComm::event_args%(...%): BrokerComm::EventArgs
|
||||
%{
|
||||
auto rval = comm_mgr->MakeEventArgs(@ARGS@);
|
||||
auto rval = broker_mgr->MakeEventArgs(@ARGS@);
|
||||
return rval;
|
||||
%}
|
||||
|
||||
|
@ -77,15 +77,15 @@ function Comm::event_args%(...%): Comm::EventArgs
|
|||
##
|
||||
## topic: a topic associated with the event message.
|
||||
##
|
||||
## args: event arguments as made by :bro:see:`Comm::event_args`.
|
||||
## args: event arguments as made by :bro:see:`BrokerComm::event_args`.
|
||||
##
|
||||
## flags: tune the behavior of how the message is sent.
|
||||
##
|
||||
## Returns: true if the message is sent.
|
||||
function Comm::event%(topic: string, args: Comm::EventArgs,
|
||||
function BrokerComm::event%(topic: string, args: BrokerComm::EventArgs,
|
||||
flags: SendFlags &default = SendFlags()%): bool
|
||||
%{
|
||||
auto rval = comm_mgr->Event(topic->CheckString(), args->AsRecordVal(),
|
||||
auto rval = broker_mgr->Event(topic->CheckString(), args->AsRecordVal(),
|
||||
flags);
|
||||
return new Val(rval, TYPE_BOOL);
|
||||
%}
|
||||
|
@ -102,23 +102,23 @@ function Comm::event%(topic: string, args: Comm::EventArgs,
|
|||
## flags: tune the behavior of how the message is send.
|
||||
##
|
||||
## Returns: true if automatic event sending is now enabled.
|
||||
function Comm::auto_event%(topic: string, ev: any,
|
||||
function BrokerComm::auto_event%(topic: string, ev: any,
|
||||
flags: SendFlags &default = SendFlags()%): bool
|
||||
%{
|
||||
auto rval = comm_mgr->AutoEvent(topic->CheckString(), ev, flags);
|
||||
auto rval = broker_mgr->AutoEvent(topic->CheckString(), ev, flags);
|
||||
return new Val(rval, TYPE_BOOL);
|
||||
%}
|
||||
|
||||
## Stop automatically sending an event to peers upon local dispatch.
|
||||
##
|
||||
## topic: a topic originally given to :bro:see:`Comm::auto_event`.
|
||||
## topic: a topic originally given to :bro:see:`BrokerComm::auto_event`.
|
||||
##
|
||||
## ev: an event originally given to :bro:see:`Comm::auto_event`.
|
||||
## ev: an event originally given to :bro:see:`BrokerComm::auto_event`.
|
||||
##
|
||||
## Returns: true if automatic events will no occur for the topic/event pair.
|
||||
function Comm::auto_event_stop%(topic: string, ev: any%): bool
|
||||
function BrokerComm::auto_event_stop%(topic: string, ev: any%): bool
|
||||
%{
|
||||
auto rval = comm_mgr->AutoEventStop(topic->CheckString(), ev);
|
||||
auto rval = broker_mgr->AutoEventStop(topic->CheckString(), ev);
|
||||
return new Val(rval, TYPE_BOOL);
|
||||
%}
|
||||
|
||||
|
@ -129,21 +129,21 @@ function Comm::auto_event_stop%(topic: string, ev: any%): bool
|
|||
## "alice" and "amy" but not "bob".
|
||||
##
|
||||
## Returns: true if it's a new event subscription and it is now registered.
|
||||
function Comm::subscribe_to_events%(topic_prefix: string%): bool
|
||||
function BrokerComm::subscribe_to_events%(topic_prefix: string%): bool
|
||||
%{
|
||||
auto rval = comm_mgr->SubscribeToEvents(topic_prefix->CheckString());
|
||||
auto rval = broker_mgr->SubscribeToEvents(topic_prefix->CheckString());
|
||||
return new Val(rval, TYPE_BOOL);
|
||||
%}
|
||||
|
||||
## Unregister interest in all peer event messages that use a topic prefix.
|
||||
##
|
||||
## topic_prefix: a prefix previously supplied to a successful call to
|
||||
## :bro:see:`Comm::subscribe_to_events`.
|
||||
## :bro:see:`BrokerComm::subscribe_to_events`.
|
||||
##
|
||||
## Returns: true if interest in the topic prefix is no longer advertised.
|
||||
function Comm::unsubscribe_to_events%(topic_prefix: string%): bool
|
||||
function BrokerComm::unsubscribe_to_events%(topic_prefix: string%): bool
|
||||
%{
|
||||
auto rval = comm_mgr->UnsubscribeToEvents(topic_prefix->CheckString());
|
||||
auto rval = broker_mgr->UnsubscribeToEvents(topic_prefix->CheckString());
|
||||
return new Val(rval, TYPE_BOOL);
|
||||
%}
|
||||
|
||||
|
@ -155,11 +155,11 @@ function Comm::unsubscribe_to_events%(topic_prefix: string%): bool
|
|||
##
|
||||
## Returns: true if remote logs are enabled for the stream.
|
||||
function
|
||||
Comm::enable_remote_logs%(id: Log::ID,
|
||||
BrokerComm::enable_remote_logs%(id: Log::ID,
|
||||
flags: SendFlags &default = SendFlags()%): bool
|
||||
%{
|
||||
auto rval = log_mgr->EnableRemoteLogs(id->AsEnumVal(),
|
||||
comm::Manager::send_flags_to_int(flags));
|
||||
bro_broker::Manager::send_flags_to_int(flags));
|
||||
return new Val(rval, TYPE_BOOL);
|
||||
%}
|
||||
|
||||
|
@ -168,14 +168,14 @@ Comm::enable_remote_logs%(id: Log::ID,
|
|||
## id: the log stream to disable remote logs for.
|
||||
##
|
||||
## Returns: true if remote logs are disabled for the stream.
|
||||
function Comm::disable_remote_logs%(id: Log::ID%): bool
|
||||
function BrokerComm::disable_remote_logs%(id: Log::ID%): bool
|
||||
%{
|
||||
auto rval = log_mgr->DisableRemoteLogs(id->AsEnumVal());
|
||||
return new Val(rval, TYPE_BOOL);
|
||||
%}
|
||||
|
||||
## Returns: true if remote logs are enabled for the given stream.
|
||||
function Comm::remote_logs_enabled%(id: Log::ID%): bool
|
||||
function BrokerComm::remote_logs_enabled%(id: Log::ID%): bool
|
||||
%{
|
||||
auto rval = log_mgr->RemoteLogsAreEnabled(id->AsEnumVal());
|
||||
return new Val(rval, TYPE_BOOL);
|
||||
|
@ -190,9 +190,9 @@ function Comm::remote_logs_enabled%(id: Log::ID%): bool
|
|||
## "alice" and "amy" but not "bob".
|
||||
##
|
||||
## Returns: true if it's a new log subscription and it is now registered.
|
||||
function Comm::subscribe_to_logs%(topic_prefix: string%): bool
|
||||
function BrokerComm::subscribe_to_logs%(topic_prefix: string%): bool
|
||||
%{
|
||||
auto rval = comm_mgr->SubscribeToLogs(topic_prefix->CheckString());
|
||||
auto rval = broker_mgr->SubscribeToLogs(topic_prefix->CheckString());
|
||||
return new Val(rval, TYPE_BOOL);
|
||||
%}
|
||||
|
||||
|
@ -201,11 +201,11 @@ function Comm::subscribe_to_logs%(topic_prefix: string%): bool
|
|||
## receiving side processes them through the logging framework as usual.
|
||||
##
|
||||
## topic_prefix: a prefix previously supplied to a successful call to
|
||||
## :bro:see:`Comm::subscribe_to_logs`.
|
||||
## :bro:see:`BrokerComm::subscribe_to_logs`.
|
||||
##
|
||||
## Returns: true if interest in the topic prefix is no longer advertised.
|
||||
function Comm::unsubscribe_to_logs%(topic_prefix: string%): bool
|
||||
function BrokerComm::unsubscribe_to_logs%(topic_prefix: string%): bool
|
||||
%{
|
||||
auto rval = comm_mgr->UnsubscribeToLogs(topic_prefix->CheckString());
|
||||
auto rval = broker_mgr->UnsubscribeToLogs(topic_prefix->CheckString());
|
||||
return new Val(rval, TYPE_BOOL);
|
||||
%}
|
|
@ -2,19 +2,19 @@
|
|||
##! Functions to interface with broker's distributed data store.
|
||||
|
||||
%%{
|
||||
#include "comm/Manager.h"
|
||||
#include "comm/Store.h"
|
||||
#include "comm/Data.h"
|
||||
#include "broker/Manager.h"
|
||||
#include "broker/Store.h"
|
||||
#include "broker/Data.h"
|
||||
#include "Trigger.h"
|
||||
%%}
|
||||
|
||||
module Store;
|
||||
module BrokerStore;
|
||||
|
||||
type Store::ExpiryTime: record;
|
||||
type BrokerStore::ExpiryTime: record;
|
||||
|
||||
type Store::QueryResult: record;
|
||||
type BrokerStore::QueryResult: record;
|
||||
|
||||
type Store::BackendOptions: record;
|
||||
type BrokerStore::BackendOptions: record;
|
||||
|
||||
## Enumerates the possible storage backends.
|
||||
enum BackendType %{
|
||||
|
@ -32,12 +32,12 @@ enum BackendType %{
|
|||
## options: tunes how some storage backends operate.
|
||||
##
|
||||
## Returns: a handle to the data store.
|
||||
function Store::create_master%(id: string, b: BackendType &default = MEMORY,
|
||||
options: BackendOptions &default = BackendOptions()%): opaque of Store::Handle
|
||||
function BrokerStore::create_master%(id: string, b: BackendType &default = MEMORY,
|
||||
options: BackendOptions &default = BackendOptions()%): opaque of BrokerStore::Handle
|
||||
%{
|
||||
auto id_str = id->CheckString();
|
||||
auto type = comm::StoreType::MASTER;
|
||||
auto rval = comm_mgr->LookupStore(id_str, type);
|
||||
auto type = bro_broker::StoreType::MASTER;
|
||||
auto rval = broker_mgr->LookupStore(id_str, type);
|
||||
|
||||
if ( rval )
|
||||
{
|
||||
|
@ -45,10 +45,10 @@ function Store::create_master%(id: string, b: BackendType &default = MEMORY,
|
|||
return rval;
|
||||
}
|
||||
|
||||
rval = new comm::StoreHandleVal(id_str, type,
|
||||
static_cast<BifEnum::Store::BackendType>(b->AsEnum()),
|
||||
rval = new bro_broker::StoreHandleVal(id_str, type,
|
||||
static_cast<BifEnum::BrokerStore::BackendType>(b->AsEnum()),
|
||||
options->AsRecordVal());
|
||||
assert(comm_mgr->AddStore(rval));
|
||||
assert(broker_mgr->AddStore(rval));
|
||||
return rval;
|
||||
%}
|
||||
|
||||
|
@ -74,13 +74,13 @@ function Store::create_master%(id: string, b: BackendType &default = MEMORY,
|
|||
## but updates will be lost until the master is once again available.
|
||||
##
|
||||
## Returns: a handle to the data store.
|
||||
function Store::create_clone%(id: string, b: BackendType &default = MEMORY,
|
||||
function BrokerStore::create_clone%(id: string, b: BackendType &default = MEMORY,
|
||||
options: BackendOptions &default = BackendOptions(),
|
||||
resync: interval &default = 1sec%): opaque of Store::Handle
|
||||
resync: interval &default = 1sec%): opaque of BrokerStore::Handle
|
||||
%{
|
||||
auto id_str = id->CheckString();
|
||||
auto type = comm::StoreType::CLONE;
|
||||
auto rval = comm_mgr->LookupStore(id_str, type);
|
||||
auto type = bro_broker::StoreType::CLONE;
|
||||
auto rval = broker_mgr->LookupStore(id_str, type);
|
||||
|
||||
if ( rval )
|
||||
{
|
||||
|
@ -88,11 +88,11 @@ function Store::create_clone%(id: string, b: BackendType &default = MEMORY,
|
|||
return rval;
|
||||
}
|
||||
|
||||
rval = new comm::StoreHandleVal(id_str, type,
|
||||
static_cast<BifEnum::Store::BackendType>(b->AsEnum()),
|
||||
rval = new bro_broker::StoreHandleVal(id_str, type,
|
||||
static_cast<BifEnum::BrokerStore::BackendType>(b->AsEnum()),
|
||||
options->AsRecordVal(),
|
||||
std::chrono::duration<double>(resync));
|
||||
assert(comm_mgr->AddStore(rval));
|
||||
assert(broker_mgr->AddStore(rval));
|
||||
return rval;
|
||||
%}
|
||||
|
||||
|
@ -102,11 +102,11 @@ function Store::create_clone%(id: string, b: BackendType &default = MEMORY,
|
|||
## id: the unique name which identifies the master data store.
|
||||
##
|
||||
## Returns: a handle to the data store.
|
||||
function Store::create_frontend%(id: string%): opaque of Store::Handle
|
||||
function BrokerStore::create_frontend%(id: string%): opaque of BrokerStore::Handle
|
||||
%{
|
||||
auto id_str = id->CheckString();
|
||||
auto type = comm::StoreType::FRONTEND;
|
||||
auto rval = comm_mgr->LookupStore(id_str, type);
|
||||
auto type = bro_broker::StoreType::FRONTEND;
|
||||
auto rval = broker_mgr->LookupStore(id_str, type);
|
||||
|
||||
if ( rval )
|
||||
{
|
||||
|
@ -114,8 +114,8 @@ function Store::create_frontend%(id: string%): opaque of Store::Handle
|
|||
return rval;
|
||||
}
|
||||
|
||||
rval = new comm::StoreHandleVal(id_str, type, {}, nullptr);
|
||||
assert(comm_mgr->AddStore(rval));
|
||||
rval = new bro_broker::StoreHandleVal(id_str, type, {}, nullptr);
|
||||
assert(broker_mgr->AddStore(rval));
|
||||
return rval;
|
||||
%}
|
||||
|
||||
|
@ -125,14 +125,14 @@ function Store::create_frontend%(id: string%): opaque of Store::Handle
|
|||
##
|
||||
## Returns: true if store was valid and is now closed. The handle can no
|
||||
## longer be used for data store operations.
|
||||
function Store::close_by_handle%(h: opaque of Store::Handle%): bool
|
||||
function BrokerStore::close_by_handle%(h: opaque of BrokerStore::Handle%): bool
|
||||
%{
|
||||
auto handle = static_cast<comm::StoreHandleVal*>(h);
|
||||
auto handle = static_cast<bro_broker::StoreHandleVal*>(h);
|
||||
|
||||
if ( ! handle->store )
|
||||
return new Val(false, TYPE_BOOL);
|
||||
|
||||
return new Val(comm_mgr->CloseStore(handle->store->id(),
|
||||
return new Val(broker_mgr->CloseStore(handle->store->id(),
|
||||
handle->store_type), TYPE_BOOL);
|
||||
%}
|
||||
|
||||
|
@ -151,26 +151,25 @@ function Store::close_by_handle%(h: opaque of Store::Handle%): bool
|
|||
## e: the expiration time of the key-value pair.
|
||||
##
|
||||
## Returns: false if the store handle was not valid.
|
||||
function Store::insert%(h: opaque of Store::Handle,
|
||||
k: Comm::Data, v: Comm::Data,
|
||||
e: Store::ExpiryTime &default = Store::ExpiryTime()%): bool
|
||||
function BrokerStore::insert%(h: opaque of BrokerStore::Handle,
|
||||
k: BrokerComm::Data, v: BrokerComm::Data,
|
||||
e: BrokerStore::ExpiryTime &default = BrokerStore::ExpiryTime()%): bool
|
||||
%{
|
||||
auto handle = static_cast<comm::StoreHandleVal*>(h);
|
||||
auto handle = static_cast<bro_broker::StoreHandleVal*>(h);
|
||||
|
||||
if ( ! handle->store )
|
||||
return new Val(false, TYPE_BOOL);
|
||||
|
||||
auto& key = comm::opaque_field_to_data(k->AsRecordVal(), frame);
|
||||
auto& val = comm::opaque_field_to_data(v->AsRecordVal(), frame);
|
||||
auto& key = bro_broker::opaque_field_to_data(k->AsRecordVal(), frame);
|
||||
auto& val = bro_broker::opaque_field_to_data(v->AsRecordVal(), frame);
|
||||
|
||||
using broker::store::expiration_time;
|
||||
broker::util::optional<expiration_time> expiry;
|
||||
|
||||
auto abs_expiry_val = e->AsRecordVal()->Lookup(0);
|
||||
|
||||
if ( abs_expiry_val )
|
||||
{
|
||||
expiry = expiration_time(abs_expiry_val->AsTime());
|
||||
auto expiry = expiration_time(abs_expiry_val->AsTime());
|
||||
handle->store->insert(key, val, expiry);
|
||||
return new Val(true, TYPE_BOOL);
|
||||
}
|
||||
|
@ -180,12 +179,12 @@ function Store::insert%(h: opaque of Store::Handle,
|
|||
if ( rel_expiry_val )
|
||||
{
|
||||
auto ct = broker::time_point::now().value;
|
||||
expiry = expiration_time(rel_expiry_val->AsInterval(), ct);
|
||||
auto expiry = expiration_time(rel_expiry_val->AsInterval(), ct);
|
||||
handle->store->insert(key, val, expiry);
|
||||
return new Val(true, TYPE_BOOL);
|
||||
}
|
||||
|
||||
handle->store->insert(key, val, expiry);
|
||||
handle->store->insert(key, val);
|
||||
return new Val(true, TYPE_BOOL);
|
||||
%}
|
||||
|
||||
|
@ -196,14 +195,14 @@ function Store::insert%(h: opaque of Store::Handle,
|
|||
## k: the key to remove.
|
||||
##
|
||||
## Returns: false if the store handle was not valid.
|
||||
function Store::erase%(h: opaque of Store::Handle, k: Comm::Data%): bool
|
||||
function BrokerStore::erase%(h: opaque of BrokerStore::Handle, k: BrokerComm::Data%): bool
|
||||
%{
|
||||
auto handle = static_cast<comm::StoreHandleVal*>(h);
|
||||
auto handle = static_cast<bro_broker::StoreHandleVal*>(h);
|
||||
|
||||
if ( ! handle->store )
|
||||
return new Val(false, TYPE_BOOL);
|
||||
|
||||
auto& key = comm::opaque_field_to_data(k->AsRecordVal(), frame);
|
||||
auto& key = bro_broker::opaque_field_to_data(k->AsRecordVal(), frame);
|
||||
handle->store->erase(key);
|
||||
return new Val(true, TYPE_BOOL);
|
||||
%}
|
||||
|
@ -213,9 +212,9 @@ function Store::erase%(h: opaque of Store::Handle, k: Comm::Data%): bool
|
|||
## h: the handle of the store to modify.
|
||||
##
|
||||
## Returns: false if the store handle was not valid.
|
||||
function Store::clear%(h: opaque of Store::Handle%): bool
|
||||
function BrokerStore::clear%(h: opaque of BrokerStore::Handle%): bool
|
||||
%{
|
||||
auto handle = static_cast<comm::StoreHandleVal*>(h);
|
||||
auto handle = static_cast<bro_broker::StoreHandleVal*>(h);
|
||||
|
||||
if ( ! handle->store )
|
||||
return new Val(false, TYPE_BOOL);
|
||||
|
@ -234,15 +233,15 @@ function Store::clear%(h: opaque of Store::Handle%): bool
|
|||
## create it with an implicit value of zero before incrementing.
|
||||
##
|
||||
## Returns: false if the store handle was not valid.
|
||||
function Store::increment%(h: opaque of Store::Handle,
|
||||
k: Comm::Data, by: int &default = +1%): bool
|
||||
function BrokerStore::increment%(h: opaque of BrokerStore::Handle,
|
||||
k: BrokerComm::Data, by: int &default = +1%): bool
|
||||
%{
|
||||
auto handle = static_cast<comm::StoreHandleVal*>(h);
|
||||
auto handle = static_cast<bro_broker::StoreHandleVal*>(h);
|
||||
|
||||
if ( ! handle->store )
|
||||
return new Val(false, TYPE_BOOL);
|
||||
|
||||
auto& key = comm::opaque_field_to_data(k->AsRecordVal(), frame);
|
||||
auto& key = bro_broker::opaque_field_to_data(k->AsRecordVal(), frame);
|
||||
handle->store->increment(key, by);
|
||||
return new Val(true, TYPE_BOOL);
|
||||
%}
|
||||
|
@ -257,15 +256,15 @@ function Store::increment%(h: opaque of Store::Handle,
|
|||
## create it with an implicit value of zero before decrementing.
|
||||
##
|
||||
## Returns: false if the store handle was not valid.
|
||||
function Store::decrement%(h: opaque of Store::Handle,
|
||||
k: Comm::Data, by: int &default = +1%): bool
|
||||
function BrokerStore::decrement%(h: opaque of BrokerStore::Handle,
|
||||
k: BrokerComm::Data, by: int &default = +1%): bool
|
||||
%{
|
||||
auto handle = static_cast<comm::StoreHandleVal*>(h);
|
||||
auto handle = static_cast<bro_broker::StoreHandleVal*>(h);
|
||||
|
||||
if ( ! handle->store )
|
||||
return new Val(false, TYPE_BOOL);
|
||||
|
||||
auto& key = comm::opaque_field_to_data(k->AsRecordVal(), frame);
|
||||
auto& key = bro_broker::opaque_field_to_data(k->AsRecordVal(), frame);
|
||||
handle->store->decrement(key, by);
|
||||
return new Val(true, TYPE_BOOL);
|
||||
%}
|
||||
|
@ -280,16 +279,16 @@ function Store::decrement%(h: opaque of Store::Handle,
|
|||
## create it with an implicit empty set value before modifying.
|
||||
##
|
||||
## Returns: false if the store handle was not valid.
|
||||
function Store::add_to_set%(h: opaque of Store::Handle,
|
||||
k: Comm::Data, element: Comm::Data%): bool
|
||||
function BrokerStore::add_to_set%(h: opaque of BrokerStore::Handle,
|
||||
k: BrokerComm::Data, element: BrokerComm::Data%): bool
|
||||
%{
|
||||
auto handle = static_cast<comm::StoreHandleVal*>(h);
|
||||
auto handle = static_cast<bro_broker::StoreHandleVal*>(h);
|
||||
|
||||
if ( ! handle->store )
|
||||
return new Val(false, TYPE_BOOL);
|
||||
|
||||
auto& key = comm::opaque_field_to_data(k->AsRecordVal(), frame);
|
||||
auto& ele = comm::opaque_field_to_data(element->AsRecordVal(), frame);
|
||||
auto& key = bro_broker::opaque_field_to_data(k->AsRecordVal(), frame);
|
||||
auto& ele = bro_broker::opaque_field_to_data(element->AsRecordVal(), frame);
|
||||
handle->store->add_to_set(key, ele);
|
||||
return new Val(true, TYPE_BOOL);
|
||||
%}
|
||||
|
@ -304,16 +303,16 @@ function Store::add_to_set%(h: opaque of Store::Handle,
|
|||
## implicitly create an empty set value associated with the key.
|
||||
##
|
||||
## Returns: false if the store handle was not valid.
|
||||
function Store::remove_from_set%(h: opaque of Store::Handle,
|
||||
k: Comm::Data, element: Comm::Data%): bool
|
||||
function BrokerStore::remove_from_set%(h: opaque of BrokerStore::Handle,
|
||||
k: BrokerComm::Data, element: BrokerComm::Data%): bool
|
||||
%{
|
||||
auto handle = static_cast<comm::StoreHandleVal*>(h);
|
||||
auto handle = static_cast<bro_broker::StoreHandleVal*>(h);
|
||||
|
||||
if ( ! handle->store )
|
||||
return new Val(false, TYPE_BOOL);
|
||||
|
||||
auto& key = comm::opaque_field_to_data(k->AsRecordVal(), frame);
|
||||
auto& ele = comm::opaque_field_to_data(element->AsRecordVal(), frame);
|
||||
auto& key = bro_broker::opaque_field_to_data(k->AsRecordVal(), frame);
|
||||
auto& ele = bro_broker::opaque_field_to_data(element->AsRecordVal(), frame);
|
||||
handle->store->remove_from_set(key, ele);
|
||||
return new Val(true, TYPE_BOOL);
|
||||
%}
|
||||
|
@ -328,21 +327,21 @@ function Store::remove_from_set%(h: opaque of Store::Handle,
|
|||
## create empty vector value before modifying.
|
||||
##
|
||||
## Returns: the handle of store to modify.
|
||||
function Store::push_left%(h: opaque of Store::Handle, k: Comm::Data,
|
||||
items: Comm::DataVector%): bool
|
||||
function BrokerStore::push_left%(h: opaque of BrokerStore::Handle, k: BrokerComm::Data,
|
||||
items: BrokerComm::DataVector%): bool
|
||||
%{
|
||||
auto handle = static_cast<comm::StoreHandleVal*>(h);
|
||||
auto handle = static_cast<bro_broker::StoreHandleVal*>(h);
|
||||
|
||||
if ( ! handle->store )
|
||||
return new Val(false, TYPE_BOOL);
|
||||
|
||||
auto& key = comm::opaque_field_to_data(k->AsRecordVal(), frame);
|
||||
auto& key = bro_broker::opaque_field_to_data(k->AsRecordVal(), frame);
|
||||
broker::vector items_vector;
|
||||
auto items_vv = items->AsVector();
|
||||
|
||||
for ( auto i = 0u; i < items_vv->size(); ++i )
|
||||
{
|
||||
auto& item = comm::opaque_field_to_data((*items_vv)[i]->AsRecordVal(),
|
||||
auto& item = bro_broker::opaque_field_to_data((*items_vv)[i]->AsRecordVal(),
|
||||
frame);
|
||||
items_vector.emplace_back(item);
|
||||
}
|
||||
|
@ -361,21 +360,21 @@ function Store::push_left%(h: opaque of Store::Handle, k: Comm::Data,
|
|||
## create empty vector value before modifying.
|
||||
##
|
||||
## Returns: the handle of store to modify.
|
||||
function Store::push_right%(h: opaque of Store::Handle, k: Comm::Data,
|
||||
items: Comm::DataVector%): bool
|
||||
function BrokerStore::push_right%(h: opaque of BrokerStore::Handle, k: BrokerComm::Data,
|
||||
items: BrokerComm::DataVector%): bool
|
||||
%{
|
||||
auto handle = static_cast<comm::StoreHandleVal*>(h);
|
||||
auto handle = static_cast<bro_broker::StoreHandleVal*>(h);
|
||||
|
||||
if ( ! handle->store )
|
||||
return new Val(false, TYPE_BOOL);
|
||||
|
||||
auto& key = comm::opaque_field_to_data(k->AsRecordVal(), frame);
|
||||
auto& key = bro_broker::opaque_field_to_data(k->AsRecordVal(), frame);
|
||||
broker::vector items_vector;
|
||||
auto items_vv = items->AsVector();
|
||||
|
||||
for ( auto i = 0u; i < items_vv->size(); ++i )
|
||||
{
|
||||
auto& item = comm::opaque_field_to_data((*items_vv)[i]->AsRecordVal(),
|
||||
auto& item = bro_broker::opaque_field_to_data((*items_vv)[i]->AsRecordVal(),
|
||||
frame);
|
||||
items_vector.emplace_back(item);
|
||||
}
|
||||
|
@ -390,11 +389,11 @@ function Store::push_right%(h: opaque of Store::Handle, k: Comm::Data,
|
|||
|
||||
%%{
|
||||
static bool prepare_for_query(Val* opaque, Frame* frame,
|
||||
comm::StoreHandleVal** handle,
|
||||
bro_broker::StoreHandleVal** handle,
|
||||
double* timeout,
|
||||
comm::StoreQueryCallback** cb)
|
||||
bro_broker::StoreQueryCallback** cb)
|
||||
{
|
||||
*handle = static_cast<comm::StoreHandleVal*>(opaque);
|
||||
*handle = static_cast<bro_broker::StoreHandleVal*>(opaque);
|
||||
|
||||
if ( ! (*handle)->store )
|
||||
return false;
|
||||
|
@ -404,7 +403,7 @@ static bool prepare_for_query(Val* opaque, Frame* frame,
|
|||
if ( ! trigger )
|
||||
{
|
||||
reporter->PushLocation(frame->GetCall()->GetLocationInfo());
|
||||
reporter->Error("Store queries can only be called inside when-condition");
|
||||
reporter->Error("BrokerStore queries can only be called inside when-condition");
|
||||
reporter->PopLocation();
|
||||
return false;
|
||||
}
|
||||
|
@ -414,17 +413,17 @@ static bool prepare_for_query(Val* opaque, Frame* frame,
|
|||
if ( *timeout < 0 )
|
||||
{
|
||||
reporter->PushLocation(frame->GetCall()->GetLocationInfo());
|
||||
reporter->Error("Store queries must specify a timeout block");
|
||||
reporter->Error("BrokerStore queries must specify a timeout block");
|
||||
reporter->PopLocation();
|
||||
return false;
|
||||
}
|
||||
|
||||
frame->SetDelayed();
|
||||
trigger->Hold();
|
||||
*cb = new comm::StoreQueryCallback(trigger, frame->GetCall(),
|
||||
*cb = new bro_broker::StoreQueryCallback(trigger, frame->GetCall(),
|
||||
(*handle)->store->id(),
|
||||
(*handle)->store_type);
|
||||
comm_mgr->TrackStoreQuery(*cb);
|
||||
broker_mgr->TrackStoreQuery(*cb);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -437,25 +436,25 @@ static bool prepare_for_query(Val* opaque, Frame* frame,
|
|||
## k: the key associated with the vector to modify.
|
||||
##
|
||||
## Returns: the result of the query.
|
||||
function Store::pop_left%(h: opaque of Store::Handle,
|
||||
k: Comm::Data%): Store::QueryResult
|
||||
function BrokerStore::pop_left%(h: opaque of BrokerStore::Handle,
|
||||
k: BrokerComm::Data%): BrokerStore::QueryResult
|
||||
%{
|
||||
if ( ! comm_mgr->Enabled() )
|
||||
return comm::query_result();
|
||||
if ( ! broker_mgr->Enabled() )
|
||||
return bro_broker::query_result();
|
||||
|
||||
Val* key = k->AsRecordVal()->Lookup(0);
|
||||
|
||||
if ( ! key )
|
||||
return comm::query_result();
|
||||
return bro_broker::query_result();
|
||||
|
||||
double timeout;
|
||||
comm::StoreQueryCallback* cb;
|
||||
comm::StoreHandleVal* handle;
|
||||
bro_broker::StoreQueryCallback* cb;
|
||||
bro_broker::StoreHandleVal* handle;
|
||||
|
||||
if ( ! prepare_for_query(h, frame, &handle, &timeout, &cb) )
|
||||
return comm::query_result();
|
||||
return bro_broker::query_result();
|
||||
|
||||
handle->store->pop_left(static_cast<comm::DataVal*>(key)->data,
|
||||
handle->store->pop_left(static_cast<bro_broker::DataVal*>(key)->data,
|
||||
std::chrono::duration<double>(timeout), cb);
|
||||
return 0;
|
||||
%}
|
||||
|
@ -467,25 +466,25 @@ function Store::pop_left%(h: opaque of Store::Handle,
|
|||
## k: the key associated with the vector to modify.
|
||||
##
|
||||
## Returns: the result of the query.
|
||||
function Store::pop_right%(h: opaque of Store::Handle,
|
||||
k: Comm::Data%): Store::QueryResult
|
||||
function BrokerStore::pop_right%(h: opaque of BrokerStore::Handle,
|
||||
k: BrokerComm::Data%): BrokerStore::QueryResult
|
||||
%{
|
||||
if ( ! comm_mgr->Enabled() )
|
||||
return comm::query_result();
|
||||
if ( ! broker_mgr->Enabled() )
|
||||
return bro_broker::query_result();
|
||||
|
||||
Val* key = k->AsRecordVal()->Lookup(0);
|
||||
|
||||
if ( ! key )
|
||||
return comm::query_result();
|
||||
return bro_broker::query_result();
|
||||
|
||||
double timeout;
|
||||
comm::StoreQueryCallback* cb;
|
||||
comm::StoreHandleVal* handle;
|
||||
bro_broker::StoreQueryCallback* cb;
|
||||
bro_broker::StoreHandleVal* handle;
|
||||
|
||||
if ( ! prepare_for_query(h, frame, &handle, &timeout, &cb) )
|
||||
return comm::query_result();
|
||||
return bro_broker::query_result();
|
||||
|
||||
handle->store->pop_right(static_cast<comm::DataVal*>(key)->data,
|
||||
handle->store->pop_right(static_cast<bro_broker::DataVal*>(key)->data,
|
||||
std::chrono::duration<double>(timeout), cb);
|
||||
return 0;
|
||||
%}
|
||||
|
@ -497,25 +496,25 @@ function Store::pop_right%(h: opaque of Store::Handle,
|
|||
## k: the key to lookup.
|
||||
##
|
||||
## Returns: the result of the query.
|
||||
function Store::lookup%(h: opaque of Store::Handle,
|
||||
k: Comm::Data%): Store::QueryResult
|
||||
function BrokerStore::lookup%(h: opaque of BrokerStore::Handle,
|
||||
k: BrokerComm::Data%): BrokerStore::QueryResult
|
||||
%{
|
||||
if ( ! comm_mgr->Enabled() )
|
||||
return comm::query_result();
|
||||
if ( ! broker_mgr->Enabled() )
|
||||
return bro_broker::query_result();
|
||||
|
||||
Val* key = k->AsRecordVal()->Lookup(0);
|
||||
|
||||
if ( ! key )
|
||||
return comm::query_result();
|
||||
return bro_broker::query_result();
|
||||
|
||||
double timeout;
|
||||
comm::StoreQueryCallback* cb;
|
||||
comm::StoreHandleVal* handle;
|
||||
bro_broker::StoreQueryCallback* cb;
|
||||
bro_broker::StoreHandleVal* handle;
|
||||
|
||||
if ( ! prepare_for_query(h, frame, &handle, &timeout, &cb) )
|
||||
return comm::query_result();
|
||||
return bro_broker::query_result();
|
||||
|
||||
handle->store->lookup(static_cast<comm::DataVal*>(key)->data,
|
||||
handle->store->lookup(static_cast<bro_broker::DataVal*>(key)->data,
|
||||
std::chrono::duration<double>(timeout), cb);
|
||||
return 0;
|
||||
%}
|
||||
|
@ -526,26 +525,26 @@ function Store::lookup%(h: opaque of Store::Handle,
|
|||
##
|
||||
## k: the key to check for existence.
|
||||
##
|
||||
## Returns: the result of the query (uses :bro:see:`Comm::BOOL`).
|
||||
function Store::exists%(h: opaque of Store::Handle,
|
||||
k: Comm::Data%): Store::QueryResult
|
||||
## Returns: the result of the query (uses :bro:see:`BrokerComm::BOOL`).
|
||||
function BrokerStore::exists%(h: opaque of BrokerStore::Handle,
|
||||
k: BrokerComm::Data%): BrokerStore::QueryResult
|
||||
%{
|
||||
if ( ! comm_mgr->Enabled() )
|
||||
return comm::query_result();
|
||||
if ( ! broker_mgr->Enabled() )
|
||||
return bro_broker::query_result();
|
||||
|
||||
Val* key = k->AsRecordVal()->Lookup(0);
|
||||
|
||||
if ( ! key )
|
||||
return comm::query_result();
|
||||
return bro_broker::query_result();
|
||||
|
||||
double timeout;
|
||||
comm::StoreQueryCallback* cb;
|
||||
comm::StoreHandleVal* handle;
|
||||
bro_broker::StoreQueryCallback* cb;
|
||||
bro_broker::StoreHandleVal* handle;
|
||||
|
||||
if ( ! prepare_for_query(h, frame, &handle, &timeout, &cb) )
|
||||
return comm::query_result();
|
||||
return bro_broker::query_result();
|
||||
|
||||
handle->store->exists(static_cast<comm::DataVal*>(key)->data,
|
||||
handle->store->exists(static_cast<bro_broker::DataVal*>(key)->data,
|
||||
std::chrono::duration<double>(timeout), cb);
|
||||
return 0;
|
||||
%}
|
||||
|
@ -554,15 +553,15 @@ function Store::exists%(h: opaque of Store::Handle,
|
|||
##
|
||||
## h: the handle of the store to query.
|
||||
##
|
||||
## Returns: the result of the query (uses :bro:see:`Comm::VECTOR`).
|
||||
function Store::keys%(h: opaque of Store::Handle%): Store::QueryResult
|
||||
## Returns: the result of the query (uses :bro:see:`BrokerComm::VECTOR`).
|
||||
function BrokerStore::keys%(h: opaque of BrokerStore::Handle%): BrokerStore::QueryResult
|
||||
%{
|
||||
double timeout;
|
||||
comm::StoreQueryCallback* cb;
|
||||
comm::StoreHandleVal* handle;
|
||||
bro_broker::StoreQueryCallback* cb;
|
||||
bro_broker::StoreHandleVal* handle;
|
||||
|
||||
if ( ! prepare_for_query(h, frame, &handle, &timeout, &cb) )
|
||||
return comm::query_result();
|
||||
return bro_broker::query_result();
|
||||
|
||||
handle->store->keys(std::chrono::duration<double>(timeout), cb);
|
||||
return 0;
|
||||
|
@ -572,18 +571,18 @@ function Store::keys%(h: opaque of Store::Handle%): Store::QueryResult
|
|||
##
|
||||
## h: the handle of the store to query.
|
||||
##
|
||||
## Returns: the result of the query (uses :bro:see:`Comm::COUNT`).
|
||||
function Store::size%(h: opaque of Store::Handle%): Store::QueryResult
|
||||
## Returns: the result of the query (uses :bro:see:`BrokerComm::COUNT`).
|
||||
function BrokerStore::size%(h: opaque of BrokerStore::Handle%): BrokerStore::QueryResult
|
||||
%{
|
||||
if ( ! comm_mgr->Enabled() )
|
||||
return comm::query_result();
|
||||
if ( ! broker_mgr->Enabled() )
|
||||
return bro_broker::query_result();
|
||||
|
||||
double timeout;
|
||||
comm::StoreQueryCallback* cb;
|
||||
comm::StoreHandleVal* handle;
|
||||
bro_broker::StoreQueryCallback* cb;
|
||||
bro_broker::StoreHandleVal* handle;
|
||||
|
||||
if ( ! prepare_for_query(h, frame, &handle, &timeout, &cb) )
|
||||
return comm::query_result();
|
||||
return bro_broker::query_result();
|
||||
|
||||
handle->store->size(std::chrono::duration<double>(timeout), cb);
|
||||
return 0;
|
|
@ -17,7 +17,7 @@
|
|||
#include "logging.bif.h"
|
||||
|
||||
#ifdef ENABLE_BROKER
|
||||
#include "comm/Manager.h"
|
||||
#include "broker/Manager.h"
|
||||
#endif
|
||||
|
||||
using namespace logging;
|
||||
|
@ -843,8 +843,9 @@ bool Manager::Write(EnumVal* id, RecordVal* columns)
|
|||
}
|
||||
|
||||
#ifdef ENABLE_BROKER
|
||||
if ( stream->enable_remote )
|
||||
comm_mgr->Log(id, columns, stream->remote_flags);
|
||||
if ( stream->enable_remote &&
|
||||
! broker_mgr->Log(id, columns, stream->columns, stream->remote_flags) )
|
||||
stream->enable_remote = false;
|
||||
#endif
|
||||
|
||||
Unref(columns);
|
||||
|
|
|
@ -64,7 +64,7 @@ extern "C" void OPENSSL_add_all_algorithms_conf(void);
|
|||
#include "3rdparty/sqlite3.h"
|
||||
|
||||
#ifdef ENABLE_BROKER
|
||||
#include <comm/Manager.h>
|
||||
#include "broker/Manager.h"
|
||||
#endif
|
||||
|
||||
Brofiler brofiler;
|
||||
|
@ -96,7 +96,7 @@ file_analysis::Manager* file_mgr = 0;
|
|||
broxygen::Manager* broxygen_mgr = 0;
|
||||
iosource::Manager* iosource_mgr = 0;
|
||||
#ifdef ENABLE_BROKER
|
||||
comm::Manager* comm_mgr = 0;
|
||||
bro_broker::Manager* broker_mgr = 0;
|
||||
#endif
|
||||
|
||||
const char* prog;
|
||||
|
@ -860,7 +860,7 @@ int main(int argc, char** argv)
|
|||
file_mgr = new file_analysis::Manager();
|
||||
|
||||
#ifdef ENABLE_BROKER
|
||||
comm_mgr = new comm::Manager();
|
||||
broker_mgr = new bro_broker::Manager();
|
||||
#endif
|
||||
|
||||
plugin_mgr->InitPreScript();
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
clone keys, [status=BrokerStore::SUCCESS, result=[d=broker::data{[one, two, myset, myvec]}]]
|
||||
lookup, one, [status=BrokerStore::SUCCESS, result=[d=broker::data{111}]]
|
||||
lookup, two, [status=BrokerStore::SUCCESS, result=[d=broker::data{222}]]
|
||||
lookup, myset, [status=BrokerStore::SUCCESS, result=[d=broker::data{{a, c, d}}]]
|
||||
lookup, myvec, [status=BrokerStore::SUCCESS, result=[d=broker::data{[delta, alpha, beta, gamma, omega]}]]
|
|
@ -0,0 +1,2 @@
|
|||
BrokerComm::incoming_connection_established, connector
|
||||
BrokerComm::incoming_connection_broken, connector
|
|
@ -0,0 +1 @@
|
|||
BrokerComm::outgoing_connection_established, 127.0.0.1, 9999/tcp, listener
|
|
@ -1,18 +1,18 @@
|
|||
Comm::BOOL
|
||||
Comm::INT
|
||||
Comm::COUNT
|
||||
Comm::DOUBLE
|
||||
Comm::STRING
|
||||
Comm::ADDR
|
||||
Comm::SUBNET
|
||||
Comm::PORT
|
||||
Comm::TIME
|
||||
Comm::INTERVAL
|
||||
Comm::ENUM
|
||||
Comm::SET
|
||||
Comm::TABLE
|
||||
Comm::VECTOR
|
||||
Comm::RECORD
|
||||
BrokerComm::BOOL
|
||||
BrokerComm::INT
|
||||
BrokerComm::COUNT
|
||||
BrokerComm::DOUBLE
|
||||
BrokerComm::STRING
|
||||
BrokerComm::ADDR
|
||||
BrokerComm::SUBNET
|
||||
BrokerComm::PORT
|
||||
BrokerComm::TIME
|
||||
BrokerComm::INTERVAL
|
||||
BrokerComm::ENUM
|
||||
BrokerComm::SET
|
||||
BrokerComm::TABLE
|
||||
BrokerComm::VECTOR
|
||||
BrokerComm::RECORD
|
||||
***************************
|
||||
T
|
||||
F
|
||||
|
@ -29,7 +29,7 @@ hello
|
|||
22/tcp
|
||||
42.0
|
||||
180.0
|
||||
Comm::BOOL
|
||||
BrokerComm::BOOL
|
||||
***************************
|
||||
{
|
||||
two,
|
14
testing/btest/Baseline/broker.master_store/master.out
Normal file
14
testing/btest/Baseline/broker.master_store/master.out
Normal file
|
@ -0,0 +1,14 @@
|
|||
lookup(two): [status=BrokerStore::SUCCESS, result=[d=broker::data{222}]]
|
||||
lookup(four): [status=BrokerStore::SUCCESS, result=[d=<uninitialized>]]
|
||||
lookup(myset): [status=BrokerStore::SUCCESS, result=[d=broker::data{{a, c, d}}]]
|
||||
lookup(one): [status=BrokerStore::SUCCESS, result=[d=broker::data{111}]]
|
||||
lookup(myvec): [status=BrokerStore::SUCCESS, result=[d=broker::data{[delta, alpha, beta, gamma, omega]}]]
|
||||
exists(one): [status=BrokerStore::SUCCESS, result=[d=broker::data{1}]]
|
||||
exists(two): [status=BrokerStore::SUCCESS, result=[d=broker::data{0}]]
|
||||
exists(myset): [status=BrokerStore::SUCCESS, result=[d=broker::data{1}]]
|
||||
exists(four): [status=BrokerStore::SUCCESS, result=[d=broker::data{0}]]
|
||||
pop_right(myvec): [status=BrokerStore::SUCCESS, result=[d=broker::data{omega}]]
|
||||
pop_left(myvec): [status=BrokerStore::SUCCESS, result=[d=broker::data{delta}]]
|
||||
keys: [status=BrokerStore::SUCCESS, result=[d=broker::data{[myvec, myset, one]}]]
|
||||
size: [status=BrokerStore::SUCCESS, result=[d=broker::data{3}]]
|
||||
size (after clear): [status=BrokerStore::SUCCESS, result=[d=broker::data{0}]]
|
|
@ -1,4 +1,4 @@
|
|||
Comm::outgoing_connection_established, 127.0.0.1, 9999/tcp
|
||||
BrokerComm::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
|
6
testing/btest/Baseline/broker.remote_log/recv.recv.out
Normal file
6
testing/btest/Baseline/broker.remote_log/recv.recv.out
Normal file
|
@ -0,0 +1,6 @@
|
|||
wrote log, [msg=ping, num=0, nolog=no]
|
||||
wrote log, [msg=ping, num=1, nolog=no]
|
||||
wrote log, [msg=ping, num=2, nolog=no]
|
||||
wrote log, [msg=ping, num=3, nolog=no]
|
||||
wrote log, [msg=ping, num=4, nolog=no]
|
||||
wrote log, [msg=ping, num=5, nolog=no]
|
1
testing/btest/Baseline/broker.remote_log/send.send.out
Normal file
1
testing/btest/Baseline/broker.remote_log/send.send.out
Normal file
|
@ -0,0 +1 @@
|
|||
BrokerComm::outgoing_connection_established, 127.0.0.1, 9999/tcp
|
|
@ -1,4 +1,4 @@
|
|||
Comm::outgoing_connection_established, 127.0.0.1, 9999/tcp
|
||||
BrokerComm::outgoing_connection_established, 127.0.0.1, 9999/tcp
|
||||
got print msg, pong 0
|
||||
got print msg, pong 1
|
||||
got print msg, pong 2
|
|
@ -1,5 +0,0 @@
|
|||
clone keys, [status=Store::SUCCESS, result=[d=broker::data{[one, two, myset, myvec]}]]
|
||||
lookup, one, [status=Store::SUCCESS, result=[d=broker::data{111}]]
|
||||
lookup, two, [status=Store::SUCCESS, result=[d=broker::data{222}]]
|
||||
lookup, myset, [status=Store::SUCCESS, result=[d=broker::data{{a, c, d}}]]
|
||||
lookup, myvec, [status=Store::SUCCESS, result=[d=broker::data{[delta, alpha, beta, gamma, omega]}]]
|
|
@ -1,2 +0,0 @@
|
|||
Comm::incoming_connection_established, connector
|
||||
Comm::incoming_connection_broken, connector
|
|
@ -1 +0,0 @@
|
|||
Comm::outgoing_connection_established, 127.0.0.1, 9999/tcp, listener
|
|
@ -1,14 +0,0 @@
|
|||
lookup(two): [status=Store::SUCCESS, result=[d=broker::data{222}]]
|
||||
lookup(four): [status=Store::SUCCESS, result=[d=<uninitialized>]]
|
||||
lookup(myset): [status=Store::SUCCESS, result=[d=broker::data{{a, c, d}}]]
|
||||
lookup(one): [status=Store::SUCCESS, result=[d=broker::data{111}]]
|
||||
lookup(myvec): [status=Store::SUCCESS, result=[d=broker::data{[delta, alpha, beta, gamma, omega]}]]
|
||||
exists(one): [status=Store::SUCCESS, result=[d=broker::data{1}]]
|
||||
exists(two): [status=Store::SUCCESS, result=[d=broker::data{0}]]
|
||||
exists(myset): [status=Store::SUCCESS, result=[d=broker::data{1}]]
|
||||
exists(four): [status=Store::SUCCESS, result=[d=broker::data{0}]]
|
||||
pop_right(myvec): [status=Store::SUCCESS, result=[d=broker::data{omega}]]
|
||||
pop_left(myvec): [status=Store::SUCCESS, result=[d=broker::data{delta}]]
|
||||
keys: [status=Store::SUCCESS, result=[d=broker::data{[myvec, myset, one]}]]
|
||||
size: [status=Store::SUCCESS, result=[d=broker::data{3}]]
|
||||
size (after clear): [status=Store::SUCCESS, result=[d=broker::data{0}]]
|
|
@ -1,6 +0,0 @@
|
|||
wrote log, [msg=ping, num=0]
|
||||
wrote log, [msg=ping, num=1]
|
||||
wrote log, [msg=ping, num=2]
|
||||
wrote log, [msg=ping, num=3]
|
||||
wrote log, [msg=ping, num=4]
|
||||
wrote log, [msg=ping, num=5]
|
|
@ -1 +0,0 @@
|
|||
Comm::outgoing_connection_established, 127.0.0.1, 9999/tcp
|
|
@ -14,8 +14,8 @@ scripts/base/init-bare.bro
|
|||
build/scripts/base/bif/reporter.bif.bro
|
||||
build/scripts/base/bif/plugins/Bro_SNMP.types.bif.bro
|
||||
build/scripts/base/bif/event.bif.bro
|
||||
scripts/base/frameworks/comm/__load__.bro
|
||||
scripts/base/frameworks/comm/main.bro
|
||||
scripts/base/frameworks/broker/__load__.bro
|
||||
scripts/base/frameworks/broker/main.bro
|
||||
scripts/base/frameworks/logging/__load__.bro
|
||||
scripts/base/frameworks/logging/main.bro
|
||||
build/scripts/base/bif/logging.bif.bro
|
||||
|
|
|
@ -14,8 +14,8 @@ scripts/base/init-bare.bro
|
|||
build/scripts/base/bif/reporter.bif.bro
|
||||
build/scripts/base/bif/plugins/Bro_SNMP.types.bif.bro
|
||||
build/scripts/base/bif/event.bif.bro
|
||||
scripts/base/frameworks/comm/__load__.bro
|
||||
scripts/base/frameworks/comm/main.bro
|
||||
scripts/base/frameworks/broker/__load__.bro
|
||||
scripts/base/frameworks/broker/main.bro
|
||||
scripts/base/frameworks/logging/__load__.bro
|
||||
scripts/base/frameworks/logging/main.bro
|
||||
build/scripts/base/bif/logging.bif.bro
|
||||
|
|
|
@ -5,19 +5,19 @@ connecting-connector.bro
|
|||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef Comm::endpoint_name = "connector";
|
||||
redef BrokerComm::endpoint_name = "connector";
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::connect("127.0.0.1", broker_port, 1sec);
|
||||
BrokerComm::enable();
|
||||
BrokerComm::connect("127.0.0.1", broker_port, 1sec);
|
||||
}
|
||||
|
||||
event Comm::outgoing_connection_established(peer_address: string,
|
||||
event BrokerComm::outgoing_connection_established(peer_address: string,
|
||||
peer_port: port,
|
||||
peer_name: string)
|
||||
{
|
||||
print "Comm::outgoing_connection_established",
|
||||
print "BrokerComm::outgoing_connection_established",
|
||||
peer_address, peer_port, peer_name;
|
||||
terminate();
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
# @TEST-EXEC: cat %INPUT >output && btest-diff output
|
||||
|
||||
connecting-listener.bro
|
||||
|
||||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef BrokerComm::endpoint_name = "listener";
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
BrokerComm::enable();
|
||||
BrokerComm::listen(broker_port, "127.0.0.1");
|
||||
}
|
||||
|
||||
event BrokerComm::incoming_connection_established(peer_name: string)
|
||||
{
|
||||
print "BrokerComm::incoming_connection_established", peer_name;
|
||||
}
|
||||
|
||||
event BrokerComm::incoming_connection_broken(peer_name: string)
|
||||
{
|
||||
print "BrokerComm::incoming_connection_broken", peer_name;
|
||||
terminate();
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
# @TEST-EXEC: cat %INPUT >output && btest-diff output
|
||||
|
||||
events-connector.bro
|
||||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef BrokerComm::endpoint_name = "connector";
|
||||
global my_event: event(msg: string, c: count);
|
||||
global my_auto_event: event(msg: string, c: count);
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
BrokerComm::enable();
|
||||
BrokerComm::connect("127.0.0.1", broker_port, 1sec);
|
||||
BrokerComm::auto_event("bro/event/my_auto_event", my_auto_event);
|
||||
}
|
||||
|
||||
event BrokerComm::outgoing_connection_established(peer_address: string,
|
||||
peer_port: port,
|
||||
peer_name: string)
|
||||
{
|
||||
print "BrokerComm::outgoing_connection_established",
|
||||
peer_address, peer_port, peer_name;
|
||||
BrokerComm::event("bro/event/my_event", BrokerComm::event_args(my_event, "hi", 0));
|
||||
event my_auto_event("stuff", 88);
|
||||
BrokerComm::event("bro/event/my_event", BrokerComm::event_args(my_event, "...", 1));
|
||||
event my_auto_event("more stuff", 51);
|
||||
BrokerComm::event("bro/event/my_event", BrokerComm::event_args(my_event, "bye", 2));
|
||||
}
|
||||
|
||||
event BrokerComm::outgoing_connection_broken(peer_address: string,
|
||||
peer_port: port)
|
||||
{
|
||||
terminate();
|
||||
}
|
|
@ -5,21 +5,21 @@ events-listener.bro
|
|||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef Comm::endpoint_name = "listener";
|
||||
redef BrokerComm::endpoint_name = "listener";
|
||||
global msg_count = 0;
|
||||
global my_event: event(msg: string, c: count);
|
||||
global my_auto_event: event(msg: string, c: count);
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::subscribe_to_events("bro/event/");
|
||||
Comm::listen(broker_port, "127.0.0.1");
|
||||
BrokerComm::enable();
|
||||
BrokerComm::subscribe_to_events("bro/event/");
|
||||
BrokerComm::listen(broker_port, "127.0.0.1");
|
||||
}
|
||||
|
||||
event Comm::incoming_connection_established(peer_name: string)
|
||||
event BrokerComm::incoming_connection_established(peer_name: string)
|
||||
{
|
||||
print "Comm::incoming_connection_established", peer_name;
|
||||
print "BrokerComm::incoming_connection_established", peer_name;
|
||||
}
|
||||
|
||||
event my_event(msg: string, c: count)
|
|
@ -6,16 +6,16 @@ logs-connector.bro
|
|||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef Comm::endpoint_name = "connector";
|
||||
redef BrokerComm::endpoint_name = "connector";
|
||||
redef Log::enable_local_logging = F;
|
||||
redef Log::enable_remote_logging = F;
|
||||
global n = 0;
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::enable_remote_logs(Test::LOG);
|
||||
Comm::connect("127.0.0.1", broker_port, 1sec);
|
||||
BrokerComm::enable();
|
||||
BrokerComm::enable_remote_logs(Test::LOG);
|
||||
BrokerComm::connect("127.0.0.1", broker_port, 1sec);
|
||||
}
|
||||
|
||||
event do_write()
|
||||
|
@ -28,16 +28,16 @@ event do_write()
|
|||
event do_write();
|
||||
}
|
||||
|
||||
event Comm::outgoing_connection_established(peer_address: string,
|
||||
event BrokerComm::outgoing_connection_established(peer_address: string,
|
||||
peer_port: port,
|
||||
peer_name: string)
|
||||
{
|
||||
print "Comm::outgoing_connection_established",
|
||||
print "BrokerComm::outgoing_connection_established",
|
||||
peer_address, peer_port, peer_name;
|
||||
event do_write();
|
||||
}
|
||||
|
||||
event Comm::outgoing_connection_broken(peer_address: string,
|
||||
event BrokerComm::outgoing_connection_broken(peer_address: string,
|
||||
peer_port: port)
|
||||
{
|
||||
terminate();
|
|
@ -0,0 +1,29 @@
|
|||
# @TEST-EXEC: cat %INPUT >output && btest-diff output
|
||||
|
||||
logs-listener.bro
|
||||
|
||||
@load ./testlog
|
||||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef BrokerComm::endpoint_name = "listener";
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
BrokerComm::enable();
|
||||
BrokerComm::subscribe_to_logs("bro/log/Test::LOG");
|
||||
BrokerComm::listen(broker_port, "127.0.0.1");
|
||||
}
|
||||
|
||||
event BrokerComm::incoming_connection_established(peer_name: string)
|
||||
{
|
||||
print "BrokerComm::incoming_connection_established", peer_name;
|
||||
}
|
||||
|
||||
event Test::log_test(rec: Test::Info)
|
||||
{
|
||||
print "wrote log", rec;
|
||||
|
||||
if ( rec$num == 5 )
|
||||
terminate();
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
# @TEST-EXEC: cat %INPUT >output && btest-diff output
|
||||
|
||||
printing-connector.bro
|
||||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef BrokerComm::endpoint_name = "connector";
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
BrokerComm::enable();
|
||||
BrokerComm::connect("127.0.0.1", broker_port, 1sec);
|
||||
}
|
||||
|
||||
event BrokerComm::outgoing_connection_established(peer_address: string,
|
||||
peer_port: port,
|
||||
peer_name: string)
|
||||
{
|
||||
print "BrokerComm::outgoing_connection_established",
|
||||
peer_address, peer_port, peer_name;
|
||||
BrokerComm::print("bro/print/hi", "hello");
|
||||
BrokerComm::print("bro/print/stuff", "...");
|
||||
BrokerComm::print("bro/print/bye", "goodbye");
|
||||
}
|
||||
|
||||
event BrokerComm::outgoing_connection_broken(peer_address: string,
|
||||
peer_port: port)
|
||||
{
|
||||
terminate();
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
# @TEST-EXEC: cat %INPUT >output && btest-diff output
|
||||
|
||||
printing-listener.bro
|
||||
|
||||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef BrokerComm::endpoint_name = "listener";
|
||||
global msg_count = 0;
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
BrokerComm::enable();
|
||||
BrokerComm::subscribe_to_prints("bro/print/");
|
||||
BrokerComm::listen(broker_port, "127.0.0.1");
|
||||
}
|
||||
|
||||
event BrokerComm::incoming_connection_established(peer_name: string)
|
||||
{
|
||||
print "BrokerComm::incoming_connection_established", peer_name;
|
||||
}
|
||||
|
||||
event BrokerComm::print_handler(msg: string)
|
||||
{
|
||||
++msg_count;
|
||||
print "got print message", msg;
|
||||
|
||||
if ( msg_count == 3 )
|
||||
terminate();
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
# @TEST-EXEC: cat %INPUT >output && btest-diff output
|
||||
|
||||
stores-connector.bro
|
||||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
global h: opaque of BrokerStore::Handle;
|
||||
|
||||
function dv(d: BrokerComm::Data): BrokerComm::DataVector
|
||||
{
|
||||
local rval: BrokerComm::DataVector;
|
||||
rval[0] = d;
|
||||
return rval;
|
||||
}
|
||||
|
||||
global ready: event();
|
||||
|
||||
event BrokerComm::outgoing_connection_broken(peer_address: string,
|
||||
peer_port: port)
|
||||
{
|
||||
terminate();
|
||||
}
|
||||
|
||||
event BrokerComm::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"};
|
||||
h = BrokerStore::create_master("mystore");
|
||||
BrokerStore::insert(h, BrokerComm::data("one"), BrokerComm::data(110));
|
||||
BrokerStore::insert(h, BrokerComm::data("two"), BrokerComm::data(223));
|
||||
BrokerStore::insert(h, BrokerComm::data("myset"), BrokerComm::data(myset));
|
||||
BrokerStore::insert(h, BrokerComm::data("myvec"), BrokerComm::data(myvec));
|
||||
BrokerStore::increment(h, BrokerComm::data("one"));
|
||||
BrokerStore::decrement(h, BrokerComm::data("two"));
|
||||
BrokerStore::add_to_set(h, BrokerComm::data("myset"), BrokerComm::data("d"));
|
||||
BrokerStore::remove_from_set(h, BrokerComm::data("myset"), BrokerComm::data("b"));
|
||||
BrokerStore::push_left(h, BrokerComm::data("myvec"), dv(BrokerComm::data("delta")));
|
||||
BrokerStore::push_right(h, BrokerComm::data("myvec"), dv(BrokerComm::data("omega")));
|
||||
|
||||
when ( local res = BrokerStore::size(h) )
|
||||
{
|
||||
print "master size", res;
|
||||
event ready();
|
||||
}
|
||||
timeout 10sec
|
||||
{ print "timeout"; }
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
BrokerComm::enable();
|
||||
BrokerComm::connect("127.0.0.1", broker_port, 1secs);
|
||||
BrokerComm::auto_event("bro/event/ready", ready);
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
# @TEST-EXEC: cat %INPUT >output && btest-diff output
|
||||
|
||||
stores-listener.bro
|
||||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
global h: opaque of BrokerStore::Handle;
|
||||
global expected_key_count = 4;
|
||||
global key_count = 0;
|
||||
|
||||
function do_lookup(key: string)
|
||||
{
|
||||
when ( local res = BrokerStore::lookup(h, BrokerComm::data(key)) )
|
||||
{
|
||||
++key_count;
|
||||
print "lookup", key, res;
|
||||
|
||||
if ( key_count == expected_key_count )
|
||||
terminate();
|
||||
}
|
||||
timeout 10sec
|
||||
{ print "timeout", key; }
|
||||
}
|
||||
|
||||
event ready()
|
||||
{
|
||||
h = BrokerStore::create_clone("mystore");
|
||||
|
||||
when ( local res = BrokerStore::keys(h) )
|
||||
{
|
||||
print "clone keys", res;
|
||||
do_lookup(BrokerComm::refine_to_string(BrokerComm::vector_lookup(res$result, 0)));
|
||||
do_lookup(BrokerComm::refine_to_string(BrokerComm::vector_lookup(res$result, 1)));
|
||||
do_lookup(BrokerComm::refine_to_string(BrokerComm::vector_lookup(res$result, 2)));
|
||||
do_lookup(BrokerComm::refine_to_string(BrokerComm::vector_lookup(res$result, 3)));
|
||||
}
|
||||
timeout 10sec
|
||||
{ print "timeout"; }
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
BrokerComm::enable();
|
||||
BrokerComm::subscribe_to_events("bro/event/ready");
|
||||
BrokerComm::listen(broker_port, "127.0.0.1");
|
||||
}
|
|
@ -18,6 +18,6 @@ export {
|
|||
|
||||
event bro_init() &priority=5
|
||||
{
|
||||
Comm::enable();
|
||||
BrokerComm::enable();
|
||||
Log::create_stream(Test::LOG, [$columns=Test::Info, $ev=log_test]);
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
# @TEST-EXEC: cat %INPUT >output && btest-diff output
|
||||
|
||||
connecting-listener.bro
|
||||
|
||||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef Comm::endpoint_name = "listener";
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::listen(broker_port, "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();
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
# @TEST-EXEC: cat %INPUT >output && btest-diff output
|
||||
|
||||
events-connector.bro
|
||||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef Comm::endpoint_name = "connector";
|
||||
global my_event: event(msg: string, c: count);
|
||||
global my_auto_event: event(msg: string, c: count);
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::connect("127.0.0.1", broker_port, 1sec);
|
||||
Comm::auto_event("bro/event/my_auto_event", my_auto_event);
|
||||
}
|
||||
|
||||
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;
|
||||
Comm::event("bro/event/my_event", Comm::event_args(my_event, "hi", 0));
|
||||
event my_auto_event("stuff", 88);
|
||||
Comm::event("bro/event/my_event", Comm::event_args(my_event, "...", 1));
|
||||
event my_auto_event("more stuff", 51);
|
||||
Comm::event("bro/event/my_event", Comm::event_args(my_event, "bye", 2));
|
||||
}
|
||||
|
||||
event Comm::outgoing_connection_broken(peer_address: string,
|
||||
peer_port: port)
|
||||
{
|
||||
terminate();
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
# @TEST-EXEC: cat %INPUT >output && btest-diff output
|
||||
|
||||
logs-listener.bro
|
||||
|
||||
@load ./testlog
|
||||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef Comm::endpoint_name = "listener";
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::subscribe_to_logs("bro/log/Test::LOG");
|
||||
Comm::listen(broker_port, "127.0.0.1");
|
||||
}
|
||||
|
||||
event Comm::incoming_connection_established(peer_name: string)
|
||||
{
|
||||
print "Comm::incoming_connection_established", peer_name;
|
||||
}
|
||||
|
||||
event Test::log_test(rec: Test::Info)
|
||||
{
|
||||
print "wrote log", rec;
|
||||
|
||||
if ( rec$num == 5 )
|
||||
terminate();
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
# @TEST-EXEC: cat %INPUT >output && btest-diff output
|
||||
|
||||
printing-connector.bro
|
||||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef Comm::endpoint_name = "connector";
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::connect("127.0.0.1", broker_port, 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;
|
||||
Comm::print("bro/print/hi", "hello");
|
||||
Comm::print("bro/print/stuff", "...");
|
||||
Comm::print("bro/print/bye", "goodbye");
|
||||
}
|
||||
|
||||
event Comm::outgoing_connection_broken(peer_address: string,
|
||||
peer_port: port)
|
||||
{
|
||||
terminate();
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
# @TEST-EXEC: cat %INPUT >output && btest-diff output
|
||||
|
||||
printing-listener.bro
|
||||
|
||||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef Comm::endpoint_name = "listener";
|
||||
global msg_count = 0;
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::subscribe_to_prints("bro/print/");
|
||||
Comm::listen(broker_port, "127.0.0.1");
|
||||
}
|
||||
|
||||
event Comm::incoming_connection_established(peer_name: string)
|
||||
{
|
||||
print "Comm::incoming_connection_established", peer_name;
|
||||
}
|
||||
|
||||
event Comm::print_handler(msg: string)
|
||||
{
|
||||
++msg_count;
|
||||
print "got print message", msg;
|
||||
|
||||
if ( msg_count == 3 )
|
||||
terminate();
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
# @TEST-EXEC: cat %INPUT >output && btest-diff output
|
||||
|
||||
stores-connector.bro
|
||||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
global h: opaque of Store::Handle;
|
||||
|
||||
function dv(d: Comm::Data): Comm::DataVector
|
||||
{
|
||||
local rval: Comm::DataVector;
|
||||
rval[0] = d;
|
||||
return rval;
|
||||
}
|
||||
|
||||
global ready: event();
|
||||
|
||||
event Comm::outgoing_connection_broken(peer_address: string,
|
||||
peer_port: port)
|
||||
{
|
||||
terminate();
|
||||
}
|
||||
|
||||
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"};
|
||||
h = Store::create_master("mystore");
|
||||
Store::insert(h, Comm::data("one"), Comm::data(110));
|
||||
Store::insert(h, Comm::data("two"), Comm::data(223));
|
||||
Store::insert(h, Comm::data("myset"), Comm::data(myset));
|
||||
Store::insert(h, Comm::data("myvec"), Comm::data(myvec));
|
||||
Store::increment(h, Comm::data("one"));
|
||||
Store::decrement(h, Comm::data("two"));
|
||||
Store::add_to_set(h, Comm::data("myset"), Comm::data("d"));
|
||||
Store::remove_from_set(h, Comm::data("myset"), Comm::data("b"));
|
||||
Store::push_left(h, Comm::data("myvec"), dv(Comm::data("delta")));
|
||||
Store::push_right(h, Comm::data("myvec"), dv(Comm::data("omega")));
|
||||
|
||||
when ( local res = Store::size(h) )
|
||||
{
|
||||
print "master size", res;
|
||||
event ready();
|
||||
}
|
||||
timeout 10sec
|
||||
{ print "timeout"; }
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::connect("127.0.0.1", broker_port, 1secs);
|
||||
Comm::auto_event("bro/event/ready", ready);
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
# @TEST-EXEC: cat %INPUT >output && btest-diff output
|
||||
|
||||
stores-listener.bro
|
||||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
global h: opaque of Store::Handle;
|
||||
global expected_key_count = 4;
|
||||
global key_count = 0;
|
||||
|
||||
function do_lookup(key: string)
|
||||
{
|
||||
when ( local res = Store::lookup(h, Comm::data(key)) )
|
||||
{
|
||||
++key_count;
|
||||
print "lookup", key, res;
|
||||
|
||||
if ( key_count == expected_key_count )
|
||||
terminate();
|
||||
}
|
||||
timeout 10sec
|
||||
{ print "timeout", key; }
|
||||
}
|
||||
|
||||
event ready()
|
||||
{
|
||||
h = Store::create_clone("mystore");
|
||||
|
||||
when ( local res = Store::keys(h) )
|
||||
{
|
||||
print "clone keys", res;
|
||||
do_lookup(Comm::refine_to_string(Comm::vector_lookup(res$result, 0)));
|
||||
do_lookup(Comm::refine_to_string(Comm::vector_lookup(res$result, 1)));
|
||||
do_lookup(Comm::refine_to_string(Comm::vector_lookup(res$result, 2)));
|
||||
do_lookup(Comm::refine_to_string(Comm::vector_lookup(res$result, 3)));
|
||||
}
|
||||
timeout 10sec
|
||||
{ print "timeout"; }
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::subscribe_to_events("bro/event/ready");
|
||||
Comm::listen(broker_port, "127.0.0.1");
|
||||
}
|
|
@ -192,7 +192,7 @@
|
|||
0.000000 MetaHookPost CallFunction(Log::__create_stream, <frame>, (Weird::LOG, [columns=<no value description>, ev=Weird::log_weird])) -> <no result>
|
||||
0.000000 MetaHookPost CallFunction(Log::__create_stream, <frame>, (X509::LOG, [columns=<no value description>, ev=X509::log_x509])) -> <no result>
|
||||
0.000000 MetaHookPost CallFunction(Log::__create_stream, <frame>, (mysql::LOG, [columns=<no value description>, ev=MySQL::log_mysql])) -> <no result>
|
||||
0.000000 MetaHookPost CallFunction(Log::__write, <frame>, (PacketFilter::LOG, [ts=1425348860.085231, node=bro, filter=ip or not ip, init=T, success=T])) -> <no result>
|
||||
0.000000 MetaHookPost CallFunction(Log::__write, <frame>, (PacketFilter::LOG, [ts=1425596289.27327, node=bro, filter=ip or not ip, init=T, success=T])) -> <no result>
|
||||
0.000000 MetaHookPost CallFunction(Log::add_default_filter, <frame>, (Cluster::LOG)) -> <no result>
|
||||
0.000000 MetaHookPost CallFunction(Log::add_default_filter, <frame>, (Communication::LOG)) -> <no result>
|
||||
0.000000 MetaHookPost CallFunction(Log::add_default_filter, <frame>, (Conn::LOG)) -> <no result>
|
||||
|
@ -286,8 +286,8 @@
|
|||
0.000000 MetaHookPost CallFunction(Log::create_stream, <frame>, (Weird::LOG, [columns=<no value description>, ev=Weird::log_weird])) -> <no result>
|
||||
0.000000 MetaHookPost CallFunction(Log::create_stream, <frame>, (X509::LOG, [columns=<no value description>, ev=X509::log_x509])) -> <no result>
|
||||
0.000000 MetaHookPost CallFunction(Log::create_stream, <frame>, (mysql::LOG, [columns=<no value description>, ev=MySQL::log_mysql])) -> <no result>
|
||||
0.000000 MetaHookPost CallFunction(Log::default_path_func, <null>, (PacketFilter::LOG, , [ts=1425348860.085231, node=bro, filter=ip or not ip, init=T, success=T])) -> <no result>
|
||||
0.000000 MetaHookPost CallFunction(Log::write, <frame>, (PacketFilter::LOG, [ts=1425348860.085231, node=bro, filter=ip or not ip, init=T, success=T])) -> <no result>
|
||||
0.000000 MetaHookPost CallFunction(Log::default_path_func, <null>, (PacketFilter::LOG, , [ts=1425596289.27327, node=bro, filter=ip or not ip, init=T, success=T])) -> <no result>
|
||||
0.000000 MetaHookPost CallFunction(Log::write, <frame>, (PacketFilter::LOG, [ts=1425596289.27327, node=bro, filter=ip or not ip, init=T, success=T])) -> <no result>
|
||||
0.000000 MetaHookPost CallFunction(Notice::want_pp, <frame>, ()) -> <no result>
|
||||
0.000000 MetaHookPost CallFunction(PacketFilter::build, <frame>, ()) -> <no result>
|
||||
0.000000 MetaHookPost CallFunction(PacketFilter::combine_filters, <frame>, (ip or not ip, and, )) -> <no result>
|
||||
|
@ -478,8 +478,8 @@
|
|||
0.000000 MetaHookPost LoadFile(base<...>/analyzer) -> -1
|
||||
0.000000 MetaHookPost LoadFile(base<...>/analyzer.bif) -> -1
|
||||
0.000000 MetaHookPost LoadFile(base<...>/bro.bif) -> -1
|
||||
0.000000 MetaHookPost LoadFile(base<...>/broker) -> -1
|
||||
0.000000 MetaHookPost LoadFile(base<...>/cluster) -> -1
|
||||
0.000000 MetaHookPost LoadFile(base<...>/comm) -> -1
|
||||
0.000000 MetaHookPost LoadFile(base<...>/communication) -> -1
|
||||
0.000000 MetaHookPost LoadFile(base<...>/conn) -> -1
|
||||
0.000000 MetaHookPost LoadFile(base<...>/conn-ids) -> -1
|
||||
|
@ -737,7 +737,7 @@
|
|||
0.000000 MetaHookPre CallFunction(Log::__create_stream, <frame>, (Weird::LOG, [columns=<no value description>, ev=Weird::log_weird]))
|
||||
0.000000 MetaHookPre CallFunction(Log::__create_stream, <frame>, (X509::LOG, [columns=<no value description>, ev=X509::log_x509]))
|
||||
0.000000 MetaHookPre CallFunction(Log::__create_stream, <frame>, (mysql::LOG, [columns=<no value description>, ev=MySQL::log_mysql]))
|
||||
0.000000 MetaHookPre CallFunction(Log::__write, <frame>, (PacketFilter::LOG, [ts=1425348860.085231, node=bro, filter=ip or not ip, init=T, success=T]))
|
||||
0.000000 MetaHookPre CallFunction(Log::__write, <frame>, (PacketFilter::LOG, [ts=1425596289.27327, node=bro, filter=ip or not ip, init=T, success=T]))
|
||||
0.000000 MetaHookPre CallFunction(Log::add_default_filter, <frame>, (Cluster::LOG))
|
||||
0.000000 MetaHookPre CallFunction(Log::add_default_filter, <frame>, (Communication::LOG))
|
||||
0.000000 MetaHookPre CallFunction(Log::add_default_filter, <frame>, (Conn::LOG))
|
||||
|
@ -831,8 +831,8 @@
|
|||
0.000000 MetaHookPre CallFunction(Log::create_stream, <frame>, (Weird::LOG, [columns=<no value description>, ev=Weird::log_weird]))
|
||||
0.000000 MetaHookPre CallFunction(Log::create_stream, <frame>, (X509::LOG, [columns=<no value description>, ev=X509::log_x509]))
|
||||
0.000000 MetaHookPre CallFunction(Log::create_stream, <frame>, (mysql::LOG, [columns=<no value description>, ev=MySQL::log_mysql]))
|
||||
0.000000 MetaHookPre CallFunction(Log::default_path_func, <null>, (PacketFilter::LOG, , [ts=1425348860.085231, node=bro, filter=ip or not ip, init=T, success=T]))
|
||||
0.000000 MetaHookPre CallFunction(Log::write, <frame>, (PacketFilter::LOG, [ts=1425348860.085231, node=bro, filter=ip or not ip, init=T, success=T]))
|
||||
0.000000 MetaHookPre CallFunction(Log::default_path_func, <null>, (PacketFilter::LOG, , [ts=1425596289.27327, node=bro, filter=ip or not ip, init=T, success=T]))
|
||||
0.000000 MetaHookPre CallFunction(Log::write, <frame>, (PacketFilter::LOG, [ts=1425596289.27327, node=bro, filter=ip or not ip, init=T, success=T]))
|
||||
0.000000 MetaHookPre CallFunction(Notice::want_pp, <frame>, ())
|
||||
0.000000 MetaHookPre CallFunction(PacketFilter::build, <frame>, ())
|
||||
0.000000 MetaHookPre CallFunction(PacketFilter::combine_filters, <frame>, (ip or not ip, and, ))
|
||||
|
@ -1023,8 +1023,8 @@
|
|||
0.000000 MetaHookPre LoadFile(base<...>/analyzer)
|
||||
0.000000 MetaHookPre LoadFile(base<...>/analyzer.bif)
|
||||
0.000000 MetaHookPre LoadFile(base<...>/bro.bif)
|
||||
0.000000 MetaHookPre LoadFile(base<...>/broker)
|
||||
0.000000 MetaHookPre LoadFile(base<...>/cluster)
|
||||
0.000000 MetaHookPre LoadFile(base<...>/comm)
|
||||
0.000000 MetaHookPre LoadFile(base<...>/communication)
|
||||
0.000000 MetaHookPre LoadFile(base<...>/conn)
|
||||
0.000000 MetaHookPre LoadFile(base<...>/conn-ids)
|
||||
|
@ -1281,7 +1281,7 @@
|
|||
0.000000 | HookCallFunction Log::__create_stream(Weird::LOG, [columns=<no value description>, ev=Weird::log_weird])
|
||||
0.000000 | HookCallFunction Log::__create_stream(X509::LOG, [columns=<no value description>, ev=X509::log_x509])
|
||||
0.000000 | HookCallFunction Log::__create_stream(mysql::LOG, [columns=<no value description>, ev=MySQL::log_mysql])
|
||||
0.000000 | HookCallFunction Log::__write(PacketFilter::LOG, [ts=1425348860.085231, node=bro, filter=ip or not ip, init=T, success=T])
|
||||
0.000000 | HookCallFunction Log::__write(PacketFilter::LOG, [ts=1425596289.27327, node=bro, filter=ip or not ip, init=T, success=T])
|
||||
0.000000 | HookCallFunction Log::add_default_filter(Cluster::LOG)
|
||||
0.000000 | HookCallFunction Log::add_default_filter(Communication::LOG)
|
||||
0.000000 | HookCallFunction Log::add_default_filter(Conn::LOG)
|
||||
|
@ -1375,8 +1375,8 @@
|
|||
0.000000 | HookCallFunction Log::create_stream(Weird::LOG, [columns=<no value description>, ev=Weird::log_weird])
|
||||
0.000000 | HookCallFunction Log::create_stream(X509::LOG, [columns=<no value description>, ev=X509::log_x509])
|
||||
0.000000 | HookCallFunction Log::create_stream(mysql::LOG, [columns=<no value description>, ev=MySQL::log_mysql])
|
||||
0.000000 | HookCallFunction Log::default_path_func(PacketFilter::LOG, , [ts=1425348860.085231, node=bro, filter=ip or not ip, init=T, success=T])
|
||||
0.000000 | HookCallFunction Log::write(PacketFilter::LOG, [ts=1425348860.085231, node=bro, filter=ip or not ip, init=T, success=T])
|
||||
0.000000 | HookCallFunction Log::default_path_func(PacketFilter::LOG, , [ts=1425596289.27327, node=bro, filter=ip or not ip, init=T, success=T])
|
||||
0.000000 | HookCallFunction Log::write(PacketFilter::LOG, [ts=1425596289.27327, node=bro, filter=ip or not ip, init=T, success=T])
|
||||
0.000000 | HookCallFunction Notice::want_pp()
|
||||
0.000000 | HookCallFunction PacketFilter::build()
|
||||
0.000000 | HookCallFunction PacketFilter::combine_filters(ip or not ip, and, )
|
||||
|
|
125
testing/btest/broker/clone_store.bro
Normal file
125
testing/btest/broker/clone_store.bro
Normal file
|
@ -0,0 +1,125 @@
|
|||
# @TEST-SERIALIZE: brokercomm
|
||||
# @TEST-REQUIRES: grep -q ENABLE_BROKER $BUILD/CMakeCache.txt
|
||||
|
||||
# @TEST-EXEC: btest-bg-run clone "bro -b -r $TRACES/wikipedia.trace ../clone.bro broker_port=$BROKER_PORT >clone.out"
|
||||
# @TEST-EXEC: btest-bg-run master "bro -b -r $TRACES/wikipedia.trace ../master.bro broker_port=$BROKER_PORT >master.out"
|
||||
|
||||
# @TEST-EXEC: btest-bg-wait 20
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-sort btest-diff clone/clone.out
|
||||
# @TEST-EXEC: btest-diff master/master.out
|
||||
|
||||
@TEST-START-FILE clone.bro
|
||||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
global h: opaque of BrokerStore::Handle;
|
||||
global expected_key_count = 4;
|
||||
global key_count = 0;
|
||||
|
||||
global query_timeout = 15sec;
|
||||
|
||||
function do_lookup(key: string)
|
||||
{
|
||||
when ( local res = BrokerStore::lookup(h, BrokerComm::data(key)) )
|
||||
{
|
||||
++key_count;
|
||||
print "lookup", key, res;
|
||||
|
||||
if ( key_count == expected_key_count )
|
||||
terminate();
|
||||
}
|
||||
timeout query_timeout
|
||||
{
|
||||
print "clone lookup query timeout";
|
||||
terminate();
|
||||
}
|
||||
}
|
||||
|
||||
event ready()
|
||||
{
|
||||
h = BrokerStore::create_clone("mystore");
|
||||
|
||||
when ( local res = BrokerStore::keys(h) )
|
||||
{
|
||||
print "clone keys", res;
|
||||
do_lookup(BrokerComm::refine_to_string(BrokerComm::vector_lookup(res$result, 0)));
|
||||
do_lookup(BrokerComm::refine_to_string(BrokerComm::vector_lookup(res$result, 1)));
|
||||
do_lookup(BrokerComm::refine_to_string(BrokerComm::vector_lookup(res$result, 2)));
|
||||
do_lookup(BrokerComm::refine_to_string(BrokerComm::vector_lookup(res$result, 3)));
|
||||
}
|
||||
timeout query_timeout
|
||||
{
|
||||
print "clone keys query timeout";
|
||||
terminate();
|
||||
}
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
BrokerComm::enable();
|
||||
BrokerComm::subscribe_to_events("bro/event/ready");
|
||||
BrokerComm::listen(broker_port, "127.0.0.1");
|
||||
}
|
||||
|
||||
@TEST-END-FILE
|
||||
|
||||
@TEST-START-FILE master.bro
|
||||
|
||||
global query_timeout = 15sec;
|
||||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
global h: opaque of BrokerStore::Handle;
|
||||
|
||||
function dv(d: BrokerComm::Data): BrokerComm::DataVector
|
||||
{
|
||||
local rval: BrokerComm::DataVector;
|
||||
rval[0] = d;
|
||||
return rval;
|
||||
}
|
||||
|
||||
global ready: event();
|
||||
|
||||
event BrokerComm::outgoing_connection_broken(peer_address: string,
|
||||
peer_port: port)
|
||||
{
|
||||
terminate();
|
||||
}
|
||||
|
||||
event BrokerComm::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"};
|
||||
h = BrokerStore::create_master("mystore");
|
||||
BrokerStore::insert(h, BrokerComm::data("one"), BrokerComm::data(110));
|
||||
BrokerStore::insert(h, BrokerComm::data("two"), BrokerComm::data(223));
|
||||
BrokerStore::insert(h, BrokerComm::data("myset"), BrokerComm::data(myset));
|
||||
BrokerStore::insert(h, BrokerComm::data("myvec"), BrokerComm::data(myvec));
|
||||
BrokerStore::increment(h, BrokerComm::data("one"));
|
||||
BrokerStore::decrement(h, BrokerComm::data("two"));
|
||||
BrokerStore::add_to_set(h, BrokerComm::data("myset"), BrokerComm::data("d"));
|
||||
BrokerStore::remove_from_set(h, BrokerComm::data("myset"), BrokerComm::data("b"));
|
||||
BrokerStore::push_left(h, BrokerComm::data("myvec"), dv(BrokerComm::data("delta")));
|
||||
BrokerStore::push_right(h, BrokerComm::data("myvec"), dv(BrokerComm::data("omega")));
|
||||
|
||||
when ( local res = BrokerStore::size(h) )
|
||||
{ event ready(); }
|
||||
timeout query_timeout
|
||||
{
|
||||
print "master size query timeout";
|
||||
terminate();
|
||||
}
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
BrokerComm::enable();
|
||||
BrokerComm::auto_event("bro/event/ready", ready);
|
||||
BrokerComm::connect("127.0.0.1", broker_port, 1secs);
|
||||
}
|
||||
|
||||
@TEST-END-FILE
|
|
@ -12,22 +12,22 @@
|
|||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef Comm::endpoint_name = "listener";
|
||||
redef BrokerComm::endpoint_name = "listener";
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::listen(broker_port, "127.0.0.1");
|
||||
BrokerComm::enable();
|
||||
BrokerComm::listen(broker_port, "127.0.0.1");
|
||||
}
|
||||
|
||||
event Comm::incoming_connection_established(peer_name: string)
|
||||
event BrokerComm::incoming_connection_established(peer_name: string)
|
||||
{
|
||||
print "Comm::incoming_connection_established", peer_name;;
|
||||
print "BrokerComm::incoming_connection_established", peer_name;;
|
||||
}
|
||||
|
||||
event Comm::incoming_connection_broken(peer_name: string)
|
||||
event BrokerComm::incoming_connection_broken(peer_name: string)
|
||||
{
|
||||
print "Comm::incoming_connection_broken", peer_name;;
|
||||
print "BrokerComm::incoming_connection_broken", peer_name;;
|
||||
terminate();
|
||||
}
|
||||
|
||||
|
@ -37,19 +37,19 @@ event Comm::incoming_connection_broken(peer_name: string)
|
|||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
redef Comm::endpoint_name = "connector";
|
||||
redef BrokerComm::endpoint_name = "connector";
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::connect("127.0.0.1", broker_port, 1sec);
|
||||
BrokerComm::enable();
|
||||
BrokerComm::connect("127.0.0.1", broker_port, 1sec);
|
||||
}
|
||||
|
||||
event Comm::outgoing_connection_established(peer_address: string,
|
||||
event BrokerComm::outgoing_connection_established(peer_address: string,
|
||||
peer_port: port,
|
||||
peer_name: string)
|
||||
{
|
||||
print "Comm::outgoing_connection_established",
|
||||
print "BrokerComm::outgoing_connection_established",
|
||||
peer_address, peer_port, peer_name;;
|
||||
terminate();
|
||||
}
|
222
testing/btest/broker/data.bro
Normal file
222
testing/btest/broker/data.bro
Normal file
|
@ -0,0 +1,222 @@
|
|||
# @TEST-REQUIRES: grep -q ENABLE_BROKER $BUILD/CMakeCache.txt
|
||||
|
||||
# @TEST-EXEC: bro -b %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
type bro_set: set[string];
|
||||
type bro_table: table[string] of count;
|
||||
type bro_vector: vector of string;
|
||||
|
||||
type bro_record : record {
|
||||
a: string &optional;
|
||||
b: string &default = "bee";
|
||||
c: count;
|
||||
};
|
||||
|
||||
function comm_record_to_bro_record_recurse(it: opaque of BrokerComm::RecordIterator,
|
||||
rval: bro_record,
|
||||
idx: count): bro_record
|
||||
{
|
||||
if ( BrokerComm::record_iterator_last(it) )
|
||||
return rval;
|
||||
|
||||
local field_value = BrokerComm::record_iterator_value(it);
|
||||
|
||||
if ( field_value?$d )
|
||||
switch ( idx ) {
|
||||
case 0:
|
||||
rval$a = BrokerComm::refine_to_string(field_value);
|
||||
break;
|
||||
case 1:
|
||||
rval$b = BrokerComm::refine_to_string(field_value);
|
||||
break;
|
||||
case 2:
|
||||
rval$c = BrokerComm::refine_to_count(field_value);
|
||||
break;
|
||||
};
|
||||
|
||||
++idx;
|
||||
BrokerComm::record_iterator_next(it);
|
||||
return comm_record_to_bro_record_recurse(it, rval, idx);
|
||||
}
|
||||
|
||||
function comm_record_to_bro_record(d: BrokerComm::Data): bro_record
|
||||
{
|
||||
return comm_record_to_bro_record_recurse(BrokerComm::record_iterator(d),
|
||||
bro_record($c = 0), 0);
|
||||
}
|
||||
|
||||
function
|
||||
comm_set_to_bro_set_recurse(it: opaque of BrokerComm::SetIterator,
|
||||
rval: bro_set): bro_set
|
||||
{
|
||||
if ( BrokerComm::set_iterator_last(it) )
|
||||
return rval;
|
||||
|
||||
add rval[BrokerComm::refine_to_string(BrokerComm::set_iterator_value(it))];
|
||||
BrokerComm::set_iterator_next(it);
|
||||
return comm_set_to_bro_set_recurse(it, rval);
|
||||
}
|
||||
|
||||
|
||||
function comm_set_to_bro_set(d: BrokerComm::Data): bro_set
|
||||
{
|
||||
return comm_set_to_bro_set_recurse(BrokerComm::set_iterator(d), bro_set());
|
||||
}
|
||||
|
||||
function
|
||||
comm_table_to_bro_table_recurse(it: opaque of BrokerComm::TableIterator,
|
||||
rval: bro_table): bro_table
|
||||
{
|
||||
if ( BrokerComm::table_iterator_last(it) )
|
||||
return rval;
|
||||
|
||||
local item = BrokerComm::table_iterator_value(it);
|
||||
rval[BrokerComm::refine_to_string(item$key)] = BrokerComm::refine_to_count(item$val);
|
||||
BrokerComm::table_iterator_next(it);
|
||||
return comm_table_to_bro_table_recurse(it, rval);
|
||||
}
|
||||
|
||||
function comm_table_to_bro_table(d: BrokerComm::Data): bro_table
|
||||
{
|
||||
return comm_table_to_bro_table_recurse(BrokerComm::table_iterator(d),
|
||||
bro_table());
|
||||
}
|
||||
|
||||
function comm_vector_to_bro_vector_recurse(it: opaque of BrokerComm::VectorIterator,
|
||||
rval: bro_vector): bro_vector
|
||||
{
|
||||
if ( BrokerComm::vector_iterator_last(it) )
|
||||
return rval;
|
||||
|
||||
rval[|rval|] = BrokerComm::refine_to_string(BrokerComm::vector_iterator_value(it));
|
||||
BrokerComm::vector_iterator_next(it);
|
||||
return comm_vector_to_bro_vector_recurse(it, rval);
|
||||
}
|
||||
|
||||
function comm_vector_to_bro_vector(d: BrokerComm::Data): bro_vector
|
||||
{
|
||||
return comm_vector_to_bro_vector_recurse(BrokerComm::vector_iterator(d),
|
||||
bro_vector());
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
BrokerComm::enable();
|
||||
print BrokerComm::data_type(BrokerComm::data(T));
|
||||
print BrokerComm::data_type(BrokerComm::data(+1));
|
||||
print BrokerComm::data_type(BrokerComm::data(1));
|
||||
print BrokerComm::data_type(BrokerComm::data(1.1));
|
||||
print BrokerComm::data_type(BrokerComm::data("1 (how creative)"));
|
||||
print BrokerComm::data_type(BrokerComm::data(1.1.1.1));
|
||||
print BrokerComm::data_type(BrokerComm::data(1.1.1.1/1));
|
||||
print BrokerComm::data_type(BrokerComm::data(1/udp));
|
||||
print BrokerComm::data_type(BrokerComm::data(double_to_time(1)));
|
||||
print BrokerComm::data_type(BrokerComm::data(1sec));
|
||||
print BrokerComm::data_type(BrokerComm::data(BrokerComm::BOOL));
|
||||
local s: bro_set = bro_set("one", "two", "three");
|
||||
local t: bro_table = bro_table(["one"] = 1, ["two"] = 2, ["three"] = 3);
|
||||
local v: bro_vector = bro_vector("zero", "one", "two");
|
||||
local r: bro_record = bro_record($c = 1);
|
||||
print BrokerComm::data_type(BrokerComm::data(s));
|
||||
print BrokerComm::data_type(BrokerComm::data(t));
|
||||
print BrokerComm::data_type(BrokerComm::data(v));
|
||||
print BrokerComm::data_type(BrokerComm::data(r));
|
||||
|
||||
print "***************************";
|
||||
|
||||
print BrokerComm::refine_to_bool(BrokerComm::data(T));
|
||||
print BrokerComm::refine_to_bool(BrokerComm::data(F));
|
||||
print BrokerComm::refine_to_int(BrokerComm::data(+1));
|
||||
print BrokerComm::refine_to_int(BrokerComm::data(+0));
|
||||
print BrokerComm::refine_to_int(BrokerComm::data(-1));
|
||||
print BrokerComm::refine_to_count(BrokerComm::data(1));
|
||||
print BrokerComm::refine_to_count(BrokerComm::data(0));
|
||||
print BrokerComm::refine_to_double(BrokerComm::data(1.1));
|
||||
print BrokerComm::refine_to_double(BrokerComm::data(-11.1));
|
||||
print BrokerComm::refine_to_string(BrokerComm::data("hello"));
|
||||
print BrokerComm::refine_to_addr(BrokerComm::data(1.2.3.4));
|
||||
print BrokerComm::refine_to_subnet(BrokerComm::data(192.168.1.1/16));
|
||||
print BrokerComm::refine_to_port(BrokerComm::data(22/tcp));
|
||||
print BrokerComm::refine_to_time(BrokerComm::data(double_to_time(42)));
|
||||
print BrokerComm::refine_to_interval(BrokerComm::data(3min));
|
||||
print BrokerComm::refine_to_enum_name(BrokerComm::data(BrokerComm::BOOL));
|
||||
|
||||
print "***************************";
|
||||
|
||||
local cs = BrokerComm::data(s);
|
||||
print comm_set_to_bro_set(cs);
|
||||
cs = BrokerComm::set_create();
|
||||
print BrokerComm::set_size(cs);
|
||||
print BrokerComm::set_insert(cs, BrokerComm::data("hi"));
|
||||
print BrokerComm::set_size(cs);
|
||||
print BrokerComm::set_contains(cs, BrokerComm::data("hi"));
|
||||
print BrokerComm::set_contains(cs, BrokerComm::data("bye"));
|
||||
print BrokerComm::set_insert(cs, BrokerComm::data("bye"));
|
||||
print BrokerComm::set_size(cs);
|
||||
print BrokerComm::set_remove(cs, BrokerComm::data("hi"));
|
||||
print BrokerComm::set_size(cs);
|
||||
print BrokerComm::set_remove(cs, BrokerComm::data("hi"));
|
||||
print comm_set_to_bro_set(cs);
|
||||
BrokerComm::set_clear(cs);
|
||||
print BrokerComm::set_size(cs);
|
||||
|
||||
print "***************************";
|
||||
|
||||
local ct = BrokerComm::data(t);
|
||||
print comm_table_to_bro_table(ct);
|
||||
ct = BrokerComm::table_create();
|
||||
print BrokerComm::table_size(ct);
|
||||
print BrokerComm::table_insert(ct, BrokerComm::data("hi"), BrokerComm::data(42));
|
||||
print BrokerComm::table_size(ct);
|
||||
print BrokerComm::table_contains(ct, BrokerComm::data("hi"));
|
||||
print BrokerComm::refine_to_count(BrokerComm::table_lookup(ct, BrokerComm::data("hi")));
|
||||
print BrokerComm::table_contains(ct, BrokerComm::data("bye"));
|
||||
print BrokerComm::table_insert(ct, BrokerComm::data("bye"), BrokerComm::data(7));
|
||||
print BrokerComm::table_size(ct);
|
||||
print BrokerComm::table_insert(ct, BrokerComm::data("bye"), BrokerComm::data(37));
|
||||
print BrokerComm::table_size(ct);
|
||||
print BrokerComm::refine_to_count(BrokerComm::table_lookup(ct, BrokerComm::data("bye")));
|
||||
print BrokerComm::table_remove(ct, BrokerComm::data("hi"));
|
||||
print BrokerComm::table_size(ct);
|
||||
|
||||
print "***************************";
|
||||
|
||||
local cv = BrokerComm::data(v);
|
||||
print comm_vector_to_bro_vector(cv);
|
||||
cv = BrokerComm::vector_create();
|
||||
print BrokerComm::vector_size(cv);
|
||||
print BrokerComm::vector_insert(cv, BrokerComm::data("hi"), 0);
|
||||
print BrokerComm::vector_insert(cv, BrokerComm::data("hello"), 1);
|
||||
print BrokerComm::vector_insert(cv, BrokerComm::data("greetings"), 2);
|
||||
print BrokerComm::vector_insert(cv, BrokerComm::data("salutations"), 1);
|
||||
print comm_vector_to_bro_vector(cv);
|
||||
print BrokerComm::vector_size(cv);
|
||||
print BrokerComm::vector_replace(cv, BrokerComm::data("bah"), 2);
|
||||
print BrokerComm::vector_lookup(cv, 2);
|
||||
print BrokerComm::vector_lookup(cv, 0);
|
||||
print comm_vector_to_bro_vector(cv);
|
||||
print BrokerComm::vector_remove(cv, 2);
|
||||
print comm_vector_to_bro_vector(cv);
|
||||
print BrokerComm::vector_size(cv);
|
||||
|
||||
print "***************************";
|
||||
|
||||
local cr = BrokerComm::data(r);
|
||||
print comm_record_to_bro_record(cr);
|
||||
r$a = "test";
|
||||
cr = BrokerComm::data(r);
|
||||
print comm_record_to_bro_record(cr);
|
||||
r$b = "testagain";
|
||||
cr = BrokerComm::data(r);
|
||||
print comm_record_to_bro_record(cr);
|
||||
cr = BrokerComm::record_create(3);
|
||||
print BrokerComm::record_size(cr);
|
||||
print BrokerComm::record_assign(cr, BrokerComm::data("hi"), 0);
|
||||
print BrokerComm::record_assign(cr, BrokerComm::data("hello"), 1);
|
||||
print BrokerComm::record_assign(cr, BrokerComm::data(37), 2);
|
||||
print BrokerComm::record_lookup(cr, 0);
|
||||
print BrokerComm::record_lookup(cr, 1);
|
||||
print BrokerComm::record_lookup(cr, 2);
|
||||
print BrokerComm::record_size(cr);
|
||||
}
|
181
testing/btest/broker/master_store.bro
Normal file
181
testing/btest/broker/master_store.bro
Normal file
|
@ -0,0 +1,181 @@
|
|||
# @TEST-REQUIRES: grep -q ENABLE_BROKER $BUILD/CMakeCache.txt
|
||||
|
||||
# @TEST-EXEC: btest-bg-run master "bro -b -r $TRACES/wikipedia.trace %INPUT >out"
|
||||
# @TEST-EXEC: btest-bg-wait 20
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-sort btest-diff master/out
|
||||
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
global h: opaque of BrokerStore::Handle;
|
||||
global lookup_count = 0;
|
||||
const lookup_expect_count = 5;
|
||||
global exists_count = 0;
|
||||
const exists_expect_count = 4;
|
||||
global pop_count = 0;
|
||||
const pop_expect_count = 2;
|
||||
|
||||
global test_size: event(where: string &default = "");
|
||||
|
||||
global query_timeout = 5sec;
|
||||
|
||||
event test_clear()
|
||||
{
|
||||
BrokerStore::clear(h);
|
||||
event test_size("after clear");
|
||||
}
|
||||
|
||||
event test_size(where: string)
|
||||
{
|
||||
when ( local res = BrokerStore::size(h) )
|
||||
{
|
||||
if ( where == "" )
|
||||
{
|
||||
print fmt("size: %s", res);
|
||||
event test_clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
print fmt("size (%s): %s", where, res);
|
||||
terminate();
|
||||
}
|
||||
}
|
||||
timeout query_timeout
|
||||
{
|
||||
print "'size' query timeout";
|
||||
|
||||
if ( where == "" )
|
||||
event test_clear();
|
||||
else
|
||||
terminate();
|
||||
}
|
||||
}
|
||||
|
||||
event test_keys()
|
||||
{
|
||||
when ( local res = BrokerStore::keys(h) )
|
||||
{
|
||||
print fmt("keys: %s", res);
|
||||
event test_size();
|
||||
}
|
||||
timeout query_timeout
|
||||
{
|
||||
print "'keys' query timeout";
|
||||
event test_size();
|
||||
}
|
||||
}
|
||||
|
||||
event test_pop(key: string)
|
||||
{
|
||||
when ( local lres = BrokerStore::pop_left(h, BrokerComm::data(key)) )
|
||||
{
|
||||
print fmt("pop_left(%s): %s", key, lres);
|
||||
++pop_count;
|
||||
|
||||
if ( pop_count == pop_expect_count )
|
||||
event test_keys();
|
||||
}
|
||||
timeout query_timeout
|
||||
{
|
||||
print "'pop_left' timeout";
|
||||
++pop_count;
|
||||
|
||||
if ( pop_count == pop_expect_count )
|
||||
event test_keys();
|
||||
}
|
||||
|
||||
when ( local rres = BrokerStore::pop_right(h, BrokerComm::data(key)) )
|
||||
{
|
||||
print fmt("pop_right(%s): %s", key, rres);
|
||||
++pop_count;
|
||||
|
||||
if ( pop_count == pop_expect_count )
|
||||
event test_keys();
|
||||
}
|
||||
timeout query_timeout
|
||||
{
|
||||
print "'pop_right' timeout";
|
||||
++pop_count;
|
||||
|
||||
if ( pop_count == pop_expect_count )
|
||||
event test_keys();
|
||||
}
|
||||
}
|
||||
|
||||
function do_exists(key: string)
|
||||
{
|
||||
when ( local res = BrokerStore::exists(h, BrokerComm::data(key)) )
|
||||
{
|
||||
print fmt("exists(%s): %s", key, res);
|
||||
++exists_count;
|
||||
|
||||
if ( exists_count == exists_expect_count )
|
||||
event test_pop("myvec");
|
||||
}
|
||||
timeout query_timeout
|
||||
{
|
||||
print "'exists' query timeout";
|
||||
++exists_count;
|
||||
|
||||
if ( exists_count == exists_expect_count )
|
||||
event test_pop("myvec");
|
||||
}
|
||||
}
|
||||
|
||||
event test_erase()
|
||||
{
|
||||
BrokerStore::erase(h, BrokerComm::data("two"));
|
||||
do_exists("one");
|
||||
do_exists("two");
|
||||
do_exists("myset");
|
||||
do_exists("four");
|
||||
}
|
||||
|
||||
function do_lookup(key: string)
|
||||
{
|
||||
when ( local res = BrokerStore::lookup(h, BrokerComm::data(key)) )
|
||||
{
|
||||
print fmt("lookup(%s): %s", key, res);
|
||||
++lookup_count;
|
||||
|
||||
if ( lookup_count == lookup_expect_count )
|
||||
event test_erase();
|
||||
}
|
||||
timeout query_timeout
|
||||
{
|
||||
print "'lookup' query timeout";
|
||||
++lookup_count;
|
||||
|
||||
if ( lookup_count == lookup_expect_count )
|
||||
event test_erase();
|
||||
}
|
||||
}
|
||||
|
||||
function dv(d: BrokerComm::Data): BrokerComm::DataVector
|
||||
{
|
||||
local rval: BrokerComm::DataVector;
|
||||
rval[0] = d;
|
||||
return rval;
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
BrokerComm::enable();
|
||||
local myset: set[string] = {"a", "b", "c"};
|
||||
local myvec: vector of string = {"alpha", "beta", "gamma"};
|
||||
h = BrokerStore::create_master("master");
|
||||
BrokerStore::insert(h, BrokerComm::data("one"), BrokerComm::data(110));
|
||||
BrokerStore::insert(h, BrokerComm::data("two"), BrokerComm::data(223));
|
||||
BrokerStore::insert(h, BrokerComm::data("myset"), BrokerComm::data(myset));
|
||||
BrokerStore::insert(h, BrokerComm::data("myvec"), BrokerComm::data(myvec));
|
||||
BrokerStore::increment(h, BrokerComm::data("one"));
|
||||
BrokerStore::decrement(h, BrokerComm::data("two"));
|
||||
BrokerStore::add_to_set(h, BrokerComm::data("myset"), BrokerComm::data("d"));
|
||||
BrokerStore::remove_from_set(h, BrokerComm::data("myset"), BrokerComm::data("b"));
|
||||
BrokerStore::push_left(h, BrokerComm::data("myvec"), dv(BrokerComm::data("delta")));
|
||||
BrokerStore::push_right(h, BrokerComm::data("myvec"), dv(BrokerComm::data("omega")));
|
||||
do_lookup("one");
|
||||
do_lookup("two");
|
||||
do_lookup("myset");
|
||||
do_lookup("four");
|
||||
do_lookup("myvec");
|
||||
}
|
|
@ -18,10 +18,10 @@ global auto_event_handler: event(msg: string, c: count);
|
|||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::subscribe_to_events("bro/event/");
|
||||
Comm::auto_event("bro/event/my_topic", auto_event_handler);
|
||||
Comm::listen(broker_port, "127.0.0.1");
|
||||
BrokerComm::enable();
|
||||
BrokerComm::subscribe_to_events("bro/event/");
|
||||
BrokerComm::auto_event("bro/event/my_topic", auto_event_handler);
|
||||
BrokerComm::listen(broker_port, "127.0.0.1");
|
||||
}
|
||||
|
||||
global event_count = 0;
|
||||
|
@ -39,8 +39,8 @@ event event_handler(msg: string, n: count)
|
|||
}
|
||||
|
||||
event auto_event_handler(msg, n);
|
||||
local args = Comm::event_args(event_handler, "pong", n);
|
||||
Comm::event("bro/event/my_topic", args);
|
||||
local args = BrokerComm::event_args(event_handler, "pong", n);
|
||||
BrokerComm::event("bro/event/my_topic", args);
|
||||
}
|
||||
|
||||
@TEST-END-FILE
|
||||
|
@ -55,24 +55,24 @@ global auto_event_handler: event(msg: string, c: count);
|
|||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::subscribe_to_events("bro/event/my_topic");
|
||||
Comm::connect("127.0.0.1", broker_port, 1secs);
|
||||
BrokerComm::enable();
|
||||
BrokerComm::subscribe_to_events("bro/event/my_topic");
|
||||
BrokerComm::connect("127.0.0.1", broker_port, 1secs);
|
||||
}
|
||||
|
||||
global event_count = 0;
|
||||
|
||||
event Comm::outgoing_connection_established(peer_address: string,
|
||||
event BrokerComm::outgoing_connection_established(peer_address: string,
|
||||
peer_port: port,
|
||||
peer_name: string)
|
||||
{
|
||||
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);
|
||||
print "BrokerComm::outgoing_connection_established", peer_address, peer_port;
|
||||
local args = BrokerComm::event_args(event_handler, "ping", event_count);
|
||||
BrokerComm::event("bro/event/hi", args);
|
||||
++event_count;
|
||||
}
|
||||
|
||||
event Comm::outgoing_connection_broken(peer_address: string,
|
||||
event BrokerComm::outgoing_connection_broken(peer_address: string,
|
||||
peer_port: port)
|
||||
{
|
||||
terminate();
|
||||
|
@ -81,8 +81,8 @@ event Comm::outgoing_connection_broken(peer_address: string,
|
|||
event event_handler(msg: string, n: count)
|
||||
{
|
||||
print "got event msg", msg, n;
|
||||
local args = Comm::event_args(event_handler, "ping", event_count);
|
||||
Comm::event("bro/event/hi", args);
|
||||
local args = BrokerComm::event_args(event_handler, "ping", event_count);
|
||||
BrokerComm::event("bro/event/hi", args);
|
||||
++event_count;
|
||||
}
|
||||
|
|
@ -20,6 +20,7 @@ export {
|
|||
type Info: record {
|
||||
msg: string &log;
|
||||
num: count &log;
|
||||
nolog: string &default="no";
|
||||
};
|
||||
|
||||
global log_test: event(rec: Test::Info);
|
||||
|
@ -27,7 +28,7 @@ export {
|
|||
|
||||
event bro_init() &priority=5
|
||||
{
|
||||
Comm::enable();
|
||||
BrokerComm::enable();
|
||||
Log::create_stream(Test::LOG, [$columns=Test::Info, $ev=log_test]);
|
||||
}
|
||||
|
||||
|
@ -40,8 +41,8 @@ redef exit_only_after_terminate = T;
|
|||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::subscribe_to_logs("bro/log/");
|
||||
Comm::listen(broker_port, "127.0.0.1");
|
||||
BrokerComm::subscribe_to_logs("bro/log/");
|
||||
BrokerComm::listen(broker_port, "127.0.0.1");
|
||||
}
|
||||
|
||||
event Test::log_test(rec: Test::Info)
|
||||
|
@ -61,8 +62,8 @@ redef exit_only_after_terminate = T;
|
|||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable_remote_logs(Test::LOG);
|
||||
Comm::connect("127.0.0.1", broker_port, 1secs);
|
||||
BrokerComm::enable_remote_logs(Test::LOG);
|
||||
BrokerComm::connect("127.0.0.1", broker_port, 1secs);
|
||||
}
|
||||
|
||||
global n = 0;
|
||||
|
@ -79,15 +80,15 @@ event do_write()
|
|||
}
|
||||
}
|
||||
|
||||
event Comm::outgoing_connection_established(peer_address: string,
|
||||
event BrokerComm::outgoing_connection_established(peer_address: string,
|
||||
peer_port: port,
|
||||
peer_name: string)
|
||||
{
|
||||
print "Comm::outgoing_connection_established", peer_address, peer_port;
|
||||
print "BrokerComm::outgoing_connection_established", peer_address, peer_port;
|
||||
event do_write();
|
||||
}
|
||||
|
||||
event Comm::outgoing_connection_broken(peer_address: string,
|
||||
event BrokerComm::outgoing_connection_broken(peer_address: string,
|
||||
peer_port: port)
|
||||
{
|
||||
terminate();
|
|
@ -15,16 +15,16 @@ redef exit_only_after_terminate = T;
|
|||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::listen(broker_port, "127.0.0.1");
|
||||
Comm::subscribe_to_prints("bro/print/");
|
||||
BrokerComm::enable();
|
||||
BrokerComm::listen(broker_port, "127.0.0.1");
|
||||
BrokerComm::subscribe_to_prints("bro/print/");
|
||||
}
|
||||
|
||||
global messages_to_recv = 6;
|
||||
global messages_sent = 0;
|
||||
global messages_recv = 0;
|
||||
|
||||
event Comm::print_handler(msg: string)
|
||||
event BrokerComm::print_handler(msg: string)
|
||||
{
|
||||
++messages_recv;
|
||||
print "got print msg", msg;
|
||||
|
@ -35,7 +35,7 @@ event Comm::print_handler(msg: string)
|
|||
return;
|
||||
}
|
||||
|
||||
Comm::print("bro/print/my_topic", fmt("pong %d", messages_sent));
|
||||
BrokerComm::print("bro/print/my_topic", fmt("pong %d", messages_sent));
|
||||
++messages_sent;
|
||||
}
|
||||
|
||||
|
@ -48,35 +48,35 @@ redef exit_only_after_terminate = T;
|
|||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::subscribe_to_prints("bro/print/my_topic");
|
||||
Comm::connect("127.0.0.1", broker_port, 1secs);
|
||||
BrokerComm::enable();
|
||||
BrokerComm::subscribe_to_prints("bro/print/my_topic");
|
||||
BrokerComm::connect("127.0.0.1", broker_port, 1secs);
|
||||
}
|
||||
|
||||
global messages_sent = 0;
|
||||
global messages_recv = 0;
|
||||
global peer_disconnected = F;
|
||||
|
||||
event Comm::outgoing_connection_established(peer_address: string,
|
||||
event BrokerComm::outgoing_connection_established(peer_address: string,
|
||||
peer_port: port,
|
||||
peer_name: string)
|
||||
{
|
||||
print "Comm::outgoing_connection_established", peer_address, peer_port;
|
||||
Comm::print("bro/print/hi", fmt("ping %d", messages_sent));
|
||||
print "BrokerComm::outgoing_connection_established", peer_address, peer_port;
|
||||
BrokerComm::print("bro/print/hi", fmt("ping %d", messages_sent));
|
||||
++messages_sent;
|
||||
}
|
||||
|
||||
event Comm::outgoing_connection_broken(peer_address: string,
|
||||
event BrokerComm::outgoing_connection_broken(peer_address: string,
|
||||
peer_port: port)
|
||||
{
|
||||
terminate();
|
||||
}
|
||||
|
||||
event Comm::print_handler(msg: string)
|
||||
event BrokerComm::print_handler(msg: string)
|
||||
{
|
||||
++messages_recv;
|
||||
print "got print msg", msg;
|
||||
Comm::print("bro/print/hi", fmt("ping %d", messages_sent));
|
||||
BrokerComm::print("bro/print/hi", fmt("ping %d", messages_sent));
|
||||
++messages_sent;
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
[btest]
|
||||
TestDirs = doc bifs language core scripts istate coverage signatures plugins comm
|
||||
TestDirs = doc bifs language core scripts istate coverage signatures plugins broker
|
||||
TmpDir = %(testbase)s/.tmp
|
||||
BaselineDir = %(testbase)s/Baseline
|
||||
IgnoreDirs = .svn CVS .tmp
|
||||
|
|
|
@ -1,112 +0,0 @@
|
|||
# @TEST-SERIALIZE: brokercomm
|
||||
# @TEST-REQUIRES: grep -q ENABLE_BROKER $BUILD/CMakeCache.txt
|
||||
|
||||
# @TEST-EXEC: btest-bg-run clone "bro -b ../clone.bro broker_port=$BROKER_PORT >clone.out"
|
||||
# @TEST-EXEC: btest-bg-run master "bro -b ../master.bro broker_port=$BROKER_PORT >master.out"
|
||||
|
||||
# @TEST-EXEC: btest-bg-wait 20
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-sort btest-diff clone/clone.out
|
||||
# @TEST-EXEC: btest-diff master/master.out
|
||||
|
||||
@TEST-START-FILE clone.bro
|
||||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
global h: opaque of Store::Handle;
|
||||
global expected_key_count = 4;
|
||||
global key_count = 0;
|
||||
|
||||
function do_lookup(key: string)
|
||||
{
|
||||
when ( local res = Store::lookup(h, Comm::data(key)) )
|
||||
{
|
||||
++key_count;
|
||||
print "lookup", key, res;
|
||||
|
||||
if ( key_count == expected_key_count )
|
||||
terminate();
|
||||
}
|
||||
timeout 10sec
|
||||
{ print "timeout"; }
|
||||
}
|
||||
|
||||
event ready()
|
||||
{
|
||||
h = Store::create_clone("mystore");
|
||||
|
||||
when ( local res = Store::keys(h) )
|
||||
{
|
||||
print "clone keys", res;
|
||||
do_lookup(Comm::refine_to_string(Comm::vector_lookup(res$result, 0)));
|
||||
do_lookup(Comm::refine_to_string(Comm::vector_lookup(res$result, 1)));
|
||||
do_lookup(Comm::refine_to_string(Comm::vector_lookup(res$result, 2)));
|
||||
do_lookup(Comm::refine_to_string(Comm::vector_lookup(res$result, 3)));
|
||||
}
|
||||
timeout 10sec
|
||||
{ print "timeout"; }
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::subscribe_to_events("bro/event/ready");
|
||||
Comm::listen(broker_port, "127.0.0.1");
|
||||
}
|
||||
|
||||
@TEST-END-FILE
|
||||
|
||||
@TEST-START-FILE master.bro
|
||||
|
||||
const broker_port: port &redef;
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
global h: opaque of Store::Handle;
|
||||
|
||||
function dv(d: Comm::Data): Comm::DataVector
|
||||
{
|
||||
local rval: Comm::DataVector;
|
||||
rval[0] = d;
|
||||
return rval;
|
||||
}
|
||||
|
||||
global ready: event();
|
||||
|
||||
event Comm::outgoing_connection_broken(peer_address: string,
|
||||
peer_port: port)
|
||||
{
|
||||
terminate();
|
||||
}
|
||||
|
||||
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"};
|
||||
h = Store::create_master("mystore");
|
||||
Store::insert(h, Comm::data("one"), Comm::data(110));
|
||||
Store::insert(h, Comm::data("two"), Comm::data(223));
|
||||
Store::insert(h, Comm::data("myset"), Comm::data(myset));
|
||||
Store::insert(h, Comm::data("myvec"), Comm::data(myvec));
|
||||
Store::increment(h, Comm::data("one"));
|
||||
Store::decrement(h, Comm::data("two"));
|
||||
Store::add_to_set(h, Comm::data("myset"), Comm::data("d"));
|
||||
Store::remove_from_set(h, Comm::data("myset"), Comm::data("b"));
|
||||
Store::push_left(h, Comm::data("myvec"), dv(Comm::data("delta")));
|
||||
Store::push_right(h, Comm::data("myvec"), dv(Comm::data("omega")));
|
||||
|
||||
when ( local res = Store::size(h) )
|
||||
{ event ready(); }
|
||||
timeout 10sec
|
||||
{ print "timeout"; }
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
Comm::connect("127.0.0.1", broker_port, 1secs);
|
||||
Comm::auto_event("bro/event/ready", ready);
|
||||
}
|
||||
|
||||
@TEST-END-FILE
|
|
@ -1,222 +0,0 @@
|
|||
# @TEST-REQUIRES: grep -q ENABLE_BROKER $BUILD/CMakeCache.txt
|
||||
|
||||
# @TEST-EXEC: bro -b %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
type bro_set: set[string];
|
||||
type bro_table: table[string] of count;
|
||||
type bro_vector: vector of string;
|
||||
|
||||
type bro_record : record {
|
||||
a: string &optional;
|
||||
b: string &default = "bee";
|
||||
c: count;
|
||||
};
|
||||
|
||||
function comm_record_to_bro_record_recurse(it: opaque of Comm::RecordIterator,
|
||||
rval: bro_record,
|
||||
idx: count): bro_record
|
||||
{
|
||||
if ( Comm::record_iterator_last(it) )
|
||||
return rval;
|
||||
|
||||
local field_value = Comm::record_iterator_value(it);
|
||||
|
||||
if ( field_value?$d )
|
||||
switch ( idx ) {
|
||||
case 0:
|
||||
rval$a = Comm::refine_to_string(field_value);
|
||||
break;
|
||||
case 1:
|
||||
rval$b = Comm::refine_to_string(field_value);
|
||||
break;
|
||||
case 2:
|
||||
rval$c = Comm::refine_to_count(field_value);
|
||||
break;
|
||||
};
|
||||
|
||||
++idx;
|
||||
Comm::record_iterator_next(it);
|
||||
return comm_record_to_bro_record_recurse(it, rval, idx);
|
||||
}
|
||||
|
||||
function comm_record_to_bro_record(d: Comm::Data): bro_record
|
||||
{
|
||||
return comm_record_to_bro_record_recurse(Comm::record_iterator(d),
|
||||
bro_record($c = 0), 0);
|
||||
}
|
||||
|
||||
function
|
||||
comm_set_to_bro_set_recurse(it: opaque of Comm::SetIterator,
|
||||
rval: bro_set): bro_set
|
||||
{
|
||||
if ( Comm::set_iterator_last(it) )
|
||||
return rval;
|
||||
|
||||
add rval[Comm::refine_to_string(Comm::set_iterator_value(it))];
|
||||
Comm::set_iterator_next(it);
|
||||
return comm_set_to_bro_set_recurse(it, rval);
|
||||
}
|
||||
|
||||
|
||||
function comm_set_to_bro_set(d: Comm::Data): bro_set
|
||||
{
|
||||
return comm_set_to_bro_set_recurse(Comm::set_iterator(d), bro_set());
|
||||
}
|
||||
|
||||
function
|
||||
comm_table_to_bro_table_recurse(it: opaque of Comm::TableIterator,
|
||||
rval: bro_table): bro_table
|
||||
{
|
||||
if ( Comm::table_iterator_last(it) )
|
||||
return rval;
|
||||
|
||||
local item = Comm::table_iterator_value(it);
|
||||
rval[Comm::refine_to_string(item$key)] = Comm::refine_to_count(item$val);
|
||||
Comm::table_iterator_next(it);
|
||||
return comm_table_to_bro_table_recurse(it, rval);
|
||||
}
|
||||
|
||||
function comm_table_to_bro_table(d: Comm::Data): bro_table
|
||||
{
|
||||
return comm_table_to_bro_table_recurse(Comm::table_iterator(d),
|
||||
bro_table());
|
||||
}
|
||||
|
||||
function comm_vector_to_bro_vector_recurse(it: opaque of Comm::VectorIterator,
|
||||
rval: bro_vector): bro_vector
|
||||
{
|
||||
if ( Comm::vector_iterator_last(it) )
|
||||
return rval;
|
||||
|
||||
rval[|rval|] = Comm::refine_to_string(Comm::vector_iterator_value(it));
|
||||
Comm::vector_iterator_next(it);
|
||||
return comm_vector_to_bro_vector_recurse(it, rval);
|
||||
}
|
||||
|
||||
function comm_vector_to_bro_vector(d: Comm::Data): bro_vector
|
||||
{
|
||||
return comm_vector_to_bro_vector_recurse(Comm::vector_iterator(d),
|
||||
bro_vector());
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
print Comm::data_type(Comm::data(T));
|
||||
print Comm::data_type(Comm::data(+1));
|
||||
print Comm::data_type(Comm::data(1));
|
||||
print Comm::data_type(Comm::data(1.1));
|
||||
print Comm::data_type(Comm::data("1 (how creative)"));
|
||||
print Comm::data_type(Comm::data(1.1.1.1));
|
||||
print Comm::data_type(Comm::data(1.1.1.1/1));
|
||||
print Comm::data_type(Comm::data(1/udp));
|
||||
print Comm::data_type(Comm::data(double_to_time(1)));
|
||||
print Comm::data_type(Comm::data(1sec));
|
||||
print Comm::data_type(Comm::data(Comm::BOOL));
|
||||
local s: bro_set = bro_set("one", "two", "three");
|
||||
local t: bro_table = bro_table(["one"] = 1, ["two"] = 2, ["three"] = 3);
|
||||
local v: bro_vector = bro_vector("zero", "one", "two");
|
||||
local r: bro_record = bro_record($c = 1);
|
||||
print Comm::data_type(Comm::data(s));
|
||||
print Comm::data_type(Comm::data(t));
|
||||
print Comm::data_type(Comm::data(v));
|
||||
print Comm::data_type(Comm::data(r));
|
||||
|
||||
print "***************************";
|
||||
|
||||
print Comm::refine_to_bool(Comm::data(T));
|
||||
print Comm::refine_to_bool(Comm::data(F));
|
||||
print Comm::refine_to_int(Comm::data(+1));
|
||||
print Comm::refine_to_int(Comm::data(+0));
|
||||
print Comm::refine_to_int(Comm::data(-1));
|
||||
print Comm::refine_to_count(Comm::data(1));
|
||||
print Comm::refine_to_count(Comm::data(0));
|
||||
print Comm::refine_to_double(Comm::data(1.1));
|
||||
print Comm::refine_to_double(Comm::data(-11.1));
|
||||
print Comm::refine_to_string(Comm::data("hello"));
|
||||
print Comm::refine_to_addr(Comm::data(1.2.3.4));
|
||||
print Comm::refine_to_subnet(Comm::data(192.168.1.1/16));
|
||||
print Comm::refine_to_port(Comm::data(22/tcp));
|
||||
print Comm::refine_to_time(Comm::data(double_to_time(42)));
|
||||
print Comm::refine_to_interval(Comm::data(3min));
|
||||
print Comm::refine_to_enum_name(Comm::data(Comm::BOOL));
|
||||
|
||||
print "***************************";
|
||||
|
||||
local cs = Comm::data(s);
|
||||
print comm_set_to_bro_set(cs);
|
||||
cs = Comm::set_create();
|
||||
print Comm::set_size(cs);
|
||||
print Comm::set_insert(cs, Comm::data("hi"));
|
||||
print Comm::set_size(cs);
|
||||
print Comm::set_contains(cs, Comm::data("hi"));
|
||||
print Comm::set_contains(cs, Comm::data("bye"));
|
||||
print Comm::set_insert(cs, Comm::data("bye"));
|
||||
print Comm::set_size(cs);
|
||||
print Comm::set_remove(cs, Comm::data("hi"));
|
||||
print Comm::set_size(cs);
|
||||
print Comm::set_remove(cs, Comm::data("hi"));
|
||||
print comm_set_to_bro_set(cs);
|
||||
Comm::set_clear(cs);
|
||||
print Comm::set_size(cs);
|
||||
|
||||
print "***************************";
|
||||
|
||||
local ct = Comm::data(t);
|
||||
print comm_table_to_bro_table(ct);
|
||||
ct = Comm::table_create();
|
||||
print Comm::table_size(ct);
|
||||
print Comm::table_insert(ct, Comm::data("hi"), Comm::data(42));
|
||||
print Comm::table_size(ct);
|
||||
print Comm::table_contains(ct, Comm::data("hi"));
|
||||
print Comm::refine_to_count(Comm::table_lookup(ct, Comm::data("hi")));
|
||||
print Comm::table_contains(ct, Comm::data("bye"));
|
||||
print Comm::table_insert(ct, Comm::data("bye"), Comm::data(7));
|
||||
print Comm::table_size(ct);
|
||||
print Comm::table_insert(ct, Comm::data("bye"), Comm::data(37));
|
||||
print Comm::table_size(ct);
|
||||
print Comm::refine_to_count(Comm::table_lookup(ct, Comm::data("bye")));
|
||||
print Comm::table_remove(ct, Comm::data("hi"));
|
||||
print Comm::table_size(ct);
|
||||
|
||||
print "***************************";
|
||||
|
||||
local cv = Comm::data(v);
|
||||
print comm_vector_to_bro_vector(cv);
|
||||
cv = Comm::vector_create();
|
||||
print Comm::vector_size(cv);
|
||||
print Comm::vector_insert(cv, Comm::data("hi"), 0);
|
||||
print Comm::vector_insert(cv, Comm::data("hello"), 1);
|
||||
print Comm::vector_insert(cv, Comm::data("greetings"), 2);
|
||||
print Comm::vector_insert(cv, Comm::data("salutations"), 1);
|
||||
print comm_vector_to_bro_vector(cv);
|
||||
print Comm::vector_size(cv);
|
||||
print Comm::vector_replace(cv, Comm::data("bah"), 2);
|
||||
print Comm::vector_lookup(cv, 2);
|
||||
print Comm::vector_lookup(cv, 0);
|
||||
print comm_vector_to_bro_vector(cv);
|
||||
print Comm::vector_remove(cv, 2);
|
||||
print comm_vector_to_bro_vector(cv);
|
||||
print Comm::vector_size(cv);
|
||||
|
||||
print "***************************";
|
||||
|
||||
local cr = Comm::data(r);
|
||||
print comm_record_to_bro_record(cr);
|
||||
r$a = "test";
|
||||
cr = Comm::data(r);
|
||||
print comm_record_to_bro_record(cr);
|
||||
r$b = "testagain";
|
||||
cr = Comm::data(r);
|
||||
print comm_record_to_bro_record(cr);
|
||||
cr = Comm::record_create(3);
|
||||
print Comm::record_size(cr);
|
||||
print Comm::record_assign(cr, Comm::data("hi"), 0);
|
||||
print Comm::record_assign(cr, Comm::data("hello"), 1);
|
||||
print Comm::record_assign(cr, Comm::data(37), 2);
|
||||
print Comm::record_lookup(cr, 0);
|
||||
print Comm::record_lookup(cr, 1);
|
||||
print Comm::record_lookup(cr, 2);
|
||||
print Comm::record_size(cr);
|
||||
}
|
|
@ -1,144 +0,0 @@
|
|||
# @TEST-REQUIRES: grep -q ENABLE_BROKER $BUILD/CMakeCache.txt
|
||||
|
||||
# @TEST-EXEC: bro -b %INPUT >out
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-sort btest-diff out
|
||||
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
global h: opaque of Store::Handle;
|
||||
global lookup_count = 0;
|
||||
const lookup_expect_count = 5;
|
||||
global exists_count = 0;
|
||||
const exists_expect_count = 4;
|
||||
global pop_count = 0;
|
||||
const pop_expect_count = 2;
|
||||
|
||||
global test_size: event(where: string &default = "");
|
||||
|
||||
event test_clear()
|
||||
{
|
||||
Store::clear(h);
|
||||
event test_size("after clear");
|
||||
}
|
||||
|
||||
event test_size(where: string)
|
||||
{
|
||||
when ( local res = Store::size(h) )
|
||||
{
|
||||
if ( where == "" )
|
||||
{
|
||||
print fmt("size: %s", res);
|
||||
event test_clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
print fmt("size (%s): %s", where, res);
|
||||
terminate();
|
||||
}
|
||||
}
|
||||
timeout 10sec
|
||||
{ print "timeout"; }
|
||||
}
|
||||
|
||||
event test_keys()
|
||||
{
|
||||
when ( local res = Store::keys(h) )
|
||||
{
|
||||
print fmt("keys: %s", res);
|
||||
event test_size();
|
||||
}
|
||||
timeout 10sec
|
||||
{ print "timeout"; }
|
||||
}
|
||||
|
||||
event test_pop(key: string)
|
||||
{
|
||||
when ( local lres = Store::pop_left(h, Comm::data(key)) )
|
||||
{
|
||||
print fmt("pop_left(%s): %s", key, lres);
|
||||
++pop_count;
|
||||
|
||||
if ( pop_count == pop_expect_count )
|
||||
event test_keys();
|
||||
}
|
||||
timeout 10sec
|
||||
{ print "timeout"; }
|
||||
|
||||
when ( local rres = Store::pop_right(h, Comm::data(key)) )
|
||||
{
|
||||
print fmt("pop_right(%s): %s", key, rres);
|
||||
++pop_count;
|
||||
|
||||
if ( pop_count == pop_expect_count )
|
||||
event test_keys();
|
||||
}
|
||||
timeout 10sec
|
||||
{ print "timeout"; }
|
||||
}
|
||||
|
||||
function do_exists(key: string)
|
||||
{
|
||||
when ( local res = Store::exists(h, Comm::data(key)) )
|
||||
{
|
||||
print fmt("exists(%s): %s", key, res);
|
||||
++exists_count;
|
||||
|
||||
if ( exists_count == exists_expect_count )
|
||||
event test_pop("myvec");
|
||||
}
|
||||
timeout 10sec
|
||||
{ print "timeout"; }
|
||||
}
|
||||
|
||||
event test_erase()
|
||||
{
|
||||
Store::erase(h, Comm::data("two"));
|
||||
do_exists("one");
|
||||
do_exists("two");
|
||||
do_exists("myset");
|
||||
do_exists("four");
|
||||
}
|
||||
|
||||
function do_lookup(key: string)
|
||||
{
|
||||
when ( local res = Store::lookup(h, Comm::data(key)) )
|
||||
{
|
||||
print fmt("lookup(%s): %s", key, res);
|
||||
++lookup_count;
|
||||
|
||||
if ( lookup_count == lookup_expect_count )
|
||||
event test_erase();
|
||||
}
|
||||
timeout 10sec
|
||||
{ print "timeout"; }
|
||||
}
|
||||
|
||||
function dv(d: Comm::Data): Comm::DataVector
|
||||
{
|
||||
local rval: Comm::DataVector;
|
||||
rval[0] = d;
|
||||
return rval;
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
Comm::enable();
|
||||
local myset: set[string] = {"a", "b", "c"};
|
||||
local myvec: vector of string = {"alpha", "beta", "gamma"};
|
||||
h = Store::create_master("master");
|
||||
Store::insert(h, Comm::data("one"), Comm::data(110));
|
||||
Store::insert(h, Comm::data("two"), Comm::data(223));
|
||||
Store::insert(h, Comm::data("myset"), Comm::data(myset));
|
||||
Store::insert(h, Comm::data("myvec"), Comm::data(myvec));
|
||||
Store::increment(h, Comm::data("one"));
|
||||
Store::decrement(h, Comm::data("two"));
|
||||
Store::add_to_set(h, Comm::data("myset"), Comm::data("d"));
|
||||
Store::remove_from_set(h, Comm::data("myset"), Comm::data("b"));
|
||||
Store::push_left(h, Comm::data("myvec"), dv(Comm::data("delta")));
|
||||
Store::push_right(h, Comm::data("myvec"), dv(Comm::data("omega")));
|
||||
do_lookup("one");
|
||||
do_lookup("two");
|
||||
do_lookup("myset");
|
||||
do_lookup("four");
|
||||
do_lookup("myvec");
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue