summaryrefslogtreecommitdiff
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.c447
1 files changed, 224 insertions, 223 deletions
diff --git a/src/transport/gnunet-service-transport_plugins.c b/src/transport/gnunet-service-transport_plugins.c
index b9203f9f4..d0a10cbc7 100644
--- a/src/transport/gnunet-service-transport_plugins.c
+++ b/src/transport/gnunet-service-transport_plugins.c
@@ -32,7 +32,8 @@
32/** 32/**
33 * Entry in doubly-linked list of all of our plugins. 33 * Entry in doubly-linked list of all of our plugins.
34 */ 34 */
35struct TransportPlugin { 35struct TransportPlugin
36{
36 /** 37 /**
37 * This is a doubly-linked list. 38 * This is a doubly-linked list.
38 */ 39 */
@@ -86,12 +87,12 @@ static struct TransportPlugin *plugins_tail;
86 * @param distance new distance 87 * @param distance new distance
87 */ 88 */
88static void 89static void
89plugin_env_update_distance(void *cls, 90plugin_env_update_distance (void *cls,
90 const struct GNUNET_HELLO_Address *address, 91 const struct GNUNET_HELLO_Address *address,
91 uint32_t distance) 92 uint32_t distance)
92{ 93{
93 GST_ats_update_distance(address, 94 GST_ats_update_distance (address,
94 distance); 95 distance);
95} 96}
96 97
97 98
@@ -105,18 +106,18 @@ plugin_env_update_distance(void *cls,
105 * @return type of the network @a addr belongs to 106 * @return type of the network @a addr belongs to
106 */ 107 */
107static enum GNUNET_NetworkType 108static enum GNUNET_NetworkType
108plugin_env_address_to_type(void *cls, 109plugin_env_address_to_type (void *cls,
109 const struct sockaddr *addr, 110 const struct sockaddr *addr,
110 size_t addrlen) 111 size_t addrlen)
111{ 112{
112 if (NULL == GST_is) 113 if (NULL == GST_is)
113 { 114 {
114 GNUNET_break(0); 115 GNUNET_break (0);
115 return GNUNET_NT_UNSPECIFIED; 116 return GNUNET_NT_UNSPECIFIED;
116 } 117 }
117 return GNUNET_NT_scanner_get_type(GST_is, 118 return GNUNET_NT_scanner_get_type (GST_is,
118 addr, 119 addr,
119 addrlen); 120 addrlen);
120} 121}
121 122
122 123
@@ -133,10 +134,10 @@ plugin_env_address_to_type(void *cls,
133 * @param address_type_cb function to call when a address type is requested 134 * @param address_type_cb function to call when a address type is requested
134 */ 135 */
135void 136void
136GST_plugins_load(GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, 137GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
137 GNUNET_TRANSPORT_AddressNotification address_cb, 138 GNUNET_TRANSPORT_AddressNotification address_cb,
138 GNUNET_TRANSPORT_SessionStart session_start_cb, 139 GNUNET_TRANSPORT_SessionStart session_start_cb,
139 GNUNET_TRANSPORT_SessionEnd session_end_cb) 140 GNUNET_TRANSPORT_SessionEnd session_end_cb)
140{ 141{
141 struct TransportPlugin *plug; 142 struct TransportPlugin *plug;
142 struct TransportPlugin *next; 143 struct TransportPlugin *next;
@@ -147,175 +148,175 @@ GST_plugins_load(GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
147 int fail; 148 int fail;
148 149
149 if (GNUNET_OK != 150 if (GNUNET_OK !=
150 GNUNET_CONFIGURATION_get_value_number(GST_cfg, 151 GNUNET_CONFIGURATION_get_value_number (GST_cfg,
151 "TRANSPORT", 152 "TRANSPORT",
152 "NEIGHBOUR_LIMIT", 153 "NEIGHBOUR_LIMIT",
153 &tneigh)) 154 &tneigh))
154 { 155 {
155 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 156 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
156 _("Transport service is lacking NEIGHBOUR_LIMIT option.\n")); 157 _ ("Transport service is lacking NEIGHBOUR_LIMIT option.\n"));
157 return; 158 return;
158 } 159 }
159 if (GNUNET_OK != 160 if (GNUNET_OK !=
160 GNUNET_CONFIGURATION_get_value_string(GST_cfg, 161 GNUNET_CONFIGURATION_get_value_string (GST_cfg,
161 "TRANSPORT", 162 "TRANSPORT",
162 "PLUGINS", 163 "PLUGINS",
163 &plugs)) 164 &plugs))
164 return; 165 return;
165 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 166 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
166 _("Starting transport plugins `%s'\n"), 167 _ ("Starting transport plugins `%s'\n"),
167 plugs); 168 plugs);
168 for (pos = strtok(plugs, " "); pos != NULL; pos = strtok(NULL, " ")) 169 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
169 { 170 {
170 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 171 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
171 _("Loading `%s' transport plugin\n"), 172 _ ("Loading `%s' transport plugin\n"),
172 pos); 173 pos);
173 GNUNET_asprintf(&libname, 174 GNUNET_asprintf (&libname,
174 "libgnunet_plugin_transport_%s", 175 "libgnunet_plugin_transport_%s",
175 pos); 176 pos);
176 plug = GNUNET_new(struct TransportPlugin); 177 plug = GNUNET_new (struct TransportPlugin);
177 plug->short_name = GNUNET_strdup(pos); 178 plug->short_name = GNUNET_strdup (pos);
178 plug->lib_name = libname; 179 plug->lib_name = libname;
179 plug->env.cfg = GST_cfg; 180 plug->env.cfg = GST_cfg;
180 plug->env.my_identity = &GST_my_identity; 181 plug->env.my_identity = &GST_my_identity;
181 plug->env.get_our_hello = &GST_hello_get; 182 plug->env.get_our_hello = &GST_hello_get;
182 plug->env.cls = plug->short_name; 183 plug->env.cls = plug->short_name;
183 plug->env.receive = recv_cb; 184 plug->env.receive = recv_cb;
184 plug->env.notify_address = address_cb; 185 plug->env.notify_address = address_cb;
185 plug->env.session_start = session_start_cb; 186 plug->env.session_start = session_start_cb;
186 plug->env.session_end = session_end_cb; 187 plug->env.session_end = session_end_cb;
187 plug->env.get_address_type = &plugin_env_address_to_type; 188 plug->env.get_address_type = &plugin_env_address_to_type;
188 plug->env.update_address_distance = &plugin_env_update_distance; 189 plug->env.update_address_distance = &plugin_env_update_distance;
189 plug->env.max_connections = tneigh; 190 plug->env.max_connections = tneigh;
190 plug->env.stats = GST_stats; 191 plug->env.stats = GST_stats;
191 GNUNET_CONTAINER_DLL_insert(plugins_head, 192 GNUNET_CONTAINER_DLL_insert (plugins_head,
192 plugins_tail, 193 plugins_tail,
193 plug); 194 plug);
194 } 195 }
195 GNUNET_free(plugs); 196 GNUNET_free (plugs);
196 next = plugins_head; 197 next = plugins_head;
197 while (NULL != next) 198 while (NULL != next)
199 {
200 plug = next;
201 next = plug->next;
202 plug->api = GNUNET_PLUGIN_load (plug->lib_name,
203 &plug->env);
204 if (NULL == plug->api)
205 {
206 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
207 _ ("Failed to load transport plugin for `%s'\n"),
208 plug->lib_name);
209 GNUNET_CONTAINER_DLL_remove (plugins_head,
210 plugins_tail,
211 plug);
212 GNUNET_free (plug->short_name);
213 GNUNET_free (plug->lib_name);
214 GNUNET_free (plug);
215 continue;
216 }
217 fail = GNUNET_NO;
218 if (NULL == plug->api->address_pretty_printer)
219 {
220 fail = GNUNET_YES;
221 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
222 _ ("Missing function `%s' in transport plugin for `%s'\n"),
223 "address_pretty_printer",
224 plug->lib_name);
225 }
226 if (NULL == plug->api->address_to_string)
227 {
228 fail = GNUNET_YES;
229 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
230 _ ("Missing function `%s' in transport plugin for `%s'\n"),
231 "address_to_string",
232 plug->lib_name);
233 }
234 if (NULL == plug->api->string_to_address)
235 {
236 fail = GNUNET_YES;
237 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
238 _ ("Missing function `%s' in transport plugin for `%s'\n"),
239 "string_to_address",
240 plug->lib_name);
241 }
242 if (NULL == plug->api->check_address)
243 {
244 fail = GNUNET_YES;
245 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
246 _ ("Missing function `%s' in transport plugin for `%s'\n"),
247 "check_address",
248 plug->lib_name);
249 }
250 if (NULL == plug->api->get_session)
251 {
252 fail = GNUNET_YES;
253 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
254 _ ("Missing function `%s' in transport plugin for `%s'\n"),
255 "get_session",
256 plug->lib_name);
257 }
258 if (NULL == plug->api->get_network)
259 {
260 fail = GNUNET_YES;
261 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
262 _ ("Missing function `%s' in transport plugin for `%s'\n"),
263 "get_network",
264 plug->lib_name);
265 }
266 if (NULL == plug->api->send)
267 {
268 fail = GNUNET_YES;
269 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
270 _ ("Missing function `%s' in transport plugin for `%s'\n"),
271 "send",
272 plug->lib_name);
273 }
274 if (NULL == plug->api->disconnect_peer)
198 { 275 {
199 plug = next; 276 fail = GNUNET_YES;
200 next = plug->next; 277 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
201 plug->api = GNUNET_PLUGIN_load(plug->lib_name, 278 _ ("Missing function `%s' in transport plugin for `%s'\n"),
202 &plug->env); 279 "disconnect_peer",
203 if (NULL == plug->api) 280 plug->lib_name);
204 {
205 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
206 _("Failed to load transport plugin for `%s'\n"),
207 plug->lib_name);
208 GNUNET_CONTAINER_DLL_remove(plugins_head,
209 plugins_tail,
210 plug);
211 GNUNET_free(plug->short_name);
212 GNUNET_free(plug->lib_name);
213 GNUNET_free(plug);
214 continue;
215 }
216 fail = GNUNET_NO;
217 if (NULL == plug->api->address_pretty_printer)
218 {
219 fail = GNUNET_YES;
220 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
221 _("Missing function `%s' in transport plugin for `%s'\n"),
222 "address_pretty_printer",
223 plug->lib_name);
224 }
225 if (NULL == plug->api->address_to_string)
226 {
227 fail = GNUNET_YES;
228 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
229 _("Missing function `%s' in transport plugin for `%s'\n"),
230 "address_to_string",
231 plug->lib_name);
232 }
233 if (NULL == plug->api->string_to_address)
234 {
235 fail = GNUNET_YES;
236 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
237 _("Missing function `%s' in transport plugin for `%s'\n"),
238 "string_to_address",
239 plug->lib_name);
240 }
241 if (NULL == plug->api->check_address)
242 {
243 fail = GNUNET_YES;
244 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
245 _("Missing function `%s' in transport plugin for `%s'\n"),
246 "check_address",
247 plug->lib_name);
248 }
249 if (NULL == plug->api->get_session)
250 {
251 fail = GNUNET_YES;
252 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
253 _("Missing function `%s' in transport plugin for `%s'\n"),
254 "get_session",
255 plug->lib_name);
256 }
257 if (NULL == plug->api->get_network)
258 {
259 fail = GNUNET_YES;
260 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
261 _("Missing function `%s' in transport plugin for `%s'\n"),
262 "get_network",
263 plug->lib_name);
264 }
265 if (NULL == plug->api->send)
266 {
267 fail = GNUNET_YES;
268 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
269 _("Missing function `%s' in transport plugin for `%s'\n"),
270 "send",
271 plug->lib_name);
272 }
273 if (NULL == plug->api->disconnect_peer)
274 {
275 fail = GNUNET_YES;
276 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
277 _("Missing function `%s' in transport plugin for `%s'\n"),
278 "disconnect_peer",
279 plug->lib_name);
280 }
281 if (NULL == plug->api->disconnect_session)
282 {
283 fail = GNUNET_YES;
284 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
285 _("Missing function `%s' in transport plugin for `%s'\n"),
286 "disconnect_session",
287 plug->lib_name);
288 }
289 if (NULL == plug->api->query_keepalive_factor)
290 {
291 fail = GNUNET_YES;
292 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
293 _("Missing function `%s' in transport plugin for `%s'\n"),
294 "query_keepalive_factor",
295 plug->lib_name);
296 }
297 if (NULL == plug->api->update_session_timeout)
298 {
299 fail = GNUNET_YES;
300 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
301 _("Missing function `%s' in transport plugin for `%s'\n"),
302 "update_session_timeout",
303 plug->lib_name);
304 }
305 if (GNUNET_YES == fail)
306 {
307 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
308 _("Did not load plugin `%s' due to missing functions\n"),
309 plug->lib_name);
310 GNUNET_break(NULL == GNUNET_PLUGIN_unload(plug->lib_name, plug->api));
311 GNUNET_CONTAINER_DLL_remove(plugins_head,
312 plugins_tail,
313 plug);
314 GNUNET_free(plug->short_name);
315 GNUNET_free(plug->lib_name);
316 GNUNET_free(plug);
317 }
318 } 281 }
282 if (NULL == plug->api->disconnect_session)
283 {
284 fail = GNUNET_YES;
285 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
286 _ ("Missing function `%s' in transport plugin for `%s'\n"),
287 "disconnect_session",
288 plug->lib_name);
289 }
290 if (NULL == plug->api->query_keepalive_factor)
291 {
292 fail = GNUNET_YES;
293 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
294 _ ("Missing function `%s' in transport plugin for `%s'\n"),
295 "query_keepalive_factor",
296 plug->lib_name);
297 }
298 if (NULL == plug->api->update_session_timeout)
299 {
300 fail = GNUNET_YES;
301 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
302 _ ("Missing function `%s' in transport plugin for `%s'\n"),
303 "update_session_timeout",
304 plug->lib_name);
305 }
306 if (GNUNET_YES == fail)
307 {
308 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
309 _ ("Did not load plugin `%s' due to missing functions\n"),
310 plug->lib_name);
311 GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
312 GNUNET_CONTAINER_DLL_remove (plugins_head,
313 plugins_tail,
314 plug);
315 GNUNET_free (plug->short_name);
316 GNUNET_free (plug->lib_name);
317 GNUNET_free (plug);
318 }
319 }
319} 320}
320 321
321 322
@@ -323,18 +324,18 @@ GST_plugins_load(GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
323 * Unload all plugins 324 * Unload all plugins
324 */ 325 */
325void 326void
326GST_plugins_unload() 327GST_plugins_unload ()
327{ 328{
328 struct TransportPlugin *plug; 329 struct TransportPlugin *plug;
329 330
330 while (NULL != (plug = plugins_head)) 331 while (NULL != (plug = plugins_head))
331 { 332 {
332 GNUNET_break(NULL == GNUNET_PLUGIN_unload(plug->lib_name, plug->api)); 333 GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
333 GNUNET_free(plug->lib_name); 334 GNUNET_free (plug->lib_name);
334 GNUNET_free(plug->short_name); 335 GNUNET_free (plug->short_name);
335 GNUNET_CONTAINER_DLL_remove(plugins_head, plugins_tail, plug); 336 GNUNET_CONTAINER_DLL_remove (plugins_head, plugins_tail, plug);
336 GNUNET_free(plug); 337 GNUNET_free (plug);
337 } 338 }
338} 339}
339 340
340 341
@@ -345,12 +346,12 @@ GST_plugins_unload()
345 * @return the plugin's API, NULL if the plugin is not loaded 346 * @return the plugin's API, NULL if the plugin is not loaded
346 */ 347 */
347struct GNUNET_TRANSPORT_PluginFunctions * 348struct GNUNET_TRANSPORT_PluginFunctions *
348GST_plugins_find(const char *name) 349GST_plugins_find (const char *name)
349{ 350{
350 struct TransportPlugin *pos; 351 struct TransportPlugin *pos;
351 352
352 for (pos = plugins_head; NULL != pos; pos = pos->next) 353 for (pos = plugins_head; NULL != pos; pos = pos->next)
353 if (0 == strcmp(name, pos->short_name)) 354 if (0 == strcmp (name, pos->short_name))
354 break; 355 break;
355 if (NULL == pos) 356 if (NULL == pos)
356 return NULL; 357 return NULL;
@@ -369,18 +370,18 @@ GST_plugins_find(const char *name)
369 * @return the plugin's API, NULL if the plugin is not loaded 370 * @return the plugin's API, NULL if the plugin is not loaded
370 */ 371 */
371struct GNUNET_TRANSPORT_PluginFunctions * 372struct GNUNET_TRANSPORT_PluginFunctions *
372GST_plugins_printer_find(const char *name) 373GST_plugins_printer_find (const char *name)
373{ 374{
374 struct TransportPlugin *pos; 375 struct TransportPlugin *pos;
375 char *stripped = GNUNET_strdup(name); 376 char *stripped = GNUNET_strdup (name);
376 char *sep = strchr(stripped, '_'); 377 char *sep = strchr (stripped, '_');
377 378
378 if (NULL != sep) 379 if (NULL != sep)
379 sep[0] = '\0'; 380 sep[0] = '\0';
380 for (pos = plugins_head; NULL != pos; pos = pos->next) 381 for (pos = plugins_head; NULL != pos; pos = pos->next)
381 if (pos->short_name == strstr(pos->short_name, stripped)) 382 if (pos->short_name == strstr (pos->short_name, stripped))
382 break; 383 break;
383 GNUNET_free(stripped); 384 GNUNET_free (stripped);
384 if (NULL == pos) 385 if (NULL == pos)
385 return NULL; 386 return NULL;
386 return pos->api; 387 return pos->api;
@@ -395,7 +396,7 @@ GST_plugins_printer_find(const char *name)
395 * @return statically allocated (!) human-readable address 396 * @return statically allocated (!) human-readable address
396 */ 397 */
397const char * 398const char *
398GST_plugins_a2s(const struct GNUNET_HELLO_Address *address) 399GST_plugins_a2s (const struct GNUNET_HELLO_Address *address)
399{ 400{
400 struct GNUNET_TRANSPORT_PluginFunctions *api; 401 struct GNUNET_TRANSPORT_PluginFunctions *api;
401 static char unable_to_show[1024]; 402 static char unable_to_show[1024];
@@ -405,26 +406,26 @@ GST_plugins_a2s(const struct GNUNET_HELLO_Address *address)
405 return "<NULL>"; 406 return "<NULL>";
406 if (0 == address->address_length) 407 if (0 == address->address_length)
407 return TRANSPORT_SESSION_INBOUND_STRING; /* Addresse with length 0 are inbound, address->address itself may be NULL */ 408 return TRANSPORT_SESSION_INBOUND_STRING; /* Addresse with length 0 are inbound, address->address itself may be NULL */
408 api = GST_plugins_printer_find(address->transport_name); 409 api = GST_plugins_printer_find (address->transport_name);
409 if (NULL == api) 410 if (NULL == api)
410 { 411 {
411 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
412 "Failed to find transport plugin `%s'\n", 413 "Failed to find transport plugin `%s'\n",
413 address->transport_name); 414 address->transport_name);
414 return "<plugin unknown>"; 415 return "<plugin unknown>";
415 } 416 }
416 if (0 == address->address_length) 417 if (0 == address->address_length)
417 { 418 {
418 GNUNET_snprintf(unable_to_show, 419 GNUNET_snprintf (unable_to_show,
419 sizeof(unable_to_show), 420 sizeof(unable_to_show),
420 "<unable to stringify %u-byte long address of %s transport>", 421 "<unable to stringify %u-byte long address of %s transport>",
421 (unsigned int)address->address_length, 422 (unsigned int) address->address_length,
422 address->transport_name); 423 address->transport_name);
423 return unable_to_show; 424 return unable_to_show;
424 } 425 }
425 return(NULL != (s = api->address_to_string(NULL, 426 return(NULL != (s = api->address_to_string (NULL,
426 address->address, 427 address->address,
427 address->address_length)) 428 address->address_length))
428 ? s 429 ? s
429 : "<invalid>"); 430 : "<invalid>");
430} 431}
@@ -437,18 +438,18 @@ GST_plugins_a2s(const struct GNUNET_HELLO_Address *address)
437 * @param cb_cls closure for @a cb 438 * @param cb_cls closure for @a cb
438 */ 439 */
439void 440void
440GST_plugins_monitor_subscribe(GNUNET_TRANSPORT_SessionInfoCallback cb, 441GST_plugins_monitor_subscribe (GNUNET_TRANSPORT_SessionInfoCallback cb,
441 void *cb_cls) 442 void *cb_cls)
442{ 443{
443 struct TransportPlugin *pos; 444 struct TransportPlugin *pos;
444 445
445 for (pos = plugins_head; NULL != pos; pos = pos->next) 446 for (pos = plugins_head; NULL != pos; pos = pos->next)
446 if (NULL == pos->api->setup_monitor) 447 if (NULL == pos->api->setup_monitor)
447 GNUNET_break(0); 448 GNUNET_break (0);
448 else 449 else
449 pos->api->setup_monitor(pos->api->cls, 450 pos->api->setup_monitor (pos->api->cls,
450 cb, 451 cb,
451 cb_cls); 452 cb_cls);
452} 453}
453 454
454 455