diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-10-07 14:15:38 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-10-07 14:15:38 +0000 |
commit | e5bd8fb4aa72717b8707a4652f14c0735acb52c4 (patch) | |
tree | 08398e22b9408cc24b6b9e6cb360fe04b9eeae05 /src/transport | |
parent | 572bab1ace57fb9d7acbd218d6940cb1e9a0797b (diff) | |
download | gnunet-e5bd8fb4aa72717b8707a4652f14c0735acb52c4.tar.gz gnunet-e5bd8fb4aa72717b8707a4652f14c0735acb52c4.zip |
determine network scope for ATS even if we do not yet have a session and only have an address
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/gnunet-service-transport_ats.c | 1 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_neighbours.c | 9 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_validation.c | 21 | ||||
-rw-r--r-- | src/transport/plugin_transport_http_client.c | 19 | ||||
-rw-r--r-- | src/transport/plugin_transport_http_common.c | 51 | ||||
-rw-r--r-- | src/transport/plugin_transport_http_common.h | 13 | ||||
-rw-r--r-- | src/transport/plugin_transport_http_server.c | 21 | ||||
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 61 | ||||
-rw-r--r-- | src/transport/plugin_transport_udp.c | 67 | ||||
-rw-r--r-- | src/transport/plugin_transport_unix.c | 17 | ||||
-rw-r--r-- | src/transport/plugin_transport_wlan.c | 20 |
11 files changed, 288 insertions, 12 deletions
diff --git a/src/transport/gnunet-service-transport_ats.c b/src/transport/gnunet-service-transport_ats.c index 74658822e..5124cd578 100644 --- a/src/transport/gnunet-service-transport_ats.c +++ b/src/transport/gnunet-service-transport_ats.c | |||
@@ -478,6 +478,7 @@ GST_ats_add_address (const struct GNUNET_HELLO_Address *address, | |||
478 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)); | 478 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)); |
479 | ai = find_ai_no_session (address); | 479 | ai = find_ai_no_session (address); |
480 | GNUNET_assert (NULL == ai); | 480 | GNUNET_assert (NULL == ai); |
481 | GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope); | ||
481 | LOG (GNUNET_ERROR_TYPE_INFO, | 482 | LOG (GNUNET_ERROR_TYPE_INFO, |
482 | "Notifying ATS about peer `%s''s new address `%s'\n", | 483 | "Notifying ATS about peer `%s''s new address `%s'\n", |
483 | GNUNET_i2s (&address->peer), | 484 | GNUNET_i2s (&address->peer), |
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index 01546ded4..461d2669a 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c | |||
@@ -3530,7 +3530,7 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message, | |||
3530 | 3530 | ||
3531 | if ( ( (GNUNET_TRANSPORT_PS_SYN_RECV_ACK != n->state) && | 3531 | if ( ( (GNUNET_TRANSPORT_PS_SYN_RECV_ACK != n->state) && |
3532 | (ACK_SEND_ACK != n->ack_state) ) || | 3532 | (ACK_SEND_ACK != n->ack_state) ) || |
3533 | (NULL == n->primary_address.address) ) | 3533 | (NULL == n->primary_address.address) ) |
3534 | { | 3534 | { |
3535 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3535 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3536 | "Received unexpected ACK message from peer `%s' in state %s/%s\n", | 3536 | "Received unexpected ACK message from peer `%s' in state %s/%s\n", |
@@ -3850,10 +3850,11 @@ neighbours_iterate (void *cls, | |||
3850 | * Iterate over all connected neighbours. | 3850 | * Iterate over all connected neighbours. |
3851 | * | 3851 | * |
3852 | * @param cb function to call | 3852 | * @param cb function to call |
3853 | * @param cb_cls closure for cb | 3853 | * @param cb_cls closure for @a cb |
3854 | */ | 3854 | */ |
3855 | void | 3855 | void |
3856 | GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls) | 3856 | GST_neighbours_iterate (GST_NeighbourIterator cb, |
3857 | void *cb_cls) | ||
3857 | { | 3858 | { |
3858 | struct IteratorContext ic; | 3859 | struct IteratorContext ic; |
3859 | 3860 | ||
@@ -3930,7 +3931,7 @@ GST_neighbours_start (unsigned int max_fds) | |||
3930 | * | 3931 | * |
3931 | * @param cls unused | 3932 | * @param cls unused |
3932 | * @param key hash of neighbour's public key (not used) | 3933 | * @param key hash of neighbour's public key (not used) |
3933 | * @param value the 'struct NeighbourMapEntry' of the neighbour | 3934 | * @param value the `struct NeighbourMapEntry` of the neighbour |
3934 | * @return #GNUNET_OK (continue to iterate) | 3935 | * @return #GNUNET_OK (continue to iterate) |
3935 | */ | 3936 | */ |
3936 | static int | 3937 | static int |
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index 66f9f5409..c7d760199 100644 --- a/src/transport/gnunet-service-transport_validation.c +++ b/src/transport/gnunet-service-transport_validation.c | |||
@@ -789,7 +789,9 @@ find_validation_entry (const struct GNUNET_HELLO_Address *address) | |||
789 | ve->in_use = GNUNET_SYSERR; /* not defined */ | 789 | ve->in_use = GNUNET_SYSERR; /* not defined */ |
790 | ve->address = GNUNET_HELLO_address_copy (address); | 790 | ve->address = GNUNET_HELLO_address_copy (address); |
791 | ve->pong_sig_valid_until = GNUNET_TIME_UNIT_ZERO_ABS; | 791 | ve->pong_sig_valid_until = GNUNET_TIME_UNIT_ZERO_ABS; |
792 | memset (&ve->pong_sig_cache, '\0', sizeof (struct GNUNET_CRYPTO_EddsaSignature)); | 792 | memset (&ve->pong_sig_cache, |
793 | '\0', | ||
794 | sizeof (struct GNUNET_CRYPTO_EddsaSignature)); | ||
793 | ve->latency = GNUNET_TIME_UNIT_FOREVER_REL; | 795 | ve->latency = GNUNET_TIME_UNIT_FOREVER_REL; |
794 | ve->challenge = | 796 | ve->challenge = |
795 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); | 797 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); |
@@ -828,6 +830,7 @@ add_valid_address (void *cls, | |||
828 | struct ValidationEntry *ve; | 830 | struct ValidationEntry *ve; |
829 | struct GNUNET_PeerIdentity pid; | 831 | struct GNUNET_PeerIdentity pid; |
830 | struct GNUNET_ATS_Properties prop; | 832 | struct GNUNET_ATS_Properties prop; |
833 | struct GNUNET_TRANSPORT_PluginFunctions *papi; | ||
831 | 834 | ||
832 | if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) | 835 | if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) |
833 | return GNUNET_OK; /* expired */ | 836 | return GNUNET_OK; /* expired */ |
@@ -836,14 +839,26 @@ add_valid_address (void *cls, | |||
836 | GNUNET_break (0); | 839 | GNUNET_break (0); |
837 | return GNUNET_OK; /* invalid HELLO !? */ | 840 | return GNUNET_OK; /* invalid HELLO !? */ |
838 | } | 841 | } |
839 | if (NULL == GST_plugins_find (address->transport_name)) | 842 | if (NULL == (papi = GST_plugins_find (address->transport_name))) |
840 | { | 843 | { |
841 | /* might have been valid in the past, but we don't have that | 844 | /* might have been valid in the past, but we don't have that |
842 | plugin loaded right now */ | 845 | plugin loaded right now */ |
843 | return GNUNET_OK; | 846 | return GNUNET_OK; |
844 | } | 847 | } |
848 | if (NULL == | ||
849 | papi->address_to_string (papi->cls, | ||
850 | address->address, | ||
851 | address->address_length)) | ||
852 | { | ||
853 | /* Why do we try to add an ill-formed address? */ | ||
854 | GNUNET_break (0); | ||
855 | return GNUNET_OK; | ||
856 | } | ||
845 | 857 | ||
846 | ve = find_validation_entry (address); | 858 | ve = find_validation_entry (address); |
859 | ve->network = papi->get_network_for_address (papi->cls, | ||
860 | address); | ||
861 | GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != ve->network); | ||
847 | ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, | 862 | ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, |
848 | expiration); | 863 | expiration); |
849 | if (NULL == ve->revalidation_task) | 864 | if (NULL == ve->revalidation_task) |
@@ -857,6 +872,7 @@ add_valid_address (void *cls, | |||
857 | validation_entry_changed (ve, | 872 | validation_entry_changed (ve, |
858 | GNUNET_TRANSPORT_VS_UPDATE); | 873 | GNUNET_TRANSPORT_VS_UPDATE); |
859 | memset (&prop, 0, sizeof (prop)); | 874 | memset (&prop, 0, sizeof (prop)); |
875 | GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != ve->network); | ||
860 | prop.scope = ve->network; | 876 | prop.scope = ve->network; |
861 | prop.delay = GNUNET_TIME_relative_divide (ve->latency, 2); | 877 | prop.delay = GNUNET_TIME_relative_divide (ve->latency, 2); |
862 | if (GNUNET_YES != ve->known_to_ats) | 878 | if (GNUNET_YES != ve->known_to_ats) |
@@ -1506,6 +1522,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, | |||
1506 | struct GNUNET_ATS_Properties prop; | 1522 | struct GNUNET_ATS_Properties prop; |
1507 | 1523 | ||
1508 | memset (&prop, 0, sizeof (prop)); | 1524 | memset (&prop, 0, sizeof (prop)); |
1525 | GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != ve->network); | ||
1509 | prop.scope = ve->network; | 1526 | prop.scope = ve->network; |
1510 | prop.delay = GNUNET_TIME_relative_divide (ve->latency, 2); | 1527 | prop.delay = GNUNET_TIME_relative_divide (ve->latency, 2); |
1511 | GNUNET_assert (GNUNET_NO == | 1528 | GNUNET_assert (GNUNET_NO == |
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index de9ad541b..8066fb384 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c | |||
@@ -1942,6 +1942,24 @@ http_client_plugin_get_network (void *cls, | |||
1942 | 1942 | ||
1943 | 1943 | ||
1944 | /** | 1944 | /** |
1945 | * Function obtain the network type for an address. | ||
1946 | * | ||
1947 | * @param cls closure (`struct Plugin *`) | ||
1948 | * @param address the address | ||
1949 | * @return the network type | ||
1950 | */ | ||
1951 | static enum GNUNET_ATS_Network_Type | ||
1952 | http_client_plugin_get_network_for_address (void *cls, | ||
1953 | const struct GNUNET_HELLO_Address *address) | ||
1954 | { | ||
1955 | struct HTTP_Client_Plugin *plugin = cls; | ||
1956 | |||
1957 | return http_common_get_network_for_address (plugin->env, | ||
1958 | address); | ||
1959 | } | ||
1960 | |||
1961 | |||
1962 | /** | ||
1945 | * Session was idle, so disconnect it | 1963 | * Session was idle, so disconnect it |
1946 | * | 1964 | * |
1947 | * @param cls the `struct Session` of the idle session | 1965 | * @param cls the `struct Session` of the idle session |
@@ -2469,6 +2487,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
2469 | api->string_to_address = &http_common_plugin_string_to_address; | 2487 | api->string_to_address = &http_common_plugin_string_to_address; |
2470 | api->address_pretty_printer = &http_common_plugin_address_pretty_printer; | 2488 | api->address_pretty_printer = &http_common_plugin_address_pretty_printer; |
2471 | api->get_network = &http_client_plugin_get_network; | 2489 | api->get_network = &http_client_plugin_get_network; |
2490 | api->get_network_for_address = &http_client_plugin_get_network_for_address; | ||
2472 | api->update_session_timeout = &http_client_plugin_update_session_timeout; | 2491 | api->update_session_timeout = &http_client_plugin_update_session_timeout; |
2473 | api->update_inbound_delay = &http_client_plugin_update_inbound_delay; | 2492 | api->update_inbound_delay = &http_client_plugin_update_inbound_delay; |
2474 | api->setup_monitor = &http_client_plugin_setup_monitor; | 2493 | api->setup_monitor = &http_client_plugin_setup_monitor; |
diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c index 77558a49b..13f01f713 100644 --- a/src/transport/plugin_transport_http_common.c +++ b/src/transport/plugin_transport_http_common.c | |||
@@ -854,8 +854,10 @@ http_common_address_get_size (const struct HttpAddress * addr) | |||
854 | * @return #GNUNET_YES if equal, #GNUNET_NO if not, #GNUNET_SYSERR on error | 854 | * @return #GNUNET_YES if equal, #GNUNET_NO if not, #GNUNET_SYSERR on error |
855 | */ | 855 | */ |
856 | size_t | 856 | size_t |
857 | http_common_cmp_addresses (const void *addr1, size_t addrlen1, | 857 | http_common_cmp_addresses (const void *addr1, |
858 | const void *addr2, size_t addrlen2) | 858 | size_t addrlen1, |
859 | const void *addr2, | ||
860 | size_t addrlen2) | ||
859 | { | 861 | { |
860 | const char *a1 = addr1; | 862 | const char *a1 = addr1; |
861 | const char *a2 = addr2; | 863 | const char *a2 = addr2; |
@@ -888,4 +890,49 @@ http_common_cmp_addresses (const void *addr1, size_t addrlen1, | |||
888 | return GNUNET_NO; | 890 | return GNUNET_NO; |
889 | } | 891 | } |
890 | 892 | ||
893 | |||
894 | /** | ||
895 | * Function obtain the network type for an address. | ||
896 | * | ||
897 | * @param env the environment | ||
898 | * @param address the address | ||
899 | * @return the network type | ||
900 | */ | ||
901 | enum GNUNET_ATS_Network_Type | ||
902 | http_common_get_network_for_address (struct GNUNET_TRANSPORT_PluginEnvironment *env, | ||
903 | const struct GNUNET_HELLO_Address *address) | ||
904 | { | ||
905 | |||
906 | struct sockaddr *sa; | ||
907 | enum GNUNET_ATS_Network_Type net_type; | ||
908 | size_t salen = 0; | ||
909 | int res; | ||
910 | |||
911 | net_type = GNUNET_ATS_NET_UNSPECIFIED; | ||
912 | sa = http_common_socket_from_address (address->address, | ||
913 | address->address_length, | ||
914 | &res); | ||
915 | if (GNUNET_SYSERR == res) | ||
916 | return net_type; | ||
917 | if (GNUNET_YES == res) | ||
918 | { | ||
919 | GNUNET_assert (NULL != sa); | ||
920 | if (AF_INET == sa->sa_family) | ||
921 | { | ||
922 | salen = sizeof (struct sockaddr_in); | ||
923 | } | ||
924 | else if (AF_INET6 == sa->sa_family) | ||
925 | { | ||
926 | salen = sizeof (struct sockaddr_in6); | ||
927 | } | ||
928 | net_type = env->get_address_type (env->cls, | ||
929 | sa, | ||
930 | salen); | ||
931 | GNUNET_free (sa); | ||
932 | } | ||
933 | return net_type; | ||
934 | } | ||
935 | |||
936 | |||
937 | |||
891 | /* end of plugin_transport_http_common.c */ | 938 | /* end of plugin_transport_http_common.c */ |
diff --git a/src/transport/plugin_transport_http_common.h b/src/transport/plugin_transport_http_common.h index 15466cc9e..51438d6e6 100644 --- a/src/transport/plugin_transport_http_common.h +++ b/src/transport/plugin_transport_http_common.h | |||
@@ -247,4 +247,17 @@ http_common_cmp_addresses (const void *addr1, | |||
247 | const void *addr2, | 247 | const void *addr2, |
248 | size_t addrlen2); | 248 | size_t addrlen2); |
249 | 249 | ||
250 | |||
251 | /** | ||
252 | * Function obtain the network type for an address. | ||
253 | * | ||
254 | * @param env the environment | ||
255 | * @param address the address | ||
256 | * @return the network type | ||
257 | */ | ||
258 | enum GNUNET_ATS_Network_Type | ||
259 | http_common_get_network_for_address (struct GNUNET_TRANSPORT_PluginEnvironment *env, | ||
260 | const struct GNUNET_HELLO_Address *address); | ||
261 | |||
262 | |||
250 | /* end of plugin_transport_http_common.h */ | 263 | /* end of plugin_transport_http_common.h */ |
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index 0000a604d..db483098a 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c | |||
@@ -3251,7 +3251,7 @@ http_server_plugin_address_to_string (void *cls, | |||
3251 | /** | 3251 | /** |
3252 | * Function obtain the network type for a session | 3252 | * Function obtain the network type for a session |
3253 | * | 3253 | * |
3254 | * @param cls closure ('struct HTTP_Server_Plugin*') | 3254 | * @param cls closure (`struct HTTP_Server_Plugin *`) |
3255 | * @param session the session | 3255 | * @param session the session |
3256 | * @return the network type in HBO or #GNUNET_SYSERR | 3256 | * @return the network type in HBO or #GNUNET_SYSERR |
3257 | */ | 3257 | */ |
@@ -3264,6 +3264,24 @@ http_server_plugin_get_network (void *cls, | |||
3264 | 3264 | ||
3265 | 3265 | ||
3266 | /** | 3266 | /** |
3267 | * Function obtain the network type for an address. | ||
3268 | * | ||
3269 | * @param cls closure (`struct Plugin *`) | ||
3270 | * @param address the address | ||
3271 | * @return the network type | ||
3272 | */ | ||
3273 | static enum GNUNET_ATS_Network_Type | ||
3274 | http_server_plugin_get_network_for_address (void *cls, | ||
3275 | const struct GNUNET_HELLO_Address *address) | ||
3276 | { | ||
3277 | struct HTTP_Server_Plugin *plugin = cls; | ||
3278 | |||
3279 | return http_common_get_network_for_address (plugin->env, | ||
3280 | address); | ||
3281 | } | ||
3282 | |||
3283 | |||
3284 | /** | ||
3267 | * Function that will be called whenever the transport service wants to | 3285 | * Function that will be called whenever the transport service wants to |
3268 | * notify the plugin that the inbound quota changed and that the plugin | 3286 | * notify the plugin that the inbound quota changed and that the plugin |
3269 | * should update it's delay for the next receive value | 3287 | * should update it's delay for the next receive value |
@@ -3393,6 +3411,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
3393 | api->string_to_address = &http_common_plugin_string_to_address; | 3411 | api->string_to_address = &http_common_plugin_string_to_address; |
3394 | api->address_pretty_printer = &http_common_plugin_address_pretty_printer; | 3412 | api->address_pretty_printer = &http_common_plugin_address_pretty_printer; |
3395 | api->get_network = &http_server_plugin_get_network; | 3413 | api->get_network = &http_server_plugin_get_network; |
3414 | api->get_network_for_address = &http_server_plugin_get_network_for_address; | ||
3396 | api->update_session_timeout = &http_server_plugin_update_session_timeout; | 3415 | api->update_session_timeout = &http_server_plugin_update_session_timeout; |
3397 | api->update_inbound_delay = &http_server_plugin_update_inbound_delay; | 3416 | api->update_inbound_delay = &http_server_plugin_update_inbound_delay; |
3398 | api->setup_monitor = &http_server_plugin_setup_monitor; | 3417 | api->setup_monitor = &http_server_plugin_setup_monitor; |
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 330b24f61..453a0095f 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -2734,6 +2734,66 @@ tcp_plugin_get_network (void *cls, | |||
2734 | 2734 | ||
2735 | 2735 | ||
2736 | /** | 2736 | /** |
2737 | * Function obtain the network type for an address. | ||
2738 | * | ||
2739 | * @param cls closure (`struct Plugin *`) | ||
2740 | * @param address the address | ||
2741 | * @return the network type | ||
2742 | */ | ||
2743 | static enum GNUNET_ATS_Network_Type | ||
2744 | tcp_plugin_get_network_for_address (void *cls, | ||
2745 | const struct GNUNET_HELLO_Address *address) | ||
2746 | { | ||
2747 | struct Plugin *plugin = cls; | ||
2748 | size_t addrlen; | ||
2749 | struct sockaddr_in a4; | ||
2750 | struct sockaddr_in6 a6; | ||
2751 | const struct IPv4TcpAddress *t4; | ||
2752 | const struct IPv6TcpAddress *t6; | ||
2753 | const void *sb; | ||
2754 | size_t sbs; | ||
2755 | |||
2756 | addrlen = address->address_length; | ||
2757 | if (addrlen == sizeof(struct IPv6TcpAddress)) | ||
2758 | { | ||
2759 | GNUNET_assert (NULL != address->address); /* make static analysis happy */ | ||
2760 | t6 = address->address; | ||
2761 | memset (&a6, 0, sizeof(a6)); | ||
2762 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
2763 | a6.sin6_len = sizeof (a6); | ||
2764 | #endif | ||
2765 | a6.sin6_family = AF_INET6; | ||
2766 | a6.sin6_port = t6->t6_port; | ||
2767 | memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); | ||
2768 | sb = &a6; | ||
2769 | sbs = sizeof(a6); | ||
2770 | } | ||
2771 | else if (addrlen == sizeof(struct IPv4TcpAddress)) | ||
2772 | { | ||
2773 | GNUNET_assert (NULL != address->address); /* make static analysis happy */ | ||
2774 | t4 = address->address; | ||
2775 | memset (&a4, 0, sizeof(a4)); | ||
2776 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
2777 | a4.sin_len = sizeof (a4); | ||
2778 | #endif | ||
2779 | a4.sin_family = AF_INET; | ||
2780 | a4.sin_port = t4->t4_port; | ||
2781 | a4.sin_addr.s_addr = t4->ipv4_addr; | ||
2782 | sb = &a4; | ||
2783 | sbs = sizeof(a4); | ||
2784 | } | ||
2785 | else | ||
2786 | { | ||
2787 | GNUNET_break (0); | ||
2788 | return GNUNET_ATS_NET_UNSPECIFIED; | ||
2789 | } | ||
2790 | return plugin->env->get_address_type (plugin->env->cls, | ||
2791 | sb, | ||
2792 | sbs); | ||
2793 | } | ||
2794 | |||
2795 | |||
2796 | /** | ||
2737 | * Return information about the given session to the | 2797 | * Return information about the given session to the |
2738 | * monitor callback. | 2798 | * monitor callback. |
2739 | * | 2799 | * |
@@ -2991,6 +3051,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2991 | api->address_to_string = &tcp_plugin_address_to_string; | 3051 | api->address_to_string = &tcp_plugin_address_to_string; |
2992 | api->string_to_address = &tcp_plugin_string_to_address; | 3052 | api->string_to_address = &tcp_plugin_string_to_address; |
2993 | api->get_network = &tcp_plugin_get_network; | 3053 | api->get_network = &tcp_plugin_get_network; |
3054 | api->get_network_for_address = &tcp_plugin_get_network_for_address; | ||
2994 | api->update_session_timeout = &tcp_plugin_update_session_timeout; | 3055 | api->update_session_timeout = &tcp_plugin_update_session_timeout; |
2995 | api->update_inbound_delay = &tcp_plugin_update_inbound_delay; | 3056 | api->update_inbound_delay = &tcp_plugin_update_inbound_delay; |
2996 | api->setup_monitor = &tcp_plugin_setup_monitor; | 3057 | api->setup_monitor = &tcp_plugin_setup_monitor; |
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 7c36e172c..ca5166600 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -614,13 +614,73 @@ udp_query_keepalive_factor (void *cls) | |||
614 | * @return the network type | 614 | * @return the network type |
615 | */ | 615 | */ |
616 | static enum GNUNET_ATS_Network_Type | 616 | static enum GNUNET_ATS_Network_Type |
617 | udp_get_network (void *cls, | 617 | udp_plugin_get_network (void *cls, |
618 | struct Session *session) | 618 | struct Session *session) |
619 | { | 619 | { |
620 | return session->scope; | 620 | return session->scope; |
621 | } | 621 | } |
622 | 622 | ||
623 | 623 | ||
624 | /** | ||
625 | * Function obtain the network type for an address. | ||
626 | * | ||
627 | * @param cls closure (`struct Plugin *`) | ||
628 | * @param address the address | ||
629 | * @return the network type | ||
630 | */ | ||
631 | static enum GNUNET_ATS_Network_Type | ||
632 | udp_plugin_get_network_for_address (void *cls, | ||
633 | const struct GNUNET_HELLO_Address *address) | ||
634 | { | ||
635 | struct Plugin *plugin = cls; | ||
636 | size_t addrlen; | ||
637 | struct sockaddr_in a4; | ||
638 | struct sockaddr_in6 a6; | ||
639 | const struct IPv4UdpAddress *u4; | ||
640 | const struct IPv6UdpAddress *u6; | ||
641 | const void *sb; | ||
642 | size_t sbs; | ||
643 | |||
644 | addrlen = address->address_length; | ||
645 | if (addrlen == sizeof(struct IPv6UdpAddress)) | ||
646 | { | ||
647 | GNUNET_assert (NULL != address->address); /* make static analysis happy */ | ||
648 | u6 = address->address; | ||
649 | memset (&a6, 0, sizeof(a6)); | ||
650 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
651 | a6.sin6_len = sizeof (a6); | ||
652 | #endif | ||
653 | a6.sin6_family = AF_INET6; | ||
654 | a6.sin6_port = u6->u6_port; | ||
655 | memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof(struct in6_addr)); | ||
656 | sb = &a6; | ||
657 | sbs = sizeof(a6); | ||
658 | } | ||
659 | else if (addrlen == sizeof(struct IPv4UdpAddress)) | ||
660 | { | ||
661 | GNUNET_assert (NULL != address->address); /* make static analysis happy */ | ||
662 | u4 = address->address; | ||
663 | memset (&a4, 0, sizeof(a4)); | ||
664 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
665 | a4.sin_len = sizeof (a4); | ||
666 | #endif | ||
667 | a4.sin_family = AF_INET; | ||
668 | a4.sin_port = u4->u4_port; | ||
669 | a4.sin_addr.s_addr = u4->ipv4_addr; | ||
670 | sb = &a4; | ||
671 | sbs = sizeof(a4); | ||
672 | } | ||
673 | else | ||
674 | { | ||
675 | GNUNET_break (0); | ||
676 | return GNUNET_ATS_NET_UNSPECIFIED; | ||
677 | } | ||
678 | return plugin->env->get_address_type (plugin->env->cls, | ||
679 | sb, | ||
680 | sbs); | ||
681 | } | ||
682 | |||
683 | |||
624 | /* ******************* Event loop ******************** */ | 684 | /* ******************* Event loop ******************** */ |
625 | 685 | ||
626 | /** | 686 | /** |
@@ -3766,7 +3826,8 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
3766 | api->check_address = &udp_plugin_check_address; | 3826 | api->check_address = &udp_plugin_check_address; |
3767 | api->get_session = &udp_plugin_get_session; | 3827 | api->get_session = &udp_plugin_get_session; |
3768 | api->send = &udp_plugin_send; | 3828 | api->send = &udp_plugin_send; |
3769 | api->get_network = &udp_get_network; | 3829 | api->get_network = &udp_plugin_get_network; |
3830 | api->get_network_for_address = &udp_plugin_get_network_for_address; | ||
3770 | api->update_session_timeout = &udp_plugin_update_session_timeout; | 3831 | api->update_session_timeout = &udp_plugin_update_session_timeout; |
3771 | api->setup_monitor = &udp_plugin_setup_monitor; | 3832 | api->setup_monitor = &udp_plugin_setup_monitor; |
3772 | return api; | 3833 | return api; |
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index a664941e0..c6ac0e508 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c | |||
@@ -805,6 +805,22 @@ unix_plugin_get_network (void *cls, | |||
805 | 805 | ||
806 | 806 | ||
807 | /** | 807 | /** |
808 | * Function obtain the network type for a session | ||
809 | * | ||
810 | * @param cls closure (`struct Plugin *`) | ||
811 | * @param address the address | ||
812 | * @return the network type | ||
813 | */ | ||
814 | static enum GNUNET_ATS_Network_Type | ||
815 | unix_plugin_get_network_for_address (void *cls, | ||
816 | const struct GNUNET_HELLO_Address *address) | ||
817 | |||
818 | { | ||
819 | return GNUNET_ATS_NET_LOOPBACK; | ||
820 | } | ||
821 | |||
822 | |||
823 | /** | ||
808 | * Creates a new outbound session the transport service will use to send data to the | 824 | * Creates a new outbound session the transport service will use to send data to the |
809 | * peer | 825 | * peer |
810 | * | 826 | * |
@@ -1798,6 +1814,7 @@ libgnunet_plugin_transport_unix_init (void *cls) | |||
1798 | api->check_address = &unix_plugin_check_address; | 1814 | api->check_address = &unix_plugin_check_address; |
1799 | api->string_to_address = &unix_plugin_string_to_address; | 1815 | api->string_to_address = &unix_plugin_string_to_address; |
1800 | api->get_network = &unix_plugin_get_network; | 1816 | api->get_network = &unix_plugin_get_network; |
1817 | api->get_network_for_address = &unix_plugin_get_network_for_address; | ||
1801 | api->update_session_timeout = &unix_plugin_update_session_timeout; | 1818 | api->update_session_timeout = &unix_plugin_update_session_timeout; |
1802 | api->setup_monitor = &unix_plugin_setup_monitor; | 1819 | api->setup_monitor = &unix_plugin_setup_monitor; |
1803 | sockets_created = unix_transport_server_start (plugin); | 1820 | sockets_created = unix_transport_server_start (plugin); |
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 52f454560..d5932bb30 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c | |||
@@ -1292,6 +1292,25 @@ wlan_plugin_get_network (void *cls, | |||
1292 | 1292 | ||
1293 | 1293 | ||
1294 | /** | 1294 | /** |
1295 | * Function obtain the network type for an address. | ||
1296 | * | ||
1297 | * @param cls closure (`struct Plugin *`) | ||
1298 | * @param address the address | ||
1299 | * @return the network type | ||
1300 | */ | ||
1301 | static enum GNUNET_ATS_Network_Type | ||
1302 | wlan_plugin_get_network_for_address (void *cls, | ||
1303 | const struct GNUNET_HELLO_Address *address) | ||
1304 | { | ||
1305 | #if BUILD_WLAN | ||
1306 | return GNUNET_ATS_NET_WLAN; | ||
1307 | #else | ||
1308 | return GNUNET_ATS_NET_BT; | ||
1309 | #endif | ||
1310 | } | ||
1311 | |||
1312 | |||
1313 | /** | ||
1295 | * Creates a new outbound session the transport service will use to | 1314 | * Creates a new outbound session the transport service will use to |
1296 | * send data to the peer | 1315 | * send data to the peer |
1297 | * | 1316 | * |
@@ -2332,6 +2351,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
2332 | api->address_to_string = &wlan_plugin_address_to_string; | 2351 | api->address_to_string = &wlan_plugin_address_to_string; |
2333 | api->string_to_address = &wlan_plugin_string_to_address; | 2352 | api->string_to_address = &wlan_plugin_string_to_address; |
2334 | api->get_network = &wlan_plugin_get_network; | 2353 | api->get_network = &wlan_plugin_get_network; |
2354 | api->get_network_for_address = &wlan_plugin_get_network_for_address; | ||
2335 | api->update_session_timeout = &wlan_plugin_update_session_timeout; | 2355 | api->update_session_timeout = &wlan_plugin_update_session_timeout; |
2336 | api->update_inbound_delay = &wlan_plugin_update_inbound_delay; | 2356 | api->update_inbound_delay = &wlan_plugin_update_inbound_delay; |
2337 | api->setup_monitor = &wlan_plugin_setup_monitor; | 2357 | api->setup_monitor = &wlan_plugin_setup_monitor; |