From 7faa62d0e03329190ad48489d09daa087c9456e2 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Wed, 27 Nov 2013 18:11:03 +0000 Subject: [PATCH] - revamp mesh_common code, minor refactoring --- src/mesh/gnunet-service-mesh_channel.c | 26 +++++++-------- src/mesh/gnunet-service-mesh_connection.c | 40 +++++++++++------------ src/mesh/gnunet-service-mesh_peer.c | 12 +++---- src/mesh/gnunet-service-mesh_tunnel.c | 8 ++--- src/mesh/mesh.h | 19 ++++++++--- src/mesh/mesh_api.c | 10 +++--- src/mesh/mesh_common.c | 38 +++++++++++++++++---- 7 files changed, 94 insertions(+), 59 deletions(-) diff --git a/src/mesh/gnunet-service-mesh_channel.c b/src/mesh/gnunet-service-mesh_channel.c index 2d9ebb660..d2bb1b3d3 100644 --- a/src/mesh/gnunet-service-mesh_channel.c +++ b/src/mesh/gnunet-service-mesh_channel.c @@ -322,7 +322,7 @@ add_buffered_data (const struct GNUNET_MESH_Data *msg, for (prev = rel->head_recv; NULL != prev; prev = prev->next) { LOG (GNUNET_ERROR_TYPE_DEBUG, " prev %u\n", prev->mid); - if (GMC_is_pid_bigger (prev->mid, mid)) + if (GM_is_pid_bigger (prev->mid, mid)) { LOG (GNUNET_ERROR_TYPE_DEBUG, " bingo!\n"); GNUNET_CONTAINER_DLL_insert_before (rel->head_recv, rel->tail_recv, @@ -467,7 +467,7 @@ send_client_ack (struct MeshChannel *ch, int fwd) LOG (GNUNET_ERROR_TYPE_DEBUG, " sending %s ack to client on channel %s\n", - fwd ? "FWD" : "BCK", GMCH_2s (ch)); + GM_f2s (fwd), GMCH_2s (ch)); if (NULL == rel) { @@ -614,7 +614,7 @@ channel_rel_free_sent (struct MeshChannelReliability *rel, /* Skip copies with mid < target */ target = mid + i + 1; LOG (GNUNET_ERROR_TYPE_DEBUG, " target %u\n", target); - while (NULL != copy && GMC_is_pid_bigger (target, copy->mid)) + while (NULL != copy && GM_is_pid_bigger (target, copy->mid)) copy = copy->next; /* Did we run out of copies? (previously freed, it's ok) */ @@ -625,7 +625,7 @@ channel_rel_free_sent (struct MeshChannelReliability *rel, } /* Did we overshoot the target? (previously freed, it's ok) */ - if (GMC_is_pid_bigger (copy->mid, target)) + if (GM_is_pid_bigger (copy->mid, target)) { LOG (GNUNET_ERROR_TYPE_DEBUG, " next copy %u\n", copy->mid); continue; @@ -741,7 +741,7 @@ channel_send_ack (struct MeshChannel *ch, int fwd) msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CHANNEL_ACK); LOG (GNUNET_ERROR_TYPE_DEBUG, " sending channel %s ack for channel %s\n", - fwd ? "FWD" : "BCK", GMCH_2s (ch)); + GM_f2s (fwd), GMCH_2s (ch)); msg.chid = htonl (ch->gid); GMCH_send_prebuilt_message (&msg.header, ch, !fwd, GNUNET_NO); @@ -784,7 +784,7 @@ channel_confirm (struct MeshChannel *ch, int fwd) LOG (GNUNET_ERROR_TYPE_DEBUG, " channel confirm %s %s:%X\n", - fwd ? "FWD" : "BCK", GMT_2s (ch->t), ch->gid); + GM_f2s (fwd), GMT_2s (ch->t), ch->gid); ch->state = MESH_CHANNEL_READY; rel = fwd ? ch->root_rel : ch->dest_rel; @@ -867,7 +867,7 @@ channel_save_copy (struct MeshChannel *ch, size = ntohs (msg->size); LOG (GNUNET_ERROR_TYPE_DEBUG, "!!! SAVE %u %s\n", - mid, GNUNET_MESH_DEBUG_M2S (type)); + mid, GM_m2s (type)); copy = GNUNET_malloc (sizeof (struct MeshReliableMessage) + size); copy->mid = mid; copy->rel = rel; @@ -955,7 +955,7 @@ handle_loopback (struct MeshChannel *ch, type = ntohs (msgh->type); LOG (GNUNET_ERROR_TYPE_DEBUG, "Loopback %s %s message!\n", - fwd ? "FWD" : "BCK", GNUNET_MESH_DEBUG_M2S (type)); + GM_f2s (fwd), GM_m2s (type)); switch (type) { @@ -1211,7 +1211,7 @@ GMCH_send_data_ack (struct MeshChannel *ch, int fwd) { LOG (GNUNET_ERROR_TYPE_DEBUG, "!! Type %s, expected DATA\n", - GNUNET_MESH_DEBUG_M2S (copy->type)); + GM_m2s (copy->type)); continue; } if (copy->mid == ack + 1) @@ -1593,8 +1593,8 @@ GMCH_handle_data (struct MeshChannel *ch, LOG (GNUNET_ERROR_TYPE_DEBUG, "!! got mid %u\n", mid); if (GNUNET_NO == ch->reliable || - ( !GMC_is_pid_bigger (rel->mid_recv, mid) && - GMC_is_pid_bigger (rel->mid_recv + 64, mid) ) ) + ( !GM_is_pid_bigger (rel->mid_recv, mid) && + GM_is_pid_bigger (rel->mid_recv + 64, mid) ) ) { LOG (GNUNET_ERROR_TYPE_DEBUG, "!!! RECV %u\n", mid); if (GNUNET_YES == ch->reliable) @@ -1687,7 +1687,7 @@ GMCH_handle_data_ack (struct MeshChannel *ch, /* Free ACK'd copies: no need to retransmit those anymore */ for (work = GNUNET_NO, copy = rel->head_sent; copy != NULL; copy = next) { - if (GMC_is_pid_bigger (copy->mid, ack)) + if (GM_is_pid_bigger (copy->mid, ack)) { LOG (GNUNET_ERROR_TYPE_DEBUG, "!!! head %u, out!\n", copy->mid); channel_rel_free_sent (rel, msg); @@ -1911,7 +1911,7 @@ GMCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message, int retransmission) { LOG (GNUNET_ERROR_TYPE_DEBUG, "GMCH Send %s %s on channel %s\n", - fwd ? "FWD" : "BCK", GNUNET_MESH_DEBUG_M2S (ntohs (message->type)), + GM_f2s (fwd), GM_m2s (ntohs (message->type)), GMCH_2s (ch)); if (GMT_is_loopback (ch->t)) diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c index 73e947753..c08f64f6d 100644 --- a/src/mesh/gnunet-service-mesh_connection.c +++ b/src/mesh/gnunet-service-mesh_connection.c @@ -449,7 +449,7 @@ send_ack (struct MeshConnection *c, unsigned int buffer, int fwd, int force) LOG (GNUNET_ERROR_TYPE_DEBUG, "connection send %s ack on %s\n", - fwd ? "FWD" : "BCK", GMC_2s (c)); + GM_f2s (fwd), GMC_2s (c)); /* Check if we need to transmit the ACK. */ delta = prev_fc->last_ack_sent - prev_fc->last_pid_recv; @@ -478,7 +478,7 @@ send_ack (struct MeshConnection *c, unsigned int buffer, int fwd, int force) /* Check if message is already in queue */ if (NULL != prev_fc->ack_msg) { - if (GMC_is_pid_bigger (ack, prev_fc->last_ack_sent)) + if (GM_is_pid_bigger (ack, prev_fc->last_ack_sent)) { LOG (GNUNET_ERROR_TYPE_DEBUG, " canceling old ACK\n"); GMC_cancel (prev_fc->ack_msg); @@ -530,8 +530,8 @@ message_sent (void *cls, fc = fwd ? &c->fwd_fc : &c->bck_fc; LOG (GNUNET_ERROR_TYPE_DEBUG, "! sent %s %s\n", - fwd ? "FWD" : "BCK", - GNUNET_MESH_DEBUG_M2S (type)); + GM_f2s (fwd), + GM_m2s (type)); LOG (GNUNET_ERROR_TYPE_DEBUG, "! C_P- %p %u\n", c, c->pending_messages); if (NULL != q) { @@ -704,7 +704,7 @@ send_connection_ack (struct MeshConnection *connection, int fwd) t = connection->t; LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection %s ACK\n", - !fwd ? "FWD" : "BCK"); + !GM_f2s (fwd)); GMP_queue_add (get_hop (connection, fwd), NULL, GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK, sizeof (struct GNUNET_MESH_ConnectionACK), @@ -760,7 +760,7 @@ connection_keepalive (struct MeshConnection *c, int fwd) LOG (GNUNET_ERROR_TYPE_DEBUG, "sending %s keepalive for connection %s]\n", - fwd ? "FWD" : "BCK", GMC_2s (c)); + GM_f2s (fwd), GMC_2s (c)); msg = (struct GNUNET_MESH_ConnectionKeepAlive *) cbuf; msg->header.size = htons (size); @@ -876,7 +876,7 @@ connection_unlock_queue (struct MeshConnection *c, int fwd) LOG (GNUNET_ERROR_TYPE_DEBUG, "connection_unlock_queue %s on %s\n", - fwd ? "FWD" : "BCK", GMC_2s (c)); + GM_f2s (fwd), GMC_2s (c)); if (GMC_is_terminal (c, fwd)) { @@ -906,7 +906,7 @@ connection_cancel_queues (struct MeshConnection *c, int fwd) LOG (GNUNET_ERROR_TYPE_DEBUG, " *** Cancel %s queues for connection %s\n", - fwd ? "FWD" : "BCK", GMC_2s (c)); + GM_f2s (fwd), GMC_2s (c)); if (NULL == c) { GNUNET_break (0); @@ -1564,7 +1564,7 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer, type = ntohs (msg->header.type); LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\n"); LOG (GNUNET_ERROR_TYPE_DEBUG, "got a %s message (#%u) from %s\n", - GNUNET_MESH_DEBUG_M2S (type), ntohl (msg->pid), GNUNET_i2s (peer)); + GM_m2s (type), ntohl (msg->pid), GNUNET_i2s (peer)); /* Check connection */ c = connection_get (&msg->cid); @@ -1602,7 +1602,7 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer, /* Check PID */ fc = fwd ? &c->bck_fc : &c->fwd_fc; pid = ntohl (msg->pid); - if (GMC_is_pid_bigger (pid, fc->last_ack_sent)) + if (GM_is_pid_bigger (pid, fc->last_ack_sent)) { GNUNET_STATISTICS_update (stats, "# unsolicited message", 1, GNUNET_NO); LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -1610,7 +1610,7 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer, pid, fc->last_pid_recv, fc->last_ack_sent); return GNUNET_OK; } - if (GNUNET_NO == GMC_is_pid_bigger (pid, fc->last_pid_recv)) + if (GNUNET_NO == GM_is_pid_bigger (pid, fc->last_pid_recv)) { GNUNET_STATISTICS_update (stats, "# duplicate PID", 1, GNUNET_NO); LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -1691,7 +1691,7 @@ handle_mesh_kx (const struct GNUNET_PeerIdentity *peer, type = ntohs (msg->header.type); LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\n"); LOG (GNUNET_ERROR_TYPE_DEBUG, "got a %s message from %s\n", - GNUNET_MESH_DEBUG_M2S (type), GNUNET_i2s (peer)); + GM_m2s (type), GNUNET_i2s (peer)); /* Check connection */ c = connection_get (&msg->cid); @@ -1853,12 +1853,12 @@ GMC_handle_ack (void *cls, const struct GNUNET_PeerIdentity *peer, ack = ntohl (msg->ack); LOG (GNUNET_ERROR_TYPE_DEBUG, " ACK %u (was %u)\n", ack, fc->last_ack_recv); - if (GMC_is_pid_bigger (ack, fc->last_ack_recv)) + if (GM_is_pid_bigger (ack, fc->last_ack_recv)) fc->last_ack_recv = ack; /* Cancel polling if the ACK is big enough. */ if (GNUNET_SCHEDULER_NO_TASK != fc->poll_task && - GMC_is_pid_bigger (fc->last_ack_recv, fc->last_pid_sent)) + GM_is_pid_bigger (fc->last_ack_recv, fc->last_pid_sent)) { LOG (GNUNET_ERROR_TYPE_DEBUG, " Cancel poll\n"); GNUNET_SCHEDULER_cancel (fc->poll_task); @@ -2024,7 +2024,7 @@ GMC_send_ack (struct MeshConnection *c, int fwd, int force) LOG (GNUNET_ERROR_TYPE_DEBUG, "GMC send %s ACK on %s\n", - fwd ? "FWD" : "BCK", GMC_2s (c)); + GM_f2s (fwd), GMC_2s (c)); if (NULL == c) { @@ -2342,7 +2342,7 @@ GMC_get_allowed (struct MeshConnection *c, int fwd) struct MeshFlowControl *fc; fc = fwd ? &c->fwd_fc : &c->bck_fc; - if (GMC_is_pid_bigger(fc->last_pid_recv, fc->last_ack_sent)) + if (GM_is_pid_bigger(fc->last_pid_recv, fc->last_ack_sent)) { return 0; } @@ -2477,7 +2477,7 @@ GMC_is_sendable (struct MeshConnection *c, int fwd) struct MeshFlowControl *fc; fc = fwd ? &c->fwd_fc : &c->bck_fc; - if (GMC_is_pid_bigger (fc->last_ack_recv, fc->last_pid_sent)) + if (GM_is_pid_bigger (fc->last_ack_recv, fc->last_pid_sent)) return GNUNET_YES; return GNUNET_NO; } @@ -2514,7 +2514,7 @@ GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, memcpy (data, message, size); type = ntohs (message->type); LOG (GNUNET_ERROR_TYPE_DEBUG, "Send %s (%u bytes) on connection %s\n", - GNUNET_MESH_DEBUG_M2S (type), size, GMC_2s (c)); + GM_m2s (type), size, GMC_2s (c)); fc = fwd ? &c->fwd_fc : &c->bck_fc; droppable = GNUNET_YES; @@ -2545,7 +2545,7 @@ GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, LOG (GNUNET_ERROR_TYPE_DEBUG, "pid %u\n", ntohl (emsg->pid)); LOG (GNUNET_ERROR_TYPE_DEBUG, "last pid sent %u\n", fc->last_pid_sent); LOG (GNUNET_ERROR_TYPE_DEBUG, " ack recv %u\n", fc->last_ack_recv); - if (GMC_is_pid_bigger (fc->last_pid_sent + 1, fc->last_ack_recv)) + if (GM_is_pid_bigger (fc->last_pid_sent + 1, fc->last_ack_recv)) { GMC_start_poll (c, fwd); } @@ -2733,7 +2733,7 @@ GMC_start_poll (struct MeshConnection *c, int fwd) fc = fwd ? &c->fwd_fc : &c->bck_fc; LOG (GNUNET_ERROR_TYPE_DEBUG, " *** POLL %s requested\n", - fwd ? "FWD" : "BCK"); + GM_f2s (fwd)); if (GNUNET_SCHEDULER_NO_TASK != fc->poll_task || NULL != fc->poll_msg) { LOG (GNUNET_ERROR_TYPE_DEBUG, " *** not needed (%u, %p)\n", diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c index dfc673321..76296c198 100644 --- a/src/mesh/gnunet-service-mesh_peer.c +++ b/src/mesh/gnunet-service-mesh_peer.c @@ -814,7 +814,7 @@ queue_send (void *cls, size_t size, void *buf) case GNUNET_MESSAGE_TYPE_MESH_POLL: LOG (GNUNET_ERROR_TYPE_DEBUG, "* raw: %s\n", - GNUNET_MESH_DEBUG_M2S (queue->type)); + GM_m2s (queue->type)); data_size = send_core_data_raw (queue->cls, size, buf); break; case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE: @@ -850,7 +850,7 @@ queue_send (void *cls, size_t size, void *buf) { LOG (GNUNET_ERROR_TYPE_WARNING, "Dropping message of type %s\n", - GNUNET_MESH_DEBUG_M2S (queue->type)); + GM_m2s (queue->type)); data_size = 0; } @@ -915,7 +915,7 @@ GMP_queue_destroy (struct MeshPeerQueue *queue, int clear_cls) if (GNUNET_YES == clear_cls) { LOG (GNUNET_ERROR_TYPE_DEBUG, "# queue destroy type %s\n", - GNUNET_MESH_DEBUG_M2S (queue->type)); + GM_m2s (queue->type)); switch (queue->type) { case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY: @@ -934,7 +934,7 @@ GMP_queue_destroy (struct MeshPeerQueue *queue, int clear_cls) default: GNUNET_break (0); LOG (GNUNET_ERROR_TYPE_ERROR, "# type %s unknown!\n", - GNUNET_MESH_DEBUG_M2S (queue->type)); + GM_m2s (queue->type)); } } GNUNET_CONTAINER_DLL_remove (peer->queue_head, peer->queue_tail, queue); @@ -985,7 +985,7 @@ GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size, LOG (GNUNET_ERROR_TYPE_DEBUG, "queue add %s %s towards %s (size %u) on c %p (%s)\n", - fwd ? "FWD" : "BCK", GNUNET_MESH_DEBUG_M2S (type), GMP_2s(peer), + GM_f2s (fwd), GM_m2s (type), GMP_2s(peer), size, c, GMC_2s (c)); GNUNET_assert (NULL != c); @@ -1075,7 +1075,7 @@ GMP_queue_cancel (struct MeshPeer *peer, struct MeshConnection *c) { LOG (GNUNET_ERROR_TYPE_DEBUG, "GMP_cancel_queue %s\n", - GNUNET_MESH_DEBUG_M2S (q->type)); + GM_m2s (q->type)); GMP_queue_destroy (q, GNUNET_YES); /* Get next from prev, q->next might be already freed: diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c index eaf21dbf0..3ffc831f5 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.c +++ b/src/mesh/gnunet-service-mesh_tunnel.c @@ -736,7 +736,7 @@ send_kx (struct MeshTunnel3 *t, break; default: LOG (GNUNET_ERROR_TYPE_DEBUG, "unkown type %s\n", - GNUNET_MESH_DEBUG_M2S (type)); + GM_m2s (type)); GNUNET_break (0); } @@ -977,7 +977,7 @@ handle_data (struct MeshTunnel3 *t, return; } LOG (GNUNET_ERROR_TYPE_DEBUG, " payload of type %s\n", - GNUNET_MESH_DEBUG_M2S (ntohs (msg[1].header.type))); + GM_m2s (ntohs (msg[1].header.type))); /* Check channel */ ch = GMT_get_channel (t, ntohl (msg->chid)); @@ -1314,7 +1314,7 @@ handle_decrypted (struct MeshTunnel3 *t, type = ntohs (msgh->type); LOG (GNUNET_ERROR_TYPE_DEBUG, "Got a %s message!\n", - GNUNET_MESH_DEBUG_M2S (type)); + GM_m2s (type)); switch (type) { @@ -2213,7 +2213,7 @@ GMT_send_prebuilt_message (const struct GNUNET_MessageHeader *message, break; default: LOG (GNUNET_ERROR_TYPE_DEBUG, "unkown type %s\n", - GNUNET_MESH_DEBUG_M2S (type)); + GM_m2s (type)); GNUNET_break (0); } diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h index a85654457..1211f7ebc 100644 --- a/src/mesh/mesh.h +++ b/src/mesh/mesh.h @@ -199,6 +199,17 @@ GNUNET_NETWORK_STRUCT_END +/** + * @brief Translate a fwd variable into a string representation, for logging. + * + * @param fwd Is FWD? (#GNUNET_YES or #GNUNET_NO) + * + * @return String representing FWD or BCK. + */ +char * +GM_f2s (int fwd); + + /** * Check if one pid is bigger than other, accounting for overflow. * @@ -208,7 +219,7 @@ GNUNET_NETWORK_STRUCT_END * @return True if bigger (arg1) has a higher value than smaller (arg 2). */ int -GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller); +GM_is_pid_bigger (uint32_t bigger, uint32_t smaller); /** @@ -220,7 +231,7 @@ GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller); * @return Highest ACK value from the two. */ uint32_t -GMC_max_pid (uint32_t a, uint32_t b); +GM_max_pid (uint32_t a, uint32_t b); /** @@ -232,7 +243,7 @@ GMC_max_pid (uint32_t a, uint32_t b); * @return Lowest ACK value from the two. */ uint32_t -GMC_min_pid (uint32_t a, uint32_t b); +GM_min_pid (uint32_t a, uint32_t b); /** @@ -246,7 +257,7 @@ GMC_min_pid (uint32_t a, uint32_t b); * @return Human readable string description. */ const char * -GNUNET_MESH_DEBUG_M2S (uint16_t m); +GM_m2s (uint16_t m); #if 0 /* keep Emacsens' auto-indent happy */ { diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index c9df698fb..0d1d70026 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c @@ -1054,7 +1054,7 @@ msg_received (void *cls, const struct GNUNET_MessageHeader *msg) type = ntohs (msg->type); LOG (GNUNET_ERROR_TYPE_DEBUG, "\n"); LOG (GNUNET_ERROR_TYPE_DEBUG, "Received a message: %s\n", - GNUNET_MESH_DEBUG_M2S (type)); + GM_m2s (type)); switch (type) { /* Notify of a new incoming channel */ @@ -1082,7 +1082,7 @@ msg_received (void *cls, const struct GNUNET_MessageHeader *msg) /* We shouldn't get any other packages, log and ignore */ LOG (GNUNET_ERROR_TYPE_WARNING, "unsolicited message form service (type %s)\n", - GNUNET_MESH_DEBUG_M2S (ntohs (msg->type))); + GM_m2s (ntohs (msg->type))); } LOG (GNUNET_ERROR_TYPE_DEBUG, "message processed\n"); if (GNUNET_YES == h->in_receive) @@ -1166,7 +1166,7 @@ send_callback (void *cls, size_t size, void *buf) dmsg->id = htonl (ch->chid); dmsg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA); LOG (GNUNET_ERROR_TYPE_DEBUG, "# payload type %s\n", - GNUNET_MESH_DEBUG_M2S (ntohs (mh->type))); + GM_m2s (ntohs (mh->type))); ch->allow_send = GNUNET_NO; } else @@ -1181,7 +1181,7 @@ send_callback (void *cls, size_t size, void *buf) struct GNUNET_MessageHeader *mh = (struct GNUNET_MessageHeader *) &th[1]; LOG (GNUNET_ERROR_TYPE_DEBUG, "# mesh internal traffic, type %s\n", - GNUNET_MESH_DEBUG_M2S (ntohs (mh->type))); + GM_m2s (ntohs (mh->type))); memcpy (cbuf, &th[1], th->size); psize = th->size; } @@ -1243,7 +1243,7 @@ send_packet (struct GNUNET_MESH_Handle *h, size_t msize; LOG (GNUNET_ERROR_TYPE_DEBUG, " Sending message to service: %s\n", - GNUNET_MESH_DEBUG_M2S(ntohs(msg->type))); + GM_m2s(ntohs(msg->type))); msize = ntohs (msg->size); th = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle) + msize); th->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; diff --git a/src/mesh/mesh_common.c b/src/mesh/mesh_common.c index ad446646a..d99018b9a 100644 --- a/src/mesh/mesh_common.c +++ b/src/mesh/mesh_common.c @@ -26,9 +26,33 @@ #include "mesh.h" +/** + * @brief Translate a fwd variable into a string representation, for logging. + * + * @param fwd Is FWD? (#GNUNET_YES or #GNUNET_NO) + * + * @return String representing FWD or BCK. + */ +char * +GM_f2s (int fwd) +{ + if (GNUNET_YES == fwd) + { + return "FWD"; + } + else if (GNUNET_NO == fwd) + { + return "BCK"; + } + else + { + GNUNET_break (0); + return ""; + } +} int -GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller) +GM_is_pid_bigger (uint32_t bigger, uint32_t smaller) { return (GNUNET_YES == PID_OVERFLOW (smaller, bigger) || (bigger > smaller && GNUNET_NO == PID_OVERFLOW (bigger, smaller))); @@ -36,18 +60,18 @@ GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller) uint32_t -GMC_max_pid (uint32_t a, uint32_t b) +GM_max_pid (uint32_t a, uint32_t b) { - if (GMC_is_pid_bigger(a, b)) + if (GM_is_pid_bigger(a, b)) return a; return b; } uint32_t -GMC_min_pid (uint32_t a, uint32_t b) +GM_min_pid (uint32_t a, uint32_t b) { - if (GMC_is_pid_bigger(a, b)) + if (GM_is_pid_bigger(a, b)) return b; return a; } @@ -55,7 +79,7 @@ GMC_min_pid (uint32_t a, uint32_t b) #if !defined(GNUNET_CULL_LOGGING) const char * -GNUNET_MESH_DEBUG_M2S (uint16_t m) +GM_m2s (uint16_t m) { static char buf[32]; switch (m) @@ -185,7 +209,7 @@ GNUNET_MESH_DEBUG_M2S (uint16_t m) } #else const char * -GNUNET_MESH_DEBUG_M2S (uint16_t m) +GM_m2s (uint16_t m) { return ""; } -- 2.25.1