aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-10-10 16:29:06 +0000
committerBart Polot <bart@net.in.tum.de>2013-10-10 16:29:06 +0000
commit42c354283221489bf52e0ab4fcc6617e0d691934 (patch)
tree415bbfad5b0bdeaf9e7c86df1bbef02d2632513f /src/mesh
parenteb003715aa2ef218876bb67cb3e204d9302a6db7 (diff)
downloadgnunet-42c354283221489bf52e0ab4fcc6617e0d691934.tar.gz
gnunet-42c354283221489bf52e0ab4fcc6617e0d691934.zip
- change queueing API, adapt connections
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh_connection.c159
-rw-r--r--src/mesh/gnunet-service-mesh_peer.c28
-rw-r--r--src/mesh/gnunet-service-mesh_peer.h13
3 files changed, 93 insertions, 107 deletions
diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c
index 7e2f61569..2feeab7cd 100644
--- a/src/mesh/gnunet-service-mesh_connection.c
+++ b/src/mesh/gnunet-service-mesh_connection.c
@@ -389,6 +389,64 @@ message_sent (void *cls,
389} 389}
390 390
391 391
392/**
393 * Get the previous hop in a connection
394 *
395 * @param c Connection.
396 *
397 * @return Previous peer in the connection.
398 */
399static struct MeshPeer *
400get_prev_hop (struct MeshConnection *c)
401{
402 GNUNET_PEER_Id id;
403
404 if (0 == c->own_pos || c->path->length < 2)
405 id = c->path->peers[0];
406 else
407 id = c->path->peers[c->own_pos - 1];
408
409 return GMP_get_short (id);
410}
411
412
413/**
414 * Get the next hop in a connection
415 *
416 * @param c Connection.
417 *
418 * @return Next peer in the connection.
419 */
420static struct MeshPeer *
421get_next_hop (struct MeshConnection *c)
422{
423 GNUNET_PEER_Id id;
424
425 if ((c->path->length - 1) == c->own_pos || c->path->length < 2)
426 id = c->path->peers[c->path->length - 1];
427 else
428 id = c->path->peers[c->own_pos + 1];
429
430 return GMP_get_short (id);
431}
432
433
434/**
435 * Get the hop in a connection.
436 *
437 * @param c Connection.
438 * @param fwd Next hop?
439 *
440 * @return Next peer in the connection.
441 */
442static struct MeshPeer *
443get_hop (struct MeshConnection *c, int fwd)
444{
445 if (fwd)
446 return get_next_hop (c);
447 return get_prev_hop (c);
448}
449
392 450
393/** 451/**
394 * Send an ACK informing the predecessor about the available buffer space. 452 * Send an ACK informing the predecessor about the available buffer space.
@@ -466,7 +524,7 @@ send_connection_ack (struct MeshConnection *connection, int fwd)
466 524
467 t = connection->t; 525 t = connection->t;
468 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection ack\n"); 526 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection ack\n");
469 GMP_queue_add (NULL, 527 GMP_queue_add (get_hop (connection, fwd), NULL,
470 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK, 528 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK,
471 sizeof (struct GNUNET_MESH_ConnectionACK), 529 sizeof (struct GNUNET_MESH_ConnectionACK),
472 connection, NULL, fwd, 530 connection, NULL, fwd,
@@ -590,66 +648,6 @@ connection_bck_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *
590} 648}
591 649
592 650
593
594/**
595 * Get the previous hop in a connection
596 *
597 * @param c Connection.
598 *
599 * @return Previous peer in the connection.
600 */
601static struct MeshPeer *
602connection_get_prev_hop (struct MeshConnection *c)
603{
604 GNUNET_PEER_Id id;
605
606 if (0 == c->own_pos || c->path->length < 2)
607 id = c->path->peers[0];
608 else
609 id = c->path->peers[c->own_pos - 1];
610
611 return peer_get_short (id);
612}
613
614
615/**
616 * Get the next hop in a connection
617 *
618 * @param c Connection.
619 *
620 * @return Next peer in the connection.
621 */
622static struct MeshPeer *
623connection_get_next_hop (struct MeshConnection *c)
624{
625 GNUNET_PEER_Id id;
626
627 if ((c->path->length - 1) == c->own_pos || c->path->length < 2)
628 id = c->path->peers[c->path->length - 1];
629 else
630 id = c->path->peers[c->own_pos + 1];
631
632 return peer_get_short (id);
633}
634
635
636/**
637 * Get the hop in a connection.
638 *
639 * @param c Connection.
640 * @param fwd Next hop?
641 *
642 * @return Next peer in the connection.
643 */
644static struct MeshPeer *
645connection_get_hop (struct MeshConnection *c, int fwd)
646{
647 if (fwd)
648 return connection_get_next_hop (c);
649 return connection_get_prev_hop (c);
650}
651
652
653/** 651/**
654 * @brief Re-initiate traffic on this connection if necessary. 652 * @brief Re-initiate traffic on this connection if necessary.
655 * 653 *
@@ -675,7 +673,7 @@ connection_unlock_queue (struct MeshConnection *c, int fwd)
675 return; 673 return;
676 } 674 }
677 675
678 peer = connection_get_hop (c, fwd); 676 peer = get_hop (c, fwd);
679 GMP_queue_unlock (peer, c); 677 GMP_queue_unlock (peer, c);
680} 678}
681 679
@@ -699,7 +697,7 @@ connection_cancel_queues (struct MeshConnection *c, int fwd)
699 return; 697 return;
700 } 698 }
701 699
702 peer = connection_get_hop (c, fwd); 700 peer = get_hop (c, fwd);
703 GMP_queue_cancel (peer, c); 701 GMP_queue_cancel (peer, c);
704 702
705 fc = fwd ? &c->fwd_fc : &c->bck_fc; 703 fc = fwd ? &c->fwd_fc : &c->bck_fc;
@@ -855,14 +853,14 @@ register_neighbors (struct MeshConnection *c)
855{ 853{
856 struct MeshPeer *peer; 854 struct MeshPeer *peer;
857 855
858 peer = connection_get_next_hop (c); 856 peer = get_next_hop (c);
859 if (GNUNET_NO == GMP_is_neighbor (peer)) 857 if (GNUNET_NO == GMP_is_neighbor (peer))
860 { 858 {
861 GMC_destroy (c); 859 GMC_destroy (c);
862 return; 860 return;
863 } 861 }
864 GMP_add_connection (peer, c); 862 GMP_add_connection (peer, c);
865 peer = connection_get_prev_hop (c); 863 peer = get_prev_hop (c);
866 if (GNUNET_NO == GMP_is_neighbor (peer)) 864 if (GNUNET_NO == GMP_is_neighbor (peer))
867 { 865 {
868 GMC_destroy (c); 866 GMC_destroy (c);
@@ -882,10 +880,10 @@ unregister_neighbors (struct MeshConnection *c)
882{ 880{
883 struct MeshPeer *peer; 881 struct MeshPeer *peer;
884 882
885 peer = connection_get_next_hop (c); 883 peer = get_next_hop (c);
886 GMP_remove_connection (peer, c); 884 GMP_remove_connection (peer, c);
887 885
888 peer = connection_get_prev_hop (c); 886 peer = get_prev_hop (c);
889 GMP_remove_connection (peer, c); 887 GMP_remove_connection (peer, c);
890 888
891} 889}
@@ -1065,14 +1063,14 @@ GMC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer,
1065 LOG (GNUNET_ERROR_TYPE_DEBUG, " via peer %s\n", 1063 LOG (GNUNET_ERROR_TYPE_DEBUG, " via peer %s\n",
1066 GNUNET_i2s (peer)); 1064 GNUNET_i2s (peer));
1067 pi = peer_get (peer); 1065 pi = peer_get (peer);
1068 if (connection_get_next_hop (c) == pi) 1066 if (get_next_hop (c) == pi)
1069 { 1067 {
1070 LOG (GNUNET_ERROR_TYPE_DEBUG, " SYNACK\n"); 1068 LOG (GNUNET_ERROR_TYPE_DEBUG, " SYNACK\n");
1071 fwd = GNUNET_NO; 1069 fwd = GNUNET_NO;
1072 if (MESH_CONNECTION_SENT == c->state) 1070 if (MESH_CONNECTION_SENT == c->state)
1073 connection_change_state (c, MESH_CONNECTION_ACK); 1071 connection_change_state (c, MESH_CONNECTION_ACK);
1074 } 1072 }
1075 else if (connection_get_prev_hop (c) == pi) 1073 else if (get_prev_hop (c) == pi)
1076 { 1074 {
1077 LOG (GNUNET_ERROR_TYPE_DEBUG, " ACK\n"); 1075 LOG (GNUNET_ERROR_TYPE_DEBUG, " ACK\n");
1078 fwd = GNUNET_YES; 1076 fwd = GNUNET_YES;
@@ -1198,9 +1196,9 @@ GMC_handle_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
1198 return GNUNET_OK; 1196 return GNUNET_OK;
1199 } 1197 }
1200 id = GNUNET_PEER_search (peer); 1198 id = GNUNET_PEER_search (peer);
1201 if (id == GMP_get_short_id (connection_get_prev_hop (c))) 1199 if (id == GMP_get_short_id (get_prev_hop (c)))
1202 fwd = GNUNET_YES; 1200 fwd = GNUNET_YES;
1203 else if (id == GMP_get_short_id (connection_get_next_hop (c))) 1201 else if (id == GMP_get_short_id (get_next_hop (c)))
1204 fwd = GNUNET_NO; 1202 fwd = GNUNET_NO;
1205 else 1203 else
1206 { 1204 {
@@ -1263,7 +1261,7 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer,
1263 fc = fwd ? &c->bck_fc : &c->fwd_fc; 1261 fc = fwd ? &c->bck_fc : &c->fwd_fc;
1264 1262
1265 /* Check if origin is as expected */ 1263 /* Check if origin is as expected */
1266 neighbor = connection_get_hop (c, !fwd); 1264 neighbor = get_hop (c, !fwd);
1267 if (GNUNET_PEER_search (peer) != GMP_get_short_id (neighbor)) 1265 if (GNUNET_PEER_search (peer) != GMP_get_short_id (neighbor))
1268 { 1266 {
1269 GNUNET_break_op (0); 1267 GNUNET_break_op (0);
@@ -1413,13 +1411,13 @@ GMC_handle_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
1413 1411
1414 /* Is this a forward or backward ACK? */ 1412 /* Is this a forward or backward ACK? */
1415 id = GNUNET_PEER_search (peer); 1413 id = GNUNET_PEER_search (peer);
1416 if (GMP_get_short_id (connection_get_next_hop (c)) == id) 1414 if (GMP_get_short_id (get_next_hop (c)) == id)
1417 { 1415 {
1418 LOG (GNUNET_ERROR_TYPE_DEBUG, " FWD ACK\n"); 1416 LOG (GNUNET_ERROR_TYPE_DEBUG, " FWD ACK\n");
1419 fc = &c->fwd_fc; 1417 fc = &c->fwd_fc;
1420 fwd = GNUNET_YES; 1418 fwd = GNUNET_YES;
1421 } 1419 }
1422 else if (GMP_get_short_id (connection_get_prev_hop (c)) == id) 1420 else if (GMP_get_short_id (get_prev_hop (c)) == id)
1423 { 1421 {
1424 LOG (GNUNET_ERROR_TYPE_DEBUG, " BCK ACK\n"); 1422 LOG (GNUNET_ERROR_TYPE_DEBUG, " BCK ACK\n");
1425 fc = &c->bck_fc; 1423 fc = &c->bck_fc;
@@ -1496,12 +1494,12 @@ GMC_handle_poll (void *cls, const struct GNUNET_PeerIdentity *peer,
1496 * this way of discerining FWD/BCK should not be a problem. 1494 * this way of discerining FWD/BCK should not be a problem.
1497 */ 1495 */
1498 id = GNUNET_PEER_search (peer); 1496 id = GNUNET_PEER_search (peer);
1499 if (GMP_get_short_id (connection_get_next_hop (c)) == id) 1497 if (GMP_get_short_id (get_next_hop (c)) == id)
1500 { 1498 {
1501 LOG (GNUNET_ERROR_TYPE_DEBUG, " FWD ACK\n"); 1499 LOG (GNUNET_ERROR_TYPE_DEBUG, " FWD ACK\n");
1502 fc = &c->fwd_fc; 1500 fc = &c->fwd_fc;
1503 } 1501 }
1504 else if (GMP_get_short_id (connection_get_prev_hop (c)) == id) 1502 else if (GMP_get_short_id (get_prev_hop (c)) == id)
1505 { 1503 {
1506 LOG (GNUNET_ERROR_TYPE_DEBUG, " BCK ACK\n"); 1504 LOG (GNUNET_ERROR_TYPE_DEBUG, " BCK ACK\n");
1507 fc = &c->bck_fc; 1505 fc = &c->bck_fc;
@@ -1559,7 +1557,7 @@ GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer,
1559 GNUNET_YES : GNUNET_NO; 1557 GNUNET_YES : GNUNET_NO;
1560 1558
1561 /* Check if origin is as expected */ 1559 /* Check if origin is as expected */
1562 neighbor = connection_get_hop (c, fwd); 1560 neighbor = get_hop (c, fwd);
1563 if (GNUNET_PEER_search (peer) != GMP_get_short_id (neighbor)) 1561 if (GNUNET_PEER_search (peer) != GMP_get_short_id (neighbor))
1564 { 1562 {
1565 GNUNET_break_op (0); 1563 GNUNET_break_op (0);
@@ -1843,7 +1841,7 @@ GMC_notify_broken (struct MeshConnection *c,
1843 struct GNUNET_MESH_ConnectionBroken msg; 1841 struct GNUNET_MESH_ConnectionBroken msg;
1844 int fwd; 1842 int fwd;
1845 1843
1846 fwd = peer == connection_get_prev_hop (c); 1844 fwd = peer == get_prev_hop (c);
1847 1845
1848 connection_cancel_queues (c, !fwd); 1846 connection_cancel_queues (c, !fwd);
1849 if (GMC_is_terminal (c, fwd)) 1847 if (GMC_is_terminal (c, fwd))
@@ -2003,7 +2001,8 @@ GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
2003 GNUNET_break (0); 2001 GNUNET_break (0);
2004 } 2002 }
2005 2003
2006 GMP_queue_add (data, type, size, c, ch, fwd, &message_sent, (void *) size); 2004 GMP_queue_add (get_hop (c, fwd), data, type, size, c, ch, fwd,
2005 &message_sent, (void *) size);
2007} 2006}
2008 2007
2009 2008
@@ -2022,7 +2021,7 @@ enum MeshTunnel3State state;
2022 size = sizeof (struct GNUNET_MESH_ConnectionCreate); 2021 size = sizeof (struct GNUNET_MESH_ConnectionCreate);
2023 size += connection->path->length * sizeof (struct GNUNET_PeerIdentity); 2022 size += connection->path->length * sizeof (struct GNUNET_PeerIdentity);
2024 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection create\n"); 2023 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection create\n");
2025 GMP_queue_add (NULL, 2024 GMP_queue_add (get_next_hop (connection), NULL,
2026 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE, 2025 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE,
2027 size, 2026 size,
2028 connection, 2027 connection,
diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c
index 940377b33..6d87960b5 100644
--- a/src/mesh/gnunet-service-mesh_peer.c
+++ b/src/mesh/gnunet-service-mesh_peer.c
@@ -1083,6 +1083,7 @@ GMP_queue_destroy (struct MeshPeerQueue *queue, int clear_cls)
1083/** 1083/**
1084 * @brief Queue and pass message to core when possible. 1084 * @brief Queue and pass message to core when possible.
1085 * 1085 *
1086 * @param peer Peer towards which to queue the message.
1086 * @param cls Closure (@c type dependant). It will be used by queue_send to 1087 * @param cls Closure (@c type dependant). It will be used by queue_send to
1087 * build the message to be sent if not already prebuilt. 1088 * build the message to be sent if not already prebuilt.
1088 * @param type Type of the message, 0 for a raw message. 1089 * @param type Type of the message, 0 for a raw message.
@@ -1090,19 +1091,15 @@ GMP_queue_destroy (struct MeshPeerQueue *queue, int clear_cls)
1090 * @param c Connection this message belongs to (cannot be NULL). 1091 * @param c Connection this message belongs to (cannot be NULL).
1091 * @param ch Channel this message belongs to, if applicable (otherwise NULL). 1092 * @param ch Channel this message belongs to, if applicable (otherwise NULL).
1092 * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!) 1093 * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!)
1093 * @param callback Function to be called once CORE has taken the message. 1094 * @param cont Continuation to be called once CORE has taken the message.
1094 * @param callback_cls Closure for @c callback. 1095 * @param cont_cls Closure for @c cont.
1095 */ 1096 */
1096void 1097void
1097GMP_queue_add (void *cls, uint16_t type, size_t size, 1098GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size,
1098 struct MeshConnection *c, 1099 struct MeshConnection *c, struct MeshChannel *ch, int fwd,
1099 struct MeshChannel *ch, 1100 GMP_sent cont, void *cont_cls)
1100 int fwd,
1101 GMP_sent callback, void *callback_cls)
1102{ 1101{
1103 struct MeshPeerQueue *queue; 1102 struct MeshPeerQueue *queue;
1104 struct MeshFlowControl *fc;
1105 struct MeshPeer *peer;
1106 int priority; 1103 int priority;
1107 int call_core; 1104 int call_core;
1108 1105
@@ -1111,15 +1108,6 @@ GMP_queue_add (void *cls, uint16_t type, size_t size,
1111 fwd ? "FWD" : "BCK", GNUNET_MESH_DEBUG_M2S (type), size, c, ch); 1108 fwd ? "FWD" : "BCK", GNUNET_MESH_DEBUG_M2S (type), size, c, ch);
1112 GNUNET_assert (NULL != c); 1109 GNUNET_assert (NULL != c);
1113 1110
1114 fc = fwd ? &c->fwd_fc : &c->bck_fc;
1115 peer = fwd ? connection_get_next_hop (c) : connection_get_prev_hop (c);
1116
1117 if (NULL == fc)
1118 {
1119 GNUNET_break (0);
1120 return;
1121 }
1122
1123 if (NULL == peer->connections) 1111 if (NULL == peer->connections)
1124 { 1112 {
1125 /* We are not connected to this peer, ignore request. */ 1113 /* We are not connected to this peer, ignore request. */
@@ -1172,8 +1160,8 @@ GMP_queue_add (void *cls, uint16_t type, size_t size,
1172 queue->c = c; 1160 queue->c = c;
1173 queue->ch = ch; 1161 queue->ch = ch;
1174 queue->fwd = fwd; 1162 queue->fwd = fwd;
1175 queue->callback = callback; 1163 queue->callback = cont;
1176 queue->callback_cls = callback_cls; 1164 queue->callback_cls = cont_cls;
1177 if (100 <= priority) 1165 if (100 <= priority)
1178 { 1166 {
1179 struct MeshPeerQueue *copy; 1167 struct MeshPeerQueue *copy;
diff --git a/src/mesh/gnunet-service-mesh_peer.h b/src/mesh/gnunet-service-mesh_peer.h
index 4213ab38b..abc45f0c9 100644
--- a/src/mesh/gnunet-service-mesh_peer.h
+++ b/src/mesh/gnunet-service-mesh_peer.h
@@ -114,6 +114,7 @@ GMP_connect (struct MeshPeer *peer);
114/** 114/**
115 * @brief Queue and pass message to core when possible. 115 * @brief Queue and pass message to core when possible.
116 * 116 *
117 * @param peer Peer towards which to queue the message.
117 * @param cls Closure (@c type dependant). It will be used by queue_send to 118 * @param cls Closure (@c type dependant). It will be used by queue_send to
118 * build the message to be sent if not already prebuilt. 119 * build the message to be sent if not already prebuilt.
119 * @param type Type of the message, 0 for a raw message. 120 * @param type Type of the message, 0 for a raw message.
@@ -121,15 +122,13 @@ GMP_connect (struct MeshPeer *peer);
121 * @param c Connection this message belongs to (cannot be NULL). 122 * @param c Connection this message belongs to (cannot be NULL).
122 * @param ch Channel this message belongs to, if applicable (otherwise NULL). 123 * @param ch Channel this message belongs to, if applicable (otherwise NULL).
123 * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!) 124 * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!)
124 * @param callback Function to be called once CORE has taken the message. 125 * @param cont Continuation to be called once CORE has taken the message.
125 * @param callback_cls Closure for @c callback. 126 * @param cont_cls Closure for @c cont.
126 */ 127 */
127void 128void
128GMP_queue_add (void *cls, uint16_t type, size_t size, 129GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size,
129 struct MeshConnection *c, 130 struct MeshConnection *c, struct MeshChannel *ch, int fwd,
130 struct MeshChannel *ch, 131 GMP_sent cont, void *cont_cls);
131 int fwd,
132 GMP_sent callback, void *callback_cls);
133 132
134/** 133/**
135 * Cancel all queued messages to a peer that belong to a certain connection. 134 * Cancel all queued messages to a peer that belong to a certain connection.