peerstore service implementation More...
#include "platform.h"
#include "gnunet_util_lib.h"
#include "peerstore.h"
#include "gnunet_peerstore_plugin.h"
#include "peerstore_common.h"
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_Handle * | cfg |
Our configuration. More... | |
static char * | db_lib_name |
Database plugin library name. More... | |
static struct GNUNET_PEERSTORE_PluginFunctions * | db |
Database handle. More... | |
static struct GNUNET_CONTAINER_MultiHashMap * | watchers |
Hashmap with all watch requests. More... | |
static struct GNUNET_SCHEDULER_Task * | expire_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... | |
peerstore service implementation
Definition in file gnunet-service-peerstore.c.
#define EXPIRED_RECORDS_CLEANUP_INTERVAL 300 /* 5mins */ |
Interval for expired records cleanup (in seconds)
Definition at line 36 of file gnunet-service-peerstore.c.
|
static |
Perform the actual shutdown operations.
Definition at line 78 of file gnunet-service-peerstore.c.
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().
|
static |
Task run during shutdown.
cls | unused |
Definition at line 108 of file gnunet-service-peerstore.c.
References do_shutdown(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_YES, in_shutdown, and num_clients.
Referenced by run().
|
static |
Continuation to expire_records called by the peerstore plugin.
cls | unused |
success | count of records deleted or GNUNET_SYSERR |
Definition at line 156 of file gnunet-service-peerstore.c.
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().
|
static |
Deletes any expired records from storage.
Definition at line 127 of file gnunet-service-peerstore.c.
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().
|
static |
A client disconnected.
Remove all of its data structure entries.
cls | closure, NULL |
client | identification of the client |
mq | the message queue |
Definition at line 178 of file gnunet-service-peerstore.c.
References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, and num_clients.
|
static |
Search for a disconnected client and remove it.
cls | closuer, a struct GNUNET_SERVICE_Client |
key | hash of record key |
value | the watcher client, a struct GNUNET_SERVICE_Client * |
Definition at line 198 of file gnunet-service-peerstore.c.
References GNUNET_assert, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_OK, GNUNET_YES, key, num_clients, value, and watchers.
Referenced by client_disconnect_cb().
|
static |
A client disconnected.
Remove all of its data structure entries.
cls | closure, NULL |
client | identification 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, num_clients, and watchers.
|
static |
Function called by for each matching record.
cls | closure |
record | peerstore record found |
emsg | error message or NULL if no errors |
Definition at line 243 of file gnunet-service-peerstore.c.
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().
|
static |
Iterator over all watcher clients to notify them of a new record.
cls | closure, a struct GNUNET_PEERSTORE_Record * |
key | hash of record key |
value | the watcher client, a struct GNUNET_SERVICE_Client * |
Definition at line 294 of file gnunet-service-peerstore.c.
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().
|
static |
Given a new record, notifies watchers.
record | changed record to update watchers with |
Definition at line 321 of file gnunet-service-peerstore.c.
References GNUNET_CONTAINER_multihashmap_get_multiple(), PEERSTORE_hash_key(), record(), watch_notifier_it(), and watchers.
Referenced by store_record_continuation().
|
static |
Handle a watch cancel request from client.
cls | identification of the client |
hm | the 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, num_clients, and watchers.
|
static |
Handle a watch request from client.
cls | identification of the client |
hm | the 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, num_clients, and watchers.
|
static |
Check an iterate request from client.
cls | client identification of the client |
srm | the actual message |
Definition at line 387 of file gnunet-service-peerstore.c.
References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, PEERSTORE_destroy_record(), PEERSTORE_parse_record_message(), and record().
|
static |
Handle an iterate request from client.
cls | identification of the client |
srm | the actual message |
Definition at line 415 of file gnunet-service-peerstore.c.
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().
|
static |
Continuation of store_record called by the peerstore plugin.
cls | closure |
success | result |
Definition at line 449 of file gnunet-service-peerstore.c.
References GNUNET_break, GNUNET_OK, GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_drop(), PEERSTORE_destroy_record(), record(), and watch_notifier().
Referenced by handle_store().
|
static |
Check a store request from client.
cls | client identification of the client |
srm | the actual message |
Definition at line 475 of file gnunet-service-peerstore.c.
References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, PEERSTORE_destroy_record(), PEERSTORE_parse_record_message(), and record().
|
static |
Handle a store request from client.
cls | client identification of the client |
srm | the actual message |
Definition at line 503 of file gnunet-service-peerstore.c.
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().
|
static |
Peerstore service runner.
cls | closure |
c | configuration to use |
service | the initialized service |
Definition at line 544 of file gnunet-service-peerstore.c.
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.
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.
|
static |
|
static |
Database plugin library name.
Definition at line 46 of file gnunet-service-peerstore.c.
Referenced by do_shutdown(), and run().
|
static |
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().
|
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().
|
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().
|
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().
|
static |
Number of connected clients.
Definition at line 71 of file gnunet-service-peerstore.c.
Referenced by client_connect_cb(), client_disconnect_cb(), client_disconnect_it(), handle_watch(), handle_watch_cancel(), run(), and shutdown_task().