summaryrefslogtreecommitdiff
path: root/src/datastore
diff options
context:
space:
mode:
Diffstat (limited to 'src/datastore')
-rw-r--r--src/datastore/gnunet-datastore.c120
-rw-r--r--src/datastore/gnunet-service-datastore.c622
-rw-r--r--src/datastore/perf_datastore_api.c10
-rw-r--r--src/datastore/perf_plugin_datastore.c8
-rw-r--r--src/datastore/plugin_datastore_sqlite.c893
-rw-r--r--src/datastore/test_datastore_api.c10
-rw-r--r--src/datastore/test_datastore_api_management.c4
-rw-r--r--src/datastore/test_plugin_datastore.c8
8 files changed, 765 insertions, 910 deletions
diff --git a/src/datastore/gnunet-datastore.c b/src/datastore/gnunet-datastore.c
index cd089071c..4cf318777 100644
--- a/src/datastore/gnunet-datastore.c
+++ b/src/datastore/gnunet-datastore.c
@@ -66,7 +66,6 @@ struct DataRecord
* Key under which the item can be found.
*/
struct GNUNET_HashCode key;
-
};
GNUNET_NETWORK_STRUCT_END
@@ -185,13 +184,11 @@ get_cb (void *cls,
qe = NULL;
if (NULL == key)
{
- FPRINTF (stderr,
- _("Dumped %" PRIu64 " records\n"),
- record_count);
+ fprintf (stderr, _ ("Dumped %" PRIu64 " records\n"), record_count);
GNUNET_DISK_file_close (file_handle);
file_handle = NULL;
if (insert)
- start_insert();
+ start_insert ();
else
{
ret = 0;
@@ -213,8 +210,8 @@ get_cb (void *cls,
len = GNUNET_DISK_file_write (file_handle, &dr, sizeof (dr));
if (sizeof (dr) != len)
{
- FPRINTF (stderr,
- _("Short write to file: %zd bytes expecting %zd\n"),
+ fprintf (stderr,
+ _ ("Short write to file: %zd bytes expecting %zd\n"),
len,
sizeof (dr));
ret = 1;
@@ -225,8 +222,8 @@ get_cb (void *cls,
len = GNUNET_DISK_file_write (file_handle, data, size);
if (size != len)
{
- FPRINTF (stderr,
- _("Short write to file: %zd bytes expecting %zd\n"),
+ fprintf (stderr,
+ _ ("Short write to file: %zd bytes expecting %zd\n"),
len,
size);
ret = 1;
@@ -235,7 +232,7 @@ get_cb (void *cls,
}
record_count++;
- do_get(uid + 1);
+ do_get (uid + 1);
}
@@ -257,8 +254,7 @@ do_get (const uint64_t next_uid)
NULL /* proc_cls */);
if (NULL == qe)
{
- FPRINTF (stderr,
- _("Error queueing datastore GET operation\n"));
+ fprintf (stderr, _ ("Error queueing datastore GET operation\n"));
ret = 1;
GNUNET_SCHEDULER_shutdown ();
}
@@ -277,15 +273,13 @@ start_dump ()
{
file_handle = GNUNET_DISK_file_open (file_name,
GNUNET_DISK_OPEN_WRITE |
- GNUNET_DISK_OPEN_TRUNCATE |
- GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_OPEN_TRUNCATE |
+ GNUNET_DISK_OPEN_CREATE,
GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
+ GNUNET_DISK_PERM_USER_WRITE);
if (NULL == file_handle)
{
- FPRINTF (stderr,
- _("Unable to open dump file: %s\n"),
- file_name);
+ fprintf (stderr, _ ("Unable to open dump file: %s\n"), file_name);
ret = 1;
GNUNET_SCHEDULER_shutdown ();
return;
@@ -296,7 +290,7 @@ start_dump ()
file_handle = GNUNET_DISK_get_handle_from_int_fd (STDOUT_FILENO);
}
GNUNET_DISK_file_write (file_handle, MAGIC_BYTES, MAGIC_LEN);
- do_get(0);
+ do_get (0);
}
@@ -322,9 +316,7 @@ put_cb (void *cls,
qe = NULL;
if (GNUNET_SYSERR == success)
{
- FPRINTF (stderr,
- _("Failed to store item: %s, aborting\n"),
- msg);
+ fprintf (stderr, _ ("Failed to store item: %s, aborting\n"), msg);
ret = 1;
GNUNET_SCHEDULER_shutdown ();
return;
@@ -336,17 +328,15 @@ put_cb (void *cls,
len = GNUNET_DISK_file_read (file_handle, &dr, sizeof (dr));
if (0 == len)
{
- FPRINTF (stderr,
- _("Inserted %" PRIu64 " records\n"),
- record_count);
+ fprintf (stderr, _ ("Inserted %" PRIu64 " records\n"), record_count);
ret = 0;
GNUNET_SCHEDULER_shutdown ();
return;
}
else if (sizeof (dr) != len)
{
- FPRINTF (stderr,
- _("Short read from file: %zd bytes expecting %zd\n"),
+ fprintf (stderr,
+ _ ("Short read from file: %zd bytes expecting %zd\n"),
len,
sizeof (dr));
ret = 1;
@@ -359,8 +349,8 @@ put_cb (void *cls,
len = GNUNET_DISK_file_read (file_handle, data, size);
if (size != len)
{
- FPRINTF (stderr,
- _("Short read from file: %zd bytes expecting %zd\n"),
+ fprintf (stderr,
+ _ ("Short read from file: %zd bytes expecting %zd\n"),
len,
size);
ret = 1;
@@ -385,8 +375,7 @@ put_cb (void *cls,
NULL);
if (NULL == qe)
{
- FPRINTF (stderr,
- _("Error queueing datastore PUT operation\n"));
+ fprintf (stderr, _ ("Error queueing datastore PUT operation\n"));
ret = 1;
GNUNET_SCHEDULER_shutdown ();
}
@@ -408,9 +397,7 @@ start_insert ()
GNUNET_DISK_PERM_NONE);
if (NULL == file_handle)
{
- FPRINTF (stderr,
- _("Unable to open dump file: %s\n"),
- file_name);
+ fprintf (stderr, _ ("Unable to open dump file: %s\n"), file_name);
ret = 1;
GNUNET_SCHEDULER_shutdown ();
return;
@@ -425,11 +412,9 @@ start_insert ()
ssize_t len;
len = GNUNET_DISK_file_read (file_handle, buf, MAGIC_LEN);
- if (len != MAGIC_LEN ||
- 0 != memcmp (buf, MAGIC_BYTES, MAGIC_LEN))
+ if (len != MAGIC_LEN || 0 != memcmp (buf, MAGIC_BYTES, MAGIC_LEN))
{
- FPRINTF (stderr,
- _("Input file is not of a supported format\n"));
+ fprintf (stderr, _ ("Input file is not of a supported format\n"));
return;
}
put_cb (NULL, GNUNET_YES, GNUNET_TIME_UNIT_ZERO_ABS, NULL);
@@ -454,20 +439,19 @@ run (void *cls,
datastore = GNUNET_DATASTORE_connect (cfg);
if (NULL == datastore)
{
- FPRINTF (stderr,
- _("Failed connecting to the datastore.\n"));
+ fprintf (stderr, _ ("Failed connecting to the datastore.\n"));
ret = 1;
GNUNET_SCHEDULER_shutdown ();
return;
}
if (dump)
- start_dump();
+ start_dump ();
else if (insert)
- start_insert();
+ start_insert ();
else
{
- FPRINTF (stderr,
- _("Please choose at least one operation: %s, %s\n"),
+ fprintf (stderr,
+ _ ("Please choose at least one operation: %s, %s\n"),
"dump",
"insert");
ret = 1;
@@ -484,34 +468,38 @@ run (void *cls,
* @return 0 ok, 1 on error
*/
int
-main (int argc,
- char *const *argv)
+main (int argc, char *const *argv)
{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_flag ('d',
- "dump",
- gettext_noop ("Dump all records from the datastore"),
- &dump),
- GNUNET_GETOPT_option_flag ('i',
- "insert",
- gettext_noop ("Insert records into the datastore"),
- &insert),
- GNUNET_GETOPT_option_filename ('f',
- "file",
- "FILENAME",
- gettext_noop ("File to dump or insert"),
- &file_name),
- GNUNET_GETOPT_OPTION_END
- };
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {GNUNET_GETOPT_option_flag ('d',
+ "dump",
+ gettext_noop (
+ "Dump all records from the datastore"),
+ &dump),
+ GNUNET_GETOPT_option_flag ('i',
+ "insert",
+ gettext_noop (
+ "Insert records into the datastore"),
+ &insert),
+ GNUNET_GETOPT_option_filename ('f',
+ "file",
+ "FILENAME",
+ gettext_noop ("File to dump or insert"),
+ &file_name),
+ GNUNET_GETOPT_OPTION_END};
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
if (GNUNET_OK !=
- GNUNET_PROGRAM_run (argc, argv, "gnunet-datastore",
- gettext_noop ("Manipulate GNUnet datastore"),
- options, &run, NULL))
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-datastore",
+ gettext_noop ("Manipulate GNUnet datastore"),
+ options,
+ &run,
+ NULL))
ret = 1;
- GNUNET_free ((void*) argv);
+ GNUNET_free ((void *) argv);
return ret;
}
diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c
index 70a946ca5..4596f6131 100644
--- a/src/datastore/gnunet-service-datastore.c
+++ b/src/datastore/gnunet-service-datastore.c
@@ -45,13 +45,15 @@
* How long are we at most keeping "expired" content
* past the expiration date in the database?
*/
-#define MAX_EXPIRE_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
+#define MAX_EXPIRE_DELAY \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
/**
* How fast are we allowed to query the database for deleting
* expired content? (1 item per second).
*/
-#define MIN_EXPIRE_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
+#define MIN_EXPIRE_DELAY \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
/**
* Name under which we store current space consumption.
@@ -97,7 +99,6 @@ struct DatastorePlugin
* for this plugin.
*/
struct GNUNET_DATASTORE_PluginEnvironment env;
-
};
@@ -131,11 +132,9 @@ struct ReservationList
* Reservation identifier.
*/
int32_t rid;
-
};
-
/**
* Our datastore plugin (NULL if not available).
*/
@@ -234,10 +233,7 @@ static int stats_worked;
static void
sync_stats ()
{
- GNUNET_STATISTICS_set (stats,
- quota_stat_name,
- payload,
- GNUNET_YES);
+ GNUNET_STATISTICS_set (stats, quota_stat_name, payload, GNUNET_YES);
GNUNET_STATISTICS_set (stats,
"# utilization by current datastore",
payload,
@@ -312,9 +308,10 @@ expired_processor (void *cls,
if (NULL == key)
{
expired_kill_task =
- GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- &delete_expired, NULL);
+ GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &delete_expired,
+ NULL);
return GNUNET_SYSERR;
}
now = GNUNET_TIME_absolute_get ();
@@ -322,17 +319,19 @@ expired_processor (void *cls,
{
/* finished processing */
expired_kill_task =
- GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- &delete_expired, NULL);
+ GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &delete_expired,
+ NULL);
return GNUNET_SYSERR;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Deleting content `%s' of type %u that expired %s ago\n",
- GNUNET_h2s (key), type,
- GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_difference (expiration,
- now),
- GNUNET_YES));
+ GNUNET_h2s (key),
+ type,
+ GNUNET_STRINGS_relative_time_to_string (
+ GNUNET_TIME_absolute_get_difference (expiration, now),
+ GNUNET_YES));
min_expiration = now;
GNUNET_STATISTICS_update (stats,
gettext_noop ("# bytes expired"),
@@ -340,9 +339,10 @@ expired_processor (void *cls,
GNUNET_YES);
GNUNET_CONTAINER_bloomfilter_remove (filter, key);
expired_kill_task =
- GNUNET_SCHEDULER_add_delayed_with_priority (MIN_EXPIRE_DELAY,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- &delete_expired, NULL);
+ GNUNET_SCHEDULER_add_delayed_with_priority (MIN_EXPIRE_DELAY,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &delete_expired,
+ NULL);
return GNUNET_NO;
}
@@ -359,9 +359,7 @@ static void
delete_expired (void *cls)
{
expired_kill_task = NULL;
- plugin->api->get_expiration (plugin->api->cls,
- &expired_processor,
- NULL);
+ plugin->api->get_expiration (plugin->api->cls, &expired_processor, NULL);
}
@@ -400,14 +398,17 @@ quota_processor (void *cls,
if (NULL == key)
return GNUNET_SYSERR;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Deleting %llu bytes of low-priority (%u) content `%s' of type %u at %s prior to expiration (still trying to free another %llu bytes)\n",
- (unsigned long long) (size + GNUNET_DATASTORE_ENTRY_OVERHEAD),
- (unsigned int) priority,
- GNUNET_h2s (key), type,
- GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (expiration),
- GNUNET_YES),
- *need);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Deleting %llu bytes of low-priority (%u) content `%s' of type %u at %s prior to expiration (still trying to free another %llu bytes)\n",
+ (unsigned long long) (size + GNUNET_DATASTORE_ENTRY_OVERHEAD),
+ (unsigned int) priority,
+ GNUNET_h2s (key),
+ type,
+ GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (
+ expiration),
+ GNUNET_YES),
+ *need);
if (size + GNUNET_DATASTORE_ENTRY_OVERHEAD > *need)
*need = 0;
else
@@ -418,7 +419,8 @@ quota_processor (void *cls,
min_expiration = expiration;
GNUNET_STATISTICS_update (stats,
gettext_noop ("# bytes purged (low-priority)"),
- size, GNUNET_YES);
+ size,
+ GNUNET_YES);
GNUNET_CONTAINER_bloomfilter_remove (filter, key);
return GNUNET_NO;
}
@@ -448,9 +450,7 @@ manage_space (unsigned long long need)
while ((need > 0) && (last != need))
{
last = need;
- plugin->api->get_expiration (plugin->api->cls,
- &quota_processor,
- &need);
+ plugin->api->get_expiration (plugin->api->cls, &quota_processor, &need);
}
}
@@ -473,18 +473,15 @@ transmit_status (struct GNUNET_SERVICE_Client *client,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Transmitting `%s' message with value %d and message `%s'\n",
- "STATUS", code, msg != NULL ? msg : "(none)");
+ "STATUS",
+ code,
+ msg != NULL ? msg : "(none)");
slen = (msg == NULL) ? 0 : strlen (msg) + 1;
- env = GNUNET_MQ_msg_extra (sm,
- slen,
- GNUNET_MESSAGE_TYPE_DATASTORE_STATUS);
+ env = GNUNET_MQ_msg_extra (sm, slen, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS);
sm->status = htonl (code);
sm->min_expiration = GNUNET_TIME_absolute_hton (min_expiration);
- GNUNET_memcpy (&sm[1],
- msg,
- slen);
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
- env);
+ GNUNET_memcpy (&sm[1], msg, slen);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
}
@@ -526,19 +523,13 @@ transmit_item (void *cls,
if (NULL == key)
{
/* transmit 'DATA_END' */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting DATA_END message\n");
- env = GNUNET_MQ_msg (end,
- GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END);
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
- env);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting DATA_END message\n");
+ env = GNUNET_MQ_msg (end, GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
return GNUNET_OK;
}
- GNUNET_assert (sizeof (struct DataMessage) + size <
- GNUNET_MAX_MESSAGE_SIZE);
- env = GNUNET_MQ_msg_extra (dm,
- size,
- GNUNET_MESSAGE_TYPE_DATASTORE_DATA);
+ GNUNET_assert (sizeof (struct DataMessage) + size < GNUNET_MAX_MESSAGE_SIZE);
+ env = GNUNET_MQ_msg_extra (dm, size, GNUNET_MESSAGE_TYPE_DATASTORE_DATA);
dm->rid = htonl (0);
dm->size = htonl (size);
dm->type = htonl (type);
@@ -548,22 +539,21 @@ transmit_item (void *cls,
dm->expiration = GNUNET_TIME_absolute_hton (expiration);
dm->uid = GNUNET_htonll (uid);
dm->key = *key;
- GNUNET_memcpy (&dm[1],
- data,
- size);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmitting DATA message for `%s' of type %u with expiration %s (in: %s)\n",
- GNUNET_h2s (key),
- type,
- GNUNET_STRINGS_absolute_time_to_string (expiration),
- GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (expiration),
- GNUNET_YES));
+ GNUNET_memcpy (&dm[1], data, size);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Transmitting DATA message for `%s' of type %u with expiration %s (in: %s)\n",
+ GNUNET_h2s (key),
+ type,
+ GNUNET_STRINGS_absolute_time_to_string (expiration),
+ GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (
+ expiration),
+ GNUNET_YES));
GNUNET_STATISTICS_update (stats,
gettext_noop ("# results found"),
1,
GNUNET_NO);
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
- env);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
return GNUNET_OK;
}
@@ -575,8 +565,7 @@ transmit_item (void *cls,
* @param message the actual message
*/
static void
-handle_reserve (void *cls,
- const struct ReserveMessage *msg)
+handle_reserve (void *cls, const struct ReserveMessage *msg)
{
/**
* Static counter to produce reservation identifiers.
@@ -589,20 +578,23 @@ handle_reserve (void *cls,
uint64_t amount;
uint32_t entries;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing RESERVE request\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing RESERVE request\n");
amount = GNUNET_ntohll (msg->amount);
entries = ntohl (msg->entries);
used = payload + reserved;
- req = amount + ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * entries;
+ req =
+ amount + ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * entries;
if (used + req > quota)
{
if (quota < used)
- used = quota; /* cheat a bit for error message (to avoid negative numbers) */
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Insufficient space (%llu bytes are available) to satisfy RESERVE request for %llu bytes\n"),
- quota - used,
- req);
+ used =
+ quota; /* cheat a bit for error message (to avoid negative numbers) */
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_WARNING,
+ _ (
+ "Insufficient space (%llu bytes are available) to satisfy RESERVE request for %llu bytes\n"),
+ quota - used,
+ req);
if (cache_size < req)
{
/* TODO: document this in the FAQ; essentially, if this
@@ -610,15 +602,17 @@ handle_reserve (void *cls,
* by less-important content from migration because it is
* larger than 1/8th of the overall available space, and
* we only reserve 1/8th for "fresh" insertions */
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("The requested amount (%llu bytes) is larger than the cache size (%llu bytes)\n"),
- req,
- cache_size);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_WARNING,
+ _ (
+ "The requested amount (%llu bytes) is larger than the cache size (%llu bytes)\n"),
+ req,
+ cache_size);
transmit_status (client,
0,
- gettext_noop
- ("Insufficient space to satisfy request and "
- "requested amount is larger than cache size"));
+ gettext_noop (
+ "Insufficient space to satisfy request and "
+ "requested amount is larger than cache size"));
}
else
{
@@ -642,10 +636,8 @@ handle_reserve (void *cls,
e->entries = entries;
e->rid = ++reservation_gen;
if (reservation_gen < 0)
- reservation_gen = 0; /* wrap around */
- transmit_status (client,
- e->rid,
- NULL);
+ reservation_gen = 0; /* wrap around */
+ transmit_status (client, e->rid, NULL);
GNUNET_SERVICE_client_continue (client);
}
@@ -657,8 +649,7 @@ handle_reserve (void *cls,
* @param message the actual message
*/
static void
-handle_release_reserve (void *cls,
- const struct ReleaseReserveMessage *msg)
+handle_release_reserve (void *cls, const struct ReleaseReserveMessage *msg)
{
struct GNUNET_SERVICE_Client *client = cls;
struct ReservationList *pos;
@@ -667,8 +658,7 @@ handle_release_reserve (void *cls,
int rid = ntohl (msg->rid);
unsigned long long rem;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing RELEASE_RESERVE request\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing RELEASE_RESERVE request\n");
next = reservations;
prev = NULL;
while (NULL != (pos = next))
@@ -681,8 +671,8 @@ handle_release_reserve (void *cls,
else
prev->next = next;
rem =
- pos->amount +
- ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries;
+ pos->amount +
+ ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries;
GNUNET_assert (reserved >= rem);
reserved -= rem;
GNUNET_STATISTICS_set (stats,
@@ -693,9 +683,7 @@ handle_release_reserve (void *cls,
"Returning %llu remaining reserved bytes to storage pool\n",
rem);
GNUNET_free (pos);
- transmit_status (client,
- GNUNET_OK,
- NULL);
+ transmit_status (client, GNUNET_OK, NULL);
GNUNET_SERVICE_client_continue (client);
return;
}
@@ -757,8 +745,7 @@ put_continuation (void *cls,
gettext_noop ("# bytes stored"),
size,
GNUNET_YES);
- GNUNET_CONTAINER_bloomfilter_add (filter,
- key);
+ GNUNET_CONTAINER_bloomfilter_add (filter, key);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Successfully stored %u bytes under key `%s'\n",
size,
@@ -770,7 +757,7 @@ put_continuation (void *cls,
if (quota - reserved - cache_size < payload)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Need %llu bytes more space (%llu allowed, using %llu)\n"),
+ _ ("Need %llu bytes more space (%llu allowed, using %llu)\n"),
(unsigned long long) size + GNUNET_DATASTORE_ENTRY_OVERHEAD,
(unsigned long long) (quota - reserved - cache_size),
(unsigned long long) payload);
@@ -787,8 +774,7 @@ put_continuation (void *cls,
* @return #GNUNET_OK if @a dm is well-formed
*/
static int
-check_put (void *cls,
- const struct DataMessage *dm)
+check_put (void *cls, const struct DataMessage *dm)
{
if (GNUNET_OK != check_data (dm))
{
@@ -806,8 +792,7 @@ check_put (void *cls,
* @param message the actual message
*/
static void
-handle_put (void *cls,
- const struct DataMessage *dm)
+handle_put (void *cls, const struct DataMessage *dm)
{
struct GNUNET_SERVICE_Client *client = cls;
int rid;
@@ -839,8 +824,8 @@ handle_put (void *cls,
GNUNET_NO);
}
}
- bool absent = GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test (filter,
- &dm->key);
+ bool absent =
+ GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test (filter, &dm->key);
plugin->api->put (plugin->api->cls,
&dm->key,
absent,
@@ -864,8 +849,7 @@ handle_put (void *cls,
* @param msg the actual message
*/
static void
-handle_get (void *cls,
- const struct GetMessage *msg)
+handle_get (void *cls, const struct GetMessage *msg)
{
struct GNUNET_SERVICE_Client *client = cls;
@@ -894,8 +878,7 @@ handle_get (void *cls,
* @param msg the actual message
*/
static void
-handle_get_key (void *cls,
- const struct GetKeyMessage *msg)
+handle_get_key (void *cls, const struct GetKeyMessage *msg)
{
struct GNUNET_SERVICE_Client *client = cls;
@@ -907,21 +890,25 @@ handle_get_key (void *cls,
gettext_noop ("# GET KEY requests received"),
1,
GNUNET_NO);
- if (GNUNET_YES !=
- GNUNET_CONTAINER_bloomfilter_test (filter,
- &msg->key))
+ if (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (filter, &msg->key))
{
/* don't bother database... */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Empty result set for GET request for `%s' (bloomfilter).\n",
GNUNET_h2s (&msg->key));
GNUNET_STATISTICS_update (stats,
- gettext_noop
- ("# requests filtered by bloomfilter"),
+ gettext_noop (
+ "# requests filtered by bloomfilter"),
1,
GNUNET_NO);
transmit_item (client,
- NULL, 0, NULL, 0, 0, 0, 0,
+ NULL,
+ 0,
+ NULL,
+ 0,
+ 0,
+ 0,
+ 0,
GNUNET_TIME_UNIT_ZERO_ABS,
0);
GNUNET_SERVICE_client_continue (client);
@@ -945,20 +932,17 @@ handle_get_key (void *cls,
* @param message the actual message
*/
static void
-handle_get_replication (void *cls,
- const struct GNUNET_MessageHeader *message)
+handle_get_replication (void *cls, const struct GNUNET_MessageHeader *message)
{
struct GNUNET_SERVICE_Client *client = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing GET_REPLICATION request\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing GET_REPLICATION request\n");
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# GET REPLICATION requests received"),
+ gettext_noop (
+ "# GET REPLICATION requests received"),
1,
GNUNET_NO);
- plugin->api->get_replication (plugin->api->cls,
- &transmit_item,
- client);
+ plugin->api->get_replication (plugin->api->cls, &transmit_item, client);
GNUNET_SERVICE_client_continue (client);
}
@@ -970,8 +954,7 @@ handle_get_replication (void *cls,
* @param message the actual message
*/
static void
-handle_get_zero_anonymity (void *cls,
- const struct GetZeroAnonymityMessage *msg)
+handle_get_zero_anonymity (void *cls, const struct GetZeroAnonymityMessage *msg)
{
struct GNUNET_SERVICE_Client *client = cls;
enum GNUNET_BLOCK_Type type;
@@ -986,7 +969,8 @@ handle_get_zero_anonymity (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Processing GET_ZERO_ANONYMITY request\n");
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# GET ZERO ANONYMITY requests received"),
+ gettext_noop (
+ "# GET ZERO ANONYMITY requests received"),
1,
GNUNET_NO);
plugin->api->get_zero_anonymity (plugin->api->cls,
@@ -1019,21 +1003,15 @@ remove_continuation (void *cls,
if (GNUNET_SYSERR == status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "REMOVE request failed: %s.\n",
- msg);
- transmit_status (client,
- GNUNET_NO,
- msg);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "REMOVE request failed: %s.\n", msg);
+ transmit_status (client, GNUNET_NO, msg);
return;
}
if (GNUNET_NO == status)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Content not found for REMOVE request.\n");
- transmit_status (client,
- GNUNET_NO,
- _("Content not found"));
+ transmit_status (client, GNUNET_NO, _ ("Content not found"));
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1043,11 +1021,8 @@ remove_continuation (void *cls,
gettext_noop ("# bytes removed (explicit request)"),
size,
GNUNET_YES);
- GNUNET_CONTAINER_bloomfilter_remove (filter,
- key);
- transmit_status (client,
- GNUNET_OK,
- NULL);
+ GNUNET_CONTAINER_bloomfilter_remove (filter, key);
+ transmit_status (client, GNUNET_OK, NULL);
}
@@ -1059,8 +1034,7 @@ remove_continuation (void *cls,
* @return #GNUNET_OK if @a dm is well-formed
*/
static int
-check_remove (void *cls,
- const struct DataMessage *dm)
+check_remove (void *cls, const struct DataMessage *dm)
{
if (GNUNET_OK != check_data (dm))
{
@@ -1079,14 +1053,14 @@ check_remove (void *cls,
* @param message the actual message
*/
static void
-handle_remove (void *cls,
- const struct DataMessage *dm)
+handle_remove (void *cls, const struct DataMessage *dm)
{
struct GNUNET_SERVICE_Client *client = cls;
GNUNET_STATISTICS_update (stats,
gettext_noop ("# REMOVE requests received"),
- 1, GNUNET_NO);
+ 1,
+ GNUNET_NO);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Processing REMOVE request for `%s'\n",
GNUNET_h2s (&dm->key));
@@ -1107,13 +1081,11 @@ handle_remove (void *cls,
* @param message the actual message
*/
static void
-handle_drop (void *cls,
- const struct GNUNET_MessageHeader *message)
+handle_drop (void *cls, const struct GNUNET_MessageHeader *message)
{
struct GNUNET_SERVICE_Client *client = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processing DROP request\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing DROP request\n");
do_drop = GNUNET_YES;
GNUNET_SERVICE_client_continue (client);
}
@@ -1128,21 +1100,21 @@ handle_drop (void *cls,
* 0 for "reset to empty"
*/
static void
-disk_utilization_change_cb (void *cls,
- int delta)
+disk_utilization_change_cb (void *cls, int delta)
{
if ((delta < 0) && (payload < -delta))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Datastore payload must have been inaccurate (%lld < %lld). Recomputing it.\n"),
- (long long) payload,
- (long long) -delta);
- plugin->api->estimate_size (plugin->api->cls,
- &payload);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_WARNING,
+ _ (
+ "Datastore payload must have been inaccurate (%lld < %lld). Recomputing it.\n"),
+ (long long) payload,
+ (long long) -delta);
+ plugin->api->estimate_size (plugin->api->cls, &payload);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("New payload: %lld\n"),
+ _ ("New payload: %lld\n"),
(long long) payload);
- sync_stats ();
+ sync_stats ();
return;
}
payload += delta;
@@ -1172,10 +1144,11 @@ process_stat_in (void *cls,
GNUNET_assert (GNUNET_NO == stats_worked);
stats_worked = GNUNET_YES;
payload += value;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Notification from statistics about existing payload (%llu), new payload is %llu\n",
- (unsigned long long) value,
- (unsigned long long) payload);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Notification from statistics about existing payload (%llu), new payload is %llu\n",
+ (unsigned long long) value,
+ (unsigned long long) payload);
return GNUNET_OK;
}
@@ -1194,19 +1167,16 @@ load_plugin ()
ret->env.duc = &disk_utilization_change_cb;
ret->env.cls = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Loading `%s' datastore plugin\n"),
+ _ ("Loading `%s' datastore plugin\n"),
plugin_name);
- GNUNET_asprintf (&libname,
- "libgnunet_plugin_datastore_%s",
- plugin_name);
+ GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", plugin_name);
ret->short_name = GNUNET_strdup (plugin_name);
ret->lib_name = libname;
- ret->api = GNUNET_PLUGIN_load (libname,
- &ret->env);
+ ret->api = GNUNET_PLUGIN_load (libname, &ret->env);
if (NULL == ret->api)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to load datastore plugin for `%s'\n"),
+ _ ("Failed to load datastore plugin for `%s'\n"),
plugin_name);
GNUNET_free (ret->short_name);
GNUNET_free (libname);
@@ -1242,10 +1212,10 @@ static void
begin_service ()
{
GNUNET_SERVICE_resume (service);
- expired_kill_task
- = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &delete_expired,
- NULL);
+ expired_kill_task =
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &delete_expired,
+ NULL);
}
@@ -1258,22 +1228,21 @@ begin_service ()
*/
static void
add_key_to_bloomfilter (void *cls,
- const struct GNUNET_HashCode *key,
- unsigned int count)
+ const struct GNUNET_HashCode *key,
+ unsigned int count)
{
struct GNUNET_CONTAINER_BloomFilter *bf = cls;
if (NULL == key)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Bloomfilter construction complete.\n"));
+ _ ("Bloomfilter construction complete.\n"));
begin_service ();
return;
}
while (0 < count--)
- GNUNET_CONTAINER_bloomfilter_add (bf,
- key);
+ GNUNET_CONTAINER_bloomfilter_add (bf, key);
}
@@ -1285,8 +1254,7 @@ add_key_to_bloomfilter (void *cls,
* @param success #GNUNET_NO if we failed to read the stat
*/
static void
-process_stat_done (void *cls,
- int success)
+process_stat_done (void *cls, int success)
{
stat_get = NULL;
if (NULL != stat_timeout_task)
@@ -1301,8 +1269,7 @@ process_stat_done (void *cls,
filter = NULL;
if (NULL != stats)
{
- GNUNET_STATISTICS_destroy (stats,
- GNUNET_YES);
+ GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
stats = NULL;
}
return;
@@ -1312,28 +1279,26 @@ process_stat_done (void *cls,
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Failed to obtain value from statistics service, recomputing it\n");
- plugin->api->estimate_size (plugin->api->cls,
- &payload);
+ plugin->api->estimate_size (plugin->api->cls, &payload);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("New payload: %lld\n"),
+ _ ("New payload: %lld\n"),
(long long) payload);
}
if (GNUNET_YES == refresh_bf)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Rebuilding bloomfilter. Please be patient.\n"));
+ _ ("Rebuilding bloomfilter. Please be patient.\n"));
if (NULL != plugin->api->get_keys)
{
- plugin->api->get_keys (plugin->api->cls,
- &add_key_to_bloomfilter,
- filter);
+ plugin->api->get_keys (plugin->api->cls, &add_key_to_bloomfilter, filter);
return;
}
else
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Plugin does not support get_keys function. Please fix!\n"));
+ _ (
+ "Plugin does not support get_keys function. Please fix!\n"));
}
}
begin_service ();
@@ -1350,8 +1315,7 @@ stat_timeout (void *cls)
{
stat_timeout_task = NULL;
GNUNET_STATISTICS_get_cancel (stat_get);
- process_stat_done (NULL,
- GNUNET_NO);
+ process_stat_done (NULL, GNUNET_NO);
}
@@ -1369,8 +1333,7 @@ cleaning_task (void *cls)
}
if (GNUNET_YES == do_drop)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Dropping database!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dropping database!\n");
plugin->api->drop (plugin->api->cls);
payload = 0;
last_sync++;
@@ -1401,8 +1364,7 @@ cleaning_task (void *cls)
sync_stats ();
if (NULL != stats)
{
- GNUNET_STATISTICS_destroy (stats,
- GNUNET_YES);
+ GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
stats = NULL;
}
GNUNET_free (quota_stat_name);
@@ -1420,8 +1382,8 @@ cleaning_task (void *cls)
*/
static void *
client_connect_cb (void *cls,
- struct GNUNET_SERVICE_Client *client,
- struct GNUNET_MQ_Handle *mq)
+ struct GNUNET_SERVICE_Client *client,
+ struct GNUNET_MQ_Handle *mq)
{
return client;
}
@@ -1437,8 +1399,8 @@ client_connect_cb (void *cls,
*/
static void
client_disconnect_cb (void *cls,
- struct GNUNET_SERVICE_Client *client,
- void *app_ctx)
+ struct GNUNET_SERVICE_Client *client,
+ void *app_ctx)
{
struct ReservationList *pos;
struct ReservationList *prev;
@@ -1469,7 +1431,6 @@ client_disconnect_cb (void *cls,
gettext_noop ("# reserved"),
reserved,
GNUNET_NO);
-
}
@@ -1491,11 +1452,10 @@ run (void *cls,
service = serv;
cfg = c;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "DATASTORE",
- "DATABASE",
- &plugin_name))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
+ "DATASTORE",
+ "DATABASE",
+ &plugin_name))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"DATABASE",
@@ -1503,26 +1463,17 @@ run (void *cls,
return;
}
GNUNET_asprintf (&quota_stat_name,
- _("# bytes used in file-sharing datastore `%s'"),
- plugin_name);
+ _ ("# bytes used in file-sharing datastore `%s'"),
+ plugin_name);
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_size (cfg,
- "DATASTORE",
- "QUOTA",
- &quota))
+ GNUNET_CONFIGURATION_get_value_size (cfg, "DATASTORE", "QUOTA", &quota))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "QUOTA",
- "DATASTORE");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "QUOTA", "DATASTORE");
return;
}
- stats = GNUNET_STATISTICS_create ("datastore",
- cfg);
- GNUNET_STATISTICS_set (stats,
- gettext_noop ("# quota"),
- quota,
- GNUNET_NO);
- cache_size = quota / 8; /* Or should we make this an option? */
+ stats = GNUNET_STATISTICS_create ("datastore", cfg);
+ GNUNET_STATISTICS_set (stats, gettext_noop ("# quota"), quota, GNUNET_NO);
+ cache_size = quota / 8; /* Or should we make this an option? */
GNUNET_STATISTICS_set (stats,
gettext_noop ("# cache size"),
cache_size,
@@ -1530,17 +1481,17 @@ run (void *cls,
if (quota / (32 * 1024LL) > MAX_BF_SIZE)
bf_size = MAX_BF_SIZE;
else
- bf_size = quota / (32 * 1024LL); /* 8 bit per entry, 1 bit per 32 kb in DB */
+ bf_size =
+ quota / (32 * 1024LL); /* 8 bit per entry, 1 bit per 32 kb in DB */
fn = NULL;
- if ((GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "DATASTORE",
- "BLOOMFILTER",
- &fn)) ||
+ if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "DATASTORE",
+ "BLOOMFILTER",
+ &fn)) ||
(GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Could not use specified filename `%s' for bloomfilter.\n"),
+ _ ("Could not use specified filename `%s' for bloomfilter.\n"),
NULL != fn ? fn : "");
GNUNET_free_non_null (fn);
fn = NULL;
@@ -1550,139 +1501,150 @@ run (void *cls,
GNUNET_asprintf (&pfn, "%s.%s", fn, plugin_name);
if (GNUNET_YES == GNUNET_DISK_file_test (pfn))
{
- filter = GNUNET_CONTAINER_bloomfilter_load (pfn, bf_size, 5); /* approx. 3% false positives at max use */
+ filter =
+ GNUNET_CONTAINER_bloomfilter_load (pfn,
+ bf_size,
+ 5); /* approx. 3% false positives at max use */
if (NULL == filter)
{
- /* file exists but not valid, remove and try again, but refresh */
- if (0 != UNLINK (pfn))
- {
- /* failed to remove, run without file */
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to remove bogus bloomfilter file `%s'\n"),
- pfn);
- GNUNET_free (pfn);
- pfn = NULL;
- filter = GNUNET_CONTAINER_bloomfilter_load (NULL, bf_size, 5); /* approx. 3% false positives at max use */
- refresh_bf = GNUNET_YES;
- }
- else
- {
- /* try again after remove */
- filter = GNUNET_CONTAINER_bloomfilter_load (pfn, bf_size, 5); /* approx. 3% false positives at max use */
- refresh_bf = GNUNET_YES;
- if (NULL == filter)
- {
- /* failed yet again, give up on using file */
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to remove bogus bloomfilter file `%s'\n"),
- pfn);
- GNUNET_free (pfn);
- pfn = NULL;
- filter = GNUNET_CONTAINER_bloomfilter_init (NULL, bf_size, 5); /* approx. 3% false positives at max use */
- }
- }
+ /* file exists but not valid, remove and try again, but refresh */
+ if (0 != unlink (pfn))
+ {
+ /* failed to remove, run without file */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Failed to remove bogus bloomfilter file `%s'\n"),
+ pfn);
+ GNUNET_free (pfn);
+ pfn = NULL;
+ filter = GNUNET_CONTAINER_bloomfilter_load (
+ NULL,
+ bf_size,
+ 5); /* approx. 3% false positives at max use */
+ refresh_bf = GNUNET_YES;
+ }
+ else
+ {
+ /* try again after remove */
+ filter = GNUNET_CONTAINER_bloomfilter_load (
+ pfn,
+ bf_size,
+ 5); /* approx. 3% false positives at max use */
+ refresh_bf = GNUNET_YES;
+ if (NULL == filter)
+ {
+ /* failed yet again, give up on using file */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Failed to remove bogus bloomfilter file `%s'\n"),
+ pfn);
+ GNUNET_free (pfn);
+ pfn = NULL;
+ filter = GNUNET_CONTAINER_bloomfilter_init (
+ NULL,
+ bf_size,
+ 5); /* approx. 3% false positives at max use */
+ }
+ }
}
else
{
- /* normal case: have an existing valid bf file, no need to refresh */
- refresh_bf = GNUNET_NO;
+ /* normal case: have an existing valid bf file, no need to refresh */
+ refresh_bf = GNUNET_NO;
}
}
else
{
- filter = GNUNET_CONTAINER_bloomfilter_load (pfn, bf_size, 5); /* approx. 3% false positives at max use */
+ filter =
+ GNUNET_CONTAINER_bloomfilter_load (pfn,
+ bf_size,
+ 5); /* approx. 3% false positives at max use */
refresh_bf = GNUNET_YES;
}
GNUNET_free (pfn);
}
else
{
- filter = GNUNET_CONTAINER_bloomfilter_init (NULL,
- bf_size,
- 5); /* approx. 3% false positives at max use */
+ filter =
+ GNUNET_CONTAINER_bloomfilter_init (NULL,
+ bf_size,
+ 5); /* approx. 3% false positives at max use */
refresh_bf = GNUNET_YES;
}
GNUNET_free_non_null (fn);
if (NULL == filter)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to initialize bloomfilter.\n"));
+ _ ("Failed to initialize bloomfilter.\n"));
if (NULL != stats)
{
- GNUNET_STATISTICS_destroy (stats,
- GNUNET_YES);
+ GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
stats = NULL;
}
return;
}
GNUNET_SERVICE_suspend (service);
- stat_get =
- GNUNET_STATISTICS_get (stats,
- "datastore",
- quota_stat_name,
- &process_stat_done,
- &process_stat_in,
- NULL);
+ stat_get = GNUNET_STATISTICS_get (stats,
+ "datastore",
+ quota_stat_name,
+ &process_stat_done,
+ &process_stat_in,
+ NULL);
if (NULL == stat_get)
- process_stat_done (NULL,
- GNUNET_SYSERR);
+ process_stat_done (NULL, GNUNET_SYSERR);
else
- stat_timeout_task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &stat_timeout,
- NULL);
- GNUNET_SCHEDULER_add_shutdown (&cleaning_task,
- NULL);
+ stat_timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &stat_timeout,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleaning_task, NULL);
}
/**
* Define "main" method using service macro.
*/
-GNUNET_SERVICE_MAIN
-("datastore",
- GNUNET_SERVICE_OPTION_NONE,
- &run,
- &client_connect_cb,
- &client_disconnect_cb,
- NULL,
- GNUNET_MQ_hd_fixed_size (reserve,
- GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE,
- struct ReserveMessage,
- NULL),
- GNUNET_MQ_hd_fixed_size (release_reserve,
- GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE,
- struct ReleaseReserveMessage,
- NULL),
- GNUNET_MQ_hd_var_size (put,
- GNUNET_MESSAGE_TYPE_DATASTORE_PUT,
- struct DataMessage,
- NULL),
- GNUNET_MQ_hd_fixed_size (get,
- GNUNET_MESSAGE_TYPE_DATASTORE_GET,
- struct GetMessage,
- NULL),
- GNUNET_MQ_hd_fixed_size (get_key,
- GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY,
- struct GetKeyMessage,
- NULL),
- GNUNET_MQ_hd_fixed_size (get_replication,
- GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION,
- struct GNUNET_MessageHeader,
- NULL),
- GNUNET_MQ_hd_fixed_size (get_zero_anonymity,
- GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY,
- struct GetZeroAnonymityMessage,
- NULL),
- GNUNET_MQ_hd_var_size (remove,
- GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE,
- struct DataMessage,
- NULL),
- GNUNET_MQ_hd_fixed_size (drop,
- GNUNET_MESSAGE_TYPE_DATASTORE_DROP,
- struct GNUNET_MessageHeader,
- NULL),
- GNUNET_MQ_handler_end ());
+GNUNET_SERVICE_MAIN (
+ "datastore",
+ GNUNET_SERVICE_OPTION_NONE,
+ &run,
+ &client_connect_cb,
+ &client_disconnect_cb,
+ NULL,
+ GNUNET_MQ_hd_fixed_size (reserve,
+ GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE,
+ struct ReserveMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (release_reserve,
+ GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE,
+ struct ReleaseReserveMessage,
+ NULL),
+ GNUNET_MQ_hd_var_size (put,
+ GNUNET_MESSAGE_TYPE_DATASTORE_PUT,
+ struct DataMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (get,
+ GNUNET_MESSAGE_TYPE_DATASTORE_GET,
+ struct GetMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (get_key,
+ GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY,
+ struct GetKeyMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (get_replication,
+ GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION,
+ struct GNUNET_MessageHeader,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (get_zero_anonymity,
+ GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY,
+ struct GetZeroAnonymityMessage,
+ NULL),
+ GNUNET_MQ_hd_var_size (remove,
+ GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE,
+ struct DataMessage,
+ NULL),
+ GNUNET_MQ_hd_fixed_size (drop,
+ GNUNET_MESSAGE_TYPE_DATASTORE_DROP,
+ struct GNUNET_MessageHeader,
+ NULL),
+ GNUNET_MQ_handler_end ());
/* end of gnunet-service-datastore.c */
diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c
index 2c261b155..96ec9e924 100644
--- a/src/datastore/perf_datastore_api.c
+++ b/src/datastore/perf_datastore_api.c
@@ -211,7 +211,7 @@ check_success (void *cls,
struct CpsRunContext *crc = cls;
#if REPORT_ID
- FPRINTF (stderr, "%s", (GNUNET_OK == success) ? "I" : "i");
+ fprintf (stderr, "%s", (GNUNET_OK == success) ? "I" : "i");
#endif
if (GNUNET_OK != success)
{
@@ -285,7 +285,7 @@ remove_next (void *cls,
return;
}
#if REPORT_ID
- FPRINTF (stderr, "%s", "D");
+ fprintf (stderr, "%s", "D");
#endif
GNUNET_assert (GNUNET_OK == success);
GNUNET_SCHEDULER_add_now (&run_continuation,
@@ -528,7 +528,7 @@ run_tests (void *cls,
if (success != GNUNET_YES)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n",
msg);
GNUNET_DATASTORE_disconnect (datastore,
@@ -573,7 +573,7 @@ run (void *cls,
0, 1,
&run_tests, crc))
{
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
"Test 'put' operation failed.\n");
ok = 1;
@@ -608,7 +608,7 @@ main (int argc,
&run,
NULL))
return 1;
- FPRINTF (stderr, "%s", "\n");
+ fprintf (stderr, "%s", "\n");
return ok;
}
diff --git a/src/datastore/perf_plugin_datastore.c b/src/datastore/perf_plugin_datastore.c
index f68d1f389..564f8f37b 100644
--- a/src/datastore/perf_plugin_datastore.c
+++ b/src/datastore/perf_plugin_datastore.c
@@ -122,7 +122,7 @@ put_continuation (void *cls,
if (GNUNET_OK != status)
{
- FPRINTF (stderr, "ERROR: `%s'\n", msg);
+ fprintf (stderr, "ERROR: `%s'\n", msg);
}
else
{
@@ -477,7 +477,7 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env)))
{
- FPRINTF (stderr, "Failed to load plugin `%s'!\n", name);
+ fprintf (stderr, "Failed to load plugin `%s'!\n", name);
GNUNET_free (name);
GNUNET_free (libname);
return NULL;
@@ -503,7 +503,7 @@ run (void *cls, char *const *args, const char *cfgfile,
api = load_plugin (c);
if (api == NULL)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"%s", "Could not initialize plugin, assuming database not configured. Test not run!\n");
return;
}
@@ -544,7 +544,7 @@ main (int argc, char *argv[])
GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
"perf-plugin-datastore", "nohelp", options, &run, NULL);
if (ok != 0)
- FPRINTF (stderr, "Missed some testcases: %u\n", ok);
+ fprintf (stderr, "Missed some testcases: %u\n", ok);
GNUNET_DISK_directory_remove (dir_name);
return ok;
diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c
index d548935ea..4bd2b39cb 100644
--- a/src/datastore/plugin_datastore_sqlite.c
+++ b/src/datastore/plugin_datastore_sqlite.c
@@ -1,4 +1,4 @@
- /*
+/*
* This file is part of GNUnet
* Copyright (C) 2009, 2011, 2017 GNUnet e.V.
*
@@ -55,7 +55,17 @@
* a failure of the command 'cmd' on file 'filename'
* with the message given by strerror(errno).
*/
-#define LOG_SQLITE(db, level, cmd) do { GNUNET_log_from (level, "sqlite", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); } while(0)
+#define LOG_SQLITE(db, level, cmd) \
+ do \
+ { \
+ GNUNET_log_from (level, \
+ "sqlite", \
+ _ ("`%s' failed at %s:%d with error: %s\n"), \
+ cmd, \
+ __FILE__, \
+ __LINE__, \
+ sqlite3_errmsg (db->dbh)); \
+ } while (0)
/**
@@ -63,8 +73,23 @@
* a failure of the command 'cmd' on file 'filename'
* with the message given by strerror(errno).
*/
-#define LOG_SQLITE_MSG(db, msg, level, cmd) do { GNUNET_log_from (level, "sqlite", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); GNUNET_asprintf(msg, _("`%s' failed at %s:%u with error: %s"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); } while(0)
-
+#define LOG_SQLITE_MSG(db, msg, level, cmd) \
+ do \
+ { \
+ GNUNET_log_from (level, \
+ "sqlite", \
+ _ ("`%s' failed at %s:%d with error: %s\n"), \
+ cmd, \
+ __FILE__, \
+ __LINE__, \
+ sqlite3_errmsg (db->dbh)); \
+ GNUNET_asprintf (msg, \
+ _ ("`%s' failed at %s:%u with error: %s"), \
+ cmd, \
+ __FILE__, \
+ __LINE__, \
+ sqlite3_errmsg (db->dbh)); \
+ } while (0)
/**
@@ -141,7 +166,6 @@ struct Plugin
* Should the database be dropped on shutdown?
*/
int drop_on_shutdown;
-
};
@@ -154,9 +178,7 @@ struct Plugin
* @return 0 on success
*/
static int
-sq_prepare (sqlite3 *dbh,
- const char *zSql,
- sqlite3_stmt **ppStmt)
+sq_prepare (sqlite3 *dbh, const char *zSql, sqlite3_stmt **ppStmt)
{
char *dummy;
int result;
@@ -182,37 +204,56 @@ sq_prepare (sqlite3 *dbh,
* @param dbh handle to the database
*/
static void
-create_indices (sqlite3 * dbh)
+create_indices (sqlite3 *dbh)
{
/* create indices */
- if (0 !=
- (SQLITE_OK !=
- sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS idx_hash ON gn091 (hash)",
- NULL, NULL, NULL)) +
+ if (
+ 0 !=
+ (SQLITE_OK !=
+ sqlite3_exec (dbh,
+ "CREATE INDEX IF NOT EXISTS idx_hash ON gn091 (hash)",
+ NULL,
+ NULL,
+ NULL)) +
(SQLITE_OK !=
- sqlite3_exec (dbh,
- "CREATE INDEX IF NOT EXISTS idx_anon_type ON gn091 (anonLevel ASC,type)",
- NULL, NULL, NULL)) +
+ sqlite3_exec (
+ dbh,
+ "CREATE INDEX IF NOT EXISTS idx_anon_type ON gn091 (anonLevel ASC,type)",
+ NULL,
+ NULL,
+ NULL)) +
(SQLITE_OK !=
sqlite3_exec (dbh,
"CREATE INDEX IF NOT EXISTS idx_expire ON gn091 (expire ASC)",
- NULL, NULL, NULL)) +
+ NULL,
+ NULL,
+ NULL)) +
(SQLITE_OK !=
- sqlite3_exec (dbh,
- "CREATE INDEX IF NOT EXISTS idx_repl_rvalue ON gn091 (repl,rvalue)",
- NULL, NULL, NULL)) )
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "sqlite",
- "Failed to create indices: %s\n", sqlite3_errmsg (dbh));
+ sqlite3_exec (
+ dbh,
+ "CREATE INDEX IF NOT EXISTS idx_repl_rvalue ON gn091 (repl,rvalue)",
+ NULL,
+ NULL,
+ NULL)))
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "sqlite",
+ "Failed to create indices: %s\n",
+ sqlite3_errmsg (dbh));
}
#if 0
-#define CHECK(a) GNUNET_break(a)
+#define CHECK(a) GNUNET_break (a)
#define ENULL NULL
#else
#define ENULL &e
#define ENULL_DEFINED 1
-#define CHECK(a) if (! (a)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", e); sqlite3_free(e); }
+#define CHECK(a) \
+ if (! (a)) \
+ { \
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", e); \
+ sqlite3_free (e); \
+ }
#endif
@@ -235,21 +276,19 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
char *e;
#endif
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "datastore-sqlite",
- "FILENAME",
- &afsdir))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "datastore-sqlite",
+ "FILENAME",
+ &afsdir))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "datastore-sqlite",
+ "datastore-sqlite",
"FILENAME");
return GNUNET_SYSERR;
}
if (GNUNET_OK != GNUNET_DISK_file_test (afsdir))
{
- if (GNUNET_OK !=
- GNUNET_DISK_directory_create_for_file (afsdir))
+ if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (afsdir))
{
GNUNET_break (0);
GNUNET_free (afsdir);
@@ -257,48 +296,46 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
}
/* database is new or got deleted, reset payload to zero! */
if (NULL != plugin->env->duc)
- plugin->env->duc (plugin->env->cls,
- 0);
+ plugin->env->duc (plugin->env->cls, 0);
}
/* afsdir should be UTF-8-encoded. If it isn't, it's a bug */
plugin->fn = afsdir;
/* Open database and precompile statements */
- if (SQLITE_OK !=
- sqlite3_open (plugin->fn, &plugin->dbh))
+ if (SQLITE_OK != sqlite3_open (plugin->fn, &plugin->dbh))
{
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "sqlite",
- _("Unable to initialize SQLite: %s.\n"),
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "sqlite",
+ _ ("Unable to initialize SQLite: %s.\n"),
sqlite3_errmsg (plugin->dbh));
return GNUNET_SYSERR;
}
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA temp_store=MEMORY", NULL, NULL,
- ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA synchronous=OFF", NULL, NULL,
- ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA legacy_file_format=OFF", NULL, NULL,
- ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA auto_vacuum=INCREMENTAL", NULL,
- NULL, ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL,
- ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA page_size=4096", NULL, NULL,
- ENULL));
-
- CHECK (SQLITE_OK ==
- sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS));
+ CHECK (
+ SQLITE_OK ==
+ sqlite3_exec (plugin->dbh, "PRAGMA temp_store=MEMORY", NULL, NULL, ENULL));
+ CHECK (
+ SQLITE_OK ==
+ sqlite3_exec (plugin->dbh, "PRAGMA synchronous=OFF", NULL, NULL, ENULL));
+ CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh,
+ "PRAGMA legacy_file_format=OFF",
+ NULL,
+ NULL,
+ ENULL));
+ CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh,
+ "PRAGMA auto_vacuum=INCREMENTAL",
+ NULL,
+ NULL,
+ ENULL));
+ CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh,
+ "PRAGMA locking_mode=EXCLUSIVE",
+ NULL,
+ NULL,
+ ENULL));
+ CHECK (
+ SQLITE_OK ==
+ sqlite3_exec (plugin->dbh, "PRAGMA page_size=4096", NULL, NULL, ENULL));
+
+ CHECK (SQLITE_OK == sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS));
/* We have to do it here, because otherwise precompiling SQL might fail */
@@ -312,152 +349,135 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
* we do math or inequality tests, so we can't handle the entire range of uint32_t.
* This will also cause problems for expiration times after 294247-01-10-04:00:54 UTC.
*/
- if ( (SQLITE_DONE ==
- sqlite3_step (stmt)) &&
- (SQLITE_OK !=
- sqlite3_exec (plugin->dbh,
- "CREATE TABLE gn091 ("
- " repl INT4 NOT NULL DEFAULT 0,"
- " type INT4 NOT NULL DEFAULT 0,"
- " prio INT4 NOT NULL DEFAULT 0,"
- " anonLevel INT4 NOT NULL DEFAULT 0,"
- " expire INT8 NOT NULL DEFAULT 0,"
- " rvalue INT8 NOT NULL,"
- " hash TEXT NOT NULL DEFAULT '',"
- " vhash TEXT NOT NULL DEFAULT '',"
- " value BLOB NOT NULL DEFAULT '')",
- NULL,
- NULL,
- NULL)) )
+ if ((SQLITE_DONE == sqlite3_step (stmt)) &&
+ (SQLITE_OK != sqlite3_exec (plugin->dbh,
+ "CREATE TABLE gn091 ("
+ " repl INT4 NOT NULL DEFAULT 0,"
+ " type INT4 NOT NULL DEFAULT 0,"
+ " prio INT4 NOT NULL DEFAULT 0,"
+ " anonLevel INT4 NOT NULL DEFAULT 0,"
+ " expire INT8 NOT NULL DEFAULT 0,"
+ " rvalue INT8 NOT NULL,"
+ " hash TEXT NOT NULL DEFAULT '',"
+ " vhash TEXT NOT NULL DEFAULT '',"
+ " value BLOB NOT NULL DEFAULT '')",
+ NULL,
+ NULL,
+ NULL)))
{
- LOG_SQLITE (plugin,
- GNUNET_ERROR_TYPE_ERROR,
- "sqlite3_exec");
+ LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec");
sqlite3_finalize (stmt);
return GNUNET_SYSERR;
}
sqlite3_finalize (stmt);
create_indices (plugin->dbh);
-#define RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, _ROWID_"
- if ( (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "UPDATE gn091 "
- "SET prio = prio + ?, "
- "repl = repl + ?, "
- "expire = MAX(expire, ?) "
- "WHERE hash = ? AND vhash = ?",
- &plugin->update)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "UPDATE gn091 " "SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?",
- &plugin->updRepl)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT " RESULT_COLUMNS " FROM gn091 "
- "WHERE repl=?2 AND " " (rvalue>=?1 OR "
- " NOT EXISTS (SELECT 1 FROM gn091 "
- "WHERE repl=?2 AND rvalue>=?1 LIMIT 1) ) "
- "ORDER BY rvalue ASC LIMIT 1",
- &plugin->selRepl)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT MAX(repl) FROM gn091",
- &plugin->maxRepl)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT " RESULT_COLUMNS " FROM gn091 "
- "WHERE NOT EXISTS (SELECT 1 FROM gn091 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) "
- "ORDER BY expire ASC LIMIT 1",
- &plugin->selExpi)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT " RESULT_COLUMNS " FROM gn091 "
- "WHERE _ROWID_ >= ? AND "
- "anonLevel = 0 AND "
- "type = ? "
- "ORDER BY _ROWID_ ASC LIMIT 1",
- &plugin->selZeroAnon)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "INSERT INTO gn091 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) "
- "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
- &plugin->insertContent)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT " RESULT_COLUMNS " FROM gn091 "
- "WHERE _ROWID_ >= ?1 "
- "ORDER BY _ROWID_ ASC LIMIT 1",
- &plugin->get[0])) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT " RESULT_COLUMNS " FROM gn091 "
- "WHERE _ROWID_ >= ?1 AND "
- "type = ?4 "
- "ORDER BY _ROWID_ ASC LIMIT 1",
- &plugin->get[1])) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT " RESULT_COLUMNS " FROM gn091 "
- "WHERE _ROWID_ >= ?1 AND "
- "hash = ?3 "
- "ORDER BY _ROWID_ ASC LIMIT 1",
- &plugin->get[2])) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT " RESULT_COLUMNS " FROM gn091 "
- "WHERE _ROWID_ >= ?1 AND "
- "hash = ?3 AND "
- "type = ?4 "
- "ORDER BY _ROWID_ ASC LIMIT 1",
- &plugin->get[3])) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT " RESULT_COLUMNS " FROM gn091 "
- "WHERE _ROWID_ >= ?1 AND "
- "rvalue >= ?2 "
- "ORDER BY _ROWID_ ASC LIMIT 1",
- &plugin->get[4])) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT " RESULT_COLUMNS " FROM gn091 "
- "WHERE _ROWID_ >= ?1 AND "
- "rvalue >= ?2 AND "
- "type = ?4 "
- "ORDER BY _ROWID_ ASC LIMIT 1",
- &plugin->get[5])) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT " RESULT_COLUMNS " FROM gn091 "
- "WHERE _ROWID_ >= ?1 AND "
- "rvalue >= ?2 AND "
- "hash = ?3 "
- "ORDER BY _ROWID_ ASC LIMIT 1",
- &plugin->get[6])) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT " RESULT_COLUMNS " FROM gn091 "
- "WHERE _ROWID_ >= ?1 AND "
- "rvalue >= ?2 AND "
- "hash = ?3 AND "
- "type = ?4 "
- "ORDER BY _ROWID_ ASC LIMIT 1",
- &plugin->get[7])) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "DELETE FROM gn091 WHERE _ROWID_ = ?",
- &plugin->delRow)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "DELETE FROM gn091 "
- "WHERE hash = ? AND "
- "value = ? ",
- &plugin->remove)) ||
- false)
+#define RESULT_COLUMNS \
+ "repl, type, prio, anonLevel, expire, hash, value, _ROWID_"
+ if (
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "UPDATE gn091 "
+ "SET prio = prio + ?, "
+ "repl = repl + ?, "
+ "expire = MAX(expire, ?) "
+ "WHERE hash = ? AND vhash = ?",
+ &plugin->update)) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "UPDATE gn091 "
+ "SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?",
+ &plugin->updRepl)) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT " RESULT_COLUMNS " FROM gn091 "
+ "WHERE repl=?2 AND "
+ " (rvalue>=?1 OR "
+ " NOT EXISTS (SELECT 1 FROM gn091 "
+ "WHERE repl=?2 AND rvalue>=?1 LIMIT 1) ) "
+ "ORDER BY rvalue ASC LIMIT 1",
+ &plugin->selRepl)) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT MAX(repl) FROM gn091",
+ &plugin->maxRepl)) ||
+ (SQLITE_OK !=
+ sq_prepare (plugin->dbh,
+ "SELECT " RESULT_COLUMNS " FROM gn091 "
+ "WHERE NOT EXISTS (SELECT 1 FROM gn091 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) "
+ "ORDER BY expire ASC LIMIT 1",
+ &plugin->selExpi)) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT " RESULT_COLUMNS " FROM gn091 "
+ "WHERE _ROWID_ >= ? AND "
+ "anonLevel = 0 AND "
+ "type = ? "
+ "ORDER BY _ROWID_ ASC LIMIT 1",
+ &plugin->selZeroAnon)) ||
+ (SQLITE_OK !=
+ sq_prepare (plugin->dbh,
+ "INSERT INTO gn091 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
+ &plugin->insertContent)) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT " RESULT_COLUMNS " FROM gn091 "
+ "WHERE _ROWID_ >= ?1 "
+ "ORDER BY _ROWID_ ASC LIMIT 1",
+ &plugin->get[0])) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT " RESULT_COLUMNS " FROM gn091 "
+ "WHERE _ROWID_ >= ?1 AND "
+ "type = ?4 "
+ "ORDER BY _ROWID_ ASC LIMIT 1",
+ &plugin->get[1])) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT " RESULT_COLUMNS " FROM gn091 "
+ "WHERE _ROWID_ >= ?1 AND "
+ "hash = ?3 "
+ "ORDER BY _ROWID_ ASC LIMIT 1",
+ &plugin->get[2])) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT " RESULT_COLUMNS " FROM gn091 "
+ "WHERE _ROWID_ >= ?1 AND "
+ "hash = ?3 AND "
+ "type = ?4 "
+ "ORDER BY _ROWID_ ASC LIMIT 1",
+ &plugin->get[3])) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT " RESULT_COLUMNS " FROM gn091 "
+ "WHERE _ROWID_ >= ?1 AND "
+ "rvalue >= ?2 "
+ "ORDER BY _ROWID_ ASC LIMIT 1",
+ &plugin->get[4])) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT " RESULT_COLUMNS " FROM gn091 "
+ "WHERE _ROWID_ >= ?1 AND "
+ "rvalue >= ?2 AND "
+ "type = ?4 "
+ "ORDER BY _ROWID_ ASC LIMIT 1",
+ &plugin->get[5])) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT " RESULT_COLUMNS " FROM gn091 "
+ "WHERE _ROWID_ >= ?1 AND "
+ "rvalue >= ?2 AND "
+ "hash = ?3 "
+ "ORDER BY _ROWID_ ASC LIMIT 1",
+ &plugin->get[6])) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "SELECT " RESULT_COLUMNS " FROM gn091 "
+ "WHERE _ROWID_ >= ?1 AND "
+ "rvalue >= ?2 AND "
+ "hash = ?3 AND "
+ "type = ?4 "
+ "ORDER BY _ROWID_ ASC LIMIT 1",
+ &plugin->get[7])) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "DELETE FROM gn091 WHERE _ROWID_ = ?",
+ &plugin->delRow)) ||
+ (SQLITE_OK != sq_prepare (plugin->dbh,
+ "DELETE FROM gn091 "
+ "WHERE hash = ? AND "
+ "value = ? ",
+ &plugin->remove)) ||
+ false)
{
- LOG_SQLITE (plugin,
- GNUNET_ERROR_TYPE_ERROR,
- "precompiling");
+ LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "precompiling");
return GNUNET_SYSERR;
}
return GNUNET_OK;
@@ -503,11 +523,12 @@ database_shutdown (struct Plugin *plugin)
#if SQLITE_VERSION_NUMBER >= 3007000
if (result == SQLITE_BUSY)
{
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
- "sqlite",
- _("Tried to close sqlite without finalizing all prepared statements.\n"));
- stmt = sqlite3_next_stmt (plugin->dbh,
- NULL);
+ GNUNET_log_from (
+ GNUNET_ERROR_TYPE_WARNING,
+ "sqlite",
+ _ (
+ "Tried to close sqlite without finalizing all prepared statements.\n"));
+ stmt = sqlite3_next_stmt (plugin->dbh, NULL);
while (NULL != stmt)
{
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
@@ -521,16 +542,13 @@ database_shutdown (struct Plugin *plugin)
"Failed to close statement %p: %d\n",
stmt,
result);
- stmt = sqlite3_next_stmt (plugin->dbh,
- NULL);
+ stmt = sqlite3_next_stmt (plugin->dbh, NULL);
}
result = sqlite3_close (plugin->dbh);
}
#endif
if (SQLITE_OK != result)
- LOG_SQLITE (plugin,
- GNUNET_ERROR_TYPE_ERROR,
- "sqlite3_close");
+ LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close");
GNUNET_free_non_null (plugin->fn);
}
@@ -543,28 +561,22 @@ database_shutdown (struct Plugin *plugin)
* @param rid the ID of the row to delete
*/
static int
-delete_by_rowid (struct Plugin *plugin,
- uint64_t rid)
+delete_by_rowid (struct Plugin *plugin, uint64_t rid)
{
- struct GNUNET_SQ_QueryParam params[] = {
- GNUNET_SQ_query_param_uint64 (&rid),
- GNUNET_SQ_query_param_end
- };
-
- if (GNUNET_OK !=
- GNUNET_SQ_bind (plugin->delRow,
- params))
+ struct GNUNET_SQ_QueryParam params[] = {GNUNET_SQ_query_param_uint64 (&rid),
+ GNUNET_SQ_query_param_end};
+
+ if (GNUNET_OK != GNUNET_SQ_bind (plugin->delRow, params))
return GNUNET_SYSERR;
if (SQLITE_DONE != sqlite3_step (plugin->delRow))
{
- LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ LOG_SQLITE (plugin,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_step");
- GNUNET_SQ_reset (plugin->dbh,
- plugin->delRow);
+ GNUNET_SQ_reset (plugin->dbh, plugin->delRow);
return GNUNET_SYSERR;
}
- GNUNET_SQ_reset (plugin->dbh,
- plugin->delRow);
+ GNUNET_SQ_reset (plugin->dbh, plugin->delRow);
return GNUNET_OK;
}
@@ -603,94 +615,78 @@ sqlite_plugin_put (void *cls,
struct GNUNET_HashCode vhash;
char *msg = NULL;
- GNUNET_CRYPTO_hash (data,
- size,
- &vhash);
+ GNUNET_CRYPTO_hash (data, size, &vhash);
- if (!absent)
+ if (! absent)
{
- struct GNUNET_SQ_QueryParam params[] = {
- GNUNET_SQ_query_param_uint32 (&priority),
- GNUNET_SQ_query_param_uint32 (&replication),
- GNUNET_SQ_query_param_absolute_time (&expiration),
- GNUNET_SQ_query_param_auto_from_type (key),
- GNUNET_SQ_query_param_auto_from_type (&vhash),
- GNUNET_SQ_query_param_end
- };
-
- if (GNUNET_OK !=
- GNUNET_SQ_bind (plugin->update,
- params))
+ struct GNUNET_SQ_QueryParam params[] =
+ {GNUNET_SQ_query_param_uint32 (&priority),
+ GNUNET_SQ_query_param_uint32 (&replication),
+ GNUNET_SQ_query_param_absolute_time (&expiration),
+ GNUNET_SQ_query_param_auto_from_type (key),
+ GNUNET_SQ_query_param_auto_from_type (&vhash),
+ GNUNET_SQ_query_param_end};
+
+ if (GNUNET_OK != GNUNET_SQ_bind (plugin->update, params))
{
- cont (cont_cls,
- key,
- size,
- GNUNET_SYSERR,
- _("sqlite bind failure"));
+ cont (cont_cls, key, size, GNUNET_SYSERR, _ ("sqlite bind failure"));
return;
}
if (SQLITE_DONE != sqlite3_step (plugin->update))
{
- LOG_SQLITE_MSG (plugin, &msg, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ LOG_SQLITE_MSG (plugin,
+ &msg,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_step");
- cont (cont_cls,
- key,
- size,
- GNUNET_SYSERR,
- msg);
+ cont (cont_cls, key, size, GNUNET_SYSERR, msg);
GNUNET_free_non_null (msg);
return;
}
int changes = sqlite3_changes (plugin->dbh);
- GNUNET_SQ_reset (plugin->dbh,
- plugin->update);
+ GNUNET_SQ_reset (plugin->dbh, plugin->update);
if (0 != changes)
{
- cont (cont_cls,
- key,
- size,
- GNUNET_NO,
- NULL);
+ cont (cont_cls, key, size, GNUNET_NO, NULL);
return;
}
}
uint64_t rvalue;
uint32_t type32 = (uint32_t) type;
- struct GNUNET_SQ_QueryParam params[] = {
- GNUNET_SQ_query_param_uint32 (&replication),
- GNUNET_SQ_query_param_uint32 (&type32),
- GNUNET_SQ_query_param_uint32 (&priority),
- GNUNET_SQ_query_param_uint32 (&anonymity),
- GNUNET_SQ_query_param_absolute_time (&expiration),
- GNUNET_SQ_query_param_uint64 (&rvalue),
- GNUNET_SQ_query_param_auto_from_type (key),
- GNUNET_SQ_query_param_auto_from_type (&vhash),
- GNUNET_SQ_query_param_fixed_size (data, size),
- GNUNET_SQ_query_param_end
- };
+ struct GNUNET_SQ_QueryParam params[] =
+ {GNUNET_SQ_query_param_uint32 (&replication),
+ GNUNET_SQ_query_param_uint32 (&type32),
+ GNUNET_SQ_query_param_uint32 (&priority),
+ GNUNET_SQ_query_param_uint32 (&anonymity),
+ GNUNET_SQ_query_param_absolute_time (&expiration),
+ GNUNET_SQ_query_param_uint64 (&rvalue),
+ GNUNET_SQ_query_param_auto_from_type (key),
+ GNUNET_SQ_query_param_auto_from_type (&vhash),
+ GNUNET_SQ_query_param_fixed_size (data, size),
+ GNUNET_SQ_query_param_end};
int n;
int ret;
sqlite3_stmt *stmt;
if (size > MAX_ITEM_SIZE)
{
- cont (cont_cls, key, size, GNUNET_SYSERR, _("Data too large"));
+ cont (cont_cls, key, size, GNUNET_SYSERR, _ ("Data too large"));
return;
}
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
- "Storing in database block with type %u/key `%s'/priority %u/expiration in %s (%s).\n",
- type,
- GNUNET_h2s (key),
- priority,
- GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (expiration),
- GNUNET_YES),
- GNUNET_STRINGS_absolute_time_to_string (expiration));
+ GNUNET_log_from (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "sqlite",
+ "Storing in database block with type %u/key `%s'/priority %u/expiration in %s (%s).\n",
+ type,
+ GNUNET_h2s (key),
+ priority,
+ GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (
+ expiration),
+ GNUNET_YES),
+ GNUNET_STRINGS_absolute_time_to_string (expiration));
stmt = plugin->insertContent;
rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
- if (GNUNET_OK !=
- GNUNET_SQ_bind (stmt,
- params))
+ if (GNUNET_OK != GNUNET_SQ_bind (stmt, params))
{
cont (cont_cls, key, size, GNUNET_SYSERR, NULL);
return;
@@ -702,7 +698,8 @@ sqlite_plugin_put (void *cls,
if (NULL != plugin->env->duc)
plugin->env->duc (plugin->env->cls,
size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "sqlite",
"Stored new entry (%u bytes)\n",
size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
ret = GNUNET_OK;
@@ -710,28 +707,26 @@ sqlite_plugin_put (void *cls,
case SQLITE_BUSY:
GNUNET_break (0);
LOG_SQLITE_MSG (plugin,
- &msg,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ &msg,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_step");
ret = GNUNET_SYSERR;
break;
default:
LOG_SQLITE_MSG (plugin,
- &msg,
- GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ &msg,
+ GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_step");
- GNUNET_SQ_reset (plugin->dbh,
- stmt);
+ GNUNET_SQ_reset (plugin->dbh, stmt);
database_shutdown (plugin);
database_setup (plugin->env->cfg, plugin);
cont (cont_cls, key, size, GNUNET_SYSERR, msg);
- GNUNET_free_non_null(msg);
+ GNUNET_free_non_null (msg);
return;
}
- GNUNET_SQ_reset (plugin->dbh,
- stmt);
+ GNUNET_SQ_reset (plugin->dbh, stmt);
cont (cont_cls, key, size, ret, msg);
- GNUNET_free_non_null(msg);
+ GNUNET_free_non_null (msg);
}
@@ -761,26 +756,22 @@ execute_get (struct Plugin *plugin,
size_t value_size;
struct GNUNET_HashCode key;
int ret;
- struct GNUNET_SQ_ResultSpec rs[] = {
- GNUNET_SQ_result_spec_uint32 (&replication),
- GNUNET_SQ_result_spec_uint32 (&type),
- GNUNET_SQ_result_spec_uint32 (&priority),
- GNUNET_SQ_result_spec_uint32 (&anonymity),
- GNUNET_SQ_result_spec_absolute_time (&expiration),
- GNUNET_SQ_result_spec_auto_from_type (&key),
- GNUNET_SQ_result_spec_variable_size (&value,
- &value_size),
- GNUNET_SQ_result_spec_uint64 (&rowid),
- GNUNET_SQ_result_spec_end
- };
+ struct GNUNET_SQ_ResultSpec rs[] =
+ {GNUNET_SQ_result_spec_uint32 (&replication),
+ GNUNET_SQ_result_spec_uint32 (&type),
+ GNUNET_SQ_result_spec_uint32 (&priority),
+ GNUNET_SQ_result_spec_uint32 (&anonymity),
+ GNUNET_SQ_result_spec_absolute_time (&expiration),
+ GNUNET_SQ_result_spec_auto_from_type (&key),
+ GNUNET_SQ_result_spec_variable_size (&value, &value_size),
+ GNUNET_SQ_result_spec_uint64 (&rowid),
+ GNUNET_SQ_result_spec_end};
n = sqlite3_step (stmt);
switch (n)
{
case SQLITE_ROW:
- if (GNUNET_OK !=
- GNUNET_SQ_extract_result (stmt,
- rs))
+ if (GNUNET_OK != GNUNET_SQ_extract_result (stmt, rs))
{
GNUNET_break (0);
break;
@@ -800,12 +791,9 @@ execute_get (struct Plugin *plugin,
expiration,
rowid);
GNUNET_SQ_cleanup_result (rs);
- GNUNET_SQ_reset (plugin->dbh,
- stmt);
- if ( (GNUNET_NO == ret) &&
- (GNUNET_OK == delete_by_rowid (plugin,
- rowid)) &&
- (NULL != plugin->env->duc) )
+ GNUNET_SQ_reset (plugin->dbh, stmt);
+ if ((GNUNET_NO == ret) && (GNUNET_OK == delete_by_rowid (plugin, rowid)) &&
+ (NULL != plugin->env->duc))
plugin->env->duc (plugin->env->cls,
-(value_size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
return;
@@ -819,20 +807,17 @@ execute_get (struct Plugin *plugin,
LOG_SQLITE (plugin,
GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_step");
- if (SQLITE_OK !=
- sqlite3_reset (stmt))
+ if (SQLITE_OK != sqlite3_reset (stmt))
LOG_SQLITE (plugin,
GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_reset");
GNUNET_break (0);
proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
database_shutdown (plugin);
- database_setup (plugin->env->cfg,
- plugin);
+ database_setup (plugin->env->cfg, plugin);
return;
}
- GNUNET_SQ_reset (plugin->dbh,
- stmt);
+ GNUNET_SQ_reset (plugin->dbh, stmt);
proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
}
@@ -858,16 +843,14 @@ sqlite_plugin_get_zero_anonymity (void *cls,
{
struct Plugin *plugin = cls;
uint32_t type32 = type;
- struct GNUNET_SQ_QueryParam params[] = {
- GNUNET_SQ_query_param_uint64 (&next_uid),
- GNUNET_SQ_query_param_uint32 (&type32),
- GNUNET_SQ_query_param_end
- };
+ struct GNUNET_SQ_QueryParam params[] = {GNUNET_SQ_query_param_uint64 (
+ &next_uid),
+ GNUNET_SQ_query_param_uint32 (
+ &type32),
+ GNUNET_SQ_query_param_end};
GNUNET_assert (type != GNUNET_BLOCK_TYPE_ANY);
- if (GNUNET_OK !=
- GNUNET_SQ_bind (plugin->selZeroAnon,
- params))
+ if (GNUNET_OK != GNUNET_SQ_bind (plugin->selZeroAnon, params))
{
proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
return;
@@ -905,13 +888,12 @@ sqlite_plugin_get_key (void *cls,
int use_type = GNUNET_BLOCK_TYPE_ANY != type;
int use_key = NULL != key;
sqlite3_stmt *stmt = plugin->get[use_rvalue * 4 + use_key * 2 + use_type];
- struct GNUNET_SQ_QueryParam params[] = {
- GNUNET_SQ_query_param_uint64 (&next_uid),
- GNUNET_SQ_query_param_uint64 (&rvalue),
- GNUNET_SQ_query_param_auto_from_type (key),
- GNUNET_SQ_query_param_uint32 (&type32),
- GNUNET_SQ_query_param_end
- };
+ struct GNUNET_SQ_QueryParam params[] =
+ {GNUNET_SQ_query_param_uint64 (&next_uid),
+ GNUNET_SQ_query_param_uint64 (&rvalue),
+ GNUNET_SQ_query_param_auto_from_type (key),
+ GNUNET_SQ_query_param_uint32 (&type32),
+ GNUNET_SQ_query_param_end};
/* SQLite doesn't like it when you try to bind a parameter greater than the
* last numbered parameter, but unused parameters in the middle are OK.
@@ -928,24 +910,18 @@ sqlite_plugin_get_key (void *cls,
}
if (random)
{
- rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT64_MAX);
+ rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
next_uid = 0;
}
else
rvalue = 0;
- if (GNUNET_OK !=
- GNUNET_SQ_bind (stmt,
- params))
+ if (GNUNET_OK != GNUNET_SQ_bind (stmt, params))
{
proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
return;
}
- execute_get (plugin,
- stmt,
- proc,
- proc_cls);
+ execute_get (plugin, stmt, proc, proc_cls);
}
@@ -1051,37 +1027,27 @@ sqlite_plugin_get_replication (void *cls,
struct ReplCtx rc;
uint64_t rvalue;
uint32_t repl;
- struct GNUNET_SQ_QueryParam params_sel_repl[] = {
- GNUNET_SQ_query_param_uint64 (&rvalue),
- GNUNET_SQ_query_param_uint32 (&repl),
- GNUNET_SQ_query_param_end
- };
- struct GNUNET_SQ_QueryParam params_upd_repl[] = {
- GNUNET_SQ_query_param_uint64 (&rc.uid),
- GNUNET_SQ_query_param_end
- };
+ struct GNUNET_SQ_QueryParam params_sel_repl[] =
+ {GNUNET_SQ_query_param_uint64 (&rvalue),
+ GNUNET_SQ_query_param_uint32 (&repl),
+ GNUNET_SQ_query_param_end};
+ struct GNUNET_SQ_QueryParam params_upd_repl[] =
+ {GNUNET_SQ_query_param_uint64 (&rc.uid), GNUNET_SQ_query_param_end};
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
"datastore-sqlite",
"Getting random block based on replication order.\n");
- if (SQLITE_ROW !=
- sqlite3_step (plugin->maxRepl))
+ if (SQLITE_ROW != sqlite3_step (plugin->maxRepl))
{
- GNUNET_SQ_reset (plugin->dbh,
- plugin->maxRepl);
+ GNUNET_SQ_reset (plugin->dbh, plugin->maxRepl);
/* DB empty */
proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
return;
}
- repl = sqlite3_column_int (plugin->maxRepl,
- 0);
- GNUNET_SQ_reset (plugin->dbh,
- plugin->maxRepl);
- rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT64_MAX);
- if (GNUNET_OK !=
- GNUNET_SQ_bind (plugin->selRepl,
- params_sel_repl))
+ repl = sqlite3_column_int (plugin->maxRepl, 0);
+ GNUNET_SQ_reset (plugin->dbh, plugin->maxRepl);
+ rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
+ if (GNUNET_OK != GNUNET_SQ_bind (plugin->selRepl, params_sel_repl))
{
proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
return;
@@ -1089,26 +1055,19 @@ sqlite_plugin_get_replication (void *cls,
rc.have_uid = GNUNET_SYSERR;
rc.proc = proc;
rc.proc_cls = proc_cls;
- execute_get (plugin,
- plugin->selRepl,
- &repl_proc,
- &rc);
+ execute_get (plugin, plugin->selRepl, &repl_proc, &rc);
if (GNUNET_YES == rc.have_uid)
{
- if (GNUNET_OK !=
- GNUNET_SQ_bind (plugin->updRepl,
- params_upd_repl))
+ if (GNUNET_OK != GNUNET_SQ_bind (plugin->updRepl, params_upd_repl))
{
proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
return;
}
- if (SQLITE_DONE !=
- sqlite3_step (plugin->updRepl))
+ if (SQLITE_DONE != sqlite3_step (plugin->updRepl))
LOG_SQLITE (plugin,
GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_step");
- GNUNET_SQ_reset (plugin->dbh,
- plugin->updRepl);
+ GNUNET_SQ_reset (plugin->dbh, plugin->updRepl);
}
if (GNUNET_SYSERR == rc.have_uid)
{
@@ -1127,25 +1086,24 @@ sqlite_plugin_get_replication (void *cls,
* @param proc_cls closure for @a proc
*/
static void
-sqlite_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
+sqlite_plugin_get_expiration (void *cls,
+ PluginDatumProcessor proc,
void *proc_cls)
{
struct Plugin *plugin = cls;
sqlite3_stmt *stmt;
struct GNUNET_TIME_Absolute now;
- struct GNUNET_SQ_QueryParam params[] = {
- GNUNET_SQ_query_param_absolute_time (&now),
- GNUNET_SQ_query_param_end
- };
-
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
- "sqlite",
- "Getting random block based on expiration and priority order.\n");
+ struct GNUNET_SQ_QueryParam params[] = {GNUNET_SQ_query_param_absolute_time (
+ &now),
+ GNUNET_SQ_query_param_end};
+
+ GNUNET_log_from (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "sqlite",
+ "Getting random block based on expiration and priority order.\n");
now = GNUNET_TIME_absolute_get ();
stmt = plugin->selExpi;
- if (GNUNET_OK !=
- GNUNET_SQ_bind (stmt,
- params))
+ if (GNUNET_OK != GNUNET_SQ_bind (stmt, params))
{
proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
return;
@@ -1162,52 +1120,35 @@ sqlite_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
* @param proc_cls closure for @a proc
*/
static void
-sqlite_plugin_get_keys (void *cls,
- PluginKeyProcessor proc,
- void *proc_cls)
+sqlite_plugin_get_keys (void *cls, PluginKeyProcessor proc, void *proc_cls)
{
struct Plugin *plugin = cls;
struct GNUNET_HashCode key;
- struct GNUNET_SQ_ResultSpec results[] = {
- GNUNET_SQ_result_spec_auto_from_type (&key),
- GNUNET_SQ_result_spec_end
- };
+ struct GNUNET_SQ_ResultSpec results[] =
+ {GNUNET_SQ_result_spec_auto_from_type (&key), GNUNET_SQ_result_spec_end};
sqlite3_stmt *stmt;
int ret;
GNUNET_assert (NULL != proc);
- if (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT hash FROM gn091",
- &stmt))
+ if (SQLITE_OK != sq_prepare (plugin->dbh, "SELECT hash FROM gn091", &stmt))
{
LOG_SQLITE (plugin,
GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "sqlite_prepare");
- proc (proc_cls,
- NULL,
- 0);
+ "sqlite_prepare");
+ proc (proc_cls, NULL, 0);
return;
}
while (SQLITE_ROW == (ret = sqlite3_step (stmt)))
{
- if (GNUNET_OK ==
- GNUNET_SQ_extract_result (stmt,
- results))
- proc (proc_cls,
- &key,
- 1);
+ if (GNUNET_OK == GNUNET_SQ_extract_result (stmt, results))
+ proc (proc_cls, &key, 1);
else
GNUNET_break (0);
}
if (SQLITE_DONE != ret)
- LOG_SQLITE (plugin,
- GNUNET_ERROR_TYPE_ERROR,
- "sqlite_step");
+ LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step");
sqlite3_finalize (stmt);
- proc (proc_cls,
- NULL,
- 0);
+ proc (proc_cls, NULL, 0);
}
@@ -1244,21 +1185,14 @@ sqlite_plugin_remove_key (void *cls,
void *cont_cls)
{
struct Plugin *plugin = cls;
- struct GNUNET_SQ_QueryParam params[] = {
- GNUNET_SQ_query_param_auto_from_type (key),
- GNUNET_SQ_query_param_fixed_size (data, size),
- GNUNET_SQ_query_param_end
- };
-
- if (GNUNET_OK !=
- GNUNET_SQ_bind (plugin->remove,
- params))
+ struct GNUNET_SQ_QueryParam params[] =
+ {GNUNET_SQ_query_param_auto_from_type (key),
+ GNUNET_SQ_query_param_fixed_size (data, size),
+ GNUNET_SQ_query_param_end};
+
+ if (GNUNET_OK != GNUNET_SQ_bind (plugin->remove, params))
{
- cont (cont_cls,
- key,
- size,
- GNUNET_SYSERR,
- "bind failed");
+ cont (cont_cls, key, size, GNUNET_SYSERR, "bind failed");
return;
}
if (SQLITE_DONE != sqlite3_step (plugin->remove))
@@ -1266,35 +1200,21 @@ sqlite_plugin_remove_key (void *cls,
LOG_SQLITE (plugin,
GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"sqlite3_step");
- GNUNET_SQ_reset (plugin->dbh,
- plugin->remove);
- cont (cont_cls,
- key,
- size,
- GNUNET_SYSERR,
- "sqlite3_step failed");
+ GNUNET_SQ_reset (plugin->dbh, plugin->remove);
+ cont (cont_cls, key, size, GNUNET_SYSERR, "sqlite3_step failed");
return;
}
int changes = sqlite3_changes (plugin->dbh);
- GNUNET_SQ_reset (plugin->dbh,
- plugin->remove);
+ GNUNET_SQ_reset (plugin->dbh, plugin->remove);
if (0 == changes)
{
- cont (cont_cls,
- key,
- size,
- GNUNET_NO,
- NULL);
+ cont (cont_cls, key, size, GNUNET_NO, NULL);
return;
}
if (NULL != plugin->env->duc)
plugin->env->duc (plugin->env->cls,
-(size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
- cont (cont_cls,
- key,
- size,
- GNUNET_OK,
- NULL);
+ cont (cont_cls, key, size, GNUNET_OK, NULL);
}
@@ -1306,8 +1226,7 @@ sqlite_plugin_remove_key (void *cls,
* @return the size of the database on disk (estimate)
*/
static void
-sqlite_plugin_estimate_size (void *cls,
- unsigned long long *estimate)
+sqlite_plugin_estimate_size (void *cls, unsigned long long *estimate)
{
struct Plugin *plugin = cls;
sqlite3_stmt *stmt;
@@ -1322,45 +1241,35 @@ sqlite_plugin_estimate_size (void *cls,
return;
if (SQLITE_VERSION_NUMBER < 3006000)
{
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
- "datastore-sqlite",
- _("sqlite version to old to determine size, assuming zero\n"));
+ GNUNET_log_from (
+ GNUNET_ERROR_TYPE_WARNING,
+ "datastore-sqlite",
+ _ ("sqlite version to old to determine size, assuming zero\n"));
*estimate = 0;
return;
}
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "VACUUM",
- NULL,
- NULL,
- ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA auto_vacuum=INCREMENTAL",
- NULL,
- NULL, ENULL));
- CHECK (SQLITE_OK ==
- sq_prepare (plugin->dbh,
- "PRAGMA page_count",
- &stmt));
+ CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, "VACUUM", NULL, NULL, ENULL));
+ CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh,
+ "PRAGMA auto_vacuum=INCREMENTAL",
+ NULL,
+ NULL,
+ ENULL));
+ CHECK (SQLITE_OK == sq_prepare (plugin->dbh, "PRAGMA page_count", &stmt));
if (SQLITE_ROW == sqlite3_step (stmt))
- pages = sqlite3_column_int64 (stmt,
- 0);
+ pages = sqlite3_column_int64 (stmt, 0);
else
pages = 0;
sqlite3_finalize (stmt);
- CHECK (SQLITE_OK ==
- sq_prepare (plugin->dbh,
- "PRAGMA page_size",
- &stmt));
- CHECK (SQLITE_ROW ==
- sqlite3_step (stmt));
+ CHECK (SQLITE_OK == sq_prepare (plugin->dbh, "PRAGMA page_size", &stmt));
+ CHECK (SQLITE_ROW == sqlite3_step (stmt));
page_size = sqlite3_column_int64 (stmt, 0);
sqlite3_finalize (stmt);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Using sqlite page utilization to estimate payload (%llu pages of size %llu bytes)\n"),
- (unsigned long long) pages,
- (unsigned long long) page_size);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_INFO,
+ _ (
+ "Using sqlite page utilization to estimate payload (%llu pages of size %llu bytes)\n"),
+ (unsigned long long) pages,
+ (unsigned long long) page_size);
*estimate = pages * page_size;
}
@@ -1379,10 +1288,8 @@ libgnunet_plugin_datastore_sqlite_init (void *cls)
struct GNUNET_DATASTORE_PluginFunctions *api;
if (NULL != plugin.env)
- return NULL; /* can only initialize once! */
- memset (&plugin,
- 0,
- sizeof (struct Plugin));
+ return NULL; /* can only initialize once! */
+ memset (&plugin, 0, sizeof (struct Plugin));
plugin.env = env;
if (GNUNET_OK != database_setup (env->cfg, &plugin))
{
@@ -1402,7 +1309,7 @@ libgnunet_plugin_datastore_sqlite_init (void *cls)
api->remove_key = &sqlite_plugin_remove_key;
GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
"sqlite",
- _("Sqlite database running\n"));
+ _ ("Sqlite database running\n"));
return api;
}
@@ -1431,10 +1338,8 @@ libgnunet_plugin_datastore_sqlite_done (void *cls)
GNUNET_free (api);
if (NULL != fn)
{
- if (0 != UNLINK (fn))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- fn);
+ if (0 != unlink (fn))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
GNUNET_free (fn);
}
return NULL;
diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c
index daf6cccb3..ee78a8cfc 100644
--- a/src/datastore/test_datastore_api.c
+++ b/src/datastore/test_datastore_api.c
@@ -251,11 +251,11 @@ check_value (void *cls,
return;
}
#if 0
- FPRINTF (stderr,
+ fprintf (stderr,
"Check value got `%s' of size %u, type %d, expire %s\n",
GNUNET_h2s (key), (unsigned int) size, type,
GNUNET_STRINGS_absolute_time_to_string (expiration));
- FPRINTF (stderr,
+ fprintf (stderr,
"Check value iteration %d wants size %u, type %d, expire %s\n", i,
(unsigned int) get_size (i), get_type (i),
GNUNET_STRINGS_absolute_time_to_string (get_expiration(i)));
@@ -555,14 +555,14 @@ run_tests (void *cls,
crc);
return;
case GNUNET_NO:
- FPRINTF (stderr,
+ fprintf (stderr,
"%s", "Test 'put' operation failed, key already exists (!?)\n");
GNUNET_DATASTORE_disconnect (datastore,
GNUNET_YES);
GNUNET_free (crc);
return;
case GNUNET_SYSERR:
- FPRINTF (stderr,
+ fprintf (stderr,
"Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n",
msg);
GNUNET_DATASTORE_disconnect (datastore,
@@ -609,7 +609,7 @@ run (void *cls,
0, 1,
&run_tests, crc))
{
- FPRINTF (stderr,
+ fprintf (stderr,
"%s",
"Test 'put' operation failed.\n");
ok = 1;
diff --git a/src/datastore/test_datastore_api_management.c b/src/datastore/test_datastore_api_management.c
index d91fe748b..fc4c03885 100644
--- a/src/datastore/test_datastore_api_management.c
+++ b/src/datastore/test_datastore_api_management.c
@@ -272,7 +272,7 @@ run_tests (void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, c
if (success != GNUNET_YES)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n",
msg);
GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
@@ -310,7 +310,7 @@ run (void *cls,
&run_tests,
crc))
{
- FPRINTF (stderr, "%s", "Test 'put' operation failed.\n");
+ fprintf (stderr, "%s", "Test 'put' operation failed.\n");
GNUNET_free (crc);
ok = 1;
}
diff --git a/src/datastore/test_plugin_datastore.c b/src/datastore/test_plugin_datastore.c
index c37b8ddb9..2b7bf9ae4 100644
--- a/src/datastore/test_plugin_datastore.c
+++ b/src/datastore/test_plugin_datastore.c
@@ -108,7 +108,7 @@ put_continuation (void *cls,
if (GNUNET_OK != status)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"ERROR: `%s'\n",
msg);
}
@@ -399,7 +399,7 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env)))
{
- FPRINTF (stderr, "Failed to load plugin `%s'!\n", name);
+ fprintf (stderr, "Failed to load plugin `%s'!\n", name);
GNUNET_free (libname);
GNUNET_free (name);
ok = 77; /* mark test as skipped */
@@ -421,7 +421,7 @@ run (void *cls, char *const *args, const char *cfgfile,
api = load_plugin (c);
if (api == NULL)
{
- FPRINTF (stderr,
+ fprintf (stderr,
"%s", "Could not initialize plugin, assuming database not configured. Test not run!\n");
return;
}
@@ -461,7 +461,7 @@ main (int argc, char *argv[])
GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
"test-plugin-datastore", "nohelp", options, &run, NULL);
if ( (0 != ok) && (77 != ok) )
- FPRINTF (stderr, "Missed some testcases: %u\n", ok);
+ fprintf (stderr, "Missed some testcases: %u\n", ok);
GNUNET_DISK_directory_remove (dir_name);
return ok;
}