Expand Broker APIs to allow tracking directionality of peering establishment

This provides ways to figure out for a given peer, or a given address/port pair,
whether the local node originally established the peering.
This commit is contained in:
Christian Kreibich 2025-04-18 15:50:13 -07:00
parent 89d22f6133
commit 960d5724e5
9 changed files with 123 additions and 1 deletions

View file

@ -264,6 +264,10 @@ export {
type PeerInfo: record {
peer: EndpointInfo;
status: PeerStatus;
## Whether the local node created the peering, as opposed to a
## remote establishing it by connecting to us.
is_outbound: bool;
};
type PeerInfos: vector of PeerInfo;
@ -367,6 +371,16 @@ export {
## TODO: We do not have a function yet to terminate a connection.
global unpeer: function(a: string, p: port): bool;
## Whether the local node originally initiated the peering with the
## given endpoint.
##
## a: the address used in previous successful call to :zeek:see:`Broker::peer`.
##
## p: the port used in previous successful call to :zeek:see:`Broker::peer`.
##
## Returns:: True if this node initiated the peering.
global is_outbound_peering: function(a: string, p: port): bool;
## Get a list of all peer connections.
##
## Returns: a list of all peer connections.
@ -522,6 +536,11 @@ function unpeer(a: string, p: port): bool
return __unpeer(a, p);
}
function is_outbound_peering(a: string, p: port): bool
{
return __is_outbound_peering(a, p);
}
function peers(): vector of PeerInfo
{
return __peers();