diff options
Diffstat (limited to 'src/transport/plugin_transport_udp_new.c')
-rw-r--r-- | src/transport/plugin_transport_udp_new.c | 222 |
1 files changed, 115 insertions, 107 deletions
diff --git a/src/transport/plugin_transport_udp_new.c b/src/transport/plugin_transport_udp_new.c index 325c5d893..7eb4cbe87 100644 --- a/src/transport/plugin_transport_udp_new.c +++ b/src/transport/plugin_transport_udp_new.c | |||
@@ -299,21 +299,22 @@ struct Plugin | |||
299 | 299 | ||
300 | }; | 300 | }; |
301 | 301 | ||
302 | int delete_session_iterator (void *cls, | 302 | int |
303 | const GNUNET_HashCode * key, | 303 | delete_session_iterator (void *cls, const GNUNET_HashCode * key, void *value) |
304 | void *value) | ||
305 | { | 304 | { |
306 | struct Session *s = (struct Session *) value; | 305 | struct Session *s = (struct Session *) value; |
306 | |||
307 | if (s->invalidation_task != GNUNET_SCHEDULER_NO_TASK) | 307 | if (s->invalidation_task != GNUNET_SCHEDULER_NO_TASK) |
308 | { | 308 | { |
309 | GNUNET_SCHEDULER_cancel(s->invalidation_task); | 309 | GNUNET_SCHEDULER_cancel (s->invalidation_task); |
310 | s->invalidation_task = GNUNET_SCHEDULER_NO_TASK; | 310 | s->invalidation_task = GNUNET_SCHEDULER_NO_TASK; |
311 | } | 311 | } |
312 | GNUNET_CONTAINER_multihashmap_remove(s->plugin->sessions, key, s); | 312 | GNUNET_CONTAINER_multihashmap_remove (s->plugin->sessions, key, s); |
313 | 313 | ||
314 | GNUNET_free (s); | 314 | GNUNET_free (s); |
315 | return GNUNET_YES; | 315 | return GNUNET_YES; |
316 | } | 316 | } |
317 | |||
317 | /** | 318 | /** |
318 | * Disconnect from a remote node. Clean up session if we have one for this peer | 319 | * Disconnect from a remote node. Clean up session if we have one for this peer |
319 | * | 320 | * |
@@ -326,7 +327,8 @@ udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) | |||
326 | { | 327 | { |
327 | struct Plugin *plugin = cls; | 328 | struct Plugin *plugin = cls; |
328 | 329 | ||
329 | GNUNET_CONTAINER_multihashmap_get_multiple(plugin, &target->hashPubKey, &delete_session_iterator, NULL); | 330 | GNUNET_CONTAINER_multihashmap_get_multiple (plugin, &target->hashPubKey, |
331 | &delete_session_iterator, NULL); | ||
330 | 332 | ||
331 | } | 333 | } |
332 | 334 | ||
@@ -370,25 +372,25 @@ udp_send (struct Plugin *plugin, const struct sockaddr *sa, | |||
370 | { | 372 | { |
371 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto"); | 373 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto"); |
372 | LOG (GNUNET_ERROR_TYPE_ERROR, | 374 | LOG (GNUNET_ERROR_TYPE_ERROR, |
373 | "UDP transmited %u-byte message to %s (%d: %s)\n", | 375 | "UDP transmited %u-byte message to %s (%d: %s)\n", |
374 | (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), | 376 | (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), (int) sent, |
375 | (int) sent, (sent < 0) ? STRERROR (errno) : "ok"); | 377 | (sent < 0) ? STRERROR (errno) : "ok"); |
376 | 378 | ||
377 | } | 379 | } |
378 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 380 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
379 | "UDP transmited %u-byte message to %s (%d: %s)\n", | 381 | "UDP transmited %u-byte message to %s (%d: %s)\n", |
380 | (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), | 382 | (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), (int) sent, |
381 | (int) sent, (sent < 0) ? STRERROR (errno) : "ok"); | 383 | (sent < 0) ? STRERROR (errno) : "ok"); |
382 | return sent; | 384 | return sent; |
383 | } | 385 | } |
384 | 386 | ||
385 | 387 | ||
386 | static struct Session * | 388 | static struct Session * |
387 | create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, | 389 | create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, |
388 | const void *addr, size_t addrlen, | 390 | const void *addr, size_t addrlen, |
389 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) | 391 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) |
390 | { | 392 | { |
391 | struct Session * s; | 393 | struct Session *s; |
392 | const struct IPv4UdpAddress *t4; | 394 | const struct IPv4UdpAddress *t4; |
393 | const struct IPv6UdpAddress *t6; | 395 | const struct IPv6UdpAddress *t6; |
394 | struct sockaddr_in *v4; | 396 | struct sockaddr_in *v4; |
@@ -403,9 +405,7 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, | |||
403 | return NULL; | 405 | return NULL; |
404 | } | 406 | } |
405 | t4 = addr; | 407 | t4 = addr; |
406 | s = | 408 | s = GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in)); |
407 | GNUNET_malloc (sizeof (struct Session) + | ||
408 | sizeof (struct sockaddr_in)); | ||
409 | len = sizeof (struct sockaddr_in); | 409 | len = sizeof (struct sockaddr_in); |
410 | v4 = (struct sockaddr_in *) &s[1]; | 410 | v4 = (struct sockaddr_in *) &s[1]; |
411 | v4->sin_family = AF_INET; | 411 | v4->sin_family = AF_INET; |
@@ -421,9 +421,7 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, | |||
421 | return NULL; | 421 | return NULL; |
422 | } | 422 | } |
423 | t6 = addr; | 423 | t6 = addr; |
424 | s = | 424 | s = GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in6)); |
425 | GNUNET_malloc (sizeof (struct Session) + | ||
426 | sizeof (struct sockaddr_in6)); | ||
427 | len = sizeof (struct sockaddr_in6); | 425 | len = sizeof (struct sockaddr_in6); |
428 | v6 = (struct sockaddr_in6 *) &s[1]; | 426 | v6 = (struct sockaddr_in6 *) &s[1]; |
429 | v6->sin6_family = AF_INET6; | 427 | v6->sin6_family = AF_INET6; |
@@ -457,13 +455,17 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, | |||
457 | static void | 455 | static void |
458 | invalidation_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 456 | invalidation_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
459 | { | 457 | { |
460 | struct Session * s = cls; | 458 | struct Session *s = cls; |
461 | s->invalidation_task = GNUNET_SCHEDULER_NO_TASK; | ||
462 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
463 | "Session %X (`%s') is now invalid\n", s, GNUNET_a2s (s->sock_addr,s->addrlen)); | ||
464 | 459 | ||
465 | s->plugin->env->session_end(s->plugin->env->cls, &s->target, s); | 460 | s->invalidation_task = GNUNET_SCHEDULER_NO_TASK; |
466 | GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(s->plugin->sessions, &s->target.hashPubKey, s)); | 461 | LOG (GNUNET_ERROR_TYPE_ERROR, "Session %X (`%s') is now invalid\n", s, |
462 | GNUNET_a2s (s->sock_addr, s->addrlen)); | ||
463 | |||
464 | s->plugin->env->session_end (s->plugin->env->cls, &s->target, s); | ||
465 | GNUNET_assert (GNUNET_YES == | ||
466 | GNUNET_CONTAINER_multihashmap_remove (s->plugin->sessions, | ||
467 | &s->target.hashPubKey, | ||
468 | s)); | ||
467 | GNUNET_free (s); | 469 | GNUNET_free (s); |
468 | } | 470 | } |
469 | 471 | ||
@@ -534,10 +536,10 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, | |||
534 | } | 536 | } |
535 | 537 | ||
536 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 538 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
537 | "UDP transmits %u-byte message to `%s' using address `%s' session 0x%X mode %i\n", | 539 | "UDP transmits %u-byte message to `%s' using address `%s' session 0x%X mode %i\n", |
538 | msgbuf_size, GNUNET_i2s (target), | 540 | msgbuf_size, GNUNET_i2s (target), udp_address_to_string (NULL, addr, |
539 | udp_address_to_string (NULL, addr, addrlen), | 541 | addrlen), |
540 | session, force_address); | 542 | session, force_address); |
541 | 543 | ||
542 | /* no valid address given */ | 544 | /* no valid address given */ |
543 | if ((addr = NULL) || (addrlen == 0)) | 545 | if ((addr = NULL) || (addrlen == 0)) |
@@ -562,10 +564,13 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, | |||
562 | if (force_address == GNUNET_SYSERR) | 564 | if (force_address == GNUNET_SYSERR) |
563 | return GNUNET_SYSERR; | 565 | return GNUNET_SYSERR; |
564 | /* create new session */ | 566 | /* create new session */ |
565 | s = create_session(plugin, target, addr, addrlen, cont, cont_cls); | 567 | s = create_session (plugin, target, addr, addrlen, cont, cont_cls); |
566 | GNUNET_CONTAINER_multihashmap_put(plugin->sessions, &target->hashPubKey, s, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 568 | GNUNET_CONTAINER_multihashmap_put (plugin->sessions, &target->hashPubKey, s, |
569 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
567 | /* schedule invalidation task */ | 570 | /* schedule invalidation task */ |
568 | s->invalidation_task = GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &invalidation_task, NULL); | 571 | s->invalidation_task = |
572 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | ||
573 | &invalidation_task, NULL); | ||
569 | } | 574 | } |
570 | 575 | ||
571 | /* Message */ | 576 | /* Message */ |
@@ -576,12 +581,16 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, | |||
576 | udp->sender = *plugin->env->my_identity; | 581 | udp->sender = *plugin->env->my_identity; |
577 | memcpy (&udp[1], msgbuf, msgbuf_size); | 582 | memcpy (&udp[1], msgbuf, msgbuf_size); |
578 | 583 | ||
579 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); | 584 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); |
585 | |||
580 | if (s->flow_delay_from_other_peer.abs_value > now.abs_value) | 586 | if (s->flow_delay_from_other_peer.abs_value > now.abs_value) |
581 | { | 587 | { |
582 | struct GNUNET_TIME_Relative delta = GNUNET_TIME_absolute_get_difference(now, s->flow_delay_from_other_peer); | 588 | struct GNUNET_TIME_Relative delta = |
583 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 589 | GNUNET_TIME_absolute_get_difference (now, |
584 | "We try to send to early! Should in %llu!\n", delta.rel_value); | 590 | s->flow_delay_from_other_peer); |
591 | |||
592 | LOG (GNUNET_ERROR_TYPE_DEBUG, "We try to send to early! Should in %llu!\n", | ||
593 | delta.rel_value); | ||
585 | } | 594 | } |
586 | else | 595 | else |
587 | LOG (GNUNET_ERROR_TYPE_DEBUG, "We can send!\n"); | 596 | LOG (GNUNET_ERROR_TYPE_DEBUG, "We can send!\n"); |
@@ -598,11 +607,11 @@ udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, | |||
598 | /* send with fragmentation */ | 607 | /* send with fragmentation */ |
599 | else | 608 | else |
600 | { | 609 | { |
601 | s->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats, UDP_MTU, | 610 | s->frag = |
611 | GNUNET_FRAGMENT_context_create (plugin->env->stats, UDP_MTU, | ||
602 | &plugin->tracker, | 612 | &plugin->tracker, |
603 | plugin->last_expected_delay, | 613 | plugin->last_expected_delay, |
604 | &udp->header, &send_fragment, | 614 | &udp->header, &send_fragment, s); |
605 | s); | ||
606 | } | 615 | } |
607 | return mlen; | 616 | return mlen; |
608 | } | 617 | } |
@@ -621,7 +630,7 @@ process_inbound_tokenized_messages (void *cls, void *client, | |||
621 | const struct GNUNET_MessageHeader *hdr) | 630 | const struct GNUNET_MessageHeader *hdr) |
622 | { | 631 | { |
623 | struct Plugin *plugin = cls; | 632 | struct Plugin *plugin = cls; |
624 | struct Session * s = client; | 633 | struct Session *s = client; |
625 | struct GNUNET_ATS_Information distance; | 634 | struct GNUNET_ATS_Information distance; |
626 | struct GNUNET_TIME_Relative delay; | 635 | struct GNUNET_TIME_Relative delay; |
627 | 636 | ||
@@ -629,11 +638,12 @@ process_inbound_tokenized_messages (void *cls, void *client, | |||
629 | distance.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); | 638 | distance.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); |
630 | distance.value = htonl (1); | 639 | distance.value = htonl (1); |
631 | 640 | ||
632 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 641 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Giving Session %X %s to transport\n", |
633 | "Giving Session %X %s to transport\n", s->session, GNUNET_i2s(&s->target)); | 642 | s->session, GNUNET_i2s (&s->target)); |
634 | delay = plugin->env->receive (plugin->env->cls, &s->target, hdr, &distance, 1, s, | 643 | delay = |
635 | // FIXME: USE UDP ADDRESSES!!!! | 644 | plugin->env->receive (plugin->env->cls, &s->target, hdr, &distance, 1, s, |
636 | s->sock_addr, s->addrlen); | 645 | // FIXME: USE UDP ADDRESSES!!!! |
646 | s->sock_addr, s->addrlen); | ||
637 | s->flow_delay_for_other_peer = delay; | 647 | s->flow_delay_for_other_peer = delay; |
638 | } | 648 | } |
639 | 649 | ||
@@ -691,54 +701,54 @@ process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, | |||
691 | } | 701 | } |
692 | #if DEBUG_UDP | 702 | #if DEBUG_UDP |
693 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 703 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
694 | "Received message with %u bytes from peer `%s' at `%s'\n", | 704 | "Received message with %u bytes from peer `%s' at `%s'\n", |
695 | (unsigned int) ntohs (msg->header.size), | 705 | (unsigned int) ntohs (msg->header.size), GNUNET_i2s (&msg->sender), |
696 | GNUNET_i2s (&msg->sender), GNUNET_a2s (sender_addr, | 706 | GNUNET_a2s (sender_addr, sender_addr_len)); |
697 | sender_addr_len)); | ||
698 | #endif | 707 | #endif |
699 | 708 | ||
700 | const struct UDPMessage * udp_msg = (const struct UDPMessage *) msg; | 709 | const struct UDPMessage *udp_msg = (const struct UDPMessage *) msg; |
710 | |||
701 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 711 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
702 | "Lookup inbound UDP sessions for peer `%s' address `%s'\n", | 712 | "Lookup inbound UDP sessions for peer `%s' address `%s'\n", |
703 | GNUNET_i2s (&udp_msg->sender), | 713 | GNUNET_i2s (&udp_msg->sender), udp_address_to_string (NULL, arg, args)); |
704 | udp_address_to_string(NULL, arg, args)); | ||
705 | 714 | ||
706 | /* create a session for inbound connections */ | 715 | /* create a session for inbound connections */ |
707 | struct Session * s = NULL; | 716 | struct Session *s = NULL; |
708 | s = find_inbound_session (plugin, &udp_msg->sender, sender_addr, sender_addr_len); | 717 | |
718 | s = find_inbound_session (plugin, &udp_msg->sender, sender_addr, | ||
719 | sender_addr_len); | ||
709 | 720 | ||
710 | if (s != NULL) | 721 | if (s != NULL) |
711 | { | 722 | { |
712 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 723 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
713 | "Found existing inbound UDP sessions 0x%X for peer `%s' address `%s'\n", | 724 | "Found existing inbound UDP sessions 0x%X for peer `%s' address `%s'\n", |
714 | s, | 725 | s, GNUNET_i2s (&s->target), udp_address_to_string (NULL, arg, args)); |
715 | GNUNET_i2s (&s->target), | ||
716 | udp_address_to_string(NULL, arg, args)); | ||
717 | } | 726 | } |
718 | else | 727 | else |
719 | { | 728 | { |
720 | s = create_session (plugin, &udp_msg->sender, arg, args, NULL, NULL); | 729 | s = create_session (plugin, &udp_msg->sender, arg, args, NULL, NULL); |
721 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 730 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
722 | "Creating inbound UDP sessions 0x%X for peer `%s' address `%s'\n", | 731 | "Creating inbound UDP sessions 0x%X for peer `%s' address `%s'\n", s, |
723 | s, | 732 | GNUNET_i2s (&s->target), udp_address_to_string (NULL, arg, args)); |
724 | GNUNET_i2s (&s->target), | 733 | |
725 | udp_address_to_string(NULL, arg, args)); | 734 | GNUNET_assert (GNUNET_OK == |
726 | 735 | GNUNET_CONTAINER_multihashmap_put (plugin->sessions, | |
727 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (plugin->sessions, | 736 | &s->target.hashPubKey, s, |
728 | &s->target.hashPubKey, | 737 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
729 | s, | ||
730 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | ||
731 | } | 738 | } |
732 | s->valid_until = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 739 | s->valid_until = |
740 | GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), | ||
741 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | ||
733 | if (s->invalidation_task != GNUNET_SCHEDULER_NO_TASK) | 742 | if (s->invalidation_task != GNUNET_SCHEDULER_NO_TASK) |
734 | { | 743 | { |
735 | GNUNET_SCHEDULER_cancel(s->invalidation_task); | 744 | GNUNET_SCHEDULER_cancel (s->invalidation_task); |
736 | s->invalidation_task = GNUNET_SCHEDULER_NO_TASK; | 745 | s->invalidation_task = GNUNET_SCHEDULER_NO_TASK; |
737 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 746 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Rescheduling %X' `%s'\n", s, |
738 | "Rescheduling %X' `%s'\n", | 747 | udp_address_to_string (NULL, arg, args)); |
739 | s, udp_address_to_string(NULL, arg, args)); | ||
740 | } | 748 | } |
741 | s->invalidation_task = GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &invalidation_task, s); | 749 | s->invalidation_task = |
750 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | ||
751 | &invalidation_task, s); | ||
742 | /* we received from peer, so session is bidirectional and reliable */ | 752 | /* we received from peer, so session is bidirectional and reliable */ |
743 | s->bidirectional = GNUNET_YES; | 753 | s->bidirectional = GNUNET_YES; |
744 | 754 | ||
@@ -768,7 +778,7 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) | |||
768 | struct ReceiveContext *rc; | 778 | struct ReceiveContext *rc; |
769 | struct GNUNET_TIME_Absolute now; | 779 | struct GNUNET_TIME_Absolute now; |
770 | struct FindReceiveContext frc; | 780 | struct FindReceiveContext frc; |
771 | struct Session * s = NULL; | 781 | struct Session *s = NULL; |
772 | struct GNUNET_TIME_Relative flow_delay; | 782 | struct GNUNET_TIME_Relative flow_delay; |
773 | 783 | ||
774 | fromlen = sizeof (addr); | 784 | fromlen = sizeof (addr); |
@@ -784,8 +794,8 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) | |||
784 | msg = (const struct GNUNET_MessageHeader *) buf; | 794 | msg = (const struct GNUNET_MessageHeader *) buf; |
785 | 795 | ||
786 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 796 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
787 | "UDP received %u-byte message from `%s' type %i\n", (unsigned int) ret, | 797 | "UDP received %u-byte message from `%s' type %i\n", (unsigned int) ret, |
788 | GNUNET_a2s ((const struct sockaddr *) addr, fromlen), ntohs(msg->type)); | 798 | GNUNET_a2s ((const struct sockaddr *) addr, fromlen), ntohs (msg->type)); |
789 | 799 | ||
790 | if (ret != ntohs (msg->size)) | 800 | if (ret != ntohs (msg->size)) |
791 | { | 801 | { |
@@ -814,26 +824,25 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) | |||
814 | } | 824 | } |
815 | udp_ack = (const struct UDP_ACK_Message *) msg; | 825 | udp_ack = (const struct UDP_ACK_Message *) msg; |
816 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 826 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
817 | "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", | 827 | "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", |
818 | (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp->sender), | 828 | (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp->sender), |
819 | GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); | 829 | GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); |
820 | 830 | ||
821 | // TODO Guess a session from address, give it defragmenter and check in process_udp if guess was right | 831 | // TODO Guess a session from address, give it defragmenter and check in process_udp if guess was right |
822 | s = guess_session (plugin->sessions, addr, addrlen); | 832 | s = guess_session (plugin->sessions, addr, addrlen); |
823 | if (GNUNET_OK != GNUNET_FRAGMENT_process_ack (peer_session->frag, ack)) | 833 | if (GNUNET_OK != GNUNET_FRAGMENT_process_ack (peer_session->frag, ack)) |
824 | // ... other stuff | 834 | // ... other stuff |
825 | return; | 835 | return; |
826 | 836 | ||
827 | case GNUNET_MESSAGE_TYPE_FRAGMENT: | 837 | case GNUNET_MESSAGE_TYPE_FRAGMENT: |
828 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 838 | LOG (GNUNET_ERROR_TYPE_DEBUG, "UDP processes %u-byte fragment from `%s'\n", |
829 | "UDP processes %u-byte fragment from `%s'\n", | 839 | (unsigned int) ntohs (msg->size), |
830 | (unsigned int) ntohs (msg->size), | 840 | GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); |
831 | GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); | ||
832 | // TODO Guess a session from address, give it defragmenter and check in process_udp if guess was right | 841 | // TODO Guess a session from address, give it defragmenter and check in process_udp if guess was right |
833 | s = guess_session (plugin->sessions, addr, addrlen); | 842 | s = guess_session (plugin->sessions, addr, addrlen); |
834 | if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (rc->defrag, msg)) | 843 | if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (rc->defrag, msg)) |
835 | // other stuff | 844 | // other stuff |
836 | return; | 845 | return; |
837 | default: | 846 | default: |
838 | GNUNET_break_op (0); | 847 | GNUNET_break_op (0); |
839 | return; | 848 | return; |
@@ -995,7 +1004,7 @@ udp_address_to_string (void *cls, const void *addr, size_t addrlen) | |||
995 | } | 1004 | } |
996 | inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); | 1005 | inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); |
997 | GNUNET_snprintf (rbuf, sizeof (rbuf), (af == AF_INET6) ? "[%s]:%u" : "%s:%u", | 1006 | GNUNET_snprintf (rbuf, sizeof (rbuf), (af == AF_INET6) ? "[%s]:%u" : "%s:%u", |
998 | buf, port); | 1007 | buf, port); |
999 | return rbuf; | 1008 | return rbuf; |
1000 | } | 1009 | } |
1001 | 1010 | ||
@@ -1206,8 +1215,8 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1206 | if (port > 65535) | 1215 | if (port > 65535) |
1207 | { | 1216 | { |
1208 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1217 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1209 | _("Given `%s' option is out of range: %llu > %u\n"), "PORT", | 1218 | _("Given `%s' option is out of range: %llu > %u\n"), "PORT", port, |
1210 | port, 65535); | 1219 | 65535); |
1211 | return NULL; | 1220 | return NULL; |
1212 | } | 1221 | } |
1213 | memset (&serverAddrv6, 0, sizeof (serverAddrv6)); | 1222 | memset (&serverAddrv6, 0, sizeof (serverAddrv6)); |
@@ -1235,8 +1244,8 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1235 | "BINDTO", &plugin->bind4_address)) | 1244 | "BINDTO", &plugin->bind4_address)) |
1236 | { | 1245 | { |
1237 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1246 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1238 | "Binding udp plugin to specific address: `%s'\n", | 1247 | "Binding udp plugin to specific address: `%s'\n", |
1239 | plugin->bind4_address); | 1248 | plugin->bind4_address); |
1240 | if (1 != inet_pton (AF_INET, plugin->bind4_address, &serverAddrv4.sin_addr)) | 1249 | if (1 != inet_pton (AF_INET, plugin->bind4_address, &serverAddrv4.sin_addr)) |
1241 | { | 1250 | { |
1242 | GNUNET_free (plugin->bind4_address); | 1251 | GNUNET_free (plugin->bind4_address); |
@@ -1251,13 +1260,13 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1251 | "BINDTO6", &plugin->bind6_address)) | 1260 | "BINDTO6", &plugin->bind6_address)) |
1252 | { | 1261 | { |
1253 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1262 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1254 | "Binding udp plugin to specific address: `%s'\n", | 1263 | "Binding udp plugin to specific address: `%s'\n", |
1255 | plugin->bind6_address); | 1264 | plugin->bind6_address); |
1256 | if (1 != | 1265 | if (1 != |
1257 | inet_pton (AF_INET6, plugin->bind6_address, &serverAddrv6.sin6_addr)) | 1266 | inet_pton (AF_INET6, plugin->bind6_address, &serverAddrv6.sin6_addr)) |
1258 | { | 1267 | { |
1259 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid IPv6 address: `%s'\n"), | 1268 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid IPv6 address: `%s'\n"), |
1260 | plugin->bind6_address); | 1269 | plugin->bind6_address); |
1261 | GNUNET_free_non_null (plugin->bind4_address); | 1270 | GNUNET_free_non_null (plugin->bind4_address); |
1262 | GNUNET_free (plugin->bind6_address); | 1271 | GNUNET_free (plugin->bind6_address); |
1263 | GNUNET_free (plugin); | 1272 | GNUNET_free (plugin); |
@@ -1296,7 +1305,7 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1296 | serverAddr = (struct sockaddr *) &serverAddrv6; | 1305 | serverAddr = (struct sockaddr *) &serverAddrv6; |
1297 | #if DEBUG_UDP | 1306 | #if DEBUG_UDP |
1298 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv6 port %d\n", | 1307 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv6 port %d\n", |
1299 | ntohs (serverAddrv6.sin6_port)); | 1308 | ntohs (serverAddrv6.sin6_port)); |
1300 | #endif | 1309 | #endif |
1301 | tries = 0; | 1310 | tries = 0; |
1302 | while (GNUNET_NETWORK_socket_bind (plugin->sockv6, serverAddr, addrlen) != | 1311 | while (GNUNET_NETWORK_socket_bind (plugin->sockv6, serverAddr, addrlen) != |
@@ -1305,8 +1314,8 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1305 | serverAddrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ | 1314 | serverAddrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ |
1306 | #if DEBUG_UDP | 1315 | #if DEBUG_UDP |
1307 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1316 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1308 | "IPv6 Binding failed, trying new port %d\n", | 1317 | "IPv6 Binding failed, trying new port %d\n", |
1309 | ntohs (serverAddrv6.sin6_port)); | 1318 | ntohs (serverAddrv6.sin6_port)); |
1310 | #endif | 1319 | #endif |
1311 | tries++; | 1320 | tries++; |
1312 | if (tries > 10) | 1321 | if (tries > 10) |
@@ -1344,7 +1353,7 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1344 | serverAddr = (struct sockaddr *) &serverAddrv4; | 1353 | serverAddr = (struct sockaddr *) &serverAddrv4; |
1345 | #if DEBUG_UDP | 1354 | #if DEBUG_UDP |
1346 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv4 port %d\n", | 1355 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv4 port %d\n", |
1347 | ntohs (serverAddrv4.sin_port)); | 1356 | ntohs (serverAddrv4.sin_port)); |
1348 | #endif | 1357 | #endif |
1349 | tries = 0; | 1358 | tries = 0; |
1350 | while (GNUNET_NETWORK_socket_bind (plugin->sockv4, serverAddr, addrlen) != | 1359 | while (GNUNET_NETWORK_socket_bind (plugin->sockv4, serverAddr, addrlen) != |
@@ -1352,9 +1361,8 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1352 | { | 1361 | { |
1353 | serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ | 1362 | serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ |
1354 | #if DEBUG_UDP | 1363 | #if DEBUG_UDP |
1355 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1364 | LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv4 Binding failed, trying new port %d\n", |
1356 | "IPv4 Binding failed, trying new port %d\n", | 1365 | ntohs (serverAddrv4.sin_port)); |
1357 | ntohs (serverAddrv4.sin_port)); | ||
1358 | #endif | 1366 | #endif |
1359 | tries++; | 1367 | tries++; |
1360 | if (tries > 10) | 1368 | if (tries > 10) |
@@ -1411,8 +1419,8 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
1411 | NULL); | 1419 | NULL); |
1412 | GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions); | 1420 | GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions); |
1413 | plugin->sessions = NULL; | 1421 | plugin->sessions = NULL; |
1414 | GNUNET_CONTAINER_multihashmap_iterate (plugin->inbound_sessions, &destroy_inbound_session, | 1422 | GNUNET_CONTAINER_multihashmap_iterate (plugin->inbound_sessions, |
1415 | NULL); | 1423 | &destroy_inbound_session, NULL); |
1416 | GNUNET_CONTAINER_multihashmap_destroy (plugin->inbound_sessions); | 1424 | GNUNET_CONTAINER_multihashmap_destroy (plugin->inbound_sessions); |
1417 | plugin->inbound_sessions = NULL; | 1425 | plugin->inbound_sessions = NULL; |
1418 | while (NULL != (rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags))) | 1426 | while (NULL != (rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags))) |