* - Adapt X to churn
*/
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: DHT_put for ID %s started.\n",
- GNUNET_h2s_full (&my_full_id.hashPubKey));
+ GNUNET_i2s (&my_full_id));
GNUNET_DHT_put (dht_handle, /* DHT handle */
&my_full_id.hashPubKey, /* Key to use */
10U, /* Replication level */
* Sends an already built message to a peer, properly registrating
* all used resources.
*
- * @param message Message to send.
+ * @param message Message to send. Fucntion makes a copy of it.
* @param peer Short ID of the neighbor whom to send the message.
*/
static void
static void
send_destroy_path (struct MeshTunnel *t, GNUNET_PEER_Id destination)
{
- struct GNUNET_MESH_ManipulatePath *msg;
- struct GNUNET_PeerIdentity *pi;
struct MeshPeerPath *p;
- unsigned int i;
size_t size;
p = tree_get_path_to_peer(t->tree, destination);
}
size = sizeof (struct GNUNET_MESH_ManipulatePath);
size += p->length * sizeof (struct GNUNET_PeerIdentity);
- msg = GNUNET_malloc (size);
- msg->header.size = htons (size);
- msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_DESTROY);
- msg->tid = htonl (t->id.tid);
- pi = (struct GNUNET_PeerIdentity *) &msg[1];
- for (i = 0; i < p->length; i++)
{
- GNUNET_PEER_resolve(p->peers[i], &pi[i]);
+ struct GNUNET_MESH_ManipulatePath *msg;
+ struct GNUNET_PeerIdentity *pi;
+ char cbuf[size];
+ unsigned int i;
+
+ msg = (struct GNUNET_MESH_ManipulatePath *) cbuf;
+ msg->header.size = htons (size);
+ msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_DESTROY);
+ msg->tid = htonl (t->id.tid);
+ pi = (struct GNUNET_PeerIdentity *) &msg[1];
+ for (i = 0; i < p->length; i++)
+ {
+ GNUNET_PEER_resolve(p->peers[i], &pi[i]);
+ }
+ send_message (&msg->header, path_get_first_hop(t->tree, destination));
}
- send_message (&msg->header, path_get_first_hop(t->tree, destination));
path_destroy (p);
}
if (NULL != peer->path_head)
{
p = tree_get_path_to_peer(t->tree, peer->id);
+ if (NULL == p)
+ {
+ GNUNET_break (0);
+ return;
+ }
+
if (p->length > 1)
{
send_create_path(peer, p, t);
}
+/**
+ * Task to delay the connection of a peer
+ *
+ * @param cls Closure (path info with tunnel and peer to connect).
+ * Will be free'd on exection.
+ * @param tc TaskContext
+ */
+static void
+peer_info_connect_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct MeshPathInfo *path_info = cls;
+
+ if (GNUNET_SCHEDULER_REASON_SHUTDOWN == tc->reason)
+ {
+ GNUNET_free (cls);
+ }
+ peer_info_connect (path_info->peer, path_info->t);
+ GNUNET_free (cls);
+}
+
+
/**
* Destroy the peer_info and free any allocated resources linked to it
*
unsigned int l;
unsigned int l2;
+#if MESH_DEBUG
+ struct GNUNET_PeerIdentity id;
+
+ GNUNET_PEER_resolve (peer_info->id, &id);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "MESH: adding path [%u] to peer %s\n",
+ path->length,
+ GNUNET_i2s (&id));
+#endif
if (NULL == peer_info || NULL == path)
{
GNUNET_break (0);
+ path_destroy (path);
return;
}
if (l2 > l)
{
GNUNET_CONTAINER_DLL_insert_before (peer_info->path_head,
- peer_info->path_tail, aux, path);
+ peer_info->path_tail,
+ aux,
+ path);
+ return;
}
else
{
*/
static struct MeshPeerPath *
path_build_from_dht (const struct GNUNET_PeerIdentity *get_path,
- unsigned int get_path_length,
+ unsigned int get_path_length,
const struct GNUNET_PeerIdentity *put_path,
- unsigned int put_path_length)
+ unsigned int put_path_length)
{
struct MeshPeerPath *p;
GNUNET_PEER_Id id;
if (get_path_length > 0)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"MESH: (first of GET: %s)\n",
- GNUNET_h2s_full(&get_path[0].hashPubKey));
+ GNUNET_i2s(&get_path[0]));
if (put_path_length > 0)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"MESH: (first of PUT: %s)\n",
- GNUNET_h2s_full(&put_path[0].hashPubKey));
+ GNUNET_i2s(&put_path[0]));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"MESH: In total: %d hops\n",
p->length);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"MESH: %u: %s\n",
p->peers[i],
- GNUNET_h2s_full(&peer_id.hashPubKey));
+ GNUNET_i2s(&peer_id));
}
#endif
return p;
notify_peer_disconnected (const struct MeshTunnelTreeNode *n)
{
struct MeshPeerInfo *peer;
+ struct MeshPathInfo *path_info;
if (NULL != n->t->client && NULL != nc)
{
&msg.header, GNUNET_NO);
}
peer = peer_info_get_short(n->peer);
- peer_info_connect(peer, n->t);
+ path_info = GNUNET_malloc (sizeof (struct MeshPathInfo));
+ path_info->peer = peer;
+ path_info->t = n->t;
+ GNUNET_SCHEDULER_add_now(&peer_info_connect_task, path_info);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"MESH: It's for us!\n");
path_add_to_origin (orig_peer_info, path);
- t->peers = GNUNET_CONTAINER_multihashmap_create(4);
+ if (NULL == t->peers)
+ t->peers = GNUNET_CONTAINER_multihashmap_create(4);
GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (
t->peers,
&my_full_id.hashPubKey,
if (own_pos < path->length - 1)
send_message (message, &pi[own_pos + 1]);
tunnel_delete_peer (t, path->peers[path->length - 1]);
+ path_destroy (path);
return GNUNET_OK;
}
GNUNET_PEER_resolve (path_info->peer->id, &pi);
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"MESH: for %s\n",
- GNUNET_h2s_full(&pi.hashPubKey));
+ GNUNET_i2s(&pi));
// GNUNET_DHT_get_stop(path_info->peer->dhtget);
// path_info->peer->dhtget = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (SERVER DOWN)\n");
return;
}
- GNUNET_SERVER_client_drop (client);
c = clients;
while (NULL != c)
{
continue;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: matching client found\n");
+ GNUNET_SERVER_client_drop (c->handle);
if (NULL != c->tunnels)
{
GNUNET_CONTAINER_multihashmap_iterate (c->tunnels,
uint16_t i;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: new client connected\n");
- GNUNET_SERVER_client_keep (client);
/* Check data sanity */
size = ntohs (message->size) - sizeof (struct GNUNET_MESH_ClientConnect);
cc_msg = (struct GNUNET_MESH_ClientConnect *) message;
#endif
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: CLIENT NEW %u at %p\n", c->id, c);
c->handle = client;
+ GNUNET_SERVER_client_keep (client);
a = (GNUNET_MESH_ApplicationType *) &cc_msg[1];
if (napps > 0)
{
return;
}
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: for %s\n",
- GNUNET_h2s_full(&peer_msg->peer.hashPubKey));
+ GNUNET_i2s(&peer_msg->peer));
peer_info = peer_info_get (&peer_msg->peer);
tunnel_add_peer(t, peer_info);
GNUNET_DHT_get_stop (t->dht_get_type);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: looking in DHT for %s\n",
- GNUNET_h2s_full (&hash));
+ GNUNET_h2s (&hash));
t->dht_get_type =
GNUNET_DHT_get_start (dht_handle,
GNUNET_TIME_UNIT_FOREVER_REL,
#if MESH_DEBUG_CONNECTION
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Peer connected\n");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n",
- GNUNET_h2s(&my_full_id.hashPubKey));
+ GNUNET_i2s(&my_full_id));
#endif
peer_info = peer_info_get (peer);
if (myid == peer_info->id)
else
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n",
- GNUNET_h2s(&peer->hashPubKey));
+ GNUNET_i2s(peer));
}
#endif
path = path_new (2);