Skip to content

Commit

Permalink
Merge pull request #298 from sphaero/feature_peer_name
Browse files Browse the repository at this point in the history
added zyre_get_peer_name method, fixes #297
  • Loading branch information
hintjens committed Dec 29, 2014
2 parents 86f3655 + 86e76ed commit 2092be7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/zyre.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ ZYRE_EXPORT zlist_t *
ZYRE_EXPORT char *
zyre_peer_address(zyre_t *self, const char *peer);

// Return the name of a connected peer. Caller owns the
// string.
ZYRE_EXPORT char *
zyre_get_peer_name(zyre_t *self, const char *peer);

// Return the value of a header of a conected peer.
// Returns null if peer or key doesn't exits. Caller
// owns the string
Expand Down
18 changes: 18 additions & 0 deletions src/zyre.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,21 @@ zyre_peer_address(zyre_t *self, const char *peer)
return address;
}

// --------------------------------------------------------------------------
// Return the name of a connected peer. Caller owns the
// string.

char *
zyre_get_peer_name(zyre_t *self, const char *peer)
{
assert (self);
char *address;
zstr_sendm (self->actor, "PEER NAME");
zstr_send (self->actor, peer);
zsock_recv (self->actor, "s", &address);
return address;
}

// --------------------------------------------------------------------------
// Return the value of a header of a conected peer.
// Returns null if peer or key doesn't exits. Caller
Expand Down Expand Up @@ -655,6 +670,9 @@ zyre_test (bool verbose)
char *name = zmsg_popstr (msg);
assert (streq (name, "node1"));
zstr_free (&name);
char *peer_name = zyre_get_peer_name(node2, peerid);
assert (streq (peer_name, "node1"));
zstr_free (&peer_name);
zframe_t *headers_packed = zmsg_pop (msg);
char *peeraddress = zmsg_popstr (msg);
char *peerendpoint = zyre_peer_address (node2, peerid);
Expand Down
8 changes: 8 additions & 0 deletions src/zyre_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,14 @@ zyre_node_recv_api (zyre_node_t *self)
zstr_free (&uuid);
}
else
if (streq (command, "PEER NAME")) {
char *uuid = zmsg_popstr (request);
zyre_peer_t *peer = (zyre_peer_t *) zhash_lookup (self->peers, uuid);
assert (peer);
zsock_send (self->pipe, "s", zyre_peer_name (peer));
zstr_free (&uuid);
}
else
if (streq (command, "PEER HEADER")) {
char *uuid = zmsg_popstr (request);
char *key = zmsg_popstr (request);
Expand Down

0 comments on commit 2092be7

Please sign in to comment.