aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-09-02 12:38:18 +0000
committerBart Polot <bart@net.in.tum.de>2011-09-02 12:38:18 +0000
commit88590a7fd73dde7fcede837cf631a8020fefc9de (patch)
tree3b581a6b5d0b2ee75d11b4645aafa1a70aa99399 /src
parentd12aa71a4d8b31475fdd3b3bd60ad947f995dc49 (diff)
downloadgnunet-88590a7fd73dde7fcede837cf631a8020fefc9de.tar.gz
gnunet-88590a7fd73dde7fcede837cf631a8020fefc9de.zip
Added tunnel destroy, changed message types in client <-> service protocol
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_protocols.h25
-rw-r--r--src/mesh/gnunet-service-mesh.c10
-rw-r--r--src/mesh/mesh_api_new.c87
3 files changed, 86 insertions, 36 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 5f3ab25ce..6d4f7265b 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -876,7 +876,6 @@ extern "C"
876 876
877/** 877/**
878 * Transport data back in the mesh (end->origin) 878 * Transport data back in the mesh (end->origin)
879 * (not sure if this is the right way, should be some other solution)
880 */ 879 */
881#define GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN 262 880#define GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN 262
882 881
@@ -908,38 +907,22 @@ extern "C"
908/** 907/**
909 * Ask the mesh service to add a peer to an existing tunnel 908 * Ask the mesh service to add a peer to an existing tunnel
910 */ 909 */
911#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD 275 910#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD 275
912 911
913/** 912/**
914 * Ask the mesh service to remove a peer from a tunnel 913 * Ask the mesh service to remove a peer from a tunnel
915 */ 914 */
916#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL 276 915#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL 276
917 916
918/** 917/**
919 * Ask the mesh service to add a peer offering a service to an existing tunnel 918 * Ask the mesh service to add a peer offering a service to an existing tunnel
920 */ 919 */
921#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE 277 920#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE 277
922
923/**
924 * Ask the mesh service to cancel a peer connection request
925 */
926#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_CANCEL 278
927
928/**
929 * Notify a mesh client that a peer has connected to a tunnel
930 */
931#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED 279
932
933/**
934 * Notify a mesh client that a peer has disconnected from a tunnel
935 */
936#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED 280
937
938 921
939/** 922/**
940 * 640kb should be enough for everybody 923 * 640kb should be enough for everybody
941 */ 924 */
942#define GNUNET_MESSAGE_TYPE_MESH_RESERVE_END 288 925#define GNUNET_MESSAGE_TYPE_MESH_RESERVE_END 288
943 926
944 927
945 928
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 0f8f2732f..c396303a8 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -1682,7 +1682,7 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
1682 return GNUNET_OK; 1682 return GNUNET_OK;
1683 } 1683 }
1684 peer_info->state = MESH_PEER_READY; 1684 peer_info->state = MESH_PEER_READY;
1685 pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED); 1685 pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD);
1686 pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); 1686 pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
1687 pc.tunnel_id = htonl (t->local_tid); 1687 pc.tunnel_id = htonl (t->local_tid);
1688 GNUNET_PEER_resolve (peer_info->id, &pc.peer); 1688 GNUNET_PEER_resolve (peer_info->id, &pc.peer);
@@ -2494,7 +2494,7 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client,
2494 get_peer_info (&pc.peer), 2494 get_peer_info (&pc.peer),
2495 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 2495 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
2496 pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); 2496 pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
2497 pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED); 2497 pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD);
2498 pc.tunnel_id = htonl (t->local_tid); 2498 pc.tunnel_id = htonl (t->local_tid);
2499 GNUNET_SERVER_notification_context_unicast (nc, client, NULL, GNUNET_NO); 2499 GNUNET_SERVER_notification_context_unicast (nc, client, NULL, GNUNET_NO);
2500 } 2500 }
@@ -2679,13 +2679,13 @@ static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = {
2679 GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY, 2679 GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY,
2680 sizeof (struct GNUNET_MESH_TunnelMessage)}, 2680 sizeof (struct GNUNET_MESH_TunnelMessage)},
2681 {&handle_local_connect_add, NULL, 2681 {&handle_local_connect_add, NULL,
2682 GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD, 2682 GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD,
2683 sizeof (struct GNUNET_MESH_PeerControl)}, 2683 sizeof (struct GNUNET_MESH_PeerControl)},
2684 {&handle_local_connect_del, NULL, 2684 {&handle_local_connect_del, NULL,
2685 GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL, 2685 GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL,
2686 sizeof (struct GNUNET_MESH_PeerControl)}, 2686 sizeof (struct GNUNET_MESH_PeerControl)},
2687 {&handle_local_connect_by_type, NULL, 2687 {&handle_local_connect_by_type, NULL,
2688 GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE, 2688 GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE,
2689 sizeof (struct GNUNET_MESH_ConnectPeerByType)}, 2689 sizeof (struct GNUNET_MESH_ConnectPeerByType)},
2690 {&handle_local_unicast, NULL, 2690 {&handle_local_unicast, NULL,
2691 GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0}, 2691 GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0},
diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c
index 34e8f4747..b639df812 100644
--- a/src/mesh/mesh_api_new.c
+++ b/src/mesh/mesh_api_new.c
@@ -325,10 +325,10 @@ retrieve_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid)
325 325
326 326
327/** 327/**
328 * Get the tunnel handler for the tunnel specified by id from the given handle 328 * Create a new tunnel and insert it in the tunnel list of the mesh handle
329 * @param h Mesh handle 329 * @param h Mesh handle
330 * @param tid ID of the wanted tunnel 330 * @param tid desired tid of the tunnel, 0 to assign one automatically
331 * @return handle to the required tunnel or NULL if not found 331 * @return handle to the created tunnel
332 */ 332 */
333static struct GNUNET_MESH_Tunnel * 333static struct GNUNET_MESH_Tunnel *
334create_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid) 334create_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid)
@@ -343,6 +343,8 @@ create_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid)
343 } 343 }
344 else 344 else
345 { 345 {
346 /* FIXME keep double numbering?
347 * client numbers from 0x8... anx service from 0xB... ? */
346 t->tid = tid; 348 t->tid = tid;
347 h->next_tid = tid + 1; 349 h->next_tid = tid + 1;
348 } 350 }
@@ -353,6 +355,42 @@ create_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid)
353 355
354 356
355/** 357/**
358 * Get the tunnel handler for the tunnel specified by id from the given handle
359 * @param h Mesh handle
360 * @param tid ID of the wanted tunnel
361 * @return handle to the required tunnel or NULL if not found
362 */
363static void
364destroy_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid)
365{
366 struct GNUNET_MESH_Tunnel *t;
367 struct GNUNET_PeerIdentity pi;
368 unsigned int i;
369
370 t = retrieve_tunnel(h, tid);
371 if (NULL == t)
372 {
373 GNUNET_break (0);
374 return;
375 }
376 GNUNET_CONTAINER_DLL_remove (h->tunnels_head, h->tunnels_tail, t);
377 for (i = 0; i < t->npeers; i++)
378 {
379 GNUNET_PEER_resolve(t->peers[i]->id, &pi);
380 t->disconnect_handler(t->cls, &pi);
381 GNUNET_PEER_change_rc(t->peers[i]->id, -1);
382 GNUNET_free (t->peers[i]);
383 }
384 h->cleaner(h->cls, t, NULL); /* FIXME ctx? */
385 if (0 != t->owner)
386 GNUNET_PEER_change_rc(t->owner, -1);
387 GNUNET_free(t->peers);
388 GNUNET_free(t);
389 return;
390}
391
392
393/**
356 * Get the peer descriptor for the peer with id from the given tunnel 394 * Get the peer descriptor for the peer with id from the given tunnel
357 * @param t Tunnel handle 395 * @param t Tunnel handle
358 * @param id Short form ID of the wanted peer 396 * @param id Short form ID of the wanted peer
@@ -524,7 +562,7 @@ reconnect (struct GNUNET_MESH_Handle *h)
524 struct GNUNET_MESH_PeerControl msg; 562 struct GNUNET_MESH_PeerControl msg;
525 563
526 msg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); 564 msg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
527 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD); 565 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD);
528 msg.tunnel_id = htonl (t->tid); 566 msg.tunnel_id = htonl (t->tid);
529 GNUNET_PEER_resolve (t->peers[i]->id, &msg.peer); 567 GNUNET_PEER_resolve (t->peers[i]->id, &msg.peer);
530 send_packet (t->mesh, &msg.header); 568 send_packet (t->mesh, &msg.header);
@@ -562,11 +600,36 @@ process_tunnel_create (struct GNUNET_MESH_Handle *h,
562 t->cls = h->cls; 600 t->cls = h->cls;
563 t->mesh = h; 601 t->mesh = h;
564 t->tid = tid; 602 t->tid = tid;
603 GNUNET_CONTAINER_DLL_insert(h->tunnels_head, h->tunnels_tail, t);
565 return; 604 return;
566} 605}
567 606
568 607
569/** 608/**
609 * Process the tunnel destroy notification and free associated resources
610 *
611 * @param h The mesh handle
612 * @param msg A message with the details of the tunnel being destroyed
613 */
614static void
615process_tunnel_destroy (struct GNUNET_MESH_Handle *h,
616 const struct GNUNET_MESH_TunnelMessage *msg)
617{
618 struct GNUNET_MESH_Tunnel *t;
619 MESH_TunnelNumber tid;
620
621 tid = ntohl (msg->tunnel_id);
622 t = retrieve_tunnel(h, tid);
623
624 t->cls = h->cls;
625 t->mesh = h;
626 t->tid = tid;
627 GNUNET_CONTAINER_DLL_insert(h->tunnels_head, h->tunnels_tail, t);
628 return;
629}
630
631
632/**
570 * Process the new peer event and notify the upper level of it 633 * Process the new peer event and notify the upper level of it
571 * 634 *
572 * @param h The mesh handle 635 * @param h The mesh handle
@@ -606,7 +669,7 @@ process_peer_event (struct GNUNET_MESH_Handle *h,
606 p = add_peer_to_tunnel (t, &msg->peer); 669 p = add_peer_to_tunnel (t, &msg->peer);
607 atsi.type = 0; 670 atsi.type = 0;
608 atsi.value = 0; 671 atsi.value = 0;
609 if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED == msg->header.type) 672 if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD == msg->header.type)
610 { 673 {
611 if (NULL != t->connect_handler) 674 if (NULL != t->connect_handler)
612 { 675 {
@@ -726,9 +789,13 @@ msg_received (void *cls, const struct GNUNET_MessageHeader *msg)
726 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE: 789 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE:
727 process_tunnel_create (h, (struct GNUNET_MESH_TunnelMessage *) msg); 790 process_tunnel_create (h, (struct GNUNET_MESH_TunnelMessage *) msg);
728 break; 791 break;
792 /* Notify of a tunnel disconnection */
793 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY:
794 process_tunnel_destroy (h, (struct GNUNET_MESH_TunnelMessage *) msg);
795 break;
729 /* Notify of a new peer or a peer disconnect in the tunnel */ 796 /* Notify of a new peer or a peer disconnect in the tunnel */
730 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED: 797 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD:
731 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED: 798 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL:
732 process_peer_event (h, (struct GNUNET_MESH_PeerControl *) msg); 799 process_peer_event (h, (struct GNUNET_MESH_PeerControl *) msg);
733 break; 800 break;
734 /* Notify of a new data packet in the tunnel */ 801 /* Notify of a new data packet in the tunnel */
@@ -1084,7 +1151,7 @@ GNUNET_MESH_peer_request_connect_add (struct GNUNET_MESH_Tunnel *tunnel,
1084 add_peer_to_tunnel (tunnel, peer); 1151 add_peer_to_tunnel (tunnel, peer);
1085 1152
1086 msg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); 1153 msg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
1087 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD); 1154 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD);
1088 msg.tunnel_id = htonl (tunnel->tid); 1155 msg.tunnel_id = htonl (tunnel->tid);
1089 msg.peer = *peer; 1156 msg.peer = *peer;
1090 send_packet (tunnel->mesh, &msg.header); 1157 send_packet (tunnel->mesh, &msg.header);
@@ -1130,7 +1197,7 @@ GNUNET_MESH_peer_request_connect_del (struct GNUNET_MESH_Tunnel *tunnel,
1130 GNUNET_array_grow (tunnel->peers, tunnel->npeers, tunnel->npeers - 1); 1197 GNUNET_array_grow (tunnel->peers, tunnel->npeers, tunnel->npeers - 1);
1131 1198
1132 msg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); 1199 msg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
1133 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL); 1200 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL);
1134 msg.tunnel_id = htonl (tunnel->tid); 1201 msg.tunnel_id = htonl (tunnel->tid);
1135 memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity)); 1202 memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity));
1136 send_packet (tunnel->mesh, &msg.header); 1203 send_packet (tunnel->mesh, &msg.header);
@@ -1155,7 +1222,7 @@ GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Tunnel *tunnel,
1155 /* FIXME: add a new api call disconnect by type? */ 1222 /* FIXME: add a new api call disconnect by type? */
1156 1223
1157 msg.header.size = htons (sizeof (struct GNUNET_MESH_ConnectPeerByType)); 1224 msg.header.size = htons (sizeof (struct GNUNET_MESH_ConnectPeerByType));
1158 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE); 1225 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE);
1159 msg.tunnel_id = htonl (tunnel->tid); 1226 msg.tunnel_id = htonl (tunnel->tid);
1160 msg.type = htonl (app_type); 1227 msg.type = htonl (app_type);
1161 send_packet (tunnel->mesh, &msg.header); 1228 send_packet (tunnel->mesh, &msg.header);