GNUnet  0.19.5
gnunet-service-peerstore.c File Reference

peerstore service implementation More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "peerstore.h"
#include "gnunet_peerstore_plugin.h"
#include "peerstore_common.h"
Include dependency graph for gnunet-service-peerstore.c:

Go to the source code of this file.

Macros

#define EXPIRED_RECORDS_CLEANUP_INTERVAL   300 /* 5mins */
 Interval for expired records cleanup (in seconds) More...
 

Functions

static void do_shutdown ()
 Perform the actual shutdown operations. More...
 
static void shutdown_task (void *cls)
 Task run during shutdown. More...
 
static void expire_records_continuation (void *cls, int success)
 Continuation to expire_records called by the peerstore plugin. More...
 
static void cleanup_expired_records (void *cls)
 Deletes any expired records from storage. More...
 
static void * client_connect_cb (void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
 A client disconnected. More...
 
static int client_disconnect_it (void *cls, const struct GNUNET_HashCode *key, void *value)
 Search for a disconnected client and remove it. More...
 
static void client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *client, void *app_cls)
 A client disconnected. More...
 
static void record_iterator (void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
 Function called by for each matching record. More...
 
static int watch_notifier_it (void *cls, const struct GNUNET_HashCode *key, void *value)
 Iterator over all watcher clients to notify them of a new record. More...
 
static void watch_notifier (struct GNUNET_PEERSTORE_Record *record)
 Given a new record, notifies watchers. More...
 
static void handle_watch_cancel (void *cls, const struct StoreKeyHashMessage *hm)
 Handle a watch cancel request from client. More...
 
static void handle_watch (void *cls, const struct StoreKeyHashMessage *hm)
 Handle a watch request from client. More...
 
static int check_iterate (void *cls, const struct StoreRecordMessage *srm)
 Check an iterate request from client. More...
 
static void handle_iterate (void *cls, const struct StoreRecordMessage *srm)
 Handle an iterate request from client. More...
 
static void store_record_continuation (void *cls, int success)
 Continuation of store_record called by the peerstore plugin. More...
 
static int check_store (void *cls, const struct StoreRecordMessage *srm)
 Check a store request from client. More...
 
static void handle_store (void *cls, const struct StoreRecordMessage *srm)
 Handle a store request from client. More...
 
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service)
 Peerstore service runner. More...
 
 GNUNET_SERVICE_MAIN ("peerstore", GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_var_size(store, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE, struct StoreRecordMessage, NULL), GNUNET_MQ_hd_var_size(iterate, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE, struct StoreRecordMessage, NULL), GNUNET_MQ_hd_fixed_size(watch, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH, struct StoreKeyHashMessage, NULL), GNUNET_MQ_hd_fixed_size(watch_cancel, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL, struct StoreKeyHashMessage, NULL), GNUNET_MQ_handler_end())
 Define "main" method using service macro. More...
 

Variables

static const struct GNUNET_CONFIGURATION_Handlecfg
 Our configuration. More...
 
static char * db_lib_name
 Database plugin library name. More...
 
static struct GNUNET_PEERSTORE_PluginFunctionsdb
 Database handle. More...
 
static struct GNUNET_CONTAINER_MultiHashMapwatchers
 Hashmap with all watch requests. More...
 
static struct GNUNET_SCHEDULER_Taskexpire_task
 Task run to clean up expired records. More...
 
static int in_shutdown
 Are we in the process of shutting down the service? GNUNET_YES / GNUNET_NO. More...
 
static unsigned int num_clients
 Number of connected clients. More...
 

Detailed Description

peerstore service implementation

Author
Omar Tarabai

Definition in file gnunet-service-peerstore.c.

Macro Definition Documentation

◆ EXPIRED_RECORDS_CLEANUP_INTERVAL

#define EXPIRED_RECORDS_CLEANUP_INTERVAL   300 /* 5mins */

Interval for expired records cleanup (in seconds)

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

Function Documentation

◆ do_shutdown()

static void do_shutdown ( )
static

Perform the actual shutdown operations.

Definition at line 78 of file gnunet-service-peerstore.c.

79 {
81  "Shutting down peerstore, bye.\n");
82  if (NULL != db_lib_name)
83  {
86  db_lib_name = NULL;
87  }
88  if (NULL != watchers)
89  {
91  watchers = NULL;
92  }
93  if (NULL != expire_task)
94  {
96  expire_task = NULL;
97  }
99 }
static struct GNUNET_CONTAINER_MultiHashMap * watchers
Hashmap with all watch requests.
static char * db_lib_name
Database plugin library name.
static struct GNUNET_PEERSTORE_PluginFunctions * db
Database handle.
static struct GNUNET_SCHEDULER_Task * expire_task
Task run to clean up expired records.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
#define GNUNET_log(kind,...)
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_PLUGIN_unload(const char *library_name, void *arg)
Unload plugin (runs the "done" callback and returns whatever "done" returned).
Definition: plugin.c:242
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:562
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975

References db, db_lib_name, expire_task, GNUNET_break, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_PLUGIN_unload(), GNUNET_SCHEDULER_cancel(), GNUNET_SCHEDULER_shutdown(), and watchers.

Referenced by client_disconnect_cb(), and shutdown_task().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shutdown_task()

static void shutdown_task ( void *  cls)
static

Task run during shutdown.

Parameters
clsunused

Definition at line 108 of file gnunet-service-peerstore.c.

109 {
111  "Priming PEERSTORE for shutdown.\n");
113  if (0 == num_clients) /* Only when no connected clients. */
114  do_shutdown ();
115 }
static int in_shutdown
Are we in the process of shutting down the service? GNUNET_YES / GNUNET_NO.
static unsigned int num_clients
Number of connected clients.
static void do_shutdown()
Perform the actual shutdown operations.
@ GNUNET_YES

References do_shutdown(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_YES, in_shutdown, and num_clients.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ expire_records_continuation()

static void expire_records_continuation ( void *  cls,
int  success 
)
static

Continuation to expire_records called by the peerstore plugin.

Parameters
clsunused
successcount of records deleted or GNUNET_SYSERR

Definition at line 156 of file gnunet-service-peerstore.c.

157 {
158  if (success > 0)
159  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", success);
160  GNUNET_assert (NULL == expire_task);
165  NULL);
166 }
#define EXPIRED_RECORDS_CLEANUP_INTERVAL
Interval for expired records cleanup (in seconds)
static void cleanup_expired_records(void *cls)
Deletes any expired records from storage.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_INFO
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1272
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:484

References cleanup_expired_records(), expire_task, EXPIRED_RECORDS_CLEANUP_INTERVAL, GNUNET_assert, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_relative_multiply(), and GNUNET_TIME_UNIT_SECONDS.

Referenced by cleanup_expired_records().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cleanup_expired_records()

static void cleanup_expired_records ( void *  cls)
static

Deletes any expired records from storage.

Definition at line 127 of file gnunet-service-peerstore.c.

128 {
129  int ret;
130 
131  expire_task = NULL;
132  GNUNET_assert (NULL != db);
133  ret = db->expire_records (db->cls,
136  NULL);
137  if (GNUNET_OK != ret)
138  {
139  GNUNET_assert (NULL == expire_task);
144  NULL);
145  }
146 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static void expire_records_continuation(void *cls, int success)
Continuation to expire_records called by the peerstore plugin.
@ GNUNET_OK
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
void * cls
Closure to pass to all plugin functions.
int(* expire_records)(void *cls, struct GNUNET_TIME_Absolute now, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
Delete expired records (expiry < now)

References GNUNET_PEERSTORE_PluginFunctions::cls, db, GNUNET_PEERSTORE_PluginFunctions::expire_records, expire_records_continuation(), expire_task, EXPIRED_RECORDS_CLEANUP_INTERVAL, GNUNET_assert, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_absolute_get(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_SECONDS, and ret.

Referenced by expire_records_continuation(), and run().

Here is the call graph for this function:
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

A client disconnected.

Remove all of its data structure entries.

Parameters
clsclosure, NULL
clientidentification of the client
mqthe message queue
Returns

Definition at line 178 of file gnunet-service-peerstore.c.

181 {
182  num_clients++;
184  "A client connected (now %u)\n", num_clients);
185  return client;
186 }

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, and num_clients.

◆ client_disconnect_it()

static int client_disconnect_it ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Search for a disconnected client and remove it.

Parameters
clsclosuer, a struct GNUNET_SERVICE_Client
keyhash of record key
valuethe watcher client, a struct GNUNET_SERVICE_Client *
Returns
GNUNET_OK to continue iterating

Definition at line 198 of file gnunet-service-peerstore.c.

199 {
200  if (value == cls)
201  {
204  num_clients++; /* Watchers do not count */
205  }
206  return GNUNET_OK;
207 }
struct GNUNET_HashCode key
The key used in the DHT.
static char * value
Value of the record to add/remove.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.

References GNUNET_assert, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_OK, GNUNET_YES, key, num_clients, value, and watchers.

Referenced by client_disconnect_cb().

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_cls 
)
static

A client disconnected.

Remove all of its data structure entries.

Parameters
clsclosure, NULL
clientidentification of the client

Definition at line 217 of file gnunet-service-peerstore.c.

220 {
221  num_clients--;
222  if (NULL != watchers)
225  client);
227  "A client disconnected (%u remaining).\n",
228  num_clients);
229  if ((0 == num_clients) && in_shutdown)
230  do_shutdown ();
231 }
static int client_disconnect_it(void *cls, const struct GNUNET_HashCode *key, void *value)
Search for a disconnected client and remove it.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.

References client_disconnect_it(), do_shutdown(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, in_shutdown, num_clients, and watchers.

Here is the call graph for this function:

◆ record_iterator()

static void record_iterator ( void *  cls,
const struct GNUNET_PEERSTORE_Record record,
const char *  emsg 
)
static

Function called by for each matching record.

Parameters
clsclosure
recordpeerstore record found
emsgerror message or NULL if no errors
Returns
GNUNET_YES to continue iteration

Definition at line 243 of file gnunet-service-peerstore.c.

246 {
247  struct GNUNET_PEERSTORE_Record *cls_record = cls;
248  struct GNUNET_MQ_Envelope *env;
249 
250  if (NULL == record)
251  {
252  /* No more records */
253  struct GNUNET_MessageHeader *endmsg;
254 
257  if (NULL == emsg)
258  {
260  }
261  else
262  {
263  GNUNET_break (0);
264  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to iterate: %s\n", emsg);
265  GNUNET_SERVICE_client_drop (cls_record->client);
266  }
267  PEERSTORE_destroy_record (cls_record);
268  return;
269  }
270 
272  record->sub_system,
273  &record->peer,
274  record->key,
275  record->value,
276  record->value_size,
277  record->expiry,
278  0,
281 }
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
@ GNUNET_ERROR_TYPE_ERROR
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:304
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:78
#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD
Iteration record message.
#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END
Iteration end message.
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2330
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2443
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2249
struct GNUNET_MQ_Envelope * PEERSTORE_create_record_mq_envelope(const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, const void *value, size_t value_size, struct GNUNET_TIME_Absolute expiry, enum GNUNET_PEERSTORE_StoreOption options, uint16_t msg_type)
Creates a MQ envelope for a single record.
void PEERSTORE_destroy_record(struct GNUNET_PEERSTORE_Record *record)
Free any memory allocated for this record.
Header for all communications.
Single PEERSTORE record.
struct GNUNET_SERVICE_Client * client
Client from which this record originated.

References GNUNET_PEERSTORE_Record::client, env, GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_drop(), GNUNET_SERVICE_client_get_mq(), PEERSTORE_create_record_mq_envelope(), PEERSTORE_destroy_record(), and record().

Referenced by handle_iterate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ watch_notifier_it()

static int watch_notifier_it ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Iterator over all watcher clients to notify them of a new record.

Parameters
clsclosure, a struct GNUNET_PEERSTORE_Record *
keyhash of record key
valuethe watcher client, a struct GNUNET_SERVICE_Client *
Returns
GNUNET_YES to continue iterating

Definition at line 294 of file gnunet-service-peerstore.c.

295 {
296  struct GNUNET_PEERSTORE_Record *record = cls;
297  struct GNUNET_SERVICE_Client *client = value;
298  struct GNUNET_MQ_Envelope *env;
299 
300  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found a watcher to update.\n");
302  record->sub_system,
303  &record->peer,
304  record->key,
305  record->value,
306  record->value_size,
307  record->expiry,
308  0,
311  return GNUNET_YES;
312 }
#define GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD
Watch response.
Handle to a client that is connected to a service.
Definition: service.c:252

References env, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD, GNUNET_MQ_send(), GNUNET_SERVICE_client_get_mq(), GNUNET_YES, PEERSTORE_create_record_mq_envelope(), record(), and value.

Referenced by watch_notifier().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ watch_notifier()

static void watch_notifier ( struct GNUNET_PEERSTORE_Record record)
static

Given a new record, notifies watchers.

Parameters
recordchanged record to update watchers with

Definition at line 321 of file gnunet-service-peerstore.c.

322 {
323  struct GNUNET_HashCode keyhash;
324 
325  PEERSTORE_hash_key (record->sub_system, &record->peer, record->key, &keyhash);
327  &keyhash,
329  record);
330 }
static int watch_notifier_it(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over all watcher clients to notify them of a new record.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_get_multiple(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map that match a particular key.
void PEERSTORE_hash_key(const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, struct GNUNET_HashCode *ret)
Creates a hash of the given key combination.
A 512-bit hashcode.

References GNUNET_CONTAINER_multihashmap_get_multiple(), PEERSTORE_hash_key(), record(), watch_notifier_it(), and watchers.

Referenced by store_record_continuation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_watch_cancel()

static void handle_watch_cancel ( void *  cls,
const struct StoreKeyHashMessage hm 
)
static

Handle a watch cancel request from client.

Parameters
clsidentification of the client
hmthe actual message

Definition at line 340 of file gnunet-service-peerstore.c.

341 {
342  struct GNUNET_SERVICE_Client *client = cls;
343 
344  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a watch cancel request.\n");
345  if (GNUNET_OK !=
347  {
348  GNUNET_break (0);
350  return;
351  }
352  num_clients++;
354 }
struct GNUNET_HashCode keyhash
Hash of a record key.
Definition: peerstore.h:104

References GNUNET_break, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_OK, GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_drop(), StoreKeyHashMessage::keyhash, num_clients, and watchers.

Here is the call graph for this function:

◆ handle_watch()

static void handle_watch ( void *  cls,
const struct StoreKeyHashMessage hm 
)
static

Handle a watch request from client.

Parameters
clsidentification of the client
hmthe actual message

Definition at line 364 of file gnunet-service-peerstore.c.

365 {
366  struct GNUNET_SERVICE_Client *client = cls;
367 
368  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a watch request.\n");
369  num_clients--; /* do not count watchers */
372  &hm->keyhash,
373  client,
376 }
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
void GNUNET_SERVICE_client_mark_monitor(struct GNUNET_SERVICE_Client *c)
Set the 'monitor' flag on this client.
Definition: service.c:2413

References GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_mark_monitor(), StoreKeyHashMessage::keyhash, num_clients, and watchers.

Here is the call graph for this function:

◆ check_iterate()

static int check_iterate ( void *  cls,
const struct StoreRecordMessage srm 
)
static

Check an iterate request from client.

Parameters
clsclient identification of the client
srmthe actual message
Returns
GNUNET_OK if srm is well-formed

Definition at line 387 of file gnunet-service-peerstore.c.

388 {
390 
392  if (NULL == record)
393  {
394  GNUNET_break (0);
395  return GNUNET_SYSERR;
396  }
397  if (NULL == record->sub_system)
398  {
399  GNUNET_break (0);
401  return GNUNET_SYSERR;
402  }
404  return GNUNET_OK;
405 }
@ GNUNET_SYSERR
struct GNUNET_PEERSTORE_Record * PEERSTORE_parse_record_message(const struct StoreRecordMessage *srm)
Parses a message carrying a record.

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, PEERSTORE_destroy_record(), PEERSTORE_parse_record_message(), and record().

Here is the call graph for this function:

◆ handle_iterate()

static void handle_iterate ( void *  cls,
const struct StoreRecordMessage srm 
)
static

Handle an iterate request from client.

Parameters
clsidentification of the client
srmthe actual message

Definition at line 415 of file gnunet-service-peerstore.c.

416 {
417  struct GNUNET_SERVICE_Client *client = cls;
419 
422  "Iterate request: ss `%s', peer `%s', key `%s'\n",
423  record->sub_system,
424  GNUNET_i2s (&record->peer),
425  (NULL == record->key) ? "NULL" : record->key);
426  record->client = client;
427  if (GNUNET_OK !=
429  record->sub_system,
430  (ntohs (srm->peer_set)) ? &record->peer : NULL,
431  record->key,
433  record))
434  {
435  GNUNET_break (0);
438  }
439 }
static void record_iterator(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
Function called by for each matching record.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
int(* iterate_records)(void *cls, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_PEERSTORE_Processor iter, void *iter_cls)
Iterate over the records given an optional peer id and/or key.
uint16_t peer_set
GNUNET_YES if peer id value set, GNUNET_NO otherwise
Definition: peerstore.h:46

References GNUNET_PEERSTORE_Record::client, GNUNET_PEERSTORE_PluginFunctions::cls, db, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_OK, GNUNET_SERVICE_client_drop(), GNUNET_PEERSTORE_PluginFunctions::iterate_records, StoreRecordMessage::peer_set, PEERSTORE_destroy_record(), PEERSTORE_parse_record_message(), record(), and record_iterator().

Here is the call graph for this function:

◆ store_record_continuation()

static void store_record_continuation ( void *  cls,
int  success 
)
static

Continuation of store_record called by the peerstore plugin.

Parameters
clsclosure
successresult

Definition at line 449 of file gnunet-service-peerstore.c.

450 {
451  struct GNUNET_PEERSTORE_Record *record = cls;
452 
453  if (GNUNET_OK == success)
454  {
457  }
458  else
459  {
460  GNUNET_break (0);
462  }
464 }
static void watch_notifier(struct GNUNET_PEERSTORE_Record *record)
Given a new record, notifies watchers.

References GNUNET_break, GNUNET_OK, GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_drop(), PEERSTORE_destroy_record(), record(), and watch_notifier().

Referenced by handle_store().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_store()

static int check_store ( void *  cls,
const struct StoreRecordMessage srm 
)
static

Check a store request from client.

Parameters
clsclient identification of the client
srmthe actual message
Returns
GNUNET_OK if srm is well-formed

Definition at line 475 of file gnunet-service-peerstore.c.

476 {
478 
480  if (NULL == record)
481  {
482  GNUNET_break (0);
483  return GNUNET_SYSERR;
484  }
485  if ((NULL == record->sub_system) || (NULL == record->key))
486  {
487  GNUNET_break (0);
489  return GNUNET_SYSERR;
490  }
492  return GNUNET_OK;
493 }

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, PEERSTORE_destroy_record(), PEERSTORE_parse_record_message(), and record().

Here is the call graph for this function:

◆ handle_store()

static void handle_store ( void *  cls,
const struct StoreRecordMessage srm 
)
static

Handle a store request from client.

Parameters
clsclient identification of the client
srmthe actual message

Definition at line 503 of file gnunet-service-peerstore.c.

504 {
505  struct GNUNET_SERVICE_Client *client = cls;
507 
509  GNUNET_log (
511  "Received a store request. Sub system `%s' Peer `%s Key `%s' Options: %u.\n",
512  record->sub_system,
513  GNUNET_i2s (&record->peer),
514  record->key,
515  (uint32_t) ntohl (srm->options));
516  record->client = client;
517  if (GNUNET_OK != db->store_record (db->cls,
518  record->sub_system,
519  &record->peer,
520  record->key,
521  record->value,
522  record->value_size,
523  record->expiry,
524  ntohl (srm->options),
526  record))
527  {
528  GNUNET_break (0);
531  return;
532  }
533 }
static void store_record_continuation(void *cls, int success)
Continuation of store_record called by the peerstore plugin.
int(* store_record)(void *cls, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, const void *value, size_t size, struct GNUNET_TIME_Absolute expiry, enum GNUNET_PEERSTORE_StoreOption options, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
Store a record in the peerstore.
uint32_t options
Options, needed only in case of a store operation.
Definition: peerstore.h:80

References GNUNET_PEERSTORE_Record::client, GNUNET_PEERSTORE_PluginFunctions::cls, db, GNUNET_break, GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_log, GNUNET_OK, GNUNET_SERVICE_client_drop(), StoreRecordMessage::options, PEERSTORE_destroy_record(), PEERSTORE_parse_record_message(), record(), GNUNET_PEERSTORE_PluginFunctions::store_record, and store_record_continuation().

Here is the call graph for this function:

◆ run()

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

Peerstore service runner.

Parameters
clsclosure
cconfiguration to use
servicethe initialized service

Definition at line 544 of file gnunet-service-peerstore.c.

547 {
548  char *database;
549 
551  num_clients = 0;
552  cfg = c;
554  "peerstore",
555  "DATABASE",
556  &database))
557  {
559  "peerstore",
560  "DATABASE");
562  return;
563  }
564  GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_peerstore_%s", database);
565  db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg);
566  GNUNET_free (database);
567  if (NULL == db)
568  {
570  _ ("Could not load database backend `%s'\n"),
571  db_lib_name);
573  return;
574  }
578 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static void shutdown_task(void *cls)
Task run during shutdown.
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.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
@ GNUNET_NO
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
void * GNUNET_PLUGIN_load(const char *library_name, void *arg)
Setup plugin (runs the "init" callback and returns whatever "init" returned).
Definition: plugin.c:198
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:1299
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:1334
#define _(String)
GNU gettext support macro.
Definition: platform.h:178

References _, cfg, cleanup_expired_records(), db, db_lib_name, expire_task, GNUNET_asprintf(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONTAINER_multihashmap_create(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_log_config_missing(), GNUNET_NO, GNUNET_OK, GNUNET_PLUGIN_load(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), in_shutdown, num_clients, shutdown_task(), and watchers.

Here is the call graph for this function:

◆ GNUNET_SERVICE_MAIN()

Define "main" method using service macro.

Variable Documentation

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Our configuration.

Definition at line 41 of file gnunet-service-peerstore.c.

Referenced by run().

◆ db_lib_name

char* db_lib_name
static

Database plugin library name.

Definition at line 46 of file gnunet-service-peerstore.c.

Referenced by do_shutdown(), and run().

◆ db

Database handle.

Definition at line 51 of file gnunet-service-peerstore.c.

Referenced by cleanup_expired_records(), do_shutdown(), handle_iterate(), handle_store(), and run().

◆ watchers

struct GNUNET_CONTAINER_MultiHashMap* watchers
static

Hashmap with all watch requests.

Definition at line 56 of file gnunet-service-peerstore.c.

Referenced by client_disconnect_cb(), client_disconnect_it(), do_shutdown(), handle_watch(), handle_watch_cancel(), run(), and watch_notifier().

◆ expire_task

struct GNUNET_SCHEDULER_Task* expire_task
static

Task run to clean up expired records.

Definition at line 61 of file gnunet-service-peerstore.c.

Referenced by cleanup_expired_records(), do_shutdown(), expire_records_continuation(), and run().

◆ in_shutdown

int in_shutdown
static

Are we in the process of shutting down the service? GNUNET_YES / GNUNET_NO.

Definition at line 66 of file gnunet-service-peerstore.c.

Referenced by client_disconnect_cb(), run(), and shutdown_task().

◆ num_clients

unsigned int num_clients
static