aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-07-09 15:23:13 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-07-09 15:23:13 +0000
commitdc330efac154fab36391d376265ffe07460b9cfd (patch)
treee9a94f7ed577e926d2e1d5c0a5bfbfd725bf03a5
parentd09bb1a4e9fb25c31bf9058c7d61ccf3e376da85 (diff)
downloadgnunet-dc330efac154fab36391d376265ffe07460b9cfd.tar.gz
gnunet-dc330efac154fab36391d376265ffe07460b9cfd.zip
new api function to get network for session
-rw-r--r--src/include/gnunet_transport_plugin.h17
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c119
-rw-r--r--src/transport/plugin_transport_tcp.c48
3 files changed, 157 insertions, 27 deletions
diff --git a/src/include/gnunet_transport_plugin.h b/src/include/gnunet_transport_plugin.h
index 603b6ee4f..025b3f8ad 100644
--- a/src/include/gnunet_transport_plugin.h
+++ b/src/include/gnunet_transport_plugin.h
@@ -494,6 +494,17 @@ typedef int (*GNUNET_TRANSPORT_StringToAddress) (void *cls,
494 494
495 495
496/** 496/**
497 * Function obtain the network type for a session
498 *
499 * @param cls closure ('struct Plugin*')
500 * @param session the session
501 * @return the network type in HBO or GNUNET_SYSERR
502 */
503typedef int (*GNUNET_TRANSPORT_GetNetworkType) (void *cls,
504 void *session);
505
506
507/**
497 * Each plugin is required to return a pointer to a struct of this 508 * Each plugin is required to return a pointer to a struct of this
498 * type as the return value from its entry point. 509 * type as the return value from its entry point.
499 */ 510 */
@@ -556,6 +567,12 @@ struct GNUNET_TRANSPORT_PluginFunctions
556 * object 567 * object
557 */ 568 */
558 GNUNET_TRANSPORT_CreateSession get_session; 569 GNUNET_TRANSPORT_CreateSession get_session;
570
571
572 /**
573 * Function to obtain the network type for a session
574 */
575 GNUNET_TRANSPORT_GetNetworkType get_network;
559}; 576};
560 577
561 578
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 32a0706dc..4cc75790e 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -1925,6 +1925,9 @@ handle_test_blacklist_cont (void *cls,
1925{ 1925{
1926 struct BlackListCheckContext *bcc = cls; 1926 struct BlackListCheckContext *bcc = cls;
1927 struct NeighbourMapEntry *n; 1927 struct NeighbourMapEntry *n;
1928 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1929 struct GNUNET_ATS_Information ats;
1930 int net;
1928 1931
1929 bcc->bc = NULL; 1932 bcc->bc = NULL;
1930 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1933 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1990,10 +1993,29 @@ handle_test_blacklist_cont (void *cls,
1990 if (GNUNET_OK == result) 1993 if (GNUNET_OK == result)
1991 { 1994 {
1992 /* valid new address, let ATS know! */ 1995 /* valid new address, let ATS know! */
1993 GNUNET_ATS_address_add (GST_ats, 1996 GNUNET_assert (bcc->na.address->transport_name != NULL);
1994 bcc->na.address, 1997 if (NULL == (papi = GST_plugins_find (bcc->na.address->transport_name)))
1995 bcc->na.session, 1998 {
1996 NULL, 0); 1999 /* we don't have the plugin for this address */
2000 GNUNET_break (0);
2001 }
2002 else
2003 {
2004 if (NULL != papi->get_network)
2005 {
2006 net = papi->get_network (NULL, bcc->na.session);
2007 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
2008 ats.value = net;
2009// GNUNET_break (0);
2010// fprintf (stderr, "NET: %u\n", ntohl(net));
2011 GNUNET_ATS_address_add (GST_ats,
2012 bcc->na.address,
2013 bcc->na.session,
2014 &ats, 1);
2015 }
2016 else
2017 GNUNET_break (0);
2018 }
1997 } 2019 }
1998 n->state = S_CONNECT_RECV_ATS; 2020 n->state = S_CONNECT_RECV_ATS;
1999 n->timeout = GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT); 2021 n->timeout = GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT);
@@ -2755,6 +2777,9 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2755 const struct SessionConnectMessage *scm; 2777 const struct SessionConnectMessage *scm;
2756 struct GNUNET_TIME_Absolute ts; 2778 struct GNUNET_TIME_Absolute ts;
2757 struct NeighbourMapEntry *n; 2779 struct NeighbourMapEntry *n;
2780 struct GNUNET_TRANSPORT_PluginFunctions *papi;
2781 struct GNUNET_ATS_Information ats;
2782 int net;
2758 2783
2759 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2784 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2760 "Received CONNECT_ACK message from peer `%s'\n", 2785 "Received CONNECT_ACK message from peer `%s'\n",
@@ -2802,10 +2827,29 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2802 n->primary_address.bandwidth_in, 2827 n->primary_address.bandwidth_in,
2803 n->primary_address.bandwidth_out); 2828 n->primary_address.bandwidth_out);
2804 /* Tell ATS that the outbound session we created to send CONNECT was successfull */ 2829 /* Tell ATS that the outbound session we created to send CONNECT was successfull */
2805 GNUNET_ATS_address_add (GST_ats, 2830 GNUNET_assert (n->primary_address.address->transport_name != NULL);
2806 n->primary_address.address, 2831 if (NULL == (papi = GST_plugins_find (n->primary_address.address->transport_name)))
2807 n->primary_address.session, 2832 {
2808 NULL, 0); 2833 /* we don't have the plugin for this address */
2834 GNUNET_break (0);
2835 }
2836 else
2837 {
2838 if (NULL != papi->get_network)
2839 {
2840 net = papi->get_network (NULL, n->primary_address.session);
2841 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
2842 ats.value = net;
2843// GNUNET_break (0);
2844// fprintf (stderr, "NET: %u\n", ntohl(net));
2845 GNUNET_ATS_address_add (GST_ats,
2846 n->primary_address.address,
2847 n->primary_address.session,
2848 &ats, 1);
2849 }
2850 else
2851 GNUNET_break (0);
2852 }
2809 set_address (&n->primary_address, 2853 set_address (&n->primary_address,
2810 n->primary_address.address, 2854 n->primary_address.address,
2811 n->primary_address.session, 2855 n->primary_address.session,
@@ -2850,10 +2894,31 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2850 n->state = S_CONNECTED; 2894 n->state = S_CONNECTED;
2851 n->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 2895 n->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2852 GNUNET_break (GNUNET_NO == n->alternative_address.ats_active); 2896 GNUNET_break (GNUNET_NO == n->alternative_address.ats_active);
2853 GNUNET_ATS_address_add(GST_ats, 2897
2854 n->alternative_address.address, 2898 GNUNET_assert (n->alternative_address.address->transport_name != NULL);
2855 n->alternative_address.session, 2899 if (NULL == (papi = GST_plugins_find (n->alternative_address.address->transport_name)))
2856 NULL, 0); 2900 {
2901 /* we don't have the plugin for this address */
2902 GNUNET_break (0);
2903 }
2904 else
2905 {
2906 if (NULL != papi->get_network)
2907 {
2908 net = papi->get_network (NULL, n->alternative_address.session);
2909 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
2910 ats.value = net;
2911// GNUNET_break (0);
2912// fprintf (stderr, "NET: %u\n", ntohl(net));
2913 GNUNET_ATS_address_add (GST_ats,
2914 n->alternative_address.address,
2915 n->alternative_address.session,
2916 &ats, 1);
2917 }
2918 else
2919 GNUNET_break (0);
2920 }
2921
2857 set_address (&n->primary_address, 2922 set_address (&n->primary_address,
2858 n->alternative_address.address, 2923 n->alternative_address.address,
2859 n->alternative_address.session, 2924 n->alternative_address.session,
@@ -3060,10 +3125,32 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
3060 connect_notify_cb (callback_cls, &n->id, 3125 connect_notify_cb (callback_cls, &n->id,
3061 n->primary_address.bandwidth_in, 3126 n->primary_address.bandwidth_in,
3062 n->primary_address.bandwidth_out); 3127 n->primary_address.bandwidth_out);
3063 GNUNET_ATS_address_add(GST_ats, 3128
3064 n->primary_address.address, 3129 GNUNET_assert (n->primary_address.address->transport_name != NULL);
3065 n->primary_address.session, 3130 struct GNUNET_TRANSPORT_PluginFunctions *papi;
3066 NULL, 0); 3131 if (NULL == (papi = GST_plugins_find (n->primary_address.address->transport_name)))
3132 {
3133 /* we don't have the plugin for this address */
3134 GNUNET_break (0);
3135 }
3136 else
3137 {
3138 if (NULL != papi->get_network)
3139 {
3140 int net = papi->get_network (NULL, n->primary_address.session);
3141 struct GNUNET_ATS_Information ats;
3142 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
3143 ats.value = net;
3144// GNUNET_break (0);
3145// fprintf (stderr, "NET: %u\n", ntohl(net));
3146 GNUNET_ATS_address_add (GST_ats,
3147 n->primary_address.address,
3148 n->primary_address.session,
3149 &ats, 1);
3150 }
3151 else
3152 GNUNET_break (0);
3153 }
3067 set_address (&n->primary_address, 3154 set_address (&n->primary_address,
3068 n->primary_address.address, 3155 n->primary_address.address,
3069 n->primary_address.session, 3156 n->primary_address.session,
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index 24ff2166d..f377392c6 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -1938,6 +1938,7 @@ handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client,
1938 struct IPv6TcpAddress *t6; 1938 struct IPv6TcpAddress *t6;
1939 const struct sockaddr_in *s4; 1939 const struct sockaddr_in *s4;
1940 const struct sockaddr_in6 *s6; 1940 const struct sockaddr_in6 *s6;
1941 struct GNUNET_ATS_Information ats;
1941 1942
1942 if (0 == 1943 if (0 ==
1943 memcmp (&wm->clientIdentity, plugin->env->my_identity, 1944 memcmp (&wm->clientIdentity, plugin->env->my_identity,
@@ -1945,11 +1946,12 @@ handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client,
1945 { 1946 {
1946 /* refuse connections from ourselves */ 1947 /* refuse connections from ourselves */
1947 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1948 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1949 GNUNET_break (0);
1948 return; 1950 return;
1949 } 1951 }
1950 LOG (GNUNET_ERROR_TYPE_DEBUG, 1952 LOG (GNUNET_ERROR_TYPE_DEBUG,
1951 "Received %s message from `%4s'\n", "WELCOME", 1953 "Received %s message from `%4s' %p\n", "WELCOME",
1952 GNUNET_i2s (&wm->clientIdentity)); 1954 GNUNET_i2s (&wm->clientIdentity), client);
1953 GNUNET_STATISTICS_update (plugin->env->stats, 1955 GNUNET_STATISTICS_update (plugin->env->stats,
1954 gettext_noop ("# TCP WELCOME messages received"), 1, 1956 gettext_noop ("# TCP WELCOME messages received"), 1,
1955 GNUNET_NO); 1957 GNUNET_NO);
@@ -1958,7 +1960,7 @@ handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client,
1958 { 1960 {
1959 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) 1961 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
1960 { 1962 {
1961 LOG (GNUNET_ERROR_TYPE_DEBUG, 1963 LOG (GNUNET_ERROR_TYPE_DEBUG,
1962 "Found existing session %p for peer `%s'\n", 1964 "Found existing session %p for peer `%s'\n",
1963 session, 1965 session,
1964 GNUNET_a2s (vaddr, alen)); 1966 GNUNET_a2s (vaddr, alen));
@@ -1998,34 +2000,43 @@ handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client,
1998 session->addrlen = sizeof (struct IPv6TcpAddress); 2000 session->addrlen = sizeof (struct IPv6TcpAddress);
1999 } 2001 }
2000 2002
2001 struct GNUNET_ATS_Information ats;
2002 ats = plugin->env->get_address_type (plugin->env->cls, vaddr ,alen); 2003 ats = plugin->env->get_address_type (plugin->env->cls, vaddr ,alen);
2003 session->ats_address_network_type = ats.value; 2004 session->ats_address_network_type = ats.value;
2004 2005 LOG (GNUNET_ERROR_TYPE_DEBUG,
2006 "Creating new session %p for peer `%s'\n",
2007 session,
2008 GNUNET_a2s (vaddr, alen));
2005 GNUNET_free (vaddr); 2009 GNUNET_free (vaddr);
2010 GNUNET_CONTAINER_multihashmap_put (plugin->sessionmap,
2011 &session->target.hashPubKey,
2012 session,
2013 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2014 inc_sessions (plugin, session, __LINE__);
2006 } 2015 }
2007 else 2016 else
2008 { 2017 {
2009 LOG (GNUNET_ERROR_TYPE_DEBUG, 2018 LOG (GNUNET_ERROR_TYPE_DEBUG,
2010 "Did not obtain TCP socket address for incoming connection\n"); 2019 "Did not obtain TCP socket address for incoming connection\n");
2020 GNUNET_break (0);
2011 } 2021 }
2012 GNUNET_CONTAINER_multihashmap_put (plugin->sessionmap,
2013 &session->target.hashPubKey,
2014 session,
2015 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2016 inc_sessions (plugin, session, __LINE__);
2017 } 2022 }
2018 2023
2019 if (session->expecting_welcome != GNUNET_YES) 2024 if (session->expecting_welcome != GNUNET_YES)
2020 { 2025 {
2021 GNUNET_break_op (0); 2026 GNUNET_break_op (0);
2022 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 2027 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2028 GNUNET_break (0);
2023 return; 2029 return;
2024 } 2030 }
2025 session->last_activity = GNUNET_TIME_absolute_get (); 2031 session->last_activity = GNUNET_TIME_absolute_get ();
2026 session->expecting_welcome = GNUNET_NO; 2032 session->expecting_welcome = GNUNET_NO;
2027 2033
2028 2034
2035 /* Notify transport and ATS about new session */
2036 plugin->env->session_start (NULL, &wm->clientIdentity,
2037 PLUGIN_NAME, session->addr, session->addrlen, session, &ats, 1);
2038
2039
2029 process_pending_messages (session); 2040 process_pending_messages (session);
2030 2041
2031 GNUNET_SERVER_client_set_timeout (client, 2042 GNUNET_SERVER_client_set_timeout (client,
@@ -2368,6 +2379,20 @@ stop_session_timeout (struct Session *s)
2368 } 2379 }
2369} 2380}
2370 2381
2382/**
2383 * Function obtain the network type for a session
2384 *
2385 * @param cls closure ('struct Plugin*')
2386 * @param session the session
2387 * @return the network type in HBO or GNUNET_SYSERR
2388 */
2389int tcp_get_network (void *cls,
2390 void *session)
2391{
2392 struct Session *s = (struct Session *) session;
2393 return s->ats_address_network_type;
2394}
2395
2371 2396
2372/** 2397/**
2373 * Entry point for the plugin. 2398 * Entry point for the plugin.
@@ -2502,6 +2527,7 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2502 api->check_address = &tcp_plugin_check_address; 2527 api->check_address = &tcp_plugin_check_address;
2503 api->address_to_string = &tcp_address_to_string; 2528 api->address_to_string = &tcp_address_to_string;
2504 api->string_to_address = &tcp_string_to_address; 2529 api->string_to_address = &tcp_string_to_address;
2530 api->get_network = &tcp_get_network;
2505 plugin->service = service; 2531 plugin->service = service;
2506 if (service != NULL) 2532 if (service != NULL)
2507 { 2533 {