GNUnet 0.25.2-10-g5b94a194f
 
Loading...
Searching...
No Matches
gnunet-namestore.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012, 2013, 2014, 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 */
28#include "platform.h"
29#include "gnunet_common.h"
30#include <gnunet_util_lib.h>
33#include <gnunet_gns_service.h>
35#include <inttypes.h>
36
41#define WARN_RELATIVE_EXPIRATION_LIMIT GNUNET_TIME_relative_multiply ( \
42 GNUNET_TIME_UNIT_MINUTES, 15)
43
59
64{
69
74
78 char *name;
79
84};
85
90{
94 struct EgoEntry *next;
95
99 struct EgoEntry *prev;
100
105
110};
111
116
121
126
130static char *ego_name;
131
136
141
146
151
156
161
166
170static struct EgoEntry *ego_head;
171
175static struct EgoEntry *ego_tail;
176
181
186
190static int list;
191
195static int add;
196
200static int del;
201
205static int is_public;
206
210static int is_shadow;
211
215static int is_maintenance;
216
220static int omit_private;
221
226
227
231static int purge_zone;
232
237
241static int purge_orphaned;
242
246static int list_orphaned;
247
252
257
262
266static char *name;
267
271static char *value;
272
276static char *uri;
277
281static char *reverse_pkey;
282
286static char *typestring;
287
291static char *expirationstring;
292
296static char *nickstring;
297
301static int ret;
302
306static uint32_t type;
307
311static void *data;
312
316static size_t data_size;
317
321static uint64_t etime;
322
327
332
336static int monitor;
337
342
347
348/* FIXME: Make array and grow as needed */
349#define INITIAL_RI_BUFFER_SIZE 5000
350
351static unsigned int ri_count = 0;
352
354
356static unsigned int record_info_capacity = 0;
357
358/* How many records to put simulatneously */
359static unsigned int max_batch_size = 1000;
360
369static int
370parse_expiration (const char *exp_str,
371 int *is_rel,
372 uint64_t *exptime)
373{
374 struct GNUNET_TIME_Relative etime_rel;
375 struct GNUNET_TIME_Absolute etime_abs;
376
377 if (0 == strcmp (exp_str, "never"))
378 {
380 *is_rel = GNUNET_NO;
381 return GNUNET_OK;
382 }
383 if (GNUNET_OK ==
384 GNUNET_STRINGS_fancy_time_to_relative (exp_str, &etime_rel))
385 {
386 *is_rel = GNUNET_YES;
387 *exptime = etime_rel.rel_value_us;
389 {
391 "Relative expiration times of less than %s are not recommended. To improve availability, consider increasing this value.\n",
394 }
396 "Storing record with relative expiration time of %s\n",
398 return GNUNET_OK;
399 }
400 if (GNUNET_OK ==
401 GNUNET_STRINGS_fancy_time_to_absolute (exp_str, &etime_abs))
402 {
403 *is_rel = GNUNET_NO;
404 *exptime = etime_abs.abs_value_us;
406 "Storing record with absolute expiration time of %s\n",
408 return GNUNET_OK;
409 }
410 return GNUNET_SYSERR;
411}
412
413
414static int
416{
417 struct RecordSetEntry *r;
419 char *cp;
420 char *tok;
421 char *saveptr;
422 void *raw_data;
423
424 cp = GNUNET_strdup (line);
425 tok = strtok_r (cp, " ", &saveptr);
426 if (NULL == tok)
427 {
429 _ ("Missing entries in record line `%s'.\n"),
430 line);
431 GNUNET_free (cp);
432 return GNUNET_SYSERR;
433 }
435 if (UINT32_MAX == record.record_type)
436 {
437 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Unknown record type `%s'\n"), tok);
438 GNUNET_free (cp);
439 return GNUNET_SYSERR;
440 }
441 tok = strtok_r (NULL, " ", &saveptr);
442 if (NULL == tok)
443 {
445 _ ("Empty record line argument is not allowed.\n"));
446 GNUNET_free (cp);
447 return GNUNET_SYSERR;
448 }
449 if (1 != sscanf (tok, "%" SCNu64, &record.expiration_time))
450 {
451 fprintf (stderr,
452 _ ("Error parsing expiration time %s.\n"), tok);
453 GNUNET_free (cp);
454 return GNUNET_SYSERR;
455 }
456 tok = strtok_r (NULL, " ", &saveptr);
457 if (NULL == tok)
458 {
460 _ ("Empty record line argument is not allowed.\n"));
461 GNUNET_free (cp);
462 return GNUNET_SYSERR;
463 }
465 if (NULL != strchr (tok, (unsigned char) 'r'))
467 if (NULL == strchr (tok, (unsigned char) 'p')) /* p = public */
469 if (NULL != strchr (tok, (unsigned char) 'S'))
471 if (NULL != strchr (tok, (unsigned char) 's'))
473 if (NULL != strchr (tok, (unsigned char) 'C'))
475 tok += strlen (tok) + 1;
477 tok,
478 &raw_data,
479 &record.data_size))
480 {
482 _ ("Invalid record data for type %s: `%s'.\n"),
484 tok);
485 GNUNET_free (cp);
486 return GNUNET_SYSERR;
487 }
488 GNUNET_free (cp);
489
490 r = GNUNET_malloc (sizeof(struct RecordSetEntry) + record.data_size);
491 r->next = recordset;
492 record.data = &r[1];
493 memcpy (&r[1], raw_data, record.data_size);
494 GNUNET_free (raw_data);
495 r->record = record;
496 recordset = r;
497 return GNUNET_OK;
498}
499
500
501static void
503{
504 struct RecordSetEntry *rs_entry;
505
506 while (NULL != (rs_entry = recordset))
507 {
509 GNUNET_free (rs_entry);
510 }
511 recordset = NULL;
512}
513
514
515static void
517{
518 struct MarkedRecord *mrec;
519 struct MarkedRecord *mrec_tmp;
521 if (NULL != ego_name)
522 {
524 ego_name = NULL;
525 }
526 if (NULL != name)
527 {
529 name = NULL;
530 }
531 if (NULL != value)
532 {
534 value = NULL;
535 }
536 if (NULL != uri)
537 {
539 uri = NULL;
540 }
541 if (NULL != expirationstring)
542 {
544 expirationstring = NULL;
545 }
546 if (NULL != purge_task)
547 {
549 purge_task = NULL;
550 }
551 for (mrec = marked_head; NULL != mrec;)
552 {
553 mrec_tmp = mrec;
554 mrec = mrec->next;
555 GNUNET_free (mrec_tmp->name);
556 GNUNET_free (mrec_tmp);
557 }
558 if (NULL != list_it)
559 {
561 list_it = NULL;
562 }
563 if (NULL != add_qe)
564 {
566 add_qe = NULL;
567 }
568 if (NULL != set_qe)
569 {
571 set_qe = NULL;
572 }
573 if (NULL != add_qe_uri)
574 {
576 add_qe_uri = NULL;
577 }
578 if (NULL != get_qe)
579 {
581 get_qe = NULL;
582 }
583 if (NULL != del_qe)
584 {
586 del_qe = NULL;
587 }
588 if (NULL != reverse_qe)
589 {
591 reverse_qe = NULL;
592 }
593 memset (&zone_pkey, 0, sizeof(zone_pkey));
594 if (NULL != zm)
595 {
597 zm = NULL;
598 }
599 if (NULL != data)
600 {
602 data = NULL;
603 }
604 if (NULL != typestring)
605 {
607 typestring = NULL;
608 }
609 list = 0;
610 is_public = 0;
611 is_shadow = 0;
612 is_maintenance = 0;
613 purge_zone = 0;
614}
615
616
622static void
623do_shutdown (void *cls)
624{
625 struct EgoEntry *ego_entry;
626 struct EgoEntry *ego_tmp;
627 (void) cls;
628
629 reset_handles ();
630 if (NULL != record_info)
632 record_info = NULL;
633 if (NULL != ns_qe)
634 {
636 ns_qe = NULL;
637 }
638 if (NULL != ns)
639 {
641 ns = NULL;
642 }
643 if (NULL != idh)
644 {
646 idh = NULL;
647 }
648 for (ego_entry = ego_head; NULL != ego_entry;)
649 {
650 ego_tmp = ego_entry;
651 ego_entry = ego_entry->next;
652 GNUNET_free (ego_tmp->identifier);
653 GNUNET_free (ego_tmp);
654 }
655}
656
657
658static void
660
661static unsigned int ri_sent = 0;
662
669static void
671
672static void
674{
675 // if (ri_sent < ri_count)
676 // {
677 // batch_insert_recordinfo (cfg);
678 // return;
679 // }
680 // reset_handles ();
681 if (read_from_stdin)
682 {
684 return;
685 }
687}
688
689
690static void
692{
693 struct GNUNET_NAMESTORE_QueueEntry **qe = cls;
694
695 *qe = NULL;
696 if (GNUNET_EC_NONE != ec)
697 {
698 fprintf (stderr,
699 _ ("Adding record failed: %s\n"),
702 ret = 1;
704 return;
705 }
706 ret = 0;
708}
709
710
711static void
713{
714 (void) cls;
715 del_qe = NULL;
717 {
718 fprintf (stderr,
719 _ ("Deleting record failed: %s\n"), GNUNET_ErrorCode_get_hint (
720 ec));
721 }
723}
724
725
726static void
727purge_next_record (void *cls);
728
729static void
731{
732 del_qe = NULL;
733 if (GNUNET_EC_NONE != ec)
734 {
735 fprintf (stderr,
736 _ ("Deleting record failed: %s\n"),
738 }
740}
741
742
743static void
745{
746 struct MarkedRecord *mrec;
747 purge_task = NULL;
748
749 if (NULL == marked_head)
750 {
751 ret = 0;
753 return;
754 }
755 mrec = marked_head;
758 mrec);
760 &mrec->key,
761 mrec->name,
762 0, NULL,
764 NULL);
765 GNUNET_free (mrec->name);
766 GNUNET_free (mrec);
767}
768
769
773static void
775{
776 (void) cls;
777 list_it = NULL;
779 {
781 return;
782 }
783 ret = 0;
785}
786
787
791static void
793{
794 (void) cls;
795 list_it = NULL;
796 fprintf (stderr, "Error iterating over zone\n");
797 ret = 1;
799}
800
801
802static void
805 const char *rname,
806 unsigned int rd_len,
807 const struct GNUNET_GNSRECORD_Data *rd)
808{
809 struct MarkedRecord *mrec;
810
811 mrec = GNUNET_new (struct MarkedRecord);
812 mrec->key = *zone_key;
813 mrec->name = GNUNET_strdup (rname);
816 mrec);
817}
818
819
820static void
822 const char *rname,
823 unsigned int rd_len,
824 const struct GNUNET_GNSRECORD_Data *rd)
825{
826 struct EgoEntry *ego;
827 struct MarkedRecord *orphan;
828 int is_orphaned = 1;
829
830 for (ego = ego_head; NULL != ego; ego = ego->next)
831 {
832 if (0 == memcmp (GNUNET_IDENTITY_ego_get_private_key (ego->ego),
833 zone_key,
834 sizeof (*zone_key)))
835 {
836 is_orphaned = 0;
837 break;
838 }
839 }
840 if (is_orphaned)
841 {
842 orphan = GNUNET_new (struct MarkedRecord);
843 orphan->key = *zone_key;
844 orphan->name = GNUNET_strdup (rname);
847 orphan);
848 }
849}
850
851
859static void
861 const char *rname,
862 unsigned int rd_len,
863 const struct GNUNET_GNSRECORD_Data *rd)
864{
865 const char *typestr;
866 char *s;
867 const char *ets;
868 struct GNUNET_TIME_Absolute at;
869 struct GNUNET_TIME_Relative rt;
870 struct EgoEntry *ego;
871 int have_record;
872 int is_orphaned = 1;
873 char *orphaned_str;
874
875 if ((NULL != name) && (0 != strcmp (name, rname)))
876 return;
877 have_record = GNUNET_NO;
878 for (unsigned int i = 0; i < rd_len; i++)
879 {
880 if ((GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) &&
881 (0 != strcmp (rname, GNUNET_GNS_EMPTY_LABEL_AT)))
882 continue;
883 if ((type != rd[i].record_type) && (GNUNET_GNSRECORD_TYPE_ANY != type))
884 continue;
885 have_record = GNUNET_YES;
886 break;
887 }
888 if (GNUNET_NO == have_record)
889 return;
890 for (ego = ego_head; NULL != ego; ego = ego->next)
891 {
892 if (0 == memcmp (GNUNET_IDENTITY_ego_get_private_key (ego->ego),
893 zone_key,
894 sizeof (*zone_key)))
895 {
896 is_orphaned = 0;
897 break;
898 }
899 }
900 if (list_orphaned && ! is_orphaned)
901 return;
902 if (! list_orphaned && is_orphaned)
903 return;
904 orphaned_str = GNUNET_CRYPTO_blindable_private_key_to_string (zone_key);
905 fprintf (stdout, "%s.%s:\n", rname, is_orphaned ? orphaned_str :
906 ego->identifier);
907 GNUNET_free (orphaned_str);
908 if (NULL != typestring)
910 else
912 for (unsigned int i = 0; i < rd_len; i++)
913 {
914 if ((GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) &&
915 (0 != strcmp (rname, GNUNET_GNS_EMPTY_LABEL_AT)))
916 continue;
917 if ((type != rd[i].record_type) && (GNUNET_GNSRECORD_TYPE_ANY != type))
918 continue;
919 typestr = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type);
920 s = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
921 rd[i].data,
922 rd[i].data_size);
923 if (NULL == s)
924 {
925 fprintf (stdout,
926 _ ("\tCorrupt or unsupported record of type %u\n"),
927 (unsigned int) rd[i].record_type);
928 continue;
929 }
930 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
931 {
934 }
935 else
936 {
939 }
940 {
941 char flgstr[16];
942 sprintf (flgstr, "[%s%s%s%s%s]",
943 (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE) ? "" : "p",
944 (rd[i].flags & GNUNET_GNSRECORD_RF_SUPPLEMENTAL) ? "S" : "",
946 "",
947 (rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW) ? "S" : "",
948 (rd[i].flags & GNUNET_GNSRECORD_RF_CRITICAL) ? "C" : "");
950 fprintf (stdout,
951 " %s %" PRIu64 " %s %s\n",
952 typestr,
953 rd[i].expiration_time,
954 flgstr,
955 s);
956 else
957 fprintf (stdout,
958 "\t%s: %s (%s)\t%s\t%s\t%s\n",
959 typestr,
960 s,
961 ets,
962 (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)) ? "PRIVATE"
963 : "PUBLIC",
964 (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW)) ? "SHADOW"
965 : "",
967 "MAINTENANCE"
968 : "");
969 GNUNET_free (s);
970 }
971 }
972 // fprintf (stdout, "%s", "\n");
973}
974
975
976static void
978 const struct GNUNET_CRYPTO_BlindablePrivateKey *zone_key,
979 const char *rname,
980 unsigned int rd_len,
981 const struct GNUNET_GNSRECORD_Data *rd,
982 struct GNUNET_TIME_Absolute expiry)
983{
984 (void) cls;
985 (void) zone_key;
986 (void) expiry;
987 collect_zone_records_to_purge (zone_key, rname, rd_len, rd);
989}
990
991
992static void
994 const struct GNUNET_CRYPTO_BlindablePrivateKey *zone_key
995 ,
996 const char *rname,
997 unsigned int rd_len,
998 const struct GNUNET_GNSRECORD_Data *rd,
999 struct GNUNET_TIME_Absolute expiry)
1000{
1001 (void) cls;
1002 (void) zone_key;
1003 (void) expiry;
1004 collect_orphans (zone_key, rname, rd_len, rd);
1006}
1007
1008
1018static void
1021 zone_key,
1022 const char *rname,
1023 unsigned int rd_len,
1024 const struct GNUNET_GNSRECORD_Data *rd,
1025 struct GNUNET_TIME_Absolute expiry)
1026{
1027 (void) cls;
1028 (void) zone_key;
1029 (void) expiry;
1030 display_record (zone_key, rname, rd_len, rd);
1032}
1033
1034
1044static void
1046 const struct GNUNET_CRYPTO_BlindablePrivateKey *zone_key
1047 ,
1048 const char *rname,
1049 unsigned int rd_len,
1050 const struct GNUNET_GNSRECORD_Data *rd,
1051 struct GNUNET_TIME_Absolute expiry)
1052{
1053 (void) cls;
1054 (void) zone_key;
1055 (void) expiry;
1056 display_record (zone_key, rname, rd_len, rd);
1058}
1059
1060
1070static void
1072 const struct GNUNET_CRYPTO_BlindablePrivateKey *zone_key,
1073 const char *rname,
1074 unsigned int rd_len,
1075 const struct GNUNET_GNSRECORD_Data *rd)
1076{
1077 (void) cls;
1078 (void) zone_key;
1079 get_qe = NULL;
1080 display_record (zone_key, rname, rd_len, rd);
1081 finish_command ();
1082}
1083
1084
1090static void
1091sync_cb (void *cls)
1092{
1093 (void) cls;
1094 fprintf (stdout, "%s", "Monitor is now in sync.\n");
1095}
1096
1097
1103static void
1105{
1106 (void) cls;
1107 fprintf (stderr, "%s", "Monitor disconnected and out of sync.\n");
1108}
1109
1110
1116static void
1118{
1119 (void) cls;
1120 get_qe = NULL;
1121 fprintf (stderr, "%s", "Failed to lookup record.\n");
1122 finish_command ();
1123}
1124
1125
1129static void
1130add_error_cb (void *cls)
1131{
1132 (void) cls;
1133 add_qe = NULL;
1134 GNUNET_break (0);
1135 ret = 1;
1136 finish_command ();
1137}
1138
1139
1150static void
1152 const struct GNUNET_CRYPTO_BlindablePrivateKey *zone_key,
1153 const char *rec_name,
1154 unsigned int rd_count,
1155 const struct GNUNET_GNSRECORD_Data *rd)
1156{
1157 struct GNUNET_GNSRECORD_Data rdn[rd_count + 1];
1158 struct GNUNET_GNSRECORD_Data *rde;
1159
1160 (void) cls;
1161 (void) zone_key;
1162 add_qe = NULL;
1163 if (0 != strcmp (rec_name, name))
1164 {
1165 GNUNET_break (0);
1166 ret = 1;
1167 finish_command ();
1168 return;
1169 }
1170
1172 "Received %u records for name `%s'\n",
1173 rd_count,
1174 rec_name);
1175 for (unsigned int i = 0; i < rd_count; i++)
1176 {
1177 switch (rd[i].record_type)
1178 {
1181 {
1182 fprintf (
1183 stderr,
1184 _ (
1185 "A SOA record exists already under `%s', cannot add a second SOA to the same zone.\n"),
1186 rec_name);
1187 ret = 1;
1188 finish_command ();
1189 return;
1190 }
1191 break;
1192 }
1193 }
1194 memset (rdn, 0, sizeof(struct GNUNET_GNSRECORD_Data));
1195 GNUNET_memcpy (&rdn[1], rd, rd_count * sizeof(struct GNUNET_GNSRECORD_Data));
1196 rde = &rdn[0];
1197 rde->data = data;
1198 rde->data_size = data_size;
1199 rde->record_type = type;
1200 if (1 == is_shadow)
1202 if (1 == is_maintenance)
1204 if (1 != is_public)
1206 rde->expiration_time = etime;
1207 if (GNUNET_YES == etime_is_rel)
1209 else if (GNUNET_NO != etime_is_rel)
1211 GNUNET_assert (NULL != name);
1213 &zone_pkey,
1214 name,
1215 rd_count + 1,
1216 rde,
1218 &add_qe);
1219}
1220
1221
1225static void
1227{
1228 (void) cls;
1229 reverse_qe = NULL;
1230 fprintf (stdout, "%s.zkey\n", reverse_pkey);
1231}
1232
1233
1244static void
1246 const struct GNUNET_CRYPTO_BlindablePrivateKey *zone,
1247 const char *label,
1248 unsigned int rd_count,
1249 const struct GNUNET_GNSRECORD_Data *rd)
1250{
1251 (void) cls;
1252 (void) zone;
1253 (void) rd_count;
1254 (void) rd;
1255 reverse_qe = NULL;
1256 if (NULL == label)
1257 fprintf (stdout, "%s\n", reverse_pkey);
1258 else
1259 fprintf (stdout, "%s.%s\n", label, ego_name);
1260 finish_command ();
1261}
1262
1263
1267static void
1269{
1270 (void) cls;
1271 del_qe = NULL;
1272 GNUNET_break (0);
1273 ret = 1;
1274 finish_command ();
1275}
1276
1277
1289static void
1290del_monitor (void *cls,
1291 const struct GNUNET_CRYPTO_BlindablePrivateKey *zone,
1292 const char *label,
1293 unsigned int rd_count,
1294 const struct GNUNET_GNSRECORD_Data *rd)
1295{
1296 struct GNUNET_GNSRECORD_Data rdx[rd_count];
1297 unsigned int rd_left;
1298 uint32_t del_type;
1299 char *vs;
1300
1301 (void) cls;
1302 (void) zone;
1303 del_qe = NULL;
1304 if (0 == rd_count)
1305 {
1306 fprintf (stderr,
1307 _ (
1308 "There are no records under label `%s' that could be deleted.\n")
1309 ,
1310 label);
1311 ret = 1;
1312 finish_command ();
1313 return;
1314 }
1315 if ((NULL == value) && (NULL == typestring))
1316 {
1317 /* delete everything */
1319 &zone_pkey,
1320 name,
1321 0,
1322 NULL,
1324 NULL);
1325 return;
1326 }
1327 rd_left = 0;
1328 if (NULL != typestring)
1330 else
1331 del_type = GNUNET_GNSRECORD_TYPE_ANY;
1332 for (unsigned int i = 0; i < rd_count; i++)
1333 {
1334 vs = NULL;
1335 if (! (((GNUNET_GNSRECORD_TYPE_ANY == del_type) ||
1336 (rd[i].record_type == del_type)) &&
1337 ((NULL == value) ||
1338 (NULL ==
1340 rd[i].data,
1341 rd[i].data_size)))) ||
1342 (0 == strcmp (vs, value)))))
1343 rdx[rd_left++] = rd[i];
1344 GNUNET_free (vs);
1345 }
1346 if (rd_count == rd_left)
1347 {
1348 /* nothing got deleted */
1349 fprintf (
1350 stderr,
1351 _ (
1352 "There are no records under label `%s' that match the request for deletion.\n"),
1353 label);
1354 finish_command ();
1355 return;
1356 }
1357 /* delete everything but what we copied to 'rdx' */
1359 &zone_pkey,
1360 name,
1361 rd_left,
1362 rdx,
1364 NULL);
1365}
1366
1367
1368static void
1370{
1371 finish_command ();
1372}
1373
1374
1375static void
1376replace_cont (void *cls, enum GNUNET_ErrorCode ec)
1377{
1378 (void) cls;
1379
1380 set_qe = NULL;
1381 if (GNUNET_EC_NONE != ec)
1382 {
1384 _ ("%s\n"),
1386 ret = 1; /* fail from 'main' */
1387 }
1389}
1390
1391
1398static void
1400{
1401 unsigned int sent_here;
1402
1403 GNUNET_assert (0 != ri_count);
1405 &zone_pkey,
1406 ri_count - ri_sent,
1408 &sent_here,
1409 &replace_cont,
1410 NULL);
1411 ri_sent += sent_here;
1412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent %d/%d record infos\n", ri_sent,
1413 ri_count);
1414 if (ri_sent == ri_count)
1415 {
1416 for (int i = 0; i < ri_count; i++)
1417 {
1418 GNUNET_free (record_info[i].a_rd);
1419 record_info[i].a_rd = NULL;
1420 }
1421 ri_count = 0;
1422 ri_sent = 0;
1423 }
1424 return;
1425}
1426
1427
1434static void
1436{
1439
1440 if (omit_private)
1444 if (! (add | del | list | (NULL != nickstring) | (NULL != uri)
1445 | (NULL != reverse_pkey) | (NULL != recordset) | (monitor)
1447 {
1448 /* nothing more to be done */
1449 fprintf (stderr, _ ("No options given\n"));
1450 finish_command ();
1451 return;
1452 }
1453
1454 if (NULL != recordset)
1455 {
1456 /* replace entire record set */
1457 unsigned int rd_count;
1458 struct GNUNET_GNSRECORD_Data *rd_tmp;
1459
1460 /* FIXME: We could easily support append and delete with this as well */
1461 if (! add)
1462 {
1463 fprintf (stderr, _ ("Recordlines only work with option `%s'\n"),
1464 "-a");
1465 ret = 1;
1466 finish_command ();
1467 return;
1468 }
1469 if (NULL == name)
1470 {
1471 fprintf (stderr,
1472 _ ("Missing option `%s' for operation `%s'\n"),
1473 "-n",
1474 _ ("name"));
1475 ret = 1;
1476 finish_command ();
1477 return;
1478 }
1479 rd_count = 0;
1480 for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next)
1481 rd_count++;
1483 rd_count = 0;
1484 for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next)
1485 {
1486 rd_tmp[rd_count] = e->record;
1487 rd_count++;
1488 }
1490 &zone_pkey,
1491 name,
1492 rd_count,
1493 rd_tmp,
1494 &replace_cont,
1495 NULL);
1496 GNUNET_free (rd_tmp);
1497 return;
1498 }
1499 if (NULL != nickstring)
1500 {
1501 if (0 == strlen (nickstring))
1502 {
1503 fprintf (stderr, _ ("Invalid nick `%s'\n"), nickstring);
1504 ret = 1;
1505 finish_command ();
1506 return;
1507 }
1508 add = 1;
1513 is_public = 0;
1514 expirationstring = GNUNET_strdup ("never");
1516 nickstring = NULL;
1517 }
1518
1519 if (add)
1520 {
1521 if (NULL == ego_name)
1522 {
1523 fprintf (stderr,
1524 _ ("Missing option `%s' for operation `%s'\n"),
1525 "-z",
1526 _ ("add"));
1527 ret = 1;
1528 finish_command ();
1529 return;
1530 }
1531 if (NULL == name)
1532 {
1533 fprintf (stderr,
1534 _ ("Missing option `%s' for operation `%s'\n"),
1535 "-n",
1536 _ ("add"));
1537 ret = 1;
1538 finish_command ();
1539 return;
1540 }
1541 if (NULL == typestring)
1542 {
1543 fprintf (stderr,
1544 _ ("Missing option `%s' for operation `%s'\n"),
1545 "-t",
1546 _ ("add"));
1547 ret = 1;
1548 finish_command ();
1549 return;
1550 }
1552 if (UINT32_MAX == type)
1553 {
1554 fprintf (stderr, _ ("Unsupported type `%s'\n"), typestring);
1555 ret = 1;
1556 finish_command ();
1557 return;
1558 }
1563 {
1564 fprintf (stderr,
1565 _ (
1566 "For DNS record types `SRV', `TLSA', `SMIMEA' and `OPENPGPKEY'"));
1567 fprintf (stderr, ", please use a `BOX' record instead\n");
1568 ret = 1;
1569 finish_command ();
1570 return;
1571 }
1572 if (NULL == value)
1573 {
1574 fprintf (stderr,
1575 _ ("Missing option `%s' for operation `%s'\n"),
1576 "-V",
1577 _ ("add"));
1578 ret = 1;
1579 finish_command ();
1580 return;
1581 }
1582 if (GNUNET_OK !=
1584 {
1585 fprintf (stderr,
1586 _ ("Value `%s' invalid for record type `%s'\n"),
1587 value,
1588 typestring);
1589 ret = 1;
1590 finish_command ();
1591 return;
1592 }
1593 if (NULL == expirationstring)
1594 {
1595 fprintf (stderr,
1596 _ ("Missing option `%s' for operation `%s'\n"),
1597 "-e",
1598 _ ("add"));
1599 ret = 1;
1600 finish_command ();
1601 return;
1602 }
1604 {
1605 fprintf (stderr, _ ("Invalid time format `%s'\n"), expirationstring);
1606 ret = 1;
1607 finish_command ();
1608 return;
1609 }
1611 &zone_pkey,
1612 name,
1613 &add_error_cb,
1614 NULL,
1616 NULL);
1617 }
1618 if (del)
1619 {
1620 if (NULL == ego_name)
1621 {
1622 fprintf (stderr,
1623 _ ("Missing option `%s' for operation `%s'\n"),
1624 "-z",
1625 _ ("del"));
1626 ret = 1;
1627 finish_command ();
1628 return;
1629 }
1630 if (NULL == name)
1631 {
1632 fprintf (stderr,
1633 _ ("Missing option `%s' for operation `%s'\n"),
1634 "-n",
1635 _ ("del"));
1636 ret = 1;
1637 finish_command ();
1638 return;
1639 }
1641 &zone_pkey,
1642 name,
1644 NULL,
1645 &del_monitor,
1646 NULL,
1647 filter_flags);
1648 }
1649 if (purge_orphaned)
1650 {
1652 NULL,
1654 NULL,
1656 NULL,
1658 NULL,
1659 filter_flags);
1660
1661 }
1662 else if (purge_zone)
1663 {
1664 if (NULL == ego_name)
1665 {
1666 fprintf (stderr,
1667 _ ("Missing option `%s' for operation `%s'\n"),
1668 "-z",
1669 _ ("purge-zone"));
1670 ret = 1;
1671 finish_command ();
1672 return;
1673 }
1675 &zone_pkey,
1677 NULL,
1679 NULL,
1681 NULL,
1682 filter_flags);
1683
1684 }
1685 else if (list || list_orphaned)
1686 {
1687 if (NULL != name)
1688 {
1689 if (NULL == ego_name)
1690 {
1691 fprintf (stderr,
1692 _ ("Missing option `%s' for operation `%s'\n"),
1693 "-z",
1694 _ ("list"));
1695 ret = 1;
1696 finish_command ();
1697 return;
1698 }
1700 &zone_pkey,
1701 name,
1703 NULL,
1705 NULL);
1706 }
1707 else
1709 (NULL == ego_name) ?
1710 NULL : &zone_pkey,
1712 ,
1713 NULL,
1715 ,
1716 NULL,
1718 ,
1719 NULL,
1720 filter_flags);
1721 }
1722 if (NULL != reverse_pkey)
1723 {
1725
1726 if (NULL == ego_name)
1727 {
1728 fprintf (stderr,
1729 _ ("Missing option `%s' for operation `%s'\n"),
1730 "-z",
1731 _ ("reverse-pkey"));
1732 ret = 1;
1733 finish_command ();
1734 return;
1735 }
1736 if (GNUNET_OK !=
1738 &pubkey))
1739 {
1740 fprintf (stderr,
1741 _ ("Invalid public key for reverse lookup `%s'\n"),
1742 reverse_pkey);
1743 ret = 1;
1744 finish_command ();
1745 return;
1746 }
1748 &zone_pkey,
1749 &pubkey,
1751 NULL,
1753 NULL);
1754 }
1755 if (NULL != uri)
1756 {
1757 char sh[105];
1758 char sname[64];
1760 if (NULL == ego_name)
1761 {
1762 fprintf (stderr,
1763 _ ("Missing option `%s' for operation `%s'\n"),
1764 "-z",
1765 _ ("uri"));
1766 ret = 1;
1767 finish_command ();
1768 return;
1769 }
1770
1771 memset (sh, 0, 105);
1772 memset (sname, 0, 64);
1773
1774 if ((2 != (sscanf (uri, "gnunet://gns/%58s/%63s", sh, sname))) ||
1775 (GNUNET_OK !=
1777 {
1778 fprintf (stderr, _ ("Invalid URI `%s'\n"), uri);
1779 ret = 1;
1780 finish_command ();
1781 return;
1782 }
1783 if (NULL == expirationstring)
1784 {
1785 fprintf (stderr,
1786 _ ("Missing option `%s' for operation `%s'\n"),
1787 "-e",
1788 _ ("add"));
1789 ret = 1;
1790 finish_command ();
1791 return;
1792 }
1794 {
1795 fprintf (stderr, _ ("Invalid time format `%s'\n"), expirationstring);
1796 ret = 1;
1797 finish_command ();
1798 return;
1799 }
1800 memset (&rd, 0, sizeof(rd));
1801 rd.data = &pkey;
1803 rd.record_type = ntohl (pkey.type);
1805 if (GNUNET_YES == etime_is_rel)
1807 if (1 == is_shadow)
1809 if (1 == is_maintenance)
1812 &zone_pkey,
1813 sname,
1814 1,
1815 &rd,
1817 &add_qe_uri);
1818 }
1819 if (monitor)
1820 {
1822 (NULL != ego_name) ?
1823 &zone_pkey : NULL,
1824 GNUNET_YES,
1826 NULL,
1828 NULL,
1829 &sync_cb,
1830 NULL,
1831 filter_flags);
1832 }
1833}
1834
1835
1836#define MAX_LINE_LEN 4086
1837
1838#define MAX_ARGS 20
1839
1840static int
1843{
1844 const struct GNUNET_CRYPTO_BlindablePrivateKey *privkey;
1846 struct GNUNET_CRYPTO_BlindablePublicKey ego_pubkey;
1847 struct EgoEntry *ego_entry;
1848
1850 &pubkey))
1851 {
1852 for (ego_entry = ego_head;
1853 NULL != ego_entry; ego_entry = ego_entry->next)
1854 {
1855 privkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1856 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &ego_pubkey);
1857 if (0 == memcmp (&ego_pubkey, &pubkey, sizeof (pubkey)))
1858 {
1859 *zk = *privkey;
1860 return GNUNET_OK;
1861 }
1862 }
1863 }
1864 else
1865 {
1866 for (ego_entry = ego_head; NULL != ego_entry; ego_entry = ego_entry->next)
1867 {
1869 if (0 != strcmp (str, ego_entry->identifier))
1870 continue;
1871 *zk = *GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1872 return GNUNET_OK;
1873 }
1874 }
1875 return GNUNET_NO;
1876}
1877
1878
1879static void
1881{
1882 char buf[MAX_LINE_LEN];
1883 static struct GNUNET_CRYPTO_BlindablePrivateKey next_zone_key;
1884 static char next_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
1885 static int finished = GNUNET_NO;
1886 static int have_next_recordline = GNUNET_NO;
1887 int zonekey_set = GNUNET_NO;
1888 char *tmp;
1889 char *current_name = NULL;
1890
1891
1892 if (GNUNET_YES == have_next_recordline)
1893 {
1894 zone_pkey = next_zone_key;
1895 if (NULL != current_name)
1896 GNUNET_free (current_name);
1897 current_name = GNUNET_strdup (next_name);
1898 zonekey_set = GNUNET_YES;
1899 }
1900 while (NULL != fgets (buf, sizeof (buf), stdin))
1901 {
1902 if (1 >= strlen (buf))
1903 continue;
1904 if (buf[strlen (buf) - 1] == '\n')
1905 buf[strlen (buf) - 1] = '\0';
1909 if (buf[strlen (buf) - 1] == ':')
1910 {
1911 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Switching to %s\n", buf);
1912 memset (next_name, 0, sizeof (next_name));
1913 strncpy (next_name, buf, strlen (buf) - 1);
1914 tmp = strchr (next_name, '.');
1915 if (NULL == tmp)
1916 {
1917 fprintf (stderr, "Error parsing name `%s'\n", next_name);
1919 ret = 1;
1920 return;
1921 }
1922 if (GNUNET_OK != get_identity_for_string (tmp + 1, &next_zone_key))
1923 {
1924 fprintf (stderr, "Error parsing zone name `%s'\n", tmp + 1);
1925 ret = 1;
1927 return;
1928 }
1929 *tmp = '\0';
1930 have_next_recordline = GNUNET_YES;
1931 /* Run a command for the previous record set */
1932 if (NULL != recordset)
1933 {
1935 {
1940 "Recordinfo array grown to %u bytes!\n",
1942 }
1943 record_info[ri_count].a_label = GNUNET_strdup (current_name);
1944 {
1945 int rd_count = 0;
1946 for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next)
1947 rd_count++;
1949 struct
1951 rd_count = 0;
1952 for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next)
1953 {
1954 record_info[ri_count].a_rd[rd_count] = e->record;
1956 record.
1957 data_size);
1959 data_size;
1960 memcpy ((void*) record_info[ri_count].a_rd[rd_count].data,
1961 e->record.data, e->record.data_size);
1962 rd_count++;
1963 }
1965 ri_count++;
1967 "Added %d records to record info\n", rd_count);
1968 clear_recordset ();
1969 }
1970 /* If the zone has changed, insert */
1971 /* If we have reached batch size, insert */
1972 if (0 != GNUNET_memcmp (&next_zone_key, &zone_pkey) ||
1974 {
1975 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Batch inserting %d RI\n",
1976 ri_count);
1978 return;
1979 }
1980 }
1981 zone_pkey = next_zone_key;
1982 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Switching from %s to %s\n",
1983 current_name, next_name);
1984 if (NULL != current_name)
1985 GNUNET_free (current_name);
1986 current_name = GNUNET_strdup (next_name);
1987 zonekey_set = GNUNET_YES;
1988 continue;
1989 }
1990 if (GNUNET_NO == zonekey_set)
1991 {
1992 fprintf (stderr, "Warning, encountered recordline without zone\n");
1993 continue;
1994 }
1995 parse_recordline (buf);
1996 }
1997 if (GNUNET_NO == finished)
1998 {
1999 if (NULL != recordset)
2000 {
2001 if (GNUNET_YES == zonekey_set)
2002 {
2003 record_info[ri_count].a_label = GNUNET_strdup (current_name);
2004 {
2005 int rd_count = 0;
2006 for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next)
2007 rd_count++;
2009 struct
2011 rd_count = 0;
2012 for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next)
2013 {
2014 record_info[ri_count].a_rd[rd_count] = e->record;
2016 .
2017 data_size);
2018 record_info[ri_count].a_rd[rd_count].data_size = e->record.data_size
2019 ;
2020 memcpy ((void*) record_info[ri_count].a_rd[rd_count].data,
2021 e->record.data, e->record.data_size);
2022 rd_count++;
2023 }
2025 }
2026 ri_count++;
2029 return;
2030 }
2031 fprintf (stderr, "Warning, encountered recordline without zone\n");
2032 }
2033 }
2034 if (ri_sent < ri_count)
2035 {
2037 return;
2038 }
2040 return;
2041}
2042
2043
2056static void
2057id_connect_cb (void *cls,
2058 struct GNUNET_IDENTITY_Ego *ego,
2059 void **ctx,
2060 const char *ego_name_tmp)
2061{
2063 struct EgoEntry *ego_entry;
2064
2065 (void) ctx;
2066 (void) ego_name_tmp;
2067 if ((NULL != ego_name_tmp) && (NULL != ego))
2068 {
2069 ego_entry = GNUNET_new (struct EgoEntry);
2071 ego_entry->ego = ego;
2072 ego_entry->identifier = GNUNET_strdup (ego_name_tmp);
2074 ego_tail,
2075 ego_entry);
2076 if ((NULL != ego_name) && (NULL != ego_name_tmp) &&
2077 (0 == strcmp (ego_name, ego_name_tmp)))
2079 return;
2080 }
2081 if (NULL != ego)
2082 return;
2083 if (read_from_stdin)
2084 {
2086 return;
2087 }
2089}
2090
2091
2100static void
2101run (void *cls,
2102 char *const *args,
2103 const char *cfgfile,
2104 const struct GNUNET_CONFIGURATION_Handle *_cfg)
2105{
2106 (void) cls;
2107 (void) args;
2108 (void) cfgfile;
2109 cfg = _cfg;
2110 if (NULL != args[0])
2111 GNUNET_log (
2113 _ ("Superfluous command line arguments (starting with `%s') ignored\n"),
2114 args[0]);
2115
2118 if (NULL == ns)
2119 {
2120 fprintf (stderr, _ ("Failed to connect to namestore\n"));
2122 return;
2123 }
2125 if (NULL == idh)
2126 {
2127 ret = -1;
2128 fprintf (stderr, _ ("Cannot connect to identity service\n"));
2130 }
2131}
2132
2133
2141int
2142main (int argc, char *const *argv)
2143{
2144 int lret;
2146 { GNUNET_GETOPT_option_flag ('a', "add", gettext_noop ("add record"), &add),
2148 "delete",
2149 gettext_noop ("delete record"),
2150 &del),
2152 "display",
2153 gettext_noop ("display records"),
2154 &list),
2156 "from-stdin",
2157 gettext_noop ("read commands from stdin"),
2160 'e',
2161 "expiration",
2162 "TIME",
2163 gettext_noop (
2164 "expiration time for record to use (for adding only), \"never\" is possible"),
2167 "nick",
2168 "NICKNAME",
2169 gettext_noop (
2170 "set the desired nick name for the zone"),
2171 &nickstring),
2173 "monitor",
2174 gettext_noop (
2175 "monitor changes in the namestore"),
2176 &monitor),
2178 "name",
2179 "NAME",
2180 gettext_noop (
2181 "name of the record to add/delete/display"),
2182 &name),
2184 "recordline",
2185 gettext_noop ("Output in recordline format"),
2188 "zone-to-name",
2189 "KEY",
2190 gettext_noop (
2191 "determine our name for the given KEY"),
2192 &reverse_pkey),
2194 "type",
2195 "TYPE",
2196 gettext_noop (
2197 "type of the record to add/delete/display"),
2198 &typestring),
2200 "uri",
2201 "URI",
2202 gettext_noop ("URI to import into our zone"),
2203 &uri),
2205 "value",
2206 "VALUE",
2207 gettext_noop (
2208 "value of the record to add/delete"),
2209 &value),
2211 "public",
2212 gettext_noop ("create or list public record"),
2213 &is_public),
2215 "omit-private",
2216 gettext_noop ("omit private records"),
2217 &omit_private),
2219 "include-maintenance",
2220 gettext_noop (
2221 "do not filter maintenance records"),
2224 "purge-orphans",
2225 gettext_noop (
2226 "purge namestore of all orphans"),
2229 "list-orphans",
2230 gettext_noop (
2231 "show private key for orphaned records for recovery using `gnunet-identity -C -P <key>'. Use in combination with --display"),
2232 &list_orphaned),
2234 "purge-zone-records",
2235 gettext_noop (
2236 "delete all records in specified zone"),
2237 &purge_zone),
2239 "batch-size",
2240 "NUMBER",
2241 gettext_noop (
2242 "number of records to buffer and send as batch (for use with --from-stdin)"),
2245 's',
2246 "shadow",
2247 gettext_noop (
2248 "create shadow record (only valid if all other records of the same type have expired)"),
2249 &is_shadow),
2251 'M',
2252 "maintenance",
2253 gettext_noop (
2254 "create maintenance record (e.g TOMBSTONEs)"),
2257 "zone",
2258 "EGO",
2259 gettext_noop (
2260 "name of the ego controlling the zone"),
2261 &ego_name),
2263
2264
2265 is_public = -1;
2266 is_shadow = -1;
2267 is_maintenance = -1;
2268 GNUNET_log_setup ("gnunet-namestore", "WARNING", NULL);
2269 if (GNUNET_OK !=
2271 argc,
2272 argv,
2273 "gnunet-namestore",
2274 _ ("GNUnet zone manipulation tool"),
2275 options,
2276 &run,
2277 NULL)))
2278 {
2279 // FIXME
2280 // GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey);
2281 return lret;
2282 }
2283 // FIXME
2284 // GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey);
2285 return ret;
2286}
2287
2288
2289/* end of gnunet-namestore.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
int main()
Program to simulate results from GCP_get_desirability_of_path() for various plausible inputs.
#define gettext_noop(String)
Definition gettext.h:74
#define GNUNET_GNSRECORD_TYPE_NICK
GNS zone nickname.
static int do_shutdown
Set to GNUNET_YES if we are shutting down.
static bool finished
Set to true once we are finished and should exit after sending our final message to the parent.
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
static char * line
Desired phone line (string to be converted to a hash).
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
static struct GNUNET_FS_Handle * ctx
static struct GNUNET_IDENTITY_Handle * sh
Handle to IDENTITY service.
struct GNUNET_CRYPTO_BlindablePrivateKey pk
Private key from command line option, or NULL.
static struct GNUNET_CRYPTO_BlindablePublicKey pubkey
Public key of the zone to look in.
static char * pkey
Public key of the zone to look in, in ASCII.
static unsigned int rd_count
Number of records for currently parsed set.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
static struct EgoEntry * ego_tail
Ego list.
static struct GNUNET_NAMESTORE_QueueEntry * ns_qe
Queue entry for begin/commit.
#define MAX_LINE_LEN
static struct GNUNET_CRYPTO_BlindablePrivateKey zone_pkey
Private key for the our zone.
static int output_recordline
Output in recordline format.
static int omit_private
Filter private records.
static void zone_iteration_finished(void *cls)
Function called when we are done with a zone iteration.
static void replace_cont(void *cls, enum GNUNET_ErrorCode ec)
static void sync_cb(void *cls)
Function called once we are in sync in monitor mode.
static struct GNUNET_NAMESTORE_QueueEntry * get_qe
Queue entry for the 'lookup' operation.
static void del_lookup_error_cb(void *cls)
Function called if lookup for deletion fails.
static struct GNUNET_NAMESTORE_ZoneMonitor * zm
Monitor handle.
static void run_with_zone_pkey(const struct GNUNET_CONFIGURATION_Handle *cfg_)
We have obtained the zone's private key, so now process the main commands using it.
static int parse_recordline(const char *line)
static void del_monitor(void *cls, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
We were asked to delete something; this function is called with the existing records.
static void del_continuation(void *cls, enum GNUNET_ErrorCode ec)
static void get_existing_record(void *cls, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone_key, const char *rec_name, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
We're storing a record; this function is given the existing record so that we can merge the informati...
static int list_orphaned
List records and zone keys of orphaned records.
#define WARN_RELATIVE_EXPIRATION_LIMIT
The upper bound for the zone iteration interval (per record).
static void purge_next_record(void *cls)
static int purge_orphaned
Purge orphaned records.
static struct GNUNET_NAMESTORE_QueueEntry * add_qe
Queue entry for the 'add' operation.
static void display_record_lookup(void *cls, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd)
Process a record that was stored in the namestore.
static void display_record_monitor(void *cls, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd, struct GNUNET_TIME_Absolute expiry)
Process a record that was stored in the namestore.
static void id_connect_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *ego_name_tmp)
Function called with ALL of the egos known to the identity service, used on startup if the user did n...
static char * nickstring
Desired nick name.
static int monitor
Enables monitor mode.
static char * value
Value of the record to add/remove.
static int list
Desired action is to list records.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration handle.
static struct GNUNET_NAMESTORE_QueueEntry * del_qe
Queue entry for the 'del' operation.
static void batch_insert_recordinfo(const struct GNUNET_CONFIGURATION_Handle *cfg)
We have obtained the zone's private key, so now process the main commands using it.
static int purge_zone
Purge zone contents.
static char * name
Name of the records to add/list/remove.
static int include_maintenance
Do not filter maintenance records.
static struct GNUNET_NAMESTORE_QueueEntry * set_qe
Queue entry for the 'set/replace' operation.
static void collect_zone_records_to_purge(const struct GNUNET_CRYPTO_BlindablePrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd)
static int ret
Global return value.
static void reset_handles(void)
static unsigned int max_batch_size
static void * data
Value in binary format.
static void lookup_error_cb(void *cls)
Function called on errors while monitoring.
static void clear_recordset()
static void display_record(const struct GNUNET_CRYPTO_BlindablePrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd)
Process a record that was stored in the namestore.
static struct GNUNET_IDENTITY_Handle * idh
Identity service handle.
static void handle_reverse_lookup(void *cls, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Function called with the result of our attempt to obtain a name for a given public key.
static struct RecordSetEntry * recordset
Entry in record set for processing records in bulk.
static char * ego_name
Name of the ego controlling the zone.
static void reverse_error_cb(void *cls)
Function called if we encountered an error in zone-to-name.
static struct MarkedRecord * marked_head
Marked record list.
static void purge_zone_iterator(void *cls, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd, struct GNUNET_TIME_Absolute expiry)
static void display_record_iterator(void *cls, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd, struct GNUNET_TIME_Absolute expiry)
Process a record that was stored in the namestore.
static struct EgoEntry * ego_head
Ego list.
static int parse_expiration(const char *exp_str, int *is_rel, uint64_t *exptime)
Parse expiration time.
static int is_shadow
Is record a shadow record (GNUNET_GNSRECORD_RF_SHADOW)
static void add_continuation(void *cls, enum GNUNET_ErrorCode ec)
static struct GNUNET_SCHEDULER_Task * purge_task
Purge task.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *_cfg)
Main function that will be run.
static unsigned int ri_sent
static void finish_command(void)
static int del
Desired action is to remove a record.
static int etime_is_rel
Is expiration time relative or absolute time?
static void add_error_cb(void *cls)
Function called if lookup fails.
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
static void marked_deleted(void *cls, enum GNUNET_ErrorCode ec)
static struct GNUNET_NAMESTORE_ZoneIterator * list_it
List iterator for the 'list' operation.
static int is_maintenance
Is record a maintenance record (GNUNET_GNSRECORD_RF_MAINTENANCE)
static struct MarkedRecord * marked_tail
Marked record list.
static void monitor_error_cb(void *cls)
Function called on errors while monitoring.
static int read_from_stdin
Run in read from stdin mode.
static void process_command_stdin(void)
static void collect_orphans(const struct GNUNET_CRYPTO_BlindablePrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd)
static uint32_t type
Type string converted to DNS type value.
static size_t data_size
Number of bytes in data.
static void purge_orphans_iterator(void *cls, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd, struct GNUNET_TIME_Absolute expiry)
static char * expirationstring
Desired expiration time.
static unsigned int record_info_capacity
Maximum capacity of record_info array.
static struct GNUNET_NAMESTORE_RecordInfo * record_info
static struct GNUNET_NAMESTORE_QueueEntry * add_qe_uri
Queue entry for the 'add-uri' operation.
static void schedule_finish(void *cls)
static int get_identity_for_string(const char *str, struct GNUNET_CRYPTO_BlindablePrivateKey *zk)
static int add
Desired action is to add a record.
static struct GNUNET_NAMESTORE_QueueEntry * reverse_qe
Queue entry for the 'reverse lookup' operation (in combination with a name).
static void zone_iteration_error_cb(void *cls)
Function called when we encountered an error in a zone iteration.
static char * typestring
Type of the record to add/remove, NULL to remove all.
static char * uri
URI to import.
static uint64_t etime
Expiration string converted to numeric value.
static char * reverse_pkey
Reverse lookup to perform.
static unsigned int ri_count
static int is_public
Is record public (opposite of GNUNET_GNSRECORD_RF_PRIVATE)
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
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_NONE
No error (success).
@ GNUNET_EC_NAMESTORE_RECORD_EXISTS
Record already exists.
@ GNUNET_EC_NAMESTORE_RECORD_NOT_FOUND
Record not found.
API to the GNS service.
API that can be used to manipulate GNS record data.
Identity service; implements identity management for GNUnet.
API that can be used to store naming information on a GNUnet node;.
#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.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_DNSPARSER_TYPE_OPENPGPKEY
#define GNUNET_DNSPARSER_TYPE_TLSA
#define GNUNET_DNSPARSER_TYPE_SRV
#define GNUNET_DNSPARSER_TYPE_SOA
#define GNUNET_DNSPARSER_TYPE_SMIMEA
#define GNUNET_DNSPARSER_MAX_NAME_LENGTH
Maximum length of a name in DNS.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint(char shortName, const char *name, const char *argumentHelp, const char *description, unsigned int *val)
Allow user to specify an unsigned int.
#define GNUNET_GETOPT_OPTION_END
Marker for the end of the list of options.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
const char * GNUNET_GNSRECORD_number_to_typename(uint32_t type)
Convert a type number to the corresponding type string (e.g.
Definition gnsrecord.c:219
uint32_t GNUNET_GNSRECORD_typename_to_number(const char *dns_typename)
Convert a type name (e.g.
Definition gnsrecord.c:192
int GNUNET_GNSRECORD_string_to_value(uint32_t type, const char *s, void **data, size_t *data_size)
Convert human-readable version of the value s of a record of type type to the respective binary repre...
Definition gnsrecord.c:169
#define GNUNET_GNS_EMPTY_LABEL_AT
String we use to indicate an empty label (top-level entry in the zone).
GNUNET_GNSRECORD_Filter
Filter for GNUNET_GNSRECORD_normalize_record_set().
#define GNUNET_GNSRECORD_TYPE_ANY
Record type indicating any record/'*'.
char * GNUNET_GNSRECORD_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the binary value data of a record of type type to a human-readable string.
Definition gnsrecord.c:147
@ GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION
This expiration time of the record is a relative time (not an absolute time).
@ GNUNET_GNSRECORD_RF_CRITICAL
This record is critical.
@ GNUNET_GNSRECORD_RF_SUPPLEMENTAL
This is a supplemental record.
@ GNUNET_GNSRECORD_RF_MAINTENANCE
Maintenance records.
@ GNUNET_GNSRECORD_RF_SHADOW
This record should not be used unless all (other) records in the set with an absolute expiration time...
@ GNUNET_GNSRECORD_RF_PRIVATE
This is a private record of this peer and it should thus not be published.
@ GNUNET_GNSRECORD_RF_NONE
Entry for no flags / cleared flags.
@ GNUNET_GNSRECORD_FILTER_NONE
No filter flags set.
@ GNUNET_GNSRECORD_FILTER_INCLUDE_MAINTENANCE
Include maintenance records (TOMBSTONE etc).
@ GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE
Filter private records.
void GNUNET_IDENTITY_ego_get_public_key(struct GNUNET_IDENTITY_Ego *ego, struct GNUNET_CRYPTO_BlindablePublicKey *pk)
Get the identifier (public key) of an ego.
struct GNUNET_IDENTITY_Handle * GNUNET_IDENTITY_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_IDENTITY_Callback cb, void *cb_cls)
Connect to the identity service.
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
const struct GNUNET_CRYPTO_BlindablePrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
ssize_t GNUNET_CRYPTO_public_key_get_length(const struct GNUNET_CRYPTO_BlindablePublicKey *key)
Get the compacted length of a GNUNET_CRYPTO_BlindablePublicKey.
Definition crypto_pkey.c:85
#define GNUNET_log(kind,...)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_blindable_public_key_from_string(const char *str, struct GNUNET_CRYPTO_BlindablePublicKey *key)
Parses a (Base32) string representation of the public key.
char * GNUNET_CRYPTO_blindable_private_key_to_string(const struct GNUNET_CRYPTO_BlindablePrivateKey *key)
Creates a (Base32) string representation of the private key.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ 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.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_MESSAGE
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_BlindablePrivateKey *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_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_BlindablePrivateKey *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.
struct GNUNET_NAMESTORE_ZoneMonitor * GNUNET_NAMESTORE_zone_monitor_start2(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, int iterate_first, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordSetMonitor monitor, void *monitor_cls, GNUNET_SCHEDULER_TaskCallback sync_cb, void *sync_cb_cls, enum GNUNET_GNSRECORD_Filter filter)
Begin monitoring a zone for changes.
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_zone_to_name(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, const struct GNUNET_CRYPTO_BlindablePublicKey *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.
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.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_lookup2(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_BlindablePrivateKey *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.
void GNUNET_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe)
Cancel a namestore operation.
void GNUNET_NAMESTORE_zone_monitor_stop(struct GNUNET_NAMESTORE_ZoneMonitor *zm)
Stop monitoring a zone for changes.
struct GNUNET_NAMESTORE_ZoneIterator * GNUNET_NAMESTORE_zone_iteration_start2(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_BlindablePrivateKey *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_BlindablePrivateKey *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.
void GNUNET_NAMESTORE_zone_monitor_next(struct GNUNET_NAMESTORE_ZoneMonitor *zm, uint64_t limit)
Calls the monitor processor specified in GNUNET_NAMESTORE_zone_monitor_start for the next record(s).
struct GNUNET_NAMESTORE_Handle * GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namestore service.
void GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it)
Stops iteration and releases the namestore handle for further calls.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition program.c:407
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition scheduler.c:567
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition scheduler.c:1339
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:980
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition scheduler.c:1304
enum GNUNET_GenericReturnValue GNUNET_STRINGS_fancy_time_to_relative(const char *fancy_time, struct GNUNET_TIME_Relative *rtime)
Convert a given fancy human-readable time to our internal representation.
Definition strings.c:259
#define GNUNET_TIME_relative_cmp(t1, op, t2)
Compare two relative times.
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:599
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition strings.c:660
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
enum GNUNET_GenericReturnValue GNUNET_STRINGS_fancy_time_to_absolute(const char *fancy_time, struct GNUNET_TIME_Absolute *atime)
Convert a given fancy human-readable time to our internal representation.
Definition strings.c:303
#define _(String)
GNU gettext support macro.
Definition platform.h:179
The default namestore ego.
char * identifier
Ego Identifier.
struct EgoEntry * prev
DLL.
struct EgoEntry * next
DLL.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
Definition of a command line option.
uint32_t record_type
Type of the GNS/DNS record.
const void * data
Binary value stored in the DNS record.
size_t data_size
Number of bytes in data.
enum GNUNET_GNSRECORD_Flags flags
Flags for the record.
uint64_t expiration_time
Expiration time for the DNS record.
Handle for an ego.
Definition identity.h:37
Handle for the service.
Connection to the NAMESTORE service.
An QueueEntry used to store information for a pending NAMESTORE record operation.
A struct for record bulk import.
struct GNUNET_GNSRECORD_Data * a_rd
Handle for a zone iterator operation.
Handle for a monitoring activity.
Entry in list of pending tasks.
Definition scheduler.c:136
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
The record marked for deletion.
struct GNUNET_CRYPTO_BlindablePrivateKey key
The zone key.
struct MarkedRecord * next
DLL.
char * name
Ego Identifier.
struct MarkedRecord * prev
DLL.
Entry in record set for bulk processing.
struct GNUNET_GNSRECORD_Data record
The record to add/remove.
struct RecordSetEntry * next
Kept in a linked list.
const char * str
Definition time.c:1252