0
0
mirror of https://github.com/zeromq/libzmq.git synced 2024-12-28 16:15:23 +08:00

Merge pull request #1309 from rodgert/master

Add 'Peer-Address' property to connection metadata
This commit is contained in:
KAPP Arnaud 2015-01-16 22:43:04 +01:00
commit 0e404ec844
4 changed files with 16 additions and 12 deletions

1
.gitignore vendored
View File

@ -137,3 +137,4 @@ zeromq-*.tar.gz
zeromq-*.zip
core
build
test-suite.log

View File

@ -29,6 +29,10 @@ function:
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, see ZAP
auththenticated connection sample below.

View File

@ -671,7 +671,7 @@ bool zmq::stream_engine_t::handshake ()
options.mechanism == ZMQ_GSSAPI? "GSSAPI":
"OTHER",
mechanism);
error (protocol_error);
return false;
}
@ -806,21 +806,18 @@ void zmq::stream_engine_t::mechanism_ready ()
properties_t properties;
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.
const properties_t& zap_properties = mechanism->get_zap_properties ();
it = zap_properties.begin ();
while (it != zap_properties.end ()) {
properties.insert (properties_t::value_type (it->first, it->second));
++it;
}
properties.insert(zap_properties.begin (), zap_properties.end ());
// Add ZMTP properties.
const properties_t& zmtp_properties = mechanism->get_zmtp_properties ();
it = zmtp_properties.begin ();
while (it != zmtp_properties.end ()) {
properties.insert (properties_t::value_type (it->first, it->second));
++it;
}
properties.insert(zmtp_properties.begin (), zmtp_properties.end ());
zmq_assert (metadata == NULL);
if (!properties.empty ())

View File

@ -41,7 +41,7 @@ zap_handler (void *handler)
assert (streq (version, "1.0"));
assert (streq (mechanism, "NULL"));
s_sendmore (handler, version);
s_sendmore (handler, sequence);
if (streq (domain, "DOMAIN")) {
@ -100,6 +100,8 @@ int main (void)
assert (streq (zmq_msg_gets (&msg, "Hello"), "World"));
assert (streq (zmq_msg_gets (&msg, "Socket-Type"), "DEALER"));
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_errno () == EINVAL);
zmq_msg_close (&msg);