diff options
author | Arthur Dewarumez <arthur.dewarumez@etudiant.univ-lille1.fr> | 2015-04-29 11:09:24 +0000 |
---|---|---|
committer | Arthur Dewarumez <arthur.dewarumez@etudiant.univ-lille1.fr> | 2015-04-29 11:09:24 +0000 |
commit | 538d3f15c3b599d57464e498a266dbf916ec01dc (patch) | |
tree | 88a09d756baa955a9d0a94f80bca7919faec55ef /src/dht | |
parent | c263ac319ddc724c1d2a1bd01ea87f6ea4999ba6 (diff) | |
download | gnunet-538d3f15c3b599d57464e498a266dbf916ec01dc.tar.gz gnunet-538d3f15c3b599d57464e498a266dbf916ec01dc.zip |
Start implementation of some functions.
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/gnunet-service-wdht_neighbours.c | 119 |
1 files changed, 112 insertions, 7 deletions
diff --git a/src/dht/gnunet-service-wdht_neighbours.c b/src/dht/gnunet-service-wdht_neighbours.c index 1ca3185f8..01b7b543b 100644 --- a/src/dht/gnunet-service-wdht_neighbours.c +++ b/src/dht/gnunet-service-wdht_neighbours.c | |||
@@ -36,11 +36,13 @@ | |||
36 | #include "gnunet_transport_service.h" | 36 | #include "gnunet_transport_service.h" |
37 | #include "gnunet_dht_service.h" | 37 | #include "gnunet_dht_service.h" |
38 | #include "gnunet_statistics_service.h" | 38 | #include "gnunet_statistics_service.h" |
39 | #include "gnunet-service-xdht.h" | 39 | #include "gnunet-service-wdht.h" |
40 | #include "gnunet-service-wdht_clients.h" | 40 | #include "gnunet-service-wdht_clients.h" |
41 | #include "gnunet-service-wdht_datacache.h" | 41 | #include "gnunet-service-wdht_datacache.h" |
42 | #include "gnunet-service-wdht_neighbours.h" | 42 | #include "gnunet-service-wdht_neighbours.h" |
43 | #include <fenv.h> | 43 | #include <fenv.h> |
44 | #include <stdlib.h> | ||
45 | #include <string.h> | ||
44 | #include "dht.h" | 46 | #include "dht.h" |
45 | 47 | ||
46 | #define DEBUG(...) \ | 48 | #define DEBUG(...) \ |
@@ -57,10 +59,84 @@ | |||
57 | #define NUMBER_LAYERED_ID 8 | 59 | #define NUMBER_LAYERED_ID 8 |
58 | 60 | ||
59 | /** | 61 | /** |
62 | * The number of random walk to launch at the beginning of the initialization | ||
63 | */ | ||
64 | /* FIXME: find a better value */ | ||
65 | #define NUMBER_RANDOM_WALK 20 | ||
66 | |||
67 | |||
68 | /** | ||
60 | * Contains all the layered ID. | 69 | * Contains all the layered ID. |
61 | */ | 70 | */ |
62 | struct GNUNET_PeerIdentity layered_id[NUMBER_LAYERED_ID]; | 71 | struct GNUNET_PeerIdentity layered_id[NUMBER_LAYERED_ID]; |
63 | 72 | ||
73 | /******************* The db structure and related functions *******************/ | ||
74 | /** | ||
75 | * The number of cell store in the db structure. | ||
76 | */ | ||
77 | int number_cell; | ||
78 | |||
79 | /** | ||
80 | * If sorted_db array are sorted 1. Otherwise 0. | ||
81 | */ | ||
82 | /* FIXME: not sure about this one */ | ||
83 | int is_sorted; | ||
84 | |||
85 | struct db_cell{ | ||
86 | /** | ||
87 | * The identity of the. | ||
88 | */ | ||
89 | GNUNET_PeerIdentity *peer_id; | ||
90 | /** | ||
91 | * The trail to use to reach the peer. | ||
92 | */ | ||
93 | struct Trail *trail; | ||
94 | /** | ||
95 | * 1 if a response are received. Otherwise 0. | ||
96 | */ | ||
97 | int valid; | ||
98 | }; | ||
99 | |||
100 | struct db_cell *unsorted_db[NUMBER_RANDOM_WALK * NUMBER_LAYERED_ID]; | ||
101 | |||
102 | struct db_cell *sorted_db[NUMBER_RANDOM_WALK * NUMBER_LAYERED_ID]; | ||
103 | |||
104 | /** | ||
105 | * Initialize the db structure with default values. | ||
106 | */ | ||
107 | static void | ||
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 | |||
116 | /** | ||
117 | * Destroy the db_structure. Basically, free every db_cell. | ||
118 | */ | ||
119 | static void | ||
120 | destroy_db_structure (){ | ||
121 | int i; | ||
122 | for(i = 0; i < NUMBER_RANDOM_WALK; i++){ | ||
123 | GNUNET_free_non_null(unsorted_db[i]); | ||
124 | } | ||
125 | } | ||
126 | |||
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 | |||
138 | /*********************** end of the db structure part ***********************/ | ||
139 | |||
64 | 140 | ||
65 | GNUNET_NETWORK_STRUCT_BEGIN | 141 | GNUNET_NETWORK_STRUCT_BEGIN |
66 | 142 | ||
@@ -582,8 +658,20 @@ do_random_walk (void *cls, | |||
582 | struct FriendInfo *friend; | 658 | struct FriendInfo *friend; |
583 | struct GNUNET_MQ_Envelope *env; | 659 | struct GNUNET_MQ_Envelope *env; |
584 | struct FingerSetupMessage *fsm; | 660 | struct FingerSetupMessage *fsm; |
661 | struct db_cell *friend_cell; | ||
662 | struct Trail *trail; | ||
585 | 663 | ||
586 | friend = NULL; // FIXME: pick at random... | 664 | friend = NULL; // FIXME: pick at random... |
665 | |||
666 | friend_cell = GNUNET_malloc(sizeof(struct db_cell)); | ||
667 | friend_cell->peer_identity = friend->id; | ||
668 | |||
669 | trail = GNUNET_new(struct Trail); | ||
670 | |||
671 | /* We create the random walk so, no predecessor */ | ||
672 | trail->succ = friend; | ||
673 | |||
674 | GNUNET_CONTAINER_MDLL_insert_tail(succ, trail->prev, trail->next,friend) | ||
587 | env = GNUNET_MQ_msg (fsm, | 675 | env = GNUNET_MQ_msg (fsm, |
588 | GNUNET_MESSAGE_TYPE_WDHT_FINGER_SETUP); | 676 | GNUNET_MESSAGE_TYPE_WDHT_FINGER_SETUP); |
589 | fsm->hops_task = htons (0); | 677 | fsm->hops_task = htons (0); |
@@ -635,9 +723,8 @@ handle_core_connect (void *cls, | |||
635 | 723 | ||
636 | if (NULL == random_walk_task) | 724 | if (NULL == random_walk_task) |
637 | { | 725 | { |
638 | /* start random walks! */ | 726 | random_walk_task = GNUNET_SCHEDULER_add_now (&do_random_walk, |
639 | random_walk_task = GNUNET_SCHEDULER_add_now (&do_random_walk, | 727 | NULL); |
640 | NULL); | ||
641 | } | 728 | } |
642 | } | 729 | } |
643 | 730 | ||
@@ -706,9 +793,17 @@ handle_dht_p2p_finger_setup_response (void *cls, | |||
706 | /* | 793 | /* |
707 | * Steps : | 794 | * Steps : |
708 | * 1 check if we are the correct layer | 795 | * 1 check if we are the correct layer |
709 | * 1.a if true : add the return value in the db structure | 796 | * 1.a if true : add the returned value (finger) in the db structure |
710 | * 1.b if true : do nothing | 797 | * 1.b if true : do nothing |
711 | */ | 798 | */ |
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 */ | ||
712 | 807 | ||
713 | return GNUNET_OK; | 808 | return GNUNET_OK; |
714 | } | 809 | } |
@@ -764,7 +859,9 @@ handle_dht_p2p_finger_route (void *cls, | |||
764 | /* | 859 | /* |
765 | * steps : | 860 | * steps : |
766 | * 1 find the good trail | 861 | * 1 find the good trail |
767 | * 2 send the finger route message | 862 | * 2 check the message inside |
863 | * 2.a if the message is a finger setup message : increments ce hops_takeb | ||
864 | * 3 send the finger route message | ||
768 | */ | 865 | */ |
769 | 866 | ||
770 | return GNUNET_OK; | 867 | return GNUNET_OK; |
@@ -951,6 +1048,11 @@ GDS_NEIGHBOURS_init (void) | |||
951 | fingers_peermap = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO); | 1048 | fingers_peermap = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO); |
952 | successors_peermap = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO); | 1049 | successors_peermap = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO); |
953 | 1050 | ||
1051 | init_db_structure(); | ||
1052 | |||
1053 | |||
1054 | |||
1055 | |||
954 | return GNUNET_OK; | 1056 | return GNUNET_OK; |
955 | } | 1057 | } |
956 | 1058 | ||
@@ -967,7 +1069,10 @@ GDS_NEIGHBOURS_done (void) | |||
967 | core_api = NULL; | 1069 | core_api = NULL; |
968 | 1070 | ||
969 | GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (friend_peermap)); | 1071 | GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (friend_peermap)); |
970 | GNUNET_CONTAINER_multipeermap_destroy (friend_peermap); | 1072 | GNUNET_CONTAINER_multipeermap_destroy (fingers_peermap); |
1073 | GNUNET_CONTAINER_multipeermap_destroy (successors_peermap); | ||
1074 | destroy_db_structure(); | ||
1075 | |||
971 | friend_peermap = NULL; | 1076 | friend_peermap = NULL; |
972 | } | 1077 | } |
973 | 1078 | ||