GNUnet  0.19.5
transport_api_monitor_plugins.c File Reference

montoring api for transport plugin session status More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_arm_service.h"
#include "gnunet_hello_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_transport_service.h"
#include "transport.h"
Include dependency graph for transport_api_monitor_plugins.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_TRANSPORT_PluginMonitor
 Handle for a plugin session state monitor. More...
 
struct  GNUNET_TRANSPORT_PluginSession
 Abstract representation of a plugin's session. More...
 
struct  SearchContext
 Context information to be used while searching for operation contexts. More...
 

Functions

static void do_plugin_connect (void *cls)
 Task run to re-establish the connection. More...
 
static int free_entry (void *cls, uint32_t key, void *value)
 Free the session entry and notify the callback about its demise. More...
 
static void reconnect_plugin_ctx (struct GNUNET_TRANSPORT_PluginMonitor *pm)
 Cut the existing connection and reconnect. More...
 
static uint32_t wrap_id (uint64_t id)
 Convert 64-bit session ID to 32-bit index for hash map. More...
 
static int locate_by_id (void *cls, uint32_t key, void *value)
 Locate a session entry. More...
 
static int check_event (void *cls, const struct TransportPluginMonitorMessage *tpmm)
 Function called with responses from the service. More...
 
static void handle_event (void *cls, const struct TransportPluginMonitorMessage *tpmm)
 Function called with responses from the service. More...
 
static void handle_sync (void *cls, const struct GNUNET_MessageHeader *msg)
 Function called with sync responses from the service. More...
 
static void mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
 Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue. More...
 
struct GNUNET_TRANSPORT_PluginMonitorGNUNET_TRANSPORT_monitor_plugins (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_TRANSPORT_SessionMonitorCallback cb, void *cb_cls)
 Install a plugin session state monitor callback. More...
 
void GNUNET_TRANSPORT_monitor_plugins_cancel (struct GNUNET_TRANSPORT_PluginMonitor *pm)
 Cancel monitoring the plugin session state. More...
 

Detailed Description

montoring api for transport plugin session status

Author
Christian Grothoff

Definition in file transport_api_monitor_plugins.c.

Function Documentation

◆ do_plugin_connect()

static void do_plugin_connect ( void *  cls)
static

Task run to re-establish the connection.

Parameters
clsour struct GNUNET_TRANSPORT_PluginMonitor *

Definition at line 370 of file transport_api_monitor_plugins.c.

371 {
372  struct GNUNET_TRANSPORT_PluginMonitor *pm = cls;
374  GNUNET_MQ_hd_var_size (event,
377  pm),
380  struct GNUNET_MessageHeader,
381  pm),
383  };
384  struct GNUNET_MessageHeader *msg;
385  struct GNUNET_MQ_Envelope *env;
386 
387  pm->reconnect_task = NULL;
389  "transport",
390  handlers,
392  pm);
393  if (NULL == pm->mq)
394  return;
395  env = GNUNET_MQ_msg (msg,
397  GNUNET_MQ_send (pm->mq,
398  env);
399 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
static struct GNUNET_TRANSPORT_PluginMonitor * pm
Handle if we are monitoring plugin session activity.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1057
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:304
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:78
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT
Monitoring event about the connection state of plugins, generated in response to a subscription initi...
#define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START
Request to start monitoring the connection state of plugins.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC
Monitoring event notifying client that the initial iteration is now completed and we are in sync with...
Message handler for a specific message type.
Header for all communications.
Handle for a plugin session state monitor.
struct GNUNET_SCHEDULER_Task * reconnect_task
Task ID for reconnect.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct GNUNET_MQ_Handle * mq
Connection to the service.
Transport-level connection status update.
Definition: transport.h:610
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...

References GNUNET_TRANSPORT_PluginMonitor::cfg, env, GNUNET_CLIENT_connect(), GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg, GNUNET_MQ_send(), handlers, GNUNET_TRANSPORT_PluginMonitor::mq, mq_error_handler(), msg, pm, and GNUNET_TRANSPORT_PluginMonitor::reconnect_task.

Referenced by GNUNET_TRANSPORT_monitor_plugins(), and reconnect_plugin_ctx().

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

◆ free_entry()

static int free_entry ( void *  cls,
uint32_t  key,
void *  value 
)
static

Free the session entry and notify the callback about its demise.

Parameters
clsour struct GNUNET_TRANSPORT_PluginMonitor
keykey of the session in the map
valuethe session to free
Returns
GNUNET_OK (continue to iterate)

Definition at line 114 of file transport_api_monitor_plugins.c.

117 {
118  struct GNUNET_TRANSPORT_PluginMonitor *pm = cls;
120 
121  pm->cb (pm->cb_cls,
122  ps,
123  &ps->client_ctx,
124  NULL);
127  key,
128  ps));
129  GNUNET_break (NULL == ps->client_ctx);
130  GNUNET_free (ps);
131  return GNUNET_OK;
132 }
struct GNUNET_HashCode key
The key used in the DHT.
static char * value
Value of the record to add/remove.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap32_remove(struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, const void *value)
Remove the given key-value pair from the map.
@ GNUNET_OK
@ GNUNET_YES
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_CONTAINER_MultiHashMap32 * sessions
Map of session_ids (reduced to 32-bits) to struct GNUNET_TRANSPORT_PluginSession objects.
GNUNET_TRANSPORT_SessionMonitorCallback cb
Callback to call.
Abstract representation of a plugin's session.
void * client_ctx
Location for the client to store "data".

References GNUNET_TRANSPORT_PluginMonitor::cb, GNUNET_TRANSPORT_PluginMonitor::cb_cls, GNUNET_TRANSPORT_PluginSession::client_ctx, GNUNET_break, GNUNET_CONTAINER_multihashmap32_remove(), GNUNET_free, GNUNET_OK, GNUNET_YES, key, pm, GNUNET_TRANSPORT_PluginMonitor::sessions, and value.

Referenced by GNUNET_TRANSPORT_monitor_plugins_cancel(), and reconnect_plugin_ctx().

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

◆ reconnect_plugin_ctx()

static void reconnect_plugin_ctx ( struct GNUNET_TRANSPORT_PluginMonitor pm)
static

Cut the existing connection and reconnect.

Parameters
pmour context

Definition at line 141 of file transport_api_monitor_plugins.c.

142 {
144  pm->mq = NULL;
146  &free_entry,
147  pm);
151  pm);
152 }
int GNUNET_CONTAINER_multihashmap32_iterate(struct GNUNET_CONTAINER_MultiHashMap32 *map, GNUNET_CONTAINER_MultiHashMapIterator32Callback it, void *it_cls)
Iterate over all entries in the map.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:683
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1272
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
struct GNUNET_TIME_Relative backoff
Backoff for reconnect.
static void do_plugin_connect(void *cls)
Task run to re-establish the connection.
static int free_entry(void *cls, uint32_t key, void *value)
Free the session entry and notify the callback about its demise.

References GNUNET_TRANSPORT_PluginMonitor::backoff, do_plugin_connect(), free_entry(), GNUNET_CONTAINER_multihashmap32_iterate(), GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_STD_BACKOFF, GNUNET_TRANSPORT_PluginMonitor::mq, pm, GNUNET_TRANSPORT_PluginMonitor::reconnect_task, and GNUNET_TRANSPORT_PluginMonitor::sessions.

Referenced by handle_event(), and mq_error_handler().

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

◆ wrap_id()

static uint32_t wrap_id ( uint64_t  id)
static

Convert 64-bit session ID to 32-bit index for hash map.

Parameters
id64-bit session ID
Returns
32-bit hash map index

Definition at line 162 of file transport_api_monitor_plugins.c.

163 {
164  return ((uint32_t) id) ^ ((uint32_t) (id >> 32));
165 }

Referenced by handle_event().

Here is the caller graph for this function:

◆ locate_by_id()

static int locate_by_id ( void *  cls,
uint32_t  key,
void *  value 
)
static

Locate a session entry.

Parameters
clsour struct SearchContext
keykey of the session in the map
valuea session
Returns
GNUNET_OK (continue to iterate), or GNUNET_SYSERR (match found)

Definition at line 194 of file transport_api_monitor_plugins.c.

197 {
198  struct SearchContext *sc = cls;
200 
201  if (sc->session_id == ps->session_id)
202  {
203  sc->ps = ps;
204  return GNUNET_SYSERR;
205  }
206  return GNUNET_OK;
207 }
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:87
@ GNUNET_SYSERR
uint64_t session_id
Unique session identifier.
Context information to be used while searching for operation contexts.
Definition: testbed_api.c:226

References GNUNET_OK, GNUNET_SYSERR, sc, GNUNET_TRANSPORT_PluginSession::session_id, and value.

Referenced by handle_event().

Here is the caller graph for this function:

◆ check_event()

static int check_event ( void *  cls,
const struct TransportPluginMonitorMessage tpmm 
)
static

Function called with responses from the service.

Parameters
clsour struct GNUNET_TRANSPORT_PluginMonitor *
tpmmmessage with event data
Returns
#GNUNET_Ok if message is well-formed

Definition at line 218 of file transport_api_monitor_plugins.c.

220 {
221  const char *pname;
222  size_t pname_len;
223  size_t paddr_len;
224 
225  pname = (const char *) &tpmm[1];
226  pname_len = ntohs (tpmm->plugin_name_len);
227  paddr_len = ntohs (tpmm->plugin_address_len);
228  if ((pname_len
229  + paddr_len
230  + sizeof(struct TransportPluginMonitorMessage) != ntohs (
231  tpmm->header.size)) ||
232  ((0 != pname_len) &&
233  ('\0' != pname[pname_len - 1])))
234  {
235  GNUNET_break (0);
236  return GNUNET_SYSERR;
237  }
238  return GNUNET_OK;
239 }
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
struct GNUNET_MessageHeader header
Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT.
Definition: transport.h:614
uint16_t plugin_address_len
Length of the plugin address in bytes.
Definition: transport.h:669
uint16_t plugin_name_len
Length of the plugin name in bytes, including 0-termination.
Definition: transport.h:664

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, TransportPluginMonitorMessage::header, TransportPluginMonitorMessage::plugin_address_len, TransportPluginMonitorMessage::plugin_name_len, and GNUNET_MessageHeader::size.

◆ handle_event()

static void handle_event ( void *  cls,
const struct TransportPluginMonitorMessage tpmm 
)
static

Function called with responses from the service.

Parameters
clsour struct GNUNET_TRANSPORT_PluginMonitor *
tpmmmessage with event data

Definition at line 249 of file transport_api_monitor_plugins.c.

251 {
252  struct GNUNET_TRANSPORT_PluginMonitor *pm = cls;
254  const char *pname;
255  const void *paddr;
257  size_t pname_len;
258  size_t paddr_len;
260  struct GNUNET_HELLO_Address addr;
261  struct SearchContext rv;
262 
263  pname = (const char *) &tpmm[1];
264  pname_len = ntohs (tpmm->plugin_name_len);
265  paddr_len = ntohs (tpmm->plugin_address_len);
266  paddr = &pname[pname_len];
267  ps = NULL;
268  ss = (enum GNUNET_TRANSPORT_SessionState) ntohs (tpmm->session_state);
269  if (GNUNET_TRANSPORT_SS_INIT == ss)
270  {
272  ps->session_id = tpmm->session_id;
274  wrap_id (tpmm->session_id),
275  ps,
277  }
278  else
279  {
280  rv.session_id = tpmm->session_id;
281  rv.ps = NULL;
283  wrap_id (
284  tpmm->session_id),
285  &locate_by_id,
286  &rv);
287  ps = rv.ps;
288  if (NULL == ps)
289  {
290  GNUNET_break (0);
292  return;
293  }
294  }
295  info.state = ss;
296  info.is_inbound = (int16_t) ntohs (tpmm->is_inbound);
297  info.num_msg_pending = ntohl (tpmm->msgs_pending);
298  info.num_bytes_pending = ntohl (tpmm->bytes_pending);
299  info.receive_delay = GNUNET_TIME_absolute_ntoh (tpmm->delay);
300  info.session_timeout = GNUNET_TIME_absolute_ntoh (tpmm->timeout);
301  info.address = &addr;
302  addr.peer = tpmm->peer;
303  addr.address = (0 == paddr_len) ? NULL : paddr;
304  addr.address_length = paddr_len;
305  addr.transport_name = (0 == pname_len) ? NULL : pname;
306  addr.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE;
307  pm->cb (pm->cb_cls,
308  ps,
309  &ps->client_ctx,
310  &info);
311 
312  if (GNUNET_TRANSPORT_SS_DONE == ss)
313  {
314  GNUNET_break (NULL == ps->client_ctx);
317  wrap_id (
318  tpmm->session_id),
319  ps));
320  GNUNET_free (ps);
321  }
322 }
#define info
int GNUNET_CONTAINER_multihashmap32_get_multiple(struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, GNUNET_CONTAINER_MultiHashMapIterator32Callback it, void *it_cls)
Iterate over all entries in the map that match a particular key.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap32_put(struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
@ GNUNET_HELLO_ADDRESS_INFO_NONE
No additional information.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:737
GNUNET_TRANSPORT_SessionState
Possible states of a session in a plugin.
@ GNUNET_TRANSPORT_SS_INIT
The session was created (first call for each session object).
@ GNUNET_TRANSPORT_SS_DONE
Session is being torn down and about to disappear.
An address for communicating with a peer.
Information about a plugin's session.
struct GNUNET_TRANSPORT_PluginSession * ps
Result.
struct GNUNET_TIME_AbsoluteNBO timeout
When will this transport plugin session time out?
Definition: transport.h:644
uint16_t session_state
An enum GNUNET_TRANSPORT_SessionState in NBO.
Definition: transport.h:619
struct GNUNET_TIME_AbsoluteNBO delay
Until how long is this plugin currently blocked from reading?
Definition: transport.h:649
uint32_t bytes_pending
Number of bytes waiting for transmission.
Definition: transport.h:639
uint32_t msgs_pending
Number of messages waiting transmission.
Definition: transport.h:634
uint64_t session_id
Unique identifier for the session.
Definition: transport.h:659
struct GNUNET_PeerIdentity peer
Which peer is this connection for?
Definition: transport.h:654
int16_t is_inbound
GNUNET_YES if this is an inbound connection, GNUNET_NO if this is an outbound connection,...
Definition: transport.h:629
static void reconnect_plugin_ctx(struct GNUNET_TRANSPORT_PluginMonitor *pm)
Cut the existing connection and reconnect.
static int locate_by_id(void *cls, uint32_t key, void *value)
Locate a session entry.
static uint32_t wrap_id(uint64_t id)
Convert 64-bit session ID to 32-bit index for hash map.

References GNUNET_HELLO_Address::address, GNUNET_HELLO_Address::address_length, TransportPluginMonitorMessage::bytes_pending, GNUNET_TRANSPORT_PluginMonitor::cb, GNUNET_TRANSPORT_PluginMonitor::cb_cls, GNUNET_TRANSPORT_PluginSession::client_ctx, TransportPluginMonitorMessage::delay, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_multihashmap32_get_multiple(), GNUNET_CONTAINER_multihashmap32_put(), GNUNET_CONTAINER_multihashmap32_remove(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_free, GNUNET_HELLO_ADDRESS_INFO_NONE, GNUNET_new, GNUNET_TIME_absolute_ntoh(), GNUNET_TRANSPORT_SS_DONE, GNUNET_TRANSPORT_SS_INIT, GNUNET_YES, info, TransportPluginMonitorMessage::is_inbound, GNUNET_HELLO_Address::local_info, locate_by_id(), TransportPluginMonitorMessage::msgs_pending, GNUNET_HELLO_Address::peer, TransportPluginMonitorMessage::peer, TransportPluginMonitorMessage::plugin_address_len, TransportPluginMonitorMessage::plugin_name_len, pm, SearchContext::ps, reconnect_plugin_ctx(), TransportPluginMonitorMessage::session_id, GNUNET_TRANSPORT_PluginSession::session_id, SearchContext::session_id, TransportPluginMonitorMessage::session_state, GNUNET_TRANSPORT_PluginMonitor::sessions, TransportPluginMonitorMessage::timeout, GNUNET_HELLO_Address::transport_name, and wrap_id().

Here is the call graph for this function:

◆ handle_sync()

static void handle_sync ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Function called with sync responses from the service.

Parameters
clsour struct GNUNET_TRANSPORT_PluginMonitor *
msgmessage from the service

Definition at line 332 of file transport_api_monitor_plugins.c.

334 {
335  struct GNUNET_TRANSPORT_PluginMonitor *pm = cls;
336 
337  /* we are in sync, notify callback */
338  pm->cb (pm->cb_cls,
339  NULL,
340  NULL,
341  NULL);
342 }

References GNUNET_TRANSPORT_PluginMonitor::cb, GNUNET_TRANSPORT_PluginMonitor::cb_cls, and pm.

◆ mq_error_handler()

static void mq_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue.

Not every message queue implementation supports an error handler.

Parameters
clsclosure with the struct GNUNET_NSE_Handle *
errorerror code

Definition at line 355 of file transport_api_monitor_plugins.c.

357 {
358  struct GNUNET_TRANSPORT_PluginMonitor *pm = cls;
359 
361 }

References pm, and reconnect_plugin_ctx().

Referenced by do_plugin_connect().

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