GNUnet 0.21.1
peerstore_api.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2013-2016, 2019 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
26#include "gnunet_time_lib.h"
27#include "platform.h"
28#include "gnunet_common.h"
29#include "gnunet_protocols.h"
30#include "gnunet_util_lib.h"
32#include "peerstore.h"
33#include "peerstore_common.h"
35
36#define LOG(kind, ...) GNUNET_log_from (kind, "peerstore-api", __VA_ARGS__)
37
38/******************************************************************************/
39/************************ DATA STRUCTURES ****************************/
40/******************************************************************************/
41
46{
51
56
61
66
71
76
81
86
91
95 uint32_t last_op_id;
96
97};
98
103{
108
113
117 void *cont_cls;
118
123
128
133
138};
139
144{
149
154
159
164
168 uint32_t rid;
169
173 void *cont_cls;
174
179
183 char *key;
184
188 void *value;
189
194
198 size_t size;
199
204
209
214};
215
220{
225
230};
231
236{
241
246
251
256
261
265 char *key;
266
271
276
280 uint32_t rid;
281
286};
287
288
293{
298
303
308
313
317 unsigned int canceled;
318
322 uint32_t rid;
323
324};
325
326/******************************************************************************/
327/******************* DECLARATIONS *********************/
328/******************************************************************************/
329
335static void
336reconnect (void *cls);
337
344static uint32_t
346{
347 return h->last_op_id++;
348}
349
350
356static void
358{
359 if (NULL != h->watches)
360 {
363 }
364 GNUNET_assert (NULL == h->iterate_head);
365 GNUNET_assert (NULL == h->store_head);
366 if (NULL != h->mq)
367 {
369 h->mq = NULL;
370 }
371}
372
373
380static void
382{
383 GNUNET_assert (NULL == h->reconnect_task);
384 disconnect (h);
386 "Scheduling task to reconnect to PEERSTORE service in %s.\n",
389 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
390 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
391}
392
393
394/******************************************************************************/
395/******************* CONNECTION FUNCTIONS *********************/
396/******************************************************************************/
397
398
402static void
404{
405 struct GNUNET_PEERSTORE_Handle *h = cls;
406
408 "Received an error notification from MQ of type: %d\n",
409 error);
411}
412
413
422{
424
426 h->cfg = cfg;
427 reconnect (h);
428 if (NULL == h->mq)
429 {
430 GNUNET_free (h);
431 return NULL;
432 }
433 return h;
434}
435
436
444void
446{
447 LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnect initiated from client.\n");
448 disconnect (h);
449}
450
451
452/******************************************************************************/
453/******************* STORE FUNCTIONS *********************/
454/******************************************************************************/
455
456
462void
464{
466 "store cancel with sc %p \n",
467 sc);
468 GNUNET_CONTAINER_DLL_remove (sc->h->store_head, sc->h->store_tail, sc);
469 GNUNET_free (sc->sub_system);
470 GNUNET_free (sc->value);
471 GNUNET_free (sc->key);
472 GNUNET_free (sc);
474 "store cancel with sc %p is null\n",
475 sc);
476}
477
478
497 const char *sub_system,
498 const struct GNUNET_PeerIdentity *peer,
499 const char *key,
500 const void *value,
501 size_t size,
505 void *cont_cls)
506{
507 struct GNUNET_MQ_Envelope *ev;
509
511 "Storing value (size: %llu) for subsystem `%s', peer `%s', key `%s'\n",
512 (unsigned long long) size,
515 key);
517 sc->rid = get_op_id (h);
518 sc->sub_system = GNUNET_strdup (sub_system);
519 GNUNET_assert (NULL != peer);
520 sc->peer = *peer;
521 sc->key = GNUNET_strdup (key);
522 sc->value = GNUNET_memdup (value, size);
523 sc->size = size;
524 sc->expiry = expiry;
525 sc->options = options;
526 sc->cont = cont;
527 sc->cont_cls = cont_cls;
528 sc->h = h;
529 ev =
532 peer,
533 key,
534 value,
535 size,
536 expiry,
537 options,
539
540 GNUNET_CONTAINER_DLL_insert_tail (h->store_head, h->store_tail, sc);
541 if (NULL == h->mq)
542 {
543 sc->env = ev;
544 }
545 else
546 {
547 GNUNET_MQ_send (h->mq, ev);
548 }
549 return sc;
550}
551
552
559static void
561{
562 struct GNUNET_PEERSTORE_Handle *h = cls;
563 struct GNUNET_PEERSTORE_StoreContext *sc = h->store_head;
564
565 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got PeerstoreResultMessage\n");
566 for (sc = h->store_head; NULL != sc; sc = sc->next)
567 {
568 if (sc->rid == ntohs (msg->rid))
569 break;
570 }
571 if (NULL == sc)
572 {
574 _ ("Unexpected store response.\n"));
575 return;
576 }
577 if (NULL != sc->cont)
578 sc->cont (sc->cont_cls, ntohl (msg->result));
579 GNUNET_CONTAINER_DLL_remove (h->store_head, h->store_tail, sc);
580}
581
582
583/******************************************************************************/
584/******************* ITERATE FUNCTIONS *********************/
585/******************************************************************************/
586
587
594static void
596{
597 struct GNUNET_PEERSTORE_Handle *h = cls;
598 struct GNUNET_PEERSTORE_IterateContext *ic = h->iterate_head;
599
600 for (ic = h->iterate_head; NULL != ic; ic = ic->next)
601 if (ic->rid == ntohs (msg->rid))
602 break;
603 if (NULL == ic)
604 {
606 _ ("Unexpected iteration response.\n"));
607 return;
608 }
609 if (NULL != ic->callback)
610 ic->callback (ic->callback_cls, NULL, NULL);
611 LOG (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up iteration with rid %u\n", ic->rid);
612 GNUNET_CONTAINER_DLL_remove (h->iterate_head, h->iterate_tail, ic);
613}
614
615
623static int
625{
626 /* we defer validation to #handle_iterate_result */
627 return GNUNET_OK;
628}
629
630
637static void
639{
640 struct GNUNET_PEERSTORE_Handle *h = cls;
643
644 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RecordMessage\n");
645 for (ic = h->iterate_head; NULL != ic; ic = ic->next)
646 if (ic->rid == ntohs (msg->rid))
647 break;
648 if (NULL == ic)
649 {
651 _ (
652 "Unexpected iteration response, no iterating client found, discarding message.\n"));
653 return;
654 }
655 if (NULL == ic->callback)
656 return;
658 if (NULL == record)
659 {
660 ic->callback (ic->callback_cls,
661 NULL,
662 _ ("Received a malformed response from service."));
663 }
664 else
665 {
666 ic->callback (ic->callback_cls, record, NULL);
668 }
669}
670
671
678void
680 uint64_t limit)
681{
682 struct GNUNET_MQ_Envelope *ev;
684
686 "Sending PEERSTORE_ITERATION_NEXT message\n");
688 inm->rid = htons (ic->rid);
689 inm->limit = GNUNET_htonll (limit);
690 if (NULL == ic->h->mq)
691 {
692 ic->env = ev;
693 }
694 else
695 {
696 GNUNET_MQ_send (ic->h->mq, ev);
697 }
698}
699
700
707void
709{
710 struct GNUNET_MQ_Envelope *ev;
712
714 "Sending PEERSTORE_ITERATION_STOP message\n");
715 if (NULL != ic->h->mq)
716 {
718 ism->rid = htons (ic->rid);
719 if (NULL != ic->h->mq)
720 GNUNET_MQ_send (ic->h->mq, ev);
721 }
724 GNUNET_free (ic->key);
725 GNUNET_free (ic);
726}
727
728
731 const char *sub_system,
732 const struct GNUNET_PeerIdentity *peer,
733 const char *key,
735 void *callback_cls)
736{
737 struct GNUNET_MQ_Envelope *ev;
740 size_t ss_size;
741 size_t key_size;
742 size_t msg_size;
743 void *dummy;
744
746 ic->rid = get_op_id (h);
747
748 GNUNET_assert (NULL != sub_system);
749 ss_size = strlen (sub_system) + 1;
750 if (NULL == key)
751 key_size = 0;
752 else
753 key_size = strlen (key) + 1;
754 msg_size = ss_size + key_size;
755 ev = GNUNET_MQ_msg_extra (srm, msg_size,
757 srm->key_size = htons (key_size);
758 srm->rid = htons (ic->rid);
759 srm->sub_system_size = htons (ss_size);
760 dummy = &srm[1];
761 GNUNET_memcpy (dummy, sub_system, ss_size);
762 dummy += ss_size;
763 GNUNET_memcpy (dummy, key, key_size);
764 ic->callback = callback;
766 ic->h = h;
768 if (NULL != peer)
769 {
770 ic->peer = *peer;
771 srm->peer_set = htons (GNUNET_YES);
772 srm->peer = *peer;
773 }
774 if (NULL != key)
775 ic->key = GNUNET_strdup (key);
776 GNUNET_CONTAINER_DLL_insert_tail (h->iterate_head, h->iterate_tail, ic);
778 "Sending an iterate request for sub system `%s'\n",
779 sub_system);
780 GNUNET_MQ_send (h->mq, ev);
781 return ic;
782}
783
784
790static void
791reconnect (void *cls)
792{
793 struct GNUNET_PEERSTORE_Handle *h = cls;
794 struct GNUNET_MQ_MessageHandler mq_handlers[] = {
795 GNUNET_MQ_hd_fixed_size (iterate_end,
798 h),
799 GNUNET_MQ_hd_fixed_size (store_result,
802 h),
803 GNUNET_MQ_hd_var_size (iterate_result,
806 h),
808 };
809
810 h->reconnect_task = NULL;
811 LOG (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting...\n");
813 "peerstore",
814 mq_handlers,
816 h);
817 if (NULL == h->mq)
818 {
820 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
821 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
822 return;
823 }
825 "Resending pending requests after reconnect.\n");
826 for (struct GNUNET_PEERSTORE_IterateContext *ic = h->iterate_head; NULL != ic;
827 ic = ic->next)
828 {
829 GNUNET_MQ_send (h->mq, ic->env);
830 }
831 for (struct GNUNET_PEERSTORE_StoreContext *sc = h->store_head; NULL != sc;
832 sc = sc->next)
833 {
834 GNUNET_MQ_send (h->mq, sc->env);
835 }
836}
837
838
839static void
840hello_store_success (void *cls, int success)
841{
842 struct GNUNET_PEERSTORE_StoreHelloContext *huc = cls;
843
844 huc->sc = NULL;
845 if (GNUNET_OK != success)
846 {
848 "Storing hello uri failed\n");
849 huc->cont (huc->cont_cls, success);
850 GNUNET_free (huc->hello);
851 GNUNET_free (huc);
852 return;
853 }
854 huc->cont (huc->cont_cls, GNUNET_OK);
855 GNUNET_free (huc->hello);
856 GNUNET_free (huc);
857}
858
859
860static void
862 const char *emsg)
863{
864 struct GNUNET_PEERSTORE_StoreHelloContext *huc = cls;
865 struct GNUNET_TIME_Absolute hello_exp =
867 if ((NULL == record) && (NULL == emsg))
868 {
872 huc->sc = GNUNET_PEERSTORE_store (huc->h,
873 "peerstore",
874 &huc->pid,
876 huc->hello,
877 ntohs (huc->hello->size),
878 hello_exp,
881 huc);
882 return;
883 }
884 if (NULL != emsg)
885 {
886 LOG (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg);
888 return;
889 }
890 if (GNUNET_TIME_absolute_cmp (record->expiry, >, hello_exp))
891 {
893 "Not storing hello for %s since we seem to have a newer version on record.\n",
894 GNUNET_i2s (&huc->pid));
895 huc->cont (huc->cont_cls, GNUNET_OK);
897 GNUNET_free (huc->hello);
898 GNUNET_free (huc);
899 return;
900 }
902}
903
904
907 const struct GNUNET_MessageHeader *msg,
909 void *cont_cls)
910{
913 const struct GNUNET_PeerIdentity *pid;
915 struct GNUNET_TIME_Absolute hello_exp =
917 struct GNUNET_TIME_Absolute huc_exp;
918 uint16_t size_msg = ntohs (msg->size);
919
920 if (NULL == builder)
921 return NULL;
922 if (GNUNET_TIME_absolute_cmp (hello_exp, <, now))
923 return NULL;
924
926 huc->h = h;
927 huc->cont = cont;
928 huc->cont_cls = cont_cls;
929 huc->hello = GNUNET_malloc (size_msg);
930 GNUNET_memcpy (huc->hello, msg, size_msg);
931 huc_exp =
934 huc->pid = *pid;
936 "Adding hello for peer %s with expiration %s msg size %u\n",
937 GNUNET_i2s (&huc->pid),
939 size_msg);
940
941 huc->ic = GNUNET_PEERSTORE_iteration_start (h, "peerstore", &huc->pid,
944 huc);
946 return huc;
947}
948
949
950void
953{
954 if (NULL != huc->sc)
956 if (NULL != huc->ic)
958 GNUNET_free (huc->hello);
959 GNUNET_free (huc);
960}
961
962
963/* end of peerstore_api.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
static struct HostSet * builder
NULL if we are not currently iterating over peer information.
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
Definition: gnunet-search.c:87
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
Helper library for handling HELLO URIs.
API to the peerstore service.
Constants for network protocols.
Functions related to time.
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
#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_builder_free(struct GNUNET_HELLO_Builder *builder)
Release resources of a builder.
Definition: hello-uri.c:373
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_from_msg(const struct GNUNET_MessageHeader *msg)
Parse msg into builder.
Definition: hello-uri.c:391
const struct GNUNET_PeerIdentity * GNUNET_HELLO_builder_get_id(const struct GNUNET_HELLO_Builder *builder)
Get the PeerIdentity for this builder.
Definition: hello-uri.c:366
struct GNUNET_TIME_Absolute GNUNET_HELLO_builder_get_expiration_time(const struct GNUNET_MessageHeader *msg)
Get the expiration time for this HELLO.
Definition: hello-uri.c:470
#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.
Definition: common_endian.c:37
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
@ GNUNET_YES
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.
Definition: mq.c:304
#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.
Definition: gnunet_mq_lib.h:63
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:78
#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.
Definition: mq.c:683
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.
Definition: scheduler.c:1278
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:570
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
#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.
Definition: strings.c:617
#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".
Definition: peer.c:68
IPC messages.
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.
#define LOG(kind,...)
Definition: peerstore_api.c:36
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.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
Definition: arm_api.c:107
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Definition: arm_api.c:112
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the reconnect task (if any).
Definition: arm_api.c:147
Internal representation of the hash map.
enum GNUNET_FS_SearchOptions options
Options for the search.
Definition: fs_api.h:1598
struct GNUNET_FS_Handle * h
Handle to the global FS context.
Definition: fs_api.h:1515
Context for building (or parsing) HELLO URIs.
Definition: hello-uri.c:205
Handle to a message queue.
Definition: mq.c:87
Message handler for a specific message type.
Header for all communications.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
Handle to the PEERSTORE service.
Definition: peerstore_api.c:46
struct GNUNET_PEERSTORE_IterateContext * iterate_tail
Tail of active ITERATE requests.
Definition: peerstore_api.c:75
struct GNUNET_MQ_Handle * mq
Message queue.
Definition: peerstore_api.c:55
struct GNUNET_TIME_Relative reconnect_delay
Delay until we try to reconnect.
Definition: peerstore_api.c:90
struct GNUNET_PEERSTORE_StoreContext * store_tail
Tail of active STORE requests.
Definition: peerstore_api.c:65
struct GNUNET_PEERSTORE_StoreContext * store_head
Head of active STORE requests.
Definition: peerstore_api.c:60
struct GNUNET_PEERSTORE_IterateContext * iterate_head
Head of active ITERATE requests.
Definition: peerstore_api.c:70
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: peerstore_api.c:50
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the task trying to reconnect to the service.
Definition: peerstore_api.c:85
struct GNUNET_CONTAINER_MultiHashMap * watches
Hashmap of watch requests.
Definition: peerstore_api.c:80
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 a monitor.
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.
Single PEERSTORE record.
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.
Definition: scheduler.c:136
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
Iteration next message.
Definition: peerstore.h:248
uint32_t rid
Request id.
Definition: peerstore.h:262
uint64_t limit
Number of records to return.
Definition: peerstore.h:257
Iteration start message.
Definition: peerstore.h:202
uint16_t peer_set
GNUNET_YES if peer id value set, GNUNET_NO otherwise
Definition: peerstore.h:221
struct GNUNET_PeerIdentity peer
Peer Identity.
Definition: peerstore.h:211
uint32_t rid
Request id.
Definition: peerstore.h:216
uint16_t sub_system_size
Size of the sub_system string Allocated at position 0 after this struct.
Definition: peerstore.h:227
uint16_t key_size
Size of the key string Allocated at position 1 after this struct.
Definition: peerstore.h:238
uint32_t rid
Request id.
Definition: peerstore.h:275
Message carrying a PEERSTORE record message.
Definition: peerstore.h:38
Message carrying a PEERSTORE result message.
Definition: peerstore.h:96
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.