work on public interface implementation

This commit is contained in:
Markus Teich 2016-08-10 14:53:31 +02:00
parent f64f620b07
commit a19b226167
3 changed files with 134 additions and 20 deletions

View File

@ -49,6 +49,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 static void
advance_round (struct BRANDT_Auction *auction, enum auction_type atype, enum outcome_type outcome) advance_round (struct BRANDT_Auction *auction, enum auction_type atype, enum outcome_type outcome)
{ {
@ -95,8 +183,8 @@ BRANDT_got_message (struct BRANDT_Auction *auction,
enum outcome_type 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->m > 0 ? auction_mPlusFirstPrice : auction_firstPrice;
outcome = auction->desc->outcome_public ? outcome_public : outcome_private; outcome = auction->outcome_public ? outcome_public : outcome_private;
/** \todo: cache out of order messages */ /** \todo: cache out of order messages */

View File

@ -97,20 +97,21 @@ BRANDT_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx);
* @param[in] unicast Pointer to the unicast callback function * @param[in] unicast Pointer to the unicast callback function
* @param[in] result Pointer to the result callback function * @param[in] result Pointer to the result callback function
* @param[in] auction_closure Closure pointer representing the auction. This * @param[in] auction_closure Closure pointer representing the auction. This
* will not be touched by libbrandt. It is only passed to the callbacks. * will not be touched by libbrandt itself. It is only passed to the callbacks.
* @param[in] auction_data The auction information data a an opaque data * @param[in] auction_data The auction information data published by the seller.
* structure. It will be parsed and checked by BRANDT_join(). * This is an opaque data structure. It will be parsed and checked by
* BRANDT_join().
* @param[in] auction_data_len The length in bytes of the @a auction_data * @param[in] auction_data_len The length in bytes of the @a auction_data
* structure. * structure.
* @return A pointer, which should only be remembered and passed to * @return A pointer, which should only be remembered and passed to
* libbrandt functions when the client needs to refer to this auction. This is a * libbrandt functions when the client needs to refer to this auction. This is a
* black-box pointer, do NOT access/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_CbBroadcast broadcast,
BRANDT_CbUnicast unicast, BRANDT_CbUnicast unicast,
BRANDT_CbResult result, BRANDT_CbResult result,
const void *auction_closure, void *auction_closure,
const void *auction_data, const void *auction_data,
size_t auction_data_len); size_t auction_data_len);
/* \todo: where do I specify my bid? */ /* \todo: where do I specify my bid? */
@ -149,7 +150,7 @@ BRANDT_join (BRANDT_CbBroadcast broadcast,
* winner and the seller. * winner and the seller.
* @return A pointer, which should only be remembered and passed to * @return A pointer, which should only be remembered and passed to
* libbrandt functions when the client needs to refer to this auction. This is a * libbrandt functions when the client needs to refer to this auction. This is a
* black-box pointer, do NOT access/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_CbBroadcast broadcast,
@ -157,6 +158,8 @@ BRANDT_new (BRANDT_CbBroadcast broadcast,
void *auction_closure, void *auction_closure,
void **auction_data, void **auction_data,
size_t *auction_data_len, size_t *auction_data_len,
struct GNUNET_TIME_Absolute time_start,
struct GNUNET_TIME_Relative time_round,
uint16_t num_prices, uint16_t num_prices,
uint16_t m, uint16_t m,
int outcome_public); int outcome_public);

View File

@ -29,6 +29,7 @@
enum rounds { enum rounds {
msg_join,
msg_init, msg_init,
msg_bid, msg_bid,
msg_outcome, msg_outcome,
@ -51,15 +52,47 @@ enum outcome_type {
}; };
GNUNET_NETWORK_STRUCT_BEGIN
/** /**
* This struct describes an auction and has to be followed by #description_len * This struct describes an auction and has to be followed by #description_len
* bytes of arbitrary data where the description of the item to be sold is * bytes of arbitrary data where the description of the item to be sold is
* stored. * stored. All fields are stored in network byte order.
* *
* \todo: align to a multiple of 64bit */ * \todo: align to a multiple of 64bit */
struct BRANDT_DescrP { struct BRANDT_DescrP {
/** Starting time of the auction. Bidders have to join the auction via
* BRANDT_join until this time */
struct GNUNET_TIME_AbsoluteNBO time_start;
/** The maximum duration the participants have to complete each round. */
struct GNUNET_TIME_RelativeNBO time_round;
/** The length of the description in bytes directly following this struct */ /** The length of the description in bytes directly following this struct */
uint32_t description_len; uint32_t description_len GNUNET_PACKED;
/** The amount of possible prices */
uint16_t k GNUNET_PACKED;
/** Auction type. 0 means first price Auction, >= 0 means M+1st price
* auction with an amount of m items being sold. */
uint16_t m GNUNET_PACKED;
/** Outcome type. 0 means private outcome, everything else means public
* outcome. */
uint16_t outcome_public GNUNET_PACKED;
};
GNUNET_NETWORK_STRUCT_END
struct BRANDT_Auction {
/** Starting time of the auction. Bidders have to join the auction via
* BRANDT_join until this time */
struct GNUNET_TIME_Absolute time_start;
/** The maximum duration the participants have to complete each round. */
struct GNUNET_TIME_Relative time_round;
/** Auction type. 0 means first price Auction, >= 0 means M+1st price /** Auction type. 0 means first price Auction, >= 0 means M+1st price
* auction with an amount of m items being sold. */ * auction with an amount of m items being sold. */
@ -69,16 +102,6 @@ struct BRANDT_DescrP {
* outcome. */ * outcome. */
uint16_t outcome_public; uint16_t outcome_public;
/** The amount of possible prices */
uint16_t price_range;
/** \todo: time */
};
struct BRANDT_Auction {
struct BRANDT_DescrP *desc; /** pointer to the auction information */
void *closure; /** auction closure given by the user */ void *closure; /** auction closure given by the user */
BRANDT_CbBroadcast bcast; /** broadcast callback */ BRANDT_CbBroadcast bcast; /** broadcast callback */