aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-11-27 18:11:03 +0000
committerBart Polot <bart@net.in.tum.de>2013-11-27 18:11:03 +0000
commit7faa62d0e03329190ad48489d09daa087c9456e2 (patch)
tree04572563db489c8ef2a7636acb8c488872931f1e
parent41dc74fc9ebb29931fc7f78cc2d3cef7eb1bee7b (diff)
downloadgnunet-7faa62d0e03329190ad48489d09daa087c9456e2.tar.gz
gnunet-7faa62d0e03329190ad48489d09daa087c9456e2.zip
- revamp mesh_common code, minor refactoring
-rw-r--r--src/mesh/gnunet-service-mesh_channel.c26
-rw-r--r--src/mesh/gnunet-service-mesh_connection.c40
-rw-r--r--src/mesh/gnunet-service-mesh_peer.c12
-rw-r--r--src/mesh/gnunet-service-mesh_tunnel.c8
-rw-r--r--src/mesh/mesh.h19
-rw-r--r--src/mesh/mesh_api.c10
-rw-r--r--src/mesh/mesh_common.c38
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,
322 for (prev = rel->head_recv; NULL != prev; prev = prev->next) 322 for (prev = rel->head_recv; NULL != prev; prev = prev->next)
323 { 323 {
324 LOG (GNUNET_ERROR_TYPE_DEBUG, " prev %u\n", prev->mid); 324 LOG (GNUNET_ERROR_TYPE_DEBUG, " prev %u\n", prev->mid);
325 if (GMC_is_pid_bigger (prev->mid, mid)) 325 if (GM_is_pid_bigger (prev->mid, mid))
326 { 326 {
327 LOG (GNUNET_ERROR_TYPE_DEBUG, " bingo!\n"); 327 LOG (GNUNET_ERROR_TYPE_DEBUG, " bingo!\n");
328 GNUNET_CONTAINER_DLL_insert_before (rel->head_recv, rel->tail_recv, 328 GNUNET_CONTAINER_DLL_insert_before (rel->head_recv, rel->tail_recv,
@@ -467,7 +467,7 @@ send_client_ack (struct MeshChannel *ch, int fwd)
467 467
468 LOG (GNUNET_ERROR_TYPE_DEBUG, 468 LOG (GNUNET_ERROR_TYPE_DEBUG,
469 " sending %s ack to client on channel %s\n", 469 " sending %s ack to client on channel %s\n",
470 fwd ? "FWD" : "BCK", GMCH_2s (ch)); 470 GM_f2s (fwd), GMCH_2s (ch));
471 471
472 if (NULL == rel) 472 if (NULL == rel)
473 { 473 {
@@ -614,7 +614,7 @@ channel_rel_free_sent (struct MeshChannelReliability *rel,
614 /* Skip copies with mid < target */ 614 /* Skip copies with mid < target */
615 target = mid + i + 1; 615 target = mid + i + 1;
616 LOG (GNUNET_ERROR_TYPE_DEBUG, " target %u\n", target); 616 LOG (GNUNET_ERROR_TYPE_DEBUG, " target %u\n", target);
617 while (NULL != copy && GMC_is_pid_bigger (target, copy->mid)) 617 while (NULL != copy && GM_is_pid_bigger (target, copy->mid))
618 copy = copy->next; 618 copy = copy->next;
619 619
620 /* Did we run out of copies? (previously freed, it's ok) */ 620 /* Did we run out of copies? (previously freed, it's ok) */
@@ -625,7 +625,7 @@ channel_rel_free_sent (struct MeshChannelReliability *rel,
625 } 625 }
626 626
627 /* Did we overshoot the target? (previously freed, it's ok) */ 627 /* Did we overshoot the target? (previously freed, it's ok) */
628 if (GMC_is_pid_bigger (copy->mid, target)) 628 if (GM_is_pid_bigger (copy->mid, target))
629 { 629 {
630 LOG (GNUNET_ERROR_TYPE_DEBUG, " next copy %u\n", copy->mid); 630 LOG (GNUNET_ERROR_TYPE_DEBUG, " next copy %u\n", copy->mid);
631 continue; 631 continue;
@@ -741,7 +741,7 @@ channel_send_ack (struct MeshChannel *ch, int fwd)
741 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CHANNEL_ACK); 741 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CHANNEL_ACK);
742 LOG (GNUNET_ERROR_TYPE_DEBUG, 742 LOG (GNUNET_ERROR_TYPE_DEBUG,
743 " sending channel %s ack for channel %s\n", 743 " sending channel %s ack for channel %s\n",
744 fwd ? "FWD" : "BCK", GMCH_2s (ch)); 744 GM_f2s (fwd), GMCH_2s (ch));
745 745
746 msg.chid = htonl (ch->gid); 746 msg.chid = htonl (ch->gid);
747 GMCH_send_prebuilt_message (&msg.header, ch, !fwd, GNUNET_NO); 747 GMCH_send_prebuilt_message (&msg.header, ch, !fwd, GNUNET_NO);
@@ -784,7 +784,7 @@ channel_confirm (struct MeshChannel *ch, int fwd)
784 784
785 LOG (GNUNET_ERROR_TYPE_DEBUG, 785 LOG (GNUNET_ERROR_TYPE_DEBUG,
786 " channel confirm %s %s:%X\n", 786 " channel confirm %s %s:%X\n",
787 fwd ? "FWD" : "BCK", GMT_2s (ch->t), ch->gid); 787 GM_f2s (fwd), GMT_2s (ch->t), ch->gid);
788 ch->state = MESH_CHANNEL_READY; 788 ch->state = MESH_CHANNEL_READY;
789 789
790 rel = fwd ? ch->root_rel : ch->dest_rel; 790 rel = fwd ? ch->root_rel : ch->dest_rel;
@@ -867,7 +867,7 @@ channel_save_copy (struct MeshChannel *ch,
867 size = ntohs (msg->size); 867 size = ntohs (msg->size);
868 868
869 LOG (GNUNET_ERROR_TYPE_DEBUG, "!!! SAVE %u %s\n", 869 LOG (GNUNET_ERROR_TYPE_DEBUG, "!!! SAVE %u %s\n",
870 mid, GNUNET_MESH_DEBUG_M2S (type)); 870 mid, GM_m2s (type));
871 copy = GNUNET_malloc (sizeof (struct MeshReliableMessage) + size); 871 copy = GNUNET_malloc (sizeof (struct MeshReliableMessage) + size);
872 copy->mid = mid; 872 copy->mid = mid;
873 copy->rel = rel; 873 copy->rel = rel;
@@ -955,7 +955,7 @@ handle_loopback (struct MeshChannel *ch,
955 type = ntohs (msgh->type); 955 type = ntohs (msgh->type);
956 LOG (GNUNET_ERROR_TYPE_DEBUG, 956 LOG (GNUNET_ERROR_TYPE_DEBUG,
957 "Loopback %s %s message!\n", 957 "Loopback %s %s message!\n",
958 fwd ? "FWD" : "BCK", GNUNET_MESH_DEBUG_M2S (type)); 958 GM_f2s (fwd), GM_m2s (type));
959 959
960 switch (type) 960 switch (type)
961 { 961 {
@@ -1211,7 +1211,7 @@ GMCH_send_data_ack (struct MeshChannel *ch, int fwd)
1211 { 1211 {
1212 LOG (GNUNET_ERROR_TYPE_DEBUG, 1212 LOG (GNUNET_ERROR_TYPE_DEBUG,
1213 "!! Type %s, expected DATA\n", 1213 "!! Type %s, expected DATA\n",
1214 GNUNET_MESH_DEBUG_M2S (copy->type)); 1214 GM_m2s (copy->type));
1215 continue; 1215 continue;
1216 } 1216 }
1217 if (copy->mid == ack + 1) 1217 if (copy->mid == ack + 1)
@@ -1593,8 +1593,8 @@ GMCH_handle_data (struct MeshChannel *ch,
1593 LOG (GNUNET_ERROR_TYPE_DEBUG, "!! got mid %u\n", mid); 1593 LOG (GNUNET_ERROR_TYPE_DEBUG, "!! got mid %u\n", mid);
1594 1594
1595 if (GNUNET_NO == ch->reliable || 1595 if (GNUNET_NO == ch->reliable ||
1596 ( !GMC_is_pid_bigger (rel->mid_recv, mid) && 1596 ( !GM_is_pid_bigger (rel->mid_recv, mid) &&
1597 GMC_is_pid_bigger (rel->mid_recv + 64, mid) ) ) 1597 GM_is_pid_bigger (rel->mid_recv + 64, mid) ) )
1598 { 1598 {
1599 LOG (GNUNET_ERROR_TYPE_DEBUG, "!!! RECV %u\n", mid); 1599 LOG (GNUNET_ERROR_TYPE_DEBUG, "!!! RECV %u\n", mid);
1600 if (GNUNET_YES == ch->reliable) 1600 if (GNUNET_YES == ch->reliable)
@@ -1687,7 +1687,7 @@ GMCH_handle_data_ack (struct MeshChannel *ch,
1687 /* Free ACK'd copies: no need to retransmit those anymore */ 1687 /* Free ACK'd copies: no need to retransmit those anymore */
1688 for (work = GNUNET_NO, copy = rel->head_sent; copy != NULL; copy = next) 1688 for (work = GNUNET_NO, copy = rel->head_sent; copy != NULL; copy = next)
1689 { 1689 {
1690 if (GMC_is_pid_bigger (copy->mid, ack)) 1690 if (GM_is_pid_bigger (copy->mid, ack))
1691 { 1691 {
1692 LOG (GNUNET_ERROR_TYPE_DEBUG, "!!! head %u, out!\n", copy->mid); 1692 LOG (GNUNET_ERROR_TYPE_DEBUG, "!!! head %u, out!\n", copy->mid);
1693 channel_rel_free_sent (rel, msg); 1693 channel_rel_free_sent (rel, msg);
@@ -1911,7 +1911,7 @@ GMCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
1911 int retransmission) 1911 int retransmission)
1912{ 1912{
1913 LOG (GNUNET_ERROR_TYPE_DEBUG, "GMCH Send %s %s on channel %s\n", 1913 LOG (GNUNET_ERROR_TYPE_DEBUG, "GMCH Send %s %s on channel %s\n",
1914 fwd ? "FWD" : "BCK", GNUNET_MESH_DEBUG_M2S (ntohs (message->type)), 1914 GM_f2s (fwd), GM_m2s (ntohs (message->type)),
1915 GMCH_2s (ch)); 1915 GMCH_2s (ch));
1916 1916
1917 if (GMT_is_loopback (ch->t)) 1917 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)
449 449
450 LOG (GNUNET_ERROR_TYPE_DEBUG, 450 LOG (GNUNET_ERROR_TYPE_DEBUG,
451 "connection send %s ack on %s\n", 451 "connection send %s ack on %s\n",
452 fwd ? "FWD" : "BCK", GMC_2s (c)); 452 GM_f2s (fwd), GMC_2s (c));
453 453
454 /* Check if we need to transmit the ACK. */ 454 /* Check if we need to transmit the ACK. */
455 delta = prev_fc->last_ack_sent - prev_fc->last_pid_recv; 455 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)
478 /* Check if message is already in queue */ 478 /* Check if message is already in queue */
479 if (NULL != prev_fc->ack_msg) 479 if (NULL != prev_fc->ack_msg)
480 { 480 {
481 if (GMC_is_pid_bigger (ack, prev_fc->last_ack_sent)) 481 if (GM_is_pid_bigger (ack, prev_fc->last_ack_sent))
482 { 482 {
483 LOG (GNUNET_ERROR_TYPE_DEBUG, " canceling old ACK\n"); 483 LOG (GNUNET_ERROR_TYPE_DEBUG, " canceling old ACK\n");
484 GMC_cancel (prev_fc->ack_msg); 484 GMC_cancel (prev_fc->ack_msg);
@@ -530,8 +530,8 @@ message_sent (void *cls,
530 fc = fwd ? &c->fwd_fc : &c->bck_fc; 530 fc = fwd ? &c->fwd_fc : &c->bck_fc;
531 LOG (GNUNET_ERROR_TYPE_DEBUG, 531 LOG (GNUNET_ERROR_TYPE_DEBUG,
532 "! sent %s %s\n", 532 "! sent %s %s\n",
533 fwd ? "FWD" : "BCK", 533 GM_f2s (fwd),
534 GNUNET_MESH_DEBUG_M2S (type)); 534 GM_m2s (type));
535 LOG (GNUNET_ERROR_TYPE_DEBUG, "! C_P- %p %u\n", c, c->pending_messages); 535 LOG (GNUNET_ERROR_TYPE_DEBUG, "! C_P- %p %u\n", c, c->pending_messages);
536 if (NULL != q) 536 if (NULL != q)
537 { 537 {
@@ -704,7 +704,7 @@ send_connection_ack (struct MeshConnection *connection, int fwd)
704 704
705 t = connection->t; 705 t = connection->t;
706 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection %s ACK\n", 706 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection %s ACK\n",
707 !fwd ? "FWD" : "BCK"); 707 !GM_f2s (fwd));
708 GMP_queue_add (get_hop (connection, fwd), NULL, 708 GMP_queue_add (get_hop (connection, fwd), NULL,
709 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK, 709 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK,
710 sizeof (struct GNUNET_MESH_ConnectionACK), 710 sizeof (struct GNUNET_MESH_ConnectionACK),
@@ -760,7 +760,7 @@ connection_keepalive (struct MeshConnection *c, int fwd)
760 760
761 LOG (GNUNET_ERROR_TYPE_DEBUG, 761 LOG (GNUNET_ERROR_TYPE_DEBUG,
762 "sending %s keepalive for connection %s]\n", 762 "sending %s keepalive for connection %s]\n",
763 fwd ? "FWD" : "BCK", GMC_2s (c)); 763 GM_f2s (fwd), GMC_2s (c));
764 764
765 msg = (struct GNUNET_MESH_ConnectionKeepAlive *) cbuf; 765 msg = (struct GNUNET_MESH_ConnectionKeepAlive *) cbuf;
766 msg->header.size = htons (size); 766 msg->header.size = htons (size);
@@ -876,7 +876,7 @@ connection_unlock_queue (struct MeshConnection *c, int fwd)
876 876
877 LOG (GNUNET_ERROR_TYPE_DEBUG, 877 LOG (GNUNET_ERROR_TYPE_DEBUG,
878 "connection_unlock_queue %s on %s\n", 878 "connection_unlock_queue %s on %s\n",
879 fwd ? "FWD" : "BCK", GMC_2s (c)); 879 GM_f2s (fwd), GMC_2s (c));
880 880
881 if (GMC_is_terminal (c, fwd)) 881 if (GMC_is_terminal (c, fwd))
882 { 882 {
@@ -906,7 +906,7 @@ connection_cancel_queues (struct MeshConnection *c, int fwd)
906 906
907 LOG (GNUNET_ERROR_TYPE_DEBUG, 907 LOG (GNUNET_ERROR_TYPE_DEBUG,
908 " *** Cancel %s queues for connection %s\n", 908 " *** Cancel %s queues for connection %s\n",
909 fwd ? "FWD" : "BCK", GMC_2s (c)); 909 GM_f2s (fwd), GMC_2s (c));
910 if (NULL == c) 910 if (NULL == c)
911 { 911 {
912 GNUNET_break (0); 912 GNUNET_break (0);
@@ -1564,7 +1564,7 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer,
1564 type = ntohs (msg->header.type); 1564 type = ntohs (msg->header.type);
1565 LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\n"); 1565 LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\n");
1566 LOG (GNUNET_ERROR_TYPE_DEBUG, "got a %s message (#%u) from %s\n", 1566 LOG (GNUNET_ERROR_TYPE_DEBUG, "got a %s message (#%u) from %s\n",
1567 GNUNET_MESH_DEBUG_M2S (type), ntohl (msg->pid), GNUNET_i2s (peer)); 1567 GM_m2s (type), ntohl (msg->pid), GNUNET_i2s (peer));
1568 1568
1569 /* Check connection */ 1569 /* Check connection */
1570 c = connection_get (&msg->cid); 1570 c = connection_get (&msg->cid);
@@ -1602,7 +1602,7 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer,
1602 /* Check PID */ 1602 /* Check PID */
1603 fc = fwd ? &c->bck_fc : &c->fwd_fc; 1603 fc = fwd ? &c->bck_fc : &c->fwd_fc;
1604 pid = ntohl (msg->pid); 1604 pid = ntohl (msg->pid);
1605 if (GMC_is_pid_bigger (pid, fc->last_ack_sent)) 1605 if (GM_is_pid_bigger (pid, fc->last_ack_sent))
1606 { 1606 {
1607 GNUNET_STATISTICS_update (stats, "# unsolicited message", 1, GNUNET_NO); 1607 GNUNET_STATISTICS_update (stats, "# unsolicited message", 1, GNUNET_NO);
1608 LOG (GNUNET_ERROR_TYPE_DEBUG, 1608 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1610,7 +1610,7 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer,
1610 pid, fc->last_pid_recv, fc->last_ack_sent); 1610 pid, fc->last_pid_recv, fc->last_ack_sent);
1611 return GNUNET_OK; 1611 return GNUNET_OK;
1612 } 1612 }
1613 if (GNUNET_NO == GMC_is_pid_bigger (pid, fc->last_pid_recv)) 1613 if (GNUNET_NO == GM_is_pid_bigger (pid, fc->last_pid_recv))
1614 { 1614 {
1615 GNUNET_STATISTICS_update (stats, "# duplicate PID", 1, GNUNET_NO); 1615 GNUNET_STATISTICS_update (stats, "# duplicate PID", 1, GNUNET_NO);
1616 LOG (GNUNET_ERROR_TYPE_DEBUG, 1616 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1691,7 +1691,7 @@ handle_mesh_kx (const struct GNUNET_PeerIdentity *peer,
1691 type = ntohs (msg->header.type); 1691 type = ntohs (msg->header.type);
1692 LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\n"); 1692 LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\n");
1693 LOG (GNUNET_ERROR_TYPE_DEBUG, "got a %s message from %s\n", 1693 LOG (GNUNET_ERROR_TYPE_DEBUG, "got a %s message from %s\n",
1694 GNUNET_MESH_DEBUG_M2S (type), GNUNET_i2s (peer)); 1694 GM_m2s (type), GNUNET_i2s (peer));
1695 1695
1696 /* Check connection */ 1696 /* Check connection */
1697 c = connection_get (&msg->cid); 1697 c = connection_get (&msg->cid);
@@ -1853,12 +1853,12 @@ GMC_handle_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
1853 ack = ntohl (msg->ack); 1853 ack = ntohl (msg->ack);
1854 LOG (GNUNET_ERROR_TYPE_DEBUG, " ACK %u (was %u)\n", 1854 LOG (GNUNET_ERROR_TYPE_DEBUG, " ACK %u (was %u)\n",
1855 ack, fc->last_ack_recv); 1855 ack, fc->last_ack_recv);
1856 if (GMC_is_pid_bigger (ack, fc->last_ack_recv)) 1856 if (GM_is_pid_bigger (ack, fc->last_ack_recv))
1857 fc->last_ack_recv = ack; 1857 fc->last_ack_recv = ack;
1858 1858
1859 /* Cancel polling if the ACK is big enough. */ 1859 /* Cancel polling if the ACK is big enough. */
1860 if (GNUNET_SCHEDULER_NO_TASK != fc->poll_task && 1860 if (GNUNET_SCHEDULER_NO_TASK != fc->poll_task &&
1861 GMC_is_pid_bigger (fc->last_ack_recv, fc->last_pid_sent)) 1861 GM_is_pid_bigger (fc->last_ack_recv, fc->last_pid_sent))
1862 { 1862 {
1863 LOG (GNUNET_ERROR_TYPE_DEBUG, " Cancel poll\n"); 1863 LOG (GNUNET_ERROR_TYPE_DEBUG, " Cancel poll\n");
1864 GNUNET_SCHEDULER_cancel (fc->poll_task); 1864 GNUNET_SCHEDULER_cancel (fc->poll_task);
@@ -2024,7 +2024,7 @@ GMC_send_ack (struct MeshConnection *c, int fwd, int force)
2024 2024
2025 LOG (GNUNET_ERROR_TYPE_DEBUG, 2025 LOG (GNUNET_ERROR_TYPE_DEBUG,
2026 "GMC send %s ACK on %s\n", 2026 "GMC send %s ACK on %s\n",
2027 fwd ? "FWD" : "BCK", GMC_2s (c)); 2027 GM_f2s (fwd), GMC_2s (c));
2028 2028
2029 if (NULL == c) 2029 if (NULL == c)
2030 { 2030 {
@@ -2342,7 +2342,7 @@ GMC_get_allowed (struct MeshConnection *c, int fwd)
2342 struct MeshFlowControl *fc; 2342 struct MeshFlowControl *fc;
2343 2343
2344 fc = fwd ? &c->fwd_fc : &c->bck_fc; 2344 fc = fwd ? &c->fwd_fc : &c->bck_fc;
2345 if (GMC_is_pid_bigger(fc->last_pid_recv, fc->last_ack_sent)) 2345 if (GM_is_pid_bigger(fc->last_pid_recv, fc->last_ack_sent))
2346 { 2346 {
2347 return 0; 2347 return 0;
2348 } 2348 }
@@ -2477,7 +2477,7 @@ GMC_is_sendable (struct MeshConnection *c, int fwd)
2477 struct MeshFlowControl *fc; 2477 struct MeshFlowControl *fc;
2478 2478
2479 fc = fwd ? &c->fwd_fc : &c->bck_fc; 2479 fc = fwd ? &c->fwd_fc : &c->bck_fc;
2480 if (GMC_is_pid_bigger (fc->last_ack_recv, fc->last_pid_sent)) 2480 if (GM_is_pid_bigger (fc->last_ack_recv, fc->last_pid_sent))
2481 return GNUNET_YES; 2481 return GNUNET_YES;
2482 return GNUNET_NO; 2482 return GNUNET_NO;
2483} 2483}
@@ -2514,7 +2514,7 @@ GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
2514 memcpy (data, message, size); 2514 memcpy (data, message, size);
2515 type = ntohs (message->type); 2515 type = ntohs (message->type);
2516 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send %s (%u bytes) on connection %s\n", 2516 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send %s (%u bytes) on connection %s\n",
2517 GNUNET_MESH_DEBUG_M2S (type), size, GMC_2s (c)); 2517 GM_m2s (type), size, GMC_2s (c));
2518 2518
2519 fc = fwd ? &c->fwd_fc : &c->bck_fc; 2519 fc = fwd ? &c->fwd_fc : &c->bck_fc;
2520 droppable = GNUNET_YES; 2520 droppable = GNUNET_YES;
@@ -2545,7 +2545,7 @@ GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
2545 LOG (GNUNET_ERROR_TYPE_DEBUG, "pid %u\n", ntohl (emsg->pid)); 2545 LOG (GNUNET_ERROR_TYPE_DEBUG, "pid %u\n", ntohl (emsg->pid));
2546 LOG (GNUNET_ERROR_TYPE_DEBUG, "last pid sent %u\n", fc->last_pid_sent); 2546 LOG (GNUNET_ERROR_TYPE_DEBUG, "last pid sent %u\n", fc->last_pid_sent);
2547 LOG (GNUNET_ERROR_TYPE_DEBUG, " ack recv %u\n", fc->last_ack_recv); 2547 LOG (GNUNET_ERROR_TYPE_DEBUG, " ack recv %u\n", fc->last_ack_recv);
2548 if (GMC_is_pid_bigger (fc->last_pid_sent + 1, fc->last_ack_recv)) 2548 if (GM_is_pid_bigger (fc->last_pid_sent + 1, fc->last_ack_recv))
2549 { 2549 {
2550 GMC_start_poll (c, fwd); 2550 GMC_start_poll (c, fwd);
2551 } 2551 }
@@ -2733,7 +2733,7 @@ GMC_start_poll (struct MeshConnection *c, int fwd)
2733 2733
2734 fc = fwd ? &c->fwd_fc : &c->bck_fc; 2734 fc = fwd ? &c->fwd_fc : &c->bck_fc;
2735 LOG (GNUNET_ERROR_TYPE_DEBUG, " *** POLL %s requested\n", 2735 LOG (GNUNET_ERROR_TYPE_DEBUG, " *** POLL %s requested\n",
2736 fwd ? "FWD" : "BCK"); 2736 GM_f2s (fwd));
2737 if (GNUNET_SCHEDULER_NO_TASK != fc->poll_task || NULL != fc->poll_msg) 2737 if (GNUNET_SCHEDULER_NO_TASK != fc->poll_task || NULL != fc->poll_msg)
2738 { 2738 {
2739 LOG (GNUNET_ERROR_TYPE_DEBUG, " *** not needed (%u, %p)\n", 2739 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)
814 case GNUNET_MESSAGE_TYPE_MESH_POLL: 814 case GNUNET_MESSAGE_TYPE_MESH_POLL:
815 LOG (GNUNET_ERROR_TYPE_DEBUG, 815 LOG (GNUNET_ERROR_TYPE_DEBUG,
816 "* raw: %s\n", 816 "* raw: %s\n",
817 GNUNET_MESH_DEBUG_M2S (queue->type)); 817 GM_m2s (queue->type));
818 data_size = send_core_data_raw (queue->cls, size, buf); 818 data_size = send_core_data_raw (queue->cls, size, buf);
819 break; 819 break;
820 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE: 820 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE:
@@ -850,7 +850,7 @@ queue_send (void *cls, size_t size, void *buf)
850 { 850 {
851 LOG (GNUNET_ERROR_TYPE_WARNING, 851 LOG (GNUNET_ERROR_TYPE_WARNING,
852 "Dropping message of type %s\n", 852 "Dropping message of type %s\n",
853 GNUNET_MESH_DEBUG_M2S (queue->type)); 853 GM_m2s (queue->type));
854 data_size = 0; 854 data_size = 0;
855 } 855 }
856 856
@@ -915,7 +915,7 @@ GMP_queue_destroy (struct MeshPeerQueue *queue, int clear_cls)
915 if (GNUNET_YES == clear_cls) 915 if (GNUNET_YES == clear_cls)
916 { 916 {
917 LOG (GNUNET_ERROR_TYPE_DEBUG, "# queue destroy type %s\n", 917 LOG (GNUNET_ERROR_TYPE_DEBUG, "# queue destroy type %s\n",
918 GNUNET_MESH_DEBUG_M2S (queue->type)); 918 GM_m2s (queue->type));
919 switch (queue->type) 919 switch (queue->type)
920 { 920 {
921 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY: 921 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY:
@@ -934,7 +934,7 @@ GMP_queue_destroy (struct MeshPeerQueue *queue, int clear_cls)
934 default: 934 default:
935 GNUNET_break (0); 935 GNUNET_break (0);
936 LOG (GNUNET_ERROR_TYPE_ERROR, "# type %s unknown!\n", 936 LOG (GNUNET_ERROR_TYPE_ERROR, "# type %s unknown!\n",
937 GNUNET_MESH_DEBUG_M2S (queue->type)); 937 GM_m2s (queue->type));
938 } 938 }
939 } 939 }
940 GNUNET_CONTAINER_DLL_remove (peer->queue_head, peer->queue_tail, queue); 940 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,
985 985
986 LOG (GNUNET_ERROR_TYPE_DEBUG, 986 LOG (GNUNET_ERROR_TYPE_DEBUG,
987 "queue add %s %s towards %s (size %u) on c %p (%s)\n", 987 "queue add %s %s towards %s (size %u) on c %p (%s)\n",
988 fwd ? "FWD" : "BCK", GNUNET_MESH_DEBUG_M2S (type), GMP_2s(peer), 988 GM_f2s (fwd), GM_m2s (type), GMP_2s(peer),
989 size, c, GMC_2s (c)); 989 size, c, GMC_2s (c));
990 GNUNET_assert (NULL != c); 990 GNUNET_assert (NULL != c);
991 991
@@ -1075,7 +1075,7 @@ GMP_queue_cancel (struct MeshPeer *peer, struct MeshConnection *c)
1075 { 1075 {
1076 LOG (GNUNET_ERROR_TYPE_DEBUG, 1076 LOG (GNUNET_ERROR_TYPE_DEBUG,
1077 "GMP_cancel_queue %s\n", 1077 "GMP_cancel_queue %s\n",
1078 GNUNET_MESH_DEBUG_M2S (q->type)); 1078 GM_m2s (q->type));
1079 GMP_queue_destroy (q, GNUNET_YES); 1079 GMP_queue_destroy (q, GNUNET_YES);
1080 1080
1081 /* Get next from prev, q->next might be already freed: 1081 /* 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,
736 break; 736 break;
737 default: 737 default:
738 LOG (GNUNET_ERROR_TYPE_DEBUG, "unkown type %s\n", 738 LOG (GNUNET_ERROR_TYPE_DEBUG, "unkown type %s\n",
739 GNUNET_MESH_DEBUG_M2S (type)); 739 GM_m2s (type));
740 GNUNET_break (0); 740 GNUNET_break (0);
741 } 741 }
742 742
@@ -977,7 +977,7 @@ handle_data (struct MeshTunnel3 *t,
977 return; 977 return;
978 } 978 }
979 LOG (GNUNET_ERROR_TYPE_DEBUG, " payload of type %s\n", 979 LOG (GNUNET_ERROR_TYPE_DEBUG, " payload of type %s\n",
980 GNUNET_MESH_DEBUG_M2S (ntohs (msg[1].header.type))); 980 GM_m2s (ntohs (msg[1].header.type)));
981 981
982 /* Check channel */ 982 /* Check channel */
983 ch = GMT_get_channel (t, ntohl (msg->chid)); 983 ch = GMT_get_channel (t, ntohl (msg->chid));
@@ -1314,7 +1314,7 @@ handle_decrypted (struct MeshTunnel3 *t,
1314 type = ntohs (msgh->type); 1314 type = ntohs (msgh->type);
1315 LOG (GNUNET_ERROR_TYPE_DEBUG, 1315 LOG (GNUNET_ERROR_TYPE_DEBUG,
1316 "Got a %s message!\n", 1316 "Got a %s message!\n",
1317 GNUNET_MESH_DEBUG_M2S (type)); 1317 GM_m2s (type));
1318 1318
1319 switch (type) 1319 switch (type)
1320 { 1320 {
@@ -2213,7 +2213,7 @@ GMT_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
2213 break; 2213 break;
2214 default: 2214 default:
2215 LOG (GNUNET_ERROR_TYPE_DEBUG, "unkown type %s\n", 2215 LOG (GNUNET_ERROR_TYPE_DEBUG, "unkown type %s\n",
2216 GNUNET_MESH_DEBUG_M2S (type)); 2216 GM_m2s (type));
2217 GNUNET_break (0); 2217 GNUNET_break (0);
2218 } 2218 }
2219 2219
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
@@ -200,6 +200,17 @@ GNUNET_NETWORK_STRUCT_END
200 200
201 201
202/** 202/**
203 * @brief Translate a fwd variable into a string representation, for logging.
204 *
205 * @param fwd Is FWD? (#GNUNET_YES or #GNUNET_NO)
206 *
207 * @return String representing FWD or BCK.
208 */
209char *
210GM_f2s (int fwd);
211
212
213/**
203 * Check if one pid is bigger than other, accounting for overflow. 214 * Check if one pid is bigger than other, accounting for overflow.
204 * 215 *
205 * @param bigger Argument that should be bigger. 216 * @param bigger Argument that should be bigger.
@@ -208,7 +219,7 @@ GNUNET_NETWORK_STRUCT_END
208 * @return True if bigger (arg1) has a higher value than smaller (arg 2). 219 * @return True if bigger (arg1) has a higher value than smaller (arg 2).
209 */ 220 */
210int 221int
211GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller); 222GM_is_pid_bigger (uint32_t bigger, uint32_t smaller);
212 223
213 224
214/** 225/**
@@ -220,7 +231,7 @@ GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller);
220 * @return Highest ACK value from the two. 231 * @return Highest ACK value from the two.
221 */ 232 */
222uint32_t 233uint32_t
223GMC_max_pid (uint32_t a, uint32_t b); 234GM_max_pid (uint32_t a, uint32_t b);
224 235
225 236
226/** 237/**
@@ -232,7 +243,7 @@ GMC_max_pid (uint32_t a, uint32_t b);
232 * @return Lowest ACK value from the two. 243 * @return Lowest ACK value from the two.
233 */ 244 */
234uint32_t 245uint32_t
235GMC_min_pid (uint32_t a, uint32_t b); 246GM_min_pid (uint32_t a, uint32_t b);
236 247
237 248
238/** 249/**
@@ -246,7 +257,7 @@ GMC_min_pid (uint32_t a, uint32_t b);
246 * @return Human readable string description. 257 * @return Human readable string description.
247 */ 258 */
248const char * 259const char *
249GNUNET_MESH_DEBUG_M2S (uint16_t m); 260GM_m2s (uint16_t m);
250 261
251#if 0 /* keep Emacsens' auto-indent happy */ 262#if 0 /* keep Emacsens' auto-indent happy */
252{ 263{
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)
1054 type = ntohs (msg->type); 1054 type = ntohs (msg->type);
1055 LOG (GNUNET_ERROR_TYPE_DEBUG, "\n"); 1055 LOG (GNUNET_ERROR_TYPE_DEBUG, "\n");
1056 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received a message: %s\n", 1056 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received a message: %s\n",
1057 GNUNET_MESH_DEBUG_M2S (type)); 1057 GM_m2s (type));
1058 switch (type) 1058 switch (type)
1059 { 1059 {
1060 /* Notify of a new incoming channel */ 1060 /* Notify of a new incoming channel */
@@ -1082,7 +1082,7 @@ msg_received (void *cls, const struct GNUNET_MessageHeader *msg)
1082 /* We shouldn't get any other packages, log and ignore */ 1082 /* We shouldn't get any other packages, log and ignore */
1083 LOG (GNUNET_ERROR_TYPE_WARNING, 1083 LOG (GNUNET_ERROR_TYPE_WARNING,
1084 "unsolicited message form service (type %s)\n", 1084 "unsolicited message form service (type %s)\n",
1085 GNUNET_MESH_DEBUG_M2S (ntohs (msg->type))); 1085 GM_m2s (ntohs (msg->type)));
1086 } 1086 }
1087 LOG (GNUNET_ERROR_TYPE_DEBUG, "message processed\n"); 1087 LOG (GNUNET_ERROR_TYPE_DEBUG, "message processed\n");
1088 if (GNUNET_YES == h->in_receive) 1088 if (GNUNET_YES == h->in_receive)
@@ -1166,7 +1166,7 @@ send_callback (void *cls, size_t size, void *buf)
1166 dmsg->id = htonl (ch->chid); 1166 dmsg->id = htonl (ch->chid);
1167 dmsg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA); 1167 dmsg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA);
1168 LOG (GNUNET_ERROR_TYPE_DEBUG, "# payload type %s\n", 1168 LOG (GNUNET_ERROR_TYPE_DEBUG, "# payload type %s\n",
1169 GNUNET_MESH_DEBUG_M2S (ntohs (mh->type))); 1169 GM_m2s (ntohs (mh->type)));
1170 ch->allow_send = GNUNET_NO; 1170 ch->allow_send = GNUNET_NO;
1171 } 1171 }
1172 else 1172 else
@@ -1181,7 +1181,7 @@ send_callback (void *cls, size_t size, void *buf)
1181 struct GNUNET_MessageHeader *mh = (struct GNUNET_MessageHeader *) &th[1]; 1181 struct GNUNET_MessageHeader *mh = (struct GNUNET_MessageHeader *) &th[1];
1182 1182
1183 LOG (GNUNET_ERROR_TYPE_DEBUG, "# mesh internal traffic, type %s\n", 1183 LOG (GNUNET_ERROR_TYPE_DEBUG, "# mesh internal traffic, type %s\n",
1184 GNUNET_MESH_DEBUG_M2S (ntohs (mh->type))); 1184 GM_m2s (ntohs (mh->type)));
1185 memcpy (cbuf, &th[1], th->size); 1185 memcpy (cbuf, &th[1], th->size);
1186 psize = th->size; 1186 psize = th->size;
1187 } 1187 }
@@ -1243,7 +1243,7 @@ send_packet (struct GNUNET_MESH_Handle *h,
1243 size_t msize; 1243 size_t msize;
1244 1244
1245 LOG (GNUNET_ERROR_TYPE_DEBUG, " Sending message to service: %s\n", 1245 LOG (GNUNET_ERROR_TYPE_DEBUG, " Sending message to service: %s\n",
1246 GNUNET_MESH_DEBUG_M2S(ntohs(msg->type))); 1246 GM_m2s(ntohs(msg->type)));
1247 msize = ntohs (msg->size); 1247 msize = ntohs (msg->size);
1248 th = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle) + msize); 1248 th = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle) + msize);
1249 th->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; 1249 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 @@
26 26
27#include "mesh.h" 27#include "mesh.h"
28 28
29/**
30 * @brief Translate a fwd variable into a string representation, for logging.
31 *
32 * @param fwd Is FWD? (#GNUNET_YES or #GNUNET_NO)
33 *
34 * @return String representing FWD or BCK.
35 */
36char *
37GM_f2s (int fwd)
38{
39 if (GNUNET_YES == fwd)
40 {
41 return "FWD";
42 }
43 else if (GNUNET_NO == fwd)
44 {
45 return "BCK";
46 }
47 else
48 {
49 GNUNET_break (0);
50 return "";
51 }
52}
29 53
30int 54int
31GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller) 55GM_is_pid_bigger (uint32_t bigger, uint32_t smaller)
32{ 56{
33 return (GNUNET_YES == PID_OVERFLOW (smaller, bigger) || 57 return (GNUNET_YES == PID_OVERFLOW (smaller, bigger) ||
34 (bigger > smaller && GNUNET_NO == PID_OVERFLOW (bigger, smaller))); 58 (bigger > smaller && GNUNET_NO == PID_OVERFLOW (bigger, smaller)));
@@ -36,18 +60,18 @@ GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller)
36 60
37 61
38uint32_t 62uint32_t
39GMC_max_pid (uint32_t a, uint32_t b) 63GM_max_pid (uint32_t a, uint32_t b)
40{ 64{
41 if (GMC_is_pid_bigger(a, b)) 65 if (GM_is_pid_bigger(a, b))
42 return a; 66 return a;
43 return b; 67 return b;
44} 68}
45 69
46 70
47uint32_t 71uint32_t
48GMC_min_pid (uint32_t a, uint32_t b) 72GM_min_pid (uint32_t a, uint32_t b)
49{ 73{
50 if (GMC_is_pid_bigger(a, b)) 74 if (GM_is_pid_bigger(a, b))
51 return b; 75 return b;
52 return a; 76 return a;
53} 77}
@@ -55,7 +79,7 @@ GMC_min_pid (uint32_t a, uint32_t b)
55 79
56#if !defined(GNUNET_CULL_LOGGING) 80#if !defined(GNUNET_CULL_LOGGING)
57const char * 81const char *
58GNUNET_MESH_DEBUG_M2S (uint16_t m) 82GM_m2s (uint16_t m)
59{ 83{
60 static char buf[32]; 84 static char buf[32];
61 switch (m) 85 switch (m)
@@ -185,7 +209,7 @@ GNUNET_MESH_DEBUG_M2S (uint16_t m)
185} 209}
186#else 210#else
187const char * 211const char *
188GNUNET_MESH_DEBUG_M2S (uint16_t m) 212GM_m2s (uint16_t m)
189{ 213{
190 return ""; 214 return "";
191} 215}