diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-05-01 09:28:51 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-05-01 09:28:51 +0000 |
commit | f6438d8a406e6fd570f0350a41d992483e21e612 (patch) | |
tree | 473098a6940498d7232079a848e525a8848b9cd5 /src/dht | |
parent | 05a0a1f05fdc8bbbbce19d48d8033bd6f055ec0e (diff) | |
download | gnunet-f6438d8a406e6fd570f0350a41d992483e21e612.tar.gz gnunet-f6438d8a406e6fd570f0350a41d992483e21e612.zip |
-fixing cleanup issues
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/gnunet-service-wdht_neighbours.c | 126 |
1 files changed, 76 insertions, 50 deletions
diff --git a/src/dht/gnunet-service-wdht_neighbours.c b/src/dht/gnunet-service-wdht_neighbours.c index c9c6d77e3..e0bab954e 100644 --- a/src/dht/gnunet-service-wdht_neighbours.c +++ b/src/dht/gnunet-service-wdht_neighbours.c | |||
@@ -76,6 +76,10 @@ | |||
76 | */ | 76 | */ |
77 | struct FriendInfo; | 77 | struct FriendInfo; |
78 | 78 | ||
79 | /** | ||
80 | * | ||
81 | */ | ||
82 | struct FingerTable; | ||
79 | 83 | ||
80 | /** | 84 | /** |
81 | * Information we keep per trail. | 85 | * Information we keep per trail. |
@@ -84,6 +88,21 @@ struct Trail | |||
84 | { | 88 | { |
85 | 89 | ||
86 | /** | 90 | /** |
91 | * Identifier of the trail with the predecessor. | ||
92 | */ | ||
93 | struct GNUNET_HashCode pred_id; | ||
94 | |||
95 | /** | ||
96 | * Identifier of the trail with the successor. | ||
97 | */ | ||
98 | struct GNUNET_HashCode succ_id; | ||
99 | |||
100 | /** | ||
101 | * When does this trail expire. | ||
102 | */ | ||
103 | struct GNUNET_TIME_Absolute expiration_time; | ||
104 | |||
105 | /** | ||
87 | * MDLL entry in the list of all trails with the same predecessor. | 106 | * MDLL entry in the list of all trails with the same predecessor. |
88 | */ | 107 | */ |
89 | struct Trail *prev_succ; | 108 | struct Trail *prev_succ; |
@@ -114,30 +133,23 @@ struct Trail | |||
114 | struct FriendInfo *succ; | 133 | struct FriendInfo *succ; |
115 | 134 | ||
116 | /** | 135 | /** |
117 | * Identifier of the trail with the predecessor. | ||
118 | */ | ||
119 | struct GNUNET_HashCode pred_id; | ||
120 | |||
121 | /** | ||
122 | * Identifier of the trail with the successor. | ||
123 | */ | ||
124 | struct GNUNET_HashCode succ_id; | ||
125 | |||
126 | /** | ||
127 | * When does this trail expire. | ||
128 | */ | ||
129 | struct GNUNET_TIME_Absolute expiration_time; | ||
130 | |||
131 | /** | ||
132 | * Location of this trail in the heap. | 136 | * Location of this trail in the heap. |
133 | */ | 137 | */ |
134 | struct GNUNET_CONTAINER_HeapNode *hn; | 138 | struct GNUNET_CONTAINER_HeapNode *hn; |
135 | 139 | ||
136 | /** | 140 | /** |
137 | * If this peer started the to create a Finger (and thus @e pred is | 141 | * If this peer started the to create a Finger (and thus @e pred is |
138 | * NULL), this is the Finger we are trying to intialize. | 142 | * NULL), this is the finger table of the finger we are trying to |
143 | * intialize. | ||
144 | */ | ||
145 | struct FingerTable *ft; | ||
146 | |||
147 | /** | ||
148 | * If this peer started the trail to create a Finger (and thus @e | ||
149 | * pred is NULL), this is the offset of the finger we are trying to | ||
150 | * intialize in the unsorted array. | ||
139 | */ | 151 | */ |
140 | struct Finger **finger; | 152 | unsigned int finger_off; |
141 | 153 | ||
142 | }; | 154 | }; |
143 | 155 | ||
@@ -183,12 +195,6 @@ struct FriendInfo | |||
183 | /** | 195 | /** |
184 | * | 196 | * |
185 | */ | 197 | */ |
186 | struct FingerTable; | ||
187 | |||
188 | |||
189 | /** | ||
190 | * | ||
191 | */ | ||
192 | struct Finger | 198 | struct Finger |
193 | { | 199 | { |
194 | /** | 200 | /** |
@@ -221,17 +227,12 @@ struct FingerTable | |||
221 | struct Finger **fingers; | 227 | struct Finger **fingers; |
222 | 228 | ||
223 | /** | 229 | /** |
224 | * Array of sorted fingers (sorted by destination, valid fingers first). | ||
225 | */ | ||
226 | struct Finger **sorted_fingers; | ||
227 | |||
228 | /** | ||
229 | * Size of the finger array. | 230 | * Size of the finger array. |
230 | */ | 231 | */ |
231 | unsigned int finger_array_size; | 232 | unsigned int finger_array_size; |
232 | 233 | ||
233 | /** | 234 | /** |
234 | * Number of valid entries in @e sorted_fingers (contiguous from offset 0) | 235 | * Number of valid entries in @e fingers |
235 | */ | 236 | */ |
236 | unsigned int number_valid_fingers; | 237 | unsigned int number_valid_fingers; |
237 | 238 | ||
@@ -695,10 +696,11 @@ delete_trail (struct Trail *trail, | |||
695 | } | 696 | } |
696 | GNUNET_break (trail == | 697 | GNUNET_break (trail == |
697 | GNUNET_CONTAINER_heap_remove_node (trail->hn)); | 698 | GNUNET_CONTAINER_heap_remove_node (trail->hn)); |
698 | finger = *trail->finger; | 699 | finger = trail->ft->fingers[trail->finger_off]; |
699 | if (NULL != finger) | 700 | if (NULL != finger) |
700 | { | 701 | { |
701 | *trail->finger = NULL; | 702 | trail->ft->fingers[trail->finger_off] = NULL; |
703 | trail->ft->number_valid_fingers--; | ||
702 | GNUNET_free (finger); | 704 | GNUNET_free (finger); |
703 | } | 705 | } |
704 | GNUNET_free (trail); | 706 | GNUNET_free (trail); |
@@ -951,6 +953,19 @@ trail_timeout_callback (void *cls, | |||
951 | 953 | ||
952 | 954 | ||
953 | /** | 955 | /** |
956 | * Compute how big our finger arrays should be (at least). | ||
957 | * | ||
958 | * @return size of the finger array, never 0 | ||
959 | */ | ||
960 | static unsigned int | ||
961 | get_desired_finger_array_size () | ||
962 | { | ||
963 | /* FIXME: This is just a stub... */ | ||
964 | return 64; | ||
965 | } | ||
966 | |||
967 | |||
968 | /** | ||
954 | * Initiate a random walk. | 969 | * Initiate a random walk. |
955 | * | 970 | * |
956 | * @param cls NULL | 971 | * @param cls NULL |
@@ -967,6 +982,7 @@ do_random_walk (void *cls, | |||
967 | struct FingerTable *ft; | 982 | struct FingerTable *ft; |
968 | struct Finger *finger; | 983 | struct Finger *finger; |
969 | struct Trail *trail; | 984 | struct Trail *trail; |
985 | unsigned int nsize; | ||
970 | 986 | ||
971 | random_walk_task = NULL; | 987 | random_walk_task = NULL; |
972 | friend = pick_random_friend (); | 988 | friend = pick_random_friend (); |
@@ -1012,21 +1028,19 @@ do_random_walk (void *cls, | |||
1012 | delete_trail (finger->trail, | 1028 | delete_trail (finger->trail, |
1013 | GNUNET_NO, | 1029 | GNUNET_NO, |
1014 | GNUNET_YES); | 1030 | GNUNET_YES); |
1015 | if (ft->finger_array_size < 42) | 1031 | if (ft->finger_array_size < (nsize = get_desired_finger_array_size()) ) |
1016 | { | 1032 | GNUNET_array_grow (ft->fingers, |
1017 | // FIXME: must have finger array of the right size here, | 1033 | ft->finger_array_size, |
1018 | // FIXME: growing / shrinking are tricky -- with pointers | 1034 | nsize); |
1019 | // from Trails!!! | ||
1020 | } | ||
1021 | |||
1022 | GNUNET_assert (NULL == ft->fingers[ft->walk_offset]); | 1035 | GNUNET_assert (NULL == ft->fingers[ft->walk_offset]); |
1023 | 1036 | trail->ft = ft; | |
1037 | trail->finger_off = ft->walk_offset; | ||
1024 | finger = GNUNET_new (struct Finger); | 1038 | finger = GNUNET_new (struct Finger); |
1025 | finger->trail = trail; | 1039 | finger->trail = trail; |
1026 | trail->finger = &ft->fingers[ft->walk_offset]; | ||
1027 | finger->ft = ft; | 1040 | finger->ft = ft; |
1028 | ft->fingers[ft->walk_offset] = finger; | 1041 | ft->fingers[ft->walk_offset] = finger; |
1029 | ft->is_sorted = GNUNET_NO; | 1042 | ft->is_sorted = GNUNET_NO; |
1043 | ft->number_valid_fingers++; | ||
1030 | ft->walk_offset = (ft->walk_offset + 1) % ft->finger_array_size; | 1044 | ft->walk_offset = (ft->walk_offset + 1) % ft->finger_array_size; |
1031 | 1045 | ||
1032 | walk_layer = (walk_layer + 1) % NUMBER_LAYERED_ID; | 1046 | walk_layer = (walk_layer + 1) % NUMBER_LAYERED_ID; |
@@ -1112,8 +1126,15 @@ handle_dht_p2p_random_walk (void *cls, | |||
1112 | const struct RandomWalkMessage *m; | 1126 | const struct RandomWalkMessage *m; |
1113 | struct Trail *t; | 1127 | struct Trail *t; |
1114 | struct FriendInfo *pred; | 1128 | struct FriendInfo *pred; |
1129 | uint16_t layer; | ||
1115 | 1130 | ||
1116 | m = (const struct RandomWalkMessage *) message; | 1131 | m = (const struct RandomWalkMessage *) message; |
1132 | layer = ntohs (m->layer); | ||
1133 | if (layer > NUMBER_LAYERED_ID) | ||
1134 | { | ||
1135 | GNUNET_break_op (0); | ||
1136 | return GNUNET_SYSERR; | ||
1137 | } | ||
1117 | pred = GNUNET_CONTAINER_multipeermap_get (friends_peermap, | 1138 | pred = GNUNET_CONTAINER_multipeermap_get (friends_peermap, |
1118 | peer); | 1139 | peer); |
1119 | t = GNUNET_new (struct Trail); | 1140 | t = GNUNET_new (struct Trail); |
@@ -1147,25 +1168,17 @@ handle_dht_p2p_random_walk (void *cls, | |||
1147 | /* We are the last hop, generate response */ | 1168 | /* We are the last hop, generate response */ |
1148 | struct GNUNET_MQ_Envelope *env; | 1169 | struct GNUNET_MQ_Envelope *env; |
1149 | struct RandomWalkResponseMessage *rwrm; | 1170 | struct RandomWalkResponseMessage *rwrm; |
1150 | uint16_t layer; | ||
1151 | 1171 | ||
1152 | env = GNUNET_MQ_msg (rwrm, | 1172 | env = GNUNET_MQ_msg (rwrm, |
1153 | GNUNET_MESSAGE_TYPE_WDHT_RANDOM_WALK_RESPONSE); | 1173 | GNUNET_MESSAGE_TYPE_WDHT_RANDOM_WALK_RESPONSE); |
1154 | rwrm->reserved = htonl (0); | 1174 | rwrm->reserved = htonl (0); |
1155 | rwrm->trail_id = m->trail_id; | 1175 | rwrm->trail_id = m->trail_id; |
1156 | layer = ntohs (m->layer); | ||
1157 | if (0 == layer) | 1176 | if (0 == layer) |
1158 | (void) GDS_DATACACHE_get_random_key (&rwrm->location); | 1177 | (void) GDS_DATACACHE_get_random_key (&rwrm->location); |
1159 | else | 1178 | else |
1160 | { | 1179 | { |
1161 | struct FingerTable *ft; | 1180 | struct FingerTable *ft; |
1162 | 1181 | ||
1163 | if (layer > NUMBER_LAYERED_ID) | ||
1164 | { | ||
1165 | GNUNET_break_op (0); | ||
1166 | // FIXME: clean up 't'... | ||
1167 | return GNUNET_SYSERR; | ||
1168 | } | ||
1169 | ft = &fingers[layer-1]; | 1182 | ft = &fingers[layer-1]; |
1170 | if (0 == ft->number_valid_fingers) | 1183 | if (0 == ft->number_valid_fingers) |
1171 | { | 1184 | { |
@@ -1175,9 +1188,13 @@ handle_dht_p2p_random_walk (void *cls, | |||
1175 | else | 1188 | else |
1176 | { | 1189 | { |
1177 | struct Finger *f; | 1190 | struct Finger *f; |
1191 | unsigned int off; | ||
1192 | unsigned int i; | ||
1178 | 1193 | ||
1179 | f = ft->fingers[GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, | 1194 | off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, |
1180 | ft->number_valid_fingers)]; | 1195 | ft->number_valid_fingers); |
1196 | for (i=0; (NULL == (f = ft->fingers[i])) || (off > 0); i++) | ||
1197 | if (NULL != f) off--; | ||
1181 | rwrm->location = f->destination; | 1198 | rwrm->location = f->destination; |
1182 | } | 1199 | } |
1183 | } | 1200 | } |
@@ -1486,6 +1503,15 @@ handle_dht_p2p_trail_route (void *cls, | |||
1486 | { &handle_dht_p2p_successor_find, NULL, | 1503 | { &handle_dht_p2p_successor_find, NULL, |
1487 | GNUNET_MESSAGE_TYPE_WDHT_SUCCESSOR_FIND, | 1504 | GNUNET_MESSAGE_TYPE_WDHT_SUCCESSOR_FIND, |
1488 | sizeof (struct FindSuccessorMessage) }, | 1505 | sizeof (struct FindSuccessorMessage) }, |
1506 | { &handle_dht_p2p_peer_get, NULL, | ||
1507 | GNUNET_MESSAGE_TYPE_WDHT_GET, | ||
1508 | sizeof (struct FindSuccessorMessage) }, | ||
1509 | { &handle_dht_p2p_peer_get_result, NULL, | ||
1510 | GNUNET_MESSAGE_TYPE_WDHT_GET_RESULT, | ||
1511 | 0 }, | ||
1512 | { &handle_dht_p2p_peer_put, NULL, | ||
1513 | GNUNET_MESSAGE_TYPE_WDHT_PUT, | ||
1514 | 0 }, | ||
1489 | { NULL, NULL, 0, 0 } | 1515 | { NULL, NULL, 0, 0 } |
1490 | }; | 1516 | }; |
1491 | unsigned int i; | 1517 | unsigned int i; |