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 lenght rd_len contains rd_count records. 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_CRYPTO_EcdsaPrivateKey *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_set_nick (struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, const char *nick, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
 Set the desired nick name for a zone. More...
 
struct GNUNET_NAMESTORE_QueueEntryGNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const struct GNUNET_CRYPTO_EcdsaPublicKey *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_CRYPTO_EcdsaPrivateKey *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...
 

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__)

◆ 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.

Referenced by GNUNET_NAMESTORE_records_store(), and warn_delay().

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 834 of file namestore_api.c.

References GNUNET_NAMESTORE_QueueEntry::cont, GNUNET_NAMESTORE_QueueEntry::cont_cls, GNUNET_NAMESTORE_QueueEntry::error_cb, GNUNET_NAMESTORE_ZoneIterator::error_cb, GNUNET_NAMESTORE_QueueEntry::error_cb_cls, 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, GNUNET_NAMESTORE_Handle::mq, GNUNET_NAMESTORE_Handle::op_head, qe, GNUNET_NAMESTORE_Handle::reconnect_delay, GNUNET_NAMESTORE_Handle::reconnect_task, reconnect_task(), and GNUNET_NAMESTORE_Handle::z_head.

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

835 {
838 
839  GNUNET_MQ_destroy (h->mq);
840  h->mq = NULL;
841  while (NULL != (ze = h->z_head))
842  {
843  if (NULL != ze->error_cb)
844  ze->error_cb (ze->error_cb_cls);
845  free_ze (ze);
846  }
847  while (NULL != (qe = h->op_head))
848  {
849  if (NULL != qe->error_cb)
850  qe->error_cb (qe->error_cb_cls);
851  if (NULL != qe->cont)
852  qe->cont (qe->cont_cls,
854  "failure in communication with namestore service");
855  free_qe (qe);
856  }
857 
858  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting to namestore\n");
860  h->reconnect_task =
862 }
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
GNUNET_SCHEDULER_TaskCallback error_cb
Function to call on errors.
GNUNET_SCHEDULER_TaskCallback error_cb
Function to call on errors.
Definition: namestore_api.c:93
void * error_cb_cls
Closure for error_cb.
void * error_cb_cls
Closure for error_cb.
Definition: namestore_api.c:98
static void free_ze(struct GNUNET_NAMESTORE_ZoneIterator *ze)
Free ze.
Handle for a zone iterator operation.
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:1253
struct GNUNET_TIME_Relative reconnect_delay
Delay introduced before we reconnect.
struct GNUNET_MQ_Handle * mq
Connection to the service (if available).
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
An QueueEntry used to store information for a pending NAMESTORE record operation. ...
Definition: namestore_api.c:53
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
GNUNET_NAMESTORE_ContinuationWithStatus cont
Continuation to call.
Definition: namestore_api.c:73
static void free_qe(struct GNUNET_NAMESTORE_QueueEntry *qe)
Free qe.
void * cont_cls
Closure for cont.
Definition: namestore_api.c:78
struct GNUNET_NAMESTORE_QueueEntry * op_head
Head of pending namestore queue entries.
struct GNUNET_NAMESTORE_ZoneIterator * z_head
Head of pending namestore zone iterator entries.
#define GNUNET_log(kind,...)
struct GNUNET_SCHEDULER_Task * reconnect_task
Reconnect task.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
static void reconnect_task(void *cls)
Re-establish the connection to the service.
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.

References GNUNET_NAMESTORE_QueueEntry::next, GNUNET_NAMESTORE_Handle::op_head, GNUNET_NAMESTORE_QueueEntry::op_id, and qe.

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

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 }
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
struct GNUNET_NAMESTORE_QueueEntry * next
Kept in a DLL.
Definition: namestore_api.c:58
An QueueEntry used to store information for a pending NAMESTORE record operation. ...
Definition: namestore_api.c:53
uint32_t op_id
The operation id this zone iteration operation has.
struct GNUNET_NAMESTORE_QueueEntry * op_head
Head of pending namestore queue entries.
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.

References GNUNET_NAMESTORE_ZoneIterator::next, GNUNET_NAMESTORE_ZoneIterator::op_id, and GNUNET_NAMESTORE_Handle::z_head.

Referenced by handle_record_result(), and handle_record_result_end().

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 }
uint32_t op_id
The operation id this zone iteration operation has.
Handle for a zone iterator operation.
struct GNUNET_NAMESTORE_ZoneIterator * next
Kept in a DLL.
struct GNUNET_NAMESTORE_ZoneIterator * z_head
Head of pending namestore zone iterator entries.
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.

References GNUNET_NAMESTORE_QueueEntry::env, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MQ_discard(), GNUNET_SCHEDULER_cancel(), GNUNET_NAMESTORE_QueueEntry::h, GNUNET_NAMESTORE_Handle::op_head, GNUNET_NAMESTORE_Handle::op_tail, and GNUNET_NAMESTORE_QueueEntry::timeout_task.

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

297 {
298  struct GNUNET_NAMESTORE_Handle *h = qe->h;
299 
301  if (NULL != qe->env)
302  GNUNET_MQ_discard (qe->env);
303  if (NULL != qe->timeout_task)
305  GNUNET_free (qe);
306 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_NAMESTORE_Handle * h
Main handle to access the namestore.
Definition: namestore_api.c:68
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
Connection to the NAMESTORE service.
struct GNUNET_MQ_Envelope * env
Envelope of the message to send to the service, if not yet sent.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:321
struct GNUNET_NAMESTORE_QueueEntry * op_tail
Tail of pending namestore queue entries.
struct GNUNET_NAMESTORE_QueueEntry * op_head
Head of pending namestore queue entries.
struct GNUNET_SCHEDULER_Task * timeout_task
Task scheduled to warn us if the namestore is way too slow.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
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.

References GNUNET_NAMESTORE_ZoneIterator::env, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MQ_discard(), GNUNET_NAMESTORE_QueueEntry::h, GNUNET_NAMESTORE_ZoneIterator::h, GNUNET_NAMESTORE_Handle::z_head, and GNUNET_NAMESTORE_Handle::z_tail.

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

316 {
317  struct GNUNET_NAMESTORE_Handle *h = ze->h;
318 
320  if (NULL != ze->env)
321  GNUNET_MQ_discard (ze->env);
322  GNUNET_free (ze);
323 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_MQ_Envelope * env
Envelope of the message to send to the service, if not yet sent.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
Connection to the NAMESTORE service.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:321
struct GNUNET_NAMESTORE_Handle * h
Main handle to access the namestore.
struct GNUNET_NAMESTORE_ZoneIterator * z_head
Head of pending namestore zone iterator entries.
struct GNUNET_NAMESTORE_ZoneIterator * z_tail
Tail of pending namestore zone iterator entries.
#define GNUNET_free(ptr)
Wrapper around free.
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 lenght 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.

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().

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 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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...
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 358 of file namestore_api.c.

References _, GNUNET_NAMESTORE_QueueEntry::cont, GNUNET_NAMESTORE_QueueEntry::cont_cls, find_qe(), free_qe(), RecordStoreResponseMessage::gns_header, GNUNET_ERROR_TYPE_DEBUG, GNUNET_SYSERR, GNUNET_NAMESTORE_QueueEntry::h, LOG, RecordStoreResponseMessage::op_result, qe, GNUNET_NAMESTORE_Header::r_id, and res.

360 {
361  struct GNUNET_NAMESTORE_Handle *h = cls;
363  int res;
364  const char *emsg;
365 
366  qe = find_qe (h, ntohl (msg->gns_header.r_id));
367  res = ntohl (msg->op_result);
369  "Received RECORD_STORE_RESPONSE with result %d\n",
370  res);
371  /* TODO: add actual error message from namestore to response... */
372  if (GNUNET_SYSERR == res)
373  emsg = _ ("Namestore failed to store record\n");
374  else
375  emsg = NULL;
376  if (NULL != qe->cont)
377  qe->cont (qe->cont_cls, res, emsg);
378  free_qe (qe);
379 }
struct GNUNET_NAMESTORE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE.
Definition: namestore.h:110
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
uint32_t r_id
Request ID in NBO.
Definition: namestore.h:51
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
int32_t op_result
GNUNET_SYSERR on failure, GNUNET_OK on success
Definition: namestore.h:115
Connection to the NAMESTORE service.
static int res
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
An QueueEntry used to store information for a pending NAMESTORE record operation. ...
Definition: namestore_api.c:53
GNUNET_NAMESTORE_ContinuationWithStatus cont
Continuation to call.
Definition: namestore_api.c:73
static void free_qe(struct GNUNET_NAMESTORE_QueueEntry *qe)
Free qe.
#define LOG(kind,...)
Definition: namestore_api.c:41
void * cont_cls
Closure for cont.
Definition: namestore_api.c:78
static struct GNUNET_NAMESTORE_QueueEntry * find_qe(struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
Find the queue entry that matches the rid.
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 391 of file namestore_api.c.

References check_rd(), LabelLookupResponseMessage::found, LabelLookupResponseMessage::gns_header, GNUNET_break, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_NAMESTORE_Header::header, name, LabelLookupResponseMessage::name_len, LabelLookupResponseMessage::rd_count, LabelLookupResponseMessage::rd_len, and GNUNET_MessageHeader::size.

392 {
393  const char *name;
394  size_t exp_msg_len;
395  size_t msg_len;
396  size_t name_len;
397  size_t rd_len;
398 
399  (void) cls;
400  rd_len = ntohs (msg->rd_len);
401  msg_len = ntohs (msg->gns_header.header.size);
402  name_len = ntohs (msg->name_len);
403  exp_msg_len = sizeof(*msg) + name_len + rd_len;
404  if (msg_len != exp_msg_len)
405  {
406  GNUNET_break (0);
407  return GNUNET_SYSERR;
408  }
409  name = (const char *) &msg[1];
410  if ((name_len > 0) && ('\0' != name[name_len - 1]))
411  {
412  GNUNET_break (0);
413  return GNUNET_SYSERR;
414  }
415  if (GNUNET_NO == ntohs (msg->found))
416  {
417  if (0 != ntohs (msg->rd_count))
418  {
419  GNUNET_break (0);
420  return GNUNET_SYSERR;
421  }
422  return GNUNET_OK;
423  }
424  return check_rd (rd_len, &name[name_len], ntohs (msg->rd_count));
425 }
uint16_t rd_len
Length of serialized record data.
Definition: namestore.h:163
uint16_t rd_count
Number of records contained.
Definition: namestore.h:168
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_MessageHeader header
header.type will be GNUNET_MESSAGE_TYPE_NAMESTORE_* header.size will be message size ...
Definition: namestore.h:46
static int check_rd(size_t rd_len, const void *rd_buf, unsigned int rd_count)
Check that rd_buf of lenght rd_len contains rd_count records.
uint16_t name_len
Name length.
Definition: namestore.h:158
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
uint16_t found
Was the label found in the database?? GNUNET_YES or GNUNET_NO.
Definition: namestore.h:174
struct GNUNET_NAMESTORE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE.
Definition: namestore.h:153
const char * name
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 436 of file namestore_api.c.

References find_qe(), LabelLookupResponseMessage::found, free_qe(), LabelLookupResponseMessage::gns_header, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_GNSRECORD_records_deserialize(), GNUNET_NO, GNUNET_OK, GNUNET_NAMESTORE_QueueEntry::h, LOG, name, LabelLookupResponseMessage::name_len, LabelLookupResponseMessage::private_key, GNUNET_NAMESTORE_QueueEntry::proc, GNUNET_NAMESTORE_QueueEntry::proc_cls, qe, GNUNET_NAMESTORE_Header::r_id, LabelLookupResponseMessage::rd_count, and LabelLookupResponseMessage::rd_len.

437 {
438  struct GNUNET_NAMESTORE_Handle *h = cls;
440  const char *name;
441  const char *rd_tmp;
442  size_t name_len;
443  size_t rd_len;
444  unsigned int rd_count;
445 
446  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_LOOKUP_RESULT\n");
447  qe = find_qe (h, ntohl (msg->gns_header.r_id));
448  if (NULL == qe)
449  return;
450  rd_len = ntohs (msg->rd_len);
451  rd_count = ntohs (msg->rd_count);
452  name_len = ntohs (msg->name_len);
453  name = (const char *) &msg[1];
454  if (GNUNET_NO == ntohs (msg->found))
455  {
456  /* label was not in namestore */
457  if (NULL != qe->proc)
458  qe->proc (qe->proc_cls, &msg->private_key, name, 0, NULL);
459  free_qe (qe);
460  return;
461  }
462 
463  rd_tmp = &name[name_len];
464  {
465  struct GNUNET_GNSRECORD_Data rd[rd_count];
466 
467  GNUNET_assert (
468  GNUNET_OK ==
469  GNUNET_GNSRECORD_records_deserialize (rd_len, rd_tmp, rd_count, rd));
470  if (0 == name_len)
471  name = NULL;
472  if (NULL != qe->proc)
473  qe->proc (qe->proc_cls,
474  &msg->private_key,
475  name,
476  rd_count,
477  (rd_count > 0) ? rd : NULL);
478  }
479  free_qe (qe);
480 }
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
GNUNET_NAMESTORE_RecordMonitor proc
Function to call with the records we get back; or NULL.
Definition: namestore_api.c:83
uint16_t rd_len
Length of serialized record data.
Definition: namestore.h:163
uint32_t r_id
Request ID in NBO.
Definition: namestore.h:51
uint16_t rd_count
Number of records contained.
Definition: namestore.h:168
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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.
void * proc_cls
Closure for proc.
Definition: namestore_api.c:88
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
Connection to the NAMESTORE service.
uint16_t name_len
Name length.
Definition: namestore.h:158
An QueueEntry used to store information for a pending NAMESTORE record operation. ...
Definition: namestore_api.c:53
uint16_t found
Was the label found in the database?? GNUNET_YES or GNUNET_NO.
Definition: namestore.h:174
static void free_qe(struct GNUNET_NAMESTORE_QueueEntry *qe)
Free qe.
#define LOG(kind,...)
Definition: namestore_api.c:41
struct GNUNET_NAMESTORE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE.
Definition: namestore.h:153
const char * name
struct GNUNET_CRYPTO_EcdsaPrivateKey private_key
The private key of the authority.
Definition: namestore.h:179
static struct GNUNET_NAMESTORE_QueueEntry * find_qe(struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
Find the queue entry that matches the rid.
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 492 of file namestore_api.c.

References check_rd(), RecordResultMessage::gns_header, GNUNET_break, GNUNET_memcmp, GNUNET_SYSERR, GNUNET_NAMESTORE_Header::header, name, RecordResultMessage::name_len, RecordResultMessage::private_key, RecordResultMessage::rd_count, RecordResultMessage::rd_len, RecordResultMessage::reserved, and GNUNET_MessageHeader::size.

493 {
494  static struct GNUNET_CRYPTO_EcdsaPrivateKey priv_dummy;
495  const char *name;
496  size_t msg_len;
497  size_t name_len;
498  size_t rd_len;
499 
500  (void) cls;
501  rd_len = ntohs (msg->rd_len);
502  msg_len = ntohs (msg->gns_header.header.size);
503  name_len = ntohs (msg->name_len);
504  if (0 != ntohs (msg->reserved))
505  {
506  GNUNET_break (0);
507  return GNUNET_SYSERR;
508  }
509  if (msg_len != sizeof(struct RecordResultMessage) + name_len + rd_len)
510  {
511  GNUNET_break (0);
512  return GNUNET_SYSERR;
513  }
514  name = (const char *) &msg[1];
515  if ((0 == name_len) || ('\0' != name[name_len - 1]))
516  {
517  GNUNET_break (0);
518  return GNUNET_SYSERR;
519  }
520  if (0 == GNUNET_memcmp (&msg->private_key, &priv_dummy))
521  {
522  GNUNET_break (0);
523  return GNUNET_SYSERR;
524  }
525  return check_rd (rd_len, &name[name_len], ntohs (msg->rd_count));
526 }
uint16_t reserved
always zero (for alignment)
Definition: namestore.h:281
Private ECC key encoded for transmission.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
uint16_t name_len
Name length.
Definition: namestore.h:266
struct GNUNET_MessageHeader header
header.type will be GNUNET_MESSAGE_TYPE_NAMESTORE_* header.size will be message size ...
Definition: namestore.h:46
struct GNUNET_CRYPTO_EcdsaPrivateKey private_key
The private key of the authority.
Definition: namestore.h:286
static int check_rd(size_t rd_len, const void *rd_buf, unsigned int rd_count)
Check that rd_buf of lenght rd_len contains rd_count records.
uint16_t rd_count
Number of records contained.
Definition: namestore.h:276
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
uint16_t rd_len
Length of serialized record data.
Definition: namestore.h:271
struct GNUNET_NAMESTORE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT.
Definition: namestore.h:261
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
const char * name
Record is returned from the namestore (as authority).
Definition: namestore.h:256
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 537 of file namestore_api.c.

References find_qe(), find_zi(), force_reconnect(), free_qe(), RecordResultMessage::gns_header, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_GNSRECORD_records_deserialize(), GNUNET_OK, GNUNET_NAMESTORE_QueueEntry::h, LOG, name, RecordResultMessage::name_len, RecordResultMessage::private_key, GNUNET_NAMESTORE_QueueEntry::proc, GNUNET_NAMESTORE_ZoneIterator::proc, GNUNET_NAMESTORE_QueueEntry::proc_cls, GNUNET_NAMESTORE_ZoneIterator::proc_cls, qe, GNUNET_NAMESTORE_Header::r_id, RecordResultMessage::rd_count, and RecordResultMessage::rd_len.

538 {
539  struct GNUNET_NAMESTORE_Handle *h = cls;
542  const char *name;
543  const char *rd_tmp;
544  size_t name_len;
545  size_t rd_len;
546  unsigned int rd_count;
547 
548  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT\n");
549  rd_len = ntohs (msg->rd_len);
550  rd_count = ntohs (msg->rd_count);
551  name_len = ntohs (msg->name_len);
552  ze = find_zi (h, ntohl (msg->gns_header.r_id));
553  qe = find_qe (h, ntohl (msg->gns_header.r_id));
554  if ((NULL == ze) && (NULL == qe))
555  return; /* rid not found */
556  if ((NULL != ze) && (NULL != qe))
557  {
558  GNUNET_break (0); /* rid ambigous */
559  force_reconnect (h);
560  return;
561  }
562  name = (const char *) &msg[1];
563  rd_tmp = &name[name_len];
564  {
565  struct GNUNET_GNSRECORD_Data rd[rd_count];
566 
567  GNUNET_assert (
568  GNUNET_OK ==
569  GNUNET_GNSRECORD_records_deserialize (rd_len, rd_tmp, rd_count, rd));
570  if (0 == name_len)
571  name = NULL;
572  if (NULL != qe)
573  {
574  if (NULL != qe->proc)
575  qe->proc (qe->proc_cls,
576  &msg->private_key,
577  name,
578  rd_count,
579  (rd_count > 0) ? rd : NULL);
580  free_qe (qe);
581  return;
582  }
583  if (NULL != ze)
584  {
585  if (NULL != ze->proc)
586  ze->proc (ze->proc_cls, &msg->private_key, name, rd_count, rd);
587  return;
588  }
589  }
590  GNUNET_assert (0);
591 }
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
GNUNET_NAMESTORE_RecordMonitor proc
Function to call with the records we get back; or NULL.
Definition: namestore_api.c:83
GNUNET_NAMESTORE_RecordMonitor proc
The continuation to call with the results.
uint32_t r_id
Request ID in NBO.
Definition: namestore.h:51
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void * proc_cls
Closure for proc.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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.
void * proc_cls
Closure for proc.
Definition: namestore_api.c:88
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
uint16_t name_len
Name length.
Definition: namestore.h:266
struct GNUNET_CRYPTO_EcdsaPrivateKey private_key
The private key of the authority.
Definition: namestore.h:286
Handle for a zone iterator operation.
uint16_t rd_count
Number of records contained.
Definition: namestore.h:276
Connection to the NAMESTORE service.
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.
An QueueEntry used to store information for a pending NAMESTORE record operation. ...
Definition: namestore_api.c:53
uint16_t rd_len
Length of serialized record data.
Definition: namestore.h:271
struct GNUNET_NAMESTORE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT.
Definition: namestore.h:261
static void free_qe(struct GNUNET_NAMESTORE_QueueEntry *qe)
Free qe.
#define LOG(kind,...)
Definition: namestore_api.c:41
const char * name
static struct GNUNET_NAMESTORE_QueueEntry * find_qe(struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
Find the queue entry that matches the rid.
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 602 of file namestore_api.c.

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, GNUNET_NAMESTORE_QueueEntry::h, LOG, qe, and GNUNET_NAMESTORE_Header::r_id.

603 {
604  struct GNUNET_NAMESTORE_Handle *h = cls;
607 
608  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT_END\n");
609  ze = find_zi (h, ntohl (msg->r_id));
610  qe = find_qe (h, ntohl (msg->r_id));
611  if ((NULL == ze) && (NULL == qe))
612  return; /* rid not found */
613  if ((NULL != ze) && (NULL != qe))
614  {
615  GNUNET_break (0); /* rid ambigous */
616  force_reconnect (h);
617  return;
618  }
619  LOG (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration completed!\n");
620  if (NULL == ze)
621  {
622  GNUNET_break (0);
623  force_reconnect (h);
624  return;
625  }
626  if (NULL != ze->finish_cb)
627  ze->finish_cb (ze->finish_cb_cls);
628  free_ze (ze);
629 }
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
GNUNET_SCHEDULER_TaskCallback finish_cb
Function to call on completion.
uint32_t r_id
Request ID in NBO.
Definition: namestore.h:51
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static void free_ze(struct GNUNET_NAMESTORE_ZoneIterator *ze)
Free ze.
Handle for a zone iterator operation.
Connection to the NAMESTORE service.
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.
An QueueEntry used to store information for a pending NAMESTORE record operation. ...
Definition: namestore_api.c:53
#define LOG(kind,...)
Definition: namestore_api.c:41
void * finish_cb_cls
Closure for error_cb.
static struct GNUNET_NAMESTORE_QueueEntry * find_qe(struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
Find the queue entry that matches the rid.
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 641 of file namestore_api.c.

References check_rd(), ZoneToNameResponseMessage::gns_header, GNUNET_break, GNUNET_OK, GNUNET_SYSERR, GNUNET_NAMESTORE_Header::header, ZoneToNameResponseMessage::name_len, ZoneToNameResponseMessage::rd_count, ZoneToNameResponseMessage::rd_len, ZoneToNameResponseMessage::res, and GNUNET_MessageHeader::size.

643 {
644  size_t name_len;
645  size_t rd_ser_len;
646  const char *name_tmp;
647 
648  (void) cls;
649  if (GNUNET_OK != ntohs (msg->res))
650  return GNUNET_OK;
651  name_len = ntohs (msg->name_len);
652  rd_ser_len = ntohs (msg->rd_len);
653  if (ntohs (msg->gns_header.header.size) !=
654  sizeof(struct ZoneToNameResponseMessage) + name_len + rd_ser_len)
655  {
656  GNUNET_break (0);
657  return GNUNET_SYSERR;
658  }
659  name_tmp = (const char *) &msg[1];
660  if ((name_len > 0) && ('\0' != name_tmp[name_len - 1]))
661  {
662  GNUNET_break (0);
663  return GNUNET_SYSERR;
664  }
665  return check_rd (rd_ser_len, &name_tmp[name_len], ntohs (msg->rd_count));
666 }
uint16_t name_len
Length of the name.
Definition: namestore.h:223
int16_t res
result in NBO: GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error ...
Definition: namestore.h:239
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
uint16_t rd_count
Number of records contained.
Definition: namestore.h:233
struct GNUNET_MessageHeader header
header.type will be GNUNET_MESSAGE_TYPE_NAMESTORE_* header.size will be message size ...
Definition: namestore.h:46
static int check_rd(size_t rd_len, const void *rd_buf, unsigned int rd_count)
Check that rd_buf of lenght rd_len contains rd_count records.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_NAMESTORE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE.
Definition: namestore.h:218
Respone for zone to name lookup.
Definition: namestore.h:213
uint16_t rd_len
Length of serialized record data.
Definition: namestore.h:228
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 677 of file namestore_api.c.

References GNUNET_NAMESTORE_QueueEntry::error_cb, GNUNET_NAMESTORE_QueueEntry::error_cb_cls, find_qe(), force_reconnect(), free_qe(), ZoneToNameResponseMessage::gns_header, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_GNSRECORD_records_deserialize(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, GNUNET_NAMESTORE_QueueEntry::h, LOG, ZoneToNameResponseMessage::name_len, GNUNET_NAMESTORE_QueueEntry::proc, GNUNET_NAMESTORE_QueueEntry::proc_cls, qe, GNUNET_NAMESTORE_Header::r_id, ZoneToNameResponseMessage::rd_count, ZoneToNameResponseMessage::rd_len, res, ZoneToNameResponseMessage::res, and ZoneToNameResponseMessage::zone.

679 {
680  struct GNUNET_NAMESTORE_Handle *h = cls;
682  int res;
683  size_t name_len;
684  size_t rd_ser_len;
685  unsigned int rd_count;
686  const char *name_tmp;
687  const char *rd_tmp;
688 
689  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME_RESPONSE\n");
690  qe = find_qe (h, ntohl (msg->gns_header.r_id));
691  res = ntohs (msg->res);
692  switch (res)
693  {
694  case GNUNET_SYSERR:
696  "An error occurred during zone to name operation\n");
697  break;
698 
699  case GNUNET_NO:
701  "Namestore has no result for zone to name mapping \n");
702  if (NULL != qe->proc)
703  qe->proc (qe->proc_cls, &msg->zone, NULL, 0, NULL);
704  free_qe (qe);
705  return;
706 
707  case GNUNET_YES:
709  "Namestore has result for zone to name mapping \n");
710  name_len = ntohs (msg->name_len);
711  rd_count = ntohs (msg->rd_count);
712  rd_ser_len = ntohs (msg->rd_len);
713  name_tmp = (const char *) &msg[1];
714  rd_tmp = &name_tmp[name_len];
715  {
716  struct GNUNET_GNSRECORD_Data rd[rd_count];
717 
720  rd_tmp,
721  rd_count,
722  rd));
723  /* normal end, call continuation with result */
724  if (NULL != qe->proc)
725  qe->proc (qe->proc_cls, &msg->zone, name_tmp, rd_count, rd);
726  /* return is important here: break would call continuation with error! */
727  free_qe (qe);
728  return;
729  }
730 
731  default:
732  GNUNET_break (0);
733  force_reconnect (h);
734  return;
735  }
736  /* error case, call continuation with error */
737  if (NULL != qe->error_cb)
738  qe->error_cb (qe->error_cb_cls);
739  free_qe (qe);
740 }
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
GNUNET_NAMESTORE_RecordMonitor proc
Function to call with the records we get back; or NULL.
Definition: namestore_api.c:83
uint32_t r_id
Request ID in NBO.
Definition: namestore.h:51
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
GNUNET_SCHEDULER_TaskCallback error_cb
Function to call on errors.
Definition: namestore_api.c:93
uint16_t name_len
Length of the name.
Definition: namestore.h:223
int16_t res
result in NBO: GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error ...
Definition: namestore.h:239
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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.
void * proc_cls
Closure for proc.
Definition: namestore_api.c:88
void * error_cb_cls
Closure for error_cb.
Definition: namestore_api.c:98
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
uint16_t rd_count
Number of records contained.
Definition: namestore.h:233
Connection to the NAMESTORE service.
static void force_reconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from service and then reconnect.
static int res
struct GNUNET_CRYPTO_EcdsaPrivateKey zone
The private key of the zone that contained the name.
Definition: namestore.h:244
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
An QueueEntry used to store information for a pending NAMESTORE record operation. ...
Definition: namestore_api.c:53
static void free_qe(struct GNUNET_NAMESTORE_QueueEntry *qe)
Free qe.
#define LOG(kind,...)
Definition: namestore_api.c:41
struct GNUNET_NAMESTORE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE.
Definition: namestore.h:218
uint16_t rd_len
Length of serialized record data.
Definition: namestore.h:228
#define GNUNET_YES
Definition: gnunet_common.h:77
static struct GNUNET_NAMESTORE_QueueEntry * find_qe(struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
Find the queue entry that matches the rid.
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 752 of file namestore_api.c.

References force_reconnect(), and GNUNET_NAMESTORE_QueueEntry::h.

Referenced by reconnect().

753 {
754  struct GNUNET_NAMESTORE_Handle *h = cls;
755 
756  (void) error;
757  force_reconnect (h);
758 }
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
Connection to the NAMESTORE service.
static void force_reconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from service and then 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 767 of file namestore_api.c.

References GNUNET_NAMESTORE_Handle::cfg, GNUNET_NAMESTORE_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(), GNUNET_NAMESTORE_Handle::mq, mq_error_handler(), GNUNET_NAMESTORE_QueueEntry::next, GNUNET_NAMESTORE_ZoneIterator::next, GNUNET_NAMESTORE_Handle::op_head, qe, and GNUNET_NAMESTORE_Handle::z_head.

Referenced by GNUNET_NAMESTORE_connect(), and reconnect_task().

768 {
770  { GNUNET_MQ_hd_fixed_size (record_store_response,
773  h),
774  GNUNET_MQ_hd_var_size (zone_to_name_response,
777  h),
778  GNUNET_MQ_hd_var_size (record_result,
780  struct RecordResultMessage,
781  h),
782  GNUNET_MQ_hd_fixed_size (record_result_end,
785  h),
786  GNUNET_MQ_hd_var_size (lookup_result,
789  h),
793 
794  GNUNET_assert (NULL == h->mq);
795  h->mq =
796  GNUNET_CLIENT_connect (h->cfg, "namestore", handlers, &mq_error_handler, h);
797  if (NULL == h->mq)
798  return;
799  /* re-transmit pending requests that waited for a reconnect... */
800  for (it = h->z_head; NULL != it; it = it->next)
801  {
802  GNUNET_MQ_send (h->mq, it->env);
803  it->env = NULL;
804  }
805  for (qe = h->op_head; NULL != qe; qe = qe->next)
806  {
807  GNUNET_MQ_send (h->mq, qe->env);
808  qe->env = NULL;
809  }
810 }
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
struct GNUNET_MQ_Envelope * env
Envelope of the message to send to the service, if not yet sent.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE
Service to client: result of zone-to-name lookup.
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_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END
Service to client: end of list of results.
Handle for a zone iterator operation.
struct GNUNET_NAMESTORE_QueueEntry * next
Kept in a DLL.
Definition: namestore_api.c:58
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
struct GNUNET_MQ_Handle * mq
Connection to the service (if available).
struct GNUNET_MQ_Envelope * env
Envelope of the message to send to the service, if not yet sent.
Message handler for a specific message type.
struct GNUNET_NAMESTORE_ZoneIterator * next
Kept in a DLL.
An QueueEntry used to store information for a pending NAMESTORE record operation. ...
Definition: namestore_api.c:53
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE
Service to client: lookup label.
Respone for zone to name lookup.
Definition: namestore.h:213
Response to a record storage request.
Definition: namestore.h:105
struct GNUNET_NAMESTORE_QueueEntry * op_head
Head of pending namestore queue entries.
struct GNUNET_NAMESTORE_ZoneIterator * z_head
Head of pending namestore zone iterator entries.
Generic namestore message with op id.
Definition: namestore.h:40
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:353
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT
Service to client: here is a (plaintext) record you requested.
Record is returned from the namestore (as authority).
Definition: namestore.h:256
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...
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
Lookup a label.
Definition: namestore.h:148
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE
Service to client: result of store operation.
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 819 of file namestore_api.c.

References GNUNET_NAMESTORE_QueueEntry::h, reconnect(), and GNUNET_NAMESTORE_Handle::reconnect_task.

Referenced by force_reconnect().

820 {
821  struct GNUNET_NAMESTORE_Handle *h = cls;
822 
823  h->reconnect_task = NULL;
824  reconnect (h);
825 }
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
Connection to the NAMESTORE service.
static void reconnect(struct GNUNET_NAMESTORE_Handle *h)
Reconnect to namestore service.
struct GNUNET_SCHEDULER_Task * reconnect_task
Reconnect task.
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 872 of file namestore_api.c.

References GNUNET_NAMESTORE_Handle::last_op_id_used.

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

873 {
874  return h->last_op_id_used++;
875 }
uint32_t last_op_id_used
The last operation id used for a NAMESTORE operation.
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 947 of file namestore_api.c.

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

Referenced by GNUNET_NAMESTORE_records_store().

948 {
949  struct GNUNET_NAMESTORE_QueueEntry *qe = cls;
950 
951  qe->timeout_task = NULL;
953  "Did not receive response from namestore after %s!\n",
955  GNUNET_YES));
956  if (NULL != qe->cont)
957  {
958  qe->cont (qe->cont_cls, GNUNET_SYSERR, "timeout");
959  qe->cont = NULL;
960  }
962 }
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
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:687
#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
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
An QueueEntry used to store information for a pending NAMESTORE record operation. ...
Definition: namestore_api.c:53
GNUNET_NAMESTORE_ContinuationWithStatus cont
Continuation to call.
Definition: namestore_api.c:73
#define LOG(kind,...)
Definition: namestore_api.c:41
void * cont_cls
Closure for cont.
Definition: namestore_api.c:78
struct GNUNET_SCHEDULER_Task * timeout_task
Task scheduled to warn us if the namestore is way too slow.
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the call graph for this function:
Here is the caller graph for this function: