aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/gnunet-namestore.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-11-13 14:59:14 +0100
committerChristian Grothoff <christian@grothoff.org>2018-11-13 14:59:14 +0100
commitc30a518e58479c6ffc5e634db3624f5e82e25f1d (patch)
tree8989b15cbc8444eb9fb0c0222e6f99fe8ed449ab /src/namestore/gnunet-namestore.c
parentc84054626c6cc460bad4b6562ee89c221be308aa (diff)
downloadgnunet-c30a518e58479c6ffc5e634db3624f5e82e25f1d.tar.gz
gnunet-c30a518e58479c6ffc5e634db3624f5e82e25f1d.zip
complete implementation of -R, to be tested by r
Diffstat (limited to 'src/namestore/gnunet-namestore.c')
-rw-r--r--src/namestore/gnunet-namestore.c117
1 files changed, 77 insertions, 40 deletions
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c
index 619d0c528..8386a696d 100644
--- a/src/namestore/gnunet-namestore.c
+++ b/src/namestore/gnunet-namestore.c
@@ -136,6 +136,11 @@ static int is_shadow;
136static struct GNUNET_NAMESTORE_QueueEntry *del_qe; 136static struct GNUNET_NAMESTORE_QueueEntry *del_qe;
137 137
138/** 138/**
139 * Queue entry for the 'set/replace' operation.
140 */
141static struct GNUNET_NAMESTORE_QueueEntry *set_qe;
142
143/**
139 * Name of the records to add/list/remove. 144 * Name of the records to add/list/remove.
140 */ 145 */
141static char *name; 146static char *name;
@@ -195,7 +200,6 @@ static size_t data_size;
195 */ 200 */
196static uint64_t etime; 201static uint64_t etime;
197 202
198
199/** 203/**
200 * Is expiration time relative or absolute time? 204 * Is expiration time relative or absolute time?
201 */ 205 */
@@ -251,6 +255,11 @@ do_shutdown (void *cls)
251 GNUNET_NAMESTORE_cancel (add_qe); 255 GNUNET_NAMESTORE_cancel (add_qe);
252 add_qe = NULL; 256 add_qe = NULL;
253 } 257 }
258 if (NULL != set_qe)
259 {
260 GNUNET_NAMESTORE_cancel (set_qe);
261 set_qe = NULL;
262 }
254 if (NULL != add_qe_uri) 263 if (NULL != add_qe_uri)
255 { 264 {
256 GNUNET_NAMESTORE_cancel (add_qe_uri); 265 GNUNET_NAMESTORE_cancel (add_qe_uri);
@@ -930,43 +939,34 @@ parse_expiration (const char *expirationstring,
930} 939}
931 940
932 941
933#if 0 942/**
934/* globals? */ 943 * Function called when namestore is done with the replace
935unsigned int rd_count; 944 * operation.
936struct GNUNET_GNSRECORD_Data *rd; 945 *
937 946 * @param cls NULL
938 947 * @param success #GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate)
939rd_count = 0; 948 * #GNUNET_NO if content was already there or not found
940for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next) 949 * #GNUNET_YES (or other positive value) on success
941 rd_count++; 950 * @param emsg NULL on success, otherwise an error message
942rd = GNUNET_new_array (rd_count, 951 */
943 struct GNUNET_GNSRECORD_Data); 952static void
944rd_count = 0; 953replace_cont (void *cls,
945for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next) 954 int success,
955 const char *emsg)
946{ 956{
947 rd[rd_count] = e->record; 957 (void) cls;
948 rd_count++; 958
959 set_qe = NULL;
960 if (GNUNET_OK != success)
961 {
962 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
963 _("Failed to replace records: %s\n"),
964 emsg);
965 ret = 1; /* fail from 'main' */
966 }
967 GNUNET_SCHEDULER_shutdown ();
949} 968}
950 969
951/* if add: */
952qe = GNUNET_NAMESTORE_records_store (...,
953 rd_count,
954 rd,
955 &my_cont
956 ..);
957
958in 'my_cont' and/or shutdown:
959
960qe = NULL;
961GNUNET_free (rd);
962
963in shutdown:
964
965if NULL != qe NAMESTORE_cancel (qe);
966GNUNET_free (rd);
967
968#endif
969
970 970
971/** 971/**
972 * Callback invoked from identity service with ego information. 972 * Callback invoked from identity service with ego information.
@@ -1000,7 +1000,7 @@ identity_cb (void *cls,
1000 GNUNET_free_non_null (ego_name); 1000 GNUNET_free_non_null (ego_name);
1001 ego_name = NULL; 1001 ego_name = NULL;
1002 1002
1003 if (! (add|del|list|(NULL != nickstring)|(NULL != uri)|(NULL != reverse_pkey)) ) 1003 if (! (add|del|list|(NULL != nickstring)|(NULL != uri)|(NULL != reverse_pkey))|(NULL != recordset) )
1004 { 1004 {
1005 /* nothing more to be done */ 1005 /* nothing more to be done */
1006 fprintf (stderr, 1006 fprintf (stderr,
@@ -1009,8 +1009,7 @@ identity_cb (void *cls,
1009 return; 1009 return;
1010 } 1010 }
1011 GNUNET_CRYPTO_ecdsa_key_get_public (&zone_pkey, 1011 GNUNET_CRYPTO_ecdsa_key_get_public (&zone_pkey,
1012 &pub); 1012 &pub);
1013
1014 ns = GNUNET_NAMESTORE_connect (cfg); 1013 ns = GNUNET_NAMESTORE_connect (cfg);
1015 if (NULL == ns) 1014 if (NULL == ns)
1016 { 1015 {
@@ -1018,6 +1017,44 @@ identity_cb (void *cls,
1018 _("Failed to connect to namestore\n")); 1017 _("Failed to connect to namestore\n"));
1019 return; 1018 return;
1020 } 1019 }
1020
1021 if (NULL != recordset)
1022 {
1023 /* replace entire record set */
1024 unsigned int rd_count;
1025 struct GNUNET_GNSRECORD_Data *rd;
1026
1027 if (NULL == name)
1028 {
1029 fprintf (stderr,
1030 _("Missing option `%s' for operation `%s'\n"),
1031 "-n", _("replace"));
1032 GNUNET_SCHEDULER_shutdown ();
1033 ret = 1;
1034 return;
1035 }
1036 rd_count = 0;
1037 for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next)
1038 rd_count++;
1039 rd = GNUNET_new_array (rd_count,
1040 struct GNUNET_GNSRECORD_Data);
1041 rd_count = 0;
1042 for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next)
1043 {
1044 rd[rd_count] = e->record;
1045 rd_count++;
1046 }
1047 set_qe = GNUNET_NAMESTORE_records_store (ns,
1048 &zone_pkey,
1049 name,
1050 rd_count,
1051 rd,
1052 &replace_cont,
1053 NULL);
1054 GNUNET_free (rd);
1055 return;
1056 }
1057
1021 if (add) 1058 if (add)
1022 { 1059 {
1023 if (NULL == name) 1060 if (NULL == name)
@@ -1526,9 +1563,9 @@ main (int argc,
1526 gettext_noop ("determine our name for the given PKEY"), 1563 gettext_noop ("determine our name for the given PKEY"),
1527 &reverse_pkey), 1564 &reverse_pkey),
1528 multirecord_option ('R', 1565 multirecord_option ('R',
1529 "record", 1566 "replace",
1530 "RECORDLINE", 1567 "RECORDLINE",
1531 gettext_noop ("complete record on one line to add/delete/display; can be specified multiple times"), 1568 gettext_noop ("set record set to values given by (possibly multiple) RECORDLINES; can be specified multiple times"),
1532 &recordset), 1569 &recordset),
1533 GNUNET_GETOPT_option_string ('t', 1570 GNUNET_GETOPT_option_string ('t',
1534 "type", 1571 "type",