GNUnet  0.11.x
Data Structures | Macros | Functions | Variables
gnunet-service-namecache.c File Reference

namecache for the GNUnet naming system More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_dnsparser_lib.h"
#include "gnunet_statistics_service.h"
#include "gnunet_namecache_service.h"
#include "gnunet_namecache_plugin.h"
#include "gnunet_signatures.h"
#include "namecache.h"
Include dependency graph for gnunet-service-namecache.c:

Go to the source code of this file.

Data Structures

struct  NamecacheClient
 A namecache client. More...
 
struct  LookupBlockContext
 Context for name lookups passed from handle_lookup_block to handle_lookup_block_it as closure. More...
 

Macros

#define LOG_STRERROR_FILE(kind, syscall, filename)
 

Functions

static void cleanup_task (void *cls)
 Task run during shutdown. More...
 
static void client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *client, void *app_ctx)
 Called whenever a client is disconnected. More...
 
static void * client_connect_cb (void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
 Add a client to our list of active clients. More...
 
static void handle_lookup_block_it (void *cls, const struct GNUNET_GNSRECORD_Block *block)
 A GNUNET_NAMECACHE_BlockCallback for name lookups in handle_lookup_block. More...
 
static void handle_lookup_block (void *cls, const struct LookupBlockMessage *ln_msg)
 Handles a GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK message. More...
 
static int check_block_cache (void *cls, const struct BlockCacheMessage *rp_msg)
 Check a GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE message. More...
 
static void handle_block_cache (void *cls, const struct BlockCacheMessage *rp_msg)
 Handles a GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE message. More...
 
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_SERVICE_Handle *service)
 Process namecache requests. More...
 
 GNUNET_SERVICE_MAIN ("namecache", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_fixed_size(lookup_block, GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK, struct LookupBlockMessage, NULL), GNUNET_MQ_hd_var_size(block_cache, GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE, struct BlockCacheMessage, NULL), GNUNET_MQ_handler_end())
 Define "main" method using service macro. More...
 

Variables

static const struct GNUNET_CONFIGURATION_HandleGSN_cfg
 Configuration handle. More...
 
static struct GNUNET_STATISTICS_Handlestatistics
 Handle to the statistics service. More...
 
static struct GNUNET_NAMECACHE_PluginFunctionsGSN_database
 Database handle. More...
 
static char * db_lib_name
 Name of the database plugin. More...
 

Detailed Description

namecache for the GNUnet naming system

Author
Matthias Wachs
Christian Grothoff

Definition in file gnunet-service-namecache.c.

Macro Definition Documentation

◆ LOG_STRERROR_FILE

#define LOG_STRERROR_FILE (   kind,
  syscall,
  filename 
)
Value:
syscall, \
#define GNUNET_log_from_strerror_file(level, component, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
static char * filename

Definition at line 36 of file gnunet-service-namecache.c.

Function Documentation

◆ cleanup_task()

static void cleanup_task ( void *  cls)
static

Task run during shutdown.

Parameters
clsunused

Definition at line 86 of file gnunet-service-namecache.c.

References db_lib_name, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_PLUGIN_unload(), and GNUNET_STATISTICS_destroy().

Referenced by run().

87 {
89  "Stopping namecache service\n");
90  GNUNET_break (NULL ==
92  GSN_database));
94  db_lib_name = NULL;
95  if (NULL != statistics)
96  {
98  GNUNET_NO);
99  statistics = NULL;
100  }
101 }
#define GNUNET_NO
Definition: gnunet_common.h:78
static char * db_lib_name
Name of the database plugin.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void * GNUNET_PLUGIN_unload(const char *library_name, void *arg)
Unload plugin (runs the "done" callback and returns whatever "done" returned).
Definition: plugin.c:256
static struct GNUNET_STATISTICS_Handle * statistics
Handle to the statistics service.
static struct GNUNET_NAMECACHE_PluginFunctions * GSN_database
Database handle.
#define GNUNET_log(kind,...)
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_disconnect_cb()

static void client_disconnect_cb ( void *  cls,
struct GNUNET_SERVICE_Client client,
void *  app_ctx 
)
static

Called whenever a client is disconnected.

Frees our resources associated with that client.

Parameters
clsclosure
clientidentification of the client
app_ctxthe struct NamecacheClient for this client

Definition at line 113 of file gnunet-service-namecache.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, and nc.

Referenced by run().

116 {
117  struct NamecacheClient *nc = app_ctx;
118 
120  "Client %p disconnected\n",
121  client);
122  GNUNET_free (nc);
123 }
A namecache client.
static struct GNUNET_PEERINFO_NotifyContext * nc
Iterator context.
#define GNUNET_log(kind,...)
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ client_connect_cb()

static void* client_connect_cb ( void *  cls,
struct GNUNET_SERVICE_Client client,
struct GNUNET_MQ_Handle mq 
)
static

Add a client to our list of active clients.

Parameters
clsNULL
clientclient to add
mqqueue to talk to client
Returns
internal namecache client structure for this client

Definition at line 135 of file gnunet-service-namecache.c.

References NamecacheClient::client, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_new, NamecacheClient::mq, and nc.

Referenced by run().

138 {
139  struct NamecacheClient *nc;
140 
142  "Client %p connected\n",
143  client);
144  nc = GNUNET_new (struct NamecacheClient);
145  nc->client = client;
146  nc->mq = mq;
147  return nc;
148 }
struct GNUNET_MQ_Handle * mq
The message queue to talk to client.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_SERVICE_Client * client
The client.
A namecache client.
static struct GNUNET_PEERINFO_NotifyContext * nc
Iterator context.
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define GNUNET_log(kind,...)
Here is the caller graph for this function:

◆ handle_lookup_block_it()

static void handle_lookup_block_it ( void *  cls,
const struct GNUNET_GNSRECORD_Block block 
)
static

A GNUNET_NAMECACHE_BlockCallback for name lookups in handle_lookup_block.

Parameters
clsa struct LookupNameContext * with information about the request
blockthe block

Definition at line 181 of file gnunet-service-namecache.c.

References bsize, LookupBlockResponseMessage::derived_key, GNUNET_GNSRECORD_Block::derived_key, env, GNUNET_GNSRECORD_Block::expiration_time, LookupBlockResponseMessage::expire, LookupBlockResponseMessage::gns_header, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK_RESPONSE, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_STRINGS_absolute_time_to_string(), GNUNET_SYSERR, GNUNET_TIME_absolute_ntoh(), NamecacheClient::mq, LookupBlockContext::nc, GNUNET_GNSRECORD_Block::purpose, GNUNET_NAMECACHE_Header::r_id, LookupBlockContext::request_id, LookupBlockResponseMessage::signature, GNUNET_GNSRECORD_Block::signature, GNUNET_CRYPTO_EccSignaturePurpose::size, and LookupBlockContext::status.

Referenced by handle_lookup_block().

183 {
184  struct LookupBlockContext *lnc = cls;
185  struct GNUNET_MQ_Envelope *env;
186  struct LookupBlockResponseMessage *r;
187  size_t esize;
188  size_t bsize;
189 
190  bsize = ntohl (block->purpose.size);
191  if (bsize <
192  (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + sizeof(struct
194  {
196  "Malformed block.");
197  lnc->status = GNUNET_SYSERR;
198  return;
199  }
200  esize = ntohl (block->purpose.size)
201  - sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
202  - sizeof(struct GNUNET_TIME_AbsoluteNBO);
203  env = GNUNET_MQ_msg_extra (r,
204  esize,
206  r->gns_header.r_id = htonl (lnc->request_id);
207  r->expire = block->expiration_time;
208  r->signature = block->signature;
209  r->derived_key = block->derived_key;
210  GNUNET_memcpy (&r[1],
211  &block[1],
212  esize);
214  "blocks found in cache",
215  1,
216  GNUNET_NO);
218  "Sending NAMECACHE_LOOKUP_BLOCK_RESPONSE message with expiration time %s\n",
221  GNUNET_MQ_send (lnc->nc->mq,
222  env);
223 }
#define GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK_RESPONSE
Service to client: result of block lookup.
struct GNUNET_TIME_AbsoluteNBO expiration_time
Expiration time of the block.
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature.
Definition: namecache.h:90
Lookup response.
Definition: namecache.h:75
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:673
struct GNUNET_MQ_Handle * mq
The message queue to talk to client.
Context for name lookups passed from handle_lookup_block to handle_lookup_block_it as closure...
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
uint32_t request_id
Operation id for the name lookup.
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
static struct GNUNET_STATISTICS_Handle * statistics
Handle to the statistics service.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!)...
static unsigned int bsize
struct GNUNET_NAMECACHE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK_RESPONSE.
Definition: namecache.h:80
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature of the block.
struct GNUNET_CRYPTO_EcdsaPublicKey derived_key
Derived public key.
Definition: namecache.h:95
uint32_t r_id
Request ID in NBO.
Definition: namecache.h:51
#define GNUNET_log(kind,...)
struct GNUNET_TIME_AbsoluteNBO expire
Expiration time.
Definition: namecache.h:85
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
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:742
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Number of bytes signed; also specifies the number of bytes of encrypted data that follow...
struct NamecacheClient * nc
The client to send the response to.
struct GNUNET_CRYPTO_EcdsaPublicKey derived_key
Derived key used for signing; hash of this is the query.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_lookup_block()

static void handle_lookup_block ( void *  cls,
const struct LookupBlockMessage ln_msg 
)
static

Handles a GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK message.

Parameters
clsa struct NamecacheClient *
theinbound message

Definition at line 233 of file gnunet-service-namecache.c.

References NamecacheClient::client, GNUNET_NAMECACHE_PluginFunctions::cls, env, LookupBlockMessage::gns_header, LookupBlockResponseMessage::gns_header, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK_RESPONSE, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_NO, GNUNET_OK, GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_drop(), GNUNET_STATISTICS_update(), GNUNET_SYSERR, handle_lookup_block_it(), GNUNET_NAMECACHE_PluginFunctions::lookup_block, NamecacheClient::mq, nc, LookupBlockContext::nc, LookupBlockMessage::query, GNUNET_NAMECACHE_Header::r_id, LookupBlockContext::request_id, ret, and LookupBlockContext::status.

235 {
236  struct NamecacheClient *nc = cls;
237  struct GNUNET_MQ_Envelope *env;
238  struct LookupBlockContext lnc;
239  struct LookupBlockResponseMessage *zir_end;
240  int ret;
241 
243  "Received NAMECACHE_LOOKUP_BLOCK message\n");
245  "blocks looked up",
246  1,
247  GNUNET_NO);
248  lnc.request_id = ntohl (ln_msg->gns_header.r_id);
249  lnc.nc = nc;
250  lnc.status = GNUNET_OK;
251  if (GNUNET_SYSERR ==
253  &ln_msg->query,
255  &lnc)))
256  {
257  /* internal error (in database plugin); might be best to just hang up on
258  plugin rather than to signal that there are 'no' results, which
259  might also be false... */
260  GNUNET_break (0);
262  return;
263  }
264  if ((0 == ret) || (GNUNET_SYSERR == lnc.status))
265  {
266  /* no records match at all, generate empty response */
268  "Sending empty NAMECACHE_LOOKUP_BLOCK_RESPONSE message\n");
269  env = GNUNET_MQ_msg (zir_end,
271  zir_end->gns_header.r_id = ln_msg->gns_header.r_id;
272  GNUNET_MQ_send (nc->mq,
273  env);
274  }
276 }
#define GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK_RESPONSE
Service to client: result of block lookup.
void * cls
Closure to pass to all plugin functions.
Lookup response.
Definition: namecache.h:75
struct GNUNET_MQ_Handle * mq
The message queue to talk to client.
Context for name lookups passed from handle_lookup_block to handle_lookup_block_it as closure...
struct GNUNET_NAMECACHE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK.
Definition: namecache.h:63
static void handle_lookup_block_it(void *cls, const struct GNUNET_GNSRECORD_Block *block)
A GNUNET_NAMECACHE_BlockCallback for name lookups in handle_lookup_block.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_SERVICE_Client * client
The client.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
A namecache client.
static struct GNUNET_STATISTICS_Handle * statistics
Handle to the statistics service.
static struct GNUNET_NAMECACHE_PluginFunctions * GSN_database
Database handle.
int(* lookup_block)(void *cls, const struct GNUNET_HashCode *query, GNUNET_NAMECACHE_BlockCallback iter, void *iter_cls)
Get the block for a particular zone and label in the datastore.
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2324
struct GNUNET_NAMECACHE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK_RESPONSE.
Definition: namecache.h:80
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static struct GNUNET_PEERINFO_NotifyContext * nc
Iterator context.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct GNUNET_HashCode query
The query.
Definition: namecache.h:68
uint32_t r_id
Request ID in NBO.
Definition: namecache.h:51
#define GNUNET_log(kind,...)
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
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2243
Here is the call graph for this function:

◆ check_block_cache()

static int check_block_cache ( void *  cls,
const struct BlockCacheMessage rp_msg 
)
static

Check a GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE message.

Parameters
clsour struct NamecacheClient
rp_msgmessage to process
Returns
GNUNET_OK (always fine)

Definition at line 287 of file gnunet-service-namecache.c.

References GNUNET_OK.

289 {
290  return GNUNET_OK;
291 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75

◆ handle_block_cache()

static void handle_block_cache ( void *  cls,
const struct BlockCacheMessage rp_msg 
)
static

Handles a GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE message.

Parameters
clsour struct NamecacheClient
rp_msgmessage to process

Definition at line 301 of file gnunet-service-namecache.c.

References GNUNET_NAMECACHE_PluginFunctions::cache_block, NamecacheClient::client, GNUNET_NAMECACHE_PluginFunctions::cls, BlockCacheMessage::derived_key, GNUNET_GNSRECORD_Block::derived_key, env, GNUNET_GNSRECORD_Block::expiration_time, BlockCacheMessage::expire, BlockCacheMessage::gns_header, BlockCacheResponseMessage::gns_header, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE_RESPONSE, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_NO, GNUNET_SERVICE_client_continue(), GNUNET_STATISTICS_update(), GNUNET_STRINGS_absolute_time_to_string(), GNUNET_TIME_absolute_ntoh(), GNUNET_NAMECACHE_Header::header, NamecacheClient::mq, nc, BlockCacheResponseMessage::op_result, GNUNET_GNSRECORD_Block::purpose, GNUNET_NAMECACHE_Header::r_id, res, BlockCacheMessage::signature, GNUNET_GNSRECORD_Block::signature, GNUNET_CRYPTO_EccSignaturePurpose::size, and GNUNET_MessageHeader::size.

303 {
304  struct NamecacheClient *nc = cls;
305  struct GNUNET_MQ_Envelope *env;
306  struct BlockCacheResponseMessage *rpr_msg;
307  struct GNUNET_GNSRECORD_Block *block;
308  size_t esize;
309  int res;
310 
312  "blocks cached",
313  1,
314  GNUNET_NO);
315  esize = ntohs (rp_msg->gns_header.header.size) - sizeof(struct
317  block = GNUNET_malloc (sizeof(struct GNUNET_GNSRECORD_Block) + esize);
318  block->signature = rp_msg->signature;
319  block->derived_key = rp_msg->derived_key;
320  block->purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
321  + sizeof(struct GNUNET_TIME_AbsoluteNBO)
322  + esize);
323  block->expiration_time = rp_msg->expire;
325  "Received NAMECACHE_BLOCK_CACHE message with expiration time %s\n",
328  GNUNET_memcpy (&block[1],
329  &rp_msg[1],
330  esize);
332  block);
333  GNUNET_free (block);
334  env = GNUNET_MQ_msg (rpr_msg,
336  rpr_msg->gns_header.r_id = rp_msg->gns_header.r_id;
337  rpr_msg->op_result = htonl (res);
338  GNUNET_MQ_send (nc->mq,
339  env);
341 }
#define GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE_RESPONSE
Service to client: result of block cache request.
struct GNUNET_TIME_AbsoluteNBO expiration_time
Expiration time of the block.
void * cls
Closure to pass to all plugin functions.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:673
struct GNUNET_MQ_Handle * mq
The message queue to talk to client.
struct GNUNET_CRYPTO_EcdsaPublicKey derived_key
Derived public key.
Definition: namecache.h:124
Response to a request to cache a block.
Definition: namecache.h:133
struct GNUNET_MessageHeader header
header.type will be GNUNET_MESSAGE_TYPE_NAMECACHE_* header.size will be message size ...
Definition: namecache.h:46
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_NO
Definition: gnunet_common.h:78
struct GNUNET_SERVICE_Client * client
The client.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
Information we have in an encrypted block with record data (i.e.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
int(* cache_block)(void *cls, const struct GNUNET_GNSRECORD_Block *block)
Cache a block in the datastore.
A namecache client.
Cache a record in the namecache.
Definition: namecache.h:104
static struct GNUNET_STATISTICS_Handle * statistics
Handle to the statistics service.
static struct GNUNET_NAMECACHE_PluginFunctions * GSN_database
Database handle.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!)...
static int res
struct GNUNET_NAMECACHE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE_RESPONSE.
Definition: namecache.h:138
static struct GNUNET_PEERINFO_NotifyContext * nc
Iterator context.
struct GNUNET_TIME_AbsoluteNBO expire
Expiration time.
Definition: namecache.h:114
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature of the block.
uint32_t r_id
Request ID in NBO.
Definition: namecache.h:51
#define GNUNET_log(kind,...)
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
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:742
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature.
Definition: namecache.h:119
int32_t op_result
GNUNET_OK on success, GNUNET_SYSERR error
Definition: namecache.h:143
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.
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2243
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_NAMECACHE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE.
Definition: namecache.h:109
Here is the call graph for this function:

◆ run()

static void run ( void *  cls,
const struct GNUNET_CONFIGURATION_Handle cfg,
struct GNUNET_SERVICE_Handle service 
)
static

Process namecache requests.

Parameters
clsclosure
cfgconfiguration to use
servicethe initialized service

Definition at line 352 of file gnunet-service-namecache.c.

References cfg, cleanup_task(), client_connect_cb(), client_disconnect_cb(), db_lib_name, GNUNET_asprintf(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE, GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_OK, GNUNET_PLUGIN_load(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SERVICE_MAIN(), GNUNET_SERVICE_OPTION_NONE, and GNUNET_STATISTICS_create().

355 {
356  char *database;
357 
359  "Starting namecache service\n");
360  GSN_cfg = cfg;
361 
362  /* Loading database plugin */
363  if (GNUNET_OK !=
365  "namecache",
366  "database",
367  &database))
369  "No database backend configured\n");
370 
372  "libgnunet_plugin_namecache_%s",
373  database);
375  (void *) GSN_cfg);
376  GNUNET_free (database);
377  if (NULL == GSN_database)
378  {
380  "Could not load database backend `%s'\n",
381  db_lib_name);
383  NULL);
384  return;
385  }
386  statistics = GNUNET_STATISTICS_create ("namecache",
387  cfg);
388 
389  /* Configuring server handles */
391  NULL);
392 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1300
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
static char * db_lib_name
Name of the database plugin.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static struct GNUNET_STATISTICS_Handle * statistics
Handle to the statistics service.
static struct GNUNET_NAMECACHE_PluginFunctions * GSN_database
Database handle.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1280
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
static const struct GNUNET_CONFIGURATION_Handle * GSN_cfg
Configuration handle.
static void cleanup_task(void *cls)
Task run during shutdown.
#define GNUNET_log(kind,...)
void * GNUNET_PLUGIN_load(const char *library_name, void *arg)
Setup plugin (runs the "init" callback and returns whatever "init" returned).
Definition: plugin.c:207
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ GNUNET_SERVICE_MAIN()

GNUNET_SERVICE_MAIN ( "namecache"  ,
GNUNET_SERVICE_OPTION_NONE  ,
run,
client_connect_cb,
client_disconnect_cb,
NULL  ,
GNUNET_MQ_hd_fixed_size(lookup_block, GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK, struct LookupBlockMessage, NULL)  ,
GNUNET_MQ_hd_var_size(block_cache, GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE, struct BlockCacheMessage, NULL)  ,
GNUNET_MQ_handler_end()   
)

Define "main" method using service macro.

Referenced by run().

Here is the caller graph for this function:

Variable Documentation

◆ GSN_cfg

const struct GNUNET_CONFIGURATION_Handle* GSN_cfg
static

Configuration handle.

Definition at line 62 of file gnunet-service-namecache.c.

◆ statistics

struct GNUNET_STATISTICS_Handle* statistics
static

Handle to the statistics service.

Definition at line 67 of file gnunet-service-namecache.c.

◆ GSN_database

struct GNUNET_NAMECACHE_PluginFunctions* GSN_database
static

Database handle.

Definition at line 72 of file gnunet-service-namecache.c.

◆ db_lib_name

char* db_lib_name
static

Name of the database plugin.

Definition at line 77 of file gnunet-service-namecache.c.

Referenced by cleanup_task(), and run().