mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 04:28:20 +00:00
cluster/websocket: Automatic WebSocket client topic subscription
Subscribe every WebSocket client to a unique topic, by default under zeek/cluster/websocket/client/<identifier>/ Add tests that verify that WebSocket clients receive messages on these topics even if they didn't explicitly pass them in their handshake message. This is somewhere between feature and bug fix. It aids the ZeroMQ backend implementation: A WebSocket client that doesn't provide any subscriptions and immediately starts publishing would discard events until receiving other nodes subscriptions from the central XPUB/XSUB proxy. ZeroMQ does sender side topic filtering. When using subscriptions, the client waits until its own subscriptions are returned from the central XPUB/XSUB proxy, thereby also learning about other node's subscriptions. Also, make the no-subscriptions.zeek test use 32 clients sequentially to trigger potential issues more quickly.
This commit is contained in:
parent
69a1ad2c3d
commit
8edec9885a
17 changed files with 352 additions and 19 deletions
|
@ -59,6 +59,18 @@ export {
|
|||
## a unique node in a cluster. Used with broker-enabled cluster communication.
|
||||
const nodeid_topic_prefix = "zeek/cluster/nodeid/" &redef;
|
||||
|
||||
## Parts used for automatic WebSocket client topic subscription.
|
||||
##
|
||||
## Every WebSocket client is automatically subscribed to a topic
|
||||
## produced by joining and suffixing this vector and the WebSocket
|
||||
## client's identifier with :zeek:see:`Cluster::websocket_topic_sep`.
|
||||
const websocket_topic_prefix_parts = vector("zeek", "cluster", "websocket", "client") &redef;
|
||||
|
||||
## Separator used for creating automatic WebSocket client topic subscriptions.
|
||||
##
|
||||
## See also :zeek:see:`Cluster::websocket_topic_prefix_parts`.
|
||||
const websocket_topic_sep = "/" &redef;
|
||||
|
||||
## Name of the node on which master data stores will be created if no other
|
||||
## has already been specified by the user in :zeek:see:`Cluster::stores`.
|
||||
## An empty value means "use whatever name corresponds to the manager
|
||||
|
@ -298,6 +310,14 @@ export {
|
|||
## a given cluster node.
|
||||
global nodeid_topic: function(id: string): string &redef;
|
||||
|
||||
## Retrieve the topic associated with a WebSocket client in the cluster.
|
||||
##
|
||||
## id: the id for the WebSocket client (:zeek:see:`Cluster::websocket_client_added`)
|
||||
##
|
||||
## Returns: a topic string that may used to send a message exclusively to
|
||||
## a given WebSocket client.
|
||||
global websocket_client_topic: function(id: string): string;
|
||||
|
||||
## Retrieve the cluster-level naming of a node based on its node ID,
|
||||
## a backend-specific identifier.
|
||||
##
|
||||
|
@ -473,6 +493,14 @@ function nodeid_topic(id: string): string
|
|||
return nodeid_topic_prefix + id + "/";
|
||||
}
|
||||
|
||||
function websocket_client_topic(id: string): string
|
||||
{
|
||||
local v = copy(websocket_topic_prefix_parts);
|
||||
v += id;
|
||||
v += "";
|
||||
return join_string_vec(v, websocket_topic_sep);
|
||||
}
|
||||
|
||||
function nodeid_to_node(id: string): NamedNode
|
||||
{
|
||||
for ( name, n in nodes )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue