diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-09-30 13:02:33 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-09-30 13:02:33 +0000 |
commit | 39e93d4bdd4ac7d2de4c736856817f402722ebae (patch) | |
tree | ad68249647bc3e147947908c5142856b26ee2c96 /src/namestore | |
parent | 87ed5554b390cbf16a9bd15c4aec13ab34d7f080 (diff) | |
download | gnunet-39e93d4bdd4ac7d2de4c736856817f402722ebae.tar.gz gnunet-39e93d4bdd4ac7d2de4c736856817f402722ebae.zip |
-fix expiration time, sqlite can only do 63-bit integers, as they are always signed
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/plugin_namestore_sqlite.c | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c index 04291cd69..f2f884290 100644 --- a/src/namestore/plugin_namestore_sqlite.c +++ b/src/namestore/plugin_namestore_sqlite.c | |||
@@ -441,7 +441,7 @@ namestore_sqlite_expire_blocks (struct Plugin *plugin) | |||
441 | * | 441 | * |
442 | * @param cls closure (internal context for the plugin) | 442 | * @param cls closure (internal context for the plugin) |
443 | * @param block block to cache | 443 | * @param block block to cache |
444 | * @return GNUNET_OK on success, else GNUNET_SYSERR | 444 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR |
445 | */ | 445 | */ |
446 | static int | 446 | static int |
447 | namestore_sqlite_cache_block (void *cls, | 447 | namestore_sqlite_cache_block (void *cls, |
@@ -450,6 +450,7 @@ namestore_sqlite_cache_block (void *cls, | |||
450 | struct Plugin *plugin = cls; | 450 | struct Plugin *plugin = cls; |
451 | struct GNUNET_HashCode query; | 451 | struct GNUNET_HashCode query; |
452 | struct GNUNET_TIME_Absolute expiration; | 452 | struct GNUNET_TIME_Absolute expiration; |
453 | int64_t dval; | ||
453 | size_t block_size; | 454 | size_t block_size; |
454 | int n; | 455 | int n; |
455 | 456 | ||
@@ -458,6 +459,9 @@ namestore_sqlite_cache_block (void *cls, | |||
458 | sizeof (struct GNUNET_CRYPTO_EccPublicSignKey), | 459 | sizeof (struct GNUNET_CRYPTO_EccPublicSignKey), |
459 | &query); | 460 | &query); |
460 | expiration = GNUNET_TIME_absolute_ntoh (block->expiration_time); | 461 | expiration = GNUNET_TIME_absolute_ntoh (block->expiration_time); |
462 | dval = (int64_t) expiration.abs_value_us; | ||
463 | if (dval < 0) | ||
464 | dval = INT64_MAX; | ||
461 | block_size = ntohl (block->purpose.size) + | 465 | block_size = ntohl (block->purpose.size) + |
462 | sizeof (struct GNUNET_CRYPTO_EccPublicSignKey) + | 466 | sizeof (struct GNUNET_CRYPTO_EccPublicSignKey) + |
463 | sizeof (struct GNUNET_CRYPTO_EccSignature); | 467 | sizeof (struct GNUNET_CRYPTO_EccSignature); |
@@ -466,9 +470,17 @@ namestore_sqlite_cache_block (void *cls, | |||
466 | GNUNET_break (0); | 470 | GNUNET_break (0); |
467 | return GNUNET_SYSERR; | 471 | return GNUNET_SYSERR; |
468 | } | 472 | } |
469 | if ((SQLITE_OK != sqlite3_bind_blob (plugin->cache_block, 1, &query, sizeof (struct GNUNET_HashCode), SQLITE_STATIC)) || | 473 | if ((SQLITE_OK != |
470 | (SQLITE_OK != sqlite3_bind_blob (plugin->cache_block, 2, block, block_size, SQLITE_STATIC)) || | 474 | sqlite3_bind_blob (plugin->cache_block, 1, |
471 | (SQLITE_OK != sqlite3_bind_int64 (plugin->cache_block, 3, expiration.abs_value_us))) | 475 | &query, sizeof (struct GNUNET_HashCode), |
476 | SQLITE_STATIC)) || | ||
477 | (SQLITE_OK != | ||
478 | sqlite3_bind_blob (plugin->cache_block, 2, | ||
479 | block, block_size, | ||
480 | SQLITE_STATIC)) || | ||
481 | (SQLITE_OK != | ||
482 | sqlite3_bind_int64 (plugin->cache_block, 3, | ||
483 | dval))) | ||
472 | { | 484 | { |
473 | LOG_SQLITE (plugin, | 485 | LOG_SQLITE (plugin, |
474 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 486 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
@@ -482,7 +494,7 @@ namestore_sqlite_cache_block (void *cls, | |||
482 | } | 494 | } |
483 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 495 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
484 | "Caching block under derived key `%s'\n", | 496 | "Caching block under derived key `%s'\n", |
485 | GNUNET_h2s (&query)); | 497 | GNUNET_h2s_full (&query)); |
486 | n = sqlite3_step (plugin->cache_block); | 498 | n = sqlite3_step (plugin->cache_block); |
487 | if (SQLITE_OK != sqlite3_reset (plugin->cache_block)) | 499 | if (SQLITE_OK != sqlite3_reset (plugin->cache_block)) |
488 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 500 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
@@ -490,7 +502,8 @@ namestore_sqlite_cache_block (void *cls, | |||
490 | switch (n) | 502 | switch (n) |
491 | { | 503 | { |
492 | case SQLITE_DONE: | 504 | case SQLITE_DONE: |
493 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", "Record stored\n"); | 505 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
506 | "Record stored\n"); | ||
494 | return GNUNET_OK; | 507 | return GNUNET_OK; |
495 | case SQLITE_BUSY: | 508 | case SQLITE_BUSY: |
496 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 509 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
@@ -511,7 +524,7 @@ namestore_sqlite_cache_block (void *cls, | |||
511 | * @param cls closure (internal context for the plugin) | 524 | * @param cls closure (internal context for the plugin) |
512 | * @param query hash of public key derived from the zone and the label | 525 | * @param query hash of public key derived from the zone and the label |
513 | * @param iter function to call with the result | 526 | * @param iter function to call with the result |
514 | * @param iter_cls closure for iter | 527 | * @param iter_cls closure for @a iter |
515 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error | 528 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error |
516 | */ | 529 | */ |
517 | static int | 530 | static int |
@@ -554,7 +567,7 @@ namestore_sqlite_lookup_block (void *cls, | |||
554 | { | 567 | { |
555 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 568 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
556 | "Found block under derived key `%s'\n", | 569 | "Found block under derived key `%s'\n", |
557 | GNUNET_h2s (query)); | 570 | GNUNET_h2s_full (query)); |
558 | iter (iter_cls, block); | 571 | iter (iter_cls, block); |
559 | ret = GNUNET_YES; | 572 | ret = GNUNET_YES; |
560 | } | 573 | } |
@@ -570,7 +583,7 @@ namestore_sqlite_lookup_block (void *cls, | |||
570 | { | 583 | { |
571 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 584 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
572 | "No block found under derived key `%s'\n", | 585 | "No block found under derived key `%s'\n", |
573 | GNUNET_h2s (query)); | 586 | GNUNET_h2s_full (query)); |
574 | } | 587 | } |
575 | } | 588 | } |
576 | if (SQLITE_OK != sqlite3_reset (plugin->lookup_block)) | 589 | if (SQLITE_OK != sqlite3_reset (plugin->lookup_block)) |
@@ -588,7 +601,7 @@ namestore_sqlite_lookup_block (void *cls, | |||
588 | * @param cls closure (internal context for the plugin) | 601 | * @param cls closure (internal context for the plugin) |
589 | * @param zone_key private key of the zone | 602 | * @param zone_key private key of the zone |
590 | * @param label name that is being mapped (at most 255 characters long) | 603 | * @param label name that is being mapped (at most 255 characters long) |
591 | * @param rd_count number of entries in 'rd' array | 604 | * @param rd_count number of entries in @a rd array |
592 | * @param rd array of records with data to store | 605 | * @param rd array of records with data to store |
593 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | 606 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR |
594 | */ | 607 | */ |