aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/gnunet-service-mesh_connection.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesh/gnunet-service-mesh_connection.c')
-rw-r--r--src/mesh/gnunet-service-mesh_connection.c57
1 files changed, 32 insertions, 25 deletions
diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c
index 2c07baa50..e856d7d71 100644
--- a/src/mesh/gnunet-service-mesh_connection.c
+++ b/src/mesh/gnunet-service-mesh_connection.c
@@ -35,7 +35,6 @@
35#include "gnunet-service-mesh_connection.h" 35#include "gnunet-service-mesh_connection.h"
36#include "gnunet-service-mesh_peer.h" 36#include "gnunet-service-mesh_peer.h"
37#include "gnunet-service-mesh_tunnel.h" 37#include "gnunet-service-mesh_tunnel.h"
38#include "gnunet-service-mesh_channel.h"
39 38
40 39
41#define LOG(level, ...) GNUNET_log_from (level,"mesh-con",__VA_ARGS__) 40#define LOG(level, ...) GNUNET_log_from (level,"mesh-con",__VA_ARGS__)
@@ -418,7 +417,7 @@ send_ack (struct MeshConnection *c, unsigned int buffer, int fwd)
418 msg.ack = htonl (ack); 417 msg.ack = htonl (ack);
419 msg.cid = c->id; 418 msg.cid = c->id;
420 419
421 GMC_send_prebuilt_message (&msg.header, c, NULL, !fwd); 420 GMC_send_prebuilt_message (&msg.header, c, !fwd);
422} 421}
423 422
424 423
@@ -493,7 +492,7 @@ message_sent (void *cls,
493 } 492 }
494 p->idx = (p->idx + 1) % AVG_MSGS; 493 p->idx = (p->idx + 1) % AVG_MSGS;
495 494
496// if (NULL != c->t) 495// if (NULL != c->t) FIXME
497// { 496// {
498// c->t->pending_messages--; 497// c->t->pending_messages--;
499// if (GNUNET_YES == c->t->destroy && 0 == t->pending_messages) 498// if (GNUNET_YES == c->t->destroy && 0 == t->pending_messages)
@@ -517,6 +516,8 @@ get_prev_hop (const struct MeshConnection *c)
517{ 516{
518 GNUNET_PEER_Id id; 517 GNUNET_PEER_Id id;
519 518
519 LOG (GNUNET_ERROR_TYPE_DEBUG, "Get prev hop, own pos %u\n", c->own_pos);
520 path_debug (c->path);
520 if (0 == c->own_pos || c->path->length < 2) 521 if (0 == c->own_pos || c->path->length < 2)
521 id = c->path->peers[0]; 522 id = c->path->peers[0];
522 else 523 else
@@ -596,7 +597,7 @@ is_fwd (const struct MeshConnection *c,
596 * or a first CONNECTION_ACK directed to us. 597 * or a first CONNECTION_ACK directed to us.
597 * 598 *
598 * @param connection Connection to confirm. 599 * @param connection Connection to confirm.
599 * @param fwd Should we send it FWD? 600 * @param fwd Should we send it FWD? (root->dest)
600 * (First (~SYNACK) goes BCK, second (~ACK) goes FWD) 601 * (First (~SYNACK) goes BCK, second (~ACK) goes FWD)
601 */ 602 */
602static void 603static void
@@ -605,12 +606,12 @@ send_connection_ack (struct MeshConnection *connection, int fwd)
605 struct MeshTunnel3 *t; 606 struct MeshTunnel3 *t;
606 607
607 t = connection->t; 608 t = connection->t;
608 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection ack\n"); 609 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection %s ACK\n",
610 !fwd ? "FWD" : "BCK");
609 GMP_queue_add (get_hop (connection, fwd), NULL, 611 GMP_queue_add (get_hop (connection, fwd), NULL,
610 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK, 612 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK,
611 sizeof (struct GNUNET_MESH_ConnectionACK), 613 sizeof (struct GNUNET_MESH_ConnectionACK),
612 connection, NULL, fwd, 614 connection, fwd, &message_sent, NULL);
613 &message_sent, NULL);
614 if (MESH_TUNNEL3_NEW == GMT_get_state (t)) 615 if (MESH_TUNNEL3_NEW == GMT_get_state (t))
615 GMT_change_state (t, MESH_TUNNEL3_WAITING); 616 GMT_change_state (t, MESH_TUNNEL3_WAITING);
616 if (MESH_CONNECTION_READY != connection->state) 617 if (MESH_CONNECTION_READY != connection->state)
@@ -639,7 +640,7 @@ send_broken (struct MeshConnection *c,
639 msg.cid = c->id; 640 msg.cid = c->id;
640 msg.peer1 = *id1; 641 msg.peer1 = *id1;
641 msg.peer2 = *id2; 642 msg.peer2 = *id2;
642 GMC_send_prebuilt_message (&msg.header, c, NULL, fwd); 643 GMC_send_prebuilt_message (&msg.header, c, fwd);
643} 644}
644 645
645 646
@@ -670,7 +671,7 @@ connection_keepalive (struct MeshConnection *c, int fwd)
670 msg->header.type = htons (type); 671 msg->header.type = htons (type);
671 msg->cid = c->id; 672 msg->cid = c->id;
672 673
673 GMC_send_prebuilt_message (&msg->header, c, NULL, fwd); 674 GMC_send_prebuilt_message (&msg->header, c, fwd);
674} 675}
675 676
676 677
@@ -846,7 +847,7 @@ connection_poll (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
846 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_POLL); 847 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_POLL);
847 msg.header.size = htons (sizeof (msg)); 848 msg.header.size = htons (sizeof (msg));
848 LOG (GNUNET_ERROR_TYPE_DEBUG, " *** pid (%u)!\n", fc->last_pid_sent); 849 LOG (GNUNET_ERROR_TYPE_DEBUG, " *** pid (%u)!\n", fc->last_pid_sent);
849 GMC_send_prebuilt_message (&msg.header, c, NULL, fc == &c->fwd_fc); 850 GMC_send_prebuilt_message (&msg.header, c, fc == &c->fwd_fc);
850 fc->poll_time = GNUNET_TIME_STD_BACKOFF (fc->poll_time); 851 fc->poll_time = GNUNET_TIME_STD_BACKOFF (fc->poll_time);
851 fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time, 852 fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time,
852 &connection_poll, fc); 853 &connection_poll, fc);
@@ -1141,7 +1142,7 @@ GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
1141 LOG (GNUNET_ERROR_TYPE_DEBUG, " Retransmitting.\n"); 1142 LOG (GNUNET_ERROR_TYPE_DEBUG, " Retransmitting.\n");
1142 GMP_add_path (dest_peer, path_duplicate (path), GNUNET_NO); 1143 GMP_add_path (dest_peer, path_duplicate (path), GNUNET_NO);
1143 GMP_add_path_to_origin (orig_peer, path, GNUNET_NO); 1144 GMP_add_path_to_origin (orig_peer, path, GNUNET_NO);
1144 GMC_send_prebuilt_message (message, c, NULL, GNUNET_YES); 1145 GMC_send_prebuilt_message (message, c, GNUNET_YES);
1145 } 1146 }
1146 return GNUNET_OK; 1147 return GNUNET_OK;
1147} 1148}
@@ -1238,7 +1239,7 @@ GMC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer,
1238 } 1239 }
1239 1240
1240 LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); 1241 LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n");
1241 GMC_send_prebuilt_message (message, c, NULL, fwd); 1242 GMC_send_prebuilt_message (message, c, fwd);
1242 return GNUNET_OK; 1243 return GNUNET_OK;
1243} 1244}
1244 1245
@@ -1287,7 +1288,7 @@ GMC_handle_broken (void* cls,
1287 } 1288 }
1288 else 1289 else
1289 { 1290 {
1290 GMC_send_prebuilt_message (message, c, NULL, fwd); 1291 GMC_send_prebuilt_message (message, c, fwd);
1291 c->destroy = GNUNET_YES; 1292 c->destroy = GNUNET_YES;
1292 } 1293 }
1293 1294
@@ -1338,7 +1339,7 @@ GMC_handle_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
1338 GNUNET_break_op (0); 1339 GNUNET_break_op (0);
1339 return GNUNET_OK; 1340 return GNUNET_OK;
1340 } 1341 }
1341 GMC_send_prebuilt_message (message, c, NULL, fwd); 1342 GMC_send_prebuilt_message (message, c, fwd);
1342 c->destroy = GNUNET_YES; 1343 c->destroy = GNUNET_YES;
1343 1344
1344 return GNUNET_OK; 1345 return GNUNET_OK;
@@ -1467,7 +1468,7 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer,
1467 } 1468 }
1468 GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO); 1469 GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO);
1469 1470
1470 GMC_send_prebuilt_message (&msg->header, c, NULL, fwd); 1471 GMC_send_prebuilt_message (&msg->header, c, fwd);
1471 1472
1472 return GNUNET_OK; 1473 return GNUNET_OK;
1473} 1474}
@@ -1689,7 +1690,7 @@ GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer,
1689 return GNUNET_OK; 1690 return GNUNET_OK;
1690 1691
1691 GNUNET_STATISTICS_update (stats, "# keepalives forwarded", 1, GNUNET_NO); 1692 GNUNET_STATISTICS_update (stats, "# keepalives forwarded", 1, GNUNET_NO);
1692 GMC_send_prebuilt_message (message, c, NULL, fwd); 1693 GMC_send_prebuilt_message (message, c, fwd);
1693 1694
1694 return GNUNET_OK; 1695 return GNUNET_OK;
1695} 1696}
@@ -1867,6 +1868,10 @@ GMC_destroy (struct MeshConnection *c)
1867 GNUNET_STATISTICS_update (stats, "# connections", -1, GNUNET_NO); 1868 GNUNET_STATISTICS_update (stats, "# connections", -1, GNUNET_NO);
1868 if (NULL != c->t) 1869 if (NULL != c->t)
1869 GMT_remove_connection (c->t, c); 1870 GMT_remove_connection (c->t, c);
1871
1872 if (GNUNET_NO == GMC_is_origin (c, GNUNET_YES))
1873 path_destroy (c->path);
1874
1870 GNUNET_free (c); 1875 GNUNET_free (c);
1871} 1876}
1872 1877
@@ -2021,14 +2026,19 @@ GMC_notify_broken (struct MeshConnection *c,
2021 GMC_destroy (c); 2026 GMC_destroy (c);
2022 return; 2027 return;
2023 } 2028 }
2024 send_broken (c, &my_full_id, GMP_get_id (peer), fwd); 2029 if (GNUNET_NO == c->destroy)
2025 connection_cancel_queues (c, !fwd); 2030 send_broken (c, &my_full_id, GMP_get_id (peer), fwd);
2026 2031
2027 /* Connection will have at least one pending message 2032 /* Connection will have at least one pending message
2028 * (the one we just scheduled), so no point in checking whether to 2033 * (the one we just scheduled), so no point in checking whether to
2029 * destroy immediately. */ 2034 * destroy immediately. */
2030 c->destroy = GNUNET_YES; 2035 c->destroy = GNUNET_YES;
2031 2036
2037 /**
2038 * Cancel all queues, if no message is left, connection will be destroyed.
2039 */
2040 connection_cancel_queues (c, !fwd);
2041
2032 return; 2042 return;
2033} 2043}
2034 2044
@@ -2094,13 +2104,11 @@ GMC_is_sendable (struct MeshConnection *c, int fwd)
2094 * @param message Message to send. Function makes a copy of it. 2104 * @param message Message to send. Function makes a copy of it.
2095 * If message is not hop-by-hop, decrements TTL of copy. 2105 * If message is not hop-by-hop, decrements TTL of copy.
2096 * @param c Connection on which this message is transmitted. 2106 * @param c Connection on which this message is transmitted.
2097 * @param ch Channel on which this message is transmitted, or NULL.
2098 * @param fwd Is this a fwd message? 2107 * @param fwd Is this a fwd message?
2099 */ 2108 */
2100void 2109void
2101GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, 2110GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
2102 struct MeshConnection *c, 2111 struct MeshConnection *c,
2103 struct MeshChannel *ch,
2104 int fwd) 2112 int fwd)
2105{ 2113{
2106 struct MeshFlowControl *fc; 2114 struct MeshFlowControl *fc;
@@ -2199,7 +2207,7 @@ GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
2199 2207
2200 c->pending_messages++; 2208 c->pending_messages++;
2201 2209
2202 GMP_queue_add (get_hop (c, fwd), data, type, size, c, ch, fwd, 2210 GMP_queue_add (get_hop (c, fwd), data, type, size, c, fwd,
2203 &message_sent, NULL); 2211 &message_sent, NULL);
2204} 2212}
2205 2213
@@ -2221,8 +2229,7 @@ GMC_send_create (struct MeshConnection *connection)
2221 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection create\n"); 2229 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection create\n");
2222 GMP_queue_add (get_next_hop (connection), NULL, 2230 GMP_queue_add (get_next_hop (connection), NULL,
2223 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE, 2231 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE,
2224 size, connection, NULL, 2232 size, connection, GNUNET_YES, &message_sent, NULL);
2225 GNUNET_YES, &message_sent, NULL);
2226 state = GMT_get_state (connection->t); 2233 state = GMT_get_state (connection->t);
2227 if (MESH_TUNNEL3_SEARCHING == state || MESH_TUNNEL3_NEW == state) 2234 if (MESH_TUNNEL3_SEARCHING == state || MESH_TUNNEL3_NEW == state)
2228 GMT_change_state (connection->t, MESH_TUNNEL3_WAITING); 2235 GMT_change_state (connection->t, MESH_TUNNEL3_WAITING);
@@ -2256,9 +2263,9 @@ GMC_send_destroy (struct MeshConnection *c)
2256 GMC_2s (c)); 2263 GMC_2s (c));
2257 2264
2258 if (GNUNET_NO == GMC_is_terminal (c, GNUNET_YES)) 2265 if (GNUNET_NO == GMC_is_terminal (c, GNUNET_YES))
2259 GMC_send_prebuilt_message (&msg.header, c, NULL, GNUNET_YES); 2266 GMC_send_prebuilt_message (&msg.header, c, GNUNET_YES);
2260 if (GNUNET_NO == GMC_is_terminal (c, GNUNET_NO)) 2267 if (GNUNET_NO == GMC_is_terminal (c, GNUNET_NO))
2261 GMC_send_prebuilt_message (&msg.header, c, NULL, GNUNET_NO); 2268 GMC_send_prebuilt_message (&msg.header, c, GNUNET_NO);
2262 c->destroy = GNUNET_YES; 2269 c->destroy = GNUNET_YES;
2263} 2270}
2264 2271