aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/gnunet-service-mesh.c
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-04-19 00:30:37 +0000
committerBart Polot <bart@net.in.tum.de>2011-04-19 00:30:37 +0000
commit6998c967808d02bb71ee2999dc81c9f5f480cdf5 (patch)
tree316add42094559758045bc8526481bcacf728de1 /src/mesh/gnunet-service-mesh.c
parenta70c061da5313f7011a81f815f8266ff6ee30657 (diff)
downloadgnunet-6998c967808d02bb71ee2999dc81c9f5f480cdf5.tar.gz
gnunet-6998c967808d02bb71ee2999dc81c9f5f480cdf5.zip
WiP
Diffstat (limited to 'src/mesh/gnunet-service-mesh.c')
-rw-r--r--src/mesh/gnunet-service-mesh.c117
1 files changed, 108 insertions, 9 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 08d2ae216..760545021 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -236,6 +236,12 @@ enum PeerState
236struct PeerInfo 236struct PeerInfo
237{ 237{
238 /** 238 /**
239 * Double linked list
240 */
241 struct PeerInfo *next;
242 struct PeerInfo *prev;
243
244 /**
239 * ID of the peer 245 * ID of the peer
240 */ 246 */
241 GNUNET_PEER_Id id; 247 GNUNET_PEER_Id id;
@@ -246,6 +252,11 @@ struct PeerInfo
246 enum PeerState state; 252 enum PeerState state;
247 253
248 /** 254 /**
255 * When to try to establish contact again?
256 */
257 struct GNUNET_TIME_Absolute next_reconnect_attempt;
258
259 /**
249 * Who to send the data to --- FIXME what about multiple (alternate) paths? 260 * Who to send the data to --- FIXME what about multiple (alternate) paths?
250 */ 261 */
251 GNUNET_PEER_Id first_hop; 262 GNUNET_PEER_Id first_hop;
@@ -643,9 +654,10 @@ handle_local_tunnel_create (void *cls,
643{ 654{
644 struct GNUNET_MESH_TunnelMessage *tunnel_msg; 655 struct GNUNET_MESH_TunnelMessage *tunnel_msg;
645 struct MESH_tunnel *t; 656 struct MESH_tunnel *t;
657 struct Client *c;
646 658
647 /* Sanity check for client registration */ 659 /* Sanity check for client registration */
648 if(NULL == client_retrieve(client)) { 660 if(NULL == (c = client_retrieve(client))) {
649 GNUNET_break(0); 661 GNUNET_break(0);
650 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 662 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
651 return; 663 return;
@@ -661,10 +673,10 @@ handle_local_tunnel_create (void *cls,
661 tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message; 673 tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message;
662 /* Sanity check for tunnel numbering */ 674 /* Sanity check for tunnel numbering */
663 if(0 == (ntohl(tunnel_msg->tunnel_id) & 0x80000000)) { 675 if(0 == (ntohl(tunnel_msg->tunnel_id) & 0x80000000)) {
664 GNUNET_break(0); 676 GNUNET_break(0);
665 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 677 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
666 return; 678 return;
667 } 679 }
668 /* Sanity check for duplicate tunnel IDs */ 680 /* Sanity check for duplicate tunnel IDs */
669 for (t = tunnels_head; t != tunnels_head; t = t->next) { 681 for (t = tunnels_head; t != tunnels_head; t = t->next) {
670 if(t->tid == ntohl(tunnel_msg->tunnel_id)) { 682 if(t->tid == ntohl(tunnel_msg->tunnel_id)) {
@@ -673,7 +685,7 @@ handle_local_tunnel_create (void *cls,
673 return; 685 return;
674 } 686 }
675 } 687 }
676 /* FIXME: calloc? is NULL != 0 on any platform? */ 688 /* FIXME: calloc? Is NULL != 0 on any platform? */
677 t = GNUNET_malloc(sizeof(struct MESH_tunnel)); 689 t = GNUNET_malloc(sizeof(struct MESH_tunnel));
678 t->tid = ntohl(tunnel_msg->tunnel_id); 690 t->tid = ntohl(tunnel_msg->tunnel_id);
679 t->oid = myid; 691 t->oid = myid;
@@ -687,6 +699,10 @@ handle_local_tunnel_create (void *cls,
687 t->in_tail = NULL; 699 t->in_tail = NULL;
688 t->out_head = NULL; 700 t->out_head = NULL;
689 t->out_tail = NULL; 701 t->out_tail = NULL;
702 t->client = c;
703
704 GNUNET_CONTAINER_DLL_insert(tunnels_head, tunnels_tail, t);
705 GNUNET_CONTAINER_DLL_insert(c->tunnels_head, c->tunnels_tail, t);
690 706
691 GNUNET_SERVER_receive_done(client, GNUNET_OK); 707 GNUNET_SERVER_receive_done(client, GNUNET_OK);
692 return; 708 return;
@@ -705,15 +721,48 @@ handle_local_tunnel_destroy (void *cls,
705 const struct GNUNET_MessageHeader *message) 721 const struct GNUNET_MessageHeader *message)
706{ 722{
707 struct GNUNET_MESH_TunnelMessage *tunnel_msg; 723 struct GNUNET_MESH_TunnelMessage *tunnel_msg;
724 struct Client *c;
725 struct MESH_tunnel *t;
726 MESH_TunnelID tid;
727 struct PeerInfo *pi;
708 728
709 /* Sanity check for client registration */ 729 /* Sanity check for client registration */
710 if(NULL == client_retrieve(client)) { 730 if(NULL == (c = client_retrieve(client))) {
731 GNUNET_break(0);
732 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
733 return;
734 }
735 /* Message sanity check */
736 if(sizeof(struct GNUNET_MESH_TunnelMessage) != ntohs(message->size)) {
711 GNUNET_break(0); 737 GNUNET_break(0);
712 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 738 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
713 return; 739 return;
714 } 740 }
741
742 /* Tunnel exists? */
715 tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message; 743 tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message;
716 744 tid = ntohl(tunnel_msg->tunnel_id);
745 for (t = tunnels_head; t != tunnels_head; t = t->next) {
746 if(t->tid == tid) {
747 break;
748 }
749 }
750 if(t->tid != tid) {
751 GNUNET_break(0);
752 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
753 return;
754 }
755
756 GNUNET_CONTAINER_DLL_remove(tunnels_head, tunnels_tail, t);
757 GNUNET_CONTAINER_DLL_remove(c->tunnels_head, c->tunnels_tail, t);
758
759 for(pi = t->peers_head; pi != t->peers_tail; pi = t->peers_head) {
760 GNUNET_PEER_change_rc(pi->id, -1);
761 GNUNET_CONTAINER_DLL_remove(t->peers_head, t->peers_tail, pi);
762 GNUNET_free(pi);
763 }
764 GNUNET_free(t);
765
717 GNUNET_SERVER_receive_done(client, GNUNET_OK); 766 GNUNET_SERVER_receive_done(client, GNUNET_OK);
718 return; 767 return;
719} 768}
@@ -730,12 +779,62 @@ handle_local_connect_add (void *cls,
730 struct GNUNET_SERVER_Client *client, 779 struct GNUNET_SERVER_Client *client,
731 const struct GNUNET_MessageHeader *message) 780 const struct GNUNET_MessageHeader *message)
732{ 781{
782 struct GNUNET_MESH_PeerControl *peer_msg;
783 struct Client *c;
784 struct MESH_tunnel *t;
785 MESH_TunnelID tid;
786 struct PeerInfo *peer_info;
787
788
733 /* Sanity check for client registration */ 789 /* Sanity check for client registration */
734 if(NULL == client_retrieve(client)) { 790 if(NULL == (c = client_retrieve(client))) {
735 GNUNET_break(0); 791 GNUNET_break(0);
736 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 792 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
737 return; 793 return;
738 } 794 }
795
796 peer_msg = (struct GNUNET_MESH_PeerControl *)message;
797 /* Sanity check for message size */
798 if(sizeof(struct GNUNET_MESH_PeerControl) != ntohs(peer_msg->header.size)) {
799 GNUNET_break(0);
800 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
801 return;
802 }
803
804 /* Does tunnel exist? */
805 tid = ntohl(peer_msg->tunnel_id);
806 for(t = c->tunnels_head; t != c->tunnels_head; t = t->next) {
807 if(t->tid == tid) {
808 break;
809 }
810 }
811 if(NULL == t) {
812 GNUNET_break(0);
813 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
814 return;
815 } else {
816 if(t->tid != tid) {
817 GNUNET_break(0);
818 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
819 return;
820 }
821 }
822
823 /* Does client own tunnel? */
824 if(t->client->handle != client) {
825 GNUNET_break(0);
826 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
827 return;
828 }
829
830 /* Ok, add peer to tunnel */
831 peer_info = (struct PeerInfo *) GNUNET_malloc(sizeof(struct PeerInfo));
832 peer_info->id = GNUNET_PEER_intern(&peer_msg->peer);
833 peer_info->state = MESH_PEER_WAITING;
834 t->peers_total++;
835 GNUNET_CONTAINER_DLL_insert(t->peers_head, t->peers_tail, peer_info);
836 /* TODO MESH SEARCH FOR PEER */
837
739 GNUNET_SERVER_receive_done(client, GNUNET_OK); 838 GNUNET_SERVER_receive_done(client, GNUNET_OK);
740 return; 839 return;
741} 840}