aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-05-12 17:52:38 +0000
committerBart Polot <bart@net.in.tum.de>2011-05-12 17:52:38 +0000
commit33b69c82ed1aed813b58aa076fbbed72a8e834b4 (patch)
tree02da05f9c65fced198f2050b4a5132fc60dda8f0 /src/mesh
parent2e7ff0e9792503ffb1aab22586b45a362a07f5bd (diff)
downloadgnunet-33b69c82ed1aed813b58aa076fbbed72a8e834b4.tar.gz
gnunet-33b69c82ed1aed813b58aa076fbbed72a8e834b4.zip
Added logging, code formatting, documentation and style changes
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh.c312
-rw-r--r--src/mesh/mesh_api_new.c62
2 files changed, 208 insertions, 166 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index f07465ae2..d3b857c6a 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -57,7 +57,7 @@
57/** 57/**
58 * All the states a peer participating in a tunnel can be in. 58 * All the states a peer participating in a tunnel can be in.
59 */ 59 */
60enum PeerState 60enum MeshPeerState
61{ 61{
62 /** 62 /**
63 * Path to the peer not known yet 63 * Path to the peer not known yet
@@ -83,13 +83,13 @@ enum PeerState
83/** 83/**
84 * Struct containing all information regarding a given peer 84 * Struct containing all information regarding a given peer
85 */ 85 */
86struct PeerInfo 86struct MeshPeerInfo
87{ 87{
88 /** 88 /**
89 * Double linked list 89 * Double linked list
90 */ 90 */
91 struct PeerInfo *next; 91 struct MeshPeerInfo *next;
92 struct PeerInfo *prev; 92 struct MeshPeerInfo *prev;
93 93
94 /** 94 /**
95 * ID of the peer 95 * ID of the peer
@@ -104,7 +104,7 @@ struct PeerInfo
104 /** 104 /**
105 * Is the peer reachable? Is the peer even connected? 105 * Is the peer reachable? Is the peer even connected?
106 */ 106 */
107 enum PeerState state; 107 enum MeshPeerState state;
108 108
109 /** 109 /**
110 * When to try to establish contact again? 110 * When to try to establish contact again?
@@ -134,13 +134,13 @@ typedef uint32_t MESH_PathID;
134/** 134/**
135 * Information regarding a path 135 * Information regarding a path
136 */ 136 */
137struct Path 137struct MeshPath
138{ 138{
139 /** 139 /**
140 * Double linked list 140 * Double linked list
141 */ 141 */
142 struct Path *next; 142 struct MeshPath *next;
143 struct Path *prev; 143 struct MeshPath *prev;
144 144
145 /** 145 /**
146 * Id of the path, in case it's needed 146 * Id of the path, in case it's needed
@@ -162,13 +162,13 @@ struct Path
162/** 162/**
163 * Data scheduled to transmit (to local client or remote peer) 163 * Data scheduled to transmit (to local client or remote peer)
164 */ 164 */
165struct MESH_queue 165struct MeshQueue
166{ 166{
167 /** 167 /**
168 * Double linked list 168 * Double linked list
169 */ 169 */
170 struct MESH_queue *next; 170 struct MeshQueue *next;
171 struct MESH_queue *prev; 171 struct MeshQueue *prev;
172 172
173 /** 173 /**
174 * Size of the message to transmit 174 * Size of the message to transmit
@@ -187,7 +187,7 @@ struct MESH_queue
187}; 187};
188 188
189 189
190struct Client; /* FWD declaration */ 190struct MeshClient; /* FWD declaration */
191/** 191/**
192 * Struct containing all information regarding a tunnel 192 * Struct containing all information regarding a tunnel
193 * For an intermediate node the improtant info used will be: 193 * For an intermediate node the improtant info used will be:
@@ -234,8 +234,8 @@ struct MESH_tunnel
234 /** 234 /**
235 * Peers in the tunnel, for future optimizations 235 * Peers in the tunnel, for future optimizations
236 */ 236 */
237 struct PeerInfo *peers_head; 237 struct MeshPeerInfo *peers_head;
238 struct PeerInfo *peers_tail; 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
@@ -250,38 +250,38 @@ struct MESH_tunnel
250 /** 250 /**
251 * Paths (used and backup) 251 * Paths (used and backup)
252 */ 252 */
253 struct Path *paths_head; 253 struct MeshPath *paths_head;
254 struct Path *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 * If this tunnel was created by a local client, what's its handle?
258 */ 258 */
259 struct Client *client; 259 struct MeshClient *client;
260 260
261 /** 261 /**
262 * Messages ready to transmit 262 * Messages ready to transmit
263 */ 263 */
264 struct MESH_queue *out_head; 264 struct MeshQueue *out_head;
265 struct MESH_queue *out_tail; 265 struct MeshQueue *out_tail;
266 266
267 /** 267 /**
268 * Messages received and not processed 268 * Messages received and not processed
269 */ 269 */
270 struct MESH_queue *in_head; 270 struct MeshQueue *in_head;
271 struct MESH_queue *in_tail; 271 struct MeshQueue *in_tail;
272 272
273}; 273};
274 274
275/** 275/**
276 * Struct containing information about a client of the service 276 * Struct containing information about a client of the service
277 */ 277 */
278struct Client 278struct MeshClient
279{ 279{
280 /** 280 /**
281 * Double linked list 281 * Double linked list
282 */ 282 */
283 struct Client *next; 283 struct MeshClient *next;
284 struct Client *prev; 284 struct MeshClient *prev;
285 285
286 /** 286 /**
287 * Tunnels that belong to this client, for convenience on disconnect 287 * Tunnels that belong to this client, for convenience on disconnect
@@ -309,8 +309,8 @@ struct Client
309/** 309/**
310 * All the clients 310 * All the clients
311 */ 311 */
312static struct Client *clients_head; 312static struct MeshClient *clients_head;
313static struct Client *clients_tail; 313static struct MeshClient *clients_tail;
314 314
315/** 315/**
316 * Tunnels not owned by this node 316 * Tunnels not owned by this node
@@ -342,12 +342,14 @@ static GNUNET_PEER_Id myid;
342 * @param client the client to check 342 * @param client the client to check
343 * @return non-NULL if client exists in the global DLL 343 * @return non-NULL if client exists in the global DLL
344 */ 344 */
345static struct Client * 345static struct MeshClient *
346retrieve_client (struct GNUNET_SERVER_Client *client) { 346retrieve_client (struct GNUNET_SERVER_Client *client)
347 struct Client *c; 347{
348 struct MeshClient *c;
349
348 c = clients_head; 350 c = clients_head;
349 while(NULL != c) { 351 while (NULL != c) {
350 if(c->handle == client) return c; 352 if (c->handle == client) return c;
351 c = c->next; 353 c = c->next;
352 } 354 }
353 return NULL; 355 return NULL;
@@ -360,7 +362,8 @@ retrieve_client (struct GNUNET_SERVER_Client *client) {
360 * @return GNUNET_OK on success 362 * @return GNUNET_OK on success
361 */ 363 */
362static int 364static int
363destroy_path(struct MESH_tunnel *t, struct Path *p) { 365destroy_path(struct MESH_tunnel *t, struct MeshPath *p)
366{
364 GNUNET_PEER_decrement_rcs(p->peers, p->length); 367 GNUNET_PEER_decrement_rcs(p->peers, p->length);
365 GNUNET_free(p->peers); 368 GNUNET_free(p->peers);
366 GNUNET_CONTAINER_DLL_remove(t->paths_head, t->paths_tail, p); 369 GNUNET_CONTAINER_DLL_remove(t->paths_head, t->paths_tail, p);
@@ -375,7 +378,8 @@ destroy_path(struct MESH_tunnel *t, struct Path *p) {
375 * @return GNUNET_OK on success 378 * @return GNUNET_OK on success
376 */ 379 */
377static int 380static int
378destroy_peer_info(struct MESH_tunnel *t, struct PeerInfo *pi) { 381destroy_peer_info(struct MESH_tunnel *t, struct MeshPeerInfo *pi)
382{
379 GNUNET_PEER_change_rc(pi->id, -1); 383 GNUNET_PEER_change_rc(pi->id, -1);
380 GNUNET_CONTAINER_DLL_remove(t->peers_head, t->peers_tail, pi); 384 GNUNET_CONTAINER_DLL_remove(t->peers_head, t->peers_tail, pi);
381 GNUNET_free(pi); 385 GNUNET_free(pi);
@@ -389,15 +393,16 @@ destroy_peer_info(struct MESH_tunnel *t, struct PeerInfo *pi) {
389 * @return GNUNET_OK on success 393 * @return GNUNET_OK on success
390 */ 394 */
391static int 395static int
392destroy_tunnel(struct Client *c, struct MESH_tunnel *t) { 396destroy_tunnel(struct MeshClient *c, struct MESH_tunnel *t)
393 struct PeerInfo *pi; 397{
394 struct Path *path; 398 struct MeshPeerInfo *pi;
399 struct MeshPath *path;
395 400
396 for(pi = t->peers_head; pi != NULL; pi = t->peers_head) { 401 for (pi = t->peers_head; pi != NULL; pi = t->peers_head) {
397 destroy_peer_info(t, pi); 402 destroy_peer_info(t, pi);
398 } 403 }
399 404
400 for(path = t->paths_head; path != NULL; path = t->paths_head) { 405 for (path = t->paths_head; path != NULL; path = t->paths_head) {
401 destroy_path(t, path); 406 destroy_path(t, path);
402 } 407 }
403 408
@@ -422,33 +427,34 @@ destroy_tunnel(struct Client *c, struct MESH_tunnel *t) {
422 * @return number of bytes written to buf 427 * @return number of bytes written to buf
423 */ 428 */
424static size_t 429static size_t
425send_core_create_path_for_peer (void *cls, size_t size, void *buf) { 430send_core_create_path_for_peer (void *cls, size_t size, void *buf)
431{
426 size_t size_needed; 432 size_t size_needed;
427 struct PeerInfo *peer_info; 433 struct MeshPeerInfo *peer_info;
428 struct GNUNET_MESH_ManipulatePath *msg; 434 struct GNUNET_MESH_ManipulatePath *msg;
429 struct Path *p; 435 struct MeshPath *p;
430 struct GNUNET_PeerIdentity peer_id; 436 struct GNUNET_PeerIdentity peer_id;
431 struct GNUNET_PeerIdentity *peer_ptr; 437 struct GNUNET_PeerIdentity *peer_ptr;
432 int i; 438 int i;
433 439
434 if(0 == size && NULL == buf) { 440 if (0 == size && NULL == buf) {
435 // TODO retry? cancel? 441 // TODO retry? cancel?
436 return 0; 442 return 0;
437 } 443 }
438 peer_info = (struct PeerInfo *)cls; 444 peer_info = (struct MeshPeerInfo *)cls;
439 peer_info->dhtget = NULL; 445 peer_info->dhtget = NULL;
440 p = peer_info->t->paths_head; 446 p = peer_info->t->paths_head;
441 while(NULL != p) { 447 while (NULL != p) {
442 if(p->peers[p->length-1] == peer_info->id) { 448 if (p->peers[p->length-1] == peer_info->id) {
443 break; 449 break;
444 } 450 }
445 p = p->next; 451 p = p->next;
446 } 452 }
447 if(p == NULL) return 0; // TODO Notify ERROR Path not found 453 if (p == NULL) return 0; // TODO Notify ERROR Path not found
448 454
449 size_needed = sizeof(struct GNUNET_MESH_ManipulatePath) 455 size_needed = sizeof(struct GNUNET_MESH_ManipulatePath)
450 + p->length * sizeof(struct GNUNET_PeerIdentity); 456 + p->length * sizeof(struct GNUNET_PeerIdentity);
451 if(size < size_needed) { 457 if (size < size_needed) {
452 // TODO retry? cancel? 458 // TODO retry? cancel?
453 return 0; 459 return 0;
454 } 460 }
@@ -459,7 +465,7 @@ send_core_create_path_for_peer (void *cls, size_t size, void *buf) {
459 msg->speed_min = 0; 465 msg->speed_min = 0;
460 466
461 peer_ptr = (struct GNUNET_PeerIdentity *) &msg[1]; 467 peer_ptr = (struct GNUNET_PeerIdentity *) &msg[1];
462 for(i = 0; i < p->length; i++) { 468 for (i = 0; i < p->length; i++) {
463 GNUNET_PEER_resolve(p->peers[i], &peer_id); 469 GNUNET_PEER_resolve(p->peers[i], &peer_id);
464 memcpy(&peer_ptr[i], &peer_id, sizeof(struct GNUNET_PeerIdentity)); 470 memcpy(&peer_ptr[i], &peer_id, sizeof(struct GNUNET_PeerIdentity));
465 } 471 }
@@ -497,6 +503,7 @@ handle_mesh_path_create (void *cls,
497 return GNUNET_OK; 503 return GNUNET_OK;
498} 504}
499 505
506
500/** 507/**
501 * Core handler for mesh network traffic 508 * Core handler for mesh network traffic
502 * 509 *
@@ -514,7 +521,7 @@ handle_mesh_network_traffic (void *cls,
514 const struct GNUNET_TRANSPORT_ATS_Information 521 const struct GNUNET_TRANSPORT_ATS_Information
515 *atsi) 522 *atsi)
516{ 523{
517 if(GNUNET_MESSAGE_TYPE_MESH_DATA_GO == ntohs(message->type)) { 524 if (GNUNET_MESSAGE_TYPE_MESH_DATA_GO == ntohs(message->type)) {
518 /* Retransmit to next in path of tunnel identified by message */ 525 /* Retransmit to next in path of tunnel identified by message */
519 return GNUNET_OK; 526 return GNUNET_OK;
520 } else { /* GNUNET_MESSAGE_TYPE_MESH_DATA_BACK */ 527 } else { /* GNUNET_MESSAGE_TYPE_MESH_DATA_BACK */
@@ -523,6 +530,7 @@ handle_mesh_network_traffic (void *cls,
523 } 530 }
524} 531}
525 532
533
526/** 534/**
527 * Functions to handle messages from core 535 * Functions to handle messages from core
528 */ 536 */
@@ -551,19 +559,20 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
551 * @return number of bytes written to buf 559 * @return number of bytes written to buf
552 */ 560 */
553static size_t 561static size_t
554notify_client_connection_failure (void *cls, size_t size, void *buf) { 562notify_client_connection_failure (void *cls, size_t size, void *buf)
563{
555 int size_needed; 564 int size_needed;
556 struct PeerInfo *peer_info; 565 struct MeshPeerInfo *peer_info;
557 struct GNUNET_MESH_PeerControl *msg; 566 struct GNUNET_MESH_PeerControl *msg;
558 struct GNUNET_PeerIdentity id; 567 struct GNUNET_PeerIdentity id;
559 568
560 if(0 == size && NULL == buf) { 569 if (0 == size && NULL == buf) {
561 // TODO retry? cancel? 570 // TODO retry? cancel?
562 return 0; 571 return 0;
563 } 572 }
564 573
565 size_needed = sizeof(struct GNUNET_MESH_PeerControl); 574 size_needed = sizeof(struct GNUNET_MESH_PeerControl);
566 peer_info = (struct PeerInfo *) cls; 575 peer_info = (struct MeshPeerInfo *) cls;
567 msg = (struct GNUNET_MESH_PeerControl *) buf; 576 msg = (struct GNUNET_MESH_PeerControl *) buf;
568 msg->header.size = htons(sizeof(struct GNUNET_MESH_PeerControl)); 577 msg->header.size = htons(sizeof(struct GNUNET_MESH_PeerControl));
569 msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED); 578 msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED);
@@ -601,15 +610,15 @@ dht_get_response_handler(void *cls,
601 size_t size, 610 size_t size,
602 const void *data) 611 const void *data)
603{ 612{
604 struct PeerInfo *peer_info; 613 struct MeshPeerInfo *peer_info;
605 struct MESH_tunnel *t; 614 struct MESH_tunnel *t;
606 struct Path *p; 615 struct MeshPath *p;
607 int i; 616 int i;
608 617
609 peer_info = (struct PeerInfo *)cls; 618 peer_info = (struct MeshPeerInfo *)cls;
610 t = peer_info->t; 619 t = peer_info->t;
611 620
612 if(NULL == get_path || NULL == put_path) { 621 if (NULL == get_path || NULL == put_path) {
613 // TODO: find ourselves some alternate initial path to the destination 622 // TODO: find ourselves some alternate initial path to the destination
614 GNUNET_SERVER_notify_transmit_ready( 623 GNUNET_SERVER_notify_transmit_ready(
615 t->client->handle, 624 t->client->handle,
@@ -620,17 +629,17 @@ dht_get_response_handler(void *cls,
620 ); 629 );
621 } 630 }
622 631
623 p = GNUNET_malloc(sizeof(struct Path)); 632 p = GNUNET_malloc(sizeof(struct MeshPath));
624 GNUNET_CONTAINER_DLL_insert(t->paths_head, t->paths_tail, p); 633 GNUNET_CONTAINER_DLL_insert(t->paths_head, t->paths_tail, p);
625 for(i = 0; get_path[i] != NULL; i++); 634 for (i = 0; get_path[i] != NULL; i++);
626 for(i--; i >= 0; i--) { 635 for (i--; i >= 0; i--) {
627 p->peers = GNUNET_realloc(p->peers, 636 p->peers = GNUNET_realloc(p->peers,
628 sizeof(GNUNET_PEER_Id) * (p->length + 1)); 637 sizeof(GNUNET_PEER_Id) * (p->length + 1));
629 p->peers[p->length] = GNUNET_PEER_intern(get_path[i]); 638 p->peers[p->length] = GNUNET_PEER_intern(get_path[i]);
630 p->length++; 639 p->length++;
631 } 640 }
632 for(i = 0; put_path[i] != NULL; i++); 641 for (i = 0; put_path[i] != NULL; i++);
633 for(i--; i >= 0; i--) { 642 for (i--; i >= 0; i--) {
634 p->peers = GNUNET_realloc(p->peers, 643 p->peers = GNUNET_realloc(p->peers,
635 sizeof(GNUNET_PEER_Id) * (p->length + 1)); 644 sizeof(GNUNET_PEER_Id) * (p->length + 1));
636 p->peers[p->length] = GNUNET_PEER_intern(put_path[i]); 645 p->peers[p->length] = GNUNET_PEER_intern(put_path[i]);
@@ -653,6 +662,7 @@ dht_get_response_handler(void *cls,
653 return; 662 return;
654} 663}
655 664
665
656/** 666/**
657 * Handler for client disconnection 667 * Handler for client disconnection
658 * 668 *
@@ -663,11 +673,11 @@ dht_get_response_handler(void *cls,
663static void 673static void
664handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) 674handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
665{ 675{
666 struct Client *c, *next; 676 struct MeshClient *c, *next;
667 struct MESH_tunnel *t; 677 struct MESH_tunnel *t;
668 678
669 c = clients_head; 679 c = clients_head;
670 while(NULL != c) { 680 while (NULL != c) {
671 if (c->handle == client) { 681 if (c->handle == client) {
672 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c); 682 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c);
673 while (NULL != (t = c->tunnels_head)) { 683 while (NULL != (t = c->tunnels_head)) {
@@ -684,6 +694,7 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
684 return; 694 return;
685} 695}
686 696
697
687/** 698/**
688 * Handler for new clients 699 * Handler for new clients
689 * 700 *
@@ -696,7 +707,7 @@ handle_local_new_client (void *cls,
696 struct GNUNET_SERVER_Client *client, 707 struct GNUNET_SERVER_Client *client,
697 const struct GNUNET_MessageHeader *message) 708 const struct GNUNET_MessageHeader *message)
698{ 709{
699 struct Client *c; 710 struct MeshClient *c;
700 unsigned int payload_size; 711 unsigned int payload_size;
701 712
702 /* Check data sanity */ 713 /* Check data sanity */
@@ -708,9 +719,9 @@ handle_local_new_client (void *cls,
708 } 719 }
709 720
710 /* Create new client structure */ 721 /* Create new client structure */
711 c = GNUNET_malloc(sizeof(struct Client)); 722 c = GNUNET_malloc(sizeof(struct MeshClient));
712 c->handle = client; 723 c->handle = client;
713 if(payload_size != 0) { 724 if (payload_size != 0) {
714 c->messages_subscribed = GNUNET_malloc(payload_size); 725 c->messages_subscribed = GNUNET_malloc(payload_size);
715 memcpy(c->messages_subscribed, &message[1], payload_size); 726 memcpy(c->messages_subscribed, &message[1], payload_size);
716 } else { 727 } else {
@@ -725,6 +736,7 @@ handle_local_new_client (void *cls,
725 736
726} 737}
727 738
739
728/** 740/**
729 * Handler for requests of new tunnels 741 * Handler for requests of new tunnels
730 * 742 *
@@ -739,17 +751,17 @@ handle_local_tunnel_create (void *cls,
739{ 751{
740 struct GNUNET_MESH_TunnelMessage *tunnel_msg; 752 struct GNUNET_MESH_TunnelMessage *tunnel_msg;
741 struct MESH_tunnel *t; 753 struct MESH_tunnel *t;
742 struct Client *c; 754 struct MeshClient *c;
743 755
744 /* Sanity check for client registration */ 756 /* Sanity check for client registration */
745 if(NULL == (c = retrieve_client(client))) { 757 if (NULL == (c = retrieve_client(client))) {
746 GNUNET_break(0); 758 GNUNET_break(0);
747 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 759 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
748 return; 760 return;
749 } 761 }
750 762
751 /* Message sanity check */ 763 /* Message sanity check */
752 if(sizeof(struct GNUNET_MESH_TunnelMessage) != ntohs(message->size)) { 764 if (sizeof(struct GNUNET_MESH_TunnelMessage) != ntohs(message->size)) {
753 GNUNET_break(0); 765 GNUNET_break(0);
754 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 766 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
755 return; 767 return;
@@ -757,15 +769,15 @@ handle_local_tunnel_create (void *cls,
757 769
758 tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message; 770 tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message;
759 /* Sanity check for tunnel numbering */ 771 /* Sanity check for tunnel numbering */
760 if(0 == (ntohl(tunnel_msg->tunnel_id) & 0x80000000)) { 772 if (0 == (ntohl(tunnel_msg->tunnel_id) & 0x80000000)) {
761 GNUNET_break(0); 773 GNUNET_break(0);
762 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 774 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
763 return; 775 return;
764 } 776 }
765 /* Sanity check for duplicate tunnel IDs */ 777 /* Sanity check for duplicate tunnel IDs */
766 t = c->tunnels_head; 778 t = c->tunnels_head;
767 while(NULL != t) { 779 while (NULL != t) {
768 if(t->tid == ntohl(tunnel_msg->tunnel_id)) { 780 if (t->tid == ntohl(tunnel_msg->tunnel_id)) {
769 GNUNET_break(0); 781 GNUNET_break(0);
770 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 782 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
771 return; 783 return;
@@ -784,6 +796,7 @@ handle_local_tunnel_create (void *cls,
784 return; 796 return;
785} 797}
786 798
799
787/** 800/**
788 * Handler for requests of deleting tunnels 801 * Handler for requests of deleting tunnels
789 * 802 *
@@ -797,18 +810,18 @@ handle_local_tunnel_destroy (void *cls,
797 const struct GNUNET_MessageHeader *message) 810 const struct GNUNET_MessageHeader *message)
798{ 811{
799 struct GNUNET_MESH_TunnelMessage *tunnel_msg; 812 struct GNUNET_MESH_TunnelMessage *tunnel_msg;
800 struct Client *c; 813 struct MeshClient *c;
801 struct MESH_tunnel *t; 814 struct MESH_tunnel *t;
802 MESH_TunnelID tid; 815 MESH_TunnelID tid;
803 816
804 /* Sanity check for client registration */ 817 /* Sanity check for client registration */
805 if(NULL == (c = retrieve_client(client))) { 818 if (NULL == (c = retrieve_client(client))) {
806 GNUNET_break(0); 819 GNUNET_break(0);
807 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 820 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
808 return; 821 return;
809 } 822 }
810 /* Message sanity check */ 823 /* Message sanity check */
811 if(sizeof(struct GNUNET_MESH_TunnelMessage) != ntohs(message->size)) { 824 if (sizeof(struct GNUNET_MESH_TunnelMessage) != ntohs(message->size)) {
812 GNUNET_break(0); 825 GNUNET_break(0);
813 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 826 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
814 return; 827 return;
@@ -818,16 +831,16 @@ handle_local_tunnel_destroy (void *cls,
818 831
819 /* Tunnel exists? */ 832 /* Tunnel exists? */
820 tid = ntohl(tunnel_msg->tunnel_id); 833 tid = ntohl(tunnel_msg->tunnel_id);
821 if(NULL == (t = c->tunnels_head)) { 834 if (NULL == (t = c->tunnels_head)) {
822 GNUNET_break(0); 835 GNUNET_break(0);
823 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 836 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
824 return; 837 return;
825 } 838 }
826 while(NULL != t) { 839 while (NULL != t) {
827 if(t->tid == tid) { 840 if (t->tid == tid) {
828 break; 841 break;
829 } 842 }
830 if(t == c->tunnels_tail) { 843 if (t == c->tunnels_tail) {
831 GNUNET_break(0); 844 GNUNET_break(0);
832 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 845 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
833 return; 846 return;
@@ -841,6 +854,7 @@ handle_local_tunnel_destroy (void *cls,
841 return; 854 return;
842} 855}
843 856
857
844/** 858/**
845 * Handler for connection requests to new peers 859 * Handler for connection requests to new peers
846 * 860 *
@@ -854,16 +868,15 @@ handle_local_connect_add (void *cls,
854 const struct GNUNET_MessageHeader *message) 868 const struct GNUNET_MessageHeader *message)
855{ 869{
856 struct GNUNET_MESH_PeerControl *peer_msg; 870 struct GNUNET_MESH_PeerControl *peer_msg;
857 struct Client *c; 871 struct MeshClient *c;
858 struct MESH_tunnel *t; 872 struct MESH_tunnel *t;
859 MESH_TunnelID tid; 873 MESH_TunnelID tid;
860 struct PeerInfo *peer_info; 874 struct MeshPeerInfo *peer_info;
861
862 GNUNET_HashCode key; 875 GNUNET_HashCode key;
863 876
864 877
865 /* Sanity check for client registration */ 878 /* Sanity check for client registration */
866 if(NULL == (c = retrieve_client(client))) { 879 if (NULL == (c = retrieve_client(client))) {
867 GNUNET_break(0); 880 GNUNET_break(0);
868 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 881 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
869 return; 882 return;
@@ -871,7 +884,7 @@ handle_local_connect_add (void *cls,
871 884
872 peer_msg = (struct GNUNET_MESH_PeerControl *)message; 885 peer_msg = (struct GNUNET_MESH_PeerControl *)message;
873 /* Sanity check for message size */ 886 /* Sanity check for message size */
874 if(sizeof(struct GNUNET_MESH_PeerControl) != ntohs(peer_msg->header.size)) { 887 if (sizeof(struct GNUNET_MESH_PeerControl) != ntohs(peer_msg->header.size)) {
875 GNUNET_break(0); 888 GNUNET_break(0);
876 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 889 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
877 return; 890 return;
@@ -880,27 +893,27 @@ handle_local_connect_add (void *cls,
880 /* Tunnel exists? */ 893 /* Tunnel exists? */
881 tid = ntohl(peer_msg->tunnel_id); 894 tid = ntohl(peer_msg->tunnel_id);
882 t = c->tunnels_head; 895 t = c->tunnels_head;
883 while(NULL != t) { 896 while (NULL != t) {
884 if(t->tid == tid) { 897 if (t->tid == tid) {
885 break; 898 break;
886 } 899 }
887 t = t->next; 900 t = t->next;
888 } 901 }
889 if(NULL == t) { 902 if (NULL == t) {
890 GNUNET_break(0); 903 GNUNET_break(0);
891 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 904 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
892 return; 905 return;
893 } 906 }
894 907
895 /* Does client own tunnel? */ 908 /* Does client own tunnel? */
896 if(t->client->handle != client) { 909 if (t->client->handle != client) {
897 GNUNET_break(0); 910 GNUNET_break(0);
898 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 911 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
899 return; 912 return;
900 } 913 }
901 914
902 /* Ok, add peer to tunnel */ 915 /* Ok, add peer to tunnel */
903 peer_info = (struct PeerInfo *) GNUNET_malloc(sizeof(struct PeerInfo)); 916 peer_info = (struct MeshPeerInfo *) GNUNET_malloc(sizeof(struct MeshPeerInfo));
904 peer_info->id = GNUNET_PEER_intern(&peer_msg->peer); 917 peer_info->id = GNUNET_PEER_intern(&peer_msg->peer);
905 peer_info->state = MESH_PEER_SEARCHING; 918 peer_info->state = MESH_PEER_SEARCHING;
906 peer_info->t = t; 919 peer_info->t = t;
@@ -941,24 +954,24 @@ handle_local_connect_del (void *cls,
941 const struct GNUNET_MessageHeader *message) 954 const struct GNUNET_MessageHeader *message)
942{ 955{
943 struct GNUNET_MESH_PeerControl *peer_msg; 956 struct GNUNET_MESH_PeerControl *peer_msg;
944 struct Client *c; 957 struct MeshClient *c;
945 struct MESH_tunnel *t; 958 struct MESH_tunnel *t;
946 struct Path *p; 959 struct MeshPath *p;
947 struct Path *aux_path; 960 struct MeshPath *aux_path;
948 MESH_TunnelID tid; 961 MESH_TunnelID tid;
949 GNUNET_PEER_Id peer_id; 962 GNUNET_PEER_Id peer_id;
950 struct PeerInfo *peer_info; 963 struct MeshPeerInfo *peer_info;
951 struct PeerInfo *aux_peer_info; 964 struct MeshPeerInfo *aux_peer_info;
952 965
953 /* Sanity check for client registration */ 966 /* Sanity check for client registration */
954 if(NULL == (c = retrieve_client(client))) { 967 if (NULL == (c = retrieve_client(client))) {
955 GNUNET_break(0); 968 GNUNET_break(0);
956 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 969 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
957 return; 970 return;
958 } 971 }
959 peer_msg = (struct GNUNET_MESH_PeerControl *)message; 972 peer_msg = (struct GNUNET_MESH_PeerControl *)message;
960 /* Sanity check for message size */ 973 /* Sanity check for message size */
961 if(sizeof(struct GNUNET_MESH_PeerControl) != ntohs(peer_msg->header.size)) { 974 if (sizeof(struct GNUNET_MESH_PeerControl) != ntohs(peer_msg->header.size)) {
962 GNUNET_break(0); 975 GNUNET_break(0);
963 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 976 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
964 return; 977 return;
@@ -966,30 +979,30 @@ handle_local_connect_del (void *cls,
966 979
967 /* Tunnel exists? */ 980 /* Tunnel exists? */
968 tid = ntohl(peer_msg->tunnel_id); 981 tid = ntohl(peer_msg->tunnel_id);
969 if(NULL == (t = c->tunnels_head)) { 982 if (NULL == (t = c->tunnels_head)) {
970 GNUNET_break(0); 983 GNUNET_break(0);
971 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 984 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
972 return; 985 return;
973 } 986 }
974 while(NULL != t) { 987 while (NULL != t) {
975 if(t->tid == tid) { 988 if (t->tid == tid) {
976 break; 989 break;
977 } 990 }
978 if(t == c->tunnels_tail) { 991 if (t == c->tunnels_tail) {
979 GNUNET_break(0); 992 GNUNET_break(0);
980 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 993 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
981 return; 994 return;
982 } 995 }
983 t = t->next; 996 t = t->next;
984 } 997 }
985 if(NULL == t) { 998 if (NULL == t) {
986 GNUNET_break(0); 999 GNUNET_break(0);
987 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1000 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
988 return; 1001 return;
989 } 1002 }
990 1003
991 /* Does client own tunnel? */ 1004 /* Does client own tunnel? */
992 if(t->client->handle != client) { 1005 if (t->client->handle != client) {
993 GNUNET_break(0); 1006 GNUNET_break(0);
994 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1007 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
995 return; 1008 return;
@@ -1000,8 +1013,8 @@ handle_local_connect_del (void *cls,
1000 1013
1001 /* Delete paths */ 1014 /* Delete paths */
1002 p = t->paths_head; 1015 p = t->paths_head;
1003 while(p != NULL) { 1016 while (p != NULL) {
1004 if(p->peers[p->length-1] == peer_id) { /* one path per destination */ 1017 if (p->peers[p->length-1] == peer_id) { /* one path per destination */
1005 GNUNET_CONTAINER_DLL_remove(t->paths_head, t->paths_tail, p); 1018 GNUNET_CONTAINER_DLL_remove(t->paths_head, t->paths_tail, p);
1006 GNUNET_PEER_decrement_rcs(p->peers, p->length); 1019 GNUNET_PEER_decrement_rcs(p->peers, p->length);
1007 aux_path = p; 1020 aux_path = p;
@@ -1014,8 +1027,8 @@ handle_local_connect_del (void *cls,
1014 1027
1015 /*Delete peer info */ 1028 /*Delete peer info */
1016 peer_info = t->peers_head; 1029 peer_info = t->peers_head;
1017 while(peer_info != NULL) { 1030 while (peer_info != NULL) {
1018 if(peer_info->id == peer_id) { 1031 if (peer_info->id == peer_id) {
1019 GNUNET_CONTAINER_DLL_remove(t->peers_head, 1032 GNUNET_CONTAINER_DLL_remove(t->peers_head,
1020 t->peers_tail, 1033 t->peers_tail,
1021 peer_info); 1034 peer_info);
@@ -1049,11 +1062,11 @@ handle_local_connect_by_type (void *cls,
1049 struct GNUNET_MESH_ConnectPeerByType *connect_msg; 1062 struct GNUNET_MESH_ConnectPeerByType *connect_msg;
1050 MESH_TunnelID tid; 1063 MESH_TunnelID tid;
1051 GNUNET_MESH_ApplicationType application; 1064 GNUNET_MESH_ApplicationType application;
1052 struct Client *c; 1065 struct MeshClient *c;
1053 struct MESH_tunnel *t; 1066 struct MESH_tunnel *t;
1054 1067
1055 /* Sanity check for client registration */ 1068 /* Sanity check for client registration */
1056 if(NULL == (c = retrieve_client(client))) { 1069 if (NULL == (c = retrieve_client(client))) {
1057 GNUNET_break(0); 1070 GNUNET_break(0);
1058 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1071 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
1059 return; 1072 return;
@@ -1061,7 +1074,9 @@ handle_local_connect_by_type (void *cls,
1061 1074
1062 connect_msg = (struct GNUNET_MESH_ConnectPeerByType *)message; 1075 connect_msg = (struct GNUNET_MESH_ConnectPeerByType *)message;
1063 /* Sanity check for message size */ 1076 /* Sanity check for message size */
1064 if(sizeof(struct GNUNET_MESH_PeerControl) != ntohs(connect_msg->header.size)) { 1077 if (sizeof(struct GNUNET_MESH_PeerControl) !=
1078 ntohs(connect_msg->header.size))
1079 {
1065 GNUNET_break(0); 1080 GNUNET_break(0);
1066 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1081 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
1067 return; 1082 return;
@@ -1070,20 +1085,20 @@ handle_local_connect_by_type (void *cls,
1070 /* Tunnel exists? */ 1085 /* Tunnel exists? */
1071 tid = ntohl(connect_msg->tunnel_id); 1086 tid = ntohl(connect_msg->tunnel_id);
1072 t = c->tunnels_head; 1087 t = c->tunnels_head;
1073 while(NULL != t) { 1088 while (NULL != t) {
1074 if(t->tid == tid) { 1089 if (t->tid == tid) {
1075 break; 1090 break;
1076 } 1091 }
1077 t = t->next; 1092 t = t->next;
1078 } 1093 }
1079 if(NULL == t) { 1094 if (NULL == t) {
1080 GNUNET_break(0); 1095 GNUNET_break(0);
1081 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1096 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
1082 return; 1097 return;
1083 } 1098 }
1084 1099
1085 /* Does client own tunnel? */ 1100 /* Does client own tunnel? */
1086 if(t->client->handle != client) { 1101 if (t->client->handle != client) {
1087 GNUNET_break(0); 1102 GNUNET_break(0);
1088 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1103 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
1089 return; 1104 return;
@@ -1110,20 +1125,22 @@ handle_local_network_traffic (void *cls,
1110 struct GNUNET_SERVER_Client *client, 1125 struct GNUNET_SERVER_Client *client,
1111 const struct GNUNET_MessageHeader *message) 1126 const struct GNUNET_MessageHeader *message)
1112{ 1127{
1113 struct Client *c; 1128 struct MeshClient *c;
1114 struct MESH_tunnel *t; 1129 struct MESH_tunnel *t;
1115 struct GNUNET_MESH_Data *data_msg; 1130 struct GNUNET_MESH_Data *data_msg;
1116 MESH_TunnelID tid; 1131 MESH_TunnelID tid;
1117 1132
1118 /* Sanity check for client registration */ 1133 /* Sanity check for client registration */
1119 if(NULL == (c = retrieve_client(client))) { 1134 if (NULL == (c = retrieve_client(client))) {
1120 GNUNET_break(0); 1135 GNUNET_break(0);
1121 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1136 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
1122 return; 1137 return;
1123 } 1138 }
1124 data_msg = (struct GNUNET_MESH_Data *)message; 1139 data_msg = (struct GNUNET_MESH_Data *)message;
1125 /* Sanity check for message size */ 1140 /* Sanity check for message size */
1126 if(sizeof(struct GNUNET_MESH_PeerControl) != ntohs(data_msg->header.size)) { 1141 if (sizeof(struct GNUNET_MESH_PeerControl) !=
1142 ntohs(data_msg->header.size))
1143 {
1127 GNUNET_break(0); 1144 GNUNET_break(0);
1128 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1145 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
1129 return; 1146 return;
@@ -1132,20 +1149,20 @@ handle_local_network_traffic (void *cls,
1132 /* Tunnel exists? */ 1149 /* Tunnel exists? */
1133 tid = ntohl(data_msg->tunnel_id); 1150 tid = ntohl(data_msg->tunnel_id);
1134 t = c->tunnels_head; 1151 t = c->tunnels_head;
1135 while(NULL != t) { 1152 while (NULL != t) {
1136 if(t->tid == tid) { 1153 if (t->tid == tid) {
1137 break; 1154 break;
1138 } 1155 }
1139 t = t->next; 1156 t = t->next;
1140 } 1157 }
1141 if(NULL == t) { 1158 if (NULL == t) {
1142 GNUNET_break(0); 1159 GNUNET_break(0);
1143 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1160 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
1144 return; 1161 return;
1145 } 1162 }
1146 1163
1147 /* Does client own tunnel? */ 1164 /* Does client own tunnel? */
1148 if(t->client->handle != client) { 1165 if (t->client->handle != client) {
1149 GNUNET_break(0); 1166 GNUNET_break(0);
1150 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1167 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
1151 return; 1168 return;
@@ -1169,20 +1186,20 @@ handle_local_network_traffic_bcast (void *cls,
1169 struct GNUNET_SERVER_Client *client, 1186 struct GNUNET_SERVER_Client *client,
1170 const struct GNUNET_MessageHeader *message) 1187 const struct GNUNET_MessageHeader *message)
1171{ 1188{
1172 struct Client *c; 1189 struct MeshClient *c;
1173 struct MESH_tunnel *t; 1190 struct MESH_tunnel *t;
1174 struct GNUNET_MESH_DataBroadcast *data_msg; 1191 struct GNUNET_MESH_DataBroadcast *data_msg;
1175 MESH_TunnelID tid; 1192 MESH_TunnelID tid;
1176 1193
1177 /* Sanity check for client registration */ 1194 /* Sanity check for client registration */
1178 if(NULL == (c = retrieve_client(client))) { 1195 if (NULL == (c = retrieve_client(client))) {
1179 GNUNET_break(0); 1196 GNUNET_break(0);
1180 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1197 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
1181 return; 1198 return;
1182 } 1199 }
1183 data_msg = (struct GNUNET_MESH_DataBroadcast *)message; 1200 data_msg = (struct GNUNET_MESH_DataBroadcast *)message;
1184 /* Sanity check for message size */ 1201 /* Sanity check for message size */
1185 if(sizeof(struct GNUNET_MESH_PeerControl) != ntohs(data_msg->header.size)) { 1202 if (sizeof(struct GNUNET_MESH_PeerControl) != ntohs(data_msg->header.size)) {
1186 GNUNET_break(0); 1203 GNUNET_break(0);
1187 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1204 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
1188 return; 1205 return;
@@ -1191,20 +1208,20 @@ handle_local_network_traffic_bcast (void *cls,
1191 /* Tunnel exists? */ 1208 /* Tunnel exists? */
1192 tid = ntohl(data_msg->tunnel_id); 1209 tid = ntohl(data_msg->tunnel_id);
1193 t = c->tunnels_head; 1210 t = c->tunnels_head;
1194 while(NULL != t) { 1211 while (NULL != t) {
1195 if(t->tid == tid) { 1212 if (t->tid == tid) {
1196 break; 1213 break;
1197 } 1214 }
1198 t = t->next; 1215 t = t->next;
1199 } 1216 }
1200 if(NULL == t) { 1217 if (NULL == t) {
1201 GNUNET_break(0); 1218 GNUNET_break(0);
1202 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1219 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
1203 return; 1220 return;
1204 } 1221 }
1205 1222
1206 /* Does client own tunnel? */ 1223 /* Does client own tunnel? */
1207 if(t->client->handle != client) { 1224 if (t->client->handle != client) {
1208 GNUNET_break(0); 1225 GNUNET_break(0);
1209 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1226 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
1210 return; 1227 return;
@@ -1258,6 +1275,8 @@ core_init (void *cls,
1258 const struct GNUNET_PeerIdentity *identity, 1275 const struct GNUNET_PeerIdentity *identity,
1259 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 1276 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
1260{ 1277{
1278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1279 "Core init\n");
1261 core_handle = server; 1280 core_handle = server;
1262 myid = GNUNET_PEER_intern(identity); 1281 myid = GNUNET_PEER_intern(identity);
1263 return; 1282 return;
@@ -1275,6 +1294,14 @@ core_connect (void *cls,
1275 const struct GNUNET_PeerIdentity *peer, 1294 const struct GNUNET_PeerIdentity *peer,
1276 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 1295 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1277{ 1296{
1297 GNUNET_PEER_Id pid;
1298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1299 "Peer connected\n");
1300 pid = GNUNET_PEER_intern(peer);
1301 if (myid == pid) {
1302 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1303 " (self)\n");
1304 }
1278 return; 1305 return;
1279} 1306}
1280 1307
@@ -1289,6 +1316,8 @@ core_disconnect (void *cls,
1289 const struct 1316 const struct
1290 GNUNET_PeerIdentity *peer) 1317 GNUNET_PeerIdentity *peer)
1291{ 1318{
1319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1320 "Peer disconnected\n");
1292 return; 1321 return;
1293} 1322}
1294 1323
@@ -1305,15 +1334,15 @@ core_disconnect (void *cls,
1305static void 1334static void
1306shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 1335shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1307{ 1336{
1308 if (core_handle != NULL) 1337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1309 { 1338 "MESH shutting down\n");
1310 GNUNET_CORE_disconnect (core_handle); 1339 if (core_handle != NULL) {
1311 core_handle = NULL; 1340 GNUNET_CORE_disconnect (core_handle);
1341 core_handle = NULL;
1312 } 1342 }
1313 if (dht_handle != NULL) 1343 if (dht_handle != NULL) {
1314 { 1344 GNUNET_DHT_disconnect (dht_handle);
1315 GNUNET_DHT_disconnect (dht_handle); 1345 dht_handle = NULL;
1316 dht_handle = NULL;
1317 } 1346 }
1318} 1347}
1319 1348
@@ -1329,7 +1358,8 @@ run (void *cls,
1329 struct GNUNET_SERVER_Handle *server, 1358 struct GNUNET_SERVER_Handle *server,
1330 const struct GNUNET_CONFIGURATION_Handle *c) 1359 const struct GNUNET_CONFIGURATION_Handle *c)
1331{ 1360{
1332GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "******* MESH DEBUG MESSAGE 3 ********\n"); 1361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1362 "MESH starting to run\n");
1333 GNUNET_SERVER_add_handlers (server, plugin_handlers); 1363 GNUNET_SERVER_add_handlers (server, plugin_handlers);
1334 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); 1364 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
1335 core_handle = GNUNET_CORE_connect (c, /* Main configuration */ 1365 core_handle = GNUNET_CORE_connect (c, /* Main configuration */
@@ -1344,7 +1374,6 @@ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "******* MESH DEBUG MESSAGE 3 ********\n");
1344 NULL, /* Don't notify about all outbound messages */ 1374 NULL, /* Don't notify about all outbound messages */
1345 GNUNET_NO, /* For header-only out notification */ 1375 GNUNET_NO, /* For header-only out notification */
1346 core_handlers); /* Register these handlers */ 1376 core_handlers); /* Register these handlers */
1347GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "******* MESH DEBUG MESSAGE 4 ********\n");
1348 if (core_handle == NULL) { 1377 if (core_handle == NULL) {
1349 GNUNET_break(0); 1378 GNUNET_break(0);
1350 } 1379 }
@@ -1353,9 +1382,9 @@ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "******* MESH DEBUG MESSAGE 4 ********\n");
1353 GNUNET_break(0); 1382 GNUNET_break(0);
1354 } 1383 }
1355 1384
1356 /* Scheduled the task to clean up when shutdown is called */ 1385 /* Scheduled the task to clean up when shutdown is called */
1357 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 1386 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
1358 &shutdown_task, NULL); 1387 &shutdown_task, NULL);
1359 1388
1360} 1389}
1361 1390
@@ -1370,13 +1399,12 @@ int
1370main (int argc, char *const *argv) 1399main (int argc, char *const *argv)
1371{ 1400{
1372 int ret; 1401 int ret;
1373GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "******* MESH DEBUG MESSAGE 1 ********\n"); 1402
1374 ret = (GNUNET_OK == 1403 ret = (GNUNET_OK ==
1375 GNUNET_SERVICE_run (argc, 1404 GNUNET_SERVICE_run (argc,
1376 argv, 1405 argv,
1377 "mesh", 1406 "mesh",
1378 GNUNET_SERVICE_OPTION_NONE, 1407 GNUNET_SERVICE_OPTION_NONE,
1379 &run, NULL)) ? 0 : 1; 1408 &run, NULL)) ? 0 : 1;
1380GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "******* MESH DEBUG MESSAGE 2 ********\n");
1381 return ret; 1409 return ret;
1382} 1410}
diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c
index 989b526ae..11376681a 100644
--- a/src/mesh/mesh_api_new.c
+++ b/src/mesh/mesh_api_new.c
@@ -48,7 +48,7 @@ struct GNUNET_MESH_Handle {
48 /** 48 /**
49 * Handle to the server connection, to send messages later 49 * Handle to the server connection, to send messages later
50 */ 50 */
51 struct GNUNET_CLIENT_Connection *mesh; 51 struct GNUNET_CLIENT_Connection *client;
52 52
53 /** 53 /**
54 * Set of handlers used for processing incoming messages in the tunnels 54 * Set of handlers used for processing incoming messages in the tunnels
@@ -76,8 +76,10 @@ struct GNUNET_MESH_Handle {
76 */ 76 */
77 GNUNET_MESH_TunnelEndHandler *cleaner; 77 GNUNET_MESH_TunnelEndHandler *cleaner;
78 78
79 79 /**
80 struct GNUNET_CLIENT_TransmitHandle *th; 80 * Handle to cancel pending transmissions in case of disconnection
81 */
82 struct GNUNET_CLIENT_TransmitHandle *th;
81 83
82 /** 84 /**
83 * Closure for all the handlers given by the client 85 * Closure for all the handlers given by the client
@@ -141,16 +143,20 @@ send_connect_packet (void *cls, size_t size, void *buf) {
141 143
142 h->th = NULL; 144 h->th = NULL;
143 if (0 == size || buf == NULL) { 145 if (0 == size || buf == NULL) {
144 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Send: buffer size 0 or buffer invalid\n"); 146 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
147 "Send: buffer size 0 or buffer invalid\n");
145 // FIXME: disconnect, reconnect, retry! 148 // FIXME: disconnect, reconnect, retry!
146 return 0; 149 return 0;
147 } 150 }
148 if (sizeof(struct GNUNET_MessageHeader) > size) { 151 if (sizeof(struct GNUNET_MessageHeader) > size) {
149 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Send: buffer size too small\n"); 152 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
153 "Send: buffer size too small\n");
150 // FIXME: disconnect, reconnect, retry! 154 // FIXME: disconnect, reconnect, retry!
151 return 0; 155 return 0;
152 } 156 }
153 157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
158 "Sending into %lu bytes buffer\n",
159 size);
154 msg = (struct GNUNET_MESH_ClientConnect *) buf; 160 msg = (struct GNUNET_MESH_ClientConnect *) buf;
155 msg->header.type = GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT; 161 msg->header.type = GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT;
156 162
@@ -182,6 +188,7 @@ send_connect_packet (void *cls, size_t size, void *buf) {
182 return msg->header.size; 188 return msg->header.size;
183} 189}
184 190
191
185/** 192/**
186 * Type of a function to call when we receive a message 193 * Type of a function to call when we receive a message
187 * from the service. 194 * from the service.
@@ -189,9 +196,9 @@ send_connect_packet (void *cls, size_t size, void *buf) {
189 * @param cls closure 196 * @param cls closure
190 * @param msg message received, NULL on timeout or fatal error 197 * @param msg message received, NULL on timeout or fatal error
191 */ 198 */
192void msg_received (void *cls, 199void
193 const struct 200msg_received (void *cls, const struct GNUNET_MessageHeader * msg)
194 GNUNET_MessageHeader * msg) { 201{
195 uint16_t t; 202 uint16_t t;
196 if(msg != NULL){ 203 if(msg != NULL){
197 t = ntohs(msg->type); 204 t = ntohs(msg->type);
@@ -204,6 +211,7 @@ void msg_received (void *cls,
204 return; 211 return;
205} 212}
206 213
214
207/** 215/**
208 * Connect to the mesh service. 216 * Connect to the mesh service.
209 * 217 *
@@ -232,12 +240,12 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
232 h = GNUNET_malloc(sizeof(struct GNUNET_MESH_Handle)); 240 h = GNUNET_malloc(sizeof(struct GNUNET_MESH_Handle));
233 241
234 h->cleaner = cleaner; 242 h->cleaner = cleaner;
235 h->mesh = GNUNET_CLIENT_connect("mesh", cfg); 243 h->client = GNUNET_CLIENT_connect("mesh", cfg);
236 GNUNET_CLIENT_receive (h->mesh, 244 GNUNET_CLIENT_receive (h->client,
237 &msg_received, 245 &msg_received,
238 h, 246 h,
239 GNUNET_TIME_UNIT_FOREVER_REL); 247 GNUNET_TIME_UNIT_FOREVER_REL);
240 if(h->mesh == NULL) { 248 if(h->client == NULL) {
241 GNUNET_free(h); 249 GNUNET_free(h);
242 return NULL; 250 return NULL;
243 } 251 }
@@ -253,7 +261,7 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
253 size += h->n_handlers * sizeof(uint16_t); 261 size += h->n_handlers * sizeof(uint16_t);
254 size += h->n_applications * sizeof(GNUNET_MESH_ApplicationType); 262 size += h->n_applications * sizeof(GNUNET_MESH_ApplicationType);
255 263
256 h->th = GNUNET_CLIENT_notify_transmit_ready(h->mesh, 264 h->th = GNUNET_CLIENT_notify_transmit_ready(h->client,
257 size, 265 size,
258 GNUNET_TIME_UNIT_FOREVER_REL, 266 GNUNET_TIME_UNIT_FOREVER_REL,
259 GNUNET_YES, 267 GNUNET_YES,
@@ -272,11 +280,13 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
272void 280void
273GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) 281GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
274{ 282{
275 if (NULL != handle->th) 283 if (NULL != handle->th) {
276 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th); 284 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
277 if (NULL != handle->mesh) 285 }
278 GNUNET_CLIENT_disconnect (handle->mesh, GNUNET_NO); 286 if (NULL != handle->client) {
279 GNUNET_free(handle); 287 GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
288 }
289 GNUNET_free(handle);
280} 290}
281 291
282 292
@@ -295,14 +305,14 @@ GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h,
295 connect_handler, 305 connect_handler,
296 GNUNET_MESH_TunnelDisconnectHandler 306 GNUNET_MESH_TunnelDisconnectHandler
297 disconnect_handler, 307 disconnect_handler,
298 void *handler_cls) { 308 void *handler_cls)
309{
299 struct GNUNET_MESH_Tunnel *tunnel; 310 struct GNUNET_MESH_Tunnel *tunnel;
300 311
301 tunnel = GNUNET_malloc(sizeof(struct GNUNET_MESH_Tunnel)); 312 tunnel = GNUNET_malloc(sizeof(struct GNUNET_MESH_Tunnel));
302 313
303 tunnel->connect_handler = connect_handler; 314 tunnel->connect_handler = connect_handler;
304 tunnel->disconnect_handler = disconnect_handler; 315 tunnel->disconnect_handler = disconnect_handler;
305 tunnel->peers = NULL;
306 tunnel->cls = handler_cls; 316 tunnel->cls = handler_cls;
307 317
308 return tunnel; 318 return tunnel;
@@ -320,7 +330,8 @@ GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h,
320void 330void
321GNUNET_MESH_peer_request_connect_add (struct GNUNET_MESH_Tunnel *tunnel, 331GNUNET_MESH_peer_request_connect_add (struct GNUNET_MESH_Tunnel *tunnel,
322 struct GNUNET_TIME_Relative timeout, 332 struct GNUNET_TIME_Relative timeout,
323 const struct GNUNET_PeerIdentity *peer) { 333 const struct GNUNET_PeerIdentity *peer)
334{
324 static GNUNET_PEER_Id peer_id; 335 static GNUNET_PEER_Id peer_id;
325 336
326 peer_id = GNUNET_PEER_intern(peer); 337 peer_id = GNUNET_PEER_intern(peer);
@@ -341,7 +352,8 @@ GNUNET_MESH_peer_request_connect_add (struct GNUNET_MESH_Tunnel *tunnel,
341 */ 352 */
342void 353void
343GNUNET_MESH_peer_request_connect_del (struct GNUNET_MESH_Tunnel *tunnel, 354GNUNET_MESH_peer_request_connect_del (struct GNUNET_MESH_Tunnel *tunnel,
344 const struct GNUNET_PeerIdentity *peer) { 355 const struct GNUNET_PeerIdentity *peer)
356{
345 /* FIXME ACTUALLY DO STUFF */ 357 /* FIXME ACTUALLY DO STUFF */
346 tunnel->peers = NULL; 358 tunnel->peers = NULL;
347 tunnel->disconnect_handler(tunnel->cls, peer); 359 tunnel->disconnect_handler(tunnel->cls, peer);
@@ -362,7 +374,8 @@ void
362GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Tunnel *tunnel, 374GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Tunnel *tunnel,
363 struct GNUNET_TIME_Relative timeout, 375 struct GNUNET_TIME_Relative timeout,
364 GNUNET_MESH_ApplicationType 376 GNUNET_MESH_ApplicationType
365 app_type) { 377 app_type)
378{
366 return; 379 return;
367} 380}
368 381
@@ -398,7 +411,8 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel,
398 size_t notify_size, 411 size_t notify_size,
399 GNUNET_CONNECTION_TransmitReadyNotify 412 GNUNET_CONNECTION_TransmitReadyNotify
400 notify, 413 notify,
401 void *notify_cls) { 414 void *notify_cls)
415{
402 struct GNUNET_MESH_TransmitHandle *handle; 416 struct GNUNET_MESH_TransmitHandle *handle;
403 417
404 handle = GNUNET_malloc(sizeof(struct GNUNET_MESH_TransmitHandle)); 418 handle = GNUNET_malloc(sizeof(struct GNUNET_MESH_TransmitHandle));