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) |
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, enum auction_type atype, enum outcome_type outcome) { + uint32_t price; + uint16_t winner = -1; unsigned char *buf; size_t buflen; - /* if we got the current round message from all participants, advance to - * next round */ + /* if we did not got the current round message from all participants, don't + * advance to the next round yet. Early return, since we have to wait for + * the other participants messages. */ for (uint16_t i = 0; i < ad->n; i++) if (!gcry_mpi_test_bit (ad->round_progress, i)) return; + /* current round finished, clear round progress and advance to next one */ gcry_mpi_clear_highbit (ad->round_progress, 0); if (msg_last == ++(ad->cur_round)) { - /** \todo: unify …_determine_outcome function signature and call here */ + /* done with all rounds, determine outcome here */ + /** \todo: unify …_determine_outcome function signature? */ + if (auction_firstPrice == atype && outcome_private == outcome) + { + if (-1 == (price = fp_priv_determine_outcome (ad))) + ad->result (ad->closure, ad->i, 0, 0); + else + ad->result (ad->closure, ad->i, 1, price); + } + else if (auction_firstPrice == atype && outcome_public == outcome) + { + if (-1 == (price = fp_pub_determine_outcome (ad, &winner))) + ad->result (ad->closure, ad->i, 0, 0); + else + ad->result (ad->closure, winner, 1, price); + } + return; } if (!handler_out[atype][outcome][ad->cur_round] || @@ -298,7 +318,7 @@ BRANDT_got_message (struct BRANDT_Auction *auction, const unsigned char *msg, size_t msg_len) { - uint16_t mtype = *(uint16_t *)msg; + struct msg_head *head = (struct msg_head *)msg; enum auction_type atype; enum outcome_type outcome; enum rounds round = auction->cur_round; @@ -306,7 +326,12 @@ BRANDT_got_message (struct BRANDT_Auction *auction, atype = auction->m > 0 ? auction_mPlusFirstPrice : auction_firstPrice; outcome = auction->outcome_public ? outcome_public : outcome_private; - /** \todo: cache out of order messages */ + /** \todo: cache out of order messages instead of discarding */ + if (ntohl (head->msg_type) != round || ntohl (head->prot_version) != 0) + { + weprintf ("got unexpected message, ignoring..."); + return; + } /* check if we already got that round message from the same user */ if (gcry_mpi_test_bit (auction->round_progress, sender)) @@ -317,8 +342,8 @@ BRANDT_got_message (struct BRANDT_Auction *auction, if (!handler_in[atype][outcome][round] || !handler_in[atype][outcome][round](auction, - msg + sizeof (mtype), - msg_len - sizeof (mtype), + msg + sizeof (*head), + msg_len - sizeof (*head), sender)) { /** \todo */ |