aboutsummaryrefslogtreecommitdiff
path: root/brandt.c
diff options
context:
space:
mode:
Diffstat (limited to 'brandt.c')
-rw-r--r--brandt.c52
1 files changed, 49 insertions, 3 deletions
diff --git a/brandt.c b/brandt.c
index 6c334b8..b175c3e 100644
--- a/brandt.c
+++ b/brandt.c
@@ -49,6 +49,41 @@ BRANDT_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx)
}
+static void
+advance_round (struct BRANDT_Auction *auction, enum auction_type atype, enum outcome_type outcome)
+{
+ unsigned char *buf;
+ size_t buflen;
+
+ /* if we got the current round message from all participants, advance to
+ * next round */
+ for (uint16_t i = 0; i < auction->n; i++)
+ if (!gcry_mpi_test_bit (auction->round_progress, i))
+ return;
+
+ gcry_mpi_clear_highbit (auction->round_progress, 0);
+ if (msg_last == ++(auction->cur_round))
+ {
+ }
+
+ if (!handler_out[atype][outcome][auction->cur_round] ||
+ !(buf = handler_out[atype][outcome][auction->cur_round](auction, &buflen)))
+ {
+ /** \todo */
+ weprintf ("wow fail out");
+ return;
+ }
+
+ /** \todo: add msgtype header in the handler_out functions */
+
+ /* last message only sent to seller, others are broadcasted */
+ if (msg_decrypt == auction->cur_round)
+ auction->ucast (auction->closure, buf, buflen);
+ else
+ auction->bcast (auction->closure, buf, buflen);
+}
+
+
void
BRANDT_got_message (struct BRANDT_Auction *auction,
uint16_t sender,
@@ -56,8 +91,8 @@ BRANDT_got_message (struct BRANDT_Auction *auction,
size_t msg_len)
{
uint16_t mtype = *(uint16_t *)msg;
- int atype;
- int outcome;
+ enum auction_type atype;
+ enum outcome_type outcome;
enum rounds round = auction->cur_round;
atype = auction->desc->m > 0 ? auction_mPlusFirstPrice : auction_firstPrice;
@@ -65,6 +100,13 @@ BRANDT_got_message (struct BRANDT_Auction *auction,
/** \todo: cache out of order messages */
+ /* check if we already got that round message from the same user */
+ if (gcry_mpi_test_bit (auction->round_progress, sender))
+ {
+ weprintf ("got a duplicate message from user %d", sender);
+ return;
+ }
+
if (!handler_in[atype][outcome][round] ||
!handler_in[atype][outcome][round](auction,
msg + sizeof (mtype),
@@ -72,6 +114,10 @@ BRANDT_got_message (struct BRANDT_Auction *auction,
sender))
{
/** \todo */
- weprintf ("wow fail");
+ weprintf ("wow fail in");
+ return;
}
+ gcry_mpi_set_bit (auction->round_progress, sender);
+
+ advance_round (auction, atype, outcome);
}