aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-transport.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-11-04 14:00:32 +0000
committerChristian Grothoff <christian@grothoff.org>2011-11-04 14:00:32 +0000
commit83b19539f4d322b43683f5838b72e9ec2c8e6073 (patch)
treed0ab9329fcbefe360d9d14e2ace21a6b3396dfe9 /src/transport/gnunet-transport.c
parent28a2eb43281a1f08a67954f07beb9af3a9bc9a35 (diff)
downloadgnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.tar.gz
gnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.zip
curly wars / auto-indentation
Diffstat (limited to 'src/transport/gnunet-transport.c')
-rw-r--r--src/transport/gnunet-transport.c242
1 files changed, 96 insertions, 146 deletions
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index 686423a3d..4d2912c34 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -162,15 +162,11 @@ display_test_result (struct TestContext *tc, int result)
162{ 162{
163 if (GNUNET_YES != result) 163 if (GNUNET_YES != result)
164 { 164 {
165 fprintf (stderr, 165 fprintf (stderr, "Configuration for plugin `%s' did not work!\n", tc->name);
166 "Configuration for plugin `%s' did not work!\n",
167 tc->name);
168 } 166 }
169 else 167 else
170 { 168 {
171 fprintf (stderr, 169 fprintf (stderr, "Configuration for plugin `%s' is working!\n", tc->name);
172 "Configuration for plugin `%s' is working!\n",
173 tc->name);
174 } 170 }
175 if (GNUNET_SCHEDULER_NO_TASK != tc->tsk) 171 if (GNUNET_SCHEDULER_NO_TASK != tc->tsk)
176 { 172 {
@@ -184,8 +180,7 @@ display_test_result (struct TestContext *tc, int result)
184 } 180 }
185 GNUNET_free (tc); 181 GNUNET_free (tc);
186 resolver_users--; 182 resolver_users--;
187 if ( (0 == resolver_users) && 183 if ((0 == resolver_users) && (NULL != resolver))
188 (NULL != resolver) )
189 { 184 {
190 GNUNET_break (0 == GNUNET_OS_process_kill (resolver, SIGTERM)); 185 GNUNET_break (0 == GNUNET_OS_process_kill (resolver, SIGTERM));
191 GNUNET_OS_process_close (resolver); 186 GNUNET_OS_process_close (resolver);
@@ -242,52 +237,46 @@ do_test_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg)
242 struct TestContext *tc; 237 struct TestContext *tc;
243 238
244 if (GNUNET_OK != 239 if (GNUNET_OK !=
245 GNUNET_CONFIGURATION_get_value_string (cfg, 240 GNUNET_CONFIGURATION_get_value_string (cfg, "transport", "plugins",
246 "transport", 241 &plugins))
247 "plugins",
248 &plugins))
249 { 242 {
250 fprintf (stderr, 243 fprintf (stderr,
251 _("No transport plugins configured, peer will never communicate\n")); 244 _
245 ("No transport plugins configured, peer will never communicate\n"));
252 ret = 4; 246 ret = 4;
253 return; 247 return;
254 } 248 }
255 for (tok = strtok (plugins, " "); tok != NULL; tok = strtok (NULL, " ")) 249 for (tok = strtok (plugins, " "); tok != NULL; tok = strtok (NULL, " "))
256 { 250 {
257 char section[12+strlen(tok)]; 251 char section[12 + strlen (tok)];
258 252
259 GNUNET_snprintf (section, 253 GNUNET_snprintf (section, sizeof (section), "transport-%s", tok);
260 sizeof (section),
261 "transport-%s",
262 tok);
263 if (GNUNET_OK != 254 if (GNUNET_OK !=
264 GNUNET_CONFIGURATION_get_value_number (cfg, section, "PORT", 255 GNUNET_CONFIGURATION_get_value_number (cfg, section, "PORT", &bnd_port))
265 &bnd_port)) 256 {
266 { 257 fprintf (stderr,
267 fprintf (stderr, 258 _("No port configured for plugin `%s', cannot test it\n"), tok);
268 _("No port configured for plugin `%s', cannot test it\n"), 259 continue;
269 tok); 260 }
270 continue;
271 }
272 if (GNUNET_OK != 261 if (GNUNET_OK !=
273 GNUNET_CONFIGURATION_get_value_number (cfg, section, 262 GNUNET_CONFIGURATION_get_value_number (cfg, section, "ADVERTISED_PORT",
274 "ADVERTISED_PORT", &adv_port)) 263 &adv_port))
275 adv_port = bnd_port; 264 adv_port = bnd_port;
276 if (NULL == resolver) 265 if (NULL == resolver)
277 resolver = 266 resolver =
278 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-resolver", 267 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-resolver",
279 "gnunet-service-resolver", NULL); 268 "gnunet-service-resolver", NULL);
280 resolver_users++; 269 resolver_users++;
281 GNUNET_RESOLVER_connect (cfg); 270 GNUNET_RESOLVER_connect (cfg);
282 tc = GNUNET_malloc (sizeof (struct TestContext)); 271 tc = GNUNET_malloc (sizeof (struct TestContext));
283 tc->name = GNUNET_strdup (tok); 272 tc->name = GNUNET_strdup (tok);
284 tc->tst = 273 tc->tst =
285 GNUNET_NAT_test_start (cfg, 274 GNUNET_NAT_test_start (cfg,
286 (0 == strcasecmp (tok, "udp")) 275 (0 ==
287 ? GNUNET_NO 276 strcasecmp (tok,
288 : GNUNET_YES, 277 "udp")) ? GNUNET_NO : GNUNET_YES,
289 (uint16_t) bnd_port, 278 (uint16_t) bnd_port, (uint16_t) adv_port,
290 (uint16_t) adv_port, &result_callback, tc); 279 &result_callback, tc);
291 if (NULL == tc->tst) 280 if (NULL == tc->tst)
292 { 281 {
293 display_test_result (tc, GNUNET_SYSERR); 282 display_test_result (tc, GNUNET_SYSERR);
@@ -303,8 +292,7 @@ do_test_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg)
303 * Shutdown, print statistics. 292 * Shutdown, print statistics.
304 */ 293 */
305static void 294static void
306do_disconnect (void *cls, 295do_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
307 const struct GNUNET_SCHEDULER_TaskContext *tc)
308{ 296{
309 struct GNUNET_TIME_Relative duration; 297 struct GNUNET_TIME_Relative duration;
310 298
@@ -317,20 +305,16 @@ do_disconnect (void *cls,
317 if (benchmark_receive) 305 if (benchmark_receive)
318 { 306 {
319 duration = GNUNET_TIME_absolute_get_duration (start_time); 307 duration = GNUNET_TIME_absolute_get_duration (start_time);
320 fprintf (stdout, 308 fprintf (stdout, _("Received %llu bytes/s (%llu bytes in %llu ms)\n"),
321 _("Received %llu bytes/s (%llu bytes in %llu ms)\n"), 309 1000 * traffic_received / (1 + duration.rel_value),
322 1000 * traffic_received / (1+duration.rel_value), 310 traffic_received, (unsigned long long) duration.rel_value);
323 traffic_received,
324 (unsigned long long) duration.rel_value);
325 } 311 }
326 if (benchmark_send) 312 if (benchmark_send)
327 { 313 {
328 duration = GNUNET_TIME_absolute_get_duration (start_time); 314 duration = GNUNET_TIME_absolute_get_duration (start_time);
329 fprintf (stdout, 315 fprintf (stdout, _("Transmitted %llu bytes/s (%llu bytes in %llu ms)\n"),
330 _("Transmitted %llu bytes/s (%llu bytes in %llu ms)\n"), 316 1000 * traffic_sent / (1 + duration.rel_value), traffic_sent,
331 1000 * traffic_sent / (1+duration.rel_value), 317 (unsigned long long) duration.rel_value);
332 traffic_sent,
333 (unsigned long long) duration.rel_value);
334 } 318 }
335} 319}
336 320
@@ -347,8 +331,7 @@ do_disconnect (void *cls,
347 * @return number of bytes written to buf 331 * @return number of bytes written to buf
348 */ 332 */
349static size_t 333static size_t
350transmit_data (void *cls, size_t size, 334transmit_data (void *cls, size_t size, void *buf)
351 void *buf)
352{ 335{
353 struct GNUNET_MessageHeader *m = buf; 336 struct GNUNET_MessageHeader *m = buf;
354 337
@@ -358,17 +341,12 @@ transmit_data (void *cls, size_t size,
358 m->type = ntohs (GNUNET_MESSAGE_TYPE_DUMMY); 341 m->type = ntohs (GNUNET_MESSAGE_TYPE_DUMMY);
359 memset (&m[1], 52, size - sizeof (struct GNUNET_MessageHeader)); 342 memset (&m[1], 52, size - sizeof (struct GNUNET_MessageHeader));
360 traffic_sent += size; 343 traffic_sent += size;
361 th = GNUNET_TRANSPORT_notify_transmit_ready (handle, 344 th = GNUNET_TRANSPORT_notify_transmit_ready (handle, &pid, 32 * 1024, 0,
362 &pid, 345 GNUNET_TIME_UNIT_FOREVER_REL,
363 32 * 1024, 346 &transmit_data, NULL);
364 0,
365 GNUNET_TIME_UNIT_FOREVER_REL,
366 &transmit_data, NULL);
367 if (verbosity > 0) 347 if (verbosity > 0)
368 fprintf (stdout, 348 fprintf (stdout, _("Transmitting %u bytes to %s\n"), (unsigned int) size,
369 _("Transmitting %u bytes to %s\n"), 349 GNUNET_i2s (&pid));
370 (unsigned int) size,
371 GNUNET_i2s (&pid));
372 return size; 350 return size;
373} 351}
374 352
@@ -383,39 +361,27 @@ transmit_data (void *cls, size_t size,
383 * @param ats_count number of entries in ats (excluding 0-termination) 361 * @param ats_count number of entries in ats (excluding 0-termination)
384 */ 362 */
385static void 363static void
386notify_connect (void *cls, 364notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
387 const struct GNUNET_PeerIdentity 365 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
388 * peer,
389 const struct
390 GNUNET_ATS_Information
391 * ats, uint32_t ats_count)
392{ 366{
393 if (verbosity > 0) 367 if (verbosity > 0)
394 fprintf (stdout, 368 fprintf (stdout, _("Connected to %s\n"), GNUNET_i2s (peer));
395 _("Connected to %s\n"), 369 if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity)))
396 GNUNET_i2s (peer));
397 if (0 != memcmp (&pid,
398 peer,
399 sizeof (struct GNUNET_PeerIdentity)))
400 return; 370 return;
401 ret = 0; 371 ret = 0;
402 if (benchmark_send) 372 if (benchmark_send)
403 { 373 {
404 start_time = GNUNET_TIME_absolute_get (); 374 start_time = GNUNET_TIME_absolute_get ();
405 th = GNUNET_TRANSPORT_notify_transmit_ready (handle, 375 th = GNUNET_TRANSPORT_notify_transmit_ready (handle, peer, 32 * 1024, 0,
406 peer, 376 GNUNET_TIME_UNIT_FOREVER_REL,
407 32 * 1024, 377 &transmit_data, NULL);
408 0,
409 GNUNET_TIME_UNIT_FOREVER_REL,
410 &transmit_data, NULL);
411 } 378 }
412 else 379 else
413 { 380 {
414 /* all done, terminate instantly */ 381 /* all done, terminate instantly */
415 GNUNET_SCHEDULER_cancel (end); 382 GNUNET_SCHEDULER_cancel (end);
416 end = GNUNET_SCHEDULER_add_now (&do_disconnect, 383 end = GNUNET_SCHEDULER_add_now (&do_disconnect, NULL);
417 NULL); 384 }
418 }
419} 385}
420 386
421 387
@@ -427,24 +393,17 @@ notify_connect (void *cls,
427 * @param peer the peer that disconnected 393 * @param peer the peer that disconnected
428 */ 394 */
429static void 395static void
430notify_disconnect (void *cls, 396notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
431 const struct
432 GNUNET_PeerIdentity * peer)
433{ 397{
434 if (verbosity > 0) 398 if (verbosity > 0)
435 fprintf (stdout, 399 fprintf (stdout, _("Disconnected from %s\n"), GNUNET_i2s (peer));
436 _("Disconnected from %s\n"), 400 if ((0 == memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) &&
437 GNUNET_i2s (peer)); 401 (NULL != th))
438 if ( (0 == memcmp (&pid,
439 peer,
440 sizeof (struct GNUNET_PeerIdentity))) &&
441 (NULL != th) )
442 { 402 {
443 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); 403 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
444 th = NULL; 404 th = NULL;
445 GNUNET_SCHEDULER_cancel (end); 405 GNUNET_SCHEDULER_cancel (end);
446 end = GNUNET_SCHEDULER_add_now (&do_disconnect, 406 end = GNUNET_SCHEDULER_add_now (&do_disconnect, NULL);
447 NULL);
448 } 407 }
449} 408}
450 409
@@ -456,26 +415,18 @@ notify_disconnect (void *cls,
456 * @param peer (claimed) identity of the other peer 415 * @param peer (claimed) identity of the other peer
457 * @param message the message 416 * @param message the message
458 * @param ats performance data 417 * @param ats performance data
459 * @param ats_count number of entries in ats 418 * @param ats_count number of entries in ats
460 */ 419 */
461static void 420static void
462notify_receive (void *cls, 421notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
463 const struct 422 const struct GNUNET_MessageHeader *message,
464 GNUNET_PeerIdentity * peer, 423 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
465 const struct
466 GNUNET_MessageHeader *
467 message,
468 const struct
469 GNUNET_ATS_Information
470 * ats, uint32_t ats_count)
471{ 424{
472 if (! benchmark_receive) 425 if (!benchmark_receive)
473 return; 426 return;
474 if (verbosity > 0) 427 if (verbosity > 0)
475 fprintf (stdout, 428 fprintf (stdout, _("Received %u bytes from %s\n"),
476 _("Received %u bytes from %s\n"), 429 (unsigned int) ntohs (message->size), GNUNET_i2s (peer));
477 (unsigned int) ntohs (message->size),
478 GNUNET_i2s (peer));
479 if (traffic_received == 0) 430 if (traffic_received == 0)
480 start_time = GNUNET_TIME_absolute_get (); 431 start_time = GNUNET_TIME_absolute_get ();
481 traffic_received += ntohs (message->size); 432 traffic_received += ntohs (message->size);
@@ -494,11 +445,12 @@ process_address (void *cls, const struct GNUNET_PeerIdentity *peer,
494{ 445{
495 if ((peer != NULL) || (transport != NULL) || 446 if ((peer != NULL) || (transport != NULL) ||
496 ((addr != NULL) && (addrlen > 0))) 447 ((addr != NULL) && (addrlen > 0)))
497 fprintf (stdout, 448 fprintf (stdout, _("Peer `%s' plugin: `%s' address `%s'\n"),
498 _("Peer `%s' plugin: `%s' address `%s'\n"),
499 (peer != NULL) ? GNUNET_i2s (peer) : "<unknown>", 449 (peer != NULL) ? GNUNET_i2s (peer) : "<unknown>",
500 (transport != NULL) ? transport : "<unknown>", 450 (transport != NULL) ? transport : "<unknown>", ((addr != NULL) &&
501 ((addr != NULL) && (addrlen > 0) && (transport != NULL)) ? 451 (addrlen > 0) &&
452 (transport !=
453 NULL)) ?
502 "how do i resolve the name without transport service?" : 454 "how do i resolve the name without transport service?" :
503 "<unknown>"); 455 "<unknown>");
504} 456}
@@ -523,45 +475,41 @@ run (void *cls, char *const *args, const char *cfgfile,
523 if (benchmark_send && (NULL == cpid)) 475 if (benchmark_send && (NULL == cpid))
524 { 476 {
525 fprintf (stderr, _("Option `%s' makes no sense without option `%s'.\n"), 477 fprintf (stderr, _("Option `%s' makes no sense without option `%s'.\n"),
526 "-s", "-C"); 478 "-s", "-C");
527 return; 479 return;
528 } 480 }
529 if (NULL != cpid) 481 if (NULL != cpid)
530 { 482 {
531 ret = 1; 483 ret = 1;
532 if (GNUNET_OK != 484 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (cpid, &pid.hashPubKey))
533 GNUNET_CRYPTO_hash_from_string (cpid, &pid.hashPubKey))
534 { 485 {
535 fprintf (stderr, 486 fprintf (stderr, _("Failed to parse peer identity `%s'\n"), cpid);
536 _("Failed to parse peer identity `%s'\n"),
537 cpid);
538 return; 487 return;
539 } 488 }
540 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, 489 handle =
541 &notify_receive, 490 GNUNET_TRANSPORT_connect (cfg, NULL, NULL, &notify_receive,
542 &notify_connect, 491 &notify_connect, &notify_disconnect);
543 &notify_disconnect);
544 GNUNET_TRANSPORT_try_connect (handle, &pid); 492 GNUNET_TRANSPORT_try_connect (handle, &pid);
545 end = GNUNET_SCHEDULER_add_delayed (benchmark_send 493 end =
546 ? GNUNET_TIME_UNIT_FOREVER_REL 494 GNUNET_SCHEDULER_add_delayed (benchmark_send ?
547 : GNUNET_TIME_UNIT_SECONDS, 495 GNUNET_TIME_UNIT_FOREVER_REL :
548 &do_disconnect, 496 GNUNET_TIME_UNIT_SECONDS, &do_disconnect,
549 NULL); 497 NULL);
550 } else if (benchmark_receive) 498 }
499 else if (benchmark_receive)
551 { 500 {
552 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, 501 handle =
553 &notify_receive, 502 GNUNET_TRANSPORT_connect (cfg, NULL, NULL, &notify_receive,
554 &notify_connect, 503 &notify_connect, &notify_disconnect);
555 &notify_disconnect);
556 GNUNET_TRANSPORT_try_connect (handle, &pid); 504 GNUNET_TRANSPORT_try_connect (handle, &pid);
557 end = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 505 end =
558 &do_disconnect, 506 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
559 NULL); 507 &do_disconnect, NULL);
560 } 508 }
561 if (iterate_connections) 509 if (iterate_connections)
562 { 510 {
563 GNUNET_TRANSPORT_address_iterate (cfg, GNUNET_TIME_UNIT_MINUTES, 511 GNUNET_TRANSPORT_address_iterate (cfg, GNUNET_TIME_UNIT_MINUTES,
564 &process_address, NULL); 512 &process_address, NULL);
565 } 513 }
566} 514}
567 515
@@ -578,20 +526,22 @@ main (int argc, char *const *argv)
578 1, &GNUNET_GETOPT_set_string, &cpid}, 526 1, &GNUNET_GETOPT_set_string, &cpid},
579 {'i', "information", NULL, 527 {'i', "information", NULL,
580 gettext_noop ("provide information about all current connections (once)"), 528 gettext_noop ("provide information about all current connections (once)"),
581 0, &GNUNET_GETOPT_set_one, &iterate_connections}, 529 0, &GNUNET_GETOPT_set_one, &iterate_connections},
582 {'s', "send", NULL, 530 {'s', "send", NULL,
583 gettext_noop ("send data for benchmarking to the other peer (until CTRL-C)"), 531 gettext_noop
584 0, &GNUNET_GETOPT_set_one, &benchmark_send}, 532 ("send data for benchmarking to the other peer (until CTRL-C)"),
533 0, &GNUNET_GETOPT_set_one, &benchmark_send},
585 {'t', "test", NULL, 534 {'t', "test", NULL,
586 gettext_noop ("test transport configuration (involves external server)"), 535 gettext_noop ("test transport configuration (involves external server)"),
587 0, &GNUNET_GETOPT_set_one, &test_configuration}, 536 0, &GNUNET_GETOPT_set_one, &test_configuration},
588 GNUNET_GETOPT_OPTION_VERBOSE(&verbosity), 537 GNUNET_GETOPT_OPTION_VERBOSE (&verbosity),
589 GNUNET_GETOPT_OPTION_END 538 GNUNET_GETOPT_OPTION_END
590 }; 539 };
591 return (GNUNET_OK == 540 return (GNUNET_OK ==
592 GNUNET_PROGRAM_run (argc, argv, "gnunet-transport", 541 GNUNET_PROGRAM_run (argc, argv, "gnunet-transport",
593 gettext_noop ("Direct access to transport service."), 542 gettext_noop
594 options, &run, NULL)) ? ret : 1; 543 ("Direct access to transport service."), options,
544 &run, NULL)) ? ret : 1;
595} 545}
596 546
597 547