Skip to content

Commit

Permalink
Keep zre_msg.h in src directory (#674)
Browse files Browse the repository at this point in the history
* Keep zre_msg.h in src directory

This is a bug in automatic code generation which places all headers in include by default

* add castings for windows compatibility, improve code presentation

* Remove unused variable

* remove useless variable

* avoid difference with generated code for zyre event

* remove API modification to avoid large changes in automatic code generation

* do not refresh deleted peer

Co-authored-by: Stéphane Valès <stephane@vales.fr@users.noreply.github.com>
Co-authored-by: stephane vales <vales@ingenuity.io>
  • Loading branch information
3 people committed Aug 12, 2020
1 parent 99669a2 commit b2a3ce5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion api/zyre_event.api
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<method name = "type">
Returns event type, as printable uppercase string. Choices are:
"ENTER", "EXIT", "JOIN", "LEAVE", "EVASIVE", "SILENT", "WHISPER" and "SHOUT"
"ENTER", "EXIT", "JOIN", "LEAVE", "EVASIVE", "WHISPER" and "SHOUT"
and for the local node: "STOP"
<return type = "string" />
</method>
Expand Down
5 changes: 1 addition & 4 deletions src/zre_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#endif

#include "../include/zyre.h"
#include "../include/zre_msg.h"
#include "./zre_msg.h"

// Structure of our class

Expand Down Expand Up @@ -1389,7 +1389,6 @@ zre_msg_encode (zre_msg_t *self)
// Now serialize message into the frame
PUT_NUMBER2 (0xAAA0 | 1);
PUT_NUMBER1 (self->id);
bool have_content = false;
size_t nbr_frames = 1; // Total number of frames to send

switch (self->id) {
Expand Down Expand Up @@ -1426,15 +1425,13 @@ zre_msg_encode (zre_msg_t *self)
PUT_NUMBER1 (2);
PUT_NUMBER2 (self->sequence);
nbr_frames += self->content? zmsg_size (self->content): 1;
have_content = true;
break;

case ZRE_MSG_SHOUT:
PUT_NUMBER1 (2);
PUT_NUMBER2 (self->sequence);
PUT_STRING (self->group);
nbr_frames += self->content? zmsg_size (self->content): 1;
have_content = true;
break;

case ZRE_MSG_JOIN:
Expand Down
28 changes: 14 additions & 14 deletions src/zyre_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,12 @@ static int
zyre_node_stop (zyre_node_t *self)
{
if (self->gossip) {
zyre_peer_t *peer = zhash_first (self->peers);
zyre_peer_t *peer = (zyre_peer_t *) zhash_first (self->peers);
while (peer) {
zre_msg_t *msg = zre_msg_new ();
zre_msg_set_id (msg, ZRE_MSG_GOODBYE);
zyre_peer_send (peer, &msg);
peer = zhash_next (self->peers);
peer = (zyre_peer_t *) zhash_next (self->peers);
}
}

Expand Down Expand Up @@ -916,7 +916,7 @@ zyre_node_remove_peer (zyre_node_t *self, zyre_peer_t *peer)
zstr_send (self->outbox, zyre_peer_name (peer));

#ifdef ZYRE_BUILD_DRAFT_API
// Clean this peer in our gossip table if needed
// Clean this peer in our gossip table if needed
if (self->gossip_bind)
zstr_sendx (self->gossip, "UNPUBLISH", zyre_peer_identity (peer), NULL);
#endif
Expand Down Expand Up @@ -1306,20 +1306,20 @@ zyre_node_recv_peer (zyre_node_t *self)

else
if (zre_msg_id (msg) == ZRE_MSG_GOODBYE) {
// If discovery mode is UDP, beacons do the job for peer removal (see zyre_node_recv_beacon)
// If discovery mode is Gossip, we need to remove here
if (self->gossip) {
zyre_peer_t *peer = (zyre_peer_t *) zhash_lookup (self->peers, zuuid_str (uuid));
if (peer)
zyre_node_remove_peer (self, peer);
// If discovery mode is UDP, beacons do the job for peer removal (see zyre_node_recv_beacon)
// If discovery mode is Gossip, we need to remove here
if (self->gossip && peer) {
zyre_node_remove_peer (self, peer);
peer = NULL;
}
}

zuuid_destroy (&uuid);
zre_msg_destroy (&msg);

// Activity from peer resets peer timers
zyre_peer_refresh (peer, self->evasive_timeout, self->expired_timeout);
if (peer)
zyre_peer_refresh (peer, self->evasive_timeout, self->expired_timeout);
}

// Handle beacon data
Expand Down Expand Up @@ -1451,9 +1451,9 @@ zyre_node_ping_peer (const char *key, void *item, void *argument)
// TODO: do this only once for a peer in this state;
// it would be nicer to use a proper state machine
// for peer management.
// if (self->verbose)
// zsys_info ("(%s) peer does not send messages (evasive) name=%s endpoint=%s",
// self->name, zyre_peer_name (peer), zyre_peer_endpoint (peer));
if (self->verbose)
zsys_info ("(%s) peer does not send messages (evasive) name=%s endpoint=%s",
self->name, zyre_peer_name (peer), zyre_peer_endpoint (peer));
zre_msg_t *msg = zre_msg_new ();
zre_msg_set_id (msg, ZRE_MSG_PING);
zyre_peer_send (peer, &msg);
Expand All @@ -1470,7 +1470,7 @@ zyre_node_ping_peer (const char *key, void *item, void *argument)
// before getting ping result and thus has poor meaning.
if (self->verbose)
zsys_info ("(%s) peer '%s' has not answered ping after %d milliseconds (silent)",
self->name, zyre_peer_name(peer), REAP_INTERVAL);
self->name, zyre_peer_name(peer), REAP_INTERVAL);
zstr_sendm (self->outbox, "SILENT");
zstr_sendm (self->outbox, zyre_peer_identity (peer));
zstr_send (self->outbox, zyre_peer_name (peer));
Expand Down

0 comments on commit b2a3ce5

Please sign in to comment.