diff options
Diffstat (limited to 'src/secretsharing/secretsharing_api.c')
-rw-r--r-- | src/secretsharing/secretsharing_api.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/src/secretsharing/secretsharing_api.c b/src/secretsharing/secretsharing_api.c index 325e07f51..a44fa2a2f 100644 --- a/src/secretsharing/secretsharing_api.c +++ b/src/secretsharing/secretsharing_api.c | |||
@@ -25,8 +25,102 @@ | |||
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_secretsharing_service.h" | ||
29 | #include "secretsharing.h" | ||
28 | 30 | ||
29 | 31 | ||
30 | #define LOG(kind,...) GNUNET_log_from (kind, "secretsharing-api",__VA_ARGS__) | 32 | #define LOG(kind,...) GNUNET_log_from (kind, "secretsharing-api",__VA_ARGS__) |
31 | 33 | ||
32 | 34 | ||
35 | |||
36 | /** | ||
37 | * Session that will eventually establish a shared secred between | ||
38 | * the involved peers and allow encryption and cooperative decryption. | ||
39 | */ | ||
40 | struct GNUNET_SECRETSHARING_Session | ||
41 | { | ||
42 | /** | ||
43 | * Client connected to the secretsharing service. | ||
44 | */ | ||
45 | struct GNUNET_CLIENT_Connection *client; | ||
46 | |||
47 | /** | ||
48 | * Message queue for 'client'. | ||
49 | */ | ||
50 | struct GNUNET_MQ_Handle *mq; | ||
51 | |||
52 | /** | ||
53 | * Called when the secret sharing is done. | ||
54 | */ | ||
55 | GNUNET_SECRETSHARING_SecretReadyCallback secret_ready_cb; | ||
56 | |||
57 | /** | ||
58 | * Closure for 'secret_ready_cb'. | ||
59 | */ | ||
60 | void *secret_ready_cls; | ||
61 | }; | ||
62 | |||
63 | |||
64 | static void | ||
65 | handle_session_client_error (void *cls, enum GNUNET_MQ_Error error) | ||
66 | { | ||
67 | struct GNUNET_SECRETSHARING_Session *s = cls; | ||
68 | |||
69 | s->secret_ready_cb (s->secret_ready_cls, NULL, NULL, 0, NULL); | ||
70 | } | ||
71 | |||
72 | static void | ||
73 | handle_secret_ready (void *cls, const struct GNUNET_MessageHeader *msg) | ||
74 | { | ||
75 | struct GNUNET_SECRETSHARING_Session *s = cls; | ||
76 | const struct GNUNET_SECRETSHARING_SecretReadyMessage *m = (const void *) msg; | ||
77 | |||
78 | s->secret_ready_cb (s->secret_ready_cls, | ||
79 | NULL, | ||
80 | &m->public_key, | ||
81 | ntohs (m->num_secret_peers), | ||
82 | (struct GNUNET_PeerIdentity *) &m[1]); | ||
83 | |||
84 | } | ||
85 | |||
86 | |||
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, | ||
95 | void *cls) | ||
96 | { | ||
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 | ||
103 | }; | ||
104 | |||
105 | |||
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); | ||
111 | |||
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); | ||
115 | |||
116 | ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_GENERATE); | ||
117 | msg->threshold = htons (threshold); | ||
118 | GNUNET_MQ_send (s->mq, ev); | ||
119 | |||
120 | LOG (GNUNET_ERROR_TYPE_DEBUG, "secretsharing session created\n"); | ||
121 | return s; | ||
122 | |||
123 | } | ||
124 | |||
125 | |||
126 | |||