GNUNET_CONTAINER_multihashmap_remove_all(tree->first_hops, &id.hashPubKey);
if (NULL != pi)
GNUNET_free(pi);
+// FIXME: add to service code on callback
// struct GNUNET_MESH_PeerControl msg;
// if (NULL == parent->t->client)
// return;
}
+/**
+ * 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)
+{
+ struct GNUNET_PeerIdentity pi;
+ struct GNUNET_PeerIdentity *copy;
+ struct GNUNET_PeerIdentity id;
+ unsigned int i;
+
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "tree: Finding first hop for %u.\n",
+ parent->peer);
+ if (NULL == hop)
+ {
+ struct MeshTunnelTreeNode *aux;
+ struct MeshTunnelTreeNode *old;
+
+ old = parent;
+ aux = old->parent;
+ while (aux != tree->me)
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "tree: ... its not %u.\n",
+ old->peer);
+ old = aux;
+ aux = aux->parent;
+ GNUNET_assert(NULL != aux);
+ }
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "tree: It's %u!!\n",
+ old->peer);
+ hop = π
+ GNUNET_PEER_resolve(old->peer, hop);
+ }
+ copy = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));
+ *copy = *hop;
+ GNUNET_PEER_resolve(parent->peer, &id);
+ GNUNET_CONTAINER_multihashmap_put(tree->first_hops, &id.hashPubKey, copy,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
+
+ for (i = 0; i < parent->nchildren; i++)
+ {
+ tree_update_first_hops (tree, &parent->children[i], hop);
+ }
+}
/**
struct MeshTunnelTreeNode *node;
struct MeshTunnelTreeNode *n;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Deleting path to %u.\n", peer_id);
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: Deleting path to %u.\n", peer_id);
if (peer_id == t->root->peer)
return NULL;
n = tree_find_peer (t->me, peer_id);
while (t->root != parent && MESH_PEER_RELAY == parent->status &&
0 == parent->nchildren)
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Deleting node %u.\n", parent->peer);
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: Deleting node %u.\n", parent->peer);
n = parent->parent;
tree_node_destroy(parent);
parent = n;
unsigned int j;
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Adding path [%u] towards peer %u to peer %u.\n",
+ "tree: Adding path [%u] towards peer %u to peer %u.\n",
p->length,
p->peers[p->length - 1],
t->me->peer);
for (i = 1; i < p->length; i++)
{
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Looking for peer %u.\n",
+ "tree: Looking for peer %u.\n",
p->peers[i]);
parent = n;
if (p->peers[i] == myid)
break;
}
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "All childen visited.\n");
+ "tree: All childen visited.\n");
if (-1 == me)
{
/* New path deviates from tree before reaching us. What happened? */
while (i < p->length)
{
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Adding peer %u, to %u.\n",
+ "tree: Adding peer %u, to %u.\n",
p->peers[i],
parent->peer);
parent->nchildren++;
parent->nchildren *
sizeof(struct MeshTunnelTreeNode));
n = &parent->children[parent->nchildren - 1];
+ n->parent = parent;
if (i == p->length - 1 && NULL != oldnode)
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Putting old note into place.\n");
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: Putting old node into place.\n");
/* Assignation and free can be misleading, using explicit mempcy */
memcpy (n, oldnode, sizeof (struct MeshTunnelTreeNode));
+ n->parent = parent;
GNUNET_free (oldnode);
for (j = 0; j < n->nchildren; j++)
{
n->children[j].parent = n;
+ tree_update_first_hops (t, &n->children[j], NULL);
}
}
else
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating new node.\n");
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: Creating new node.\n");
n->t = t->t;
n->status = MESH_PEER_RELAY;
n->peer = p->peers[i];
n->nchildren = 0;
n->children = NULL;
}
- n->parent = parent;
i++;
parent = n;
}
hop,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
}
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New node added.\n");
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: New node added.\n");
return GNUNET_OK;
}
if (n->children != NULL)
GNUNET_free(n->children);
}
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Destroying node %u.\n", n->peer);
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: Destroying node %u.\n", n->peer);
if (NULL == (parent = n->parent))
return;
i = (n - parent->children) / sizeof(struct MeshTunnelTreeNode);
parent->nchildren
* sizeof(struct MeshTunnelTreeNode));
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Destroyed.\n");
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: Destroyed.\n");
}
{
unsigned int i;
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Finishing...\n");
for (i = 0; i < 10; i++)
{
GNUNET_free(pi[i]);
path->peers[3] = 3;
path->length = 4;
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding first path: 0 1 2 3\n");
tree_add_path(tree, path, &cb);
path1 = tree_get_path_to_peer(tree, 3);
if (path->length != path1->length ||
failed++;
}
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding second path: 0 1 2\n");
path->length--;
tree_add_path(tree, path, &cb);
- path->length++;
- path_destroy(path);
- finish();
node = tree_find_peer(tree->root, 2);
if (node->peer != 2)
if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 1)
{
GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n");
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "3 GOT: %u\n", GNUNET_PEER_search(path_get_first_hop(tree, 3)));
failed++;
}
if (GNUNET_PEER_search(path_get_first_hop(tree, 2)) != 1)
{
GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n");
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "2 GOT: %u\n", GNUNET_PEER_search(path_get_first_hop(tree, 2)));
failed++;
}
GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n");
failed++;
}
+ path->length++;
+ path_destroy(path);
+ finish();
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding third path...\n");
path->length++;
path->peers[3] = 4;
tree_add_path(tree, path, &cb);
GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
failed++;
}
+
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path...\n");
node->status = MESH_PEER_READY;
cb_call = 1;
node2 = tree_del_path(tree, 4, &cb);
GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n");
failed++;
}
-// GNUNET_free(node2); FIXME destroy
+
node = tree_find_peer(tree->root, 2);
if (node->peer != 2)
{
failed++;
}
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Destroying node copy...\n");
+ tree_node_destroy(node2);
+
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Adding new shorter first path...\n");
path->length = 2;
path->peers[1] = 3;
cb_call = 1;