aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-08-13 17:48:54 +0000
committerChristian Grothoff <christian@grothoff.org>2013-08-13 17:48:54 +0000
commitbc7d219460d5ef0511164eb90039710940d905dd (patch)
treeacd96a93da163e17d3af3fe70c4e905e559fc84a
parent37070fdc2fb6fd36ccae94d93067b0bdb7ee9350 (diff)
downloadgnunet-bc7d219460d5ef0511164eb90039710940d905dd.tar.gz
gnunet-bc7d219460d5ef0511164eb90039710940d905dd.zip
-more work on simplified GNS API implementation
-rw-r--r--src/gns/gns_api.c24
-rw-r--r--src/gns/gnunet-gns.c225
-rw-r--r--src/include/gnunet_gns_service.h4
3 files changed, 55 insertions, 198 deletions
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c
index 9bc85efea..6472018f8 100644
--- a/src/gns/gns_api.c
+++ b/src/gns/gns_api.c
@@ -489,7 +489,7 @@ GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle)
489 * @param lr the lookup request to cancel 489 * @param lr the lookup request to cancel
490 */ 490 */
491void 491void
492GNUNET_GNS_cancel_lookup_request (struct GNUNET_GNS_LookupRequest *lr) 492GNUNET_GNS_lookup_cancel (struct GNUNET_GNS_LookupRequest *lr)
493{ 493{
494 struct PendingMessage *p = (struct PendingMessage*) &lr[1]; 494 struct PendingMessage *p = (struct PendingMessage*) &lr[1];
495 495
@@ -519,14 +519,14 @@ GNUNET_GNS_cancel_lookup_request (struct GNUNET_GNS_LookupRequest *lr)
519 * @return handle to the get request 519 * @return handle to the get request
520 */ 520 */
521struct GNUNET_GNS_LookupRequest* 521struct GNUNET_GNS_LookupRequest*
522GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle, 522GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
523 const char *name, 523 const char *name,
524 struct GNUNET_CRYPTO_ShortHashCode *zone, 524 const struct GNUNET_CRYPTO_EccPublicKey *zone,
525 int type, 525 int type,
526 int only_cached, 526 int only_cached,
527 struct GNUNET_CRYPTO_EccPrivateKey *shorten_key, 527 const struct GNUNET_CRYPTO_EccPrivateKey *shorten_key,
528 GNUNET_GNS_LookupResultProcessor proc, 528 GNUNET_GNS_LookupResultProcessor proc,
529 void *proc_cls) 529 void *proc_cls)
530{ 530{
531 /* IPC to shorten gns names, return shorten_handle */ 531 /* IPC to shorten gns names, return shorten_handle */
532 struct GNUNET_GNS_ClientLookupMessage *lookup_msg; 532 struct GNUNET_GNS_ClientLookupMessage *lookup_msg;
@@ -566,11 +566,7 @@ GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle,
566 lookup_msg->header.size = htons (msize); 566 lookup_msg->header.size = htons (msize);
567 lookup_msg->id = htonl (lr->r_id); 567 lookup_msg->id = htonl (lr->r_id);
568 lookup_msg->only_cached = htonl (only_cached); 568 lookup_msg->only_cached = htonl (only_cached);
569 if (NULL != zone) 569 lookup_msg->zone = *zone;
570 {
571 lookup_msg->have_zone = htonl (GNUNET_YES);
572 lookup_msg->zone = *zone;
573 }
574 lookup_msg->type = htonl (type); 570 lookup_msg->type = htonl (type);
575 if (NULL != shorten_key) 571 if (NULL != shorten_key)
576 { 572 {
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c
index d3b61d510..d58018d20 100644
--- a/src/gns/gnunet-gns.c
+++ b/src/gns/gnunet-gns.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2012 Christian Grothoff (and other contributing authors) 3 (C) 2012-2013 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -35,11 +35,6 @@
35static struct GNUNET_GNS_Handle *gns; 35static struct GNUNET_GNS_Handle *gns;
36 36
37/** 37/**
38 * GNS name to shorten. (-s option)
39 */
40static char *shorten_name;
41
42/**
43 * GNS name to lookup. (-u option) 38 * GNS name to lookup. (-u option)
44 */ 39 */
45static char *lookup_name; 40static char *lookup_name;
@@ -50,11 +45,6 @@ static char *lookup_name;
50static char *lookup_type; 45static char *lookup_type;
51 46
52/** 47/**
53 * name to look up authority for (-a option)
54 */
55static char *auth_name;
56
57/**
58 * raw output 48 * raw output
59 */ 49 */
60static int raw; 50static int raw;
@@ -69,16 +59,6 @@ static int rtype;
69 */ 59 */
70static struct GNUNET_GNS_LookupRequest *lookup_request; 60static struct GNUNET_GNS_LookupRequest *lookup_request;
71 61
72/**
73 * Handle to shorten request
74 */
75static struct GNUNET_GNS_ShortenRequest *shorten_request;
76
77/**
78 * Handle to get authority request
79 */
80static struct GNUNET_GNS_GetAuthRequest *getauth_request;
81
82 62
83/** 63/**
84 * Task run on shutdown. Cleans up everything. 64 * Task run on shutdown. Cleans up everything.
@@ -92,19 +72,9 @@ do_shutdown (void *cls,
92{ 72{
93 if (NULL != lookup_request) 73 if (NULL != lookup_request)
94 { 74 {
95 GNUNET_GNS_cancel_lookup_request (lookup_request); 75 GNUNET_GNS_lookup_cancel (lookup_request);
96 lookup_request = NULL; 76 lookup_request = NULL;
97 } 77 }
98 if (NULL != shorten_request)
99 {
100 GNUNET_GNS_cancel_shorten_request (shorten_request);
101 shorten_request = NULL;
102 }
103 if (NULL != getauth_request)
104 {
105 GNUNET_GNS_cancel_get_auth_request (getauth_request);
106 getauth_request = NULL;
107 }
108 if (NULL != gns) 78 if (NULL != gns)
109 { 79 {
110 GNUNET_GNS_disconnect (gns); 80 GNUNET_GNS_disconnect (gns);
@@ -114,27 +84,6 @@ do_shutdown (void *cls,
114 84
115 85
116/** 86/**
117 * Function called with the result of a shorten operation.
118 * Prints the result.
119 *
120 * @param cls a 'const char *' with the original (long) name
121 * @param nshort the shortened name
122 */
123static void
124process_shorten_result (void* cls, const char *nshort)
125{
126 const char *original_name = cls;
127
128 shorten_request = NULL;
129 if (raw)
130 printf("%s", nshort);
131 else
132 printf("%s shortened to %s\n", original_name, nshort);
133 GNUNET_SCHEDULER_shutdown ();
134}
135
136
137/**
138 * Function called with the result of a GADS lookup. 87 * Function called with the result of a GADS lookup.
139 * 88 *
140 * @param cls the 'const char *' name that was resolved 89 * @param cls the 'const char *' name that was resolved
@@ -142,21 +91,22 @@ process_shorten_result (void* cls, const char *nshort)
142 * @param rd array of 'rd_count' records with the results 91 * @param rd array of 'rd_count' records with the results
143 */ 92 */
144static void 93static void
145process_lookup_result (void* cls, uint32_t rd_count, 94process_lookup_result (void *cls, uint32_t rd_count,
146 const struct GNUNET_NAMESTORE_RecordData *rd) 95 const struct GNUNET_NAMESTORE_RecordData *rd)
147{ 96{
148 const char* name = cls; 97 const char *name = cls;
149 uint32_t i; 98 uint32_t i;
150 const char* typename; 99 const char *typename;
151 char* string_val; 100 char* string_val;
152 101
153 lookup_request = NULL; 102 lookup_request = NULL;
154 if (!raw) 103 if (!raw)
155 { 104 {
156 if (0 == rd_count) 105 if (0 == rd_count)
157 printf("No results.\n"); 106 printf ("No results.\n");
158 else 107 else
159 printf("%s:\n", name); 108 printf ("%s:\n",
109 name);
160 } 110 }
161 for (i=0; i<rd_count; i++) 111 for (i=0; i<rd_count; i++)
162 { 112 {
@@ -165,9 +115,12 @@ process_lookup_result (void* cls, uint32_t rd_count,
165 rd[i].data, 115 rd[i].data,
166 rd[i].data_size); 116 rd[i].data_size);
167 if (raw) 117 if (raw)
168 printf ("%s\n", string_val); 118 printf ("%s\n",
119 string_val);
169 else 120 else
170 printf ("Got `%s' record: %s\n", typename, string_val); 121 printf ("Got `%s' record: %s\n",
122 typename,
123 string_val);
171 GNUNET_free_non_null (string_val); 124 GNUNET_free_non_null (string_val);
172 } 125 }
173 GNUNET_SCHEDULER_shutdown (); 126 GNUNET_SCHEDULER_shutdown ();
@@ -175,23 +128,6 @@ process_lookup_result (void* cls, uint32_t rd_count,
175 128
176 129
177/** 130/**
178 * Function called with the result of an authority lookup.
179 *
180 * @param cls the 'const char *' with the name for which the
181 * authority was resolved
182 * @param auth name of the authority
183 */
184static void
185process_auth_result (void* cls,
186 const char *auth)
187{
188 getauth_request = NULL;
189 printf ("%s\n", auth);
190 GNUNET_SCHEDULER_shutdown ();
191}
192
193
194/**
195 * Main function that will be run. 131 * Main function that will be run.
196 * 132 *
197 * @param cls closure 133 * @param cls closure
@@ -203,16 +139,10 @@ static void
203run (void *cls, char *const *args, const char *cfgfile, 139run (void *cls, char *const *args, const char *cfgfile,
204 const struct GNUNET_CONFIGURATION_Handle *cfg) 140 const struct GNUNET_CONFIGURATION_Handle *cfg)
205{ 141{
206 char* keyfile; 142 char *keyfile;
207 struct GNUNET_CRYPTO_EccPrivateKey *key = NULL; 143 struct GNUNET_CRYPTO_EccPrivateKey *key;
208 struct GNUNET_CRYPTO_EccPublicKey pkey; 144 struct GNUNET_CRYPTO_EccPublicKey pkey;
209 struct GNUNET_CRYPTO_ShortHashCode *zone = NULL; 145 struct GNUNET_CRYPTO_EccPrivateKey *shorten_key;
210 struct GNUNET_CRYPTO_ShortHashCode user_zone;
211 struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename;
212 struct GNUNET_CRYPTO_EccPrivateKey *shorten_key = NULL;
213 struct GNUNET_CRYPTO_EccPrivateKey *private_key = NULL;
214 struct GNUNET_CRYPTO_ShortHashCode *private_zone = NULL;
215 struct GNUNET_CRYPTO_ShortHashCode *shorten_zone = NULL;
216 146
217 gns = GNUNET_GNS_connect (cfg); 147 gns = GNUNET_GNS_connect (cfg);
218 if (NULL == gns) 148 if (NULL == gns)
@@ -224,118 +154,55 @@ run (void *cls, char *const *args, const char *cfgfile,
224 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", 154 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
225 "ZONEKEY", &keyfile)) 155 "ZONEKEY", &keyfile))
226 { 156 {
227 if (! raw) 157 fprintf (stderr,
228 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 158 "Need zone to perform lookup in!\n");
229 "No private key for root zone found, using default!\n"); 159 GNUNET_SCHEDULER_shutdown ();
230 } 160 return;
231 else
232 {
233 key = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile);
234 GNUNET_CRYPTO_ecc_key_get_public (key, &pkey);
235 GNUNET_CRYPTO_short_hash (&pkey,
236 sizeof(struct GNUNET_CRYPTO_EccPublicKey),
237 &user_zone);
238 zone = &user_zone;
239 GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename);
240 if (!raw)
241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
242 "Using zone: %s!\n", &zonename);
243 GNUNET_CRYPTO_ecc_key_free (key);
244 GNUNET_free(keyfile);
245 } 161 }
162 /* FIXME: use identity service and/or allow user to specify public key! */
163 key = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile);
164 GNUNET_CRYPTO_ecc_key_get_public (key, &pkey);
165 GNUNET_CRYPTO_ecc_key_free (key);
166 GNUNET_free (keyfile);
246 167
247 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", 168 if (GNUNET_OK !=
248 "SHORTEN_ZONEKEY", &keyfile)) 169 GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
170 "SHORTEN_ZONEKEY", &keyfile))
249 { 171 {
250 if (! raw) 172 shorten_key = NULL;
251 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
252 "No shorten key found!\n");
253 } 173 }
254 else 174 else
255 { 175 {
176 // FIXME: use identity service!
256 shorten_key = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile); 177 shorten_key = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile);
257 GNUNET_CRYPTO_ecc_key_get_public (shorten_key, &pkey);
258 shorten_zone = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_ShortHashCode));
259 GNUNET_CRYPTO_short_hash(&pkey,
260 sizeof(struct GNUNET_CRYPTO_EccPublicKey),
261 shorten_zone);
262 GNUNET_CRYPTO_short_hash_to_enc (shorten_zone, &zonename);
263 if (! raw)
264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
265 "Using shorten zone: %s!\n", &zonename);
266 GNUNET_free (keyfile); 178 GNUNET_free (keyfile);
267 } 179 }
268 180
269 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
270 "PRIVATE_ZONEKEY", &keyfile))
271 {
272 if (! raw)
273 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
274 "No private zone key file name specified in configuration!\n");
275 }
276 else
277 {
278 private_key = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile);
279 GNUNET_CRYPTO_ecc_key_get_public (private_key, &pkey);
280 private_zone = GNUNET_new (struct GNUNET_CRYPTO_ShortHashCode);
281 GNUNET_CRYPTO_short_hash (&pkey,
282 sizeof(struct GNUNET_CRYPTO_EccPublicKey),
283 private_zone);
284 GNUNET_CRYPTO_short_hash_to_enc (private_zone, &zonename);
285 if (! raw)
286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
287 "Using private zone: %s!\n", &zonename);
288 GNUNET_CRYPTO_ecc_key_free (private_key);
289 }
290
291 if (NULL != lookup_type) 181 if (NULL != lookup_type)
292 rtype = GNUNET_NAMESTORE_typename_to_number (lookup_type); 182 rtype = GNUNET_NAMESTORE_typename_to_number (lookup_type);
293 else 183 else
294 rtype = GNUNET_DNSPARSER_TYPE_A; 184 rtype = GNUNET_DNSPARSER_TYPE_A;
295 185
296 if ( (NULL != shorten_name) &&
297 (NULL != shorten_zone) &&
298 (NULL != private_zone) )
299 {
300 shorten_request = GNUNET_GNS_shorten_zone (gns, shorten_name,
301 private_zone,
302 shorten_zone,
303 zone,
304 &process_shorten_result,
305 shorten_name);
306 }
307 if (NULL != lookup_name) 186 if (NULL != lookup_name)
308 { 187 {
309 lookup_request = GNUNET_GNS_lookup_zone (gns, lookup_name, 188 lookup_request = GNUNET_GNS_lookup (gns,
310 zone, 189 lookup_name,
311 rtype, 190 &pkey,
312 GNUNET_NO, /* Use DHT */ 191 rtype,
313 shorten_key, 192 GNUNET_NO, /* Use DHT */
314 &process_lookup_result, 193 shorten_key,
315 lookup_name); 194 &process_lookup_result,
316 } 195 lookup_name);
317 if (NULL != auth_name)
318 {
319 getauth_request = GNUNET_GNS_get_authority (gns, auth_name,
320 &process_auth_result, auth_name);
321 } 196 }
322 197 else
323 if (NULL != shorten_key)
324 GNUNET_CRYPTO_ecc_key_free (shorten_key);
325 if (NULL != shorten_zone)
326 GNUNET_free (shorten_zone);
327 if (NULL != private_zone)
328 GNUNET_free (private_zone);
329
330 if ( (NULL == auth_name) &&
331 (NULL == shorten_name) &&
332 (NULL == lookup_name))
333 { 198 {
334 fprintf (stderr, 199 fprintf (stderr,
335 _("Please specify lookup, shorten or authority operation!\n")); 200 _("Please specify name to lookup!\n"));
336 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 201 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
337 return; 202 return;
338 } 203 }
204 if (NULL != shorten_key)
205 GNUNET_CRYPTO_ecc_key_free (shorten_key);
339 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 206 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
340 &do_shutdown, NULL); 207 &do_shutdown, NULL);
341} 208}
@@ -352,15 +219,9 @@ int
352main (int argc, char *const *argv) 219main (int argc, char *const *argv)
353{ 220{
354 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 221 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
355 {'s', "shorten", "NAME",
356 gettext_noop ("try to shorten a given name"), 1,
357 &GNUNET_GETOPT_set_string, &shorten_name},
358 {'u', "lookup", "NAME", 222 {'u', "lookup", "NAME",
359 gettext_noop ("Lookup a record for the given name"), 1, 223 gettext_noop ("Lookup a record for the given name"), 1,
360 &GNUNET_GETOPT_set_string, &lookup_name}, 224 &GNUNET_GETOPT_set_string, &lookup_name},
361 {'a', "authority", "NAME",
362 gettext_noop ("Get the authority of a particular name"), 1,
363 &GNUNET_GETOPT_set_string, &auth_name},
364 {'t', "type", "TYPE", 225 {'t', "type", "TYPE",
365 gettext_noop ("Specify the type of the record to lookup"), 1, 226 gettext_noop ("Specify the type of the record to lookup"), 1,
366 &GNUNET_GETOPT_set_string, &lookup_type}, 227 &GNUNET_GETOPT_set_string, &lookup_type},
@@ -378,7 +239,7 @@ main (int argc, char *const *argv)
378 ret = 239 ret =
379 (GNUNET_OK == 240 (GNUNET_OK ==
380 GNUNET_PROGRAM_run (argc, argv, "gnunet-gns", 241 GNUNET_PROGRAM_run (argc, argv, "gnunet-gns",
381 _("GNUnet GNS access tool"), 242 _("GNUnet GNS resolver tool"),
382 options, 243 options,
383 &run, NULL)) ? 0 : 1; 244 &run, NULL)) ? 0 : 1;
384 GNUNET_free ((void*) argv); 245 GNUNET_free ((void*) argv);
diff --git a/src/include/gnunet_gns_service.h b/src/include/gnunet_gns_service.h
index d9aad6d77..283229dbf 100644
--- a/src/include/gnunet_gns_service.h
+++ b/src/include/gnunet_gns_service.h
@@ -110,7 +110,7 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
110 const struct GNUNET_CRYPTO_EccPublicKey *zone, 110 const struct GNUNET_CRYPTO_EccPublicKey *zone,
111 int type, 111 int type,
112 int only_cached, 112 int only_cached,
113 struct GNUNET_CRYPTO_EccPrivateKey *shorten_zone_key, 113 const struct GNUNET_CRYPTO_EccPrivateKey *shorten_zone_key,
114 GNUNET_GNS_LookupResultProcessor proc, 114 GNUNET_GNS_LookupResultProcessor proc,
115 void *proc_cls); 115 void *proc_cls);
116 116
@@ -121,7 +121,7 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
121 * @param lr the lookup request to cancel 121 * @param lr the lookup request to cancel
122 */ 122 */
123void 123void
124GNUNET_GNS_cancel_lookup_request (struct GNUNET_GNS_LookupRequest *lr); 124GNUNET_GNS_lookup_cancel (struct GNUNET_GNS_LookupRequest *lr);
125 125
126 126
127#if 0 /* keep Emacsens' auto-indent happy */ 127#if 0 /* keep Emacsens' auto-indent happy */