GNUnet  0.11.x
Macros | Functions | Variables
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.

Referenced by cleanup_expired_records(), and expire_records_continuation().

Function Documentation

◆ do_shutdown()

static void do_shutdown ( )
static

Perform the actual shutdown operations.

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

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

Referenced by client_disconnect_cb(), and shutdown_task().

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 }
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
#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:269
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.
static struct GNUNET_CONTAINER_MultiHashMap * watchers
Hashmap with all watch requests.
static struct GNUNET_PEERSTORE_PluginFunctions * db
Database handle.
#define GNUNET_log(kind,...)
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
static char * db_lib_name
Database plugin library name.
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.

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

Referenced by run().

109 {
111  "Priming PEERSTORE for shutdown.\n");
113  if (0 == num_clients) /* Only when no connected clients. */
114  do_shutdown ();
115 }
static unsigned int num_clients
Number of connected clients.
static void do_shutdown()
Perform the actual shutdown operations.
#define GNUNET_log(kind,...)
static int in_shutdown
Are we in the process of shutting down the service? GNUNET_YES / GNUNET_NO.
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.

References cleanup_expired_records(), 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(), and shutdown_task().

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 }
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.
#define GNUNET_TIME_UNIT_SECONDS
One second.
static struct GNUNET_SCHEDULER_Task * expire_task
Task run to clean up expired records.
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:1269
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:311
#define EXPIRED_RECORDS_CLEANUP_INTERVAL
Interval for expired records cleanup (in seconds)
#define GNUNET_log(kind,...)
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.

References GNUNET_PEERSTORE_PluginFunctions::cls, GNUNET_PEERSTORE_PluginFunctions::expire_records, expire_records_continuation(), 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().

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 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.
#define GNUNET_TIME_UNIT_SECONDS
One second.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
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)
static struct GNUNET_SCHEDULER_Task * expire_task
Task run to clean up expired records.
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:1269
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:311
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:86
static struct GNUNET_PEERSTORE_PluginFunctions * db
Database handle.
#define EXPIRED_RECORDS_CLEANUP_INTERVAL
Interval for expired records cleanup (in seconds)
static void expire_records_continuation(void *cls, int success)
Continuation to expire_records called by the peerstore plugin.
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.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, and num_clients.

Referenced by run().

181 {
182  num_clients++;
184  "A client connected (now %u)\n", num_clients);
185  return client;
186 }
static unsigned int num_clients
Number of connected clients.
#define GNUNET_log(kind,...)
Here is the caller graph for this function:

◆ 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.

References GNUNET_assert, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_OK, GNUNET_YES, and num_clients.

Referenced by client_disconnect_cb().

199 {
200  if (value == cls)
201  {
204  num_clients++; /* Watchers do not count */
205  }
206  return GNUNET_OK;
207 }
static unsigned int num_clients
Number of connected clients.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static char * value
Value of the record to add/remove.
int 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.
static struct GNUNET_CONTAINER_MultiHashMap * watchers
Hashmap with all watch requests.
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.

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

Referenced by run().

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 unsigned int num_clients
Number of connected clients.
static int client_disconnect_it(void *cls, const struct GNUNET_HashCode *key, void *value)
Search for a disconnected client and remove it.
static struct GNUNET_CONTAINER_MultiHashMap * watchers
Hashmap with all watch requests.
static void do_shutdown()
Perform the actual shutdown operations.
#define GNUNET_log(kind,...)
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
static int in_shutdown
Are we in the process of shutting down the service? GNUNET_YES / GNUNET_NO.
Here is the call graph for this function:
Here is the caller 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.

References GNUNET_PEERSTORE_Record::client, env, GNUNET_PEERSTORE_Record::expiry, 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(), GNUNET_PEERSTORE_Record::key, GNUNET_PEERSTORE_Record::peer, PEERSTORE_create_record_mq_envelope(), PEERSTORE_destroy_record(), GNUNET_PEERSTORE_Record::sub_system, GNUNET_PEERSTORE_Record::value, and GNUNET_PEERSTORE_Record::value_size.

Referenced by handle_iterate().

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_PeerIdentity peer
Peer Identity.
void PEERSTORE_destroy_record(struct GNUNET_PEERSTORE_Record *record)
Free any memory allocated for this record.
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2438
size_t value_size
Size of value BLOB.
struct GNUNET_SERVICE_Client * client
Client from which this record originated.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD
Iteration record message.
char * key
Record key string.
void * value
Record value BLOB.
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2325
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.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END
Iteration end message.
struct GNUNET_TIME_Absolute expiry
Expiry time of entry.
char * sub_system
Responsible sub system string.
Single PEERSTORE record.
#define GNUNET_log(kind,...)
Header for all communications.
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
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2244
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.

References env, GNUNET_PEERSTORE_Record::expiry, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD, GNUNET_MQ_send(), GNUNET_SERVICE_client_get_mq(), GNUNET_YES, GNUNET_PEERSTORE_Record::key, GNUNET_PEERSTORE_Record::peer, PEERSTORE_create_record_mq_envelope(), record(), GNUNET_PEERSTORE_Record::sub_system, GNUNET_PEERSTORE_Record::value, value, and GNUNET_PEERSTORE_Record::value_size.

Referenced by watch_notifier().

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 }
struct GNUNET_PeerIdentity peer
Peer Identity.
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2438
size_t value_size
Size of value BLOB.
#define GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD
Watch response.
Handle to a client that is connected to a service.
Definition: service.c:250
char * key
Record key string.
void * value
Record value BLOB.
static char * value
Value of the record to add/remove.
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.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct GNUNET_TIME_Absolute expiry
Expiry time of entry.
char * sub_system
Responsible sub system string.
Single PEERSTORE record.
#define GNUNET_log(kind,...)
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:355
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

References GNUNET_CONTAINER_multihashmap_get_multiple(), GNUNET_PEERSTORE_Record::key, GNUNET_PEERSTORE_Record::peer, PEERSTORE_hash_key(), GNUNET_PEERSTORE_Record::sub_system, and watch_notifier_it().

Referenced by store_record_continuation().

322 {
323  struct GNUNET_HashCode keyhash;
324 
325  PEERSTORE_hash_key (record->sub_system, &record->peer, record->key, &keyhash);
327  &keyhash,
329  record);
330 }
struct GNUNET_PeerIdentity peer
Peer Identity.
char * key
Record key string.
static struct GNUNET_CONTAINER_MultiHashMap * watchers
Hashmap with all watch requests.
A 512-bit hashcode.
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.
int GNUNET_CONTAINER_multihashmap_get_multiple(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map that match a particular key.
char * sub_system
Responsible sub system string.
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.
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.

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, and num_clients.

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 }
static unsigned int num_clients
Number of connected clients.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Handle to a client that is connected to a service.
Definition: service.c:250
int 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.
struct GNUNET_HashCode keyhash
Hash of a record key.
Definition: peerstore.h:104
static struct GNUNET_CONTAINER_MultiHashMap * watchers
Hashmap with all watch requests.
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2325
#define GNUNET_log(kind,...)
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2244
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.

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, and num_clients.

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 }
static unsigned int num_clients
Number of connected clients.
Handle to a client that is connected to a service.
Definition: service.c:250
struct GNUNET_HashCode keyhash
Hash of a record key.
Definition: peerstore.h:104
static struct GNUNET_CONTAINER_MultiHashMap * watchers
Hashmap with all watch requests.
void GNUNET_SERVICE_client_mark_monitor(struct GNUNET_SERVICE_Client *c)
Set the &#39;monitor&#39; flag on this client.
Definition: service.c:2408
int 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.
Allow multiple values with the same key.
#define GNUNET_log(kind,...)
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2244
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.

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

388 {
390 
391  record = PEERSTORE_parse_record_message (srm);
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);
400  PEERSTORE_destroy_record (record);
401  return GNUNET_SYSERR;
402  }
403  PEERSTORE_destroy_record (record);
404  return GNUNET_OK;
405 }
struct GNUNET_PEERSTORE_Record * PEERSTORE_parse_record_message(const struct StoreRecordMessage *srm)
Parses a message carrying a record.
void PEERSTORE_destroy_record(struct GNUNET_PEERSTORE_Record *record)
Free any memory allocated for this record.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
char * sub_system
Responsible sub system string.
Single PEERSTORE record.
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
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.

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

416 {
417  struct GNUNET_SERVICE_Client *client = cls;
419 
420  record = PEERSTORE_parse_record_message (srm);
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);
437  PEERSTORE_destroy_record (record);
438  }
439 }
static void record_iterator(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
Function called by for each matching record.
struct GNUNET_PEERSTORE_Record * PEERSTORE_parse_record_message(const struct StoreRecordMessage *srm)
Parses a message carrying a record.
struct GNUNET_PeerIdentity peer
Peer Identity.
void PEERSTORE_destroy_record(struct GNUNET_PEERSTORE_Record *record)
Free any memory allocated for this record.
struct GNUNET_SERVICE_Client * client
Client from which this record originated.
void * cls
Closure to pass to all plugin functions.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Handle to a client that is connected to a service.
Definition: service.c:250
char * key
Record key string.
uint16_t peer_set
GNUNET_YES if peer id value set, GNUNET_NO otherwise
Definition: peerstore.h:46
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2325
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.
static struct GNUNET_PEERSTORE_PluginFunctions * db
Database handle.
char * sub_system
Responsible sub system string.
Single PEERSTORE record.
#define GNUNET_log(kind,...)
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
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.

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

Referenced by handle_store().

450 {
451  struct GNUNET_PEERSTORE_Record *record = cls;
452 
453  if (GNUNET_OK == success)
454  {
455  watch_notifier (record);
457  }
458  else
459  {
460  GNUNET_break (0);
462  }
463  PEERSTORE_destroy_record (record);
464 }
void PEERSTORE_destroy_record(struct GNUNET_PEERSTORE_Record *record)
Free any memory allocated for this record.
struct GNUNET_SERVICE_Client * client
Client from which this record originated.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2325
Single PEERSTORE record.
static void watch_notifier(struct GNUNET_PEERSTORE_Record *record)
Given a new record, notifies watchers.
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2244
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.

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, GNUNET_PEERSTORE_Record::key, PEERSTORE_destroy_record(), PEERSTORE_parse_record_message(), record(), and GNUNET_PEERSTORE_Record::sub_system.

476 {
478 
479  record = PEERSTORE_parse_record_message (srm);
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);
488  PEERSTORE_destroy_record (record);
489  return GNUNET_SYSERR;
490  }
491  PEERSTORE_destroy_record (record);
492  return GNUNET_OK;
493 }
struct GNUNET_PEERSTORE_Record * PEERSTORE_parse_record_message(const struct StoreRecordMessage *srm)
Parses a message carrying a record.
void PEERSTORE_destroy_record(struct GNUNET_PEERSTORE_Record *record)
Free any memory allocated for this record.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
char * key
Record key string.
char * sub_system
Responsible sub system string.
Single PEERSTORE record.
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
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.

References GNUNET_PEERSTORE_Record::client, GNUNET_PEERSTORE_PluginFunctions::cls, GNUNET_PEERSTORE_Record::expiry, GNUNET_break, GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_log, GNUNET_OK, GNUNET_SERVICE_client_drop(), GNUNET_PEERSTORE_Record::key, StoreRecordMessage::options, GNUNET_PEERSTORE_Record::peer, PEERSTORE_destroy_record(), PEERSTORE_parse_record_message(), record(), GNUNET_PEERSTORE_PluginFunctions::store_record, store_record_continuation(), GNUNET_PEERSTORE_Record::sub_system, GNUNET_PEERSTORE_Record::value, and GNUNET_PEERSTORE_Record::value_size.

504 {
505  struct GNUNET_SERVICE_Client *client = cls;
507 
508  record = PEERSTORE_parse_record_message (srm);
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);
529  PEERSTORE_destroy_record (record);
531  return;
532  }
533 }
struct GNUNET_PEERSTORE_Record * PEERSTORE_parse_record_message(const struct StoreRecordMessage *srm)
Parses a message carrying a record.
struct GNUNET_PeerIdentity peer
Peer Identity.
void PEERSTORE_destroy_record(struct GNUNET_PEERSTORE_Record *record)
Free any memory allocated for this record.
size_t value_size
Size of value BLOB.
struct GNUNET_SERVICE_Client * client
Client from which this record originated.
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.
void * cls
Closure to pass to all plugin functions.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Handle to a client that is connected to a service.
Definition: service.c:250
char * key
Record key string.
void * value
Record value BLOB.
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2325
uint32_t options
Options, needed only in case of a store operation.
Definition: peerstore.h:80
static struct GNUNET_PEERSTORE_PluginFunctions * db
Database handle.
static void store_record_continuation(void *cls, int success)
Continuation of store_record called by the peerstore plugin.
struct GNUNET_TIME_Absolute expiry
Expiry time of entry.
char * sub_system
Responsible sub system string.
Single PEERSTORE record.
#define GNUNET_log(kind,...)
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
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.

References _, cleanup_expired_records(), client_connect_cb(), client_disconnect_cb(), db_lib_name, GNUNET_asprintf(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONTAINER_multihashmap_create(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_log_config_missing(), GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_NO, GNUNET_OK, GNUNET_PLUGIN_load(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_SERVICE_MAIN(), GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, in_shutdown, num_clients, shutdown_task(), and watch.

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 unsigned int num_clients
Number of connected clients.
static void cleanup_expired_records(void *cls)
Deletes any expired records from storage.
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:1331
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
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.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
static struct GNUNET_SCHEDULER_Task * expire_task
Task run to clean up expired records.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
static void shutdown_task(void *cls)
Task run during shutdown.
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:1296
static struct GNUNET_CONTAINER_MultiHashMap * watchers
Hashmap with all watch requests.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static struct GNUNET_PEERSTORE_PluginFunctions * db
Database handle.
#define GNUNET_log(kind,...)
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
void * GNUNET_PLUGIN_load(const char *library_name, void *arg)
Setup plugin (runs the "init" callback and returns whatever "init" returned).
Definition: plugin.c:217
static int in_shutdown
Are we in the process of shutting down the service? GNUNET_YES / GNUNET_NO.
#define GNUNET_free(ptr)
Wrapper around free.
static char * db_lib_name
Database plugin library name.
Here is the call graph for this function:

◆ GNUNET_SERVICE_MAIN()

Define "main" method using service macro.

Referenced by run().

Here is the caller graph for this function:

Variable Documentation

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Our configuration.

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

◆ 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.

◆ watchers

struct GNUNET_CONTAINER_MultiHashMap* watchers
static

Hashmap with all watch requests.

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

◆ 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.

◆ 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