diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
commit | 502af2167f7c218366666ca4944bd7cc54b5b19a (patch) | |
tree | a91fec5cc9769d260640bd91c6633cb9cf395524 /src/transport/plugin_transport_udp.c | |
parent | 03af5a603b7cc53432249d5854cd412aa90dde0d (diff) | |
download | gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip |
indentation
Diffstat (limited to 'src/transport/plugin_transport_udp.c')
-rw-r--r-- | src/transport/plugin_transport_udp.c | 1228 |
1 files changed, 580 insertions, 648 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 7d8c1520f..df8447a12 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -193,7 +193,7 @@ struct ReceiveContext | |||
193 | 193 | ||
194 | /** | 194 | /** |
195 | * Node in the defrag heap. | 195 | * Node in the defrag heap. |
196 | */ | 196 | */ |
197 | struct GNUNET_CONTAINER_HeapNode *hnode; | 197 | struct GNUNET_CONTAINER_HeapNode *hnode; |
198 | 198 | ||
199 | /** | 199 | /** |
@@ -297,11 +297,10 @@ struct Plugin | |||
297 | * @return NULL if we have no session | 297 | * @return NULL if we have no session |
298 | */ | 298 | */ |
299 | struct PeerSession * | 299 | struct PeerSession * |
300 | find_session (struct Plugin *plugin, | 300 | find_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *peer) |
301 | const struct GNUNET_PeerIdentity *peer) | ||
302 | { | 301 | { |
303 | return GNUNET_CONTAINER_multihashmap_get (plugin->sessions, | 302 | return GNUNET_CONTAINER_multihashmap_get (plugin->sessions, |
304 | &peer->hashPubKey); | 303 | &peer->hashPubKey); |
305 | } | 304 | } |
306 | 305 | ||
307 | 306 | ||
@@ -322,9 +321,9 @@ udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) | |||
322 | if (NULL == session) | 321 | if (NULL == session) |
323 | return; | 322 | return; |
324 | GNUNET_assert (GNUNET_OK == | 323 | GNUNET_assert (GNUNET_OK == |
325 | GNUNET_CONTAINER_multihashmap_remove (plugin->sessions, | 324 | GNUNET_CONTAINER_multihashmap_remove (plugin->sessions, |
326 | &target->hashPubKey, | 325 | &target->hashPubKey, |
327 | session)); | 326 | session)); |
328 | plugin->last_expected_delay = GNUNET_FRAGMENT_context_destroy (session->frag); | 327 | plugin->last_expected_delay = GNUNET_FRAGMENT_context_destroy (session->frag); |
329 | session->cont (session->cont_cls, target, GNUNET_SYSERR); | 328 | session->cont (session->cont_cls, target, GNUNET_SYSERR); |
330 | GNUNET_free (session); | 329 | GNUNET_free (session); |
@@ -352,48 +351,43 @@ udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) | |||
352 | */ | 351 | */ |
353 | static ssize_t | 352 | static ssize_t |
354 | udp_send (struct Plugin *plugin, | 353 | udp_send (struct Plugin *plugin, |
355 | const struct sockaddr *sa, | 354 | const struct sockaddr *sa, const struct GNUNET_MessageHeader *msg) |
356 | const struct GNUNET_MessageHeader *msg) | ||
357 | { | 355 | { |
358 | ssize_t sent; | 356 | ssize_t sent; |
359 | size_t slen; | 357 | size_t slen; |
360 | 358 | ||
361 | switch (sa->sa_family) | 359 | switch (sa->sa_family) |
362 | { | 360 | { |
363 | case AF_INET: | 361 | case AF_INET: |
364 | if (NULL == plugin->sockv4) | 362 | if (NULL == plugin->sockv4) |
365 | return 0; | ||
366 | sent = | ||
367 | GNUNET_NETWORK_socket_sendto (plugin->sockv4, | ||
368 | msg, | ||
369 | ntohs (msg->size), | ||
370 | sa, | ||
371 | slen = sizeof (struct sockaddr_in)); | ||
372 | break; | ||
373 | case AF_INET6: | ||
374 | if (NULL == plugin->sockv6) | ||
375 | return 0; | ||
376 | sent = | ||
377 | GNUNET_NETWORK_socket_sendto (plugin->sockv6, | ||
378 | msg, | ||
379 | ntohs (msg->size), | ||
380 | sa, | ||
381 | slen = sizeof (struct sockaddr_in6)); | ||
382 | break; | ||
383 | default: | ||
384 | GNUNET_break (0); | ||
385 | return 0; | 363 | return 0; |
386 | } | 364 | sent = |
365 | GNUNET_NETWORK_socket_sendto (plugin->sockv4, | ||
366 | msg, | ||
367 | ntohs (msg->size), | ||
368 | sa, slen = sizeof (struct sockaddr_in)); | ||
369 | break; | ||
370 | case AF_INET6: | ||
371 | if (NULL == plugin->sockv6) | ||
372 | return 0; | ||
373 | sent = | ||
374 | GNUNET_NETWORK_socket_sendto (plugin->sockv6, | ||
375 | msg, | ||
376 | ntohs (msg->size), | ||
377 | sa, slen = sizeof (struct sockaddr_in6)); | ||
378 | break; | ||
379 | default: | ||
380 | GNUNET_break (0); | ||
381 | return 0; | ||
382 | } | ||
387 | if (GNUNET_SYSERR == sent) | 383 | if (GNUNET_SYSERR == sent) |
388 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, | 384 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "sendto"); |
389 | "sendto"); | ||
390 | #if DEBUG_UDP | 385 | #if DEBUG_UDP |
391 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
392 | "UDP transmited %u-byte message to %s (%d: %s)\n", | 387 | "UDP transmited %u-byte message to %s (%d: %s)\n", |
393 | (unsigned int) ntohs (msg->size), | 388 | (unsigned int) ntohs (msg->size), |
394 | GNUNET_a2s (sa, slen), | 389 | GNUNET_a2s (sa, slen), |
395 | (int) sent, | 390 | (int) sent, (sent < 0) ? STRERROR (errno) : "ok"); |
396 | (sent < 0) ? STRERROR (errno) : "ok"); | ||
397 | #endif | 391 | #endif |
398 | return sent; | 392 | return sent; |
399 | } | 393 | } |
@@ -408,15 +402,12 @@ udp_send (struct Plugin *plugin, | |||
408 | * @param cls closure, the 'struct PeerSession' | 402 | * @param cls closure, the 'struct PeerSession' |
409 | * @param msg the message that was created | 403 | * @param msg the message that was created |
410 | */ | 404 | */ |
411 | static void | 405 | static void |
412 | send_fragment (void *cls, | 406 | send_fragment (void *cls, const struct GNUNET_MessageHeader *msg) |
413 | const struct GNUNET_MessageHeader *msg) | ||
414 | { | 407 | { |
415 | struct PeerSession *session = cls; | 408 | struct PeerSession *session = cls; |
416 | 409 | ||
417 | udp_send (session->plugin, | 410 | udp_send (session->plugin, session->sock_addr, msg); |
418 | session->sock_addr, | ||
419 | msg); | ||
420 | GNUNET_FRAGMENT_context_transmission_done (session->frag); | 411 | GNUNET_FRAGMENT_context_transmission_done (session->frag); |
421 | } | 412 | } |
422 | 413 | ||
@@ -447,16 +438,16 @@ send_fragment (void *cls, | |||
447 | */ | 438 | */ |
448 | static ssize_t | 439 | static ssize_t |
449 | udp_plugin_send (void *cls, | 440 | udp_plugin_send (void *cls, |
450 | const struct GNUNET_PeerIdentity *target, | 441 | const struct GNUNET_PeerIdentity *target, |
451 | const char *msgbuf, | 442 | const char *msgbuf, |
452 | size_t msgbuf_size, | 443 | size_t msgbuf_size, |
453 | unsigned int priority, | 444 | unsigned int priority, |
454 | struct GNUNET_TIME_Relative timeout, | 445 | struct GNUNET_TIME_Relative timeout, |
455 | struct Session *session, | 446 | struct Session *session, |
456 | const void *addr, | 447 | const void *addr, |
457 | size_t addrlen, | 448 | size_t addrlen, |
458 | int force_address, | 449 | int force_address, |
459 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) | 450 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) |
460 | { | 451 | { |
461 | struct Plugin *plugin = cls; | 452 | struct Plugin *plugin = cls; |
462 | struct PeerSession *peer_session; | 453 | struct PeerSession *peer_session; |
@@ -472,50 +463,54 @@ udp_plugin_send (void *cls, | |||
472 | return GNUNET_SYSERR; | 463 | return GNUNET_SYSERR; |
473 | GNUNET_assert (NULL == session); | 464 | GNUNET_assert (NULL == session); |
474 | if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 465 | if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
475 | { | 466 | { |
476 | GNUNET_break (0); | 467 | GNUNET_break (0); |
477 | return GNUNET_SYSERR; | 468 | return GNUNET_SYSERR; |
478 | } | 469 | } |
479 | switch (addrlen) | 470 | switch (addrlen) |
471 | { | ||
472 | case sizeof (struct IPv4UdpAddress): | ||
473 | if (NULL == plugin->sockv4) | ||
480 | { | 474 | { |
481 | case sizeof(struct IPv4UdpAddress): | 475 | cont (cont_cls, target, GNUNET_SYSERR); |
482 | if (NULL == plugin->sockv4) | 476 | return 0; |
483 | { | 477 | } |
484 | cont (cont_cls, target, GNUNET_SYSERR); | 478 | t4 = addr; |
485 | return 0; | 479 | peer_session = |
486 | } | 480 | GNUNET_malloc (sizeof (struct PeerSession) + |
487 | t4 = addr; | 481 | sizeof (struct sockaddr_in)); |
488 | peer_session = GNUNET_malloc (sizeof (struct PeerSession) + sizeof (struct sockaddr_in)); | 482 | v4 = (struct sockaddr_in *) &peer_session[1]; |
489 | v4 = (struct sockaddr_in*) &peer_session[1]; | 483 | v4->sin_family = AF_INET; |
490 | v4->sin_family = AF_INET; | ||
491 | #if HAVE_SOCKADDR_IN_SIN_LEN | 484 | #if HAVE_SOCKADDR_IN_SIN_LEN |
492 | v4->sin_len = sizeof (struct sockaddr_in); | 485 | v4->sin_len = sizeof (struct sockaddr_in); |
493 | #endif | 486 | #endif |
494 | v4->sin_port = t4->u4_port; | 487 | v4->sin_port = t4->u4_port; |
495 | v4->sin_addr.s_addr = t4->ipv4_addr; | 488 | v4->sin_addr.s_addr = t4->ipv4_addr; |
496 | break; | 489 | break; |
497 | case sizeof(struct IPv6UdpAddress): | 490 | case sizeof (struct IPv6UdpAddress): |
498 | if (NULL == plugin->sockv6) | 491 | if (NULL == plugin->sockv6) |
499 | { | 492 | { |
500 | cont (cont_cls, target, GNUNET_SYSERR); | 493 | cont (cont_cls, target, GNUNET_SYSERR); |
501 | return 0; | 494 | return 0; |
502 | } | 495 | } |
503 | t6 = addr; | 496 | t6 = addr; |
504 | peer_session = GNUNET_malloc (sizeof (struct PeerSession) + sizeof (struct sockaddr_in6)); | 497 | peer_session = |
505 | v6 = (struct sockaddr_in6*) &peer_session[1]; | 498 | GNUNET_malloc (sizeof (struct PeerSession) + |
506 | v6->sin6_family = AF_INET6; | 499 | sizeof (struct sockaddr_in6)); |
500 | v6 = (struct sockaddr_in6 *) &peer_session[1]; | ||
501 | v6->sin6_family = AF_INET6; | ||
507 | #if HAVE_SOCKADDR_IN_SIN_LEN | 502 | #if HAVE_SOCKADDR_IN_SIN_LEN |
508 | v6->sin6_len = sizeof (struct sockaddr_in6); | 503 | v6->sin6_len = sizeof (struct sockaddr_in6); |
509 | #endif | 504 | #endif |
510 | v6->sin6_port = t6->u6_port; | 505 | v6->sin6_port = t6->u6_port; |
511 | v6->sin6_addr = t6->ipv6_addr; | 506 | v6->sin6_addr = t6->ipv6_addr; |
512 | break; | 507 | break; |
513 | default: | 508 | default: |
514 | /* Must have a valid address to send to */ | 509 | /* Must have a valid address to send to */ |
515 | GNUNET_break_op(0); | 510 | GNUNET_break_op (0); |
516 | return GNUNET_SYSERR; | 511 | return GNUNET_SYSERR; |
517 | } | 512 | } |
518 | udp = (struct UDPMessage*) mbuf; | 513 | udp = (struct UDPMessage *) mbuf; |
519 | udp->header.size = htons (mlen); | 514 | udp->header.size = htons (mlen); |
520 | udp->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE); | 515 | udp->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE); |
521 | udp->reserved = htonl (0); | 516 | udp->reserved = htonl (0); |
@@ -523,32 +518,30 @@ udp_plugin_send (void *cls, | |||
523 | memcpy (&udp[1], msgbuf, msgbuf_size); | 518 | memcpy (&udp[1], msgbuf, msgbuf_size); |
524 | peer_session->target = *target; | 519 | peer_session->target = *target; |
525 | peer_session->plugin = plugin; | 520 | peer_session->plugin = plugin; |
526 | peer_session->sock_addr = (const struct sockaddr*) &peer_session[1]; | 521 | peer_session->sock_addr = (const struct sockaddr *) &peer_session[1]; |
527 | peer_session->cont = cont; | 522 | peer_session->cont = cont; |
528 | peer_session->cont_cls = cont_cls; | 523 | peer_session->cont_cls = cont_cls; |
529 | if (mlen <= UDP_MTU) | 524 | if (mlen <= UDP_MTU) |
530 | { | 525 | { |
531 | mlen = udp_send (plugin, | 526 | mlen = udp_send (plugin, peer_session->sock_addr, &udp->header); |
532 | peer_session->sock_addr, | 527 | cont (cont_cls, target, (mlen > 0) ? GNUNET_OK : GNUNET_SYSERR); |
533 | &udp->header); | 528 | GNUNET_free (peer_session); |
534 | cont (cont_cls, target, (mlen > 0) ? GNUNET_OK : GNUNET_SYSERR); | 529 | } |
535 | GNUNET_free (peer_session); | ||
536 | } | ||
537 | else | 530 | else |
538 | { | 531 | { |
539 | GNUNET_assert (GNUNET_OK == | 532 | GNUNET_assert (GNUNET_OK == |
540 | GNUNET_CONTAINER_multihashmap_put (plugin->sessions, | 533 | GNUNET_CONTAINER_multihashmap_put (plugin->sessions, |
541 | &target->hashPubKey, | 534 | &target->hashPubKey, |
542 | peer_session, | 535 | peer_session, |
543 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 536 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
544 | peer_session->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats, | 537 | peer_session->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats, |
545 | UDP_MTU, | 538 | UDP_MTU, |
546 | &plugin->tracker, | 539 | &plugin->tracker, |
547 | plugin->last_expected_delay, | 540 | plugin->last_expected_delay, |
548 | &udp->header, | 541 | &udp->header, |
549 | &send_fragment, | 542 | &send_fragment, |
550 | peer_session); | 543 | peer_session); |
551 | } | 544 | } |
552 | return mlen; | 545 | return mlen; |
553 | } | 546 | } |
554 | 547 | ||
@@ -562,7 +555,7 @@ struct SourceInformation | |||
562 | * Sender identity. | 555 | * Sender identity. |
563 | */ | 556 | */ |
564 | struct GNUNET_PeerIdentity sender; | 557 | struct GNUNET_PeerIdentity sender; |
565 | 558 | ||
566 | /** | 559 | /** |
567 | * Source address. | 560 | * Source address. |
568 | */ | 561 | */ |
@@ -585,11 +578,11 @@ struct SourceInformation | |||
585 | */ | 578 | */ |
586 | static void | 579 | static void |
587 | process_inbound_tokenized_messages (void *cls, | 580 | process_inbound_tokenized_messages (void *cls, |
588 | void *client, | 581 | void *client, |
589 | const struct GNUNET_MessageHeader *hdr) | 582 | const struct GNUNET_MessageHeader *hdr) |
590 | { | 583 | { |
591 | struct Plugin *plugin = cls; | 584 | struct Plugin *plugin = cls; |
592 | struct SourceInformation* si = client; | 585 | struct SourceInformation *si = client; |
593 | struct GNUNET_TRANSPORT_ATS_Information distance[2]; | 586 | struct GNUNET_TRANSPORT_ATS_Information distance[2]; |
594 | 587 | ||
595 | /* setup ATS */ | 588 | /* setup ATS */ |
@@ -598,12 +591,8 @@ process_inbound_tokenized_messages (void *cls, | |||
598 | distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); | 591 | distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); |
599 | distance[1].value = htonl (0); | 592 | distance[1].value = htonl (0); |
600 | 593 | ||
601 | plugin->env->receive (plugin->env->cls, | 594 | plugin->env->receive (plugin->env->cls, |
602 | &si->sender, | 595 | &si->sender, hdr, distance, 2, NULL, si->arg, si->args); |
603 | hdr, | ||
604 | distance, 2, | ||
605 | NULL, | ||
606 | si->arg, si->args); | ||
607 | } | 596 | } |
608 | 597 | ||
609 | 598 | ||
@@ -617,55 +606,56 @@ process_inbound_tokenized_messages (void *cls, | |||
617 | */ | 606 | */ |
618 | static void | 607 | static void |
619 | process_udp_message (struct Plugin *plugin, | 608 | process_udp_message (struct Plugin *plugin, |
620 | const struct UDPMessage *msg, | 609 | const struct UDPMessage *msg, |
621 | const struct sockaddr *sender_addr, | 610 | const struct sockaddr *sender_addr, |
622 | socklen_t sender_addr_len) | 611 | socklen_t sender_addr_len) |
623 | { | 612 | { |
624 | struct SourceInformation si; | 613 | struct SourceInformation si; |
625 | struct IPv4UdpAddress u4; | 614 | struct IPv4UdpAddress u4; |
626 | struct IPv6UdpAddress u6; | 615 | struct IPv6UdpAddress u6; |
627 | const void *arg; | 616 | const void *arg; |
628 | size_t args; | 617 | size_t args; |
629 | 618 | ||
630 | if (0 != ntohl (msg->reserved)) | 619 | if (0 != ntohl (msg->reserved)) |
631 | { | 620 | { |
632 | GNUNET_break_op (0); | 621 | GNUNET_break_op (0); |
633 | return; | 622 | return; |
634 | } | 623 | } |
635 | if (ntohs (msg->header.size) < sizeof (struct GNUNET_MessageHeader) + sizeof (struct UDPMessage)) | 624 | if (ntohs (msg->header.size) < |
636 | { | 625 | sizeof (struct GNUNET_MessageHeader) + sizeof (struct UDPMessage)) |
637 | GNUNET_break_op (0); | 626 | { |
638 | return; | 627 | GNUNET_break_op (0); |
639 | } | 628 | return; |
629 | } | ||
640 | 630 | ||
641 | /* convert address */ | 631 | /* convert address */ |
642 | switch (sender_addr->sa_family) | 632 | switch (sender_addr->sa_family) |
643 | { | 633 | { |
644 | case AF_INET: | 634 | case AF_INET: |
645 | GNUNET_assert (sender_addr_len == sizeof (struct sockaddr_in)); | 635 | GNUNET_assert (sender_addr_len == sizeof (struct sockaddr_in)); |
646 | u4.ipv4_addr = ((struct sockaddr_in *) sender_addr)->sin_addr.s_addr; | 636 | u4.ipv4_addr = ((struct sockaddr_in *) sender_addr)->sin_addr.s_addr; |
647 | u4.u4_port = ((struct sockaddr_in *) sender_addr)->sin_port; | 637 | u4.u4_port = ((struct sockaddr_in *) sender_addr)->sin_port; |
648 | arg = &u4; | 638 | arg = &u4; |
649 | args = sizeof (u4); | 639 | args = sizeof (u4); |
650 | break; | 640 | break; |
651 | case AF_INET6: | 641 | case AF_INET6: |
652 | GNUNET_assert (sender_addr_len == sizeof (struct sockaddr_in6)); | 642 | GNUNET_assert (sender_addr_len == sizeof (struct sockaddr_in6)); |
653 | u6.ipv6_addr = ((struct sockaddr_in6*) sender_addr)->sin6_addr; | 643 | u6.ipv6_addr = ((struct sockaddr_in6 *) sender_addr)->sin6_addr; |
654 | u6.u6_port = ((struct sockaddr_in6 *) sender_addr)->sin6_port; | 644 | u6.u6_port = ((struct sockaddr_in6 *) sender_addr)->sin6_port; |
655 | arg = &u6; | 645 | arg = &u6; |
656 | args = sizeof (u6); | 646 | args = sizeof (u6); |
657 | break; | 647 | break; |
658 | default: | 648 | default: |
659 | GNUNET_break (0); | 649 | GNUNET_break (0); |
660 | return; | 650 | return; |
661 | } | 651 | } |
662 | #if DEBUG_UDP | 652 | #if DEBUG_UDP |
663 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 653 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
664 | "udp", | 654 | "udp", |
665 | "Received message with %u bytes from peer `%s' at `%s'\n", | 655 | "Received message with %u bytes from peer `%s' at `%s'\n", |
666 | (unsigned int) ntohs (msg->header.size), | 656 | (unsigned int) ntohs (msg->header.size), |
667 | GNUNET_i2s (&msg->sender), | 657 | GNUNET_i2s (&msg->sender), |
668 | GNUNET_a2s (sender_addr, sender_addr_len)); | 658 | GNUNET_a2s (sender_addr, sender_addr_len)); |
669 | #endif | 659 | #endif |
670 | 660 | ||
671 | /* iterate over all embedded messages */ | 661 | /* iterate over all embedded messages */ |
@@ -673,11 +663,10 @@ process_udp_message (struct Plugin *plugin, | |||
673 | si.arg = arg; | 663 | si.arg = arg; |
674 | si.args = args; | 664 | si.args = args; |
675 | GNUNET_SERVER_mst_receive (plugin->mst, | 665 | GNUNET_SERVER_mst_receive (plugin->mst, |
676 | &si, | 666 | &si, |
677 | (const char*) &msg[1], | 667 | (const char *) &msg[1], |
678 | ntohs (msg->header.size) - sizeof (struct UDPMessage), | 668 | ntohs (msg->header.size) - |
679 | GNUNET_YES, | 669 | sizeof (struct UDPMessage), GNUNET_YES, GNUNET_NO); |
680 | GNUNET_NO); | ||
681 | } | 670 | } |
682 | 671 | ||
683 | 672 | ||
@@ -688,26 +677,24 @@ process_udp_message (struct Plugin *plugin, | |||
688 | * @param msg the message | 677 | * @param msg the message |
689 | */ | 678 | */ |
690 | static void | 679 | static void |
691 | fragment_msg_proc (void *cls, | 680 | fragment_msg_proc (void *cls, const struct GNUNET_MessageHeader *msg) |
692 | const struct GNUNET_MessageHeader *msg) | ||
693 | { | 681 | { |
694 | struct ReceiveContext *rc = cls; | 682 | struct ReceiveContext *rc = cls; |
695 | 683 | ||
696 | if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE) | 684 | if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE) |
697 | { | 685 | { |
698 | GNUNET_break (0); | 686 | GNUNET_break (0); |
699 | return; | 687 | return; |
700 | } | 688 | } |
701 | if (ntohs (msg->size) < sizeof(struct UDPMessage)) | 689 | if (ntohs (msg->size) < sizeof (struct UDPMessage)) |
702 | { | 690 | { |
703 | GNUNET_break (0); | 691 | GNUNET_break (0); |
704 | return; | 692 | return; |
705 | } | 693 | } |
706 | process_udp_message (rc->plugin, | 694 | process_udp_message (rc->plugin, |
707 | (const struct UDPMessage*) msg, | 695 | (const struct UDPMessage *) msg, |
708 | rc->src_addr, | 696 | rc->src_addr, rc->addr_len); |
709 | rc->addr_len); | 697 | } |
710 | } | ||
711 | 698 | ||
712 | 699 | ||
713 | /** | 700 | /** |
@@ -718,9 +705,7 @@ fragment_msg_proc (void *cls, | |||
718 | * @param msg ack to transmit | 705 | * @param msg ack to transmit |
719 | */ | 706 | */ |
720 | static void | 707 | static void |
721 | ack_proc (void *cls, | 708 | ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) |
722 | uint32_t id, | ||
723 | const struct GNUNET_MessageHeader *msg) | ||
724 | { | 709 | { |
725 | struct ReceiveContext *rc = cls; | 710 | struct ReceiveContext *rc = cls; |
726 | size_t msize = sizeof (struct UDPMessage) + ntohs (msg->size); | 711 | size_t msize = sizeof (struct UDPMessage) + ntohs (msg->size); |
@@ -729,22 +714,20 @@ ack_proc (void *cls, | |||
729 | 714 | ||
730 | #if DEBUG_UDP | 715 | #if DEBUG_UDP |
731 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 716 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
732 | "udp", | 717 | "udp", |
733 | "Sending ACK to `%s'\n", | 718 | "Sending ACK to `%s'\n", |
734 | GNUNET_a2s (rc->src_addr, | 719 | GNUNET_a2s (rc->src_addr, |
735 | (rc->src_addr->sa_family == AF_INET) | 720 | (rc->src_addr->sa_family == AF_INET) |
736 | ? sizeof (struct sockaddr_in) | 721 | ? sizeof (struct sockaddr_in) |
737 | : sizeof (struct sockaddr_in6))); | 722 | : sizeof (struct sockaddr_in6))); |
738 | #endif | 723 | #endif |
739 | udp = (struct UDPMessage*) buf; | 724 | udp = (struct UDPMessage *) buf; |
740 | udp->header.size = htons ((uint16_t) msize); | 725 | udp->header.size = htons ((uint16_t) msize); |
741 | udp->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK); | 726 | udp->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK); |
742 | udp->reserved = htonl (0); | 727 | udp->reserved = htonl (0); |
743 | udp->sender = *rc->plugin->env->my_identity; | 728 | udp->sender = *rc->plugin->env->my_identity; |
744 | memcpy (&udp[1], msg, ntohs (msg->size)); | 729 | memcpy (&udp[1], msg, ntohs (msg->size)); |
745 | (void) udp_send (rc->plugin, | 730 | (void) udp_send (rc->plugin, rc->src_addr, &udp->header); |
746 | rc->src_addr, | ||
747 | &udp->header); | ||
748 | } | 731 | } |
749 | 732 | ||
750 | 733 | ||
@@ -782,21 +765,18 @@ struct FindReceiveContext | |||
782 | */ | 765 | */ |
783 | static int | 766 | static int |
784 | find_receive_context (void *cls, | 767 | find_receive_context (void *cls, |
785 | struct GNUNET_CONTAINER_HeapNode *node, | 768 | struct GNUNET_CONTAINER_HeapNode *node, |
786 | void *element, | 769 | void *element, GNUNET_CONTAINER_HeapCostType cost) |
787 | GNUNET_CONTAINER_HeapCostType cost) | ||
788 | { | 770 | { |
789 | struct FindReceiveContext *frc = cls; | 771 | struct FindReceiveContext *frc = cls; |
790 | struct ReceiveContext *e = element; | 772 | struct ReceiveContext *e = element; |
791 | 773 | ||
792 | if ( (frc->addr_len == e->addr_len) && | 774 | if ((frc->addr_len == e->addr_len) && |
793 | (0 == memcmp (frc->addr, | 775 | (0 == memcmp (frc->addr, e->src_addr, frc->addr_len))) |
794 | e->src_addr, | 776 | { |
795 | frc->addr_len) ) ) | 777 | frc->rc = e; |
796 | { | 778 | return GNUNET_NO; |
797 | frc->rc = e; | 779 | } |
798 | return GNUNET_NO; | ||
799 | } | ||
800 | return GNUNET_YES; | 780 | return GNUNET_YES; |
801 | } | 781 | } |
802 | 782 | ||
@@ -808,8 +788,7 @@ find_receive_context (void *cls, | |||
808 | * @param rsock socket to read from | 788 | * @param rsock socket to read from |
809 | */ | 789 | */ |
810 | static void | 790 | static void |
811 | udp_read (struct Plugin *plugin, | 791 | udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) |
812 | struct GNUNET_NETWORK_Handle *rsock) | ||
813 | { | 792 | { |
814 | socklen_t fromlen; | 793 | socklen_t fromlen; |
815 | char addr[32]; | 794 | char addr[32]; |
@@ -824,144 +803,142 @@ udp_read (struct Plugin *plugin, | |||
824 | struct FindReceiveContext frc; | 803 | struct FindReceiveContext frc; |
825 | 804 | ||
826 | fromlen = sizeof (addr); | 805 | fromlen = sizeof (addr); |
827 | memset (&addr, 0, sizeof(addr)); | 806 | memset (&addr, 0, sizeof (addr)); |
828 | ret = GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof (buf), | 807 | ret = GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof (buf), |
829 | (struct sockaddr *)&addr, &fromlen); | 808 | (struct sockaddr *) &addr, &fromlen); |
830 | if (ret < sizeof (struct GNUNET_MessageHeader)) | 809 | if (ret < sizeof (struct GNUNET_MessageHeader)) |
831 | { | 810 | { |
832 | GNUNET_break_op (0); | 811 | GNUNET_break_op (0); |
833 | return; | 812 | return; |
834 | } | 813 | } |
835 | #if DEBUG_UDP | 814 | #if DEBUG_UDP |
836 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 815 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
837 | "UDP received %u-byte message from `%s'\n", | 816 | "UDP received %u-byte message from `%s'\n", |
838 | (unsigned int) ret, | 817 | (unsigned int) ret, |
839 | GNUNET_a2s ((const struct sockaddr*) addr, fromlen)); | 818 | GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); |
840 | #endif | 819 | #endif |
841 | msg = (const struct GNUNET_MessageHeader *) buf; | 820 | msg = (const struct GNUNET_MessageHeader *) buf; |
842 | if (ret != ntohs (msg->size)) | 821 | if (ret != ntohs (msg->size)) |
822 | { | ||
823 | GNUNET_break_op (0); | ||
824 | return; | ||
825 | } | ||
826 | switch (ntohs (msg->type)) | ||
827 | { | ||
828 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE: | ||
829 | if (ntohs (msg->size) < sizeof (struct UDPMessage)) | ||
843 | { | 830 | { |
844 | GNUNET_break_op (0); | 831 | GNUNET_break_op (0); |
845 | return; | 832 | return; |
846 | } | 833 | } |
847 | switch (ntohs (msg->type)) | 834 | process_udp_message (plugin, |
835 | (const struct UDPMessage *) msg, | ||
836 | (const struct sockaddr *) addr, fromlen); | ||
837 | return; | ||
838 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK: | ||
839 | if (ntohs (msg->size) < | ||
840 | sizeof (struct UDPMessage) + sizeof (struct GNUNET_MessageHeader)) | ||
848 | { | 841 | { |
849 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE: | 842 | GNUNET_break_op (0); |
850 | if (ntohs (msg->size) < sizeof (struct UDPMessage)) | ||
851 | { | ||
852 | GNUNET_break_op (0); | ||
853 | return; | ||
854 | } | ||
855 | process_udp_message (plugin, | ||
856 | (const struct UDPMessage *) msg, | ||
857 | (const struct sockaddr*) addr, | ||
858 | fromlen); | ||
859 | return; | 843 | return; |
860 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK: | 844 | } |
861 | if (ntohs (msg->size) < sizeof (struct UDPMessage) + sizeof (struct GNUNET_MessageHeader)) | 845 | udp = (const struct UDPMessage *) msg; |
862 | { | 846 | if (ntohl (udp->reserved) != 0) |
863 | GNUNET_break_op (0); | 847 | { |
864 | return; | 848 | GNUNET_break_op (0); |
865 | } | 849 | return; |
866 | udp = (const struct UDPMessage *) msg; | 850 | } |
867 | if (ntohl (udp->reserved) != 0) | 851 | ack = (const struct GNUNET_MessageHeader *) &udp[1]; |
868 | { | 852 | if (ntohs (ack->size) != ntohs (msg->size) - sizeof (struct UDPMessage)) |
869 | GNUNET_break_op (0); | 853 | { |
870 | return; | 854 | GNUNET_break_op (0); |
871 | } | 855 | return; |
872 | ack = (const struct GNUNET_MessageHeader*) &udp[1]; | 856 | } |
873 | if (ntohs (ack->size) != ntohs (msg->size) - sizeof (struct UDPMessage)) | ||
874 | { | ||
875 | GNUNET_break_op (0); | ||
876 | return; | ||
877 | } | ||
878 | #if DEBUG_UDP | 857 | #if DEBUG_UDP |
879 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 858 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
880 | "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", | 859 | "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", |
881 | (unsigned int) ntohs (msg->size), | 860 | (unsigned int) ntohs (msg->size), |
882 | GNUNET_i2s (&udp->sender), | 861 | GNUNET_i2s (&udp->sender), |
883 | GNUNET_a2s ((const struct sockaddr*) addr, fromlen)); | 862 | GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); |
884 | #endif | 863 | #endif |
885 | 864 | ||
886 | peer_session = find_session (plugin, &udp->sender); | 865 | peer_session = find_session (plugin, &udp->sender); |
887 | if (NULL == peer_session) | 866 | if (NULL == peer_session) |
888 | { | 867 | { |
889 | #if DEBUG_UDP | 868 | #if DEBUG_UDP |
890 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 869 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
891 | "Session for ACK not found, dropping ACK!\n"); | 870 | "Session for ACK not found, dropping ACK!\n"); |
892 | #endif | 871 | #endif |
893 | return; | ||
894 | } | ||
895 | if (GNUNET_OK != | ||
896 | GNUNET_FRAGMENT_process_ack (peer_session->frag, | ||
897 | ack)) | ||
898 | return; | ||
899 | GNUNET_assert (GNUNET_OK == | ||
900 | GNUNET_CONTAINER_multihashmap_remove (plugin->sessions, | ||
901 | &udp->sender.hashPubKey, | ||
902 | peer_session)); | ||
903 | plugin->last_expected_delay = GNUNET_FRAGMENT_context_destroy (peer_session->frag); | ||
904 | peer_session->cont (peer_session->cont_cls, | ||
905 | &udp->sender, | ||
906 | GNUNET_OK); | ||
907 | GNUNET_free (peer_session); | ||
908 | return; | 872 | return; |
909 | case GNUNET_MESSAGE_TYPE_FRAGMENT: | 873 | } |
910 | frc.rc = NULL; | 874 | if (GNUNET_OK != GNUNET_FRAGMENT_process_ack (peer_session->frag, ack)) |
911 | frc.addr = (const struct sockaddr*) addr; | 875 | return; |
912 | frc.addr_len = fromlen; | 876 | GNUNET_assert (GNUNET_OK == |
913 | GNUNET_CONTAINER_heap_iterate (plugin->defrags, | 877 | GNUNET_CONTAINER_multihashmap_remove (plugin->sessions, |
914 | &find_receive_context, | 878 | &udp-> |
915 | &frc); | 879 | sender.hashPubKey, |
916 | now = GNUNET_TIME_absolute_get (); | 880 | peer_session)); |
917 | rc = frc.rc; | 881 | plugin->last_expected_delay = |
918 | if (rc == NULL) | 882 | GNUNET_FRAGMENT_context_destroy (peer_session->frag); |
919 | { | 883 | peer_session->cont (peer_session->cont_cls, &udp->sender, GNUNET_OK); |
920 | /* need to create a new RC */ | 884 | GNUNET_free (peer_session); |
921 | rc = GNUNET_malloc (sizeof (struct ReceiveContext) + fromlen); | 885 | return; |
922 | memcpy (&rc[1], addr, fromlen); | 886 | case GNUNET_MESSAGE_TYPE_FRAGMENT: |
923 | rc->src_addr = (const struct sockaddr*) &rc[1]; | 887 | frc.rc = NULL; |
924 | rc->addr_len = fromlen; | 888 | frc.addr = (const struct sockaddr *) addr; |
925 | rc->plugin = plugin; | 889 | frc.addr_len = fromlen; |
926 | rc->defrag = GNUNET_DEFRAGMENT_context_create (plugin->env->stats, | 890 | GNUNET_CONTAINER_heap_iterate (plugin->defrags, |
927 | UDP_MTU, | 891 | &find_receive_context, &frc); |
928 | UDP_MAX_MESSAGES_IN_DEFRAG, | 892 | now = GNUNET_TIME_absolute_get (); |
929 | rc, | 893 | rc = frc.rc; |
930 | &fragment_msg_proc, | 894 | if (rc == NULL) |
931 | &ack_proc); | 895 | { |
932 | rc->hnode = GNUNET_CONTAINER_heap_insert (plugin->defrags, | 896 | /* need to create a new RC */ |
933 | rc, | 897 | rc = GNUNET_malloc (sizeof (struct ReceiveContext) + fromlen); |
934 | (GNUNET_CONTAINER_HeapCostType) now.abs_value); | 898 | memcpy (&rc[1], addr, fromlen); |
935 | } | 899 | rc->src_addr = (const struct sockaddr *) &rc[1]; |
900 | rc->addr_len = fromlen; | ||
901 | rc->plugin = plugin; | ||
902 | rc->defrag = GNUNET_DEFRAGMENT_context_create (plugin->env->stats, | ||
903 | UDP_MTU, | ||
904 | UDP_MAX_MESSAGES_IN_DEFRAG, | ||
905 | rc, | ||
906 | &fragment_msg_proc, | ||
907 | &ack_proc); | ||
908 | rc->hnode = GNUNET_CONTAINER_heap_insert (plugin->defrags, | ||
909 | rc, | ||
910 | (GNUNET_CONTAINER_HeapCostType) | ||
911 | now.abs_value); | ||
912 | } | ||
936 | #if DEBUG_UDP | 913 | #if DEBUG_UDP |
937 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 914 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
938 | "UDP processes %u-byte fragment from `%s'\n", | 915 | "UDP processes %u-byte fragment from `%s'\n", |
939 | (unsigned int) ntohs (msg->size), | 916 | (unsigned int) ntohs (msg->size), |
940 | GNUNET_a2s ((const struct sockaddr*) addr, fromlen)); | 917 | GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); |
941 | #endif | 918 | #endif |
942 | 919 | ||
943 | if (GNUNET_OK == | 920 | if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (rc->defrag, msg)) |
944 | GNUNET_DEFRAGMENT_process_fragment (rc->defrag, | 921 | { |
945 | msg)) | 922 | /* keep this 'rc' from expiring */ |
946 | { | 923 | GNUNET_CONTAINER_heap_update_cost (plugin->defrags, |
947 | /* keep this 'rc' from expiring */ | 924 | rc->hnode, |
948 | GNUNET_CONTAINER_heap_update_cost (plugin->defrags, | 925 | (GNUNET_CONTAINER_HeapCostType) |
949 | rc->hnode, | 926 | now.abs_value); |
950 | (GNUNET_CONTAINER_HeapCostType) now.abs_value); | ||
951 | } | ||
952 | if (GNUNET_CONTAINER_heap_get_size (plugin->defrags) > UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG) | ||
953 | { | ||
954 | /* remove 'rc' that was inactive the longest */ | ||
955 | rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags); | ||
956 | GNUNET_assert (NULL != rc); | ||
957 | GNUNET_DEFRAGMENT_context_destroy (rc->defrag); | ||
958 | GNUNET_free (rc); | ||
959 | } | ||
960 | return; | ||
961 | default: | ||
962 | GNUNET_break_op (0); | ||
963 | return; | ||
964 | } | 927 | } |
928 | if (GNUNET_CONTAINER_heap_get_size (plugin->defrags) > | ||
929 | UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG) | ||
930 | { | ||
931 | /* remove 'rc' that was inactive the longest */ | ||
932 | rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags); | ||
933 | GNUNET_assert (NULL != rc); | ||
934 | GNUNET_DEFRAGMENT_context_destroy (rc->defrag); | ||
935 | GNUNET_free (rc); | ||
936 | } | ||
937 | return; | ||
938 | default: | ||
939 | GNUNET_break_op (0); | ||
940 | return; | ||
941 | } | ||
965 | } | 942 | } |
966 | 943 | ||
967 | 944 | ||
@@ -974,28 +951,25 @@ udp_read (struct Plugin *plugin, | |||
974 | * @param tc the scheduling context (for rescheduling this function again) | 951 | * @param tc the scheduling context (for rescheduling this function again) |
975 | */ | 952 | */ |
976 | static void | 953 | static void |
977 | udp_plugin_select (void *cls, | 954 | udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
978 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
979 | { | 955 | { |
980 | struct Plugin *plugin = cls; | 956 | struct Plugin *plugin = cls; |
981 | 957 | ||
982 | plugin->select_task = GNUNET_SCHEDULER_NO_TASK; | 958 | plugin->select_task = GNUNET_SCHEDULER_NO_TASK; |
983 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 959 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
984 | return; | 960 | return; |
985 | if ( (NULL != plugin->sockv4) && | 961 | if ((NULL != plugin->sockv4) && |
986 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, | 962 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv4))) |
987 | plugin->sockv4)) ) | ||
988 | udp_read (plugin, plugin->sockv4); | 963 | udp_read (plugin, plugin->sockv4); |
989 | if ( (NULL != plugin->sockv6) && | 964 | if ((NULL != plugin->sockv6) && |
990 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, | 965 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv6))) |
991 | plugin->sockv6)) ) | ||
992 | udp_read (plugin, plugin->sockv6); | 966 | udp_read (plugin, plugin->sockv6); |
993 | plugin->select_task = | 967 | plugin->select_task = |
994 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 968 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
995 | GNUNET_SCHEDULER_NO_TASK, | 969 | GNUNET_SCHEDULER_NO_TASK, |
996 | GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs, | 970 | GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs, |
997 | NULL, &udp_plugin_select, plugin); | 971 | NULL, &udp_plugin_select, plugin); |
998 | 972 | ||
999 | } | 973 | } |
1000 | 974 | ||
1001 | 975 | ||
@@ -1011,8 +985,7 @@ udp_plugin_select (void *cls, | |||
1011 | static int | 985 | static int |
1012 | check_port (struct Plugin *plugin, uint16_t in_port) | 986 | check_port (struct Plugin *plugin, uint16_t in_port) |
1013 | { | 987 | { |
1014 | if ( (in_port == plugin->port) || | 988 | if ((in_port == plugin->port) || (in_port == plugin->aport)) |
1015 | (in_port == plugin->aport) ) | ||
1016 | return GNUNET_OK; | 989 | return GNUNET_OK; |
1017 | return GNUNET_SYSERR; | 990 | return GNUNET_SYSERR; |
1018 | } | 991 | } |
@@ -1035,9 +1008,7 @@ check_port (struct Plugin *plugin, uint16_t in_port) | |||
1035 | * | 1008 | * |
1036 | */ | 1009 | */ |
1037 | static int | 1010 | static int |
1038 | udp_plugin_check_address (void *cls, | 1011 | udp_plugin_check_address (void *cls, const void *addr, size_t addrlen) |
1039 | const void *addr, | ||
1040 | size_t addrlen) | ||
1041 | { | 1012 | { |
1042 | struct Plugin *plugin = cls; | 1013 | struct Plugin *plugin = cls; |
1043 | struct IPv4UdpAddress *v4; | 1014 | struct IPv4UdpAddress *v4; |
@@ -1045,37 +1016,35 @@ udp_plugin_check_address (void *cls, | |||
1045 | 1016 | ||
1046 | if ((addrlen != sizeof (struct IPv4UdpAddress)) && | 1017 | if ((addrlen != sizeof (struct IPv4UdpAddress)) && |
1047 | (addrlen != sizeof (struct IPv6UdpAddress))) | 1018 | (addrlen != sizeof (struct IPv6UdpAddress))) |
1048 | { | 1019 | { |
1049 | GNUNET_break_op (0); | 1020 | GNUNET_break_op (0); |
1050 | return GNUNET_SYSERR; | 1021 | return GNUNET_SYSERR; |
1051 | } | 1022 | } |
1052 | if (addrlen == sizeof (struct IPv4UdpAddress)) | 1023 | if (addrlen == sizeof (struct IPv4UdpAddress)) |
1053 | { | 1024 | { |
1054 | v4 = (struct IPv4UdpAddress *) addr; | 1025 | v4 = (struct IPv4UdpAddress *) addr; |
1055 | if (GNUNET_OK != | 1026 | if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port))) |
1056 | check_port (plugin, ntohs (v4->u4_port))) | 1027 | return GNUNET_SYSERR; |
1057 | return GNUNET_SYSERR; | 1028 | if (GNUNET_OK != |
1058 | if (GNUNET_OK != | 1029 | GNUNET_NAT_test_address (plugin->nat, |
1059 | GNUNET_NAT_test_address (plugin->nat, | 1030 | &v4->ipv4_addr, sizeof (struct in_addr))) |
1060 | &v4->ipv4_addr, sizeof (struct in_addr))) | 1031 | return GNUNET_SYSERR; |
1061 | return GNUNET_SYSERR; | 1032 | } |
1062 | } | ||
1063 | else | 1033 | else |
1034 | { | ||
1035 | v6 = (struct IPv6UdpAddress *) addr; | ||
1036 | if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) | ||
1064 | { | 1037 | { |
1065 | v6 = (struct IPv6UdpAddress *) addr; | 1038 | GNUNET_break_op (0); |
1066 | if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) | 1039 | return GNUNET_SYSERR; |
1067 | { | ||
1068 | GNUNET_break_op (0); | ||
1069 | return GNUNET_SYSERR; | ||
1070 | } | ||
1071 | if (GNUNET_OK != | ||
1072 | check_port (plugin, ntohs (v6->u6_port))) | ||
1073 | return GNUNET_SYSERR; | ||
1074 | if (GNUNET_OK != | ||
1075 | GNUNET_NAT_test_address (plugin->nat, | ||
1076 | &v6->ipv6_addr, sizeof (struct in6_addr))) | ||
1077 | return GNUNET_SYSERR; | ||
1078 | } | 1040 | } |
1041 | if (GNUNET_OK != check_port (plugin, ntohs (v6->u6_port))) | ||
1042 | return GNUNET_SYSERR; | ||
1043 | if (GNUNET_OK != | ||
1044 | GNUNET_NAT_test_address (plugin->nat, | ||
1045 | &v6->ipv6_addr, sizeof (struct in6_addr))) | ||
1046 | return GNUNET_SYSERR; | ||
1047 | } | ||
1079 | return GNUNET_OK; | 1048 | return GNUNET_OK; |
1080 | } | 1049 | } |
1081 | 1050 | ||
@@ -1091,10 +1060,8 @@ udp_plugin_check_address (void *cls, | |||
1091 | * @param addrlen length of the address | 1060 | * @param addrlen length of the address |
1092 | * @return string representing the same address | 1061 | * @return string representing the same address |
1093 | */ | 1062 | */ |
1094 | static const char* | 1063 | static const char * |
1095 | udp_address_to_string (void *cls, | 1064 | udp_address_to_string (void *cls, const void *addr, size_t addrlen) |
1096 | const void *addr, | ||
1097 | size_t addrlen) | ||
1098 | { | 1065 | { |
1099 | static char rbuf[INET6_ADDRSTRLEN + 10]; | 1066 | static char rbuf[INET6_ADDRSTRLEN + 10]; |
1100 | char buf[INET6_ADDRSTRLEN]; | 1067 | char buf[INET6_ADDRSTRLEN]; |
@@ -1107,32 +1074,28 @@ udp_address_to_string (void *cls, | |||
1107 | uint16_t port; | 1074 | uint16_t port; |
1108 | 1075 | ||
1109 | if (addrlen == sizeof (struct IPv6UdpAddress)) | 1076 | if (addrlen == sizeof (struct IPv6UdpAddress)) |
1110 | { | 1077 | { |
1111 | t6 = addr; | 1078 | t6 = addr; |
1112 | af = AF_INET6; | 1079 | af = AF_INET6; |
1113 | port = ntohs (t6->u6_port); | 1080 | port = ntohs (t6->u6_port); |
1114 | memcpy (&a6, &t6->ipv6_addr, sizeof (a6)); | 1081 | memcpy (&a6, &t6->ipv6_addr, sizeof (a6)); |
1115 | sb = &a6; | 1082 | sb = &a6; |
1116 | } | 1083 | } |
1117 | else if (addrlen == sizeof (struct IPv4UdpAddress)) | 1084 | else if (addrlen == sizeof (struct IPv4UdpAddress)) |
1118 | { | 1085 | { |
1119 | t4 = addr; | 1086 | t4 = addr; |
1120 | af = AF_INET; | 1087 | af = AF_INET; |
1121 | port = ntohs (t4->u4_port); | 1088 | port = ntohs (t4->u4_port); |
1122 | memcpy (&a4, &t4->ipv4_addr, sizeof (a4)); | 1089 | memcpy (&a4, &t4->ipv4_addr, sizeof (a4)); |
1123 | sb = &a4; | 1090 | sb = &a4; |
1124 | } | 1091 | } |
1125 | else | 1092 | else |
1126 | { | 1093 | { |
1127 | GNUNET_break_op (0); | 1094 | GNUNET_break_op (0); |
1128 | return NULL; | 1095 | return NULL; |
1129 | } | 1096 | } |
1130 | inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); | 1097 | inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); |
1131 | GNUNET_snprintf (rbuf, | 1098 | GNUNET_snprintf (rbuf, sizeof (rbuf), "%s:%u", buf, port); |
1132 | sizeof (rbuf), | ||
1133 | "%s:%u", | ||
1134 | buf, | ||
1135 | port); | ||
1136 | return rbuf; | 1099 | return rbuf; |
1137 | } | 1100 | } |
1138 | 1101 | ||
@@ -1172,15 +1135,12 @@ append_port (void *cls, const char *hostname) | |||
1172 | char *ret; | 1135 | char *ret; |
1173 | 1136 | ||
1174 | if (hostname == NULL) | 1137 | if (hostname == NULL) |
1175 | { | 1138 | { |
1176 | ppc->asc (ppc->asc_cls, NULL); | 1139 | ppc->asc (ppc->asc_cls, NULL); |
1177 | GNUNET_free (ppc); | 1140 | GNUNET_free (ppc); |
1178 | return; | 1141 | return; |
1179 | } | 1142 | } |
1180 | GNUNET_asprintf (&ret, | 1143 | GNUNET_asprintf (&ret, "%s:%d", hostname, ppc->port); |
1181 | "%s:%d", | ||
1182 | hostname, | ||
1183 | ppc->port); | ||
1184 | ppc->asc (ppc->asc_cls, ret); | 1144 | ppc->asc (ppc->asc_cls, ret); |
1185 | GNUNET_free (ret); | 1145 | GNUNET_free (ret); |
1186 | } | 1146 | } |
@@ -1220,50 +1180,45 @@ udp_plugin_address_pretty_printer (void *cls, | |||
1220 | uint16_t port; | 1180 | uint16_t port; |
1221 | 1181 | ||
1222 | if (addrlen == sizeof (struct IPv6UdpAddress)) | 1182 | if (addrlen == sizeof (struct IPv6UdpAddress)) |
1223 | { | 1183 | { |
1224 | u6 = addr; | 1184 | u6 = addr; |
1225 | memset (&a6, 0, sizeof (a6)); | 1185 | memset (&a6, 0, sizeof (a6)); |
1226 | a6.sin6_family = AF_INET6; | 1186 | a6.sin6_family = AF_INET6; |
1227 | #if HAVE_SOCKADDR_IN_SIN_LEN | 1187 | #if HAVE_SOCKADDR_IN_SIN_LEN |
1228 | a6.sin6_len = sizeof (a6); | 1188 | a6.sin6_len = sizeof (a6); |
1229 | #endif | 1189 | #endif |
1230 | a6.sin6_port = u6->u6_port; | 1190 | a6.sin6_port = u6->u6_port; |
1231 | memcpy (&a6.sin6_addr, | 1191 | memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof (struct in6_addr)); |
1232 | &u6->ipv6_addr, | 1192 | port = ntohs (u6->u6_port); |
1233 | sizeof (struct in6_addr)); | 1193 | sb = &a6; |
1234 | port = ntohs (u6->u6_port); | 1194 | sbs = sizeof (a6); |
1235 | sb = &a6; | 1195 | } |
1236 | sbs = sizeof (a6); | ||
1237 | } | ||
1238 | else if (addrlen == sizeof (struct IPv4UdpAddress)) | 1196 | else if (addrlen == sizeof (struct IPv4UdpAddress)) |
1239 | { | 1197 | { |
1240 | u4 = addr; | 1198 | u4 = addr; |
1241 | memset (&a4, 0, sizeof (a4)); | 1199 | memset (&a4, 0, sizeof (a4)); |
1242 | a4.sin_family = AF_INET; | 1200 | a4.sin_family = AF_INET; |
1243 | #if HAVE_SOCKADDR_IN_SIN_LEN | 1201 | #if HAVE_SOCKADDR_IN_SIN_LEN |
1244 | a4.sin_len = sizeof (a4); | 1202 | a4.sin_len = sizeof (a4); |
1245 | #endif | 1203 | #endif |
1246 | a4.sin_port = u4->u4_port; | 1204 | a4.sin_port = u4->u4_port; |
1247 | a4.sin_addr.s_addr = u4->ipv4_addr; | 1205 | a4.sin_addr.s_addr = u4->ipv4_addr; |
1248 | port = ntohs (u4->u4_port); | 1206 | port = ntohs (u4->u4_port); |
1249 | sb = &a4; | 1207 | sb = &a4; |
1250 | sbs = sizeof (a4); | 1208 | sbs = sizeof (a4); |
1251 | } | 1209 | } |
1252 | else | 1210 | else |
1253 | { | 1211 | { |
1254 | /* invalid address */ | 1212 | /* invalid address */ |
1255 | GNUNET_break_op (0); | 1213 | GNUNET_break_op (0); |
1256 | asc (asc_cls, NULL); | 1214 | asc (asc_cls, NULL); |
1257 | return; | 1215 | return; |
1258 | } | 1216 | } |
1259 | ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext)); | 1217 | ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext)); |
1260 | ppc->asc = asc; | 1218 | ppc->asc = asc; |
1261 | ppc->asc_cls = asc_cls; | 1219 | ppc->asc_cls = asc_cls; |
1262 | ppc->port = port; | 1220 | ppc->port = port; |
1263 | GNUNET_RESOLVER_hostname_get (sb, | 1221 | GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, timeout, &append_port, ppc); |
1264 | sbs, | ||
1265 | !numeric, timeout, | ||
1266 | &append_port, ppc); | ||
1267 | } | 1222 | } |
1268 | 1223 | ||
1269 | 1224 | ||
@@ -1278,9 +1233,8 @@ udp_plugin_address_pretty_printer (void *cls, | |||
1278 | */ | 1233 | */ |
1279 | static void | 1234 | static void |
1280 | udp_nat_port_map_callback (void *cls, | 1235 | udp_nat_port_map_callback (void *cls, |
1281 | int add_remove, | 1236 | int add_remove, |
1282 | const struct sockaddr *addr, | 1237 | const struct sockaddr *addr, socklen_t addrlen) |
1283 | socklen_t addrlen) | ||
1284 | { | 1238 | { |
1285 | struct Plugin *plugin = cls; | 1239 | struct Plugin *plugin = cls; |
1286 | struct IPv4UdpAddress u4; | 1240 | struct IPv4UdpAddress u4; |
@@ -1290,31 +1244,29 @@ udp_nat_port_map_callback (void *cls, | |||
1290 | 1244 | ||
1291 | /* convert 'addr' to our internal format */ | 1245 | /* convert 'addr' to our internal format */ |
1292 | switch (addr->sa_family) | 1246 | switch (addr->sa_family) |
1293 | { | 1247 | { |
1294 | case AF_INET: | 1248 | case AF_INET: |
1295 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); | 1249 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); |
1296 | u4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; | 1250 | u4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; |
1297 | u4.u4_port = ((struct sockaddr_in *) addr)->sin_port; | 1251 | u4.u4_port = ((struct sockaddr_in *) addr)->sin_port; |
1298 | arg = &u4; | 1252 | arg = &u4; |
1299 | args = sizeof (u4); | 1253 | args = sizeof (u4); |
1300 | break; | 1254 | break; |
1301 | case AF_INET6: | 1255 | case AF_INET6: |
1302 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); | 1256 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); |
1303 | memcpy (&u6.ipv6_addr, | 1257 | memcpy (&u6.ipv6_addr, |
1304 | &((struct sockaddr_in6 *) addr)->sin6_addr, | 1258 | &((struct sockaddr_in6 *) addr)->sin6_addr, |
1305 | sizeof (struct in6_addr)); | 1259 | sizeof (struct in6_addr)); |
1306 | u6.u6_port = ((struct sockaddr_in6 *) addr)->sin6_port; | 1260 | u6.u6_port = ((struct sockaddr_in6 *) addr)->sin6_port; |
1307 | arg = &u6; | 1261 | arg = &u6; |
1308 | args = sizeof (u6); | 1262 | args = sizeof (u6); |
1309 | break; | 1263 | break; |
1310 | default: | 1264 | default: |
1311 | GNUNET_break (0); | 1265 | GNUNET_break (0); |
1312 | return; | 1266 | return; |
1313 | } | 1267 | } |
1314 | /* modify our published address list */ | 1268 | /* modify our published address list */ |
1315 | plugin->env->notify_address (plugin->env->cls, | 1269 | plugin->env->notify_address (plugin->env->cls, add_remove, arg, args); |
1316 | add_remove, | ||
1317 | arg, args); | ||
1318 | } | 1270 | } |
1319 | 1271 | ||
1320 | 1272 | ||
@@ -1345,38 +1297,32 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1345 | 1297 | ||
1346 | if (GNUNET_OK != | 1298 | if (GNUNET_OK != |
1347 | GNUNET_CONFIGURATION_get_value_number (env->cfg, | 1299 | GNUNET_CONFIGURATION_get_value_number (env->cfg, |
1348 | "transport-udp", | 1300 | "transport-udp", "PORT", &port)) |
1349 | "PORT", | ||
1350 | &port)) | ||
1351 | port = 2086; | 1301 | port = 2086; |
1352 | if (GNUNET_OK != | 1302 | if (GNUNET_OK != |
1353 | GNUNET_CONFIGURATION_get_value_number (env->cfg, | 1303 | GNUNET_CONFIGURATION_get_value_number (env->cfg, |
1354 | "transport-udp", | 1304 | "transport-udp", |
1355 | "MAX_BPS", | 1305 | "MAX_BPS", &udp_max_bps)) |
1356 | &udp_max_bps)) | 1306 | udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical purposes */ |
1357 | udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical purposes */ | ||
1358 | if (GNUNET_OK != | 1307 | if (GNUNET_OK != |
1359 | GNUNET_CONFIGURATION_get_value_number (env->cfg, | 1308 | GNUNET_CONFIGURATION_get_value_number (env->cfg, |
1360 | "transport-udp", | 1309 | "transport-udp", |
1361 | "ADVERTISED_PORT", | 1310 | "ADVERTISED_PORT", &aport)) |
1362 | &aport)) | ||
1363 | aport = port; | 1311 | aport = port; |
1364 | if (port > 65535) | 1312 | if (port > 65535) |
1365 | { | 1313 | { |
1366 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1314 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1367 | _("Given `%s' option is out of range: %llu > %u\n"), | 1315 | _("Given `%s' option is out of range: %llu > %u\n"), |
1368 | "PORT", | 1316 | "PORT", port, 65535); |
1369 | port, | 1317 | return NULL; |
1370 | 65535); | 1318 | } |
1371 | return NULL; | ||
1372 | } | ||
1373 | memset (&serverAddrv6, 0, sizeof (serverAddrv6)); | 1319 | memset (&serverAddrv6, 0, sizeof (serverAddrv6)); |
1374 | memset (&serverAddrv4, 0, sizeof (serverAddrv4)); | 1320 | memset (&serverAddrv4, 0, sizeof (serverAddrv4)); |
1375 | 1321 | ||
1376 | plugin = GNUNET_malloc (sizeof (struct Plugin)); | 1322 | plugin = GNUNET_malloc (sizeof (struct Plugin)); |
1377 | GNUNET_BANDWIDTH_tracker_init (&plugin->tracker, | 1323 | GNUNET_BANDWIDTH_tracker_init (&plugin->tracker, |
1378 | GNUNET_BANDWIDTH_value_init ((uint32_t) udp_max_bps), | 1324 | GNUNET_BANDWIDTH_value_init ((uint32_t) |
1379 | 30); | 1325 | udp_max_bps), 30); |
1380 | plugin->last_expected_delay = GNUNET_TIME_UNIT_SECONDS; | 1326 | plugin->last_expected_delay = GNUNET_TIME_UNIT_SECONDS; |
1381 | plugin->port = port; | 1327 | plugin->port = port; |
1382 | plugin->aport = aport; | 1328 | plugin->aport = aport; |
@@ -1390,178 +1336,167 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1390 | api->address_to_string = &udp_address_to_string; | 1336 | api->address_to_string = &udp_address_to_string; |
1391 | api->check_address = &udp_plugin_check_address; | 1337 | api->check_address = &udp_plugin_check_address; |
1392 | 1338 | ||
1393 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(env->cfg, | 1339 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg, |
1394 | "transport-udp", | 1340 | "transport-udp", |
1395 | "BINDTO", | 1341 | "BINDTO", |
1396 | &plugin->bind4_address)) | 1342 | &plugin->bind4_address)) |
1343 | { | ||
1344 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1345 | "Binding udp plugin to specific address: `%s'\n", | ||
1346 | plugin->bind4_address); | ||
1347 | if (1 != inet_pton (AF_INET, plugin->bind4_address, &serverAddrv4.sin_addr)) | ||
1397 | { | 1348 | { |
1398 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1349 | GNUNET_free (plugin->bind4_address); |
1399 | "Binding udp plugin to specific address: `%s'\n", | 1350 | GNUNET_free (plugin); |
1400 | plugin->bind4_address); | 1351 | GNUNET_free (api); |
1401 | if (1 != inet_pton(AF_INET, | 1352 | return NULL; |
1402 | plugin->bind4_address, | ||
1403 | &serverAddrv4.sin_addr)) | ||
1404 | { | ||
1405 | GNUNET_free (plugin->bind4_address); | ||
1406 | GNUNET_free (plugin); | ||
1407 | GNUNET_free (api); | ||
1408 | return NULL; | ||
1409 | } | ||
1410 | } | 1353 | } |
1411 | 1354 | } | |
1412 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(env->cfg, | 1355 | |
1413 | "transport-udp", | 1356 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg, |
1414 | "BINDTO6", | 1357 | "transport-udp", |
1415 | &plugin->bind6_address)) | 1358 | "BINDTO6", |
1359 | &plugin->bind6_address)) | ||
1360 | { | ||
1361 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1362 | "Binding udp plugin to specific address: `%s'\n", | ||
1363 | plugin->bind6_address); | ||
1364 | if (1 != inet_pton (AF_INET6, | ||
1365 | plugin->bind6_address, &serverAddrv6.sin6_addr)) | ||
1416 | { | 1366 | { |
1417 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1367 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1418 | "Binding udp plugin to specific address: `%s'\n", | 1368 | _("Invalid IPv6 address: `%s'\n"), plugin->bind6_address); |
1419 | plugin->bind6_address); | 1369 | GNUNET_free_non_null (plugin->bind4_address); |
1420 | if (1 != inet_pton(AF_INET6, | 1370 | GNUNET_free (plugin->bind6_address); |
1421 | plugin->bind6_address, | 1371 | GNUNET_free (plugin); |
1422 | &serverAddrv6.sin6_addr)) | 1372 | GNUNET_free (api); |
1423 | { | 1373 | return NULL; |
1424 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
1425 | _("Invalid IPv6 address: `%s'\n"), | ||
1426 | plugin->bind6_address); | ||
1427 | GNUNET_free_non_null (plugin->bind4_address); | ||
1428 | GNUNET_free (plugin->bind6_address); | ||
1429 | GNUNET_free (plugin); | ||
1430 | GNUNET_free (api); | ||
1431 | return NULL; | ||
1432 | } | ||
1433 | } | 1374 | } |
1375 | } | ||
1434 | 1376 | ||
1435 | plugin->defrags = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 1377 | plugin->defrags = |
1436 | plugin->sessions = GNUNET_CONTAINER_multihashmap_create (UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG * 2); | 1378 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
1379 | plugin->sessions = | ||
1380 | GNUNET_CONTAINER_multihashmap_create (UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG | ||
1381 | * 2); | ||
1437 | sockets_created = 0; | 1382 | sockets_created = 0; |
1438 | if ( (GNUNET_YES != | 1383 | if ((GNUNET_YES != |
1439 | GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, | 1384 | GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, |
1440 | "nat", | 1385 | "nat", "DISABLEV6"))) |
1441 | "DISABLEV6"))) | 1386 | { |
1387 | plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0); | ||
1388 | if (NULL == plugin->sockv6) | ||
1389 | { | ||
1390 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket"); | ||
1391 | } | ||
1392 | else | ||
1442 | { | 1393 | { |
1443 | plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0); | ||
1444 | if (NULL == plugin->sockv6) | ||
1445 | { | ||
1446 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket"); | ||
1447 | } | ||
1448 | else | ||
1449 | { | ||
1450 | #if HAVE_SOCKADDR_IN_SIN_LEN | 1394 | #if HAVE_SOCKADDR_IN_SIN_LEN |
1451 | serverAddrv6.sin6_len = sizeof (serverAddrv6); | 1395 | serverAddrv6.sin6_len = sizeof (serverAddrv6); |
1452 | #endif | 1396 | #endif |
1453 | serverAddrv6.sin6_family = AF_INET6; | 1397 | serverAddrv6.sin6_family = AF_INET6; |
1454 | serverAddrv6.sin6_addr = in6addr_any; | 1398 | serverAddrv6.sin6_addr = in6addr_any; |
1455 | serverAddrv6.sin6_port = htons (plugin->port); | 1399 | serverAddrv6.sin6_port = htons (plugin->port); |
1456 | addrlen = sizeof (serverAddrv6); | 1400 | addrlen = sizeof (serverAddrv6); |
1457 | serverAddr = (struct sockaddr *) &serverAddrv6; | 1401 | serverAddr = (struct sockaddr *) &serverAddrv6; |
1458 | #if DEBUG_UDP | 1402 | #if DEBUG_UDP |
1459 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1403 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1460 | "Binding to IPv6 port %d\n", | 1404 | "Binding to IPv6 port %d\n", ntohs (serverAddrv6.sin6_port)); |
1461 | ntohs(serverAddrv6.sin6_port)); | ||
1462 | #endif | 1405 | #endif |
1463 | tries = 0; | 1406 | tries = 0; |
1464 | while (GNUNET_NETWORK_socket_bind (plugin->sockv6, | 1407 | while (GNUNET_NETWORK_socket_bind (plugin->sockv6, |
1465 | serverAddr, addrlen) != | 1408 | serverAddr, addrlen) != GNUNET_OK) |
1466 | GNUNET_OK) | 1409 | { |
1467 | { | 1410 | serverAddrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ |
1468 | serverAddrv6.sin6_port | ||
1469 | = htons (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ | ||
1470 | #if DEBUG_UDP | 1411 | #if DEBUG_UDP |
1471 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1412 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1472 | "IPv6 Binding failed, trying new port %d\n", | 1413 | "IPv6 Binding failed, trying new port %d\n", |
1473 | ntohs(serverAddrv6.sin6_port)); | 1414 | ntohs (serverAddrv6.sin6_port)); |
1474 | #endif | 1415 | #endif |
1475 | tries++; | 1416 | tries++; |
1476 | if (tries > 10) | 1417 | if (tries > 10) |
1477 | { | 1418 | { |
1478 | GNUNET_NETWORK_socket_close (plugin->sockv6); | 1419 | GNUNET_NETWORK_socket_close (plugin->sockv6); |
1479 | plugin->sockv6 = NULL; | 1420 | plugin->sockv6 = NULL; |
1480 | break; | 1421 | break; |
1481 | } | 1422 | } |
1482 | } | 1423 | } |
1483 | if (plugin->sockv6 != NULL) | 1424 | if (plugin->sockv6 != NULL) |
1484 | { | 1425 | { |
1485 | addrs[sockets_created] = (struct sockaddr*) &serverAddrv6; | 1426 | addrs[sockets_created] = (struct sockaddr *) &serverAddrv6; |
1486 | addrlens[sockets_created] = sizeof (serverAddrv6); | 1427 | addrlens[sockets_created] = sizeof (serverAddrv6); |
1487 | sockets_created++; | 1428 | sockets_created++; |
1488 | } | 1429 | } |
1489 | } | ||
1490 | } | 1430 | } |
1431 | } | ||
1491 | 1432 | ||
1492 | plugin->mst = GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages, | 1433 | plugin->mst = GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages, |
1493 | plugin); | 1434 | plugin); |
1494 | plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0); | 1435 | plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0); |
1495 | if (NULL == plugin->sockv4) | 1436 | if (NULL == plugin->sockv4) |
1496 | { | 1437 | { |
1497 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket"); | 1438 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket"); |
1498 | } | 1439 | } |
1499 | else | 1440 | else |
1500 | { | 1441 | { |
1501 | #if HAVE_SOCKADDR_IN_SIN_LEN | 1442 | #if HAVE_SOCKADDR_IN_SIN_LEN |
1502 | serverAddrv4.sin_len = sizeof (serverAddrv4); | 1443 | serverAddrv4.sin_len = sizeof (serverAddrv4); |
1503 | #endif | 1444 | #endif |
1504 | serverAddrv4.sin_family = AF_INET; | 1445 | serverAddrv4.sin_family = AF_INET; |
1505 | serverAddrv4.sin_addr.s_addr = INADDR_ANY; | 1446 | serverAddrv4.sin_addr.s_addr = INADDR_ANY; |
1506 | serverAddrv4.sin_port = htons (plugin->port); | 1447 | serverAddrv4.sin_port = htons (plugin->port); |
1507 | addrlen = sizeof (serverAddrv4); | 1448 | addrlen = sizeof (serverAddrv4); |
1508 | serverAddr = (struct sockaddr *) &serverAddrv4; | 1449 | serverAddr = (struct sockaddr *) &serverAddrv4; |
1509 | #if DEBUG_UDP | 1450 | #if DEBUG_UDP |
1510 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1451 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1511 | "Binding to IPv4 port %d\n", | 1452 | "Binding to IPv4 port %d\n", ntohs (serverAddrv4.sin_port)); |
1512 | ntohs(serverAddrv4.sin_port)); | ||
1513 | #endif | 1453 | #endif |
1514 | tries = 0; | 1454 | tries = 0; |
1515 | while (GNUNET_NETWORK_socket_bind (plugin->sockv4, serverAddr, addrlen) != | 1455 | while (GNUNET_NETWORK_socket_bind (plugin->sockv4, serverAddr, addrlen) != |
1516 | GNUNET_OK) | 1456 | GNUNET_OK) |
1517 | { | 1457 | { |
1518 | serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ | 1458 | serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ |
1519 | #if DEBUG_UDP | 1459 | #if DEBUG_UDP |
1520 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1460 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1521 | "IPv4 Binding failed, trying new port %d\n", | 1461 | "IPv4 Binding failed, trying new port %d\n", |
1522 | ntohs(serverAddrv4.sin_port)); | 1462 | ntohs (serverAddrv4.sin_port)); |
1523 | #endif | 1463 | #endif |
1524 | tries++; | 1464 | tries++; |
1525 | if (tries > 10) | 1465 | if (tries > 10) |
1526 | { | 1466 | { |
1527 | GNUNET_NETWORK_socket_close (plugin->sockv4); | 1467 | GNUNET_NETWORK_socket_close (plugin->sockv4); |
1528 | plugin->sockv4 = NULL; | 1468 | plugin->sockv4 = NULL; |
1529 | break; | 1469 | break; |
1530 | } | 1470 | } |
1531 | } | ||
1532 | if (plugin->sockv4 != NULL) | ||
1533 | { | ||
1534 | addrs[sockets_created] = (struct sockaddr*) &serverAddrv4; | ||
1535 | addrlens[sockets_created] = sizeof (serverAddrv4); | ||
1536 | sockets_created++; | ||
1537 | } | ||
1538 | } | 1471 | } |
1472 | if (plugin->sockv4 != NULL) | ||
1473 | { | ||
1474 | addrs[sockets_created] = (struct sockaddr *) &serverAddrv4; | ||
1475 | addrlens[sockets_created] = sizeof (serverAddrv4); | ||
1476 | sockets_created++; | ||
1477 | } | ||
1478 | } | ||
1539 | 1479 | ||
1540 | plugin->rs = GNUNET_NETWORK_fdset_create (); | 1480 | plugin->rs = GNUNET_NETWORK_fdset_create (); |
1541 | GNUNET_NETWORK_fdset_zero (plugin->rs); | 1481 | GNUNET_NETWORK_fdset_zero (plugin->rs); |
1542 | if (NULL != plugin->sockv4) | 1482 | if (NULL != plugin->sockv4) |
1543 | GNUNET_NETWORK_fdset_set (plugin->rs, | 1483 | GNUNET_NETWORK_fdset_set (plugin->rs, plugin->sockv4); |
1544 | plugin->sockv4); | ||
1545 | if (NULL != plugin->sockv6) | 1484 | if (NULL != plugin->sockv6) |
1546 | GNUNET_NETWORK_fdset_set (plugin->rs, | 1485 | GNUNET_NETWORK_fdset_set (plugin->rs, plugin->sockv6); |
1547 | plugin->sockv6); | ||
1548 | 1486 | ||
1549 | plugin->select_task = | 1487 | plugin->select_task = |
1550 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 1488 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
1551 | GNUNET_SCHEDULER_NO_TASK, | 1489 | GNUNET_SCHEDULER_NO_TASK, |
1552 | GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs, | 1490 | GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs, |
1553 | NULL, &udp_plugin_select, plugin); | 1491 | NULL, &udp_plugin_select, plugin); |
1554 | if (sockets_created == 0) | 1492 | if (sockets_created == 0) |
1555 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1493 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to open UDP sockets\n")); |
1556 | _("Failed to open UDP sockets\n")); | ||
1557 | plugin->nat = GNUNET_NAT_register (env->cfg, | 1494 | plugin->nat = GNUNET_NAT_register (env->cfg, |
1558 | GNUNET_NO, | 1495 | GNUNET_NO, |
1559 | port, | 1496 | port, |
1560 | sockets_created, | 1497 | sockets_created, |
1561 | (const struct sockaddr**) addrs, addrlens, | 1498 | (const struct sockaddr **) addrs, addrlens, |
1562 | &udp_nat_port_map_callback, | 1499 | &udp_nat_port_map_callback, NULL, plugin); |
1563 | NULL, | ||
1564 | plugin); | ||
1565 | return api; | 1500 | return api; |
1566 | } | 1501 | } |
1567 | 1502 | ||
@@ -1575,9 +1510,7 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1575 | * @return GNUNET_OK (continue to iterate) | 1510 | * @return GNUNET_OK (continue to iterate) |
1576 | */ | 1511 | */ |
1577 | static int | 1512 | static int |
1578 | destroy_session (void *cls, | 1513 | destroy_session (void *cls, const GNUNET_HashCode * key, void *value) |
1579 | const GNUNET_HashCode *key, | ||
1580 | void *value) | ||
1581 | { | 1514 | { |
1582 | struct PeerSession *peer_session = value; | 1515 | struct PeerSession *peer_session = value; |
1583 | 1516 | ||
@@ -1602,32 +1535,31 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
1602 | 1535 | ||
1603 | /* FIXME: clean up heap and hashmap */ | 1536 | /* FIXME: clean up heap and hashmap */ |
1604 | GNUNET_CONTAINER_multihashmap_iterate (plugin->sessions, | 1537 | GNUNET_CONTAINER_multihashmap_iterate (plugin->sessions, |
1605 | &destroy_session, | 1538 | &destroy_session, NULL); |
1606 | NULL); | ||
1607 | GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions); | 1539 | GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions); |
1608 | plugin->sessions = NULL; | 1540 | plugin->sessions = NULL; |
1609 | while (NULL != (rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags))) | 1541 | while (NULL != (rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags))) |
1610 | { | 1542 | { |
1611 | GNUNET_DEFRAGMENT_context_destroy (rc->defrag); | 1543 | GNUNET_DEFRAGMENT_context_destroy (rc->defrag); |
1612 | GNUNET_free (rc); | 1544 | GNUNET_free (rc); |
1613 | } | 1545 | } |
1614 | GNUNET_CONTAINER_heap_destroy (plugin->defrags); | 1546 | GNUNET_CONTAINER_heap_destroy (plugin->defrags); |
1615 | 1547 | ||
1616 | if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK) | 1548 | if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK) |
1617 | { | 1549 | { |
1618 | GNUNET_SCHEDULER_cancel (plugin->select_task); | 1550 | GNUNET_SCHEDULER_cancel (plugin->select_task); |
1619 | plugin->select_task = GNUNET_SCHEDULER_NO_TASK; | 1551 | plugin->select_task = GNUNET_SCHEDULER_NO_TASK; |
1620 | } | 1552 | } |
1621 | if (plugin->sockv4 != NULL) | 1553 | if (plugin->sockv4 != NULL) |
1622 | { | 1554 | { |
1623 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4)); | 1555 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4)); |
1624 | plugin->sockv4 = NULL; | 1556 | plugin->sockv4 = NULL; |
1625 | } | 1557 | } |
1626 | if (plugin->sockv6 != NULL) | 1558 | if (plugin->sockv6 != NULL) |
1627 | { | 1559 | { |
1628 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6)); | 1560 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6)); |
1629 | plugin->sockv6 = NULL; | 1561 | plugin->sockv6 = NULL; |
1630 | } | 1562 | } |
1631 | GNUNET_SERVER_mst_destroy (plugin->mst); | 1563 | GNUNET_SERVER_mst_destroy (plugin->mst); |
1632 | GNUNET_NETWORK_fdset_destroy (plugin->rs); | 1564 | GNUNET_NETWORK_fdset_destroy (plugin->rs); |
1633 | GNUNET_NAT_unregister (plugin->nat); | 1565 | GNUNET_NAT_unregister (plugin->nat); |