diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-05-16 17:21:13 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-05-16 17:21:13 +0000 |
commit | 35d2df8c825e2ccdeb11dd64cd46d801bf0456a4 (patch) | |
tree | 17452bd06bec12e06f60f1cfbcf07136058050d4 /src | |
parent | db1bb9ce90445dc4e72761c83476c56b6b6828a1 (diff) | |
download | gnunet-35d2df8c825e2ccdeb11dd64cd46d801bf0456a4.tar.gz gnunet-35d2df8c825e2ccdeb11dd64cd46d801bf0456a4.zip |
- fix memory leak, path assignment, peer_rc updates
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/gnunet-service-mesh-new.c | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/src/mesh/gnunet-service-mesh-new.c b/src/mesh/gnunet-service-mesh-new.c index f2fc72dd0..815b2a3b0 100644 --- a/src/mesh/gnunet-service-mesh-new.c +++ b/src/mesh/gnunet-service-mesh-new.c | |||
@@ -744,7 +744,9 @@ tunnel_notify_connection_broken (struct MeshTunnel *t, GNUNET_PEER_Id p1, | |||
744 | 744 | ||
745 | 745 | ||
746 | /** | 746 | /** |
747 | * Use the given path for the tunnel. | 747 | * @brief Use the given path for the tunnel. |
748 | * Update the next and prev hops (and RCs). | ||
749 | * (Re)start the path refresh in case the tunnel is locally owned. | ||
748 | * | 750 | * |
749 | * @param t Tunnel to update. | 751 | * @param t Tunnel to update. |
750 | * @param p Path to use. | 752 | * @param p Path to use. |
@@ -1422,7 +1424,6 @@ peer_info_add_path (struct MeshPeerInfo *peer_info, struct MeshPeerPath *path, | |||
1422 | path_destroy (path); | 1424 | path_destroy (path); |
1423 | return; | 1425 | return; |
1424 | } | 1426 | } |
1425 | GNUNET_assert (peer_info->id == path->peers[path->length - 1]); | ||
1426 | for (l = 1; l < path->length; l++) | 1427 | for (l = 1; l < path->length; l++) |
1427 | { | 1428 | { |
1428 | if (path->peers[l] == myid) | 1429 | if (path->peers[l] == myid) |
@@ -1652,7 +1653,7 @@ path_add_to_peers (struct MeshPeerPath *p, int confirmed) | |||
1652 | aux = peer_get_short (p->peers[i]); | 1653 | aux = peer_get_short (p->peers[i]); |
1653 | copy = path_duplicate (p); | 1654 | copy = path_duplicate (p); |
1654 | copy->length = i + 1; | 1655 | copy->length = i + 1; |
1655 | peer_info_add_path (aux, copy, GNUNET_NO); | 1656 | peer_info_add_path (aux, copy, p->length < 3 ? GNUNET_NO : confirmed); |
1656 | } | 1657 | } |
1657 | } | 1658 | } |
1658 | 1659 | ||
@@ -1775,34 +1776,40 @@ tunnel_add_client (struct MeshTunnel *t, struct MeshClient *c) | |||
1775 | static void | 1776 | static void |
1776 | tunnel_use_path (struct MeshTunnel *t, struct MeshPeerPath *p) | 1777 | tunnel_use_path (struct MeshTunnel *t, struct MeshPeerPath *p) |
1777 | { | 1778 | { |
1778 | unsigned int i; | 1779 | unsigned int own_pos; |
1779 | 1780 | ||
1780 | for (i = 0; i < p->length; i++) | 1781 | for (own_pos = 0; own_pos < p->length; own_pos++) |
1781 | { | 1782 | { |
1782 | if (p->peers[i] == myid) | 1783 | if (p->peers[own_pos] == myid) |
1783 | break; | 1784 | break; |
1784 | } | 1785 | } |
1785 | if (i > p->length - 1) | 1786 | if (own_pos > p->length - 1) |
1786 | { | 1787 | { |
1787 | GNUNET_break (0); | 1788 | GNUNET_break (0); |
1788 | return; | 1789 | return; |
1789 | } | 1790 | } |
1790 | 1791 | ||
1791 | if (i < p->length - 1) | 1792 | if (own_pos < p->length - 1) |
1792 | t->next_hop = p->peers[i + 1]; | 1793 | t->next_hop = p->peers[own_pos + 1]; |
1793 | else | 1794 | else |
1794 | t->next_hop = p->peers[i]; | 1795 | t->next_hop = p->peers[own_pos]; |
1795 | if (0 < i) | 1796 | GNUNET_PEER_change_rc (t->next_hop, 1); |
1796 | t->prev_hop = p->peers[i - 1]; | 1797 | if (0 < own_pos) |
1798 | t->prev_hop = p->peers[own_pos - 1]; | ||
1797 | else | 1799 | else |
1798 | t->prev_hop = p->peers[0]; | 1800 | t->prev_hop = p->peers[0]; |
1801 | GNUNET_PEER_change_rc (t->prev_hop, 1); | ||
1799 | 1802 | ||
1800 | if (NULL != t->path) | 1803 | if (NULL != t->path) |
1801 | path_destroy (t->path); | 1804 | path_destroy (t->path); |
1802 | t->path = path_duplicate (p); | 1805 | t->path = path_duplicate (p); |
1803 | if (GNUNET_SCHEDULER_NO_TASK == t->maintenance_task) | 1806 | if (0 == own_pos) |
1804 | t->maintenance_task = | 1807 | { |
1805 | GNUNET_SCHEDULER_add_delayed (refresh_path_time, &path_refresh, t); | 1808 | if (GNUNET_SCHEDULER_NO_TASK != t->maintenance_task) |
1809 | GNUNET_SCHEDULER_cancel (t->maintenance_task); | ||
1810 | t->maintenance_task = GNUNET_SCHEDULER_add_delayed (refresh_path_time, | ||
1811 | &path_refresh, t); | ||
1812 | } | ||
1806 | } | 1813 | } |
1807 | 1814 | ||
1808 | 1815 | ||
@@ -2220,6 +2227,8 @@ tunnel_destroy (struct MeshTunnel *t) | |||
2220 | 2227 | ||
2221 | peer_cancel_queues (t->next_hop, t); | 2228 | peer_cancel_queues (t->next_hop, t); |
2222 | peer_cancel_queues (t->prev_hop, t); | 2229 | peer_cancel_queues (t->prev_hop, t); |
2230 | GNUNET_PEER_change_rc(t->next_hop, -1); | ||
2231 | GNUNET_PEER_change_rc(t->prev_hop, -1); | ||
2223 | 2232 | ||
2224 | if (GNUNET_SCHEDULER_NO_TASK != t->maintenance_task) | 2233 | if (GNUNET_SCHEDULER_NO_TASK != t->maintenance_task) |
2225 | GNUNET_SCHEDULER_cancel (t->maintenance_task); | 2234 | GNUNET_SCHEDULER_cancel (t->maintenance_task); |
@@ -2230,8 +2239,6 @@ tunnel_destroy (struct MeshTunnel *t) | |||
2230 | return r; | 2239 | return r; |
2231 | } | 2240 | } |
2232 | 2241 | ||
2233 | #define TUNNEL_DESTROY_EMPTY_TIME GNUNET_TIME_UNIT_MILLISECONDS | ||
2234 | |||
2235 | /** | 2242 | /** |
2236 | * Tunnel is empty: destroy it. | 2243 | * Tunnel is empty: destroy it. |
2237 | * | 2244 | * |
@@ -2917,7 +2924,7 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2917 | return GNUNET_OK; | 2924 | return GNUNET_OK; |
2918 | } | 2925 | } |
2919 | size /= sizeof (struct GNUNET_PeerIdentity); | 2926 | size /= sizeof (struct GNUNET_PeerIdentity); |
2920 | if (size < 2) | 2927 | if (size < 1) |
2921 | { | 2928 | { |
2922 | GNUNET_break_op (0); | 2929 | GNUNET_break_op (0); |
2923 | return GNUNET_OK; | 2930 | return GNUNET_OK; |
@@ -2928,9 +2935,9 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2928 | tid = ntohl (msg->tid); | 2935 | tid = ntohl (msg->tid); |
2929 | pi = (struct GNUNET_PeerIdentity *) &msg[1]; | 2936 | pi = (struct GNUNET_PeerIdentity *) &msg[1]; |
2930 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2937 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2931 | " path is for tunnel %s [%X].\n", GNUNET_i2s (pi), tid); | 2938 | " path is for tunnel %s[%X].\n", GNUNET_i2s (pi), tid); |
2932 | t = tunnel_get (pi, tid); | 2939 | t = tunnel_get (pi, tid); |
2933 | if (NULL == t) | 2940 | if (NULL == t) /* might be a local tunnel */ |
2934 | { | 2941 | { |
2935 | uint32_t opt; | 2942 | uint32_t opt; |
2936 | 2943 | ||
@@ -2963,10 +2970,6 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2963 | return GNUNET_OK; | 2970 | return GNUNET_OK; |
2964 | } | 2971 | } |
2965 | } | 2972 | } |
2966 | else | ||
2967 | { | ||
2968 | GNUNET_break_op (0); | ||
2969 | } | ||
2970 | t->state = MESH_TUNNEL_WAITING; | 2973 | t->state = MESH_TUNNEL_WAITING; |
2971 | dest_peer_info = | 2974 | dest_peer_info = |
2972 | GNUNET_CONTAINER_multihashmap_get (peers, &pi[size - 1].hashPubKey); | 2975 | GNUNET_CONTAINER_multihashmap_get (peers, &pi[size - 1].hashPubKey); |
@@ -3002,9 +3005,8 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3002 | own_pos = i; | 3005 | own_pos = i; |
3003 | } | 3006 | } |
3004 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Own position: %u\n", own_pos); | 3007 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Own position: %u\n", own_pos); |
3005 | if (own_pos == 0) | 3008 | if (own_pos == 0 && path->peers[own_pos] != myid) |
3006 | { | 3009 | { |
3007 | /* cannot be self, must be 'not found' */ | ||
3008 | /* create path: self not found in path through self */ | 3010 | /* create path: self not found in path through self */ |
3009 | GNUNET_break_op (0); | 3011 | GNUNET_break_op (0); |
3010 | path_destroy (path); | 3012 | path_destroy (path); |
@@ -3012,8 +3014,8 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3012 | return GNUNET_OK; | 3014 | return GNUNET_OK; |
3013 | } | 3015 | } |
3014 | path_add_to_peers (path, GNUNET_NO); | 3016 | path_add_to_peers (path, GNUNET_NO); |
3015 | t->prev_hop = path->peers[own_pos - 1]; | 3017 | tunnel_use_path (t, path); |
3016 | GNUNET_PEER_change_rc (t->prev_hop, 1); | 3018 | |
3017 | if (own_pos == size - 1) | 3019 | if (own_pos == size - 1) |
3018 | { | 3020 | { |
3019 | struct MeshClient *c; | 3021 | struct MeshClient *c; |
@@ -3057,6 +3059,7 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3057 | peer_info_add_path_to_origin (orig_peer_info, path2, GNUNET_NO); | 3059 | peer_info_add_path_to_origin (orig_peer_info, path2, GNUNET_NO); |
3058 | send_create_path (t); | 3060 | send_create_path (t); |
3059 | } | 3061 | } |
3062 | path_destroy (path); | ||
3060 | return GNUNET_OK; | 3063 | return GNUNET_OK; |
3061 | } | 3064 | } |
3062 | 3065 | ||