aboutsummaryrefslogtreecommitdiff
path: root/src/dht/test_dht_2dtorus.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/test_dht_2dtorus.c')
-rw-r--r--src/dht/test_dht_2dtorus.c208
1 files changed, 88 insertions, 120 deletions
diff --git a/src/dht/test_dht_2dtorus.c b/src/dht/test_dht_2dtorus.c
index 220554e15..1db351841 100644
--- a/src/dht/test_dht_2dtorus.c
+++ b/src/dht/test_dht_2dtorus.c
@@ -138,7 +138,8 @@ shutdown_callback (void *cls, const char *emsg)
138 else 138 else
139 { 139 {
140#if VERBOSE 140#if VERBOSE
141 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: All peers successfully shut down!\n"); 141 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
142 "test: All peers successfully shut down!\n");
142#endif 143#endif
143 } 144 }
144} 145}
@@ -169,22 +170,21 @@ disconnect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
169{ 170{
170 unsigned int i; 171 unsigned int i;
171 172
172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: disconnecting peers\n");
173 "test: disconnecting peers\n");
174 disconnect_task = GNUNET_SCHEDULER_NO_TASK; 174 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
175 GNUNET_SCHEDULER_cancel (put_task); 175 GNUNET_SCHEDULER_cancel (put_task);
176 if (NULL != get_h) 176 if (NULL != get_h)
177 GNUNET_DHT_get_stop(get_h); 177 GNUNET_DHT_get_stop (get_h);
178 if (NULL != get_h_2) 178 if (NULL != get_h_2)
179 GNUNET_DHT_get_stop(get_h_2); 179 GNUNET_DHT_get_stop (get_h_2);
180 if (NULL != get_h_far) 180 if (NULL != get_h_far)
181 GNUNET_DHT_get_stop(get_h_far); 181 GNUNET_DHT_get_stop (get_h_far);
182 for (i = 0; i < num_peers; i++) 182 for (i = 0; i < num_peers; i++)
183 { 183 {
184 GNUNET_DHT_disconnect(hs[i]); 184 GNUNET_DHT_disconnect (hs[i]);
185 } 185 }
186 GNUNET_SCHEDULER_cancel (shutdown_handle); 186 GNUNET_SCHEDULER_cancel (shutdown_handle);
187 shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); 187 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
188} 188}
189 189
190static void 190static void
@@ -193,44 +193,39 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
193 const struct GNUNET_PeerIdentity *get_path, 193 const struct GNUNET_PeerIdentity *get_path,
194 unsigned int get_path_length, 194 unsigned int get_path_length,
195 const struct GNUNET_PeerIdentity *put_path, 195 const struct GNUNET_PeerIdentity *put_path,
196 unsigned int put_path_length, 196 unsigned int put_path_length, enum GNUNET_BLOCK_Type type,
197 enum GNUNET_BLOCK_Type type, size_t size, const void *data) 197 size_t size, const void *data)
198{ 198{
199 int i; 199 int i;
200 200
201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
202 "test: ************* FOUND!!! ***********\n"); 202 "test: ************* FOUND!!! ***********\n");
203 if (sizeof(GNUNET_HashCode) == size) 203 if (sizeof (GNUNET_HashCode) == size)
204 { 204 {
205 const GNUNET_HashCode *h = data; 205 const GNUNET_HashCode *h = data;
206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 206
207 "test: Contents: %s\n", 207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Contents: %s\n",
208 GNUNET_h2s_full (h)); 208 GNUNET_h2s_full (h));
209 209
210 } 210 }
211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: PATH: (get %u, put %u)\n",
212 "test: PATH: (get %u, put %u)\n", 212 get_path_length, put_path_length);
213 get_path_length, 213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: LOCAL\n");
214 put_path_length);
215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
216 "test: LOCAL\n");
217 for (i = get_path_length - 1; i >= 0; i--) 214 for (i = get_path_length - 1; i >= 0; i--)
218 { 215 {
219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %s\n",
220 "test: %s\n", 217 GNUNET_i2s (&get_path[i]));
221 GNUNET_i2s (&get_path[i]));
222 } 218 }
223 for (i = put_path_length - 1; i >= 0; i--) 219 for (i = put_path_length - 1; i >= 0; i--)
224 { 220 {
225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %s\n",
226 "test: %s\n", 222 GNUNET_i2s (&put_path[i]));
227 GNUNET_i2s (&put_path[i]));
228 } 223 }
229 found++; 224 found++;
230 if (found < 3) 225 if (found < 3)
231 return; 226 return;
232 ok = 0; 227 ok = 0;
233 GNUNET_SCHEDULER_cancel(disconnect_task); 228 GNUNET_SCHEDULER_cancel (disconnect_task);
234 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL); 229 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL);
235} 230}
236 231
@@ -263,7 +258,7 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
263 if (strcmp (id_aux, id_near2) == 0) 258 if (strcmp (id_aux, id_near2) == 0)
264 d2 = aux; 259 d2 = aux;
265 } 260 }
266 if ( (NULL == o) || (NULL == d) || (NULL == d2) || (NULL == d_far)) 261 if ((NULL == o) || (NULL == d) || (NULL == d2) || (NULL == d_far))
267 { 262 {
268 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 263 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
269 "test: Peers not found (hostkey file changed?)\n"); 264 "test: Peers not found (hostkey file changed?)\n");
@@ -272,55 +267,39 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
272 return; 267 return;
273 } 268 }
274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n"); 269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n");
275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n",
276 "test: looking for %s\n",
277 GNUNET_h2s_full (&d->id.hashPubKey)); 271 GNUNET_h2s_full (&d->id.hashPubKey));
278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n",
279 "test: looking for %s\n",
280 GNUNET_h2s_full (&d2->id.hashPubKey)); 273 GNUNET_h2s_full (&d2->id.hashPubKey));
281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n",
282 "test: looking for %s\n",
283 GNUNET_h2s_full (&d_far->id.hashPubKey)); 275 GNUNET_h2s_full (&d_far->id.hashPubKey));
284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 276 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: from %s\n",
285 "test: from %s\n",
286 GNUNET_h2s_full (&o->id.hashPubKey)); 277 GNUNET_h2s_full (&o->id.hashPubKey));
287 found = 0; 278 found = 0;
288 get_h = GNUNET_DHT_get_start (hs[0], 279 get_h = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
289 GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ 280 GNUNET_BLOCK_TYPE_TEST, /* type */
290 GNUNET_BLOCK_TYPE_TEST, /* type */ 281 &d->id.hashPubKey, /*key to search */
291 &d->id.hashPubKey, /*key to search */ 282 4U, /* replication level */
292 4U, /* replication level */ 283 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */
293 GNUNET_DHT_RO_RECORD_ROUTE | 284 0, /* xquery bits */
294 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 285 &dht_get_id_handler, NULL);
295 NULL, /* xquery */ 286 get_h_2 = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
296 0, /* xquery bits */ 287 GNUNET_BLOCK_TYPE_TEST, /* type */
297 &dht_get_id_handler,
298 NULL);
299 get_h_2 = GNUNET_DHT_get_start (hs[0],
300 GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
301 GNUNET_BLOCK_TYPE_TEST, /* type */
302 &d2->id.hashPubKey, /*key to search */ 288 &d2->id.hashPubKey, /*key to search */
303 4U, /* replication level */ 289 4U, /* replication level */
304 GNUNET_DHT_RO_RECORD_ROUTE | 290 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */
305 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 291 0, /* xquery bits */
306 NULL, /* xquery */ 292 &dht_get_id_handler, NULL);
307 0, /* xquery bits */ 293 get_h_far = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
308 &dht_get_id_handler, 294 GNUNET_BLOCK_TYPE_TEST, /* type */
309 NULL); 295 &d_far->id.hashPubKey, /*key to search */
310 get_h_far = GNUNET_DHT_get_start (hs[0], 296 4U, /* replication level */
311 GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ 297 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */
312 GNUNET_BLOCK_TYPE_TEST, /* type */ 298 0, /* xquery bits */
313 &d_far->id.hashPubKey, /*key to search */ 299 &dht_get_id_handler, NULL);
314 4U, /* replication level */
315 GNUNET_DHT_RO_RECORD_ROUTE |
316 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
317 NULL, /* xquery */
318 0, /* xquery bits */
319 &dht_get_id_handler,
320 NULL);
321 GNUNET_SCHEDULER_cancel (disconnect_task); 300 GNUNET_SCHEDULER_cancel (disconnect_task);
322 disconnect_task = GNUNET_SCHEDULER_add_delayed(GET_TIMEOUT, 301 disconnect_task =
323 &disconnect_peers, NULL); 302 GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL);
324} 303}
325 304
326 305
@@ -331,28 +310,20 @@ put_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
331 unsigned int i; 310 unsigned int i;
332 311
333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: putting id's in DHT\n"); 312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: putting id's in DHT\n");
334 for (i = 0; i < num_peers; i++) 313 for (i = 0; i < num_peers; i++)
335 { 314 {
336 d = GNUNET_TESTING_daemon_get (pg, i); 315 d = GNUNET_TESTING_daemon_get (pg, i);
337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 316 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: putting into DHT: %s\n",
338 "test: putting into DHT: %s\n",
339 GNUNET_h2s_full (&d->id.hashPubKey)); 317 GNUNET_h2s_full (&d->id.hashPubKey));
340 GNUNET_DHT_put(hs[i], 318 GNUNET_DHT_put (hs[i], &d->id.hashPubKey, 10U,
341 &d->id.hashPubKey, 319 GNUNET_DHT_RO_RECORD_ROUTE |
342 10U, 320 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
343 GNUNET_DHT_RO_RECORD_ROUTE | 321 GNUNET_BLOCK_TYPE_TEST, sizeof (struct GNUNET_PeerIdentity),
344 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 322 (const char *) &d->id, GNUNET_TIME_UNIT_FOREVER_ABS,
345 GNUNET_BLOCK_TYPE_TEST, 323 GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL);
346 sizeof(struct GNUNET_PeerIdentity),
347 (const char *) &d->id,
348 GNUNET_TIME_UNIT_FOREVER_ABS,
349 GNUNET_TIME_UNIT_FOREVER_REL,
350 NULL,
351 NULL);
352 324
353 } 325 }
354 put_task = GNUNET_SCHEDULER_add_delayed(PUT_FREQUENCY, 326 put_task = GNUNET_SCHEDULER_add_delayed (PUT_FREQUENCY, &put_id, NULL);
355 &put_id, NULL);
356} 327}
357 328
358 329
@@ -373,8 +344,8 @@ peergroup_ready (void *cls, const char *emsg)
373 { 344 {
374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
375 "test: Peergroup callback called with error, aborting test!\n"); 346 "test: Peergroup callback called with error, aborting test!\n");
376 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 347 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Error from testing: `%s'\n",
377 "test: Error from testing: `%s'\n", emsg); 348 emsg);
378 ok++; 349 ok++;
379 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 350 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
380 return; 351 return;
@@ -384,8 +355,7 @@ peergroup_ready (void *cls, const char *emsg)
384 "************************************************************\n"); 355 "************************************************************\n");
385 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
386 "test: Peer Group started successfully!\n"); 357 "test: Peer Group started successfully!\n");
387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Have %u connections\n",
388 "test: Have %u connections\n",
389 total_connections); 359 total_connections);
390#endif 360#endif
391 361
@@ -398,24 +368,22 @@ peergroup_ready (void *cls, const char *emsg)
398 GNUNET_free (buf); 368 GNUNET_free (buf);
399 } 369 }
400 peers_running = GNUNET_TESTING_daemons_running (pg); 370 peers_running = GNUNET_TESTING_daemons_running (pg);
401 371
402 GNUNET_assert (peers_running == num_peers); 372 GNUNET_assert (peers_running == num_peers);
403 hs = GNUNET_malloc (num_peers * sizeof(struct GNUNET_DHT_Handle *)); 373 hs = GNUNET_malloc (num_peers * sizeof (struct GNUNET_DHT_Handle *));
404 for (i = 0; i < num_peers; i++) 374 for (i = 0; i < num_peers; i++)
405 { 375 {
406 d = GNUNET_TESTING_daemon_get (pg, i); 376 d = GNUNET_TESTING_daemon_get (pg, i);
407 hs[i] = GNUNET_DHT_connect(d->cfg, 32); 377 hs[i] = GNUNET_DHT_connect (d->cfg, 32);
408 } 378 }
409 379
410 put_task = GNUNET_SCHEDULER_add_now(&put_id, NULL); 380 put_task = GNUNET_SCHEDULER_add_now (&put_id, NULL);
411 test_task = 381 test_task =
412 GNUNET_SCHEDULER_add_delayed( 382 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
413 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), 383 (GNUNET_TIME_UNIT_SECONDS, 2), &do_test,
414 &do_test, NULL);
415 disconnect_task =
416 GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT,
417 &disconnect_peers,
418 NULL); 384 NULL);
385 disconnect_task =
386 GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL);
419 387
420} 388}
421 389
@@ -446,14 +414,13 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
446 if (emsg == NULL) 414 if (emsg == NULL)
447 { 415 {
448 total_connections++; 416 total_connections++;
449 GNUNET_PEER_intern(first); 417 GNUNET_PEER_intern (first);
450 GNUNET_PEER_intern(second); 418 GNUNET_PEER_intern (second);
451 } 419 }
452 else 420 else
453 { 421 {
454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
455 "test: Problem with new connection (%s)\n", 423 "test: Problem with new connection (%s)\n", emsg);
456 emsg);
457 } 424 }
458 425
459} 426}
@@ -496,7 +463,7 @@ run (void *cls, char *const *args, const char *cfgfile,
496 "num_peers", &num_peers)) 463 "num_peers", &num_peers))
497 { 464 {
498 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 465 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
499 "Option TESTING:NUM_PEERS is required!\n"); 466 "Option TESTING:NUM_PEERS is required!\n");
500 return; 467 return;
501 } 468 }
502 469
@@ -516,17 +483,17 @@ run (void *cls, char *const *args, const char *cfgfile,
516 &data_filename)) 483 &data_filename))
517 { 484 {
518 data_file = 485 data_file =
519 GNUNET_DISK_file_open (data_filename, 486 GNUNET_DISK_file_open (data_filename,
520 GNUNET_DISK_OPEN_READWRITE | 487 GNUNET_DISK_OPEN_READWRITE |
521 GNUNET_DISK_OPEN_CREATE, 488 GNUNET_DISK_OPEN_CREATE,
522 GNUNET_DISK_PERM_USER_READ | 489 GNUNET_DISK_PERM_USER_READ |
523 GNUNET_DISK_PERM_USER_WRITE); 490 GNUNET_DISK_PERM_USER_WRITE);
524 if (data_file == NULL) 491 if (data_file == NULL)
525 { 492 {
526 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", 493 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
527 data_filename); 494 data_filename);
528 GNUNET_free (data_filename); 495 GNUNET_free (data_filename);
529 } 496 }
530 } 497 }
531 498
532 if (GNUNET_YES == 499 if (GNUNET_YES ==
@@ -552,7 +519,7 @@ run (void *cls, char *const *args, const char *cfgfile,
552 hosts); 519 hosts);
553 GNUNET_assert (pg != NULL); 520 GNUNET_assert (pg != NULL);
554 shutdown_handle = 521 shutdown_handle =
555 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 522 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
556 &shutdown_task, NULL); 523 &shutdown_task, NULL);
557} 524}
558 525
@@ -584,7 +551,8 @@ main (int xargc, char *xargv[])
584 NULL 551 NULL
585 }; 552 };
586 553
587 GNUNET_PROGRAM_run (sizeof(argv)/sizeof(char*) - 1, argv, "test_dht_2dtorus", 554 GNUNET_PROGRAM_run (sizeof (argv) / sizeof (char *) - 1, argv,
555 "test_dht_2dtorus",
588 gettext_noop ("Test dht in a small 2D torus."), options, 556 gettext_noop ("Test dht in a small 2D torus."), options,
589 &run, NULL); 557 &run, NULL);
590#if REMOVE_DIR 558#if REMOVE_DIR