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 101 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 130 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 406 of file namecache_api.c.

407 {
408  struct GNUNET_NAMECACHE_Handle *h;
409 
411  h->cfg = cfg;
412  reconnect (h);
413  if (NULL == h->mq)
414  {
415  GNUNET_free (h);
416  return NULL;
417  }
418  return h;
419 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
static void reconnect(struct GNUNET_NAMECACHE_Handle *h)
Reconnect to namecache service.
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
Definition: arm_api.c:107
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Definition: arm_api.c:112
Connection to the NAMECACHE service.
Definition: namecache_api.c:95

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

Referenced by run().

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 429 of file namecache_api.c.

430 {
432 
433  GNUNET_break (NULL == h->op_head);
434  while (NULL != (q = h->op_head))
435  {
436  GNUNET_CONTAINER_DLL_remove (h->op_head,
437  h->op_tail,
438  q);
439  GNUNET_free (q);
440  }
441  if (NULL != h->mq)
442  {
444  h->mq = NULL;
445  }
446  if (NULL != h->reconnect_task)
447  {
449  h->reconnect_task = NULL;
450  }
451  GNUNET_free (h);
452 }
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:837
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the reconnect task (if any).
Definition: arm_api.c:147
An QueueEntry used to store information for a pending NAMECACHE record operation.
Definition: namecache_api.c:48

References GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_cancel(), h, GNUNET_ARM_Handle::mq, q, and GNUNET_ARM_Handle::reconnect_task.

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

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 466 of file namecache_api.c.

470 {
472  struct BlockCacheMessage *msg;
473  struct GNUNET_MQ_Envelope *env;
474  uint32_t rid;
475  size_t blen;
476 
477  if (NULL == h->mq)
478  return NULL;
479  blen = GNUNET_GNSRECORD_block_get_size (block);
480  rid = get_op_id (h);
482  qe->nsh = h;
483  qe->cont = cont;
484  qe->cont_cls = cont_cls;
485  qe->op_id = rid;
487  h->op_tail,
488  qe);
489  /* send msg */
491  blen,
493  msg->gns_header.r_id = htonl (rid);
494  GNUNET_memcpy (&msg[1],
495  block,
496  blen);
497  GNUNET_MQ_send (h->mq,
498  env);
499  return qe;
500 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
size_t GNUNET_GNSRECORD_block_get_size(const struct GNUNET_GNSRECORD_Block *block)
Returns the length of this block in bytes.
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
#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
#define GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE
Client to service: cache a block.
static uint32_t get_op_id(struct GNUNET_NAMECACHE_Handle *h)
Get a fresh operation id to distinguish between namecache requests.
Cache a record in the namecache.
Definition: namecache.h:105
GNUNET_DATASTORE_ContinuationWithStatus cont
Function to call after transmission of the request.
void * cont_cls
Closure for cont.

References GNUNET_DATASTORE_QueueEntry::cont, GNUNET_DATASTORE_QueueEntry::cont_cls, env, get_op_id(), 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_ARM_Handle::mq, msg, and qe.

Referenced by handle_dht_response(), and refresh_block().

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 515 of file namecache_api.c.

519 {
521  struct LookupBlockMessage *msg;
522  struct GNUNET_MQ_Envelope *env;
523  uint32_t rid;
524 
525  if (NULL == h->mq)
526  return NULL;
528  "Looking for block under %s\n",
529  GNUNET_h2s (derived_hash));
530  rid = get_op_id (h);
532  qe->nsh = h;
533  qe->block_proc = proc;
534  qe->block_proc_cls = proc_cls;
535  qe->op_id = rid;
537  h->op_tail,
538  qe);
539  env = GNUNET_MQ_msg (msg,
541  msg->gns_header.r_id = htonl (rid);
542  msg->query = *derived_hash;
543  GNUNET_MQ_send (h->mq,
544  env);
545  return qe;
546 }
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK
Client to service: lookup block.
#define LOG(kind,...)
Definition: namecache_api.c:40
Lookup a block in the namecache.
Definition: namecache.h:59

References env, get_op_id(), 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_ARM_Handle::mq, msg, and qe.

Referenced by recursive_gns_resolution_namecache(), and run().

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 556 of file namecache_api.c.

557 {
558  struct GNUNET_NAMECACHE_Handle *h = qe->nsh;
559 
560  GNUNET_CONTAINER_DLL_remove (h->op_head,
561  h->op_tail,
562  qe);
563  GNUNET_free (qe);
564 }

References GNUNET_CONTAINER_DLL_remove, GNUNET_free, h, and qe.

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

Here is the caller graph for this function: