aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2014-05-07 10:42:51 +0000
committerBart Polot <bart@net.in.tum.de>2014-05-07 10:42:51 +0000
commit087f0e8e1768db05cb5b8cd668c47c7667df1982 (patch)
treee6fdf6ccca2cad58da5d53650c442d6e28d6c537 /src/mesh
parentee677929b0582716e218bb97e4d7f7aca5bf8bb8 (diff)
downloadgnunet-087f0e8e1768db05cb5b8cd668c47c7667df1982.tar.gz
gnunet-087f0e8e1768db05cb5b8cd668c47c7667df1982.zip
- Eliminate next_pid
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh_connection.c47
-rw-r--r--src/mesh/gnunet-service-mesh_peer.c24
-rw-r--r--src/mesh/gnunet-service-mesh_peer.h7
3 files changed, 35 insertions, 43 deletions
diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c
index b043615ed..31c225ee9 100644
--- a/src/mesh/gnunet-service-mesh_connection.c
+++ b/src/mesh/gnunet-service-mesh_connection.c
@@ -71,11 +71,6 @@ struct MeshFlowControl
71 unsigned int queue_max; 71 unsigned int queue_max;
72 72
73 /** 73 /**
74 * Next ID to use.
75 */
76 uint32_t next_pid;
77
78 /**
79 * ID of the last packet sent towards the peer. 74 * ID of the last packet sent towards the peer.
80 */ 75 */
81 uint32_t last_pid_sent; 76 uint32_t last_pid_sent;
@@ -239,11 +234,6 @@ struct MeshConnectionQueue
239 int forced; 234 int forced;
240 235
241 /** 236 /**
242 * Packet ID of the message, if relevant.
243 */
244 uint32_t pid;
245
246 /**
247 * Continuation to call once sent. 237 * Continuation to call once sent.
248 */ 238 */
249 GMC_sent cont; 239 GMC_sent cont;
@@ -400,7 +390,6 @@ GMC_state2s (enum MeshConnectionState s)
400static void 390static void
401fc_init (struct MeshFlowControl *fc) 391fc_init (struct MeshFlowControl *fc)
402{ 392{
403 fc->next_pid = 0;
404 fc->last_pid_sent = (uint32_t) -1; /* Next (expected) = 0 */ 393 fc->last_pid_sent = (uint32_t) -1; /* Next (expected) = 0 */
405 fc->last_pid_recv = (uint32_t) -1; 394 fc->last_pid_recv = (uint32_t) -1;
406 fc->last_ack_sent = (uint32_t) 0; 395 fc->last_ack_sent = (uint32_t) 0;
@@ -557,7 +546,7 @@ send_ack (struct MeshConnection *c, unsigned int buffer, int fwd, int force)
557 546
558 547
559/** 548/**
560 * Callback called when a queued message is sent. 549 * Callback called when a connection queued message is sent.
561 * 550 *
562 * Calculates the average time and connection packet tracking. 551 * Calculates the average time and connection packet tracking.
563 * 552 *
@@ -565,32 +554,30 @@ send_ack (struct MeshConnection *c, unsigned int buffer, int fwd, int force)
565 * @param c Connection this message was on. 554 * @param c Connection this message was on.
566 * @param sent Was it really sent? (Could have been canceled) 555 * @param sent Was it really sent? (Could have been canceled)
567 * @param type Type of message sent. 556 * @param type Type of message sent.
557 * @param pid Packet ID, or 0 if not applicable (create, destroy, etc).
568 * @param fwd Was this a FWD going message? 558 * @param fwd Was this a FWD going message?
569 * @param size Size of the message. 559 * @param size Size of the message.
570 * @param wait Time spent waiting for core (only the time for THIS message) 560 * @param wait Time spent waiting for core (only the time for THIS message)
571 */ 561 */
572static void 562static void
573message_sent (void *cls, 563conn_message_sent (void *cls,
574 struct MeshConnection *c, int sent, 564 struct MeshConnection *c, int sent,
575 uint16_t type, int fwd, size_t size, 565 uint16_t type, uint32_t pid, int fwd, size_t size,
576 struct GNUNET_TIME_Relative wait) 566 struct GNUNET_TIME_Relative wait)
577{ 567{
578 struct MeshConnectionPerformance *p; 568 struct MeshConnectionPerformance *p;
579 struct MeshFlowControl *fc; 569 struct MeshFlowControl *fc;
580 struct MeshConnectionQueue *q = cls; 570 struct MeshConnectionQueue *q = cls;
581 double usecsperbyte; 571 double usecsperbyte;
582 int forced; 572 int forced;
583 uint32_t pid;
584 573
585 LOG (GNUNET_ERROR_TYPE_DEBUG, "connection message_sent\n"); 574 LOG (GNUNET_ERROR_TYPE_DEBUG, "connection message_sent\n");
586 575
587 fc = fwd ? &c->fwd_fc : &c->bck_fc; 576 fc = fwd ? &c->fwd_fc : &c->bck_fc;
588 pid = 0;
589 LOG (GNUNET_ERROR_TYPE_DEBUG, " %ssent %s %s\n", 577 LOG (GNUNET_ERROR_TYPE_DEBUG, " %ssent %s %s\n",
590 sent ? "" : "not ", GM_f2s (fwd), GM_m2s (type)); 578 sent ? "" : "not ", GM_f2s (fwd), GM_m2s (type));
591 if (NULL != q) 579 if (NULL != q)
592 { 580 {
593 pid = q->pid;
594 forced = q->forced; 581 forced = q->forced;
595 if (NULL != q->cont) 582 if (NULL != q->cont)
596 { 583 {
@@ -639,7 +626,7 @@ message_sent (void *cls,
639 if (GNUNET_YES == sent) 626 if (GNUNET_YES == sent)
640 { 627 {
641 GNUNET_assert (NULL != q); 628 GNUNET_assert (NULL != q);
642 fc->last_pid_sent = pid; 629 fc->last_pid_sent = pid; // FIXME
643 GMC_send_ack (c, fwd, GNUNET_NO); 630 GMC_send_ack (c, fwd, GNUNET_NO);
644 connection_reset_timeout (c, fwd); 631 connection_reset_timeout (c, fwd);
645 } 632 }
@@ -821,7 +808,7 @@ send_connection_ack (struct MeshConnection *connection, int fwd)
821 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK, 808 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK,
822 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK, 0, 809 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK, 0,
823 sizeof (struct GNUNET_MESH_ConnectionACK), 810 sizeof (struct GNUNET_MESH_ConnectionACK),
824 connection, fwd, &message_sent, NULL); 811 connection, fwd, &conn_message_sent, NULL);
825 connection->pending_messages++; 812 connection->pending_messages++;
826 if (MESH_TUNNEL3_NEW == GMT_get_cstate (t)) 813 if (MESH_TUNNEL3_NEW == GMT_get_cstate (t))
827 GMT_change_cstate (t, MESH_TUNNEL3_WAITING); 814 GMT_change_cstate (t, MESH_TUNNEL3_WAITING);
@@ -2841,8 +2828,8 @@ GMC_is_sendable (struct MeshConnection *c, int fwd)
2841 } 2828 }
2842 fc = fwd ? &c->fwd_fc : &c->bck_fc; 2829 fc = fwd ? &c->fwd_fc : &c->bck_fc;
2843 LOG (GNUNET_ERROR_TYPE_DEBUG, 2830 LOG (GNUNET_ERROR_TYPE_DEBUG,
2844 " last ack recv: %u, last pid sent: %u, next pid %u\n", 2831 " last ack recv: %u, last pid sent: %u\n",
2845 fc->last_ack_recv, fc->last_pid_sent, fc->next_pid); 2832 fc->last_ack_recv, fc->last_pid_sent);
2846 if (GM_is_pid_bigger (fc->last_ack_recv, fc->last_pid_sent)) 2833 if (GM_is_pid_bigger (fc->last_ack_recv, fc->last_pid_sent))
2847 { 2834 {
2848 LOG (GNUNET_ERROR_TYPE_DEBUG, " sendable\n"); 2835 LOG (GNUNET_ERROR_TYPE_DEBUG, " sendable\n");
@@ -2891,7 +2878,6 @@ GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
2891{ 2878{
2892 struct MeshFlowControl *fc; 2879 struct MeshFlowControl *fc;
2893 struct MeshConnectionQueue *q; 2880 struct MeshConnectionQueue *q;
2894 uint32_t pid;
2895 void *data; 2881 void *data;
2896 size_t size; 2882 size_t size;
2897 uint16_t type; 2883 uint16_t type;
@@ -2906,7 +2892,6 @@ GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
2906 2892
2907 fc = fwd ? &c->fwd_fc : &c->bck_fc; 2893 fc = fwd ? &c->fwd_fc : &c->bck_fc;
2908 droppable = GNUNET_NO == force; 2894 droppable = GNUNET_NO == force;
2909 pid = 0;
2910 switch (type) 2895 switch (type)
2911 { 2896 {
2912 struct GNUNET_MESH_Encrypted *emsg; 2897 struct GNUNET_MESH_Encrypted *emsg;
@@ -2928,10 +2913,8 @@ GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
2928 } 2913 }
2929 emsg->cid = c->id; 2914 emsg->cid = c->id;
2930 emsg->ttl = htonl (ttl - 1); 2915 emsg->ttl = htonl (ttl - 1);
2931 pid = fc->next_pid++; 2916 emsg->pid = htonl (0);
2932 emsg->pid = htonl (pid);
2933 LOG (GNUNET_ERROR_TYPE_DEBUG, " Q_N+ %p %u\n", fc, fc->queue_n); 2917 LOG (GNUNET_ERROR_TYPE_DEBUG, " Q_N+ %p %u\n", fc, fc->queue_n);
2934 LOG (GNUNET_ERROR_TYPE_DEBUG, "pid %u\n", pid);
2935 LOG (GNUNET_ERROR_TYPE_DEBUG, "last pid sent %u\n", fc->last_pid_sent); 2918 LOG (GNUNET_ERROR_TYPE_DEBUG, "last pid sent %u\n", fc->last_pid_sent);
2936 LOG (GNUNET_ERROR_TYPE_DEBUG, " ack recv %u\n", fc->last_ack_recv); 2919 LOG (GNUNET_ERROR_TYPE_DEBUG, " ack recv %u\n", fc->last_ack_recv);
2937 if (GNUNET_YES == droppable) 2920 if (GNUNET_YES == droppable)
@@ -3001,7 +2984,6 @@ GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
3001 if (GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED == type) 2984 if (GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED == type)
3002 { 2985 {
3003 fc->queue_n--; 2986 fc->queue_n--;
3004 fc->next_pid--;
3005 } 2987 }
3006 GNUNET_free (data); 2988 GNUNET_free (data);
3007 return NULL; /* Drop this message */ 2989 return NULL; /* Drop this message */
@@ -3012,9 +2994,8 @@ GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
3012 2994
3013 q = GNUNET_new (struct MeshConnectionQueue); 2995 q = GNUNET_new (struct MeshConnectionQueue);
3014 q->forced = !droppable; 2996 q->forced = !droppable;
3015 q->pid = pid;
3016 q->q = GMP_queue_add (get_hop (c, fwd), data, type, payload_type, payload_id, 2997 q->q = GMP_queue_add (get_hop (c, fwd), data, type, payload_type, payload_id,
3017 size, c, fwd, &message_sent, q); 2998 size, c, fwd, &conn_message_sent, q);
3018 if (NULL == q->q) 2999 if (NULL == q->q)
3019 { 3000 {
3020 LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING dropping msg on %s\n", GMC_2s (c)); 3001 LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING dropping msg on %s\n", GMC_2s (c));
@@ -3043,7 +3024,7 @@ GMC_cancel (struct MeshConnectionQueue *q)
3043 LOG (GNUNET_ERROR_TYPE_DEBUG, "! GMC cancel message\n"); 3024 LOG (GNUNET_ERROR_TYPE_DEBUG, "! GMC cancel message\n");
3044 3025
3045 /* queue destroy calls message_sent, which calls q->cont and frees q */ 3026 /* queue destroy calls message_sent, which calls q->cont and frees q */
3046 GMP_queue_destroy (q->q, GNUNET_YES, GNUNET_NO); 3027 GMP_queue_destroy (q->q, GNUNET_YES, GNUNET_NO, 0);
3047} 3028}
3048 3029
3049 3030
@@ -3073,7 +3054,7 @@ GMC_send_create (struct MeshConnection *connection)
3073 GMP_queue_add (get_next_hop (connection), NULL, 3054 GMP_queue_add (get_next_hop (connection), NULL,
3074 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE, 3055 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE,
3075 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE, 0, 3056 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE, 0,
3076 size, connection, GNUNET_YES, &message_sent, NULL); 3057 size, connection, GNUNET_YES, &conn_message_sent, NULL);
3077 3058
3078 state = GMT_get_cstate (connection->t); 3059 state = GMT_get_cstate (connection->t);
3079 if (MESH_TUNNEL3_SEARCHING == state || MESH_TUNNEL3_NEW == state) 3060 if (MESH_TUNNEL3_SEARCHING == state || MESH_TUNNEL3_NEW == state)
diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c
index 99f8eb07d..fce548f8e 100644
--- a/src/mesh/gnunet-service-mesh_peer.c
+++ b/src/mesh/gnunet-service-mesh_peer.c
@@ -905,7 +905,9 @@ queue_send (void *cls, size_t size, void *buf)
905 struct MeshPeerQueue *queue; 905 struct MeshPeerQueue *queue;
906 const struct GNUNET_PeerIdentity *dst_id; 906 const struct GNUNET_PeerIdentity *dst_id;
907 size_t data_size; 907 size_t data_size;
908 uint32_t pid;
908 909
910 pid = 0;
909 peer->core_transmit = NULL; 911 peer->core_transmit = NULL;
910 LOG (GNUNET_ERROR_TYPE_DEBUG, "Queue send towards %s (max %u)\n", 912 LOG (GNUNET_ERROR_TYPE_DEBUG, "Queue send towards %s (max %u)\n",
911 GMP_2s (peer), size); 913 GMP_2s (peer), size);
@@ -926,7 +928,8 @@ queue_send (void *cls, size_t size, void *buf)
926 c = queue->c; 928 c = queue->c;
927 929
928 dst_id = GNUNET_PEER_resolve2 (peer->id); 930 dst_id = GNUNET_PEER_resolve2 (peer->id);
929 LOG (GNUNET_ERROR_TYPE_DEBUG, " on connection %s\n", GMC_2s (c)); 931 LOG (GNUNET_ERROR_TYPE_DEBUG, " on connection %s %s\n",
932 GMC_2s (c), GM_f2s(queue->fwd));
930 /* Check if buffer size is enough for the message */ 933 /* Check if buffer size is enough for the message */
931 if (queue->size > size) 934 if (queue->size > size)
932 { 935 {
@@ -947,9 +950,12 @@ queue_send (void *cls, size_t size, void *buf)
947 /* Fill buf */ 950 /* Fill buf */
948 switch (queue->type) 951 switch (queue->type)
949 { 952 {
953 case GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED:
954 pid = GMC_get_pid (queue->c, queue->fwd);
955 LOG (GNUNET_ERROR_TYPE_DEBUG, " payload ID %u\n", pid);
956 /* fall-through */
950 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY: 957 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY:
951 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN: 958 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN:
952 case GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED:
953 case GNUNET_MESSAGE_TYPE_MESH_KX: 959 case GNUNET_MESSAGE_TYPE_MESH_KX:
954 case GNUNET_MESSAGE_TYPE_MESH_ACK: 960 case GNUNET_MESSAGE_TYPE_MESH_ACK:
955 case GNUNET_MESSAGE_TYPE_MESH_POLL: 961 case GNUNET_MESSAGE_TYPE_MESH_POLL:
@@ -1000,7 +1006,7 @@ queue_send (void *cls, size_t size, void *buf)
1000 } 1006 }
1001 1007
1002 /* Free queue, but cls was freed by send_core_* */ 1008 /* Free queue, but cls was freed by send_core_* */
1003 GMP_queue_destroy (queue, GNUNET_NO, GNUNET_YES); 1009 GMP_queue_destroy (queue, GNUNET_NO, GNUNET_YES, pid);
1004 1010
1005 /* If more data in queue, send next */ 1011 /* If more data in queue, send next */
1006 queue = peer_get_first_message (peer); 1012 queue = peer_get_first_message (peer);
@@ -1049,9 +1055,11 @@ queue_send (void *cls, size_t size, void *buf)
1049 * @param queue Queue handler to cancel. 1055 * @param queue Queue handler to cancel.
1050 * @param clear_cls Is it necessary to free associated cls? 1056 * @param clear_cls Is it necessary to free associated cls?
1051 * @param sent Was it really sent? (Could have been canceled) 1057 * @param sent Was it really sent? (Could have been canceled)
1058 * @param pid PID, if relevant (was sent and was a payload message).
1052 */ 1059 */
1053void 1060void
1054GMP_queue_destroy (struct MeshPeerQueue *queue, int clear_cls, int sent) 1061GMP_queue_destroy (struct MeshPeerQueue *queue, int clear_cls,
1062 int sent, uint32_t pid)
1055{ 1063{
1056 struct MeshPeer *peer; 1064 struct MeshPeer *peer;
1057 1065
@@ -1095,7 +1103,7 @@ GMP_queue_destroy (struct MeshPeerQueue *queue, int clear_cls, int sent)
1095 { 1103 {
1096 LOG (GNUNET_ERROR_TYPE_DEBUG, " calling callback\n"); 1104 LOG (GNUNET_ERROR_TYPE_DEBUG, " calling callback\n");
1097 queue->callback (queue->callback_cls, 1105 queue->callback (queue->callback_cls,
1098 queue->c, sent, queue->type, 1106 queue->c, sent, queue->type, pid,
1099 queue->fwd, queue->size, 1107 queue->fwd, queue->size,
1100 GNUNET_TIME_absolute_get_duration (queue->start_waiting)); 1108 GNUNET_TIME_absolute_get_duration (queue->start_waiting));
1101 } 1109 }
@@ -1241,7 +1249,7 @@ GMP_queue_cancel (struct MeshPeer *peer, struct MeshConnection *c)
1241 } 1249 }
1242 else 1250 else
1243 { 1251 {
1244 GMP_queue_destroy (q, GNUNET_YES, GNUNET_NO); 1252 GMP_queue_destroy (q, GNUNET_YES, GNUNET_NO, 0);
1245 } 1253 }
1246 1254
1247 /* Get next from prev, q->next might be already freed: 1255 /* Get next from prev, q->next might be already freed:
@@ -1326,13 +1334,13 @@ GMP_connection_pop (struct MeshPeer *peer, struct MeshConnection *c)
1326 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN: 1334 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN:
1327 case GNUNET_MESSAGE_TYPE_MESH_ACK: 1335 case GNUNET_MESSAGE_TYPE_MESH_ACK:
1328 case GNUNET_MESSAGE_TYPE_MESH_POLL: 1336 case GNUNET_MESSAGE_TYPE_MESH_POLL:
1329 GMP_queue_destroy (q, GNUNET_YES, GNUNET_NO); 1337 GMP_queue_destroy (q, GNUNET_YES, GNUNET_NO, 0);
1330 continue; 1338 continue;
1331 1339
1332 case GNUNET_MESSAGE_TYPE_MESH_KX: 1340 case GNUNET_MESSAGE_TYPE_MESH_KX:
1333 case GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED: 1341 case GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED:
1334 msg = (struct GNUNET_MessageHeader *) q->cls; 1342 msg = (struct GNUNET_MessageHeader *) q->cls;
1335 GMP_queue_destroy (q, GNUNET_NO, GNUNET_NO); 1343 GMP_queue_destroy (q, GNUNET_NO, GNUNET_NO, 0);
1336 return msg; 1344 return msg;
1337 1345
1338 default: 1346 default:
diff --git a/src/mesh/gnunet-service-mesh_peer.h b/src/mesh/gnunet-service-mesh_peer.h
index 153e8a15d..57f5212b0 100644
--- a/src/mesh/gnunet-service-mesh_peer.h
+++ b/src/mesh/gnunet-service-mesh_peer.h
@@ -59,13 +59,14 @@ struct MeshPeerQueue;
59 * @param c Connection this message was on. 59 * @param c Connection this message was on.
60 * @param sent Was it really sent? (Could have been canceled) 60 * @param sent Was it really sent? (Could have been canceled)
61 * @param type Type of message sent. 61 * @param type Type of message sent.
62 * @param pid Packet ID, or 0 if not applicable (create, destroy, etc).
62 * @param fwd Was this a FWD going message? 63 * @param fwd Was this a FWD going message?
63 * @param size Size of the message. 64 * @param size Size of the message.
64 * @param wait Time spent waiting for core (only the time for THIS message) 65 * @param wait Time spent waiting for core (only the time for THIS message)
65 */ 66 */
66typedef void (*GMP_sent) (void *cls, 67typedef void (*GMP_sent) (void *cls,
67 struct MeshConnection *c, int sent, 68 struct MeshConnection *c, int sent,
68 uint16_t type, int fwd, size_t size, 69 uint16_t type, uint32_t pid, int fwd, size_t size,
69 struct GNUNET_TIME_Relative wait); 70 struct GNUNET_TIME_Relative wait);
70 71
71/******************************************************************************/ 72/******************************************************************************/
@@ -127,9 +128,11 @@ GMP_connect (struct MeshPeer *peer);
127 * @param queue Queue handler to cancel. 128 * @param queue Queue handler to cancel.
128 * @param clear_cls Is it necessary to free associated cls? 129 * @param clear_cls Is it necessary to free associated cls?
129 * @param sent Was it really sent? (Could have been canceled) 130 * @param sent Was it really sent? (Could have been canceled)
131 * @param pid PID, if relevant (was sent and was a payload message).
130 */ 132 */
131void 133void
132GMP_queue_destroy (struct MeshPeerQueue *queue, int clear_cls, int sent); 134GMP_queue_destroy (struct MeshPeerQueue *queue, int clear_cls,
135 int sent, uint32_t pid);
133 136
134/** 137/**
135 * @brief Queue and pass message to core when possible. 138 * @brief Queue and pass message to core when possible.