summaryrefslogtreecommitdiff
path: root/src/namestore/gnunet-service-namestore.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-11-13 15:04:21 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-11-13 15:04:21 +0000
commit97f8a1ba8d1d43025ae43ab33bca12efbd49f355 (patch)
tree406396c6cd263e9cac02f60a9b80663f66bb374c /src/namestore/gnunet-service-namestore.c
parentbe479981b97e8eeeb4ac251bb413a08b425a0fdd (diff)
downloadgnunet-97f8a1ba8d1d43025ae43ab33bca12efbd49f355.tar.gz
gnunet-97f8a1ba8d1d43025ae43ab33bca12efbd49f355.zip
adding pseudonym NICK automatically to records sets
Diffstat (limited to 'src/namestore/gnunet-service-namestore.c')
-rw-r--r--src/namestore/gnunet-service-namestore.c183
1 files changed, 170 insertions, 13 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index ad8c9e798..ffffc704e 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -27,6 +27,7 @@
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29#include "gnunet_dnsparser_lib.h" 29#include "gnunet_dnsparser_lib.h"
30#include "gnunet_gns_service.h"
30#include "gnunet_namecache_service.h" 31#include "gnunet_namecache_service.h"
31#include "gnunet_namestore_service.h" 32#include "gnunet_namestore_service.h"
32#include "gnunet_namestore_plugin.h" 33#include "gnunet_namestore_plugin.h"
@@ -63,6 +64,11 @@ struct ZoneIteration
63 struct NamestoreClient *client; 64 struct NamestoreClient *client;
64 65
65 /** 66 /**
67 * The nick to add to the records
68 */
69 struct GNUNET_GNSRECORD_Data *nick;
70
71 /**
66 * Key of the zone we are iterating over. 72 * Key of the zone we are iterating over.
67 */ 73 */
68 struct GNUNET_CRYPTO_EcdsaPrivateKey zone; 74 struct GNUNET_CRYPTO_EcdsaPrivateKey zone;
@@ -391,6 +397,109 @@ client_lookup (struct GNUNET_SERVER_Client *client)
391} 397}
392 398
393 399
400static void lookup_nick_it (void *cls,
401 const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key,
402 const char *label,
403 unsigned int rd_count,
404 const struct GNUNET_GNSRECORD_Data *rd)
405{
406 struct GNUNET_GNSRECORD_Data **res = (cls);
407
408 int c;
409 if (0 != strcmp (label, GNUNET_GNS_MASTERZONE_STR))
410 {
411 GNUNET_break (0);
412 return;
413 }
414 for (c = 0; c < rd_count; c++)
415 {
416 if (GNUNET_GNSRECORD_TYPE_NICK == rd[c].record_type)
417 {
418 (*res) = GNUNET_malloc (rd[c].data_size + sizeof (struct GNUNET_GNSRECORD_Data));
419 (*res)->data = &(*res)[1];
420 memcpy ((char *)(*res)->data, rd[c].data, rd[c].data_size);
421 (*res)->data_size = rd[c].data_size;
422 (*res)->expiration_time = rd[c].expiration_time;
423 (*res)->flags = rd[c].flags;
424 (*res)->record_type = GNUNET_GNSRECORD_TYPE_NICK;
425 return;
426 }
427 }
428 (*res) = NULL;
429}
430
431
432static struct GNUNET_GNSRECORD_Data *
433get_nick_record (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone)
434{
435 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
436 struct GNUNET_GNSRECORD_Data *nick;
437 int res;
438
439 res = GSN_database->lookup_records (GSN_database->cls, zone,
440 GNUNET_GNS_MASTERZONE_STR, &lookup_nick_it, &nick);
441
442 if ((NULL == nick) || (GNUNET_OK != res))
443 {
444 GNUNET_CRYPTO_ecdsa_key_get_public (zone, &pub);
445 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No nick name set for zone `%s'\n",
446 GNUNET_CRYPTO_ecdsa_public_key_to_string (&pub));
447 return NULL;
448 }
449
450 return nick;
451}
452
453
454static void merge_records (unsigned int rdc1,
455 const struct GNUNET_GNSRECORD_Data *rd1,
456 unsigned int rdc2,
457 const struct GNUNET_GNSRECORD_Data *rd2,
458 unsigned int *rdc_res,
459 struct GNUNET_GNSRECORD_Data **rd_res)
460{
461 int c;
462 size_t req;
463 char *data;
464 int record_offset;
465 size_t data_offset;
466 (*rdc_res) = rdc1 + rdc2;
467
468 if (0 == rdc1 + rdc2)
469 {
470 (*rd_res) = NULL;
471 return;
472 }
473
474 req = 0;
475 for (c=0; c< rdc1; c++)
476 req += sizeof (struct GNUNET_GNSRECORD_Data) + rd1[c].data_size;
477 for (c=0; c< rdc2; c++)
478 req += sizeof (struct GNUNET_GNSRECORD_Data) + rd2[c].data_size;
479 (*rd_res) = GNUNET_malloc (req);
480 data = (char *) &(*rd_res)[rdc1 + rdc2];
481 data_offset = 0;
482
483 for (c=0; c< rdc1; c++)
484 {
485 (*rd_res)[c] = rd1[c];
486 (*rd_res)[c].data = (void *) &data[data_offset];
487 memcpy ((void *) (*rd_res)[c].data, rd1[c].data, rd1[c].data_size);
488 data_offset += (*rd_res)[c].data_size;
489 }
490 record_offset = rdc1;
491 for (c=0; c< rdc2; c++)
492 {
493 (*rd_res)[c+record_offset] = rd2[c];
494 (*rd_res)[c+record_offset].data = (void *) &data[data_offset];
495 memcpy ((void *) (*rd_res)[c+record_offset].data, rd2[c].data, rd2[c].data_size);
496 data_offset += (*rd_res)[c+record_offset].data_size;
497 }
498 GNUNET_assert (req == (sizeof (struct GNUNET_GNSRECORD_Data)) * (*rdc_res) + data_offset);
499}
500
501
502
394/** 503/**
395 * Generate a 'struct LookupNameResponseMessage' and send it to the 504 * Generate a 'struct LookupNameResponseMessage' and send it to the
396 * given client using the given notification context. 505 * given client using the given notification context.
@@ -413,14 +522,29 @@ send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc,
413 const struct GNUNET_GNSRECORD_Data *rd) 522 const struct GNUNET_GNSRECORD_Data *rd)
414{ 523{
415 struct RecordResultMessage *zir_msg; 524 struct RecordResultMessage *zir_msg;
525 struct GNUNET_GNSRECORD_Data *nick;
526 struct GNUNET_GNSRECORD_Data *res;
527 unsigned int res_count;
416 size_t name_len; 528 size_t name_len;
417 size_t rd_ser_len; 529 size_t rd_ser_len;
418 size_t msg_size; 530 size_t msg_size;
419 char *name_tmp; 531 char *name_tmp;
420 char *rd_ser; 532 char *rd_ser;
421 533
534 nick = get_nick_record (zone_key);
535 if ((NULL != nick) && (0 != strcmp(name, GNUNET_GNS_MASTERZONE_STR)))
536 {
537 merge_records (rd_count,rd, 1, nick, &res_count, &res);
538 GNUNET_free (nick);
539 }
540 else
541 {
542 res_count = rd_count;
543 res = (struct GNUNET_GNSRECORD_Data *) rd;
544 }
545
422 name_len = strlen (name) + 1; 546 name_len = strlen (name) + 1;
423 rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, rd); 547 rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count, res);
424 msg_size = sizeof (struct RecordResultMessage) + name_len + rd_ser_len; 548 msg_size = sizeof (struct RecordResultMessage) + name_len + rd_ser_len;
425 (void) client_lookup (client); 549 (void) client_lookup (client);
426 zir_msg = GNUNET_malloc (msg_size); 550 zir_msg = GNUNET_malloc (msg_size);
@@ -428,13 +552,13 @@ send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc,
428 zir_msg->gns_header.header.size = htons (msg_size); 552 zir_msg->gns_header.header.size = htons (msg_size);
429 zir_msg->gns_header.r_id = htonl (request_id); 553 zir_msg->gns_header.r_id = htonl (request_id);
430 zir_msg->name_len = htons (name_len); 554 zir_msg->name_len = htons (name_len);
431 zir_msg->rd_count = htons (rd_count); 555 zir_msg->rd_count = htons (res_count);
432 zir_msg->rd_len = htons (rd_ser_len); 556 zir_msg->rd_len = htons (rd_ser_len);
433 zir_msg->private_key = *zone_key; 557 zir_msg->private_key = *zone_key;
434 name_tmp = (char *) &zir_msg[1]; 558 name_tmp = (char *) &zir_msg[1];
435 memcpy (name_tmp, name, name_len); 559 memcpy (name_tmp, name, name_len);
436 rd_ser = &name_tmp[name_len]; 560 rd_ser = &name_tmp[name_len];
437 GNUNET_GNSRECORD_records_serialize (rd_count, rd, rd_ser_len, rd_ser); 561 GNUNET_GNSRECORD_records_serialize (res_count, res, rd_ser_len, rd_ser);
438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 562 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
439 "Sending `%s' message with %u records and size %u\n", 563 "Sending `%s' message with %u records and size %u\n",
440 "RECORD_RESULT", 564 "RECORD_RESULT",
@@ -444,6 +568,8 @@ send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc,
444 client, 568 client,
445 &zir_msg->gns_header.header, 569 &zir_msg->gns_header.header,
446 GNUNET_NO); 570 GNUNET_NO);
571 if (rd != res)
572 GNUNET_free (res);
447 GNUNET_free (zir_msg); 573 GNUNET_free (zir_msg);
448} 574}
449 575
@@ -573,25 +699,51 @@ struct RecordLookupContext
573 size_t rd_ser_len; 699 size_t rd_ser_len;
574 700
575 char *res_rd; 701 char *res_rd;
702
703 struct GNUNET_GNSRECORD_Data *nick;
576}; 704};
577 705
578static void lookup_it (void *cls, 706
579 const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, 707
580 const char *label, 708static void
581 unsigned int rd_count, 709lookup_it (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key,
582 const struct GNUNET_GNSRECORD_Data *rd) 710 const char *label, unsigned int rd_count,
711 const struct GNUNET_GNSRECORD_Data *rd)
583{ 712{
584 struct RecordLookupContext *rlc = cls; 713 struct RecordLookupContext *rlc = cls;
714 struct GNUNET_GNSRECORD_Data *rd_res;
715 unsigned int rdc_res;
585 716
586 if (0 == strcmp (label, rlc->label)) 717 if (0 == strcmp (label, rlc->label))
587 { 718 {
588 rlc->found = GNUNET_YES; 719 rlc->found = GNUNET_YES;
589 if (0 != rd_count) 720 if (0 != rd_count)
590 { 721 {
591 rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, rd); 722 if ((NULL != rlc->nick) && (0 != strcmp(label, GNUNET_GNS_MASTERZONE_STR)))
592 rlc->res_rd_count = rd_count; 723 {
593 rlc->res_rd = GNUNET_malloc (rlc->rd_ser_len); 724 /* Merge */
594 GNUNET_GNSRECORD_records_serialize (rd_count, rd, rlc->rd_ser_len , rlc->res_rd); 725 rd_res = NULL;
726 rdc_res = 0;
727 merge_records (rd_count, rd,
728 1, rlc->nick,
729 &rdc_res, &rd_res);
730
731 rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rdc_res, rd_res);
732 rlc->res_rd_count = rdc_res;
733 rlc->res_rd = GNUNET_malloc (rlc->rd_ser_len);
734 GNUNET_GNSRECORD_records_serialize (rdc_res, rd_res, rlc->rd_ser_len , rlc->res_rd);
735
736 GNUNET_free (rd_res);
737 GNUNET_free (rlc->nick);
738 rlc->nick = NULL;
739 }
740 else
741 {
742 rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, rd);
743 rlc->res_rd_count = rd_count;
744 rlc->res_rd = GNUNET_malloc (rlc->rd_ser_len);
745 GNUNET_GNSRECORD_records_serialize (rd_count, rd, rlc->rd_ser_len , rlc->res_rd);
746 }
595 } 747 }
596 else 748 else
597 { 749 {
@@ -603,6 +755,9 @@ static void lookup_it (void *cls,
603} 755}
604 756
605 757
758
759
760
606/** 761/**
607 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP message 762 * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP message
608 * 763 *
@@ -666,8 +821,8 @@ handle_record_lookup (void *cls,
666 rlc.label = name_tmp; 821 rlc.label = name_tmp;
667 rlc.found = GNUNET_NO; 822 rlc.found = GNUNET_NO;
668 rlc.res_rd_count = 0; 823 rlc.res_rd_count = 0;
669 rlc.rd_ser_len = 0;
670 rlc.res_rd = NULL; 824 rlc.res_rd = NULL;
825 rlc.nick = get_nick_record (&ll_msg->zone);
671 826
672 res = GSN_database->lookup_records (GSN_database->cls, 827 res = GSN_database->lookup_records (GSN_database->cls,
673 &ll_msg->zone, name_tmp, &lookup_it, &rlc); 828 &ll_msg->zone, name_tmp, &lookup_it, &rlc);
@@ -1188,6 +1343,8 @@ handle_iteration_start (void *cls,
1188 zi->offset = 0; 1343 zi->offset = 0;
1189 zi->client = nc; 1344 zi->client = nc;
1190 zi->zone = zis_msg->zone; 1345 zi->zone = zis_msg->zone;
1346
1347
1191 GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi); 1348 GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi);
1192 run_zone_iteration_round (zi); 1349 run_zone_iteration_round (zi);
1193 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1350 GNUNET_SERVER_receive_done (client, GNUNET_OK);