aboutsummaryrefslogtreecommitdiff
path: root/src/dht/test_dht_topo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/test_dht_topo.c')
-rw-r--r--src/dht/test_dht_topo.c98
1 files changed, 65 insertions, 33 deletions
diff --git a/src/dht/test_dht_topo.c b/src/dht/test_dht_topo.c
index fec3ec16d..81dc7cb85 100644
--- a/src/dht/test_dht_topo.c
+++ b/src/dht/test_dht_topo.c
@@ -128,7 +128,9 @@ struct GNUNET_DHT_GetHandle *get_h_2;
128 128
129struct GNUNET_DHT_GetHandle *get_h_far; 129struct GNUNET_DHT_GetHandle *get_h_far;
130 130
131unsigned int found; 131int found_1;
132int found_2;
133int found_far;
132 134
133/** 135/**
134 * Which topology are we to run 136 * Which topology are we to run
@@ -144,7 +146,7 @@ shutdown_callback (void *cls, const char *emsg)
144 if (emsg != NULL) 146 if (emsg != NULL)
145 { 147 {
146#if VERBOSE 148#if VERBOSE
147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Shutdown of peers failed!\n"); 149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
148#endif 150#endif
149 ok++; 151 ok++;
150 } 152 }
@@ -152,7 +154,7 @@ shutdown_callback (void *cls, const char *emsg)
152 { 154 {
153#if VERBOSE 155#if VERBOSE
154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
155 "test: All peers successfully shut down!\n"); 157 "All peers successfully shut down!\n");
156#endif 158#endif
157 } 159 }
158 GNUNET_CONFIGURATION_destroy (testing_cfg); 160 GNUNET_CONFIGURATION_destroy (testing_cfg);
@@ -163,7 +165,7 @@ static void
163shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 165shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
164{ 166{
165#if VERBOSE 167#if VERBOSE
166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Ending test.\n"); 168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n");
167#endif 169#endif
168 170
169 if (disconnect_task != GNUNET_SCHEDULER_NO_TASK) 171 if (disconnect_task != GNUNET_SCHEDULER_NO_TASK)
@@ -183,7 +185,7 @@ disconnect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
183{ 185{
184 unsigned int i; 186 unsigned int i;
185 187
186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: disconnecting peers\n"); 188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "disconnecting peers\n");
187 disconnect_task = GNUNET_SCHEDULER_NO_TASK; 189 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
188 GNUNET_SCHEDULER_cancel (put_task); 190 GNUNET_SCHEDULER_cancel (put_task);
189 if (NULL != get_h) 191 if (NULL != get_h)
@@ -211,31 +213,50 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp,
211{ 213{
212 int i; 214 int i;
213 215
214 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
215 "test: ************* FOUND!!! ***********\n");
216 if (sizeof (GNUNET_HashCode) == size) 216 if (sizeof (GNUNET_HashCode) == size)
217 { 217 {
218 const GNUNET_HashCode *h = data; 218 const GNUNET_HashCode *h = data;
219 219
220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Contents: %s\n", 220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Contents: %s\n",
221 GNUNET_h2s_full (h)); 221 GNUNET_h2s_full (h));
222 222
223 } 223 }
224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: PATH: (get %u, put %u)\n", 224 else
225 {
226 GNUNET_break(0);
227 }
228 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "PATH: (get %u, put %u)\n",
225 get_path_length, put_path_length); 229 get_path_length, put_path_length);
226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: LOCAL\n"); 230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " LOCAL\n");
227 for (i = get_path_length - 1; i >= 0; i--) 231 for (i = get_path_length - 1; i >= 0; i--)
228 { 232 {
229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %s\n", 233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %s\n",
230 GNUNET_i2s (&get_path[i])); 234 GNUNET_i2s (&get_path[i]));
231 } 235 }
232 for (i = put_path_length - 1; i >= 0; i--) 236 for (i = put_path_length - 1; i >= 0; i--)
233 { 237 {
234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %s\n", 238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %s\n",
235 GNUNET_i2s (&put_path[i])); 239 GNUNET_i2s (&put_path[i]));
236 } 240 }
237 found++; 241 switch ((long)cls)
238 if (TORUS == test_topology && found < 3) 242 {
243 case 1:
244 found_1++;
245 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "FOUND 1!\n");
246 break;
247 case 2:
248 found_2++;
249 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "FOUND 2!\n");
250 break;
251 case 3:
252 found_far++;
253 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "FOUND FAR!\n");
254 break;
255 default:
256 GNUNET_break(0);
257 }
258 if (TORUS == test_topology &&
259 (found_1 == 0 || found_2 == 0 || found_far == 0))
239 return; 260 return;
240 ok = 0; 261 ok = 0;
241 GNUNET_SCHEDULER_cancel (disconnect_task); 262 GNUNET_SCHEDULER_cancel (disconnect_task);
@@ -258,6 +279,7 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
258 unsigned int i; 279 unsigned int i;
259 280
260 d = d2 = d_far = o = NULL; 281 d = d2 = d_far = o = NULL;
282 found_1 = found_2 = found_far = 0;
261 if (LINE == test_topology) 283 if (LINE == test_topology)
262 { 284 {
263 o = GNUNET_TESTING_daemon_get (pg, 0); 285 o = GNUNET_TESTING_daemon_get (pg, 0);
@@ -281,7 +303,7 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
281 if ((NULL == o) || (NULL == d) || (NULL == d2) || (NULL == d_far)) 303 if ((NULL == o) || (NULL == d) || (NULL == d2) || (NULL == d_far))
282 { 304 {
283 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 305 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
284 "test: Peers not found (hostkey file changed?)\n"); 306 "Peers not found (hostkey file changed?)\n");
285 GNUNET_SCHEDULER_cancel (disconnect_task); 307 GNUNET_SCHEDULER_cancel (disconnect_task);
286 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL); 308 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL);
287 return; 309 return;
@@ -291,21 +313,20 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
291 { 313 {
292 GNUNET_assert (0); 314 GNUNET_assert (0);
293 } 315 }
294 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\ntest: from %s\n", 316 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test_task\ntest: from %s\n",
295 GNUNET_h2s_full (&o->id.hashPubKey)); 317 GNUNET_h2s_full (&o->id.hashPubKey));
296 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", 318 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " looking for %s\n",
297 GNUNET_h2s_full (&d->id.hashPubKey)); 319 GNUNET_h2s_full (&d->id.hashPubKey));
298 found = 0;
299 get_h = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ 320 get_h = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
300 GNUNET_BLOCK_TYPE_TEST, /* type */ 321 GNUNET_BLOCK_TYPE_TEST, /* type */
301 &d->id.hashPubKey, /*key to search */ 322 &d->id.hashPubKey, /*key to search */
302 4U, /* replication level */ 323 4U, /* replication level */
303 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ 324 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */
304 0, /* xquery bits */ 325 0, /* xquery bits */
305 &dht_get_id_handler, NULL); 326 &dht_get_id_handler, (void *)1);
306 if (TORUS == test_topology) 327 if (TORUS == test_topology)
307 { 328 {
308 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", 329 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " looking for %s\n",
309 GNUNET_h2s_full (&d2->id.hashPubKey)); 330 GNUNET_h2s_full (&d2->id.hashPubKey));
310 get_h_2 = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ 331 get_h_2 = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
311 GNUNET_BLOCK_TYPE_TEST, /* type */ 332 GNUNET_BLOCK_TYPE_TEST, /* type */
@@ -313,8 +334,8 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
313 4U, /* replication level */ 334 4U, /* replication level */
314 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ 335 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */
315 0, /* xquery bits */ 336 0, /* xquery bits */
316 &dht_get_id_handler, NULL); 337 &dht_get_id_handler, (void *)2);
317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", 338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " looking for %s\n",
318 GNUNET_h2s_full (&d_far->id.hashPubKey)); 339 GNUNET_h2s_full (&d_far->id.hashPubKey));
319 get_h_far = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ 340 get_h_far = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */
320 GNUNET_BLOCK_TYPE_TEST, /* type */ 341 GNUNET_BLOCK_TYPE_TEST, /* type */
@@ -322,7 +343,7 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
322 4U, /* replication level */ 343 4U, /* replication level */
323 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ 344 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */
324 0, /* xquery bits */ 345 0, /* xquery bits */
325 &dht_get_id_handler, NULL); 346 &dht_get_id_handler, (void *)3);
326 } 347 }
327 GNUNET_SCHEDULER_cancel (disconnect_task); 348 GNUNET_SCHEDULER_cancel (disconnect_task);
328 disconnect_task = 349 disconnect_task =
@@ -342,11 +363,11 @@ put_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
342 struct GNUNET_TESTING_Daemon *d; 363 struct GNUNET_TESTING_Daemon *d;
343 unsigned int i; 364 unsigned int i;
344 365
345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: putting id's in DHT\n"); 366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "putting id's in DHT\n");
346 for (i = 0; i < num_peers; i++) 367 for (i = 0; i < num_peers; i++)
347 { 368 {
348 d = GNUNET_TESTING_daemon_get (pg, i); 369 d = GNUNET_TESTING_daemon_get (pg, i);
349 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: putting into DHT: %s\n", 370 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " putting into DHT: %s\n",
350 GNUNET_h2s_full (&d->id.hashPubKey)); 371 GNUNET_h2s_full (&d->id.hashPubKey));
351 GNUNET_DHT_put (hs[i], &d->id.hashPubKey, 10U, 372 GNUNET_DHT_put (hs[i], &d->id.hashPubKey, 10U,
352 GNUNET_DHT_RO_RECORD_ROUTE | 373 GNUNET_DHT_RO_RECORD_ROUTE |
@@ -380,8 +401,8 @@ peergroup_ready (void *cls, const char *emsg)
380 if (emsg != NULL) 401 if (emsg != NULL)
381 { 402 {
382 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
383 "test: Peergroup callback called with error, aborting test!\n"); 404 "Peergroup callback called with error, aborting test!\n");
384 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Error from testing: `%s'\n", 405 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n",
385 emsg); 406 emsg);
386 ok++; 407 ok++;
387 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 408 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
@@ -391,8 +412,8 @@ peergroup_ready (void *cls, const char *emsg)
391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
392 "************************************************************\n"); 413 "************************************************************\n");
393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 414 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
394 "test: Peer Group started successfully!\n"); 415 "Peer Group started successfully!\n");
395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Have %u connections\n", 416 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Have %u connections\n",
396 total_connections); 417 total_connections);
397#endif 418#endif
398 419
@@ -454,7 +475,7 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
454 else 475 else
455 { 476 {
456 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 477 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
457 "test: Problem with new connection (%s)\n", emsg); 478 "Problem with new connection (%s)\n", emsg);
458 } 479 }
459 480
460} 481}
@@ -487,7 +508,7 @@ run (void *cls, char *const *args, const char *cfgfile,
487 NULL); 508 NULL);
488 509
489#if VERBOSE 510#if VERBOSE
490 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Starting daemons.\n"); 511 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
491 GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing", 512 GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing",
492 "use_progressbars", "YES"); 513 "use_progressbars", "YES");
493#endif 514#endif
@@ -620,9 +641,20 @@ main (int xargc, char *xargv[])
620#if REMOVE_DIR 641#if REMOVE_DIR
621 GNUNET_DISK_directory_remove ("/tmp/test_dht_topo"); 642 GNUNET_DISK_directory_remove ("/tmp/test_dht_topo");
622#endif 643#endif
623 if (0 != ok) 644 if (found_1 == 0)
645 {
646 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "ID 1 not found!\n");
647 }
648 if (TORUS == test_topology)
624 { 649 {
625 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test: FAILED!\n"); 650 if (found_2 == 0)
651 {
652 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "ID 2 not found!\n");
653 }
654 if (found_far == 0)
655 {
656 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "ID far not found!\n");
657 }
626 } 658 }
627 return ok; 659 return ok;
628} 660}