diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-01-07 15:46:30 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-01-07 15:46:30 +0100 |
commit | b0ab600ddc91843c7dbab894cd56ad006be30ed5 (patch) | |
tree | 354f97499a51d4fe1203287d76985eeeeadc3c2c /src/transport/plugin_transport_tcp.c | |
parent | 0d271e8c1e5014989326b9f84b025c08552df95a (diff) | |
download | gnunet-b0ab600ddc91843c7dbab894cd56ad006be30ed5.tar.gz gnunet-b0ab600ddc91843c7dbab894cd56ad006be30ed5.zip |
migrate TCP plugin to new NAT logic
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 83 |
1 files changed, 49 insertions, 34 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 79c70138f..605579c18 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -26,7 +26,7 @@ | |||
26 | #include "gnunet_hello_lib.h" | 26 | #include "gnunet_hello_lib.h" |
27 | #include "gnunet_constants.h" | 27 | #include "gnunet_constants.h" |
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_nat_lib.h" | 29 | #include "gnunet_nat_service.h" |
30 | #include "gnunet_protocols.h" | 30 | #include "gnunet_protocols.h" |
31 | #include "gnunet_resolver_service.h" | 31 | #include "gnunet_resolver_service.h" |
32 | #include "gnunet_signatures.h" | 32 | #include "gnunet_signatures.h" |
@@ -945,13 +945,15 @@ notify_session_monitor (struct Plugin *plugin, | |||
945 | * @param cls closure, the `struct Plugin` | 945 | * @param cls closure, the `struct Plugin` |
946 | * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean | 946 | * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean |
947 | * the previous (now invalid) one | 947 | * the previous (now invalid) one |
948 | * @param ac address class the address belongs to | ||
948 | * @param addr either the previous or the new public IP address | 949 | * @param addr either the previous or the new public IP address |
949 | * @param addrlen actual length of @a addr | 950 | * @param addrlen actual length of @a addr |
950 | */ | 951 | */ |
951 | static void | 952 | static void |
952 | tcp_nat_port_map_callback (void *cls, | 953 | tcp_nat_port_map_callback (void *cls, |
953 | int add_remove, | 954 | int add_remove, |
954 | const struct sockaddr *addr, | 955 | enum GNUNET_NAT_AddressClass ac, |
956 | const struct sockaddr *addr, | ||
955 | socklen_t addrlen) | 957 | socklen_t addrlen) |
956 | { | 958 | { |
957 | struct Plugin *plugin = cls; | 959 | struct Plugin *plugin = cls; |
@@ -961,10 +963,10 @@ tcp_nat_port_map_callback (void *cls, | |||
961 | void *arg; | 963 | void *arg; |
962 | size_t args; | 964 | size_t args; |
963 | 965 | ||
964 | LOG(GNUNET_ERROR_TYPE_INFO, | 966 | LOG (GNUNET_ERROR_TYPE_INFO, |
965 | "NAT notification to %s address `%s'\n", | 967 | "NAT notification to %s address `%s'\n", |
966 | (GNUNET_YES == add_remove) ? "add" : "remove", | 968 | (GNUNET_YES == add_remove) ? "add" : "remove", |
967 | GNUNET_a2s (addr, addrlen)); | 969 | GNUNET_a2s (addr, addrlen)); |
968 | /* convert 'addr' to our internal format */ | 970 | /* convert 'addr' to our internal format */ |
969 | switch (addr->sa_family) | 971 | switch (addr->sa_family) |
970 | { | 972 | { |
@@ -980,8 +982,9 @@ tcp_nat_port_map_callback (void *cls, | |||
980 | case AF_INET6: | 982 | case AF_INET6: |
981 | GNUNET_assert(addrlen == sizeof(struct sockaddr_in6)); | 983 | GNUNET_assert(addrlen == sizeof(struct sockaddr_in6)); |
982 | memset (&t6, 0, sizeof(t6)); | 984 | memset (&t6, 0, sizeof(t6)); |
983 | GNUNET_memcpy (&t6.ipv6_addr, &((struct sockaddr_in6 *) addr)->sin6_addr, | 985 | GNUNET_memcpy (&t6.ipv6_addr, |
984 | sizeof(struct in6_addr)); | 986 | &((struct sockaddr_in6 *) addr)->sin6_addr, |
987 | sizeof(struct in6_addr)); | ||
985 | t6.options = htonl (plugin->myoptions); | 988 | t6.options = htonl (plugin->myoptions); |
986 | t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port; | 989 | t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port; |
987 | arg = &t6; | 990 | arg = &t6; |
@@ -993,11 +996,17 @@ tcp_nat_port_map_callback (void *cls, | |||
993 | } | 996 | } |
994 | /* modify our published address list */ | 997 | /* modify our published address list */ |
995 | GNUNET_assert ((args == sizeof (struct IPv4TcpAddress)) || | 998 | GNUNET_assert ((args == sizeof (struct IPv4TcpAddress)) || |
996 | (args == sizeof (struct IPv6TcpAddress))); | 999 | (args == sizeof (struct IPv6TcpAddress))); |
1000 | /* TODO: use 'ac' here in the future... */ | ||
997 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, | 1001 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, |
998 | PLUGIN_NAME, arg, args, GNUNET_HELLO_ADDRESS_INFO_NONE); | 1002 | PLUGIN_NAME, |
999 | plugin->env->notify_address (plugin->env->cls, add_remove, address); | 1003 | arg, |
1000 | GNUNET_HELLO_address_free(address); | 1004 | args, |
1005 | GNUNET_HELLO_ADDRESS_INFO_NONE); | ||
1006 | plugin->env->notify_address (plugin->env->cls, | ||
1007 | add_remove, | ||
1008 | address); | ||
1009 | GNUNET_HELLO_address_free (address); | ||
1001 | } | 1010 | } |
1002 | 1011 | ||
1003 | 1012 | ||
@@ -2068,6 +2077,8 @@ tcp_plugin_get_session (void *cls, | |||
2068 | GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, | 2077 | GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, |
2069 | &address->peer))) | 2078 | &address->peer))) |
2070 | { | 2079 | { |
2080 | struct sockaddr_in local_sa; | ||
2081 | |||
2071 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2082 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2072 | "Found valid IPv4 NAT address (creating session)!\n"); | 2083 | "Found valid IPv4 NAT address (creating session)!\n"); |
2073 | session = create_session (plugin, | 2084 | session = create_session (plugin, |
@@ -2085,23 +2096,29 @@ tcp_plugin_get_session (void *cls, | |||
2085 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 2096 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
2086 | 2097 | ||
2087 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2098 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2088 | "Created NAT WAIT connection to `%4s' at `%s'\n", | 2099 | "Created NAT WAIT connection to `%s' at `%s'\n", |
2089 | GNUNET_i2s (&session->target), | 2100 | GNUNET_i2s (&session->target), |
2090 | GNUNET_a2s (sb, sbs)); | 2101 | GNUNET_a2s (sb, sbs)); |
2091 | if (GNUNET_OK == GNUNET_NAT_run_client (plugin->nat, &a4)) | 2102 | memset (&local_sa, |
2092 | { | 2103 | 0, |
2104 | sizeof (local_sa)); | ||
2105 | local_sa.sin_family = AF_INET; | ||
2106 | local_sa.sin_port = htons (plugin->open_port); | ||
2107 | /* We leave sin_address at 0, let the kernel figure it out, | ||
2108 | even if our bind() is more specific. (May want to reconsider | ||
2109 | later.) */ | ||
2110 | if (GNUNET_OK == | ||
2111 | GNUNET_NAT_request_reversal (plugin->nat, | ||
2112 | &local_sa, | ||
2113 | &a4)) | ||
2093 | return session; | 2114 | return session; |
2094 | } | 2115 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2095 | else | 2116 | "Running NAT client for `%s' at `%s' failed\n", |
2096 | { | 2117 | GNUNET_i2s (&session->target), |
2097 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2118 | GNUNET_a2s (sb, sbs)); |
2098 | "Running NAT client for `%4s' at `%s' failed\n", | 2119 | tcp_plugin_disconnect_session (plugin, |
2099 | GNUNET_i2s (&session->target), | 2120 | session); |
2100 | GNUNET_a2s (sb, sbs)); | 2121 | return NULL; |
2101 | tcp_plugin_disconnect_session (plugin, | ||
2102 | session); | ||
2103 | return NULL; | ||
2104 | } | ||
2105 | } | 2122 | } |
2106 | 2123 | ||
2107 | /* create new outbound session */ | 2124 | /* create new outbound session */ |
@@ -3388,15 +3405,14 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
3388 | GNUNET_a2s (addrs[ret], addrlens[ret])); | 3405 | GNUNET_a2s (addrs[ret], addrlens[ret])); |
3389 | plugin->nat | 3406 | plugin->nat |
3390 | = GNUNET_NAT_register (env->cfg, | 3407 | = GNUNET_NAT_register (env->cfg, |
3391 | GNUNET_YES, | 3408 | "transport-tcp", |
3392 | aport, | 3409 | IPPROTO_TCP, |
3393 | (unsigned int) ret_s, | 3410 | (unsigned int) ret_s, |
3394 | (const struct sockaddr **) addrs, | 3411 | (const struct sockaddr **) addrs, |
3395 | addrlens, | 3412 | addrlens, |
3396 | &tcp_nat_port_map_callback, | 3413 | &tcp_nat_port_map_callback, |
3397 | &try_connection_reversal, | 3414 | &try_connection_reversal, |
3398 | plugin, | 3415 | plugin); |
3399 | NULL); | ||
3400 | for (ret = ret_s -1; ret >= 0; ret--) | 3416 | for (ret = ret_s -1; ret >= 0; ret--) |
3401 | GNUNET_free (addrs[ret]); | 3417 | GNUNET_free (addrs[ret]); |
3402 | GNUNET_free_non_null (addrs); | 3418 | GNUNET_free_non_null (addrs); |
@@ -3405,15 +3421,14 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
3405 | else | 3421 | else |
3406 | { | 3422 | { |
3407 | plugin->nat = GNUNET_NAT_register (plugin->env->cfg, | 3423 | plugin->nat = GNUNET_NAT_register (plugin->env->cfg, |
3408 | GNUNET_YES, | 3424 | "transport-tcp", |
3409 | 0, | 3425 | IPPROTO_TCP, |
3410 | 0, | 3426 | 0, |
3411 | NULL, | 3427 | NULL, |
3412 | NULL, | 3428 | NULL, |
3413 | NULL, | 3429 | NULL, |
3414 | &try_connection_reversal, | 3430 | &try_connection_reversal, |
3415 | plugin, | 3431 | plugin); |
3416 | NULL); | ||
3417 | } | 3432 | } |
3418 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); | 3433 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
3419 | api->cls = plugin; | 3434 | api->cls = plugin; |