GNUnet 0.22.2
core_api_monitor_peers.c File Reference

implementation of the peer_iterate function More...

#include "platform.h"
#include "gnunet_core_service.h"
#include "core.h"
Include dependency graph for core_api_monitor_peers.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_CORE_MonitorHandle
 Handle to a CORE monitoring operation. More...
 

Functions

static void reconnect (struct GNUNET_CORE_MonitorHandle *mh)
 Protocol error, reconnect to CORE service and notify client. More...
 
static void handle_mq_error (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...
 
static void handle_receive_info (void *cls, const struct MonitorNotifyMessage *mon_message)
 Receive reply from CORE service with information about a peer. More...
 
struct GNUNET_CORE_MonitorHandleGNUNET_CORE_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CORE_MonitorCallback peer_cb, void *peer_cb_cls)
 Monitor connectivity and KX status of all peers known to CORE. More...
 
void GNUNET_CORE_monitor_stop (struct GNUNET_CORE_MonitorHandle *mh)
 Stop monitoring CORE activity. More...
 

Detailed Description

implementation of the peer_iterate function

Author
Christian Grothoff
Nathan Evans

Definition in file core_api_monitor_peers.c.

Function Documentation

◆ reconnect()

static void reconnect ( struct GNUNET_CORE_MonitorHandle mh)
static

Protocol error, reconnect to CORE service and notify client.

Parameters
mhmonitoring session to reconnect to CORE

Definition at line 112 of file core_api_monitor_peers.c.

113{
115 { GNUNET_MQ_hd_fixed_size (receive_info,
118 mh),
120 struct GNUNET_MQ_Envelope *env;
122
123 if (NULL != mh->mq)
125 /* FIXME: use backoff? */
126 mh->mq =
128 if (NULL == mh->mq)
129 return;
130 /* notify callback about reconnect */
131 if (NULL != mh->peer_cb)
132 mh->peer_cb (mh->peer_cb_cls,
133 NULL,
138}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static void handle_mq_error(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
static struct GNUNET_CADET_Handle * mh
Cadet handle.
Definition: gnunet-cadet.c:92
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:1060
@ GNUNET_CORE_KX_CORE_DISCONNECT
This is not a state in a peer's state machine, but a special value used with the GNUNET_CORE_MonitorC...
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:305
#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:76
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:700
#define GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS
Request for connection monitoring from CORE service.
#define GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY
Reply for monitor by CORE service.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration given by the client, in case of reconnection.
Definition: cadet_api.c:63
struct GNUNET_MQ_Handle * mq
Message queue.
Definition: cadet_api.c:43
Message handler for a specific message type.
Header for all communications.
Message sent by the service to monitor clients to notify them about a peer changing status.
Definition: core.h:301

References GNUNET_CADET_Handle::cfg, env, GNUNET_CLIENT_connect(), GNUNET_CORE_KX_CORE_DISCONNECT, GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY, GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS, GNUNET_MQ_destroy(), GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_TIME_UNIT_FOREVER_ABS, handle_mq_error(), handlers, mh, GNUNET_CADET_Handle::mq, and msg.

Referenced by GNUNET_CORE_monitor_start(), and handle_mq_error().

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

◆ handle_mq_error()

static void handle_mq_error ( 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, a struct GNUNET_CORE_MonitorHandle *
errorerror code

Definition at line 78 of file core_api_monitor_peers.c.

79{
80 struct GNUNET_CORE_MonitorHandle *mh = cls;
81
82 (void) error;
83 reconnect (mh);
84}
static void reconnect(struct GNUNET_CORE_MonitorHandle *mh)
Protocol error, reconnect to CORE service and notify client.
Handle to a CORE monitoring operation.

References mh, and reconnect().

Referenced by reconnect().

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

◆ handle_receive_info()

static void handle_receive_info ( void *  cls,
const struct MonitorNotifyMessage mon_message 
)
static

Receive reply from CORE service with information about a peer.

Parameters
clsour struct GNUNET_CORE_MonitorHandle *
mon_messagemonitor message

Definition at line 94 of file core_api_monitor_peers.c.

95{
96 struct GNUNET_CORE_MonitorHandle *mh = cls;
97
98 mh->peer_cb (mh->peer_cb_cls,
99 &mon_message->peer,
100 ntohl (mon_message->state),
101 GNUNET_TIME_absolute_ntoh (mon_message->timeout));
102}
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:741
struct GNUNET_PeerIdentity peer
Identity of the peer.
Definition: core.h:315
uint32_t state
New peer state, an enum GNUNET_CORE_KxState in NBO.
Definition: core.h:310
struct GNUNET_TIME_AbsoluteNBO timeout
How long will we stay in this state (if nothing else happens)?
Definition: core.h:320

References GNUNET_TIME_absolute_ntoh(), mh, MonitorNotifyMessage::peer, MonitorNotifyMessage::state, and MonitorNotifyMessage::timeout.

Here is the call graph for this function: