aboutsummaryrefslogtreecommitdiff
path: root/src/gns/gnunet-gns.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2016-10-06 15:54:30 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2016-10-06 15:54:30 +0000
commit810bc9ef12ddcc67cfc7cd762759ee13ecd14a8d (patch)
treee6950609e302c8cee5dd49cd75a890e660dde02a /src/gns/gnunet-gns.c
parent16f524720ce08aadb35912731217eaeafc690dba (diff)
downloadgnunet-810bc9ef12ddcc67cfc7cd762759ee13ecd14a8d.tar.gz
gnunet-810bc9ef12ddcc67cfc7cd762759ee13ecd14a8d.zip
- Add reverse resolution with limited functionality
Diffstat (limited to 'src/gns/gnunet-gns.c')
-rw-r--r--src/gns/gnunet-gns.c110
1 files changed, 91 insertions, 19 deletions
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c
index 62cec54cb..17fe4cbda 100644
--- a/src/gns/gnunet-gns.c
+++ b/src/gns/gnunet-gns.c
@@ -66,6 +66,16 @@ static char *zone_ego_name;
66static char *public_key; 66static char *public_key;
67 67
68/** 68/**
69 * Reverse key
70 */
71static char *reverse_key;
72
73/**
74 * Reverse key
75 */
76static struct GNUNET_CRYPTO_EcdsaPublicKey rkey;
77
78/**
69 * Set to GNUNET_GNS_LO_LOCAL_MASTER if we are looking up in the master zone. 79 * Set to GNUNET_GNS_LO_LOCAL_MASTER if we are looking up in the master zone.
70 */ 80 */
71static enum GNUNET_GNS_LocalOptions local_options; 81static enum GNUNET_GNS_LocalOptions local_options;
@@ -86,6 +96,11 @@ static int rtype;
86static struct GNUNET_GNS_LookupRequest *lookup_request; 96static struct GNUNET_GNS_LookupRequest *lookup_request;
87 97
88/** 98/**
99 * Handle to reverse lookup request
100 */
101static struct GNUNET_GNS_ReverseLookupRequest *rev_lookup_request;
102
103/**
89 * Lookup an ego with the identity service. 104 * Lookup an ego with the identity service.
90 */ 105 */
91static struct GNUNET_IDENTITY_EgoLookup *el; 106static struct GNUNET_IDENTITY_EgoLookup *el;
@@ -159,6 +174,24 @@ do_timeout (void *cls)
159 GNUNET_SCHEDULER_shutdown (); 174 GNUNET_SCHEDULER_shutdown ();
160} 175}
161 176
177static void
178process_reverse_result (void *cls,
179 const char *name)
180{
181 rev_lookup_request = NULL;
182 if (NULL == name)
183 {
184 printf ("No name found.\n");
185 return;
186 }
187 if (raw)
188 printf ("%s\n", name);
189 else
190 printf ("%s is known as %s\n",
191 reverse_key,
192 name);
193 GNUNET_SCHEDULER_shutdown ();
194}
162 195
163/** 196/**
164 * Function called with the result of a GNS lookup. 197 * Function called with the result of a GNS lookup.
@@ -248,6 +281,14 @@ lookup_with_keys (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey,
248 &process_lookup_result, 281 &process_lookup_result,
249 lookup_name); 282 lookup_name);
250 } 283 }
284 else if (NULL != reverse_key)
285 {
286 rev_lookup_request = GNUNET_GNS_reverse_lookup (gns,
287 &rkey,
288 pkey,
289 &process_reverse_result,
290 NULL);
291 }
251 else 292 else
252 { 293 {
253 fprintf (stderr, 294 fprintf (stderr,
@@ -416,49 +457,77 @@ run (void *cls,
416 return; 457 return;
417 } 458 }
418 tt = GNUNET_SCHEDULER_add_delayed (timeout, 459 tt = GNUNET_SCHEDULER_add_delayed (timeout,
419 &do_timeout, NULL); 460 &do_timeout, NULL);
420 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); 461 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
462 if (NULL != reverse_key)
463 {
464 if (GNUNET_OK !=
465 GNUNET_CRYPTO_ecdsa_public_key_from_string (reverse_key,
466 strlen (reverse_key),
467 &rkey))
468 {
469 fprintf (stderr,
470 _("Reverse key `%s' is not well-formed\n"),
471 reverse_key);
472 GNUNET_SCHEDULER_shutdown ();
473 return;
474 }
475 }
421 if (NULL != public_key) 476 if (NULL != public_key)
422 { 477 {
423 if (GNUNET_OK != 478 if (GNUNET_OK !=
424 GNUNET_CRYPTO_ecdsa_public_key_from_string (public_key, 479 GNUNET_CRYPTO_ecdsa_public_key_from_string (public_key,
425 strlen (public_key), 480 strlen (public_key),
426 &pkey)) 481 &pkey))
427 { 482 {
428 fprintf (stderr, 483 fprintf (stderr,
429 _("Public key `%s' is not well-formed\n"), 484 _("Public key `%s' is not well-formed\n"),
430 public_key); 485 public_key);
431 GNUNET_SCHEDULER_shutdown (); 486 GNUNET_SCHEDULER_shutdown ();
432 return; 487 return;
433 } 488 }
434 lookup_with_public_key (&pkey); 489 lookup_with_public_key (&pkey);
435 return; 490 return;
436 } 491 }
492 if (NULL != reverse_key)
493 {
494 if (GNUNET_OK !=
495 GNUNET_CRYPTO_ecdsa_public_key_from_string (reverse_key,
496 strlen (reverse_key),
497 &rkey))
498 {
499 fprintf (stderr,
500 _("Reverse key `%s' is not well-formed\n"),
501 reverse_key);
502 GNUNET_SCHEDULER_shutdown ();
503 return;
504 }
505 }
437 if (NULL != zone_ego_name) 506 if (NULL != zone_ego_name)
438 { 507 {
439 el = GNUNET_IDENTITY_ego_lookup (cfg, 508 el = GNUNET_IDENTITY_ego_lookup (cfg,
440 zone_ego_name, 509 zone_ego_name,
441 &identity_zone_cb, 510 &identity_zone_cb,
442 NULL); 511 NULL);
443 return; 512 return;
444 } 513 }
445 if ( (NULL != lookup_name) && 514 if ( (NULL != lookup_name) &&
446 (strlen (lookup_name) > 4) && 515 (strlen (lookup_name) > 4) &&
447 (0 == strcmp (".zkey", 516 (0 == strcmp (".zkey",
448 &lookup_name[strlen (lookup_name) - 4])) ) 517 &lookup_name[strlen (lookup_name) - 4])) )
449 { 518 {
450 /* no zone required, use 'anonymous' zone */ 519 /* no zone required, use 'anonymous' zone */
451 GNUNET_CRYPTO_ecdsa_key_get_public (GNUNET_CRYPTO_ecdsa_key_get_anonymous (), 520 GNUNET_CRYPTO_ecdsa_key_get_public (GNUNET_CRYPTO_ecdsa_key_get_anonymous (),
452 &pkey); 521 &pkey);
453 lookup_with_public_key (&pkey); 522 lookup_with_public_key (&pkey);
454 } 523 }
455 else 524 else
456 { 525 {
457 GNUNET_break (NULL == id_op); 526 GNUNET_break (NULL == id_op);
458 id_op = GNUNET_IDENTITY_get (identity, 527 id_op = GNUNET_IDENTITY_get (identity,
459 "gns-master", 528 "gns-master",
460 &identity_master_cb, 529 &identity_master_cb,
461 NULL); 530 NULL);
462 GNUNET_assert (NULL != id_op); 531 GNUNET_assert (NULL != id_op);
463 } 532 }
464} 533}
@@ -493,6 +562,9 @@ main (int argc, char *const *argv)
493 {'z', "zone", "NAME", 562 {'z', "zone", "NAME",
494 gettext_noop ("Specify the name of the ego of the zone to lookup the record in"), 1, 563 gettext_noop ("Specify the name of the ego of the zone to lookup the record in"), 1,
495 &GNUNET_GETOPT_set_string, &zone_ego_name}, 564 &GNUNET_GETOPT_set_string, &zone_ego_name},
565 {'R', "reverse", "PKEY",
566 gettext_noop ("Specify the public key of the zone to reverse lookup a name for"), 1,
567 &GNUNET_GETOPT_set_string, &reverse_key},
496 GNUNET_GETOPT_OPTION_END 568 GNUNET_GETOPT_OPTION_END
497 }; 569 };
498 int ret; 570 int ret;
@@ -503,11 +575,11 @@ main (int argc, char *const *argv)
503 575
504 GNUNET_log_setup ("gnunet-gns", "WARNING", NULL); 576 GNUNET_log_setup ("gnunet-gns", "WARNING", NULL);
505 ret = 577 ret =
506 (GNUNET_OK == 578 (GNUNET_OK ==
507 GNUNET_PROGRAM_run (argc, argv, "gnunet-gns", 579 GNUNET_PROGRAM_run (argc, argv, "gnunet-gns",
508 _("GNUnet GNS resolver tool"), 580 _("GNUnet GNS resolver tool"),
509 options, 581 options,
510 &run, NULL)) ? 0 : 1; 582 &run, NULL)) ? 0 : 1;
511 GNUNET_free ((void*) argv); 583 GNUNET_free ((void*) argv);
512 return ret; 584 return ret;
513} 585}