coding style fixes

This commit is contained in:
Markus Teich 2016-09-21 13:50:20 +02:00
parent 658cb96846
commit b31da162a8
6 changed files with 101 additions and 102 deletions

View File

@ -77,7 +77,6 @@ BRANDT_bidder_start (struct BRANDT_Auction *auction,
return; return;
} }
weprintf("broadcasting msg_init %p from bidder %d", buf, i);
auction->bcast (auction->closure, buf, buflen); auction->bcast (auction->closure, buf, buflen);
gcry_mpi_set_bit (auction->round_progress, auction->i); gcry_mpi_set_bit (auction->round_progress, auction->i);
free (buf); free (buf);
@ -88,8 +87,8 @@ static void
seller_start (void *arg) seller_start (void *arg)
{ {
struct BRANDT_Auction *ad = (struct BRANDT_Auction *)arg; struct BRANDT_Auction *ad = (struct BRANDT_Auction *)arg;
enum auction_type atype; enum auction_type atype;
enum outcome_type outcome; enum outcome_type outcome;
ad->task = NULL; ad->task = NULL;
@ -302,7 +301,7 @@ report_outcome (struct BRANDT_Auction *ad,
uint16_t reslen = 0; uint16_t reslen = 0;
if (!handler_res[atype][outcome] || if (!handler_res[atype][outcome] ||
!(res = handler_res[atype][outcome] (ad, &reslen))) !(res = handler_res[atype][outcome] (ad, &reslen)))
ad->result (ad->closure, NULL, 0); ad->result (ad->closure, NULL, 0);
else else
ad->result (ad->closure, res, reslen); ad->result (ad->closure, res, reslen);
@ -341,7 +340,7 @@ advance_round (struct BRANDT_Auction *ad,
{ {
/* all bidders msg_decrypt received, broadcast combined msg_decrypt */ /* all bidders msg_decrypt received, broadcast combined msg_decrypt */
if (!handler_out[atype][outcome][ad->cur_round] || if (!handler_out[atype][outcome][ad->cur_round] ||
!(buf = handler_out[atype][outcome][ad->cur_round](ad, &buflen))) !(buf = handler_out[atype][outcome][ad->cur_round](ad, &buflen)))
{ {
weprintf ("failed to create msg %d buffer as seller", weprintf ("failed to create msg %d buffer as seller",
ad->cur_round); ad->cur_round);
@ -371,7 +370,7 @@ advance_round (struct BRANDT_Auction *ad,
/* create next message buffer */ /* create next message buffer */
if (!handler_out[atype][outcome][ad->cur_round] || if (!handler_out[atype][outcome][ad->cur_round] ||
!(buf = handler_out[atype][outcome][ad->cur_round](ad, &buflen))) !(buf = handler_out[atype][outcome][ad->cur_round](ad, &buflen)))
{ {
weprintf ("failed to create msg %d buffer as bidder", ad->cur_round); weprintf ("failed to create msg %d buffer as bidder", ad->cur_round);
return; return;
@ -404,7 +403,6 @@ BRANDT_got_message (struct BRANDT_Auction *auction,
/** \todo: cache out of order messages instead of discarding */ /** \todo: cache out of order messages instead of discarding */
if (ntohl (head->msg_type) != round || ntohl (head->prot_version) != 0) if (ntohl (head->msg_type) != round || ntohl (head->prot_version) != 0)
{ {
weprintf ("%d", auction->i);
weprintf ("got unexpected message, ignoring..."); weprintf ("got unexpected message, ignoring...");
return; return;
} }
@ -427,7 +425,6 @@ BRANDT_got_message (struct BRANDT_Auction *auction,
return; return;
} }
gcry_mpi_set_bit (auction->round_progress, sender); gcry_mpi_set_bit (auction->round_progress, sender);
DM(auction->round_progress);
advance_round (auction, atype, outcome); advance_round (auction, atype, outcome);
} }

View File

@ -29,8 +29,7 @@
#include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_util_lib.h>
/** Enumeration of all possible status reports for a single bidder */ /** Enumeration of all possible status reports for a single bidder */
enum BRANDT_BidderStatus enum BRANDT_BidderStatus {
{
BRANDT_bidder_won, BRANDT_bidder_won,
}; };
@ -41,8 +40,7 @@ struct BRANDT_Auction;
* An array of this struct is given to the application by the BRANDT_CbResult() * An array of this struct is given to the application by the BRANDT_CbResult()
* callback. One instance represents the status of a single bidder. * callback. One instance represents the status of a single bidder.
*/ */
struct BRANDT_Result struct BRANDT_Result {
{
/** Id of the bidder this instance refers to */ /** Id of the bidder this instance refers to */
uint16_t bidder; uint16_t bidder;

View File

@ -816,12 +816,12 @@ quit:
void void
fp_pub_prep_outcome (struct BRANDT_Auction *ad) fp_pub_prep_outcome (struct BRANDT_Auction *ad)
{ {
gcry_mpi_t coeff = gcry_mpi_copy (GCRYMPI_CONST_ONE); gcry_mpi_t coeff = gcry_mpi_copy (GCRYMPI_CONST_ONE);
gcry_mpi_point_t tmp = gcry_mpi_point_new (0); gcry_mpi_point_t tmp = gcry_mpi_point_new (0);
gcry_mpi_point_t *tlta1; gcry_mpi_point_t *tlta1;
gcry_mpi_point_t *tltb1; gcry_mpi_point_t *tltb1;
gcry_mpi_point_t **tlta2; gcry_mpi_point_t **tlta2;
gcry_mpi_point_t **tltb2; gcry_mpi_point_t **tltb2;
ad->gamma2 = smc_init2 (ad->n, ad->k); ad->gamma2 = smc_init2 (ad->n, ad->k);
brandt_assert (ad->gamma2); brandt_assert (ad->gamma2);
@ -1045,7 +1045,7 @@ quit:
void void
fp_pub_prep_decryption (struct BRANDT_Auction *ad) fp_pub_prep_decryption (struct BRANDT_Auction *ad)
{ {
gcry_mpi_point_t tmp = gcry_mpi_point_new (0); gcry_mpi_point_t tmp = gcry_mpi_point_new (0);
ad->phi2 = smc_init2 (ad->n, ad->k); ad->phi2 = smc_init2 (ad->n, ad->k);
brandt_assert (ad->phi2); brandt_assert (ad->phi2);
@ -1162,15 +1162,16 @@ quit:
} }
struct BRANDT_Result *fp_pub_determine_outcome (struct BRANDT_Auction *ad, struct BRANDT_Result *
uint16_t *len) fp_pub_determine_outcome (struct BRANDT_Auction *ad,
uint16_t *len)
{ {
struct BRANDT_Result *ret; struct BRANDT_Result *ret;
int32_t price = -1; int32_t price = -1;
int32_t winner = -1; int32_t winner = -1;
int dlogi = -1; int dlogi = -1;
gcry_mpi_point_t sum_gamma = gcry_mpi_point_new (0); gcry_mpi_point_t sum_gamma = gcry_mpi_point_new (0);
gcry_mpi_point_t sum_phi = gcry_mpi_point_new (0); gcry_mpi_point_t sum_phi = gcry_mpi_point_new (0);
brandt_assert (ad); brandt_assert (ad);
@ -1208,7 +1209,7 @@ struct BRANDT_Result *fp_pub_determine_outcome (struct BRANDT_Auction *ad,
if (-1 == winner || -1 == price) if (-1 == winner || -1 == price)
return NULL; return NULL;
ret = GNUNET_new(struct BRANDT_Result); ret = GNUNET_new (struct BRANDT_Result);
ret->bidder = winner; ret->bidder = winner;
ret->price = price; ret->price = price;
ret->status = BRANDT_bidder_won; ret->status = BRANDT_bidder_won;
@ -1221,14 +1222,14 @@ struct BRANDT_Result *fp_pub_determine_outcome (struct BRANDT_Auction *ad,
void void
fp_priv_prep_outcome (struct BRANDT_Auction *ad) fp_priv_prep_outcome (struct BRANDT_Auction *ad)
{ {
gcry_mpi_point_t tmpa = gcry_mpi_point_new (0); gcry_mpi_point_t tmpa = gcry_mpi_point_new (0);
gcry_mpi_point_t tmpb = gcry_mpi_point_new (0); gcry_mpi_point_t tmpb = gcry_mpi_point_new (0);
gcry_mpi_point_t *tlta1; gcry_mpi_point_t *tlta1;
gcry_mpi_point_t *tltb1; gcry_mpi_point_t *tltb1;
gcry_mpi_point_t **tlta2; gcry_mpi_point_t **tlta2;
gcry_mpi_point_t **tltb2; gcry_mpi_point_t **tltb2;
gcry_mpi_point_t **tlta3; gcry_mpi_point_t **tlta3;
gcry_mpi_point_t **tltb3; gcry_mpi_point_t **tltb3;
ad->gamma3 = smc_init3 (ad->n, ad->n, ad->k); ad->gamma3 = smc_init3 (ad->n, ad->n, ad->k);
brandt_assert (ad->gamma3); brandt_assert (ad->gamma3);
@ -1452,7 +1453,7 @@ quit:
void void
fp_priv_prep_decryption (struct BRANDT_Auction *ad) fp_priv_prep_decryption (struct BRANDT_Auction *ad)
{ {
gcry_mpi_point_t tmp = gcry_mpi_point_new (0); gcry_mpi_point_t tmp = gcry_mpi_point_new (0);
ad->phi3 = smc_init3 (ad->n, ad->n, ad->k); ad->phi3 = smc_init3 (ad->n, ad->n, ad->k);
brandt_assert (ad->phi3); brandt_assert (ad->phi3);
@ -1682,10 +1683,10 @@ fp_priv_recv_decryption_bidder (struct BRANDT_Auction *ad,
ec_point_parse (phi, (struct ec_mpi *)cur); ec_point_parse (phi, (struct ec_mpi *)cur);
proof2 = (struct proof_2dle *)(cur + sizeof (struct ec_mpi)); proof2 = (struct proof_2dle *)(cur + sizeof (struct ec_mpi));
if (smc_zkp_2dle_check (phi, if (smc_zkp_2dle_check (phi,
ad->y[h], ad->y[h],
ad->phi3[h][i][j], ad->phi3[h][i][j],
ec_gen, ec_gen,
proof2)) proof2))
{ {
weprintf ("wrong zkp2 for phi, y received from seller"); weprintf ("wrong zkp2 for phi, y received from seller");
goto quit; goto quit;
@ -1717,8 +1718,9 @@ fp_priv_recv_decryption (struct BRANDT_Auction *ad,
} }
struct BRANDT_Result *fp_priv_determine_outcome (struct BRANDT_Auction *ad, struct BRANDT_Result *
uint16_t *len) fp_priv_determine_outcome (struct BRANDT_Auction *ad,
uint16_t *len)
{ {
struct BRANDT_Result *ret; struct BRANDT_Result *ret;
int32_t price = -1; int32_t price = -1;
@ -1762,7 +1764,7 @@ struct BRANDT_Result *fp_priv_determine_outcome (struct BRANDT_Auction *ad,
if (-1 == winner || -1 == price) if (-1 == winner || -1 == price)
return NULL; return NULL;
ret = GNUNET_new(struct BRANDT_Result); ret = GNUNET_new (struct BRANDT_Result);
ret->bidder = winner; ret->bidder = winner;
ret->price = price; ret->price = price;
ret->status = BRANDT_bidder_won; ret->status = BRANDT_bidder_won;

View File

@ -176,14 +176,14 @@ typedef void
typedef int typedef int
(*MsgIn)(struct BRANDT_Auction *ad, (*MsgIn)(struct BRANDT_Auction *ad,
const unsigned char *buf, const unsigned char *buf,
size_t buflen, size_t buflen,
uint16_t sender); uint16_t sender);
typedef unsigned char * typedef unsigned char *
(*MsgOut)(struct BRANDT_Auction *ad, (*MsgOut)(struct BRANDT_Auction *ad,
size_t *buflen); size_t *buflen);
/** /**
@ -317,9 +317,9 @@ static const MsgOut handler_out[auction_last][outcome_last][msg_last] = {
* of 0 means a private outcome, while a value of 1 means public outcome. * of 0 means a private outcome, while a value of 1 means public outcome.
*/ */
static const Result handler_res[auction_last][outcome_last] = { static const Result handler_res[auction_last][outcome_last] = {
[auction_firstPrice] = { [auction_firstPrice] = {
[outcome_private] = &fp_priv_determine_outcome, [outcome_private] = &fp_priv_determine_outcome,
[outcome_public] = &fp_pub_determine_outcome, [outcome_public] = &fp_pub_determine_outcome,
}, },
// [auction_mPlusFirstPrice] = { // [auction_mPlusFirstPrice] = {
// [outcome_private] = , // [outcome_private] = ,

View File

@ -30,19 +30,18 @@
#include "util.h" #include "util.h"
struct msg struct msg {
{ uint16_t sender;
uint16_t sender; uint16_t receiver;
uint16_t receiver; void *buf;
void *buf; size_t buf_len;
size_t buf_len;
}; };
static uint16_t *id; static uint16_t *id;
static struct BRANDT_Auction **ad; static struct BRANDT_Auction **ad;
static uint16_t bidders = 3; static uint16_t bidders = 3;
static uint16_t prizes = 8; static uint16_t prizes = 8;
static void static void
@ -50,7 +49,7 @@ bidder_start (void *arg)
{ {
uint16_t i = *(uint16_t *)arg; uint16_t i = *(uint16_t *)arg;
weprintf("starting bidder %d", i); weprintf ("starting bidder %d", i);
BRANDT_bidder_start (ad[i], i, bidders); BRANDT_bidder_start (ad[i], i, bidders);
} }
@ -58,10 +57,11 @@ bidder_start (void *arg)
static void static void
transfer_message (void *arg) transfer_message (void *arg)
{ {
struct msg *m = (struct msg *)arg; struct msg *m = (struct msg *)arg;
struct msg_head *h = (struct msg_head *)m->buf; struct msg_head *h = (struct msg_head *)m->buf;
weprintf("xfer msg %d %x from %d to %d", ntohl(h->msg_type), arg, m->sender, m->receiver); weprintf ("xfer msg %d %x from %d to %d", ntohl (
h->msg_type), arg, m->sender, m->receiver);
BRANDT_got_message (ad[m->receiver], m->sender, m->buf, m->buf_len); BRANDT_got_message (ad[m->receiver], m->sender, m->buf, m->buf_len);
free (arg); free (arg);
} }
@ -71,6 +71,7 @@ static uint16_t
cb_start (void *auction_closure) cb_start (void *auction_closure)
{ {
uint16_t *s = (uint16_t *)auction_closure; uint16_t *s = (uint16_t *)auction_closure;
if (!s || bidders != *s) if (!s || bidders != *s)
{ {
weprintf ("start callback called from bidder"); weprintf ("start callback called from bidder");
@ -89,7 +90,7 @@ cb_broadcast (void *auction_closure,
const void *msg, const void *msg,
size_t msg_len) size_t msg_len)
{ {
uint16_t *s = (uint16_t *)auction_closure; uint16_t *s = (uint16_t *)auction_closure;
struct msg *m; struct msg *m;
for (uint16_t i = 0; i <= bidders; i++) for (uint16_t i = 0; i <= bidders; i++)
@ -113,7 +114,7 @@ cb_unicast (void *auction_closure,
const void *msg, const void *msg,
size_t msg_len) size_t msg_len)
{ {
uint16_t *s = (uint16_t *)auction_closure; uint16_t *s = (uint16_t *)auction_closure;
struct msg *m; struct msg *m;
m = GNUNET_new (struct msg); m = GNUNET_new (struct msg);
@ -139,37 +140,38 @@ cb_result (void *auction_closure,
weprintf ("result determined by agent %d: none", *s); weprintf ("result determined by agent %d: none", *s);
for (uint16_t i = 0; i < results_len; i++) for (uint16_t i = 0; i < results_len; i++)
weprintf ("result determined by agent %d: bidder %d got status %d with price %d", weprintf (
*s, "result determined by agent %d: bidder %d got status %d with price %d",
results[i].bidder, *s,
results[i].status, results[i].bidder,
results[i].price); results[i].status,
results[i].price);
} }
static void static void
run_new_join (void *arg) run_new_join (void *arg)
{ {
int *ret = arg; int *ret = arg;
const char description[] = "test description for test_new_join"; const char description[] = "test description for test_new_join";
void *desc; void *desc;
size_t desc_len; size_t desc_len;
ad = GNUNET_new_array (bidders + 1, struct BRANDT_Auction *); ad = GNUNET_new_array (bidders + 1, struct BRANDT_Auction *);
ad[bidders] = BRANDT_new (&cb_result, ad[bidders] = BRANDT_new (&cb_result,
&cb_broadcast, &cb_broadcast,
&cb_start, &cb_start,
&id[bidders], &id[bidders],
&desc, &desc,
&desc_len, &desc_len,
description, description,
sizeof (description), sizeof (description),
GNUNET_TIME_absolute_get (), GNUNET_TIME_absolute_get (),
GNUNET_TIME_UNIT_MINUTES, GNUNET_TIME_UNIT_MINUTES,
prizes, /* amount of possible prizes */ prizes, /* amount of possible prizes */
0, /* m */ 0, /* m */
1); /* outcome public */ 1); /* outcome public */
if (!ad[bidders]) if (!ad[bidders])
{ {
weprintf ("BRANDT_new() failed."); weprintf ("BRANDT_new() failed.");
@ -179,14 +181,14 @@ run_new_join (void *arg)
for (uint16_t i = 0; i < bidders; i++) for (uint16_t i = 0; i < bidders; i++)
{ {
ad[i] = BRANDT_join (&cb_result, ad[i] = BRANDT_join (&cb_result,
&cb_broadcast, &cb_broadcast,
&cb_unicast, &cb_unicast,
&id[i], &id[i],
desc, desc,
desc_len, desc_len,
description, description,
sizeof (description), sizeof (description),
3); /* bid */ 3); /* bid */
if (!ad[i]) if (!ad[i])
{ {
weprintf ("BRANDT_join() failed."); weprintf ("BRANDT_join() failed.");
@ -194,14 +196,14 @@ run_new_join (void *arg)
} }
if (ad[bidders]->k != ad[i]->k || if (ad[bidders]->k != ad[i]->k ||
ad[bidders]->m != ad[i]->m || ad[bidders]->m != ad[i]->m ||
ad[bidders]->outcome_public != ad[i]->outcome_public || ad[bidders]->outcome_public != ad[i]->outcome_public ||
ad[bidders]->time_start.abs_value_us ad[bidders]->time_start.abs_value_us
!= ad[i]->time_start.abs_value_us || != ad[i]->time_start.abs_value_us ||
ad[bidders]->time_round.rel_value_us ad[bidders]->time_round.rel_value_us
!= ad[i]->time_round.rel_value_us || != ad[i]->time_round.rel_value_us ||
!ad[bidders]->seller_mode || /* todo: split out */ !ad[bidders]->seller_mode || /* todo: split out */
ad[i]->seller_mode) ad[i]->seller_mode)
{ {
weprintf ("error/mismatch in basic auction data"); weprintf ("error/mismatch in basic auction data");
_exit (1); _exit (1);

View File

@ -199,7 +199,7 @@ test_setup_auction_data ()
/** /**
* compute round @a index of the protocol specified by @a type and @a oc * compute round @a index of the protocol specified by @a type and @a oc
* *
* @param[in] type auction type * @param[in] type auction type
* @param[in] oc outcome type * @param[in] oc outcome type
* @param[in] index round index * @param[in] index round index
@ -310,7 +310,7 @@ test_all_auctions ()
for (size_t oc = 0; oc < outcome_last; oc++) for (size_t oc = 0; oc < outcome_last; oc++)
{ {
if (!test_setup_auction_data() || !test_auction (atype, oc)) if (!test_setup_auction_data () || !test_auction (atype, oc))
{ {
cleanup_auction_data (); cleanup_auction_data ();
return 0; return 0;