Fixed a memory leak when receiving a second create path for the same tunnel
[oweals/gnunet.git] / src / mesh / mesh_tunnel_tree.h
index 2529295498b1161e849d3a8cffce13567a8c2ec0..59a60839d43cd922698786d01fd1726bf45e043f 100644 (file)
@@ -127,6 +127,16 @@ struct MeshTunnelTree
    */
   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
@@ -161,6 +171,15 @@ void
 path_invert (struct MeshPeerPath *p);
 
 
+/**
+ * Duplicate a path, incrementing short peer's rc.
+ *
+ * @param p The path to duplicate.
+ */
+struct MeshPeerPath *
+path_duplicate (struct MeshPeerPath *path);
+
+
 /**
  * Find the first peer whom to send a packet to go down this path
  *
@@ -247,6 +266,19 @@ tree_find_peer (struct MeshTunnelTreeNode *parent,
                 GNUNET_PEER_Id peer);
 
 
+/**
+ * Recusively update the info about what is the first hop to reach the node
+ *
+ * @param tree Tree this nodes belongs to
+ * @param parent Node to be 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,
+                        struct MeshTunnelTreeNode *parent,
+                        struct GNUNET_PeerIdentity *hop);
+
 /**
  * Delete the current path to the peer, including all now unused relays.
  * The destination peer is NOT destroyed, it is returned in order to either set
@@ -297,6 +329,41 @@ tree_add_path (struct MeshTunnelTree *t,
                MeshNodeDisconnectCB cb);
 
 
+/**
+ * Notifies a tree that a connection it might be using is broken.
+ * Marks all peers down the paths as disconnected and notifies the client.
+ *
+ * @param t Tree to use.
+ * @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.
+ *
+ * @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);
+
+
+/**
+ * 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.
+ *
+ * @return GNUNET_OK or GNUNET_SYSERR
+ */
+int
+tree_del_peer (struct MeshTunnelTree *t,
+               GNUNET_PEER_Id peer,
+               MeshNodeDisconnectCB cb);
+
 /**
  * Print the tree on stderr
  *