aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mesh/gnunet-service-mesh.c83
-rw-r--r--src/mesh/mesh_api_new.c7
2 files changed, 47 insertions, 43 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 77e09e88c..4865ed7e8 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -99,7 +99,7 @@ struct MeshPeerInfo
99 /** 99 /**
100 * Tunnel this peer belongs to 100 * Tunnel this peer belongs to
101 */ 101 */
102 struct MESH_tunnel *t; 102 struct MeshTunnel *t;
103 103
104 /** 104 /**
105 * Is the peer reachable? Is the peer even connected? 105 * Is the peer reachable? Is the peer even connected?
@@ -197,14 +197,14 @@ struct MeshClient; /* FWD declaration */
197 * - metainfo: ready, speeds, accounting 197 * - metainfo: ready, speeds, accounting
198 * For an end node more fields will be needed (client-handling) 198 * For an end node more fields will be needed (client-handling)
199 */ 199 */
200struct MESH_tunnel 200struct MeshTunnel
201{ 201{
202 202
203 /** 203 /**
204 * Double linked list 204 * Double linked list
205 */ 205 */
206 struct MESH_tunnel *next; 206 struct MeshTunnel *next;
207 struct MESH_tunnel *prev; 207 struct MeshTunnel *prev;
208 208
209 /** 209 /**
210 * Origin ID: Node that created the tunnel 210 * Origin ID: Node that created the tunnel
@@ -286,8 +286,8 @@ struct MeshClient
286 /** 286 /**
287 * Tunnels that belong to this client, for convenience on disconnect 287 * Tunnels that belong to this client, for convenience on disconnect
288 */ 288 */
289 struct MESH_tunnel *tunnels_head; 289 struct MeshTunnel *tunnels_head;
290 struct MESH_tunnel *tunnels_tail; 290 struct MeshTunnel *tunnels_tail;
291 291
292 /** 292 /**
293 * Handle to communicate with the client 293 * Handle to communicate with the client
@@ -306,6 +306,11 @@ struct MeshClient
306 uint16_t *types; 306 uint16_t *types;
307 unsigned int type_counter; 307 unsigned int type_counter;
308 308
309 /**
310 * Map tunnel IDs used by the client to owner and global tunnel ID
311 */
312 struct GNUNET_CONTAINER_MultiHashMap* tunnel_ids;
313
309}; 314};
310 315
311/******************************************************************************/ 316/******************************************************************************/
@@ -368,7 +373,7 @@ retrieve_client (struct GNUNET_SERVER_Client *client)
368 * @return GNUNET_OK on success 373 * @return GNUNET_OK on success
369 */ 374 */
370static int 375static int
371destroy_path(struct MESH_tunnel *t, struct MeshPath *p) 376destroy_path(struct MeshTunnel *t, struct MeshPath *p)
372{ 377{
373 GNUNET_PEER_decrement_rcs(p->peers, p->length); 378 GNUNET_PEER_decrement_rcs(p->peers, p->length);
374 GNUNET_free(p->peers); 379 GNUNET_free(p->peers);
@@ -384,7 +389,7 @@ destroy_path(struct MESH_tunnel *t, struct MeshPath *p)
384 * @return GNUNET_OK on success 389 * @return GNUNET_OK on success
385 */ 390 */
386static int 391static int
387destroy_peer_info(struct MESH_tunnel *t, struct MeshPeerInfo *pi) 392destroy_peer_info(struct MeshTunnel *t, struct MeshPeerInfo *pi)
388{ 393{
389 GNUNET_PEER_change_rc(pi->id, -1); 394 GNUNET_PEER_change_rc(pi->id, -1);
390 GNUNET_CONTAINER_DLL_remove(t->peers_head, t->peers_tail, pi); 395 GNUNET_CONTAINER_DLL_remove(t->peers_head, t->peers_tail, pi);
@@ -399,11 +404,13 @@ destroy_peer_info(struct MESH_tunnel *t, struct MeshPeerInfo *pi)
399 * @return GNUNET_OK on success 404 * @return GNUNET_OK on success
400 */ 405 */
401static int 406static int
402destroy_tunnel(struct MeshClient *c, struct MESH_tunnel *t) 407destroy_tunnel(struct MeshClient *c, struct MeshTunnel *t)
403{ 408{
404 struct MeshPeerInfo *pi; 409 struct MeshPeerInfo *pi;
405 struct MeshPath *path; 410 struct MeshPath *path;
406 411
412 if (NULL == t) return GNUNET_OK;
413
407 for (pi = t->peers_head; pi != NULL; pi = t->peers_head) { 414 for (pi = t->peers_head; pi != NULL; pi = t->peers_head) {
408 destroy_peer_info(t, pi); 415 destroy_peer_info(t, pi);
409 } 416 }
@@ -617,7 +624,7 @@ dht_get_response_handler(void *cls,
617 const void *data) 624 const void *data)
618{ 625{
619 struct MeshPeerInfo *peer_info; 626 struct MeshPeerInfo *peer_info;
620 struct MESH_tunnel *t; 627 struct MeshTunnel *t;
621 struct MeshPath *p; 628 struct MeshPath *p;
622 int i; 629 int i;
623 630
@@ -679,7 +686,7 @@ static void
679handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) 686handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
680{ 687{
681 struct MeshClient *c, *next; 688 struct MeshClient *c, *next;
682 struct MESH_tunnel *t; 689 struct MeshTunnel *t;
683 690
684 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 691 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
685 "MESH: client disconnected\n"); 692 "MESH: client disconnected\n");
@@ -694,6 +701,7 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
694 } 701 }
695 if(0 != c->app_counter) GNUNET_free (c->apps); 702 if(0 != c->app_counter) GNUNET_free (c->apps);
696 if(0 != c->type_counter) GNUNET_free (c->types); 703 if(0 != c->type_counter) GNUNET_free (c->types);
704 GNUNET_CONTAINER_multihashmap_destroy(c->tunnel_ids);
697 next = c->next; 705 next = c->next;
698 GNUNET_free (c); 706 GNUNET_free (c);
699 c = next; 707 c = next;
@@ -761,6 +769,7 @@ handle_local_new_client (void *cls,
761 769
762 /* Insert new client in DLL */ 770 /* Insert new client in DLL */
763 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c); 771 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c);
772 c->tunnel_ids = GNUNET_CONTAINER_multihashmap_create(100);
764 773
765 GNUNET_SERVER_receive_done(client, GNUNET_OK); 774 GNUNET_SERVER_receive_done(client, GNUNET_OK);
766 775
@@ -780,8 +789,9 @@ handle_local_tunnel_create (void *cls,
780 const struct GNUNET_MessageHeader *message) 789 const struct GNUNET_MessageHeader *message)
781{ 790{
782 struct GNUNET_MESH_TunnelMessage *tunnel_msg; 791 struct GNUNET_MESH_TunnelMessage *tunnel_msg;
783 struct MESH_tunnel *t; 792 struct MeshTunnel *t;
784 struct MeshClient *c; 793 struct MeshClient *c;
794 GNUNET_HashCode hash;
785 795
786 /* Sanity check for client registration */ 796 /* Sanity check for client registration */
787 if (NULL == (c = retrieve_client(client))) { 797 if (NULL == (c = retrieve_client(client))) {
@@ -814,12 +824,21 @@ handle_local_tunnel_create (void *cls,
814 } 824 }
815 t = t->next; 825 t = t->next;
816 } 826 }
817 /* FIXME: calloc? Is NULL != 0 on any platform? */ 827 t = GNUNET_malloc(sizeof(struct MeshTunnel ));
818 t = GNUNET_malloc(sizeof(struct MESH_tunnel));
819 t->tid = ntohl(tunnel_msg->tunnel_id); 828 t->tid = ntohl(tunnel_msg->tunnel_id);
820 t->oid = myid; 829 t->oid = myid;
821 t->client = c; 830 t->client = c;
822 831
832 GNUNET_CRYPTO_hash(&t->tid, sizeof(MESH_TunnelID), &hash);
833 if (GNUNET_OK !=
834 GNUNET_CONTAINER_multihashmap_put(c->tunnel_ids, &hash, t,
835 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
836 {
837 GNUNET_break(0);
838 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
839 return;
840 }
841
823 GNUNET_CONTAINER_DLL_insert(c->tunnels_head, c->tunnels_tail, t); 842 GNUNET_CONTAINER_DLL_insert(c->tunnels_head, c->tunnels_tail, t);
824 843
825 GNUNET_SERVER_receive_done(client, GNUNET_OK); 844 GNUNET_SERVER_receive_done(client, GNUNET_OK);
@@ -841,8 +860,10 @@ handle_local_tunnel_destroy (void *cls,
841{ 860{
842 struct GNUNET_MESH_TunnelMessage *tunnel_msg; 861 struct GNUNET_MESH_TunnelMessage *tunnel_msg;
843 struct MeshClient *c; 862 struct MeshClient *c;
844 struct MESH_tunnel *t; 863 struct MeshTunnel *t;
845 MESH_TunnelID tid; 864 MESH_TunnelID tid;
865 GNUNET_HashCode hash;
866
846 867
847 /* Sanity check for client registration */ 868 /* Sanity check for client registration */
848 if (NULL == (c = retrieve_client(client))) { 869 if (NULL == (c = retrieve_client(client))) {
@@ -859,25 +880,11 @@ handle_local_tunnel_destroy (void *cls,
859 880
860 tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message; 881 tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message;
861 882
862 /* Tunnel exists? */ 883 /* Retrieve tunnel */
863 tid = ntohl(tunnel_msg->tunnel_id); 884 tid = ntohl(tunnel_msg->tunnel_id);
864 if (NULL == (t = c->tunnels_head)) { 885 GNUNET_CRYPTO_hash(&tid, sizeof(MESH_TunnelID), &hash);
865 GNUNET_break(0); 886 t = GNUNET_CONTAINER_multihashmap_get(c->tunnel_ids, &hash);
866 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 887 GNUNET_CONTAINER_multihashmap_remove_all(c->tunnel_ids, &hash);
867 return;
868 }
869 while (NULL != t) {
870 if (t->tid == tid) {
871 break;
872 }
873 if (t == c->tunnels_tail) {
874 GNUNET_break(0);
875 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
876 return;
877 }
878 t = t->next;
879 }
880
881 destroy_tunnel(c, t); 888 destroy_tunnel(c, t);
882 889
883 GNUNET_SERVER_receive_done(client, GNUNET_OK); 890 GNUNET_SERVER_receive_done(client, GNUNET_OK);
@@ -899,7 +906,7 @@ handle_local_connect_add (void *cls,
899{ 906{
900 struct GNUNET_MESH_PeerControl *peer_msg; 907 struct GNUNET_MESH_PeerControl *peer_msg;
901 struct MeshClient *c; 908 struct MeshClient *c;
902 struct MESH_tunnel *t; 909 struct MeshTunnel *t;
903 MESH_TunnelID tid; 910 MESH_TunnelID tid;
904 struct MeshPeerInfo *peer_info; 911 struct MeshPeerInfo *peer_info;
905 GNUNET_HashCode key; 912 GNUNET_HashCode key;
@@ -985,7 +992,7 @@ handle_local_connect_del (void *cls,
985{ 992{
986 struct GNUNET_MESH_PeerControl *peer_msg; 993 struct GNUNET_MESH_PeerControl *peer_msg;
987 struct MeshClient *c; 994 struct MeshClient *c;
988 struct MESH_tunnel *t; 995 struct MeshTunnel *t;
989 struct MeshPath *p; 996 struct MeshPath *p;
990 struct MeshPath *aux_path; 997 struct MeshPath *aux_path;
991 MESH_TunnelID tid; 998 MESH_TunnelID tid;
@@ -1093,7 +1100,7 @@ handle_local_connect_by_type (void *cls,
1093 MESH_TunnelID tid; 1100 MESH_TunnelID tid;
1094 GNUNET_MESH_ApplicationType application; 1101 GNUNET_MESH_ApplicationType application;
1095 struct MeshClient *c; 1102 struct MeshClient *c;
1096 struct MESH_tunnel *t; 1103 struct MeshTunnel *t;
1097 1104
1098 /* Sanity check for client registration */ 1105 /* Sanity check for client registration */
1099 if (NULL == (c = retrieve_client(client))) { 1106 if (NULL == (c = retrieve_client(client))) {
@@ -1156,7 +1163,7 @@ handle_local_network_traffic (void *cls,
1156 const struct GNUNET_MessageHeader *message) 1163 const struct GNUNET_MessageHeader *message)
1157{ 1164{
1158 struct MeshClient *c; 1165 struct MeshClient *c;
1159 struct MESH_tunnel *t; 1166 struct MeshTunnel *t;
1160 struct GNUNET_MESH_Data *data_msg; 1167 struct GNUNET_MESH_Data *data_msg;
1161 MESH_TunnelID tid; 1168 MESH_TunnelID tid;
1162 1169
@@ -1217,7 +1224,7 @@ handle_local_network_traffic_bcast (void *cls,
1217 const struct GNUNET_MessageHeader *message) 1224 const struct GNUNET_MessageHeader *message)
1218{ 1225{
1219 struct MeshClient *c; 1226 struct MeshClient *c;
1220 struct MESH_tunnel *t; 1227 struct MeshTunnel *t;
1221 struct GNUNET_MESH_DataBroadcast *data_msg; 1228 struct GNUNET_MESH_DataBroadcast *data_msg;
1222 MESH_TunnelID tid; 1229 MESH_TunnelID tid;
1223 1230
diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c
index e466bca94..c9c71405c 100644
--- a/src/mesh/mesh_api_new.c
+++ b/src/mesh/mesh_api_new.c
@@ -45,6 +45,7 @@ extern "C"
45#include "gnunet_common.h" 45#include "gnunet_common.h"
46#include "gnunet_client_lib.h" 46#include "gnunet_client_lib.h"
47#include "gnunet_util_lib.h" 47#include "gnunet_util_lib.h"
48#include "gnunet_peer_lib.h"
48#include "gnunet_mesh_service_new.h" 49#include "gnunet_mesh_service_new.h"
49#include "mesh.h" 50#include "mesh.h"
50 51
@@ -121,11 +122,6 @@ struct GNUNET_MESH_Tunnel {
121 struct GNUNET_MESH_Tunnel *prev; 122 struct GNUNET_MESH_Tunnel *prev;
122 123
123 /** 124 /**
124 * Owner of the tunnel, either local or remote
125 */
126 GNUNET_PEER_Id owner;
127
128 /**
129 * Local ID of the tunnel 125 * Local ID of the tunnel
130 */ 126 */
131 MESH_TunnelID tid; 127 MESH_TunnelID tid;
@@ -341,6 +337,7 @@ process_tunnel_create(struct GNUNET_MESH_Handle *h,
341 t->disconnect_handler = NULL; 337 t->disconnect_handler = NULL;
342 t->mesh = h; 338 t->mesh = h;
343 t->tid = tid; 339 t->tid = tid;
340
344 return; 341 return;
345} 342}
346 343