GNUnet  0.17.6
Data Structures | Functions
namestore_api_monitor.c File Reference

API to monitor changes in the NAMESTORE. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_crypto_lib.h"
#include "gnunet_constants.h"
#include "gnunet_dnsparser_lib.h"
#include "gnunet_arm_service.h"
#include "gnunet_signatures.h"
#include "gnunet_namestore_service.h"
#include "namestore.h"
Include dependency graph for namestore_api_monitor.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_NAMESTORE_ZoneMonitor
 Handle for a monitoring activity. More...
 

Functions

static void reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm)
 Reconnect to the namestore service. More...
 
static void handle_sync (void *cls, const struct GNUNET_MessageHeader *msg)
 Handle SYNC message from the namestore service. More...
 
static int check_result (void *cls, const struct RecordResultMessage *lrm)
 We've received a notification about a change to our zone. More...
 
static void handle_result (void *cls, const struct RecordResultMessage *lrm)
 We've received a notification about a change to our zone. More...
 
static void mq_error_handler (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...
 
struct GNUNET_NAMESTORE_ZoneMonitorGNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_IDENTITY_PrivateKey *zone, int iterate_first, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor monitor, void *monitor_cls, GNUNET_SCHEDULER_TaskCallback sync_cb, void *sync_cb_cls)
 
struct GNUNET_NAMESTORE_ZoneMonitorGNUNET_NAMESTORE_zone_monitor_start2 (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_IDENTITY_PrivateKey *zone, int iterate_first, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordSetMonitor monitor, void *monitor_cls, GNUNET_SCHEDULER_TaskCallback sync_cb, void *sync_cb_cls, enum GNUNET_GNSRECORD_Filter filter)
 Begin monitoring a zone for changes. More...
 
void GNUNET_NAMESTORE_zone_monitor_next (struct GNUNET_NAMESTORE_ZoneMonitor *zm, uint64_t limit)
 Calls the monitor processor specified in GNUNET_NAMESTORE_zone_monitor_start for the next record(s). More...
 
void GNUNET_NAMESTORE_zone_monitor_stop (struct GNUNET_NAMESTORE_ZoneMonitor *zm)
 Stop monitoring a zone for changes. More...
 

Detailed Description

API to monitor changes in the NAMESTORE.

Author
Christian Grothoff

Definition in file namestore_api_monitor.c.

Function Documentation

◆ reconnect()

static void reconnect ( struct GNUNET_NAMESTORE_ZoneMonitor zm)
static

Reconnect to the namestore service.

Parameters
zmmonitor to reconnect

Definition at line 259 of file namestore_api_monitor.c.

260 {
262  { GNUNET_MQ_hd_fixed_size (sync,
264  struct GNUNET_MessageHeader,
265  zm),
268  struct RecordResultMessage,
269  zm),
271  struct GNUNET_MQ_Envelope *env;
272  struct ZoneMonitorStartMessage *sm;
273 
274  if (NULL != zm->mq)
275  {
278  }
280  "namestore",
281  handlers,
283  zm);
284  if (NULL == zm->mq)
285  return;
287  sm->iterate_first = htonl (zm->iterate_first);
288  sm->zone = zm->zone;
289  sm->filter = htons ((uint16_t) zm->filter);
290  GNUNET_MQ_send (zm->mq, env);
291 }
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
static struct GNUNET_NAMESTORE_ZoneMonitor * zm
Monitor handle.
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:1055
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:302
#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:71
#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:685
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT
Service to client: here is a (plaintext) record you requested.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START
Client to service: start monitoring (yields sequence of "ZONE_ITERATION_RESPONSES" — forever).
#define GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC
Service to client: you're now in sync.
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
Message handler for a specific message type.
Header for all communications.
struct GNUNET_IDENTITY_PrivateKey zone
Monitored zone.
struct GNUNET_MQ_Handle * mq
Handle to namestore service.
void * error_cb_cls
Closure for error_cb.
enum GNUNET_GNSRECORD_Filter filter
Record set filter for this monitor.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration (to reconnect).
int iterate_first
Do we first iterate over all existing records?
GNUNET_SCHEDULER_TaskCallback error_cb
Function to call on errors.
Record is returned from the namestore (as authority).
Definition: namestore.h:283
Start monitoring a zone.
Definition: namestore.h:379
uint32_t iterate_first
GNUNET_YES to first iterate over all records, GNUNET_NO to only monitor changes.o
Definition: namestore.h:389
uint16_t filter
Record set filter control flags.
Definition: namestore.h:395
struct GNUNET_IDENTITY_PrivateKey zone
Zone key.
Definition: namestore.h:405

References GNUNET_NAMESTORE_ZoneMonitor::cfg, env, GNUNET_NAMESTORE_ZoneMonitor::error_cb, GNUNET_NAMESTORE_ZoneMonitor::error_cb_cls, ZoneMonitorStartMessage::filter, GNUNET_NAMESTORE_ZoneMonitor::filter, GNUNET_CLIENT_connect(), GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC, GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT, GNUNET_MQ_destroy(), GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg, GNUNET_MQ_send(), handlers, ZoneMonitorStartMessage::iterate_first, GNUNET_NAMESTORE_ZoneMonitor::iterate_first, GNUNET_NAMESTORE_ZoneMonitor::mq, mq_error_handler(), result, zm, ZoneMonitorStartMessage::zone, and GNUNET_NAMESTORE_ZoneMonitor::zone.

Referenced by GNUNET_NAMESTORE_zone_monitor_start(), GNUNET_NAMESTORE_zone_monitor_start2(), and mq_error_handler().

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

◆ handle_sync()

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

Handle SYNC message from the namestore service.

Parameters
clsthe monitor
msgthe sync message

Definition at line 120 of file namestore_api_monitor.c.

121 {
122  struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
123 
124  (void) cls;
125  (void) msg;
126  if (NULL != zm->sync_cb)
127  zm->sync_cb (zm->sync_cb_cls);
128 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
Handle for a monitoring activity.
GNUNET_SCHEDULER_TaskCallback sync_cb
Function called when we've synchronized.
void * sync_cb_cls
Closure for sync_cb.

References msg, GNUNET_NAMESTORE_ZoneMonitor::sync_cb, GNUNET_NAMESTORE_ZoneMonitor::sync_cb_cls, and zm.

◆ check_result()

static int check_result ( void *  cls,
const struct RecordResultMessage lrm 
)
static

We've received a notification about a change to our zone.

Check that it is well-formed.

Parameters
clsthe zone monitor handle
lrmthe message from the service.

Definition at line 139 of file namestore_api_monitor.c.

140 {
141  struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
142  size_t lrm_len;
143  size_t exp_lrm_len;
144  size_t name_len;
145  size_t rd_len;
146  unsigned rd_count;
147  const char *name_tmp;
148  const char *rd_ser_tmp;
149 
150  (void) cls;
151  if ((0 != GNUNET_memcmp (&lrm->private_key, &zm->zone)) &&
152  (GNUNET_NO == GNUNET_is_zero (&zm->zone)))
153  {
154  GNUNET_break (0);
155  return GNUNET_SYSERR;
156  }
157  lrm_len = ntohs (lrm->gns_header.header.size);
158  rd_len = ntohs (lrm->rd_len);
159  rd_count = ntohs (lrm->rd_count);
160  name_len = ntohs (lrm->name_len);
161  if (name_len > MAX_NAME_LEN)
162  {
163  GNUNET_break (0);
164  return GNUNET_SYSERR;
165  }
166  exp_lrm_len = sizeof(struct RecordResultMessage) + name_len + rd_len;
167  if (lrm_len != exp_lrm_len)
168  {
169  GNUNET_break (0);
170  return GNUNET_SYSERR;
171  }
172  if (0 == name_len)
173  {
174  GNUNET_break (0);
175  return GNUNET_SYSERR;
176  }
177  name_tmp = (const char *) &lrm[1];
178  if (name_tmp[name_len - 1] != '\0')
179  {
180  GNUNET_break (0);
181  return GNUNET_SYSERR;
182  }
183  rd_ser_tmp = (const char *) &name_tmp[name_len];
184  {
185  struct GNUNET_GNSRECORD_Data rd[rd_count];
186 
187  if (GNUNET_OK !=
188  GNUNET_GNSRECORD_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd))
189  {
190  GNUNET_break (0);
191  return GNUNET_SYSERR;
192  }
193  }
194  return GNUNET_OK;
195 }
int GNUNET_GNSRECORD_records_deserialize(size_t len, const char *src, unsigned int rd_count, struct GNUNET_GNSRECORD_Data *dest)
Deserialize the given records to the given destination.
#define GNUNET_is_zero(a)
Check that memory in a is all zeros.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
@ GNUNET_OK
Definition: gnunet_common.h:99
@ GNUNET_NO
Definition: gnunet_common.h:98
@ GNUNET_SYSERR
Definition: gnunet_common.h:97
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define MAX_NAME_LEN
Maximum length of any name, including 0-termination.
Definition: namecache.h:33
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
struct GNUNET_MessageHeader header
header.type will be GNUNET_MESSAGE_TYPE_NAMESTORE_* header.size will be message size
Definition: namestore.h:46
uint16_t rd_len
Length of serialized record data.
Definition: namestore.h:303
uint16_t name_len
Name length.
Definition: namestore.h:298
struct GNUNET_IDENTITY_PrivateKey private_key
The private key of the authority.
Definition: namestore.h:318
uint16_t rd_count
Number of records contained.
Definition: namestore.h:308
struct GNUNET_NAMESTORE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT.
Definition: namestore.h:287

References RecordResultMessage::gns_header, GNUNET_break, GNUNET_GNSRECORD_records_deserialize(), GNUNET_is_zero, GNUNET_memcmp, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_NAMESTORE_Header::header, MAX_NAME_LEN, RecordResultMessage::name_len, RecordResultMessage::private_key, RecordResultMessage::rd_count, RecordResultMessage::rd_len, GNUNET_MessageHeader::size, zm, and GNUNET_NAMESTORE_ZoneMonitor::zone.

Here is the call graph for this function:

◆ handle_result()

static void handle_result ( void *  cls,
const struct RecordResultMessage lrm 
)
static

We've received a notification about a change to our zone.

Forward to monitor callback.

Parameters
clsthe zone monitor handle
lrmthe message from the service.

Definition at line 206 of file namestore_api_monitor.c.

207 {
208  struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
209  size_t name_len;
210  size_t rd_len;
211  unsigned rd_count;
212  const char *name_tmp;
213  const char *rd_ser_tmp;
214 
215  rd_len = ntohs (lrm->rd_len);
216  rd_count = ntohs (lrm->rd_count);
217  name_len = ntohs (lrm->name_len);
218  name_tmp = (const char *) &lrm[1];
219  rd_ser_tmp = (const char *) &name_tmp[name_len];
220  {
221  struct GNUNET_GNSRECORD_Data rd[rd_count];
222 
223  GNUNET_assert (
224  GNUNET_OK ==
225  GNUNET_GNSRECORD_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd));
226  if (NULL != zm->monitor2)
227  zm->monitor2 (zm->monitor_cls, &lrm->private_key, name_tmp,
228  rd_count, rd, GNUNET_TIME_absolute_ntoh (lrm->expire));
229  else
230  zm->monitor (zm->monitor_cls, &lrm->private_key, name_tmp, rd_count, rd);
231  }
232 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:736
void * monitor_cls
Closure for monitor.
GNUNET_NAMESTORE_RecordMonitor monitor
Function to call on events.
GNUNET_NAMESTORE_RecordSetMonitor monitor2
Function to call on events.
struct GNUNET_TIME_AbsoluteNBO expire
Expiration time if the record result (if any).
Definition: namestore.h:293

References RecordResultMessage::expire, GNUNET_assert, GNUNET_GNSRECORD_records_deserialize(), GNUNET_OK, GNUNET_TIME_absolute_ntoh(), GNUNET_NAMESTORE_ZoneMonitor::monitor, GNUNET_NAMESTORE_ZoneMonitor::monitor2, GNUNET_NAMESTORE_ZoneMonitor::monitor_cls, RecordResultMessage::name_len, RecordResultMessage::private_key, RecordResultMessage::rd_count, RecordResultMessage::rd_len, and zm.

Here is the call graph for this function:

◆ mq_error_handler()

static void mq_error_handler ( 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 with the struct GNUNET_NAMESTORE_ZoneMonitor *
errorerror code

Definition at line 244 of file namestore_api_monitor.c.

245 {
246  struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
247 
248  (void) error;
249  reconnect (zm);
250 }
static void reconnect(struct GNUNET_NAMESTORE_ZoneMonitor *zm)
Reconnect to the namestore service.

References reconnect(), and zm.

Referenced by reconnect().

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