diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-02 12:15:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-02 12:15:35 +0000 |
commit | 42b829bb6005f07403370931509d0f83b4235e15 (patch) | |
tree | dc70bfbb15271f45443e2d2267bfb3cb3fa490b1 /src/namestore | |
parent | 98bbddca603be552e75903ac6ac5f44b9388977c (diff) | |
download | gnunet-42b829bb6005f07403370931509d0f83b4235e15.tar.gz gnunet-42b829bb6005f07403370931509d0f83b4235e15.zip |
-address #3050, refresh encrypted blocks from plaintext blocks during iteration, compute block expiration time correctly
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 108 | ||||
-rw-r--r-- | src/namestore/namestore_api_common.c | 2 | ||||
-rw-r--r-- | src/namestore/plugin_namestore_sqlite.c | 46 |
3 files changed, 121 insertions, 35 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 4c64dcd29..b39d3858c 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -552,6 +552,45 @@ send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc, | |||
552 | 552 | ||
553 | 553 | ||
554 | /** | 554 | /** |
555 | * We just touched the plaintext information about a name in our zone; | ||
556 | * refresh the corresponding (encrypted) block in the namestore. | ||
557 | * | ||
558 | * @param zone_key private key of the zone | ||
559 | * @param name label for the records | ||
560 | * @param rd_count number of records | ||
561 | * @param rd records stored under the given @a name | ||
562 | */ | ||
563 | static void | ||
564 | refresh_block (const struct GNUNET_CRYPTO_EccPrivateKey *zone_key, | ||
565 | const char *name, | ||
566 | unsigned int rd_count, | ||
567 | const struct GNUNET_NAMESTORE_RecordData *rd) | ||
568 | { | ||
569 | struct GNUNET_NAMESTORE_Block *block; | ||
570 | |||
571 | if (0 == rd_count) | ||
572 | block = GNUNET_NAMESTORE_block_create (zone_key, | ||
573 | GNUNET_TIME_UNIT_ZERO_ABS, | ||
574 | name, | ||
575 | rd, rd_count); | ||
576 | else | ||
577 | block = GNUNET_NAMESTORE_block_create (zone_key, | ||
578 | GNUNET_NAMESTORE_record_get_expiration_time (rd_count, | ||
579 | rd), | ||
580 | name, | ||
581 | rd, rd_count); | ||
582 | if (GNUNET_OK != | ||
583 | GSN_database->cache_block (GSN_database->cls, | ||
584 | block)) | ||
585 | { | ||
586 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
587 | _("Failed to cache encrypted block of my own zone!\n")); | ||
588 | } | ||
589 | GNUNET_free (block); | ||
590 | } | ||
591 | |||
592 | |||
593 | /** | ||
555 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE message | 594 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE message |
556 | * | 595 | * |
557 | * @param cls unused | 596 | * @param cls unused |
@@ -577,6 +616,7 @@ handle_record_store (void *cls, | |||
577 | unsigned int rd_count; | 616 | unsigned int rd_count; |
578 | int res; | 617 | int res; |
579 | struct GNUNET_CRYPTO_EccPublicSignKey pubkey; | 618 | struct GNUNET_CRYPTO_EccPublicSignKey pubkey; |
619 | struct ZoneMonitor *zm; | ||
580 | 620 | ||
581 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 621 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
582 | "Received `%s' message\n", | 622 | "Received `%s' message\n", |
@@ -644,7 +684,10 @@ handle_record_store (void *cls, | |||
644 | conv_name, | 684 | conv_name, |
645 | GNUNET_NAMESTORE_z2s (&pubkey)); | 685 | GNUNET_NAMESTORE_z2s (&pubkey)); |
646 | 686 | ||
647 | if ((rd_count == 0) && (GNUNET_NO == GSN_database->iterate_records (GSN_database->cls, &rp_msg->private_key, 0, NULL, 0))) | 687 | if ( (0 == rd_count) && |
688 | (GNUNET_NO == | ||
689 | GSN_database->iterate_records (GSN_database->cls, | ||
690 | &rp_msg->private_key, 0, NULL, 0)) ) | ||
648 | { | 691 | { |
649 | /* This name does not exist, so cannot be removed */ | 692 | /* This name does not exist, so cannot be removed */ |
650 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 693 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -660,39 +703,20 @@ handle_record_store (void *cls, | |||
660 | rd_count, rd); | 703 | rd_count, rd); |
661 | if (GNUNET_OK == res) | 704 | if (GNUNET_OK == res) |
662 | { | 705 | { |
663 | struct ZoneMonitor *zm; | 706 | refresh_block (&rp_msg->private_key, |
664 | struct GNUNET_NAMESTORE_Block *block; | 707 | conv_name, |
665 | 708 | rd_count, rd); | |
666 | if (0 == rd_count) | 709 | |
667 | block = GNUNET_NAMESTORE_block_create (&rp_msg->private_key, | 710 | for (zm = monitor_head; NULL != zm; zm = zm->next) |
668 | GNUNET_TIME_UNIT_ZERO_ABS, | 711 | if (0 == memcmp (&rp_msg->private_key, &zm->zone, |
669 | conv_name, | 712 | sizeof (struct GNUNET_CRYPTO_EccPrivateKey))) |
670 | rd, rd_count); | 713 | send_lookup_response (monitor_nc, |
671 | else | 714 | zm->nc->client, |
672 | block = GNUNET_NAMESTORE_block_create (&rp_msg->private_key, | 715 | zm->request_id, |
673 | GNUNET_TIME_UNIT_FOREVER_ABS, | 716 | &rp_msg->private_key, |
674 | conv_name, | 717 | conv_name, |
675 | rd, rd_count); | 718 | rd_count, rd); |
676 | if (GNUNET_OK != | 719 | } |
677 | GSN_database->cache_block (GSN_database->cls, | ||
678 | block)) | ||
679 | { | ||
680 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
681 | _("Failed to cache encrypted block of my own zone!\n")); | ||
682 | res = GNUNET_SYSERR; | ||
683 | } | ||
684 | GNUNET_free (block); | ||
685 | |||
686 | for (zm = monitor_head; NULL != zm; zm = zm->next) | ||
687 | if (0 == memcmp (&rp_msg->private_key, &zm->zone, | ||
688 | sizeof (struct GNUNET_CRYPTO_EccPrivateKey))) | ||
689 | send_lookup_response (monitor_nc, | ||
690 | zm->nc->client, | ||
691 | zm->request_id, | ||
692 | &rp_msg->private_key, | ||
693 | conv_name, | ||
694 | rd_count, rd); | ||
695 | } | ||
696 | GNUNET_free (conv_name); | 720 | GNUNET_free (conv_name); |
697 | } | 721 | } |
698 | } | 722 | } |
@@ -914,6 +938,8 @@ zone_iteraterate_proc (void *cls, | |||
914 | const struct GNUNET_NAMESTORE_RecordData *rd) | 938 | const struct GNUNET_NAMESTORE_RecordData *rd) |
915 | { | 939 | { |
916 | struct ZoneIterationProcResult *proc = cls; | 940 | struct ZoneIterationProcResult *proc = cls; |
941 | unsigned int i; | ||
942 | int do_refresh_block; | ||
917 | 943 | ||
918 | if ((NULL == zone_key) && (NULL == name)) | 944 | if ((NULL == zone_key) && (NULL == name)) |
919 | { | 945 | { |
@@ -937,6 +963,20 @@ zone_iteraterate_proc (void *cls, | |||
937 | name, | 963 | name, |
938 | rd_count, | 964 | rd_count, |
939 | rd); | 965 | rd); |
966 | do_refresh_block = GNUNET_NO; | ||
967 | for (i=0;i<rd_count;i++) | ||
968 | if( (0 != (rd[i].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION)) && | ||
969 | (0 == (rd[i].flags & GNUNET_NAMESTORE_RF_PENDING)) ) | ||
970 | { | ||
971 | do_refresh_block = GNUNET_YES; | ||
972 | break; | ||
973 | } | ||
974 | if (GNUNET_YES == do_refresh_block) | ||
975 | refresh_block (zone_key, | ||
976 | name, | ||
977 | rd_count, | ||
978 | rd); | ||
979 | |||
940 | } | 980 | } |
941 | 981 | ||
942 | 982 | ||
diff --git a/src/namestore/namestore_api_common.c b/src/namestore/namestore_api_common.c index e6b78d8c9..e9d15b205 100644 --- a/src/namestore/namestore_api_common.c +++ b/src/namestore/namestore_api_common.c | |||
@@ -276,7 +276,7 @@ GNUNET_NAMESTORE_records_deserialize (size_t len, | |||
276 | 276 | ||
277 | /** | 277 | /** |
278 | * Returns the expiration time of the given block of records. The block | 278 | * Returns the expiration time of the given block of records. The block |
279 | * expiration time is the expiration time of the block with smallest | 279 | * expiration time is the expiration time of the record with smallest |
280 | * expiration time. | 280 | * expiration time. |
281 | * | 281 | * |
282 | * @param rd_count number of records given in @a rd | 282 | * @param rd_count number of records given in @a rd |
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c index 4c040cc97..134b65395 100644 --- a/src/namestore/plugin_namestore_sqlite.c +++ b/src/namestore/plugin_namestore_sqlite.c | |||
@@ -77,6 +77,11 @@ struct Plugin | |||
77 | sqlite3_stmt *cache_block; | 77 | sqlite3_stmt *cache_block; |
78 | 78 | ||
79 | /** | 79 | /** |
80 | * Precompiled SQL for deleting an older block | ||
81 | */ | ||
82 | sqlite3_stmt *delete_block; | ||
83 | |||
84 | /** | ||
80 | * Precompiled SQL for looking up a block | 85 | * Precompiled SQL for looking up a block |
81 | */ | 86 | */ |
82 | sqlite3_stmt *lookup_block; | 87 | sqlite3_stmt *lookup_block; |
@@ -305,6 +310,10 @@ database_setup (struct Plugin *plugin) | |||
305 | &plugin->expire_blocks) != SQLITE_OK) || | 310 | &plugin->expire_blocks) != SQLITE_OK) || |
306 | (sq_prepare | 311 | (sq_prepare |
307 | (plugin->dbh, | 312 | (plugin->dbh, |
313 | "DELETE FROM ns096blocks WHERE query=? AND expiration_time<=?", | ||
314 | &plugin->delete_block) != SQLITE_OK) || | ||
315 | (sq_prepare | ||
316 | (plugin->dbh, | ||
308 | "SELECT block FROM ns096blocks WHERE query=? ORDER BY expiration_time DESC LIMIT 1", | 317 | "SELECT block FROM ns096blocks WHERE query=? ORDER BY expiration_time DESC LIMIT 1", |
309 | &plugin->lookup_block) != SQLITE_OK) || | 318 | &plugin->lookup_block) != SQLITE_OK) || |
310 | (sq_prepare | 319 | (sq_prepare |
@@ -357,6 +366,8 @@ database_shutdown (struct Plugin *plugin) | |||
357 | sqlite3_finalize (plugin->lookup_block); | 366 | sqlite3_finalize (plugin->lookup_block); |
358 | if (NULL != plugin->expire_blocks) | 367 | if (NULL != plugin->expire_blocks) |
359 | sqlite3_finalize (plugin->expire_blocks); | 368 | sqlite3_finalize (plugin->expire_blocks); |
369 | if (NULL != plugin->delete_block) | ||
370 | sqlite3_finalize (plugin->delete_block); | ||
360 | if (NULL != plugin->store_records) | 371 | if (NULL != plugin->store_records) |
361 | sqlite3_finalize (plugin->store_records); | 372 | sqlite3_finalize (plugin->store_records); |
362 | if (NULL != plugin->delete_records) | 373 | if (NULL != plugin->delete_records) |
@@ -470,6 +481,41 @@ namestore_sqlite_cache_block (void *cls, | |||
470 | GNUNET_break (0); | 481 | GNUNET_break (0); |
471 | return GNUNET_SYSERR; | 482 | return GNUNET_SYSERR; |
472 | } | 483 | } |
484 | |||
485 | /* delete old version of the block */ | ||
486 | if ( (SQLITE_OK != | ||
487 | sqlite3_bind_blob (plugin->delete_block, 1, | ||
488 | &query, sizeof (struct GNUNET_HashCode), | ||
489 | SQLITE_STATIC)) || | ||
490 | (SQLITE_OK != | ||
491 | sqlite3_bind_int64 (plugin->delete_block, | ||
492 | 2, dval)) ) | ||
493 | { | ||
494 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
495 | "sqlite3_bind_XXXX"); | ||
496 | if (SQLITE_OK != sqlite3_reset (plugin->delete_block)) | ||
497 | LOG_SQLITE (plugin, | ||
498 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
499 | "sqlite3_reset"); | ||
500 | return GNUNET_SYSERR; | ||
501 | } | ||
502 | n = sqlite3_step (plugin->delete_block); | ||
503 | switch (n) | ||
504 | { | ||
505 | case SQLITE_DONE: | ||
506 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", "Old block deleted\n"); | ||
507 | break; | ||
508 | case SQLITE_BUSY: | ||
509 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | ||
510 | "sqlite3_step"); | ||
511 | break; | ||
512 | default: | ||
513 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
514 | "sqlite3_step"); | ||
515 | break; | ||
516 | } | ||
517 | |||
518 | /* insert new version of the block */ | ||
473 | if ((SQLITE_OK != | 519 | if ((SQLITE_OK != |
474 | sqlite3_bind_blob (plugin->cache_block, 1, | 520 | sqlite3_bind_blob (plugin->cache_block, 1, |
475 | &query, sizeof (struct GNUNET_HashCode), | 521 | &query, sizeof (struct GNUNET_HashCode), |