GNUnet  0.11.x
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_util_lib.h>
30 #include <gnunet_dnsparser_lib.h>
32 #include <gnunet_gnsrecord_lib.h>
33 #include <gnunet_gns_service.h>
35 
36 
41 {
46 
51 };
52 
53 
57 static struct GNUNET_NAMESTORE_Handle *ns;
58 
63 
68 
72 static struct GNUNET_IDENTITY_Handle *idh;
73 
78 
82 static char *ego_name;
83 
87 static int add;
88 
93 
98 
103 
108 
112 static int list;
113 
118 
122 static int del;
123 
127 static int is_public;
128 
132 static int is_shadow;
133 
138 
143 
147 static char *name;
148 
152 static char *value;
153 
157 static char *uri;
158 
162 static char *reverse_pkey;
163 
167 static char *typestring;
168 
172 static char *expirationstring;
173 
177 static char *nickstring;
178 
182 static int ret;
183 
187 static uint32_t type;
188 
192 static void *data;
193 
197 static size_t data_size;
198 
202 static uint64_t etime;
203 
208 
213 
217 static int monitor;
218 
222 static struct RecordSetEntry *recordset;
223 
224 
230 static void
231 do_shutdown (void *cls)
232 {
233  (void) cls;
234  if (NULL != get_default)
235  {
236  GNUNET_IDENTITY_cancel (get_default);
237  get_default = NULL;
238  }
239  if (NULL != idh)
240  {
242  idh = NULL;
243  }
244  if (NULL != el)
245  {
247  el = NULL;
248  }
249  if (NULL != list_it)
250  {
252  list_it = NULL;
253  }
254  if (NULL != add_qe)
255  {
256  GNUNET_NAMESTORE_cancel (add_qe);
257  add_qe = NULL;
258  }
259  if (NULL != set_qe)
260  {
261  GNUNET_NAMESTORE_cancel (set_qe);
262  set_qe = NULL;
263  }
264  if (NULL != add_qe_uri)
265  {
266  GNUNET_NAMESTORE_cancel (add_qe_uri);
267  add_qe_uri = NULL;
268  }
269  if (NULL != get_qe)
270  {
271  GNUNET_NAMESTORE_cancel (get_qe);
272  get_qe = NULL;
273  }
274  if (NULL != del_qe)
275  {
276  GNUNET_NAMESTORE_cancel (del_qe);
277  del_qe = NULL;
278  }
279  if (NULL != ns)
280  {
282  ns = NULL;
283  }
284  memset (&zone_pkey, 0, sizeof(zone_pkey));
285  if (NULL != uri)
286  {
287  GNUNET_free (uri);
288  uri = NULL;
289  }
290  if (NULL != zm)
291  {
293  zm = NULL;
294  }
295  if (NULL != data)
296  {
297  GNUNET_free (data);
298  data = NULL;
299  }
300 }
301 
302 
306 static void
308 {
309  if ((NULL == add_qe) && (NULL == add_qe_uri) && (NULL == get_qe) &&
310  (NULL == del_qe) && (NULL == reverse_qe) && (NULL == list_it))
312 }
313 
314 
325 static void
326 add_continuation (void *cls, int32_t success, const char *emsg)
327 {
328  struct GNUNET_NAMESTORE_QueueEntry **qe = cls;
329 
330  *qe = NULL;
331  if (GNUNET_YES != success)
332  {
333  fprintf (stderr,
334  _ ("Adding record failed: %s\n"),
335  (GNUNET_NO == success) ? "record exists" : emsg);
336  if (GNUNET_NO != success)
337  ret = 1;
338  }
339  ret = 0;
340  test_finished ();
341 }
342 
343 
354 static void
355 del_continuation (void *cls, int32_t success, const char *emsg)
356 {
357  (void) cls;
358  del_qe = NULL;
359  if (GNUNET_NO == success)
360  {
361  fprintf (stderr,
362  _ ("Deleting record failed, record does not exist%s%s\n"),
363  (NULL != emsg) ? ": " : "",
364  (NULL != emsg) ? emsg : "");
365  }
366  if (GNUNET_SYSERR == success)
367  {
368  fprintf (stderr,
369  _ ("Deleting record failed%s%s\n"),
370  (NULL != emsg) ? ": " : "",
371  (NULL != emsg) ? emsg : "");
372  }
373  test_finished ();
374 }
375 
376 
380 static void
382 {
383  (void) cls;
384  list_it = NULL;
385  test_finished ();
386 }
387 
388 
392 static void
394 {
395  (void) cls;
396  list_it = NULL;
397  fprintf (stderr, "Error iterating over zone\n");
398  ret = 1;
399  test_finished ();
400 }
401 
402 
410 static void
411 display_record (const char *rname,
412  unsigned int rd_len,
413  const struct GNUNET_GNSRECORD_Data *rd)
414 {
415  const char *typestr;
416  char *s;
417  const char *ets;
418  struct GNUNET_TIME_Absolute at;
419  struct GNUNET_TIME_Relative rt;
420  int have_record;
421 
422  if ((NULL != name) && (0 != strcmp (name, rname)))
423  {
425  return;
426  }
427  have_record = GNUNET_NO;
428  for (unsigned int i = 0; i < rd_len; i++)
429  {
430  if ((GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) &&
431  (0 != strcmp (rname, GNUNET_GNS_EMPTY_LABEL_AT)))
432  continue;
433  if ((type != rd[i].record_type) && (GNUNET_GNSRECORD_TYPE_ANY != type))
434  continue;
435  have_record = GNUNET_YES;
436  break;
437  }
438  if (GNUNET_NO == have_record)
439  return;
440  fprintf (stdout, "%s:\n", rname);
441  if (NULL != typestring)
443  else
445  for (unsigned int i = 0; i < rd_len; i++)
446  {
447  if ((GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) &&
448  (0 != strcmp (rname, GNUNET_GNS_EMPTY_LABEL_AT)))
449  continue;
450  if ((type != rd[i].record_type) && (GNUNET_GNSRECORD_TYPE_ANY != type))
451  continue;
452  typestr = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type);
453  s = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
454  rd[i].data,
455  rd[i].data_size);
456  if (NULL == s)
457  {
458  fprintf (stdout,
459  _ ("\tCorrupt or unsupported record of type %u\n"),
460  (unsigned int) rd[i].record_type);
461  continue;
462  }
463  if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
464  {
465  rt.rel_value_us = rd[i].expiration_time;
467  }
468  else
469  {
470  at.abs_value_us = rd[i].expiration_time;
472  }
473  fprintf (stdout,
474  "\t%s: %s (%s)\t%s\t%s\n",
475  typestr,
476  s,
477  ets,
478  (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)) ? "PRIVATE"
479  : "PUBLIC",
480  (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)) ? "SHADOW"
481  : "");
482  GNUNET_free (s);
483  }
484  fprintf (stdout, "%s", "\n");
485 }
486 
487 
497 static void
499  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
500  const char *rname,
501  unsigned int rd_len,
502  const struct GNUNET_GNSRECORD_Data *rd)
503 {
504  (void) cls;
505  (void) zone_key;
506  display_record (rname, rd_len, rd);
508 }
509 
510 
520 static void
522  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
523  const char *rname,
524  unsigned int rd_len,
525  const struct GNUNET_GNSRECORD_Data *rd)
526 {
527  (void) cls;
528  (void) zone_key;
529  display_record (rname, rd_len, rd);
531 }
532 
533 
543 static void
545  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
546  const char *rname,
547  unsigned int rd_len,
548  const struct GNUNET_GNSRECORD_Data *rd)
549 {
550  (void) cls;
551  (void) zone_key;
552  get_qe = NULL;
553  display_record (rname, rd_len, rd);
554  test_finished ();
555 }
556 
557 
563 static void
564 sync_cb (void *cls)
565 {
566  (void) cls;
567  fprintf (stdout, "%s", "Monitor is now in sync.\n");
568 }
569 
570 
576 static void
577 monitor_error_cb (void *cls)
578 {
579  (void) cls;
580  fprintf (stderr, "%s", "Monitor disconnected and out of sync.\n");
581 }
582 
583 
589 static void
590 lookup_error_cb (void *cls)
591 {
592  (void) cls;
593  get_qe = NULL;
594  fprintf (stderr, "%s", "Failed to lookup record.\n");
595  test_finished ();
596 }
597 
598 
602 static void
603 add_error_cb (void *cls)
604 {
605  (void) cls;
606  add_qe = NULL;
607  GNUNET_break (0);
608  ret = 1;
609  test_finished ();
610 }
611 
612 
623 static void
625  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
626  const char *rec_name,
627  unsigned int rd_count,
628  const struct GNUNET_GNSRECORD_Data *rd)
629 {
630  struct GNUNET_GNSRECORD_Data rdn[rd_count + 1];
631  struct GNUNET_GNSRECORD_Data *rde;
632 
633  (void) cls;
634  (void) zone_key;
635  add_qe = NULL;
636  if (0 != strcmp (rec_name, name))
637  {
638  GNUNET_break (0);
639  ret = 1;
640  test_finished ();
641  return;
642  }
643 
645  "Received %u records for name `%s'\n",
646  rd_count,
647  rec_name);
648  for (unsigned int i = 0; i < rd_count; i++)
649  {
650  switch (rd[i].record_type)
651  {
653  fprintf (
654  stderr,
655  _ (
656  "A %s record exists already under `%s', no other records can be added.\n"),
657  "CNAME",
658  rec_name);
659  ret = 1;
660  test_finished ();
661  return;
662 
664  fprintf (
665  stderr,
666  _ (
667  "A %s record exists already under `%s', no other records can be added.\n"),
668  "PKEY",
669  rec_name);
670  ret = 1;
671  test_finished ();
672  return;
673 
676  {
677  fprintf (
678  stderr,
679  _ (
680  "A SOA record exists already under `%s', cannot add a second SOA to the same zone.\n"),
681  rec_name);
682  ret = 1;
683  test_finished ();
684  return;
685  }
686  break;
687  }
688  }
689  switch (type)
690  {
692  if (0 != rd_count)
693  {
694  fprintf (stderr,
695  _ (
696  "Records already exist under `%s', cannot add `%s' record.\n"),
697  rec_name,
698  "CNAME");
699  ret = 1;
700  test_finished ();
701  return;
702  }
703  break;
704 
706  if (0 != rd_count)
707  {
708  fprintf (stderr,
709  _ (
710  "Records already exist under `%s', cannot add `%s' record.\n"),
711  rec_name,
712  "PKEY");
713  ret = 1;
714  test_finished ();
715  return;
716  }
717  break;
718 
720  for (unsigned int i = 0; i < rd_count; i++)
722  {
723  fprintf (
724  stderr,
725  _ (
726  "Non-GNS2DNS records already exist under `%s', cannot add GNS2DNS record.\n"),
727  rec_name);
728  ret = 1;
729  test_finished ();
730  return;
731  }
732  break;
733  }
734  memset (rdn, 0, sizeof(struct GNUNET_GNSRECORD_Data));
735  GNUNET_memcpy (&rdn[1], rd, rd_count * sizeof(struct GNUNET_GNSRECORD_Data));
736  rde = &rdn[0];
737  rde->data = data;
738  rde->data_size = data_size;
739  rde->record_type = type;
740  if (1 == is_shadow)
742  if (1 != is_public)
744  rde->expiration_time = etime;
745  if (GNUNET_YES == etime_is_rel)
747  else if (GNUNET_NO != etime_is_rel)
748  rde->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
749  GNUNET_assert (NULL != name);
750  add_qe = GNUNET_NAMESTORE_records_store (ns,
751  &zone_pkey,
752  name,
753  rd_count + 1,
754  rde,
756  &add_qe);
757 }
758 
759 
763 static void
764 reverse_error_cb (void *cls)
765 {
766  (void) cls;
767  reverse_qe = NULL;
768  fprintf (stdout, "%s.zkey\n", reverse_pkey);
769 }
770 
771 
782 static void
784  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
785  const char *label,
786  unsigned int rd_count,
787  const struct GNUNET_GNSRECORD_Data *rd)
788 {
789  (void) cls;
790  (void) zone;
791  (void) rd_count;
792  (void) rd;
793  reverse_qe = NULL;
794  if (NULL == label)
795  fprintf (stdout, "%s\n", reverse_pkey);
796  else
797  fprintf (stdout, "%s.%s\n", label, ego_name);
798  test_finished ();
799 }
800 
801 
805 static void
807 {
808  (void) cls;
809  del_qe = NULL;
810  GNUNET_break (0);
811  ret = 1;
812  test_finished ();
813 }
814 
815 
827 static void
828 del_monitor (void *cls,
829  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
830  const char *label,
831  unsigned int rd_count,
832  const struct GNUNET_GNSRECORD_Data *rd)
833 {
834  struct GNUNET_GNSRECORD_Data rdx[rd_count];
835  unsigned int rd_left;
836  uint32_t type;
837  char *vs;
838 
839  (void) cls;
840  (void) zone;
841  del_qe = NULL;
842  if (0 == rd_count)
843  {
844  fprintf (stderr,
845  _ (
846  "There are no records under label `%s' that could be deleted.\n"),
847  label);
848  ret = 1;
849  test_finished ();
850  return;
851  }
852  if ((NULL == value) && (NULL == typestring))
853  {
854  /* delete everything */
855  del_qe = GNUNET_NAMESTORE_records_store (ns,
856  &zone_pkey,
857  name,
858  0,
859  NULL,
861  NULL);
862  return;
863  }
864  rd_left = 0;
865  if (NULL != typestring)
867  else
869  for (unsigned int i = 0; i < rd_count; i++)
870  {
871  vs = NULL;
872  if (! (((GNUNET_GNSRECORD_TYPE_ANY == type) ||
873  (rd[i].record_type == type)) &&
874  ((NULL == value) ||
875  (NULL ==
877  rd[i].data,
878  rd[i].data_size)))) ||
879  (0 == strcmp (vs, value)))))
880  rdx[rd_left++] = rd[i];
881  GNUNET_free (vs);
882  }
883  if (rd_count == rd_left)
884  {
885  /* nothing got deleted */
886  fprintf (
887  stderr,
888  _ (
889  "There are no records under label `%s' that match the request for deletion.\n"),
890  label);
891  test_finished ();
892  return;
893  }
894  /* delete everything but what we copied to 'rdx' */
895  del_qe = GNUNET_NAMESTORE_records_store (ns,
896  &zone_pkey,
897  name,
898  rd_left,
899  rdx,
901  NULL);
902 }
903 
904 
913 static int
915  int *etime_is_rel,
916  uint64_t *etime)
917 {
918  struct GNUNET_TIME_Relative etime_rel;
919  struct GNUNET_TIME_Absolute etime_abs;
920 
921  if (0 == strcmp (expirationstring, "never"))
922  {
923  *etime = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
924  *etime_is_rel = GNUNET_NO;
925  return GNUNET_OK;
926  }
927  if (GNUNET_OK ==
928  GNUNET_STRINGS_fancy_time_to_relative (expirationstring, &etime_rel))
929  {
930  *etime_is_rel = GNUNET_YES;
931  *etime = etime_rel.rel_value_us;
933  "Storing record with relative expiration time of %s\n",
935  return GNUNET_OK;
936  }
937  if (GNUNET_OK ==
938  GNUNET_STRINGS_fancy_time_to_absolute (expirationstring, &etime_abs))
939  {
940  *etime_is_rel = GNUNET_NO;
941  *etime = etime_abs.abs_value_us;
943  "Storing record with absolute expiration time of %s\n",
945  return GNUNET_OK;
946  }
947  return GNUNET_SYSERR;
948 }
949 
950 
961 static void
962 replace_cont (void *cls, int success, const char *emsg)
963 {
964  (void) cls;
965 
966  set_qe = NULL;
967  if (GNUNET_OK != success)
968  {
970  _ ("Failed to replace records: %s\n"),
971  emsg);
972  ret = 1; /* fail from 'main' */
973  }
975 }
976 
977 
984 static void
986 {
987  struct GNUNET_GNSRECORD_Data rd;
988 
989  if (! (add | del | list | (NULL != nickstring) | (NULL != uri)
990  | (NULL != reverse_pkey) | (NULL != recordset)))
991  {
992  /* nothing more to be done */
993  fprintf (stderr, _ ("No options given\n"));
995  return;
996  }
997  ns = GNUNET_NAMESTORE_connect (cfg);
998  if (NULL == ns)
999  {
1001  _ ("Failed to connect to namestore\n"));
1002  return;
1003  }
1004 
1005  if (NULL != recordset)
1006  {
1007  /* replace entire record set */
1008  unsigned int rd_count;
1009  struct GNUNET_GNSRECORD_Data *rd;
1010 
1011  if (NULL == name)
1012  {
1013  fprintf (stderr,
1014  _ ("Missing option `%s' for operation `%s'\n"),
1015  "-R",
1016  _ ("replace"));
1018  ret = 1;
1019  return;
1020  }
1021  rd_count = 0;
1022  for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next)
1023  rd_count++;
1024  rd = GNUNET_new_array (rd_count, struct GNUNET_GNSRECORD_Data);
1025  rd_count = 0;
1026  for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next)
1027  {
1028  rd[rd_count] = e->record;
1029  rd_count++;
1030  }
1031  set_qe = GNUNET_NAMESTORE_records_store (ns,
1032  &zone_pkey,
1033  name,
1034  rd_count,
1035  rd,
1036  &replace_cont,
1037  NULL);
1038  GNUNET_free (rd);
1039  return;
1040  }
1041  if (NULL != nickstring)
1042  {
1043  if (0 == strlen (nickstring))
1044  {
1045  fprintf (stderr, _ ("Invalid nick `%s'\n"), nickstring);
1047  ret = 1;
1048  return;
1049  }
1050  add = 1;
1055  is_public = 0;
1056  expirationstring = GNUNET_strdup ("never");
1058  nickstring = NULL;
1059  }
1060 
1061  if (add)
1062  {
1063  if (NULL == name)
1064  {
1065  fprintf (stderr,
1066  _ ("Missing option `%s' for operation `%s'\n"),
1067  "-n",
1068  _ ("add"));
1070  ret = 1;
1071  return;
1072  }
1073  if (NULL == typestring)
1074  {
1075  fprintf (stderr,
1076  _ ("Missing option `%s' for operation `%s'\n"),
1077  "-t",
1078  _ ("add"));
1080  ret = 1;
1081  return;
1082  }
1084  if (UINT32_MAX == type)
1085  {
1086  fprintf (stderr, _ ("Unsupported type `%s'\n"), typestring);
1088  ret = 1;
1089  return;
1090  }
1091  if ((GNUNET_DNSPARSER_TYPE_SRV == type) ||
1094  {
1095  fprintf (stderr,
1096  _ ("For DNS record types `SRV', `TLSA' and `OPENPGPKEY'"));
1097  fprintf (stderr, ", please use a `BOX' record instead\n");
1099  ret = 1;
1100  return;
1101  }
1102  if (NULL == value)
1103  {
1104  fprintf (stderr,
1105  _ ("Missing option `%s' for operation `%s'\n"),
1106  "-V",
1107  _ ("add"));
1108  ret = 1;
1110  return;
1111  }
1112  if (GNUNET_OK !=
1114  {
1115  fprintf (stderr,
1116  _ ("Value `%s' invalid for record type `%s'\n"),
1117  value,
1118  typestring);
1120  ret = 1;
1121  return;
1122  }
1123  if (NULL == expirationstring)
1124  {
1125  fprintf (stderr,
1126  _ ("Missing option `%s' for operation `%s'\n"),
1127  "-e",
1128  _ ("add"));
1130  ret = 1;
1131  return;
1132  }
1134  {
1135  fprintf (stderr, _ ("Invalid time format `%s'\n"), expirationstring);
1137  ret = 1;
1138  return;
1139  }
1140  add_qe = GNUNET_NAMESTORE_records_lookup (ns,
1141  &zone_pkey,
1142  name,
1143  &add_error_cb,
1144  NULL,
1146  NULL);
1147  }
1148  if (del)
1149  {
1150  if (NULL == name)
1151  {
1152  fprintf (stderr,
1153  _ ("Missing option `%s' for operation `%s'\n"),
1154  "-n",
1155  _ ("del"));
1157  ret = 1;
1158  return;
1159  }
1160  del_qe = GNUNET_NAMESTORE_records_lookup (ns,
1161  &zone_pkey,
1162  name,
1164  NULL,
1165  &del_monitor,
1166  NULL);
1167  }
1168  if (list)
1169  {
1170  if (NULL != name)
1171  get_qe = GNUNET_NAMESTORE_records_lookup (ns,
1172  &zone_pkey,
1173  name,
1174  &lookup_error_cb,
1175  NULL,
1177  NULL);
1178  else
1180  &zone_pkey,
1182  NULL,
1184  NULL,
1186  NULL);
1187  }
1188  if (NULL != reverse_pkey)
1189  {
1190  struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
1191 
1192  if (GNUNET_OK !=
1194  strlen (reverse_pkey),
1195  &pubkey))
1196  {
1197  fprintf (stderr,
1198  _ ("Invalid public key for reverse lookup `%s'\n"),
1199  reverse_pkey);
1201  }
1202  reverse_qe = GNUNET_NAMESTORE_zone_to_name (ns,
1203  &zone_pkey,
1204  &pubkey,
1206  NULL,
1208  NULL);
1209  }
1210  if (NULL != uri)
1211  {
1212  char sh[105];
1213  char sname[64];
1214  struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
1215 
1217  if ((2 != (sscanf (uri, "gnunet://gns/%52s/%63s", sh, sname))) ||
1218  (GNUNET_OK !=
1219  GNUNET_CRYPTO_ecdsa_public_key_from_string (sh, strlen (sh), &pkey)))
1220  {
1221  fprintf (stderr, _ ("Invalid URI `%s'\n"), uri);
1223  ret = 1;
1224  return;
1225  }
1226  if (NULL == expirationstring)
1227  {
1228  fprintf (stderr,
1229  _ ("Missing option `%s' for operation `%s'\n"),
1230  "-e",
1231  _ ("add"));
1233  ret = 1;
1234  return;
1235  }
1237  {
1238  fprintf (stderr, _ ("Invalid time format `%s'\n"), expirationstring);
1240  ret = 1;
1241  return;
1242  }
1243  memset (&rd, 0, sizeof(rd));
1244  rd.data = &pkey;
1245  rd.data_size = sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey);
1247  rd.expiration_time = etime;
1248  if (GNUNET_YES == etime_is_rel)
1250  if (1 == is_shadow)
1252  add_qe_uri = GNUNET_NAMESTORE_records_store (ns,
1253  &zone_pkey,
1254  sname,
1255  1,
1256  &rd,
1258  &add_qe_uri);
1259  }
1260  if (monitor)
1261  {
1263  &zone_pkey,
1264  GNUNET_YES,
1266  NULL,
1268  NULL,
1269  &sync_cb,
1270  NULL);
1271  }
1272 }
1273 
1274 
1282 static void
1283 identity_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
1284 {
1285  const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
1286 
1287  el = NULL;
1288  if ((NULL != name) && (0 != strchr (name, '.')))
1289  {
1290  fprintf (stderr,
1291  _ ("Label `%s' contains `.' which is not allowed\n"),
1292  name);
1294  ret = -1;
1295  return;
1296  }
1297 
1298  if (NULL == ego)
1299  {
1300  if (NULL != ego_name)
1301  {
1302  fprintf (stderr,
1303  _ ("Ego `%s' not known to identity service\n"),
1304  ego_name);
1305  }
1307  ret = -1;
1308  return;
1309  }
1312  ego_name = NULL;
1313  run_with_zone_pkey (cfg);
1314 }
1315 
1316 
1327 static void
1328 default_ego_cb (void *cls,
1329  struct GNUNET_IDENTITY_Ego *ego,
1330  void **ctx,
1331  const char *name)
1332 {
1333  const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
1334 
1335  (void) ctx;
1336  (void) name;
1337  get_default = NULL;
1338  if (NULL == ego)
1339  {
1340  fprintf (stderr,
1341  _ ("No default identity configured for `namestore' subsystem\n"
1342  "Run gnunet-identity -s namestore -e $NAME to set the default to $NAME\n"
1343  "Run gnunet-identity -d to get a list of choices for $NAME\n"));
1345  ret = -1;
1346  return;
1347  }
1348  else
1349  {
1350  identity_cb ((void *) cfg, ego);
1351  }
1352 }
1353 
1354 
1367 static void
1368 id_connect_cb (void *cls,
1369  struct GNUNET_IDENTITY_Ego *ego,
1370  void **ctx,
1371  const char *name)
1372 {
1373  const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
1374 
1375  (void) ctx;
1376  (void) name;
1377  if (NULL != ego)
1378  return;
1379  get_default =
1380  GNUNET_IDENTITY_get (idh, "namestore", &default_ego_cb, (void *) cfg);
1381 }
1382 
1383 
1392 static void
1393 run (void *cls,
1394  char *const *args,
1395  const char *cfgfile,
1396  const struct GNUNET_CONFIGURATION_Handle *cfg)
1397 {
1398  const char *pkey_str;
1399 
1400  (void) cls;
1401  (void) args;
1402  (void) cfgfile;
1403  if (NULL != args[0])
1404  GNUNET_log (
1406  _ ("Superfluous command line arguments (starting with `%s') ignored\n"),
1407  args[0]);
1408  if ((NULL != args[0]) && (NULL == uri))
1409  uri = GNUNET_strdup (args[0]);
1410 
1411  GNUNET_SCHEDULER_add_shutdown (&do_shutdown, (void *) cfg);
1412  pkey_str = getenv ("GNUNET_NAMESTORE_EGO_PRIVATE_KEY");
1413  if (NULL != pkey_str)
1414  {
1415  if (GNUNET_OK != GNUNET_STRINGS_string_to_data (pkey_str,
1416  strlen (pkey_str),
1417  &zone_pkey,
1418  sizeof(zone_pkey)))
1419  {
1420  fprintf (stderr,
1421  "Malformed private key `%s' in $%s\n",
1422  pkey_str,
1423  "GNUNET_NAMESTORE_EGO_PRIVATE_KEY");
1424  ret = 1;
1426  return;
1427  }
1428  run_with_zone_pkey (cfg);
1429  return;
1430  }
1431  if (NULL == ego_name)
1432  {
1433  idh = GNUNET_IDENTITY_connect (cfg, &id_connect_cb, (void *) cfg);
1434  if (NULL == idh)
1435  fprintf (stderr, _ ("Cannot connect to identity service\n"));
1436  ret = -1;
1437  return;
1438  }
1439  el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &identity_cb, (void *) cfg);
1440 }
1441 
1442 
1460 static int
1462  void *scls,
1463  const char *option,
1464  const char *value)
1465 {
1466  struct RecordSetEntry **head = scls;
1467  struct RecordSetEntry *r;
1468  struct GNUNET_GNSRECORD_Data record;
1469  char *cp;
1470  char *tok;
1471  char *saveptr;
1472  int etime_is_rel;
1473  void *raw_data;
1474 
1475  (void) ctx;
1476  (void) option;
1477  cp = GNUNET_strdup (value);
1478  tok = strtok_r (cp, " ", &saveptr);
1479  if (NULL == tok)
1480  {
1482  _ ("Empty record line argument is not allowed.\n"));
1483  GNUNET_free (cp);
1484  return GNUNET_SYSERR;
1485  }
1486  {
1487  char *etime_in_s;
1488 
1489  GNUNET_asprintf (&etime_in_s, "%s s", tok);
1490  if (GNUNET_OK !=
1491  parse_expiration (etime_in_s, &etime_is_rel, &record.expiration_time))
1492  {
1494  _ ("Invalid expiration time `%s' (must be without unit)\n"),
1495  tok);
1496  GNUNET_free (cp);
1497  GNUNET_free (etime_in_s);
1498  return GNUNET_SYSERR;
1499  }
1500  GNUNET_free (etime_in_s);
1501  }
1502  tok = strtok_r (NULL, " ", &saveptr);
1503  if (NULL == tok)
1504  {
1506  _ ("Missing entries in record line `%s'.\n"),
1507  value);
1508  GNUNET_free (cp);
1509  return GNUNET_SYSERR;
1510  }
1512  if (UINT32_MAX == record.record_type)
1513  {
1514  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Unknown record type `%s'\n"), tok);
1515  GNUNET_free (cp);
1516  return GNUNET_SYSERR;
1517  }
1518  tok = strtok_r (NULL, " ", &saveptr);
1519  if (NULL == tok)
1520  {
1522  _ ("Missing entries in record line `%s'.\n"),
1523  value);
1524  GNUNET_free (cp);
1525  return GNUNET_SYSERR;
1526  }
1528  if (etime_is_rel)
1530  if (NULL == strchr (tok, (unsigned char) 'p')) /* p = public */
1532  if (NULL != strchr (tok, (unsigned char) 's'))
1534  /* find beginning of record value */
1535  tok = strchr (&value[tok - cp], (unsigned char) ' ');
1536  if (NULL == tok)
1537  {
1539  _ ("Missing entries in record line `%s'.\n"),
1540  value);
1541  GNUNET_free (cp);
1542  return GNUNET_SYSERR;
1543  }
1544  GNUNET_free (cp);
1545  tok++; /* skip space */
1547  tok,
1548  &raw_data,
1549  &record.data_size))
1550  {
1552  _ ("Invalid record data for type %s: `%s'.\n"),
1554  tok);
1555  return GNUNET_SYSERR;
1556  }
1557 
1558  r = GNUNET_malloc (sizeof(struct RecordSetEntry) + record.data_size);
1559  r->next = *head;
1560  record.data = &r[1];
1561  memcpy (&r[1], raw_data, record.data_size);
1562  GNUNET_free (raw_data);
1563  r->record = record;
1564  *head = r;
1565  return GNUNET_OK;
1566 }
1567 
1568 
1580  const char *name,
1581  const char *argumentHelp,
1582  const char *description,
1583  struct RecordSetEntry **rs)
1584 {
1586  .name = name,
1587  .argumentHelp = argumentHelp,
1588  .description = description,
1589  .require_argument = 1,
1590  .processor =
1592  .scls = (void *) rs };
1593 
1594  return clo;
1595 }
1596 
1597 
1605 int
1606 main (int argc, char *const *argv)
1607 {
1608  struct GNUNET_GETOPT_CommandLineOption options[] =
1609  { GNUNET_GETOPT_option_flag ('a', "add", gettext_noop ("add record"), &add),
1611  "delete",
1612  gettext_noop ("delete record"),
1613  &del),
1615  "display",
1616  gettext_noop ("display records"),
1617  &list),
1619  'e',
1620  "expiration",
1621  "TIME",
1622  gettext_noop (
1623  "expiration time for record to use (for adding only), \"never\" is possible"),
1624  &expirationstring),
1626  "nick",
1627  "NICKNAME",
1628  gettext_noop (
1629  "set the desired nick name for the zone"),
1630  &nickstring),
1632  "monitor",
1633  gettext_noop (
1634  "monitor changes in the namestore"),
1635  &monitor),
1637  "name",
1638  "NAME",
1639  gettext_noop (
1640  "name of the record to add/delete/display"),
1641  &name),
1643  "reverse",
1644  "PKEY",
1645  gettext_noop (
1646  "determine our name for the given PKEY"),
1647  &reverse_pkey),
1649  'R',
1650  "replace",
1651  "RECORDLINE",
1652  gettext_noop (
1653  "set record set to values given by (possibly multiple) RECORDLINES; can be specified multiple times"),
1654  &recordset),
1656  "type",
1657  "TYPE",
1658  gettext_noop (
1659  "type of the record to add/delete/display"),
1660  &typestring),
1662  "uri",
1663  "URI",
1664  gettext_noop ("URI to import into our zone"),
1665  &uri),
1667  "value",
1668  "VALUE",
1669  gettext_noop (
1670  "value of the record to add/delete"),
1671  &value),
1673  "public",
1674  gettext_noop ("create or list public record"),
1675  &is_public),
1677  's',
1678  "shadow",
1679  gettext_noop (
1680  "create shadow record (only valid if all other records of the same type have expired"),
1681  &is_shadow),
1683  "zone",
1684  "EGO",
1685  gettext_noop (
1686  "name of the ego controlling the zone"),
1687  &ego_name),
1689  int lret;
1690 
1691  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1692  return 2;
1693 
1694  is_public = -1;
1695  is_shadow = -1;
1696  GNUNET_log_setup ("gnunet-namestore", "WARNING", NULL);
1697  if (GNUNET_OK !=
1698  (lret = GNUNET_PROGRAM_run (argc,
1699  argv,
1700  "gnunet-namestore",
1701  _ ("GNUnet zone manipulation tool"),
1702  options,
1703  &run,
1704  NULL)))
1705  {
1706  GNUNET_free_nz ((void *) argv);
1708  return lret;
1709  }
1710  GNUNET_free_nz ((void *) argv);
1712  return ret;
1713 }
1714 
1715 
1716 /* end of gnunet-namestore.c */
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.
Definition: identity_api.c:566
General context for command line processors.
static void add_error_cb(void *cls)
Function called if lookup fails.
void GNUNET_IDENTITY_cancel(struct GNUNET_IDENTITY_Operation *op)
Cancel an identity operation.
Definition: identity_api.c:867
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
This record should not be used unless all (other) records with an absolute expiration time have expir...
struct RecordSetEntry * next
Kept in a linked list.
const char * argumentHelp
Name of the argument for the user in help text.
void GNUNET_IDENTITY_ego_lookup_cancel(struct GNUNET_IDENTITY_EgoLookup *el)
Abort ego lookup attempt.
Handle for ego lookup.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
uint64_t rel_value_us
The actual value.
static struct GNUNET_NAMESTORE_QueueEntry * add_qe
Queue entry for the &#39;add&#39; operation.
static void lookup_error_cb(void *cls)
Function called on errors while monitoring.
static char * pkey
Public key of the zone to look in, in ASCII.
static int parse_expiration(const char *expirationstring, int *etime_is_rel, uint64_t *etime)
Parse expiration time.
static struct GNUNET_NAMESTORE_QueueEntry * add_qe_uri
Queue entry for the &#39;add-uri&#39; operation.
struct GNUNET_NAMESTORE_ZoneMonitor * GNUNET_NAMESTORE_zone_monitor_start(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, int iterate_first, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor monitor, void *monitor_cls, GNUNET_SCHEDULER_TaskCallback sync_cb, void *sync_cb_cls)
Begin monitoring a zone for changes.
#define GNUNET_GNS_EMPTY_LABEL_AT
String we use to indicate an empty label (top-level entry in the zone).
static void run_with_zone_pkey(const struct GNUNET_CONFIGURATION_Handle *cfg)
We have obtained the zone&#39;s private key, so now process the main commands using it.
void GNUNET_CRYPTO_ecdsa_key_clear(struct GNUNET_CRYPTO_EcdsaPrivateKey *pk)
Clear memory that was used to store a private key.
Definition: crypto_ecc.c:483
#define GNUNET_DNSPARSER_TYPE_CNAME
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_lookup(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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.
static void sync_cb(void *cls)
Function called once we are in sync in monitor mode.
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, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1331
struct GNUNET_NAMESTORE_ZoneIterator * GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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)
Starts a new zone iteration (used to periodically PUT all of our records into our DHT)...
const char * description
Help text for the option (description)
static struct GNUNET_IDENTITY_EgoLookup * el
Handle to identity lookup.
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1458
uint32_t GNUNET_GNSRECORD_typename_to_number(const char *dns_typename)
Convert a type name (i.e.
Definition: gnsrecord.c:220
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int 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:356
#define GNUNET_GNSRECORD_TYPE_ANY
Record type indicating any record/&#39;*&#39;.
const struct GNUNET_CRYPTO_EcdsaPrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:595
static void handle_reverse_lookup(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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 void do_shutdown(void *cls)
Task run on shutdown.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static void * data
Value in binary format.
int 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:407
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_get(struct GNUNET_IDENTITY_Handle *h, const char *service_name, GNUNET_IDENTITY_Callback cb, void *cb_cls)
Obtain the identity that is currently preferred/default for a service.
Definition: identity_api.c:632
void GNUNET_NAMESTORE_zone_monitor_stop(struct GNUNET_NAMESTORE_ZoneMonitor *zm)
Stop monitoring a zone for changes.
int main(int argc, char *const *argv)
The main function for gnunet-namestore.
static struct Experiment * e
static struct GNUNET_NAMESTORE_ZoneMonitor * zm
Monitor handle.
static void get_existing_record(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, const char *rec_name, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
We&#39;re storing a record; this function is given the existing record so that we can merge the informati...
size_t data_size
Number of bytes in data.
Definition of a command line option.
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...
Private ECC key encoded for transmission.
static char * name
Name of the records to add/list/remove.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
static void zone_iteration_finished(void *cls)
Function called when we are done with a zone iteration.
const char shortName
Short name of the option.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_GNSRECORD_TYPE_NICK
Record type for GNS nick names ("NICK").
static struct RecordSetEntry * recordset
Entry in record set for processing records in bulk.
uint64_t abs_value_us
The actual value.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Handle for an operation with the identity service.
Definition: identity_api.c:39
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
static void zone_iteration_error_cb(void *cls)
Function called when we encountered an error in a zone iteration.
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
static int etime_is_rel
Is expiration time relative or absolute time?
void GNUNET_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe)
Cancel a namestore operation.
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.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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.
static struct GNUNET_IDENTITY_Handle * idh
Identity service handle.
static void add_continuation(void *cls, int32_t success, const char *emsg)
Continuation called to notify client about result of the operation.
static char * zone
Name of the zone we manage.
static void identity_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego)
Callback invoked from identity service with ego information.
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
Handle for a monitoring activity.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
Handle for a zone iterator operation.
Handle for an ego.
Definition: identity.h:245
static void replace_cont(void *cls, int success, const char *emsg)
Function called when namestore is done with the replace operation.
static int is_shadow
Is record a shadow record (GNUNET_GNSRECORD_RF_SHADOW_RECORD)
#define GNUNET_DNSPARSER_TYPE_SOA
const void * data
Binary value stored in the DNS record.
static char * value
Value of the record to add/remove.
static int monitor
Enables monitor mode.
static int del
Desired action is to remove a record.
#define GNUNET_GNSRECORD_TYPE_PKEY
Record type for GNS zone transfer ("PKEY").
Connection to the NAMESTORE service.
Handle for the service.
Definition: identity_api.c:95
uint64_t expiration_time
Expiration time for the DNS record.
static int ret
Global return value.
static struct SolverHandle * sh
#define GNUNET_GNSRECORD_TYPE_GNS2DNS
Record type for delegation to DNS.
static struct GNUNET_NAMESTORE_QueueEntry * set_qe
Queue entry for the &#39;set/replace&#39; operation.
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:702
static void display_record_lookup(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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 char * option
Name of the option.
Definition: gnunet-config.c:38
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
static void id_connect_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *name)
Function called with ALL of the egos known to the identity service, used on startup if the user did n...
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:884
static void del_continuation(void *cls, int32_t success, const char *emsg)
Continuation called to notify client about result of the operation.
This is a private record of this peer and it should thus not be handed out to other peers...
void GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it)
Stops iteration and releases the namestore handle for further calls.
static void del_monitor(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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.
int GNUNET_GNSRECORD_string_to_value(uint32_t type, const char *s, void **data, size_t *data_size)
Convert human-readable version of a &#39;value&#39; of a record to the binary representation.
Definition: gnsrecord.c:191
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run.
#define GNUNET_free_nz(ptr)
Wrapper around free.
static struct GNUNET_NAMESTORE_QueueEntry * reverse_qe
Queue entry for the &#39;reverse lookup&#39; operation (in combination with a name).
static uint64_t etime
Expiration string converted to numeric value.
An QueueEntry used to store information for a pending NAMESTORE record operation. ...
Definition: namestore_api.c:53
static char * reverse_pkey
Reverse lookup to perform.
static char * expirationstring
Desired expiration time.
struct GNUNET_NAMESTORE_Handle * GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namestore service.
char * getenv()
static void test_finished()
Check if we are finished, and if so, perform shutdown.
static char * uri
URI to import.
struct GNUNET_GNSRECORD_Data record
The record to add/remove.
static int is_public
Is record public (opposite of GNUNET_GNSRECORD_RF_PRIVATE)
static int add
Desired action is to add a record.
#define GNUNET_DNSPARSER_TYPE_OPENPGPKEY
static int list
Desired action is to list records.
#define GNUNET_DNSPARSER_TYPE_TLSA
static void display_record_iterator(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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 default_ego_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *name)
Function called with the default ego to be used for GNS operations.
Entry in record set for bulk processing.
static void display_record_monitor(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd)
Process a record that was stored in the namestore.
struct GNUNET_IDENTITY_EgoLookup * GNUNET_IDENTITY_ego_lookup(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *name, GNUNET_IDENTITY_EgoCallback cb, void *cb_cls)
Lookup an ego by name.
struct GNUNET_IDENTITY_Operation * get_default
Obtain default ego.
int GNUNET_CRYPTO_ecdsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:366
static uint32_t type
Type string converted to DNS type value.
uint32_t record_type
Type of the GNS/DNS record.
static void del_lookup_error_cb(void *cls)
Function called if lookup for deletion fails.
static char * nickstring
Desired nick name.
configuration data
Definition: configuration.c:84
static struct PendingResolutions * head
Head of list of pending resolution requests.
Definition: gnunet-ats.c:230
static char * ego_name
Name of the ego controlling the zone.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
static struct GNUNET_CRYPTO_EcdsaPrivateKey zone_pkey
Private key for the our zone.
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_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_zone_to_name(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const struct GNUNET_CRYPTO_EcdsaPublicKey *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.
#define GNUNET_log(kind,...)
static struct GNUNET_NAMESTORE_ZoneIterator * list_it
List iterator for the &#39;list&#39; operation.
static void monitor_error_cb(void *cls)
Function called on errors while monitoring.
int GNUNET_PROGRAM_run(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, parse options).
Definition: program.c:367
static struct GNUNET_NAMESTORE_QueueEntry * get_qe
Queue entry for the &#39;lookup&#39; operation.
static struct GNUNET_NAMESTORE_QueueEntry * del_qe
Queue entry for the &#39;del&#39; operation.
Time for absolute times used by GNUnet, in microseconds.
static char * typestring
Type of the record to add/remove, NULL to remove all.
static void display_record(const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd)
Process a record that was stored in the namestore.
enum GNUNET_GNSRECORD_Flags flags
Flags for the record.
This expiration time of the record is a relative time (not an absolute time).
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:757
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
static void reverse_error_cb(void *cls)
Function called if we encountered an error in zone-to-name.
#define GNUNET_DNSPARSER_TYPE_SRV
char * GNUNET_GNSRECORD_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the &#39;value&#39; of a record to a string.
Definition: gnsrecord.c:159
static int multirecord_process(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
Command-line option parser function that allows the user to specify a complete record as one argument...
static size_t data_size
Number of bytes in data.
const char * GNUNET_GNSRECORD_number_to_typename(uint32_t type)
Convert a type number (i.e.
Definition: gnsrecord.c:247
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)...
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
#define GNUNET_malloc(size)
Wrapper around malloc.
int GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:971
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
struct GNUNET_GETOPT_CommandLineOption multirecord_option(char shortName, const char *name, const char *argumentHelp, const char *description, struct RecordSetEntry **rs)
Allow user to specify keywords.
void GNUNET_STRINGS_utf8_tolower(const char *input, char *output)
Convert the utf-8 input string to lower case.
Definition: strings.c:568
#define gettext_noop(String)
Definition: gettext.h:69