Skip to content

Commit

Permalink
Problem: Cannot obtain a list of all peer in one group
Browse files Browse the repository at this point in the history
Solution: Add a new API call to get all peers from one group. This
requires the peer to be in that group.
  • Loading branch information
sappo committed Jun 14, 2016
1 parent 1c4cd42 commit 26417ce
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 18 deletions.
26 changes: 16 additions & 10 deletions api/zyre.api
Expand Up @@ -42,13 +42,13 @@
</method>

<method name = "set verbose">
Set verbose mode; this tells the node to log all traffic as well as
Set verbose mode; this tells the node to log all traffic as well as
all major events.
</method>

<method name = "set port">
Set UDP beacon discovery port; defaults to 5670, this call overrides
that so you can create independent clusters on the same network, for
Set UDP beacon discovery port; defaults to 5670, this call overrides
that so you can create independent clusters on the same network, for
e.g. development vs. production. Has no effect after zyre_start().
<argument name = "port nbr" type = "integer" />
</method>
Expand Down Expand Up @@ -90,7 +90,7 @@
<method name = "gossip connect">
Set-up gossip discovery of other nodes. A node may connect to multiple
other nodes, for redundancy paths. For details of the gossip network
design, see the CZMQ zgossip class.
design, see the CZMQ zgossip class.
<argument name = "format" type = "format" />
</method>

Expand Down Expand Up @@ -158,29 +158,35 @@
</method>

<method name = "peers">
Return zlist of current peer ids.
Return zlist of current peer ids.
<return type = "zlist" fresh = "1" />
</method>

<method name = "peers by group">
Return zlist of current peers of this group.
<argument name = "name" type = "string" />
<return type = "zlist" fresh = "1" />
</method>

<method name = "own groups">
Return zlist of currently joined groups.
Return zlist of currently joined groups.
<return type = "zlist" fresh = "1" />
</method>

<method name = "peer groups">
Return zlist of groups known through connected peers.
Return zlist of groups known through connected peers.
<return type = "zlist" fresh = "1" />
</method>

<method name = "peer address">
Return the endpoint of a connected peer.
Return the endpoint of a connected peer.
<argument name = "peer" type = "string" />
<return type = "string" fresh = "1" />
</method>

<method name = "peer header value">
Return the value of a header of a conected peer.
Returns null if peer or key doesn't exits.
Return the value of a header of a conected peer.
Returns null if peer or key doesn't exits.
<argument name = "peer" type = "string" />
<argument name = "name" type = "string" />
<return type = "string" fresh = "1" />
Expand Down
20 changes: 13 additions & 7 deletions include/zyre.h
Expand Up @@ -58,15 +58,15 @@ ZYRE_EXPORT void
zyre_set_header (zyre_t *self, const char *name, const char *format, ...);

// *** Draft method, for development use, may change without warning ***
// Set verbose mode; this tells the node to log all traffic as well as
// all major events.
// Set verbose mode; this tells the node to log all traffic as well as
// all major events.
ZYRE_EXPORT void
zyre_set_verbose (zyre_t *self);

// *** Draft method, for development use, may change without warning ***
// Set UDP beacon discovery port; defaults to 5670, this call overrides
// that so you can create independent clusters on the same network, for
// e.g. development vs. production. Has no effect after zyre_start().
// Set UDP beacon discovery port; defaults to 5670, this call overrides
// that so you can create independent clusters on the same network, for
// e.g. development vs. production. Has no effect after zyre_start().
ZYRE_EXPORT void
zyre_set_port (zyre_t *self, int port_nbr);

Expand Down Expand Up @@ -171,6 +171,12 @@ ZYRE_EXPORT int
ZYRE_EXPORT zlist_t *
zyre_peers (zyre_t *self);

// *** Draft method, for development use, may change without warning ***
// Return zlist of current peers of this group.
// Caller owns return value and must destroy it when done.
ZYRE_EXPORT zlist_t *
zyre_peers_by_group (zyre_t *self, const char *name);

// *** Draft method, for development use, may change without warning ***
// Return zlist of currently joined groups.
// Caller owns return value and must destroy it when done.
Expand All @@ -190,8 +196,8 @@ ZYRE_EXPORT char *
zyre_peer_address (zyre_t *self, const char *peer);

// *** Draft method, for development use, may change without warning ***
// Return the value of a header of a conected peer.
// Returns null if peer or key doesn't exits.
// Return the value of a header of a conected peer.
// Returns null if peer or key doesn't exits.
// Caller owns return value and must destroy it when done.
ZYRE_EXPORT char *
zyre_peer_header_value (zyre_t *self, const char *peer, const char *name);
Expand Down
16 changes: 16 additions & 0 deletions src/zyre.c
Expand Up @@ -450,6 +450,22 @@ zyre_peers (zyre_t *self)
return peers;
}


// --------------------------------------------------------------------------
// Return zlist of current peers of this group. The caller owns this list and
// should destroy it when finished with it.

zlist_t *
zyre_peers_by_group (zyre_t *self, const char *group)
{
zlist_t *peers;
zstr_sendm (self->actor, "GROUP PEERS");
zstr_send (self->actor, group);
zsock_recv (self->actor, "p", &peers);
return peers;
}


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

Expand Down
11 changes: 11 additions & 0 deletions src/zyre_group.c
Expand Up @@ -118,6 +118,17 @@ zyre_group_send (zyre_group_t *self, zre_msg_t **msg_p)
}


// --------------------------------------------------------------------------
// Return zlist of peer ids currently in this group
// Caller owns return value and must destroy it when done.

zlist_t *
zyre_group_peers (zyre_group_t *self)
{
return zhash_keys (self->peers);
}


// --------------------------------------------------------------------------
// Self test of this class

Expand Down
5 changes: 5 additions & 0 deletions src/zyre_group.h
Expand Up @@ -42,6 +42,11 @@ void
void
zyre_group_send (zyre_group_t *self, zre_msg_t **msg_p);

// Return zlist of peer ids currently in this group
// Caller owns return value and must destroy it when done.
zlist_t *
zyre_group_peers (zyre_group_t *self);

// Self test of this class
ZYRE_EXPORT void
zyre_group_test (bool verbose);
Expand Down
16 changes: 15 additions & 1 deletion src/zyre_node.c
Expand Up @@ -295,8 +295,11 @@ zyre_node_dump (zyre_node_t *self)
zsys_info (" - peers=%zu:", zhash_size (self->peers));
zhash_foreach (self->peers, (zhash_foreach_fn *) zyre_node_log_item, self);

zsys_info (" - groups=%zu:", zhash_size (self->own_groups));
zsys_info (" - own groups=%zu:", zhash_size (self->own_groups));
zhash_foreach (self->own_groups, (zhash_foreach_fn *) zyre_node_log_item, self);

zsys_info (" - peer groups=%zu:", zhash_size (self->peer_groups));
zhash_foreach (self->peer_groups, (zhash_foreach_fn *) zyre_node_log_item, self);
}


Expand Down Expand Up @@ -447,6 +450,17 @@ zyre_node_recv_api (zyre_node_t *self)
if (streq (command, "PEERS"))
zsock_send (self->pipe, "p", zhash_keys (self->peers));
else
if (streq (command, "GROUP PEERS")) {
char *name = zmsg_popstr (request);
zyre_group_t *group = (zyre_group_t *) zhash_lookup (self->own_groups, name);
if (group)
zsock_send (self->pipe, "p", zyre_group_peers (group));
else
zsock_send (self->pipe, "p", NULL);

zstr_free (&name);
}
else
if (streq (command, "PEER ENDPOINT")) {
char *uuid = zmsg_popstr (request);
zyre_peer_t *peer = (zyre_peer_t *) zhash_lookup (self->peers, uuid);
Expand Down

0 comments on commit 26417ce

Please sign in to comment.