diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-02-19 23:26:57 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-02-19 23:26:57 +0100 |
commit | c2d8966687f4c1b88c9fee8ce8913a51c4bb0f83 (patch) | |
tree | db3ba8dd37e2b1abdff6fbe1a239cd567538cb85 /src/transport/plugin_transport_tcp.c | |
parent | 3902d240e408e85f08d9c444356eb18fc6ea44e7 (diff) | |
download | gnunet-c2d8966687f4c1b88c9fee8ce8913a51c4bb0f83.tar.gz gnunet-c2d8966687f4c1b88c9fee8ce8913a51c4bb0f83.zip |
misc log fixes, plus prevent multiple TCP connections from wrecking havoc by creating a missunderstanding about which one is active
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 92 |
1 files changed, 60 insertions, 32 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index eca62a8ca..4ed5b38f7 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -1418,7 +1418,7 @@ create_session (struct Plugin *plugin, | |||
1418 | GNUNET_assert (NULL == client); | 1418 | GNUNET_assert (NULL == client); |
1419 | 1419 | ||
1420 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1420 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1421 | "Creating new session for peer `%4s' at address %s\n", | 1421 | "Creating new session for peer `%s' at address %s\n", |
1422 | GNUNET_i2s (&address->peer), | 1422 | GNUNET_i2s (&address->peer), |
1423 | tcp_plugin_address_to_string (plugin, | 1423 | tcp_plugin_address_to_string (plugin, |
1424 | address->address, | 1424 | address->address, |
@@ -1522,7 +1522,7 @@ do_transmit (void *cls, | |||
1522 | if (NULL == buf) | 1522 | if (NULL == buf) |
1523 | { | 1523 | { |
1524 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1524 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1525 | "Timeout trying to transmit to peer `%4s', discarding message queue.\n", | 1525 | "Timeout trying to transmit to peer `%s', discarding message queue.\n", |
1526 | GNUNET_i2s (&session->target)); | 1526 | GNUNET_i2s (&session->target)); |
1527 | /* timeout; cancel all messages that have already expired */ | 1527 | /* timeout; cancel all messages that have already expired */ |
1528 | hd = NULL; | 1528 | hd = NULL; |
@@ -1540,7 +1540,7 @@ do_transmit (void *cls, | |||
1540 | GNUNET_assert (pos->message_size <= session->bytes_in_queue); | 1540 | GNUNET_assert (pos->message_size <= session->bytes_in_queue); |
1541 | session->bytes_in_queue -= pos->message_size; | 1541 | session->bytes_in_queue -= pos->message_size; |
1542 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1542 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1543 | "Failed to transmit %u byte message to `%4s'.\n", | 1543 | "Failed to transmit %u byte message to `%s'.\n", |
1544 | pos->message_size, | 1544 | pos->message_size, |
1545 | GNUNET_i2s (&session->target)); | 1545 | GNUNET_i2s (&session->target)); |
1546 | ret += pos->message_size; | 1546 | ret += pos->message_size; |
@@ -1729,10 +1729,10 @@ tcp_plugin_send (void *cls, | |||
1729 | pm->transmit_cont = cont; | 1729 | pm->transmit_cont = cont; |
1730 | pm->transmit_cont_cls = cont_cls; | 1730 | pm->transmit_cont_cls = cont_cls; |
1731 | 1731 | ||
1732 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1732 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1733 | "Asked to transmit %u bytes to `%s', added message to list.\n", | 1733 | "Asked to transmit %u bytes to `%s', added message to list.\n", |
1734 | msgbuf_size, | 1734 | msgbuf_size, |
1735 | GNUNET_i2s (&session->target)); | 1735 | GNUNET_i2s (&session->target)); |
1736 | 1736 | ||
1737 | if (GNUNET_YES == | 1737 | if (GNUNET_YES == |
1738 | GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, | 1738 | GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, |
@@ -1997,6 +1997,13 @@ tcp_plugin_get_session (void *cls, | |||
1997 | address->address_length)); | 1997 | address->address_length)); |
1998 | return session; | 1998 | return session; |
1999 | } | 1999 | } |
2000 | /* This is a bit of a hack, limiting TCP to never allow more than | ||
2001 | one TCP connection to any given peer at the same time. | ||
2002 | Without this, peers sometimes disagree about which of the TCP | ||
2003 | connections they should use, causing one side to believe that | ||
2004 | they transmit successfully, while the other receives nothing. */ | ||
2005 | return NULL; /* Refuse to have more than one TCP connection per | ||
2006 | peer pair at the same time. */ | ||
2000 | } | 2007 | } |
2001 | 2008 | ||
2002 | if (addrlen == sizeof(struct IPv6TcpAddress)) | 2009 | if (addrlen == sizeof(struct IPv6TcpAddress)) |
@@ -2078,7 +2085,7 @@ tcp_plugin_get_session (void *cls, | |||
2078 | &address->peer))) | 2085 | &address->peer))) |
2079 | { | 2086 | { |
2080 | struct sockaddr_in local_sa; | 2087 | struct sockaddr_in local_sa; |
2081 | 2088 | ||
2082 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2089 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2083 | "Found valid IPv4 NAT address (creating session)!\n"); | 2090 | "Found valid IPv4 NAT address (creating session)!\n"); |
2084 | session = create_session (plugin, | 2091 | session = create_session (plugin, |
@@ -2168,13 +2175,13 @@ tcp_plugin_get_session (void *cls, | |||
2168 | if (NULL == sa) | 2175 | if (NULL == sa) |
2169 | { | 2176 | { |
2170 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2177 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2171 | "Failed to create connection to `%4s' at `%s'\n", | 2178 | "Failed to create connection to `%s' at `%s'\n", |
2172 | GNUNET_i2s (&address->peer), | 2179 | GNUNET_i2s (&address->peer), |
2173 | GNUNET_a2s (sb, sbs)); | 2180 | GNUNET_a2s (sb, sbs)); |
2174 | return NULL; | 2181 | return NULL; |
2175 | } | 2182 | } |
2176 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2183 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2177 | "Asked to transmit to `%4s', creating fresh session using address `%s'.\n", | 2184 | "Asked to transmit to `%s', creating fresh session using address `%s'.\n", |
2178 | GNUNET_i2s (&address->peer), | 2185 | GNUNET_i2s (&address->peer), |
2179 | GNUNET_a2s (sb, sbs)); | 2186 | GNUNET_a2s (sb, sbs)); |
2180 | 2187 | ||
@@ -2246,7 +2253,7 @@ tcp_plugin_disconnect (void *cls, | |||
2246 | struct Plugin *plugin = cls; | 2253 | struct Plugin *plugin = cls; |
2247 | 2254 | ||
2248 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2255 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2249 | "Disconnecting peer `%4s'\n", | 2256 | "Disconnecting peer `%s'\n", |
2250 | GNUNET_i2s (target)); | 2257 | GNUNET_i2s (target)); |
2251 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap, | 2258 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap, |
2252 | target, | 2259 | target, |
@@ -2446,7 +2453,7 @@ tcp_plugin_check_address (void *cls, | |||
2446 | if (addrlen == sizeof(struct IPv4TcpAddress)) | 2453 | if (addrlen == sizeof(struct IPv4TcpAddress)) |
2447 | { | 2454 | { |
2448 | struct sockaddr_in s4; | 2455 | struct sockaddr_in s4; |
2449 | 2456 | ||
2450 | v4 = (const struct IPv4TcpAddress *) addr; | 2457 | v4 = (const struct IPv4TcpAddress *) addr; |
2451 | if (0 != memcmp (&v4->options, | 2458 | if (0 != memcmp (&v4->options, |
2452 | &plugin->myoptions, | 2459 | &plugin->myoptions, |
@@ -2462,7 +2469,7 @@ tcp_plugin_check_address (void *cls, | |||
2462 | #endif | 2469 | #endif |
2463 | s4.sin_port = v4->t4_port; | 2470 | s4.sin_port = v4->t4_port; |
2464 | s4.sin_addr.s_addr = v4->ipv4_addr; | 2471 | s4.sin_addr.s_addr = v4->ipv4_addr; |
2465 | 2472 | ||
2466 | if (GNUNET_OK != | 2473 | if (GNUNET_OK != |
2467 | GNUNET_NAT_test_address (plugin->nat, | 2474 | GNUNET_NAT_test_address (plugin->nat, |
2468 | &s4, | 2475 | &s4, |
@@ -2472,7 +2479,7 @@ tcp_plugin_check_address (void *cls, | |||
2472 | else | 2479 | else |
2473 | { | 2480 | { |
2474 | struct sockaddr_in6 s6; | 2481 | struct sockaddr_in6 s6; |
2475 | 2482 | ||
2476 | v6 = (const struct IPv6TcpAddress *) addr; | 2483 | v6 = (const struct IPv6TcpAddress *) addr; |
2477 | if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) | 2484 | if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) |
2478 | { | 2485 | { |
@@ -2686,27 +2693,37 @@ handle_tcp_welcome (void *cls, | |||
2686 | &alen)) | 2693 | &alen)) |
2687 | { | 2694 | { |
2688 | LOG (GNUNET_ERROR_TYPE_INFO, | 2695 | LOG (GNUNET_ERROR_TYPE_INFO, |
2689 | "Received WELCOME message from my own identity `%4s' on address `%s'\n", | 2696 | "Received WELCOME message from my own identity `%s' on address `%s'\n", |
2690 | GNUNET_i2s (&wm->clientIdentity), | 2697 | GNUNET_i2s (&wm->clientIdentity), |
2691 | GNUNET_a2s (vaddr, alen)); | 2698 | GNUNET_a2s (vaddr, alen)); |
2692 | GNUNET_free(vaddr); | 2699 | GNUNET_free (vaddr); |
2693 | } | 2700 | } |
2694 | return; | 2701 | return; |
2695 | } | 2702 | } |
2696 | 2703 | ||
2697 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2704 | if (GNUNET_OK == |
2698 | "Received WELCOME message from `%4s' %p\n", | 2705 | GNUNET_SERVER_client_get_address (client, |
2699 | GNUNET_i2s (&wm->clientIdentity), | 2706 | &vaddr, |
2700 | client); | 2707 | &alen)) |
2708 | { | ||
2709 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
2710 | "Received WELCOME message from `%s' on address `%s'\n", | ||
2711 | GNUNET_i2s (&wm->clientIdentity), | ||
2712 | GNUNET_a2s (vaddr, alen)); | ||
2713 | GNUNET_free (vaddr); | ||
2714 | } | ||
2701 | GNUNET_STATISTICS_update (plugin->env->stats, | 2715 | GNUNET_STATISTICS_update (plugin->env->stats, |
2702 | gettext_noop ("# TCP WELCOME messages received"), | 2716 | gettext_noop ("# TCP WELCOME messages received"), |
2703 | 1, | 2717 | 1, |
2704 | GNUNET_NO); | 2718 | GNUNET_NO); |
2705 | session = lookup_session_by_client (plugin, client); | 2719 | session = lookup_session_by_client (plugin, |
2720 | client); | ||
2706 | if (NULL != session) | 2721 | if (NULL != session) |
2707 | { | 2722 | { |
2708 | if (GNUNET_OK == | 2723 | if (GNUNET_OK == |
2709 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) | 2724 | GNUNET_SERVER_client_get_address (client, |
2725 | &vaddr, | ||
2726 | &alen)) | ||
2710 | { | 2727 | { |
2711 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2728 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2712 | "Found existing session %p for peer `%s'\n", | 2729 | "Found existing session %p for peer `%s'\n", |
@@ -2795,12 +2812,11 @@ handle_tcp_welcome (void *cls, | |||
2795 | } | 2812 | } |
2796 | } | 2813 | } |
2797 | 2814 | ||
2798 | if (session->expecting_welcome != GNUNET_YES) | 2815 | if (GNUNET_YES != session->expecting_welcome) |
2799 | { | 2816 | { |
2800 | GNUNET_break_op(0); | 2817 | GNUNET_break_op (0); |
2801 | GNUNET_SERVER_receive_done (client, | 2818 | GNUNET_SERVER_receive_done (client, |
2802 | GNUNET_SYSERR); | 2819 | GNUNET_SYSERR); |
2803 | GNUNET_break(0); | ||
2804 | return; | 2820 | return; |
2805 | } | 2821 | } |
2806 | session->last_activity = GNUNET_TIME_absolute_get (); | 2822 | session->last_activity = GNUNET_TIME_absolute_get (); |
@@ -2869,7 +2885,9 @@ handle_tcp_data (void *cls, | |||
2869 | void *vaddr; | 2885 | void *vaddr; |
2870 | size_t alen; | 2886 | size_t alen; |
2871 | 2887 | ||
2872 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen); | 2888 | GNUNET_SERVER_client_get_address (client, |
2889 | &vaddr, | ||
2890 | &alen); | ||
2873 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2891 | LOG (GNUNET_ERROR_TYPE_ERROR, |
2874 | "Received unexpected %u bytes of type %u from `%s'\n", | 2892 | "Received unexpected %u bytes of type %u from `%s'\n", |
2875 | (unsigned int) ntohs (message->size), | 2893 | (unsigned int) ntohs (message->size), |
@@ -2883,11 +2901,21 @@ handle_tcp_data (void *cls, | |||
2883 | } | 2901 | } |
2884 | 2902 | ||
2885 | session->last_activity = GNUNET_TIME_absolute_get (); | 2903 | session->last_activity = GNUNET_TIME_absolute_get (); |
2886 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2904 | { |
2887 | "Passing %u bytes of type %u from `%4s' to transport service.\n", | 2905 | void *vaddr; |
2888 | (unsigned int) ntohs (message->size), | 2906 | size_t alen; |
2889 | (unsigned int) ntohs (message->type), | 2907 | |
2890 | GNUNET_i2s (&session->target)); | 2908 | GNUNET_SERVER_client_get_address (client, |
2909 | &vaddr, | ||
2910 | &alen); | ||
2911 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2912 | "Passing %u bytes of type %u from `%s' at %s to transport service.\n", | ||
2913 | (unsigned int) ntohs (message->size), | ||
2914 | (unsigned int) ntohs (message->type), | ||
2915 | GNUNET_i2s (&session->target), | ||
2916 | GNUNET_a2s (vaddr, alen)); | ||
2917 | GNUNET_free_non_null (vaddr); | ||
2918 | } | ||
2891 | 2919 | ||
2892 | GNUNET_STATISTICS_update (plugin->env->stats, | 2920 | GNUNET_STATISTICS_update (plugin->env->stats, |
2893 | gettext_noop ("# bytes received via TCP"), | 2921 | gettext_noop ("# bytes received via TCP"), |
@@ -2984,7 +3012,7 @@ disconnect_notify (void *cls, | |||
2984 | if (NULL == session) | 3012 | if (NULL == session) |
2985 | return; /* unknown, nothing to do */ | 3013 | return; /* unknown, nothing to do */ |
2986 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3014 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2987 | "Destroying session of `%4s' with %s due to network-level disconnect.\n", | 3015 | "Destroying session of `%s' with %s due to network-level disconnect.\n", |
2988 | GNUNET_i2s (&session->target), | 3016 | GNUNET_i2s (&session->target), |
2989 | tcp_plugin_address_to_string (session->plugin, | 3017 | tcp_plugin_address_to_string (session->plugin, |
2990 | session->address->address, | 3018 | session->address->address, |