GNUnet  0.19.4
gnunet-service-transport_plugins.h File Reference

plugin management API More...

Include dependency graph for gnunet-service-transport_plugins.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, GNUNET_TRANSPORT_AddressNotification address_cb, GNUNET_TRANSPORT_SessionStart session_start_cb, GNUNET_TRANSPORT_SessionEnd session_end_cb)
 Load and initialize all plugins. More...
 
void GST_plugins_unload (void)
 Unload all plugins. More...
 
struct GNUNET_TRANSPORT_PluginFunctionsGST_plugins_find (const char *name)
 Obtain the plugin API based on a plugin name. More...
 
struct GNUNET_TRANSPORT_PluginFunctionsGST_plugins_printer_find (const char *name)
 Obtain the plugin API based on a the stripped plugin name after the underscore. More...
 
const char * GST_plugins_a2s (const struct GNUNET_HELLO_Address *address)
 Convert a given address to a human-readable format. More...
 
void GST_plugins_monitor_subscribe (GNUNET_TRANSPORT_SessionInfoCallback cb, void *cb_cls)
 Register callback with all plugins to monitor their status. More...
 

Detailed Description

plugin management API

Author
Christian Grothoff

Definition in file gnunet-service-transport_plugins.h.

Function Documentation

◆ GST_plugins_load()

void GST_plugins_load ( GNUNET_TRANSPORT_PluginReceiveCallback  recv_cb,
GNUNET_TRANSPORT_AddressNotification  address_cb,
GNUNET_TRANSPORT_SessionStart  session_start_cb,
GNUNET_TRANSPORT_SessionEnd  session_end_cb 
)

Load and initialize all plugins.

The respective functions will be invoked by the plugins when the respective events happen. The closure will be set to a 'const char*' containing the name of the plugin that caused the call.

Parameters
recv_cbfunction to call when data is received
address_cbfunction to call when our public addresses changed
session_start_cbfunction to call when a session was created
session_end_cbfunction to call when a session was terminated

Definition at line 124 of file gnunet-service-transport_plugins.c.

128 {
129  struct TransportPlugin *plug;
130  struct TransportPlugin *next;
131  unsigned long long tneigh;
132  char *libname;
133  char *plugs;
134  char *pos;
135  int fail;
136 
137  if (GNUNET_OK !=
139  "TRANSPORT",
140  "NEIGHBOUR_LIMIT",
141  &tneigh))
142  {
144  _ ("Transport service is lacking NEIGHBOUR_LIMIT option.\n"));
145  return;
146  }
147  if (GNUNET_OK !=
149  "TRANSPORT",
150  "PLUGINS",
151  &plugs))
152  return;
154  _ ("Starting transport plugins `%s'\n"),
155  plugs);
156  for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
157  {
159  _ ("Loading `%s' transport plugin\n"),
160  pos);
161  GNUNET_asprintf (&libname,
162  "libgnunet_plugin_transport_%s",
163  pos);
164  plug = GNUNET_new (struct TransportPlugin);
165  plug->short_name = GNUNET_strdup (pos);
166  plug->lib_name = libname;
167  plug->env.cfg = GST_cfg;
170  plug->env.cls = plug->short_name;
171  plug->env.receive = recv_cb;
172  plug->env.notify_address = address_cb;
173  plug->env.session_start = session_start_cb;
174  plug->env.session_end = session_end_cb;
177  plug->env.max_connections = tneigh;
178  plug->env.stats = GST_stats;
180  plugins_tail,
181  plug);
182  }
183  GNUNET_free (plugs);
184  next = plugins_head;
185  while (NULL != next)
186  {
187  plug = next;
188  next = plug->next;
189  plug->api = GNUNET_PLUGIN_load (plug->lib_name,
190  &plug->env);
191  if (NULL == plug->api)
192  {
194  _ ("Failed to load transport plugin for `%s'\n"),
195  plug->lib_name);
197  plugins_tail,
198  plug);
199  GNUNET_free (plug->short_name);
200  GNUNET_free (plug->lib_name);
201  GNUNET_free (plug);
202  continue;
203  }
204  fail = GNUNET_NO;
205  if (NULL == plug->api->address_pretty_printer)
206  {
207  fail = GNUNET_YES;
209  _ ("Missing function `%s' in transport plugin for `%s'\n"),
210  "address_pretty_printer",
211  plug->lib_name);
212  }
213  if (NULL == plug->api->address_to_string)
214  {
215  fail = GNUNET_YES;
217  _ ("Missing function `%s' in transport plugin for `%s'\n"),
218  "address_to_string",
219  plug->lib_name);
220  }
221  if (NULL == plug->api->string_to_address)
222  {
223  fail = GNUNET_YES;
225  _ ("Missing function `%s' in transport plugin for `%s'\n"),
226  "string_to_address",
227  plug->lib_name);
228  }
229  if (NULL == plug->api->check_address)
230  {
231  fail = GNUNET_YES;
233  _ ("Missing function `%s' in transport plugin for `%s'\n"),
234  "check_address",
235  plug->lib_name);
236  }
237  if (NULL == plug->api->get_session)
238  {
239  fail = GNUNET_YES;
241  _ ("Missing function `%s' in transport plugin for `%s'\n"),
242  "get_session",
243  plug->lib_name);
244  }
245  if (NULL == plug->api->get_network)
246  {
247  fail = GNUNET_YES;
249  _ ("Missing function `%s' in transport plugin for `%s'\n"),
250  "get_network",
251  plug->lib_name);
252  }
253  if (NULL == plug->api->send)
254  {
255  fail = GNUNET_YES;
257  _ ("Missing function `%s' in transport plugin for `%s'\n"),
258  "send",
259  plug->lib_name);
260  }
261  if (NULL == plug->api->disconnect_peer)
262  {
263  fail = GNUNET_YES;
265  _ ("Missing function `%s' in transport plugin for `%s'\n"),
266  "disconnect_peer",
267  plug->lib_name);
268  }
269  if (NULL == plug->api->disconnect_session)
270  {
271  fail = GNUNET_YES;
273  _ ("Missing function `%s' in transport plugin for `%s'\n"),
274  "disconnect_session",
275  plug->lib_name);
276  }
277  if (NULL == plug->api->query_keepalive_factor)
278  {
279  fail = GNUNET_YES;
281  _ ("Missing function `%s' in transport plugin for `%s'\n"),
282  "query_keepalive_factor",
283  plug->lib_name);
284  }
285  if (NULL == plug->api->update_session_timeout)
286  {
287  fail = GNUNET_YES;
289  _ ("Missing function `%s' in transport plugin for `%s'\n"),
290  "update_session_timeout",
291  plug->lib_name);
292  }
293  if (GNUNET_YES == fail)
294  {
296  _ ("Did not load plugin `%s' due to missing functions\n"),
297  plug->lib_name);
298  GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
300  plugins_tail,
301  plug);
302  GNUNET_free (plug->short_name);
303  GNUNET_free (plug->lib_name);
304  GNUNET_free (plug);
305  }
306  }
307 }
static void address_cb(void *cls, void **app_ctx, int add_remove, enum GNUNET_NAT_AddressClass ac, const struct sockaddr *addr, socklen_t addrlen)
Signature of the callback passed to GNUNET_NAT_register() for a function to call whenever our set of ...
Definition: gnunet-nat.c:122
static struct GNUNET_PeerIdentity GST_my_identity
Our public key.
static const struct GNUNET_CONFIGURATION_Handle * GST_cfg
Configuration handle.
static struct GNUNET_STATISTICS_Handle * GST_stats
Statistics handle.
const struct GNUNET_MessageHeader * GST_hello_get()
Obtain this peers HELLO message.
static void plugin_env_update_distance(void *cls, const struct GNUNET_HELLO_Address *address, uint32_t distance)
Function that will be called to update metrics for an address.
static enum GNUNET_NetworkType plugin_env_address_to_type(void *cls, const struct sockaddr *addr, size_t addrlen)
Function that will be called to figure if an address is an loopback, LAN, WAN etc.
static struct TransportPlugin * plugins_head
Head of DLL of all loaded plugins.
static struct TransportPlugin * plugins_tail
Head of DLL of all loaded plugins.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_INFO
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_PLUGIN_unload(const char *library_name, void *arg)
Unload plugin (runs the "done" callback and returns whatever "done" returned).
Definition: plugin.c:242
void * GNUNET_PLUGIN_load(const char *library_name, void *arg)
Setup plugin (runs the "init" callback and returns whatever "init" returned).
Definition: plugin.c:198
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
GNUNET_TRANSPORT_AddressToType get_address_type
Function that will be called to figure if an address is an loopback, LAN, WAN etc.
GNUNET_TRANSPORT_SessionEnd session_end
Function that must be called by the plugin when a non-NULL session handle stops being valid (is destr...
GNUNET_TRANSPORT_GetHelloCallback get_our_hello
Function that returns our HELLO.
GNUNET_TRANSPORT_AddressNotification notify_address
Function that must be called by each plugin to notify the transport service about the addresses under...
void * cls
Closure for the various callbacks.
GNUNET_TRANSPORT_UpdateAddressDistance update_address_distance
Function that will be called by DV to update distance for an address.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
GNUNET_TRANSPORT_SessionStart session_start
Function called by the plugin when a new (incoming) session was created not explicitly created using ...
GNUNET_TRANSPORT_PluginReceiveCallback receive
Function that should be called by the transport plugin whenever a message is received.
const struct GNUNET_PeerIdentity * my_identity
Identity of this peer.
uint32_t max_connections
What is the maximum number of connections that this transport should allow? Transports that do not ha...
GNUNET_TRANSPORT_TransmitFunction send
Function that the transport service will use to transmit data to another peer.
GNUNET_TRANSPORT_DisconnectPeerFunction disconnect_peer
Function that can be used to force the plugin to disconnect from the given peer and cancel all previo...
GNUNET_TRANSPORT_DisconnectSessionFunction disconnect_session
Function that can be used to force the plugin to disconnect from the given peer and cancel all previo...
GNUNET_TRANSPORT_QueryKeepaliveFactorFunction query_keepalive_factor
Function that is used to query keepalive factor.
GNUNET_TRANSPORT_AddressPrettyPrinter address_pretty_printer
Function to pretty-print addresses.
GNUNET_TRANSPORT_AddressToString address_to_string
Function that will be called to convert a binary address to a string (numeric conversion only).
GNUNET_TRANSPORT_GetNetworkType get_network
Function to obtain the network type for a session.
GNUNET_TRANSPORT_CreateSession get_session
Function that will be called tell the plugin to create a session object.
GNUNET_TRANSPORT_CheckAddress check_address
Function that will be called to check if a binary address for this plugin is well-formed and correspo...
GNUNET_TRANSPORT_StringToAddress string_to_address
Function that will be called to convert a string address to binary (numeric conversion only).
GNUNET_TRANSPORT_UpdateSessionTimeout update_session_timeout
Function that will be called whenever the transport service wants to notify the plugin that a session...
Entry in doubly-linked list of all of our plugins.
struct TransportPlugin * next
This is a doubly-linked list.
struct GNUNET_TRANSPORT_PluginEnvironment env
Environment this transport service is using for this plugin.
char * short_name
Short name for the plugin (e.g.
char * lib_name
Name of the library (e.g.
struct GNUNET_TRANSPORT_PluginFunctions * api
API of the transport as returned by the plugin's initialization function.

References _, address_cb(), GNUNET_TRANSPORT_PluginFunctions::address_pretty_printer, GNUNET_TRANSPORT_PluginFunctions::address_to_string, TransportPlugin::api, GNUNET_TRANSPORT_PluginEnvironment::cfg, GNUNET_TRANSPORT_PluginFunctions::check_address, GNUNET_TRANSPORT_PluginEnvironment::cls, GNUNET_TRANSPORT_PluginFunctions::disconnect_peer, GNUNET_TRANSPORT_PluginFunctions::disconnect_session, TransportPlugin::env, GNUNET_TRANSPORT_PluginEnvironment::get_address_type, GNUNET_TRANSPORT_PluginFunctions::get_network, GNUNET_TRANSPORT_PluginEnvironment::get_our_hello, GNUNET_TRANSPORT_PluginFunctions::get_session, GNUNET_asprintf(), GNUNET_break, GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_PLUGIN_load(), GNUNET_PLUGIN_unload(), GNUNET_strdup, GNUNET_YES, GST_cfg, GST_hello_get(), GST_my_identity, GST_stats, TransportPlugin::lib_name, GNUNET_TRANSPORT_PluginEnvironment::max_connections, GNUNET_TRANSPORT_PluginEnvironment::my_identity, TransportPlugin::next, GNUNET_TRANSPORT_PluginEnvironment::notify_address, plugin_env_address_to_type(), plugin_env_update_distance(), plugins_head, plugins_tail, GNUNET_TRANSPORT_PluginFunctions::query_keepalive_factor, GNUNET_TRANSPORT_PluginEnvironment::receive, GNUNET_TRANSPORT_PluginFunctions::send, GNUNET_TRANSPORT_PluginEnvironment::session_end, GNUNET_TRANSPORT_PluginEnvironment::session_start, TransportPlugin::short_name, GNUNET_TRANSPORT_PluginEnvironment::stats, GNUNET_TRANSPORT_PluginFunctions::string_to_address, GNUNET_TRANSPORT_PluginEnvironment::update_address_distance, and GNUNET_TRANSPORT_PluginFunctions::update_session_timeout.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_plugins_unload()

void GST_plugins_unload ( void  )

Unload all plugins.

Definition at line 314 of file gnunet-service-transport_plugins.c.

315 {
316  struct TransportPlugin *plug;
317 
318  while (NULL != (plug = plugins_head))
319  {
320  GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
321  GNUNET_free (plug->lib_name);
322  GNUNET_free (plug->short_name);
324  GNUNET_free (plug);
325  }
326 }

References TransportPlugin::api, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_PLUGIN_unload(), TransportPlugin::lib_name, plugins_head, plugins_tail, and TransportPlugin::short_name.

Referenced by shutdown_task().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_plugins_find()

struct GNUNET_TRANSPORT_PluginFunctions* GST_plugins_find ( const char *  name)

Obtain the plugin API based on a plugin name.

Parameters
namename of the plugin
Returns
the plugin's API, NULL if the plugin is not loaded

Definition at line 336 of file gnunet-service-transport_plugins.c.

337 {
338  struct TransportPlugin *pos;
339 
340  for (pos = plugins_head; NULL != pos; pos = pos->next)
341  if (0 == strcmp (name, pos->short_name))
342  break;
343  if (NULL == pos)
344  return NULL;
345  return pos->api;
346 }
const char * name

References TransportPlugin::api, name, TransportPlugin::next, plugins_head, and TransportPlugin::short_name.

Referenced by add_valid_address(), GST_neighbours_calculate_receive_delay(), GST_neighbours_switch_to_address(), GST_validation_handle_address(), GST_validation_handle_ping(), GST_validation_handle_pong(), inbound_bw_tracker_update(), kill_session(), multicast_pong(), send_syn(), send_syn_ack_message(), send_with_session(), switch_address_bl_check_cont(), and transmit_ping_if_allowed().

Here is the caller graph for this function:

◆ GST_plugins_printer_find()

struct GNUNET_TRANSPORT_PluginFunctions* GST_plugins_printer_find ( const char *  name)

Obtain the plugin API based on a the stripped plugin name after the underscore.

Example: GST_plugins_printer_find (http_client) will return all plugins starting with the prefix "http": http_client or server if loaded

Parameters
namename of the plugin
Returns
the plugin's API, NULL if the plugin is not loaded

Definition at line 360 of file gnunet-service-transport_plugins.c.

361 {
362  struct TransportPlugin *pos;
363  char *stripped = GNUNET_strdup (name);
364  char *sep = strchr (stripped, '_');
365 
366  if (NULL != sep)
367  sep[0] = '\0';
368  for (pos = plugins_head; NULL != pos; pos = pos->next)
369  if (pos->short_name == strstr (pos->short_name, stripped))
370  break;
371  GNUNET_free (stripped);
372  if (NULL == pos)
373  return NULL;
374  return pos->api;
375 }

References TransportPlugin::api, GNUNET_free, GNUNET_strdup, name, TransportPlugin::next, plugins_head, and TransportPlugin::short_name.

Referenced by GST_plugins_a2s(), and handle_client_address_to_string().

Here is the caller graph for this function:

◆ GST_plugins_a2s()

const char* GST_plugins_a2s ( const struct GNUNET_HELLO_Address address)

Convert a given address to a human-readable format.

Note that the return value will be overwritten on the next call to this function.

Parameters
addressaddress to convert
Returns
statically allocated (!) human-readable address

Note that the return value will be overwritten on the next call to this function.

Parameters
addressthe address to convert
Returns
statically allocated (!) human-readable address

Definition at line 386 of file gnunet-service-transport_plugins.c.

387 {
389  static char unable_to_show[1024];
390  static const char *s;
391 
392  if (NULL == address)
393  return "<NULL>";
394  if (0 == address->address_length)
395  return TRANSPORT_SESSION_INBOUND_STRING; /* Addresse with length 0 are inbound, address->address itself may be NULL */
396  api = GST_plugins_printer_find (address->transport_name);
397  if (NULL == api)
398  {
400  "Failed to find transport plugin `%s'\n",
401  address->transport_name);
402  return "<plugin unknown>";
403  }
404  if (0 == address->address_length)
405  {
406  GNUNET_snprintf (unable_to_show,
407  sizeof(unable_to_show),
408  "<unable to stringify %u-byte long address of %s transport>",
409  (unsigned int) address->address_length,
410  address->transport_name);
411  return unable_to_show;
412  }
413  return(NULL != (s = api->address_to_string (NULL,
414  address->address,
415  address->address_length))
416  ? s
417  : "<invalid>");
418 }
static char * address
GNS address for this phone.
struct GNUNET_TRANSPORT_PluginFunctions * GST_plugins_printer_find(const char *name)
Obtain the plugin API based on a the stripped plugin name after the underscore.
@ GNUNET_ERROR_TYPE_DEBUG
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#define TRANSPORT_SESSION_INBOUND_STRING
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...

References address, GNUNET_TRANSPORT_PluginFunctions::address_to_string, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_snprintf(), GST_plugins_printer_find(), and TRANSPORT_SESSION_INBOUND_STRING.

Referenced by add_valid_address(), connect_bl_check_cont(), GST_ats_add_address(), GST_ats_add_inbound_address(), GST_ats_block_address(), GST_ats_expire_address(), GST_ats_update_utilization(), GST_hello_modify_addresses(), GST_neighbours_session_terminated(), GST_neighbours_switch_to_address(), GST_validation_handle_address(), GST_validation_handle_ping(), GST_validation_handle_pong(), neighbours_changed_notification(), plugin_env_session_end(), plugin_env_session_start(), plugin_env_session_start_bl_check_cont(), revalidate_address(), send_peer_information(), send_session_syn_ack_cont(), send_syn(), send_syn_ack_message(), send_with_session(), set_primary_address(), switch_address_bl_check_cont(), transmit_ping_if_allowed(), and unblock_address().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_plugins_monitor_subscribe()

void GST_plugins_monitor_subscribe ( GNUNET_TRANSPORT_SessionInfoCallback  cb,
void *  cb_cls 
)

Register callback with all plugins to monitor their status.

Parameters
cbcallback to register, NULL to unsubscribe
cb_clsclosure for cb

Definition at line 422 of file gnunet-service-transport_plugins.c.

424 {
425  struct TransportPlugin *pos;
426 
427  for (pos = plugins_head; NULL != pos; pos = pos->next)
428  if (NULL == pos->api->setup_monitor)
429  GNUNET_break (0);
430  else
431  pos->api->setup_monitor (pos->api->cls,
432  cb,
433  cb_cls);
434 }
void * cls
Closure for all of the callbacks.
GNUNET_TRANSPORT_SessionMonitorSetup setup_monitor
Function to monitor the sessions managed by the plugin.

References TransportPlugin::api, GNUNET_TRANSPORT_PluginFunctions::cls, GNUNET_break, TransportPlugin::next, plugins_head, and GNUNET_TRANSPORT_PluginFunctions::setup_monitor.

Referenced by handle_client_monitor_plugins(), and plugin_session_info_cb().

Here is the caller graph for this function: