diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-10-10 16:26:15 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-10-10 16:26:15 +0000 |
commit | 0b3a3d3f528101f53a5e3a1fad81dc9b6f62cd3c (patch) | |
tree | e0db21f05cc684d8b09cf96a939ee65982976ad4 /src/mesh | |
parent | c7b454f407512be4f8ae85962e332b3a1d026c09 (diff) | |
download | gnunet-0b3a3d3f528101f53a5e3a1fad81dc9b6f62cd3c.tar.gz gnunet-0b3a3d3f528101f53a5e3a1fad81dc9b6f62cd3c.zip |
Fixed bugs, refactored path tree
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 68 | ||||
-rw-r--r-- | src/mesh/mesh_tunnel_tree.c | 23 | ||||
-rw-r--r-- | src/mesh/mesh_tunnel_tree.h | 9 | ||||
-rw-r--r-- | src/mesh/test_mesh_small.conf | 2 |
4 files changed, 85 insertions, 17 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index e76d440cf..53feb309d 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -852,16 +852,30 @@ send_create_path (struct MeshPeerInfo *peer, | |||
852 | struct MeshPeerPath *p, | 852 | struct MeshPeerPath *p, |
853 | struct MeshTunnel *t) | 853 | struct MeshTunnel *t) |
854 | { | 854 | { |
855 | struct GNUNET_PeerIdentity *id; | 855 | struct GNUNET_PeerIdentity id; |
856 | struct MeshPathInfo *path_info; | 856 | struct MeshPathInfo *path_info; |
857 | struct MeshPeerInfo *neighbor; | 857 | struct MeshPeerInfo *neighbor; |
858 | unsigned int i; | ||
859 | |||
860 | if (NULL == p) | ||
861 | p = tree_get_path_to_peer(t->tree, peer->id); | ||
862 | for (i = 0; i < p->length; i++) | ||
863 | { | ||
864 | if (p->peers[i] == myid) | ||
865 | break; | ||
866 | } | ||
867 | if (i >= p->length - 1) | ||
868 | { | ||
869 | GNUNET_break (0); | ||
870 | return; | ||
871 | } | ||
872 | GNUNET_PEER_resolve(p->peers[i + 1], &id); | ||
858 | 873 | ||
859 | path_info = GNUNET_malloc (sizeof (struct MeshPathInfo)); | 874 | path_info = GNUNET_malloc (sizeof (struct MeshPathInfo)); |
860 | path_info->path = p; | 875 | path_info->path = p; |
861 | path_info->peer = peer; | 876 | path_info->peer = peer; |
862 | path_info->t = t; | 877 | path_info->t = t; |
863 | id = path_get_first_hop(t->tree, peer->id); | 878 | neighbor = peer_info_get(&id); |
864 | neighbor = peer_info_get(id); | ||
865 | path_info->pos = peer_info_transmit_position(neighbor); | 879 | path_info->pos = peer_info_transmit_position(neighbor); |
866 | neighbor->types[path_info->pos] = GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE; | 880 | neighbor->types[path_info->pos] = GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE; |
867 | neighbor->infos[path_info->pos] = path_info; | 881 | neighbor->infos[path_info->pos] = path_info; |
@@ -871,7 +885,7 @@ send_create_path (struct MeshPeerInfo *peer, | |||
871 | 0, /* cork */ | 885 | 0, /* cork */ |
872 | 0, /* priority */ | 886 | 0, /* priority */ |
873 | GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ | 887 | GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ |
874 | id, /* target */ | 888 | &id, /* target */ |
875 | sizeof (struct GNUNET_MESH_ManipulatePath) | 889 | sizeof (struct GNUNET_MESH_ManipulatePath) |
876 | + (p->length * sizeof (struct GNUNET_PeerIdentity)), /*size */ | 890 | + (p->length * sizeof (struct GNUNET_PeerIdentity)), /*size */ |
877 | &send_core_create_path, /* callback */ | 891 | &send_core_create_path, /* callback */ |
@@ -1366,7 +1380,7 @@ tunnel_add_peer (struct MeshTunnel *t, struct MeshPeerInfo *peer) | |||
1366 | if (NULL != (p = peer->path_head)) | 1380 | if (NULL != (p = peer->path_head)) |
1367 | { | 1381 | { |
1368 | best_p = p; | 1382 | best_p = p; |
1369 | best_cost = UINT_MAX; | 1383 | best_cost = path_get_cost(t->tree, p); |
1370 | while (NULL != p) | 1384 | while (NULL != p) |
1371 | { | 1385 | { |
1372 | if ((cost = path_get_cost (t->tree, p)) < best_cost) | 1386 | if ((cost = path_get_cost (t->tree, p)) < best_cost) |
@@ -1811,7 +1825,8 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1811 | struct MeshTunnel *t; | 1825 | struct MeshTunnel *t; |
1812 | 1826 | ||
1813 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1827 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1814 | "MESH: Received a path create msg\n"); | 1828 | "MESH: Received a path create msg [%s]\n", |
1829 | GNUNET_i2s(&my_full_id)); | ||
1815 | size = ntohs (message->size); | 1830 | size = ntohs (message->size); |
1816 | if (size < sizeof (struct GNUNET_MESH_ManipulatePath)) | 1831 | if (size < sizeof (struct GNUNET_MESH_ManipulatePath)) |
1817 | { | 1832 | { |
@@ -1832,7 +1847,7 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1832 | return GNUNET_OK; | 1847 | return GNUNET_OK; |
1833 | } | 1848 | } |
1834 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1849 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1835 | "MESH: path as %u hops.\n", | 1850 | "MESH: path has %u hops.\n", |
1836 | size); | 1851 | size); |
1837 | msg = (struct GNUNET_MESH_ManipulatePath *) message; | 1852 | msg = (struct GNUNET_MESH_ManipulatePath *) message; |
1838 | 1853 | ||
@@ -1851,7 +1866,9 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1851 | t->id.tid = tid; | 1866 | t->id.tid = tid; |
1852 | t->peers = GNUNET_CONTAINER_multihashmap_create (32); | 1867 | t->peers = GNUNET_CONTAINER_multihashmap_create (32); |
1853 | t->local_tid = next_local_tid++; | 1868 | t->local_tid = next_local_tid++; |
1869 | /* FIXME test if taken */ | ||
1854 | next_local_tid |= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV; | 1870 | next_local_tid |= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV; |
1871 | t->tree = tree_new(t, t->id.oid); | ||
1855 | 1872 | ||
1856 | GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); | 1873 | GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); |
1857 | if (GNUNET_OK != | 1874 | if (GNUNET_OK != |
@@ -1866,6 +1883,8 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1866 | GNUNET_CONTAINER_multihashmap_get (peers, &pi[size - 1].hashPubKey); | 1883 | GNUNET_CONTAINER_multihashmap_get (peers, &pi[size - 1].hashPubKey); |
1867 | if (NULL == dest_peer_info) | 1884 | if (NULL == dest_peer_info) |
1868 | { | 1885 | { |
1886 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1887 | "MESH: Creating PeerInfo for destination.\n"); | ||
1869 | dest_peer_info = GNUNET_malloc (sizeof (struct MeshPeerInfo)); | 1888 | dest_peer_info = GNUNET_malloc (sizeof (struct MeshPeerInfo)); |
1870 | dest_peer_info->id = GNUNET_PEER_intern (&pi[size - 1]); | 1889 | dest_peer_info->id = GNUNET_PEER_intern (&pi[size - 1]); |
1871 | GNUNET_CONTAINER_multihashmap_put (peers, &pi[size - 1].hashPubKey, | 1890 | GNUNET_CONTAINER_multihashmap_put (peers, &pi[size - 1].hashPubKey, |
@@ -1875,22 +1894,30 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1875 | orig_peer_info = GNUNET_CONTAINER_multihashmap_get (peers, &pi->hashPubKey); | 1894 | orig_peer_info = GNUNET_CONTAINER_multihashmap_get (peers, &pi->hashPubKey); |
1876 | if (NULL == orig_peer_info) | 1895 | if (NULL == orig_peer_info) |
1877 | { | 1896 | { |
1897 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1898 | "MESH: Creating PeerInfo for origin.\n"); | ||
1878 | orig_peer_info = GNUNET_malloc (sizeof (struct MeshPeerInfo)); | 1899 | orig_peer_info = GNUNET_malloc (sizeof (struct MeshPeerInfo)); |
1879 | orig_peer_info->id = GNUNET_PEER_intern (pi); | 1900 | orig_peer_info->id = GNUNET_PEER_intern (pi); |
1880 | GNUNET_CONTAINER_multihashmap_put (peers, &pi->hashPubKey, orig_peer_info, | 1901 | GNUNET_CONTAINER_multihashmap_put (peers, &pi->hashPubKey, orig_peer_info, |
1881 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 1902 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
1882 | } | 1903 | } |
1883 | 1904 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Creating path...\n"); | |
1884 | path = path_new (size); | 1905 | path = path_new (size); |
1885 | own_pos = 0; | 1906 | own_pos = 0; |
1886 | for (i = 0; i < size; i++) | 1907 | for (i = 0; i < size; i++) |
1887 | { | 1908 | { |
1909 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1910 | "MESH: ... adding %s\n", | ||
1911 | GNUNET_i2s(&pi[i])); | ||
1888 | path->peers[i] = GNUNET_PEER_intern (&pi[i]); | 1912 | path->peers[i] = GNUNET_PEER_intern (&pi[i]); |
1889 | if (path->peers[i] == myid) | 1913 | if (path->peers[i] == myid) |
1890 | own_pos = i; | 1914 | own_pos = i; |
1891 | } | 1915 | } |
1916 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1917 | "MESH: Own position: %u\n", own_pos); | ||
1892 | if (own_pos == 0) | 1918 | if (own_pos == 0) |
1893 | { /* cannot be self, must be 'not found' */ | 1919 | { |
1920 | /* cannot be self, must be 'not found' */ | ||
1894 | /* create path: self not found in path through self */ | 1921 | /* create path: self not found in path through self */ |
1895 | GNUNET_break_op (0); | 1922 | GNUNET_break_op (0); |
1896 | path_destroy (path); | 1923 | path_destroy (path); |
@@ -1904,6 +1931,8 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1904 | struct MeshDataDescriptor *info; | 1931 | struct MeshDataDescriptor *info; |
1905 | unsigned int j; | 1932 | unsigned int j; |
1906 | 1933 | ||
1934 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1935 | "MESH: It's for us!\n"); | ||
1907 | path_add_to_origin (orig_peer_info, path); /* inverts path! */ | 1936 | path_add_to_origin (orig_peer_info, path); /* inverts path! */ |
1908 | info = GNUNET_malloc (sizeof (struct MeshDataDescriptor)); | 1937 | info = GNUNET_malloc (sizeof (struct MeshDataDescriptor)); |
1909 | info->origin = &t->id; | 1938 | info->origin = &t->id; |
@@ -1931,7 +1960,16 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1931 | } | 1960 | } |
1932 | else | 1961 | else |
1933 | { | 1962 | { |
1963 | struct MeshPeerPath *path2; | ||
1964 | |||
1965 | path2 = path_duplicate(path); | ||
1934 | /* It's for somebody else! Retransmit. */ | 1966 | /* It's for somebody else! Retransmit. */ |
1967 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1968 | "MESH: Retransmitting.\n"); | ||
1969 | path_add_to_peer(dest_peer_info, path); | ||
1970 | tunnel_add_peer(t, dest_peer_info); | ||
1971 | path = path_duplicate(path2); | ||
1972 | path_add_to_origin(orig_peer_info, path2); | ||
1935 | send_create_path(dest_peer_info, path, t); | 1973 | send_create_path(dest_peer_info, path, t); |
1936 | } | 1974 | } |
1937 | return GNUNET_OK; | 1975 | return GNUNET_OK; |
@@ -3235,19 +3273,19 @@ core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3235 | struct MeshPeerInfo *peer_info; | 3273 | struct MeshPeerInfo *peer_info; |
3236 | struct MeshPeerPath *path; | 3274 | struct MeshPeerPath *path; |
3237 | 3275 | ||
3238 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Peer connected\n"); | 3276 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Peer connected\n"); |
3239 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n", | 3277 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n", |
3240 | // GNUNET_h2s(&my_full_id.hashPubKey)); | 3278 | GNUNET_h2s(&my_full_id.hashPubKey)); |
3241 | peer_info = peer_info_get (peer); | 3279 | peer_info = peer_info_get (peer); |
3242 | if (myid == peer_info->id) | 3280 | if (myid == peer_info->id) |
3243 | { | 3281 | { |
3244 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (self)\n"); | 3282 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (self)\n"); |
3245 | return; | 3283 | return; |
3246 | } | 3284 | } |
3247 | else | 3285 | else |
3248 | { | 3286 | { |
3249 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n", | 3287 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n", |
3250 | // GNUNET_h2s(&peer->hashPubKey)); | 3288 | GNUNET_h2s(&peer->hashPubKey)); |
3251 | } | 3289 | } |
3252 | path = path_new (2); | 3290 | path = path_new (2); |
3253 | path->peers[0] = myid; | 3291 | path->peers[0] = myid; |
diff --git a/src/mesh/mesh_tunnel_tree.c b/src/mesh/mesh_tunnel_tree.c index da16bc95b..56f592de5 100644 --- a/src/mesh/mesh_tunnel_tree.c +++ b/src/mesh/mesh_tunnel_tree.c | |||
@@ -70,6 +70,24 @@ path_invert (struct MeshPeerPath *path) | |||
70 | } | 70 | } |
71 | 71 | ||
72 | 72 | ||
73 | /** | ||
74 | * Duplicate a path, incrementing short peer's rc. | ||
75 | * | ||
76 | * @param p The path to duplicate. | ||
77 | */ | ||
78 | struct MeshPeerPath * | ||
79 | path_duplicate (struct MeshPeerPath *path) | ||
80 | { | ||
81 | struct MeshPeerPath *aux; | ||
82 | unsigned int i; | ||
83 | |||
84 | aux = path_new(path->length); | ||
85 | memcpy (aux->peers, path->peers, path->length * sizeof(GNUNET_PEER_Id)); | ||
86 | for (i = 0; i < path->length; i++) | ||
87 | GNUNET_PEER_change_rc(path->peers[i], 1); | ||
88 | return aux; | ||
89 | } | ||
90 | |||
73 | 91 | ||
74 | /** | 92 | /** |
75 | * Find the first peer whom to send a packet to go down this path | 93 | * Find the first peer whom to send a packet to go down this path |
@@ -499,7 +517,7 @@ tree_add_path (struct MeshTunnelTree *t, | |||
499 | struct MeshTunnelTreeNode *c; | 517 | struct MeshTunnelTreeNode *c; |
500 | struct GNUNET_PeerIdentity id; | 518 | struct GNUNET_PeerIdentity id; |
501 | struct GNUNET_PeerIdentity *hop; | 519 | struct GNUNET_PeerIdentity *hop; |
502 | GNUNET_PEER_Id myid = t->me->peer; | 520 | GNUNET_PEER_Id myid; |
503 | int me; | 521 | int me; |
504 | unsigned int i; | 522 | unsigned int i; |
505 | 523 | ||
@@ -508,6 +526,9 @@ tree_add_path (struct MeshTunnelTree *t, | |||
508 | p->length, | 526 | p->length, |
509 | p->peers[p->length - 1], | 527 | p->peers[p->length - 1], |
510 | t->me->peer); | 528 | t->me->peer); |
529 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %p %p %p\n", t, t->root, t->me); | ||
530 | |||
531 | myid = t->me->peer; | ||
511 | GNUNET_assert(0 != p->length); | 532 | GNUNET_assert(0 != p->length); |
512 | parent = n = t->root; | 533 | parent = n = t->root; |
513 | if (n->peer != p->peers[0]) | 534 | if (n->peer != p->peers[0]) |
diff --git a/src/mesh/mesh_tunnel_tree.h b/src/mesh/mesh_tunnel_tree.h index f187e7957..509d254a1 100644 --- a/src/mesh/mesh_tunnel_tree.h +++ b/src/mesh/mesh_tunnel_tree.h | |||
@@ -172,6 +172,15 @@ path_invert (struct MeshPeerPath *p); | |||
172 | 172 | ||
173 | 173 | ||
174 | /** | 174 | /** |
175 | * Duplicate a path, incrementing short peer's rc. | ||
176 | * | ||
177 | * @param p The path to duplicate. | ||
178 | */ | ||
179 | struct MeshPeerPath * | ||
180 | path_duplicate (struct MeshPeerPath *path); | ||
181 | |||
182 | |||
183 | /** | ||
175 | * Find the first peer whom to send a packet to go down this path | 184 | * Find the first peer whom to send a packet to go down this path |
176 | * | 185 | * |
177 | * @param t The tunnel tree to use | 186 | * @param t The tunnel tree to use |
diff --git a/src/mesh/test_mesh_small.conf b/src/mesh/test_mesh_small.conf index 1015e4d44..833fab062 100644 --- a/src/mesh/test_mesh_small.conf +++ b/src/mesh/test_mesh_small.conf | |||
@@ -54,7 +54,7 @@ PORT = 10005 | |||
54 | DEBUG=YES | 54 | DEBUG=YES |
55 | ACCEPT_FROM = 127.0.0.1; | 55 | ACCEPT_FROM = 127.0.0.1; |
56 | HOSTNAME = localhost | 56 | HOSTNAME = localhost |
57 | # PREFIX = valgrind --leak-check=full | 57 | PREFIX = valgrind --leak-check=full |
58 | # PREFIX = xterm -geometry 100x85 -T peer1 -e gdb --args | 58 | # PREFIX = xterm -geometry 100x85 -T peer1 -e gdb --args |
59 | 59 | ||
60 | [testing] | 60 | [testing] |