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 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:900
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:523
#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:458
struct GNUNET_PeerIdentity peer
The identity of the peer to look up.
Definition: transport.h:472
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:467
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:351
#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 190 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().

191 {
192  GNUNET_assert(GNUNET_NO == pal_ctx->one_shot);
193  GNUNET_MQ_destroy(pal_ctx->mq);
194  pal_ctx->mq = NULL;
195  pal_ctx->cb(pal_ctx->cb_cls,
196  NULL,
197  NULL,
200  pal_ctx->backoff = GNUNET_TIME_STD_BACKOFF(pal_ctx->backoff);
203  pal_ctx);
204 }
#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:1237
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:821
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 214 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().

216 {
217  struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
218 
219  if (pal_ctx->one_shot)
220  {
221  /* iteration finished */
222  pal_ctx->cb(pal_ctx->cb_cls,
223  NULL,
224  NULL,
228  return;
229  }
230  /* not quite what we expected, reconnect */
231  GNUNET_break(0);
232  reconnect_peer_ctx(pal_ctx);
233 }
#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 244 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.

246 {
247  uint16_t size = ntohs(pir_msg->header.size) - sizeof(*pir_msg);
248  size_t alen = ntohl(pir_msg->addrlen);
249  size_t tlen = ntohl(pir_msg->pluginlen);
250  const char *addr;
251  const char *transport_name;
252 
253  if (size != tlen + alen)
254  {
255  GNUNET_break(0);
256  return GNUNET_SYSERR;
257  }
258  if ((0 == tlen) && (0 == alen))
259  return GNUNET_OK;
260  if (0 == tlen)
261  {
262  GNUNET_break(0); /* This must not happen: address without plugin */
263  return GNUNET_SYSERR;
264  }
265  addr = (const char *)&pir_msg[1];
266  transport_name = &addr[alen];
267  if (transport_name[tlen - 1] != '\0')
268  {
269  GNUNET_break(0);
270  return GNUNET_SYSERR;
271  }
272  return GNUNET_OK;
273 }
#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:557
#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:66
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE.
Definition: transport.h:527
uint32_t pluginlen
Length of the plugin name.
Definition: transport.h:562

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

285 {
286  struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
288  size_t alen = ntohl(pir_msg->addrlen);
289  size_t tlen = ntohl(pir_msg->pluginlen);
290  const char *addr;
291  const char *transport_name;
292 
293  if ((0 == tlen) &&
294  (0 == alen))
295  {
296  /* No address available */
297  pal_ctx->cb(pal_ctx->cb_cls,
298  &pir_msg->peer,
299  NULL,
300  ntohl(pir_msg->state),
302  return;
303  }
304  addr = (const char *)&pir_msg[1];
305  transport_name = &addr[alen];
306 
307  /* notify client */
308  address = GNUNET_HELLO_address_allocate(&pir_msg->peer,
309  transport_name,
310  addr,
311  alen,
312  ntohl(pir_msg->local_address_info));
313  pal_ctx->cb(pal_ctx->cb_cls,
314  &pir_msg->peer,
315  address,
316  ntohl(pir_msg->state),
318  GNUNET_HELLO_address_free(address);
319 }
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:671
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:547
Context for iterating validation entries.
struct GNUNET_TIME_AbsoluteNBO state_timeout
Timeout for the state this peer is in.
Definition: transport.h:542
uint32_t addrlen
Address length.
Definition: transport.h:557
uint32_t state
State this peer is in as an enum GNUNET_TRANSPORT_PeerState
Definition: transport.h:552
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:537
uint32_t pluginlen
Length of the plugin name.
Definition: transport.h:562
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: