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 it
6 * under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License,
8 * or (at your 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 * Affero General Public License for more details.
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @file psycstore/gnunet-service-psycstore.c
21 * @brief PSYCstore service
22 * @author Gabor X Toth
23 * @author Christian Grothoff
29 #include "gnunet_util_lib.h"
30 #include "gnunet_constants.h"
31 #include "gnunet_protocols.h"
32 #include "gnunet_statistics_service.h"
33 #include "gnunet_psyc_util_lib.h"
34 #include "gnunet_psycstore_service.h"
35 #include "gnunet_psycstore_plugin.h"
36 #include "psycstore.h"
40 * Handle to our current configuration.
42 static const struct GNUNET_CONFIGURATION_Handle *cfg;
47 static struct GNUNET_SERVICE_Handle *service;
50 * Handle to the statistics service.
52 static struct GNUNET_STATISTICS_Handle *stats;
57 static struct GNUNET_PSYCSTORE_PluginFunctions *db;
60 * Name of the database plugin
62 static char *db_lib_name;
66 * Task run during shutdown.
71 shutdown_task (void *cls)
75 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
78 GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db));
79 GNUNET_free (db_lib_name);
85 * Send a result code back to the client.
88 * Client that should receive the result code.
92 * Operation ID in network byte order.
94 * Error message to include (or NULL for none).
97 send_result_code (struct GNUNET_SERVICE_Client *client,
102 struct OperationResult *res;
106 err_size = strnlen (err_msg,
107 GNUNET_MAX_MESSAGE_SIZE - sizeof (*res) - 1) + 1;
108 struct GNUNET_MQ_Envelope *
109 env = GNUNET_MQ_msg_extra (res, err_size,
110 GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_CODE);
111 res->result_code = GNUNET_htonll (result_code - INT64_MIN);
115 GNUNET_memcpy (&res[1], err_msg, err_size);
116 ((char *) &res[1])[err_size - 1] = '\0';
119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
120 "Sending result to client: %" PRId64 " (%s)\n",
121 result_code, err_msg);
122 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
128 MEMBERSHIP_TEST_NOT_NEEDED = 0,
129 MEMBERSHIP_TEST_NEEDED = 1,
130 MEMBERSHIP_TEST_DONE = 2,
131 } MessageMembershipTest;
136 struct GNUNET_SERVICE_Client *client;
139 * Channel's public key.
141 struct GNUNET_CRYPTO_EddsaPublicKey channel_key;
144 * Slave's public key.
146 struct GNUNET_CRYPTO_EcdsaPublicKey slave_key;
154 * Membership test result.
156 int membership_test_result;
159 * Do membership test with @a slave_key before returning fragment?
160 * @see enum MessageMembershipTest
162 uint8_t membership_test;
167 send_fragment (void *cls, struct GNUNET_MULTICAST_MessageHeader *msg,
168 enum GNUNET_PSYCSTORE_MessageFlags flags)
170 struct SendClosure *sc = cls;
171 struct FragmentResult *res;
173 if (MEMBERSHIP_TEST_NEEDED == sc->membership_test)
175 sc->membership_test = MEMBERSHIP_TEST_DONE;
176 sc->membership_test_result
177 = db->membership_test (db->cls, &sc->channel_key, &sc->slave_key,
178 GNUNET_ntohll (msg->message_id));
179 switch (sc->membership_test_result)
190 size_t msg_size = ntohs (msg->header.size);
192 struct GNUNET_MQ_Envelope *
193 env = GNUNET_MQ_msg_extra (res, msg_size,
194 GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_FRAGMENT);
195 res->op_id = sc->op_id;
196 res->psycstore_flags = htonl (flags);
197 GNUNET_memcpy (&res[1], msg, msg_size);
198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
199 "Sending fragment %llu to client\n",
200 (unsigned long long) GNUNET_ntohll (msg->fragment_id));
203 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (sc->client), env);
209 send_state_var (void *cls, const char *name,
210 const void *value, uint32_t value_size)
212 struct SendClosure *sc = cls;
213 struct StateResult *res;
214 size_t name_size = strlen (name) + 1;
216 /** @todo FIXME: split up value into 64k chunks */
218 struct GNUNET_MQ_Envelope *
219 env = GNUNET_MQ_msg_extra (res, name_size + value_size,
220 GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_STATE);
221 res->op_id = sc->op_id;
222 res->name_size = htons (name_size);
223 GNUNET_memcpy (&res[1], name, name_size);
224 GNUNET_memcpy ((char *) &res[1] + name_size, value, value_size);
225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
226 "Sending state variable %s to client\n", name);
228 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (sc->client), env);
234 handle_client_membership_store (void *cls,
235 const struct MembershipStoreRequest *req)
237 struct GNUNET_SERVICE_Client *client = cls;
239 int ret = db->membership_store (db->cls, &req->channel_key, &req->slave_key,
241 GNUNET_ntohll (req->announced_at),
242 GNUNET_ntohll (req->effective_since),
243 GNUNET_ntohll (req->group_generation));
245 if (ret != GNUNET_OK)
246 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
247 _("Failed to store membership information!\n"));
249 send_result_code (client, req->op_id, ret, NULL);
250 GNUNET_SERVICE_client_continue (client);
255 handle_client_membership_test (void *cls,
256 const struct MembershipTestRequest *req)
258 struct GNUNET_SERVICE_Client *client = cls;
260 int ret = db->membership_test (db->cls, &req->channel_key, &req->slave_key,
261 GNUNET_ntohll (req->message_id));
268 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
269 _("Failed to test membership!\n"));
272 send_result_code (client, req->op_id, ret, NULL);
273 GNUNET_SERVICE_client_continue (client);
278 check_client_fragment_store (void *cls,
279 const struct FragmentStoreRequest *req)
286 handle_client_fragment_store (void *cls,
287 const struct FragmentStoreRequest *req)
289 struct GNUNET_SERVICE_Client *client = cls;
291 const struct GNUNET_MessageHeader *
292 msg = GNUNET_MQ_extract_nested_mh (req);
294 || ntohs (msg->size) < sizeof (struct GNUNET_MULTICAST_MessageHeader))
297 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
298 _("Dropping invalid fragment\n"));
299 GNUNET_SERVICE_client_drop (client);
303 int ret = db->fragment_store (db->cls, &req->channel_key,
304 (const struct GNUNET_MULTICAST_MessageHeader *)
305 msg, ntohl (req->psycstore_flags));
307 if (ret != GNUNET_OK)
308 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
309 _("Failed to store fragment\n"));
311 send_result_code (client, req->op_id, ret, NULL);
312 GNUNET_SERVICE_client_continue (client);
317 handle_client_fragment_get (void *cls,
318 const struct FragmentGetRequest *req)
320 struct GNUNET_SERVICE_Client *client = cls;
323 sc = { .op_id = req->op_id,
325 .channel_key = req->channel_key,
326 .slave_key = req->slave_key,
327 .membership_test = req->do_membership_test };
330 uint64_t ret_frags = 0;
331 uint64_t first_fragment_id = GNUNET_ntohll (req->first_fragment_id);
332 uint64_t last_fragment_id = GNUNET_ntohll (req->last_fragment_id);
333 uint64_t limit = GNUNET_ntohll (req->fragment_limit);
336 ret = db->fragment_get (db->cls, &req->channel_key,
337 first_fragment_id, last_fragment_id,
338 &ret_frags, send_fragment, &sc);
340 ret = db->fragment_get_latest (db->cls, &req->channel_key, limit,
341 &ret_frags, send_fragment, &sc);
347 if (MEMBERSHIP_TEST_DONE == sc.membership_test)
349 switch (sc.membership_test_result)
355 ret = GNUNET_PSYCSTORE_MEMBERSHIP_TEST_FAILED;
365 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
366 _("Failed to get fragment!\n"));
368 send_result_code (client, req->op_id, (ret < 0) ? ret : ret_frags, NULL);
369 GNUNET_SERVICE_client_continue (client);
374 check_client_message_get (void *cls,
375 const struct MessageGetRequest *req)
382 handle_client_message_get (void *cls,
383 const struct MessageGetRequest *req)
385 struct GNUNET_SERVICE_Client *client = cls;
387 uint16_t size = ntohs (req->header.size);
388 const char *method_prefix = (const char *) &req[1];
390 if (size < sizeof (*req) + 1
391 || '\0' != method_prefix[size - sizeof (*req) - 1])
393 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
394 "Message get: invalid method prefix. size: %u < %u?\n",
396 (unsigned int) (sizeof (*req) + 1));
398 GNUNET_SERVICE_client_drop (client);
403 sc = { .op_id = req->op_id,
405 .channel_key = req->channel_key,
406 .slave_key = req->slave_key,
407 .membership_test = req->do_membership_test };
410 uint64_t ret_frags = 0;
411 uint64_t first_message_id = GNUNET_ntohll (req->first_message_id);
412 uint64_t last_message_id = GNUNET_ntohll (req->last_message_id);
413 uint64_t msg_limit = GNUNET_ntohll (req->message_limit);
414 uint64_t frag_limit = GNUNET_ntohll (req->fragment_limit);
416 /** @todo method_prefix */
418 ret = db->message_get (db->cls, &req->channel_key,
419 first_message_id, last_message_id, frag_limit,
420 &ret_frags, send_fragment, &sc);
422 ret = db->message_get_latest (db->cls, &req->channel_key, msg_limit,
423 &ret_frags, send_fragment, &sc);
431 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
432 _("Failed to get message!\n"));
435 send_result_code (client, req->op_id, (ret < 0) ? ret : ret_frags, NULL);
436 GNUNET_SERVICE_client_continue (client);
441 handle_client_message_get_fragment (void *cls,
442 const struct MessageGetFragmentRequest *req)
444 struct GNUNET_SERVICE_Client *client = cls;
447 sc = { .op_id = req->op_id, .client = client,
448 .channel_key = req->channel_key, .slave_key = req->slave_key,
449 .membership_test = req->do_membership_test };
451 int ret = db->message_get_fragment (db->cls, &req->channel_key,
452 GNUNET_ntohll (req->message_id),
453 GNUNET_ntohll (req->fragment_offset),
454 &send_fragment, &sc);
461 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
462 _("Failed to get message fragment!\n"));
465 send_result_code (client, req->op_id, ret, NULL);
466 GNUNET_SERVICE_client_continue (client);
471 handle_client_counters_get (void *cls,
472 const struct OperationRequest *req)
474 struct GNUNET_SERVICE_Client *client = cls;
476 struct CountersResult *res;
477 struct GNUNET_MQ_Envelope *
478 env = GNUNET_MQ_msg (res, GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS);
480 int ret = db->counters_message_get (db->cls, &req->channel_key,
481 &res->max_fragment_id, &res->max_message_id,
482 &res->max_group_generation);
486 ret = db->counters_state_get (db->cls, &req->channel_key,
487 &res->max_state_message_id);
491 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
492 _("Failed to get master counters!\n"));
495 res->result_code = htonl (ret);
496 res->op_id = req->op_id;
497 res->max_fragment_id = GNUNET_htonll (res->max_fragment_id);
498 res->max_message_id = GNUNET_htonll (res->max_message_id);
499 res->max_group_generation = GNUNET_htonll (res->max_group_generation);
500 res->max_state_message_id = GNUNET_htonll (res->max_state_message_id);
502 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
503 GNUNET_SERVICE_client_continue (client);
507 struct StateModifyClosure
509 const struct GNUNET_CRYPTO_EddsaPublicKey channel_key;
510 struct GNUNET_PSYC_ReceiveHandle *recv;
511 enum GNUNET_PSYC_MessageState msg_state;
515 uint32_t mod_value_size;
516 uint32_t mod_value_remaining;
521 recv_state_message_part (void *cls,
522 const struct GNUNET_PSYC_MessageHeader *msg,
523 const struct GNUNET_MessageHeader *pmsg)
525 struct StateModifyClosure *scls = cls;
529 { // FIXME: error on unknown message
533 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
534 "recv_state_message_part() message_id: %" PRIu64
535 ", fragment_offset: %" PRIu64 ", flags: %u\n",
536 GNUNET_ntohll (msg->message_id),
537 GNUNET_ntohll (msg->fragment_offset),
542 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_ERROR;
546 switch (ntohs (pmsg->type))
548 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD:
550 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_METHOD;
554 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER:
556 struct GNUNET_PSYC_MessageModifier *
557 pmod = (struct GNUNET_PSYC_MessageModifier *) pmsg;
558 psize = ntohs (pmod->header.size);
559 uint16_t name_size = ntohs (pmod->name_size);
560 uint32_t value_size = ntohl (pmod->value_size);
562 const char *name = (const char *) &pmod[1];
563 const void *value = name + name_size;
565 if (GNUNET_PSYC_OP_SET != pmod->oper)
566 { // Apply non-transient operation.
567 if (psize == sizeof (*pmod) + name_size + value_size)
569 db->state_modify_op (db->cls, &scls->channel_key,
570 pmod->oper, name, value, value_size);
574 scls->mod_oper = pmod->oper;
575 scls->mod_name = GNUNET_malloc (name_size);
576 GNUNET_memcpy (scls->mod_name, name, name_size);
578 scls->mod_value_size = value_size;
579 scls->mod_value = GNUNET_malloc (scls->mod_value_size);
580 scls->mod_value_remaining
581 = scls->mod_value_size - (psize - sizeof (*pmod) - name_size);
582 GNUNET_memcpy (scls->mod_value, value, value_size - scls->mod_value_remaining);
585 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_MODIFIER;
589 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT:
590 if (GNUNET_PSYC_OP_SET != scls->mod_oper)
592 if (scls->mod_value_remaining == 0)
595 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_ERROR;
597 psize = ntohs (pmsg->size);
598 GNUNET_memcpy (scls->mod_value + (scls->mod_value_size - scls->mod_value_remaining),
599 &pmsg[1], psize - sizeof (*pmsg));
600 scls->mod_value_remaining -= psize - sizeof (*pmsg);
601 if (0 == scls->mod_value_remaining)
603 db->state_modify_op (db->cls, &scls->channel_key,
604 scls->mod_oper, scls->mod_name,
605 scls->mod_value, scls->mod_value_size);
606 GNUNET_free (scls->mod_name);
607 GNUNET_free (scls->mod_value);
609 scls->mod_name = NULL;
610 scls->mod_value = NULL;
611 scls->mod_value_size = 0;
614 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_MOD_CONT;
617 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_DATA:
618 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_DATA;
621 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_END:
622 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_END;
626 scls->msg_state = GNUNET_PSYC_MESSAGE_STATE_ERROR;
632 recv_state_fragment (void *cls, struct GNUNET_MULTICAST_MessageHeader *msg,
633 enum GNUNET_PSYCSTORE_MessageFlags flags)
635 struct StateModifyClosure *scls = cls;
637 if (NULL == scls->recv)
639 scls->recv = GNUNET_PSYC_receive_create (NULL, recv_state_message_part,
643 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
644 "recv_state_fragment: %" PRIu64 "\n", GNUNET_ntohll (msg->fragment_id));
646 struct GNUNET_PSYC_MessageHeader *
647 pmsg = GNUNET_PSYC_message_header_create (msg, flags);
648 GNUNET_PSYC_receive_message (scls->recv, pmsg);
656 handle_client_state_modify (void *cls,
657 const struct StateModifyRequest *req)
659 struct GNUNET_SERVICE_Client *client = cls;
661 uint64_t message_id = GNUNET_ntohll (req->message_id);
662 uint64_t state_delta = GNUNET_ntohll (req->state_delta);
663 uint64_t ret_frags = 0;
664 struct StateModifyClosure
665 scls = { .channel_key = req->channel_key };
667 int ret = db->state_modify_begin (db->cls, &req->channel_key,
668 message_id, state_delta);
670 if (GNUNET_OK != ret)
672 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
673 _("Failed to begin modifying state: %d\n"), ret);
677 ret = db->message_get (db->cls, &req->channel_key,
678 message_id, message_id, 0,
679 &ret_frags, recv_state_fragment, &scls);
680 if (GNUNET_OK != ret)
682 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
683 _("Failed to modify state: %d\n"), ret);
688 if (GNUNET_OK != db->state_modify_end (db->cls, &req->channel_key, message_id))
690 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
691 _("Failed to end modifying state!\n"));
695 if (NULL != scls.recv)
697 GNUNET_PSYC_receive_destroy (scls.recv);
701 send_result_code (client, req->op_id, ret, NULL);
702 GNUNET_SERVICE_client_continue (client);
707 check_client_state_sync (void *cls,
708 const struct StateSyncRequest *req)
714 /** @todo FIXME: stop processing further state sync messages after an error */
716 handle_client_state_sync (void *cls,
717 const struct StateSyncRequest *req)
719 struct GNUNET_SERVICE_Client *client = cls;
721 int ret = GNUNET_SYSERR;
722 const char *name = (const char *) &req[1];
723 uint16_t name_size = ntohs (req->name_size);
725 if (name_size <= 2 || '\0' != name[name_size - 1])
727 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
728 _("Tried to set invalid state variable name!\n"));
735 if (req->flags & STATE_OP_FIRST)
737 ret = db->state_sync_begin (db->cls, &req->channel_key);
739 if (ret != GNUNET_OK)
741 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
742 _("Failed to begin synchronizing state!\n"));
746 ret = db->state_sync_assign (db->cls, &req->channel_key, name,
747 name + ntohs (req->name_size),
748 ntohs (req->header.size) - sizeof (*req)
749 - ntohs (req->name_size));
752 if (GNUNET_OK == ret && req->flags & STATE_OP_LAST)
754 ret = db->state_sync_end (db->cls, &req->channel_key,
755 GNUNET_ntohll (req->max_state_message_id),
756 GNUNET_ntohll (req->state_hash_message_id));
757 if (ret != GNUNET_OK)
758 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
759 _("Failed to end synchronizing state!\n"));
762 send_result_code (client, req->op_id, ret, NULL);
763 GNUNET_SERVICE_client_continue (client);
768 handle_client_state_reset (void *cls,
769 const struct OperationRequest *req)
771 struct GNUNET_SERVICE_Client *client = cls;
773 int ret = db->state_reset (db->cls, &req->channel_key);
775 if (ret != GNUNET_OK)
776 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
777 _("Failed to reset state!\n"));
779 send_result_code (client, req->op_id, ret, NULL);
780 GNUNET_SERVICE_client_continue (client);
785 handle_client_state_hash_update (void *cls,
786 const struct StateHashUpdateRequest *req)
788 struct GNUNET_SERVICE_Client *client = cls;
790 int ret = db->state_reset (db->cls, &req->channel_key);
791 if (ret != GNUNET_OK)
792 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
793 _("Failed to reset state!\n"));
795 send_result_code (client, req->op_id, ret, NULL);
796 GNUNET_SERVICE_client_continue (client);
801 check_client_state_get (void *cls,
802 const struct OperationRequest *req)
809 handle_client_state_get (void *cls,
810 const struct OperationRequest *req)
812 struct GNUNET_SERVICE_Client *client = cls;
814 struct SendClosure sc = { .op_id = req->op_id, .client = client };
815 int64_t ret = GNUNET_SYSERR;
816 const char *name = (const char *) &req[1];
817 uint16_t name_size = ntohs (req->header.size) - sizeof (*req);
819 if (name_size <= 2 || '\0' != name[name_size - 1])
821 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
822 _("Tried to get invalid state variable name!\n"));
827 ret = db->state_get (db->cls, &req->channel_key, name,
828 &send_state_var, &sc);
829 if (GNUNET_NO == ret && name_size >= 5) /* min: _a_b\0 */
831 char *p, *n = GNUNET_malloc (name_size);
832 GNUNET_memcpy (n, name, name_size);
833 while (&n[1] < (p = strrchr (n, '_')) && GNUNET_NO == ret)
836 ret = db->state_get (db->cls, &req->channel_key, n,
837 &send_state_var, &sc);
848 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
849 _("Failed to get state variable!\n"));
852 send_result_code (client, req->op_id, ret, NULL);
853 GNUNET_SERVICE_client_continue (client);
858 check_client_state_get_prefix (void *cls,
859 const struct OperationRequest *req)
866 handle_client_state_get_prefix (void *cls,
867 const struct OperationRequest *req)
869 struct GNUNET_SERVICE_Client *client = cls;
871 struct SendClosure sc = { .op_id = req->op_id, .client = client };
872 int64_t ret = GNUNET_SYSERR;
873 const char *name = (const char *) &req[1];
874 uint16_t name_size = ntohs (req->header.size) - sizeof (*req);
876 if (name_size <= 1 || '\0' != name[name_size - 1])
878 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
879 _("Tried to get invalid state variable name!\n"));
884 ret = db->state_get_prefix (db->cls, &req->channel_key, name,
885 &send_state_var, &sc);
893 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
894 _("Failed to get state variable!\n"));
897 send_result_code (client, req->op_id, ret, NULL);
898 GNUNET_SERVICE_client_continue (client);
903 * A new client connected.
906 * @param client client to add
907 * @param mq message queue for @a client
911 client_notify_connect (void *cls,
912 struct GNUNET_SERVICE_Client *client,
913 struct GNUNET_MQ_Handle *mq)
915 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client connected: %p\n", client);
922 * Called whenever a client is disconnected.
923 * Frees our resources associated with that client.
926 * @param client identification of the client
927 * @param app_ctx must match @a client
930 client_notify_disconnect (void *cls,
931 struct GNUNET_SERVICE_Client *client,
938 * Initialize the PSYCstore service.
940 * @param cls Closure.
941 * @param server The initialized server.
942 * @param c Configuration to use.
946 const struct GNUNET_CONFIGURATION_Handle *c,
947 struct GNUNET_SERVICE_Handle *svc)
952 /* Loading database plugin */
955 GNUNET_CONFIGURATION_get_value_string (cfg, "psycstore", "database",
958 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
964 GNUNET_asprintf (&db_lib_name,
965 "libgnunet_plugin_psycstore_%s",
967 db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg);
968 GNUNET_free (database);
972 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
973 "Could not load database backend `%s'\n",
975 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
979 stats = GNUNET_STATISTICS_create ("psycstore", cfg);
980 GNUNET_SCHEDULER_add_shutdown (shutdown_task,
985 * Define "main" method using service macro.
989 GNUNET_SERVICE_OPTION_NONE,
991 client_notify_connect,
992 client_notify_disconnect,
994 GNUNET_MQ_hd_fixed_size (client_membership_store,
995 GNUNET_MESSAGE_TYPE_PSYCSTORE_MEMBERSHIP_STORE,
996 struct MembershipStoreRequest,
998 GNUNET_MQ_hd_fixed_size (client_membership_test,
999 GNUNET_MESSAGE_TYPE_PSYCSTORE_MEMBERSHIP_TEST,
1000 struct MembershipTestRequest,
1002 GNUNET_MQ_hd_var_size (client_fragment_store,
1003 GNUNET_MESSAGE_TYPE_PSYCSTORE_FRAGMENT_STORE,
1004 struct FragmentStoreRequest,
1006 GNUNET_MQ_hd_fixed_size (client_fragment_get,
1007 GNUNET_MESSAGE_TYPE_PSYCSTORE_FRAGMENT_GET,
1008 struct FragmentGetRequest,
1010 GNUNET_MQ_hd_var_size (client_message_get,
1011 GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET,
1012 struct MessageGetRequest,
1014 GNUNET_MQ_hd_fixed_size (client_message_get_fragment,
1015 GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET_FRAGMENT,
1016 struct MessageGetFragmentRequest,
1018 GNUNET_MQ_hd_fixed_size (client_counters_get,
1019 GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET,
1020 struct OperationRequest,
1022 GNUNET_MQ_hd_fixed_size (client_state_modify,
1023 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_MODIFY,
1024 struct StateModifyRequest,
1026 GNUNET_MQ_hd_var_size (client_state_sync,
1027 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_SYNC,
1028 struct StateSyncRequest,
1030 GNUNET_MQ_hd_fixed_size (client_state_reset,
1031 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_RESET,
1032 struct OperationRequest,
1034 GNUNET_MQ_hd_fixed_size (client_state_hash_update,
1035 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_HASH_UPDATE,
1036 struct StateHashUpdateRequest,
1038 GNUNET_MQ_hd_var_size (client_state_get,
1039 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_GET,
1040 struct OperationRequest,
1042 GNUNET_MQ_hd_var_size (client_state_get_prefix,
1043 GNUNET_MESSAGE_TYPE_PSYCSTORE_STATE_GET_PREFIX,
1044 struct OperationRequest,
1047 /* end of gnunet-service-psycstore.c */