stuff
This commit is contained in:
parent
342d3729df
commit
fbc3e92e59
52
brandt.c
52
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
|
void
|
||||||
BRANDT_got_message (struct BRANDT_Auction *auction,
|
BRANDT_got_message (struct BRANDT_Auction *auction,
|
||||||
uint16_t sender,
|
uint16_t sender,
|
||||||
@ -56,8 +91,8 @@ BRANDT_got_message (struct BRANDT_Auction *auction,
|
|||||||
size_t msg_len)
|
size_t msg_len)
|
||||||
{
|
{
|
||||||
uint16_t mtype = *(uint16_t *)msg;
|
uint16_t mtype = *(uint16_t *)msg;
|
||||||
int atype;
|
enum auction_type atype;
|
||||||
int outcome;
|
enum outcome_type outcome;
|
||||||
enum rounds round = auction->cur_round;
|
enum rounds round = auction->cur_round;
|
||||||
|
|
||||||
atype = auction->desc->m > 0 ? auction_mPlusFirstPrice : auction_firstPrice;
|
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 */
|
/** \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] ||
|
if (!handler_in[atype][outcome][round] ||
|
||||||
!handler_in[atype][outcome][round](auction,
|
!handler_in[atype][outcome][round](auction,
|
||||||
msg + sizeof (mtype),
|
msg + sizeof (mtype),
|
||||||
@ -72,6 +114,10 @@ BRANDT_got_message (struct BRANDT_Auction *auction,
|
|||||||
sender))
|
sender))
|
||||||
{
|
{
|
||||||
/** \todo */
|
/** \todo */
|
||||||
weprintf ("wow fail");
|
weprintf ("wow fail in");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
gcry_mpi_set_bit (auction->round_progress, sender);
|
||||||
|
|
||||||
|
advance_round (auction, atype, outcome);
|
||||||
}
|
}
|
||||||
|
4
brandt.h
4
brandt.h
@ -170,6 +170,10 @@ BRANDT_free ();
|
|||||||
/**
|
/**
|
||||||
* Receive a message related to a specific auction.
|
* Receive a message related to a specific auction.
|
||||||
*
|
*
|
||||||
|
* If the message is from a future round and cannot be processed yet, it is
|
||||||
|
* cached in RAM. It will not be stored on disc until it can be used, since the
|
||||||
|
* messages completing the previous round should all arrive relatively soon.
|
||||||
|
*
|
||||||
* @param[in] auction The pointer returned by BRANDT_join() or BRANDT_new() from
|
* @param[in] auction The pointer returned by BRANDT_join() or BRANDT_new() from
|
||||||
* which message @a msg was received.
|
* which message @a msg was received.
|
||||||
* @param[in] sender The id of the sender.
|
* @param[in] sender The id of the sender.
|
||||||
|
@ -79,6 +79,8 @@ struct BRANDT_DescrP {
|
|||||||
struct BRANDT_Auction {
|
struct BRANDT_Auction {
|
||||||
struct BRANDT_DescrP *desc; /** pointer to the auction information */
|
struct BRANDT_DescrP *desc; /** pointer to the auction information */
|
||||||
|
|
||||||
|
void *closure; /** auction closure given by the user */
|
||||||
|
|
||||||
BRANDT_CbBroadcast bcast; /** broadcast callback */
|
BRANDT_CbBroadcast bcast; /** broadcast callback */
|
||||||
BRANDT_CbUnicast ucast; /** unicast callback */
|
BRANDT_CbUnicast ucast; /** unicast callback */
|
||||||
BRANDT_CbResult result; /** result reporting callback */
|
BRANDT_CbResult result; /** result reporting callback */
|
||||||
|
Loading…
Reference in New Issue
Block a user