GNUnet  0.10.x
Data Structures | Functions
transport_api2_monitor.c File Reference

implementation of the gnunet_transport_monitor_service.h API More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_transport_monitor_service.h"
#include "transport.h"
Include dependency graph for transport_api2_monitor.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_TRANSPORT_MonitorContext
 Opaque handle to the transport service for monitors. More...
 

Functions

static void reconnect (struct GNUNET_TRANSPORT_MonitorContext *mc)
 (re)connect our monitor to the transport service More...
 
static void send_start_monitor (struct GNUNET_TRANSPORT_MonitorContext *mc)
 Send message to the transport service about our montoring desire. More...
 
static void disconnect (struct GNUNET_TRANSPORT_MonitorContext *mc)
 Disconnect from the transport service. More...
 
static void error_handler (void *cls, enum GNUNET_MQ_Error error)
 Function called on MQ errors. More...
 
static int check_monitor_data (void *cls, const struct GNUNET_TRANSPORT_MonitorData *md)
 Transport service sends us information about what is going on. More...
 
static void handle_monitor_data (void *cls, const struct GNUNET_TRANSPORT_MonitorData *md)
 Transport service sends us information about what is going on. More...
 
static void handle_monitor_end (void *cls, const struct GNUNET_MessageHeader *me)
 One shot was requested, and transport service is done. More...
 
struct GNUNET_TRANSPORT_MonitorContextGNUNET_TRANSPORT_monitor (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_PeerIdentity *peer, int one_shot, GNUNET_TRANSPORT_MonitorCallback cb, void *cb_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_cancel (struct GNUNET_TRANSPORT_MonitorContext *mc)
 Cancel request to monitor peers. More...
 

Detailed Description

implementation of the gnunet_transport_monitor_service.h API

Author
Christian Grothoff

Definition in file transport_api2_monitor.c.

Function Documentation

◆ reconnect()

static void reconnect ( struct GNUNET_TRANSPORT_MonitorContext mc)
static

(re)connect our monitor to the transport service

Parameters
mchandle to reconnect

Definition at line 205 of file transport_api2_monitor.c.

References GNUNET_TRANSPORT_MonitorContext::cfg, error_handler(), GNUNET_CLIENT_connect(), GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_END, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_TRANSPORT_MonitorContext::mq, and send_start_monitor().

Referenced by error_handler(), GNUNET_TRANSPORT_monitor(), and handle_monitor_end().

206 {
208  { GNUNET_MQ_hd_var_size(monitor_data,
210  struct GNUNET_TRANSPORT_MonitorData,
211  mc),
212  GNUNET_MQ_hd_fixed_size(monitor_end,
214  struct GNUNET_MessageHeader,
215  mc),
217 
218  mc->mq =
219  GNUNET_CLIENT_connect(mc->cfg, "transport", handlers, &error_handler, mc);
220  if (NULL == mc->mq)
221  return;
222  send_start_monitor(mc);
223 }
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
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
static void error_handler(void *cls, enum GNUNET_MQ_Error error)
Function called on MQ errors.
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_DATA
Message sent to indicate to a monitor about events.
static void send_start_monitor(struct GNUNET_TRANSPORT_MonitorContext *mc)
Send message to the transport service about our montoring desire.
struct GNUNET_MQ_Handle * mq
Queue to talk to the transport service.
Message handler for a specific message type.
Header for all communications.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_END
Message sent to indicate to a monitor that a one-shot iteration over events is done.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_start_monitor()

static void send_start_monitor ( struct GNUNET_TRANSPORT_MonitorContext mc)
static

Send message to the transport service about our montoring desire.

Parameters
aiaddress to delete

Definition at line 85 of file transport_api2_monitor.c.

References env, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_TRANSPORT_MonitorContext::mq, GNUNET_TRANSPORT_MonitorContext::one_shot, and GNUNET_TRANSPORT_MonitorContext::peer.

Referenced by reconnect().

86 {
87  struct GNUNET_MQ_Envelope *env;
88  struct GNUNET_TRANSPORT_MonitorStart *smm;
89 
90  if (NULL == mc->mq)
91  return;
93  smm->one_shot = htonl((uint32_t)mc->one_shot);
94  smm->peer = mc->peer;
95  GNUNET_MQ_send(mc->mq, env);
96 }
#define GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START
Message sent to indicate to the transport that a monitor wants to observe certain events...
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
struct GNUNET_PeerIdentity peer
Peer we monitor, all zeros for "all".
int one_shot
GNUNET_YES to return the current state and then end.
struct GNUNET_MQ_Handle * mq
Queue to talk to the transport service.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ disconnect()

static void disconnect ( struct GNUNET_TRANSPORT_MonitorContext mc)
static

Disconnect from the transport service.

Parameters
mcservice to disconnect from

Definition at line 105 of file transport_api2_monitor.c.

References GNUNET_MQ_destroy(), and GNUNET_TRANSPORT_MonitorContext::mq.

Referenced by error_handler(), GNUNET_TRANSPORT_monitor_cancel(), and handle_monitor_end().

106 {
107  if (NULL == mc->mq)
108  return;
109  GNUNET_MQ_destroy(mc->mq);
110  mc->mq = NULL;
111 }
struct GNUNET_MQ_Handle * mq
Queue to talk to the transport service.
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:

◆ error_handler()

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

Function called on MQ errors.

Reconnects to the service.

Parameters
clsour struct GNUNET_TRANSPORT_MonitorContext *
errorwhat error happened?

Definition at line 121 of file transport_api2_monitor.c.

References disconnect(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, mc, and reconnect().

Referenced by reconnect().

122 {
123  struct GNUNET_TRANSPORT_MonitorContext *mc = cls;
124 
126  "MQ failure %d, reconnecting to transport service.\n",
127  error);
128  disconnect(mc);
129  /* TODO: maybe do this with exponential backoff/delay */
130  reconnect(mc);
131 }
Opaque handle to the transport service for monitors.
static void reconnect(struct GNUNET_TRANSPORT_MonitorContext *mc)
(re)connect our monitor to the transport service
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
#define GNUNET_log(kind,...)
static void disconnect(struct GNUNET_TRANSPORT_MonitorContext *mc)
Disconnect from the transport service.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_monitor_data()

static int check_monitor_data ( void *  cls,
const struct GNUNET_TRANSPORT_MonitorData *  md 
)
static

Transport service sends us information about what is going on.

Check if md is well-formed.

Parameters
clsour struct GNUNET_TRANSPORT_MonitorContext *
mdthe monitor data we got
Returns
GNUNET_OK if smt is well-formed

Definition at line 143 of file transport_api2_monitor.c.

References GNUNET_MQ_check_zero_termination, and GNUNET_OK.

144 {
145  (void)cls;
147  return GNUNET_OK;
148 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_MQ_check_zero_termination(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...

◆ handle_monitor_data()

static void handle_monitor_data ( void *  cls,
const struct GNUNET_TRANSPORT_MonitorData *  md 
)
static

Transport service sends us information about what is going on.

Parameters
clsour struct GNUNET_TRANSPORT_MonitorContext *
mdmonitor data

Definition at line 158 of file transport_api2_monitor.c.

References GNUNET_TRANSPORT_MonitorInformation::address, GNUNET_TRANSPORT_MonitorContext::cb, GNUNET_TRANSPORT_MonitorContext::cb_cls, GNUNET_TRANSPORT_MonitorInformation::cs, GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_relative_ntoh(), GNUNET_TRANSPORT_MonitorInformation::last_validation, mc, GNUNET_TRANSPORT_MonitorInformation::next_validation, GNUNET_TRANSPORT_MonitorInformation::nt, GNUNET_TRANSPORT_MonitorInformation::num_bytes_pending, GNUNET_TRANSPORT_MonitorInformation::num_msg_pending, GNUNET_TRANSPORT_MonitorInformation::rtt, and GNUNET_TRANSPORT_MonitorInformation::valid_until.

159 {
160  struct GNUNET_TRANSPORT_MonitorContext *mc = cls;
162 
163  mi.address = (const char *)&md[1];
164  mi.nt = (enum GNUNET_NetworkType)ntohl(md->nt);
165  mi.cs = (enum GNUNET_TRANSPORT_ConnectionStatus)ntohl(md->cs);
166  mi.num_msg_pending = ntohl(md->num_msg_pending);
167  mi.num_bytes_pending = ntohl(md->num_bytes_pending);
168  mi.last_validation = GNUNET_TIME_absolute_ntoh(md->last_validation);
169  mi.valid_until = GNUNET_TIME_absolute_ntoh(md->valid_until);
170  mi.next_validation = GNUNET_TIME_absolute_ntoh(md->next_validation);
171  mi.rtt = GNUNET_TIME_relative_ntoh(md->rtt);
172  mc->cb(mc->cb_cls, &md->peer, &mi);
173 }
Information about another peer's address.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:671
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:35
const char * address
Address we have for the peer, human-readable, 0-terminated, in UTF-8.
Opaque handle to the transport service for monitors.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:639
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
GNUNET_TRANSPORT_MonitorCallback cb
Function to call with monitor data.
GNUNET_TRANSPORT_ConnectionStatus
Possible states of a connection.
Here is the call graph for this function:

◆ handle_monitor_end()

static void handle_monitor_end ( void *  cls,
const struct GNUNET_MessageHeader me 
)
static

One shot was requested, and transport service is done.

Parameters
clsour struct GNUNET_TRANSPORT_MonitorContext *
meend message

Definition at line 183 of file transport_api2_monitor.c.

References GNUNET_TRANSPORT_MonitorContext::cb, GNUNET_TRANSPORT_MonitorContext::cb_cls, disconnect(), GNUNET_break, GNUNET_TRANSPORT_monitor_cancel(), GNUNET_YES, mc, GNUNET_TRANSPORT_MonitorContext::one_shot, and reconnect().

184 {
185  struct GNUNET_TRANSPORT_MonitorContext *mc = cls;
186 
187  if (GNUNET_YES != mc->one_shot)
188  {
189  GNUNET_break(0);
190  disconnect(mc);
191  reconnect(mc);
192  return;
193  }
194  mc->cb(mc->cb_cls, NULL, NULL);
196 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Opaque handle to the transport service for monitors.
int one_shot
GNUNET_YES to return the current state and then end.
static void reconnect(struct GNUNET_TRANSPORT_MonitorContext *mc)
(re)connect our monitor to the transport service
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
GNUNET_TRANSPORT_MonitorCallback cb
Function to call with monitor data.
void GNUNET_TRANSPORT_monitor_cancel(struct GNUNET_TRANSPORT_MonitorContext *mc)
Cancel request to monitor peers.
#define GNUNET_YES
Definition: gnunet_common.h:77
static void disconnect(struct GNUNET_TRANSPORT_MonitorContext *mc)
Disconnect from the transport service.
Here is the call graph for this function: