GNUnet  0.10.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_free, GNUNET_PLUGIN_unload(), GNUNET_SCHEDULER_cancel(), and GNUNET_SCHEDULER_shutdown().

Referenced by client_disconnect_cb(), and shutdown_task().

79 {
80  if (NULL != db_lib_name)
81  {
84  db_lib_name = NULL;
85  }
86  if (NULL != watchers)
87  {
89  watchers = NULL;
90  }
91  if (NULL != expire_task)
92  {
94  expire_task = NULL;
95  }
97 }
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:517
#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:255
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_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
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 106 of file gnunet-service-peerstore.c.

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

Referenced by run().

107 {
109  if (0 == num_clients) /* Only when no connected clients. */
110  do_shutdown();
111 }
static unsigned int num_clients
Number of connected clients.
static void do_shutdown()
Perform the actual shutdown operations.
#define GNUNET_YES
Definition: gnunet_common.h:77
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 152 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().

153 {
154  if (success > 0)
155  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", success);
156  GNUNET_assert(NULL == expire_task);
161  NULL);
162 }
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:1237
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:440
#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 123 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().

124 {
125  int ret;
126 
127  expire_task = NULL;
128  GNUNET_assert(NULL != db);
129  ret = db->expire_records(db->cls,
132  NULL);
133  if (GNUNET_OK != ret)
134  {
135  GNUNET_assert(NULL == expire_task);
140  NULL);
141  }
142 }
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.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static int ret
Final status code.
Definition: gnunet-arm.c:89
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:1237
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:440
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
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 174 of file gnunet-service-peerstore.c.

References num_clients.

Referenced by run().

177 {
178  num_clients++;
179  return client;
180 }
static unsigned int num_clients
Number of connected clients.
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 192 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().

193 {
194  if (value == cls)
195  {
198  num_clients++;
199  }
200  return GNUNET_OK;
201 }
static unsigned int num_clients
Number of connected clients.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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.
#define GNUNET_YES
Definition: gnunet_common.h:77
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 211 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().

214 {
215  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "A client disconnected, cleaning up.\n");
216  if (NULL != watchers)
219  client);
220  num_clients--;
221  if ((0 == num_clients) && in_shutdown)
222  do_shutdown();
223 }
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 235 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().

238 {
239  struct GNUNET_PEERSTORE_Record *cls_record = cls;
240  struct GNUNET_MQ_Envelope *env;
241 
242  if (NULL == record)
243  {
244  /* No more records */
245  struct GNUNET_MessageHeader *endmsg;
246 
249  if (NULL == emsg)
250  {
252  }
253  else
254  {
255  GNUNET_break(0);
256  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to iterate: %s\n", emsg);
257  GNUNET_SERVICE_client_drop(cls_record->client);
258  }
259  PEERSTORE_destroy_record(cls_record);
260  return;
261  }
262 
264  record->sub_system,
265  &record->peer,
266  record->key,
267  record->value,
268  record->value_size,
269  record->expiry,
270  0,
273 }
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:2424
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:2315
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:351
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2234
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 286 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().

287 {
288  struct GNUNET_PEERSTORE_Record *record = cls;
289  struct GNUNET_SERVICE_Client *client = value;
290  struct GNUNET_MQ_Envelope *env;
291 
292  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found a watcher to update.\n");
294  record->sub_system,
295  &record->peer,
296  record->key,
297  record->value,
298  record->value_size,
299  record->expiry,
300  0,
303  return GNUNET_YES;
304 }
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:2424
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:246
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.
#define GNUNET_YES
Definition: gnunet_common.h:77
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:351
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 313 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().

314 {
315  struct GNUNET_HashCode keyhash;
316 
317  PEERSTORE_hash_key(record->sub_system, &record->peer, record->key, &keyhash);
319  &keyhash,
321  record);
322 }
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 332 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.

333 {
334  struct GNUNET_SERVICE_Client *client = cls;
335 
336  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received a watch cancel request.\n");
337  if (GNUNET_OK !=
339  {
340  GNUNET_break(0);
342  return;
343  }
344  num_clients++;
346 }
static unsigned int num_clients
Number of connected clients.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#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:246
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:102
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:2315
#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:2234
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 356 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.

357 {
358  struct GNUNET_SERVICE_Client *client = cls;
359 
360  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received a watch request.\n");
361  num_clients--; /* do not count watchers */
364  &hm->keyhash,
365  client,
368 }
static unsigned int num_clients
Number of connected clients.
Handle to a client that is connected to a service.
Definition: service.c:246
struct GNUNET_HashCode keyhash
Hash of a record key.
Definition: peerstore.h:102
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:2394
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:2234
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 379 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.

380 {
382 
383  record = PEERSTORE_parse_record_message(srm);
384  if (NULL == record)
385  {
386  GNUNET_break(0);
387  return GNUNET_SYSERR;
388  }
389  if (NULL == record->sub_system)
390  {
391  GNUNET_break(0);
392  PEERSTORE_destroy_record(record);
393  return GNUNET_SYSERR;
394  }
395  PEERSTORE_destroy_record(record);
396  return GNUNET_OK;
397 }
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_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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 407 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.

408 {
409  struct GNUNET_SERVICE_Client *client = cls;
411 
412  record = PEERSTORE_parse_record_message(srm);
414  "Iterate request: ss `%s', peer `%s', key `%s'\n",
415  record->sub_system,
416  GNUNET_i2s(&record->peer),
417  (NULL == record->key) ? "NULL" : record->key);
418  record->client = client;
419  if (GNUNET_OK !=
421  record->sub_system,
422  (ntohs(srm->peer_set)) ? &record->peer : NULL,
423  record->key,
425  record))
426  {
427  GNUNET_break(0);
429  PEERSTORE_destroy_record(record);
430  }
431 }
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.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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:246
char * key
Record key string.
uint16_t peer_set
GNUNET_YES if peer id value set, GNUNET_NO otherwise
Definition: peerstore.h:45
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2315
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 441 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().

442 {
443  struct GNUNET_PEERSTORE_Record *record = cls;
444 
445  if (GNUNET_OK == success)
446  {
447  watch_notifier(record);
449  }
450  else
451  {
452  GNUNET_break(0);
454  }
455  PEERSTORE_destroy_record(record);
456 }
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_OK
Named constants for return values.
Definition: gnunet_common.h:75
#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:2315
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:2234
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 467 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.

468 {
470 
471  record = PEERSTORE_parse_record_message(srm);
472  if (NULL == record)
473  {
474  GNUNET_break(0);
475  return GNUNET_SYSERR;
476  }
477  if ((NULL == record->sub_system) || (NULL == record->key))
478  {
479  GNUNET_break(0);
480  PEERSTORE_destroy_record(record);
481  return GNUNET_SYSERR;
482  }
483  PEERSTORE_destroy_record(record);
484  return GNUNET_OK;
485 }
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_OK
Named constants for return values.
Definition: gnunet_common.h:75
#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.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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 495 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.

496 {
497  struct GNUNET_SERVICE_Client *client = cls;
499 
500  record = PEERSTORE_parse_record_message(srm);
501  GNUNET_log(
503  "Received a store request. Sub system `%s' Peer `%s Key `%s' Options: %u.\n",
504  record->sub_system,
505  GNUNET_i2s(&record->peer),
506  record->key,
507  (uint32_t)ntohl(srm->options));
508  record->client = client;
509  if (GNUNET_OK != db->store_record(db->cls,
510  record->sub_system,
511  &record->peer,
512  record->key,
513  record->value,
514  record->value_size,
515  record->expiry,
516  ntohl(srm->options),
518  record))
519  {
520  GNUNET_break(0);
521  PEERSTORE_destroy_record(record);
523  return;
524  }
525 }
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.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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:246
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:2315
uint32_t options
Options, needed only in case of a store operation.
Definition: peerstore.h:79
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 536 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, shutdown_task(), and watch.

539 {
540  char *database;
541 
543  cfg = c;
545  "peerstore",
546  "DATABASE",
547  &database))
548  {
550  "peerstore",
551  "DATABASE");
553  return;
554  }
555  GNUNET_asprintf(&db_lib_name, "libgnunet_plugin_peerstore_%s", database);
556  db = GNUNET_PLUGIN_load(db_lib_name, (void *)cfg);
557  GNUNET_free(database);
558  if (NULL == db)
559  {
561  _("Could not load database backend `%s'\n"),
562  db_lib_name);
564  return;
565  }
569 }
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:1284
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:517
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
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:1264
static struct GNUNET_CONTAINER_MultiHashMap * watchers
Hashmap with all watch requests.
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
static const struct GNUNET_CONFIGURATION_Handle * 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:206
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