add outcome determination to brandt.c
This commit is contained in:
parent
4561ac2026
commit
0d3b32b248
39
brandt.c
39
brandt.c
@ -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 */
|
||||
|
4
crypto.h
4
crypto.h
@ -142,6 +142,8 @@ int fp_priv_recv_decryption (struct BRANDT_Auction *ad,
|
||||
size_t buflen,
|
||||
uint16_t sender);
|
||||
|
||||
int32_t fp_priv_determine_outcome (struct BRANDT_Auction *ad);
|
||||
|
||||
unsigned char *fp_pub_compute_outcome (struct BRANDT_Auction *ad,
|
||||
size_t *buflen);
|
||||
int fp_pub_recv_outcome (struct BRANDT_Auction *ad,
|
||||
@ -156,7 +158,7 @@ int fp_pub_recv_decryption (struct BRANDT_Auction *ad,
|
||||
size_t buflen,
|
||||
uint16_t sender);
|
||||
|
||||
int32_t fp_priv_determine_outcome (struct BRANDT_Auction *ad);
|
||||
int32_t fp_pub_determine_outcome (struct BRANDT_Auction *ad, uint16_t *winner);
|
||||
|
||||
|
||||
/* --- Round dictionaries --- */
|
||||
|
Loading…
Reference in New Issue
Block a user