GNUnet  0.11.x
Data Structures | Functions
transport_api_monitor_peers.c File Reference

montoring api for transport peer 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_peers.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_TRANSPORT_PeerMonitoringContext
 Context for iterating validation entries. More...
 

Functions

int GNUNET_TRANSPORT_is_connected (enum GNUNET_TRANSPORT_PeerState state)
 Check if a state is defined as connected. More...
 
const char * GNUNET_TRANSPORT_ps2s (enum GNUNET_TRANSPORT_PeerState state)
 Convert peer state to human-readable string. More...
 
static void do_peer_connect (void *cls)
 Task run to re-establish the connection. More...
 
static void reconnect_peer_ctx (struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx)
 Cut the existing connection and reconnect. More...
 
static void handle_response_end (void *cls, const struct GNUNET_MessageHeader *msg)
 Function called with responses from the service. More...
 
static int check_response (void *cls, const struct PeerIterateResponseMessage *pir_msg)
 Function called to check responses from the service. More...
 
static void handle_response (void *cls, const struct PeerIterateResponseMessage *pir_msg)
 Function called with 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_PeerMonitoringContextGNUNET_TRANSPORT_monitor_peers (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_PeerIdentity *peer, int one_shot, GNUNET_TRANSPORT_PeerIterateCallback peer_callback, void *peer_callback_cls)
 Return information about a specific peer or all peers currently known to transport service once or in monitoring mode. More...
 
void GNUNET_TRANSPORT_monitor_peers_cancel (struct GNUNET_TRANSPORT_PeerMonitoringContext *pic)
 Cancel request to monitor peers. More...
 

Detailed Description

montoring api for transport peer status

This api provides the ability to query the transport service about the connection status of a specific or all peers.

Calls back with information about peer(s) including address used, state and state timeout for peer requests.

Definition in file transport_api_monitor_peers.c.

Function Documentation

◆ do_peer_connect()

static void do_peer_connect ( void *  cls)
static

Task run to re-establish the connection.

Parameters
clsour struct GNUNET_TRANSPORT_PeerMonitoringContext *

Definition at line 358 of file transport_api_monitor_peers.c.

References GNUNET_TRANSPORT_PeerMonitoringContext::cfg, env, GNUNET_CLIENT_connect(), GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_TRANSPORT_PeerMonitoringContext::mq, mq_error_handler(), msg, GNUNET_TRANSPORT_PeerMonitoringContext::one_shot, PeerMonitorMessage::one_shot, GNUNET_TRANSPORT_PeerMonitoringContext::peer, PeerMonitorMessage::peer, GNUNET_TRANSPORT_PeerMonitoringContext::reconnect_task, and response.

Referenced by GNUNET_TRANSPORT_monitor_peers(), GNUNET_TRANSPORT_ps2s(), and reconnect_peer_ctx().

359 {
360  struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
365  pal_ctx),
366  GNUNET_MQ_hd_fixed_size (response_end,
368  struct GNUNET_MessageHeader,
369  pal_ctx),
371  };
372  struct PeerMonitorMessage *msg;
373  struct GNUNET_MQ_Envelope *env;
374 
375  pal_ctx->reconnect_task = NULL;
376  pal_ctx->mq = GNUNET_CLIENT_connect (pal_ctx->cfg,
377  "transport",
378  handlers,
380  pal_ctx);
381  if (NULL == pal_ctx->mq)
382  return;
383  env = GNUNET_MQ_msg (msg,
385  msg->one_shot = htonl (pal_ctx->one_shot);
386  msg->peer = pal_ctx->peer;
387  GNUNET_MQ_send (pal_ctx->mq,
388  env);
389 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
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
Context for iterating validation entries.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
Message from the transport service to the library containing information about a peer.
Definition: transport.h:537
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
struct GNUNET_PeerIdentity peer
Identity of the peer to monitor.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END
Response to GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END terminating list of replies...
struct GNUNET_MQ_Handle * mq
Connection to the service.
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE
Response to GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST request to iterate over all known addr...
Message from the library to the transport service asking for binary addresses known for a peer...
Definition: transport.h:470
struct GNUNET_PeerIdentity peer
The identity of the peer to look up.
Definition: transport.h:485
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST
Request to monitor addresses used by a peer or all peers.
Message handler for a specific message type.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
uint32_t one_shot
One shot call or continous replies?
Definition: transport.h:480
static struct MHD_Response * response
Our canonical response.
struct GNUNET_SCHEDULER_Task * reconnect_task
Task ID for reconnect.
Header for all communications.
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:353
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
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...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reconnect_peer_ctx()

static void reconnect_peer_ctx ( struct GNUNET_TRANSPORT_PeerMonitoringContext pal_ctx)
static

Cut the existing connection and reconnect.

Parameters
pal_ctxour context

Definition at line 191 of file transport_api_monitor_peers.c.

References GNUNET_TRANSPORT_PeerMonitoringContext::backoff, GNUNET_TRANSPORT_PeerMonitoringContext::cb, GNUNET_TRANSPORT_PeerMonitoringContext::cb_cls, do_peer_connect(), GNUNET_assert, GNUNET_MQ_destroy(), GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_STD_BACKOFF, GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_PS_NOT_CONNECTED, GNUNET_TRANSPORT_PeerMonitoringContext::mq, GNUNET_TRANSPORT_PeerMonitoringContext::one_shot, and GNUNET_TRANSPORT_PeerMonitoringContext::reconnect_task.

Referenced by handle_response_end(), and mq_error_handler().

192 {
193  GNUNET_assert (GNUNET_NO == pal_ctx->one_shot);
194  GNUNET_MQ_destroy (pal_ctx->mq);
195  pal_ctx->mq = NULL;
196  pal_ctx->cb (pal_ctx->cb_cls,
197  NULL,
198  NULL,
201  pal_ctx->backoff = GNUNET_TIME_STD_BACKOFF (pal_ctx->backoff);
204  pal_ctx);
205 }
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
GNUNET_TRANSPORT_PeerIterateCallback cb
Function to call with the binary address.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
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:1253
Fresh peer or completely disconnected.
struct GNUNET_MQ_Handle * mq
Connection to the service.
static void do_peer_connect(void *cls)
Task run to re-establish the connection.
#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.
struct GNUNET_SCHEDULER_Task * reconnect_task
Task ID for reconnect.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_response_end()

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

Function called with responses from the service.

Parameters
clsour struct GNUNET_TRANSPORT_PeerMonitoringContext *
msgmessage from service

Definition at line 215 of file transport_api_monitor_peers.c.

References GNUNET_TRANSPORT_PeerMonitoringContext::cb, GNUNET_TRANSPORT_PeerMonitoringContext::cb_cls, GNUNET_break, GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_monitor_peers_cancel(), GNUNET_TRANSPORT_PS_NOT_CONNECTED, GNUNET_TRANSPORT_PeerMonitoringContext::one_shot, and reconnect_peer_ctx().

217 {
218  struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
219 
220  if (pal_ctx->one_shot)
221  {
222  /* iteration finished */
223  pal_ctx->cb (pal_ctx->cb_cls,
224  NULL,
225  NULL,
229  return;
230  }
231  /* not quite what we expected, reconnect */
232  GNUNET_break (0);
233  reconnect_peer_ctx (pal_ctx);
234 }
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
GNUNET_TRANSPORT_PeerIterateCallback cb
Function to call with the binary address.
Context for iterating validation entries.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void GNUNET_TRANSPORT_monitor_peers_cancel(struct GNUNET_TRANSPORT_PeerMonitoringContext *pic)
Cancel request to monitor peers.
static void reconnect_peer_ctx(struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx)
Cut the existing connection and reconnect.
Fresh peer or completely disconnected.
Here is the call graph for this function:

◆ check_response()

static int check_response ( void *  cls,
const struct PeerIterateResponseMessage pir_msg 
)
static

Function called to check responses from the service.

Parameters
clsour struct GNUNET_TRANSPORT_PeerMonitoringContext *
pir_msgmessage with the human-readable address
Returns
GNUNET_OK if pir_msg is well-formed

Definition at line 245 of file transport_api_monitor_peers.c.

References PeerIterateResponseMessage::addrlen, GNUNET_break, GNUNET_OK, GNUNET_SYSERR, PeerIterateResponseMessage::header, PeerIterateResponseMessage::pluginlen, size, and GNUNET_MessageHeader::size.

247 {
248  uint16_t size = ntohs (pir_msg->header.size) - sizeof(*pir_msg);
249  size_t alen = ntohl (pir_msg->addrlen);
250  size_t tlen = ntohl (pir_msg->pluginlen);
251  const char *addr;
252  const char *transport_name;
253 
254  if (size != tlen + alen)
255  {
256  GNUNET_break (0);
257  return GNUNET_SYSERR;
258  }
259  if ((0 == tlen) && (0 == alen))
260  return GNUNET_OK;
261  if (0 == tlen)
262  {
263  GNUNET_break (0); /* This must not happen: address without plugin */
264  return GNUNET_SYSERR;
265  }
266  addr = (const char *) &pir_msg[1];
267  transport_name = &addr[alen];
268  if (transport_name[tlen - 1] != '\0')
269  {
270  GNUNET_break (0);
271  return GNUNET_SYSERR;
272  }
273  return GNUNET_OK;
274 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
uint32_t addrlen
Address length.
Definition: transport.h:572
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:67
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE.
Definition: transport.h:542
uint32_t pluginlen
Length of the plugin name.
Definition: transport.h:577

◆ handle_response()

static void handle_response ( void *  cls,
const struct PeerIterateResponseMessage pir_msg 
)
static

Function called with responses from the service.

Parameters
clsour struct GNUNET_TRANSPORT_PeerMonitoringContext *
msgmessage with the human-readable address

Definition at line 284 of file transport_api_monitor_peers.c.

References address, PeerIterateResponseMessage::addrlen, GNUNET_TRANSPORT_PeerMonitoringContext::cb, GNUNET_TRANSPORT_PeerMonitoringContext::cb_cls, GNUNET_HELLO_address_allocate(), GNUNET_HELLO_address_free, GNUNET_TIME_absolute_ntoh(), PeerIterateResponseMessage::local_address_info, PeerIterateResponseMessage::peer, PeerIterateResponseMessage::pluginlen, PeerIterateResponseMessage::state, PeerIterateResponseMessage::state_timeout, and GNUNET_HELLO_Address::transport_name.

286 {
287  struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
289  size_t alen = ntohl (pir_msg->addrlen);
290  size_t tlen = ntohl (pir_msg->pluginlen);
291  const char *addr;
292  const char *transport_name;
293 
294  if ((0 == tlen) &&
295  (0 == alen))
296  {
297  /* No address available */
298  pal_ctx->cb (pal_ctx->cb_cls,
299  &pir_msg->peer,
300  NULL,
301  ntohl (pir_msg->state),
303  return;
304  }
305  addr = (const char *) &pir_msg[1];
306  transport_name = &addr[alen];
307 
308  /* notify client */
309  address = GNUNET_HELLO_address_allocate (&pir_msg->peer,
310  transport_name,
311  addr,
312  alen,
313  ntohl (pir_msg->local_address_info));
314  pal_ctx->cb (pal_ctx->cb_cls,
315  &pir_msg->peer,
316  address,
317  ntohl (pir_msg->state),
319  GNUNET_HELLO_address_free (address);
320 }
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:673
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_allocate(const struct GNUNET_PeerIdentity *peer, const char *transport_name, const void *address, size_t address_length, enum GNUNET_HELLO_AddressInfo local_info)
Allocate an address struct.
Definition: address.c:73
GNUNET_TRANSPORT_PeerIterateCallback cb
Function to call with the binary address.
uint32_t local_address_info
Local info about the address.
Definition: transport.h:562
Context for iterating validation entries.
struct GNUNET_TIME_AbsoluteNBO state_timeout
Timeout for the state this peer is in.
Definition: transport.h:557
uint32_t addrlen
Address length.
Definition: transport.h:572
uint32_t state
State this peer is in as an enum GNUNET_TRANSPORT_PeerState
Definition: transport.h:567
const char * transport_name
Name of the transport plugin enabling the communication using this address.
An address for communicating with a peer.
struct GNUNET_PeerIdentity peer
Peer identity.
Definition: transport.h:552
uint32_t pluginlen
Length of the plugin name.
Definition: transport.h:577
static char * address
GNS address for this phone.
#define GNUNET_HELLO_address_free(addr)
Free an address.
Here is the call graph for this function:

◆ 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_TRANSPORT_PeerMonitoringContext *
errorerror code

Definition at line 332 of file transport_api_monitor_peers.c.

References GNUNET_TRANSPORT_PeerMonitoringContext::cb, GNUNET_TRANSPORT_PeerMonitoringContext::cb_cls, GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_monitor_peers_cancel(), GNUNET_TRANSPORT_PS_NOT_CONNECTED, GNUNET_TRANSPORT_PeerMonitoringContext::one_shot, and reconnect_peer_ctx().

Referenced by do_peer_connect().

334 {
335  struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
336 
337  if (pal_ctx->one_shot)
338  {
339  /* Disconnect */
340  pal_ctx->cb (pal_ctx->cb_cls,
341  NULL,
342  NULL,
346  return;
347  }
348  reconnect_peer_ctx (pal_ctx);
349 }
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
GNUNET_TRANSPORT_PeerIterateCallback cb
Function to call with the binary address.
Context for iterating validation entries.
void GNUNET_TRANSPORT_monitor_peers_cancel(struct GNUNET_TRANSPORT_PeerMonitoringContext *pic)
Cancel request to monitor peers.
static void reconnect_peer_ctx(struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx)
Cut the existing connection and reconnect.
Fresh peer or completely disconnected.
Here is the call graph for this function:
Here is the caller graph for this function: