aboutsummaryrefslogtreecommitdiff
path: root/src/consensus
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/consensus
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/consensus')
-rw-r--r--src/consensus/consensus.h6
-rw-r--r--src/consensus/consensus_api.c183
-rw-r--r--src/consensus/consensus_protocol.h15
-rw-r--r--src/consensus/gnunet-consensus-profiler.c536
-rw-r--r--src/consensus/gnunet-service-consensus.c3196
-rw-r--r--src/consensus/plugin_block_consensus.c60
-rw-r--r--src/consensus/test_consensus_api.c74
7 files changed, 2092 insertions, 1978 deletions
diff --git a/src/consensus/consensus.h b/src/consensus/consensus.h
index f110b23b2..888213d55 100644
--- a/src/consensus/consensus.h
+++ b/src/consensus/consensus.h
@@ -34,7 +34,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
34 * Sent by the client to the service, 34 * Sent by the client to the service,
35 * when the client wants the service to join a consensus session. 35 * when the client wants the service to join a consensus session.
36 */ 36 */
37struct GNUNET_CONSENSUS_JoinMessage { 37struct GNUNET_CONSENSUS_JoinMessage
38{
38 /** 39 /**
39 * Type: GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_JOIN 40 * Type: GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_JOIN
40 */ 41 */
@@ -68,7 +69,8 @@ struct GNUNET_CONSENSUS_JoinMessage {
68/** 69/**
69 * Message with an element 70 * Message with an element
70 */ 71 */
71struct GNUNET_CONSENSUS_ElementMessage { 72struct GNUNET_CONSENSUS_ElementMessage
73{
72 /** 74 /**
73 * Type: 75 * Type:
74 * Either GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_RECEIVED_ELEMENT 76 * Either GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_RECEIVED_ELEMENT
diff --git a/src/consensus/consensus_api.c b/src/consensus/consensus_api.c
index 2da145932..c4350adaf 100644
--- a/src/consensus/consensus_api.c
+++ b/src/consensus/consensus_api.c
@@ -31,13 +31,14 @@
31#include "consensus.h" 31#include "consensus.h"
32 32
33 33
34#define LOG(kind, ...) GNUNET_log_from(kind, "consensus-api", __VA_ARGS__) 34#define LOG(kind, ...) GNUNET_log_from (kind, "consensus-api", __VA_ARGS__)
35 35
36 36
37/** 37/**
38 * Handle for the service. 38 * Handle for the service.
39 */ 39 */
40struct GNUNET_CONSENSUS_Handle { 40struct GNUNET_CONSENSUS_Handle
41{
41 /** 42 /**
42 * Configuration to use. 43 * Configuration to use.
43 */ 44 */
@@ -89,7 +90,8 @@ struct GNUNET_CONSENSUS_Handle {
89 * FIXME: this should not bee necessary when the API 90 * FIXME: this should not bee necessary when the API
90 * issue has been fixed 91 * issue has been fixed
91 */ 92 */
92struct InsertDoneInfo { 93struct InsertDoneInfo
94{
93 GNUNET_CONSENSUS_InsertDoneCallback idc; 95 GNUNET_CONSENSUS_InsertDoneCallback idc;
94 void *cls; 96 void *cls;
95}; 97};
@@ -102,8 +104,8 @@ struct InsertDoneInfo {
102 * @param msg element message 104 * @param msg element message
103 */ 105 */
104static int 106static int
105check_new_element(void *cls, 107check_new_element (void *cls,
106 const struct GNUNET_CONSENSUS_ElementMessage *msg) 108 const struct GNUNET_CONSENSUS_ElementMessage *msg)
107{ 109{
108 /* any size is fine, elements are variable-size */ 110 /* any size is fine, elements are variable-size */
109 return GNUNET_OK; 111 return GNUNET_OK;
@@ -117,19 +119,20 @@ check_new_element(void *cls,
117 * @param msg element message 119 * @param msg element message
118 */ 120 */
119static void 121static void
120handle_new_element(void *cls, 122handle_new_element (void *cls,
121 const struct GNUNET_CONSENSUS_ElementMessage *msg) 123 const struct GNUNET_CONSENSUS_ElementMessage *msg)
122{ 124{
123 struct GNUNET_CONSENSUS_Handle *consensus = cls; 125 struct GNUNET_CONSENSUS_Handle *consensus = cls;
124 struct GNUNET_SET_Element element; 126 struct GNUNET_SET_Element element;
125 127
126 LOG(GNUNET_ERROR_TYPE_DEBUG, 128 LOG (GNUNET_ERROR_TYPE_DEBUG,
127 "received new element\n"); 129 "received new element\n");
128 element.element_type = msg->element_type; 130 element.element_type = msg->element_type;
129 element.size = ntohs(msg->header.size) - sizeof(struct GNUNET_CONSENSUS_ElementMessage); 131 element.size = ntohs (msg->header.size) - sizeof(struct
132 GNUNET_CONSENSUS_ElementMessage);
130 element.data = &msg[1]; 133 element.data = &msg[1];
131 consensus->new_element_cb(consensus->new_element_cls, 134 consensus->new_element_cb (consensus->new_element_cls,
132 &element); 135 &element);
133} 136}
134 137
135 138
@@ -141,17 +144,17 @@ handle_new_element(void *cls,
141 * @param msg conclude done message 144 * @param msg conclude done message
142 */ 145 */
143static void 146static void
144handle_conclude_done(void *cls, 147handle_conclude_done (void *cls,
145 const struct GNUNET_MessageHeader *msg) 148 const struct GNUNET_MessageHeader *msg)
146{ 149{
147 struct GNUNET_CONSENSUS_Handle *consensus = cls; 150 struct GNUNET_CONSENSUS_Handle *consensus = cls;
148 GNUNET_CONSENSUS_ConcludeCallback cc; 151 GNUNET_CONSENSUS_ConcludeCallback cc;
149 152
150 GNUNET_MQ_destroy(consensus->mq); 153 GNUNET_MQ_destroy (consensus->mq);
151 consensus->mq = NULL; 154 consensus->mq = NULL;
152 GNUNET_assert(NULL != (cc = consensus->conclude_cb)); 155 GNUNET_assert (NULL != (cc = consensus->conclude_cb));
153 consensus->conclude_cb = NULL; 156 consensus->conclude_cb = NULL;
154 cc(consensus->conclude_cls); 157 cc (consensus->conclude_cls);
155} 158}
156 159
157 160
@@ -165,11 +168,11 @@ handle_conclude_done(void *cls,
165 * @param error error code 168 * @param error error code
166 */ 169 */
167static void 170static void
168mq_error_handler(void *cls, 171mq_error_handler (void *cls,
169 enum GNUNET_MQ_Error error) 172 enum GNUNET_MQ_Error error)
170{ 173{
171 LOG(GNUNET_ERROR_TYPE_WARNING, 174 LOG (GNUNET_ERROR_TYPE_WARNING,
172 "consensus service disconnected us\n"); 175 "consensus service disconnected us\n");
173} 176}
174 177
175 178
@@ -191,27 +194,27 @@ mq_error_handler(void *cls,
191 * @return handle to use, NULL on error 194 * @return handle to use, NULL on error
192 */ 195 */
193struct GNUNET_CONSENSUS_Handle * 196struct GNUNET_CONSENSUS_Handle *
194GNUNET_CONSENSUS_create(const struct GNUNET_CONFIGURATION_Handle *cfg, 197GNUNET_CONSENSUS_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
195 unsigned int num_peers, 198 unsigned int num_peers,
196 const struct GNUNET_PeerIdentity *peers, 199 const struct GNUNET_PeerIdentity *peers,
197 const struct GNUNET_HashCode *session_id, 200 const struct GNUNET_HashCode *session_id,
198 struct GNUNET_TIME_Absolute start, 201 struct GNUNET_TIME_Absolute start,
199 struct GNUNET_TIME_Absolute deadline, 202 struct GNUNET_TIME_Absolute deadline,
200 GNUNET_CONSENSUS_ElementCallback new_element_cb, 203 GNUNET_CONSENSUS_ElementCallback new_element_cb,
201 void *new_element_cls) 204 void *new_element_cls)
202{ 205{
203 struct GNUNET_CONSENSUS_Handle *consensus 206 struct GNUNET_CONSENSUS_Handle *consensus
204 = GNUNET_new(struct GNUNET_CONSENSUS_Handle); 207 = GNUNET_new (struct GNUNET_CONSENSUS_Handle);
205 struct GNUNET_MQ_MessageHandler mq_handlers[] = { 208 struct GNUNET_MQ_MessageHandler mq_handlers[] = {
206 GNUNET_MQ_hd_var_size(new_element, 209 GNUNET_MQ_hd_var_size (new_element,
207 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_RECEIVED_ELEMENT, 210 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_RECEIVED_ELEMENT,
208 struct GNUNET_CONSENSUS_ElementMessage, 211 struct GNUNET_CONSENSUS_ElementMessage,
209 consensus), 212 consensus),
210 GNUNET_MQ_hd_fixed_size(conclude_done, 213 GNUNET_MQ_hd_fixed_size (conclude_done,
211 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE_DONE, 214 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE_DONE,
212 struct GNUNET_MessageHeader, 215 struct GNUNET_MessageHeader,
213 consensus), 216 consensus),
214 GNUNET_MQ_handler_end() 217 GNUNET_MQ_handler_end ()
215 }; 218 };
216 struct GNUNET_CONSENSUS_JoinMessage *join_msg; 219 struct GNUNET_CONSENSUS_JoinMessage *join_msg;
217 struct GNUNET_MQ_Envelope *ev; 220 struct GNUNET_MQ_Envelope *ev;
@@ -220,40 +223,40 @@ GNUNET_CONSENSUS_create(const struct GNUNET_CONFIGURATION_Handle *cfg,
220 consensus->new_element_cb = new_element_cb; 223 consensus->new_element_cb = new_element_cb;
221 consensus->new_element_cls = new_element_cls; 224 consensus->new_element_cls = new_element_cls;
222 consensus->session_id = *session_id; 225 consensus->session_id = *session_id;
223 consensus->mq = GNUNET_CLIENT_connect(cfg, 226 consensus->mq = GNUNET_CLIENT_connect (cfg,
224 "consensus", 227 "consensus",
225 mq_handlers, 228 mq_handlers,
226 &mq_error_handler, 229 &mq_error_handler,
227 consensus); 230 consensus);
228 if (NULL == consensus->mq) 231 if (NULL == consensus->mq)
229 { 232 {
230 GNUNET_free(consensus); 233 GNUNET_free (consensus);
231 return NULL; 234 return NULL;
232 } 235 }
233 ev = GNUNET_MQ_msg_extra(join_msg, 236 ev = GNUNET_MQ_msg_extra (join_msg,
234 (num_peers * sizeof(struct GNUNET_PeerIdentity)), 237 (num_peers * sizeof(struct GNUNET_PeerIdentity)),
235 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_JOIN); 238 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_JOIN);
236 239
237 join_msg->session_id = consensus->session_id; 240 join_msg->session_id = consensus->session_id;
238 join_msg->start = GNUNET_TIME_absolute_hton(start); 241 join_msg->start = GNUNET_TIME_absolute_hton (start);
239 join_msg->deadline = GNUNET_TIME_absolute_hton(deadline); 242 join_msg->deadline = GNUNET_TIME_absolute_hton (deadline);
240 join_msg->num_peers = htonl(num_peers); 243 join_msg->num_peers = htonl (num_peers);
241 GNUNET_memcpy(&join_msg[1], 244 GNUNET_memcpy (&join_msg[1],
242 peers, 245 peers,
243 num_peers * sizeof(struct GNUNET_PeerIdentity)); 246 num_peers * sizeof(struct GNUNET_PeerIdentity));
244 247
245 GNUNET_MQ_send(consensus->mq, ev); 248 GNUNET_MQ_send (consensus->mq, ev);
246 return consensus; 249 return consensus;
247} 250}
248 251
249 252
250static void 253static void
251idc_adapter(void *cls) 254idc_adapter (void *cls)
252{ 255{
253 struct InsertDoneInfo *i = cls; 256 struct InsertDoneInfo *i = cls;
254 257
255 i->idc(i->cls, GNUNET_OK); 258 i->idc (i->cls, GNUNET_OK);
256 GNUNET_free(i); 259 GNUNET_free (i);
257} 260}
258 261
259/** 262/**
@@ -267,30 +270,30 @@ idc_adapter(void *cls)
267 * @param idc_cls closure for 'idc' 270 * @param idc_cls closure for 'idc'
268 */ 271 */
269void 272void
270GNUNET_CONSENSUS_insert(struct GNUNET_CONSENSUS_Handle *consensus, 273GNUNET_CONSENSUS_insert (struct GNUNET_CONSENSUS_Handle *consensus,
271 const struct GNUNET_SET_Element *element, 274 const struct GNUNET_SET_Element *element,
272 GNUNET_CONSENSUS_InsertDoneCallback idc, 275 GNUNET_CONSENSUS_InsertDoneCallback idc,
273 void *idc_cls) 276 void *idc_cls)
274{ 277{
275 struct GNUNET_CONSENSUS_ElementMessage *element_msg; 278 struct GNUNET_CONSENSUS_ElementMessage *element_msg;
276 struct GNUNET_MQ_Envelope *ev; 279 struct GNUNET_MQ_Envelope *ev;
277 struct InsertDoneInfo *i; 280 struct InsertDoneInfo *i;
278 281
279 LOG(GNUNET_ERROR_TYPE_DEBUG, "inserting, size=%llu\n", element->size); 282 LOG (GNUNET_ERROR_TYPE_DEBUG, "inserting, size=%llu\n", element->size);
280 283
281 ev = GNUNET_MQ_msg_extra(element_msg, element->size, 284 ev = GNUNET_MQ_msg_extra (element_msg, element->size,
282 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_INSERT); 285 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_INSERT);
283 286
284 GNUNET_memcpy(&element_msg[1], element->data, element->size); 287 GNUNET_memcpy (&element_msg[1], element->data, element->size);
285 288
286 if (NULL != idc) 289 if (NULL != idc)
287 { 290 {
288 i = GNUNET_new(struct InsertDoneInfo); 291 i = GNUNET_new (struct InsertDoneInfo);
289 i->idc = idc; 292 i->idc = idc;
290 i->cls = idc_cls; 293 i->cls = idc_cls;
291 GNUNET_MQ_notify_sent(ev, idc_adapter, i); 294 GNUNET_MQ_notify_sent (ev, idc_adapter, i);
292 } 295 }
293 GNUNET_MQ_send(consensus->mq, ev); 296 GNUNET_MQ_send (consensus->mq, ev);
294} 297}
295 298
296 299
@@ -307,20 +310,20 @@ GNUNET_CONSENSUS_insert(struct GNUNET_CONSENSUS_Handle *consensus,
307 * @param conclude_cls closure for the conclude callback 310 * @param conclude_cls closure for the conclude callback
308 */ 311 */
309void 312void
310GNUNET_CONSENSUS_conclude(struct GNUNET_CONSENSUS_Handle *consensus, 313GNUNET_CONSENSUS_conclude (struct GNUNET_CONSENSUS_Handle *consensus,
311 GNUNET_CONSENSUS_ConcludeCallback conclude, 314 GNUNET_CONSENSUS_ConcludeCallback conclude,
312 void *conclude_cls) 315 void *conclude_cls)
313{ 316{
314 struct GNUNET_MQ_Envelope *ev; 317 struct GNUNET_MQ_Envelope *ev;
315 318
316 GNUNET_assert(NULL != conclude); 319 GNUNET_assert (NULL != conclude);
317 GNUNET_assert(NULL == consensus->conclude_cb); 320 GNUNET_assert (NULL == consensus->conclude_cb);
318 321
319 consensus->conclude_cls = conclude_cls; 322 consensus->conclude_cls = conclude_cls;
320 consensus->conclude_cb = conclude; 323 consensus->conclude_cb = conclude;
321 324
322 ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE); 325 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE);
323 GNUNET_MQ_send(consensus->mq, ev); 326 GNUNET_MQ_send (consensus->mq, ev);
324} 327}
325 328
326 329
@@ -331,14 +334,14 @@ GNUNET_CONSENSUS_conclude(struct GNUNET_CONSENSUS_Handle *consensus,
331 * @param consensus handle to destroy 334 * @param consensus handle to destroy
332 */ 335 */
333void 336void
334GNUNET_CONSENSUS_destroy(struct GNUNET_CONSENSUS_Handle *consensus) 337GNUNET_CONSENSUS_destroy (struct GNUNET_CONSENSUS_Handle *consensus)
335{ 338{
336 if (NULL != consensus->mq) 339 if (NULL != consensus->mq)
337 { 340 {
338 GNUNET_MQ_destroy(consensus->mq); 341 GNUNET_MQ_destroy (consensus->mq);
339 consensus->mq = NULL; 342 consensus->mq = NULL;
340 } 343 }
341 GNUNET_free(consensus); 344 GNUNET_free (consensus);
342} 345}
343 346
344/* end of consensus_api.c */ 347/* end of consensus_api.c */
diff --git a/src/consensus/consensus_protocol.h b/src/consensus/consensus_protocol.h
index fc8ae7533..a40162fb8 100644
--- a/src/consensus/consensus_protocol.h
+++ b/src/consensus/consensus_protocol.h
@@ -42,7 +42,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
42 * Essentially contains all the fields 42 * Essentially contains all the fields
43 * from 'struct TaskKey', but in NBO. 43 * from 'struct TaskKey', but in NBO.
44 */ 44 */
45struct GNUNET_CONSENSUS_RoundContextMessage { 45struct GNUNET_CONSENSUS_RoundContextMessage
46{
46 /** 47 /**
47 * Type: #GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ROUND_CONTEXT 48 * Type: #GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ROUND_CONTEXT
48 */ 49 */
@@ -88,7 +89,8 @@ struct GNUNET_CONSENSUS_RoundContextMessage {
88}; 89};
89 90
90 91
91enum { 92enum
93{
92 CONSENSUS_MARKER_CONTESTED = 1, 94 CONSENSUS_MARKER_CONTESTED = 1,
93 CONSENSUS_MARKER_SIZE = 2, 95 CONSENSUS_MARKER_SIZE = 2,
94}; 96};
@@ -97,7 +99,8 @@ enum {
97/** 99/**
98 * Consensus element, either marker or payload. 100 * Consensus element, either marker or payload.
99 */ 101 */
100struct ConsensusElement { 102struct ConsensusElement
103{
101 /** 104 /**
102 * Payload element_type, only valid 105 * Payload element_type, only valid
103 * if this is not a marker element. 106 * if this is not a marker element.
@@ -113,14 +116,16 @@ struct ConsensusElement {
113}; 116};
114 117
115 118
116struct ConsensusSizeElement { 119struct ConsensusSizeElement
120{
117 struct ConsensusElement ce; 121 struct ConsensusElement ce;
118 122
119 uint64_t size GNUNET_PACKED; 123 uint64_t size GNUNET_PACKED;
120 uint8_t sender_index; 124 uint8_t sender_index;
121}; 125};
122 126
123struct ConsensusStuffedElement { 127struct ConsensusStuffedElement
128{
124 struct ConsensusElement ce; 129 struct ConsensusElement ce;
125 struct GNUNET_HashCode rand GNUNET_PACKED; 130 struct GNUNET_HashCode rand GNUNET_PACKED;
126}; 131};
diff --git a/src/consensus/gnunet-consensus-profiler.c b/src/consensus/gnunet-consensus-profiler.c
index 9feee87cd..65fc23d8f 100644
--- a/src/consensus/gnunet-consensus-profiler.c
+++ b/src/consensus/gnunet-consensus-profiler.c
@@ -92,26 +92,26 @@ static struct GNUNET_TIME_Absolute deadline;
92 * @param event information about the event 92 * @param event information about the event
93 */ 93 */
94static void 94static void
95controller_cb(void *cls, 95controller_cb (void *cls,
96 const struct GNUNET_TESTBED_EventInformation *event) 96 const struct GNUNET_TESTBED_EventInformation *event)
97{ 97{
98 GNUNET_assert(0); 98 GNUNET_assert (0);
99} 99}
100 100
101 101
102static void 102static void
103statistics_done_cb(void *cls, 103statistics_done_cb (void *cls,
104 struct 104 struct
105 GNUNET_TESTBED_Operation 105 GNUNET_TESTBED_Operation
106 *op, 106 *op,
107 const char *emsg) 107 const char *emsg)
108{ 108{
109 GNUNET_assert(NULL == emsg); 109 GNUNET_assert (NULL == emsg);
110 GNUNET_TESTBED_operation_done(op); 110 GNUNET_TESTBED_operation_done (op);
111 if (NULL != statistics_file) 111 if (NULL != statistics_file)
112 fclose(statistics_file); 112 fclose (statistics_file);
113 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "got statistics, shutting down\n"); 113 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "got statistics, shutting down\n");
114 GNUNET_SCHEDULER_shutdown(); 114 GNUNET_SCHEDULER_shutdown ();
115} 115}
116 116
117 117
@@ -127,47 +127,48 @@ statistics_done_cb(void *cls,
127 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration 127 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
128 */ 128 */
129static int 129static int
130statistics_cb(void *cls, 130statistics_cb (void *cls,
131 const struct GNUNET_TESTBED_Peer *peer, 131 const struct GNUNET_TESTBED_Peer *peer,
132 const char *subsystem, 132 const char *subsystem,
133 const char *name, 133 const char *name,
134 uint64_t value, 134 uint64_t value,
135 int is_persistent) 135 int is_persistent)
136{ 136{
137 if (NULL != statistics_file) 137 if (NULL != statistics_file)
138 { 138 {
139 fprintf(statistics_file, "P%u\t%s\t%s\t%lu\n", GNUNET_TESTBED_get_index(peer), subsystem, name, (unsigned long)value); 139 fprintf (statistics_file, "P%u\t%s\t%s\t%lu\n", GNUNET_TESTBED_get_index (
140 } 140 peer), subsystem, name, (unsigned long) value);
141 }
141 return GNUNET_OK; 142 return GNUNET_OK;
142} 143}
143 144
144 145
145static void 146static void
146destroy(void *cls) 147destroy (void *cls)
147{ 148{
148 struct GNUNET_CONSENSUS_Handle *consensus = cls; 149 struct GNUNET_CONSENSUS_Handle *consensus = cls;
149 150
150 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 151 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
151 "destroying consensus\n"); 152 "destroying consensus\n");
152 GNUNET_CONSENSUS_destroy(consensus); 153 GNUNET_CONSENSUS_destroy (consensus);
153 peers_done++; 154 peers_done++;
154 if (peers_done == num_peers) 155 if (peers_done == num_peers)
155 { 156 {
156 unsigned int i; 157 unsigned int i;
157 for (i = 0; i < num_peers; i++) 158 for (i = 0; i < num_peers; i++)
158 GNUNET_TESTBED_operation_done(testbed_operations[i]); 159 GNUNET_TESTBED_operation_done (testbed_operations[i]);
159 for (i = 0; i < num_peers; i++) 160 for (i = 0; i < num_peers; i++)
160 printf("P%u got %u of %u elements\n", 161 printf ("P%u got %u of %u elements\n",
161 i, 162 i,
162 results_for_peer[i], 163 results_for_peer[i],
163 num_values); 164 num_values);
164 if (NULL != statistics_filename) 165 if (NULL != statistics_filename)
165 statistics_file = fopen(statistics_filename, "w"); 166 statistics_file = fopen (statistics_filename, "w");
166 GNUNET_TESTBED_get_statistics(num_peers, peers, NULL, NULL, 167 GNUNET_TESTBED_get_statistics (num_peers, peers, NULL, NULL,
167 statistics_cb, 168 statistics_cb,
168 statistics_done_cb, 169 statistics_done_cb,
169 NULL); 170 NULL);
170 } 171 }
171} 172}
172 173
173 174
@@ -179,44 +180,44 @@ destroy(void *cls)
179 * #GNUNET_NO if not 180 * #GNUNET_NO if not
180 */ 181 */
181static void 182static void
182conclude_cb(void *cls) 183conclude_cb (void *cls)
183{ 184{
184 struct GNUNET_CONSENSUS_Handle **chp = cls; 185 struct GNUNET_CONSENSUS_Handle **chp = cls;
185 186
186 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 187 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
187 "consensus %d done\n", 188 "consensus %d done\n",
188 (int)(chp - consensus_handles)); 189 (int) (chp - consensus_handles));
189 GNUNET_SCHEDULER_add_now(destroy, *chp); 190 GNUNET_SCHEDULER_add_now (destroy, *chp);
190} 191}
191 192
192 193
193static void 194static void
194generate_indices(int *indices) 195generate_indices (int *indices)
195{ 196{
196 int j; 197 int j;
197 198
198 j = 0; 199 j = 0;
199 while (j < replication) 200 while (j < replication)
200 { 201 {
201 int n; 202 int n;
202 int k; 203 int k;
203 int repeat; 204 int repeat;
204 n = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers); 205 n = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
205 repeat = GNUNET_NO; 206 repeat = GNUNET_NO;
206 for (k = 0; k < j; k++) 207 for (k = 0; k < j; k++)
207 if (indices[k] == n) 208 if (indices[k] == n)
208 { 209 {
209 repeat = GNUNET_YES; 210 repeat = GNUNET_YES;
210 break; 211 break;
211 } 212 }
212 if (GNUNET_NO == repeat) 213 if (GNUNET_NO == repeat)
213 indices[j++] = n; 214 indices[j++] = n;
214 } 215 }
215} 216}
216 217
217 218
218static void 219static void
219do_consensus() 220do_consensus ()
220{ 221{
221 int unique_indices[replication]; 222 int unique_indices[replication];
222 unsigned int i; 223 unsigned int i;
@@ -225,48 +226,48 @@ do_consensus()
225 struct GNUNET_SET_Element element; 226 struct GNUNET_SET_Element element;
226 227
227 if (dist_static) 228 if (dist_static)
229 {
230 for (i = 0; i < num_values; i++)
228 { 231 {
229 for (i = 0; i < num_values; i++) 232 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &val);
230 { 233
231 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &val); 234 element.data = &val;
232 235 element.size = sizeof(val);
233 element.data = &val; 236 for (j = 0; j < replication; j++)
234 element.size = sizeof(val); 237 {
235 for (j = 0; j < replication; j++) 238 GNUNET_CONSENSUS_insert (consensus_handles[j],
236 { 239 &element,
237 GNUNET_CONSENSUS_insert(consensus_handles[j], 240 NULL, NULL);
238 &element, 241 }
239 NULL, NULL);
240 }
241 }
242 } 242 }
243 }
243 else 244 else
245 {
246 for (i = 0; i < num_values; i++)
244 { 247 {
245 for (i = 0; i < num_values; i++) 248 generate_indices (unique_indices);
246 { 249 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &val);
247 generate_indices(unique_indices); 250
248 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &val); 251 element.data = &val;
249 252 element.size = sizeof(val);
250 element.data = &val; 253 for (j = 0; j < replication; j++)
251 element.size = sizeof(val); 254 {
252 for (j = 0; j < replication; j++) 255 int cid;
253 { 256
254 int cid; 257 cid = unique_indices[j];
255 258 GNUNET_CONSENSUS_insert (consensus_handles[cid],
256 cid = unique_indices[j]; 259 &element,
257 GNUNET_CONSENSUS_insert(consensus_handles[cid], 260 NULL, NULL);
258 &element, 261 }
259 NULL, NULL);
260 }
261 }
262 } 262 }
263 }
263 264
264 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 265 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
265 "all elements inserted, calling conclude\n"); 266 "all elements inserted, calling conclude\n");
266 267
267 for (i = 0; i < num_peers; i++) 268 for (i = 0; i < num_peers; i++)
268 GNUNET_CONSENSUS_conclude(consensus_handles[i], 269 GNUNET_CONSENSUS_conclude (consensus_handles[i],
269 conclude_cb, &consensus_handles[i]); 270 conclude_cb, &consensus_handles[i]);
270} 271}
271 272
272 273
@@ -280,50 +281,50 @@ do_consensus()
280 * operation has executed successfully. 281 * operation has executed successfully.
281 */ 282 */
282static void 283static void
283connect_complete(void *cls, 284connect_complete (void *cls,
284 struct GNUNET_TESTBED_Operation *op, 285 struct GNUNET_TESTBED_Operation *op,
285 void *ca_result, 286 void *ca_result,
286 const char *emsg) 287 const char *emsg)
287{ 288{
288 if (NULL != emsg) 289 if (NULL != emsg)
289 { 290 {
290 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 291 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
291 "testbed connect emsg: %s\n", 292 "testbed connect emsg: %s\n",
292 emsg); 293 emsg);
293 GNUNET_assert(0); 294 GNUNET_assert (0);
294 } 295 }
295 296
296 num_connected_handles++; 297 num_connected_handles++;
297 298
298 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 299 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
299 "connect complete\n"); 300 "connect complete\n");
300 301
301 if (num_connected_handles == num_peers) 302 if (num_connected_handles == num_peers)
302 { 303 {
303 do_consensus(); 304 do_consensus ();
304 } 305 }
305} 306}
306 307
307 308
308static void 309static void
309new_element_cb(void *cls, 310new_element_cb (void *cls,
310 const struct GNUNET_SET_Element *element) 311 const struct GNUNET_SET_Element *element)
311{ 312{
312 struct GNUNET_CONSENSUS_Handle **chp = cls; 313 struct GNUNET_CONSENSUS_Handle **chp = cls;
313 int idx = chp - consensus_handles; 314 int idx = chp - consensus_handles;
314 315
315 GNUNET_assert(NULL != cls); 316 GNUNET_assert (NULL != cls);
316 317
317 results_for_peer[idx]++; 318 results_for_peer[idx]++;
318 319
319 GNUNET_assert(sizeof(struct GNUNET_HashCode) == element->size); 320 GNUNET_assert (sizeof(struct GNUNET_HashCode) == element->size);
320 321
321 if (GNUNET_YES == verbose) 322 if (GNUNET_YES == verbose)
322 { 323 {
323 printf("P%d received %s\n", 324 printf ("P%d received %s\n",
324 idx, 325 idx,
325 GNUNET_h2s((struct GNUNET_HashCode *)element->data)); 326 GNUNET_h2s ((struct GNUNET_HashCode *) element->data));
326 } 327 }
327} 328}
328 329
329 330
@@ -338,24 +339,24 @@ new_element_cb(void *cls,
338 * @return service handle to return in 'op_result', NULL on error 339 * @return service handle to return in 'op_result', NULL on error
339 */ 340 */
340static void * 341static void *
341connect_adapter(void *cls, 342connect_adapter (void *cls,
342 const struct GNUNET_CONFIGURATION_Handle *cfg) 343 const struct GNUNET_CONFIGURATION_Handle *cfg)
343{ 344{
344 struct GNUNET_CONSENSUS_Handle **chp = cls; 345 struct GNUNET_CONSENSUS_Handle **chp = cls;
345 struct GNUNET_CONSENSUS_Handle *consensus; 346 struct GNUNET_CONSENSUS_Handle *consensus;
346 347
347 chp = (struct GNUNET_CONSENSUS_Handle **)cls; 348 chp = (struct GNUNET_CONSENSUS_Handle **) cls;
348 349
349 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 350 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
350 "connect adapter, %d peers\n", 351 "connect adapter, %d peers\n",
351 num_peers); 352 num_peers);
352 consensus = GNUNET_CONSENSUS_create(cfg, 353 consensus = GNUNET_CONSENSUS_create (cfg,
353 num_peers, peer_ids, 354 num_peers, peer_ids,
354 &session_id, 355 &session_id,
355 start, 356 start,
356 deadline, 357 deadline,
357 &new_element_cb, chp); 358 &new_element_cb, chp);
358 *chp = (struct GNUNET_CONSENSUS_Handle *)consensus; 359 *chp = (struct GNUNET_CONSENSUS_Handle *) consensus;
359 return consensus; 360 return consensus;
360} 361}
361 362
@@ -368,11 +369,11 @@ connect_adapter(void *cls,
368 * @param op_result service handle returned from the connect adapter 369 * @param op_result service handle returned from the connect adapter
369 */ 370 */
370static void 371static void
371disconnect_adapter(void *cls, void *op_result) 372disconnect_adapter (void *cls, void *op_result)
372{ 373{
373 /* FIXME: what to do here? */ 374 /* FIXME: what to do here? */
374 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 375 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
375 "disconnect adapter called\n"); 376 "disconnect adapter called\n");
376} 377}
377 378
378 379
@@ -386,34 +387,36 @@ disconnect_adapter(void *cls, void *op_result)
386 * operation is successfull 387 * operation is successfull
387 */ 388 */
388static void 389static void
389peer_info_cb(void *cb_cls, 390peer_info_cb (void *cb_cls,
390 struct GNUNET_TESTBED_Operation *op, 391 struct GNUNET_TESTBED_Operation *op,
391 const struct GNUNET_TESTBED_PeerInformation *pinfo, 392 const struct GNUNET_TESTBED_PeerInformation *pinfo,
392 const char *emsg) 393 const char *emsg)
393{ 394{
394 struct GNUNET_PeerIdentity *p; 395 struct GNUNET_PeerIdentity *p;
395 int i; 396 int i;
396 397
397 GNUNET_assert(NULL == emsg); 398 GNUNET_assert (NULL == emsg);
398 399
399 p = (struct GNUNET_PeerIdentity *)cb_cls; 400 p = (struct GNUNET_PeerIdentity *) cb_cls;
400 401
401 if (pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY) 402 if (pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY)
402 { 403 {
403 *p = *pinfo->result.id; 404 *p = *pinfo->result.id;
404 num_retrieved_peer_ids++; 405 num_retrieved_peer_ids++;
405 if (num_retrieved_peer_ids == num_peers) 406 if (num_retrieved_peer_ids == num_peers)
406 for (i = 0; i < num_peers; i++) 407 for (i = 0; i < num_peers; i++)
407 testbed_operations[i] = 408 testbed_operations[i] =
408 GNUNET_TESTBED_service_connect(NULL, peers[i], "consensus", connect_complete, NULL, 409 GNUNET_TESTBED_service_connect (NULL, peers[i], "consensus",
409 connect_adapter, disconnect_adapter, &consensus_handles[i]); 410 connect_complete, NULL,
410 } 411 connect_adapter, disconnect_adapter,
412 &consensus_handles[i]);
413 }
411 else 414 else
412 { 415 {
413 GNUNET_assert(0); 416 GNUNET_assert (0);
414 } 417 }
415 418
416 GNUNET_TESTBED_operation_done(op); 419 GNUNET_TESTBED_operation_done (op);
417} 420}
418 421
419 422
@@ -431,144 +434,153 @@ peer_info_cb(void *cb_cls,
431 * failed 434 * failed
432 */ 435 */
433static void 436static void
434test_master(void *cls, 437test_master (void *cls,
435 struct GNUNET_TESTBED_RunHandle *h, 438 struct GNUNET_TESTBED_RunHandle *h,
436 unsigned int num_peers, 439 unsigned int num_peers,
437 struct GNUNET_TESTBED_Peer **started_peers, 440 struct GNUNET_TESTBED_Peer **started_peers,
438 unsigned int links_succeeded, 441 unsigned int links_succeeded,
439 unsigned int links_failed) 442 unsigned int links_failed)
440{ 443{
441 int i; 444 int i;
442 445
443 GNUNET_log_setup("gnunet-consensus", "INFO", NULL); 446 GNUNET_log_setup ("gnunet-consensus", "INFO", NULL);
444 447
445 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "test master\n"); 448 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "test master\n");
446 449
447 peers = started_peers; 450 peers = started_peers;
448 451
449 peer_ids = GNUNET_malloc(num_peers * sizeof(struct GNUNET_PeerIdentity)); 452 peer_ids = GNUNET_malloc (num_peers * sizeof(struct GNUNET_PeerIdentity));
450 453
451 results_for_peer = GNUNET_malloc(num_peers * sizeof(unsigned int)); 454 results_for_peer = GNUNET_malloc (num_peers * sizeof(unsigned int));
452 consensus_handles = GNUNET_malloc(num_peers * sizeof(struct ConsensusHandle *)); 455 consensus_handles = GNUNET_malloc (num_peers * sizeof(struct
453 testbed_operations = GNUNET_malloc(num_peers * sizeof(struct ConsensusHandle *)); 456 ConsensusHandle *));
457 testbed_operations = GNUNET_malloc (num_peers * sizeof(struct
458 ConsensusHandle *));
454 459
455 for (i = 0; i < num_peers; i++) 460 for (i = 0; i < num_peers; i++)
456 GNUNET_TESTBED_peer_get_information(peers[i], 461 GNUNET_TESTBED_peer_get_information (peers[i],
457 GNUNET_TESTBED_PIT_IDENTITY, 462 GNUNET_TESTBED_PIT_IDENTITY,
458 peer_info_cb, 463 peer_info_cb,
459 &peer_ids[i]); 464 &peer_ids[i]);
460} 465}
461 466
462 467
463static void 468static void
464run(void *cls, char *const *args, const char *cfgfile, 469run (void *cls, char *const *args, const char *cfgfile,
465 const struct GNUNET_CONFIGURATION_Handle *cfg) 470 const struct GNUNET_CONFIGURATION_Handle *cfg)
466{ 471{
467 static char *session_str = "gnunet-consensus/test"; 472 static char *session_str = "gnunet-consensus/test";
468 char *topology; 473 char *topology;
469 int topology_cmp_result; 474 int topology_cmp_result;
470 475
471 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "testbed", "OVERLAY_TOPOLOGY", &topology)) 476 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "testbed",
472 { 477 "OVERLAY_TOPOLOGY",
473 fprintf(stderr, 478 &topology))
474 "'OVERLAY_TOPOLOGY' not found in 'testbed' config section, " 479 {
475 "seems like you passed the wrong configuration file\n"); 480 fprintf (stderr,
476 return; 481 "'OVERLAY_TOPOLOGY' not found in 'testbed' config section, "
477 } 482 "seems like you passed the wrong configuration file\n");
483 return;
484 }
478 485
479 topology_cmp_result = strcasecmp(topology, "NONE"); 486 topology_cmp_result = strcasecmp (topology, "NONE");
480 GNUNET_free(topology); 487 GNUNET_free (topology);
481 488
482 if (0 == topology_cmp_result) 489 if (0 == topology_cmp_result)
483 { 490 {
484 fprintf(stderr, 491 fprintf (stderr,
485 "'OVERLAY_TOPOLOGY' set to 'NONE', " 492 "'OVERLAY_TOPOLOGY' set to 'NONE', "
486 "seems like you passed the wrong configuration file\n"); 493 "seems like you passed the wrong configuration file\n");
487 return; 494 return;
488 } 495 }
489 496
490 if (num_peers < replication) 497 if (num_peers < replication)
491 { 498 {
492 fprintf(stderr, "k must be <=n\n"); 499 fprintf (stderr, "k must be <=n\n");
493 return; 500 return;
494 } 501 }
495 502
496 start = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), consensus_delay); 503 start = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
497 deadline = GNUNET_TIME_absolute_add(start, conclude_timeout); 504 consensus_delay);
498 505 deadline = GNUNET_TIME_absolute_add (start, conclude_timeout);
499 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 506
500 "running gnunet-consensus\n"); 507 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
501 508 "running gnunet-consensus\n");
502 GNUNET_CRYPTO_hash(session_str, strlen(session_str), &session_id); 509
503 510 GNUNET_CRYPTO_hash (session_str, strlen (session_str), &session_id);
504 (void)GNUNET_TESTBED_test_run("gnunet-consensus", 511
505 cfgfile, 512 (void) GNUNET_TESTBED_test_run ("gnunet-consensus",
506 num_peers, 513 cfgfile,
507 0, 514 num_peers,
508 controller_cb, 515 0,
509 NULL, 516 controller_cb,
510 test_master, 517 NULL,
511 NULL); 518 test_master,
519 NULL);
512} 520}
513 521
514 522
515int 523int
516main(int argc, char **argv) 524main (int argc, char **argv)
517{ 525{
518 struct GNUNET_GETOPT_CommandLineOption options[] = { 526 struct GNUNET_GETOPT_CommandLineOption options[] = {
519 GNUNET_GETOPT_option_uint('n', 527 GNUNET_GETOPT_option_uint ('n',
520 "num-peers", 528 "num-peers",
521 NULL, 529 NULL,
522 gettext_noop("number of peers in consensus"), 530 gettext_noop ("number of peers in consensus"),
523 &num_peers), 531 &num_peers),
524 532
525 GNUNET_GETOPT_option_uint('k', 533 GNUNET_GETOPT_option_uint ('k',
526 "value-replication", 534 "value-replication",
527 NULL, 535 NULL,
528 gettext_noop("how many peers (random selection without replacement) receive one value?"), 536 gettext_noop (
529 &replication), 537 "how many peers (random selection without replacement) receive one value?"),
530 538 &replication),
531 GNUNET_GETOPT_option_uint('x', 539
532 "num-values", 540 GNUNET_GETOPT_option_uint ('x',
533 NULL, 541 "num-values",
534 gettext_noop("number of values"), 542 NULL,
535 &num_values), 543 gettext_noop ("number of values"),
536 544 &num_values),
537 GNUNET_GETOPT_option_relative_time('t', 545
538 "timeout", 546 GNUNET_GETOPT_option_relative_time ('t',
539 NULL, 547 "timeout",
540 gettext_noop("consensus timeout"), 548 NULL,
541 &conclude_timeout), 549 gettext_noop ("consensus timeout"),
542 550 &conclude_timeout),
543 551
544 GNUNET_GETOPT_option_relative_time('d', 552
545 "delay", 553 GNUNET_GETOPT_option_relative_time ('d',
546 NULL, 554 "delay",
547 gettext_noop("delay until consensus starts"), 555 NULL,
548 &consensus_delay), 556 gettext_noop (
549 557 "delay until consensus starts"),
550 GNUNET_GETOPT_option_filename('s', 558 &consensus_delay),
551 "statistics", 559
552 "FILENAME", 560 GNUNET_GETOPT_option_filename ('s',
553 gettext_noop("write statistics to file"), 561 "statistics",
554 &statistics_filename), 562 "FILENAME",
555 563 gettext_noop ("write statistics to file"),
556 GNUNET_GETOPT_option_flag('S', 564 &statistics_filename),
557 "dist-static", 565
558 gettext_noop("distribute elements to a static subset of good peers"), 566 GNUNET_GETOPT_option_flag ('S',
559 &dist_static), 567 "dist-static",
560 568 gettext_noop (
561 GNUNET_GETOPT_option_flag('V', 569 "distribute elements to a static subset of good peers"),
562 "verbose", 570 &dist_static),
563 gettext_noop("be more verbose (print received values)"), 571
564 &verbose), 572 GNUNET_GETOPT_option_flag ('V',
573 "verbose",
574 gettext_noop (
575 "be more verbose (print received values)"),
576 &verbose),
565 577
566 GNUNET_GETOPT_OPTION_END 578 GNUNET_GETOPT_OPTION_END
567 }; 579 };
568 580
569 conclude_timeout = GNUNET_TIME_UNIT_SECONDS; 581 conclude_timeout = GNUNET_TIME_UNIT_SECONDS;
570 GNUNET_PROGRAM_run2(argc, argv, "gnunet-consensus-profiler", 582 GNUNET_PROGRAM_run2 (argc, argv, "gnunet-consensus-profiler",
571 "help", 583 "help",
572 options, &run, NULL, GNUNET_YES); 584 options, &run, NULL, GNUNET_YES);
573 return 0; 585 return 0;
574} 586}
diff --git a/src/consensus/gnunet-service-consensus.c b/src/consensus/gnunet-service-consensus.c
index 98fd551b2..8ef70eee8 100644
--- a/src/consensus/gnunet-service-consensus.c
+++ b/src/consensus/gnunet-service-consensus.c
@@ -36,7 +36,8 @@
36#include "consensus.h" 36#include "consensus.h"
37 37
38 38
39enum ReferendumVote { 39enum ReferendumVote
40{
40 /** 41 /**
41 * Vote that nothing should change. 42 * Vote that nothing should change.
42 * This option is never voted explicitly. 43 * This option is never voted explicitly.
@@ -53,7 +54,8 @@ enum ReferendumVote {
53}; 54};
54 55
55 56
56enum EarlyStoppingPhase { 57enum EarlyStoppingPhase
58{
57 EARLY_STOPPING_NONE = 0, 59 EARLY_STOPPING_NONE = 0,
58 EARLY_STOPPING_ONE_MORE = 1, 60 EARLY_STOPPING_ONE_MORE = 1,
59 EARLY_STOPPING_DONE = 2, 61 EARLY_STOPPING_DONE = 2,
@@ -66,7 +68,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
66 * Tuple of integers that together 68 * Tuple of integers that together
67 * identify a task uniquely. 69 * identify a task uniquely.
68 */ 70 */
69struct TaskKey { 71struct TaskKey
72{
70 /** 73 /**
71 * A value from 'enum PhaseKind'. 74 * A value from 'enum PhaseKind'.
72 */ 75 */
@@ -98,14 +101,16 @@ struct TaskKey {
98 101
99 102
100 103
101struct SetKey { 104struct SetKey
105{
102 int set_kind GNUNET_PACKED; 106 int set_kind GNUNET_PACKED;
103 int k1 GNUNET_PACKED; 107 int k1 GNUNET_PACKED;
104 int k2 GNUNET_PACKED; 108 int k2 GNUNET_PACKED;
105}; 109};
106 110
107 111
108struct SetEntry { 112struct SetEntry
113{
109 struct SetKey key; 114 struct SetKey key;
110 struct GNUNET_SET_Handle *h; 115 struct GNUNET_SET_Handle *h;
111 /** 116 /**
@@ -117,13 +122,15 @@ struct SetEntry {
117}; 122};
118 123
119 124
120struct DiffKey { 125struct DiffKey
126{
121 int diff_kind GNUNET_PACKED; 127 int diff_kind GNUNET_PACKED;
122 int k1 GNUNET_PACKED; 128 int k1 GNUNET_PACKED;
123 int k2 GNUNET_PACKED; 129 int k2 GNUNET_PACKED;
124}; 130};
125 131
126struct RfnKey { 132struct RfnKey
133{
127 int rfn_kind GNUNET_PACKED; 134 int rfn_kind GNUNET_PACKED;
128 int k1 GNUNET_PACKED; 135 int k1 GNUNET_PACKED;
129 int k2 GNUNET_PACKED; 136 int k2 GNUNET_PACKED;
@@ -132,7 +139,8 @@ struct RfnKey {
132 139
133GNUNET_NETWORK_STRUCT_END 140GNUNET_NETWORK_STRUCT_END
134 141
135enum PhaseKind { 142enum PhaseKind
143{
136 PHASE_KIND_ALL_TO_ALL, 144 PHASE_KIND_ALL_TO_ALL,
137 PHASE_KIND_ALL_TO_ALL_2, 145 PHASE_KIND_ALL_TO_ALL_2,
138 PHASE_KIND_GRADECAST_LEADER, 146 PHASE_KIND_GRADECAST_LEADER,
@@ -149,7 +157,8 @@ enum PhaseKind {
149}; 157};
150 158
151 159
152enum SetKind { 160enum SetKind
161{
153 SET_KIND_NONE = 0, 162 SET_KIND_NONE = 0,
154 SET_KIND_CURRENT, 163 SET_KIND_CURRENT,
155 /** 164 /**
@@ -160,14 +169,16 @@ enum SetKind {
160 SET_KIND_ECHO_RESULT, 169 SET_KIND_ECHO_RESULT,
161}; 170};
162 171
163enum DiffKind { 172enum DiffKind
173{
164 DIFF_KIND_NONE = 0, 174 DIFF_KIND_NONE = 0,
165 DIFF_KIND_LEADER_PROPOSAL, 175 DIFF_KIND_LEADER_PROPOSAL,
166 DIFF_KIND_LEADER_CONSENSUS, 176 DIFF_KIND_LEADER_CONSENSUS,
167 DIFF_KIND_GRADECAST_RESULT, 177 DIFF_KIND_GRADECAST_RESULT,
168}; 178};
169 179
170enum RfnKind { 180enum RfnKind
181{
171 RFN_KIND_NONE = 0, 182 RFN_KIND_NONE = 0,
172 RFN_KIND_ECHO, 183 RFN_KIND_ECHO,
173 RFN_KIND_CONFIRM, 184 RFN_KIND_CONFIRM,
@@ -175,7 +186,8 @@ enum RfnKind {
175}; 186};
176 187
177 188
178struct SetOpCls { 189struct SetOpCls
190{
179 struct SetKey input_set; 191 struct SetKey input_set;
180 192
181 struct SetKey output_set; 193 struct SetKey output_set;
@@ -190,7 +202,8 @@ struct SetOpCls {
190}; 202};
191 203
192 204
193struct FinishCls { 205struct FinishCls
206{
194 struct SetKey input_set; 207 struct SetKey input_set;
195}; 208};
196 209
@@ -198,7 +211,8 @@ struct FinishCls {
198 * Closure for both @a start_task 211 * Closure for both @a start_task
199 * and @a cancel_task. 212 * and @a cancel_task.
200 */ 213 */
201union TaskFuncCls { 214union TaskFuncCls
215{
202 struct SetOpCls setop; 216 struct SetOpCls setop;
203 struct FinishCls finish; 217 struct FinishCls finish;
204}; 218};
@@ -210,7 +224,8 @@ typedef void (*TaskFunc) (struct TaskEntry *task);
210/* 224/*
211 * Node in the consensus task graph. 225 * Node in the consensus task graph.
212 */ 226 */
213struct TaskEntry { 227struct TaskEntry
228{
214 struct TaskKey key; 229 struct TaskKey key;
215 230
216 struct Step *step; 231 struct Step *step;
@@ -226,7 +241,8 @@ struct TaskEntry {
226}; 241};
227 242
228 243
229struct Step { 244struct Step
245{
230 /** 246 /**
231 * All steps of one session are in a 247 * All steps of one session are in a
232 * linked list for easier deallocation. 248 * linked list for easier deallocation.
@@ -304,7 +320,8 @@ struct Step {
304}; 320};
305 321
306 322
307struct RfnElementInfo { 323struct RfnElementInfo
324{
308 const struct GNUNET_SET_Element *element; 325 const struct GNUNET_SET_Element *element;
309 326
310 /* 327 /*
@@ -320,7 +337,8 @@ struct RfnElementInfo {
320}; 337};
321 338
322 339
323struct ReferendumEntry { 340struct ReferendumEntry
341{
324 struct RfnKey key; 342 struct RfnKey key;
325 343
326 /* 344 /*
@@ -355,7 +373,8 @@ struct ReferendumEntry {
355}; 373};
356 374
357 375
358struct DiffElementInfo { 376struct DiffElementInfo
377{
359 const struct GNUNET_SET_Element *element; 378 const struct GNUNET_SET_Element *element;
360 379
361 /** 380 /**
@@ -369,12 +388,14 @@ struct DiffElementInfo {
369/** 388/**
370 * Weighted diff. 389 * Weighted diff.
371 */ 390 */
372struct DiffEntry { 391struct DiffEntry
392{
373 struct DiffKey key; 393 struct DiffKey key;
374 struct GNUNET_CONTAINER_MultiHashMap *changes; 394 struct GNUNET_CONTAINER_MultiHashMap *changes;
375}; 395};
376 396
377struct SetHandle { 397struct SetHandle
398{
378 struct SetHandle *prev; 399 struct SetHandle *prev;
379 struct SetHandle *next; 400 struct SetHandle *next;
380 401
@@ -386,7 +407,8 @@ struct SetHandle {
386/** 407/**
387 * A consensus session consists of one local client and the remote authorities. 408 * A consensus session consists of one local client and the remote authorities.
388 */ 409 */
389struct ConsensusSession { 410struct ConsensusSession
411{
390 /** 412 /**
391 * Consensus sessions are kept in a DLL. 413 * Consensus sessions are kept in a DLL.
392 */ 414 */
@@ -518,147 +540,147 @@ struct GNUNET_STATISTICS_Handle *statistics;
518 540
519 541
520static void 542static void
521finish_task(struct TaskEntry *task); 543finish_task (struct TaskEntry *task);
522 544
523 545
524static void 546static void
525run_ready_steps(struct ConsensusSession *session); 547run_ready_steps (struct ConsensusSession *session);
526 548
527 549
528static const char * 550static const char *
529phasename(uint16_t phase) 551phasename (uint16_t phase)
530{ 552{
531 switch (phase) 553 switch (phase)
532 { 554 {
533 case PHASE_KIND_ALL_TO_ALL: return "ALL_TO_ALL"; 555 case PHASE_KIND_ALL_TO_ALL: return "ALL_TO_ALL";
534 556
535 case PHASE_KIND_ALL_TO_ALL_2: return "ALL_TO_ALL_2"; 557 case PHASE_KIND_ALL_TO_ALL_2: return "ALL_TO_ALL_2";
536 558
537 case PHASE_KIND_FINISH: return "FINISH"; 559 case PHASE_KIND_FINISH: return "FINISH";
538 560
539 case PHASE_KIND_GRADECAST_LEADER: return "GRADECAST_LEADER"; 561 case PHASE_KIND_GRADECAST_LEADER: return "GRADECAST_LEADER";
540 562
541 case PHASE_KIND_GRADECAST_ECHO: return "GRADECAST_ECHO"; 563 case PHASE_KIND_GRADECAST_ECHO: return "GRADECAST_ECHO";
542 564
543 case PHASE_KIND_GRADECAST_ECHO_GRADE: return "GRADECAST_ECHO_GRADE"; 565 case PHASE_KIND_GRADECAST_ECHO_GRADE: return "GRADECAST_ECHO_GRADE";
544 566
545 case PHASE_KIND_GRADECAST_CONFIRM: return "GRADECAST_CONFIRM"; 567 case PHASE_KIND_GRADECAST_CONFIRM: return "GRADECAST_CONFIRM";
546 568
547 case PHASE_KIND_GRADECAST_CONFIRM_GRADE: return "GRADECAST_CONFIRM_GRADE"; 569 case PHASE_KIND_GRADECAST_CONFIRM_GRADE: return "GRADECAST_CONFIRM_GRADE";
548 570
549 case PHASE_KIND_APPLY_REP: return "APPLY_REP"; 571 case PHASE_KIND_APPLY_REP: return "APPLY_REP";
550 572
551 default: return "(unknown)"; 573 default: return "(unknown)";
552 } 574 }
553} 575}
554 576
555 577
556static const char * 578static const char *
557setname(uint16_t kind) 579setname (uint16_t kind)
558{ 580{
559 switch (kind) 581 switch (kind)
560 { 582 {
561 case SET_KIND_CURRENT: return "CURRENT"; 583 case SET_KIND_CURRENT: return "CURRENT";
562 584
563 case SET_KIND_LEADER_PROPOSAL: return "LEADER_PROPOSAL"; 585 case SET_KIND_LEADER_PROPOSAL: return "LEADER_PROPOSAL";
564 586
565 case SET_KIND_NONE: return "NONE"; 587 case SET_KIND_NONE: return "NONE";
566 588
567 default: return "(unknown)"; 589 default: return "(unknown)";
568 } 590 }
569} 591}
570 592
571static const char * 593static const char *
572rfnname(uint16_t kind) 594rfnname (uint16_t kind)
573{ 595{
574 switch (kind) 596 switch (kind)
575 { 597 {
576 case RFN_KIND_NONE: return "NONE"; 598 case RFN_KIND_NONE: return "NONE";
577 599
578 case RFN_KIND_ECHO: return "ECHO"; 600 case RFN_KIND_ECHO: return "ECHO";
579 601
580 case RFN_KIND_CONFIRM: return "CONFIRM"; 602 case RFN_KIND_CONFIRM: return "CONFIRM";
581 603
582 default: return "(unknown)"; 604 default: return "(unknown)";
583 } 605 }
584} 606}
585 607
586static const char * 608static const char *
587diffname(uint16_t kind) 609diffname (uint16_t kind)
588{ 610{
589 switch (kind) 611 switch (kind)
590 { 612 {
591 case DIFF_KIND_NONE: return "NONE"; 613 case DIFF_KIND_NONE: return "NONE";
592 614
593 case DIFF_KIND_LEADER_CONSENSUS: return "LEADER_CONSENSUS"; 615 case DIFF_KIND_LEADER_CONSENSUS: return "LEADER_CONSENSUS";
594 616
595 case DIFF_KIND_GRADECAST_RESULT: return "GRADECAST_RESULT"; 617 case DIFF_KIND_GRADECAST_RESULT: return "GRADECAST_RESULT";
596 618
597 case DIFF_KIND_LEADER_PROPOSAL: return "LEADER_PROPOSAL"; 619 case DIFF_KIND_LEADER_PROPOSAL: return "LEADER_PROPOSAL";
598 620
599 default: return "(unknown)"; 621 default: return "(unknown)";
600 } 622 }
601} 623}
602 624
603#ifdef GNUNET_EXTRA_LOGGING 625#ifdef GNUNET_EXTRA_LOGGING
604 626
605 627
606static const char * 628static const char *
607debug_str_element(const struct GNUNET_SET_Element *el) 629debug_str_element (const struct GNUNET_SET_Element *el)
608{ 630{
609 struct GNUNET_HashCode hash; 631 struct GNUNET_HashCode hash;
610 632
611 GNUNET_SET_element_hash(el, &hash); 633 GNUNET_SET_element_hash (el, &hash);
612 634
613 return GNUNET_h2s(&hash); 635 return GNUNET_h2s (&hash);
614} 636}
615 637
616static const char * 638static const char *
617debug_str_task_key(struct TaskKey *tk) 639debug_str_task_key (struct TaskKey *tk)
618{ 640{
619 static char buf[256]; 641 static char buf[256];
620 642
621 snprintf(buf, sizeof(buf), 643 snprintf (buf, sizeof(buf),
622 "TaskKey kind=%s, p1=%d, p2=%d, l=%d, rep=%d", 644 "TaskKey kind=%s, p1=%d, p2=%d, l=%d, rep=%d",
623 phasename(tk->kind), tk->peer1, tk->peer2, 645 phasename (tk->kind), tk->peer1, tk->peer2,
624 tk->leader, tk->repetition); 646 tk->leader, tk->repetition);
625 647
626 return buf; 648 return buf;
627} 649}
628 650
629static const char * 651static const char *
630debug_str_diff_key(struct DiffKey *dk) 652debug_str_diff_key (struct DiffKey *dk)
631{ 653{
632 static char buf[256]; 654 static char buf[256];
633 655
634 snprintf(buf, sizeof(buf), 656 snprintf (buf, sizeof(buf),
635 "DiffKey kind=%s, k1=%d, k2=%d", 657 "DiffKey kind=%s, k1=%d, k2=%d",
636 diffname(dk->diff_kind), dk->k1, dk->k2); 658 diffname (dk->diff_kind), dk->k1, dk->k2);
637 659
638 return buf; 660 return buf;
639} 661}
640 662
641static const char * 663static const char *
642debug_str_set_key(const struct SetKey *sk) 664debug_str_set_key (const struct SetKey *sk)
643{ 665{
644 static char buf[256]; 666 static char buf[256];
645 667
646 snprintf(buf, sizeof(buf), 668 snprintf (buf, sizeof(buf),
647 "SetKey kind=%s, k1=%d, k2=%d", 669 "SetKey kind=%s, k1=%d, k2=%d",
648 setname(sk->set_kind), sk->k1, sk->k2); 670 setname (sk->set_kind), sk->k1, sk->k2);
649 671
650 return buf; 672 return buf;
651} 673}
652 674
653 675
654static const char * 676static const char *
655debug_str_rfn_key(const struct RfnKey *rk) 677debug_str_rfn_key (const struct RfnKey *rk)
656{ 678{
657 static char buf[256]; 679 static char buf[256];
658 680
659 snprintf(buf, sizeof(buf), 681 snprintf (buf, sizeof(buf),
660 "RfnKey kind=%s, k1=%d, k2=%d", 682 "RfnKey kind=%s, k1=%d, k2=%d",
661 rfnname(rk->rfn_kind), rk->k1, rk->k2); 683 rfnname (rk->rfn_kind), rk->k1, rk->k2);
662 684
663 return buf; 685 return buf;
664} 686}
@@ -676,164 +698,170 @@ debug_str_rfn_key(const struct RfnKey *rk)
676 * @return #GNUNET_YES to continue iterating, #GNUNET_NO to stop. 698 * @return #GNUNET_YES to continue iterating, #GNUNET_NO to stop.
677 */ 699 */
678static int 700static int
679send_to_client_iter(void *cls, 701send_to_client_iter (void *cls,
680 const struct GNUNET_SET_Element *element) 702 const struct GNUNET_SET_Element *element)
681{ 703{
682 struct TaskEntry *task = (struct TaskEntry *)cls; 704 struct TaskEntry *task = (struct TaskEntry *) cls;
683 struct ConsensusSession *session = task->step->session; 705 struct ConsensusSession *session = task->step->session;
684 struct GNUNET_MQ_Envelope *ev; 706 struct GNUNET_MQ_Envelope *ev;
685 707
686 if (NULL != element) 708 if (NULL != element)
687 { 709 {
688 struct GNUNET_CONSENSUS_ElementMessage *m; 710 struct GNUNET_CONSENSUS_ElementMessage *m;
689 const struct ConsensusElement *ce; 711 const struct ConsensusElement *ce;
690 712
691 GNUNET_assert(GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT == element->element_type); 713 GNUNET_assert (GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT ==
692 ce = element->data; 714 element->element_type);
693 715 ce = element->data;
694 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "marker is %u\n", (unsigned)ce->marker); 716
695 717 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "marker is %u\n",
696 if (0 != ce->marker) 718 (unsigned) ce->marker);
697 return GNUNET_YES; 719
698 720 if (0 != ce->marker)
699 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 721 return GNUNET_YES;
700 "P%d: sending element %s to client\n", 722
701 session->local_peer_idx, 723 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
702 debug_str_element(element)); 724 "P%d: sending element %s to client\n",
703 725 session->local_peer_idx,
704 ev = GNUNET_MQ_msg_extra(m, element->size - sizeof(struct ConsensusElement), 726 debug_str_element (element));
705 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_RECEIVED_ELEMENT); 727
706 m->element_type = ce->payload_type; 728 ev = GNUNET_MQ_msg_extra (m, element->size - sizeof(struct
707 GNUNET_memcpy(&m[1], &ce[1], element->size - sizeof(struct ConsensusElement)); 729 ConsensusElement),
708 GNUNET_MQ_send(session->client_mq, ev); 730 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_RECEIVED_ELEMENT);
709 } 731 m->element_type = ce->payload_type;
732 GNUNET_memcpy (&m[1], &ce[1], element->size - sizeof(struct
733 ConsensusElement));
734 GNUNET_MQ_send (session->client_mq, ev);
735 }
710 else 736 else
711 { 737 {
712 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 738 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
713 "P%d: finished iterating elements for client\n", 739 "P%d: finished iterating elements for client\n",
714 session->local_peer_idx); 740 session->local_peer_idx);
715 ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE_DONE); 741 ev = GNUNET_MQ_msg_header (
716 GNUNET_MQ_send(session->client_mq, ev); 742 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE_DONE);
717 } 743 GNUNET_MQ_send (session->client_mq, ev);
744 }
718 return GNUNET_YES; 745 return GNUNET_YES;
719} 746}
720 747
721 748
722static struct SetEntry * 749static struct SetEntry *
723lookup_set(struct ConsensusSession *session, struct SetKey *key) 750lookup_set (struct ConsensusSession *session, struct SetKey *key)
724{ 751{
725 struct GNUNET_HashCode hash; 752 struct GNUNET_HashCode hash;
726 753
727 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 754 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
728 "P%u: looking up set {%s}\n", 755 "P%u: looking up set {%s}\n",
729 session->local_peer_idx, 756 session->local_peer_idx,
730 debug_str_set_key(key)); 757 debug_str_set_key (key));
731 758
732 GNUNET_assert(SET_KIND_NONE != key->set_kind); 759 GNUNET_assert (SET_KIND_NONE != key->set_kind);
733 GNUNET_CRYPTO_hash(key, sizeof(struct SetKey), &hash); 760 GNUNET_CRYPTO_hash (key, sizeof(struct SetKey), &hash);
734 return GNUNET_CONTAINER_multihashmap_get(session->setmap, &hash); 761 return GNUNET_CONTAINER_multihashmap_get (session->setmap, &hash);
735} 762}
736 763
737 764
738static struct DiffEntry * 765static struct DiffEntry *
739lookup_diff(struct ConsensusSession *session, struct DiffKey *key) 766lookup_diff (struct ConsensusSession *session, struct DiffKey *key)
740{ 767{
741 struct GNUNET_HashCode hash; 768 struct GNUNET_HashCode hash;
742 769
743 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 770 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
744 "P%u: looking up diff {%s}\n", 771 "P%u: looking up diff {%s}\n",
745 session->local_peer_idx, 772 session->local_peer_idx,
746 debug_str_diff_key(key)); 773 debug_str_diff_key (key));
747 774
748 GNUNET_assert(DIFF_KIND_NONE != key->diff_kind); 775 GNUNET_assert (DIFF_KIND_NONE != key->diff_kind);
749 GNUNET_CRYPTO_hash(key, sizeof(struct DiffKey), &hash); 776 GNUNET_CRYPTO_hash (key, sizeof(struct DiffKey), &hash);
750 return GNUNET_CONTAINER_multihashmap_get(session->diffmap, &hash); 777 return GNUNET_CONTAINER_multihashmap_get (session->diffmap, &hash);
751} 778}
752 779
753 780
754static struct ReferendumEntry * 781static struct ReferendumEntry *
755lookup_rfn(struct ConsensusSession *session, struct RfnKey *key) 782lookup_rfn (struct ConsensusSession *session, struct RfnKey *key)
756{ 783{
757 struct GNUNET_HashCode hash; 784 struct GNUNET_HashCode hash;
758 785
759 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 786 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
760 "P%u: looking up rfn {%s}\n", 787 "P%u: looking up rfn {%s}\n",
761 session->local_peer_idx, 788 session->local_peer_idx,
762 debug_str_rfn_key(key)); 789 debug_str_rfn_key (key));
763 790
764 GNUNET_assert(RFN_KIND_NONE != key->rfn_kind); 791 GNUNET_assert (RFN_KIND_NONE != key->rfn_kind);
765 GNUNET_CRYPTO_hash(key, sizeof(struct RfnKey), &hash); 792 GNUNET_CRYPTO_hash (key, sizeof(struct RfnKey), &hash);
766 return GNUNET_CONTAINER_multihashmap_get(session->rfnmap, &hash); 793 return GNUNET_CONTAINER_multihashmap_get (session->rfnmap, &hash);
767} 794}
768 795
769 796
770static void 797static void
771diff_insert(struct DiffEntry *diff, 798diff_insert (struct DiffEntry *diff,
772 int weight, 799 int weight,
773 const struct GNUNET_SET_Element *element) 800 const struct GNUNET_SET_Element *element)
774{ 801{
775 struct DiffElementInfo *di; 802 struct DiffElementInfo *di;
776 struct GNUNET_HashCode hash; 803 struct GNUNET_HashCode hash;
777 804
778 GNUNET_assert((1 == weight) || (-1 == weight)); 805 GNUNET_assert ((1 == weight) || (-1 == weight));
779 806
780 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 807 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
781 "diff_insert with element size %u\n", 808 "diff_insert with element size %u\n",
782 element->size); 809 element->size);
783 810
784 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 811 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
785 "hashing element\n"); 812 "hashing element\n");
786 813
787 GNUNET_SET_element_hash(element, &hash); 814 GNUNET_SET_element_hash (element, &hash);
788 815
789 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 816 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
790 "hashed element\n"); 817 "hashed element\n");
791 818
792 di = GNUNET_CONTAINER_multihashmap_get(diff->changes, &hash); 819 di = GNUNET_CONTAINER_multihashmap_get (diff->changes, &hash);
793 820
794 if (NULL == di) 821 if (NULL == di)
795 { 822 {
796 di = GNUNET_new(struct DiffElementInfo); 823 di = GNUNET_new (struct DiffElementInfo);
797 di->element = GNUNET_SET_element_dup(element); 824 di->element = GNUNET_SET_element_dup (element);
798 GNUNET_assert(GNUNET_OK == 825 GNUNET_assert (GNUNET_OK ==
799 GNUNET_CONTAINER_multihashmap_put(diff->changes, 826 GNUNET_CONTAINER_multihashmap_put (diff->changes,
800 &hash, di, 827 &hash, di,
801 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 828 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
802 } 829 }
803 830
804 di->weight = weight; 831 di->weight = weight;
805} 832}
806 833
807 834
808static void 835static void
809rfn_commit(struct ReferendumEntry *rfn, 836rfn_commit (struct ReferendumEntry *rfn,
810 uint16_t commit_peer) 837 uint16_t commit_peer)
811{ 838{
812 GNUNET_assert(commit_peer < rfn->num_peers); 839 GNUNET_assert (commit_peer < rfn->num_peers);
813 840
814 rfn->peer_commited[commit_peer] = GNUNET_YES; 841 rfn->peer_commited[commit_peer] = GNUNET_YES;
815} 842}
816 843
817 844
818static void 845static void
819rfn_contest(struct ReferendumEntry *rfn, 846rfn_contest (struct ReferendumEntry *rfn,
820 uint16_t contested_peer) 847 uint16_t contested_peer)
821{ 848{
822 GNUNET_assert(contested_peer < rfn->num_peers); 849 GNUNET_assert (contested_peer < rfn->num_peers);
823 850
824 rfn->peer_contested[contested_peer] = GNUNET_YES; 851 rfn->peer_contested[contested_peer] = GNUNET_YES;
825} 852}
826 853
827 854
828static uint16_t 855static uint16_t
829rfn_noncontested(struct ReferendumEntry *rfn) 856rfn_noncontested (struct ReferendumEntry *rfn)
830{ 857{
831 uint16_t i; 858 uint16_t i;
832 uint16_t ret; 859 uint16_t ret;
833 860
834 ret = 0; 861 ret = 0;
835 for (i = 0; i < rfn->num_peers; i++) 862 for (i = 0; i < rfn->num_peers; i++)
836 if ((GNUNET_YES == rfn->peer_commited[i]) && (GNUNET_NO == rfn->peer_contested[i])) 863 if ((GNUNET_YES == rfn->peer_commited[i]) && (GNUNET_NO ==
864 rfn->peer_contested[i]))
837 ret++; 865 ret++;
838 866
839 return ret; 867 return ret;
@@ -841,33 +869,33 @@ rfn_noncontested(struct ReferendumEntry *rfn)
841 869
842 870
843static void 871static void
844rfn_vote(struct ReferendumEntry *rfn, 872rfn_vote (struct ReferendumEntry *rfn,
845 uint16_t voting_peer, 873 uint16_t voting_peer,
846 enum ReferendumVote vote, 874 enum ReferendumVote vote,
847 const struct GNUNET_SET_Element *element) 875 const struct GNUNET_SET_Element *element)
848{ 876{
849 struct RfnElementInfo *ri; 877 struct RfnElementInfo *ri;
850 struct GNUNET_HashCode hash; 878 struct GNUNET_HashCode hash;
851 879
852 GNUNET_assert(voting_peer < rfn->num_peers); 880 GNUNET_assert (voting_peer < rfn->num_peers);
853 881
854 /* Explicit voting only makes sense with VOTE_ADD or VOTE_REMOTE, 882 /* Explicit voting only makes sense with VOTE_ADD or VOTE_REMOTE,
855 since VOTE_KEEP is implicit in not voting. */ 883 since VOTE_KEEP is implicit in not voting. */
856 GNUNET_assert((VOTE_ADD == vote) || (VOTE_REMOVE == vote)); 884 GNUNET_assert ((VOTE_ADD == vote) || (VOTE_REMOVE == vote));
857 885
858 GNUNET_SET_element_hash(element, &hash); 886 GNUNET_SET_element_hash (element, &hash);
859 ri = GNUNET_CONTAINER_multihashmap_get(rfn->rfn_elements, &hash); 887 ri = GNUNET_CONTAINER_multihashmap_get (rfn->rfn_elements, &hash);
860 888
861 if (NULL == ri) 889 if (NULL == ri)
862 { 890 {
863 ri = GNUNET_new(struct RfnElementInfo); 891 ri = GNUNET_new (struct RfnElementInfo);
864 ri->element = GNUNET_SET_element_dup(element); 892 ri->element = GNUNET_SET_element_dup (element);
865 ri->votes = GNUNET_new_array(rfn->num_peers, int); 893 ri->votes = GNUNET_new_array (rfn->num_peers, int);
866 GNUNET_assert(GNUNET_OK == 894 GNUNET_assert (GNUNET_OK ==
867 GNUNET_CONTAINER_multihashmap_put(rfn->rfn_elements, 895 GNUNET_CONTAINER_multihashmap_put (rfn->rfn_elements,
868 &hash, ri, 896 &hash, ri,
869 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 897 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
870 } 898 }
871 899
872 ri->votes[voting_peer] = GNUNET_YES; 900 ri->votes[voting_peer] = GNUNET_YES;
873 ri->proposal = vote; 901 ri->proposal = vote;
@@ -875,7 +903,7 @@ rfn_vote(struct ReferendumEntry *rfn,
875 903
876 904
877static uint16_t 905static uint16_t
878task_other_peer(struct TaskEntry *task) 906task_other_peer (struct TaskEntry *task)
879{ 907{
880 uint16_t me = task->step->session->local_peer_idx; 908 uint16_t me = task->step->session->local_peer_idx;
881 909
@@ -886,10 +914,10 @@ task_other_peer(struct TaskEntry *task)
886 914
887 915
888static int 916static int
889cmp_uint64_t(const void *pa, const void *pb) 917cmp_uint64_t (const void *pa, const void *pb)
890{ 918{
891 uint64_t a = *(uint64_t *)pa; 919 uint64_t a = *(uint64_t *) pa;
892 uint64_t b = *(uint64_t *)pb; 920 uint64_t b = *(uint64_t *) pb;
893 921
894 if (a == b) 922 if (a == b)
895 return 0; 923 return 0;
@@ -909,10 +937,10 @@ cmp_uint64_t(const void *pa, const void *pb)
909 * @param status see enum GNUNET_SET_Status 937 * @param status see enum GNUNET_SET_Status
910 */ 938 */
911static void 939static void
912set_result_cb(void *cls, 940set_result_cb (void *cls,
913 const struct GNUNET_SET_Element *element, 941 const struct GNUNET_SET_Element *element,
914 uint64_t current_size, 942 uint64_t current_size,
915 enum GNUNET_SET_Status status) 943 enum GNUNET_SET_Status status)
916{ 944{
917 struct TaskEntry *task = cls; 945 struct TaskEntry *task = cls;
918 struct ConsensusSession *session = task->step->session; 946 struct ConsensusSession *session = task->step->session;
@@ -924,246 +952,250 @@ set_result_cb(void *cls,
924 const struct ConsensusElement *consensus_element = NULL; 952 const struct ConsensusElement *consensus_element = NULL;
925 953
926 if (NULL != element) 954 if (NULL != element)
927 { 955 {
928 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 956 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
929 "P%u: got element of type %u, status %u\n", 957 "P%u: got element of type %u, status %u\n",
930 session->local_peer_idx, 958 session->local_peer_idx,
931 (unsigned)element->element_type, 959 (unsigned) element->element_type,
932 (unsigned)status); 960 (unsigned) status);
933 GNUNET_assert(GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT == element->element_type); 961 GNUNET_assert (GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT ==
934 consensus_element = element->data; 962 element->element_type);
935 } 963 consensus_element = element->data;
964 }
936 965
937 setop = &task->cls.setop; 966 setop = &task->cls.setop;
938 967
939 968
940 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 969 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
941 "P%u: got set result for {%s}, status %u\n", 970 "P%u: got set result for {%s}, status %u\n",
942 session->local_peer_idx, 971 session->local_peer_idx,
943 debug_str_task_key(&task->key), 972 debug_str_task_key (&task->key),
944 status); 973 status);
945 974
946 if (GNUNET_NO == task->is_started) 975 if (GNUNET_NO == task->is_started)
947 { 976 {
948 GNUNET_break_op(0); 977 GNUNET_break_op (0);
949 return; 978 return;
950 } 979 }
951 980
952 if (GNUNET_YES == task->is_finished) 981 if (GNUNET_YES == task->is_finished)
953 { 982 {
954 GNUNET_break_op(0); 983 GNUNET_break_op (0);
955 return; 984 return;
956 } 985 }
957 986
958 other_idx = task_other_peer(task); 987 other_idx = task_other_peer (task);
959 988
960 if (SET_KIND_NONE != setop->output_set.set_kind) 989 if (SET_KIND_NONE != setop->output_set.set_kind)
961 { 990 {
962 output_set = lookup_set(session, &setop->output_set); 991 output_set = lookup_set (session, &setop->output_set);
963 GNUNET_assert(NULL != output_set); 992 GNUNET_assert (NULL != output_set);
964 } 993 }
965 994
966 if (DIFF_KIND_NONE != setop->output_diff.diff_kind) 995 if (DIFF_KIND_NONE != setop->output_diff.diff_kind)
967 { 996 {
968 output_diff = lookup_diff(session, &setop->output_diff); 997 output_diff = lookup_diff (session, &setop->output_diff);
969 GNUNET_assert(NULL != output_diff); 998 GNUNET_assert (NULL != output_diff);
970 } 999 }
971 1000
972 if (RFN_KIND_NONE != setop->output_rfn.rfn_kind) 1001 if (RFN_KIND_NONE != setop->output_rfn.rfn_kind)
973 { 1002 {
974 output_rfn = lookup_rfn(session, &setop->output_rfn); 1003 output_rfn = lookup_rfn (session, &setop->output_rfn);
975 GNUNET_assert(NULL != output_rfn); 1004 GNUNET_assert (NULL != output_rfn);
976 } 1005 }
977 1006
978 if (GNUNET_YES == session->peers_blacklisted[other_idx]) 1007 if (GNUNET_YES == session->peers_blacklisted[other_idx])
979 { 1008 {
980 /* Peer might have been blacklisted 1009 /* Peer might have been blacklisted
981 by a gradecast running in parallel, ignore elements from now */ 1010 by a gradecast running in parallel, ignore elements from now */
982 if (GNUNET_SET_STATUS_ADD_LOCAL == status) 1011 if (GNUNET_SET_STATUS_ADD_LOCAL == status)
983 return; 1012 return;
984 if (GNUNET_SET_STATUS_ADD_REMOTE == status) 1013 if (GNUNET_SET_STATUS_ADD_REMOTE == status)
985 return; 1014 return;
986 } 1015 }
987 1016
988 if ((NULL != consensus_element) && (0 != consensus_element->marker)) 1017 if ((NULL != consensus_element) && (0 != consensus_element->marker))
1018 {
1019 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1020 "P%u: got some marker\n",
1021 session->local_peer_idx);
1022 if ((GNUNET_YES == setop->transceive_contested) &&
1023 (CONSENSUS_MARKER_CONTESTED == consensus_element->marker))
1024 {
1025 GNUNET_assert (NULL != output_rfn);
1026 rfn_contest (output_rfn, task_other_peer (task));
1027 return;
1028 }
1029
1030 if (CONSENSUS_MARKER_SIZE == consensus_element->marker)
989 { 1031 {
990 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1032 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
991 "P%u: got some marker\n", 1033 "P%u: got size marker\n",
992 session->local_peer_idx); 1034 session->local_peer_idx);
993 if ((GNUNET_YES == setop->transceive_contested) &&
994 (CONSENSUS_MARKER_CONTESTED == consensus_element->marker))
995 {
996 GNUNET_assert(NULL != output_rfn);
997 rfn_contest(output_rfn, task_other_peer(task));
998 return;
999 }
1000 1035
1001 if (CONSENSUS_MARKER_SIZE == consensus_element->marker)
1002 {
1003 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1004 "P%u: got size marker\n",
1005 session->local_peer_idx);
1006
1007
1008 struct ConsensusSizeElement *cse = (void *)consensus_element;
1009
1010 if (cse->sender_index == other_idx)
1011 {
1012 if (NULL == session->first_sizes_received)
1013 session->first_sizes_received = GNUNET_new_array(session->num_peers, uint64_t);
1014 session->first_sizes_received[other_idx] = GNUNET_ntohll(cse->size);
1015
1016 uint64_t *copy = GNUNET_memdup(session->first_sizes_received, sizeof(uint64_t) * session->num_peers);
1017 qsort(copy, session->num_peers, sizeof(uint64_t), cmp_uint64_t);
1018 session->lower_bound = copy[session->num_peers / 3 + 1];
1019 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1020 "P%u: lower bound %llu\n",
1021 session->local_peer_idx,
1022 (long long)session->lower_bound);
1023 GNUNET_free(copy);
1024 }
1025 return;
1026 }
1027 1036
1037 struct ConsensusSizeElement *cse = (void *) consensus_element;
1038
1039 if (cse->sender_index == other_idx)
1040 {
1041 if (NULL == session->first_sizes_received)
1042 session->first_sizes_received = GNUNET_new_array (session->num_peers,
1043 uint64_t);
1044 session->first_sizes_received[other_idx] = GNUNET_ntohll (cse->size);
1045
1046 uint64_t *copy = GNUNET_memdup (session->first_sizes_received,
1047 sizeof(uint64_t) * session->num_peers);
1048 qsort (copy, session->num_peers, sizeof(uint64_t), cmp_uint64_t);
1049 session->lower_bound = copy[session->num_peers / 3 + 1];
1050 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1051 "P%u: lower bound %llu\n",
1052 session->local_peer_idx,
1053 (long long) session->lower_bound);
1054 GNUNET_free (copy);
1055 }
1028 return; 1056 return;
1029 } 1057 }
1030 1058
1059 return;
1060 }
1061
1031 switch (status) 1062 switch (status)
1032 { 1063 {
1033 case GNUNET_SET_STATUS_ADD_LOCAL: 1064 case GNUNET_SET_STATUS_ADD_LOCAL:
1034 GNUNET_assert(NULL != consensus_element); 1065 GNUNET_assert (NULL != consensus_element);
1035 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1066 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1036 "Adding element in Task {%s}\n", 1067 "Adding element in Task {%s}\n",
1037 debug_str_task_key(&task->key)); 1068 debug_str_task_key (&task->key));
1038 if (NULL != output_set) 1069 if (NULL != output_set)
1039 { 1070 {
1040 // FIXME: record pending adds, use callback 1071 // FIXME: record pending adds, use callback
1041 GNUNET_SET_add_element(output_set->h, 1072 GNUNET_SET_add_element (output_set->h,
1042 element, 1073 element,
1043 NULL, 1074 NULL,
1044 NULL); 1075 NULL);
1045#ifdef GNUNET_EXTRA_LOGGING 1076#ifdef GNUNET_EXTRA_LOGGING
1046 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1077 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1047 "P%u: adding element %s into set {%s} of task {%s}\n", 1078 "P%u: adding element %s into set {%s} of task {%s}\n",
1048 session->local_peer_idx, 1079 session->local_peer_idx,
1049 debug_str_element(element), 1080 debug_str_element (element),
1050 debug_str_set_key(&setop->output_set), 1081 debug_str_set_key (&setop->output_set),
1051 debug_str_task_key(&task->key)); 1082 debug_str_task_key (&task->key));
1052#endif 1083#endif
1053 } 1084 }
1054 if (NULL != output_diff) 1085 if (NULL != output_diff)
1055 { 1086 {
1056 diff_insert(output_diff, 1, element); 1087 diff_insert (output_diff, 1, element);
1057#ifdef GNUNET_EXTRA_LOGGING 1088#ifdef GNUNET_EXTRA_LOGGING
1058 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1089 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1059 "P%u: adding element %s into diff {%s} of task {%s}\n", 1090 "P%u: adding element %s into diff {%s} of task {%s}\n",
1060 session->local_peer_idx, 1091 session->local_peer_idx,
1061 debug_str_element(element), 1092 debug_str_element (element),
1062 debug_str_diff_key(&setop->output_diff), 1093 debug_str_diff_key (&setop->output_diff),
1063 debug_str_task_key(&task->key)); 1094 debug_str_task_key (&task->key));
1064#endif 1095#endif
1065 } 1096 }
1066 if (NULL != output_rfn) 1097 if (NULL != output_rfn)
1067 { 1098 {
1068 rfn_vote(output_rfn, task_other_peer(task), VOTE_ADD, element); 1099 rfn_vote (output_rfn, task_other_peer (task), VOTE_ADD, element);
1069#ifdef GNUNET_EXTRA_LOGGING 1100#ifdef GNUNET_EXTRA_LOGGING
1070 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1101 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1071 "P%u: adding element %s into rfn {%s} of task {%s}\n", 1102 "P%u: adding element %s into rfn {%s} of task {%s}\n",
1072 session->local_peer_idx, 1103 session->local_peer_idx,
1073 debug_str_element(element), 1104 debug_str_element (element),
1074 debug_str_rfn_key(&setop->output_rfn), 1105 debug_str_rfn_key (&setop->output_rfn),
1075 debug_str_task_key(&task->key)); 1106 debug_str_task_key (&task->key));
1076#endif 1107#endif
1077 } 1108 }
1078 // XXX: add result to structures in task 1109 // XXX: add result to structures in task
1079 break; 1110 break;
1080 1111
1081 case GNUNET_SET_STATUS_ADD_REMOTE: 1112 case GNUNET_SET_STATUS_ADD_REMOTE:
1082 GNUNET_assert(NULL != consensus_element); 1113 GNUNET_assert (NULL != consensus_element);
1083 if (GNUNET_YES == setop->do_not_remove) 1114 if (GNUNET_YES == setop->do_not_remove)
1084 break; 1115 break;
1085 if (CONSENSUS_MARKER_CONTESTED == consensus_element->marker) 1116 if (CONSENSUS_MARKER_CONTESTED == consensus_element->marker)
1086 break; 1117 break;
1087 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1088 "Removing element in Task {%s}\n", 1119 "Removing element in Task {%s}\n",
1089 debug_str_task_key(&task->key)); 1120 debug_str_task_key (&task->key));
1090 if (NULL != output_set) 1121 if (NULL != output_set)
1091 { 1122 {
1092 // FIXME: record pending adds, use callback 1123 // FIXME: record pending adds, use callback
1093 GNUNET_SET_remove_element(output_set->h, 1124 GNUNET_SET_remove_element (output_set->h,
1094 element, 1125 element,
1095 NULL, 1126 NULL,
1096 NULL); 1127 NULL);
1097#ifdef GNUNET_EXTRA_LOGGING 1128#ifdef GNUNET_EXTRA_LOGGING
1098 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1129 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1099 "P%u: removing element %s from set {%s} of task {%s}\n", 1130 "P%u: removing element %s from set {%s} of task {%s}\n",
1100 session->local_peer_idx, 1131 session->local_peer_idx,
1101 debug_str_element(element), 1132 debug_str_element (element),
1102 debug_str_set_key(&setop->output_set), 1133 debug_str_set_key (&setop->output_set),
1103 debug_str_task_key(&task->key)); 1134 debug_str_task_key (&task->key));
1104#endif 1135#endif
1105 } 1136 }
1106 if (NULL != output_diff) 1137 if (NULL != output_diff)
1107 { 1138 {
1108 diff_insert(output_diff, -1, element); 1139 diff_insert (output_diff, -1, element);
1109#ifdef GNUNET_EXTRA_LOGGING 1140#ifdef GNUNET_EXTRA_LOGGING
1110 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1141 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1111 "P%u: removing element %s from diff {%s} of task {%s}\n", 1142 "P%u: removing element %s from diff {%s} of task {%s}\n",
1112 session->local_peer_idx, 1143 session->local_peer_idx,
1113 debug_str_element(element), 1144 debug_str_element (element),
1114 debug_str_diff_key(&setop->output_diff), 1145 debug_str_diff_key (&setop->output_diff),
1115 debug_str_task_key(&task->key)); 1146 debug_str_task_key (&task->key));
1116#endif 1147#endif
1117 } 1148 }
1118 if (NULL != output_rfn) 1149 if (NULL != output_rfn)
1119 { 1150 {
1120 rfn_vote(output_rfn, task_other_peer(task), VOTE_REMOVE, element); 1151 rfn_vote (output_rfn, task_other_peer (task), VOTE_REMOVE, element);
1121#ifdef GNUNET_EXTRA_LOGGING 1152#ifdef GNUNET_EXTRA_LOGGING
1122 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1123 "P%u: removing element %s from rfn {%s} of task {%s}\n", 1154 "P%u: removing element %s from rfn {%s} of task {%s}\n",
1124 session->local_peer_idx, 1155 session->local_peer_idx,
1125 debug_str_element(element), 1156 debug_str_element (element),
1126 debug_str_rfn_key(&setop->output_rfn), 1157 debug_str_rfn_key (&setop->output_rfn),
1127 debug_str_task_key(&task->key)); 1158 debug_str_task_key (&task->key));
1128#endif 1159#endif
1129 } 1160 }
1130 break; 1161 break;
1131 1162
1132 case GNUNET_SET_STATUS_DONE: 1163 case GNUNET_SET_STATUS_DONE:
1133 // XXX: check first if any changes to the underlying 1164 // XXX: check first if any changes to the underlying
1134 // set are still pending 1165 // set are still pending
1135 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1136 "P%u: Finishing setop in Task {%s} (%u/%u)\n", 1167 "P%u: Finishing setop in Task {%s} (%u/%u)\n",
1137 session->local_peer_idx, 1168 session->local_peer_idx,
1138 debug_str_task_key(&task->key), 1169 debug_str_task_key (&task->key),
1139 (unsigned int)task->step->finished_tasks, 1170 (unsigned int) task->step->finished_tasks,
1140 (unsigned int)task->step->tasks_len); 1171 (unsigned int) task->step->tasks_len);
1141 if (NULL != output_rfn) 1172 if (NULL != output_rfn)
1142 { 1173 {
1143 rfn_commit(output_rfn, task_other_peer(task)); 1174 rfn_commit (output_rfn, task_other_peer (task));
1144 } 1175 }
1145 if (PHASE_KIND_ALL_TO_ALL == task->key.kind) 1176 if (PHASE_KIND_ALL_TO_ALL == task->key.kind)
1146 { 1177 {
1147 session->first_size = current_size; 1178 session->first_size = current_size;
1148 } 1179 }
1149 finish_task(task); 1180 finish_task (task);
1150 break; 1181 break;
1151 1182
1152 case GNUNET_SET_STATUS_FAILURE: 1183 case GNUNET_SET_STATUS_FAILURE:
1153 // XXX: cleanup 1184 // XXX: cleanup
1154 GNUNET_break_op(0); 1185 GNUNET_break_op (0);
1155 finish_task(task); 1186 finish_task (task);
1156 return; 1187 return;
1157 1188
1158 default: 1189 default:
1159 /* not reached */ 1190 /* not reached */
1160 GNUNET_assert(0); 1191 GNUNET_assert (0);
1161 } 1192 }
1162} 1193}
1163 1194
1164#ifdef EVIL 1195#ifdef EVIL
1165 1196
1166enum EvilnessType { 1197enum EvilnessType
1198{
1167 EVILNESS_NONE, 1199 EVILNESS_NONE,
1168 EVILNESS_CRAM_ALL, 1200 EVILNESS_CRAM_ALL,
1169 EVILNESS_CRAM_LEAD, 1201 EVILNESS_CRAM_LEAD,
@@ -1172,13 +1204,15 @@ enum EvilnessType {
1172 EVILNESS_SLACK_A2A, 1204 EVILNESS_SLACK_A2A,
1173}; 1205};
1174 1206
1175enum EvilnessSubType { 1207enum EvilnessSubType
1208{
1176 EVILNESS_SUB_NONE, 1209 EVILNESS_SUB_NONE,
1177 EVILNESS_SUB_REPLACEMENT, 1210 EVILNESS_SUB_REPLACEMENT,
1178 EVILNESS_SUB_NO_REPLACEMENT, 1211 EVILNESS_SUB_NO_REPLACEMENT,
1179}; 1212};
1180 1213
1181struct Evilness { 1214struct Evilness
1215{
1182 enum EvilnessType type; 1216 enum EvilnessType type;
1183 enum EvilnessSubType subtype; 1217 enum EvilnessSubType subtype;
1184 unsigned int num; 1218 unsigned int num;
@@ -1186,129 +1220,133 @@ struct Evilness {
1186 1220
1187 1221
1188static int 1222static int
1189parse_evilness_cram_subtype(const char *evil_subtype_str, struct Evilness *evil) 1223parse_evilness_cram_subtype (const char *evil_subtype_str, struct
1224 Evilness *evil)
1190{ 1225{
1191 if (0 == strcmp("replace", evil_subtype_str)) 1226 if (0 == strcmp ("replace", evil_subtype_str))
1192 { 1227 {
1193 evil->subtype = EVILNESS_SUB_REPLACEMENT; 1228 evil->subtype = EVILNESS_SUB_REPLACEMENT;
1194 } 1229 }
1195 else if (0 == strcmp("noreplace", evil_subtype_str)) 1230 else if (0 == strcmp ("noreplace", evil_subtype_str))
1196 { 1231 {
1197 evil->subtype = EVILNESS_SUB_NO_REPLACEMENT; 1232 evil->subtype = EVILNESS_SUB_NO_REPLACEMENT;
1198 } 1233 }
1199 else 1234 else
1200 { 1235 {
1201 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1236 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1202 "Malformed field '%s' in EVIL_SPEC (unknown subtype), behaving like a good peer.\n", 1237 "Malformed field '%s' in EVIL_SPEC (unknown subtype), behaving like a good peer.\n",
1203 evil_subtype_str); 1238 evil_subtype_str);
1204 return GNUNET_SYSERR; 1239 return GNUNET_SYSERR;
1205 } 1240 }
1206 return GNUNET_OK; 1241 return GNUNET_OK;
1207} 1242}
1208 1243
1209 1244
1210static void 1245static void
1211get_evilness(struct ConsensusSession *session, struct Evilness *evil) 1246get_evilness (struct ConsensusSession *session, struct Evilness *evil)
1212{ 1247{
1213 char *evil_spec; 1248 char *evil_spec;
1214 char *field; 1249 char *field;
1215 char *evil_type_str = NULL; 1250 char *evil_type_str = NULL;
1216 char *evil_subtype_str = NULL; 1251 char *evil_subtype_str = NULL;
1217 1252
1218 GNUNET_assert(NULL != evil); 1253 GNUNET_assert (NULL != evil);
1219 1254
1220 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "consensus", "EVIL_SPEC", &evil_spec)) 1255 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "consensus",
1221 { 1256 "EVIL_SPEC",
1222 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1257 &evil_spec))
1223 "P%u: no evilness\n", 1258 {
1224 session->local_peer_idx); 1259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1225 evil->type = EVILNESS_NONE; 1260 "P%u: no evilness\n",
1226 return; 1261 session->local_peer_idx);
1227 } 1262 evil->type = EVILNESS_NONE;
1228 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1263 return;
1229 "P%u: got evilness spec\n", 1264 }
1230 session->local_peer_idx); 1265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1266 "P%u: got evilness spec\n",
1267 session->local_peer_idx);
1231 1268
1232 for (field = strtok(evil_spec, "/"); 1269 for (field = strtok (evil_spec, "/");
1233 NULL != field; 1270 NULL != field;
1234 field = strtok(NULL, "/")) 1271 field = strtok (NULL, "/"))
1235 { 1272 {
1236 unsigned int peer_num; 1273 unsigned int peer_num;
1237 unsigned int evil_num; 1274 unsigned int evil_num;
1238 int ret; 1275 int ret;
1239 1276
1240 evil_type_str = NULL; 1277 evil_type_str = NULL;
1241 evil_subtype_str = NULL; 1278 evil_subtype_str = NULL;
1242 1279
1243 ret = sscanf(field, "%u;%m[a-z-];%m[a-z-];%u", &peer_num, &evil_type_str, &evil_subtype_str, &evil_num); 1280 ret = sscanf (field, "%u;%m[a-z-];%m[a-z-];%u", &peer_num, &evil_type_str,
1281 &evil_subtype_str, &evil_num);
1244 1282
1245 if (ret != 4) 1283 if (ret != 4)
1246 { 1284 {
1247 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1285 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1248 "Malformed field '%s' in EVIL_SPEC (expected 4 components got %d), behaving like a good peer.\n", 1286 "Malformed field '%s' in EVIL_SPEC (expected 4 components got %d), behaving like a good peer.\n",
1249 field, 1287 field,
1250 ret); 1288 ret);
1251 goto not_evil; 1289 goto not_evil;
1252 } 1290 }
1253 1291
1254 GNUNET_assert(NULL != evil_type_str); 1292 GNUNET_assert (NULL != evil_type_str);
1255 GNUNET_assert(NULL != evil_subtype_str); 1293 GNUNET_assert (NULL != evil_subtype_str);
1256 1294
1257 if (peer_num == session->local_peer_idx) 1295 if (peer_num == session->local_peer_idx)
1258 { 1296 {
1259 if (0 == strcmp("slack", evil_type_str)) 1297 if (0 == strcmp ("slack", evil_type_str))
1260 { 1298 {
1261 evil->type = EVILNESS_SLACK; 1299 evil->type = EVILNESS_SLACK;
1262 } 1300 }
1263 if (0 == strcmp("slack-a2a", evil_type_str)) 1301 if (0 == strcmp ("slack-a2a", evil_type_str))
1264 { 1302 {
1265 evil->type = EVILNESS_SLACK_A2A; 1303 evil->type = EVILNESS_SLACK_A2A;
1266 } 1304 }
1267 else if (0 == strcmp("cram-all", evil_type_str)) 1305 else if (0 == strcmp ("cram-all", evil_type_str))
1268 { 1306 {
1269 evil->type = EVILNESS_CRAM_ALL; 1307 evil->type = EVILNESS_CRAM_ALL;
1270 evil->num = evil_num; 1308 evil->num = evil_num;
1271 if (GNUNET_OK != parse_evilness_cram_subtype(evil_subtype_str, evil)) 1309 if (GNUNET_OK != parse_evilness_cram_subtype (evil_subtype_str, evil))
1272 goto not_evil; 1310 goto not_evil;
1273 } 1311 }
1274 else if (0 == strcmp("cram-lead", evil_type_str)) 1312 else if (0 == strcmp ("cram-lead", evil_type_str))
1275 { 1313 {
1276 evil->type = EVILNESS_CRAM_LEAD; 1314 evil->type = EVILNESS_CRAM_LEAD;
1277 evil->num = evil_num; 1315 evil->num = evil_num;
1278 if (GNUNET_OK != parse_evilness_cram_subtype(evil_subtype_str, evil)) 1316 if (GNUNET_OK != parse_evilness_cram_subtype (evil_subtype_str, evil))
1279 goto not_evil; 1317 goto not_evil;
1280 } 1318 }
1281 else if (0 == strcmp("cram-echo", evil_type_str)) 1319 else if (0 == strcmp ("cram-echo", evil_type_str))
1282 { 1320 {
1283 evil->type = EVILNESS_CRAM_ECHO; 1321 evil->type = EVILNESS_CRAM_ECHO;
1284 evil->num = evil_num; 1322 evil->num = evil_num;
1285 if (GNUNET_OK != parse_evilness_cram_subtype(evil_subtype_str, evil)) 1323 if (GNUNET_OK != parse_evilness_cram_subtype (evil_subtype_str, evil))
1286 goto not_evil; 1324 goto not_evil;
1287 } 1325 }
1288 else 1326 else
1289 { 1327 {
1290 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1328 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1291 "Malformed field '%s' in EVIL_SPEC (unknown type), behaving like a good peer.\n", 1329 "Malformed field '%s' in EVIL_SPEC (unknown type), behaving like a good peer.\n",
1292 evil_type_str); 1330 evil_type_str);
1293 goto not_evil; 1331 goto not_evil;
1294 } 1332 }
1295 goto cleanup; 1333 goto cleanup;
1296 }
1297 /* No GNUNET_free since memory was allocated by libc */
1298 free(evil_type_str);
1299 evil_type_str = NULL;
1300 evil_subtype_str = NULL;
1301 } 1334 }
1335 /* No GNUNET_free since memory was allocated by libc */
1336 free (evil_type_str);
1337 evil_type_str = NULL;
1338 evil_subtype_str = NULL;
1339 }
1302not_evil: 1340not_evil:
1303 evil->type = EVILNESS_NONE; 1341 evil->type = EVILNESS_NONE;
1304cleanup: 1342cleanup:
1305 GNUNET_free(evil_spec); 1343 GNUNET_free (evil_spec);
1306 /* no GNUNET_free_non_null since it wasn't 1344 /* no GNUNET_free_non_null since it wasn't
1307 * allocated with GNUNET_malloc */ 1345 * allocated with GNUNET_malloc */
1308 if (NULL != evil_type_str) 1346 if (NULL != evil_type_str)
1309 free(evil_type_str); 1347 free (evil_type_str);
1310 if (NULL != evil_subtype_str) 1348 if (NULL != evil_subtype_str)
1311 free(evil_subtype_str); 1349 free (evil_subtype_str);
1312} 1350}
1313 1351
1314#endif 1352#endif
@@ -1319,301 +1357,312 @@ cleanup:
1319 * task. 1357 * task.
1320 */ 1358 */
1321static void 1359static void
1322commit_set(struct ConsensusSession *session, 1360commit_set (struct ConsensusSession *session,
1323 struct TaskEntry *task) 1361 struct TaskEntry *task)
1324{ 1362{
1325 struct SetEntry *set; 1363 struct SetEntry *set;
1326 struct SetOpCls *setop = &task->cls.setop; 1364 struct SetOpCls *setop = &task->cls.setop;
1327 1365
1328 GNUNET_assert(NULL != setop->op); 1366 GNUNET_assert (NULL != setop->op);
1329 set = lookup_set(session, &setop->input_set); 1367 set = lookup_set (session, &setop->input_set);
1330 GNUNET_assert(NULL != set); 1368 GNUNET_assert (NULL != set);
1331 1369
1332 if ((GNUNET_YES == setop->transceive_contested) && (GNUNET_YES == set->is_contested)) 1370 if ((GNUNET_YES == setop->transceive_contested) && (GNUNET_YES ==
1333 { 1371 set->is_contested))
1334 struct GNUNET_SET_Element element; 1372 {
1335 struct ConsensusElement ce = { 0 }; 1373 struct GNUNET_SET_Element element;
1336 ce.marker = CONSENSUS_MARKER_CONTESTED; 1374 struct ConsensusElement ce = { 0 };
1337 element.data = &ce; 1375 ce.marker = CONSENSUS_MARKER_CONTESTED;
1338 element.size = sizeof(struct ConsensusElement); 1376 element.data = &ce;
1339 element.element_type = GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT; 1377 element.size = sizeof(struct ConsensusElement);
1340 GNUNET_SET_add_element(set->h, &element, NULL, NULL); 1378 element.element_type = GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT;
1341 } 1379 GNUNET_SET_add_element (set->h, &element, NULL, NULL);
1380 }
1342 1381
1343 if (PHASE_KIND_ALL_TO_ALL_2 == task->key.kind) 1382 if (PHASE_KIND_ALL_TO_ALL_2 == task->key.kind)
1344 { 1383 {
1345 struct GNUNET_SET_Element element; 1384 struct GNUNET_SET_Element element;
1346 struct ConsensusSizeElement cse = { 1385 struct ConsensusSizeElement cse = {
1347 .size = 0, 1386 .size = 0,
1348 .sender_index = 0 1387 .sender_index = 0
1349 }; 1388 };
1350 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "inserting size marker\n"); 1389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "inserting size marker\n");
1351 cse.ce.marker = CONSENSUS_MARKER_SIZE; 1390 cse.ce.marker = CONSENSUS_MARKER_SIZE;
1352 cse.size = GNUNET_htonll(session->first_size); 1391 cse.size = GNUNET_htonll (session->first_size);
1353 cse.sender_index = session->local_peer_idx; 1392 cse.sender_index = session->local_peer_idx;
1354 element.data = &cse; 1393 element.data = &cse;
1355 element.size = sizeof(struct ConsensusSizeElement); 1394 element.size = sizeof(struct ConsensusSizeElement);
1356 element.element_type = GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT; 1395 element.element_type = GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT;
1357 GNUNET_SET_add_element(set->h, &element, NULL, NULL); 1396 GNUNET_SET_add_element (set->h, &element, NULL, NULL);
1358 } 1397 }
1359 1398
1360#ifdef EVIL 1399#ifdef EVIL
1361 { 1400 {
1362 unsigned int i; 1401 unsigned int i;
1363 struct Evilness evil; 1402 struct Evilness evil;
1364 1403
1365 get_evilness(session, &evil); 1404 get_evilness (session, &evil);
1366 if (EVILNESS_NONE != evil.type) 1405 if (EVILNESS_NONE != evil.type)
1406 {
1407 /* Useful for evaluation */
1408 GNUNET_STATISTICS_set (statistics,
1409 "is evil",
1410 1,
1411 GNUNET_NO);
1412 }
1413 switch (evil.type)
1414 {
1415 case EVILNESS_CRAM_ALL:
1416 case EVILNESS_CRAM_LEAD:
1417 case EVILNESS_CRAM_ECHO:
1418 /* We're not cramming elements in the
1419 all-to-all round, since that would just
1420 add more elements to the result set, but
1421 wouldn't test robustness. */
1422 if (PHASE_KIND_ALL_TO_ALL == task->key.kind)
1367 { 1423 {
1368 /* Useful for evaluation */ 1424 GNUNET_SET_commit (setop->op, set->h);
1369 GNUNET_STATISTICS_set(statistics, 1425 break;
1370 "is evil",
1371 1,
1372 GNUNET_NO);
1373 } 1426 }
1374 switch (evil.type) 1427 if ((EVILNESS_CRAM_LEAD == evil.type) &&
1428 ((PHASE_KIND_GRADECAST_LEADER != task->key.kind) ||
1429 (SET_KIND_CURRENT != set->key.set_kind) ))
1430 {
1431 GNUNET_SET_commit (setop->op, set->h);
1432 break;
1433 }
1434 if ((EVILNESS_CRAM_ECHO == evil.type) && (PHASE_KIND_GRADECAST_ECHO !=
1435 task->key.kind))
1375 { 1436 {
1376 case EVILNESS_CRAM_ALL: 1437 GNUNET_SET_commit (setop->op, set->h);
1377 case EVILNESS_CRAM_LEAD: 1438 break;
1378 case EVILNESS_CRAM_ECHO: 1439 }
1379 /* We're not cramming elements in the 1440 for (i = 0; i < evil.num; i++)
1380 all-to-all round, since that would just 1441 {
1381 add more elements to the result set, but 1442 struct GNUNET_SET_Element element;
1382 wouldn't test robustness. */ 1443 struct ConsensusStuffedElement se = {
1383 if (PHASE_KIND_ALL_TO_ALL == task->key.kind) 1444 .ce.payload_type = 0,
1384 { 1445 .ce.marker = 0,
1385 GNUNET_SET_commit(setop->op, set->h); 1446 };
1386 break; 1447 element.data = &se;
1387 } 1448 element.size = sizeof(struct ConsensusStuffedElement);
1388 if ((EVILNESS_CRAM_LEAD == evil.type) && 1449 element.element_type = GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT;
1389 ((PHASE_KIND_GRADECAST_LEADER != task->key.kind) || SET_KIND_CURRENT != set->key.set_kind)) 1450
1390 { 1451 if (EVILNESS_SUB_REPLACEMENT == evil.subtype)
1391 GNUNET_SET_commit(setop->op, set->h); 1452 {
1392 break; 1453 /* Always generate a new element. */
1393 } 1454 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
1394 if (EVILNESS_CRAM_ECHO == evil.type && (PHASE_KIND_GRADECAST_ECHO != task->key.kind)) 1455 &se.rand);
1395 { 1456 }
1396 GNUNET_SET_commit(setop->op, set->h); 1457 else if (EVILNESS_SUB_NO_REPLACEMENT == evil.subtype)
1397 break; 1458 {
1398 } 1459 /* Always cram the same elements, derived from counter. */
1399 for (i = 0; i < evil.num; i++) 1460 GNUNET_CRYPTO_hash (&i, sizeof(i), &se.rand);
1400 { 1461 }
1401 struct GNUNET_SET_Element element; 1462 else
1402 struct ConsensusStuffedElement se = { 1463 {
1403 .ce.payload_type = 0, 1464 GNUNET_assert (0);
1404 .ce.marker = 0, 1465 }
1405 }; 1466 GNUNET_SET_add_element (set->h, &element, NULL, NULL);
1406 element.data = &se;
1407 element.size = sizeof(struct ConsensusStuffedElement);
1408 element.element_type = GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT;
1409
1410 if (EVILNESS_SUB_REPLACEMENT == evil.subtype)
1411 {
1412 /* Always generate a new element. */
1413 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &se.rand);
1414 }
1415 else if (EVILNESS_SUB_NO_REPLACEMENT == evil.subtype)
1416 {
1417 /* Always cram the same elements, derived from counter. */
1418 GNUNET_CRYPTO_hash(&i, sizeof(i), &se.rand);
1419 }
1420 else
1421 {
1422 GNUNET_assert(0);
1423 }
1424 GNUNET_SET_add_element(set->h, &element, NULL, NULL);
1425#ifdef GNUNET_EXTRA_LOGGING 1467#ifdef GNUNET_EXTRA_LOGGING
1426 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1468 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1427 "P%u: evil peer: cramming element %s into set {%s} of task {%s}\n", 1469 "P%u: evil peer: cramming element %s into set {%s} of task {%s}\n",
1428 session->local_peer_idx, 1470 session->local_peer_idx,
1429 debug_str_element(&element), 1471 debug_str_element (&element),
1430 debug_str_set_key(&setop->input_set), 1472 debug_str_set_key (&setop->input_set),
1431 debug_str_task_key(&task->key)); 1473 debug_str_task_key (&task->key));
1432#endif 1474#endif
1433 } 1475 }
1434 GNUNET_STATISTICS_update(statistics, 1476 GNUNET_STATISTICS_update (statistics,
1435 "# stuffed elements", 1477 "# stuffed elements",
1436 evil.num, 1478 evil.num,
1437 GNUNET_NO); 1479 GNUNET_NO);
1438 GNUNET_SET_commit(setop->op, set->h); 1480 GNUNET_SET_commit (setop->op, set->h);
1439 break; 1481 break;
1440 1482
1441 case EVILNESS_SLACK: 1483 case EVILNESS_SLACK:
1442 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1484 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1443 "P%u: evil peer: slacking\n", 1485 "P%u: evil peer: slacking\n",
1444 (unsigned int)session->local_peer_idx); 1486 (unsigned int) session->local_peer_idx);
1445
1446 /* Do nothing. */
1447 case EVILNESS_SLACK_A2A:
1448 if ((PHASE_KIND_ALL_TO_ALL_2 == task->key.kind) ||
1449 (PHASE_KIND_ALL_TO_ALL == task->key.kind))
1450 {
1451 struct GNUNET_SET_Handle *empty_set;
1452 empty_set = GNUNET_SET_create(cfg, GNUNET_SET_OPERATION_UNION);
1453 GNUNET_SET_commit(setop->op, empty_set);
1454 GNUNET_SET_destroy(empty_set);
1455 }
1456 else
1457 {
1458 GNUNET_SET_commit(setop->op, set->h);
1459 }
1460 break;
1461 1487
1462 case EVILNESS_NONE: 1488 /* Do nothing. */
1463 GNUNET_SET_commit(setop->op, set->h); 1489 case EVILNESS_SLACK_A2A:
1464 break; 1490 if ((PHASE_KIND_ALL_TO_ALL_2 == task->key.kind) ||
1491 (PHASE_KIND_ALL_TO_ALL == task->key.kind))
1492 {
1493 struct GNUNET_SET_Handle *empty_set;
1494 empty_set = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION);
1495 GNUNET_SET_commit (setop->op, empty_set);
1496 GNUNET_SET_destroy (empty_set);
1465 } 1497 }
1498 else
1499 {
1500 GNUNET_SET_commit (setop->op, set->h);
1501 }
1502 break;
1503
1504 case EVILNESS_NONE:
1505 GNUNET_SET_commit (setop->op, set->h);
1506 break;
1507 }
1466 } 1508 }
1467#else 1509#else
1468 if (GNUNET_NO == session->peers_blacklisted[task_other_peer(task)]) 1510 if (GNUNET_NO == session->peers_blacklisted[task_other_peer (task)])
1469 { 1511 {
1470 GNUNET_SET_commit(setop->op, set->h); 1512 GNUNET_SET_commit (setop->op, set->h);
1471 } 1513 }
1472 else 1514 else
1473 { 1515 {
1474 /* For our testcases, we don't want the blacklisted 1516 /* For our testcases, we don't want the blacklisted
1475 peers to wait. */ 1517 peers to wait. */
1476 GNUNET_SET_operation_cancel(setop->op); 1518 GNUNET_SET_operation_cancel (setop->op);
1477 setop->op = NULL; 1519 setop->op = NULL;
1478 finish_task(task); 1520 finish_task (task);
1479 } 1521 }
1480#endif 1522#endif
1481} 1523}
1482 1524
1483 1525
1484static void 1526static void
1485put_diff(struct ConsensusSession *session, 1527put_diff (struct ConsensusSession *session,
1486 struct DiffEntry *diff) 1528 struct DiffEntry *diff)
1487{ 1529{
1488 struct GNUNET_HashCode hash; 1530 struct GNUNET_HashCode hash;
1489 1531
1490 GNUNET_assert(NULL != diff); 1532 GNUNET_assert (NULL != diff);
1491 1533
1492 GNUNET_CRYPTO_hash(&diff->key, sizeof(struct DiffKey), &hash); 1534 GNUNET_CRYPTO_hash (&diff->key, sizeof(struct DiffKey), &hash);
1493 GNUNET_assert(GNUNET_OK == 1535 GNUNET_assert (GNUNET_OK ==
1494 GNUNET_CONTAINER_multihashmap_put(session->diffmap, &hash, diff, 1536 GNUNET_CONTAINER_multihashmap_put (session->diffmap, &hash,
1495 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1537 diff,
1538 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1496} 1539}
1497 1540
1498static void 1541static void
1499put_set(struct ConsensusSession *session, 1542put_set (struct ConsensusSession *session,
1500 struct SetEntry *set) 1543 struct SetEntry *set)
1501{ 1544{
1502 struct GNUNET_HashCode hash; 1545 struct GNUNET_HashCode hash;
1503 1546
1504 GNUNET_assert(NULL != set->h); 1547 GNUNET_assert (NULL != set->h);
1505 1548
1506 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1549 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1507 "Putting set %s\n", 1550 "Putting set %s\n",
1508 debug_str_set_key(&set->key)); 1551 debug_str_set_key (&set->key));
1509 1552
1510 GNUNET_CRYPTO_hash(&set->key, sizeof(struct SetKey), &hash); 1553 GNUNET_CRYPTO_hash (&set->key, sizeof(struct SetKey), &hash);
1511 GNUNET_assert(GNUNET_SYSERR != 1554 GNUNET_assert (GNUNET_SYSERR !=
1512 GNUNET_CONTAINER_multihashmap_put(session->setmap, &hash, set, 1555 GNUNET_CONTAINER_multihashmap_put (session->setmap, &hash, set,
1513 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)); 1556 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
1514} 1557}
1515 1558
1516 1559
1517static void 1560static void
1518put_rfn(struct ConsensusSession *session, 1561put_rfn (struct ConsensusSession *session,
1519 struct ReferendumEntry *rfn) 1562 struct ReferendumEntry *rfn)
1520{ 1563{
1521 struct GNUNET_HashCode hash; 1564 struct GNUNET_HashCode hash;
1522 1565
1523 GNUNET_CRYPTO_hash(&rfn->key, sizeof(struct RfnKey), &hash); 1566 GNUNET_CRYPTO_hash (&rfn->key, sizeof(struct RfnKey), &hash);
1524 GNUNET_assert(GNUNET_OK == 1567 GNUNET_assert (GNUNET_OK ==
1525 GNUNET_CONTAINER_multihashmap_put(session->rfnmap, &hash, rfn, 1568 GNUNET_CONTAINER_multihashmap_put (session->rfnmap, &hash, rfn,
1526 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1569 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1527} 1570}
1528 1571
1529 1572
1530 1573
1531static void 1574static void
1532task_cancel_reconcile(struct TaskEntry *task) 1575task_cancel_reconcile (struct TaskEntry *task)
1533{ 1576{
1534 /* not implemented yet */ 1577 /* not implemented yet */
1535 GNUNET_assert(0); 1578 GNUNET_assert (0);
1536} 1579}
1537 1580
1538 1581
1539static void 1582static void
1540apply_diff_to_rfn(struct DiffEntry *diff, 1583apply_diff_to_rfn (struct DiffEntry *diff,
1541 struct ReferendumEntry *rfn, 1584 struct ReferendumEntry *rfn,
1542 uint16_t voting_peer, 1585 uint16_t voting_peer,
1543 uint16_t num_peers) 1586 uint16_t num_peers)
1544{ 1587{
1545 struct GNUNET_CONTAINER_MultiHashMapIterator *iter; 1588 struct GNUNET_CONTAINER_MultiHashMapIterator *iter;
1546 struct DiffElementInfo *di; 1589 struct DiffElementInfo *di;
1547 1590
1548 iter = GNUNET_CONTAINER_multihashmap_iterator_create(diff->changes); 1591 iter = GNUNET_CONTAINER_multihashmap_iterator_create (diff->changes);
1549 1592
1550 while (GNUNET_YES == 1593 while (GNUNET_YES ==
1551 GNUNET_CONTAINER_multihashmap_iterator_next(iter, 1594 GNUNET_CONTAINER_multihashmap_iterator_next (iter,
1552 NULL, 1595 NULL,
1553 (const void **)&di)) 1596 (const void **) &di))
1597 {
1598 if (di->weight > 0)
1554 { 1599 {
1555 if (di->weight > 0) 1600 rfn_vote (rfn, voting_peer, VOTE_ADD, di->element);
1556 {
1557 rfn_vote(rfn, voting_peer, VOTE_ADD, di->element);
1558 }
1559 if (di->weight < 0)
1560 {
1561 rfn_vote(rfn, voting_peer, VOTE_REMOVE, di->element);
1562 }
1563 } 1601 }
1602 if (di->weight < 0)
1603 {
1604 rfn_vote (rfn, voting_peer, VOTE_REMOVE, di->element);
1605 }
1606 }
1564 1607
1565 GNUNET_CONTAINER_multihashmap_iterator_destroy(iter); 1608 GNUNET_CONTAINER_multihashmap_iterator_destroy (iter);
1566} 1609}
1567 1610
1568 1611
1569struct DiffEntry * 1612struct DiffEntry *
1570diff_create() 1613diff_create ()
1571{ 1614{
1572 struct DiffEntry *d = GNUNET_new(struct DiffEntry); 1615 struct DiffEntry *d = GNUNET_new (struct DiffEntry);
1573 1616
1574 d->changes = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); 1617 d->changes = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO);
1575 1618
1576 return d; 1619 return d;
1577} 1620}
1578 1621
1579 1622
1580struct DiffEntry * 1623struct DiffEntry *
1581diff_compose(struct DiffEntry *diff_1, 1624diff_compose (struct DiffEntry *diff_1,
1582 struct DiffEntry *diff_2) 1625 struct DiffEntry *diff_2)
1583{ 1626{
1584 struct DiffEntry *diff_new; 1627 struct DiffEntry *diff_new;
1585 struct GNUNET_CONTAINER_MultiHashMapIterator *iter; 1628 struct GNUNET_CONTAINER_MultiHashMapIterator *iter;
1586 struct DiffElementInfo *di; 1629 struct DiffElementInfo *di;
1587 1630
1588 diff_new = diff_create(); 1631 diff_new = diff_create ();
1589 1632
1590 iter = GNUNET_CONTAINER_multihashmap_iterator_create(diff_1->changes); 1633 iter = GNUNET_CONTAINER_multihashmap_iterator_create (diff_1->changes);
1591 while (GNUNET_YES == GNUNET_CONTAINER_multihashmap_iterator_next(iter, NULL, (const void **)&di)) 1634 while (GNUNET_YES == GNUNET_CONTAINER_multihashmap_iterator_next (iter, NULL,
1592 { 1635 (const
1593 diff_insert(diff_new, di->weight, di->element); 1636 void **) &
1594 } 1637 di))
1595 GNUNET_CONTAINER_multihashmap_iterator_destroy(iter); 1638 {
1639 diff_insert (diff_new, di->weight, di->element);
1640 }
1641 GNUNET_CONTAINER_multihashmap_iterator_destroy (iter);
1596 1642
1597 iter = GNUNET_CONTAINER_multihashmap_iterator_create(diff_2->changes); 1643 iter = GNUNET_CONTAINER_multihashmap_iterator_create (diff_2->changes);
1598 while (GNUNET_YES == GNUNET_CONTAINER_multihashmap_iterator_next(iter, NULL, (const void **)&di)) 1644 while (GNUNET_YES == GNUNET_CONTAINER_multihashmap_iterator_next (iter, NULL,
1599 { 1645 (const
1600 diff_insert(diff_new, di->weight, di->element); 1646 void **) &
1601 } 1647 di))
1602 GNUNET_CONTAINER_multihashmap_iterator_destroy(iter); 1648 {
1649 diff_insert (diff_new, di->weight, di->element);
1650 }
1651 GNUNET_CONTAINER_multihashmap_iterator_destroy (iter);
1603 1652
1604 return diff_new; 1653 return diff_new;
1605} 1654}
1606 1655
1607 1656
1608struct ReferendumEntry * 1657struct ReferendumEntry *
1609rfn_create(uint16_t size) 1658rfn_create (uint16_t size)
1610{ 1659{
1611 struct ReferendumEntry *rfn; 1660 struct ReferendumEntry *rfn;
1612 1661
1613 rfn = GNUNET_new(struct ReferendumEntry); 1662 rfn = GNUNET_new (struct ReferendumEntry);
1614 rfn->rfn_elements = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); 1663 rfn->rfn_elements = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO);
1615 rfn->peer_commited = GNUNET_new_array(size, int); 1664 rfn->peer_commited = GNUNET_new_array (size, int);
1616 rfn->peer_contested = GNUNET_new_array(size, int); 1665 rfn->peer_contested = GNUNET_new_array (size, int);
1617 rfn->num_peers = size; 1666 rfn->num_peers = size;
1618 1667
1619 return rfn; 1668 return rfn;
@@ -1622,10 +1671,10 @@ rfn_create(uint16_t size)
1622 1671
1623#if UNUSED 1672#if UNUSED
1624static void 1673static void
1625diff_destroy(struct DiffEntry *diff) 1674diff_destroy (struct DiffEntry *diff)
1626{ 1675{
1627 GNUNET_CONTAINER_multihashmap_destroy(diff->changes); 1676 GNUNET_CONTAINER_multihashmap_destroy (diff->changes);
1628 GNUNET_free(diff); 1677 GNUNET_free (diff);
1629} 1678}
1630#endif 1679#endif
1631 1680
@@ -1636,70 +1685,71 @@ diff_destroy(struct DiffEntry *diff)
1636 * of peers that voted for this outcome. 1685 * of peers that voted for this outcome.
1637 */ 1686 */
1638static void 1687static void
1639rfn_majority(const struct ReferendumEntry *rfn, 1688rfn_majority (const struct ReferendumEntry *rfn,
1640 const struct RfnElementInfo *ri, 1689 const struct RfnElementInfo *ri,
1641 uint16_t *ret_majority, 1690 uint16_t *ret_majority,
1642 enum ReferendumVote *ret_vote) 1691 enum ReferendumVote *ret_vote)
1643{ 1692{
1644 uint16_t votes_yes = 0; 1693 uint16_t votes_yes = 0;
1645 uint16_t num_commited = 0; 1694 uint16_t num_commited = 0;
1646 uint16_t i; 1695 uint16_t i;
1647 1696
1648 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1697 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1649 "Computing rfn majority for element %s of rfn {%s}\n", 1698 "Computing rfn majority for element %s of rfn {%s}\n",
1650 debug_str_element(ri->element), 1699 debug_str_element (ri->element),
1651 debug_str_rfn_key(&rfn->key)); 1700 debug_str_rfn_key (&rfn->key));
1652 1701
1653 for (i = 0; i < rfn->num_peers; i++) 1702 for (i = 0; i < rfn->num_peers; i++)
1654 { 1703 {
1655 if (GNUNET_NO == rfn->peer_commited[i]) 1704 if (GNUNET_NO == rfn->peer_commited[i])
1656 continue; 1705 continue;
1657 num_commited++; 1706 num_commited++;
1658 1707
1659 if (GNUNET_YES == ri->votes[i]) 1708 if (GNUNET_YES == ri->votes[i])
1660 votes_yes++; 1709 votes_yes++;
1661 } 1710 }
1662 1711
1663 if (votes_yes > (num_commited) / 2) 1712 if (votes_yes > (num_commited) / 2)
1664 { 1713 {
1665 *ret_vote = ri->proposal; 1714 *ret_vote = ri->proposal;
1666 *ret_majority = votes_yes; 1715 *ret_majority = votes_yes;
1667 } 1716 }
1668 else 1717 else
1669 { 1718 {
1670 *ret_vote = VOTE_STAY; 1719 *ret_vote = VOTE_STAY;
1671 *ret_majority = num_commited - votes_yes; 1720 *ret_majority = num_commited - votes_yes;
1672 } 1721 }
1673} 1722}
1674 1723
1675 1724
1676struct SetCopyCls { 1725struct SetCopyCls
1726{
1677 struct TaskEntry *task; 1727 struct TaskEntry *task;
1678 struct SetKey dst_set_key; 1728 struct SetKey dst_set_key;
1679}; 1729};
1680 1730
1681 1731
1682static void 1732static void
1683set_copy_cb(void *cls, struct GNUNET_SET_Handle *copy) 1733set_copy_cb (void *cls, struct GNUNET_SET_Handle *copy)
1684{ 1734{
1685 struct SetCopyCls *scc = cls; 1735 struct SetCopyCls *scc = cls;
1686 struct TaskEntry *task = scc->task; 1736 struct TaskEntry *task = scc->task;
1687 struct SetKey dst_set_key = scc->dst_set_key; 1737 struct SetKey dst_set_key = scc->dst_set_key;
1688 struct SetEntry *set; 1738 struct SetEntry *set;
1689 struct SetHandle *sh = GNUNET_new(struct SetHandle); 1739 struct SetHandle *sh = GNUNET_new (struct SetHandle);
1690 1740
1691 sh->h = copy; 1741 sh->h = copy;
1692 GNUNET_CONTAINER_DLL_insert(task->step->session->set_handles_head, 1742 GNUNET_CONTAINER_DLL_insert (task->step->session->set_handles_head,
1693 task->step->session->set_handles_tail, 1743 task->step->session->set_handles_tail,
1694 sh); 1744 sh);
1695 1745
1696 GNUNET_free(scc); 1746 GNUNET_free (scc);
1697 set = GNUNET_new(struct SetEntry); 1747 set = GNUNET_new (struct SetEntry);
1698 set->h = copy; 1748 set->h = copy;
1699 set->key = dst_set_key; 1749 set->key = dst_set_key;
1700 put_set(task->step->session, set); 1750 put_set (task->step->session, set);
1701 1751
1702 task->start(task); 1752 task->start (task);
1703} 1753}
1704 1754
1705 1755
@@ -1708,30 +1758,31 @@ set_copy_cb(void *cls, struct GNUNET_SET_Handle *copy)
1708 * task again after we created a copy of the given set. 1758 * task again after we created a copy of the given set.
1709 */ 1759 */
1710static void 1760static void
1711create_set_copy_for_task(struct TaskEntry *task, 1761create_set_copy_for_task (struct TaskEntry *task,
1712 struct SetKey *src_set_key, 1762 struct SetKey *src_set_key,
1713 struct SetKey *dst_set_key) 1763 struct SetKey *dst_set_key)
1714{ 1764{
1715 struct SetEntry *src_set; 1765 struct SetEntry *src_set;
1716 struct SetCopyCls *scc = GNUNET_new(struct SetCopyCls); 1766 struct SetCopyCls *scc = GNUNET_new (struct SetCopyCls);
1717 1767
1718 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1768 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1719 "Copying set {%s} to {%s} for task {%s}\n", 1769 "Copying set {%s} to {%s} for task {%s}\n",
1720 debug_str_set_key(src_set_key), 1770 debug_str_set_key (src_set_key),
1721 debug_str_set_key(dst_set_key), 1771 debug_str_set_key (dst_set_key),
1722 debug_str_task_key(&task->key)); 1772 debug_str_task_key (&task->key));
1723 1773
1724 scc->task = task; 1774 scc->task = task;
1725 scc->dst_set_key = *dst_set_key; 1775 scc->dst_set_key = *dst_set_key;
1726 src_set = lookup_set(task->step->session, src_set_key); 1776 src_set = lookup_set (task->step->session, src_set_key);
1727 GNUNET_assert(NULL != src_set); 1777 GNUNET_assert (NULL != src_set);
1728 GNUNET_SET_copy_lazy(src_set->h, 1778 GNUNET_SET_copy_lazy (src_set->h,
1729 set_copy_cb, 1779 set_copy_cb,
1730 scc); 1780 scc);
1731} 1781}
1732 1782
1733 1783
1734struct SetMutationProgressCls { 1784struct SetMutationProgressCls
1785{
1735 int num_pending; 1786 int num_pending;
1736 /** 1787 /**
1737 * Task to finish once all changes are through. 1788 * Task to finish once all changes are through.
@@ -1741,25 +1792,25 @@ struct SetMutationProgressCls {
1741 1792
1742 1793
1743static void 1794static void
1744set_mutation_done(void *cls) 1795set_mutation_done (void *cls)
1745{ 1796{
1746 struct SetMutationProgressCls *pc = cls; 1797 struct SetMutationProgressCls *pc = cls;
1747 1798
1748 GNUNET_assert(pc->num_pending > 0); 1799 GNUNET_assert (pc->num_pending > 0);
1749 1800
1750 pc->num_pending--; 1801 pc->num_pending--;
1751 1802
1752 if (0 == pc->num_pending) 1803 if (0 == pc->num_pending)
1753 { 1804 {
1754 struct TaskEntry *task = pc->task; 1805 struct TaskEntry *task = pc->task;
1755 GNUNET_free(pc); 1806 GNUNET_free (pc);
1756 finish_task(task); 1807 finish_task (task);
1757 } 1808 }
1758} 1809}
1759 1810
1760 1811
1761static void 1812static void
1762try_finish_step_early(struct Step *step) 1813try_finish_step_early (struct Step *step)
1763{ 1814{
1764 unsigned int i; 1815 unsigned int i;
1765 1816
@@ -1773,61 +1824,61 @@ try_finish_step_early(struct Step *step)
1773 step->is_finished = GNUNET_YES; 1824 step->is_finished = GNUNET_YES;
1774 1825
1775#ifdef GNUNET_EXTRA_LOGGING 1826#ifdef GNUNET_EXTRA_LOGGING
1776 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1827 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1777 "Finishing step `%s' early.\n", 1828 "Finishing step `%s' early.\n",
1778 step->debug_name); 1829 step->debug_name);
1779#endif 1830#endif
1780 1831
1781 for (i = 0; i < step->subordinates_len; i++) 1832 for (i = 0; i < step->subordinates_len; i++)
1782 { 1833 {
1783 GNUNET_assert(step->subordinates[i]->pending_prereq > 0); 1834 GNUNET_assert (step->subordinates[i]->pending_prereq > 0);
1784 step->subordinates[i]->pending_prereq--; 1835 step->subordinates[i]->pending_prereq--;
1785#ifdef GNUNET_EXTRA_LOGGING 1836#ifdef GNUNET_EXTRA_LOGGING
1786 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1837 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1787 "Decreased pending_prereq to %u for step `%s'.\n", 1838 "Decreased pending_prereq to %u for step `%s'.\n",
1788 (unsigned int)step->subordinates[i]->pending_prereq, 1839 (unsigned int) step->subordinates[i]->pending_prereq,
1789 step->subordinates[i]->debug_name); 1840 step->subordinates[i]->debug_name);
1790#endif 1841#endif
1791 try_finish_step_early(step->subordinates[i]); 1842 try_finish_step_early (step->subordinates[i]);
1792 } 1843 }
1793 1844
1794 // XXX: maybe schedule as task to avoid recursion? 1845 // XXX: maybe schedule as task to avoid recursion?
1795 run_ready_steps(step->session); 1846 run_ready_steps (step->session);
1796} 1847}
1797 1848
1798 1849
1799static void 1850static void
1800finish_step(struct Step *step) 1851finish_step (struct Step *step)
1801{ 1852{
1802 unsigned int i; 1853 unsigned int i;
1803 1854
1804 GNUNET_assert(step->finished_tasks == step->tasks_len); 1855 GNUNET_assert (step->finished_tasks == step->tasks_len);
1805 GNUNET_assert(GNUNET_YES == step->is_running); 1856 GNUNET_assert (GNUNET_YES == step->is_running);
1806 GNUNET_assert(GNUNET_NO == step->is_finished); 1857 GNUNET_assert (GNUNET_NO == step->is_finished);
1807 1858
1808#ifdef GNUNET_EXTRA_LOGGING 1859#ifdef GNUNET_EXTRA_LOGGING
1809 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1860 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1810 "All tasks of step `%s' with %u subordinates finished.\n", 1861 "All tasks of step `%s' with %u subordinates finished.\n",
1811 step->debug_name, 1862 step->debug_name,
1812 step->subordinates_len); 1863 step->subordinates_len);
1813#endif 1864#endif
1814 1865
1815 for (i = 0; i < step->subordinates_len; i++) 1866 for (i = 0; i < step->subordinates_len; i++)
1816 { 1867 {
1817 GNUNET_assert(step->subordinates[i]->pending_prereq > 0); 1868 GNUNET_assert (step->subordinates[i]->pending_prereq > 0);
1818 step->subordinates[i]->pending_prereq--; 1869 step->subordinates[i]->pending_prereq--;
1819#ifdef GNUNET_EXTRA_LOGGING 1870#ifdef GNUNET_EXTRA_LOGGING
1820 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1871 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1821 "Decreased pending_prereq to %u for step `%s'.\n", 1872 "Decreased pending_prereq to %u for step `%s'.\n",
1822 (unsigned int)step->subordinates[i]->pending_prereq, 1873 (unsigned int) step->subordinates[i]->pending_prereq,
1823 step->subordinates[i]->debug_name); 1874 step->subordinates[i]->debug_name);
1824#endif 1875#endif
1825 } 1876 }
1826 1877
1827 step->is_finished = GNUNET_YES; 1878 step->is_finished = GNUNET_YES;
1828 1879
1829 // XXX: maybe schedule as task to avoid recursion? 1880 // XXX: maybe schedule as task to avoid recursion?
1830 run_ready_steps(step->session); 1881 run_ready_steps (step->session);
1831} 1882}
1832 1883
1833 1884
@@ -1839,7 +1890,7 @@ finish_step(struct Step *step)
1839 * @param task the task with context information 1890 * @param task the task with context information
1840 */ 1891 */
1841static void 1892static void
1842task_start_apply_round(struct TaskEntry *task) 1893task_start_apply_round (struct TaskEntry *task)
1843{ 1894{
1844 struct ConsensusSession *session = task->step->session; 1895 struct ConsensusSession *session = task->step->session;
1845 struct SetKey sk_in; 1896 struct SetKey sk_in;
@@ -1856,136 +1907,138 @@ task_start_apply_round(struct TaskEntry *task)
1856 rk_in = (struct RfnKey) { RFN_KIND_GRADECAST_RESULT, task->key.repetition }; 1907 rk_in = (struct RfnKey) { RFN_KIND_GRADECAST_RESULT, task->key.repetition };
1857 sk_out = (struct SetKey) { SET_KIND_CURRENT, task->key.repetition + 1 }; 1908 sk_out = (struct SetKey) { SET_KIND_CURRENT, task->key.repetition + 1 };
1858 1909
1859 set_out = lookup_set(session, &sk_out); 1910 set_out = lookup_set (session, &sk_out);
1860 if (NULL == set_out) 1911 if (NULL == set_out)
1861 { 1912 {
1862 create_set_copy_for_task(task, &sk_in, &sk_out); 1913 create_set_copy_for_task (task, &sk_in, &sk_out);
1863 return; 1914 return;
1864 } 1915 }
1865 1916
1866 rfn_in = lookup_rfn(session, &rk_in); 1917 rfn_in = lookup_rfn (session, &rk_in);
1867 GNUNET_assert(NULL != rfn_in); 1918 GNUNET_assert (NULL != rfn_in);
1868 1919
1869 progress_cls = GNUNET_new(struct SetMutationProgressCls); 1920 progress_cls = GNUNET_new (struct SetMutationProgressCls);
1870 progress_cls->task = task; 1921 progress_cls->task = task;
1871 1922
1872 iter = GNUNET_CONTAINER_multihashmap_iterator_create(rfn_in->rfn_elements); 1923 iter = GNUNET_CONTAINER_multihashmap_iterator_create (rfn_in->rfn_elements);
1873 1924
1874 while (GNUNET_YES == 1925 while (GNUNET_YES ==
1875 GNUNET_CONTAINER_multihashmap_iterator_next(iter, 1926 GNUNET_CONTAINER_multihashmap_iterator_next (iter,
1876 NULL, 1927 NULL,
1877 (const void **)&ri)) 1928 (const void **) &ri))
1878 { 1929 {
1879 uint16_t majority_num; 1930 uint16_t majority_num;
1880 enum ReferendumVote majority_vote; 1931 enum ReferendumVote majority_vote;
1932
1933 rfn_majority (rfn_in, ri, &majority_num, &majority_vote);
1934
1935 if (worst_majority > majority_num)
1936 worst_majority = majority_num;
1937
1938 switch (majority_vote)
1939 {
1940 case VOTE_ADD:
1941 progress_cls->num_pending++;
1942 GNUNET_assert (GNUNET_OK ==
1943 GNUNET_SET_add_element (set_out->h,
1944 ri->element,
1945 &set_mutation_done,
1946 progress_cls));
1947 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1948 "P%u: apply round: adding element %s with %u-majority.\n",
1949 session->local_peer_idx,
1950 debug_str_element (ri->element), majority_num);
1951 break;
1881 1952
1882 rfn_majority(rfn_in, ri, &majority_num, &majority_vote); 1953 case VOTE_REMOVE:
1954 progress_cls->num_pending++;
1955 GNUNET_assert (GNUNET_OK ==
1956 GNUNET_SET_remove_element (set_out->h,
1957 ri->element,
1958 &set_mutation_done,
1959 progress_cls));
1960 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1961 "P%u: apply round: deleting element %s with %u-majority.\n",
1962 session->local_peer_idx,
1963 debug_str_element (ri->element), majority_num);
1964 break;
1883 1965
1884 if (worst_majority > majority_num) 1966 case VOTE_STAY:
1885 worst_majority = majority_num; 1967 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1968 "P%u: apply round: keeping element %s with %u-majority.\n",
1969 session->local_peer_idx,
1970 debug_str_element (ri->element), majority_num);
1971 // do nothing
1972 break;
1886 1973
1887 switch (majority_vote) 1974 default:
1888 { 1975 GNUNET_assert (0);
1889 case VOTE_ADD: 1976 break;
1890 progress_cls->num_pending++;
1891 GNUNET_assert(GNUNET_OK ==
1892 GNUNET_SET_add_element(set_out->h,
1893 ri->element,
1894 &set_mutation_done,
1895 progress_cls));
1896 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1897 "P%u: apply round: adding element %s with %u-majority.\n",
1898 session->local_peer_idx,
1899 debug_str_element(ri->element), majority_num);
1900 break;
1901
1902 case VOTE_REMOVE:
1903 progress_cls->num_pending++;
1904 GNUNET_assert(GNUNET_OK ==
1905 GNUNET_SET_remove_element(set_out->h,
1906 ri->element,
1907 &set_mutation_done,
1908 progress_cls));
1909 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1910 "P%u: apply round: deleting element %s with %u-majority.\n",
1911 session->local_peer_idx,
1912 debug_str_element(ri->element), majority_num);
1913 break;
1914
1915 case VOTE_STAY:
1916 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1917 "P%u: apply round: keeping element %s with %u-majority.\n",
1918 session->local_peer_idx,
1919 debug_str_element(ri->element), majority_num);
1920 // do nothing
1921 break;
1922
1923 default:
1924 GNUNET_assert(0);
1925 break;
1926 }
1927 } 1977 }
1978 }
1928 1979
1929 if (0 == progress_cls->num_pending) 1980 if (0 == progress_cls->num_pending)
1930 { 1981 {
1931 // call closure right now, no pending ops 1982 // call closure right now, no pending ops
1932 GNUNET_free(progress_cls); 1983 GNUNET_free (progress_cls);
1933 finish_task(task); 1984 finish_task (task);
1934 } 1985 }
1935 1986
1936 { 1987 {
1937 uint16_t thresh = (session->num_peers / 3) * 2; 1988 uint16_t thresh = (session->num_peers / 3) * 2;
1938 1989
1939 if (worst_majority >= thresh) 1990 if (worst_majority >= thresh)
1991 {
1992 switch (session->early_stopping)
1940 { 1993 {
1941 switch (session->early_stopping) 1994 case EARLY_STOPPING_NONE:
1942 { 1995 session->early_stopping = EARLY_STOPPING_ONE_MORE;
1943 case EARLY_STOPPING_NONE: 1996 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1944 session->early_stopping = EARLY_STOPPING_ONE_MORE; 1997 "P%u: Stopping early (after one more superround)\n",
1945 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1998 session->local_peer_idx);
1946 "P%u: Stopping early (after one more superround)\n", 1999 break;
1947 session->local_peer_idx); 2000
1948 break; 2001 case EARLY_STOPPING_ONE_MORE:
1949 2002 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1950 case EARLY_STOPPING_ONE_MORE: 2003 "P%u: finishing steps due to early finish\n",
1951 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "P%u: finishing steps due to early finish\n", 2004 session->local_peer_idx);
1952 session->local_peer_idx); 2005 session->early_stopping = EARLY_STOPPING_DONE;
1953 session->early_stopping = EARLY_STOPPING_DONE; 2006 {
1954 { 2007 struct Step *step;
1955 struct Step *step; 2008 for (step = session->steps_head; NULL != step; step = step->next)
1956 for (step = session->steps_head; NULL != step; step = step->next) 2009 try_finish_step_early (step);
1957 try_finish_step_early(step); 2010 }
1958 } 2011 break;
1959 break; 2012
1960 2013 case EARLY_STOPPING_DONE:
1961 case EARLY_STOPPING_DONE: 2014 /* We shouldn't be here anymore after early stopping */
1962 /* We shouldn't be here anymore after early stopping */ 2015 GNUNET_break (0);
1963 GNUNET_break(0); 2016 break;
1964 break; 2017
1965 2018 default:
1966 default: 2019 GNUNET_assert (0);
1967 GNUNET_assert(0); 2020 break;
1968 break;
1969 }
1970 } 2021 }
2022 }
1971 else if (EARLY_STOPPING_NONE != session->early_stopping) 2023 else if (EARLY_STOPPING_NONE != session->early_stopping)
1972 { 2024 {
1973 // Our assumption about the number of bad peers 2025 // Our assumption about the number of bad peers
1974 // has been broken. 2026 // has been broken.
1975 GNUNET_break_op(0); 2027 GNUNET_break_op (0);
1976 } 2028 }
1977 else 2029 else
1978 { 2030 {
1979 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "P%u: NOT finishing early (majority not good enough)\n", 2031 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1980 session->local_peer_idx); 2032 "P%u: NOT finishing early (majority not good enough)\n",
1981 } 2033 session->local_peer_idx);
2034 }
1982 } 2035 }
1983 GNUNET_CONTAINER_multihashmap_iterator_destroy(iter); 2036 GNUNET_CONTAINER_multihashmap_iterator_destroy (iter);
1984} 2037}
1985 2038
1986 2039
1987static void 2040static void
1988task_start_grade(struct TaskEntry *task) 2041task_start_grade (struct TaskEntry *task)
1989{ 2042{
1990 struct ConsensusSession *session = task->step->session; 2043 struct ConsensusSession *session = task->step->session;
1991 struct ReferendumEntry *output_rfn; 2044 struct ReferendumEntry *output_rfn;
@@ -1998,93 +2051,97 @@ task_start_grade(struct TaskEntry *task)
1998 unsigned int gradecast_confidence = 2; 2051 unsigned int gradecast_confidence = 2;
1999 2052
2000 rfn_key = (struct RfnKey) { RFN_KIND_GRADECAST_RESULT, task->key.repetition }; 2053 rfn_key = (struct RfnKey) { RFN_KIND_GRADECAST_RESULT, task->key.repetition };
2001 output_rfn = lookup_rfn(session, &rfn_key); 2054 output_rfn = lookup_rfn (session, &rfn_key);
2002 if (NULL == output_rfn) 2055 if (NULL == output_rfn)
2003 { 2056 {
2004 output_rfn = rfn_create(session->num_peers); 2057 output_rfn = rfn_create (session->num_peers);
2005 output_rfn->key = rfn_key; 2058 output_rfn->key = rfn_key;
2006 put_rfn(session, output_rfn); 2059 put_rfn (session, output_rfn);
2007 } 2060 }
2008 2061
2009 diff_key = (struct DiffKey) { DIFF_KIND_LEADER_PROPOSAL, task->key.repetition, task->key.leader }; 2062 diff_key = (struct DiffKey) { DIFF_KIND_LEADER_PROPOSAL, task->key.repetition,
2010 input_diff = lookup_diff(session, &diff_key); 2063 task->key.leader };
2011 GNUNET_assert(NULL != input_diff); 2064 input_diff = lookup_diff (session, &diff_key);
2065 GNUNET_assert (NULL != input_diff);
2012 2066
2013 rfn_key = (struct RfnKey) { RFN_KIND_ECHO, task->key.repetition, task->key.leader }; 2067 rfn_key = (struct RfnKey) { RFN_KIND_ECHO, task->key.repetition,
2014 input_rfn = lookup_rfn(session, &rfn_key); 2068 task->key.leader };
2015 GNUNET_assert(NULL != input_rfn); 2069 input_rfn = lookup_rfn (session, &rfn_key);
2070 GNUNET_assert (NULL != input_rfn);
2016 2071
2017 iter = GNUNET_CONTAINER_multihashmap_iterator_create(input_rfn->rfn_elements); 2072 iter = GNUNET_CONTAINER_multihashmap_iterator_create (
2073 input_rfn->rfn_elements);
2018 2074
2019 apply_diff_to_rfn(input_diff, output_rfn, task->key.leader, session->num_peers); 2075 apply_diff_to_rfn (input_diff, output_rfn, task->key.leader,
2076 session->num_peers);
2020 2077
2021 while (GNUNET_YES == 2078 while (GNUNET_YES ==
2022 GNUNET_CONTAINER_multihashmap_iterator_next(iter, 2079 GNUNET_CONTAINER_multihashmap_iterator_next (iter,
2023 NULL, 2080 NULL,
2024 (const void **)&ri)) 2081 (const void **) &ri))
2025 { 2082 {
2026 uint16_t majority_num; 2083 uint16_t majority_num;
2027 enum ReferendumVote majority_vote; 2084 enum ReferendumVote majority_vote;
2028 2085
2029 // XXX: we need contested votes and non-contested votes here 2086 // XXX: we need contested votes and non-contested votes here
2030 rfn_majority(input_rfn, ri, &majority_num, &majority_vote); 2087 rfn_majority (input_rfn, ri, &majority_num, &majority_vote);
2031 2088
2032 if (majority_num <= session->num_peers / 3) 2089 if (majority_num <= session->num_peers / 3)
2033 majority_vote = VOTE_REMOVE; 2090 majority_vote = VOTE_REMOVE;
2034 2091
2035 switch (majority_vote) 2092 switch (majority_vote)
2036 { 2093 {
2037 case VOTE_STAY: 2094 case VOTE_STAY:
2038 break; 2095 break;
2039 2096
2040 case VOTE_ADD: 2097 case VOTE_ADD:
2041 rfn_vote(output_rfn, task->key.leader, VOTE_ADD, ri->element); 2098 rfn_vote (output_rfn, task->key.leader, VOTE_ADD, ri->element);
2042 break; 2099 break;
2043 2100
2044 case VOTE_REMOVE: 2101 case VOTE_REMOVE:
2045 rfn_vote(output_rfn, task->key.leader, VOTE_REMOVE, ri->element); 2102 rfn_vote (output_rfn, task->key.leader, VOTE_REMOVE, ri->element);
2046 break; 2103 break;
2047 2104
2048 default: 2105 default:
2049 GNUNET_assert(0); 2106 GNUNET_assert (0);
2050 break; 2107 break;
2051 }
2052 } 2108 }
2053 GNUNET_CONTAINER_multihashmap_iterator_destroy(iter); 2109 }
2110 GNUNET_CONTAINER_multihashmap_iterator_destroy (iter);
2054 2111
2055 { 2112 {
2056 uint16_t noncontested; 2113 uint16_t noncontested;
2057 noncontested = rfn_noncontested(input_rfn); 2114 noncontested = rfn_noncontested (input_rfn);
2058 if (noncontested < (session->num_peers / 3) * 2) 2115 if (noncontested < (session->num_peers / 3) * 2)
2059 { 2116 {
2060 gradecast_confidence = GNUNET_MIN(1, gradecast_confidence); 2117 gradecast_confidence = GNUNET_MIN (1, gradecast_confidence);
2061 } 2118 }
2062 if (noncontested < (session->num_peers / 3) + 1) 2119 if (noncontested < (session->num_peers / 3) + 1)
2063 { 2120 {
2064 gradecast_confidence = 0; 2121 gradecast_confidence = 0;
2065 } 2122 }
2066 } 2123 }
2067 2124
2068 if (gradecast_confidence >= 1) 2125 if (gradecast_confidence >= 1)
2069 rfn_commit(output_rfn, task->key.leader); 2126 rfn_commit (output_rfn, task->key.leader);
2070 2127
2071 if (gradecast_confidence <= 1) 2128 if (gradecast_confidence <= 1)
2072 session->peers_blacklisted[task->key.leader] = GNUNET_YES; 2129 session->peers_blacklisted[task->key.leader] = GNUNET_YES;
2073 2130
2074 finish_task(task); 2131 finish_task (task);
2075} 2132}
2076 2133
2077 2134
2078static void 2135static void
2079task_start_reconcile(struct TaskEntry *task) 2136task_start_reconcile (struct TaskEntry *task)
2080{ 2137{
2081 struct SetEntry *input; 2138 struct SetEntry *input;
2082 struct SetOpCls *setop = &task->cls.setop; 2139 struct SetOpCls *setop = &task->cls.setop;
2083 struct ConsensusSession *session = task->step->session; 2140 struct ConsensusSession *session = task->step->session;
2084 2141
2085 input = lookup_set(session, &setop->input_set); 2142 input = lookup_set (session, &setop->input_set);
2086 GNUNET_assert(NULL != input); 2143 GNUNET_assert (NULL != input);
2087 GNUNET_assert(NULL != input->h); 2144 GNUNET_assert (NULL != input->h);
2088 2145
2089 /* We create the outputs for the operation here 2146 /* We create the outputs for the operation here
2090 (rather than in the set operation callback) 2147 (rather than in the set operation callback)
@@ -2092,113 +2149,117 @@ task_start_reconcile(struct TaskEntry *task)
2092 if the other peer doesn't talk to us */ 2149 if the other peer doesn't talk to us */
2093 2150
2094 if (SET_KIND_NONE != setop->output_set.set_kind) 2151 if (SET_KIND_NONE != setop->output_set.set_kind)
2152 {
2153 /* If we don't have an existing output set,
2154 we clone the input set. */
2155 if (NULL == lookup_set (session, &setop->output_set))
2095 { 2156 {
2096 /* If we don't have an existing output set, 2157 create_set_copy_for_task (task, &setop->input_set, &setop->output_set);
2097 we clone the input set. */ 2158 return;
2098 if (NULL == lookup_set(session, &setop->output_set))
2099 {
2100 create_set_copy_for_task(task, &setop->input_set, &setop->output_set);
2101 return;
2102 }
2103 } 2159 }
2160 }
2104 2161
2105 if (RFN_KIND_NONE != setop->output_rfn.rfn_kind) 2162 if (RFN_KIND_NONE != setop->output_rfn.rfn_kind)
2163 {
2164 if (NULL == lookup_rfn (session, &setop->output_rfn))
2106 { 2165 {
2107 if (NULL == lookup_rfn(session, &setop->output_rfn)) 2166 struct ReferendumEntry *rfn;
2108 {
2109 struct ReferendumEntry *rfn;
2110 2167
2111 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2112 "P%u: output rfn <%s> missing, creating.\n", 2169 "P%u: output rfn <%s> missing, creating.\n",
2113 session->local_peer_idx, 2170 session->local_peer_idx,
2114 debug_str_rfn_key(&setop->output_rfn)); 2171 debug_str_rfn_key (&setop->output_rfn));
2115 2172
2116 rfn = rfn_create(session->num_peers); 2173 rfn = rfn_create (session->num_peers);
2117 rfn->key = setop->output_rfn; 2174 rfn->key = setop->output_rfn;
2118 put_rfn(session, rfn); 2175 put_rfn (session, rfn);
2119 }
2120 } 2176 }
2177 }
2121 2178
2122 if (DIFF_KIND_NONE != setop->output_diff.diff_kind) 2179 if (DIFF_KIND_NONE != setop->output_diff.diff_kind)
2180 {
2181 if (NULL == lookup_diff (session, &setop->output_diff))
2123 { 2182 {
2124 if (NULL == lookup_diff(session, &setop->output_diff)) 2183 struct DiffEntry *diff;
2125 {
2126 struct DiffEntry *diff;
2127 2184
2128 diff = diff_create(); 2185 diff = diff_create ();
2129 diff->key = setop->output_diff; 2186 diff->key = setop->output_diff;
2130 put_diff(session, diff); 2187 put_diff (session, diff);
2131 }
2132 } 2188 }
2189 }
2133 2190
2134 if ((task->key.peer1 == session->local_peer_idx) && (task->key.peer2 == session->local_peer_idx)) 2191 if ((task->key.peer1 == session->local_peer_idx) && (task->key.peer2 ==
2135 { 2192 session->local_peer_idx))
2136 /* XXX: mark the corresponding rfn as commited if necessary */ 2193 {
2137 finish_task(task); 2194 /* XXX: mark the corresponding rfn as commited if necessary */
2138 return; 2195 finish_task (task);
2139 } 2196 return;
2197 }
2140 2198
2141 if (task->key.peer1 == session->local_peer_idx) 2199 if (task->key.peer1 == session->local_peer_idx)
2142 { 2200 {
2143 struct GNUNET_CONSENSUS_RoundContextMessage rcm; 2201 struct GNUNET_CONSENSUS_RoundContextMessage rcm;
2144 2202
2145 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2146 "P%u: Looking up set {%s} to run remote union\n", 2204 "P%u: Looking up set {%s} to run remote union\n",
2147 session->local_peer_idx, 2205 session->local_peer_idx,
2148 debug_str_set_key(&setop->input_set)); 2206 debug_str_set_key (&setop->input_set));
2149 2207
2150 rcm.header.type = htons(GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ROUND_CONTEXT); 2208 rcm.header.type = htons (GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ROUND_CONTEXT);
2151 rcm.header.size = htons(sizeof(struct GNUNET_CONSENSUS_RoundContextMessage)); 2209 rcm.header.size = htons (sizeof(struct
2152 2210 GNUNET_CONSENSUS_RoundContextMessage));
2153 rcm.kind = htons(task->key.kind); 2211
2154 rcm.peer1 = htons(task->key.peer1); 2212 rcm.kind = htons (task->key.kind);
2155 rcm.peer2 = htons(task->key.peer2); 2213 rcm.peer1 = htons (task->key.peer1);
2156 rcm.leader = htons(task->key.leader); 2214 rcm.peer2 = htons (task->key.peer2);
2157 rcm.repetition = htons(task->key.repetition); 2215 rcm.leader = htons (task->key.leader);
2158 rcm.is_contested = htons(0); 2216 rcm.repetition = htons (task->key.repetition);
2159 2217 rcm.is_contested = htons (0);
2160 GNUNET_assert(NULL == setop->op); 2218
2161 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "P%u: initiating set op with P%u, our set is %s\n", 2219 GNUNET_assert (NULL == setop->op);
2162 session->local_peer_idx, task->key.peer2, debug_str_set_key(&setop->input_set)); 2220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2163 2221 "P%u: initiating set op with P%u, our set is %s\n",
2164 struct GNUNET_SET_Option opts[] = { 2222 session->local_peer_idx, task->key.peer2, debug_str_set_key (
2165 { GNUNET_SET_OPTION_BYZANTINE, { .num = session->lower_bound } }, 2223 &setop->input_set));
2166 { GNUNET_SET_OPTION_END }, 2224
2167 }; 2225 struct GNUNET_SET_Option opts[] = {
2168 2226 { GNUNET_SET_OPTION_BYZANTINE, { .num = session->lower_bound } },
2169 // XXX: maybe this should be done while 2227 { GNUNET_SET_OPTION_END },
2170 // setting up tasks alreays? 2228 };
2171 setop->op = GNUNET_SET_prepare(&session->peers[task->key.peer2], 2229
2172 &session->global_id, 2230 // XXX: maybe this should be done while
2173 &rcm.header, 2231 // setting up tasks alreays?
2174 GNUNET_SET_RESULT_SYMMETRIC, 2232 setop->op = GNUNET_SET_prepare (&session->peers[task->key.peer2],
2175 opts, 2233 &session->global_id,
2176 set_result_cb, 2234 &rcm.header,
2177 task); 2235 GNUNET_SET_RESULT_SYMMETRIC,
2178 2236 opts,
2179 commit_set(session, task); 2237 set_result_cb,
2180 } 2238 task);
2239
2240 commit_set (session, task);
2241 }
2181 else if (task->key.peer2 == session->local_peer_idx) 2242 else if (task->key.peer2 == session->local_peer_idx)
2182 { 2243 {
2183 /* Wait for the other peer to contact us */ 2244 /* Wait for the other peer to contact us */
2184 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "P%u: waiting set op with P%u\n", 2245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: waiting set op with P%u\n",
2185 session->local_peer_idx, task->key.peer1); 2246 session->local_peer_idx, task->key.peer1);
2186 2247
2187 if (NULL != setop->op) 2248 if (NULL != setop->op)
2188 {
2189 commit_set(session, task);
2190 }
2191 }
2192 else
2193 { 2249 {
2194 /* We made an error while constructing the task graph. */ 2250 commit_set (session, task);
2195 GNUNET_assert(0);
2196 } 2251 }
2252 }
2253 else
2254 {
2255 /* We made an error while constructing the task graph. */
2256 GNUNET_assert (0);
2257 }
2197} 2258}
2198 2259
2199 2260
2200static void 2261static void
2201task_start_eval_echo(struct TaskEntry *task) 2262task_start_eval_echo (struct TaskEntry *task)
2202{ 2263{
2203 struct GNUNET_CONTAINER_MultiHashMapIterator *iter; 2264 struct GNUNET_CONTAINER_MultiHashMapIterator *iter;
2204 struct ReferendumEntry *input_rfn; 2265 struct ReferendumEntry *input_rfn;
@@ -2210,128 +2271,133 @@ task_start_eval_echo(struct TaskEntry *task)
2210 struct SetKey sk_out; 2271 struct SetKey sk_out;
2211 struct RfnKey rk_in; 2272 struct RfnKey rk_in;
2212 2273
2213 sk_in = (struct SetKey) { SET_KIND_LEADER_PROPOSAL, task->key.repetition, task->key.leader }; 2274 sk_in = (struct SetKey) { SET_KIND_LEADER_PROPOSAL, task->key.repetition,
2214 sk_out = (struct SetKey) { SET_KIND_ECHO_RESULT, task->key.repetition, task->key.leader }; 2275 task->key.leader };
2215 output_set = lookup_set(session, &sk_out); 2276 sk_out = (struct SetKey) { SET_KIND_ECHO_RESULT, task->key.repetition,
2277 task->key.leader };
2278 output_set = lookup_set (session, &sk_out);
2216 if (NULL == output_set) 2279 if (NULL == output_set)
2217 { 2280 {
2218 create_set_copy_for_task(task, &sk_in, &sk_out); 2281 create_set_copy_for_task (task, &sk_in, &sk_out);
2219 return; 2282 return;
2220 } 2283 }
2221 2284
2222 2285
2223 { 2286 {
2224 // FIXME: should be marked as a shallow copy, so 2287 // FIXME: should be marked as a shallow copy, so
2225 // we can destroy everything correctly 2288 // we can destroy everything correctly
2226 struct SetEntry *last_set = GNUNET_new(struct SetEntry); 2289 struct SetEntry *last_set = GNUNET_new (struct SetEntry);
2227 last_set->h = output_set->h; 2290 last_set->h = output_set->h;
2228 last_set->key = (struct SetKey) { SET_KIND_LAST_GRADECAST }; 2291 last_set->key = (struct SetKey) { SET_KIND_LAST_GRADECAST };
2229 put_set(session, last_set); 2292 put_set (session, last_set);
2230 } 2293 }
2231 2294
2232 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2233 "Evaluating referendum in Task {%s}\n", 2296 "Evaluating referendum in Task {%s}\n",
2234 debug_str_task_key(&task->key)); 2297 debug_str_task_key (&task->key));
2235 2298
2236 progress_cls = GNUNET_new(struct SetMutationProgressCls); 2299 progress_cls = GNUNET_new (struct SetMutationProgressCls);
2237 progress_cls->task = task; 2300 progress_cls->task = task;
2238 2301
2239 rk_in = (struct RfnKey) { RFN_KIND_ECHO, task->key.repetition, task->key.leader }; 2302 rk_in = (struct RfnKey) { RFN_KIND_ECHO, task->key.repetition,
2240 input_rfn = lookup_rfn(session, &rk_in); 2303 task->key.leader };
2304 input_rfn = lookup_rfn (session, &rk_in);
2241 2305
2242 GNUNET_assert(NULL != input_rfn); 2306 GNUNET_assert (NULL != input_rfn);
2243 2307
2244 iter = GNUNET_CONTAINER_multihashmap_iterator_create(input_rfn->rfn_elements); 2308 iter = GNUNET_CONTAINER_multihashmap_iterator_create (
2245 GNUNET_assert(NULL != iter); 2309 input_rfn->rfn_elements);
2310 GNUNET_assert (NULL != iter);
2246 2311
2247 while (GNUNET_YES == 2312 while (GNUNET_YES ==
2248 GNUNET_CONTAINER_multihashmap_iterator_next(iter, 2313 GNUNET_CONTAINER_multihashmap_iterator_next (iter,
2249 NULL, 2314 NULL,
2250 (const void **)&ri)) 2315 (const void **) &ri))
2316 {
2317 enum ReferendumVote majority_vote;
2318 uint16_t majority_num;
2319
2320 rfn_majority (input_rfn, ri, &majority_num, &majority_vote);
2321
2322 if (majority_num < session->num_peers / 3)
2251 { 2323 {
2252 enum ReferendumVote majority_vote; 2324 /* It is not the case that all nonfaulty peers
2253 uint16_t majority_num; 2325 echoed the same value. Since we're doing a set reconciliation, we
2326 can't simply send "nothing" for the value. Thus we mark our 'confirm'
2327 reconciliation as contested. Other peers might not know that the
2328 leader is faulty, thus we still re-distribute in the confirmation
2329 round. */
2330 output_set->is_contested = GNUNET_YES;
2331 }
2254 2332
2255 rfn_majority(input_rfn, ri, &majority_num, &majority_vote); 2333 switch (majority_vote)
2334 {
2335 case VOTE_ADD:
2336 progress_cls->num_pending++;
2337 GNUNET_assert (GNUNET_OK ==
2338 GNUNET_SET_add_element (output_set->h,
2339 ri->element,
2340 set_mutation_done,
2341 progress_cls));
2342 break;
2256 2343
2257 if (majority_num < session->num_peers / 3) 2344 case VOTE_REMOVE:
2258 { 2345 progress_cls->num_pending++;
2259 /* It is not the case that all nonfaulty peers 2346 GNUNET_assert (GNUNET_OK ==
2260 echoed the same value. Since we're doing a set reconciliation, we 2347 GNUNET_SET_remove_element (output_set->h,
2261 can't simply send "nothing" for the value. Thus we mark our 'confirm' 2348 ri->element,
2262 reconciliation as contested. Other peers might not know that the 2349 set_mutation_done,
2263 leader is faulty, thus we still re-distribute in the confirmation 2350 progress_cls));
2264 round. */ 2351 break;
2265 output_set->is_contested = GNUNET_YES;
2266 }
2267 2352
2268 switch (majority_vote) 2353 case VOTE_STAY:
2269 { 2354 /* Nothing to do. */
2270 case VOTE_ADD: 2355 break;
2271 progress_cls->num_pending++; 2356
2272 GNUNET_assert(GNUNET_OK == 2357 default:
2273 GNUNET_SET_add_element(output_set->h, 2358 /* not reached */
2274 ri->element, 2359 GNUNET_assert (0);
2275 set_mutation_done,
2276 progress_cls));
2277 break;
2278
2279 case VOTE_REMOVE:
2280 progress_cls->num_pending++;
2281 GNUNET_assert(GNUNET_OK ==
2282 GNUNET_SET_remove_element(output_set->h,
2283 ri->element,
2284 set_mutation_done,
2285 progress_cls));
2286 break;
2287
2288 case VOTE_STAY:
2289 /* Nothing to do. */
2290 break;
2291
2292 default:
2293 /* not reached */
2294 GNUNET_assert(0);
2295 }
2296 } 2360 }
2361 }
2297 2362
2298 GNUNET_CONTAINER_multihashmap_iterator_destroy(iter); 2363 GNUNET_CONTAINER_multihashmap_iterator_destroy (iter);
2299 2364
2300 if (0 == progress_cls->num_pending) 2365 if (0 == progress_cls->num_pending)
2301 { 2366 {
2302 // call closure right now, no pending ops 2367 // call closure right now, no pending ops
2303 GNUNET_free(progress_cls); 2368 GNUNET_free (progress_cls);
2304 finish_task(task); 2369 finish_task (task);
2305 } 2370 }
2306} 2371}
2307 2372
2308 2373
2309static void 2374static void
2310task_start_finish(struct TaskEntry *task) 2375task_start_finish (struct TaskEntry *task)
2311{ 2376{
2312 struct SetEntry *final_set; 2377 struct SetEntry *final_set;
2313 struct ConsensusSession *session = task->step->session; 2378 struct ConsensusSession *session = task->step->session;
2314 2379
2315 final_set = lookup_set(session, &task->cls.finish.input_set); 2380 final_set = lookup_set (session, &task->cls.finish.input_set);
2316 2381
2317 GNUNET_assert(NULL != final_set); 2382 GNUNET_assert (NULL != final_set);
2318 2383
2319 2384
2320 GNUNET_SET_iterate(final_set->h, 2385 GNUNET_SET_iterate (final_set->h,
2321 send_to_client_iter, 2386 send_to_client_iter,
2322 task); 2387 task);
2323} 2388}
2324 2389
2325static void 2390static void
2326start_task(struct ConsensusSession *session, struct TaskEntry *task) 2391start_task (struct ConsensusSession *session, struct TaskEntry *task)
2327{ 2392{
2328 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "P%u: starting task {%s}\n", session->local_peer_idx, debug_str_task_key(&task->key)); 2393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: starting task {%s}\n",
2394 session->local_peer_idx, debug_str_task_key (&task->key));
2329 2395
2330 GNUNET_assert(GNUNET_NO == task->is_started); 2396 GNUNET_assert (GNUNET_NO == task->is_started);
2331 GNUNET_assert(GNUNET_NO == task->is_finished); 2397 GNUNET_assert (GNUNET_NO == task->is_finished);
2332 GNUNET_assert(NULL != task->start); 2398 GNUNET_assert (NULL != task->start);
2333 2399
2334 task->start(task); 2400 task->start (task);
2335 2401
2336 task->is_started = GNUNET_YES; 2402 task->is_started = GNUNET_YES;
2337} 2403}
@@ -2344,40 +2410,43 @@ start_task(struct ConsensusSession *session, struct TaskEntry *task)
2344 * more dependencies. 2410 * more dependencies.
2345 */ 2411 */
2346static void 2412static void
2347run_ready_steps(struct ConsensusSession *session) 2413run_ready_steps (struct ConsensusSession *session)
2348{ 2414{
2349 struct Step *step; 2415 struct Step *step;
2350 2416
2351 step = session->steps_head; 2417 step = session->steps_head;
2352 2418
2353 while (NULL != step) 2419 while (NULL != step)
2420 {
2421 if ((GNUNET_NO == step->is_running) && (0 == step->pending_prereq) &&
2422 (GNUNET_NO == step->is_finished))
2354 { 2423 {
2355 if ((GNUNET_NO == step->is_running) && (0 == step->pending_prereq) && (GNUNET_NO == step->is_finished)) 2424 size_t i;
2356 {
2357 size_t i;
2358 2425
2359 GNUNET_assert(0 == step->finished_tasks); 2426 GNUNET_assert (0 == step->finished_tasks);
2360 2427
2361#ifdef GNUNET_EXTRA_LOGGING 2428#ifdef GNUNET_EXTRA_LOGGING
2362 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "P%u: Running step `%s' of round %d with %d tasks and %d subordinates\n", 2429 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2363 session->local_peer_idx, 2430 "P%u: Running step `%s' of round %d with %d tasks and %d subordinates\n",
2364 step->debug_name, 2431 session->local_peer_idx,
2365 step->round, step->tasks_len, step->subordinates_len); 2432 step->debug_name,
2433 step->round, step->tasks_len, step->subordinates_len);
2366#endif 2434#endif
2367 2435
2368 step->is_running = GNUNET_YES; 2436 step->is_running = GNUNET_YES;
2369 for (i = 0; i < step->tasks_len; i++) 2437 for (i = 0; i < step->tasks_len; i++)
2370 start_task(session, step->tasks[i]); 2438 start_task (session, step->tasks[i]);
2371 2439
2372 /* Sometimes there is no task to trigger finishing the step, so we have to do it here. */ 2440 /* Sometimes there is no task to trigger finishing the step, so we have to do it here. */
2373 if ((step->finished_tasks == step->tasks_len) && (GNUNET_NO == step->is_finished)) 2441 if ((step->finished_tasks == step->tasks_len) && (GNUNET_NO ==
2374 finish_step(step); 2442 step->is_finished))
2443 finish_step (step);
2375 2444
2376 /* Running the next ready steps will be triggered by task completion */ 2445 /* Running the next ready steps will be triggered by task completion */
2377 return; 2446 return;
2378 }
2379 step = step->next;
2380 } 2447 }
2448 step = step->next;
2449 }
2381 2450
2382 return; 2451 return;
2383} 2452}
@@ -2385,22 +2454,22 @@ run_ready_steps(struct ConsensusSession *session)
2385 2454
2386 2455
2387static void 2456static void
2388finish_task(struct TaskEntry *task) 2457finish_task (struct TaskEntry *task)
2389{ 2458{
2390 GNUNET_assert(GNUNET_NO == task->is_finished); 2459 GNUNET_assert (GNUNET_NO == task->is_finished);
2391 task->is_finished = GNUNET_YES; 2460 task->is_finished = GNUNET_YES;
2392 2461
2393 task->step->finished_tasks++; 2462 task->step->finished_tasks++;
2394 2463
2395 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2464 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2396 "P%u: Finishing Task {%s} (now %u/%u tasks finished in step)\n", 2465 "P%u: Finishing Task {%s} (now %u/%u tasks finished in step)\n",
2397 task->step->session->local_peer_idx, 2466 task->step->session->local_peer_idx,
2398 debug_str_task_key(&task->key), 2467 debug_str_task_key (&task->key),
2399 (unsigned int)task->step->finished_tasks, 2468 (unsigned int) task->step->finished_tasks,
2400 (unsigned int)task->step->tasks_len); 2469 (unsigned int) task->step->tasks_len);
2401 2470
2402 if (task->step->finished_tasks == task->step->tasks_len) 2471 if (task->step->finished_tasks == task->step->tasks_len)
2403 finish_step(task->step); 2472 finish_step (task->step);
2404} 2473}
2405 2474
2406 2475
@@ -2412,12 +2481,13 @@ finish_task(struct TaskEntry *task)
2412 * @return index of peer, -1 if peer is not in session 2481 * @return index of peer, -1 if peer is not in session
2413 */ 2482 */
2414static int 2483static int
2415get_peer_idx(const struct GNUNET_PeerIdentity *peer, const struct ConsensusSession *session) 2484get_peer_idx (const struct GNUNET_PeerIdentity *peer, const struct
2485 ConsensusSession *session)
2416{ 2486{
2417 int i; 2487 int i;
2418 2488
2419 for (i = 0; i < session->num_peers; i++) 2489 for (i = 0; i < session->num_peers; i++)
2420 if (0 == GNUNET_memcmp(peer, &session->peers[i])) 2490 if (0 == GNUNET_memcmp (peer, &session->peers[i]))
2421 return i; 2491 return i;
2422 return -1; 2492 return -1;
2423} 2493}
@@ -2433,21 +2503,22 @@ get_peer_idx(const struct GNUNET_PeerIdentity *peer, const struct ConsensusSessi
2433 * @param local_session_id local id of the consensus session 2503 * @param local_session_id local id of the consensus session
2434 */ 2504 */
2435static void 2505static void
2436compute_global_id(struct ConsensusSession *session, 2506compute_global_id (struct ConsensusSession *session,
2437 const struct GNUNET_HashCode *local_session_id) 2507 const struct GNUNET_HashCode *local_session_id)
2438{ 2508{
2439 const char *salt = "gnunet-service-consensus/session_id"; 2509 const char *salt = "gnunet-service-consensus/session_id";
2440 2510
2441 GNUNET_assert(GNUNET_YES == 2511 GNUNET_assert (GNUNET_YES ==
2442 GNUNET_CRYPTO_kdf(&session->global_id, 2512 GNUNET_CRYPTO_kdf (&session->global_id,
2443 sizeof(struct GNUNET_HashCode), 2513 sizeof(struct GNUNET_HashCode),
2444 salt, 2514 salt,
2445 strlen(salt), 2515 strlen (salt),
2446 session->peers, 2516 session->peers,
2447 session->num_peers * sizeof(struct GNUNET_PeerIdentity), 2517 session->num_peers * sizeof(struct
2448 local_session_id, 2518 GNUNET_PeerIdentity),
2449 sizeof(struct GNUNET_HashCode), 2519 local_session_id,
2450 NULL)); 2520 sizeof(struct GNUNET_HashCode),
2521 NULL));
2451} 2522}
2452 2523
2453 2524
@@ -2459,9 +2530,9 @@ compute_global_id(struct ConsensusSession *session,
2459 * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. 2530 * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2.
2460 */ 2531 */
2461static int 2532static int
2462peer_id_cmp(const void *h1, const void *h2) 2533peer_id_cmp (const void *h1, const void *h2)
2463{ 2534{
2464 return memcmp(h1, h2, sizeof(struct GNUNET_PeerIdentity)); 2535 return memcmp (h1, h2, sizeof(struct GNUNET_PeerIdentity));
2465} 2536}
2466 2537
2467 2538
@@ -2473,56 +2544,58 @@ peer_id_cmp(const void *h1, const void *h2)
2473 * @param join_msg join message with the list of peers participating at the end 2544 * @param join_msg join message with the list of peers participating at the end
2474 */ 2545 */
2475static void 2546static void
2476initialize_session_peer_list(struct ConsensusSession *session, 2547initialize_session_peer_list (struct ConsensusSession *session,
2477 const struct GNUNET_CONSENSUS_JoinMessage *join_msg) 2548 const struct
2549 GNUNET_CONSENSUS_JoinMessage *join_msg)
2478{ 2550{
2479 const struct GNUNET_PeerIdentity *msg_peers 2551 const struct GNUNET_PeerIdentity *msg_peers
2480 = (const struct GNUNET_PeerIdentity *)&join_msg[1]; 2552 = (const struct GNUNET_PeerIdentity *) &join_msg[1];
2481 int local_peer_in_list; 2553 int local_peer_in_list;
2482 2554
2483 session->num_peers = ntohl(join_msg->num_peers); 2555 session->num_peers = ntohl (join_msg->num_peers);
2484 2556
2485 /* Peers in the join message, may or may not include the local peer, 2557 /* Peers in the join message, may or may not include the local peer,
2486 Add it if it is missing. */ 2558 Add it if it is missing. */
2487 local_peer_in_list = GNUNET_NO; 2559 local_peer_in_list = GNUNET_NO;
2488 for (unsigned int i = 0; i < session->num_peers; i++) 2560 for (unsigned int i = 0; i < session->num_peers; i++)
2561 {
2562 if (0 == GNUNET_memcmp (&msg_peers[i],
2563 &my_peer))
2489 { 2564 {
2490 if (0 == GNUNET_memcmp(&msg_peers[i], 2565 local_peer_in_list = GNUNET_YES;
2491 &my_peer)) 2566 break;
2492 {
2493 local_peer_in_list = GNUNET_YES;
2494 break;
2495 }
2496 } 2567 }
2568 }
2497 if (GNUNET_NO == local_peer_in_list) 2569 if (GNUNET_NO == local_peer_in_list)
2498 session->num_peers++; 2570 session->num_peers++;
2499 2571
2500 session->peers = GNUNET_new_array(session->num_peers, 2572 session->peers = GNUNET_new_array (session->num_peers,
2501 struct GNUNET_PeerIdentity); 2573 struct GNUNET_PeerIdentity);
2502 if (GNUNET_NO == local_peer_in_list) 2574 if (GNUNET_NO == local_peer_in_list)
2503 session->peers[session->num_peers - 1] = my_peer; 2575 session->peers[session->num_peers - 1] = my_peer;
2504 2576
2505 GNUNET_memcpy(session->peers, 2577 GNUNET_memcpy (session->peers,
2506 msg_peers, 2578 msg_peers,
2507 ntohl(join_msg->num_peers) * sizeof(struct GNUNET_PeerIdentity)); 2579 ntohl (join_msg->num_peers) * sizeof(struct
2508 qsort(session->peers, 2580 GNUNET_PeerIdentity));
2509 session->num_peers, 2581 qsort (session->peers,
2510 sizeof(struct GNUNET_PeerIdentity), 2582 session->num_peers,
2511 &peer_id_cmp); 2583 sizeof(struct GNUNET_PeerIdentity),
2584 &peer_id_cmp);
2512} 2585}
2513 2586
2514 2587
2515static struct TaskEntry * 2588static struct TaskEntry *
2516lookup_task(struct ConsensusSession *session, 2589lookup_task (struct ConsensusSession *session,
2517 struct TaskKey *key) 2590 struct TaskKey *key)
2518{ 2591{
2519 struct GNUNET_HashCode hash; 2592 struct GNUNET_HashCode hash;
2520 2593
2521 2594
2522 GNUNET_CRYPTO_hash(key, sizeof(struct TaskKey), &hash); 2595 GNUNET_CRYPTO_hash (key, sizeof(struct TaskKey), &hash);
2523 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Looking up task hash %s\n", 2596 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up task hash %s\n",
2524 GNUNET_h2s(&hash)); 2597 GNUNET_h2s (&hash));
2525 return GNUNET_CONTAINER_multihashmap_get(session->taskmap, &hash); 2598 return GNUNET_CONTAINER_multihashmap_get (session->taskmap, &hash);
2526} 2599}
2527 2600
2528 2601
@@ -2542,10 +2615,10 @@ lookup_task(struct ConsensusSession *session,
2542 * Also necessary to specify the timeout. 2615 * Also necessary to specify the timeout.
2543 */ 2616 */
2544static void 2617static void
2545set_listen_cb(void *cls, 2618set_listen_cb (void *cls,
2546 const struct GNUNET_PeerIdentity *other_peer, 2619 const struct GNUNET_PeerIdentity *other_peer,
2547 const struct GNUNET_MessageHeader *context_msg, 2620 const struct GNUNET_MessageHeader *context_msg,
2548 struct GNUNET_SET_Request *request) 2621 struct GNUNET_SET_Request *request)
2549{ 2622{
2550 struct ConsensusSession *session = cls; 2623 struct ConsensusSession *session = cls;
2551 struct TaskKey tk; 2624 struct TaskKey tk;
@@ -2553,122 +2626,124 @@ set_listen_cb(void *cls,
2553 struct GNUNET_CONSENSUS_RoundContextMessage *cm; 2626 struct GNUNET_CONSENSUS_RoundContextMessage *cm;
2554 2627
2555 if (NULL == context_msg) 2628 if (NULL == context_msg)
2556 { 2629 {
2557 GNUNET_break_op(0); 2630 GNUNET_break_op (0);
2558 return; 2631 return;
2559 } 2632 }
2560 2633
2561 if (GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ROUND_CONTEXT != ntohs(context_msg->type)) 2634 if (GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ROUND_CONTEXT != ntohs (
2562 { 2635 context_msg->type))
2563 GNUNET_break_op(0); 2636 {
2564 return; 2637 GNUNET_break_op (0);
2565 } 2638 return;
2639 }
2566 2640
2567 if (sizeof(struct GNUNET_CONSENSUS_RoundContextMessage) != ntohs(context_msg->size)) 2641 if (sizeof(struct GNUNET_CONSENSUS_RoundContextMessage) != ntohs (
2568 { 2642 context_msg->size))
2569 GNUNET_break_op(0); 2643 {
2570 return; 2644 GNUNET_break_op (0);
2571 } 2645 return;
2646 }
2572 2647
2573 cm = (struct GNUNET_CONSENSUS_RoundContextMessage *)context_msg; 2648 cm = (struct GNUNET_CONSENSUS_RoundContextMessage *) context_msg;
2574 2649
2575 tk = ((struct TaskKey) { 2650 tk = ((struct TaskKey) {
2576 .kind = ntohs(cm->kind), 2651 .kind = ntohs (cm->kind),
2577 .peer1 = ntohs(cm->peer1), 2652 .peer1 = ntohs (cm->peer1),
2578 .peer2 = ntohs(cm->peer2), 2653 .peer2 = ntohs (cm->peer2),
2579 .repetition = ntohs(cm->repetition), 2654 .repetition = ntohs (cm->repetition),
2580 .leader = ntohs(cm->leader), 2655 .leader = ntohs (cm->leader),
2581 }); 2656 });
2582 2657
2583 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "P%u: got req for task %s\n", 2658 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: got req for task %s\n",
2584 session->local_peer_idx, debug_str_task_key(&tk)); 2659 session->local_peer_idx, debug_str_task_key (&tk));
2585 2660
2586 task = lookup_task(session, &tk); 2661 task = lookup_task (session, &tk);
2587 2662
2588 if (NULL == task) 2663 if (NULL == task)
2589 { 2664 {
2590 GNUNET_break_op(0); 2665 GNUNET_break_op (0);
2591 return; 2666 return;
2592 } 2667 }
2593 2668
2594 if (GNUNET_YES == task->is_finished) 2669 if (GNUNET_YES == task->is_finished)
2595 { 2670 {
2596 GNUNET_break_op(0); 2671 GNUNET_break_op (0);
2597 return; 2672 return;
2598 } 2673 }
2599 2674
2600 if (task->key.peer2 != session->local_peer_idx) 2675 if (task->key.peer2 != session->local_peer_idx)
2601 { 2676 {
2602 /* We're being asked, so we must be thne 2nd peer. */ 2677 /* We're being asked, so we must be thne 2nd peer. */
2603 GNUNET_break_op(0); 2678 GNUNET_break_op (0);
2604 return; 2679 return;
2605 } 2680 }
2606 2681
2607 GNUNET_assert(!((task->key.peer1 == session->local_peer_idx) && 2682 GNUNET_assert (! ((task->key.peer1 == session->local_peer_idx) &&
2608 (task->key.peer2 == session->local_peer_idx))); 2683 (task->key.peer2 == session->local_peer_idx)));
2609 2684
2610 struct GNUNET_SET_Option opts[] = { 2685 struct GNUNET_SET_Option opts[] = {
2611 { GNUNET_SET_OPTION_BYZANTINE, { .num = session->lower_bound } }, 2686 { GNUNET_SET_OPTION_BYZANTINE, { .num = session->lower_bound } },
2612 { GNUNET_SET_OPTION_END }, 2687 { GNUNET_SET_OPTION_END },
2613 }; 2688 };
2614 2689
2615 task->cls.setop.op = GNUNET_SET_accept(request, 2690 task->cls.setop.op = GNUNET_SET_accept (request,
2616 GNUNET_SET_RESULT_SYMMETRIC, 2691 GNUNET_SET_RESULT_SYMMETRIC,
2617 opts, 2692 opts,
2618 set_result_cb, 2693 set_result_cb,
2619 task); 2694 task);
2620 2695
2621 /* If the task hasn't been started yet, 2696 /* If the task hasn't been started yet,
2622 we wait for that until we commit. */ 2697 we wait for that until we commit. */
2623 2698
2624 if (GNUNET_YES == task->is_started) 2699 if (GNUNET_YES == task->is_started)
2625 { 2700 {
2626 commit_set(session, task); 2701 commit_set (session, task);
2627 } 2702 }
2628} 2703}
2629 2704
2630 2705
2631 2706
2632static void 2707static void
2633put_task(struct GNUNET_CONTAINER_MultiHashMap *taskmap, 2708put_task (struct GNUNET_CONTAINER_MultiHashMap *taskmap,
2634 struct TaskEntry *t) 2709 struct TaskEntry *t)
2635{ 2710{
2636 struct GNUNET_HashCode round_hash; 2711 struct GNUNET_HashCode round_hash;
2637 struct Step *s; 2712 struct Step *s;
2638 2713
2639 GNUNET_assert(NULL != t->step); 2714 GNUNET_assert (NULL != t->step);
2640 2715
2641 t = GNUNET_memdup(t, sizeof(struct TaskEntry)); 2716 t = GNUNET_memdup (t, sizeof(struct TaskEntry));
2642 2717
2643 s = t->step; 2718 s = t->step;
2644 2719
2645 if (s->tasks_len == s->tasks_cap) 2720 if (s->tasks_len == s->tasks_cap)
2646 { 2721 {
2647 unsigned int target_size = 3 * (s->tasks_cap + 1) / 2; 2722 unsigned int target_size = 3 * (s->tasks_cap + 1) / 2;
2648 GNUNET_array_grow(s->tasks, 2723 GNUNET_array_grow (s->tasks,
2649 s->tasks_cap, 2724 s->tasks_cap,
2650 target_size); 2725 target_size);
2651 } 2726 }
2652 2727
2653#ifdef GNUNET_EXTRA_LOGGING 2728#ifdef GNUNET_EXTRA_LOGGING
2654 GNUNET_assert(NULL != s->debug_name); 2729 GNUNET_assert (NULL != s->debug_name);
2655 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Putting task <%s> into step `%s'\n", 2730 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting task <%s> into step `%s'\n",
2656 debug_str_task_key(&t->key), 2731 debug_str_task_key (&t->key),
2657 s->debug_name); 2732 s->debug_name);
2658#endif 2733#endif
2659 2734
2660 s->tasks[s->tasks_len] = t; 2735 s->tasks[s->tasks_len] = t;
2661 s->tasks_len++; 2736 s->tasks_len++;
2662 2737
2663 GNUNET_CRYPTO_hash(&t->key, sizeof(struct TaskKey), &round_hash); 2738 GNUNET_CRYPTO_hash (&t->key, sizeof(struct TaskKey), &round_hash);
2664 GNUNET_assert(GNUNET_OK == 2739 GNUNET_assert (GNUNET_OK ==
2665 GNUNET_CONTAINER_multihashmap_put(taskmap, &round_hash, t, 2740 GNUNET_CONTAINER_multihashmap_put (taskmap, &round_hash, t,
2666 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 2741 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
2667} 2742}
2668 2743
2669 2744
2670static void 2745static void
2671install_step_timeouts(struct ConsensusSession *session) 2746install_step_timeouts (struct ConsensusSession *session)
2672{ 2747{
2673 /* Given the fully constructed task graph 2748 /* Given the fully constructed task graph
2674 with rounds for tasks, we can give the tasks timeouts. */ 2749 with rounds for tasks, we can give the tasks timeouts. */
@@ -2684,37 +2759,37 @@ install_step_timeouts(struct ConsensusSession *session)
2684 * Arrange two peers in some canonical order. 2759 * Arrange two peers in some canonical order.
2685 */ 2760 */
2686static void 2761static void
2687arrange_peers(uint16_t *p1, uint16_t *p2, uint16_t n) 2762arrange_peers (uint16_t *p1, uint16_t *p2, uint16_t n)
2688{ 2763{
2689 uint16_t a; 2764 uint16_t a;
2690 uint16_t b; 2765 uint16_t b;
2691 2766
2692 GNUNET_assert(*p1 < n); 2767 GNUNET_assert (*p1 < n);
2693 GNUNET_assert(*p2 < n); 2768 GNUNET_assert (*p2 < n);
2694 2769
2695 if (*p1 < *p2) 2770 if (*p1 < *p2)
2696 { 2771 {
2697 a = *p1; 2772 a = *p1;
2698 b = *p2; 2773 b = *p2;
2699 } 2774 }
2700 else 2775 else
2701 { 2776 {
2702 a = *p2; 2777 a = *p2;
2703 b = *p1; 2778 b = *p1;
2704 } 2779 }
2705 2780
2706 /* For uniformly random *p1, *p2, 2781 /* For uniformly random *p1, *p2,
2707 this condition is true with 50% chance */ 2782 this condition is true with 50% chance */
2708 if (((b - a) + n) % n <= n / 2) 2783 if (((b - a) + n) % n <= n / 2)
2709 { 2784 {
2710 *p1 = a; 2785 *p1 = a;
2711 *p2 = b; 2786 *p2 = b;
2712 } 2787 }
2713 else 2788 else
2714 { 2789 {
2715 *p1 = b; 2790 *p1 = b;
2716 *p2 = a; 2791 *p2 = a;
2717 } 2792 }
2718} 2793}
2719 2794
2720 2795
@@ -2722,36 +2797,36 @@ arrange_peers(uint16_t *p1, uint16_t *p2, uint16_t n)
2722 * Record @a dep as a dependency of @a step. 2797 * Record @a dep as a dependency of @a step.
2723 */ 2798 */
2724static void 2799static void
2725step_depend_on(struct Step *step, struct Step *dep) 2800step_depend_on (struct Step *step, struct Step *dep)
2726{ 2801{
2727 /* We're not checking for cyclic dependencies, 2802 /* We're not checking for cyclic dependencies,
2728 but this is a cheap sanity check. */ 2803 but this is a cheap sanity check. */
2729 GNUNET_assert(step != dep); 2804 GNUNET_assert (step != dep);
2730 GNUNET_assert(NULL != step); 2805 GNUNET_assert (NULL != step);
2731 GNUNET_assert(NULL != dep); 2806 GNUNET_assert (NULL != dep);
2732 GNUNET_assert(dep->round <= step->round); 2807 GNUNET_assert (dep->round <= step->round);
2733 2808
2734#ifdef GNUNET_EXTRA_LOGGING 2809#ifdef GNUNET_EXTRA_LOGGING
2735 /* Make sure we have complete debugging information. 2810 /* Make sure we have complete debugging information.
2736 Also checks that we don't screw up too badly 2811 Also checks that we don't screw up too badly
2737 constructing the task graph. */ 2812 constructing the task graph. */
2738 GNUNET_assert(NULL != step->debug_name); 2813 GNUNET_assert (NULL != step->debug_name);
2739 GNUNET_assert(NULL != dep->debug_name); 2814 GNUNET_assert (NULL != dep->debug_name);
2740 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2815 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2741 "Making step `%s' depend on `%s'\n", 2816 "Making step `%s' depend on `%s'\n",
2742 step->debug_name, 2817 step->debug_name,
2743 dep->debug_name); 2818 dep->debug_name);
2744#endif 2819#endif
2745 2820
2746 if (dep->subordinates_cap == dep->subordinates_len) 2821 if (dep->subordinates_cap == dep->subordinates_len)
2747 { 2822 {
2748 unsigned int target_size = 3 * (dep->subordinates_cap + 1) / 2; 2823 unsigned int target_size = 3 * (dep->subordinates_cap + 1) / 2;
2749 GNUNET_array_grow(dep->subordinates, 2824 GNUNET_array_grow (dep->subordinates,
2750 dep->subordinates_cap, 2825 dep->subordinates_cap,
2751 target_size); 2826 target_size);
2752 } 2827 }
2753 2828
2754 GNUNET_assert(dep->subordinates_len <= dep->subordinates_cap); 2829 GNUNET_assert (dep->subordinates_len <= dep->subordinates_cap);
2755 2830
2756 dep->subordinates[dep->subordinates_len] = step; 2831 dep->subordinates[dep->subordinates_len] = step;
2757 dep->subordinates_len++; 2832 dep->subordinates_len++;
@@ -2761,17 +2836,17 @@ step_depend_on(struct Step *step, struct Step *dep)
2761 2836
2762 2837
2763static struct Step * 2838static struct Step *
2764create_step(struct ConsensusSession *session, int round, int early_finishable) 2839create_step (struct ConsensusSession *session, int round, int early_finishable)
2765{ 2840{
2766 struct Step *step; 2841 struct Step *step;
2767 2842
2768 step = GNUNET_new(struct Step); 2843 step = GNUNET_new (struct Step);
2769 step->session = session; 2844 step->session = session;
2770 step->round = round; 2845 step->round = round;
2771 step->early_finishable = early_finishable; 2846 step->early_finishable = early_finishable;
2772 GNUNET_CONTAINER_DLL_insert_tail(session->steps_head, 2847 GNUNET_CONTAINER_DLL_insert_tail (session->steps_head,
2773 session->steps_tail, 2848 session->steps_tail,
2774 step); 2849 step);
2775 return step; 2850 return step;
2776} 2851}
2777 2852
@@ -2781,11 +2856,11 @@ create_step(struct ConsensusSession *session, int round, int early_finishable)
2781 * gradecast. 2856 * gradecast.
2782 */ 2857 */
2783static void 2858static void
2784construct_task_graph_gradecast(struct ConsensusSession *session, 2859construct_task_graph_gradecast (struct ConsensusSession *session,
2785 uint16_t rep, 2860 uint16_t rep,
2786 uint16_t lead, 2861 uint16_t lead,
2787 struct Step *step_before, 2862 struct Step *step_before,
2788 struct Step *step_after) 2863 struct Step *step_after)
2789{ 2864{
2790 uint16_t n = session->num_peers; 2865 uint16_t n = session->num_peers;
2791 uint16_t me = session->local_peer_idx; 2866 uint16_t me = session->local_peer_idx;
@@ -2807,155 +2882,168 @@ construct_task_graph_gradecast(struct ConsensusSession *session,
2807 2882
2808 /* gcast step 1: leader disseminates */ 2883 /* gcast step 1: leader disseminates */
2809 2884
2810 step = create_step(session, round, GNUNET_YES); 2885 step = create_step (session, round, GNUNET_YES);
2811 2886
2812#ifdef GNUNET_EXTRA_LOGGING 2887#ifdef GNUNET_EXTRA_LOGGING
2813 GNUNET_asprintf(&step->debug_name, "disseminate leader %u rep %u", lead, rep); 2888 GNUNET_asprintf (&step->debug_name, "disseminate leader %u rep %u", lead,
2889 rep);
2814#endif 2890#endif
2815 step_depend_on(step, step_before); 2891 step_depend_on (step, step_before);
2816 2892
2817 if (lead == me) 2893 if (lead == me)
2894 {
2895 for (k = 0; k < n; k++)
2818 { 2896 {
2819 for (k = 0; k < n; k++) 2897 if (k == me)
2820 { 2898 continue;
2821 if (k == me) 2899 p1 = me;
2822 continue; 2900 p2 = k;
2823 p1 = me; 2901 arrange_peers (&p1, &p2, n);
2824 p2 = k; 2902 task = ((struct TaskEntry) {
2825 arrange_peers(&p1, &p2, n);
2826 task = ((struct TaskEntry) {
2827 .step = step, 2903 .step = step,
2828 .start = task_start_reconcile, 2904 .start = task_start_reconcile,
2829 .cancel = task_cancel_reconcile, 2905 .cancel = task_cancel_reconcile,
2830 .key = (struct TaskKey) { PHASE_KIND_GRADECAST_LEADER, p1, p2, rep, me }, 2906 .key = (struct TaskKey) { PHASE_KIND_GRADECAST_LEADER, p1, p2, rep,
2907 me },
2831 }); 2908 });
2832 task.cls.setop.input_set = (struct SetKey) { SET_KIND_CURRENT, rep }; 2909 task.cls.setop.input_set = (struct SetKey) { SET_KIND_CURRENT, rep };
2833 put_task(session->taskmap, &task); 2910 put_task (session->taskmap, &task);
2834 } 2911 }
2835 /* We run this task to make sure that the leader 2912 /* We run this task to make sure that the leader
2836 has the stored the SET_KIND_LEADER set of himself, 2913 has the stored the SET_KIND_LEADER set of himself,
2837 so it can participate in the rest of the gradecast 2914 so it can participate in the rest of the gradecast
2838 without the code having to handle any special cases. */ 2915 without the code having to handle any special cases. */
2839 task = ((struct TaskEntry) { 2916 task = ((struct TaskEntry) {
2840 .step = step, 2917 .step = step,
2841 .key = (struct TaskKey) { PHASE_KIND_GRADECAST_LEADER, me, me, rep, me }, 2918 .key = (struct TaskKey) { PHASE_KIND_GRADECAST_LEADER, me, me, rep, me },
2842 .start = task_start_reconcile, 2919 .start = task_start_reconcile,
2843 .cancel = task_cancel_reconcile, 2920 .cancel = task_cancel_reconcile,
2844 }); 2921 });
2845 task.cls.setop.input_set = (struct SetKey) { SET_KIND_CURRENT, rep }; 2922 task.cls.setop.input_set = (struct SetKey) { SET_KIND_CURRENT, rep };
2846 task.cls.setop.output_set = (struct SetKey) { SET_KIND_LEADER_PROPOSAL, rep, me }; 2923 task.cls.setop.output_set = (struct SetKey) { SET_KIND_LEADER_PROPOSAL, rep,
2847 task.cls.setop.output_diff = (struct DiffKey) { DIFF_KIND_LEADER_PROPOSAL, rep, me }; 2924 me };
2848 put_task(session->taskmap, &task); 2925 task.cls.setop.output_diff = (struct DiffKey) { DIFF_KIND_LEADER_PROPOSAL,
2849 } 2926 rep, me };
2927 put_task (session->taskmap, &task);
2928 }
2850 else 2929 else
2851 { 2930 {
2852 p1 = me; 2931 p1 = me;
2853 p2 = lead; 2932 p2 = lead;
2854 arrange_peers(&p1, &p2, n); 2933 arrange_peers (&p1, &p2, n);
2855 task = ((struct TaskEntry) { 2934 task = ((struct TaskEntry) {
2856 .step = step, 2935 .step = step,
2857 .key = (struct TaskKey) { PHASE_KIND_GRADECAST_LEADER, p1, p2, rep, lead }, 2936 .key = (struct TaskKey) { PHASE_KIND_GRADECAST_LEADER, p1, p2, rep,
2937 lead },
2858 .start = task_start_reconcile, 2938 .start = task_start_reconcile,
2859 .cancel = task_cancel_reconcile, 2939 .cancel = task_cancel_reconcile,
2860 }); 2940 });
2861 task.cls.setop.input_set = (struct SetKey) { SET_KIND_CURRENT, rep }; 2941 task.cls.setop.input_set = (struct SetKey) { SET_KIND_CURRENT, rep };
2862 task.cls.setop.output_set = (struct SetKey) { SET_KIND_LEADER_PROPOSAL, rep, lead }; 2942 task.cls.setop.output_set = (struct SetKey) { SET_KIND_LEADER_PROPOSAL, rep,
2863 task.cls.setop.output_diff = (struct DiffKey) { DIFF_KIND_LEADER_PROPOSAL, rep, lead }; 2943 lead };
2864 put_task(session->taskmap, &task); 2944 task.cls.setop.output_diff = (struct DiffKey) { DIFF_KIND_LEADER_PROPOSAL,
2865 } 2945 rep, lead };
2946 put_task (session->taskmap, &task);
2947 }
2866 2948
2867 /* gcast phase 2: echo */ 2949 /* gcast phase 2: echo */
2868 prev_step = step; 2950 prev_step = step;
2869 round += 1; 2951 round += 1;
2870 step = create_step(session, round, GNUNET_YES); 2952 step = create_step (session, round, GNUNET_YES);
2871#ifdef GNUNET_EXTRA_LOGGING 2953#ifdef GNUNET_EXTRA_LOGGING
2872 GNUNET_asprintf(&step->debug_name, "echo leader %u rep %u", lead, rep); 2954 GNUNET_asprintf (&step->debug_name, "echo leader %u rep %u", lead, rep);
2873#endif 2955#endif
2874 step_depend_on(step, prev_step); 2956 step_depend_on (step, prev_step);
2875 2957
2876 for (k = 0; k < n; k++) 2958 for (k = 0; k < n; k++)
2877 { 2959 {
2878 p1 = k; 2960 p1 = k;
2879 p2 = me; 2961 p2 = me;
2880 arrange_peers(&p1, &p2, n); 2962 arrange_peers (&p1, &p2, n);
2881 task = ((struct TaskEntry) { 2963 task = ((struct TaskEntry) {
2882 .step = step, 2964 .step = step,
2883 .key = (struct TaskKey) { PHASE_KIND_GRADECAST_ECHO, p1, p2, rep, lead }, 2965 .key = (struct TaskKey) { PHASE_KIND_GRADECAST_ECHO, p1, p2, rep, lead },
2884 .start = task_start_reconcile, 2966 .start = task_start_reconcile,
2885 .cancel = task_cancel_reconcile, 2967 .cancel = task_cancel_reconcile,
2886 }); 2968 });
2887 task.cls.setop.input_set = (struct SetKey) { SET_KIND_LEADER_PROPOSAL, rep, lead }; 2969 task.cls.setop.input_set = (struct SetKey) { SET_KIND_LEADER_PROPOSAL, rep,
2888 task.cls.setop.output_rfn = (struct RfnKey) { RFN_KIND_ECHO, rep, lead }; 2970 lead };
2889 put_task(session->taskmap, &task); 2971 task.cls.setop.output_rfn = (struct RfnKey) { RFN_KIND_ECHO, rep, lead };
2890 } 2972 put_task (session->taskmap, &task);
2973 }
2891 2974
2892 prev_step = step; 2975 prev_step = step;
2893 /* Same round, since step only has local tasks */ 2976 /* Same round, since step only has local tasks */
2894 step = create_step(session, round, GNUNET_YES); 2977 step = create_step (session, round, GNUNET_YES);
2895#ifdef GNUNET_EXTRA_LOGGING 2978#ifdef GNUNET_EXTRA_LOGGING
2896 GNUNET_asprintf(&step->debug_name, "echo grade leader %u rep %u", lead, rep); 2979 GNUNET_asprintf (&step->debug_name, "echo grade leader %u rep %u", lead, rep);
2897#endif 2980#endif
2898 step_depend_on(step, prev_step); 2981 step_depend_on (step, prev_step);
2899 2982
2900 arrange_peers(&p1, &p2, n); 2983 arrange_peers (&p1, &p2, n);
2901 task = ((struct TaskEntry) { 2984 task = ((struct TaskEntry) {
2902 .key = (struct TaskKey) { PHASE_KIND_GRADECAST_ECHO_GRADE, -1, -1, rep, lead }, 2985 .key = (struct TaskKey) { PHASE_KIND_GRADECAST_ECHO_GRADE, -1, -1, rep,
2986 lead },
2903 .step = step, 2987 .step = step,
2904 .start = task_start_eval_echo 2988 .start = task_start_eval_echo
2905 }); 2989 });
2906 put_task(session->taskmap, &task); 2990 put_task (session->taskmap, &task);
2907 2991
2908 prev_step = step; 2992 prev_step = step;
2909 round += 1; 2993 round += 1;
2910 step = create_step(session, round, GNUNET_YES); 2994 step = create_step (session, round, GNUNET_YES);
2911#ifdef GNUNET_EXTRA_LOGGING 2995#ifdef GNUNET_EXTRA_LOGGING
2912 GNUNET_asprintf(&step->debug_name, "confirm leader %u rep %u", lead, rep); 2996 GNUNET_asprintf (&step->debug_name, "confirm leader %u rep %u", lead, rep);
2913#endif 2997#endif
2914 step_depend_on(step, prev_step); 2998 step_depend_on (step, prev_step);
2915 2999
2916 /* gcast phase 3: confirmation and grading */ 3000 /* gcast phase 3: confirmation and grading */
2917 for (k = 0; k < n; k++) 3001 for (k = 0; k < n; k++)
2918 { 3002 {
2919 p1 = k; 3003 p1 = k;
2920 p2 = me; 3004 p2 = me;
2921 arrange_peers(&p1, &p2, n); 3005 arrange_peers (&p1, &p2, n);
2922 task = ((struct TaskEntry) { 3006 task = ((struct TaskEntry) {
2923 .step = step, 3007 .step = step,
2924 .start = task_start_reconcile, 3008 .start = task_start_reconcile,
2925 .cancel = task_cancel_reconcile, 3009 .cancel = task_cancel_reconcile,
2926 .key = (struct TaskKey) { PHASE_KIND_GRADECAST_CONFIRM, p1, p2, rep, lead }, 3010 .key = (struct TaskKey) { PHASE_KIND_GRADECAST_CONFIRM, p1, p2, rep,
3011 lead },
2927 }); 3012 });
2928 task.cls.setop.input_set = (struct SetKey) { SET_KIND_ECHO_RESULT, rep, lead }; 3013 task.cls.setop.input_set = (struct SetKey) { SET_KIND_ECHO_RESULT, rep,
2929 task.cls.setop.output_rfn = (struct RfnKey) { RFN_KIND_CONFIRM, rep, lead }; 3014 lead };
2930 /* If there was at least one element in the echo round that was 3015 task.cls.setop.output_rfn = (struct RfnKey) { RFN_KIND_CONFIRM, rep, lead };
2931 contested (i.e. it had no n-t majority), then we let the other peers 3016 /* If there was at least one element in the echo round that was
2932 know, and other peers let us know. The contested flag for each peer is 3017 contested (i.e. it had no n-t majority), then we let the other peers
2933 stored in the rfn. */ 3018 know, and other peers let us know. The contested flag for each peer is
2934 task.cls.setop.transceive_contested = GNUNET_YES; 3019 stored in the rfn. */
2935 put_task(session->taskmap, &task); 3020 task.cls.setop.transceive_contested = GNUNET_YES;
2936 } 3021 put_task (session->taskmap, &task);
3022 }
2937 3023
2938 prev_step = step; 3024 prev_step = step;
2939 /* Same round, since step only has local tasks */ 3025 /* Same round, since step only has local tasks */
2940 step = create_step(session, round, GNUNET_YES); 3026 step = create_step (session, round, GNUNET_YES);
2941#ifdef GNUNET_EXTRA_LOGGING 3027#ifdef GNUNET_EXTRA_LOGGING
2942 GNUNET_asprintf(&step->debug_name, "confirm grade leader %u rep %u", lead, rep); 3028 GNUNET_asprintf (&step->debug_name, "confirm grade leader %u rep %u", lead,
3029 rep);
2943#endif 3030#endif
2944 step_depend_on(step, prev_step); 3031 step_depend_on (step, prev_step);
2945 3032
2946 task = ((struct TaskEntry) { 3033 task = ((struct TaskEntry) {
2947 .step = step, 3034 .step = step,
2948 .key = (struct TaskKey) { PHASE_KIND_GRADECAST_CONFIRM_GRADE, -1, -1, rep, lead }, 3035 .key = (struct TaskKey) { PHASE_KIND_GRADECAST_CONFIRM_GRADE, -1, -1, rep,
3036 lead },
2949 .start = task_start_grade, 3037 .start = task_start_grade,
2950 }); 3038 });
2951 put_task(session->taskmap, &task); 3039 put_task (session->taskmap, &task);
2952 3040
2953 step_depend_on(step_after, step); 3041 step_depend_on (step_after, step);
2954} 3042}
2955 3043
2956 3044
2957static void 3045static void
2958construct_task_graph(struct ConsensusSession *session) 3046construct_task_graph (struct ConsensusSession *session)
2959{ 3047{
2960 uint16_t n = session->num_peers; 3048 uint16_t n = session->num_peers;
2961 uint16_t t = n / 3; 3049 uint16_t t = n / 3;
@@ -2985,60 +3073,60 @@ construct_task_graph(struct ConsensusSession *session)
2985 3073
2986 /* all-to-all step */ 3074 /* all-to-all step */
2987 3075
2988 step = create_step(session, round, GNUNET_NO); 3076 step = create_step (session, round, GNUNET_NO);
2989 3077
2990#ifdef GNUNET_EXTRA_LOGGING 3078#ifdef GNUNET_EXTRA_LOGGING
2991 step->debug_name = GNUNET_strdup("all to all"); 3079 step->debug_name = GNUNET_strdup ("all to all");
2992#endif 3080#endif
2993 3081
2994 for (i = 0; i < n; i++) 3082 for (i = 0; i < n; i++)
2995 { 3083 {
2996 uint16_t p1; 3084 uint16_t p1;
2997 uint16_t p2; 3085 uint16_t p2;
2998 3086
2999 p1 = me; 3087 p1 = me;
3000 p2 = i; 3088 p2 = i;
3001 arrange_peers(&p1, &p2, n); 3089 arrange_peers (&p1, &p2, n);
3002 task = ((struct TaskEntry) { 3090 task = ((struct TaskEntry) {
3003 .key = (struct TaskKey) { PHASE_KIND_ALL_TO_ALL, p1, p2, -1, -1 }, 3091 .key = (struct TaskKey) { PHASE_KIND_ALL_TO_ALL, p1, p2, -1, -1 },
3004 .step = step, 3092 .step = step,
3005 .start = task_start_reconcile, 3093 .start = task_start_reconcile,
3006 .cancel = task_cancel_reconcile, 3094 .cancel = task_cancel_reconcile,
3007 }); 3095 });
3008 task.cls.setop.input_set = (struct SetKey) { SET_KIND_CURRENT, 0 }; 3096 task.cls.setop.input_set = (struct SetKey) { SET_KIND_CURRENT, 0 };
3009 task.cls.setop.output_set = task.cls.setop.input_set; 3097 task.cls.setop.output_set = task.cls.setop.input_set;
3010 task.cls.setop.do_not_remove = GNUNET_YES; 3098 task.cls.setop.do_not_remove = GNUNET_YES;
3011 put_task(session->taskmap, &task); 3099 put_task (session->taskmap, &task);
3012 } 3100 }
3013 3101
3014 round += 1; 3102 round += 1;
3015 prev_step = step; 3103 prev_step = step;
3016 step = create_step(session, round, GNUNET_NO);; 3104 step = create_step (session, round, GNUNET_NO);;
3017#ifdef GNUNET_EXTRA_LOGGING 3105#ifdef GNUNET_EXTRA_LOGGING
3018 step->debug_name = GNUNET_strdup("all to all 2"); 3106 step->debug_name = GNUNET_strdup ("all to all 2");
3019#endif 3107#endif
3020 step_depend_on(step, prev_step); 3108 step_depend_on (step, prev_step);
3021 3109
3022 3110
3023 for (i = 0; i < n; i++) 3111 for (i = 0; i < n; i++)
3024 { 3112 {
3025 uint16_t p1; 3113 uint16_t p1;
3026 uint16_t p2; 3114 uint16_t p2;
3027 3115
3028 p1 = me; 3116 p1 = me;
3029 p2 = i; 3117 p2 = i;
3030 arrange_peers(&p1, &p2, n); 3118 arrange_peers (&p1, &p2, n);
3031 task = ((struct TaskEntry) { 3119 task = ((struct TaskEntry) {
3032 .key = (struct TaskKey) { PHASE_KIND_ALL_TO_ALL_2, p1, p2, -1, -1 }, 3120 .key = (struct TaskKey) { PHASE_KIND_ALL_TO_ALL_2, p1, p2, -1, -1 },
3033 .step = step, 3121 .step = step,
3034 .start = task_start_reconcile, 3122 .start = task_start_reconcile,
3035 .cancel = task_cancel_reconcile, 3123 .cancel = task_cancel_reconcile,
3036 }); 3124 });
3037 task.cls.setop.input_set = (struct SetKey) { SET_KIND_CURRENT, 0 }; 3125 task.cls.setop.input_set = (struct SetKey) { SET_KIND_CURRENT, 0 };
3038 task.cls.setop.output_set = task.cls.setop.input_set; 3126 task.cls.setop.output_set = task.cls.setop.input_set;
3039 task.cls.setop.do_not_remove = GNUNET_YES; 3127 task.cls.setop.do_not_remove = GNUNET_YES;
3040 put_task(session->taskmap, &task); 3128 put_task (session->taskmap, &task);
3041 } 3129 }
3042 3130
3043 round += 1; 3131 round += 1;
3044 3132
@@ -3051,47 +3139,48 @@ construct_task_graph(struct ConsensusSession *session)
3051 3139
3052 /* sequential repetitions of the gradecasts */ 3140 /* sequential repetitions of the gradecasts */
3053 for (i = 0; i < t + 1; i++) 3141 for (i = 0; i < t + 1; i++)
3054 { 3142 {
3055 struct Step *step_rep_start; 3143 struct Step *step_rep_start;
3056 struct Step *step_rep_end; 3144 struct Step *step_rep_end;
3057 3145
3058 /* Every repetition is in a separate round. */ 3146 /* Every repetition is in a separate round. */
3059 step_rep_start = create_step(session, round, GNUNET_YES); 3147 step_rep_start = create_step (session, round, GNUNET_YES);
3060#ifdef GNUNET_EXTRA_LOGGING 3148#ifdef GNUNET_EXTRA_LOGGING
3061 GNUNET_asprintf(&step_rep_start->debug_name, "gradecast start rep %u", i); 3149 GNUNET_asprintf (&step_rep_start->debug_name, "gradecast start rep %u", i);
3062#endif 3150#endif
3063 3151
3064 step_depend_on(step_rep_start, prev_step); 3152 step_depend_on (step_rep_start, prev_step);
3065 3153
3066 /* gradecast has three rounds */ 3154 /* gradecast has three rounds */
3067 round += 3; 3155 round += 3;
3068 step_rep_end = create_step(session, round, GNUNET_YES); 3156 step_rep_end = create_step (session, round, GNUNET_YES);
3069#ifdef GNUNET_EXTRA_LOGGING 3157#ifdef GNUNET_EXTRA_LOGGING
3070 GNUNET_asprintf(&step_rep_end->debug_name, "gradecast end rep %u", i); 3158 GNUNET_asprintf (&step_rep_end->debug_name, "gradecast end rep %u", i);
3071#endif 3159#endif
3072 3160
3073 /* parallel gradecasts */ 3161 /* parallel gradecasts */
3074 for (lead = 0; lead < n; lead++) 3162 for (lead = 0; lead < n; lead++)
3075 construct_task_graph_gradecast(session, i, lead, step_rep_start, step_rep_end); 3163 construct_task_graph_gradecast (session, i, lead, step_rep_start,
3164 step_rep_end);
3076 3165
3077 task = ((struct TaskEntry) { 3166 task = ((struct TaskEntry) {
3078 .step = step_rep_end, 3167 .step = step_rep_end,
3079 .key = (struct TaskKey) { PHASE_KIND_APPLY_REP, -1, -1, i, -1 }, 3168 .key = (struct TaskKey) { PHASE_KIND_APPLY_REP, -1, -1, i, -1 },
3080 .start = task_start_apply_round, 3169 .start = task_start_apply_round,
3081 }); 3170 });
3082 put_task(session->taskmap, &task); 3171 put_task (session->taskmap, &task);
3083 3172
3084 prev_step = step_rep_end; 3173 prev_step = step_rep_end;
3085 } 3174 }
3086 3175
3087 /* There is no next gradecast round, thus the final 3176 /* There is no next gradecast round, thus the final
3088 start step is the overall end step of the gradecasts */ 3177 start step is the overall end step of the gradecasts */
3089 round += 1; 3178 round += 1;
3090 step = create_step(session, round, GNUNET_NO); 3179 step = create_step (session, round, GNUNET_NO);
3091#ifdef GNUNET_EXTRA_LOGGING 3180#ifdef GNUNET_EXTRA_LOGGING
3092 GNUNET_asprintf(&step->debug_name, "finish"); 3181 GNUNET_asprintf (&step->debug_name, "finish");
3093#endif 3182#endif
3094 step_depend_on(step, prev_step); 3183 step_depend_on (step, prev_step);
3095 3184
3096 task = ((struct TaskEntry) { 3185 task = ((struct TaskEntry) {
3097 .step = step, 3186 .step = step,
@@ -3100,7 +3189,7 @@ construct_task_graph(struct ConsensusSession *session)
3100 }); 3189 });
3101 task.cls.finish.input_set = (struct SetKey) { SET_KIND_LAST_GRADECAST }; 3190 task.cls.finish.input_set = (struct SetKey) { SET_KIND_LAST_GRADECAST };
3102 3191
3103 put_task(session->taskmap, &task); 3192 put_task (session->taskmap, &task);
3104} 3193}
3105 3194
3106 3195
@@ -3113,17 +3202,17 @@ construct_task_graph(struct ConsensusSession *session)
3113 * @return #GNUNET_OK if @a m is well-formed 3202 * @return #GNUNET_OK if @a m is well-formed
3114 */ 3203 */
3115static int 3204static int
3116check_client_join(void *cls, 3205check_client_join (void *cls,
3117 const struct GNUNET_CONSENSUS_JoinMessage *m) 3206 const struct GNUNET_CONSENSUS_JoinMessage *m)
3118{ 3207{
3119 uint32_t listed_peers = ntohl(m->num_peers); 3208 uint32_t listed_peers = ntohl (m->num_peers);
3120 3209
3121 if ((ntohs(m->header.size) - sizeof(*m)) != 3210 if ((ntohs (m->header.size) - sizeof(*m)) !=
3122 listed_peers * sizeof(struct GNUNET_PeerIdentity)) 3211 listed_peers * sizeof(struct GNUNET_PeerIdentity))
3123 { 3212 {
3124 GNUNET_break(0); 3213 GNUNET_break (0);
3125 return GNUNET_SYSERR; 3214 return GNUNET_SYSERR;
3126 } 3215 }
3127 return GNUNET_OK; 3216 return GNUNET_OK;
3128} 3217}
3129 3218
@@ -3135,16 +3224,16 @@ check_client_join(void *cls,
3135 * @param m message sent by the client 3224 * @param m message sent by the client
3136 */ 3225 */
3137static void 3226static void
3138handle_client_join(void *cls, 3227handle_client_join (void *cls,
3139 const struct GNUNET_CONSENSUS_JoinMessage *m) 3228 const struct GNUNET_CONSENSUS_JoinMessage *m)
3140{ 3229{
3141 struct ConsensusSession *session = cls; 3230 struct ConsensusSession *session = cls;
3142 struct ConsensusSession *other_session; 3231 struct ConsensusSession *other_session;
3143 3232
3144 initialize_session_peer_list(session, 3233 initialize_session_peer_list (session,
3145 m); 3234 m);
3146 compute_global_id(session, 3235 compute_global_id (session,
3147 &m->session_id); 3236 &m->session_id);
3148 3237
3149 /* Check if some local client already owns the session. 3238 /* Check if some local client already owns the session.
3150 It is only legal to have a session with an existing global id 3239 It is only legal to have a session with an existing global id
@@ -3152,75 +3241,75 @@ handle_client_join(void *cls,
3152 for (other_session = sessions_head; 3241 for (other_session = sessions_head;
3153 NULL != other_session; 3242 NULL != other_session;
3154 other_session = other_session->next) 3243 other_session = other_session->next)
3155 { 3244 {
3156 if ((other_session != session) && 3245 if ((other_session != session) &&
3157 (0 == GNUNET_CRYPTO_hash_cmp(&session->global_id, 3246 (0 == GNUNET_CRYPTO_hash_cmp (&session->global_id,
3158 &other_session->global_id))) 3247 &other_session->global_id)))
3159 break; 3248 break;
3160 } 3249 }
3161 3250
3162 session->conclude_deadline 3251 session->conclude_deadline
3163 = GNUNET_TIME_absolute_ntoh(m->deadline); 3252 = GNUNET_TIME_absolute_ntoh (m->deadline);
3164 session->conclude_start 3253 session->conclude_start
3165 = GNUNET_TIME_absolute_ntoh(m->start); 3254 = GNUNET_TIME_absolute_ntoh (m->start);
3166 session->local_peer_idx = get_peer_idx(&my_peer, 3255 session->local_peer_idx = get_peer_idx (&my_peer,
3167 session); 3256 session);
3168 GNUNET_assert(-1 != session->local_peer_idx); 3257 GNUNET_assert (-1 != session->local_peer_idx);
3169 3258
3170 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3171 "Joining consensus session %s containing %u peers as %u with timeout %s\n", 3260 "Joining consensus session %s containing %u peers as %u with timeout %s\n",
3172 GNUNET_h2s(&m->session_id), 3261 GNUNET_h2s (&m->session_id),
3173 session->num_peers, 3262 session->num_peers,
3174 session->local_peer_idx, 3263 session->local_peer_idx,
3175 GNUNET_STRINGS_relative_time_to_string 3264 GNUNET_STRINGS_relative_time_to_string
3176 (GNUNET_TIME_absolute_get_difference(session->conclude_start, 3265 (GNUNET_TIME_absolute_get_difference (session->conclude_start,
3177 session->conclude_deadline), 3266 session->conclude_deadline),
3178 GNUNET_YES)); 3267 GNUNET_YES));
3179 3268
3180 session->set_listener 3269 session->set_listener
3181 = GNUNET_SET_listen(cfg, 3270 = GNUNET_SET_listen (cfg,
3182 GNUNET_SET_OPERATION_UNION, 3271 GNUNET_SET_OPERATION_UNION,
3183 &session->global_id, 3272 &session->global_id,
3184 &set_listen_cb, 3273 &set_listen_cb,
3185 session); 3274 session);
3186 3275
3187 session->setmap = GNUNET_CONTAINER_multihashmap_create(1, 3276 session->setmap = GNUNET_CONTAINER_multihashmap_create (1,
3188 GNUNET_NO);
3189 session->taskmap = GNUNET_CONTAINER_multihashmap_create(1,
3190 GNUNET_NO); 3277 GNUNET_NO);
3191 session->diffmap = GNUNET_CONTAINER_multihashmap_create(1, 3278 session->taskmap = GNUNET_CONTAINER_multihashmap_create (1,
3279 GNUNET_NO);
3280 session->diffmap = GNUNET_CONTAINER_multihashmap_create (1,
3281 GNUNET_NO);
3282 session->rfnmap = GNUNET_CONTAINER_multihashmap_create (1,
3192 GNUNET_NO); 3283 GNUNET_NO);
3193 session->rfnmap = GNUNET_CONTAINER_multihashmap_create(1,
3194 GNUNET_NO);
3195 3284
3196 { 3285 {
3197 struct SetEntry *client_set; 3286 struct SetEntry *client_set;
3198 3287
3199 client_set = GNUNET_new(struct SetEntry); 3288 client_set = GNUNET_new (struct SetEntry);
3200 client_set->h = GNUNET_SET_create(cfg, 3289 client_set->h = GNUNET_SET_create (cfg,
3201 GNUNET_SET_OPERATION_UNION); 3290 GNUNET_SET_OPERATION_UNION);
3202 struct SetHandle *sh = GNUNET_new(struct SetHandle); 3291 struct SetHandle *sh = GNUNET_new (struct SetHandle);
3203 sh->h = client_set->h; 3292 sh->h = client_set->h;
3204 GNUNET_CONTAINER_DLL_insert(session->set_handles_head, 3293 GNUNET_CONTAINER_DLL_insert (session->set_handles_head,
3205 session->set_handles_tail, 3294 session->set_handles_tail,
3206 sh); 3295 sh);
3207 client_set->key = ((struct SetKey) { SET_KIND_CURRENT, 0, 0 }); 3296 client_set->key = ((struct SetKey) { SET_KIND_CURRENT, 0, 0 });
3208 put_set(session, 3297 put_set (session,
3209 client_set); 3298 client_set);
3210 } 3299 }
3211 3300
3212 session->peers_blacklisted = GNUNET_new_array(session->num_peers, 3301 session->peers_blacklisted = GNUNET_new_array (session->num_peers,
3213 int); 3302 int);
3214 3303
3215 /* Just construct the task graph, 3304 /* Just construct the task graph,
3216 but don't run anything until the client calls conclude. */ 3305 but don't run anything until the client calls conclude. */
3217 construct_task_graph(session); 3306 construct_task_graph (session);
3218 GNUNET_SERVICE_client_continue(session->client); 3307 GNUNET_SERVICE_client_continue (session->client);
3219} 3308}
3220 3309
3221 3310
3222static void 3311static void
3223client_insert_done(void *cls) 3312client_insert_done (void *cls)
3224{ 3313{
3225 // FIXME: implement 3314 // FIXME: implement
3226} 3315}
@@ -3234,8 +3323,8 @@ client_insert_done(void *cls)
3234 * @return #GNUNET_OK (always well-formed) 3323 * @return #GNUNET_OK (always well-formed)
3235 */ 3324 */
3236static int 3325static int
3237check_client_insert(void *cls, 3326check_client_insert (void *cls,
3238 const struct GNUNET_CONSENSUS_ElementMessage *msg) 3327 const struct GNUNET_CONSENSUS_ElementMessage *msg)
3239{ 3328{
3240 return GNUNET_OK; 3329 return GNUNET_OK;
3241} 3330}
@@ -3248,8 +3337,8 @@ check_client_insert(void *cls,
3248 * @param msg message sent by the client 3337 * @param msg message sent by the client
3249 */ 3338 */
3250static void 3339static void
3251handle_client_insert(void *cls, 3340handle_client_insert (void *cls,
3252 const struct GNUNET_CONSENSUS_ElementMessage *msg) 3341 const struct GNUNET_CONSENSUS_ElementMessage *msg)
3253{ 3342{
3254 struct ConsensusSession *session = cls; 3343 struct ConsensusSession *session = cls;
3255 ssize_t element_size; 3344 ssize_t element_size;
@@ -3257,15 +3346,16 @@ handle_client_insert(void *cls,
3257 struct ConsensusElement *ce; 3346 struct ConsensusElement *ce;
3258 3347
3259 if (GNUNET_YES == session->conclude_started) 3348 if (GNUNET_YES == session->conclude_started)
3260 { 3349 {
3261 GNUNET_break(0); 3350 GNUNET_break (0);
3262 GNUNET_SERVICE_client_drop(session->client); 3351 GNUNET_SERVICE_client_drop (session->client);
3263 return; 3352 return;
3264 } 3353 }
3265 3354
3266 element_size = ntohs(msg->header.size) - sizeof(struct GNUNET_CONSENSUS_ElementMessage); 3355 element_size = ntohs (msg->header.size) - sizeof(struct
3267 ce = GNUNET_malloc(sizeof(struct ConsensusElement) + element_size); 3356 GNUNET_CONSENSUS_ElementMessage);
3268 GNUNET_memcpy(&ce[1], &msg[1], element_size); 3357 ce = GNUNET_malloc (sizeof(struct ConsensusElement) + element_size);
3358 GNUNET_memcpy (&ce[1], &msg[1], element_size);
3269 ce->payload_type = msg->element_type; 3359 ce->payload_type = msg->element_type;
3270 3360
3271 struct GNUNET_SET_Element element = { 3361 struct GNUNET_SET_Element element = {
@@ -3278,28 +3368,28 @@ handle_client_insert(void *cls,
3278 struct SetKey key = { SET_KIND_CURRENT, 0, 0 }; 3368 struct SetKey key = { SET_KIND_CURRENT, 0, 0 };
3279 struct SetEntry *entry; 3369 struct SetEntry *entry;
3280 3370
3281 entry = lookup_set(session, 3371 entry = lookup_set (session,
3282 &key); 3372 &key);
3283 GNUNET_assert(NULL != entry); 3373 GNUNET_assert (NULL != entry);
3284 initial_set = entry->h; 3374 initial_set = entry->h;
3285 } 3375 }
3286 3376
3287 session->num_client_insert_pending++; 3377 session->num_client_insert_pending++;
3288 GNUNET_SET_add_element(initial_set, 3378 GNUNET_SET_add_element (initial_set,
3289 &element, 3379 &element,
3290 &client_insert_done, 3380 &client_insert_done,
3291 session); 3381 session);
3292 3382
3293#ifdef GNUNET_EXTRA_LOGGING 3383#ifdef GNUNET_EXTRA_LOGGING
3294 { 3384 {
3295 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3385 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3296 "P%u: element %s added\n", 3386 "P%u: element %s added\n",
3297 session->local_peer_idx, 3387 session->local_peer_idx,
3298 debug_str_element(&element)); 3388 debug_str_element (&element));
3299 } 3389 }
3300#endif 3390#endif
3301 GNUNET_free(ce); 3391 GNUNET_free (ce);
3302 GNUNET_SERVICE_client_continue(session->client); 3392 GNUNET_SERVICE_client_continue (session->client);
3303} 3393}
3304 3394
3305 3395
@@ -3310,24 +3400,24 @@ handle_client_insert(void *cls,
3310 * @param message message sent by the client 3400 * @param message message sent by the client
3311 */ 3401 */
3312static void 3402static void
3313handle_client_conclude(void *cls, 3403handle_client_conclude (void *cls,
3314 const struct GNUNET_MessageHeader *message) 3404 const struct GNUNET_MessageHeader *message)
3315{ 3405{
3316 struct ConsensusSession *session = cls; 3406 struct ConsensusSession *session = cls;
3317 3407
3318 if (GNUNET_YES == session->conclude_started) 3408 if (GNUNET_YES == session->conclude_started)
3319 { 3409 {
3320 /* conclude started twice */ 3410 /* conclude started twice */
3321 GNUNET_break(0); 3411 GNUNET_break (0);
3322 GNUNET_SERVICE_client_drop(session->client); 3412 GNUNET_SERVICE_client_drop (session->client);
3323 return; 3413 return;
3324 } 3414 }
3325 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3415 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3326 "conclude requested\n"); 3416 "conclude requested\n");
3327 session->conclude_started = GNUNET_YES; 3417 session->conclude_started = GNUNET_YES;
3328 install_step_timeouts(session); 3418 install_step_timeouts (session);
3329 run_ready_steps(session); 3419 run_ready_steps (session);
3330 GNUNET_SERVICE_client_continue(session->client); 3420 GNUNET_SERVICE_client_continue (session->client);
3331} 3421}
3332 3422
3333 3423
@@ -3337,12 +3427,12 @@ handle_client_conclude(void *cls,
3337 * @param cls closure 3427 * @param cls closure
3338 */ 3428 */
3339static void 3429static void
3340shutdown_task(void *cls) 3430shutdown_task (void *cls)
3341{ 3431{
3342 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3432 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3343 "shutting down\n"); 3433 "shutting down\n");
3344 GNUNET_STATISTICS_destroy(statistics, 3434 GNUNET_STATISTICS_destroy (statistics,
3345 GNUNET_NO); 3435 GNUNET_NO);
3346 statistics = NULL; 3436 statistics = NULL;
3347} 3437}
3348 3438
@@ -3355,24 +3445,24 @@ shutdown_task(void *cls)
3355 * @param service the initialized service 3445 * @param service the initialized service
3356 */ 3446 */
3357static void 3447static void
3358run(void *cls, 3448run (void *cls,
3359 const struct GNUNET_CONFIGURATION_Handle *c, 3449 const struct GNUNET_CONFIGURATION_Handle *c,
3360 struct GNUNET_SERVICE_Handle *service) 3450 struct GNUNET_SERVICE_Handle *service)
3361{ 3451{
3362 cfg = c; 3452 cfg = c;
3363 if (GNUNET_OK != 3453 if (GNUNET_OK !=
3364 GNUNET_CRYPTO_get_peer_identity(cfg, 3454 GNUNET_CRYPTO_get_peer_identity (cfg,
3365 &my_peer)) 3455 &my_peer))
3366 { 3456 {
3367 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 3457 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3368 "Could not retrieve host identity\n"); 3458 "Could not retrieve host identity\n");
3369 GNUNET_SCHEDULER_shutdown(); 3459 GNUNET_SCHEDULER_shutdown ();
3370 return; 3460 return;
3371 } 3461 }
3372 statistics = GNUNET_STATISTICS_create("consensus", 3462 statistics = GNUNET_STATISTICS_create ("consensus",
3373 cfg); 3463 cfg);
3374 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, 3464 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
3375 NULL); 3465 NULL);
3376} 3466}
3377 3467
3378 3468
@@ -3385,17 +3475,17 @@ run(void *cls,
3385 * @return @a c 3475 * @return @a c
3386 */ 3476 */
3387static void * 3477static void *
3388client_connect_cb(void *cls, 3478client_connect_cb (void *cls,
3389 struct GNUNET_SERVICE_Client *c, 3479 struct GNUNET_SERVICE_Client *c,
3390 struct GNUNET_MQ_Handle *mq) 3480 struct GNUNET_MQ_Handle *mq)
3391{ 3481{
3392 struct ConsensusSession *session = GNUNET_new(struct ConsensusSession); 3482 struct ConsensusSession *session = GNUNET_new (struct ConsensusSession);
3393 3483
3394 session->client = c; 3484 session->client = c;
3395 session->client_mq = mq; 3485 session->client_mq = mq;
3396 GNUNET_CONTAINER_DLL_insert(sessions_head, 3486 GNUNET_CONTAINER_DLL_insert (sessions_head,
3397 sessions_tail, 3487 sessions_tail,
3398 session); 3488 session);
3399 return session; 3489 return session;
3400} 3490}
3401 3491
@@ -3408,29 +3498,29 @@ client_connect_cb(void *cls,
3408 * @param internal_cls should be equal to @a c 3498 * @param internal_cls should be equal to @a c
3409 */ 3499 */
3410static void 3500static void
3411client_disconnect_cb(void *cls, 3501client_disconnect_cb (void *cls,
3412 struct GNUNET_SERVICE_Client *c, 3502 struct GNUNET_SERVICE_Client *c,
3413 void *internal_cls) 3503 void *internal_cls)
3414{ 3504{
3415 struct ConsensusSession *session = internal_cls; 3505 struct ConsensusSession *session = internal_cls;
3416 3506
3417 if (NULL != session->set_listener) 3507 if (NULL != session->set_listener)
3418 { 3508 {
3419 GNUNET_SET_listen_cancel(session->set_listener); 3509 GNUNET_SET_listen_cancel (session->set_listener);
3420 session->set_listener = NULL; 3510 session->set_listener = NULL;
3421 } 3511 }
3422 GNUNET_CONTAINER_DLL_remove(sessions_head, 3512 GNUNET_CONTAINER_DLL_remove (sessions_head,
3423 sessions_tail, 3513 sessions_tail,
3424 session); 3514 session);
3425 3515
3426 while (session->set_handles_head) 3516 while (session->set_handles_head)
3427 { 3517 {
3428 struct SetHandle *sh = session->set_handles_head; 3518 struct SetHandle *sh = session->set_handles_head;
3429 session->set_handles_head = sh->next; 3519 session->set_handles_head = sh->next;
3430 GNUNET_SET_destroy(sh->h); 3520 GNUNET_SET_destroy (sh->h);
3431 GNUNET_free(sh); 3521 GNUNET_free (sh);
3432 } 3522 }
3433 GNUNET_free(session); 3523 GNUNET_free (session);
3434} 3524}
3435 3525
3436 3526
@@ -3444,18 +3534,18 @@ GNUNET_SERVICE_MAIN
3444 &client_connect_cb, 3534 &client_connect_cb,
3445 &client_disconnect_cb, 3535 &client_disconnect_cb,
3446 NULL, 3536 NULL,
3447 GNUNET_MQ_hd_fixed_size(client_conclude, 3537 GNUNET_MQ_hd_fixed_size (client_conclude,
3448 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE, 3538 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE,
3449 struct GNUNET_MessageHeader, 3539 struct GNUNET_MessageHeader,
3450 NULL), 3540 NULL),
3451 GNUNET_MQ_hd_var_size(client_insert, 3541 GNUNET_MQ_hd_var_size (client_insert,
3452 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_INSERT, 3542 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_INSERT,
3453 struct GNUNET_CONSENSUS_ElementMessage, 3543 struct GNUNET_CONSENSUS_ElementMessage,
3454 NULL), 3544 NULL),
3455 GNUNET_MQ_hd_var_size(client_join, 3545 GNUNET_MQ_hd_var_size (client_join,
3456 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_JOIN, 3546 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_JOIN,
3457 struct GNUNET_CONSENSUS_JoinMessage, 3547 struct GNUNET_CONSENSUS_JoinMessage,
3458 NULL), 3548 NULL),
3459 GNUNET_MQ_handler_end()); 3549 GNUNET_MQ_handler_end ());
3460 3550
3461/* end of gnunet-service-consensus.c */ 3551/* end of gnunet-service-consensus.c */
diff --git a/src/consensus/plugin_block_consensus.c b/src/consensus/plugin_block_consensus.c
index a90b451d2..1caf4fc39 100644
--- a/src/consensus/plugin_block_consensus.c
+++ b/src/consensus/plugin_block_consensus.c
@@ -47,16 +47,16 @@
47 * @return characterization of result 47 * @return characterization of result
48 */ 48 */
49static enum GNUNET_BLOCK_EvaluationResult 49static enum GNUNET_BLOCK_EvaluationResult
50block_plugin_consensus_evaluate(void *cls, 50block_plugin_consensus_evaluate (void *cls,
51 struct GNUNET_BLOCK_Context *ctx, 51 struct GNUNET_BLOCK_Context *ctx,
52 enum GNUNET_BLOCK_Type type, 52 enum GNUNET_BLOCK_Type type,
53 struct GNUNET_BLOCK_Group *group, 53 struct GNUNET_BLOCK_Group *group,
54 enum GNUNET_BLOCK_EvaluationOptions eo, 54 enum GNUNET_BLOCK_EvaluationOptions eo,
55 const struct GNUNET_HashCode *query, 55 const struct GNUNET_HashCode *query,
56 const void *xquery, 56 const void *xquery,
57 size_t xquery_size, 57 size_t xquery_size,
58 const void *reply_block, 58 const void *reply_block,
59 size_t reply_block_size) 59 size_t reply_block_size)
60{ 60{
61 if (reply_block_size < sizeof(struct ConsensusElement)) 61 if (reply_block_size < sizeof(struct ConsensusElement))
62 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 62 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
@@ -67,15 +67,16 @@ block_plugin_consensus_evaluate(void *cls,
67 (0 == ce->payload_type)) 67 (0 == ce->payload_type))
68 return GNUNET_BLOCK_EVALUATION_OK_MORE; 68 return GNUNET_BLOCK_EVALUATION_OK_MORE;
69 69
70 return GNUNET_BLOCK_evaluate(ctx, 70 return GNUNET_BLOCK_evaluate (ctx,
71 type, 71 type,
72 group, 72 group,
73 eo, 73 eo,
74 query, 74 query,
75 xquery, 75 xquery,
76 xquery_size, 76 xquery_size,
77 &ce[1], 77 &ce[1],
78 reply_block_size - sizeof(struct ConsensusElement)); 78 reply_block_size - sizeof(struct
79 ConsensusElement));
79} 80}
80 81
81 82
@@ -91,11 +92,11 @@ block_plugin_consensus_evaluate(void *cls,
91 * (or if extracting a key from a block of this type does not work) 92 * (or if extracting a key from a block of this type does not work)
92 */ 93 */
93static int 94static int
94block_plugin_consensus_get_key(void *cls, 95block_plugin_consensus_get_key (void *cls,
95 enum GNUNET_BLOCK_Type type, 96 enum GNUNET_BLOCK_Type type,
96 const void *block, 97 const void *block,
97 size_t block_size, 98 size_t block_size,
98 struct GNUNET_HashCode *key) 99 struct GNUNET_HashCode *key)
99{ 100{
100 return GNUNET_SYSERR; 101 return GNUNET_SYSERR;
101} 102}
@@ -105,16 +106,15 @@ block_plugin_consensus_get_key(void *cls,
105 * Entry point for the plugin. 106 * Entry point for the plugin.
106 */ 107 */
107void * 108void *
108libgnunet_plugin_block_consensus_init(void *cls) 109libgnunet_plugin_block_consensus_init (void *cls)
109{ 110{
110 static enum GNUNET_BLOCK_Type types[] = 111 static enum GNUNET_BLOCK_Type types[] = {
111 {
112 GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT, 112 GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT,
113 GNUNET_BLOCK_TYPE_ANY /* end of list */ 113 GNUNET_BLOCK_TYPE_ANY /* end of list */
114 }; 114 };
115 struct GNUNET_BLOCK_PluginFunctions *api; 115 struct GNUNET_BLOCK_PluginFunctions *api;
116 116
117 api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions); 117 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
118 api->evaluate = &block_plugin_consensus_evaluate; 118 api->evaluate = &block_plugin_consensus_evaluate;
119 api->get_key = &block_plugin_consensus_get_key; 119 api->get_key = &block_plugin_consensus_get_key;
120 api->types = types; 120 api->types = types;
@@ -126,11 +126,11 @@ libgnunet_plugin_block_consensus_init(void *cls)
126 * Exit point from the plugin. 126 * Exit point from the plugin.
127 */ 127 */
128void * 128void *
129libgnunet_plugin_block_consensus_done(void *cls) 129libgnunet_plugin_block_consensus_done (void *cls)
130{ 130{
131 struct GNUNET_BLOCK_PluginFunctions *api = cls; 131 struct GNUNET_BLOCK_PluginFunctions *api = cls;
132 132
133 GNUNET_free(api); 133 GNUNET_free (api);
134 return NULL; 134 return NULL;
135} 135}
136 136
diff --git a/src/consensus/test_consensus_api.c b/src/consensus/test_consensus_api.c
index a2ae36222..d32bc06ed 100644
--- a/src/consensus/test_consensus_api.c
+++ b/src/consensus/test_consensus_api.c
@@ -36,31 +36,31 @@ static unsigned int elements_received;
36 36
37 37
38static void 38static void
39conclude_done(void *cls) 39conclude_done (void *cls)
40{ 40{
41 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "conclude over\n"); 41 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "conclude over\n");
42 if (2 != elements_received) 42 if (2 != elements_received)
43 GNUNET_assert(0); 43 GNUNET_assert (0);
44 GNUNET_SCHEDULER_shutdown(); 44 GNUNET_SCHEDULER_shutdown ();
45} 45}
46 46
47static void 47static void
48on_new_element(void *cls, 48on_new_element (void *cls,
49 const struct GNUNET_SET_Element *element) 49 const struct GNUNET_SET_Element *element)
50{ 50{
51 elements_received++; 51 elements_received++;
52} 52}
53 53
54static void 54static void
55insert_done(void *cls, int success) 55insert_done (void *cls, int success)
56{ 56{
57 /* make sure cb is only called once */ 57 /* make sure cb is only called once */
58 static int called = GNUNET_NO; 58 static int called = GNUNET_NO;
59 59
60 GNUNET_assert(GNUNET_NO == called); 60 GNUNET_assert (GNUNET_NO == called);
61 called = GNUNET_YES; 61 called = GNUNET_YES;
62 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "insert done\n"); 62 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "insert done\n");
63 GNUNET_CONSENSUS_conclude(consensus, &conclude_done, NULL); 63 GNUNET_CONSENSUS_conclude (consensus, &conclude_done, NULL);
64} 64}
65 65
66 66
@@ -70,47 +70,49 @@ insert_done(void *cls, int success)
70 * @param cls closure 70 * @param cls closure
71 */ 71 */
72static void 72static void
73on_shutdown(void *cls) 73on_shutdown (void *cls)
74{ 74{
75 if (NULL != consensus) 75 if (NULL != consensus)
76 { 76 {
77 GNUNET_CONSENSUS_destroy(consensus); 77 GNUNET_CONSENSUS_destroy (consensus);
78 consensus = NULL; 78 consensus = NULL;
79 } 79 }
80} 80}
81 81
82 82
83static void 83static void
84run(void *cls, 84run (void *cls,
85 const struct GNUNET_CONFIGURATION_Handle *cfg, 85 const struct GNUNET_CONFIGURATION_Handle *cfg,
86 struct GNUNET_TESTING_Peer *peer) 86 struct GNUNET_TESTING_Peer *peer)
87{ 87{
88 char *str = "foo"; 88 char *str = "foo";
89 89
90 struct GNUNET_SET_Element el1 = { 4, 0, "foo" }; 90 struct GNUNET_SET_Element el1 = { 4, 0, "foo" };
91 struct GNUNET_SET_Element el2 = { 5, 0, "quux" }; 91 struct GNUNET_SET_Element el2 = { 5, 0, "quux" };
92 92
93 GNUNET_log_setup("test_consensus_api", 93 GNUNET_log_setup ("test_consensus_api",
94 "INFO", 94 "INFO",
95 NULL); 95 NULL);
96 GNUNET_SCHEDULER_add_shutdown(&on_shutdown, NULL); 96 GNUNET_SCHEDULER_add_shutdown (&on_shutdown, NULL);
97 97
98 GNUNET_CRYPTO_hash(str, strlen(str), &session_id); 98 GNUNET_CRYPTO_hash (str, strlen (str), &session_id);
99 consensus = GNUNET_CONSENSUS_create(cfg, 0, NULL, &session_id, 99 consensus = GNUNET_CONSENSUS_create (cfg, 0, NULL, &session_id,
100 GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_SECONDS), 100 GNUNET_TIME_relative_to_absolute (
101 GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_MINUTES), 101 GNUNET_TIME_UNIT_SECONDS),
102 on_new_element, &consensus); 102 GNUNET_TIME_relative_to_absolute (
103 GNUNET_assert(consensus != NULL); 103 GNUNET_TIME_UNIT_MINUTES),
104 104 on_new_element, &consensus);
105 GNUNET_CONSENSUS_insert(consensus, &el1, NULL, &consensus); 105 GNUNET_assert (consensus != NULL);
106 GNUNET_CONSENSUS_insert(consensus, &el2, &insert_done, &consensus); 106
107 GNUNET_CONSENSUS_insert (consensus, &el1, NULL, &consensus);
108 GNUNET_CONSENSUS_insert (consensus, &el2, &insert_done, &consensus);
107} 109}
108 110
109 111
110int 112int
111main(int argc, char **argv) 113main (int argc, char **argv)
112{ 114{
113 return GNUNET_TESTING_peer_run("test_consensus_api", 115 return GNUNET_TESTING_peer_run ("test_consensus_api",
114 "test_consensus.conf", 116 "test_consensus.conf",
115 &run, NULL); 117 &run, NULL);
116} 118}