31 #define LOG(kind, ...) GNUNET_log_from (kind, "peerstore-api", __VA_ARGS__)
279 icb_cls = ic->callback_cls;
282 icb (icb_cls, NULL,
"Iteration canceled due to reconnection");
306 "Scheduling task to reconnect to PEERSTORE service in %s.\n",
351 "Received an error notification from MQ of type: %d\n",
456 if (NULL !=
h->watches)
462 while (NULL != (ic =
h->iterate_head))
467 if (NULL !=
h->store_head)
472 "Delaying disconnection due to pending store requests.\n");
476 while (NULL != (
sc =
h->store_head))
499 "store cancel with sc %p \n",
507 "store cancel with sc %p is null\n",
509 if ((
GNUNET_YES ==
h->disconnecting) && (NULL ==
h->store_head))
546 "Storing value (size: %lu) for subsystem `%s', peer `%s', key `%s'\n",
599 ic =
h->iterate_head;
603 _ (
"Unexpected iteration response, this should not happen.\n"));
648 ic =
h->iterate_head;
652 _ (
"Unexpected iteration response, this should not happen.\n"));
659 if (NULL == callback)
664 callback (callback_cls,
666 _ (
"Received a malformed response from service."));
670 callback (callback_cls,
record, NULL);
728 "Sending an iterate request for sub system `%s'\n",
780 _ (
"Received a watch result for a non existing watch.\n"));
832 "Resending pending requests after reconnect.\n");
833 if (NULL !=
h->watches)
904 const char *sub_system,
921 if (NULL ==
h->watches)
929 "Sending a watch request for subsystem `%s', peer `%s', key `%s'.\n",
struct GNUNET_GETOPT_CommandLineOption options[]
struct GNUNET_MessageHeader * msg
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
struct GNUNET_HashCode key
The key used in the DHT.
static char * value
Value of the record to add/remove.
static struct GNUNET_FS_SearchContext * sc
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
#define GNUNET_log(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
GNUNET_MQ_Error
Error codes for the queue.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
struct GNUNET_PEERSTORE_Handle * GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the PEERSTORE service.
struct GNUNET_PEERSTORE_StoreContext * GNUNET_PEERSTORE_store(struct GNUNET_PEERSTORE_Handle *h, 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 new entry in the PEERSTORE.
void GNUNET_PEERSTORE_store_cancel(struct GNUNET_PEERSTORE_StoreContext *sc)
Cancel a store request.
void GNUNET_PEERSTORE_iterate_cancel(struct GNUNET_PEERSTORE_IterateContext *ic)
Cancel an iterate request Please do not call after the iterate request is done.
GNUNET_PEERSTORE_StoreOption
Options for storing values in PEERSTORE.
void(* GNUNET_PEERSTORE_Processor)(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
Function called by PEERSTORE for each matching record.
struct GNUNET_PEERSTORE_WatchContext * GNUNET_PEERSTORE_watch(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_PEERSTORE_Processor callback, void *callback_cls)
Request watching a given key User will be notified with any new values added to key.
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h, int sync_first)
Disconnect from the PEERSTORE service.
void GNUNET_PEERSTORE_watch_cancel(struct GNUNET_PEERSTORE_WatchContext *wc)
Cancel a watch request.
void(* GNUNET_PEERSTORE_Continuation)(void *cls, int success)
Continuation called with a status result.
struct GNUNET_PEERSTORE_IterateContext * GNUNET_PEERSTORE_iterate(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_PEERSTORE_Processor callback, void *callback_cls)
Iterate over records matching supplied key information.
#define GNUNET_MESSAGE_TYPE_PEERSTORE_STORE
Store request message.
#define GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL
Watch cancel request.
#define GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH
Watch request.
#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD
Iteration record message.
#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE
Iteration request.
#define GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD
Watch response.
#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END
Iteration end message.
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.
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
static unsigned int size
Size of the "table".
static int check_watch_record(void *cls, const struct StoreRecordMessage *msg)
When a watch record is received, validate it is well-formed.
static int destroy_watch(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over watch requests to cancel them.
static void handle_client_error(void *cls, enum GNUNET_MQ_Error error)
Function called when we had trouble talking to the service.
static void handle_iterate_result(void *cls, const struct StoreRecordMessage *msg)
When a response for iterate request is received.
static void handle_iterate_end(void *cls, const struct GNUNET_MessageHeader *msg)
When a response for iterate request is received.
static void reconnect(void *cls)
Close the existing connection to PEERSTORE and reconnect.
static int rewatch_it(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over previous watches to resend them.
static void store_request_sent(void *cls)
Callback after MQ envelope is sent.
static void disconnect_and_schedule_reconnect(struct GNUNET_PEERSTORE_Handle *h)
Function that will schedule the job that will try to connect us again to the client.
static void disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the peerstore service.
static void final_disconnect(struct GNUNET_PEERSTORE_Handle *h)
Kill the connection to the service.
static void handle_watch_record(void *cls, const struct StoreRecordMessage *msg)
When a watch record is received, process it.
static int check_iterate_result(void *cls, const struct StoreRecordMessage *msg)
When a response for iterate request is received, check the message is well-formed.
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.
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_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.
Helper peerstore functions.
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the reconnect task (if any).
Internal representation of the hash map.
enum GNUNET_FS_SearchOptions options
Options for the search.
struct GNUNET_FS_Handle * h
Handle to the global FS context.
Handle to a message queue.
Message handler for a specific message type.
Handle to the PEERSTORE service.
struct GNUNET_PEERSTORE_IterateContext * iterate_tail
Tail of active ITERATE requests.
struct GNUNET_MQ_Handle * mq
Message queue.
int disconnecting
Are we in the process of disconnecting but need to sync first?
struct GNUNET_TIME_Relative reconnect_delay
Delay until we try to reconnect.
struct GNUNET_PEERSTORE_StoreContext * store_tail
Tail of active STORE requests.
struct GNUNET_PEERSTORE_StoreContext * store_head
Head of active STORE requests.
struct GNUNET_PEERSTORE_IterateContext * iterate_head
Head of active ITERATE requests.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the task trying to reconnect to the service.
struct GNUNET_CONTAINER_MultiHashMap * watches
Hashmap of watch requests.
Context for a iterate request.
char * sub_system
Which subsystem does the store?
void * callback_cls
Closure for callback.
int iterating
GNUNET_YES if we are currently processing records.
char * key
Key for the store operation.
GNUNET_PEERSTORE_Processor callback
Callback with each matching record.
struct GNUNET_PEERSTORE_IterateContext * prev
Kept in a DLL.
struct GNUNET_PEERSTORE_Handle * h
Handle to the PEERSTORE service.
struct GNUNET_PEERSTORE_IterateContext * next
Kept in a DLL.
struct GNUNET_PeerIdentity peer
Peer the store is for.
Context for a store request.
char * sub_system
Which subsystem does the store?
enum GNUNET_PEERSTORE_StoreOption options
Options for the store operation.
void * value
Contains size bytes.
struct GNUNET_TIME_Absolute expiry
When does the value expire?
struct GNUNET_PEERSTORE_StoreContext * prev
Kept in a DLL.
void * cont_cls
Closure for cont.
struct GNUNET_PEERSTORE_StoreContext * next
Kept in a DLL.
size_t size
Number of bytes in value.
struct GNUNET_PEERSTORE_Handle * h
Handle to the PEERSTORE service.
GNUNET_PEERSTORE_Continuation cont
Continuation called with service response.
struct GNUNET_PeerIdentity peer
Peer the store is for.
char * key
Key for the store operation.
Context for a watch request.
struct GNUNET_PEERSTORE_WatchContext * next
Kept in a DLL.
void * callback_cls
Closure for callback.
struct GNUNET_HashCode keyhash
Hash of the combined key.
struct GNUNET_PEERSTORE_WatchContext * prev
Kept in a DLL.
GNUNET_PEERSTORE_Processor callback
Callback with each record received.
struct GNUNET_PEERSTORE_Handle * h
Handle to the PEERSTORE service.
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
Message carrying record key hash.
struct GNUNET_HashCode keyhash
Hash of a record key.
Message carrying a PEERSTORE record message.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.