aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-10-07 14:15:38 +0000
committerChristian Grothoff <christian@grothoff.org>2015-10-07 14:15:38 +0000
commite5bd8fb4aa72717b8707a4652f14c0735acb52c4 (patch)
tree08398e22b9408cc24b6b9e6cb360fe04b9eeae05
parent572bab1ace57fb9d7acbd218d6940cb1e9a0797b (diff)
downloadgnunet-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
-rw-r--r--src/ats-tool/gnunet-ats.c4
-rw-r--r--src/ats/ats_api_scheduling.c3
-rw-r--r--src/ats/gnunet-service-ats_addresses.c3
-rw-r--r--src/ats/gnunet-service-ats_performance.c3
-rw-r--r--src/ats/gnunet-service-ats_scheduling.c1
-rw-r--r--src/dv/plugin_transport_dv.c16
-rw-r--r--src/include/gnunet_transport_plugin.h18
-rw-r--r--src/transport/gnunet-service-transport_ats.c1
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c9
-rw-r--r--src/transport/gnunet-service-transport_validation.c21
-rw-r--r--src/transport/plugin_transport_http_client.c19
-rw-r--r--src/transport/plugin_transport_http_common.c51
-rw-r--r--src/transport/plugin_transport_http_common.h13
-rw-r--r--src/transport/plugin_transport_http_server.c21
-rw-r--r--src/transport/plugin_transport_tcp.c61
-rw-r--r--src/transport/plugin_transport_udp.c67
-rw-r--r--src/transport/plugin_transport_unix.c17
-rw-r--r--src/transport/plugin_transport_wlan.c20
18 files changed, 333 insertions, 15 deletions
diff --git a/src/ats-tool/gnunet-ats.c b/src/ats-tool/gnunet-ats.c
index 7fd8e826b..9ea603bc1 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)
647 GNUNET_ATS_print_network_type (c)); 647 GNUNET_ATS_print_network_type (c));
648 GNUNET_asprintf (&quota_out_str, "-"); 648 GNUNET_asprintf (&quota_out_str, "-");
649 } 649 }
650 GNUNET_free(entry_out); 650 GNUNET_free (entry_out);
651 651
652 /* quota in */ 652 /* quota in */
653 if (GNUNET_OK == 653 if (GNUNET_OK ==
@@ -660,7 +660,7 @@ print_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg)
660 || (GNUNET_SYSERR == 660 || (GNUNET_SYSERR ==
661 GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &quota_in))) 661 GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &quota_in)))
662 quota_in = UINT32_MAX; 662 quota_in = UINT32_MAX;
663 GNUNET_free(quota_in_str); 663 GNUNET_free (quota_in_str);
664 GNUNET_asprintf (&quota_in_str, "%llu", quota_in); 664 GNUNET_asprintf (&quota_in_str, "%llu", quota_in);
665 } 665 }
666 else 666 else
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c
index 838de6623..355a279ba 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,
494 494
495 if (NULL == sh->mq) 495 if (NULL == sh->mq)
496 return; /* disconnected, skip for now */ 496 return; /* disconnected, skip for now */
497 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != ar->properties.scope);
497 namelen = strlen (ar->address->transport_name) + 1; 498 namelen = strlen (ar->address->transport_name) + 1;
498 msize = ar->address->address_length + namelen; 499 msize = ar->address->address_length + namelen;
499 ev = GNUNET_MQ_msg_extra (m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD); 500 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,
672 GNUNET_break (0); 673 GNUNET_break (0);
673 return NULL; 674 return NULL;
674 } 675 }
676 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope);
675 namelen = strlen (address->transport_name) + 1; 677 namelen = strlen (address->transport_name) + 1;
676 msize = address->address_length + namelen; 678 msize = address->address_length + namelen;
677 if ((msize + sizeof (struct AddressUpdateMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 679 if ((msize + sizeof (struct AddressUpdateMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
@@ -774,6 +776,7 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar,
774 ar->address->transport_name, 776 ar->address->transport_name,
775 ar->session, 777 ar->session,
776 ar->slot); 778 ar->slot);
779 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope);
777 GNUNET_ATS_properties_hton (&ar->properties, 780 GNUNET_ATS_properties_hton (&ar->properties,
778 prop); 781 prop);
779 if (NULL == sh->mq) 782 if (NULL == sh->mq)
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c
index d587d832b..aa0e67ff8 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,
225 GNUNET_break (0); 225 GNUNET_break (0);
226 return; 226 return;
227 } 227 }
228 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope);
228 new_address = create_address (peer, 229 new_address = create_address (peer,
229 plugin_name, 230 plugin_name,
230 plugin_addr, 231 plugin_addr,
@@ -294,7 +295,7 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
294 "Received ADDRESS_UPDATE for peer `%s' slot %u\n", 295 "Received ADDRESS_UPDATE for peer `%s' slot %u\n",
295 GNUNET_i2s (peer), 296 GNUNET_i2s (peer),
296 (unsigned int) session_id); 297 (unsigned int) session_id);
297 298 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope);
298 /* Update address */ 299 /* Update address */
299 aa->t_last_activity = GNUNET_TIME_absolute_get(); 300 aa->t_last_activity = GNUNET_TIME_absolute_get();
300 aa->properties = *prop; 301 aa->properties = *prop;
diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c
index f0fe1927c..831afb418 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,
85 struct GNUNET_SERVER_NotificationContext *nc; 85 struct GNUNET_SERVER_NotificationContext *nc;
86 char *addrp; 86 char *addrp;
87 87
88 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope);
88 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); 89 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
89 msg = (struct PeerInformationMessage *) buf; 90 msg = (struct PeerInformationMessage *) buf;
90 msg->header.size = htons (msize); 91 msg->header.size = htons (msize);
@@ -159,6 +160,7 @@ GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer,
159 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 160 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
160 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 161 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
161{ 162{
163 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope);
162 notify_client (NULL, 164 notify_client (NULL,
163 peer, 165 peer,
164 plugin_name, 166 plugin_name,
@@ -212,6 +214,7 @@ peerinfo_it (void *cls,
212 plugin_name, 214 plugin_name,
213 (unsigned int) ntohl (bandwidth_out.value__), 215 (unsigned int) ntohl (bandwidth_out.value__),
214 (unsigned int) ntohl (bandwidth_in.value__)); 216 (unsigned int) ntohl (bandwidth_in.value__));
217 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope);
215 notify_client (client, 218 notify_client (client,
216 id, 219 id,
217 plugin_name, 220 plugin_name,
diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c
index 1bd243aae..1aa96b861 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,
176 GNUNET_NO); 176 GNUNET_NO);
177 GNUNET_ATS_properties_ntoh (&prop, 177 GNUNET_ATS_properties_ntoh (&prop,
178 &m->properties); 178 &m->properties);
179 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop.scope);
179 GAS_addresses_add (&m->peer, 180 GAS_addresses_add (&m->peer,
180 plugin_name, 181 plugin_name,
181 address, 182 address,
diff --git a/src/dv/plugin_transport_dv.c b/src/dv/plugin_transport_dv.c
index 7d5da645e..a1565f09a 100644
--- a/src/dv/plugin_transport_dv.c
+++ b/src/dv/plugin_transport_dv.c
@@ -860,6 +860,21 @@ dv_get_network (void *cls,
860 860
861 861
862/** 862/**
863 * Function obtain the network type for an address.
864 *
865 * @param cls closure (`struct Plugin *`)
866 * @param address the address
867 * @return the network type
868 */
869static enum GNUNET_ATS_Network_Type
870dv_plugin_get_network_for_address (void *cls,
871 const struct GNUNET_HELLO_Address *address)
872{
873 return GNUNET_ATS_NET_WAN; /* FOR NOW */
874}
875
876
877/**
863 * Function that is called to get the keepalive factor. 878 * Function that is called to get the keepalive factor.
864 * #GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to 879 * #GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to
865 * calculate the interval between keepalive packets. 880 * calculate the interval between keepalive packets.
@@ -975,6 +990,7 @@ libgnunet_plugin_transport_dv_init (void *cls)
975 api->query_keepalive_factor = &dv_plugin_query_keepalive_factor; 990 api->query_keepalive_factor = &dv_plugin_query_keepalive_factor;
976 api->get_session = &dv_get_session; 991 api->get_session = &dv_get_session;
977 api->get_network = &dv_get_network; 992 api->get_network = &dv_get_network;
993 api->get_network_for_address = &dv_get_network_for_address;
978 api->update_session_timeout = &dv_plugin_update_session_timeout; 994 api->update_session_timeout = &dv_plugin_update_session_timeout;
979 api->setup_monitor = &dv_plugin_setup_monitor; 995 api->setup_monitor = &dv_plugin_setup_monitor;
980 return api; 996 return api;
diff --git a/src/include/gnunet_transport_plugin.h b/src/include/gnunet_transport_plugin.h
index 0b0be1fb9..0dc159cb4 100644
--- a/src/include/gnunet_transport_plugin.h
+++ b/src/include/gnunet_transport_plugin.h
@@ -499,6 +499,7 @@ typedef void
499 struct Session *session, 499 struct Session *session,
500 struct GNUNET_TIME_Relative delay); 500 struct GNUNET_TIME_Relative delay);
501 501
502
502/** 503/**
503 * Function called for a quick conversion of the binary address to 504 * Function called for a quick conversion of the binary address to
504 * a numeric address. Note that the caller must not free the 505 * a numeric address. Note that the caller must not free the
@@ -549,6 +550,18 @@ typedef enum GNUNET_ATS_Network_Type
549 550
550 551
551/** 552/**
553 * Function to obtain the network type for an address.
554 *
555 * @param cls closure (`struct Plugin *`)
556 * @param address the address
557 * @return the network type
558 */
559typedef enum GNUNET_ATS_Network_Type
560(*GNUNET_TRANSPORT_GetNetworkTypeForAddress) (void *cls,
561 const struct GNUNET_HELLO_Address *address);
562
563
564/**
552 * Function called by the plugin with information about the 565 * Function called by the plugin with information about the
553 * current sessions managed by the plugin (for monitoring). 566 * current sessions managed by the plugin (for monitoring).
554 * 567 *
@@ -680,6 +693,11 @@ struct GNUNET_TRANSPORT_PluginFunctions
680 GNUNET_TRANSPORT_GetNetworkType get_network; 693 GNUNET_TRANSPORT_GetNetworkType get_network;
681 694
682 /** 695 /**
696 * Function to obtain the network type for an address
697 */
698 GNUNET_TRANSPORT_GetNetworkTypeForAddress get_network_for_address;
699
700 /**
683 * Function to monitor the sessions managed by the plugin. 701 * Function to monitor the sessions managed by the plugin.
684 */ 702 */
685 GNUNET_TRANSPORT_SessionMonitorSetup setup_monitor; 703 GNUNET_TRANSPORT_SessionMonitorSetup setup_monitor;
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 */
3855void 3855void
3856GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls) 3856GST_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 */
3936static int 3937static 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 */
1951static enum GNUNET_ATS_Network_Type
1952http_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 */
856size_t 856size_t
857http_common_cmp_addresses (const void *addr1, size_t addrlen1, 857http_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 */
901enum GNUNET_ATS_Network_Type
902http_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 */
258enum GNUNET_ATS_Network_Type
259http_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 */
3273static enum GNUNET_ATS_Network_Type
3274http_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 */
2743static enum GNUNET_ATS_Network_Type
2744tcp_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 */
616static enum GNUNET_ATS_Network_Type 616static enum GNUNET_ATS_Network_Type
617udp_get_network (void *cls, 617udp_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 */
631static enum GNUNET_ATS_Network_Type
632udp_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 */
814static enum GNUNET_ATS_Network_Type
815unix_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 */
1301static enum GNUNET_ATS_Network_Type
1302wlan_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;