aboutsummaryrefslogtreecommitdiff
path: root/src/datacache/plugin_datacache_sqlite.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/datacache/plugin_datacache_sqlite.c')
-rw-r--r--src/datacache/plugin_datacache_sqlite.c52
1 files changed, 37 insertions, 15 deletions
diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c
index d08b32caf..46ff66dce 100644
--- a/src/datacache/plugin_datacache_sqlite.c
+++ b/src/datacache/plugin_datacache_sqlite.c
@@ -454,6 +454,7 @@ sqlite_plugin_del (void *cls)
454 * 454 *
455 * @param cls closure (internal context for the plugin) 455 * @param cls closure (internal context for the plugin)
456 * @param key area of the keyspace to look into 456 * @param key area of the keyspace to look into
457 * @param type desired block type for the replies
457 * @param num_results number of results that should be returned to @a iter 458 * @param num_results number of results that should be returned to @a iter
458 * @param iter maybe NULL (to just count) 459 * @param iter maybe NULL (to just count)
459 * @param iter_cls closure for @a iter 460 * @param iter_cls closure for @a iter
@@ -462,11 +463,13 @@ sqlite_plugin_del (void *cls)
462static unsigned int 463static unsigned int
463sqlite_plugin_get_closest (void *cls, 464sqlite_plugin_get_closest (void *cls,
464 const struct GNUNET_HashCode *key, 465 const struct GNUNET_HashCode *key,
466 enum GNUNET_BLOCK_Type type,
465 unsigned int num_results, 467 unsigned int num_results,
466 GNUNET_DATACACHE_Iterator iter, 468 GNUNET_DATACACHE_Iterator iter,
467 void *iter_cls) 469 void *iter_cls)
468{ 470{
469 struct Plugin *plugin = cls; 471 struct Plugin *plugin = cls;
472 uint32_t type32 = type;
470 uint32_t num_results32 = num_results; 473 uint32_t num_results32 = num_results;
471 struct GNUNET_TIME_Absolute now; 474 struct GNUNET_TIME_Absolute now;
472 struct GNUNET_TIME_Absolute exp; 475 struct GNUNET_TIME_Absolute exp;
@@ -474,38 +477,46 @@ sqlite_plugin_get_closest (void *cls,
474 void *dat; 477 void *dat;
475 unsigned int cnt; 478 unsigned int cnt;
476 size_t psize; 479 size_t psize;
477 uint32_t type; 480 uint32_t rtype;
478 struct GNUNET_HashCode hc; 481 struct GNUNET_HashCode hc;
479 struct GNUNET_DHT_PathElement *path; 482 struct GNUNET_DHT_PathElement *path;
480 struct GNUNET_SQ_QueryParam params[] = 483 struct GNUNET_SQ_QueryParam params[] = {
481 { GNUNET_SQ_query_param_auto_from_type (key), 484 GNUNET_SQ_query_param_auto_from_type (key),
482 GNUNET_SQ_query_param_absolute_time (&now), 485 GNUNET_SQ_query_param_absolute_time (&now),
486 GNUNET_SQ_query_param_uint32 (&type32),
483 GNUNET_SQ_query_param_uint32 (&num_results32), 487 GNUNET_SQ_query_param_uint32 (&num_results32),
484 GNUNET_SQ_query_param_end }; 488 GNUNET_SQ_query_param_end
485 struct GNUNET_SQ_ResultSpec rs[] = 489 };
486 { GNUNET_SQ_result_spec_variable_size (&dat, &size), 490 struct GNUNET_SQ_ResultSpec rs[] = {
491 GNUNET_SQ_result_spec_variable_size (&dat, &size),
487 GNUNET_SQ_result_spec_absolute_time (&exp), 492 GNUNET_SQ_result_spec_absolute_time (&exp),
488 GNUNET_SQ_result_spec_variable_size ((void **) &path, &psize), 493 GNUNET_SQ_result_spec_variable_size ((void **) &path, &psize),
489 GNUNET_SQ_result_spec_uint32 (&type), 494 GNUNET_SQ_result_spec_uint32 (&rtype),
490 GNUNET_SQ_result_spec_auto_from_type (&hc), 495 GNUNET_SQ_result_spec_auto_from_type (&hc),
491 GNUNET_SQ_result_spec_end }; 496 GNUNET_SQ_result_spec_end
497 };
492 498
493 now = GNUNET_TIME_absolute_get (); 499 now = GNUNET_TIME_absolute_get ();
494 LOG (GNUNET_ERROR_TYPE_DEBUG, 500 LOG (GNUNET_ERROR_TYPE_DEBUG,
495 "Processing GET_CLOSEST for key `%s'\n", 501 "Processing GET_CLOSEST for key `%s'\n",
496 GNUNET_h2s (key)); 502 GNUNET_h2s (key));
497 if (GNUNET_OK != GNUNET_SQ_bind (plugin->get_closest_stmt, params)) 503 if (GNUNET_OK !=
504 GNUNET_SQ_bind (plugin->get_closest_stmt,
505 params))
498 { 506 {
499 LOG_SQLITE (plugin->dbh, 507 LOG_SQLITE (plugin->dbh,
500 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 508 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
501 "sqlite3_bind_xxx"); 509 "sqlite3_bind_xxx");
502 GNUNET_SQ_reset (plugin->dbh, plugin->get_closest_stmt); 510 GNUNET_SQ_reset (plugin->dbh,
511 plugin->get_closest_stmt);
503 return 0; 512 return 0;
504 } 513 }
505 cnt = 0; 514 cnt = 0;
506 while (SQLITE_ROW == sqlite3_step (plugin->get_closest_stmt)) 515 while (SQLITE_ROW == sqlite3_step (plugin->get_closest_stmt))
507 { 516 {
508 if (GNUNET_OK != GNUNET_SQ_extract_result (plugin->get_closest_stmt, rs)) 517 if (GNUNET_OK !=
518 GNUNET_SQ_extract_result (plugin->get_closest_stmt,
519 rs))
509 { 520 {
510 GNUNET_break (0); 521 GNUNET_break (0);
511 break; 522 break;
@@ -522,14 +533,22 @@ sqlite_plugin_get_closest (void *cls,
522 "Found %u-byte result at %s when processing GET_CLOSE\n", 533 "Found %u-byte result at %s when processing GET_CLOSE\n",
523 (unsigned int) size, 534 (unsigned int) size,
524 GNUNET_h2s (&hc)); 535 GNUNET_h2s (&hc));
525 if (GNUNET_OK != iter (iter_cls, &hc, size, dat, type, exp, psize, path)) 536 if (GNUNET_OK != iter (iter_cls,
537 &hc,
538 size,
539 dat,
540 rtype,
541 exp,
542 psize,
543 path))
526 { 544 {
527 GNUNET_SQ_cleanup_result (rs); 545 GNUNET_SQ_cleanup_result (rs);
528 break; 546 break;
529 } 547 }
530 GNUNET_SQ_cleanup_result (rs); 548 GNUNET_SQ_cleanup_result (rs);
531 } 549 }
532 GNUNET_SQ_reset (plugin->dbh, plugin->get_closest_stmt); 550 GNUNET_SQ_reset (plugin->dbh,
551 plugin->get_closest_stmt);
533 return cnt; 552 return cnt;
534} 553}
535 554
@@ -620,7 +639,7 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
620 &plugin->get_stmt)) || 639 &plugin->get_stmt)) ||
621 (SQLITE_OK != sq_prepare (plugin->dbh, 640 (SQLITE_OK != sq_prepare (plugin->dbh,
622 "SELECT _ROWID_,key,value FROM ds091" 641 "SELECT _ROWID_,key,value FROM ds091"
623 " WHERE expire < ?" 642 " WHERE expire < ?1"
624 " ORDER BY expire ASC LIMIT 1", 643 " ORDER BY expire ASC LIMIT 1",
625 &plugin->del_expired_stmt)) || 644 &plugin->del_expired_stmt)) ||
626 (SQLITE_OK != sq_prepare (plugin->dbh, 645 (SQLITE_OK != sq_prepare (plugin->dbh,
@@ -633,7 +652,10 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
633 (SQLITE_OK != 652 (SQLITE_OK !=
634 sq_prepare (plugin->dbh, 653 sq_prepare (plugin->dbh,
635 "SELECT value,expire,path,type,key FROM ds091 " 654 "SELECT value,expire,path,type,key FROM ds091 "
636 "WHERE key>=? AND expire >= ? ORDER BY KEY ASC LIMIT ?", 655 " WHERE key>=?1 "
656 " AND expire >= ?2"
657 " AND ( (type=?3) or (0 == ?3) )"
658 " ORDER BY KEY ASC LIMIT ?4",
637 &plugin->get_closest_stmt))) 659 &plugin->get_closest_stmt)))
638 { 660 {
639 LOG_SQLITE (plugin->dbh, 661 LOG_SQLITE (plugin->dbh,