aboutsummaryrefslogtreecommitdiff
path: root/src/gns/gnunet-gns.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-09-05 12:36:43 +0000
committerChristian Grothoff <christian@grothoff.org>2013-09-05 12:36:43 +0000
commit60b7a7174aef637217d73ca3d1514f547392edb9 (patch)
treed1fa79c4b02dcf981034f9033ff4ab30b62f7070 /src/gns/gnunet-gns.c
parentf119aafc2bfc888ddd435a0527e5ddd5123874d0 (diff)
downloadgnunet-60b7a7174aef637217d73ca3d1514f547392edb9.tar.gz
gnunet-60b7a7174aef637217d73ca3d1514f547392edb9.zip
-use standard zones in gnunet-gns
Diffstat (limited to 'src/gns/gnunet-gns.c')
-rw-r--r--src/gns/gnunet-gns.c139
1 files changed, 93 insertions, 46 deletions
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c
index 28e06e844..4472c764e 100644
--- a/src/gns/gnunet-gns.c
+++ b/src/gns/gnunet-gns.c
@@ -79,6 +79,16 @@ static struct GNUNET_GNS_LookupRequest *lookup_request;
79 */ 79 */
80static struct GNUNET_IDENTITY_EgoLookup *el; 80static struct GNUNET_IDENTITY_EgoLookup *el;
81 81
82/**
83 * Handle for identity service.
84 */
85static struct GNUNET_IDENTITY_Handle *identity;
86
87/**
88 * Active operation on identity service.
89 */
90static struct GNUNET_IDENTITY_Operation *id_op;
91
82 92
83/** 93/**
84 * Task run on shutdown. Cleans up everything. 94 * Task run on shutdown. Cleans up everything.
@@ -95,11 +105,21 @@ do_shutdown (void *cls,
95 GNUNET_IDENTITY_ego_lookup_cancel (el); 105 GNUNET_IDENTITY_ego_lookup_cancel (el);
96 el = NULL; 106 el = NULL;
97 } 107 }
108 if (NULL != id_op)
109 {
110 GNUNET_IDENTITY_cancel (id_op);
111 id_op = NULL;
112 }
98 if (NULL != lookup_request) 113 if (NULL != lookup_request)
99 { 114 {
100 GNUNET_GNS_lookup_cancel (lookup_request); 115 GNUNET_GNS_lookup_cancel (lookup_request);
101 lookup_request = NULL; 116 lookup_request = NULL;
102 } 117 }
118 if (NULL != identity)
119 {
120 GNUNET_IDENTITY_disconnect (identity);
121 identity = NULL;
122 }
103 if (NULL != gns) 123 if (NULL != gns)
104 { 124 {
105 GNUNET_GNS_disconnect (gns); 125 GNUNET_GNS_disconnect (gns);
@@ -190,31 +210,32 @@ lookup_with_keys (const struct GNUNET_CRYPTO_EccPublicKey *pkey,
190 210
191 211
192/** 212/**
193 * Method called to with the ego we are to use for the lookup. 213 * Method called to with the ego we are to use for shortening
214 * during the lookup.
194 * 215 *
195 * @param cls closure with the `struct GNUNET_CRYPTO_EccPublicKey` 216 * @param cls closure contains the public key to use
196 * @param ego ego handle, NULL if not found 217 * @param ego ego handle, NULL if not found
218 * @param ctx context for application to store data for this ego
219 * (during the lifetime of this process, initially NULL)
220 * @param name name assigned by the user for this ego,
221 * NULL if the user just deleted the ego and it
222 * must thus no longer be used
197 */ 223 */
198static void 224static void
199shorten_cb (void *cls, 225identity_shorten_cb (void *cls,
200 const struct GNUNET_IDENTITY_Ego *ego) 226 struct GNUNET_IDENTITY_Ego *ego,
227 void **ctx,
228 const char *name)
201{ 229{
202 struct GNUNET_CRYPTO_EccPublicKey *pkey = cls; 230 struct GNUNET_CRYPTO_EccPublicKey *pkeym = cls;
203 const struct GNUNET_CRYPTO_EccPrivateKey *shorten_key;
204 231
205 el = NULL; 232 id_op = NULL;
206 if (NULL == ego) 233 if (NULL == ego)
207 { 234 lookup_with_keys (pkeym, NULL);
208 fprintf (stderr,
209 _("Shorten zone not found (looking up without shortening)\n"));
210 shorten_key = NULL;
211 }
212 else 235 else
213 { 236 lookup_with_keys (pkeym,
214 shorten_key = GNUNET_IDENTITY_ego_get_private_key (ego); 237 GNUNET_IDENTITY_ego_get_private_key (ego));
215 } 238 GNUNET_free (pkeym);
216 lookup_with_keys (pkey, shorten_key);
217 GNUNET_free_non_null (pkey);
218} 239}
219 240
220 241
@@ -228,59 +249,83 @@ static void
228lookup_with_public_key (const struct GNUNET_CRYPTO_EccPublicKey *pkey) 249lookup_with_public_key (const struct GNUNET_CRYPTO_EccPublicKey *pkey)
229{ 250{
230 struct GNUNET_CRYPTO_EccPublicKey *pkeym; 251 struct GNUNET_CRYPTO_EccPublicKey *pkeym;
231 char *szone;
232 252
233 if (GNUNET_OK != 253 GNUNET_assert (NULL != pkey);
234 GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", 254 pkeym = GNUNET_new (struct GNUNET_CRYPTO_EccPublicKey);
235 "SHORTEN_ZONE", &szone)) 255 *pkeym = *pkey;
256 id_op = GNUNET_IDENTITY_get (identity,
257 "shorten-zone",
258 &identity_shorten_cb,
259 pkeym);
260 if (NULL == id_op)
236 { 261 {
262 GNUNET_break (0);
237 lookup_with_keys (pkey, NULL); 263 lookup_with_keys (pkey, NULL);
238 return;
239 } 264 }
240 if (NULL == pkey) 265}
266
267
268/**
269 * Method called to with the ego we are to use for the lookup,
270 * when the ego is determined by a name.
271 *
272 * @param cls closure (NULL, unused)
273 * @param ego ego handle, NULL if not found
274 */
275static void
276identity_zone_cb (void *cls,
277 const struct GNUNET_IDENTITY_Ego *ego)
278{
279 struct GNUNET_CRYPTO_EccPublicKey pkey;
280
281 el = NULL;
282 if (NULL == ego)
241 { 283 {
242 pkeym = NULL; 284 fprintf (stderr,
285 _("Ego for `%s' not found, cannot perform lookup.\n"),
286 zone_ego_name);
287 GNUNET_SCHEDULER_shutdown ();
243 } 288 }
244 else 289 else
245 { 290 {
246 pkeym = GNUNET_new (struct GNUNET_CRYPTO_EccPublicKey); 291 GNUNET_IDENTITY_ego_get_public_key (ego, &pkey);
247 *pkeym = *pkey; 292 lookup_with_public_key (&pkey);
248 } 293 }
249 el = GNUNET_IDENTITY_ego_lookup (cfg, 294 GNUNET_free_non_null (zone_ego_name);
250 szone, 295 zone_ego_name = NULL;
251 &shorten_cb,
252 pkeym);
253 GNUNET_free (szone);
254} 296}
255 297
256 298
257/** 299/**
258 * Method called to with the ego we are to use for the lookup. 300 * Method called to with the ego we are to use for the lookup,
301 * when the ego is the one for the default master zone.
259 * 302 *
260 * @param cls closure (NULL, unused) 303 * @param cls closure (NULL, unused)
261 * @param ego ego handle, NULL if not found 304 * @param ego ego handle, NULL if not found
305 * @param ctx context for application to store data for this ego
306 * (during the lifetime of this process, initially NULL)
307 * @param name name assigned by the user for this ego,
308 * NULL if the user just deleted the ego and it
309 * must thus no longer be used
262 */ 310 */
263static void 311static void
264identity_cb (void *cls, 312identity_master_cb (void *cls,
265 const struct GNUNET_IDENTITY_Ego *ego) 313 struct GNUNET_IDENTITY_Ego *ego,
314 void **ctx,
315 const char *name)
266{ 316{
267 struct GNUNET_CRYPTO_EccPublicKey pkey; 317 struct GNUNET_CRYPTO_EccPublicKey pkey;
268 318
269 el = NULL; 319 id_op = NULL;
270 if (NULL == ego) 320 if (NULL == ego)
271 { 321 {
272 fprintf (stderr, 322 fprintf (stderr,
273 _("Ego `%s' not found\n"), 323 _("Ego for `master-zone' not found, cannot perform lookup. Did you run gnunet-gns-import.sh?\n"));
274 zone_ego_name);
275 GNUNET_free (zone_ego_name);
276 zone_ego_name = NULL;
277 GNUNET_SCHEDULER_shutdown (); 324 GNUNET_SCHEDULER_shutdown ();
278 return; 325 return;
279 } 326 }
280 GNUNET_IDENTITY_ego_get_public_key (ego, &pkey); 327 GNUNET_IDENTITY_ego_get_public_key (ego, &pkey);
281 lookup_with_public_key (&pkey); 328 lookup_with_public_key (&pkey);
282 GNUNET_free (zone_ego_name);
283 zone_ego_name = NULL;
284} 329}
285 330
286 331
@@ -300,6 +345,7 @@ run (void *cls, char *const *args, const char *cfgfile,
300 345
301 cfg = c; 346 cfg = c;
302 gns = GNUNET_GNS_connect (cfg); 347 gns = GNUNET_GNS_connect (cfg);
348 identity = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
303 if (NULL == gns) 349 if (NULL == gns)
304 { 350 {
305 fprintf (stderr, 351 fprintf (stderr,
@@ -328,7 +374,7 @@ run (void *cls, char *const *args, const char *cfgfile,
328 { 374 {
329 el = GNUNET_IDENTITY_ego_lookup (cfg, 375 el = GNUNET_IDENTITY_ego_lookup (cfg,
330 zone_ego_name, 376 zone_ego_name,
331 &identity_cb, 377 &identity_zone_cb,
332 NULL); 378 NULL);
333 return; 379 return;
334 } 380 }
@@ -344,10 +390,11 @@ run (void *cls, char *const *args, const char *cfgfile,
344 } 390 }
345 else 391 else
346 { 392 {
347 fprintf (stderr, 393 id_op = GNUNET_IDENTITY_get (identity,
348 _("I need a zone (`-p' or `-z' option) to resolve this name\n")); 394 "master-zone",
349 GNUNET_SCHEDULER_shutdown (); 395 &identity_master_cb,
350 return; 396 NULL);
397 GNUNET_assert (NULL != id_op);
351 } 398 }
352} 399}
353 400