/**
* Node of path tree for a tunnel
*/
-struct MeshTunnelTreeNode
-{
- /**
- * Tunnel this node belongs to (and therefore tree)
- */
- struct MeshTunnel *t;
-
- /**
- * Peer this node describes
- */
- GNUNET_PEER_Id peer;
-
- /**
- * Parent node in the tree
- */
- struct MeshTunnelTreeNode *parent;
-
- /**
- * DLL of siblings
- */
- struct MeshTunnelTreeNode *next;
-
- /**
- * DLL of siblings
- */
- struct MeshTunnelTreeNode *prev;
-
- /**
- * DLL of children
- */
- struct MeshTunnelTreeNode *children_head;
-
- /**
- * DLL of children
- */
- struct MeshTunnelTreeNode *children_tail;
-
- /**
- * Status of the peer in the tunnel
- */
- enum MeshPeerState status;
-};
+struct MeshTunnelTreeNode;
/**
* Tree to reach all peers in the tunnel
*/
-struct MeshTunnelTree
-{
- /**
- * How often to refresh the path
- */
- struct GNUNET_TIME_Relative refresh;
-
- /**
- * Tunnel this path belongs to
- */
- struct MeshTunnel *t;
-
- /**
- * Root node of peer tree
- */
- struct MeshTunnelTreeNode *root;
-
- /**
- * Node that represents our position in the tree (for non local tunnels)
- */
- struct MeshTunnelTreeNode *me;
-
- /**
- * DLL of disconneted nodes
- */
- struct MeshTunnelTreeNode *disconnected_head;
-
- /**
- * DLL of disconneted nodes
- */
- struct MeshTunnelTreeNode *disconnected_tail;
-
- /**
- * Cache of all peers and the first hop to them.
- * Indexed by PeerIdentity, contains a pointer to the PeerIdentity
- * of 1st hop.
- */
- struct GNUNET_CONTAINER_MultiHashMap *first_hops;
-
-};
+struct MeshTunnelTree;
/******************************************************************************/
* NULL on error
*/
struct GNUNET_PeerIdentity *
-path_get_first_hop (struct MeshTunnelTree *t,
- GNUNET_PEER_Id peer);
+path_get_first_hop (struct MeshTunnelTree *t, GNUNET_PEER_Id peer);
/**
* in the path
*/
unsigned int
-path_get_cost (struct MeshTunnelTree *t,
- struct MeshPeerPath *path);
+path_get_cost (struct MeshTunnelTree *t, struct MeshPeerPath *path);
/**
/**
* 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 (*MeshTreeCallback) (void *cls, GNUNET_PEER_Id peer_id);
/**
* Create a new tunnel tree associated to a tunnel
*
- * @param t Tunnel this tree will represent
* @param peer A short peer id of the root of the tree
*
* @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);
/**
- * Recursively find the given peer in the tree.
+ * Set own identity in the tree
*
- * @param parent Parent node where to start looking.
- * @param peer Short ID of peer to find.
+ * @param tree Tree.
+ * @param peer A short peer id of local peer.
+ */
+void
+tree_set_me (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer);
+
+
+/**
+ * Get the id of the local id of the tree.
+ *
+ * @param tree Tree whose local id we want to now.
+ *
+ * @return Short peer id of local peer.
+ */
+GNUNET_PEER_Id
+tree_get_me (struct MeshTunnelTree *tree);
+
+
+/**
+ * Set the status of a node.
+ *
+ * @param tree Tree.
+ * @param peer A short peer id of local peer.
+ */
+void
+tree_set_status (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer,
+ enum MeshPeerState status);
+
+
+/**
+ * Get the status of a node.
+ *
+ * @param tree Tree whose local id we want to now.
+ *
+ * @return Short peer id of local peer.
+ */
+enum MeshPeerState
+tree_get_status (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer);
+
+
+/**
+ * Get the id of the predecessor of the local node.
+ *
+ * @param tree Tree whose local id we want to now.
+ *
+ * @return Short peer id of local peer.
+ */
+GNUNET_PEER_Id
+tree_get_predecessor (struct MeshTunnelTree *tree);
+
+
+/**
+ * Find the given peer in the tree.
+ *
+ * @param tree Tree where to look for the peer.
+ * @param peer Peer to find.
*
* @return Pointer to the node of the peer. NULL if not found.
*/
struct MeshTunnelTreeNode *
-tree_find_peer (struct MeshTunnelTreeNode *parent,
- GNUNET_PEER_Id peer);
+tree_find_peer (struct MeshTunnelTree *tree, GNUNET_PEER_Id peer_id);
+
+
+/**
+ * Iterate over all children of the local node.
+ *
+ * @param tree Tree to use. Must have "me" set.
+ * @param cb Callback to call over each child.
+ * @param cls Closure.
+ */
+void
+tree_iterate_children (struct MeshTunnelTree *tree, MeshTreeCallback cb,
+ void *cls);
+
+/**
+ * Recusively update the info about what is the first hop to reach the node
+ *
+ * @param tree Tree this nodes belongs to.
+ * @param parent_id Short ID from node form which to start updating.
+ * @param hop If known, ID of the first hop.
+ * If not known, NULL to find out and pass on children.
+ */
+void
+tree_update_first_hops (struct MeshTunnelTree *tree, GNUNET_PEER_Id parent_id,
+ struct GNUNET_PeerIdentity *hop);
/**
* Delete the current path to the peer, including all now unused relays.
* @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
*/
struct MeshTunnelTreeNode *
-tree_del_path (struct MeshTunnelTree *t,
- GNUNET_PEER_Id peer,
- MeshNodeDisconnectCB cb);
+tree_del_path (struct MeshTunnelTree *t, GNUNET_PEER_Id peer,
+ MeshTreeCallback cb, void *cbcls);
/**
* Path must be destroyed afterwards.
*/
struct MeshPeerPath *
-tree_get_path_to_peer(struct MeshTunnelTree *t,
- GNUNET_PEER_Id peer);
+tree_get_path_to_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer);
/**
*
* @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.
*/
int
-tree_add_path (struct MeshTunnelTree *t,
- const struct MeshPeerPath *p,
- MeshNodeDisconnectCB cb);
+tree_add_path (struct MeshTunnelTree *t, const struct MeshPeerPath *p,
+ MeshTreeCallback cb, void *cbcls);
/**
* @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.
*/
GNUNET_PEER_Id
-tree_notify_connection_broken (struct MeshTunnelTree *t,
- GNUNET_PEER_Id p1,
- GNUNET_PEER_Id p2,
- MeshNodeDisconnectCB cb);
+tree_notify_connection_broken (struct MeshTunnelTree *t, GNUNET_PEER_Id p1,
+ GNUNET_PEER_Id p2, MeshTreeCallback cb,
+ void *cbcls);
+
+/**
+ * Deletes a peer from a tunnel, liberating all unused resources on the path to
+ * it. It shouldn't have children, if it has they will be destroyed as well.
+ * If the tree is not local and no longer has any paths, the root node will be
+ * destroyed and marked as NULL.
+ *
+ * @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_YES if the tunnel still has nodes
+ */
+int
+tree_del_peer (struct MeshTunnelTree *t, GNUNET_PEER_Id peer,
+ MeshTreeCallback cb, void *cbcls);
/**
* Print the tree on stderr
* @param t The tree
*/
void
-tree_debug(struct MeshTunnelTree *t);
+tree_debug (struct MeshTunnelTree *t);
/**