summaryrefslogtreecommitdiff
path: root/src/dht/gnunet-dht-get.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/gnunet-dht-get.c')
-rw-r--r--src/dht/gnunet-dht-get.c149
1 files changed, 77 insertions, 72 deletions
diff --git a/src/dht/gnunet-dht-get.c b/src/dht/gnunet-dht-get.c
index b42326fc5..af667584b 100644
--- a/src/dht/gnunet-dht-get.c
+++ b/src/dht/gnunet-dht-get.c
@@ -26,7 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_dht_service.h" 27#include "gnunet_dht_service.h"
28 28
29#define LOG(kind,...) GNUNET_log_from (kind, "dht-clients",__VA_ARGS__) 29#define LOG(kind, ...) GNUNET_log_from (kind, "dht-clients", __VA_ARGS__)
30/** 30/**
31 * The type of the query 31 * The type of the query
32 */ 32 */
@@ -45,7 +45,7 @@ static char *query_key;
45/** 45/**
46 * User supplied timeout value 46 * User supplied timeout value
47 */ 47 */
48static struct GNUNET_TIME_Relative timeout_request = { 60000 }; 48static struct GNUNET_TIME_Relative timeout_request = {60000};
49 49
50/** 50/**
51 * Be verbose 51 * Be verbose
@@ -143,8 +143,9 @@ timeout_task (void *cls)
143 * @param data pointer to the result data 143 * @param data pointer to the result data
144 */ 144 */
145static void 145static void
146get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp, 146get_result_iterator (void *cls,
147 const struct GNUNET_HashCode * key, 147 struct GNUNET_TIME_Absolute exp,
148 const struct GNUNET_HashCode *key,
148 const struct GNUNET_PeerIdentity *get_path, 149 const struct GNUNET_PeerIdentity *get_path,
149 unsigned int get_path_length, 150 unsigned int get_path_length,
150 const struct GNUNET_PeerIdentity *put_path, 151 const struct GNUNET_PeerIdentity *put_path,
@@ -153,32 +154,22 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
153 size_t size, 154 size_t size,
154 const void *data) 155 const void *data)
155{ 156{
156 FPRINTF (stdout, 157 fprintf (stdout,
157 (GNUNET_BLOCK_TYPE_TEST == type) 158 (GNUNET_BLOCK_TYPE_TEST == type) ? _ ("Result %d, type %d:\n%.*s\n")
158 ? _("Result %d, type %d:\n%.*s\n") 159 : _ ("Result %d, type %d:\n"),
159 : _("Result %d, type %d:\n"), 160 result_count,
160 result_count,
161 type, 161 type,
162 (unsigned int) size, 162 (unsigned int) size,
163 (char *) data); 163 (char *) data);
164 if (verbose) 164 if (verbose)
165 { 165 {
166 FPRINTF (stdout, 166 fprintf (stdout, " GET path: ");
167 " GET path: "); 167 for (unsigned int i = 0; i < get_path_length; i++)
168 for (unsigned int i=0;i<get_path_length;i++) 168 fprintf (stdout, "%s%s", (0 == i) ? "" : "-", GNUNET_i2s (&get_path[i]));
169 FPRINTF (stdout, 169 fprintf (stdout, "\n PUT path: ");
170 "%s%s", 170 for (unsigned int i = 0; i < put_path_length; i++)
171 (0 == i) ? "" : "-", 171 fprintf (stdout, "%s%s", (0 == i) ? "" : "-", GNUNET_i2s (&put_path[i]));
172 GNUNET_i2s (&get_path[i])); 172 fprintf (stdout, "\n");
173 FPRINTF (stdout,
174 "\n PUT path: ");
175 for (unsigned int i=0;i<put_path_length;i++)
176 FPRINTF (stdout,
177 "%s%s",
178 (0 == i) ? "" : "-",
179 GNUNET_i2s (&put_path[i]));
180 FPRINTF (stdout,
181 "\n");
182 } 173 }
183 result_count++; 174 result_count++;
184} 175}
@@ -193,7 +184,9 @@ get_result_iterator (void *cls, struct GNUNET_TIME_Absolute exp,
193 * @param c configuration 184 * @param c configuration
194 */ 185 */
195static void 186static void
196run (void *cls, char *const *args, const char *cfgfile, 187run (void *cls,
188 char *const *args,
189 const char *cfgfile,
197 const struct GNUNET_CONFIGURATION_Handle *c) 190 const struct GNUNET_CONFIGURATION_Handle *c)
198{ 191{
199 struct GNUNET_HashCode key; 192 struct GNUNET_HashCode key;
@@ -201,33 +194,37 @@ run (void *cls, char *const *args, const char *cfgfile,
201 cfg = c; 194 cfg = c;
202 if (NULL == query_key) 195 if (NULL == query_key)
203 { 196 {
204 FPRINTF (stderr, "%s", _("Must provide key for DHT GET!\n")); 197 fprintf (stderr, "%s", _ ("Must provide key for DHT GET!\n"));
205 ret = 1; 198 ret = 1;
206 return; 199 return;
207 } 200 }
208 if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1))) 201 if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1)))
209 { 202 {
210 FPRINTF (stderr, "%s", _("Failed to connect to DHT service!\n")); 203 fprintf (stderr, "%s", _ ("Failed to connect to DHT service!\n"));
211 ret = 1; 204 ret = 1;
212 return; 205 return;
213 } 206 }
214 if (query_type == GNUNET_BLOCK_TYPE_ANY) /* Type of data not set */ 207 if (query_type == GNUNET_BLOCK_TYPE_ANY) /* Type of data not set */
215 query_type = GNUNET_BLOCK_TYPE_TEST; 208 query_type = GNUNET_BLOCK_TYPE_TEST;
216 GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key); 209 GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key);
217 if (verbose) 210 if (verbose)
218 FPRINTF (stderr, "%s `%s' \n", 211 fprintf (stderr,
219 _("Issuing DHT GET with key"), 212 "%s `%s' \n",
213 _ ("Issuing DHT GET with key"),
220 GNUNET_h2s_full (&key)); 214 GNUNET_h2s_full (&key));
221 GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL); 215 GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL);
222 tt = GNUNET_SCHEDULER_add_delayed (timeout_request, 216 tt = GNUNET_SCHEDULER_add_delayed (timeout_request, &timeout_task, NULL);
223 &timeout_task, 217 get_handle = GNUNET_DHT_get_start (dht_handle,
218 query_type,
219 &key,
220 replication,
221 (demultixplex_everywhere)
222 ? GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE
223 : GNUNET_DHT_RO_NONE,
224 NULL,
225 0,
226 &get_result_iterator,
224 NULL); 227 NULL);
225 get_handle =
226 GNUNET_DHT_get_start (dht_handle, query_type, &key, replication,
227 (demultixplex_everywhere) ? GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE : GNUNET_DHT_RO_NONE,
228 NULL, 0,
229 &get_result_iterator,
230 NULL);
231} 228}
232 229
233 230
@@ -241,44 +238,52 @@ run (void *cls, char *const *args, const char *cfgfile,
241int 238int
242main (int argc, char *const *argv) 239main (int argc, char *const *argv)
243{ 240{
244 struct GNUNET_GETOPT_CommandLineOption options[] = { 241 struct GNUNET_GETOPT_CommandLineOption options[] =
245 GNUNET_GETOPT_option_string ('k', 242 {GNUNET_GETOPT_option_string ('k',
246 "key", 243 "key",
247 "KEY", 244 "KEY",
248 gettext_noop ("the query key"), 245 gettext_noop ("the query key"),
249 &query_key), 246 &query_key),
250 GNUNET_GETOPT_option_uint ('r', 247 GNUNET_GETOPT_option_uint (
251 "replication", 248 'r',
252 "LEVEL", 249 "replication",
253 gettext_noop ("how many parallel requests (replicas) to create"), 250 "LEVEL",
254 &replication), 251 gettext_noop ("how many parallel requests (replicas) to create"),
255 GNUNET_GETOPT_option_uint ('t', 252 &replication),
256 "type", 253 GNUNET_GETOPT_option_uint ('t',
257 "TYPE", 254 "type",
258 gettext_noop ("the type of data to look for"), 255 "TYPE",
259 &query_type), 256 gettext_noop ("the type of data to look for"),
260 GNUNET_GETOPT_option_relative_time ('T', 257 &query_type),
261 "timeout", 258 GNUNET_GETOPT_option_relative_time (
262 "TIMEOUT", 259 'T',
263 gettext_noop ("how long to execute this query before giving up?"), 260 "timeout",
264 &timeout_request), 261 "TIMEOUT",
265 GNUNET_GETOPT_option_flag ('x', 262 gettext_noop ("how long to execute this query before giving up?"),
266 "demultiplex", 263 &timeout_request),
267 gettext_noop ("use DHT's demultiplex everywhere option"), 264 GNUNET_GETOPT_option_flag ('x',
268 &demultixplex_everywhere), 265 "demultiplex",
269 GNUNET_GETOPT_option_verbose (&verbose), 266 gettext_noop (
270 GNUNET_GETOPT_OPTION_END 267 "use DHT's demultiplex everywhere option"),
271 }; 268 &demultixplex_everywhere),
272 269 GNUNET_GETOPT_option_verbose (&verbose),
270 GNUNET_GETOPT_OPTION_END};
273 271
274 272
275 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 273 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
276 return 2; 274 return 2;
277 return (GNUNET_OK == 275 return (GNUNET_OK ==
278 GNUNET_PROGRAM_run (argc, argv, "gnunet-dht-get", 276 GNUNET_PROGRAM_run (
279 gettext_noop 277 argc,
280 ("Issue a GET request to the GNUnet DHT, prints results."), 278 argv,
281 options, &run, NULL)) ? ret : 1; 279 "gnunet-dht-get",
280 gettext_noop (
281 "Issue a GET request to the GNUnet DHT, prints results."),
282 options,
283 &run,
284 NULL))
285 ? ret
286 : 1;
282} 287}
283 288
284/* end of gnunet-dht-get.c */ 289/* end of gnunet-dht-get.c */