aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-10-24 02:04:48 +0000
committerBart Polot <bart@net.in.tum.de>2013-10-24 02:04:48 +0000
commit8d774a0d462c9de472d58594663c1dd8a850164b (patch)
tree658cfbb326364a623831110edbb9f800443d1638
parent297126b8347dd8d164f26accdf723d805a4c31bc (diff)
downloadgnunet-8d774a0d462c9de472d58594663c1dd8a850164b.tar.gz
gnunet-8d774a0d462c9de472d58594663c1dd8a850164b.zip
- fix leaks
- refactor to simplify APIs
-rw-r--r--src/mesh/gnunet-service-mesh_connection.c57
-rw-r--r--src/mesh/gnunet-service-mesh_connection.h4
-rw-r--r--src/mesh/gnunet-service-mesh_peer.c92
-rw-r--r--src/mesh/gnunet-service-mesh_peer.h15
-rw-r--r--src/mesh/gnunet-service-mesh_tunnel.c15
5 files changed, 95 insertions, 88 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
diff --git a/src/mesh/gnunet-service-mesh_connection.h b/src/mesh/gnunet-service-mesh_connection.h
index 3f75bcdab..fbff84335 100644
--- a/src/mesh/gnunet-service-mesh_connection.h
+++ b/src/mesh/gnunet-service-mesh_connection.h
@@ -223,6 +223,8 @@ GMC_shutdown (void);
223 * @param t Tunnel this connection belongs to (or NULL); 223 * @param t Tunnel this connection belongs to (or NULL);
224 * @param p Path this connection has to use. 224 * @param p Path this connection has to use.
225 * @param own_pos Own position in the @c p path. 225 * @param own_pos Own position in the @c p path.
226 *
227 * @return Newly created connection, NULL in case of error (own id not in path).
226 */ 228 */
227struct MeshConnection * 229struct MeshConnection *
228GMC_new (const struct GNUNET_HashCode *cid, 230GMC_new (const struct GNUNET_HashCode *cid,
@@ -398,13 +400,11 @@ GMC_is_sendable (struct MeshConnection *c, int fwd);
398 * @param message Message to send. Function makes a copy of it. 400 * @param message Message to send. Function makes a copy of it.
399 * If message is not hop-by-hop, decrements TTL of copy. 401 * If message is not hop-by-hop, decrements TTL of copy.
400 * @param c Connection on which this message is transmitted. 402 * @param c Connection on which this message is transmitted.
401 * @param ch Channel on which this message is transmitted, or NULL.
402 * @param fwd Is this a fwd message? 403 * @param fwd Is this a fwd message?
403 */ 404 */
404void 405void
405GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, 406GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
406 struct MeshConnection *c, 407 struct MeshConnection *c,
407 struct MeshChannel *ch,
408 int fwd); 408 int fwd);
409 409
410/** 410/**
diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c
index 38750f1ae..2ef116544 100644
--- a/src/mesh/gnunet-service-mesh_peer.c
+++ b/src/mesh/gnunet-service-mesh_peer.c
@@ -30,7 +30,6 @@
30#include "gnunet-service-mesh_peer.h" 30#include "gnunet-service-mesh_peer.h"
31#include "gnunet-service-mesh_dht.h" 31#include "gnunet-service-mesh_dht.h"
32#include "gnunet-service-mesh_connection.h" 32#include "gnunet-service-mesh_connection.h"
33#include "gnunet-service-mesh_local.h"
34#include "gnunet-service-mesh_tunnel.h" 33#include "gnunet-service-mesh_tunnel.h"
35#include "mesh_path.h" 34#include "mesh_path.h"
36 35
@@ -71,11 +70,6 @@ struct MeshPeerQueue
71 int fwd; 70 int fwd;
72 71
73 /** 72 /**
74 * Channel this message belongs to, if known.
75 */
76 struct MeshChannel *ch;
77
78 /**
79 * Pointer to info stucture used as cls. 73 * Pointer to info stucture used as cls.
80 */ 74 */
81 void *cls; 75 void *cls;
@@ -967,14 +961,13 @@ queue_send (void *cls, size_t size, void *buf)
967 * @param type Type of the message, 0 for a raw message. 961 * @param type Type of the message, 0 for a raw message.
968 * @param size Size of the message. 962 * @param size Size of the message.
969 * @param c Connection this message belongs to (cannot be NULL). 963 * @param c Connection this message belongs to (cannot be NULL).
970 * @param ch Channel this message belongs to, if applicable (otherwise NULL).
971 * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!) 964 * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!)
972 * @param cont Continuation to be called once CORE has taken the message. 965 * @param cont Continuation to be called once CORE has taken the message.
973 * @param cont_cls Closure for @c cont. 966 * @param cont_cls Closure for @c cont.
974 */ 967 */
975void 968void
976GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size, 969GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size,
977 struct MeshConnection *c, struct MeshChannel *ch, int fwd, 970 struct MeshConnection *c, int fwd,
978 GMP_sent cont, void *cont_cls) 971 GMP_sent cont, void *cont_cls)
979{ 972{
980 struct MeshPeerQueue *queue; 973 struct MeshPeerQueue *queue;
@@ -982,8 +975,9 @@ GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size,
982 int call_core; 975 int call_core;
983 976
984 LOG (GNUNET_ERROR_TYPE_DEBUG, 977 LOG (GNUNET_ERROR_TYPE_DEBUG,
985 "queue add %s %s (%u) on c %p, ch %p\n", 978 "queue add %s %s towards %s (size %u) on c %p (%s)\n",
986 fwd ? "FWD" : "BCK", GNUNET_MESH_DEBUG_M2S (type), size, c, ch); 979 fwd ? "FWD" : "BCK", GNUNET_MESH_DEBUG_M2S (type), GMP_2s(peer),
980 size, c, GMC_2s (c));
987 GNUNET_assert (NULL != c); 981 GNUNET_assert (NULL != c);
988 982
989 if (NULL == peer->connections) 983 if (NULL == peer->connections)
@@ -1010,7 +1004,6 @@ GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size,
1010 queue->size = size; 1004 queue->size = size;
1011 queue->peer = peer; 1005 queue->peer = peer;
1012 queue->c = c; 1006 queue->c = c;
1013 queue->ch = ch;
1014 queue->fwd = fwd; 1007 queue->fwd = fwd;
1015 queue->callback = cont; 1008 queue->callback = cont;
1016 queue->callback_cls = cont_cls; 1009 queue->callback_cls = cont_cls;
@@ -1447,36 +1440,42 @@ GMP_add_connection (struct MeshPeer *peer,
1447 * Add the path to the peer and update the path used to reach it in case this 1440 * Add the path to the peer and update the path used to reach it in case this
1448 * is the shortest. 1441 * is the shortest.
1449 * 1442 *
1450 * @param peer_info Destination peer to add the path to. 1443 * @param peer Destination peer to add the path to.
1451 * @param path New path to add. Last peer must be the peer in arg 1. 1444 * @param path New path to add. Last peer must be the peer in arg 1.
1452 * Path will be either used of freed if already known. 1445 * Path will be either used of freed if already known.
1453 * @param trusted Do we trust that this path is real? 1446 * @param trusted Do we trust that this path is real?
1447 *
1448 * @return path if path was taken, pointer to existing duplicate if exists
1449 * NULL on error.
1454 */ 1450 */
1455void 1451struct MeshPeerPath *
1456GMP_add_path (struct MeshPeer *peer_info, struct MeshPeerPath *path, 1452GMP_add_path (struct MeshPeer *peer, struct MeshPeerPath *path,
1457 int trusted) 1453 int trusted)
1458{ 1454{
1459 struct MeshPeerPath *aux; 1455 struct MeshPeerPath *aux;
1460 unsigned int l; 1456 unsigned int l;
1461 unsigned int l2; 1457 unsigned int l2;
1462 1458
1463 if ((NULL == peer_info) || (NULL == path)) 1459 LOG (GNUNET_ERROR_TYPE_DEBUG, "adding path [%u] to peer %s\n",
1460 path->length, GMP_2s (peer));
1461
1462 if ((NULL == peer) || (NULL == path))
1464 { 1463 {
1465 GNUNET_break (0); 1464 GNUNET_break (0);
1466 path_destroy (path); 1465 path_destroy (path);
1467 return; 1466 return NULL;
1468 } 1467 }
1469 if (path->peers[path->length - 1] != peer_info->id) 1468 if (path->peers[path->length - 1] != peer->id)
1470 { 1469 {
1471 GNUNET_break (0); 1470 GNUNET_break (0);
1472 path_destroy (path); 1471 path_destroy (path);
1473 return; 1472 return NULL;
1474 } 1473 }
1475 if (2 >= path->length && GNUNET_NO == trusted) 1474 if (2 >= path->length && GNUNET_NO == trusted)
1476 { 1475 {
1477 /* Only allow CORE to tell us about direct paths */ 1476 /* Only allow CORE to tell us about direct paths */
1478 path_destroy (path); 1477 path_destroy (path);
1479 return; 1478 return NULL;
1480 } 1479 }
1481 for (l = 1; l < path->length; l++) 1480 for (l = 1; l < path->length; l++)
1482 { 1481 {
@@ -1487,45 +1486,47 @@ GMP_add_path (struct MeshPeer *peer_info, struct MeshPeerPath *path,
1487 { 1486 {
1488 path->peers[l2] = path->peers[l + l2]; 1487 path->peers[l2] = path->peers[l + l2];
1489 } 1488 }
1490 path->length -= l; 1489 path->length -= l;
1491 l = 1; 1490 l = 1;
1492 path->peers = 1491 path->peers = GNUNET_realloc (path->peers,
1493 GNUNET_realloc (path->peers, path->length * sizeof (GNUNET_PEER_Id)); 1492 path->length * sizeof (GNUNET_PEER_Id));
1494 } 1493 }
1495 } 1494 }
1496 1495
1497 LOG (GNUNET_ERROR_TYPE_DEBUG, "adding path [%u] to peer %s\n", 1496 LOG (GNUNET_ERROR_TYPE_DEBUG, "adding path [%u]\n", path->length);
1498 path->length, GMP_2s (peer_info));
1499 1497
1500 l = path_get_length (path); 1498 l = path_get_length (path);
1501 if (0 == l) 1499 if (0 == l)
1502 { 1500 {
1503 path_destroy (path); 1501 path_destroy (path);
1504 return; 1502 return NULL;
1505 } 1503 }
1506 1504
1507 GNUNET_assert (peer_info->id == path->peers[path->length - 1]); 1505 GNUNET_assert (peer->id == path->peers[path->length - 1]);
1508 for (aux = peer_info->path_head; aux != NULL; aux = aux->next) 1506 for (aux = peer->path_head; aux != NULL; aux = aux->next)
1509 { 1507 {
1510 l2 = path_get_length (aux); 1508 l2 = path_get_length (aux);
1511 if (l2 > l) 1509 if (l2 > l)
1512 { 1510 {
1513 GNUNET_CONTAINER_DLL_insert_before (peer_info->path_head, 1511 LOG (GNUNET_ERROR_TYPE_DEBUG, " added\n");
1514 peer_info->path_tail, aux, path); 1512 GNUNET_CONTAINER_DLL_insert_before (peer->path_head,
1515 return; 1513 peer->path_tail, aux, path);
1514 return path;
1515 }
1516 else
1517 {
1518 if (l2 == l && memcmp (path->peers, aux->peers, l) == 0)
1519 {
1520 LOG (GNUNET_ERROR_TYPE_DEBUG, " already known\n");
1521 path_destroy (path);
1522 return aux;
1523 }
1516 } 1524 }
1517 else
1518 {
1519 if (l2 == l && memcmp (path->peers, aux->peers, l) == 0)
1520 {
1521 path_destroy (path);
1522 return;
1523 }
1524 }
1525 } 1525 }
1526 GNUNET_CONTAINER_DLL_insert_tail (peer_info->path_head, peer_info->path_tail, 1526 GNUNET_CONTAINER_DLL_insert_tail (peer->path_head, peer->path_tail,
1527 path); 1527 path);
1528 return; 1528 LOG (GNUNET_ERROR_TYPE_DEBUG, " added last\n");
1529 return path;
1529} 1530}
1530 1531
1531 1532
@@ -1539,16 +1540,19 @@ GMP_add_path (struct MeshPeer *peer_info, struct MeshPeerPath *path,
1539 * @param path New path to add after being inversed. 1540 * @param path New path to add after being inversed.
1540 * Path will be either used or freed. 1541 * Path will be either used or freed.
1541 * @param trusted Do we trust that this path is real? 1542 * @param trusted Do we trust that this path is real?
1543 *
1544 * @return path if path was taken, pointer to existing duplicate if exists
1545 * NULL on error.
1542 */ 1546 */
1543void 1547struct MeshPeerPath *
1544GMP_add_path_to_origin (struct MeshPeer *peer, 1548GMP_add_path_to_origin (struct MeshPeer *peer,
1545 struct MeshPeerPath *path, 1549 struct MeshPeerPath *path,
1546 int trusted) 1550 int trusted)
1547{ 1551{
1548 if (NULL == path) 1552 if (NULL == path)
1549 return; 1553 return NULL;
1550 path_invert (path); 1554 path_invert (path);
1551 GMP_add_path (peer, path, trusted); 1555 return GMP_add_path (peer, path, trusted);
1552} 1556}
1553 1557
1554 1558
diff --git a/src/mesh/gnunet-service-mesh_peer.h b/src/mesh/gnunet-service-mesh_peer.h
index df044ad14..f3082543f 100644
--- a/src/mesh/gnunet-service-mesh_peer.h
+++ b/src/mesh/gnunet-service-mesh_peer.h
@@ -123,14 +123,13 @@ GMP_connect (struct MeshPeer *peer);
123 * @param type Type of the message, 0 for a raw message. 123 * @param type Type of the message, 0 for a raw message.
124 * @param size Size of the message. 124 * @param size Size of the message.
125 * @param c Connection this message belongs to (cannot be NULL). 125 * @param c Connection this message belongs to (cannot be NULL).
126 * @param ch Channel this message belongs to, if applicable (otherwise NULL).
127 * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!) 126 * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!)
128 * @param cont Continuation to be called once CORE has taken the message. 127 * @param cont Continuation to be called once CORE has taken the message.
129 * @param cont_cls Closure for @c cont. 128 * @param cont_cls Closure for @c cont.
130 */ 129 */
131void 130void
132GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size, 131GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size,
133 struct MeshConnection *c, struct MeshChannel *ch, int fwd, 132 struct MeshConnection *c, int fwd,
134 GMP_sent cont, void *cont_cls); 133 GMP_sent cont, void *cont_cls);
135 134
136/** 135/**
@@ -194,12 +193,15 @@ GMP_add_connection (struct MeshPeer *peer, struct MeshConnection *c);
194 * Add the path to the peer and update the path used to reach it in case this 193 * Add the path to the peer and update the path used to reach it in case this
195 * is the shortest. 194 * is the shortest.
196 * 195 *
197 * @param peer_info Destination peer to add the path to. 196 * @param peer Destination peer to add the path to.
198 * @param path New path to add. Last peer must be the peer in arg 1. 197 * @param path New path to add. Last peer must be the peer in arg 1.
199 * Path will be either used of freed if already known. 198 * Path will be either used of freed if already known.
200 * @param trusted Do we trust that this path is real? 199 * @param trusted Do we trust that this path is real?
200 *
201 * @return path if path was taken, pointer to existing duplicate if exists
202 * NULL on error.
201 */ 203 */
202void 204struct MeshPeerPath *
203GMP_add_path (struct MeshPeer *peer, struct MeshPeerPath *p, int trusted); 205GMP_add_path (struct MeshPeer *peer, struct MeshPeerPath *p, int trusted);
204 206
205/** 207/**
@@ -212,8 +214,11 @@ GMP_add_path (struct MeshPeer *peer, struct MeshPeerPath *p, int trusted);
212 * @param path New path to add after being inversed. 214 * @param path New path to add after being inversed.
213 * Path will be either used or freed. 215 * Path will be either used or freed.
214 * @param trusted Do we trust that this path is real? 216 * @param trusted Do we trust that this path is real?
217 *
218 * @return path if path was taken, pointer to existing duplicate if exists
219 * NULL on error.
215 */ 220 */
216void 221struct MeshPeerPath *
217GMP_add_path_to_origin (struct MeshPeer *peer, 222GMP_add_path_to_origin (struct MeshPeer *peer,
218 struct MeshPeerPath *path, 223 struct MeshPeerPath *path,
219 int trusted); 224 int trusted);
diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c
index 41e7deb4e..6cb536110 100644
--- a/src/mesh/gnunet-service-mesh_tunnel.c
+++ b/src/mesh/gnunet-service-mesh_tunnel.c
@@ -118,11 +118,6 @@ struct MeshTunnel3
118 MESH_ChannelNumber next_chid; 118 MESH_ChannelNumber next_chid;
119 119
120 /** 120 /**
121 * Pending message count.
122 */
123 int pending_messages;
124
125 /**
126 * Destroy flag: if true, destroy on last message. 121 * Destroy flag: if true, destroy on last message.
127 */ 122 */
128 int destroy; 123 int destroy;
@@ -848,10 +843,7 @@ GMT_destroy_empty (struct MeshTunnel3 *t)
848 GMC_send_destroy (iter->c); 843 GMC_send_destroy (iter->c);
849 } 844 }
850 845
851 if (0 == t->pending_messages) 846 t->destroy = GNUNET_YES;
852 GMT_destroy (t);
853 else
854 t->destroy = GNUNET_YES;
855} 847}
856 848
857 849
@@ -1249,7 +1241,7 @@ GMT_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
1249 uint64_t iv; 1241 uint64_t iv;
1250 uint16_t type; 1242 uint16_t type;
1251 1243
1252 LOG (GNUNET_ERROR_TYPE_DEBUG, "GMT Send on Tunnel %s\n", GMP_2s (t->peer)); 1244 LOG (GNUNET_ERROR_TYPE_DEBUG, "GMT Send on Tunnel %s\n", GMT_2s (t));
1253 1245
1254 iv = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_NONCE, UINT64_MAX); 1246 iv = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_NONCE, UINT64_MAX);
1255 msg = (struct GNUNET_MESH_Encrypted *) cbuf; 1247 msg = (struct GNUNET_MESH_Encrypted *) cbuf;
@@ -1280,8 +1272,7 @@ GMT_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
1280 } 1272 }
1281 msg->reserved = 0; 1273 msg->reserved = 0;
1282 1274
1283 t->pending_messages++; 1275 GMC_send_prebuilt_message (&msg->header, c, fwd);
1284 GMC_send_prebuilt_message (&msg->header, c, ch, fwd);
1285} 1276}
1286 1277
1287/** 1278/**