aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_neighbours.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-07-10 08:24:33 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-07-10 08:24:33 +0000
commitecf423bfc3a95ff966776559a3fd97da6cbd91b8 (patch)
tree256875cdaa630f0b1408246a45931b56b995d5dd /src/transport/gnunet-service-transport_neighbours.c
parente050077cbe2bbd54e53cbfbe81eef7c16d758c7e (diff)
downloadgnunet-ecf423bfc3a95ff966776559a3fd97da6cbd91b8.tar.gz
gnunet-ecf423bfc3a95ff966776559a3fd97da6cbd91b8.zip
code deduplication: move to function
Diffstat (limited to 'src/transport/gnunet-service-transport_neighbours.c')
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c147
1 files changed, 43 insertions, 104 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index d372f5c43..2ee10da47 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -934,6 +934,44 @@ free_address (struct NeighbourAddress *na)
934 934
935 935
936/** 936/**
937 * Notify ATS about the new address including the network this address is
938 * located in.
939 *
940 * @param address the address
941 * @param session the session*
942 */
943static void
944add_address (struct GNUNET_HELLO_Address *address,
945 void *session)
946{
947 struct GNUNET_TRANSPORT_PluginFunctions *papi;
948 struct GNUNET_ATS_Information ats;
949 uint32_t net;
950
951 /* valid new address, let ATS know! */
952 if (NULL == address->transport_name)
953 {
954 GNUNET_break (0);
955 return;
956 }
957 if (NULL == (papi = GST_plugins_find (address->transport_name)))
958 {
959 /* we don't have the plugin for this address */
960 GNUNET_break (0);
961 return;
962 }
963
964 net = papi->get_network (NULL, session);
965 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
966 ats.value = htonl(net);
967// GNUNET_break (0);
968// fprintf (stderr, "NET: %u\n", ntohl(net));
969 GNUNET_ATS_address_add (GST_ats,
970 address, session, &ats, 1);
971}
972
973
974/**
937 * Initialize the 'struct NeighbourAddress'. 975 * Initialize the 'struct NeighbourAddress'.
938 * 976 *
939 * @param na neighbour address to initialize 977 * @param na neighbour address to initialize
@@ -1925,9 +1963,6 @@ handle_test_blacklist_cont (void *cls,
1925{ 1963{
1926 struct BlackListCheckContext *bcc = cls; 1964 struct BlackListCheckContext *bcc = cls;
1927 struct NeighbourMapEntry *n; 1965 struct NeighbourMapEntry *n;
1928 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1929 struct GNUNET_ATS_Information ats;
1930 int net;
1931 1966
1932 bcc->bc = NULL; 1967 bcc->bc = NULL;
1933 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1968 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1991,32 +2026,8 @@ handle_test_blacklist_cont (void *cls,
1991 break; 2026 break;
1992 case S_CONNECT_RECV_BLACKLIST_INBOUND: 2027 case S_CONNECT_RECV_BLACKLIST_INBOUND:
1993 if (GNUNET_OK == result) 2028 if (GNUNET_OK == result)
1994 { 2029 add_address (bcc->na.address, bcc->na.session);
1995 /* valid new address, let ATS know! */ 2030
1996 GNUNET_assert (bcc->na.address->transport_name != NULL);
1997 if (NULL == (papi = GST_plugins_find (bcc->na.address->transport_name)))
1998 {
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 = htonl(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 }
2019 }
2020 n->state = S_CONNECT_RECV_ATS; 2031 n->state = S_CONNECT_RECV_ATS;
2021 n->timeout = GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT); 2032 n->timeout = GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT);
2022 GNUNET_ATS_reset_backoff (GST_ats, peer); 2033 GNUNET_ATS_reset_backoff (GST_ats, peer);
@@ -2777,9 +2788,6 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2777 const struct SessionConnectMessage *scm; 2788 const struct SessionConnectMessage *scm;
2778 struct GNUNET_TIME_Absolute ts; 2789 struct GNUNET_TIME_Absolute ts;
2779 struct NeighbourMapEntry *n; 2790 struct NeighbourMapEntry *n;
2780 struct GNUNET_TRANSPORT_PluginFunctions *papi;
2781 struct GNUNET_ATS_Information ats;
2782 int net;
2783 2791
2784 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2792 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2785 "Received CONNECT_ACK message from peer `%s'\n", 2793 "Received CONNECT_ACK message from peer `%s'\n",
@@ -2827,29 +2835,7 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2827 n->primary_address.bandwidth_in, 2835 n->primary_address.bandwidth_in,
2828 n->primary_address.bandwidth_out); 2836 n->primary_address.bandwidth_out);
2829 /* Tell ATS that the outbound session we created to send CONNECT was successfull */ 2837 /* Tell ATS that the outbound session we created to send CONNECT was successfull */
2830 GNUNET_assert (n->primary_address.address->transport_name != NULL); 2838 add_address (n->primary_address.address, n->primary_address.session);
2831 if (NULL == (papi = GST_plugins_find (n->primary_address.address->transport_name)))
2832 {
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 = htonl(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 }
2853 set_address (&n->primary_address, 2839 set_address (&n->primary_address,
2854 n->primary_address.address, 2840 n->primary_address.address,
2855 n->primary_address.session, 2841 n->primary_address.session,
@@ -2895,30 +2881,7 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2895 n->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 2881 n->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2896 GNUNET_break (GNUNET_NO == n->alternative_address.ats_active); 2882 GNUNET_break (GNUNET_NO == n->alternative_address.ats_active);
2897 2883
2898 GNUNET_assert (n->alternative_address.address->transport_name != NULL); 2884 add_address (n->alternative_address.address, n->alternative_address.session);
2899 if (NULL == (papi = GST_plugins_find (n->alternative_address.address->transport_name)))
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 = htonl(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
2922 set_address (&n->primary_address, 2885 set_address (&n->primary_address,
2923 n->alternative_address.address, 2886 n->alternative_address.address,
2924 n->alternative_address.session, 2887 n->alternative_address.session,
@@ -3126,31 +3089,7 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
3126 n->primary_address.bandwidth_in, 3089 n->primary_address.bandwidth_in,
3127 n->primary_address.bandwidth_out); 3090 n->primary_address.bandwidth_out);
3128 3091
3129 GNUNET_assert (n->primary_address.address->transport_name != NULL); 3092 add_address (n->primary_address.address, n->primary_address.session);
3130 struct GNUNET_TRANSPORT_PluginFunctions *papi;
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 = htonl(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 }
3154 set_address (&n->primary_address, 3093 set_address (&n->primary_address,
3155 n->primary_address.address, 3094 n->primary_address.address,
3156 n->primary_address.session, 3095 n->primary_address.session,