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 static 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 check_client_fragment_store (void *cls,
281 const struct FragmentStoreRequest *req)
288 handle_client_fragment_store (void *cls,
289 const struct FragmentStoreRequest *req)
291 struct GNUNET_SERVICE_Client *client = cls;
293 const struct GNUNET_MessageHeader *
294 msg = GNUNET_MQ_extract_nested_mh (req);
296 || ntohs (msg->size) < sizeof (struct GNUNET_MULTICAST_MessageHeader))
299 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
300 _("Dropping invalid fragment\n"));
301 GNUNET_SERVICE_client_drop (client);
305 int ret = db->fragment_store (db->cls, &req->channel_key,
306 (const struct GNUNET_MULTICAST_MessageHeader *)
307 msg, ntohl (req->psycstore_flags));
309 if (ret != GNUNET_OK)
310 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
311 _("Failed to store fragment\n"));
313 send_result_code (client, req->op_id, ret, NULL);
314 GNUNET_SERVICE_client_continue (client);
319 handle_client_fragment_get (void *cls,
320 const struct FragmentGetRequest *req)
322 struct GNUNET_SERVICE_Client *client = cls;
325 sc = { .op_id = req->op_id,
327 .channel_key = req->channel_key,
328 .slave_key = req->slave_key,
329 .membership_test = req->do_membership_test };
332 uint64_t ret_frags = 0;
333 uint64_t first_fragment_id = GNUNET_ntohll (req->first_fragment_id);
334 uint64_t last_fragment_id = GNUNET_ntohll (req->last_fragment_id);
335 uint64_t limit = GNUNET_ntohll (req->fragment_limit);
338 ret = db->fragment_get (db->cls, &req->channel_key,
339 first_fragment_id, last_fragment_id,
340 &ret_frags, send_fragment, &sc);
342 ret = db->fragment_get_latest (db->cls, &req->channel_key, limit,
343 &ret_frags, send_fragment, &sc);
349 if (MEMBERSHIP_TEST_DONE == sc.membership_test)
351 switch (sc.membership_test_result)
357 ret = GNUNET_PSYCSTORE_MEMBERSHIP_TEST_FAILED;
367 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
368 _("Failed to get fragment!\n"));
370 send_result_code (client, req->op_id, (ret < 0) ? ret : ret_frags, NULL);
371 GNUNET_SERVICE_client_continue (client);
376 check_client_message_get (void *cls,
377 const struct MessageGetRequest *req)
384 handle_client_message_get (void *cls,
385 const struct MessageGetRequest *req)
387 struct GNUNET_SERVICE_Client *client = cls;
389 uint16_t size = ntohs (req->header.size);
390 const char *method_prefix = (const char *) &req[1];
392 if (size < sizeof (*req) + 1
393 || '\0' != method_prefix[size - sizeof (*req) - 1])
395 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
396 "Message get: invalid method prefix. size: %u < %u?\n",
398 (unsigned int) (sizeof (*req) + 1));
400 GNUNET_SERVICE_client_drop (client);
405 sc = { .op_id = req->op_id,
407 .channel_key = req->channel_key,
408 .slave_key = req->slave_key,
409 .membership_test = req->do_membership_test };
412 uint64_t ret_frags = 0;
413 uint64_t first_message_id = GNUNET_ntohll (req->first_message_id);
414 uint64_t last_message_id = GNUNET_ntohll (req->last_message_id);
415 uint64_t msg_limit = GNUNET_ntohll (req->message_limit);
416 uint64_t frag_limit = GNUNET_ntohll (req->fragment_limit);
418 /** @todo method_prefix */
420 ret = db->message_get (db->cls, &req->channel_key,
421 first_message_id, last_message_id, frag_limit,
422 &ret_frags, send_fragment, &sc);
424 ret = db->message_get_latest (db->cls, &req->channel_key, msg_limit,
425 &ret_frags, send_fragment, &sc);
433 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
434 _("Failed to get message!\n"));
437 send_result_code (client, req->op_id, (ret < 0) ? ret : ret_frags, NULL);
438 GNUNET_SERVICE_client_continue (client);
443 handle_client_message_get_fragment (void *cls,
444 const struct MessageGetFragmentRequest *req)
446 struct GNUNET_SERVICE_Client *client = cls;
449 sc = { .op_id = req->op_id, .client = client,
450 .channel_key = req->channel_key, .slave_key = req->slave_key,
451 .membership_test = req->do_membership_test };
453 int ret = db->message_get_fragment (db->cls, &req->channel_key,
454 GNUNET_ntohll (req->message_id),
455 GNUNET_ntohll (req->fragment_offset),
456 &send_fragment, &sc);
463 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
464 _("Failed to get message fragment!\n"));
467 send_result_code (client, req->op_id, ret, NULL);
468 GNUNET_SERVICE_client_continue (client);
473 handle_client_counters_get (void *cls,
474 const struct OperationRequest *req)
476 struct GNUNET_SERVICE_Client *client = cls;
478 struct CountersResult *res;
479 struct GNUNET_MQ_Envelope *
480 env = GNUNET_MQ_msg (res, GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS);
482 int ret = db->counters_message_get (db->cls, &req->channel_key,
483 &res->max_fragment_id, &res->max_message_id,
484 &res->max_group_generation);
488 ret = db->counters_state_get (db->cls, &req->channel_key,
489 &res->max_state_message_id);
493 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
494 _("Failed to get master counters!\n"));
497 res->result_code = htonl (ret);
498 res->op_id = req->op_id;
499 res->max_fragment_id = GNUNET_htonll (res->max_fragment_id);
500 res->max_message_id = GNUNET_htonll (res->max_message_id);
501 res->max_group_generation = GNUNET_htonll (res->max_group_generation);
502 res->max_state_message_id = GNUNET_htonll (res->max_state_message_id);
504 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
505 GNUNET_SERVICE_client_continue (client);
509 struct StateModifyClosure
511 const struct GNUNET_CRYPTO_EddsaPublicKey channel_key;
512 struct GNUNET_PSYC_ReceiveHandle *recv;
513 enum GNUNET_PSYC_MessageState msg_state;
517 uint32_t mod_value_size;
518 uint32_t mod_value_remaining;
523 recv_state_message_part (void *cls,
524 const struct GNUNET_PSYC_MessageHeader *msg,
525 const struct GNUNET_MessageHeader *pmsg)
527 struct StateModifyClosure *scls = cls;
531 { // FIXME: error on unknown message
535 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
536 "recv_state_message_part() message_id: %" PRIu64
537 ", fragment_offset: %" PRIu64 ", flags: %u\n",
538 GNUNET_ntohll (msg->message_id),
539 GNUNET_ntohll (msg->fragment_offset),
544 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_ERROR;
548 switch (ntohs (pmsg->type))
550 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD:
552 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_METHOD;
556 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER:
558 struct GNUNET_PSYC_MessageModifier *
559 pmod = (struct GNUNET_PSYC_MessageModifier *) pmsg;
560 psize = ntohs (pmod->header.size);
561 uint16_t name_size = ntohs (pmod->name_size);
562 uint32_t value_size = ntohl (pmod->value_size);
564 const char *name = (const char *) &pmod[1];
565 const void *value = name + name_size;
567 if (GNUNET_PSYC_OP_SET != pmod->oper)
568 { // Apply non-transient operation.
569 if (psize == sizeof (*pmod) + name_size + value_size)
571 db->state_modify_op (db->cls, &scls->channel_key,
572 pmod->oper, name, value, value_size);
576 scls->mod_oper = pmod->oper;
577 scls->mod_name = GNUNET_malloc (name_size);
578 GNUNET_memcpy (scls->mod_name, name, name_size);
580 scls->mod_value_size = value_size;
581 scls->mod_value = GNUNET_malloc (scls->mod_value_size);
582 scls->mod_value_remaining
583 = scls->mod_value_size - (psize - sizeof (*pmod) - name_size);
584 GNUNET_memcpy (scls->mod_value, value, value_size - scls->mod_value_remaining);
587 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_MODIFIER;
591 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT:
592 if (GNUNET_PSYC_OP_SET != scls->mod_oper)
594 if (scls->mod_value_remaining == 0)
597 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_ERROR;
599 psize = ntohs (pmsg->size);
600 GNUNET_memcpy (scls->mod_value + (scls->mod_value_size - scls->mod_value_remaining),
601 &pmsg[1], psize - sizeof (*pmsg));
602 scls->mod_value_remaining -= psize - sizeof (*pmsg);
603 if (0 == scls->mod_value_remaining)
605 db->state_modify_op (db->cls, &scls->channel_key,
606 scls->mod_oper, scls->mod_name,
607 scls->mod_value, scls->mod_value_size);
608 GNUNET_free (scls->mod_name);
609 GNUNET_free (scls->mod_value);
611 scls->mod_name = NULL;
612 scls->mod_value = NULL;
613 scls->mod_value_size = 0;
616 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_MOD_CONT;
619 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_DATA:
620 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_DATA;
623 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_END:
624 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_END;
628 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_ERROR;
634 recv_state_fragment (void *cls, struct GNUNET_MULTICAST_MessageHeader *msg,
635 enum GNUNET_PSYCSTORE_MessageFlags flags)
637 struct StateModifyClosure *scls = cls;
639 if (NULL == scls->recv)
641 scls->recv = GNUNET_PSYC_receive_create (NULL, recv_state_message_part,
645 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
646 "recv_state_fragment: %" PRIu64 "\n", GNUNET_ntohll (msg->fragment_id));
648 struct GNUNET_PSYC_MessageHeader *
649 pmsg = GNUNET_PSYC_message_header_create (msg, flags);
650 GNUNET_PSYC_receive_message (scls->recv, pmsg);
658 handle_client_state_modify (void *cls,
659 const struct StateModifyRequest *req)
661 struct GNUNET_SERVICE_Client *client = cls;
663 uint64_t message_id = GNUNET_ntohll (req->message_id);
664 uint64_t state_delta = GNUNET_ntohll (req->state_delta);
665 uint64_t ret_frags = 0;
666 struct StateModifyClosure
667 scls = { .channel_key = req->channel_key };
669 int ret = db->state_modify_begin (db->cls, &req->channel_key,
670 message_id, state_delta);
672 if (GNUNET_OK != ret)
674 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
675 _("Failed to begin modifying state: %d\n"), ret);
679 ret = db->message_get (db->cls, &req->channel_key,
680 message_id, message_id, 0,
681 &ret_frags, recv_state_fragment, &scls);
682 if (GNUNET_OK != ret)
684 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
685 _("Failed to modify state: %d\n"), ret);
690 if (GNUNET_OK != db->state_modify_end (db->cls, &req->channel_key, message_id))
692 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
693 _("Failed to end modifying state!\n"));
697 if (NULL != scls.recv)
699 GNUNET_PSYC_receive_destroy (scls.recv);
703 send_result_code (client, req->op_id, ret, NULL);
704 GNUNET_SERVICE_client_continue (client);
709 check_client_state_sync (void *cls,
710 const struct StateSyncRequest *req)
716 /** @todo FIXME: stop processing further state sync messages after an error */
718 handle_client_state_sync (void *cls,
719 const struct StateSyncRequest *req)
721 struct GNUNET_SERVICE_Client *client = cls;
723 int ret = GNUNET_SYSERR;
724 const char *name = (const char *) &req[1];
725 uint16_t name_size = ntohs (req->name_size);
727 if (name_size <= 2 || '\0' != name[name_size - 1])
729 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
730 _("Tried to set invalid state variable name!\n"));
737 if (req->flags & STATE_OP_FIRST)
739 ret = db->state_sync_begin (db->cls, &req->channel_key);
741 if (ret != GNUNET_OK)
743 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
744 _("Failed to begin synchronizing state!\n"));
748 ret = db->state_sync_assign (db->cls, &req->channel_key, name,
749 name + ntohs (req->name_size),
750 ntohs (req->header.size) - sizeof (*req)
751 - ntohs (req->name_size));
754 if (GNUNET_OK == ret && req->flags & STATE_OP_LAST)
756 ret = db->state_sync_end (db->cls, &req->channel_key,
757 GNUNET_ntohll (req->max_state_message_id),
758 GNUNET_ntohll (req->state_hash_message_id));
759 if (ret != GNUNET_OK)
760 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
761 _("Failed to end synchronizing state!\n"));
764 send_result_code (client, req->op_id, ret, NULL);
765 GNUNET_SERVICE_client_continue (client);
770 handle_client_state_reset (void *cls,
771 const struct OperationRequest *req)
773 struct GNUNET_SERVICE_Client *client = cls;
775 int ret = db->state_reset (db->cls, &req->channel_key);
777 if (ret != GNUNET_OK)
778 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
779 _("Failed to reset state!\n"));
781 send_result_code (client, req->op_id, ret, NULL);
782 GNUNET_SERVICE_client_continue (client);
787 handle_client_state_hash_update (void *cls,
788 const struct StateHashUpdateRequest *req)
790 struct GNUNET_SERVICE_Client *client = cls;
792 int ret = db->state_reset (db->cls, &req->channel_key);
793 if (ret != GNUNET_OK)
794 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
795 _("Failed to reset state!\n"));
797 send_result_code (client, req->op_id, ret, NULL);
798 GNUNET_SERVICE_client_continue (client);
803 check_client_state_get (void *cls,
804 const struct OperationRequest *req)
811 handle_client_state_get (void *cls,
812 const struct OperationRequest *req)
814 struct GNUNET_SERVICE_Client *client = cls;
816 struct SendClosure sc = { .op_id = req->op_id, .client = client };
817 int64_t ret = GNUNET_SYSERR;
818 const char *name = (const char *) &req[1];
819 uint16_t name_size = ntohs (req->header.size) - sizeof (*req);
821 if (name_size <= 2 || '\0' != name[name_size - 1])
823 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
824 _("Tried to get invalid state variable name!\n"));
829 ret = db->state_get (db->cls, &req->channel_key, name,
830 &send_state_var, &sc);
831 if (GNUNET_NO == ret && name_size >= 5) /* min: _a_b\0 */
833 char *p, *n = GNUNET_malloc (name_size);
834 GNUNET_memcpy (n, name, name_size);
835 while (&n[1] < (p = strrchr (n, '_')) && GNUNET_NO == ret)
838 ret = db->state_get (db->cls, &req->channel_key, n,
839 &send_state_var, &sc);
850 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
851 _("Failed to get state variable!\n"));
854 send_result_code (client, req->op_id, ret, NULL);
855 GNUNET_SERVICE_client_continue (client);
860 check_client_state_get_prefix (void *cls,
861 const struct OperationRequest *req)
868 handle_client_state_get_prefix (void *cls,
869 const struct OperationRequest *req)
871 struct GNUNET_SERVICE_Client *client = cls;
873 struct SendClosure sc = { .op_id = req->op_id, .client = client };
874 int64_t ret = GNUNET_SYSERR;
875 const char *name = (const char *) &req[1];
876 uint16_t name_size = ntohs (req->header.size) - sizeof (*req);
878 if (name_size <= 1 || '\0' != name[name_size - 1])
880 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
881 _("Tried to get invalid state variable name!\n"));
886 ret = db->state_get_prefix (db->cls, &req->channel_key, name,
887 &send_state_var, &sc);
895 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
896 _("Failed to get state variable!\n"));
899 send_result_code (client, req->op_id, ret, NULL);
900 GNUNET_SERVICE_client_continue (client);
905 * A new client connected.
908 * @param client client to add
909 * @param mq message queue for @a client
913 client_notify_connect (void *cls,
914 struct GNUNET_SERVICE_Client *client,
915 struct GNUNET_MQ_Handle *mq)
917 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client connected: %p\n", client);
924 * Called whenever a client is disconnected.
925 * Frees our resources associated with that client.
928 * @param client identification of the client
929 * @param app_ctx must match @a client
932 client_notify_disconnect (void *cls,
933 struct GNUNET_SERVICE_Client *client,
940 * Initialize the PSYCstore service.
942 * @param cls Closure.
943 * @param server The initialized server.
944 * @param c Configuration to use.
948 const struct GNUNET_CONFIGURATION_Handle *c,
949 struct GNUNET_SERVICE_Handle *svc)
954 /* Loading database plugin */
957 GNUNET_CONFIGURATION_get_value_string (cfg, "psycstore", "database",
960 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
966 GNUNET_asprintf (&db_lib_name,
967 "libgnunet_plugin_psycstore_%s",
969 db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg);
970 GNUNET_free (database);
974 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
975 "Could not load database backend `%s'\n",
977 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
981 stats = GNUNET_STATISTICS_create ("psycstore", cfg);
982 GNUNET_SCHEDULER_add_shutdown (shutdown_task,
987 * Define "main" method using service macro.
991 GNUNET_SERVICE_OPTION_NONE,
993 client_notify_connect,
994 client_notify_disconnect,
996 GNUNET_MQ_hd_fixed_size (client_membership_store,
997 GNUNET_MESSAGE_TYPE_PSYCSTORE_MEMBERSHIP_STORE,
998 struct MembershipStoreRequest,
1000 GNUNET_MQ_hd_fixed_size (client_membership_test,
1001 GNUNET_MESSAGE_TYPE_PSYCSTORE_MEMBERSHIP_TEST,
1002 struct MembershipTestRequest,
1004 GNUNET_MQ_hd_var_size (client_fragment_store,
1005 GNUNET_MESSAGE_TYPE_PSYCSTORE_FRAGMENT_STORE,
1006 struct FragmentStoreRequest,
1008 GNUNET_MQ_hd_fixed_size (client_fragment_get,
1009 GNUNET_MESSAGE_TYPE_PSYCSTORE_FRAGMENT_GET,
1010 struct FragmentGetRequest,
1012 GNUNET_MQ_hd_var_size (client_message_get,
1013 GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET,
1014 struct MessageGetRequest,
1016 GNUNET_MQ_hd_fixed_size (client_message_get_fragment,
1017 GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET_FRAGMENT,
1018 struct MessageGetFragmentRequest,
1020 GNUNET_MQ_hd_fixed_size (client_counters_get,
1021 GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET,
1022 struct OperationRequest,
1024 GNUNET_MQ_hd_fixed_size (client_state_modify,
1025 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_MODIFY,
1026 struct StateModifyRequest,
1028 GNUNET_MQ_hd_var_size (client_state_sync,
1029 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_SYNC,
1030 struct StateSyncRequest,
1032 GNUNET_MQ_hd_fixed_size (client_state_reset,
1033 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_RESET,
1034 struct OperationRequest,
1036 GNUNET_MQ_hd_fixed_size (client_state_hash_update,
1037 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_HASH_UPDATE,
1038 struct StateHashUpdateRequest,
1040 GNUNET_MQ_hd_var_size (client_state_get,
1041 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_GET,
1042 struct OperationRequest,
1044 GNUNET_MQ_hd_var_size (client_state_get_prefix,
1045 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_GET_PREFIX,
1046 struct OperationRequest,
1049 /* end of gnunet-service-psycstore.c */