GNUnet  0.10.x
Data Structures | Functions
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 111 of file core_api_monitor_peers.c.

References GNUNET_CORE_MonitorHandle::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(), GNUNET_CORE_MonitorHandle::mq, msg, GNUNET_CORE_MonitorHandle::peer_cb, and GNUNET_CORE_MonitorHandle::peer_cb_cls.

Referenced by GNUNET_CORE_monitor_start(), and handle_mq_error().

112 {
114  { GNUNET_MQ_hd_fixed_size(receive_info,
116  struct MonitorNotifyMessage,
117  mh),
119  struct GNUNET_MQ_Envelope *env;
120  struct GNUNET_MessageHeader *msg;
121 
122  if (NULL != mh->mq)
123  GNUNET_MQ_destroy(mh->mq);
124  /* FIXME: use backoff? */
125  mh->mq =
126  GNUNET_CLIENT_connect(mh->cfg, "core", handlers, &handle_mq_error, mh);
127  if (NULL == mh->mq)
128  return;
129  /* notify callback about reconnect */
130  if (NULL != mh->peer_cb)
131  mh->peer_cb(mh->peer_cb_cls,
132  NULL,
136  GNUNET_MQ_send(mh->mq, env);
137 }
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
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
struct GNUNET_MQ_Handle * mq
Our connection to the service.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS
Request for connection monitoring from CORE service.
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
Message handler for a specific message type.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
void * peer_cb_cls
Closure for peer_cb.
GNUNET_CORE_MonitorCallback peer_cb
Function called with the peer.
Header for all communications.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:821
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
Message sent by the service to monitor clients to notify them about a peer changing status...
Definition: core.h:294
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
This is not a state in a peer's state machine, but a special value used with the GNUNET_CORE_MonitorC...
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...
#define GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY
Reply for monitor by CORE service.
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 77 of file core_api_monitor_peers.c.

References mh, and reconnect().

Referenced by reconnect().

78 {
79  struct GNUNET_CORE_MonitorHandle *mh = cls;
80 
81  (void)error;
82  reconnect(mh);
83 }
static void reconnect(struct GNUNET_CORE_MonitorHandle *mh)
Protocol error, reconnect to CORE service and notify client.
static struct GNUNET_CADET_Handle * mh
Cadet handle.
Definition: gnunet-cadet.c:92
Handle to a CORE monitoring operation.
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 93 of file core_api_monitor_peers.c.

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

94 {
95  struct GNUNET_CORE_MonitorHandle *mh = cls;
96 
97  mh->peer_cb(mh->peer_cb_cls,
98  &mon_message->peer,
99  (enum GNUNET_CORE_KxState)ntohl(mon_message->state),
100  GNUNET_TIME_absolute_ntoh(mon_message->timeout));
101 }
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:671
static struct GNUNET_CADET_Handle * mh
Cadet handle.
Definition: gnunet-cadet.c:92
Handle to a CORE monitoring operation.
struct GNUNET_TIME_AbsoluteNBO timeout
How long will we stay in this state (if nothing else happens)?
Definition: core.h:313
GNUNET_CORE_KxState
State machine for our P2P encryption handshake.
void * peer_cb_cls
Closure for peer_cb.
uint32_t state
New peer state, an enum GNUNET_CORE_KxState in NBO.
Definition: core.h:303
GNUNET_CORE_MonitorCallback peer_cb
Function called with the peer.
struct GNUNET_PeerIdentity peer
Identity of the peer.
Definition: core.h:308
Here is the call graph for this function: