diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-12-20 12:02:13 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-12-20 12:02:13 +0100 |
commit | b5e9bdbdde10102023074d57086975b354019a22 (patch) | |
tree | a892d19fdd0cd7bf6068514d4728536e5216e976 /src/transport | |
parent | e60f76eab3447fba5982d30f0e4e7ebecf4edc0b (diff) | |
download | gnunet-b5e9bdbdde10102023074d57086975b354019a22.tar.gz gnunet-b5e9bdbdde10102023074d57086975b354019a22.zip |
fix sendto bug
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/gnunet-communicator-udp.c | 79 |
1 files changed, 55 insertions, 24 deletions
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c index 1f87ba6d4..7e353e4b1 100644 --- a/src/transport/gnunet-communicator-udp.c +++ b/src/transport/gnunet-communicator-udp.c | |||
@@ -1464,7 +1464,7 @@ destroy_all_secrets (struct SharedSecret *ss, int withoutKce) | |||
1464 | } | 1464 | } |
1465 | 1465 | ||
1466 | pos = ss_start; | 1466 | pos = ss_start; |
1467 | while ( NULL != pos) | 1467 | while (NULL != pos) |
1468 | { | 1468 | { |
1469 | ss_to_destroy = pos; | 1469 | ss_to_destroy = pos; |
1470 | pos = pos->next; | 1470 | pos = pos->next; |
@@ -1484,6 +1484,7 @@ destroy_all_secrets (struct SharedSecret *ss, int withoutKce) | |||
1484 | "Finished destroy all.\n"); | 1484 | "Finished destroy all.\n"); |
1485 | } | 1485 | } |
1486 | 1486 | ||
1487 | |||
1487 | static void | 1488 | static void |
1488 | add_acks (struct SharedSecret *ss, int acks_to_add) | 1489 | add_acks (struct SharedSecret *ss, int acks_to_add) |
1489 | { | 1490 | { |
@@ -1520,6 +1521,7 @@ add_acks (struct SharedSecret *ss, int acks_to_add) | |||
1520 | destroy_all_secrets (ss, GNUNET_YES); | 1521 | destroy_all_secrets (ss, GNUNET_YES); |
1521 | } | 1522 | } |
1522 | 1523 | ||
1524 | |||
1523 | static uint32_t | 1525 | static uint32_t |
1524 | reset_rekey_kces (struct ReceiverAddress *receiver, | 1526 | reset_rekey_kces (struct ReceiverAddress *receiver, |
1525 | uint32_t acks_to_add) | 1527 | uint32_t acks_to_add) |
@@ -1550,6 +1552,7 @@ reset_rekey_kces (struct ReceiverAddress *receiver, | |||
1550 | return acks_to_add; | 1552 | return acks_to_add; |
1551 | } | 1553 | } |
1552 | 1554 | ||
1555 | |||
1553 | static void | 1556 | static void |
1554 | add_acks_rekey (struct ReceiverAddress *receiver) | 1557 | add_acks_rekey (struct ReceiverAddress *receiver) |
1555 | { | 1558 | { |
@@ -1575,6 +1578,7 @@ add_acks_rekey (struct ReceiverAddress *receiver) | |||
1575 | GNUNET_NO); | 1578 | GNUNET_NO); |
1576 | } | 1579 | } |
1577 | 1580 | ||
1581 | |||
1578 | /** | 1582 | /** |
1579 | * We received an ACK for @a pid. Check if it is for | 1583 | * We received an ACK for @a pid. Check if it is for |
1580 | * the receiver in @a value and if so, handle it and | 1584 | * the receiver in @a value and if so, handle it and |
@@ -1736,7 +1740,6 @@ try_handle_plaintext (struct SenderAddress *sender, | |||
1736 | } | 1740 | } |
1737 | 1741 | ||
1738 | 1742 | ||
1739 | |||
1740 | static void | 1743 | static void |
1741 | kce_generate_cb (void *cls) | 1744 | kce_generate_cb (void *cls) |
1742 | { | 1745 | { |
@@ -1771,6 +1774,7 @@ kce_generate_cb (void *cls) | |||
1771 | 1774 | ||
1772 | } | 1775 | } |
1773 | 1776 | ||
1777 | |||
1774 | static void | 1778 | static void |
1775 | kce_generate_rekey_cb (void *cls) | 1779 | kce_generate_rekey_cb (void *cls) |
1776 | { | 1780 | { |
@@ -1870,7 +1874,8 @@ consider_ss_ack (struct SharedSecret *ss, int initial) | |||
1870 | kce_task_finished = GNUNET_NO; | 1874 | kce_task_finished = GNUNET_NO; |
1871 | } | 1875 | } |
1872 | } | 1876 | } |
1873 | else if ((NULL == kce_task) && ((KCN_THRESHOLD > ss->sender->acks_available)|| | 1877 | else if ((NULL == kce_task) && ((KCN_THRESHOLD > |
1878 | ss->sender->acks_available) || | ||
1874 | (GNUNET_YES == ss->sender->rekeying) || | 1879 | (GNUNET_YES == ss->sender->rekeying) || |
1875 | (ss->sender->num_secrets > MAX_SECRETS) )) | 1880 | (ss->sender->num_secrets > MAX_SECRETS) )) |
1876 | { | 1881 | { |
@@ -1945,13 +1950,15 @@ decrypt_box (const struct UDPBox *box, | |||
1945 | } | 1950 | } |
1946 | else if (GNUNET_NO == box->rekeying) | 1951 | else if (GNUNET_NO == box->rekeying) |
1947 | consider_ss_ack (ss, GNUNET_NO); | 1952 | consider_ss_ack (ss, GNUNET_NO); |
1948 | else{ | 1953 | else |
1954 | { | ||
1949 | ss->sender->rekeying = GNUNET_YES; | 1955 | ss->sender->rekeying = GNUNET_YES; |
1950 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1956 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1951 | "Got Box: Receiver doing rekeying.\n"); | 1957 | "Got Box: Receiver doing rekeying.\n"); |
1952 | } | 1958 | } |
1953 | } | 1959 | } |
1954 | 1960 | ||
1961 | |||
1955 | /** | 1962 | /** |
1956 | * We received a @a rekey with matching @a kce. Decrypt and process it. | 1963 | * We received a @a rekey with matching @a kce. Decrypt and process it. |
1957 | * | 1964 | * |
@@ -2039,6 +2046,7 @@ decrypt_rekey (const struct UDPRekey *rekey, | |||
2039 | 2046 | ||
2040 | } | 2047 | } |
2041 | 2048 | ||
2049 | |||
2042 | /** | 2050 | /** |
2043 | * Closure for #find_sender_by_address() | 2051 | * Closure for #find_sender_by_address() |
2044 | */ | 2052 | */ |
@@ -2249,15 +2257,16 @@ sock_read (void *cls) | |||
2249 | box = (const struct UDPBox *) buf; | 2257 | box = (const struct UDPBox *) buf; |
2250 | kce = GNUNET_CONTAINER_multishortmap_get (key_cache, &rekey->kid); | 2258 | kce = GNUNET_CONTAINER_multishortmap_get (key_cache, &rekey->kid); |
2251 | 2259 | ||
2252 | if ((GNUNET_YES == box->rekeying)||(GNUNET_NO == box->rekeying)) | 2260 | if ((GNUNET_YES == box->rekeying) || (GNUNET_NO == box->rekeying)) |
2253 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2261 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2254 | "UDPRekey has rekeying %u\n", | 2262 | "UDPRekey has rekeying %u\n", |
2255 | box->rekeying); | 2263 | box->rekeying); |
2256 | else | 2264 | else |
2257 | do_decrypt = GNUNET_YES; | 2265 | do_decrypt = GNUNET_YES; |
2258 | 2266 | ||
2259 | if ((GNUNET_YES == do_decrypt)&& (NULL != kce) && (GNUNET_YES == | 2267 | if ((GNUNET_YES == do_decrypt) && (NULL != kce) && (GNUNET_YES == |
2260 | kce->ss->sender->rekeying)) | 2268 | kce->ss->sender-> |
2269 | rekeying)) | ||
2261 | { | 2270 | { |
2262 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2271 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2263 | "UDPRekey with kid %s\n", | 2272 | "UDPRekey with kid %s\n", |
@@ -2400,7 +2409,8 @@ sock_read (void *cls) | |||
2400 | } | 2409 | } |
2401 | else if (GNUNET_NO == kx->rekeying) | 2410 | else if (GNUNET_NO == kx->rekeying) |
2402 | consider_ss_ack (ss, GNUNET_YES); | 2411 | consider_ss_ack (ss, GNUNET_YES); |
2403 | else{ | 2412 | else |
2413 | { | ||
2404 | ss->sender->rekeying = GNUNET_YES; | 2414 | ss->sender->rekeying = GNUNET_YES; |
2405 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2415 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2406 | "Got KX: Receiver doing rekeying.\n"); | 2416 | "Got KX: Receiver doing rekeying.\n"); |
@@ -2664,6 +2674,7 @@ mq_send_kx (struct GNUNET_MQ_Handle *mq, | |||
2664 | GNUNET_MQ_impl_send_continue (mq); | 2674 | GNUNET_MQ_impl_send_continue (mq); |
2665 | } | 2675 | } |
2666 | 2676 | ||
2677 | |||
2667 | static void | 2678 | static void |
2668 | check_for_rekeying (struct ReceiverAddress *receiver, struct UDPBox *box) | 2679 | check_for_rekeying (struct ReceiverAddress *receiver, struct UDPBox *box) |
2669 | { | 2680 | { |
@@ -2687,8 +2698,8 @@ check_for_rekeying (struct ReceiverAddress *receiver, struct UDPBox *box) | |||
2687 | rt.rel_value_us, | 2698 | rt.rel_value_us, |
2688 | receiver->rekey_timeout.abs_value_us); | 2699 | receiver->rekey_timeout.abs_value_us); |
2689 | 2700 | ||
2690 | if ((0 == rt.rel_value_us)||(receiver->rekey_send_bytes > | 2701 | if ((0 == rt.rel_value_us) || (receiver->rekey_send_bytes > |
2691 | rekey_max_bytes) ) | 2702 | rekey_max_bytes) ) |
2692 | { | 2703 | { |
2693 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2704 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2694 | "Bytes send %lu greater than %llu max bytes\n.", | 2705 | "Bytes send %lu greater than %llu max bytes\n.", |
@@ -2716,6 +2727,7 @@ check_for_rekeying (struct ReceiverAddress *receiver, struct UDPBox *box) | |||
2716 | } | 2727 | } |
2717 | } | 2728 | } |
2718 | 2729 | ||
2730 | |||
2719 | static void | 2731 | static void |
2720 | send_UDPRekey (struct ReceiverAddress *receiver, struct SharedSecret *ss) | 2732 | send_UDPRekey (struct ReceiverAddress *receiver, struct SharedSecret *ss) |
2721 | { | 2733 | { |
@@ -3283,14 +3295,17 @@ do_shutdown (void *cls) | |||
3283 | } | 3295 | } |
3284 | if (NULL != udp_sock) | 3296 | if (NULL != udp_sock) |
3285 | { | 3297 | { |
3286 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (udp_sock)); | 3298 | GNUNET_break (GNUNET_OK == |
3299 | GNUNET_NETWORK_socket_close (udp_sock)); | ||
3287 | udp_sock = NULL; | 3300 | udp_sock = NULL; |
3288 | } | 3301 | } |
3289 | GNUNET_CONTAINER_multipeermap_iterate (receivers, | 3302 | GNUNET_CONTAINER_multipeermap_iterate (receivers, |
3290 | &get_receiver_delete_it, | 3303 | &get_receiver_delete_it, |
3291 | NULL); | 3304 | NULL); |
3292 | GNUNET_CONTAINER_multipeermap_destroy (receivers); | 3305 | GNUNET_CONTAINER_multipeermap_destroy (receivers); |
3293 | GNUNET_CONTAINER_multipeermap_iterate (senders, &get_sender_delete_it, NULL); | 3306 | GNUNET_CONTAINER_multipeermap_iterate (senders, |
3307 | &get_sender_delete_it, | ||
3308 | NULL); | ||
3294 | GNUNET_CONTAINER_multipeermap_destroy (senders); | 3309 | GNUNET_CONTAINER_multipeermap_destroy (senders); |
3295 | GNUNET_CONTAINER_multishortmap_destroy (key_cache); | 3310 | GNUNET_CONTAINER_multishortmap_destroy (key_cache); |
3296 | GNUNET_CONTAINER_heap_destroy (senders_heap); | 3311 | GNUNET_CONTAINER_heap_destroy (senders_heap); |
@@ -3438,25 +3453,33 @@ ifc_broadcast (void *cls) | |||
3438 | static int no = 0; | 3453 | static int no = 0; |
3439 | ssize_t sent; | 3454 | ssize_t sent; |
3440 | 3455 | ||
3441 | if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock, | 3456 | if (GNUNET_OK != |
3442 | SOL_SOCKET, | 3457 | GNUNET_NETWORK_socket_setsockopt (udp_sock, |
3443 | SO_BROADCAST, | 3458 | SOL_SOCKET, |
3444 | &yes, | 3459 | SO_BROADCAST, |
3445 | sizeof(int))) | 3460 | &yes, |
3446 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); | 3461 | sizeof(int))) |
3462 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | ||
3463 | "setsockopt"); | ||
3464 | fprintf (stderr, | ||
3465 | "BC to %s\n", | ||
3466 | GNUNET_a2s (bi->ba, | ||
3467 | bi->salen)); | ||
3447 | sent = GNUNET_NETWORK_socket_sendto (udp_sock, | 3468 | sent = GNUNET_NETWORK_socket_sendto (udp_sock, |
3448 | &bi->bcm, | 3469 | &bi->bcm, |
3449 | sizeof(bi->bcm), | 3470 | sizeof(bi->bcm), |
3450 | bi->ba, | 3471 | bi->ba, |
3451 | bi->salen); | 3472 | bi->salen); |
3452 | if (-1 == sent) | 3473 | if (-1 == sent) |
3453 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto"); | 3474 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
3475 | "sendto"); | ||
3454 | if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock, | 3476 | if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock, |
3455 | SOL_SOCKET, | 3477 | SOL_SOCKET, |
3456 | SO_BROADCAST, | 3478 | SO_BROADCAST, |
3457 | &no, | 3479 | &no, |
3458 | sizeof(int))) | 3480 | sizeof(int))) |
3459 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); | 3481 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
3482 | "setsockopt"); | ||
3460 | break; | 3483 | break; |
3461 | } | 3484 | } |
3462 | 3485 | ||
@@ -3540,7 +3563,8 @@ iface_proc (void *cls, | |||
3540 | bi = GNUNET_new (struct BroadcastInterface); | 3563 | bi = GNUNET_new (struct BroadcastInterface); |
3541 | bi->sa = GNUNET_memdup (addr, addrlen); | 3564 | bi->sa = GNUNET_memdup (addr, addrlen); |
3542 | if (NULL != broadcast_addr) | 3565 | if (NULL != broadcast_addr) |
3543 | bi->ba = GNUNET_memdup (broadcast_addr, addrlen); | 3566 | bi->ba = GNUNET_memdup (broadcast_addr, |
3567 | addrlen); | ||
3544 | bi->salen = addrlen; | 3568 | bi->salen = addrlen; |
3545 | bi->found = GNUNET_YES; | 3569 | bi->found = GNUNET_YES; |
3546 | bi->bcm.sender = my_identity; | 3570 | bi->bcm.sender = my_identity; |
@@ -3675,7 +3699,9 @@ run (void *cls, | |||
3675 | return; | 3699 | return; |
3676 | } | 3700 | } |
3677 | udp_sock = | 3701 | udp_sock = |
3678 | GNUNET_NETWORK_socket_create (in->sa_family, SOCK_DGRAM, IPPROTO_UDP); | 3702 | GNUNET_NETWORK_socket_create (in->sa_family, |
3703 | SOCK_DGRAM, | ||
3704 | IPPROTO_UDP); | ||
3679 | if (NULL == udp_sock) | 3705 | if (NULL == udp_sock) |
3680 | { | 3706 | { |
3681 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); | 3707 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); |
@@ -3685,9 +3711,14 @@ run (void *cls, | |||
3685 | } | 3711 | } |
3686 | if (AF_INET6 == in->sa_family) | 3712 | if (AF_INET6 == in->sa_family) |
3687 | have_v6_socket = GNUNET_YES; | 3713 | have_v6_socket = GNUNET_YES; |
3688 | if (GNUNET_OK != GNUNET_NETWORK_socket_bind (udp_sock, in, in_len)) | 3714 | if (GNUNET_OK != |
3715 | GNUNET_NETWORK_socket_bind (udp_sock, | ||
3716 | in, | ||
3717 | in_len)) | ||
3689 | { | 3718 | { |
3690 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", bindto); | 3719 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, |
3720 | "bind", | ||
3721 | bindto); | ||
3691 | GNUNET_NETWORK_socket_close (udp_sock); | 3722 | GNUNET_NETWORK_socket_close (udp_sock); |
3692 | udp_sock = NULL; | 3723 | udp_sock = NULL; |
3693 | GNUNET_free (in); | 3724 | GNUNET_free (in); |