diff options
author | Markus Teich <markus.teich@stusta.mhn.de> | 2016-08-23 13:33:08 +0200 |
---|---|---|
committer | Markus Teich <markus.teich@stusta.mhn.de> | 2016-08-23 13:33:08 +0200 |
commit | 0d3b32b24881cb9ce89d0b6689ada53f88d0008e (patch) | |
tree | 37127d2c38c393f9c00d3f3eee3ca9a44c603d1d /brandt.c | |
parent | 4561ac2026d931d9aeab36e07fd041ae60c937ee (diff) | |
download | libbrandt-0d3b32b24881cb9ce89d0b6689ada53f88d0008e.tar.gz libbrandt-0d3b32b24881cb9ce89d0b6689ada53f88d0008e.zip |
add outcome determination to brandt.c
Diffstat (limited to 'brandt.c')
-rw-r--r-- | brandt.c | 39 |
1 files changed, 32 insertions, 7 deletions
@@ -261,19 +261,39 @@ advance_round (struct BRANDT_Auction *ad, | |||
261 | enum auction_type atype, | 261 | enum auction_type atype, |
262 | enum outcome_type outcome) | 262 | enum outcome_type outcome) |
263 | { | 263 | { |
264 | uint32_t price; | ||
265 | uint16_t winner = -1; | ||
264 | unsigned char *buf; | 266 | unsigned char *buf; |
265 | size_t buflen; | 267 | size_t buflen; |
266 | 268 | ||
267 | /* if we got the current round message from all participants, advance to | 269 | /* if we did not got the current round message from all participants, don't |
268 | * next round */ | 270 | * advance to the next round yet. Early return, since we have to wait for |
271 | * the other participants messages. */ | ||
269 | for (uint16_t i = 0; i < ad->n; i++) | 272 | for (uint16_t i = 0; i < ad->n; i++) |
270 | if (!gcry_mpi_test_bit (ad->round_progress, i)) | 273 | if (!gcry_mpi_test_bit (ad->round_progress, i)) |
271 | return; | 274 | return; |
272 | 275 | ||
276 | /* current round finished, clear round progress and advance to next one */ | ||
273 | gcry_mpi_clear_highbit (ad->round_progress, 0); | 277 | gcry_mpi_clear_highbit (ad->round_progress, 0); |
274 | if (msg_last == ++(ad->cur_round)) | 278 | if (msg_last == ++(ad->cur_round)) |
275 | { | 279 | { |
276 | /** \todo: unify …_determine_outcome function signature and call here */ | 280 | /* done with all rounds, determine outcome here */ |
281 | /** \todo: unify …_determine_outcome function signature? */ | ||
282 | if (auction_firstPrice == atype && outcome_private == outcome) | ||
283 | { | ||
284 | if (-1 == (price = fp_priv_determine_outcome (ad))) | ||
285 | ad->result (ad->closure, ad->i, 0, 0); | ||
286 | else | ||
287 | ad->result (ad->closure, ad->i, 1, price); | ||
288 | } | ||
289 | else if (auction_firstPrice == atype && outcome_public == outcome) | ||
290 | { | ||
291 | if (-1 == (price = fp_pub_determine_outcome (ad, &winner))) | ||
292 | ad->result (ad->closure, ad->i, 0, 0); | ||
293 | else | ||
294 | ad->result (ad->closure, winner, 1, price); | ||
295 | } | ||
296 | return; | ||
277 | } | 297 | } |
278 | 298 | ||
279 | if (!handler_out[atype][outcome][ad->cur_round] || | 299 | if (!handler_out[atype][outcome][ad->cur_round] || |
@@ -298,7 +318,7 @@ BRANDT_got_message (struct BRANDT_Auction *auction, | |||
298 | const unsigned char *msg, | 318 | const unsigned char *msg, |
299 | size_t msg_len) | 319 | size_t msg_len) |
300 | { | 320 | { |
301 | uint16_t mtype = *(uint16_t *)msg; | 321 | struct msg_head *head = (struct msg_head *)msg; |
302 | enum auction_type atype; | 322 | enum auction_type atype; |
303 | enum outcome_type outcome; | 323 | enum outcome_type outcome; |
304 | enum rounds round = auction->cur_round; | 324 | enum rounds round = auction->cur_round; |
@@ -306,7 +326,12 @@ BRANDT_got_message (struct BRANDT_Auction *auction, | |||
306 | atype = auction->m > 0 ? auction_mPlusFirstPrice : auction_firstPrice; | 326 | atype = auction->m > 0 ? auction_mPlusFirstPrice : auction_firstPrice; |
307 | outcome = auction->outcome_public ? outcome_public : outcome_private; | 327 | outcome = auction->outcome_public ? outcome_public : outcome_private; |
308 | 328 | ||
309 | /** \todo: cache out of order messages */ | 329 | /** \todo: cache out of order messages instead of discarding */ |
330 | if (ntohl (head->msg_type) != round || ntohl (head->prot_version) != 0) | ||
331 | { | ||
332 | weprintf ("got unexpected message, ignoring..."); | ||
333 | return; | ||
334 | } | ||
310 | 335 | ||
311 | /* check if we already got that round message from the same user */ | 336 | /* check if we already got that round message from the same user */ |
312 | if (gcry_mpi_test_bit (auction->round_progress, sender)) | 337 | if (gcry_mpi_test_bit (auction->round_progress, sender)) |
@@ -317,8 +342,8 @@ BRANDT_got_message (struct BRANDT_Auction *auction, | |||
317 | 342 | ||
318 | if (!handler_in[atype][outcome][round] || | 343 | if (!handler_in[atype][outcome][round] || |
319 | !handler_in[atype][outcome][round](auction, | 344 | !handler_in[atype][outcome][round](auction, |
320 | msg + sizeof (mtype), | 345 | msg + sizeof (*head), |
321 | msg_len - sizeof (mtype), | 346 | msg_len - sizeof (*head), |
322 | sender)) | 347 | sender)) |
323 | { | 348 | { |
324 | /** \todo */ | 349 | /** \todo */ |