GNUnet  0.11.x
Data Structures | Macros | Functions
namestore_api.c File Reference

API to access the NAMESTORE service. 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_gns_service.h"
#include "gnunet_namestore_service.h"
#include "namestore.h"
Include dependency graph for namestore_api.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_NAMESTORE_QueueEntry
 An QueueEntry used to store information for a pending NAMESTORE record operation. More...
 
struct  GNUNET_NAMESTORE_ZoneIterator
 Handle for a zone iterator operation. More...
 
struct  GNUNET_NAMESTORE_Handle
 Connection to the NAMESTORE service. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "namestore-api", __VA_ARGS__)
 
#define NAMESTORE_DELAY_TOLERANCE   GNUNET_TIME_UNIT_MINUTES
 We grant the namestore up to 1 minute of latency, if it is slower than that, store queries will fail. More...
 

Functions

static void force_reconnect (struct GNUNET_NAMESTORE_Handle *h)
 Disconnect from service and then reconnect. More...
 
static struct GNUNET_NAMESTORE_QueueEntryfind_qe (struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
 Find the queue entry that matches the rid. More...
 
static struct GNUNET_NAMESTORE_ZoneIteratorfind_zi (struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
 Find the zone iteration entry that matches the rid. More...
 
static void free_qe (struct GNUNET_NAMESTORE_QueueEntry *qe)
 Free qe. More...
 
static void free_ze (struct GNUNET_NAMESTORE_ZoneIterator *ze)
 Free ze. More...
 
static int check_rd (size_t rd_len, const void *rd_buf, unsigned int rd_count)
 Check that rd_buf of length rd_len contains rd_count records. More...
 
static int check_record_store_response (void *cls, const struct RecordStoreResponseMessage *msg)
 Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE. More...
 
static void handle_record_store_response (void *cls, const struct RecordStoreResponseMessage *msg)
 Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE. More...
 
static int check_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
 Check validity of an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE. More...
 
static void handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
 Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE. More...
 
static int check_record_result (void *cls, const struct RecordResultMessage *msg)
 Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT. More...
 
static void handle_record_result (void *cls, const struct RecordResultMessage *msg)
 Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT. More...
 
static void handle_record_result_end (void *cls, const struct GNUNET_NAMESTORE_Header *msg)
 Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END. More...
 
static int check_zone_to_name_response (void *cls, const struct ZoneToNameResponseMessage *msg)
 Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE. More...
 
static void handle_zone_to_name_response (void *cls, const struct ZoneToNameResponseMessage *msg)
 Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE. 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...
 
static void reconnect (struct GNUNET_NAMESTORE_Handle *h)
 Reconnect to namestore service. More...
 
static void reconnect_task (void *cls)
 Re-establish the connection to the service. More...
 
static uint32_t get_op_id (struct GNUNET_NAMESTORE_Handle *h)
 Get a fresh operation id to distinguish between namestore requests. More...
 
struct GNUNET_NAMESTORE_HandleGNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Initialize the connection with the NAMESTORE service. More...
 
void GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h)
 Disconnect from the namestore service (and free associated resources). More...
 
static void warn_delay (void *cls)
 Task launched to warn the user that the namestore is excessively slow and that a query was thus dropped. More...
 
struct GNUNET_NAMESTORE_QueueEntryGNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
 Store an item in the namestore. More...
 
struct GNUNET_NAMESTORE_QueueEntryGNUNET_NAMESTORE_records_replace (struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
 TODO: Experimental API will replace API above. More...
 
struct GNUNET_NAMESTORE_QueueEntryGNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor rm, void *rm_cls)
 Lookup an item in the namestore. More...
 
struct GNUNET_NAMESTORE_QueueEntryGNUNET_NAMESTORE_records_select (struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor rm, void *rm_cls)
 TODO experimental API. More...
 
struct GNUNET_NAMESTORE_QueueEntryGNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *zone, const struct GNUNET_IDENTITY_PublicKey *value_zone, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls)
 Look for an existing PKEY delegation record for a given public key. More...
 
struct GNUNET_NAMESTORE_ZoneIteratorGNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *zone, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls, GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls)
 Starts a new zone iteration (used to periodically PUT all of our records into our DHT). More...
 
void GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it, uint64_t limit)
 Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start for the next record. More...
 
void GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it)
 Stops iteration and releases the namestore handle for further calls. More...
 
void GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe)
 Cancel a namestore operation. More...
 
struct GNUNET_NAMESTORE_QueueEntryGNUNET_NAMESTORE_transaction_begin (struct GNUNET_NAMESTORE_Handle *h, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls)
 New API draft. More...
 
struct GNUNET_NAMESTORE_QueueEntryGNUNET_NAMESTORE_transaction_abort (struct GNUNET_NAMESTORE_Handle *h, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls)
 Begin rollback all actions in a transaction. More...
 
struct GNUNET_NAMESTORE_QueueEntryGNUNET_NAMESTORE_transaction_commit (struct GNUNET_NAMESTORE_Handle *h, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls)
 Commit a namestore transaction. More...
 

Detailed Description

API to access the NAMESTORE service.

Author
Martin Schanzenbach
Matthias Wachs
Christian Grothoff

Definition in file namestore_api.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "namestore-api", __VA_ARGS__)

Definition at line 41 of file namestore_api.c.

◆ NAMESTORE_DELAY_TOLERANCE

#define NAMESTORE_DELAY_TOLERANCE   GNUNET_TIME_UNIT_MINUTES

We grant the namestore up to 1 minute of latency, if it is slower than that, store queries will fail.

Definition at line 47 of file namestore_api.c.

Function Documentation

◆ force_reconnect()

static void force_reconnect ( struct GNUNET_NAMESTORE_Handle h)
static

Disconnect from service and then reconnect.

Parameters
hour handle

Definition at line 886 of file namestore_api.c.

887 {
890 
892  h->mq = NULL;
893  while (NULL != (ze = h->z_head))
894  {
895  if (NULL != ze->error_cb)
896  ze->error_cb (ze->error_cb_cls);
897  free_ze (ze);
898  }
899  while (NULL != (qe = h->op_head))
900  {
901  if (NULL != qe->error_cb)
902  qe->error_cb (qe->error_cb_cls);
903  if (NULL != qe->cont)
904  qe->cont (qe->cont_cls,
906  "failure in communication with namestore service");
907  free_qe (qe);
908  }
909 
910  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting to namestore\n");
911  h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
912  h->reconnect_task =
913  GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect_task, h);
914 }
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
#define GNUNET_log(kind,...)
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
@ GNUNET_ERROR_TYPE_DEBUG
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:685
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1254
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
static void free_qe(struct GNUNET_NAMESTORE_QueueEntry *qe)
Free qe.
static void free_ze(struct GNUNET_NAMESTORE_ZoneIterator *ze)
Free ze.
static void reconnect_task(void *cls)
Re-establish the connection to the service.
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
Definition: arm_api.c:107
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the reconnect task (if any).
Definition: arm_api.c:147
GNUNET_DATASTORE_ContinuationWithStatus cont
Function to call after transmission of the request.
void * cont_cls
Closure for cont.
An QueueEntry used to store information for a pending NAMESTORE record operation.
Definition: namestore_api.c:54
Handle for a zone iterator operation.
void * error_cb_cls
Closure for error_cb.
GNUNET_SCHEDULER_TaskCallback error_cb
Function to call on errors.

References GNUNET_DATASTORE_QueueEntry::cont, GNUNET_DATASTORE_QueueEntry::cont_cls, GNUNET_NAMESTORE_ZoneIterator::error_cb, GNUNET_NAMESTORE_ZoneIterator::error_cb_cls, free_qe(), free_ze(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), GNUNET_SYSERR, GNUNET_TIME_STD_BACKOFF, h, GNUNET_ARM_Handle::mq, qe, GNUNET_ARM_Handle::reconnect_task, and reconnect_task().

Referenced by handle_record_result(), handle_record_result_end(), handle_zone_to_name_response(), and mq_error_handler().

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

◆ find_qe()

static struct GNUNET_NAMESTORE_QueueEntry* find_qe ( struct GNUNET_NAMESTORE_Handle h,
uint32_t  rid 
)
static

Find the queue entry that matches the rid.

Parameters
hnamestore handle
ridid to look up
Returns
NULL if rid was not found

Definition at line 260 of file namestore_api.c.

261 {
263 
264  for (qe = h->op_head; qe != NULL; qe = qe->next)
265  if (qe->op_id == rid)
266  return qe;
267  return NULL;
268 }
struct GNUNET_DATASTORE_QueueEntry * next
This is a linked list.

References h, GNUNET_DATASTORE_QueueEntry::next, and qe.

Referenced by handle_lookup_result(), handle_record_result(), handle_record_result_end(), handle_record_store_response(), and handle_zone_to_name_response().

Here is the caller graph for this function:

◆ find_zi()

static struct GNUNET_NAMESTORE_ZoneIterator* find_zi ( struct GNUNET_NAMESTORE_Handle h,
uint32_t  rid 
)
static

Find the zone iteration entry that matches the rid.

Parameters
hnamestore handle
ridid to look up
Returns
NULL if rid was not found

Definition at line 279 of file namestore_api.c.

280 {
282 
283  for (ze = h->z_head; ze != NULL; ze = ze->next)
284  if (ze->op_id == rid)
285  return ze;
286  return NULL;
287 }
struct GNUNET_NAMESTORE_ZoneIterator * next
Kept in a DLL.
uint32_t op_id
The operation id this zone iteration operation has.

References h, GNUNET_NAMESTORE_ZoneIterator::next, and GNUNET_NAMESTORE_ZoneIterator::op_id.

Referenced by handle_record_result(), and handle_record_result_end().

Here is the caller graph for this function:

◆ free_qe()

static void free_qe ( struct GNUNET_NAMESTORE_QueueEntry qe)
static

Free qe.

Parameters
qeentry to free

Definition at line 296 of file namestore_api.c.

297 {
298  struct GNUNET_NAMESTORE_Handle *h = qe->h;
299 
300  GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, qe);
301  if (NULL != qe->env)
303  if (NULL != qe->timeout_task)
304  GNUNET_SCHEDULER_cancel (qe->timeout_task);
305  GNUNET_free (qe);
306 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:283
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:957
struct GNUNET_DATASTORE_Handle * h
Handle to the master context.
struct GNUNET_MQ_Envelope * env
Envelope of the request to transmit, NULL after transmission.
Connection to the NAMESTORE service.

References GNUNET_DATASTORE_QueueEntry::env, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MQ_discard(), GNUNET_SCHEDULER_cancel(), h, GNUNET_DATASTORE_QueueEntry::h, and qe.

Referenced by force_reconnect(), GNUNET_NAMESTORE_cancel(), handle_lookup_result(), handle_record_result(), handle_record_store_response(), and handle_zone_to_name_response().

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

◆ free_ze()

static void free_ze ( struct GNUNET_NAMESTORE_ZoneIterator ze)
static

Free ze.

Parameters
zeentry to free

Definition at line 315 of file namestore_api.c.

316 {
317  struct GNUNET_NAMESTORE_Handle *h = ze->h;
318 
319  GNUNET_CONTAINER_DLL_remove (h->z_head, h->z_tail, ze);
320  if (NULL != ze->env)
321  GNUNET_MQ_discard (ze->env);
322  GNUNET_free (ze);
323 }
struct GNUNET_NAMESTORE_Handle * h
Main handle to access the namestore.
struct GNUNET_MQ_Envelope * env
Envelope of the message to send to the service, if not yet sent.

References GNUNET_NAMESTORE_ZoneIterator::env, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MQ_discard(), h, and GNUNET_NAMESTORE_ZoneIterator::h.

Referenced by force_reconnect(), GNUNET_NAMESTORE_zone_iteration_stop(), and handle_record_result_end().

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

◆ check_rd()

static int check_rd ( size_t  rd_len,
const void *  rd_buf,
unsigned int  rd_count 
)
static

Check that rd_buf of length rd_len contains rd_count records.

Parameters
rd_lenlength of rd_buf
rd_bufbuffer with serialized records
rd_countnumber of records expected
Returns
GNUNET_OK if rd_buf is well-formed

Definition at line 336 of file namestore_api.c.

337 {
338  struct GNUNET_GNSRECORD_Data rd[rd_count];
339 
340  if (GNUNET_OK !=
341  GNUNET_GNSRECORD_records_deserialize (rd_len, rd_buf, rd_count, rd))
342  {
343  GNUNET_break (0);
344  return GNUNET_SYSERR;
345  }
346  return GNUNET_OK;
347 }
@ GNUNET_OK
Definition: gnunet_common.h:95
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_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.

References GNUNET_break, GNUNET_GNSRECORD_records_deserialize(), GNUNET_OK, and GNUNET_SYSERR.

Referenced by check_lookup_result(), check_record_result(), and check_zone_to_name_response().

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

◆ check_record_store_response()

static int check_record_store_response ( void *  cls,
const struct RecordStoreResponseMessage msg 
)
static

Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE.

Parameters
cls
msgthe message we received
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 358 of file namestore_api.c.

360 {
361  const char *emsg;
362  size_t msg_len;
363  size_t emsg_len;
364 
365  (void) cls;
366  msg_len = ntohs (msg->gns_header.header.size);
367  emsg_len = ntohs (msg->emsg_len);
368  if (0 != ntohs (msg->reserved))
369  {
370  GNUNET_break (0);
371  return GNUNET_SYSERR;
372  }
373  if (msg_len != sizeof(struct RecordStoreResponseMessage) + emsg_len)
374  {
375  GNUNET_break (0);
376  return GNUNET_SYSERR;
377  }
378  emsg = (const char *) &msg[1];
379  if ((0 != emsg_len) && ('\0' != emsg[emsg_len - 1]))
380  {
381  GNUNET_break (0);
382  return GNUNET_SYSERR;
383  }
384  return GNUNET_OK;
385 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
Response to a record storage request.
Definition: namestore.h:106

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, msg, and GNUNET_MessageHeader::size.

◆ handle_record_store_response()

static void handle_record_store_response ( void *  cls,
const struct RecordStoreResponseMessage msg 
)
static

Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE.

Parameters
cls
msgthe message we received

Definition at line 396 of file namestore_api.c.

398 {
399  struct GNUNET_NAMESTORE_Handle *h = cls;
401  int res;
402  const char *emsg;
403 
404  qe = find_qe (h, ntohl (msg->gns_header.r_id));
405  emsg = (const char *) &msg[1];
406  res = ntohl (msg->op_result);
408  "Received RECORD_STORE_RESPONSE with result %d\n",
409  res);
410  if (NULL == qe)
411  return;
412  if (NULL != qe->cont)
413  qe->cont (qe->cont_cls, res,
414  (GNUNET_OK == res) ? NULL : emsg);
415  free_qe (qe);
416 }
static int res
static struct GNUNET_NAMESTORE_QueueEntry * find_qe(struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
Find the queue entry that matches the rid.
#define LOG(kind,...)
Definition: namestore_api.c:41

References GNUNET_DATASTORE_QueueEntry::cont, GNUNET_DATASTORE_QueueEntry::cont_cls, find_qe(), free_qe(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_OK, h, LOG, msg, qe, and res.

Here is the call graph for this function:

◆ check_lookup_result()

static int check_lookup_result ( void *  cls,
const struct LabelLookupResponseMessage msg 
)
static

Check validity of an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE.

Parameters
cls
msgthe message we received
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 428 of file namestore_api.c.

429 {
430  const char *name;
431  size_t exp_msg_len;
432  size_t msg_len;
433  size_t name_len;
434  size_t rd_len;
435 
436  (void) cls;
437  rd_len = ntohs (msg->rd_len);
438  msg_len = ntohs (msg->gns_header.header.size);
439  name_len = ntohs (msg->name_len);
440  exp_msg_len = sizeof(*msg) + name_len + rd_len;
441  if (msg_len != exp_msg_len)
442  {
443  GNUNET_break (0);
444  return GNUNET_SYSERR;
445  }
446  name = (const char *) &msg[1];
447  if ((name_len > 0) && ('\0' != name[name_len - 1]))
448  {
449  GNUNET_break (0);
450  return GNUNET_SYSERR;
451  }
452  if (GNUNET_NO == ntohs (msg->found))
453  {
454  if (0 != ntohs (msg->rd_count))
455  {
456  GNUNET_break (0);
457  return GNUNET_SYSERR;
458  }
459  return GNUNET_OK;
460  }
461  return check_rd (rd_len, &name[name_len], ntohs (msg->rd_count));
462 }
@ GNUNET_NO
Definition: gnunet_common.h:94
static int check_rd(size_t rd_len, const void *rd_buf, unsigned int rd_count)
Check that rd_buf of length rd_len contains rd_count records.
const char * name

References check_rd(), GNUNET_break, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, msg, name, and GNUNET_MessageHeader::size.

Here is the call graph for this function:

◆ handle_lookup_result()

static void handle_lookup_result ( void *  cls,
const struct LabelLookupResponseMessage msg 
)
static

Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE.

Parameters
cls
msgthe message we received

Definition at line 473 of file namestore_api.c.

474 {
475  struct GNUNET_NAMESTORE_Handle *h = cls;
477  const char *name;
478  const char *rd_tmp;
479  size_t name_len;
480  size_t rd_len;
481  unsigned int rd_count;
482  int16_t found = (int16_t) ntohs (msg->found);
483 
484  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_LOOKUP_RESULT (found=%i)\n",
485  found);
486  qe = find_qe (h, ntohl (msg->gns_header.r_id));
487  if (NULL == qe)
488  return;
489  rd_len = ntohs (msg->rd_len);
490  rd_count = ntohs (msg->rd_count);
491  name_len = ntohs (msg->name_len);
492  name = (const char *) &msg[1];
493  if (GNUNET_NO == found)
494  {
495  /* label was not in namestore */
496  if (NULL != qe->proc)
497  qe->proc (qe->proc_cls, &msg->private_key, name, 0, NULL);
498  free_qe (qe);
499  return;
500  }
501  if (GNUNET_SYSERR == found)
502  {
503  if (NULL != qe->error_cb)
504  qe->error_cb (qe->error_cb_cls);
505  free_qe (qe);
506  return;
507  }
508 
509  rd_tmp = &name[name_len];
510  {
511  struct GNUNET_GNSRECORD_Data rd[rd_count];
512 
513  GNUNET_assert (
514  GNUNET_OK ==
515  GNUNET_GNSRECORD_records_deserialize (rd_len, rd_tmp, rd_count, rd));
516  if (0 == name_len)
517  name = NULL;
518  if (NULL != qe->proc)
519  qe->proc (qe->proc_cls,
520  &msg->private_key,
521  name,
522  rd_count,
523  (rd_count > 0) ? rd : NULL);
524  }
525  free_qe (qe);
526 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.

References find_qe(), free_qe(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_GNSRECORD_records_deserialize(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, h, LOG, msg, name, and qe.

Here is the call graph for this function:

◆ check_record_result()

static int check_record_result ( void *  cls,
const struct RecordResultMessage msg 
)
static

Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT.

Parameters
cls
msgthe message we received
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 538 of file namestore_api.c.

539 {
540  static struct GNUNET_IDENTITY_PrivateKey priv_dummy;
541  const char *name;
542  size_t msg_len;
543  size_t name_len;
544  size_t rd_len;
545 
546  (void) cls;
547  rd_len = ntohs (msg->rd_len);
548  msg_len = ntohs (msg->gns_header.header.size);
549  name_len = ntohs (msg->name_len);
550  if (0 != ntohs (msg->reserved))
551  {
552  GNUNET_break (0);
553  return GNUNET_SYSERR;
554  }
555  if (msg_len != sizeof(struct RecordResultMessage) + name_len + rd_len)
556  {
557  GNUNET_break (0);
558  return GNUNET_SYSERR;
559  }
560  name = (const char *) &msg[1];
561  if ((0 == name_len) || ('\0' != name[name_len - 1]))
562  {
563  GNUNET_break (0);
564  return GNUNET_SYSERR;
565  }
566  if (0 == GNUNET_memcmp (&msg->private_key, &priv_dummy))
567  {
568  GNUNET_break (0);
569  return GNUNET_SYSERR;
570  }
571  return check_rd (rd_len, &name[name_len], ntohs (msg->rd_count));
572 }
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
A private key for an identity as per LSD0001.
Record is returned from the namestore (as authority).
Definition: namestore.h:271

References check_rd(), GNUNET_break, GNUNET_memcmp, GNUNET_SYSERR, msg, name, and GNUNET_MessageHeader::size.

Here is the call graph for this function:

◆ handle_record_result()

static void handle_record_result ( void *  cls,
const struct RecordResultMessage msg 
)
static

Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT.

Parameters
cls
msgthe message we received

Definition at line 583 of file namestore_api.c.

584 {
585  struct GNUNET_NAMESTORE_Handle *h = cls;
588  const char *name;
589  const char *rd_tmp;
590  size_t name_len;
591  size_t rd_len;
592  unsigned int rd_count;
593 
594  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT\n");
595  rd_len = ntohs (msg->rd_len);
596  rd_count = ntohs (msg->rd_count);
597  name_len = ntohs (msg->name_len);
598  ze = find_zi (h, ntohl (msg->gns_header.r_id));
599  qe = find_qe (h, ntohl (msg->gns_header.r_id));
600  if ((NULL == ze) && (NULL == qe))
601  return; /* rid not found */
602  if ((NULL != ze) && (NULL != qe))
603  {
604  GNUNET_break (0); /* rid ambiguous */
605  force_reconnect (h);
606  return;
607  }
608  name = (const char *) &msg[1];
609  rd_tmp = &name[name_len];
610  {
611  struct GNUNET_GNSRECORD_Data rd[rd_count];
612 
613  GNUNET_assert (
614  GNUNET_OK ==
615  GNUNET_GNSRECORD_records_deserialize (rd_len, rd_tmp, rd_count, rd));
616  if (0 == name_len)
617  name = NULL;
618  if (NULL != qe)
619  {
620  if (NULL != qe->proc)
621  qe->proc (qe->proc_cls,
622  &msg->private_key,
623  name,
624  rd_count,
625  (rd_count > 0) ? rd : NULL);
626  free_qe (qe);
627  return;
628  }
629  if (NULL != ze)
630  {
631  if (NULL != ze->proc)
632  ze->proc (ze->proc_cls, &msg->private_key, name, rd_count, rd);
633  return;
634  }
635  }
636  GNUNET_assert (0);
637 }
static void force_reconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from service and then reconnect.
static struct GNUNET_NAMESTORE_ZoneIterator * find_zi(struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
Find the zone iteration entry that matches the rid.
void * proc_cls
Closure for proc.
GNUNET_NAMESTORE_RecordMonitor proc
The continuation to call with the results.

References find_qe(), find_zi(), force_reconnect(), free_qe(), GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_GNSRECORD_records_deserialize(), GNUNET_OK, h, LOG, msg, name, GNUNET_NAMESTORE_ZoneIterator::proc, GNUNET_NAMESTORE_ZoneIterator::proc_cls, and qe.

Here is the call graph for this function:

◆ handle_record_result_end()

static void handle_record_result_end ( void *  cls,
const struct GNUNET_NAMESTORE_Header msg 
)
static

Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END.

Parameters
cls
msgthe message we received

Definition at line 648 of file namestore_api.c.

649 {
650  struct GNUNET_NAMESTORE_Handle *h = cls;
653 
654  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT_END\n");
655  ze = find_zi (h, ntohl (msg->r_id));
656  qe = find_qe (h, ntohl (msg->r_id));
657  if ((NULL == ze) && (NULL == qe))
658  return; /* rid not found */
659  if ((NULL != ze) && (NULL != qe))
660  {
661  GNUNET_break (0); /* rid ambiguous */
662  force_reconnect (h);
663  return;
664  }
665  LOG (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration completed!\n");
666  if (NULL == ze)
667  {
668  GNUNET_break (0);
669  force_reconnect (h);
670  return;
671  }
672  if (NULL != ze->finish_cb)
673  ze->finish_cb (ze->finish_cb_cls);
674  free_ze (ze);
675 }
void * finish_cb_cls
Closure for error_cb.
GNUNET_SCHEDULER_TaskCallback finish_cb
Function to call on completion.

References find_qe(), find_zi(), GNUNET_NAMESTORE_ZoneIterator::finish_cb, GNUNET_NAMESTORE_ZoneIterator::finish_cb_cls, force_reconnect(), free_ze(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, h, LOG, msg, and qe.

Here is the call graph for this function:

◆ check_zone_to_name_response()

static int check_zone_to_name_response ( void *  cls,
const struct ZoneToNameResponseMessage msg 
)
static

Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE.

Parameters
qethe respective entry in the message queue
msgthe message we received
Returns
GNUNET_OK on success, GNUNET_SYSERR if message malformed

Definition at line 687 of file namestore_api.c.

689 {
690  size_t name_len;
691  size_t rd_ser_len;
692  const char *name_tmp;
693 
694  (void) cls;
695  if (GNUNET_OK != ntohs (msg->res))
696  return GNUNET_OK;
697  name_len = ntohs (msg->name_len);
698  rd_ser_len = ntohs (msg->rd_len);
699  if (ntohs (msg->gns_header.header.size) !=
700  sizeof(struct ZoneToNameResponseMessage) + name_len + rd_ser_len)
701  {
702  GNUNET_break (0);
703  return GNUNET_SYSERR;
704  }
705  name_tmp = (const char *) &msg[1];
706  if ((name_len > 0) && ('\0' != name_tmp[name_len - 1]))
707  {
708  GNUNET_break (0);
709  return GNUNET_SYSERR;
710  }
711  return check_rd (rd_ser_len, &name_tmp[name_len], ntohs (msg->rd_count));
712 }
Respone for zone to name lookup.
Definition: namestore.h:228

References check_rd(), GNUNET_break, GNUNET_OK, GNUNET_SYSERR, msg, and GNUNET_MessageHeader::size.

Here is the call graph for this function:

◆ handle_zone_to_name_response()

static void handle_zone_to_name_response ( void *  cls,
const struct ZoneToNameResponseMessage msg 
)
static

Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE.

Parameters
cls
msgthe message we received

Definition at line 723 of file namestore_api.c.

725 {
726  struct GNUNET_NAMESTORE_Handle *h = cls;
728  int res;
729  size_t name_len;
730  size_t rd_ser_len;
731  unsigned int rd_count;
732  const char *name_tmp;
733  const char *rd_tmp;
734 
735  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME_RESPONSE\n");
736  qe = find_qe (h, ntohl (msg->gns_header.r_id));
737  if (NULL == qe)
738  {
740  "Response queue already gone...\n");
741  return;
742  }
743  res = ntohs (msg->res);
744  switch (res)
745  {
746  case GNUNET_SYSERR:
748  "An error occurred during zone to name operation\n");
749  break;
750 
751  case GNUNET_NO:
753  "Namestore has no result for zone to name mapping \n");
754  if (NULL != qe->proc)
755  qe->proc (qe->proc_cls, &msg->zone, NULL, 0, NULL);
756  free_qe (qe);
757  return;
758 
759  case GNUNET_YES:
761  "Namestore has result for zone to name mapping \n");
762  name_len = ntohs (msg->name_len);
763  rd_count = ntohs (msg->rd_count);
764  rd_ser_len = ntohs (msg->rd_len);
765  name_tmp = (const char *) &msg[1];
766  rd_tmp = &name_tmp[name_len];
767  {
768  struct GNUNET_GNSRECORD_Data rd[rd_count];
769 
772  rd_tmp,
773  rd_count,
774  rd));
775  /* normal end, call continuation with result */
776  if (NULL != qe->proc)
777  qe->proc (qe->proc_cls, &msg->zone, name_tmp, rd_count, rd);
778  /* return is important here: break would call continuation with error! */
779  free_qe (qe);
780  return;
781  }
782 
783  default:
784  GNUNET_break (0);
785  force_reconnect (h);
786  return;
787  }
788  /* error case, call continuation with error */
789  if (NULL != qe->error_cb)
790  qe->error_cb (qe->error_cb_cls);
791  free_qe (qe);
792 }
@ GNUNET_YES
Definition: gnunet_common.h:97
@ GNUNET_ERROR_TYPE_WARNING

References find_qe(), force_reconnect(), free_qe(), GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_GNSRECORD_records_deserialize(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, h, LOG, msg, qe, and res.

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_Handle *
errorerror code

Definition at line 804 of file namestore_api.c.

805 {
806  struct GNUNET_NAMESTORE_Handle *h = cls;
807 
808  (void) error;
809  force_reconnect (h);
810 }

References force_reconnect(), and h.

Referenced by reconnect().

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

◆ reconnect()

static void reconnect ( struct GNUNET_NAMESTORE_Handle h)
static

Reconnect to namestore service.

Parameters
hthe handle to the NAMESTORE service

Definition at line 819 of file namestore_api.c.

820 {
822  { GNUNET_MQ_hd_var_size (record_store_response,
825  h),
826  GNUNET_MQ_hd_var_size (zone_to_name_response,
829  h),
830  GNUNET_MQ_hd_var_size (record_result,
832  struct RecordResultMessage,
833  h),
834  GNUNET_MQ_hd_fixed_size (record_result_end,
837  h),
838  GNUNET_MQ_hd_var_size (lookup_result,
841  h),
845 
846  GNUNET_assert (NULL == h->mq);
847  h->mq =
849  if (NULL == h->mq)
850  return;
851  /* re-transmit pending requests that waited for a reconnect... */
852  for (it = h->z_head; NULL != it; it = it->next)
853  {
854  GNUNET_MQ_send (h->mq, it->env);
855  it->env = NULL;
856  }
857  for (qe = h->op_head; NULL != qe; qe = qe->next)
858  {
859  GNUNET_MQ_send (h->mq, qe->env);
860  qe->env = NULL;
861  }
862 }
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
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:1066
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_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END
Service to client: end of list of results.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT
Service to client: here is a (plaintext) record you requested.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE
Service to client: result of zone-to-name lookup.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE
Service to client: result of store operation.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE
Service to client: lookup label.
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...
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Definition: arm_api.c:112
Message handler for a specific message type.
Generic namestore message with op id.
Definition: namestore.h:41

References GNUNET_ARM_Handle::cfg, GNUNET_DATASTORE_QueueEntry::env, GNUNET_NAMESTORE_ZoneIterator::env, GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE, GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT, GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END, GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_MQ_send(), h, handlers, GNUNET_ARM_Handle::mq, mq_error_handler(), GNUNET_DATASTORE_QueueEntry::next, GNUNET_NAMESTORE_ZoneIterator::next, and qe.

Referenced by GNUNET_NAMESTORE_connect(), and reconnect_task().

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

◆ reconnect_task()

static void reconnect_task ( void *  cls)
static

Re-establish the connection to the service.

Parameters
clshandle to use to re-connect.

Definition at line 871 of file namestore_api.c.

872 {
873  struct GNUNET_NAMESTORE_Handle *h = cls;
874 
875  h->reconnect_task = NULL;
876  reconnect (h);
877 }
static void reconnect(struct GNUNET_NAMESTORE_Handle *h)
Reconnect to namestore service.

References h, reconnect(), and GNUNET_ARM_Handle::reconnect_task.

Referenced by force_reconnect().

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

◆ get_op_id()

static uint32_t get_op_id ( struct GNUNET_NAMESTORE_Handle h)
static

Get a fresh operation id to distinguish between namestore requests.

Parameters
hthe namestore handle
Returns
next operation id to use

Definition at line 924 of file namestore_api.c.

925 {
926  return h->last_op_id_used++;
927 }

References h.

Referenced by GNUNET_NAMESTORE_records_lookup(), GNUNET_NAMESTORE_records_store(), GNUNET_NAMESTORE_zone_iteration_start(), and GNUNET_NAMESTORE_zone_to_name().

Here is the caller graph for this function:

◆ warn_delay()

static void warn_delay ( void *  cls)
static

Task launched to warn the user that the namestore is excessively slow and that a query was thus dropped.

Parameters
clsa struct GNUNET_NAMESTORE_QueueEntry *

Definition at line 999 of file namestore_api.c.

1000 {
1001  struct GNUNET_NAMESTORE_QueueEntry *qe = cls;
1002 
1003  qe->timeout_task = NULL;
1005  "Did not receive response from namestore after %s!\n",
1007  GNUNET_YES));
1008  if (NULL != qe->cont)
1009  {
1010  qe->cont (qe->cont_cls, GNUNET_SYSERR, "timeout");
1011  qe->cont = NULL;
1012  }
1014 }
void GNUNET_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe)
Cancel a namestore operation.
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:570
#define NAMESTORE_DELAY_TOLERANCE
We grant the namestore up to 1 minute of latency, if it is slower than that, store queries will fail.
Definition: namestore_api.c:47

References GNUNET_DATASTORE_QueueEntry::cont, GNUNET_DATASTORE_QueueEntry::cont_cls, GNUNET_ERROR_TYPE_WARNING, GNUNET_NAMESTORE_cancel(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_SYSERR, GNUNET_YES, LOG, NAMESTORE_DELAY_TOLERANCE, and qe.

Referenced by GNUNET_NAMESTORE_records_store().

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