GNUnet 0.28.1-dev.5-1-gae1c02d74
 
Loading...
Searching...
No Matches
gnunet-gns.c File Reference

command line tool to access distributed GNS More...

Include dependency graph for gnunet-gns.c:

Go to the source code of this file.

Functions

static void spin (void *cls)
 
static void do_shutdown (void *cls)
 Task run on shutdown.
 
static void do_timeout (void *cls)
 Task to run on timeout.
 
static void process_lookup_result (void *cls, int was_gns, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
 Function called with the result of a GNS lookup.
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
 Main function that will be run.
 
int main (int argc, char *const *argv)
 The main function for gnunet-gns.
 

Variables

static const struct GNUNET_CONFIGURATION_Handlecfg
 Configuration we are using.
 
static struct GNUNET_GNS_Handlegns
 Handle to GNS service.
 
static char * lookup_name
 GNS name to lookup.
 
char * idna_name
 DNS IDNA name to lookup.
 
static int dns_compat
 DNS compatibility (name is given as DNS name, possible IDNA).
 
static char * lookup_type
 record type to look up (-t option)
 
static int raw
 raw output
 
static uint32_t rtype
 Desired record type.
 
static struct GNUNET_TIME_Relative timeout
 Timeout for lookup.
 
static struct GNUNET_SCHEDULER_Taskto_task
 Timeout task.
 
static struct GNUNET_GNS_LookupWithTldRequestlr
 Handle to lookup request.
 
static int global_ret
 Global return value.
 
static const char spinner [] = {'|', '/', '-', '\\'}
 Spinner.
 
static struct GNUNET_SCHEDULER_Taskt_spinner
 Spinner task.
 
struct GNUNET_TIME_Absolute res_start
 Resolution start.
 

Detailed Description

command line tool to access distributed GNS

Author
Christian Grothoff

Definition in file gnunet-gns.c.

Function Documentation

◆ spin()

static void spin ( void *  cls)
static

Definition at line 125 of file gnunet-gns.c.

126{
127 static int i = 0;
128 printf ("%c\rResolving... ", spinner[i++ % sizeof spinner]);
129 fflush (stdout);
132 ),
133 &spin,
134 NULL);
135}
static const char spinner[]
Spinner.
Definition gnunet-gns.c:112
static void spin(void *cls)
Definition gnunet-gns.c:125
static struct GNUNET_SCHEDULER_Task * t_spinner
Spinner task.
Definition gnunet-gns.c:117
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition scheduler.c:1283
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition time.c:486

References GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_MILLISECONDS, spin(), spinner, and t_spinner.

Referenced by run(), and spin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Task run on shutdown.

Cleans up everything.

Parameters
clsunused

Definition at line 144 of file gnunet-gns.c.

145{
146 (void) cls;
147 if (NULL != t_spinner)
148 {
149 printf ("\nResolution cancelled after %s\n",
152 GNUNET_YES));
154 t_spinner = NULL;
155 }
156 if (NULL != to_task)
157 {
159 to_task = NULL;
160 }
161 if (NULL != lr)
162 {
164 lr = NULL;
165 }
166 if (NULL != gns)
167 {
169 gns = NULL;
170 }
171 if (NULL != idna_name)
172 {
174 idna_name = NULL;
175 }
176}
static struct GNUNET_GNS_Handle * gns
Handle to GNS service.
Definition gnunet-gns.c:53
struct GNUNET_TIME_Absolute res_start
Resolution start.
Definition gnunet-gns.c:122
static struct GNUNET_SCHEDULER_Task * to_task
Timeout task.
Definition gnunet-gns.c:93
char * idna_name
DNS IDNA name to lookup.
Definition gnunet-gns.c:63
static struct GNUNET_GNS_LookupWithTldRequest * lr
Handle to lookup request.
Definition gnunet-gns.c:98
void GNUNET_GNS_disconnect(struct GNUNET_GNS_Handle *handle)
Shutdown connection with the GNS service.
Definition gns_api.c:289
void * GNUNET_GNS_lookup_with_tld_cancel(struct GNUNET_GNS_LookupWithTldRequest *ltr)
Cancel pending lookup request.
@ GNUNET_YES
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition time.c:438
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:610

References gns, GNUNET_free, GNUNET_GNS_disconnect(), GNUNET_GNS_lookup_with_tld_cancel(), GNUNET_SCHEDULER_cancel(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_duration(), GNUNET_YES, idna_name, lr, res_start, t_spinner, and to_task.

Here is the call graph for this function:

◆ do_timeout()

static void do_timeout ( void *  cls)
static

Task to run on timeout.

Parameters
clsunused

Definition at line 185 of file gnunet-gns.c.

186{
187 to_task = NULL;
188 global_ret = 3; // Timeout
190}
static int global_ret
Global return value.
Definition gnunet-gns.c:107
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition scheduler.c:572

References global_ret, GNUNET_SCHEDULER_shutdown(), and to_task.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_lookup_result()

static void process_lookup_result ( void *  cls,
int  was_gns,
uint32_t  rd_count,
const struct GNUNET_GNSRECORD_Data rd 
)
static

Function called with the result of a GNS lookup.

Parameters
clsthe 'const char *' name that was resolved
was_gnsGNUNET_NO if TLD did not indicate use of GNS
rd_countnumber of records returned
rdarray of rd_count records with the results

Definition at line 202 of file gnunet-gns.c.

206{
207 struct GNUNET_TIME_Relative block_exp;
208 const char *typename;
209 char *string_val;
210
211 lr = NULL;
213 t_spinner = NULL;
214 if (GNUNET_NO == was_gns)
215 {
216 global_ret = 4; /* not for GNS */
218 return;
219 }
222 rd_count,
223 rd,
225 if (! raw)
226 {
227 printf ("\r<<< %u record(s) found:\n\n", rd_count);
228 }
229 for (uint32_t i = 0; i < rd_count; i++)
230 {
232 record_type);
233 string_val = GNUNET_GNSRECORD_value_to_string (rd[i].record_type
234 ,
235 rd[i].data,
236 rd[i].data_size);
237 if (NULL == string_val)
238 {
239 fprintf (stderr,
240 "Record %u of type %d malformed, skipping\n",
241 (unsigned int) i,
242 (int) rd[i].record_type);
243 continue;
244 }
245 if (raw)
246 printf ("%s\n", string_val);
247 else
248 printf ("%s: `%s' %s\n",
249 typename,
250 string_val,
251 (0 != (rd[i].flags
252 &
254 ) ?
255 "(supplemental)" : "");
256 GNUNET_free (string_val);
257 }
258 if (! raw)
259 {
260 printf ("\nResolution finished after %s\n",
263 GNUNET_YES));
264 if (0 != rd_count)
265 printf ("Record set expires in %s.\n",
267 block_exp, GNUNET_YES));
268 }
270}
static char * data
The data to insert into the dht.
static int raw
raw output
Definition gnunet-gns.c:78
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 size_t data_size
Number of bytes in data.
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
struct GNUNET_TIME_Absolute GNUNET_GNSRECORD_record_get_expiration_time(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, struct GNUNET_TIME_Absolute min)
Returns the expiration time of the given block of records.
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_SUPPLEMENTAL
This is a supplemental record.
@ GNUNET_NO
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition time.c:406
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
Time for relative time used by GNUnet, in microseconds.

References data, data_size, global_ret, GNUNET_free, GNUNET_GNSRECORD_number_to_typename(), GNUNET_GNSRECORD_record_get_expiration_time(), GNUNET_GNSRECORD_RF_SUPPLEMENTAL, GNUNET_GNSRECORD_value_to_string(), GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_SCHEDULER_shutdown(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_YES, lr, raw, rd, rd_count, res_start, and t_spinner.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle c 
)
static

Main function that will be run.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cconfiguration

If DNS compatibility is requested, we first verify that the lookup_name is in a DNS format. If yes, we convert it to UTF-8.

Definition at line 282 of file gnunet-gns.c.

286{
287 const char *effective_lookup_type;
288 (void) cls;
289 (void) args;
290 (void) cfgfile;
291
292 cfg = c;
293 to_task = NULL;
294 {
295 char *colon;
296
297 if (NULL != (colon = strchr (lookup_name, ':')))
298 *colon = '\0';
299 }
300
305 if (GNUNET_YES == dns_compat)
306 {
307 Idna_rc rc;
308
310 {
311 fprintf (stderr,
312 _ ("`%s' is not a valid DNS domain name\n"),
314 global_ret = 3;
315 return;
316 }
317 if (IDNA_SUCCESS !=
318 (rc = idna_to_unicode_8z8z (lookup_name, &idna_name,
319 IDNA_ALLOW_UNASSIGNED)))
320 {
321 fprintf (stderr,
322 _ (
323 "Failed to convert DNS IDNA name `%s' to UTF-8: %s\n"),
325 idna_strerror (rc));
326 global_ret = 4;
327 return;
328 }
330 }
331
332 if (GNUNET_YES !=
334 "arm"))
335 {
337 _ (
338 "Cannot resolve using GNS: GNUnet peer not running\n"));
339 global_ret = 5;
340 return;
341 }
343 &do_timeout,
344 NULL);
346 if (NULL == gns)
347 {
348 fprintf (stderr,
349 _ ("Failed to connect to GNS\n"));
350 global_ret = 2;
351 return;
352 }
354 NULL);
355 if (NULL != lookup_type)
356 {
357 effective_lookup_type = lookup_type;
359 }
360 else
361 {
362 effective_lookup_type = "A";
364 }
365 if (UINT32_MAX == rtype)
366 {
367 fprintf (stderr,
368 _ ("Invalid typename specified, assuming `ANY'\n"));
370 }
371 if (! raw)
372 {
373 printf (">>> Looking for `%s' records under `%s'\n",
374 effective_lookup_type, lookup_name);
375 }
380 rtype,
384 if (NULL == lr)
385 {
386 global_ret = 2;
389 return;
390 }
391}
static int do_shutdown
Set to GNUNET_YES if we are shutting down.
static void do_timeout(void *cls)
Task to run on timeout.
Definition gnunet-gns.c:185
static char * lookup_name
GNS name to lookup.
Definition gnunet-gns.c:58
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition gnunet-gns.c:48
static int dns_compat
DNS compatibility (name is given as DNS name, possible IDNA).
Definition gnunet-gns.c:68
static struct GNUNET_TIME_Relative timeout
Timeout for lookup.
Definition gnunet-gns.c:88
static void process_lookup_result(void *cls, int was_gns, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Function called with the result of a GNS lookup.
Definition gnunet-gns.c:202
static char * lookup_type
record type to look up (-t option)
Definition gnunet-gns.c:73
static uint32_t rtype
Desired record type.
Definition gnunet-gns.c:83
enum GNUNET_GenericReturnValue GNUNET_CLIENT_test(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name)
Test if the port or UNIXPATH of the given service_name is in use and thus (most likely) the respectiv...
Definition client.c:1006
#define GNUNET_DNSPARSER_TYPE_A
enum GNUNET_GenericReturnValue GNUNET_DNSPARSER_check_name(const char *name)
Check if a hostname in UTF-8 format can be coded into valid IDNA.
Definition dnsparser.c:79
struct GNUNET_GNS_LookupWithTldRequest * GNUNET_GNS_lookup_with_tld(struct GNUNET_GNS_Handle *handle, const char *name, uint32_t type, enum GNUNET_GNS_LocalOptions options, GNUNET_GNS_LookupResultProcessor2 proc, void *proc_cls)
Perform an asynchronous lookup operation on the GNS, determining the zone using the TLD of the given ...
struct GNUNET_GNS_Handle * GNUNET_GNS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the connection with the GNS service.
Definition gns_api.c:267
@ GNUNET_GNS_LO_DEFAULT
Defaults, look in cache, then in DHT.
uint32_t GNUNET_GNSRECORD_typename_to_number(const char *dns_typename)
Convert a type name (e.g.
Definition gnsrecord.c:192
#define GNUNET_GNSRECORD_TYPE_ANY
Record type indicating any record/'*'.
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_ERROR_TYPE_WARNING
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:1345
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:1310
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition time.c:111
#define _(String)
GNU gettext support macro.
Definition platform.h:179

References _, cfg, dns_compat, do_shutdown, do_timeout(), global_ret, gns, GNUNET_CLIENT_test(), GNUNET_DNSPARSER_check_name(), GNUNET_DNSPARSER_TYPE_A, GNUNET_ERROR_TYPE_WARNING, GNUNET_GNS_connect(), GNUNET_GNS_LO_DEFAULT, GNUNET_GNS_lookup_with_tld(), GNUNET_GNSRECORD_TYPE_ANY, GNUNET_GNSRECORD_typename_to_number(), GNUNET_log, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_cancel(), GNUNET_SCHEDULER_shutdown(), GNUNET_TIME_absolute_get(), GNUNET_YES, idna_name, lookup_name, lookup_type, lr, process_lookup_result(), raw, res_start, rtype, spin(), t_spinner, timeout, and to_task.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function for gnunet-gns.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 402 of file gnunet-gns.c.

403{
407 "lookup",
408 "NAME",
410 "Lookup a record for the given name"),
411 &lookup_name)),
413 "type",
414 "TYPE",
416 "Specify the type of the record to lookup"),
417 &lookup_type),
419 "timeout",
420 "TIMEOUT",
422 "Specify a timeout for the lookup"),
423 &timeout),
425 "raw",
426 gettext_noop ("No unneeded output"),
427 &raw),
429 "dns",
431 "DNS Compatibility: Name is passed in IDNA instead of UTF-8"),
432 &dns_compat),
434 int ret;
436
437 GNUNET_log_setup ("gnunet-gns", "WARNING", NULL);
439 argc,
440 argv,
441 "gnunet-gns",
442 _ ("GNUnet GNS resolver tool"),
443 options,
444 &run,
445 NULL);
446 if (GNUNET_OK != ret)
447 return 1;
448 return global_ret;
449}
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
#define gettext_noop(String)
Definition gettext.h:74
static int ret
Final status code.
Definition gnunet-arm.c:93
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Main function that will be run.
Definition gnunet-gns.c:282
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_mandatory(struct GNUNET_GETOPT_CommandLineOption opt)
Make the given option mandatory.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_relative_time(char shortName, const char *name, const char *argumentHelp, const char *description, struct GNUNET_TIME_Relative *val)
Allow user to specify a struct GNUNET_TIME_Relative (using human-readable "fancy" time).
#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.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
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:406
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
Definition of a command line option.

References _, dns_compat, gettext_noop, global_ret, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_mandatory(), GNUNET_GETOPT_option_relative_time(), GNUNET_GETOPT_option_string(), GNUNET_log_setup(), GNUNET_OK, GNUNET_OS_project_data_gnunet(), GNUNET_PROGRAM_run(), GNUNET_TIME_UNIT_FOREVER_REL, lookup_name, lookup_type, options, raw, ret, run(), and timeout.

Here is the call graph for this function:

Variable Documentation

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Configuration we are using.

Definition at line 48 of file gnunet-gns.c.

Referenced by run().

◆ gns

struct GNUNET_GNS_Handle* gns
static

Handle to GNS service.

Definition at line 53 of file gnunet-gns.c.

Referenced by do_shutdown(), and run().

◆ lookup_name

char* lookup_name
static

GNS name to lookup.

(-u option)

Definition at line 58 of file gnunet-gns.c.

Referenced by main(), and run().

◆ idna_name

char* idna_name

DNS IDNA name to lookup.

(set if -d option is set)

Definition at line 63 of file gnunet-gns.c.

Referenced by do_shutdown(), GNUNET_DNSPARSER_builder_add_name(), and run().

◆ dns_compat

int dns_compat
static

DNS compatibility (name is given as DNS name, possible IDNA).

Definition at line 68 of file gnunet-gns.c.

Referenced by main(), and run().

◆ lookup_type

char* lookup_type
static

record type to look up (-t option)

Definition at line 73 of file gnunet-gns.c.

Referenced by main(), and run().

◆ raw

int raw
static

raw output

Definition at line 78 of file gnunet-gns.c.

Referenced by bf_group_serialize_cb(), build_dns_query(), main(), process_lookup_result(), process_queue(), queue(), and run().

◆ rtype

uint32_t rtype
static

Desired record type.

Definition at line 83 of file gnunet-gns.c.

Referenced by run().

◆ timeout

struct GNUNET_TIME_Relative timeout
static

Timeout for lookup.

Definition at line 88 of file gnunet-gns.c.

Referenced by main(), and run().

◆ to_task

struct GNUNET_SCHEDULER_Task* to_task
static

Timeout task.

Definition at line 93 of file gnunet-gns.c.

Referenced by do_shutdown(), do_timeout(), and run().

◆ lr

◆ global_ret

int global_ret
static

Global return value.

0 on success (default), 1 on internal failures 2 on launch failure, 4 if the name is not a GNS-supported TLD,

Definition at line 107 of file gnunet-gns.c.

Referenced by do_timeout(), main(), process_lookup_result(), and run().

◆ spinner

const char spinner[] = {'|', '/', '-', '\\'}
static

Spinner.

Definition at line 112 of file gnunet-gns.c.

112{'|', '/', '-', '\\'};

Referenced by spin().

◆ t_spinner

struct GNUNET_SCHEDULER_Task* t_spinner
static

Spinner task.

Definition at line 117 of file gnunet-gns.c.

Referenced by do_shutdown(), process_lookup_result(), run(), and spin().

◆ res_start

struct GNUNET_TIME_Absolute res_start

Resolution start.

Definition at line 122 of file gnunet-gns.c.

Referenced by do_shutdown(), process_lookup_result(), and run().