aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-04-19 11:42:21 +0000
committerBart Polot <bart@net.in.tum.de>2011-04-19 11:42:21 +0000
commitb3c4c13375bd560114ab26016f92f9cbf8e6b814 (patch)
treec4d8798f1a6016033acc4e683f595da65b7c811b /src/mesh
parent10e27ef7411f47f290887a9cfe040cc171d1dff3 (diff)
downloadgnunet-b3c4c13375bd560114ab26016f92f9cbf8e6b814.tar.gz
gnunet-b3c4c13375bd560114ab26016f92f9cbf8e6b814.zip
WiP
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh.c80
1 files changed, 41 insertions, 39 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 760545021..b60b54279 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -308,12 +308,12 @@ struct MESH_queue
308 * Size of the message to transmit 308 * Size of the message to transmit
309 */ 309 */
310 unsigned int size; 310 unsigned int size;
311 311
312 /** 312 /**
313 * How old is the data? 313 * How old is the data?
314 */ 314 */
315 struct GNUNET_TIME_Absolute timestamp; 315 struct GNUNET_TIME_Absolute timestamp;
316 316
317 /** 317 /**
318 * Data itself 318 * Data itself
319 */ 319 */
@@ -447,18 +447,6 @@ static struct Client *clients_head;
447static struct Client *clients_tail; 447static struct Client *clients_tail;
448 448
449/** 449/**
450 * All the tunnels
451 */
452static struct MESH_tunnel *tunnels_head;
453static struct MESH_tunnel *tunnels_tail;
454
455/**
456 * All the paths (for future path optimization)
457 */
458// static struct Path *paths_head;
459// static struct Path *paths_tail;
460
461/**
462 * Handle to communicate with core 450 * Handle to communicate with core
463 */ 451 */
464static struct GNUNET_CORE_Handle *core_handle; 452static struct GNUNET_CORE_Handle *core_handle;
@@ -554,8 +542,13 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
554struct Client * 542struct Client *
555client_retrieve (struct GNUNET_SERVER_Client *client) { 543client_retrieve (struct GNUNET_SERVER_Client *client) {
556 struct Client *c; 544 struct Client *c;
557 for (c = clients_head; c != clients_head; c = c->next) { 545 c = clients_head;
546 while(NULL != c) {
558 if(c->handle == client) return c; 547 if(c->handle == client) return c;
548 if(c == clients_tail)
549 return NULL;
550 else
551 c = c->next;
559 } 552 }
560 return NULL; 553 return NULL;
561} 554}
@@ -578,23 +571,24 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
578 * and disconnects? Does the service get a disconnect notification anyway? 571 * and disconnects? Does the service get a disconnect notification anyway?
579 */ 572 */
580 GNUNET_assert(NULL != clients_head); 573 GNUNET_assert(NULL != clients_head);
581 for (c = clients_head; c != clients_head; c = next) { 574 c = clients_head;
575 while(NULL != c) {
582 if (c->handle == client) { 576 if (c->handle == client) {
583 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c); 577 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c);
584 while (NULL != (t = c->tunnels_head)) { 578 while (NULL != (t = c->tunnels_head)) {
585 GNUNET_CONTAINER_DLL_remove (c->tunnels_head, c->tunnels_tail, t); 579 GNUNET_CONTAINER_DLL_remove (c->tunnels_head, c->tunnels_tail, t);
586 GNUNET_CONTAINER_DLL_remove (tunnels_head, tunnels_tail, t);
587 /* TODO free paths and other tunnel dynamic structures */ 580 /* TODO free paths and other tunnel dynamic structures */
588 GNUNET_free (t); 581 GNUNET_free (t);
589 } 582 }
590 GNUNET_free (c->messages_subscribed); 583 GNUNET_free (c->messages_subscribed);
591 next = c->next; 584 next = c->next;
592 GNUNET_free (c); 585 GNUNET_free (c);
586 c = next;
593 } else { 587 } else {
594 next = c->next; 588 c = c->next;
595 } 589 }
590 if(c == clients_head) return; /* Tail already processed? */
596 } 591 }
597
598 return; 592 return;
599} 593}
600 594
@@ -678,12 +672,15 @@ handle_local_tunnel_create (void *cls,
678 return; 672 return;
679 } 673 }
680 /* Sanity check for duplicate tunnel IDs */ 674 /* Sanity check for duplicate tunnel IDs */
681 for (t = tunnels_head; t != tunnels_head; t = t->next) { 675 t = c->tunnels_head;
676 while(NULL != t) {
682 if(t->tid == ntohl(tunnel_msg->tunnel_id)) { 677 if(t->tid == ntohl(tunnel_msg->tunnel_id)) {
683 GNUNET_break(0); 678 GNUNET_break(0);
684 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 679 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
685 return; 680 return;
686 } 681 }
682 if(t == c->tunnels_tail) break;
683 t = t->next;
687 } 684 }
688 /* FIXME: calloc? Is NULL != 0 on any platform? */ 685 /* FIXME: calloc? Is NULL != 0 on any platform? */
689 t = GNUNET_malloc(sizeof(struct MESH_tunnel)); 686 t = GNUNET_malloc(sizeof(struct MESH_tunnel));
@@ -701,7 +698,6 @@ handle_local_tunnel_create (void *cls,
701 t->out_tail = NULL; 698 t->out_tail = NULL;
702 t->client = c; 699 t->client = c;
703 700
704 GNUNET_CONTAINER_DLL_insert(tunnels_head, tunnels_tail, t);
705 GNUNET_CONTAINER_DLL_insert(c->tunnels_head, c->tunnels_tail, t); 701 GNUNET_CONTAINER_DLL_insert(c->tunnels_head, c->tunnels_tail, t);
706 702
707 GNUNET_SERVER_receive_done(client, GNUNET_OK); 703 GNUNET_SERVER_receive_done(client, GNUNET_OK);
@@ -739,24 +735,30 @@ handle_local_tunnel_destroy (void *cls,
739 return; 735 return;
740 } 736 }
741 737
742 /* Tunnel exists? */
743 tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message; 738 tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message;
739
740 /* Tunnel exists? */
744 tid = ntohl(tunnel_msg->tunnel_id); 741 tid = ntohl(tunnel_msg->tunnel_id);
745 for (t = tunnels_head; t != tunnels_head; t = t->next) { 742 if(NULL == (t = c->tunnels_head)) {
746 if(t->tid == tid) {
747 break;
748 }
749 }
750 if(t->tid != tid) {
751 GNUNET_break(0); 743 GNUNET_break(0);
752 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 744 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
753 return; 745 return;
754 } 746 }
747 while(NULL != t) {
748 if(t->tid == tid) {
749 break;
750 }
751 if(t == c->tunnels_tail) {
752 GNUNET_break(0);
753 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
754 return;
755 }
756 t = t->next;
757 }
755 758
756 GNUNET_CONTAINER_DLL_remove(tunnels_head, tunnels_tail, t);
757 GNUNET_CONTAINER_DLL_remove(c->tunnels_head, c->tunnels_tail, t); 759 GNUNET_CONTAINER_DLL_remove(c->tunnels_head, c->tunnels_tail, t);
758 760
759 for(pi = t->peers_head; pi != t->peers_tail; pi = t->peers_head) { 761 for(pi = t->peers_head; pi != NULL; pi = t->peers_head) {
760 GNUNET_PEER_change_rc(pi->id, -1); 762 GNUNET_PEER_change_rc(pi->id, -1);
761 GNUNET_CONTAINER_DLL_remove(t->peers_head, t->peers_tail, pi); 763 GNUNET_CONTAINER_DLL_remove(t->peers_head, t->peers_tail, pi);
762 GNUNET_free(pi); 764 GNUNET_free(pi);
@@ -801,23 +803,23 @@ handle_local_connect_add (void *cls,
801 return; 803 return;
802 } 804 }
803 805
804 /* Does tunnel exist? */ 806 /* Tunnel exists? */
805 tid = ntohl(peer_msg->tunnel_id); 807 tid = ntohl(peer_msg->tunnel_id);
806 for(t = c->tunnels_head; t != c->tunnels_head; t = t->next) { 808 if(NULL == (t = c->tunnels_head)) {
807 if(t->tid == tid) {
808 break;
809 }
810 }
811 if(NULL == t) {
812 GNUNET_break(0); 809 GNUNET_break(0);
813 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 810 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
814 return; 811 return;
815 } else { 812 }
816 if(t->tid != tid) { 813 while(NULL != t) {
814 if(t->tid == tid) {
815 break;
816 }
817 if(t == c->tunnels_tail) {
817 GNUNET_break(0); 818 GNUNET_break(0);
818 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 819 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
819 return; 820 return;
820 } 821 }
822 t = t->next;
821 } 823 }
822 824
823 /* Does client own tunnel? */ 825 /* Does client own tunnel? */