diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-11-02 14:34:27 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-11-02 14:34:27 +0000 |
commit | 5d4dd95a17d90d532b52e1060dd259f80a333931 (patch) | |
tree | cbce3e30515d17f551814c7bfed09df72bf7f11a /src/mesh | |
parent | 5510235d61541aa1a52544918d8f3605efb40b5a (diff) | |
download | gnunet-5d4dd95a17d90d532b52e1060dd259f80a333931.tar.gz gnunet-5d4dd95a17d90d532b52e1060dd259f80a333931.zip |
Make tree library independent from tunnels, add cls to callbacks
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 35 | ||||
-rw-r--r-- | src/mesh/mesh_tunnel_tree.c | 40 | ||||
-rw-r--r-- | src/mesh/mesh_tunnel_tree.h | 36 | ||||
-rw-r--r-- | src/mesh/test_mesh_path_api.c | 18 |
4 files changed, 68 insertions, 61 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 9e37345d0..54f46379a 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -1496,7 +1496,7 @@ path_remove_from_peer (struct MeshPeerInfo *peer, | |||
1496 | if (NULL != aux) | 1496 | if (NULL != aux) |
1497 | { | 1497 | { |
1498 | /* No callback, as peer will be already disconnected */ | 1498 | /* No callback, as peer will be already disconnected */ |
1499 | tree_add_path(peer->tunnels[i]->tree, aux, NULL); | 1499 | tree_add_path(peer->tunnels[i]->tree, aux, NULL, NULL); |
1500 | } | 1500 | } |
1501 | else | 1501 | else |
1502 | { | 1502 | { |
@@ -1808,30 +1808,30 @@ tunnel_get (struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid) | |||
1808 | * Callback used to notify a client owner of a tunnel that a peer has | 1808 | * Callback used to notify a client owner of a tunnel that a peer has |
1809 | * disconnected, most likely because of a path change. | 1809 | * disconnected, most likely because of a path change. |
1810 | * | 1810 | * |
1811 | * @param n Node in the tree representing the disconnected peer | 1811 | * @param cls Closure (tunnel this notification is about). |
1812 | * | 1812 | * @param peer_id Short ID of disconnected peer. |
1813 | * FIXME: pass tunnel via cls, make param just a peer identity | ||
1814 | */ | 1813 | */ |
1815 | void | 1814 | void |
1816 | notify_peer_disconnected (const struct MeshTunnelTreeNode *n) | 1815 | notify_peer_disconnected (void *cls, GNUNET_PEER_Id peer_id) |
1817 | { | 1816 | { |
1817 | struct MeshTunnel *t = cls; | ||
1818 | struct MeshPeerInfo *peer; | 1818 | struct MeshPeerInfo *peer; |
1819 | struct MeshPathInfo *path_info; | 1819 | struct MeshPathInfo *path_info; |
1820 | 1820 | ||
1821 | if (NULL != n->t->client && NULL != nc) | 1821 | if (NULL != t->client && NULL != nc) |
1822 | { | 1822 | { |
1823 | struct GNUNET_MESH_PeerControl msg; | 1823 | struct GNUNET_MESH_PeerControl msg; |
1824 | msg.header.size = htons (sizeof (msg)); | 1824 | msg.header.size = htons (sizeof (msg)); |
1825 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL); | 1825 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL); |
1826 | msg.tunnel_id = htonl (n->t->local_tid); | 1826 | msg.tunnel_id = htonl (t->local_tid); |
1827 | GNUNET_PEER_resolve (n->peer, &msg.peer); | 1827 | GNUNET_PEER_resolve (peer_id, &msg.peer); |
1828 | GNUNET_SERVER_notification_context_unicast (nc, n->t->client->handle, | 1828 | GNUNET_SERVER_notification_context_unicast (nc, t->client->handle, |
1829 | &msg.header, GNUNET_NO); | 1829 | &msg.header, GNUNET_NO); |
1830 | } | 1830 | } |
1831 | peer = peer_info_get_short(n->peer); | 1831 | peer = peer_info_get_short(peer_id); |
1832 | path_info = GNUNET_malloc (sizeof (struct MeshPathInfo)); | 1832 | path_info = GNUNET_malloc (sizeof (struct MeshPathInfo)); |
1833 | path_info->peer = peer; | 1833 | path_info->peer = peer; |
1834 | path_info->t = n->t; | 1834 | path_info->t = t; |
1835 | GNUNET_SCHEDULER_add_now(&peer_info_connect_task, path_info); | 1835 | GNUNET_SCHEDULER_add_now(&peer_info_connect_task, path_info); |
1836 | } | 1836 | } |
1837 | 1837 | ||
@@ -1880,7 +1880,7 @@ tunnel_add_peer (struct MeshTunnel *t, struct MeshPeerInfo *peer) | |||
1880 | } | 1880 | } |
1881 | p = p->next; | 1881 | p = p->next; |
1882 | } | 1882 | } |
1883 | tree_add_path (t->tree, best_p, ¬ify_peer_disconnected); | 1883 | tree_add_path (t->tree, best_p, ¬ify_peer_disconnected, t); |
1884 | if (GNUNET_SCHEDULER_NO_TASK == t->path_refresh_task) | 1884 | if (GNUNET_SCHEDULER_NO_TASK == t->path_refresh_task) |
1885 | t->path_refresh_task = | 1885 | t->path_refresh_task = |
1886 | GNUNET_SCHEDULER_add_delayed (t->tree->refresh, &path_refresh, t); | 1886 | GNUNET_SCHEDULER_add_delayed (t->tree->refresh, &path_refresh, t); |
@@ -1910,7 +1910,7 @@ tunnel_add_path (struct MeshTunnel *t, | |||
1910 | struct GNUNET_PeerIdentity id; | 1910 | struct GNUNET_PeerIdentity id; |
1911 | 1911 | ||
1912 | GNUNET_assert (0 != own_pos); | 1912 | GNUNET_assert (0 != own_pos); |
1913 | tree_add_path(t->tree, p, NULL); | 1913 | tree_add_path(t->tree, p, NULL, NULL); |
1914 | if (NULL == t->tree->me) | 1914 | if (NULL == t->tree->me) |
1915 | t->tree->me = tree_find_peer(t->tree->root, p->peers[own_pos]); | 1915 | t->tree->me = tree_find_peer(t->tree->root, p->peers[own_pos]); |
1916 | if (own_pos < p->length - 1) | 1916 | if (own_pos < p->length - 1) |
@@ -1944,7 +1944,8 @@ tunnel_notify_connection_broken (struct MeshTunnel *t, | |||
1944 | pid = tree_notify_connection_broken (t->tree, | 1944 | pid = tree_notify_connection_broken (t->tree, |
1945 | p1, | 1945 | p1, |
1946 | p2, | 1946 | p2, |
1947 | ¬ify_peer_disconnected); | 1947 | ¬ify_peer_disconnected, |
1948 | t); | ||
1948 | if (myid != p1 && myid != p2) | 1949 | if (myid != p1 && myid != p2) |
1949 | { | 1950 | { |
1950 | return pid; | 1951 | return pid; |
@@ -2171,7 +2172,7 @@ static void | |||
2171 | tunnel_delete_peer (struct MeshTunnel *t, | 2172 | tunnel_delete_peer (struct MeshTunnel *t, |
2172 | GNUNET_PEER_Id peer) | 2173 | GNUNET_PEER_Id peer) |
2173 | { | 2174 | { |
2174 | GNUNET_break (GNUNET_OK == tree_del_peer (t->tree, peer, NULL)); | 2175 | GNUNET_break (GNUNET_OK == tree_del_peer (t->tree, peer, NULL, NULL)); |
2175 | if (NULL == t->tree->root) | 2176 | if (NULL == t->tree->root) |
2176 | tunnel_destroy (t); | 2177 | tunnel_destroy (t); |
2177 | } | 2178 | } |
@@ -2513,7 +2514,7 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2513 | next_local_tid = (next_local_tid + 1) | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV; | 2514 | next_local_tid = (next_local_tid + 1) | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV; |
2514 | t->local_tid = next_local_tid++; | 2515 | t->local_tid = next_local_tid++; |
2515 | next_local_tid = next_local_tid | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV; | 2516 | next_local_tid = next_local_tid | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV; |
2516 | t->tree = tree_new(t, t->id.oid); | 2517 | t->tree = tree_new(t->id.oid); |
2517 | 2518 | ||
2518 | GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); | 2519 | GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); |
2519 | if (GNUNET_OK != | 2520 | if (GNUNET_OK != |
@@ -3590,7 +3591,7 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client, | |||
3590 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 3591 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
3591 | return; | 3592 | return; |
3592 | } | 3593 | } |
3593 | t->tree = tree_new (t, myid); | 3594 | t->tree = tree_new (myid); |
3594 | t->tree->refresh = REFRESH_PATH_TIME; | 3595 | t->tree->refresh = REFRESH_PATH_TIME; |
3595 | t->tree->root->status = MESH_PEER_READY; | 3596 | t->tree->root->status = MESH_PEER_READY; |
3596 | t->tree->me = t->tree->root; | 3597 | t->tree->me = t->tree->root; |
diff --git a/src/mesh/mesh_tunnel_tree.c b/src/mesh/mesh_tunnel_tree.c index d052a3c4d..deb702604 100644 --- a/src/mesh/mesh_tunnel_tree.c +++ b/src/mesh/mesh_tunnel_tree.c | |||
@@ -293,7 +293,7 @@ tree_node_destroy (struct MeshTunnelTreeNode *parent) | |||
293 | * @return A newly allocated and initialized tunnel tree | 293 | * @return A newly allocated and initialized tunnel tree |
294 | */ | 294 | */ |
295 | struct MeshTunnelTree * | 295 | struct MeshTunnelTree * |
296 | tree_new (struct MeshTunnel *t, GNUNET_PEER_Id peer) | 296 | tree_new (GNUNET_PEER_Id peer) |
297 | { | 297 | { |
298 | struct MeshTunnelTree *tree; | 298 | struct MeshTunnelTree *tree; |
299 | 299 | ||
@@ -301,8 +301,6 @@ tree_new (struct MeshTunnel *t, GNUNET_PEER_Id peer) | |||
301 | tree->first_hops = GNUNET_CONTAINER_multihashmap_create(32); | 301 | tree->first_hops = GNUNET_CONTAINER_multihashmap_create(32); |
302 | tree->root = tree_node_new(NULL, peer); | 302 | tree->root = tree_node_new(NULL, peer); |
303 | tree->root->status = MESH_PEER_ROOT; | 303 | tree->root->status = MESH_PEER_ROOT; |
304 | tree->t = t; | ||
305 | tree->root->t = t; | ||
306 | 304 | ||
307 | return tree; | 305 | return tree; |
308 | } | 306 | } |
@@ -344,7 +342,8 @@ tree_find_peer (struct MeshTunnelTreeNode *parent, GNUNET_PEER_Id peer_id) | |||
344 | static void | 342 | static void |
345 | tree_mark_peers_disconnected (struct MeshTunnelTree *tree, | 343 | tree_mark_peers_disconnected (struct MeshTunnelTree *tree, |
346 | struct MeshTunnelTreeNode *parent, | 344 | struct MeshTunnelTreeNode *parent, |
347 | MeshNodeDisconnectCB cb) | 345 | MeshNodeDisconnectCB cb, |
346 | void *cbcls) | ||
348 | { | 347 | { |
349 | struct GNUNET_PeerIdentity *pi; | 348 | struct GNUNET_PeerIdentity *pi; |
350 | struct GNUNET_PeerIdentity id; | 349 | struct GNUNET_PeerIdentity id; |
@@ -352,12 +351,12 @@ tree_mark_peers_disconnected (struct MeshTunnelTree *tree, | |||
352 | 351 | ||
353 | for (n = parent->children_head; NULL != n; n = n->next) | 352 | for (n = parent->children_head; NULL != n; n = n->next) |
354 | { | 353 | { |
355 | tree_mark_peers_disconnected (tree, n, cb); | 354 | tree_mark_peers_disconnected (tree, n, cb, cbcls); |
356 | } | 355 | } |
357 | if (MESH_PEER_READY == parent->status) | 356 | if (MESH_PEER_READY == parent->status) |
358 | { | 357 | { |
359 | if (NULL != cb) | 358 | if (NULL != cb) |
360 | cb (parent); | 359 | cb (cbcls, parent->peer); |
361 | parent->status = MESH_PEER_RECONNECTING; | 360 | parent->status = MESH_PEER_RECONNECTING; |
362 | } | 361 | } |
363 | 362 | ||
@@ -448,6 +447,7 @@ tree_update_first_hops (struct MeshTunnelTree *tree, | |||
448 | * @param t Tunnel tree where to delete the path from. | 447 | * @param t Tunnel tree where to delete the path from. |
449 | * @param peer Destination peer whose path we want to remove. | 448 | * @param peer Destination peer whose path we want to remove. |
450 | * @param cb Callback to use to notify about disconnected peers. | 449 | * @param cb Callback to use to notify about disconnected peers. |
450 | * @param cbcls Closure for cb. | ||
451 | * | 451 | * |
452 | * @return pointer to the pathless node. | 452 | * @return pointer to the pathless node. |
453 | * NULL when not found | 453 | * NULL when not found |
@@ -455,7 +455,8 @@ tree_update_first_hops (struct MeshTunnelTree *tree, | |||
455 | struct MeshTunnelTreeNode * | 455 | struct MeshTunnelTreeNode * |
456 | tree_del_path (struct MeshTunnelTree *t, | 456 | tree_del_path (struct MeshTunnelTree *t, |
457 | GNUNET_PEER_Id peer_id, | 457 | GNUNET_PEER_Id peer_id, |
458 | MeshNodeDisconnectCB cb) | 458 | MeshNodeDisconnectCB cb, |
459 | void *cbcls) | ||
459 | { | 460 | { |
460 | struct MeshTunnelTreeNode *parent; | 461 | struct MeshTunnelTreeNode *parent; |
461 | struct MeshTunnelTreeNode *node; | 462 | struct MeshTunnelTreeNode *node; |
@@ -510,7 +511,7 @@ tree_del_path (struct MeshTunnelTree *t, | |||
510 | GNUNET_i2s (&id)); | 511 | GNUNET_i2s (&id)); |
511 | #endif | 512 | #endif |
512 | 513 | ||
513 | tree_mark_peers_disconnected (t, node, cb); | 514 | tree_mark_peers_disconnected (t, node, cb, cbcls); |
514 | 515 | ||
515 | return node; | 516 | return node; |
516 | } | 517 | } |
@@ -567,7 +568,8 @@ tree_get_path_to_peer(struct MeshTunnelTree *t, GNUNET_PEER_Id peer) | |||
567 | * | 568 | * |
568 | * @param t Tunnel where to add the new path. | 569 | * @param t Tunnel where to add the new path. |
569 | * @param p Path to be integrated. | 570 | * @param p Path to be integrated. |
570 | * @param cb Callback to use to notify about peers temporarily disconnecting | 571 | * @param cb Callback to use to notify about peers temporarily disconnecting. |
572 | * @param cbcls Closure for cb. | ||
571 | * | 573 | * |
572 | * @return GNUNET_OK in case of success. | 574 | * @return GNUNET_OK in case of success. |
573 | * GNUNET_SYSERR in case of error. | 575 | * GNUNET_SYSERR in case of error. |
@@ -579,7 +581,8 @@ tree_get_path_to_peer(struct MeshTunnelTree *t, GNUNET_PEER_Id peer) | |||
579 | int | 581 | int |
580 | tree_add_path (struct MeshTunnelTree *t, | 582 | tree_add_path (struct MeshTunnelTree *t, |
581 | const struct MeshPeerPath *p, | 583 | const struct MeshPeerPath *p, |
582 | MeshNodeDisconnectCB cb) | 584 | MeshNodeDisconnectCB cb, |
585 | void *cbcls) | ||
583 | { | 586 | { |
584 | struct MeshTunnelTreeNode *parent; | 587 | struct MeshTunnelTreeNode *parent; |
585 | struct MeshTunnelTreeNode *oldnode; | 588 | struct MeshTunnelTreeNode *oldnode; |
@@ -611,7 +614,7 @@ tree_add_path (struct MeshTunnelTree *t, | |||
611 | } | 614 | } |
612 | if (1 == p->length) | 615 | if (1 == p->length) |
613 | return GNUNET_OK; | 616 | return GNUNET_OK; |
614 | oldnode = tree_del_path (t, p->peers[p->length - 1], cb); | 617 | oldnode = tree_del_path (t, p->peers[p->length - 1], cb, cbcls); |
615 | /* Look for the first node that is not already present in the tree | 618 | /* Look for the first node that is not already present in the tree |
616 | * | 619 | * |
617 | * Assuming that the tree is somewhat balanced, O(log n * log N). | 620 | * Assuming that the tree is somewhat balanced, O(log n * log N). |
@@ -689,7 +692,6 @@ tree_add_path (struct MeshTunnelTree *t, | |||
689 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: Creating new node.\n"); | 692 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: Creating new node.\n"); |
690 | #endif | 693 | #endif |
691 | n = tree_node_new(parent, p->peers[i]); | 694 | n = tree_node_new(parent, p->peers[i]); |
692 | n->t = t->t; | ||
693 | n->status = MESH_PEER_RELAY; | 695 | n->status = MESH_PEER_RELAY; |
694 | if (n->peer == myid) | 696 | if (n->peer == myid) |
695 | t->me = n; | 697 | t->me = n; |
@@ -727,6 +729,7 @@ tree_add_path (struct MeshTunnelTree *t, | |||
727 | * @param p1 Short id of one of the peers (order unimportant) | 729 | * @param p1 Short id of one of the peers (order unimportant) |
728 | * @param p2 Short id of one of the peers (order unimportant) | 730 | * @param p2 Short id of one of the peers (order unimportant) |
729 | * @param cb Function to call for every peer that is marked as disconnected. | 731 | * @param cb Function to call for every peer that is marked as disconnected. |
732 | * @param cbcls Closure for cb. | ||
730 | * | 733 | * |
731 | * @return Short ID of the first disconnected peer in the tree. | 734 | * @return Short ID of the first disconnected peer in the tree. |
732 | */ | 735 | */ |
@@ -734,7 +737,8 @@ GNUNET_PEER_Id | |||
734 | tree_notify_connection_broken (struct MeshTunnelTree *t, | 737 | tree_notify_connection_broken (struct MeshTunnelTree *t, |
735 | GNUNET_PEER_Id p1, | 738 | GNUNET_PEER_Id p1, |
736 | GNUNET_PEER_Id p2, | 739 | GNUNET_PEER_Id p2, |
737 | MeshNodeDisconnectCB cb) | 740 | MeshNodeDisconnectCB cb, |
741 | void *cbcls) | ||
738 | { | 742 | { |
739 | struct MeshTunnelTreeNode *n; | 743 | struct MeshTunnelTreeNode *n; |
740 | struct MeshTunnelTreeNode *c; | 744 | struct MeshTunnelTreeNode *c; |
@@ -744,7 +748,7 @@ tree_notify_connection_broken (struct MeshTunnelTree *t, | |||
744 | return 0; | 748 | return 0; |
745 | if (NULL != n->parent && n->parent->peer == p2) | 749 | if (NULL != n->parent && n->parent->peer == p2) |
746 | { | 750 | { |
747 | tree_mark_peers_disconnected(t, n, cb); | 751 | tree_mark_peers_disconnected(t, n, cb, cbcls); |
748 | GNUNET_CONTAINER_DLL_remove(n->parent->children_head, | 752 | GNUNET_CONTAINER_DLL_remove(n->parent->children_head, |
749 | n->parent->children_tail, | 753 | n->parent->children_tail, |
750 | n); | 754 | n); |
@@ -757,7 +761,7 @@ tree_notify_connection_broken (struct MeshTunnelTree *t, | |||
757 | { | 761 | { |
758 | if (c->peer == p2) | 762 | if (c->peer == p2) |
759 | { | 763 | { |
760 | tree_mark_peers_disconnected(t, c, cb); | 764 | tree_mark_peers_disconnected(t, c, cb, cbcls); |
761 | GNUNET_CONTAINER_DLL_remove(n->children_head, | 765 | GNUNET_CONTAINER_DLL_remove(n->children_head, |
762 | n->children_tail, | 766 | n->children_tail, |
763 | c); | 767 | c); |
@@ -780,17 +784,19 @@ tree_notify_connection_broken (struct MeshTunnelTree *t, | |||
780 | * @param t Tunnel tree to use. | 784 | * @param t Tunnel tree to use. |
781 | * @param peer Short ID of the peer to remove from the tunnel tree. | 785 | * @param peer Short ID of the peer to remove from the tunnel tree. |
782 | * @param cb Callback to notify client of disconnected peers. | 786 | * @param cb Callback to notify client of disconnected peers. |
787 | * @param cbcls Closure for cb. | ||
783 | * | 788 | * |
784 | * @return GNUNET_OK or GNUNET_SYSERR | 789 | * @return GNUNET_OK or GNUNET_SYSERR |
785 | */ | 790 | */ |
786 | int | 791 | int |
787 | tree_del_peer (struct MeshTunnelTree *t, | 792 | tree_del_peer (struct MeshTunnelTree *t, |
788 | GNUNET_PEER_Id peer, | 793 | GNUNET_PEER_Id peer, |
789 | MeshNodeDisconnectCB cb) | 794 | MeshNodeDisconnectCB cb, |
795 | void *cbcls) | ||
790 | { | 796 | { |
791 | struct MeshTunnelTreeNode *n; | 797 | struct MeshTunnelTreeNode *n; |
792 | 798 | ||
793 | n = tree_del_path(t, peer, cb); | 799 | n = tree_del_path(t, peer, cb, cbcls); |
794 | if (NULL == n) | 800 | if (NULL == n) |
795 | return GNUNET_SYSERR; | 801 | return GNUNET_SYSERR; |
796 | GNUNET_break_op (NULL == n->children_head); | 802 | GNUNET_break_op (NULL == n->children_head); |
diff --git a/src/mesh/mesh_tunnel_tree.h b/src/mesh/mesh_tunnel_tree.h index 59a60839d..2cb28a28c 100644 --- a/src/mesh/mesh_tunnel_tree.h +++ b/src/mesh/mesh_tunnel_tree.h | |||
@@ -61,11 +61,6 @@ struct MeshPeerPath | |||
61 | struct MeshTunnelTreeNode | 61 | struct MeshTunnelTreeNode |
62 | { | 62 | { |
63 | /** | 63 | /** |
64 | * Tunnel this node belongs to (and therefore tree) | ||
65 | */ | ||
66 | struct MeshTunnel *t; | ||
67 | |||
68 | /** | ||
69 | * Peer this node describes | 64 | * Peer this node describes |
70 | */ | 65 | */ |
71 | GNUNET_PEER_Id peer; | 66 | GNUNET_PEER_Id peer; |
@@ -113,11 +108,6 @@ struct MeshTunnelTree | |||
113 | struct GNUNET_TIME_Relative refresh; | 108 | struct GNUNET_TIME_Relative refresh; |
114 | 109 | ||
115 | /** | 110 | /** |
116 | * Tunnel this path belongs to | ||
117 | */ | ||
118 | struct MeshTunnel *t; | ||
119 | |||
120 | /** | ||
121 | * Root node of peer tree | 111 | * Root node of peer tree |
122 | */ | 112 | */ |
123 | struct MeshTunnelTreeNode *root; | 113 | struct MeshTunnelTreeNode *root; |
@@ -236,9 +226,11 @@ path_destroy (struct MeshPeerPath *p); | |||
236 | /** | 226 | /** |
237 | * Method called whenever a node has been marked as disconnected. | 227 | * Method called whenever a node has been marked as disconnected. |
238 | * | 228 | * |
239 | * @param node peer identity the tunnel stopped working with | 229 | * @param cls Closure. |
230 | * @param peer_id short ID of peer that is no longer reachable. | ||
240 | */ | 231 | */ |
241 | typedef void (*MeshNodeDisconnectCB) (const struct MeshTunnelTreeNode * node); | 232 | typedef void (*MeshNodeDisconnectCB) (void *cls, |
233 | GNUNET_PEER_Id peer_id); | ||
242 | 234 | ||
243 | 235 | ||
244 | /** | 236 | /** |
@@ -250,7 +242,7 @@ typedef void (*MeshNodeDisconnectCB) (const struct MeshTunnelTreeNode * node); | |||
250 | * @return A newly allocated and initialized tunnel tree | 242 | * @return A newly allocated and initialized tunnel tree |
251 | */ | 243 | */ |
252 | struct MeshTunnelTree * | 244 | struct MeshTunnelTree * |
253 | tree_new (struct MeshTunnel *t, GNUNET_PEER_Id peer); | 245 | tree_new (GNUNET_PEER_Id peer); |
254 | 246 | ||
255 | 247 | ||
256 | /** | 248 | /** |
@@ -288,6 +280,7 @@ tree_update_first_hops (struct MeshTunnelTree *tree, | |||
288 | * @param peer Destination peer whose path we want to remove. | 280 | * @param peer Destination peer whose path we want to remove. |
289 | * @param cb Callback to use to notify about which peers are going to be | 281 | * @param cb Callback to use to notify about which peers are going to be |
290 | * disconnected. | 282 | * disconnected. |
283 | * @param cbcls Closure for cb. | ||
291 | * | 284 | * |
292 | * @return pointer to the pathless node. | 285 | * @return pointer to the pathless node. |
293 | * NULL when not found | 286 | * NULL when not found |
@@ -295,7 +288,8 @@ tree_update_first_hops (struct MeshTunnelTree *tree, | |||
295 | struct MeshTunnelTreeNode * | 288 | struct MeshTunnelTreeNode * |
296 | tree_del_path (struct MeshTunnelTree *t, | 289 | tree_del_path (struct MeshTunnelTree *t, |
297 | GNUNET_PEER_Id peer, | 290 | GNUNET_PEER_Id peer, |
298 | MeshNodeDisconnectCB cb); | 291 | MeshNodeDisconnectCB cb, |
292 | void *cbcls); | ||
299 | 293 | ||
300 | 294 | ||
301 | /** | 295 | /** |
@@ -318,7 +312,8 @@ tree_get_path_to_peer(struct MeshTunnelTree *t, | |||
318 | * | 312 | * |
319 | * @param t Tunnel where to add the new path. | 313 | * @param t Tunnel where to add the new path. |
320 | * @param p Path to be integrated. | 314 | * @param p Path to be integrated. |
321 | * @param cb Callback to use to notify about peers temporarily disconnecting | 315 | * @param cb Callback to use to notify about peers temporarily disconnecting. |
316 | * @param cbcls Closure for cb. | ||
322 | * | 317 | * |
323 | * @return GNUNET_OK in case of success. | 318 | * @return GNUNET_OK in case of success. |
324 | * GNUNET_SYSERR in case of error. | 319 | * GNUNET_SYSERR in case of error. |
@@ -326,7 +321,8 @@ tree_get_path_to_peer(struct MeshTunnelTree *t, | |||
326 | int | 321 | int |
327 | tree_add_path (struct MeshTunnelTree *t, | 322 | tree_add_path (struct MeshTunnelTree *t, |
328 | const struct MeshPeerPath *p, | 323 | const struct MeshPeerPath *p, |
329 | MeshNodeDisconnectCB cb); | 324 | MeshNodeDisconnectCB cb, |
325 | void *cbcls); | ||
330 | 326 | ||
331 | 327 | ||
332 | /** | 328 | /** |
@@ -337,6 +333,7 @@ tree_add_path (struct MeshTunnelTree *t, | |||
337 | * @param p1 Short id of one of the peers (order unimportant) | 333 | * @param p1 Short id of one of the peers (order unimportant) |
338 | * @param p2 Short id of one of the peers (order unimportant) | 334 | * @param p2 Short id of one of the peers (order unimportant) |
339 | * @param cb Function to call for every peer that is marked as disconnected. | 335 | * @param cb Function to call for every peer that is marked as disconnected. |
336 | * @param cbcls Closure for cb. | ||
340 | * | 337 | * |
341 | * @return Short ID of the first disconnected peer in the tree. | 338 | * @return Short ID of the first disconnected peer in the tree. |
342 | */ | 339 | */ |
@@ -344,7 +341,8 @@ GNUNET_PEER_Id | |||
344 | tree_notify_connection_broken (struct MeshTunnelTree *t, | 341 | tree_notify_connection_broken (struct MeshTunnelTree *t, |
345 | GNUNET_PEER_Id p1, | 342 | GNUNET_PEER_Id p1, |
346 | GNUNET_PEER_Id p2, | 343 | GNUNET_PEER_Id p2, |
347 | MeshNodeDisconnectCB cb); | 344 | MeshNodeDisconnectCB cb, |
345 | void *cbcls); | ||
348 | 346 | ||
349 | 347 | ||
350 | /** | 348 | /** |
@@ -356,13 +354,15 @@ tree_notify_connection_broken (struct MeshTunnelTree *t, | |||
356 | * @param t Tunnel tree to use. | 354 | * @param t Tunnel tree to use. |
357 | * @param peer Short ID of the peer to remove from the tunnel tree. | 355 | * @param peer Short ID of the peer to remove from the tunnel tree. |
358 | * @param cb Callback to notify client of disconnected peers. | 356 | * @param cb Callback to notify client of disconnected peers. |
357 | * @param cbcls Closure for cb. | ||
359 | * | 358 | * |
360 | * @return GNUNET_OK or GNUNET_SYSERR | 359 | * @return GNUNET_OK or GNUNET_SYSERR |
361 | */ | 360 | */ |
362 | int | 361 | int |
363 | tree_del_peer (struct MeshTunnelTree *t, | 362 | tree_del_peer (struct MeshTunnelTree *t, |
364 | GNUNET_PEER_Id peer, | 363 | GNUNET_PEER_Id peer, |
365 | MeshNodeDisconnectCB cb); | 364 | MeshNodeDisconnectCB cb, |
365 | void *cbcls); | ||
366 | 366 | ||
367 | /** | 367 | /** |
368 | * Print the tree on stderr | 368 | * Print the tree on stderr |
diff --git a/src/mesh/test_mesh_path_api.c b/src/mesh/test_mesh_path_api.c index e7c2a6fdf..45c4f3c14 100644 --- a/src/mesh/test_mesh_path_api.c +++ b/src/mesh/test_mesh_path_api.c | |||
@@ -40,9 +40,9 @@ struct GNUNET_PeerIdentity* pi[10]; | |||
40 | struct MeshTunnelTree *tree; | 40 | struct MeshTunnelTree *tree; |
41 | 41 | ||
42 | static void | 42 | static void |
43 | cb (const struct MeshTunnelTreeNode *n) | 43 | cb (void *cls, GNUNET_PEER_Id peer_id) |
44 | { | 44 | { |
45 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: CB: Disconnected %u\n", n->peer); | 45 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: CB: Disconnected %u\n", peer_id); |
46 | if(0 == cb_call) | 46 | if(0 == cb_call) |
47 | { | 47 | { |
48 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: and it shouldn't!\n"); | 48 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: and it shouldn't!\n"); |
@@ -181,7 +181,7 @@ main (int argc, char *argv[]) | |||
181 | path->length = 4; | 181 | path->length = 4; |
182 | 182 | ||
183 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3 4\n"); | 183 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3 4\n"); |
184 | tree_add_path(tree, path, &cb); | 184 | tree_add_path(tree, path, &cb, NULL); |
185 | tree_debug(tree); | 185 | tree_debug(tree); |
186 | path1 = tree_get_path_to_peer(tree, 4); | 186 | path1 = tree_get_path_to_peer(tree, 4); |
187 | if (path->length != path1->length || | 187 | if (path->length != path1->length || |
@@ -198,7 +198,7 @@ main (int argc, char *argv[]) | |||
198 | 198 | ||
199 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding second path: 1 2 3\n"); | 199 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding second path: 1 2 3\n"); |
200 | path->length--; | 200 | path->length--; |
201 | tree_add_path(tree, path, &cb); | 201 | tree_add_path(tree, path, &cb, NULL); |
202 | tree_debug(tree); | 202 | tree_debug(tree); |
203 | 203 | ||
204 | test_assert (4, MESH_PEER_SEARCHING, 0, 2); | 204 | test_assert (4, MESH_PEER_SEARCHING, 0, 2); |
@@ -209,7 +209,7 @@ main (int argc, char *argv[]) | |||
209 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding third path...\n"); | 209 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding third path...\n"); |
210 | path->length++; | 210 | path->length++; |
211 | path->peers[3] = 5; | 211 | path->peers[3] = 5; |
212 | tree_add_path(tree, path, &cb); | 212 | tree_add_path(tree, path, &cb, NULL); |
213 | tree_debug(tree); | 213 | tree_debug(tree); |
214 | 214 | ||
215 | test_assert (5, MESH_PEER_SEARCHING, 0, 2); | 215 | test_assert (5, MESH_PEER_SEARCHING, 0, 2); |
@@ -222,7 +222,7 @@ main (int argc, char *argv[]) | |||
222 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path...\n"); | 222 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path...\n"); |
223 | node->status = MESH_PEER_READY; | 223 | node->status = MESH_PEER_READY; |
224 | cb_call = 1; | 224 | cb_call = 1; |
225 | node2 = tree_del_path(tree, 5, &cb); | 225 | node2 = tree_del_path(tree, 5, &cb, NULL); |
226 | tree_debug(tree); | 226 | tree_debug(tree); |
227 | if (cb_call != 0) | 227 | if (cb_call != 0) |
228 | { | 228 | { |
@@ -249,7 +249,7 @@ main (int argc, char *argv[]) | |||
249 | path->peers[1] = 4; | 249 | path->peers[1] = 4; |
250 | cb_call = 1; | 250 | cb_call = 1; |
251 | tree_find_peer(tree->root, 4)->status = MESH_PEER_READY; | 251 | tree_find_peer(tree->root, 4)->status = MESH_PEER_READY; |
252 | tree_add_path(tree, path, cb); | 252 | tree_add_path(tree, path, &cb, NULL); |
253 | tree_debug(tree); | 253 | tree_debug(tree); |
254 | if (cb_call != 0) | 254 | if (cb_call != 0) |
255 | { | 255 | { |
@@ -287,7 +287,7 @@ main (int argc, char *argv[]) | |||
287 | path->length = 3; | 287 | path->length = 3; |
288 | 288 | ||
289 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3\n"); | 289 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3\n"); |
290 | tree_add_path(tree, path, &cb); | 290 | tree_add_path(tree, path, &cb, NULL); |
291 | tree_debug(tree); | 291 | tree_debug(tree); |
292 | tree->me = tree_find_peer (tree->root, 2); | 292 | tree->me = tree_find_peer (tree->root, 2); |
293 | 293 | ||
@@ -296,7 +296,7 @@ main (int argc, char *argv[]) | |||
296 | test_assert (1, MESH_PEER_ROOT, 1, 0); | 296 | test_assert (1, MESH_PEER_ROOT, 1, 0); |
297 | 297 | ||
298 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding same path: 1 2 3\n"); | 298 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding same path: 1 2 3\n"); |
299 | tree_add_path(tree, path, &cb); | 299 | tree_add_path(tree, path, &cb, NULL); |
300 | 300 | ||
301 | GNUNET_free (path->peers); | 301 | GNUNET_free (path->peers); |
302 | GNUNET_free (path); | 302 | GNUNET_free (path); |