{
struct MeshPeerPath *p;
- p = GNUNET_malloc (sizeof (struct MeshPeerPath));
+ p = GNUNET_new (struct MeshPeerPath);
if (length > 0)
{
p->length = length;
{
struct MeshTunnelTreeNode *node;
- node = GNUNET_malloc (sizeof (struct MeshTunnelTreeNode));
+ node = GNUNET_new (struct MeshTunnelTreeNode);
node->peer = peer;
GNUNET_PEER_change_rc (peer, 1);
node->parent = parent;
GNUNET_PEER_resolve (parent->peer, &id);
copy = GNUNET_CONTAINER_multihashmap_get (tree->first_hops, &id.hashPubKey);
if (NULL == copy)
- copy = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
+ copy = GNUNET_new (struct GNUNET_PeerIdentity);
*copy = *hop;
(void) GNUNET_CONTAINER_multihashmap_put (tree->first_hops, &id.hashPubKey,
struct MeshTunnelTreeNode *n;
struct MeshTunnelTreeNode *next;
+ if (NULL == parent)
+ return;
#if MESH_TREE_DEBUG
struct GNUNET_PeerIdentity id;
{
struct MeshTunnelTree *tree;
- tree = GNUNET_malloc (sizeof (struct MeshTunnelTree));
+ tree = GNUNET_new (struct MeshTunnelTree);
tree->first_hops = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
tree->root = tree_node_new (NULL, peer);
tree->root->status = MESH_PEER_ROOT;
*
* @return peerinfo of the peer who is the first hop in the tunnel
* NULL on error
- *
+ *
* FIXME use PEER_Id
*/
struct GNUNET_PeerIdentity *
struct MeshTunnelTreeNode *n;
if (NULL == tree->me)
- {
- GNUNET_break (0);
return;
- }
for (n = tree->me->children_head; NULL != n; n = n->next)
{
cb (cb_cls, n->peer);
struct MeshTreePendingNode *pending;
cb (cb_cls, tree->root->peer, 0);
- pending = GNUNET_malloc (sizeof (struct MeshTreePendingNode));
+ pending = GNUNET_new (struct MeshTreePendingNode);
pending->node = tree->root;
head = tail = NULL;
GNUNET_CONTAINER_DLL_insert (head, tail, pending);
for (n = parent->children_head; NULL != n; n = n->next)
{
cb (cb_cls, n->peer, parent->peer);
- pending = GNUNET_malloc (sizeof (struct MeshTreePendingNode));
+ pending = GNUNET_new (struct MeshTreePendingNode);
pending->node = n;
/* Insert_tail: breadth first, Insert: depth first */
GNUNET_CONTAINER_DLL_insert (head, tail, pending);
}
+/**
+ * Iterator to count the children in a tree.
+ */
+static void
+count_children_cb (void *cls, GNUNET_PEER_Id peer)
+{
+ unsigned int *i = cls;
+
+ (*i)++;
+}
+
+
+/**
+ * Count how many children does the local node have in the tree.
+ *
+ * @param tree Tree to use. Must have "me" set.
+ */
+unsigned int
+tree_count_children (struct MeshTunnelTree *tree)
+{
+ unsigned int i;
+
+ i = 0;
+ tree_iterate_children(tree, &count_children_cb, &i);
+ return i;
+}
+
+
/**
* Recusively update the info about what is the first hop to reach the node
*
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tree: Deleting path to %s.\n",
GNUNET_i2s (&id));
#endif
- if (peer_id == t->root->peer)
+ if (NULL == t->root || peer_id == t->root->peer)
return NULL;
for (n = t->disconnected_head; NULL != n; n = n->next)
GNUNET_CONTAINER_DLL_remove (parent->children_head, parent->children_tail, n);
n->parent = NULL;
- while (MESH_PEER_RELAY == parent->status && NULL == parent->children_head)
+ while (MESH_PEER_RELAY == parent->status &&
+ NULL == parent->children_head)
{
#if MESH_TREE_DEBUG
GNUNET_PEER_resolve (parent->peer, &id);
GNUNET_i2s (&id));
#endif
n = parent->parent;
+ if (parent == t->me)
+ t->me = NULL;
tree_node_destroy (parent);
parent = n;
}
GNUNET_break (0);
return GNUNET_YES;
}
- GNUNET_break_op (NULL == n->children_head);
tree_node_destroy (n);
if (NULL == t->root->children_head && t->me != t->root)
{
tree_debug (struct MeshTunnelTree *t)
{
tree_node_debug (t->root, 0);
+ FPRINTF (stderr, "root: %p\n", t->root);
+ FPRINTF (stderr, "me: %p\n", t->me);
}