aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/test_mesh_small_unicast_far.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesh/test_mesh_small_unicast_far.c')
-rw-r--r--src/mesh/test_mesh_small_unicast_far.c111
1 files changed, 46 insertions, 65 deletions
diff --git a/src/mesh/test_mesh_small_unicast_far.c b/src/mesh/test_mesh_small_unicast_far.c
index e35922929..cc9995b48 100644
--- a/src/mesh/test_mesh_small_unicast_far.c
+++ b/src/mesh/test_mesh_small_unicast_far.c
@@ -148,7 +148,8 @@ shutdown_callback (void *cls, const char *emsg)
148 else 148 else
149 { 149 {
150#if VERBOSE 150#if VERBOSE
151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: All peers successfully shut down!\n"); 151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
152 "test: All peers successfully shut down!\n");
152#endif 153#endif
153 } 154 }
154} 155}
@@ -189,10 +190,10 @@ disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
190 "test: disconnecting mesh service of peers\n"); 191 "test: disconnecting mesh service of peers\n");
191 disconnect_task = GNUNET_SCHEDULER_NO_TASK; 192 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
192 GNUNET_MESH_disconnect(h1); 193 GNUNET_MESH_disconnect (h1);
193 GNUNET_MESH_disconnect(h2); 194 GNUNET_MESH_disconnect (h2);
194 GNUNET_SCHEDULER_cancel (shutdown_handle); 195 GNUNET_SCHEDULER_cancel (shutdown_handle);
195 shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); 196 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
196} 197}
197 198
198 199
@@ -208,16 +209,14 @@ disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
208 * (can be NULL -- that's not an error) 209 * (can be NULL -- that's not an error)
209 */ 210 */
210static void * 211static void *
211incoming_tunnel (void *cls, 212incoming_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
212 struct GNUNET_MESH_Tunnel * tunnel, 213 const struct GNUNET_PeerIdentity *initiator,
213 const struct GNUNET_PeerIdentity * initiator, 214 const struct GNUNET_ATS_Information *atsi)
214 const struct GNUNET_ATS_Information * atsi)
215{ 215{
216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Incoming tunnel from %s\n",
217 "test: Incoming tunnel from %s\n", 217 GNUNET_i2s (initiator));
218 GNUNET_i2s(initiator));
219 GNUNET_SCHEDULER_cancel (disconnect_task); 218 GNUNET_SCHEDULER_cancel (disconnect_task);
220 disconnect_task = GNUNET_SCHEDULER_add_now(&disconnect_mesh_peers, NULL); 219 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_mesh_peers, NULL);
221 ok = 0; 220 ok = 0;
222 return NULL; 221 return NULL;
223} 222}
@@ -238,7 +237,7 @@ tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
238#if VERBOSE 237#if VERBOSE
239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: tunnel disconnected\n"); 238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: tunnel disconnected\n");
240#endif 239#endif
241 240
242 return; 241 return;
243} 242}
244 243
@@ -251,9 +250,8 @@ tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
251static void 250static void
252dh (void *cls, const struct GNUNET_PeerIdentity *peer) 251dh (void *cls, const struct GNUNET_PeerIdentity *peer)
253{ 252{
254 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: peer %s disconnected\n",
255 "test: peer %s disconnected\n", 254 GNUNET_i2s (peer));
256 GNUNET_i2s(peer));
257 return; 255 return;
258} 256}
259 257
@@ -269,9 +267,8 @@ static void
269ch (void *cls, const struct GNUNET_PeerIdentity *peer, 267ch (void *cls, const struct GNUNET_PeerIdentity *peer,
270 const struct GNUNET_ATS_Information *atsi) 268 const struct GNUNET_ATS_Information *atsi)
271{ 269{
272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: peer %s connected\n",
273 "test: peer %s connected\n", 271 GNUNET_i2s (peer));
274 GNUNET_i2s(peer));
275 return; 272 return;
276} 273}
277 274
@@ -280,11 +277,12 @@ static void
280do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 277do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
281{ 278{
282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n"); 279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n");
283 GNUNET_MESH_peer_request_connect_add(t, &d2->id); 280 GNUNET_MESH_peer_request_connect_add (t, &d2->id);
284 GNUNET_SCHEDULER_cancel (disconnect_task); 281 GNUNET_SCHEDULER_cancel (disconnect_task);
285 disconnect_task = GNUNET_SCHEDULER_add_delayed( 282 disconnect_task =
286 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30), 283 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
287 &disconnect_mesh_peers, NULL); 284 (GNUNET_TIME_UNIT_SECONDS, 30),
285 &disconnect_mesh_peers, NULL);
288} 286}
289 287
290 288
@@ -300,10 +298,9 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
300 298
301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: connect_mesh_service\n"); 299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: connect_mesh_service\n");
302 300
303 GNUNET_PEER_resolve(11, &id); 301 GNUNET_PEER_resolve (11, &id);
304 d2 = GNUNET_TESTING_daemon_get_by_id (pg, &id); 302 d2 = GNUNET_TESTING_daemon_get_by_id (pg, &id);
305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 303 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Peer searched: %s\n",
306 "test: Peer searched: %s\n",
307 GNUNET_i2s (&d2->id)); 304 GNUNET_i2s (&d2->id));
308 app = (GNUNET_MESH_ApplicationType) 0; 305 app = (GNUNET_MESH_ApplicationType) 0;
309 306
@@ -315,20 +312,10 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
315 "test: connecting to mesh service of peer %s\n", 312 "test: connecting to mesh service of peer %s\n",
316 GNUNET_i2s (&d2->id)); 313 GNUNET_i2s (&d2->id));
317#endif 314#endif
318 h1 = GNUNET_MESH_connect (d1->cfg, 315 h1 = GNUNET_MESH_connect (d1->cfg, 10, NULL, NULL, &tunnel_cleaner, handlers,
319 10,
320 NULL,
321 NULL,
322 &tunnel_cleaner,
323 handlers,
324 &app);
325 h2 = GNUNET_MESH_connect (d2->cfg,
326 10,
327 NULL,
328 &incoming_tunnel,
329 &tunnel_cleaner,
330 handlers,
331 &app); 316 &app);
317 h2 = GNUNET_MESH_connect (d2->cfg, 10, NULL, &incoming_tunnel,
318 &tunnel_cleaner, handlers, &app);
332#if VERBOSE 319#if VERBOSE
333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 320 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
334 "test: connected to mesh service of peer %s\n", 321 "test: connected to mesh service of peer %s\n",
@@ -339,9 +326,9 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
339#endif 326#endif
340 t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, NULL); 327 t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, NULL);
341 test_task = 328 test_task =
342 GNUNET_SCHEDULER_add_delayed( 329 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
343 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 6), 330 (GNUNET_TIME_UNIT_SECONDS, 6), &do_test,
344 &do_test, NULL); 331 NULL);
345} 332}
346 333
347 334
@@ -362,8 +349,8 @@ peergroup_ready (void *cls, const char *emsg)
362 { 349 {
363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
364 "test: Peergroup callback called with error, aborting test!\n"); 351 "test: Peergroup callback called with error, aborting test!\n");
365 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 352 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Error from testing: `%s'\n",
366 "test: Error from testing: `%s'\n", emsg); 353 emsg);
367 ok++; 354 ok++;
368 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 355 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
369 return; 356 return;
@@ -373,8 +360,7 @@ peergroup_ready (void *cls, const char *emsg)
373 "************************************************************\n"); 360 "************************************************************\n");
374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
375 "test: Peer Group started successfully!\n"); 362 "test: Peer Group started successfully!\n");
376 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Have %u connections\n",
377 "test: Have %u connections\n",
378 total_connections); 364 total_connections);
379#endif 365#endif
380 366
@@ -390,18 +376,14 @@ peergroup_ready (void *cls, const char *emsg)
390 for (i = 0; i < num_peers; i++) 376 for (i = 0; i < num_peers; i++)
391 { 377 {
392 d1 = GNUNET_TESTING_daemon_get (pg, i); 378 d1 = GNUNET_TESTING_daemon_get (pg, i);
393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 379 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: %u: %s\n",
394 "test: %u: %s\n", 380 GNUNET_PEER_intern (&d1->id), GNUNET_i2s (&d1->id));
395 GNUNET_PEER_intern(&d1->id),
396 GNUNET_i2s (&d1->id));
397 } 381 }
398 d1 = GNUNET_TESTING_daemon_get (pg, 0); 382 d1 = GNUNET_TESTING_daemon_get (pg, 0);
399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 383 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Peer looking: %s\n",
400 "test: Peer looking: %s\n",
401 GNUNET_i2s (&d1->id)); 384 GNUNET_i2s (&d1->id));
402 385
403 GNUNET_SCHEDULER_add_now (&connect_mesh_service, 386 GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL);
404 NULL);
405 disconnect_task = 387 disconnect_task =
406 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL); 388 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL);
407 389
@@ -437,8 +419,7 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
437 else 419 else
438 { 420 {
439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 421 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
440 "test: Problem with new connection (%s)\n", 422 "test: Problem with new connection (%s)\n", emsg);
441 emsg);
442 } 423 }
443 424
444} 425}
@@ -495,7 +476,7 @@ run (void *cls, char *const *args, const char *cfgfile,
495 } 476 }
496 } 477 }
497 478
498 mesh_peers = GNUNET_malloc (sizeof(GNUNET_PEER_Id) * (num_peers + 1)); 479 mesh_peers = GNUNET_malloc (sizeof (GNUNET_PEER_Id) * (num_peers + 1));
499 480
500 if (GNUNET_OK != 481 if (GNUNET_OK !=
501 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small", 482 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small",
@@ -522,15 +503,15 @@ run (void *cls, char *const *args, const char *cfgfile,
522 &data_filename)) 503 &data_filename))
523 { 504 {
524 data_file = 505 data_file =
525 GNUNET_DISK_file_open (data_filename, 506 GNUNET_DISK_file_open (data_filename,
526 GNUNET_DISK_OPEN_READWRITE | 507 GNUNET_DISK_OPEN_READWRITE |
527 GNUNET_DISK_OPEN_CREATE, 508 GNUNET_DISK_OPEN_CREATE,
528 GNUNET_DISK_PERM_USER_READ | 509 GNUNET_DISK_PERM_USER_READ |
529 GNUNET_DISK_PERM_USER_WRITE); 510 GNUNET_DISK_PERM_USER_WRITE);
530 if (data_file == NULL) 511 if (data_file == NULL)
531 { 512 {
532 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", 513 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
533 data_filename); 514 data_filename);
534 GNUNET_free (data_filename); 515 GNUNET_free (data_filename);
535 } 516 }
536 } 517 }
@@ -585,8 +566,8 @@ int
585main (int argc, char *argv[]) 566main (int argc, char *argv[])
586{ 567{
587 GNUNET_PROGRAM_run (argc, argv, "test_mesh_small_unicast", 568 GNUNET_PROGRAM_run (argc, argv, "test_mesh_small_unicast",
588 gettext_noop ("Test mesh unicast in a small network."), options, 569 gettext_noop ("Test mesh unicast in a small network."),
589 &run, NULL); 570 options, &run, NULL);
590#if REMOVE_DIR 571#if REMOVE_DIR
591 GNUNET_DISK_directory_remove ("/tmp/test_mesh_small_unicast"); 572 GNUNET_DISK_directory_remove ("/tmp/test_mesh_small_unicast");
592#endif 573#endif