2 This file is part of GNUnet.
3 (C) 2012 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file secretsharing/secretsharing_api.c
24 * @author Florian Dold
27 #include "gnunet_util_lib.h"
28 #include "gnunet_secretsharing_service.h"
29 #include "secretsharing.h"
32 #define LOG(kind,...) GNUNET_log_from (kind, "secretsharing-api",__VA_ARGS__)
37 * Session that will eventually establish a shared secred between
38 * the involved peers and allow encryption and cooperative decryption.
40 struct GNUNET_SECRETSHARING_Session
43 * Client connected to the secretsharing service.
45 struct GNUNET_CLIENT_Connection *client;
48 * Message queue for 'client'.
50 struct GNUNET_MQ_Handle *mq;
53 * Called when the secret sharing is done.
55 GNUNET_SECRETSHARING_SecretReadyCallback secret_ready_cb;
58 * Closure for 'secret_ready_cb'.
60 void *secret_ready_cls;
65 handle_session_client_error (void *cls, enum GNUNET_MQ_Error error)
67 struct GNUNET_SECRETSHARING_Session *s = cls;
69 s->secret_ready_cb (s->secret_ready_cls, NULL, NULL, 0, NULL);
73 handle_secret_ready (void *cls, const struct GNUNET_MessageHeader *msg)
75 struct GNUNET_SECRETSHARING_Session *s = cls;
76 const struct GNUNET_SECRETSHARING_SecretReadyMessage *m = (const void *) msg;
78 s->secret_ready_cb (s->secret_ready_cls,
81 ntohs (m->num_secret_peers),
82 (struct GNUNET_PeerIdentity *) &m[1]);
87 struct GNUNET_SECRETSHARING_Session *
88 GNUNET_SECRETSHARING_create_session (const struct GNUNET_CONFIGURATION_Handle *cfg,
89 unsigned int num_peers,
90 const struct GNUNET_PeerIdentity *peers,
91 const struct GNUNET_HashCode *session_id,
92 struct GNUNET_TIME_Absolute deadline,
93 unsigned int threshold,
94 GNUNET_SECRETSHARING_SecretReadyCallback cb,
97 struct GNUNET_SECRETSHARING_Session *s;
98 struct GNUNET_MQ_Envelope *ev;
99 struct GNUNET_SECRETSHARING_CreateMessage *msg;
100 static const struct GNUNET_MQ_MessageHandler mq_handlers[] = {
101 {handle_secret_ready, GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_SECRET_READY, 0},
102 GNUNET_MQ_HANDLERS_END
106 s = GNUNET_new (struct GNUNET_SECRETSHARING_Session);
107 s->client = GNUNET_CLIENT_connect ("secretsharing", cfg);
108 s->secret_ready_cb = cb;
109 s->secret_ready_cls = cls;
110 GNUNET_assert (NULL != s->client);
112 s->mq = GNUNET_MQ_queue_for_connection_client (s->client, mq_handlers,
113 handle_session_client_error, s);
114 GNUNET_assert (NULL != s->mq);
116 ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_GENERATE);
117 msg->threshold = htons (threshold);
118 GNUNET_MQ_send (s->mq, ev);
120 LOG (GNUNET_ERROR_TYPE_DEBUG, "secretsharing session created\n");