0
0
mirror of https://github.com/zeromq/libzmq.git synced 2025-01-15 10:18:01 +08:00

resolve #1347 Backport zmq_msg_gets "Peer-Address"

This commit is contained in:
Thomas Rodgers 2015-02-14 10:44:52 -06:00
parent 712e74eebd
commit 5229eeef5b
4 changed files with 24 additions and 11 deletions

1
.gitignore vendored
View File

@ -133,6 +133,7 @@ zeromq-*.tar.gz
zeromq-*.zip zeromq-*.zip
core core
build build
test-suite.log
curve_keygen curve_keygen
inproc_lat inproc_lat
inproc_thr inproc_thr

View File

@ -19,8 +19,22 @@ property specified by the 'property' argument for the message pointed to by
the 'message' argument. Both the 'property' argument and the 'value' the 'message' argument. Both the 'property' argument and the 'value'
shall be NULL-terminated UTF8-encoded strings. shall be NULL-terminated UTF8-encoded strings.
The following properties can be retrieved with the _zmq_msg_gets()_ function: Metadata is defined on a per-connection basis during the ZeroMQ connection
handshake as specified in <rfc.zeromq.org/spec:37>.
The following ZMTP properties can be retrieved with the _zmq_msg_gets()_
function:
Socket-Type
Identity
Resource
Additionally, when available for the underlying transport, the *Peer-Address*
property will return the IP address of the remote endpoint as returned by
getnameinfo(2).
Other properties may be defined based on the underlying security mechanism,
see ZAP authenticated connection sample below.
RETURN VALUE RETURN VALUE
------------ ------------

View File

@ -794,21 +794,18 @@ void zmq::stream_engine_t::mechanism_ready ()
properties_t properties; properties_t properties;
properties_t::const_iterator it; properties_t::const_iterator it;
// If we have a peer_address, add it to metadata
if (!peer_address.empty()) {
properties.insert(std::make_pair("Peer-Address", peer_address));
}
// Add ZAP properties. // Add ZAP properties.
const properties_t& zap_properties = mechanism->get_zap_properties (); const properties_t& zap_properties = mechanism->get_zap_properties ();
it = zap_properties.begin (); properties.insert(zap_properties.begin (), zap_properties.end ());
while (it != zap_properties.end ()) {
properties.insert (properties_t::value_type (it->first, it->second));
++it;
}
// Add ZMTP properties. // Add ZMTP properties.
const properties_t& zmtp_properties = mechanism->get_zmtp_properties (); const properties_t& zmtp_properties = mechanism->get_zmtp_properties ();
it = zmtp_properties.begin (); properties.insert(zmtp_properties.begin (), zmtp_properties.end ());
while (it != zmtp_properties.end ()) {
properties.insert (properties_t::value_type (it->first, it->second));
++it;
}
zmq_assert (metadata == NULL); zmq_assert (metadata == NULL);
if (!properties.empty ()) if (!properties.empty ())

View File

@ -100,6 +100,7 @@ int main (void)
assert (streq (zmq_msg_gets (&msg, "Hello"), "World")); assert (streq (zmq_msg_gets (&msg, "Hello"), "World"));
assert (streq (zmq_msg_gets (&msg, "Socket-Type"), "DEALER")); assert (streq (zmq_msg_gets (&msg, "Socket-Type"), "DEALER"));
assert (streq (zmq_msg_gets (&msg, "User-Id"), "anonymous")); assert (streq (zmq_msg_gets (&msg, "User-Id"), "anonymous"));
assert (streq (zmq_msg_gets (&msg, "Peer-Address"), "127.0.0.1"));
assert (zmq_msg_gets (&msg, "No Such") == NULL); assert (zmq_msg_gets (&msg, "No Such") == NULL);
assert (zmq_errno () == EINVAL); assert (zmq_errno () == EINVAL);
zmq_msg_close (&msg); zmq_msg_close (&msg);