mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
broker integration: add knobs to set auto publish/advertise behavior
This commit is contained in:
parent
cfb666af2b
commit
ebc9407a2b
4 changed files with 48 additions and 5 deletions
|
@ -5,6 +5,11 @@ export {
|
||||||
|
|
||||||
const endpoint_name = "" &redef;
|
const endpoint_name = "" &redef;
|
||||||
|
|
||||||
|
type EndpointFlags: record {
|
||||||
|
auto_publish: bool &default = T;
|
||||||
|
auto_advertise: bool &default = T;
|
||||||
|
};
|
||||||
|
|
||||||
type SendFlags: record {
|
type SendFlags: record {
|
||||||
self: bool &default = F;
|
self: bool &default = F;
|
||||||
peers: bool &default = T;
|
peers: bool &default = T;
|
||||||
|
|
|
@ -41,7 +41,25 @@ static int require_field(RecordType* rt, const char* name)
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool comm::Manager::Enable()
|
static int GetEndpointFlags(Val* broker_endpoint_flags)
|
||||||
|
{
|
||||||
|
int rval = 0;
|
||||||
|
auto r = broker_endpoint_flags->AsRecordVal();
|
||||||
|
Val* auto_publish_flag = r->Lookup("auto_publish", true);
|
||||||
|
Val* auto_advertise_flag = r->Lookup("auto_advertise", true);
|
||||||
|
|
||||||
|
if ( auto_publish_flag->AsBool() )
|
||||||
|
rval |= broker::AUTO_PUBLISH;
|
||||||
|
|
||||||
|
if ( auto_advertise_flag->AsBool() )
|
||||||
|
rval |= broker::AUTO_ADVERTISE;
|
||||||
|
|
||||||
|
Unref(auto_publish_flag);
|
||||||
|
Unref(auto_advertise_flag);
|
||||||
|
return rval;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool comm::Manager::Enable(Val* broker_endpoint_flags)
|
||||||
{
|
{
|
||||||
if ( endpoint != nullptr )
|
if ( endpoint != nullptr )
|
||||||
return true;
|
return true;
|
||||||
|
@ -93,11 +111,22 @@ bool comm::Manager::Enable()
|
||||||
name = fmt("bro@<unknown>.%ld", static_cast<long>(getpid()));
|
name = fmt("bro@<unknown>.%ld", static_cast<long>(getpid()));
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint = unique_ptr<broker::endpoint>(new broker::endpoint(name));
|
int flags = GetEndpointFlags(broker_endpoint_flags);
|
||||||
|
endpoint = unique_ptr<broker::endpoint>(new broker::endpoint(name, flags));
|
||||||
iosource_mgr->Register(this, true);
|
iosource_mgr->Register(this, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool comm::Manager::SetEndpointFlags(Val* broker_endpoint_flags)
|
||||||
|
{
|
||||||
|
if ( ! Enabled() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int flags = GetEndpointFlags(broker_endpoint_flags);
|
||||||
|
endpoint->set_flags(flags);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool comm::Manager::Listen(uint16_t port, const char* addr, bool reuse_addr)
|
bool comm::Manager::Listen(uint16_t port, const char* addr, bool reuse_addr)
|
||||||
{
|
{
|
||||||
if ( ! Enabled() )
|
if ( ! Enabled() )
|
||||||
|
|
|
@ -24,7 +24,9 @@ public:
|
||||||
|
|
||||||
~Manager();
|
~Manager();
|
||||||
|
|
||||||
bool Enable();
|
bool Enable(Val* flags);
|
||||||
|
|
||||||
|
bool SetEndpointFlags(Val* flags);
|
||||||
|
|
||||||
bool Enabled()
|
bool Enabled()
|
||||||
{ return endpoint != nullptr; }
|
{ return endpoint != nullptr; }
|
||||||
|
|
|
@ -7,9 +7,16 @@
|
||||||
|
|
||||||
module Comm;
|
module Comm;
|
||||||
|
|
||||||
function Comm::enable%(%): bool
|
type Comm::EndpointFlags: record;
|
||||||
|
|
||||||
|
function Comm::enable%(flags: EndpointFlags &default = EndpointFlags()%): bool
|
||||||
%{
|
%{
|
||||||
return new Val(comm_mgr->Enable(), TYPE_BOOL);
|
return new Val(comm_mgr->Enable(flags), TYPE_BOOL);
|
||||||
|
%}
|
||||||
|
|
||||||
|
function Comm::set_endpoint_flags%(flags: EndpointFlags &default = EndpointFlags()%): bool
|
||||||
|
%{
|
||||||
|
return new Val(comm_mgr->SetEndpointFlags(flags), TYPE_BOOL);
|
||||||
%}
|
%}
|
||||||
|
|
||||||
event Comm::outgoing_connection_established%(peer_address: string,
|
event Comm::outgoing_connection_established%(peer_address: string,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue