diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:54:06 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:54:06 +0000 |
commit | 5746309cb4be2073d550ad7a6885e918631dbc38 (patch) | |
tree | 89455bc4aadf977816b38df13f990372cd81d71a /src/transport/plugin_transport_udp.c | |
parent | 6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff) | |
download | gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip |
indentation
Diffstat (limited to 'src/transport/plugin_transport_udp.c')
-rw-r--r-- | src/transport/plugin_transport_udp.c | 216 |
1 files changed, 90 insertions, 126 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index df8447a12..f9310fb8f 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -350,8 +350,8 @@ udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) | |||
350 | * @return the number of bytes written | 350 | * @return the number of bytes written |
351 | */ | 351 | */ |
352 | static ssize_t | 352 | static ssize_t |
353 | udp_send (struct Plugin *plugin, | 353 | udp_send (struct Plugin *plugin, const struct sockaddr *sa, |
354 | const struct sockaddr *sa, const struct GNUNET_MessageHeader *msg) | 354 | const struct GNUNET_MessageHeader *msg) |
355 | { | 355 | { |
356 | ssize_t sent; | 356 | ssize_t sent; |
357 | size_t slen; | 357 | size_t slen; |
@@ -362,18 +362,14 @@ udp_send (struct Plugin *plugin, | |||
362 | if (NULL == plugin->sockv4) | 362 | if (NULL == plugin->sockv4) |
363 | return 0; | 363 | return 0; |
364 | sent = | 364 | sent = |
365 | GNUNET_NETWORK_socket_sendto (plugin->sockv4, | 365 | GNUNET_NETWORK_socket_sendto (plugin->sockv4, msg, ntohs (msg->size), |
366 | msg, | ||
367 | ntohs (msg->size), | ||
368 | sa, slen = sizeof (struct sockaddr_in)); | 366 | sa, slen = sizeof (struct sockaddr_in)); |
369 | break; | 367 | break; |
370 | case AF_INET6: | 368 | case AF_INET6: |
371 | if (NULL == plugin->sockv6) | 369 | if (NULL == plugin->sockv6) |
372 | return 0; | 370 | return 0; |
373 | sent = | 371 | sent = |
374 | GNUNET_NETWORK_socket_sendto (plugin->sockv6, | 372 | GNUNET_NETWORK_socket_sendto (plugin->sockv6, msg, ntohs (msg->size), |
375 | msg, | ||
376 | ntohs (msg->size), | ||
377 | sa, slen = sizeof (struct sockaddr_in6)); | 373 | sa, slen = sizeof (struct sockaddr_in6)); |
378 | break; | 374 | break; |
379 | default: | 375 | default: |
@@ -385,8 +381,7 @@ udp_send (struct Plugin *plugin, | |||
385 | #if DEBUG_UDP | 381 | #if DEBUG_UDP |
386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 382 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
387 | "UDP transmited %u-byte message to %s (%d: %s)\n", | 383 | "UDP transmited %u-byte message to %s (%d: %s)\n", |
388 | (unsigned int) ntohs (msg->size), | 384 | (unsigned int) ntohs (msg->size), GNUNET_a2s (sa, slen), |
389 | GNUNET_a2s (sa, slen), | ||
390 | (int) sent, (sent < 0) ? STRERROR (errno) : "ok"); | 385 | (int) sent, (sent < 0) ? STRERROR (errno) : "ok"); |
391 | #endif | 386 | #endif |
392 | return sent; | 387 | return sent; |
@@ -437,16 +432,10 @@ send_fragment (void *cls, const struct GNUNET_MessageHeader *msg) | |||
437 | * still be transmitted later!) | 432 | * still be transmitted later!) |
438 | */ | 433 | */ |
439 | static ssize_t | 434 | static ssize_t |
440 | udp_plugin_send (void *cls, | 435 | udp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, |
441 | const struct GNUNET_PeerIdentity *target, | 436 | const char *msgbuf, size_t msgbuf_size, unsigned int priority, |
442 | const char *msgbuf, | 437 | struct GNUNET_TIME_Relative timeout, struct Session *session, |
443 | size_t msgbuf_size, | 438 | const void *addr, size_t addrlen, int force_address, |
444 | unsigned int priority, | ||
445 | struct GNUNET_TIME_Relative timeout, | ||
446 | struct Session *session, | ||
447 | const void *addr, | ||
448 | size_t addrlen, | ||
449 | int force_address, | ||
450 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) | 439 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) |
451 | { | 440 | { |
452 | struct Plugin *plugin = cls; | 441 | struct Plugin *plugin = cls; |
@@ -534,13 +523,12 @@ udp_plugin_send (void *cls, | |||
534 | &target->hashPubKey, | 523 | &target->hashPubKey, |
535 | peer_session, | 524 | peer_session, |
536 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 525 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
537 | peer_session->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats, | 526 | peer_session->frag = |
538 | UDP_MTU, | 527 | GNUNET_FRAGMENT_context_create (plugin->env->stats, UDP_MTU, |
539 | &plugin->tracker, | 528 | &plugin->tracker, |
540 | plugin->last_expected_delay, | 529 | plugin->last_expected_delay, |
541 | &udp->header, | 530 | &udp->header, &send_fragment, |
542 | &send_fragment, | 531 | peer_session); |
543 | peer_session); | ||
544 | } | 532 | } |
545 | return mlen; | 533 | return mlen; |
546 | } | 534 | } |
@@ -577,8 +565,7 @@ struct SourceInformation | |||
577 | * @param hdr the actual message | 565 | * @param hdr the actual message |
578 | */ | 566 | */ |
579 | static void | 567 | static void |
580 | process_inbound_tokenized_messages (void *cls, | 568 | process_inbound_tokenized_messages (void *cls, void *client, |
581 | void *client, | ||
582 | const struct GNUNET_MessageHeader *hdr) | 569 | const struct GNUNET_MessageHeader *hdr) |
583 | { | 570 | { |
584 | struct Plugin *plugin = cls; | 571 | struct Plugin *plugin = cls; |
@@ -591,8 +578,8 @@ process_inbound_tokenized_messages (void *cls, | |||
591 | distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); | 578 | distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); |
592 | distance[1].value = htonl (0); | 579 | distance[1].value = htonl (0); |
593 | 580 | ||
594 | plugin->env->receive (plugin->env->cls, | 581 | plugin->env->receive (plugin->env->cls, &si->sender, hdr, distance, 2, NULL, |
595 | &si->sender, hdr, distance, 2, NULL, si->arg, si->args); | 582 | si->arg, si->args); |
596 | } | 583 | } |
597 | 584 | ||
598 | 585 | ||
@@ -605,8 +592,7 @@ process_inbound_tokenized_messages (void *cls, | |||
605 | * @param sender_addr_len number of bytes in sender_addr | 592 | * @param sender_addr_len number of bytes in sender_addr |
606 | */ | 593 | */ |
607 | static void | 594 | static void |
608 | process_udp_message (struct Plugin *plugin, | 595 | process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, |
609 | const struct UDPMessage *msg, | ||
610 | const struct sockaddr *sender_addr, | 596 | const struct sockaddr *sender_addr, |
611 | socklen_t sender_addr_len) | 597 | socklen_t sender_addr_len) |
612 | { | 598 | { |
@@ -650,21 +636,18 @@ process_udp_message (struct Plugin *plugin, | |||
650 | return; | 636 | return; |
651 | } | 637 | } |
652 | #if DEBUG_UDP | 638 | #if DEBUG_UDP |
653 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 639 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", |
654 | "udp", | ||
655 | "Received message with %u bytes from peer `%s' at `%s'\n", | 640 | "Received message with %u bytes from peer `%s' at `%s'\n", |
656 | (unsigned int) ntohs (msg->header.size), | 641 | (unsigned int) ntohs (msg->header.size), |
657 | GNUNET_i2s (&msg->sender), | 642 | GNUNET_i2s (&msg->sender), GNUNET_a2s (sender_addr, |
658 | GNUNET_a2s (sender_addr, sender_addr_len)); | 643 | sender_addr_len)); |
659 | #endif | 644 | #endif |
660 | 645 | ||
661 | /* iterate over all embedded messages */ | 646 | /* iterate over all embedded messages */ |
662 | si.sender = msg->sender; | 647 | si.sender = msg->sender; |
663 | si.arg = arg; | 648 | si.arg = arg; |
664 | si.args = args; | 649 | si.args = args; |
665 | GNUNET_SERVER_mst_receive (plugin->mst, | 650 | GNUNET_SERVER_mst_receive (plugin->mst, &si, (const char *) &msg[1], |
666 | &si, | ||
667 | (const char *) &msg[1], | ||
668 | ntohs (msg->header.size) - | 651 | ntohs (msg->header.size) - |
669 | sizeof (struct UDPMessage), GNUNET_YES, GNUNET_NO); | 652 | sizeof (struct UDPMessage), GNUNET_YES, GNUNET_NO); |
670 | } | 653 | } |
@@ -691,8 +674,7 @@ fragment_msg_proc (void *cls, const struct GNUNET_MessageHeader *msg) | |||
691 | GNUNET_break (0); | 674 | GNUNET_break (0); |
692 | return; | 675 | return; |
693 | } | 676 | } |
694 | process_udp_message (rc->plugin, | 677 | process_udp_message (rc->plugin, (const struct UDPMessage *) msg, |
695 | (const struct UDPMessage *) msg, | ||
696 | rc->src_addr, rc->addr_len); | 678 | rc->src_addr, rc->addr_len); |
697 | } | 679 | } |
698 | 680 | ||
@@ -713,13 +695,11 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) | |||
713 | struct UDPMessage *udp; | 695 | struct UDPMessage *udp; |
714 | 696 | ||
715 | #if DEBUG_UDP | 697 | #if DEBUG_UDP |
716 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 698 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "udp", "Sending ACK to `%s'\n", |
717 | "udp", | ||
718 | "Sending ACK to `%s'\n", | ||
719 | GNUNET_a2s (rc->src_addr, | 699 | GNUNET_a2s (rc->src_addr, |
720 | (rc->src_addr->sa_family == AF_INET) | 700 | (rc->src_addr->sa_family == |
721 | ? sizeof (struct sockaddr_in) | 701 | AF_INET) ? sizeof (struct sockaddr_in) : |
722 | : sizeof (struct sockaddr_in6))); | 702 | sizeof (struct sockaddr_in6))); |
723 | #endif | 703 | #endif |
724 | udp = (struct UDPMessage *) buf; | 704 | udp = (struct UDPMessage *) buf; |
725 | udp->header.size = htons ((uint16_t) msize); | 705 | udp->header.size = htons ((uint16_t) msize); |
@@ -764,8 +744,7 @@ struct FindReceiveContext | |||
764 | * GNUNET_NO if not. | 744 | * GNUNET_NO if not. |
765 | */ | 745 | */ |
766 | static int | 746 | static int |
767 | find_receive_context (void *cls, | 747 | find_receive_context (void *cls, struct GNUNET_CONTAINER_HeapNode *node, |
768 | struct GNUNET_CONTAINER_HeapNode *node, | ||
769 | void *element, GNUNET_CONTAINER_HeapCostType cost) | 748 | void *element, GNUNET_CONTAINER_HeapCostType cost) |
770 | { | 749 | { |
771 | struct FindReceiveContext *frc = cls; | 750 | struct FindReceiveContext *frc = cls; |
@@ -804,8 +783,9 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) | |||
804 | 783 | ||
805 | fromlen = sizeof (addr); | 784 | fromlen = sizeof (addr); |
806 | memset (&addr, 0, sizeof (addr)); | 785 | memset (&addr, 0, sizeof (addr)); |
807 | ret = GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof (buf), | 786 | ret = |
808 | (struct sockaddr *) &addr, &fromlen); | 787 | GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof (buf), |
788 | (struct sockaddr *) &addr, &fromlen); | ||
809 | if (ret < sizeof (struct GNUNET_MessageHeader)) | 789 | if (ret < sizeof (struct GNUNET_MessageHeader)) |
810 | { | 790 | { |
811 | GNUNET_break_op (0); | 791 | GNUNET_break_op (0); |
@@ -813,8 +793,7 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) | |||
813 | } | 793 | } |
814 | #if DEBUG_UDP | 794 | #if DEBUG_UDP |
815 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 795 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
816 | "UDP received %u-byte message from `%s'\n", | 796 | "UDP received %u-byte message from `%s'\n", (unsigned int) ret, |
817 | (unsigned int) ret, | ||
818 | GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); | 797 | GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); |
819 | #endif | 798 | #endif |
820 | msg = (const struct GNUNET_MessageHeader *) buf; | 799 | msg = (const struct GNUNET_MessageHeader *) buf; |
@@ -831,8 +810,7 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) | |||
831 | GNUNET_break_op (0); | 810 | GNUNET_break_op (0); |
832 | return; | 811 | return; |
833 | } | 812 | } |
834 | process_udp_message (plugin, | 813 | process_udp_message (plugin, (const struct UDPMessage *) msg, |
835 | (const struct UDPMessage *) msg, | ||
836 | (const struct sockaddr *) addr, fromlen); | 814 | (const struct sockaddr *) addr, fromlen); |
837 | return; | 815 | return; |
838 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK: | 816 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK: |
@@ -857,8 +835,7 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) | |||
857 | #if DEBUG_UDP | 835 | #if DEBUG_UDP |
858 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 836 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
859 | "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", | 837 | "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", |
860 | (unsigned int) ntohs (msg->size), | 838 | (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp->sender), |
861 | GNUNET_i2s (&udp->sender), | ||
862 | GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); | 839 | GNUNET_a2s ((const struct sockaddr *) addr, fromlen)); |
863 | #endif | 840 | #endif |
864 | 841 | ||
@@ -875,8 +852,8 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) | |||
875 | return; | 852 | return; |
876 | GNUNET_assert (GNUNET_OK == | 853 | GNUNET_assert (GNUNET_OK == |
877 | GNUNET_CONTAINER_multihashmap_remove (plugin->sessions, | 854 | GNUNET_CONTAINER_multihashmap_remove (plugin->sessions, |
878 | &udp-> | 855 | &udp->sender. |
879 | sender.hashPubKey, | 856 | hashPubKey, |
880 | peer_session)); | 857 | peer_session)); |
881 | plugin->last_expected_delay = | 858 | plugin->last_expected_delay = |
882 | GNUNET_FRAGMENT_context_destroy (peer_session->frag); | 859 | GNUNET_FRAGMENT_context_destroy (peer_session->frag); |
@@ -887,8 +864,8 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) | |||
887 | frc.rc = NULL; | 864 | frc.rc = NULL; |
888 | frc.addr = (const struct sockaddr *) addr; | 865 | frc.addr = (const struct sockaddr *) addr; |
889 | frc.addr_len = fromlen; | 866 | frc.addr_len = fromlen; |
890 | GNUNET_CONTAINER_heap_iterate (plugin->defrags, | 867 | GNUNET_CONTAINER_heap_iterate (plugin->defrags, &find_receive_context, |
891 | &find_receive_context, &frc); | 868 | &frc); |
892 | now = GNUNET_TIME_absolute_get (); | 869 | now = GNUNET_TIME_absolute_get (); |
893 | rc = frc.rc; | 870 | rc = frc.rc; |
894 | if (rc == NULL) | 871 | if (rc == NULL) |
@@ -899,16 +876,14 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) | |||
899 | rc->src_addr = (const struct sockaddr *) &rc[1]; | 876 | rc->src_addr = (const struct sockaddr *) &rc[1]; |
900 | rc->addr_len = fromlen; | 877 | rc->addr_len = fromlen; |
901 | rc->plugin = plugin; | 878 | rc->plugin = plugin; |
902 | rc->defrag = GNUNET_DEFRAGMENT_context_create (plugin->env->stats, | 879 | rc->defrag = |
903 | UDP_MTU, | 880 | GNUNET_DEFRAGMENT_context_create (plugin->env->stats, UDP_MTU, |
904 | UDP_MAX_MESSAGES_IN_DEFRAG, | 881 | UDP_MAX_MESSAGES_IN_DEFRAG, rc, |
905 | rc, | 882 | &fragment_msg_proc, &ack_proc); |
906 | &fragment_msg_proc, | 883 | rc->hnode = |
907 | &ack_proc); | 884 | GNUNET_CONTAINER_heap_insert (plugin->defrags, rc, |
908 | rc->hnode = GNUNET_CONTAINER_heap_insert (plugin->defrags, | 885 | (GNUNET_CONTAINER_HeapCostType) now. |
909 | rc, | 886 | abs_value); |
910 | (GNUNET_CONTAINER_HeapCostType) | ||
911 | now.abs_value); | ||
912 | } | 887 | } |
913 | #if DEBUG_UDP | 888 | #if DEBUG_UDP |
914 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 889 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -920,10 +895,9 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) | |||
920 | if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (rc->defrag, msg)) | 895 | if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (rc->defrag, msg)) |
921 | { | 896 | { |
922 | /* keep this 'rc' from expiring */ | 897 | /* keep this 'rc' from expiring */ |
923 | GNUNET_CONTAINER_heap_update_cost (plugin->defrags, | 898 | GNUNET_CONTAINER_heap_update_cost (plugin->defrags, rc->hnode, |
924 | rc->hnode, | 899 | (GNUNET_CONTAINER_HeapCostType) now. |
925 | (GNUNET_CONTAINER_HeapCostType) | 900 | abs_value); |
926 | now.abs_value); | ||
927 | } | 901 | } |
928 | if (GNUNET_CONTAINER_heap_get_size (plugin->defrags) > | 902 | if (GNUNET_CONTAINER_heap_get_size (plugin->defrags) > |
929 | UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG) | 903 | UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG) |
@@ -1026,8 +1000,8 @@ udp_plugin_check_address (void *cls, const void *addr, size_t addrlen) | |||
1026 | if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port))) | 1000 | if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port))) |
1027 | return GNUNET_SYSERR; | 1001 | return GNUNET_SYSERR; |
1028 | if (GNUNET_OK != | 1002 | if (GNUNET_OK != |
1029 | GNUNET_NAT_test_address (plugin->nat, | 1003 | GNUNET_NAT_test_address (plugin->nat, &v4->ipv4_addr, |
1030 | &v4->ipv4_addr, sizeof (struct in_addr))) | 1004 | sizeof (struct in_addr))) |
1031 | return GNUNET_SYSERR; | 1005 | return GNUNET_SYSERR; |
1032 | } | 1006 | } |
1033 | else | 1007 | else |
@@ -1041,8 +1015,8 @@ udp_plugin_check_address (void *cls, const void *addr, size_t addrlen) | |||
1041 | if (GNUNET_OK != check_port (plugin, ntohs (v6->u6_port))) | 1015 | if (GNUNET_OK != check_port (plugin, ntohs (v6->u6_port))) |
1042 | return GNUNET_SYSERR; | 1016 | return GNUNET_SYSERR; |
1043 | if (GNUNET_OK != | 1017 | if (GNUNET_OK != |
1044 | GNUNET_NAT_test_address (plugin->nat, | 1018 | GNUNET_NAT_test_address (plugin->nat, &v6->ipv6_addr, |
1045 | &v6->ipv6_addr, sizeof (struct in6_addr))) | 1019 | sizeof (struct in6_addr))) |
1046 | return GNUNET_SYSERR; | 1020 | return GNUNET_SYSERR; |
1047 | } | 1021 | } |
1048 | return GNUNET_OK; | 1022 | return GNUNET_OK; |
@@ -1161,10 +1135,8 @@ append_port (void *cls, const char *hostname) | |||
1161 | * @param asc_cls closure for asc | 1135 | * @param asc_cls closure for asc |
1162 | */ | 1136 | */ |
1163 | static void | 1137 | static void |
1164 | udp_plugin_address_pretty_printer (void *cls, | 1138 | udp_plugin_address_pretty_printer (void *cls, const char *type, |
1165 | const char *type, | 1139 | const void *addr, size_t addrlen, |
1166 | const void *addr, | ||
1167 | size_t addrlen, | ||
1168 | int numeric, | 1140 | int numeric, |
1169 | struct GNUNET_TIME_Relative timeout, | 1141 | struct GNUNET_TIME_Relative timeout, |
1170 | GNUNET_TRANSPORT_AddressStringCallback asc, | 1142 | GNUNET_TRANSPORT_AddressStringCallback asc, |
@@ -1232,8 +1204,7 @@ udp_plugin_address_pretty_printer (void *cls, | |||
1232 | * @param addrlen actual lenght of the address | 1204 | * @param addrlen actual lenght of the address |
1233 | */ | 1205 | */ |
1234 | static void | 1206 | static void |
1235 | udp_nat_port_map_callback (void *cls, | 1207 | udp_nat_port_map_callback (void *cls, int add_remove, |
1236 | int add_remove, | ||
1237 | const struct sockaddr *addr, socklen_t addrlen) | 1208 | const struct sockaddr *addr, socklen_t addrlen) |
1238 | { | 1209 | { |
1239 | struct Plugin *plugin = cls; | 1210 | struct Plugin *plugin = cls; |
@@ -1254,8 +1225,7 @@ udp_nat_port_map_callback (void *cls, | |||
1254 | break; | 1225 | break; |
1255 | case AF_INET6: | 1226 | case AF_INET6: |
1256 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); | 1227 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); |
1257 | memcpy (&u6.ipv6_addr, | 1228 | memcpy (&u6.ipv6_addr, &((struct sockaddr_in6 *) addr)->sin6_addr, |
1258 | &((struct sockaddr_in6 *) addr)->sin6_addr, | ||
1259 | sizeof (struct in6_addr)); | 1229 | sizeof (struct in6_addr)); |
1260 | u6.u6_port = ((struct sockaddr_in6 *) addr)->sin6_port; | 1230 | u6.u6_port = ((struct sockaddr_in6 *) addr)->sin6_port; |
1261 | arg = &u6; | 1231 | arg = &u6; |
@@ -1296,24 +1266,22 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1296 | unsigned long long udp_max_bps; | 1266 | unsigned long long udp_max_bps; |
1297 | 1267 | ||
1298 | if (GNUNET_OK != | 1268 | if (GNUNET_OK != |
1299 | GNUNET_CONFIGURATION_get_value_number (env->cfg, | 1269 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", "PORT", |
1300 | "transport-udp", "PORT", &port)) | 1270 | &port)) |
1301 | port = 2086; | 1271 | port = 2086; |
1302 | if (GNUNET_OK != | 1272 | if (GNUNET_OK != |
1303 | GNUNET_CONFIGURATION_get_value_number (env->cfg, | 1273 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", |
1304 | "transport-udp", | ||
1305 | "MAX_BPS", &udp_max_bps)) | 1274 | "MAX_BPS", &udp_max_bps)) |
1306 | udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical purposes */ | 1275 | udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical purposes */ |
1307 | if (GNUNET_OK != | 1276 | if (GNUNET_OK != |
1308 | GNUNET_CONFIGURATION_get_value_number (env->cfg, | 1277 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", |
1309 | "transport-udp", | ||
1310 | "ADVERTISED_PORT", &aport)) | 1278 | "ADVERTISED_PORT", &aport)) |
1311 | aport = port; | 1279 | aport = port; |
1312 | if (port > 65535) | 1280 | if (port > 65535) |
1313 | { | 1281 | { |
1314 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1282 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1315 | _("Given `%s' option is out of range: %llu > %u\n"), | 1283 | _("Given `%s' option is out of range: %llu > %u\n"), "PORT", |
1316 | "PORT", port, 65535); | 1284 | port, 65535); |
1317 | return NULL; | 1285 | return NULL; |
1318 | } | 1286 | } |
1319 | memset (&serverAddrv6, 0, sizeof (serverAddrv6)); | 1287 | memset (&serverAddrv6, 0, sizeof (serverAddrv6)); |
@@ -1336,10 +1304,9 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1336 | api->address_to_string = &udp_address_to_string; | 1304 | api->address_to_string = &udp_address_to_string; |
1337 | api->check_address = &udp_plugin_check_address; | 1305 | api->check_address = &udp_plugin_check_address; |
1338 | 1306 | ||
1339 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg, | 1307 | if (GNUNET_YES == |
1340 | "transport-udp", | 1308 | GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", |
1341 | "BINDTO", | 1309 | "BINDTO", &plugin->bind4_address)) |
1342 | &plugin->bind4_address)) | ||
1343 | { | 1310 | { |
1344 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1345 | "Binding udp plugin to specific address: `%s'\n", | 1312 | "Binding udp plugin to specific address: `%s'\n", |
@@ -1353,19 +1320,18 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1353 | } | 1320 | } |
1354 | } | 1321 | } |
1355 | 1322 | ||
1356 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg, | 1323 | if (GNUNET_YES == |
1357 | "transport-udp", | 1324 | GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", |
1358 | "BINDTO6", | 1325 | "BINDTO6", &plugin->bind6_address)) |
1359 | &plugin->bind6_address)) | ||
1360 | { | 1326 | { |
1361 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1327 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1362 | "Binding udp plugin to specific address: `%s'\n", | 1328 | "Binding udp plugin to specific address: `%s'\n", |
1363 | plugin->bind6_address); | 1329 | plugin->bind6_address); |
1364 | if (1 != inet_pton (AF_INET6, | 1330 | if (1 != |
1365 | plugin->bind6_address, &serverAddrv6.sin6_addr)) | 1331 | inet_pton (AF_INET6, plugin->bind6_address, &serverAddrv6.sin6_addr)) |
1366 | { | 1332 | { |
1367 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1333 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Invalid IPv6 address: `%s'\n"), |
1368 | _("Invalid IPv6 address: `%s'\n"), plugin->bind6_address); | 1334 | plugin->bind6_address); |
1369 | GNUNET_free_non_null (plugin->bind4_address); | 1335 | GNUNET_free_non_null (plugin->bind4_address); |
1370 | GNUNET_free (plugin->bind6_address); | 1336 | GNUNET_free (plugin->bind6_address); |
1371 | GNUNET_free (plugin); | 1337 | GNUNET_free (plugin); |
@@ -1381,8 +1347,8 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1381 | * 2); | 1347 | * 2); |
1382 | sockets_created = 0; | 1348 | sockets_created = 0; |
1383 | if ((GNUNET_YES != | 1349 | if ((GNUNET_YES != |
1384 | GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, | 1350 | GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, "nat", |
1385 | "nat", "DISABLEV6"))) | 1351 | "DISABLEV6"))) |
1386 | { | 1352 | { |
1387 | plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0); | 1353 | plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0); |
1388 | if (NULL == plugin->sockv6) | 1354 | if (NULL == plugin->sockv6) |
@@ -1400,12 +1366,12 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1400 | addrlen = sizeof (serverAddrv6); | 1366 | addrlen = sizeof (serverAddrv6); |
1401 | serverAddr = (struct sockaddr *) &serverAddrv6; | 1367 | serverAddr = (struct sockaddr *) &serverAddrv6; |
1402 | #if DEBUG_UDP | 1368 | #if DEBUG_UDP |
1403 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1369 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv6 port %d\n", |
1404 | "Binding to IPv6 port %d\n", ntohs (serverAddrv6.sin6_port)); | 1370 | ntohs (serverAddrv6.sin6_port)); |
1405 | #endif | 1371 | #endif |
1406 | tries = 0; | 1372 | tries = 0; |
1407 | while (GNUNET_NETWORK_socket_bind (plugin->sockv6, | 1373 | while (GNUNET_NETWORK_socket_bind (plugin->sockv6, serverAddr, addrlen) != |
1408 | serverAddr, addrlen) != GNUNET_OK) | 1374 | GNUNET_OK) |
1409 | { | 1375 | { |
1410 | serverAddrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ | 1376 | serverAddrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ |
1411 | #if DEBUG_UDP | 1377 | #if DEBUG_UDP |
@@ -1430,8 +1396,8 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1430 | } | 1396 | } |
1431 | } | 1397 | } |
1432 | 1398 | ||
1433 | plugin->mst = GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages, | 1399 | plugin->mst = |
1434 | plugin); | 1400 | GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages, plugin); |
1435 | plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0); | 1401 | plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0); |
1436 | if (NULL == plugin->sockv4) | 1402 | if (NULL == plugin->sockv4) |
1437 | { | 1403 | { |
@@ -1448,8 +1414,8 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1448 | addrlen = sizeof (serverAddrv4); | 1414 | addrlen = sizeof (serverAddrv4); |
1449 | serverAddr = (struct sockaddr *) &serverAddrv4; | 1415 | serverAddr = (struct sockaddr *) &serverAddrv4; |
1450 | #if DEBUG_UDP | 1416 | #if DEBUG_UDP |
1451 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1417 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv4 port %d\n", |
1452 | "Binding to IPv4 port %d\n", ntohs (serverAddrv4.sin_port)); | 1418 | ntohs (serverAddrv4.sin_port)); |
1453 | #endif | 1419 | #endif |
1454 | tries = 0; | 1420 | tries = 0; |
1455 | while (GNUNET_NETWORK_socket_bind (plugin->sockv4, serverAddr, addrlen) != | 1421 | while (GNUNET_NETWORK_socket_bind (plugin->sockv4, serverAddr, addrlen) != |
@@ -1491,12 +1457,10 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
1491 | NULL, &udp_plugin_select, plugin); | 1457 | NULL, &udp_plugin_select, plugin); |
1492 | if (sockets_created == 0) | 1458 | if (sockets_created == 0) |
1493 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to open UDP sockets\n")); | 1459 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to open UDP sockets\n")); |
1494 | plugin->nat = GNUNET_NAT_register (env->cfg, | 1460 | plugin->nat = |
1495 | GNUNET_NO, | 1461 | GNUNET_NAT_register (env->cfg, GNUNET_NO, port, sockets_created, |
1496 | port, | 1462 | (const struct sockaddr **) addrs, addrlens, |
1497 | sockets_created, | 1463 | &udp_nat_port_map_callback, NULL, plugin); |
1498 | (const struct sockaddr **) addrs, addrlens, | ||
1499 | &udp_nat_port_map_callback, NULL, plugin); | ||
1500 | return api; | 1464 | return api; |
1501 | } | 1465 | } |
1502 | 1466 | ||
@@ -1534,8 +1498,8 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
1534 | struct ReceiveContext *rc; | 1498 | struct ReceiveContext *rc; |
1535 | 1499 | ||
1536 | /* FIXME: clean up heap and hashmap */ | 1500 | /* FIXME: clean up heap and hashmap */ |
1537 | GNUNET_CONTAINER_multihashmap_iterate (plugin->sessions, | 1501 | GNUNET_CONTAINER_multihashmap_iterate (plugin->sessions, &destroy_session, |
1538 | &destroy_session, NULL); | 1502 | NULL); |
1539 | GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions); | 1503 | GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions); |
1540 | plugin->sessions = NULL; | 1504 | plugin->sessions = NULL; |
1541 | while (NULL != (rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags))) | 1505 | while (NULL != (rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags))) |