GNUnet 0.21.1
peerstore_api_monitor.c File Reference
#include "gnunet_common.h"
#include "gnunet_protocols.h"
#include "platform.h"
#include "gnunet_util_lib.h"
#include "peerstore.h"
#include "peerstore_common.h"
#include "gnunet_peerstore_service.h"
Include dependency graph for peerstore_api_monitor.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_PEERSTORE_Monitor
 Context for a monitor. More...
 

Macros

#define LOG(kind, ...)
 

Functions

static void handle_sync (void *cls, const struct GNUNET_MessageHeader *msg)
 
static int check_result (void *cls, const struct PeerstoreRecordMessage *msg)
 When a response for iterate request is received, check the message is well-formed. More...
 
static void handle_result (void *cls, const struct PeerstoreRecordMessage *msg)
 When a response to monitor is received. More...
 
static void reconnect (struct GNUNET_PEERSTORE_Monitor *mc)
 
static void mq_error_handler (void *cls, enum GNUNET_MQ_Error err)
 
struct GNUNET_PEERSTORE_MonitorGNUNET_PEERSTORE_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, int iterate_first, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_SCHEDULER_TaskCallback sync_cb, void *sync_cb_cls, GNUNET_PEERSTORE_Processor callback, void *callback_cls)
 Request watching a given key The monitoring can be filtered to contain only records matching peer and/or key. More...
 
void GNUNET_PEERSTORE_monitor_stop (struct GNUNET_PEERSTORE_Monitor *zm)
 Stop monitoring. More...
 
void GNUNET_PEERSTORE_monitor_next (struct GNUNET_PEERSTORE_Monitor *zm, uint64_t limit)
 Calls the monitor processor specified in GNUNET_PEERSTORE_monitor_start for the next record(s). More...
 

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)
Value:
GNUNET_log_from (kind, "peerstore-monitor-api", \
__VA_ARGS__)
#define GNUNET_log_from(kind, comp,...)

Definition at line 33 of file peerstore_api_monitor.c.

Function Documentation

◆ handle_sync()

static void handle_sync ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Definition at line 122 of file peerstore_api_monitor.c.

123{
124 struct GNUNET_PEERSTORE_Monitor *mc = cls;
125
126 if (NULL != mc->sync_cb)
127 mc->sync_cb (mc->sync_cb_cls);
128}
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
Context for a monitor.

References mc.

◆ check_result()

static int check_result ( void *  cls,
const struct PeerstoreRecordMessage msg 
)
static

When a response for iterate request is received, check the message is well-formed.

Parameters
clsa struct GNUNET_PEERSTORE_Handle *
msgmessage received

Definition at line 139 of file peerstore_api_monitor.c.

140{
141 /* we defer validation to #handle_result */
142 return GNUNET_OK;
143}
@ GNUNET_OK

References GNUNET_OK.

◆ handle_result()

static void handle_result ( void *  cls,
const struct PeerstoreRecordMessage msg 
)
static

When a response to monitor is received.

Parameters
clsa struct GNUNET_PEERSTORE_Handle *
msgmessage received

Definition at line 153 of file peerstore_api_monitor.c.

154{
155 struct GNUNET_PEERSTORE_Monitor *mc = cls;
157
158 LOG (GNUNET_ERROR_TYPE_DEBUG, "Monitor received RecordMessage\n");
160 if (NULL == record)
161 {
162 mc->callback (mc->callback_cls,
163 NULL,
164 _ ("Received a malformed response from service."));
165 }
166 else
167 {
168 mc->callback (mc->callback_cls, record, NULL);
170 }
171}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
@ GNUNET_ERROR_TYPE_DEBUG
#define LOG(kind,...)
struct GNUNET_PEERSTORE_Record * PEERSTORE_parse_record_message(const struct PeerstoreRecordMessage *srm)
Parses a message carrying a record.
void PEERSTORE_destroy_record(struct GNUNET_PEERSTORE_Record *record)
Free any memory allocated for this record.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
Single PEERSTORE record.

References _, GNUNET_ERROR_TYPE_DEBUG, LOG, mc, msg, PEERSTORE_destroy_record(), PEERSTORE_parse_record_message(), and record().

Here is the call graph for this function:

◆ reconnect()

static void reconnect ( struct GNUNET_PEERSTORE_Monitor mc)
static

Definition at line 186 of file peerstore_api_monitor.c.

187{
192 mc),
195 struct PeerstoreRecordMessage, mc),
197 };
198 struct GNUNET_MQ_Envelope *env;
200 size_t key_len = 0;
201 size_t ss_size = 0;
202
203 if (NULL != mc->mq)
204 {
205 GNUNET_MQ_destroy (mc->mq);
206 mc->error_cb (mc->error_cb_cls);
207 }
208 mc->mq = GNUNET_CLIENT_connect (mc->cfg,
209 "peerstore",
210 handlers,
212 mc);
213 if (NULL == mc->mq)
214 return;
215 if (NULL != mc->key)
216 key_len = strlen (mc->key) + 1;
217 if (NULL != mc->sub_system)
218 ss_size = strlen (mc->sub_system) + 1;
219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending MONITOR_START\n");
221 htons (key_len) + htons (ss_size),
223 sm->iterate_first = htons (mc->iterate_first);
224 if (NULL != mc->peer)
225 {
226 sm->peer = *mc->peer;
227 sm->peer_set = htons (GNUNET_YES);
228 }
229 if (NULL != mc->sub_system)
230 GNUNET_memcpy (&sm[1], mc->sub_system, ss_size);
231 sm->sub_system_size = htons (ss_size);
232 if (NULL != mc->key)
233 GNUNET_memcpy (((char*) &sm[1]) + ss_size, mc->key, key_len);
234 sm->key_size = htons (key_len);
235 GNUNET_MQ_send (mc->mq, env);
236}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static int result
Global testing status.
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:1057
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_YES
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:304
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:63
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#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:683
#define GNUNET_MESSAGE_TYPE_PEERSTORE_MONITOR_SYNC
Monitor sync.
#define GNUNET_MESSAGE_TYPE_PEERSTORE_MONITOR_START
Monitor request.
#define GNUNET_MESSAGE_TYPE_PEERSTORE_RECORD
Record result message.
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error err)
Message handler for a specific message type.
Header for all communications.
Iteration start message.
Definition: peerstore.h:140
uint16_t iterate_first
GNUNET_YES if iterate first, GNUNET_NO otherwise
Definition: peerstore.h:176
struct GNUNET_PeerIdentity peer
Peer Identity.
Definition: peerstore.h:149
uint16_t peer_set
GNUNET_YES if peer id value set, GNUNET_NO otherwise
Definition: peerstore.h:165
uint16_t key_size
Size of the key string Allocated at position 1 after this struct.
Definition: peerstore.h:160
uint16_t sub_system_size
Size of the sub_system string Allocated at position 0 after this struct.
Definition: peerstore.h:171
Message carrying a PEERSTORE record message.
Definition: peerstore.h:38

References env, GNUNET_CLIENT_connect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_PEERSTORE_MONITOR_START, GNUNET_MESSAGE_TYPE_PEERSTORE_MONITOR_SYNC, GNUNET_MESSAGE_TYPE_PEERSTORE_RECORD, GNUNET_MQ_destroy(), GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_YES, handlers, PeerstoreMonitorStartMessage::iterate_first, PeerstoreMonitorStartMessage::key_size, mc, mq_error_handler(), PeerstoreMonitorStartMessage::peer, PeerstoreMonitorStartMessage::peer_set, result, and PeerstoreMonitorStartMessage::sub_system_size.

Referenced by GNUNET_PEERSTORE_monitor_start(), and mq_error_handler().

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

◆ mq_error_handler()

static void mq_error_handler ( void *  cls,
enum GNUNET_MQ_Error  err 
)
static

Definition at line 177 of file peerstore_api_monitor.c.

178{
179 struct GNUNET_PEERSTORE_Monitor *mc = cls;
180
181 reconnect (mc);
182}
static void reconnect(struct GNUNET_PEERSTORE_Monitor *mc)

References mc, and reconnect().

Referenced by reconnect().

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