GNUnet  0.11.x
Data Structures | Macros | Functions
peerstore_api.c File Reference

API for peerstore. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "peerstore.h"
#include "peerstore_common.h"
Include dependency graph for peerstore_api.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_PEERSTORE_Handle
 Handle to the PEERSTORE service. More...
 
struct  GNUNET_PEERSTORE_StoreContext
 Context for a store request. More...
 
struct  GNUNET_PEERSTORE_IterateContext
 Context for a iterate request. More...
 
struct  GNUNET_PEERSTORE_WatchContext
 Context for a watch request. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "peerstore-api", __VA_ARGS__)
 

Functions

static void reconnect (void *cls)
 Close the existing connection to PEERSTORE and reconnect. More...
 
static void disconnect (struct GNUNET_PEERSTORE_Handle *h)
 Disconnect from the peerstore service. More...
 
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. More...
 
static void store_request_sent (void *cls)
 Callback after MQ envelope is sent. More...
 
static void handle_client_error (void *cls, enum GNUNET_MQ_Error error)
 Function called when we had trouble talking to the service. More...
 
static int rewatch_it (void *cls, const struct GNUNET_HashCode *key, void *value)
 Iterator over previous watches to resend them. More...
 
static int destroy_watch (void *cls, const struct GNUNET_HashCode *key, void *value)
 Iterator over watch requests to cancel them. More...
 
static void final_disconnect (struct GNUNET_PEERSTORE_Handle *h)
 Kill the connection to the service. More...
 
struct GNUNET_PEERSTORE_HandleGNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Connect to the PEERSTORE service. More...
 
void GNUNET_PEERSTORE_disconnect (struct GNUNET_PEERSTORE_Handle *h, int sync_first)
 Disconnect from the PEERSTORE service. More...
 
void GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc)
 Cancel a store request. More...
 
struct GNUNET_PEERSTORE_StoreContextGNUNET_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. More...
 
static void handle_iterate_end (void *cls, const struct GNUNET_MessageHeader *msg)
 When a response for iterate request is received. More...
 
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. More...
 
static void handle_iterate_result (void *cls, const struct StoreRecordMessage *msg)
 When a response for iterate request is received. More...
 
void GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic)
 Cancel an iterate request Please do not call after the iterate request is done. More...
 
struct GNUNET_PEERSTORE_IterateContextGNUNET_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. More...
 
static int check_watch_record (void *cls, const struct StoreRecordMessage *msg)
 When a watch record is received, validate it is well-formed. More...
 
static void handle_watch_record (void *cls, const struct StoreRecordMessage *msg)
 When a watch record is received, process it. More...
 
void GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext *wc)
 Cancel a watch request. More...
 
struct GNUNET_PEERSTORE_WatchContextGNUNET_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. More...
 

Detailed Description

API for peerstore.

Author
Omar Tarabai
Christian Grothoff

Definition in file peerstore_api.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "peerstore-api", __VA_ARGS__)

Function Documentation

◆ reconnect()

static void reconnect ( void *  cls)
static

Close the existing connection to PEERSTORE and reconnect.

Parameters
clsa struct GNUNET_PEERSTORE_Handle *h
clsa struct GNUNET_PEERSTORE_Handle *

Definition at line 799 of file peerstore_api.c.

References GNUNET_PEERSTORE_Handle::cfg, GNUNET_CLIENT_connect(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_TIME_UNIT_FOREVER_ABS, h, handle_client_error(), GNUNET_PEERSTORE_Handle::iterate_head, LOG, GNUNET_PEERSTORE_Handle::mq, GNUNET_PEERSTORE_IterateContext::next, GNUNET_FS_SearchContext::options, PEERSTORE_create_record_mq_envelope(), GNUNET_PEERSTORE_Handle::reconnect_task, rewatch_it(), sc, GNUNET_PEERSTORE_Handle::store_head, store_request_sent(), and GNUNET_PEERSTORE_Handle::watches.

Referenced by disconnect_and_schedule_reconnect(), and GNUNET_PEERSTORE_connect().

800 {
801  struct GNUNET_PEERSTORE_Handle *h = cls;
802  struct GNUNET_MQ_MessageHandler mq_handlers[] =
803  { GNUNET_MQ_hd_fixed_size (iterate_end,
805  struct GNUNET_MessageHeader,
806  h),
807  GNUNET_MQ_hd_var_size (iterate_result,
809  struct StoreRecordMessage,
810  h),
811  GNUNET_MQ_hd_var_size (watch_record,
813  struct StoreRecordMessage,
814  h),
816  struct GNUNET_MQ_Envelope *ev;
817 
818  h->reconnect_task = NULL;
819  LOG (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting...\n");
820  h->mq = GNUNET_CLIENT_connect (h->cfg,
821  "peerstore",
822  mq_handlers,
824  h);
825  if (NULL == h->mq)
826  return;
828  "Resending pending requests after reconnect.\n");
829  if (NULL != h->watches)
831  for (struct GNUNET_PEERSTORE_IterateContext *ic = h->iterate_head; NULL != ic;
832  ic = ic->next)
833  {
834  ev =
835  PEERSTORE_create_record_mq_envelope (ic->sub_system,
836  &ic->peer,
837  ic->key,
838  NULL,
839  0,
841  0,
843  GNUNET_MQ_send (h->mq, ev);
844  }
845  for (struct GNUNET_PEERSTORE_StoreContext *sc = h->store_head; NULL != sc;
846  sc = sc->next)
847  {
848  ev =
850  &sc->peer,
851  sc->key,
852  sc->value,
853  sc->size,
854  sc->expiry,
855  sc->options,
858  GNUNET_MQ_send (h->mq, ev);
859  }
860 }
struct GNUNET_PEERSTORE_IterateContext * iterate_head
Head of active ITERATE requests.
Definition: peerstore_api.c:65
#define GNUNET_MESSAGE_TYPE_PEERSTORE_STORE
Store request message.
static void handle_client_error(void *cls, enum GNUNET_MQ_Error error)
Function called when we had trouble talking to the service.
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.
Definition: client.c:1057
enum GNUNET_FS_SearchOptions options
Options for the search.
Definition: fs_api.h:1597
#define LOG(kind,...)
Definition: peerstore_api.c:31
static void store_request_sent(void *cls)
Callback after MQ envelope is sent.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE
Iteration request.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
#define GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD
Watch response.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD
Iteration record message.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: peerstore_api.c:45
struct GNUNET_PEERSTORE_IterateContext * next
Kept in a DLL.
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...
Definition: mq.c:774
static int rewatch_it(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over previous watches to resend them.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
Context for a store request.
Definition: peerstore_api.c:96
Handle to the PEERSTORE service.
Definition: peerstore_api.c:40
Message handler for a specific message type.
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_Handle * mq
Message queue.
Definition: peerstore_api.c:50
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
#define GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END
Iteration end message.
Message carrying a PEERSTORE record message.
Definition: peerstore.h:36
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:353
struct GNUNET_PEERSTORE_StoreContext * store_head
Head of active STORE requests.
Definition: peerstore_api.c:55
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
struct GNUNET_CONTAINER_MultiHashMap * watches
Hashmap of watch requests.
Definition: peerstore_api.c:75
Context for a iterate request.
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the task trying to reconnect to the service.
Definition: peerstore_api.c:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ disconnect()

static void disconnect ( struct GNUNET_PEERSTORE_Handle h)
static

Disconnect from the peerstore service.

Parameters
hpeerstore handle to disconnect

Definition at line 265 of file peerstore_api.c.

References GNUNET_MQ_destroy(), GNUNET_PEERSTORE_iterate_cancel(), GNUNET_YES, GNUNET_PEERSTORE_Handle::iterate_head, GNUNET_PEERSTORE_Handle::mq, and GNUNET_PEERSTORE_IterateContext::next.

Referenced by disconnect_and_schedule_reconnect(), reconnect(), and run().

266 {
268 
269  for (struct GNUNET_PEERSTORE_IterateContext *ic = h->iterate_head; NULL != ic;
270  ic = next)
271  {
272  next = ic->next;
273  if (GNUNET_YES == ic->iterating)
274  {
276  void *icb_cls;
277 
278  icb = ic->callback;
279  icb_cls = ic->callback_cls;
281  if (NULL != icb)
282  icb (icb_cls, NULL, "Iteration canceled due to reconnection");
283  }
284  }
285 
286  if (NULL != h->mq)
287  {
288  GNUNET_MQ_destroy (h->mq);
289  h->mq = NULL;
290  }
291 }
struct GNUNET_PEERSTORE_IterateContext * iterate_head
Head of active ITERATE requests.
Definition: peerstore_api.c:65
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_IterateContext * next
Kept in a DLL.
struct GNUNET_MQ_Handle * mq
Message queue.
Definition: peerstore_api.c:50
void GNUNET_PEERSTORE_iterate_cancel(struct GNUNET_PEERSTORE_IterateContext *ic)
Cancel an iterate request Please do not call after the iterate request is done.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
#define GNUNET_YES
Definition: gnunet_common.h:77
Context for a iterate request.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ disconnect_and_schedule_reconnect()

static void disconnect_and_schedule_reconnect ( struct GNUNET_PEERSTORE_Handle h)
static

Function that will schedule the job that will try to connect us again to the client.

Parameters
hpeerstore to reconnect

Definition at line 301 of file peerstore_api.c.

References disconnect(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_STD_BACKOFF, GNUNET_YES, LOG, reconnect(), GNUNET_PEERSTORE_Handle::reconnect_delay, and GNUNET_PEERSTORE_Handle::reconnect_task.

Referenced by handle_client_error(), handle_iterate_end(), handle_iterate_result(), and handle_watch_record().

302 {
303  GNUNET_assert (NULL == h->reconnect_task);
304  disconnect (h);
306  "Scheduling task to reconnect to PEERSTORE service in %s.\n",
308  h->reconnect_task =
311 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define LOG(kind,...)
Definition: peerstore_api.c:31
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:1253
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:687
static void disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the peerstore service.
static void reconnect(void *cls)
Close the existing connection to PEERSTORE and reconnect.
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_TIME_Relative reconnect_delay
Delay until we try to reconnect.
Definition: peerstore_api.c:85
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the task trying to reconnect to the service.
Definition: peerstore_api.c:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ store_request_sent()

static void store_request_sent ( void *  cls)
static

Callback after MQ envelope is sent.

Parameters
clsa struct GNUNET_PEERSTORE_StoreContext *

Definition at line 320 of file peerstore_api.c.

References GNUNET_PEERSTORE_StoreContext::cont, GNUNET_PEERSTORE_StoreContext::cont_cls, GNUNET_OK, GNUNET_PEERSTORE_store_cancel(), and sc.

Referenced by GNUNET_PEERSTORE_store(), and reconnect().

321 {
322  struct GNUNET_PEERSTORE_StoreContext *sc = cls;
324  void *cont_cls;
325 
326  cont = sc->cont;
327  cont_cls = sc->cont_cls;
329  if (NULL != cont)
330  cont (cont_cls, GNUNET_OK);
331 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Context for a store request.
Definition: peerstore_api.c:96
void * cont_cls
Closure for cont.
void GNUNET_PEERSTORE_store_cancel(struct GNUNET_PEERSTORE_StoreContext *sc)
Cancel a store request.
void(* GNUNET_PEERSTORE_Continuation)(void *cls, int success)
Continuation called with a status result.
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
GNUNET_PEERSTORE_Continuation cont
Continuation called with service response.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_client_error()

static void handle_client_error ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Function called when we had trouble talking to the service.

Definition at line 343 of file peerstore_api.c.

References disconnect_and_schedule_reconnect(), GNUNET_ERROR_TYPE_ERROR, h, and LOG.

Referenced by reconnect().

344 {
345  struct GNUNET_PEERSTORE_Handle *h = cls;
346 
348  "Received an error notification from MQ of type: %d\n",
349  error);
351 }
#define LOG(kind,...)
Definition: peerstore_api.c:31
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
Handle to the PEERSTORE service.
Definition: peerstore_api.c:40
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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rewatch_it()

static int rewatch_it ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Iterator over previous watches to resend them.

Parameters
clsthe struct GNUNET_PEERSTORE_Handle
keykey for the watch
valuethe struct GNUNET_PEERSTORE_WatchContext *
Returns
GNUNET_YES (continue to iterate)

Definition at line 363 of file peerstore_api.c.

References GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_YES, h, StoreKeyHashMessage::keyhash, GNUNET_PEERSTORE_WatchContext::keyhash, GNUNET_PEERSTORE_Handle::mq, and value.

Referenced by reconnect().

364 {
365  struct GNUNET_PEERSTORE_Handle *h = cls;
367  struct StoreKeyHashMessage *hm;
368  struct GNUNET_MQ_Envelope *ev;
369 
371  hm->keyhash = wc->keyhash;
372  GNUNET_MQ_send (h->mq, ev);
373  return GNUNET_YES;
374 }
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
struct GNUNET_HashCode keyhash
Hash of the combined key.
static char * value
Value of the record to add/remove.
struct GNUNET_HashCode keyhash
Hash of a record key.
Definition: peerstore.h:104
Context for a watch request.
Handle to the PEERSTORE service.
Definition: peerstore_api.c:40
#define GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH
Watch request.
struct GNUNET_MQ_Handle * mq
Message queue.
Definition: peerstore_api.c:50
Message carrying record key hash.
Definition: peerstore.h:89
#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:353
Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy_watch()

static int destroy_watch ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Iterator over watch requests to cancel them.

Parameters
clsunsused
keykey to the watch request
valuewatch context
Returns
GNUNET_YES to continue iteration

Definition at line 386 of file peerstore_api.c.

References GNUNET_PEERSTORE_watch_cancel(), GNUNET_YES, and value.

Referenced by GNUNET_PEERSTORE_disconnect().

387 {
389 
391  return GNUNET_YES;
392 }
void GNUNET_PEERSTORE_watch_cancel(struct GNUNET_PEERSTORE_WatchContext *wc)
Cancel a watch request.
static char * value
Value of the record to add/remove.
Context for a watch request.
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ final_disconnect()

static void final_disconnect ( struct GNUNET_PEERSTORE_Handle h)
static

Kill the connection to the service.

This can be delayed in case of pending STORE requests and the user explicitly asked to sync first. Otherwise it is performed instantly.

Parameters
hHandle to the service.

Definition at line 403 of file peerstore_api.c.

References GNUNET_free, GNUNET_MQ_destroy(), and GNUNET_PEERSTORE_Handle::mq.

Referenced by GNUNET_PEERSTORE_disconnect(), and GNUNET_PEERSTORE_store_cancel().

404 {
405  if (NULL != h->mq)
406  {
407  GNUNET_MQ_destroy (h->mq);
408  h->mq = NULL;
409  }
410  GNUNET_free (h);
411 }
struct GNUNET_MQ_Handle * mq
Message queue.
Definition: peerstore_api.c:50
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_iterate_end()

static void handle_iterate_end ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

When a response for iterate request is received.

Parameters
clsa struct GNUNET_PEERSTORE_Handle *
msgmessage received

Definition at line 583 of file peerstore_api.c.

References _, GNUNET_PEERSTORE_IterateContext::callback, GNUNET_PEERSTORE_IterateContext::callback_cls, disconnect_and_schedule_reconnect(), GNUNET_ERROR_TYPE_ERROR, GNUNET_NO, GNUNET_PEERSTORE_iterate_cancel(), GNUNET_TIME_UNIT_ZERO, h, GNUNET_PEERSTORE_Handle::iterate_head, GNUNET_PEERSTORE_IterateContext::iterating, LOG, and GNUNET_PEERSTORE_Handle::reconnect_delay.

584 {
585  struct GNUNET_PEERSTORE_Handle *h = cls;
588  void *callback_cls;
589 
590  ic = h->iterate_head;
591  if (NULL == ic)
592  {
594  _ ("Unexpected iteration response, this should not happen.\n"));
596  return;
597  }
598  callback = ic->callback;
599  callback_cls = ic->callback_cls;
600  ic->iterating = GNUNET_NO;
602  if (NULL != callback)
603  callback (callback_cls, NULL, NULL);
605 }
struct GNUNET_PEERSTORE_IterateContext * iterate_head
Head of active ITERATE requests.
Definition: peerstore_api.c:65
void(* GNUNET_PEERSTORE_Processor)(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
Function called by PEERSTORE for each matching record.
#define LOG(kind,...)
Definition: peerstore_api.c:31
#define GNUNET_NO
Definition: gnunet_common.h:78
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
GNUNET_PEERSTORE_Processor callback
Callback with each matching record.
void * callback_cls
Closure for callback.
Handle to the PEERSTORE service.
Definition: peerstore_api.c:40
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
void GNUNET_PEERSTORE_iterate_cancel(struct GNUNET_PEERSTORE_IterateContext *ic)
Cancel an iterate request Please do not call after the iterate request is done.
int iterating
GNUNET_YES if we are currently processing records.
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.
struct GNUNET_TIME_Relative reconnect_delay
Delay until we try to reconnect.
Definition: peerstore_api.c:85
Context for a iterate request.
Here is the call graph for this function:

◆ check_iterate_result()

static int check_iterate_result ( void *  cls,
const struct StoreRecordMessage msg 
)
static

When a response for iterate request is received, check the message is well-formed.

Parameters
clsa struct GNUNET_PEERSTORE_Handle *
msgmessage received

Definition at line 616 of file peerstore_api.c.

References GNUNET_OK.

617 {
618  /* we defer validation to #handle_iterate_result */
619  return GNUNET_OK;
620 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75

◆ handle_iterate_result()

static void handle_iterate_result ( void *  cls,
const struct StoreRecordMessage msg 
)
static

When a response for iterate request is received.

Parameters
clsa struct GNUNET_PEERSTORE_Handle *
msgmessage received

Definition at line 630 of file peerstore_api.c.

References _, GNUNET_PEERSTORE_IterateContext::callback, GNUNET_PEERSTORE_IterateContext::callback_cls, disconnect_and_schedule_reconnect(), GNUNET_ERROR_TYPE_ERROR, GNUNET_YES, h, GNUNET_PEERSTORE_Handle::iterate_head, GNUNET_PEERSTORE_IterateContext::iterating, LOG, PEERSTORE_destroy_record(), PEERSTORE_parse_record_message(), and record().

631 {
632  struct GNUNET_PEERSTORE_Handle *h = cls;
635  void *callback_cls;
637 
638  ic = h->iterate_head;
639  if (NULL == ic)
640  {
642  _ ("Unexpected iteration response, this should not happen.\n"));
644  return;
645  }
646  ic->iterating = GNUNET_YES;
647  callback = ic->callback;
648  callback_cls = ic->callback_cls;
649  if (NULL == callback)
650  return;
651  record = PEERSTORE_parse_record_message (msg);
652  if (NULL == record)
653  {
654  callback (callback_cls,
655  NULL,
656  _ ("Received a malformed response from service."));
657  }
658  else
659  {
660  callback (callback_cls, record, NULL);
661  PEERSTORE_destroy_record (record);
662  }
663 }
struct GNUNET_PEERSTORE_IterateContext * iterate_head
Head of active ITERATE requests.
Definition: peerstore_api.c:65
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_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 LOG(kind,...)
Definition: peerstore_api.c:31
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
GNUNET_PEERSTORE_Processor callback
Callback with each matching record.
void * callback_cls
Closure for callback.
Handle to the PEERSTORE service.
Definition: peerstore_api.c:40
Single PEERSTORE record.
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
#define GNUNET_YES
Definition: gnunet_common.h:77
int iterating
GNUNET_YES if we are currently processing records.
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.
Context for a iterate request.
Here is the call graph for this function:

◆ check_watch_record()

static int check_watch_record ( void *  cls,
const struct StoreRecordMessage msg 
)
static

When a watch record is received, validate it is well-formed.

Parameters
clsa struct GNUNET_PEERSTORE_Handle *
msgmessage received

Definition at line 747 of file peerstore_api.c.

References GNUNET_OK.

748 {
749  /* we defer validation to #handle_watch_result */
750  return GNUNET_OK;
751 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75

◆ handle_watch_record()

static void handle_watch_record ( void *  cls,
const struct StoreRecordMessage msg 
)
static

When a watch record is received, process it.

Parameters
clsa struct GNUNET_PEERSTORE_Handle *
msgmessage received

Definition at line 761 of file peerstore_api.c.

References _, GNUNET_PEERSTORE_WatchContext::callback, GNUNET_PEERSTORE_WatchContext::callback_cls, disconnect_and_schedule_reconnect(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_TIME_UNIT_ZERO, h, GNUNET_PEERSTORE_Record::key, LOG, GNUNET_PEERSTORE_Record::peer, PEERSTORE_destroy_record(), PEERSTORE_hash_key(), PEERSTORE_parse_record_message(), GNUNET_PEERSTORE_Handle::reconnect_delay, record(), GNUNET_PEERSTORE_Record::sub_system, and GNUNET_PEERSTORE_Handle::watches.

762 {
763  struct GNUNET_PEERSTORE_Handle *h = cls;
765  struct GNUNET_HashCode keyhash;
767 
768  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received a watch record from service.\n");
769  record = PEERSTORE_parse_record_message (msg);
770  if (NULL == record)
771  {
773  return;
774  }
775  PEERSTORE_hash_key (record->sub_system, &record->peer, record->key, &keyhash);
776  // FIXME: what if there are multiple watches for the same key?
778  if (NULL == wc)
779  {
781  _ ("Received a watch result for a non existing watch.\n"));
782  PEERSTORE_destroy_record (record);
784  return;
785  }
786  if (NULL != wc->callback)
787  wc->callback (wc->callback_cls, record, NULL);
789  PEERSTORE_destroy_record (record);
790 }
GNUNET_PEERSTORE_Processor callback
Callback with each record received.
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.
void * callback_cls
Closure for callback.
#define LOG(kind,...)
Definition: peerstore_api.c:31
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
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.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
char * key
Record key string.
struct GNUNET_HashCode keyhash
Hash of the combined key.
Context for a watch request.
Handle to the PEERSTORE service.
Definition: peerstore_api.c:40
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.
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
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.
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.
struct GNUNET_TIME_Relative reconnect_delay
Delay until we try to reconnect.
Definition: peerstore_api.c:85
struct GNUNET_CONTAINER_MultiHashMap * watches
Hashmap of watch requests.
Definition: peerstore_api.c:75
Here is the call graph for this function: