add start callback and further basic tests

This commit is contained in:
Markus Teich 2016-08-17 17:37:56 +02:00
parent 6eb35ae72f
commit ec43082b1a
5 changed files with 61 additions and 21 deletions

View File

@ -60,8 +60,9 @@ start_auction (void *arg)
struct BRANDT_Auction * struct BRANDT_Auction *
BRANDT_new (BRANDT_CbBroadcast broadcast, BRANDT_new (BRANDT_CbResult result,
BRANDT_CbResult result, BRANDT_CbBroadcast broadcast,
BRANDT_CbStart start,
void *auction_closure, void *auction_closure,
void **auction_desc, void **auction_desc,
size_t *auction_desc_len, size_t *auction_desc_len,
@ -97,7 +98,7 @@ BRANDT_new (BRANDT_CbBroadcast broadcast,
ret->k = num_prices; ret->k = num_prices;
ret->m = m; ret->m = m;
ret->outcome_public = outcome_public; ret->outcome_public = outcome_public;
ret->cur_round = msg_join; ret->cur_round = msg_init;
ret->round_progress = gcry_mpi_new (256); ret->round_progress = gcry_mpi_new (256);
/* we are the seller */ /* we are the seller */
@ -107,9 +108,9 @@ BRANDT_new (BRANDT_CbBroadcast broadcast,
ret->closure = auction_closure; ret->closure = auction_closure;
ret->bcast = broadcast; ret->bcast = broadcast;
ret->result = result; ret->result = result;
ret->start = start;
until_start = GNUNET_TIME_absolute_get_remaining (time_start); until_start = GNUNET_TIME_absolute_get_remaining (time_start);
/* \todo: store returned task somewhere to cancel it on shutdown */
ret->task = GNUNET_SCHEDULER_add_delayed (until_start, ret->task = GNUNET_SCHEDULER_add_delayed (until_start,
&start_auction, &start_auction,
ret); ret);
@ -178,9 +179,9 @@ BRANDT_verify_desc (const void *auction_desc,
struct BRANDT_Auction * struct BRANDT_Auction *
BRANDT_join (BRANDT_CbBroadcast broadcast, BRANDT_join (BRANDT_CbResult result,
BRANDT_CbBroadcast broadcast,
BRANDT_CbUnicast unicast, BRANDT_CbUnicast unicast,
BRANDT_CbResult result,
void *auction_closure, void *auction_closure,
const void *auction_desc, const void *auction_desc,
size_t auction_desc_len, size_t auction_desc_len,
@ -202,7 +203,7 @@ BRANDT_join (BRANDT_CbBroadcast broadcast,
weprintf ("failed to parse auction description blob"); weprintf ("failed to parse auction description blob");
return NULL; return NULL;
} }
ret->cur_round = msg_join; ret->cur_round = msg_init;
ret->round_progress = gcry_mpi_new (256); ret->round_progress = gcry_mpi_new (256);
/* we are the seller */ /* we are the seller */

View File

@ -31,6 +31,22 @@
/** defined in internals.h */ /** defined in internals.h */
struct BRANDT_Auction; struct BRANDT_Auction;
/**
* Functions of this type are called by libbrandt when the auction should be
* started. The application has to announce the ordered list of all bidders to
* them and must return the amount of bidders. After this function is called no
* more new bidders may be accepted by the application. This callback is only
* used if the auction is in seller mode.
*
* @param[in] auction_closure Closure pointer representing the respective
* auction. This is the Pointer given to BRANDT_new().
* @return The amount of bidders participating in the auction.
*/
typedef uint16_t
(*BRANDT_CbStart)(void *auction_closure);
/** /**
* Functions of this type are called by libbrandt to broadcast messages to the * Functions of this type are called by libbrandt to broadcast messages to the
* blackboard of a specific auction. They have to be sent using authenticated * blackboard of a specific auction. They have to be sent using authenticated
@ -70,7 +86,7 @@ typedef int
* Functions of this type are called by libbrandt to report the auction outcome * Functions of this type are called by libbrandt to report the auction outcome
* or malicious/erroneous participants. * or malicious/erroneous participants.
* *
* \todo: export proof of erroneous behaviour. * \todo: export proof of erroneous behaviour / outcome.
* *
* @param[in] auction_closure Closure pointer representing the respective * @param[in] auction_closure Closure pointer representing the respective
* auction. This is the Pointer given to BRANDT_join() / BRANDT_new(). * auction. This is the Pointer given to BRANDT_join() / BRANDT_new().
@ -135,9 +151,9 @@ BRANDT_verify_desc (const void *auction_desc,
* black-box pointer, do NOT dereference/change it or the data it points to! * black-box pointer, do NOT dereference/change it or the data it points to!
*/ */
struct BRANDT_Auction * struct BRANDT_Auction *
BRANDT_join (BRANDT_CbBroadcast broadcast, BRANDT_join (BRANDT_CbResult result,
BRANDT_CbBroadcast broadcast,
BRANDT_CbUnicast unicast, BRANDT_CbUnicast unicast,
BRANDT_CbResult result,
void *auction_closure, void *auction_closure,
const void *auction_desc, const void *auction_desc,
size_t auction_desc_len, size_t auction_desc_len,
@ -182,8 +198,9 @@ BRANDT_join (BRANDT_CbBroadcast broadcast,
* black-box pointer, do NOT dereference/change it or the data it points to! * black-box pointer, do NOT dereference/change it or the data it points to!
*/ */
struct BRANDT_Auction * struct BRANDT_Auction *
BRANDT_new (BRANDT_CbBroadcast broadcast, BRANDT_new (BRANDT_CbResult result,
BRANDT_CbResult result, BRANDT_CbBroadcast broadcast,
BRANDT_CbStart start,
void *auction_closure, void *auction_closure,
void **auction_desc, void **auction_desc,
size_t *auction_desc_len, size_t *auction_desc_len,

View File

@ -29,7 +29,6 @@
enum rounds { enum rounds {
msg_join,
msg_init, msg_init,
msg_bid, msg_bid,
msg_outcome, msg_outcome,
@ -39,21 +38,27 @@ enum rounds {
enum auction_type { enum auction_type {
auction_firstPrice, auction_firstPrice = 0,
auction_mPlusFirstPrice, auction_mPlusFirstPrice = 1,
auction_last auction_last = 2
}; };
enum outcome_type { enum outcome_type {
outcome_private, outcome_private = 0,
outcome_public, outcome_public = 1,
outcome_last outcome_last = 2
}; };
GNUNET_NETWORK_STRUCT_BEGIN GNUNET_NETWORK_STRUCT_BEGIN
struct msg_head {
uint32_t prot_version GNUNET_PACKED;
uint32_t msg_type GNUNET_PACKED;
};
/** /**
* This struct describes an auction and is always linked to a description buffer * This struct describes an auction and is always linked to a description buffer
* of #description_len bytes of arbitrary data where the description of the item * of #description_len bytes of arbitrary data where the description of the item
@ -121,9 +126,10 @@ struct BRANDT_Auction {
void *closure; /** auction closure given by the user */ void *closure; /** auction closure given by the user */
BRANDT_CbResult result; /** result reporting callback */
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_CbStart start; /** start callback */
int seller_mode; /** If 0 we are bidding, selling otherwise */ int seller_mode; /** If 0 we are bidding, selling otherwise */
enum rounds cur_round; /** The round we expect messages from */ enum rounds cur_round; /** The round we expect messages from */

View File

@ -41,6 +41,7 @@ run_new_join (void *arg)
size_t desc_len; size_t desc_len;
ad_seller = BRANDT_new (NULL, ad_seller = BRANDT_new (NULL,
NULL,
NULL, NULL,
NULL, NULL,
&desc, &desc,
@ -75,6 +76,21 @@ run_new_join (void *arg)
return; return;
} }
if (ad_seller->k != ad_bidder->k ||
ad_seller->m != ad_bidder->m ||
ad_seller->outcome_public != ad_bidder->outcome_public ||
ad_seller->time_start.abs_value_us
!= ad_bidder->time_start.abs_value_us ||
ad_seller->time_round.rel_value_us
!= ad_bidder->time_round.rel_value_us ||
!ad_seller->seller_mode ||
ad_bidder->seller_mode)
{
weprintf ("error/mismatch in basic auction data");
*ret = 0;
return;
}
BRANDT_destroy (ad_seller); BRANDT_destroy (ad_seller);
BRANDT_destroy (ad_bidder); BRANDT_destroy (ad_bidder);