diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-04-29 11:47:54 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-04-29 11:47:54 +0000 |
commit | d97cb7e3039c0c3d560a1e43761afe9a3b0d1cb6 (patch) | |
tree | 54da1c453c7956f1f1a86b8e2e45148bc98b47b9 /src/dht | |
parent | 538d3f15c3b599d57464e498a266dbf916ec01dc (diff) | |
download | gnunet-d97cb7e3039c0c3d560a1e43761afe9a3b0d1cb6.tar.gz gnunet-d97cb7e3039c0c3d560a1e43761afe9a3b0d1cb6.zip |
-fix ftbfs issues
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/Makefile.am | 4 | ||||
-rw-r--r-- | src/dht/gnunet-service-wdht_neighbours.c | 333 |
2 files changed, 175 insertions, 162 deletions
diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am index fd34f7d9c..8bfcc4b7d 100644 --- a/src/dht/Makefile.am +++ b/src/dht/Makefile.am | |||
@@ -48,8 +48,8 @@ libgnunet_plugin_block_dht_la_LDFLAGS = \ | |||
48 | 48 | ||
49 | libexec_PROGRAMS = \ | 49 | libexec_PROGRAMS = \ |
50 | gnunet-service-dht \ | 50 | gnunet-service-dht \ |
51 | gnunet-service-dht-xvine | 51 | gnunet-service-dht-xvine \ |
52 | # gnunet-service-dht-whanau | 52 | gnunet-service-dht-whanau |
53 | 53 | ||
54 | noinst_PROGRAMS = \ | 54 | noinst_PROGRAMS = \ |
55 | gnunet-dht-monitor \ | 55 | gnunet-dht-monitor \ |
diff --git a/src/dht/gnunet-service-wdht_neighbours.c b/src/dht/gnunet-service-wdht_neighbours.c index 01b7b543b..0818e21a4 100644 --- a/src/dht/gnunet-service-wdht_neighbours.c +++ b/src/dht/gnunet-service-wdht_neighbours.c | |||
@@ -17,13 +17,11 @@ | |||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | |||
21 | /** | 20 | /** |
22 | * @file dht/gnunet-service-wdht_neighbours.c | 21 | * @file dht/gnunet-service-wdht_neighbours.c |
23 | * @brief GNUnet DHT service's finger and friend table management code | 22 | * @brief GNUnet DHT service's finger and friend table management code |
24 | * @author Supriti Singh | 23 | * @author Supriti Singh |
25 | */ | 24 | */ |
26 | |||
27 | #include "platform.h" | 25 | #include "platform.h" |
28 | #include "gnunet_util_lib.h" | 26 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_block_lib.h" | 27 | #include "gnunet_block_lib.h" |
@@ -65,75 +63,117 @@ | |||
65 | #define NUMBER_RANDOM_WALK 20 | 63 | #define NUMBER_RANDOM_WALK 20 |
66 | 64 | ||
67 | 65 | ||
66 | /******************* The db structure and related functions *******************/ | ||
67 | |||
68 | /** | 68 | /** |
69 | * Contains all the layered ID. | 69 | * Entry in friend_peermap. |
70 | */ | 70 | */ |
71 | struct GNUNET_PeerIdentity layered_id[NUMBER_LAYERED_ID]; | 71 | struct FriendInfo; |
72 | |||
72 | 73 | ||
73 | /******************* The db structure and related functions *******************/ | ||
74 | /** | 74 | /** |
75 | * The number of cell store in the db structure. | 75 | * Information we keep per trail. |
76 | */ | 76 | */ |
77 | int number_cell; | 77 | struct Trail |
78 | { | ||
79 | |||
80 | /** | ||
81 | * MDLL entry in the list of all trails with the same predecessor. | ||
82 | */ | ||
83 | struct Trail *prev_succ; | ||
84 | |||
85 | /** | ||
86 | * MDLL entry in the list of all trails with the same predecessor. | ||
87 | */ | ||
88 | struct Trail *next_succ; | ||
89 | |||
90 | /** | ||
91 | * MDLL entry in the list of all trails with the same predecessor. | ||
92 | */ | ||
93 | struct Trail *prev_pred; | ||
94 | |||
95 | /** | ||
96 | * MDLL entry in the list of all trails with the same predecessor. | ||
97 | */ | ||
98 | struct Trail *next_pred; | ||
99 | |||
100 | /** | ||
101 | * Our predecessor in the trail, NULL if we are initiator (?). | ||
102 | */ | ||
103 | struct FriendInfo *pred; | ||
104 | |||
105 | /** | ||
106 | * Our successor in the trail, NULL if we are the last peer. | ||
107 | */ | ||
108 | struct FriendInfo *succ; | ||
109 | |||
110 | /** | ||
111 | * Identifier of the trail with the predecessor. | ||
112 | */ | ||
113 | struct GNUNET_HashCode pred_id; | ||
114 | |||
115 | /** | ||
116 | * Identifier of the trail with the successor. | ||
117 | */ | ||
118 | struct GNUNET_HashCode succ_id; | ||
119 | |||
120 | /** | ||
121 | * When does this trail expire. | ||
122 | */ | ||
123 | struct GNUNET_TIME_Absolute expiration_time; | ||
124 | |||
125 | /** | ||
126 | * Location of this trail in the heap. | ||
127 | */ | ||
128 | struct GNUNET_CONTAINER_HeapNode *hn; | ||
129 | |||
130 | }; | ||
131 | |||
78 | 132 | ||
79 | /** | 133 | /** |
80 | * If sorted_db array are sorted 1. Otherwise 0. | 134 | * Entry in friend_peermap. |
81 | */ | 135 | */ |
82 | /* FIXME: not sure about this one */ | 136 | struct FriendInfo |
83 | int is_sorted; | 137 | { |
84 | 138 | /** | |
85 | struct db_cell{ | 139 | * Friend Identity |
86 | /** | 140 | */ |
87 | * The identity of the. | 141 | struct GNUNET_PeerIdentity id; |
88 | */ | 142 | |
89 | GNUNET_PeerIdentity *peer_id; | 143 | struct Trail *pred_head; |
90 | /** | 144 | |
91 | * The trail to use to reach the peer. | 145 | struct Trail *pred_tail; |
92 | */ | 146 | |
93 | struct Trail *trail; | 147 | struct Trail *succ_head; |
94 | /** | 148 | |
95 | * 1 if a response are received. Otherwise 0. | 149 | struct Trail *succ_tail; |
96 | */ | 150 | |
97 | int valid; | 151 | /** |
152 | * Core handle for sending messages to this friend. | ||
153 | */ | ||
154 | struct GNUNET_MQ_Handle *mq; | ||
155 | |||
98 | }; | 156 | }; |
99 | 157 | ||
100 | struct db_cell *unsorted_db[NUMBER_RANDOM_WALK * NUMBER_LAYERED_ID]; | ||
101 | 158 | ||
102 | struct db_cell *sorted_db[NUMBER_RANDOM_WALK * NUMBER_LAYERED_ID]; | 159 | struct db_cell |
160 | { | ||
161 | /** | ||
162 | * The identity of the peer. | ||
163 | */ | ||
164 | struct GNUNET_PeerIdentity peer_id; | ||
103 | 165 | ||
104 | /** | 166 | /** |
105 | * Initialize the db structure with default values. | 167 | * The trail to use to reach the peer. |
106 | */ | 168 | */ |
107 | static void | 169 | struct Trail *trail; |
108 | init_db_structure (){ | ||
109 | int i; | ||
110 | for(i = 0; i < NUMBER_RANDOM_WALK; i++){ | ||
111 | unsorted_db[i] = NULL; | ||
112 | sorted_db[i] = unsorted_db[i]; | ||
113 | } | ||
114 | } | ||
115 | 170 | ||
116 | /** | 171 | /** |
117 | * Destroy the db_structure. Basically, free every db_cell. | 172 | * #GNUNET_YES if a response has been received. Otherwise #GNUNET_NO. |
118 | */ | 173 | */ |
119 | static void | 174 | int valid; |
120 | destroy_db_structure (){ | 175 | }; |
121 | int i; | ||
122 | for(i = 0; i < NUMBER_RANDOM_WALK; i++){ | ||
123 | GNUNET_free_non_null(unsorted_db[i]); | ||
124 | } | ||
125 | } | ||
126 | 176 | ||
127 | /** | ||
128 | * Add a new db_cell in the db structure. | ||
129 | */ | ||
130 | static int | ||
131 | add_new_cell(const struct *bd_cell){ | ||
132 | unsorted_db[number_cell] = bd_cell; | ||
133 | sorted_db[number_cell] = db_cell; | ||
134 | /* FIXME: add some code to sort by friend id */ | ||
135 | return 0; | ||
136 | } | ||
137 | 177 | ||
138 | /*********************** end of the db structure part ***********************/ | 178 | /*********************** end of the db structure part ***********************/ |
139 | 179 | ||
@@ -399,96 +439,30 @@ struct PeerGetResultMessage | |||
399 | GNUNET_NETWORK_STRUCT_END | 439 | GNUNET_NETWORK_STRUCT_END |
400 | 440 | ||
401 | /** | 441 | /** |
402 | * Entry in friend_peermap. | 442 | * The number of cells stored in the db structure. |
403 | */ | 443 | */ |
404 | struct FriendInfo; | 444 | static unsigned int number_cell; |
405 | |||
406 | 445 | ||
407 | /** | 446 | /** |
408 | * Information we keep per trail. | 447 | * If sorted_db array is sorted #GNUNET_YES. Otherwise #GNUNET_NO. |
409 | */ | 448 | */ |
410 | struct Trail | 449 | static int is_sorted; |
411 | { | ||
412 | |||
413 | /** | ||
414 | * MDLL entry in the list of all trails with the same predecessor. | ||
415 | */ | ||
416 | struct Tail *prev_succ; | ||
417 | |||
418 | /** | ||
419 | * MDLL entry in the list of all trails with the same predecessor. | ||
420 | */ | ||
421 | struct Tail *next_succ; | ||
422 | |||
423 | /** | ||
424 | * MDLL entry in the list of all trails with the same predecessor. | ||
425 | */ | ||
426 | struct Tail *prev_pred; | ||
427 | |||
428 | /** | ||
429 | * MDLL entry in the list of all trails with the same predecessor. | ||
430 | */ | ||
431 | struct Tail *next_pred; | ||
432 | |||
433 | /** | ||
434 | * Our predecessor in the trail, NULL if we are initiator (?). | ||
435 | */ | ||
436 | struct FriendInfo *pred; | ||
437 | |||
438 | /** | ||
439 | * Our successor in the trail, NULL if we are the last peer. | ||
440 | */ | ||
441 | struct FriendInfo *succ; | ||
442 | |||
443 | /** | ||
444 | * Identifier of the trail with the predecessor. | ||
445 | */ | ||
446 | struct GNUNET_HashCode pred_id; | ||
447 | |||
448 | /** | ||
449 | * Identifier of the trail with the successor. | ||
450 | */ | ||
451 | struct GNUNET_HashCode succ_id; | ||
452 | |||
453 | /** | ||
454 | * When does this trail expire. | ||
455 | */ | ||
456 | struct GNUNET_TIME_Absolute expiration_time; | ||
457 | |||
458 | /** | ||
459 | * Location of this trail in the heap. | ||
460 | */ | ||
461 | struct GNUNET_CONTAINER_HeapNode *hn; | ||
462 | |||
463 | }; | ||
464 | |||
465 | 450 | ||
466 | /** | 451 | /** |
467 | * Entry in friend_peermap. | 452 | * Contains all the layered IDs of this peer. |
468 | */ | 453 | */ |
469 | struct FriendInfo | 454 | struct GNUNET_PeerIdentity layered_id[NUMBER_LAYERED_ID]; |
470 | { | ||
471 | /** | ||
472 | * Friend Identity | ||
473 | */ | ||
474 | struct GNUNET_PeerIdentity id; | ||
475 | |||
476 | struct Tail *pred_head; | ||
477 | |||
478 | struct Tail *pred_tail; | ||
479 | |||
480 | struct Tail *succ_head; | ||
481 | |||
482 | struct Tail *succ_tail; | ||
483 | |||
484 | /** | ||
485 | * Core handle for sending messages to this friend. | ||
486 | */ | ||
487 | struct GNUNET_MQ_Handle *mq; | ||
488 | |||
489 | }; | ||
490 | 455 | ||
456 | /** | ||
457 | * Unsorted database, here we manage the entries. | ||
458 | */ | ||
459 | static struct db_cell *unsorted_db[NUMBER_RANDOM_WALK * NUMBER_LAYERED_ID]; | ||
491 | 460 | ||
461 | /** | ||
462 | * Sorted database by peer identity, needs to be re-sorted if | ||
463 | * #is_sorted is #GNUNET_NO. | ||
464 | */ | ||
465 | static struct db_cell **sorted_db[NUMBER_RANDOM_WALK * NUMBER_LAYERED_ID]; | ||
492 | 466 | ||
493 | /** | 467 | /** |
494 | * Task to timeout trails that have expired. | 468 | * Task to timeout trails that have expired. |
@@ -518,12 +492,12 @@ static struct GNUNET_CONTAINER_MultiPeerMap *successors_peermap; | |||
518 | /** | 492 | /** |
519 | * Tail map, mapping tail identifiers to `struct Trail`s | 493 | * Tail map, mapping tail identifiers to `struct Trail`s |
520 | */ | 494 | */ |
521 | static struct GNUNET_CONTAINER_MultiHashMap *tail_map; | 495 | static struct GNUNET_CONTAINER_MultiHashMap *trail_map; |
522 | 496 | ||
523 | /** | 497 | /** |
524 | * Tail heap, organizing trails by expiration time. | 498 | * Tail heap, organizing trails by expiration time. |
525 | */ | 499 | */ |
526 | static struct GNUNET_CONTAINER_Heap *tail_heap; | 500 | static struct GNUNET_CONTAINER_Heap *trail_heap; |
527 | 501 | ||
528 | /** | 502 | /** |
529 | * Handle to CORE. | 503 | * Handle to CORE. |
@@ -532,6 +506,49 @@ static struct GNUNET_CORE_Handle *core_api; | |||
532 | 506 | ||
533 | 507 | ||
534 | /** | 508 | /** |
509 | * Initialize the db structure with default values. | ||
510 | */ | ||
511 | static void | ||
512 | init_db_structure () | ||
513 | { | ||
514 | unsigned int i; | ||
515 | |||
516 | for (i = 0; i < NUMBER_RANDOM_WALK; i++) | ||
517 | { | ||
518 | unsorted_db[i] = NULL; | ||
519 | sorted_db[i] = &unsorted_db[i]; | ||
520 | } | ||
521 | } | ||
522 | |||
523 | |||
524 | /** | ||
525 | * Destroy the db_structure. Basically, free every db_cell. | ||
526 | */ | ||
527 | static void | ||
528 | destroy_db_structure () | ||
529 | { | ||
530 | unsigned int i; | ||
531 | |||
532 | for (i = 0; i < NUMBER_RANDOM_WALK; i++) | ||
533 | { | ||
534 | // what about 'unsorted_db[i]->trail? | ||
535 | GNUNET_free_non_null (unsorted_db[i]); | ||
536 | } | ||
537 | } | ||
538 | |||
539 | |||
540 | /** | ||
541 | * Add a new db_cell in the db structure. | ||
542 | */ | ||
543 | static void | ||
544 | add_new_cell (struct db_cell *bd_cell) | ||
545 | { | ||
546 | unsorted_db[number_cell] = bd_cell; | ||
547 | is_sorted = GNUNET_NO; | ||
548 | } | ||
549 | |||
550 | |||
551 | /** | ||
535 | * Handle the put request from the client. | 552 | * Handle the put request from the client. |
536 | * | 553 | * |
537 | * @param key Key for the content | 554 | * @param key Key for the content |
@@ -622,7 +639,7 @@ handle_core_disconnect (void *cls, | |||
622 | return; | 639 | return; |
623 | 640 | ||
624 | if (NULL == (remove_friend = | 641 | if (NULL == (remove_friend = |
625 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | 642 | GNUNET_CONTAINER_multipeermap_get (fingers_peermap, |
626 | peer))) | 643 | peer))) |
627 | { | 644 | { |
628 | GNUNET_break (0); | 645 | GNUNET_break (0); |
@@ -630,14 +647,14 @@ handle_core_disconnect (void *cls, | |||
630 | } | 647 | } |
631 | 648 | ||
632 | GNUNET_assert (GNUNET_YES == | 649 | GNUNET_assert (GNUNET_YES == |
633 | GNUNET_CONTAINER_multipeermap_remove (friend_peermap, | 650 | GNUNET_CONTAINER_multipeermap_remove (fingers_peermap, |
634 | peer, | 651 | peer, |
635 | remove_friend)); | 652 | remove_friend)); |
636 | /* FIXME: do stuff */ | 653 | /* FIXME: do stuff */ |
637 | GNUNET_MQ_destroy (remove_friend->mq); | 654 | GNUNET_MQ_destroy (remove_friend->mq); |
638 | GNUNET_free (remove_friend); | 655 | GNUNET_free (remove_friend); |
639 | if (0 == | 656 | if (0 == |
640 | GNUNET_CONTAINER_multipeermap_size (friend_peermap)) | 657 | GNUNET_CONTAINER_multipeermap_size (fingers_peermap)) |
641 | { | 658 | { |
642 | GNUNET_SCHEDULER_cancel (random_walk_task); | 659 | GNUNET_SCHEDULER_cancel (random_walk_task); |
643 | random_walk_task = NULL; | 660 | random_walk_task = NULL; |
@@ -663,18 +680,21 @@ do_random_walk (void *cls, | |||
663 | 680 | ||
664 | friend = NULL; // FIXME: pick at random... | 681 | friend = NULL; // FIXME: pick at random... |
665 | 682 | ||
666 | friend_cell = GNUNET_malloc(sizeof(struct db_cell)); | 683 | friend_cell = GNUNET_new (struct db_cell); |
667 | friend_cell->peer_identity = friend->id; | 684 | friend_cell->peer_id = friend->id; |
668 | 685 | ||
669 | trail = GNUNET_new(struct Trail); | 686 | trail = GNUNET_new (struct Trail); |
670 | 687 | ||
671 | /* We create the random walk so, no predecessor */ | 688 | /* We create the random walk so, no predecessor */ |
672 | trail->succ = friend; | 689 | trail->succ = friend; |
673 | 690 | ||
674 | GNUNET_CONTAINER_MDLL_insert_tail(succ, trail->prev, trail->next,friend) | 691 | GNUNET_CONTAINER_MDLL_insert (succ, |
692 | friend->succ_head, | ||
693 | friend->succ_tail, | ||
694 | trail); | ||
675 | env = GNUNET_MQ_msg (fsm, | 695 | env = GNUNET_MQ_msg (fsm, |
676 | GNUNET_MESSAGE_TYPE_WDHT_FINGER_SETUP); | 696 | GNUNET_MESSAGE_TYPE_WDHT_FINGER_SETUP); |
677 | fsm->hops_task = htons (0); | 697 | fsm->hops_taken = htons (0); |
678 | fsm->layer = htons (0); // FIXME: not always 0... | 698 | fsm->layer = htons (0); // FIXME: not always 0... |
679 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_NONCE, | 699 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_NONCE, |
680 | &fsm->finger_id); | 700 | &fsm->finger_id); |
@@ -703,7 +723,7 @@ handle_core_connect (void *cls, | |||
703 | 723 | ||
704 | /* If peer already exists in our friend_peermap, then exit. */ | 724 | /* If peer already exists in our friend_peermap, then exit. */ |
705 | if (GNUNET_YES == | 725 | if (GNUNET_YES == |
706 | GNUNET_CONTAINER_multipeermap_contains (friend_peermap, | 726 | GNUNET_CONTAINER_multipeermap_contains (fingers_peermap, |
707 | peer_identity)) | 727 | peer_identity)) |
708 | { | 728 | { |
709 | GNUNET_break (0); | 729 | GNUNET_break (0); |
@@ -715,7 +735,7 @@ handle_core_connect (void *cls, | |||
715 | friend->mq = GNUNET_CORE_mq_create (core_api, | 735 | friend->mq = GNUNET_CORE_mq_create (core_api, |
716 | peer_identity); | 736 | peer_identity); |
717 | GNUNET_assert (GNUNET_OK == | 737 | GNUNET_assert (GNUNET_OK == |
718 | GNUNET_CONTAINER_multipeermap_put (friend_peermap, | 738 | GNUNET_CONTAINER_multipeermap_put (fingers_peermap, |
719 | peer_identity, | 739 | peer_identity, |
720 | friend, | 740 | friend, |
721 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 741 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
@@ -788,7 +808,7 @@ handle_dht_p2p_finger_setup_response (void *cls, | |||
788 | { | 808 | { |
789 | const struct FingerSetupResponseMessage *fsrm; | 809 | const struct FingerSetupResponseMessage *fsrm; |
790 | 810 | ||
791 | fsm = (const struct FingerSetupResponseMessage *) message; | 811 | fsrm = (const struct FingerSetupResponseMessage *) message; |
792 | 812 | ||
793 | /* | 813 | /* |
794 | * Steps : | 814 | * Steps : |
@@ -796,13 +816,6 @@ handle_dht_p2p_finger_setup_response (void *cls, | |||
796 | * 1.a if true : add the returned value (finger) in the db structure | 816 | * 1.a if true : add the returned value (finger) in the db structure |
797 | * 1.b if true : do nothing | 817 | * 1.b if true : do nothing |
798 | */ | 818 | */ |
799 | if(NUMBER_LAYERED_ID >= fsm->layer){ | ||
800 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
801 | "The layer id is too big. %d received, an id below %d is expected", | ||
802 | fsm->layer, NUMBER_LAYERED_ID); | ||
803 | return GNUNET_SYSERR | ||
804 | } | ||
805 | |||
806 | /* FIXME: add the value in db structure 1.a */ | 819 | /* FIXME: add the value in db structure 1.a */ |
807 | 820 | ||
808 | return GNUNET_OK; | 821 | return GNUNET_OK; |
@@ -1068,12 +1081,12 @@ GDS_NEIGHBOURS_done (void) | |||
1068 | GNUNET_CORE_disconnect (core_api); | 1081 | GNUNET_CORE_disconnect (core_api); |
1069 | core_api = NULL; | 1082 | core_api = NULL; |
1070 | 1083 | ||
1071 | GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (friend_peermap)); | 1084 | GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (fingers_peermap)); |
1072 | GNUNET_CONTAINER_multipeermap_destroy (fingers_peermap); | 1085 | GNUNET_CONTAINER_multipeermap_destroy (fingers_peermap); |
1073 | GNUNET_CONTAINER_multipeermap_destroy (successors_peermap); | 1086 | GNUNET_CONTAINER_multipeermap_destroy (successors_peermap); |
1074 | destroy_db_structure(); | 1087 | destroy_db_structure(); |
1075 | 1088 | ||
1076 | friend_peermap = NULL; | 1089 | fingers_peermap = NULL; |
1077 | } | 1090 | } |
1078 | 1091 | ||
1079 | 1092 | ||