aboutsummaryrefslogtreecommitdiff
path: root/src/datastore
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-07-19 11:31:54 +0000
committerChristian Grothoff <christian@grothoff.org>2009-07-19 11:31:54 +0000
commit1e879063d6c677c3cb0f57bbc61b8d908aeb2a05 (patch)
treefb8bf3cbf850a4741137fb4f0615fa1162f14d10 /src/datastore
parentc6689c4e233c663f79cf00449e70ce3c56653f1c (diff)
downloadgnunet-1e879063d6c677c3cb0f57bbc61b8d908aeb2a05.tar.gz
gnunet-1e879063d6c677c3cb0f57bbc61b8d908aeb2a05.zip
bugfixes
Diffstat (limited to 'src/datastore')
-rw-r--r--src/datastore/datastore.h2
-rw-r--r--src/datastore/datastore_api.c33
-rw-r--r--src/datastore/gnunet-service-datastore.c38
-rw-r--r--src/datastore/plugin_datastore_sqlite.c10
-rw-r--r--src/datastore/test_datastore_api.c2
5 files changed, 49 insertions, 36 deletions
diff --git a/src/datastore/datastore.h b/src/datastore/datastore.h
index 45dc70047..7d8e683f5 100644
--- a/src/datastore/datastore.h
+++ b/src/datastore/datastore.h
@@ -27,6 +27,8 @@
27#ifndef DATASTORE_H 27#ifndef DATASTORE_H
28#define DATASTORE_H 28#define DATASTORE_H
29 29
30#define DEBUG_DATASTORE GNUNET_YES
31
30#include "gnunet_util_lib.h" 32#include "gnunet_util_lib.h"
31 33
32/** 34/**
diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c
index 4fc719629..6f02e6fea 100644
--- a/src/datastore/datastore_api.c
+++ b/src/datastore/datastore_api.c
@@ -215,7 +215,7 @@ with_status_response_handler (void *cls,
215 } 215 }
216 } 216 }
217 h->response_proc = NULL; 217 h->response_proc = NULL;
218#if VERBOSE 218#if DEBUG_DATASTORE
219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
220 "Received status %d/%s\n", 220 "Received status %d/%s\n",
221 status, 221 status,
@@ -255,12 +255,13 @@ transmit_get_status (void *cls,
255 gettext_noop ("Error transmitting message to datastore service.\n")); 255 gettext_noop ("Error transmitting message to datastore service.\n"));
256 return 0; 256 return 0;
257 } 257 }
258 GNUNET_assert (h->message_size <= size); 258 msize = h->message_size;
259 memcpy (buf, &h[1], h->message_size); 259 GNUNET_assert (msize <= size);
260#if VERBOSE 260 memcpy (buf, &h[1], msize);
261#if DEBUG_DATASTORE
261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
262 "Transmitted %u byte message to datastore service, now waiting for status.\n", 263 "Transmitted %u byte message to datastore service, now waiting for status.\n",
263 h->message_size); 264 msize);
264#endif 265#endif
265 h->message_size = 0; 266 h->message_size = 0;
266 GNUNET_CLIENT_receive (h->client, 267 GNUNET_CLIENT_receive (h->client,
@@ -295,7 +296,7 @@ transmit_for_status (struct GNUNET_DATASTORE_Handle *h,
295 296
296 hdr = (const struct GNUNET_MessageHeader*) &h[1]; 297 hdr = (const struct GNUNET_MessageHeader*) &h[1];
297 msize = ntohs(hdr->size); 298 msize = ntohs(hdr->size);
298#if VERBOSE 299#if DEBUG_DATASTORE
299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
300 "Transmitting %u byte message of type %u to datastore service\n", 301 "Transmitting %u byte message of type %u to datastore service\n",
301 msize, 302 msize,
@@ -356,6 +357,11 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
356 struct DataMessage *dm; 357 struct DataMessage *dm;
357 size_t msize; 358 size_t msize;
358 359
360#if DEBUG_DATASTORE
361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
362 "Asked to put %u bytes of data\n",
363 size);
364#endif
359 msize = sizeof(struct DataMessage) + size; 365 msize = sizeof(struct DataMessage) + size;
360 GNUNET_assert (msize <= GNUNET_SERVER_MAX_MESSAGE_SIZE); 366 GNUNET_assert (msize <= GNUNET_SERVER_MAX_MESSAGE_SIZE);
361 dm = (struct DataMessage*) &h[1]; 367 dm = (struct DataMessage*) &h[1];
@@ -502,7 +508,7 @@ with_result_response_handler (void *cls,
502 { 508 {
503 GNUNET_break (ntohs(msg->size) == sizeof(struct GNUNET_MessageHeader)); 509 GNUNET_break (ntohs(msg->size) == sizeof(struct GNUNET_MessageHeader));
504 h->response_proc = NULL; 510 h->response_proc = NULL;
505#if VERBOSE 511#if DEBUG_DATASTORE
506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 512 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
507 "Received end of result set\n"); 513 "Received end of result set\n");
508#endif 514#endif
@@ -533,7 +539,7 @@ with_result_response_handler (void *cls,
533 NULL, 0, NULL, 0, 0, 0, zero, 0); 539 NULL, 0, NULL, 0, 0, 0, zero, 0);
534 return; 540 return;
535 } 541 }
536#if VERBOSE 542#if DEBUG_DATASTORE
537 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 543 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
538 "Received result %llu with type %u and size %u with key %s\n", 544 "Received result %llu with type %u and size %u with key %s\n",
539 (unsigned long long) GNUNET_ntohll(dm->uid), 545 (unsigned long long) GNUNET_ntohll(dm->uid),
@@ -585,12 +591,13 @@ transmit_get_result (void *cls,
585 gettext_noop ("Error transmitting message to datastore service.\n")); 591 gettext_noop ("Error transmitting message to datastore service.\n"));
586 return 0; 592 return 0;
587 } 593 }
588 GNUNET_assert (h->message_size <= size); 594 msize = h->message_size;
589 memcpy (buf, &h[1], h->message_size); 595 GNUNET_assert (msize <= size);
590#if VERBOSE 596 memcpy (buf, &h[1], msize);
597#if DEBUG_DATASTORE
591 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 598 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
592 "Transmitted %u byte message to datastore service, now waiting for result.\n", 599 "Transmitted %u byte message to datastore service, now waiting for result.\n",
593 h->message_size); 600 msize);
594#endif 601#endif
595 h->message_size = 0; 602 h->message_size = 0;
596 GNUNET_CLIENT_receive (h->client, 603 GNUNET_CLIENT_receive (h->client,
@@ -626,7 +633,7 @@ transmit_for_result (struct GNUNET_DATASTORE_Handle *h,
626 633
627 hdr = (const struct GNUNET_MessageHeader*) &h[1]; 634 hdr = (const struct GNUNET_MessageHeader*) &h[1];
628 msize = ntohs(hdr->size); 635 msize = ntohs(hdr->size);
629#if VERBOSE 636#if DEBUG_DATASTORE
630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 637 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
631 "Transmitting %u byte message of type %u to datastore service\n", 638 "Transmitting %u byte message of type %u to datastore service\n",
632 msize, 639 msize,
diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c
index 70d349693..74196dd1e 100644
--- a/src/datastore/gnunet-service-datastore.c
+++ b/src/datastore/gnunet-service-datastore.c
@@ -38,8 +38,6 @@
38#include "plugin_datastore.h" 38#include "plugin_datastore.h"
39#include "datastore.h" 39#include "datastore.h"
40 40
41#define DEBUG_DATASTORE GNUNET_YES
42
43/** 41/**
44 * How many messages do we queue at most per client? 42 * How many messages do we queue at most per client?
45 */ 43 */
@@ -207,10 +205,6 @@ transmit_callback (void *cls,
207 tcc->tc (tcc->tc_cls, GNUNET_SYSERR); 205 tcc->tc (tcc->tc_cls, GNUNET_SYSERR);
208 if (GNUNET_YES == tcc->end) 206 if (GNUNET_YES == tcc->end)
209 { 207 {
210#if DEBUG_DATASTORE
211 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
212 "Disconnecting client.\n");
213#endif
214 GNUNET_SERVER_receive_done (tcc->client, GNUNET_SYSERR); 208 GNUNET_SERVER_receive_done (tcc->client, GNUNET_SYSERR);
215 } 209 }
216 GNUNET_free (tcc->msg); 210 GNUNET_free (tcc->msg);
@@ -308,10 +302,10 @@ transmit_status (struct GNUNET_SERVER_Client *client,
308 302
309#if DEBUG_DATASTORE 303#if DEBUG_DATASTORE
310 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 304 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
311 "Transmitting `s' message with value %d and message %s\n", 305 "Transmitting `%s' message with value %d and message %s\n",
312 "STATUS", 306 "STATUS",
313 code, 307 code,
314 msg); 308 msg != NULL ? msg : "(none)");
315#endif 309#endif
316 slen = (msg == NULL) ? 0 : strlen(msg) + 1; 310 slen = (msg == NULL) ? 0 : strlen(msg) + 1;
317 sm = GNUNET_malloc (sizeof(struct StatusMessage) + slen); 311 sm = GNUNET_malloc (sizeof(struct StatusMessage) + slen);
@@ -578,7 +572,7 @@ handle_put (void *cls,
578 GNUNET_CONTAINER_bloomfilter_add (filter, 572 GNUNET_CONTAINER_bloomfilter_add (filter,
579 &dm->key); 573 &dm->key);
580 transmit_status (client, 574 transmit_status (client,
581 GNUNET_SYSERR == ret ? GNUNET_SYSERR : GNUNET_OK, 575 (GNUNET_SYSERR == ret) ? GNUNET_SYSERR : GNUNET_OK,
582 msg); 576 msg);
583 GNUNET_free_non_null (msg); 577 GNUNET_free_non_null (msg);
584} 578}
@@ -619,11 +613,16 @@ handle_get (void *cls,
619 &msg->key)) ) 613 &msg->key)) )
620 { 614 {
621 /* don't bother database... */ 615 /* don't bother database... */
616#if DEBUG_DATASTORE
617 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
618 "Empty result set for `%s' request.\n",
619 "GET");
620#endif
622 transmit_item (client, 621 transmit_item (client,
623 NULL, NULL, 0, NULL, 0, 0, 0, zero, 0); 622 NULL, NULL, 0, NULL, 0, 0, 0, zero, 0);
624 return; 623 return;
625 } 624 }
626 GNUNET_SERVER_client_drop (client); 625 GNUNET_SERVER_client_keep (client);
627 plugin->api->get (plugin->api->cls, 626 plugin->api->get (plugin->api->cls,
628 ((size == sizeof(struct GetMessage)) ? &msg->key : NULL), 627 ((size == sizeof(struct GetMessage)) ? &msg->key : NULL),
629 NULL, 628 NULL,
@@ -683,7 +682,7 @@ handle_get_random (void *cls,
683 "Processing `%s' request\n", 682 "Processing `%s' request\n",
684 "GET_RANDOM"); 683 "GET_RANDOM");
685#endif 684#endif
686 GNUNET_SERVER_client_drop (client); // FIXME: WTF? 685 GNUNET_SERVER_client_keep (client);
687 plugin->api->iter_migration_order (plugin->api->cls, 686 plugin->api->iter_migration_order (plugin->api->cls,
688 0, 687 0,
689 &transmit_item, 688 &transmit_item,
@@ -725,8 +724,14 @@ remove_callback (void *cls,
725 expiration, uint64_t uid) 724 expiration, uint64_t uid)
726{ 725{
727 struct RemoveContext *rc = cls; 726 struct RemoveContext *rc = cls;
727
728 if (key == NULL) 728 if (key == NULL)
729 { 729 {
730#if DEBUG_DATASTORE
731 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
732 "No further matches for `%s' request.\n",
733 "REMOVE");
734#endif
730 if (GNUNET_YES == rc->found) 735 if (GNUNET_YES == rc->found)
731 transmit_status (rc->client, GNUNET_OK, NULL); 736 transmit_status (rc->client, GNUNET_OK, NULL);
732 else 737 else
@@ -736,9 +741,15 @@ remove_callback (void *cls,
736 return GNUNET_OK; /* last item */ 741 return GNUNET_OK; /* last item */
737 } 742 }
738 rc->found = GNUNET_YES; 743 rc->found = GNUNET_YES;
739 plugin->api->next_request (next_cls, GNUNET_YES); 744#if DEBUG_DATASTORE
745 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
746 "Item %llu matches `%s' request.\n",
747 (unsigned long long) uid,
748 "REMOVE");
749#endif
740 GNUNET_CONTAINER_bloomfilter_remove (filter, 750 GNUNET_CONTAINER_bloomfilter_remove (filter,
741 key); 751 key);
752 plugin->api->next_request (next_cls, GNUNET_YES);
742 return GNUNET_NO; 753 return GNUNET_NO;
743} 754}
744 755
@@ -776,6 +787,7 @@ handle_remove (void *cls,
776 GNUNET_CRYPTO_hash (&dm[1], 787 GNUNET_CRYPTO_hash (&dm[1],
777 ntohl(dm->size), 788 ntohl(dm->size),
778 &vhash); 789 &vhash);
790 GNUNET_SERVER_client_keep (client);
779 plugin->api->get (plugin->api->cls, 791 plugin->api->get (plugin->api->cls,
780 &dm->key, 792 &dm->key,
781 &vhash, 793 &vhash,
@@ -857,7 +869,7 @@ load_plugin (struct GNUNET_CONFIGURATION_Handle *cfg,
857 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 869 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
858 _("Loading `%s' datastore plugin\n"), name); 870 _("Loading `%s' datastore plugin\n"), name);
859 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); 871 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
860 ret->short_name = GNUNET_strdup (name); 872 ret->short_name = name;
861 ret->lib_name = libname; 873 ret->lib_name = libname;
862 ret->api = GNUNET_PLUGIN_load (libname, &ret->env); 874 ret->api = GNUNET_PLUGIN_load (libname, &ret->env);
863 if (ret->api == NULL) 875 if (ret->api == NULL)
diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c
index 99f940317..ce92d3882 100644
--- a/src/datastore/plugin_datastore_sqlite.c
+++ b/src/datastore/plugin_datastore_sqlite.c
@@ -29,7 +29,7 @@
29#include "plugin_datastore.h" 29#include "plugin_datastore.h"
30#include <sqlite3.h> 30#include <sqlite3.h>
31 31
32#define DEBUG_SQLITE GNUNET_NO 32#define DEBUG_SQLITE GNUNET_YES
33 33
34/** 34/**
35 * After how many payload-changing operations 35 * After how many payload-changing operations
@@ -39,14 +39,6 @@
39 39
40#define QUOTA_STAT_NAME gettext_noop ("file-sharing datastore utilization (in bytes)") 40#define QUOTA_STAT_NAME gettext_noop ("file-sharing datastore utilization (in bytes)")
41 41
42
43/**
44 * Die with an error message that indicates
45 * a failure of the command 'cmd' with the message given
46 * by strerror(errno).
47 */
48#define DIE_SQLITE(db, cmd) do { GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, "sqlite", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); abort(); } while(0)
49
50/** 42/**
51 * Log an error message at log-level 'level' that indicates 43 * Log an error message at log-level 'level' that indicates
52 * a failure of the command 'cmd' on file 'filename' 44 * a failure of the command 'cmd' on file 'filename'
diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c
index e9545bbf1..56cf0e588 100644
--- a/src/datastore/test_datastore_api.c
+++ b/src/datastore/test_datastore_api.c
@@ -68,7 +68,7 @@ get_data (int i)
68static int 68static int
69get_type(int i) 69get_type(int i)
70{ 70{
71 return i; 71 return i+1;
72} 72}
73 73
74 74