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

406 {
407  struct GNUNET_NAMECACHE_Handle *h;
408 
409  h = GNUNET_new (struct GNUNET_NAMECACHE_Handle);
410  h->cfg = cfg;
411  reconnect (h);
412  if (NULL == h->mq)
413  {
414  GNUNET_free (h);
415  return NULL;
416  }
417  return h;
418 }
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 428 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().

429 {
431 
432  GNUNET_break (NULL == h->op_head);
433  while (NULL != (q = h->op_head))
434  {
436  h->op_tail,
437  q);
438  GNUNET_free (q);
439  }
440  if (NULL != h->mq)
441  {
442  GNUNET_MQ_destroy (h->mq);
443  h->mq = NULL;
444  }
445  if (NULL != h->reconnect_task)
446  {
448  h->reconnect_task = NULL;
449  }
450  GNUNET_free (h);
451 }
#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:837
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:972
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 465 of file namecache_api.c.

References GNUNET_NAMECACHE_QueueEntry::cont, GNUNET_NAMECACHE_QueueEntry::cont_cls, env, get_op_id(), BlockCacheMessage::gns_header, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_GNSRECORD_block_get_size(), 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, qe, and GNUNET_NAMECACHE_Header::r_id.

Referenced by handle_dht_response(), and refresh_block().

469 {
471  struct BlockCacheMessage *msg;
472  struct GNUNET_MQ_Envelope *env;
473  uint32_t rid;
474  size_t blen;
475 
476  if (NULL == h->mq)
477  return NULL;
478  blen = GNUNET_GNSRECORD_block_get_size (block);
479  rid = get_op_id (h);
481  qe->nsh = h;
482  qe->cont = cont;
483  qe->cont_cls = cont_cls;
484  qe->op_id = rid;
486  h->op_tail,
487  qe);
488  /* send msg */
489  env = GNUNET_MQ_msg_extra (msg,
490  blen,
492  msg->gns_header.r_id = htonl (rid);
493  GNUNET_memcpy (&msg[1],
494  block,
495  blen);
496  GNUNET_MQ_send (h->mq,
497  env);
498  return qe;
499 }
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
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_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.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
#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
size_t GNUNET_GNSRECORD_block_get_size(const struct GNUNET_GNSRECORD_Block *block)
Returns the length of this block in bytes.
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_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:355
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 514 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().

518 {
520  struct LookupBlockMessage *msg;
521  struct GNUNET_MQ_Envelope *env;
522  uint32_t rid;
523 
524  if (NULL == h->mq)
525  return NULL;
527  "Looking for block under %s\n",
528  GNUNET_h2s (derived_hash));
529  rid = get_op_id (h);
531  qe->nsh = h;
532  qe->block_proc = proc;
533  qe->block_proc_cls = proc_cls;
534  qe->op_id = rid;
536  h->op_tail,
537  qe);
538  env = GNUNET_MQ_msg (msg,
540  msg->gns_header.r_id = htonl (rid);
541  msg->query = *derived_hash;
542  GNUNET_MQ_send (h->mq,
543  env);
544  return qe;
545 }
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:355
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 555 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().

556 {
557  struct GNUNET_NAMECACHE_Handle *h = qe->nsh;
558 
560  h->op_tail,
561  qe);
562  GNUNET_free (qe);
563 }
#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: