diff options
author | Markus Teich <markus.teich@stusta.mhn.de> | 2016-08-31 14:37:22 +0200 |
---|---|---|
committer | Markus Teich <markus.teich@stusta.mhn.de> | 2016-08-31 14:37:22 +0200 |
commit | 9f0e72f1e8615c9c03222372b2c579471bcce602 (patch) | |
tree | a7fd357b79a9f939de5d5f67de1a030b59ff4418 /brandt.c | |
parent | 0d3b32b24881cb9ce89d0b6689ada53f88d0008e (diff) | |
download | libbrandt-9f0e72f1e8615c9c03222372b2c579471bcce602.tar.gz libbrandt-9f0e72f1e8615c9c03222372b2c579471bcce602.zip |
temporary dump for discussion
Diffstat (limited to 'brandt.c')
-rw-r--r-- | brandt.c | 82 |
1 files changed, 61 insertions, 21 deletions
@@ -52,11 +52,35 @@ BRANDT_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx) | |||
52 | 52 | ||
53 | void | 53 | void |
54 | BRANDT_bidder_start (struct BRANDT_Auction *auction, | 54 | BRANDT_bidder_start (struct BRANDT_Auction *auction, |
55 | uint16_t i, | ||
55 | uint16_t n) | 56 | uint16_t n) |
56 | { | 57 | { |
57 | GNUNET_assert (n > 0); | 58 | GNUNET_assert (auction && n > 0 && i < n); |
58 | auction->n = n; | 59 | auction->n = n; |
59 | /** \todo: send first message */ | 60 | auction->i = i; |
61 | enum auction_type atype; | ||
62 | enum outcome_type outcome; | ||
63 | unsigned char *buf; | ||
64 | size_t buflen; | ||
65 | |||
66 | atype = auction->m > 0 ? auction_mPlusFirstPrice : auction_firstPrice; | ||
67 | outcome = auction->outcome_public ? outcome_public : outcome_private; | ||
68 | |||
69 | if (handler_prep[atype][outcome][msg_init]) | ||
70 | handler_prep[atype][outcome][msg_init] (auction); | ||
71 | |||
72 | if (!handler_out[atype][outcome][msg_init] || | ||
73 | !(buf = handler_out[atype][outcome][msg_init](auction, &buflen))) | ||
74 | { | ||
75 | /** \todo */ | ||
76 | weprintf ("wow fail out"); | ||
77 | return; | ||
78 | } | ||
79 | |||
80 | weprintf("broadcasting msg_init %p from bidder %d", buf, i); | ||
81 | if (0 == auction->bcast (auction->closure, buf, buflen)) | ||
82 | gcry_mpi_set_bit (auction->round_progress, auction->i); | ||
83 | free (buf); | ||
60 | } | 84 | } |
61 | 85 | ||
62 | 86 | ||
@@ -65,10 +89,12 @@ seller_start (void *arg) | |||
65 | { | 89 | { |
66 | struct BRANDT_Auction *ad = (struct BRANDT_Auction *)arg; | 90 | struct BRANDT_Auction *ad = (struct BRANDT_Auction *)arg; |
67 | 91 | ||
92 | ad->task = NULL; | ||
93 | |||
68 | if (0 == (ad->n = ad->start (ad->closure))) | 94 | if (0 == (ad->n = ad->start (ad->closure))) |
69 | { | 95 | { |
70 | weprintf ("no bidders registered for auction"); | 96 | weprintf ("no bidders registered for auction"); |
71 | ad->result (ad->closure, -1, result_no_bidders, 0); | 97 | /** todo: somehow mark auction as done / ready for cleanup */ |
72 | return; | 98 | return; |
73 | } | 99 | } |
74 | } | 100 | } |
@@ -201,7 +227,8 @@ BRANDT_join (BRANDT_CbResult result, | |||
201 | const void *auction_desc, | 227 | const void *auction_desc, |
202 | size_t auction_desc_len, | 228 | size_t auction_desc_len, |
203 | const void *description, | 229 | const void *description, |
204 | uint32_t description_len) | 230 | uint32_t description_len, |
231 | uint16_t bid) | ||
205 | { | 232 | { |
206 | struct BRANDT_Auction *ret = GNUNET_new (struct BRANDT_Auction); | 233 | struct BRANDT_Auction *ret = GNUNET_new (struct BRANDT_Auction); |
207 | 234 | ||
@@ -220,6 +247,7 @@ BRANDT_join (BRANDT_CbResult result, | |||
220 | } | 247 | } |
221 | ret->cur_round = msg_init; | 248 | ret->cur_round = msg_init; |
222 | ret->round_progress = gcry_mpi_new (256); | 249 | ret->round_progress = gcry_mpi_new (256); |
250 | ret->b = bid; | ||
223 | 251 | ||
224 | /* we are the seller */ | 252 | /* we are the seller */ |
225 | ret->seller_mode = 0; | 253 | ret->seller_mode = 0; |
@@ -261,8 +289,8 @@ advance_round (struct BRANDT_Auction *ad, | |||
261 | enum auction_type atype, | 289 | enum auction_type atype, |
262 | enum outcome_type outcome) | 290 | enum outcome_type outcome) |
263 | { | 291 | { |
264 | uint32_t price; | 292 | struct BRANDT_Result *res; |
265 | uint16_t winner = -1; | 293 | uint16_t reslen = 0; |
266 | unsigned char *buf; | 294 | unsigned char *buf; |
267 | size_t buflen; | 295 | size_t buflen; |
268 | 296 | ||
@@ -278,21 +306,25 @@ advance_round (struct BRANDT_Auction *ad, | |||
278 | if (msg_last == ++(ad->cur_round)) | 306 | if (msg_last == ++(ad->cur_round)) |
279 | { | 307 | { |
280 | /* done with all rounds, determine outcome here */ | 308 | /* done with all rounds, determine outcome here */ |
281 | /** \todo: unify …_determine_outcome function signature? */ | 309 | if (!handler_res[atype][outcome] || |
282 | if (auction_firstPrice == atype && outcome_private == outcome) | 310 | !(res = handler_res[atype][outcome] (ad, &reslen))) |
283 | { | 311 | { |
284 | if (-1 == (price = fp_priv_determine_outcome (ad))) | 312 | /** \todo */ |
285 | ad->result (ad->closure, ad->i, 0, 0); | 313 | weprintf ("wow fail result"); |
286 | else | 314 | /** \todo: call result with null pointer here? */ |
287 | ad->result (ad->closure, ad->i, 1, price); | 315 | return; |
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 | } | 316 | } |
317 | |||
318 | ad->result (ad->closure, res, reslen); | ||
319 | return; | ||
320 | } | ||
321 | |||
322 | if (handler_prep[atype][outcome][ad->cur_round]) | ||
323 | handler_prep[atype][outcome][ad->cur_round] (ad); | ||
324 | |||
325 | if (ad->seller_mode) | ||
326 | { | ||
327 | /** \todo: setup round timeout trigger */ | ||
296 | return; | 328 | return; |
297 | } | 329 | } |
298 | 330 | ||
@@ -306,9 +338,15 @@ advance_round (struct BRANDT_Auction *ad, | |||
306 | 338 | ||
307 | /* last message only sent to seller, others are broadcasted */ | 339 | /* last message only sent to seller, others are broadcasted */ |
308 | if (msg_decrypt == ad->cur_round) | 340 | if (msg_decrypt == ad->cur_round) |
309 | ad->ucast (ad->closure, buf, buflen); | 341 | { |
342 | if (0 == ad->ucast (ad->closure, buf, buflen)) | ||
343 | gcry_mpi_set_bit (ad->round_progress, ad->i); | ||
344 | } | ||
310 | else | 345 | else |
311 | ad->bcast (ad->closure, buf, buflen); | 346 | { |
347 | if (0 == ad->bcast (ad->closure, buf, buflen)) | ||
348 | gcry_mpi_set_bit (ad->round_progress, ad->i); | ||
349 | } | ||
312 | } | 350 | } |
313 | 351 | ||
314 | 352 | ||
@@ -329,6 +367,7 @@ BRANDT_got_message (struct BRANDT_Auction *auction, | |||
329 | /** \todo: cache out of order messages instead of discarding */ | 367 | /** \todo: cache out of order messages instead of discarding */ |
330 | if (ntohl (head->msg_type) != round || ntohl (head->prot_version) != 0) | 368 | if (ntohl (head->msg_type) != round || ntohl (head->prot_version) != 0) |
331 | { | 369 | { |
370 | weprintf ("%d", auction->i); | ||
332 | weprintf ("got unexpected message, ignoring..."); | 371 | weprintf ("got unexpected message, ignoring..."); |
333 | return; | 372 | return; |
334 | } | 373 | } |
@@ -351,6 +390,7 @@ BRANDT_got_message (struct BRANDT_Auction *auction, | |||
351 | return; | 390 | return; |
352 | } | 391 | } |
353 | gcry_mpi_set_bit (auction->round_progress, sender); | 392 | gcry_mpi_set_bit (auction->round_progress, sender); |
393 | DM(auction->round_progress); | ||
354 | 394 | ||
355 | /** \todo: seller_mode and new task for round timing */ | 395 | /** \todo: seller_mode and new task for round timing */ |
356 | advance_round (auction, atype, outcome); | 396 | advance_round (auction, atype, outcome); |