mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-09 15:26:04 +00:00
Merge pull request #2282 from bluca/event_test
Problems: test_monitor failing, DRAFT events leaking when draft APIs are disabled
This commit is contained in:
commit
086bb890c5
7
NEWS
7
NEWS
@ -1,8 +1,15 @@
|
||||
0MQ version 4.2.1 stable, released on 201x/xx/xx
|
||||
=============================================
|
||||
|
||||
* New DRAFT (see NEWS for 4.2.0) Socket Monitor events:
|
||||
- ZMQ_EVENT_HANDSHAKE_SUCCEED
|
||||
- ZMQ_EVENT_HANDSHAKE_FAILED
|
||||
These events trigger when the ZMTP security mechanism handshake is
|
||||
completed. See doc/zmq_socket_monitor.txt for more information.
|
||||
|
||||
* New DRAFT (see NEWS for 4.2.0) Context options:
|
||||
- ZMQ_MSG_T_SIZE
|
||||
See doc/zmq_ctx_get.txt for more information.
|
||||
|
||||
* Fixed #2268 - improved compatibility with mingw32
|
||||
|
||||
|
@ -23,7 +23,10 @@ your own 'ZMQ_PAIR' socket, and connect that to the endpoint.
|
||||
|
||||
The 'events' argument is a bitmask of the socket events you wish to
|
||||
monitor, see 'Supported events' below. To monitor all events, use the
|
||||
event value ZMQ_EVENT_ALL.
|
||||
event value ZMQ_EVENT_ALL. NOTE: as new events are added, the catch-all
|
||||
value will start returning them. An application that relies on a strict
|
||||
and fixed sequence of events must not use ZMQ_EVENT_ALL in order to
|
||||
guarantee compatibility with future versions.
|
||||
|
||||
Each event is sent as two frames. The first frame contains an event
|
||||
number (16 bits), and an event value (32 bits) that provides additional
|
||||
@ -96,6 +99,18 @@ ZMQ_EVENT_MONITOR_STOPPED
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Monitoring on this socket ended.
|
||||
|
||||
ZMQ_EVENT_HANDSHAKE_FAILED
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
The ZMTP security mechanism handshake failed.
|
||||
The event value is unspecified.
|
||||
NOTE: in DRAFT state, not yet available in stable releases.
|
||||
|
||||
ZMQ_EVENT_HANDSHAKE_SUCCEED
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
The ZMTP security mechanism handshake succeeded.
|
||||
The event value is unspecified.
|
||||
NOTE: in DRAFT state, not yet available in stable releases.
|
||||
|
||||
|
||||
RETURN VALUE
|
||||
------------
|
||||
|
@ -790,8 +790,10 @@ int zmq::stream_engine_t::next_handshake_command (msg_t *msg_)
|
||||
|
||||
if (rc == 0)
|
||||
msg_->set_flags (msg_t::command);
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
if(mechanism->status() == mechanism_t::error)
|
||||
socket->event_handshake_failed(endpoint, 0);
|
||||
#endif
|
||||
|
||||
return rc;
|
||||
}
|
||||
@ -871,7 +873,9 @@ void zmq::stream_engine_t::mechanism_ready ()
|
||||
if (!properties.empty ())
|
||||
metadata = new (std::nothrow) metadata_t (properties);
|
||||
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
socket->event_handshake_succeed(endpoint, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
int zmq::stream_engine_t::pull_msg_from_session (msg_t *msg_)
|
||||
@ -976,8 +980,10 @@ void zmq::stream_engine_t::error (error_reason_t reason)
|
||||
terminator.close();
|
||||
}
|
||||
zmq_assert (session);
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
if(reason == encryption_error)
|
||||
socket->event_handshake_failed(endpoint, (int) s);
|
||||
#endif
|
||||
socket->event_disconnected (endpoint, (int) s);
|
||||
session->flush ();
|
||||
session->engine_error (reason);
|
||||
|
@ -116,6 +116,10 @@ int main (void)
|
||||
if (event == ZMQ_EVENT_CONNECT_DELAYED)
|
||||
event = get_monitor_event (client_mon, NULL, NULL);
|
||||
assert (event == ZMQ_EVENT_CONNECTED);
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
event = get_monitor_event (client_mon, NULL, NULL);
|
||||
assert (event == ZMQ_EVENT_HANDSHAKE_SUCCEED);
|
||||
#endif
|
||||
event = get_monitor_event (client_mon, NULL, NULL);
|
||||
assert (event == ZMQ_EVENT_MONITOR_STOPPED);
|
||||
|
||||
@ -124,6 +128,10 @@ int main (void)
|
||||
assert (event == ZMQ_EVENT_LISTENING);
|
||||
event = get_monitor_event (server_mon, NULL, NULL);
|
||||
assert (event == ZMQ_EVENT_ACCEPTED);
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
event = get_monitor_event (server_mon, NULL, NULL);
|
||||
assert (event == ZMQ_EVENT_HANDSHAKE_SUCCEED);
|
||||
#endif
|
||||
event = get_monitor_event (server_mon, NULL, NULL);
|
||||
// Sometimes the server sees the client closing before it gets closed.
|
||||
if (event != ZMQ_EVENT_DISCONNECTED) {
|
||||
|
@ -46,6 +46,44 @@ static char client_secret [41];
|
||||
static char server_public [41];
|
||||
static char server_secret [41];
|
||||
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
// Read one event off the monitor socket; return value and address
|
||||
// by reference, if not null, and event number by value. Returns -1
|
||||
// in case of error.
|
||||
|
||||
static int
|
||||
get_monitor_event (void *monitor, int *value, char **address)
|
||||
{
|
||||
// First frame in message contains event number and value
|
||||
zmq_msg_t msg;
|
||||
zmq_msg_init (&msg);
|
||||
if (zmq_msg_recv (&msg, monitor, 0) == -1)
|
||||
return -1; // Interruped, presumably
|
||||
assert (zmq_msg_more (&msg));
|
||||
|
||||
uint8_t *data = (uint8_t *) zmq_msg_data (&msg);
|
||||
uint16_t event = *(uint16_t *) (data);
|
||||
if (value)
|
||||
*value = *(uint32_t *) (data + 2);
|
||||
|
||||
// Second frame in message contains event address
|
||||
zmq_msg_init (&msg);
|
||||
if (zmq_msg_recv (&msg, monitor, 0) == -1)
|
||||
return -1; // Interruped, presumably
|
||||
assert (!zmq_msg_more (&msg));
|
||||
|
||||
if (address) {
|
||||
uint8_t *data = (uint8_t *) zmq_msg_data (&msg);
|
||||
size_t size = zmq_msg_size (&msg);
|
||||
*address = (char *) malloc (size + 1);
|
||||
memcpy (*address, data, size);
|
||||
*address [size] = 0;
|
||||
}
|
||||
return event;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// This methods receives and validates ZAP requestes (allowing or denying
|
||||
// each client connection).
|
||||
@ -138,6 +176,21 @@ int main (void)
|
||||
rc = zmq_bind (server, "tcp://127.0.0.1:9998");
|
||||
assert (rc == 0);
|
||||
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
// Monitor handshake events on the server
|
||||
rc = zmq_socket_monitor (server, "inproc://monitor-server",
|
||||
ZMQ_EVENT_HANDSHAKE_SUCCEED | ZMQ_EVENT_HANDSHAKE_FAILED);
|
||||
assert (rc == 0);
|
||||
|
||||
// Create socket for collecting monitor events
|
||||
void *server_mon = zmq_socket (ctx, ZMQ_PAIR);
|
||||
assert (server_mon);
|
||||
|
||||
// Connect it to the inproc endpoints so they'll get events
|
||||
rc = zmq_connect (server_mon, "inproc://monitor-server");
|
||||
assert (rc == 0);
|
||||
#endif
|
||||
|
||||
// Check CURVE security with valid credentials
|
||||
void *client = zmq_socket (ctx, ZMQ_DEALER);
|
||||
assert (client);
|
||||
@ -153,6 +206,11 @@ int main (void)
|
||||
rc = zmq_close (client);
|
||||
assert (rc == 0);
|
||||
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
int event = get_monitor_event (server_mon, NULL, NULL);
|
||||
assert (event == ZMQ_EVENT_HANDSHAKE_SUCCEED);
|
||||
#endif
|
||||
|
||||
// Check CURVE security with a garbage server key
|
||||
// This will be caught by the curve_server class, not passed to ZAP
|
||||
char garbage_key [] = "0000000000000000000000000000000000000000";
|
||||
@ -169,6 +227,11 @@ int main (void)
|
||||
expect_bounce_fail (server, client);
|
||||
close_zero_linger (client);
|
||||
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
event = get_monitor_event (server_mon, NULL, NULL);
|
||||
assert (event == ZMQ_EVENT_HANDSHAKE_FAILED);
|
||||
#endif
|
||||
|
||||
// Check CURVE security with a garbage client public key
|
||||
// This will be caught by the curve_server class, not passed to ZAP
|
||||
client = zmq_socket (ctx, ZMQ_DEALER);
|
||||
@ -184,6 +247,11 @@ int main (void)
|
||||
expect_bounce_fail (server, client);
|
||||
close_zero_linger (client);
|
||||
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
event = get_monitor_event (server_mon, NULL, NULL);
|
||||
assert (event == ZMQ_EVENT_HANDSHAKE_FAILED);
|
||||
#endif
|
||||
|
||||
// Check CURVE security with a garbage client secret key
|
||||
// This will be caught by the curve_server class, not passed to ZAP
|
||||
client = zmq_socket (ctx, ZMQ_DEALER);
|
||||
@ -199,6 +267,11 @@ int main (void)
|
||||
expect_bounce_fail (server, client);
|
||||
close_zero_linger (client);
|
||||
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
event = get_monitor_event (server_mon, NULL, NULL);
|
||||
assert (event == ZMQ_EVENT_HANDSHAKE_FAILED);
|
||||
#endif
|
||||
|
||||
// Check CURVE security with bogus client credentials
|
||||
// This must be caught by the ZAP handler
|
||||
char bogus_public [41];
|
||||
@ -218,6 +291,11 @@ int main (void)
|
||||
expect_bounce_fail (server, client);
|
||||
close_zero_linger (client);
|
||||
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
event = get_monitor_event (server_mon, NULL, NULL);
|
||||
assert (event == ZMQ_EVENT_HANDSHAKE_FAILED);
|
||||
#endif
|
||||
|
||||
// Check CURVE security with NULL client credentials
|
||||
// This must be caught by the curve_server class, not passed to ZAP
|
||||
client = zmq_socket (ctx, ZMQ_DEALER);
|
||||
@ -227,6 +305,11 @@ int main (void)
|
||||
expect_bounce_fail (server, client);
|
||||
close_zero_linger (client);
|
||||
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
event = get_monitor_event (server_mon, NULL, NULL);
|
||||
assert (event == ZMQ_EVENT_HANDSHAKE_FAILED);
|
||||
#endif
|
||||
|
||||
// Check CURVE security with PLAIN client credentials
|
||||
// This must be caught by the curve_server class, not passed to ZAP
|
||||
client = zmq_socket (ctx, ZMQ_DEALER);
|
||||
@ -282,6 +365,9 @@ int main (void)
|
||||
assert (rc == 0);
|
||||
|
||||
// Shutdown
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
close_zero_linger (server_mon);
|
||||
#endif
|
||||
rc = zmq_close (server);
|
||||
assert (rc == 0);
|
||||
rc = zmq_ctx_term (ctx);
|
||||
|
Loading…
x
Reference in New Issue
Block a user