aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_plugins.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-service-transport_plugins.c')
-rw-r--r--src/transport/gnunet-service-transport_plugins.c57
1 files changed, 51 insertions, 6 deletions
diff --git a/src/transport/gnunet-service-transport_plugins.c b/src/transport/gnunet-service-transport_plugins.c
index 79f7f4ddd..1571cee71 100644
--- a/src/transport/gnunet-service-transport_plugins.c
+++ b/src/transport/gnunet-service-transport_plugins.c
@@ -26,6 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet-service-transport.h" 27#include "gnunet-service-transport.h"
28#include "gnunet-service-transport_hello.h" 28#include "gnunet-service-transport_hello.h"
29#include "gnunet-service-transport_ats.h"
29#include "gnunet-service-transport_plugins.h" 30#include "gnunet-service-transport_plugins.h"
30 31
31/** 32/**
@@ -79,6 +80,53 @@ static struct TransportPlugin *plugins_tail;
79 80
80 81
81/** 82/**
83 * Function that will be called to update metrics for an address
84 *
85 * @param cls closure
86 * @param address address to update metrics for
87 * @param session the session
88 * @param ats the ats information to update
89 * @param ats_count the number of @a ats elements
90 */
91static void
92plugin_env_update_metrics (void *cls,
93 const struct GNUNET_HELLO_Address *address,
94 struct Session *session,
95 const struct GNUNET_ATS_Information *ats,
96 uint32_t ats_count)
97{
98 GST_ats_update_metrics (address,
99 session,
100 ats, ats_count);
101}
102
103
104/**
105 * Function that will be called to figure if an address is an loopback,
106 * LAN, WAN etc. address
107 *
108 * @param cls closure
109 * @param addr binary address
110 * @param addrlen length of the @a addr
111 * @return type of the network @a addr belongs to
112 */
113static enum GNUNET_ATS_Network_Type
114plugin_env_address_to_type (void *cls,
115 const struct sockaddr *addr,
116 size_t addrlen)
117{
118 if (NULL == GST_is)
119 {
120 GNUNET_break(0);
121 return GNUNET_ATS_NET_UNSPECIFIED;
122 }
123 return GNUNET_ATS_scanner_address_get_type (GST_is,
124 addr,
125 addrlen);
126}
127
128
129/**
82 * Load and initialize all plugins. The respective functions will be 130 * Load and initialize all plugins. The respective functions will be
83 * invoked by the plugins when the respective events happen. The 131 * invoked by the plugins when the respective events happen. The
84 * closure will be set to a 'const char*' containing the name of the 132 * closure will be set to a 'const char*' containing the name of the
@@ -89,15 +137,12 @@ static struct TransportPlugin *plugins_tail;
89 * @param session_start_cb function to call when a session was created 137 * @param session_start_cb function to call when a session was created
90 * @param session_end_cb function to call when a session was terminated 138 * @param session_end_cb function to call when a session was terminated
91 * @param address_type_cb function to call when a address type is requested 139 * @param address_type_cb function to call when a address type is requested
92 * @param metric_update_cb function to call when address metrics change
93 */ 140 */
94void 141void
95GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, 142GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
96 GNUNET_TRANSPORT_AddressNotification address_cb, 143 GNUNET_TRANSPORT_AddressNotification address_cb,
97 GNUNET_TRANSPORT_SessionStart session_start_cb, 144 GNUNET_TRANSPORT_SessionStart session_start_cb,
98 GNUNET_TRANSPORT_SessionEnd session_end_cb, 145 GNUNET_TRANSPORT_SessionEnd session_end_cb)
99 GNUNET_TRANSPORT_AddressToType address_type_cb,
100 GNUNET_TRANSPORT_UpdateAddressMetrics metric_update_cb)
101{ 146{
102 struct TransportPlugin *plug; 147 struct TransportPlugin *plug;
103 struct TransportPlugin *next; 148 struct TransportPlugin *next;
@@ -145,8 +190,8 @@ GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
145 plug->env.notify_address = address_cb; 190 plug->env.notify_address = address_cb;
146 plug->env.session_start = session_start_cb; 191 plug->env.session_start = session_start_cb;
147 plug->env.session_end = session_end_cb; 192 plug->env.session_end = session_end_cb;
148 plug->env.get_address_type = address_type_cb; 193 plug->env.get_address_type = &plugin_env_address_to_type;
149 plug->env.update_address_metrics = metric_update_cb; 194 plug->env.update_address_metrics = &plugin_env_update_metrics;
150 plug->env.max_connections = tneigh; 195 plug->env.max_connections = tneigh;
151 plug->env.stats = GST_stats; 196 plug->env.stats = GST_stats;
152 GNUNET_CONTAINER_DLL_insert (plugins_head, 197 GNUNET_CONTAINER_DLL_insert (plugins_head,