/**
* Transport data back in the mesh (end->origin)
- * (not sure if this is the right way, should be some other solution)
*/
#define GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN 262
/**
* Ask the mesh service to add a peer to an existing tunnel
*/
-#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD 275
+#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD 275
/**
* Ask the mesh service to remove a peer from a tunnel
*/
-#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL 276
+#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL 276
/**
* Ask the mesh service to add a peer offering a service to an existing tunnel
*/
-#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE 277
-
-/**
- * Ask the mesh service to cancel a peer connection request
- */
-#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_CANCEL 278
-
-/**
- * Notify a mesh client that a peer has connected to a tunnel
- */
-#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED 279
-
-/**
- * Notify a mesh client that a peer has disconnected from a tunnel
- */
-#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED 280
-
+#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE 277
/**
* 640kb should be enough for everybody
*/
-#define GNUNET_MESSAGE_TYPE_MESH_RESERVE_END 288
+#define GNUNET_MESSAGE_TYPE_MESH_RESERVE_END 288
return GNUNET_OK;
}
peer_info->state = MESH_PEER_READY;
- pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED);
+ pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD);
pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
pc.tunnel_id = htonl (t->local_tid);
GNUNET_PEER_resolve (peer_info->id, &pc.peer);
get_peer_info (&pc.peer),
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
- pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED);
+ pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD);
pc.tunnel_id = htonl (t->local_tid);
GNUNET_SERVER_notification_context_unicast (nc, client, NULL, GNUNET_NO);
}
GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY,
sizeof (struct GNUNET_MESH_TunnelMessage)},
{&handle_local_connect_add, NULL,
- GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD,
+ GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD,
sizeof (struct GNUNET_MESH_PeerControl)},
{&handle_local_connect_del, NULL,
- GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL,
+ GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL,
sizeof (struct GNUNET_MESH_PeerControl)},
{&handle_local_connect_by_type, NULL,
- GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE,
+ GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE,
sizeof (struct GNUNET_MESH_ConnectPeerByType)},
{&handle_local_unicast, NULL,
GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0},
/**
- * Get the tunnel handler for the tunnel specified by id from the given handle
+ * Create a new tunnel and insert it in the tunnel list of the mesh handle
* @param h Mesh handle
- * @param tid ID of the wanted tunnel
- * @return handle to the required tunnel or NULL if not found
+ * @param tid desired tid of the tunnel, 0 to assign one automatically
+ * @return handle to the created tunnel
*/
static struct GNUNET_MESH_Tunnel *
create_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid)
}
else
{
+ /* FIXME keep double numbering?
+ * client numbers from 0x8... anx service from 0xB... ? */
t->tid = tid;
h->next_tid = tid + 1;
}
}
+/**
+ * Get the tunnel handler for the tunnel specified by id from the given handle
+ * @param h Mesh handle
+ * @param tid ID of the wanted tunnel
+ * @return handle to the required tunnel or NULL if not found
+ */
+static void
+destroy_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid)
+{
+ struct GNUNET_MESH_Tunnel *t;
+ struct GNUNET_PeerIdentity pi;
+ unsigned int i;
+
+ t = retrieve_tunnel(h, tid);
+ if (NULL == t)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ GNUNET_CONTAINER_DLL_remove (h->tunnels_head, h->tunnels_tail, t);
+ for (i = 0; i < t->npeers; i++)
+ {
+ GNUNET_PEER_resolve(t->peers[i]->id, &pi);
+ t->disconnect_handler(t->cls, &pi);
+ GNUNET_PEER_change_rc(t->peers[i]->id, -1);
+ GNUNET_free (t->peers[i]);
+ }
+ h->cleaner(h->cls, t, NULL); /* FIXME ctx? */
+ if (0 != t->owner)
+ GNUNET_PEER_change_rc(t->owner, -1);
+ GNUNET_free(t->peers);
+ GNUNET_free(t);
+ return;
+}
+
+
/**
* Get the peer descriptor for the peer with id from the given tunnel
* @param t Tunnel handle
struct GNUNET_MESH_PeerControl msg;
msg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
- msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD);
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD);
msg.tunnel_id = htonl (t->tid);
GNUNET_PEER_resolve (t->peers[i]->id, &msg.peer);
send_packet (t->mesh, &msg.header);
t->cls = h->cls;
t->mesh = h;
t->tid = tid;
+ GNUNET_CONTAINER_DLL_insert(h->tunnels_head, h->tunnels_tail, t);
return;
}
+/**
+ * Process the tunnel destroy notification and free associated resources
+ *
+ * @param h The mesh handle
+ * @param msg A message with the details of the tunnel being destroyed
+ */
+static void
+process_tunnel_destroy (struct GNUNET_MESH_Handle *h,
+ const struct GNUNET_MESH_TunnelMessage *msg)
+{
+ struct GNUNET_MESH_Tunnel *t;
+ MESH_TunnelNumber tid;
+
+ tid = ntohl (msg->tunnel_id);
+ t = retrieve_tunnel(h, tid);
+
+ t->cls = h->cls;
+ t->mesh = h;
+ t->tid = tid;
+ GNUNET_CONTAINER_DLL_insert(h->tunnels_head, h->tunnels_tail, t);
+ return;
+}
+
+
/**
* Process the new peer event and notify the upper level of it
*
p = add_peer_to_tunnel (t, &msg->peer);
atsi.type = 0;
atsi.value = 0;
- if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED == msg->header.type)
+ if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD == msg->header.type)
{
if (NULL != t->connect_handler)
{
case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE:
process_tunnel_create (h, (struct GNUNET_MESH_TunnelMessage *) msg);
break;
+ /* Notify of a tunnel disconnection */
+ case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY:
+ process_tunnel_destroy (h, (struct GNUNET_MESH_TunnelMessage *) msg);
+ break;
/* Notify of a new peer or a peer disconnect in the tunnel */
- case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED:
- case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED:
+ case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD:
+ case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL:
process_peer_event (h, (struct GNUNET_MESH_PeerControl *) msg);
break;
/* Notify of a new data packet in the tunnel */
add_peer_to_tunnel (tunnel, peer);
msg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
- msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD);
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD);
msg.tunnel_id = htonl (tunnel->tid);
msg.peer = *peer;
send_packet (tunnel->mesh, &msg.header);
GNUNET_array_grow (tunnel->peers, tunnel->npeers, tunnel->npeers - 1);
msg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
- msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL);
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL);
msg.tunnel_id = htonl (tunnel->tid);
memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity));
send_packet (tunnel->mesh, &msg.header);
/* FIXME: add a new api call disconnect by type? */
msg.header.size = htons (sizeof (struct GNUNET_MESH_ConnectPeerByType));
- msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE);
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE);
msg.tunnel_id = htonl (tunnel->tid);
msg.type = htonl (app_type);
send_packet (tunnel->mesh, &msg.header);