34#define LOG(kind, ...) GNUNET_log_from (kind, "peerstore-api", __VA_ARGS__)
345 return h->last_op_id++;
357 if (NULL !=
h->watches)
384 "Scheduling task to reconnect to PEERSTORE service in %s.\n",
406 "Received an error notification from MQ of type: %d\n",
475 "store cancel with sc %p \n",
479 "store cancel with sc %p is null\n",
516 "Storing value (size: %llu) for subsystem `%s', peer `%s', key `%s'\n",
517 (
unsigned long long)
size,
571 for (
sc =
h->store_head; NULL !=
sc;
sc =
sc->next)
573 if (
sc->rid == ntohs (
msg->rid))
579 _ (
"Unexpected store response.\n"));
582 if (NULL !=
sc->cont)
583 sc->cont (
sc->cont_cls, ntohl (
msg->result));
614 for (ic =
h->iterate_head; NULL != ic; ic = ic->
next)
615 if (ic->
rid == ntohs (
msg->rid))
620 _ (
"Unexpected iteration response.\n"));
659 for (ic =
h->iterate_head; NULL != ic; ic = ic->
next)
660 if (ic->
rid == ntohs (
msg->rid))
666 "Unexpected iteration response, no iterating client found, discarding message.\n"));
676 _ (
"Received a malformed response from service."));
700 "Sending PEERSTORE_ITERATION_NEXT message\n");
702 inm->
rid = htons (ic->
rid);
704 if (NULL == ic->
h->
mq)
728 "Sending PEERSTORE_ITERATION_STOP message\n");
729 if (NULL != ic->
h->
mq)
732 ism->
rid = htons (ic->
rid);
733 if (NULL != ic->
h->
mq)
764 key_size = strlen (
key) + 1;
765 msg_size = ss_size + key_size;
769 srm->
rid = htons (ic->
rid);
789 "Sending an iterate request for sub system `%s'\n",
836 "Resending pending requests after reconnect.\n");
859 "Storing hello uri failed\n");
880 if ((NULL ==
record) && (NULL == emsg))
907 "Not storing hello for %s since we seem to have a newer version on record expiring `%s' and after `%s'.\n",
934 uint16_t size_msg = ntohs (
msg->
size);
952 "Adding hello for peer %s with expiration %s msg size %u\n",
struct GNUNET_GETOPT_CommandLineOption options[]
struct GNUNET_MessageHeader * msg
static struct GNUNET_ARM_Handle * h
Connection with ARM.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
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 struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static char * value
Value of the record to add/remove.
static struct GNUNET_FS_SearchContext * sc
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
Helper library for handling HELLO URIs.
API to the peerstore service.
Constants for network protocols.
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.
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
void GNUNET_HELLO_parser_free(struct GNUNET_HELLO_Parser *parser)
Release resources of a builder.
struct GNUNET_HELLO_Parser * GNUNET_HELLO_parser_from_msg(const struct GNUNET_MessageHeader *msg)
Parse msg.
struct GNUNET_TIME_Absolute GNUNET_HELLO_get_expiration_time_from_msg(const struct GNUNET_MessageHeader *msg)
Get the expiration time for this HELLO.
const struct GNUNET_PeerIdentity * GNUNET_HELLO_parser_get_id(const struct GNUNET_HELLO_Parser *parser)
Get the PeerIdentity for this builder.
#define GNUNET_log(kind,...)
void * cls
Closure for mv and cb.
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
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.
@ GNUNET_ERROR_TYPE_WARNING
@ 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_malloc(size)
Wrapper around malloc.
#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_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#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_IterateContext * GNUNET_PEERSTORE_iteration_start(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 peerstore entries.
void GNUNET_PEERSTORE_iteration_next(struct GNUNET_PEERSTORE_IterateContext *ic, uint64_t limit)
Cancel an iterate request Please do not call after the iterate request is done.
void GNUNET_PEERSTORE_store_cancel(struct GNUNET_PEERSTORE_StoreContext *sc)
Cancel a store request.
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the PEERSTORE service.
void(* GNUNET_PEERSTORE_hello_notify_cb)(void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *hello, const char *err_msg)
Function called by PEERSTORE when notifying a client about a changed hello.
struct GNUNET_PEERSTORE_Handle * GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the PEERSTORE service.
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.
void GNUNET_PEERSTORE_hello_add_cancel(struct GNUNET_PEERSTORE_StoreHelloContext *huc)
Cancel the request to add a hello.
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_Continuation)(void *cls, int success)
Continuation called with a status result.
void GNUNET_PEERSTORE_iteration_stop(struct GNUNET_PEERSTORE_IterateContext *ic)
Cancel an iterate request Please do not call after the iterate request is done.
#define GNUNET_PEERSTORE_HELLO_KEY
Key used for storing HELLO in the peerstore.
struct GNUNET_PEERSTORE_StoreHelloContext * GNUNET_PEERSTORE_hello_add(struct GNUNET_PEERSTORE_Handle *h, const struct GNUNET_MessageHeader *msg, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
Add hello to peerstore.
@ GNUNET_PEERSTORE_STOREOPTION_REPLACE
Delete any previous values for the given key before storing the given value.
#define GNUNET_MESSAGE_TYPE_PEERSTORE_STORE
Store request message.
#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_START
Iteration request (see also 828, 829)
#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_NEXT
Iteration request (see also 821, 829)
#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_STOP
Iteration request (see also 821, 828)
#define GNUNET_MESSAGE_TYPE_PEERSTORE_RECORD
Record result message.
#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END
Iteration end message.
#define GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT
Store result 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.
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
#define GNUNET_TIME_absolute_cmp(t1, op, t2)
Compare two absolute times.
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
#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 void handle_iterate_result(void *cls, const struct PeerstoreRecordMessage *msg)
When a response for iterate request is received.
static void handle_client_error(void *cls, enum GNUNET_MQ_Error error)
Function called when we had trouble talking to the service.
static void hello_add_iter(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
static void handle_iterate_end(void *cls, const struct PeerstoreResultMessage *msg)
When a response for iterate request is received.
static uint32_t get_op_id(struct GNUNET_PEERSTORE_Handle *h)
Get a fresh operation id to distinguish between namestore requests.
static void reconnect(void *cls)
Close the existing connection to PEERSTORE and reconnect.
static int check_iterate_result(void *cls, const struct PeerstoreRecordMessage *msg)
When a response for iterate request is received, check the message is well-formed.
static void handle_store_result(void *cls, const struct PeerstoreResultMessage *msg)
When a response for store request is received.
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 destroy_iteratecontext(struct GNUNET_PEERSTORE_IterateContext *ic)
static void destroy_storecontext(struct GNUNET_PEERSTORE_StoreContext *sc)
static void hello_store_success(void *cls, int success)
struct GNUNET_PEERSTORE_Record * PEERSTORE_parse_record_message(const struct PeerstoreRecordMessage *srm)
Parses a message carrying a record.
struct GNUNET_MQ_Envelope * PEERSTORE_create_record_mq_envelope(uint32_t rid, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, const void *value, size_t value_size, struct GNUNET_TIME_Absolute expiry, enum GNUNET_PEERSTORE_StoreOption options, uint16_t msg_type)
Creates a MQ envelope for a single record.
void PEERSTORE_destroy_record(struct GNUNET_PEERSTORE_Record *record)
Free any memory allocated for this record.
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.
Context for parsing HELLOs.
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.
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.
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_MQ_Envelope * env
Temporary envelope.
struct GNUNET_PEERSTORE_IterateContext * next
Kept in a DLL.
struct GNUNET_PeerIdentity peer
Peer the store is for.
Context for the info handler.
void * callback_cls
Closure for callback.
GNUNET_PEERSTORE_hello_notify_cb callback
Function to call with information.
unsigned int canceled
Is this request canceled.
struct GNUNET_PEERSTORE_Monitor * wc
The watch for this context.
struct GNUNET_PEERSTORE_Handle * h
Peerstore handle.
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_MQ_Envelope * env
Temporary envelope.
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 add hello uri request.
struct GNUNET_MessageHeader * hello
Hello uri which was request for storing.
struct GNUNET_PEERSTORE_Handle * h
Peerstore handle.
struct GNUNET_PEERSTORE_IterateContext * ic
The iteration for the merge.
GNUNET_PEERSTORE_Continuation cont
Function to call with information.
struct GNUNET_PeerIdentity pid
The peer id for the hello.
struct GNUNET_PEERSTORE_StoreContext * sc
Store operation for the merge.
void * cont_cls
Closure for callback.
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.
uint64_t limit
Number of records to return.
uint16_t peer_set
GNUNET_YES if peer id value set, GNUNET_NO otherwise
struct GNUNET_PeerIdentity peer
Peer Identity.
uint16_t sub_system_size
Size of the sub_system string Allocated at position 0 after this struct.
uint16_t key_size
Size of the key string Allocated at position 1 after this struct.
Message carrying a PEERSTORE record message.
Message carrying a PEERSTORE result message.
Closure for store callback when storing hello uris.
struct GNUNET_PEERSTORE_StoreHelloContext * huc
The corresponding hello uri add request.
struct GNUNET_PEERSTORE_StoreContext * sc
The corresponding store context.