diff options
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 44 | ||||
-rw-r--r-- | src/dht/test_dht_multipeer.c | 295 | ||||
-rw-r--r-- | src/dht/test_dht_multipeer_data.conf | 5 |
3 files changed, 194 insertions, 150 deletions
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index 697e49442..acc8eaa27 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -76,12 +76,12 @@ | |||
76 | /** | 76 | /** |
77 | * How long at least to wait before sending another find peer request. | 77 | * How long at least to wait before sending another find peer request. |
78 | */ | 78 | */ |
79 | #define DHT_MINIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2) | 79 | #define DHT_MINIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) |
80 | 80 | ||
81 | /** | 81 | /** |
82 | * How long at most to wait before sending another find peer request. | 82 | * How long at most to wait before sending another find peer request. |
83 | */ | 83 | */ |
84 | #define DHT_MAXIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 8) | 84 | #define DHT_MAXIMUM_FIND_PEER_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 10) |
85 | 85 | ||
86 | /** | 86 | /** |
87 | * How long at most to wait for transmission of a GET request to another peer? | 87 | * How long at most to wait for transmission of a GET request to another peer? |
@@ -611,11 +611,11 @@ send_find_peer_message (void *cls, | |||
611 | GNUNET_CONTAINER_bloomfilter_free (peer_bf); | 611 | GNUNET_CONTAINER_bloomfilter_free (peer_bf); |
612 | GNUNET_CONTAINER_bloomfilter_free (bcc.bloom); | 612 | GNUNET_CONTAINER_bloomfilter_free (bcc.bloom); |
613 | /* schedule next round */ | 613 | /* schedule next round */ |
614 | newly_found_peers = 0; | ||
615 | next_send_time.rel_value = | 614 | next_send_time.rel_value = |
616 | (DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / 2) + | 615 | DHT_MINIMUM_FIND_PEER_INTERVAL.rel_value + |
617 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, | 616 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
618 | DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / 2); | 617 | DHT_MAXIMUM_FIND_PEER_INTERVAL.rel_value / (newly_found_peers+1)); |
618 | newly_found_peers = 0; | ||
619 | find_peer_task = GNUNET_SCHEDULER_add_delayed (next_send_time, | 619 | find_peer_task = GNUNET_SCHEDULER_add_delayed (next_send_time, |
620 | &send_find_peer_message, | 620 | &send_find_peer_message, |
621 | NULL); | 621 | NULL); |
@@ -646,6 +646,9 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
646 | GNUNET_break (0); | 646 | GNUNET_break (0); |
647 | return; | 647 | return; |
648 | } | 648 | } |
649 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
650 | "Peer `%s' connected!\n", | ||
651 | GNUNET_i2s (peer)); | ||
649 | GNUNET_STATISTICS_update (GDS_stats, | 652 | GNUNET_STATISTICS_update (GDS_stats, |
650 | gettext_noop ("# Peers connected"), 1, | 653 | gettext_noop ("# Peers connected"), 1, |
651 | GNUNET_NO); | 654 | GNUNET_NO); |
@@ -664,8 +667,10 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
664 | peer_bucket); | 667 | peer_bucket); |
665 | if ( (peer_bucket > 0) && | 668 | if ( (peer_bucket > 0) && |
666 | (k_buckets[peer_bucket].peers_size <= bucket_size) ) | 669 | (k_buckets[peer_bucket].peers_size <= bucket_size) ) |
670 | { | ||
667 | ret->preference_task = GNUNET_SCHEDULER_add_now (&update_core_preference, ret); | 671 | ret->preference_task = GNUNET_SCHEDULER_add_now (&update_core_preference, ret); |
668 | newly_found_peers++; | 672 | newly_found_peers++; |
673 | } | ||
669 | GNUNET_assert (GNUNET_OK == | 674 | GNUNET_assert (GNUNET_OK == |
670 | GNUNET_CONTAINER_multihashmap_put (all_known_peers, | 675 | GNUNET_CONTAINER_multihashmap_put (all_known_peers, |
671 | &peer->hashPubKey, ret, | 676 | &peer->hashPubKey, ret, |
@@ -692,9 +697,6 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
692 | int current_bucket; | 697 | int current_bucket; |
693 | struct P2PPendingMessage *pos; | 698 | struct P2PPendingMessage *pos; |
694 | 699 | ||
695 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
696 | "Peer `%s' disconnected!\n", | ||
697 | GNUNET_i2s (peer)); | ||
698 | /* Check for disconnect from self message */ | 700 | /* Check for disconnect from self message */ |
699 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) | 701 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) |
700 | return; | 702 | return; |
@@ -705,6 +707,9 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
705 | GNUNET_break (0); | 707 | GNUNET_break (0); |
706 | return; | 708 | return; |
707 | } | 709 | } |
710 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
711 | "Peer `%s' disconnected!\n", | ||
712 | GNUNET_i2s (peer)); | ||
708 | GNUNET_STATISTICS_update (GDS_stats, | 713 | GNUNET_STATISTICS_update (GDS_stats, |
709 | gettext_noop ("# Peers connected"), -1, | 714 | gettext_noop ("# Peers connected"), -1, |
710 | GNUNET_NO); | 715 | GNUNET_NO); |
@@ -1208,7 +1213,13 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, | |||
1208 | desired_replication_level, | 1213 | desired_replication_level, |
1209 | &targets); | 1214 | &targets); |
1210 | if (0 == target_count) | 1215 | if (0 == target_count) |
1211 | return; | 1216 | { |
1217 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1218 | "Not forwarding PUT for `%s' after %u hops!\n", | ||
1219 | GNUNET_h2s (key), | ||
1220 | hop_count); | ||
1221 | return; | ||
1222 | } | ||
1212 | msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + sizeof (struct PeerPutMessage); | 1223 | msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + sizeof (struct PeerPutMessage); |
1213 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1224 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
1214 | { | 1225 | { |
@@ -1306,7 +1317,13 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, | |||
1306 | desired_replication_level, | 1317 | desired_replication_level, |
1307 | &targets); | 1318 | &targets); |
1308 | if (0 == target_count) | 1319 | if (0 == target_count) |
1309 | return; | 1320 | { |
1321 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1322 | "Not forwarding PUT for `%s' after %u hops!\n", | ||
1323 | GNUNET_h2s (key), | ||
1324 | hop_count); | ||
1325 | return; | ||
1326 | } | ||
1310 | reply_bf_size = GNUNET_CONTAINER_bloomfilter_get_size (reply_bf); | 1327 | reply_bf_size = GNUNET_CONTAINER_bloomfilter_get_size (reply_bf); |
1311 | msize = xquery_size + sizeof (struct PeerGetMessage) + reply_bf_size; | 1328 | msize = xquery_size + sizeof (struct PeerGetMessage) + reply_bf_size; |
1312 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1329 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
@@ -1406,6 +1423,9 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, | |||
1406 | if (NULL == pi) | 1423 | if (NULL == pi) |
1407 | { | 1424 | { |
1408 | /* peer disconnected in the meantime, drop reply */ | 1425 | /* peer disconnected in the meantime, drop reply */ |
1426 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1427 | "Not forwarding REPLY for `%s' due to predecessor disconnect\n", | ||
1428 | GNUNET_h2s (key)); | ||
1409 | return; | 1429 | return; |
1410 | } | 1430 | } |
1411 | GNUNET_STATISTICS_update (GDS_stats, | 1431 | GNUNET_STATISTICS_update (GDS_stats, |
diff --git a/src/dht/test_dht_multipeer.c b/src/dht/test_dht_multipeer.c index 3db2e1e5e..b41a8e371 100644 --- a/src/dht/test_dht_multipeer.c +++ b/src/dht/test_dht_multipeer.c | |||
@@ -34,13 +34,13 @@ | |||
34 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 30) | 34 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 30) |
35 | 35 | ||
36 | /* Timeout for waiting for replies to get requests */ | 36 | /* Timeout for waiting for replies to get requests */ |
37 | #define GET_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) | 37 | #define GET_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) |
38 | 38 | ||
39 | /* Timeout for waiting for gets to complete */ | 39 | /* Timeout for waiting for gets to complete */ |
40 | #define GET_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) | 40 | #define GET_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 50) |
41 | 41 | ||
42 | /* Timeout for waiting for puts to complete */ | 42 | /* Timeout for waiting for puts to complete */ |
43 | #define PUT_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) | 43 | #define PUT_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 50) |
44 | 44 | ||
45 | /* If number of peers not in config file, use this number */ | 45 | /* If number of peers not in config file, use this number */ |
46 | #define DEFAULT_NUM_PEERS 10 | 46 | #define DEFAULT_NUM_PEERS 10 |
@@ -53,7 +53,7 @@ | |||
53 | 53 | ||
54 | #define PATH_TRACKING GNUNET_YES | 54 | #define PATH_TRACKING GNUNET_YES |
55 | 55 | ||
56 | /* Structs */ | 56 | |
57 | 57 | ||
58 | struct TestPutContext | 58 | struct TestPutContext |
59 | { | 59 | { |
@@ -63,6 +63,11 @@ struct TestPutContext | |||
63 | struct TestPutContext *next; | 63 | struct TestPutContext *next; |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * This is a linked list | ||
67 | */ | ||
68 | struct TestPutContext *prev; | ||
69 | |||
70 | /** | ||
66 | * Handle to the first peers DHT service (via the API) | 71 | * Handle to the first peers DHT service (via the API) |
67 | */ | 72 | */ |
68 | struct GNUNET_DHT_Handle *dht_handle; | 73 | struct GNUNET_DHT_Handle *dht_handle; |
@@ -78,17 +83,25 @@ struct TestPutContext | |||
78 | uint32_t uid; | 83 | uint32_t uid; |
79 | 84 | ||
80 | /** | 85 | /** |
81 | * Task for disconnecting DHT handles | 86 | * Task handle for processing of the put. |
82 | */ | 87 | */ |
83 | GNUNET_SCHEDULER_TaskIdentifier disconnect_task; | 88 | GNUNET_SCHEDULER_TaskIdentifier task; |
84 | }; | 89 | }; |
85 | 90 | ||
91 | |||
86 | struct TestGetContext | 92 | struct TestGetContext |
87 | { | 93 | { |
88 | /* This is a linked list */ | 94 | /** |
95 | * This is a linked list | ||
96 | */ | ||
89 | struct TestGetContext *next; | 97 | struct TestGetContext *next; |
90 | 98 | ||
91 | /** | 99 | /** |
100 | * This is a linked list | ||
101 | */ | ||
102 | struct TestGetContext *prev; | ||
103 | |||
104 | /** | ||
92 | * Handle to the first peers DHT service (via the API) | 105 | * Handle to the first peers DHT service (via the API) |
93 | */ | 106 | */ |
94 | struct GNUNET_DHT_Handle *dht_handle; | 107 | struct GNUNET_DHT_Handle *dht_handle; |
@@ -111,7 +124,7 @@ struct TestGetContext | |||
111 | /** | 124 | /** |
112 | * Task for disconnecting DHT handles (and stopping GET) | 125 | * Task for disconnecting DHT handles (and stopping GET) |
113 | */ | 126 | */ |
114 | GNUNET_SCHEDULER_TaskIdentifier disconnect_task; | 127 | GNUNET_SCHEDULER_TaskIdentifier task; |
115 | 128 | ||
116 | /** | 129 | /** |
117 | * Whether or not this request has been fulfilled already. | 130 | * Whether or not this request has been fulfilled already. |
@@ -119,17 +132,26 @@ struct TestGetContext | |||
119 | int succeeded; | 132 | int succeeded; |
120 | }; | 133 | }; |
121 | 134 | ||
122 | /* Globals */ | ||
123 | 135 | ||
124 | /** | 136 | /** |
125 | * List of GETS to perform | 137 | * List of GETS to perform |
126 | */ | 138 | */ |
127 | struct TestGetContext *all_gets; | 139 | static struct TestGetContext *all_gets_head; |
140 | |||
141 | /** | ||
142 | * List of GETS to perform | ||
143 | */ | ||
144 | static struct TestGetContext *all_gets_tail; | ||
128 | 145 | ||
129 | /** | 146 | /** |
130 | * List of PUTS to perform | 147 | * List of PUTS to perform |
131 | */ | 148 | */ |
132 | struct TestPutContext *all_puts; | 149 | static struct TestPutContext *all_puts_head; |
150 | |||
151 | /** | ||
152 | * List of PUTS to perform | ||
153 | */ | ||
154 | static struct TestPutContext *all_puts_tail; | ||
133 | 155 | ||
134 | /** | 156 | /** |
135 | * Handle to the set of all peers run for this test. | 157 | * Handle to the set of all peers run for this test. |
@@ -181,9 +203,12 @@ static enum GNUNET_DHT_RouteOption route_option; | |||
181 | */ | 203 | */ |
182 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | 204 | static GNUNET_SCHEDULER_TaskIdentifier die_task; |
183 | 205 | ||
184 | /* Global return value (0 for success, anything else for failure) */ | 206 | /** |
207 | * Global return value (0 for success, anything else for failure) | ||
208 | */ | ||
185 | static int ok; | 209 | static int ok; |
186 | 210 | ||
211 | |||
187 | /** | 212 | /** |
188 | * Check whether peers successfully shut down. | 213 | * Check whether peers successfully shut down. |
189 | */ | 214 | */ |
@@ -200,18 +225,6 @@ shutdown_callback (void *cls, const char *emsg) | |||
200 | } | 225 | } |
201 | } | 226 | } |
202 | 227 | ||
203 | /** | ||
204 | * Task to release DHT handles for PUT | ||
205 | */ | ||
206 | static void | ||
207 | put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
208 | { | ||
209 | struct TestPutContext *test_put = cls; | ||
210 | |||
211 | test_put->disconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
212 | GNUNET_DHT_disconnect (test_put->dht_handle); | ||
213 | test_put->dht_handle = NULL; | ||
214 | } | ||
215 | 228 | ||
216 | /** | 229 | /** |
217 | * Function scheduled to be run on the successful completion of this | 230 | * Function scheduled to be run on the successful completion of this |
@@ -220,32 +233,39 @@ put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
220 | static void | 233 | static void |
221 | finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 234 | finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
222 | { | 235 | { |
223 | GNUNET_assert (pg != NULL); | 236 | struct TestPutContext *test_put; |
224 | struct TestPutContext *test_put = all_puts; | 237 | struct TestGetContext *test_get; |
225 | struct TestGetContext *test_get = all_gets; | ||
226 | 238 | ||
227 | while (test_put != NULL) | 239 | die_task = GNUNET_SCHEDULER_NO_TASK; |
240 | while (NULL != (test_put = all_puts_head)) | ||
228 | { | 241 | { |
229 | if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK) | 242 | if (test_put->task != GNUNET_SCHEDULER_NO_TASK) |
230 | GNUNET_SCHEDULER_cancel (test_put->disconnect_task); | 243 | GNUNET_SCHEDULER_cancel (test_put->task); |
231 | if (test_put->dht_handle != NULL) | 244 | if (test_put->dht_handle != NULL) |
232 | GNUNET_DHT_disconnect (test_put->dht_handle); | 245 | GNUNET_DHT_disconnect (test_put->dht_handle); |
233 | test_put = test_put->next; | 246 | GNUNET_CONTAINER_DLL_remove (all_puts_head, |
247 | all_puts_tail, | ||
248 | test_put); | ||
249 | GNUNET_free (test_put); | ||
234 | } | 250 | } |
235 | 251 | ||
236 | while (test_get != NULL) | 252 | while (NULL != (test_get = all_gets_head)) |
237 | { | 253 | { |
238 | if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK) | 254 | if (test_get->task != GNUNET_SCHEDULER_NO_TASK) |
239 | GNUNET_SCHEDULER_cancel (test_get->disconnect_task); | 255 | GNUNET_SCHEDULER_cancel (test_get->task); |
240 | if (test_get->get_handle != NULL) | 256 | if (test_get->get_handle != NULL) |
241 | GNUNET_DHT_get_stop (test_get->get_handle); | 257 | GNUNET_DHT_get_stop (test_get->get_handle); |
242 | if (test_get->dht_handle != NULL) | 258 | if (test_get->dht_handle != NULL) |
243 | GNUNET_DHT_disconnect (test_get->dht_handle); | 259 | GNUNET_DHT_disconnect (test_get->dht_handle); |
244 | test_get = test_get->next; | 260 | GNUNET_CONTAINER_DLL_remove (all_gets_head, |
261 | all_gets_tail, | ||
262 | test_get); | ||
263 | GNUNET_free (test_get); | ||
245 | } | 264 | } |
246 | 265 | ||
247 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | ||
248 | ok = 0; | 266 | ok = 0; |
267 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | ||
268 | pg = NULL; | ||
249 | } | 269 | } |
250 | 270 | ||
251 | 271 | ||
@@ -258,36 +278,41 @@ static void | |||
258 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 278 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
259 | { | 279 | { |
260 | const char *emsg = cls; | 280 | const char *emsg = cls; |
281 | struct TestPutContext *test_put; | ||
282 | struct TestGetContext *test_get; | ||
261 | 283 | ||
284 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
262 | fprintf (stderr, | 285 | fprintf (stderr, |
263 | "Failing test with error: `%s'!\n", | 286 | "Failing test with error: `%s'!\n", |
264 | emsg); | 287 | emsg); |
265 | 288 | while (NULL != (test_put = all_puts_head)) | |
266 | struct TestPutContext *test_put = all_puts; | ||
267 | struct TestGetContext *test_get = all_gets; | ||
268 | |||
269 | while (test_put != NULL) | ||
270 | { | 289 | { |
271 | if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK) | 290 | if (test_put->task != GNUNET_SCHEDULER_NO_TASK) |
272 | GNUNET_SCHEDULER_cancel (test_put->disconnect_task); | 291 | GNUNET_SCHEDULER_cancel (test_put->task); |
273 | if (test_put->dht_handle != NULL) | 292 | if (test_put->dht_handle != NULL) |
274 | GNUNET_DHT_disconnect (test_put->dht_handle); | 293 | GNUNET_DHT_disconnect (test_put->dht_handle); |
275 | test_put = test_put->next; | 294 | GNUNET_CONTAINER_DLL_remove (all_puts_head, |
295 | all_puts_tail, | ||
296 | test_put); | ||
297 | GNUNET_free (test_put); | ||
276 | } | 298 | } |
277 | 299 | ||
278 | while (test_get != NULL) | 300 | while (NULL != (test_get = all_gets_head)) |
279 | { | 301 | { |
280 | if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK) | 302 | if (test_get->task != GNUNET_SCHEDULER_NO_TASK) |
281 | GNUNET_SCHEDULER_cancel (test_get->disconnect_task); | 303 | GNUNET_SCHEDULER_cancel (test_get->task); |
282 | if (test_get->get_handle != NULL) | 304 | if (test_get->get_handle != NULL) |
283 | GNUNET_DHT_get_stop (test_get->get_handle); | 305 | GNUNET_DHT_get_stop (test_get->get_handle); |
284 | if (test_get->dht_handle != NULL) | 306 | if (test_get->dht_handle != NULL) |
285 | GNUNET_DHT_disconnect (test_get->dht_handle); | 307 | GNUNET_DHT_disconnect (test_get->dht_handle); |
286 | test_get = test_get->next; | 308 | GNUNET_CONTAINER_DLL_remove (all_gets_head, |
309 | all_gets_tail, | ||
310 | test_get); | ||
311 | GNUNET_free (test_get); | ||
287 | } | 312 | } |
288 | |||
289 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | ||
290 | ok = 1; | 313 | ok = 1; |
314 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | ||
315 | pg = NULL; | ||
291 | } | 316 | } |
292 | 317 | ||
293 | 318 | ||
@@ -301,16 +326,16 @@ get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
301 | GNUNET_HashCode search_key; /* Key stored under */ | 326 | GNUNET_HashCode search_key; /* Key stored under */ |
302 | char original_data[TEST_DATA_SIZE]; /* Made up data to store */ | 327 | char original_data[TEST_DATA_SIZE]; /* Made up data to store */ |
303 | 328 | ||
304 | test_get->disconnect_task = GNUNET_SCHEDULER_NO_TASK; | 329 | test_get->task = GNUNET_SCHEDULER_NO_TASK; |
305 | memset (original_data, test_get->uid, sizeof (original_data)); | 330 | memset (original_data, test_get->uid, sizeof (original_data)); |
306 | GNUNET_CRYPTO_hash (original_data, TEST_DATA_SIZE, &search_key); | 331 | GNUNET_CRYPTO_hash (original_data, TEST_DATA_SIZE, &search_key); |
307 | |||
308 | if (test_get->succeeded != GNUNET_YES) | 332 | if (test_get->succeeded != GNUNET_YES) |
309 | { | 333 | { |
310 | gets_failed++; | 334 | gets_failed++; |
311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 335 | fprintf (stderr, |
312 | "Get from peer %s for key %s failed!\n", | 336 | "Get from peer %s for key %s failed!\n", |
313 | test_get->daemon->shortname, GNUNET_h2s (&search_key)); | 337 | GNUNET_i2s (&test_get->daemon->id), |
338 | GNUNET_h2s (&search_key)); | ||
314 | } | 339 | } |
315 | GNUNET_assert (test_get->get_handle != NULL); | 340 | GNUNET_assert (test_get->get_handle != NULL); |
316 | GNUNET_DHT_get_stop (test_get->get_handle); | 341 | GNUNET_DHT_get_stop (test_get->get_handle); |
@@ -323,23 +348,27 @@ get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
323 | fprintf (stderr, | 348 | fprintf (stderr, |
324 | "%llu gets succeeded, %llu gets failed!\n", | 349 | "%llu gets succeeded, %llu gets failed!\n", |
325 | gets_completed, gets_failed); | 350 | gets_completed, gets_failed); |
351 | GNUNET_CONTAINER_DLL_remove (all_gets_head, | ||
352 | all_gets_tail, | ||
353 | test_get); | ||
354 | GNUNET_free (test_get); | ||
355 | |||
326 | if ((gets_failed > 0) && (outstanding_gets == 0)) /* Had some failures */ | 356 | if ((gets_failed > 0) && (outstanding_gets == 0)) /* Had some failures */ |
327 | { | 357 | { |
328 | GNUNET_SCHEDULER_cancel (die_task); | 358 | GNUNET_SCHEDULER_cancel (die_task); |
329 | die_task = | 359 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, "not all gets succeeded"); |
330 | GNUNET_SCHEDULER_add_now (&end_badly, "not all gets succeeded"); | 360 | return; |
331 | return; | ||
332 | } | 361 | } |
333 | 362 | ||
334 | if ( (gets_completed == num_peers * num_peers) && | 363 | if ( (gets_completed == num_peers * num_peers) && |
335 | (outstanding_gets == 0) ) /* All gets successful */ | 364 | (outstanding_gets == 0) ) /* All gets successful */ |
336 | { | 365 | { |
337 | GNUNET_SCHEDULER_cancel (die_task); | 366 | GNUNET_SCHEDULER_cancel (die_task); |
338 | //GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5), &get_topology, NULL); | ||
339 | die_task = GNUNET_SCHEDULER_add_now (&finish_testing, NULL); | 367 | die_task = GNUNET_SCHEDULER_add_now (&finish_testing, NULL); |
340 | } | 368 | } |
341 | } | 369 | } |
342 | 370 | ||
371 | |||
343 | /** | 372 | /** |
344 | * Iterator called if the GET request initiated returns a response. | 373 | * Iterator called if the GET request initiated returns a response. |
345 | * | 374 | * |
@@ -366,7 +395,6 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | |||
366 | 395 | ||
367 | memset (original_data, test_get->uid, sizeof (original_data)); | 396 | memset (original_data, test_get->uid, sizeof (original_data)); |
368 | GNUNET_CRYPTO_hash (original_data, TEST_DATA_SIZE, &search_key); | 397 | GNUNET_CRYPTO_hash (original_data, TEST_DATA_SIZE, &search_key); |
369 | |||
370 | if (test_get->succeeded == GNUNET_YES) | 398 | if (test_get->succeeded == GNUNET_YES) |
371 | return; /* Get has already been successful, probably ending now */ | 399 | return; /* Get has already been successful, probably ending now */ |
372 | 400 | ||
@@ -394,18 +422,14 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | |||
394 | if ((0 != memcmp (&search_key, key, sizeof (GNUNET_HashCode))) || | 422 | if ((0 != memcmp (&search_key, key, sizeof (GNUNET_HashCode))) || |
395 | (0 != memcmp (original_data, data, sizeof (original_data)))) | 423 | (0 != memcmp (original_data, data, sizeof (original_data)))) |
396 | { | 424 | { |
397 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 425 | fprintf (stderr, |
398 | "Key or data is not the same as was inserted!\n"); | 426 | "Key or data is not the same as was inserted!\n"); |
399 | } | 427 | return; |
400 | else | ||
401 | { | ||
402 | gets_completed++; | ||
403 | test_get->succeeded = GNUNET_YES; | ||
404 | } | 428 | } |
405 | 429 | gets_completed++; | |
406 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n"); | 430 | test_get->succeeded = GNUNET_YES; |
407 | GNUNET_SCHEDULER_cancel (test_get->disconnect_task); | 431 | GNUNET_SCHEDULER_cancel (test_get->task); |
408 | test_get->disconnect_task = GNUNET_SCHEDULER_add_now (&get_stop_task, test_get); | 432 | test_get->task = GNUNET_SCHEDULER_add_now (&get_stop_task, test_get); |
409 | } | 433 | } |
410 | 434 | ||
411 | 435 | ||
@@ -419,35 +443,44 @@ do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
419 | GNUNET_HashCode key; /* Made up key to store data under */ | 443 | GNUNET_HashCode key; /* Made up key to store data under */ |
420 | char data[TEST_DATA_SIZE]; /* Made up data to store */ | 444 | char data[TEST_DATA_SIZE]; /* Made up data to store */ |
421 | 445 | ||
422 | if (test_get == NULL) | ||
423 | return; /* End of the list */ | ||
424 | memset (data, test_get->uid, sizeof (data)); | ||
425 | GNUNET_CRYPTO_hash (data, TEST_DATA_SIZE, &key); | ||
426 | |||
427 | if (outstanding_gets > MAX_OUTSTANDING_GETS) | 446 | if (outstanding_gets > MAX_OUTSTANDING_GETS) |
428 | { | 447 | { |
429 | GNUNET_SCHEDULER_add_delayed (GET_DELAY, &do_get, test_get); | 448 | GNUNET_SCHEDULER_add_delayed (GET_DELAY, &do_get, test_get); |
430 | return; | 449 | return; |
431 | } | 450 | } |
432 | 451 | memset (data, test_get->uid, sizeof (data)); | |
452 | GNUNET_CRYPTO_hash (data, TEST_DATA_SIZE, &key); | ||
433 | test_get->dht_handle = GNUNET_DHT_connect (test_get->daemon->cfg, 10); | 453 | test_get->dht_handle = GNUNET_DHT_connect (test_get->daemon->cfg, 10); |
434 | /* Insert the data at the first peer */ | ||
435 | GNUNET_assert (test_get->dht_handle != NULL); | 454 | GNUNET_assert (test_get->dht_handle != NULL); |
436 | outstanding_gets++; | 455 | outstanding_gets++; |
437 | test_get->get_handle = | 456 | test_get->get_handle = |
438 | GNUNET_DHT_get_start (test_get->dht_handle, GNUNET_TIME_UNIT_FOREVER_REL, | 457 | GNUNET_DHT_get_start (test_get->dht_handle, GNUNET_TIME_UNIT_FOREVER_REL, |
439 | GNUNET_BLOCK_TYPE_TEST, &key, | 458 | GNUNET_BLOCK_TYPE_TEST, &key, |
440 | 1, route_option, NULL, 0, | 459 | 1, route_option, NULL, 0, |
441 | &get_result_iterator, test_get); | 460 | &get_result_iterator, test_get); |
442 | #if VERBOSE | 461 | test_get->task = |
443 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting get for uid %u from peer %s\n", | 462 | GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &get_stop_task, test_get); |
444 | test_get->uid, test_get->daemon->shortname); | 463 | } |
445 | #endif | 464 | |
446 | test_get->disconnect_task = | 465 | |
447 | GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &get_stop_task, test_get); | 466 | /** |
448 | GNUNET_SCHEDULER_add_now (&do_get, test_get->next); | 467 | * Task to release DHT handles for PUT |
468 | */ | ||
469 | static void | ||
470 | put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
471 | { | ||
472 | struct TestPutContext *test_put = cls; | ||
473 | |||
474 | test_put->task = GNUNET_SCHEDULER_NO_TASK; | ||
475 | GNUNET_DHT_disconnect (test_put->dht_handle); | ||
476 | test_put->dht_handle = NULL; | ||
477 | GNUNET_CONTAINER_DLL_remove (all_puts_head, | ||
478 | all_puts_tail, | ||
479 | test_put); | ||
480 | GNUNET_free (test_put); | ||
449 | } | 481 | } |
450 | 482 | ||
483 | |||
451 | /** | 484 | /** |
452 | * Called when the PUT request has been transmitted to the DHT service. | 485 | * Called when the PUT request has been transmitted to the DHT service. |
453 | * Schedule the GET request for some time in the future. | 486 | * Schedule the GET request for some time in the future. |
@@ -456,23 +489,37 @@ static void | |||
456 | put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 489 | put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
457 | { | 490 | { |
458 | struct TestPutContext *test_put = cls; | 491 | struct TestPutContext *test_put = cls; |
492 | unsigned long long i; | ||
493 | unsigned long long j; | ||
494 | struct TestGetContext *test_get; | ||
459 | 495 | ||
460 | outstanding_puts--; | 496 | outstanding_puts--; |
461 | puts_completed++; | 497 | puts_completed++; |
462 | 498 | GNUNET_SCHEDULER_cancel (test_put->task); | |
463 | GNUNET_SCHEDULER_cancel (test_put->disconnect_task); | 499 | test_put->task = |
464 | test_put->disconnect_task = | ||
465 | GNUNET_SCHEDULER_add_now (&put_disconnect_task, test_put); | 500 | GNUNET_SCHEDULER_add_now (&put_disconnect_task, test_put); |
466 | if (puts_completed == num_peers) | 501 | if (puts_completed != num_peers) |
467 | { | ||
468 | GNUNET_assert (outstanding_puts == 0); | ||
469 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
470 | (GNUNET_TIME_UNIT_SECONDS, 10), &do_get, | ||
471 | all_gets); | ||
472 | return; | 502 | return; |
473 | } | 503 | |
504 | GNUNET_assert (outstanding_puts == 0); | ||
505 | fprintf (stderr, | ||
506 | "Issuing %llu GETs\n", | ||
507 | num_peers * num_peers); | ||
508 | for (i = 0; i < num_peers; i++) | ||
509 | for (j = 0; j < num_peers; j++) | ||
510 | { | ||
511 | test_get = GNUNET_malloc (sizeof (struct TestGetContext)); | ||
512 | test_get->uid = i; | ||
513 | test_get->daemon = GNUNET_TESTING_daemon_get (pg, j); | ||
514 | GNUNET_CONTAINER_DLL_insert (all_gets_head, | ||
515 | all_gets_tail, | ||
516 | test_get); | ||
517 | test_get->task = GNUNET_SCHEDULER_add_now (&do_get, | ||
518 | test_get); | ||
519 | } | ||
474 | } | 520 | } |
475 | 521 | ||
522 | |||
476 | /** | 523 | /** |
477 | * Set up some data, and call API PUT function | 524 | * Set up some data, and call API PUT function |
478 | */ | 525 | */ |
@@ -483,24 +530,15 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
483 | GNUNET_HashCode key; /* Made up key to store data under */ | 530 | GNUNET_HashCode key; /* Made up key to store data under */ |
484 | char data[TEST_DATA_SIZE]; /* Made up data to store */ | 531 | char data[TEST_DATA_SIZE]; /* Made up data to store */ |
485 | 532 | ||
486 | if (test_put == NULL) | 533 | test_put->task = GNUNET_SCHEDULER_NO_TASK; |
487 | return; /* End of list */ | ||
488 | |||
489 | memset (data, test_put->uid, sizeof (data)); | ||
490 | GNUNET_CRYPTO_hash (data, TEST_DATA_SIZE, &key); | ||
491 | |||
492 | if (outstanding_puts > MAX_OUTSTANDING_PUTS) | 534 | if (outstanding_puts > MAX_OUTSTANDING_PUTS) |
493 | { | 535 | { |
494 | GNUNET_SCHEDULER_add_delayed (PUT_DELAY, &do_put, test_put); | 536 | test_put->task = GNUNET_SCHEDULER_add_delayed (PUT_DELAY, &do_put, test_put); |
495 | return; | 537 | return; |
496 | } | 538 | } |
497 | 539 | memset (data, test_put->uid, sizeof (data)); | |
498 | #if VERBOSE | 540 | GNUNET_CRYPTO_hash (data, TEST_DATA_SIZE, &key); |
499 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting put for uid %u from peer %s\n", | ||
500 | test_put->uid, test_put->daemon->shortname); | ||
501 | #endif | ||
502 | test_put->dht_handle = GNUNET_DHT_connect (test_put->daemon->cfg, 10); | 541 | test_put->dht_handle = GNUNET_DHT_connect (test_put->daemon->cfg, 10); |
503 | |||
504 | GNUNET_assert (test_put->dht_handle != NULL); | 542 | GNUNET_assert (test_put->dht_handle != NULL); |
505 | outstanding_puts++; | 543 | outstanding_puts++; |
506 | fprintf (stderr, "PUT %u at `%s'\n", | 544 | fprintf (stderr, "PUT %u at `%s'\n", |
@@ -510,10 +548,9 @@ do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
510 | route_option, GNUNET_BLOCK_TYPE_TEST, sizeof (data), data, | 548 | route_option, GNUNET_BLOCK_TYPE_TEST, sizeof (data), data, |
511 | GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL, | 549 | GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL, |
512 | &put_finished, test_put); | 550 | &put_finished, test_put); |
513 | test_put->disconnect_task = | 551 | test_put->task = |
514 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 552 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
515 | &put_disconnect_task, test_put); | 553 | &put_disconnect_task, test_put); |
516 | GNUNET_SCHEDULER_add_now (&do_put, test_put->next); | ||
517 | } | 554 | } |
518 | 555 | ||
519 | 556 | ||
@@ -529,9 +566,7 @@ static void | |||
529 | run_dht_test (void *cls, const char *emsg) | 566 | run_dht_test (void *cls, const char *emsg) |
530 | { | 567 | { |
531 | unsigned long long i; | 568 | unsigned long long i; |
532 | unsigned long long j; | ||
533 | struct TestPutContext *test_put; | 569 | struct TestPutContext *test_put; |
534 | struct TestGetContext *test_get; | ||
535 | 570 | ||
536 | if (emsg != NULL) | 571 | if (emsg != NULL) |
537 | { | 572 | { |
@@ -560,23 +595,11 @@ run_dht_test (void *cls, const char *emsg) | |||
560 | test_put = GNUNET_malloc (sizeof (struct TestPutContext)); | 595 | test_put = GNUNET_malloc (sizeof (struct TestPutContext)); |
561 | test_put->uid = i; | 596 | test_put->uid = i; |
562 | test_put->daemon = GNUNET_TESTING_daemon_get (pg, i); | 597 | test_put->daemon = GNUNET_TESTING_daemon_get (pg, i); |
563 | test_put->next = all_puts; | 598 | test_put->task = GNUNET_SCHEDULER_add_now (&do_put, test_put); |
564 | all_puts = test_put; | 599 | GNUNET_CONTAINER_DLL_insert (all_puts_head, |
600 | all_puts_tail, | ||
601 | test_put); | ||
565 | } | 602 | } |
566 | GNUNET_SCHEDULER_add_now (&do_put, all_puts); | ||
567 | |||
568 | fprintf (stderr, | ||
569 | "Issuing %llu GETs\n", | ||
570 | num_peers * num_peers); | ||
571 | for (i = 0; i < num_peers; i++) | ||
572 | for (j = 0; j < num_peers; j++) | ||
573 | { | ||
574 | test_get = GNUNET_malloc (sizeof (struct TestGetContext)); | ||
575 | test_get->uid = i; | ||
576 | test_get->daemon = GNUNET_TESTING_daemon_get (pg, j); | ||
577 | test_get->next = all_gets; | ||
578 | all_gets = test_get; | ||
579 | } | ||
580 | } | 603 | } |
581 | 604 | ||
582 | 605 | ||
@@ -604,11 +627,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
604 | &run_dht_test, | 627 | &run_dht_test, |
605 | NULL, | 628 | NULL, |
606 | NULL); | 629 | NULL); |
607 | if (NULL == pg) | 630 | GNUNET_assert (NULL != pg); |
608 | { | ||
609 | GNUNET_break (0); | ||
610 | return; | ||
611 | } | ||
612 | } | 631 | } |
613 | 632 | ||
614 | 633 | ||
diff --git a/src/dht/test_dht_multipeer_data.conf b/src/dht/test_dht_multipeer_data.conf index f5ffa6a0b..2b4569881 100644 --- a/src/dht/test_dht_multipeer_data.conf +++ b/src/dht/test_dht_multipeer_data.conf | |||
@@ -81,7 +81,12 @@ NUM_PUTS = 5 | |||
81 | 81 | ||
82 | [TESTING] | 82 | [TESTING] |
83 | TOPOLOGY = FROM_FILE | 83 | TOPOLOGY = FROM_FILE |
84 | # file contains a ring | ||
84 | CONNECT_TOPOLOGY = NONE | 85 | CONNECT_TOPOLOGY = NONE |
86 | # None == use all allowed connections | ||
87 | # BLACKLIST_TOPOLOGY = X | ||
88 | # No additional restrictions... | ||
89 | |||
85 | TOPOLOGY_FILE = multipeer_topo.dat | 90 | TOPOLOGY_FILE = multipeer_topo.dat |
86 | MAX_CONCURRENT_SSH = 1 | 91 | MAX_CONCURRENT_SSH = 1 |
87 | PEERGROUP_TIMEOUT = 10000 | 92 | PEERGROUP_TIMEOUT = 10000 |