aboutsummaryrefslogtreecommitdiff
path: root/src/datastore
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/datastore
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/datastore')
-rw-r--r--src/datastore/datastore.h21
-rw-r--r--src/datastore/datastore_api.c1295
-rw-r--r--src/datastore/gnunet-datastore.c431
-rw-r--r--src/datastore/gnunet-service-datastore.c1510
-rw-r--r--src/datastore/perf_datastore_api.c486
-rw-r--r--src/datastore/perf_plugin_datastore.c587
-rw-r--r--src/datastore/plugin_datastore_heap.c611
-rw-r--r--src/datastore/plugin_datastore_mysql.c1007
-rw-r--r--src/datastore/plugin_datastore_postgres.c936
-rw-r--r--src/datastore/plugin_datastore_sqlite.c1388
-rw-r--r--src/datastore/plugin_datastore_template.c115
-rw-r--r--src/datastore/test_datastore_api.c708
-rw-r--r--src/datastore/test_datastore_api_management.c381
-rw-r--r--src/datastore/test_plugin_datastore.c450
14 files changed, 5008 insertions, 4918 deletions
diff --git a/src/datastore/datastore.h b/src/datastore/datastore.h
index b4a51dc02..ee963b5ef 100644
--- a/src/datastore/datastore.h
+++ b/src/datastore/datastore.h
@@ -36,7 +36,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
36 * Message from datastore service informing client about 36 * Message from datastore service informing client about
37 * the current size of the datastore. 37 * the current size of the datastore.
38 */ 38 */
39struct ReserveMessage { 39struct ReserveMessage
40{
40 /** 41 /**
41 * Type is GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE. 42 * Type is GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE.
42 */ 43 */
@@ -60,7 +61,8 @@ struct ReserveMessage {
60 * This header is optionally followed by a variable-size, 61 * This header is optionally followed by a variable-size,
61 * 0-terminated error message. 62 * 0-terminated error message.
62 */ 63 */
63struct StatusMessage { 64struct StatusMessage
65{
64 /** 66 /**
65 * Type is GNUNET_MESSAGE_TYPE_DATASTORE_STATUS. 67 * Type is GNUNET_MESSAGE_TYPE_DATASTORE_STATUS.
66 */ 68 */
@@ -84,7 +86,8 @@ struct StatusMessage {
84 * the remainder of the reserved bytes can now be released 86 * the remainder of the reserved bytes can now be released
85 * for other requests. 87 * for other requests.
86 */ 88 */
87struct ReleaseReserveMessage { 89struct ReleaseReserveMessage
90{
88 /** 91 /**
89 * Type is GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE. 92 * Type is GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE.
90 */ 93 */
@@ -101,7 +104,8 @@ struct ReleaseReserveMessage {
101 * Message to the datastore service asking about specific 104 * Message to the datastore service asking about specific
102 * content. 105 * content.
103 */ 106 */
104struct GetKeyMessage { 107struct GetKeyMessage
108{
105 /** 109 /**
106 * Type is #GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY. 110 * Type is #GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY.
107 */ 111 */
@@ -133,7 +137,8 @@ struct GetKeyMessage {
133 * Message to the datastore service asking about specific 137 * Message to the datastore service asking about specific
134 * content. 138 * content.
135 */ 139 */
136struct GetMessage { 140struct GetMessage
141{
137 /** 142 /**
138 * Type is #GNUNET_MESSAGE_TYPE_DATASTORE_GET. 143 * Type is #GNUNET_MESSAGE_TYPE_DATASTORE_GET.
139 */ 144 */
@@ -160,7 +165,8 @@ struct GetMessage {
160 * Message to the datastore service asking about zero 165 * Message to the datastore service asking about zero
161 * anonymity content. 166 * anonymity content.
162 */ 167 */
163struct GetZeroAnonymityMessage { 168struct GetZeroAnonymityMessage
169{
164 /** 170 /**
165 * Type is GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY. 171 * Type is GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY.
166 */ 172 */
@@ -182,7 +188,8 @@ struct GetZeroAnonymityMessage {
182 * Message transmitting content from or to the datastore 188 * Message transmitting content from or to the datastore
183 * service. 189 * service.
184 */ 190 */
185struct DataMessage { 191struct DataMessage
192{
186 /** 193 /**
187 * Type is either GNUNET_MESSAGE_TYPE_DATASTORE_PUT, 194 * Type is either GNUNET_MESSAGE_TYPE_DATASTORE_PUT,
188 * GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE or 195 * GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE or
diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c
index 7069975e4..b10c43944 100644
--- a/src/datastore/datastore_api.c
+++ b/src/datastore/datastore_api.c
@@ -31,7 +31,7 @@
31#include "gnunet_statistics_service.h" 31#include "gnunet_statistics_service.h"
32#include "datastore.h" 32#include "datastore.h"
33 33
34#define LOG(kind, ...) GNUNET_log_from(kind, "datastore-api", __VA_ARGS__) 34#define LOG(kind, ...) GNUNET_log_from (kind, "datastore-api", __VA_ARGS__)
35 35
36#define DELAY_WARN_TIMEOUT GNUNET_TIME_UNIT_MINUTES 36#define DELAY_WARN_TIMEOUT GNUNET_TIME_UNIT_MINUTES
37 37
@@ -51,7 +51,8 @@
51/** 51/**
52 * Context for processing status messages. 52 * Context for processing status messages.
53 */ 53 */
54struct StatusContext { 54struct StatusContext
55{
55 /** 56 /**
56 * Continuation to call with the status. 57 * Continuation to call with the status.
57 */ 58 */
@@ -67,7 +68,8 @@ struct StatusContext {
67/** 68/**
68 * Context for processing result messages. 69 * Context for processing result messages.
69 */ 70 */
70struct ResultContext { 71struct ResultContext
72{
71 /** 73 /**
72 * Function to call with the result. 74 * Function to call with the result.
73 */ 75 */
@@ -83,7 +85,8 @@ struct ResultContext {
83/** 85/**
84 * Context for a queue operation. 86 * Context for a queue operation.
85 */ 87 */
86union QueueContext { 88union QueueContext
89{
87 struct StatusContext sc; 90 struct StatusContext sc;
88 91
89 struct ResultContext rc; 92 struct ResultContext rc;
@@ -93,7 +96,8 @@ union QueueContext {
93/** 96/**
94 * Entry in our priority queue. 97 * Entry in our priority queue.
95 */ 98 */
96struct GNUNET_DATASTORE_QueueEntry { 99struct GNUNET_DATASTORE_QueueEntry
100{
97 /** 101 /**
98 * This is a linked list. 102 * This is a linked list.
99 */ 103 */
@@ -157,7 +161,8 @@ struct GNUNET_DATASTORE_QueueEntry {
157/** 161/**
158 * Handle to the datastore service. 162 * Handle to the datastore service.
159 */ 163 */
160struct GNUNET_DATASTORE_Handle { 164struct GNUNET_DATASTORE_Handle
165{
161 /** 166 /**
162 * Our configuration. 167 * Our configuration.
163 */ 168 */
@@ -219,7 +224,7 @@ struct GNUNET_DATASTORE_Handle {
219 * @param cls the `struct GNUNET_DATASTORE_Handle` 224 * @param cls the `struct GNUNET_DATASTORE_Handle`
220 */ 225 */
221static void 226static void
222try_reconnect(void *cls); 227try_reconnect (void *cls);
223 228
224 229
225/** 230/**
@@ -229,20 +234,20 @@ try_reconnect(void *cls);
229 * @param h handle to datastore to disconnect and reconnect 234 * @param h handle to datastore to disconnect and reconnect
230 */ 235 */
231static void 236static void
232do_disconnect(struct GNUNET_DATASTORE_Handle *h) 237do_disconnect (struct GNUNET_DATASTORE_Handle *h)
233{ 238{
234 if (NULL == h->mq) 239 if (NULL == h->mq)
235 { 240 {
236 GNUNET_break(0); 241 GNUNET_break (0);
237 return; 242 return;
238 } 243 }
239 GNUNET_MQ_destroy(h->mq); 244 GNUNET_MQ_destroy (h->mq);
240 h->mq = NULL; 245 h->mq = NULL;
241 h->skip_next_messages = 0; 246 h->skip_next_messages = 0;
242 h->reconnect_task 247 h->reconnect_task
243 = GNUNET_SCHEDULER_add_delayed(h->retry_time, 248 = GNUNET_SCHEDULER_add_delayed (h->retry_time,
244 &try_reconnect, 249 &try_reconnect,
245 h); 250 h);
246} 251}
247 252
248 253
@@ -254,19 +259,19 @@ do_disconnect(struct GNUNET_DATASTORE_Handle *h)
254 * @param qe entry to free. 259 * @param qe entry to free.
255 */ 260 */
256static void 261static void
257free_queue_entry(struct GNUNET_DATASTORE_QueueEntry *qe) 262free_queue_entry (struct GNUNET_DATASTORE_QueueEntry *qe)
258{ 263{
259 struct GNUNET_DATASTORE_Handle *h = qe->h; 264 struct GNUNET_DATASTORE_Handle *h = qe->h;
260 265
261 GNUNET_CONTAINER_DLL_remove(h->queue_head, 266 GNUNET_CONTAINER_DLL_remove (h->queue_head,
262 h->queue_tail, 267 h->queue_tail,
263 qe); 268 qe);
264 h->queue_size--; 269 h->queue_size--;
265 if (NULL != qe->env) 270 if (NULL != qe->env)
266 GNUNET_MQ_discard(qe->env); 271 GNUNET_MQ_discard (qe->env);
267 if (NULL != qe->delay_warn_task) 272 if (NULL != qe->delay_warn_task)
268 GNUNET_SCHEDULER_cancel(qe->delay_warn_task); 273 GNUNET_SCHEDULER_cancel (qe->delay_warn_task);
269 GNUNET_free(qe); 274 GNUNET_free (qe);
270} 275}
271 276
272 277
@@ -276,20 +281,20 @@ free_queue_entry(struct GNUNET_DATASTORE_QueueEntry *qe)
276 * @param qe `struct GNUNET_DATASTORE_QueueEntry` about which the error is 281 * @param qe `struct GNUNET_DATASTORE_QueueEntry` about which the error is
277 */ 282 */
278static void 283static void
279delay_warning(void *cls) 284delay_warning (void *cls)
280{ 285{
281 struct GNUNET_DATASTORE_QueueEntry *qe = cls; 286 struct GNUNET_DATASTORE_QueueEntry *qe = cls;
282 287
283 qe->delay_warn_task = NULL; 288 qe->delay_warn_task = NULL;
284 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 289 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
285 "Request %p of type %u at head of datastore queue for more than %s\n", 290 "Request %p of type %u at head of datastore queue for more than %s\n",
286 qe, 291 qe,
287 (unsigned int)qe->response_type, 292 (unsigned int) qe->response_type,
288 GNUNET_STRINGS_relative_time_to_string(DELAY_WARN_TIMEOUT, 293 GNUNET_STRINGS_relative_time_to_string (DELAY_WARN_TIMEOUT,
289 GNUNET_YES)); 294 GNUNET_YES));
290 qe->delay_warn_task = GNUNET_SCHEDULER_add_delayed(DELAY_WARN_TIMEOUT, 295 qe->delay_warn_task = GNUNET_SCHEDULER_add_delayed (DELAY_WARN_TIMEOUT,
291 &delay_warning, 296 &delay_warning,
292 qe); 297 qe);
293} 298}
294 299
295 300
@@ -300,59 +305,59 @@ delay_warning(void *cls)
300 * @param error error code 305 * @param error error code
301 */ 306 */
302static void 307static void
303mq_error_handler(void *cls, 308mq_error_handler (void *cls,
304 enum GNUNET_MQ_Error error) 309 enum GNUNET_MQ_Error error)
305{ 310{
306 struct GNUNET_DATASTORE_Handle *h = cls; 311 struct GNUNET_DATASTORE_Handle *h = cls;
307 struct GNUNET_DATASTORE_QueueEntry *qe; 312 struct GNUNET_DATASTORE_QueueEntry *qe;
308 313
309 LOG(GNUNET_ERROR_TYPE_DEBUG, 314 LOG (GNUNET_ERROR_TYPE_DEBUG,
310 "MQ error, reconnecting to DATASTORE\n"); 315 "MQ error, reconnecting to DATASTORE\n");
311 do_disconnect(h); 316 do_disconnect (h);
312 qe = h->queue_head; 317 qe = h->queue_head;
313 if (NULL == qe) 318 if (NULL == qe)
314 return; 319 return;
315 if (NULL != qe->delay_warn_task) 320 if (NULL != qe->delay_warn_task)
316 { 321 {
317 GNUNET_SCHEDULER_cancel(qe->delay_warn_task); 322 GNUNET_SCHEDULER_cancel (qe->delay_warn_task);
318 qe->delay_warn_task = NULL; 323 qe->delay_warn_task = NULL;
319 } 324 }
320 if (NULL == qe->env) 325 if (NULL == qe->env)
326 {
327 union QueueContext qc = qe->qc;
328 uint16_t rt = qe->response_type;
329
330 LOG (GNUNET_ERROR_TYPE_DEBUG,
331 "Failed to receive response from database.\n");
332 free_queue_entry (qe);
333 switch (rt)
321 { 334 {
322 union QueueContext qc = qe->qc; 335 case GNUNET_MESSAGE_TYPE_DATASTORE_STATUS:
323 uint16_t rt = qe->response_type; 336 if (NULL != qc.sc.cont)
324 337 qc.sc.cont (qc.sc.cont_cls,
325 LOG(GNUNET_ERROR_TYPE_DEBUG, 338 GNUNET_SYSERR,
326 "Failed to receive response from database.\n"); 339 GNUNET_TIME_UNIT_ZERO_ABS,
327 free_queue_entry(qe); 340 _ ("DATASTORE disconnected"));
328 switch (rt) 341 break;
329 { 342
330 case GNUNET_MESSAGE_TYPE_DATASTORE_STATUS: 343 case GNUNET_MESSAGE_TYPE_DATASTORE_DATA:
331 if (NULL != qc.sc.cont) 344 if (NULL != qc.rc.proc)
332 qc.sc.cont(qc.sc.cont_cls, 345 qc.rc.proc (qc.rc.proc_cls,
333 GNUNET_SYSERR, 346 NULL,
334 GNUNET_TIME_UNIT_ZERO_ABS, 347 0,
335 _("DATASTORE disconnected")); 348 NULL,
336 break; 349 0,
337 350 0,
338 case GNUNET_MESSAGE_TYPE_DATASTORE_DATA: 351 0,
339 if (NULL != qc.rc.proc) 352 0,
340 qc.rc.proc(qc.rc.proc_cls, 353 GNUNET_TIME_UNIT_ZERO_ABS,
341 NULL, 354 0);
342 0, 355 break;
343 NULL, 356
344 0, 357 default:
345 0, 358 GNUNET_break (0);
346 0,
347 0,
348 GNUNET_TIME_UNIT_ZERO_ABS,
349 0);
350 break;
351
352 default:
353 GNUNET_break(0);
354 }
355 } 359 }
360 }
356} 361}
357 362
358 363
@@ -363,22 +368,22 @@ mq_error_handler(void *cls,
363 * @return handle to use to access the service 368 * @return handle to use to access the service
364 */ 369 */
365struct GNUNET_DATASTORE_Handle * 370struct GNUNET_DATASTORE_Handle *
366GNUNET_DATASTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) 371GNUNET_DATASTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
367{ 372{
368 struct GNUNET_DATASTORE_Handle *h; 373 struct GNUNET_DATASTORE_Handle *h;
369 374
370 LOG(GNUNET_ERROR_TYPE_DEBUG, 375 LOG (GNUNET_ERROR_TYPE_DEBUG,
371 "Establishing DATASTORE connection!\n"); 376 "Establishing DATASTORE connection!\n");
372 h = GNUNET_new(struct GNUNET_DATASTORE_Handle); 377 h = GNUNET_new (struct GNUNET_DATASTORE_Handle);
373 h->cfg = cfg; 378 h->cfg = cfg;
374 try_reconnect(h); 379 try_reconnect (h);
375 if (NULL == h->mq) 380 if (NULL == h->mq)
376 { 381 {
377 GNUNET_free(h); 382 GNUNET_free (h);
378 return NULL; 383 return NULL;
379 } 384 }
380 h->stats = GNUNET_STATISTICS_create("datastore-api", 385 h->stats = GNUNET_STATISTICS_create ("datastore-api",
381 cfg); 386 cfg);
382 return h; 387 return h;
383} 388}
384 389
@@ -390,14 +395,14 @@ GNUNET_DATASTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
390 * @param cls the datastore handle 395 * @param cls the datastore handle
391 */ 396 */
392static void 397static void
393disconnect_after_drop(void *cls) 398disconnect_after_drop (void *cls)
394{ 399{
395 struct GNUNET_DATASTORE_Handle *h = cls; 400 struct GNUNET_DATASTORE_Handle *h = cls;
396 401
397 LOG(GNUNET_ERROR_TYPE_DEBUG, 402 LOG (GNUNET_ERROR_TYPE_DEBUG,
398 "Drop sent, disconnecting\n"); 403 "Drop sent, disconnecting\n");
399 GNUNET_DATASTORE_disconnect(h, 404 GNUNET_DATASTORE_disconnect (h,
400 GNUNET_NO); 405 GNUNET_NO);
401} 406}
402 407
403 408
@@ -408,15 +413,15 @@ disconnect_after_drop(void *cls)
408 * @param error error code 413 * @param error error code
409 */ 414 */
410static void 415static void
411disconnect_on_mq_error(void *cls, 416disconnect_on_mq_error (void *cls,
412 enum GNUNET_MQ_Error error) 417 enum GNUNET_MQ_Error error)
413{ 418{
414 struct GNUNET_DATASTORE_Handle *h = cls; 419 struct GNUNET_DATASTORE_Handle *h = cls;
415 420
416 LOG(GNUNET_ERROR_TYPE_ERROR, 421 LOG (GNUNET_ERROR_TYPE_ERROR,
417 "Failed to ask datastore to drop tables\n"); 422 "Failed to ask datastore to drop tables\n");
418 GNUNET_DATASTORE_disconnect(h, 423 GNUNET_DATASTORE_disconnect (h,
419 GNUNET_NO); 424 GNUNET_NO);
420} 425}
421 426
422 427
@@ -428,84 +433,84 @@ disconnect_on_mq_error(void *cls,
428 * @param drop set to #GNUNET_YES to delete all data in datastore (!) 433 * @param drop set to #GNUNET_YES to delete all data in datastore (!)
429 */ 434 */
430void 435void
431GNUNET_DATASTORE_disconnect(struct GNUNET_DATASTORE_Handle *h, 436GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
432 int drop) 437 int drop)
433{ 438{
434 struct GNUNET_DATASTORE_QueueEntry *qe; 439 struct GNUNET_DATASTORE_QueueEntry *qe;
435 440
436 LOG(GNUNET_ERROR_TYPE_DEBUG, 441 LOG (GNUNET_ERROR_TYPE_DEBUG,
437 "Datastore disconnect\n"); 442 "Datastore disconnect\n");
438 if (NULL != h->mq) 443 if (NULL != h->mq)
439 { 444 {
440 GNUNET_MQ_destroy(h->mq); 445 GNUNET_MQ_destroy (h->mq);
441 h->mq = NULL; 446 h->mq = NULL;
442 } 447 }
443 if (NULL != h->reconnect_task) 448 if (NULL != h->reconnect_task)
444 { 449 {
445 GNUNET_SCHEDULER_cancel(h->reconnect_task); 450 GNUNET_SCHEDULER_cancel (h->reconnect_task);
446 h->reconnect_task = NULL; 451 h->reconnect_task = NULL;
447 } 452 }
448 while (NULL != (qe = h->queue_head)) 453 while (NULL != (qe = h->queue_head))
454 {
455 switch (qe->response_type)
449 { 456 {
450 switch (qe->response_type) 457 case GNUNET_MESSAGE_TYPE_DATASTORE_STATUS:
451 { 458 if (NULL != qe->qc.sc.cont)
452 case GNUNET_MESSAGE_TYPE_DATASTORE_STATUS: 459 qe->qc.sc.cont (qe->qc.sc.cont_cls,
453 if (NULL != qe->qc.sc.cont) 460 GNUNET_SYSERR,
454 qe->qc.sc.cont(qe->qc.sc.cont_cls, 461 GNUNET_TIME_UNIT_ZERO_ABS,
455 GNUNET_SYSERR, 462 _ ("Disconnected from DATASTORE"));
456 GNUNET_TIME_UNIT_ZERO_ABS, 463 break;
457 _("Disconnected from DATASTORE")); 464
458 break; 465 case GNUNET_MESSAGE_TYPE_DATASTORE_DATA:
459 466 if (NULL != qe->qc.rc.proc)
460 case GNUNET_MESSAGE_TYPE_DATASTORE_DATA: 467 qe->qc.rc.proc (qe->qc.rc.proc_cls,
461 if (NULL != qe->qc.rc.proc) 468 NULL,
462 qe->qc.rc.proc(qe->qc.rc.proc_cls, 469 0,
463 NULL, 470 NULL,
464 0, 471 0,
465 NULL, 472 0,
466 0, 473 0,
467 0, 474 0,
468 0, 475 GNUNET_TIME_UNIT_ZERO_ABS,
469 0, 476 0);
470 GNUNET_TIME_UNIT_ZERO_ABS, 477 break;
471 0); 478
472 break; 479 default:
473 480 GNUNET_break (0);
474 default:
475 GNUNET_break(0);
476 }
477 free_queue_entry(qe);
478 } 481 }
482 free_queue_entry (qe);
483 }
479 if (GNUNET_YES == drop) 484 if (GNUNET_YES == drop)
485 {
486 LOG (GNUNET_ERROR_TYPE_DEBUG,
487 "Re-connecting to issue DROP!\n");
488 GNUNET_assert (NULL == h->mq);
489 h->mq = GNUNET_CLIENT_connect (h->cfg,
490 "datastore",
491 NULL,
492 &disconnect_on_mq_error,
493 h);
494 if (NULL != h->mq)
480 { 495 {
481 LOG(GNUNET_ERROR_TYPE_DEBUG, 496 struct GNUNET_MessageHeader *hdr;
482 "Re-connecting to issue DROP!\n"); 497 struct GNUNET_MQ_Envelope *env;
483 GNUNET_assert(NULL == h->mq); 498
484 h->mq = GNUNET_CLIENT_connect(h->cfg, 499 env = GNUNET_MQ_msg (hdr,
485 "datastore", 500 GNUNET_MESSAGE_TYPE_DATASTORE_DROP);
486 NULL, 501 GNUNET_MQ_notify_sent (env,
487 &disconnect_on_mq_error, 502 &disconnect_after_drop,
488 h); 503 h);
489 if (NULL != h->mq) 504 GNUNET_MQ_send (h->mq,
490 { 505 env);
491 struct GNUNET_MessageHeader *hdr; 506 return;
492 struct GNUNET_MQ_Envelope *env;
493
494 env = GNUNET_MQ_msg(hdr,
495 GNUNET_MESSAGE_TYPE_DATASTORE_DROP);
496 GNUNET_MQ_notify_sent(env,
497 &disconnect_after_drop,
498 h);
499 GNUNET_MQ_send(h->mq,
500 env);
501 return;
502 }
503 GNUNET_break(0);
504 } 507 }
505 GNUNET_STATISTICS_destroy(h->stats, 508 GNUNET_break (0);
506 GNUNET_NO); 509 }
510 GNUNET_STATISTICS_destroy (h->stats,
511 GNUNET_NO);
507 h->stats = NULL; 512 h->stats = NULL;
508 GNUNET_free(h); 513 GNUNET_free (h);
509} 514}
510 515
511 516
@@ -525,12 +530,12 @@ GNUNET_DATASTORE_disconnect(struct GNUNET_DATASTORE_Handle *h,
525 * @return NULL if the queue is full 530 * @return NULL if the queue is full
526 */ 531 */
527static struct GNUNET_DATASTORE_QueueEntry * 532static struct GNUNET_DATASTORE_QueueEntry *
528make_queue_entry(struct GNUNET_DATASTORE_Handle *h, 533make_queue_entry (struct GNUNET_DATASTORE_Handle *h,
529 struct GNUNET_MQ_Envelope *env, 534 struct GNUNET_MQ_Envelope *env,
530 unsigned int queue_priority, 535 unsigned int queue_priority,
531 unsigned int max_queue_size, 536 unsigned int max_queue_size,
532 uint16_t expected_type, 537 uint16_t expected_type,
533 const union QueueContext *qc) 538 const union QueueContext *qc)
534{ 539{
535 struct GNUNET_DATASTORE_QueueEntry *qe; 540 struct GNUNET_DATASTORE_QueueEntry *qe;
536 struct GNUNET_DATASTORE_QueueEntry *pos; 541 struct GNUNET_DATASTORE_QueueEntry *pos;
@@ -538,32 +543,32 @@ make_queue_entry(struct GNUNET_DATASTORE_Handle *h,
538 543
539 if ((NULL != h->queue_tail) && 544 if ((NULL != h->queue_tail) &&
540 (h->queue_tail->priority >= queue_priority)) 545 (h->queue_tail->priority >= queue_priority))
541 { 546 {
542 c = h->queue_size; 547 c = h->queue_size;
543 pos = NULL; 548 pos = NULL;
544 } 549 }
545 else 550 else
546 { 551 {
547 c = 0; 552 c = 0;
548 pos = h->queue_head; 553 pos = h->queue_head;
549 } 554 }
550 while ((NULL != pos) && 555 while ((NULL != pos) &&
551 (c < max_queue_size) && 556 (c < max_queue_size) &&
552 (pos->priority >= queue_priority)) 557 (pos->priority >= queue_priority))
553 { 558 {
554 c++; 559 c++;
555 pos = pos->next; 560 pos = pos->next;
556 } 561 }
557 if (c >= max_queue_size) 562 if (c >= max_queue_size)
558 { 563 {
559 GNUNET_STATISTICS_update(h->stats, 564 GNUNET_STATISTICS_update (h->stats,
560 gettext_noop("# queue overflows"), 565 gettext_noop ("# queue overflows"),
561 1, 566 1,
562 GNUNET_NO); 567 GNUNET_NO);
563 GNUNET_MQ_discard(env); 568 GNUNET_MQ_discard (env);
564 return NULL; 569 return NULL;
565 } 570 }
566 qe = GNUNET_new(struct GNUNET_DATASTORE_QueueEntry); 571 qe = GNUNET_new (struct GNUNET_DATASTORE_QueueEntry);
567 qe->h = h; 572 qe->h = h;
568 qe->env = env; 573 qe->env = env;
569 qe->response_type = expected_type; 574 qe->response_type = expected_type;
@@ -571,30 +576,30 @@ make_queue_entry(struct GNUNET_DATASTORE_Handle *h,
571 qe->priority = queue_priority; 576 qe->priority = queue_priority;
572 qe->max_queue = max_queue_size; 577 qe->max_queue = max_queue_size;
573 if (NULL == pos) 578 if (NULL == pos)
574 { 579 {
575 /* append at the tail */ 580 /* append at the tail */
576 pos = h->queue_tail; 581 pos = h->queue_tail;
577 } 582 }
578 else 583 else
579 { 584 {
580 pos = pos->prev; 585 pos = pos->prev;
581 /* do not insert at HEAD if HEAD query was already 586 /* do not insert at HEAD if HEAD query was already
582 * transmitted and we are still receiving replies! */ 587 * transmitted and we are still receiving replies! */
583 if ((NULL == pos) && 588 if ((NULL == pos) &&
584 (NULL == h->queue_head->env)) 589 (NULL == h->queue_head->env))
585 pos = h->queue_head; 590 pos = h->queue_head;
586 } 591 }
587 c++; 592 c++;
588#if INSANE_STATISTICS 593#if INSANE_STATISTICS
589 GNUNET_STATISTICS_update(h->stats, 594 GNUNET_STATISTICS_update (h->stats,
590 gettext_noop("# queue entries created"), 595 gettext_noop ("# queue entries created"),
591 1, 596 1,
592 GNUNET_NO); 597 GNUNET_NO);
593#endif 598#endif
594 GNUNET_CONTAINER_DLL_insert_after(h->queue_head, 599 GNUNET_CONTAINER_DLL_insert_after (h->queue_head,
595 h->queue_tail, 600 h->queue_tail,
596 pos, 601 pos,
597 qe); 602 qe);
598 h->queue_size++; 603 h->queue_size++;
599 return qe; 604 return qe;
600} 605}
@@ -607,37 +612,37 @@ make_queue_entry(struct GNUNET_DATASTORE_Handle *h,
607 * @param h handle to the datastore 612 * @param h handle to the datastore
608 */ 613 */
609static void 614static void
610process_queue(struct GNUNET_DATASTORE_Handle *h) 615process_queue (struct GNUNET_DATASTORE_Handle *h)
611{ 616{
612 struct GNUNET_DATASTORE_QueueEntry *qe; 617 struct GNUNET_DATASTORE_QueueEntry *qe;
613 618
614 if (NULL == (qe = h->queue_head)) 619 if (NULL == (qe = h->queue_head))
615 { 620 {
616 /* no entry in queue */ 621 /* no entry in queue */
617 LOG(GNUNET_ERROR_TYPE_DEBUG, 622 LOG (GNUNET_ERROR_TYPE_DEBUG,
618 "Queue empty\n"); 623 "Queue empty\n");
619 return; 624 return;
620 } 625 }
621 if (NULL == qe->env) 626 if (NULL == qe->env)
622 { 627 {
623 /* waiting for replies */ 628 /* waiting for replies */
624 LOG(GNUNET_ERROR_TYPE_DEBUG, 629 LOG (GNUNET_ERROR_TYPE_DEBUG,
625 "Head request already transmitted\n"); 630 "Head request already transmitted\n");
626 return; 631 return;
627 } 632 }
628 if (NULL == h->mq) 633 if (NULL == h->mq)
629 { 634 {
630 /* waiting for reconnect */ 635 /* waiting for reconnect */
631 LOG(GNUNET_ERROR_TYPE_DEBUG, 636 LOG (GNUNET_ERROR_TYPE_DEBUG,
632 "Not connected\n"); 637 "Not connected\n");
633 return; 638 return;
634 } 639 }
635 GNUNET_assert(NULL == qe->delay_warn_task); 640 GNUNET_assert (NULL == qe->delay_warn_task);
636 qe->delay_warn_task = GNUNET_SCHEDULER_add_delayed(DELAY_WARN_TIMEOUT, 641 qe->delay_warn_task = GNUNET_SCHEDULER_add_delayed (DELAY_WARN_TIMEOUT,
637 &delay_warning, 642 &delay_warning,
638 qe); 643 qe);
639 GNUNET_MQ_send(h->mq, 644 GNUNET_MQ_send (h->mq,
640 qe->env); 645 qe->env);
641 qe->env = NULL; 646 qe->env = NULL;
642} 647}
643 648
@@ -650,36 +655,36 @@ process_queue(struct GNUNET_DATASTORE_Handle *h)
650 * @return the queue entry 655 * @return the queue entry
651 */ 656 */
652static struct GNUNET_DATASTORE_QueueEntry * 657static struct GNUNET_DATASTORE_QueueEntry *
653get_queue_head(struct GNUNET_DATASTORE_Handle *h, 658get_queue_head (struct GNUNET_DATASTORE_Handle *h,
654 uint16_t response_type) 659 uint16_t response_type)
655{ 660{
656 struct GNUNET_DATASTORE_QueueEntry *qe; 661 struct GNUNET_DATASTORE_QueueEntry *qe;
657 662
658 if (h->skip_next_messages > 0) 663 if (h->skip_next_messages > 0)
659 { 664 {
660 h->skip_next_messages--; 665 h->skip_next_messages--;
661 process_queue(h); 666 process_queue (h);
662 return NULL; 667 return NULL;
663 } 668 }
664 qe = h->queue_head; 669 qe = h->queue_head;
665 if (NULL == qe) 670 if (NULL == qe)
666 { 671 {
667 GNUNET_break(0); 672 GNUNET_break (0);
668 do_disconnect(h); 673 do_disconnect (h);
669 return NULL; 674 return NULL;
670 } 675 }
671 if (NULL != qe->env) 676 if (NULL != qe->env)
672 { 677 {
673 GNUNET_break(0); 678 GNUNET_break (0);
674 do_disconnect(h); 679 do_disconnect (h);
675 return NULL; 680 return NULL;
676 } 681 }
677 if (response_type != qe->response_type) 682 if (response_type != qe->response_type)
678 { 683 {
679 GNUNET_break(0); 684 GNUNET_break (0);
680 do_disconnect(h); 685 do_disconnect (h);
681 return NULL; 686 return NULL;
682 } 687 }
683 return qe; 688 return qe;
684} 689}
685 690
@@ -692,27 +697,27 @@ get_queue_head(struct GNUNET_DATASTORE_Handle *h,
692 * @return #GNUNET_OK if the message is well-formed 697 * @return #GNUNET_OK if the message is well-formed
693 */ 698 */
694static int 699static int
695check_status(void *cls, 700check_status (void *cls,
696 const struct StatusMessage *sm) 701 const struct StatusMessage *sm)
697{ 702{
698 uint16_t msize = ntohs(sm->header.size) - sizeof(*sm); 703 uint16_t msize = ntohs (sm->header.size) - sizeof(*sm);
699 int32_t status = ntohl(sm->status); 704 int32_t status = ntohl (sm->status);
700 705
701 if (msize > 0) 706 if (msize > 0)
702 { 707 {
703 const char *emsg = (const char *)&sm[1]; 708 const char *emsg = (const char *) &sm[1];
704 709
705 if ('\0' != emsg[msize - 1]) 710 if ('\0' != emsg[msize - 1])
706 {
707 GNUNET_break(0);
708 return GNUNET_SYSERR;
709 }
710 }
711 else if (GNUNET_SYSERR == status)
712 { 711 {
713 GNUNET_break(0); 712 GNUNET_break (0);
714 return GNUNET_SYSERR; 713 return GNUNET_SYSERR;
715 } 714 }
715 }
716 else if (GNUNET_SYSERR == status)
717 {
718 GNUNET_break (0);
719 return GNUNET_SYSERR;
720 }
716 return GNUNET_OK; 721 return GNUNET_OK;
717} 722}
718 723
@@ -724,40 +729,40 @@ check_status(void *cls,
724 * @param sm status message received 729 * @param sm status message received
725 */ 730 */
726static void 731static void
727handle_status(void *cls, 732handle_status (void *cls,
728 const struct StatusMessage *sm) 733 const struct StatusMessage *sm)
729{ 734{
730 struct GNUNET_DATASTORE_Handle *h = cls; 735 struct GNUNET_DATASTORE_Handle *h = cls;
731 struct GNUNET_DATASTORE_QueueEntry *qe; 736 struct GNUNET_DATASTORE_QueueEntry *qe;
732 struct StatusContext rc; 737 struct StatusContext rc;
733 const char *emsg; 738 const char *emsg;
734 int32_t status = ntohl(sm->status); 739 int32_t status = ntohl (sm->status);
735 740
736 qe = get_queue_head(h, 741 qe = get_queue_head (h,
737 GNUNET_MESSAGE_TYPE_DATASTORE_STATUS); 742 GNUNET_MESSAGE_TYPE_DATASTORE_STATUS);
738 if (NULL == qe) 743 if (NULL == qe)
739 return; 744 return;
740 rc = qe->qc.sc; 745 rc = qe->qc.sc;
741 free_queue_entry(qe); 746 free_queue_entry (qe);
742 if (ntohs(sm->header.size) > sizeof(struct StatusMessage)) 747 if (ntohs (sm->header.size) > sizeof(struct StatusMessage))
743 emsg = (const char *)&sm[1]; 748 emsg = (const char *) &sm[1];
744 else 749 else
745 emsg = NULL; 750 emsg = NULL;
746 LOG(GNUNET_ERROR_TYPE_DEBUG, 751 LOG (GNUNET_ERROR_TYPE_DEBUG,
747 "Received status %d/%s\n", 752 "Received status %d/%s\n",
748 (int)status, 753 (int) status,
749 emsg); 754 emsg);
750 GNUNET_STATISTICS_update(h->stats, 755 GNUNET_STATISTICS_update (h->stats,
751 gettext_noop("# status messages received"), 756 gettext_noop ("# status messages received"),
752 1, 757 1,
753 GNUNET_NO); 758 GNUNET_NO);
754 h->retry_time = GNUNET_TIME_UNIT_ZERO; 759 h->retry_time = GNUNET_TIME_UNIT_ZERO;
755 process_queue(h); 760 process_queue (h);
756 if (NULL != rc.cont) 761 if (NULL != rc.cont)
757 rc.cont(rc.cont_cls, 762 rc.cont (rc.cont_cls,
758 status, 763 status,
759 GNUNET_TIME_absolute_ntoh(sm->min_expiration), 764 GNUNET_TIME_absolute_ntoh (sm->min_expiration),
760 emsg); 765 emsg);
761} 766}
762 767
763 768
@@ -768,16 +773,16 @@ handle_status(void *cls,
768 * @param dm message received 773 * @param dm message received
769 */ 774 */
770static int 775static int
771check_data(void *cls, 776check_data (void *cls,
772 const struct DataMessage *dm) 777 const struct DataMessage *dm)
773{ 778{
774 uint16_t msize = ntohs(dm->header.size) - sizeof(*dm); 779 uint16_t msize = ntohs (dm->header.size) - sizeof(*dm);
775 780
776 if (msize != ntohl(dm->size)) 781 if (msize != ntohl (dm->size))
777 { 782 {
778 GNUNET_break(0); 783 GNUNET_break (0);
779 return GNUNET_SYSERR; 784 return GNUNET_SYSERR;
780 } 785 }
781 return GNUNET_OK; 786 return GNUNET_OK;
782} 787}
783 788
@@ -789,44 +794,44 @@ check_data(void *cls,
789 * @param dm message received 794 * @param dm message received
790 */ 795 */
791static void 796static void
792handle_data(void *cls, 797handle_data (void *cls,
793 const struct DataMessage *dm) 798 const struct DataMessage *dm)
794{ 799{
795 struct GNUNET_DATASTORE_Handle *h = cls; 800 struct GNUNET_DATASTORE_Handle *h = cls;
796 struct GNUNET_DATASTORE_QueueEntry *qe; 801 struct GNUNET_DATASTORE_QueueEntry *qe;
797 struct ResultContext rc; 802 struct ResultContext rc;
798 803
799 qe = get_queue_head(h, 804 qe = get_queue_head (h,
800 GNUNET_MESSAGE_TYPE_DATASTORE_DATA); 805 GNUNET_MESSAGE_TYPE_DATASTORE_DATA);
801 if (NULL == qe) 806 if (NULL == qe)
802 return; 807 return;
803#if INSANE_STATISTICS 808#if INSANE_STATISTICS
804 GNUNET_STATISTICS_update(h->stats, 809 GNUNET_STATISTICS_update (h->stats,
805 gettext_noop("# Results received"), 810 gettext_noop ("# Results received"),
806 1, 811 1,
807 GNUNET_NO); 812 GNUNET_NO);
808#endif 813#endif
809 LOG(GNUNET_ERROR_TYPE_DEBUG, 814 LOG (GNUNET_ERROR_TYPE_DEBUG,
810 "Received result %llu with type %u and size %u with key %s\n", 815 "Received result %llu with type %u and size %u with key %s\n",
811 (unsigned long long)GNUNET_ntohll(dm->uid), 816 (unsigned long long) GNUNET_ntohll (dm->uid),
812 ntohl(dm->type), 817 ntohl (dm->type),
813 ntohl(dm->size), 818 ntohl (dm->size),
814 GNUNET_h2s(&dm->key)); 819 GNUNET_h2s (&dm->key));
815 rc = qe->qc.rc; 820 rc = qe->qc.rc;
816 free_queue_entry(qe); 821 free_queue_entry (qe);
817 h->retry_time = GNUNET_TIME_UNIT_ZERO; 822 h->retry_time = GNUNET_TIME_UNIT_ZERO;
818 process_queue(h); 823 process_queue (h);
819 if (NULL != rc.proc) 824 if (NULL != rc.proc)
820 rc.proc(rc.proc_cls, 825 rc.proc (rc.proc_cls,
821 &dm->key, 826 &dm->key,
822 ntohl(dm->size), 827 ntohl (dm->size),
823 &dm[1], 828 &dm[1],
824 ntohl(dm->type), 829 ntohl (dm->type),
825 ntohl(dm->priority), 830 ntohl (dm->priority),
826 ntohl(dm->anonymity), 831 ntohl (dm->anonymity),
827 ntohl(dm->replication), 832 ntohl (dm->replication),
828 GNUNET_TIME_absolute_ntoh(dm->expiration), 833 GNUNET_TIME_absolute_ntoh (dm->expiration),
829 GNUNET_ntohll(dm->uid)); 834 GNUNET_ntohll (dm->uid));
830} 835}
831 836
832 837
@@ -838,37 +843,37 @@ handle_data(void *cls,
838 * @param msg message received 843 * @param msg message received
839 */ 844 */
840static void 845static void
841handle_data_end(void *cls, 846handle_data_end (void *cls,
842 const struct GNUNET_MessageHeader *msg) 847 const struct GNUNET_MessageHeader *msg)
843{ 848{
844 struct GNUNET_DATASTORE_Handle *h = cls; 849 struct GNUNET_DATASTORE_Handle *h = cls;
845 struct GNUNET_DATASTORE_QueueEntry *qe; 850 struct GNUNET_DATASTORE_QueueEntry *qe;
846 struct ResultContext rc; 851 struct ResultContext rc;
847 852
848 qe = get_queue_head(h, 853 qe = get_queue_head (h,
849 GNUNET_MESSAGE_TYPE_DATASTORE_DATA); 854 GNUNET_MESSAGE_TYPE_DATASTORE_DATA);
850 if (NULL == qe) 855 if (NULL == qe)
851 return; 856 return;
852 rc = qe->qc.rc; 857 rc = qe->qc.rc;
853 free_queue_entry(qe); 858 free_queue_entry (qe);
854 LOG(GNUNET_ERROR_TYPE_DEBUG, 859 LOG (GNUNET_ERROR_TYPE_DEBUG,
855 "Received end of result set, new queue size is %u\n", 860 "Received end of result set, new queue size is %u\n",
856 h->queue_size); 861 h->queue_size);
857 h->retry_time = GNUNET_TIME_UNIT_ZERO; 862 h->retry_time = GNUNET_TIME_UNIT_ZERO;
858 h->result_count = 0; 863 h->result_count = 0;
859 process_queue(h); 864 process_queue (h);
860 /* signal end of iteration */ 865 /* signal end of iteration */
861 if (NULL != rc.proc) 866 if (NULL != rc.proc)
862 rc.proc(rc.proc_cls, 867 rc.proc (rc.proc_cls,
863 NULL, 868 NULL,
864 0, 869 0,
865 NULL, 870 NULL,
866 0, 871 0,
867 0, 872 0,
868 0, 873 0,
869 0, 874 0,
870 GNUNET_TIME_UNIT_ZERO_ABS, 875 GNUNET_TIME_UNIT_ZERO_ABS,
871 0); 876 0);
872} 877}
873 878
874 879
@@ -878,42 +883,43 @@ handle_data_end(void *cls,
878 * @param cls the `struct GNUNET_DATASTORE_Handle` 883 * @param cls the `struct GNUNET_DATASTORE_Handle`
879 */ 884 */
880static void 885static void
881try_reconnect(void *cls) 886try_reconnect (void *cls)
882{ 887{
883 struct GNUNET_DATASTORE_Handle *h = cls; 888 struct GNUNET_DATASTORE_Handle *h = cls;
884 struct GNUNET_MQ_MessageHandler handlers[] = { 889 struct GNUNET_MQ_MessageHandler handlers[] = {
885 GNUNET_MQ_hd_var_size(status, 890 GNUNET_MQ_hd_var_size (status,
886 GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, 891 GNUNET_MESSAGE_TYPE_DATASTORE_STATUS,
887 struct StatusMessage, 892 struct StatusMessage,
888 h), 893 h),
889 GNUNET_MQ_hd_var_size(data, 894 GNUNET_MQ_hd_var_size (data,
890 GNUNET_MESSAGE_TYPE_DATASTORE_DATA, 895 GNUNET_MESSAGE_TYPE_DATASTORE_DATA,
891 struct DataMessage, 896 struct DataMessage,
892 h), 897 h),
893 GNUNET_MQ_hd_fixed_size(data_end, 898 GNUNET_MQ_hd_fixed_size (data_end,
894 GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END, 899 GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END,
895 struct GNUNET_MessageHeader, 900 struct GNUNET_MessageHeader,
896 h), 901 h),
897 GNUNET_MQ_handler_end() 902 GNUNET_MQ_handler_end ()
898 }; 903 };
899 904
900 h->retry_time = GNUNET_TIME_STD_BACKOFF(h->retry_time); 905 h->retry_time = GNUNET_TIME_STD_BACKOFF (h->retry_time);
901 h->reconnect_task = NULL; 906 h->reconnect_task = NULL;
902 GNUNET_assert(NULL == h->mq); 907 GNUNET_assert (NULL == h->mq);
903 h->mq = GNUNET_CLIENT_connect(h->cfg, 908 h->mq = GNUNET_CLIENT_connect (h->cfg,
904 "datastore", 909 "datastore",
905 handlers, 910 handlers,
906 &mq_error_handler, 911 &mq_error_handler,
907 h); 912 h);
908 if (NULL == h->mq) 913 if (NULL == h->mq)
909 return; 914 return;
910 GNUNET_STATISTICS_update(h->stats, 915 GNUNET_STATISTICS_update (h->stats,
911 gettext_noop("# datastore connections (re)created"), 916 gettext_noop (
912 1, 917 "# datastore connections (re)created"),
913 GNUNET_NO); 918 1,
914 LOG(GNUNET_ERROR_TYPE_DEBUG, 919 GNUNET_NO);
915 "Reconnected to DATASTORE\n"); 920 LOG (GNUNET_ERROR_TYPE_DEBUG,
916 process_queue(h); 921 "Reconnected to DATASTORE\n");
922 process_queue (h);
917} 923}
918 924
919 925
@@ -926,10 +932,10 @@ try_reconnect(void *cls)
926 * @param emsg error message 932 * @param emsg error message
927 */ 933 */
928static void 934static void
929drop_status_cont(void *cls, 935drop_status_cont (void *cls,
930 int32_t result, 936 int32_t result,
931 struct GNUNET_TIME_Absolute min_expiration, 937 struct GNUNET_TIME_Absolute min_expiration,
932 const char *emsg) 938 const char *emsg)
933{ 939{
934 /* do nothing */ 940 /* do nothing */
935} 941}
@@ -961,20 +967,20 @@ drop_status_cont(void *cls,
961 * (or rather, will already have been invoked) 967 * (or rather, will already have been invoked)
962 */ 968 */
963struct GNUNET_DATASTORE_QueueEntry * 969struct GNUNET_DATASTORE_QueueEntry *
964GNUNET_DATASTORE_put(struct GNUNET_DATASTORE_Handle *h, 970GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
965 uint32_t rid, 971 uint32_t rid,
966 const struct GNUNET_HashCode *key, 972 const struct GNUNET_HashCode *key,
967 size_t size, 973 size_t size,
968 const void *data, 974 const void *data,
969 enum GNUNET_BLOCK_Type type, 975 enum GNUNET_BLOCK_Type type,
970 uint32_t priority, 976 uint32_t priority,
971 uint32_t anonymity, 977 uint32_t anonymity,
972 uint32_t replication, 978 uint32_t replication,
973 struct GNUNET_TIME_Absolute expiration, 979 struct GNUNET_TIME_Absolute expiration,
974 unsigned int queue_priority, 980 unsigned int queue_priority,
975 unsigned int max_queue_size, 981 unsigned int max_queue_size,
976 GNUNET_DATASTORE_ContinuationWithStatus cont, 982 GNUNET_DATASTORE_ContinuationWithStatus cont,
977 void *cont_cls) 983 void *cont_cls)
978{ 984{
979 struct GNUNET_DATASTORE_QueueEntry *qe; 985 struct GNUNET_DATASTORE_QueueEntry *qe;
980 struct GNUNET_MQ_Envelope *env; 986 struct GNUNET_MQ_Envelope *env;
@@ -982,50 +988,51 @@ GNUNET_DATASTORE_put(struct GNUNET_DATASTORE_Handle *h,
982 union QueueContext qc; 988 union QueueContext qc;
983 989
984 if (size + sizeof(*dm) >= GNUNET_MAX_MESSAGE_SIZE) 990 if (size + sizeof(*dm) >= GNUNET_MAX_MESSAGE_SIZE)
985 { 991 {
986 GNUNET_break(0); 992 GNUNET_break (0);
987 return NULL; 993 return NULL;
988 } 994 }
989 995
990 LOG(GNUNET_ERROR_TYPE_DEBUG, 996 LOG (GNUNET_ERROR_TYPE_DEBUG,
991 "Asked to put %u bytes of data under key `%s' for %s\n", 997 "Asked to put %u bytes of data under key `%s' for %s\n",
992 size, 998 size,
993 GNUNET_h2s(key), 999 GNUNET_h2s (key),
994 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_remaining(expiration), 1000 GNUNET_STRINGS_relative_time_to_string (
995 GNUNET_YES)); 1001 GNUNET_TIME_absolute_get_remaining (expiration),
996 env = GNUNET_MQ_msg_extra(dm, 1002 GNUNET_YES));
997 size, 1003 env = GNUNET_MQ_msg_extra (dm,
998 GNUNET_MESSAGE_TYPE_DATASTORE_PUT); 1004 size,
999 dm->rid = htonl(rid); 1005 GNUNET_MESSAGE_TYPE_DATASTORE_PUT);
1000 dm->size = htonl((uint32_t)size); 1006 dm->rid = htonl (rid);
1001 dm->type = htonl(type); 1007 dm->size = htonl ((uint32_t) size);
1002 dm->priority = htonl(priority); 1008 dm->type = htonl (type);
1003 dm->anonymity = htonl(anonymity); 1009 dm->priority = htonl (priority);
1004 dm->replication = htonl(replication); 1010 dm->anonymity = htonl (anonymity);
1005 dm->expiration = GNUNET_TIME_absolute_hton(expiration); 1011 dm->replication = htonl (replication);
1012 dm->expiration = GNUNET_TIME_absolute_hton (expiration);
1006 dm->key = *key; 1013 dm->key = *key;
1007 GNUNET_memcpy(&dm[1], 1014 GNUNET_memcpy (&dm[1],
1008 data, 1015 data,
1009 size); 1016 size);
1010 qc.sc.cont = cont; 1017 qc.sc.cont = cont;
1011 qc.sc.cont_cls = cont_cls; 1018 qc.sc.cont_cls = cont_cls;
1012 qe = make_queue_entry(h, 1019 qe = make_queue_entry (h,
1013 env, 1020 env,
1014 queue_priority, 1021 queue_priority,
1015 max_queue_size, 1022 max_queue_size,
1016 GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, 1023 GNUNET_MESSAGE_TYPE_DATASTORE_STATUS,
1017 &qc); 1024 &qc);
1018 if (NULL == qe) 1025 if (NULL == qe)
1019 { 1026 {
1020 LOG(GNUNET_ERROR_TYPE_DEBUG, 1027 LOG (GNUNET_ERROR_TYPE_DEBUG,
1021 "Could not create queue entry for PUT\n"); 1028 "Could not create queue entry for PUT\n");
1022 return NULL; 1029 return NULL;
1023 } 1030 }
1024 GNUNET_STATISTICS_update(h->stats, 1031 GNUNET_STATISTICS_update (h->stats,
1025 gettext_noop("# PUT requests executed"), 1032 gettext_noop ("# PUT requests executed"),
1026 1, 1033 1,
1027 GNUNET_NO); 1034 GNUNET_NO);
1028 process_queue(h); 1035 process_queue (h);
1029 return qe; 1036 return qe;
1030} 1037}
1031 1038
@@ -1046,11 +1053,11 @@ GNUNET_DATASTORE_put(struct GNUNET_DATASTORE_Handle *h,
1046 * (or rather, will already have been invoked) 1053 * (or rather, will already have been invoked)
1047 */ 1054 */
1048struct GNUNET_DATASTORE_QueueEntry * 1055struct GNUNET_DATASTORE_QueueEntry *
1049GNUNET_DATASTORE_reserve(struct GNUNET_DATASTORE_Handle *h, 1056GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
1050 uint64_t amount, 1057 uint64_t amount,
1051 uint32_t entries, 1058 uint32_t entries,
1052 GNUNET_DATASTORE_ContinuationWithStatus cont, 1059 GNUNET_DATASTORE_ContinuationWithStatus cont,
1053 void *cont_cls) 1060 void *cont_cls)
1054{ 1061{
1055 struct GNUNET_DATASTORE_QueueEntry *qe; 1062 struct GNUNET_DATASTORE_QueueEntry *qe;
1056 struct GNUNET_MQ_Envelope *env; 1063 struct GNUNET_MQ_Envelope *env;
@@ -1059,34 +1066,34 @@ GNUNET_DATASTORE_reserve(struct GNUNET_DATASTORE_Handle *h,
1059 1066
1060 if (NULL == cont) 1067 if (NULL == cont)
1061 cont = &drop_status_cont; 1068 cont = &drop_status_cont;
1062 LOG(GNUNET_ERROR_TYPE_DEBUG, 1069 LOG (GNUNET_ERROR_TYPE_DEBUG,
1063 "Asked to reserve %llu bytes of data and %u entries\n", 1070 "Asked to reserve %llu bytes of data and %u entries\n",
1064 (unsigned long long)amount, 1071 (unsigned long long) amount,
1065 (unsigned int)entries); 1072 (unsigned int) entries);
1066 env = GNUNET_MQ_msg(rm, 1073 env = GNUNET_MQ_msg (rm,
1067 GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE); 1074 GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE);
1068 rm->entries = htonl(entries); 1075 rm->entries = htonl (entries);
1069 rm->amount = GNUNET_htonll(amount); 1076 rm->amount = GNUNET_htonll (amount);
1070 1077
1071 qc.sc.cont = cont; 1078 qc.sc.cont = cont;
1072 qc.sc.cont_cls = cont_cls; 1079 qc.sc.cont_cls = cont_cls;
1073 qe = make_queue_entry(h, 1080 qe = make_queue_entry (h,
1074 env, 1081 env,
1075 UINT_MAX, 1082 UINT_MAX,
1076 UINT_MAX, 1083 UINT_MAX,
1077 GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, 1084 GNUNET_MESSAGE_TYPE_DATASTORE_STATUS,
1078 &qc); 1085 &qc);
1079 if (NULL == qe) 1086 if (NULL == qe)
1080 { 1087 {
1081 LOG(GNUNET_ERROR_TYPE_DEBUG, 1088 LOG (GNUNET_ERROR_TYPE_DEBUG,
1082 "Could not create queue entry to reserve\n"); 1089 "Could not create queue entry to reserve\n");
1083 return NULL; 1090 return NULL;
1084 } 1091 }
1085 GNUNET_STATISTICS_update(h->stats, 1092 GNUNET_STATISTICS_update (h->stats,
1086 gettext_noop("# RESERVE requests executed"), 1093 gettext_noop ("# RESERVE requests executed"),
1087 1, 1094 1,
1088 GNUNET_NO); 1095 GNUNET_NO);
1089 process_queue(h); 1096 process_queue (h);
1090 return qe; 1097 return qe;
1091} 1098}
1092 1099
@@ -1112,12 +1119,12 @@ GNUNET_DATASTORE_reserve(struct GNUNET_DATASTORE_Handle *h,
1112 * (or rather, will already have been invoked) 1119 * (or rather, will already have been invoked)
1113 */ 1120 */
1114struct GNUNET_DATASTORE_QueueEntry * 1121struct GNUNET_DATASTORE_QueueEntry *
1115GNUNET_DATASTORE_release_reserve(struct GNUNET_DATASTORE_Handle *h, 1122GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
1116 uint32_t rid, 1123 uint32_t rid,
1117 unsigned int queue_priority, 1124 unsigned int queue_priority,
1118 unsigned int max_queue_size, 1125 unsigned int max_queue_size,
1119 GNUNET_DATASTORE_ContinuationWithStatus cont, 1126 GNUNET_DATASTORE_ContinuationWithStatus cont,
1120 void *cont_cls) 1127 void *cont_cls)
1121{ 1128{
1122 struct GNUNET_DATASTORE_QueueEntry *qe; 1129 struct GNUNET_DATASTORE_QueueEntry *qe;
1123 struct GNUNET_MQ_Envelope *env; 1130 struct GNUNET_MQ_Envelope *env;
@@ -1126,31 +1133,31 @@ GNUNET_DATASTORE_release_reserve(struct GNUNET_DATASTORE_Handle *h,
1126 1133
1127 if (NULL == cont) 1134 if (NULL == cont)
1128 cont = &drop_status_cont; 1135 cont = &drop_status_cont;
1129 LOG(GNUNET_ERROR_TYPE_DEBUG, 1136 LOG (GNUNET_ERROR_TYPE_DEBUG,
1130 "Asked to release reserve %d\n", 1137 "Asked to release reserve %d\n",
1131 rid); 1138 rid);
1132 env = GNUNET_MQ_msg(rrm, 1139 env = GNUNET_MQ_msg (rrm,
1133 GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE); 1140 GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE);
1134 rrm->rid = htonl(rid); 1141 rrm->rid = htonl (rid);
1135 qc.sc.cont = cont; 1142 qc.sc.cont = cont;
1136 qc.sc.cont_cls = cont_cls; 1143 qc.sc.cont_cls = cont_cls;
1137 qe = make_queue_entry(h, 1144 qe = make_queue_entry (h,
1138 env, 1145 env,
1139 queue_priority, 1146 queue_priority,
1140 max_queue_size, 1147 max_queue_size,
1141 GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, 1148 GNUNET_MESSAGE_TYPE_DATASTORE_STATUS,
1142 &qc); 1149 &qc);
1143 if (NULL == qe) 1150 if (NULL == qe)
1144 { 1151 {
1145 LOG(GNUNET_ERROR_TYPE_DEBUG, 1152 LOG (GNUNET_ERROR_TYPE_DEBUG,
1146 "Could not create queue entry to release reserve\n"); 1153 "Could not create queue entry to release reserve\n");
1147 return NULL; 1154 return NULL;
1148 } 1155 }
1149 GNUNET_STATISTICS_update(h->stats, 1156 GNUNET_STATISTICS_update (h->stats,
1150 gettext_noop 1157 gettext_noop
1151 ("# RELEASE RESERVE requests executed"), 1, 1158 ("# RELEASE RESERVE requests executed"), 1,
1152 GNUNET_NO); 1159 GNUNET_NO);
1153 process_queue(h); 1160 process_queue (h);
1154 return qe; 1161 return qe;
1155} 1162}
1156 1163
@@ -1176,14 +1183,14 @@ GNUNET_DATASTORE_release_reserve(struct GNUNET_DATASTORE_Handle *h,
1176 * (or rather, will already have been invoked) 1183 * (or rather, will already have been invoked)
1177 */ 1184 */
1178struct GNUNET_DATASTORE_QueueEntry * 1185struct GNUNET_DATASTORE_QueueEntry *
1179GNUNET_DATASTORE_remove(struct GNUNET_DATASTORE_Handle *h, 1186GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
1180 const struct GNUNET_HashCode *key, 1187 const struct GNUNET_HashCode *key,
1181 size_t size, 1188 size_t size,
1182 const void *data, 1189 const void *data,
1183 unsigned int queue_priority, 1190 unsigned int queue_priority,
1184 unsigned int max_queue_size, 1191 unsigned int max_queue_size,
1185 GNUNET_DATASTORE_ContinuationWithStatus cont, 1192 GNUNET_DATASTORE_ContinuationWithStatus cont,
1186 void *cont_cls) 1193 void *cont_cls)
1187{ 1194{
1188 struct GNUNET_DATASTORE_QueueEntry *qe; 1195 struct GNUNET_DATASTORE_QueueEntry *qe;
1189 struct DataMessage *dm; 1196 struct DataMessage *dm;
@@ -1191,45 +1198,45 @@ GNUNET_DATASTORE_remove(struct GNUNET_DATASTORE_Handle *h,
1191 union QueueContext qc; 1198 union QueueContext qc;
1192 1199
1193 if (sizeof(*dm) + size >= GNUNET_MAX_MESSAGE_SIZE) 1200 if (sizeof(*dm) + size >= GNUNET_MAX_MESSAGE_SIZE)
1194 { 1201 {
1195 GNUNET_break(0); 1202 GNUNET_break (0);
1196 return NULL; 1203 return NULL;
1197 } 1204 }
1198 if (NULL == cont) 1205 if (NULL == cont)
1199 cont = &drop_status_cont; 1206 cont = &drop_status_cont;
1200 LOG(GNUNET_ERROR_TYPE_DEBUG, 1207 LOG (GNUNET_ERROR_TYPE_DEBUG,
1201 "Asked to remove %u bytes under key `%s'\n", 1208 "Asked to remove %u bytes under key `%s'\n",
1202 size, 1209 size,
1203 GNUNET_h2s(key)); 1210 GNUNET_h2s (key));
1204 env = GNUNET_MQ_msg_extra(dm, 1211 env = GNUNET_MQ_msg_extra (dm,
1205 size, 1212 size,
1206 GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE); 1213 GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE);
1207 dm->size = htonl(size); 1214 dm->size = htonl (size);
1208 dm->key = *key; 1215 dm->key = *key;
1209 GNUNET_memcpy(&dm[1], 1216 GNUNET_memcpy (&dm[1],
1210 data, 1217 data,
1211 size); 1218 size);
1212 1219
1213 qc.sc.cont = cont; 1220 qc.sc.cont = cont;
1214 qc.sc.cont_cls = cont_cls; 1221 qc.sc.cont_cls = cont_cls;
1215 1222
1216 qe = make_queue_entry(h, 1223 qe = make_queue_entry (h,
1217 env, 1224 env,
1218 queue_priority, 1225 queue_priority,
1219 max_queue_size, 1226 max_queue_size,
1220 GNUNET_MESSAGE_TYPE_DATASTORE_STATUS, 1227 GNUNET_MESSAGE_TYPE_DATASTORE_STATUS,
1221 &qc); 1228 &qc);
1222 if (NULL == qe) 1229 if (NULL == qe)
1223 { 1230 {
1224 LOG(GNUNET_ERROR_TYPE_DEBUG, 1231 LOG (GNUNET_ERROR_TYPE_DEBUG,
1225 "Could not create queue entry for REMOVE\n"); 1232 "Could not create queue entry for REMOVE\n");
1226 return NULL; 1233 return NULL;
1227 } 1234 }
1228 GNUNET_STATISTICS_update(h->stats, 1235 GNUNET_STATISTICS_update (h->stats,
1229 gettext_noop("# REMOVE requests executed"), 1236 gettext_noop ("# REMOVE requests executed"),
1230 1, 1237 1,
1231 GNUNET_NO); 1238 GNUNET_NO);
1232 process_queue(h); 1239 process_queue (h);
1233 return qe; 1240 return qe;
1234} 1241}
1235 1242
@@ -1254,41 +1261,41 @@ GNUNET_DATASTORE_remove(struct GNUNET_DATASTORE_Handle *h,
1254 * cancel 1261 * cancel
1255 */ 1262 */
1256struct GNUNET_DATASTORE_QueueEntry * 1263struct GNUNET_DATASTORE_QueueEntry *
1257GNUNET_DATASTORE_get_for_replication(struct GNUNET_DATASTORE_Handle *h, 1264GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h,
1258 unsigned int queue_priority, 1265 unsigned int queue_priority,
1259 unsigned int max_queue_size, 1266 unsigned int max_queue_size,
1260 GNUNET_DATASTORE_DatumProcessor proc, 1267 GNUNET_DATASTORE_DatumProcessor proc,
1261 void *proc_cls) 1268 void *proc_cls)
1262{ 1269{
1263 struct GNUNET_DATASTORE_QueueEntry *qe; 1270 struct GNUNET_DATASTORE_QueueEntry *qe;
1264 struct GNUNET_MQ_Envelope *env; 1271 struct GNUNET_MQ_Envelope *env;
1265 struct GNUNET_MessageHeader *m; 1272 struct GNUNET_MessageHeader *m;
1266 union QueueContext qc; 1273 union QueueContext qc;
1267 1274
1268 GNUNET_assert(NULL != proc); 1275 GNUNET_assert (NULL != proc);
1269 LOG(GNUNET_ERROR_TYPE_DEBUG, 1276 LOG (GNUNET_ERROR_TYPE_DEBUG,
1270 "Asked to get replication entry\n"); 1277 "Asked to get replication entry\n");
1271 env = GNUNET_MQ_msg(m, 1278 env = GNUNET_MQ_msg (m,
1272 GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION); 1279 GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION);
1273 qc.rc.proc = proc; 1280 qc.rc.proc = proc;
1274 qc.rc.proc_cls = proc_cls; 1281 qc.rc.proc_cls = proc_cls;
1275 qe = make_queue_entry(h, 1282 qe = make_queue_entry (h,
1276 env, 1283 env,
1277 queue_priority, 1284 queue_priority,
1278 max_queue_size, 1285 max_queue_size,
1279 GNUNET_MESSAGE_TYPE_DATASTORE_DATA, 1286 GNUNET_MESSAGE_TYPE_DATASTORE_DATA,
1280 &qc); 1287 &qc);
1281 if (NULL == qe) 1288 if (NULL == qe)
1282 { 1289 {
1283 LOG(GNUNET_ERROR_TYPE_DEBUG, 1290 LOG (GNUNET_ERROR_TYPE_DEBUG,
1284 "Could not create queue entry for GET REPLICATION\n"); 1291 "Could not create queue entry for GET REPLICATION\n");
1285 return NULL; 1292 return NULL;
1286 } 1293 }
1287 GNUNET_STATISTICS_update(h->stats, 1294 GNUNET_STATISTICS_update (h->stats,
1288 gettext_noop 1295 gettext_noop
1289 ("# GET REPLICATION requests executed"), 1, 1296 ("# GET REPLICATION requests executed"), 1,
1290 GNUNET_NO); 1297 GNUNET_NO);
1291 process_queue(h); 1298 process_queue (h);
1292 return qe; 1299 return qe;
1293} 1300}
1294 1301
@@ -1310,47 +1317,47 @@ GNUNET_DATASTORE_get_for_replication(struct GNUNET_DATASTORE_Handle *h,
1310 * cancel 1317 * cancel
1311 */ 1318 */
1312struct GNUNET_DATASTORE_QueueEntry * 1319struct GNUNET_DATASTORE_QueueEntry *
1313GNUNET_DATASTORE_get_zero_anonymity(struct GNUNET_DATASTORE_Handle *h, 1320GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
1314 uint64_t next_uid, 1321 uint64_t next_uid,
1315 unsigned int queue_priority, 1322 unsigned int queue_priority,
1316 unsigned int max_queue_size, 1323 unsigned int max_queue_size,
1317 enum GNUNET_BLOCK_Type type, 1324 enum GNUNET_BLOCK_Type type,
1318 GNUNET_DATASTORE_DatumProcessor proc, 1325 GNUNET_DATASTORE_DatumProcessor proc,
1319 void *proc_cls) 1326 void *proc_cls)
1320{ 1327{
1321 struct GNUNET_DATASTORE_QueueEntry *qe; 1328 struct GNUNET_DATASTORE_QueueEntry *qe;
1322 struct GNUNET_MQ_Envelope *env; 1329 struct GNUNET_MQ_Envelope *env;
1323 struct GetZeroAnonymityMessage *m; 1330 struct GetZeroAnonymityMessage *m;
1324 union QueueContext qc; 1331 union QueueContext qc;
1325 1332
1326 GNUNET_assert(NULL != proc); 1333 GNUNET_assert (NULL != proc);
1327 GNUNET_assert(type != GNUNET_BLOCK_TYPE_ANY); 1334 GNUNET_assert (type != GNUNET_BLOCK_TYPE_ANY);
1328 LOG(GNUNET_ERROR_TYPE_DEBUG, 1335 LOG (GNUNET_ERROR_TYPE_DEBUG,
1329 "Asked to get a zero-anonymity entry of type %d\n", 1336 "Asked to get a zero-anonymity entry of type %d\n",
1330 type); 1337 type);
1331 env = GNUNET_MQ_msg(m, 1338 env = GNUNET_MQ_msg (m,
1332 GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY); 1339 GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY);
1333 m->type = htonl((uint32_t)type); 1340 m->type = htonl ((uint32_t) type);
1334 m->next_uid = GNUNET_htonll(next_uid); 1341 m->next_uid = GNUNET_htonll (next_uid);
1335 qc.rc.proc = proc; 1342 qc.rc.proc = proc;
1336 qc.rc.proc_cls = proc_cls; 1343 qc.rc.proc_cls = proc_cls;
1337 qe = make_queue_entry(h, 1344 qe = make_queue_entry (h,
1338 env, 1345 env,
1339 queue_priority, 1346 queue_priority,
1340 max_queue_size, 1347 max_queue_size,
1341 GNUNET_MESSAGE_TYPE_DATASTORE_DATA, 1348 GNUNET_MESSAGE_TYPE_DATASTORE_DATA,
1342 &qc); 1349 &qc);
1343 if (NULL == qe) 1350 if (NULL == qe)
1344 { 1351 {
1345 LOG(GNUNET_ERROR_TYPE_DEBUG, 1352 LOG (GNUNET_ERROR_TYPE_DEBUG,
1346 "Could not create queue entry for zero-anonymity procation\n"); 1353 "Could not create queue entry for zero-anonymity procation\n");
1347 return NULL; 1354 return NULL;
1348 } 1355 }
1349 GNUNET_STATISTICS_update(h->stats, 1356 GNUNET_STATISTICS_update (h->stats,
1350 gettext_noop 1357 gettext_noop
1351 ("# GET ZERO ANONYMITY requests executed"), 1, 1358 ("# GET ZERO ANONYMITY requests executed"), 1,
1352 GNUNET_NO); 1359 GNUNET_NO);
1353 process_queue(h); 1360 process_queue (h);
1354 return qe; 1361 return qe;
1355} 1362}
1356 1363
@@ -1374,15 +1381,15 @@ GNUNET_DATASTORE_get_zero_anonymity(struct GNUNET_DATASTORE_Handle *h,
1374 * cancel 1381 * cancel
1375 */ 1382 */
1376struct GNUNET_DATASTORE_QueueEntry * 1383struct GNUNET_DATASTORE_QueueEntry *
1377GNUNET_DATASTORE_get_key(struct GNUNET_DATASTORE_Handle *h, 1384GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h,
1378 uint64_t next_uid, 1385 uint64_t next_uid,
1379 bool random, 1386 bool random,
1380 const struct GNUNET_HashCode *key, 1387 const struct GNUNET_HashCode *key,
1381 enum GNUNET_BLOCK_Type type, 1388 enum GNUNET_BLOCK_Type type,
1382 unsigned int queue_priority, 1389 unsigned int queue_priority,
1383 unsigned int max_queue_size, 1390 unsigned int max_queue_size,
1384 GNUNET_DATASTORE_DatumProcessor proc, 1391 GNUNET_DATASTORE_DatumProcessor proc,
1385 void *proc_cls) 1392 void *proc_cls)
1386{ 1393{
1387 struct GNUNET_DATASTORE_QueueEntry *qe; 1394 struct GNUNET_DATASTORE_QueueEntry *qe;
1388 struct GNUNET_MQ_Envelope *env; 1395 struct GNUNET_MQ_Envelope *env;
@@ -1390,50 +1397,50 @@ GNUNET_DATASTORE_get_key(struct GNUNET_DATASTORE_Handle *h,
1390 struct GetMessage *gm; 1397 struct GetMessage *gm;
1391 union QueueContext qc; 1398 union QueueContext qc;
1392 1399
1393 GNUNET_assert(NULL != proc); 1400 GNUNET_assert (NULL != proc);
1394 LOG(GNUNET_ERROR_TYPE_DEBUG, 1401 LOG (GNUNET_ERROR_TYPE_DEBUG,
1395 "Asked to look for data of type %u under key `%s'\n", 1402 "Asked to look for data of type %u under key `%s'\n",
1396 (unsigned int)type, 1403 (unsigned int) type,
1397 GNUNET_h2s(key)); 1404 GNUNET_h2s (key));
1398 if (NULL == key) 1405 if (NULL == key)
1399 { 1406 {
1400 env = GNUNET_MQ_msg(gm, 1407 env = GNUNET_MQ_msg (gm,
1401 GNUNET_MESSAGE_TYPE_DATASTORE_GET); 1408 GNUNET_MESSAGE_TYPE_DATASTORE_GET);
1402 gm->type = htonl(type); 1409 gm->type = htonl (type);
1403 gm->next_uid = GNUNET_htonll(next_uid); 1410 gm->next_uid = GNUNET_htonll (next_uid);
1404 gm->random = random; 1411 gm->random = random;
1405 } 1412 }
1406 else 1413 else
1407 { 1414 {
1408 env = GNUNET_MQ_msg(gkm, 1415 env = GNUNET_MQ_msg (gkm,
1409 GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY); 1416 GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY);
1410 gkm->type = htonl(type); 1417 gkm->type = htonl (type);
1411 gkm->next_uid = GNUNET_htonll(next_uid); 1418 gkm->next_uid = GNUNET_htonll (next_uid);
1412 gkm->random = random; 1419 gkm->random = random;
1413 gkm->key = *key; 1420 gkm->key = *key;
1414 } 1421 }
1415 qc.rc.proc = proc; 1422 qc.rc.proc = proc;
1416 qc.rc.proc_cls = proc_cls; 1423 qc.rc.proc_cls = proc_cls;
1417 qe = make_queue_entry(h, 1424 qe = make_queue_entry (h,
1418 env, 1425 env,
1419 queue_priority, 1426 queue_priority,
1420 max_queue_size, 1427 max_queue_size,
1421 GNUNET_MESSAGE_TYPE_DATASTORE_DATA, 1428 GNUNET_MESSAGE_TYPE_DATASTORE_DATA,
1422 &qc); 1429 &qc);
1423 if (NULL == qe) 1430 if (NULL == qe)
1424 { 1431 {
1425 LOG(GNUNET_ERROR_TYPE_DEBUG, 1432 LOG (GNUNET_ERROR_TYPE_DEBUG,
1426 "Could not queue request for `%s'\n", 1433 "Could not queue request for `%s'\n",
1427 GNUNET_h2s(key)); 1434 GNUNET_h2s (key));
1428 return NULL; 1435 return NULL;
1429 } 1436 }
1430#if INSANE_STATISTICS 1437#if INSANE_STATISTICS
1431 GNUNET_STATISTICS_update(h->stats, 1438 GNUNET_STATISTICS_update (h->stats,
1432 gettext_noop("# GET requests executed"), 1439 gettext_noop ("# GET requests executed"),
1433 1, 1440 1,
1434 GNUNET_NO); 1441 GNUNET_NO);
1435#endif 1442#endif
1436 process_queue(h); 1443 process_queue (h);
1437 return qe; 1444 return qe;
1438} 1445}
1439 1446
@@ -1445,23 +1452,23 @@ GNUNET_DATASTORE_get_key(struct GNUNET_DATASTORE_Handle *h,
1445 * @param qe operation to cancel 1452 * @param qe operation to cancel
1446 */ 1453 */
1447void 1454void
1448GNUNET_DATASTORE_cancel(struct GNUNET_DATASTORE_QueueEntry *qe) 1455GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe)
1449{ 1456{
1450 struct GNUNET_DATASTORE_Handle *h = qe->h; 1457 struct GNUNET_DATASTORE_Handle *h = qe->h;
1451 1458
1452 LOG(GNUNET_ERROR_TYPE_DEBUG, 1459 LOG (GNUNET_ERROR_TYPE_DEBUG,
1453 "Pending DATASTORE request %p cancelled (%d, %d)\n", 1460 "Pending DATASTORE request %p cancelled (%d, %d)\n",
1454 qe, 1461 qe,
1455 NULL == qe->env, 1462 NULL == qe->env,
1456 h->queue_head == qe); 1463 h->queue_head == qe);
1457 if (NULL == qe->env) 1464 if (NULL == qe->env)
1458 { 1465 {
1459 free_queue_entry(qe); 1466 free_queue_entry (qe);
1460 h->skip_next_messages++; 1467 h->skip_next_messages++;
1461 return; 1468 return;
1462 } 1469 }
1463 free_queue_entry(qe); 1470 free_queue_entry (qe);
1464 process_queue(h); 1471 process_queue (h);
1465} 1472}
1466 1473
1467 1474
diff --git a/src/datastore/gnunet-datastore.c b/src/datastore/gnunet-datastore.c
index 46a0b2358..259fa518b 100644
--- a/src/datastore/gnunet-datastore.c
+++ b/src/datastore/gnunet-datastore.c
@@ -30,7 +30,8 @@
30 30
31GNUNET_NETWORK_STRUCT_BEGIN 31GNUNET_NETWORK_STRUCT_BEGIN
32 32
33struct DataRecord { 33struct DataRecord
34{
34 /** 35 /**
35 * Number of bytes in the item (NBO). 36 * Number of bytes in the item (NBO).
36 */ 37 */
@@ -121,14 +122,14 @@ static uint64_t record_count;
121 122
122 123
123static void 124static void
124do_shutdown(void *cls) 125do_shutdown (void *cls)
125{ 126{
126 if (NULL != qe) 127 if (NULL != qe)
127 GNUNET_DATASTORE_cancel(qe); 128 GNUNET_DATASTORE_cancel (qe);
128 if (NULL != datastore) 129 if (NULL != datastore)
129 GNUNET_DATASTORE_disconnect(datastore, GNUNET_NO); 130 GNUNET_DATASTORE_disconnect (datastore, GNUNET_NO);
130 if (NULL != file_handle) 131 if (NULL != file_handle)
131 GNUNET_DISK_file_close(file_handle); 132 GNUNET_DISK_file_close (file_handle);
132} 133}
133 134
134 135
@@ -136,21 +137,21 @@ do_shutdown(void *cls)
136 * Begin dumping the database. 137 * Begin dumping the database.
137 */ 138 */
138static void 139static void
139start_dump(void); 140start_dump (void);
140 141
141 142
142/** 143/**
143 * Begin inserting into the database. 144 * Begin inserting into the database.
144 */ 145 */
145static void 146static void
146start_insert(void); 147start_insert (void);
147 148
148 149
149/** 150/**
150 * Perform next GET operation. 151 * Perform next GET operation.
151 */ 152 */
152static void 153static void
153do_get(const uint64_t next_uid); 154do_get (const uint64_t next_uid);
154 155
155 156
156/** 157/**
@@ -169,69 +170,69 @@ do_get(const uint64_t next_uid);
169 * maybe 0 if no unique identifier is available 170 * maybe 0 if no unique identifier is available
170 */ 171 */
171static void 172static void
172get_cb(void *cls, 173get_cb (void *cls,
173 const struct GNUNET_HashCode *key, 174 const struct GNUNET_HashCode *key,
174 size_t size, 175 size_t size,
175 const void *data, 176 const void *data,
176 enum GNUNET_BLOCK_Type type, 177 enum GNUNET_BLOCK_Type type,
177 uint32_t priority, 178 uint32_t priority,
178 uint32_t anonymity, 179 uint32_t anonymity,
179 uint32_t replication, 180 uint32_t replication,
180 struct GNUNET_TIME_Absolute expiration, 181 struct GNUNET_TIME_Absolute expiration,
181 uint64_t uid) 182 uint64_t uid)
182{ 183{
183 qe = NULL; 184 qe = NULL;
184 if (NULL == key) 185 if (NULL == key)
186 {
187 fprintf (stderr, _ ("Dumped %" PRIu64 " records\n"), record_count);
188 GNUNET_DISK_file_close (file_handle);
189 file_handle = NULL;
190 if (insert)
191 start_insert ();
192 else
185 { 193 {
186 fprintf(stderr, _("Dumped %" PRIu64 " records\n"), record_count); 194 ret = 0;
187 GNUNET_DISK_file_close(file_handle); 195 GNUNET_SCHEDULER_shutdown ();
188 file_handle = NULL;
189 if (insert)
190 start_insert();
191 else
192 {
193 ret = 0;
194 GNUNET_SCHEDULER_shutdown();
195 }
196 return;
197 } 196 }
197 return;
198 }
198 199
199 struct DataRecord dr; 200 struct DataRecord dr;
200 dr.size = htonl((uint32_t)size); 201 dr.size = htonl ((uint32_t) size);
201 dr.type = htonl(type); 202 dr.type = htonl (type);
202 dr.priority = htonl(priority); 203 dr.priority = htonl (priority);
203 dr.anonymity = htonl(anonymity); 204 dr.anonymity = htonl (anonymity);
204 dr.replication = htonl(replication); 205 dr.replication = htonl (replication);
205 dr.expiration = GNUNET_TIME_absolute_hton(expiration); 206 dr.expiration = GNUNET_TIME_absolute_hton (expiration);
206 dr.key = *key; 207 dr.key = *key;
207 208
208 ssize_t len; 209 ssize_t len;
209 len = GNUNET_DISK_file_write(file_handle, &dr, sizeof(dr)); 210 len = GNUNET_DISK_file_write (file_handle, &dr, sizeof(dr));
210 if (sizeof(dr) != len) 211 if (sizeof(dr) != len)
211 { 212 {
212 fprintf(stderr, 213 fprintf (stderr,
213 _("Short write to file: %zd bytes expecting %zd\n"), 214 _ ("Short write to file: %zd bytes expecting %zd\n"),
214 len, 215 len,
215 sizeof(dr)); 216 sizeof(dr));
216 ret = 1; 217 ret = 1;
217 GNUNET_SCHEDULER_shutdown(); 218 GNUNET_SCHEDULER_shutdown ();
218 return; 219 return;
219 } 220 }
220 221
221 len = GNUNET_DISK_file_write(file_handle, data, size); 222 len = GNUNET_DISK_file_write (file_handle, data, size);
222 if (size != len) 223 if (size != len)
223 { 224 {
224 fprintf(stderr, 225 fprintf (stderr,
225 _("Short write to file: %zd bytes expecting %zd\n"), 226 _ ("Short write to file: %zd bytes expecting %zd\n"),
226 len, 227 len,
227 size); 228 size);
228 ret = 1; 229 ret = 1;
229 GNUNET_SCHEDULER_shutdown(); 230 GNUNET_SCHEDULER_shutdown ();
230 return; 231 return;
231 } 232 }
232 233
233 record_count++; 234 record_count++;
234 do_get(uid + 1); 235 do_get (uid + 1);
235} 236}
236 237
237 238
@@ -239,24 +240,24 @@ get_cb(void *cls,
239 * Perform next GET operation. 240 * Perform next GET operation.
240 */ 241 */
241static void 242static void
242do_get(const uint64_t next_uid) 243do_get (const uint64_t next_uid)
243{ 244{
244 GNUNET_assert(NULL == qe); 245 GNUNET_assert (NULL == qe);
245 qe = GNUNET_DATASTORE_get_key(datastore, 246 qe = GNUNET_DATASTORE_get_key (datastore,
246 next_uid, 247 next_uid,
247 false /* random */, 248 false /* random */,
248 NULL /* key */, 249 NULL /* key */,
249 GNUNET_BLOCK_TYPE_ANY, 250 GNUNET_BLOCK_TYPE_ANY,
250 0 /* queue_priority */, 251 0 /* queue_priority */,
251 1 /* max_queue_size */, 252 1 /* max_queue_size */,
252 &get_cb, 253 &get_cb,
253 NULL /* proc_cls */); 254 NULL /* proc_cls */);
254 if (NULL == qe) 255 if (NULL == qe)
255 { 256 {
256 fprintf(stderr, _("Error queueing datastore GET operation\n")); 257 fprintf (stderr, _ ("Error queueing datastore GET operation\n"));
257 ret = 1; 258 ret = 1;
258 GNUNET_SCHEDULER_shutdown(); 259 GNUNET_SCHEDULER_shutdown ();
259 } 260 }
260} 261}
261 262
262 263
@@ -264,32 +265,32 @@ do_get(const uint64_t next_uid)
264 * Begin dumping the database. 265 * Begin dumping the database.
265 */ 266 */
266static void 267static void
267start_dump() 268start_dump ()
268{ 269{
269 record_count = 0; 270 record_count = 0;
270 271
271 if (NULL != file_name) 272 if (NULL != file_name)
273 {
274 file_handle = GNUNET_DISK_file_open (file_name,
275 GNUNET_DISK_OPEN_WRITE
276 | GNUNET_DISK_OPEN_TRUNCATE
277 | GNUNET_DISK_OPEN_CREATE,
278 GNUNET_DISK_PERM_USER_READ
279 | GNUNET_DISK_PERM_USER_WRITE);
280 if (NULL == file_handle)
272 { 281 {
273 file_handle = GNUNET_DISK_file_open(file_name, 282 fprintf (stderr, _ ("Unable to open dump file: %s\n"), file_name);
274 GNUNET_DISK_OPEN_WRITE | 283 ret = 1;
275 GNUNET_DISK_OPEN_TRUNCATE | 284 GNUNET_SCHEDULER_shutdown ();
276 GNUNET_DISK_OPEN_CREATE, 285 return;
277 GNUNET_DISK_PERM_USER_READ |
278 GNUNET_DISK_PERM_USER_WRITE);
279 if (NULL == file_handle)
280 {
281 fprintf(stderr, _("Unable to open dump file: %s\n"), file_name);
282 ret = 1;
283 GNUNET_SCHEDULER_shutdown();
284 return;
285 }
286 } 286 }
287 }
287 else 288 else
288 { 289 {
289 file_handle = GNUNET_DISK_get_handle_from_int_fd(STDOUT_FILENO); 290 file_handle = GNUNET_DISK_get_handle_from_int_fd (STDOUT_FILENO);
290 } 291 }
291 GNUNET_DISK_file_write(file_handle, MAGIC_BYTES, MAGIC_LEN); 292 GNUNET_DISK_file_write (file_handle, MAGIC_BYTES, MAGIC_LEN);
292 do_get(0); 293 do_get (0);
293} 294}
294 295
295 296
@@ -307,77 +308,77 @@ start_dump()
307 * @param msg NULL on success, otherwise an error message 308 * @param msg NULL on success, otherwise an error message
308 */ 309 */
309static void 310static void
310put_cb(void *cls, 311put_cb (void *cls,
311 int32_t success, 312 int32_t success,
312 struct GNUNET_TIME_Absolute min_expiration, 313 struct GNUNET_TIME_Absolute min_expiration,
313 const char *msg) 314 const char *msg)
314{ 315{
315 qe = NULL; 316 qe = NULL;
316 if (GNUNET_SYSERR == success) 317 if (GNUNET_SYSERR == success)
317 { 318 {
318 fprintf(stderr, _("Failed to store item: %s, aborting\n"), msg); 319 fprintf (stderr, _ ("Failed to store item: %s, aborting\n"), msg);
319 ret = 1; 320 ret = 1;
320 GNUNET_SCHEDULER_shutdown(); 321 GNUNET_SCHEDULER_shutdown ();
321 return; 322 return;
322 } 323 }
323 324
324 struct DataRecord dr; 325 struct DataRecord dr;
325 ssize_t len; 326 ssize_t len;
326 327
327 len = GNUNET_DISK_file_read(file_handle, &dr, sizeof(dr)); 328 len = GNUNET_DISK_file_read (file_handle, &dr, sizeof(dr));
328 if (0 == len) 329 if (0 == len)
329 { 330 {
330 fprintf(stderr, _("Inserted %" PRIu64 " records\n"), record_count); 331 fprintf (stderr, _ ("Inserted %" PRIu64 " records\n"), record_count);
331 ret = 0; 332 ret = 0;
332 GNUNET_SCHEDULER_shutdown(); 333 GNUNET_SCHEDULER_shutdown ();
333 return; 334 return;
334 } 335 }
335 else if (sizeof(dr) != len) 336 else if (sizeof(dr) != len)
336 { 337 {
337 fprintf(stderr, 338 fprintf (stderr,
338 _("Short read from file: %zd bytes expecting %zd\n"), 339 _ ("Short read from file: %zd bytes expecting %zd\n"),
339 len, 340 len,
340 sizeof(dr)); 341 sizeof(dr));
341 ret = 1; 342 ret = 1;
342 GNUNET_SCHEDULER_shutdown(); 343 GNUNET_SCHEDULER_shutdown ();
343 return; 344 return;
344 } 345 }
345 346
346 const size_t size = ntohl(dr.size); 347 const size_t size = ntohl (dr.size);
347 uint8_t data[size]; 348 uint8_t data[size];
348 len = GNUNET_DISK_file_read(file_handle, data, size); 349 len = GNUNET_DISK_file_read (file_handle, data, size);
349 if (size != len) 350 if (size != len)
350 { 351 {
351 fprintf(stderr, 352 fprintf (stderr,
352 _("Short read from file: %zd bytes expecting %zd\n"), 353 _ ("Short read from file: %zd bytes expecting %zd\n"),
353 len, 354 len,
354 size); 355 size);
355 ret = 1; 356 ret = 1;
356 GNUNET_SCHEDULER_shutdown(); 357 GNUNET_SCHEDULER_shutdown ();
357 return; 358 return;
358 } 359 }
359 360
360 record_count++; 361 record_count++;
361 qe = GNUNET_DATASTORE_put(datastore, 362 qe = GNUNET_DATASTORE_put (datastore,
362 0, 363 0,
363 &dr.key, 364 &dr.key,
364 size, 365 size,
365 data, 366 data,
366 ntohl(dr.type), 367 ntohl (dr.type),
367 ntohl(dr.priority), 368 ntohl (dr.priority),
368 ntohl(dr.anonymity), 369 ntohl (dr.anonymity),
369 ntohl(dr.replication), 370 ntohl (dr.replication),
370 GNUNET_TIME_absolute_ntoh(dr.expiration), 371 GNUNET_TIME_absolute_ntoh (dr.expiration),
371 0, 372 0,
372 1, 373 1,
373 &put_cb, 374 &put_cb,
374 NULL); 375 NULL);
375 if (NULL == qe) 376 if (NULL == qe)
376 { 377 {
377 fprintf(stderr, _("Error queueing datastore PUT operation\n")); 378 fprintf (stderr, _ ("Error queueing datastore PUT operation\n"));
378 ret = 1; 379 ret = 1;
379 GNUNET_SCHEDULER_shutdown(); 380 GNUNET_SCHEDULER_shutdown ();
380 } 381 }
381} 382}
382 383
383 384
@@ -385,38 +386,38 @@ put_cb(void *cls,
385 * Begin inserting into the database. 386 * Begin inserting into the database.
386 */ 387 */
387static void 388static void
388start_insert() 389start_insert ()
389{ 390{
390 record_count = 0; 391 record_count = 0;
391 392
392 if (NULL != file_name) 393 if (NULL != file_name)
394 {
395 file_handle = GNUNET_DISK_file_open (file_name,
396 GNUNET_DISK_OPEN_READ,
397 GNUNET_DISK_PERM_NONE);
398 if (NULL == file_handle)
393 { 399 {
394 file_handle = GNUNET_DISK_file_open(file_name, 400 fprintf (stderr, _ ("Unable to open dump file: %s\n"), file_name);
395 GNUNET_DISK_OPEN_READ, 401 ret = 1;
396 GNUNET_DISK_PERM_NONE); 402 GNUNET_SCHEDULER_shutdown ();
397 if (NULL == file_handle) 403 return;
398 {
399 fprintf(stderr, _("Unable to open dump file: %s\n"), file_name);
400 ret = 1;
401 GNUNET_SCHEDULER_shutdown();
402 return;
403 }
404 } 404 }
405 }
405 else 406 else
406 { 407 {
407 file_handle = GNUNET_DISK_get_handle_from_int_fd(STDIN_FILENO); 408 file_handle = GNUNET_DISK_get_handle_from_int_fd (STDIN_FILENO);
408 } 409 }
409 410
410 uint8_t buf[MAGIC_LEN]; 411 uint8_t buf[MAGIC_LEN];
411 ssize_t len; 412 ssize_t len;
412 413
413 len = GNUNET_DISK_file_read(file_handle, buf, MAGIC_LEN); 414 len = GNUNET_DISK_file_read (file_handle, buf, MAGIC_LEN);
414 if (len != MAGIC_LEN || 0 != memcmp(buf, MAGIC_BYTES, MAGIC_LEN)) 415 if ((len != MAGIC_LEN)||(0 != memcmp (buf, MAGIC_BYTES, MAGIC_LEN)))
415 { 416 {
416 fprintf(stderr, _("Input file is not of a supported format\n")); 417 fprintf (stderr, _ ("Input file is not of a supported format\n"));
417 return; 418 return;
418 } 419 }
419 put_cb(NULL, GNUNET_YES, GNUNET_TIME_UNIT_ZERO_ABS, NULL); 420 put_cb (NULL, GNUNET_YES, GNUNET_TIME_UNIT_ZERO_ABS, NULL);
420} 421}
421 422
422 423
@@ -429,33 +430,33 @@ start_insert()
429 * @param cfg configuration 430 * @param cfg configuration
430 */ 431 */
431static void 432static void
432run(void *cls, 433run (void *cls,
433 char *const *args, 434 char *const *args,
434 const char *cfgfile, 435 const char *cfgfile,
435 const struct GNUNET_CONFIGURATION_Handle *cfg) 436 const struct GNUNET_CONFIGURATION_Handle *cfg)
436{ 437{
437 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); 438 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
438 datastore = GNUNET_DATASTORE_connect(cfg); 439 datastore = GNUNET_DATASTORE_connect (cfg);
439 if (NULL == datastore) 440 if (NULL == datastore)
440 { 441 {
441 fprintf(stderr, _("Failed connecting to the datastore.\n")); 442 fprintf (stderr, _ ("Failed connecting to the datastore.\n"));
442 ret = 1; 443 ret = 1;
443 GNUNET_SCHEDULER_shutdown(); 444 GNUNET_SCHEDULER_shutdown ();
444 return; 445 return;
445 } 446 }
446 if (dump) 447 if (dump)
447 start_dump(); 448 start_dump ();
448 else if (insert) 449 else if (insert)
449 start_insert(); 450 start_insert ();
450 else 451 else
451 { 452 {
452 fprintf(stderr, 453 fprintf (stderr,
453 _("Please choose at least one operation: %s, %s\n"), 454 _ ("Please choose at least one operation: %s, %s\n"),
454 "dump", 455 "dump",
455 "insert"); 456 "insert");
456 ret = 1; 457 ret = 1;
457 GNUNET_SCHEDULER_shutdown(); 458 GNUNET_SCHEDULER_shutdown ();
458 } 459 }
459} 460}
460 461
461 462
@@ -467,39 +468,39 @@ run(void *cls,
467 * @return 0 ok, 1 on error 468 * @return 0 ok, 1 on error
468 */ 469 */
469int 470int
470main(int argc, char *const *argv) 471main (int argc, char *const *argv)
471{ 472{
472 struct GNUNET_GETOPT_CommandLineOption options[] = 473 struct GNUNET_GETOPT_CommandLineOption options[] =
473 { GNUNET_GETOPT_option_flag('d', 474 { GNUNET_GETOPT_option_flag ('d',
474 "dump", 475 "dump",
475 gettext_noop( 476 gettext_noop (
476 "Dump all records from the datastore"), 477 "Dump all records from the datastore"),
477 &dump), 478 &dump),
478 GNUNET_GETOPT_option_flag('i', 479 GNUNET_GETOPT_option_flag ('i',
479 "insert", 480 "insert",
480 gettext_noop( 481 gettext_noop (
481 "Insert records into the datastore"), 482 "Insert records into the datastore"),
482 &insert), 483 &insert),
483 GNUNET_GETOPT_option_filename('f', 484 GNUNET_GETOPT_option_filename ('f',
484 "file", 485 "file",
485 "FILENAME", 486 "FILENAME",
486 gettext_noop("File to dump or insert"), 487 gettext_noop ("File to dump or insert"),
487 &file_name), 488 &file_name),
488 GNUNET_GETOPT_OPTION_END }; 489 GNUNET_GETOPT_OPTION_END };
489 490
490 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 491 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
491 return 2; 492 return 2;
492 493
493 if (GNUNET_OK != 494 if (GNUNET_OK !=
494 GNUNET_PROGRAM_run(argc, 495 GNUNET_PROGRAM_run (argc,
495 argv, 496 argv,
496 "gnunet-datastore", 497 "gnunet-datastore",
497 gettext_noop("Manipulate GNUnet datastore"), 498 gettext_noop ("Manipulate GNUnet datastore"),
498 options, 499 options,
499 &run, 500 &run,
500 NULL)) 501 NULL))
501 ret = 1; 502 ret = 1;
502 GNUNET_free((void *)argv); 503 GNUNET_free ((void *) argv);
503 return ret; 504 return ret;
504} 505}
505 506
diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c
index 41abf77ca..bd86fdad1 100644
--- a/src/datastore/gnunet-service-datastore.c
+++ b/src/datastore/gnunet-service-datastore.c
@@ -39,21 +39,21 @@
39/** 39/**
40 * Limit size of bloom filter to 2 GB. 40 * Limit size of bloom filter to 2 GB.
41 */ 41 */
42#define MAX_BF_SIZE ((uint32_t)(1LL << 31)) 42#define MAX_BF_SIZE ((uint32_t) (1LL << 31))
43 43
44/** 44/**
45 * How long are we at most keeping "expired" content 45 * How long are we at most keeping "expired" content
46 * past the expiration date in the database? 46 * past the expiration date in the database?
47 */ 47 */
48#define MAX_EXPIRE_DELAY \ 48#define MAX_EXPIRE_DELAY \
49 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) 49 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
50 50
51/** 51/**
52 * How fast are we allowed to query the database for deleting 52 * How fast are we allowed to query the database for deleting
53 * expired content? (1 item per second). 53 * expired content? (1 item per second).
54 */ 54 */
55#define MIN_EXPIRE_DELAY \ 55#define MIN_EXPIRE_DELAY \
56 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) 56 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
57 57
58/** 58/**
59 * Name under which we store current space consumption. 59 * Name under which we store current space consumption.
@@ -75,7 +75,8 @@ static struct GNUNET_SCHEDULER_Task *stat_timeout_task;
75/** 75/**
76 * Our datastore plugin. 76 * Our datastore plugin.
77 */ 77 */
78struct DatastorePlugin { 78struct DatastorePlugin
79{
79 /** 80 /**
80 * API of the transport as returned by the plugin's 81 * API of the transport as returned by the plugin's
81 * initialization function. 82 * initialization function.
@@ -103,7 +104,8 @@ struct DatastorePlugin {
103/** 104/**
104 * Linked list of active reservations. 105 * Linked list of active reservations.
105 */ 106 */
106struct ReservationList { 107struct ReservationList
108{
107 /** 109 /**
108 * This is a linked list. 110 * This is a linked list.
109 */ 111 */
@@ -227,13 +229,13 @@ static int stats_worked;
227 * statistics service. 229 * statistics service.
228 */ 230 */
229static void 231static void
230sync_stats() 232sync_stats ()
231{ 233{
232 GNUNET_STATISTICS_set(stats, quota_stat_name, payload, GNUNET_YES); 234 GNUNET_STATISTICS_set (stats, quota_stat_name, payload, GNUNET_YES);
233 GNUNET_STATISTICS_set(stats, 235 GNUNET_STATISTICS_set (stats,
234 "# utilization by current datastore", 236 "# utilization by current datastore",
235 payload, 237 payload,
236 GNUNET_NO); 238 GNUNET_NO);
237 last_sync = 0; 239 last_sync = 0;
238} 240}
239 241
@@ -263,7 +265,7 @@ static struct GNUNET_SERVICE_Handle *service;
263 * @param cls not used 265 * @param cls not used
264 */ 266 */
265static void 267static void
266delete_expired(void *cls); 268delete_expired (void *cls);
267 269
268 270
269/** 271/**
@@ -288,57 +290,57 @@ delete_expired(void *cls);
288 * #GNUNET_NO to delete the item and continue (if supported) 290 * #GNUNET_NO to delete the item and continue (if supported)
289 */ 291 */
290static int 292static int
291expired_processor(void *cls, 293expired_processor (void *cls,
292 const struct GNUNET_HashCode *key, 294 const struct GNUNET_HashCode *key,
293 uint32_t size, 295 uint32_t size,
294 const void *data, 296 const void *data,
295 enum GNUNET_BLOCK_Type type, 297 enum GNUNET_BLOCK_Type type,
296 uint32_t priority, 298 uint32_t priority,
297 uint32_t anonymity, 299 uint32_t anonymity,
298 uint32_t replication, 300 uint32_t replication,
299 struct GNUNET_TIME_Absolute expiration, 301 struct GNUNET_TIME_Absolute expiration,
300 uint64_t uid) 302 uint64_t uid)
301{ 303{
302 struct GNUNET_TIME_Absolute now; 304 struct GNUNET_TIME_Absolute now;
303 305
304 if (NULL == key) 306 if (NULL == key)
305 { 307 {
306 expired_kill_task = 308 expired_kill_task =
307 GNUNET_SCHEDULER_add_delayed_with_priority(MAX_EXPIRE_DELAY, 309 GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY,
308 GNUNET_SCHEDULER_PRIORITY_IDLE, 310 GNUNET_SCHEDULER_PRIORITY_IDLE,
309 &delete_expired, 311 &delete_expired,
310 NULL); 312 NULL);
311 return GNUNET_SYSERR; 313 return GNUNET_SYSERR;
312 } 314 }
313 now = GNUNET_TIME_absolute_get(); 315 now = GNUNET_TIME_absolute_get ();
314 if (expiration.abs_value_us > now.abs_value_us) 316 if (expiration.abs_value_us > now.abs_value_us)
315 { 317 {
316 /* finished processing */ 318 /* finished processing */
317 expired_kill_task = 319 expired_kill_task =
318 GNUNET_SCHEDULER_add_delayed_with_priority(MAX_EXPIRE_DELAY, 320 GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY,
319 GNUNET_SCHEDULER_PRIORITY_IDLE, 321 GNUNET_SCHEDULER_PRIORITY_IDLE,
320 &delete_expired, 322 &delete_expired,
321 NULL); 323 NULL);
322 return GNUNET_SYSERR; 324 return GNUNET_SYSERR;
323 } 325 }
324 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 326 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
325 "Deleting content `%s' of type %u that expired %s ago\n", 327 "Deleting content `%s' of type %u that expired %s ago\n",
326 GNUNET_h2s(key), 328 GNUNET_h2s (key),
327 type, 329 type,
328 GNUNET_STRINGS_relative_time_to_string( 330 GNUNET_STRINGS_relative_time_to_string (
329 GNUNET_TIME_absolute_get_difference(expiration, now), 331 GNUNET_TIME_absolute_get_difference (expiration, now),
330 GNUNET_YES)); 332 GNUNET_YES));
331 min_expiration = now; 333 min_expiration = now;
332 GNUNET_STATISTICS_update(stats, 334 GNUNET_STATISTICS_update (stats,
333 gettext_noop("# bytes expired"), 335 gettext_noop ("# bytes expired"),
334 size, 336 size,
335 GNUNET_YES); 337 GNUNET_YES);
336 GNUNET_CONTAINER_bloomfilter_remove(filter, key); 338 GNUNET_CONTAINER_bloomfilter_remove (filter, key);
337 expired_kill_task = 339 expired_kill_task =
338 GNUNET_SCHEDULER_add_delayed_with_priority(MIN_EXPIRE_DELAY, 340 GNUNET_SCHEDULER_add_delayed_with_priority (MIN_EXPIRE_DELAY,
339 GNUNET_SCHEDULER_PRIORITY_IDLE, 341 GNUNET_SCHEDULER_PRIORITY_IDLE,
340 &delete_expired, 342 &delete_expired,
341 NULL); 343 NULL);
342 return GNUNET_NO; 344 return GNUNET_NO;
343} 345}
344 346
@@ -352,10 +354,10 @@ expired_processor(void *cls,
352 * @param cls not used 354 * @param cls not used
353 */ 355 */
354static void 356static void
355delete_expired(void *cls) 357delete_expired (void *cls)
356{ 358{
357 expired_kill_task = NULL; 359 expired_kill_task = NULL;
358 plugin->api->get_expiration(plugin->api->cls, &expired_processor, NULL); 360 plugin->api->get_expiration (plugin->api->cls, &expired_processor, NULL);
359} 361}
360 362
361 363
@@ -379,31 +381,31 @@ delete_expired(void *cls)
379 * #GNUNET_NO to delete the item and continue (if supported) 381 * #GNUNET_NO to delete the item and continue (if supported)
380 */ 382 */
381static int 383static int
382quota_processor(void *cls, 384quota_processor (void *cls,
383 const struct GNUNET_HashCode *key, 385 const struct GNUNET_HashCode *key,
384 uint32_t size, 386 uint32_t size,
385 const void *data, 387 const void *data,
386 enum GNUNET_BLOCK_Type type, 388 enum GNUNET_BLOCK_Type type,
387 uint32_t priority, 389 uint32_t priority,
388 uint32_t anonymity, 390 uint32_t anonymity,
389 uint32_t replication, 391 uint32_t replication,
390 struct GNUNET_TIME_Absolute expiration, 392 struct GNUNET_TIME_Absolute expiration,
391 uint64_t uid) 393 uint64_t uid)
392{ 394{
393 unsigned long long *need = cls; 395 unsigned long long *need = cls;
394 396
395 if (NULL == key) 397 if (NULL == key)
396 return GNUNET_SYSERR; 398 return GNUNET_SYSERR;
397 GNUNET_log( 399 GNUNET_log (
398 GNUNET_ERROR_TYPE_DEBUG, 400 GNUNET_ERROR_TYPE_DEBUG,
399 "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", 401 "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",
400 (unsigned long long)(size + GNUNET_DATASTORE_ENTRY_OVERHEAD), 402 (unsigned long long) (size + GNUNET_DATASTORE_ENTRY_OVERHEAD),
401 (unsigned int)priority, 403 (unsigned int) priority,
402 GNUNET_h2s(key), 404 GNUNET_h2s (key),
403 type, 405 type,
404 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_remaining( 406 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (
405 expiration), 407 expiration),
406 GNUNET_YES), 408 GNUNET_YES),
407 *need); 409 *need);
408 if (size + GNUNET_DATASTORE_ENTRY_OVERHEAD > *need) 410 if (size + GNUNET_DATASTORE_ENTRY_OVERHEAD > *need)
409 *need = 0; 411 *need = 0;
@@ -413,11 +415,11 @@ quota_processor(void *cls,
413 min_expiration = GNUNET_TIME_UNIT_FOREVER_ABS; 415 min_expiration = GNUNET_TIME_UNIT_FOREVER_ABS;
414 else 416 else
415 min_expiration = expiration; 417 min_expiration = expiration;
416 GNUNET_STATISTICS_update(stats, 418 GNUNET_STATISTICS_update (stats,
417 gettext_noop("# bytes purged (low-priority)"), 419 gettext_noop ("# bytes purged (low-priority)"),
418 size, 420 size,
419 GNUNET_YES); 421 GNUNET_YES);
420 GNUNET_CONTAINER_bloomfilter_remove(filter, key); 422 GNUNET_CONTAINER_bloomfilter_remove (filter, key);
421 return GNUNET_NO; 423 return GNUNET_NO;
422} 424}
423 425
@@ -435,19 +437,19 @@ quota_processor(void *cls,
435 * number of bytes that should be removed). 437 * number of bytes that should be removed).
436 */ 438 */
437static void 439static void
438manage_space(unsigned long long need) 440manage_space (unsigned long long need)
439{ 441{
440 unsigned long long last; 442 unsigned long long last;
441 443
442 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
443 "Asked to free up %llu bytes of cache space\n", 445 "Asked to free up %llu bytes of cache space\n",
444 need); 446 need);
445 last = 0; 447 last = 0;
446 while ((need > 0) && (last != need)) 448 while ((need > 0) && (last != need))
447 { 449 {
448 last = need; 450 last = need;
449 plugin->api->get_expiration(plugin->api->cls, &quota_processor, &need); 451 plugin->api->get_expiration (plugin->api->cls, &quota_processor, &need);
450 } 452 }
451} 453}
452 454
453 455
@@ -459,25 +461,25 @@ manage_space(unsigned long long need)
459 * @param msg optional error message (can be NULL) 461 * @param msg optional error message (can be NULL)
460 */ 462 */
461static void 463static void
462transmit_status(struct GNUNET_SERVICE_Client *client, 464transmit_status (struct GNUNET_SERVICE_Client *client,
463 int code, 465 int code,
464 const char *msg) 466 const char *msg)
465{ 467{
466 struct GNUNET_MQ_Envelope *env; 468 struct GNUNET_MQ_Envelope *env;
467 struct StatusMessage *sm; 469 struct StatusMessage *sm;
468 size_t slen; 470 size_t slen;
469 471
470 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 472 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
471 "Transmitting `%s' message with value %d and message `%s'\n", 473 "Transmitting `%s' message with value %d and message `%s'\n",
472 "STATUS", 474 "STATUS",
473 code, 475 code,
474 msg != NULL ? msg : "(none)"); 476 msg != NULL ? msg : "(none)");
475 slen = (msg == NULL) ? 0 : strlen(msg) + 1; 477 slen = (msg == NULL) ? 0 : strlen (msg) + 1;
476 env = GNUNET_MQ_msg_extra(sm, slen, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS); 478 env = GNUNET_MQ_msg_extra (sm, slen, GNUNET_MESSAGE_TYPE_DATASTORE_STATUS);
477 sm->status = htonl(code); 479 sm->status = htonl (code);
478 sm->min_expiration = GNUNET_TIME_absolute_hton(min_expiration); 480 sm->min_expiration = GNUNET_TIME_absolute_hton (min_expiration);
479 GNUNET_memcpy(&sm[1], msg, slen); 481 GNUNET_memcpy (&sm[1], msg, slen);
480 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); 482 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
481} 483}
482 484
483 485
@@ -500,16 +502,16 @@ transmit_status(struct GNUNET_SERVICE_Client *client,
500 * #GNUNET_NO to delete the item and continue (if supported) 502 * #GNUNET_NO to delete the item and continue (if supported)
501 */ 503 */
502static int 504static int
503transmit_item(void *cls, 505transmit_item (void *cls,
504 const struct GNUNET_HashCode *key, 506 const struct GNUNET_HashCode *key,
505 uint32_t size, 507 uint32_t size,
506 const void *data, 508 const void *data,
507 enum GNUNET_BLOCK_Type type, 509 enum GNUNET_BLOCK_Type type,
508 uint32_t priority, 510 uint32_t priority,
509 uint32_t anonymity, 511 uint32_t anonymity,
510 uint32_t replication, 512 uint32_t replication,
511 struct GNUNET_TIME_Absolute expiration, 513 struct GNUNET_TIME_Absolute expiration,
512 uint64_t uid) 514 uint64_t uid)
513{ 515{
514 struct GNUNET_SERVICE_Client *client = cls; 516 struct GNUNET_SERVICE_Client *client = cls;
515 struct GNUNET_MQ_Envelope *env; 517 struct GNUNET_MQ_Envelope *env;
@@ -517,39 +519,39 @@ transmit_item(void *cls,
517 struct DataMessage *dm; 519 struct DataMessage *dm;
518 520
519 if (NULL == key) 521 if (NULL == key)
520 { 522 {
521 /* transmit 'DATA_END' */ 523 /* transmit 'DATA_END' */
522 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Transmitting DATA_END message\n"); 524 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting DATA_END message\n");
523 env = GNUNET_MQ_msg(end, GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END); 525 env = GNUNET_MQ_msg (end, GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END);
524 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); 526 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
525 return GNUNET_OK; 527 return GNUNET_OK;
526 } 528 }
527 GNUNET_assert(sizeof(struct DataMessage) + size < GNUNET_MAX_MESSAGE_SIZE); 529 GNUNET_assert (sizeof(struct DataMessage) + size < GNUNET_MAX_MESSAGE_SIZE);
528 env = GNUNET_MQ_msg_extra(dm, size, GNUNET_MESSAGE_TYPE_DATASTORE_DATA); 530 env = GNUNET_MQ_msg_extra (dm, size, GNUNET_MESSAGE_TYPE_DATASTORE_DATA);
529 dm->rid = htonl(0); 531 dm->rid = htonl (0);
530 dm->size = htonl(size); 532 dm->size = htonl (size);
531 dm->type = htonl(type); 533 dm->type = htonl (type);
532 dm->priority = htonl(priority); 534 dm->priority = htonl (priority);
533 dm->anonymity = htonl(anonymity); 535 dm->anonymity = htonl (anonymity);
534 dm->replication = htonl(replication); 536 dm->replication = htonl (replication);
535 dm->expiration = GNUNET_TIME_absolute_hton(expiration); 537 dm->expiration = GNUNET_TIME_absolute_hton (expiration);
536 dm->uid = GNUNET_htonll(uid); 538 dm->uid = GNUNET_htonll (uid);
537 dm->key = *key; 539 dm->key = *key;
538 GNUNET_memcpy(&dm[1], data, size); 540 GNUNET_memcpy (&dm[1], data, size);
539 GNUNET_log( 541 GNUNET_log (
540 GNUNET_ERROR_TYPE_DEBUG, 542 GNUNET_ERROR_TYPE_DEBUG,
541 "Transmitting DATA message for `%s' of type %u with expiration %s (in: %s)\n", 543 "Transmitting DATA message for `%s' of type %u with expiration %s (in: %s)\n",
542 GNUNET_h2s(key), 544 GNUNET_h2s (key),
543 type, 545 type,
544 GNUNET_STRINGS_absolute_time_to_string(expiration), 546 GNUNET_STRINGS_absolute_time_to_string (expiration),
545 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_remaining( 547 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (
546 expiration), 548 expiration),
547 GNUNET_YES)); 549 GNUNET_YES));
548 GNUNET_STATISTICS_update(stats, 550 GNUNET_STATISTICS_update (stats,
549 gettext_noop("# results found"), 551 gettext_noop ("# results found"),
550 1, 552 1,
551 GNUNET_NO); 553 GNUNET_NO);
552 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); 554 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
553 return GNUNET_OK; 555 return GNUNET_OK;
554} 556}
555 557
@@ -561,7 +563,7 @@ transmit_item(void *cls,
561 * @param message the actual message 563 * @param message the actual message
562 */ 564 */
563static void 565static void
564handle_reserve(void *cls, const struct ReserveMessage *msg) 566handle_reserve (void *cls, const struct ReserveMessage *msg)
565{ 567{
566 /** 568 /**
567 * Static counter to produce reservation identifiers. 569 * Static counter to produce reservation identifiers.
@@ -574,57 +576,57 @@ handle_reserve(void *cls, const struct ReserveMessage *msg)
574 uint64_t amount; 576 uint64_t amount;
575 uint32_t entries; 577 uint32_t entries;
576 578
577 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Processing RESERVE request\n"); 579 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing RESERVE request\n");
578 amount = GNUNET_ntohll(msg->amount); 580 amount = GNUNET_ntohll (msg->amount);
579 entries = ntohl(msg->entries); 581 entries = ntohl (msg->entries);
580 used = payload + reserved; 582 used = payload + reserved;
581 req = 583 req =
582 amount + ((unsigned long long)GNUNET_DATASTORE_ENTRY_OVERHEAD) * entries; 584 amount + ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * entries;
583 if (used + req > quota) 585 if (used + req > quota)
586 {
587 if (quota < used)
588 used =
589 quota; /* cheat a bit for error message (to avoid negative numbers) */
590 GNUNET_log (
591 GNUNET_ERROR_TYPE_WARNING,
592 _ (
593 "Insufficient space (%llu bytes are available) to satisfy RESERVE request for %llu bytes\n"),
594 quota - used,
595 req);
596 if (cache_size < req)
584 { 597 {
585 if (quota < used) 598 /* TODO: document this in the FAQ; essentially, if this
586 used = 599 * message happens, the insertion request could be blocked
587 quota; /* cheat a bit for error message (to avoid negative numbers) */ 600 * by less-important content from migration because it is
588 GNUNET_log( 601 * larger than 1/8th of the overall available space, and
602 * we only reserve 1/8th for "fresh" insertions */
603 GNUNET_log (
589 GNUNET_ERROR_TYPE_WARNING, 604 GNUNET_ERROR_TYPE_WARNING,
590 _( 605 _ (
591 "Insufficient space (%llu bytes are available) to satisfy RESERVE request for %llu bytes\n"), 606 "The requested amount (%llu bytes) is larger than the cache size (%llu bytes)\n"),
592 quota - used, 607 req,
593 req); 608 cache_size);
594 if (cache_size < req) 609 transmit_status (client,
595 { 610 0,
596 /* TODO: document this in the FAQ; essentially, if this 611 gettext_noop (
597 * message happens, the insertion request could be blocked 612 "Insufficient space to satisfy request and "
598 * by less-important content from migration because it is 613 "requested amount is larger than cache size"));
599 * larger than 1/8th of the overall available space, and 614 }
600 * we only reserve 1/8th for "fresh" insertions */ 615 else
601 GNUNET_log( 616 {
602 GNUNET_ERROR_TYPE_WARNING, 617 transmit_status (client,
603 _( 618 0,
604 "The requested amount (%llu bytes) is larger than the cache size (%llu bytes)\n"), 619 gettext_noop ("Insufficient space to satisfy request"));
605 req,
606 cache_size);
607 transmit_status(client,
608 0,
609 gettext_noop(
610 "Insufficient space to satisfy request and "
611 "requested amount is larger than cache size"));
612 }
613 else
614 {
615 transmit_status(client,
616 0,
617 gettext_noop("Insufficient space to satisfy request"));
618 }
619 GNUNET_SERVICE_client_continue(client);
620 return;
621 } 620 }
621 GNUNET_SERVICE_client_continue (client);
622 return;
623 }
622 reserved += req; 624 reserved += req;
623 GNUNET_STATISTICS_set(stats, 625 GNUNET_STATISTICS_set (stats,
624 gettext_noop("# reserved"), 626 gettext_noop ("# reserved"),
625 reserved, 627 reserved,
626 GNUNET_NO); 628 GNUNET_NO);
627 e = GNUNET_new(struct ReservationList); 629 e = GNUNET_new (struct ReservationList);
628 e->next = reservations; 630 e->next = reservations;
629 reservations = e; 631 reservations = e;
630 e->client = client; 632 e->client = client;
@@ -633,8 +635,8 @@ handle_reserve(void *cls, const struct ReserveMessage *msg)
633 e->rid = ++reservation_gen; 635 e->rid = ++reservation_gen;
634 if (reservation_gen < 0) 636 if (reservation_gen < 0)
635 reservation_gen = 0; /* wrap around */ 637 reservation_gen = 0; /* wrap around */
636 transmit_status(client, e->rid, NULL); 638 transmit_status (client, e->rid, NULL);
637 GNUNET_SERVICE_client_continue(client); 639 GNUNET_SERVICE_client_continue (client);
638} 640}
639 641
640 642
@@ -645,51 +647,51 @@ handle_reserve(void *cls, const struct ReserveMessage *msg)
645 * @param message the actual message 647 * @param message the actual message
646 */ 648 */
647static void 649static void
648handle_release_reserve(void *cls, const struct ReleaseReserveMessage *msg) 650handle_release_reserve (void *cls, const struct ReleaseReserveMessage *msg)
649{ 651{
650 struct GNUNET_SERVICE_Client *client = cls; 652 struct GNUNET_SERVICE_Client *client = cls;
651 struct ReservationList *pos; 653 struct ReservationList *pos;
652 struct ReservationList *prev; 654 struct ReservationList *prev;
653 struct ReservationList *next; 655 struct ReservationList *next;
654 int rid = ntohl(msg->rid); 656 int rid = ntohl (msg->rid);
655 unsigned long long rem; 657 unsigned long long rem;
656 658
657 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Processing RELEASE_RESERVE request\n"); 659 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing RELEASE_RESERVE request\n");
658 next = reservations; 660 next = reservations;
659 prev = NULL; 661 prev = NULL;
660 while (NULL != (pos = next)) 662 while (NULL != (pos = next))
663 {
664 next = pos->next;
665 if (rid == pos->rid)
661 { 666 {
662 next = pos->next; 667 if (prev == NULL)
663 if (rid == pos->rid) 668 reservations = next;
664 { 669 else
665 if (prev == NULL) 670 prev->next = next;
666 reservations = next; 671 rem =
667 else 672 pos->amount
668 prev->next = next; 673 + ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries;
669 rem = 674 GNUNET_assert (reserved >= rem);
670 pos->amount + 675 reserved -= rem;
671 ((unsigned long long)GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries; 676 GNUNET_STATISTICS_set (stats,
672 GNUNET_assert(reserved >= rem); 677 gettext_noop ("# reserved"),
673 reserved -= rem; 678 reserved,
674 GNUNET_STATISTICS_set(stats, 679 GNUNET_NO);
675 gettext_noop("# reserved"), 680 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
676 reserved, 681 "Returning %llu remaining reserved bytes to storage pool\n",
677 GNUNET_NO); 682 rem);
678 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 683 GNUNET_free (pos);
679 "Returning %llu remaining reserved bytes to storage pool\n", 684 transmit_status (client, GNUNET_OK, NULL);
680 rem); 685 GNUNET_SERVICE_client_continue (client);
681 GNUNET_free(pos); 686 return;
682 transmit_status(client, GNUNET_OK, NULL);
683 GNUNET_SERVICE_client_continue(client);
684 return;
685 }
686 prev = pos;
687 } 687 }
688 GNUNET_break(0); 688 prev = pos;
689 transmit_status(client, 689 }
690 GNUNET_SYSERR, 690 GNUNET_break (0);
691 gettext_noop("Could not find matching reservation")); 691 transmit_status (client,
692 GNUNET_SERVICE_client_continue(client); 692 GNUNET_SYSERR,
693 gettext_noop ("Could not find matching reservation"));
694 GNUNET_SERVICE_client_continue (client);
693} 695}
694 696
695 697
@@ -700,18 +702,18 @@ handle_release_reserve(void *cls, const struct ReleaseReserveMessage *msg)
700 * @return #GNUNET_SYSERR is not well-formed, otherwise #GNUNET_OK 702 * @return #GNUNET_SYSERR is not well-formed, otherwise #GNUNET_OK
701 */ 703 */
702static int 704static int
703check_data(const struct DataMessage *dm) 705check_data (const struct DataMessage *dm)
704{ 706{
705 uint16_t size; 707 uint16_t size;
706 uint32_t dsize; 708 uint32_t dsize;
707 709
708 size = ntohs(dm->header.size); 710 size = ntohs (dm->header.size);
709 dsize = ntohl(dm->size); 711 dsize = ntohl (dm->size);
710 if (size != dsize + sizeof(struct DataMessage)) 712 if (size != dsize + sizeof(struct DataMessage))
711 { 713 {
712 GNUNET_break(0); 714 GNUNET_break (0);
713 return GNUNET_SYSERR; 715 return GNUNET_SYSERR;
714 } 716 }
715 return GNUNET_OK; 717 return GNUNET_OK;
716} 718}
717 719
@@ -727,38 +729,38 @@ check_data(const struct DataMessage *dm)
727 * @param msg error message on error 729 * @param msg error message on error
728 */ 730 */
729static void 731static void
730put_continuation(void *cls, 732put_continuation (void *cls,
731 const struct GNUNET_HashCode *key, 733 const struct GNUNET_HashCode *key,
732 uint32_t size, 734 uint32_t size,
733 int status, 735 int status,
734 const char *msg) 736 const char *msg)
735{ 737{
736 struct GNUNET_SERVICE_Client *client = cls; 738 struct GNUNET_SERVICE_Client *client = cls;
737 739
738 if (GNUNET_OK == status) 740 if (GNUNET_OK == status)
739 { 741 {
740 GNUNET_STATISTICS_update(stats, 742 GNUNET_STATISTICS_update (stats,
741 gettext_noop("# bytes stored"), 743 gettext_noop ("# bytes stored"),
742 size, 744 size,
743 GNUNET_YES); 745 GNUNET_YES);
744 GNUNET_CONTAINER_bloomfilter_add(filter, key); 746 GNUNET_CONTAINER_bloomfilter_add (filter, key);
745 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 747 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
746 "Successfully stored %u bytes under key `%s'\n", 748 "Successfully stored %u bytes under key `%s'\n",
747 size, 749 size,
748 GNUNET_h2s(key)); 750 GNUNET_h2s (key));
749 } 751 }
750 transmit_status(client, 752 transmit_status (client,
751 GNUNET_SYSERR == status ? GNUNET_SYSERR : GNUNET_OK, 753 GNUNET_SYSERR == status ? GNUNET_SYSERR : GNUNET_OK,
752 msg); 754 msg);
753 if (quota - reserved - cache_size < payload) 755 if (quota - reserved - cache_size < payload)
754 { 756 {
755 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 757 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
756 _("Need %llu bytes more space (%llu allowed, using %llu)\n"), 758 _ ("Need %llu bytes more space (%llu allowed, using %llu)\n"),
757 (unsigned long long)size + GNUNET_DATASTORE_ENTRY_OVERHEAD, 759 (unsigned long long) size + GNUNET_DATASTORE_ENTRY_OVERHEAD,
758 (unsigned long long)(quota - reserved - cache_size), 760 (unsigned long long) (quota - reserved - cache_size),
759 (unsigned long long)payload); 761 (unsigned long long) payload);
760 manage_space(size + GNUNET_DATASTORE_ENTRY_OVERHEAD); 762 manage_space (size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
761 } 763 }
762} 764}
763 765
764 766
@@ -770,13 +772,13 @@ put_continuation(void *cls,
770 * @return #GNUNET_OK if @a dm is well-formed 772 * @return #GNUNET_OK if @a dm is well-formed
771 */ 773 */
772static int 774static int
773check_put(void *cls, const struct DataMessage *dm) 775check_put (void *cls, const struct DataMessage *dm)
774{ 776{
775 if (GNUNET_OK != check_data(dm)) 777 if (GNUNET_OK != check_data (dm))
776 { 778 {
777 GNUNET_break(0); 779 GNUNET_break (0);
778 return GNUNET_SYSERR; 780 return GNUNET_SYSERR;
779 } 781 }
780 return GNUNET_OK; 782 return GNUNET_OK;
781} 783}
782 784
@@ -788,53 +790,53 @@ check_put(void *cls, const struct DataMessage *dm)
788 * @param message the actual message 790 * @param message the actual message
789 */ 791 */
790static void 792static void
791handle_put(void *cls, const struct DataMessage *dm) 793handle_put (void *cls, const struct DataMessage *dm)
792{ 794{
793 struct GNUNET_SERVICE_Client *client = cls; 795 struct GNUNET_SERVICE_Client *client = cls;
794 int rid; 796 int rid;
795 struct ReservationList *pos; 797 struct ReservationList *pos;
796 uint32_t size; 798 uint32_t size;
797 799
798 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 800 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
799 "Processing PUT request for `%s' of type %u\n", 801 "Processing PUT request for `%s' of type %u\n",
800 GNUNET_h2s(&dm->key), 802 GNUNET_h2s (&dm->key),
801 (uint32_t)ntohl(dm->type)); 803 (uint32_t) ntohl (dm->type));
802 rid = ntohl(dm->rid); 804 rid = ntohl (dm->rid);
803 size = ntohl(dm->size); 805 size = ntohl (dm->size);
804 if (rid > 0) 806 if (rid > 0)
807 {
808 pos = reservations;
809 while ((NULL != pos) && (rid != pos->rid))
810 pos = pos->next;
811 GNUNET_break (pos != NULL);
812 if (NULL != pos)
805 { 813 {
806 pos = reservations; 814 GNUNET_break (pos->entries > 0);
807 while ((NULL != pos) && (rid != pos->rid)) 815 GNUNET_break (pos->amount >= size);
808 pos = pos->next; 816 pos->entries--;
809 GNUNET_break(pos != NULL); 817 pos->amount -= size;
810 if (NULL != pos) 818 reserved -= (size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
811 { 819 GNUNET_STATISTICS_set (stats,
812 GNUNET_break(pos->entries > 0); 820 gettext_noop ("# reserved"),
813 GNUNET_break(pos->amount >= size); 821 reserved,
814 pos->entries--; 822 GNUNET_NO);
815 pos->amount -= size;
816 reserved -= (size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
817 GNUNET_STATISTICS_set(stats,
818 gettext_noop("# reserved"),
819 reserved,
820 GNUNET_NO);
821 }
822 } 823 }
824 }
823 bool absent = 825 bool absent =
824 GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test(filter, &dm->key); 826 GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test (filter, &dm->key);
825 plugin->api->put(plugin->api->cls, 827 plugin->api->put (plugin->api->cls,
826 &dm->key, 828 &dm->key,
827 absent, 829 absent,
828 ntohl(dm->size), 830 ntohl (dm->size),
829 &dm[1], 831 &dm[1],
830 ntohl(dm->type), 832 ntohl (dm->type),
831 ntohl(dm->priority), 833 ntohl (dm->priority),
832 ntohl(dm->anonymity), 834 ntohl (dm->anonymity),
833 ntohl(dm->replication), 835 ntohl (dm->replication),
834 GNUNET_TIME_absolute_ntoh(dm->expiration), 836 GNUNET_TIME_absolute_ntoh (dm->expiration),
835 &put_continuation, 837 &put_continuation,
836 client); 838 client);
837 GNUNET_SERVICE_client_continue(client); 839 GNUNET_SERVICE_client_continue (client);
838} 840}
839 841
840 842
@@ -845,25 +847,25 @@ handle_put(void *cls, const struct DataMessage *dm)
845 * @param msg the actual message 847 * @param msg the actual message
846 */ 848 */
847static void 849static void
848handle_get(void *cls, const struct GetMessage *msg) 850handle_get (void *cls, const struct GetMessage *msg)
849{ 851{
850 struct GNUNET_SERVICE_Client *client = cls; 852 struct GNUNET_SERVICE_Client *client = cls;
851 853
852 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 854 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
853 "Processing GET request of type %u\n", 855 "Processing GET request of type %u\n",
854 (uint32_t)ntohl(msg->type)); 856 (uint32_t) ntohl (msg->type));
855 GNUNET_STATISTICS_update(stats, 857 GNUNET_STATISTICS_update (stats,
856 gettext_noop("# GET requests received"), 858 gettext_noop ("# GET requests received"),
857 1, 859 1,
858 GNUNET_NO); 860 GNUNET_NO);
859 plugin->api->get_key(plugin->api->cls, 861 plugin->api->get_key (plugin->api->cls,
860 GNUNET_ntohll(msg->next_uid), 862 GNUNET_ntohll (msg->next_uid),
861 msg->random, 863 msg->random,
862 NULL, 864 NULL,
863 ntohl(msg->type), 865 ntohl (msg->type),
864 &transmit_item, 866 &transmit_item,
865 client); 867 client);
866 GNUNET_SERVICE_client_continue(client); 868 GNUNET_SERVICE_client_continue (client);
867} 869}
868 870
869 871
@@ -874,50 +876,50 @@ handle_get(void *cls, const struct GetMessage *msg)
874 * @param msg the actual message 876 * @param msg the actual message
875 */ 877 */
876static void 878static void
877handle_get_key(void *cls, const struct GetKeyMessage *msg) 879handle_get_key (void *cls, const struct GetKeyMessage *msg)
878{ 880{
879 struct GNUNET_SERVICE_Client *client = cls; 881 struct GNUNET_SERVICE_Client *client = cls;
880 882
881 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 883 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
882 "Processing GET request for `%s' of type %u\n", 884 "Processing GET request for `%s' of type %u\n",
883 GNUNET_h2s(&msg->key), 885 GNUNET_h2s (&msg->key),
884 (uint32_t)ntohl(msg->type)); 886 (uint32_t) ntohl (msg->type));
885 GNUNET_STATISTICS_update(stats, 887 GNUNET_STATISTICS_update (stats,
886 gettext_noop("# GET KEY requests received"), 888 gettext_noop ("# GET KEY requests received"),
887 1, 889 1,
888 GNUNET_NO); 890 GNUNET_NO);
889 if (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test(filter, &msg->key)) 891 if (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (filter, &msg->key))
890 { 892 {
891 /* don't bother database... */ 893 /* don't bother database... */
892 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 894 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
893 "Empty result set for GET request for `%s' (bloomfilter).\n", 895 "Empty result set for GET request for `%s' (bloomfilter).\n",
894 GNUNET_h2s(&msg->key)); 896 GNUNET_h2s (&msg->key));
895 GNUNET_STATISTICS_update(stats, 897 GNUNET_STATISTICS_update (stats,
896 gettext_noop( 898 gettext_noop (
897 "# requests filtered by bloomfilter"), 899 "# requests filtered by bloomfilter"),
898 1, 900 1,
899 GNUNET_NO); 901 GNUNET_NO);
900 transmit_item(client, 902 transmit_item (client,
901 NULL, 903 NULL,
902 0, 904 0,
903 NULL, 905 NULL,
904 0, 906 0,
905 0, 907 0,
906 0, 908 0,
907 0, 909 0,
908 GNUNET_TIME_UNIT_ZERO_ABS, 910 GNUNET_TIME_UNIT_ZERO_ABS,
909 0); 911 0);
910 GNUNET_SERVICE_client_continue(client); 912 GNUNET_SERVICE_client_continue (client);
911 return; 913 return;
912 } 914 }
913 plugin->api->get_key(plugin->api->cls, 915 plugin->api->get_key (plugin->api->cls,
914 GNUNET_ntohll(msg->next_uid), 916 GNUNET_ntohll (msg->next_uid),
915 msg->random, 917 msg->random,
916 &msg->key, 918 &msg->key,
917 ntohl(msg->type), 919 ntohl (msg->type),
918 &transmit_item, 920 &transmit_item,
919 client); 921 client);
920 GNUNET_SERVICE_client_continue(client); 922 GNUNET_SERVICE_client_continue (client);
921} 923}
922 924
923 925
@@ -928,18 +930,18 @@ handle_get_key(void *cls, const struct GetKeyMessage *msg)
928 * @param message the actual message 930 * @param message the actual message
929 */ 931 */
930static void 932static void
931handle_get_replication(void *cls, const struct GNUNET_MessageHeader *message) 933handle_get_replication (void *cls, const struct GNUNET_MessageHeader *message)
932{ 934{
933 struct GNUNET_SERVICE_Client *client = cls; 935 struct GNUNET_SERVICE_Client *client = cls;
934 936
935 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Processing GET_REPLICATION request\n"); 937 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing GET_REPLICATION request\n");
936 GNUNET_STATISTICS_update(stats, 938 GNUNET_STATISTICS_update (stats,
937 gettext_noop( 939 gettext_noop (
938 "# GET REPLICATION requests received"), 940 "# GET REPLICATION requests received"),
939 1, 941 1,
940 GNUNET_NO); 942 GNUNET_NO);
941 plugin->api->get_replication(plugin->api->cls, &transmit_item, client); 943 plugin->api->get_replication (plugin->api->cls, &transmit_item, client);
942 GNUNET_SERVICE_client_continue(client); 944 GNUNET_SERVICE_client_continue (client);
943} 945}
944 946
945 947
@@ -950,31 +952,31 @@ handle_get_replication(void *cls, const struct GNUNET_MessageHeader *message)
950 * @param message the actual message 952 * @param message the actual message
951 */ 953 */
952static void 954static void
953handle_get_zero_anonymity(void *cls, const struct GetZeroAnonymityMessage *msg) 955handle_get_zero_anonymity (void *cls, const struct GetZeroAnonymityMessage *msg)
954{ 956{
955 struct GNUNET_SERVICE_Client *client = cls; 957 struct GNUNET_SERVICE_Client *client = cls;
956 enum GNUNET_BLOCK_Type type; 958 enum GNUNET_BLOCK_Type type;
957 959
958 type = (enum GNUNET_BLOCK_Type)ntohl(msg->type); 960 type = (enum GNUNET_BLOCK_Type) ntohl (msg->type);
959 if (type == GNUNET_BLOCK_TYPE_ANY) 961 if (type == GNUNET_BLOCK_TYPE_ANY)
960 { 962 {
961 GNUNET_break(0); 963 GNUNET_break (0);
962 GNUNET_SERVICE_client_drop(client); 964 GNUNET_SERVICE_client_drop (client);
963 return; 965 return;
964 } 966 }
965 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 967 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
966 "Processing GET_ZERO_ANONYMITY request\n"); 968 "Processing GET_ZERO_ANONYMITY request\n");
967 GNUNET_STATISTICS_update(stats, 969 GNUNET_STATISTICS_update (stats,
968 gettext_noop( 970 gettext_noop (
969 "# GET ZERO ANONYMITY requests received"), 971 "# GET ZERO ANONYMITY requests received"),
970 1, 972 1,
971 GNUNET_NO); 973 GNUNET_NO);
972 plugin->api->get_zero_anonymity(plugin->api->cls, 974 plugin->api->get_zero_anonymity (plugin->api->cls,
973 GNUNET_ntohll(msg->next_uid), 975 GNUNET_ntohll (msg->next_uid),
974 type, 976 type,
975 &transmit_item, 977 &transmit_item,
976 client); 978 client);
977 GNUNET_SERVICE_client_continue(client); 979 GNUNET_SERVICE_client_continue (client);
978} 980}
979 981
980 982
@@ -989,36 +991,36 @@ handle_get_zero_anonymity(void *cls, const struct GetZeroAnonymityMessage *msg)
989 * @param msg error message on error 991 * @param msg error message on error
990 */ 992 */
991static void 993static void
992remove_continuation(void *cls, 994remove_continuation (void *cls,
993 const struct GNUNET_HashCode *key, 995 const struct GNUNET_HashCode *key,
994 uint32_t size, 996 uint32_t size,
995 int status, 997 int status,
996 const char *msg) 998 const char *msg)
997{ 999{
998 struct GNUNET_SERVICE_Client *client = cls; 1000 struct GNUNET_SERVICE_Client *client = cls;
999 1001
1000 if (GNUNET_SYSERR == status) 1002 if (GNUNET_SYSERR == status)
1001 { 1003 {
1002 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "REMOVE request failed: %s.\n", msg); 1004 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "REMOVE request failed: %s.\n", msg);
1003 transmit_status(client, GNUNET_NO, msg); 1005 transmit_status (client, GNUNET_NO, msg);
1004 return; 1006 return;
1005 } 1007 }
1006 if (GNUNET_NO == status) 1008 if (GNUNET_NO == status)
1007 { 1009 {
1008 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1010 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1009 "Content not found for REMOVE request.\n"); 1011 "Content not found for REMOVE request.\n");
1010 transmit_status(client, GNUNET_NO, _("Content not found")); 1012 transmit_status (client, GNUNET_NO, _ ("Content not found"));
1011 return; 1013 return;
1012 } 1014 }
1013 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1015 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1014 "Item matches REMOVE request for key `%s'.\n", 1016 "Item matches REMOVE request for key `%s'.\n",
1015 GNUNET_h2s(key)); 1017 GNUNET_h2s (key));
1016 GNUNET_STATISTICS_update(stats, 1018 GNUNET_STATISTICS_update (stats,
1017 gettext_noop("# bytes removed (explicit request)"), 1019 gettext_noop ("# bytes removed (explicit request)"),
1018 size, 1020 size,
1019 GNUNET_YES); 1021 GNUNET_YES);
1020 GNUNET_CONTAINER_bloomfilter_remove(filter, key); 1022 GNUNET_CONTAINER_bloomfilter_remove (filter, key);
1021 transmit_status(client, GNUNET_OK, NULL); 1023 transmit_status (client, GNUNET_OK, NULL);
1022} 1024}
1023 1025
1024 1026
@@ -1030,13 +1032,13 @@ remove_continuation(void *cls,
1030 * @return #GNUNET_OK if @a dm is well-formed 1032 * @return #GNUNET_OK if @a dm is well-formed
1031 */ 1033 */
1032static int 1034static int
1033check_remove(void *cls, const struct DataMessage *dm) 1035check_remove (void *cls, const struct DataMessage *dm)
1034{ 1036{
1035 if (GNUNET_OK != check_data(dm)) 1037 if (GNUNET_OK != check_data (dm))
1036 { 1038 {
1037 GNUNET_break(0); 1039 GNUNET_break (0);
1038 return GNUNET_SYSERR; 1040 return GNUNET_SYSERR;
1039 } 1041 }
1040 return GNUNET_OK; 1042 return GNUNET_OK;
1041} 1043}
1042 1044
@@ -1049,24 +1051,24 @@ check_remove(void *cls, const struct DataMessage *dm)
1049 * @param message the actual message 1051 * @param message the actual message
1050 */ 1052 */
1051static void 1053static void
1052handle_remove(void *cls, const struct DataMessage *dm) 1054handle_remove (void *cls, const struct DataMessage *dm)
1053{ 1055{
1054 struct GNUNET_SERVICE_Client *client = cls; 1056 struct GNUNET_SERVICE_Client *client = cls;
1055 1057
1056 GNUNET_STATISTICS_update(stats, 1058 GNUNET_STATISTICS_update (stats,
1057 gettext_noop("# REMOVE requests received"), 1059 gettext_noop ("# REMOVE requests received"),
1058 1, 1060 1,
1059 GNUNET_NO); 1061 GNUNET_NO);
1060 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1062 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1061 "Processing REMOVE request for `%s'\n", 1063 "Processing REMOVE request for `%s'\n",
1062 GNUNET_h2s(&dm->key)); 1064 GNUNET_h2s (&dm->key));
1063 plugin->api->remove_key(plugin->api->cls, 1065 plugin->api->remove_key (plugin->api->cls,
1064 &dm->key, 1066 &dm->key,
1065 ntohl(dm->size), 1067 ntohl (dm->size),
1066 &dm[1], 1068 &dm[1],
1067 &remove_continuation, 1069 &remove_continuation,
1068 client); 1070 client);
1069 GNUNET_SERVICE_client_continue(client); 1071 GNUNET_SERVICE_client_continue (client);
1070} 1072}
1071 1073
1072 1074
@@ -1077,13 +1079,13 @@ handle_remove(void *cls, const struct DataMessage *dm)
1077 * @param message the actual message 1079 * @param message the actual message
1078 */ 1080 */
1079static void 1081static void
1080handle_drop(void *cls, const struct GNUNET_MessageHeader *message) 1082handle_drop (void *cls, const struct GNUNET_MessageHeader *message)
1081{ 1083{
1082 struct GNUNET_SERVICE_Client *client = cls; 1084 struct GNUNET_SERVICE_Client *client = cls;
1083 1085
1084 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Processing DROP request\n"); 1086 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing DROP request\n");
1085 do_drop = GNUNET_YES; 1087 do_drop = GNUNET_YES;
1086 GNUNET_SERVICE_client_continue(client); 1088 GNUNET_SERVICE_client_continue (client);
1087} 1089}
1088 1090
1089 1091
@@ -1096,27 +1098,27 @@ handle_drop(void *cls, const struct GNUNET_MessageHeader *message)
1096 * 0 for "reset to empty" 1098 * 0 for "reset to empty"
1097 */ 1099 */
1098static void 1100static void
1099disk_utilization_change_cb(void *cls, int delta) 1101disk_utilization_change_cb (void *cls, int delta)
1100{ 1102{
1101 if ((delta < 0) && (payload < -delta)) 1103 if ((delta < 0) && (payload < -delta))
1102 { 1104 {
1103 GNUNET_log( 1105 GNUNET_log (
1104 GNUNET_ERROR_TYPE_WARNING, 1106 GNUNET_ERROR_TYPE_WARNING,
1105 _( 1107 _ (
1106 "Datastore payload must have been inaccurate (%lld < %lld). Recomputing it.\n"), 1108 "Datastore payload must have been inaccurate (%lld < %lld). Recomputing it.\n"),
1107 (long long)payload, 1109 (long long) payload,
1108 (long long)-delta); 1110 (long long) -delta);
1109 plugin->api->estimate_size(plugin->api->cls, &payload); 1111 plugin->api->estimate_size (plugin->api->cls, &payload);
1110 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1112 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1111 _("New payload: %lld\n"), 1113 _ ("New payload: %lld\n"),
1112 (long long)payload); 1114 (long long) payload);
1113 sync_stats(); 1115 sync_stats ();
1114 return; 1116 return;
1115 } 1117 }
1116 payload += delta; 1118 payload += delta;
1117 last_sync++; 1119 last_sync++;
1118 if (last_sync >= MAX_STAT_SYNC_LAG) 1120 if (last_sync >= MAX_STAT_SYNC_LAG)
1119 sync_stats(); 1121 sync_stats ();
1120} 1122}
1121 1123
1122 1124
@@ -1131,20 +1133,20 @@ disk_utilization_change_cb(void *cls, int delta)
1131 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration 1133 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
1132 */ 1134 */
1133static int 1135static int
1134process_stat_in(void *cls, 1136process_stat_in (void *cls,
1135 const char *subsystem, 1137 const char *subsystem,
1136 const char *name, 1138 const char *name,
1137 uint64_t value, 1139 uint64_t value,
1138 int is_persistent) 1140 int is_persistent)
1139{ 1141{
1140 GNUNET_assert(GNUNET_NO == stats_worked); 1142 GNUNET_assert (GNUNET_NO == stats_worked);
1141 stats_worked = GNUNET_YES; 1143 stats_worked = GNUNET_YES;
1142 payload += value; 1144 payload += value;
1143 GNUNET_log( 1145 GNUNET_log (
1144 GNUNET_ERROR_TYPE_DEBUG, 1146 GNUNET_ERROR_TYPE_DEBUG,
1145 "Notification from statistics about existing payload (%llu), new payload is %llu\n", 1147 "Notification from statistics about existing payload (%llu), new payload is %llu\n",
1146 (unsigned long long)value, 1148 (unsigned long long) value,
1147 (unsigned long long)payload); 1149 (unsigned long long) payload);
1148 return GNUNET_OK; 1150 return GNUNET_OK;
1149} 1151}
1150 1152
@@ -1153,32 +1155,32 @@ process_stat_in(void *cls,
1153 * Load the datastore plugin. 1155 * Load the datastore plugin.
1154 */ 1156 */
1155static struct DatastorePlugin * 1157static struct DatastorePlugin *
1156load_plugin() 1158load_plugin ()
1157{ 1159{
1158 struct DatastorePlugin *ret; 1160 struct DatastorePlugin *ret;
1159 char *libname; 1161 char *libname;
1160 1162
1161 ret = GNUNET_new(struct DatastorePlugin); 1163 ret = GNUNET_new (struct DatastorePlugin);
1162 ret->env.cfg = cfg; 1164 ret->env.cfg = cfg;
1163 ret->env.duc = &disk_utilization_change_cb; 1165 ret->env.duc = &disk_utilization_change_cb;
1164 ret->env.cls = NULL; 1166 ret->env.cls = NULL;
1165 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1167 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1166 _("Loading `%s' datastore plugin\n"), 1168 _ ("Loading `%s' datastore plugin\n"),
1167 plugin_name); 1169 plugin_name);
1168 GNUNET_asprintf(&libname, "libgnunet_plugin_datastore_%s", plugin_name); 1170 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", plugin_name);
1169 ret->short_name = GNUNET_strdup(plugin_name); 1171 ret->short_name = GNUNET_strdup (plugin_name);
1170 ret->lib_name = libname; 1172 ret->lib_name = libname;
1171 ret->api = GNUNET_PLUGIN_load(libname, &ret->env); 1173 ret->api = GNUNET_PLUGIN_load (libname, &ret->env);
1172 if (NULL == ret->api) 1174 if (NULL == ret->api)
1173 { 1175 {
1174 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1176 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1175 _("Failed to load datastore plugin for `%s'\n"), 1177 _ ("Failed to load datastore plugin for `%s'\n"),
1176 plugin_name); 1178 plugin_name);
1177 GNUNET_free(ret->short_name); 1179 GNUNET_free (ret->short_name);
1178 GNUNET_free(libname); 1180 GNUNET_free (libname);
1179 GNUNET_free(ret); 1181 GNUNET_free (ret);
1180 return NULL; 1182 return NULL;
1181 } 1183 }
1182 return ret; 1184 return ret;
1183} 1185}
1184 1186
@@ -1190,14 +1192,14 @@ load_plugin()
1190 * @param plug plugin to unload 1192 * @param plug plugin to unload
1191 */ 1193 */
1192static void 1194static void
1193unload_plugin(struct DatastorePlugin *plug) 1195unload_plugin (struct DatastorePlugin *plug)
1194{ 1196{
1195 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1196 "Datastore service is unloading plugin...\n"); 1198 "Datastore service is unloading plugin...\n");
1197 GNUNET_break(NULL == GNUNET_PLUGIN_unload(plug->lib_name, plug->api)); 1199 GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
1198 GNUNET_free(plug->lib_name); 1200 GNUNET_free (plug->lib_name);
1199 GNUNET_free(plug->short_name); 1201 GNUNET_free (plug->short_name);
1200 GNUNET_free(plug); 1202 GNUNET_free (plug);
1201} 1203}
1202 1204
1203 1205
@@ -1205,13 +1207,13 @@ unload_plugin(struct DatastorePlugin *plug)
1205 * Initialization complete, start operating the service. 1207 * Initialization complete, start operating the service.
1206 */ 1208 */
1207static void 1209static void
1208begin_service() 1210begin_service ()
1209{ 1211{
1210 GNUNET_SERVICE_resume(service); 1212 GNUNET_SERVICE_resume (service);
1211 expired_kill_task = 1213 expired_kill_task =
1212 GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_IDLE, 1214 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
1213 &delete_expired, 1215 &delete_expired,
1214 NULL); 1216 NULL);
1215} 1217}
1216 1218
1217 1219
@@ -1223,22 +1225,22 @@ begin_service()
1223 * @param count number of times to add key 1225 * @param count number of times to add key
1224 */ 1226 */
1225static void 1227static void
1226add_key_to_bloomfilter(void *cls, 1228add_key_to_bloomfilter (void *cls,
1227 const struct GNUNET_HashCode *key, 1229 const struct GNUNET_HashCode *key,
1228 unsigned int count) 1230 unsigned int count)
1229{ 1231{
1230 struct GNUNET_CONTAINER_BloomFilter *bf = cls; 1232 struct GNUNET_CONTAINER_BloomFilter *bf = cls;
1231 1233
1232 if (NULL == key) 1234 if (NULL == key)
1233 { 1235 {
1234 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1236 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1235 _("Bloomfilter construction complete.\n")); 1237 _ ("Bloomfilter construction complete.\n"));
1236 begin_service(); 1238 begin_service ();
1237 return; 1239 return;
1238 } 1240 }
1239 1241
1240 while (0 < count--) 1242 while (0 < count--)
1241 GNUNET_CONTAINER_bloomfilter_add(bf, key); 1243 GNUNET_CONTAINER_bloomfilter_add (bf, key);
1242} 1244}
1243 1245
1244 1246
@@ -1250,54 +1252,54 @@ add_key_to_bloomfilter(void *cls,
1250 * @param success #GNUNET_NO if we failed to read the stat 1252 * @param success #GNUNET_NO if we failed to read the stat
1251 */ 1253 */
1252static void 1254static void
1253process_stat_done(void *cls, int success) 1255process_stat_done (void *cls, int success)
1254{ 1256{
1255 stat_get = NULL; 1257 stat_get = NULL;
1256 if (NULL != stat_timeout_task) 1258 if (NULL != stat_timeout_task)
1257 { 1259 {
1258 GNUNET_SCHEDULER_cancel(stat_timeout_task); 1260 GNUNET_SCHEDULER_cancel (stat_timeout_task);
1259 stat_timeout_task = NULL; 1261 stat_timeout_task = NULL;
1260 } 1262 }
1261 plugin = load_plugin(); 1263 plugin = load_plugin ();
1262 if (NULL == plugin) 1264 if (NULL == plugin)
1265 {
1266 GNUNET_CONTAINER_bloomfilter_free (filter);
1267 filter = NULL;
1268 if (NULL != stats)
1263 { 1269 {
1264 GNUNET_CONTAINER_bloomfilter_free(filter); 1270 GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
1265 filter = NULL; 1271 stats = NULL;
1266 if (NULL != stats)
1267 {
1268 GNUNET_STATISTICS_destroy(stats, GNUNET_YES);
1269 stats = NULL;
1270 }
1271 return;
1272 } 1272 }
1273 return;
1274 }
1273 1275
1274 if (GNUNET_NO == stats_worked) 1276 if (GNUNET_NO == stats_worked)
1275 { 1277 {
1276 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1277 "Failed to obtain value from statistics service, recomputing it\n"); 1279 "Failed to obtain value from statistics service, recomputing it\n");
1278 plugin->api->estimate_size(plugin->api->cls, &payload); 1280 plugin->api->estimate_size (plugin->api->cls, &payload);
1279 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1281 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1280 _("New payload: %lld\n"), 1282 _ ("New payload: %lld\n"),
1281 (long long)payload); 1283 (long long) payload);
1282 } 1284 }
1283 1285
1284 if (GNUNET_YES == refresh_bf) 1286 if (GNUNET_YES == refresh_bf)
1287 {
1288 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1289 _ ("Rebuilding bloomfilter. Please be patient.\n"));
1290 if (NULL != plugin->api->get_keys)
1285 { 1291 {
1286 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1292 plugin->api->get_keys (plugin->api->cls, &add_key_to_bloomfilter, filter);
1287 _("Rebuilding bloomfilter. Please be patient.\n")); 1293 return;
1288 if (NULL != plugin->api->get_keys) 1294 }
1289 { 1295 else
1290 plugin->api->get_keys(plugin->api->cls, &add_key_to_bloomfilter, filter); 1296 {
1291 return; 1297 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1292 } 1298 _ (
1293 else 1299 "Plugin does not support get_keys function. Please fix!\n"));
1294 {
1295 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1296 _(
1297 "Plugin does not support get_keys function. Please fix!\n"));
1298 }
1299 } 1300 }
1300 begin_service(); 1301 }
1302 begin_service ();
1301} 1303}
1302 1304
1303 1305
@@ -1307,11 +1309,11 @@ process_stat_done(void *cls, int success)
1307 * @param cls NULL 1309 * @param cls NULL
1308 */ 1310 */
1309static void 1311static void
1310stat_timeout(void *cls) 1312stat_timeout (void *cls)
1311{ 1313{
1312 stat_timeout_task = NULL; 1314 stat_timeout_task = NULL;
1313 GNUNET_STATISTICS_get_cancel(stat_get); 1315 GNUNET_STATISTICS_get_cancel (stat_get);
1314 process_stat_done(NULL, GNUNET_NO); 1316 process_stat_done (NULL, GNUNET_NO);
1315} 1317}
1316 1318
1317 1319
@@ -1319,51 +1321,51 @@ stat_timeout(void *cls)
1319 * Task run during shutdown. 1321 * Task run during shutdown.
1320 */ 1322 */
1321static void 1323static void
1322cleaning_task(void *cls) 1324cleaning_task (void *cls)
1323{ 1325{
1324 cleaning_done = GNUNET_YES; 1326 cleaning_done = GNUNET_YES;
1325 if (NULL != expired_kill_task) 1327 if (NULL != expired_kill_task)
1326 { 1328 {
1327 GNUNET_SCHEDULER_cancel(expired_kill_task); 1329 GNUNET_SCHEDULER_cancel (expired_kill_task);
1328 expired_kill_task = NULL; 1330 expired_kill_task = NULL;
1329 } 1331 }
1330 if (GNUNET_YES == do_drop) 1332 if (GNUNET_YES == do_drop)
1331 { 1333 {
1332 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Dropping database!\n"); 1334 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dropping database!\n");
1333 plugin->api->drop(plugin->api->cls); 1335 plugin->api->drop (plugin->api->cls);
1334 payload = 0; 1336 payload = 0;
1335 last_sync++; 1337 last_sync++;
1336 } 1338 }
1337 if (NULL != plugin) 1339 if (NULL != plugin)
1338 { 1340 {
1339 unload_plugin(plugin); 1341 unload_plugin (plugin);
1340 plugin = NULL; 1342 plugin = NULL;
1341 } 1343 }
1342 if (NULL != filter) 1344 if (NULL != filter)
1343 { 1345 {
1344 GNUNET_CONTAINER_bloomfilter_free(filter); 1346 GNUNET_CONTAINER_bloomfilter_free (filter);
1345 filter = NULL; 1347 filter = NULL;
1346 } 1348 }
1347 if (NULL != stat_get) 1349 if (NULL != stat_get)
1348 { 1350 {
1349 GNUNET_STATISTICS_get_cancel(stat_get); 1351 GNUNET_STATISTICS_get_cancel (stat_get);
1350 stat_get = NULL; 1352 stat_get = NULL;
1351 } 1353 }
1352 if (NULL != stat_timeout_task) 1354 if (NULL != stat_timeout_task)
1353 { 1355 {
1354 GNUNET_SCHEDULER_cancel(stat_timeout_task); 1356 GNUNET_SCHEDULER_cancel (stat_timeout_task);
1355 stat_timeout_task = NULL; 1357 stat_timeout_task = NULL;
1356 } 1358 }
1357 GNUNET_free_non_null(plugin_name); 1359 GNUNET_free_non_null (plugin_name);
1358 plugin_name = NULL; 1360 plugin_name = NULL;
1359 if (last_sync > 0) 1361 if (last_sync > 0)
1360 sync_stats(); 1362 sync_stats ();
1361 if (NULL != stats) 1363 if (NULL != stats)
1362 { 1364 {
1363 GNUNET_STATISTICS_destroy(stats, GNUNET_YES); 1365 GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
1364 stats = NULL; 1366 stats = NULL;
1365 } 1367 }
1366 GNUNET_free(quota_stat_name); 1368 GNUNET_free (quota_stat_name);
1367 quota_stat_name = NULL; 1369 quota_stat_name = NULL;
1368} 1370}
1369 1371
@@ -1377,9 +1379,9 @@ cleaning_task(void *cls)
1377 * @return @a client 1379 * @return @a client
1378 */ 1380 */
1379static void * 1381static void *
1380client_connect_cb(void *cls, 1382client_connect_cb (void *cls,
1381 struct GNUNET_SERVICE_Client *client, 1383 struct GNUNET_SERVICE_Client *client,
1382 struct GNUNET_MQ_Handle *mq) 1384 struct GNUNET_MQ_Handle *mq)
1383{ 1385{
1384 return client; 1386 return client;
1385} 1387}
@@ -1394,39 +1396,39 @@ client_connect_cb(void *cls,
1394 * @param app_ctx must match @a client 1396 * @param app_ctx must match @a client
1395 */ 1397 */
1396static void 1398static void
1397client_disconnect_cb(void *cls, 1399client_disconnect_cb (void *cls,
1398 struct GNUNET_SERVICE_Client *client, 1400 struct GNUNET_SERVICE_Client *client,
1399 void *app_ctx) 1401 void *app_ctx)
1400{ 1402{
1401 struct ReservationList *pos; 1403 struct ReservationList *pos;
1402 struct ReservationList *prev; 1404 struct ReservationList *prev;
1403 struct ReservationList *next; 1405 struct ReservationList *next;
1404 1406
1405 GNUNET_assert(app_ctx == client); 1407 GNUNET_assert (app_ctx == client);
1406 prev = NULL; 1408 prev = NULL;
1407 pos = reservations; 1409 pos = reservations;
1408 while (NULL != pos) 1410 while (NULL != pos)
1411 {
1412 next = pos->next;
1413 if (pos->client == client)
1409 { 1414 {
1410 next = pos->next; 1415 if (NULL == prev)
1411 if (pos->client == client) 1416 reservations = next;
1412 {
1413 if (NULL == prev)
1414 reservations = next;
1415 else
1416 prev->next = next;
1417 reserved -= pos->amount + pos->entries * GNUNET_DATASTORE_ENTRY_OVERHEAD;
1418 GNUNET_free(pos);
1419 }
1420 else 1417 else
1421 { 1418 prev->next = next;
1422 prev = pos; 1419 reserved -= pos->amount + pos->entries * GNUNET_DATASTORE_ENTRY_OVERHEAD;
1423 } 1420 GNUNET_free (pos);
1424 pos = next;
1425 } 1421 }
1426 GNUNET_STATISTICS_set(stats, 1422 else
1427 gettext_noop("# reserved"), 1423 {
1428 reserved, 1424 prev = pos;
1429 GNUNET_NO); 1425 }
1426 pos = next;
1427 }
1428 GNUNET_STATISTICS_set (stats,
1429 gettext_noop ("# reserved"),
1430 reserved,
1431 GNUNET_NO);
1430} 1432}
1431 1433
1432 1434
@@ -1438,9 +1440,9 @@ client_disconnect_cb(void *cls,
1438 * @param c configuration to use 1440 * @param c configuration to use
1439 */ 1441 */
1440static void 1442static void
1441run(void *cls, 1443run (void *cls,
1442 const struct GNUNET_CONFIGURATION_Handle *c, 1444 const struct GNUNET_CONFIGURATION_Handle *c,
1443 struct GNUNET_SERVICE_Handle *serv) 1445 struct GNUNET_SERVICE_Handle *serv)
1444{ 1446{
1445 char *fn; 1447 char *fn;
1446 char *pfn; 1448 char *pfn;
@@ -1448,199 +1450,199 @@ run(void *cls,
1448 1450
1449 service = serv; 1451 service = serv;
1450 cfg = c; 1452 cfg = c;
1451 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, 1453 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
1452 "DATASTORE", 1454 "DATASTORE",
1453 "DATABASE", 1455 "DATABASE",
1454 &plugin_name)) 1456 &plugin_name))
1455 { 1457 {
1456 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, 1458 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1457 "DATABASE", 1459 "DATABASE",
1458 "DATASTORE"); 1460 "DATASTORE");
1459 return; 1461 return;
1460 } 1462 }
1461 GNUNET_asprintf(&quota_stat_name, 1463 GNUNET_asprintf (&quota_stat_name,
1462 _("# bytes used in file-sharing datastore `%s'"), 1464 _ ("# bytes used in file-sharing datastore `%s'"),
1463 plugin_name); 1465 plugin_name);
1464 if (GNUNET_OK != 1466 if (GNUNET_OK !=
1465 GNUNET_CONFIGURATION_get_value_size(cfg, "DATASTORE", "QUOTA", &quota)) 1467 GNUNET_CONFIGURATION_get_value_size (cfg, "DATASTORE", "QUOTA", &quota))
1466 { 1468 {
1467 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "QUOTA", "DATASTORE"); 1469 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "QUOTA", "DATASTORE");
1468 return; 1470 return;
1469 } 1471 }
1470 stats = GNUNET_STATISTICS_create("datastore", cfg); 1472 stats = GNUNET_STATISTICS_create ("datastore", cfg);
1471 GNUNET_STATISTICS_set(stats, gettext_noop("# quota"), quota, GNUNET_NO); 1473 GNUNET_STATISTICS_set (stats, gettext_noop ("# quota"), quota, GNUNET_NO);
1472 cache_size = quota / 8; /* Or should we make this an option? */ 1474 cache_size = quota / 8; /* Or should we make this an option? */
1473 GNUNET_STATISTICS_set(stats, 1475 GNUNET_STATISTICS_set (stats,
1474 gettext_noop("# cache size"), 1476 gettext_noop ("# cache size"),
1475 cache_size, 1477 cache_size,
1476 GNUNET_NO); 1478 GNUNET_NO);
1477 if (quota / (32 * 1024LL) > MAX_BF_SIZE) 1479 if (quota / (32 * 1024LL) > MAX_BF_SIZE)
1478 bf_size = MAX_BF_SIZE; 1480 bf_size = MAX_BF_SIZE;
1479 else 1481 else
1480 bf_size = 1482 bf_size =
1481 quota / (32 * 1024LL); /* 8 bit per entry, 1 bit per 32 kb in DB */ 1483 quota / (32 * 1024LL); /* 8 bit per entry, 1 bit per 32 kb in DB */
1482 fn = NULL; 1484 fn = NULL;
1483 if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(cfg, 1485 if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
1484 "DATASTORE", 1486 "DATASTORE",
1485 "BLOOMFILTER", 1487 "BLOOMFILTER",
1486 &fn)) || 1488 &fn)) ||
1487 (GNUNET_OK != GNUNET_DISK_directory_create_for_file(fn))) 1489 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)))
1488 { 1490 {
1489 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1491 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1490 _("Could not use specified filename `%s' for bloomfilter.\n"), 1492 _ ("Could not use specified filename `%s' for bloomfilter.\n"),
1491 NULL != fn ? fn : ""); 1493 NULL != fn ? fn : "");
1492 GNUNET_free_non_null(fn); 1494 GNUNET_free_non_null (fn);
1493 fn = NULL; 1495 fn = NULL;
1494 } 1496 }
1495 if (NULL != fn) 1497 if (NULL != fn)
1498 {
1499 GNUNET_asprintf (&pfn, "%s.%s", fn, plugin_name);
1500 if (GNUNET_YES == GNUNET_DISK_file_test (pfn))
1496 { 1501 {
1497 GNUNET_asprintf(&pfn, "%s.%s", fn, plugin_name); 1502 filter =
1498 if (GNUNET_YES == GNUNET_DISK_file_test(pfn)) 1503 GNUNET_CONTAINER_bloomfilter_load (pfn,
1504 bf_size,
1505 5); /* approx. 3% false positives at max use */
1506 if (NULL == filter)
1507 {
1508 /* file exists but not valid, remove and try again, but refresh */
1509 if (0 != unlink (pfn))
1499 { 1510 {
1500 filter = 1511 /* failed to remove, run without file */
1501 GNUNET_CONTAINER_bloomfilter_load(pfn, 1512 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1502 bf_size, 1513 _ ("Failed to remove bogus bloomfilter file `%s'\n"),
1503 5); /* approx. 3% false positives at max use */ 1514 pfn);
1504 if (NULL == filter) 1515 GNUNET_free (pfn);
1505 { 1516 pfn = NULL;
1506 /* file exists but not valid, remove and try again, but refresh */ 1517 filter = GNUNET_CONTAINER_bloomfilter_load (
1507 if (0 != unlink(pfn)) 1518 NULL,
1508 { 1519 bf_size,
1509 /* failed to remove, run without file */ 1520 5); /* approx. 3% false positives at max use */
1510 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1521 refresh_bf = GNUNET_YES;
1511 _("Failed to remove bogus bloomfilter file `%s'\n"),
1512 pfn);
1513 GNUNET_free(pfn);
1514 pfn = NULL;
1515 filter = GNUNET_CONTAINER_bloomfilter_load(
1516 NULL,
1517 bf_size,
1518 5); /* approx. 3% false positives at max use */
1519 refresh_bf = GNUNET_YES;
1520 }
1521 else
1522 {
1523 /* try again after remove */
1524 filter = GNUNET_CONTAINER_bloomfilter_load(
1525 pfn,
1526 bf_size,
1527 5); /* approx. 3% false positives at max use */
1528 refresh_bf = GNUNET_YES;
1529 if (NULL == filter)
1530 {
1531 /* failed yet again, give up on using file */
1532 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1533 _("Failed to remove bogus bloomfilter file `%s'\n"),
1534 pfn);
1535 GNUNET_free(pfn);
1536 pfn = NULL;
1537 filter = GNUNET_CONTAINER_bloomfilter_init(
1538 NULL,
1539 bf_size,
1540 5); /* approx. 3% false positives at max use */
1541 }
1542 }
1543 }
1544 else
1545 {
1546 /* normal case: have an existing valid bf file, no need to refresh */
1547 refresh_bf = GNUNET_NO;
1548 }
1549 } 1522 }
1550 else 1523 else
1551 { 1524 {
1552 filter = 1525 /* try again after remove */
1553 GNUNET_CONTAINER_bloomfilter_load(pfn, 1526 filter = GNUNET_CONTAINER_bloomfilter_load (
1554 bf_size, 1527 pfn,
1555 5); /* approx. 3% false positives at max use */ 1528 bf_size,
1529 5); /* approx. 3% false positives at max use */
1556 refresh_bf = GNUNET_YES; 1530 refresh_bf = GNUNET_YES;
1531 if (NULL == filter)
1532 {
1533 /* failed yet again, give up on using file */
1534 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1535 _ ("Failed to remove bogus bloomfilter file `%s'\n"),
1536 pfn);
1537 GNUNET_free (pfn);
1538 pfn = NULL;
1539 filter = GNUNET_CONTAINER_bloomfilter_init (
1540 NULL,
1541 bf_size,
1542 5); /* approx. 3% false positives at max use */
1543 }
1557 } 1544 }
1558 GNUNET_free(pfn); 1545 }
1546 else
1547 {
1548 /* normal case: have an existing valid bf file, no need to refresh */
1549 refresh_bf = GNUNET_NO;
1550 }
1559 } 1551 }
1560 else 1552 else
1561 { 1553 {
1562 filter = 1554 filter =
1563 GNUNET_CONTAINER_bloomfilter_init(NULL, 1555 GNUNET_CONTAINER_bloomfilter_load (pfn,
1564 bf_size, 1556 bf_size,
1565 5); /* approx. 3% false positives at max use */ 1557 5); /* approx. 3% false positives at max use */
1566 refresh_bf = GNUNET_YES; 1558 refresh_bf = GNUNET_YES;
1567 } 1559 }
1568 GNUNET_free_non_null(fn); 1560 GNUNET_free (pfn);
1561 }
1562 else
1563 {
1564 filter =
1565 GNUNET_CONTAINER_bloomfilter_init (NULL,
1566 bf_size,
1567 5); /* approx. 3% false positives at max use */
1568 refresh_bf = GNUNET_YES;
1569 }
1570 GNUNET_free_non_null (fn);
1569 if (NULL == filter) 1571 if (NULL == filter)
1572 {
1573 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1574 _ ("Failed to initialize bloomfilter.\n"));
1575 if (NULL != stats)
1570 { 1576 {
1571 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1577 GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
1572 _("Failed to initialize bloomfilter.\n")); 1578 stats = NULL;
1573 if (NULL != stats)
1574 {
1575 GNUNET_STATISTICS_destroy(stats, GNUNET_YES);
1576 stats = NULL;
1577 }
1578 return;
1579 } 1579 }
1580 GNUNET_SERVICE_suspend(service); 1580 return;
1581 stat_get = GNUNET_STATISTICS_get(stats, 1581 }
1582 "datastore", 1582 GNUNET_SERVICE_suspend (service);
1583 quota_stat_name, 1583 stat_get = GNUNET_STATISTICS_get (stats,
1584 &process_stat_done, 1584 "datastore",
1585 &process_stat_in, 1585 quota_stat_name,
1586 NULL); 1586 &process_stat_done,
1587 &process_stat_in,
1588 NULL);
1587 if (NULL == stat_get) 1589 if (NULL == stat_get)
1588 process_stat_done(NULL, GNUNET_SYSERR); 1590 process_stat_done (NULL, GNUNET_SYSERR);
1589 else 1591 else
1590 stat_timeout_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 1592 stat_timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
1591 &stat_timeout, 1593 &stat_timeout,
1592 NULL); 1594 NULL);
1593 GNUNET_SCHEDULER_add_shutdown(&cleaning_task, NULL); 1595 GNUNET_SCHEDULER_add_shutdown (&cleaning_task, NULL);
1594} 1596}
1595 1597
1596 1598
1597/** 1599/**
1598 * Define "main" method using service macro. 1600 * Define "main" method using service macro.
1599 */ 1601 */
1600GNUNET_SERVICE_MAIN( 1602GNUNET_SERVICE_MAIN (
1601 "datastore", 1603 "datastore",
1602 GNUNET_SERVICE_OPTION_NONE, 1604 GNUNET_SERVICE_OPTION_NONE,
1603 &run, 1605 &run,
1604 &client_connect_cb, 1606 &client_connect_cb,
1605 &client_disconnect_cb, 1607 &client_disconnect_cb,
1606 NULL, 1608 NULL,
1607 GNUNET_MQ_hd_fixed_size(reserve, 1609 GNUNET_MQ_hd_fixed_size (reserve,
1608 GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE, 1610 GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE,
1609 struct ReserveMessage, 1611 struct ReserveMessage,
1610 NULL), 1612 NULL),
1611 GNUNET_MQ_hd_fixed_size(release_reserve, 1613 GNUNET_MQ_hd_fixed_size (release_reserve,
1612 GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE, 1614 GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE,
1613 struct ReleaseReserveMessage, 1615 struct ReleaseReserveMessage,
1614 NULL), 1616 NULL),
1615 GNUNET_MQ_hd_var_size(put, 1617 GNUNET_MQ_hd_var_size (put,
1616 GNUNET_MESSAGE_TYPE_DATASTORE_PUT, 1618 GNUNET_MESSAGE_TYPE_DATASTORE_PUT,
1617 struct DataMessage, 1619 struct DataMessage,
1618 NULL), 1620 NULL),
1619 GNUNET_MQ_hd_fixed_size(get, 1621 GNUNET_MQ_hd_fixed_size (get,
1620 GNUNET_MESSAGE_TYPE_DATASTORE_GET, 1622 GNUNET_MESSAGE_TYPE_DATASTORE_GET,
1621 struct GetMessage, 1623 struct GetMessage,
1622 NULL), 1624 NULL),
1623 GNUNET_MQ_hd_fixed_size(get_key, 1625 GNUNET_MQ_hd_fixed_size (get_key,
1624 GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY, 1626 GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY,
1625 struct GetKeyMessage, 1627 struct GetKeyMessage,
1626 NULL), 1628 NULL),
1627 GNUNET_MQ_hd_fixed_size(get_replication, 1629 GNUNET_MQ_hd_fixed_size (get_replication,
1628 GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION, 1630 GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION,
1629 struct GNUNET_MessageHeader, 1631 struct GNUNET_MessageHeader,
1630 NULL), 1632 NULL),
1631 GNUNET_MQ_hd_fixed_size(get_zero_anonymity, 1633 GNUNET_MQ_hd_fixed_size (get_zero_anonymity,
1632 GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY, 1634 GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY,
1633 struct GetZeroAnonymityMessage, 1635 struct GetZeroAnonymityMessage,
1634 NULL), 1636 NULL),
1635 GNUNET_MQ_hd_var_size(remove, 1637 GNUNET_MQ_hd_var_size (remove,
1636 GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE, 1638 GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE,
1637 struct DataMessage, 1639 struct DataMessage,
1638 NULL), 1640 NULL),
1639 GNUNET_MQ_hd_fixed_size(drop, 1641 GNUNET_MQ_hd_fixed_size (drop,
1640 GNUNET_MESSAGE_TYPE_DATASTORE_DROP, 1642 GNUNET_MESSAGE_TYPE_DATASTORE_DROP,
1641 struct GNUNET_MessageHeader, 1643 struct GNUNET_MessageHeader,
1642 NULL), 1644 NULL),
1643 GNUNET_MQ_handler_end()); 1645 GNUNET_MQ_handler_end ());
1644 1646
1645 1647
1646/* end of gnunet-service-datastore.c */ 1648/* end of gnunet-service-datastore.c */
diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c
index e7eff0e6a..f353d0452 100644
--- a/src/datastore/perf_datastore_api.c
+++ b/src/datastore/perf_datastore_api.c
@@ -41,7 +41,7 @@
41/** 41/**
42 * How long until we give up on transmitting the message? 42 * How long until we give up on transmitting the message?
43 */ 43 */
44#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) 44#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
45 45
46/** 46/**
47 * Target datastore size (in bytes). 47 * Target datastore size (in bytes).
@@ -114,7 +114,8 @@ static int ok;
114/** 114/**
115 * Which phase of the process are we in? 115 * Which phase of the process are we in?
116 */ 116 */
117enum RunPhase { 117enum RunPhase
118{
118 /** 119 /**
119 * We are done (shutting down normally). 120 * We are done (shutting down normally).
120 */ 121 */
@@ -153,7 +154,8 @@ enum RunPhase {
153 * benchmark. Could right now be global, but this allows 154 * benchmark. Could right now be global, but this allows
154 * us to theoretically run multiple clients "in parallel". 155 * us to theoretically run multiple clients "in parallel".
155 */ 156 */
156struct CpsRunContext { 157struct CpsRunContext
158{
157 /** 159 /**
158 * Execution phase we are in. 160 * Execution phase we are in.
159 */ 161 */
@@ -186,7 +188,7 @@ struct CpsRunContext {
186 * @param cls the `struct CpsRunContext` 188 * @param cls the `struct CpsRunContext`
187 */ 189 */
188static void 190static void
189run_continuation(void *cls); 191run_continuation (void *cls);
190 192
191 193
192/** 194/**
@@ -201,57 +203,57 @@ run_continuation(void *cls);
201 * @param msg NULL on success, otherwise an error message 203 * @param msg NULL on success, otherwise an error message
202 */ 204 */
203static void 205static void
204check_success(void *cls, 206check_success (void *cls,
205 int success, 207 int success,
206 struct GNUNET_TIME_Absolute min_expiration, 208 struct GNUNET_TIME_Absolute min_expiration,
207 const char *msg) 209 const char *msg)
208{ 210{
209 struct CpsRunContext *crc = cls; 211 struct CpsRunContext *crc = cls;
210 212
211#if REPORT_ID 213#if REPORT_ID
212 fprintf(stderr, "%s", (GNUNET_OK == success) ? "I" : "i"); 214 fprintf (stderr, "%s", (GNUNET_OK == success) ? "I" : "i");
213#endif 215#endif
214 if (GNUNET_OK != success) 216 if (GNUNET_OK != success)
215 { 217 {
216 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 218 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
217 "Check success failed: `%s'\n", 219 "Check success failed: `%s'\n",
218 msg); 220 msg);
219 crc->phase = RP_ERROR; 221 crc->phase = RP_ERROR;
220 GNUNET_SCHEDULER_add_now(&run_continuation, 222 GNUNET_SCHEDULER_add_now (&run_continuation,
221 crc); 223 crc);
222 return; 224 return;
223 } 225 }
224 stored_bytes += crc->size; 226 stored_bytes += crc->size;
225 stored_ops++; 227 stored_ops++;
226 stored_entries++; 228 stored_entries++;
227 crc->j++; 229 crc->j++;
228 switch (crc->phase) 230 switch (crc->phase)
231 {
232 case RP_PUT:
233 if (crc->j >= PUT_10)
234 {
235 crc->j = 0;
236 crc->i++;
237 if (crc->i == ITERATIONS)
238 crc->phase = RP_PUT_QUOTA;
239 else
240 crc->phase = RP_CUT;
241 }
242 break;
243
244 case RP_PUT_QUOTA:
245 if (crc->j >= QUOTA_PUTS)
229 { 246 {
230 case RP_PUT: 247 crc->j = 0;
231 if (crc->j >= PUT_10) 248 crc->phase = RP_DONE;
232 {
233 crc->j = 0;
234 crc->i++;
235 if (crc->i == ITERATIONS)
236 crc->phase = RP_PUT_QUOTA;
237 else
238 crc->phase = RP_CUT;
239 }
240 break;
241
242 case RP_PUT_QUOTA:
243 if (crc->j >= QUOTA_PUTS)
244 {
245 crc->j = 0;
246 crc->phase = RP_DONE;
247 }
248 break;
249
250 default:
251 GNUNET_assert(0);
252 } 249 }
253 GNUNET_SCHEDULER_add_now(&run_continuation, 250 break;
254 crc); 251
252 default:
253 GNUNET_assert (0);
254 }
255 GNUNET_SCHEDULER_add_now (&run_continuation,
256 crc);
255} 257}
256 258
257 259
@@ -267,29 +269,29 @@ check_success(void *cls,
267 * @param msg NULL on success, otherwise an error message 269 * @param msg NULL on success, otherwise an error message
268 */ 270 */
269static void 271static void
270remove_next(void *cls, 272remove_next (void *cls,
271 int success, 273 int success,
272 struct GNUNET_TIME_Absolute min_expiration, 274 struct GNUNET_TIME_Absolute min_expiration,
273 const char *msg) 275 const char *msg)
274{ 276{
275 struct CpsRunContext *crc = cls; 277 struct CpsRunContext *crc = cls;
276 278
277 if (GNUNET_OK != success) 279 if (GNUNET_OK != success)
278 { 280 {
279 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 281 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
280 "remove_next failed: `%s'\n", 282 "remove_next failed: `%s'\n",
281 msg); 283 msg);
282 crc->phase = RP_ERROR; 284 crc->phase = RP_ERROR;
283 GNUNET_SCHEDULER_add_now(&run_continuation, 285 GNUNET_SCHEDULER_add_now (&run_continuation,
284 crc); 286 crc);
285 return; 287 return;
286 } 288 }
287#if REPORT_ID 289#if REPORT_ID
288 fprintf(stderr, "%s", "D"); 290 fprintf (stderr, "%s", "D");
289#endif 291#endif
290 GNUNET_assert(GNUNET_OK == success); 292 GNUNET_assert (GNUNET_OK == success);
291 GNUNET_SCHEDULER_add_now(&run_continuation, 293 GNUNET_SCHEDULER_add_now (&run_continuation,
292 crc); 294 crc);
293} 295}
294 296
295 297
@@ -309,32 +311,32 @@ remove_next(void *cls,
309 * maybe 0 if no unique identifier is available 311 * maybe 0 if no unique identifier is available
310 */ 312 */
311static void 313static void
312delete_value(void *cls, 314delete_value (void *cls,
313 const struct GNUNET_HashCode *key, 315 const struct GNUNET_HashCode *key,
314 size_t size, 316 size_t size,
315 const void *data, 317 const void *data,
316 enum GNUNET_BLOCK_Type type, 318 enum GNUNET_BLOCK_Type type,
317 uint32_t priority, 319 uint32_t priority,
318 uint32_t anonymity, 320 uint32_t anonymity,
319 uint32_t replication, 321 uint32_t replication,
320 struct GNUNET_TIME_Absolute expiration, 322 struct GNUNET_TIME_Absolute expiration,
321 uint64_t uid) 323 uint64_t uid)
322{ 324{
323 struct CpsRunContext *crc = cls; 325 struct CpsRunContext *crc = cls;
324 326
325 GNUNET_assert(NULL != key); 327 GNUNET_assert (NULL != key);
326 stored_ops++; 328 stored_ops++;
327 stored_bytes -= size; 329 stored_bytes -= size;
328 stored_entries--; 330 stored_entries--;
329 stored_ops++; 331 stored_ops++;
330 if (stored_bytes < MAX_SIZE) 332 if (stored_bytes < MAX_SIZE)
331 crc->phase = RP_PUT; 333 crc->phase = RP_PUT;
332 GNUNET_assert(NULL != 334 GNUNET_assert (NULL !=
333 GNUNET_DATASTORE_remove(datastore, 335 GNUNET_DATASTORE_remove (datastore,
334 key, 336 key,
335 size, 337 size,
336 data, 1, 1, 338 data, 1, 1,
337 &remove_next, crc)); 339 &remove_next, crc));
338} 340}
339 341
340 342
@@ -345,7 +347,7 @@ delete_value(void *cls,
345 * @param cls the `struct CpsRunContext` 347 * @param cls the `struct CpsRunContext`
346 */ 348 */
347static void 349static void
348run_continuation(void *cls) 350run_continuation (void *cls)
349{ 351{
350 struct CpsRunContext *crc = cls; 352 struct CpsRunContext *crc = cls;
351 size_t size; 353 size_t size;
@@ -353,34 +355,34 @@ run_continuation(void *cls)
353 static char data[65536]; 355 static char data[65536];
354 char gstr[128]; 356 char gstr[128];
355 357
356 ok = (int)crc->phase; 358 ok = (int) crc->phase;
357 switch (crc->phase) 359 switch (crc->phase)
358 { 360 {
359 case RP_PUT: 361 case RP_PUT:
360 memset(&key, 362 memset (&key,
361 256 - crc->i, 363 256 - crc->i,
362 sizeof(struct GNUNET_HashCode)); 364 sizeof(struct GNUNET_HashCode));
363 /* most content is 32k */ 365 /* most content is 32k */
364 size = 32 * 1024; 366 size = 32 * 1024;
365 if (0 == 367 if (0 ==
366 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 368 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
367 16)) /* but some of it is less! */ 369 16)) /* but some of it is less! */
368 size = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 370 size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
369 32 * 1024); 371 32 * 1024);
370 crc->size = size = size - (size & 7); /* always multiple of 8 */ 372 crc->size = size = size - (size & 7); /* always multiple of 8 */
371 GNUNET_CRYPTO_hash(&key, 373 GNUNET_CRYPTO_hash (&key,
372 sizeof(struct GNUNET_HashCode), 374 sizeof(struct GNUNET_HashCode),
373 &key); 375 &key);
374 memset(data, 376 memset (data,
375 (int)crc->j, 377 (int) crc->j,
376 size); 378 size);
377 if (crc->j > 255) 379 if (crc->j > 255)
378 memset(data, 380 memset (data,
379 (int)(crc->j - 255), 381 (int) (crc->j - 255),
380 size / 2); 382 size / 2);
381 data[0] = crc->i; 383 data[0] = crc->i;
382 GNUNET_assert(NULL != 384 GNUNET_assert (NULL !=
383 GNUNET_DATASTORE_put(datastore, 385 GNUNET_DATASTORE_put (datastore,
384 0, 386 0,
385 &key, 387 &key,
386 size, 388 size,
@@ -394,63 +396,64 @@ run_continuation(void *cls)
394 (GNUNET_TIME_relative_multiply 396 (GNUNET_TIME_relative_multiply
395 (GNUNET_TIME_UNIT_SECONDS, 397 (GNUNET_TIME_UNIT_SECONDS,
396 GNUNET_CRYPTO_random_u32 398 GNUNET_CRYPTO_random_u32
397 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), 399 (GNUNET_CRYPTO_QUALITY_WEAK,
400 1000))),
398 1, 401 1,
399 1, 402 1,
400 &check_success, crc)); 403 &check_success, crc));
401 break; 404 break;
402 405
403 case RP_CUT: 406 case RP_CUT:
404 /* trim down below MAX_SIZE again */ 407 /* trim down below MAX_SIZE again */
405 GNUNET_assert(NULL != 408 GNUNET_assert (NULL !=
406 GNUNET_DATASTORE_get_for_replication(datastore, 409 GNUNET_DATASTORE_get_for_replication (datastore,
407 1, 1, 410 1, 1,
408 &delete_value, 411 &delete_value,
409 crc)); 412 crc));
410 break; 413 break;
411 414
412 case RP_REPORT: 415 case RP_REPORT:
413 printf( 416 printf (
414#if REPORT_ID 417#if REPORT_ID
415 "\n" 418 "\n"
416#endif 419#endif
417 "Stored %llu kB / %lluk ops / %llu ops/s\n", 420 "Stored %llu kB / %lluk ops / %llu ops/s\n",
418 stored_bytes / 1024, /* used size in k */ 421 stored_bytes / 1024, /* used size in k */
419 stored_ops / 1024, /* total operations (in k) */ 422 stored_ops / 1024, /* total operations (in k) */
420 1000LL * 1000LL * stored_ops / (1 + 423 1000LL * 1000LL * stored_ops / (1
421 GNUNET_TIME_absolute_get_duration 424 + GNUNET_TIME_absolute_get_duration
422 (start_time).rel_value_us)); 425 (start_time).rel_value_us));
423 crc->phase = RP_PUT; 426 crc->phase = RP_PUT;
424 crc->j = 0; 427 crc->j = 0;
425 GNUNET_SCHEDULER_add_now(&run_continuation, 428 GNUNET_SCHEDULER_add_now (&run_continuation,
426 crc); 429 crc);
427 break; 430 break;
428 431
429 case RP_PUT_QUOTA: 432 case RP_PUT_QUOTA:
430 memset(&key, 433 memset (&key,
431 256 - crc->i, 434 256 - crc->i,
432 sizeof(struct GNUNET_HashCode)); 435 sizeof(struct GNUNET_HashCode));
433 /* most content is 32k */ 436 /* most content is 32k */
434 size = 32 * 1024; 437 size = 32 * 1024;
435 if (0 == 438 if (0 ==
436 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 439 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
437 16)) /* but some of it is less! */ 440 16)) /* but some of it is less! */
438 size = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 441 size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
439 32 * 1024); 442 32 * 1024);
440 crc->size = size = size - (size & 7); /* always multiple of 8 */ 443 crc->size = size = size - (size & 7); /* always multiple of 8 */
441 GNUNET_CRYPTO_hash(&key, 444 GNUNET_CRYPTO_hash (&key,
442 sizeof(struct GNUNET_HashCode), 445 sizeof(struct GNUNET_HashCode),
443 &key); 446 &key);
444 memset(data, 447 memset (data,
445 (int)crc->j, 448 (int) crc->j,
446 size); 449 size);
447 if (crc->j > 255) 450 if (crc->j > 255)
448 memset(data, 451 memset (data,
449 (int)(crc->j - 255), 452 (int) (crc->j - 255),
450 size / 2); 453 size / 2);
451 data[0] = crc->i; 454 data[0] = crc->i;
452 GNUNET_assert(NULL != 455 GNUNET_assert (NULL !=
453 GNUNET_DATASTORE_put(datastore, 456 GNUNET_DATASTORE_put (datastore,
454 0, /* reservation ID */ 457 0, /* reservation ID */
455 &key, 458 &key,
456 size, 459 size,
@@ -465,49 +468,53 @@ run_continuation(void *cls)
465 (GNUNET_TIME_relative_multiply 468 (GNUNET_TIME_relative_multiply
466 (GNUNET_TIME_UNIT_SECONDS, 469 (GNUNET_TIME_UNIT_SECONDS,
467 GNUNET_CRYPTO_random_u32 470 GNUNET_CRYPTO_random_u32
468 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), 471 (GNUNET_CRYPTO_QUALITY_WEAK,
472 1000))),
469 1, 473 1,
470 1, 474 1,
471 &check_success, crc)); 475 &check_success, crc));
472 break; 476 break;
473 477
474 case RP_DONE: 478 case RP_DONE:
475 GNUNET_snprintf(gstr, 479 GNUNET_snprintf (gstr,
476 sizeof(gstr), 480 sizeof(gstr),
477 "DATASTORE-%s", 481 "DATASTORE-%s",
478 plugin_name); 482 plugin_name);
479 if ((crc->i == ITERATIONS) && (stored_ops > 0)) 483 if ((crc->i == ITERATIONS) && (stored_ops > 0))
480 { 484 {
481 GAUGER(gstr, 485 GAUGER (gstr,
482 "PUT operation duration", 486 "PUT operation duration",
483 GNUNET_TIME_absolute_get_duration(start_time).rel_value_us / 1000LL / 487 GNUNET_TIME_absolute_get_duration (start_time).rel_value_us
484 stored_ops, 488 / 1000LL
485 "ms/operation"); 489 / stored_ops,
486 fprintf(stdout, 490 "ms/operation");
487 "\nPUT performance: %s for %llu operations\n", 491 fprintf (stdout,
488 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration(start_time), 492 "\nPUT performance: %s for %llu operations\n",
489 GNUNET_YES), 493 GNUNET_STRINGS_relative_time_to_string (
490 stored_ops); 494 GNUNET_TIME_absolute_get_duration (start_time),
491 fprintf(stdout, 495 GNUNET_YES),
492 "PUT performance: %llu ms/operation\n", 496 stored_ops);
493 GNUNET_TIME_absolute_get_duration(start_time).rel_value_us / 1000LL / 497 fprintf (stdout,
494 stored_ops); 498 "PUT performance: %llu ms/operation\n",
495 } 499 GNUNET_TIME_absolute_get_duration (start_time).rel_value_us
496 GNUNET_DATASTORE_disconnect(datastore, 500 / 1000LL
497 GNUNET_YES); 501 / stored_ops);
498 GNUNET_free(crc);
499 ok = 0;
500 break;
501
502 case RP_ERROR:
503 GNUNET_DATASTORE_disconnect(datastore, GNUNET_YES);
504 GNUNET_free(crc);
505 ok = 1;
506 break;
507
508 default:
509 GNUNET_assert(0);
510 } 502 }
503 GNUNET_DATASTORE_disconnect (datastore,
504 GNUNET_YES);
505 GNUNET_free (crc);
506 ok = 0;
507 break;
508
509 case RP_ERROR:
510 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
511 GNUNET_free (crc);
512 ok = 1;
513 break;
514
515 default:
516 GNUNET_assert (0);
517 }
511} 518}
512 519
513 520
@@ -524,25 +531,25 @@ run_continuation(void *cls)
524 * @param msg NULL on success, otherwise an error message 531 * @param msg NULL on success, otherwise an error message
525 */ 532 */
526static void 533static void
527run_tests(void *cls, 534run_tests (void *cls,
528 int success, 535 int success,
529 struct GNUNET_TIME_Absolute min_expiration, 536 struct GNUNET_TIME_Absolute min_expiration,
530 const char *msg) 537 const char *msg)
531{ 538{
532 struct CpsRunContext *crc = cls; 539 struct CpsRunContext *crc = cls;
533 540
534 if (success != GNUNET_YES) 541 if (success != GNUNET_YES)
535 { 542 {
536 fprintf(stderr, 543 fprintf (stderr,
537 "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", 544 "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n",
538 msg); 545 msg);
539 GNUNET_DATASTORE_disconnect(datastore, 546 GNUNET_DATASTORE_disconnect (datastore,
540 GNUNET_YES); 547 GNUNET_YES);
541 GNUNET_free(crc); 548 GNUNET_free (crc);
542 return; 549 return;
543 } 550 }
544 GNUNET_SCHEDULER_add_now(&run_continuation, 551 GNUNET_SCHEDULER_add_now (&run_continuation,
545 crc); 552 crc);
546} 553}
547 554
548 555
@@ -556,34 +563,35 @@ run_tests(void *cls,
556 * @param peer peer handle (unused) 563 * @param peer peer handle (unused)
557 */ 564 */
558static void 565static void
559run(void *cls, 566run (void *cls,
560 const struct GNUNET_CONFIGURATION_Handle *cfg, 567 const struct GNUNET_CONFIGURATION_Handle *cfg,
561 struct GNUNET_TESTING_Peer *peer) 568 struct GNUNET_TESTING_Peer *peer)
562{ 569{
563 struct CpsRunContext *crc; 570 struct CpsRunContext *crc;
564 static struct GNUNET_HashCode zkey; 571 static struct GNUNET_HashCode zkey;
565 572
566 datastore = GNUNET_DATASTORE_connect(cfg); 573 datastore = GNUNET_DATASTORE_connect (cfg);
567 start_time = GNUNET_TIME_absolute_get(); 574 start_time = GNUNET_TIME_absolute_get ();
568 crc = GNUNET_new(struct CpsRunContext); 575 crc = GNUNET_new (struct CpsRunContext);
569 crc->phase = RP_PUT; 576 crc->phase = RP_PUT;
570 if (NULL == 577 if (NULL ==
571 GNUNET_DATASTORE_put(datastore, 578 GNUNET_DATASTORE_put (datastore,
572 0, 579 0,
573 &zkey, 580 &zkey,
574 4, "TEST", 581 4, "TEST",
575 GNUNET_BLOCK_TYPE_TEST, 582 GNUNET_BLOCK_TYPE_TEST,
576 0, 0, 0, 583 0, 0, 0,
577 GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_SECONDS), 584 GNUNET_TIME_relative_to_absolute (
578 0, 1, 585 GNUNET_TIME_UNIT_SECONDS),
579 &run_tests, crc)) 586 0, 1,
580 { 587 &run_tests, crc))
581 fprintf(stderr, 588 {
582 "%s", 589 fprintf (stderr,
583 "Test 'put' operation failed.\n"); 590 "%s",
584 ok = 1; 591 "Test 'put' operation failed.\n");
585 GNUNET_free(crc); 592 ok = 1;
586 } 593 GNUNET_free (crc);
594 }
587} 595}
588 596
589 597
@@ -597,23 +605,23 @@ run(void *cls,
597 * @return 0 on success 605 * @return 0 on success
598 */ 606 */
599int 607int
600main(int argc, 608main (int argc,
601 char *argv[]) 609 char *argv[])
602{ 610{
603 char cfg_name[PATH_MAX]; 611 char cfg_name[PATH_MAX];
604 612
605 plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); 613 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
606 GNUNET_snprintf(cfg_name, 614 GNUNET_snprintf (cfg_name,
607 sizeof(cfg_name), 615 sizeof(cfg_name),
608 "test_datastore_api_data_%s.conf", 616 "test_datastore_api_data_%s.conf",
609 plugin_name); 617 plugin_name);
610 if (0 != 618 if (0 !=
611 GNUNET_TESTING_peer_run("perf-gnunet-datastore", 619 GNUNET_TESTING_peer_run ("perf-gnunet-datastore",
612 cfg_name, 620 cfg_name,
613 &run, 621 &run,
614 NULL)) 622 NULL))
615 return 1; 623 return 1;
616 fprintf(stderr, "%s", "\n"); 624 fprintf (stderr, "%s", "\n");
617 return ok; 625 return ok;
618} 626}
619 627
diff --git a/src/datastore/perf_plugin_datastore.c b/src/datastore/perf_plugin_datastore.c
index a051f27ca..a1604d441 100644
--- a/src/datastore/perf_plugin_datastore.c
+++ b/src/datastore/perf_plugin_datastore.c
@@ -59,7 +59,8 @@ static const char *plugin_name;
59 59
60static int ok; 60static int ok;
61 61
62enum RunPhase { 62enum RunPhase
63{
63 RP_ERROR = 0, 64 RP_ERROR = 0,
64 RP_PUT, 65 RP_PUT,
65 RP_REP_GET, 66 RP_REP_GET,
@@ -69,7 +70,8 @@ enum RunPhase {
69}; 70};
70 71
71 72
72struct CpsRunContext { 73struct CpsRunContext
74{
73 unsigned int i; 75 unsigned int i;
74 struct GNUNET_TIME_Absolute start; 76 struct GNUNET_TIME_Absolute start;
75 struct GNUNET_TIME_Absolute end; 77 struct GNUNET_TIME_Absolute end;
@@ -91,13 +93,13 @@ struct CpsRunContext {
91 * 0 for "reset to empty" 93 * 0 for "reset to empty"
92 */ 94 */
93static void 95static void
94disk_utilization_change_cb(void *cls, int delta) 96disk_utilization_change_cb (void *cls, int delta)
95{ 97{
96} 98}
97 99
98 100
99static void 101static void
100test(void *cls); 102test (void *cls);
101 103
102 104
103/** 105/**
@@ -110,30 +112,30 @@ test(void *cls);
110 * @param msg error message on error 112 * @param msg error message on error
111 */ 113 */
112static void 114static void
113put_continuation(void *cls, 115put_continuation (void *cls,
114 const struct GNUNET_HashCode *key, 116 const struct GNUNET_HashCode *key,
115 uint32_t size, 117 uint32_t size,
116 int status, 118 int status,
117 const char *msg) 119 const char *msg)
118{ 120{
119 struct CpsRunContext *crc = cls; 121 struct CpsRunContext *crc = cls;
120 122
121 if (GNUNET_OK != status) 123 if (GNUNET_OK != status)
122 { 124 {
123 fprintf(stderr, "ERROR: `%s'\n", msg); 125 fprintf (stderr, "ERROR: `%s'\n", msg);
124 } 126 }
125 else 127 else
126 { 128 {
127 stored_bytes += size; 129 stored_bytes += size;
128 stored_ops++; 130 stored_ops++;
129 stored_entries++; 131 stored_entries++;
130 } 132 }
131 GNUNET_SCHEDULER_add_now(&test, crc); 133 GNUNET_SCHEDULER_add_now (&test, crc);
132} 134}
133 135
134 136
135static void 137static void
136do_put(struct CpsRunContext *crc) 138do_put (struct CpsRunContext *crc)
137{ 139{
138 char value[65536]; 140 char value[65536];
139 size_t size; 141 size_t size;
@@ -142,123 +144,69 @@ do_put(struct CpsRunContext *crc)
142 unsigned int prio; 144 unsigned int prio;
143 145
144 if (0 == i) 146 if (0 == i)
145 crc->start = GNUNET_TIME_absolute_get(); 147 crc->start = GNUNET_TIME_absolute_get ();
146 if (PUT_10 == i) 148 if (PUT_10 == i)
149 {
150 i = 0;
151 crc->end = GNUNET_TIME_absolute_get ();
147 { 152 {
148 i = 0; 153 printf ("%s took %s for %llu items\n", "Storing an item",
149 crc->end = GNUNET_TIME_absolute_get(); 154 GNUNET_STRINGS_relative_time_to_string (
150 { 155 GNUNET_TIME_absolute_get_difference (crc->start,
151 printf("%s took %s for %llu items\n", "Storing an item", 156 crc
152 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_difference(crc->start, 157 ->end),
153 crc->end), 158 GNUNET_YES),
154 GNUNET_YES), 159 PUT_10);
155 PUT_10); 160 if (PUT_10 > 0)
156 if (PUT_10 > 0) 161 GAUGER (category, "Storing an item",
157 GAUGER(category, "Storing an item", 162 (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL
158 (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL / PUT_10, 163 / PUT_10,
159 "ms/item"); 164 "ms/item");
160 }
161 crc->i++;
162 crc->start = GNUNET_TIME_absolute_get();
163 crc->phase++;
164 GNUNET_SCHEDULER_add_now(&test, crc);
165 return;
166 } 165 }
166 crc->i++;
167 crc->start = GNUNET_TIME_absolute_get ();
168 crc->phase++;
169 GNUNET_SCHEDULER_add_now (&test, crc);
170 return;
171 }
167 /* most content is 32k */ 172 /* most content is 32k */
168 size = 32 * 1024; 173 size = 32 * 1024;
169 if (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */ 174 if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */
170 size = 8 + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024); 175 size = 8 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024);
171 size = size - (size & 7); /* always multiple of 8 */ 176 size = size - (size & 7); /* always multiple of 8 */
172 177
173 /* generate random key */ 178 /* generate random key */
174 key.bits[0] = (unsigned int)GNUNET_TIME_absolute_get().abs_value_us; 179 key.bits[0] = (unsigned int) GNUNET_TIME_absolute_get ().abs_value_us;
175 GNUNET_CRYPTO_hash(&key, sizeof(struct GNUNET_HashCode), &key); 180 GNUNET_CRYPTO_hash (&key, sizeof(struct GNUNET_HashCode), &key);
176 memset(value, i, size); 181 memset (value, i, size);
177 if (i > 255) 182 if (i > 255)
178 memset(value, i - 255, size / 2); 183 memset (value, i - 255, size / 2);
179 value[0] = crc->i; 184 value[0] = crc->i;
180 GNUNET_memcpy(&value[4], &i, sizeof(i)); 185 GNUNET_memcpy (&value[4], &i, sizeof(i));
181 prio = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 100); 186 prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
182 crc->api->put(crc->api->cls, 187 crc->api->put (crc->api->cls,
183 &key, 188 &key,
184 false /* absent */, 189 false /* absent */,
185 size, 190 size,
186 value, 191 value,
187 1 + i % 4 /* type */, 192 1 + i % 4 /* type */,
188 prio, 193 prio,
189 i % 4 /* anonymity */, 194 i % 4 /* anonymity */,
190 0 /* replication */, 195 0 /* replication */,
191 GNUNET_TIME_relative_to_absolute 196 GNUNET_TIME_relative_to_absolute
192 (GNUNET_TIME_relative_multiply 197 (GNUNET_TIME_relative_multiply
193 (GNUNET_TIME_UNIT_MILLISECONDS, 198 (GNUNET_TIME_UNIT_MILLISECONDS,
194 60 * 60 * 60 * 1000 + 199 60 * 60 * 60 * 1000
195 GNUNET_CRYPTO_random_u32 200 + GNUNET_CRYPTO_random_u32
196 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), 201 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))),
197 put_continuation, 202 put_continuation,
198 crc); 203 crc);
199 i++; 204 i++;
200} 205}
201 206
202 207
203static int 208static int
204iterate_zeros(void *cls, 209iterate_zeros (void *cls,
205 const struct GNUNET_HashCode *key,
206 uint32_t size,
207 const void *data,
208 enum GNUNET_BLOCK_Type type,
209 uint32_t priority,
210 uint32_t anonymity,
211 uint32_t replication,
212 struct GNUNET_TIME_Absolute expiration,
213 uint64_t uid)
214{
215 struct CpsRunContext *crc = cls;
216 int i;
217 const char *cdata = data;
218
219 GNUNET_assert(key != NULL);
220 GNUNET_assert(size >= 8);
221 GNUNET_memcpy(&i, &cdata[4], sizeof(i));
222 hits[i / 8] |= (1 << (i % 8));
223
224 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
225 "Found result %d type=%u, priority=%u, size=%u, expire=%s\n",
226 i,
227 type, priority, size,
228 GNUNET_STRINGS_absolute_time_to_string(expiration));
229 crc->cnt++;
230 if (crc->cnt == PUT_10 / 4 - 1)
231 {
232 unsigned int bc;
233
234 bc = 0;
235 for (i = 0; i < PUT_10; i++)
236 if (0 != (hits[i / 8] & (1 << (i % 8))))
237 bc++;
238
239 crc->end = GNUNET_TIME_absolute_get();
240 printf("%s took %s yielding %u/%u items\n",
241 "Select random zero-anonymity item",
242 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_difference(crc->start,
243 crc->end),
244 GNUNET_YES),
245 bc, crc->cnt);
246 if (crc->cnt > 0)
247 GAUGER(category, "Select random zero-anonymity item",
248 (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL / crc->cnt,
249 "ms/item");
250 memset(hits, 0, sizeof(hits));
251 crc->phase++;
252 crc->cnt = 0;
253 crc->start = GNUNET_TIME_absolute_get();
254 }
255 GNUNET_SCHEDULER_add_now(&test, crc);
256 return GNUNET_OK;
257}
258
259
260static int
261expiration_get(void *cls,
262 const struct GNUNET_HashCode *key, 210 const struct GNUNET_HashCode *key,
263 uint32_t size, 211 uint32_t size,
264 const void *data, 212 const void *data,
@@ -273,45 +221,52 @@ expiration_get(void *cls,
273 int i; 221 int i;
274 const char *cdata = data; 222 const char *cdata = data;
275 223
276 GNUNET_assert(size >= 8); 224 GNUNET_assert (key != NULL);
277 GNUNET_memcpy(&i, &cdata[4], sizeof(i)); 225 GNUNET_assert (size >= 8);
226 GNUNET_memcpy (&i, &cdata[4], sizeof(i));
278 hits[i / 8] |= (1 << (i % 8)); 227 hits[i / 8] |= (1 << (i % 8));
228
229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
230 "Found result %d type=%u, priority=%u, size=%u, expire=%s\n",
231 i,
232 type, priority, size,
233 GNUNET_STRINGS_absolute_time_to_string (expiration));
279 crc->cnt++; 234 crc->cnt++;
280 if (PUT_10 <= crc->cnt) 235 if (crc->cnt == PUT_10 / 4 - 1)
281 { 236 {
282 unsigned int bc; 237 unsigned int bc;
283 238
284 bc = 0; 239 bc = 0;
285 for (i = 0; i < PUT_10; i++) 240 for (i = 0; i < PUT_10; i++)
286 if (0 != (hits[i / 8] & (1 << (i % 8)))) 241 if (0 != (hits[i / 8] & (1 << (i % 8))))
287 bc++; 242 bc++;
288 243
289 crc->end = GNUNET_TIME_absolute_get(); 244 crc->end = GNUNET_TIME_absolute_get ();
290 printf("%s took %s yielding %u/%u items\n", 245 printf ("%s took %s yielding %u/%u items\n",
291 "Selecting and deleting by expiration", 246 "Select random zero-anonymity item",
292 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_difference(crc->start, 247 GNUNET_STRINGS_relative_time_to_string (
293 crc->end), 248 GNUNET_TIME_absolute_get_difference (crc->start,
294 GNUNET_YES), 249 crc
295 bc, (unsigned int)PUT_10); 250 ->end),
296 if (crc->cnt > 0) 251 GNUNET_YES),
297 GAUGER(category, "Selecting and deleting by expiration", 252 bc, crc->cnt);
298 (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL / crc->cnt, 253 if (crc->cnt > 0)
299 "ms/item"); 254 GAUGER (category, "Select random zero-anonymity item",
300 memset(hits, 0, sizeof(hits)); 255 (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL
301 if (++crc->iter == ITERATIONS) 256 / crc->cnt,
302 crc->phase++; 257 "ms/item");
303 else 258 memset (hits, 0, sizeof(hits));
304 crc->phase = RP_PUT; 259 crc->phase++;
305 crc->cnt = 0; 260 crc->cnt = 0;
306 crc->start = GNUNET_TIME_absolute_get(); 261 crc->start = GNUNET_TIME_absolute_get ();
307 } 262 }
308 GNUNET_SCHEDULER_add_now(&test, crc); 263 GNUNET_SCHEDULER_add_now (&test, crc);
309 return GNUNET_NO; 264 return GNUNET_OK;
310} 265}
311 266
312 267
313static int 268static int
314replication_get(void *cls, 269expiration_get (void *cls,
315 const struct GNUNET_HashCode *key, 270 const struct GNUNET_HashCode *key,
316 uint32_t size, 271 uint32_t size,
317 const void *data, 272 const void *data,
@@ -326,39 +281,98 @@ replication_get(void *cls,
326 int i; 281 int i;
327 const char *cdata = data; 282 const char *cdata = data;
328 283
329 GNUNET_assert(NULL != key); 284 GNUNET_assert (size >= 8);
330 GNUNET_assert(size >= 8); 285 GNUNET_memcpy (&i, &cdata[4], sizeof(i));
331 GNUNET_memcpy(&i, &cdata[4], sizeof(i));
332 hits[i / 8] |= (1 << (i % 8)); 286 hits[i / 8] |= (1 << (i % 8));
333 crc->cnt++; 287 crc->cnt++;
334 if (PUT_10 <= crc->cnt) 288 if (PUT_10 <= crc->cnt)
335 { 289 {
336 unsigned int bc; 290 unsigned int bc;
337 291
338 bc = 0; 292 bc = 0;
339 for (i = 0; i < PUT_10; i++) 293 for (i = 0; i < PUT_10; i++)
340 if (0 != (hits[i / 8] & (1 << (i % 8)))) 294 if (0 != (hits[i / 8] & (1 << (i % 8))))
341 bc++; 295 bc++;
342 296
343 crc->end = GNUNET_TIME_absolute_get(); 297 crc->end = GNUNET_TIME_absolute_get ();
344 printf("%s took %s yielding %u/%u items\n", 298 printf ("%s took %s yielding %u/%u items\n",
345 "Selecting random item for replication", 299 "Selecting and deleting by expiration",
346 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_difference(crc->start, 300 GNUNET_STRINGS_relative_time_to_string (
347 crc->end), 301 GNUNET_TIME_absolute_get_difference (crc->start,
348 GNUNET_YES), 302 crc
349 bc, (unsigned int)PUT_10); 303 ->end),
350 if (crc->cnt > 0) 304 GNUNET_YES),
351 GAUGER(category, "Selecting random item for replication", 305 bc, (unsigned int) PUT_10);
352 (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL / crc->cnt, 306 if (crc->cnt > 0)
353 "ms/item"); 307 GAUGER (category, "Selecting and deleting by expiration",
354 memset(hits, 0, sizeof(hits)); 308 (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL
309 / crc->cnt,
310 "ms/item");
311 memset (hits, 0, sizeof(hits));
312 if (++crc->iter == ITERATIONS)
355 crc->phase++; 313 crc->phase++;
356 crc->offset = 0; 314 else
357 crc->cnt = 0; 315 crc->phase = RP_PUT;
358 crc->start = GNUNET_TIME_absolute_get(); 316 crc->cnt = 0;
359 } 317 crc->start = GNUNET_TIME_absolute_get ();
318 }
319 GNUNET_SCHEDULER_add_now (&test, crc);
320 return GNUNET_NO;
321}
322
323
324static int
325replication_get (void *cls,
326 const struct GNUNET_HashCode *key,
327 uint32_t size,
328 const void *data,
329 enum GNUNET_BLOCK_Type type,
330 uint32_t priority,
331 uint32_t anonymity,
332 uint32_t replication,
333 struct GNUNET_TIME_Absolute expiration,
334 uint64_t uid)
335{
336 struct CpsRunContext *crc = cls;
337 int i;
338 const char *cdata = data;
360 339
361 GNUNET_SCHEDULER_add_now(&test, crc); 340 GNUNET_assert (NULL != key);
341 GNUNET_assert (size >= 8);
342 GNUNET_memcpy (&i, &cdata[4], sizeof(i));
343 hits[i / 8] |= (1 << (i % 8));
344 crc->cnt++;
345 if (PUT_10 <= crc->cnt)
346 {
347 unsigned int bc;
348
349 bc = 0;
350 for (i = 0; i < PUT_10; i++)
351 if (0 != (hits[i / 8] & (1 << (i % 8))))
352 bc++;
353
354 crc->end = GNUNET_TIME_absolute_get ();
355 printf ("%s took %s yielding %u/%u items\n",
356 "Selecting random item for replication",
357 GNUNET_STRINGS_relative_time_to_string (
358 GNUNET_TIME_absolute_get_difference (crc->start,
359 crc
360 ->end),
361 GNUNET_YES),
362 bc, (unsigned int) PUT_10);
363 if (crc->cnt > 0)
364 GAUGER (category, "Selecting random item for replication",
365 (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL
366 / crc->cnt,
367 "ms/item");
368 memset (hits, 0, sizeof(hits));
369 crc->phase++;
370 crc->offset = 0;
371 crc->cnt = 0;
372 crc->start = GNUNET_TIME_absolute_get ();
373 }
374
375 GNUNET_SCHEDULER_add_now (&test, crc);
362 return GNUNET_OK; 376 return GNUNET_OK;
363} 377}
364 378
@@ -371,25 +385,26 @@ replication_get(void *cls,
371 * @param cfg configuration to use 385 * @param cfg configuration to use
372 */ 386 */
373static void 387static void
374unload_plugin(struct GNUNET_DATASTORE_PluginFunctions *api, 388unload_plugin (struct GNUNET_DATASTORE_PluginFunctions *api,
375 const struct GNUNET_CONFIGURATION_Handle *cfg) 389 const struct GNUNET_CONFIGURATION_Handle *cfg)
376{ 390{
377 char *name; 391 char *name;
378 char *libname; 392 char *libname;
379 393
380 if (GNUNET_OK != 394 if (GNUNET_OK !=
381 GNUNET_CONFIGURATION_get_value_string(cfg, "DATASTORE", "DATABASE", 395 GNUNET_CONFIGURATION_get_value_string (cfg, "DATASTORE", "DATABASE",
382 &name)) 396 &name))
383 { 397 {
384 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 398 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
385 _("No `%s' specified for `%s' in configuration!\n"), "DATABASE", 399 _ ("No `%s' specified for `%s' in configuration!\n"),
386 "DATASTORE"); 400 "DATABASE",
387 return; 401 "DATASTORE");
388 } 402 return;
389 GNUNET_asprintf(&libname, "libgnunet_plugin_datastore_%s", name); 403 }
390 GNUNET_break(NULL == GNUNET_PLUGIN_unload(libname, api)); 404 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
391 GNUNET_free(libname); 405 GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api));
392 GNUNET_free(name); 406 GNUNET_free (libname);
407 GNUNET_free (name);
393} 408}
394 409
395 410
@@ -399,56 +414,56 @@ unload_plugin(struct GNUNET_DATASTORE_PluginFunctions *api,
399 * the transport and core. 414 * the transport and core.
400 */ 415 */
401static void 416static void
402cleaning_task(void *cls) 417cleaning_task (void *cls)
403{ 418{
404 struct CpsRunContext *crc = cls; 419 struct CpsRunContext *crc = cls;
405 420
406 unload_plugin(crc->api, crc->cfg); 421 unload_plugin (crc->api, crc->cfg);
407 GNUNET_free(crc); 422 GNUNET_free (crc);
408} 423}
409 424
410 425
411static void 426static void
412test(void *cls) 427test (void *cls)
413{ 428{
414 struct CpsRunContext *crc = cls; 429 struct CpsRunContext *crc = cls;
415 430
416 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 431 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
417 "In phase %d, iteration %u\n", crc->phase, crc->cnt); 432 "In phase %d, iteration %u\n", crc->phase, crc->cnt);
418 switch (crc->phase) 433 switch (crc->phase)
419 { 434 {
420 case RP_ERROR: 435 case RP_ERROR:
421 GNUNET_break(0); 436 GNUNET_break (0);
422 crc->api->drop(crc->api->cls); 437 crc->api->drop (crc->api->cls);
423 ok = 1; 438 ok = 1;
424 GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_IDLE, 439 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
425 &cleaning_task, crc); 440 &cleaning_task, crc);
426 break; 441 break;
427 442
428 case RP_PUT: 443 case RP_PUT:
429 do_put(crc); 444 do_put (crc);
430 break; 445 break;
431 446
432 case RP_REP_GET: 447 case RP_REP_GET:
433 crc->api->get_replication(crc->api->cls, &replication_get, crc); 448 crc->api->get_replication (crc->api->cls, &replication_get, crc);
434 break; 449 break;
435 450
436 case RP_ZA_GET: 451 case RP_ZA_GET:
437 crc->api->get_zero_anonymity(crc->api->cls, crc->offset++, 1, 452 crc->api->get_zero_anonymity (crc->api->cls, crc->offset++, 1,
438 &iterate_zeros, crc); 453 &iterate_zeros, crc);
439 break; 454 break;
440 455
441 case RP_EXP_GET: 456 case RP_EXP_GET:
442 crc->api->get_expiration(crc->api->cls, &expiration_get, crc); 457 crc->api->get_expiration (crc->api->cls, &expiration_get, crc);
443 break; 458 break;
444 459
445 case RP_DONE: 460 case RP_DONE:
446 crc->api->drop(crc->api->cls); 461 crc->api->drop (crc->api->cls);
447 ok = 0; 462 ok = 0;
448 GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_IDLE, 463 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
449 &cleaning_task, crc); 464 &cleaning_task, crc);
450 break; 465 break;
451 } 466 }
452} 467}
453 468
454 469
@@ -456,7 +471,7 @@ test(void *cls)
456 * Load the datastore plugin. 471 * Load the datastore plugin.
457 */ 472 */
458static struct GNUNET_DATASTORE_PluginFunctions * 473static struct GNUNET_DATASTORE_PluginFunctions *
459load_plugin(const struct GNUNET_CONFIGURATION_Handle *cfg) 474load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
460{ 475{
461 static struct GNUNET_DATASTORE_PluginEnvironment env; 476 static struct GNUNET_DATASTORE_PluginEnvironment env;
462 struct GNUNET_DATASTORE_PluginFunctions *ret; 477 struct GNUNET_DATASTORE_PluginFunctions *ret;
@@ -464,63 +479,65 @@ load_plugin(const struct GNUNET_CONFIGURATION_Handle *cfg)
464 char *libname; 479 char *libname;
465 480
466 if (GNUNET_OK != 481 if (GNUNET_OK !=
467 GNUNET_CONFIGURATION_get_value_string(cfg, "DATASTORE", "DATABASE", 482 GNUNET_CONFIGURATION_get_value_string (cfg, "DATASTORE", "DATABASE",
468 &name)) 483 &name))
469 { 484 {
470 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 485 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
471 _("No `%s' specified for `%s' in configuration!\n"), "DATABASE", 486 _ ("No `%s' specified for `%s' in configuration!\n"),
472 "DATASTORE"); 487 "DATABASE",
473 return NULL; 488 "DATASTORE");
474 } 489 return NULL;
490 }
475 env.cfg = cfg; 491 env.cfg = cfg;
476 env.duc = &disk_utilization_change_cb; 492 env.duc = &disk_utilization_change_cb;
477 env.cls = NULL; 493 env.cls = NULL;
478 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Loading `%s' datastore plugin\n"), 494 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Loading `%s' datastore plugin\n"),
479 name); 495 name);
480 GNUNET_asprintf(&libname, "libgnunet_plugin_datastore_%s", name); 496 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
481 if (NULL == (ret = GNUNET_PLUGIN_load(libname, &env))) 497 if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env)))
482 { 498 {
483 fprintf(stderr, "Failed to load plugin `%s'!\n", name); 499 fprintf (stderr, "Failed to load plugin `%s'!\n", name);
484 GNUNET_free(name); 500 GNUNET_free (name);
485 GNUNET_free(libname); 501 GNUNET_free (libname);
486 return NULL; 502 return NULL;
487 } 503 }
488 GNUNET_free(libname); 504 GNUNET_free (libname);
489 GNUNET_free(name); 505 GNUNET_free (name);
490 return ret; 506 return ret;
491} 507}
492 508
493 509
494static void 510static void
495run(void *cls, char *const *args, const char *cfgfile, 511run (void *cls, char *const *args, const char *cfgfile,
496 const struct GNUNET_CONFIGURATION_Handle *c) 512 const struct GNUNET_CONFIGURATION_Handle *c)
497{ 513{
498 struct GNUNET_DATASTORE_PluginFunctions *api; 514 struct GNUNET_DATASTORE_PluginFunctions *api;
499 struct CpsRunContext *crc; 515 struct CpsRunContext *crc;
500 516
501 if (NULL == c) 517 if (NULL == c)
502 { 518 {
503 GNUNET_break(0); 519 GNUNET_break (0);
504 return; 520 return;
505 } 521 }
506 api = load_plugin(c); 522 api = load_plugin (c);
507 if (api == NULL) 523 if (api == NULL)
508 { 524 {
509 fprintf(stderr, 525 fprintf (stderr,
510 "%s", "Could not initialize plugin, assuming database not configured. Test not run!\n"); 526 "%s",
511 return; 527 "Could not initialize plugin, assuming database not configured. Test not run!\n");
512 } 528 return;
513 crc = GNUNET_new(struct CpsRunContext); 529 }
530 crc = GNUNET_new (struct CpsRunContext);
514 crc->api = api; 531 crc->api = api;
515 crc->cfg = c; 532 crc->cfg = c;
516 crc->phase = RP_PUT; 533 crc->phase = RP_PUT;
517 ok = 2; 534 ok = 2;
518 GNUNET_SCHEDULER_add_now(&test, crc); 535 GNUNET_SCHEDULER_add_now (&test, crc);
519} 536}
520 537
521 538
522int 539int
523main(int argc, char *argv[]) 540main (int argc, char *argv[])
524{ 541{
525 char dir_name[PATH_MAX]; 542 char dir_name[PATH_MAX];
526 char cfg_name[PATH_MAX]; 543 char cfg_name[PATH_MAX];
@@ -534,21 +551,21 @@ main(int argc, char *argv[])
534 GNUNET_GETOPT_OPTION_END 551 GNUNET_GETOPT_OPTION_END
535 }; 552 };
536 553
537 plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); 554 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
538 GNUNET_snprintf(dir_name, sizeof(dir_name), "/tmp/perf-gnunet-datastore-%s", 555 GNUNET_snprintf (dir_name, sizeof(dir_name), "/tmp/perf-gnunet-datastore-%s",
539 plugin_name); 556 plugin_name);
540 GNUNET_DISK_directory_remove(dir_name); 557 GNUNET_DISK_directory_remove (dir_name);
541 GNUNET_log_setup("perf-plugin-datastore", 558 GNUNET_log_setup ("perf-plugin-datastore",
542 "WARNING", 559 "WARNING",
543 NULL); 560 NULL);
544 GNUNET_snprintf(category, sizeof(category), "DATASTORE-%s", plugin_name); 561 GNUNET_snprintf (category, sizeof(category), "DATASTORE-%s", plugin_name);
545 GNUNET_snprintf(cfg_name, sizeof(cfg_name), 562 GNUNET_snprintf (cfg_name, sizeof(cfg_name),
546 "perf_plugin_datastore_data_%s.conf", plugin_name); 563 "perf_plugin_datastore_data_%s.conf", plugin_name);
547 GNUNET_PROGRAM_run((sizeof(xargv) / sizeof(char *)) - 1, xargv, 564 GNUNET_PROGRAM_run ((sizeof(xargv) / sizeof(char *)) - 1, xargv,
548 "perf-plugin-datastore", "nohelp", options, &run, NULL); 565 "perf-plugin-datastore", "nohelp", options, &run, NULL);
549 if (ok != 0) 566 if (ok != 0)
550 fprintf(stderr, "Missed some testcases: %u\n", ok); 567 fprintf (stderr, "Missed some testcases: %u\n", ok);
551 GNUNET_DISK_directory_remove(dir_name); 568 GNUNET_DISK_directory_remove (dir_name);
552 569
553 return ok; 570 return ok;
554} 571}
diff --git a/src/datastore/plugin_datastore_heap.c b/src/datastore/plugin_datastore_heap.c
index b7d73f0c4..4e48bfd4c 100644
--- a/src/datastore/plugin_datastore_heap.c
+++ b/src/datastore/plugin_datastore_heap.c
@@ -34,7 +34,8 @@
34/** 34/**
35 * A value that we are storing. 35 * A value that we are storing.
36 */ 36 */
37struct Value { 37struct Value
38{
38 /** 39 /**
39 * Key for the value. 40 * Key for the value.
40 */ 41 */
@@ -96,7 +97,8 @@ struct Value {
96/** 97/**
97 * We organize 0-anonymity values in arrays "by type". 98 * We organize 0-anonymity values in arrays "by type".
98 */ 99 */
99struct ZeroAnonByType { 100struct ZeroAnonByType
101{
100 /** 102 /**
101 * We keep these in a DLL. 103 * We keep these in a DLL.
102 */ 104 */
@@ -132,7 +134,8 @@ struct ZeroAnonByType {
132/** 134/**
133 * Context for all functions in this plugin. 135 * Context for all functions in this plugin.
134 */ 136 */
135struct Plugin { 137struct Plugin
138{
136 /** 139 /**
137 * Our execution environment. 140 * Our execution environment.
138 */ 141 */
@@ -178,7 +181,7 @@ struct Plugin {
178 * @return number of bytes used on disk 181 * @return number of bytes used on disk
179 */ 182 */
180static void 183static void
181heap_plugin_estimate_size(void *cls, unsigned long long *estimate) 184heap_plugin_estimate_size (void *cls, unsigned long long *estimate)
182{ 185{
183 struct Plugin *plugin = cls; 186 struct Plugin *plugin = cls;
184 187
@@ -190,7 +193,8 @@ heap_plugin_estimate_size(void *cls, unsigned long long *estimate)
190/** 193/**
191 * Closure for iterator for updating. 194 * Closure for iterator for updating.
192 */ 195 */
193struct UpdateContext { 196struct UpdateContext
197{
194 /** 198 /**
195 * Number of bytes in 'data'. 199 * Number of bytes in 'data'.
196 */ 200 */
@@ -232,25 +236,25 @@ struct UpdateContext {
232 * @return GNUNET_YES (continue iteration), GNUNET_NO if value was found 236 * @return GNUNET_YES (continue iteration), GNUNET_NO if value was found
233 */ 237 */
234static int 238static int
235update_iterator(void *cls, 239update_iterator (void *cls,
236 const struct GNUNET_HashCode *key, 240 const struct GNUNET_HashCode *key,
237 void *val) 241 void *val)
238{ 242{
239 struct UpdateContext *uc = cls; 243 struct UpdateContext *uc = cls;
240 struct Value *value = val; 244 struct Value *value = val;
241 245
242 if (value->size != uc->size) 246 if (value->size != uc->size)
243 return GNUNET_YES; 247 return GNUNET_YES;
244 if (0 != memcmp(value->data, uc->data, uc->size)) 248 if (0 != memcmp (value->data, uc->data, uc->size))
245 return GNUNET_YES; 249 return GNUNET_YES;
246 uc->expiration = GNUNET_TIME_absolute_max(value->expiration, 250 uc->expiration = GNUNET_TIME_absolute_max (value->expiration,
247 uc->expiration); 251 uc->expiration);
248 if (value->expiration.abs_value_us != uc->expiration.abs_value_us) 252 if (value->expiration.abs_value_us != uc->expiration.abs_value_us)
249 { 253 {
250 value->expiration = uc->expiration; 254 value->expiration = uc->expiration;
251 GNUNET_CONTAINER_heap_update_cost(value->expire_heap, 255 GNUNET_CONTAINER_heap_update_cost (value->expire_heap,
252 value->expiration.abs_value_us); 256 value->expiration.abs_value_us);
253 } 257 }
254 /* Saturating adds, don't overflow */ 258 /* Saturating adds, don't overflow */
255 if (value->priority > UINT32_MAX - uc->priority) 259 if (value->priority > UINT32_MAX - uc->priority)
256 value->priority = UINT32_MAX; 260 value->priority = UINT32_MAX;
@@ -281,88 +285,89 @@ update_iterator(void *cls,
281 * @param cont_cls continuation closure 285 * @param cont_cls continuation closure
282 */ 286 */
283static void 287static void
284heap_plugin_put(void *cls, 288heap_plugin_put (void *cls,
285 const struct GNUNET_HashCode *key, 289 const struct GNUNET_HashCode *key,
286 bool absent, 290 bool absent,
287 uint32_t size, 291 uint32_t size,
288 const void *data, 292 const void *data,
289 enum GNUNET_BLOCK_Type type, 293 enum GNUNET_BLOCK_Type type,
290 uint32_t priority, 294 uint32_t priority,
291 uint32_t anonymity, 295 uint32_t anonymity,
292 uint32_t replication, 296 uint32_t replication,
293 struct GNUNET_TIME_Absolute expiration, 297 struct GNUNET_TIME_Absolute expiration,
294 PluginPutCont cont, 298 PluginPutCont cont,
295 void *cont_cls) 299 void *cont_cls)
296{ 300{
297 struct Plugin *plugin = cls; 301 struct Plugin *plugin = cls;
298 struct Value *value; 302 struct Value *value;
299 303
300 if (!absent) 304 if (! absent)
305 {
306 struct UpdateContext uc;
307
308 uc.size = size;
309 uc.data = data;
310 uc.priority = priority;
311 uc.replication = replication;
312 uc.expiration = expiration;
313 uc.updated = false;
314 GNUNET_CONTAINER_multihashmap_get_multiple (plugin->keyvalue,
315 key,
316 &update_iterator,
317 &uc);
318 if (uc.updated)
301 { 319 {
302 struct UpdateContext uc; 320 cont (cont_cls, key, size, GNUNET_NO, NULL);
303 321 return;
304 uc.size = size;
305 uc.data = data;
306 uc.priority = priority;
307 uc.replication = replication;
308 uc.expiration = expiration;
309 uc.updated = false;
310 GNUNET_CONTAINER_multihashmap_get_multiple(plugin->keyvalue,
311 key,
312 &update_iterator,
313 &uc);
314 if (uc.updated)
315 {
316 cont(cont_cls, key, size, GNUNET_NO, NULL);
317 return;
318 }
319 } 322 }
320 value = GNUNET_malloc(sizeof(struct Value) + size); 323 }
324 value = GNUNET_malloc (sizeof(struct Value) + size);
321 value->key = *key; 325 value->key = *key;
322 value->data = &value[1]; 326 value->data = &value[1];
323 value->expire_heap = GNUNET_CONTAINER_heap_insert(plugin->by_expiration, 327 value->expire_heap = GNUNET_CONTAINER_heap_insert (plugin->by_expiration,
324 value, 328 value,
325 expiration.abs_value_us); 329 expiration.abs_value_us);
326 value->replication_heap = GNUNET_CONTAINER_heap_insert(plugin->by_replication, 330 value->replication_heap = GNUNET_CONTAINER_heap_insert (
327 value, 331 plugin->by_replication,
328 replication); 332 value,
333 replication);
329 value->expiration = expiration; 334 value->expiration = expiration;
330 if (0 == anonymity) 335 if (0 == anonymity)
336 {
337 struct ZeroAnonByType *zabt;
338
339 for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next)
340 if (zabt->type == type)
341 break;
342 if (NULL == zabt)
331 { 343 {
332 struct ZeroAnonByType *zabt; 344 zabt = GNUNET_new (struct ZeroAnonByType);
333 345 zabt->type = type;
334 for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next) 346 GNUNET_CONTAINER_DLL_insert (plugin->zero_head,
335 if (zabt->type == type) 347 plugin->zero_tail,
336 break; 348 zabt);
337 if (NULL == zabt)
338 {
339 zabt = GNUNET_new(struct ZeroAnonByType);
340 zabt->type = type;
341 GNUNET_CONTAINER_DLL_insert(plugin->zero_head,
342 plugin->zero_tail,
343 zabt);
344 }
345 if (zabt->array_size == zabt->array_pos)
346 {
347 GNUNET_array_grow(zabt->array,
348 zabt->array_size,
349 zabt->array_size * 2 + 4);
350 }
351 value->zero_anon_offset = zabt->array_pos;
352 zabt->array[zabt->array_pos++] = value;
353 } 349 }
350 if (zabt->array_size == zabt->array_pos)
351 {
352 GNUNET_array_grow (zabt->array,
353 zabt->array_size,
354 zabt->array_size * 2 + 4);
355 }
356 value->zero_anon_offset = zabt->array_pos;
357 zabt->array[zabt->array_pos++] = value;
358 }
354 value->size = size; 359 value->size = size;
355 value->priority = priority; 360 value->priority = priority;
356 value->anonymity = anonymity; 361 value->anonymity = anonymity;
357 value->replication = replication; 362 value->replication = replication;
358 value->type = type; 363 value->type = type;
359 GNUNET_memcpy(&value[1], data, size); 364 GNUNET_memcpy (&value[1], data, size);
360 GNUNET_CONTAINER_multihashmap_put(plugin->keyvalue, 365 GNUNET_CONTAINER_multihashmap_put (plugin->keyvalue,
361 &value->key, 366 &value->key,
362 value, 367 value,
363 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 368 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
364 plugin->size += size; 369 plugin->size += size;
365 cont(cont_cls, key, size, GNUNET_OK, NULL); 370 cont (cont_cls, key, size, GNUNET_OK, NULL);
366} 371}
367 372
368 373
@@ -374,45 +379,49 @@ heap_plugin_put(void *cls,
374 * @param value value to delete 379 * @param value value to delete
375 */ 380 */
376static void 381static void
377delete_value(struct Plugin *plugin, 382delete_value (struct Plugin *plugin,
378 struct Value *value) 383 struct Value *value)
379{ 384{
380 GNUNET_assert(GNUNET_YES == 385 GNUNET_assert (GNUNET_YES ==
381 GNUNET_CONTAINER_multihashmap_remove(plugin->keyvalue, 386 GNUNET_CONTAINER_multihashmap_remove (plugin->keyvalue,
382 &value->key, 387 &value->key,
383 value)); 388 value));
384 GNUNET_assert(value == GNUNET_CONTAINER_heap_remove_node(value->expire_heap)); 389 GNUNET_assert (value == GNUNET_CONTAINER_heap_remove_node (
385 GNUNET_assert(value == GNUNET_CONTAINER_heap_remove_node(value->replication_heap)); 390 value->expire_heap));
391 GNUNET_assert (value == GNUNET_CONTAINER_heap_remove_node (
392 value->replication_heap));
386 if (0 == value->anonymity) 393 if (0 == value->anonymity)
394 {
395 struct ZeroAnonByType *zabt;
396
397 for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next)
398 if (zabt->type == value->type)
399 break;
400 GNUNET_assert (NULL != zabt);
401 zabt->array[value->zero_anon_offset] = zabt->array[--zabt->array_pos];
402 zabt->array[value->zero_anon_offset]->zero_anon_offset =
403 value->zero_anon_offset;
404 if (0 == zabt->array_pos)
387 { 405 {
388 struct ZeroAnonByType *zabt; 406 GNUNET_array_grow (zabt->array,
389 407 zabt->array_size,
390 for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next) 408 0);
391 if (zabt->type == value->type) 409 GNUNET_CONTAINER_DLL_remove (plugin->zero_head,
392 break; 410 plugin->zero_tail,
393 GNUNET_assert(NULL != zabt); 411 zabt);
394 zabt->array[value->zero_anon_offset] = zabt->array[--zabt->array_pos]; 412 GNUNET_free (zabt);
395 zabt->array[value->zero_anon_offset]->zero_anon_offset = value->zero_anon_offset;
396 if (0 == zabt->array_pos)
397 {
398 GNUNET_array_grow(zabt->array,
399 zabt->array_size,
400 0);
401 GNUNET_CONTAINER_DLL_remove(plugin->zero_head,
402 plugin->zero_tail,
403 zabt);
404 GNUNET_free(zabt);
405 }
406 } 413 }
414 }
407 plugin->size -= value->size; 415 plugin->size -= value->size;
408 GNUNET_free(value); 416 GNUNET_free (value);
409} 417}
410 418
411 419
412/** 420/**
413 * Closure for iterator called during 'get_key'. 421 * Closure for iterator called during 'get_key'.
414 */ 422 */
415struct GetContext { 423struct GetContext
424{
416 /** 425 /**
417 * Lowest uid to consider. 426 * Lowest uid to consider.
418 */ 427 */
@@ -444,9 +453,9 @@ struct GetContext {
444 * @return GNUNET_YES (continue iteration), GNUNET_NO if result was found 453 * @return GNUNET_YES (continue iteration), GNUNET_NO if result was found
445 */ 454 */
446static int 455static int
447get_iterator(void *cls, 456get_iterator (void *cls,
448 const struct GNUNET_HashCode *key, 457 const struct GNUNET_HashCode *key,
449 void *val) 458 void *val)
450{ 459{
451 struct GetContext *gc = cls; 460 struct GetContext *gc = cls;
452 struct Value *value = val; 461 struct Value *value = val;
@@ -455,11 +464,11 @@ get_iterator(void *cls,
455 (gc->type != value->type)) 464 (gc->type != value->type))
456 return GNUNET_OK; 465 return GNUNET_OK;
457 if (gc->random) 466 if (gc->random)
458 { 467 {
459 gc->value = value; 468 gc->value = value;
460 return GNUNET_NO; 469 return GNUNET_NO;
461 } 470 }
462 if ((uint64_t)(intptr_t)value < gc->next_uid) 471 if ((uint64_t) (intptr_t) value < gc->next_uid)
463 return GNUNET_OK; 472 return GNUNET_OK;
464 if ((NULL != gc->value) && 473 if ((NULL != gc->value) &&
465 (value > gc->value)) 474 (value > gc->value))
@@ -483,13 +492,13 @@ get_iterator(void *cls,
483 * @param proc_cls closure for @a proc 492 * @param proc_cls closure for @a proc
484 */ 493 */
485static void 494static void
486heap_plugin_get_key(void *cls, 495heap_plugin_get_key (void *cls,
487 uint64_t next_uid, 496 uint64_t next_uid,
488 bool random, 497 bool random,
489 const struct GNUNET_HashCode *key, 498 const struct GNUNET_HashCode *key,
490 enum GNUNET_BLOCK_Type type, 499 enum GNUNET_BLOCK_Type type,
491 PluginDatumProcessor proc, 500 PluginDatumProcessor proc,
492 void *proc_cls) 501 void *proc_cls)
493{ 502{
494 struct Plugin *plugin = cls; 503 struct Plugin *plugin = cls;
495 struct GetContext gc; 504 struct GetContext gc;
@@ -499,34 +508,34 @@ heap_plugin_get_key(void *cls,
499 gc.random = random; 508 gc.random = random;
500 gc.type = type; 509 gc.type = type;
501 if (NULL == key) 510 if (NULL == key)
502 { 511 {
503 GNUNET_CONTAINER_multihashmap_iterate(plugin->keyvalue, 512 GNUNET_CONTAINER_multihashmap_iterate (plugin->keyvalue,
504 &get_iterator, 513 &get_iterator,
505 &gc); 514 &gc);
506 } 515 }
507 else 516 else
508 { 517 {
509 GNUNET_CONTAINER_multihashmap_get_multiple(plugin->keyvalue, 518 GNUNET_CONTAINER_multihashmap_get_multiple (plugin->keyvalue,
510 key, 519 key,
511 &get_iterator, 520 &get_iterator,
512 &gc); 521 &gc);
513 } 522 }
514 if (NULL == gc.value) 523 if (NULL == gc.value)
515 { 524 {
516 proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 525 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
517 return; 526 return;
518 } 527 }
519 GNUNET_assert(GNUNET_OK == 528 GNUNET_assert (GNUNET_OK ==
520 proc(proc_cls, 529 proc (proc_cls,
521 &gc.value->key, 530 &gc.value->key,
522 gc.value->size, 531 gc.value->size,
523 &gc.value[1], 532 &gc.value[1],
524 gc.value->type, 533 gc.value->type,
525 gc.value->priority, 534 gc.value->priority,
526 gc.value->anonymity, 535 gc.value->anonymity,
527 gc.value->replication, 536 gc.value->replication,
528 gc.value->expiration, 537 gc.value->expiration,
529 (uint64_t)(intptr_t)gc.value)); 538 (uint64_t) (intptr_t) gc.value));
530} 539}
531 540
532 541
@@ -542,45 +551,47 @@ heap_plugin_get_key(void *cls,
542 * @param proc_cls closure for proc 551 * @param proc_cls closure for proc
543 */ 552 */
544static void 553static void
545heap_plugin_get_replication(void *cls, 554heap_plugin_get_replication (void *cls,
546 PluginDatumProcessor proc, 555 PluginDatumProcessor proc,
547 void *proc_cls) 556 void *proc_cls)
548{ 557{
549 struct Plugin *plugin = cls; 558 struct Plugin *plugin = cls;
550 struct Value *value; 559 struct Value *value;
551 560
552 value = GNUNET_CONTAINER_heap_remove_root(plugin->by_replication); 561 value = GNUNET_CONTAINER_heap_remove_root (plugin->by_replication);
553 if (NULL == value) 562 if (NULL == value)
554 { 563 {
555 proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 564 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
556 return; 565 return;
557 } 566 }
558 if (value->replication > 0) 567 if (value->replication > 0)
559 { 568 {
560 value->replication--; 569 value->replication--;
561 value->replication_heap = GNUNET_CONTAINER_heap_insert(plugin->by_replication, 570 value->replication_heap = GNUNET_CONTAINER_heap_insert (
562 value, 571 plugin->by_replication,
563 value->replication); 572 value,
564 } 573 value->replication);
574 }
565 else 575 else
566 { 576 {
567 /* need a better way to pick a random item, replication level is always 0 */ 577 /* need a better way to pick a random item, replication level is always 0 */
568 value->replication_heap = GNUNET_CONTAINER_heap_insert(plugin->by_replication, 578 value->replication_heap = GNUNET_CONTAINER_heap_insert (
569 value, 579 plugin->by_replication,
570 value->replication); 580 value,
571 value = GNUNET_CONTAINER_heap_walk_get_next(plugin->by_replication); 581 value->replication);
572 } 582 value = GNUNET_CONTAINER_heap_walk_get_next (plugin->by_replication);
573 GNUNET_assert(GNUNET_OK == 583 }
574 proc(proc_cls, 584 GNUNET_assert (GNUNET_OK ==
575 &value->key, 585 proc (proc_cls,
576 value->size, 586 &value->key,
577 &value[1], 587 value->size,
578 value->type, 588 &value[1],
579 value->priority, 589 value->type,
580 value->anonymity, 590 value->priority,
581 value->replication, 591 value->anonymity,
582 value->expiration, 592 value->replication,
583 (uint64_t)(intptr_t)value)); 593 value->expiration,
594 (uint64_t) (intptr_t) value));
584} 595}
585 596
586 597
@@ -593,30 +604,30 @@ heap_plugin_get_replication(void *cls,
593 * @param proc_cls closure for proc 604 * @param proc_cls closure for proc
594 */ 605 */
595static void 606static void
596heap_plugin_get_expiration(void *cls, PluginDatumProcessor proc, 607heap_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
597 void *proc_cls) 608 void *proc_cls)
598{ 609{
599 struct Plugin *plugin = cls; 610 struct Plugin *plugin = cls;
600 struct Value *value; 611 struct Value *value;
601 612
602 value = GNUNET_CONTAINER_heap_peek(plugin->by_expiration); 613 value = GNUNET_CONTAINER_heap_peek (plugin->by_expiration);
603 if (NULL == value) 614 if (NULL == value)
604 { 615 {
605 proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 616 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
606 return; 617 return;
607 } 618 }
608 if (GNUNET_NO == 619 if (GNUNET_NO ==
609 proc(proc_cls, 620 proc (proc_cls,
610 &value->key, 621 &value->key,
611 value->size, 622 value->size,
612 &value[1], 623 &value[1],
613 value->type, 624 value->type,
614 value->priority, 625 value->priority,
615 value->anonymity, 626 value->anonymity,
616 value->replication, 627 value->replication,
617 value->expiration, 628 value->expiration,
618 (uint64_t)(intptr_t)value)) 629 (uint64_t) (intptr_t) value))
619 delete_value(plugin, value); 630 delete_value (plugin, value);
620} 631}
621 632
622 633
@@ -632,45 +643,45 @@ heap_plugin_get_expiration(void *cls, PluginDatumProcessor proc,
632 * @param proc_cls closure for proc 643 * @param proc_cls closure for proc
633 */ 644 */
634static void 645static void
635heap_plugin_get_zero_anonymity(void *cls, uint64_t next_uid, 646heap_plugin_get_zero_anonymity (void *cls, uint64_t next_uid,
636 enum GNUNET_BLOCK_Type type, 647 enum GNUNET_BLOCK_Type type,
637 PluginDatumProcessor proc, void *proc_cls) 648 PluginDatumProcessor proc, void *proc_cls)
638{ 649{
639 struct Plugin *plugin = cls; 650 struct Plugin *plugin = cls;
640 struct ZeroAnonByType *zabt; 651 struct ZeroAnonByType *zabt;
641 struct Value *value = NULL; 652 struct Value *value = NULL;
642 653
643 for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next) 654 for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next)
655 {
656 if ((type != GNUNET_BLOCK_TYPE_ANY) &&
657 (type != zabt->type))
658 continue;
659 for (int i = 0; i < zabt->array_pos; ++i)
644 { 660 {
645 if ((type != GNUNET_BLOCK_TYPE_ANY) && 661 if ((uint64_t) (intptr_t) zabt->array[i] < next_uid)
646 (type != zabt->type)) 662 continue;
663 if ((NULL != value) &&
664 (zabt->array[i] > value))
647 continue; 665 continue;
648 for (int i = 0; i < zabt->array_pos; ++i) 666 value = zabt->array[i];
649 {
650 if ((uint64_t)(intptr_t)zabt->array[i] < next_uid)
651 continue;
652 if ((NULL != value) &&
653 (zabt->array[i] > value))
654 continue;
655 value = zabt->array[i];
656 }
657 } 667 }
668 }
658 if (NULL == value) 669 if (NULL == value)
659 { 670 {
660 proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 671 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
661 return; 672 return;
662 } 673 }
663 GNUNET_assert(GNUNET_OK == 674 GNUNET_assert (GNUNET_OK ==
664 proc(proc_cls, 675 proc (proc_cls,
665 &value->key, 676 &value->key,
666 value->size, 677 value->size,
667 &value[1], 678 &value[1],
668 value->type, 679 value->type,
669 value->priority, 680 value->priority,
670 value->anonymity, 681 value->anonymity,
671 value->replication, 682 value->replication,
672 value->expiration, 683 value->expiration,
673 (uint64_t)(intptr_t)value)); 684 (uint64_t) (intptr_t) value));
674} 685}
675 686
676 687
@@ -678,7 +689,7 @@ heap_plugin_get_zero_anonymity(void *cls, uint64_t next_uid,
678 * Drop database. 689 * Drop database.
679 */ 690 */
680static void 691static void
681heap_plugin_drop(void *cls) 692heap_plugin_drop (void *cls)
682{ 693{
683 /* nothing needs to be done */ 694 /* nothing needs to be done */
684} 695}
@@ -687,7 +698,8 @@ heap_plugin_drop(void *cls)
687/** 698/**
688 * Closure for the 'return_value' function. 699 * Closure for the 'return_value' function.
689 */ 700 */
690struct GetAllContext { 701struct GetAllContext
702{
691 /** 703 /**
692 * Function to call. 704 * Function to call.
693 */ 705 */
@@ -709,15 +721,15 @@ struct GetAllContext {
709 * @return GNUNET_OK (continue to iterate) 721 * @return GNUNET_OK (continue to iterate)
710 */ 722 */
711static int 723static int
712return_value(void *cls, 724return_value (void *cls,
713 const struct GNUNET_HashCode *key, 725 const struct GNUNET_HashCode *key,
714 void *val) 726 void *val)
715{ 727{
716 struct GetAllContext *gac = cls; 728 struct GetAllContext *gac = cls;
717 729
718 gac->proc(gac->proc_cls, 730 gac->proc (gac->proc_cls,
719 key, 731 key,
720 1); 732 1);
721 return GNUNET_OK; 733 return GNUNET_OK;
722} 734}
723 735
@@ -730,26 +742,27 @@ return_value(void *cls,
730 * @param proc_cls closure for proc 742 * @param proc_cls closure for proc
731 */ 743 */
732static void 744static void
733heap_get_keys(void *cls, 745heap_get_keys (void *cls,
734 PluginKeyProcessor proc, 746 PluginKeyProcessor proc,
735 void *proc_cls) 747 void *proc_cls)
736{ 748{
737 struct Plugin *plugin = cls; 749 struct Plugin *plugin = cls;
738 struct GetAllContext gac; 750 struct GetAllContext gac;
739 751
740 gac.proc = proc; 752 gac.proc = proc;
741 gac.proc_cls = proc_cls; 753 gac.proc_cls = proc_cls;
742 GNUNET_CONTAINER_multihashmap_iterate(plugin->keyvalue, 754 GNUNET_CONTAINER_multihashmap_iterate (plugin->keyvalue,
743 &return_value, 755 &return_value,
744 &gac); 756 &gac);
745 proc(proc_cls, NULL, 0); 757 proc (proc_cls, NULL, 0);
746} 758}
747 759
748 760
749/** 761/**
750 * Closure for iterator called during 'remove_key'. 762 * Closure for iterator called during 'remove_key'.
751 */ 763 */
752struct RemoveContext { 764struct RemoveContext
765{
753 /** 766 /**
754 * Value found. 767 * Value found.
755 */ 768 */
@@ -776,16 +789,16 @@ struct RemoveContext {
776 * @return GNUNET_YES (continue iteration), GNUNET_NO if result was found 789 * @return GNUNET_YES (continue iteration), GNUNET_NO if result was found
777 */ 790 */
778static int 791static int
779remove_iterator(void *cls, 792remove_iterator (void *cls,
780 const struct GNUNET_HashCode *key, 793 const struct GNUNET_HashCode *key,
781 void *val) 794 void *val)
782{ 795{
783 struct RemoveContext *rc = cls; 796 struct RemoveContext *rc = cls;
784 struct Value *value = val; 797 struct Value *value = val;
785 798
786 if (value->size != rc->size) 799 if (value->size != rc->size)
787 return GNUNET_YES; 800 return GNUNET_YES;
788 if (0 != memcmp(value->data, rc->data, rc->size)) 801 if (0 != memcmp (value->data, rc->data, rc->size))
789 return GNUNET_YES; 802 return GNUNET_YES;
790 rc->value = value; 803 rc->value = value;
791 return GNUNET_NO; 804 return GNUNET_NO;
@@ -803,12 +816,12 @@ remove_iterator(void *cls,
803 * @param cont_cls continuation closure for @a cont 816 * @param cont_cls continuation closure for @a cont
804 */ 817 */
805static void 818static void
806heap_plugin_remove_key(void *cls, 819heap_plugin_remove_key (void *cls,
807 const struct GNUNET_HashCode *key, 820 const struct GNUNET_HashCode *key,
808 uint32_t size, 821 uint32_t size,
809 const void *data, 822 const void *data,
810 PluginRemoveCont cont, 823 PluginRemoveCont cont,
811 void *cont_cls) 824 void *cont_cls)
812{ 825{
813 struct Plugin *plugin = cls; 826 struct Plugin *plugin = cls;
814 struct RemoveContext rc; 827 struct RemoveContext rc;
@@ -816,26 +829,26 @@ heap_plugin_remove_key(void *cls,
816 rc.value = NULL; 829 rc.value = NULL;
817 rc.size = size; 830 rc.size = size;
818 rc.data = data; 831 rc.data = data;
819 GNUNET_CONTAINER_multihashmap_get_multiple(plugin->keyvalue, 832 GNUNET_CONTAINER_multihashmap_get_multiple (plugin->keyvalue,
820 key, 833 key,
821 &remove_iterator, 834 &remove_iterator,
822 &rc); 835 &rc);
823 if (NULL == rc.value) 836 if (NULL == rc.value)
824 { 837 {
825 cont(cont_cls, 838 cont (cont_cls,
826 key, 839 key,
827 size, 840 size,
828 GNUNET_NO, 841 GNUNET_NO,
829 NULL); 842 NULL);
830 return; 843 return;
831 } 844 }
832 delete_value(plugin, 845 delete_value (plugin,
833 rc.value); 846 rc.value);
834 cont(cont_cls, 847 cont (cont_cls,
835 key, 848 key,
836 size, 849 size,
837 GNUNET_OK, 850 GNUNET_OK,
838 NULL); 851 NULL);
839} 852}
840 853
841 854
@@ -846,7 +859,7 @@ heap_plugin_remove_key(void *cls,
846 * @return our "struct Plugin*" 859 * @return our "struct Plugin*"
847 */ 860 */
848void * 861void *
849libgnunet_plugin_datastore_heap_init(void *cls) 862libgnunet_plugin_datastore_heap_init (void *cls)
850{ 863{
851 struct GNUNET_DATASTORE_PluginEnvironment *env = cls; 864 struct GNUNET_DATASTORE_PluginEnvironment *env = cls;
852 struct GNUNET_DATASTORE_PluginFunctions *api; 865 struct GNUNET_DATASTORE_PluginFunctions *api;
@@ -854,17 +867,19 @@ libgnunet_plugin_datastore_heap_init(void *cls)
854 unsigned long long esize; 867 unsigned long long esize;
855 868
856 if (GNUNET_OK != 869 if (GNUNET_OK !=
857 GNUNET_CONFIGURATION_get_value_number(env->cfg, 870 GNUNET_CONFIGURATION_get_value_number (env->cfg,
858 "datastore-heap", 871 "datastore-heap",
859 "HASHMAPSIZE", 872 "HASHMAPSIZE",
860 &esize)) 873 &esize))
861 esize = 128 * 1024; 874 esize = 128 * 1024;
862 plugin = GNUNET_new(struct Plugin); 875 plugin = GNUNET_new (struct Plugin);
863 plugin->env = env; 876 plugin->env = env;
864 plugin->keyvalue = GNUNET_CONTAINER_multihashmap_create(esize, GNUNET_YES); 877 plugin->keyvalue = GNUNET_CONTAINER_multihashmap_create (esize, GNUNET_YES);
865 plugin->by_expiration = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); 878 plugin->by_expiration = GNUNET_CONTAINER_heap_create (
866 plugin->by_replication = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MAX); 879 GNUNET_CONTAINER_HEAP_ORDER_MIN);
867 api = GNUNET_new(struct GNUNET_DATASTORE_PluginFunctions); 880 plugin->by_replication = GNUNET_CONTAINER_heap_create (
881 GNUNET_CONTAINER_HEAP_ORDER_MAX);
882 api = GNUNET_new (struct GNUNET_DATASTORE_PluginFunctions);
868 api->cls = plugin; 883 api->cls = plugin;
869 api->estimate_size = &heap_plugin_estimate_size; 884 api->estimate_size = &heap_plugin_estimate_size;
870 api->put = &heap_plugin_put; 885 api->put = &heap_plugin_put;
@@ -875,8 +890,8 @@ libgnunet_plugin_datastore_heap_init(void *cls)
875 api->drop = &heap_plugin_drop; 890 api->drop = &heap_plugin_drop;
876 api->get_keys = &heap_get_keys; 891 api->get_keys = &heap_get_keys;
877 api->remove_key = &heap_plugin_remove_key; 892 api->remove_key = &heap_plugin_remove_key;
878 GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "heap", 893 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "heap",
879 _("Heap database running\n")); 894 _ ("Heap database running\n"));
880 return api; 895 return api;
881} 896}
882 897
@@ -890,14 +905,14 @@ libgnunet_plugin_datastore_heap_init(void *cls)
890 * @return GNUNET_OK (continue to iterate) 905 * @return GNUNET_OK (continue to iterate)
891 */ 906 */
892static int 907static int
893free_value(void *cls, 908free_value (void *cls,
894 const struct GNUNET_HashCode *key, 909 const struct GNUNET_HashCode *key,
895 void *val) 910 void *val)
896{ 911{
897 struct Plugin *plugin = cls; 912 struct Plugin *plugin = cls;
898 struct Value *value = val; 913 struct Value *value = val;
899 914
900 delete_value(plugin, value); 915 delete_value (plugin, value);
901 return GNUNET_OK; 916 return GNUNET_OK;
902} 917}
903 918
@@ -908,19 +923,19 @@ free_value(void *cls,
908 * @return always NULL 923 * @return always NULL
909 */ 924 */
910void * 925void *
911libgnunet_plugin_datastore_heap_done(void *cls) 926libgnunet_plugin_datastore_heap_done (void *cls)
912{ 927{
913 struct GNUNET_DATASTORE_PluginFunctions *api = cls; 928 struct GNUNET_DATASTORE_PluginFunctions *api = cls;
914 struct Plugin *plugin = api->cls; 929 struct Plugin *plugin = api->cls;
915 930
916 GNUNET_CONTAINER_multihashmap_iterate(plugin->keyvalue, 931 GNUNET_CONTAINER_multihashmap_iterate (plugin->keyvalue,
917 &free_value, 932 &free_value,
918 plugin); 933 plugin);
919 GNUNET_CONTAINER_multihashmap_destroy(plugin->keyvalue); 934 GNUNET_CONTAINER_multihashmap_destroy (plugin->keyvalue);
920 GNUNET_CONTAINER_heap_destroy(plugin->by_expiration); 935 GNUNET_CONTAINER_heap_destroy (plugin->by_expiration);
921 GNUNET_CONTAINER_heap_destroy(plugin->by_replication); 936 GNUNET_CONTAINER_heap_destroy (plugin->by_replication);
922 GNUNET_free(plugin); 937 GNUNET_free (plugin);
923 GNUNET_free(api); 938 GNUNET_free (api);
924 return NULL; 939 return NULL;
925} 940}
926 941
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c
index cc5b558ee..6aec09c54 100644
--- a/src/datastore/plugin_datastore_mysql.c
+++ b/src/datastore/plugin_datastore_mysql.c
@@ -129,7 +129,8 @@
129/** 129/**
130 * Context for all functions in this plugin. 130 * Context for all functions in this plugin.
131 */ 131 */
132struct Plugin { 132struct Plugin
133{
133 /** 134 /**
134 * Our execution environment. 135 * Our execution environment.
135 */ 136 */
@@ -143,7 +144,8 @@ struct Plugin {
143 /** 144 /**
144 * Prepared statements. 145 * Prepared statements.
145 */ 146 */
146#define INSERT_ENTRY "INSERT INTO gn090 (repl,type,prio,anonLevel,expire,rvalue,hash,vhash,value) VALUES (?,?,?,?,?,?,?,?,?)" 147#define INSERT_ENTRY \
148 "INSERT INTO gn090 (repl,type,prio,anonLevel,expire,rvalue,hash,vhash,value) VALUES (?,?,?,?,?,?,?,?,?)"
147 struct GNUNET_MYSQL_StatementHandle *insert_entry; 149 struct GNUNET_MYSQL_StatementHandle *insert_entry;
148 150
149#define DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?" 151#define DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?"
@@ -238,29 +240,29 @@ struct Plugin {
238 * @return #GNUNET_OK on success, #GNUNET_NO if no such value exists, #GNUNET_SYSERR on error 240 * @return #GNUNET_OK on success, #GNUNET_NO if no such value exists, #GNUNET_SYSERR on error
239 */ 241 */
240static int 242static int
241do_delete_entry(struct Plugin *plugin, 243do_delete_entry (struct Plugin *plugin,
242 unsigned long long uid) 244 unsigned long long uid)
243{ 245{
244 int ret; 246 int ret;
245 uint64_t uid64 = (uint64_t)uid; 247 uint64_t uid64 = (uint64_t) uid;
246 struct GNUNET_MY_QueryParam params_delete[] = { 248 struct GNUNET_MY_QueryParam params_delete[] = {
247 GNUNET_MY_query_param_uint64(&uid64), 249 GNUNET_MY_query_param_uint64 (&uid64),
248 GNUNET_MY_query_param_end 250 GNUNET_MY_query_param_end
249 }; 251 };
250 252
251 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
252 "Deleting value %llu from gn090 table\n", 254 "Deleting value %llu from gn090 table\n",
253 uid); 255 uid);
254 ret = GNUNET_MY_exec_prepared(plugin->mc, 256 ret = GNUNET_MY_exec_prepared (plugin->mc,
255 plugin->delete_entry_by_uid, 257 plugin->delete_entry_by_uid,
256 params_delete); 258 params_delete);
257 if (ret >= 0) 259 if (ret >= 0)
258 { 260 {
259 return GNUNET_OK; 261 return GNUNET_OK;
260 } 262 }
261 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 263 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
262 "Deleting value %llu from gn090 table failed\n", 264 "Deleting value %llu from gn090 table failed\n",
263 (unsigned long long)uid); 265 (unsigned long long) uid);
264 return ret; 266 return ret;
265} 267}
266 268
@@ -273,8 +275,8 @@ do_delete_entry(struct Plugin *plugin,
273 * @return number of bytes used on disk 275 * @return number of bytes used on disk
274 */ 276 */
275static void 277static void
276mysql_plugin_estimate_size(void *cls, 278mysql_plugin_estimate_size (void *cls,
277 unsigned long long *estimate) 279 unsigned long long *estimate)
278{ 280{
279 struct Plugin *plugin = cls; 281 struct Plugin *plugin = cls;
280 uint64_t total; 282 uint64_t total;
@@ -283,29 +285,29 @@ mysql_plugin_estimate_size(void *cls,
283 GNUNET_MY_query_param_end 285 GNUNET_MY_query_param_end
284 }; 286 };
285 struct GNUNET_MY_ResultSpec results_get[] = { 287 struct GNUNET_MY_ResultSpec results_get[] = {
286 GNUNET_MY_result_spec_uint64(&total), 288 GNUNET_MY_result_spec_uint64 (&total),
287 GNUNET_MY_result_spec_end 289 GNUNET_MY_result_spec_end
288 }; 290 };
289 291
290 ret = GNUNET_MY_exec_prepared(plugin->mc, 292 ret = GNUNET_MY_exec_prepared (plugin->mc,
291 plugin->get_size, 293 plugin->get_size,
292 params_get); 294 params_get);
293 *estimate = 0; 295 *estimate = 0;
294 total = UINT64_MAX; 296 total = UINT64_MAX;
295 if ((GNUNET_OK == ret) && 297 if ((GNUNET_OK == ret) &&
296 (GNUNET_OK == 298 (GNUNET_OK ==
297 GNUNET_MY_extract_result(plugin->get_size, 299 GNUNET_MY_extract_result (plugin->get_size,
298 results_get))) 300 results_get)))
299 { 301 {
300 *estimate = (unsigned long long)total; 302 *estimate = (unsigned long long) total;
301 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 303 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
302 "Size estimate for MySQL payload is %lld\n", 304 "Size estimate for MySQL payload is %lld\n",
303 (long long)total); 305 (long long) total);
304 GNUNET_assert(UINT64_MAX != total); 306 GNUNET_assert (UINT64_MAX != total);
305 GNUNET_break(GNUNET_NO == 307 GNUNET_break (GNUNET_NO ==
306 GNUNET_MY_extract_result(plugin->get_size, 308 GNUNET_MY_extract_result (plugin->get_size,
307 NULL)); 309 NULL));
308 } 310 }
309} 311}
310 312
311 313
@@ -326,116 +328,116 @@ mysql_plugin_estimate_size(void *cls,
326 * @param cont_cls closure for @a cont 328 * @param cont_cls closure for @a cont
327 */ 329 */
328static void 330static void
329mysql_plugin_put(void *cls, 331mysql_plugin_put (void *cls,
330 const struct GNUNET_HashCode *key, 332 const struct GNUNET_HashCode *key,
331 bool absent, 333 bool absent,
332 uint32_t size, 334 uint32_t size,
333 const void *data, 335 const void *data,
334 enum GNUNET_BLOCK_Type type, 336 enum GNUNET_BLOCK_Type type,
335 uint32_t priority, 337 uint32_t priority,
336 uint32_t anonymity, 338 uint32_t anonymity,
337 uint32_t replication, 339 uint32_t replication,
338 struct GNUNET_TIME_Absolute expiration, 340 struct GNUNET_TIME_Absolute expiration,
339 PluginPutCont cont, 341 PluginPutCont cont,
340 void *cont_cls) 342 void *cont_cls)
341{ 343{
342 struct Plugin *plugin = cls; 344 struct Plugin *plugin = cls;
343 uint64_t lexpiration = expiration.abs_value_us; 345 uint64_t lexpiration = expiration.abs_value_us;
344 struct GNUNET_HashCode vhash; 346 struct GNUNET_HashCode vhash;
345 347
346 GNUNET_CRYPTO_hash(data, 348 GNUNET_CRYPTO_hash (data,
347 size, 349 size,
348 &vhash); 350 &vhash);
349 if (!absent) 351 if (! absent)
352 {
353 struct GNUNET_MY_QueryParam params_update[] = {
354 GNUNET_MY_query_param_uint32 (&priority),
355 GNUNET_MY_query_param_uint32 (&replication),
356 GNUNET_MY_query_param_uint64 (&lexpiration),
357 GNUNET_MY_query_param_auto_from_type (key),
358 GNUNET_MY_query_param_auto_from_type (&vhash),
359 GNUNET_MY_query_param_end
360 };
361
362 if (GNUNET_OK !=
363 GNUNET_MY_exec_prepared (plugin->mc,
364 plugin->update_entry,
365 params_update))
350 { 366 {
351 struct GNUNET_MY_QueryParam params_update[] = { 367 cont (cont_cls,
352 GNUNET_MY_query_param_uint32(&priority), 368 key,
353 GNUNET_MY_query_param_uint32(&replication), 369 size,
354 GNUNET_MY_query_param_uint64(&lexpiration), 370 GNUNET_SYSERR,
355 GNUNET_MY_query_param_auto_from_type(key), 371 _ ("MySQL statement run failure"));
356 GNUNET_MY_query_param_auto_from_type(&vhash), 372 return;
357 GNUNET_MY_query_param_end 373 }
358 }; 374
359 375 MYSQL_STMT *stmt = GNUNET_MYSQL_statement_get_stmt (plugin->update_entry);
360 if (GNUNET_OK != 376 my_ulonglong rows = mysql_stmt_affected_rows (stmt);
361 GNUNET_MY_exec_prepared(plugin->mc, 377
362 plugin->update_entry, 378 GNUNET_break (GNUNET_NO ==
363 params_update)) 379 GNUNET_MY_extract_result (plugin->update_entry,
364 {
365 cont(cont_cls,
366 key,
367 size,
368 GNUNET_SYSERR,
369 _("MySQL statement run failure"));
370 return;
371 }
372
373 MYSQL_STMT *stmt = GNUNET_MYSQL_statement_get_stmt(plugin->update_entry);
374 my_ulonglong rows = mysql_stmt_affected_rows(stmt);
375
376 GNUNET_break(GNUNET_NO ==
377 GNUNET_MY_extract_result(plugin->update_entry,
378 NULL)); 380 NULL));
379 if (0 != rows) 381 if (0 != rows)
380 { 382 {
381 cont(cont_cls, 383 cont (cont_cls,
382 key, 384 key,
383 size, 385 size,
384 GNUNET_NO, 386 GNUNET_NO,
385 NULL); 387 NULL);
386 return; 388 return;
387 }
388 } 389 }
390 }
389 391
390 uint64_t lrvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, 392 uint64_t lrvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
391 UINT64_MAX); 393 UINT64_MAX);
392 struct GNUNET_MY_QueryParam params_insert[] = { 394 struct GNUNET_MY_QueryParam params_insert[] = {
393 GNUNET_MY_query_param_uint32(&replication), 395 GNUNET_MY_query_param_uint32 (&replication),
394 GNUNET_MY_query_param_uint32(&type), 396 GNUNET_MY_query_param_uint32 (&type),
395 GNUNET_MY_query_param_uint32(&priority), 397 GNUNET_MY_query_param_uint32 (&priority),
396 GNUNET_MY_query_param_uint32(&anonymity), 398 GNUNET_MY_query_param_uint32 (&anonymity),
397 GNUNET_MY_query_param_uint64(&lexpiration), 399 GNUNET_MY_query_param_uint64 (&lexpiration),
398 GNUNET_MY_query_param_uint64(&lrvalue), 400 GNUNET_MY_query_param_uint64 (&lrvalue),
399 GNUNET_MY_query_param_auto_from_type(key), 401 GNUNET_MY_query_param_auto_from_type (key),
400 GNUNET_MY_query_param_auto_from_type(&vhash), 402 GNUNET_MY_query_param_auto_from_type (&vhash),
401 GNUNET_MY_query_param_fixed_size(data, size), 403 GNUNET_MY_query_param_fixed_size (data, size),
402 GNUNET_MY_query_param_end 404 GNUNET_MY_query_param_end
403 }; 405 };
404 406
405 if (size > MAX_DATUM_SIZE) 407 if (size > MAX_DATUM_SIZE)
406 { 408 {
407 GNUNET_break(0); 409 GNUNET_break (0);
408 cont(cont_cls, key, size, GNUNET_SYSERR, _("Data too large")); 410 cont (cont_cls, key, size, GNUNET_SYSERR, _ ("Data too large"));
409 return; 411 return;
410 } 412 }
411 413
412 if (GNUNET_OK != 414 if (GNUNET_OK !=
413 GNUNET_MY_exec_prepared(plugin->mc, 415 GNUNET_MY_exec_prepared (plugin->mc,
414 plugin->insert_entry, 416 plugin->insert_entry,
415 params_insert)) 417 params_insert))
416 { 418 {
417 cont(cont_cls, 419 cont (cont_cls,
418 key, 420 key,
419 size, 421 size,
420 GNUNET_SYSERR, 422 GNUNET_SYSERR,
421 _("MySQL statement run failure")); 423 _ ("MySQL statement run failure"));
422 return; 424 return;
423 } 425 }
424 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
425 "Inserted value `%s' with size %u into gn090 table\n", 427 "Inserted value `%s' with size %u into gn090 table\n",
426 GNUNET_h2s(key), 428 GNUNET_h2s (key),
427 (unsigned int)size); 429 (unsigned int) size);
428 if (size > 0) 430 if (size > 0)
429 plugin->env->duc(plugin->env->cls, 431 plugin->env->duc (plugin->env->cls,
430 size); 432 size);
431 GNUNET_break(GNUNET_NO == 433 GNUNET_break (GNUNET_NO ==
432 GNUNET_MY_extract_result(plugin->insert_entry, 434 GNUNET_MY_extract_result (plugin->insert_entry,
433 NULL)); 435 NULL));
434 cont(cont_cls, 436 cont (cont_cls,
435 key, 437 key,
436 size, 438 size,
437 GNUNET_OK, 439 GNUNET_OK,
438 NULL); 440 NULL);
439} 441}
440 442
441 443
@@ -450,11 +452,11 @@ mysql_plugin_put(void *cls,
450 * @param params_select arguments to initialize stmt 452 * @param params_select arguments to initialize stmt
451 */ 453 */
452static void 454static void
453execute_select(struct Plugin *plugin, 455execute_select (struct Plugin *plugin,
454 struct GNUNET_MYSQL_StatementHandle *stmt, 456 struct GNUNET_MYSQL_StatementHandle *stmt,
455 PluginDatumProcessor proc, 457 PluginDatumProcessor proc,
456 void *proc_cls, 458 void *proc_cls,
457 struct GNUNET_MY_QueryParam *params_select) 459 struct GNUNET_MY_QueryParam *params_select)
458{ 460{
459 int ret; 461 int ret;
460 uint32_t replication; 462 uint32_t replication;
@@ -467,65 +469,65 @@ execute_select(struct Plugin *plugin,
467 struct GNUNET_HashCode key; 469 struct GNUNET_HashCode key;
468 struct GNUNET_TIME_Absolute expiration; 470 struct GNUNET_TIME_Absolute expiration;
469 struct GNUNET_MY_ResultSpec results_select[] = { 471 struct GNUNET_MY_ResultSpec results_select[] = {
470 GNUNET_MY_result_spec_uint32(&replication), 472 GNUNET_MY_result_spec_uint32 (&replication),
471 GNUNET_MY_result_spec_uint32(&type), 473 GNUNET_MY_result_spec_uint32 (&type),
472 GNUNET_MY_result_spec_uint32(&priority), 474 GNUNET_MY_result_spec_uint32 (&priority),
473 GNUNET_MY_result_spec_uint32(&anonymity), 475 GNUNET_MY_result_spec_uint32 (&anonymity),
474 GNUNET_MY_result_spec_absolute_time(&expiration), 476 GNUNET_MY_result_spec_absolute_time (&expiration),
475 GNUNET_MY_result_spec_auto_from_type(&key), 477 GNUNET_MY_result_spec_auto_from_type (&key),
476 GNUNET_MY_result_spec_variable_size(&value, &value_size), 478 GNUNET_MY_result_spec_variable_size (&value, &value_size),
477 GNUNET_MY_result_spec_uint64(&uid), 479 GNUNET_MY_result_spec_uint64 (&uid),
478 GNUNET_MY_result_spec_end 480 GNUNET_MY_result_spec_end
479 }; 481 };
480 482
481 ret = GNUNET_MY_exec_prepared(plugin->mc, 483 ret = GNUNET_MY_exec_prepared (plugin->mc,
482 stmt, 484 stmt,
483 params_select); 485 params_select);
484 if (GNUNET_OK != ret) 486 if (GNUNET_OK != ret)
485 { 487 {
486 proc(proc_cls, 488 proc (proc_cls,
487 NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 489 NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
488 return; 490 return;
489 } 491 }
490 492
491 ret = GNUNET_MY_extract_result(stmt, 493 ret = GNUNET_MY_extract_result (stmt,
492 results_select); 494 results_select);
493 if (GNUNET_OK != ret) 495 if (GNUNET_OK != ret)
494 { 496 {
495 proc(proc_cls, 497 proc (proc_cls,
496 NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 498 NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
497 return; 499 return;
498 } 500 }
499 501
500 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
501 "Found %u-byte value under key `%s' with prio %u, anon %u, expire %s selecting from gn090 table\n", 503 "Found %u-byte value under key `%s' with prio %u, anon %u, expire %s selecting from gn090 table\n",
502 (unsigned int)value_size, 504 (unsigned int) value_size,
503 GNUNET_h2s(&key), 505 GNUNET_h2s (&key),
504 (unsigned int)priority, 506 (unsigned int) priority,
505 (unsigned int)anonymity, 507 (unsigned int) anonymity,
506 GNUNET_STRINGS_absolute_time_to_string(expiration)); 508 GNUNET_STRINGS_absolute_time_to_string (expiration));
507 GNUNET_assert(value_size < MAX_DATUM_SIZE); 509 GNUNET_assert (value_size < MAX_DATUM_SIZE);
508 GNUNET_break(GNUNET_NO == 510 GNUNET_break (GNUNET_NO ==
509 GNUNET_MY_extract_result(stmt, 511 GNUNET_MY_extract_result (stmt,
510 NULL)); 512 NULL));
511 ret = proc(proc_cls, 513 ret = proc (proc_cls,
512 &key, 514 &key,
513 value_size, 515 value_size,
514 value, 516 value,
515 type, 517 type,
516 priority, 518 priority,
517 anonymity, 519 anonymity,
518 replication, 520 replication,
519 expiration, 521 expiration,
520 uid); 522 uid);
521 GNUNET_MY_cleanup_result(results_select); 523 GNUNET_MY_cleanup_result (results_select);
522 if (GNUNET_NO == ret) 524 if (GNUNET_NO == ret)
523 { 525 {
524 do_delete_entry(plugin, uid); 526 do_delete_entry (plugin, uid);
525 if (0 != value_size) 527 if (0 != value_size)
526 plugin->env->duc(plugin->env->cls, 528 plugin->env->duc (plugin->env->cls,
527 -value_size); 529 -value_size);
528 } 530 }
529} 531}
530 532
531 533
@@ -543,74 +545,74 @@ execute_select(struct Plugin *plugin,
543 * @param proc_cls closure for @a proc 545 * @param proc_cls closure for @a proc
544 */ 546 */
545static void 547static void
546mysql_plugin_get_key(void *cls, 548mysql_plugin_get_key (void *cls,
547 uint64_t next_uid, 549 uint64_t next_uid,
548 bool random, 550 bool random,
549 const struct GNUNET_HashCode *key, 551 const struct GNUNET_HashCode *key,
550 enum GNUNET_BLOCK_Type type, 552 enum GNUNET_BLOCK_Type type,
551 PluginDatumProcessor proc, 553 PluginDatumProcessor proc,
552 void *proc_cls) 554 void *proc_cls)
553{ 555{
554 struct Plugin *plugin = cls; 556 struct Plugin *plugin = cls;
555 uint64_t rvalue; 557 uint64_t rvalue;
556 558
557 if (random) 559 if (random)
558 { 560 {
559 rvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, 561 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
560 UINT64_MAX); 562 UINT64_MAX);
561 next_uid = 0; 563 next_uid = 0;
562 } 564 }
563 else 565 else
564 rvalue = 0; 566 rvalue = 0;
565 567
566 if (NULL == key) 568 if (NULL == key)
567 { 569 {
568 struct GNUNET_MY_QueryParam params_select[] = { 570 struct GNUNET_MY_QueryParam params_select[] = {
569 GNUNET_MY_query_param_uint64(&next_uid), 571 GNUNET_MY_query_param_uint64 (&next_uid),
570 GNUNET_MY_query_param_uint64(&rvalue), 572 GNUNET_MY_query_param_uint64 (&rvalue),
571 GNUNET_MY_query_param_uint64(&rvalue), 573 GNUNET_MY_query_param_uint64 (&rvalue),
572 GNUNET_MY_query_param_end 574 GNUNET_MY_query_param_end
573 }; 575 };
574 576
575 execute_select(plugin, 577 execute_select (plugin,
576 plugin->select_entry, 578 plugin->select_entry,
577 proc, 579 proc,
578 proc_cls, 580 proc_cls,
579 params_select); 581 params_select);
580 } 582 }
581 else if (type != GNUNET_BLOCK_TYPE_ANY) 583 else if (type != GNUNET_BLOCK_TYPE_ANY)
582 { 584 {
583 struct GNUNET_MY_QueryParam params_select[] = { 585 struct GNUNET_MY_QueryParam params_select[] = {
584 GNUNET_MY_query_param_auto_from_type(key), 586 GNUNET_MY_query_param_auto_from_type (key),
585 GNUNET_MY_query_param_uint32(&type), 587 GNUNET_MY_query_param_uint32 (&type),
586 GNUNET_MY_query_param_uint64(&next_uid), 588 GNUNET_MY_query_param_uint64 (&next_uid),
587 GNUNET_MY_query_param_uint64(&rvalue), 589 GNUNET_MY_query_param_uint64 (&rvalue),
588 GNUNET_MY_query_param_uint64(&rvalue), 590 GNUNET_MY_query_param_uint64 (&rvalue),
589 GNUNET_MY_query_param_end 591 GNUNET_MY_query_param_end
590 }; 592 };
591 593
592 execute_select(plugin, 594 execute_select (plugin,
593 plugin->select_entry_by_hash_and_type, 595 plugin->select_entry_by_hash_and_type,
594 proc, 596 proc,
595 proc_cls, 597 proc_cls,
596 params_select); 598 params_select);
597 } 599 }
598 else 600 else
599 { 601 {
600 struct GNUNET_MY_QueryParam params_select[] = { 602 struct GNUNET_MY_QueryParam params_select[] = {
601 GNUNET_MY_query_param_auto_from_type(key), 603 GNUNET_MY_query_param_auto_from_type (key),
602 GNUNET_MY_query_param_uint64(&next_uid), 604 GNUNET_MY_query_param_uint64 (&next_uid),
603 GNUNET_MY_query_param_uint64(&rvalue), 605 GNUNET_MY_query_param_uint64 (&rvalue),
604 GNUNET_MY_query_param_uint64(&rvalue), 606 GNUNET_MY_query_param_uint64 (&rvalue),
605 GNUNET_MY_query_param_end 607 GNUNET_MY_query_param_end
606 }; 608 };
607 609
608 execute_select(plugin, 610 execute_select (plugin,
609 plugin->select_entry_by_hash, 611 plugin->select_entry_by_hash,
610 proc, 612 proc,
611 proc_cls, 613 proc_cls,
612 params_select); 614 params_select);
613 } 615 }
614} 616}
615 617
616 618
@@ -626,33 +628,34 @@ mysql_plugin_get_key(void *cls,
626 * @param proc_cls closure for @a proc 628 * @param proc_cls closure for @a proc
627 */ 629 */
628static void 630static void
629mysql_plugin_get_zero_anonymity(void *cls, 631mysql_plugin_get_zero_anonymity (void *cls,
630 uint64_t next_uid, 632 uint64_t next_uid,
631 enum GNUNET_BLOCK_Type type, 633 enum GNUNET_BLOCK_Type type,
632 PluginDatumProcessor proc, 634 PluginDatumProcessor proc,
633 void *proc_cls) 635 void *proc_cls)
634{ 636{
635 struct Plugin *plugin = cls; 637 struct Plugin *plugin = cls;
636 uint32_t typei = (uint32_t)type; 638 uint32_t typei = (uint32_t) type;
637 639
638 struct GNUNET_MY_QueryParam params_zero_iter[] = { 640 struct GNUNET_MY_QueryParam params_zero_iter[] = {
639 GNUNET_MY_query_param_uint32(&typei), 641 GNUNET_MY_query_param_uint32 (&typei),
640 GNUNET_MY_query_param_uint64(&next_uid), 642 GNUNET_MY_query_param_uint64 (&next_uid),
641 GNUNET_MY_query_param_end 643 GNUNET_MY_query_param_end
642 }; 644 };
643 645
644 execute_select(plugin, 646 execute_select (plugin,
645 plugin->zero_iter, 647 plugin->zero_iter,
646 proc, 648 proc,
647 proc_cls, 649 proc_cls,
648 params_zero_iter); 650 params_zero_iter);
649} 651}
650 652
651 653
652/** 654/**
653 * Context for #repl_proc() function. 655 * Context for #repl_proc() function.
654 */ 656 */
655struct ReplCtx { 657struct ReplCtx
658{
656 /** 659 /**
657 * Plugin handle. 660 * Plugin handle.
658 */ 661 */
@@ -691,49 +694,49 @@ struct ReplCtx {
691 * #GNUNET_NO to delete the item and continue (if supported) 694 * #GNUNET_NO to delete the item and continue (if supported)
692 */ 695 */
693static int 696static int
694repl_proc(void *cls, 697repl_proc (void *cls,
695 const struct GNUNET_HashCode *key, 698 const struct GNUNET_HashCode *key,
696 uint32_t size, 699 uint32_t size,
697 const void *data, 700 const void *data,
698 enum GNUNET_BLOCK_Type type, 701 enum GNUNET_BLOCK_Type type,
699 uint32_t priority, 702 uint32_t priority,
700 uint32_t anonymity, 703 uint32_t anonymity,
701 uint32_t replication, 704 uint32_t replication,
702 struct GNUNET_TIME_Absolute expiration, 705 struct GNUNET_TIME_Absolute expiration,
703 uint64_t uid) 706 uint64_t uid)
704{ 707{
705 struct ReplCtx *rc = cls; 708 struct ReplCtx *rc = cls;
706 struct Plugin *plugin = rc->plugin; 709 struct Plugin *plugin = rc->plugin;
707 int ret; 710 int ret;
708 int iret; 711 int iret;
709 712
710 ret = rc->proc(rc->proc_cls, 713 ret = rc->proc (rc->proc_cls,
711 key, 714 key,
712 size, 715 size,
713 data, 716 data,
714 type, 717 type,
715 priority, 718 priority,
716 anonymity, 719 anonymity,
717 replication, 720 replication,
718 expiration, 721 expiration,
719 uid); 722 uid);
720 if (NULL != key) 723 if (NULL != key)
724 {
725 struct GNUNET_MY_QueryParam params_proc[] = {
726 GNUNET_MY_query_param_uint64 (&uid),
727 GNUNET_MY_query_param_end
728 };
729
730 iret = GNUNET_MY_exec_prepared (plugin->mc,
731 plugin->dec_repl,
732 params_proc);
733 if (GNUNET_SYSERR == iret)
721 { 734 {
722 struct GNUNET_MY_QueryParam params_proc[] = { 735 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
723 GNUNET_MY_query_param_uint64(&uid), 736 "Failed to reduce replication counter\n");
724 GNUNET_MY_query_param_end 737 return GNUNET_SYSERR;
725 };
726
727 iret = GNUNET_MY_exec_prepared(plugin->mc,
728 plugin->dec_repl,
729 params_proc);
730 if (GNUNET_SYSERR == iret)
731 {
732 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
733 "Failed to reduce replication counter\n");
734 return GNUNET_SYSERR;
735 }
736 } 738 }
739 }
737 return ret; 740 return ret;
738} 741}
739 742
@@ -750,9 +753,9 @@ repl_proc(void *cls,
750 * @param proc_cls closure for @a proc 753 * @param proc_cls closure for @a proc
751 */ 754 */
752static void 755static void
753mysql_plugin_get_replication(void *cls, 756mysql_plugin_get_replication (void *cls,
754 PluginDatumProcessor proc, 757 PluginDatumProcessor proc,
755 void *proc_cls) 758 void *proc_cls)
756{ 759{
757 struct Plugin *plugin = cls; 760 struct Plugin *plugin = cls;
758 uint64_t rvalue; 761 uint64_t rvalue;
@@ -762,14 +765,14 @@ mysql_plugin_get_replication(void *cls,
762 GNUNET_MY_query_param_end 765 GNUNET_MY_query_param_end
763 }; 766 };
764 struct GNUNET_MY_ResultSpec results_get[] = { 767 struct GNUNET_MY_ResultSpec results_get[] = {
765 GNUNET_MY_result_spec_uint32(&repl), 768 GNUNET_MY_result_spec_uint32 (&repl),
766 GNUNET_MY_result_spec_end 769 GNUNET_MY_result_spec_end
767 }; 770 };
768 struct GNUNET_MY_QueryParam params_select[] = { 771 struct GNUNET_MY_QueryParam params_select[] = {
769 GNUNET_MY_query_param_uint32(&repl), 772 GNUNET_MY_query_param_uint32 (&repl),
770 GNUNET_MY_query_param_uint64(&rvalue), 773 GNUNET_MY_query_param_uint64 (&rvalue),
771 GNUNET_MY_query_param_uint32(&repl), 774 GNUNET_MY_query_param_uint32 (&repl),
772 GNUNET_MY_query_param_uint64(&rvalue), 775 GNUNET_MY_query_param_uint64 (&rvalue),
773 GNUNET_MY_query_param_end 776 GNUNET_MY_query_param_end
774 }; 777 };
775 778
@@ -778,32 +781,32 @@ mysql_plugin_get_replication(void *cls,
778 rc.proc_cls = proc_cls; 781 rc.proc_cls = proc_cls;
779 782
780 if (1 != 783 if (1 !=
781 GNUNET_MY_exec_prepared(plugin->mc, 784 GNUNET_MY_exec_prepared (plugin->mc,
782 plugin->max_repl, 785 plugin->max_repl,
783 params_get)) 786 params_get))
784 { 787 {
785 proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 788 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
786 return; 789 return;
787 } 790 }
788 791
789 if (GNUNET_OK != 792 if (GNUNET_OK !=
790 GNUNET_MY_extract_result(plugin->max_repl, 793 GNUNET_MY_extract_result (plugin->max_repl,
791 results_get)) 794 results_get))
792 { 795 {
793 proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 796 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
794 return; 797 return;
795 } 798 }
796 GNUNET_break(GNUNET_NO == 799 GNUNET_break (GNUNET_NO ==
797 GNUNET_MY_extract_result(plugin->max_repl, 800 GNUNET_MY_extract_result (plugin->max_repl,
798 NULL)); 801 NULL));
799 rvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, 802 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
800 UINT64_MAX); 803 UINT64_MAX);
801 804
802 execute_select(plugin, 805 execute_select (plugin,
803 plugin->select_replication, 806 plugin->select_replication,
804 &repl_proc, 807 &repl_proc,
805 &rc, 808 &rc,
806 params_select); 809 params_select);
807} 810}
808 811
809 812
@@ -815,9 +818,9 @@ mysql_plugin_get_replication(void *cls,
815 * @param proc_cls closure for @a proc 818 * @param proc_cls closure for @a proc
816 */ 819 */
817static void 820static void
818mysql_plugin_get_keys(void *cls, 821mysql_plugin_get_keys (void *cls,
819 PluginKeyProcessor proc, 822 PluginKeyProcessor proc,
820 void *proc_cls) 823 void *proc_cls)
821{ 824{
822 struct Plugin *plugin = cls; 825 struct Plugin *plugin = cls;
823 int ret; 826 int ret;
@@ -829,76 +832,77 @@ mysql_plugin_get_keys(void *cls,
829 GNUNET_MY_query_param_end 832 GNUNET_MY_query_param_end
830 }; 833 };
831 struct GNUNET_MY_ResultSpec results_select[] = { 834 struct GNUNET_MY_ResultSpec results_select[] = {
832 GNUNET_MY_result_spec_auto_from_type(&key), 835 GNUNET_MY_result_spec_auto_from_type (&key),
833 GNUNET_MY_result_spec_end 836 GNUNET_MY_result_spec_end
834 }; 837 };
835 838
836 GNUNET_assert(NULL != proc); 839 GNUNET_assert (NULL != proc);
837 statement = GNUNET_MYSQL_statement_get_stmt(plugin->get_all_keys); 840 statement = GNUNET_MYSQL_statement_get_stmt (plugin->get_all_keys);
838 if (GNUNET_OK != 841 if (GNUNET_OK !=
839 GNUNET_MY_exec_prepared(plugin->mc, 842 GNUNET_MY_exec_prepared (plugin->mc,
840 plugin->get_all_keys, 843 plugin->get_all_keys,
841 params_select)) 844 params_select))
842 { 845 {
843 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 846 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
844 _("`%s' for `%s' failed at %s:%d with error: %s\n"), 847 _ ("`%s' for `%s' failed at %s:%d with error: %s\n"),
845 "mysql_stmt_execute", 848 "mysql_stmt_execute",
846 GET_ALL_KEYS, 849 GET_ALL_KEYS,
847 __FILE__, 850 __FILE__,
848 __LINE__, 851 __LINE__,
849 mysql_stmt_error(statement)); 852 mysql_stmt_error (statement));
850 GNUNET_MYSQL_statements_invalidate(plugin->mc); 853 GNUNET_MYSQL_statements_invalidate (plugin->mc);
851 proc(proc_cls, NULL, 0); 854 proc (proc_cls, NULL, 0);
852 return; 855 return;
853 } 856 }
854 memset(&last, 0, sizeof(last)); /* make static analysis happy */ 857 memset (&last, 0, sizeof(last)); /* make static analysis happy */
855 ret = GNUNET_YES; 858 ret = GNUNET_YES;
856 cnt = 0; 859 cnt = 0;
857 while (ret == GNUNET_YES) 860 while (ret == GNUNET_YES)
861 {
862 ret = GNUNET_MY_extract_result (plugin->get_all_keys,
863 results_select);
864 if (0 != GNUNET_memcmp (&last,
865 &key))
866 {
867 if (0 != cnt)
868 proc (proc_cls,
869 &last,
870 cnt);
871 cnt = 1;
872 last = key;
873 }
874 else
858 { 875 {
859 ret = GNUNET_MY_extract_result(plugin->get_all_keys, 876 cnt++;
860 results_select);
861 if (0 != GNUNET_memcmp(&last,
862 &key))
863 {
864 if (0 != cnt)
865 proc(proc_cls,
866 &last,
867 cnt);
868 cnt = 1;
869 last = key;
870 }
871 else
872 {
873 cnt++;
874 }
875 } 877 }
878 }
876 if (0 != cnt) 879 if (0 != cnt)
877 proc(proc_cls, 880 proc (proc_cls,
878 &last, 881 &last,
879 cnt); 882 cnt);
880 /* finally, let app know we are done */ 883 /* finally, let app know we are done */
881 proc(proc_cls, 884 proc (proc_cls,
882 NULL, 885 NULL,
883 0); 886 0);
884 if (GNUNET_SYSERR == ret) 887 if (GNUNET_SYSERR == ret)
885 { 888 {
886 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 889 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
887 _("`%s' failed at %s:%d with error: %s\n"), 890 _ ("`%s' failed at %s:%d with error: %s\n"),
888 "mysql_stmt_fetch", 891 "mysql_stmt_fetch",
889 __FILE__, 892 __FILE__,
890 __LINE__, 893 __LINE__,
891 mysql_stmt_error(statement)); 894 mysql_stmt_error (statement));
892 GNUNET_MYSQL_statements_invalidate(plugin->mc); 895 GNUNET_MYSQL_statements_invalidate (plugin->mc);
893 return; 896 return;
894 } 897 }
895} 898}
896 899
897 900
898/** 901/**
899 * Context for #expi_proc() function. 902 * Context for #expi_proc() function.
900 */ 903 */
901struct ExpiCtx { 904struct ExpiCtx
905{
902 /** 906 /**
903 * Plugin handle. 907 * Plugin handle.
904 */ 908 */
@@ -938,16 +942,16 @@ struct ExpiCtx {
938 * #GNUNET_NO to delete the item and continue (if supported) 942 * #GNUNET_NO to delete the item and continue (if supported)
939 */ 943 */
940static int 944static int
941expi_proc(void *cls, 945expi_proc (void *cls,
942 const struct GNUNET_HashCode *key, 946 const struct GNUNET_HashCode *key,
943 uint32_t size, 947 uint32_t size,
944 const void *data, 948 const void *data,
945 enum GNUNET_BLOCK_Type type, 949 enum GNUNET_BLOCK_Type type,
946 uint32_t priority, 950 uint32_t priority,
947 uint32_t anonymity, 951 uint32_t anonymity,
948 uint32_t replication, 952 uint32_t replication,
949 struct GNUNET_TIME_Absolute expiration, 953 struct GNUNET_TIME_Absolute expiration,
950 uint64_t uid) 954 uint64_t uid)
951{ 955{
952 struct ExpiCtx *rc = cls; 956 struct ExpiCtx *rc = cls;
953 struct Plugin *plugin = rc->plugin; 957 struct Plugin *plugin = rc->plugin;
@@ -956,24 +960,24 @@ expi_proc(void *cls,
956 }; 960 };
957 961
958 if (NULL == key) 962 if (NULL == key)
959 { 963 {
960 execute_select(plugin, 964 execute_select (plugin,
961 plugin->select_priority, 965 plugin->select_priority,
962 rc->proc, 966 rc->proc,
963 rc->proc_cls, 967 rc->proc_cls,
964 params_select); 968 params_select);
965 return GNUNET_SYSERR; 969 return GNUNET_SYSERR;
966 } 970 }
967 return rc->proc(rc->proc_cls, 971 return rc->proc (rc->proc_cls,
968 key, 972 key,
969 size, 973 size,
970 data, 974 data,
971 type, 975 type,
972 priority, 976 priority,
973 anonymity, 977 anonymity,
974 replication, 978 replication,
975 expiration, 979 expiration,
976 uid); 980 uid);
977} 981}
978 982
979 983
@@ -986,14 +990,14 @@ expi_proc(void *cls,
986 * @param proc_cls closure for @a proc 990 * @param proc_cls closure for @a proc
987 */ 991 */
988static void 992static void
989mysql_plugin_get_expiration(void *cls, 993mysql_plugin_get_expiration (void *cls,
990 PluginDatumProcessor proc, 994 PluginDatumProcessor proc,
991 void *proc_cls) 995 void *proc_cls)
992{ 996{
993 struct Plugin *plugin = cls; 997 struct Plugin *plugin = cls;
994 struct GNUNET_TIME_Absolute now; 998 struct GNUNET_TIME_Absolute now;
995 struct GNUNET_MY_QueryParam params_select[] = { 999 struct GNUNET_MY_QueryParam params_select[] = {
996 GNUNET_MY_query_param_absolute_time(&now), 1000 GNUNET_MY_query_param_absolute_time (&now),
997 GNUNET_MY_query_param_end 1001 GNUNET_MY_query_param_end
998 }; 1002 };
999 struct ExpiCtx rc; 1003 struct ExpiCtx rc;
@@ -1001,12 +1005,12 @@ mysql_plugin_get_expiration(void *cls,
1001 rc.plugin = plugin; 1005 rc.plugin = plugin;
1002 rc.proc = proc; 1006 rc.proc = proc;
1003 rc.proc_cls = proc_cls; 1007 rc.proc_cls = proc_cls;
1004 now = GNUNET_TIME_absolute_get(); 1008 now = GNUNET_TIME_absolute_get ();
1005 execute_select(plugin, 1009 execute_select (plugin,
1006 plugin->select_expiration, 1010 plugin->select_expiration,
1007 expi_proc, 1011 expi_proc,
1008 &rc, 1012 &rc,
1009 params_select); 1013 params_select);
1010} 1014}
1011 1015
1012 1016
@@ -1016,15 +1020,15 @@ mysql_plugin_get_expiration(void *cls,
1016 * @param cls the `struct Plugin *` 1020 * @param cls the `struct Plugin *`
1017 */ 1021 */
1018static void 1022static void
1019mysql_plugin_drop(void *cls) 1023mysql_plugin_drop (void *cls)
1020{ 1024{
1021 struct Plugin *plugin = cls; 1025 struct Plugin *plugin = cls;
1022 1026
1023 if (GNUNET_OK != 1027 if (GNUNET_OK !=
1024 GNUNET_MYSQL_statement_run(plugin->mc, 1028 GNUNET_MYSQL_statement_run (plugin->mc,
1025 "DROP TABLE gn090")) 1029 "DROP TABLE gn090"))
1026 return; /* error */ 1030 return; /* error */
1027 plugin->env->duc(plugin->env->cls, 0); 1031 plugin->env->duc (plugin->env->cls, 0);
1028} 1032}
1029 1033
1030 1034
@@ -1039,55 +1043,56 @@ mysql_plugin_drop(void *cls)
1039 * @param cont_cls continuation closure for @a cont 1043 * @param cont_cls continuation closure for @a cont
1040 */ 1044 */
1041static void 1045static void
1042mysql_plugin_remove_key(void *cls, 1046mysql_plugin_remove_key (void *cls,
1043 const struct GNUNET_HashCode *key, 1047 const struct GNUNET_HashCode *key,
1044 uint32_t size, 1048 uint32_t size,
1045 const void *data, 1049 const void *data,
1046 PluginRemoveCont cont, 1050 PluginRemoveCont cont,
1047 void *cont_cls) 1051 void *cont_cls)
1048{ 1052{
1049 struct Plugin *plugin = cls; 1053 struct Plugin *plugin = cls;
1050 struct GNUNET_MY_QueryParam params_delete[] = { 1054 struct GNUNET_MY_QueryParam params_delete[] = {
1051 GNUNET_MY_query_param_auto_from_type(key), 1055 GNUNET_MY_query_param_auto_from_type (key),
1052 GNUNET_MY_query_param_fixed_size(data, size), 1056 GNUNET_MY_query_param_fixed_size (data, size),
1053 GNUNET_MY_query_param_end 1057 GNUNET_MY_query_param_end
1054 }; 1058 };
1055 1059
1056 if (GNUNET_OK != 1060 if (GNUNET_OK !=
1057 GNUNET_MY_exec_prepared(plugin->mc, 1061 GNUNET_MY_exec_prepared (plugin->mc,
1058 plugin->delete_entry_by_hash_value, 1062 plugin->delete_entry_by_hash_value,
1059 params_delete)) 1063 params_delete))
1060 { 1064 {
1061 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1065 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1062 "Removing key `%s' from gn090 table failed\n", 1066 "Removing key `%s' from gn090 table failed\n",
1063 GNUNET_h2s(key)); 1067 GNUNET_h2s (key));
1064 cont(cont_cls, 1068 cont (cont_cls,
1065 key, 1069 key,
1066 size, 1070 size,
1067 GNUNET_SYSERR, 1071 GNUNET_SYSERR,
1068 _("MySQL statement run failure")); 1072 _ ("MySQL statement run failure"));
1069 return; 1073 return;
1070 } 1074 }
1071 1075
1072 MYSQL_STMT *stmt = GNUNET_MYSQL_statement_get_stmt(plugin->delete_entry_by_hash_value); 1076 MYSQL_STMT *stmt = GNUNET_MYSQL_statement_get_stmt (
1073 my_ulonglong rows = mysql_stmt_affected_rows(stmt); 1077 plugin->delete_entry_by_hash_value);
1078 my_ulonglong rows = mysql_stmt_affected_rows (stmt);
1074 1079
1075 if (0 == rows) 1080 if (0 == rows)
1076 { 1081 {
1077 cont(cont_cls, 1082 cont (cont_cls,
1078 key, 1083 key,
1079 size, 1084 size,
1080 GNUNET_NO, 1085 GNUNET_NO,
1081 NULL); 1086 NULL);
1082 return; 1087 return;
1083 } 1088 }
1084 plugin->env->duc(plugin->env->cls, 1089 plugin->env->duc (plugin->env->cls,
1085 -size); 1090 -size);
1086 cont(cont_cls, 1091 cont (cont_cls,
1087 key, 1092 key,
1088 size, 1093 size,
1089 GNUNET_OK, 1094 GNUNET_OK,
1090 NULL); 1095 NULL);
1091} 1096}
1092 1097
1093 1098
@@ -1098,23 +1103,24 @@ mysql_plugin_remove_key(void *cls,
1098 * @return our `struct Plugin *` 1103 * @return our `struct Plugin *`
1099 */ 1104 */
1100void * 1105void *
1101libgnunet_plugin_datastore_mysql_init(void *cls) 1106libgnunet_plugin_datastore_mysql_init (void *cls)
1102{ 1107{
1103 struct GNUNET_DATASTORE_PluginEnvironment *env = cls; 1108 struct GNUNET_DATASTORE_PluginEnvironment *env = cls;
1104 struct GNUNET_DATASTORE_PluginFunctions *api; 1109 struct GNUNET_DATASTORE_PluginFunctions *api;
1105 struct Plugin *plugin; 1110 struct Plugin *plugin;
1106 1111
1107 plugin = GNUNET_new(struct Plugin); 1112 plugin = GNUNET_new (struct Plugin);
1108 plugin->env = env; 1113 plugin->env = env;
1109 plugin->mc = GNUNET_MYSQL_context_create(env->cfg, 1114 plugin->mc = GNUNET_MYSQL_context_create (env->cfg,
1110 "datastore-mysql"); 1115 "datastore-mysql");
1111 if (NULL == plugin->mc) 1116 if (NULL == plugin->mc)
1112 { 1117 {
1113 GNUNET_free(plugin); 1118 GNUNET_free (plugin);
1114 return NULL; 1119 return NULL;
1115 } 1120 }
1116#define MRUNS(a) (GNUNET_OK != GNUNET_MYSQL_statement_run(plugin->mc, a)) 1121#define MRUNS(a) (GNUNET_OK != GNUNET_MYSQL_statement_run (plugin->mc, a))
1117#define PINIT(a, b) (NULL == (a = GNUNET_MYSQL_statement_prepare(plugin->mc, b))) 1122#define PINIT(a, b) (NULL == (a = GNUNET_MYSQL_statement_prepare (plugin->mc, \
1123 b)))
1118 if (MRUNS 1124 if (MRUNS
1119 ("CREATE TABLE IF NOT EXISTS gn090 (" 1125 ("CREATE TABLE IF NOT EXISTS gn090 ("
1120 " repl INT(11) UNSIGNED NOT NULL DEFAULT 0," 1126 " repl INT(11) UNSIGNED NOT NULL DEFAULT 0,"
@@ -1125,40 +1131,41 @@ libgnunet_plugin_datastore_mysql_init(void *cls)
1125 " rvalue BIGINT UNSIGNED NOT NULL," 1131 " rvalue BIGINT UNSIGNED NOT NULL,"
1126 " hash BINARY(64) NOT NULL DEFAULT ''," 1132 " hash BINARY(64) NOT NULL DEFAULT '',"
1127 " vhash BINARY(64) NOT NULL DEFAULT ''," 1133 " vhash BINARY(64) NOT NULL DEFAULT '',"
1128 " value BLOB NOT NULL DEFAULT ''," " uid BIGINT NOT NULL AUTO_INCREMENT," 1134 " value BLOB NOT NULL DEFAULT '',"
1135 " uid BIGINT NOT NULL AUTO_INCREMENT,"
1129 " PRIMARY KEY (uid)," 1136 " PRIMARY KEY (uid),"
1130 " INDEX idx_hash_type_uid (hash(64),type,rvalue)," 1137 " INDEX idx_hash_type_uid (hash(64),type,rvalue),"
1131 " INDEX idx_prio (prio)," 1138 " INDEX idx_prio (prio),"
1132 " INDEX idx_repl_rvalue (repl,rvalue)," 1139 " INDEX idx_repl_rvalue (repl,rvalue),"
1133 " INDEX idx_expire (expire)," 1140 " INDEX idx_expire (expire),"
1134 " INDEX idx_anonLevel_type_rvalue (anonLevel,type,rvalue)" 1141 " INDEX idx_anonLevel_type_rvalue (anonLevel,type,rvalue)"
1135 ") ENGINE=InnoDB") || MRUNS("SET AUTOCOMMIT = 1") || 1142 ") ENGINE=InnoDB") || MRUNS ("SET AUTOCOMMIT = 1") ||
1136 PINIT(plugin->insert_entry, INSERT_ENTRY) || 1143 PINIT (plugin->insert_entry, INSERT_ENTRY) ||
1137 PINIT(plugin->delete_entry_by_uid, DELETE_ENTRY_BY_UID) || 1144 PINIT (plugin->delete_entry_by_uid, DELETE_ENTRY_BY_UID) ||
1138 PINIT(plugin->delete_entry_by_hash_value, DELETE_ENTRY_BY_HASH_VALUE) || 1145 PINIT (plugin->delete_entry_by_hash_value, DELETE_ENTRY_BY_HASH_VALUE) ||
1139 PINIT(plugin->select_entry, SELECT_ENTRY) || 1146 PINIT (plugin->select_entry, SELECT_ENTRY) ||
1140 PINIT(plugin->select_entry_by_hash, SELECT_ENTRY_BY_HASH) || 1147 PINIT (plugin->select_entry_by_hash, SELECT_ENTRY_BY_HASH) ||
1141 PINIT(plugin->select_entry_by_hash_and_type, 1148 PINIT (plugin->select_entry_by_hash_and_type,
1142 SELECT_ENTRY_BY_HASH_AND_TYPE) || 1149 SELECT_ENTRY_BY_HASH_AND_TYPE) ||
1143 PINIT(plugin->get_size, SELECT_SIZE) || 1150 PINIT (plugin->get_size, SELECT_SIZE) ||
1144 PINIT(plugin->update_entry, UPDATE_ENTRY) || 1151 PINIT (plugin->update_entry, UPDATE_ENTRY) ||
1145 PINIT(plugin->dec_repl, DEC_REPL) || 1152 PINIT (plugin->dec_repl, DEC_REPL) ||
1146 PINIT(plugin->zero_iter, SELECT_IT_NON_ANONYMOUS) || 1153 PINIT (plugin->zero_iter, SELECT_IT_NON_ANONYMOUS) ||
1147 PINIT(plugin->select_expiration, SELECT_IT_EXPIRATION) || 1154 PINIT (plugin->select_expiration, SELECT_IT_EXPIRATION) ||
1148 PINIT(plugin->select_priority, SELECT_IT_PRIORITY) || 1155 PINIT (plugin->select_priority, SELECT_IT_PRIORITY) ||
1149 PINIT(plugin->max_repl, SELECT_MAX_REPL) || 1156 PINIT (plugin->max_repl, SELECT_MAX_REPL) ||
1150 PINIT(plugin->get_all_keys, GET_ALL_KEYS) || 1157 PINIT (plugin->get_all_keys, GET_ALL_KEYS) ||
1151 PINIT(plugin->select_replication, SELECT_IT_REPLICATION) || 1158 PINIT (plugin->select_replication, SELECT_IT_REPLICATION) ||
1152 false) 1159 false)
1153 { 1160 {
1154 GNUNET_MYSQL_context_destroy(plugin->mc); 1161 GNUNET_MYSQL_context_destroy (plugin->mc);
1155 GNUNET_free(plugin); 1162 GNUNET_free (plugin);
1156 return NULL; 1163 return NULL;
1157 } 1164 }
1158#undef PINIT 1165#undef PINIT
1159#undef MRUNS 1166#undef MRUNS
1160 1167
1161 api = GNUNET_new(struct GNUNET_DATASTORE_PluginFunctions); 1168 api = GNUNET_new (struct GNUNET_DATASTORE_PluginFunctions);
1162 api->cls = plugin; 1169 api->cls = plugin;
1163 api->estimate_size = &mysql_plugin_estimate_size; 1170 api->estimate_size = &mysql_plugin_estimate_size;
1164 api->put = &mysql_plugin_put; 1171 api->put = &mysql_plugin_put;
@@ -1169,8 +1176,8 @@ libgnunet_plugin_datastore_mysql_init(void *cls)
1169 api->get_keys = &mysql_plugin_get_keys; 1176 api->get_keys = &mysql_plugin_get_keys;
1170 api->drop = &mysql_plugin_drop; 1177 api->drop = &mysql_plugin_drop;
1171 api->remove_key = &mysql_plugin_remove_key; 1178 api->remove_key = &mysql_plugin_remove_key;
1172 GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "mysql", 1179 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "mysql",
1173 _("Mysql database running\n")); 1180 _ ("Mysql database running\n"));
1174 return api; 1181 return api;
1175} 1182}
1176 1183
@@ -1182,14 +1189,14 @@ libgnunet_plugin_datastore_mysql_init(void *cls)
1182 * @return always NULL 1189 * @return always NULL
1183 */ 1190 */
1184void * 1191void *
1185libgnunet_plugin_datastore_mysql_done(void *cls) 1192libgnunet_plugin_datastore_mysql_done (void *cls)
1186{ 1193{
1187 struct GNUNET_DATASTORE_PluginFunctions *api = cls; 1194 struct GNUNET_DATASTORE_PluginFunctions *api = cls;
1188 struct Plugin *plugin = api->cls; 1195 struct Plugin *plugin = api->cls;
1189 1196
1190 GNUNET_MYSQL_context_destroy(plugin->mc); 1197 GNUNET_MYSQL_context_destroy (plugin->mc);
1191 GNUNET_free(plugin); 1198 GNUNET_free (plugin);
1192 GNUNET_free(api); 1199 GNUNET_free (api);
1193 return NULL; 1200 return NULL;
1194} 1201}
1195 1202
diff --git a/src/datastore/plugin_datastore_postgres.c b/src/datastore/plugin_datastore_postgres.c
index 17b645585..181cf8cf8 100644
--- a/src/datastore/plugin_datastore_postgres.c
+++ b/src/datastore/plugin_datastore_postgres.c
@@ -44,7 +44,8 @@
44/** 44/**
45 * Context for all functions in this plugin. 45 * Context for all functions in this plugin.
46 */ 46 */
47struct Plugin { 47struct Plugin
48{
48 /** 49 /**
49 * Our execution environment. 50 * Our execution environment.
50 */ 51 */
@@ -64,7 +65,7 @@ struct Plugin {
64 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 65 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
65 */ 66 */
66static int 67static int
67init_connection(struct Plugin *plugin) 68init_connection (struct Plugin *plugin)
68{ 69{
69 struct GNUNET_PQ_ExecuteStatement es[] = { 70 struct GNUNET_PQ_ExecuteStatement es[] = {
70 /* FIXME: PostgreSQL does not have unsigned integers! This is ok for the type column because 71 /* FIXME: PostgreSQL does not have unsigned integers! This is ok for the type column because
@@ -73,111 +74,119 @@ init_connection(struct Plugin *plugin)
73 * This will also cause problems for expiration times after 294247-01-10-04:00:54 UTC. 74 * This will also cause problems for expiration times after 294247-01-10-04:00:54 UTC.
74 * PostgreSQL also recommends against using WITH OIDS. 75 * PostgreSQL also recommends against using WITH OIDS.
75 */ 76 */
76 GNUNET_PQ_make_execute("CREATE TABLE IF NOT EXISTS gn090 (" 77 GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS gn090 ("
77 " repl INTEGER NOT NULL DEFAULT 0," 78 " repl INTEGER NOT NULL DEFAULT 0,"
78 " type INTEGER NOT NULL DEFAULT 0," 79 " type INTEGER NOT NULL DEFAULT 0,"
79 " prio INTEGER NOT NULL DEFAULT 0," 80 " prio INTEGER NOT NULL DEFAULT 0,"
80 " anonLevel INTEGER NOT NULL DEFAULT 0," 81 " anonLevel INTEGER NOT NULL DEFAULT 0,"
81 " expire BIGINT NOT NULL DEFAULT 0," 82 " expire BIGINT NOT NULL DEFAULT 0,"
82 " rvalue BIGINT NOT NULL DEFAULT 0," 83 " rvalue BIGINT NOT NULL DEFAULT 0,"
83 " hash BYTEA NOT NULL DEFAULT ''," 84 " hash BYTEA NOT NULL DEFAULT '',"
84 " vhash BYTEA NOT NULL DEFAULT ''," 85 " vhash BYTEA NOT NULL DEFAULT '',"
85 " value BYTEA NOT NULL DEFAULT '')" 86 " value BYTEA NOT NULL DEFAULT '')"
86 "WITH OIDS"), 87 "WITH OIDS"),
87 GNUNET_PQ_make_try_execute("CREATE INDEX IF NOT EXISTS idx_hash ON gn090 (hash)"), 88 GNUNET_PQ_make_try_execute (
88 GNUNET_PQ_make_try_execute("CREATE INDEX IF NOT EXISTS idx_prio ON gn090 (prio)"), 89 "CREATE INDEX IF NOT EXISTS idx_hash ON gn090 (hash)"),
89 GNUNET_PQ_make_try_execute("CREATE INDEX IF NOT EXISTS idx_expire ON gn090 (expire)"), 90 GNUNET_PQ_make_try_execute (
90 GNUNET_PQ_make_try_execute("CREATE INDEX IF NOT EXISTS idx_prio_anon ON gn090 (prio,anonLevel)"), 91 "CREATE INDEX IF NOT EXISTS idx_prio ON gn090 (prio)"),
91 GNUNET_PQ_make_try_execute("CREATE INDEX IF NOT EXISTS idx_prio_hash_anon ON gn090 (prio,hash,anonLevel)"), 92 GNUNET_PQ_make_try_execute (
92 GNUNET_PQ_make_try_execute("CREATE INDEX IF NOT EXISTS idx_repl_rvalue ON gn090 (repl,rvalue)"), 93 "CREATE INDEX IF NOT EXISTS idx_expire ON gn090 (expire)"),
93 GNUNET_PQ_make_try_execute("CREATE INDEX IF NOT EXISTS idx_expire_hash ON gn090 (expire,hash)"), 94 GNUNET_PQ_make_try_execute (
94 GNUNET_PQ_make_execute("ALTER TABLE gn090 ALTER value SET STORAGE EXTERNAL"), 95 "CREATE INDEX IF NOT EXISTS idx_prio_anon ON gn090 (prio,anonLevel)"),
95 GNUNET_PQ_make_execute("ALTER TABLE gn090 ALTER hash SET STORAGE PLAIN"), 96 GNUNET_PQ_make_try_execute (
96 GNUNET_PQ_make_execute("ALTER TABLE gn090 ALTER vhash SET STORAGE PLAIN"), 97 "CREATE INDEX IF NOT EXISTS idx_prio_hash_anon ON gn090 (prio,hash,anonLevel)"),
98 GNUNET_PQ_make_try_execute (
99 "CREATE INDEX IF NOT EXISTS idx_repl_rvalue ON gn090 (repl,rvalue)"),
100 GNUNET_PQ_make_try_execute (
101 "CREATE INDEX IF NOT EXISTS idx_expire_hash ON gn090 (expire,hash)"),
102 GNUNET_PQ_make_execute (
103 "ALTER TABLE gn090 ALTER value SET STORAGE EXTERNAL"),
104 GNUNET_PQ_make_execute ("ALTER TABLE gn090 ALTER hash SET STORAGE PLAIN"),
105 GNUNET_PQ_make_execute ("ALTER TABLE gn090 ALTER vhash SET STORAGE PLAIN"),
97 GNUNET_PQ_EXECUTE_STATEMENT_END 106 GNUNET_PQ_EXECUTE_STATEMENT_END
98 }; 107 };
99 108
100#define RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, oid" 109#define RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, oid"
101 struct GNUNET_PQ_PreparedStatement ps[] = { 110 struct GNUNET_PQ_PreparedStatement ps[] = {
102 GNUNET_PQ_make_prepare("get", 111 GNUNET_PQ_make_prepare ("get",
103 "SELECT " RESULT_COLUMNS " FROM gn090" 112 "SELECT " RESULT_COLUMNS " FROM gn090"
104 " WHERE oid >= $1::bigint AND" 113 " WHERE oid >= $1::bigint AND"
105 " (rvalue >= $2 OR 0 = $3::smallint) AND" 114 " (rvalue >= $2 OR 0 = $3::smallint) AND"
106 " (hash = $4 OR 0 = $5::smallint) AND" 115 " (hash = $4 OR 0 = $5::smallint) AND"
107 " (type = $6 OR 0 = $7::smallint)" 116 " (type = $6 OR 0 = $7::smallint)"
108 " ORDER BY oid ASC LIMIT 1", 117 " ORDER BY oid ASC LIMIT 1",
109 7), 118 7),
110 GNUNET_PQ_make_prepare("put", 119 GNUNET_PQ_make_prepare ("put",
111 "INSERT INTO gn090 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) " 120 "INSERT INTO gn090 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) "
112 "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", 121 "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
113 9), 122 9),
114 GNUNET_PQ_make_prepare("update", 123 GNUNET_PQ_make_prepare ("update",
115 "UPDATE gn090" 124 "UPDATE gn090"
116 " SET prio = prio + $1," 125 " SET prio = prio + $1,"
117 " repl = repl + $2," 126 " repl = repl + $2,"
118 " expire = GREATEST(expire, $3)" 127 " expire = GREATEST(expire, $3)"
119 " WHERE hash = $4 AND vhash = $5", 128 " WHERE hash = $4 AND vhash = $5",
120 5), 129 5),
121 GNUNET_PQ_make_prepare("decrepl", 130 GNUNET_PQ_make_prepare ("decrepl",
122 "UPDATE gn090 SET repl = GREATEST (repl - 1, 0) " 131 "UPDATE gn090 SET repl = GREATEST (repl - 1, 0) "
123 "WHERE oid = $1", 132 "WHERE oid = $1",
124 1), 133 1),
125 GNUNET_PQ_make_prepare("select_non_anonymous", 134 GNUNET_PQ_make_prepare ("select_non_anonymous",
126 "SELECT " RESULT_COLUMNS " FROM gn090 " 135 "SELECT " RESULT_COLUMNS " FROM gn090 "
127 "WHERE anonLevel = 0 AND type = $1 AND oid >= $2::bigint " 136 "WHERE anonLevel = 0 AND type = $1 AND oid >= $2::bigint "
128 "ORDER BY oid ASC LIMIT 1", 137 "ORDER BY oid ASC LIMIT 1",
129 2), 138 2),
130 GNUNET_PQ_make_prepare("select_expiration_order", 139 GNUNET_PQ_make_prepare ("select_expiration_order",
131 "(SELECT " RESULT_COLUMNS " FROM gn090 " 140 "(SELECT " RESULT_COLUMNS " FROM gn090 "
132 "WHERE expire < $1 ORDER BY prio ASC LIMIT 1) " 141 "WHERE expire < $1 ORDER BY prio ASC LIMIT 1) "
133 "UNION " 142 "UNION "
134 "(SELECT " RESULT_COLUMNS " FROM gn090 " 143 "(SELECT " RESULT_COLUMNS " FROM gn090 "
135 "ORDER BY prio ASC LIMIT 1) " 144 "ORDER BY prio ASC LIMIT 1) "
136 "ORDER BY expire ASC LIMIT 1", 145 "ORDER BY expire ASC LIMIT 1",
137 1), 146 1),
138 GNUNET_PQ_make_prepare("select_replication_order", 147 GNUNET_PQ_make_prepare ("select_replication_order",
139 "SELECT " RESULT_COLUMNS " FROM gn090 " 148 "SELECT " RESULT_COLUMNS " FROM gn090 "
140 "ORDER BY repl DESC,RANDOM() LIMIT 1", 149 "ORDER BY repl DESC,RANDOM() LIMIT 1",
141 0), 150 0),
142 GNUNET_PQ_make_prepare("delrow", 151 GNUNET_PQ_make_prepare ("delrow",
143 "DELETE FROM gn090 " 152 "DELETE FROM gn090 "
144 "WHERE oid=$1", 153 "WHERE oid=$1",
145 1), 154 1),
146 GNUNET_PQ_make_prepare("remove", 155 GNUNET_PQ_make_prepare ("remove",
147 "DELETE FROM gn090" 156 "DELETE FROM gn090"
148 " WHERE hash = $1 AND" 157 " WHERE hash = $1 AND"
149 " value = $2", 158 " value = $2",
150 2), 159 2),
151 GNUNET_PQ_make_prepare("get_keys", 160 GNUNET_PQ_make_prepare ("get_keys",
152 "SELECT hash FROM gn090", 161 "SELECT hash FROM gn090",
153 0), 162 0),
154 GNUNET_PQ_make_prepare("estimate_size", 163 GNUNET_PQ_make_prepare ("estimate_size",
155 "SELECT CASE WHEN NOT EXISTS" 164 "SELECT CASE WHEN NOT EXISTS"
156 " (SELECT 1 FROM gn090)" 165 " (SELECT 1 FROM gn090)"
157 " THEN 0" 166 " THEN 0"
158 " ELSE (SELECT SUM(LENGTH(value))+256*COUNT(*) FROM gn090)" 167 " ELSE (SELECT SUM(LENGTH(value))+256*COUNT(*) FROM gn090)"
159 "END AS total", 168 "END AS total",
160 0), 169 0),
161 GNUNET_PQ_PREPARED_STATEMENT_END 170 GNUNET_PQ_PREPARED_STATEMENT_END
162 }; 171 };
163#undef RESULT_COLUMNS 172#undef RESULT_COLUMNS
164 173
165 plugin->dbh = GNUNET_PQ_connect_with_cfg(plugin->env->cfg, 174 plugin->dbh = GNUNET_PQ_connect_with_cfg (plugin->env->cfg,
166 "datastore-postgres"); 175 "datastore-postgres");
167 if (NULL == plugin->dbh) 176 if (NULL == plugin->dbh)
168 return GNUNET_SYSERR; 177 return GNUNET_SYSERR;
169 178
170 if ((GNUNET_OK != 179 if ((GNUNET_OK !=
171 GNUNET_PQ_exec_statements(plugin->dbh, 180 GNUNET_PQ_exec_statements (plugin->dbh,
172 es)) || 181 es)) ||
173 (GNUNET_OK != 182 (GNUNET_OK !=
174 GNUNET_PQ_prepare_statements(plugin->dbh, 183 GNUNET_PQ_prepare_statements (plugin->dbh,
175 ps))) 184 ps)))
176 { 185 {
177 PQfinish(plugin->dbh); 186 PQfinish (plugin->dbh);
178 plugin->dbh = NULL; 187 plugin->dbh = NULL;
179 return GNUNET_SYSERR; 188 return GNUNET_SYSERR;
180 } 189 }
181 return GNUNET_OK; 190 return GNUNET_OK;
182} 191}
183 192
@@ -190,8 +199,8 @@ init_connection(struct Plugin *plugin)
190 * @return number of bytes used on disk 199 * @return number of bytes used on disk
191 */ 200 */
192static void 201static void
193postgres_plugin_estimate_size(void *cls, 202postgres_plugin_estimate_size (void *cls,
194 unsigned long long *estimate) 203 unsigned long long *estimate)
195{ 204{
196 struct Plugin *plugin = cls; 205 struct Plugin *plugin = cls;
197 uint64_t total; 206 uint64_t total;
@@ -199,23 +208,23 @@ postgres_plugin_estimate_size(void *cls,
199 GNUNET_PQ_query_param_end 208 GNUNET_PQ_query_param_end
200 }; 209 };
201 struct GNUNET_PQ_ResultSpec rs[] = { 210 struct GNUNET_PQ_ResultSpec rs[] = {
202 GNUNET_PQ_result_spec_uint64("total", 211 GNUNET_PQ_result_spec_uint64 ("total",
203 &total), 212 &total),
204 GNUNET_PQ_result_spec_end 213 GNUNET_PQ_result_spec_end
205 }; 214 };
206 enum GNUNET_DB_QueryStatus ret; 215 enum GNUNET_DB_QueryStatus ret;
207 216
208 if (NULL == estimate) 217 if (NULL == estimate)
209 return; 218 return;
210 ret = GNUNET_PQ_eval_prepared_singleton_select(plugin->dbh, 219 ret = GNUNET_PQ_eval_prepared_singleton_select (plugin->dbh,
211 "estimate_size", 220 "estimate_size",
212 params, 221 params,
213 rs); 222 rs);
214 if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != ret) 223 if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != ret)
215 { 224 {
216 *estimate = 0LL; 225 *estimate = 0LL;
217 return; 226 return;
218 } 227 }
219 *estimate = total; 228 *estimate = total;
220} 229}
221 230
@@ -237,108 +246,109 @@ postgres_plugin_estimate_size(void *cls,
237 * @param cont_cls continuation closure 246 * @param cont_cls continuation closure
238 */ 247 */
239static void 248static void
240postgres_plugin_put(void *cls, 249postgres_plugin_put (void *cls,
241 const struct GNUNET_HashCode *key, 250 const struct GNUNET_HashCode *key,
242 bool absent, 251 bool absent,
243 uint32_t size, 252 uint32_t size,
244 const void *data, 253 const void *data,
245 enum GNUNET_BLOCK_Type type, 254 enum GNUNET_BLOCK_Type type,
246 uint32_t priority, 255 uint32_t priority,
247 uint32_t anonymity, 256 uint32_t anonymity,
248 uint32_t replication, 257 uint32_t replication,
249 struct GNUNET_TIME_Absolute expiration, 258 struct GNUNET_TIME_Absolute expiration,
250 PluginPutCont cont, 259 PluginPutCont cont,
251 void *cont_cls) 260 void *cont_cls)
252{ 261{
253 struct Plugin *plugin = cls; 262 struct Plugin *plugin = cls;
254 struct GNUNET_HashCode vhash; 263 struct GNUNET_HashCode vhash;
255 enum GNUNET_DB_QueryStatus ret; 264 enum GNUNET_DB_QueryStatus ret;
256 265
257 GNUNET_CRYPTO_hash(data, 266 GNUNET_CRYPTO_hash (data,
258 size, 267 size,
259 &vhash); 268 &vhash);
260 if (!absent) 269 if (! absent)
270 {
271 struct GNUNET_PQ_QueryParam params[] = {
272 GNUNET_PQ_query_param_uint32 (&priority),
273 GNUNET_PQ_query_param_uint32 (&replication),
274 GNUNET_PQ_query_param_absolute_time (&expiration),
275 GNUNET_PQ_query_param_auto_from_type (key),
276 GNUNET_PQ_query_param_auto_from_type (&vhash),
277 GNUNET_PQ_query_param_end
278 };
279 ret = GNUNET_PQ_eval_prepared_non_select (plugin->dbh,
280 "update",
281 params);
282 if (0 > ret)
261 { 283 {
262 struct GNUNET_PQ_QueryParam params[] = { 284 cont (cont_cls,
263 GNUNET_PQ_query_param_uint32(&priority), 285 key,
264 GNUNET_PQ_query_param_uint32(&replication), 286 size,
265 GNUNET_PQ_query_param_absolute_time(&expiration), 287 GNUNET_SYSERR,
266 GNUNET_PQ_query_param_auto_from_type(key), 288 _ ("Postgress exec failure"));
267 GNUNET_PQ_query_param_auto_from_type(&vhash), 289 return;
268 GNUNET_PQ_query_param_end 290 }
269 }; 291 bool affected = (0 != ret);
270 ret = GNUNET_PQ_eval_prepared_non_select(plugin->dbh, 292 if (affected)
271 "update", 293 {
272 params); 294 cont (cont_cls,
273 if (0 > ret) 295 key,
274 { 296 size,
275 cont(cont_cls, 297 GNUNET_NO,
276 key, 298 NULL);
277 size, 299 return;
278 GNUNET_SYSERR,
279 _("Postgress exec failure"));
280 return;
281 }
282 bool affected = (0 != ret);
283 if (affected)
284 {
285 cont(cont_cls,
286 key,
287 size,
288 GNUNET_NO,
289 NULL);
290 return;
291 }
292 } 300 }
301 }
293 302
294 { 303 {
295 uint32_t utype = (uint32_t)type; 304 uint32_t utype = (uint32_t) type;
296 uint64_t rvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, 305 uint64_t rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
297 UINT64_MAX); 306 UINT64_MAX);
298 struct GNUNET_PQ_QueryParam params[] = { 307 struct GNUNET_PQ_QueryParam params[] = {
299 GNUNET_PQ_query_param_uint32(&replication), 308 GNUNET_PQ_query_param_uint32 (&replication),
300 GNUNET_PQ_query_param_uint32(&utype), 309 GNUNET_PQ_query_param_uint32 (&utype),
301 GNUNET_PQ_query_param_uint32(&priority), 310 GNUNET_PQ_query_param_uint32 (&priority),
302 GNUNET_PQ_query_param_uint32(&anonymity), 311 GNUNET_PQ_query_param_uint32 (&anonymity),
303 GNUNET_PQ_query_param_absolute_time(&expiration), 312 GNUNET_PQ_query_param_absolute_time (&expiration),
304 GNUNET_PQ_query_param_uint64(&rvalue), 313 GNUNET_PQ_query_param_uint64 (&rvalue),
305 GNUNET_PQ_query_param_auto_from_type(key), 314 GNUNET_PQ_query_param_auto_from_type (key),
306 GNUNET_PQ_query_param_auto_from_type(&vhash), 315 GNUNET_PQ_query_param_auto_from_type (&vhash),
307 GNUNET_PQ_query_param_fixed_size(data, size), 316 GNUNET_PQ_query_param_fixed_size (data, size),
308 GNUNET_PQ_query_param_end 317 GNUNET_PQ_query_param_end
309 }; 318 };
310 319
311 ret = GNUNET_PQ_eval_prepared_non_select(plugin->dbh, 320 ret = GNUNET_PQ_eval_prepared_non_select (plugin->dbh,
312 "put", 321 "put",
313 params); 322 params);
314 if (0 > ret) 323 if (0 > ret)
315 { 324 {
316 cont(cont_cls, 325 cont (cont_cls,
317 key, 326 key,
318 size, 327 size,
319 GNUNET_SYSERR, 328 GNUNET_SYSERR,
320 "Postgress exec failure"); 329 "Postgress exec failure");
321 return; 330 return;
322 } 331 }
323 } 332 }
324 plugin->env->duc(plugin->env->cls, 333 plugin->env->duc (plugin->env->cls,
325 size + GNUNET_DATASTORE_ENTRY_OVERHEAD); 334 size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
326 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, 335 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
327 "datastore-postgres", 336 "datastore-postgres",
328 "Stored %u bytes in database\n", 337 "Stored %u bytes in database\n",
329 (unsigned int)size); 338 (unsigned int) size);
330 cont(cont_cls, 339 cont (cont_cls,
331 key, 340 key,
332 size, 341 size,
333 GNUNET_OK, 342 GNUNET_OK,
334 NULL); 343 NULL);
335} 344}
336 345
337 346
338/** 347/**
339 * Closure for #process_result. 348 * Closure for #process_result.
340 */ 349 */
341struct ProcessResultContext { 350struct ProcessResultContext
351{
342 /** 352 /**
343 * The plugin handle. 353 * The plugin handle.
344 */ 354 */
@@ -365,111 +375,111 @@ struct ProcessResultContext {
365 * @param num_results number of results in @a res 375 * @param num_results number of results in @a res
366 */ 376 */
367static void 377static void
368process_result(void *cls, 378process_result (void *cls,
369 PGresult *res, 379 PGresult *res,
370 unsigned int num_results) 380 unsigned int num_results)
371{ 381{
372 struct ProcessResultContext *prc = cls; 382 struct ProcessResultContext *prc = cls;
373 struct Plugin *plugin = prc->plugin; 383 struct Plugin *plugin = prc->plugin;
374 384
375 if (0 == num_results) 385 if (0 == num_results)
376 { 386 {
377 /* no result */ 387 /* no result */
378 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, 388 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
379 "datastore-postgres", 389 "datastore-postgres",
380 "Ending iteration (no more results)\n"); 390 "Ending iteration (no more results)\n");
381 prc->proc(prc->proc_cls, NULL, 0, NULL, 0, 0, 0, 0, 391 prc->proc (prc->proc_cls, NULL, 0, NULL, 0, 0, 0, 0,
382 GNUNET_TIME_UNIT_ZERO_ABS, 0); 392 GNUNET_TIME_UNIT_ZERO_ABS, 0);
383 return; 393 return;
384 } 394 }
385 if (1 != num_results) 395 if (1 != num_results)
386 { 396 {
387 GNUNET_break(0); 397 GNUNET_break (0);
388 prc->proc(prc->proc_cls, NULL, 0, NULL, 0, 0, 0, 0, 398 prc->proc (prc->proc_cls, NULL, 0, NULL, 0, 0, 0, 0,
389 GNUNET_TIME_UNIT_ZERO_ABS, 0); 399 GNUNET_TIME_UNIT_ZERO_ABS, 0);
390 return; 400 return;
391 } 401 }
392 /* Technically we don't need the loop here, but nicer in case 402 /* Technically we don't need the loop here, but nicer in case
393 we ever relax the condition above. */ 403 we ever relax the condition above. */
394 for (unsigned int i = 0; i < num_results; i++) 404 for (unsigned int i = 0; i < num_results; i++)
405 {
406 int iret;
407 uint32_t rowid;
408 uint32_t utype;
409 uint32_t anonymity;
410 uint32_t replication;
411 uint32_t priority;
412 size_t size;
413 void *data;
414 struct GNUNET_TIME_Absolute expiration_time;
415 struct GNUNET_HashCode key;
416 struct GNUNET_PQ_ResultSpec rs[] = {
417 GNUNET_PQ_result_spec_uint32 ("repl", &replication),
418 GNUNET_PQ_result_spec_uint32 ("type", &utype),
419 GNUNET_PQ_result_spec_uint32 ("prio", &priority),
420 GNUNET_PQ_result_spec_uint32 ("anonLevel", &anonymity),
421 GNUNET_PQ_result_spec_absolute_time ("expire", &expiration_time),
422 GNUNET_PQ_result_spec_auto_from_type ("hash", &key),
423 GNUNET_PQ_result_spec_variable_size ("value", &data, &size),
424 GNUNET_PQ_result_spec_uint32 ("oid", &rowid),
425 GNUNET_PQ_result_spec_end
426 };
427
428 if (GNUNET_OK !=
429 GNUNET_PQ_extract_result (res,
430 rs,
431 i))
395 { 432 {
396 int iret; 433 GNUNET_break (0);
397 uint32_t rowid; 434 prc->proc (prc->proc_cls, NULL, 0, NULL, 0, 0, 0, 0,
398 uint32_t utype; 435 GNUNET_TIME_UNIT_ZERO_ABS, 0);
399 uint32_t anonymity; 436 return;
400 uint32_t replication; 437 }
401 uint32_t priority; 438
402 size_t size; 439 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
403 void *data; 440 "datastore-postgres",
404 struct GNUNET_TIME_Absolute expiration_time; 441 "Found result of size %u bytes and type %u in database\n",
405 struct GNUNET_HashCode key; 442 (unsigned int) size,
406 struct GNUNET_PQ_ResultSpec rs[] = { 443 (unsigned int) utype);
407 GNUNET_PQ_result_spec_uint32("repl", &replication), 444 iret = prc->proc (prc->proc_cls,
408 GNUNET_PQ_result_spec_uint32("type", &utype), 445 &key,
409 GNUNET_PQ_result_spec_uint32("prio", &priority), 446 size,
410 GNUNET_PQ_result_spec_uint32("anonLevel", &anonymity), 447 data,
411 GNUNET_PQ_result_spec_absolute_time("expire", &expiration_time), 448 (enum GNUNET_BLOCK_Type) utype,
412 GNUNET_PQ_result_spec_auto_from_type("hash", &key), 449 priority,
413 GNUNET_PQ_result_spec_variable_size("value", &data, &size), 450 anonymity,
414 GNUNET_PQ_result_spec_uint32("oid", &rowid), 451 replication,
415 GNUNET_PQ_result_spec_end 452 expiration_time,
453 rowid);
454 if (iret == GNUNET_NO)
455 {
456 struct GNUNET_PQ_QueryParam param[] = {
457 GNUNET_PQ_query_param_uint32 (&rowid),
458 GNUNET_PQ_query_param_end
416 }; 459 };
417 460
418 if (GNUNET_OK != 461 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
419 GNUNET_PQ_extract_result(res, 462 "Processor asked for item %u to be removed.\n",
420 rs, 463 (unsigned int) rowid);
421 i)) 464 if (0 <
422 { 465 GNUNET_PQ_eval_prepared_non_select (plugin->dbh,
423 GNUNET_break(0); 466 "delrow",
424 prc->proc(prc->proc_cls, NULL, 0, NULL, 0, 0, 0, 0, 467 param))
425 GNUNET_TIME_UNIT_ZERO_ABS, 0); 468 {
426 return; 469 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
427 } 470 "datastore-postgres",
428 471 "Deleting %u bytes from database\n",
429 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, 472 (unsigned int) size);
430 "datastore-postgres", 473 plugin->env->duc (plugin->env->cls,
431 "Found result of size %u bytes and type %u in database\n", 474 -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
432 (unsigned int)size, 475 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
433 (unsigned int)utype); 476 "datastore-postgres",
434 iret = prc->proc(prc->proc_cls, 477 "Deleted %u bytes from database\n",
435 &key, 478 (unsigned int) size);
436 size, 479 }
437 data, 480 }
438 (enum GNUNET_BLOCK_Type)utype, 481 GNUNET_PQ_cleanup_result (rs);
439 priority, 482 } /* for (i) */
440 anonymity,
441 replication,
442 expiration_time,
443 rowid);
444 if (iret == GNUNET_NO)
445 {
446 struct GNUNET_PQ_QueryParam param[] = {
447 GNUNET_PQ_query_param_uint32(&rowid),
448 GNUNET_PQ_query_param_end
449 };
450
451 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
452 "Processor asked for item %u to be removed.\n",
453 (unsigned int)rowid);
454 if (0 <
455 GNUNET_PQ_eval_prepared_non_select(plugin->dbh,
456 "delrow",
457 param))
458 {
459 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG,
460 "datastore-postgres",
461 "Deleting %u bytes from database\n",
462 (unsigned int)size);
463 plugin->env->duc(plugin->env->cls,
464 -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
465 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG,
466 "datastore-postgres",
467 "Deleted %u bytes from database\n",
468 (unsigned int)size);
469 }
470 }
471 GNUNET_PQ_cleanup_result(rs);
472 } /* for (i) */
473} 483}
474 484
475 485
@@ -487,13 +497,13 @@ process_result(void *cls,
487 * @param proc_cls closure for @a proc 497 * @param proc_cls closure for @a proc
488 */ 498 */
489static void 499static void
490postgres_plugin_get_key(void *cls, 500postgres_plugin_get_key (void *cls,
491 uint64_t next_uid, 501 uint64_t next_uid,
492 bool random, 502 bool random,
493 const struct GNUNET_HashCode *key, 503 const struct GNUNET_HashCode *key,
494 enum GNUNET_BLOCK_Type type, 504 enum GNUNET_BLOCK_Type type,
495 PluginDatumProcessor proc, 505 PluginDatumProcessor proc,
496 void *proc_cls) 506 void *proc_cls)
497{ 507{
498 struct Plugin *plugin = cls; 508 struct Plugin *plugin = cls;
499 uint32_t utype = type; 509 uint32_t utype = type;
@@ -502,40 +512,40 @@ postgres_plugin_get_key(void *cls,
502 uint16_t use_type = GNUNET_BLOCK_TYPE_ANY != type; 512 uint16_t use_type = GNUNET_BLOCK_TYPE_ANY != type;
503 uint64_t rvalue; 513 uint64_t rvalue;
504 struct GNUNET_PQ_QueryParam params[] = { 514 struct GNUNET_PQ_QueryParam params[] = {
505 GNUNET_PQ_query_param_uint64(&next_uid), 515 GNUNET_PQ_query_param_uint64 (&next_uid),
506 GNUNET_PQ_query_param_uint64(&rvalue), 516 GNUNET_PQ_query_param_uint64 (&rvalue),
507 GNUNET_PQ_query_param_uint16(&use_rvalue), 517 GNUNET_PQ_query_param_uint16 (&use_rvalue),
508 GNUNET_PQ_query_param_auto_from_type(key), 518 GNUNET_PQ_query_param_auto_from_type (key),
509 GNUNET_PQ_query_param_uint16(&use_key), 519 GNUNET_PQ_query_param_uint16 (&use_key),
510 GNUNET_PQ_query_param_uint32(&utype), 520 GNUNET_PQ_query_param_uint32 (&utype),
511 GNUNET_PQ_query_param_uint16(&use_type), 521 GNUNET_PQ_query_param_uint16 (&use_type),
512 GNUNET_PQ_query_param_end 522 GNUNET_PQ_query_param_end
513 }; 523 };
514 struct ProcessResultContext prc; 524 struct ProcessResultContext prc;
515 enum GNUNET_DB_QueryStatus res; 525 enum GNUNET_DB_QueryStatus res;
516 526
517 if (random) 527 if (random)
518 { 528 {
519 rvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, 529 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
520 UINT64_MAX); 530 UINT64_MAX);
521 next_uid = 0; 531 next_uid = 0;
522 } 532 }
523 else 533 else
524 { 534 {
525 rvalue = 0; 535 rvalue = 0;
526 } 536 }
527 prc.plugin = plugin; 537 prc.plugin = plugin;
528 prc.proc = proc; 538 prc.proc = proc;
529 prc.proc_cls = proc_cls; 539 prc.proc_cls = proc_cls;
530 540
531 res = GNUNET_PQ_eval_prepared_multi_select(plugin->dbh, 541 res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh,
532 "get", 542 "get",
533 params, 543 params,
534 &process_result, 544 &process_result,
535 &prc); 545 &prc);
536 if (0 > res) 546 if (0 > res)
537 proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, 547 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0,
538 GNUNET_TIME_UNIT_ZERO_ABS, 0); 548 GNUNET_TIME_UNIT_ZERO_ABS, 0);
539} 549}
540 550
541 551
@@ -552,17 +562,17 @@ postgres_plugin_get_key(void *cls,
552 * @param proc_cls closure for @a proc 562 * @param proc_cls closure for @a proc
553 */ 563 */
554static void 564static void
555postgres_plugin_get_zero_anonymity(void *cls, 565postgres_plugin_get_zero_anonymity (void *cls,
556 uint64_t next_uid, 566 uint64_t next_uid,
557 enum GNUNET_BLOCK_Type type, 567 enum GNUNET_BLOCK_Type type,
558 PluginDatumProcessor proc, 568 PluginDatumProcessor proc,
559 void *proc_cls) 569 void *proc_cls)
560{ 570{
561 struct Plugin *plugin = cls; 571 struct Plugin *plugin = cls;
562 uint32_t utype = type; 572 uint32_t utype = type;
563 struct GNUNET_PQ_QueryParam params[] = { 573 struct GNUNET_PQ_QueryParam params[] = {
564 GNUNET_PQ_query_param_uint32(&utype), 574 GNUNET_PQ_query_param_uint32 (&utype),
565 GNUNET_PQ_query_param_uint64(&next_uid), 575 GNUNET_PQ_query_param_uint64 (&next_uid),
566 GNUNET_PQ_query_param_end 576 GNUNET_PQ_query_param_end
567 }; 577 };
568 struct ProcessResultContext prc; 578 struct ProcessResultContext prc;
@@ -571,21 +581,22 @@ postgres_plugin_get_zero_anonymity(void *cls,
571 prc.plugin = plugin; 581 prc.plugin = plugin;
572 prc.proc = proc; 582 prc.proc = proc;
573 prc.proc_cls = proc_cls; 583 prc.proc_cls = proc_cls;
574 res = GNUNET_PQ_eval_prepared_multi_select(plugin->dbh, 584 res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh,
575 "select_non_anonymous", 585 "select_non_anonymous",
576 params, 586 params,
577 &process_result, 587 &process_result,
578 &prc); 588 &prc);
579 if (0 > res) 589 if (0 > res)
580 proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, 590 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0,
581 GNUNET_TIME_UNIT_ZERO_ABS, 0); 591 GNUNET_TIME_UNIT_ZERO_ABS, 0);
582} 592}
583 593
584 594
585/** 595/**
586 * Context for #repl_iter() function. 596 * Context for #repl_iter() function.
587 */ 597 */
588struct ReplCtx { 598struct ReplCtx
599{
589 /** 600 /**
590 * Plugin handle. 601 * Plugin handle.
591 */ 602 */
@@ -625,42 +636,42 @@ struct ReplCtx {
625 * #GNUNET_NO to delete the item and continue (if supported) 636 * #GNUNET_NO to delete the item and continue (if supported)
626 */ 637 */
627static int 638static int
628repl_proc(void *cls, 639repl_proc (void *cls,
629 const struct GNUNET_HashCode *key, 640 const struct GNUNET_HashCode *key,
630 uint32_t size, 641 uint32_t size,
631 const void *data, 642 const void *data,
632 enum GNUNET_BLOCK_Type type, 643 enum GNUNET_BLOCK_Type type,
633 uint32_t priority, 644 uint32_t priority,
634 uint32_t anonymity, 645 uint32_t anonymity,
635 uint32_t replication, 646 uint32_t replication,
636 struct GNUNET_TIME_Absolute expiration, 647 struct GNUNET_TIME_Absolute expiration,
637 uint64_t uid) 648 uint64_t uid)
638{ 649{
639 struct ReplCtx *rc = cls; 650 struct ReplCtx *rc = cls;
640 struct Plugin *plugin = rc->plugin; 651 struct Plugin *plugin = rc->plugin;
641 int ret; 652 int ret;
642 uint32_t oid = (uint32_t)uid; 653 uint32_t oid = (uint32_t) uid;
643 struct GNUNET_PQ_QueryParam params[] = { 654 struct GNUNET_PQ_QueryParam params[] = {
644 GNUNET_PQ_query_param_uint32(&oid), 655 GNUNET_PQ_query_param_uint32 (&oid),
645 GNUNET_PQ_query_param_end 656 GNUNET_PQ_query_param_end
646 }; 657 };
647 enum GNUNET_DB_QueryStatus qret; 658 enum GNUNET_DB_QueryStatus qret;
648 659
649 ret = rc->proc(rc->proc_cls, 660 ret = rc->proc (rc->proc_cls,
650 key, 661 key,
651 size, 662 size,
652 data, 663 data,
653 type, 664 type,
654 priority, 665 priority,
655 anonymity, 666 anonymity,
656 replication, 667 replication,
657 expiration, 668 expiration,
658 uid); 669 uid);
659 if (NULL == key) 670 if (NULL == key)
660 return ret; 671 return ret;
661 qret = GNUNET_PQ_eval_prepared_non_select(plugin->dbh, 672 qret = GNUNET_PQ_eval_prepared_non_select (plugin->dbh,
662 "decrepl", 673 "decrepl",
663 params); 674 params);
664 if (0 > qret) 675 if (0 > qret)
665 return GNUNET_SYSERR; 676 return GNUNET_SYSERR;
666 return ret; 677 return ret;
@@ -679,9 +690,9 @@ repl_proc(void *cls,
679 * @param proc_cls closure for @a proc 690 * @param proc_cls closure for @a proc
680 */ 691 */
681static void 692static void
682postgres_plugin_get_replication(void *cls, 693postgres_plugin_get_replication (void *cls,
683 PluginDatumProcessor proc, 694 PluginDatumProcessor proc,
684 void *proc_cls) 695 void *proc_cls)
685{ 696{
686 struct Plugin *plugin = cls; 697 struct Plugin *plugin = cls;
687 struct GNUNET_PQ_QueryParam params[] = { 698 struct GNUNET_PQ_QueryParam params[] = {
@@ -697,14 +708,14 @@ postgres_plugin_get_replication(void *cls,
697 prc.plugin = plugin; 708 prc.plugin = plugin;
698 prc.proc = &repl_proc; 709 prc.proc = &repl_proc;
699 prc.proc_cls = &rc; 710 prc.proc_cls = &rc;
700 res = GNUNET_PQ_eval_prepared_multi_select(plugin->dbh, 711 res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh,
701 "select_replication_order", 712 "select_replication_order",
702 params, 713 params,
703 &process_result, 714 &process_result,
704 &prc); 715 &prc);
705 if (0 > res) 716 if (0 > res)
706 proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, 717 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0,
707 GNUNET_TIME_UNIT_ZERO_ABS, 0); 718 GNUNET_TIME_UNIT_ZERO_ABS, 0);
708} 719}
709 720
710 721
@@ -717,34 +728,35 @@ postgres_plugin_get_replication(void *cls,
717 * @param proc_cls closure for @a proc 728 * @param proc_cls closure for @a proc
718 */ 729 */
719static void 730static void
720postgres_plugin_get_expiration(void *cls, 731postgres_plugin_get_expiration (void *cls,
721 PluginDatumProcessor proc, 732 PluginDatumProcessor proc,
722 void *proc_cls) 733 void *proc_cls)
723{ 734{
724 struct Plugin *plugin = cls; 735 struct Plugin *plugin = cls;
725 struct GNUNET_TIME_Absolute now; 736 struct GNUNET_TIME_Absolute now;
726 struct GNUNET_PQ_QueryParam params[] = { 737 struct GNUNET_PQ_QueryParam params[] = {
727 GNUNET_PQ_query_param_absolute_time(&now), 738 GNUNET_PQ_query_param_absolute_time (&now),
728 GNUNET_PQ_query_param_end 739 GNUNET_PQ_query_param_end
729 }; 740 };
730 struct ProcessResultContext prc; 741 struct ProcessResultContext prc;
731 742
732 now = GNUNET_TIME_absolute_get(); 743 now = GNUNET_TIME_absolute_get ();
733 prc.plugin = plugin; 744 prc.plugin = plugin;
734 prc.proc = proc; 745 prc.proc = proc;
735 prc.proc_cls = proc_cls; 746 prc.proc_cls = proc_cls;
736 (void)GNUNET_PQ_eval_prepared_multi_select(plugin->dbh, 747 (void) GNUNET_PQ_eval_prepared_multi_select (plugin->dbh,
737 "select_expiration_order", 748 "select_expiration_order",
738 params, 749 params,
739 &process_result, 750 &process_result,
740 &prc); 751 &prc);
741} 752}
742 753
743 754
744/** 755/**
745 * Closure for #process_keys. 756 * Closure for #process_keys.
746 */ 757 */
747struct ProcessKeysContext { 758struct ProcessKeysContext
759{
748 /** 760 /**
749 * Function to call for each key. 761 * Function to call for each key.
750 */ 762 */
@@ -766,34 +778,34 @@ struct ProcessKeysContext {
766 * @param num_result the number of results in @a result 778 * @param num_result the number of results in @a result
767 */ 779 */
768static void 780static void
769process_keys(void *cls, 781process_keys (void *cls,
770 PGresult *result, 782 PGresult *result,
771 unsigned int num_results) 783 unsigned int num_results)
772{ 784{
773 struct ProcessKeysContext *pkc = cls; 785 struct ProcessKeysContext *pkc = cls;
774 786
775 for (unsigned i = 0; i < num_results; i++) 787 for (unsigned i = 0; i < num_results; i++)
776 { 788 {
777 struct GNUNET_HashCode key; 789 struct GNUNET_HashCode key;
778 struct GNUNET_PQ_ResultSpec rs[] = { 790 struct GNUNET_PQ_ResultSpec rs[] = {
779 GNUNET_PQ_result_spec_auto_from_type("hash", 791 GNUNET_PQ_result_spec_auto_from_type ("hash",
780 &key), 792 &key),
781 GNUNET_PQ_result_spec_end 793 GNUNET_PQ_result_spec_end
782 }; 794 };
783 795
784 if (GNUNET_OK != 796 if (GNUNET_OK !=
785 GNUNET_PQ_extract_result(result, 797 GNUNET_PQ_extract_result (result,
786 rs, 798 rs,
787 i)) 799 i))
788 { 800 {
789 GNUNET_break(0); 801 GNUNET_break (0);
790 continue; 802 continue;
791 }
792 pkc->proc(pkc->proc_cls,
793 &key,
794 1);
795 GNUNET_PQ_cleanup_result(rs);
796 } 803 }
804 pkc->proc (pkc->proc_cls,
805 &key,
806 1);
807 GNUNET_PQ_cleanup_result (rs);
808 }
797} 809}
798 810
799 811
@@ -805,9 +817,9 @@ process_keys(void *cls,
805 * @param proc_cls closure for @a proc 817 * @param proc_cls closure for @a proc
806 */ 818 */
807static void 819static void
808postgres_plugin_get_keys(void *cls, 820postgres_plugin_get_keys (void *cls,
809 PluginKeyProcessor proc, 821 PluginKeyProcessor proc,
810 void *proc_cls) 822 void *proc_cls)
811{ 823{
812 struct Plugin *plugin = cls; 824 struct Plugin *plugin = cls;
813 struct GNUNET_PQ_QueryParam params[] = { 825 struct GNUNET_PQ_QueryParam params[] = {
@@ -817,14 +829,14 @@ postgres_plugin_get_keys(void *cls,
817 829
818 pkc.proc = proc; 830 pkc.proc = proc;
819 pkc.proc_cls = proc_cls; 831 pkc.proc_cls = proc_cls;
820 (void)GNUNET_PQ_eval_prepared_multi_select(plugin->dbh, 832 (void) GNUNET_PQ_eval_prepared_multi_select (plugin->dbh,
821 "get_keys", 833 "get_keys",
822 params, 834 params,
823 &process_keys, 835 &process_keys,
824 &pkc); 836 &pkc);
825 proc(proc_cls, 837 proc (proc_cls,
826 NULL, 838 NULL,
827 0); 839 0);
828} 840}
829 841
830 842
@@ -834,20 +846,20 @@ postgres_plugin_get_keys(void *cls,
834 * @param cls closure with the `struct Plugin *` 846 * @param cls closure with the `struct Plugin *`
835 */ 847 */
836static void 848static void
837postgres_plugin_drop(void *cls) 849postgres_plugin_drop (void *cls)
838{ 850{
839 struct Plugin *plugin = cls; 851 struct Plugin *plugin = cls;
840 struct GNUNET_PQ_ExecuteStatement es[] = { 852 struct GNUNET_PQ_ExecuteStatement es[] = {
841 GNUNET_PQ_make_execute("DROP TABLE gn090"), 853 GNUNET_PQ_make_execute ("DROP TABLE gn090"),
842 GNUNET_PQ_EXECUTE_STATEMENT_END 854 GNUNET_PQ_EXECUTE_STATEMENT_END
843 }; 855 };
844 856
845 if (GNUNET_OK != 857 if (GNUNET_OK !=
846 GNUNET_PQ_exec_statements(plugin->dbh, 858 GNUNET_PQ_exec_statements (plugin->dbh,
847 es)) 859 es))
848 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, 860 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
849 "postgres", 861 "postgres",
850 _("Failed to drop table from database.\n")); 862 _ ("Failed to drop table from database.\n"));
851} 863}
852 864
853 865
@@ -862,53 +874,53 @@ postgres_plugin_drop(void *cls)
862 * @param cont_cls continuation closure for @a cont 874 * @param cont_cls continuation closure for @a cont
863 */ 875 */
864static void 876static void
865postgres_plugin_remove_key(void *cls, 877postgres_plugin_remove_key (void *cls,
866 const struct GNUNET_HashCode *key, 878 const struct GNUNET_HashCode *key,
867 uint32_t size, 879 uint32_t size,
868 const void *data, 880 const void *data,
869 PluginRemoveCont cont, 881 PluginRemoveCont cont,
870 void *cont_cls) 882 void *cont_cls)
871{ 883{
872 struct Plugin *plugin = cls; 884 struct Plugin *plugin = cls;
873 enum GNUNET_DB_QueryStatus ret; 885 enum GNUNET_DB_QueryStatus ret;
874 struct GNUNET_PQ_QueryParam params[] = { 886 struct GNUNET_PQ_QueryParam params[] = {
875 GNUNET_PQ_query_param_auto_from_type(key), 887 GNUNET_PQ_query_param_auto_from_type (key),
876 GNUNET_PQ_query_param_fixed_size(data, size), 888 GNUNET_PQ_query_param_fixed_size (data, size),
877 GNUNET_PQ_query_param_end 889 GNUNET_PQ_query_param_end
878 }; 890 };
879 891
880 ret = GNUNET_PQ_eval_prepared_non_select(plugin->dbh, 892 ret = GNUNET_PQ_eval_prepared_non_select (plugin->dbh,
881 "remove", 893 "remove",
882 params); 894 params);
883 if (0 > ret) 895 if (0 > ret)
884 { 896 {
885 cont(cont_cls, 897 cont (cont_cls,
886 key, 898 key,
887 size, 899 size,
888 GNUNET_SYSERR, 900 GNUNET_SYSERR,
889 _("Postgress exec failure")); 901 _ ("Postgress exec failure"));
890 return; 902 return;
891 } 903 }
892 if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == ret) 904 if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == ret)
893 { 905 {
894 cont(cont_cls, 906 cont (cont_cls,
895 key, 907 key,
896 size, 908 size,
897 GNUNET_NO, 909 GNUNET_NO,
898 NULL); 910 NULL);
899 return; 911 return;
900 } 912 }
901 plugin->env->duc(plugin->env->cls, 913 plugin->env->duc (plugin->env->cls,
902 -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); 914 -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
903 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, 915 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
904 "datastore-postgres", 916 "datastore-postgres",
905 "Deleted %u bytes from database\n", 917 "Deleted %u bytes from database\n",
906 (unsigned int)size); 918 (unsigned int) size);
907 cont(cont_cls, 919 cont (cont_cls,
908 key, 920 key,
909 size, 921 size,
910 GNUNET_OK, 922 GNUNET_OK,
911 NULL); 923 NULL);
912} 924}
913 925
914 926
@@ -919,20 +931,20 @@ postgres_plugin_remove_key(void *cls,
919 * @return our `struct Plugin *` 931 * @return our `struct Plugin *`
920 */ 932 */
921void * 933void *
922libgnunet_plugin_datastore_postgres_init(void *cls) 934libgnunet_plugin_datastore_postgres_init (void *cls)
923{ 935{
924 struct GNUNET_DATASTORE_PluginEnvironment *env = cls; 936 struct GNUNET_DATASTORE_PluginEnvironment *env = cls;
925 struct GNUNET_DATASTORE_PluginFunctions *api; 937 struct GNUNET_DATASTORE_PluginFunctions *api;
926 struct Plugin *plugin; 938 struct Plugin *plugin;
927 939
928 plugin = GNUNET_new(struct Plugin); 940 plugin = GNUNET_new (struct Plugin);
929 plugin->env = env; 941 plugin->env = env;
930 if (GNUNET_OK != init_connection(plugin)) 942 if (GNUNET_OK != init_connection (plugin))
931 { 943 {
932 GNUNET_free(plugin); 944 GNUNET_free (plugin);
933 return NULL; 945 return NULL;
934 } 946 }
935 api = GNUNET_new(struct GNUNET_DATASTORE_PluginFunctions); 947 api = GNUNET_new (struct GNUNET_DATASTORE_PluginFunctions);
936 api->cls = plugin; 948 api->cls = plugin;
937 api->estimate_size = &postgres_plugin_estimate_size; 949 api->estimate_size = &postgres_plugin_estimate_size;
938 api->put = &postgres_plugin_put; 950 api->put = &postgres_plugin_put;
@@ -943,9 +955,9 @@ libgnunet_plugin_datastore_postgres_init(void *cls)
943 api->get_keys = &postgres_plugin_get_keys; 955 api->get_keys = &postgres_plugin_get_keys;
944 api->drop = &postgres_plugin_drop; 956 api->drop = &postgres_plugin_drop;
945 api->remove_key = &postgres_plugin_remove_key; 957 api->remove_key = &postgres_plugin_remove_key;
946 GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, 958 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
947 "datastore-postgres", 959 "datastore-postgres",
948 _("Postgres database running\n")); 960 _ ("Postgres database running\n"));
949 return api; 961 return api;
950} 962}
951 963
@@ -957,14 +969,14 @@ libgnunet_plugin_datastore_postgres_init(void *cls)
957 * @return always NULL 969 * @return always NULL
958 */ 970 */
959void * 971void *
960libgnunet_plugin_datastore_postgres_done(void *cls) 972libgnunet_plugin_datastore_postgres_done (void *cls)
961{ 973{
962 struct GNUNET_DATASTORE_PluginFunctions *api = cls; 974 struct GNUNET_DATASTORE_PluginFunctions *api = cls;
963 struct Plugin *plugin = api->cls; 975 struct Plugin *plugin = api->cls;
964 976
965 PQfinish(plugin->dbh); 977 PQfinish (plugin->dbh);
966 GNUNET_free(plugin); 978 GNUNET_free (plugin);
967 GNUNET_free(api); 979 GNUNET_free (api);
968 return NULL; 980 return NULL;
969} 981}
970 982
diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c
index 7d8d06529..b1bb7df7e 100644
--- a/src/datastore/plugin_datastore_sqlite.c
+++ b/src/datastore/plugin_datastore_sqlite.c
@@ -57,15 +57,15 @@
57 */ 57 */
58#define LOG_SQLITE(db, level, cmd) \ 58#define LOG_SQLITE(db, level, cmd) \
59 do \ 59 do \
60 { \ 60 { \
61 GNUNET_log_from(level, \ 61 GNUNET_log_from (level, \
62 "sqlite", \ 62 "sqlite", \
63 _("`%s' failed at %s:%d with error: %s\n"), \ 63 _ ("`%s' failed at %s:%d with error: %s\n"), \
64 cmd, \ 64 cmd, \
65 __FILE__, \ 65 __FILE__, \
66 __LINE__, \ 66 __LINE__, \
67 sqlite3_errmsg(db->dbh)); \ 67 sqlite3_errmsg (db->dbh)); \
68 } while (0) 68 } while (0)
69 69
70 70
71/** 71/**
@@ -75,27 +75,28 @@
75 */ 75 */
76#define LOG_SQLITE_MSG(db, msg, level, cmd) \ 76#define LOG_SQLITE_MSG(db, msg, level, cmd) \
77 do \ 77 do \
78 { \ 78 { \
79 GNUNET_log_from(level, \ 79 GNUNET_log_from (level, \
80 "sqlite", \ 80 "sqlite", \
81 _("`%s' failed at %s:%d with error: %s\n"), \ 81 _ ("`%s' failed at %s:%d with error: %s\n"), \
82 cmd, \ 82 cmd, \
83 __FILE__, \ 83 __FILE__, \
84 __LINE__, \ 84 __LINE__, \
85 sqlite3_errmsg(db->dbh)); \ 85 sqlite3_errmsg (db->dbh)); \
86 GNUNET_asprintf(msg, \ 86 GNUNET_asprintf (msg, \
87 _("`%s' failed at %s:%u with error: %s"), \ 87 _ ("`%s' failed at %s:%u with error: %s"), \
88 cmd, \ 88 cmd, \
89 __FILE__, \ 89 __FILE__, \
90 __LINE__, \ 90 __LINE__, \
91 sqlite3_errmsg(db->dbh)); \ 91 sqlite3_errmsg (db->dbh)); \
92 } while (0) 92 } while (0)
93 93
94 94
95/** 95/**
96 * Context for all functions in this plugin. 96 * Context for all functions in this plugin.
97 */ 97 */
98struct Plugin { 98struct Plugin
99{
99 /** 100 /**
100 * Our execution environment. 101 * Our execution environment.
101 */ 102 */
@@ -177,22 +178,22 @@ struct Plugin {
177 * @return 0 on success 178 * @return 0 on success
178 */ 179 */
179static int 180static int
180sq_prepare(sqlite3 *dbh, const char *zSql, sqlite3_stmt **ppStmt) 181sq_prepare (sqlite3 *dbh, const char *zSql, sqlite3_stmt **ppStmt)
181{ 182{
182 char *dummy; 183 char *dummy;
183 int result; 184 int result;
184 185
185 result = sqlite3_prepare_v2(dbh, 186 result = sqlite3_prepare_v2 (dbh,
186 zSql, 187 zSql,
187 strlen(zSql), 188 strlen (zSql),
188 ppStmt, 189 ppStmt,
189 (const char **)&dummy); 190 (const char **) &dummy);
190 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, 191 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
191 "sqlite", 192 "sqlite",
192 "Prepared `%s' / %p: %d\n", 193 "Prepared `%s' / %p: %d\n",
193 zSql, 194 zSql,
194 *ppStmt, 195 *ppStmt,
195 result); 196 result);
196 return result; 197 return result;
197} 198}
198 199
@@ -203,56 +204,56 @@ sq_prepare(sqlite3 *dbh, const char *zSql, sqlite3_stmt **ppStmt)
203 * @param dbh handle to the database 204 * @param dbh handle to the database
204 */ 205 */
205static void 206static void
206create_indices(sqlite3 *dbh) 207create_indices (sqlite3 *dbh)
207{ 208{
208 /* create indices */ 209 /* create indices */
209 if ( 210 if (
210 0 != 211 0 !=
211 (SQLITE_OK != 212 (SQLITE_OK !=
212 sqlite3_exec(dbh, 213 sqlite3_exec (dbh,
213 "CREATE INDEX IF NOT EXISTS idx_hash ON gn091 (hash)", 214 "CREATE INDEX IF NOT EXISTS idx_hash ON gn091 (hash)",
214 NULL, 215 NULL,
215 NULL, 216 NULL,
216 NULL)) + 217 NULL))
217 (SQLITE_OK != 218 + (SQLITE_OK !=
218 sqlite3_exec( 219 sqlite3_exec (
219 dbh, 220 dbh,
220 "CREATE INDEX IF NOT EXISTS idx_anon_type ON gn091 (anonLevel ASC,type)", 221 "CREATE INDEX IF NOT EXISTS idx_anon_type ON gn091 (anonLevel ASC,type)",
221 NULL, 222 NULL,
222 NULL, 223 NULL,
223 NULL)) + 224 NULL))
224 (SQLITE_OK != 225 + (SQLITE_OK !=
225 sqlite3_exec(dbh, 226 sqlite3_exec (dbh,
226 "CREATE INDEX IF NOT EXISTS idx_expire ON gn091 (expire ASC)", 227 "CREATE INDEX IF NOT EXISTS idx_expire ON gn091 (expire ASC)",
227 NULL, 228 NULL,
228 NULL, 229 NULL,
229 NULL)) + 230 NULL))
230 (SQLITE_OK != 231 + (SQLITE_OK !=
231 sqlite3_exec( 232 sqlite3_exec (
232 dbh, 233 dbh,
233 "CREATE INDEX IF NOT EXISTS idx_repl_rvalue ON gn091 (repl,rvalue)", 234 "CREATE INDEX IF NOT EXISTS idx_repl_rvalue ON gn091 (repl,rvalue)",
234 NULL, 235 NULL,
235 NULL, 236 NULL,
236 NULL))) 237 NULL)))
237 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, 238 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
238 "sqlite", 239 "sqlite",
239 "Failed to create indices: %s\n", 240 "Failed to create indices: %s\n",
240 sqlite3_errmsg(dbh)); 241 sqlite3_errmsg (dbh));
241} 242}
242 243
243 244
244#if 0 245#if 0
245#define CHECK(a) GNUNET_break(a) 246#define CHECK(a) GNUNET_break (a)
246#define ENULL NULL 247#define ENULL NULL
247#else 248#else
248#define ENULL &e 249#define ENULL &e
249#define ENULL_DEFINED 1 250#define ENULL_DEFINED 1
250#define CHECK(a) \ 251#define CHECK(a) \
251 if (!(a)) \ 252 if (! (a)) \
252 { \ 253 { \
253 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", e); \ 254 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", e); \
254 sqlite3_free(e); \ 255 sqlite3_free (e); \
255 } 256 }
256#endif 257#endif
257 258
258 259
@@ -266,8 +267,8 @@ create_indices(sqlite3 *dbh)
266 * @return #GNUNET_OK on success 267 * @return #GNUNET_OK on success
267 */ 268 */
268static int 269static int
269database_setup(const struct GNUNET_CONFIGURATION_Handle *cfg, 270database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
270 struct Plugin *plugin) 271 struct Plugin *plugin)
271{ 272{
272 sqlite3_stmt *stmt; 273 sqlite3_stmt *stmt;
273 char *afsdir; 274 char *afsdir;
@@ -276,210 +277,210 @@ database_setup(const struct GNUNET_CONFIGURATION_Handle *cfg,
276 char *e; 277 char *e;
277#endif 278#endif
278 279
279 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(cfg, 280 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
280 "datastore-sqlite", 281 "datastore-sqlite",
281 "FILENAME", 282 "FILENAME",
282 &afsdir)) 283 &afsdir))
284 {
285 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
286 "datastore-sqlite",
287 "FILENAME");
288 return GNUNET_SYSERR;
289 }
290 if (GNUNET_OK != GNUNET_DISK_file_test (afsdir))
291 {
292 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (afsdir))
283 { 293 {
284 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, 294 GNUNET_break (0);
285 "datastore-sqlite", 295 GNUNET_free (afsdir);
286 "FILENAME");
287 return GNUNET_SYSERR; 296 return GNUNET_SYSERR;
288 } 297 }
289 if (GNUNET_OK != GNUNET_DISK_file_test(afsdir)) 298 /* database is new or got deleted, reset payload to zero! */
290 { 299 if (NULL != plugin->env->duc)
291 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(afsdir)) 300 plugin->env->duc (plugin->env->cls, 0);
292 { 301 }
293 GNUNET_break(0);
294 GNUNET_free(afsdir);
295 return GNUNET_SYSERR;
296 }
297 /* database is new or got deleted, reset payload to zero! */
298 if (NULL != plugin->env->duc)
299 plugin->env->duc(plugin->env->cls, 0);
300 }
301 /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */ 302 /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */
302 plugin->fn = afsdir; 303 plugin->fn = afsdir;
303 304
304 /* Open database and precompile statements */ 305 /* Open database and precompile statements */
305 if (SQLITE_OK != sqlite3_open(plugin->fn, &plugin->dbh)) 306 if (SQLITE_OK != sqlite3_open (plugin->fn, &plugin->dbh))
306 { 307 {
307 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, 308 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
308 "sqlite", 309 "sqlite",
309 _("Unable to initialize SQLite: %s.\n"), 310 _ ("Unable to initialize SQLite: %s.\n"),
310 sqlite3_errmsg(plugin->dbh)); 311 sqlite3_errmsg (plugin->dbh));
311 return GNUNET_SYSERR; 312 return GNUNET_SYSERR;
312 } 313 }
313 CHECK( 314 CHECK (
314 SQLITE_OK == 315 SQLITE_OK ==
315 sqlite3_exec(plugin->dbh, "PRAGMA temp_store=MEMORY", NULL, NULL, ENULL)); 316 sqlite3_exec (plugin->dbh, "PRAGMA temp_store=MEMORY", NULL, NULL, ENULL));
316 CHECK( 317 CHECK (
317 SQLITE_OK == 318 SQLITE_OK ==
318 sqlite3_exec(plugin->dbh, "PRAGMA synchronous=OFF", NULL, NULL, ENULL)); 319 sqlite3_exec (plugin->dbh, "PRAGMA synchronous=OFF", NULL, NULL, ENULL));
319 CHECK(SQLITE_OK == sqlite3_exec(plugin->dbh, 320 CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh,
320 "PRAGMA legacy_file_format=OFF", 321 "PRAGMA legacy_file_format=OFF",
321 NULL, 322 NULL,
322 NULL, 323 NULL,
323 ENULL)); 324 ENULL));
324 CHECK(SQLITE_OK == sqlite3_exec(plugin->dbh, 325 CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh,
325 "PRAGMA auto_vacuum=INCREMENTAL", 326 "PRAGMA auto_vacuum=INCREMENTAL",
326 NULL, 327 NULL,
327 NULL, 328 NULL,
328 ENULL)); 329 ENULL));
329 CHECK(SQLITE_OK == sqlite3_exec(plugin->dbh, 330 CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh,
330 "PRAGMA locking_mode=EXCLUSIVE", 331 "PRAGMA locking_mode=EXCLUSIVE",
331 NULL, 332 NULL,
332 NULL, 333 NULL,
333 ENULL)); 334 ENULL));
334 CHECK( 335 CHECK (
335 SQLITE_OK == 336 SQLITE_OK ==
336 sqlite3_exec(plugin->dbh, "PRAGMA page_size=4096", NULL, NULL, ENULL)); 337 sqlite3_exec (plugin->dbh, "PRAGMA page_size=4096", NULL, NULL, ENULL));
337 338
338 CHECK(SQLITE_OK == sqlite3_busy_timeout(plugin->dbh, BUSY_TIMEOUT_MS)); 339 CHECK (SQLITE_OK == sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS));
339 340
340 341
341 /* We have to do it here, because otherwise precompiling SQL might fail */ 342 /* We have to do it here, because otherwise precompiling SQL might fail */
342 CHECK(SQLITE_OK == 343 CHECK (SQLITE_OK ==
343 sq_prepare(plugin->dbh, 344 sq_prepare (plugin->dbh,
344 "SELECT 1 FROM sqlite_master WHERE tbl_name = 'gn091'", 345 "SELECT 1 FROM sqlite_master WHERE tbl_name = 'gn091'",
345 &stmt)); 346 &stmt));
346 347
347 /* FIXME: SQLite does not have unsigned integers! This is ok for the type column because 348 /* FIXME: SQLite does not have unsigned integers! This is ok for the type column because
348 * we only test equality on it and can cast it to/from uint32_t. For repl, prio, and anonLevel 349 * we only test equality on it and can cast it to/from uint32_t. For repl, prio, and anonLevel
349 * we do math or inequality tests, so we can't handle the entire range of uint32_t. 350 * we do math or inequality tests, so we can't handle the entire range of uint32_t.
350 * This will also cause problems for expiration times after 294247-01-10-04:00:54 UTC. 351 * This will also cause problems for expiration times after 294247-01-10-04:00:54 UTC.
351 */ 352 */
352 if ((SQLITE_DONE == sqlite3_step(stmt)) && 353 if ((SQLITE_DONE == sqlite3_step (stmt)) &&
353 (SQLITE_OK != sqlite3_exec(plugin->dbh, 354 (SQLITE_OK != sqlite3_exec (plugin->dbh,
354 "CREATE TABLE gn091 (" 355 "CREATE TABLE gn091 ("
355 " repl INT4 NOT NULL DEFAULT 0," 356 " repl INT4 NOT NULL DEFAULT 0,"
356 " type INT4 NOT NULL DEFAULT 0," 357 " type INT4 NOT NULL DEFAULT 0,"
357 " prio INT4 NOT NULL DEFAULT 0," 358 " prio INT4 NOT NULL DEFAULT 0,"
358 " anonLevel INT4 NOT NULL DEFAULT 0," 359 " anonLevel INT4 NOT NULL DEFAULT 0,"
359 " expire INT8 NOT NULL DEFAULT 0," 360 " expire INT8 NOT NULL DEFAULT 0,"
360 " rvalue INT8 NOT NULL," 361 " rvalue INT8 NOT NULL,"
361 " hash TEXT NOT NULL DEFAULT ''," 362 " hash TEXT NOT NULL DEFAULT '',"
362 " vhash TEXT NOT NULL DEFAULT ''," 363 " vhash TEXT NOT NULL DEFAULT '',"
363 " value BLOB NOT NULL DEFAULT '')", 364 " value BLOB NOT NULL DEFAULT '')",
364 NULL, 365 NULL,
365 NULL, 366 NULL,
366 NULL))) 367 NULL)))
367 { 368 {
368 LOG_SQLITE(plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec"); 369 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec");
369 sqlite3_finalize(stmt); 370 sqlite3_finalize (stmt);
370 return GNUNET_SYSERR; 371 return GNUNET_SYSERR;
371 } 372 }
372 sqlite3_finalize(stmt); 373 sqlite3_finalize (stmt);
373 create_indices(plugin->dbh); 374 create_indices (plugin->dbh);
374 375
375#define RESULT_COLUMNS \ 376#define RESULT_COLUMNS \
376 "repl, type, prio, anonLevel, expire, hash, value, _ROWID_" 377 "repl, type, prio, anonLevel, expire, hash, value, _ROWID_"
377 if ( 378 if (
378 (SQLITE_OK != sq_prepare(plugin->dbh, 379 (SQLITE_OK != sq_prepare (plugin->dbh,
379 "UPDATE gn091 " 380 "UPDATE gn091 "
380 "SET prio = prio + ?, " 381 "SET prio = prio + ?, "
381 "repl = repl + ?, " 382 "repl = repl + ?, "
382 "expire = MAX(expire, ?) " 383 "expire = MAX(expire, ?) "
383 "WHERE hash = ? AND vhash = ?", 384 "WHERE hash = ? AND vhash = ?",
384 &plugin->update)) || 385 &plugin->update)) ||
385 (SQLITE_OK != sq_prepare(plugin->dbh, 386 (SQLITE_OK != sq_prepare (plugin->dbh,
386 "UPDATE gn091 " 387 "UPDATE gn091 "
387 "SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?", 388 "SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?",
388 &plugin->updRepl)) || 389 &plugin->updRepl)) ||
389 (SQLITE_OK != sq_prepare(plugin->dbh, 390 (SQLITE_OK != sq_prepare (plugin->dbh,
390 "SELECT " RESULT_COLUMNS " FROM gn091 " 391 "SELECT " RESULT_COLUMNS " FROM gn091 "
391 "WHERE repl=?2 AND " 392 "WHERE repl=?2 AND "
392 " (rvalue>=?1 OR " 393 " (rvalue>=?1 OR "
393 " NOT EXISTS (SELECT 1 FROM gn091 " 394 " NOT EXISTS (SELECT 1 FROM gn091 "
394 "WHERE repl=?2 AND rvalue>=?1 LIMIT 1) ) " 395 "WHERE repl=?2 AND rvalue>=?1 LIMIT 1) ) "
395 "ORDER BY rvalue ASC LIMIT 1", 396 "ORDER BY rvalue ASC LIMIT 1",
396 &plugin->selRepl)) || 397 &plugin->selRepl)) ||
397 (SQLITE_OK != sq_prepare(plugin->dbh, 398 (SQLITE_OK != sq_prepare (plugin->dbh,
398 "SELECT MAX(repl) FROM gn091", 399 "SELECT MAX(repl) FROM gn091",
399 &plugin->maxRepl)) || 400 &plugin->maxRepl)) ||
400 (SQLITE_OK != 401 (SQLITE_OK !=
401 sq_prepare(plugin->dbh, 402 sq_prepare (plugin->dbh,
402 "SELECT " RESULT_COLUMNS " FROM gn091 " 403 "SELECT " RESULT_COLUMNS " FROM gn091 "
403 "WHERE NOT EXISTS (SELECT 1 FROM gn091 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) " 404 "WHERE NOT EXISTS (SELECT 1 FROM gn091 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) "
404 "ORDER BY expire ASC LIMIT 1", 405 "ORDER BY expire ASC LIMIT 1",
405 &plugin->selExpi)) || 406 &plugin->selExpi)) ||
406 (SQLITE_OK != sq_prepare(plugin->dbh, 407 (SQLITE_OK != sq_prepare (plugin->dbh,
407 "SELECT " RESULT_COLUMNS " FROM gn091 " 408 "SELECT " RESULT_COLUMNS " FROM gn091 "
408 "WHERE _ROWID_ >= ? AND " 409 "WHERE _ROWID_ >= ? AND "
409 "anonLevel = 0 AND " 410 "anonLevel = 0 AND "
410 "type = ? " 411 "type = ? "
411 "ORDER BY _ROWID_ ASC LIMIT 1", 412 "ORDER BY _ROWID_ ASC LIMIT 1",
412 &plugin->selZeroAnon)) || 413 &plugin->selZeroAnon)) ||
413 (SQLITE_OK != 414 (SQLITE_OK !=
414 sq_prepare(plugin->dbh, 415 sq_prepare (plugin->dbh,
415 "INSERT INTO gn091 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) " 416 "INSERT INTO gn091 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) "
416 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", 417 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
417 &plugin->insertContent)) || 418 &plugin->insertContent)) ||
418 (SQLITE_OK != sq_prepare(plugin->dbh, 419 (SQLITE_OK != sq_prepare (plugin->dbh,
419 "SELECT " RESULT_COLUMNS " FROM gn091 " 420 "SELECT " RESULT_COLUMNS " FROM gn091 "
420 "WHERE _ROWID_ >= ?1 " 421 "WHERE _ROWID_ >= ?1 "
421 "ORDER BY _ROWID_ ASC LIMIT 1", 422 "ORDER BY _ROWID_ ASC LIMIT 1",
422 &plugin->get[0])) || 423 &plugin->get[0])) ||
423 (SQLITE_OK != sq_prepare(plugin->dbh, 424 (SQLITE_OK != sq_prepare (plugin->dbh,
424 "SELECT " RESULT_COLUMNS " FROM gn091 " 425 "SELECT " RESULT_COLUMNS " FROM gn091 "
425 "WHERE _ROWID_ >= ?1 AND " 426 "WHERE _ROWID_ >= ?1 AND "
426 "type = ?4 " 427 "type = ?4 "
427 "ORDER BY _ROWID_ ASC LIMIT 1", 428 "ORDER BY _ROWID_ ASC LIMIT 1",
428 &plugin->get[1])) || 429 &plugin->get[1])) ||
429 (SQLITE_OK != sq_prepare(plugin->dbh, 430 (SQLITE_OK != sq_prepare (plugin->dbh,
430 "SELECT " RESULT_COLUMNS " FROM gn091 " 431 "SELECT " RESULT_COLUMNS " FROM gn091 "
431 "WHERE _ROWID_ >= ?1 AND " 432 "WHERE _ROWID_ >= ?1 AND "
432 "hash = ?3 " 433 "hash = ?3 "
433 "ORDER BY _ROWID_ ASC LIMIT 1", 434 "ORDER BY _ROWID_ ASC LIMIT 1",
434 &plugin->get[2])) || 435 &plugin->get[2])) ||
435 (SQLITE_OK != sq_prepare(plugin->dbh, 436 (SQLITE_OK != sq_prepare (plugin->dbh,
436 "SELECT " RESULT_COLUMNS " FROM gn091 " 437 "SELECT " RESULT_COLUMNS " FROM gn091 "
437 "WHERE _ROWID_ >= ?1 AND " 438 "WHERE _ROWID_ >= ?1 AND "
438 "hash = ?3 AND " 439 "hash = ?3 AND "
439 "type = ?4 " 440 "type = ?4 "
440 "ORDER BY _ROWID_ ASC LIMIT 1", 441 "ORDER BY _ROWID_ ASC LIMIT 1",
441 &plugin->get[3])) || 442 &plugin->get[3])) ||
442 (SQLITE_OK != sq_prepare(plugin->dbh, 443 (SQLITE_OK != sq_prepare (plugin->dbh,
443 "SELECT " RESULT_COLUMNS " FROM gn091 " 444 "SELECT " RESULT_COLUMNS " FROM gn091 "
444 "WHERE _ROWID_ >= ?1 AND " 445 "WHERE _ROWID_ >= ?1 AND "
445 "rvalue >= ?2 " 446 "rvalue >= ?2 "
446 "ORDER BY _ROWID_ ASC LIMIT 1", 447 "ORDER BY _ROWID_ ASC LIMIT 1",
447 &plugin->get[4])) || 448 &plugin->get[4])) ||
448 (SQLITE_OK != sq_prepare(plugin->dbh, 449 (SQLITE_OK != sq_prepare (plugin->dbh,
449 "SELECT " RESULT_COLUMNS " FROM gn091 " 450 "SELECT " RESULT_COLUMNS " FROM gn091 "
450 "WHERE _ROWID_ >= ?1 AND " 451 "WHERE _ROWID_ >= ?1 AND "
451 "rvalue >= ?2 AND " 452 "rvalue >= ?2 AND "
452 "type = ?4 " 453 "type = ?4 "
453 "ORDER BY _ROWID_ ASC LIMIT 1", 454 "ORDER BY _ROWID_ ASC LIMIT 1",
454 &plugin->get[5])) || 455 &plugin->get[5])) ||
455 (SQLITE_OK != sq_prepare(plugin->dbh, 456 (SQLITE_OK != sq_prepare (plugin->dbh,
456 "SELECT " RESULT_COLUMNS " FROM gn091 " 457 "SELECT " RESULT_COLUMNS " FROM gn091 "
457 "WHERE _ROWID_ >= ?1 AND " 458 "WHERE _ROWID_ >= ?1 AND "
458 "rvalue >= ?2 AND " 459 "rvalue >= ?2 AND "
459 "hash = ?3 " 460 "hash = ?3 "
460 "ORDER BY _ROWID_ ASC LIMIT 1", 461 "ORDER BY _ROWID_ ASC LIMIT 1",
461 &plugin->get[6])) || 462 &plugin->get[6])) ||
462 (SQLITE_OK != sq_prepare(plugin->dbh, 463 (SQLITE_OK != sq_prepare (plugin->dbh,
463 "SELECT " RESULT_COLUMNS " FROM gn091 " 464 "SELECT " RESULT_COLUMNS " FROM gn091 "
464 "WHERE _ROWID_ >= ?1 AND " 465 "WHERE _ROWID_ >= ?1 AND "
465 "rvalue >= ?2 AND " 466 "rvalue >= ?2 AND "
466 "hash = ?3 AND " 467 "hash = ?3 AND "
467 "type = ?4 " 468 "type = ?4 "
468 "ORDER BY _ROWID_ ASC LIMIT 1", 469 "ORDER BY _ROWID_ ASC LIMIT 1",
469 &plugin->get[7])) || 470 &plugin->get[7])) ||
470 (SQLITE_OK != sq_prepare(plugin->dbh, 471 (SQLITE_OK != sq_prepare (plugin->dbh,
471 "DELETE FROM gn091 WHERE _ROWID_ = ?", 472 "DELETE FROM gn091 WHERE _ROWID_ = ?",
472 &plugin->delRow)) || 473 &plugin->delRow)) ||
473 (SQLITE_OK != sq_prepare(plugin->dbh, 474 (SQLITE_OK != sq_prepare (plugin->dbh,
474 "DELETE FROM gn091 " 475 "DELETE FROM gn091 "
475 "WHERE hash = ? AND " 476 "WHERE hash = ? AND "
476 "value = ? ", 477 "value = ? ",
477 &plugin->remove)) || 478 &plugin->remove)) ||
478 false) 479 false)
479 { 480 {
480 LOG_SQLITE(plugin, GNUNET_ERROR_TYPE_ERROR, "precompiling"); 481 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "precompiling");
481 return GNUNET_SYSERR; 482 return GNUNET_SYSERR;
482 } 483 }
483 return GNUNET_OK; 484 return GNUNET_OK;
484} 485}
485 486
@@ -491,7 +492,7 @@ database_setup(const struct GNUNET_CONFIGURATION_Handle *cfg,
491 * @param plugin the plugin context (state for this module) 492 * @param plugin the plugin context (state for this module)
492 */ 493 */
493static void 494static void
494database_shutdown(struct Plugin *plugin) 495database_shutdown (struct Plugin *plugin)
495{ 496{
496 int result; 497 int result;
497 498
@@ -500,57 +501,57 @@ database_shutdown(struct Plugin *plugin)
500#endif 501#endif
501 502
502 if (NULL != plugin->remove) 503 if (NULL != plugin->remove)
503 sqlite3_finalize(plugin->remove); 504 sqlite3_finalize (plugin->remove);
504 if (NULL != plugin->delRow) 505 if (NULL != plugin->delRow)
505 sqlite3_finalize(plugin->delRow); 506 sqlite3_finalize (plugin->delRow);
506 if (NULL != plugin->update) 507 if (NULL != plugin->update)
507 sqlite3_finalize(plugin->update); 508 sqlite3_finalize (plugin->update);
508 if (NULL != plugin->updRepl) 509 if (NULL != plugin->updRepl)
509 sqlite3_finalize(plugin->updRepl); 510 sqlite3_finalize (plugin->updRepl);
510 if (NULL != plugin->selRepl) 511 if (NULL != plugin->selRepl)
511 sqlite3_finalize(plugin->selRepl); 512 sqlite3_finalize (plugin->selRepl);
512 if (NULL != plugin->maxRepl) 513 if (NULL != plugin->maxRepl)
513 sqlite3_finalize(plugin->maxRepl); 514 sqlite3_finalize (plugin->maxRepl);
514 if (NULL != plugin->selExpi) 515 if (NULL != plugin->selExpi)
515 sqlite3_finalize(plugin->selExpi); 516 sqlite3_finalize (plugin->selExpi);
516 if (NULL != plugin->selZeroAnon) 517 if (NULL != plugin->selZeroAnon)
517 sqlite3_finalize(plugin->selZeroAnon); 518 sqlite3_finalize (plugin->selZeroAnon);
518 if (NULL != plugin->insertContent) 519 if (NULL != plugin->insertContent)
519 sqlite3_finalize(plugin->insertContent); 520 sqlite3_finalize (plugin->insertContent);
520 for (int i = 0; i < 8; ++i) 521 for (int i = 0; i < 8; ++i)
521 if (NULL != plugin->get[i]) 522 if (NULL != plugin->get[i])
522 sqlite3_finalize(plugin->get[i]); 523 sqlite3_finalize (plugin->get[i]);
523 result = sqlite3_close(plugin->dbh); 524 result = sqlite3_close (plugin->dbh);
524#if SQLITE_VERSION_NUMBER >= 3007000 525#if SQLITE_VERSION_NUMBER >= 3007000
525 if (result == SQLITE_BUSY) 526 if (result == SQLITE_BUSY)
527 {
528 GNUNET_log_from (
529 GNUNET_ERROR_TYPE_WARNING,
530 "sqlite",
531 _ (
532 "Tried to close sqlite without finalizing all prepared statements.\n"));
533 stmt = sqlite3_next_stmt (plugin->dbh, NULL);
534 while (NULL != stmt)
526 { 535 {
527 GNUNET_log_from( 536 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
528 GNUNET_ERROR_TYPE_WARNING, 537 "sqlite",
529 "sqlite", 538 "Closing statement %p\n",
530 _( 539 stmt);
531 "Tried to close sqlite without finalizing all prepared statements.\n")); 540 result = sqlite3_finalize (stmt);
532 stmt = sqlite3_next_stmt(plugin->dbh, NULL); 541 if (result != SQLITE_OK)
533 while (NULL != stmt) 542 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
534 { 543 "sqlite",
535 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, 544 "Failed to close statement %p: %d\n",
536 "sqlite", 545 stmt,
537 "Closing statement %p\n", 546 result);
538 stmt); 547 stmt = sqlite3_next_stmt (plugin->dbh, NULL);
539 result = sqlite3_finalize(stmt);
540 if (result != SQLITE_OK)
541 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING,
542 "sqlite",
543 "Failed to close statement %p: %d\n",
544 stmt,
545 result);
546 stmt = sqlite3_next_stmt(plugin->dbh, NULL);
547 }
548 result = sqlite3_close(plugin->dbh);
549 } 548 }
549 result = sqlite3_close (plugin->dbh);
550 }
550#endif 551#endif
551 if (SQLITE_OK != result) 552 if (SQLITE_OK != result)
552 LOG_SQLITE(plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close"); 553 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close");
553 GNUNET_free_non_null(plugin->fn); 554 GNUNET_free_non_null (plugin->fn);
554} 555}
555 556
556 557
@@ -562,22 +563,22 @@ database_shutdown(struct Plugin *plugin)
562 * @param rid the ID of the row to delete 563 * @param rid the ID of the row to delete
563 */ 564 */
564static int 565static int
565delete_by_rowid(struct Plugin *plugin, uint64_t rid) 566delete_by_rowid (struct Plugin *plugin, uint64_t rid)
566{ 567{
567 struct GNUNET_SQ_QueryParam params[] = { GNUNET_SQ_query_param_uint64(&rid), 568 struct GNUNET_SQ_QueryParam params[] = { GNUNET_SQ_query_param_uint64 (&rid),
568 GNUNET_SQ_query_param_end }; 569 GNUNET_SQ_query_param_end };
569 570
570 if (GNUNET_OK != GNUNET_SQ_bind(plugin->delRow, params)) 571 if (GNUNET_OK != GNUNET_SQ_bind (plugin->delRow, params))
571 return GNUNET_SYSERR; 572 return GNUNET_SYSERR;
572 if (SQLITE_DONE != sqlite3_step(plugin->delRow)) 573 if (SQLITE_DONE != sqlite3_step (plugin->delRow))
573 { 574 {
574 LOG_SQLITE(plugin, 575 LOG_SQLITE (plugin,
575 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 576 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
576 "sqlite3_step"); 577 "sqlite3_step");
577 GNUNET_SQ_reset(plugin->dbh, plugin->delRow); 578 GNUNET_SQ_reset (plugin->dbh, plugin->delRow);
578 return GNUNET_SYSERR; 579 return GNUNET_SYSERR;
579 } 580 }
580 GNUNET_SQ_reset(plugin->dbh, plugin->delRow); 581 GNUNET_SQ_reset (plugin->dbh, plugin->delRow);
581 return GNUNET_OK; 582 return GNUNET_OK;
582} 583}
583 584
@@ -599,137 +600,137 @@ delete_by_rowid(struct Plugin *plugin, uint64_t rid)
599 * @param cont_cls continuation closure 600 * @param cont_cls continuation closure
600 */ 601 */
601static void 602static void
602sqlite_plugin_put(void *cls, 603sqlite_plugin_put (void *cls,
603 const struct GNUNET_HashCode *key, 604 const struct GNUNET_HashCode *key,
604 bool absent, 605 bool absent,
605 uint32_t size, 606 uint32_t size,
606 const void *data, 607 const void *data,
607 enum GNUNET_BLOCK_Type type, 608 enum GNUNET_BLOCK_Type type,
608 uint32_t priority, 609 uint32_t priority,
609 uint32_t anonymity, 610 uint32_t anonymity,
610 uint32_t replication, 611 uint32_t replication,
611 struct GNUNET_TIME_Absolute expiration, 612 struct GNUNET_TIME_Absolute expiration,
612 PluginPutCont cont, 613 PluginPutCont cont,
613 void *cont_cls) 614 void *cont_cls)
614{ 615{
615 struct Plugin *plugin = cls; 616 struct Plugin *plugin = cls;
616 struct GNUNET_HashCode vhash; 617 struct GNUNET_HashCode vhash;
617 char *msg = NULL; 618 char *msg = NULL;
618 619
619 GNUNET_CRYPTO_hash(data, size, &vhash); 620 GNUNET_CRYPTO_hash (data, size, &vhash);
621
622 if (! absent)
623 {
624 struct GNUNET_SQ_QueryParam params[] =
625 { GNUNET_SQ_query_param_uint32 (&priority),
626 GNUNET_SQ_query_param_uint32 (&replication),
627 GNUNET_SQ_query_param_absolute_time (&expiration),
628 GNUNET_SQ_query_param_auto_from_type (key),
629 GNUNET_SQ_query_param_auto_from_type (&vhash),
630 GNUNET_SQ_query_param_end };
620 631
621 if (!absent) 632 if (GNUNET_OK != GNUNET_SQ_bind (plugin->update, params))
633 {
634 cont (cont_cls, key, size, GNUNET_SYSERR, _ ("sqlite bind failure"));
635 return;
636 }
637 if (SQLITE_DONE != sqlite3_step (plugin->update))
638 {
639 LOG_SQLITE_MSG (plugin,
640 &msg,
641 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
642 "sqlite3_step");
643 cont (cont_cls, key, size, GNUNET_SYSERR, msg);
644 GNUNET_free_non_null (msg);
645 return;
646 }
647 int changes = sqlite3_changes (plugin->dbh);
648 GNUNET_SQ_reset (plugin->dbh, plugin->update);
649 if (0 != changes)
622 { 650 {
623 struct GNUNET_SQ_QueryParam params[] = 651 cont (cont_cls, key, size, GNUNET_NO, NULL);
624 { GNUNET_SQ_query_param_uint32(&priority), 652 return;
625 GNUNET_SQ_query_param_uint32(&replication),
626 GNUNET_SQ_query_param_absolute_time(&expiration),
627 GNUNET_SQ_query_param_auto_from_type(key),
628 GNUNET_SQ_query_param_auto_from_type(&vhash),
629 GNUNET_SQ_query_param_end };
630
631 if (GNUNET_OK != GNUNET_SQ_bind(plugin->update, params))
632 {
633 cont(cont_cls, key, size, GNUNET_SYSERR, _("sqlite bind failure"));
634 return;
635 }
636 if (SQLITE_DONE != sqlite3_step(plugin->update))
637 {
638 LOG_SQLITE_MSG(plugin,
639 &msg,
640 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
641 "sqlite3_step");
642 cont(cont_cls, key, size, GNUNET_SYSERR, msg);
643 GNUNET_free_non_null(msg);
644 return;
645 }
646 int changes = sqlite3_changes(plugin->dbh);
647 GNUNET_SQ_reset(plugin->dbh, plugin->update);
648 if (0 != changes)
649 {
650 cont(cont_cls, key, size, GNUNET_NO, NULL);
651 return;
652 }
653 } 653 }
654 }
654 655
655 uint64_t rvalue; 656 uint64_t rvalue;
656 uint32_t type32 = (uint32_t)type; 657 uint32_t type32 = (uint32_t) type;
657 struct GNUNET_SQ_QueryParam params[] = 658 struct GNUNET_SQ_QueryParam params[] =
658 { GNUNET_SQ_query_param_uint32(&replication), 659 { GNUNET_SQ_query_param_uint32 (&replication),
659 GNUNET_SQ_query_param_uint32(&type32), 660 GNUNET_SQ_query_param_uint32 (&type32),
660 GNUNET_SQ_query_param_uint32(&priority), 661 GNUNET_SQ_query_param_uint32 (&priority),
661 GNUNET_SQ_query_param_uint32(&anonymity), 662 GNUNET_SQ_query_param_uint32 (&anonymity),
662 GNUNET_SQ_query_param_absolute_time(&expiration), 663 GNUNET_SQ_query_param_absolute_time (&expiration),
663 GNUNET_SQ_query_param_uint64(&rvalue), 664 GNUNET_SQ_query_param_uint64 (&rvalue),
664 GNUNET_SQ_query_param_auto_from_type(key), 665 GNUNET_SQ_query_param_auto_from_type (key),
665 GNUNET_SQ_query_param_auto_from_type(&vhash), 666 GNUNET_SQ_query_param_auto_from_type (&vhash),
666 GNUNET_SQ_query_param_fixed_size(data, size), 667 GNUNET_SQ_query_param_fixed_size (data, size),
667 GNUNET_SQ_query_param_end }; 668 GNUNET_SQ_query_param_end };
668 int n; 669 int n;
669 int ret; 670 int ret;
670 sqlite3_stmt *stmt; 671 sqlite3_stmt *stmt;
671 672
672 if (size > MAX_ITEM_SIZE) 673 if (size > MAX_ITEM_SIZE)
673 { 674 {
674 cont(cont_cls, key, size, GNUNET_SYSERR, _("Data too large")); 675 cont (cont_cls, key, size, GNUNET_SYSERR, _ ("Data too large"));
675 return; 676 return;
676 } 677 }
677 GNUNET_log_from( 678 GNUNET_log_from (
678 GNUNET_ERROR_TYPE_DEBUG, 679 GNUNET_ERROR_TYPE_DEBUG,
679 "sqlite", 680 "sqlite",
680 "Storing in database block with type %u/key `%s'/priority %u/expiration in %s (%s).\n", 681 "Storing in database block with type %u/key `%s'/priority %u/expiration in %s (%s).\n",
681 type, 682 type,
682 GNUNET_h2s(key), 683 GNUNET_h2s (key),
683 priority, 684 priority,
684 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_remaining( 685 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (
685 expiration), 686 expiration),
686 GNUNET_YES), 687 GNUNET_YES),
687 GNUNET_STRINGS_absolute_time_to_string(expiration)); 688 GNUNET_STRINGS_absolute_time_to_string (expiration));
688 stmt = plugin->insertContent; 689 stmt = plugin->insertContent;
689 rvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); 690 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
690 if (GNUNET_OK != GNUNET_SQ_bind(stmt, params)) 691 if (GNUNET_OK != GNUNET_SQ_bind (stmt, params))
691 { 692 {
692 cont(cont_cls, key, size, GNUNET_SYSERR, NULL); 693 cont (cont_cls, key, size, GNUNET_SYSERR, NULL);
693 return; 694 return;
694 } 695 }
695 n = sqlite3_step(stmt); 696 n = sqlite3_step (stmt);
696 switch (n) 697 switch (n)
697 { 698 {
698 case SQLITE_DONE: 699 case SQLITE_DONE:
699 if (NULL != plugin->env->duc) 700 if (NULL != plugin->env->duc)
700 plugin->env->duc(plugin->env->cls, 701 plugin->env->duc (plugin->env->cls,
701 size + GNUNET_DATASTORE_ENTRY_OVERHEAD); 702 size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
702 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, 703 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
703 "sqlite", 704 "sqlite",
704 "Stored new entry (%u bytes)\n", 705 "Stored new entry (%u bytes)\n",
705 size + GNUNET_DATASTORE_ENTRY_OVERHEAD); 706 size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
706 ret = GNUNET_OK; 707 ret = GNUNET_OK;
707 break; 708 break;
708 709
709 case SQLITE_BUSY: 710 case SQLITE_BUSY:
710 GNUNET_break(0); 711 GNUNET_break (0);
711 LOG_SQLITE_MSG(plugin, 712 LOG_SQLITE_MSG (plugin,
712 &msg, 713 &msg,
713 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 714 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
714 "sqlite3_step"); 715 "sqlite3_step");
715 ret = GNUNET_SYSERR; 716 ret = GNUNET_SYSERR;
716 break; 717 break;
717 718
718 default: 719 default:
719 LOG_SQLITE_MSG(plugin, 720 LOG_SQLITE_MSG (plugin,
720 &msg, 721 &msg,
721 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 722 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
722 "sqlite3_step"); 723 "sqlite3_step");
723 GNUNET_SQ_reset(plugin->dbh, stmt); 724 GNUNET_SQ_reset (plugin->dbh, stmt);
724 database_shutdown(plugin); 725 database_shutdown (plugin);
725 database_setup(plugin->env->cfg, plugin); 726 database_setup (plugin->env->cfg, plugin);
726 cont(cont_cls, key, size, GNUNET_SYSERR, msg); 727 cont (cont_cls, key, size, GNUNET_SYSERR, msg);
727 GNUNET_free_non_null(msg); 728 GNUNET_free_non_null (msg);
728 return; 729 return;
729 } 730 }
730 GNUNET_SQ_reset(plugin->dbh, stmt); 731 GNUNET_SQ_reset (plugin->dbh, stmt);
731 cont(cont_cls, key, size, ret, msg); 732 cont (cont_cls, key, size, ret, msg);
732 GNUNET_free_non_null(msg); 733 GNUNET_free_non_null (msg);
733} 734}
734 735
735 736
@@ -743,10 +744,10 @@ sqlite_plugin_put(void *cls,
743 * @param proc_cls closure for @a proc 744 * @param proc_cls closure for @a proc
744 */ 745 */
745static void 746static void
746execute_get(struct Plugin *plugin, 747execute_get (struct Plugin *plugin,
747 sqlite3_stmt *stmt, 748 sqlite3_stmt *stmt,
748 PluginDatumProcessor proc, 749 PluginDatumProcessor proc,
749 void *proc_cls) 750 void *proc_cls)
750{ 751{
751 int n; 752 int n;
752 struct GNUNET_TIME_Absolute expiration; 753 struct GNUNET_TIME_Absolute expiration;
@@ -760,70 +761,70 @@ execute_get(struct Plugin *plugin,
760 struct GNUNET_HashCode key; 761 struct GNUNET_HashCode key;
761 int ret; 762 int ret;
762 struct GNUNET_SQ_ResultSpec rs[] = 763 struct GNUNET_SQ_ResultSpec rs[] =
763 { GNUNET_SQ_result_spec_uint32(&replication), 764 { GNUNET_SQ_result_spec_uint32 (&replication),
764 GNUNET_SQ_result_spec_uint32(&type), 765 GNUNET_SQ_result_spec_uint32 (&type),
765 GNUNET_SQ_result_spec_uint32(&priority), 766 GNUNET_SQ_result_spec_uint32 (&priority),
766 GNUNET_SQ_result_spec_uint32(&anonymity), 767 GNUNET_SQ_result_spec_uint32 (&anonymity),
767 GNUNET_SQ_result_spec_absolute_time(&expiration), 768 GNUNET_SQ_result_spec_absolute_time (&expiration),
768 GNUNET_SQ_result_spec_auto_from_type(&key), 769 GNUNET_SQ_result_spec_auto_from_type (&key),
769 GNUNET_SQ_result_spec_variable_size(&value, &value_size), 770 GNUNET_SQ_result_spec_variable_size (&value, &value_size),
770 GNUNET_SQ_result_spec_uint64(&rowid), 771 GNUNET_SQ_result_spec_uint64 (&rowid),
771 GNUNET_SQ_result_spec_end }; 772 GNUNET_SQ_result_spec_end };
772 773
773 n = sqlite3_step(stmt); 774 n = sqlite3_step (stmt);
774 switch (n) 775 switch (n)
776 {
777 case SQLITE_ROW:
778 if (GNUNET_OK != GNUNET_SQ_extract_result (stmt, rs))
775 { 779 {
776 case SQLITE_ROW: 780 GNUNET_break (0);
777 if (GNUNET_OK != GNUNET_SQ_extract_result(stmt, rs))
778 {
779 GNUNET_break(0);
780 break;
781 }
782 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG,
783 "sqlite",
784 "Found reply in database with expiration %s\n",
785 GNUNET_STRINGS_absolute_time_to_string(expiration));
786 ret = proc(proc_cls,
787 &key,
788 value_size,
789 value,
790 type,
791 priority,
792 anonymity,
793 replication,
794 expiration,
795 rowid);
796 GNUNET_SQ_cleanup_result(rs);
797 GNUNET_SQ_reset(plugin->dbh, stmt);
798 if ((GNUNET_NO == ret) && (GNUNET_OK == delete_by_rowid(plugin, rowid)) &&
799 (NULL != plugin->env->duc))
800 plugin->env->duc(plugin->env->cls,
801 -(value_size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
802 return;
803
804 case SQLITE_DONE:
805 /* database must be empty */
806 break; 781 break;
807
808 case SQLITE_BUSY:
809 case SQLITE_ERROR:
810 case SQLITE_MISUSE:
811 default:
812 LOG_SQLITE(plugin,
813 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
814 "sqlite3_step");
815 if (SQLITE_OK != sqlite3_reset(stmt))
816 LOG_SQLITE(plugin,
817 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
818 "sqlite3_reset");
819 GNUNET_break(0);
820 proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
821 database_shutdown(plugin);
822 database_setup(plugin->env->cfg, plugin);
823 return;
824 } 782 }
825 GNUNET_SQ_reset(plugin->dbh, stmt); 783 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
826 proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 784 "sqlite",
785 "Found reply in database with expiration %s\n",
786 GNUNET_STRINGS_absolute_time_to_string (expiration));
787 ret = proc (proc_cls,
788 &key,
789 value_size,
790 value,
791 type,
792 priority,
793 anonymity,
794 replication,
795 expiration,
796 rowid);
797 GNUNET_SQ_cleanup_result (rs);
798 GNUNET_SQ_reset (plugin->dbh, stmt);
799 if ((GNUNET_NO == ret) && (GNUNET_OK == delete_by_rowid (plugin, rowid)) &&
800 (NULL != plugin->env->duc))
801 plugin->env->duc (plugin->env->cls,
802 -(value_size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
803 return;
804
805 case SQLITE_DONE:
806 /* database must be empty */
807 break;
808
809 case SQLITE_BUSY:
810 case SQLITE_ERROR:
811 case SQLITE_MISUSE:
812 default:
813 LOG_SQLITE (plugin,
814 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
815 "sqlite3_step");
816 if (SQLITE_OK != sqlite3_reset (stmt))
817 LOG_SQLITE (plugin,
818 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
819 "sqlite3_reset");
820 GNUNET_break (0);
821 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
822 database_shutdown (plugin);
823 database_setup (plugin->env->cfg, plugin);
824 return;
825 }
826 GNUNET_SQ_reset (plugin->dbh, stmt);
827 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
827} 828}
828 829
829 830
@@ -840,27 +841,27 @@ execute_get(struct Plugin *plugin,
840 * @param proc_cls closure for @a proc 841 * @param proc_cls closure for @a proc
841 */ 842 */
842static void 843static void
843sqlite_plugin_get_zero_anonymity(void *cls, 844sqlite_plugin_get_zero_anonymity (void *cls,
844 uint64_t next_uid, 845 uint64_t next_uid,
845 enum GNUNET_BLOCK_Type type, 846 enum GNUNET_BLOCK_Type type,
846 PluginDatumProcessor proc, 847 PluginDatumProcessor proc,
847 void *proc_cls) 848 void *proc_cls)
848{ 849{
849 struct Plugin *plugin = cls; 850 struct Plugin *plugin = cls;
850 uint32_t type32 = type; 851 uint32_t type32 = type;
851 struct GNUNET_SQ_QueryParam params[] = { GNUNET_SQ_query_param_uint64( 852 struct GNUNET_SQ_QueryParam params[] = { GNUNET_SQ_query_param_uint64 (
852 &next_uid), 853 &next_uid),
853 GNUNET_SQ_query_param_uint32( 854 GNUNET_SQ_query_param_uint32 (
854 &type32), 855 &type32),
855 GNUNET_SQ_query_param_end }; 856 GNUNET_SQ_query_param_end };
856 857
857 GNUNET_assert(type != GNUNET_BLOCK_TYPE_ANY); 858 GNUNET_assert (type != GNUNET_BLOCK_TYPE_ANY);
858 if (GNUNET_OK != GNUNET_SQ_bind(plugin->selZeroAnon, params)) 859 if (GNUNET_OK != GNUNET_SQ_bind (plugin->selZeroAnon, params))
859 { 860 {
860 proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 861 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
861 return; 862 return;
862 } 863 }
863 execute_get(plugin, plugin->selZeroAnon, proc, proc_cls); 864 execute_get (plugin, plugin->selZeroAnon, proc, proc_cls);
864} 865}
865 866
866 867
@@ -878,62 +879,63 @@ sqlite_plugin_get_zero_anonymity(void *cls,
878 * @param proc_cls closure for @a proc 879 * @param proc_cls closure for @a proc
879 */ 880 */
880static void 881static void
881sqlite_plugin_get_key(void *cls, 882sqlite_plugin_get_key (void *cls,
882 uint64_t next_uid, 883 uint64_t next_uid,
883 bool random, 884 bool random,
884 const struct GNUNET_HashCode *key, 885 const struct GNUNET_HashCode *key,
885 enum GNUNET_BLOCK_Type type, 886 enum GNUNET_BLOCK_Type type,
886 PluginDatumProcessor proc, 887 PluginDatumProcessor proc,
887 void *proc_cls) 888 void *proc_cls)
888{ 889{
889 struct Plugin *plugin = cls; 890 struct Plugin *plugin = cls;
890 uint64_t rvalue; 891 uint64_t rvalue;
891 int use_rvalue = random; 892 int use_rvalue = random;
892 uint32_t type32 = (uint32_t)type; 893 uint32_t type32 = (uint32_t) type;
893 int use_type = GNUNET_BLOCK_TYPE_ANY != type; 894 int use_type = GNUNET_BLOCK_TYPE_ANY != type;
894 int use_key = NULL != key; 895 int use_key = NULL != key;
895 sqlite3_stmt *stmt = plugin->get[use_rvalue * 4 + use_key * 2 + use_type]; 896 sqlite3_stmt *stmt = plugin->get[use_rvalue * 4 + use_key * 2 + use_type];
896 struct GNUNET_SQ_QueryParam params[] = 897 struct GNUNET_SQ_QueryParam params[] =
897 { GNUNET_SQ_query_param_uint64(&next_uid), 898 { GNUNET_SQ_query_param_uint64 (&next_uid),
898 GNUNET_SQ_query_param_uint64(&rvalue), 899 GNUNET_SQ_query_param_uint64 (&rvalue),
899 GNUNET_SQ_query_param_auto_from_type(key), 900 GNUNET_SQ_query_param_auto_from_type (key),
900 GNUNET_SQ_query_param_uint32(&type32), 901 GNUNET_SQ_query_param_uint32 (&type32),
901 GNUNET_SQ_query_param_end }; 902 GNUNET_SQ_query_param_end };
902 903
903 /* SQLite doesn't like it when you try to bind a parameter greater than the 904 /* SQLite doesn't like it when you try to bind a parameter greater than the
904 * last numbered parameter, but unused parameters in the middle are OK. 905 * last numbered parameter, but unused parameters in the middle are OK.
905 */ 906 */
906 if (!use_type) 907 if (! use_type)
908 {
909 params[3] = (struct GNUNET_SQ_QueryParam) GNUNET_SQ_query_param_end;
910 if (! use_key)
907 { 911 {
908 params[3] = (struct GNUNET_SQ_QueryParam)GNUNET_SQ_query_param_end; 912 params[2] = (struct GNUNET_SQ_QueryParam) GNUNET_SQ_query_param_end;
909 if (!use_key) 913 if (! use_rvalue)
910 { 914 params[1] = (struct GNUNET_SQ_QueryParam) GNUNET_SQ_query_param_end;
911 params[2] = (struct GNUNET_SQ_QueryParam)GNUNET_SQ_query_param_end;
912 if (!use_rvalue)
913 params[1] = (struct GNUNET_SQ_QueryParam)GNUNET_SQ_query_param_end;
914 }
915 } 915 }
916 }
916 if (random) 917 if (random)
917 { 918 {
918 rvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); 919 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
919 next_uid = 0; 920 next_uid = 0;
920 } 921 }
921 else 922 else
922 rvalue = 0; 923 rvalue = 0;
923 924
924 if (GNUNET_OK != GNUNET_SQ_bind(stmt, params)) 925 if (GNUNET_OK != GNUNET_SQ_bind (stmt, params))
925 { 926 {
926 proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 927 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
927 return; 928 return;
928 } 929 }
929 execute_get(plugin, stmt, proc, proc_cls); 930 execute_get (plugin, stmt, proc, proc_cls);
930} 931}
931 932
932 933
933/** 934/**
934 * Context for #repl_proc() function. 935 * Context for #repl_proc() function.
935 */ 936 */
936struct ReplCtx { 937struct ReplCtx
938{
937 /** 939 /**
938 * Function to call for the result (or the NULL). 940 * Function to call for the result (or the NULL).
939 */ 941 */
@@ -976,37 +978,37 @@ struct ReplCtx {
976 * #GNUNET_NO to delete the item 978 * #GNUNET_NO to delete the item
977 */ 979 */
978static int 980static int
979repl_proc(void *cls, 981repl_proc (void *cls,
980 const struct GNUNET_HashCode *key, 982 const struct GNUNET_HashCode *key,
981 uint32_t size, 983 uint32_t size,
982 const void *data, 984 const void *data,
983 enum GNUNET_BLOCK_Type type, 985 enum GNUNET_BLOCK_Type type,
984 uint32_t priority, 986 uint32_t priority,
985 uint32_t anonymity, 987 uint32_t anonymity,
986 uint32_t replication, 988 uint32_t replication,
987 struct GNUNET_TIME_Absolute expiration, 989 struct GNUNET_TIME_Absolute expiration,
988 uint64_t uid) 990 uint64_t uid)
989{ 991{
990 struct ReplCtx *rc = cls; 992 struct ReplCtx *rc = cls;
991 int ret; 993 int ret;
992 994
993 if (GNUNET_SYSERR == rc->have_uid) 995 if (GNUNET_SYSERR == rc->have_uid)
994 rc->have_uid = GNUNET_NO; 996 rc->have_uid = GNUNET_NO;
995 ret = rc->proc(rc->proc_cls, 997 ret = rc->proc (rc->proc_cls,
996 key, 998 key,
997 size, 999 size,
998 data, 1000 data,
999 type, 1001 type,
1000 priority, 1002 priority,
1001 anonymity, 1003 anonymity,
1002 replication, 1004 replication,
1003 expiration, 1005 expiration,
1004 uid); 1006 uid);
1005 if (NULL != key) 1007 if (NULL != key)
1006 { 1008 {
1007 rc->uid = uid; 1009 rc->uid = uid;
1008 rc->have_uid = GNUNET_YES; 1010 rc->have_uid = GNUNET_YES;
1009 } 1011 }
1010 return ret; 1012 return ret;
1011} 1013}
1012 1014
@@ -1022,61 +1024,61 @@ repl_proc(void *cls,
1022 * @param proc_cls closure for @a proc 1024 * @param proc_cls closure for @a proc
1023 */ 1025 */
1024static void 1026static void
1025sqlite_plugin_get_replication(void *cls, 1027sqlite_plugin_get_replication (void *cls,
1026 PluginDatumProcessor proc, 1028 PluginDatumProcessor proc,
1027 void *proc_cls) 1029 void *proc_cls)
1028{ 1030{
1029 struct Plugin *plugin = cls; 1031 struct Plugin *plugin = cls;
1030 struct ReplCtx rc; 1032 struct ReplCtx rc;
1031 uint64_t rvalue; 1033 uint64_t rvalue;
1032 uint32_t repl; 1034 uint32_t repl;
1033 struct GNUNET_SQ_QueryParam params_sel_repl[] = 1035 struct GNUNET_SQ_QueryParam params_sel_repl[] =
1034 { GNUNET_SQ_query_param_uint64(&rvalue), 1036 { GNUNET_SQ_query_param_uint64 (&rvalue),
1035 GNUNET_SQ_query_param_uint32(&repl), 1037 GNUNET_SQ_query_param_uint32 (&repl),
1036 GNUNET_SQ_query_param_end }; 1038 GNUNET_SQ_query_param_end };
1037 struct GNUNET_SQ_QueryParam params_upd_repl[] = 1039 struct GNUNET_SQ_QueryParam params_upd_repl[] =
1038 { GNUNET_SQ_query_param_uint64(&rc.uid), GNUNET_SQ_query_param_end }; 1040 { GNUNET_SQ_query_param_uint64 (&rc.uid), GNUNET_SQ_query_param_end };
1039 1041
1040 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, 1042 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1041 "datastore-sqlite", 1043 "datastore-sqlite",
1042 "Getting random block based on replication order.\n"); 1044 "Getting random block based on replication order.\n");
1043 if (SQLITE_ROW != sqlite3_step(plugin->maxRepl)) 1045 if (SQLITE_ROW != sqlite3_step (plugin->maxRepl))
1044 { 1046 {
1045 GNUNET_SQ_reset(plugin->dbh, plugin->maxRepl); 1047 GNUNET_SQ_reset (plugin->dbh, plugin->maxRepl);
1046 /* DB empty */ 1048 /* DB empty */
1047 proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 1049 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1048 return; 1050 return;
1049 } 1051 }
1050 repl = sqlite3_column_int(plugin->maxRepl, 0); 1052 repl = sqlite3_column_int (plugin->maxRepl, 0);
1051 GNUNET_SQ_reset(plugin->dbh, plugin->maxRepl); 1053 GNUNET_SQ_reset (plugin->dbh, plugin->maxRepl);
1052 rvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); 1054 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
1053 if (GNUNET_OK != GNUNET_SQ_bind(plugin->selRepl, params_sel_repl)) 1055 if (GNUNET_OK != GNUNET_SQ_bind (plugin->selRepl, params_sel_repl))
1054 { 1056 {
1055 proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 1057 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1056 return; 1058 return;
1057 } 1059 }
1058 rc.have_uid = GNUNET_SYSERR; 1060 rc.have_uid = GNUNET_SYSERR;
1059 rc.proc = proc; 1061 rc.proc = proc;
1060 rc.proc_cls = proc_cls; 1062 rc.proc_cls = proc_cls;
1061 execute_get(plugin, plugin->selRepl, &repl_proc, &rc); 1063 execute_get (plugin, plugin->selRepl, &repl_proc, &rc);
1062 if (GNUNET_YES == rc.have_uid) 1064 if (GNUNET_YES == rc.have_uid)
1065 {
1066 if (GNUNET_OK != GNUNET_SQ_bind (plugin->updRepl, params_upd_repl))
1063 { 1067 {
1064 if (GNUNET_OK != GNUNET_SQ_bind(plugin->updRepl, params_upd_repl)) 1068 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1065 { 1069 return;
1066 proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1067 return;
1068 }
1069 if (SQLITE_DONE != sqlite3_step(plugin->updRepl))
1070 LOG_SQLITE(plugin,
1071 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1072 "sqlite3_step");
1073 GNUNET_SQ_reset(plugin->dbh, plugin->updRepl);
1074 } 1070 }
1071 if (SQLITE_DONE != sqlite3_step (plugin->updRepl))
1072 LOG_SQLITE (plugin,
1073 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1074 "sqlite3_step");
1075 GNUNET_SQ_reset (plugin->dbh, plugin->updRepl);
1076 }
1075 if (GNUNET_SYSERR == rc.have_uid) 1077 if (GNUNET_SYSERR == rc.have_uid)
1076 { 1078 {
1077 /* proc was not called at all so far, do it now. */ 1079 /* proc was not called at all so far, do it now. */
1078 proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 1080 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1079 } 1081 }
1080} 1082}
1081 1083
1082 1084
@@ -1089,29 +1091,29 @@ sqlite_plugin_get_replication(void *cls,
1089 * @param proc_cls closure for @a proc 1091 * @param proc_cls closure for @a proc
1090 */ 1092 */
1091static void 1093static void
1092sqlite_plugin_get_expiration(void *cls, 1094sqlite_plugin_get_expiration (void *cls,
1093 PluginDatumProcessor proc, 1095 PluginDatumProcessor proc,
1094 void *proc_cls) 1096 void *proc_cls)
1095{ 1097{
1096 struct Plugin *plugin = cls; 1098 struct Plugin *plugin = cls;
1097 sqlite3_stmt *stmt; 1099 sqlite3_stmt *stmt;
1098 struct GNUNET_TIME_Absolute now; 1100 struct GNUNET_TIME_Absolute now;
1099 struct GNUNET_SQ_QueryParam params[] = { GNUNET_SQ_query_param_absolute_time( 1101 struct GNUNET_SQ_QueryParam params[] = { GNUNET_SQ_query_param_absolute_time (
1100 &now), 1102 &now),
1101 GNUNET_SQ_query_param_end }; 1103 GNUNET_SQ_query_param_end };
1102 1104
1103 GNUNET_log_from( 1105 GNUNET_log_from (
1104 GNUNET_ERROR_TYPE_DEBUG, 1106 GNUNET_ERROR_TYPE_DEBUG,
1105 "sqlite", 1107 "sqlite",
1106 "Getting random block based on expiration and priority order.\n"); 1108 "Getting random block based on expiration and priority order.\n");
1107 now = GNUNET_TIME_absolute_get(); 1109 now = GNUNET_TIME_absolute_get ();
1108 stmt = plugin->selExpi; 1110 stmt = plugin->selExpi;
1109 if (GNUNET_OK != GNUNET_SQ_bind(stmt, params)) 1111 if (GNUNET_OK != GNUNET_SQ_bind (stmt, params))
1110 { 1112 {
1111 proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 1113 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1112 return; 1114 return;
1113 } 1115 }
1114 execute_get(plugin, stmt, proc, proc_cls); 1116 execute_get (plugin, stmt, proc, proc_cls);
1115} 1117}
1116 1118
1117 1119
@@ -1123,35 +1125,35 @@ sqlite_plugin_get_expiration(void *cls,
1123 * @param proc_cls closure for @a proc 1125 * @param proc_cls closure for @a proc
1124 */ 1126 */
1125static void 1127static void
1126sqlite_plugin_get_keys(void *cls, PluginKeyProcessor proc, void *proc_cls) 1128sqlite_plugin_get_keys (void *cls, PluginKeyProcessor proc, void *proc_cls)
1127{ 1129{
1128 struct Plugin *plugin = cls; 1130 struct Plugin *plugin = cls;
1129 struct GNUNET_HashCode key; 1131 struct GNUNET_HashCode key;
1130 struct GNUNET_SQ_ResultSpec results[] = 1132 struct GNUNET_SQ_ResultSpec results[] =
1131 { GNUNET_SQ_result_spec_auto_from_type(&key), GNUNET_SQ_result_spec_end }; 1133 { GNUNET_SQ_result_spec_auto_from_type (&key), GNUNET_SQ_result_spec_end };
1132 sqlite3_stmt *stmt; 1134 sqlite3_stmt *stmt;
1133 int ret; 1135 int ret;
1134 1136
1135 GNUNET_assert(NULL != proc); 1137 GNUNET_assert (NULL != proc);
1136 if (SQLITE_OK != sq_prepare(plugin->dbh, "SELECT hash FROM gn091", &stmt)) 1138 if (SQLITE_OK != sq_prepare (plugin->dbh, "SELECT hash FROM gn091", &stmt))
1137 { 1139 {
1138 LOG_SQLITE(plugin, 1140 LOG_SQLITE (plugin,
1139 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 1141 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1140 "sqlite_prepare"); 1142 "sqlite_prepare");
1141 proc(proc_cls, NULL, 0); 1143 proc (proc_cls, NULL, 0);
1142 return; 1144 return;
1143 } 1145 }
1144 while (SQLITE_ROW == (ret = sqlite3_step(stmt))) 1146 while (SQLITE_ROW == (ret = sqlite3_step (stmt)))
1145 { 1147 {
1146 if (GNUNET_OK == GNUNET_SQ_extract_result(stmt, results)) 1148 if (GNUNET_OK == GNUNET_SQ_extract_result (stmt, results))
1147 proc(proc_cls, &key, 1); 1149 proc (proc_cls, &key, 1);
1148 else 1150 else
1149 GNUNET_break(0); 1151 GNUNET_break (0);
1150 } 1152 }
1151 if (SQLITE_DONE != ret) 1153 if (SQLITE_DONE != ret)
1152 LOG_SQLITE(plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step"); 1154 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step");
1153 sqlite3_finalize(stmt); 1155 sqlite3_finalize (stmt);
1154 proc(proc_cls, NULL, 0); 1156 proc (proc_cls, NULL, 0);
1155} 1157}
1156 1158
1157 1159
@@ -1161,7 +1163,7 @@ sqlite_plugin_get_keys(void *cls, PluginKeyProcessor proc, void *proc_cls)
1161 * @param cls our plugin context 1163 * @param cls our plugin context
1162 */ 1164 */
1163static void 1165static void
1164sqlite_plugin_drop(void *cls) 1166sqlite_plugin_drop (void *cls)
1165{ 1167{
1166 struct Plugin *plugin = cls; 1168 struct Plugin *plugin = cls;
1167 1169
@@ -1180,44 +1182,44 @@ sqlite_plugin_drop(void *cls)
1180 * @param cont_cls continuation closure for @a cont 1182 * @param cont_cls continuation closure for @a cont
1181 */ 1183 */
1182static void 1184static void
1183sqlite_plugin_remove_key(void *cls, 1185sqlite_plugin_remove_key (void *cls,
1184 const struct GNUNET_HashCode *key, 1186 const struct GNUNET_HashCode *key,
1185 uint32_t size, 1187 uint32_t size,
1186 const void *data, 1188 const void *data,
1187 PluginRemoveCont cont, 1189 PluginRemoveCont cont,
1188 void *cont_cls) 1190 void *cont_cls)
1189{ 1191{
1190 struct Plugin *plugin = cls; 1192 struct Plugin *plugin = cls;
1191 struct GNUNET_SQ_QueryParam params[] = 1193 struct GNUNET_SQ_QueryParam params[] =
1192 { GNUNET_SQ_query_param_auto_from_type(key), 1194 { GNUNET_SQ_query_param_auto_from_type (key),
1193 GNUNET_SQ_query_param_fixed_size(data, size), 1195 GNUNET_SQ_query_param_fixed_size (data, size),
1194 GNUNET_SQ_query_param_end }; 1196 GNUNET_SQ_query_param_end };
1195 1197
1196 if (GNUNET_OK != GNUNET_SQ_bind(plugin->remove, params)) 1198 if (GNUNET_OK != GNUNET_SQ_bind (plugin->remove, params))
1197 { 1199 {
1198 cont(cont_cls, key, size, GNUNET_SYSERR, "bind failed"); 1200 cont (cont_cls, key, size, GNUNET_SYSERR, "bind failed");
1199 return; 1201 return;
1200 } 1202 }
1201 if (SQLITE_DONE != sqlite3_step(plugin->remove)) 1203 if (SQLITE_DONE != sqlite3_step (plugin->remove))
1202 { 1204 {
1203 LOG_SQLITE(plugin, 1205 LOG_SQLITE (plugin,
1204 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 1206 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1205 "sqlite3_step"); 1207 "sqlite3_step");
1206 GNUNET_SQ_reset(plugin->dbh, plugin->remove); 1208 GNUNET_SQ_reset (plugin->dbh, plugin->remove);
1207 cont(cont_cls, key, size, GNUNET_SYSERR, "sqlite3_step failed"); 1209 cont (cont_cls, key, size, GNUNET_SYSERR, "sqlite3_step failed");
1208 return; 1210 return;
1209 } 1211 }
1210 int changes = sqlite3_changes(plugin->dbh); 1212 int changes = sqlite3_changes (plugin->dbh);
1211 GNUNET_SQ_reset(plugin->dbh, plugin->remove); 1213 GNUNET_SQ_reset (plugin->dbh, plugin->remove);
1212 if (0 == changes) 1214 if (0 == changes)
1213 { 1215 {
1214 cont(cont_cls, key, size, GNUNET_NO, NULL); 1216 cont (cont_cls, key, size, GNUNET_NO, NULL);
1215 return; 1217 return;
1216 } 1218 }
1217 if (NULL != plugin->env->duc) 1219 if (NULL != plugin->env->duc)
1218 plugin->env->duc(plugin->env->cls, 1220 plugin->env->duc (plugin->env->cls,
1219 -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); 1221 -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
1220 cont(cont_cls, key, size, GNUNET_OK, NULL); 1222 cont (cont_cls, key, size, GNUNET_OK, NULL);
1221} 1223}
1222 1224
1223 1225
@@ -1229,7 +1231,7 @@ sqlite_plugin_remove_key(void *cls,
1229 * @return the size of the database on disk (estimate) 1231 * @return the size of the database on disk (estimate)
1230 */ 1232 */
1231static void 1233static void
1232sqlite_plugin_estimate_size(void *cls, unsigned long long *estimate) 1234sqlite_plugin_estimate_size (void *cls, unsigned long long *estimate)
1233{ 1235{
1234 struct Plugin *plugin = cls; 1236 struct Plugin *plugin = cls;
1235 sqlite3_stmt *stmt; 1237 sqlite3_stmt *stmt;
@@ -1243,36 +1245,36 @@ sqlite_plugin_estimate_size(void *cls, unsigned long long *estimate)
1243 if (NULL == estimate) 1245 if (NULL == estimate)
1244 return; 1246 return;
1245 if (SQLITE_VERSION_NUMBER < 3006000) 1247 if (SQLITE_VERSION_NUMBER < 3006000)
1246 { 1248 {
1247 GNUNET_log_from( 1249 GNUNET_log_from (
1248 GNUNET_ERROR_TYPE_WARNING, 1250 GNUNET_ERROR_TYPE_WARNING,
1249 "datastore-sqlite", 1251 "datastore-sqlite",
1250 _("sqlite version to old to determine size, assuming zero\n")); 1252 _ ("sqlite version to old to determine size, assuming zero\n"));
1251 *estimate = 0; 1253 *estimate = 0;
1252 return; 1254 return;
1253 } 1255 }
1254 CHECK(SQLITE_OK == sqlite3_exec(plugin->dbh, "VACUUM", NULL, NULL, ENULL)); 1256 CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, "VACUUM", NULL, NULL, ENULL));
1255 CHECK(SQLITE_OK == sqlite3_exec(plugin->dbh, 1257 CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh,
1256 "PRAGMA auto_vacuum=INCREMENTAL", 1258 "PRAGMA auto_vacuum=INCREMENTAL",
1257 NULL, 1259 NULL,
1258 NULL, 1260 NULL,
1259 ENULL)); 1261 ENULL));
1260 CHECK(SQLITE_OK == sq_prepare(plugin->dbh, "PRAGMA page_count", &stmt)); 1262 CHECK (SQLITE_OK == sq_prepare (plugin->dbh, "PRAGMA page_count", &stmt));
1261 if (SQLITE_ROW == sqlite3_step(stmt)) 1263 if (SQLITE_ROW == sqlite3_step (stmt))
1262 pages = sqlite3_column_int64(stmt, 0); 1264 pages = sqlite3_column_int64 (stmt, 0);
1263 else 1265 else
1264 pages = 0; 1266 pages = 0;
1265 sqlite3_finalize(stmt); 1267 sqlite3_finalize (stmt);
1266 CHECK(SQLITE_OK == sq_prepare(plugin->dbh, "PRAGMA page_size", &stmt)); 1268 CHECK (SQLITE_OK == sq_prepare (plugin->dbh, "PRAGMA page_size", &stmt));
1267 CHECK(SQLITE_ROW == sqlite3_step(stmt)); 1269 CHECK (SQLITE_ROW == sqlite3_step (stmt));
1268 page_size = sqlite3_column_int64(stmt, 0); 1270 page_size = sqlite3_column_int64 (stmt, 0);
1269 sqlite3_finalize(stmt); 1271 sqlite3_finalize (stmt);
1270 GNUNET_log( 1272 GNUNET_log (
1271 GNUNET_ERROR_TYPE_INFO, 1273 GNUNET_ERROR_TYPE_INFO,
1272 _( 1274 _ (
1273 "Using sqlite page utilization to estimate payload (%llu pages of size %llu bytes)\n"), 1275 "Using sqlite page utilization to estimate payload (%llu pages of size %llu bytes)\n"),
1274 (unsigned long long)pages, 1276 (unsigned long long) pages,
1275 (unsigned long long)page_size); 1277 (unsigned long long) page_size);
1276 *estimate = pages * page_size; 1278 *estimate = pages * page_size;
1277} 1279}
1278 1280
@@ -1284,7 +1286,7 @@ sqlite_plugin_estimate_size(void *cls, unsigned long long *estimate)
1284 * @return NULL on error, othrewise the plugin context 1286 * @return NULL on error, othrewise the plugin context
1285 */ 1287 */
1286void * 1288void *
1287libgnunet_plugin_datastore_sqlite_init(void *cls) 1289libgnunet_plugin_datastore_sqlite_init (void *cls)
1288{ 1290{
1289 static struct Plugin plugin; 1291 static struct Plugin plugin;
1290 struct GNUNET_DATASTORE_PluginEnvironment *env = cls; 1292 struct GNUNET_DATASTORE_PluginEnvironment *env = cls;
@@ -1292,14 +1294,14 @@ libgnunet_plugin_datastore_sqlite_init(void *cls)
1292 1294
1293 if (NULL != plugin.env) 1295 if (NULL != plugin.env)
1294 return NULL; /* can only initialize once! */ 1296 return NULL; /* can only initialize once! */
1295 memset(&plugin, 0, sizeof(struct Plugin)); 1297 memset (&plugin, 0, sizeof(struct Plugin));
1296 plugin.env = env; 1298 plugin.env = env;
1297 if (GNUNET_OK != database_setup(env->cfg, &plugin)) 1299 if (GNUNET_OK != database_setup (env->cfg, &plugin))
1298 { 1300 {
1299 database_shutdown(&plugin); 1301 database_shutdown (&plugin);
1300 return NULL; 1302 return NULL;
1301 } 1303 }
1302 api = GNUNET_new(struct GNUNET_DATASTORE_PluginFunctions); 1304 api = GNUNET_new (struct GNUNET_DATASTORE_PluginFunctions);
1303 api->cls = &plugin; 1305 api->cls = &plugin;
1304 api->estimate_size = &sqlite_plugin_estimate_size; 1306 api->estimate_size = &sqlite_plugin_estimate_size;
1305 api->put = &sqlite_plugin_put; 1307 api->put = &sqlite_plugin_put;
@@ -1310,9 +1312,9 @@ libgnunet_plugin_datastore_sqlite_init(void *cls)
1310 api->get_keys = &sqlite_plugin_get_keys; 1312 api->get_keys = &sqlite_plugin_get_keys;
1311 api->drop = &sqlite_plugin_drop; 1313 api->drop = &sqlite_plugin_drop;
1312 api->remove_key = &sqlite_plugin_remove_key; 1314 api->remove_key = &sqlite_plugin_remove_key;
1313 GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, 1315 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
1314 "sqlite", 1316 "sqlite",
1315 _("Sqlite database running\n")); 1317 _ ("Sqlite database running\n"));
1316 return api; 1318 return api;
1317} 1319}
1318 1320
@@ -1324,27 +1326,27 @@ libgnunet_plugin_datastore_sqlite_init(void *cls)
1324 * @return always NULL 1326 * @return always NULL
1325 */ 1327 */
1326void * 1328void *
1327libgnunet_plugin_datastore_sqlite_done(void *cls) 1329libgnunet_plugin_datastore_sqlite_done (void *cls)
1328{ 1330{
1329 char *fn; 1331 char *fn;
1330 struct GNUNET_DATASTORE_PluginFunctions *api = cls; 1332 struct GNUNET_DATASTORE_PluginFunctions *api = cls;
1331 struct Plugin *plugin = api->cls; 1333 struct Plugin *plugin = api->cls;
1332 1334
1333 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, 1335 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1334 "sqlite", 1336 "sqlite",
1335 "sqlite plugin is done\n"); 1337 "sqlite plugin is done\n");
1336 fn = NULL; 1338 fn = NULL;
1337 if (plugin->drop_on_shutdown) 1339 if (plugin->drop_on_shutdown)
1338 fn = GNUNET_strdup(plugin->fn); 1340 fn = GNUNET_strdup (plugin->fn);
1339 database_shutdown(plugin); 1341 database_shutdown (plugin);
1340 plugin->env = NULL; 1342 plugin->env = NULL;
1341 GNUNET_free(api); 1343 GNUNET_free (api);
1342 if (NULL != fn) 1344 if (NULL != fn)
1343 { 1345 {
1344 if (0 != unlink(fn)) 1346 if (0 != unlink (fn))
1345 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", fn); 1347 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
1346 GNUNET_free(fn); 1348 GNUNET_free (fn);
1347 } 1349 }
1348 return NULL; 1350 return NULL;
1349} 1351}
1350 1352
diff --git a/src/datastore/plugin_datastore_template.c b/src/datastore/plugin_datastore_template.c
index dea6151ad..1f9a0f416 100644
--- a/src/datastore/plugin_datastore_template.c
+++ b/src/datastore/plugin_datastore_template.c
@@ -31,7 +31,8 @@
31/** 31/**
32 * Context for all functions in this plugin. 32 * Context for all functions in this plugin.
33 */ 33 */
34struct Plugin { 34struct Plugin
35{
35 /** 36 /**
36 * Our execution environment. 37 * Our execution environment.
37 */ 38 */
@@ -47,11 +48,11 @@ struct Plugin {
47 * @return number of bytes used on disk 48 * @return number of bytes used on disk
48 */ 49 */
49static void 50static void
50template_plugin_estimate_size(void *cls, unsigned long long *estimate) 51template_plugin_estimate_size (void *cls, unsigned long long *estimate)
51{ 52{
52 if (NULL == estimate) 53 if (NULL == estimate)
53 return; 54 return;
54 GNUNET_break(0); 55 GNUNET_break (0);
55 *estimate = 0; 56 *estimate = 0;
56} 57}
57 58
@@ -73,21 +74,21 @@ template_plugin_estimate_size(void *cls, unsigned long long *estimate)
73 * @param cont_cls continuation closure 74 * @param cont_cls continuation closure
74 */ 75 */
75static void 76static void
76template_plugin_put(void *cls, 77template_plugin_put (void *cls,
77 const struct GNUNET_HashCode *key, 78 const struct GNUNET_HashCode *key,
78 bool absent, 79 bool absent,
79 uint32_t size, 80 uint32_t size,
80 const void *data, 81 const void *data,
81 enum GNUNET_BLOCK_Type type, 82 enum GNUNET_BLOCK_Type type,
82 uint32_t priority, 83 uint32_t priority,
83 uint32_t anonymity, 84 uint32_t anonymity,
84 uint32_t replication, 85 uint32_t replication,
85 struct GNUNET_TIME_Absolute expiration, 86 struct GNUNET_TIME_Absolute expiration,
86 PluginPutCont cont, 87 PluginPutCont cont,
87 void *cont_cls) 88 void *cont_cls)
88{ 89{
89 GNUNET_break(0); 90 GNUNET_break (0);
90 cont(cont_cls, key, size, GNUNET_SYSERR, "not implemented"); 91 cont (cont_cls, key, size, GNUNET_SYSERR, "not implemented");
91} 92}
92 93
93 94
@@ -105,15 +106,15 @@ template_plugin_put(void *cls,
105 * @param proc_cls closure for proc 106 * @param proc_cls closure for proc
106 */ 107 */
107static void 108static void
108template_plugin_get_key(void *cls, 109template_plugin_get_key (void *cls,
109 uint64_t next_uid, 110 uint64_t next_uid,
110 bool random, 111 bool random,
111 const struct GNUNET_HashCode *key, 112 const struct GNUNET_HashCode *key,
112 enum GNUNET_BLOCK_Type type, 113 enum GNUNET_BLOCK_Type type,
113 PluginDatumProcessor proc, 114 PluginDatumProcessor proc,
114 void *proc_cls) 115 void *proc_cls)
115{ 116{
116 GNUNET_break(0); 117 GNUNET_break (0);
117} 118}
118 119
119 120
@@ -130,10 +131,10 @@ template_plugin_get_key(void *cls,
130 * @param proc_cls closure for proc 131 * @param proc_cls closure for proc
131 */ 132 */
132static void 133static void
133template_plugin_get_replication(void *cls, PluginDatumProcessor proc, 134template_plugin_get_replication (void *cls, PluginDatumProcessor proc,
134 void *proc_cls) 135 void *proc_cls)
135{ 136{
136 GNUNET_break(0); 137 GNUNET_break (0);
137} 138}
138 139
139 140
@@ -146,10 +147,10 @@ template_plugin_get_replication(void *cls, PluginDatumProcessor proc,
146 * @param proc_cls closure for proc 147 * @param proc_cls closure for proc
147 */ 148 */
148static void 149static void
149template_plugin_get_expiration(void *cls, PluginDatumProcessor proc, 150template_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
150 void *proc_cls) 151 void *proc_cls)
151{ 152{
152 GNUNET_break(0); 153 GNUNET_break (0);
153} 154}
154 155
155 156
@@ -165,11 +166,11 @@ template_plugin_get_expiration(void *cls, PluginDatumProcessor proc,
165 * @param proc_cls closure for proc 166 * @param proc_cls closure for proc
166 */ 167 */
167static void 168static void
168template_plugin_get_zero_anonymity(void *cls, uint64_t next_uid, 169template_plugin_get_zero_anonymity (void *cls, uint64_t next_uid,
169 enum GNUNET_BLOCK_Type type, 170 enum GNUNET_BLOCK_Type type,
170 PluginDatumProcessor proc, void *proc_cls) 171 PluginDatumProcessor proc, void *proc_cls)
171{ 172{
172 GNUNET_break(0); 173 GNUNET_break (0);
173} 174}
174 175
175 176
@@ -177,9 +178,9 @@ template_plugin_get_zero_anonymity(void *cls, uint64_t next_uid,
177 * Drop database. 178 * Drop database.
178 */ 179 */
179static void 180static void
180template_plugin_drop(void *cls) 181template_plugin_drop (void *cls)
181{ 182{
182 GNUNET_break(0); 183 GNUNET_break (0);
183} 184}
184 185
185 186
@@ -191,11 +192,11 @@ template_plugin_drop(void *cls)
191 * @param proc_cls closure for proc 192 * @param proc_cls closure for proc
192 */ 193 */
193static void 194static void
194template_get_keys(void *cls, 195template_get_keys (void *cls,
195 PluginKeyProcessor proc, 196 PluginKeyProcessor proc,
196 void *proc_cls) 197 void *proc_cls)
197{ 198{
198 proc(proc_cls, NULL, 0); 199 proc (proc_cls, NULL, 0);
199} 200}
200 201
201 202
@@ -210,15 +211,15 @@ template_get_keys(void *cls,
210 * @param cont_cls continuation closure for @a cont 211 * @param cont_cls continuation closure for @a cont
211 */ 212 */
212static void 213static void
213template_plugin_remove_key(void *cls, 214template_plugin_remove_key (void *cls,
214 const struct GNUNET_HashCode *key, 215 const struct GNUNET_HashCode *key,
215 uint32_t size, 216 uint32_t size,
216 const void *data, 217 const void *data,
217 PluginRemoveCont cont, 218 PluginRemoveCont cont,
218 void *cont_cls) 219 void *cont_cls)
219{ 220{
220 GNUNET_break(0); 221 GNUNET_break (0);
221 cont(cont_cls, key, size, GNUNET_SYSERR, "not implemented"); 222 cont (cont_cls, key, size, GNUNET_SYSERR, "not implemented");
222} 223}
223 224
224 225
@@ -229,15 +230,15 @@ template_plugin_remove_key(void *cls,
229 * @return our "struct Plugin*" 230 * @return our "struct Plugin*"
230 */ 231 */
231void * 232void *
232libgnunet_plugin_datastore_template_init(void *cls) 233libgnunet_plugin_datastore_template_init (void *cls)
233{ 234{
234 struct GNUNET_DATASTORE_PluginEnvironment *env = cls; 235 struct GNUNET_DATASTORE_PluginEnvironment *env = cls;
235 struct GNUNET_DATASTORE_PluginFunctions *api; 236 struct GNUNET_DATASTORE_PluginFunctions *api;
236 struct Plugin *plugin; 237 struct Plugin *plugin;
237 238
238 plugin = GNUNET_new(struct Plugin); 239 plugin = GNUNET_new (struct Plugin);
239 plugin->env = env; 240 plugin->env = env;
240 api = GNUNET_new(struct GNUNET_DATASTORE_PluginFunctions); 241 api = GNUNET_new (struct GNUNET_DATASTORE_PluginFunctions);
241 api->cls = plugin; 242 api->cls = plugin;
242 api->estimate_size = &template_plugin_estimate_size; 243 api->estimate_size = &template_plugin_estimate_size;
243 api->put = &template_plugin_put; 244 api->put = &template_plugin_put;
@@ -248,8 +249,8 @@ libgnunet_plugin_datastore_template_init(void *cls)
248 api->drop = &template_plugin_drop; 249 api->drop = &template_plugin_drop;
249 api->get_keys = &template_get_keys; 250 api->get_keys = &template_get_keys;
250 api->remove_key = &template_plugin_remove_key; 251 api->remove_key = &template_plugin_remove_key;
251 GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "template", 252 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "template",
252 _("Template database running\n")); 253 _ ("Template database running\n"));
253 return api; 254 return api;
254} 255}
255 256
@@ -260,13 +261,13 @@ libgnunet_plugin_datastore_template_init(void *cls)
260 * @return always NULL 261 * @return always NULL
261 */ 262 */
262void * 263void *
263libgnunet_plugin_datastore_template_done(void *cls) 264libgnunet_plugin_datastore_template_done (void *cls)
264{ 265{
265 struct GNUNET_DATASTORE_PluginFunctions *api = cls; 266 struct GNUNET_DATASTORE_PluginFunctions *api = cls;
266 struct Plugin *plugin = api->cls; 267 struct Plugin *plugin = api->cls;
267 268
268 GNUNET_free(plugin); 269 GNUNET_free (plugin);
269 GNUNET_free(api); 270 GNUNET_free (api);
270 return NULL; 271 return NULL;
271} 272}
272 273
diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c
index 56a7cdd3b..93ba46ff8 100644
--- a/src/datastore/test_datastore_api.c
+++ b/src/datastore/test_datastore_api.c
@@ -37,7 +37,7 @@
37/** 37/**
38 * How long until we give up on transmitting the message? 38 * How long until we give up on transmitting the message?
39 */ 39 */
40#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) 40#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
41 41
42#define ITERATIONS 256 42#define ITERATIONS 256
43 43
@@ -60,45 +60,45 @@ static const char *plugin_name;
60 60
61 61
62static size_t 62static size_t
63get_size(int i) 63get_size (int i)
64{ 64{
65 return 8 * i; 65 return 8 * i;
66} 66}
67 67
68 68
69static const void * 69static const void *
70get_data(int i) 70get_data (int i)
71{ 71{
72 static char buf[60000]; 72 static char buf[60000];
73 73
74 memset(buf, i, 8 * i); 74 memset (buf, i, 8 * i);
75 return buf; 75 return buf;
76} 76}
77 77
78 78
79static int 79static int
80get_type(int i) 80get_type (int i)
81{ 81{
82 return i + 1; 82 return i + 1;
83} 83}
84 84
85 85
86static int 86static int
87get_priority(int i) 87get_priority (int i)
88{ 88{
89 return i + 1; 89 return i + 1;
90} 90}
91 91
92 92
93static int 93static int
94get_anonymity(int i) 94get_anonymity (int i)
95{ 95{
96 return i; 96 return i;
97} 97}
98 98
99 99
100static struct GNUNET_TIME_Absolute 100static struct GNUNET_TIME_Absolute
101get_expiration(int i) 101get_expiration (int i)
102{ 102{
103 struct GNUNET_TIME_Absolute av; 103 struct GNUNET_TIME_Absolute av;
104 104
@@ -110,7 +110,8 @@ get_expiration(int i)
110/** 110/**
111 * Which phase of the process are we in? 111 * Which phase of the process are we in?
112 */ 112 */
113enum RunPhase { 113enum RunPhase
114{
114 /** 115 /**
115 * We are done (shutting down normally). 116 * We are done (shutting down normally).
116 */ 117 */
@@ -142,7 +143,8 @@ enum RunPhase {
142 * benchmark. Could right now be global, but this allows 143 * benchmark. Could right now be global, but this allows
143 * us to theoretically run multiple clients "in parallel". 144 * us to theoretically run multiple clients "in parallel".
144 */ 145 */
145struct CpsRunContext { 146struct CpsRunContext
147{
146 /** 148 /**
147 * Execution phase we are in. 149 * Execution phase we are in.
148 */ 150 */
@@ -165,7 +167,7 @@ struct CpsRunContext {
165 * @param cls the `struct CpsRunContext` 167 * @param cls the `struct CpsRunContext`
166 */ 168 */
167static void 169static void
168run_continuation(void *cls); 170run_continuation (void *cls);
169 171
170 172
171/** 173/**
@@ -180,102 +182,49 @@ run_continuation(void *cls);
180 * @param msg NULL on success, otherwise an error message 182 * @param msg NULL on success, otherwise an error message
181 */ 183 */
182static void 184static void
183check_success(void *cls, 185check_success (void *cls,
184 int success, 186 int success,
185 struct GNUNET_TIME_Absolute min_expiration, 187 struct GNUNET_TIME_Absolute min_expiration,
186 const char *msg) 188 const char *msg)
187{ 189{
188 struct CpsRunContext *crc = cls; 190 struct CpsRunContext *crc = cls;
189 191
190 if (GNUNET_OK != success) 192 if (GNUNET_OK != success)
191 { 193 {
192 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 194 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
193 "Operation %d/%d not successful: `%s'\n", 195 "Operation %d/%d not successful: `%s'\n",
194 crc->phase, 196 crc->phase,
195 crc->i, 197 crc->i,
196 msg); 198 msg);
197 crc->phase = RP_ERROR; 199 crc->phase = RP_ERROR;
198 } 200 }
199 GNUNET_free_non_null(crc->data); 201 GNUNET_free_non_null (crc->data);
200 crc->data = NULL; 202 crc->data = NULL;
201 GNUNET_SCHEDULER_add_now(&run_continuation, crc); 203 GNUNET_SCHEDULER_add_now (&run_continuation, crc);
202} 204}
203 205
204 206
205static void 207static void
206get_reserved(void *cls, 208get_reserved (void *cls,
207 int success, 209 int success,
208 struct GNUNET_TIME_Absolute min_expiration, 210 struct GNUNET_TIME_Absolute min_expiration,
209 const char *msg) 211 const char *msg)
210{ 212{
211 struct CpsRunContext *crc = cls; 213 struct CpsRunContext *crc = cls;
212 214
213 if (0 >= success) 215 if (0 >= success)
214 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 216 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
215 "Error obtaining reservation: `%s'\n", 217 "Error obtaining reservation: `%s'\n",
216 msg); 218 msg);
217 GNUNET_assert(0 < success); 219 GNUNET_assert (0 < success);
218 crc->rid = success; 220 crc->rid = success;
219 GNUNET_SCHEDULER_add_now(&run_continuation, 221 GNUNET_SCHEDULER_add_now (&run_continuation,
220 crc); 222 crc);
221}
222
223
224static void
225check_value(void *cls,
226 const struct GNUNET_HashCode *key,
227 size_t size,
228 const void *data,
229 enum GNUNET_BLOCK_Type type,
230 uint32_t priority,
231 uint32_t anonymity,
232 uint32_t replication,
233 struct GNUNET_TIME_Absolute expiration,
234 uint64_t uid)
235{
236 struct CpsRunContext *crc = cls;
237 int i;
238
239 i = crc->i;
240 if (NULL == key)
241 {
242 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
243 "Value check failed (got NULL key) in %d/%d\n",
244 crc->phase,
245 crc->i);
246 crc->phase = RP_ERROR;
247 GNUNET_SCHEDULER_add_now(&run_continuation,
248 crc);
249 return;
250 }
251#if 0
252 fprintf(stderr,
253 "Check value got `%s' of size %u, type %d, expire %s\n",
254 GNUNET_h2s(key), (unsigned int)size, type,
255 GNUNET_STRINGS_absolute_time_to_string(expiration));
256 fprintf(stderr,
257 "Check value iteration %d wants size %u, type %d, expire %s\n", i,
258 (unsigned int)get_size(i), get_type(i),
259 GNUNET_STRINGS_absolute_time_to_string(get_expiration(i)));
260#endif
261 GNUNET_assert(size == get_size(i));
262 GNUNET_assert(0 == memcmp(data, get_data(i), size));
263 GNUNET_assert(type == get_type(i));
264 GNUNET_assert(priority == get_priority(i));
265 GNUNET_assert(anonymity == get_anonymity(i));
266 GNUNET_assert(expiration.abs_value_us == get_expiration(i).abs_value_us);
267 if (crc->i == 0)
268 {
269 crc->phase = RP_DEL;
270 crc->i = ITERATIONS;
271 }
272 GNUNET_SCHEDULER_add_now(&run_continuation,
273 crc);
274} 223}
275 224
276 225
277static void 226static void
278delete_value(void *cls, 227check_value (void *cls,
279 const struct GNUNET_HashCode *key, 228 const struct GNUNET_HashCode *key,
280 size_t size, 229 size_t size,
281 const void *data, 230 const void *data,
@@ -287,21 +236,48 @@ delete_value(void *cls,
287 uint64_t uid) 236 uint64_t uid)
288{ 237{
289 struct CpsRunContext *crc = cls; 238 struct CpsRunContext *crc = cls;
239 int i;
290 240
291 GNUNET_assert(NULL == crc->data); 241 i = crc->i;
292 GNUNET_assert(NULL != key); 242 if (NULL == key)
293 crc->size = size; 243 {
294 crc->key = *key; 244 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
295 crc->data = GNUNET_malloc(size); 245 "Value check failed (got NULL key) in %d/%d\n",
296 GNUNET_memcpy(crc->data, data, size); 246 crc->phase,
297 crc->phase = RP_DO_DEL; 247 crc->i);
298 GNUNET_SCHEDULER_add_now(&run_continuation, 248 crc->phase = RP_ERROR;
299 crc); 249 GNUNET_SCHEDULER_add_now (&run_continuation,
250 crc);
251 return;
252 }
253#if 0
254 fprintf (stderr,
255 "Check value got `%s' of size %u, type %d, expire %s\n",
256 GNUNET_h2s (key), (unsigned int) size, type,
257 GNUNET_STRINGS_absolute_time_to_string (expiration));
258 fprintf (stderr,
259 "Check value iteration %d wants size %u, type %d, expire %s\n", i,
260 (unsigned int) get_size (i), get_type (i),
261 GNUNET_STRINGS_absolute_time_to_string (get_expiration (i)));
262#endif
263 GNUNET_assert (size == get_size (i));
264 GNUNET_assert (0 == memcmp (data, get_data (i), size));
265 GNUNET_assert (type == get_type (i));
266 GNUNET_assert (priority == get_priority (i));
267 GNUNET_assert (anonymity == get_anonymity (i));
268 GNUNET_assert (expiration.abs_value_us == get_expiration (i).abs_value_us);
269 if (crc->i == 0)
270 {
271 crc->phase = RP_DEL;
272 crc->i = ITERATIONS;
273 }
274 GNUNET_SCHEDULER_add_now (&run_continuation,
275 crc);
300} 276}
301 277
302 278
303static void 279static void
304check_nothing(void *cls, 280delete_value (void *cls,
305 const struct GNUNET_HashCode *key, 281 const struct GNUNET_HashCode *key,
306 size_t size, 282 size_t size,
307 const void *data, 283 const void *data,
@@ -314,16 +290,20 @@ check_nothing(void *cls,
314{ 290{
315 struct CpsRunContext *crc = cls; 291 struct CpsRunContext *crc = cls;
316 292
317 GNUNET_assert(key == NULL); 293 GNUNET_assert (NULL == crc->data);
318 if (crc->i == 0) 294 GNUNET_assert (NULL != key);
319 crc->phase = RP_RESERVE; 295 crc->size = size;
320 GNUNET_SCHEDULER_add_now(&run_continuation, 296 crc->key = *key;
321 crc); 297 crc->data = GNUNET_malloc (size);
298 GNUNET_memcpy (crc->data, data, size);
299 crc->phase = RP_DO_DEL;
300 GNUNET_SCHEDULER_add_now (&run_continuation,
301 crc);
322} 302}
323 303
324 304
325static void 305static void
326check_multiple(void *cls, 306check_nothing (void *cls,
327 const struct GNUNET_HashCode *key, 307 const struct GNUNET_HashCode *key,
328 size_t size, 308 size_t size,
329 const void *data, 309 const void *data,
@@ -336,25 +316,47 @@ check_multiple(void *cls,
336{ 316{
337 struct CpsRunContext *crc = cls; 317 struct CpsRunContext *crc = cls;
338 318
339 GNUNET_assert(key != NULL); 319 GNUNET_assert (key == NULL);
320 if (crc->i == 0)
321 crc->phase = RP_RESERVE;
322 GNUNET_SCHEDULER_add_now (&run_continuation,
323 crc);
324}
325
326
327static void
328check_multiple (void *cls,
329 const struct GNUNET_HashCode *key,
330 size_t size,
331 const void *data,
332 enum GNUNET_BLOCK_Type type,
333 uint32_t priority,
334 uint32_t anonymity,
335 uint32_t replication,
336 struct GNUNET_TIME_Absolute expiration,
337 uint64_t uid)
338{
339 struct CpsRunContext *crc = cls;
340
341 GNUNET_assert (key != NULL);
340 switch (crc->phase) 342 switch (crc->phase)
341 { 343 {
342 case RP_GET_MULTIPLE: 344 case RP_GET_MULTIPLE:
343 crc->phase = RP_GET_MULTIPLE_NEXT; 345 crc->phase = RP_GET_MULTIPLE_NEXT;
344 crc->first_uid = uid; 346 crc->first_uid = uid;
345 break; 347 break;
346 348
347 case RP_GET_MULTIPLE_NEXT: 349 case RP_GET_MULTIPLE_NEXT:
348 GNUNET_assert(uid != crc->first_uid); 350 GNUNET_assert (uid != crc->first_uid);
349 crc->phase = RP_DONE; 351 crc->phase = RP_DONE;
350 break; 352 break;
351 353
352 default: 354 default:
353 GNUNET_break(0); 355 GNUNET_break (0);
354 crc->phase = RP_ERROR; 356 crc->phase = RP_ERROR;
355 break; 357 break;
356 } 358 }
357 GNUNET_SCHEDULER_add_now(&run_continuation, crc); 359 GNUNET_SCHEDULER_add_now (&run_continuation, crc);
358} 360}
359 361
360 362
@@ -365,177 +367,177 @@ check_multiple(void *cls,
365 * @param cls the `struct CpsRunContext` 367 * @param cls the `struct CpsRunContext`
366 */ 368 */
367static void 369static void
368run_continuation(void *cls) 370run_continuation (void *cls)
369{ 371{
370 struct CpsRunContext *crc = cls; 372 struct CpsRunContext *crc = cls;
371 373
372 ok = (int)crc->phase; 374 ok = (int) crc->phase;
373 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 375 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
374 "Test in phase %u\n", 376 "Test in phase %u\n",
375 crc->phase); 377 crc->phase);
376 switch (crc->phase) 378 switch (crc->phase)
377 { 379 {
378 case RP_PUT: 380 case RP_PUT:
379 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
380 "Executing PUT number %u\n", 382 "Executing PUT number %u\n",
381 crc->i); 383 crc->i);
382 GNUNET_CRYPTO_hash(&crc->i, sizeof(int), &crc->key); 384 GNUNET_CRYPTO_hash (&crc->i, sizeof(int), &crc->key);
383 GNUNET_DATASTORE_put(datastore, 0, &crc->key, get_size(crc->i), 385 GNUNET_DATASTORE_put (datastore, 0, &crc->key, get_size (crc->i),
384 get_data(crc->i), get_type(crc->i), 386 get_data (crc->i), get_type (crc->i),
385 get_priority(crc->i), get_anonymity(crc->i), 0, 387 get_priority (crc->i), get_anonymity (crc->i), 0,
386 get_expiration(crc->i), 1, 1, 388 get_expiration (crc->i), 1, 1,
387 &check_success, crc); 389 &check_success, crc);
388 crc->i++; 390 crc->i++;
389 if (crc->i == ITERATIONS) 391 if (crc->i == ITERATIONS)
390 crc->phase = RP_GET; 392 crc->phase = RP_GET;
391 break; 393 break;
392 394
393 case RP_GET: 395 case RP_GET:
394 crc->i--; 396 crc->i--;
395 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 397 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
396 "Executing GET number %u\n", 398 "Executing GET number %u\n",
397 crc->i); 399 crc->i);
398 GNUNET_CRYPTO_hash(&crc->i, 400 GNUNET_CRYPTO_hash (&crc->i,
399 sizeof(int), 401 sizeof(int),
400 &crc->key); 402 &crc->key);
401 GNUNET_DATASTORE_get_key(datastore, 403 GNUNET_DATASTORE_get_key (datastore,
402 0, 404 0,
403 false, 405 false,
404 &crc->key, 406 &crc->key,
405 get_type(crc->i), 407 get_type (crc->i),
406 1, 408 1,
407 1, 409 1,
408 &check_value, 410 &check_value,
409 crc); 411 crc);
410 break; 412 break;
411 413
412 case RP_DEL: 414 case RP_DEL:
413 crc->i--; 415 crc->i--;
414 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 416 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
415 "Executing DEL number %u\n", 417 "Executing DEL number %u\n",
416 crc->i); 418 crc->i);
417 crc->data = NULL; 419 crc->data = NULL;
418 GNUNET_CRYPTO_hash(&crc->i, sizeof(int), &crc->key); 420 GNUNET_CRYPTO_hash (&crc->i, sizeof(int), &crc->key);
419 GNUNET_assert(NULL != 421 GNUNET_assert (NULL !=
420 GNUNET_DATASTORE_get_key(datastore, 422 GNUNET_DATASTORE_get_key (datastore,
421 0, 423 0,
422 false, 424 false,
423 &crc->key, 425 &crc->key,
424 get_type(crc->i), 426 get_type (crc->i),
425 1, 427 1,
426 1, 428 1,
427 &delete_value, 429 &delete_value,
428 crc)); 430 crc));
429 break; 431 break;
430 432
431 case RP_DO_DEL: 433 case RP_DO_DEL:
432 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
433 "Executing DO_DEL number %u\n", 435 "Executing DO_DEL number %u\n",
434 crc->i); 436 crc->i);
435 if (crc->i == 0) 437 if (crc->i == 0)
436 { 438 {
437 crc->i = ITERATIONS; 439 crc->i = ITERATIONS;
438 crc->phase = RP_DELVALIDATE; 440 crc->phase = RP_DELVALIDATE;
439 } 441 }
440 else 442 else
441 { 443 {
442 crc->phase = RP_DEL; 444 crc->phase = RP_DEL;
443 } 445 }
444 GNUNET_assert(NULL != 446 GNUNET_assert (NULL !=
445 GNUNET_DATASTORE_remove(datastore, &crc->key, crc->size, 447 GNUNET_DATASTORE_remove (datastore, &crc->key, crc->size,
446 crc->data, 1, 1, 448 crc->data, 1, 1,
447 &check_success, crc)); 449 &check_success, crc));
448 break; 450 break;
449 451
450 case RP_DELVALIDATE: 452 case RP_DELVALIDATE:
451 crc->i--; 453 crc->i--;
452 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
453 "Executing DELVALIDATE number %u\n", 455 "Executing DELVALIDATE number %u\n",
454 crc->i); 456 crc->i);
455 GNUNET_CRYPTO_hash(&crc->i, sizeof(int), &crc->key); 457 GNUNET_CRYPTO_hash (&crc->i, sizeof(int), &crc->key);
456 GNUNET_assert(NULL != 458 GNUNET_assert (NULL !=
457 GNUNET_DATASTORE_get_key(datastore, 459 GNUNET_DATASTORE_get_key (datastore,
458 0, 460 0,
459 false, 461 false,
460 &crc->key, 462 &crc->key,
461 get_type(crc->i), 463 get_type (crc->i),
462 1, 464 1,
463 1, 465 1,
464 &check_nothing, 466 &check_nothing,
465 crc)); 467 crc));
466 break; 468 break;
467 469
468 case RP_RESERVE: 470 case RP_RESERVE:
469 crc->phase = RP_PUT_MULTIPLE; 471 crc->phase = RP_PUT_MULTIPLE;
470 GNUNET_DATASTORE_reserve(datastore, 128 * 1024, 2, 472 GNUNET_DATASTORE_reserve (datastore, 128 * 1024, 2,
471 &get_reserved, crc); 473 &get_reserved, crc);
472 break; 474 break;
473 475
474 case RP_PUT_MULTIPLE: 476 case RP_PUT_MULTIPLE:
475 crc->phase = RP_PUT_MULTIPLE_NEXT; 477 crc->phase = RP_PUT_MULTIPLE_NEXT;
476 GNUNET_DATASTORE_put(datastore, crc->rid, &crc->key, get_size(42), 478 GNUNET_DATASTORE_put (datastore, crc->rid, &crc->key, get_size (42),
477 get_data(42), get_type(42), get_priority(42), 479 get_data (42), get_type (42), get_priority (42),
478 get_anonymity(42), 0, get_expiration(42), 1, 1, 480 get_anonymity (42), 0, get_expiration (42), 1, 1,
479 &check_success, crc); 481 &check_success, crc);
480 break; 482 break;
481 483
482 case RP_PUT_MULTIPLE_NEXT: 484 case RP_PUT_MULTIPLE_NEXT:
483 crc->phase = RP_GET_MULTIPLE; 485 crc->phase = RP_GET_MULTIPLE;
484 GNUNET_DATASTORE_put(datastore, crc->rid, 486 GNUNET_DATASTORE_put (datastore, crc->rid,
485 &crc->key, 487 &crc->key,
486 get_size(43), 488 get_size (43),
487 get_data(43), 489 get_data (43),
488 get_type(42), 490 get_type (42),
489 get_priority(43), 491 get_priority (43),
490 get_anonymity(43), 492 get_anonymity (43),
491 0, 493 0,
492 get_expiration(43), 494 get_expiration (43),
493 1, 1, 495 1, 1,
494 &check_success, crc); 496 &check_success, crc);
495 break; 497 break;
496 498
497 case RP_GET_MULTIPLE: 499 case RP_GET_MULTIPLE:
498 GNUNET_assert(NULL != 500 GNUNET_assert (NULL !=
499 GNUNET_DATASTORE_get_key(datastore, 501 GNUNET_DATASTORE_get_key (datastore,
500 0, 502 0,
501 false, 503 false,
502 &crc->key, 504 &crc->key,
503 get_type(42), 505 get_type (42),
504 1, 506 1,
505 1, 507 1,
506 &check_multiple, 508 &check_multiple,
507 crc)); 509 crc));
508 break; 510 break;
509 511
510 case RP_GET_MULTIPLE_NEXT: 512 case RP_GET_MULTIPLE_NEXT:
511 GNUNET_assert(NULL != 513 GNUNET_assert (NULL !=
512 GNUNET_DATASTORE_get_key(datastore, 514 GNUNET_DATASTORE_get_key (datastore,
513 crc->first_uid + 1, 515 crc->first_uid + 1,
514 false, 516 false,
515 &crc->key, 517 &crc->key,
516 get_type(42), 518 get_type (42),
517 1, 519 1,
518 1, 520 1,
519 &check_multiple, 521 &check_multiple,
520 crc)); 522 crc));
521 break; 523 break;
522 524
523 case RP_DONE: 525 case RP_DONE:
524 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 526 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
525 "Finished, disconnecting\n"); 527 "Finished, disconnecting\n");
526 GNUNET_DATASTORE_disconnect(datastore, 528 GNUNET_DATASTORE_disconnect (datastore,
527 GNUNET_YES); 529 GNUNET_YES);
528 GNUNET_free(crc); 530 GNUNET_free (crc);
529 ok = 0; 531 ok = 0;
530 break; 532 break;
531 533
532 case RP_ERROR: 534 case RP_ERROR:
533 GNUNET_DATASTORE_disconnect(datastore, 535 GNUNET_DATASTORE_disconnect (datastore,
534 GNUNET_YES); 536 GNUNET_YES);
535 GNUNET_free(crc); 537 GNUNET_free (crc);
536 ok = 43; 538 ok = 43;
537 break; 539 break;
538 } 540 }
539} 541}
540 542
541 543
@@ -552,40 +554,40 @@ run_continuation(void *cls)
552 * @param msg NULL on success, otherwise an error message 554 * @param msg NULL on success, otherwise an error message
553 */ 555 */
554static void 556static void
555run_tests(void *cls, 557run_tests (void *cls,
556 int32_t success, 558 int32_t success,
557 struct GNUNET_TIME_Absolute min_expiration, 559 struct GNUNET_TIME_Absolute min_expiration,
558 const char *msg) 560 const char *msg)
559{ 561{
560 struct CpsRunContext *crc = cls; 562 struct CpsRunContext *crc = cls;
561 563
562 switch (success) 564 switch (success)
563 { 565 {
564 case GNUNET_YES: 566 case GNUNET_YES:
565 GNUNET_SCHEDULER_add_now(&run_continuation, 567 GNUNET_SCHEDULER_add_now (&run_continuation,
566 crc); 568 crc);
567 return; 569 return;
568 570
569 case GNUNET_NO: 571 case GNUNET_NO:
570 fprintf(stderr, 572 fprintf (stderr,
571 "%s", "Test 'put' operation failed, key already exists (!?)\n"); 573 "%s", "Test 'put' operation failed, key already exists (!?)\n");
572 GNUNET_DATASTORE_disconnect(datastore, 574 GNUNET_DATASTORE_disconnect (datastore,
573 GNUNET_YES); 575 GNUNET_YES);
574 GNUNET_free(crc); 576 GNUNET_free (crc);
575 return; 577 return;
576 578
577 case GNUNET_SYSERR: 579 case GNUNET_SYSERR:
578 fprintf(stderr, 580 fprintf (stderr,
579 "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", 581 "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n",
580 msg); 582 msg);
581 GNUNET_DATASTORE_disconnect(datastore, 583 GNUNET_DATASTORE_disconnect (datastore,
582 GNUNET_YES); 584 GNUNET_YES);
583 GNUNET_free(crc); 585 GNUNET_free (crc);
584 return; 586 return;
585 587
586 default: 588 default:
587 GNUNET_assert(0); 589 GNUNET_assert (0);
588 } 590 }
589} 591}
590 592
591 593
@@ -599,36 +601,36 @@ run_tests(void *cls,
599 * @param peer peer handle (unused) 601 * @param peer peer handle (unused)
600 */ 602 */
601static void 603static void
602run(void *cls, 604run (void *cls,
603 const struct GNUNET_CONFIGURATION_Handle *cfg, 605 const struct GNUNET_CONFIGURATION_Handle *cfg,
604 struct GNUNET_TESTING_Peer *peer) 606 struct GNUNET_TESTING_Peer *peer)
605{ 607{
606 struct CpsRunContext *crc; 608 struct CpsRunContext *crc;
607 static struct GNUNET_HashCode zkey; 609 static struct GNUNET_HashCode zkey;
608 610
609 crc = GNUNET_new(struct CpsRunContext); 611 crc = GNUNET_new (struct CpsRunContext);
610 crc->phase = RP_PUT; 612 crc->phase = RP_PUT;
611 now = GNUNET_TIME_absolute_get(); 613 now = GNUNET_TIME_absolute_get ();
612 datastore = GNUNET_DATASTORE_connect(cfg); 614 datastore = GNUNET_DATASTORE_connect (cfg);
613 if (NULL == 615 if (NULL ==
614 GNUNET_DATASTORE_put(datastore, 616 GNUNET_DATASTORE_put (datastore,
615 0, 617 0,
616 &zkey, 618 &zkey,
617 4, 619 4,
618 "TEST", 620 "TEST",
619 GNUNET_BLOCK_TYPE_TEST, 621 GNUNET_BLOCK_TYPE_TEST,
620 0, 0, 0, 622 0, 0, 0,
621 GNUNET_TIME_relative_to_absolute 623 GNUNET_TIME_relative_to_absolute
622 (GNUNET_TIME_UNIT_SECONDS), 624 (GNUNET_TIME_UNIT_SECONDS),
623 0, 1, 625 0, 1,
624 &run_tests, crc)) 626 &run_tests, crc))
625 { 627 {
626 fprintf(stderr, 628 fprintf (stderr,
627 "%s", 629 "%s",
628 "Test 'put' operation failed.\n"); 630 "Test 'put' operation failed.\n");
629 ok = 1; 631 ok = 1;
630 GNUNET_free(crc); 632 GNUNET_free (crc);
631 } 633 }
632} 634}
633 635
634 636
@@ -641,8 +643,8 @@ run(void *cls,
641 * 0 for "reset to empty" 643 * 0 for "reset to empty"
642 */ 644 */
643static void 645static void
644duc_dummy(void *cls, 646duc_dummy (void *cls,
645 int delta) 647 int delta)
646{ 648{
647 /* intentionally empty */ 649 /* intentionally empty */
648} 650}
@@ -652,42 +654,42 @@ duc_dummy(void *cls,
652 * check if plugin is actually working 654 * check if plugin is actually working
653 */ 655 */
654static int 656static int
655test_plugin(const char *cfg_name) 657test_plugin (const char *cfg_name)
656{ 658{
657 char libname[128]; 659 char libname[128];
658 struct GNUNET_CONFIGURATION_Handle *cfg; 660 struct GNUNET_CONFIGURATION_Handle *cfg;
659 struct GNUNET_DATASTORE_PluginFunctions *api; 661 struct GNUNET_DATASTORE_PluginFunctions *api;
660 struct GNUNET_DATASTORE_PluginEnvironment env; 662 struct GNUNET_DATASTORE_PluginEnvironment env;
661 663
662 cfg = GNUNET_CONFIGURATION_create(); 664 cfg = GNUNET_CONFIGURATION_create ();
663 if (GNUNET_OK != 665 if (GNUNET_OK !=
664 GNUNET_CONFIGURATION_load(cfg, 666 GNUNET_CONFIGURATION_load (cfg,
665 cfg_name)) 667 cfg_name))
666 { 668 {
667 GNUNET_CONFIGURATION_destroy(cfg); 669 GNUNET_CONFIGURATION_destroy (cfg);
668 fprintf(stderr, 670 fprintf (stderr,
669 "Failed to load configuration %s\n", 671 "Failed to load configuration %s\n",
670 cfg_name); 672 cfg_name);
671 return 1; 673 return 1;
672 } 674 }
673 memset(&env, 0, sizeof(env)); 675 memset (&env, 0, sizeof(env));
674 env.cfg = cfg; 676 env.cfg = cfg;
675 env.duc = &duc_dummy; 677 env.duc = &duc_dummy;
676 GNUNET_snprintf(libname, 678 GNUNET_snprintf (libname,
677 sizeof(libname), 679 sizeof(libname),
678 "libgnunet_plugin_datastore_%s", 680 "libgnunet_plugin_datastore_%s",
679 plugin_name); 681 plugin_name);
680 api = GNUNET_PLUGIN_load(libname, &env); 682 api = GNUNET_PLUGIN_load (libname, &env);
681 if (NULL == api) 683 if (NULL == api)
682 { 684 {
683 GNUNET_CONFIGURATION_destroy(cfg); 685 GNUNET_CONFIGURATION_destroy (cfg);
684 fprintf(stderr, 686 fprintf (stderr,
685 "Failed to load plugin `%s'\n", 687 "Failed to load plugin `%s'\n",
686 libname); 688 libname);
687 return 77; 689 return 77;
688 } 690 }
689 GNUNET_PLUGIN_unload(libname, api); 691 GNUNET_PLUGIN_unload (libname, api);
690 GNUNET_CONFIGURATION_destroy(cfg); 692 GNUNET_CONFIGURATION_destroy (cfg);
691 return 0; 693 return 0;
692} 694}
693 695
@@ -702,26 +704,26 @@ test_plugin(const char *cfg_name)
702 * @return 0 on success 704 * @return 0 on success
703 */ 705 */
704int 706int
705main(int argc, 707main (int argc,
706 char *argv[]) 708 char *argv[])
707{ 709{
708 char cfg_name[PATH_MAX]; 710 char cfg_name[PATH_MAX];
709 int ret; 711 int ret;
710 712
711 plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); 713 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
712 GNUNET_snprintf(cfg_name, 714 GNUNET_snprintf (cfg_name,
713 sizeof(cfg_name), 715 sizeof(cfg_name),
714 "test_datastore_api_data_%s.conf", 716 "test_datastore_api_data_%s.conf",
715 plugin_name); 717 plugin_name);
716 ret = test_plugin(cfg_name); 718 ret = test_plugin (cfg_name);
717 if (0 != ret) 719 if (0 != ret)
718 return ret; 720 return ret;
719 /* run actual test */ 721 /* run actual test */
720 if (0 != 722 if (0 !=
721 GNUNET_TESTING_peer_run("test-gnunet-datastore", 723 GNUNET_TESTING_peer_run ("test-gnunet-datastore",
722 cfg_name, 724 cfg_name,
723 &run, 725 &run,
724 NULL)) 726 NULL))
725 return 1; 727 return 1;
726 return ok; 728 return ok;
727} 729}
diff --git a/src/datastore/test_datastore_api_management.c b/src/datastore/test_datastore_api_management.c
index e7599999f..e6bacaf6e 100644
--- a/src/datastore/test_datastore_api_management.c
+++ b/src/datastore/test_datastore_api_management.c
@@ -33,7 +33,7 @@
33/** 33/**
34 * How long until we give up on transmitting the message? 34 * How long until we give up on transmitting the message?
35 */ 35 */
36#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) 36#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
37 37
38/** 38/**
39 * Number of iterations to run; must be large enough 39 * Number of iterations to run; must be large enough
@@ -41,7 +41,8 @@
41 */ 41 */
42#define ITERATIONS 5000 42#define ITERATIONS 5000
43 43
44enum RunPhase { 44enum RunPhase
45{
45 RP_PUT, 46 RP_PUT,
46 RP_GET, 47 RP_GET,
47 RP_DONE, 48 RP_DONE,
@@ -49,7 +50,8 @@ enum RunPhase {
49}; 50};
50 51
51 52
52struct CpsRunContext { 53struct CpsRunContext
54{
53 struct GNUNET_HashCode key; 55 struct GNUNET_HashCode key;
54 int i; 56 int i;
55 int found; 57 int found;
@@ -69,45 +71,45 @@ static const char *plugin_name;
69 71
70 72
71static size_t 73static size_t
72get_size(int i) 74get_size (int i)
73{ 75{
74 return 8 + 8 * (i % 256); 76 return 8 + 8 * (i % 256);
75} 77}
76 78
77 79
78static const void * 80static const void *
79get_data(int i) 81get_data (int i)
80{ 82{
81 static char buf[60000]; 83 static char buf[60000];
82 84
83 memset(buf, i, 8 + 8 * (i % 256)); 85 memset (buf, i, 8 + 8 * (i % 256));
84 return buf; 86 return buf;
85} 87}
86 88
87 89
88static int 90static int
89get_type(int i) 91get_type (int i)
90{ 92{
91 return 1; 93 return 1;
92} 94}
93 95
94 96
95static int 97static int
96get_priority(int i) 98get_priority (int i)
97{ 99{
98 return i + 1; 100 return i + 1;
99} 101}
100 102
101 103
102static int 104static int
103get_anonymity(int i) 105get_anonymity (int i)
104{ 106{
105 return i; 107 return i;
106} 108}
107 109
108 110
109static struct GNUNET_TIME_Absolute 111static struct GNUNET_TIME_Absolute
110get_expiration(int i) 112get_expiration (int i)
111{ 113{
112 struct GNUNET_TIME_Absolute av; 114 struct GNUNET_TIME_Absolute av;
113 115
@@ -117,204 +119,207 @@ get_expiration(int i)
117 119
118 120
119static void 121static void
120run_continuation(void *cls); 122run_continuation (void *cls);
121 123
122 124
123static void 125static void
124check_success(void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg) 126check_success (void *cls, int success, struct GNUNET_TIME_Absolute
127 min_expiration, const char *msg)
125{ 128{
126 struct CpsRunContext *crc = cls; 129 struct CpsRunContext *crc = cls;
127 130
128 if (GNUNET_OK != success) 131 if (GNUNET_OK != success)
129 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", msg); 132 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", msg);
130 GNUNET_assert(GNUNET_OK == success); 133 GNUNET_assert (GNUNET_OK == success);
131 GNUNET_free_non_null(crc->data); 134 GNUNET_free_non_null (crc->data);
132 crc->data = NULL; 135 crc->data = NULL;
133 GNUNET_SCHEDULER_add_now(&run_continuation, crc); 136 GNUNET_SCHEDULER_add_now (&run_continuation, crc);
134} 137}
135 138
136 139
137static void 140static void
138check_value(void *cls, 141check_value (void *cls,
139 const struct GNUNET_HashCode *key, 142 const struct GNUNET_HashCode *key,
140 size_t size, 143 size_t size,
141 const void *data, 144 const void *data,
142 enum GNUNET_BLOCK_Type type, 145 enum GNUNET_BLOCK_Type type,
143 uint32_t priority, 146 uint32_t priority,
144 uint32_t anonymity, 147 uint32_t anonymity,
145 uint32_t replication, 148 uint32_t replication,
146 struct GNUNET_TIME_Absolute expiration, 149 struct GNUNET_TIME_Absolute expiration,
147 uint64_t uid) 150 uint64_t uid)
148{ 151{
149 struct CpsRunContext *crc = cls; 152 struct CpsRunContext *crc = cls;
150 int i; 153 int i;
151 154
152 if (NULL == key) 155 if (NULL == key)
153 { 156 {
154 crc->phase = RP_GET_FAIL; 157 crc->phase = RP_GET_FAIL;
155 GNUNET_SCHEDULER_add_now(&run_continuation, crc); 158 GNUNET_SCHEDULER_add_now (&run_continuation, crc);
156 return; 159 return;
157 } 160 }
158 i = crc->i; 161 i = crc->i;
159 GNUNET_assert(size == get_size(i)); 162 GNUNET_assert (size == get_size (i));
160 GNUNET_assert(0 == memcmp(data, get_data(i), size)); 163 GNUNET_assert (0 == memcmp (data, get_data (i), size));
161 GNUNET_assert(type == get_type(i)); 164 GNUNET_assert (type == get_type (i));
162 GNUNET_assert(priority == get_priority(i)); 165 GNUNET_assert (priority == get_priority (i));
163 GNUNET_assert(anonymity == get_anonymity(i)); 166 GNUNET_assert (anonymity == get_anonymity (i));
164 GNUNET_assert(expiration.abs_value_us == get_expiration(i).abs_value_us); 167 GNUNET_assert (expiration.abs_value_us == get_expiration (i).abs_value_us);
165 crc->i--; 168 crc->i--;
166 if (crc->i == 0) 169 if (crc->i == 0)
167 crc->phase = RP_DONE; 170 crc->phase = RP_DONE;
168 GNUNET_SCHEDULER_add_now(&run_continuation, crc); 171 GNUNET_SCHEDULER_add_now (&run_continuation, crc);
169} 172}
170 173
171 174
172static void 175static void
173check_nothing(void *cls, 176check_nothing (void *cls,
174 const struct GNUNET_HashCode *key, 177 const struct GNUNET_HashCode *key,
175 size_t size, 178 size_t size,
176 const void *data, 179 const void *data,
177 enum GNUNET_BLOCK_Type type, 180 enum GNUNET_BLOCK_Type type,
178 uint32_t priority, 181 uint32_t priority,
179 uint32_t anonymity, 182 uint32_t anonymity,
180 uint32_t replication, 183 uint32_t replication,
181 struct GNUNET_TIME_Absolute expiration, 184 struct GNUNET_TIME_Absolute expiration,
182 uint64_t uid) 185 uint64_t uid)
183{ 186{
184 struct CpsRunContext *crc = cls; 187 struct CpsRunContext *crc = cls;
185 188
186 GNUNET_assert(key == NULL); 189 GNUNET_assert (key == NULL);
187 if (0 == --crc->i) 190 if (0 == --crc->i)
188 crc->phase = RP_DONE; 191 crc->phase = RP_DONE;
189 GNUNET_SCHEDULER_add_now(&run_continuation, crc); 192 GNUNET_SCHEDULER_add_now (&run_continuation, crc);
190} 193}
191 194
192 195
193static void 196static void
194run_continuation(void *cls) 197run_continuation (void *cls)
195{ 198{
196 struct CpsRunContext *crc = cls; 199 struct CpsRunContext *crc = cls;
197 200
198 ok = (int)crc->phase; 201 ok = (int) crc->phase;
199 switch (crc->phase) 202 switch (crc->phase)
203 {
204 case RP_PUT:
205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "PUT",
206 crc->i);
207 GNUNET_CRYPTO_hash (&crc->i, sizeof(int), &crc->key);
208 GNUNET_DATASTORE_put (datastore,
209 0,
210 &crc->key,
211 get_size (crc->i),
212 get_data (crc->i),
213 get_type (crc->i),
214 get_priority (crc->i),
215 get_anonymity (crc->i),
216 0,
217 get_expiration (crc->i),
218 1,
219 1,
220 &check_success, crc);
221 crc->i++;
222 if (crc->i == ITERATIONS)
200 { 223 {
201 case RP_PUT: 224 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
202 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "PUT", 225 "Sleeping to give datastore time to clean up\n");
203 crc->i); 226 sleep (1);
204 GNUNET_CRYPTO_hash(&crc->i, sizeof(int), &crc->key); 227 crc->phase = RP_GET;
205 GNUNET_DATASTORE_put(datastore, 228 crc->i--;
206 0,
207 &crc->key,
208 get_size(crc->i),
209 get_data(crc->i),
210 get_type(crc->i),
211 get_priority(crc->i),
212 get_anonymity(crc->i),
213 0,
214 get_expiration(crc->i),
215 1,
216 1,
217 &check_success, crc);
218 crc->i++;
219 if (crc->i == ITERATIONS)
220 {
221 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
222 "Sleeping to give datastore time to clean up\n");
223 sleep(1);
224 crc->phase = RP_GET;
225 crc->i--;
226 }
227 break;
228
229 case RP_GET:
230 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET",
231 crc->i);
232 GNUNET_CRYPTO_hash(&crc->i, sizeof(int), &crc->key);
233 GNUNET_DATASTORE_get_key(datastore,
234 0,
235 false,
236 &crc->key,
237 get_type(crc->i),
238 1,
239 1,
240 &check_value,
241 crc);
242 break;
243
244 case RP_GET_FAIL:
245 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET(f)",
246 crc->i);
247 GNUNET_CRYPTO_hash(&crc->i, sizeof(int), &crc->key);
248 GNUNET_DATASTORE_get_key(datastore,
249 0,
250 false,
251 &crc->key,
252 get_type(crc->i),
253 1,
254 1,
255 &check_nothing,
256 crc);
257 break;
258
259 case RP_DONE:
260 GNUNET_assert(0 == crc->i);
261 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Finished, disconnecting\n");
262 GNUNET_DATASTORE_disconnect(datastore, GNUNET_YES);
263 GNUNET_free(crc);
264 ok = 0;
265 } 229 }
230 break;
231
232 case RP_GET:
233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET",
234 crc->i);
235 GNUNET_CRYPTO_hash (&crc->i, sizeof(int), &crc->key);
236 GNUNET_DATASTORE_get_key (datastore,
237 0,
238 false,
239 &crc->key,
240 get_type (crc->i),
241 1,
242 1,
243 &check_value,
244 crc);
245 break;
246
247 case RP_GET_FAIL:
248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET(f)",
249 crc->i);
250 GNUNET_CRYPTO_hash (&crc->i, sizeof(int), &crc->key);
251 GNUNET_DATASTORE_get_key (datastore,
252 0,
253 false,
254 &crc->key,
255 get_type (crc->i),
256 1,
257 1,
258 &check_nothing,
259 crc);
260 break;
261
262 case RP_DONE:
263 GNUNET_assert (0 == crc->i);
264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished, disconnecting\n");
265 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
266 GNUNET_free (crc);
267 ok = 0;
268 }
266} 269}
267 270
268 271
269static void 272static void
270run_tests(void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg) 273run_tests (void *cls, int success, struct GNUNET_TIME_Absolute min_expiration,
274 const char *msg)
271{ 275{
272 struct CpsRunContext *crc = cls; 276 struct CpsRunContext *crc = cls;
273 277
274 if (success != GNUNET_YES) 278 if (success != GNUNET_YES)
275 { 279 {
276 fprintf(stderr, 280 fprintf (stderr,
277 "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n", 281 "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n",
278 msg); 282 msg);
279 GNUNET_DATASTORE_disconnect(datastore, GNUNET_YES); 283 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
280 GNUNET_free(crc); 284 GNUNET_free (crc);
281 return; 285 return;
282 } 286 }
283 GNUNET_SCHEDULER_add_now(&run_continuation, crc); 287 GNUNET_SCHEDULER_add_now (&run_continuation, crc);
284} 288}
285 289
286 290
287static void 291static void
288run(void *cls, 292run (void *cls,
289 const struct GNUNET_CONFIGURATION_Handle *cfg, 293 const struct GNUNET_CONFIGURATION_Handle *cfg,
290 struct GNUNET_TESTING_Peer *peer) 294 struct GNUNET_TESTING_Peer *peer)
291{ 295{
292 struct CpsRunContext *crc; 296 struct CpsRunContext *crc;
293 static struct GNUNET_HashCode zkey; 297 static struct GNUNET_HashCode zkey;
294 298
295 crc = GNUNET_new(struct CpsRunContext); 299 crc = GNUNET_new (struct CpsRunContext);
296 crc->cfg = cfg; 300 crc->cfg = cfg;
297 crc->phase = RP_PUT; 301 crc->phase = RP_PUT;
298 now = GNUNET_TIME_absolute_get(); 302 now = GNUNET_TIME_absolute_get ();
299 datastore = GNUNET_DATASTORE_connect(cfg); 303 datastore = GNUNET_DATASTORE_connect (cfg);
300 if (NULL == 304 if (NULL ==
301 GNUNET_DATASTORE_put(datastore, 305 GNUNET_DATASTORE_put (datastore,
302 0, 306 0,
303 &zkey, 307 &zkey,
304 4, 308 4,
305 "TEST", 309 "TEST",
306 GNUNET_BLOCK_TYPE_TEST, 310 GNUNET_BLOCK_TYPE_TEST,
307 0, 0, 0, 311 0, 0, 0,
308 GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_SECONDS), 312 GNUNET_TIME_relative_to_absolute (
309 0, 313 GNUNET_TIME_UNIT_SECONDS),
310 1, 314 0,
311 &run_tests, 315 1,
312 crc)) 316 &run_tests,
313 { 317 crc))
314 fprintf(stderr, "%s", "Test 'put' operation failed.\n"); 318 {
315 GNUNET_free(crc); 319 fprintf (stderr, "%s", "Test 'put' operation failed.\n");
316 ok = 1; 320 GNUNET_free (crc);
317 } 321 ok = 1;
322 }
318} 323}
319 324
320 325
@@ -325,8 +330,8 @@ run(void *cls,
325 * @param delta change in utilization 330 * @param delta change in utilization
326 */ 331 */
327static void 332static void
328ignore_payload_cb(void *cls, 333ignore_payload_cb (void *cls,
329 int delta) 334 int delta)
330{ 335{
331 /* do nothing */ 336 /* do nothing */
332} 337}
@@ -336,65 +341,65 @@ ignore_payload_cb(void *cls,
336 * check if plugin is actually working 341 * check if plugin is actually working
337 */ 342 */
338static int 343static int
339test_plugin(const char *cfg_name) 344test_plugin (const char *cfg_name)
340{ 345{
341 char libname[PATH_MAX]; 346 char libname[PATH_MAX];
342 struct GNUNET_CONFIGURATION_Handle *cfg; 347 struct GNUNET_CONFIGURATION_Handle *cfg;
343 struct GNUNET_DATASTORE_PluginFunctions *api; 348 struct GNUNET_DATASTORE_PluginFunctions *api;
344 struct GNUNET_DATASTORE_PluginEnvironment env; 349 struct GNUNET_DATASTORE_PluginEnvironment env;
345 350
346 cfg = GNUNET_CONFIGURATION_create(); 351 cfg = GNUNET_CONFIGURATION_create ();
347 if (GNUNET_OK != 352 if (GNUNET_OK !=
348 GNUNET_CONFIGURATION_load(cfg, 353 GNUNET_CONFIGURATION_load (cfg,
349 cfg_name)) 354 cfg_name))
350 { 355 {
351 GNUNET_CONFIGURATION_destroy(cfg); 356 GNUNET_CONFIGURATION_destroy (cfg);
352 fprintf(stderr, 357 fprintf (stderr,
353 "Failed to load configuration %s\n", 358 "Failed to load configuration %s\n",
354 cfg_name); 359 cfg_name);
355 return 1; 360 return 1;
356 } 361 }
357 memset(&env, 0, sizeof(env)); 362 memset (&env, 0, sizeof(env));
358 env.cfg = cfg; 363 env.cfg = cfg;
359 env.duc = &ignore_payload_cb; 364 env.duc = &ignore_payload_cb;
360 GNUNET_snprintf(libname, 365 GNUNET_snprintf (libname,
361 sizeof(libname), 366 sizeof(libname),
362 "libgnunet_plugin_datastore_%s", 367 "libgnunet_plugin_datastore_%s",
363 plugin_name); 368 plugin_name);
364 api = GNUNET_PLUGIN_load(libname, &env); 369 api = GNUNET_PLUGIN_load (libname, &env);
365 if (NULL == api) 370 if (NULL == api)
366 { 371 {
367 GNUNET_CONFIGURATION_destroy(cfg); 372 GNUNET_CONFIGURATION_destroy (cfg);
368 fprintf(stderr, 373 fprintf (stderr,
369 "Failed to load plugin `%s'\n", 374 "Failed to load plugin `%s'\n",
370 libname); 375 libname);
371 return 77; 376 return 77;
372 } 377 }
373 GNUNET_PLUGIN_unload(libname, api); 378 GNUNET_PLUGIN_unload (libname, api);
374 GNUNET_CONFIGURATION_destroy(cfg); 379 GNUNET_CONFIGURATION_destroy (cfg);
375 return 0; 380 return 0;
376} 381}
377 382
378 383
379int 384int
380main(int argc, char *argv[]) 385main (int argc, char *argv[])
381{ 386{
382 char cfg_name[PATH_MAX]; 387 char cfg_name[PATH_MAX];
383 int ret; 388 int ret;
384 389
385 plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); 390 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
386 GNUNET_snprintf(cfg_name, 391 GNUNET_snprintf (cfg_name,
387 sizeof(cfg_name), 392 sizeof(cfg_name),
388 "test_datastore_api_data_%s.conf", 393 "test_datastore_api_data_%s.conf",
389 plugin_name); 394 plugin_name);
390 ret = test_plugin(cfg_name); 395 ret = test_plugin (cfg_name);
391 if (0 != ret) 396 if (0 != ret)
392 return ret; 397 return ret;
393 if (0 != 398 if (0 !=
394 GNUNET_TESTING_peer_run("test-gnunet-datastore-management", 399 GNUNET_TESTING_peer_run ("test-gnunet-datastore-management",
395 cfg_name, 400 cfg_name,
396 &run, 401 &run,
397 NULL)) 402 NULL))
398 return 1; 403 return 1;
399 return ok; 404 return ok;
400} 405}
diff --git a/src/datastore/test_plugin_datastore.c b/src/datastore/test_plugin_datastore.c
index a260e1575..15fead3b7 100644
--- a/src/datastore/test_plugin_datastore.c
+++ b/src/datastore/test_plugin_datastore.c
@@ -44,7 +44,8 @@ static const char *plugin_name;
44 44
45static int ok; 45static int ok;
46 46
47enum RunPhase { 47enum RunPhase
48{
48 RP_ERROR = 0, 49 RP_ERROR = 0,
49 RP_PUT, 50 RP_PUT,
50 RP_GET, 51 RP_GET,
@@ -56,7 +57,8 @@ enum RunPhase {
56}; 57};
57 58
58 59
59struct CpsRunContext { 60struct CpsRunContext
61{
60 const struct GNUNET_CONFIGURATION_Handle *cfg; 62 const struct GNUNET_CONFIGURATION_Handle *cfg;
61 struct GNUNET_DATASTORE_PluginFunctions *api; 63 struct GNUNET_DATASTORE_PluginFunctions *api;
62 enum RunPhase phase; 64 enum RunPhase phase;
@@ -74,14 +76,14 @@ struct CpsRunContext {
74 * 0 for "reset to empty" 76 * 0 for "reset to empty"
75 */ 77 */
76static void 78static void
77disk_utilization_change_cb(void *cls, int delta) 79disk_utilization_change_cb (void *cls, int delta)
78{ 80{
79 /* do nothing */ 81 /* do nothing */
80} 82}
81 83
82 84
83static void 85static void
84test(void *cls); 86test (void *cls);
85 87
86 88
87/** 89/**
@@ -94,47 +96,47 @@ test(void *cls);
94 * @param msg error message on error 96 * @param msg error message on error
95 */ 97 */
96static void 98static void
97put_continuation(void *cls, 99put_continuation (void *cls,
98 const struct GNUNET_HashCode *key, 100 const struct GNUNET_HashCode *key,
99 uint32_t size, 101 uint32_t size,
100 int status, 102 int status,
101 const char *msg) 103 const char *msg)
102{ 104{
103 struct CpsRunContext *crc = cls; 105 struct CpsRunContext *crc = cls;
104 static unsigned long long os; 106 static unsigned long long os;
105 unsigned long long cs; 107 unsigned long long cs;
106 108
107 if (GNUNET_OK != status) 109 if (GNUNET_OK != status)
108 { 110 {
109 fprintf(stderr, 111 fprintf (stderr,
110 "ERROR: `%s'\n", 112 "ERROR: `%s'\n",
111 msg); 113 msg);
112 } 114 }
113 else 115 else
114 { 116 {
115 crc->api->estimate_size(crc->api->cls, 117 crc->api->estimate_size (crc->api->cls,
116 &cs); 118 &cs);
117 GNUNET_assert(os <= cs); 119 GNUNET_assert (os <= cs);
118 os = cs; 120 os = cs;
119 stored_bytes += size; 121 stored_bytes += size;
120 stored_ops++; 122 stored_ops++;
121 stored_entries++; 123 stored_entries++;
122 } 124 }
123 GNUNET_SCHEDULER_add_now(&test, crc); 125 GNUNET_SCHEDULER_add_now (&test, crc);
124} 126}
125 127
126 128
127static void 129static void
128gen_key(int i, struct GNUNET_HashCode * key) 130gen_key (int i, struct GNUNET_HashCode *key)
129{ 131{
130 memset(key, 0, sizeof(struct GNUNET_HashCode)); 132 memset (key, 0, sizeof(struct GNUNET_HashCode));
131 key->bits[0] = (unsigned int)i; 133 key->bits[0] = (unsigned int) i;
132 GNUNET_CRYPTO_hash(key, sizeof(struct GNUNET_HashCode), key); 134 GNUNET_CRYPTO_hash (key, sizeof(struct GNUNET_HashCode), key);
133} 135}
134 136
135 137
136static void 138static void
137do_put(struct CpsRunContext *crc) 139do_put (struct CpsRunContext *crc)
138{ 140{
139 char value[65536]; 141 char value[65536];
140 size_t size; 142 size_t size;
@@ -143,45 +145,46 @@ do_put(struct CpsRunContext *crc)
143 static int i; 145 static int i;
144 146
145 if (PUT_10 == i) 147 if (PUT_10 == i)
146 { 148 {
147 i = 0; 149 i = 0;
148 crc->phase++; 150 crc->phase++;
149 GNUNET_SCHEDULER_add_now(&test, crc); 151 GNUNET_SCHEDULER_add_now (&test, crc);
150 return; 152 return;
151 } 153 }
152 /* most content is 32k */ 154 /* most content is 32k */
153 size = 32 * 1024; 155 size = 32 * 1024;
154 156
155 if (0 != i && GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */ 157 if ((0 != i)&&(GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) ==
156 size = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024); 158 0) ) /* but some of it is less! */
159 size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024);
157 size = size - (size & 7); /* always multiple of 8 */ 160 size = size - (size & 7); /* always multiple of 8 */
158 161
159 /* generate random key */ 162 /* generate random key */
160 gen_key(i, &key); 163 gen_key (i, &key);
161 memset(value, i, size); 164 memset (value, i, size);
162 if (i > 255) 165 if (i > 255)
163 memset(value, i - 255, size / 2); 166 memset (value, i - 255, size / 2);
164 value[0] = crc->i; 167 value[0] = crc->i;
165 prio = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 100); 168 prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
166 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
167 "putting type %u, anon %u under key %s\n", i + 1, i, 170 "putting type %u, anon %u under key %s\n", i + 1, i,
168 GNUNET_h2s(&key)); 171 GNUNET_h2s (&key));
169 crc->api->put(crc->api->cls, 172 crc->api->put (crc->api->cls,
170 &key, 173 &key,
171 false /* absent */, 174 false /* absent */,
172 size, 175 size,
173 value, i + 1 /* type */, 176 value, i + 1 /* type */,
174 prio, 177 prio,
175 i /* anonymity */, 178 i /* anonymity */,
176 0 /* replication */, 179 0 /* replication */,
177 GNUNET_TIME_relative_to_absolute 180 GNUNET_TIME_relative_to_absolute
178 (GNUNET_TIME_relative_multiply 181 (GNUNET_TIME_relative_multiply
179 (GNUNET_TIME_UNIT_MILLISECONDS, 182 (GNUNET_TIME_UNIT_MILLISECONDS,
180 60 * 60 * 60 * 1000 + 183 60 * 60 * 60 * 1000
181 GNUNET_CRYPTO_random_u32 184 + GNUNET_CRYPTO_random_u32
182 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), 185 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))),
183 put_continuation, 186 put_continuation,
184 crc); 187 crc);
185 i++; 188 i++;
186} 189}
187 190
@@ -190,51 +193,51 @@ static uint64_t guid;
190 193
191 194
192static int 195static int
193iterate_one_shot(void *cls, 196iterate_one_shot (void *cls,
194 const struct GNUNET_HashCode *key, 197 const struct GNUNET_HashCode *key,
195 uint32_t size, 198 uint32_t size,
196 const void *data, 199 const void *data,
197 enum GNUNET_BLOCK_Type type, 200 enum GNUNET_BLOCK_Type type,
198 uint32_t priority, 201 uint32_t priority,
199 uint32_t anonymity, 202 uint32_t anonymity,
200 uint32_t replication, 203 uint32_t replication,
201 struct GNUNET_TIME_Absolute expiration, 204 struct GNUNET_TIME_Absolute expiration,
202 uint64_t uid) 205 uint64_t uid)
203{ 206{
204 struct CpsRunContext *crc = cls; 207 struct CpsRunContext *crc = cls;
205 208
206 GNUNET_assert(NULL != key); 209 GNUNET_assert (NULL != key);
207 guid = uid; 210 guid = uid;
208 crc->phase++; 211 crc->phase++;
209 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
210 "Found result type=%u, priority=%u, size=%u, expire=%s, key %s\n", 213 "Found result type=%u, priority=%u, size=%u, expire=%s, key %s\n",
211 (unsigned int)type, 214 (unsigned int) type,
212 (unsigned int)priority, 215 (unsigned int) priority,
213 (unsigned int)size, 216 (unsigned int) size,
214 GNUNET_STRINGS_absolute_time_to_string(expiration), 217 GNUNET_STRINGS_absolute_time_to_string (expiration),
215 GNUNET_h2s(key)); 218 GNUNET_h2s (key));
216 GNUNET_SCHEDULER_add_now(&test, 219 GNUNET_SCHEDULER_add_now (&test,
217 crc); 220 crc);
218 return GNUNET_OK; 221 return GNUNET_OK;
219} 222}
220 223
221 224
222static void 225static void
223remove_continuation(void *cls, 226remove_continuation (void *cls,
224 const struct GNUNET_HashCode *key, 227 const struct GNUNET_HashCode *key,
225 uint32_t size, 228 uint32_t size,
226 int status, 229 int status,
227 const char *msg) 230 const char *msg)
228{ 231{
229 struct CpsRunContext *crc = cls; 232 struct CpsRunContext *crc = cls;
230 233
231 GNUNET_assert(NULL != key); 234 GNUNET_assert (NULL != key);
232 GNUNET_assert(32768 == size); 235 GNUNET_assert (32768 == size);
233 GNUNET_assert(GNUNET_OK == status); 236 GNUNET_assert (GNUNET_OK == status);
234 GNUNET_assert(NULL == msg); 237 GNUNET_assert (NULL == msg);
235 crc->phase++; 238 crc->phase++;
236 GNUNET_SCHEDULER_add_now(&test, 239 GNUNET_SCHEDULER_add_now (&test,
237 crc); 240 crc);
238} 241}
239 242
240 243
@@ -246,28 +249,28 @@ remove_continuation(void *cls,
246 * @param cfg configuration to use 249 * @param cfg configuration to use
247 */ 250 */
248static void 251static void
249unload_plugin(struct GNUNET_DATASTORE_PluginFunctions *api, 252unload_plugin (struct GNUNET_DATASTORE_PluginFunctions *api,
250 const struct GNUNET_CONFIGURATION_Handle *cfg) 253 const struct GNUNET_CONFIGURATION_Handle *cfg)
251{ 254{
252 char *name; 255 char *name;
253 char *libname; 256 char *libname;
254 257
255 if (GNUNET_OK != 258 if (GNUNET_OK !=
256 GNUNET_CONFIGURATION_get_value_string(cfg, 259 GNUNET_CONFIGURATION_get_value_string (cfg,
257 "DATASTORE", 260 "DATASTORE",
258 "DATABASE", 261 "DATABASE",
259 &name)) 262 &name))
260 { 263 {
261 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 264 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
262 _("No `%s' specified for `%s' in configuration!\n"), 265 _ ("No `%s' specified for `%s' in configuration!\n"),
263 "DATABASE", 266 "DATABASE",
264 "DATASTORE"); 267 "DATASTORE");
265 return; 268 return;
266 } 269 }
267 GNUNET_asprintf(&libname, "libgnunet_plugin_datastore_%s", name); 270 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
268 GNUNET_break(NULL == GNUNET_PLUGIN_unload(libname, api)); 271 GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api));
269 GNUNET_free(libname); 272 GNUNET_free (libname);
270 GNUNET_free(name); 273 GNUNET_free (name);
271} 274}
272 275
273 276
@@ -277,99 +280,99 @@ unload_plugin(struct GNUNET_DATASTORE_PluginFunctions *api,
277 * the transport and core. 280 * the transport and core.
278 */ 281 */
279static void 282static void
280cleaning_task(void *cls) 283cleaning_task (void *cls)
281{ 284{
282 struct CpsRunContext *crc = cls; 285 struct CpsRunContext *crc = cls;
283 286
284 unload_plugin(crc->api, crc->cfg); 287 unload_plugin (crc->api, crc->cfg);
285 GNUNET_free(crc); 288 GNUNET_free (crc);
286} 289}
287 290
288 291
289static void 292static void
290test(void *cls) 293test (void *cls)
291{ 294{
292 struct CpsRunContext *crc = cls; 295 struct CpsRunContext *crc = cls;
293 struct GNUNET_HashCode key; 296 struct GNUNET_HashCode key;
294 297
295 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
296 "In phase %d, iteration %u\n", crc->phase, crc->cnt); 299 "In phase %d, iteration %u\n", crc->phase, crc->cnt);
297 switch (crc->phase) 300 switch (crc->phase)
301 {
302 case RP_ERROR:
303 ok = 1;
304 GNUNET_break (0);
305 crc->api->drop (crc->api->cls);
306 GNUNET_SCHEDULER_add_now (&cleaning_task, crc);
307 break;
308
309 case RP_PUT:
310 do_put (crc);
311 break;
312
313 case RP_GET:
314 if (crc->cnt == 1)
298 { 315 {
299 case RP_ERROR: 316 crc->cnt = 0;
300 ok = 1; 317 crc->phase++;
301 GNUNET_break(0); 318 GNUNET_SCHEDULER_add_now (&test, crc);
302 crc->api->drop(crc->api->cls);
303 GNUNET_SCHEDULER_add_now(&cleaning_task, crc);
304 break;
305
306 case RP_PUT:
307 do_put(crc);
308 break;
309
310 case RP_GET:
311 if (crc->cnt == 1)
312 {
313 crc->cnt = 0;
314 crc->phase++;
315 GNUNET_SCHEDULER_add_now(&test, crc);
316 break;
317 }
318 gen_key(5, &key);
319 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
320 "Looking for %s\n",
321 GNUNET_h2s(&key));
322 crc->api->get_key(crc->api->cls,
323 0,
324 false,
325 &key,
326 GNUNET_BLOCK_TYPE_ANY,
327 &iterate_one_shot,
328 crc);
329 break; 319 break;
330 320 }
331 case RP_ITER_ZERO: 321 gen_key (5, &key);
332 if (crc->cnt == 1) 322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
333 { 323 "Looking for %s\n",
334 crc->cnt = 0; 324 GNUNET_h2s (&key));
335 crc->phase++; 325 crc->api->get_key (crc->api->cls,
336 GNUNET_SCHEDULER_add_now(&test, crc); 326 0,
337 break; 327 false,
338 } 328 &key,
339 crc->api->get_zero_anonymity(crc->api->cls, 0, 1, &iterate_one_shot, crc); 329 GNUNET_BLOCK_TYPE_ANY,
330 &iterate_one_shot,
331 crc);
332 break;
333
334 case RP_ITER_ZERO:
335 if (crc->cnt == 1)
336 {
337 crc->cnt = 0;
338 crc->phase++;
339 GNUNET_SCHEDULER_add_now (&test, crc);
340 break; 340 break;
341 }
342 crc->api->get_zero_anonymity (crc->api->cls, 0, 1, &iterate_one_shot, crc);
343 break;
341 344
342 case RP_REPL_GET: 345 case RP_REPL_GET:
343 crc->api->get_replication(crc->api->cls, &iterate_one_shot, crc); 346 crc->api->get_replication (crc->api->cls, &iterate_one_shot, crc);
344 break; 347 break;
345 348
346 case RP_EXPI_GET: 349 case RP_EXPI_GET:
347 crc->api->get_expiration(crc->api->cls, &iterate_one_shot, crc); 350 crc->api->get_expiration (crc->api->cls, &iterate_one_shot, crc);
348 break; 351 break;
349 352
350 case RP_REMOVE: 353 case RP_REMOVE:
351 { 354 {
352 struct GNUNET_HashCode key; 355 struct GNUNET_HashCode key;
353 uint32_t size = 32768; 356 uint32_t size = 32768;
354 char value[size]; 357 char value[size];
355 358
356 gen_key(0, &key); 359 gen_key (0, &key);
357 memset(value, 0, size); 360 memset (value, 0, size);
358 value[0] = crc->i; 361 value[0] = crc->i;
359 crc->api->remove_key(crc->api->cls, 362 crc->api->remove_key (crc->api->cls,
360 &key, 363 &key,
361 size, 364 size,
362 value, 365 value,
363 &remove_continuation, 366 &remove_continuation,
364 crc); 367 crc);
365 break; 368 break;
366 } 369 }
367 370
368 case RP_DROP: 371 case RP_DROP:
369 crc->api->drop(crc->api->cls); 372 crc->api->drop (crc->api->cls);
370 GNUNET_SCHEDULER_add_now(&cleaning_task, crc); 373 GNUNET_SCHEDULER_add_now (&cleaning_task, crc);
371 break; 374 break;
372 } 375 }
373} 376}
374 377
375 378
@@ -377,7 +380,7 @@ test(void *cls)
377 * Load the datastore plugin. 380 * Load the datastore plugin.
378 */ 381 */
379static struct GNUNET_DATASTORE_PluginFunctions * 382static struct GNUNET_DATASTORE_PluginFunctions *
380load_plugin(const struct GNUNET_CONFIGURATION_Handle *cfg) 383load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
381{ 384{
382 static struct GNUNET_DATASTORE_PluginEnvironment env; 385 static struct GNUNET_DATASTORE_PluginEnvironment env;
383 struct GNUNET_DATASTORE_PluginFunctions *ret; 386 struct GNUNET_DATASTORE_PluginFunctions *ret;
@@ -385,61 +388,62 @@ load_plugin(const struct GNUNET_CONFIGURATION_Handle *cfg)
385 char *libname; 388 char *libname;
386 389
387 if (GNUNET_OK != 390 if (GNUNET_OK !=
388 GNUNET_CONFIGURATION_get_value_string(cfg, 391 GNUNET_CONFIGURATION_get_value_string (cfg,
389 "DATASTORE", 392 "DATASTORE",
390 "DATABASE", 393 "DATABASE",
391 &name)) 394 &name))
392 { 395 {
393 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 396 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
394 _("No `%s' specified for `%s' in configuration!\n"), 397 _ ("No `%s' specified for `%s' in configuration!\n"),
395 "DATABASE", 398 "DATABASE",
396 "DATASTORE"); 399 "DATASTORE");
397 return NULL; 400 return NULL;
398 } 401 }
399 env.cfg = cfg; 402 env.cfg = cfg;
400 env.duc = &disk_utilization_change_cb; 403 env.duc = &disk_utilization_change_cb;
401 env.cls = NULL; 404 env.cls = NULL;
402 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Loading `%s' datastore plugin\n"), 405 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Loading `%s' datastore plugin\n"),
403 name); 406 name);
404 GNUNET_asprintf(&libname, "libgnunet_plugin_datastore_%s", name); 407 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
405 if (NULL == (ret = GNUNET_PLUGIN_load(libname, &env))) 408 if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env)))
406 { 409 {
407 fprintf(stderr, "Failed to load plugin `%s'!\n", name); 410 fprintf (stderr, "Failed to load plugin `%s'!\n", name);
408 GNUNET_free(libname); 411 GNUNET_free (libname);
409 GNUNET_free(name); 412 GNUNET_free (name);
410 ok = 77; /* mark test as skipped */ 413 ok = 77; /* mark test as skipped */
411 return NULL; 414 return NULL;
412 } 415 }
413 GNUNET_free(libname); 416 GNUNET_free (libname);
414 GNUNET_free(name); 417 GNUNET_free (name);
415 return ret; 418 return ret;
416} 419}
417 420
418 421
419static void 422static void
420run(void *cls, char *const *args, const char *cfgfile, 423run (void *cls, char *const *args, const char *cfgfile,
421 const struct GNUNET_CONFIGURATION_Handle *c) 424 const struct GNUNET_CONFIGURATION_Handle *c)
422{ 425{
423 struct GNUNET_DATASTORE_PluginFunctions *api; 426 struct GNUNET_DATASTORE_PluginFunctions *api;
424 struct CpsRunContext *crc; 427 struct CpsRunContext *crc;
425 428
426 api = load_plugin(c); 429 api = load_plugin (c);
427 if (api == NULL) 430 if (api == NULL)
428 { 431 {
429 fprintf(stderr, 432 fprintf (stderr,
430 "%s", "Could not initialize plugin, assuming database not configured. Test not run!\n"); 433 "%s",
431 return; 434 "Could not initialize plugin, assuming database not configured. Test not run!\n");
432 } 435 return;
433 crc = GNUNET_new(struct CpsRunContext); 436 }
437 crc = GNUNET_new (struct CpsRunContext);
434 crc->api = api; 438 crc->api = api;
435 crc->cfg = c; 439 crc->cfg = c;
436 crc->phase = RP_PUT; 440 crc->phase = RP_PUT;
437 GNUNET_SCHEDULER_add_now(&test, crc); 441 GNUNET_SCHEDULER_add_now (&test, crc);
438} 442}
439 443
440 444
441int 445int
442main(int argc, char *argv[]) 446main (int argc, char *argv[])
443{ 447{
444 char dir_name[PATH_MAX]; 448 char dir_name[PATH_MAX];
445 char cfg_name[PATH_MAX]; 449 char cfg_name[PATH_MAX];
@@ -454,20 +458,20 @@ main(int argc, char *argv[])
454 }; 458 };
455 459
456 /* determine name of plugin to use */ 460 /* determine name of plugin to use */
457 plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]); 461 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
458 GNUNET_snprintf(dir_name, sizeof(dir_name), 462 GNUNET_snprintf (dir_name, sizeof(dir_name),
459 "/tmp/test-gnunet-datastore-plugin-%s", plugin_name); 463 "/tmp/test-gnunet-datastore-plugin-%s", plugin_name);
460 GNUNET_DISK_directory_remove(dir_name); 464 GNUNET_DISK_directory_remove (dir_name);
461 GNUNET_log_setup("test-plugin-datastore", 465 GNUNET_log_setup ("test-plugin-datastore",
462 "WARNING", 466 "WARNING",
463 NULL); 467 NULL);
464 GNUNET_snprintf(cfg_name, sizeof(cfg_name), 468 GNUNET_snprintf (cfg_name, sizeof(cfg_name),
465 "test_plugin_datastore_data_%s.conf", plugin_name); 469 "test_plugin_datastore_data_%s.conf", plugin_name);
466 GNUNET_PROGRAM_run((sizeof(xargv) / sizeof(char *)) - 1, xargv, 470 GNUNET_PROGRAM_run ((sizeof(xargv) / sizeof(char *)) - 1, xargv,
467 "test-plugin-datastore", "nohelp", options, &run, NULL); 471 "test-plugin-datastore", "nohelp", options, &run, NULL);
468 if ((0 != ok) && (77 != ok)) 472 if ((0 != ok) && (77 != ok))
469 fprintf(stderr, "Missed some testcases: %u\n", ok); 473 fprintf (stderr, "Missed some testcases: %u\n", ok);
470 GNUNET_DISK_directory_remove(dir_name); 474 GNUNET_DISK_directory_remove (dir_name);
471 return ok; 475 return ok;
472} 476}
473 477