From 9f0e72f1e8615c9c03222372b2c579471bcce602 Mon Sep 17 00:00:00 2001 From: Markus Teich Date: Wed, 31 Aug 2016 14:37:22 +0200 Subject: temporary dump for discussion --- brandt.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 21 deletions(-) (limited to 'brandt.c') diff --git a/brandt.c b/brandt.c index 4a4dc49..4f5a3f5 100644 --- a/brandt.c +++ b/brandt.c @@ -52,11 +52,35 @@ BRANDT_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx) void BRANDT_bidder_start (struct BRANDT_Auction *auction, + uint16_t i, uint16_t n) { - GNUNET_assert (n > 0); + GNUNET_assert (auction && n > 0 && i < n); auction->n = n; - /** \todo: send first message */ + auction->i = i; + enum auction_type atype; + enum outcome_type outcome; + unsigned char *buf; + size_t buflen; + + atype = auction->m > 0 ? auction_mPlusFirstPrice : auction_firstPrice; + outcome = auction->outcome_public ? outcome_public : outcome_private; + + if (handler_prep[atype][outcome][msg_init]) + handler_prep[atype][outcome][msg_init] (auction); + + if (!handler_out[atype][outcome][msg_init] || + !(buf = handler_out[atype][outcome][msg_init](auction, &buflen))) + { + /** \todo */ + weprintf ("wow fail out"); + return; + } + + weprintf("broadcasting msg_init %p from bidder %d", buf, i); + if (0 == auction->bcast (auction->closure, buf, buflen)) + gcry_mpi_set_bit (auction->round_progress, auction->i); + free (buf); } @@ -65,10 +89,12 @@ seller_start (void *arg) { struct BRANDT_Auction *ad = (struct BRANDT_Auction *)arg; + ad->task = NULL; + if (0 == (ad->n = ad->start (ad->closure))) { weprintf ("no bidders registered for auction"); - ad->result (ad->closure, -1, result_no_bidders, 0); + /** todo: somehow mark auction as done / ready for cleanup */ return; } } @@ -201,7 +227,8 @@ BRANDT_join (BRANDT_CbResult result, const void *auction_desc, size_t auction_desc_len, const void *description, - uint32_t description_len) + uint32_t description_len, + uint16_t bid) { struct BRANDT_Auction *ret = GNUNET_new (struct BRANDT_Auction); @@ -220,6 +247,7 @@ BRANDT_join (BRANDT_CbResult result, } ret->cur_round = msg_init; ret->round_progress = gcry_mpi_new (256); + ret->b = bid; /* we are the seller */ ret->seller_mode = 0; @@ -261,8 +289,8 @@ advance_round (struct BRANDT_Auction *ad, enum auction_type atype, enum outcome_type outcome) { - uint32_t price; - uint16_t winner = -1; + struct BRANDT_Result *res; + uint16_t reslen = 0; unsigned char *buf; size_t buflen; @@ -278,21 +306,25 @@ advance_round (struct BRANDT_Auction *ad, if (msg_last == ++(ad->cur_round)) { /* done with all rounds, determine outcome here */ - /** \todo: unify …_determine_outcome function signature? */ - if (auction_firstPrice == atype && outcome_private == outcome) + if (!handler_res[atype][outcome] || + !(res = handler_res[atype][outcome] (ad, &reslen))) { - 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); + /** \todo */ + weprintf ("wow fail result"); + /** \todo: call result with null pointer here? */ + return; } + + ad->result (ad->closure, res, reslen); + return; + } + + if (handler_prep[atype][outcome][ad->cur_round]) + handler_prep[atype][outcome][ad->cur_round] (ad); + + if (ad->seller_mode) + { + /** \todo: setup round timeout trigger */ return; } @@ -306,9 +338,15 @@ advance_round (struct BRANDT_Auction *ad, /* last message only sent to seller, others are broadcasted */ if (msg_decrypt == ad->cur_round) - ad->ucast (ad->closure, buf, buflen); + { + if (0 == ad->ucast (ad->closure, buf, buflen)) + gcry_mpi_set_bit (ad->round_progress, ad->i); + } else - ad->bcast (ad->closure, buf, buflen); + { + if (0 == ad->bcast (ad->closure, buf, buflen)) + gcry_mpi_set_bit (ad->round_progress, ad->i); + } } @@ -329,6 +367,7 @@ BRANDT_got_message (struct BRANDT_Auction *auction, /** \todo: cache out of order messages instead of discarding */ if (ntohl (head->msg_type) != round || ntohl (head->prot_version) != 0) { + weprintf ("%d", auction->i); weprintf ("got unexpected message, ignoring..."); return; } @@ -351,6 +390,7 @@ BRANDT_got_message (struct BRANDT_Auction *auction, return; } gcry_mpi_set_bit (auction->round_progress, sender); + DM(auction->round_progress); /** \todo: seller_mode and new task for round timing */ advance_round (auction, atype, outcome); -- cgit v1.2.3