aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-03-05 10:49:29 +0000
committerChristian Grothoff <christian@grothoff.org>2012-03-05 10:49:29 +0000
commitc9a1014c8b91bd121d511f807346ce69fcd08479 (patch)
treea5137b8afaba816d8ad5a51a3cc79be64d305f57 /src
parent67b1d5de1c51fa08c6136b94f4d06bd24e9e40fd (diff)
downloadgnunet-c9a1014c8b91bd121d511f807346ce69fcd08479.tar.gz
gnunet-c9a1014c8b91bd121d511f807346ce69fcd08479.zip
-more work on gnunet-gns
Diffstat (limited to 'src')
-rw-r--r--src/gns/gnunet-gns.c178
1 files changed, 167 insertions, 11 deletions
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c
index e2fbb7509..a6b45586b 100644
--- a/src/gns/gnunet-gns.c
+++ b/src/gns/gnunet-gns.c
@@ -23,7 +23,13 @@
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 * 24 *
25 * TODO: 25 * TODO:
26 * - everything 26 * - printing records
27 * - allow users to set record options (not just 'RF_AUTHORITY')
28 * - test
29 * - parsing SOA, PTR and MX value specifications (and define format!)
30 * - add options to list/lookup individual records
31 * - add option to shorten name (lookup PKEY, then lookup name by zone,
32 * then possibly lookup PSEU for the zone and update our zone)
27 */ 33 */
28#include "platform.h" 34#include "platform.h"
29#include <gnunet_util_lib.h> 35#include <gnunet_util_lib.h>
@@ -56,16 +62,31 @@ static char *keyfile;
56static int add; 62static int add;
57 63
58/** 64/**
65 * Queue entry for the 'add' operation.
66 */
67static struct GNUNET_NAMESTORE_QueueEntry *add_qe;
68
69/**
59 * Desired action is to list records. 70 * Desired action is to list records.
60 */ 71 */
61static int list; 72static int list;
62 73
63/** 74/**
75 * List iterator for the 'list' operation.
76 */
77static struct GNUNET_NAMESTORE_ZoneIterator *list_it;
78
79/**
64 * Desired action is to remove a record. 80 * Desired action is to remove a record.
65 */ 81 */
66static int del; 82static int del;
67 83
68/** 84/**
85 * Queue entry for the 'del' operation.
86 */
87static struct GNUNET_NAMESTORE_QueueEntry *del_qe;
88
89/**
69 * Name of the records to add/list/remove. 90 * Name of the records to add/list/remove.
70 */ 91 */
71static char *name; 92static char *name;
@@ -110,6 +131,96 @@ do_shutdown (void *cls,
110 131
111 132
112/** 133/**
134 * Continuation called to notify client about result of the
135 * operation.
136 *
137 * @param cls closure, unused
138 * @param success GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate)
139 * GNUNET_NO if content was already there
140 * GNUNET_YES (or other positive value) on success
141 * @param emsg NULL on success, otherwise an error message
142 */
143static void
144add_continuation (void *cls,
145 int32_t success,
146 const char *emsg)
147{
148 add_qe = NULL;
149 if (success != GNUNET_YES)
150 fprintf (stderr,
151 _("Adding record failed: %s\n"),
152 (success == GNUNET_NO) ? "record exists" : emsg);
153 if ( (NULL == del_qe) &&
154 (NULL == list_it) )
155 GNUNET_SCHEDULER_shutdown ();
156}
157
158
159/**
160 * Continuation called to notify client about result of the
161 * operation.
162 *
163 * @param cls closure, unused
164 * @param success GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate)
165 * GNUNET_NO if content was already there
166 * GNUNET_YES (or other positive value) on success
167 * @param emsg NULL on success, otherwise an error message
168 */
169static void
170del_continuation (void *cls,
171 int32_t success,
172 const char *emsg)
173{
174 del_qe = NULL;
175 if (success != GNUNET_YES)
176 fprintf (stderr,
177 _("Deleting record failed: %s\n"),
178 emsg);
179 if ( (NULL == add_qe) &&
180 (NULL == list_it) )
181 GNUNET_SCHEDULER_shutdown ();
182}
183
184
185/**
186 * Process a record that was stored in the namestore.
187 *
188 * @param cls closure
189 * @param zone_key public key of the zone
190 * @param expire when does the corresponding block in the DHT expire (until
191 * when should we never do a DHT lookup for the same name again)?;
192 * GNUNET_TIME_UNIT_ZERO_ABS if there are no records of any type in the namestore,
193 * or the expiration time of the block in the namestore (even if there are zero
194 * records matching the desired record type)
195 * @param name name that is being mapped (at most 255 characters long)
196 * @param rd_count number of entries in 'rd' array
197 * @param rd array of records with data to store
198 * @param signature signature of the record block, NULL if signature is unavailable (i.e.
199 * because the user queried for a particular record type only)
200 */
201static void
202display_record (void *cls,
203 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
204 struct GNUNET_TIME_Absolute expire,
205 const char *name,
206 unsigned int rd_len,
207 const struct GNUNET_NAMESTORE_RecordData *rd,
208 const struct GNUNET_CRYPTO_RsaSignature *signature)
209{
210 if (NULL == name)
211 {
212 list_it = NULL;
213 if ( (NULL == del_qe) &&
214 (NULL == add_qe) )
215 GNUNET_SCHEDULER_shutdown ();
216 return;
217 }
218 // FIXME: display record!
219 GNUNET_NAMESTORE_zone_iterator_next (list_it);
220}
221
222
223/**
113 * Main function that will be run. 224 * Main function that will be run.
114 * 225 *
115 * @param cls closure 226 * @param cls closure
@@ -128,6 +239,7 @@ run (void *cls, char *const *args, const char *cfgfile,
128 struct in_addr value_a; 239 struct in_addr value_a;
129 struct in6_addr value_aaaa; 240 struct in6_addr value_aaaa;
130 struct GNUNET_TIME_Relative etime; 241 struct GNUNET_TIME_Relative etime;
242 struct GNUNET_NAMESTORE_RecordData rd;
131 243
132 if (NULL == keyfile) 244 if (NULL == keyfile)
133 { 245 {
@@ -163,7 +275,8 @@ run (void *cls, char *const *args, const char *cfgfile,
163 _("Failed to connect to namestore\n")); 275 _("Failed to connect to namestore\n"));
164 return; 276 return;
165 } 277 }
166 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 278 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
279 &do_shutdown, NULL);
167 if (NULL == typestring) 280 if (NULL == typestring)
168 type = 0; 281 type = 0;
169 else 282 else
@@ -173,11 +286,11 @@ run (void *cls, char *const *args, const char *cfgfile,
173 fprintf (stderr, _("Unsupported type `%s'\n"), typestring); 286 fprintf (stderr, _("Unsupported type `%s'\n"), typestring);
174 GNUNET_SCHEDULER_shutdown (); 287 GNUNET_SCHEDULER_shutdown ();
175 return; 288 return;
176 } else if (add) 289 } else if (add | del)
177 { 290 {
178 fprintf (stderr, 291 fprintf (stderr,
179 _("Missing option `%s' for operation `%s'\n"), 292 _("Missing option `%s' for operation `%s'\n"),
180 "-t", _("add")); 293 "-t", _("add/del"));
181 GNUNET_SCHEDULER_shutdown (); 294 GNUNET_SCHEDULER_shutdown ();
182 return; 295 return;
183 } 296 }
@@ -210,14 +323,17 @@ run (void *cls, char *const *args, const char *cfgfile,
210 data_size = strlen (value); 323 data_size = strlen (value);
211 break; 324 break;
212 case GNUNET_DNSPARSER_TYPE_SOA: 325 case GNUNET_DNSPARSER_TYPE_SOA:
326 // FIXME
213 fprintf (stderr, _("Record type `%s' not implemented yet\n"), typestring); 327 fprintf (stderr, _("Record type `%s' not implemented yet\n"), typestring);
214 GNUNET_SCHEDULER_shutdown (); 328 GNUNET_SCHEDULER_shutdown ();
215 return; 329 return;
216 case GNUNET_DNSPARSER_TYPE_PTR: 330 case GNUNET_DNSPARSER_TYPE_PTR:
331 // FIXME
217 fprintf (stderr, _("Record type `%s' not implemented yet\n"), typestring); 332 fprintf (stderr, _("Record type `%s' not implemented yet\n"), typestring);
218 GNUNET_SCHEDULER_shutdown (); 333 GNUNET_SCHEDULER_shutdown ();
219 return; 334 return;
220 case GNUNET_DNSPARSER_TYPE_MX: 335 case GNUNET_DNSPARSER_TYPE_MX:
336 // FIXME
221 fprintf (stderr, _("Record type `%s' not implemented yet\n"), typestring); 337 fprintf (stderr, _("Record type `%s' not implemented yet\n"), typestring);
222 GNUNET_SCHEDULER_shutdown (); 338 GNUNET_SCHEDULER_shutdown ();
223 return; 339 return;
@@ -248,11 +364,11 @@ run (void *cls, char *const *args, const char *cfgfile,
248 default: 364 default:
249 GNUNET_assert (0); 365 GNUNET_assert (0);
250 } 366 }
251 } else if (add) 367 } else if (add | del)
252 { 368 {
253 fprintf (stderr, 369 fprintf (stderr,
254 _("Missing option `%s' for operation `%s'\n"), 370 _("Missing option `%s' for operation `%s'\n"),
255 "-V", _("add")); 371 "-V", _("add/del"));
256 GNUNET_SCHEDULER_shutdown (); 372 GNUNET_SCHEDULER_shutdown ();
257 return; 373 return;
258 } 374 }
@@ -268,25 +384,65 @@ run (void *cls, char *const *args, const char *cfgfile,
268 GNUNET_SCHEDULER_shutdown (); 384 GNUNET_SCHEDULER_shutdown ();
269 return; 385 return;
270 } 386 }
271 } else if (add) 387 } else if (add | del)
272 { 388 {
273 fprintf (stderr, 389 fprintf (stderr,
274 _("Missing option `%s' for operation `%s'\n"), 390 _("Missing option `%s' for operation `%s'\n"),
275 "-e", _("add")); 391 "-e", _("add/del"));
276 GNUNET_SCHEDULER_shutdown (); 392 GNUNET_SCHEDULER_shutdown ();
277 return; 393 return;
278 } 394 }
279 if (add) 395 if (add)
280 { 396 {
281 // FIXME 397 if (NULL == name)
398 {
399 fprintf (stderr,
400 _("Missing option `%s' for operation `%s'\n"),
401 "-n", _("add"));
402 GNUNET_SCHEDULER_shutdown ();
403 return;
404 }
405 rd.data = data;
406 rd.data_size = data_size;
407 rd.record_type = type;
408 rd.expiration = GNUNET_TIME_relative_to_absolute (etime);
409 rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY; // FIXME: not always...
410 add_qe = GNUNET_NAMESTORE_record_create (ns,
411 zone_pkey,
412 name,
413 &rd,
414 &add_continuation,
415 NULL);
282 } 416 }
283 if (del) 417 if (del)
284 { 418 {
285 // FIXME 419 if (NULL == name)
420 {
421 fprintf (stderr,
422 _("Missing option `%s' for operation `%s'\n"),
423 "-n", _("del"));
424 GNUNET_SCHEDULER_shutdown ();
425 return;
426 }
427 rd.data = data;
428 rd.data_size = data_size;
429 rd.record_type = type;
430 rd.expiration = GNUNET_TIME_relative_to_absolute (etime);
431 rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY; // FIXME: not always...
432 del_qe = GNUNET_NAMESTORE_record_create (ns,
433 zone_pkey,
434 name,
435 &rd,
436 &del_continuation,
437 NULL);
286 } 438 }
287 if (list) 439 if (list)
288 { 440 {
289 // FIXME 441 list_it = GNUNET_NAMESTORE_zone_iteration_start (ns,
442 &zone,
443 0, 0,
444 &display_record,
445 NULL);
290 } 446 }
291} 447}
292 448