diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:54:06 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:54:06 +0000 |
commit | 5746309cb4be2073d550ad7a6885e918631dbc38 (patch) | |
tree | 89455bc4aadf977816b38df13f990372cd81d71a /src/datastore | |
parent | 6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff) | |
download | gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip |
indentation
Diffstat (limited to 'src/datastore')
-rw-r--r-- | src/datastore/datastore_api.c | 191 | ||||
-rw-r--r-- | src/datastore/gnunet-service-datastore.c | 299 | ||||
-rw-r--r-- | src/datastore/perf_datastore_api.c | 83 | ||||
-rw-r--r-- | src/datastore/perf_plugin_datastore.c | 89 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_mysql.c | 315 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_postgres.c | 376 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_sqlite.c | 429 | ||||
-rw-r--r-- | src/datastore/plugin_datastore_template.c | 36 | ||||
-rw-r--r-- | src/datastore/test_datastore_api.c | 280 | ||||
-rw-r--r-- | src/datastore/test_datastore_api_management.c | 125 | ||||
-rw-r--r-- | src/datastore/test_plugin_datastore.c | 63 |
11 files changed, 946 insertions, 1340 deletions
diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c index 85e402a4d..ff49c106e 100644 --- a/src/datastore/datastore_api.c +++ b/src/datastore/datastore_api.c | |||
@@ -367,8 +367,8 @@ timeout_queue_entry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
367 | struct GNUNET_DATASTORE_QueueEntry *qe = cls; | 367 | struct GNUNET_DATASTORE_QueueEntry *qe = cls; |
368 | 368 | ||
369 | GNUNET_STATISTICS_update (qe->h->stats, | 369 | GNUNET_STATISTICS_update (qe->h->stats, |
370 | gettext_noop ("# queue entry timeouts"), | 370 | gettext_noop ("# queue entry timeouts"), 1, |
371 | 1, GNUNET_NO); | 371 | GNUNET_NO); |
372 | qe->task = GNUNET_SCHEDULER_NO_TASK; | 372 | qe->task = GNUNET_SCHEDULER_NO_TASK; |
373 | GNUNET_assert (qe->was_transmitted == GNUNET_NO); | 373 | GNUNET_assert (qe->was_transmitted == GNUNET_NO); |
374 | #if DEBUG_DATASTORE | 374 | #if DEBUG_DATASTORE |
@@ -394,10 +394,8 @@ timeout_queue_entry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
394 | * @return NULL if the queue is full | 394 | * @return NULL if the queue is full |
395 | */ | 395 | */ |
396 | static struct GNUNET_DATASTORE_QueueEntry * | 396 | static struct GNUNET_DATASTORE_QueueEntry * |
397 | make_queue_entry (struct GNUNET_DATASTORE_Handle *h, | 397 | make_queue_entry (struct GNUNET_DATASTORE_Handle *h, size_t msize, |
398 | size_t msize, | 398 | unsigned int queue_priority, unsigned int max_queue_size, |
399 | unsigned int queue_priority, | ||
400 | unsigned int max_queue_size, | ||
401 | struct GNUNET_TIME_Relative timeout, | 399 | struct GNUNET_TIME_Relative timeout, |
402 | GNUNET_CLIENT_MessageHandler response_proc, | 400 | GNUNET_CLIENT_MessageHandler response_proc, |
403 | const union QueueContext *qc) | 401 | const union QueueContext *qc) |
@@ -408,16 +406,16 @@ make_queue_entry (struct GNUNET_DATASTORE_Handle *h, | |||
408 | 406 | ||
409 | c = 0; | 407 | c = 0; |
410 | pos = h->queue_head; | 408 | pos = h->queue_head; |
411 | while ((pos != NULL) && | 409 | while ((pos != NULL) && (c < max_queue_size) && |
412 | (c < max_queue_size) && (pos->priority >= queue_priority)) | 410 | (pos->priority >= queue_priority)) |
413 | { | 411 | { |
414 | c++; | 412 | c++; |
415 | pos = pos->next; | 413 | pos = pos->next; |
416 | } | 414 | } |
417 | if (c >= max_queue_size) | 415 | if (c >= max_queue_size) |
418 | { | 416 | { |
419 | GNUNET_STATISTICS_update (h->stats, | 417 | GNUNET_STATISTICS_update (h->stats, gettext_noop ("# queue overflows"), 1, |
420 | gettext_noop ("# queue overflows"), 1, GNUNET_NO); | 418 | GNUNET_NO); |
421 | return NULL; | 419 | return NULL; |
422 | } | 420 | } |
423 | ret = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_QueueEntry) + msize); | 421 | ret = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_QueueEntry) + msize); |
@@ -443,8 +441,7 @@ make_queue_entry (struct GNUNET_DATASTORE_Handle *h, | |||
443 | pos = h->queue_head; | 441 | pos = h->queue_head; |
444 | } | 442 | } |
445 | c++; | 443 | c++; |
446 | GNUNET_STATISTICS_update (h->stats, | 444 | GNUNET_STATISTICS_update (h->stats, gettext_noop ("# queue entries created"), |
447 | gettext_noop ("# queue entries created"), | ||
448 | 1, GNUNET_NO); | 445 | 1, GNUNET_NO); |
449 | GNUNET_CONTAINER_DLL_insert_after (h->queue_head, h->queue_tail, pos, ret); | 446 | GNUNET_CONTAINER_DLL_insert_after (h->queue_head, h->queue_tail, pos, ret); |
450 | h->queue_size++; | 447 | h->queue_size++; |
@@ -540,15 +537,14 @@ do_disconnect (struct GNUNET_DATASTORE_Handle *h) | |||
540 | return; | 537 | return; |
541 | } | 538 | } |
542 | #if 0 | 539 | #if 0 |
543 | GNUNET_STATISTICS_update (stats, | 540 | GNUNET_STATISTICS_update (stats, gettext_noop ("# reconnected to DATASTORE"), |
544 | gettext_noop ("# reconnected to DATASTORE"), | ||
545 | 1, GNUNET_NO); | 541 | 1, GNUNET_NO); |
546 | #endif | 542 | #endif |
547 | GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); | 543 | GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); |
548 | h->skip_next_messages = 0; | 544 | h->skip_next_messages = 0; |
549 | h->client = NULL; | 545 | h->client = NULL; |
550 | h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_time, | 546 | h->reconnect_task = |
551 | &try_reconnect, h); | 547 | GNUNET_SCHEDULER_add_delayed (h->retry_time, &try_reconnect, h); |
552 | } | 548 | } |
553 | 549 | ||
554 | 550 | ||
@@ -628,12 +624,11 @@ transmit_request (void *cls, size_t size, void *buf) | |||
628 | qe->task = GNUNET_SCHEDULER_NO_TASK; | 624 | qe->task = GNUNET_SCHEDULER_NO_TASK; |
629 | GNUNET_assert (GNUNET_NO == h->in_receive); | 625 | GNUNET_assert (GNUNET_NO == h->in_receive); |
630 | h->in_receive = GNUNET_YES; | 626 | h->in_receive = GNUNET_YES; |
631 | GNUNET_CLIENT_receive (h->client, | 627 | GNUNET_CLIENT_receive (h->client, &receive_cb, h, |
632 | &receive_cb, | 628 | GNUNET_TIME_absolute_get_remaining (qe->timeout)); |
633 | h, GNUNET_TIME_absolute_get_remaining (qe->timeout)); | ||
634 | GNUNET_STATISTICS_update (h->stats, | 629 | GNUNET_STATISTICS_update (h->stats, |
635 | gettext_noop ("# bytes sent to datastore"), | 630 | gettext_noop ("# bytes sent to datastore"), 1, |
636 | 1, GNUNET_NO); | 631 | GNUNET_NO); |
637 | return msize; | 632 | return msize; |
638 | } | 633 | } |
639 | 634 | ||
@@ -686,11 +681,11 @@ process_queue (struct GNUNET_DATASTORE_Handle *h) | |||
686 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 681 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
687 | "Queueing %u byte request to DATASTORE\n", qe->message_size); | 682 | "Queueing %u byte request to DATASTORE\n", qe->message_size); |
688 | #endif | 683 | #endif |
689 | h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, | 684 | h->th = |
690 | qe->message_size, | 685 | GNUNET_CLIENT_notify_transmit_ready (h->client, qe->message_size, |
691 | GNUNET_TIME_absolute_get_remaining | 686 | GNUNET_TIME_absolute_get_remaining |
692 | (qe->timeout), GNUNET_YES, | 687 | (qe->timeout), GNUNET_YES, |
693 | &transmit_request, h); | 688 | &transmit_request, h); |
694 | GNUNET_assert (GNUNET_NO == h->in_receive); | 689 | GNUNET_assert (GNUNET_NO == h->in_receive); |
695 | GNUNET_break (NULL != h->th); | 690 | GNUNET_break (NULL != h->th); |
696 | } | 691 | } |
@@ -768,8 +763,7 @@ process_status_message (void *cls, const struct GNUNET_MessageHeader *msg) | |||
768 | else | 763 | else |
769 | process_queue (h); | 764 | process_queue (h); |
770 | if (rc.cont != NULL) | 765 | if (rc.cont != NULL) |
771 | rc.cont (rc.cont_cls, | 766 | rc.cont (rc.cont_cls, GNUNET_SYSERR, |
772 | GNUNET_SYSERR, | ||
773 | _("Failed to receive status response from database.")); | 767 | _("Failed to receive status response from database.")); |
774 | return; | 768 | return; |
775 | } | 769 | } |
@@ -782,8 +776,7 @@ process_status_message (void *cls, const struct GNUNET_MessageHeader *msg) | |||
782 | h->retry_time = GNUNET_TIME_UNIT_ZERO; | 776 | h->retry_time = GNUNET_TIME_UNIT_ZERO; |
783 | do_disconnect (h); | 777 | do_disconnect (h); |
784 | if (rc.cont != NULL) | 778 | if (rc.cont != NULL) |
785 | rc.cont (rc.cont_cls, | 779 | rc.cont (rc.cont_cls, GNUNET_SYSERR, |
786 | GNUNET_SYSERR, | ||
787 | _("Error reading response from datastore service")); | 780 | _("Error reading response from datastore service")); |
788 | return; | 781 | return; |
789 | } | 782 | } |
@@ -805,12 +798,12 @@ process_status_message (void *cls, const struct GNUNET_MessageHeader *msg) | |||
805 | emsg = _("Invalid error message received from datastore service"); | 798 | emsg = _("Invalid error message received from datastore service"); |
806 | } | 799 | } |
807 | #if DEBUG_DATASTORE | 800 | #if DEBUG_DATASTORE |
808 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 801 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received status %d/%s\n", (int) status, |
809 | "Received status %d/%s\n", (int) status, emsg); | 802 | emsg); |
810 | #endif | 803 | #endif |
811 | GNUNET_STATISTICS_update (h->stats, | 804 | GNUNET_STATISTICS_update (h->stats, |
812 | gettext_noop ("# status messages received"), | 805 | gettext_noop ("# status messages received"), 1, |
813 | 1, GNUNET_NO); | 806 | GNUNET_NO); |
814 | h->retry_time.rel_value = 0; | 807 | h->retry_time.rel_value = 0; |
815 | process_queue (h); | 808 | process_queue (h); |
816 | if (rc.cont != NULL) | 809 | if (rc.cont != NULL) |
@@ -845,18 +838,13 @@ process_status_message (void *cls, const struct GNUNET_MessageHeader *msg) | |||
845 | * (or rather, will already have been invoked) | 838 | * (or rather, will already have been invoked) |
846 | */ | 839 | */ |
847 | struct GNUNET_DATASTORE_QueueEntry * | 840 | struct GNUNET_DATASTORE_QueueEntry * |
848 | GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h, | 841 | GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h, uint32_t rid, |
849 | uint32_t rid, | 842 | const GNUNET_HashCode * key, size_t size, |
850 | const GNUNET_HashCode * key, | 843 | const void *data, enum GNUNET_BLOCK_Type type, |
851 | size_t size, | 844 | uint32_t priority, uint32_t anonymity, |
852 | const void *data, | ||
853 | enum GNUNET_BLOCK_Type type, | ||
854 | uint32_t priority, | ||
855 | uint32_t anonymity, | ||
856 | uint32_t replication, | 845 | uint32_t replication, |
857 | struct GNUNET_TIME_Absolute expiration, | 846 | struct GNUNET_TIME_Absolute expiration, |
858 | unsigned int queue_priority, | 847 | unsigned int queue_priority, unsigned int max_queue_size, |
859 | unsigned int max_queue_size, | ||
860 | struct GNUNET_TIME_Relative timeout, | 848 | struct GNUNET_TIME_Relative timeout, |
861 | GNUNET_DATASTORE_ContinuationWithStatus cont, | 849 | GNUNET_DATASTORE_ContinuationWithStatus cont, |
862 | void *cont_cls) | 850 | void *cont_cls) |
@@ -869,16 +857,14 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h, | |||
869 | #if DEBUG_DATASTORE | 857 | #if DEBUG_DATASTORE |
870 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 858 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
871 | "Asked to put %u bytes of data under key `%s' for %llu ms\n", | 859 | "Asked to put %u bytes of data under key `%s' for %llu ms\n", |
872 | size, | 860 | size, GNUNET_h2s (key), |
873 | GNUNET_h2s (key), | ||
874 | GNUNET_TIME_absolute_get_remaining (expiration).rel_value); | 861 | GNUNET_TIME_absolute_get_remaining (expiration).rel_value); |
875 | #endif | 862 | #endif |
876 | msize = sizeof (struct DataMessage) + size; | 863 | msize = sizeof (struct DataMessage) + size; |
877 | GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); | 864 | GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); |
878 | qc.sc.cont = cont; | 865 | qc.sc.cont = cont; |
879 | qc.sc.cont_cls = cont_cls; | 866 | qc.sc.cont_cls = cont_cls; |
880 | qe = make_queue_entry (h, msize, | 867 | qe = make_queue_entry (h, msize, queue_priority, max_queue_size, timeout, |
881 | queue_priority, max_queue_size, timeout, | ||
882 | &process_status_message, &qc); | 868 | &process_status_message, &qc); |
883 | if (qe == NULL) | 869 | if (qe == NULL) |
884 | { | 870 | { |
@@ -888,8 +874,7 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h, | |||
888 | #endif | 874 | #endif |
889 | return NULL; | 875 | return NULL; |
890 | } | 876 | } |
891 | GNUNET_STATISTICS_update (h->stats, | 877 | GNUNET_STATISTICS_update (h->stats, gettext_noop ("# PUT requests executed"), |
892 | gettext_noop ("# PUT requests executed"), | ||
893 | 1, GNUNET_NO); | 878 | 1, GNUNET_NO); |
894 | dm = (struct DataMessage *) &qe[1]; | 879 | dm = (struct DataMessage *) &qe[1]; |
895 | dm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_PUT); | 880 | dm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_PUT); |
@@ -930,10 +915,8 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h, | |||
930 | * (or rather, will already have been invoked) | 915 | * (or rather, will already have been invoked) |
931 | */ | 916 | */ |
932 | struct GNUNET_DATASTORE_QueueEntry * | 917 | struct GNUNET_DATASTORE_QueueEntry * |
933 | GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h, | 918 | GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h, uint64_t amount, |
934 | uint64_t amount, | 919 | uint32_t entries, unsigned int queue_priority, |
935 | uint32_t entries, | ||
936 | unsigned int queue_priority, | ||
937 | unsigned int max_queue_size, | 920 | unsigned int max_queue_size, |
938 | struct GNUNET_TIME_Relative timeout, | 921 | struct GNUNET_TIME_Relative timeout, |
939 | GNUNET_DATASTORE_ContinuationWithStatus cont, | 922 | GNUNET_DATASTORE_ContinuationWithStatus cont, |
@@ -952,9 +935,8 @@ GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h, | |||
952 | #endif | 935 | #endif |
953 | qc.sc.cont = cont; | 936 | qc.sc.cont = cont; |
954 | qc.sc.cont_cls = cont_cls; | 937 | qc.sc.cont_cls = cont_cls; |
955 | qe = make_queue_entry (h, sizeof (struct ReserveMessage), | 938 | qe = make_queue_entry (h, sizeof (struct ReserveMessage), queue_priority, |
956 | queue_priority, max_queue_size, timeout, | 939 | max_queue_size, timeout, &process_status_message, &qc); |
957 | &process_status_message, &qc); | ||
958 | if (qe == NULL) | 940 | if (qe == NULL) |
959 | { | 941 | { |
960 | #if DEBUG_DATASTORE | 942 | #if DEBUG_DATASTORE |
@@ -964,8 +946,8 @@ GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h, | |||
964 | return NULL; | 946 | return NULL; |
965 | } | 947 | } |
966 | GNUNET_STATISTICS_update (h->stats, | 948 | GNUNET_STATISTICS_update (h->stats, |
967 | gettext_noop ("# RESERVE requests executed"), | 949 | gettext_noop ("# RESERVE requests executed"), 1, |
968 | 1, GNUNET_NO); | 950 | GNUNET_NO); |
969 | rm = (struct ReserveMessage *) &qe[1]; | 951 | rm = (struct ReserveMessage *) &qe[1]; |
970 | rm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE); | 952 | rm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE); |
971 | rm->header.size = htons (sizeof (struct ReserveMessage)); | 953 | rm->header.size = htons (sizeof (struct ReserveMessage)); |
@@ -999,8 +981,7 @@ GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h, | |||
999 | */ | 981 | */ |
1000 | struct GNUNET_DATASTORE_QueueEntry * | 982 | struct GNUNET_DATASTORE_QueueEntry * |
1001 | GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h, | 983 | GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h, |
1002 | uint32_t rid, | 984 | uint32_t rid, unsigned int queue_priority, |
1003 | unsigned int queue_priority, | ||
1004 | unsigned int max_queue_size, | 985 | unsigned int max_queue_size, |
1005 | struct GNUNET_TIME_Relative timeout, | 986 | struct GNUNET_TIME_Relative timeout, |
1006 | GNUNET_DATASTORE_ContinuationWithStatus cont, | 987 | GNUNET_DATASTORE_ContinuationWithStatus cont, |
@@ -1059,8 +1040,7 @@ GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h, | |||
1059 | * (or rather, will already have been invoked) | 1040 | * (or rather, will already have been invoked) |
1060 | */ | 1041 | */ |
1061 | struct GNUNET_DATASTORE_QueueEntry * | 1042 | struct GNUNET_DATASTORE_QueueEntry * |
1062 | GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h, | 1043 | GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h, uint64_t uid, |
1063 | uint64_t uid, | ||
1064 | uint32_t priority, | 1044 | uint32_t priority, |
1065 | struct GNUNET_TIME_Absolute expiration, | 1045 | struct GNUNET_TIME_Absolute expiration, |
1066 | unsigned int queue_priority, | 1046 | unsigned int queue_priority, |
@@ -1078,15 +1058,13 @@ GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h, | |||
1078 | #if DEBUG_DATASTORE | 1058 | #if DEBUG_DATASTORE |
1079 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1059 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1080 | "Asked to update entry %llu raising priority by %u and expiration to %llu\n", | 1060 | "Asked to update entry %llu raising priority by %u and expiration to %llu\n", |
1081 | uid, | 1061 | uid, (unsigned int) priority, |
1082 | (unsigned int) priority, | ||
1083 | (unsigned long long) expiration.abs_value); | 1062 | (unsigned long long) expiration.abs_value); |
1084 | #endif | 1063 | #endif |
1085 | qc.sc.cont = cont; | 1064 | qc.sc.cont = cont; |
1086 | qc.sc.cont_cls = cont_cls; | 1065 | qc.sc.cont_cls = cont_cls; |
1087 | qe = make_queue_entry (h, sizeof (struct UpdateMessage), | 1066 | qe = make_queue_entry (h, sizeof (struct UpdateMessage), queue_priority, |
1088 | queue_priority, max_queue_size, timeout, | 1067 | max_queue_size, timeout, &process_status_message, &qc); |
1089 | &process_status_message, &qc); | ||
1090 | if (qe == NULL) | 1068 | if (qe == NULL) |
1091 | { | 1069 | { |
1092 | #if DEBUG_DATASTORE | 1070 | #if DEBUG_DATASTORE |
@@ -1096,8 +1074,8 @@ GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h, | |||
1096 | return NULL; | 1074 | return NULL; |
1097 | } | 1075 | } |
1098 | GNUNET_STATISTICS_update (h->stats, | 1076 | GNUNET_STATISTICS_update (h->stats, |
1099 | gettext_noop ("# UPDATE requests executed"), | 1077 | gettext_noop ("# UPDATE requests executed"), 1, |
1100 | 1, GNUNET_NO); | 1078 | GNUNET_NO); |
1101 | um = (struct UpdateMessage *) &qe[1]; | 1079 | um = (struct UpdateMessage *) &qe[1]; |
1102 | um->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_UPDATE); | 1080 | um->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_UPDATE); |
1103 | um->header.size = htons (sizeof (struct UpdateMessage)); | 1081 | um->header.size = htons (sizeof (struct UpdateMessage)); |
@@ -1132,10 +1110,8 @@ GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h, | |||
1132 | */ | 1110 | */ |
1133 | struct GNUNET_DATASTORE_QueueEntry * | 1111 | struct GNUNET_DATASTORE_QueueEntry * |
1134 | GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h, | 1112 | GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h, |
1135 | const GNUNET_HashCode * key, | 1113 | const GNUNET_HashCode * key, size_t size, |
1136 | size_t size, | 1114 | const void *data, unsigned int queue_priority, |
1137 | const void *data, | ||
1138 | unsigned int queue_priority, | ||
1139 | unsigned int max_queue_size, | 1115 | unsigned int max_queue_size, |
1140 | struct GNUNET_TIME_Relative timeout, | 1116 | struct GNUNET_TIME_Relative timeout, |
1141 | GNUNET_DATASTORE_ContinuationWithStatus cont, | 1117 | GNUNET_DATASTORE_ContinuationWithStatus cont, |
@@ -1150,15 +1126,14 @@ GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h, | |||
1150 | cont = &drop_status_cont; | 1126 | cont = &drop_status_cont; |
1151 | #if DEBUG_DATASTORE | 1127 | #if DEBUG_DATASTORE |
1152 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1128 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1153 | "Asked to remove %u bytes under key `%s'\n", | 1129 | "Asked to remove %u bytes under key `%s'\n", size, |
1154 | size, GNUNET_h2s (key)); | 1130 | GNUNET_h2s (key)); |
1155 | #endif | 1131 | #endif |
1156 | qc.sc.cont = cont; | 1132 | qc.sc.cont = cont; |
1157 | qc.sc.cont_cls = cont_cls; | 1133 | qc.sc.cont_cls = cont_cls; |
1158 | msize = sizeof (struct DataMessage) + size; | 1134 | msize = sizeof (struct DataMessage) + size; |
1159 | GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); | 1135 | GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); |
1160 | qe = make_queue_entry (h, msize, | 1136 | qe = make_queue_entry (h, msize, queue_priority, max_queue_size, timeout, |
1161 | queue_priority, max_queue_size, timeout, | ||
1162 | &process_status_message, &qc); | 1137 | &process_status_message, &qc); |
1163 | if (qe == NULL) | 1138 | if (qe == NULL) |
1164 | { | 1139 | { |
@@ -1169,8 +1144,8 @@ GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h, | |||
1169 | return NULL; | 1144 | return NULL; |
1170 | } | 1145 | } |
1171 | GNUNET_STATISTICS_update (h->stats, | 1146 | GNUNET_STATISTICS_update (h->stats, |
1172 | gettext_noop ("# REMOVE requests executed"), | 1147 | gettext_noop ("# REMOVE requests executed"), 1, |
1173 | 1, GNUNET_NO); | 1148 | GNUNET_NO); |
1174 | dm = (struct DataMessage *) &qe[1]; | 1149 | dm = (struct DataMessage *) &qe[1]; |
1175 | dm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE); | 1150 | dm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE); |
1176 | dm->header.size = htons (msize); | 1151 | dm->header.size = htons (msize); |
@@ -1222,8 +1197,8 @@ process_result_message (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1222 | process_queue (h); | 1197 | process_queue (h); |
1223 | } | 1198 | } |
1224 | if (rc.proc != NULL) | 1199 | if (rc.proc != NULL) |
1225 | rc.proc (rc.proc_cls, | 1200 | rc.proc (rc.proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, |
1226 | NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 1201 | 0); |
1227 | return; | 1202 | return; |
1228 | } | 1203 | } |
1229 | if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END) | 1204 | if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END) |
@@ -1239,8 +1214,8 @@ process_result_message (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1239 | h->queue_size); | 1214 | h->queue_size); |
1240 | #endif | 1215 | #endif |
1241 | if (rc.proc != NULL) | 1216 | if (rc.proc != NULL) |
1242 | rc.proc (rc.proc_cls, | 1217 | rc.proc (rc.proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, |
1243 | NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 1218 | 0); |
1244 | h->retry_time.rel_value = 0; | 1219 | h->retry_time.rel_value = 0; |
1245 | h->result_count = 0; | 1220 | h->result_count = 0; |
1246 | process_queue (h); | 1221 | process_queue (h); |
@@ -1256,8 +1231,8 @@ process_result_message (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1256 | h->retry_time = GNUNET_TIME_UNIT_ZERO; | 1231 | h->retry_time = GNUNET_TIME_UNIT_ZERO; |
1257 | do_disconnect (h); | 1232 | do_disconnect (h); |
1258 | if (rc.proc != NULL) | 1233 | if (rc.proc != NULL) |
1259 | rc.proc (rc.proc_cls, | 1234 | rc.proc (rc.proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, |
1260 | NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 1235 | 0); |
1261 | return; | 1236 | return; |
1262 | } | 1237 | } |
1263 | if ((ntohs (msg->size) < sizeof (struct DataMessage)) || | 1238 | if ((ntohs (msg->size) < sizeof (struct DataMessage)) || |
@@ -1271,30 +1246,25 @@ process_result_message (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1271 | h->retry_time = GNUNET_TIME_UNIT_ZERO; | 1246 | h->retry_time = GNUNET_TIME_UNIT_ZERO; |
1272 | do_disconnect (h); | 1247 | do_disconnect (h); |
1273 | if (rc.proc != NULL) | 1248 | if (rc.proc != NULL) |
1274 | rc.proc (rc.proc_cls, | 1249 | rc.proc (rc.proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, |
1275 | NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 1250 | 0); |
1276 | return; | 1251 | return; |
1277 | } | 1252 | } |
1278 | GNUNET_STATISTICS_update (h->stats, | 1253 | GNUNET_STATISTICS_update (h->stats, gettext_noop ("# Results received"), 1, |
1279 | gettext_noop ("# Results received"), 1, GNUNET_NO); | 1254 | GNUNET_NO); |
1280 | dm = (const struct DataMessage *) msg; | 1255 | dm = (const struct DataMessage *) msg; |
1281 | #if DEBUG_DATASTORE | 1256 | #if DEBUG_DATASTORE |
1282 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1257 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1283 | "Received result %llu with type %u and size %u with key %s\n", | 1258 | "Received result %llu with type %u and size %u with key %s\n", |
1284 | (unsigned long long) GNUNET_ntohll (dm->uid), | 1259 | (unsigned long long) GNUNET_ntohll (dm->uid), ntohl (dm->type), |
1285 | ntohl (dm->type), ntohl (dm->size), GNUNET_h2s (&dm->key)); | 1260 | ntohl (dm->size), GNUNET_h2s (&dm->key)); |
1286 | #endif | 1261 | #endif |
1287 | free_queue_entry (qe); | 1262 | free_queue_entry (qe); |
1288 | h->retry_time.rel_value = 0; | 1263 | h->retry_time.rel_value = 0; |
1289 | process_queue (h); | 1264 | process_queue (h); |
1290 | if (rc.proc != NULL) | 1265 | if (rc.proc != NULL) |
1291 | rc.proc (rc.proc_cls, | 1266 | rc.proc (rc.proc_cls, &dm->key, ntohl (dm->size), &dm[1], ntohl (dm->type), |
1292 | &dm->key, | 1267 | ntohl (dm->priority), ntohl (dm->anonymity), |
1293 | ntohl (dm->size), | ||
1294 | &dm[1], | ||
1295 | ntohl (dm->type), | ||
1296 | ntohl (dm->priority), | ||
1297 | ntohl (dm->anonymity), | ||
1298 | GNUNET_TIME_absolute_ntoh (dm->expiration), | 1268 | GNUNET_TIME_absolute_ntoh (dm->expiration), |
1299 | GNUNET_ntohll (dm->uid)); | 1269 | GNUNET_ntohll (dm->uid)); |
1300 | } | 1270 | } |
@@ -1401,8 +1371,8 @@ GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h, | |||
1401 | #if DEBUG_DATASTORE | 1371 | #if DEBUG_DATASTORE |
1402 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1372 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1403 | "Asked to get %llu-th zero-anonymity entry of type %d in %llu ms\n", | 1373 | "Asked to get %llu-th zero-anonymity entry of type %d in %llu ms\n", |
1404 | (unsigned long long) offset, | 1374 | (unsigned long long) offset, type, |
1405 | type, (unsigned long long) timeout.rel_value); | 1375 | (unsigned long long) timeout.rel_value); |
1406 | #endif | 1376 | #endif |
1407 | qc.rc.proc = proc; | 1377 | qc.rc.proc = proc; |
1408 | qc.rc.proc_cls = proc_cls; | 1378 | qc.rc.proc_cls = proc_cls; |
@@ -1453,8 +1423,7 @@ GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h, | |||
1453 | * cancel | 1423 | * cancel |
1454 | */ | 1424 | */ |
1455 | struct GNUNET_DATASTORE_QueueEntry * | 1425 | struct GNUNET_DATASTORE_QueueEntry * |
1456 | GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h, | 1426 | GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h, uint64_t offset, |
1457 | uint64_t offset, | ||
1458 | const GNUNET_HashCode * key, | 1427 | const GNUNET_HashCode * key, |
1459 | enum GNUNET_BLOCK_Type type, | 1428 | enum GNUNET_BLOCK_Type type, |
1460 | unsigned int queue_priority, | 1429 | unsigned int queue_priority, |
@@ -1474,19 +1443,17 @@ GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h, | |||
1474 | #endif | 1443 | #endif |
1475 | qc.rc.proc = proc; | 1444 | qc.rc.proc = proc; |
1476 | qc.rc.proc_cls = proc_cls; | 1445 | qc.rc.proc_cls = proc_cls; |
1477 | qe = make_queue_entry (h, sizeof (struct GetMessage), | 1446 | qe = make_queue_entry (h, sizeof (struct GetMessage), queue_priority, |
1478 | queue_priority, max_queue_size, timeout, | 1447 | max_queue_size, timeout, &process_result_message, &qc); |
1479 | &process_result_message, &qc); | ||
1480 | if (qe == NULL) | 1448 | if (qe == NULL) |
1481 | { | 1449 | { |
1482 | #if DEBUG_DATASTORE | 1450 | #if DEBUG_DATASTORE |
1483 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1451 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could not queue request for `%s'\n", |
1484 | "Could not queue request for `%s'\n", GNUNET_h2s (key)); | 1452 | GNUNET_h2s (key)); |
1485 | #endif | 1453 | #endif |
1486 | return NULL; | 1454 | return NULL; |
1487 | } | 1455 | } |
1488 | GNUNET_STATISTICS_update (h->stats, | 1456 | GNUNET_STATISTICS_update (h->stats, gettext_noop ("# GET requests executed"), |
1489 | gettext_noop ("# GET requests executed"), | ||
1490 | 1, GNUNET_NO); | 1457 | 1, GNUNET_NO); |
1491 | gm = (struct GetMessage *) &qe[1]; | 1458 | gm = (struct GetMessage *) &qe[1]; |
1492 | gm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_GET); | 1459 | gm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_GET); |
@@ -1522,8 +1489,8 @@ GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe) | |||
1522 | h = qe->h; | 1489 | h = qe->h; |
1523 | #if DEBUG_DATASTORE | 1490 | #if DEBUG_DATASTORE |
1524 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1491 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1525 | "Pending DATASTORE request %p cancelled (%d, %d)\n", | 1492 | "Pending DATASTORE request %p cancelled (%d, %d)\n", qe, |
1526 | qe, qe->was_transmitted, h->queue_head == qe); | 1493 | qe->was_transmitted, h->queue_head == qe); |
1527 | #endif | 1494 | #endif |
1528 | if (GNUNET_YES == qe->was_transmitted) | 1495 | if (GNUNET_YES == qe->was_transmitted) |
1529 | { | 1496 | { |
diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c index c01de5891..8efb706c1 100644 --- a/src/datastore/gnunet-service-datastore.c +++ b/src/datastore/gnunet-service-datastore.c | |||
@@ -276,8 +276,8 @@ static struct GNUNET_STATISTICS_GetHandle *stat_get; | |||
276 | * @param cls not used | 276 | * @param cls not used |
277 | * @param tc task context | 277 | * @param tc task context |
278 | */ | 278 | */ |
279 | static void | 279 | static void delete_expired (void *cls, |
280 | delete_expired (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 280 | const struct GNUNET_SCHEDULER_TaskContext *tc); |
281 | 281 | ||
282 | 282 | ||
283 | /** | 283 | /** |
@@ -301,45 +301,38 @@ delete_expired (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | |||
301 | * GNUNET_NO to delete the item and continue (if supported) | 301 | * GNUNET_NO to delete the item and continue (if supported) |
302 | */ | 302 | */ |
303 | static int | 303 | static int |
304 | expired_processor (void *cls, | 304 | expired_processor (void *cls, const GNUNET_HashCode * key, uint32_t size, |
305 | const GNUNET_HashCode * key, | 305 | const void *data, enum GNUNET_BLOCK_Type type, |
306 | uint32_t size, | 306 | uint32_t priority, uint32_t anonymity, |
307 | const void *data, | ||
308 | enum GNUNET_BLOCK_Type type, | ||
309 | uint32_t priority, | ||
310 | uint32_t anonymity, | ||
311 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | 307 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) |
312 | { | 308 | { |
313 | struct GNUNET_TIME_Absolute now; | 309 | struct GNUNET_TIME_Absolute now; |
314 | 310 | ||
315 | if (key == NULL) | 311 | if (key == NULL) |
316 | { | 312 | { |
317 | expired_kill_task | 313 | expired_kill_task = |
318 | = GNUNET_SCHEDULER_add_delayed (MAX_EXPIRE_DELAY, | 314 | GNUNET_SCHEDULER_add_delayed (MAX_EXPIRE_DELAY, &delete_expired, NULL); |
319 | &delete_expired, NULL); | ||
320 | return GNUNET_SYSERR; | 315 | return GNUNET_SYSERR; |
321 | } | 316 | } |
322 | now = GNUNET_TIME_absolute_get (); | 317 | now = GNUNET_TIME_absolute_get (); |
323 | if (expiration.abs_value > now.abs_value) | 318 | if (expiration.abs_value > now.abs_value) |
324 | { | 319 | { |
325 | /* finished processing */ | 320 | /* finished processing */ |
326 | expired_kill_task | 321 | expired_kill_task = |
327 | = GNUNET_SCHEDULER_add_delayed (MAX_EXPIRE_DELAY, | 322 | GNUNET_SCHEDULER_add_delayed (MAX_EXPIRE_DELAY, &delete_expired, NULL); |
328 | &delete_expired, NULL); | ||
329 | return GNUNET_SYSERR; | 323 | return GNUNET_SYSERR; |
330 | } | 324 | } |
331 | #if DEBUG_DATASTORE | 325 | #if DEBUG_DATASTORE |
332 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 326 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
333 | "Deleting content `%s' of type %u that expired %llu ms ago\n", | 327 | "Deleting content `%s' of type %u that expired %llu ms ago\n", |
334 | GNUNET_h2s (key), | 328 | GNUNET_h2s (key), type, |
335 | type, | ||
336 | (unsigned long long) (now.abs_value - expiration.abs_value)); | 329 | (unsigned long long) (now.abs_value - expiration.abs_value)); |
337 | #endif | 330 | #endif |
338 | GNUNET_STATISTICS_update (stats, | 331 | GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes expired"), size, |
339 | gettext_noop ("# bytes expired"), size, GNUNET_YES); | 332 | GNUNET_YES); |
340 | GNUNET_CONTAINER_bloomfilter_remove (filter, key); | 333 | GNUNET_CONTAINER_bloomfilter_remove (filter, key); |
341 | expired_kill_task | 334 | expired_kill_task = |
342 | = GNUNET_SCHEDULER_add_delayed (MIN_EXPIRE_DELAY, &delete_expired, NULL); | 335 | GNUNET_SCHEDULER_add_delayed (MIN_EXPIRE_DELAY, &delete_expired, NULL); |
343 | return GNUNET_NO; | 336 | return GNUNET_NO; |
344 | } | 337 | } |
345 | 338 | ||
@@ -381,13 +374,9 @@ delete_expired (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
381 | * GNUNET_NO to delete the item and continue (if supported) | 374 | * GNUNET_NO to delete the item and continue (if supported) |
382 | */ | 375 | */ |
383 | static int | 376 | static int |
384 | quota_processor (void *cls, | 377 | quota_processor (void *cls, const GNUNET_HashCode * key, uint32_t size, |
385 | const GNUNET_HashCode * key, | 378 | const void *data, enum GNUNET_BLOCK_Type type, |
386 | uint32_t size, | 379 | uint32_t priority, uint32_t anonymity, |
387 | const void *data, | ||
388 | enum GNUNET_BLOCK_Type type, | ||
389 | uint32_t priority, | ||
390 | uint32_t anonymity, | ||
391 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | 380 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) |
392 | { | 381 | { |
393 | unsigned long long *need = cls; | 382 | unsigned long long *need = cls; |
@@ -507,10 +496,10 @@ transmit (struct GNUNET_SERVER_Client *client, struct GNUNET_MessageHeader *msg) | |||
507 | tcc->msg = msg; | 496 | tcc->msg = msg; |
508 | tcc->client = client; | 497 | tcc->client = client; |
509 | if (NULL == | 498 | if (NULL == |
510 | (tcc->th = GNUNET_SERVER_notify_transmit_ready (client, | 499 | (tcc->th = |
511 | ntohs (msg->size), | 500 | GNUNET_SERVER_notify_transmit_ready (client, ntohs (msg->size), |
512 | GNUNET_TIME_UNIT_FOREVER_REL, | 501 | GNUNET_TIME_UNIT_FOREVER_REL, |
513 | &transmit_callback, tcc))) | 502 | &transmit_callback, tcc))) |
514 | { | 503 | { |
515 | GNUNET_break (0); | 504 | GNUNET_break (0); |
516 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 505 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
@@ -572,14 +561,10 @@ transmit_status (struct GNUNET_SERVER_Client *client, int code, const char *msg) | |||
572 | * GNUNET_NO to delete the item and continue (if supported) | 561 | * GNUNET_NO to delete the item and continue (if supported) |
573 | */ | 562 | */ |
574 | static int | 563 | static int |
575 | transmit_item (void *cls, | 564 | transmit_item (void *cls, const GNUNET_HashCode * key, uint32_t size, |
576 | const GNUNET_HashCode * key, | 565 | const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, |
577 | uint32_t size, | 566 | uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, |
578 | const void *data, | 567 | uint64_t uid) |
579 | enum GNUNET_BLOCK_Type type, | ||
580 | uint32_t priority, | ||
581 | uint32_t anonymity, | ||
582 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | ||
583 | { | 568 | { |
584 | struct GNUNET_SERVER_Client *client = cls; | 569 | struct GNUNET_SERVER_Client *client = cls; |
585 | struct GNUNET_MessageHeader *end; | 570 | struct GNUNET_MessageHeader *end; |
@@ -589,8 +574,8 @@ transmit_item (void *cls, | |||
589 | { | 574 | { |
590 | /* transmit 'DATA_END' */ | 575 | /* transmit 'DATA_END' */ |
591 | #if DEBUG_DATASTORE | 576 | #if DEBUG_DATASTORE |
592 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 577 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' message\n", |
593 | "Transmitting `%s' message\n", "DATA_END"); | 578 | "DATA_END"); |
594 | #endif | 579 | #endif |
595 | end = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader)); | 580 | end = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader)); |
596 | end->size = htons (sizeof (struct GNUNET_MessageHeader)); | 581 | end->size = htons (sizeof (struct GNUNET_MessageHeader)); |
@@ -618,14 +603,12 @@ transmit_item (void *cls, | |||
618 | #if DEBUG_DATASTORE | 603 | #if DEBUG_DATASTORE |
619 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 604 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
620 | "Transmitting `%s' message for `%s' of type %u with expiration %llu (now: %llu)\n", | 605 | "Transmitting `%s' message for `%s' of type %u with expiration %llu (now: %llu)\n", |
621 | "DATA", | 606 | "DATA", GNUNET_h2s (key), type, |
622 | GNUNET_h2s (key), | ||
623 | type, | ||
624 | (unsigned long long) expiration.abs_value, | 607 | (unsigned long long) expiration.abs_value, |
625 | (unsigned long long) GNUNET_TIME_absolute_get ().abs_value); | 608 | (unsigned long long) GNUNET_TIME_absolute_get ().abs_value); |
626 | #endif | 609 | #endif |
627 | GNUNET_STATISTICS_update (stats, | 610 | GNUNET_STATISTICS_update (stats, gettext_noop ("# results found"), 1, |
628 | gettext_noop ("# results found"), 1, GNUNET_NO); | 611 | GNUNET_NO); |
629 | transmit (client, &dm->header); | 612 | transmit (client, &dm->header); |
630 | GNUNET_SERVER_client_drop (client); | 613 | GNUNET_SERVER_client_drop (client); |
631 | return GNUNET_OK; | 614 | return GNUNET_OK; |
@@ -640,8 +623,7 @@ transmit_item (void *cls, | |||
640 | * @param message the actual message | 623 | * @param message the actual message |
641 | */ | 624 | */ |
642 | static void | 625 | static void |
643 | handle_reserve (void *cls, | 626 | handle_reserve (void *cls, struct GNUNET_SERVER_Client *client, |
644 | struct GNUNET_SERVER_Client *client, | ||
645 | const struct GNUNET_MessageHeader *message) | 627 | const struct GNUNET_MessageHeader *message) |
646 | { | 628 | { |
647 | /** | 629 | /** |
@@ -696,8 +678,8 @@ handle_reserve (void *cls, | |||
696 | return; | 678 | return; |
697 | } | 679 | } |
698 | reserved += req; | 680 | reserved += req; |
699 | GNUNET_STATISTICS_set (stats, | 681 | GNUNET_STATISTICS_set (stats, gettext_noop ("# reserved"), reserved, |
700 | gettext_noop ("# reserved"), reserved, GNUNET_NO); | 682 | GNUNET_NO); |
701 | e = GNUNET_malloc (sizeof (struct ReservationList)); | 683 | e = GNUNET_malloc (sizeof (struct ReservationList)); |
702 | e->next = reservations; | 684 | e->next = reservations; |
703 | reservations = e; | 685 | reservations = e; |
@@ -719,8 +701,7 @@ handle_reserve (void *cls, | |||
719 | * @param message the actual message | 701 | * @param message the actual message |
720 | */ | 702 | */ |
721 | static void | 703 | static void |
722 | handle_release_reserve (void *cls, | 704 | handle_release_reserve (void *cls, struct GNUNET_SERVER_Client *client, |
723 | struct GNUNET_SERVER_Client *client, | ||
724 | const struct GNUNET_MessageHeader *message) | 705 | const struct GNUNET_MessageHeader *message) |
725 | { | 706 | { |
726 | const struct ReleaseReserveMessage *msg = | 707 | const struct ReleaseReserveMessage *msg = |
@@ -732,8 +713,8 @@ handle_release_reserve (void *cls, | |||
732 | unsigned long long rem; | 713 | unsigned long long rem; |
733 | 714 | ||
734 | #if DEBUG_DATASTORE | 715 | #if DEBUG_DATASTORE |
735 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 716 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' request\n", |
736 | "Processing `%s' request\n", "RELEASE_RESERVE"); | 717 | "RELEASE_RESERVE"); |
737 | #endif | 718 | #endif |
738 | next = reservations; | 719 | next = reservations; |
739 | prev = NULL; | 720 | prev = NULL; |
@@ -751,8 +732,8 @@ handle_release_reserve (void *cls, | |||
751 | ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries; | 732 | ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries; |
752 | GNUNET_assert (reserved >= rem); | 733 | GNUNET_assert (reserved >= rem); |
753 | reserved -= rem; | 734 | reserved -= rem; |
754 | GNUNET_STATISTICS_set (stats, | 735 | GNUNET_STATISTICS_set (stats, gettext_noop ("# reserved"), reserved, |
755 | gettext_noop ("# reserved"), reserved, GNUNET_NO); | 736 | GNUNET_NO); |
756 | #if DEBUG_DATASTORE | 737 | #if DEBUG_DATASTORE |
757 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 738 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
758 | "Returning %llu remaining reserved bytes to storage pool\n", | 739 | "Returning %llu remaining reserved bytes to storage pool\n", |
@@ -830,20 +811,15 @@ execute_put (struct GNUNET_SERVER_Client *client, const struct DataMessage *dm) | |||
830 | 811 | ||
831 | size = ntohl (dm->size); | 812 | size = ntohl (dm->size); |
832 | msg = NULL; | 813 | msg = NULL; |
833 | ret = plugin->api->put (plugin->api->cls, | 814 | ret = |
834 | &dm->key, | 815 | plugin->api->put (plugin->api->cls, &dm->key, size, &dm[1], |
835 | size, | 816 | ntohl (dm->type), ntohl (dm->priority), |
836 | &dm[1], | 817 | ntohl (dm->anonymity), ntohl (dm->replication), |
837 | ntohl (dm->type), | 818 | GNUNET_TIME_absolute_ntoh (dm->expiration), &msg); |
838 | ntohl (dm->priority), | ||
839 | ntohl (dm->anonymity), | ||
840 | ntohl (dm->replication), | ||
841 | GNUNET_TIME_absolute_ntoh (dm->expiration), &msg); | ||
842 | if (GNUNET_OK == ret) | 819 | if (GNUNET_OK == ret) |
843 | { | 820 | { |
844 | GNUNET_STATISTICS_update (stats, | 821 | GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes stored"), size, |
845 | gettext_noop ("# bytes stored"), | 822 | GNUNET_YES); |
846 | size, GNUNET_YES); | ||
847 | GNUNET_CONTAINER_bloomfilter_add (filter, &dm->key); | 823 | GNUNET_CONTAINER_bloomfilter_add (filter, &dm->key); |
848 | #if DEBUG_DATASTORE | 824 | #if DEBUG_DATASTORE |
849 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 825 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -884,14 +860,10 @@ execute_put (struct GNUNET_SERVER_Client *client, const struct DataMessage *dm) | |||
884 | * GNUNET_NO to delete the item | 860 | * GNUNET_NO to delete the item |
885 | */ | 861 | */ |
886 | static int | 862 | static int |
887 | check_present (void *cls, | 863 | check_present (void *cls, const GNUNET_HashCode * key, uint32_t size, |
888 | const GNUNET_HashCode * key, | 864 | const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, |
889 | uint32_t size, | 865 | uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, |
890 | const void *data, | 866 | uint64_t uid) |
891 | enum GNUNET_BLOCK_Type type, | ||
892 | uint32_t priority, | ||
893 | uint32_t anonymity, | ||
894 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | ||
895 | { | 867 | { |
896 | struct PutContext *pc = cls; | 868 | struct PutContext *pc = cls; |
897 | const struct DataMessage *dm; | 869 | const struct DataMessage *dm; |
@@ -905,8 +877,9 @@ check_present (void *cls, | |||
905 | return GNUNET_OK; | 877 | return GNUNET_OK; |
906 | } | 878 | } |
907 | if ((GNUNET_BLOCK_TYPE_FS_DBLOCK == type) || | 879 | if ((GNUNET_BLOCK_TYPE_FS_DBLOCK == type) || |
908 | (GNUNET_BLOCK_TYPE_FS_IBLOCK == type) || | 880 | (GNUNET_BLOCK_TYPE_FS_IBLOCK == type) || ((size == ntohl (dm->size)) && |
909 | ((size == ntohl (dm->size)) && (0 == memcmp (&dm[1], data, size)))) | 881 | (0 == |
882 | memcmp (&dm[1], data, size)))) | ||
910 | { | 883 | { |
911 | #if DEBUG_MYSQL | 884 | #if DEBUG_MYSQL |
912 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 885 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -916,8 +889,7 @@ check_present (void *cls, | |||
916 | if ((ntohl (dm->priority) > 0) || | 889 | if ((ntohl (dm->priority) > 0) || |
917 | (GNUNET_TIME_absolute_ntoh (dm->expiration).abs_value > | 890 | (GNUNET_TIME_absolute_ntoh (dm->expiration).abs_value > |
918 | expiration.abs_value)) | 891 | expiration.abs_value)) |
919 | plugin->api->update (plugin->api->cls, | 892 | plugin->api->update (plugin->api->cls, uid, |
920 | uid, | ||
921 | (int32_t) ntohl (dm->priority), | 893 | (int32_t) ntohl (dm->priority), |
922 | GNUNET_TIME_absolute_ntoh (dm->expiration), NULL); | 894 | GNUNET_TIME_absolute_ntoh (dm->expiration), NULL); |
923 | transmit_status (pc->client, GNUNET_NO, NULL); | 895 | transmit_status (pc->client, GNUNET_NO, NULL); |
@@ -942,8 +914,7 @@ check_present (void *cls, | |||
942 | * @param message the actual message | 914 | * @param message the actual message |
943 | */ | 915 | */ |
944 | static void | 916 | static void |
945 | handle_put (void *cls, | 917 | handle_put (void *cls, struct GNUNET_SERVER_Client *client, |
946 | struct GNUNET_SERVER_Client *client, | ||
947 | const struct GNUNET_MessageHeader *message) | 918 | const struct GNUNET_MessageHeader *message) |
948 | { | 919 | { |
949 | const struct DataMessage *dm = check_data (message); | 920 | const struct DataMessage *dm = check_data (message); |
@@ -961,8 +932,8 @@ handle_put (void *cls, | |||
961 | } | 932 | } |
962 | #if DEBUG_DATASTORE | 933 | #if DEBUG_DATASTORE |
963 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 934 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
964 | "Processing `%s' request for `%s' of type %u\n", | 935 | "Processing `%s' request for `%s' of type %u\n", "PUT", |
965 | "PUT", GNUNET_h2s (&dm->key), ntohl (dm->type)); | 936 | GNUNET_h2s (&dm->key), ntohl (dm->type)); |
966 | #endif | 937 | #endif |
967 | rid = ntohl (dm->rid); | 938 | rid = ntohl (dm->rid); |
968 | size = ntohl (dm->size); | 939 | size = ntohl (dm->size); |
@@ -979,8 +950,8 @@ handle_put (void *cls, | |||
979 | pos->entries--; | 950 | pos->entries--; |
980 | pos->amount -= size; | 951 | pos->amount -= size; |
981 | reserved -= (size + GNUNET_DATASTORE_ENTRY_OVERHEAD); | 952 | reserved -= (size + GNUNET_DATASTORE_ENTRY_OVERHEAD); |
982 | GNUNET_STATISTICS_set (stats, | 953 | GNUNET_STATISTICS_set (stats, gettext_noop ("# reserved"), reserved, |
983 | gettext_noop ("# reserved"), reserved, GNUNET_NO); | 954 | GNUNET_NO); |
984 | } | 955 | } |
985 | } | 956 | } |
986 | if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (filter, &dm->key)) | 957 | if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (filter, &dm->key)) |
@@ -991,10 +962,8 @@ handle_put (void *cls, | |||
991 | pc->client = client; | 962 | pc->client = client; |
992 | GNUNET_SERVER_client_keep (client); | 963 | GNUNET_SERVER_client_keep (client); |
993 | memcpy (&pc[1], dm, size + sizeof (struct DataMessage)); | 964 | memcpy (&pc[1], dm, size + sizeof (struct DataMessage)); |
994 | plugin->api->get_key (plugin->api->cls, | 965 | plugin->api->get_key (plugin->api->cls, 0, &dm->key, &vhash, |
995 | 0, | 966 | ntohl (dm->type), &check_present, pc); |
996 | &dm->key, | ||
997 | &vhash, ntohl (dm->type), &check_present, pc); | ||
998 | return; | 967 | return; |
999 | } | 968 | } |
1000 | execute_put (client, dm); | 969 | execute_put (client, dm); |
@@ -1009,8 +978,7 @@ handle_put (void *cls, | |||
1009 | * @param message the actual message | 978 | * @param message the actual message |
1010 | */ | 979 | */ |
1011 | static void | 980 | static void |
1012 | handle_get (void *cls, | 981 | handle_get (void *cls, struct GNUNET_SERVER_Client *client, |
1013 | struct GNUNET_SERVER_Client *client, | ||
1014 | const struct GNUNET_MessageHeader *message) | 982 | const struct GNUNET_MessageHeader *message) |
1015 | { | 983 | { |
1016 | const struct GetMessage *msg; | 984 | const struct GetMessage *msg; |
@@ -1027,12 +995,11 @@ handle_get (void *cls, | |||
1027 | msg = (const struct GetMessage *) message; | 995 | msg = (const struct GetMessage *) message; |
1028 | #if DEBUG_DATASTORE | 996 | #if DEBUG_DATASTORE |
1029 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 997 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1030 | "Processing `%s' request for `%s' of type %u\n", | 998 | "Processing `%s' request for `%s' of type %u\n", "GET", |
1031 | "GET", GNUNET_h2s (&msg->key), ntohl (msg->type)); | 999 | GNUNET_h2s (&msg->key), ntohl (msg->type)); |
1032 | #endif | 1000 | #endif |
1033 | GNUNET_STATISTICS_update (stats, | 1001 | GNUNET_STATISTICS_update (stats, gettext_noop ("# GET requests received"), 1, |
1034 | gettext_noop ("# GET requests received"), | 1002 | GNUNET_NO); |
1035 | 1, GNUNET_NO); | ||
1036 | GNUNET_SERVER_client_keep (client); | 1003 | GNUNET_SERVER_client_keep (client); |
1037 | if ((size == sizeof (struct GetMessage)) && | 1004 | if ((size == sizeof (struct GetMessage)) && |
1038 | (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (filter, &msg->key))) | 1005 | (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (filter, &msg->key))) |
@@ -1051,8 +1018,7 @@ handle_get (void *cls, | |||
1051 | 0); | 1018 | 0); |
1052 | return; | 1019 | return; |
1053 | } | 1020 | } |
1054 | plugin->api->get_key (plugin->api->cls, | 1021 | plugin->api->get_key (plugin->api->cls, GNUNET_ntohll (msg->offset), |
1055 | GNUNET_ntohll (msg->offset), | ||
1056 | ((size == | 1022 | ((size == |
1057 | sizeof (struct GetMessage)) ? &msg->key : NULL), NULL, | 1023 | sizeof (struct GetMessage)) ? &msg->key : NULL), NULL, |
1058 | ntohl (msg->type), &transmit_item, client); | 1024 | ntohl (msg->type), &transmit_item, client); |
@@ -1067,29 +1033,25 @@ handle_get (void *cls, | |||
1067 | * @param message the actual message | 1033 | * @param message the actual message |
1068 | */ | 1034 | */ |
1069 | static void | 1035 | static void |
1070 | handle_update (void *cls, | 1036 | handle_update (void *cls, struct GNUNET_SERVER_Client *client, |
1071 | struct GNUNET_SERVER_Client *client, | ||
1072 | const struct GNUNET_MessageHeader *message) | 1037 | const struct GNUNET_MessageHeader *message) |
1073 | { | 1038 | { |
1074 | const struct UpdateMessage *msg; | 1039 | const struct UpdateMessage *msg; |
1075 | int ret; | 1040 | int ret; |
1076 | char *emsg; | 1041 | char *emsg; |
1077 | 1042 | ||
1078 | GNUNET_STATISTICS_update (stats, | 1043 | GNUNET_STATISTICS_update (stats, gettext_noop ("# UPDATE requests received"), |
1079 | gettext_noop ("# UPDATE requests received"), | ||
1080 | 1, GNUNET_NO); | 1044 | 1, GNUNET_NO); |
1081 | msg = (const struct UpdateMessage *) message; | 1045 | msg = (const struct UpdateMessage *) message; |
1082 | emsg = NULL; | 1046 | emsg = NULL; |
1083 | #if DEBUG_DATASTORE | 1047 | #if DEBUG_DATASTORE |
1084 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1048 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' request for %llu\n", |
1085 | "Processing `%s' request for %llu\n", | ||
1086 | "UPDATE", (unsigned long long) GNUNET_ntohll (msg->uid)); | 1049 | "UPDATE", (unsigned long long) GNUNET_ntohll (msg->uid)); |
1087 | #endif | 1050 | #endif |
1088 | ret = plugin->api->update (plugin->api->cls, | 1051 | ret = |
1089 | GNUNET_ntohll (msg->uid), | 1052 | plugin->api->update (plugin->api->cls, GNUNET_ntohll (msg->uid), |
1090 | (int32_t) ntohl (msg->priority), | 1053 | (int32_t) ntohl (msg->priority), |
1091 | GNUNET_TIME_absolute_ntoh (msg->expiration), | 1054 | GNUNET_TIME_absolute_ntoh (msg->expiration), &emsg); |
1092 | &emsg); | ||
1093 | transmit_status (client, ret, emsg); | 1055 | transmit_status (client, ret, emsg); |
1094 | GNUNET_free_non_null (emsg); | 1056 | GNUNET_free_non_null (emsg); |
1095 | } | 1057 | } |
@@ -1103,13 +1065,12 @@ handle_update (void *cls, | |||
1103 | * @param message the actual message | 1065 | * @param message the actual message |
1104 | */ | 1066 | */ |
1105 | static void | 1067 | static void |
1106 | handle_get_replication (void *cls, | 1068 | handle_get_replication (void *cls, struct GNUNET_SERVER_Client *client, |
1107 | struct GNUNET_SERVER_Client *client, | ||
1108 | const struct GNUNET_MessageHeader *message) | 1069 | const struct GNUNET_MessageHeader *message) |
1109 | { | 1070 | { |
1110 | #if DEBUG_DATASTORE | 1071 | #if DEBUG_DATASTORE |
1111 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1072 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' request\n", |
1112 | "Processing `%s' request\n", "GET_REPLICATION"); | 1073 | "GET_REPLICATION"); |
1113 | #endif | 1074 | #endif |
1114 | GNUNET_STATISTICS_update (stats, | 1075 | GNUNET_STATISTICS_update (stats, |
1115 | gettext_noop | 1076 | gettext_noop |
@@ -1128,8 +1089,7 @@ handle_get_replication (void *cls, | |||
1128 | * @param message the actual message | 1089 | * @param message the actual message |
1129 | */ | 1090 | */ |
1130 | static void | 1091 | static void |
1131 | handle_get_zero_anonymity (void *cls, | 1092 | handle_get_zero_anonymity (void *cls, struct GNUNET_SERVER_Client *client, |
1132 | struct GNUNET_SERVER_Client *client, | ||
1133 | const struct GNUNET_MessageHeader *message) | 1093 | const struct GNUNET_MessageHeader *message) |
1134 | { | 1094 | { |
1135 | const struct GetZeroAnonymityMessage *msg = | 1095 | const struct GetZeroAnonymityMessage *msg = |
@@ -1144,8 +1104,8 @@ handle_get_zero_anonymity (void *cls, | |||
1144 | return; | 1104 | return; |
1145 | } | 1105 | } |
1146 | #if DEBUG_DATASTORE | 1106 | #if DEBUG_DATASTORE |
1147 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1107 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' request\n", |
1148 | "Processing `%s' request\n", "GET_ZERO_ANONYMITY"); | 1108 | "GET_ZERO_ANONYMITY"); |
1149 | #endif | 1109 | #endif |
1150 | GNUNET_STATISTICS_update (stats, | 1110 | GNUNET_STATISTICS_update (stats, |
1151 | gettext_noop | 1111 | gettext_noop |
@@ -1153,8 +1113,8 @@ handle_get_zero_anonymity (void *cls, | |||
1153 | GNUNET_NO); | 1113 | GNUNET_NO); |
1154 | GNUNET_SERVER_client_keep (client); | 1114 | GNUNET_SERVER_client_keep (client); |
1155 | plugin->api->get_zero_anonymity (plugin->api->cls, | 1115 | plugin->api->get_zero_anonymity (plugin->api->cls, |
1156 | GNUNET_ntohll (msg->offset), | 1116 | GNUNET_ntohll (msg->offset), type, |
1157 | type, &transmit_item, client); | 1117 | &transmit_item, client); |
1158 | } | 1118 | } |
1159 | 1119 | ||
1160 | 1120 | ||
@@ -1163,13 +1123,9 @@ handle_get_zero_anonymity (void *cls, | |||
1163 | * in to be deleted (by returning GNUNET_NO). | 1123 | * in to be deleted (by returning GNUNET_NO). |
1164 | */ | 1124 | */ |
1165 | static int | 1125 | static int |
1166 | remove_callback (void *cls, | 1126 | remove_callback (void *cls, const GNUNET_HashCode * key, uint32_t size, |
1167 | const GNUNET_HashCode * key, | 1127 | const void *data, enum GNUNET_BLOCK_Type type, |
1168 | uint32_t size, | 1128 | uint32_t priority, uint32_t anonymity, |
1169 | const void *data, | ||
1170 | enum GNUNET_BLOCK_Type type, | ||
1171 | uint32_t priority, | ||
1172 | uint32_t anonymity, | ||
1173 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | 1129 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) |
1174 | { | 1130 | { |
1175 | struct GNUNET_SERVER_Client *client = cls; | 1131 | struct GNUNET_SERVER_Client *client = cls; |
@@ -1207,8 +1163,7 @@ remove_callback (void *cls, | |||
1207 | * @param message the actual message | 1163 | * @param message the actual message |
1208 | */ | 1164 | */ |
1209 | static void | 1165 | static void |
1210 | handle_remove (void *cls, | 1166 | handle_remove (void *cls, struct GNUNET_SERVER_Client *client, |
1211 | struct GNUNET_SERVER_Client *client, | ||
1212 | const struct GNUNET_MessageHeader *message) | 1167 | const struct GNUNET_MessageHeader *message) |
1213 | { | 1168 | { |
1214 | const struct DataMessage *dm = check_data (message); | 1169 | const struct DataMessage *dm = check_data (message); |
@@ -1222,18 +1177,14 @@ handle_remove (void *cls, | |||
1222 | } | 1177 | } |
1223 | #if DEBUG_DATASTORE | 1178 | #if DEBUG_DATASTORE |
1224 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1179 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1225 | "Processing `%s' request for `%s' of type %u\n", | 1180 | "Processing `%s' request for `%s' of type %u\n", "REMOVE", |
1226 | "REMOVE", GNUNET_h2s (&dm->key), ntohl (dm->type)); | 1181 | GNUNET_h2s (&dm->key), ntohl (dm->type)); |
1227 | #endif | 1182 | #endif |
1228 | GNUNET_STATISTICS_update (stats, | 1183 | GNUNET_STATISTICS_update (stats, gettext_noop ("# REMOVE requests received"), |
1229 | gettext_noop ("# REMOVE requests received"), | ||
1230 | 1, GNUNET_NO); | 1184 | 1, GNUNET_NO); |
1231 | GNUNET_SERVER_client_keep (client); | 1185 | GNUNET_SERVER_client_keep (client); |
1232 | GNUNET_CRYPTO_hash (&dm[1], ntohl (dm->size), &vhash); | 1186 | GNUNET_CRYPTO_hash (&dm[1], ntohl (dm->size), &vhash); |
1233 | plugin->api->get_key (plugin->api->cls, | 1187 | plugin->api->get_key (plugin->api->cls, 0, &dm->key, &vhash, |
1234 | 0, | ||
1235 | &dm->key, | ||
1236 | &vhash, | ||
1237 | (enum GNUNET_BLOCK_Type) ntohl (dm->type), | 1188 | (enum GNUNET_BLOCK_Type) ntohl (dm->type), |
1238 | &remove_callback, client); | 1189 | &remove_callback, client); |
1239 | } | 1190 | } |
@@ -1247,8 +1198,7 @@ handle_remove (void *cls, | |||
1247 | * @param message the actual message | 1198 | * @param message the actual message |
1248 | */ | 1199 | */ |
1249 | static void | 1200 | static void |
1250 | handle_drop (void *cls, | 1201 | handle_drop (void *cls, struct GNUNET_SERVER_Client *client, |
1251 | struct GNUNET_SERVER_Client *client, | ||
1252 | const struct GNUNET_MessageHeader *message) | 1202 | const struct GNUNET_MessageHeader *message) |
1253 | { | 1203 | { |
1254 | #if DEBUG_DATASTORE | 1204 | #if DEBUG_DATASTORE |
@@ -1298,9 +1248,8 @@ disk_utilization_change_cb (void *cls, int delta) | |||
1298 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration | 1248 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration |
1299 | */ | 1249 | */ |
1300 | static int | 1250 | static int |
1301 | process_stat_in (void *cls, | 1251 | process_stat_in (void *cls, const char *subsystem, const char *name, |
1302 | const char *subsystem, | 1252 | uint64_t value, int is_persistent) |
1303 | const char *name, uint64_t value, int is_persistent) | ||
1304 | { | 1253 | { |
1305 | GNUNET_assert (stats_worked == GNUNET_NO); | 1254 | GNUNET_assert (stats_worked == GNUNET_NO); |
1306 | stats_worked = GNUNET_YES; | 1255 | stats_worked = GNUNET_YES; |
@@ -1336,20 +1285,20 @@ load_plugin () | |||
1336 | char *name; | 1285 | char *name; |
1337 | 1286 | ||
1338 | if (GNUNET_OK != | 1287 | if (GNUNET_OK != |
1339 | GNUNET_CONFIGURATION_get_value_string (cfg, | 1288 | GNUNET_CONFIGURATION_get_value_string (cfg, "DATASTORE", "DATABASE", |
1340 | "DATASTORE", "DATABASE", &name)) | 1289 | &name)) |
1341 | { | 1290 | { |
1342 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1291 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1343 | _("No `%s' specified for `%s' in configuration!\n"), | 1292 | _("No `%s' specified for `%s' in configuration!\n"), "DATABASE", |
1344 | "DATABASE", "DATASTORE"); | 1293 | "DATASTORE"); |
1345 | return NULL; | 1294 | return NULL; |
1346 | } | 1295 | } |
1347 | ret = GNUNET_malloc (sizeof (struct DatastorePlugin)); | 1296 | ret = GNUNET_malloc (sizeof (struct DatastorePlugin)); |
1348 | ret->env.cfg = cfg; | 1297 | ret->env.cfg = cfg; |
1349 | ret->env.duc = &disk_utilization_change_cb; | 1298 | ret->env.duc = &disk_utilization_change_cb; |
1350 | ret->env.cls = NULL; | 1299 | ret->env.cls = NULL; |
1351 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1300 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' datastore plugin\n"), |
1352 | _("Loading `%s' datastore plugin\n"), name); | 1301 | name); |
1353 | GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); | 1302 | GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); |
1354 | ret->short_name = name; | 1303 | ret->short_name = name; |
1355 | ret->lib_name = libname; | 1304 | ret->lib_name = libname; |
@@ -1444,8 +1393,8 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1444 | GNUNET_SCHEDULER_cancel (expired_kill_task); | 1393 | GNUNET_SCHEDULER_cancel (expired_kill_task); |
1445 | expired_kill_task = GNUNET_SCHEDULER_NO_TASK; | 1394 | expired_kill_task = GNUNET_SCHEDULER_NO_TASK; |
1446 | } | 1395 | } |
1447 | GNUNET_SCHEDULER_add_continuation (&unload_task, | 1396 | GNUNET_SCHEDULER_add_continuation (&unload_task, NULL, |
1448 | NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 1397 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
1449 | } | 1398 | } |
1450 | 1399 | ||
1451 | 1400 | ||
@@ -1486,8 +1435,8 @@ cleanup_reservations (void *cls, struct GNUNET_SERVER_Client *client) | |||
1486 | } | 1435 | } |
1487 | pos = next; | 1436 | pos = next; |
1488 | } | 1437 | } |
1489 | GNUNET_STATISTICS_set (stats, | 1438 | GNUNET_STATISTICS_set (stats, gettext_noop ("# reserved"), reserved, |
1490 | gettext_noop ("# reserved"), reserved, GNUNET_NO); | 1439 | GNUNET_NO); |
1491 | } | 1440 | } |
1492 | 1441 | ||
1493 | 1442 | ||
@@ -1499,8 +1448,7 @@ cleanup_reservations (void *cls, struct GNUNET_SERVER_Client *client) | |||
1499 | * @param c configuration to use | 1448 | * @param c configuration to use |
1500 | */ | 1449 | */ |
1501 | static void | 1450 | static void |
1502 | run (void *cls, | 1451 | run (void *cls, struct GNUNET_SERVER_Handle *server, |
1503 | struct GNUNET_SERVER_Handle *server, | ||
1504 | const struct GNUNET_CONFIGURATION_Handle *c) | 1452 | const struct GNUNET_CONFIGURATION_Handle *c) |
1505 | { | 1453 | { |
1506 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 1454 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
@@ -1532,21 +1480,19 @@ run (void *cls, | |||
1532 | GNUNET_CONFIGURATION_get_value_number (cfg, "DATASTORE", "QUOTA", "a)) | 1480 | GNUNET_CONFIGURATION_get_value_number (cfg, "DATASTORE", "QUOTA", "a)) |
1533 | { | 1481 | { |
1534 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1482 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1535 | _("No `%s' specified for `%s' in configuration!\n"), | 1483 | _("No `%s' specified for `%s' in configuration!\n"), "QUOTA", |
1536 | "QUOTA", "DATASTORE"); | 1484 | "DATASTORE"); |
1537 | return; | 1485 | return; |
1538 | } | 1486 | } |
1539 | stats = GNUNET_STATISTICS_create ("datastore", cfg); | 1487 | stats = GNUNET_STATISTICS_create ("datastore", cfg); |
1540 | GNUNET_STATISTICS_set (stats, gettext_noop ("# quota"), quota, GNUNET_NO); | 1488 | GNUNET_STATISTICS_set (stats, gettext_noop ("# quota"), quota, GNUNET_NO); |
1541 | cache_size = quota / 8; /* Or should we make this an option? */ | 1489 | cache_size = quota / 8; /* Or should we make this an option? */ |
1542 | GNUNET_STATISTICS_set (stats, | 1490 | GNUNET_STATISTICS_set (stats, gettext_noop ("# cache size"), cache_size, |
1543 | gettext_noop ("# cache size"), cache_size, GNUNET_NO); | 1491 | GNUNET_NO); |
1544 | bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */ | 1492 | bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */ |
1545 | fn = NULL; | 1493 | fn = NULL; |
1546 | if ((GNUNET_OK != | 1494 | if ((GNUNET_OK != |
1547 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 1495 | GNUNET_CONFIGURATION_get_value_filename (cfg, "DATASTORE", "BLOOMFILTER", |
1548 | "DATASTORE", | ||
1549 | "BLOOMFILTER", | ||
1550 | &fn)) || | 1496 | &fn)) || |
1551 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn))) | 1497 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn))) |
1552 | { | 1498 | { |
@@ -1584,19 +1530,17 @@ run (void *cls, | |||
1584 | } | 1530 | } |
1585 | return; | 1531 | return; |
1586 | } | 1532 | } |
1587 | stat_get = GNUNET_STATISTICS_get (stats, | 1533 | stat_get = |
1588 | "datastore", | 1534 | GNUNET_STATISTICS_get (stats, "datastore", QUOTA_STAT_NAME, |
1589 | QUOTA_STAT_NAME, | 1535 | GNUNET_TIME_UNIT_SECONDS, &process_stat_done, |
1590 | GNUNET_TIME_UNIT_SECONDS, | 1536 | &process_stat_in, plugin); |
1591 | &process_stat_done, | ||
1592 | &process_stat_in, plugin); | ||
1593 | GNUNET_SERVER_disconnect_notify (server, &cleanup_reservations, NULL); | 1537 | GNUNET_SERVER_disconnect_notify (server, &cleanup_reservations, NULL); |
1594 | GNUNET_SERVER_add_handlers (server, handlers); | 1538 | GNUNET_SERVER_add_handlers (server, handlers); |
1595 | expired_kill_task | 1539 | expired_kill_task = |
1596 | = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 1540 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
1597 | &delete_expired, NULL); | 1541 | &delete_expired, NULL); |
1598 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 1542 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task, |
1599 | &cleaning_task, NULL); | 1543 | NULL); |
1600 | } | 1544 | } |
1601 | 1545 | ||
1602 | 1546 | ||
@@ -1612,11 +1556,10 @@ main (int argc, char *const *argv) | |||
1612 | { | 1556 | { |
1613 | int ret; | 1557 | int ret; |
1614 | 1558 | ||
1615 | ret = (GNUNET_OK == | 1559 | ret = |
1616 | GNUNET_SERVICE_run (argc, | 1560 | (GNUNET_OK == |
1617 | argv, | 1561 | GNUNET_SERVICE_run (argc, argv, "datastore", GNUNET_SERVICE_OPTION_NONE, |
1618 | "datastore", | 1562 | &run, NULL)) ? 0 : 1; |
1619 | GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; | ||
1620 | return ret; | 1563 | return ret; |
1621 | } | 1564 | } |
1622 | 1565 | ||
diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c index 9d567aacd..cf9911329 100644 --- a/src/datastore/perf_datastore_api.c +++ b/src/datastore/perf_datastore_api.c | |||
@@ -104,8 +104,8 @@ struct CpsRunContext | |||
104 | 104 | ||
105 | 105 | ||
106 | 106 | ||
107 | static void | 107 | static void run_continuation (void *cls, |
108 | run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 108 | const struct GNUNET_SCHEDULER_TaskContext *tc); |
109 | 109 | ||
110 | 110 | ||
111 | 111 | ||
@@ -138,8 +138,8 @@ check_success (void *cls, int success, const char *msg) | |||
138 | else | 138 | else |
139 | crc->phase = RP_CUT; | 139 | crc->phase = RP_CUT; |
140 | } | 140 | } |
141 | GNUNET_SCHEDULER_add_continuation (&run_continuation, | 141 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, |
142 | crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 142 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
143 | } | 143 | } |
144 | 144 | ||
145 | 145 | ||
@@ -172,14 +172,10 @@ remove_next (void *cls, int success, const char *msg) | |||
172 | 172 | ||
173 | 173 | ||
174 | static void | 174 | static void |
175 | delete_value (void *cls, | 175 | delete_value (void *cls, const GNUNET_HashCode * key, size_t size, |
176 | const GNUNET_HashCode * key, | 176 | const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, |
177 | size_t size, | 177 | uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, |
178 | const void *data, | 178 | uint64_t uid) |
179 | enum GNUNET_BLOCK_Type type, | ||
180 | uint32_t priority, | ||
181 | uint32_t anonymity, | ||
182 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | ||
183 | { | 179 | { |
184 | struct CpsRunContext *crc = cls; | 180 | struct CpsRunContext *crc = cls; |
185 | 181 | ||
@@ -191,11 +187,8 @@ delete_value (void *cls, | |||
191 | if (stored_bytes < MAX_SIZE) | 187 | if (stored_bytes < MAX_SIZE) |
192 | crc->phase = RP_PUT; | 188 | crc->phase = RP_PUT; |
193 | GNUNET_assert (NULL != | 189 | GNUNET_assert (NULL != |
194 | GNUNET_DATASTORE_remove (datastore, | 190 | GNUNET_DATASTORE_remove (datastore, key, size, data, 1, 1, |
195 | key, | 191 | TIMEOUT, &remove_next, crc)); |
196 | size, | ||
197 | data, | ||
198 | 1, 1, TIMEOUT, &remove_next, crc)); | ||
199 | } | 192 | } |
200 | 193 | ||
201 | 194 | ||
@@ -228,12 +221,7 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
228 | memset (data, i - 255, size / 2); | 221 | memset (data, i - 255, size / 2); |
229 | data[0] = k; | 222 | data[0] = k; |
230 | GNUNET_assert (NULL != | 223 | GNUNET_assert (NULL != |
231 | GNUNET_DATASTORE_put (datastore, | 224 | GNUNET_DATASTORE_put (datastore, 0, &key, size, data, i + 1, |
232 | 0, | ||
233 | &key, | ||
234 | size, | ||
235 | data, | ||
236 | i + 1, | ||
237 | GNUNET_CRYPTO_random_u32 | 225 | GNUNET_CRYPTO_random_u32 |
238 | (GNUNET_CRYPTO_QUALITY_WEAK, 100), i, | 226 | (GNUNET_CRYPTO_QUALITY_WEAK, 100), i, |
239 | 0, | 227 | 0, |
@@ -247,9 +235,9 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
247 | case RP_CUT: | 235 | case RP_CUT: |
248 | /* trim down below MAX_SIZE again */ | 236 | /* trim down below MAX_SIZE again */ |
249 | GNUNET_assert (NULL != | 237 | GNUNET_assert (NULL != |
250 | GNUNET_DATASTORE_get_for_replication (datastore, | 238 | GNUNET_DATASTORE_get_for_replication (datastore, 1, 1, |
251 | 1, 1, TIMEOUT, | 239 | TIMEOUT, &delete_value, |
252 | &delete_value, crc)); | 240 | crc)); |
253 | break; | 241 | break; |
254 | case RP_REPORT: | 242 | case RP_REPORT: |
255 | printf ( | 243 | printf ( |
@@ -263,15 +251,13 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
263 | (start_time).rel_value)); | 251 | (start_time).rel_value)); |
264 | crc->phase = RP_PUT; | 252 | crc->phase = RP_PUT; |
265 | crc->j = 0; | 253 | crc->j = 0; |
266 | GNUNET_SCHEDULER_add_continuation (&run_continuation, | 254 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, |
267 | crc, | ||
268 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 255 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
269 | break; | 256 | break; |
270 | case RP_DONE: | 257 | case RP_DONE: |
271 | GNUNET_snprintf (gstr, sizeof (gstr), "DATASTORE-%s", plugin_name); | 258 | GNUNET_snprintf (gstr, sizeof (gstr), "DATASTORE-%s", plugin_name); |
272 | if ((crc->i == ITERATIONS) && (stored_ops > 0)) | 259 | if ((crc->i == ITERATIONS) && (stored_ops > 0)) |
273 | GAUGER (gstr, | 260 | GAUGER (gstr, "PUT operation duration", |
274 | "PUT operation duration", | ||
275 | GNUNET_TIME_absolute_get_duration (start_time).rel_value / | 261 | GNUNET_TIME_absolute_get_duration (start_time).rel_value / |
276 | stored_ops, "ms/operation"); | 262 | stored_ops, "ms/operation"); |
277 | GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); | 263 | GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); |
@@ -302,15 +288,14 @@ run_tests (void *cls, int success, const char *msg) | |||
302 | GNUNET_free (crc); | 288 | GNUNET_free (crc); |
303 | return; | 289 | return; |
304 | } | 290 | } |
305 | GNUNET_SCHEDULER_add_continuation (&run_continuation, | 291 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, |
306 | crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 292 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
307 | } | 293 | } |
308 | 294 | ||
309 | 295 | ||
310 | static void | 296 | static void |
311 | run (void *cls, | 297 | run (void *cls, char *const *args, const char *cfgfile, |
312 | char *const *args, | 298 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
313 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
314 | { | 299 | { |
315 | struct CpsRunContext *crc; | 300 | struct CpsRunContext *crc; |
316 | static GNUNET_HashCode zkey; | 301 | static GNUNET_HashCode zkey; |
@@ -321,10 +306,8 @@ run (void *cls, | |||
321 | crc->cfg = cfg; | 306 | crc->cfg = cfg; |
322 | crc->phase = RP_PUT; | 307 | crc->phase = RP_PUT; |
323 | if (NULL == | 308 | if (NULL == |
324 | GNUNET_DATASTORE_put (datastore, 0, | 309 | GNUNET_DATASTORE_put (datastore, 0, &zkey, 4, "TEST", |
325 | &zkey, 4, "TEST", | 310 | GNUNET_BLOCK_TYPE_TEST, 0, 0, 0, |
326 | GNUNET_BLOCK_TYPE_TEST, | ||
327 | 0, 0, 0, | ||
328 | GNUNET_TIME_relative_to_absolute | 311 | GNUNET_TIME_relative_to_absolute |
329 | (GNUNET_TIME_UNIT_SECONDS), 0, 1, | 312 | (GNUNET_TIME_UNIT_SECONDS), 0, 1, |
330 | GNUNET_TIME_UNIT_MINUTES, &run_tests, crc)) | 313 | GNUNET_TIME_UNIT_MINUTES, &run_tests, crc)) |
@@ -355,19 +338,18 @@ check () | |||
355 | GNUNET_GETOPT_OPTION_END | 338 | GNUNET_GETOPT_OPTION_END |
356 | }; | 339 | }; |
357 | 340 | ||
358 | GNUNET_snprintf (cfg_name, | 341 | GNUNET_snprintf (cfg_name, sizeof (cfg_name), |
359 | sizeof (cfg_name), | ||
360 | "test_datastore_api_data_%s.conf", plugin_name); | 342 | "test_datastore_api_data_%s.conf", plugin_name); |
361 | proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 343 | proc = |
362 | "gnunet-service-arm", | 344 | GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
345 | "gnunet-service-arm", | ||
363 | #if VERBOSE | 346 | #if VERBOSE |
364 | "-L", "DEBUG", | 347 | "-L", "DEBUG", |
365 | #endif | 348 | #endif |
366 | "-c", cfg_name, NULL); | 349 | "-c", cfg_name, NULL); |
367 | GNUNET_assert (NULL != proc); | 350 | GNUNET_assert (NULL != proc); |
368 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 351 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, |
369 | argv, "perf-datastore-api", "nohelp", | 352 | "perf-datastore-api", "nohelp", options, &run, NULL); |
370 | options, &run, NULL); | ||
371 | sleep (1); /* give datastore chance to process 'DROP' */ | 353 | sleep (1); /* give datastore chance to process 'DROP' */ |
372 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | 354 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) |
373 | { | 355 | { |
@@ -398,9 +380,8 @@ main (int argc, char *argv[]) | |||
398 | else | 380 | else |
399 | pos = (char *) plugin_name; | 381 | pos = (char *) plugin_name; |
400 | 382 | ||
401 | GNUNET_snprintf (dir_name, | 383 | GNUNET_snprintf (dir_name, sizeof (dir_name), "/tmp/test-gnunet-datastore-%s", |
402 | sizeof (dir_name), | 384 | plugin_name); |
403 | "/tmp/test-gnunet-datastore-%s", plugin_name); | ||
404 | GNUNET_DISK_directory_remove (dir_name); | 385 | GNUNET_DISK_directory_remove (dir_name); |
405 | GNUNET_log_setup ("perf-datastore-api", | 386 | GNUNET_log_setup ("perf-datastore-api", |
406 | #if VERBOSE | 387 | #if VERBOSE |
diff --git a/src/datastore/perf_plugin_datastore.c b/src/datastore/perf_plugin_datastore.c index f8a3705e4..1e2a29f14 100644 --- a/src/datastore/perf_plugin_datastore.c +++ b/src/datastore/perf_plugin_datastore.c | |||
@@ -149,14 +149,10 @@ static void test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | |||
149 | 149 | ||
150 | 150 | ||
151 | static int | 151 | static int |
152 | iterate_zeros (void *cls, | 152 | iterate_zeros (void *cls, const GNUNET_HashCode * key, uint32_t size, |
153 | const GNUNET_HashCode * key, | 153 | const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, |
154 | uint32_t size, | 154 | uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, |
155 | const void *data, | 155 | uint64_t uid) |
156 | enum GNUNET_BLOCK_Type type, | ||
157 | uint32_t priority, | ||
158 | uint32_t anonymity, | ||
159 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | ||
160 | { | 156 | { |
161 | struct CpsRunContext *crc = cls; | 157 | struct CpsRunContext *crc = cls; |
162 | int i; | 158 | int i; |
@@ -187,8 +183,7 @@ iterate_zeros (void *cls, | |||
187 | (unsigned long long) (crc->end.abs_value - crc->start.abs_value), | 183 | (unsigned long long) (crc->end.abs_value - crc->start.abs_value), |
188 | bc, crc->cnt); | 184 | bc, crc->cnt); |
189 | if (crc->cnt > 0) | 185 | if (crc->cnt > 0) |
190 | GAUGER (category, | 186 | GAUGER (category, "Select random zero-anonymity item", |
191 | "Select random zero-anonymity item", | ||
192 | (crc->end.abs_value - crc->start.abs_value) / crc->cnt, | 187 | (crc->end.abs_value - crc->start.abs_value) / crc->cnt, |
193 | "ms/item"); | 188 | "ms/item"); |
194 | memset (hits, 0, sizeof (hits)); | 189 | memset (hits, 0, sizeof (hits)); |
@@ -202,13 +197,9 @@ iterate_zeros (void *cls, | |||
202 | 197 | ||
203 | 198 | ||
204 | static int | 199 | static int |
205 | expiration_get (void *cls, | 200 | expiration_get (void *cls, const GNUNET_HashCode * key, uint32_t size, |
206 | const GNUNET_HashCode * key, | 201 | const void *data, enum GNUNET_BLOCK_Type type, |
207 | uint32_t size, | 202 | uint32_t priority, uint32_t anonymity, |
208 | const void *data, | ||
209 | enum GNUNET_BLOCK_Type type, | ||
210 | uint32_t priority, | ||
211 | uint32_t anonymity, | ||
212 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | 203 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) |
213 | { | 204 | { |
214 | struct CpsRunContext *crc = cls; | 205 | struct CpsRunContext *crc = cls; |
@@ -234,8 +225,7 @@ expiration_get (void *cls, | |||
234 | (unsigned long long) (crc->end.abs_value - crc->start.abs_value), | 225 | (unsigned long long) (crc->end.abs_value - crc->start.abs_value), |
235 | bc, (unsigned int) PUT_10); | 226 | bc, (unsigned int) PUT_10); |
236 | if (crc->cnt > 0) | 227 | if (crc->cnt > 0) |
237 | GAUGER (category, | 228 | GAUGER (category, "Selecting and deleting by expiration", |
238 | "Selecting and deleting by expiration", | ||
239 | (crc->end.abs_value - crc->start.abs_value) / crc->cnt, | 229 | (crc->end.abs_value - crc->start.abs_value) / crc->cnt, |
240 | "ms/item"); | 230 | "ms/item"); |
241 | memset (hits, 0, sizeof (hits)); | 231 | memset (hits, 0, sizeof (hits)); |
@@ -252,13 +242,9 @@ expiration_get (void *cls, | |||
252 | 242 | ||
253 | 243 | ||
254 | static int | 244 | static int |
255 | replication_get (void *cls, | 245 | replication_get (void *cls, const GNUNET_HashCode * key, uint32_t size, |
256 | const GNUNET_HashCode * key, | 246 | const void *data, enum GNUNET_BLOCK_Type type, |
257 | uint32_t size, | 247 | uint32_t priority, uint32_t anonymity, |
258 | const void *data, | ||
259 | enum GNUNET_BLOCK_Type type, | ||
260 | uint32_t priority, | ||
261 | uint32_t anonymity, | ||
262 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | 248 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) |
263 | { | 249 | { |
264 | struct CpsRunContext *crc = cls; | 250 | struct CpsRunContext *crc = cls; |
@@ -285,8 +271,7 @@ replication_get (void *cls, | |||
285 | (unsigned long long) (crc->end.abs_value - crc->start.abs_value), | 271 | (unsigned long long) (crc->end.abs_value - crc->start.abs_value), |
286 | bc, (unsigned int) PUT_10); | 272 | bc, (unsigned int) PUT_10); |
287 | if (crc->cnt > 0) | 273 | if (crc->cnt > 0) |
288 | GAUGER (category, | 274 | GAUGER (category, "Selecting random item for replication", |
289 | "Selecting random item for replication", | ||
290 | (crc->end.abs_value - crc->start.abs_value) / crc->cnt, | 275 | (crc->end.abs_value - crc->start.abs_value) / crc->cnt, |
291 | "ms/item"); | 276 | "ms/item"); |
292 | memset (hits, 0, sizeof (hits)); | 277 | memset (hits, 0, sizeof (hits)); |
@@ -316,12 +301,12 @@ unload_plugin (struct GNUNET_DATASTORE_PluginFunctions *api, | |||
316 | char *libname; | 301 | char *libname; |
317 | 302 | ||
318 | if (GNUNET_OK != | 303 | if (GNUNET_OK != |
319 | GNUNET_CONFIGURATION_get_value_string (cfg, | 304 | GNUNET_CONFIGURATION_get_value_string (cfg, "DATASTORE", "DATABASE", |
320 | "DATASTORE", "DATABASE", &name)) | 305 | &name)) |
321 | { | 306 | { |
322 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 307 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
323 | _("No `%s' specified for `%s' in configuration!\n"), | 308 | _("No `%s' specified for `%s' in configuration!\n"), "DATABASE", |
324 | "DATABASE", "DATASTORE"); | 309 | "DATASTORE"); |
325 | return; | 310 | return; |
326 | } | 311 | } |
327 | GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); | 312 | GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); |
@@ -375,13 +360,11 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
375 | putValue (crc->api, j, crc->i); | 360 | putValue (crc->api, j, crc->i); |
376 | crc->end = GNUNET_TIME_absolute_get (); | 361 | crc->end = GNUNET_TIME_absolute_get (); |
377 | { | 362 | { |
378 | printf ("%s took %llu ms for %llu items\n", | 363 | printf ("%s took %llu ms for %llu items\n", "Storing an item", |
379 | "Storing an item", | ||
380 | (unsigned long long) (crc->end.abs_value - crc->start.abs_value), | 364 | (unsigned long long) (crc->end.abs_value - crc->start.abs_value), |
381 | PUT_10); | 365 | PUT_10); |
382 | if (PUT_10 > 0) | 366 | if (PUT_10 > 0) |
383 | GAUGER (category, | 367 | GAUGER (category, "Storing an item", |
384 | "Storing an item", | ||
385 | (crc->end.abs_value - crc->start.abs_value) / PUT_10, | 368 | (crc->end.abs_value - crc->start.abs_value) / PUT_10, |
386 | "ms/item"); | 369 | "ms/item"); |
387 | } | 370 | } |
@@ -394,8 +377,8 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
394 | crc->api->get_replication (crc->api->cls, &replication_get, crc); | 377 | crc->api->get_replication (crc->api->cls, &replication_get, crc); |
395 | break; | 378 | break; |
396 | case RP_ZA_GET: | 379 | case RP_ZA_GET: |
397 | crc->api->get_zero_anonymity (crc->api->cls, | 380 | crc->api->get_zero_anonymity (crc->api->cls, crc->offset++, 1, |
398 | crc->offset++, 1, &iterate_zeros, crc); | 381 | &iterate_zeros, crc); |
399 | break; | 382 | break; |
400 | case RP_EXP_GET: | 383 | case RP_EXP_GET: |
401 | crc->api->get_expiration (crc->api->cls, &expiration_get, crc); | 384 | crc->api->get_expiration (crc->api->cls, &expiration_get, crc); |
@@ -422,19 +405,19 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
422 | char *libname; | 405 | char *libname; |
423 | 406 | ||
424 | if (GNUNET_OK != | 407 | if (GNUNET_OK != |
425 | GNUNET_CONFIGURATION_get_value_string (cfg, | 408 | GNUNET_CONFIGURATION_get_value_string (cfg, "DATASTORE", "DATABASE", |
426 | "DATASTORE", "DATABASE", &name)) | 409 | &name)) |
427 | { | 410 | { |
428 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 411 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
429 | _("No `%s' specified for `%s' in configuration!\n"), | 412 | _("No `%s' specified for `%s' in configuration!\n"), "DATABASE", |
430 | "DATABASE", "DATASTORE"); | 413 | "DATASTORE"); |
431 | return NULL; | 414 | return NULL; |
432 | } | 415 | } |
433 | env.cfg = cfg; | 416 | env.cfg = cfg; |
434 | env.duc = &disk_utilization_change_cb; | 417 | env.duc = &disk_utilization_change_cb; |
435 | env.cls = NULL; | 418 | env.cls = NULL; |
436 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 419 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' datastore plugin\n"), |
437 | _("Loading `%s' datastore plugin\n"), name); | 420 | name); |
438 | GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); | 421 | GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); |
439 | if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env))) | 422 | if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env))) |
440 | { | 423 | { |
@@ -448,9 +431,8 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
448 | 431 | ||
449 | 432 | ||
450 | static void | 433 | static void |
451 | run (void *cls, | 434 | run (void *cls, char *const *args, const char *cfgfile, |
452 | char *const *args, | 435 | const struct GNUNET_CONFIGURATION_Handle *c) |
453 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) | ||
454 | { | 436 | { |
455 | struct GNUNET_DATASTORE_PluginFunctions *api; | 437 | struct GNUNET_DATASTORE_PluginFunctions *api; |
456 | struct CpsRunContext *crc; | 438 | struct CpsRunContext *crc; |
@@ -490,12 +472,10 @@ check () | |||
490 | }; | 472 | }; |
491 | 473 | ||
492 | GNUNET_snprintf (category, sizeof (category), "DATASTORE-%s", plugin_name); | 474 | GNUNET_snprintf (category, sizeof (category), "DATASTORE-%s", plugin_name); |
493 | GNUNET_snprintf (cfg_name, | 475 | GNUNET_snprintf (cfg_name, sizeof (cfg_name), |
494 | sizeof (cfg_name), | ||
495 | "perf_plugin_datastore_data_%s.conf", plugin_name); | 476 | "perf_plugin_datastore_data_%s.conf", plugin_name); |
496 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 477 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, |
497 | argv, "perf-plugin-datastore", "nohelp", | 478 | "perf-plugin-datastore", "nohelp", options, &run, NULL); |
498 | options, &run, NULL); | ||
499 | if (ok != 0) | 479 | if (ok != 0) |
500 | fprintf (stderr, "Missed some testcases: %u\n", ok); | 480 | fprintf (stderr, "Missed some testcases: %u\n", ok); |
501 | return ok; | 481 | return ok; |
@@ -519,9 +499,8 @@ main (int argc, char *argv[]) | |||
519 | else | 499 | else |
520 | pos = (char *) plugin_name; | 500 | pos = (char *) plugin_name; |
521 | 501 | ||
522 | GNUNET_snprintf (dir_name, | 502 | GNUNET_snprintf (dir_name, sizeof (dir_name), "/tmp/perf-gnunet-datastore-%s", |
523 | sizeof (dir_name), | 503 | plugin_name); |
524 | "/tmp/perf-gnunet-datastore-%s", plugin_name); | ||
525 | GNUNET_DISK_directory_remove (dir_name); | 504 | GNUNET_DISK_directory_remove (dir_name); |
526 | GNUNET_log_setup ("perf-plugin-datastore", | 505 | GNUNET_log_setup ("perf-plugin-datastore", |
527 | #if VERBOSE | 506 | #if VERBOSE |
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c index a9b039981..63b065b0c 100644 --- a/src/datastore/plugin_datastore_mysql.c +++ b/src/datastore/plugin_datastore_mysql.c | |||
@@ -314,8 +314,8 @@ get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
314 | 314 | ||
315 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 315 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
316 | _("Trying to use file `%s' for MySQL configuration.\n"), cnffile); | 316 | _("Trying to use file `%s' for MySQL configuration.\n"), cnffile); |
317 | if ((0 != STAT (cnffile, &st)) || | 317 | if ((0 != STAT (cnffile, &st)) || (0 != ACCESS (cnffile, R_OK)) || |
318 | (0 != ACCESS (cnffile, R_OK)) || (!S_ISREG (st.st_mode))) | 318 | (!S_ISREG (st.st_mode))) |
319 | { | 319 | { |
320 | if (configured == GNUNET_YES) | 320 | if (configured == GNUNET_YES) |
321 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 321 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -383,16 +383,16 @@ iopen (struct Plugin *plugin) | |||
383 | reconnect = 0; | 383 | reconnect = 0; |
384 | mysql_options (plugin->dbf, MYSQL_OPT_RECONNECT, &reconnect); | 384 | mysql_options (plugin->dbf, MYSQL_OPT_RECONNECT, &reconnect); |
385 | timeout = 120; /* in seconds */ | 385 | timeout = 120; /* in seconds */ |
386 | mysql_options (plugin->dbf, | 386 | mysql_options (plugin->dbf, MYSQL_OPT_CONNECT_TIMEOUT, |
387 | MYSQL_OPT_CONNECT_TIMEOUT, (const void *) &timeout); | 387 | (const void *) &timeout); |
388 | mysql_options (plugin->dbf, MYSQL_SET_CHARSET_NAME, "UTF8"); | 388 | mysql_options (plugin->dbf, MYSQL_SET_CHARSET_NAME, "UTF8"); |
389 | timeout = 60; /* in seconds */ | 389 | timeout = 60; /* in seconds */ |
390 | mysql_options (plugin->dbf, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout); | 390 | mysql_options (plugin->dbf, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout); |
391 | mysql_options (plugin->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout); | 391 | mysql_options (plugin->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout); |
392 | mysql_dbname = NULL; | 392 | mysql_dbname = NULL; |
393 | if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg, | 393 | if (GNUNET_YES == |
394 | "datastore-mysql", | 394 | GNUNET_CONFIGURATION_have_value (plugin->env->cfg, "datastore-mysql", |
395 | "DATABASE")) | 395 | "DATABASE")) |
396 | GNUNET_assert (GNUNET_OK == | 396 | GNUNET_assert (GNUNET_OK == |
397 | GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, | 397 | GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, |
398 | "datastore-mysql", | 398 | "datastore-mysql", |
@@ -401,8 +401,9 @@ iopen (struct Plugin *plugin) | |||
401 | else | 401 | else |
402 | mysql_dbname = GNUNET_strdup ("gnunet"); | 402 | mysql_dbname = GNUNET_strdup ("gnunet"); |
403 | mysql_user = NULL; | 403 | mysql_user = NULL; |
404 | if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg, | 404 | if (GNUNET_YES == |
405 | "datastore-mysql", "USER")) | 405 | GNUNET_CONFIGURATION_have_value (plugin->env->cfg, "datastore-mysql", |
406 | "USER")) | ||
406 | { | 407 | { |
407 | GNUNET_assert (GNUNET_OK == | 408 | GNUNET_assert (GNUNET_OK == |
408 | GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, | 409 | GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, |
@@ -410,9 +411,9 @@ iopen (struct Plugin *plugin) | |||
410 | "USER", &mysql_user)); | 411 | "USER", &mysql_user)); |
411 | } | 412 | } |
412 | mysql_password = NULL; | 413 | mysql_password = NULL; |
413 | if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg, | 414 | if (GNUNET_YES == |
414 | "datastore-mysql", | 415 | GNUNET_CONFIGURATION_have_value (plugin->env->cfg, "datastore-mysql", |
415 | "PASSWORD")) | 416 | "PASSWORD")) |
416 | { | 417 | { |
417 | GNUNET_assert (GNUNET_OK == | 418 | GNUNET_assert (GNUNET_OK == |
418 | GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, | 419 | GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, |
@@ -421,8 +422,9 @@ iopen (struct Plugin *plugin) | |||
421 | &mysql_password)); | 422 | &mysql_password)); |
422 | } | 423 | } |
423 | mysql_server = NULL; | 424 | mysql_server = NULL; |
424 | if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg, | 425 | if (GNUNET_YES == |
425 | "datastore-mysql", "HOST")) | 426 | GNUNET_CONFIGURATION_have_value (plugin->env->cfg, "datastore-mysql", |
427 | "HOST")) | ||
426 | { | 428 | { |
427 | GNUNET_assert (GNUNET_OK == | 429 | GNUNET_assert (GNUNET_OK == |
428 | GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, | 430 | GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, |
@@ -431,8 +433,9 @@ iopen (struct Plugin *plugin) | |||
431 | &mysql_server)); | 433 | &mysql_server)); |
432 | } | 434 | } |
433 | mysql_port = 0; | 435 | mysql_port = 0; |
434 | if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg, | 436 | if (GNUNET_YES == |
435 | "datastore-mysql", "PORT")) | 437 | GNUNET_CONFIGURATION_have_value (plugin->env->cfg, "datastore-mysql", |
438 | "PORT")) | ||
436 | { | 439 | { |
437 | GNUNET_assert (GNUNET_OK == | 440 | GNUNET_assert (GNUNET_OK == |
438 | GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, | 441 | GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, |
@@ -441,11 +444,9 @@ iopen (struct Plugin *plugin) | |||
441 | } | 444 | } |
442 | 445 | ||
443 | GNUNET_assert (mysql_dbname != NULL); | 446 | GNUNET_assert (mysql_dbname != NULL); |
444 | mysql_real_connect (plugin->dbf, | 447 | mysql_real_connect (plugin->dbf, mysql_server, mysql_user, mysql_password, |
445 | mysql_server, | 448 | mysql_dbname, (unsigned int) mysql_port, NULL, |
446 | mysql_user, mysql_password, | 449 | CLIENT_IGNORE_SIGPIPE); |
447 | mysql_dbname, | ||
448 | (unsigned int) mysql_port, NULL, CLIENT_IGNORE_SIGPIPE); | ||
449 | GNUNET_free_non_null (mysql_server); | 450 | GNUNET_free_non_null (mysql_server); |
450 | GNUNET_free_non_null (mysql_user); | 451 | GNUNET_free_non_null (mysql_user); |
451 | GNUNET_free_non_null (mysql_password); | 452 | GNUNET_free_non_null (mysql_password); |
@@ -524,8 +525,7 @@ prepare_statement (struct Plugin *plugin, | |||
524 | } | 525 | } |
525 | if (mysql_stmt_prepare (ret->statement, ret->query, strlen (ret->query))) | 526 | if (mysql_stmt_prepare (ret->statement, ret->query, strlen (ret->query))) |
526 | { | 527 | { |
527 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 528 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", |
528 | "mysql", | ||
529 | _("Failed to prepare statement `%s'\n"), ret->query); | 529 | _("Failed to prepare statement `%s'\n"), ret->query); |
530 | LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_stmt_prepare", plugin); | 530 | LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_stmt_prepare", plugin); |
531 | mysql_stmt_close (ret->statement); | 531 | mysql_stmt_close (ret->statement); |
@@ -549,8 +549,8 @@ prepare_statement (struct Plugin *plugin, | |||
549 | * @return GNUNET_SYSERR on error, GNUNET_OK on success | 549 | * @return GNUNET_SYSERR on error, GNUNET_OK on success |
550 | */ | 550 | */ |
551 | static int | 551 | static int |
552 | init_params (struct Plugin *plugin, | 552 | init_params (struct Plugin *plugin, struct GNUNET_MysqlStatementHandle *s, |
553 | struct GNUNET_MysqlStatementHandle *s, va_list ap) | 553 | va_list ap) |
554 | { | 554 | { |
555 | MYSQL_BIND qbind[MAX_PARAM]; | 555 | MYSQL_BIND qbind[MAX_PARAM]; |
556 | unsigned int pc; | 556 | unsigned int pc; |
@@ -611,8 +611,8 @@ init_params (struct Plugin *plugin, | |||
611 | { | 611 | { |
612 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 612 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
613 | _("`%s' failed at %s:%d with error: %s\n"), | 613 | _("`%s' failed at %s:%d with error: %s\n"), |
614 | "mysql_stmt_bind_param", | 614 | "mysql_stmt_bind_param", __FILE__, __LINE__, |
615 | __FILE__, __LINE__, mysql_stmt_error (s->statement)); | 615 | mysql_stmt_error (s->statement)); |
616 | iclose (plugin); | 616 | iclose (plugin); |
617 | return GNUNET_SYSERR; | 617 | return GNUNET_SYSERR; |
618 | } | 618 | } |
@@ -620,8 +620,8 @@ init_params (struct Plugin *plugin, | |||
620 | { | 620 | { |
621 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 621 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
622 | _("`%s' for `%s' failed at %s:%d with error: %s\n"), | 622 | _("`%s' for `%s' failed at %s:%d with error: %s\n"), |
623 | "mysql_stmt_execute", | 623 | "mysql_stmt_execute", s->query, __FILE__, __LINE__, |
624 | s->query, __FILE__, __LINE__, mysql_stmt_error (s->statement)); | 624 | mysql_stmt_error (s->statement)); |
625 | iclose (plugin); | 625 | iclose (plugin); |
626 | return GNUNET_SYSERR; | 626 | return GNUNET_SYSERR; |
627 | } | 627 | } |
@@ -671,8 +671,8 @@ prepared_statement_run_select_va (struct Plugin *plugin, | |||
671 | { | 671 | { |
672 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 672 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
673 | _("`%s' failed at %s:%d with error: %s\n"), | 673 | _("`%s' failed at %s:%d with error: %s\n"), |
674 | "mysql_stmt_bind_result", | 674 | "mysql_stmt_bind_result", __FILE__, __LINE__, |
675 | __FILE__, __LINE__, mysql_stmt_error (s->statement)); | 675 | mysql_stmt_error (s->statement)); |
676 | iclose (plugin); | 676 | iclose (plugin); |
677 | return GNUNET_SYSERR; | 677 | return GNUNET_SYSERR; |
678 | } | 678 | } |
@@ -682,8 +682,7 @@ prepared_statement_run_select_va (struct Plugin *plugin, | |||
682 | if (ret != 0) | 682 | if (ret != 0) |
683 | { | 683 | { |
684 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 684 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
685 | _("`%s' failed at %s:%d with error: %s\n"), | 685 | _("`%s' failed at %s:%d with error: %s\n"), "mysql_stmt_fetch", |
686 | "mysql_stmt_fetch", | ||
687 | __FILE__, __LINE__, mysql_stmt_error (s->statement)); | 686 | __FILE__, __LINE__, mysql_stmt_error (s->statement)); |
688 | iclose (plugin); | 687 | iclose (plugin); |
689 | return GNUNET_SYSERR; | 688 | return GNUNET_SYSERR; |
@@ -710,8 +709,8 @@ prepared_statement_run_select_va (struct Plugin *plugin, | |||
710 | static int | 709 | static int |
711 | prepared_statement_run_select (struct Plugin *plugin, | 710 | prepared_statement_run_select (struct Plugin *plugin, |
712 | struct GNUNET_MysqlStatementHandle *s, | 711 | struct GNUNET_MysqlStatementHandle *s, |
713 | unsigned int result_size, | 712 | unsigned int result_size, MYSQL_BIND * results, |
714 | MYSQL_BIND * results, ...) | 713 | ...) |
715 | { | 714 | { |
716 | va_list ap; | 715 | va_list ap; |
717 | int ret; | 716 | int ret; |
@@ -774,13 +773,12 @@ do_delete_entry (struct Plugin *plugin, unsigned long long uid) | |||
774 | int ret; | 773 | int ret; |
775 | 774 | ||
776 | #if DEBUG_MYSQL | 775 | #if DEBUG_MYSQL |
777 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 776 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting value %llu from gn090 table\n", |
778 | "Deleting value %llu from gn090 table\n", uid); | 777 | uid); |
779 | #endif | 778 | #endif |
780 | ret = prepared_statement_run (plugin, | 779 | ret = |
781 | plugin->delete_entry_by_uid, | 780 | prepared_statement_run (plugin, plugin->delete_entry_by_uid, NULL, |
782 | NULL, | 781 | MYSQL_TYPE_LONGLONG, &uid, GNUNET_YES, -1); |
783 | MYSQL_TYPE_LONGLONG, &uid, GNUNET_YES, -1); | ||
784 | if (ret >= 0) | 782 | if (ret >= 0) |
785 | return GNUNET_OK; | 783 | return GNUNET_OK; |
786 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 784 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -831,14 +829,9 @@ mysql_plugin_estimate_size (void *cls) | |||
831 | * @return GNUNET_OK on success | 829 | * @return GNUNET_OK on success |
832 | */ | 830 | */ |
833 | static int | 831 | static int |
834 | mysql_plugin_put (void *cls, | 832 | mysql_plugin_put (void *cls, const GNUNET_HashCode * key, uint32_t size, |
835 | const GNUNET_HashCode * key, | 833 | const void *data, enum GNUNET_BLOCK_Type type, |
836 | uint32_t size, | 834 | uint32_t priority, uint32_t anonymity, uint32_t replication, |
837 | const void *data, | ||
838 | enum GNUNET_BLOCK_Type type, | ||
839 | uint32_t priority, | ||
840 | uint32_t anonymity, | ||
841 | uint32_t replication, | ||
842 | struct GNUNET_TIME_Absolute expiration, char **msg) | 835 | struct GNUNET_TIME_Absolute expiration, char **msg) |
843 | { | 836 | { |
844 | struct Plugin *plugin = cls; | 837 | struct Plugin *plugin = cls; |
@@ -864,9 +857,7 @@ mysql_plugin_put (void *cls, | |||
864 | lsize = size; | 857 | lsize = size; |
865 | GNUNET_CRYPTO_hash (data, size, &vhash); | 858 | GNUNET_CRYPTO_hash (data, size, &vhash); |
866 | if (GNUNET_OK != | 859 | if (GNUNET_OK != |
867 | prepared_statement_run (plugin, | 860 | prepared_statement_run (plugin, plugin->insert_entry, NULL, |
868 | plugin->insert_entry, | ||
869 | NULL, | ||
870 | MYSQL_TYPE_LONG, &irepl, GNUNET_YES, | 861 | MYSQL_TYPE_LONG, &irepl, GNUNET_YES, |
871 | MYSQL_TYPE_LONG, &type, GNUNET_YES, | 862 | MYSQL_TYPE_LONG, &type, GNUNET_YES, |
872 | MYSQL_TYPE_LONG, &ipriority, GNUNET_YES, | 863 | MYSQL_TYPE_LONG, &ipriority, GNUNET_YES, |
@@ -912,9 +903,8 @@ mysql_plugin_put (void *cls, | |||
912 | * @return GNUNET_OK on success | 903 | * @return GNUNET_OK on success |
913 | */ | 904 | */ |
914 | static int | 905 | static int |
915 | mysql_plugin_update (void *cls, | 906 | mysql_plugin_update (void *cls, uint64_t uid, int delta, |
916 | uint64_t uid, | 907 | struct GNUNET_TIME_Absolute expire, char **msg) |
917 | int delta, struct GNUNET_TIME_Absolute expire, char **msg) | ||
918 | { | 908 | { |
919 | struct Plugin *plugin = cls; | 909 | struct Plugin *plugin = cls; |
920 | unsigned long long vkey = uid; | 910 | unsigned long long vkey = uid; |
@@ -926,17 +916,16 @@ mysql_plugin_update (void *cls, | |||
926 | "Updating value %llu adding %d to priority and maxing exp at %llu\n", | 916 | "Updating value %llu adding %d to priority and maxing exp at %llu\n", |
927 | vkey, delta, lexpire); | 917 | vkey, delta, lexpire); |
928 | #endif | 918 | #endif |
929 | ret = prepared_statement_run (plugin, | 919 | ret = |
930 | plugin->update_entry, | 920 | prepared_statement_run (plugin, plugin->update_entry, NULL, |
931 | NULL, | 921 | MYSQL_TYPE_LONG, &delta, GNUNET_NO, |
932 | MYSQL_TYPE_LONG, &delta, GNUNET_NO, | 922 | MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES, |
933 | MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES, | 923 | MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES, |
934 | MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES, | 924 | MYSQL_TYPE_LONGLONG, &vkey, GNUNET_YES, -1); |
935 | MYSQL_TYPE_LONGLONG, &vkey, GNUNET_YES, -1); | ||
936 | if (ret != GNUNET_OK) | 925 | if (ret != GNUNET_OK) |
937 | { | 926 | { |
938 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 927 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to update value %llu\n", |
939 | "Failed to update value %llu\n", vkey); | 928 | vkey); |
940 | } | 929 | } |
941 | return ret; | 930 | return ret; |
942 | } | 931 | } |
@@ -953,8 +942,7 @@ mysql_plugin_update (void *cls, | |||
953 | * @param ... arguments to initialize stmt | 942 | * @param ... arguments to initialize stmt |
954 | */ | 943 | */ |
955 | static void | 944 | static void |
956 | execute_select (struct Plugin *plugin, | 945 | execute_select (struct Plugin *plugin, struct GNUNET_MysqlStatementHandle *stmt, |
957 | struct GNUNET_MysqlStatementHandle *stmt, | ||
958 | PluginDatumProcessor proc, void *proc_cls, ...) | 946 | PluginDatumProcessor proc, void *proc_cls, ...) |
959 | { | 947 | { |
960 | va_list ap; | 948 | va_list ap; |
@@ -1020,8 +1008,9 @@ execute_select (struct Plugin *plugin, | |||
1020 | #endif | 1008 | #endif |
1021 | GNUNET_assert (size < MAX_DATUM_SIZE); | 1009 | GNUNET_assert (size < MAX_DATUM_SIZE); |
1022 | expiration.abs_value = exp; | 1010 | expiration.abs_value = exp; |
1023 | ret = proc (proc_cls, | 1011 | ret = |
1024 | &key, size, value, type, priority, anonymity, expiration, uid); | 1012 | proc (proc_cls, &key, size, value, type, priority, anonymity, expiration, |
1013 | uid); | ||
1025 | if (ret == GNUNET_NO) | 1014 | if (ret == GNUNET_NO) |
1026 | { | 1015 | { |
1027 | do_delete_entry (plugin, uid); | 1016 | do_delete_entry (plugin, uid); |
@@ -1051,12 +1040,10 @@ execute_select (struct Plugin *plugin, | |||
1051 | * @param proc_cls closure for proc | 1040 | * @param proc_cls closure for proc |
1052 | */ | 1041 | */ |
1053 | static void | 1042 | static void |
1054 | mysql_plugin_get_key (void *cls, | 1043 | mysql_plugin_get_key (void *cls, uint64_t offset, const GNUNET_HashCode * key, |
1055 | uint64_t offset, | ||
1056 | const GNUNET_HashCode * key, | ||
1057 | const GNUNET_HashCode * vhash, | 1044 | const GNUNET_HashCode * vhash, |
1058 | enum GNUNET_BLOCK_Type type, | 1045 | enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, |
1059 | PluginDatumProcessor proc, void *proc_cls) | 1046 | void *proc_cls) |
1060 | { | 1047 | { |
1061 | struct Plugin *plugin = cls; | 1048 | struct Plugin *plugin = cls; |
1062 | int ret; | 1049 | int ret; |
@@ -1081,22 +1068,21 @@ mysql_plugin_get_key (void *cls, | |||
1081 | { | 1068 | { |
1082 | ret = | 1069 | ret = |
1083 | prepared_statement_run_select (plugin, | 1070 | prepared_statement_run_select (plugin, |
1084 | plugin-> | 1071 | plugin->count_entry_by_hash_vhash_and_type, |
1085 | count_entry_by_hash_vhash_and_type, 1, | 1072 | 1, cbind, MYSQL_TYPE_BLOB, key, |
1086 | cbind, MYSQL_TYPE_BLOB, key, hashSize, | 1073 | hashSize, &hashSize, MYSQL_TYPE_BLOB, |
1087 | &hashSize, MYSQL_TYPE_BLOB, vhash, | 1074 | vhash, hashSize2, &hashSize2, |
1088 | hashSize2, &hashSize2, MYSQL_TYPE_LONG, | 1075 | MYSQL_TYPE_LONG, &type, GNUNET_YES, |
1089 | &type, GNUNET_YES, -1); | 1076 | -1); |
1090 | } | 1077 | } |
1091 | else | 1078 | else |
1092 | { | 1079 | { |
1093 | ret = | 1080 | ret = |
1094 | prepared_statement_run_select (plugin, | 1081 | prepared_statement_run_select (plugin, |
1095 | plugin->count_entry_by_hash_and_type, | 1082 | plugin->count_entry_by_hash_and_type, |
1096 | 1, cbind, | 1083 | 1, cbind, MYSQL_TYPE_BLOB, key, |
1097 | MYSQL_TYPE_BLOB, key, hashSize, | 1084 | hashSize, &hashSize, MYSQL_TYPE_LONG, |
1098 | &hashSize, MYSQL_TYPE_LONG, &type, | 1085 | &type, GNUNET_YES, -1); |
1099 | GNUNET_YES, -1); | ||
1100 | } | 1086 | } |
1101 | } | 1087 | } |
1102 | else | 1088 | else |
@@ -1106,19 +1092,16 @@ mysql_plugin_get_key (void *cls, | |||
1106 | ret = | 1092 | ret = |
1107 | prepared_statement_run_select (plugin, | 1093 | prepared_statement_run_select (plugin, |
1108 | plugin->count_entry_by_hash_and_vhash, | 1094 | plugin->count_entry_by_hash_and_vhash, |
1109 | 1, cbind, | 1095 | 1, cbind, MYSQL_TYPE_BLOB, key, |
1110 | MYSQL_TYPE_BLOB, key, hashSize, | 1096 | hashSize, &hashSize, MYSQL_TYPE_BLOB, |
1111 | &hashSize, MYSQL_TYPE_BLOB, vhash, | 1097 | vhash, hashSize2, &hashSize2, -1); |
1112 | hashSize2, &hashSize2, -1); | ||
1113 | 1098 | ||
1114 | } | 1099 | } |
1115 | else | 1100 | else |
1116 | { | 1101 | { |
1117 | ret = | 1102 | ret = |
1118 | prepared_statement_run_select (plugin, | 1103 | prepared_statement_run_select (plugin, plugin->count_entry_by_hash, 1, |
1119 | plugin->count_entry_by_hash, | 1104 | cbind, MYSQL_TYPE_BLOB, key, hashSize, |
1120 | 1, cbind, | ||
1121 | MYSQL_TYPE_BLOB, key, hashSize, | ||
1122 | &hashSize, -1); | 1105 | &hashSize, -1); |
1123 | } | 1106 | } |
1124 | } | 1107 | } |
@@ -1131,48 +1114,40 @@ mysql_plugin_get_key (void *cls, | |||
1131 | off = (unsigned long long) offset; | 1114 | off = (unsigned long long) offset; |
1132 | #if DEBUG_MYSQL | 1115 | #if DEBUG_MYSQL |
1133 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1116 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1134 | "Obtaining %llu/%lld result for GET `%s'\n", | 1117 | "Obtaining %llu/%lld result for GET `%s'\n", off, total, |
1135 | off, total, GNUNET_h2s (key)); | 1118 | GNUNET_h2s (key)); |
1136 | #endif | 1119 | #endif |
1137 | 1120 | ||
1138 | if (type != GNUNET_BLOCK_TYPE_ANY) | 1121 | if (type != GNUNET_BLOCK_TYPE_ANY) |
1139 | { | 1122 | { |
1140 | if (NULL != vhash) | 1123 | if (NULL != vhash) |
1141 | { | 1124 | { |
1142 | execute_select (plugin, | 1125 | execute_select (plugin, plugin->select_entry_by_hash_vhash_and_type, proc, |
1143 | plugin->select_entry_by_hash_vhash_and_type, | 1126 | proc_cls, MYSQL_TYPE_BLOB, key, hashSize, &hashSize, |
1144 | proc, proc_cls, | ||
1145 | MYSQL_TYPE_BLOB, key, hashSize, &hashSize, | ||
1146 | MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize, | 1127 | MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize, |
1147 | MYSQL_TYPE_LONG, &type, GNUNET_YES, | 1128 | MYSQL_TYPE_LONG, &type, GNUNET_YES, MYSQL_TYPE_LONGLONG, |
1148 | MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1); | 1129 | &off, GNUNET_YES, -1); |
1149 | } | 1130 | } |
1150 | else | 1131 | else |
1151 | { | 1132 | { |
1152 | execute_select (plugin, | 1133 | execute_select (plugin, plugin->select_entry_by_hash_and_type, proc, |
1153 | plugin->select_entry_by_hash_and_type, | 1134 | proc_cls, MYSQL_TYPE_BLOB, key, hashSize, &hashSize, |
1154 | proc, proc_cls, | 1135 | MYSQL_TYPE_LONG, &type, GNUNET_YES, MYSQL_TYPE_LONGLONG, |
1155 | MYSQL_TYPE_BLOB, key, hashSize, &hashSize, | 1136 | &off, GNUNET_YES, -1); |
1156 | MYSQL_TYPE_LONG, &type, GNUNET_YES, | ||
1157 | MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1); | ||
1158 | } | 1137 | } |
1159 | } | 1138 | } |
1160 | else | 1139 | else |
1161 | { | 1140 | { |
1162 | if (NULL != vhash) | 1141 | if (NULL != vhash) |
1163 | { | 1142 | { |
1164 | execute_select (plugin, | 1143 | execute_select (plugin, plugin->select_entry_by_hash_and_vhash, proc, |
1165 | plugin->select_entry_by_hash_and_vhash, | 1144 | proc_cls, MYSQL_TYPE_BLOB, key, hashSize, &hashSize, |
1166 | proc, proc_cls, | ||
1167 | MYSQL_TYPE_BLOB, key, hashSize, &hashSize, | ||
1168 | MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize, | 1145 | MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize, |
1169 | MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1); | 1146 | MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1); |
1170 | } | 1147 | } |
1171 | else | 1148 | else |
1172 | { | 1149 | { |
1173 | execute_select (plugin, | 1150 | execute_select (plugin, plugin->select_entry_by_hash, proc, proc_cls, |
1174 | plugin->select_entry_by_hash, | ||
1175 | proc, proc_cls, | ||
1176 | MYSQL_TYPE_BLOB, key, hashSize, &hashSize, | 1151 | MYSQL_TYPE_BLOB, key, hashSize, &hashSize, |
1177 | MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1); | 1152 | MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1); |
1178 | } | 1153 | } |
@@ -1191,8 +1166,7 @@ mysql_plugin_get_key (void *cls, | |||
1191 | * @param proc_cls closure for iter | 1166 | * @param proc_cls closure for iter |
1192 | */ | 1167 | */ |
1193 | static void | 1168 | static void |
1194 | mysql_plugin_get_zero_anonymity (void *cls, | 1169 | mysql_plugin_get_zero_anonymity (void *cls, uint64_t offset, |
1195 | uint64_t offset, | ||
1196 | enum GNUNET_BLOCK_Type type, | 1170 | enum GNUNET_BLOCK_Type type, |
1197 | PluginDatumProcessor proc, void *proc_cls) | 1171 | PluginDatumProcessor proc, void *proc_cls) |
1198 | { | 1172 | { |
@@ -1201,13 +1175,10 @@ mysql_plugin_get_zero_anonymity (void *cls, | |||
1201 | (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 1175 | (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
1202 | UINT64_MAX); | 1176 | UINT64_MAX); |
1203 | 1177 | ||
1204 | execute_select (plugin, | 1178 | execute_select (plugin, plugin->zero_iter, proc, proc_cls, MYSQL_TYPE_LONG, |
1205 | plugin->zero_iter, | 1179 | &type, GNUNET_YES, MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES, |
1206 | proc, proc_cls, | 1180 | MYSQL_TYPE_LONG, &type, GNUNET_YES, MYSQL_TYPE_LONGLONG, |
1207 | MYSQL_TYPE_LONG, &type, GNUNET_YES, | 1181 | &rvalue, GNUNET_YES, -1); |
1208 | MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES, | ||
1209 | MYSQL_TYPE_LONG, &type, GNUNET_YES, | ||
1210 | MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES, -1); | ||
1211 | } | 1182 | } |
1212 | 1183 | ||
1213 | 1184 | ||
@@ -1255,14 +1226,10 @@ struct ReplCtx | |||
1255 | * GNUNET_NO to delete the item and continue (if supported) | 1226 | * GNUNET_NO to delete the item and continue (if supported) |
1256 | */ | 1227 | */ |
1257 | static int | 1228 | static int |
1258 | repl_proc (void *cls, | 1229 | repl_proc (void *cls, const GNUNET_HashCode * key, uint32_t size, |
1259 | const GNUNET_HashCode * key, | 1230 | const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, |
1260 | uint32_t size, | 1231 | uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, |
1261 | const void *data, | 1232 | uint64_t uid) |
1262 | enum GNUNET_BLOCK_Type type, | ||
1263 | uint32_t priority, | ||
1264 | uint32_t anonymity, | ||
1265 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | ||
1266 | { | 1233 | { |
1267 | struct ReplCtx *rc = cls; | 1234 | struct ReplCtx *rc = cls; |
1268 | struct Plugin *plugin = rc->plugin; | 1235 | struct Plugin *plugin = rc->plugin; |
@@ -1270,15 +1237,15 @@ repl_proc (void *cls, | |||
1270 | int ret; | 1237 | int ret; |
1271 | int iret; | 1238 | int iret; |
1272 | 1239 | ||
1273 | ret = rc->proc (rc->proc_cls, | 1240 | ret = |
1274 | key, size, data, type, priority, anonymity, expiration, uid); | 1241 | rc->proc (rc->proc_cls, key, size, data, type, priority, anonymity, |
1242 | expiration, uid); | ||
1275 | if (NULL != key) | 1243 | if (NULL != key) |
1276 | { | 1244 | { |
1277 | oid = (unsigned long long) uid; | 1245 | oid = (unsigned long long) uid; |
1278 | iret = prepared_statement_run (plugin, | 1246 | iret = |
1279 | plugin->dec_repl, | 1247 | prepared_statement_run (plugin, plugin->dec_repl, NULL, |
1280 | NULL, | 1248 | MYSQL_TYPE_LONGLONG, &oid, GNUNET_YES, -1); |
1281 | MYSQL_TYPE_LONGLONG, &oid, GNUNET_YES, -1); | ||
1282 | if (iret == GNUNET_SYSERR) | 1249 | if (iret == GNUNET_SYSERR) |
1283 | { | 1250 | { |
1284 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1251 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -1302,8 +1269,8 @@ repl_proc (void *cls, | |||
1302 | * @param proc_cls closure for proc | 1269 | * @param proc_cls closure for proc |
1303 | */ | 1270 | */ |
1304 | static void | 1271 | static void |
1305 | mysql_plugin_get_replication (void *cls, | 1272 | mysql_plugin_get_replication (void *cls, PluginDatumProcessor proc, |
1306 | PluginDatumProcessor proc, void *proc_cls) | 1273 | void *proc_cls) |
1307 | { | 1274 | { |
1308 | struct Plugin *plugin = cls; | 1275 | struct Plugin *plugin = cls; |
1309 | struct ReplCtx rc; | 1276 | struct ReplCtx rc; |
@@ -1382,26 +1349,22 @@ struct ExpiCtx | |||
1382 | * GNUNET_NO to delete the item and continue (if supported) | 1349 | * GNUNET_NO to delete the item and continue (if supported) |
1383 | */ | 1350 | */ |
1384 | static int | 1351 | static int |
1385 | expi_proc (void *cls, | 1352 | expi_proc (void *cls, const GNUNET_HashCode * key, uint32_t size, |
1386 | const GNUNET_HashCode * key, | 1353 | const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, |
1387 | uint32_t size, | 1354 | uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, |
1388 | const void *data, | 1355 | uint64_t uid) |
1389 | enum GNUNET_BLOCK_Type type, | ||
1390 | uint32_t priority, | ||
1391 | uint32_t anonymity, | ||
1392 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | ||
1393 | { | 1356 | { |
1394 | struct ExpiCtx *rc = cls; | 1357 | struct ExpiCtx *rc = cls; |
1395 | struct Plugin *plugin = rc->plugin; | 1358 | struct Plugin *plugin = rc->plugin; |
1396 | 1359 | ||
1397 | if (NULL == key) | 1360 | if (NULL == key) |
1398 | { | 1361 | { |
1399 | execute_select (plugin, | 1362 | execute_select (plugin, plugin->select_priority, rc->proc, rc->proc_cls, |
1400 | plugin->select_priority, rc->proc, rc->proc_cls, -1); | 1363 | -1); |
1401 | return GNUNET_SYSERR; | 1364 | return GNUNET_SYSERR; |
1402 | } | 1365 | } |
1403 | return rc->proc (rc->proc_cls, | 1366 | return rc->proc (rc->proc_cls, key, size, data, type, priority, anonymity, |
1404 | key, size, data, type, priority, anonymity, expiration, uid); | 1367 | expiration, uid); |
1405 | } | 1368 | } |
1406 | 1369 | ||
1407 | 1370 | ||
@@ -1414,8 +1377,8 @@ expi_proc (void *cls, | |||
1414 | * @param proc_cls closure for proc | 1377 | * @param proc_cls closure for proc |
1415 | */ | 1378 | */ |
1416 | static void | 1379 | static void |
1417 | mysql_plugin_get_expiration (void *cls, | 1380 | mysql_plugin_get_expiration (void *cls, PluginDatumProcessor proc, |
1418 | PluginDatumProcessor proc, void *proc_cls) | 1381 | void *proc_cls) |
1419 | { | 1382 | { |
1420 | struct Plugin *plugin = cls; | 1383 | struct Plugin *plugin = cls; |
1421 | long long nt; | 1384 | long long nt; |
@@ -1425,9 +1388,8 @@ mysql_plugin_get_expiration (void *cls, | |||
1425 | rc.proc = proc; | 1388 | rc.proc = proc; |
1426 | rc.proc_cls = proc_cls; | 1389 | rc.proc_cls = proc_cls; |
1427 | nt = (long long) GNUNET_TIME_absolute_get ().abs_value; | 1390 | nt = (long long) GNUNET_TIME_absolute_get ().abs_value; |
1428 | execute_select (plugin, | 1391 | execute_select (plugin, plugin->select_expiration, expi_proc, &rc, |
1429 | plugin->select_expiration, | 1392 | MYSQL_TYPE_LONGLONG, &nt, GNUNET_YES, -1); |
1430 | expi_proc, &rc, MYSQL_TYPE_LONGLONG, &nt, GNUNET_YES, -1); | ||
1431 | 1393 | ||
1432 | } | 1394 | } |
1433 | 1395 | ||
@@ -1473,28 +1435,25 @@ libgnunet_plugin_datastore_mysql_init (void *cls) | |||
1473 | } | 1435 | } |
1474 | #define MRUNS(a) (GNUNET_OK != run_statement (plugin, a) ) | 1436 | #define MRUNS(a) (GNUNET_OK != run_statement (plugin, a) ) |
1475 | #define PINIT(a,b) (NULL == (a = prepared_statement_create(plugin, b))) | 1437 | #define PINIT(a,b) (NULL == (a = prepared_statement_create(plugin, b))) |
1476 | if (MRUNS ("CREATE TABLE IF NOT EXISTS gn090 (" | 1438 | if (MRUNS |
1477 | " repl INT(11) UNSIGNED NOT NULL DEFAULT 0," | 1439 | ("CREATE TABLE IF NOT EXISTS gn090 (" |
1478 | " type INT(11) UNSIGNED NOT NULL DEFAULT 0," | 1440 | " repl INT(11) UNSIGNED NOT NULL DEFAULT 0," |
1479 | " prio INT(11) UNSIGNED NOT NULL DEFAULT 0," | 1441 | " type INT(11) UNSIGNED NOT NULL DEFAULT 0," |
1480 | " anonLevel INT(11) UNSIGNED NOT NULL DEFAULT 0," | 1442 | " prio INT(11) UNSIGNED NOT NULL DEFAULT 0," |
1481 | " expire BIGINT UNSIGNED NOT NULL DEFAULT 0," | 1443 | " anonLevel INT(11) UNSIGNED NOT NULL DEFAULT 0," |
1482 | " rvalue BIGINT UNSIGNED NOT NULL," | 1444 | " expire BIGINT UNSIGNED NOT NULL DEFAULT 0," |
1483 | " hash BINARY(64) NOT NULL DEFAULT ''," | 1445 | " rvalue BIGINT UNSIGNED NOT NULL," |
1484 | " vhash BINARY(64) NOT NULL DEFAULT ''," | 1446 | " hash BINARY(64) NOT NULL DEFAULT ''," |
1485 | " value BLOB NOT NULL DEFAULT ''," | 1447 | " vhash BINARY(64) NOT NULL DEFAULT ''," |
1486 | " uid BIGINT NOT NULL AUTO_INCREMENT," | 1448 | " value BLOB NOT NULL DEFAULT ''," " uid BIGINT NOT NULL AUTO_INCREMENT," |
1487 | " PRIMARY KEY (uid)," | 1449 | " PRIMARY KEY (uid)," " INDEX idx_hash (hash(64))," |
1488 | " INDEX idx_hash (hash(64))," | 1450 | " INDEX idx_hash_uid (hash(64),uid)," |
1489 | " INDEX idx_hash_uid (hash(64),uid)," | 1451 | " INDEX idx_hash_vhash (hash(64),vhash(64))," |
1490 | " INDEX idx_hash_vhash (hash(64),vhash(64))," | 1452 | " INDEX idx_hash_type_uid (hash(64),type,rvalue)," |
1491 | " INDEX idx_hash_type_uid (hash(64),type,rvalue)," | 1453 | " INDEX idx_prio (prio)," " INDEX idx_repl_rvalue (repl,rvalue)," |
1492 | " INDEX idx_prio (prio)," | 1454 | " INDEX idx_expire (expire)," |
1493 | " INDEX idx_repl_rvalue (repl,rvalue)," | 1455 | " INDEX idx_anonLevel_type_rvalue (anonLevel,type,rvalue)" |
1494 | " INDEX idx_expire (expire)," | 1456 | ") ENGINE=InnoDB") || MRUNS ("SET AUTOCOMMIT = 1") || |
1495 | " INDEX idx_anonLevel_type_rvalue (anonLevel,type,rvalue)" | ||
1496 | ") ENGINE=InnoDB") || | ||
1497 | MRUNS ("SET AUTOCOMMIT = 1") || | ||
1498 | PINIT (plugin->insert_entry, INSERT_ENTRY) || | 1457 | PINIT (plugin->insert_entry, INSERT_ENTRY) || |
1499 | PINIT (plugin->delete_entry_by_uid, DELETE_ENTRY_BY_UID) || | 1458 | PINIT (plugin->delete_entry_by_uid, DELETE_ENTRY_BY_UID) || |
1500 | PINIT (plugin->select_entry_by_hash, SELECT_ENTRY_BY_HASH) || | 1459 | PINIT (plugin->select_entry_by_hash, SELECT_ENTRY_BY_HASH) || |
@@ -1537,8 +1496,8 @@ libgnunet_plugin_datastore_mysql_init (void *cls) | |||
1537 | api->get_expiration = &mysql_plugin_get_expiration; | 1496 | api->get_expiration = &mysql_plugin_get_expiration; |
1538 | api->get_zero_anonymity = &mysql_plugin_get_zero_anonymity; | 1497 | api->get_zero_anonymity = &mysql_plugin_get_zero_anonymity; |
1539 | api->drop = &mysql_plugin_drop; | 1498 | api->drop = &mysql_plugin_drop; |
1540 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, | 1499 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "mysql", |
1541 | "mysql", _("Mysql database running\n")); | 1500 | _("Mysql database running\n")); |
1542 | return api; | 1501 | return api; |
1543 | } | 1502 | } |
1544 | 1503 | ||
diff --git a/src/datastore/plugin_datastore_postgres.c b/src/datastore/plugin_datastore_postgres.c index b79178dac..d71d5e0ef 100644 --- a/src/datastore/plugin_datastore_postgres.c +++ b/src/datastore/plugin_datastore_postgres.c | |||
@@ -75,9 +75,7 @@ struct Plugin | |||
75 | * @return GNUNET_OK if the result is acceptable | 75 | * @return GNUNET_OK if the result is acceptable |
76 | */ | 76 | */ |
77 | static int | 77 | static int |
78 | check_result (struct Plugin *plugin, | 78 | check_result (struct Plugin *plugin, PGresult * ret, int expected_status, |
79 | PGresult * ret, | ||
80 | int expected_status, | ||
81 | const char *command, const char *args, int line) | 79 | const char *command, const char *args, int line) |
82 | { | 80 | { |
83 | if (ret == NULL) | 81 | if (ret == NULL) |
@@ -92,9 +90,8 @@ check_result (struct Plugin *plugin, | |||
92 | { | 90 | { |
93 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 91 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
94 | "datastore-postgres", | 92 | "datastore-postgres", |
95 | _("`%s:%s' failed at %s:%d with error: %s"), | 93 | _("`%s:%s' failed at %s:%d with error: %s"), command, args, |
96 | command, args, __FILE__, line, | 94 | __FILE__, line, PQerrorMessage (plugin->dbh)); |
97 | PQerrorMessage (plugin->dbh)); | ||
98 | PQclear (ret); | 95 | PQclear (ret); |
99 | return GNUNET_SYSERR; | 96 | return GNUNET_SYSERR; |
100 | } | 97 | } |
@@ -114,8 +111,8 @@ pq_exec (struct Plugin *plugin, const char *sql, int line) | |||
114 | PGresult *ret; | 111 | PGresult *ret; |
115 | 112 | ||
116 | ret = PQexec (plugin->dbh, sql); | 113 | ret = PQexec (plugin->dbh, sql); |
117 | if (GNUNET_OK != check_result (plugin, | 114 | if (GNUNET_OK != |
118 | ret, PGRES_COMMAND_OK, "PQexec", sql, line)) | 115 | check_result (plugin, ret, PGRES_COMMAND_OK, "PQexec", sql, line)) |
119 | return GNUNET_SYSERR; | 116 | return GNUNET_SYSERR; |
120 | PQclear (ret); | 117 | PQclear (ret); |
121 | return GNUNET_OK; | 118 | return GNUNET_OK; |
@@ -132,8 +129,8 @@ pq_exec (struct Plugin *plugin, const char *sql, int line) | |||
132 | * @return GNUNET_OK on success | 129 | * @return GNUNET_OK on success |
133 | */ | 130 | */ |
134 | static int | 131 | static int |
135 | pq_prepare (struct Plugin *plugin, | 132 | pq_prepare (struct Plugin *plugin, const char *name, const char *sql, |
136 | const char *name, const char *sql, int nparams, int line) | 133 | int nparams, int line) |
137 | { | 134 | { |
138 | PGresult *ret; | 135 | PGresult *ret; |
139 | 136 | ||
@@ -160,8 +157,8 @@ init_connection (struct Plugin *plugin) | |||
160 | /* Open database and precompile statements */ | 157 | /* Open database and precompile statements */ |
161 | conninfo = NULL; | 158 | conninfo = NULL; |
162 | (void) GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, | 159 | (void) GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, |
163 | "datastore-postgres", | 160 | "datastore-postgres", "CONFIG", |
164 | "CONFIG", &conninfo); | 161 | &conninfo); |
165 | plugin->dbh = PQconnectdb (conninfo == NULL ? "" : conninfo); | 162 | plugin->dbh = PQconnectdb (conninfo == NULL ? "" : conninfo); |
166 | if (NULL == plugin->dbh) | 163 | if (NULL == plugin->dbh) |
167 | { | 164 | { |
@@ -171,8 +168,7 @@ init_connection (struct Plugin *plugin) | |||
171 | } | 168 | } |
172 | if (PQstatus (plugin->dbh) != CONNECTION_OK) | 169 | if (PQstatus (plugin->dbh) != CONNECTION_OK) |
173 | { | 170 | { |
174 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 171 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "datastore-postgres", |
175 | "datastore-postgres", | ||
176 | _ | 172 | _ |
177 | ("Unable to initialize Postgres with configuration `%s': %s"), | 173 | ("Unable to initialize Postgres with configuration `%s': %s"), |
178 | conninfo, PQerrorMessage (plugin->dbh)); | 174 | conninfo, PQerrorMessage (plugin->dbh)); |
@@ -182,24 +178,23 @@ init_connection (struct Plugin *plugin) | |||
182 | return GNUNET_SYSERR; | 178 | return GNUNET_SYSERR; |
183 | } | 179 | } |
184 | GNUNET_free_non_null (conninfo); | 180 | GNUNET_free_non_null (conninfo); |
185 | ret = PQexec (plugin->dbh, | 181 | ret = |
186 | "CREATE TABLE gn090 (" | 182 | PQexec (plugin->dbh, |
187 | " repl INTEGER NOT NULL DEFAULT 0," | 183 | "CREATE TABLE gn090 (" " repl INTEGER NOT NULL DEFAULT 0," |
188 | " type INTEGER NOT NULL DEFAULT 0," | 184 | " type INTEGER NOT NULL DEFAULT 0," |
189 | " prio INTEGER NOT NULL DEFAULT 0," | 185 | " prio INTEGER NOT NULL DEFAULT 0," |
190 | " anonLevel INTEGER NOT NULL DEFAULT 0," | 186 | " anonLevel INTEGER NOT NULL DEFAULT 0," |
191 | " expire BIGINT NOT NULL DEFAULT 0," | 187 | " expire BIGINT NOT NULL DEFAULT 0," |
192 | " rvalue BIGINT NOT NULL DEFAULT 0," | 188 | " rvalue BIGINT NOT NULL DEFAULT 0," |
193 | " hash BYTEA NOT NULL DEFAULT ''," | 189 | " hash BYTEA NOT NULL DEFAULT ''," |
194 | " vhash BYTEA NOT NULL DEFAULT ''," | 190 | " vhash BYTEA NOT NULL DEFAULT ''," |
195 | " value BYTEA NOT NULL DEFAULT '')" "WITH OIDS"); | 191 | " value BYTEA NOT NULL DEFAULT '')" "WITH OIDS"); |
196 | if ((ret == NULL) || ((PQresultStatus (ret) != PGRES_COMMAND_OK) && (0 != strcmp ("42P07", /* duplicate table */ | 192 | if ((ret == NULL) || ((PQresultStatus (ret) != PGRES_COMMAND_OK) && (0 != strcmp ("42P07", /* duplicate table */ |
197 | PQresultErrorField | 193 | PQresultErrorField |
198 | (ret, | 194 | (ret, |
199 | PG_DIAG_SQLSTATE))))) | 195 | PG_DIAG_SQLSTATE))))) |
200 | { | 196 | { |
201 | (void) check_result (plugin, | 197 | (void) check_result (plugin, ret, PGRES_COMMAND_OK, "CREATE TABLE", "gn090", |
202 | ret, PGRES_COMMAND_OK, "CREATE TABLE", "gn090", | ||
203 | __LINE__); | 198 | __LINE__); |
204 | PQfinish (plugin->dbh); | 199 | PQfinish (plugin->dbh); |
205 | plugin->dbh = NULL; | 200 | plugin->dbh = NULL; |
@@ -211,12 +206,12 @@ init_connection (struct Plugin *plugin) | |||
211 | pq_exec (plugin, "CREATE INDEX idx_hash ON gn090 (hash)", __LINE__)) || | 206 | pq_exec (plugin, "CREATE INDEX idx_hash ON gn090 (hash)", __LINE__)) || |
212 | (GNUNET_OK != | 207 | (GNUNET_OK != |
213 | pq_exec (plugin, "CREATE INDEX idx_hash_vhash ON gn090 (hash,vhash)", | 208 | pq_exec (plugin, "CREATE INDEX idx_hash_vhash ON gn090 (hash,vhash)", |
214 | __LINE__)) | 209 | __LINE__)) || |
215 | || (GNUNET_OK != | 210 | (GNUNET_OK != |
216 | pq_exec (plugin, "CREATE INDEX idx_prio ON gn090 (prio)", __LINE__)) | 211 | pq_exec (plugin, "CREATE INDEX idx_prio ON gn090 (prio)", __LINE__)) || |
217 | || (GNUNET_OK != | 212 | (GNUNET_OK != |
218 | pq_exec (plugin, "CREATE INDEX idx_expire ON gn090 (expire)", | 213 | pq_exec (plugin, "CREATE INDEX idx_expire ON gn090 (expire)", |
219 | __LINE__)) || | 214 | __LINE__)) || |
220 | (GNUNET_OK != | 215 | (GNUNET_OK != |
221 | pq_exec (plugin, | 216 | pq_exec (plugin, |
222 | "CREATE INDEX idx_prio_anon ON gn090 (prio,anonLevel)", | 217 | "CREATE INDEX idx_prio_anon ON gn090 (prio,anonLevel)", |
@@ -239,11 +234,12 @@ init_connection (struct Plugin *plugin) | |||
239 | } | 234 | } |
240 | } | 235 | } |
241 | PQclear (ret); | 236 | PQclear (ret); |
242 | ret = PQexec (plugin->dbh, | 237 | ret = |
243 | "ALTER TABLE gn090 ALTER value SET STORAGE EXTERNAL"); | 238 | PQexec (plugin->dbh, |
239 | "ALTER TABLE gn090 ALTER value SET STORAGE EXTERNAL"); | ||
244 | if (GNUNET_OK != | 240 | if (GNUNET_OK != |
245 | check_result (plugin, | 241 | check_result (plugin, ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090", |
246 | ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090", __LINE__)) | 242 | __LINE__)) |
247 | { | 243 | { |
248 | PQfinish (plugin->dbh); | 244 | PQfinish (plugin->dbh); |
249 | plugin->dbh = NULL; | 245 | plugin->dbh = NULL; |
@@ -252,8 +248,8 @@ init_connection (struct Plugin *plugin) | |||
252 | PQclear (ret); | 248 | PQclear (ret); |
253 | ret = PQexec (plugin->dbh, "ALTER TABLE gn090 ALTER hash SET STORAGE PLAIN"); | 249 | ret = PQexec (plugin->dbh, "ALTER TABLE gn090 ALTER hash SET STORAGE PLAIN"); |
254 | if (GNUNET_OK != | 250 | if (GNUNET_OK != |
255 | check_result (plugin, | 251 | check_result (plugin, ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090", |
256 | ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090", __LINE__)) | 252 | __LINE__)) |
257 | { | 253 | { |
258 | PQfinish (plugin->dbh); | 254 | PQfinish (plugin->dbh); |
259 | plugin->dbh = NULL; | 255 | plugin->dbh = NULL; |
@@ -262,8 +258,8 @@ init_connection (struct Plugin *plugin) | |||
262 | PQclear (ret); | 258 | PQclear (ret); |
263 | ret = PQexec (plugin->dbh, "ALTER TABLE gn090 ALTER vhash SET STORAGE PLAIN"); | 259 | ret = PQexec (plugin->dbh, "ALTER TABLE gn090 ALTER vhash SET STORAGE PLAIN"); |
264 | if (GNUNET_OK != | 260 | if (GNUNET_OK != |
265 | check_result (plugin, | 261 | check_result (plugin, ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090", |
266 | ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090", __LINE__)) | 262 | __LINE__)) |
267 | { | 263 | { |
268 | PQfinish (plugin->dbh); | 264 | PQfinish (plugin->dbh); |
269 | plugin->dbh = NULL; | 265 | plugin->dbh = NULL; |
@@ -271,86 +267,57 @@ init_connection (struct Plugin *plugin) | |||
271 | } | 267 | } |
272 | PQclear (ret); | 268 | PQclear (ret); |
273 | if ((GNUNET_OK != | 269 | if ((GNUNET_OK != |
274 | pq_prepare (plugin, | 270 | pq_prepare (plugin, "getvt", |
275 | "getvt", | ||
276 | "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " | 271 | "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " |
277 | "WHERE hash=$1 AND vhash=$2 AND type=$3 " | 272 | "WHERE hash=$1 AND vhash=$2 AND type=$3 " |
278 | "ORDER BY oid ASC LIMIT 1 OFFSET $4", | 273 | "ORDER BY oid ASC LIMIT 1 OFFSET $4", 4, __LINE__)) || |
279 | 4, | ||
280 | __LINE__)) || | ||
281 | (GNUNET_OK != | 274 | (GNUNET_OK != |
282 | pq_prepare (plugin, | 275 | pq_prepare (plugin, "gett", |
283 | "gett", | ||
284 | "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " | 276 | "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " |
285 | "WHERE hash=$1 AND type=$2 " | 277 | "WHERE hash=$1 AND type=$2 " |
286 | "ORDER BY oid ASC LIMIT 1 OFFSET $3", | 278 | "ORDER BY oid ASC LIMIT 1 OFFSET $3", 3, __LINE__)) || |
287 | 3, | ||
288 | __LINE__)) || | ||
289 | (GNUNET_OK != | 279 | (GNUNET_OK != |
290 | pq_prepare (plugin, | 280 | pq_prepare (plugin, "getv", |
291 | "getv", | ||
292 | "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " | 281 | "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " |
293 | "WHERE hash=$1 AND vhash=$2 " | 282 | "WHERE hash=$1 AND vhash=$2 " |
294 | "ORDER BY oid ASC LIMIT 1 OFFSET $3", | 283 | "ORDER BY oid ASC LIMIT 1 OFFSET $3", 3, __LINE__)) || |
295 | 3, | ||
296 | __LINE__)) || | ||
297 | (GNUNET_OK != | 284 | (GNUNET_OK != |
298 | pq_prepare (plugin, | 285 | pq_prepare (plugin, "get", |
299 | "get", | ||
300 | "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " | 286 | "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " |
301 | "WHERE hash=$1 " | 287 | "WHERE hash=$1 " "ORDER BY oid ASC LIMIT 1 OFFSET $2", 2, |
302 | "ORDER BY oid ASC LIMIT 1 OFFSET $2", | ||
303 | 2, | ||
304 | __LINE__)) || | 288 | __LINE__)) || |
305 | (GNUNET_OK != | 289 | (GNUNET_OK != |
306 | pq_prepare (plugin, | 290 | pq_prepare (plugin, "put", |
307 | "put", | ||
308 | "INSERT INTO gn090 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) " | 291 | "INSERT INTO gn090 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) " |
309 | "VALUES ($1, $2, $3, $4, $5, RANDOM(), $6, $7, $8)", | 292 | "VALUES ($1, $2, $3, $4, $5, RANDOM(), $6, $7, $8)", 9, |
310 | 9, | ||
311 | __LINE__)) || | 293 | __LINE__)) || |
312 | (GNUNET_OK != | 294 | (GNUNET_OK != |
313 | pq_prepare (plugin, | 295 | pq_prepare (plugin, "update", |
314 | "update", | ||
315 | "UPDATE gn090 SET prio = prio + $1, expire = CASE WHEN expire < $2 THEN $2 ELSE expire END " | 296 | "UPDATE gn090 SET prio = prio + $1, expire = CASE WHEN expire < $2 THEN $2 ELSE expire END " |
316 | "WHERE oid = $3", | 297 | "WHERE oid = $3", 3, __LINE__)) || |
317 | 3, | ||
318 | __LINE__)) || | ||
319 | (GNUNET_OK != | 298 | (GNUNET_OK != |
320 | pq_prepare (plugin, | 299 | pq_prepare (plugin, "decrepl", |
321 | "decrepl", | ||
322 | "UPDATE gn090 SET repl = GREATEST (repl - 1, 0) " | 300 | "UPDATE gn090 SET repl = GREATEST (repl - 1, 0) " |
323 | "WHERE oid = $1", | 301 | "WHERE oid = $1", 1, __LINE__)) || |
324 | 1, | ||
325 | __LINE__)) || | ||
326 | (GNUNET_OK != | 302 | (GNUNET_OK != |
327 | pq_prepare (plugin, | 303 | pq_prepare (plugin, "select_non_anonymous", |
328 | "select_non_anonymous", | ||
329 | "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " | 304 | "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " |
330 | "WHERE anonLevel = 0 AND type = $1 ORDER BY oid DESC LIMIT 1 OFFSET $2", | 305 | "WHERE anonLevel = 0 AND type = $1 ORDER BY oid DESC LIMIT 1 OFFSET $2", |
331 | 1, | 306 | 1, __LINE__)) || |
332 | __LINE__)) || | ||
333 | (GNUNET_OK != | 307 | (GNUNET_OK != |
334 | pq_prepare (plugin, | 308 | pq_prepare (plugin, "select_expiration_order", |
335 | "select_expiration_order", | ||
336 | "(SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " | 309 | "(SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " |
337 | "WHERE expire < $1 ORDER BY prio ASC LIMIT 1) " | 310 | "WHERE expire < $1 ORDER BY prio ASC LIMIT 1) " "UNION " |
338 | "UNION " | ||
339 | "(SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " | 311 | "(SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " |
340 | "ORDER BY prio ASC LIMIT 1) " | 312 | "ORDER BY prio ASC LIMIT 1) " "ORDER BY expire ASC LIMIT 1", |
341 | "ORDER BY expire ASC LIMIT 1", | 313 | 1, __LINE__)) || |
342 | 1, | ||
343 | __LINE__)) || | ||
344 | (GNUNET_OK != | 314 | (GNUNET_OK != |
345 | pq_prepare (plugin, | 315 | pq_prepare (plugin, "select_replication_order", |
346 | "select_replication_order", | ||
347 | "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " | 316 | "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " |
348 | "ORDER BY repl DESC,RANDOM() LIMIT 1", | 317 | "ORDER BY repl DESC,RANDOM() LIMIT 1", 0, __LINE__)) || |
349 | 0, | ||
350 | __LINE__)) || | ||
351 | (GNUNET_OK != | 318 | (GNUNET_OK != |
352 | pq_prepare (plugin, | 319 | pq_prepare (plugin, "delrow", "DELETE FROM gn090 " "WHERE oid=$1", 1, |
353 | "delrow", "DELETE FROM gn090 " "WHERE oid=$1", 1, __LINE__))) | 320 | __LINE__))) |
354 | { | 321 | { |
355 | PQfinish (plugin->dbh); | 322 | PQfinish (plugin->dbh); |
356 | plugin->dbh = NULL; | 323 | plugin->dbh = NULL; |
@@ -378,12 +345,11 @@ delete_by_rowid (struct Plugin *plugin, unsigned int rowid) | |||
378 | PGresult *ret; | 345 | PGresult *ret; |
379 | 346 | ||
380 | browid = htonl (rowid); | 347 | browid = htonl (rowid); |
381 | ret = PQexecPrepared (plugin->dbh, | 348 | ret = |
382 | "delrow", | 349 | PQexecPrepared (plugin->dbh, "delrow", 1, paramValues, paramLengths, |
383 | 1, paramValues, paramLengths, paramFormats, 1); | 350 | paramFormats, 1); |
384 | if (GNUNET_OK != | 351 | if (GNUNET_OK != |
385 | check_result (plugin, | 352 | check_result (plugin, ret, PGRES_COMMAND_OK, "PQexecPrepared", "delrow", |
386 | ret, PGRES_COMMAND_OK, "PQexecPrepared", "delrow", | ||
387 | __LINE__)) | 353 | __LINE__)) |
388 | { | 354 | { |
389 | return GNUNET_SYSERR; | 355 | return GNUNET_SYSERR; |
@@ -407,18 +373,17 @@ postgres_plugin_estimate_size (void *cls) | |||
407 | unsigned long long total; | 373 | unsigned long long total; |
408 | PGresult *ret; | 374 | PGresult *ret; |
409 | 375 | ||
410 | ret = PQexecParams (plugin->dbh, | 376 | ret = |
411 | "SELECT SUM(LENGTH(value))+256*COUNT(*) FROM gn090", | 377 | PQexecParams (plugin->dbh, |
412 | 0, NULL, NULL, NULL, NULL, 1); | 378 | "SELECT SUM(LENGTH(value))+256*COUNT(*) FROM gn090", 0, |
413 | if (GNUNET_OK != check_result (plugin, | 379 | NULL, NULL, NULL, NULL, 1); |
414 | ret, | 380 | if (GNUNET_OK != |
415 | PGRES_TUPLES_OK, | 381 | check_result (plugin, ret, PGRES_TUPLES_OK, "PQexecParams", "get_size", |
416 | "PQexecParams", "get_size", __LINE__)) | 382 | __LINE__)) |
417 | { | 383 | { |
418 | return 0; | 384 | return 0; |
419 | } | 385 | } |
420 | if ((PQntuples (ret) != 1) || | 386 | if ((PQntuples (ret) != 1) || (PQnfields (ret) != 1) || |
421 | (PQnfields (ret) != 1) || | ||
422 | (PQgetlength (ret, 0, 0) != sizeof (unsigned long long))) | 387 | (PQgetlength (ret, 0, 0) != sizeof (unsigned long long))) |
423 | { | 388 | { |
424 | GNUNET_break (0); | 389 | GNUNET_break (0); |
@@ -447,13 +412,9 @@ postgres_plugin_estimate_size (void *cls) | |||
447 | * @return GNUNET_OK on success | 412 | * @return GNUNET_OK on success |
448 | */ | 413 | */ |
449 | static int | 414 | static int |
450 | postgres_plugin_put (void *cls, | 415 | postgres_plugin_put (void *cls, const GNUNET_HashCode * key, uint32_t size, |
451 | const GNUNET_HashCode * key, | 416 | const void *data, enum GNUNET_BLOCK_Type type, |
452 | uint32_t size, | 417 | uint32_t priority, uint32_t anonymity, |
453 | const void *data, | ||
454 | enum GNUNET_BLOCK_Type type, | ||
455 | uint32_t priority, | ||
456 | uint32_t anonymity, | ||
457 | uint32_t replication, | 418 | uint32_t replication, |
458 | struct GNUNET_TIME_Absolute expiration, char **msg) | 419 | struct GNUNET_TIME_Absolute expiration, char **msg) |
459 | { | 420 | { |
@@ -489,17 +450,17 @@ postgres_plugin_put (void *cls, | |||
489 | const int paramFormats[] = { 1, 1, 1, 1, 1, 1, 1, 1 }; | 450 | const int paramFormats[] = { 1, 1, 1, 1, 1, 1, 1, 1 }; |
490 | 451 | ||
491 | GNUNET_CRYPTO_hash (data, size, &vhash); | 452 | GNUNET_CRYPTO_hash (data, size, &vhash); |
492 | ret = PQexecPrepared (plugin->dbh, | 453 | ret = |
493 | "put", 8, paramValues, paramLengths, paramFormats, 1); | 454 | PQexecPrepared (plugin->dbh, "put", 8, paramValues, paramLengths, |
494 | if (GNUNET_OK != check_result (plugin, ret, | 455 | paramFormats, 1); |
495 | PGRES_COMMAND_OK, | 456 | if (GNUNET_OK != |
496 | "PQexecPrepared", "put", __LINE__)) | 457 | check_result (plugin, ret, PGRES_COMMAND_OK, "PQexecPrepared", "put", |
458 | __LINE__)) | ||
497 | return GNUNET_SYSERR; | 459 | return GNUNET_SYSERR; |
498 | PQclear (ret); | 460 | PQclear (ret); |
499 | plugin->env->duc (plugin->env->cls, size + GNUNET_DATASTORE_ENTRY_OVERHEAD); | 461 | plugin->env->duc (plugin->env->cls, size + GNUNET_DATASTORE_ENTRY_OVERHEAD); |
500 | #if DEBUG_POSTGRES | 462 | #if DEBUG_POSTGRES |
501 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 463 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datastore-postgres", |
502 | "datastore-postgres", | ||
503 | "Stored %u bytes in database\n", (unsigned int) size); | 464 | "Stored %u bytes in database\n", (unsigned int) size); |
504 | #endif | 465 | #endif |
505 | return GNUNET_OK; | 466 | return GNUNET_OK; |
@@ -517,9 +478,8 @@ postgres_plugin_put (void *cls, | |||
517 | * @param line line number for error messages | 478 | * @param line line number for error messages |
518 | */ | 479 | */ |
519 | static void | 480 | static void |
520 | process_result (struct Plugin *plugin, | 481 | process_result (struct Plugin *plugin, PluginDatumProcessor proc, |
521 | PluginDatumProcessor proc, void *proc_cls, | 482 | void *proc_cls, PGresult * res, int line) |
522 | PGresult * res, int line) | ||
523 | { | 483 | { |
524 | int iret; | 484 | int iret; |
525 | enum GNUNET_BLOCK_Type type; | 485 | enum GNUNET_BLOCK_Type type; |
@@ -530,14 +490,12 @@ process_result (struct Plugin *plugin, | |||
530 | struct GNUNET_TIME_Absolute expiration_time; | 490 | struct GNUNET_TIME_Absolute expiration_time; |
531 | GNUNET_HashCode key; | 491 | GNUNET_HashCode key; |
532 | 492 | ||
533 | if (GNUNET_OK != check_result (plugin, | 493 | if (GNUNET_OK != |
534 | res, | 494 | check_result (plugin, res, PGRES_TUPLES_OK, "PQexecPrepared", "select", |
535 | PGRES_TUPLES_OK, | 495 | line)) |
536 | "PQexecPrepared", "select", line)) | ||
537 | { | 496 | { |
538 | #if DEBUG_POSTGRES | 497 | #if DEBUG_POSTGRES |
539 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 498 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datastore-postgres", |
540 | "datastore-postgres", | ||
541 | "Ending iteration (postgres error)\n"); | 499 | "Ending iteration (postgres error)\n"); |
542 | #endif | 500 | #endif |
543 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 501 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
@@ -548,16 +506,14 @@ process_result (struct Plugin *plugin, | |||
548 | { | 506 | { |
549 | /* no result */ | 507 | /* no result */ |
550 | #if DEBUG_POSTGRES | 508 | #if DEBUG_POSTGRES |
551 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 509 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datastore-postgres", |
552 | "datastore-postgres", | ||
553 | "Ending iteration (no more results)\n"); | 510 | "Ending iteration (no more results)\n"); |
554 | #endif | 511 | #endif |
555 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 512 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
556 | PQclear (res); | 513 | PQclear (res); |
557 | return; | 514 | return; |
558 | } | 515 | } |
559 | if ((1 != PQntuples (res)) || | 516 | if ((1 != PQntuples (res)) || (7 != PQnfields (res)) || |
560 | (7 != PQnfields (res)) || | ||
561 | (sizeof (uint32_t) != PQfsize (res, 0)) || | 517 | (sizeof (uint32_t) != PQfsize (res, 0)) || |
562 | (sizeof (uint32_t) != PQfsize (res, 6))) | 518 | (sizeof (uint32_t) != PQfsize (res, 6))) |
563 | { | 519 | { |
@@ -588,17 +544,14 @@ process_result (struct Plugin *plugin, | |||
588 | memcpy (&key, PQgetvalue (res, 0, 4), sizeof (GNUNET_HashCode)); | 544 | memcpy (&key, PQgetvalue (res, 0, 4), sizeof (GNUNET_HashCode)); |
589 | size = PQgetlength (res, 0, 5); | 545 | size = PQgetlength (res, 0, 5); |
590 | #if DEBUG_POSTGRES | 546 | #if DEBUG_POSTGRES |
591 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 547 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datastore-postgres", |
592 | "datastore-postgres", | ||
593 | "Found result of size %u bytes and type %u in database\n", | 548 | "Found result of size %u bytes and type %u in database\n", |
594 | (unsigned int) size, (unsigned int) type); | 549 | (unsigned int) size, (unsigned int) type); |
595 | #endif | 550 | #endif |
596 | iret = proc (proc_cls, | 551 | iret = |
597 | &key, | 552 | proc (proc_cls, &key, size, PQgetvalue (res, 0, 5), |
598 | size, | 553 | (enum GNUNET_BLOCK_Type) type, priority, anonymity, expiration_time, |
599 | PQgetvalue (res, 0, 5), | 554 | rowid); |
600 | (enum GNUNET_BLOCK_Type) type, | ||
601 | priority, anonymity, expiration_time, rowid); | ||
602 | PQclear (res); | 555 | PQclear (res); |
603 | if (iret == GNUNET_NO) | 556 | if (iret == GNUNET_NO) |
604 | { | 557 | { |
@@ -609,16 +562,14 @@ process_result (struct Plugin *plugin, | |||
609 | if (GNUNET_OK == delete_by_rowid (plugin, rowid)) | 562 | if (GNUNET_OK == delete_by_rowid (plugin, rowid)) |
610 | { | 563 | { |
611 | #if DEBUG_POSTGRES | 564 | #if DEBUG_POSTGRES |
612 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 565 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datastore-postgres", |
613 | "datastore-postgres", | ||
614 | "Deleting %u bytes from database\n", | 566 | "Deleting %u bytes from database\n", |
615 | (unsigned int) size); | 567 | (unsigned int) size); |
616 | #endif | 568 | #endif |
617 | plugin->env->duc (plugin->env->cls, | 569 | plugin->env->duc (plugin->env->cls, |
618 | -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); | 570 | -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); |
619 | #if DEBUG_POSTGRES | 571 | #if DEBUG_POSTGRES |
620 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 572 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datastore-postgres", |
621 | "datastore-postgres", | ||
622 | "Deleted %u bytes from database\n", (unsigned int) size); | 573 | "Deleted %u bytes from database\n", (unsigned int) size); |
623 | #endif | 574 | #endif |
624 | } | 575 | } |
@@ -646,12 +597,11 @@ process_result (struct Plugin *plugin, | |||
646 | * @param proc_cls closure for iter | 597 | * @param proc_cls closure for iter |
647 | */ | 598 | */ |
648 | static void | 599 | static void |
649 | postgres_plugin_get_key (void *cls, | 600 | postgres_plugin_get_key (void *cls, uint64_t offset, |
650 | uint64_t offset, | ||
651 | const GNUNET_HashCode * key, | 601 | const GNUNET_HashCode * key, |
652 | const GNUNET_HashCode * vhash, | 602 | const GNUNET_HashCode * vhash, |
653 | enum GNUNET_BLOCK_Type type, | 603 | enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, |
654 | PluginDatumProcessor proc, void *proc_cls) | 604 | void *proc_cls) |
655 | { | 605 | { |
656 | struct Plugin *plugin = cls; | 606 | struct Plugin *plugin = cls; |
657 | const int paramFormats[] = { 1, 1, 1, 1, 1 }; | 607 | const int paramFormats[] = { 1, 1, 1, 1, 1 }; |
@@ -680,9 +630,10 @@ postgres_plugin_get_key (void *cls, | |||
680 | paramLengths[3] = sizeof (blimit_off); | 630 | paramLengths[3] = sizeof (blimit_off); |
681 | nparams = 4; | 631 | nparams = 4; |
682 | pname = "getvt"; | 632 | pname = "getvt"; |
683 | ret = PQexecParams (plugin->dbh, | 633 | ret = |
684 | "SELECT count(*) FROM gn090 WHERE hash=$1 AND vhash=$2 AND type=$3", | 634 | PQexecParams (plugin->dbh, |
685 | 3, NULL, paramValues, paramLengths, paramFormats, 1); | 635 | "SELECT count(*) FROM gn090 WHERE hash=$1 AND vhash=$2 AND type=$3", |
636 | 3, NULL, paramValues, paramLengths, paramFormats, 1); | ||
686 | } | 637 | } |
687 | else | 638 | else |
688 | { | 639 | { |
@@ -692,9 +643,10 @@ postgres_plugin_get_key (void *cls, | |||
692 | paramLengths[2] = sizeof (blimit_off); | 643 | paramLengths[2] = sizeof (blimit_off); |
693 | nparams = 3; | 644 | nparams = 3; |
694 | pname = "gett"; | 645 | pname = "gett"; |
695 | ret = PQexecParams (plugin->dbh, | 646 | ret = |
696 | "SELECT count(*) FROM gn090 WHERE hash=$1 AND type=$2", | 647 | PQexecParams (plugin->dbh, |
697 | 2, NULL, paramValues, paramLengths, paramFormats, 1); | 648 | "SELECT count(*) FROM gn090 WHERE hash=$1 AND type=$2", |
649 | 2, NULL, paramValues, paramLengths, paramFormats, 1); | ||
698 | } | 650 | } |
699 | } | 651 | } |
700 | else | 652 | else |
@@ -707,9 +659,10 @@ postgres_plugin_get_key (void *cls, | |||
707 | paramLengths[2] = sizeof (blimit_off); | 659 | paramLengths[2] = sizeof (blimit_off); |
708 | nparams = 3; | 660 | nparams = 3; |
709 | pname = "getv"; | 661 | pname = "getv"; |
710 | ret = PQexecParams (plugin->dbh, | 662 | ret = |
711 | "SELECT count(*) FROM gn090 WHERE hash=$1 AND vhash=$2", | 663 | PQexecParams (plugin->dbh, |
712 | 2, NULL, paramValues, paramLengths, paramFormats, 1); | 664 | "SELECT count(*) FROM gn090 WHERE hash=$1 AND vhash=$2", |
665 | 2, NULL, paramValues, paramLengths, paramFormats, 1); | ||
713 | } | 666 | } |
714 | else | 667 | else |
715 | { | 668 | { |
@@ -717,21 +670,19 @@ postgres_plugin_get_key (void *cls, | |||
717 | paramLengths[1] = sizeof (blimit_off); | 670 | paramLengths[1] = sizeof (blimit_off); |
718 | nparams = 2; | 671 | nparams = 2; |
719 | pname = "get"; | 672 | pname = "get"; |
720 | ret = PQexecParams (plugin->dbh, | 673 | ret = |
721 | "SELECT count(*) FROM gn090 WHERE hash=$1", | 674 | PQexecParams (plugin->dbh, "SELECT count(*) FROM gn090 WHERE hash=$1", |
722 | 1, NULL, paramValues, paramLengths, paramFormats, 1); | 675 | 1, NULL, paramValues, paramLengths, paramFormats, 1); |
723 | } | 676 | } |
724 | } | 677 | } |
725 | if (GNUNET_OK != check_result (plugin, | 678 | if (GNUNET_OK != |
726 | ret, | 679 | check_result (plugin, ret, PGRES_TUPLES_OK, "PQexecParams", pname, |
727 | PGRES_TUPLES_OK, | 680 | __LINE__)) |
728 | "PQexecParams", pname, __LINE__)) | ||
729 | { | 681 | { |
730 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 682 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
731 | return; | 683 | return; |
732 | } | 684 | } |
733 | if ((PQntuples (ret) != 1) || | 685 | if ((PQntuples (ret) != 1) || (PQnfields (ret) != 1) || |
734 | (PQnfields (ret) != 1) || | ||
735 | (PQgetlength (ret, 0, 0) != sizeof (unsigned long long))) | 686 | (PQgetlength (ret, 0, 0) != sizeof (unsigned long long))) |
736 | { | 687 | { |
737 | GNUNET_break (0); | 688 | GNUNET_break (0); |
@@ -747,9 +698,9 @@ postgres_plugin_get_key (void *cls, | |||
747 | return; | 698 | return; |
748 | } | 699 | } |
749 | blimit_off = GNUNET_htonll (offset % total); | 700 | blimit_off = GNUNET_htonll (offset % total); |
750 | ret = PQexecPrepared (plugin->dbh, | 701 | ret = |
751 | pname, | 702 | PQexecPrepared (plugin->dbh, pname, nparams, paramValues, paramLengths, |
752 | nparams, paramValues, paramLengths, paramFormats, 1); | 703 | paramFormats, 1); |
753 | process_result (plugin, proc, proc_cls, ret, __LINE__); | 704 | process_result (plugin, proc, proc_cls, ret, __LINE__); |
754 | } | 705 | } |
755 | 706 | ||
@@ -766,8 +717,7 @@ postgres_plugin_get_key (void *cls, | |||
766 | * @param proc_cls closure for proc | 717 | * @param proc_cls closure for proc |
767 | */ | 718 | */ |
768 | static void | 719 | static void |
769 | postgres_plugin_get_zero_anonymity (void *cls, | 720 | postgres_plugin_get_zero_anonymity (void *cls, uint64_t offset, |
770 | uint64_t offset, | ||
771 | enum GNUNET_BLOCK_Type type, | 721 | enum GNUNET_BLOCK_Type type, |
772 | PluginDatumProcessor proc, void *proc_cls) | 722 | PluginDatumProcessor proc, void *proc_cls) |
773 | { | 723 | { |
@@ -781,9 +731,9 @@ postgres_plugin_get_zero_anonymity (void *cls, | |||
781 | 731 | ||
782 | btype = htonl ((uint32_t) type); | 732 | btype = htonl ((uint32_t) type); |
783 | boff = GNUNET_htonll (offset); | 733 | boff = GNUNET_htonll (offset); |
784 | ret = PQexecPrepared (plugin->dbh, | 734 | ret = |
785 | "select_non_anonymous", | 735 | PQexecPrepared (plugin->dbh, "select_non_anonymous", 2, paramValues, |
786 | 2, paramValues, paramLengths, paramFormats, 1); | 736 | paramLengths, paramFormats, 1); |
787 | process_result (plugin, proc, proc_cls, ret, __LINE__); | 737 | process_result (plugin, proc, proc_cls, ret, __LINE__); |
788 | } | 738 | } |
789 | 739 | ||
@@ -833,14 +783,10 @@ struct ReplCtx | |||
833 | * GNUNET_NO to delete the item and continue (if supported) | 783 | * GNUNET_NO to delete the item and continue (if supported) |
834 | */ | 784 | */ |
835 | static int | 785 | static int |
836 | repl_proc (void *cls, | 786 | repl_proc (void *cls, const GNUNET_HashCode * key, uint32_t size, |
837 | const GNUNET_HashCode * key, | 787 | const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, |
838 | uint32_t size, | 788 | uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, |
839 | const void *data, | 789 | uint64_t uid) |
840 | enum GNUNET_BLOCK_Type type, | ||
841 | uint32_t priority, | ||
842 | uint32_t anonymity, | ||
843 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | ||
844 | { | 790 | { |
845 | struct ReplCtx *rc = cls; | 791 | struct ReplCtx *rc = cls; |
846 | struct Plugin *plugin = rc->plugin; | 792 | struct Plugin *plugin = rc->plugin; |
@@ -848,8 +794,9 @@ repl_proc (void *cls, | |||
848 | PGresult *qret; | 794 | PGresult *qret; |
849 | uint32_t boid; | 795 | uint32_t boid; |
850 | 796 | ||
851 | ret = rc->proc (rc->proc_cls, | 797 | ret = |
852 | key, size, data, type, priority, anonymity, expiration, uid); | 798 | rc->proc (rc->proc_cls, key, size, data, type, priority, anonymity, |
799 | expiration, uid); | ||
853 | if (NULL != key) | 800 | if (NULL != key) |
854 | { | 801 | { |
855 | boid = htonl ((uint32_t) uid); | 802 | boid = htonl ((uint32_t) uid); |
@@ -860,13 +807,12 @@ repl_proc (void *cls, | |||
860 | sizeof (boid), | 807 | sizeof (boid), |
861 | }; | 808 | }; |
862 | const int paramFormats[] = { 1 }; | 809 | const int paramFormats[] = { 1 }; |
863 | qret = PQexecPrepared (plugin->dbh, | 810 | qret = |
864 | "decrepl", | 811 | PQexecPrepared (plugin->dbh, "decrepl", 1, paramValues, paramLengths, |
865 | 1, paramValues, paramLengths, paramFormats, 1); | 812 | paramFormats, 1); |
866 | if (GNUNET_OK != check_result (plugin, | 813 | if (GNUNET_OK != |
867 | qret, | 814 | check_result (plugin, qret, PGRES_COMMAND_OK, "PQexecPrepared", |
868 | PGRES_COMMAND_OK, | 815 | "decrepl", __LINE__)) |
869 | "PQexecPrepared", "decrepl", __LINE__)) | ||
870 | return GNUNET_SYSERR; | 816 | return GNUNET_SYSERR; |
871 | PQclear (qret); | 817 | PQclear (qret); |
872 | } | 818 | } |
@@ -885,8 +831,8 @@ repl_proc (void *cls, | |||
885 | * @param proc_cls closure for proc | 831 | * @param proc_cls closure for proc |
886 | */ | 832 | */ |
887 | static void | 833 | static void |
888 | postgres_plugin_get_replication (void *cls, | 834 | postgres_plugin_get_replication (void *cls, PluginDatumProcessor proc, |
889 | PluginDatumProcessor proc, void *proc_cls) | 835 | void *proc_cls) |
890 | { | 836 | { |
891 | struct Plugin *plugin = cls; | 837 | struct Plugin *plugin = cls; |
892 | struct ReplCtx rc; | 838 | struct ReplCtx rc; |
@@ -895,8 +841,9 @@ postgres_plugin_get_replication (void *cls, | |||
895 | rc.plugin = plugin; | 841 | rc.plugin = plugin; |
896 | rc.proc = proc; | 842 | rc.proc = proc; |
897 | rc.proc_cls = proc_cls; | 843 | rc.proc_cls = proc_cls; |
898 | ret = PQexecPrepared (plugin->dbh, | 844 | ret = |
899 | "select_replication_order", 0, NULL, NULL, NULL, 1); | 845 | PQexecPrepared (plugin->dbh, "select_replication_order", 0, NULL, NULL, |
846 | NULL, 1); | ||
900 | process_result (plugin, &repl_proc, &rc, ret, __LINE__); | 847 | process_result (plugin, &repl_proc, &rc, ret, __LINE__); |
901 | } | 848 | } |
902 | 849 | ||
@@ -910,8 +857,8 @@ postgres_plugin_get_replication (void *cls, | |||
910 | * @param proc_cls closure for proc | 857 | * @param proc_cls closure for proc |
911 | */ | 858 | */ |
912 | static void | 859 | static void |
913 | postgres_plugin_get_expiration (void *cls, | 860 | postgres_plugin_get_expiration (void *cls, PluginDatumProcessor proc, |
914 | PluginDatumProcessor proc, void *proc_cls) | 861 | void *proc_cls) |
915 | { | 862 | { |
916 | struct Plugin *plugin = cls; | 863 | struct Plugin *plugin = cls; |
917 | uint64_t btime; | 864 | uint64_t btime; |
@@ -921,9 +868,9 @@ postgres_plugin_get_expiration (void *cls, | |||
921 | PGresult *ret; | 868 | PGresult *ret; |
922 | 869 | ||
923 | btime = GNUNET_htonll (GNUNET_TIME_absolute_get ().abs_value); | 870 | btime = GNUNET_htonll (GNUNET_TIME_absolute_get ().abs_value); |
924 | ret = PQexecPrepared (plugin->dbh, | 871 | ret = |
925 | "select_expiration_order", | 872 | PQexecPrepared (plugin->dbh, "select_expiration_order", 1, paramValues, |
926 | 1, paramValues, paramLengths, paramFormats, 1); | 873 | paramLengths, paramFormats, 1); |
927 | process_result (plugin, proc, proc_cls, ret, __LINE__); | 874 | process_result (plugin, proc, proc_cls, ret, __LINE__); |
928 | } | 875 | } |
929 | 876 | ||
@@ -952,10 +899,8 @@ postgres_plugin_get_expiration (void *cls, | |||
952 | * @return GNUNET_OK on success | 899 | * @return GNUNET_OK on success |
953 | */ | 900 | */ |
954 | static int | 901 | static int |
955 | postgres_plugin_update (void *cls, | 902 | postgres_plugin_update (void *cls, uint64_t uid, int delta, |
956 | uint64_t uid, | 903 | struct GNUNET_TIME_Absolute expire, char **msg) |
957 | int delta, struct GNUNET_TIME_Absolute expire, | ||
958 | char **msg) | ||
959 | { | 904 | { |
960 | struct Plugin *plugin = cls; | 905 | struct Plugin *plugin = cls; |
961 | PGresult *ret; | 906 | PGresult *ret; |
@@ -975,13 +920,12 @@ postgres_plugin_update (void *cls, | |||
975 | }; | 920 | }; |
976 | const int paramFormats[] = { 1, 1, 1 }; | 921 | const int paramFormats[] = { 1, 1, 1 }; |
977 | 922 | ||
978 | ret = PQexecPrepared (plugin->dbh, | 923 | ret = |
979 | "update", | 924 | PQexecPrepared (plugin->dbh, "update", 3, paramValues, paramLengths, |
980 | 3, paramValues, paramLengths, paramFormats, 1); | 925 | paramFormats, 1); |
981 | if (GNUNET_OK != check_result (plugin, | 926 | if (GNUNET_OK != |
982 | ret, | 927 | check_result (plugin, ret, PGRES_COMMAND_OK, "PQexecPrepared", "update", |
983 | PGRES_COMMAND_OK, | 928 | __LINE__)) |
984 | "PQexecPrepared", "update", __LINE__)) | ||
985 | return GNUNET_SYSERR; | 929 | return GNUNET_SYSERR; |
986 | PQclear (ret); | 930 | PQclear (ret); |
987 | return GNUNET_OK; | 931 | return GNUNET_OK; |
@@ -1030,8 +974,8 @@ libgnunet_plugin_datastore_postgres_init (void *cls) | |||
1030 | api->get_expiration = &postgres_plugin_get_expiration; | 974 | api->get_expiration = &postgres_plugin_get_expiration; |
1031 | api->get_zero_anonymity = &postgres_plugin_get_zero_anonymity; | 975 | api->get_zero_anonymity = &postgres_plugin_get_zero_anonymity; |
1032 | api->drop = &postgres_plugin_drop; | 976 | api->drop = &postgres_plugin_drop; |
1033 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, | 977 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "datastore-postgres", |
1034 | "datastore-postgres", _("Postgres database running\n")); | 978 | _("Postgres database running\n")); |
1035 | return api; | 979 | return api; |
1036 | } | 980 | } |
1037 | 981 | ||
diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c index 075d31623..46486d933 100644 --- a/src/datastore/plugin_datastore_sqlite.c +++ b/src/datastore/plugin_datastore_sqlite.c | |||
@@ -144,12 +144,12 @@ sq_prepare (sqlite3 * dbh, const char *zSql, sqlite3_stmt ** ppStmt) | |||
144 | char *dummy; | 144 | char *dummy; |
145 | int result; | 145 | int result; |
146 | 146 | ||
147 | result = sqlite3_prepare_v2 (dbh, | 147 | result = |
148 | zSql, | 148 | sqlite3_prepare_v2 (dbh, zSql, strlen (zSql), ppStmt, |
149 | strlen (zSql), ppStmt, (const char **) &dummy); | 149 | (const char **) &dummy); |
150 | #if DEBUG_SQLITE && 0 | 150 | #if DEBUG_SQLITE && 0 |
151 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 151 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", |
152 | "sqlite", "Prepared `%s' / %p: %d\n", zSql, *ppStmt, result); | 152 | "Prepared `%s' / %p: %d\n", zSql, *ppStmt, result); |
153 | #endif | 153 | #endif |
154 | return result; | 154 | return result; |
155 | } | 155 | } |
@@ -165,8 +165,7 @@ create_indices (sqlite3 * dbh) | |||
165 | { | 165 | { |
166 | /* create indices */ | 166 | /* create indices */ |
167 | if ((SQLITE_OK != | 167 | if ((SQLITE_OK != |
168 | sqlite3_exec (dbh, | 168 | sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS idx_hash ON gn090 (hash)", |
169 | "CREATE INDEX IF NOT EXISTS idx_hash ON gn090 (hash)", | ||
170 | NULL, NULL, NULL)) || | 169 | NULL, NULL, NULL)) || |
171 | (SQLITE_OK != | 170 | (SQLITE_OK != |
172 | sqlite3_exec (dbh, | 171 | sqlite3_exec (dbh, |
@@ -232,12 +231,10 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
232 | #endif | 231 | #endif |
233 | 232 | ||
234 | if (GNUNET_OK != | 233 | if (GNUNET_OK != |
235 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 234 | GNUNET_CONFIGURATION_get_value_filename (cfg, "datastore-sqlite", |
236 | "datastore-sqlite", | ||
237 | "FILENAME", &afsdir)) | 235 | "FILENAME", &afsdir)) |
238 | { | 236 | { |
239 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 237 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "sqlite", |
240 | "sqlite", | ||
241 | _ | 238 | _ |
242 | ("Option `%s' in section `%s' missing in configuration!\n"), | 239 | ("Option `%s' in section `%s' missing in configuration!\n"), |
243 | "FILENAME", "datastore-sqlite"); | 240 | "FILENAME", "datastore-sqlite"); |
@@ -255,8 +252,8 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
255 | plugin->env->duc (plugin->env->cls, 0); | 252 | plugin->env->duc (plugin->env->cls, 0); |
256 | } | 253 | } |
257 | #ifdef ENABLE_NLS | 254 | #ifdef ENABLE_NLS |
258 | plugin->fn = GNUNET_STRINGS_to_utf8 (afsdir, strlen (afsdir), | 255 | plugin->fn = |
259 | nl_langinfo (CODESET)); | 256 | GNUNET_STRINGS_to_utf8 (afsdir, strlen (afsdir), nl_langinfo (CODESET)); |
260 | #else | 257 | #else |
261 | plugin->fn = GNUNET_STRINGS_to_utf8 (afsdir, strlen (afsdir), "UTF-8"); /* good luck */ | 258 | plugin->fn = GNUNET_STRINGS_to_utf8 (afsdir, strlen (afsdir), "UTF-8"); /* good luck */ |
262 | #endif | 259 | #endif |
@@ -265,33 +262,32 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
265 | /* Open database and precompile statements */ | 262 | /* Open database and precompile statements */ |
266 | if (sqlite3_open (plugin->fn, &plugin->dbh) != SQLITE_OK) | 263 | if (sqlite3_open (plugin->fn, &plugin->dbh) != SQLITE_OK) |
267 | { | 264 | { |
268 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 265 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "sqlite", |
269 | "sqlite", | ||
270 | _("Unable to initialize SQLite: %s.\n"), | 266 | _("Unable to initialize SQLite: %s.\n"), |
271 | sqlite3_errmsg (plugin->dbh)); | 267 | sqlite3_errmsg (plugin->dbh)); |
272 | return GNUNET_SYSERR; | 268 | return GNUNET_SYSERR; |
273 | } | 269 | } |
274 | CHECK (SQLITE_OK == | 270 | CHECK (SQLITE_OK == |
275 | sqlite3_exec (plugin->dbh, | 271 | sqlite3_exec (plugin->dbh, "PRAGMA temp_store=MEMORY", NULL, NULL, |
276 | "PRAGMA temp_store=MEMORY", NULL, NULL, ENULL)); | 272 | ENULL)); |
277 | CHECK (SQLITE_OK == | 273 | CHECK (SQLITE_OK == |
278 | sqlite3_exec (plugin->dbh, | 274 | sqlite3_exec (plugin->dbh, "PRAGMA synchronous=OFF", NULL, NULL, |
279 | "PRAGMA synchronous=OFF", NULL, NULL, ENULL)); | 275 | ENULL)); |
280 | CHECK (SQLITE_OK == | 276 | CHECK (SQLITE_OK == |
281 | sqlite3_exec (plugin->dbh, | 277 | sqlite3_exec (plugin->dbh, "PRAGMA legacy_file_format=OFF", NULL, NULL, |
282 | "PRAGMA legacy_file_format=OFF", NULL, NULL, ENULL)); | 278 | ENULL)); |
283 | CHECK (SQLITE_OK == | 279 | CHECK (SQLITE_OK == |
284 | sqlite3_exec (plugin->dbh, | 280 | sqlite3_exec (plugin->dbh, "PRAGMA auto_vacuum=INCREMENTAL", NULL, |
285 | "PRAGMA auto_vacuum=INCREMENTAL", NULL, NULL, ENULL)); | 281 | NULL, ENULL)); |
286 | CHECK (SQLITE_OK == | 282 | CHECK (SQLITE_OK == |
287 | sqlite3_exec (plugin->dbh, | 283 | sqlite3_exec (plugin->dbh, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, |
288 | "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, ENULL)); | 284 | ENULL)); |
289 | CHECK (SQLITE_OK == | 285 | CHECK (SQLITE_OK == |
290 | sqlite3_exec (plugin->dbh, | 286 | sqlite3_exec (plugin->dbh, "PRAGMA count_changes=OFF", NULL, NULL, |
291 | "PRAGMA count_changes=OFF", NULL, NULL, ENULL)); | 287 | ENULL)); |
292 | CHECK (SQLITE_OK == | 288 | CHECK (SQLITE_OK == |
293 | sqlite3_exec (plugin->dbh, | 289 | sqlite3_exec (plugin->dbh, "PRAGMA page_size=4092", NULL, NULL, |
294 | "PRAGMA page_size=4092", NULL, NULL, ENULL)); | 290 | ENULL)); |
295 | 291 | ||
296 | CHECK (SQLITE_OK == sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS)); | 292 | CHECK (SQLITE_OK == sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS)); |
297 | 293 | ||
@@ -302,18 +298,14 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
302 | "SELECT 1 FROM sqlite_master WHERE tbl_name = 'gn090'", | 298 | "SELECT 1 FROM sqlite_master WHERE tbl_name = 'gn090'", |
303 | &stmt)); | 299 | &stmt)); |
304 | if ((sqlite3_step (stmt) == SQLITE_DONE) && | 300 | if ((sqlite3_step (stmt) == SQLITE_DONE) && |
305 | (sqlite3_exec (plugin->dbh, | 301 | (sqlite3_exec |
306 | "CREATE TABLE gn090 (" | 302 | (plugin->dbh, |
307 | " repl INT4 NOT NULL DEFAULT 0," | 303 | "CREATE TABLE gn090 (" " repl INT4 NOT NULL DEFAULT 0," |
308 | " type INT4 NOT NULL DEFAULT 0," | 304 | " type INT4 NOT NULL DEFAULT 0," " prio INT4 NOT NULL DEFAULT 0," |
309 | " prio INT4 NOT NULL DEFAULT 0," | 305 | " anonLevel INT4 NOT NULL DEFAULT 0," |
310 | " anonLevel INT4 NOT NULL DEFAULT 0," | 306 | " expire INT8 NOT NULL DEFAULT 0," " rvalue INT8 NOT NULL," |
311 | " expire INT8 NOT NULL DEFAULT 0," | 307 | " hash TEXT NOT NULL DEFAULT ''," " vhash TEXT NOT NULL DEFAULT ''," |
312 | " rvalue INT8 NOT NULL," | 308 | " value BLOB NOT NULL DEFAULT '')", NULL, NULL, NULL) != SQLITE_OK)) |
313 | " hash TEXT NOT NULL DEFAULT ''," | ||
314 | " vhash TEXT NOT NULL DEFAULT ''," | ||
315 | " value BLOB NOT NULL DEFAULT '')", NULL, NULL, | ||
316 | NULL) != SQLITE_OK)) | ||
317 | { | 309 | { |
318 | LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec"); | 310 | LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec"); |
319 | sqlite3_finalize (stmt); | 311 | sqlite3_finalize (stmt); |
@@ -322,47 +314,49 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
322 | sqlite3_finalize (stmt); | 314 | sqlite3_finalize (stmt); |
323 | create_indices (plugin->dbh); | 315 | create_indices (plugin->dbh); |
324 | 316 | ||
325 | if ((sq_prepare (plugin->dbh, | 317 | if ((sq_prepare |
326 | "UPDATE gn090 " | 318 | (plugin->dbh, |
327 | "SET prio = prio + ?, expire = MAX(expire,?) WHERE _ROWID_ = ?", | 319 | "UPDATE gn090 " |
328 | &plugin->updPrio) != SQLITE_OK) || | 320 | "SET prio = prio + ?, expire = MAX(expire,?) WHERE _ROWID_ = ?", |
329 | (sq_prepare (plugin->dbh, | 321 | &plugin->updPrio) != SQLITE_OK) || |
330 | "UPDATE gn090 " | 322 | (sq_prepare |
331 | "SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?", | 323 | (plugin->dbh, |
332 | &plugin->updRepl) != SQLITE_OK) || | 324 | "UPDATE gn090 " "SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?", |
333 | (sq_prepare (plugin->dbh, | 325 | &plugin->updRepl) != SQLITE_OK) || |
334 | "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " | 326 | (sq_prepare |
335 | "FROM gn090 INDEXED BY idx_repl_rvalue " | 327 | (plugin->dbh, |
336 | "WHERE repl=?2 AND" | 328 | "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " |
337 | " (rvalue>=?1 OR" | 329 | "FROM gn090 INDEXED BY idx_repl_rvalue " "WHERE repl=?2 AND" |
338 | " NOT EXISTS (SELECT 1 FROM gn090 INDEXED BY idx_repl_rvalue WHERE repl=?2 AND rvalue>=?1 LIMIT 1))" | 330 | " (rvalue>=?1 OR" |
339 | " ORDER BY rvalue ASC" | 331 | " NOT EXISTS (SELECT 1 FROM gn090 INDEXED BY idx_repl_rvalue WHERE repl=?2 AND rvalue>=?1 LIMIT 1))" |
340 | " LIMIT 1", | 332 | " ORDER BY rvalue ASC" " LIMIT 1", |
341 | &plugin->selRepl) != SQLITE_OK) || | 333 | &plugin->selRepl) != SQLITE_OK) || |
342 | (sq_prepare (plugin->dbh, | 334 | (sq_prepare |
343 | "SELECT MAX(repl) " | 335 | (plugin->dbh, |
344 | "FROM gn090 INDEXED BY idx_repl_rvalue", | 336 | "SELECT MAX(repl) " "FROM gn090 INDEXED BY idx_repl_rvalue", |
345 | &plugin->maxRepl) != SQLITE_OK) || | 337 | &plugin->maxRepl) != SQLITE_OK) || |
346 | (sq_prepare (plugin->dbh, | 338 | (sq_prepare |
347 | "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " | 339 | (plugin->dbh, |
348 | "FROM gn090 INDEXED BY idx_expire" | 340 | "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " |
349 | " WHERE NOT EXISTS (SELECT 1 FROM gn090 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) " | 341 | "FROM gn090 INDEXED BY idx_expire" |
350 | " ORDER BY expire ASC LIMIT 1", | 342 | " WHERE NOT EXISTS (SELECT 1 FROM gn090 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) " |
351 | &plugin->selExpi) != SQLITE_OK) || | 343 | " ORDER BY expire ASC LIMIT 1", &plugin->selExpi) != SQLITE_OK) || |
352 | (sq_prepare (plugin->dbh, | 344 | (sq_prepare |
353 | "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " | 345 | (plugin->dbh, |
354 | "FROM gn090 INDEXED BY idx_anon_type_hash " | 346 | "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " |
355 | "WHERE (anonLevel = 0 AND type=?1) " | 347 | "FROM gn090 INDEXED BY idx_anon_type_hash " |
356 | "ORDER BY hash DESC LIMIT 1 OFFSET ?2", | 348 | "WHERE (anonLevel = 0 AND type=?1) " |
357 | &plugin->selZeroAnon) != SQLITE_OK) || | 349 | "ORDER BY hash DESC LIMIT 1 OFFSET ?2", |
358 | (sq_prepare (plugin->dbh, | 350 | &plugin->selZeroAnon) != SQLITE_OK) || |
359 | "INSERT INTO gn090 (repl, type, prio, " | 351 | (sq_prepare |
360 | "anonLevel, expire, rvalue, hash, vhash, value) " | 352 | (plugin->dbh, |
361 | "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", | 353 | "INSERT INTO gn090 (repl, type, prio, " |
362 | &plugin->insertContent) != SQLITE_OK) || | 354 | "anonLevel, expire, rvalue, hash, vhash, value) " |
363 | (sq_prepare (plugin->dbh, | 355 | "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", |
364 | "DELETE FROM gn090 WHERE _ROWID_ = ?", | 356 | &plugin->insertContent) != SQLITE_OK) || |
365 | &plugin->delRow) != SQLITE_OK)) | 357 | (sq_prepare |
358 | (plugin->dbh, "DELETE FROM gn090 WHERE _ROWID_ = ?", | ||
359 | &plugin->delRow) != SQLITE_OK)) | ||
366 | { | 360 | { |
367 | LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR, "precompiling"); | 361 | LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR, "precompiling"); |
368 | return GNUNET_SYSERR; | 362 | return GNUNET_SYSERR; |
@@ -406,22 +400,20 @@ database_shutdown (struct Plugin *plugin) | |||
406 | #if SQLITE_VERSION_NUMBER >= 3007000 | 400 | #if SQLITE_VERSION_NUMBER >= 3007000 |
407 | if (result == SQLITE_BUSY) | 401 | if (result == SQLITE_BUSY) |
408 | { | 402 | { |
409 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, | 403 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "sqlite", |
410 | "sqlite", | ||
411 | _ | 404 | _ |
412 | ("Tried to close sqlite without finalizing all prepared statements.\n")); | 405 | ("Tried to close sqlite without finalizing all prepared statements.\n")); |
413 | stmt = sqlite3_next_stmt (plugin->dbh, NULL); | 406 | stmt = sqlite3_next_stmt (plugin->dbh, NULL); |
414 | while (stmt != NULL) | 407 | while (stmt != NULL) |
415 | { | 408 | { |
416 | #if DEBUG_SQLITE | 409 | #if DEBUG_SQLITE |
417 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 410 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", |
418 | "sqlite", "Closing statement %p\n", stmt); | 411 | "Closing statement %p\n", stmt); |
419 | #endif | 412 | #endif |
420 | result = sqlite3_finalize (stmt); | 413 | result = sqlite3_finalize (stmt); |
421 | #if DEBUG_SQLITE | 414 | #if DEBUG_SQLITE |
422 | if (result != SQLITE_OK) | 415 | if (result != SQLITE_OK) |
423 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 416 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", |
424 | "sqlite", | ||
425 | "Failed to close statement %p: %d\n", stmt, result); | 417 | "Failed to close statement %p: %d\n", stmt, result); |
426 | #endif | 418 | #endif |
427 | stmt = sqlite3_next_stmt (plugin->dbh, NULL); | 419 | stmt = sqlite3_next_stmt (plugin->dbh, NULL); |
@@ -448,8 +440,7 @@ delete_by_rowid (struct Plugin *plugin, unsigned long long rid) | |||
448 | { | 440 | { |
449 | if (SQLITE_OK != sqlite3_bind_int64 (plugin->delRow, 1, rid)) | 441 | if (SQLITE_OK != sqlite3_bind_int64 (plugin->delRow, 1, rid)) |
450 | { | 442 | { |
451 | LOG_SQLITE (plugin, NULL, | 443 | LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
452 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
453 | "sqlite3_bind_XXXX"); | 444 | "sqlite3_bind_XXXX"); |
454 | if (SQLITE_OK != sqlite3_reset (plugin->delRow)) | 445 | if (SQLITE_OK != sqlite3_reset (plugin->delRow)) |
455 | LOG_SQLITE (plugin, NULL, | 446 | LOG_SQLITE (plugin, NULL, |
@@ -459,19 +450,17 @@ delete_by_rowid (struct Plugin *plugin, unsigned long long rid) | |||
459 | } | 450 | } |
460 | if (SQLITE_DONE != sqlite3_step (plugin->delRow)) | 451 | if (SQLITE_DONE != sqlite3_step (plugin->delRow)) |
461 | { | 452 | { |
462 | LOG_SQLITE (plugin, NULL, | 453 | LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
463 | GNUNET_ERROR_TYPE_ERROR | | 454 | "sqlite3_step"); |
464 | GNUNET_ERROR_TYPE_BULK, "sqlite3_step"); | ||
465 | if (SQLITE_OK != sqlite3_reset (plugin->delRow)) | 455 | if (SQLITE_OK != sqlite3_reset (plugin->delRow)) |
466 | LOG_SQLITE (plugin, NULL, | 456 | LOG_SQLITE (plugin, NULL, |
467 | GNUNET_ERROR_TYPE_ERROR | | 457 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
468 | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); | 458 | "sqlite3_reset"); |
469 | return GNUNET_SYSERR; | 459 | return GNUNET_SYSERR; |
470 | } | 460 | } |
471 | if (SQLITE_OK != sqlite3_reset (plugin->delRow)) | 461 | if (SQLITE_OK != sqlite3_reset (plugin->delRow)) |
472 | LOG_SQLITE (plugin, NULL, | 462 | LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
473 | GNUNET_ERROR_TYPE_ERROR | | 463 | "sqlite3_reset"); |
474 | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); | ||
475 | return GNUNET_OK; | 464 | return GNUNET_OK; |
476 | } | 465 | } |
477 | 466 | ||
@@ -492,14 +481,9 @@ delete_by_rowid (struct Plugin *plugin, unsigned long long rid) | |||
492 | * @return GNUNET_OK on success | 481 | * @return GNUNET_OK on success |
493 | */ | 482 | */ |
494 | static int | 483 | static int |
495 | sqlite_plugin_put (void *cls, | 484 | sqlite_plugin_put (void *cls, const GNUNET_HashCode * key, uint32_t size, |
496 | const GNUNET_HashCode * key, | 485 | const void *data, enum GNUNET_BLOCK_Type type, |
497 | uint32_t size, | 486 | uint32_t priority, uint32_t anonymity, uint32_t replication, |
498 | const void *data, | ||
499 | enum GNUNET_BLOCK_Type type, | ||
500 | uint32_t priority, | ||
501 | uint32_t anonymity, | ||
502 | uint32_t replication, | ||
503 | struct GNUNET_TIME_Absolute expiration, char **msg) | 487 | struct GNUNET_TIME_Absolute expiration, char **msg) |
504 | { | 488 | { |
505 | struct Plugin *plugin = cls; | 489 | struct Plugin *plugin = cls; |
@@ -512,12 +496,9 @@ sqlite_plugin_put (void *cls, | |||
512 | if (size > MAX_ITEM_SIZE) | 496 | if (size > MAX_ITEM_SIZE) |
513 | return GNUNET_SYSERR; | 497 | return GNUNET_SYSERR; |
514 | #if DEBUG_SQLITE | 498 | #if DEBUG_SQLITE |
515 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 499 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", |
516 | "sqlite", | ||
517 | "Storing in database block with type %u/key `%s'/priority %u/expiration in %llu ms (%lld).\n", | 500 | "Storing in database block with type %u/key `%s'/priority %u/expiration in %llu ms (%lld).\n", |
518 | type, | 501 | type, GNUNET_h2s (key), priority, |
519 | GNUNET_h2s (key), | ||
520 | priority, | ||
521 | (unsigned long long) | 502 | (unsigned long long) |
522 | GNUNET_TIME_absolute_get_remaining (expiration).rel_value, | 503 | GNUNET_TIME_absolute_get_remaining (expiration).rel_value, |
523 | (long long) expiration.abs_value); | 504 | (long long) expiration.abs_value); |
@@ -536,13 +517,10 @@ sqlite_plugin_put (void *cls, | |||
536 | SQLITE_TRANSIENT)) || | 517 | SQLITE_TRANSIENT)) || |
537 | (SQLITE_OK != | 518 | (SQLITE_OK != |
538 | sqlite3_bind_blob (stmt, 8, &vhash, sizeof (GNUNET_HashCode), | 519 | sqlite3_bind_blob (stmt, 8, &vhash, sizeof (GNUNET_HashCode), |
539 | SQLITE_TRANSIENT)) | 520 | SQLITE_TRANSIENT)) || |
540 | || (SQLITE_OK != | 521 | (SQLITE_OK != sqlite3_bind_blob (stmt, 9, data, size, SQLITE_TRANSIENT))) |
541 | sqlite3_bind_blob (stmt, 9, data, size, SQLITE_TRANSIENT))) | ||
542 | { | 522 | { |
543 | LOG_SQLITE (plugin, | 523 | LOG_SQLITE (plugin, msg, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
544 | msg, | ||
545 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
546 | "sqlite3_bind_XXXX"); | 524 | "sqlite3_bind_XXXX"); |
547 | if (SQLITE_OK != sqlite3_reset (stmt)) | 525 | if (SQLITE_OK != sqlite3_reset (stmt)) |
548 | LOG_SQLITE (plugin, NULL, | 526 | LOG_SQLITE (plugin, NULL, |
@@ -556,8 +534,7 @@ sqlite_plugin_put (void *cls, | |||
556 | case SQLITE_DONE: | 534 | case SQLITE_DONE: |
557 | plugin->env->duc (plugin->env->cls, size + GNUNET_DATASTORE_ENTRY_OVERHEAD); | 535 | plugin->env->duc (plugin->env->cls, size + GNUNET_DATASTORE_ENTRY_OVERHEAD); |
558 | #if DEBUG_SQLITE | 536 | #if DEBUG_SQLITE |
559 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 537 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", |
560 | "sqlite", | ||
561 | "Stored new entry (%u bytes)\n", | 538 | "Stored new entry (%u bytes)\n", |
562 | size + GNUNET_DATASTORE_ENTRY_OVERHEAD); | 539 | size + GNUNET_DATASTORE_ENTRY_OVERHEAD); |
563 | #endif | 540 | #endif |
@@ -565,27 +542,24 @@ sqlite_plugin_put (void *cls, | |||
565 | break; | 542 | break; |
566 | case SQLITE_BUSY: | 543 | case SQLITE_BUSY: |
567 | GNUNET_break (0); | 544 | GNUNET_break (0); |
568 | LOG_SQLITE (plugin, msg, | 545 | LOG_SQLITE (plugin, msg, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
569 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
570 | "sqlite3_step"); | 546 | "sqlite3_step"); |
571 | ret = GNUNET_SYSERR; | 547 | ret = GNUNET_SYSERR; |
572 | break; | 548 | break; |
573 | default: | 549 | default: |
574 | LOG_SQLITE (plugin, msg, | 550 | LOG_SQLITE (plugin, msg, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
575 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
576 | "sqlite3_step"); | 551 | "sqlite3_step"); |
577 | if (SQLITE_OK != sqlite3_reset (stmt)) | 552 | if (SQLITE_OK != sqlite3_reset (stmt)) |
578 | LOG_SQLITE (plugin, NULL, | 553 | LOG_SQLITE (plugin, NULL, |
579 | GNUNET_ERROR_TYPE_ERROR | | 554 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
580 | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); | 555 | "sqlite3_reset"); |
581 | database_shutdown (plugin); | 556 | database_shutdown (plugin); |
582 | database_setup (plugin->env->cfg, plugin); | 557 | database_setup (plugin->env->cfg, plugin); |
583 | return GNUNET_SYSERR; | 558 | return GNUNET_SYSERR; |
584 | } | 559 | } |
585 | if (SQLITE_OK != sqlite3_reset (stmt)) | 560 | if (SQLITE_OK != sqlite3_reset (stmt)) |
586 | LOG_SQLITE (plugin, NULL, | 561 | LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
587 | GNUNET_ERROR_TYPE_ERROR | | 562 | "sqlite3_reset"); |
588 | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); | ||
589 | return ret; | 563 | return ret; |
590 | } | 564 | } |
591 | 565 | ||
@@ -614,21 +588,17 @@ sqlite_plugin_put (void *cls, | |||
614 | * @return GNUNET_OK on success | 588 | * @return GNUNET_OK on success |
615 | */ | 589 | */ |
616 | static int | 590 | static int |
617 | sqlite_plugin_update (void *cls, | 591 | sqlite_plugin_update (void *cls, uint64_t uid, int delta, |
618 | uint64_t uid, | 592 | struct GNUNET_TIME_Absolute expire, char **msg) |
619 | int delta, struct GNUNET_TIME_Absolute expire, char **msg) | ||
620 | { | 593 | { |
621 | struct Plugin *plugin = cls; | 594 | struct Plugin *plugin = cls; |
622 | int n; | 595 | int n; |
623 | 596 | ||
624 | if ((SQLITE_OK != | 597 | if ((SQLITE_OK != sqlite3_bind_int (plugin->updPrio, 1, delta)) || |
625 | sqlite3_bind_int (plugin->updPrio, 1, delta)) || | 598 | (SQLITE_OK != sqlite3_bind_int64 (plugin->updPrio, 2, expire.abs_value)) |
626 | (SQLITE_OK != | 599 | || (SQLITE_OK != sqlite3_bind_int64 (plugin->updPrio, 3, uid))) |
627 | sqlite3_bind_int64 (plugin->updPrio, 2, expire.abs_value)) || | ||
628 | (SQLITE_OK != sqlite3_bind_int64 (plugin->updPrio, 3, uid))) | ||
629 | { | 600 | { |
630 | LOG_SQLITE (plugin, msg, | 601 | LOG_SQLITE (plugin, msg, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
631 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
632 | "sqlite3_bind_XXXX"); | 602 | "sqlite3_bind_XXXX"); |
633 | if (SQLITE_OK != sqlite3_reset (plugin->updPrio)) | 603 | if (SQLITE_OK != sqlite3_reset (plugin->updPrio)) |
634 | LOG_SQLITE (plugin, NULL, | 604 | LOG_SQLITE (plugin, NULL, |
@@ -639,8 +609,7 @@ sqlite_plugin_update (void *cls, | |||
639 | } | 609 | } |
640 | n = sqlite3_step (plugin->updPrio); | 610 | n = sqlite3_step (plugin->updPrio); |
641 | if (SQLITE_OK != sqlite3_reset (plugin->updPrio)) | 611 | if (SQLITE_OK != sqlite3_reset (plugin->updPrio)) |
642 | LOG_SQLITE (plugin, NULL, | 612 | LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
643 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
644 | "sqlite3_reset"); | 613 | "sqlite3_reset"); |
645 | switch (n) | 614 | switch (n) |
646 | { | 615 | { |
@@ -650,13 +619,11 @@ sqlite_plugin_update (void *cls, | |||
650 | #endif | 619 | #endif |
651 | return GNUNET_OK; | 620 | return GNUNET_OK; |
652 | case SQLITE_BUSY: | 621 | case SQLITE_BUSY: |
653 | LOG_SQLITE (plugin, msg, | 622 | LOG_SQLITE (plugin, msg, GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
654 | GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | ||
655 | "sqlite3_step"); | 623 | "sqlite3_step"); |
656 | return GNUNET_NO; | 624 | return GNUNET_NO; |
657 | default: | 625 | default: |
658 | LOG_SQLITE (plugin, msg, | 626 | LOG_SQLITE (plugin, msg, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
659 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
660 | "sqlite3_step"); | 627 | "sqlite3_step"); |
661 | return GNUNET_SYSERR; | 628 | return GNUNET_SYSERR; |
662 | } | 629 | } |
@@ -673,8 +640,8 @@ sqlite_plugin_update (void *cls, | |||
673 | * @param proc_cls closure for 'proc' | 640 | * @param proc_cls closure for 'proc' |
674 | */ | 641 | */ |
675 | static void | 642 | static void |
676 | execute_get (struct Plugin *plugin, | 643 | execute_get (struct Plugin *plugin, sqlite3_stmt * stmt, |
677 | sqlite3_stmt * stmt, PluginDatumProcessor proc, void *proc_cls) | 644 | PluginDatumProcessor proc, void *proc_cls) |
678 | { | 645 | { |
679 | int n; | 646 | int n; |
680 | struct GNUNET_TIME_Absolute expiration; | 647 | struct GNUNET_TIME_Absolute expiration; |
@@ -690,14 +657,13 @@ execute_get (struct Plugin *plugin, | |||
690 | rowid = sqlite3_column_int64 (stmt, 6); | 657 | rowid = sqlite3_column_int64 (stmt, 6); |
691 | if (sqlite3_column_bytes (stmt, 4) != sizeof (GNUNET_HashCode)) | 658 | if (sqlite3_column_bytes (stmt, 4) != sizeof (GNUNET_HashCode)) |
692 | { | 659 | { |
693 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, | 660 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "sqlite", |
694 | "sqlite", | ||
695 | _ | 661 | _ |
696 | ("Invalid data in database. Trying to fix (by deletion).\n")); | 662 | ("Invalid data in database. Trying to fix (by deletion).\n")); |
697 | if (SQLITE_OK != sqlite3_reset (stmt)) | 663 | if (SQLITE_OK != sqlite3_reset (stmt)) |
698 | LOG_SQLITE (plugin, NULL, | 664 | LOG_SQLITE (plugin, NULL, |
699 | GNUNET_ERROR_TYPE_ERROR | | 665 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
700 | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); | 666 | "sqlite3_reset"); |
701 | if (GNUNET_OK == delete_by_rowid (plugin, rowid)) | 667 | if (GNUNET_OK == delete_by_rowid (plugin, rowid)) |
702 | plugin->env->duc (plugin->env->cls, | 668 | plugin->env->duc (plugin->env->cls, |
703 | -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); | 669 | -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); |
@@ -705,8 +671,7 @@ execute_get (struct Plugin *plugin, | |||
705 | } | 671 | } |
706 | expiration.abs_value = sqlite3_column_int64 (stmt, 3); | 672 | expiration.abs_value = sqlite3_column_int64 (stmt, 3); |
707 | #if DEBUG_SQLITE | 673 | #if DEBUG_SQLITE |
708 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 674 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", |
709 | "sqlite", | ||
710 | "Found reply in database with expiration %llu\n", | 675 | "Found reply in database with expiration %llu\n", |
711 | (unsigned long long) expiration.abs_value); | 676 | (unsigned long long) expiration.abs_value); |
712 | #endif | 677 | #endif |
@@ -718,8 +683,8 @@ execute_get (struct Plugin *plugin, | |||
718 | expiration, rowid); | 683 | expiration, rowid); |
719 | if (SQLITE_OK != sqlite3_reset (stmt)) | 684 | if (SQLITE_OK != sqlite3_reset (stmt)) |
720 | LOG_SQLITE (plugin, NULL, | 685 | LOG_SQLITE (plugin, NULL, |
721 | GNUNET_ERROR_TYPE_ERROR | | 686 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
722 | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); | 687 | "sqlite3_reset"); |
723 | if ((GNUNET_NO == ret) && (GNUNET_OK == delete_by_rowid (plugin, rowid))) | 688 | if ((GNUNET_NO == ret) && (GNUNET_OK == delete_by_rowid (plugin, rowid))) |
724 | plugin->env->duc (plugin->env->cls, | 689 | plugin->env->duc (plugin->env->cls, |
725 | -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); | 690 | -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); |
@@ -728,29 +693,27 @@ execute_get (struct Plugin *plugin, | |||
728 | /* database must be empty */ | 693 | /* database must be empty */ |
729 | if (SQLITE_OK != sqlite3_reset (stmt)) | 694 | if (SQLITE_OK != sqlite3_reset (stmt)) |
730 | LOG_SQLITE (plugin, NULL, | 695 | LOG_SQLITE (plugin, NULL, |
731 | GNUNET_ERROR_TYPE_ERROR | | 696 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
732 | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); | 697 | "sqlite3_reset"); |
733 | break; | 698 | break; |
734 | case SQLITE_BUSY: | 699 | case SQLITE_BUSY: |
735 | case SQLITE_ERROR: | 700 | case SQLITE_ERROR: |
736 | case SQLITE_MISUSE: | 701 | case SQLITE_MISUSE: |
737 | default: | 702 | default: |
738 | LOG_SQLITE (plugin, NULL, | 703 | LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
739 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
740 | "sqlite3_step"); | 704 | "sqlite3_step"); |
741 | if (SQLITE_OK != sqlite3_reset (stmt)) | 705 | if (SQLITE_OK != sqlite3_reset (stmt)) |
742 | LOG_SQLITE (plugin, NULL, | 706 | LOG_SQLITE (plugin, NULL, |
743 | GNUNET_ERROR_TYPE_ERROR | | 707 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
744 | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); | 708 | "sqlite3_reset"); |
745 | GNUNET_break (0); | 709 | GNUNET_break (0); |
746 | database_shutdown (plugin); | 710 | database_shutdown (plugin); |
747 | database_setup (plugin->env->cfg, plugin); | 711 | database_setup (plugin->env->cfg, plugin); |
748 | break; | 712 | break; |
749 | } | 713 | } |
750 | if (SQLITE_OK != sqlite3_reset (stmt)) | 714 | if (SQLITE_OK != sqlite3_reset (stmt)) |
751 | LOG_SQLITE (plugin, NULL, | 715 | LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
752 | GNUNET_ERROR_TYPE_ERROR | | 716 | "sqlite3_reset"); |
753 | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); | ||
754 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 717 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
755 | } | 718 | } |
756 | 719 | ||
@@ -770,8 +733,7 @@ execute_get (struct Plugin *plugin, | |||
770 | * @param proc_cls closure for proc | 733 | * @param proc_cls closure for proc |
771 | */ | 734 | */ |
772 | static void | 735 | static void |
773 | sqlite_plugin_get_zero_anonymity (void *cls, | 736 | sqlite_plugin_get_zero_anonymity (void *cls, uint64_t offset, |
774 | uint64_t offset, | ||
775 | enum GNUNET_BLOCK_Type type, | 737 | enum GNUNET_BLOCK_Type type, |
776 | PluginDatumProcessor proc, void *proc_cls) | 738 | PluginDatumProcessor proc, void *proc_cls) |
777 | { | 739 | { |
@@ -783,13 +745,12 @@ sqlite_plugin_get_zero_anonymity (void *cls, | |||
783 | if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) || | 745 | if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) || |
784 | (SQLITE_OK != sqlite3_bind_int64 (stmt, 2, offset))) | 746 | (SQLITE_OK != sqlite3_bind_int64 (stmt, 2, offset))) |
785 | { | 747 | { |
786 | LOG_SQLITE (plugin, NULL, | 748 | LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
787 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
788 | "sqlite3_bind_XXXX"); | 749 | "sqlite3_bind_XXXX"); |
789 | if (SQLITE_OK != sqlite3_reset (stmt)) | 750 | if (SQLITE_OK != sqlite3_reset (stmt)) |
790 | LOG_SQLITE (plugin, NULL, | 751 | LOG_SQLITE (plugin, NULL, |
791 | GNUNET_ERROR_TYPE_ERROR | | 752 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
792 | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); | 753 | "sqlite3_reset"); |
793 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 754 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
794 | return; | 755 | return; |
795 | } | 756 | } |
@@ -816,12 +777,10 @@ sqlite_plugin_get_zero_anonymity (void *cls, | |||
816 | * @param proc_cls closure for proc | 777 | * @param proc_cls closure for proc |
817 | */ | 778 | */ |
818 | static void | 779 | static void |
819 | sqlite_plugin_get_key (void *cls, | 780 | sqlite_plugin_get_key (void *cls, uint64_t offset, const GNUNET_HashCode * key, |
820 | uint64_t offset, | ||
821 | const GNUNET_HashCode * key, | ||
822 | const GNUNET_HashCode * vhash, | 781 | const GNUNET_HashCode * vhash, |
823 | enum GNUNET_BLOCK_Type type, | 782 | enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, |
824 | PluginDatumProcessor proc, void *proc_cls) | 783 | void *proc_cls) |
825 | { | 784 | { |
826 | struct Plugin *plugin = cls; | 785 | struct Plugin *plugin = cls; |
827 | int ret; | 786 | int ret; |
@@ -839,18 +798,19 @@ sqlite_plugin_get_key (void *cls, | |||
839 | type == 0 ? "" : " AND type=?"); | 798 | type == 0 ? "" : " AND type=?"); |
840 | if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK) | 799 | if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK) |
841 | { | 800 | { |
842 | LOG_SQLITE (plugin, NULL, | 801 | LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
843 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
844 | "sqlite_prepare"); | 802 | "sqlite_prepare"); |
845 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 803 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
846 | return; | 804 | return; |
847 | } | 805 | } |
848 | sqoff = 1; | 806 | sqoff = 1; |
849 | ret = sqlite3_bind_blob (stmt, sqoff++, | 807 | ret = |
850 | key, sizeof (GNUNET_HashCode), SQLITE_TRANSIENT); | 808 | sqlite3_bind_blob (stmt, sqoff++, key, sizeof (GNUNET_HashCode), |
809 | SQLITE_TRANSIENT); | ||
851 | if ((vhash != NULL) && (ret == SQLITE_OK)) | 810 | if ((vhash != NULL) && (ret == SQLITE_OK)) |
852 | ret = sqlite3_bind_blob (stmt, sqoff++, | 811 | ret = |
853 | vhash, sizeof (GNUNET_HashCode), SQLITE_TRANSIENT); | 812 | sqlite3_bind_blob (stmt, sqoff++, vhash, sizeof (GNUNET_HashCode), |
813 | SQLITE_TRANSIENT); | ||
854 | if ((type != 0) && (ret == SQLITE_OK)) | 814 | if ((type != 0) && (ret == SQLITE_OK)) |
855 | ret = sqlite3_bind_int (stmt, sqoff++, type); | 815 | ret = sqlite3_bind_int (stmt, sqoff++, type); |
856 | if (SQLITE_OK != ret) | 816 | if (SQLITE_OK != ret) |
@@ -863,8 +823,7 @@ sqlite_plugin_get_key (void *cls, | |||
863 | ret = sqlite3_step (stmt); | 823 | ret = sqlite3_step (stmt); |
864 | if (ret != SQLITE_ROW) | 824 | if (ret != SQLITE_ROW) |
865 | { | 825 | { |
866 | LOG_SQLITE (plugin, NULL, | 826 | LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
867 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
868 | "sqlite_step"); | 827 | "sqlite_step"); |
869 | sqlite3_finalize (stmt); | 828 | sqlite3_finalize (stmt); |
870 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 829 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
@@ -888,29 +847,27 @@ sqlite_plugin_get_key (void *cls, | |||
888 | type == 0 ? "" : " AND type=?"); | 847 | type == 0 ? "" : " AND type=?"); |
889 | if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK) | 848 | if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK) |
890 | { | 849 | { |
891 | LOG_SQLITE (plugin, NULL, | 850 | LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
892 | GNUNET_ERROR_TYPE_ERROR | | 851 | "sqlite_prepare"); |
893 | GNUNET_ERROR_TYPE_BULK, "sqlite_prepare"); | ||
894 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 852 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
895 | return; | 853 | return; |
896 | } | 854 | } |
897 | sqoff = 1; | 855 | sqoff = 1; |
898 | ret = sqlite3_bind_blob (stmt, | 856 | ret = |
899 | sqoff++, | 857 | sqlite3_bind_blob (stmt, sqoff++, key, sizeof (GNUNET_HashCode), |
900 | key, sizeof (GNUNET_HashCode), SQLITE_TRANSIENT); | 858 | SQLITE_TRANSIENT); |
901 | if ((vhash != NULL) && (ret == SQLITE_OK)) | 859 | if ((vhash != NULL) && (ret == SQLITE_OK)) |
902 | ret = sqlite3_bind_blob (stmt, | 860 | ret = |
903 | sqoff++, | 861 | sqlite3_bind_blob (stmt, sqoff++, vhash, sizeof (GNUNET_HashCode), |
904 | vhash, sizeof (GNUNET_HashCode), SQLITE_TRANSIENT); | 862 | SQLITE_TRANSIENT); |
905 | if ((type != 0) && (ret == SQLITE_OK)) | 863 | if ((type != 0) && (ret == SQLITE_OK)) |
906 | ret = sqlite3_bind_int (stmt, sqoff++, type); | 864 | ret = sqlite3_bind_int (stmt, sqoff++, type); |
907 | if (ret == SQLITE_OK) | 865 | if (ret == SQLITE_OK) |
908 | ret = sqlite3_bind_int64 (stmt, sqoff++, limit_off); | 866 | ret = sqlite3_bind_int64 (stmt, sqoff++, limit_off); |
909 | if (ret != SQLITE_OK) | 867 | if (ret != SQLITE_OK) |
910 | { | 868 | { |
911 | LOG_SQLITE (plugin, NULL, | 869 | LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
912 | GNUNET_ERROR_TYPE_ERROR | | 870 | "sqlite_bind"); |
913 | GNUNET_ERROR_TYPE_BULK, "sqlite_bind"); | ||
914 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 871 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
915 | return; | 872 | return; |
916 | } | 873 | } |
@@ -968,20 +925,17 @@ struct ReplCtx | |||
968 | * GNUNET_NO to delete the item | 925 | * GNUNET_NO to delete the item |
969 | */ | 926 | */ |
970 | static int | 927 | static int |
971 | repl_proc (void *cls, | 928 | repl_proc (void *cls, const GNUNET_HashCode * key, uint32_t size, |
972 | const GNUNET_HashCode * key, | 929 | const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, |
973 | uint32_t size, | 930 | uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, |
974 | const void *data, | 931 | uint64_t uid) |
975 | enum GNUNET_BLOCK_Type type, | ||
976 | uint32_t priority, | ||
977 | uint32_t anonymity, | ||
978 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | ||
979 | { | 932 | { |
980 | struct ReplCtx *rc = cls; | 933 | struct ReplCtx *rc = cls; |
981 | int ret; | 934 | int ret; |
982 | 935 | ||
983 | ret = rc->proc (rc->proc_cls, | 936 | ret = |
984 | key, size, data, type, priority, anonymity, expiration, uid); | 937 | rc->proc (rc->proc_cls, key, size, data, type, priority, anonymity, |
938 | expiration, uid); | ||
985 | if (key != NULL) | 939 | if (key != NULL) |
986 | { | 940 | { |
987 | rc->uid = uid; | 941 | rc->uid = uid; |
@@ -1002,8 +956,8 @@ repl_proc (void *cls, | |||
1002 | * @param proc_cls closure for proc | 956 | * @param proc_cls closure for proc |
1003 | */ | 957 | */ |
1004 | static void | 958 | static void |
1005 | sqlite_plugin_get_replication (void *cls, | 959 | sqlite_plugin_get_replication (void *cls, PluginDatumProcessor proc, |
1006 | PluginDatumProcessor proc, void *proc_cls) | 960 | void *proc_cls) |
1007 | { | 961 | { |
1008 | struct Plugin *plugin = cls; | 962 | struct Plugin *plugin = cls; |
1009 | struct ReplCtx rc; | 963 | struct ReplCtx rc; |
@@ -1012,8 +966,7 @@ sqlite_plugin_get_replication (void *cls, | |||
1012 | sqlite3_stmt *stmt; | 966 | sqlite3_stmt *stmt; |
1013 | 967 | ||
1014 | #if DEBUG_SQLITE | 968 | #if DEBUG_SQLITE |
1015 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 969 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", |
1016 | "sqlite", | ||
1017 | "Getting random block based on replication order.\n"); | 970 | "Getting random block based on replication order.\n"); |
1018 | #endif | 971 | #endif |
1019 | rc.have_uid = GNUNET_NO; | 972 | rc.have_uid = GNUNET_NO; |
@@ -1024,23 +977,21 @@ sqlite_plugin_get_replication (void *cls, | |||
1024 | { | 977 | { |
1025 | if (SQLITE_OK != sqlite3_reset (stmt)) | 978 | if (SQLITE_OK != sqlite3_reset (stmt)) |
1026 | LOG_SQLITE (plugin, NULL, | 979 | LOG_SQLITE (plugin, NULL, |
1027 | GNUNET_ERROR_TYPE_ERROR | | 980 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1028 | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); | 981 | "sqlite3_reset"); |
1029 | /* DB empty */ | 982 | /* DB empty */ |
1030 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 983 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
1031 | return; | 984 | return; |
1032 | } | 985 | } |
1033 | repl = sqlite3_column_int (stmt, 0); | 986 | repl = sqlite3_column_int (stmt, 0); |
1034 | if (SQLITE_OK != sqlite3_reset (stmt)) | 987 | if (SQLITE_OK != sqlite3_reset (stmt)) |
1035 | LOG_SQLITE (plugin, NULL, | 988 | LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1036 | GNUNET_ERROR_TYPE_ERROR | | 989 | "sqlite3_reset"); |
1037 | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); | ||
1038 | stmt = plugin->selRepl; | 990 | stmt = plugin->selRepl; |
1039 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); | 991 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); |
1040 | if (SQLITE_OK != sqlite3_bind_int64 (stmt, 1, rvalue)) | 992 | if (SQLITE_OK != sqlite3_bind_int64 (stmt, 1, rvalue)) |
1041 | { | 993 | { |
1042 | LOG_SQLITE (plugin, NULL, | 994 | LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1043 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
1044 | "sqlite3_bind_XXXX"); | 995 | "sqlite3_bind_XXXX"); |
1045 | if (SQLITE_OK != sqlite3_reset (stmt)) | 996 | if (SQLITE_OK != sqlite3_reset (stmt)) |
1046 | LOG_SQLITE (plugin, NULL, | 997 | LOG_SQLITE (plugin, NULL, |
@@ -1051,8 +1002,7 @@ sqlite_plugin_get_replication (void *cls, | |||
1051 | } | 1002 | } |
1052 | if (SQLITE_OK != sqlite3_bind_int (stmt, 2, repl)) | 1003 | if (SQLITE_OK != sqlite3_bind_int (stmt, 2, repl)) |
1053 | { | 1004 | { |
1054 | LOG_SQLITE (plugin, NULL, | 1005 | LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1055 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
1056 | "sqlite3_bind_XXXX"); | 1006 | "sqlite3_bind_XXXX"); |
1057 | if (SQLITE_OK != sqlite3_reset (stmt)) | 1007 | if (SQLITE_OK != sqlite3_reset (stmt)) |
1058 | LOG_SQLITE (plugin, NULL, | 1008 | LOG_SQLITE (plugin, NULL, |
@@ -1071,18 +1021,18 @@ sqlite_plugin_get_replication (void *cls, | |||
1071 | "sqlite3_bind_XXXX"); | 1021 | "sqlite3_bind_XXXX"); |
1072 | if (SQLITE_OK != sqlite3_reset (plugin->updRepl)) | 1022 | if (SQLITE_OK != sqlite3_reset (plugin->updRepl)) |
1073 | LOG_SQLITE (plugin, NULL, | 1023 | LOG_SQLITE (plugin, NULL, |
1074 | GNUNET_ERROR_TYPE_ERROR | | 1024 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1075 | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); | 1025 | "sqlite3_reset"); |
1076 | return; | 1026 | return; |
1077 | } | 1027 | } |
1078 | if (SQLITE_DONE != sqlite3_step (plugin->updRepl)) | 1028 | if (SQLITE_DONE != sqlite3_step (plugin->updRepl)) |
1079 | LOG_SQLITE (plugin, NULL, | 1029 | LOG_SQLITE (plugin, NULL, |
1080 | GNUNET_ERROR_TYPE_ERROR | | 1030 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1081 | GNUNET_ERROR_TYPE_BULK, "sqlite3_step"); | 1031 | "sqlite3_step"); |
1082 | if (SQLITE_OK != sqlite3_reset (plugin->updRepl)) | 1032 | if (SQLITE_OK != sqlite3_reset (plugin->updRepl)) |
1083 | LOG_SQLITE (plugin, NULL, | 1033 | LOG_SQLITE (plugin, NULL, |
1084 | GNUNET_ERROR_TYPE_ERROR | | 1034 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1085 | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); | 1035 | "sqlite3_reset"); |
1086 | } | 1036 | } |
1087 | } | 1037 | } |
1088 | 1038 | ||
@@ -1097,24 +1047,22 @@ sqlite_plugin_get_replication (void *cls, | |||
1097 | * @param proc_cls closure for proc | 1047 | * @param proc_cls closure for proc |
1098 | */ | 1048 | */ |
1099 | static void | 1049 | static void |
1100 | sqlite_plugin_get_expiration (void *cls, | 1050 | sqlite_plugin_get_expiration (void *cls, PluginDatumProcessor proc, |
1101 | PluginDatumProcessor proc, void *proc_cls) | 1051 | void *proc_cls) |
1102 | { | 1052 | { |
1103 | struct Plugin *plugin = cls; | 1053 | struct Plugin *plugin = cls; |
1104 | sqlite3_stmt *stmt; | 1054 | sqlite3_stmt *stmt; |
1105 | struct GNUNET_TIME_Absolute now; | 1055 | struct GNUNET_TIME_Absolute now; |
1106 | 1056 | ||
1107 | #if DEBUG_SQLITE | 1057 | #if DEBUG_SQLITE |
1108 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1058 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", |
1109 | "sqlite", | ||
1110 | "Getting random block based on expiration and priority order.\n"); | 1059 | "Getting random block based on expiration and priority order.\n"); |
1111 | #endif | 1060 | #endif |
1112 | now = GNUNET_TIME_absolute_get (); | 1061 | now = GNUNET_TIME_absolute_get (); |
1113 | stmt = plugin->selExpi; | 1062 | stmt = plugin->selExpi; |
1114 | if (SQLITE_OK != sqlite3_bind_int64 (stmt, 1, now.abs_value)) | 1063 | if (SQLITE_OK != sqlite3_bind_int64 (stmt, 1, now.abs_value)) |
1115 | { | 1064 | { |
1116 | LOG_SQLITE (plugin, NULL, | 1065 | LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1117 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
1118 | "sqlite3_bind_XXXX"); | 1066 | "sqlite3_bind_XXXX"); |
1119 | if (SQLITE_OK != sqlite3_reset (stmt)) | 1067 | if (SQLITE_OK != sqlite3_reset (stmt)) |
1120 | LOG_SQLITE (plugin, NULL, | 1068 | LOG_SQLITE (plugin, NULL, |
@@ -1162,16 +1110,15 @@ sqlite_plugin_estimate_size (void *cls) | |||
1162 | 1110 | ||
1163 | if (SQLITE_VERSION_NUMBER < 3006000) | 1111 | if (SQLITE_VERSION_NUMBER < 3006000) |
1164 | { | 1112 | { |
1165 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, | 1113 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "datastore-sqlite", |
1166 | "datastore-sqlite", | ||
1167 | _ | 1114 | _ |
1168 | ("sqlite version to old to determine size, assuming zero\n")); | 1115 | ("sqlite version to old to determine size, assuming zero\n")); |
1169 | return 0; | 1116 | return 0; |
1170 | } | 1117 | } |
1171 | CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, "VACUUM", NULL, NULL, ENULL)); | 1118 | CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, "VACUUM", NULL, NULL, ENULL)); |
1172 | CHECK (SQLITE_OK == | 1119 | CHECK (SQLITE_OK == |
1173 | sqlite3_exec (plugin->dbh, | 1120 | sqlite3_exec (plugin->dbh, "PRAGMA auto_vacuum=INCREMENTAL", NULL, |
1174 | "PRAGMA auto_vacuum=INCREMENTAL", NULL, NULL, ENULL)); | 1121 | NULL, ENULL)); |
1175 | CHECK (SQLITE_OK == sq_prepare (plugin->dbh, "PRAGMA page_count", &stmt)); | 1122 | CHECK (SQLITE_OK == sq_prepare (plugin->dbh, "PRAGMA page_count", &stmt)); |
1176 | if (SQLITE_ROW == sqlite3_step (stmt)) | 1123 | if (SQLITE_ROW == sqlite3_step (stmt)) |
1177 | pages = sqlite3_column_int64 (stmt, 0); | 1124 | pages = sqlite3_column_int64 (stmt, 0); |
@@ -1222,8 +1169,8 @@ libgnunet_plugin_datastore_sqlite_init (void *cls) | |||
1222 | api->get_expiration = &sqlite_plugin_get_expiration; | 1169 | api->get_expiration = &sqlite_plugin_get_expiration; |
1223 | api->get_zero_anonymity = &sqlite_plugin_get_zero_anonymity; | 1170 | api->get_zero_anonymity = &sqlite_plugin_get_zero_anonymity; |
1224 | api->drop = &sqlite_plugin_drop; | 1171 | api->drop = &sqlite_plugin_drop; |
1225 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, | 1172 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "sqlite", |
1226 | "sqlite", _("Sqlite database running\n")); | 1173 | _("Sqlite database running\n")); |
1227 | return api; | 1174 | return api; |
1228 | } | 1175 | } |
1229 | 1176 | ||
@@ -1242,16 +1189,16 @@ libgnunet_plugin_datastore_sqlite_done (void *cls) | |||
1242 | struct Plugin *plugin = api->cls; | 1189 | struct Plugin *plugin = api->cls; |
1243 | 1190 | ||
1244 | #if DEBUG_SQLITE | 1191 | #if DEBUG_SQLITE |
1245 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1192 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", |
1246 | "sqlite", "sqlite plugin is done\n"); | 1193 | "sqlite plugin is done\n"); |
1247 | #endif | 1194 | #endif |
1248 | 1195 | ||
1249 | fn = NULL; | 1196 | fn = NULL; |
1250 | if (plugin->drop_on_shutdown) | 1197 | if (plugin->drop_on_shutdown) |
1251 | fn = GNUNET_strdup (plugin->fn); | 1198 | fn = GNUNET_strdup (plugin->fn); |
1252 | #if DEBUG_SQLITE | 1199 | #if DEBUG_SQLITE |
1253 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1200 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", |
1254 | "sqlite", "Shutting down database\n"); | 1201 | "Shutting down database\n"); |
1255 | #endif | 1202 | #endif |
1256 | database_shutdown (plugin); | 1203 | database_shutdown (plugin); |
1257 | plugin->env = NULL; | 1204 | plugin->env = NULL; |
@@ -1263,8 +1210,8 @@ libgnunet_plugin_datastore_sqlite_done (void *cls) | |||
1263 | GNUNET_free (fn); | 1210 | GNUNET_free (fn); |
1264 | } | 1211 | } |
1265 | #if DEBUG_SQLITE | 1212 | #if DEBUG_SQLITE |
1266 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1213 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", |
1267 | "sqlite", "sqlite plugin is finished\n"); | 1214 | "sqlite plugin is finished\n"); |
1268 | #endif | 1215 | #endif |
1269 | return NULL; | 1216 | return NULL; |
1270 | } | 1217 | } |
diff --git a/src/datastore/plugin_datastore_template.c b/src/datastore/plugin_datastore_template.c index 7ab469140..566155fb5 100644 --- a/src/datastore/plugin_datastore_template.c +++ b/src/datastore/plugin_datastore_template.c | |||
@@ -71,13 +71,9 @@ template_plugin_estimate_size (void *cls) | |||
71 | * @return GNUNET_OK on success | 71 | * @return GNUNET_OK on success |
72 | */ | 72 | */ |
73 | static int | 73 | static int |
74 | template_plugin_put (void *cls, | 74 | template_plugin_put (void *cls, const GNUNET_HashCode * key, uint32_t size, |
75 | const GNUNET_HashCode * key, | 75 | const void *data, enum GNUNET_BLOCK_Type type, |
76 | uint32_t size, | 76 | uint32_t priority, uint32_t anonymity, |
77 | const void *data, | ||
78 | enum GNUNET_BLOCK_Type type, | ||
79 | uint32_t priority, | ||
80 | uint32_t anonymity, | ||
81 | uint32_t replication, | 77 | uint32_t replication, |
82 | struct GNUNET_TIME_Absolute expiration, char **msg) | 78 | struct GNUNET_TIME_Absolute expiration, char **msg) |
83 | { | 79 | { |
@@ -106,12 +102,11 @@ template_plugin_put (void *cls, | |||
106 | * @param proc_cls closure for proc | 102 | * @param proc_cls closure for proc |
107 | */ | 103 | */ |
108 | static void | 104 | static void |
109 | template_plugin_get_key (void *cls, | 105 | template_plugin_get_key (void *cls, uint64_t offset, |
110 | uint64_t offset, | ||
111 | const GNUNET_HashCode * key, | 106 | const GNUNET_HashCode * key, |
112 | const GNUNET_HashCode * vhash, | 107 | const GNUNET_HashCode * vhash, |
113 | enum GNUNET_BLOCK_Type type, | 108 | enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, |
114 | PluginDatumProcessor proc, void *proc_cls) | 109 | void *proc_cls) |
115 | { | 110 | { |
116 | GNUNET_break (0); | 111 | GNUNET_break (0); |
117 | } | 112 | } |
@@ -130,8 +125,8 @@ template_plugin_get_key (void *cls, | |||
130 | * @param proc_cls closure for proc | 125 | * @param proc_cls closure for proc |
131 | */ | 126 | */ |
132 | static void | 127 | static void |
133 | template_plugin_get_replication (void *cls, | 128 | template_plugin_get_replication (void *cls, PluginDatumProcessor proc, |
134 | PluginDatumProcessor proc, void *proc_cls) | 129 | void *proc_cls) |
135 | { | 130 | { |
136 | GNUNET_break (0); | 131 | GNUNET_break (0); |
137 | } | 132 | } |
@@ -146,8 +141,8 @@ template_plugin_get_replication (void *cls, | |||
146 | * @param proc_cls closure for proc | 141 | * @param proc_cls closure for proc |
147 | */ | 142 | */ |
148 | static void | 143 | static void |
149 | template_plugin_get_expiration (void *cls, | 144 | template_plugin_get_expiration (void *cls, PluginDatumProcessor proc, |
150 | PluginDatumProcessor proc, void *proc_cls) | 145 | void *proc_cls) |
151 | { | 146 | { |
152 | GNUNET_break (0); | 147 | GNUNET_break (0); |
153 | } | 148 | } |
@@ -177,9 +172,7 @@ template_plugin_get_expiration (void *cls, | |||
177 | * @return GNUNET_OK on success | 172 | * @return GNUNET_OK on success |
178 | */ | 173 | */ |
179 | static int | 174 | static int |
180 | template_plugin_update (void *cls, | 175 | template_plugin_update (void *cls, uint64_t uid, int delta, |
181 | uint64_t uid, | ||
182 | int delta, | ||
183 | struct GNUNET_TIME_Absolute expire, char **msg) | 176 | struct GNUNET_TIME_Absolute expire, char **msg) |
184 | { | 177 | { |
185 | GNUNET_break (0); | 178 | GNUNET_break (0); |
@@ -201,8 +194,7 @@ template_plugin_update (void *cls, | |||
201 | * @param proc_cls closure for proc | 194 | * @param proc_cls closure for proc |
202 | */ | 195 | */ |
203 | static void | 196 | static void |
204 | template_plugin_get_zero_anonymity (void *cls, | 197 | template_plugin_get_zero_anonymity (void *cls, uint64_t offset, |
205 | uint64_t offset, | ||
206 | enum GNUNET_BLOCK_Type type, | 198 | enum GNUNET_BLOCK_Type type, |
207 | PluginDatumProcessor proc, void *proc_cls) | 199 | PluginDatumProcessor proc, void *proc_cls) |
208 | { | 200 | { |
@@ -245,8 +237,8 @@ libgnunet_plugin_datastore_template_init (void *cls) | |||
245 | api->get_expiration = &template_plugin_get_expiration; | 237 | api->get_expiration = &template_plugin_get_expiration; |
246 | api->get_zero_anonymity = &template_plugin_get_zero_anonymity; | 238 | api->get_zero_anonymity = &template_plugin_get_zero_anonymity; |
247 | api->drop = &template_plugin_drop; | 239 | api->drop = &template_plugin_drop; |
248 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, | 240 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "template", |
249 | "template", _("Template database running\n")); | 241 | _("Template database running\n")); |
250 | return api; | 242 | return api; |
251 | } | 243 | } |
252 | 244 | ||
diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c index 39b7a1ae2..3dff4a588 100644 --- a/src/datastore/test_datastore_api.c +++ b/src/datastore/test_datastore_api.c | |||
@@ -134,8 +134,8 @@ struct CpsRunContext | |||
134 | }; | 134 | }; |
135 | 135 | ||
136 | 136 | ||
137 | static void | 137 | static void run_continuation (void *cls, |
138 | run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 138 | const struct GNUNET_SCHEDULER_TaskContext *tc); |
139 | 139 | ||
140 | 140 | ||
141 | static void | 141 | static void |
@@ -146,14 +146,14 @@ check_success (void *cls, int success, const char *msg) | |||
146 | if (GNUNET_OK != success) | 146 | if (GNUNET_OK != success) |
147 | { | 147 | { |
148 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 148 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
149 | "Operation %d/%d not successfull: `%s'\n", | 149 | "Operation %d/%d not successfull: `%s'\n", crc->phase, crc->i, |
150 | crc->phase, crc->i, msg); | 150 | msg); |
151 | crc->phase = RP_ERROR; | 151 | crc->phase = RP_ERROR; |
152 | } | 152 | } |
153 | GNUNET_free_non_null (crc->data); | 153 | GNUNET_free_non_null (crc->data); |
154 | crc->data = NULL; | 154 | crc->data = NULL; |
155 | GNUNET_SCHEDULER_add_continuation (&run_continuation, | 155 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, |
156 | crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 156 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
157 | } | 157 | } |
158 | 158 | ||
159 | 159 | ||
@@ -163,40 +163,33 @@ get_reserved (void *cls, int success, const char *msg) | |||
163 | struct CpsRunContext *crc = cls; | 163 | struct CpsRunContext *crc = cls; |
164 | 164 | ||
165 | if (0 >= success) | 165 | if (0 >= success) |
166 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 166 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error obtaining reservation: `%s'\n", |
167 | "Error obtaining reservation: `%s'\n", msg); | 167 | msg); |
168 | GNUNET_assert (0 < success); | 168 | GNUNET_assert (0 < success); |
169 | crc->rid = success; | 169 | crc->rid = success; |
170 | GNUNET_SCHEDULER_add_continuation (&run_continuation, | 170 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, |
171 | crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 171 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
172 | } | 172 | } |
173 | 173 | ||
174 | 174 | ||
175 | static void | 175 | static void |
176 | check_value (void *cls, | 176 | check_value (void *cls, const GNUNET_HashCode * key, size_t size, |
177 | const GNUNET_HashCode * key, | 177 | const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, |
178 | size_t size, | 178 | uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, |
179 | const void *data, | 179 | uint64_t uid) |
180 | enum GNUNET_BLOCK_Type type, | ||
181 | uint32_t priority, | ||
182 | uint32_t anonymity, | ||
183 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | ||
184 | { | 180 | { |
185 | struct CpsRunContext *crc = cls; | 181 | struct CpsRunContext *crc = cls; |
186 | int i; | 182 | int i; |
187 | 183 | ||
188 | i = crc->i; | 184 | i = crc->i; |
189 | #if 0 | 185 | #if 0 |
186 | fprintf (stderr, "Check value got `%s' of size %u, type %d, expire %llu\n", | ||
187 | GNUNET_h2s (key), (unsigned int) size, type, | ||
188 | (unsigned long long) expiration.abs_value); | ||
190 | fprintf (stderr, | 189 | fprintf (stderr, |
191 | "Check value got `%s' of size %u, type %d, expire %llu\n", | 190 | "Check value iteration %d wants size %u, type %d, expire %llu\n", i, |
192 | GNUNET_h2s (key), | 191 | (unsigned int) get_size (i), get_type (i), |
193 | (unsigned int) size, | 192 | (unsigned long long) get_expiration (i).abs_value); |
194 | type, (unsigned long long) expiration.abs_value); | ||
195 | fprintf (stderr, | ||
196 | "Check value iteration %d wants size %u, type %d, expire %llu\n", | ||
197 | i, | ||
198 | (unsigned int) get_size (i), | ||
199 | get_type (i), (unsigned long long) get_expiration (i).abs_value); | ||
200 | #endif | 193 | #endif |
201 | GNUNET_assert (size == get_size (i)); | 194 | GNUNET_assert (size == get_size (i)); |
202 | GNUNET_assert (0 == memcmp (data, get_data (i), size)); | 195 | GNUNET_assert (0 == memcmp (data, get_data (i), size)); |
@@ -210,20 +203,16 @@ check_value (void *cls, | |||
210 | crc->phase = RP_DEL; | 203 | crc->phase = RP_DEL; |
211 | crc->i = ITERATIONS; | 204 | crc->i = ITERATIONS; |
212 | } | 205 | } |
213 | GNUNET_SCHEDULER_add_continuation (&run_continuation, | 206 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, |
214 | crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 207 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
215 | } | 208 | } |
216 | 209 | ||
217 | 210 | ||
218 | static void | 211 | static void |
219 | delete_value (void *cls, | 212 | delete_value (void *cls, const GNUNET_HashCode * key, size_t size, |
220 | const GNUNET_HashCode * key, | 213 | const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, |
221 | size_t size, | 214 | uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, |
222 | const void *data, | 215 | uint64_t uid) |
223 | enum GNUNET_BLOCK_Type type, | ||
224 | uint32_t priority, | ||
225 | uint32_t anonymity, | ||
226 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | ||
227 | { | 216 | { |
228 | struct CpsRunContext *crc = cls; | 217 | struct CpsRunContext *crc = cls; |
229 | 218 | ||
@@ -234,39 +223,31 @@ delete_value (void *cls, | |||
234 | crc->data = GNUNET_malloc (size); | 223 | crc->data = GNUNET_malloc (size); |
235 | memcpy (crc->data, data, size); | 224 | memcpy (crc->data, data, size); |
236 | crc->phase = RP_DO_DEL; | 225 | crc->phase = RP_DO_DEL; |
237 | GNUNET_SCHEDULER_add_continuation (&run_continuation, | 226 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, |
238 | crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 227 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
239 | } | 228 | } |
240 | 229 | ||
241 | 230 | ||
242 | static void | 231 | static void |
243 | check_nothing (void *cls, | 232 | check_nothing (void *cls, const GNUNET_HashCode * key, size_t size, |
244 | const GNUNET_HashCode * key, | 233 | const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, |
245 | size_t size, | 234 | uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, |
246 | const void *data, | 235 | uint64_t uid) |
247 | enum GNUNET_BLOCK_Type type, | ||
248 | uint32_t priority, | ||
249 | uint32_t anonymity, | ||
250 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | ||
251 | { | 236 | { |
252 | struct CpsRunContext *crc = cls; | 237 | struct CpsRunContext *crc = cls; |
253 | 238 | ||
254 | GNUNET_assert (key == NULL); | 239 | GNUNET_assert (key == NULL); |
255 | if (crc->i == 0) | 240 | if (crc->i == 0) |
256 | crc->phase = RP_RESERVE; | 241 | crc->phase = RP_RESERVE; |
257 | GNUNET_SCHEDULER_add_continuation (&run_continuation, | 242 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, |
258 | crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 243 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
259 | } | 244 | } |
260 | 245 | ||
261 | 246 | ||
262 | static void | 247 | static void |
263 | check_multiple (void *cls, | 248 | check_multiple (void *cls, const GNUNET_HashCode * key, size_t size, |
264 | const GNUNET_HashCode * key, | 249 | const void *data, enum GNUNET_BLOCK_Type type, |
265 | size_t size, | 250 | uint32_t priority, uint32_t anonymity, |
266 | const void *data, | ||
267 | enum GNUNET_BLOCK_Type type, | ||
268 | uint32_t priority, | ||
269 | uint32_t anonymity, | ||
270 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | 251 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) |
271 | { | 252 | { |
272 | struct CpsRunContext *crc = cls; | 253 | struct CpsRunContext *crc = cls; |
@@ -290,34 +271,30 @@ check_multiple (void *cls, | |||
290 | } | 271 | } |
291 | if (priority == get_priority (42)) | 272 | if (priority == get_priority (42)) |
292 | crc->uid = uid; | 273 | crc->uid = uid; |
293 | GNUNET_SCHEDULER_add_continuation (&run_continuation, | 274 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, |
294 | crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 275 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
295 | } | 276 | } |
296 | 277 | ||
297 | 278 | ||
298 | static void | 279 | static void |
299 | check_update (void *cls, | 280 | check_update (void *cls, const GNUNET_HashCode * key, size_t size, |
300 | const GNUNET_HashCode * key, | 281 | const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, |
301 | size_t size, | 282 | uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, |
302 | const void *data, | 283 | uint64_t uid) |
303 | enum GNUNET_BLOCK_Type type, | ||
304 | uint32_t priority, | ||
305 | uint32_t anonymity, | ||
306 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | ||
307 | { | 284 | { |
308 | struct CpsRunContext *crc = cls; | 285 | struct CpsRunContext *crc = cls; |
309 | 286 | ||
310 | GNUNET_assert (key != NULL); | 287 | GNUNET_assert (key != NULL); |
311 | if ((anonymity == get_anonymity (42)) && | 288 | if ((anonymity == get_anonymity (42)) && (size == get_size (42)) && |
312 | (size == get_size (42)) && (priority == get_priority (42) + 100)) | 289 | (priority == get_priority (42) + 100)) |
313 | crc->phase = RP_DONE; | 290 | crc->phase = RP_DONE; |
314 | else | 291 | else |
315 | { | 292 | { |
316 | GNUNET_assert (size == get_size (43)); | 293 | GNUNET_assert (size == get_size (43)); |
317 | crc->offset++; | 294 | crc->offset++; |
318 | } | 295 | } |
319 | GNUNET_SCHEDULER_add_continuation (&run_continuation, | 296 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, |
320 | crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 297 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
321 | } | 298 | } |
322 | 299 | ||
323 | 300 | ||
@@ -334,21 +311,15 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
334 | { | 311 | { |
335 | case RP_PUT: | 312 | case RP_PUT: |
336 | #if VERBOSE | 313 | #if VERBOSE |
337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 314 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "PUT", |
338 | "Executing `%s' number %u\n", "PUT", crc->i); | 315 | crc->i); |
339 | #endif | 316 | #endif |
340 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); | 317 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); |
341 | GNUNET_DATASTORE_put (datastore, | 318 | GNUNET_DATASTORE_put (datastore, 0, &crc->key, get_size (crc->i), |
342 | 0, | 319 | get_data (crc->i), get_type (crc->i), |
343 | &crc->key, | 320 | get_priority (crc->i), get_anonymity (crc->i), 0, |
344 | get_size (crc->i), | 321 | get_expiration (crc->i), 1, 1, TIMEOUT, |
345 | get_data (crc->i), | 322 | &check_success, crc); |
346 | get_type (crc->i), | ||
347 | get_priority (crc->i), | ||
348 | get_anonymity (crc->i), | ||
349 | 0, | ||
350 | get_expiration (crc->i), | ||
351 | 1, 1, TIMEOUT, &check_success, crc); | ||
352 | crc->i++; | 323 | crc->i++; |
353 | if (crc->i == ITERATIONS) | 324 | if (crc->i == ITERATIONS) |
354 | crc->phase = RP_GET; | 325 | crc->phase = RP_GET; |
@@ -356,36 +327,31 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
356 | case RP_GET: | 327 | case RP_GET: |
357 | crc->i--; | 328 | crc->i--; |
358 | #if VERBOSE | 329 | #if VERBOSE |
359 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 330 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET", |
360 | "Executing `%s' number %u\n", "GET", crc->i); | 331 | crc->i); |
361 | #endif | 332 | #endif |
362 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); | 333 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); |
363 | GNUNET_DATASTORE_get_key (datastore, | 334 | GNUNET_DATASTORE_get_key (datastore, crc->offset, &crc->key, |
364 | crc->offset, | 335 | get_type (crc->i), 1, 1, TIMEOUT, &check_value, |
365 | &crc->key, | 336 | crc); |
366 | get_type (crc->i), | ||
367 | 1, 1, TIMEOUT, &check_value, crc); | ||
368 | break; | 337 | break; |
369 | case RP_DEL: | 338 | case RP_DEL: |
370 | crc->i--; | 339 | crc->i--; |
371 | #if VERBOSE | 340 | #if VERBOSE |
372 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 341 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "DEL", |
373 | "Executing `%s' number %u\n", "DEL", crc->i); | 342 | crc->i); |
374 | #endif | 343 | #endif |
375 | crc->data = NULL; | 344 | crc->data = NULL; |
376 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); | 345 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); |
377 | GNUNET_assert (NULL != | 346 | GNUNET_assert (NULL != |
378 | GNUNET_DATASTORE_get_key (datastore, | 347 | GNUNET_DATASTORE_get_key (datastore, crc->offset, &crc->key, |
379 | crc->offset, | 348 | get_type (crc->i), 1, 1, TIMEOUT, |
380 | &crc->key, | ||
381 | get_type (crc->i), | ||
382 | 1, 1, TIMEOUT, | ||
383 | &delete_value, crc)); | 349 | &delete_value, crc)); |
384 | break; | 350 | break; |
385 | case RP_DO_DEL: | 351 | case RP_DO_DEL: |
386 | #if VERBOSE | 352 | #if VERBOSE |
387 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 353 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "DO_DEL", |
388 | "Executing `%s' number %u\n", "DO_DEL", crc->i); | 354 | crc->i); |
389 | #endif | 355 | #endif |
390 | if (crc->i == 0) | 356 | if (crc->i == 0) |
391 | { | 357 | { |
@@ -397,95 +363,63 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
397 | crc->phase = RP_DEL; | 363 | crc->phase = RP_DEL; |
398 | } | 364 | } |
399 | GNUNET_assert (NULL != | 365 | GNUNET_assert (NULL != |
400 | GNUNET_DATASTORE_remove (datastore, | 366 | GNUNET_DATASTORE_remove (datastore, &crc->key, crc->size, |
401 | &crc->key, | 367 | crc->data, 1, 1, TIMEOUT, |
402 | crc->size, | ||
403 | crc->data, | ||
404 | 1, 1, TIMEOUT, | ||
405 | &check_success, crc)); | 368 | &check_success, crc)); |
406 | break; | 369 | break; |
407 | case RP_DELVALIDATE: | 370 | case RP_DELVALIDATE: |
408 | crc->i--; | 371 | crc->i--; |
409 | #if VERBOSE | 372 | #if VERBOSE |
410 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 373 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", |
411 | "Executing `%s' number %u\n", "DEL-VALIDATE", crc->i); | 374 | "DEL-VALIDATE", crc->i); |
412 | #endif | 375 | #endif |
413 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); | 376 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); |
414 | GNUNET_assert (NULL != | 377 | GNUNET_assert (NULL != |
415 | GNUNET_DATASTORE_get_key (datastore, | 378 | GNUNET_DATASTORE_get_key (datastore, crc->offset, &crc->key, |
416 | crc->offset, | 379 | get_type (crc->i), 1, 1, TIMEOUT, |
417 | &crc->key, | ||
418 | get_type (crc->i), | ||
419 | 1, 1, TIMEOUT, | ||
420 | &check_nothing, crc)); | 380 | &check_nothing, crc)); |
421 | break; | 381 | break; |
422 | case RP_RESERVE: | 382 | case RP_RESERVE: |
423 | crc->phase = RP_PUT_MULTIPLE; | 383 | crc->phase = RP_PUT_MULTIPLE; |
424 | GNUNET_DATASTORE_reserve (datastore, | 384 | GNUNET_DATASTORE_reserve (datastore, 128 * 1024, 2, 1, 1, TIMEOUT, |
425 | 128 * 1024, 2, 1, 1, TIMEOUT, &get_reserved, crc); | 385 | &get_reserved, crc); |
426 | break; | 386 | break; |
427 | case RP_PUT_MULTIPLE: | 387 | case RP_PUT_MULTIPLE: |
428 | crc->phase = RP_PUT_MULTIPLE_NEXT; | 388 | crc->phase = RP_PUT_MULTIPLE_NEXT; |
429 | GNUNET_DATASTORE_put (datastore, | 389 | GNUNET_DATASTORE_put (datastore, crc->rid, &crc->key, get_size (42), |
430 | crc->rid, | 390 | get_data (42), get_type (42), get_priority (42), |
431 | &crc->key, | 391 | get_anonymity (42), 0, get_expiration (42), 1, 1, |
432 | get_size (42), | 392 | TIMEOUT, &check_success, crc); |
433 | get_data (42), | ||
434 | get_type (42), | ||
435 | get_priority (42), | ||
436 | get_anonymity (42), | ||
437 | 0, | ||
438 | get_expiration (42), | ||
439 | 1, 1, TIMEOUT, &check_success, crc); | ||
440 | break; | 393 | break; |
441 | case RP_PUT_MULTIPLE_NEXT: | 394 | case RP_PUT_MULTIPLE_NEXT: |
442 | crc->phase = RP_GET_MULTIPLE; | 395 | crc->phase = RP_GET_MULTIPLE; |
443 | GNUNET_DATASTORE_put (datastore, | 396 | GNUNET_DATASTORE_put (datastore, crc->rid, &crc->key, get_size (43), |
444 | crc->rid, | 397 | get_data (43), get_type (42), get_priority (43), |
445 | &crc->key, | 398 | get_anonymity (43), 0, get_expiration (43), 1, 1, |
446 | get_size (43), | 399 | TIMEOUT, &check_success, crc); |
447 | get_data (43), | ||
448 | get_type (42), | ||
449 | get_priority (43), | ||
450 | get_anonymity (43), | ||
451 | 0, | ||
452 | get_expiration (43), | ||
453 | 1, 1, TIMEOUT, &check_success, crc); | ||
454 | break; | 400 | break; |
455 | case RP_GET_MULTIPLE: | 401 | case RP_GET_MULTIPLE: |
456 | GNUNET_assert (NULL != | 402 | GNUNET_assert (NULL != |
457 | GNUNET_DATASTORE_get_key (datastore, | 403 | GNUNET_DATASTORE_get_key (datastore, crc->offset, &crc->key, |
458 | crc->offset, | 404 | get_type (42), 1, 1, TIMEOUT, |
459 | &crc->key, | ||
460 | get_type (42), | ||
461 | 1, 1, TIMEOUT, | ||
462 | &check_multiple, crc)); | 405 | &check_multiple, crc)); |
463 | break; | 406 | break; |
464 | case RP_GET_MULTIPLE_NEXT: | 407 | case RP_GET_MULTIPLE_NEXT: |
465 | GNUNET_assert (NULL != | 408 | GNUNET_assert (NULL != |
466 | GNUNET_DATASTORE_get_key (datastore, | 409 | GNUNET_DATASTORE_get_key (datastore, crc->offset, &crc->key, |
467 | crc->offset, | 410 | get_type (42), 1, 1, TIMEOUT, |
468 | &crc->key, | ||
469 | get_type (42), | ||
470 | 1, 1, TIMEOUT, | ||
471 | &check_multiple, crc)); | 411 | &check_multiple, crc)); |
472 | break; | 412 | break; |
473 | case RP_UPDATE: | 413 | case RP_UPDATE: |
474 | GNUNET_assert (crc->uid > 0); | 414 | GNUNET_assert (crc->uid > 0); |
475 | crc->phase = RP_UPDATE_VALIDATE; | 415 | crc->phase = RP_UPDATE_VALIDATE; |
476 | GNUNET_DATASTORE_update (datastore, | 416 | GNUNET_DATASTORE_update (datastore, crc->uid, 100, get_expiration (42), 1, |
477 | crc->uid, | 417 | 1, TIMEOUT, &check_success, crc); |
478 | 100, | ||
479 | get_expiration (42), | ||
480 | 1, 1, TIMEOUT, &check_success, crc); | ||
481 | break; | 418 | break; |
482 | case RP_UPDATE_VALIDATE: | 419 | case RP_UPDATE_VALIDATE: |
483 | GNUNET_assert (NULL != | 420 | GNUNET_assert (NULL != |
484 | GNUNET_DATASTORE_get_key (datastore, | 421 | GNUNET_DATASTORE_get_key (datastore, crc->offset, &crc->key, |
485 | crc->offset, | 422 | get_type (42), 1, 1, TIMEOUT, |
486 | &crc->key, | ||
487 | get_type (42), | ||
488 | 1, 1, TIMEOUT, | ||
489 | &check_update, crc)); | 423 | &check_update, crc)); |
490 | break; | 424 | break; |
491 | case RP_DONE: | 425 | case RP_DONE: |
@@ -513,8 +447,7 @@ run_tests (void *cls, int32_t success, const char *msg) | |||
513 | switch (success) | 447 | switch (success) |
514 | { | 448 | { |
515 | case GNUNET_YES: | 449 | case GNUNET_YES: |
516 | GNUNET_SCHEDULER_add_continuation (&run_continuation, | 450 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, |
517 | crc, | ||
518 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 451 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
519 | return; | 452 | return; |
520 | case GNUNET_NO: | 453 | case GNUNET_NO: |
@@ -534,9 +467,8 @@ run_tests (void *cls, int32_t success, const char *msg) | |||
534 | 467 | ||
535 | 468 | ||
536 | static void | 469 | static void |
537 | run (void *cls, | 470 | run (void *cls, char *const *args, const char *cfgfile, |
538 | char *const *args, | 471 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
539 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
540 | { | 472 | { |
541 | struct CpsRunContext *crc; | 473 | struct CpsRunContext *crc; |
542 | static GNUNET_HashCode zkey; | 474 | static GNUNET_HashCode zkey; |
@@ -547,10 +479,8 @@ run (void *cls, | |||
547 | now = GNUNET_TIME_absolute_get (); | 479 | now = GNUNET_TIME_absolute_get (); |
548 | datastore = GNUNET_DATASTORE_connect (cfg); | 480 | datastore = GNUNET_DATASTORE_connect (cfg); |
549 | if (NULL == | 481 | if (NULL == |
550 | GNUNET_DATASTORE_put (datastore, 0, | 482 | GNUNET_DATASTORE_put (datastore, 0, &zkey, 4, "TEST", |
551 | &zkey, 4, "TEST", | 483 | GNUNET_BLOCK_TYPE_TEST, 0, 0, 0, |
552 | GNUNET_BLOCK_TYPE_TEST, | ||
553 | 0, 0, 0, | ||
554 | GNUNET_TIME_relative_to_absolute | 484 | GNUNET_TIME_relative_to_absolute |
555 | (GNUNET_TIME_UNIT_SECONDS), 0, 1, | 485 | (GNUNET_TIME_UNIT_SECONDS), 0, 1, |
556 | GNUNET_TIME_UNIT_MINUTES, &run_tests, crc)) | 486 | GNUNET_TIME_UNIT_MINUTES, &run_tests, crc)) |
@@ -582,21 +512,20 @@ check () | |||
582 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 512 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
583 | GNUNET_GETOPT_OPTION_END | 513 | GNUNET_GETOPT_OPTION_END |
584 | }; | 514 | }; |
585 | GNUNET_snprintf (cfg_name, | 515 | GNUNET_snprintf (cfg_name, sizeof (cfg_name), |
586 | sizeof (cfg_name), | ||
587 | "test_datastore_api_data_%s.conf", plugin_name); | 516 | "test_datastore_api_data_%s.conf", plugin_name); |
588 | #if START_DATASTORE | 517 | #if START_DATASTORE |
589 | proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 518 | proc = |
590 | "gnunet-service-arm", | 519 | GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
520 | "gnunet-service-arm", | ||
591 | #if VERBOSE | 521 | #if VERBOSE |
592 | "-L", "DEBUG", | 522 | "-L", "DEBUG", |
593 | #endif | 523 | #endif |
594 | "-c", cfg_name, NULL); | 524 | "-c", cfg_name, NULL); |
595 | #endif | 525 | #endif |
596 | GNUNET_assert (NULL != proc); | 526 | GNUNET_assert (NULL != proc); |
597 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 527 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, |
598 | argv, "test-datastore-api", "nohelp", | 528 | "test-datastore-api", "nohelp", options, &run, NULL); |
599 | options, &run, NULL); | ||
600 | #if START_DATASTORE | 529 | #if START_DATASTORE |
601 | sleep (1); /* give datastore chance to receive 'DROP' request */ | 530 | sleep (1); /* give datastore chance to receive 'DROP' request */ |
602 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | 531 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) |
@@ -630,9 +559,8 @@ main (int argc, char *argv[]) | |||
630 | else | 559 | else |
631 | pos = (char *) plugin_name; | 560 | pos = (char *) plugin_name; |
632 | 561 | ||
633 | GNUNET_snprintf (dir_name, | 562 | GNUNET_snprintf (dir_name, sizeof (dir_name), "/tmp/test-gnunet-datastore-%s", |
634 | sizeof (dir_name), | 563 | plugin_name); |
635 | "/tmp/test-gnunet-datastore-%s", plugin_name); | ||
636 | GNUNET_DISK_directory_remove (dir_name); | 564 | GNUNET_DISK_directory_remove (dir_name); |
637 | GNUNET_log_setup ("test-datastore-api", | 565 | GNUNET_log_setup ("test-datastore-api", |
638 | #if VERBOSE | 566 | #if VERBOSE |
diff --git a/src/datastore/test_datastore_api_management.c b/src/datastore/test_datastore_api_management.c index b2146a915..230b7eb67 100644 --- a/src/datastore/test_datastore_api_management.c +++ b/src/datastore/test_datastore_api_management.c | |||
@@ -117,8 +117,8 @@ struct CpsRunContext | |||
117 | }; | 117 | }; |
118 | 118 | ||
119 | 119 | ||
120 | static void | 120 | static void run_continuation (void *cls, |
121 | run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 121 | const struct GNUNET_SCHEDULER_TaskContext *tc); |
122 | 122 | ||
123 | 123 | ||
124 | static void | 124 | static void |
@@ -131,20 +131,16 @@ check_success (void *cls, int success, const char *msg) | |||
131 | GNUNET_assert (GNUNET_OK == success); | 131 | GNUNET_assert (GNUNET_OK == success); |
132 | GNUNET_free_non_null (crc->data); | 132 | GNUNET_free_non_null (crc->data); |
133 | crc->data = NULL; | 133 | crc->data = NULL; |
134 | GNUNET_SCHEDULER_add_continuation (&run_continuation, | 134 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, |
135 | crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 135 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
136 | } | 136 | } |
137 | 137 | ||
138 | 138 | ||
139 | static void | 139 | static void |
140 | check_value (void *cls, | 140 | check_value (void *cls, const GNUNET_HashCode * key, size_t size, |
141 | const GNUNET_HashCode * key, | 141 | const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, |
142 | size_t size, | 142 | uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, |
143 | const void *data, | 143 | uint64_t uid) |
144 | enum GNUNET_BLOCK_Type type, | ||
145 | uint32_t priority, | ||
146 | uint32_t anonymity, | ||
147 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | ||
148 | { | 144 | { |
149 | struct CpsRunContext *crc = cls; | 145 | struct CpsRunContext *crc = cls; |
150 | int i; | 146 | int i; |
@@ -152,8 +148,7 @@ check_value (void *cls, | |||
152 | if (NULL == key) | 148 | if (NULL == key) |
153 | { | 149 | { |
154 | crc->phase = RP_GET_FAIL; | 150 | crc->phase = RP_GET_FAIL; |
155 | GNUNET_SCHEDULER_add_continuation (&run_continuation, | 151 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, |
156 | crc, | ||
157 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 152 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
158 | return; | 153 | return; |
159 | } | 154 | } |
@@ -168,28 +163,24 @@ check_value (void *cls, | |||
168 | crc->i--; | 163 | crc->i--; |
169 | if (crc->i == 0) | 164 | if (crc->i == 0) |
170 | crc->phase = RP_DONE; | 165 | crc->phase = RP_DONE; |
171 | GNUNET_SCHEDULER_add_continuation (&run_continuation, | 166 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, |
172 | crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 167 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
173 | } | 168 | } |
174 | 169 | ||
175 | 170 | ||
176 | static void | 171 | static void |
177 | check_nothing (void *cls, | 172 | check_nothing (void *cls, const GNUNET_HashCode * key, size_t size, |
178 | const GNUNET_HashCode * key, | 173 | const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, |
179 | size_t size, | 174 | uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, |
180 | const void *data, | 175 | uint64_t uid) |
181 | enum GNUNET_BLOCK_Type type, | ||
182 | uint32_t priority, | ||
183 | uint32_t anonymity, | ||
184 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | ||
185 | { | 176 | { |
186 | struct CpsRunContext *crc = cls; | 177 | struct CpsRunContext *crc = cls; |
187 | 178 | ||
188 | GNUNET_assert (key == NULL); | 179 | GNUNET_assert (key == NULL); |
189 | if (0 == --crc->i) | 180 | if (0 == --crc->i) |
190 | crc->phase = RP_DONE; | 181 | crc->phase = RP_DONE; |
191 | GNUNET_SCHEDULER_add_continuation (&run_continuation, | 182 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, |
192 | crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 183 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
193 | } | 184 | } |
194 | 185 | ||
195 | 186 | ||
@@ -203,21 +194,15 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
203 | { | 194 | { |
204 | case RP_PUT: | 195 | case RP_PUT: |
205 | #if VERBOSE | 196 | #if VERBOSE |
206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 197 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "PUT", |
207 | "Executing `%s' number %u\n", "PUT", crc->i); | 198 | crc->i); |
208 | #endif | 199 | #endif |
209 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); | 200 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); |
210 | GNUNET_DATASTORE_put (datastore, | 201 | GNUNET_DATASTORE_put (datastore, 0, &crc->key, get_size (crc->i), |
211 | 0, | 202 | get_data (crc->i), get_type (crc->i), |
212 | &crc->key, | 203 | get_priority (crc->i), get_anonymity (crc->i), 0, |
213 | get_size (crc->i), | 204 | get_expiration (crc->i), 1, 1, TIMEOUT, |
214 | get_data (crc->i), | 205 | &check_success, crc); |
215 | get_type (crc->i), | ||
216 | get_priority (crc->i), | ||
217 | get_anonymity (crc->i), | ||
218 | 0, | ||
219 | get_expiration (crc->i), | ||
220 | 1, 1, TIMEOUT, &check_success, crc); | ||
221 | crc->i++; | 206 | crc->i++; |
222 | if (crc->i == ITERATIONS) | 207 | if (crc->i == ITERATIONS) |
223 | { | 208 | { |
@@ -230,27 +215,23 @@ run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
230 | break; | 215 | break; |
231 | case RP_GET: | 216 | case RP_GET: |
232 | #if VERBOSE | 217 | #if VERBOSE |
233 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 218 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET", |
234 | "Executing `%s' number %u\n", "GET", crc->i); | 219 | crc->i); |
235 | #endif | 220 | #endif |
236 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); | 221 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); |
237 | GNUNET_DATASTORE_get_key (datastore, | 222 | GNUNET_DATASTORE_get_key (datastore, crc->offset++, &crc->key, |
238 | crc->offset++, | 223 | get_type (crc->i), 1, 1, TIMEOUT, &check_value, |
239 | &crc->key, | 224 | crc); |
240 | get_type (crc->i), | ||
241 | 1, 1, TIMEOUT, &check_value, crc); | ||
242 | break; | 225 | break; |
243 | case RP_GET_FAIL: | 226 | case RP_GET_FAIL: |
244 | #if VERBOSE | 227 | #if VERBOSE |
245 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 228 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET(f)", |
246 | "Executing `%s' number %u\n", "GET(f)", crc->i); | 229 | crc->i); |
247 | #endif | 230 | #endif |
248 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); | 231 | GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); |
249 | GNUNET_DATASTORE_get_key (datastore, | 232 | GNUNET_DATASTORE_get_key (datastore, crc->offset++, &crc->key, |
250 | crc->offset++, | 233 | get_type (crc->i), 1, 1, TIMEOUT, &check_nothing, |
251 | &crc->key, | 234 | crc); |
252 | get_type (crc->i), | ||
253 | 1, 1, TIMEOUT, &check_nothing, crc); | ||
254 | break; | 235 | break; |
255 | case RP_DONE: | 236 | case RP_DONE: |
256 | GNUNET_assert (0 == crc->i); | 237 | GNUNET_assert (0 == crc->i); |
@@ -277,15 +258,14 @@ run_tests (void *cls, int success, const char *msg) | |||
277 | GNUNET_free (crc); | 258 | GNUNET_free (crc); |
278 | return; | 259 | return; |
279 | } | 260 | } |
280 | GNUNET_SCHEDULER_add_continuation (&run_continuation, | 261 | GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, |
281 | crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 262 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
282 | } | 263 | } |
283 | 264 | ||
284 | 265 | ||
285 | static void | 266 | static void |
286 | run (void *cls, | 267 | run (void *cls, char *const *args, const char *cfgfile, |
287 | char *const *args, | 268 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
288 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
289 | { | 269 | { |
290 | struct CpsRunContext *crc; | 270 | struct CpsRunContext *crc; |
291 | static GNUNET_HashCode zkey; | 271 | static GNUNET_HashCode zkey; |
@@ -296,10 +276,8 @@ run (void *cls, | |||
296 | now = GNUNET_TIME_absolute_get (); | 276 | now = GNUNET_TIME_absolute_get (); |
297 | datastore = GNUNET_DATASTORE_connect (cfg); | 277 | datastore = GNUNET_DATASTORE_connect (cfg); |
298 | if (NULL == | 278 | if (NULL == |
299 | GNUNET_DATASTORE_put (datastore, 0, | 279 | GNUNET_DATASTORE_put (datastore, 0, &zkey, 4, "TEST", |
300 | &zkey, 4, "TEST", | 280 | GNUNET_BLOCK_TYPE_TEST, 0, 0, 0, |
301 | GNUNET_BLOCK_TYPE_TEST, | ||
302 | 0, 0, 0, | ||
303 | GNUNET_TIME_relative_to_absolute | 281 | GNUNET_TIME_relative_to_absolute |
304 | (GNUNET_TIME_UNIT_SECONDS), 0, 1, | 282 | (GNUNET_TIME_UNIT_SECONDS), 0, 1, |
305 | GNUNET_TIME_UNIT_MINUTES, &run_tests, crc)) | 283 | GNUNET_TIME_UNIT_MINUTES, &run_tests, crc)) |
@@ -330,19 +308,19 @@ check () | |||
330 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 308 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
331 | GNUNET_GETOPT_OPTION_END | 309 | GNUNET_GETOPT_OPTION_END |
332 | }; | 310 | }; |
333 | GNUNET_snprintf (cfg_name, | 311 | GNUNET_snprintf (cfg_name, sizeof (cfg_name), |
334 | sizeof (cfg_name), | ||
335 | "test_datastore_api_data_%s.conf", plugin_name); | 312 | "test_datastore_api_data_%s.conf", plugin_name); |
336 | proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 313 | proc = |
337 | "gnunet-service-arm", | 314 | GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
315 | "gnunet-service-arm", | ||
338 | #if VERBOSE | 316 | #if VERBOSE |
339 | "-L", "DEBUG", | 317 | "-L", "DEBUG", |
340 | #endif | 318 | #endif |
341 | "-c", cfg_name, NULL); | 319 | "-c", cfg_name, NULL); |
342 | GNUNET_assert (NULL != proc); | 320 | GNUNET_assert (NULL != proc); |
343 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 321 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, |
344 | argv, "test-datastore-api-management", "nohelp", | 322 | "test-datastore-api-management", "nohelp", options, &run, |
345 | options, &run, NULL); | 323 | NULL); |
346 | sleep (1); /* give datastore chance to process 'DROP' request */ | 324 | sleep (1); /* give datastore chance to process 'DROP' request */ |
347 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | 325 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) |
348 | { | 326 | { |
@@ -375,9 +353,8 @@ main (int argc, char *argv[]) | |||
375 | else | 353 | else |
376 | pos = (char *) plugin_name; | 354 | pos = (char *) plugin_name; |
377 | 355 | ||
378 | GNUNET_snprintf (dir_name, | 356 | GNUNET_snprintf (dir_name, sizeof (dir_name), "/tmp/test-gnunet-datastore-%s", |
379 | sizeof (dir_name), | 357 | plugin_name); |
380 | "/tmp/test-gnunet-datastore-%s", plugin_name); | ||
381 | GNUNET_DISK_directory_remove (dir_name); | 358 | GNUNET_DISK_directory_remove (dir_name); |
382 | GNUNET_log_setup ("test-datastore-api-management", | 359 | GNUNET_log_setup ("test-datastore-api-management", |
383 | #if VERBOSE | 360 | #if VERBOSE |
diff --git a/src/datastore/test_plugin_datastore.c b/src/datastore/test_plugin_datastore.c index 15cca61f1..a34c4e38a 100644 --- a/src/datastore/test_plugin_datastore.c +++ b/src/datastore/test_plugin_datastore.c | |||
@@ -118,9 +118,8 @@ put_value (struct GNUNET_DATASTORE_PluginFunctions *api, int i, int k) | |||
118 | msg = NULL; | 118 | msg = NULL; |
119 | prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100); | 119 | prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100); |
120 | #if VERBOSE | 120 | #if VERBOSE |
121 | fprintf (stderr, | 121 | fprintf (stderr, "putting type %u, anon %u under key %s\n", i + 1, i, |
122 | "putting type %u, anon %u under key %s\n", | 122 | GNUNET_h2s (&key)); |
123 | i + 1, i, GNUNET_h2s (&key)); | ||
124 | #endif | 123 | #endif |
125 | if (GNUNET_OK != api->put (api->cls, &key, size, value, i + 1 /* type */ , | 124 | if (GNUNET_OK != api->put (api->cls, &key, size, value, i + 1 /* type */ , |
126 | prio, i /* anonymity */ , | 125 | prio, i /* anonymity */ , |
@@ -149,13 +148,9 @@ static uint64_t guid; | |||
149 | 148 | ||
150 | 149 | ||
151 | static int | 150 | static int |
152 | iterate_one_shot (void *cls, | 151 | iterate_one_shot (void *cls, const GNUNET_HashCode * key, uint32_t size, |
153 | const GNUNET_HashCode * key, | 152 | const void *data, enum GNUNET_BLOCK_Type type, |
154 | uint32_t size, | 153 | uint32_t priority, uint32_t anonymity, |
155 | const void *data, | ||
156 | enum GNUNET_BLOCK_Type type, | ||
157 | uint32_t priority, | ||
158 | uint32_t anonymity, | ||
159 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | 154 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) |
160 | { | 155 | { |
161 | struct CpsRunContext *crc = cls; | 156 | struct CpsRunContext *crc = cls; |
@@ -166,8 +161,8 @@ iterate_one_shot (void *cls, | |||
166 | #if VERBOSE | 161 | #if VERBOSE |
167 | fprintf (stderr, | 162 | fprintf (stderr, |
168 | "Found result type=%u, priority=%u, size=%u, expire=%llu, key %s\n", | 163 | "Found result type=%u, priority=%u, size=%u, expire=%llu, key %s\n", |
169 | type, priority, size, | 164 | type, priority, size, (unsigned long long) expiration.abs_value, |
170 | (unsigned long long) expiration.abs_value, GNUNET_h2s (key)); | 165 | GNUNET_h2s (key)); |
171 | #endif | 166 | #endif |
172 | GNUNET_SCHEDULER_add_now (&test, crc); | 167 | GNUNET_SCHEDULER_add_now (&test, crc); |
173 | return GNUNET_OK; | 168 | return GNUNET_OK; |
@@ -189,12 +184,12 @@ unload_plugin (struct GNUNET_DATASTORE_PluginFunctions *api, | |||
189 | char *libname; | 184 | char *libname; |
190 | 185 | ||
191 | if (GNUNET_OK != | 186 | if (GNUNET_OK != |
192 | GNUNET_CONFIGURATION_get_value_string (cfg, | 187 | GNUNET_CONFIGURATION_get_value_string (cfg, "DATASTORE", "DATABASE", |
193 | "DATASTORE", "DATABASE", &name)) | 188 | &name)) |
194 | { | 189 | { |
195 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 190 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
196 | _("No `%s' specified for `%s' in configuration!\n"), | 191 | _("No `%s' specified for `%s' in configuration!\n"), "DATABASE", |
197 | "DATABASE", "DATASTORE"); | 192 | "DATASTORE"); |
198 | return; | 193 | return; |
199 | } | 194 | } |
200 | GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); | 195 | GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); |
@@ -265,15 +260,13 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
265 | break; | 260 | break; |
266 | } | 261 | } |
267 | gen_key (5, &key); | 262 | gen_key (5, &key); |
268 | crc->api->get_key (crc->api->cls, | 263 | crc->api->get_key (crc->api->cls, crc->offset++, &key, NULL, |
269 | crc->offset++, | ||
270 | &key, NULL, | ||
271 | GNUNET_BLOCK_TYPE_ANY, &iterate_one_shot, crc); | 264 | GNUNET_BLOCK_TYPE_ANY, &iterate_one_shot, crc); |
272 | break; | 265 | break; |
273 | case RP_UPDATE: | 266 | case RP_UPDATE: |
274 | GNUNET_assert (GNUNET_OK == | 267 | GNUNET_assert (GNUNET_OK == |
275 | crc->api->update (crc->api->cls, | 268 | crc->api->update (crc->api->cls, guid, 1, |
276 | guid, 1, GNUNET_TIME_UNIT_ZERO_ABS, NULL)); | 269 | GNUNET_TIME_UNIT_ZERO_ABS, NULL)); |
277 | crc->phase++; | 270 | crc->phase++; |
278 | GNUNET_SCHEDULER_add_now (&test, crc); | 271 | GNUNET_SCHEDULER_add_now (&test, crc); |
279 | break; | 272 | break; |
@@ -314,19 +307,19 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
314 | char *libname; | 307 | char *libname; |
315 | 308 | ||
316 | if (GNUNET_OK != | 309 | if (GNUNET_OK != |
317 | GNUNET_CONFIGURATION_get_value_string (cfg, | 310 | GNUNET_CONFIGURATION_get_value_string (cfg, "DATASTORE", "DATABASE", |
318 | "DATASTORE", "DATABASE", &name)) | 311 | &name)) |
319 | { | 312 | { |
320 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 313 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
321 | _("No `%s' specified for `%s' in configuration!\n"), | 314 | _("No `%s' specified for `%s' in configuration!\n"), "DATABASE", |
322 | "DATABASE", "DATASTORE"); | 315 | "DATASTORE"); |
323 | return NULL; | 316 | return NULL; |
324 | } | 317 | } |
325 | env.cfg = cfg; | 318 | env.cfg = cfg; |
326 | env.duc = &disk_utilization_change_cb; | 319 | env.duc = &disk_utilization_change_cb; |
327 | env.cls = NULL; | 320 | env.cls = NULL; |
328 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 321 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' datastore plugin\n"), |
329 | _("Loading `%s' datastore plugin\n"), name); | 322 | name); |
330 | GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); | 323 | GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); |
331 | if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env))) | 324 | if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env))) |
332 | { | 325 | { |
@@ -340,9 +333,8 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
340 | 333 | ||
341 | 334 | ||
342 | static void | 335 | static void |
343 | run (void *cls, | 336 | run (void *cls, char *const *args, const char *cfgfile, |
344 | char *const *args, | 337 | const struct GNUNET_CONFIGURATION_Handle *c) |
345 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) | ||
346 | { | 338 | { |
347 | struct GNUNET_DATASTORE_PluginFunctions *api; | 339 | struct GNUNET_DATASTORE_PluginFunctions *api; |
348 | struct CpsRunContext *crc; | 340 | struct CpsRunContext *crc; |
@@ -380,12 +372,10 @@ check () | |||
380 | GNUNET_GETOPT_OPTION_END | 372 | GNUNET_GETOPT_OPTION_END |
381 | }; | 373 | }; |
382 | 374 | ||
383 | GNUNET_snprintf (cfg_name, | 375 | GNUNET_snprintf (cfg_name, sizeof (cfg_name), |
384 | sizeof (cfg_name), | ||
385 | "test_plugin_datastore_data_%s.conf", plugin_name); | 376 | "test_plugin_datastore_data_%s.conf", plugin_name); |
386 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 377 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, |
387 | argv, "test-plugin-datastore", "nohelp", | 378 | "test-plugin-datastore", "nohelp", options, &run, NULL); |
388 | options, &run, NULL); | ||
389 | if (ok != 0) | 379 | if (ok != 0) |
390 | fprintf (stderr, "Missed some testcases: %u\n", ok); | 380 | fprintf (stderr, "Missed some testcases: %u\n", ok); |
391 | return ok; | 381 | return ok; |
@@ -409,8 +399,7 @@ main (int argc, char *argv[]) | |||
409 | else | 399 | else |
410 | pos = (char *) plugin_name; | 400 | pos = (char *) plugin_name; |
411 | 401 | ||
412 | GNUNET_snprintf (dir_name, | 402 | GNUNET_snprintf (dir_name, sizeof (dir_name), |
413 | sizeof (dir_name), | ||
414 | "/tmp/test-gnunet-datastore-plugin-%s", plugin_name); | 403 | "/tmp/test-gnunet-datastore-plugin-%s", plugin_name); |
415 | GNUNET_DISK_directory_remove (dir_name); | 404 | GNUNET_DISK_directory_remove (dir_name); |
416 | GNUNET_log_setup ("test-plugin-datastore", | 405 | GNUNET_log_setup ("test-plugin-datastore", |