summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-07-10 08:53:22 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-07-10 08:53:22 +0000
commit11fd564b2998cca1e02eb403794ec47fe5859a12 (patch)
tree82c54f644631ed3c933c09b275a83e6fe4149b3e /src
parentecf423bfc3a95ff966776559a3fd97da6cbd91b8 (diff)
downloadgnunet-11fd564b2998cca1e02eb403794ec47fe5859a12.tar.gz
gnunet-11fd564b2998cca1e02eb403794ec47fe5859a12.zip
move add function directly to transport
Diffstat (limited to 'src')
-rw-r--r--src/transport/gnunet-service-transport.c56
-rw-r--r--src/transport/gnunet-service-transport.h20
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c48
3 files changed, 78 insertions, 46 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index 7f39bb3bd..99f72e729 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -393,8 +393,56 @@ plugin_env_address_to_type (void *cls,
393} 393}
394 394
395 395
396/**
397 * Notify ATS about the new address including the network this address is
398 * located in.
399 *
400 * @param address the address
401 * @param session the session
402 */
403void
404GST_ats_add_address (struct GNUNET_HELLO_Address *address,
405 void *session)
406{
407 struct GNUNET_TRANSPORT_PluginFunctions *papi;
408 struct GNUNET_ATS_Information ats;
409 uint32_t net;
410
411 /* valid new address, let ATS know! */
412 if (NULL == address->transport_name)
413 {
414 GNUNET_break (0);
415 return;
416 }
417 if (NULL == (papi = GST_plugins_find (address->transport_name)))
418 {
419 /* we don't have the plugin for this address */
420 GNUNET_break (0);
421 return;
422 }
423
424 net = papi->get_network (NULL, session);
425 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
426 ats.value = htonl(net);
427 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Notifying ATS about new address `%s' in network %s\n",
428 (0 == address->address_length) ? "<inbound>" : GST_plugins_a2s (address),
429 GNUNET_ATS_print_network_type(net));
430 GNUNET_ATS_address_add (GST_ats,
431 address, session, &ats, 1);
432}
433
434
435/**
436 * Notify ATS about property changes to an address
437 *
438 * @param peer the peer
439 * @param address the address
440 * @param session the session
441 * @param ats performance information
442 * @param ats_count number of elements in ats
443 */
396void 444void
397GST_update_ats_metrics (const struct GNUNET_PeerIdentity *peer, 445GST_ats_update_metrics (const struct GNUNET_PeerIdentity *peer,
398 const struct GNUNET_HELLO_Address *address, 446 const struct GNUNET_HELLO_Address *address,
399 struct Session *session, 447 struct Session *session,
400 const struct GNUNET_ATS_Information *ats, 448 const struct GNUNET_ATS_Information *ats,
@@ -446,7 +494,7 @@ plugin_env_update_metrics (void *cls,
446 haddress.address_length = address_len; 494 haddress.address_length = address_len;
447 haddress.transport_name = plugin_name; 495 haddress.transport_name = plugin_name;
448 496
449 GST_update_ats_metrics (peer, &haddress, session, ats, ats_count); 497 GST_ats_update_metrics (peer, &haddress, session, ats, ats_count);
450} 498}
451 499
452static void 500static void
@@ -484,7 +532,9 @@ plugin_env_session_start (void *cls,
484 addr = GNUNET_HELLO_address_allocate (peer, plugin, address, address_len); 532 addr = GNUNET_HELLO_address_allocate (peer, plugin, address, address_len);
485 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding peer `%s' address %s session %p\n", 533 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding peer `%s' address %s session %p\n",
486 GNUNET_i2s (peer), GST_plugins_a2s(addr), session); 534 GNUNET_i2s (peer), GST_plugins_a2s(addr), session);
487 GNUNET_ATS_address_add (GST_ats, addr, session, ats, ats_count); 535 GST_ats_add_address (addr, session);
536 if (0 < ats_count)
537 GST_ats_update_metrics (peer, addr, session, ats, ats_count);
488 GNUNET_free (addr); 538 GNUNET_free (addr);
489} 539}
490 540
diff --git a/src/transport/gnunet-service-transport.h b/src/transport/gnunet-service-transport.h
index 5e3a25031..c53e471f3 100644
--- a/src/transport/gnunet-service-transport.h
+++ b/src/transport/gnunet-service-transport.h
@@ -97,6 +97,26 @@ GST_receive_callback (void *cls,
97 uint16_t sender_address_len); 97 uint16_t sender_address_len);
98 98
99 99
100/**
101 * Notify ATS about the new address including the network this address is
102 * located in.
103 *
104 * @param address the address
105 * @param session the session
106 */
107void
108GST_ats_add_address (struct GNUNET_HELLO_Address *address, void *session);
109
110/**
111 * Notify ATS about property changes to an address
112 *
113 * @param peer the peer
114 * @param address the address
115 * @param session the session
116 * @param ats performance information
117 * @param ats_count number of elements in ats
118 */
119
100void 120void
101GST_update_ats_metrics (const struct GNUNET_PeerIdentity *peer, 121GST_update_ats_metrics (const struct GNUNET_PeerIdentity *peer,
102 const struct GNUNET_HELLO_Address *address, 122 const struct GNUNET_HELLO_Address *address,
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 2ee10da47..269525a55 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -934,44 +934,6 @@ 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/**
975 * Initialize the 'struct NeighbourAddress'. 937 * Initialize the 'struct NeighbourAddress'.
976 * 938 *
977 * @param na neighbour address to initialize 939 * @param na neighbour address to initialize
@@ -1581,7 +1543,7 @@ GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour)
1581 else 1543 else
1582 latency = n->latency.rel_value; 1544 latency = n->latency.rel_value;
1583 ats.value = htonl (latency); 1545 ats.value = htonl (latency);
1584 GST_update_ats_metrics (&n->id, 1546 GST_ats_update_metrics (&n->id,
1585 n->primary_address.address, 1547 n->primary_address.address,
1586 n->primary_address.session, 1548 n->primary_address.session,
1587 &ats, 1); 1549 &ats, 1);
@@ -2026,7 +1988,7 @@ handle_test_blacklist_cont (void *cls,
2026 break; 1988 break;
2027 case S_CONNECT_RECV_BLACKLIST_INBOUND: 1989 case S_CONNECT_RECV_BLACKLIST_INBOUND:
2028 if (GNUNET_OK == result) 1990 if (GNUNET_OK == result)
2029 add_address (bcc->na.address, bcc->na.session); 1991 GST_ats_add_address (bcc->na.address, bcc->na.session);
2030 1992
2031 n->state = S_CONNECT_RECV_ATS; 1993 n->state = S_CONNECT_RECV_ATS;
2032 n->timeout = GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT); 1994 n->timeout = GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT);
@@ -2835,7 +2797,7 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2835 n->primary_address.bandwidth_in, 2797 n->primary_address.bandwidth_in,
2836 n->primary_address.bandwidth_out); 2798 n->primary_address.bandwidth_out);
2837 /* Tell ATS that the outbound session we created to send CONNECT was successfull */ 2799 /* Tell ATS that the outbound session we created to send CONNECT was successfull */
2838 add_address (n->primary_address.address, n->primary_address.session); 2800 GST_ats_add_address (n->primary_address.address, n->primary_address.session);
2839 set_address (&n->primary_address, 2801 set_address (&n->primary_address,
2840 n->primary_address.address, 2802 n->primary_address.address,
2841 n->primary_address.session, 2803 n->primary_address.session,
@@ -2881,7 +2843,7 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2881 n->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 2843 n->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2882 GNUNET_break (GNUNET_NO == n->alternative_address.ats_active); 2844 GNUNET_break (GNUNET_NO == n->alternative_address.ats_active);
2883 2845
2884 add_address (n->alternative_address.address, n->alternative_address.session); 2846 GST_ats_add_address (n->alternative_address.address, n->alternative_address.session);
2885 set_address (&n->primary_address, 2847 set_address (&n->primary_address,
2886 n->alternative_address.address, 2848 n->alternative_address.address,
2887 n->alternative_address.session, 2849 n->alternative_address.session,
@@ -3089,7 +3051,7 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
3089 n->primary_address.bandwidth_in, 3051 n->primary_address.bandwidth_in,
3090 n->primary_address.bandwidth_out); 3052 n->primary_address.bandwidth_out);
3091 3053
3092 add_address (n->primary_address.address, n->primary_address.session); 3054 GST_ats_add_address (n->primary_address.address, n->primary_address.session);
3093 set_address (&n->primary_address, 3055 set_address (&n->primary_address,
3094 n->primary_address.address, 3056 n->primary_address.address,
3095 n->primary_address.session, 3057 n->primary_address.session,