aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-11-14 14:51:20 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-11-14 14:51:20 +0000
commitbfa72b33236a5e43688fa3c170d2db49b58e7405 (patch)
tree4c303de89da6877f1e4cf2d8138399819385550a /src/gns
parent576382564c21c546595f57eefc7e57b3e9fc523b (diff)
downloadgnunet-bfa72b33236a5e43688fa3c170d2db49b58e7405.tar.gz
gnunet-bfa72b33236a5e43688fa3c170d2db49b58e7405.zip
remove DHT lookup code
- do not shorten shorten zone
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/gnunet-service-gns_shorten.c226
1 files changed, 19 insertions, 207 deletions
diff --git a/src/gns/gnunet-service-gns_shorten.c b/src/gns/gnunet-service-gns_shorten.c
index 7467c681b..2b8aa06f9 100644
--- a/src/gns/gnunet-service-gns_shorten.c
+++ b/src/gns/gnunet-service-gns_shorten.c
@@ -221,6 +221,9 @@ process_pseu_block_ns (void *cls,
221 gph->namecache_task = NULL; 221 gph->namecache_task = NULL;
222 if (NULL == block) 222 if (NULL == block)
223 { 223 {
224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
225 "Namecache did not return information for label `%s' \n",
226 gph->current_label);
224 process_pseu_lookup_ns (gph, 0, NULL); 227 process_pseu_lookup_ns (gph, 0, NULL);
225 return; 228 return;
226 } 229 }
@@ -247,7 +250,7 @@ process_pseu_block_ns (void *cls,
247 * @param label the label to lookup 250 * @param label the label to lookup
248 */ 251 */
249static void 252static void
250perform_pseu_lookup (struct GetPseuAuthorityHandle *gph, 253perform_nick_lookup (struct GetPseuAuthorityHandle *gph,
251 const char *label) 254 const char *label)
252{ 255{
253 struct GNUNET_CRYPTO_EcdsaPublicKey pub; 256 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
@@ -298,7 +301,7 @@ process_pseu_lookup_ns (void *cls,
298 } 301 }
299 else 302 else
300 { 303 {
301 perform_pseu_lookup (gph, gph->label); 304 perform_nick_lookup (gph, gph->label);
302 } 305 }
303 return; 306 return;
304 } 307 }
@@ -323,185 +326,6 @@ process_pseu_lookup_ns (void *cls,
323 326
324 327
325/** 328/**
326 * Process result of a DHT lookup for a PSEU record.
327 *
328 * @param gph the handle to our shorten operation
329 * @param pseu the pseu result or NULL
330 */
331static void
332process_pseu_result (struct GetPseuAuthorityHandle* gph,
333 const char *pseu)
334{
335 if (NULL == pseu)
336 {
337 /* no PSEU found, try original label */
338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
339 "No PSEU found, trying original label `%s' instead.\n",
340 gph->label);
341 perform_pseu_lookup (gph, gph->label);
342 return;
343 }
344 /* check if 'pseu' is taken */
345 perform_pseu_lookup (gph, pseu);
346}
347
348
349/**
350 * Handle timeout for DHT request during shortening.
351 *
352 * @param cls the request handle as closure
353 * @param tc the task context
354 */
355static void
356handle_auth_discovery_timeout (void *cls,
357 const struct GNUNET_SCHEDULER_TaskContext *tc)
358{
359 struct GetPseuAuthorityHandle *gph = cls;
360
361 gph->timeout_task = GNUNET_SCHEDULER_NO_TASK;
362 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
363 "DHT lookup for PSEU query in zone `%s' timed out.\n",
364 GNUNET_GNSRECORD_z2s (&gph->target_zone));
365 GNUNET_DHT_get_stop (gph->get_handle);
366 gph->get_handle = NULL;
367 process_pseu_result (gph, NULL);
368}
369
370
371/**
372 * Handle decrypted records from DHT result.
373 *
374 * @param cls closure with our 'struct GetPseuAuthorityHandle'
375 * @param rd_count number of entries in 'rd' array
376 * @param rd array of records with data to store
377 */
378static void
379process_auth_records (void *cls,
380 unsigned int rd_count,
381 const struct GNUNET_GNSRECORD_Data *rd)
382{
383 struct GetPseuAuthorityHandle *gph = cls;
384 unsigned int i;
385
386 for (i=0; i < rd_count; i++)
387 {
388 if (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type)
389 {
390 char pseu[rd[i].data_size + 1];
391
392 /* found pseu */
393 memcpy (pseu,
394 rd[i].data,
395 rd[i].data_size);
396 pseu[rd[i].data_size] = '\0';
397 process_pseu_result (gph,
398 pseu);
399 return;
400 }
401 }
402 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
403 "No PSEU record found in DHT reply with %u records.\n",
404 rd_count);
405 process_pseu_result (gph, NULL);
406}
407
408
409/**
410 * Function called when we find a PSEU entry in the DHT
411 *
412 * @param cls the request handle
413 * @param exp lifetime
414 * @param key the key the record was stored under
415 * @param get_path get path
416 * @param get_path_length @a get_path length
417 * @param put_path put path
418 * @param put_path_length @a put_path length
419 * @param type the block type
420 * @param size number of bytes in @a data
421 * @param data the record data
422 */
423static void
424process_auth_discovery_dht_result (void* cls,
425 struct GNUNET_TIME_Absolute exp,
426 const struct GNUNET_HashCode *key,
427 const struct GNUNET_PeerIdentity *get_path,
428 unsigned int get_path_length,
429 const struct GNUNET_PeerIdentity *put_path,
430 unsigned int put_path_length,
431 enum GNUNET_BLOCK_Type type,
432 size_t size,
433 const void *data)
434{
435 struct GetPseuAuthorityHandle *gph = cls;
436 const struct GNUNET_GNSRECORD_Block *block;
437
438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
439 "Got DHT result for PSEU request\n");
440 GNUNET_DHT_get_stop (gph->get_handle);
441 gph->get_handle = NULL;
442 GNUNET_SCHEDULER_cancel (gph->timeout_task);
443 gph->timeout_task = GNUNET_SCHEDULER_NO_TASK;
444
445 if (NULL == data)
446 {
447 /* is this allowed!? */
448 GNUNET_break (0);
449 process_pseu_result (gph, NULL);
450 return;
451 }
452 if (size < sizeof (struct GNUNET_GNSRECORD_Block))
453 {
454 /* how did this pass DHT block validation!? */
455 GNUNET_break (0);
456 process_pseu_result (gph, NULL);
457 return;
458 }
459 block = data;
460 if (size !=
461 ntohl (block->purpose.size) +
462 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) +
463 sizeof (struct GNUNET_CRYPTO_EcdsaSignature))
464 {
465 /* how did this pass DHT block validation!? */
466 GNUNET_break (0);
467 process_pseu_result (gph, NULL);
468 return;
469 }
470 if (GNUNET_OK !=
471 GNUNET_GNSRECORD_block_decrypt (block,
472 &gph->target_zone,
473 GNUNET_GNS_TLD_PLUS,
474 &process_auth_records,
475 gph))
476 {
477 /* other peer encrypted invalid block, complain */
478 GNUNET_break_op (0);
479 process_pseu_result (gph, NULL);
480 return;
481 }
482}
483
484static void suggested_lookup_cb (void *cls,
485 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
486 const char *label,
487 unsigned int rd_count,
488 const struct GNUNET_GNSRECORD_Data *rd)
489{
490 struct GetPseuAuthorityHandle* gph = cls;
491 gph->namestore_task = NULL;
492 if ((0 == strcmp (label, gph->suggested_label)) && (0 == rd_count) && (NULL == rd))
493 {
494
495 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
496 "Shortening to suggested name `%s' possible\n",
497 gph->suggested_label);
498 process_pseu_result (gph, gph->suggested_label);
499 }
500}
501
502
503
504/**
505 * Callback called by namestore for a zone to name result. We're 329 * Callback called by namestore for a zone to name result. We're
506 * trying to see if a short name for a given zone already exists. 330 * trying to see if a short name for a given zone already exists.
507 * 331 *
@@ -533,33 +357,13 @@ process_zone_to_name_discover (void *cls,
533 free_get_pseu_authority_handle (gph); 357 free_get_pseu_authority_handle (gph);
534 return; 358 return;
535 } 359 }
360 else
361 {
362 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
363 "Shortening continuing, no name not reserved in shorten zone\n");
364 }
536 /* record does not yet exist, check if suggested label is available */ 365 /* record does not yet exist, check if suggested label is available */
537 366 perform_nick_lookup (gph, gph->suggested_label);
538 if (NULL != gph->suggested_label)
539 gph->namestore_task = GNUNET_NAMESTORE_records_lookup (namestore_handle, zone_key,
540 gph->suggested_label, &suggested_lookup_cb, gph);
541
542#if 0
543 GNUNET_GNSRECORD_query_from_public_key (&gph->target_zone,
544 GNUNET_GNS_TLD_PLUS,
545 &lookup_key);
546 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
547 "Shortening searches in DHT for PSEU record under `%s' in zone `%s'\n",
548 GNUNET_h2s (&lookup_key),
549 GNUNET_GNSRECORD_z2s (&gph->target_zone));
550
551 gph->timeout_task = GNUNET_SCHEDULER_add_delayed (DHT_LOOKUP_TIMEOUT,
552 &handle_auth_discovery_timeout,
553 gph);
554 gph->get_handle = GNUNET_DHT_get_start (dht_handle,
555 GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
556 &lookup_key,
557 DHT_GNS_REPLICATION_LEVEL,
558 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
559 NULL, 0,
560 &process_auth_discovery_dht_result,
561 gph);
562#endif
563} 367}
564 368
565 369
@@ -580,12 +384,20 @@ GNS_shorten_start (const char *original_label,
580 const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_zone) 384 const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_zone)
581{ 385{
582 struct GetPseuAuthorityHandle *gph; 386 struct GetPseuAuthorityHandle *gph;
387 struct GNUNET_CRYPTO_EcdsaPublicKey shorten_pub;
583 388
584 if (strlen (original_label) > GNUNET_DNSPARSER_MAX_LABEL_LENGTH) 389 if (strlen (original_label) > GNUNET_DNSPARSER_MAX_LABEL_LENGTH)
585 { 390 {
586 GNUNET_break (0); 391 GNUNET_break (0);
587 return; 392 return;
588 } 393 }
394 GNUNET_CRYPTO_ecdsa_key_get_public(shorten_zone, &shorten_pub);
395 if (0 == memcmp (&shorten_pub, pub, sizeof (pub)))
396 {
397 /* Do not shorten the shorten zone */
398 return;
399 }
400
589 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 401 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
590 "Starting shortening process for `%s' with old label `%s' and suggested nickname `%s'\n", 402 "Starting shortening process for `%s' with old label `%s' and suggested nickname `%s'\n",
591 GNUNET_GNSRECORD_z2s (pub), 403 GNUNET_GNSRECORD_z2s (pub),