aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/gnunet-service-namestore.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/gnunet-service-namestore.c')
-rw-r--r--src/namestore/gnunet-service-namestore.c68
1 files changed, 42 insertions, 26 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index 3685c93af..3ba4f9ec3 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -439,9 +439,24 @@ get_nick_record (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone)
439} 439}
440 440
441 441
442/**
443 * Merge the nick record @a nick_rd with the rest of the
444 * record set given in @a rd2. Store the result in @a rdc_res
445 * and @a rd_res. The @a nick_rd's expiration time is set to
446 * the maximum expiration time of all of the records in @a rd2.
447 *
448 * @param nick_rd the nick record to integrate
449 * @param rd2_length length of the @a rd2 array
450 * @param rd2 array of records
451 * @param rdc_res[out] length of the resulting @a rd_res array
452 * @param rd_res[out] set to an array of records,
453 * including @a nick_rd and @a rd2;
454 * all of the variable-size 'data' fields in @a rd2 are
455 * allocated in the same chunk of memory!
456 */
442static void 457static void
443merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd, 458merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd,
444 unsigned int rdc2, 459 unsigned int rd2_length,
445 const struct GNUNET_GNSRECORD_Data *rd2, 460 const struct GNUNET_GNSRECORD_Data *rd2,
446 unsigned int *rdc_res, 461 unsigned int *rdc_res,
447 struct GNUNET_GNSRECORD_Data **rd_res) 462 struct GNUNET_GNSRECORD_Data **rd_res)
@@ -452,24 +467,22 @@ merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd,
452 int record_offset; 467 int record_offset;
453 size_t data_offset; 468 size_t data_offset;
454 469
455 (*rdc_res) = 1 + rdc2; 470 (*rdc_res) = 1 + rd2_length;
456 if (0 == 1 + rdc2) 471 if (0 == 1 + rd2_length)
457 { 472 {
458 (*rd_res) = NULL; 473 (*rd_res) = NULL;
459 return; 474 return;
460 } 475 }
461
462 req = 0; 476 req = 0;
463 for (unsigned int c=0; c< 1; c++) 477 for (unsigned int c=0; c< 1; c++)
464 req += sizeof (struct GNUNET_GNSRECORD_Data) + nick_rd[c].data_size; 478 req += sizeof (struct GNUNET_GNSRECORD_Data) + nick_rd[c].data_size;
465 for (unsigned int c=0; c< rdc2; c++) 479 for (unsigned int c=0; c< rd2_length; c++)
466 req += sizeof (struct GNUNET_GNSRECORD_Data) + rd2[c].data_size; 480 req += sizeof (struct GNUNET_GNSRECORD_Data) + rd2[c].data_size;
467 (*rd_res) = GNUNET_malloc (req); 481 (*rd_res) = GNUNET_malloc (req);
468 data = (char *) &(*rd_res)[1 + rdc2]; 482 data = (char *) &(*rd_res)[1 + rd2_length];
469 data_offset = 0; 483 data_offset = 0;
470 latest_expiration = 0; 484 latest_expiration = 0;
471 485 for (unsigned int c=0; c< rd2_length; c++)
472 for (unsigned int c=0; c< rdc2; c++)
473 { 486 {
474 if (0 != (rd2[c].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) 487 if (0 != (rd2[c].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
475 { 488 {
@@ -486,17 +499,15 @@ merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd,
486 rd2[c].data_size); 499 rd2[c].data_size);
487 data_offset += (*rd_res)[c].data_size; 500 data_offset += (*rd_res)[c].data_size;
488 } 501 }
489 record_offset = rdc2; 502 /* append nick */
490 for (unsigned int c=0; c< 1; c++) 503 record_offset = rd2_length;
491 { 504 (*rd_res)[record_offset] = *nick_rd;
492 (*rd_res)[c+record_offset] = nick_rd[c]; 505 (*rd_res)[record_offset].expiration_time = latest_expiration;
493 (*rd_res)[c+record_offset].expiration_time = latest_expiration; 506 (*rd_res)[record_offset].data = (void *) &data[data_offset];
494 (*rd_res)[c+record_offset].data = (void *) &data[data_offset]; 507 GNUNET_memcpy ((void *) (*rd_res)[record_offset].data,
495 GNUNET_memcpy ((void *) (*rd_res)[c+record_offset].data, 508 nick_rd->data,
496 nick_rd[c].data, 509 nick_rd->data_size);
497 nick_rd[c].data_size); 510 data_offset += (*rd_res)[record_offset].data_size;
498 data_offset += (*rd_res)[c+record_offset].data_size;
499 }
500 GNUNET_assert (req == (sizeof (struct GNUNET_GNSRECORD_Data)) * (*rdc_res) + data_offset); 511 GNUNET_assert (req == (sizeof (struct GNUNET_GNSRECORD_Data)) * (*rdc_res) + data_offset);
501} 512}
502 513
@@ -531,7 +542,9 @@ send_lookup_response (struct NamestoreClient *nc,
531 char *rd_ser; 542 char *rd_ser;
532 543
533 nick = get_nick_record (zone_key); 544 nick = get_nick_record (zone_key);
534 if ((NULL != nick) && (0 != strcmp(name, GNUNET_GNS_EMPTY_LABEL_AT))) 545 if ( (NULL != nick) &&
546 (0 != strcmp (name,
547 GNUNET_GNS_EMPTY_LABEL_AT)))
535 { 548 {
536 nick->flags = (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE; 549 nick->flags = (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE;
537 merge_with_nick_records (nick, 550 merge_with_nick_records (nick,
@@ -677,13 +690,15 @@ refresh_block (struct NamestoreClient *nc,
677 block = GNUNET_GNSRECORD_block_create (zone_key, 690 block = GNUNET_GNSRECORD_block_create (zone_key,
678 GNUNET_TIME_UNIT_ZERO_ABS, 691 GNUNET_TIME_UNIT_ZERO_ABS,
679 name, 692 name,
680 res, rd_count); 693 res,
694 rd_count);
681 else 695 else
682 block = GNUNET_GNSRECORD_block_create (zone_key, 696 block = GNUNET_GNSRECORD_block_create (zone_key,
683 GNUNET_GNSRECORD_record_get_expiration_time (res_count, 697 GNUNET_GNSRECORD_record_get_expiration_time (res_count,
684 res), 698 res),
685 name, 699 name,
686 res, res_count); 700 res,
701 res_count);
687 GNUNET_assert (NULL != block); 702 GNUNET_assert (NULL != block);
688 GNUNET_CRYPTO_ecdsa_key_get_public (zone_key, 703 GNUNET_CRYPTO_ecdsa_key_get_public (zone_key,
689 &pkey); 704 &pkey);
@@ -773,9 +788,10 @@ lookup_it (void *cls,
773 rdc_res = 0; 788 rdc_res = 0;
774 rlc->nick->flags = (rlc->nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE; 789 rlc->nick->flags = (rlc->nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE;
775 merge_with_nick_records (rlc->nick, 790 merge_with_nick_records (rlc->nick,
776 rd_count, rd, 791 rd_count,
777 &rdc_res, &rd_res); 792 rd,
778 793 &rdc_res,
794 &rd_res);
779 rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rdc_res, 795 rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rdc_res,
780 rd_res); 796 rd_res);
781 rlc->res_rd_count = rdc_res; 797 rlc->res_rd_count = rdc_res;