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 | |
parent | 572bab1ace57fb9d7acbd218d6940cb1e9a0797b (diff) |
determine network scope for ATS even if we do not yet have a session and only have an address
-rw-r--r-- | src/ats-tool/gnunet-ats.c | 4 | ||||
-rw-r--r-- | src/ats/ats_api_scheduling.c | 3 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 3 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_performance.c | 3 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_scheduling.c | 1 | ||||
-rw-r--r-- | src/dv/plugin_transport_dv.c | 16 | ||||
-rw-r--r-- | src/include/gnunet_transport_plugin.h | 18 | ||||
-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 |
18 files changed, 333 insertions, 15 deletions
diff --git a/src/ats-tool/gnunet-ats.c b/src/ats-tool/gnunet-ats.c index 7fd8e826bd..9ea603bc17 100644 --- a/src/ats-tool/gnunet-ats.c +++ b/src/ats-tool/gnunet-ats.c @@ -647,7 +647,7 @@ print_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg) GNUNET_ATS_print_network_type (c)); GNUNET_asprintf ("a_out_str, "-"); } - GNUNET_free(entry_out); + GNUNET_free (entry_out); /* quota in */ if (GNUNET_OK == @@ -660,7 +660,7 @@ print_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg) || (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, "a_in))) quota_in = UINT32_MAX; - GNUNET_free(quota_in_str); + GNUNET_free (quota_in_str); GNUNET_asprintf ("a_in_str, "%llu", quota_in); } else diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c index 838de6623c..355a279bac 100644 --- a/src/ats/ats_api_scheduling.c +++ b/src/ats/ats_api_scheduling.c @@ -494,6 +494,7 @@ send_add_address_message (struct GNUNET_ATS_SchedulingHandle *sh, if (NULL == sh->mq) return; /* disconnected, skip for now */ + GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != ar->properties.scope); namelen = strlen (ar->address->transport_name) + 1; msize = ar->address->address_length + namelen; ev = GNUNET_MQ_msg_extra (m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD); @@ -672,6 +673,7 @@ GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh, GNUNET_break (0); return NULL; } + GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope); namelen = strlen (address->transport_name) + 1; msize = address->address_length + namelen; if ((msize + sizeof (struct AddressUpdateMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || @@ -774,6 +776,7 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar, ar->address->transport_name, ar->session, ar->slot); + GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope); GNUNET_ATS_properties_hton (&ar->properties, prop); if (NULL == sh->mq) diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index d587d832b3..aa0e67ff8b 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c @@ -225,6 +225,7 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, GNUNET_break (0); return; } + GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope); new_address = create_address (peer, plugin_name, plugin_addr, @@ -294,7 +295,7 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, "Received ADDRESS_UPDATE for peer `%s' slot %u\n", GNUNET_i2s (peer), (unsigned int) session_id); - + GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope); /* Update address */ aa->t_last_activity = GNUNET_TIME_absolute_get(); aa->properties = *prop; diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c index f0fe1927cb..831afb4186 100644 --- a/src/ats/gnunet-service-ats_performance.c +++ b/src/ats/gnunet-service-ats_performance.c @@ -85,6 +85,7 @@ notify_client (struct GNUNET_SERVER_Client *client, struct GNUNET_SERVER_NotificationContext *nc; char *addrp; + GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope); GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); msg = (struct PeerInformationMessage *) buf; msg->header.size = htons (msize); @@ -159,6 +160,7 @@ GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) { + GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope); notify_client (NULL, peer, plugin_name, @@ -212,6 +214,7 @@ peerinfo_it (void *cls, plugin_name, (unsigned int) ntohl (bandwidth_out.value__), (unsigned int) ntohl (bandwidth_in.value__)); + GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope); notify_client (client, id, plugin_name, diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c index 1bd243aae0..1aa96b861e 100644 --- a/src/ats/gnunet-service-ats_scheduling.c +++ b/src/ats/gnunet-service-ats_scheduling.c @@ -176,6 +176,7 @@ GAS_handle_address_add (void *cls, GNUNET_NO); GNUNET_ATS_properties_ntoh (&prop, &m->properties); + GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop.scope); GAS_addresses_add (&m->peer, plugin_name, address, diff --git a/src/dv/plugin_transport_dv.c b/src/dv/plugin_transport_dv.c index 7d5da645ee..a1565f09a5 100644 --- a/src/dv/plugin_transport_dv.c +++ b/src/dv/plugin_transport_dv.c @@ -860,6 +860,21 @@ dv_get_network (void *cls, /** + * Function obtain the network type for an address. + * + * @param cls closure (`struct Plugin *`) + * @param address the address + * @return the network type + */ +static enum GNUNET_ATS_Network_Type +dv_plugin_get_network_for_address (void *cls, + const struct GNUNET_HELLO_Address *address) +{ + return GNUNET_ATS_NET_WAN; /* FOR NOW */ +} + + +/** * Function that is called to get the keepalive factor. * #GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to * calculate the interval between keepalive packets. @@ -975,6 +990,7 @@ libgnunet_plugin_transport_dv_init (void *cls) api->query_keepalive_factor = &dv_plugin_query_keepalive_factor; api->get_session = &dv_get_session; api->get_network = &dv_get_network; + api->get_network_for_address = &dv_get_network_for_address; api->update_session_timeout = &dv_plugin_update_session_timeout; api->setup_monitor = &dv_plugin_setup_monitor; return api; diff --git a/src/include/gnunet_transport_plugin.h b/src/include/gnunet_transport_plugin.h index 0b0be1fb97..0dc159cb42 100644 --- a/src/include/gnunet_transport_plugin.h +++ b/src/include/gnunet_transport_plugin.h @@ -499,6 +499,7 @@ typedef void struct Session *session, struct GNUNET_TIME_Relative delay); + /** * Function called for a quick conversion of the binary address to * a numeric address. Note that the caller must not free the @@ -549,6 +550,18 @@ typedef enum GNUNET_ATS_Network_Type /** + * Function to obtain the network type for an address. + * + * @param cls closure (`struct Plugin *`) + * @param address the address + * @return the network type + */ +typedef enum GNUNET_ATS_Network_Type +(*GNUNET_TRANSPORT_GetNetworkTypeForAddress) (void *cls, + const struct GNUNET_HELLO_Address *address); + + +/** * Function called by the plugin with information about the * current sessions managed by the plugin (for monitoring). * @@ -680,6 +693,11 @@ struct GNUNET_TRANSPORT_PluginFunctions GNUNET_TRANSPORT_GetNetworkType get_network; /** + * Function to obtain the network type for an address + */ + GNUNET_TRANSPORT_GetNetworkTypeForAddress get_network_for_address; + + /** * Function to monitor the sessions managed by the plugin. */ GNUNET_TRANSPORT_SessionMonitorSetup setup_monitor; diff --git a/src/transport/gnunet-service-transport_ats.c b/src/transport/gnunet-service-transport_ats.c index 74658822ec..5124cd5785 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, GNUNET_HELLO_ADDRESS_INFO_INBOUND)); ai = find_ai_no_session (address); GNUNET_assert (NULL == ai); + GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope); LOG (GNUNET_ERROR_TYPE_INFO, "Notifying ATS about peer `%s''s new address `%s'\n", GNUNET_i2s (&address->peer), diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index 01546ded4d..461d2669a0 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, if ( ( (GNUNET_TRANSPORT_PS_SYN_RECV_ACK != n->state) && (ACK_SEND_ACK != n->ack_state) ) || - (NULL == n->primary_address.address) ) + (NULL == n->primary_address.address) ) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Received unexpected ACK message from peer `%s' in state %s/%s\n", @@ -3850,10 +3850,11 @@ neighbours_iterate (void *cls, * Iterate over all connected neighbours. * * @param cb function to call - * @param cb_cls closure for cb + * @param cb_cls closure for @a cb */ void -GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls) +GST_neighbours_iterate (GST_NeighbourIterator cb, + void *cb_cls) { struct IteratorContext ic; @@ -3930,7 +3931,7 @@ GST_neighbours_start (unsigned int max_fds) * * @param cls unused * @param key hash of neighbour's public key (not used) - * @param value the 'struct NeighbourMapEntry' of the neighbour + * @param value the `struct NeighbourMapEntry` of the neighbour * @return #GNUNET_OK (continue to iterate) */ static int diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index 66f9f5409c..c7d7601995 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) ve->in_use = GNUNET_SYSERR; /* not defined */ ve->address = GNUNET_HELLO_address_copy (address); ve->pong_sig_valid_until = GNUNET_TIME_UNIT_ZERO_ABS; - memset (&ve->pong_sig_cache, '\0', sizeof (struct GNUNET_CRYPTO_EddsaSignature)); + memset (&ve->pong_sig_cache, + '\0', + sizeof (struct GNUNET_CRYPTO_EddsaSignature)); ve->latency = GNUNET_TIME_UNIT_FOREVER_REL; ve->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); @@ -828,6 +830,7 @@ add_valid_address (void *cls, struct ValidationEntry *ve; struct GNUNET_PeerIdentity pid; struct GNUNET_ATS_Properties prop; + struct GNUNET_TRANSPORT_PluginFunctions *papi; if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) return GNUNET_OK; /* expired */ @@ -836,14 +839,26 @@ add_valid_address (void *cls, GNUNET_break (0); return GNUNET_OK; /* invalid HELLO !? */ } - if (NULL == GST_plugins_find (address->transport_name)) + if (NULL == (papi = GST_plugins_find (address->transport_name))) { /* might have been valid in the past, but we don't have that plugin loaded right now */ return GNUNET_OK; } + if (NULL == + papi->address_to_string (papi->cls, + address->address, + address->address_length)) + { + /* Why do we try to add an ill-formed address? */ + GNUNET_break (0); + return GNUNET_OK; + } ve = find_validation_entry (address); + ve->network = papi->get_network_for_address (papi->cls, + address); + GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != ve->network); ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, expiration); if (NULL == ve->revalidation_task) @@ -857,6 +872,7 @@ add_valid_address (void *cls, validation_entry_changed (ve, GNUNET_TRANSPORT_VS_UPDATE); memset (&prop, 0, sizeof (prop)); + GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != ve->network); prop.scope = ve->network; prop.delay = GNUNET_TIME_relative_divide (ve->latency, 2); if (GNUNET_YES != ve->known_to_ats) @@ -1506,6 +1522,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, struct GNUNET_ATS_Properties prop; memset (&prop, 0, sizeof (prop)); + GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != ve->network); prop.scope = ve->network; prop.delay = GNUNET_TIME_relative_divide (ve->latency, 2); GNUNET_assert (GNUNET_NO == diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index de9ad541b2..8066fb384b 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, /** + * Function obtain the network type for an address. + * + * @param cls closure (`struct Plugin *`) + * @param address the address + * @return the network type + */ +static enum GNUNET_ATS_Network_Type +http_client_plugin_get_network_for_address (void *cls, + const struct GNUNET_HELLO_Address *address) +{ + struct HTTP_Client_Plugin *plugin = cls; + + return http_common_get_network_for_address (plugin->env, + address); +} + + +/** * Session was idle, so disconnect it * * @param cls the `struct Session` of the idle session @@ -2469,6 +2487,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) api->string_to_address = &http_common_plugin_string_to_address; api->address_pretty_printer = &http_common_plugin_address_pretty_printer; api->get_network = &http_client_plugin_get_network; + api->get_network_for_address = &http_client_plugin_get_network_for_address; api->update_session_timeout = &http_client_plugin_update_session_timeout; api->update_inbound_delay = &http_client_plugin_update_inbound_delay; 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 77558a49bd..13f01f7131 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) * @return #GNUNET_YES if equal, #GNUNET_NO if not, #GNUNET_SYSERR on error */ size_t -http_common_cmp_addresses (const void *addr1, size_t addrlen1, - const void *addr2, size_t addrlen2) +http_common_cmp_addresses (const void *addr1, + size_t addrlen1, + const void *addr2, + size_t addrlen2) { const char *a1 = addr1; const char *a2 = addr2; @@ -888,4 +890,49 @@ http_common_cmp_addresses (const void *addr1, size_t addrlen1, return GNUNET_NO; } + +/** + * Function obtain the network type for an address. + * + * @param env the environment + * @param address the address + * @return the network type + */ +enum GNUNET_ATS_Network_Type +http_common_get_network_for_address (struct GNUNET_TRANSPORT_PluginEnvironment *env, + const struct GNUNET_HELLO_Address *address) +{ + + struct sockaddr *sa; + enum GNUNET_ATS_Network_Type net_type; + size_t salen = 0; + int res; + + net_type = GNUNET_ATS_NET_UNSPECIFIED; + sa = http_common_socket_from_address (address->address, + address->address_length, + &res); + if (GNUNET_SYSERR == res) + return net_type; + if (GNUNET_YES == res) + { + GNUNET_assert (NULL != sa); + if (AF_INET == sa->sa_family) + { + salen = sizeof (struct sockaddr_in); + } + else if (AF_INET6 == sa->sa_family) + { + salen = sizeof (struct sockaddr_in6); + } + net_type = env->get_address_type (env->cls, + sa, + salen); + GNUNET_free (sa); + } + return net_type; +} + + + /* 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 15466cc9e4..51438d6e67 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, const void *addr2, size_t addrlen2); + +/** + * Function obtain the network type for an address. + * + * @param env the environment + * @param address the address + * @return the network type + */ +enum GNUNET_ATS_Network_Type +http_common_get_network_for_address (struct GNUNET_TRANSPORT_PluginEnvironment *env, + const struct GNUNET_HELLO_Address *address); + + /* 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 0000a604db..db483098ac 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, /** * Function obtain the network type for a session * - * @param cls closure ('struct HTTP_Server_Plugin*') + * @param cls closure (`struct HTTP_Server_Plugin *`) * @param session the session * @return the network type in HBO or #GNUNET_SYSERR */ @@ -3264,6 +3264,24 @@ http_server_plugin_get_network (void *cls, /** + * Function obtain the network type for an address. + * + * @param cls closure (`struct Plugin *`) + * @param address the address + * @return the network type + */ +static enum GNUNET_ATS_Network_Type +http_server_plugin_get_network_for_address (void *cls, + const struct GNUNET_HELLO_Address *address) +{ + struct HTTP_Server_Plugin *plugin = cls; + + return http_common_get_network_for_address (plugin->env, + address); +} + + +/** * Function that will be called whenever the transport service wants to * notify the plugin that the inbound quota changed and that the plugin * should update it's delay for the next receive value @@ -3393,6 +3411,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) api->string_to_address = &http_common_plugin_string_to_address; api->address_pretty_printer = &http_common_plugin_address_pretty_printer; api->get_network = &http_server_plugin_get_network; + api->get_network_for_address = &http_server_plugin_get_network_for_address; api->update_session_timeout = &http_server_plugin_update_session_timeout; api->update_inbound_delay = &http_server_plugin_update_inbound_delay; 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 330b24f61a..453a0095f3 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, /** + * Function obtain the network type for an address. + * + * @param cls closure (`struct Plugin *`) + * @param address the address + * @return the network type + */ +static enum GNUNET_ATS_Network_Type +tcp_plugin_get_network_for_address (void *cls, + const struct GNUNET_HELLO_Address *address) +{ + struct Plugin *plugin = cls; + size_t addrlen; + struct sockaddr_in a4; + struct sockaddr_in6 a6; + const struct IPv4TcpAddress *t4; + const struct IPv6TcpAddress *t6; + const void *sb; + size_t sbs; + + addrlen = address->address_length; + if (addrlen == sizeof(struct IPv6TcpAddress)) + { + GNUNET_assert (NULL != address->address); /* make static analysis happy */ + t6 = address->address; + memset (&a6, 0, sizeof(a6)); +#if HAVE_SOCKADDR_IN_SIN_LEN + a6.sin6_len = sizeof (a6); +#endif + a6.sin6_family = AF_INET6; + a6.sin6_port = t6->t6_port; + memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); + sb = &a6; + sbs = sizeof(a6); + } + else if (addrlen == sizeof(struct IPv4TcpAddress)) + { + GNUNET_assert (NULL != address->address); /* make static analysis happy */ + t4 = address->address; + memset (&a4, 0, sizeof(a4)); +#if HAVE_SOCKADDR_IN_SIN_LEN + a4.sin_len = sizeof (a4); +#endif + a4.sin_family = AF_INET; + a4.sin_port = t4->t4_port; + a4.sin_addr.s_addr = t4->ipv4_addr; + sb = &a4; + sbs = sizeof(a4); + } + else + { + GNUNET_break (0); + return GNUNET_ATS_NET_UNSPECIFIED; + } + return plugin->env->get_address_type (plugin->env->cls, + sb, + sbs); +} + + +/** * Return information about the given session to the * monitor callback. * @@ -2991,6 +3051,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) api->address_to_string = &tcp_plugin_address_to_string; api->string_to_address = &tcp_plugin_string_to_address; api->get_network = &tcp_plugin_get_network; + api->get_network_for_address = &tcp_plugin_get_network_for_address; api->update_session_timeout = &tcp_plugin_update_session_timeout; api->update_inbound_delay = &tcp_plugin_update_inbound_delay; api->setup_monitor = &tcp_plugin_setup_monitor; diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 7c36e172c7..ca51666008 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) * @return the network type */ static enum GNUNET_ATS_Network_Type -udp_get_network (void *cls, - struct Session *session) +udp_plugin_get_network (void *cls, + struct Session *session) { return session->scope; } +/** + * Function obtain the network type for an address. + * + * @param cls closure (`struct Plugin *`) + * @param address the address + * @return the network type + */ +static enum GNUNET_ATS_Network_Type +udp_plugin_get_network_for_address (void *cls, + const struct GNUNET_HELLO_Address *address) +{ + struct Plugin *plugin = cls; + size_t addrlen; + struct sockaddr_in a4; + struct sockaddr_in6 a6; + const struct IPv4UdpAddress *u4; + const struct IPv6UdpAddress *u6; + const void *sb; + size_t sbs; + + addrlen = address->address_length; + if (addrlen == sizeof(struct IPv6UdpAddress)) + { + GNUNET_assert (NULL != address->address); /* make static analysis happy */ + u6 = address->address; + memset (&a6, 0, sizeof(a6)); +#if HAVE_SOCKADDR_IN_SIN_LEN + a6.sin6_len = sizeof (a6); +#endif + a6.sin6_family = AF_INET6; + a6.sin6_port = u6->u6_port; + memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof(struct in6_addr)); + sb = &a6; + sbs = sizeof(a6); + } + else if (addrlen == sizeof(struct IPv4UdpAddress)) + { + GNUNET_assert (NULL != address->address); /* make static analysis happy */ + u4 = address->address; + memset (&a4, 0, sizeof(a4)); +#if HAVE_SOCKADDR_IN_SIN_LEN + a4.sin_len = sizeof (a4); +#endif + a4.sin_family = AF_INET; + a4.sin_port = u4->u4_port; + a4.sin_addr.s_addr = u4->ipv4_addr; + sb = &a4; + sbs = sizeof(a4); + } + else + { + GNUNET_break (0); + return GNUNET_ATS_NET_UNSPECIFIED; + } + return plugin->env->get_address_type (plugin->env->cls, + sb, + sbs); +} + + /* ******************* Event loop ******************** */ /** @@ -3766,7 +3826,8 @@ libgnunet_plugin_transport_udp_init (void *cls) api->check_address = &udp_plugin_check_address; api->get_session = &udp_plugin_get_session; api->send = &udp_plugin_send; - api->get_network = &udp_get_network; + api->get_network = &udp_plugin_get_network; + api->get_network_for_address = &udp_plugin_get_network_for_address; api->update_session_timeout = &udp_plugin_update_session_timeout; api->setup_monitor = &udp_plugin_setup_monitor; return api; diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index a664941e0a..c6ac0e5084 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, /** + * Function obtain the network type for a session + * + * @param cls closure (`struct Plugin *`) + * @param address the address + * @return the network type + */ +static enum GNUNET_ATS_Network_Type +unix_plugin_get_network_for_address (void *cls, + const struct GNUNET_HELLO_Address *address) + +{ + return GNUNET_ATS_NET_LOOPBACK; +} + + +/** * Creates a new outbound session the transport service will use to send data to the * peer * @@ -1798,6 +1814,7 @@ libgnunet_plugin_transport_unix_init (void *cls) api->check_address = &unix_plugin_check_address; api->string_to_address = &unix_plugin_string_to_address; api->get_network = &unix_plugin_get_network; + api->get_network_for_address = &unix_plugin_get_network_for_address; api->update_session_timeout = &unix_plugin_update_session_timeout; api->setup_monitor = &unix_plugin_setup_monitor; sockets_created = unix_transport_server_start (plugin); diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 52f4545603..d5932bb30d 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, /** + * Function obtain the network type for an address. + * + * @param cls closure (`struct Plugin *`) + * @param address the address + * @return the network type + */ +static enum GNUNET_ATS_Network_Type +wlan_plugin_get_network_for_address (void *cls, + const struct GNUNET_HELLO_Address *address) +{ +#if BUILD_WLAN + return GNUNET_ATS_NET_WLAN; +#else + return GNUNET_ATS_NET_BT; +#endif +} + + +/** * Creates a new outbound session the transport service will use to * send data to the peer * @@ -2332,6 +2351,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) api->address_to_string = &wlan_plugin_address_to_string; api->string_to_address = &wlan_plugin_string_to_address; api->get_network = &wlan_plugin_get_network; + api->get_network_for_address = &wlan_plugin_get_network_for_address; api->update_session_timeout = &wlan_plugin_update_session_timeout; api->update_inbound_delay = &wlan_plugin_update_inbound_delay; api->setup_monitor = &wlan_plugin_setup_monitor; |