GNUnet 0.21.1
peerstore_api_monitor.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_protocols.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 32 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 121 of file peerstore_api_monitor.c.

122{
123 struct GNUNET_PEERSTORE_Monitor *mc = cls;
124
125 if (NULL != mc->sync_cb)
126 mc->sync_cb (mc->sync_cb_cls);
127}
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 138 of file peerstore_api_monitor.c.

139{
140 /* we defer validation to #handle_result */
141 return GNUNET_OK;
142}
@ 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 152 of file peerstore_api_monitor.c.

153{
154 struct GNUNET_PEERSTORE_Monitor *mc = cls;
156
157 LOG (GNUNET_ERROR_TYPE_DEBUG, "Monitor received RecordMessage\n");
159 if (NULL == record)
160 {
161 mc->callback (mc->callback_cls,
162 NULL,
163 _ ("Received a malformed response from service."));
164 }
165 else
166 {
167 mc->callback (mc->callback_cls, record, NULL);
169 }
170}
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 185 of file peerstore_api_monitor.c.

186{
191 mc),
194 struct PeerstoreRecordMessage, mc),
196 };
197 struct GNUNET_MQ_Envelope *env;
199 size_t key_len = 0;
200 size_t ss_size = 0;
201
202 if (NULL != mc->mq)
203 {
204 GNUNET_MQ_destroy (mc->mq);
205 mc->error_cb (mc->error_cb_cls);
206 }
207 mc->mq = GNUNET_CLIENT_connect (mc->cfg,
208 "peerstore",
209 handlers,
211 mc);
212 if (NULL == mc->mq)
213 return;
214 if (NULL != mc->key)
215 key_len = strlen (mc->key) + 1;
216 if (NULL != mc->sub_system)
217 ss_size = strlen (mc->sub_system) + 1;
218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending MONITOR_START\n");
220 htons (key_len) + htons (ss_size),
222 sm->iterate_first = htons (mc->iterate_first);
223 if (NULL != mc->peer)
224 {
225 sm->peer = *mc->peer;
226 sm->peer_set = htons (GNUNET_YES);
227 }
228 if (NULL != mc->sub_system)
229 GNUNET_memcpy (&sm[1], mc->sub_system, ss_size);
230 sm->sub_system_size = htons (ss_size);
231 if (NULL != mc->key)
232 GNUNET_memcpy (((char*) &sm[1]) + ss_size, mc->key, key_len);
233 sm->key_size = htons (key_len);
234 GNUNET_MQ_send (mc->mq, env);
235}
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 176 of file peerstore_api_monitor.c.

177{
178 struct GNUNET_PEERSTORE_Monitor *mc = cls;
179
180 reconnect (mc);
181}
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: