2 * This file is part of GNUnet
3 * Copyright (C) 2013 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 psycstore/gnunet-service-psycstore.c
23 * @brief PSYCstore service
24 * @author Gabor X Toth
25 * @author Christian Grothoff
31 #include "gnunet_util_lib.h"
32 #include "gnunet_constants.h"
33 #include "gnunet_protocols.h"
34 #include "gnunet_statistics_service.h"
35 #include "gnunet_psyc_util_lib.h"
36 #include "gnunet_psycstore_service.h"
37 #include "gnunet_psycstore_plugin.h"
38 #include "psycstore.h"
42 * Handle to our current configuration.
44 static const struct GNUNET_CONFIGURATION_Handle *cfg;
49 struct GNUNET_SERVICE_Handle *service;
52 * Handle to the statistics service.
54 static struct GNUNET_STATISTICS_Handle *stats;
59 static struct GNUNET_PSYCSTORE_PluginFunctions *db;
62 * Name of the database plugin
64 static char *db_lib_name;
68 * Task run during shutdown.
73 shutdown_task (void *cls)
77 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
80 GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db));
81 GNUNET_free (db_lib_name);
87 * Send a result code back to the client.
90 * Client that should receive the result code.
94 * Operation ID in network byte order.
96 * Error message to include (or NULL for none).
99 send_result_code (struct GNUNET_SERVICE_Client *client,
104 struct OperationResult *res;
108 err_size = strnlen (err_msg,
109 GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (*res) - 1) + 1;
110 struct GNUNET_MQ_Envelope *
111 env = GNUNET_MQ_msg_extra (res, err_size,
112 GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_CODE);
113 res->result_code = GNUNET_htonll (result_code - INT64_MIN);
117 GNUNET_memcpy (&res[1], err_msg, err_size);
118 ((char *) &res[1])[err_size - 1] = '\0';
121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
122 "Sending result to client: %" PRId64 " (%s)\n",
123 result_code, err_msg);
124 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
130 MEMBERSHIP_TEST_NOT_NEEDED = 0,
131 MEMBERSHIP_TEST_NEEDED = 1,
132 MEMBERSHIP_TEST_DONE = 2,
133 } MessageMembershipTest;
138 struct GNUNET_SERVICE_Client *client;
141 * Channel's public key.
143 struct GNUNET_CRYPTO_EddsaPublicKey channel_key;
146 * Slave's public key.
148 struct GNUNET_CRYPTO_EcdsaPublicKey slave_key;
156 * Membership test result.
158 int membership_test_result;
161 * Do membership test with @a slave_key before returning fragment?
162 * @see enum MessageMembershipTest
164 uint8_t membership_test;
169 send_fragment (void *cls, struct GNUNET_MULTICAST_MessageHeader *msg,
170 enum GNUNET_PSYCSTORE_MessageFlags flags)
172 struct SendClosure *sc = cls;
173 struct FragmentResult *res;
175 if (MEMBERSHIP_TEST_NEEDED == sc->membership_test)
177 sc->membership_test = MEMBERSHIP_TEST_DONE;
178 sc->membership_test_result
179 = db->membership_test (db->cls, &sc->channel_key, &sc->slave_key,
180 GNUNET_ntohll (msg->message_id));
181 switch (sc->membership_test_result)
192 size_t msg_size = ntohs (msg->header.size);
194 struct GNUNET_MQ_Envelope *
195 env = GNUNET_MQ_msg_extra (res, msg_size,
196 GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_FRAGMENT);
197 res->op_id = sc->op_id;
198 res->psycstore_flags = htonl (flags);
199 GNUNET_memcpy (&res[1], msg, msg_size);
200 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
201 "Sending fragment %ld to client\n",
202 GNUNET_ntohll (msg->fragment_id));
205 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (sc->client), env);
211 send_state_var (void *cls, const char *name,
212 const void *value, uint32_t value_size)
214 struct SendClosure *sc = cls;
215 struct StateResult *res;
216 size_t name_size = strlen (name) + 1;
218 /** @todo FIXME: split up value into 64k chunks */
220 struct GNUNET_MQ_Envelope *
221 env = GNUNET_MQ_msg_extra (res, name_size + value_size,
222 GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_STATE);
223 res->op_id = sc->op_id;
224 res->name_size = htons (name_size);
225 GNUNET_memcpy (&res[1], name, name_size);
226 GNUNET_memcpy ((char *) &res[1] + name_size, value, value_size);
227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
228 "Sending state variable %s to client\n", name);
230 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (sc->client), env);
236 handle_client_membership_store (void *cls,
237 const struct MembershipStoreRequest *req)
239 struct GNUNET_SERVICE_Client *client = cls;
241 int ret = db->membership_store (db->cls, &req->channel_key, &req->slave_key,
243 GNUNET_ntohll (req->announced_at),
244 GNUNET_ntohll (req->effective_since),
245 GNUNET_ntohll (req->group_generation));
247 if (ret != GNUNET_OK)
248 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
249 _("Failed to store membership information!\n"));
251 send_result_code (client, req->op_id, ret, NULL);
252 GNUNET_SERVICE_client_continue (client);
257 handle_client_membership_test (void *cls,
258 const struct MembershipTestRequest *req)
260 struct GNUNET_SERVICE_Client *client = cls;
262 int ret = db->membership_test (db->cls, &req->channel_key, &req->slave_key,
263 GNUNET_ntohll (req->message_id));
270 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
271 _("Failed to test membership!\n"));
274 send_result_code (client, req->op_id, ret, NULL);
275 GNUNET_SERVICE_client_continue (client);
280 handle_client_fragment_store (void *cls,
281 const struct FragmentStoreRequest *req)
283 struct GNUNET_SERVICE_Client *client = cls;
285 int ret = db->fragment_store (db->cls, &req->channel_key,
286 (const struct GNUNET_MULTICAST_MessageHeader *)
287 &req[1], ntohl (req->psycstore_flags));
289 if (ret != GNUNET_OK)
290 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
291 _("Failed to store fragment!\n"));
293 send_result_code (client, req->op_id, ret, NULL);
294 GNUNET_SERVICE_client_continue (client);
299 handle_client_fragment_get (void *cls,
300 const struct FragmentGetRequest *req)
302 struct GNUNET_SERVICE_Client *client = cls;
305 sc = { .op_id = req->op_id,
307 .channel_key = req->channel_key,
308 .slave_key = req->slave_key,
309 .membership_test = req->do_membership_test };
312 uint64_t ret_frags = 0;
313 uint64_t first_fragment_id = GNUNET_ntohll (req->first_fragment_id);
314 uint64_t last_fragment_id = GNUNET_ntohll (req->last_fragment_id);
315 uint64_t limit = GNUNET_ntohll (req->fragment_limit);
318 ret = db->fragment_get (db->cls, &req->channel_key,
319 first_fragment_id, last_fragment_id,
320 &ret_frags, send_fragment, &sc);
322 ret = db->fragment_get_latest (db->cls, &req->channel_key, limit,
323 &ret_frags, send_fragment, &sc);
329 if (MEMBERSHIP_TEST_DONE == sc.membership_test)
331 switch (sc.membership_test_result)
337 ret = GNUNET_PSYCSTORE_MEMBERSHIP_TEST_FAILED;
347 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
348 _("Failed to get fragment!\n"));
350 send_result_code (client, req->op_id, (ret < 0) ? ret : ret_frags, NULL);
351 GNUNET_SERVICE_client_continue (client);
356 handle_client_message_get (void *cls,
357 const struct MessageGetRequest *req)
359 struct GNUNET_SERVICE_Client *client = cls;
361 uint16_t size = ntohs (req->header.size);
362 const char *method_prefix = (const char *) &req[1];
364 if (size < sizeof (*req) + 1
365 || '\0' != method_prefix[size - sizeof (*req) - 1])
367 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
368 "Message get: invalid method prefix. size: %u < %u?\n",
370 (unsigned int) (sizeof (*req) + 1));
372 GNUNET_SERVICE_client_drop (client);
377 sc = { .op_id = req->op_id,
379 .channel_key = req->channel_key,
380 .slave_key = req->slave_key,
381 .membership_test = req->do_membership_test };
384 uint64_t ret_frags = 0;
385 uint64_t first_message_id = GNUNET_ntohll (req->first_message_id);
386 uint64_t last_message_id = GNUNET_ntohll (req->last_message_id);
387 uint64_t msg_limit = GNUNET_ntohll (req->message_limit);
388 uint64_t frag_limit = GNUNET_ntohll (req->fragment_limit);
390 /** @todo method_prefix */
392 ret = db->message_get (db->cls, &req->channel_key,
393 first_message_id, last_message_id, frag_limit,
394 &ret_frags, send_fragment, &sc);
396 ret = db->message_get_latest (db->cls, &req->channel_key, msg_limit,
397 &ret_frags, send_fragment, &sc);
405 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
406 _("Failed to get message!\n"));
409 send_result_code (client, req->op_id, (ret < 0) ? ret : ret_frags, NULL);
410 GNUNET_SERVICE_client_continue (client);
415 handle_client_message_get_fragment (void *cls,
416 const struct MessageGetFragmentRequest *req)
418 struct GNUNET_SERVICE_Client *client = cls;
421 sc = { .op_id = req->op_id, .client = client,
422 .channel_key = req->channel_key, .slave_key = req->slave_key,
423 .membership_test = req->do_membership_test };
425 int ret = db->message_get_fragment (db->cls, &req->channel_key,
426 GNUNET_ntohll (req->message_id),
427 GNUNET_ntohll (req->fragment_offset),
428 &send_fragment, &sc);
435 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
436 _("Failed to get message fragment!\n"));
439 send_result_code (client, req->op_id, ret, NULL);
440 GNUNET_SERVICE_client_continue (client);
445 handle_client_counters_get (void *cls,
446 const struct OperationRequest *req)
448 struct GNUNET_SERVICE_Client *client = cls;
450 struct CountersResult *res;
451 struct GNUNET_MQ_Envelope *
452 env = GNUNET_MQ_msg (res, GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS);
454 int ret = db->counters_message_get (db->cls, &req->channel_key,
455 &res->max_fragment_id, &res->max_message_id,
456 &res->max_group_generation);
460 ret = db->counters_state_get (db->cls, &req->channel_key,
461 &res->max_state_message_id);
465 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
466 _("Failed to get master counters!\n"));
469 res->result_code = htonl (ret);
470 res->op_id = req->op_id;
471 res->max_fragment_id = GNUNET_htonll (res->max_fragment_id);
472 res->max_message_id = GNUNET_htonll (res->max_message_id);
473 res->max_group_generation = GNUNET_htonll (res->max_group_generation);
474 res->max_state_message_id = GNUNET_htonll (res->max_state_message_id);
476 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
477 GNUNET_SERVICE_client_continue (client);
481 struct StateModifyClosure
483 const struct GNUNET_CRYPTO_EddsaPublicKey channel_key;
484 struct GNUNET_PSYC_ReceiveHandle *recv;
485 enum GNUNET_PSYC_MessageState msg_state;
489 uint32_t mod_value_size;
490 uint32_t mod_value_remaining;
495 recv_state_message_part (void *cls,
496 const struct GNUNET_PSYC_MessageHeader *msg,
497 const struct GNUNET_MessageHeader *pmsg)
499 struct StateModifyClosure *scls = cls;
503 { // FIXME: error on unknown message
507 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
508 "recv_state_message_part() message_id: %" PRIu64
509 ", fragment_offset: %" PRIu64 ", flags: %u\n",
510 GNUNET_ntohll (msg->message_id),
511 GNUNET_ntohll (msg->fragment_offset),
516 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_ERROR;
520 switch (ntohs (pmsg->type))
522 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD:
524 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_METHOD;
528 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER:
530 struct GNUNET_PSYC_MessageModifier *
531 pmod = (struct GNUNET_PSYC_MessageModifier *) pmsg;
532 psize = ntohs (pmod->header.size);
533 uint16_t name_size = ntohs (pmod->name_size);
534 uint32_t value_size = ntohl (pmod->value_size);
536 const char *name = (const char *) &pmod[1];
537 const void *value = name + name_size;
539 if (GNUNET_PSYC_OP_SET != pmod->oper)
540 { // Apply non-transient operation.
541 if (psize == sizeof (*pmod) + name_size + value_size)
543 db->state_modify_op (db->cls, &scls->channel_key,
544 pmod->oper, name, value, value_size);
548 scls->mod_oper = pmod->oper;
549 scls->mod_name = GNUNET_malloc (name_size);
550 GNUNET_memcpy (scls->mod_name, name, name_size);
552 scls->mod_value_size = value_size;
553 scls->mod_value = GNUNET_malloc (scls->mod_value_size);
554 scls->mod_value_remaining
555 = scls->mod_value_size - (psize - sizeof (*pmod) - name_size);
556 GNUNET_memcpy (scls->mod_value, value, value_size - scls->mod_value_remaining);
559 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_MODIFIER;
563 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT:
564 if (GNUNET_PSYC_OP_SET != scls->mod_oper)
566 if (scls->mod_value_remaining == 0)
569 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_ERROR;
571 psize = ntohs (pmsg->size);
572 GNUNET_memcpy (scls->mod_value + (scls->mod_value_size - scls->mod_value_remaining),
573 &pmsg[1], psize - sizeof (*pmsg));
574 scls->mod_value_remaining -= psize - sizeof (*pmsg);
575 if (0 == scls->mod_value_remaining)
577 db->state_modify_op (db->cls, &scls->channel_key,
578 scls->mod_oper, scls->mod_name,
579 scls->mod_value, scls->mod_value_size);
580 GNUNET_free (scls->mod_name);
581 GNUNET_free (scls->mod_value);
583 scls->mod_name = NULL;
584 scls->mod_value = NULL;
585 scls->mod_value_size = 0;
588 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_MOD_CONT;
591 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_DATA:
592 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_DATA;
595 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_END:
596 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_END;
600 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_ERROR;
606 recv_state_fragment (void *cls, struct GNUNET_MULTICAST_MessageHeader *msg,
607 enum GNUNET_PSYCSTORE_MessageFlags flags)
609 struct StateModifyClosure *scls = cls;
611 if (NULL == scls->recv)
613 scls->recv = GNUNET_PSYC_receive_create (NULL, recv_state_message_part,
617 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
618 "recv_state_fragment: %" PRIu64 "\n", GNUNET_ntohll (msg->fragment_id));
620 struct GNUNET_PSYC_MessageHeader *
621 pmsg = GNUNET_PSYC_message_header_create (msg, flags);
622 GNUNET_PSYC_receive_message (scls->recv, pmsg);
630 handle_client_state_modify (void *cls,
631 const struct StateModifyRequest *req)
633 struct GNUNET_SERVICE_Client *client = cls;
635 uint64_t message_id = GNUNET_ntohll (req->message_id);
636 uint64_t state_delta = GNUNET_ntohll (req->state_delta);
637 uint64_t ret_frags = 0;
638 struct StateModifyClosure
639 scls = { .channel_key = req->channel_key };
641 int ret = db->state_modify_begin (db->cls, &req->channel_key,
642 message_id, state_delta);
644 if (GNUNET_OK != ret)
646 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
647 _("Failed to begin modifying state: %d\n"), ret);
651 ret = db->message_get (db->cls, &req->channel_key,
652 message_id, message_id, 0,
653 &ret_frags, recv_state_fragment, &scls);
654 if (GNUNET_OK != ret)
656 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
657 _("Failed to modify state: %d\n"), ret);
662 if (GNUNET_OK != db->state_modify_end (db->cls, &req->channel_key, message_id))
664 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
665 _("Failed to end modifying state!\n"));
669 if (NULL != scls.recv)
671 GNUNET_PSYC_receive_destroy (scls.recv);
675 send_result_code (client, req->op_id, ret, NULL);
676 GNUNET_SERVICE_client_continue (client);
681 check_client_state_sync (void *cls,
682 const struct StateSyncRequest *req)
688 /** @todo FIXME: stop processing further state sync messages after an error */
690 handle_client_state_sync (void *cls,
691 const struct StateSyncRequest *req)
693 struct GNUNET_SERVICE_Client *client = cls;
695 int ret = GNUNET_SYSERR;
696 const char *name = (const char *) &req[1];
697 uint16_t name_size = ntohs (req->name_size);
699 if (name_size <= 2 || '\0' != name[name_size - 1])
701 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
702 _("Tried to set invalid state variable name!\n"));
709 if (req->flags & STATE_OP_FIRST)
711 ret = db->state_sync_begin (db->cls, &req->channel_key);
713 if (ret != GNUNET_OK)
715 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
716 _("Failed to begin synchronizing state!\n"));
720 ret = db->state_sync_assign (db->cls, &req->channel_key, name,
721 name + ntohs (req->name_size),
722 ntohs (req->header.size) - sizeof (*req)
723 - ntohs (req->name_size));
726 if (GNUNET_OK == ret && req->flags & STATE_OP_LAST)
728 ret = db->state_sync_end (db->cls, &req->channel_key,
729 GNUNET_ntohll (req->max_state_message_id),
730 GNUNET_ntohll (req->state_hash_message_id));
731 if (ret != GNUNET_OK)
732 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
733 _("Failed to end synchronizing state!\n"));
736 send_result_code (client, req->op_id, ret, NULL);
737 GNUNET_SERVICE_client_continue (client);
742 handle_client_state_reset (void *cls,
743 const struct OperationRequest *req)
745 struct GNUNET_SERVICE_Client *client = cls;
747 int ret = db->state_reset (db->cls, &req->channel_key);
749 if (ret != GNUNET_OK)
750 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
751 _("Failed to reset state!\n"));
753 send_result_code (client, req->op_id, ret, NULL);
754 GNUNET_SERVICE_client_continue (client);
759 handle_client_state_hash_update (void *cls,
760 const struct StateHashUpdateRequest *req)
762 struct GNUNET_SERVICE_Client *client = cls;
764 int ret = db->state_reset (db->cls, &req->channel_key);
765 if (ret != GNUNET_OK)
766 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
767 _("Failed to reset state!\n"));
769 send_result_code (client, req->op_id, ret, NULL);
770 GNUNET_SERVICE_client_continue (client);
775 check_client_state_get (void *cls,
776 const struct OperationRequest *req)
783 handle_client_state_get (void *cls,
784 const struct OperationRequest *req)
786 struct GNUNET_SERVICE_Client *client = cls;
788 struct SendClosure sc = { .op_id = req->op_id, .client = client };
789 int64_t ret = GNUNET_SYSERR;
790 const char *name = (const char *) &req[1];
791 uint16_t name_size = ntohs (req->header.size) - sizeof (*req);
793 if (name_size <= 2 || '\0' != name[name_size - 1])
795 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
796 _("Tried to get invalid state variable name!\n"));
801 ret = db->state_get (db->cls, &req->channel_key, name,
802 &send_state_var, &sc);
803 if (GNUNET_NO == ret && name_size >= 5) /* min: _a_b\0 */
805 char *p, *n = GNUNET_malloc (name_size);
806 GNUNET_memcpy (n, name, name_size);
807 while (&n[1] < (p = strrchr (n, '_')) && GNUNET_NO == ret)
810 ret = db->state_get (db->cls, &req->channel_key, n,
811 &send_state_var, &sc);
822 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
823 _("Failed to get state variable!\n"));
826 send_result_code (client, req->op_id, ret, NULL);
827 GNUNET_SERVICE_client_continue (client);
832 check_client_state_get_prefix (void *cls,
833 const struct OperationRequest *req)
840 handle_client_state_get_prefix (void *cls,
841 const struct OperationRequest *req)
843 struct GNUNET_SERVICE_Client *client = cls;
845 struct SendClosure sc = { .op_id = req->op_id, .client = client };
846 int64_t ret = GNUNET_SYSERR;
847 const char *name = (const char *) &req[1];
848 uint16_t name_size = ntohs (req->header.size) - sizeof (*req);
850 if (name_size <= 1 || '\0' != name[name_size - 1])
852 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
853 _("Tried to get invalid state variable name!\n"));
858 ret = db->state_get_prefix (db->cls, &req->channel_key, name,
859 &send_state_var, &sc);
867 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
868 _("Failed to get state variable!\n"));
871 send_result_code (client, req->op_id, ret, NULL);
872 GNUNET_SERVICE_client_continue (client);
877 * A new client connected.
880 * @param client client to add
881 * @param mq message queue for @a client
885 client_notify_connect (void *cls,
886 struct GNUNET_SERVICE_Client *client,
887 struct GNUNET_MQ_Handle *mq)
889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client connected: %p\n", client);
896 * Called whenever a client is disconnected.
897 * Frees our resources associated with that client.
900 * @param client identification of the client
901 * @param app_ctx must match @a client
904 client_notify_disconnect (void *cls,
905 struct GNUNET_SERVICE_Client *client,
912 * Initialize the PSYCstore service.
914 * @param cls Closure.
915 * @param server The initialized server.
916 * @param c Configuration to use.
920 const struct GNUNET_CONFIGURATION_Handle *c,
921 struct GNUNET_SERVICE_Handle *svc)
926 /* Loading database plugin */
929 GNUNET_CONFIGURATION_get_value_string (cfg, "psycstore", "database",
932 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
938 GNUNET_asprintf (&db_lib_name,
939 "libgnunet_plugin_psycstore_%s",
941 db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg);
942 GNUNET_free (database);
946 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
947 "Could not load database backend `%s'\n",
949 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
953 stats = GNUNET_STATISTICS_create ("psycstore", cfg);
954 GNUNET_SCHEDULER_add_shutdown (shutdown_task,
959 * Define "main" method using service macro.
963 GNUNET_SERVICE_OPTION_NONE,
965 client_notify_connect,
966 client_notify_disconnect,
968 GNUNET_MQ_hd_fixed_size (client_membership_store,
969 GNUNET_MESSAGE_TYPE_PSYCSTORE_MEMBERSHIP_STORE,
970 struct MembershipStoreRequest,
972 GNUNET_MQ_hd_fixed_size (client_membership_test,
973 GNUNET_MESSAGE_TYPE_PSYCSTORE_MEMBERSHIP_TEST,
974 struct MembershipTestRequest,
976 GNUNET_MQ_hd_fixed_size (client_fragment_store,
977 GNUNET_MESSAGE_TYPE_PSYCSTORE_FRAGMENT_STORE,
978 struct FragmentStoreRequest,
980 GNUNET_MQ_hd_fixed_size (client_fragment_get,
981 GNUNET_MESSAGE_TYPE_PSYCSTORE_FRAGMENT_GET,
982 struct FragmentGetRequest,
984 GNUNET_MQ_hd_fixed_size (client_message_get,
985 GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET,
986 struct MessageGetRequest,
988 GNUNET_MQ_hd_fixed_size (client_message_get_fragment,
989 GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET_FRAGMENT,
990 struct MessageGetFragmentRequest,
992 GNUNET_MQ_hd_fixed_size (client_counters_get,
993 GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET,
994 struct OperationRequest,
996 GNUNET_MQ_hd_fixed_size (client_state_modify,
997 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_MODIFY,
998 struct StateModifyRequest,
1000 GNUNET_MQ_hd_var_size (client_state_sync,
1001 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_SYNC,
1002 struct StateSyncRequest,
1004 GNUNET_MQ_hd_fixed_size (client_state_reset,
1005 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_RESET,
1006 struct OperationRequest,
1008 GNUNET_MQ_hd_fixed_size (client_state_hash_update,
1009 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_HASH_UPDATE,
1010 struct StateHashUpdateRequest,
1012 GNUNET_MQ_hd_var_size (client_state_get,
1013 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_GET,
1014 struct OperationRequest,
1016 GNUNET_MQ_hd_var_size (client_state_get_prefix,
1017 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_GET_PREFIX,
1018 struct OperationRequest,
1021 /* end of gnunet-service-psycstore.c */