mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
cluster/websocket: Deprecate $listen_host, introduce $listen_addr
This only changes the script-layer API, but keeps the std::string host in the C++ layer's ServerOptions. Mostly because the ixwebsocket library takes host as std::string. Also, maybe at some point we'd want to support something scheme-based like unix:///var/run/zeek.sock and placing that in a string could not be totally wrong. Add tests for IPV6, too.
This commit is contained in:
parent
8b029d0050
commit
544d571089
39 changed files with 325 additions and 35 deletions
|
@ -35,7 +35,7 @@ global pong: event(msg: string, c: count) &is_used;
|
|||
event zeek_init()
|
||||
{
|
||||
Cluster::subscribe("/zeek/event/my_topic");
|
||||
Cluster::listen_websocket([$listen_host="127.0.0.1", $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
Cluster::listen_websocket([$listen_addr=127.0.0.1, $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
}
|
||||
|
||||
event ping(msg: string, n: count) &is_used
|
||||
|
|
|
@ -35,7 +35,7 @@ global pong: event(msg: string, c: count) &is_used;
|
|||
event zeek_init()
|
||||
{
|
||||
Cluster::subscribe("/zeek/event/my_topic");
|
||||
Cluster::listen_websocket([$listen_host="127.0.0.1", $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
Cluster::listen_websocket([$listen_addr=127.0.0.1, $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
}
|
||||
|
||||
global added = 0;
|
||||
|
|
|
@ -37,7 +37,7 @@ global pong: event(msg: string, c: count) &is_used;
|
|||
event zeek_init()
|
||||
{
|
||||
Cluster::subscribe("/zeek/event/my_topic");
|
||||
Cluster::listen_websocket([$listen_host="127.0.0.1", $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
Cluster::listen_websocket([$listen_addr=127.0.0.1, $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
}
|
||||
|
||||
event ping(msg: string, n: count) &is_used
|
||||
|
|
|
@ -42,7 +42,7 @@ event zeek_init()
|
|||
Cluster::subscribe("/test/pings/");
|
||||
|
||||
Cluster::listen_websocket([
|
||||
$listen_host="127.0.0.1",
|
||||
$listen_addr=127.0.0.1,
|
||||
$listen_port=to_port(getenv("WEBSOCKET_PORT")),
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ global lost = 0;
|
|||
event zeek_init()
|
||||
{
|
||||
Cluster::listen_websocket([
|
||||
$listen_host="127.0.0.1",
|
||||
$listen_addr=127.0.0.1,
|
||||
$listen_port=to_port(getenv("WEBSOCKET_PORT")),
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ event Cluster::node_up(name: string, id: string)
|
|||
# Delay listening on WebSocket clients until worker-1 is around.
|
||||
if ( name == "worker-1" )
|
||||
Cluster::listen_websocket([
|
||||
$listen_host="127.0.0.1",
|
||||
$listen_addr=127.0.0.1,
|
||||
$listen_port=to_port(getenv("WEBSOCKET_PORT"))
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ redef Broker::disable_ssl = T;
|
|||
event zeek_init()
|
||||
{
|
||||
Cluster::subscribe("/test/pings");
|
||||
Cluster::listen_websocket([$listen_host="127.0.0.1", $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
Cluster::listen_websocket([$listen_addr=127.0.0.1, $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
}
|
||||
|
||||
global ping_count = 0;
|
||||
|
|
|
@ -36,7 +36,7 @@ global ping: event(msg: string, c: count) &is_used;
|
|||
event zeek_init()
|
||||
{
|
||||
Cluster::subscribe("/test/pings");
|
||||
Cluster::listen_websocket([$listen_host="127.0.0.1", $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
Cluster::listen_websocket([$listen_addr=127.0.0.1, $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
}
|
||||
|
||||
event ping(msg: string, n: count) &is_used
|
||||
|
|
|
@ -43,7 +43,7 @@ global pong: event(msg: string, c: count) &is_used;
|
|||
event zeek_init()
|
||||
{
|
||||
Cluster::subscribe("/test/manager");
|
||||
Cluster::listen_websocket([$listen_host="127.0.0.1", $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
Cluster::listen_websocket([$listen_addr=127.0.0.1, $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
}
|
||||
|
||||
event ping(msg: string, n: count) &is_used
|
||||
|
|
|
@ -20,20 +20,20 @@ event zeek_init()
|
|||
local ws_port = to_port(getenv("WEBSOCKET_PORT"));
|
||||
local wss_port = to_port(getenv("WEBSOCKET_SECURE_PORT"));
|
||||
|
||||
local ws_opts = Cluster::WebSocketServerOptions($listen_host="127.0.0.1", $listen_port=ws_port);
|
||||
local ws_opts = Cluster::WebSocketServerOptions($listen_addr=127.0.0.1, $listen_port=ws_port);
|
||||
local ws_opts_x = copy(ws_opts);
|
||||
ws_opts_x$tls_options = tls_options;
|
||||
|
||||
local ws_opts_wss_port = Cluster::WebSocketServerOptions($listen_host="127.0.0.1", $listen_port=wss_port);
|
||||
local ws_opts_wss_port = Cluster::WebSocketServerOptions($listen_addr=127.0.0.1, $listen_port=wss_port);
|
||||
|
||||
local ws_tls_opts = Cluster::WebSocketServerOptions(
|
||||
$listen_host="127.0.0.1",
|
||||
$listen_addr=127.0.0.1,
|
||||
$listen_port=wss_port,
|
||||
$tls_options=tls_options,
|
||||
);
|
||||
# Same as ws_tls_opts
|
||||
local ws_tls_opts_copy = Cluster::WebSocketServerOptions(
|
||||
$listen_host="127.0.0.1",
|
||||
$listen_addr=127.0.0.1,
|
||||
$listen_port=wss_port,
|
||||
$tls_options=tls_options_2,
|
||||
);
|
||||
|
|
85
testing/btest/cluster/websocket/one-ipv6-deprecated.zeek
Normal file
85
testing/btest/cluster/websocket/one-ipv6-deprecated.zeek
Normal file
|
@ -0,0 +1,85 @@
|
|||
# @TEST-DOC: Use listen_host to listen on an IPv6 address, otherwise same as one-ipv6.zeek
|
||||
#
|
||||
# @TEST-REQUIRES: have-zeromq
|
||||
# @TEST-REQUIRES: python3 -c 'import websockets.sync'
|
||||
# @TEST-REQUIRES: can-listen-tcp 6 ::1
|
||||
#
|
||||
# @TEST-GROUP: cluster-zeromq
|
||||
#
|
||||
# @TEST-PORT: XPUB_PORT
|
||||
# @TEST-PORT: XSUB_PORT
|
||||
# @TEST-PORT: LOG_PULL_PORT
|
||||
# @TEST-PORT: WEBSOCKET_PORT
|
||||
#
|
||||
# @TEST-EXEC: cp $FILES/zeromq/cluster-layout-simple.zeek cluster-layout.zeek
|
||||
# @TEST-EXEC: cp $FILES/zeromq/test-bootstrap.zeek zeromq-test-bootstrap.zeek
|
||||
# @TEST-EXEC: cp $FILES/ws/wstest.py .
|
||||
#
|
||||
# @TEST-EXEC: zeek -b --parse-only manager.zeek
|
||||
# @TEST-EXEC: python3 -m py_compile client.py
|
||||
#
|
||||
# @TEST-EXEC: btest-bg-run manager "ZEEKPATH=$ZEEKPATH:.. && CLUSTER_NODE=manager zeek -b ../manager.zeek >out"
|
||||
# @TEST-EXEC: btest-bg-run client "python3 ../client.py >out"
|
||||
#
|
||||
# @TEST-EXEC: btest-bg-wait 30
|
||||
# @TEST-EXEC: btest-diff ./manager/out
|
||||
# @TEST-EXEC: btest-diff ./manager/.stderr
|
||||
# @TEST-EXEC: btest-diff ./client/out
|
||||
# @TEST-EXEC: btest-diff ./client/.stderr
|
||||
|
||||
# @TEST-START-FILE manager.zeek
|
||||
@load ./zeromq-test-bootstrap
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
global ping_count = 0;
|
||||
|
||||
global ping: event(msg: string, c: count) &is_used;
|
||||
global pong: event(msg: string, c: count) &is_used;
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
Cluster::subscribe("/test/pings/");
|
||||
Cluster::listen_websocket([$listen_host="::1", $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
}
|
||||
|
||||
event ping(msg: string, n: count) &is_used
|
||||
{
|
||||
++ping_count;
|
||||
print fmt("got ping: %s, %s", msg, n);
|
||||
local e = Cluster::make_event(pong, "my-message", ping_count);
|
||||
Cluster::publish("/test/pings", e);
|
||||
}
|
||||
|
||||
event Cluster::websocket_client_added(info: Cluster::EndpointInfo, subscriptions: string_vec)
|
||||
{
|
||||
print "Cluster::websocket_client_added", subscriptions;
|
||||
}
|
||||
|
||||
event Cluster::websocket_client_lost(info: Cluster::EndpointInfo, code: count, reason: string)
|
||||
{
|
||||
print "Cluster::websocket_client_lost";
|
||||
terminate();
|
||||
}
|
||||
# @TEST-END-FILE
|
||||
|
||||
|
||||
# @TEST-START-FILE client.py
|
||||
# @TEST-START-FILE client.py
|
||||
import wstest
|
||||
|
||||
def run(ws_url):
|
||||
with wstest.connect("ws1", ws_url) as tc:
|
||||
print("Connected")
|
||||
tc.hello_v1(["/test/pings"])
|
||||
|
||||
for i in range(5):
|
||||
print("Sending ping", i)
|
||||
tc.send_json(wstest.build_event_v1("/test/pings/", "ping", [f"ping {i}", i]))
|
||||
pong = tc.recv_json()
|
||||
assert pong["@data-type"] == "vector"
|
||||
ev = pong["data"][2]["data"]
|
||||
print("topic", pong["topic"], "event name", ev[0]["data"], "args", ev[1]["data"])
|
||||
|
||||
if __name__ == "__main__":
|
||||
wstest.main(run, wstest.WS6_URL_V1)
|
||||
# @TEST-END-FILE
|
85
testing/btest/cluster/websocket/one-ipv6.zeek
Normal file
85
testing/btest/cluster/websocket/one-ipv6.zeek
Normal file
|
@ -0,0 +1,85 @@
|
|||
# @TEST-DOC: Make a WebSocket server listen on IPv6 ::1.
|
||||
#
|
||||
# @TEST-REQUIRES: have-zeromq
|
||||
# @TEST-REQUIRES: python3 -c 'import websockets.sync'
|
||||
# @TEST-REQUIRES: can-listen-tcp 6 ::1
|
||||
#
|
||||
# @TEST-GROUP: cluster-zeromq
|
||||
#
|
||||
# @TEST-PORT: XPUB_PORT
|
||||
# @TEST-PORT: XSUB_PORT
|
||||
# @TEST-PORT: LOG_PULL_PORT
|
||||
# @TEST-PORT: WEBSOCKET_PORT
|
||||
#
|
||||
# @TEST-EXEC: cp $FILES/zeromq/cluster-layout-simple.zeek cluster-layout.zeek
|
||||
# @TEST-EXEC: cp $FILES/zeromq/test-bootstrap.zeek zeromq-test-bootstrap.zeek
|
||||
# @TEST-EXEC: cp $FILES/ws/wstest.py .
|
||||
#
|
||||
# @TEST-EXEC: zeek -b --parse-only manager.zeek
|
||||
# @TEST-EXEC: python3 -m py_compile client.py
|
||||
#
|
||||
# @TEST-EXEC: btest-bg-run manager "ZEEKPATH=$ZEEKPATH:.. && CLUSTER_NODE=manager zeek -b ../manager.zeek >out"
|
||||
# @TEST-EXEC: btest-bg-run client "python3 ../client.py >out"
|
||||
#
|
||||
# @TEST-EXEC: btest-bg-wait 30
|
||||
# @TEST-EXEC: btest-diff ./manager/out
|
||||
# @TEST-EXEC: btest-diff ./manager/.stderr
|
||||
# @TEST-EXEC: btest-diff ./client/out
|
||||
# @TEST-EXEC: btest-diff ./client/.stderr
|
||||
|
||||
# @TEST-START-FILE manager.zeek
|
||||
@load ./zeromq-test-bootstrap
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
global ping_count = 0;
|
||||
|
||||
global ping: event(msg: string, c: count) &is_used;
|
||||
global pong: event(msg: string, c: count) &is_used;
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
Cluster::subscribe("/test/pings/");
|
||||
Cluster::listen_websocket([$listen_addr=[::1], $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
}
|
||||
|
||||
event ping(msg: string, n: count) &is_used
|
||||
{
|
||||
++ping_count;
|
||||
print fmt("got ping: %s, %s", msg, n);
|
||||
local e = Cluster::make_event(pong, "my-message", ping_count);
|
||||
Cluster::publish("/test/pings", e);
|
||||
}
|
||||
|
||||
event Cluster::websocket_client_added(info: Cluster::EndpointInfo, subscriptions: string_vec)
|
||||
{
|
||||
print "Cluster::websocket_client_added", subscriptions;
|
||||
}
|
||||
|
||||
event Cluster::websocket_client_lost(info: Cluster::EndpointInfo, code: count, reason: string)
|
||||
{
|
||||
print "Cluster::websocket_client_lost";
|
||||
terminate();
|
||||
}
|
||||
# @TEST-END-FILE
|
||||
|
||||
|
||||
# @TEST-START-FILE client.py
|
||||
# @TEST-START-FILE client.py
|
||||
import wstest
|
||||
|
||||
def run(ws_url):
|
||||
with wstest.connect("ws1", ws_url) as tc:
|
||||
print("Connected")
|
||||
tc.hello_v1(["/test/pings"])
|
||||
|
||||
for i in range(5):
|
||||
print("Sending ping", i)
|
||||
tc.send_json(wstest.build_event_v1("/test/pings/", "ping", [f"ping {i}", i]))
|
||||
pong = tc.recv_json()
|
||||
assert pong["@data-type"] == "vector"
|
||||
ev = pong["data"][2]["data"]
|
||||
print("topic", pong["topic"], "event name", ev[0]["data"], "args", ev[1]["data"])
|
||||
|
||||
if __name__ == "__main__":
|
||||
wstest.main(run, wstest.WS6_URL_V1)
|
||||
# @TEST-END-FILE
|
|
@ -37,7 +37,7 @@ global pong: event(msg: string, c: count) &is_used;
|
|||
event zeek_init()
|
||||
{
|
||||
Cluster::subscribe("/zeek/event/my_topic");
|
||||
Cluster::listen_websocket([$listen_host="127.0.0.1", $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
Cluster::listen_websocket([$listen_addr=127.0.0.1, $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
}
|
||||
|
||||
event ping(msg: string, n: count) &is_used
|
||||
|
|
|
@ -37,7 +37,7 @@ global pong: event(msg: string, c: count) &is_used;
|
|||
event zeek_init()
|
||||
{
|
||||
Cluster::subscribe("/zeek/event/my_topic");
|
||||
Cluster::listen_websocket([$listen_host="127.0.0.1", $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
Cluster::listen_websocket([$listen_addr=127.0.0.1, $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
}
|
||||
|
||||
event ping(msg: string, n: count) &is_used
|
||||
|
|
|
@ -39,7 +39,7 @@ event Cluster::websocket_client_lost(info: Cluster::EndpointInfo, code: count, r
|
|||
|
||||
event zeek_init()
|
||||
{
|
||||
Cluster::listen_websocket([$listen_host="127.0.0.1", $listen_port=to_port(getenv("WEBSOCKET_PORT")), $ping_interval=1sec]);
|
||||
Cluster::listen_websocket([$listen_addr=127.0.0.1, $listen_port=to_port(getenv("WEBSOCKET_PORT")), $ping_interval=1sec]);
|
||||
Cluster::subscribe("/test/pings/");
|
||||
}
|
||||
# @TEST-END-FILE
|
||||
|
|
|
@ -53,7 +53,7 @@ event Cluster::websocket_client_lost(info: Cluster::EndpointInfo, code: count, r
|
|||
|
||||
event zeek_init()
|
||||
{
|
||||
Cluster::listen_websocket([$listen_host="127.0.0.1", $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
Cluster::listen_websocket([$listen_addr=127.0.0.1, $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
Cluster::subscribe("/test/pings/");
|
||||
}
|
||||
# @TEST-END-FILE
|
||||
|
|
|
@ -71,7 +71,7 @@ event Cluster::Backend::ZeroMQ::subscription(topic: string)
|
|||
|
||||
event zeek_init()
|
||||
{
|
||||
Cluster::listen_websocket([$listen_host="127.0.0.1", $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
Cluster::listen_websocket([$listen_addr=127.0.0.1, $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
Cluster::subscribe("/test/manager");
|
||||
}
|
||||
# @TEST-END-FILE
|
||||
|
|
|
@ -14,6 +14,6 @@ event zeek_init()
|
|||
$key_file="../localhost.key",
|
||||
);
|
||||
|
||||
assert ! Cluster::listen_websocket([$listen_host="127.0.0.1", $listen_port=1234/tcp, $tls_options=tls_options_no_key]);
|
||||
assert ! Cluster::listen_websocket([$listen_host="127.0.0.1", $listen_port=1234/tcp, $tls_options=tls_options_no_cert]);
|
||||
assert ! Cluster::listen_websocket([$listen_addr=127.0.0.1, $listen_port=1234/tcp, $tls_options=tls_options_no_key]);
|
||||
assert ! Cluster::listen_websocket([$listen_addr=127.0.0.1, $listen_port=1234/tcp, $tls_options=tls_options_no_cert]);
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ event zeek_init()
|
|||
);
|
||||
|
||||
local ws_server_options = Cluster::WebSocketServerOptions(
|
||||
$listen_host="127.0.0.1",
|
||||
$listen_addr=127.0.0.1,
|
||||
$listen_port=to_port(getenv("WEBSOCKET_PORT")),
|
||||
$tls_options=tls_options,
|
||||
);
|
||||
|
|
|
@ -103,7 +103,7 @@ event Cluster::Backend::ZeroMQ::subscription(topic: string)
|
|||
|
||||
event zeek_init()
|
||||
{
|
||||
Cluster::listen_websocket([$listen_host="127.0.0.1", $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
Cluster::listen_websocket([$listen_addr=127.0.0.1, $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
Cluster::subscribe("/test/manager");
|
||||
}
|
||||
# @TEST-END-FILE
|
||||
|
|
|
@ -79,7 +79,7 @@ event Cluster::node_up(name: string, id: string)
|
|||
# Delay listening on WebSocket clients until worker-1 is around.
|
||||
if ( name == "worker-1" )
|
||||
Cluster::listen_websocket([
|
||||
$listen_host="127.0.0.1",
|
||||
$listen_addr=127.0.0.1,
|
||||
$listen_port=to_port(getenv("WEBSOCKET_PORT"))
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ redef exit_only_after_terminate = T;
|
|||
event zeek_init()
|
||||
{
|
||||
Cluster::subscribe("/test/pings");
|
||||
Cluster::listen_websocket([$listen_host="127.0.0.1", $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
Cluster::listen_websocket([$listen_addr=127.0.0.1, $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
}
|
||||
|
||||
global ping_count = 0;
|
||||
|
|
|
@ -38,7 +38,7 @@ global ping: event(msg: string, c: count) &is_used;
|
|||
event zeek_init()
|
||||
{
|
||||
Cluster::subscribe("/test/pings");
|
||||
Cluster::listen_websocket([$listen_host="127.0.0.1", $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
Cluster::listen_websocket([$listen_addr=127.0.0.1, $listen_port=to_port(getenv("WEBSOCKET_PORT"))]);
|
||||
}
|
||||
|
||||
event ping(msg: string, n: count) &is_used
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue