GNUnet debian-0.24.3-29-g453fda2cf
 
Loading...
Searching...
No Matches
gnunet-service-namecache.c File Reference

namecache for the GNUnet naming system More...

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.
 
static void client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *client, void *app_ctx)
 Called whenever a client is disconnected.
 
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.
 
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 void handle_lookup_block (void *cls, const struct LookupBlockMessage *ln_msg)
 Handles a GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK message.
 
static int check_block_cache (void *cls, const struct BlockCacheMessage *rp_msg)
 Check a GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE message.
 
static void handle_block_cache (void *cls, const struct BlockCacheMessage *rp_msg)
 Handles a GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE message.
 
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_SERVICE_Handle *service)
 Process namecache requests.
 
 GNUNET_SERVICE_MAIN (GNUNET_OS_project_data_gnunet(), "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.
 

Variables

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

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, \
static char * filename
#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...

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

41{
45 struct GNUNET_SERVICE_Client *client;
46
50 struct GNUNET_MQ_Handle *mq;
51};
52
53
57static const struct GNUNET_CONFIGURATION_Handle *GSN_cfg;
58
63
68
72static char *db_lib_name;
73
74
80static void
81cleanup_task (void *cls)
82{
84 "Stopping namecache service\n");
85 GNUNET_break (NULL ==
89 db_lib_name = NULL;
90 if (NULL != statistics)
91 {
93 GNUNET_NO);
94 statistics = NULL;
95 }
96}
97
98
107static void
109 struct GNUNET_SERVICE_Client *client,
110 void *app_ctx)
111{
112 struct NamecacheClient *nc = app_ctx;
113
115 "Client %p disconnected\n",
116 client);
117 GNUNET_free (nc);
118}
119
120
129static void *
130client_connect_cb (void *cls,
132 struct GNUNET_MQ_Handle *mq)
133{
134 struct NamecacheClient *nc;
135
137 "Client %p connected\n",
138 client);
139 nc = GNUNET_new (struct NamecacheClient);
140 nc->client = client;
141 nc->mq = mq;
142 return nc;
143}
144
145
151{
155 struct NamecacheClient *nc;
156
160 uint32_t request_id;
161
165 int status;
166};
167
168
175static void
176handle_lookup_block_it (void *cls,
177 const struct GNUNET_GNSRECORD_Block *block)
178{
179 struct LookupBlockContext *lnc = cls;
180 struct GNUNET_MQ_Envelope *env;
182 size_t bsize;
183
186 bsize,
188 r->gns_header.r_id = htonl (lnc->request_id);
189 GNUNET_memcpy (&r[1],
190 block,
191 bsize);
193 "blocks found in cache",
194 1,
195 GNUNET_NO);
199 "Sending NAMECACHE_LOOKUP_BLOCK_RESPONSE message\n");
200 GNUNET_MQ_send (lnc->nc->mq,
201 env);
202}
203
204
211static void
212handle_lookup_block (void *cls,
213 const struct LookupBlockMessage *ln_msg)
214{
215 struct NamecacheClient *nc = cls;
216 struct GNUNET_MQ_Envelope *env;
217 struct LookupBlockContext lnc;
218 struct LookupBlockResponseMessage *zir_end;
219 int ret;
220
222 "Received NAMECACHE_LOOKUP_BLOCK message\n");
224 "blocks looked up",
225 1,
226 GNUNET_NO);
227 lnc.request_id = ntohl (ln_msg->gns_header.r_id);
228 lnc.nc = nc;
229 lnc.status = GNUNET_OK;
230 if (GNUNET_SYSERR ==
232 &ln_msg->query,
234 &lnc)))
235 {
236 /* internal error (in database plugin); might be best to just hang up on
237 plugin rather than to signal that there are 'no' results, which
238 might also be false... */
239 GNUNET_break (0);
241 return;
242 }
243 if ((0 == ret) || (GNUNET_SYSERR == lnc.status))
244 {
245 /* no records match at all, generate empty response */
247 "Sending empty NAMECACHE_LOOKUP_BLOCK_RESPONSE message\n");
248 env = GNUNET_MQ_msg (zir_end,
250 zir_end->gns_header.r_id = ln_msg->gns_header.r_id;
251 GNUNET_MQ_send (nc->mq,
252 env);
253 }
255}
256
257
265static int
266check_block_cache (void *cls,
267 const struct BlockCacheMessage *rp_msg)
268{
269 return GNUNET_OK;
270}
271
272
279static void
280handle_block_cache (void *cls,
281 const struct BlockCacheMessage *rp_msg)
282{
283 struct NamecacheClient *nc = cls;
284 struct GNUNET_MQ_Envelope *env;
285 struct BlockCacheResponseMessage *rpr_msg;
286 struct GNUNET_GNSRECORD_Block *block;
287 size_t esize;
288 int res;
289
291 "blocks cached",
292 1,
293 GNUNET_NO);
294 esize = ntohs (rp_msg->gns_header.header.size) - sizeof(struct
296 block = GNUNET_malloc (esize);
297 memcpy (block, &rp_msg[1], esize);
299 "Received NAMECACHE_BLOCK_CACHE message with type %u\n",
300 htonl (block->type));
302 block);
303 GNUNET_free (block);
304 env = GNUNET_MQ_msg (rpr_msg,
306 rpr_msg->gns_header.r_id = rp_msg->gns_header.r_id;
307 rpr_msg->op_result = htonl (res);
308 GNUNET_MQ_send (nc->mq,
309 env);
311}
312
313
321static void
322run (void *cls,
323 const struct GNUNET_CONFIGURATION_Handle *cfg,
325{
326 char *database;
327
329 "Starting namecache service\n");
330 GSN_cfg = cfg;
331
332 /* Loading database plugin */
333 if (GNUNET_OK !=
335 "namecache",
336 "database",
337 &database))
339 "No database backend configured\n");
340
342 "libgnunet_plugin_namecache_%s",
343 database);
346 (void *) GSN_cfg);
347 GNUNET_free (database);
348 if (NULL == GSN_database)
349 {
351 "Could not load database backend `%s'\n",
354 NULL);
355 return;
356 }
358 cfg);
359
360 /* Configuring server handles */
362 NULL);
363}
364
365
371 "namecache",
373 &run,
376 NULL,
377 GNUNET_MQ_hd_fixed_size (lookup_block,
379 struct LookupBlockMessage,
380 NULL),
381 GNUNET_MQ_hd_var_size (block_cache,
383 struct BlockCacheMessage,
384 NULL),
386
387
388/* end of gnunet-service-namecache.c */
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
static int ret
Final status code.
Definition gnunet-arm.c:93
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
static char * res
Currently read line or NULL on EOF.
static struct GNUNET_SCHEDULER_Task * cleanup_task
Cleanup task.
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
static struct GNUNET_NotificationContext * nc
Notification context for broadcasting to monitors.
static void handle_lookup_block(void *cls, const struct LookupBlockMessage *ln_msg)
Handles a GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK message.
static void handle_block_cache(void *cls, const struct BlockCacheMessage *rp_msg)
Handles a GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE message.
static struct GNUNET_NAMECACHE_PluginFunctions * GSN_database
Database handle.
static char * db_lib_name
Name of the database plugin.
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 struct GNUNET_STATISTICS_Handle * statistics
Handle to the statistics service.
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.
static const struct GNUNET_CONFIGURATION_Handle * GSN_cfg
Configuration handle.
static int check_block_cache(void *cls, const struct BlockCacheMessage *rp_msg)
Check a GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE message.
static void client_disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *client, void *app_ctx)
Called whenever a client is disconnected.
static void run(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_SERVICE_Handle *service)
Process namecache requests.
static unsigned int bsize
enum GNUNET_GenericReturnValue 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.
size_t GNUNET_GNSRECORD_block_get_size(const struct GNUNET_GNSRECORD_Block *block)
Returns the length of this block in bytes.
struct GNUNET_TIME_Absolute GNUNET_GNSRECORD_block_get_expiration(const struct GNUNET_GNSRECORD_Block *block)
Returns the expiration of a block.
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
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:305
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
void * GNUNET_PLUGIN_load(const struct GNUNET_OS_ProjectData *pd, const char *library_name, void *arg)
Setup plugin (runs the "init" callback and returns whatever "init" returned).
Definition plugin.c:221
void * GNUNET_PLUGIN_unload(const char *library_name, void *arg)
Unload plugin (runs the "done" callback and returns whatever "done" returned).
Definition plugin.c:277
#define GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK
Client to service: lookup block.
#define GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE_RESPONSE
Service to client: result of block cache request.
#define GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE
Client to service: cache a block.
#define GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK_RESPONSE
Service to client: result of block lookup.
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,...
Definition scheduler.c:1339
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:1304
#define GNUNET_SERVICE_MAIN(pd, service_name, service_options, init_cb, connect_cb, disconnect_cb, cls,...)
Creates the "main" function for a GNUnet service.
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition service.c:2462
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition service.c:2433
@ GNUNET_SERVICE_OPTION_NONE
Use defaults.
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition time.c:640
static struct GNUNET_MQ_Handle * mq
Our connection to the resolver service, created on-demand, but then persists until error or shutdown.
Cache a record in the namecache.
Definition namecache.h:95
struct GNUNET_NAMECACHE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE.
Definition namecache.h:99
Response to a request to cache a block.
Definition namecache.h:114
int32_t op_result
GNUNET_OK on success, GNUNET_SYSERR error
Definition namecache.h:123
struct GNUNET_NAMECACHE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE_RESPONSE.
Definition namecache.h:118
uint32_t type
The zone type (GNUNET_GNSRECORD_TYPE_PKEY)
Handle to a message queue.
Definition mq.c:87
uint32_t r_id
Request ID in NBO.
Definition namecache.h:51
struct GNUNET_MessageHeader header
header.type will be GNUNET_MESSAGE_TYPE_NAMECACHE_* header.size will be message size
Definition namecache.h:46
struct returned by the initialization function of the plugin
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.
int(* cache_block)(void *cls, const struct GNUNET_GNSRECORD_Block *block)
Cache a block in the datastore.
void * cls
Closure to pass to all plugin functions.
Handle to a client that is connected to a service.
Definition service.c:249
Handle to a service.
Definition service.c:116
Handle for the service.
Context for name lookups passed from handle_lookup_block to handle_lookup_block_it as closure.
struct NamecacheClient * nc
The client to send the response to.
uint32_t request_id
Operation id for the name lookup.
Lookup a block in the namecache.
Definition namecache.h:59
struct GNUNET_NAMECACHE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK.
Definition namecache.h:63
struct GNUNET_HashCode query
The query.
Definition namecache.h:68
Lookup response.
Definition namecache.h:76
struct GNUNET_TIME_AbsoluteNBO expire
Expiration time.
Definition namecache.h:85
struct GNUNET_NAMECACHE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK_RESPONSE.
Definition namecache.h:80
A namecache client.
struct GNUNET_MQ_Handle * mq
The message queue to talk to client.
struct GNUNET_SERVICE_Client * client
The client.

Function Documentation

◆ cleanup_task()

static void cleanup_task ( void *  cls)
static

Task run during shutdown.

Parameters
clsunused

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

83{
85 "Stopping namecache service\n");
86 GNUNET_break (NULL ==
90 db_lib_name = NULL;
91 if (NULL != statistics)
92 {
94 GNUNET_NO);
95 statistics = NULL;
96 }
97}

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

Here is the call 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 109 of file gnunet-service-namecache.c.

112{
113 struct NamecacheClient *nc = app_ctx;
114
116 "Client %p disconnected\n",
117 client);
118 GNUNET_free (nc);
119}

References NamecacheClient::client, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, and nc.

◆ 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 131 of file gnunet-service-namecache.c.

134{
135 struct NamecacheClient *nc;
136
138 "Client %p connected\n",
139 client);
140 nc = GNUNET_new (struct NamecacheClient);
141 nc->client = client;
142 nc->mq = mq;
143 return nc;
144}

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

◆ 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 177 of file gnunet-service-namecache.c.

179{
180 struct LookupBlockContext *lnc = cls;
181 struct GNUNET_MQ_Envelope *env;
183 size_t bsize;
184
187 bsize,
189 r->gns_header.r_id = htonl (lnc->request_id);
190 GNUNET_memcpy (&r[1],
191 block,
192 bsize);
194 "blocks found in cache",
195 1,
196 GNUNET_NO);
200 "Sending NAMECACHE_LOOKUP_BLOCK_RESPONSE message\n");
201 GNUNET_MQ_send (lnc->nc->mq,
202 env);
203}

References bsize, env, LookupBlockResponseMessage::expire, LookupBlockResponseMessage::gns_header, GNUNET_ERROR_TYPE_DEBUG, GNUNET_GNSRECORD_block_get_expiration(), GNUNET_GNSRECORD_block_get_size(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK_RESPONSE, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_hton(), NamecacheClient::mq, LookupBlockContext::nc, GNUNET_NAMECACHE_Header::r_id, LookupBlockContext::request_id, and statistics.

Referenced by handle_lookup_block().

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 *
ln_msgthe inbound message

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

215{
216 struct NamecacheClient *nc = cls;
217 struct GNUNET_MQ_Envelope *env;
218 struct LookupBlockContext lnc;
219 struct LookupBlockResponseMessage *zir_end;
220 int ret;
221
223 "Received NAMECACHE_LOOKUP_BLOCK message\n");
225 "blocks looked up",
226 1,
227 GNUNET_NO);
228 lnc.request_id = ntohl (ln_msg->gns_header.r_id);
229 lnc.nc = nc;
230 lnc.status = GNUNET_OK;
231 if (GNUNET_SYSERR ==
233 &ln_msg->query,
235 &lnc)))
236 {
237 /* internal error (in database plugin); might be best to just hang up on
238 plugin rather than to signal that there are 'no' results, which
239 might also be false... */
240 GNUNET_break (0);
242 return;
243 }
244 if ((0 == ret) || (GNUNET_SYSERR == lnc.status))
245 {
246 /* no records match at all, generate empty response */
248 "Sending empty NAMECACHE_LOOKUP_BLOCK_RESPONSE message\n");
249 env = GNUNET_MQ_msg (zir_end,
251 zir_end->gns_header.r_id = ln_msg->gns_header.r_id;
252 GNUNET_MQ_send (nc->mq,
253 env);
254 }
256}

References 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, GSN_database, handle_lookup_block_it(), GNUNET_NAMECACHE_PluginFunctions::lookup_block, nc, LookupBlockContext::nc, LookupBlockMessage::query, GNUNET_NAMECACHE_Header::r_id, LookupBlockContext::request_id, ret, statistics, and LookupBlockContext::status.

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 267 of file gnunet-service-namecache.c.

269{
270 return GNUNET_OK;
271}

References GNUNET_OK.

◆ 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 281 of file gnunet-service-namecache.c.

283{
284 struct NamecacheClient *nc = cls;
285 struct GNUNET_MQ_Envelope *env;
286 struct BlockCacheResponseMessage *rpr_msg;
287 struct GNUNET_GNSRECORD_Block *block;
288 size_t esize;
289 int res;
290
292 "blocks cached",
293 1,
294 GNUNET_NO);
295 esize = ntohs (rp_msg->gns_header.header.size) - sizeof(struct
297 block = GNUNET_malloc (esize);
298 memcpy (block, &rp_msg[1], esize);
300 "Received NAMECACHE_BLOCK_CACHE message with type %u\n",
301 htonl (block->type));
303 block);
304 GNUNET_free (block);
305 env = GNUNET_MQ_msg (rpr_msg,
307 rpr_msg->gns_header.r_id = rp_msg->gns_header.r_id;
308 rpr_msg->op_result = htonl (res);
309 GNUNET_MQ_send (nc->mq,
310 env);
312}

References GNUNET_NAMECACHE_PluginFunctions::cache_block, GNUNET_NAMECACHE_PluginFunctions::cls, env, BlockCacheMessage::gns_header, BlockCacheResponseMessage::gns_header, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE_RESPONSE, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_NO, GNUNET_SERVICE_client_continue(), GNUNET_STATISTICS_update(), GSN_database, GNUNET_NAMECACHE_Header::header, nc, BlockCacheResponseMessage::op_result, GNUNET_NAMECACHE_Header::r_id, res, GNUNET_MessageHeader::size, statistics, and GNUNET_GNSRECORD_Block::type.

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 323 of file gnunet-service-namecache.c.

326{
327 char *database;
328
330 "Starting namecache service\n");
331 GSN_cfg = cfg;
332
333 /* Loading database plugin */
334 if (GNUNET_OK !=
336 "namecache",
337 "database",
338 &database))
340 "No database backend configured\n");
341
343 "libgnunet_plugin_namecache_%s",
344 database);
347 (void *) GSN_cfg);
348 GNUNET_free (database);
349 if (NULL == GSN_database)
350 {
352 "Could not load database backend `%s'\n",
355 NULL);
356 return;
357 }
359 cfg);
360
361 /* Configuring server handles */
363 NULL);
364}

References cfg, cleanup_task, db_lib_name, GNUNET_asprintf(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_OS_project_data_gnunet(), GNUNET_PLUGIN_load(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_STATISTICS_create(), GSN_cfg, GSN_database, and statistics.

Here is the call graph for this function:

◆ GNUNET_SERVICE_MAIN()

GNUNET_SERVICE_MAIN ( GNUNET_OS_project_data_gnunet()  ,
"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.

Variable Documentation

◆ GSN_cfg

const struct GNUNET_CONFIGURATION_Handle* GSN_cfg
static

Configuration handle.

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

Referenced by run().

◆ statistics

struct GNUNET_STATISTICS_Handle* statistics
static

Handle to the statistics service.

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

Referenced by cleanup_task(), handle_block_cache(), handle_lookup_block(), handle_lookup_block_it(), and run().

◆ GSN_database

struct GNUNET_NAMECACHE_PluginFunctions* GSN_database
static

Database handle.

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

Referenced by cleanup_task(), handle_block_cache(), handle_lookup_block(), and run().

◆ db_lib_name

char* db_lib_name
static

Name of the database plugin.

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

Referenced by cleanup_task(), run(), and run().