aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-05-04 08:53:42 +0000
committerBart Polot <bart@net.in.tum.de>2011-05-04 08:53:42 +0000
commit49a8c3c3374726914aa2c3d9d38a4683e8332c60 (patch)
tree4536687afaca2360ad86d3357d1e720507130ee8 /src/mesh
parent9ee83b1cb503a4d604c9ae4f53acfde2e95c1d09 (diff)
downloadgnunet-49a8c3c3374726914aa2c3d9d38a4683e8332c60.tar.gz
gnunet-49a8c3c3374726914aa2c3d9d38a4683e8332c60.zip
WiP
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh.c159
1 files changed, 105 insertions, 54 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 6755e55c7..8843afcd2 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -488,6 +488,82 @@ static struct GNUNET_DHT_Handle *dht_handle;
488static GNUNET_PEER_Id myid; 488static GNUNET_PEER_Id myid;
489 489
490/******************************************************************************/ 490/******************************************************************************/
491/****************** GENERAL HELPER FUNCTIONS ************************/
492/******************************************************************************/
493
494/**
495 * Check if client has registered with the service and has not disconnected
496 * @param client the client to check
497 * @return non-NULL if client exists in the global DLL
498 */
499static struct Client *
500retrieve_client (struct GNUNET_SERVER_Client *client) {
501 struct Client *c;
502 c = clients_head;
503 while(NULL != c) {
504 if(c->handle == client) return c;
505 if(c == clients_tail)
506 return NULL;
507 else
508 c = c->next;
509 }
510 return NULL;
511}
512
513/**
514 * Destroy the path and free any allocated resources linked to it
515 * @param t tunnel the path belongs to
516 * @param p the path to destroy
517 * @return GNUNET_OK on success
518 */
519static int
520destroy_path(struct MESH_tunnel *t, struct Path *p) {
521 GNUNET_PEER_decrement_rcs(p->peers, p->length);
522 GNUNET_free(p->peers);
523 GNUNET_CONTAINER_DLL_remove(t->paths_head, t->paths_tail, p);
524 GNUNET_free(p);
525 return GNUNET_OK;
526}
527
528/**
529 * Destroy the peer_info and free any allocated resources linked to it
530 * @param t tunnel the path belongs to
531 * @param pi the peer_info to destroy
532 * @return GNUNET_OK on success
533 */
534static int
535destroy_peer_info(struct MESH_tunnel *t, struct PeerInfo *pi) {
536 GNUNET_PEER_change_rc(pi->id, -1);
537 GNUNET_CONTAINER_DLL_remove(t->peers_head, t->peers_tail, pi);
538 GNUNET_free(pi);
539 return GNUNET_OK;
540}
541
542/**
543 * Destroy the tunnel and free any allocated resources linked to it
544 * @param c client the tunnel belongs to
545 * @param t the tunnel to destroy
546 * @return GNUNET_OK on success
547 */
548static int
549destroy_tunnel(struct Client *c, struct MESH_tunnel *t) {
550 struct PeerInfo *pi;
551 struct Path *path;
552
553 for(pi = t->peers_head; pi != NULL; pi = t->peers_head) {
554 destroy_peer_info(t, pi);
555 }
556
557 for(path = t->paths_head; path != NULL; path = t->paths_head) {
558 destroy_path(t, path);
559 }
560
561 GNUNET_CONTAINER_DLL_remove(c->tunnels_head, c->tunnels_tail, t);
562 GNUNET_free(t);
563 return GNUNET_OK;
564}
565
566/******************************************************************************/
491/******************** MESH NETWORK HANDLERS **************************/ 567/******************** MESH NETWORK HANDLERS **************************/
492/******************************************************************************/ 568/******************************************************************************/
493 569
@@ -502,7 +578,8 @@ static GNUNET_PEER_Id myid;
502 * @param buf where the callee should write the message 578 * @param buf where the callee should write the message
503 * @return number of bytes written to buf 579 * @return number of bytes written to buf
504 */ 580 */
505size_t send_core_create_path_for_peer (void *cls, size_t size, void *buf) { 581static size_t
582send_core_create_path_for_peer (void *cls, size_t size, void *buf) {
506 size_t size_needed; 583 size_t size_needed;
507 struct PeerInfo *peer_info; 584 struct PeerInfo *peer_info;
508 struct GNUNET_MESH_ManipulatePath *msg; 585 struct GNUNET_MESH_ManipulatePath *msg;
@@ -623,25 +700,6 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
623/******************************************************************************/ 700/******************************************************************************/
624 701
625/** 702/**
626 * Check if client has registered with the service and has not disconnected
627 * @param client the client to check
628 * @return non-NULL if client exists in the global DLL
629 */
630struct Client *
631client_retrieve (struct GNUNET_SERVER_Client *client) {
632 struct Client *c;
633 c = clients_head;
634 while(NULL != c) {
635 if(c->handle == client) return c;
636 if(c == clients_tail)
637 return NULL;
638 else
639 c = c->next;
640 }
641 return NULL;
642}
643
644/**
645 * notify_client_connection_failure: notify a client that the connection to the 703 * notify_client_connection_failure: notify a client that the connection to the
646 * requested remote peer is not possible (for instance, no route found) 704 * requested remote peer is not possible (for instance, no route found)
647 * Function called when the socket is ready to queue more data."buf" will be 705 * Function called when the socket is ready to queue more data."buf" will be
@@ -652,7 +710,8 @@ client_retrieve (struct GNUNET_SERVER_Client *client) {
652 * @param buf where the callee should write the message 710 * @param buf where the callee should write the message
653 * @return number of bytes written to buf 711 * @return number of bytes written to buf
654 */ 712 */
655size_t notify_client_connection_failure (void *cls, size_t size, void *buf) { 713static size_t
714notify_client_connection_failure (void *cls, size_t size, void *buf) {
656 int size_needed; 715 int size_needed;
657 struct PeerInfo *peer_info; 716 struct PeerInfo *peer_info;
658 struct GNUNET_MESH_PeerControl *msg; 717 struct GNUNET_MESH_PeerControl *msg;
@@ -677,8 +736,9 @@ size_t notify_client_connection_failure (void *cls, size_t size, void *buf) {
677 736
678 737
679/** 738/**
680 * Iterator called on each result obtained for a DHT 739 * Function to process paths received for a new peer addition. The recorded
681 * operation that expects a reply 740 * paths form the initial tunnel, which can be optimized later.
741 * Called on each result obtained for the DHT search.
682 * 742 *
683 * @param cls closure 743 * @param cls closure
684 * @param exp when will this value expire 744 * @param exp when will this value expire
@@ -691,14 +751,15 @@ size_t notify_client_connection_failure (void *cls, size_t size, void *buf) {
691 * @param size number of bytes in data 751 * @param size number of bytes in data
692 * @param data pointer to the result data 752 * @param data pointer to the result data
693 */ 753 */
694void dht_get_response_handler(void *cls, 754static void
695 struct GNUNET_TIME_Absolute exp, 755dht_get_response_handler(void *cls,
696 const GNUNET_HashCode * key, 756 struct GNUNET_TIME_Absolute exp,
697 const struct GNUNET_PeerIdentity * const *get_path, 757 const GNUNET_HashCode * key,
698 const struct GNUNET_PeerIdentity * const *put_path, 758 const struct GNUNET_PeerIdentity * const *get_path,
699 enum GNUNET_BLOCK_Type type, 759 const struct GNUNET_PeerIdentity * const *put_path,
700 size_t size, 760 enum GNUNET_BLOCK_Type type,
701 const void *data) 761 size_t size,
762 const void *data)
702{ 763{
703 struct PeerInfo *peer_info; 764 struct PeerInfo *peer_info;
704 struct MESH_tunnel *t; 765 struct MESH_tunnel *t;
@@ -721,13 +782,15 @@ void dht_get_response_handler(void *cls,
721 782
722 p = GNUNET_malloc(sizeof(struct Path)); 783 p = GNUNET_malloc(sizeof(struct Path));
723 GNUNET_CONTAINER_DLL_insert(t->paths_head, t->paths_tail, p); 784 GNUNET_CONTAINER_DLL_insert(t->paths_head, t->paths_tail, p);
724 for(i = 0; get_path[i] != NULL; i++) { 785 for(i = 0; get_path[i] != NULL; i++);
786 for(i--; i >= 0; i--) {
725 p->peers = GNUNET_realloc(p->peers, 787 p->peers = GNUNET_realloc(p->peers,
726 sizeof(GNUNET_PEER_Id) * (p->length + 1)); 788 sizeof(GNUNET_PEER_Id) * (p->length + 1));
727 p->peers[p->length] = GNUNET_PEER_intern(get_path[i]); 789 p->peers[p->length] = GNUNET_PEER_intern(get_path[i]);
728 p->length++; 790 p->length++;
729 } 791 }
730 for(i = 0; put_path[i] != NULL; i++) { 792 for(i = 0; put_path[i] != NULL; i++);
793 for(i--; i >= 0; i--) {
731 p->peers = GNUNET_realloc(p->peers, 794 p->peers = GNUNET_realloc(p->peers,
732 sizeof(GNUNET_PEER_Id) * (p->length + 1)); 795 sizeof(GNUNET_PEER_Id) * (p->length + 1));
733 p->peers[p->length] = GNUNET_PEER_intern(put_path[i]); 796 p->peers[p->length] = GNUNET_PEER_intern(put_path[i]);
@@ -768,11 +831,7 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
768 if (c->handle == client) { 831 if (c->handle == client) {
769 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c); 832 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c);
770 while (NULL != (t = c->tunnels_head)) { 833 while (NULL != (t = c->tunnels_head)) {
771 GNUNET_CONTAINER_DLL_remove (c->tunnels_head, 834 destroy_tunnel(c, t);
772 c->tunnels_tail,
773 t);
774 /* TODO free paths and other tunnel dynamic structures */
775 GNUNET_free (t);
776 } 835 }
777 GNUNET_free (c->messages_subscribed); 836 GNUNET_free (c->messages_subscribed);
778 next = c->next; 837 next = c->next;
@@ -845,7 +904,7 @@ handle_local_tunnel_create (void *cls,
845 struct Client *c; 904 struct Client *c;
846 905
847 /* Sanity check for client registration */ 906 /* Sanity check for client registration */
848 if(NULL == (c = client_retrieve(client))) { 907 if(NULL == (c = retrieve_client(client))) {
849 GNUNET_break(0); 908 GNUNET_break(0);
850 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 909 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
851 return; 910 return;
@@ -914,10 +973,9 @@ handle_local_tunnel_destroy (void *cls,
914 struct Client *c; 973 struct Client *c;
915 struct MESH_tunnel *t; 974 struct MESH_tunnel *t;
916 MESH_TunnelID tid; 975 MESH_TunnelID tid;
917 struct PeerInfo *pi;
918 976
919 /* Sanity check for client registration */ 977 /* Sanity check for client registration */
920 if(NULL == (c = client_retrieve(client))) { 978 if(NULL == (c = retrieve_client(client))) {
921 GNUNET_break(0); 979 GNUNET_break(0);
922 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 980 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
923 return; 981 return;
@@ -950,14 +1008,7 @@ handle_local_tunnel_destroy (void *cls,
950 t = t->next; 1008 t = t->next;
951 } 1009 }
952 1010
953 GNUNET_CONTAINER_DLL_remove(c->tunnels_head, c->tunnels_tail, t); 1011 destroy_tunnel(c, t);
954
955 for(pi = t->peers_head; pi != NULL; pi = t->peers_head) {
956 GNUNET_PEER_change_rc(pi->id, -1);
957 GNUNET_CONTAINER_DLL_remove(t->peers_head, t->peers_tail, pi);
958 GNUNET_free(pi);
959 }
960 GNUNET_free(t);
961 1012
962 GNUNET_SERVER_receive_done(client, GNUNET_OK); 1013 GNUNET_SERVER_receive_done(client, GNUNET_OK);
963 return; 1014 return;
@@ -985,7 +1036,7 @@ handle_local_connect_add (void *cls,
985 1036
986 1037
987 /* Sanity check for client registration */ 1038 /* Sanity check for client registration */
988 if(NULL == (c = client_retrieve(client))) { 1039 if(NULL == (c = retrieve_client(client))) {
989 GNUNET_break(0); 1040 GNUNET_break(0);
990 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1041 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
991 return; 1042 return;
@@ -1075,7 +1126,7 @@ handle_local_connect_del (void *cls,
1075 struct PeerInfo *aux_peer_info; 1126 struct PeerInfo *aux_peer_info;
1076 1127
1077 /* Sanity check for client registration */ 1128 /* Sanity check for client registration */
1078 if(NULL == (c = client_retrieve(client))) { 1129 if(NULL == (c = retrieve_client(client))) {
1079 GNUNET_break(0); 1130 GNUNET_break(0);
1080 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1131 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
1081 return; 1132 return;
@@ -1178,7 +1229,7 @@ handle_local_connect_by_type (void *cls,
1178 struct MESH_tunnel *t; 1229 struct MESH_tunnel *t;
1179 1230
1180 /* Sanity check for client registration */ 1231 /* Sanity check for client registration */
1181 if(NULL == (c = client_retrieve(client))) { 1232 if(NULL == (c = retrieve_client(client))) {
1182 GNUNET_break(0); 1233 GNUNET_break(0);
1183 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1234 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
1184 return; 1235 return;
@@ -1245,7 +1296,7 @@ handle_local_network_traffic (void *cls,
1245 MESH_TunnelID tid; 1296 MESH_TunnelID tid;
1246 1297
1247 /* Sanity check for client registration */ 1298 /* Sanity check for client registration */
1248 if(NULL == (c = client_retrieve(client))) { 1299 if(NULL == (c = retrieve_client(client))) {
1249 GNUNET_break(0); 1300 GNUNET_break(0);
1250 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1301 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
1251 return; 1302 return;
@@ -1308,7 +1359,7 @@ handle_local_network_traffic_bcast (void *cls,
1308 MESH_TunnelID tid; 1359 MESH_TunnelID tid;
1309 1360
1310 /* Sanity check for client registration */ 1361 /* Sanity check for client registration */
1311 if(NULL == (c = client_retrieve(client))) { 1362 if(NULL == (c = retrieve_client(client))) {
1312 GNUNET_break(0); 1363 GNUNET_break(0);
1313 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 1364 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
1314 return; 1365 return;