GNUnet  0.10.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 132 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 410 of file namecache_api.c.

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

Referenced by run().

411 {
412  struct GNUNET_NAMECACHE_Handle *h;
413 
415  h->cfg = cfg;
416  reconnect(h);
417  if (NULL == h->mq)
418  {
419  GNUNET_free(h);
420  return NULL;
421  }
422  return h;
423 }
#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:94
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: namecache_api.c:97
static void reconnect(struct GNUNET_NAMECACHE_Handle *h)
Reconnect to namecache service.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
struct GNUNET_MQ_Handle * mq
Message queue to service.
Connection to the NAMECACHE service.
Definition: namecache_api.c:93
#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 433 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().

434 {
436 
437  GNUNET_break(NULL == h->op_head);
438  while (NULL != (q = h->op_head))
439  {
441  h->op_tail,
442  q);
443  GNUNET_free(q);
444  }
445  if (NULL != h->mq)
446  {
447  GNUNET_MQ_destroy(h->mq);
448  h->mq = NULL;
449  }
450  if (NULL != h->reconnect_task)
451  {
453  h->reconnect_task = NULL;
454  }
455  GNUNET_free(h);
456 }
#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:821
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:956
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 470 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().

474 {
476  struct BlockCacheMessage *msg;
477  struct GNUNET_MQ_Envelope *env;
478  uint32_t rid;
479  size_t blen;
480 
481  if (NULL == h->mq)
482  return NULL;
483  blen = ntohl(block->purpose.size);
484  GNUNET_assert(blen > (sizeof(struct GNUNET_TIME_AbsoluteNBO) +
485  sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)));
486  blen -= (sizeof(struct GNUNET_TIME_AbsoluteNBO) +
487  sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose));
488  rid = get_op_id(h);
490  qe->nsh = h;
491  qe->cont = cont;
492  qe->cont_cls = cont_cls;
493  qe->op_id = rid;
495  h->op_tail,
496  qe);
497  /* send msg */
498  env = GNUNET_MQ_msg_extra(msg,
499  blen,
501  msg->gns_header.r_id = htonl(rid);
502  msg->expire = block->expiration_time;
503  msg->signature = block->signature;
504  msg->derived_key = block->derived_key;
505  GNUNET_memcpy(&msg[1],
506  &block[1],
507  blen);
508  GNUNET_MQ_send(h->mq,
509  env);
510  return qe;
511 }
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:120
uint32_t op_id
The operation id this zone iteration operation has.
Definition: namecache_api.c:86
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:94
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:61
Cache a record in the namecache.
Definition: namecache.h:101
void * cont_cls
Closure for cont.
Definition: namecache_api.c:71
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:110
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:50
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:351
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature.
Definition: namecache.h:115
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:105
GNUNET_NAMECACHE_ContinuationWithStatus cont
Continuation to call.
Definition: namecache_api.c:66
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 526 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().

530 {
532  struct LookupBlockMessage *msg;
533  struct GNUNET_MQ_Envelope *env;
534  uint32_t rid;
535 
536  if (NULL == h->mq)
537  return NULL;
539  "Looking for block under %s\n",
540  GNUNET_h2s(derived_hash));
541  rid = get_op_id(h);
543  qe->nsh = h;
544  qe->block_proc = proc;
545  qe->block_proc_cls = proc_cls;
546  qe->op_id = rid;
548  h->op_tail,
549  qe);
550  env = GNUNET_MQ_msg(msg,
552  msg->gns_header.r_id = htonl(rid);
553  msg->query = *derived_hash;
554  GNUNET_MQ_send(h->mq,
555  env);
556  return qe;
557 }
Lookup a block in the namecache.
Definition: namecache.h:57
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:86
struct GNUNET_NAMECACHE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK.
Definition: namecache.h:61
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:94
struct GNUNET_NAMECACHE_Handle * nsh
Main handle to access the namecache.
Definition: namecache_api.c:61
void * block_proc_cls
Closure for block_proc.
Definition: namecache_api.c:81
GNUNET_NAMECACHE_BlockProcessor block_proc
Function to call with the blocks we get back; or NULL.
Definition: namecache_api.c:76
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:66
struct GNUNET_NAMECACHE_QueueEntry * op_head
Head of pending namecache queue entries.
uint32_t r_id
Request ID in NBO.
Definition: namecache.h:50
#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:351
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 567 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().

568 {
569  struct GNUNET_NAMECACHE_Handle *h = qe->nsh;
570 
572  h->op_tail,
573  qe);
574  GNUNET_free(qe);
575 }
#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:94
struct GNUNET_NAMECACHE_Handle * nsh
Main handle to access the namecache.
Definition: namecache_api.c:61
struct GNUNET_NAMECACHE_QueueEntry * op_head
Head of pending namecache queue entries.
Connection to the NAMECACHE service.
Definition: namecache_api.c:93
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function: