aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2014-02-03 21:25:53 +0000
committerFlorian Dold <florian.dold@gmail.com>2014-02-03 21:25:53 +0000
commit8a3563b5c242b60aa4b7d2b9a3c3607ef8dcbadb (patch)
treef4b85c248403ba6783db017930b2258f3e61e18a /src
parent694581b42a78419c1c8ffc31ee873484ff93d79b (diff)
downloadgnunet-8a3563b5c242b60aa4b7d2b9a3c3607ef8dcbadb.tar.gz
gnunet-8a3563b5c242b60aa4b7d2b9a3c3607ef8dcbadb.zip
- consensus and secretsharing have both start time and deadline
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/consensus/consensus.h24
-rw-r--r--src/consensus/consensus_api.c13
-rw-r--r--src/consensus/gnunet-consensus-profiler.c17
-rw-r--r--src/consensus/gnunet-service-consensus.c14
-rw-r--r--src/include/gnunet_consensus_service.h8
-rw-r--r--src/include/gnunet_secretsharing_service.h5
-rw-r--r--src/secretsharing/gnunet-secretsharing-profiler.c36
-rw-r--r--src/secretsharing/gnunet-service-secretsharing.c46
-rw-r--r--src/secretsharing/secretsharing.h10
-rw-r--r--src/secretsharing/secretsharing_api.c4
11 files changed, 124 insertions, 55 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 9054c8793..fcb78c3be 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -6,7 +6,7 @@ if HAVE_TESTING
6 TESTING = testing 6 TESTING = testing
7 TESTBED = testbed 7 TESTBED = testbed
8 CONSENSUS = consensus 8 CONSENSUS = consensus
9# SECRETSHARING = secretsharing 9 SECRETSHARING = secretsharing
10 EXPERIMENTATION = experimentation 10 EXPERIMENTATION = experimentation
11# SCALARPRODUCT = scalarproduct 11# SCALARPRODUCT = scalarproduct
12endif 12endif
diff --git a/src/consensus/consensus.h b/src/consensus/consensus.h
index a752988fd..e8b5c6106 100644
--- a/src/consensus/consensus.h
+++ b/src/consensus/consensus.h
@@ -41,30 +41,28 @@ struct GNUNET_CONSENSUS_JoinMessage
41 */ 41 */
42 struct GNUNET_MessageHeader header; 42 struct GNUNET_MessageHeader header;
43 43
44 /**
45 * Number of peers (at the end of this message) that want to
46 * participate in the consensus.
47 */
44 uint32_t num_peers GNUNET_PACKED; 48 uint32_t num_peers GNUNET_PACKED;
45 49
46 struct GNUNET_HashCode session_id;
47
48 /* GNUNET_PeerIdentity[num_peers] */
49};
50
51
52struct GNUNET_CONSENSUS_ConcludeMessage
53{
54 /** 50 /**
55 * Type: GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE 51 * Session id of the consensus.
56 */ 52 */
57 struct GNUNET_MessageHeader header; 53 struct GNUNET_HashCode session_id;
58 54
59 /** 55 /**
60 * Padding, must be zero. 56 * Start time for the consensus.
61 */ 57 */
62 uint32_t reserved GNUNET_PACKED; 58 struct GNUNET_TIME_AbsoluteNBO start;
63 59
64 /** 60 /**
65 * Deadline for conclude 61 * Deadline for conclude.
66 */ 62 */
67 struct GNUNET_TIME_AbsoluteNBO deadline; 63 struct GNUNET_TIME_AbsoluteNBO deadline;
64
65 /* GNUNET_PeerIdentity[num_peers] */
68}; 66};
69 67
70 68
diff --git a/src/consensus/consensus_api.c b/src/consensus/consensus_api.c
index 14a1bf54e..5ebdf71e7 100644
--- a/src/consensus/consensus_api.c
+++ b/src/consensus/consensus_api.c
@@ -156,6 +156,9 @@ handle_conclude_done (void *cls,
156 * Inclusion of the local peer is optional. 156 * Inclusion of the local peer is optional.
157 * @param session_id session identifier 157 * @param session_id session identifier
158 * Allows a group of peers to have more than consensus session. 158 * Allows a group of peers to have more than consensus session.
159 * @param start start time of the consensus, conclude should be called before
160 * the start time.
161 * @param deadline time when the consensus should have concluded
159 * @param new_element_cb callback, called when a new element is added to the set by 162 * @param new_element_cb callback, called when a new element is added to the set by
160 * another peer 163 * another peer
161 * @param new_element_cls closure for new_element 164 * @param new_element_cls closure for new_element
@@ -166,6 +169,8 @@ GNUNET_CONSENSUS_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
166 unsigned int num_peers, 169 unsigned int num_peers,
167 const struct GNUNET_PeerIdentity *peers, 170 const struct GNUNET_PeerIdentity *peers,
168 const struct GNUNET_HashCode *session_id, 171 const struct GNUNET_HashCode *session_id,
172 struct GNUNET_TIME_Absolute start,
173 struct GNUNET_TIME_Absolute deadline,
169 GNUNET_CONSENSUS_ElementCallback new_element_cb, 174 GNUNET_CONSENSUS_ElementCallback new_element_cb,
170 void *new_element_cls) 175 void *new_element_cls)
171{ 176{
@@ -196,6 +201,8 @@ GNUNET_CONSENSUS_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
196 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_JOIN); 201 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_JOIN);
197 202
198 join_msg->session_id = consensus->session_id; 203 join_msg->session_id = consensus->session_id;
204 join_msg->start = GNUNET_TIME_absolute_hton (start);
205 join_msg->deadline = GNUNET_TIME_absolute_hton (deadline);
199 join_msg->num_peers = htonl (num_peers); 206 join_msg->num_peers = htonl (num_peers);
200 memcpy(&join_msg[1], 207 memcpy(&join_msg[1],
201 peers, 208 peers,
@@ -266,12 +273,10 @@ GNUNET_CONSENSUS_insert (struct GNUNET_CONSENSUS_Handle *consensus,
266 */ 273 */
267void 274void
268GNUNET_CONSENSUS_conclude (struct GNUNET_CONSENSUS_Handle *consensus, 275GNUNET_CONSENSUS_conclude (struct GNUNET_CONSENSUS_Handle *consensus,
269 struct GNUNET_TIME_Absolute deadline,
270 GNUNET_CONSENSUS_ConcludeCallback conclude, 276 GNUNET_CONSENSUS_ConcludeCallback conclude,
271 void *conclude_cls) 277 void *conclude_cls)
272{ 278{
273 struct GNUNET_MQ_Envelope *ev; 279 struct GNUNET_MQ_Envelope *ev;
274 struct GNUNET_CONSENSUS_ConcludeMessage *conclude_msg;
275 280
276 GNUNET_assert (NULL != conclude); 281 GNUNET_assert (NULL != conclude);
277 GNUNET_assert (NULL == consensus->conclude_cb); 282 GNUNET_assert (NULL == consensus->conclude_cb);
@@ -279,9 +284,7 @@ GNUNET_CONSENSUS_conclude (struct GNUNET_CONSENSUS_Handle *consensus,
279 consensus->conclude_cls = conclude_cls; 284 consensus->conclude_cls = conclude_cls;
280 consensus->conclude_cb = conclude; 285 consensus->conclude_cb = conclude;
281 286
282 ev = GNUNET_MQ_msg (conclude_msg, GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE); 287 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE);
283 conclude_msg->deadline = GNUNET_TIME_absolute_hton (deadline);
284
285 GNUNET_MQ_send (consensus->mq, ev); 288 GNUNET_MQ_send (consensus->mq, ev);
286} 289}
287 290
diff --git a/src/consensus/gnunet-consensus-profiler.c b/src/consensus/gnunet-consensus-profiler.c
index 272a675db..d7a14f68e 100644
--- a/src/consensus/gnunet-consensus-profiler.c
+++ b/src/consensus/gnunet-consensus-profiler.c
@@ -25,6 +25,7 @@
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_time_lib.h"
28#include "gnunet_consensus_service.h" 29#include "gnunet_consensus_service.h"
29#include "gnunet_testbed_service.h" 30#include "gnunet_testbed_service.h"
30 31
@@ -56,6 +57,16 @@ static unsigned *results_for_peer;
56 57
57static int verbose; 58static int verbose;
58 59
60/**
61 * Start time for all consensuses.
62 */
63static struct GNUNET_TIME_Absolute start;
64
65/**
66 * Deadline for all consensuses.
67 */
68static struct GNUNET_TIME_Absolute deadline;
69
59 70
60/** 71/**
61 * Signature of the event handler function called by the 72 * Signature of the event handler function called by the
@@ -172,7 +183,6 @@ do_consensus ()
172 183
173 for (i = 0; i < num_peers; i++) 184 for (i = 0; i < num_peers; i++)
174 GNUNET_CONSENSUS_conclude (consensus_handles[i], 185 GNUNET_CONSENSUS_conclude (consensus_handles[i],
175 GNUNET_TIME_relative_to_absolute (conclude_timeout),
176 conclude_cb, &consensus_handles[i]); 186 conclude_cb, &consensus_handles[i]);
177} 187}
178 188
@@ -259,6 +269,8 @@ connect_adapter (void *cls,
259 consensus = GNUNET_CONSENSUS_create (cfg, 269 consensus = GNUNET_CONSENSUS_create (cfg,
260 num_peers, peer_ids, 270 num_peers, peer_ids,
261 &session_id, 271 &session_id,
272 start,
273 deadline,
262 &new_element_cb, chp); 274 &new_element_cb, chp);
263 *chp = (struct GNUNET_CONSENSUS_Handle *) consensus; 275 *chp = (struct GNUNET_CONSENSUS_Handle *) consensus;
264 return consensus; 276 return consensus;
@@ -396,6 +408,9 @@ run (void *cls, char *const *args, const char *cfgfile,
396 return; 408 return;
397 } 409 }
398 410
411 start = GNUNET_TIME_absolute_get ();
412 deadline = GNUNET_TIME_absolute_add (start, conclude_timeout);
413
399 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 414 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
400 "running gnunet-consensus\n"); 415 "running gnunet-consensus\n");
401 416
diff --git a/src/consensus/gnunet-service-consensus.c b/src/consensus/gnunet-service-consensus.c
index 688190c14..ffd9786d3 100644
--- a/src/consensus/gnunet-service-consensus.c
+++ b/src/consensus/gnunet-service-consensus.c
@@ -142,6 +142,11 @@ struct ConsensusSession
142 struct GNUNET_MQ_Handle *client_mq; 142 struct GNUNET_MQ_Handle *client_mq;
143 143
144 /** 144 /**
145 * Time when the conclusion of the consensus should begin.
146 */
147 struct GNUNET_TIME_Absolute conclude_start;
148
149 /**
145 * Timeout for all rounds together, single rounds will schedule a timeout task 150 * Timeout for all rounds together, single rounds will schedule a timeout task
146 * with a fraction of the conclude timeout. 151 * with a fraction of the conclude timeout.
147 * Only valid once the current round is not CONSENSUS_ROUND_BEGIN. 152 * Only valid once the current round is not CONSENSUS_ROUND_BEGIN.
@@ -1039,6 +1044,9 @@ initialize_session (struct ConsensusSession *session,
1039 other_session = other_session->next; 1044 other_session = other_session->next;
1040 } 1045 }
1041 1046
1047 session->conclude_deadline = GNUNET_TIME_absolute_ntoh (join_msg->deadline);
1048 session->conclude_start = GNUNET_TIME_absolute_ntoh (join_msg->start);
1049
1042 session->local_peer_idx = get_peer_idx (&my_peer, session); 1050 session->local_peer_idx = get_peer_idx (&my_peer, session);
1043 GNUNET_assert (-1 != session->local_peer_idx); 1051 GNUNET_assert (-1 != session->local_peer_idx);
1044 session->element_set = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION); 1052 session->element_set = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION);
@@ -1168,11 +1176,8 @@ client_conclude (void *cls,
1168 const struct GNUNET_MessageHeader *message) 1176 const struct GNUNET_MessageHeader *message)
1169{ 1177{
1170 struct ConsensusSession *session; 1178 struct ConsensusSession *session;
1171 struct GNUNET_CONSENSUS_ConcludeMessage *cmsg;
1172
1173 1179
1174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "conclude requested\n"); 1180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "conclude requested\n");
1175 cmsg = (struct GNUNET_CONSENSUS_ConcludeMessage *) message;
1176 session = get_session_by_client (client); 1181 session = get_session_by_client (client);
1177 if (NULL == session) 1182 if (NULL == session)
1178 { 1183 {
@@ -1194,7 +1199,6 @@ client_conclude (void *cls,
1194 } 1199 }
1195 else 1200 else
1196 { 1201 {
1197 session->conclude_deadline = GNUNET_TIME_absolute_ntoh (cmsg->deadline);
1198 /* the 'begin' round is over, start with the next, actual round */ 1202 /* the 'begin' round is over, start with the next, actual round */
1199 round_over (session, NULL); 1203 round_over (session, NULL);
1200 } 1204 }
@@ -1257,7 +1261,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1257{ 1261{
1258 static const struct GNUNET_SERVER_MessageHandler server_handlers[] = { 1262 static const struct GNUNET_SERVER_MessageHandler server_handlers[] = {
1259 {&client_conclude, NULL, GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE, 1263 {&client_conclude, NULL, GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE,
1260 sizeof (struct GNUNET_CONSENSUS_ConcludeMessage)}, 1264 sizeof (struct GNUNET_MessageHeader)},
1261 {&client_insert, NULL, GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_INSERT, 0}, 1265 {&client_insert, NULL, GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_INSERT, 0},
1262 {&client_join, NULL, GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_JOIN, 0}, 1266 {&client_join, NULL, GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_JOIN, 0},
1263 {NULL, NULL, 0, 0} 1267 {NULL, NULL, 0, 0}
diff --git a/src/include/gnunet_consensus_service.h b/src/include/gnunet_consensus_service.h
index 3b08b2dee..ef799773f 100644
--- a/src/include/gnunet_consensus_service.h
+++ b/src/include/gnunet_consensus_service.h
@@ -72,6 +72,9 @@ struct GNUNET_CONSENSUS_Handle;
72 * Inclusion of the local peer is optional. 72 * Inclusion of the local peer is optional.
73 * @param session_id session identifier 73 * @param session_id session identifier
74 * Allows a group of peers to have more than consensus session. 74 * Allows a group of peers to have more than consensus session.
75 * @param start start time of the consensus, conclude should be called before
76 * the start time.
77 * @param deadline time when the consensus should have concluded
75 * @param new_element_cb callback, called when a new element is added to the set by 78 * @param new_element_cb callback, called when a new element is added to the set by
76 * another peer. Also called when an error occurs. 79 * another peer. Also called when an error occurs.
77 * @param new_element_cls closure for new_element 80 * @param new_element_cls closure for new_element
@@ -82,6 +85,8 @@ GNUNET_CONSENSUS_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
82 unsigned int num_peers, 85 unsigned int num_peers,
83 const struct GNUNET_PeerIdentity *peers, 86 const struct GNUNET_PeerIdentity *peers,
84 const struct GNUNET_HashCode *session_id, 87 const struct GNUNET_HashCode *session_id,
88 struct GNUNET_TIME_Absolute start,
89 struct GNUNET_TIME_Absolute deadline,
85 GNUNET_CONSENSUS_ElementCallback new_element_cb, 90 GNUNET_CONSENSUS_ElementCallback new_element_cb,
86 void *new_element_cls); 91 void *new_element_cls);
87 92
@@ -135,14 +140,11 @@ typedef void (*GNUNET_CONSENSUS_ConcludeCallback) (void *cls);
135 * try to conclude the consensus within a given time window. 140 * try to conclude the consensus within a given time window.
136 * 141 *
137 * @param consensus consensus session 142 * @param consensus consensus session
138 * @param deadline deadline after which the conculde callback
139 * whill be called
140 * @param conclude called when the conclusion was successful 143 * @param conclude called when the conclusion was successful
141 * @param conclude_cls closure for the conclude callback 144 * @param conclude_cls closure for the conclude callback
142 */ 145 */
143void 146void
144GNUNET_CONSENSUS_conclude (struct GNUNET_CONSENSUS_Handle *consensus, 147GNUNET_CONSENSUS_conclude (struct GNUNET_CONSENSUS_Handle *consensus,
145 struct GNUNET_TIME_Absolute deadline,
146 GNUNET_CONSENSUS_ConcludeCallback conclude, 148 GNUNET_CONSENSUS_ConcludeCallback conclude,
147 void *conclude_cls); 149 void *conclude_cls);
148 150
diff --git a/src/include/gnunet_secretsharing_service.h b/src/include/gnunet_secretsharing_service.h
index 1524c79fe..3673ca0fe 100644
--- a/src/include/gnunet_secretsharing_service.h
+++ b/src/include/gnunet_secretsharing_service.h
@@ -190,6 +190,8 @@ typedef void (*GNUNET_SECRETSHARING_DecryptCallback) (void *cls,
190 * @param num_peers number of peers in 'peers' 190 * @param num_peers number of peers in 'peers'
191 * @param peers array of peers that we will share secrets with, can optionally contain the local peer 191 * @param peers array of peers that we will share secrets with, can optionally contain the local peer
192 * @param session_id unique session id 192 * @param session_id unique session id
193 * @param start When should all peers be available for sharing the secret?
194 * Random number generation can take place before the start time.
193 * @param deadline point in time where the session must be established; taken as hint 195 * @param deadline point in time where the session must be established; taken as hint
194 * by underlying consensus sessions 196 * by underlying consensus sessions
195 * @param threshold minimum number of peers that must cooperate to decrypt a value 197 * @param threshold minimum number of peers that must cooperate to decrypt a value
@@ -201,6 +203,7 @@ GNUNET_SECRETSHARING_create_session (const struct GNUNET_CONFIGURATION_Handle *c
201 unsigned int num_peers, 203 unsigned int num_peers,
202 const struct GNUNET_PeerIdentity *peers, 204 const struct GNUNET_PeerIdentity *peers,
203 const struct GNUNET_HashCode *session_id, 205 const struct GNUNET_HashCode *session_id,
206 struct GNUNET_TIME_Absolute start,
204 struct GNUNET_TIME_Absolute deadline, 207 struct GNUNET_TIME_Absolute deadline,
205 unsigned int threshold, 208 unsigned int threshold,
206 GNUNET_SECRETSHARING_SecretReadyCallback cb, 209 GNUNET_SECRETSHARING_SecretReadyCallback cb,
@@ -247,6 +250,7 @@ GNUNET_SECRETSHARING_encrypt (const struct GNUNET_SECRETSHARING_PublicKey *publi
247 * @param share our secret share to use for decryption 250 * @param share our secret share to use for decryption
248 * @param ciphertext ciphertext to publish in order to decrypt it (if enough peers agree) 251 * @param ciphertext ciphertext to publish in order to decrypt it (if enough peers agree)
249 * @param decrypt_cb callback called once the decryption succeeded 252 * @param decrypt_cb callback called once the decryption succeeded
253 * @param start By when should the cooperation for decryption start?
250 * @param deadline By when should the decryption be finished? 254 * @param deadline By when should the decryption be finished?
251 * @param decrypt_cb_cls closure for @a decrypt_cb 255 * @param decrypt_cb_cls closure for @a decrypt_cb
252 * @return handle to cancel the operation 256 * @return handle to cancel the operation
@@ -255,6 +259,7 @@ struct GNUNET_SECRETSHARING_DecryptionHandle *
255GNUNET_SECRETSHARING_decrypt (const struct GNUNET_CONFIGURATION_Handle *cfg, 259GNUNET_SECRETSHARING_decrypt (const struct GNUNET_CONFIGURATION_Handle *cfg,
256 struct GNUNET_SECRETSHARING_Share *share, 260 struct GNUNET_SECRETSHARING_Share *share,
257 const struct GNUNET_SECRETSHARING_Ciphertext *ciphertext, 261 const struct GNUNET_SECRETSHARING_Ciphertext *ciphertext,
262 struct GNUNET_TIME_Absolute start,
258 struct GNUNET_TIME_Absolute deadline, 263 struct GNUNET_TIME_Absolute deadline,
259 GNUNET_SECRETSHARING_DecryptCallback decrypt_cb, 264 GNUNET_SECRETSHARING_DecryptCallback decrypt_cb,
260 void *decrypt_cb_cls); 265 void *decrypt_cb_cls);
diff --git a/src/secretsharing/gnunet-secretsharing-profiler.c b/src/secretsharing/gnunet-secretsharing-profiler.c
index b718e8a27..712203c33 100644
--- a/src/secretsharing/gnunet-secretsharing-profiler.c
+++ b/src/secretsharing/gnunet-secretsharing-profiler.c
@@ -49,6 +49,11 @@ static unsigned int decrypt = GNUNET_NO;
49static struct GNUNET_TIME_Relative timeout; 49static struct GNUNET_TIME_Relative timeout;
50 50
51/** 51/**
52 * When should dkg communication start?
53 */
54static struct GNUNET_TIME_Relative delay;
55
56/**
52 * Handles for secretsharing sessions. 57 * Handles for secretsharing sessions.
53 */ 58 */
54static struct GNUNET_SECRETSHARING_Session **session_handles; 59static struct GNUNET_SECRETSHARING_Session **session_handles;
@@ -85,9 +90,18 @@ static struct GNUNET_HashCode session_id;
85 90
86static int verbose; 91static int verbose;
87 92
88struct GNUNET_SECRETSHARING_Plaintext reference_plaintext; 93static struct GNUNET_SECRETSHARING_Plaintext reference_plaintext;
94
95static struct GNUNET_SECRETSHARING_Ciphertext ciphertext;
96
97static struct GNUNET_TIME_Absolute dkg_start;
98
99static struct GNUNET_TIME_Absolute dkg_deadline;
89 100
90struct GNUNET_SECRETSHARING_Ciphertext ciphertext; 101
102static struct GNUNET_TIME_Absolute decrypt_start;
103
104static struct GNUNET_TIME_Absolute decrypt_deadline;
91 105
92 106
93/** 107/**
@@ -236,7 +250,7 @@ decrypt_connect_adapter (void *cls,
236 "decrypt connect adapter, %d peers\n", 250 "decrypt connect adapter, %d peers\n",
237 num_peers); 251 num_peers);
238 *hp = GNUNET_SECRETSHARING_decrypt (cfg, shares[n], &ciphertext, 252 *hp = GNUNET_SECRETSHARING_decrypt (cfg, shares[n], &ciphertext,
239 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES), 253 decrypt_start, decrypt_deadline,
240 decrypt_cb, 254 decrypt_cb,
241 hp); 255 hp);
242 256
@@ -315,6 +329,10 @@ secret_ready_cb (void *cls,
315 return; 329 return;
316 } 330 }
317 331
332 decrypt_start = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay);
333 decrypt_deadline = GNUNET_TIME_absolute_add (decrypt_start, timeout);
334
335
318 // compute g^42 336 // compute g^42
319 GNUNET_SECRETSHARING_plaintext_generate_i (&reference_plaintext, 42); 337 GNUNET_SECRETSHARING_plaintext_generate_i (&reference_plaintext, 42);
320 GNUNET_SECRETSHARING_encrypt (&common_pubkey, &reference_plaintext, &ciphertext); 338 GNUNET_SECRETSHARING_encrypt (&common_pubkey, &reference_plaintext, &ciphertext);
@@ -350,7 +368,8 @@ session_connect_adapter (void *cls,
350 num_peers, 368 num_peers,
351 peer_ids, 369 peer_ids,
352 &session_id, 370 &session_id,
353 GNUNET_TIME_relative_to_absolute (timeout), 371 dkg_start,
372 dkg_deadline,
354 threshold, 373 threshold,
355 &secret_ready_cb, sp); 374 &secret_ready_cb, sp);
356 return *sp; 375 return *sp;
@@ -471,6 +490,9 @@ run (void *cls, char *const *args, const char *cfgfile,
471 char *topology; 490 char *topology;
472 int topology_cmp_result; 491 int topology_cmp_result;
473 492
493 dkg_start = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay);
494 dkg_deadline = GNUNET_TIME_absolute_add (dkg_start, timeout);
495
474 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "testbed", "OVERLAY_TOPOLOGY", &topology)) 496 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "testbed", "OVERLAY_TOPOLOGY", &topology))
475 { 497 {
476 fprintf (stderr, 498 fprintf (stderr,
@@ -513,6 +535,9 @@ main (int argc, char **argv)
513 { 'n', "num-peers", NULL, 535 { 'n', "num-peers", NULL,
514 gettext_noop ("number of peers in consensus"), 536 gettext_noop ("number of peers in consensus"),
515 GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_peers }, 537 GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_peers },
538 { 'D', "delay", NULL,
539 gettext_noop ("dkg start delay"),
540 GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &delay },
516 { 't', "timeout", NULL, 541 { 't', "timeout", NULL,
517 gettext_noop ("dkg timeout"), 542 gettext_noop ("dkg timeout"),
518 GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &timeout }, 543 GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &timeout },
@@ -527,7 +552,8 @@ main (int argc, char **argv)
527 GNUNET_NO, &GNUNET_GETOPT_set_one, &verbose }, 552 GNUNET_NO, &GNUNET_GETOPT_set_one, &verbose },
528 GNUNET_GETOPT_OPTION_END 553 GNUNET_GETOPT_OPTION_END
529 }; 554 };
530 timeout = GNUNET_TIME_UNIT_SECONDS; 555 delay = GNUNET_TIME_UNIT_ZERO;
556 timeout = GNUNET_TIME_UNIT_MINUTES;
531 GNUNET_PROGRAM_run2 (argc, argv, "gnunet-secretsharing-profiler", 557 GNUNET_PROGRAM_run2 (argc, argv, "gnunet-secretsharing-profiler",
532 "help", 558 "help",
533 options, &run, NULL, GNUNET_YES); 559 options, &run, NULL, GNUNET_YES);
diff --git a/src/secretsharing/gnunet-service-secretsharing.c b/src/secretsharing/gnunet-service-secretsharing.c
index 4af5124ca..9c8c44264 100644
--- a/src/secretsharing/gnunet-service-secretsharing.c
+++ b/src/secretsharing/gnunet-service-secretsharing.c
@@ -238,6 +238,11 @@ struct DecryptSession
238 struct GNUNET_MQ_Handle *client_mq; 238 struct GNUNET_MQ_Handle *client_mq;
239 239
240 /** 240 /**
241 * When should we start communicating for decryption?
242 */
243 struct GNUNET_TIME_Absolute start;
244
245 /**
241 * When would we like the ciphertext to be 246 * When would we like the ciphertext to be
242 * decrypted? 247 * decrypted?
243 */ 248 */
@@ -814,8 +819,8 @@ insert_round2_element (struct KeygenSession *ks)
814 819
815 element_size = (sizeof (struct GNUNET_SECRETSHARING_KeygenRevealData) + 820 element_size = (sizeof (struct GNUNET_SECRETSHARING_KeygenRevealData) +
816 GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->num_peers + 821 GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->num_peers +
817 GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->threshold + 822 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * ks->num_peers +
818 GNUNET_CRYPTO_PAILLIER_BITS * 2 / 8 * ks->num_peers); 823 GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->threshold);
819 824
820 element = GNUNET_malloc (sizeof (struct GNUNET_SET_Element) + element_size); 825 element = GNUNET_malloc (sizeof (struct GNUNET_SET_Element) + element_size);
821 element->size = element_size; 826 element->size = element_size;
@@ -857,13 +862,11 @@ insert_round2_element (struct KeygenSession *ks)
857 memset (ciphertext, 0, sizeof *ciphertext); 862 memset (ciphertext, 0, sizeof *ciphertext);
858 if (GNUNET_YES == ks->info[i].round1_valid) 863 if (GNUNET_YES == ks->info[i].round1_valid)
859 { 864 {
860 struct GNUNET_CRYPTO_PaillierPlaintext plaintext;
861 gcry_mpi_set_ui (idx, i + 1); 865 gcry_mpi_set_ui (idx, i + 1);
862 // evaluate the polynomial 866 // evaluate the polynomial
863 horner_eval (v, ks->presecret_polynomial, ks->threshold, idx, elgamal_q); 867 horner_eval (v, ks->presecret_polynomial, ks->threshold, idx, elgamal_q);
864 GNUNET_CRYPTO_mpi_print_unsigned (&plaintext, sizeof plaintext, v);
865 // encrypt the result 868 // encrypt the result
866 GNUNET_CRYPTO_paillier_encrypt (&ks->info[i].paillier_public_key, &plaintext, ciphertext); 869 GNUNET_CRYPTO_paillier_encrypt (&ks->info[i].paillier_public_key, v, ciphertext);
867 } 870 }
868 pos += sizeof *ciphertext; 871 pos += sizeof *ciphertext;
869 } 872 }
@@ -904,7 +907,6 @@ keygen_round2_new_element (void *cls,
904 const struct GNUNET_SECRETSHARING_KeygenRevealData *d; 907 const struct GNUNET_SECRETSHARING_KeygenRevealData *d;
905 struct KeygenPeerInfo *info; 908 struct KeygenPeerInfo *info;
906 unsigned char *pos; 909 unsigned char *pos;
907 struct GNUNET_CRYPTO_PaillierPlaintext plaintext;
908 size_t expected_element_size; 910 size_t expected_element_size;
909 911
910 if (NULL == element) 912 if (NULL == element)
@@ -915,7 +917,7 @@ keygen_round2_new_element (void *cls,
915 917
916 expected_element_size = (sizeof (struct GNUNET_SECRETSHARING_KeygenRevealData) + 918 expected_element_size = (sizeof (struct GNUNET_SECRETSHARING_KeygenRevealData) +
917 GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->num_peers + 919 GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->num_peers +
918 GNUNET_CRYPTO_PAILLIER_BITS / 8 * 2 * ks->num_peers + 920 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * ks->num_peers +
919 GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->threshold); 921 GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->threshold);
920 922
921 if (element->size != expected_element_size) 923 if (element->size != expected_element_size)
@@ -960,7 +962,7 @@ keygen_round2_new_element (void *cls,
960 // skip exponentiated pre-shares 962 // skip exponentiated pre-shares
961 pos += GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->num_peers; 963 pos += GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->num_peers;
962 // skip encrypted pre-shares 964 // skip encrypted pre-shares
963 pos += GNUNET_CRYPTO_PAILLIER_BITS * 2 / 8 * ks->num_peers; 965 pos += sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * ks->num_peers;
964 // the first exponentiated coefficient is the public key share 966 // the first exponentiated coefficient is the public key share
965 GNUNET_CRYPTO_mpi_scan_unsigned (&info->public_key_share, pos, GNUNET_SECRETSHARING_ELGAMAL_BITS / 8); 967 GNUNET_CRYPTO_mpi_scan_unsigned (&info->public_key_share, pos, GNUNET_SECRETSHARING_ELGAMAL_BITS / 8);
966 968
@@ -968,12 +970,11 @@ keygen_round2_new_element (void *cls,
968 // skip exp. pre-shares 970 // skip exp. pre-shares
969 pos += GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->num_peers; 971 pos += GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->num_peers;
970 // skip to the encrypted value for our peer 972 // skip to the encrypted value for our peer
971 pos += GNUNET_CRYPTO_PAILLIER_BITS * 2 / 8 * ks->local_peer_idx; 973 pos += sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * ks->local_peer_idx;
972 974
975 GNUNET_assert (NULL != (info->decrypted_preshare = gcry_mpi_new (0)));
973 GNUNET_CRYPTO_paillier_decrypt (&ks->paillier_private_key, &ks->info[ks->local_peer_idx].paillier_public_key, 976 GNUNET_CRYPTO_paillier_decrypt (&ks->paillier_private_key, &ks->info[ks->local_peer_idx].paillier_public_key,
974 (struct GNUNET_CRYPTO_PaillierCiphertext *) pos, &plaintext); 977 (struct GNUNET_CRYPTO_PaillierCiphertext *) pos, info->decrypted_preshare);
975 GNUNET_CRYPTO_mpi_scan_unsigned (&info->decrypted_preshare, &plaintext,
976 sizeof plaintext);
977 978
978 // TODO: validate zero knowledge proofs 979 // TODO: validate zero knowledge proofs
979 980
@@ -1009,13 +1010,13 @@ keygen_round1_conclude (void *cls)
1009 GNUNET_CONSENSUS_destroy (ks->consensus); 1010 GNUNET_CONSENSUS_destroy (ks->consensus);
1010 1011
1011 ks->consensus = GNUNET_CONSENSUS_create (cfg, ks->num_peers, ks->peers, &ks->session_id, 1012 ks->consensus = GNUNET_CONSENSUS_create (cfg, ks->num_peers, ks->peers, &ks->session_id,
1013 time_between (ks->start_time, ks->deadline, 1, 2),
1014 ks->deadline,
1012 keygen_round2_new_element, ks); 1015 keygen_round2_new_element, ks);
1013 1016
1014 insert_round2_element (ks); 1017 insert_round2_element (ks);
1015 1018
1016 GNUNET_CONSENSUS_conclude (ks->consensus, 1019 GNUNET_CONSENSUS_conclude (ks->consensus,
1017 /* last round, thus conclude at DKG deadline */
1018 ks->deadline,
1019 keygen_round2_conclude, 1020 keygen_round2_conclude,
1020 ks); 1021 ks);
1021} 1022}
@@ -1104,6 +1105,8 @@ static void handle_client_keygen (void *cls,
1104 1105
1105 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "first round of consensus with %u peers\n", ks->num_peers); 1106 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "first round of consensus with %u peers\n", ks->num_peers);
1106 ks->consensus = GNUNET_CONSENSUS_create (cfg, ks->num_peers, ks->peers, &msg->session_id, 1107 ks->consensus = GNUNET_CONSENSUS_create (cfg, ks->num_peers, ks->peers, &msg->session_id,
1108 GNUNET_TIME_absolute_ntoh (msg->start),
1109 GNUNET_TIME_absolute_ntoh (msg->deadline),
1107 keygen_round1_new_element, ks); 1110 keygen_round1_new_element, ks);
1108 1111
1109 ks->info = GNUNET_new_array (ks->num_peers, struct KeygenPeerInfo); 1112 ks->info = GNUNET_new_array (ks->num_peers, struct KeygenPeerInfo);
@@ -1125,8 +1128,6 @@ static void handle_client_keygen (void *cls,
1125 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: Concluding for round 1\n", ks->local_peer_idx); 1128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: Concluding for round 1\n", ks->local_peer_idx);
1126 1129
1127 GNUNET_CONSENSUS_conclude (ks->consensus, 1130 GNUNET_CONSENSUS_conclude (ks->consensus,
1128 /* half the overall time */
1129 time_between (ks->start_time, ks->deadline, 1, 2),
1130 keygen_round1_conclude, 1131 keygen_round1_conclude,
1131 ks); 1132 ks);
1132 1133
@@ -1259,6 +1260,9 @@ insert_decrypt_element (struct DecryptSession *ds)
1259 gcry_mpi_t x; 1260 gcry_mpi_t x;
1260 gcry_mpi_t s; 1261 gcry_mpi_t s;
1261 1262
1263 /* make vagrind happy until we implement the real deal ... */
1264 memset (&d, 0, sizeof d);
1265
1262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: Inserting decrypt element\n", 1266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: Inserting decrypt element\n",
1263 ds->share->my_peer); 1267 ds->share->my_peer);
1264 1268
@@ -1273,11 +1277,6 @@ insert_decrypt_element (struct DecryptSession *ds)
1273 element.size = sizeof (struct GNUNET_SECRETSHARING_DecryptData); 1277 element.size = sizeof (struct GNUNET_SECRETSHARING_DecryptData);
1274 element.type = 0; 1278 element.type = 0;
1275 1279
1276 /* make vagrind happy until we implement the real deal ... */
1277 memset (&d.nizk_commit1, 0, sizeof d.nizk_commit1);
1278 memset (&d.nizk_commit2, 0, sizeof d.nizk_commit2);
1279 memset (&d.nizk_response, 0, sizeof d.nizk_response);
1280
1281 d.ciphertext = ds->ciphertext; 1280 d.ciphertext = ds->ciphertext;
1282 d.peer = my_peer; 1281 d.peer = my_peer;
1283 d.purpose.size = htonl (element.size - offsetof (struct GNUNET_SECRETSHARING_DecryptData, purpose)); 1282 d.purpose.size = htonl (element.size - offsetof (struct GNUNET_SECRETSHARING_DecryptData, purpose));
@@ -1317,6 +1316,7 @@ static void handle_client_decrypt (void *cls,
1317 GNUNET_CONTAINER_DLL_insert (decrypt_sessions_head, decrypt_sessions_tail, ds); 1316 GNUNET_CONTAINER_DLL_insert (decrypt_sessions_head, decrypt_sessions_tail, ds);
1318 ds->client = client; 1317 ds->client = client;
1319 ds->client_mq = GNUNET_MQ_queue_for_server_client (client); 1318 ds->client_mq = GNUNET_MQ_queue_for_server_client (client);
1319 ds->start = GNUNET_TIME_absolute_ntoh (msg->start);
1320 ds->deadline = GNUNET_TIME_absolute_ntoh (msg->deadline); 1320 ds->deadline = GNUNET_TIME_absolute_ntoh (msg->deadline);
1321 ds->ciphertext = msg->ciphertext; 1321 ds->ciphertext = msg->ciphertext;
1322 1322
@@ -1331,6 +1331,8 @@ static void handle_client_decrypt (void *cls,
1331 ds->share->num_peers, 1331 ds->share->num_peers,
1332 ds->share->peers, 1332 ds->share->peers,
1333 &session_id, 1333 &session_id,
1334 ds->start,
1335 ds->deadline,
1334 &decrypt_new_element, 1336 &decrypt_new_element,
1335 ds); 1337 ds);
1336 1338
@@ -1344,7 +1346,7 @@ static void handle_client_decrypt (void *cls,
1344 1346
1345 insert_decrypt_element (ds); 1347 insert_decrypt_element (ds);
1346 1348
1347 GNUNET_CONSENSUS_conclude (ds->consensus, ds->deadline, decrypt_conclude, ds); 1349 GNUNET_CONSENSUS_conclude (ds->consensus, decrypt_conclude, ds);
1348 1350
1349 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1351 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1350 1352
diff --git a/src/secretsharing/secretsharing.h b/src/secretsharing/secretsharing.h
index e94ff46b7..796feabae 100644
--- a/src/secretsharing/secretsharing.h
+++ b/src/secretsharing/secretsharing.h
@@ -57,6 +57,11 @@ struct GNUNET_SECRETSHARING_CreateMessage
57 struct GNUNET_HashCode session_id GNUNET_PACKED; 57 struct GNUNET_HashCode session_id GNUNET_PACKED;
58 58
59 /** 59 /**
60 * Start time for communication with the other peers.
61 */
62 struct GNUNET_TIME_AbsoluteNBO start;
63
64 /**
60 * Deadline for the establishment of the crypto system. 65 * Deadline for the establishment of the crypto system.
61 */ 66 */
62 struct GNUNET_TIME_AbsoluteNBO deadline; 67 struct GNUNET_TIME_AbsoluteNBO deadline;
@@ -131,6 +136,11 @@ struct GNUNET_SECRETSHARING_DecryptRequestMessage
131 struct GNUNET_MessageHeader header; 136 struct GNUNET_MessageHeader header;
132 137
133 /** 138 /**
139 * Until when should the decryption start?
140 */
141 struct GNUNET_TIME_AbsoluteNBO start;
142
143 /**
134 * Until when should the decryption be finished? 144 * Until when should the decryption be finished?
135 */ 145 */
136 struct GNUNET_TIME_AbsoluteNBO deadline; 146 struct GNUNET_TIME_AbsoluteNBO deadline;
diff --git a/src/secretsharing/secretsharing_api.c b/src/secretsharing/secretsharing_api.c
index 1489a5c45..d46d24e9d 100644
--- a/src/secretsharing/secretsharing_api.c
+++ b/src/secretsharing/secretsharing_api.c
@@ -174,6 +174,7 @@ GNUNET_SECRETSHARING_create_session (const struct GNUNET_CONFIGURATION_Handle *c
174 unsigned int num_peers, 174 unsigned int num_peers,
175 const struct GNUNET_PeerIdentity *peers, 175 const struct GNUNET_PeerIdentity *peers,
176 const struct GNUNET_HashCode *session_id, 176 const struct GNUNET_HashCode *session_id,
177 struct GNUNET_TIME_Absolute start,
177 struct GNUNET_TIME_Absolute deadline, 178 struct GNUNET_TIME_Absolute deadline,
178 unsigned int threshold, 179 unsigned int threshold,
179 GNUNET_SECRETSHARING_SecretReadyCallback cb, 180 GNUNET_SECRETSHARING_SecretReadyCallback cb,
@@ -205,6 +206,7 @@ GNUNET_SECRETSHARING_create_session (const struct GNUNET_CONFIGURATION_Handle *c
205 msg->threshold = htons (threshold); 206 msg->threshold = htons (threshold);
206 msg->num_peers = htons (num_peers); 207 msg->num_peers = htons (num_peers);
207 msg->session_id = *session_id; 208 msg->session_id = *session_id;
209 msg->start = GNUNET_TIME_absolute_hton (start);
208 msg->deadline = GNUNET_TIME_absolute_hton (deadline); 210 msg->deadline = GNUNET_TIME_absolute_hton (deadline);
209 memcpy (&msg[1], peers, num_peers * sizeof (struct GNUNET_PeerIdentity)); 211 memcpy (&msg[1], peers, num_peers * sizeof (struct GNUNET_PeerIdentity));
210 212
@@ -253,6 +255,7 @@ struct GNUNET_SECRETSHARING_DecryptionHandle *
253GNUNET_SECRETSHARING_decrypt (const struct GNUNET_CONFIGURATION_Handle *cfg, 255GNUNET_SECRETSHARING_decrypt (const struct GNUNET_CONFIGURATION_Handle *cfg,
254 struct GNUNET_SECRETSHARING_Share *share, 256 struct GNUNET_SECRETSHARING_Share *share,
255 const struct GNUNET_SECRETSHARING_Ciphertext *ciphertext, 257 const struct GNUNET_SECRETSHARING_Ciphertext *ciphertext,
258 struct GNUNET_TIME_Absolute start,
256 struct GNUNET_TIME_Absolute deadline, 259 struct GNUNET_TIME_Absolute deadline,
257 GNUNET_SECRETSHARING_DecryptCallback decrypt_cb, 260 GNUNET_SECRETSHARING_DecryptCallback decrypt_cb,
258 void *decrypt_cb_cls) 261 void *decrypt_cb_cls)
@@ -285,6 +288,7 @@ GNUNET_SECRETSHARING_decrypt (const struct GNUNET_CONFIGURATION_Handle *cfg,
285 288
286 GNUNET_assert (GNUNET_OK == GNUNET_SECRETSHARING_share_write (share, &msg[1], share_size, NULL)); 289 GNUNET_assert (GNUNET_OK == GNUNET_SECRETSHARING_share_write (share, &msg[1], share_size, NULL));
287 290
291 msg->start = GNUNET_TIME_absolute_hton (start);
288 msg->deadline = GNUNET_TIME_absolute_hton (deadline); 292 msg->deadline = GNUNET_TIME_absolute_hton (deadline);
289 msg->ciphertext = *ciphertext; 293 msg->ciphertext = *ciphertext;
290 294