diff options
Diffstat (limited to 'brandt.c')
| -rw-r--r-- | brandt.c | 92 | 
1 files changed, 90 insertions, 2 deletions
@@ -50,6 +50,94 @@ BRANDT_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx)  static void +start_auction (void *arg) +{ +	struct BRANDT_Auction *ad = (struct BRANDT_Auction *)arg; + +	/* \todo: broadcast start message to all participants */ +} + + +struct BRANDT_Auction * +BRANDT_new (BRANDT_CbBroadcast broadcast, +            BRANDT_CbResult    result, +            void               *auction_closure, +            void               **auction_data, +            size_t             *auction_data_len, +            struct GNUNET_TIME_Absolute time_start, +            struct GNUNET_TIME_Relative time_round, +            uint16_t           num_prices, +            uint16_t           m, +            int                outcome_public) +{ +	struct BRANDT_Auction *ret; + +	ret = GNUNET_new (struct BRANDT_Auction); + +	ret->time_start = time_start; +	ret->time_round = time_round; + +	ret->k = num_prices; +	ret->m = m; +	ret->outcome_public = outcome_public; + +	/* we are the seller */ +	ret->seller_mode = 1; + +	/* interface with application */ +	ret->closure = auction_closure; +	ret->bcast = broadcast; +	ret->result = result; + +	ret->cur_round = msg_join; +	ret->round_progress = gcry_mpi_new (256); + +	/* \todo: store returned task somewhere to cancel it on shutdown */ +	GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (time_start), +	                              &start_auction, +	                              ret); + +	return ret; +} + + +struct BRANDT_Auction * +BRANDT_join (BRANDT_CbBroadcast broadcast, +             BRANDT_CbUnicast   unicast, +             BRANDT_CbResult    result, +             void               *auction_closure, +             const void         *auction_data, +             size_t             auction_data_len) +{ +	struct BRANDT_Auction *ret; +	struct BRANDT_DescrP *desc = (struct BRANDT_DescrP *)auction_data; + +	ret = GNUNET_new (struct BRANDT_Auction); + +	ret->time_start = GNUNET_TIME_absolute_ntoh(desc->time_start); +	ret->time_round = GNUNET_TIME_relative_ntoh(desc->time_round); + +	ret->k = ntohs(desc->k); +	ret->m = ntohs(desc->m); +	ret->outcome_public = ntohs(desc->outcome_public); + +	/* we are the seller */ +	ret->seller_mode = 0; + +	/* interface with application */ +	ret->closure = auction_closure; +	ret->bcast = broadcast; +	ret->ucast = unicast; +	ret->result = result; + +	ret->cur_round = msg_join; +	ret->round_progress = gcry_mpi_new (256); + +	return ret; +} + + +static void  advance_round (struct BRANDT_Auction *auction, enum auction_type atype, enum outcome_type outcome)  {  	unsigned char *buf; @@ -95,8 +183,8 @@ BRANDT_got_message (struct BRANDT_Auction *auction,  	enum outcome_type         outcome;  	enum rounds round = auction->cur_round; -	atype = auction->desc->m > 0 ? auction_mPlusFirstPrice : auction_firstPrice; -	outcome = auction->desc->outcome_public ? outcome_public : outcome_private; +	atype = auction->m > 0 ? auction_mPlusFirstPrice : auction_firstPrice; +	outcome = auction->outcome_public ? outcome_public : outcome_private;  	/** \todo: cache out of order messages */  | 
