aboutsummaryrefslogtreecommitdiff
path: root/src/datastore
diff options
context:
space:
mode:
authorChristophe Genevey Metat <genevey.christophe@gmail.com>2016-06-17 15:28:55 +0000
committerChristophe Genevey Metat <genevey.christophe@gmail.com>2016-06-17 15:28:55 +0000
commit5623b6bfbcafeb80f44b6882729a104ad60d9b09 (patch)
tree1c475bcb403180213dc466f36b203b922b420540 /src/datastore
parent0539ede165af8110a046b6ea1121e13dffc35abe (diff)
downloadgnunet-5623b6bfbcafeb80f44b6882729a104ad60d9b09.tar.gz
gnunet-5623b6bfbcafeb80f44b6882729a104ad60d9b09.zip
plugin datastore mysql
Diffstat (limited to 'src/datastore')
-rw-r--r--src/datastore/Makefile.am1
-rw-r--r--src/datastore/plugin_datastore_mysql.c316
2 files changed, 282 insertions, 35 deletions
diff --git a/src/datastore/Makefile.am b/src/datastore/Makefile.am
index 9d08c8ac9..6a4b6a27b 100644
--- a/src/datastore/Makefile.am
+++ b/src/datastore/Makefile.am
@@ -28,6 +28,7 @@ libgnunetdatastore_la_SOURCES = \
28libgnunetdatastore_la_LIBADD = \ 28libgnunetdatastore_la_LIBADD = \
29 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 29 $(top_builddir)/src/statistics/libgnunetstatistics.la \
30 $(top_builddir)/src/util/libgnunetutil.la \ 30 $(top_builddir)/src/util/libgnunetutil.la \
31 $(top_builddir)/src/my/libgnunetmy.la \
31 $(GN_LIBINTL) 32 $(GN_LIBINTL)
32libgnunetdatastore_la_LDFLAGS = \ 33libgnunetdatastore_la_LDFLAGS = \
33 $(GN_LIB_LDFLAGS) $(WINFLAGS) \ 34 $(GN_LIB_LDFLAGS) $(WINFLAGS) \
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c
index 0d9f58783..eb04ac56b 100644
--- a/src/datastore/plugin_datastore_mysql.c
+++ b/src/datastore/plugin_datastore_mysql.c
@@ -120,6 +120,7 @@
120#include "gnunet_datastore_plugin.h" 120#include "gnunet_datastore_plugin.h"
121#include "gnunet_util_lib.h" 121#include "gnunet_util_lib.h"
122#include "gnunet_mysql_lib.h" 122#include "gnunet_mysql_lib.h"
123#include "gnunet_my_lib.h"
123 124
124 125
125#define MAX_DATUM_SIZE 65536 126#define MAX_DATUM_SIZE 65536
@@ -228,9 +229,25 @@ do_delete_entry (struct Plugin *plugin, unsigned long long uid)
228 229
229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting value %llu from gn090 table\n", 230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting value %llu from gn090 table\n",
230 uid); 231 uid);
231 ret = GNUNET_MYSQL_statement_run_prepared (plugin->mc, 232/* ret = GNUNET_MYSQL_statement_run_prepared (plugin->mc,
232 plugin->delete_entry_by_uid, NULL, 233 plugin->delete_entry_by_uid,
233 MYSQL_TYPE_LONGLONG, &uid, GNUNET_YES, -1); 234 NULL,
235 MYSQL_TYPE_LONGLONG,
236 &uid,
237 GNUNET_YES,
238 -1);
239*/
240
241 uint64_t uid64 = (uint64_t) uid;
242
243 struct GNUNET_MY_QueryParam params_delete[] = {
244 GNUNET_MY_query_param_uint64 (&uid64),
245 GNUNET_MY_query_param_end
246 };
247
248 ret = GNUNET_MY_exec_prepared (plugin->mc,
249 plugin->delete_entry_by_uid,
250 params_delete);
234 if (ret >= 0) 251 if (ret >= 0)
235 return GNUNET_OK; 252 return GNUNET_OK;
236 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 253 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -250,19 +267,39 @@ static void
250mysql_plugin_estimate_size (void *cls, unsigned long long *estimate) 267mysql_plugin_estimate_size (void *cls, unsigned long long *estimate)
251{ 268{
252 struct Plugin *plugin = cls; 269 struct Plugin *plugin = cls;
253 MYSQL_BIND cbind[1]; 270// MYSQL_BIND cbind[1];
254 long long total; 271 uint64_t total;
272// long long total;
255 273
256 if (NULL == estimate) 274 if (NULL == estimate)
257 return; 275 return;
258 memset (cbind, 0, sizeof (cbind)); 276// memset (cbind, 0, sizeof (cbind));
259 total = 0; 277 total = 0;
260 cbind[0].buffer_type = MYSQL_TYPE_LONGLONG; 278/* cbind[0].buffer_type = MYSQL_TYPE_LONGLONG;
261 cbind[0].buffer = &total; 279 cbind[0].buffer = &total;
262 cbind[0].is_unsigned = GNUNET_NO; 280 cbind[0].is_unsigned = GNUNET_NO;
263 if (GNUNET_OK == 281*/
282 struct GNUNET_MY_QueryParam params_get[] = {
283 GNUNET_MY_query_param_end
284 };
285
286 struct GNUNET_MY_ResultSpec results_get[] = {
287 GNUNET_MY_result_spec_uint64 (&total),
288 GNUNET_MY_result_spec_end
289 };
290
291/* if (GNUNET_OK ==
264 GNUNET_MYSQL_statement_run_prepared_select (plugin->mc, plugin->get_size, 1, cbind, NULL, NULL, -1)) 292 GNUNET_MYSQL_statement_run_prepared_select (plugin->mc, plugin->get_size, 1, cbind, NULL, NULL, -1))
265 *estimate = total; 293*/ if (GNUNET_OK ==
294 GNUNET_MY_exec_prepared (plugin->mc, plugin->get_size, params_get))
295 {
296 if (GNUNET_OK == GNUNET_MY_extract_result (plugin->get_size, results_get))
297 {
298 *estimate = (unsigned long long)total;
299 }
300 }
301
302// *estimate = total;
266 else 303 else
267 *estimate = 0; 304 *estimate = 0;
268} 305}
@@ -313,7 +350,21 @@ mysql_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
313 hashSize2 = sizeof (struct GNUNET_HashCode); 350 hashSize2 = sizeof (struct GNUNET_HashCode);
314 lsize = size; 351 lsize = size;
315 GNUNET_CRYPTO_hash (data, size, &vhash); 352 GNUNET_CRYPTO_hash (data, size, &vhash);
316 if (GNUNET_OK != 353
354 struct GNUNET_MY_QueryParam params_insert[] = {
355 GNUNET_MY_query_param_uint32 (&irepl),
356 GNUNET_MY_query_param_uint32 (&type),
357 GNUNET_MY_query_param_uint32 (&ipriority),
358 GNUNET_MY_query_param_uint32 (&ianonymity),
359 GNUNET_MY_query_param_uint64 (&lexpiration),
360 GNUNET_MY_query_param_uint64 (&lrvalue),
361 GNUNET_MY_query_param_fixed_size (key, hashSize),
362 GNUNET_MY_query_param_fixed_size (&vhash, hashSize2),
363 GNUNET_MY_query_param_fixed_size (data, lsize),
364 GNUNET_MY_query_param_end
365 };
366
367/* if (GNUNET_OK !=
317 GNUNET_MYSQL_statement_run_prepared (plugin->mc, plugin->insert_entry, NULL, 368 GNUNET_MYSQL_statement_run_prepared (plugin->mc, plugin->insert_entry, NULL,
318 MYSQL_TYPE_LONG, &irepl, GNUNET_YES, 369 MYSQL_TYPE_LONG, &irepl, GNUNET_YES,
319 MYSQL_TYPE_LONG, &type, GNUNET_YES, 370 MYSQL_TYPE_LONG, &type, GNUNET_YES,
@@ -328,6 +379,16 @@ mysql_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
328 cont (cont_cls, key, size, GNUNET_SYSERR, _("MySQL statement run failure")); 379 cont (cont_cls, key, size, GNUNET_SYSERR, _("MySQL statement run failure"));
329 return; 380 return;
330 } 381 }
382*/
383 if (GNUNET_OK !=
384 GNUNET_MY_exec_prepared (plugin->mc,
385 plugin->insert_entry,
386 params_insert))
387 {
388 cont (cont_cls, key, size, GNUNET_SYSERR, _("MySQL statement run failure"));
389 return;
390 }
391
331 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
332 "Inserted value `%s' with size %u into gn090 table\n", 393 "Inserted value `%s' with size %u into gn090 table\n",
333 GNUNET_h2s (key), (unsigned int) size); 394 GNUNET_h2s (key), (unsigned int) size);
@@ -366,20 +427,35 @@ mysql_plugin_update (void *cls, uint64_t uid, int delta,
366 PluginUpdateCont cont, void *cont_cls) 427 PluginUpdateCont cont, void *cont_cls)
367{ 428{
368 struct Plugin *plugin = cls; 429 struct Plugin *plugin = cls;
430 uint32_t delta1 = (uint32_t)delta;
369 unsigned long long vkey = uid; 431 unsigned long long vkey = uid;
370 unsigned long long lexpire = expire.abs_value_us; 432// unsigned long long lexpire = expire.abs_value_us;
433 uint64_t lexpire = expire.abs_value_us;
371 int ret; 434 int ret;
372 435
373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 436 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
374 "Updating value %llu adding %d to priority and maxing exp at %s\n", 437 "Updating value %llu adding %d to priority and maxing exp at %s\n",
375 vkey, delta, 438 vkey, delta,
376 GNUNET_STRINGS_absolute_time_to_string (expire)); 439 GNUNET_STRINGS_absolute_time_to_string (expire));
377 ret = 440/* ret =
378 GNUNET_MYSQL_statement_run_prepared (plugin->mc, plugin->update_entry, NULL, 441 GNUNET_MYSQL_statement_run_prepared (plugin->mc, plugin->update_entry, NULL,
379 MYSQL_TYPE_LONG, &delta, GNUNET_NO, 442 MYSQL_TYPE_LONG, &delta, GNUNET_NO,
380 MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES, 443 MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES,
381 MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES, 444 MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES,
382 MYSQL_TYPE_LONGLONG, &vkey, GNUNET_YES, -1); 445 MYSQL_TYPE_LONGLONG, &vkey, GNUNET_YES, -1);
446*/
447 struct GNUNET_MY_QueryParam params_update[] = {
448 GNUNET_MY_query_param_uint32 (&delta1),
449 GNUNET_MY_query_param_uint64 (&lexpire),
450 GNUNET_MY_query_param_uint64 (&lexpire),
451 GNUNET_MY_query_param_uint64 (&uid),
452 GNUNET_MY_query_param_end
453 };
454
455 ret = GNUNET_MY_exec_prepared (plugin->mc,
456 plugin->update_entry,
457 params_update);
458
383 if (ret != GNUNET_OK) 459 if (ret != GNUNET_OK)
384 { 460 {
385 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to update value %llu\n", 461 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to update value %llu\n",
@@ -409,16 +485,18 @@ execute_select (struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stmt
409 unsigned int priority; 485 unsigned int priority;
410 unsigned int anonymity; 486 unsigned int anonymity;
411 unsigned long long exp; 487 unsigned long long exp;
412 unsigned long hashSize; 488 //unsigned long hashSize;
413 unsigned long size; 489 size_t hashSize;
414 unsigned long long uid; 490 //unsigned long size;
491 uint64_t size;
492 unsigned long long uid = 0;
415 char value[GNUNET_DATASTORE_MAX_VALUE_SIZE]; 493 char value[GNUNET_DATASTORE_MAX_VALUE_SIZE];
416 struct GNUNET_HashCode key; 494 struct GNUNET_HashCode key;
417 struct GNUNET_TIME_Absolute expiration; 495 struct GNUNET_TIME_Absolute expiration;
418 MYSQL_BIND rbind[7]; 496// MYSQL_BIND rbind[7];
419 497
420 hashSize = sizeof (struct GNUNET_HashCode); 498 hashSize = sizeof (struct GNUNET_HashCode);
421 memset (rbind, 0, sizeof (rbind)); 499/* memset (rbind, 0, sizeof (rbind));
422 rbind[0].buffer_type = MYSQL_TYPE_LONG; 500 rbind[0].buffer_type = MYSQL_TYPE_LONG;
423 rbind[0].buffer = &type; 501 rbind[0].buffer = &type;
424 rbind[0].is_unsigned = 1; 502 rbind[0].is_unsigned = 1;
@@ -442,19 +520,48 @@ execute_select (struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stmt
442 rbind[6].buffer_type = MYSQL_TYPE_LONGLONG; 520 rbind[6].buffer_type = MYSQL_TYPE_LONGLONG;
443 rbind[6].buffer = &uid; 521 rbind[6].buffer = &uid;
444 rbind[6].is_unsigned = 1; 522 rbind[6].is_unsigned = 1;
523*/
524 struct GNUNET_MY_QueryParam params_select[] ={
525 GNUNET_MY_query_param_end
526 };
527
528 struct GNUNET_MY_ResultSpec results_select[] = {
529 GNUNET_MY_result_spec_uint32 (&type),
530 GNUNET_MY_result_spec_uint32 (&priority),
531 GNUNET_MY_result_spec_uint32 (&anonymity),
532 GNUNET_MY_result_spec_uint64 (&exp),
533 GNUNET_MY_result_spec_auto_from_type (&key),
534// GNUNET_MY_result_spec_variable_size (&key, &hashSize),
535 GNUNET_MY_result_spec_fixed_size (value, sizeof (value)),
536 GNUNET_MY_result_spec_uint64 (&size),
537 GNUNET_MY_query_param_end
538 };
445 539
446 va_start (ap, proc_cls); 540 va_start (ap, proc_cls);
447 ret = GNUNET_MYSQL_statement_run_prepared_select_va (plugin->mc, stmt, 7, rbind, NULL, NULL, ap); 541// ret = GNUNET_MYSQL_statement_run_prepared_select_va (plugin->mc, stmt, 7, rbind, NULL, NULL, ap);
542 ret = GNUNET_MY_exec_prepared (plugin->mc, stmt, params_select);
448 va_end (ap); 543 va_end (ap);
449 if (ret <= 0) 544 if (ret <= 0)
450 { 545 {
451 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 546 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
452 return; 547 return;
453 } 548 }
549
550 ret = GNUNET_MY_extract_result (stmt, results_select);
551 if (ret <= 0)
552 {
553 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
554 return;
555 }
556
454 GNUNET_assert (size <= sizeof (value)); 557 GNUNET_assert (size <= sizeof (value));
455 if ((rbind[4].buffer_length != sizeof (struct GNUNET_HashCode)) || 558
559/* if ((rbind[4].buffer_length != sizeof (struct GNUNET_HashCode)) ||
456 (hashSize != sizeof (struct GNUNET_HashCode))) 560 (hashSize != sizeof (struct GNUNET_HashCode)))
457 { 561 {
562*/
563 if (hashSize != sizeof (struct GNUNET_HashCode))
564 {
458 GNUNET_break (0); 565 GNUNET_break (0);
459 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 566 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
460 return; 567 return;
@@ -505,8 +612,9 @@ mysql_plugin_get_key (void *cls, uint64_t offset, const struct GNUNET_HashCode *
505{ 612{
506 struct Plugin *plugin = cls; 613 struct Plugin *plugin = cls;
507 int ret; 614 int ret;
508 MYSQL_BIND cbind[1]; 615 //MYSQL_BIND cbind[1];
509 long long total; 616 //long long total;
617 uint64_t total;
510 unsigned long hashSize; 618 unsigned long hashSize;
511 unsigned long hashSize2; 619 unsigned long hashSize2;
512 unsigned long long off; 620 unsigned long long off;
@@ -515,16 +623,23 @@ mysql_plugin_get_key (void *cls, uint64_t offset, const struct GNUNET_HashCode *
515 GNUNET_assert (NULL != proc); 623 GNUNET_assert (NULL != proc);
516 hashSize = sizeof (struct GNUNET_HashCode); 624 hashSize = sizeof (struct GNUNET_HashCode);
517 hashSize2 = sizeof (struct GNUNET_HashCode); 625 hashSize2 = sizeof (struct GNUNET_HashCode);
518 memset (cbind, 0, sizeof (cbind)); 626// memset (cbind, 0, sizeof (cbind));
519 total = -1; 627 total = -1;
520 cbind[0].buffer_type = MYSQL_TYPE_LONGLONG; 628/* cbind[0].buffer_type = MYSQL_TYPE_LONGLONG;
521 cbind[0].buffer = &total; 629 cbind[0].buffer = &total;
522 cbind[0].is_unsigned = GNUNET_NO; 630 cbind[0].is_unsigned = GNUNET_NO;
631*/
632
633 struct GNUNET_MY_ResultSpec results_get[] = {
634 GNUNET_MY_result_spec_uint64 (&total),
635 GNUNET_MY_result_spec_end
636 };
637
523 if (type != 0) 638 if (type != 0)
524 { 639 {
525 if (vhash != NULL) 640 if (vhash != NULL)
526 { 641 {
527 ret = 642/* ret =
528 GNUNET_MYSQL_statement_run_prepared_select (plugin->mc, 643 GNUNET_MYSQL_statement_run_prepared_select (plugin->mc,
529 plugin-> 644 plugin->
530 count_entry_by_hash_vhash_and_type, 1, 645 count_entry_by_hash_vhash_and_type, 1,
@@ -532,36 +647,96 @@ mysql_plugin_get_key (void *cls, uint64_t offset, const struct GNUNET_HashCode *
532 &hashSize, MYSQL_TYPE_BLOB, vhash, 647 &hashSize, MYSQL_TYPE_BLOB, vhash,
533 hashSize2, &hashSize2, MYSQL_TYPE_LONG, 648 hashSize2, &hashSize2, MYSQL_TYPE_LONG,
534 &type, GNUNET_YES, -1); 649 &type, GNUNET_YES, -1);
650*/
651 struct GNUNET_MY_QueryParam params_get[] = {
652 GNUNET_MY_query_param_fixed_size (key, hashSize),
653 GNUNET_MY_query_param_fixed_size (vhash, hashSize2),
654 GNUNET_MY_query_param_uint32 (&type),
655 GNUNET_MY_query_param_end
656 };
657
658 ret =
659 GNUNET_MY_exec_prepared (plugin->mc,
660 plugin->count_entry_by_hash_vhash_and_type,
661 params_get);
662 ret =
663 GNUNET_MY_extract_result (plugin->count_entry_by_hash_vhash_and_type,
664 results_get);
665
535 } 666 }
536 else 667 else
537 { 668 {
538 ret = 669/* ret =
539 GNUNET_MYSQL_statement_run_prepared_select (plugin->mc, 670 GNUNET_MYSQL_statement_run_prepared_select (plugin->mc,
540 plugin->count_entry_by_hash_and_type, 671 plugin->count_entry_by_hash_and_type,
541 1, cbind, NULL, NULL, MYSQL_TYPE_BLOB, key, 672 1, cbind, NULL, NULL, MYSQL_TYPE_BLOB, key,
542 hashSize, &hashSize, MYSQL_TYPE_LONG, 673 hashSize, &hashSize, MYSQL_TYPE_LONG,
543 &type, GNUNET_YES, -1); 674 &type, GNUNET_YES, -1);
675 */
676 struct GNUNET_MY_QueryParam params_get[] = {
677 GNUNET_MY_query_param_fixed_size (key, hashSize),
678 GNUNET_MY_query_param_uint32 (&type),
679 GNUNET_MY_query_param_end
680 };
681
682
683 ret =
684 GNUNET_MY_exec_prepared (plugin->mc,
685 plugin->count_entry_by_hash_and_type,
686 params_get);
687 ret =
688 GNUNET_MY_extract_result (plugin->count_entry_by_hash_vhash_and_type,
689 results_get);
544 } 690 }
545 } 691 }
546 else 692 else
547 { 693 {
548 if (vhash != NULL) 694 if (vhash != NULL)
549 { 695 {
550 ret = 696/* ret =
551 GNUNET_MYSQL_statement_run_prepared_select (plugin->mc, 697 GNUNET_MYSQL_statement_run_prepared_select (plugin->mc,
552 plugin->count_entry_by_hash_and_vhash, 698 plugin->count_entry_by_hash_and_vhash,
553 1, cbind, NULL, NULL, MYSQL_TYPE_BLOB, key, 699 1, cbind, NULL, NULL, MYSQL_TYPE_BLOB, key,
554 hashSize, &hashSize, MYSQL_TYPE_BLOB, 700 hashSize, &hashSize, MYSQL_TYPE_BLOB,
555 vhash, hashSize2, &hashSize2, -1); 701 vhash, hashSize2, &hashSize2, -1);
556 702*/
703 struct GNUNET_MY_QueryParam params_get[] = {
704 GNUNET_MY_query_param_fixed_size (key, hashSize),
705 GNUNET_MY_query_param_fixed_size (vhash, hashSize2),
706 GNUNET_MY_query_param_end
707 };
708
709
710 ret =
711 GNUNET_MY_exec_prepared (plugin->mc,
712 plugin->count_entry_by_hash_and_type,
713 params_get);
714 ret =
715 GNUNET_MY_extract_result (plugin->count_entry_by_hash_vhash_and_type,
716 results_get);
557 } 717 }
558 else 718 else
559 { 719 {
560 ret = 720/* ret =
561 GNUNET_MYSQL_statement_run_prepared_select (plugin->mc, plugin->count_entry_by_hash, 1, 721 GNUNET_MYSQL_statement_run_prepared_select (plugin->mc, plugin->count_entry_by_hash, 1,
562 cbind, NULL, NULL, MYSQL_TYPE_BLOB, key, hashSize, 722 cbind, NULL, NULL, MYSQL_TYPE_BLOB, key, hashSize,
563 &hashSize, -1); 723 &hashSize, -1);
724*/
725 struct GNUNET_MY_QueryParam params_get[] = {
726 GNUNET_MY_query_param_fixed_size (key, hashSize),
727 GNUNET_MY_query_param_end
728 };
729
730
731 ret =
732 GNUNET_MY_exec_prepared (plugin->mc,
733 plugin->count_entry_by_hash_and_type,
734 params_get);
735 ret =
736 GNUNET_MY_extract_result (plugin->count_entry_by_hash_vhash_and_type,
737 results_get);
564 } 738 }
739
565 } 740 }
566 if ((ret != GNUNET_OK) || (0 >= total)) 741 if ((ret != GNUNET_OK) || (0 >= total))
567 { 742 {
@@ -701,7 +876,17 @@ repl_proc (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
701 iret = 876 iret =
702 GNUNET_MYSQL_statement_run_prepared (plugin->mc, plugin->dec_repl, NULL, 877 GNUNET_MYSQL_statement_run_prepared (plugin->mc, plugin->dec_repl, NULL,
703 MYSQL_TYPE_LONGLONG, &oid, GNUNET_YES, -1); 878 MYSQL_TYPE_LONGLONG, &oid, GNUNET_YES, -1);
704 if (iret == GNUNET_SYSERR) 879
880/* struct GNUNET_MY_QueryParam params_proc[] = {
881 GNUNET_MY_query_param_uint64 (&oid),
882 GNUNET_MY_query_param_end
883 };
884
885 iret =
886 GNUNET_MY_exec_prepared (plugin->mc,
887 plugin->dec_repl,
888 params_proc);
889*/ if (iret == GNUNET_SYSERR)
705 { 890 {
706 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 891 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
707 "Failed to reduce replication counter\n"); 892 "Failed to reduce replication counter\n");
@@ -730,7 +915,8 @@ mysql_plugin_get_replication (void *cls, PluginDatumProcessor proc,
730 struct Plugin *plugin = cls; 915 struct Plugin *plugin = cls;
731 struct ReplCtx rc; 916 struct ReplCtx rc;
732 unsigned long long rvalue; 917 unsigned long long rvalue;
733 unsigned long repl; 918// unsigned long repl;
919 uint32_t repl;
734 MYSQL_BIND results; 920 MYSQL_BIND results;
735 921
736 rc.plugin = plugin; 922 rc.plugin = plugin;
@@ -741,12 +927,35 @@ mysql_plugin_get_replication (void *cls, PluginDatumProcessor proc,
741 results.buffer = &repl; 927 results.buffer = &repl;
742 results.is_unsigned = GNUNET_YES; 928 results.is_unsigned = GNUNET_YES;
743 929
744 if (1 != 930 struct GNUNET_MY_QueryParam params_get[] = {
931 GNUNET_MY_query_param_end
932 };
933
934 struct GNUNET_MY_ResultSpec results_get[] = {
935 GNUNET_MY_result_spec_uint32 (&repl),
936 GNUNET_MY_result_spec_end
937 };
938
939/* if (1 !=
745 GNUNET_MYSQL_statement_run_prepared_select (plugin->mc, plugin->max_repl, 1, &results, NULL, NULL, -1)) 940 GNUNET_MYSQL_statement_run_prepared_select (plugin->mc, plugin->max_repl, 1, &results, NULL, NULL, -1))
746 { 941 {
747 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 942 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
748 return; 943 return;
749 } 944 }
945*/
946 if (1 !=
947 GNUNET_MY_exec_prepared (plugin->mc, plugin->max_repl, params_get))
948 {
949 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
950 return;
951 }
952
953 if (1 !=
954 GNUNET_MY_extract_result (plugin->max_repl, results_get))
955 {
956 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
957 return;
958 }
750 959
751 rvalue = 960 rvalue =
752 (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 961 (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
@@ -772,22 +981,31 @@ mysql_plugin_get_keys (void *cls,
772 void *proc_cls) 981 void *proc_cls)
773{ 982{
774 struct Plugin *plugin = cls; 983 struct Plugin *plugin = cls;
775 const char *query = "SELECT hash FROM gn090"; 984// const char *query = "SELECT hash FROM gn090";
985 char *query = "SELECT hash FROM gn090";
776 int ret; 986 int ret;
777 MYSQL_STMT *statement; 987 MYSQL_STMT *statement;
988 struct GNUNET_MYSQL_StatementHandle *statements_handle_select = NULL;
989
990
778 struct GNUNET_HashCode key; 991 struct GNUNET_HashCode key;
779 MYSQL_BIND cbind[1]; 992// MYSQL_BIND cbind[1];
780 unsigned long length; 993 unsigned long length;
781 994
782 statement = GNUNET_MYSQL_statement_get_stmt (plugin->mc, 995 statement = GNUNET_MYSQL_statement_get_stmt (plugin->mc,
783 plugin->get_all_keys); 996 plugin->get_all_keys);
997
998 statements_handle_select = GNUNET_MYSQL_statement_prepare (plugin->mc,
999 query);
1000
784 if (statement == NULL) 1001 if (statement == NULL)
785 { 1002 {
786 GNUNET_MYSQL_statements_invalidate (plugin->mc); 1003 GNUNET_MYSQL_statements_invalidate (plugin->mc);
787 proc (proc_cls, NULL, 0); 1004 proc (proc_cls, NULL, 0);
788 return; 1005 return;
789 } 1006 }
790 if (mysql_stmt_prepare (statement, query, strlen (query))) 1007
1008/* if (mysql_stmt_prepare (statement, query, strlen (query)))
791 { 1009 {
792 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", 1010 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
793 _("Failed to prepare statement `%s'\n"), query); 1011 _("Failed to prepare statement `%s'\n"), query);
@@ -795,8 +1013,34 @@ mysql_plugin_get_keys (void *cls,
795 proc (proc_cls, NULL, 0); 1013 proc (proc_cls, NULL, 0);
796 return; 1014 return;
797 } 1015 }
1016*/
798 GNUNET_assert (proc != NULL); 1017 GNUNET_assert (proc != NULL);
799 if (mysql_stmt_execute (statement)) 1018
1019 struct GNUNET_MY_QueryParam params_select[] = {
1020 GNUNET_MY_query_param_end
1021 };
1022
1023 struct GNUNET_MY_ResultSpec results_select[] = {
1024 GNUNET_MY_result_spec_auto_from_type (&key),
1025 GNUNET_MY_result_spec_end
1026 };
1027
1028 if (GNUNET_OK != GNUNET_MY_exec_prepared (plugin->mc,
1029 statements_handle_select,
1030 params_select))
1031 {
1032 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1033 _("`%s' for `%s' failed at %s:%d with error: %s\n"),
1034 "mysql_stmt_execute", query, __FILE__, __LINE__,
1035 mysql_stmt_error (statement));
1036 GNUNET_MYSQL_statements_invalidate (plugin->mc);
1037 proc (proc_cls, NULL, 0);
1038 return;
1039 }
1040
1041 ret = GNUNET_MY_extract_result (statements_handle_select,
1042 results_select);
1043/* if (mysql_stmt_execute (statement))
800 { 1044 {
801 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1045 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
802 _("`%s' for `%s' failed at %s:%d with error: %s\n"), 1046 _("`%s' for `%s' failed at %s:%d with error: %s\n"),
@@ -828,6 +1072,7 @@ mysql_plugin_get_keys (void *cls,
828 proc (proc_cls, &key, 1); 1072 proc (proc_cls, &key, 1);
829 } 1073 }
830 proc (proc_cls, NULL, 0); 1074 proc (proc_cls, NULL, 0);
1075*/
831 if (ret != MYSQL_NO_DATA) 1076 if (ret != MYSQL_NO_DATA)
832 { 1077 {
833 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1078 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -837,6 +1082,7 @@ mysql_plugin_get_keys (void *cls,
837 GNUNET_MYSQL_statements_invalidate (plugin->mc); 1082 GNUNET_MYSQL_statements_invalidate (plugin->mc);
838 return; 1083 return;
839 } 1084 }
1085
840 mysql_stmt_reset (statement); 1086 mysql_stmt_reset (statement);
841} 1087}
842 1088