2 This file is part of GNUnet
3 Copyright (C) 2004-2014 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file datastore/gnunet-service-datastore.c
23 * @brief Management for the datastore for files stored on a GNUnet node
24 * @author Christian Grothoff
28 #include "gnunet_util_lib.h"
29 #include "gnunet_protocols.h"
30 #include "gnunet_statistics_service.h"
31 #include "gnunet_datastore_plugin.h"
32 #include "datastore.h"
35 * How many messages do we queue at most per client?
37 #define MAX_PENDING 1024
40 * Limit size of bloom filter to 2 GB.
42 #define MAX_BF_SIZE ((uint32_t) (1LL << 31))
45 * How long are we at most keeping "expired" content
46 * past the expiration date in the database?
48 #define MAX_EXPIRE_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
51 * How fast are we allowed to query the database for deleting
52 * expired content? (1 item per second).
54 #define MIN_EXPIRE_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
57 * Name under which we store current space consumption.
59 static char *quota_stat_name;
62 * Task to timeout stat GET.
64 static struct GNUNET_SCHEDULER_Task *stat_timeout_task;
67 * After how many payload-changing operations
68 * do we sync our statistics?
70 #define MAX_STAT_SYNC_LAG 50
74 * Our datastore plugin.
76 struct DatastorePlugin
80 * API of the transport as returned by the plugin's
81 * initialization function.
83 struct GNUNET_DATASTORE_PluginFunctions *api;
86 * Short name for the plugin (i.e. "sqlite").
91 * Name of the library (i.e. "gnunet_plugin_datastore_sqlite").
96 * Environment this transport service is using
99 struct GNUNET_DATASTORE_PluginEnvironment env;
105 * Linked list of active reservations.
107 struct ReservationList
111 * This is a linked list.
113 struct ReservationList *next;
116 * Client that made the reservation.
118 struct GNUNET_SERVER_Client *client;
121 * Number of bytes (still) reserved.
126 * Number of items (still) reserved.
131 * Reservation identifier.
140 * Our datastore plugin (NULL if not available).
142 static struct DatastorePlugin *plugin;
145 * Linked list of space reservations made by clients.
147 static struct ReservationList *reservations;
150 * Bloomfilter to quickly tell if we don't have the content.
152 static struct GNUNET_CONTAINER_BloomFilter *filter;
155 * Name of our plugin.
157 static char *plugin_name;
162 static const struct GNUNET_CONFIGURATION_Handle *cfg;
165 * Handle for reporting statistics.
167 static struct GNUNET_STATISTICS_Handle *stats;
170 * How much space are we using for the cache? (space available for
171 * insertions that will be instantly reclaimed by discarding less
172 * important content --- or possibly whatever we just inserted into
175 static unsigned long long cache_size;
178 * How much space have we currently reserved?
180 static unsigned long long reserved;
183 * How much data are we currently storing
186 static unsigned long long payload;
189 * Identity of the task that is used to delete
192 static struct GNUNET_SCHEDULER_Task *expired_kill_task;
195 * Minimum time that content should have to not be discarded instantly
196 * (time stamp of any content that we've been discarding recently to
197 * stay below the quota). FOREVER if we had to expire content with
200 static struct GNUNET_TIME_Absolute min_expiration;
203 * How much space are we allowed to use?
205 static unsigned long long quota;
208 * Should the database be dropped on exit?
213 * Should we refresh the BF when the DB is loaded?
215 static int refresh_bf;
218 * Number of updates that were made to the
219 * payload value since we last synchronized
220 * it with the statistics service.
222 static unsigned int last_sync;
225 * Did we get an answer from statistics?
227 static int stats_worked;
231 * Synchronize our utilization statistics with the
232 * statistics service.
237 GNUNET_STATISTICS_set (stats,
241 GNUNET_STATISTICS_set (stats,
242 "# utilization by current datastore",
250 * Context for transmitting replies to clients.
252 struct TransmitCallbackContext
256 * We keep these in a doubly-linked list (for cleanup).
258 struct TransmitCallbackContext *next;
261 * We keep these in a doubly-linked list (for cleanup).
263 struct TransmitCallbackContext *prev;
266 * The message that we're asked to transmit.
268 struct GNUNET_MessageHeader *msg;
271 * Handle for the transmission request.
273 struct GNUNET_SERVER_TransmitHandle *th;
276 * Client that we are transmitting to.
278 struct GNUNET_SERVER_Client *client;
284 * Head of the doubly-linked list (for cleanup).
286 static struct TransmitCallbackContext *tcc_head;
289 * Tail of the doubly-linked list (for cleanup).
291 static struct TransmitCallbackContext *tcc_tail;
294 * Have we already cleaned up the TCCs and are hence no longer
295 * willing (or able) to transmit anything to anyone?
297 static int cleaning_done;
300 * Handle for pending get request.
302 static struct GNUNET_STATISTICS_GetHandle *stat_get;
305 * Handle to our server.
307 static struct GNUNET_SERVER_Handle *server;
310 * Task that is used to remove expired entries from
311 * the datastore. This task will schedule itself
312 * again automatically to always delete all expired
315 * @param cls not used
318 delete_expired (void *cls);
322 * Iterate over the expired items stored in the datastore.
323 * Delete all expired items; once we have processed all
324 * expired items, re-schedule the "delete_expired" task.
326 * @param cls not used
327 * @param key key for the content
328 * @param size number of bytes in data
329 * @param data content stored
330 * @param type type of the content
331 * @param priority priority of the content
332 * @param anonymity anonymity-level for the content
333 * @param expiration expiration time for the content
334 * @param uid unique identifier for the datum;
335 * maybe 0 if no unique identifier is available
337 * @return #GNUNET_SYSERR to abort the iteration, #GNUNET_OK to continue
338 * (continue on call to "next", of course),
339 * #GNUNET_NO to delete the item and continue (if supported)
342 expired_processor (void *cls,
343 const struct GNUNET_HashCode *key,
346 enum GNUNET_BLOCK_Type type,
349 struct GNUNET_TIME_Absolute expiration,
352 struct GNUNET_TIME_Absolute now;
357 GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY,
358 GNUNET_SCHEDULER_PRIORITY_IDLE,
359 &delete_expired, NULL);
360 return GNUNET_SYSERR;
362 now = GNUNET_TIME_absolute_get ();
363 if (expiration.abs_value_us > now.abs_value_us)
365 /* finished processing */
367 GNUNET_SCHEDULER_add_delayed_with_priority (MAX_EXPIRE_DELAY,
368 GNUNET_SCHEDULER_PRIORITY_IDLE,
369 &delete_expired, NULL);
370 return GNUNET_SYSERR;
372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
373 "Deleting content `%s' of type %u that expired %s ago\n",
374 GNUNET_h2s (key), type,
375 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_difference (expiration,
378 min_expiration = now;
379 GNUNET_STATISTICS_update (stats,
380 gettext_noop ("# bytes expired"),
383 GNUNET_CONTAINER_bloomfilter_remove (filter, key);
385 GNUNET_SCHEDULER_add_delayed_with_priority (MIN_EXPIRE_DELAY,
386 GNUNET_SCHEDULER_PRIORITY_IDLE,
387 &delete_expired, NULL);
393 * Task that is used to remove expired entries from
394 * the datastore. This task will schedule itself
395 * again automatically to always delete all expired
398 * @param cls not used
401 delete_expired (void *cls)
403 expired_kill_task = NULL;
404 plugin->api->get_expiration (plugin->api->cls,
411 * An iterator over a set of items stored in the datastore
412 * that deletes until we're happy with respect to our quota.
415 * @param key key for the content
416 * @param size number of bytes in data
417 * @param data content stored
418 * @param type type of the content
419 * @param priority priority of the content
420 * @param anonymity anonymity-level for the content
421 * @param expiration expiration time for the content
422 * @param uid unique identifier for the datum;
423 * maybe 0 if no unique identifier is available
424 * @return #GNUNET_SYSERR to abort the iteration, #GNUNET_OK to continue
425 * (continue on call to "next", of course),
426 * #GNUNET_NO to delete the item and continue (if supported)
429 quota_processor (void *cls,
430 const struct GNUNET_HashCode *key,
433 enum GNUNET_BLOCK_Type type,
436 struct GNUNET_TIME_Absolute expiration,
439 unsigned long long *need = cls;
442 return GNUNET_SYSERR;
443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
444 "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",
445 (unsigned long long) (size + GNUNET_DATASTORE_ENTRY_OVERHEAD),
446 (unsigned int) priority,
447 GNUNET_h2s (key), type,
448 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (expiration),
451 if (size + GNUNET_DATASTORE_ENTRY_OVERHEAD > *need)
454 *need -= size + GNUNET_DATASTORE_ENTRY_OVERHEAD;
456 min_expiration = GNUNET_TIME_UNIT_FOREVER_ABS;
458 min_expiration = expiration;
459 GNUNET_STATISTICS_update (stats,
460 gettext_noop ("# bytes purged (low-priority)"),
462 GNUNET_CONTAINER_bloomfilter_remove (filter, key);
468 * Manage available disk space by running tasks
469 * that will discard content if necessary. This
470 * function will be run whenever a request for
471 * "need" bytes of storage could only be satisfied
472 * by eating into the "cache" (and we want our cache
475 * @param need number of bytes of content that were
476 * placed into the "cache" (and hence the
477 * number of bytes that should be removed).
480 manage_space (unsigned long long need)
482 unsigned long long last;
484 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
485 "Asked to free up %llu bytes of cache space\n",
488 while ((need > 0) && (last != need))
491 plugin->api->get_expiration (plugin->api->cls,
499 * Function called to notify a client about the socket
500 * begin ready to queue more data. "buf" will be
501 * NULL and "size" zero if the socket was closed for
502 * writing in the meantime.
505 * @param size number of bytes available in buf
506 * @param buf where the callee should write the message
507 * @return number of bytes written to buf
510 transmit_callback (void *cls, size_t size, void *buf)
512 struct TransmitCallbackContext *tcc = cls;
516 GNUNET_CONTAINER_DLL_remove (tcc_head, tcc_tail, tcc);
517 msize = ntohs (tcc->msg->size);
520 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
521 _("Transmission to client failed!\n"));
522 GNUNET_SERVER_receive_done (tcc->client, GNUNET_SYSERR);
523 GNUNET_SERVER_client_drop (tcc->client);
524 GNUNET_free (tcc->msg);
528 GNUNET_assert (size >= msize);
529 GNUNET_memcpy (buf, tcc->msg, msize);
530 GNUNET_SERVER_receive_done (tcc->client, GNUNET_OK);
531 GNUNET_SERVER_client_drop (tcc->client);
532 GNUNET_free (tcc->msg);
539 * Transmit the given message to the client.
541 * @param client target of the message
542 * @param msg message to transmit, will be freed!
545 transmit (struct GNUNET_SERVER_Client *client,
546 struct GNUNET_MessageHeader *msg)
548 struct TransmitCallbackContext *tcc;
550 if (GNUNET_YES == cleaning_done)
552 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
553 _("Shutdown in progress, aborting transmission.\n"));
554 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
558 tcc = GNUNET_new (struct TransmitCallbackContext);
560 tcc->client = client;
563 GNUNET_SERVER_notify_transmit_ready (client, ntohs (msg->size),
564 GNUNET_TIME_UNIT_FOREVER_REL,
565 &transmit_callback, tcc)))
568 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
573 GNUNET_SERVER_client_keep (client);
574 GNUNET_CONTAINER_DLL_insert (tcc_head, tcc_tail, tcc);
579 * Transmit a status code to the client.
581 * @param client receiver of the response
582 * @param code status code
583 * @param msg optional error message (can be NULL)
586 transmit_status (struct GNUNET_SERVER_Client *client, int code, const char *msg)
588 struct StatusMessage *sm;
591 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
592 "Transmitting `%s' message with value %d and message `%s'\n",
593 "STATUS", code, msg != NULL ? msg : "(none)");
594 slen = (msg == NULL) ? 0 : strlen (msg) + 1;
595 sm = GNUNET_malloc (sizeof (struct StatusMessage) + slen);
596 sm->header.size = htons (sizeof (struct StatusMessage) + slen);
597 sm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_STATUS);
598 sm->status = htonl (code);
599 sm->min_expiration = GNUNET_TIME_absolute_hton (min_expiration);
601 GNUNET_memcpy (&sm[1], msg, slen);
602 transmit (client, &sm->header);
607 * Function that will transmit the given datastore entry
610 * @param cls closure, pointer to the client (of type GNUNET_SERVER_Client).
611 * @param key key for the content
612 * @param size number of bytes in data
613 * @param data content stored
614 * @param type type of the content
615 * @param priority priority of the content
616 * @param anonymity anonymity-level for the content
617 * @param expiration expiration time for the content
618 * @param uid unique identifier for the datum;
619 * maybe 0 if no unique identifier is available
620 * @return #GNUNET_SYSERR to abort the iteration, #GNUNET_OK to continue,
621 * #GNUNET_NO to delete the item and continue (if supported)
624 transmit_item (void *cls,
625 const struct GNUNET_HashCode *key,
628 enum GNUNET_BLOCK_Type type,
631 struct GNUNET_TIME_Absolute expiration,
634 struct GNUNET_SERVER_Client *client = cls;
635 struct GNUNET_MessageHeader *end;
636 struct DataMessage *dm;
640 /* transmit 'DATA_END' */
641 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' message\n",
643 end = GNUNET_new (struct GNUNET_MessageHeader);
644 end->size = htons (sizeof (struct GNUNET_MessageHeader));
645 end->type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END);
646 transmit (client, end);
647 GNUNET_SERVER_client_drop (client);
650 GNUNET_assert (sizeof (struct DataMessage) + size <
651 GNUNET_SERVER_MAX_MESSAGE_SIZE);
652 dm = GNUNET_malloc (sizeof (struct DataMessage) + size);
653 dm->header.size = htons (sizeof (struct DataMessage) + size);
654 dm->header.type = htons (GNUNET_MESSAGE_TYPE_DATASTORE_DATA);
656 dm->size = htonl (size);
657 dm->type = htonl (type);
658 dm->priority = htonl (priority);
659 dm->anonymity = htonl (anonymity);
660 dm->replication = htonl (0);
661 dm->reserved = htonl (0);
662 dm->expiration = GNUNET_TIME_absolute_hton (expiration);
663 dm->uid = GNUNET_htonll (uid);
665 GNUNET_memcpy (&dm[1], data, size);
666 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
667 "Transmitting `%s' message for `%s' of type %u with expiration %s (in: %s)\n",
668 "DATA", GNUNET_h2s (key), type,
669 GNUNET_STRINGS_absolute_time_to_string (expiration),
670 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (expiration),
672 GNUNET_STATISTICS_update (stats,
673 gettext_noop ("# results found"),
676 transmit (client, &dm->header);
677 GNUNET_SERVER_client_drop (client);
683 * Handle RESERVE-message.
686 * @param client identification of the client
687 * @param message the actual message
690 handle_reserve (void *cls, struct GNUNET_SERVER_Client *client,
691 const struct GNUNET_MessageHeader *message)
694 * Static counter to produce reservation identifiers.
696 static int reservation_gen;
698 const struct ReserveMessage *msg = (const struct ReserveMessage *) message;
699 struct ReservationList *e;
700 unsigned long long used;
701 unsigned long long req;
705 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
706 "Processing RESERVE request\n");
707 amount = GNUNET_ntohll (msg->amount);
708 entries = ntohl (msg->entries);
709 used = payload + reserved;
711 amount + ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * entries;
712 if (used + req > quota)
715 used = quota; /* cheat a bit for error message (to avoid negative numbers) */
716 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
718 ("Insufficient space (%llu bytes are available) to satisfy `%s' request for %llu bytes\n"),
719 quota - used, "RESERVE", req);
720 if (cache_size < req)
722 /* TODO: document this in the FAQ; essentially, if this
723 * message happens, the insertion request could be blocked
724 * by less-important content from migration because it is
725 * larger than 1/8th of the overall available space, and
726 * we only reserve 1/8th for "fresh" insertions */
727 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
729 ("The requested amount (%llu bytes) is larger than the cache size (%llu bytes)\n"),
731 transmit_status (client, 0,
733 ("Insufficient space to satisfy request and "
734 "requested amount is larger than cache size"));
738 transmit_status (client, 0,
739 gettext_noop ("Insufficient space to satisfy request"));
744 GNUNET_STATISTICS_set (stats,
745 gettext_noop ("# reserved"),
748 e = GNUNET_new (struct ReservationList);
749 e->next = reservations;
753 e->entries = entries;
754 e->rid = ++reservation_gen;
755 if (reservation_gen < 0)
756 reservation_gen = 0; /* wrap around */
757 transmit_status (client, e->rid, NULL);
762 * Handle RELEASE_RESERVE-message.
765 * @param client identification of the client
766 * @param message the actual message
769 handle_release_reserve (void *cls,
770 struct GNUNET_SERVER_Client *client,
771 const struct GNUNET_MessageHeader *message)
773 const struct ReleaseReserveMessage *msg =
774 (const struct ReleaseReserveMessage *) message;
775 struct ReservationList *pos;
776 struct ReservationList *prev;
777 struct ReservationList *next;
778 int rid = ntohl (msg->rid);
779 unsigned long long rem;
781 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
782 "Processing RELEASE_RESERVE request\n");
785 while (NULL != (pos = next))
796 ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries;
797 GNUNET_assert (reserved >= rem);
799 GNUNET_STATISTICS_set (stats,
800 gettext_noop ("# reserved"),
803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
804 "Returning %llu remaining reserved bytes to storage pool\n",
807 transmit_status (client, GNUNET_OK, NULL);
813 transmit_status (client, GNUNET_SYSERR,
814 gettext_noop ("Could not find matching reservation"));
819 * Check that the given message is a valid data message.
821 * @return NULL if the message is not well-formed, otherwise the message
823 static const struct DataMessage *
824 check_data (const struct GNUNET_MessageHeader *message)
828 const struct DataMessage *dm;
830 size = ntohs (message->size);
831 if (size < sizeof (struct DataMessage))
836 dm = (const struct DataMessage *) message;
837 dsize = ntohl (dm->size);
838 if (size != dsize + sizeof (struct DataMessage))
848 * Context for a PUT request used to see if the content is
854 * Client to notify on completion.
856 struct GNUNET_SERVER_Client *client;
858 #if ! HAVE_UNALIGNED_64_ACCESS
862 /* followed by the 'struct DataMessage' */
870 * @param key key for the item stored
871 * @param size size of the item stored
872 * @param status #GNUNET_OK or #GNUNET_SYSERROR
873 * @param msg error message on error
876 put_continuation (void *cls,
877 const struct GNUNET_HashCode *key,
882 struct PutContext *pc = cls;
884 if (GNUNET_OK == status)
886 GNUNET_STATISTICS_update (stats,
887 gettext_noop ("# bytes stored"),
890 GNUNET_CONTAINER_bloomfilter_add (filter, key);
891 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
892 "Successfully stored %u bytes under key `%s'\n",
893 size, GNUNET_h2s (key));
895 transmit_status (pc->client, status, msg);
896 GNUNET_SERVER_client_drop (pc->client);
898 if (quota - reserved - cache_size < payload)
900 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
901 _("Need %llu bytes more space (%llu allowed, using %llu)\n"),
902 (unsigned long long) size + GNUNET_DATASTORE_ENTRY_OVERHEAD,
903 (unsigned long long) (quota - reserved - cache_size),
904 (unsigned long long) payload);
905 manage_space (size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
911 * Actually put the data message.
913 * @param pc put context
916 execute_put (struct PutContext *pc)
918 const struct DataMessage *dm;
920 dm = (const struct DataMessage *) &pc[1];
921 plugin->api->put (plugin->api->cls, &dm->key, ntohl (dm->size), &dm[1],
922 ntohl (dm->type), ntohl (dm->priority),
923 ntohl (dm->anonymity), ntohl (dm->replication),
924 GNUNET_TIME_absolute_ntoh (dm->expiration),
925 &put_continuation, pc);
932 * @param status #GNUNET_OK or #GNUNET_SYSERR
933 * @param msg error message on error
936 check_present_continuation (void *cls,
940 struct GNUNET_SERVER_Client *client = cls;
942 transmit_status (client, GNUNET_NO, NULL);
943 GNUNET_SERVER_client_drop (client);
948 * Function that will check if the given datastore entry
949 * matches the put and if none match executes the put.
951 * @param cls closure, pointer to the client (of type `struct PutContext`).
952 * @param key key for the content
953 * @param size number of bytes in data
954 * @param data content stored
955 * @param type type of the content
956 * @param priority priority of the content
957 * @param anonymity anonymity-level for the content
958 * @param expiration expiration time for the content
959 * @param uid unique identifier for the datum;
960 * maybe 0 if no unique identifier is available
961 * @return #GNUNET_OK usually
962 * #GNUNET_NO to delete the item
965 check_present (void *cls,
966 const struct GNUNET_HashCode *key,
969 enum GNUNET_BLOCK_Type type,
972 struct GNUNET_TIME_Absolute expiration,
975 struct PutContext *pc = cls;
976 const struct DataMessage *dm;
978 dm = (const struct DataMessage *) &pc[1];
984 if ( (GNUNET_BLOCK_TYPE_FS_DBLOCK == type) ||
985 (GNUNET_BLOCK_TYPE_FS_IBLOCK == type) ||
986 ( (size == ntohl (dm->size)) &&
987 (0 == memcmp (&dm[1], data, size)) ) )
989 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
990 "Result already present in datastore\n");
991 /* FIXME: change API to allow increasing 'replication' counter */
992 if ((ntohl (dm->priority) > 0) ||
993 (GNUNET_TIME_absolute_ntoh (dm->expiration).abs_value_us >
994 expiration.abs_value_us))
995 plugin->api->update (plugin->api->cls,
997 (int32_t) ntohl (dm->priority),
998 GNUNET_TIME_absolute_ntoh (dm->expiration),
999 &check_present_continuation,
1003 transmit_status (pc->client, GNUNET_NO, NULL);
1004 GNUNET_SERVER_client_drop (pc->client);
1017 * Handle PUT-message.
1019 * @param cls closure
1020 * @param client identification of the client
1021 * @param message the actual message
1024 handle_put (void *cls,
1025 struct GNUNET_SERVER_Client *client,
1026 const struct GNUNET_MessageHeader *message)
1028 const struct DataMessage *dm = check_data (message);
1030 struct ReservationList *pos;
1031 struct PutContext *pc;
1032 struct GNUNET_HashCode vhash;
1035 if ((dm == NULL) || (ntohl (dm->type) == 0))
1038 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1041 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1042 "Processing PUT request for `%s' of type %u\n",
1043 GNUNET_h2s (&dm->key),
1045 rid = ntohl (dm->rid);
1046 size = ntohl (dm->size);
1050 while ((NULL != pos) && (rid != pos->rid))
1052 GNUNET_break (pos != NULL);
1055 GNUNET_break (pos->entries > 0);
1056 GNUNET_break (pos->amount >= size);
1058 pos->amount -= size;
1059 reserved -= (size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
1060 GNUNET_STATISTICS_set (stats,
1061 gettext_noop ("# reserved"),
1066 pc = GNUNET_malloc (sizeof (struct PutContext) + size +
1067 sizeof (struct DataMessage));
1068 pc->client = client;
1069 GNUNET_SERVER_client_keep (client);
1070 GNUNET_memcpy (&pc[1], dm, size + sizeof (struct DataMessage));
1071 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (filter, &dm->key))
1073 GNUNET_CRYPTO_hash (&dm[1], size, &vhash);
1074 plugin->api->get_key (plugin->api->cls,
1088 * Handle #GNUNET_MESSAGE_TYPE_DATASTORE_GET-message.
1090 * @param cls closure
1091 * @param client identification of the client
1092 * @param message the actual message
1095 handle_get (void *cls,
1096 struct GNUNET_SERVER_Client *client,
1097 const struct GNUNET_MessageHeader *message)
1099 const struct GetMessage *msg;
1101 msg = (const struct GetMessage *) message;
1102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1103 "Processing GET request of type %u\n",
1105 GNUNET_STATISTICS_update (stats,
1106 gettext_noop ("# GET requests received"),
1109 GNUNET_SERVER_client_keep (client);
1110 plugin->api->get_key (plugin->api->cls,
1111 GNUNET_ntohll (msg->offset),
1120 * Handle #GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY-message.
1122 * @param cls closure
1123 * @param client identification of the client
1124 * @param message the actual message
1127 handle_get_key (void *cls,
1128 struct GNUNET_SERVER_Client *client,
1129 const struct GNUNET_MessageHeader *message)
1131 const struct GetKeyMessage *msg;
1133 msg = (const struct GetKeyMessage *) message;
1134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1135 "Processing GET request for `%s' of type %u\n",
1136 GNUNET_h2s (&msg->key),
1138 GNUNET_STATISTICS_update (stats,
1139 gettext_noop ("# GET KEY requests received"),
1142 GNUNET_SERVER_client_keep (client);
1144 GNUNET_CONTAINER_bloomfilter_test (filter,
1147 /* don't bother database... */
1148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1149 "Empty result set for GET request for `%s' (bloomfilter).\n",
1150 GNUNET_h2s (&msg->key));
1151 GNUNET_STATISTICS_update (stats,
1153 ("# requests filtered by bloomfilter"),
1156 transmit_item (client,
1157 NULL, 0, NULL, 0, 0, 0,
1158 GNUNET_TIME_UNIT_ZERO_ABS,
1162 plugin->api->get_key (plugin->api->cls,
1163 GNUNET_ntohll (msg->offset),
1173 * Function called with the result of an update operation.
1175 * @param cls closure
1176 * @param status #GNUNET_OK or #GNUNET_SYSERR
1177 * @param msg error message on error
1180 update_continuation (void *cls,
1184 struct GNUNET_SERVER_Client *client = cls;
1186 transmit_status (client, status, msg);
1187 GNUNET_SERVER_client_drop (client);
1192 * Handle UPDATE-message.
1194 * @param cls closure
1195 * @param client identification of the client
1196 * @param message the actual message
1199 handle_update (void *cls,
1200 struct GNUNET_SERVER_Client *client,
1201 const struct GNUNET_MessageHeader *message)
1203 const struct UpdateMessage *msg;
1205 GNUNET_STATISTICS_update (stats,
1206 gettext_noop ("# UPDATE requests received"),
1209 msg = (const struct UpdateMessage *) message;
1210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1211 "Processing UPDATE request for %llu\n",
1212 (unsigned long long) GNUNET_ntohll (msg->uid));
1213 GNUNET_SERVER_client_keep (client);
1214 plugin->api->update (plugin->api->cls,
1215 GNUNET_ntohll (msg->uid),
1216 (int32_t) ntohl (msg->priority),
1217 GNUNET_TIME_absolute_ntoh (msg->expiration),
1218 &update_continuation, client);
1223 * Handle GET_REPLICATION-message.
1225 * @param cls closure
1226 * @param client identification of the client
1227 * @param message the actual message
1230 handle_get_replication (void *cls,
1231 struct GNUNET_SERVER_Client *client,
1232 const struct GNUNET_MessageHeader *message)
1234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1235 "Processing `%s' request\n",
1237 GNUNET_STATISTICS_update (stats,
1238 gettext_noop ("# GET REPLICATION requests received"),
1241 GNUNET_SERVER_client_keep (client);
1242 plugin->api->get_replication (plugin->api->cls,
1243 &transmit_item, client);
1248 * Handle GET_ZERO_ANONYMITY-message.
1250 * @param cls closure
1251 * @param client identification of the client
1252 * @param message the actual message
1255 handle_get_zero_anonymity (void *cls,
1256 struct GNUNET_SERVER_Client *client,
1257 const struct GNUNET_MessageHeader *message)
1259 const struct GetZeroAnonymityMessage *msg =
1260 (const struct GetZeroAnonymityMessage *) message;
1261 enum GNUNET_BLOCK_Type type;
1263 type = (enum GNUNET_BLOCK_Type) ntohl (msg->type);
1264 if (type == GNUNET_BLOCK_TYPE_ANY)
1267 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1271 "Processing `%s' request\n",
1272 "GET_ZERO_ANONYMITY");
1273 GNUNET_STATISTICS_update (stats,
1274 gettext_noop ("# GET ZERO ANONYMITY requests received"),
1277 GNUNET_SERVER_client_keep (client);
1278 plugin->api->get_zero_anonymity (plugin->api->cls,
1279 GNUNET_ntohll (msg->offset),
1281 &transmit_item, client);
1286 * Callback function that will cause the item that is passed
1287 * in to be deleted (by returning #GNUNET_NO).
1289 * @param cls closure
1290 * @param key key for the content
1291 * @param size number of bytes in data
1292 * @param data content stored
1293 * @param type type of the content
1294 * @param priority priority of the content
1295 * @param anonymity anonymity-level for the content
1296 * @param expiration expiration time for the content
1297 * @param uid unique identifier for the datum
1298 * @return #GNUNET_OK to keep the item
1299 * #GNUNET_NO to delete the item
1302 remove_callback (void *cls,
1303 const struct GNUNET_HashCode *key,
1306 enum GNUNET_BLOCK_Type type,
1309 struct GNUNET_TIME_Absolute expiration,
1312 struct GNUNET_SERVER_Client *client = cls;
1316 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1317 "No further matches for REMOVE request.\n");
1318 transmit_status (client,
1320 _("Content not found"));
1321 GNUNET_SERVER_client_drop (client);
1322 return GNUNET_OK; /* last item */
1324 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1325 "Item %llu matches REMOVE request for key `%s' and type %u.\n",
1326 (unsigned long long) uid,
1329 GNUNET_STATISTICS_update (stats,
1330 gettext_noop ("# bytes removed (explicit request)"),
1333 GNUNET_CONTAINER_bloomfilter_remove (filter, key);
1334 transmit_status (client, GNUNET_OK, NULL);
1335 GNUNET_SERVER_client_drop (client);
1341 * Handle REMOVE-message.
1343 * @param cls closure
1344 * @param client identification of the client
1345 * @param message the actual message
1348 handle_remove (void *cls,
1349 struct GNUNET_SERVER_Client *client,
1350 const struct GNUNET_MessageHeader *message)
1352 const struct DataMessage *dm = check_data (message);
1353 struct GNUNET_HashCode vhash;
1358 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1361 GNUNET_STATISTICS_update (stats,
1362 gettext_noop ("# REMOVE requests received"),
1364 GNUNET_SERVER_client_keep (client);
1365 GNUNET_CRYPTO_hash (&dm[1],
1368 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1369 "Processing REMOVE request for `%s' of type %u\n",
1370 GNUNET_h2s (&dm->key),
1372 plugin->api->get_key (plugin->api->cls,
1376 (enum GNUNET_BLOCK_Type) ntohl (dm->type),
1377 &remove_callback, client);
1382 * Handle DROP-message.
1384 * @param cls closure
1385 * @param client identification of the client
1386 * @param message the actual message
1389 handle_drop (void *cls,
1390 struct GNUNET_SERVER_Client *client,
1391 const struct GNUNET_MessageHeader *message)
1393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1394 "Processing DROP request\n");
1395 do_drop = GNUNET_YES;
1396 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1401 * Function called by plugins to notify us about a
1402 * change in their disk utilization.
1404 * @param cls closure (NULL)
1405 * @param delta change in disk utilization,
1406 * 0 for "reset to empty"
1409 disk_utilization_change_cb (void *cls,
1412 if ((delta < 0) && (payload < -delta))
1414 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1415 _("Datastore payload must have been inaccurate (%lld < %lld). Recomputing it.\n"),
1416 (long long) payload,
1417 (long long) -delta);
1418 plugin->api->estimate_size (plugin->api->cls,
1420 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1421 _("New payload: %lld\n"),
1422 (long long) payload);
1428 if (last_sync >= MAX_STAT_SYNC_LAG)
1434 * Callback function to process statistic values.
1436 * @param cls closure (struct Plugin*)
1437 * @param subsystem name of subsystem that created the statistic
1438 * @param name the name of the datum
1439 * @param value the current value
1440 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
1441 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
1444 process_stat_in (void *cls,
1445 const char *subsystem,
1450 GNUNET_assert (GNUNET_NO == stats_worked);
1451 stats_worked = GNUNET_YES;
1453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1454 "Notification from statistics about existing payload (%llu), new payload is %llu\n",
1455 (unsigned long long) value,
1456 (unsigned long long) payload);
1462 * Load the datastore plugin.
1464 static struct DatastorePlugin *
1467 struct DatastorePlugin *ret;
1470 ret = GNUNET_new (struct DatastorePlugin);
1472 ret->env.duc = &disk_utilization_change_cb;
1473 ret->env.cls = NULL;
1474 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1475 _("Loading `%s' datastore plugin\n"),
1477 GNUNET_asprintf (&libname,
1478 "libgnunet_plugin_datastore_%s",
1480 ret->short_name = GNUNET_strdup (plugin_name);
1481 ret->lib_name = libname;
1482 ret->api = GNUNET_PLUGIN_load (libname, &ret->env);
1483 if (NULL == ret->api)
1485 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1486 _("Failed to load datastore plugin for `%s'\n"),
1488 GNUNET_free (ret->short_name);
1489 GNUNET_free (libname);
1498 * Function called when the service shuts
1499 * down. Unloads our datastore plugin.
1501 * @param plug plugin to unload
1504 unload_plugin (struct DatastorePlugin *plug)
1506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1507 "Datastore service is unloading plugin...\n");
1508 GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
1509 GNUNET_free (plug->lib_name);
1510 GNUNET_free (plug->short_name);
1515 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
1516 {&handle_reserve, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE,
1517 sizeof (struct ReserveMessage)},
1518 {&handle_release_reserve, NULL,
1519 GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE,
1520 sizeof (struct ReleaseReserveMessage)},
1521 {&handle_put, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_PUT, 0},
1522 {&handle_update, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_UPDATE,
1523 sizeof (struct UpdateMessage)},
1524 {&handle_get, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_GET,
1525 sizeof (struct GetMessage) },
1526 {&handle_get_key, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_GET_KEY,
1527 sizeof (struct GetKeyMessage) },
1528 {&handle_get_replication, NULL,
1529 GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION,
1530 sizeof (struct GNUNET_MessageHeader)},
1531 {&handle_get_zero_anonymity, NULL,
1532 GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY,
1533 sizeof (struct GetZeroAnonymityMessage)},
1534 {&handle_remove, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE, 0},
1535 {&handle_drop, NULL, GNUNET_MESSAGE_TYPE_DATASTORE_DROP,
1536 sizeof (struct GNUNET_MessageHeader)},
1542 * Adds a given @a key to the bloomfilter in @a cls @a count times.
1544 * @param cls the bloomfilter
1545 * @param key key to add
1546 * @param count number of times to add key
1549 add_key_to_bloomfilter (void *cls,
1550 const struct GNUNET_HashCode *key,
1553 struct GNUNET_CONTAINER_BloomFilter *bf = cls;
1557 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1558 _("Bloomfilter construction complete.\n"));
1559 GNUNET_SERVER_add_handlers (server, handlers);
1560 GNUNET_SERVER_resume (server);
1562 = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
1569 GNUNET_CONTAINER_bloomfilter_add (bf, key);
1574 * We finished receiving the statistic. Initialize the plugin; if
1575 * loading the statistic failed, run the estimator.
1578 * @param success #GNUNET_NO if we failed to read the stat
1581 process_stat_done (void *cls,
1585 if (NULL != stat_timeout_task)
1587 GNUNET_SCHEDULER_cancel (stat_timeout_task);
1588 stat_timeout_task = NULL;
1590 plugin = load_plugin ();
1593 GNUNET_CONTAINER_bloomfilter_free (filter);
1597 GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
1602 if (GNUNET_NO == stats_worked)
1604 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1605 "Failed to obtain value from statistics service, recomputing it\n");
1606 plugin->api->estimate_size (plugin->api->cls,
1608 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1609 _("New payload: %lld\n"),
1610 (long long) payload);
1613 if (GNUNET_YES == refresh_bf)
1615 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1616 _("Rebuilding bloomfilter. Please be patient.\n"));
1617 if (NULL != plugin->api->get_keys)
1619 plugin->api->get_keys (plugin->api->cls,
1620 &add_key_to_bloomfilter,
1625 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1626 _("Plugin does not support get_keys function. Please fix!\n"));
1628 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1629 _("Bloomfilter construction complete.\n"));
1632 GNUNET_SERVER_add_handlers (server, handlers);
1633 GNUNET_SERVER_resume (server);
1635 = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
1642 * Fetching stats took to long, run without.
1647 stat_timeout (void *cls)
1649 stat_timeout_task = NULL;
1650 GNUNET_STATISTICS_get_cancel (stat_get);
1651 process_stat_done (NULL, GNUNET_NO);
1656 * Task run during shutdown.
1659 cleaning_task (void *cls)
1661 struct TransmitCallbackContext *tcc;
1663 cleaning_done = GNUNET_YES;
1664 while (NULL != (tcc = tcc_head))
1666 GNUNET_CONTAINER_DLL_remove (tcc_head, tcc_tail, tcc);
1667 if (tcc->th != NULL)
1669 GNUNET_SERVER_notify_transmit_ready_cancel (tcc->th);
1670 GNUNET_SERVER_client_drop (tcc->client);
1672 GNUNET_free (tcc->msg);
1675 if (NULL != expired_kill_task)
1677 GNUNET_SCHEDULER_cancel (expired_kill_task);
1678 expired_kill_task = NULL;
1680 if (GNUNET_YES == do_drop)
1682 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1683 "Dropping database!\n");
1684 plugin->api->drop (plugin->api->cls);
1690 unload_plugin (plugin);
1695 GNUNET_CONTAINER_bloomfilter_free (filter);
1698 if (NULL != stat_get)
1700 GNUNET_STATISTICS_get_cancel (stat_get);
1703 if (NULL != stat_timeout_task)
1705 GNUNET_SCHEDULER_cancel (stat_timeout_task);
1706 stat_timeout_task = NULL;
1708 GNUNET_free_non_null (plugin_name);
1714 GNUNET_STATISTICS_destroy (stats,
1718 GNUNET_free (quota_stat_name);
1719 quota_stat_name = NULL;
1724 * Function that removes all active reservations made
1725 * by the given client and releases the space for other
1728 * @param cls closure
1729 * @param client identification of the client
1732 cleanup_reservations (void *cls,
1733 struct GNUNET_SERVER_Client *client)
1735 struct ReservationList *pos;
1736 struct ReservationList *prev;
1737 struct ReservationList *next;
1746 if (pos->client == client)
1749 reservations = next;
1752 reserved -= pos->amount + pos->entries * GNUNET_DATASTORE_ENTRY_OVERHEAD;
1761 GNUNET_STATISTICS_set (stats,
1762 gettext_noop ("# reserved"),
1769 * Process datastore requests.
1771 * @param cls closure
1772 * @param serv the initialized server
1773 * @param c configuration to use
1777 struct GNUNET_SERVER_Handle *serv,
1778 const struct GNUNET_CONFIGURATION_Handle *c)
1782 unsigned int bf_size;
1787 GNUNET_CONFIGURATION_get_value_string (cfg,
1792 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1793 _("No `%s' specified for `%s' in configuration!\n"),
1798 GNUNET_asprintf ("a_stat_name,
1799 _("# bytes used in file-sharing datastore `%s'"),
1802 GNUNET_CONFIGURATION_get_value_size (cfg, "DATASTORE", "QUOTA", "a))
1804 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1805 _("No `%s' specified for `%s' in configuration!\n"),
1810 stats = GNUNET_STATISTICS_create ("datastore", cfg);
1811 GNUNET_STATISTICS_set (stats,
1812 gettext_noop ("# quota"),
1815 cache_size = quota / 8; /* Or should we make this an option? */
1816 GNUNET_STATISTICS_set (stats,
1817 gettext_noop ("# cache size"),
1820 if (quota / (32 * 1024LL) > MAX_BF_SIZE)
1821 bf_size = MAX_BF_SIZE;
1823 bf_size = quota / (32 * 1024LL); /* 8 bit per entry, 1 bit per 32 kb in DB */
1826 GNUNET_CONFIGURATION_get_value_filename (cfg,
1830 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)))
1832 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1833 _("Could not use specified filename `%s' for bloomfilter.\n"),
1834 NULL != fn ? fn : "");
1835 GNUNET_free_non_null (fn);
1840 GNUNET_asprintf (&pfn, "%s.%s", fn, plugin_name);
1841 if (GNUNET_YES == GNUNET_DISK_file_test (pfn))
1843 filter = GNUNET_CONTAINER_bloomfilter_load (pfn, bf_size, 5); /* approx. 3% false positives at max use */
1846 /* file exists but not valid, remove and try again, but refresh */
1847 if (0 != UNLINK (pfn))
1849 /* failed to remove, run without file */
1850 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1851 _("Failed to remove bogus bloomfilter file `%s'\n"),
1855 filter = GNUNET_CONTAINER_bloomfilter_load (NULL, bf_size, 5); /* approx. 3% false positives at max use */
1856 refresh_bf = GNUNET_YES;
1860 /* try again after remove */
1861 filter = GNUNET_CONTAINER_bloomfilter_load (pfn, bf_size, 5); /* approx. 3% false positives at max use */
1862 refresh_bf = GNUNET_YES;
1865 /* failed yet again, give up on using file */
1866 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1867 _("Failed to remove bogus bloomfilter file `%s'\n"),
1871 filter = GNUNET_CONTAINER_bloomfilter_init (NULL, bf_size, 5); /* approx. 3% false positives at max use */
1877 /* normal case: have an existing valid bf file, no need to refresh */
1878 refresh_bf = GNUNET_NO;
1883 filter = GNUNET_CONTAINER_bloomfilter_load (pfn, bf_size, 5); /* approx. 3% false positives at max use */
1884 refresh_bf = GNUNET_YES;
1890 filter = GNUNET_CONTAINER_bloomfilter_init (NULL, bf_size, 5); /* approx. 3% false positives at max use */
1891 refresh_bf = GNUNET_YES;
1893 GNUNET_free_non_null (fn);
1896 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1897 _("Failed to initialize bloomfilter.\n"));
1900 GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
1905 GNUNET_SERVER_suspend (server);
1907 GNUNET_STATISTICS_get (stats,
1913 if (NULL == stat_get)
1914 process_stat_done (NULL, GNUNET_SYSERR);
1916 stat_timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
1919 GNUNET_SERVER_disconnect_notify (server,
1920 &cleanup_reservations,
1922 GNUNET_SCHEDULER_add_shutdown (&cleaning_task,
1928 * The main function for the datastore service.
1930 * @param argc number of arguments from the command line
1931 * @param argv command line arguments
1932 * @return 0 ok, 1 on error
1942 GNUNET_SERVICE_run (argc, argv, "datastore",
1943 GNUNET_SERVICE_OPTION_NONE,
1944 &run, NULL)) ? 0 : 1;
1949 /* end of gnunet-service-datastore.c */