diff options
Diffstat (limited to 'src/gns/gnunet-gns.c')
-rw-r--r-- | src/gns/gnunet-gns.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c index 1cda84c59..d795f89fc 100644 --- a/src/gns/gnunet-gns.c +++ b/src/gns/gnunet-gns.c | |||
@@ -60,6 +60,16 @@ static int raw; | |||
60 | static uint32_t rtype; | 60 | static uint32_t rtype; |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * Timeout for lookup | ||
64 | */ | ||
65 | static struct GNUNET_TIME_Relative timeout; | ||
66 | |||
67 | /** | ||
68 | * Timeout task | ||
69 | */ | ||
70 | static struct GNUNET_SCHEDULER_Task *to_task; | ||
71 | |||
72 | /** | ||
63 | * Handle to lookup request | 73 | * Handle to lookup request |
64 | */ | 74 | */ |
65 | static struct GNUNET_GNS_LookupWithTldRequest *lr; | 75 | static struct GNUNET_GNS_LookupWithTldRequest *lr; |
@@ -83,6 +93,11 @@ static void | |||
83 | do_shutdown (void *cls) | 93 | do_shutdown (void *cls) |
84 | { | 94 | { |
85 | (void) cls; | 95 | (void) cls; |
96 | if (NULL != to_task) | ||
97 | { | ||
98 | GNUNET_SCHEDULER_cancel (to_task); | ||
99 | to_task = NULL; | ||
100 | } | ||
86 | if (NULL != lr) | 101 | if (NULL != lr) |
87 | { | 102 | { |
88 | GNUNET_GNS_lookup_with_tld_cancel (lr); | 103 | GNUNET_GNS_lookup_with_tld_cancel (lr); |
@@ -95,6 +110,18 @@ do_shutdown (void *cls) | |||
95 | } | 110 | } |
96 | } | 111 | } |
97 | 112 | ||
113 | /** | ||
114 | * Task to run on timeout | ||
115 | * | ||
116 | * @param cls unused | ||
117 | */ | ||
118 | static void | ||
119 | do_timeout (void* cls) | ||
120 | { | ||
121 | to_task = NULL; | ||
122 | global_ret = 3; //Timeout | ||
123 | GNUNET_SCHEDULER_shutdown (); | ||
124 | } | ||
98 | 125 | ||
99 | /** | 126 | /** |
100 | * Function called with the result of a GNS lookup. | 127 | * Function called with the result of a GNS lookup. |
@@ -173,12 +200,14 @@ run (void *cls, | |||
173 | (void) cfgfile; | 200 | (void) cfgfile; |
174 | 201 | ||
175 | cfg = c; | 202 | cfg = c; |
203 | to_task = NULL; | ||
176 | if (GNUNET_OK != GNUNET_DNSPARSER_check_name (lookup_name)) | 204 | if (GNUNET_OK != GNUNET_DNSPARSER_check_name (lookup_name)) |
177 | { | 205 | { |
178 | fprintf (stderr, _ ("`%s' is not a valid domain name\n"), lookup_name); | 206 | fprintf (stderr, _ ("`%s' is not a valid domain name\n"), lookup_name); |
179 | global_ret = 3; | 207 | global_ret = 3; |
180 | return; | 208 | return; |
181 | } | 209 | } |
210 | to_task = GNUNET_SCHEDULER_add_delayed (timeout, &do_timeout, NULL); | ||
182 | gns = GNUNET_GNS_connect (cfg); | 211 | gns = GNUNET_GNS_connect (cfg); |
183 | if (NULL == gns) | 212 | if (NULL == gns) |
184 | { | 213 | { |
@@ -221,6 +250,7 @@ run (void *cls, | |||
221 | int | 250 | int |
222 | main (int argc, char *const *argv) | 251 | main (int argc, char *const *argv) |
223 | { | 252 | { |
253 | timeout = GNUNET_TIME_UNIT_FOREVER_REL; | ||
224 | struct GNUNET_GETOPT_CommandLineOption options[] = | 254 | struct GNUNET_GETOPT_CommandLineOption options[] = |
225 | {GNUNET_GETOPT_option_mandatory ( | 255 | {GNUNET_GETOPT_option_mandatory ( |
226 | GNUNET_GETOPT_option_string ('u', | 256 | GNUNET_GETOPT_option_string ('u', |
@@ -235,6 +265,12 @@ main (int argc, char *const *argv) | |||
235 | gettext_noop ( | 265 | gettext_noop ( |
236 | "Specify the type of the record to lookup"), | 266 | "Specify the type of the record to lookup"), |
237 | &lookup_type), | 267 | &lookup_type), |
268 | GNUNET_GETOPT_option_relative_time ('T', | ||
269 | "timeout", | ||
270 | "TIMEOUT", | ||
271 | gettext_noop ( | ||
272 | "Specify a timeout for the lookup"), | ||
273 | &timeout), | ||
238 | GNUNET_GETOPT_option_flag ('r', | 274 | GNUNET_GETOPT_option_flag ('r', |
239 | "raw", | 275 | "raw", |
240 | gettext_noop ("No unneeded output"), | 276 | gettext_noop ("No unneeded output"), |