GNUnet  0.11.x
Macros | Typedefs | Functions
Name Cache service

Store naming information on a GNUnet node. More...

Macros

#define GNUNET_NAMECACHE_MAX_VALUE_SIZE   (63 * 1024)
 Maximum size of a value that can be stored in the namecache. More...
 

Typedefs

typedef void(* GNUNET_NAMECACHE_ContinuationWithStatus) (void *cls, int32_t success, const char *emsg)
 Continuation called to notify client about result of the operation. More...
 
typedef void(* GNUNET_NAMECACHE_BlockProcessor) (void *cls, const struct GNUNET_GNSRECORD_Block *block)
 Process a record that was stored in the namecache. More...
 

Functions

struct GNUNET_NAMECACHE_HandleGNUNET_NAMECACHE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Connect to the namecache service. More...
 
void GNUNET_NAMECACHE_disconnect (struct GNUNET_NAMECACHE_Handle *h)
 Disconnect from the namecache service (and free associated resources). More...
 
struct GNUNET_NAMECACHE_QueueEntryGNUNET_NAMECACHE_block_cache (struct GNUNET_NAMECACHE_Handle *h, const struct GNUNET_GNSRECORD_Block *block, GNUNET_NAMECACHE_ContinuationWithStatus cont, void *cont_cls)
 Store an item in the namecache. More...
 
struct GNUNET_NAMECACHE_QueueEntryGNUNET_NAMECACHE_lookup_block (struct GNUNET_NAMECACHE_Handle *h, const struct GNUNET_HashCode *derived_hash, GNUNET_NAMECACHE_BlockProcessor proc, void *proc_cls)
 Get a result for a particular key from the namecache. More...
 
void GNUNET_NAMECACHE_cancel (struct GNUNET_NAMECACHE_QueueEntry *qe)
 Cancel a namecache operation. More...
 

Detailed Description

Store naming information on a GNUnet node.

Naming information can either be records for which this peer/user is authoritative, or blocks which are cached, encrypted naming data from other peers.

See also
Documentation

Macro Definition Documentation

◆ GNUNET_NAMECACHE_MAX_VALUE_SIZE

#define GNUNET_NAMECACHE_MAX_VALUE_SIZE   (63 * 1024)

Maximum size of a value that can be stored in the namecache.

Definition at line 67 of file gnunet_namecache_service.h.

Typedef Documentation

◆ GNUNET_NAMECACHE_ContinuationWithStatus

typedef void(* GNUNET_NAMECACHE_ContinuationWithStatus) (void *cls, int32_t success, const char *emsg)

Continuation called to notify client about result of the operation.

Parameters
clsclosure
successGNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) GNUNET_NO if content was already there or not found GNUNET_YES (or other positive value) on success
emsgNULL on success, otherwise an error message

Definition at line 102 of file gnunet_namecache_service.h.

◆ GNUNET_NAMECACHE_BlockProcessor

typedef void(* GNUNET_NAMECACHE_BlockProcessor) (void *cls, const struct GNUNET_GNSRECORD_Block *block)

Process a record that was stored in the namecache.

Parameters
clsclosure
blockblock that was stored in the namecache

Definition at line 131 of file gnunet_namecache_service.h.

Function Documentation

◆ GNUNET_NAMECACHE_connect()

struct GNUNET_NAMECACHE_Handle* GNUNET_NAMECACHE_connect ( const struct GNUNET_CONFIGURATION_Handle cfg)

Connect to the namecache service.

Parameters
cfgconfiguration to use
Returns
handle to use to access the service

Connect to the namecache service.

Parameters
cfgconfiguration to use
Returns
handle to the GNS service, or NULL on error

Definition at line 413 of file namecache_api.c.

References cfg, GNUNET_NAMECACHE_Handle::cfg, GNUNET_free, GNUNET_new, h, GNUNET_NAMECACHE_Handle::mq, and reconnect().

Referenced by run().

414 {
415  struct GNUNET_NAMECACHE_Handle *h;
416 
417  h = GNUNET_new (struct GNUNET_NAMECACHE_Handle);
418  h->cfg = cfg;
419  reconnect (h);
420  if (NULL == h->mq)
421  {
422  GNUNET_free (h);
423  return NULL;
424  }
425  return h;
426 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: namecache_api.c:99
static void reconnect(struct GNUNET_NAMECACHE_Handle *h)
Reconnect to namecache service.
struct GNUNET_MQ_Handle * mq
Message queue to service.
Connection to the NAMECACHE service.
Definition: namecache_api.c:94
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_NAMECACHE_disconnect()

void GNUNET_NAMECACHE_disconnect ( struct GNUNET_NAMECACHE_Handle h)

Disconnect from the namecache service (and free associated resources).

Must not be called from within operation callbacks of the API.

Parameters
hhandle to the namecache
hhandle to the namecache

Definition at line 436 of file namecache_api.c.

References GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_cancel(), GNUNET_NAMECACHE_Handle::mq, GNUNET_NAMECACHE_Handle::op_head, GNUNET_NAMECACHE_Handle::op_tail, q, and GNUNET_NAMECACHE_Handle::reconnect_task.

Referenced by cleanup_task(), do_shutdown(), and shutdown_task().

437 {
439 
440  GNUNET_break (NULL == h->op_head);
441  while (NULL != (q = h->op_head))
442  {
444  h->op_tail,
445  q);
446  GNUNET_free (q);
447  }
448  if (NULL != h->mq)
449  {
450  GNUNET_MQ_destroy (h->mq);
451  h->mq = NULL;
452  }
453  if (NULL != h->reconnect_task)
454  {
456  h->reconnect_task = NULL;
457  }
458  GNUNET_free (h);
459 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_NAMECACHE_QueueEntry * op_tail
Tail of pending namecache queue entries.
struct GNUNET_SCHEDULER_Task * reconnect_task
Reconnect task.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
struct GNUNET_MQ_Handle * mq
Message queue to service.
struct GNUNET_NAMECACHE_QueueEntry * op_head
Head of pending namecache queue entries.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
An QueueEntry used to store information for a pending NAMECACHE record operation. ...
Definition: namecache_api.c:47
#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:

◆ GNUNET_NAMECACHE_block_cache()

struct GNUNET_NAMECACHE_QueueEntry* GNUNET_NAMECACHE_block_cache ( struct GNUNET_NAMECACHE_Handle h,
const struct GNUNET_GNSRECORD_Block block,
GNUNET_NAMECACHE_ContinuationWithStatus  cont,
void *  cont_cls 
)

Store an item in the namecache.

If the item is already present, it is replaced with the new record.

Parameters
hhandle to the namecache
blockblock to store
contcontinuation to call when done
cont_clsclosure for cont
Returns
handle to abort the request, NULL on error

Definition at line 473 of file namecache_api.c.

References GNUNET_NAMECACHE_QueueEntry::cont, GNUNET_NAMECACHE_QueueEntry::cont_cls, BlockCacheMessage::derived_key, GNUNET_GNSRECORD_Block::derived_key, env, GNUNET_GNSRECORD_Block::expiration_time, BlockCacheMessage::expire, get_op_id(), BlockCacheMessage::gns_header, GNUNET_assert, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_new, h, GNUNET_NAMECACHE_Handle::mq, msg, GNUNET_NAMECACHE_QueueEntry::nsh, GNUNET_NAMECACHE_Handle::op_head, GNUNET_NAMECACHE_QueueEntry::op_id, GNUNET_NAMECACHE_Handle::op_tail, GNUNET_GNSRECORD_Block::purpose, qe, GNUNET_NAMECACHE_Header::r_id, BlockCacheMessage::signature, GNUNET_GNSRECORD_Block::signature, and GNUNET_CRYPTO_EccSignaturePurpose::size.

Referenced by handle_dht_response(), and refresh_block().

477 {
479  struct BlockCacheMessage *msg;
480  struct GNUNET_MQ_Envelope *env;
481  uint32_t rid;
482  size_t blen;
483 
484  if (NULL == h->mq)
485  return NULL;
486  blen = ntohl (block->purpose.size);
487  GNUNET_assert (blen > (sizeof(struct GNUNET_TIME_AbsoluteNBO)
488  + sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)));
489  blen -= (sizeof(struct GNUNET_TIME_AbsoluteNBO)
490  + sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose));
491  rid = get_op_id (h);
493  qe->nsh = h;
494  qe->cont = cont;
495  qe->cont_cls = cont_cls;
496  qe->op_id = rid;
498  h->op_tail,
499  qe);
500  /* send msg */
501  env = GNUNET_MQ_msg_extra (msg,
502  blen,
504  msg->gns_header.r_id = htonl (rid);
505  msg->expire = block->expiration_time;
506  msg->signature = block->signature;
507  msg->derived_key = block->derived_key;
508  GNUNET_memcpy (&msg[1],
509  &block[1],
510  blen);
511  GNUNET_MQ_send (h->mq,
512  env);
513  return qe;
514 }
struct GNUNET_TIME_AbsoluteNBO expiration_time
Expiration time of the block.
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
#define GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE
Client to service: cache a block.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_CRYPTO_EcdsaPublicKey derived_key
Derived public key.
Definition: namecache.h:124
uint32_t op_id
The operation id this zone iteration operation has.
Definition: namecache_api.c:87
struct GNUNET_NAMECACHE_QueueEntry * op_tail
Tail of pending namecache queue entries.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
struct GNUNET_NAMECACHE_Handle * nsh
Main handle to access the namecache.
Definition: namecache_api.c:62
Cache a record in the namecache.
Definition: namecache.h:104
void * cont_cls
Closure for cont.
Definition: namecache_api.c:72
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!)...
static uint32_t get_op_id(struct GNUNET_NAMECACHE_Handle *h)
Get a fresh operation id to distinguish between namecache requests.
struct GNUNET_MQ_Handle * mq
Message queue to service.
struct GNUNET_TIME_AbsoluteNBO expire
Expiration time.
Definition: namecache.h:114
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature of the block.
struct GNUNET_NAMECACHE_QueueEntry * op_head
Head of pending namecache queue entries.
uint32_t r_id
Request ID in NBO.
Definition: namecache.h:51
An QueueEntry used to store information for a pending NAMECACHE record operation. ...
Definition: namecache_api.c:47
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
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature.
Definition: namecache.h:119
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Number of bytes signed; also specifies the number of bytes of encrypted data that follow...
struct GNUNET_CRYPTO_EcdsaPublicKey derived_key
Derived key used for signing; hash of this is the query.
struct GNUNET_NAMECACHE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE.
Definition: namecache.h:109
GNUNET_NAMECACHE_ContinuationWithStatus cont
Continuation to call.
Definition: namecache_api.c:67
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_NAMECACHE_lookup_block()

struct GNUNET_NAMECACHE_QueueEntry* GNUNET_NAMECACHE_lookup_block ( struct GNUNET_NAMECACHE_Handle h,
const struct GNUNET_HashCode derived_hash,
GNUNET_NAMECACHE_BlockProcessor  proc,
void *  proc_cls 
)

Get a result for a particular key from the namecache.

The processor will only be called once.

Parameters
hhandle to the namecache
derived_hashhash of zone key combined with name to lookup then at the end once with NULL
procfunction to call on the matching block, or with NULL if there is no matching block
proc_clsclosure for proc
Returns
a handle that can be used to cancel, NULL on error

The processor will only be called once.

Parameters
hhandle to the namecache
derived_hashhash of zone key combined with name to lookup
procfunction to call on the matching block, or with NULL if there is no matching block
proc_clsclosure for proc
Returns
a handle that can be used to cancel, NULL on error

Definition at line 529 of file namecache_api.c.

References GNUNET_NAMECACHE_QueueEntry::block_proc, GNUNET_NAMECACHE_QueueEntry::block_proc_cls, env, get_op_id(), LookupBlockMessage::gns_header, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_new, h, LOG, GNUNET_NAMECACHE_Handle::mq, msg, GNUNET_NAMECACHE_QueueEntry::nsh, GNUNET_NAMECACHE_Handle::op_head, GNUNET_NAMECACHE_QueueEntry::op_id, GNUNET_NAMECACHE_Handle::op_tail, qe, LookupBlockMessage::query, and GNUNET_NAMECACHE_Header::r_id.

Referenced by recursive_gns_resolution_namecache(), and run().

533 {
535  struct LookupBlockMessage *msg;
536  struct GNUNET_MQ_Envelope *env;
537  uint32_t rid;
538 
539  if (NULL == h->mq)
540  return NULL;
542  "Looking for block under %s\n",
543  GNUNET_h2s (derived_hash));
544  rid = get_op_id (h);
546  qe->nsh = h;
547  qe->block_proc = proc;
548  qe->block_proc_cls = proc_cls;
549  qe->op_id = rid;
551  h->op_tail,
552  qe);
553  env = GNUNET_MQ_msg (msg,
555  msg->gns_header.r_id = htonl (rid);
556  msg->query = *derived_hash;
557  GNUNET_MQ_send (h->mq,
558  env);
559  return qe;
560 }
Lookup a block in the namecache.
Definition: namecache.h:58
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
uint32_t op_id
The operation id this zone iteration operation has.
Definition: namecache_api.c:87
struct GNUNET_NAMECACHE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK.
Definition: namecache.h:63
struct GNUNET_NAMECACHE_QueueEntry * op_tail
Tail of pending namecache queue entries.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK
Client to service: lookup block.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
struct GNUNET_NAMECACHE_Handle * nsh
Main handle to access the namecache.
Definition: namecache_api.c:62
void * block_proc_cls
Closure for block_proc.
Definition: namecache_api.c:82
GNUNET_NAMECACHE_BlockProcessor block_proc
Function to call with the blocks we get back; or NULL.
Definition: namecache_api.c:77
static uint32_t get_op_id(struct GNUNET_NAMECACHE_Handle *h)
Get a fresh operation id to distinguish between namecache requests.
struct GNUNET_MQ_Handle * mq
Message queue to service.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
struct GNUNET_HashCode query
The query.
Definition: namecache.h:68
struct GNUNET_NAMECACHE_QueueEntry * op_head
Head of pending namecache queue entries.
uint32_t r_id
Request ID in NBO.
Definition: namecache.h:51
#define LOG(kind,...)
Definition: namecache_api.c:40
An QueueEntry used to store information for a pending NAMECACHE record operation. ...
Definition: namecache_api.c:47
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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_NAMECACHE_cancel()

void GNUNET_NAMECACHE_cancel ( struct GNUNET_NAMECACHE_QueueEntry qe)

Cancel a namecache operation.

The final callback from the operation must not have been done yet. Must be called on any namecache operation that has not yet completed prior to calling GNUNET_NAMECACHE_disconnect.

Parameters
qeoperation to cancel

The final callback from the operation must not have been done yet.

Parameters
qeoperation to cancel

Definition at line 570 of file namecache_api.c.

References GNUNET_CONTAINER_DLL_remove, GNUNET_free, h, GNUNET_NAMECACHE_QueueEntry::nsh, GNUNET_NAMECACHE_Handle::op_head, and GNUNET_NAMECACHE_Handle::op_tail.

Referenced by cleanup_task(), do_shutdown(), GNS_resolver_done(), and GNS_resolver_lookup_cancel().

571 {
572  struct GNUNET_NAMECACHE_Handle *h = qe->nsh;
573 
575  h->op_tail,
576  qe);
577  GNUNET_free (qe);
578 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_NAMECACHE_QueueEntry * op_tail
Tail of pending namecache queue entries.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
struct GNUNET_NAMECACHE_Handle * nsh
Main handle to access the namecache.
Definition: namecache_api.c:62
struct GNUNET_NAMECACHE_QueueEntry * op_head
Head of pending namecache queue entries.
Connection to the NAMECACHE service.
Definition: namecache_api.c:94
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function: