GNUnet 0.21.1
namestore_api.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2010-2013, 2016 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 */
20
29#include "gnunet_protocols.h"
30#include "gnunet_error_codes.h"
31#include "gnunet_util_lib.h"
33#include "namestore.h"
34
35
36#define LOG(kind, ...) GNUNET_log_from (kind, "namestore-api", __VA_ARGS__)
37
42#define NAMESTORE_DELAY_TOLERANCE GNUNET_TIME_UNIT_MINUTES
43
49{
54
59
64
69
73 void *cont_cls;
74
79
84
89
93 void *proc_cls;
94
99
104
110
115
119 uint32_t op_id;
120};
121
122
127{
132
137
142
147
152
157
162
166 void *proc_cls;
167
172
177
183
188
192 uint32_t op_id;
193};
194
195
200{
205
210
215
220
225
230
235
240
245
250};
251
252
258static void
260
261
269static struct GNUNET_NAMESTORE_QueueEntry *
270find_qe (struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
271{
273
274 for (qe = h->op_head; qe != NULL; qe = qe->next)
275 if (qe->op_id == rid)
276 return qe;
277 return NULL;
278}
279
280
288static struct GNUNET_NAMESTORE_ZoneIterator *
289find_zi (struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
290{
292
293 for (ze = h->z_head; ze != NULL; ze = ze->next)
294 if (ze->op_id == rid)
295 return ze;
296 return NULL;
297}
298
299
305static void
307{
308 struct GNUNET_NAMESTORE_Handle *h = qe->h;
309
310 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, qe);
311 if (NULL != qe->env)
313 if (NULL != qe->timeout_task)
314 GNUNET_SCHEDULER_cancel (qe->timeout_task);
315 GNUNET_free (qe);
316}
317
318
324static void
326{
327 struct GNUNET_NAMESTORE_Handle *h = ze->h;
328
329 GNUNET_CONTAINER_DLL_remove (h->z_head, h->z_tail, ze);
330 if (NULL != ze->env)
332 GNUNET_free (ze);
333}
334
335
345static int
346check_rd (size_t rd_len, const void *rd_buf, unsigned int rd_count)
347{
349
350 if (GNUNET_OK !=
352 {
353 GNUNET_break (0);
354 return GNUNET_SYSERR;
355 }
356 return GNUNET_OK;
357}
358
359
367static void
369 const struct NamestoreResponseMessage *msg)
370{
371 struct GNUNET_NAMESTORE_Handle *h = cls;
374
375 qe = find_qe (h, ntohl (msg->gns_header.r_id));
376 res = ntohl (msg->ec);
378 "Received GENERIC_RESPONSE with result %s\n",
380 if (NULL == qe)
381 return;
382 if (NULL != qe->cont)
383 qe->cont (qe->cont_cls, res);
384 free_qe (qe);
385}
386
387
396static int
398{
399 const char *name;
400 size_t exp_msg_len;
401 size_t msg_len;
402 size_t name_len;
403 size_t rd_len;
404 size_t key_len;
405
406 (void) cls;
407 rd_len = ntohs (msg->rd_len);
408 msg_len = ntohs (msg->gns_header.header.size);
409 name_len = ntohs (msg->name_len);
410 key_len = ntohs (msg->key_len);
411 exp_msg_len = sizeof(*msg) + name_len + rd_len + key_len;
412 if (0 != ntohs (msg->reserved))
413 {
414 GNUNET_break (0);
415 return GNUNET_SYSERR;
416 }
417 if (msg_len != exp_msg_len)
418 {
419 GNUNET_break (0);
420 return GNUNET_SYSERR;
421 }
422 name = (const char *) &msg[1] + key_len;
423 if ((name_len > 0) && ('\0' != name[name_len - 1]))
424 {
425 GNUNET_break (0);
426 return GNUNET_SYSERR;
427 }
428 if (GNUNET_NO == ntohs (msg->found))
429 {
430 if (0 != ntohs (msg->rd_count))
431 {
432 GNUNET_break (0);
433 return GNUNET_SYSERR;
434 }
435 return GNUNET_OK;
436 }
437 return check_rd (rd_len, &name[name_len], ntohs (msg->rd_count));
438}
439
440
448static void
450{
451 struct GNUNET_NAMESTORE_Handle *h = cls;
453 struct GNUNET_CRYPTO_PrivateKey private_key;
454 const char *name;
455 const char *rd_tmp;
456 size_t name_len;
457 size_t rd_len;
458 size_t key_len;
459 size_t kbytes_read;
460 unsigned int rd_count;
461 int16_t found = (int16_t) ntohs (msg->found);
462
463 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_LOOKUP_RESULT (found=%i)\n",
464 found);
465 qe = find_qe (h, ntohl (msg->gns_header.r_id));
466 if (NULL == qe)
467 return;
468 rd_len = ntohs (msg->rd_len);
469 rd_count = ntohs (msg->rd_count);
470 name_len = ntohs (msg->name_len);
471 key_len = ntohs (msg->key_len);
474 key_len,
475 &private_key,
476 &kbytes_read));
477 GNUNET_assert (kbytes_read == key_len);
478 name = (const char *) &msg[1] + key_len;
479 if (GNUNET_NO == found)
480 {
481 /* label was not in namestore */
482 if (NULL != qe->proc)
483 qe->proc (qe->proc_cls, &private_key, name, 0, NULL);
484 free_qe (qe);
485 return;
486 }
487 if (GNUNET_SYSERR == found)
488 {
489 if (NULL != qe->error_cb)
490 qe->error_cb (qe->error_cb_cls);
491 free_qe (qe);
492 return;
493 }
494
495 rd_tmp = &name[name_len];
496 {
498
500 GNUNET_OK ==
502 if (0 == name_len)
503 name = NULL;
504 if (NULL != qe->proc)
505 qe->proc (qe->proc_cls,
506 &private_key,
507 name,
508 rd_count,
509 (rd_count > 0) ? rd : NULL);
510 }
511 free_qe (qe);
512}
513
514
523static int
524check_edit_record_set_response (void *cls, const struct
526{
527 const char *editor_hint;
528 size_t msg_len;
529 size_t editor_hint_len;
530 size_t rd_len;
531
532 (void) cls;
533 rd_len = ntohs (msg->rd_len);
534 msg_len = ntohs (msg->gns_header.header.size);
535 editor_hint_len = ntohs (msg->editor_hint_len);
536 if (msg_len != sizeof(struct EditRecordSetResponseMessage) + editor_hint_len
537 + rd_len)
538 {
539 GNUNET_break (0);
540 return GNUNET_SYSERR;
541 }
542 editor_hint = (const char *) &msg[1];
543 if ((0 == editor_hint_len) || ('\0' != editor_hint[editor_hint_len - 1]))
544 {
545 GNUNET_break (0);
546 return GNUNET_SYSERR;
547 }
548 return check_rd (rd_len, &editor_hint[editor_hint_len], ntohs (
549 msg->rd_count));
550}
551
552
560static void
561handle_edit_record_set_response (void *cls, const struct
563{
564 struct GNUNET_NAMESTORE_Handle *h = cls;
566 const char *editor_hint;
567 const char *rd_tmp;
568 size_t rd_len;
569 size_t editor_hint_len;
570 unsigned int rd_count;
571
572 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received EDIT_RECORD_SET_RESPONSE\n");
573 rd_len = ntohs (msg->rd_len);
574 rd_count = ntohs (msg->rd_count);
575 editor_hint_len = ntohs (msg->editor_hint_len);
576 qe = find_qe (h, ntohl (msg->gns_header.r_id));
577 if (NULL == qe)
578 return; /* rid not found */
579 editor_hint = (const char *) &msg[1];
580 rd_tmp = &editor_hint[editor_hint_len];
581 {
583
585 GNUNET_OK ==
587 if (0 == editor_hint_len)
588 editor_hint = NULL;
589 if (NULL != qe->edit_proc)
590 qe->edit_proc (qe->proc_cls,
591 ntohs (msg->ec),
592 rd_count,
593 (rd_count > 0) ? rd : NULL,
594 editor_hint);
595 free_qe (qe);
596 return;
597 }
598 GNUNET_assert (0);
599}
600
601
610static int
612{
613 const char *name;
614 size_t msg_len;
615 size_t name_len;
616 size_t rd_len;
617 size_t key_len;
618
619 (void) cls;
620 rd_len = ntohs (msg->rd_len);
621 msg_len = ntohs (msg->gns_header.header.size);
622 key_len = ntohs (msg->key_len);
623 name_len = ntohs (msg->name_len);
624 if (msg_len != sizeof(struct RecordResultMessage) + key_len + name_len
625 + rd_len)
626 {
627 GNUNET_break (0);
628 return GNUNET_SYSERR;
629 }
630 name = (const char *) &msg[1] + key_len;
631 if ((0 == name_len) || ('\0' != name[name_len - 1]))
632 {
633 GNUNET_break (0);
634 return GNUNET_SYSERR;
635 }
636 if (0 == key_len)
637 {
638 GNUNET_break (0);
639 return GNUNET_SYSERR;
640 }
641 return check_rd (rd_len, &name[name_len], ntohs (msg->rd_count));
642}
643
644
652static void
654{
655 struct GNUNET_NAMESTORE_Handle *h = cls;
658 struct GNUNET_CRYPTO_PrivateKey private_key;
659 const char *name;
660 const char *rd_tmp;
661 size_t name_len;
662 size_t rd_len;
663 size_t key_len;
664 size_t kbytes_read;
665 unsigned int rd_count;
666
667 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT\n");
668 rd_len = ntohs (msg->rd_len);
669 rd_count = ntohs (msg->rd_count);
670 name_len = ntohs (msg->name_len);
671 key_len = ntohs (msg->key_len);
672 ze = find_zi (h, ntohl (msg->gns_header.r_id));
673 qe = find_qe (h, ntohl (msg->gns_header.r_id));
674 if ((NULL == ze) && (NULL == qe))
675 return; /* rid not found */
676 if ((NULL != ze) && (NULL != qe))
677 {
678 GNUNET_break (0); /* rid ambiguous */
680 return;
681 }
682 name = (const char *) &msg[1] + key_len;
685 key_len,
686 &private_key,
687 &kbytes_read));
688 GNUNET_assert (kbytes_read == key_len);
689 rd_tmp = &name[name_len];
690 {
692
694 GNUNET_OK ==
696 if (0 == name_len)
697 name = NULL;
698 if (NULL != qe)
699 {
700 if (NULL != qe->proc)
701 qe->proc (qe->proc_cls,
702 &private_key,
703 name,
704 rd_count,
705 (rd_count > 0) ? rd : NULL);
706 free_qe (qe);
707 return;
708 }
709 if (NULL != ze)
710 {
711 // Store them here because a callback could free ze
714 void *proc_cls = ze->proc_cls;
715 proc = ze->proc;
716 proc2 = ze->proc2;
717 if (NULL != proc)
718 proc (proc_cls, &private_key, name, rd_count, rd);
719 if (NULL != proc2)
720 proc2 (proc_cls, &private_key, name,
722 return;
723 }
724 }
725 GNUNET_assert (0);
726}
727
728
736static void
738{
739 struct GNUNET_NAMESTORE_Handle *h = cls;
742
743 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT_END\n");
744 ze = find_zi (h, ntohl (msg->r_id));
745 qe = find_qe (h, ntohl (msg->r_id));
746 if ((NULL == ze) && (NULL == qe))
747 return; /* rid not found */
748 if ((NULL != ze) && (NULL != qe))
749 {
750 GNUNET_break (0); /* rid ambiguous */
752 return;
753 }
754 LOG (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration completed!\n");
755 if (NULL == ze)
756 {
757 GNUNET_break (0);
759 return;
760 }
761 if (NULL != ze->finish_cb)
762 ze->finish_cb (ze->finish_cb_cls);
763 free_ze (ze);
764}
765
766
775static int
777 const struct ZoneToNameResponseMessage *msg)
778{
779 size_t name_len;
780 size_t rd_ser_len;
781 size_t key_len;
782 const char *name_tmp;
783
784 (void) cls;
785 if (GNUNET_EC_NONE != ntohl (msg->ec))
786 return GNUNET_OK;
787 key_len = ntohs (msg->key_len);
788 name_len = ntohs (msg->name_len);
789 rd_ser_len = ntohs (msg->rd_len);
790 if (ntohs (msg->gns_header.header.size) !=
791 sizeof(struct ZoneToNameResponseMessage) + key_len + name_len
792 + rd_ser_len)
793 {
794 GNUNET_break (0);
795 return GNUNET_SYSERR;
796 }
797 name_tmp = (const char *) &msg[1] + key_len;
798 if ((name_len > 0) && ('\0' != name_tmp[name_len - 1]))
799 {
800 GNUNET_break (0);
801 return GNUNET_SYSERR;
802 }
803 return check_rd (rd_ser_len, &name_tmp[name_len], ntohs (msg->rd_count));
804}
805
806
814static void
816 const struct ZoneToNameResponseMessage *msg)
817{
818 struct GNUNET_NAMESTORE_Handle *h = cls;
820 struct GNUNET_CRYPTO_PrivateKey zone;
822 size_t name_len;
823 size_t rd_ser_len;
824 unsigned int rd_count;
825 const char *name_tmp;
826 const char *rd_tmp;
827 size_t key_len;
828 size_t kbytes_read;
829
830 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME_RESPONSE\n");
831 qe = find_qe (h, ntohl (msg->gns_header.r_id));
832 if (NULL == qe)
833 {
835 "Response queue already gone...\n");
836 return;
837 }
838 res = ntohl (msg->ec);
839 key_len = ntohs (msg->key_len);
842 key_len,
843 &zone,
844 &kbytes_read));
845 GNUNET_assert (kbytes_read == key_len);
846 switch (res)
847 {
848 break;
849
852 "Namestore has no result for zone to name mapping \n");
853 if (NULL != qe->proc)
854 qe->proc (qe->proc_cls, &zone, NULL, 0, NULL);
855 free_qe (qe);
856 return;
857
858 case GNUNET_EC_NONE:
860 "Namestore has result for zone to name mapping \n");
861 name_len = ntohs (msg->name_len);
862 rd_count = ntohs (msg->rd_count);
863 rd_ser_len = ntohs (msg->rd_len);
864 name_tmp = (const char *) &msg[1] + key_len;
865 rd_tmp = &name_tmp[name_len];
866 {
868
871 rd_tmp,
872 rd_count,
873 rd));
874 /* normal end, call continuation with result */
875 if (NULL != qe->proc)
876 qe->proc (qe->proc_cls, &zone, name_tmp, rd_count, rd);
877 /* return is important here: break would call continuation with error! */
878 free_qe (qe);
879 return;
880 }
881
882 default:
884 "An error occurred during zone to name operation: %s\n",
886 break;
887 }
888 /* error case, call continuation with error */
889 if (NULL != qe->error_cb)
890 qe->error_cb (qe->error_cb_cls);
891 free_qe (qe);
892}
893
894
903static void
904mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
905{
906 struct GNUNET_NAMESTORE_Handle *h = cls;
907
908 (void) error;
910}
911
912
918static void
920{
922 { GNUNET_MQ_hd_fixed_size (generic_response,
925 h),
926 GNUNET_MQ_hd_var_size (zone_to_name_response,
929 h),
930 GNUNET_MQ_hd_var_size (record_result,
932 struct RecordResultMessage,
933 h),
934 GNUNET_MQ_hd_fixed_size (record_result_end,
937 h),
938 GNUNET_MQ_hd_var_size (lookup_result,
941 h),
942 GNUNET_MQ_hd_var_size (edit_record_set_response,
945 h),
949
950 GNUNET_assert (NULL == h->mq);
951 h->mq =
953 if (NULL == h->mq)
954 return;
955 /* re-transmit pending requests that waited for a reconnect... */
956 for (it = h->z_head; NULL != it; it = it->next)
957 {
958 GNUNET_MQ_send (h->mq, it->env);
959 it->env = NULL;
960 }
961 for (qe = h->op_head; NULL != qe; qe = qe->next)
962 {
963 GNUNET_MQ_send (h->mq, qe->env);
964 qe->env = NULL;
965 }
966}
967
968
974static void
975reconnect_task (void *cls)
976{
977 struct GNUNET_NAMESTORE_Handle *h = cls;
978
979 h->reconnect_task = NULL;
980 reconnect (h);
981}
982
983
989static void
991{
994
996 h->mq = NULL;
997 while (NULL != (ze = h->z_head))
998 {
999 if (NULL != ze->error_cb)
1000 ze->error_cb (ze->error_cb_cls);
1001 free_ze (ze);
1002 }
1003 while (NULL != (qe = h->op_head))
1004 {
1005 if (NULL != qe->error_cb)
1006 qe->error_cb (qe->error_cb_cls);
1007 if (NULL != qe->cont)
1008 qe->cont (qe->cont_cls,
1010 free_qe (qe);
1011 }
1012
1013 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting to namestore\n");
1014 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
1015 h->reconnect_task =
1016 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect_task, h);
1017}
1018
1019
1026static uint32_t
1028{
1029 return h->last_op_id_used++;
1030}
1031
1032
1041{
1042 struct GNUNET_NAMESTORE_Handle *h;
1043
1045 h->cfg = cfg;
1046 reconnect (h);
1047 if (NULL == h->mq)
1048 {
1049 GNUNET_free (h);
1050 return NULL;
1051 }
1052 return h;
1053}
1054
1055
1062void
1064{
1067
1068 LOG (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
1069 GNUNET_break (NULL == h->op_head);
1070 while (NULL != (q = h->op_head))
1071 {
1072 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, q);
1073 GNUNET_free (q);
1074 }
1075 GNUNET_break (NULL == h->z_head);
1076 while (NULL != (z = h->z_head))
1077 {
1078 GNUNET_CONTAINER_DLL_remove (h->z_head, h->z_tail, z);
1079 GNUNET_free (z);
1080 }
1081 if (NULL != h->mq)
1082 {
1084 h->mq = NULL;
1085 }
1086 if (NULL != h->reconnect_task)
1087 {
1089 h->reconnect_task = NULL;
1090 }
1091 GNUNET_free (h);
1092}
1093
1094
1101static void
1102warn_delay (void *cls)
1103{
1104 struct GNUNET_NAMESTORE_QueueEntry *qe = cls;
1105
1106 qe->timeout_task = NULL;
1108 "Did not receive response from namestore after %s!\n",
1110 GNUNET_YES));
1111 if (NULL != qe->cont)
1112 {
1114 qe->cont = NULL;
1115 }
1117}
1118
1119
1122 struct GNUNET_NAMESTORE_Handle *h,
1123 const struct GNUNET_CRYPTO_PrivateKey *pkey,
1124 const char *label,
1125 unsigned int rd_count,
1126 const struct GNUNET_GNSRECORD_Data *rd,
1128 void *cont_cls)
1129{
1131 unsigned int rds_sent;
1132 ri.a_label = label;
1133 ri.a_rd_count = rd_count;
1134 ri.a_rd = (struct GNUNET_GNSRECORD_Data *) rd;
1135 return GNUNET_NAMESTORE_records_store (h, pkey, 1, &ri, &rds_sent,
1136 cont, cont_cls);
1137}
1138
1139
1142 struct GNUNET_NAMESTORE_Handle *h,
1143 const struct GNUNET_CRYPTO_PrivateKey *pkey,
1144 unsigned int rd_set_count,
1145 const struct GNUNET_NAMESTORE_RecordInfo *record_info,
1146 unsigned int *rds_sent,
1148 void *cont_cls)
1149{
1151 struct GNUNET_MQ_Envelope *env;
1152 const char *label;
1153 unsigned int rd_count;
1154 const struct GNUNET_GNSRECORD_Data *rd;
1155 char *name_tmp;
1156 char *rd_ser;
1157 ssize_t rd_ser_len[rd_set_count];
1158 size_t name_len;
1159 uint32_t rid;
1160 struct RecordStoreMessage *msg;
1161 struct RecordSet *rd_set;
1162 ssize_t sret;
1163 int i;
1164 size_t rd_set_len = 0;
1165 size_t key_len = 0;
1166 size_t max_len;
1168 max_len = UINT16_MAX - key_len - sizeof (struct RecordStoreMessage);
1169
1170 *rds_sent = 0;
1171 for (i = 0; i < rd_set_count; i++)
1172 {
1173 label = record_info[i].a_label;
1174 rd_count = record_info[i].a_rd_count;
1175 rd = record_info[i].a_rd;
1176 name_len = strlen (label) + 1;
1177 if (name_len > MAX_NAME_LEN)
1178 {
1179 GNUNET_break (0);
1180 *rds_sent = 0;
1181 return NULL;
1182 }
1184 if (rd_ser_len[i] < 0)
1185 {
1186 GNUNET_break (0);
1187 *rds_sent = 0;
1188 return NULL;
1189 }
1190 if (rd_ser_len[i] > max_len)
1191 {
1192 GNUNET_break (0);
1193 *rds_sent = 0;
1194 return NULL;
1195 }
1196 if ((rd_set_len + sizeof (struct RecordSet) + name_len + rd_ser_len[i]) >
1197 max_len)
1198 break;
1199 rd_set_len += sizeof (struct RecordSet) + name_len + rd_ser_len[i];
1200 }
1201 *rds_sent = i;
1203 "Sending %u of %u records!\n", *rds_sent, rd_set_count);
1204 rid = get_op_id (h);
1206 qe->h = h;
1207 qe->cont = cont;
1208 qe->cont_cls = cont_cls;
1209 qe->op_id = rid;
1210 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1211 /* setup msg */
1213 key_len + rd_set_len,
1215 GNUNET_assert (NULL != msg);
1216 GNUNET_assert (NULL != env);
1217 msg->gns_header.r_id = htonl (rid);
1218 msg->key_len = htons (key_len);
1219 msg->rd_set_count = htons ((uint16_t) (*rds_sent));
1221 &msg[1],
1222 key_len);
1223 rd_set = (struct RecordSet*) (((char*) &msg[1]) + key_len);
1224 for (int i = 0; i < *rds_sent; i++)
1225 {
1226 label = record_info[i].a_label;
1227 rd = record_info[i].a_rd;
1228 name_len = strlen (label) + 1;
1229 rd_set->name_len = htons (name_len);
1230 rd_set->rd_count = htons (record_info[i].a_rd_count);
1231 rd_set->rd_len = htons (rd_ser_len[i]);
1232 rd_set->reserved = ntohs (0);
1233 name_tmp = (char *) &rd_set[1];
1234 GNUNET_memcpy (name_tmp, label, name_len);
1235 rd_ser = &name_tmp[name_len];
1236 sret = GNUNET_GNSRECORD_records_serialize (record_info[i].a_rd_count,
1237 rd, rd_ser_len[i], rd_ser);
1238 if ((0 > sret) || (sret != rd_ser_len[i]))
1239 {
1240 GNUNET_break (0);
1241 GNUNET_free (env);
1242 return NULL;
1243 }
1244 // Point to next RecordSet
1245 rd_set = (struct RecordSet*) &name_tmp[name_len + rd_ser_len[i]];
1246 }
1248 "Sending NAMESTORE_RECORD_STORE message for name %u record sets\n",
1249 *rds_sent);
1250 qe->timeout_task =
1252 if (NULL == h->mq)
1253 {
1254 qe->env = env;
1256 "Delaying NAMESTORE_RECORD_STORE message as namestore is not ready!\n");
1257 }
1258 else
1259 {
1260 GNUNET_MQ_send (h->mq, env);
1261 }
1262 return qe;
1263}
1264
1265
1266static struct GNUNET_NAMESTORE_QueueEntry *
1268 struct GNUNET_NAMESTORE_Handle *h,
1269 const struct GNUNET_CRYPTO_PrivateKey *pkey,
1270 const char *label,
1272 void *error_cb_cls,
1274 void *rm_cls,
1276{
1278 struct GNUNET_MQ_Envelope *env;
1279 struct LabelLookupMessage *msg;
1280 size_t label_len;
1281 size_t key_len;
1282
1283 if (1 == (label_len = strlen (label) + 1))
1284 {
1285 GNUNET_break (0);
1286 return NULL;
1287 }
1288
1290 qe->h = h;
1291 qe->error_cb = error_cb;
1292 qe->error_cb_cls = error_cb_cls;
1293 qe->proc = rm;
1294 qe->proc_cls = rm_cls;
1295 qe->op_id = get_op_id (h);
1296 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1297
1302 msg->gns_header.r_id = htonl (qe->op_id);
1304 &msg[1],
1305 key_len);
1306
1307 msg->key_len = htons (key_len);
1308 msg->label_len = htons (label_len);
1309 msg->filter = htons (filter);
1310 GNUNET_memcpy (((char*) &msg[1]) + key_len, label, label_len);
1311 if (NULL == h->mq)
1312 qe->env = env;
1313 else
1314 GNUNET_MQ_send (h->mq, env);
1315 return qe;
1316}
1317
1318
1321 struct GNUNET_NAMESTORE_Handle *h,
1322 const struct GNUNET_CRYPTO_PrivateKey *pkey,
1323 const char *label,
1325 void *error_cb_cls,
1327 void *rm_cls)
1328{
1329 return records_lookup (h, pkey, label,
1331 rm, rm_cls, GNUNET_GNSRECORD_FILTER_NONE);
1332
1333}
1334
1335
1338 struct GNUNET_NAMESTORE_Handle *h,
1339 const struct GNUNET_CRYPTO_PrivateKey *pkey,
1340 const char *label,
1342 void *error_cb_cls,
1344 void *rm_cls,
1346{
1347 return records_lookup (h, pkey, label,
1349 rm, rm_cls, filter);
1350
1351}
1352
1353
1356 struct GNUNET_NAMESTORE_Handle *h,
1357 const struct GNUNET_CRYPTO_PrivateKey *zone,
1358 const struct GNUNET_CRYPTO_PublicKey *value_zone,
1360 void *error_cb_cls,
1362 void *proc_cls)
1363{
1365 struct GNUNET_MQ_Envelope *env;
1366 struct ZoneToNameMessage *msg;
1367 uint32_t rid;
1368 size_t key_len;
1369 ssize_t pkey_len;
1370
1371 rid = get_op_id (h);
1373 qe->h = h;
1374 qe->error_cb = error_cb;
1375 qe->error_cb_cls = error_cb_cls;
1376 qe->proc = proc;
1377 qe->proc_cls = proc_cls;
1378 qe->op_id = rid;
1379 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1380
1385 msg->gns_header.r_id = htonl (rid);
1386 msg->key_len = htons (key_len);
1387 msg->pkey_len = htons (pkey_len);
1390 (char*) &msg[1] + key_len,
1391 pkey_len);
1392 if (NULL == h->mq)
1393 qe->env = env;
1394 else
1395 GNUNET_MQ_send (h->mq, env);
1396 return qe;
1397}
1398
1399
1402 struct GNUNET_NAMESTORE_Handle *h,
1403 const struct GNUNET_CRYPTO_PrivateKey *zone,
1405 void *error_cb_cls,
1407 void *proc_cls,
1409 void *finish_cb_cls)
1410{
1412 struct GNUNET_MQ_Envelope *env;
1414 uint32_t rid;
1415 size_t key_len = 0;
1416
1417 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_START message\n");
1418 rid = get_op_id (h);
1420 it->h = h;
1421 it->error_cb = error_cb;
1422 it->error_cb_cls = error_cb_cls;
1423 it->finish_cb = finish_cb;
1424 it->finish_cb_cls = finish_cb_cls;
1425 it->proc = proc;
1426 it->proc_cls = proc_cls;
1427 it->op_id = rid;
1428 if (NULL != zone)
1429 {
1430 it->zone = *zone;
1432 }
1433 GNUNET_CONTAINER_DLL_insert_tail (h->z_head, h->z_tail, it);
1435 key_len,
1437 msg->gns_header.r_id = htonl (rid);
1438 msg->key_len = htons (key_len);
1439 if (NULL != zone)
1441 if (NULL == h->mq)
1442 it->env = env;
1443 else
1444 GNUNET_MQ_send (h->mq, env);
1445 return it;
1446}
1447
1448
1451 struct GNUNET_NAMESTORE_Handle *h,
1452 const struct GNUNET_CRYPTO_PrivateKey *zone,
1454 void *error_cb_cls,
1456 void *proc_cls,
1458 void *finish_cb_cls,
1460{
1462 struct GNUNET_MQ_Envelope *env;
1464 uint32_t rid;
1465 size_t key_len = 0;
1466
1467 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_START message\n");
1468 rid = get_op_id (h);
1470 it->h = h;
1471 it->error_cb = error_cb;
1472 it->error_cb_cls = error_cb_cls;
1473 it->finish_cb = finish_cb;
1474 it->finish_cb_cls = finish_cb_cls;
1475 it->proc2 = proc;
1476 it->proc_cls = proc_cls;
1477 it->op_id = rid;
1478 if (NULL != zone)
1479 {
1480 it->zone = *zone;
1482 }
1483 GNUNET_CONTAINER_DLL_insert_tail (h->z_head, h->z_tail, it);
1485 key_len,
1487 msg->gns_header.r_id = htonl (rid);
1488 msg->key_len = htons (key_len);
1489 msg->filter = htons ((uint16_t) filter);
1490 if (NULL != zone)
1492 if (NULL == h->mq)
1493 it->env = env;
1494 else
1495 GNUNET_MQ_send (h->mq, env);
1496 return it;
1497}
1498
1499
1500void
1502 uint64_t limit)
1503{
1504 struct GNUNET_NAMESTORE_Handle *h = it->h;
1506 struct GNUNET_MQ_Envelope *env;
1507
1509 "Sending ZONE_ITERATION_NEXT message with limit %llu\n",
1510 (unsigned long long) limit);
1512 msg->gns_header.r_id = htonl (it->op_id);
1513 msg->limit = GNUNET_htonll (limit);
1514 GNUNET_MQ_send (h->mq, env);
1515}
1516
1517
1523void
1525{
1526 struct GNUNET_NAMESTORE_Handle *h = it->h;
1527 struct GNUNET_MQ_Envelope *env;
1529
1530 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_STOP message\n");
1531 if (NULL != h->mq)
1532 {
1533 env =
1535 msg->gns_header.r_id = htonl (it->op_id);
1536 GNUNET_MQ_send (h->mq, env);
1537 }
1538 free_ze (it);
1539}
1540
1541
1548void
1550{
1551 free_qe (qe);
1552}
1553
1554
1561 const struct
1563 const char *label,
1564 const char *editor_hint,
1566 edit_cb,
1567 void *edit_cb_cls)
1568{
1570 struct GNUNET_MQ_Envelope *env;
1571 struct EditRecordSetMessage *msg;
1572 size_t label_len;
1573 size_t key_len;
1574 size_t editor_hint_len;
1575
1576 if (1 == (label_len = strlen (label) + 1))
1577 {
1578 GNUNET_break (0);
1579 return NULL;
1580 }
1581 GNUNET_assert (editor_hint != NULL);
1582 editor_hint_len = strlen (editor_hint) + 1;
1584 qe->h = h;
1585 qe->edit_proc = edit_cb;
1586 qe->proc_cls = edit_cb_cls;
1587 qe->op_id = get_op_id (h);
1588 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1589
1594 msg->gns_header.r_id = htonl (qe->op_id);
1596 &msg[1],
1597 key_len);
1598
1599 msg->key_len = htons (key_len);
1600 msg->label_len = htons (label_len);
1601 msg->editor_hint_len = htons (editor_hint_len);
1602 GNUNET_memcpy (((char*) &msg[1]) + key_len, label, label_len);
1603 GNUNET_memcpy (((char*) &msg[1]) + key_len + label_len, editor_hint,
1605 if (NULL == h->mq)
1606 qe->env = env;
1607 else
1608 GNUNET_MQ_send (h->mq, env);
1609 return qe;
1610}
1611
1612
1615 const struct
1617 const char *label,
1618 const char *editor_hint,
1619 const char *editor_hint_replacement,
1621 void *finished_cls)
1622{
1624 struct GNUNET_MQ_Envelope *env;
1626 size_t label_len;
1627 size_t key_len;
1628 size_t editor_hint_len;
1630
1631 if (1 == (label_len = strlen (label) + 1))
1632 {
1633 GNUNET_break (0);
1634 return NULL;
1635 }
1636 GNUNET_assert (editor_hint != NULL);
1637 editor_hint_len = strlen (editor_hint) + 1;
1638 GNUNET_assert (editor_hint != NULL);
1639 editor_hint_replacement_len = strlen (editor_hint_replacement) + 1;
1641 qe->h = h;
1642 qe->op_id = get_op_id (h);
1643 qe->cont = finished_cb;
1644 qe->cont_cls = finished_cls;
1645 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1646
1652 msg->gns_header.r_id = htonl (qe->op_id);
1654 &msg[1],
1655 key_len);
1656
1657 msg->key_len = htons (key_len);
1658 msg->label_len = htons (label_len);
1659 msg->editor_hint_len = htons (editor_hint_len);
1660 msg->editor_hint_replacement_len = htons (editor_hint_replacement_len);
1661 GNUNET_memcpy (((char*) &msg[1]) + key_len, label, label_len);
1662 GNUNET_memcpy (((char*) &msg[1]) + key_len + label_len, editor_hint,
1664 GNUNET_memcpy (((char*) &msg[1]) + key_len + label_len + editor_hint_len,
1665 editor_hint_replacement,
1667 if (NULL == h->mq)
1668 qe->env = env;
1669 else
1670 GNUNET_MQ_send (h->mq, env);
1671 return qe;
1672}
1673
1674
1675/* end of namestore_api.c */
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static void error_cb(void *cls)
Function called if lookup fails.
Definition: gnunet-abd.c:479
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 finished_cb(enum GNUNET_GenericReturnValue rv)
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
static char * pkey
Public key of the zone to look in, in ASCII.
static char * name
Name (label) of the records to list.
static unsigned int rd_count
Number of records for currently parsed set.
static char * res
Currently read line or NULL on EOF.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
static struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don't have the content.
API that can be used to store naming information on a GNUnet node;.
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.
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.
int GNUNET_GNSRECORD_records_deserialize(size_t len, const char *src, unsigned int rd_count, struct GNUNET_GNSRECORD_Data *dest)
Deserialize the given records to the given destination.
ssize_t GNUNET_GNSRECORD_records_serialize(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, size_t dest_size, char *dest)
Serialize the given records to the given destination buffer.
ssize_t GNUNET_GNSRECORD_records_get_size(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Calculate how many bytes we will need to serialize the given records.
GNUNET_GNSRECORD_Filter
Filter for GNUNET_GNSRECORD_normalize_record_set().
@ GNUNET_GNSRECORD_FILTER_NONE
No filter flags set.
ssize_t GNUNET_CRYPTO_public_key_get_length(const struct GNUNET_CRYPTO_PublicKey *key)
Get the compacted length of a GNUNET_CRYPTO_PublicKey.
Definition: crypto_pkey.c:68
#define GNUNET_log(kind,...)
ssize_t GNUNET_CRYPTO_write_public_key_to_buffer(const struct GNUNET_CRYPTO_PublicKey *key, void *buffer, size_t len)
Writes a GNUNET_CRYPTO_PublicKey to a compact buffer.
Definition: crypto_pkey.c:128
ssize_t GNUNET_CRYPTO_private_key_get_length(const struct GNUNET_CRYPTO_PrivateKey *key)
Get the compacted length of a GNUNET_CRYPTO_PrivateKey.
Definition: crypto_pkey.c:47
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:37
ssize_t GNUNET_CRYPTO_write_private_key_to_buffer(const struct GNUNET_CRYPTO_PrivateKey *key, void *buffer, size_t len)
Writes a GNUNET_CRYPTO_PrivateKey to a compact buffer.
Definition: crypto_pkey.c:171
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_read_private_key_from_buffer(const void *buffer, size_t len, struct GNUNET_CRYPTO_PrivateKey *key, size_t *read)
Reads a GNUNET_CRYPTO_PrivateKey from a compact buffer.
Definition: crypto_pkey.c:146
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#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_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
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.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:285
#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
void(* GNUNET_NAMESTORE_ContinuationWithStatus)(void *cls, enum GNUNET_ErrorCode ec)
Continuation called to notify client about result of the operation.
struct GNUNET_NAMESTORE_ZoneIterator * GNUNET_NAMESTORE_zone_iteration_start2(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *zone, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordSetMonitor proc, void *proc_cls, GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls, enum GNUNET_GNSRECORD_Filter filter)
Starts a new zone iteration (used to periodically PUT all of our records into our DHT).
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_lookup(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *pkey, const char *label, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor rm, void *rm_cls)
Lookup an item in the namestore.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_record_set_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *pkey, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
Store an item in the namestore.
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
void(* GNUNET_NAMESTORE_RecordMonitor)(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Process a record that was stored in the namestore.
void GNUNET_NAMESTORE_zone_iterator_next(struct GNUNET_NAMESTORE_ZoneIterator *it, uint64_t limit)
Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start for the next record.
void GNUNET_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe)
Cancel a namestore operation.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_lookup2(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *pkey, const char *label, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor rm, void *rm_cls, enum GNUNET_GNSRECORD_Filter filter)
Lookup an item in the namestore with GNSRECORD filter.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_zone_to_name(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *zone, const struct GNUNET_CRYPTO_PublicKey *value_zone, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls)
Look for an existing PKEY delegation record for a given public key.
struct GNUNET_NAMESTORE_ZoneIterator * GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *zone, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls, GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls)
void(* GNUNET_NAMESTORE_RecordSetMonitor)(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, struct GNUNET_TIME_Absolute expiry)
Process a record set that was stored in the namestore.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_record_set_edit_cancel(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *pkey, const char *label, const char *editor_hint, const char *editor_hint_replacement, GNUNET_NAMESTORE_ContinuationWithStatus finished_cb, void *finished_cls)
If the current advisory lock is set to the provided editor hint, this API cancels the editing of a re...
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *pkey, unsigned int rd_set_count, const struct GNUNET_NAMESTORE_RecordInfo *record_info, unsigned int *rds_sent, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
Store one or more record sets in the namestore.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_record_set_edit_begin(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *pkey, const char *label, const char *editor_hint, GNUNET_NAMESTORE_EditRecordSetBeginCallback edit_cb, void *edit_cb_cls)
New API draft.
void(* GNUNET_NAMESTORE_EditRecordSetBeginCallback)(void *cls, enum GNUNET_ErrorCode ec, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, const char *editor_hint)
Process a record that was stored in the namestore.
struct GNUNET_NAMESTORE_Handle * GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the connection with the NAMESTORE service.
void GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it)
Stops iteration and releases the namestore handle for further calls.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END
Service to client: end of list of results.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT
Service to client: here is a (plaintext) record you requested.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_SET_EDIT
Message type for start of record edit with advisory lock.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE
Service to client: result of zone-to-name lookup.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_GENERIC_RESPONSE
Service to client: result of store operation.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_SET_EDIT_CANCEL
Message type for cancellation/reset of editor hint/advisory lock.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT
Client to service: next record(s) in iteration please.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START
Client to service: please start iteration; receives "GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPON...
#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP
Client to service: stop iterating.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE
Service to client: lookup label.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_SET_EDIT_RESPONSE
Return record set to edit with previous editor hint/advisory lock.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE
Client to service: store records (as authority)
#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME
Client to service: "reverse" lookup for zone name based on zone key.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP
Client to service: lookup label.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
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_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:737
#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 MAX_NAME_LEN
Maximum length of any name, including 0-termination.
Definition: namecache.h:33
common internal definitions for namestore service
static void handle_zone_to_name_response(void *cls, const struct ZoneToNameResponseMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE.
static int check_lookup_result(void *cls, const struct LabelLookupResponseMessage *msg)
Check validity of an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE.
static int check_edit_record_set_response(void *cls, const struct EditRecordSetResponseMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_SET_EDIT_RESPONSE.
#define NAMESTORE_DELAY_TOLERANCE
We grant the namestore up to 1 minute of latency, if it is slower than that, store queries will fail.
Definition: namestore_api.c:42
static void free_qe(struct GNUNET_NAMESTORE_QueueEntry *qe)
Free qe.
static void handle_edit_record_set_response(void *cls, const struct EditRecordSetResponseMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_SET_EDIT_RESPONSE.
static void warn_delay(void *cls)
Task launched to warn the user that the namestore is excessively slow and that a query was thus dropp...
static int check_record_result(void *cls, const struct RecordResultMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT.
static void handle_record_result_end(void *cls, const struct GNUNET_NAMESTORE_Header *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END.
static void free_ze(struct GNUNET_NAMESTORE_ZoneIterator *ze)
Free ze.
static struct GNUNET_NAMESTORE_QueueEntry * find_qe(struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
Find the queue entry that matches the rid.
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
static int check_rd(size_t rd_len, const void *rd_buf, unsigned int rd_count)
Check that rd_buf of length rd_len contains rd_count records.
static int check_zone_to_name_response(void *cls, const struct ZoneToNameResponseMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE.
static void handle_generic_response(void *cls, const struct NamestoreResponseMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_GENERIC_RESPONSE.
static void handle_lookup_result(void *cls, const struct LabelLookupResponseMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE.
static void reconnect(struct GNUNET_NAMESTORE_Handle *h)
Reconnect to namestore service.
static void force_reconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from service and then reconnect.
#define LOG(kind,...)
Definition: namestore_api.c:36
static uint32_t get_op_id(struct GNUNET_NAMESTORE_Handle *h)
Get a fresh operation id to distinguish between namestore requests.
static void handle_record_result(void *cls, const struct RecordResultMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT.
static struct GNUNET_NAMESTORE_QueueEntry * records_lookup(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *pkey, const char *label, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor rm, void *rm_cls, enum GNUNET_GNSRECORD_Filter filter)
static void reconnect_task(void *cls)
Re-establish the connection to the service.
static struct GNUNET_NAMESTORE_ZoneIterator * find_zi(struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
Find the zone iteration entry that matches the rid.
const char * GNUNET_ErrorCode_get_hint(enum GNUNET_ErrorCode ec)
Returns a hint for a given error code.
GNUNET_ErrorCode
Taler error codes.
@ GNUNET_EC_NAMESTORE_NO_RESULTS
No results given.
@ GNUNET_EC_NONE
No error (success).
@ GNUNET_EC_NAMESTORE_UNKNOWN
Unknown namestore error.
Edit a record set and set editor hint/advisory lock.
Definition: namestore.h:242
uint16_t editor_hint_replacement_len
Unused.
Definition: namestore.h:261
uint16_t editor_hint_len
Unused.
Definition: namestore.h:256
uint16_t label_len
Length of the name.
Definition: namestore.h:251
uint16_t key_len
Length of the zone key.
Definition: namestore.h:266
Edit a record set and set editor hint/advisory lock.
Definition: namestore.h:204
uint16_t editor_hint_len
Unused.
Definition: namestore.h:218
uint16_t label_len
Length of the name.
Definition: namestore.h:213
uint16_t key_len
Length of the zone key.
Definition: namestore.h:228
Response to RecordSetEditMessage.
Definition: namestore.h:131
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
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
struct GNUNET_DATASTORE_Handle * h
Handle to the master context.
struct GNUNET_MQ_Envelope * env
Envelope of the request to transmit, NULL after transmission.
struct GNUNET_DATASTORE_QueueEntry * next
This is a linked list.
GNUNET_DATASTORE_ContinuationWithStatus cont
Function to call after transmission of the request.
void * cont_cls
Closure for cont.
Handle to a message queue.
Definition: mq.c:87
Message handler for a specific message type.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
Connection to the NAMESTORE service.
uint32_t last_op_id_used
The last operation id used for a NAMESTORE operation.
struct GNUNET_NAMESTORE_ZoneIterator * z_head
Head of pending namestore zone iterator entries.
struct GNUNET_NAMESTORE_QueueEntry * op_tail
Tail of pending namestore queue entries.
struct GNUNET_SCHEDULER_Task * reconnect_task
Reconnect task.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
struct GNUNET_NAMESTORE_QueueEntry * op_head
Head of pending namestore queue entries.
struct GNUNET_TIME_Relative reconnect_delay
Delay introduced before we reconnect.
struct GNUNET_NAMESTORE_ZoneIterator * z_tail
Tail of pending namestore zone iterator entries.
int reconnect
Should we reconnect to service due to some serious error?
struct GNUNET_MQ_Handle * mq
Connection to the service (if available).
Generic namestore message with op id.
Definition: namestore.h:41
An QueueEntry used to store information for a pending NAMESTORE record operation.
Definition: namestore_api.c:49
GNUNET_NAMESTORE_EditRecordSetBeginCallback edit_proc
Function to call with the records we get back including optional editor hint.
Definition: namestore_api.c:88
struct GNUNET_MQ_Envelope * env
Envelope of the message to send to the service, if not yet sent.
struct GNUNET_NAMESTORE_QueueEntry * prev
Kept in a DLL.
Definition: namestore_api.c:58
uint32_t op_id
The operation id this zone iteration operation has.
void * error_cb_cls
Closure for error_cb.
GNUNET_NAMESTORE_RecordMonitor proc
Function to call with the records we get back; or NULL.
Definition: namestore_api.c:78
struct GNUNET_NAMESTORE_QueueEntry * next
Kept in a DLL.
Definition: namestore_api.c:53
struct GNUNET_NAMESTORE_Handle * h
Main handle to access the namestore.
Definition: namestore_api.c:63
GNUNET_NAMESTORE_ContinuationWithStatus cont
Continuation to call.
Definition: namestore_api.c:68
GNUNET_NAMESTORE_RecordSetMonitor proc2
Function to call with the records we get back; or NULL.
Definition: namestore_api.c:83
struct GNUNET_SCHEDULER_Task * timeout_task
Task scheduled to warn us if the namestore is way too slow.
void * cont_cls
Closure for cont.
Definition: namestore_api.c:73
void * proc_cls
Closure for proc.
Definition: namestore_api.c:93
GNUNET_SCHEDULER_TaskCallback error_cb
Function to call on errors.
Definition: namestore_api.c:98
A struct for record bulk import.
struct GNUNET_GNSRECORD_Data * a_rd
Handle for a zone iterator operation.
void * finish_cb_cls
Closure for error_cb.
void * error_cb_cls
Closure for error_cb.
struct GNUNET_CRYPTO_PrivateKey zone
Private key of the zone.
struct GNUNET_NAMESTORE_ZoneIterator * next
Kept in a DLL.
GNUNET_NAMESTORE_RecordSetMonitor proc2
The continuation to call with the results.
struct GNUNET_NAMESTORE_Handle * h
Main handle to access the namestore.
void * proc_cls
Closure for proc.
uint32_t op_id
The operation id this zone iteration operation has.
GNUNET_NAMESTORE_RecordMonitor proc
The continuation to call with the results.
GNUNET_SCHEDULER_TaskCallback error_cb
Function to call on errors.
struct GNUNET_MQ_Envelope * env
Envelope of the message to send to the service, if not yet sent.
GNUNET_SCHEDULER_TaskCallback finish_cb
Function to call on completion.
struct GNUNET_NAMESTORE_ZoneIterator * prev
Kept in a DLL.
Entry in list of pending tasks.
Definition: scheduler.c:136
Time for relative time used by GNUnet, in microseconds.
Lookup a label.
Definition: namestore.h:168
uint16_t key_len
Length of the zone key.
Definition: namestore.h:192
uint16_t label_len
Length of the name.
Definition: namestore.h:177
Response to a record storage request.
Definition: namestore.h:114
Record is returned from the namestore (as authority).
Definition: namestore.h:404
uint16_t rd_len
Length of serialized record data.
Definition: namestore.h:64
uint16_t rd_count
Number of records contained.
Definition: namestore.h:69
uint16_t reserved
Reserved for alignment.
Definition: namestore.h:74
uint16_t name_len
Name length.
Definition: namestore.h:59
Store a record to the namestore (as authority).
Definition: namestore.h:87
uint16_t rd_set_count
Number of record sets.
Definition: namestore.h:96
Ask for next result of zone iteration for the given operation.
Definition: namestore.h:572
Start a zone iteration for the given zone.
Definition: namestore.h:545
uint16_t key_len
Length of the zone key.
Definition: namestore.h:560
Stop zone iteration for the given operation.
Definition: namestore.h:591
Lookup a name for a zone hash.
Definition: namestore.h:330
uint16_t pkey_len
Length of the public value zone key.
Definition: namestore.h:344
uint16_t key_len
Length of the zone key.
Definition: namestore.h:339
Respone for zone to name lookup.
Definition: namestore.h:358