aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/gnunet-service-mesh.c
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-06-09 17:05:42 +0000
committerBart Polot <bart@net.in.tum.de>2011-06-09 17:05:42 +0000
commitd137ef455b759490dfc4c658054fdbe3bc8708e7 (patch)
treeab0b0faf030517d9b2022dcf5ed660ec314bbeb5 /src/mesh/gnunet-service-mesh.c
parent7827837df0b1a254080fb1e4d1f4163ebfddebc7 (diff)
downloadgnunet-d137ef455b759490dfc4c658054fdbe3bc8708e7.tar.gz
gnunet-d137ef455b759490dfc4c658054fdbe3bc8708e7.zip
WiP (service rewrite)
Diffstat (limited to 'src/mesh/gnunet-service-mesh.c')
-rw-r--r--src/mesh/gnunet-service-mesh.c336
1 files changed, 159 insertions, 177 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index ca2d652e7..04b562687 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -86,22 +86,11 @@ enum MeshPeerState
86struct MeshPeerInfo 86struct MeshPeerInfo
87{ 87{
88 /** 88 /**
89 * Double linked list
90 */
91 struct MeshPeerInfo *next;
92 struct MeshPeerInfo *prev;
93
94 /**
95 * ID of the peer 89 * ID of the peer
96 */ 90 */
97 GNUNET_PEER_Id id; 91 GNUNET_PEER_Id id;
98 92
99 /** 93 /**
100 * Tunnel this peer belongs to
101 */
102 struct MeshTunnel *t;
103
104 /**
105 * Is the peer reachable? Is the peer even connected? 94 * Is the peer reachable? Is the peer even connected?
106 */ 95 */
107 enum MeshPeerState state; 96 enum MeshPeerState state;
@@ -112,19 +101,19 @@ struct MeshPeerInfo
112 struct GNUNET_TIME_Absolute next_reconnect_attempt; 101 struct GNUNET_TIME_Absolute next_reconnect_attempt;
113 102
114 /** 103 /**
115 * Who to send the data to --- FIXME what about multiple (alternate) paths? 104 * Number of attempts to reconnect so far
116 */ 105 */
117 GNUNET_PEER_Id first_hop; 106 int n_reconnect_attempts;
118 107
119 /** 108 /**
120 * Max data rate to this peer 109 * First hop whom to send data to reach this peer in the current active path
121 */ 110 */
122 uint32_t max_speed; 111 GNUNET_PEER_Id first_hop;
123 112
124 /** 113 /**
125 * Handle to stop the DHT search for a path to this peer 114 * Handle to stop the DHT search for a path to this peer
126 */ 115 */
127 struct GNUNET_DHT_GetHandle *dhtget; 116 struct GNUNET_DHT_GetHandle *dhtget;
128}; 117};
129 118
130 119
@@ -156,6 +145,10 @@ struct MeshPath
156 * List of all the peers that form the path from origin to target 145 * List of all the peers that form the path from origin to target
157 */ 146 */
158 GNUNET_PEER_Id *peers; 147 GNUNET_PEER_Id *peers;
148
149 /**
150 * Number of peers (hops) in the path
151 */
159 int length; 152 int length;
160}; 153};
161 154
@@ -171,6 +164,16 @@ struct MeshQueue
171 struct MeshQueue *prev; 164 struct MeshQueue *prev;
172 165
173 /** 166 /**
167 * Target of the data (NULL if target is client)
168 */
169 struct MeshPeerInfo *peer;
170
171 /**
172 * Client to send the data to (NULL if target is peer)
173 */
174 struct MeshClient *client;
175
176 /**
174 * Size of the message to transmit 177 * Size of the message to transmit
175 */ 178 */
176 unsigned int size; 179 unsigned int size;
@@ -186,45 +189,43 @@ struct MeshQueue
186 struct GNUNET_MessageHeader *data; 189 struct GNUNET_MessageHeader *data;
187}; 190};
188 191
189
190struct MeshClient; /* FWD declaration */
191/** 192/**
192 * Struct containing all information regarding a tunnel 193 * Globally unique tunnel identification (owner + number)
193 * For an intermediate node the improtant info used will be: 194 * DO NOT USE OVER THE NETWORK
194 * - OID \ To identify
195 * - TID / the tunnel
196 * - paths[0] | To know where to send it next
197 * - metainfo: ready, speeds, accounting
198 * For an end node more fields will be needed (client-handling)
199 */ 195 */
200struct MeshTunnel 196struct MESH_TunnelID {
201{
202
203 /** 197 /**
204 * Double linked list 198 * Node that owns the tunnel
205 */ 199 */
206 struct MeshTunnel *next; 200 GNUNET_PEER_Id oid;
207 struct MeshTunnel *prev;
208 201
209 /** 202 /**
210 * Origin ID: Node that created the tunnel 203 * Tunnel number to differentiate all the tunnels owned by the node oid
204 * ( tid < GNUNET_MESH_LOCAL_TUNNEL_ID_MARK )
211 */ 205 */
212 GNUNET_PEER_Id oid; 206 MESH_TunnelNumber tid;
207};
213 208
214 /**
215 * Tunnel number (unique for a given oid)
216 */
217 MESH_TunnelID tid;
218 209
210struct MeshClient; /* FWD declaration */
211/**
212 * Struct containing all information regarding a tunnel
213 * For an intermediate node the improtant info used will be:
214 * - id Tunnel unique identification
215 * - paths[0] To know where to send it next
216 * - metainfo: ready, speeds, accounting
217 */
218struct MeshTunnel
219{
219 /** 220 /**
220 * Minimal speed for this tunnel in kb/s 221 * Tunnel ID
221 */ 222 */
222 uint32_t speed_min; 223 struct MESH_TunnelID id;
223 224
224 /** 225 /**
225 * Maximal speed for this tunnel in kb/s 226 * Local tunnel number ( >= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK or 0 )
226 */ 227 */
227 uint32_t speed_max; 228 MESH_TunnelNumber local_tid;
228 229
229 /** 230 /**
230 * Last time the tunnel was used 231 * Last time the tunnel was used
@@ -234,8 +235,7 @@ struct MeshTunnel
234 /** 235 /**
235 * Peers in the tunnel, for future optimizations 236 * Peers in the tunnel, for future optimizations
236 */ 237 */
237 struct MeshPeerInfo *peers_head; 238 struct GNUNET_CONTAINER_MultiHashMap* peers;
238 struct MeshPeerInfo *peers_tail;
239 239
240 /** 240 /**
241 * Number of peers that are connected and potentially ready to receive data 241 * Number of peers that are connected and potentially ready to receive data
@@ -254,21 +254,15 @@ struct MeshTunnel
254 struct MeshPath *paths_tail; 254 struct MeshPath *paths_tail;
255 255
256 /** 256 /**
257 * If this tunnel was created by a local client, what's its handle? 257 * Client owner of the tunnel, if any
258 */ 258 */
259 struct MeshClient *client; 259 struct MeshClient *client;
260 260
261 /** 261 /**
262 * Messages ready to transmit 262 * Messages ready to transmit
263 */ 263 */
264 struct MeshQueue *out_head; 264 struct MeshQueue *queue_head;
265 struct MeshQueue *out_tail; 265 struct MeshQueue *queue_tail;
266
267 /**
268 * Messages received and not processed
269 */
270 struct MeshQueue *in_head;
271 struct MeshQueue *in_tail;
272 266
273}; 267};
274 268
@@ -278,16 +272,14 @@ struct MeshTunnel
278struct MeshClient 272struct MeshClient
279{ 273{
280 /** 274 /**
281 * Double linked list 275 * Linked list
282 */ 276 */
283 struct MeshClient *next; 277 struct MeshClient *next;
284 struct MeshClient *prev;
285 278
286 /** 279 /**
287 * Tunnels that belong to this client, for convenience on disconnect 280 * Tunnels that belong to this client, indexed by local id
288 */ 281 */
289 struct MeshTunnel *tunnels_head; 282 struct GNUNET_CONTAINER_MultiHashMap* tunnels;
290 struct MeshTunnel *tunnels_tail;
291 283
292 /** 284 /**
293 * Handle to communicate with the client 285 * Handle to communicate with the client
@@ -306,11 +298,6 @@ struct MeshClient
306 uint16_t *types; 298 uint16_t *types;
307 unsigned int type_counter; 299 unsigned int type_counter;
308 300
309 /**
310 * Map tunnel IDs used by the client to owner and global tunnel ID
311 */
312 struct GNUNET_CONTAINER_MultiHashMap* tunnel_ids;
313
314}; 301};
315 302
316/******************************************************************************/ 303/******************************************************************************/
@@ -320,14 +307,12 @@ struct MeshClient
320/** 307/**
321 * All the clients 308 * All the clients
322 */ 309 */
323static struct MeshClient *clients_head; 310static struct MeshClient *clients;
324static struct MeshClient *clients_tail;
325 311
326/** 312/**
327 * Tunnels not owned by this node 313 * Tunnels known, indexed by MESH_TunnelID
328 */ 314 */
329// static struct MESH_Tunnel *tunnels_head; 315struct GNUNET_CONTAINER_MultiHashMap *tunnels;
330// static struct MESH_Tunnel *tunnels_tail;
331 316
332/** 317/**
333 * Handle to communicate with core 318 * Handle to communicate with core
@@ -344,6 +329,11 @@ static struct GNUNET_DHT_Handle *dht_handle;
344 */ 329 */
345static GNUNET_PEER_Id myid; 330static GNUNET_PEER_Id myid;
346 331
332/**
333 * Tunnel ID for the next created tunnel
334 */
335static MESH_TunnelNumber next_tid;
336
347/******************************************************************************/ 337/******************************************************************************/
348/****************** GENERAL HELPER FUNCTIONS ************************/ 338/****************** GENERAL HELPER FUNCTIONS ************************/
349/******************************************************************************/ 339/******************************************************************************/
@@ -358,7 +348,7 @@ retrieve_client (struct GNUNET_SERVER_Client *client)
358{ 348{
359 struct MeshClient *c; 349 struct MeshClient *c;
360 350
361 c = clients_head; 351 c = clients;
362 while (NULL != c) { 352 while (NULL != c) {
363 if (c->handle == client) return c; 353 if (c->handle == client) return c;
364 c = c->next; 354 c = c->next;
@@ -367,6 +357,38 @@ retrieve_client (struct GNUNET_SERVER_Client *client)
367} 357}
368 358
369/** 359/**
360 * Search for a tunnel among the tunnels for a client
361 * @param client the client whose tunnels to search in
362 * @param tid the local id of the tunnel
363 * @return tunnel handler, NULL if doesn't exist
364 */
365static struct MeshTunnel *
366retrieve_tunnel_by_local_id (struct MeshClient *c, MESH_TunnelNumber tid)
367{
368 GNUNET_HashCode hash;
369
370 GNUNET_CRYPTO_hash(&tid, sizeof(MESH_TunnelNumber), &hash);
371 return GNUNET_CONTAINER_multihashmap_get(c->tunnels, &hash);
372}
373
374/**
375 * Search for a tunnel by global ID
376 */
377static struct MeshTunnel *
378retrieve_tunnel (struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid)
379{
380 struct MESH_TunnelID id;
381 GNUNET_HashCode hash;
382
383 id.oid = GNUNET_PEER_intern(oid);
384 GNUNET_PEER_change_rc(id.oid, -1);
385 id.tid = tid;
386
387 GNUNET_CRYPTO_hash(&id, sizeof(struct MESH_TunnelID), &hash);
388 return GNUNET_CONTAINER_multihashmap_get(tunnels, &hash);
389}
390
391/**
370 * Destroy the path and free any allocated resources linked to it 392 * Destroy the path and free any allocated resources linked to it
371 * @param t tunnel the path belongs to 393 * @param t tunnel the path belongs to
372 * @param p the path to destroy 394 * @param p the path to destroy
@@ -392,7 +414,7 @@ static int
392destroy_peer_info(struct MeshTunnel *t, struct MeshPeerInfo *pi) 414destroy_peer_info(struct MeshTunnel *t, struct MeshPeerInfo *pi)
393{ 415{
394 GNUNET_PEER_change_rc(pi->id, -1); 416 GNUNET_PEER_change_rc(pi->id, -1);
395 GNUNET_CONTAINER_DLL_remove(t->peers_head, t->peers_tail, pi); 417 /* FIXME delete from list */
396 GNUNET_free(pi); 418 GNUNET_free(pi);
397 return GNUNET_OK; 419 return GNUNET_OK;
398} 420}
@@ -406,22 +428,29 @@ destroy_peer_info(struct MeshTunnel *t, struct MeshPeerInfo *pi)
406static int 428static int
407destroy_tunnel(struct MeshClient *c, struct MeshTunnel *t) 429destroy_tunnel(struct MeshClient *c, struct MeshTunnel *t)
408{ 430{
409 struct MeshPeerInfo *pi;
410 struct MeshPath *path; 431 struct MeshPath *path;
432 GNUNET_HashCode hash;
433 int r;
411 434
412 if (NULL == t) return GNUNET_OK; 435 if (NULL == t) return GNUNET_OK;
413 436
414 for (pi = t->peers_head; pi != NULL; pi = t->peers_head) { 437 for (path = t->paths_head; path != NULL; path = t->paths_head) {
415 destroy_peer_info(t, pi); 438 if(GNUNET_OK != destroy_path(t, path)) r = GNUNET_SYSERR;
416 } 439 }
417 440
418 for (path = t->paths_head; path != NULL; path = t->paths_head) { 441 GNUNET_CRYPTO_hash(&t->id, sizeof(struct MESH_TunnelID), &hash);
419 destroy_path(t, path); 442 if(GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove(tunnels, &hash, t)) {
443 r = GNUNET_SYSERR;
420 } 444 }
421 445
422 GNUNET_CONTAINER_DLL_remove(c->tunnels_head, c->tunnels_tail, t); 446 GNUNET_CRYPTO_hash(&t->local_tid, sizeof(MESH_TunnelNumber), &hash);
447 if(GNUNET_YES !=
448 GNUNET_CONTAINER_multihashmap_remove(c->tunnels, &hash, t))
449 {
450 r = GNUNET_SYSERR;
451 }
423 GNUNET_free(t); 452 GNUNET_free(t);
424 return GNUNET_OK; 453 return r;
425} 454}
426 455
427/******************************************************************************/ 456/******************************************************************************/
@@ -429,6 +458,7 @@ destroy_tunnel(struct MeshClient *c, struct MeshTunnel *t)
429/******************************************************************************/ 458/******************************************************************************/
430 459
431/** 460/**
461 * FIXME: rewrite
432 * Function called to notify a client about the socket 462 * Function called to notify a client about the socket
433 * being ready to queue more data. "buf" will be 463 * being ready to queue more data. "buf" will be
434 * NULL and "size" zero if the socket was closed for 464 * NULL and "size" zero if the socket was closed for
@@ -456,7 +486,7 @@ send_core_create_path_for_peer (void *cls, size_t size, void *buf)
456 } 486 }
457 peer_info = (struct MeshPeerInfo *)cls; 487 peer_info = (struct MeshPeerInfo *)cls;
458 peer_info->dhtget = NULL; 488 peer_info->dhtget = NULL;
459 p = peer_info->t->paths_head; 489// p = peer_info->t->paths_head;
460 while (NULL != p) { 490 while (NULL != p) {
461 if (p->peers[p->length-1] == peer_info->id) { 491 if (p->peers[p->length-1] == peer_info->id) {
462 break; 492 break;
@@ -507,7 +537,7 @@ send_p2p_tunnel_destroy(void *cls, size_t size, void *buf)
507 msg = buf; 537 msg = buf;
508 msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); /*FIXME*/ 538 msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); /*FIXME*/
509 msg->header.size = htons(sizeof(struct GNUNET_MESH_TunnelMessage)); 539 msg->header.size = htons(sizeof(struct GNUNET_MESH_TunnelMessage));
510 msg->tunnel_id = htonl(t->tid); 540 msg->tunnel_id = htonl(t->id.tid);
511 541
512 destroy_tunnel(c, t); 542 destroy_tunnel(c, t);
513 return sizeof(struct GNUNET_MESH_TunnelMessage); 543 return sizeof(struct GNUNET_MESH_TunnelMessage);
@@ -585,6 +615,13 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
585/********************* MESH LOCAL HANDLES **************************/ 615/********************* MESH LOCAL HANDLES **************************/
586/******************************************************************************/ 616/******************************************************************************/
587 617
618static int
619delete_tunnel_entry (void *cls, const GNUNET_HashCode * key, void *value) {
620 int r;
621 r = destroy_tunnel((struct MeshClient *) cls, (struct MeshTunnel *) value);
622 return r;
623}
624
588/** 625/**
589 * notify_client_connection_failure: notify a client that the connection to the 626 * notify_client_connection_failure: notify a client that the connection to the
590 * requested remote peer is not possible (for instance, no route found) 627 * requested remote peer is not possible (for instance, no route found)
@@ -614,7 +651,7 @@ notify_client_connection_failure (void *cls, size_t size, void *buf)
614 msg = (struct GNUNET_MESH_PeerControl *) buf; 651 msg = (struct GNUNET_MESH_PeerControl *) buf;
615 msg->header.size = htons(sizeof(struct GNUNET_MESH_PeerControl)); 652 msg->header.size = htons(sizeof(struct GNUNET_MESH_PeerControl));
616 msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED); 653 msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED);
617 msg->tunnel_id = htonl(peer_info->t->tid); 654// msg->tunnel_id = htonl(peer_info->t->tid);
618 GNUNET_PEER_resolve(peer_info->id, &id); 655 GNUNET_PEER_resolve(peer_info->id, &id);
619 memcpy(&msg->peer, &id, sizeof(struct GNUNET_PeerIdentity)); 656 memcpy(&msg->peer, &id, sizeof(struct GNUNET_PeerIdentity));
620 657
@@ -623,6 +660,7 @@ notify_client_connection_failure (void *cls, size_t size, void *buf)
623 660
624 661
625/** 662/**
663 * FIXME: rewrite
626 * Function to process paths received for a new peer addition. The recorded 664 * Function to process paths received for a new peer addition. The recorded
627 * paths form the initial tunnel, which can be optimized later. 665 * paths form the initial tunnel, which can be optimized later.
628 * Called on each result obtained for the DHT search. 666 * Called on each result obtained for the DHT search.
@@ -654,7 +692,7 @@ dht_get_response_handler(void *cls,
654 int i; 692 int i;
655 693
656 peer_info = (struct MeshPeerInfo *)cls; 694 peer_info = (struct MeshPeerInfo *)cls;
657 t = peer_info->t; 695// t = peer_info->t;
658 696
659 if (NULL == get_path || NULL == put_path) { 697 if (NULL == get_path || NULL == put_path) {
660 // TODO: find ourselves some alternate initial path to the destination 698 // TODO: find ourselves some alternate initial path to the destination
@@ -710,23 +748,22 @@ dht_get_response_handler(void *cls,
710static void 748static void
711handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) 749handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
712{ 750{
713 struct MeshClient *c, *next; 751 struct MeshClient *c;
714 struct MeshTunnel *t; 752 struct MeshClient *next;
715 753
716 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 754 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
717 "MESH: client disconnected\n"); 755 "MESH: client disconnected\n");
718 c = clients_head; 756 c = clients;
719 while (NULL != c) { 757 while (NULL != c) {
720 if (c->handle == client) { 758 if (c->handle == client) {
721 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 759 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
722 "MESH: matching client found, cleaning\n"); 760 "MESH: matching client found, cleaning\n");
723 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c); 761 GNUNET_CONTAINER_multihashmap_iterate(c->tunnels,
724 while (NULL != (t = c->tunnels_head)) { 762 &delete_tunnel_entry,
725 destroy_tunnel(c, t); 763 c);
726 } 764 GNUNET_CONTAINER_multihashmap_destroy(c->tunnels);
727 if(0 != c->app_counter) GNUNET_free (c->apps); 765 if(0 != c->app_counter) GNUNET_free (c->apps);
728 if(0 != c->type_counter) GNUNET_free (c->types); 766 if(0 != c->type_counter) GNUNET_free (c->types);
729 GNUNET_CONTAINER_multihashmap_destroy(c->tunnel_ids);
730 next = c->next; 767 next = c->next;
731 GNUNET_free (c); 768 GNUNET_free (c);
732 c = next; 769 c = next;
@@ -793,8 +830,8 @@ handle_local_new_client (void *cls,
793 c->app_counter); 830 c->app_counter);
794 831
795 /* Insert new client in DLL */ 832 /* Insert new client in DLL */
796 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c); 833 /* FIXME insert client */
797 c->tunnel_ids = GNUNET_CONTAINER_multihashmap_create(100); 834 c->tunnels = GNUNET_CONTAINER_multihashmap_create(100);
798 835
799 GNUNET_SERVER_receive_done(client, GNUNET_OK); 836 GNUNET_SERVER_receive_done(client, GNUNET_OK);
800 837
@@ -813,7 +850,7 @@ handle_local_tunnel_create (void *cls,
813 struct GNUNET_SERVER_Client *client, 850 struct GNUNET_SERVER_Client *client,
814 const struct GNUNET_MessageHeader *message) 851 const struct GNUNET_MessageHeader *message)
815{ 852{
816 struct GNUNET_MESH_TunnelMessage *tunnel_msg; 853 struct GNUNET_MESH_TunnelMessage *t_msg;
817 struct MeshTunnel *t; 854 struct MeshTunnel *t;
818 struct MeshClient *c; 855 struct MeshClient *c;
819 GNUNET_HashCode hash; 856 GNUNET_HashCode hash;
@@ -832,31 +869,30 @@ handle_local_tunnel_create (void *cls,
832 return; 869 return;
833 } 870 }
834 871
835 tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message; 872 t_msg = (struct GNUNET_MESH_TunnelMessage *) message;
836 /* Sanity check for tunnel numbering */ 873 /* Sanity check for tunnel numbering */
837 if (0 == (ntohl(tunnel_msg->tunnel_id) & 0x80000000)) { 874 if (0 == (ntohl(t_msg->tunnel_id) & GNUNET_MESH_LOCAL_TUNNEL_ID_MARK)) {
838 GNUNET_break(0); 875 GNUNET_break(0);
839 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 876 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
840 return; 877 return;
841 } 878 }
842 /* Sanity check for duplicate tunnel IDs */ 879 /* Sanity check for duplicate tunnel IDs */
843 t = c->tunnels_head; 880 if(NULL != retrieve_tunnel_by_local_id(c, ntohl(t_msg->tunnel_id))) {
844 while (NULL != t) { 881 GNUNET_break(0);
845 if (t->tid == ntohl(tunnel_msg->tunnel_id)) { 882 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
846 GNUNET_break(0); 883 return;
847 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
848 return;
849 }
850 t = t->next;
851 } 884 }
852 t = GNUNET_malloc(sizeof(struct MeshTunnel )); 885 t = GNUNET_malloc(sizeof(struct MeshTunnel ));
853 t->tid = ntohl(tunnel_msg->tunnel_id); 886 // FIXME:what if all 2^32 ID are taken?
854 t->oid = myid; 887 while (NULL != retrieve_tunnel_by_local_id(c, next_tid)) next_tid++;
888 t->id.tid = next_tid++;
889 t->id.oid = myid;
890 t->local_tid = ntohl(t_msg->tunnel_id);
855 t->client = c; 891 t->client = c;
856 892
857 GNUNET_CRYPTO_hash(&t->tid, sizeof(MESH_TunnelID), &hash); 893 GNUNET_CRYPTO_hash(&t->local_tid, sizeof(MESH_TunnelNumber), &hash);
858 if (GNUNET_OK != 894 if (GNUNET_OK !=
859 GNUNET_CONTAINER_multihashmap_put(c->tunnel_ids, &hash, t, 895 GNUNET_CONTAINER_multihashmap_put(c->tunnels, &hash, t,
860 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 896 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
861 { 897 {
862 GNUNET_break(0); 898 GNUNET_break(0);
@@ -864,7 +900,7 @@ handle_local_tunnel_create (void *cls,
864 return; 900 return;
865 } 901 }
866 902
867 GNUNET_CONTAINER_DLL_insert(c->tunnels_head, c->tunnels_tail, t); 903 /* FIXME insert */
868 904
869 GNUNET_SERVER_receive_done(client, GNUNET_OK); 905 GNUNET_SERVER_receive_done(client, GNUNET_OK);
870 return; 906 return;
@@ -886,7 +922,7 @@ handle_local_tunnel_destroy (void *cls,
886 struct GNUNET_MESH_TunnelMessage *tunnel_msg; 922 struct GNUNET_MESH_TunnelMessage *tunnel_msg;
887 struct MeshClient *c; 923 struct MeshClient *c;
888 struct MeshTunnel *t; 924 struct MeshTunnel *t;
889 MESH_TunnelID tid; 925 MESH_TunnelNumber tid;
890 GNUNET_HashCode hash; 926 GNUNET_HashCode hash;
891 927
892 928
@@ -907,9 +943,9 @@ handle_local_tunnel_destroy (void *cls,
907 943
908 /* Retrieve tunnel */ 944 /* Retrieve tunnel */
909 tid = ntohl(tunnel_msg->tunnel_id); 945 tid = ntohl(tunnel_msg->tunnel_id);
910 GNUNET_CRYPTO_hash(&tid, sizeof(MESH_TunnelID), &hash); 946 GNUNET_CRYPTO_hash(&tid, sizeof(MESH_TunnelNumber), &hash);
911 t = GNUNET_CONTAINER_multihashmap_get(c->tunnel_ids, &hash); 947 t = GNUNET_CONTAINER_multihashmap_get(c->tunnels, &hash);
912 GNUNET_CONTAINER_multihashmap_remove_all(c->tunnel_ids, &hash); 948 GNUNET_CONTAINER_multihashmap_remove_all(c->tunnels, &hash);
913 GNUNET_CORE_notify_transmit_ready(core_handle, 949 GNUNET_CORE_notify_transmit_ready(core_handle,
914 1, 950 1,
915 1, 951 1,
@@ -939,7 +975,7 @@ handle_local_connect_add (void *cls,
939 struct GNUNET_MESH_PeerControl *peer_msg; 975 struct GNUNET_MESH_PeerControl *peer_msg;
940 struct MeshClient *c; 976 struct MeshClient *c;
941 struct MeshTunnel *t; 977 struct MeshTunnel *t;
942 MESH_TunnelID tid; 978 MESH_TunnelNumber tid;
943 struct MeshPeerInfo *peer_info; 979 struct MeshPeerInfo *peer_info;
944 GNUNET_HashCode key; 980 GNUNET_HashCode key;
945 981
@@ -961,13 +997,7 @@ handle_local_connect_add (void *cls,
961 997
962 /* Tunnel exists? */ 998 /* Tunnel exists? */
963 tid = ntohl(peer_msg->tunnel_id); 999 tid = ntohl(peer_msg->tunnel_id);
964 t = c->tunnels_head; 1000 t = retrieve_tunnel_by_local_id(c, tid);
965 while (NULL != t) {
966 if (t->tid == tid) {
967 break;
968 }
969 t = t->next;
970 }
971 if (NULL == t) { 1001 if (NULL == t) {
972 GNUNET_break(0); 1002 GNUNET_break(0);
973 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1003 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
@@ -985,9 +1015,8 @@ handle_local_connect_add (void *cls,
985 peer_info = (struct MeshPeerInfo *) GNUNET_malloc(sizeof(struct MeshPeerInfo)); 1015 peer_info = (struct MeshPeerInfo *) GNUNET_malloc(sizeof(struct MeshPeerInfo));
986 peer_info->id = GNUNET_PEER_intern(&peer_msg->peer); 1016 peer_info->id = GNUNET_PEER_intern(&peer_msg->peer);
987 peer_info->state = MESH_PEER_SEARCHING; 1017 peer_info->state = MESH_PEER_SEARCHING;
988 peer_info->t = t;
989 t->peers_total++; 1018 t->peers_total++;
990 GNUNET_CONTAINER_DLL_insert(t->peers_head, t->peers_tail, peer_info); 1019 /* FIXME insert */
991 /* Start DHT search */ 1020 /* Start DHT search */
992 GNUNET_CRYPTO_hash (&peer_msg->peer, 1021 GNUNET_CRYPTO_hash (&peer_msg->peer,
993 sizeof(struct GNUNET_PeerIdentity), 1022 sizeof(struct GNUNET_PeerIdentity),
@@ -1027,10 +1056,8 @@ handle_local_connect_del (void *cls,
1027 struct MeshTunnel *t; 1056 struct MeshTunnel *t;
1028 struct MeshPath *p; 1057 struct MeshPath *p;
1029 struct MeshPath *aux_path; 1058 struct MeshPath *aux_path;
1030 MESH_TunnelID tid; 1059 MESH_TunnelNumber tid;
1031 GNUNET_PEER_Id peer_id; 1060 GNUNET_PEER_Id peer_id;
1032 struct MeshPeerInfo *peer_info;
1033 struct MeshPeerInfo *aux_peer_info;
1034 1061
1035 /* Sanity check for client registration */ 1062 /* Sanity check for client registration */
1036 if (NULL == (c = retrieve_client(client))) { 1063 if (NULL == (c = retrieve_client(client))) {
@@ -1048,22 +1075,7 @@ handle_local_connect_del (void *cls,
1048 1075
1049 /* Tunnel exists? */ 1076 /* Tunnel exists? */
1050 tid = ntohl(peer_msg->tunnel_id); 1077 tid = ntohl(peer_msg->tunnel_id);
1051 if (NULL == (t = c->tunnels_head)) { 1078 t = retrieve_tunnel_by_local_id(c, tid);
1052 GNUNET_break(0);
1053 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
1054 return;
1055 }
1056 while (NULL != t) {
1057 if (t->tid == tid) {
1058 break;
1059 }
1060 if (t == c->tunnels_tail) {
1061 GNUNET_break(0);
1062 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
1063 return;
1064 }
1065 t = t->next;
1066 }
1067 if (NULL == t) { 1079 if (NULL == t) {
1068 GNUNET_break(0); 1080 GNUNET_break(0);
1069 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1081 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
@@ -1094,20 +1106,7 @@ handle_local_connect_del (void *cls,
1094 } 1106 }
1095 } 1107 }
1096 1108
1097 /*Delete peer info */ 1109 /* FIXME Delete peer info */
1098 peer_info = t->peers_head;
1099 while (peer_info != NULL) {
1100 if (peer_info->id == peer_id) {
1101 GNUNET_CONTAINER_DLL_remove(t->peers_head,
1102 t->peers_tail,
1103 peer_info);
1104 aux_peer_info = peer_info;
1105 peer_info = peer_info->next;
1106 GNUNET_free(aux_peer_info);
1107 } else {
1108 peer_info = peer_info->next;
1109 }
1110 }
1111 1110
1112 GNUNET_PEER_change_rc(peer_id, -1); 1111 GNUNET_PEER_change_rc(peer_id, -1);
1113 1112
@@ -1129,7 +1128,7 @@ handle_local_connect_by_type (void *cls,
1129 const struct GNUNET_MessageHeader *message) 1128 const struct GNUNET_MessageHeader *message)
1130{ 1129{
1131 struct GNUNET_MESH_ConnectPeerByType *connect_msg; 1130 struct GNUNET_MESH_ConnectPeerByType *connect_msg;
1132 MESH_TunnelID tid; 1131 MESH_TunnelNumber tid;
1133 GNUNET_MESH_ApplicationType application; 1132 GNUNET_MESH_ApplicationType application;
1134 struct MeshClient *c; 1133 struct MeshClient *c;
1135 struct MeshTunnel *t; 1134 struct MeshTunnel *t;
@@ -1153,13 +1152,7 @@ handle_local_connect_by_type (void *cls,
1153 1152
1154 /* Tunnel exists? */ 1153 /* Tunnel exists? */
1155 tid = ntohl(connect_msg->tunnel_id); 1154 tid = ntohl(connect_msg->tunnel_id);
1156 t = c->tunnels_head; 1155 t = retrieve_tunnel_by_local_id(c, tid);
1157 while (NULL != t) {
1158 if (t->tid == tid) {
1159 break;
1160 }
1161 t = t->next;
1162 }
1163 if (NULL == t) { 1156 if (NULL == t) {
1164 GNUNET_break(0); 1157 GNUNET_break(0);
1165 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1158 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
@@ -1197,7 +1190,7 @@ handle_local_network_traffic (void *cls,
1197 struct MeshClient *c; 1190 struct MeshClient *c;
1198 struct MeshTunnel *t; 1191 struct MeshTunnel *t;
1199 struct GNUNET_MESH_Data *data_msg; 1192 struct GNUNET_MESH_Data *data_msg;
1200 MESH_TunnelID tid; 1193 MESH_TunnelNumber tid;
1201 1194
1202 /* Sanity check for client registration */ 1195 /* Sanity check for client registration */
1203 if (NULL == (c = retrieve_client(client))) { 1196 if (NULL == (c = retrieve_client(client))) {
@@ -1217,13 +1210,7 @@ handle_local_network_traffic (void *cls,
1217 1210
1218 /* Tunnel exists? */ 1211 /* Tunnel exists? */
1219 tid = ntohl(data_msg->tunnel_id); 1212 tid = ntohl(data_msg->tunnel_id);
1220 t = c->tunnels_head; 1213 t = retrieve_tunnel_by_local_id(c, tid);
1221 while (NULL != t) {
1222 if (t->tid == tid) {
1223 break;
1224 }
1225 t = t->next;
1226 }
1227 if (NULL == t) { 1214 if (NULL == t) {
1228 GNUNET_break(0); 1215 GNUNET_break(0);
1229 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1216 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
@@ -1258,7 +1245,7 @@ handle_local_network_traffic_bcast (void *cls,
1258 struct MeshClient *c; 1245 struct MeshClient *c;
1259 struct MeshTunnel *t; 1246 struct MeshTunnel *t;
1260 struct GNUNET_MESH_DataBroadcast *data_msg; 1247 struct GNUNET_MESH_DataBroadcast *data_msg;
1261 MESH_TunnelID tid; 1248 MESH_TunnelNumber tid;
1262 1249
1263 /* Sanity check for client registration */ 1250 /* Sanity check for client registration */
1264 if (NULL == (c = retrieve_client(client))) { 1251 if (NULL == (c = retrieve_client(client))) {
@@ -1276,13 +1263,7 @@ handle_local_network_traffic_bcast (void *cls,
1276 1263
1277 /* Tunnel exists? */ 1264 /* Tunnel exists? */
1278 tid = ntohl(data_msg->tunnel_id); 1265 tid = ntohl(data_msg->tunnel_id);
1279 t = c->tunnels_head; 1266 t = retrieve_tunnel_by_local_id(c, tid);
1280 while (NULL != t) {
1281 if (t->tid == tid) {
1282 break;
1283 }
1284 t = t->next;
1285 }
1286 if (NULL == t) { 1267 if (NULL == t) {
1287 GNUNET_break(0); 1268 GNUNET_break(0);
1288 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1269 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
@@ -1450,6 +1431,7 @@ run (void *cls,
1450 if (dht_handle == NULL) { 1431 if (dht_handle == NULL) {
1451 GNUNET_break(0); 1432 GNUNET_break(0);
1452 } 1433 }
1434 next_tid = 0;
1453 1435
1454 /* Scheduled the task to clean up when shutdown is called */ 1436 /* Scheduled the task to clean up when shutdown is called */
1455 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 1437 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,