aboutsummaryrefslogtreecommitdiff
path: root/brandt.c
diff options
context:
space:
mode:
authorMarkus Teich <markus.teich@stusta.mhn.de>2016-08-03 14:07:21 +0200
committerMarkus Teich <markus.teich@stusta.mhn.de>2016-08-03 14:07:21 +0200
commitfbc3e92e59d07c77440d1ecb858871d9d2958fb0 (patch)
tree62bcd039282fcff503495fb56c61ffc71a916313 /brandt.c
parent342d3729dfcb88060c3541d2b38d23d3294a11fb (diff)
downloadlibbrandt-fbc3e92e59d07c77440d1ecb858871d9d2958fb0.tar.gz
libbrandt-fbc3e92e59d07c77440d1ecb858871d9d2958fb0.zip
stuff
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)
49} 49}
50 50
51 51
52static void
53advance_round (struct BRANDT_Auction *auction, enum auction_type atype, enum outcome_type outcome)
54{
55 unsigned char *buf;
56 size_t buflen;
57
58 /* if we got the current round message from all participants, advance to
59 * next round */
60 for (uint16_t i = 0; i < auction->n; i++)
61 if (!gcry_mpi_test_bit (auction->round_progress, i))
62 return;
63
64 gcry_mpi_clear_highbit (auction->round_progress, 0);
65 if (msg_last == ++(auction->cur_round))
66 {
67 }
68
69 if (!handler_out[atype][outcome][auction->cur_round] ||
70 !(buf = handler_out[atype][outcome][auction->cur_round](auction, &buflen)))
71 {
72 /** \todo */
73 weprintf ("wow fail out");
74 return;
75 }
76
77 /** \todo: add msgtype header in the handler_out functions */
78
79 /* last message only sent to seller, others are broadcasted */
80 if (msg_decrypt == auction->cur_round)
81 auction->ucast (auction->closure, buf, buflen);
82 else
83 auction->bcast (auction->closure, buf, buflen);
84}
85
86
52void 87void
53BRANDT_got_message (struct BRANDT_Auction *auction, 88BRANDT_got_message (struct BRANDT_Auction *auction,
54 uint16_t sender, 89 uint16_t sender,
@@ -56,8 +91,8 @@ BRANDT_got_message (struct BRANDT_Auction *auction,
56 size_t msg_len) 91 size_t msg_len)
57{ 92{
58 uint16_t mtype = *(uint16_t *)msg; 93 uint16_t mtype = *(uint16_t *)msg;
59 int atype; 94 enum auction_type atype;
60 int outcome; 95 enum outcome_type outcome;
61 enum rounds round = auction->cur_round; 96 enum rounds round = auction->cur_round;
62 97
63 atype = auction->desc->m > 0 ? auction_mPlusFirstPrice : auction_firstPrice; 98 atype = auction->desc->m > 0 ? auction_mPlusFirstPrice : auction_firstPrice;
@@ -65,6 +100,13 @@ BRANDT_got_message (struct BRANDT_Auction *auction,
65 100
66 /** \todo: cache out of order messages */ 101 /** \todo: cache out of order messages */
67 102
103 /* check if we already got that round message from the same user */
104 if (gcry_mpi_test_bit (auction->round_progress, sender))
105 {
106 weprintf ("got a duplicate message from user %d", sender);
107 return;
108 }
109
68 if (!handler_in[atype][outcome][round] || 110 if (!handler_in[atype][outcome][round] ||
69 !handler_in[atype][outcome][round](auction, 111 !handler_in[atype][outcome][round](auction,
70 msg + sizeof (mtype), 112 msg + sizeof (mtype),
@@ -72,6 +114,10 @@ BRANDT_got_message (struct BRANDT_Auction *auction,
72 sender)) 114 sender))
73 { 115 {
74 /** \todo */ 116 /** \todo */
75 weprintf ("wow fail"); 117 weprintf ("wow fail in");
118 return;
76 } 119 }
120 gcry_mpi_set_bit (auction->round_progress, sender);
121
122 advance_round (auction, atype, outcome);
77} 123}