GNUnet  0.10.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 345 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().

346 {
347  struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
352  pal_ctx),
353  GNUNET_MQ_hd_fixed_size (response_end,
355  struct GNUNET_MessageHeader,
356  pal_ctx),
358  };
359  struct PeerMonitorMessage *msg;
360  struct GNUNET_MQ_Envelope *env;
361 
362  pal_ctx->reconnect_task = NULL;
363  pal_ctx->mq = GNUNET_CLIENT_connect (pal_ctx->cfg,
364  "transport",
365  handlers,
367  pal_ctx);
368  if (NULL == pal_ctx->mq)
369  return;
370  env = GNUNET_MQ_msg (msg,
372  msg->one_shot = htonl (pal_ctx->one_shot);
373  msg->peer = pal_ctx->peer;
374  GNUNET_MQ_send (pal_ctx->mq,
375  env);
376 }
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:901
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:552
#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:485
struct GNUNET_PeerIdentity peer
The identity of the peer to look up.
Definition: transport.h:500
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:495
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 177 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().

178 {
179  GNUNET_assert (GNUNET_NO == pal_ctx->one_shot);
180  GNUNET_MQ_destroy (pal_ctx->mq);
181  pal_ctx->mq = NULL;
182  pal_ctx->cb (pal_ctx->cb_cls,
183  NULL,
184  NULL,
187  pal_ctx->backoff = GNUNET_TIME_STD_BACKOFF (pal_ctx->backoff);
190  pal_ctx);
191 }
#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:81
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:1246
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 201 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().

203 {
204  struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
205 
206  if (pal_ctx->one_shot)
207  {
208  /* iteration finished */
209  pal_ctx->cb (pal_ctx->cb_cls,
210  NULL,
211  NULL,
215  return;
216  }
217  /* not quite what we expected, reconnect */
218  GNUNET_break (0);
219  reconnect_peer_ctx (pal_ctx);
220 }
#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 231 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.

233 {
234  uint16_t size = ntohs (pir_msg->header.size) - sizeof (*pir_msg);
235  size_t alen = ntohl (pir_msg->addrlen);
236  size_t tlen = ntohl (pir_msg->pluginlen);
237  const char *addr;
238  const char *transport_name;
239 
240  if (size != tlen + alen)
241  {
242  GNUNET_break (0);
243  return GNUNET_SYSERR;
244  }
245  if ( (0 == tlen) && (0 == alen) )
246  return GNUNET_OK;
247  if (0 == tlen)
248  {
249  GNUNET_break (0); /* This must not happen: address without plugin */
250  return GNUNET_SYSERR;
251  }
252  addr = (const char *) &pir_msg[1];
253  transport_name = &addr[alen];
254  if (transport_name[tlen - 1] != '\0')
255  {
256  GNUNET_break (0);
257  return GNUNET_SYSERR;
258  }
259  return GNUNET_OK;
260 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
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:587
#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:79
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:557
uint32_t pluginlen
Length of the plugin name.
Definition: transport.h:592

◆ 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 270 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.

272 {
273  struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
275  size_t alen = ntohl (pir_msg->addrlen);
276  size_t tlen = ntohl (pir_msg->pluginlen);
277  const char *addr;
278  const char *transport_name;
279 
280  if ( (0 == tlen) &&
281  (0 == alen) )
282  {
283  /* No address available */
284  pal_ctx->cb (pal_ctx->cb_cls,
285  &pir_msg->peer,
286  NULL,
287  ntohl(pir_msg->state),
289  return;
290  }
291  addr = (const char *) &pir_msg[1];
292  transport_name = &addr[alen];
293 
294  /* notify client */
295  address = GNUNET_HELLO_address_allocate (&pir_msg->peer,
296  transport_name,
297  addr,
298  alen,
299  ntohl (pir_msg->local_address_info));
300  pal_ctx->cb (pal_ctx->cb_cls,
301  &pir_msg->peer,
302  address,
303  ntohl (pir_msg->state),
305  GNUNET_HELLO_address_free (address);
306 }
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:670
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:577
Context for iterating validation entries.
struct GNUNET_TIME_AbsoluteNBO state_timeout
Timeout for the state this peer is in.
Definition: transport.h:572
uint32_t addrlen
Address length.
Definition: transport.h:587
uint32_t state
State this peer is in as an enum GNUNET_TRANSPORT_PeerState
Definition: transport.h:582
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:567
uint32_t pluginlen
Length of the plugin name.
Definition: transport.h:592
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 319 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().

321 {
322  struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
323 
324  if (pal_ctx->one_shot)
325  {
326  /* Disconnect */
327  pal_ctx->cb (pal_ctx->cb_cls,
328  NULL,
329  NULL,
333  return;
334  }
335  reconnect_peer_ctx (pal_ctx);
336 }
#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: