[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r17924 - gnunet/src/mesh
From: |
gnunet |
Subject: |
[GNUnet-SVN] r17924 - gnunet/src/mesh |
Date: |
Wed, 2 Nov 2011 15:34:27 +0100 |
Author: bartpolot
Date: 2011-11-02 15:34:27 +0100 (Wed, 02 Nov 2011)
New Revision: 17924
Modified:
gnunet/src/mesh/gnunet-service-mesh.c
gnunet/src/mesh/mesh_tunnel_tree.c
gnunet/src/mesh/mesh_tunnel_tree.h
gnunet/src/mesh/test_mesh_path_api.c
Log:
Make tree library independent from tunnels, add cls to callbacks
Modified: gnunet/src/mesh/gnunet-service-mesh.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh.c 2011-11-02 14:07:50 UTC (rev
17923)
+++ gnunet/src/mesh/gnunet-service-mesh.c 2011-11-02 14:34:27 UTC (rev
17924)
@@ -1496,7 +1496,7 @@
if (NULL != aux)
{
/* No callback, as peer will be already disconnected */
- tree_add_path(peer->tunnels[i]->tree, aux, NULL);
+ tree_add_path(peer->tunnels[i]->tree, aux, NULL, NULL);
}
else
{
@@ -1808,30 +1808,30 @@
* Callback used to notify a client owner of a tunnel that a peer has
* disconnected, most likely because of a path change.
*
- * @param n Node in the tree representing the disconnected peer
- *
- * FIXME: pass tunnel via cls, make param just a peer identity
+ * @param cls Closure (tunnel this notification is about).
+ * @param peer_id Short ID of disconnected peer.
*/
void
-notify_peer_disconnected (const struct MeshTunnelTreeNode *n)
+notify_peer_disconnected (void *cls, GNUNET_PEER_Id peer_id)
{
+ struct MeshTunnel *t = cls;
struct MeshPeerInfo *peer;
struct MeshPathInfo *path_info;
- if (NULL != n->t->client && NULL != nc)
+ if (NULL != t->client && NULL != nc)
{
struct GNUNET_MESH_PeerControl msg;
msg.header.size = htons (sizeof (msg));
msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL);
- msg.tunnel_id = htonl (n->t->local_tid);
- GNUNET_PEER_resolve (n->peer, &msg.peer);
- GNUNET_SERVER_notification_context_unicast (nc, n->t->client->handle,
+ msg.tunnel_id = htonl (t->local_tid);
+ GNUNET_PEER_resolve (peer_id, &msg.peer);
+ GNUNET_SERVER_notification_context_unicast (nc, t->client->handle,
&msg.header, GNUNET_NO);
}
- peer = peer_info_get_short(n->peer);
+ peer = peer_info_get_short(peer_id);
path_info = GNUNET_malloc (sizeof (struct MeshPathInfo));
path_info->peer = peer;
- path_info->t = n->t;
+ path_info->t = t;
GNUNET_SCHEDULER_add_now(&peer_info_connect_task, path_info);
}
@@ -1880,7 +1880,7 @@
}
p = p->next;
}
- tree_add_path (t->tree, best_p, ¬ify_peer_disconnected);
+ tree_add_path (t->tree, best_p, ¬ify_peer_disconnected, t);
if (GNUNET_SCHEDULER_NO_TASK == t->path_refresh_task)
t->path_refresh_task =
GNUNET_SCHEDULER_add_delayed (t->tree->refresh, &path_refresh, t);
@@ -1910,7 +1910,7 @@
struct GNUNET_PeerIdentity id;
GNUNET_assert (0 != own_pos);
- tree_add_path(t->tree, p, NULL);
+ tree_add_path(t->tree, p, NULL, NULL);
if (NULL == t->tree->me)
t->tree->me = tree_find_peer(t->tree->root, p->peers[own_pos]);
if (own_pos < p->length - 1)
@@ -1944,7 +1944,8 @@
pid = tree_notify_connection_broken (t->tree,
p1,
p2,
- ¬ify_peer_disconnected);
+ ¬ify_peer_disconnected,
+ t);
if (myid != p1 && myid != p2)
{
return pid;
@@ -2171,7 +2172,7 @@
tunnel_delete_peer (struct MeshTunnel *t,
GNUNET_PEER_Id peer)
{
- GNUNET_break (GNUNET_OK == tree_del_peer (t->tree, peer, NULL));
+ GNUNET_break (GNUNET_OK == tree_del_peer (t->tree, peer, NULL, NULL));
if (NULL == t->tree->root)
tunnel_destroy (t);
}
@@ -2513,7 +2514,7 @@
next_local_tid = (next_local_tid + 1) | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV;
t->local_tid = next_local_tid++;
next_local_tid = next_local_tid | GNUNET_MESH_LOCAL_TUNNEL_ID_SERV;
- t->tree = tree_new(t, t->id.oid);
+ t->tree = tree_new(t->id.oid);
GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash);
if (GNUNET_OK !=
@@ -3590,7 +3591,7 @@
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- t->tree = tree_new (t, myid);
+ t->tree = tree_new (myid);
t->tree->refresh = REFRESH_PATH_TIME;
t->tree->root->status = MESH_PEER_READY;
t->tree->me = t->tree->root;
Modified: gnunet/src/mesh/mesh_tunnel_tree.c
===================================================================
--- gnunet/src/mesh/mesh_tunnel_tree.c 2011-11-02 14:07:50 UTC (rev 17923)
+++ gnunet/src/mesh/mesh_tunnel_tree.c 2011-11-02 14:34:27 UTC (rev 17924)
@@ -293,7 +293,7 @@
* @return A newly allocated and initialized tunnel tree
*/
struct MeshTunnelTree *
-tree_new (struct MeshTunnel *t, GNUNET_PEER_Id peer)
+tree_new (GNUNET_PEER_Id peer)
{
struct MeshTunnelTree *tree;
@@ -301,8 +301,6 @@
tree->first_hops = GNUNET_CONTAINER_multihashmap_create(32);
tree->root = tree_node_new(NULL, peer);
tree->root->status = MESH_PEER_ROOT;
- tree->t = t;
- tree->root->t = t;
return tree;
}
@@ -344,7 +342,8 @@
static void
tree_mark_peers_disconnected (struct MeshTunnelTree *tree,
struct MeshTunnelTreeNode *parent,
- MeshNodeDisconnectCB cb)
+ MeshNodeDisconnectCB cb,
+ void *cbcls)
{
struct GNUNET_PeerIdentity *pi;
struct GNUNET_PeerIdentity id;
@@ -352,12 +351,12 @@
for (n = parent->children_head; NULL != n; n = n->next)
{
- tree_mark_peers_disconnected (tree, n, cb);
+ tree_mark_peers_disconnected (tree, n, cb, cbcls);
}
if (MESH_PEER_READY == parent->status)
{
if (NULL != cb)
- cb (parent);
+ cb (cbcls, parent->peer);
parent->status = MESH_PEER_RECONNECTING;
}
@@ -448,6 +447,7 @@
* @param t Tunnel tree where to delete the path from.
* @param peer Destination peer whose path we want to remove.
* @param cb Callback to use to notify about disconnected peers.
+ * @param cbcls Closure for cb.
*
* @return pointer to the pathless node.
* NULL when not found
@@ -455,7 +455,8 @@
struct MeshTunnelTreeNode *
tree_del_path (struct MeshTunnelTree *t,
GNUNET_PEER_Id peer_id,
- MeshNodeDisconnectCB cb)
+ MeshNodeDisconnectCB cb,
+ void *cbcls)
{
struct MeshTunnelTreeNode *parent;
struct MeshTunnelTreeNode *node;
@@ -510,7 +511,7 @@
GNUNET_i2s (&id));
#endif
- tree_mark_peers_disconnected (t, node, cb);
+ tree_mark_peers_disconnected (t, node, cb, cbcls);
return node;
}
@@ -567,7 +568,8 @@
*
* @param t Tunnel where to add the new path.
* @param p Path to be integrated.
- * @param cb Callback to use to notify about peers temporarily disconnecting
+ * @param cb Callback to use to notify about peers temporarily disconnecting.
+ * @param cbcls Closure for cb.
*
* @return GNUNET_OK in case of success.
* GNUNET_SYSERR in case of error.
@@ -579,7 +581,8 @@
int
tree_add_path (struct MeshTunnelTree *t,
const struct MeshPeerPath *p,
- MeshNodeDisconnectCB cb)
+ MeshNodeDisconnectCB cb,
+ void *cbcls)
{
struct MeshTunnelTreeNode *parent;
struct MeshTunnelTreeNode *oldnode;
@@ -611,7 +614,7 @@
}
if (1 == p->length)
return GNUNET_OK;
- oldnode = tree_del_path (t, p->peers[p->length - 1], cb);
+ oldnode = tree_del_path (t, p->peers[p->length - 1], cb, cbcls);
/* Look for the first node that is not already present in the tree
*
* Assuming that the tree is somewhat balanced, O(log n * log N).
@@ -689,7 +692,6 @@
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: Creating new node.\n");
#endif
n = tree_node_new(parent, p->peers[i]);
- n->t = t->t;
n->status = MESH_PEER_RELAY;
if (n->peer == myid)
t->me = n;
@@ -727,6 +729,7 @@
* @param p1 Short id of one of the peers (order unimportant)
* @param p2 Short id of one of the peers (order unimportant)
* @param cb Function to call for every peer that is marked as disconnected.
+ * @param cbcls Closure for cb.
*
* @return Short ID of the first disconnected peer in the tree.
*/
@@ -734,7 +737,8 @@
tree_notify_connection_broken (struct MeshTunnelTree *t,
GNUNET_PEER_Id p1,
GNUNET_PEER_Id p2,
- MeshNodeDisconnectCB cb)
+ MeshNodeDisconnectCB cb,
+ void *cbcls)
{
struct MeshTunnelTreeNode *n;
struct MeshTunnelTreeNode *c;
@@ -744,7 +748,7 @@
return 0;
if (NULL != n->parent && n->parent->peer == p2)
{
- tree_mark_peers_disconnected(t, n, cb);
+ tree_mark_peers_disconnected(t, n, cb, cbcls);
GNUNET_CONTAINER_DLL_remove(n->parent->children_head,
n->parent->children_tail,
n);
@@ -757,7 +761,7 @@
{
if (c->peer == p2)
{
- tree_mark_peers_disconnected(t, c, cb);
+ tree_mark_peers_disconnected(t, c, cb, cbcls);
GNUNET_CONTAINER_DLL_remove(n->children_head,
n->children_tail,
c);
@@ -780,17 +784,19 @@
* @param t Tunnel tree to use.
* @param peer Short ID of the peer to remove from the tunnel tree.
* @param cb Callback to notify client of disconnected peers.
+ * @param cbcls Closure for cb.
*
* @return GNUNET_OK or GNUNET_SYSERR
*/
int
tree_del_peer (struct MeshTunnelTree *t,
GNUNET_PEER_Id peer,
- MeshNodeDisconnectCB cb)
+ MeshNodeDisconnectCB cb,
+ void *cbcls)
{
struct MeshTunnelTreeNode *n;
- n = tree_del_path(t, peer, cb);
+ n = tree_del_path(t, peer, cb, cbcls);
if (NULL == n)
return GNUNET_SYSERR;
GNUNET_break_op (NULL == n->children_head);
Modified: gnunet/src/mesh/mesh_tunnel_tree.h
===================================================================
--- gnunet/src/mesh/mesh_tunnel_tree.h 2011-11-02 14:07:50 UTC (rev 17923)
+++ gnunet/src/mesh/mesh_tunnel_tree.h 2011-11-02 14:34:27 UTC (rev 17924)
@@ -61,11 +61,6 @@
struct MeshTunnelTreeNode
{
/**
- * Tunnel this node belongs to (and therefore tree)
- */
- struct MeshTunnel *t;
-
- /**
* Peer this node describes
*/
GNUNET_PEER_Id peer;
@@ -113,11 +108,6 @@
struct GNUNET_TIME_Relative refresh;
/**
- * Tunnel this path belongs to
- */
- struct MeshTunnel *t;
-
- /**
* Root node of peer tree
*/
struct MeshTunnelTreeNode *root;
@@ -236,9 +226,11 @@
/**
* Method called whenever a node has been marked as disconnected.
*
- * @param node peer identity the tunnel stopped working with
+ * @param cls Closure.
+ * @param peer_id short ID of peer that is no longer reachable.
*/
-typedef void (*MeshNodeDisconnectCB) (const struct MeshTunnelTreeNode * node);
+typedef void (*MeshNodeDisconnectCB) (void *cls,
+ GNUNET_PEER_Id peer_id);
/**
@@ -250,7 +242,7 @@
* @return A newly allocated and initialized tunnel tree
*/
struct MeshTunnelTree *
-tree_new (struct MeshTunnel *t, GNUNET_PEER_Id peer);
+tree_new (GNUNET_PEER_Id peer);
/**
@@ -288,6 +280,7 @@
* @param peer Destination peer whose path we want to remove.
* @param cb Callback to use to notify about which peers are going to be
* disconnected.
+ * @param cbcls Closure for cb.
*
* @return pointer to the pathless node.
* NULL when not found
@@ -295,7 +288,8 @@
struct MeshTunnelTreeNode *
tree_del_path (struct MeshTunnelTree *t,
GNUNET_PEER_Id peer,
- MeshNodeDisconnectCB cb);
+ MeshNodeDisconnectCB cb,
+ void *cbcls);
/**
@@ -318,7 +312,8 @@
*
* @param t Tunnel where to add the new path.
* @param p Path to be integrated.
- * @param cb Callback to use to notify about peers temporarily disconnecting
+ * @param cb Callback to use to notify about peers temporarily disconnecting.
+ * @param cbcls Closure for cb.
*
* @return GNUNET_OK in case of success.
* GNUNET_SYSERR in case of error.
@@ -326,7 +321,8 @@
int
tree_add_path (struct MeshTunnelTree *t,
const struct MeshPeerPath *p,
- MeshNodeDisconnectCB cb);
+ MeshNodeDisconnectCB cb,
+ void *cbcls);
/**
@@ -337,6 +333,7 @@
* @param p1 Short id of one of the peers (order unimportant)
* @param p2 Short id of one of the peers (order unimportant)
* @param cb Function to call for every peer that is marked as disconnected.
+ * @param cbcls Closure for cb.
*
* @return Short ID of the first disconnected peer in the tree.
*/
@@ -344,7 +341,8 @@
tree_notify_connection_broken (struct MeshTunnelTree *t,
GNUNET_PEER_Id p1,
GNUNET_PEER_Id p2,
- MeshNodeDisconnectCB cb);
+ MeshNodeDisconnectCB cb,
+ void *cbcls);
/**
@@ -356,13 +354,15 @@
* @param t Tunnel tree to use.
* @param peer Short ID of the peer to remove from the tunnel tree.
* @param cb Callback to notify client of disconnected peers.
+ * @param cbcls Closure for cb.
*
* @return GNUNET_OK or GNUNET_SYSERR
*/
int
tree_del_peer (struct MeshTunnelTree *t,
GNUNET_PEER_Id peer,
- MeshNodeDisconnectCB cb);
+ MeshNodeDisconnectCB cb,
+ void *cbcls);
/**
* Print the tree on stderr
Modified: gnunet/src/mesh/test_mesh_path_api.c
===================================================================
--- gnunet/src/mesh/test_mesh_path_api.c 2011-11-02 14:07:50 UTC (rev
17923)
+++ gnunet/src/mesh/test_mesh_path_api.c 2011-11-02 14:34:27 UTC (rev
17924)
@@ -40,9 +40,9 @@
struct MeshTunnelTree *tree;
static void
-cb (const struct MeshTunnelTreeNode *n)
+cb (void *cls, GNUNET_PEER_Id peer_id)
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: CB: Disconnected %u\n", n->peer);
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: CB: Disconnected %u\n", peer_id);
if(0 == cb_call)
{
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: and it shouldn't!\n");
@@ -181,7 +181,7 @@
path->length = 4;
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3 4\n");
- tree_add_path(tree, path, &cb);
+ tree_add_path(tree, path, &cb, NULL);
tree_debug(tree);
path1 = tree_get_path_to_peer(tree, 4);
if (path->length != path1->length ||
@@ -198,7 +198,7 @@
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding second path: 1 2 3\n");
path->length--;
- tree_add_path(tree, path, &cb);
+ tree_add_path(tree, path, &cb, NULL);
tree_debug(tree);
test_assert (4, MESH_PEER_SEARCHING, 0, 2);
@@ -209,7 +209,7 @@
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding third path...\n");
path->length++;
path->peers[3] = 5;
- tree_add_path(tree, path, &cb);
+ tree_add_path(tree, path, &cb, NULL);
tree_debug(tree);
test_assert (5, MESH_PEER_SEARCHING, 0, 2);
@@ -222,7 +222,7 @@
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path...\n");
node->status = MESH_PEER_READY;
cb_call = 1;
- node2 = tree_del_path(tree, 5, &cb);
+ node2 = tree_del_path(tree, 5, &cb, NULL);
tree_debug(tree);
if (cb_call != 0)
{
@@ -249,7 +249,7 @@
path->peers[1] = 4;
cb_call = 1;
tree_find_peer(tree->root, 4)->status = MESH_PEER_READY;
- tree_add_path(tree, path, cb);
+ tree_add_path(tree, path, &cb, NULL);
tree_debug(tree);
if (cb_call != 0)
{
@@ -287,7 +287,7 @@
path->length = 3;
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 1 2 3\n");
- tree_add_path(tree, path, &cb);
+ tree_add_path(tree, path, &cb, NULL);
tree_debug(tree);
tree->me = tree_find_peer (tree->root, 2);
@@ -296,7 +296,7 @@
test_assert (1, MESH_PEER_ROOT, 1, 0);
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding same path: 1 2 3\n");
- tree_add_path(tree, path, &cb);
+ tree_add_path(tree, path, &cb, NULL);
GNUNET_free (path->peers);
GNUNET_free (path);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r17924 - gnunet/src/mesh,
gnunet <=