diff options
author | Florian Dold <florian.dold@gmail.com> | 2014-02-03 21:25:53 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2014-02-03 21:25:53 +0000 |
commit | 8a3563b5c242b60aa4b7d2b9a3c3607ef8dcbadb (patch) | |
tree | f4b85c248403ba6783db017930b2258f3e61e18a /src/consensus | |
parent | 694581b42a78419c1c8ffc31ee873484ff93d79b (diff) | |
download | gnunet-8a3563b5c242b60aa4b7d2b9a3c3607ef8dcbadb.tar.gz gnunet-8a3563b5c242b60aa4b7d2b9a3c3607ef8dcbadb.zip |
- consensus and secretsharing have both start time and deadline
Diffstat (limited to 'src/consensus')
-rw-r--r-- | src/consensus/consensus.h | 24 | ||||
-rw-r--r-- | src/consensus/consensus_api.c | 13 | ||||
-rw-r--r-- | src/consensus/gnunet-consensus-profiler.c | 17 | ||||
-rw-r--r-- | src/consensus/gnunet-service-consensus.c | 14 |
4 files changed, 44 insertions, 24 deletions
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 | |||
52 | struct 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 | */ |
267 | void | 274 | void |
268 | GNUNET_CONSENSUS_conclude (struct GNUNET_CONSENSUS_Handle *consensus, | 275 | GNUNET_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 | ||
57 | static int verbose; | 58 | static int verbose; |
58 | 59 | ||
60 | /** | ||
61 | * Start time for all consensuses. | ||
62 | */ | ||
63 | static struct GNUNET_TIME_Absolute start; | ||
64 | |||
65 | /** | ||
66 | * Deadline for all consensuses. | ||
67 | */ | ||
68 | static 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} |