aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Teich <markus.teich@stusta.mhn.de>2016-08-10 14:53:31 +0200
committerMarkus Teich <markus.teich@stusta.mhn.de>2016-08-10 14:53:31 +0200
commita19b226167966952138a9905a78c5b29067717d0 (patch)
treec6f9e9ac44a6bccfb00ae7d6ee7a8821d14f3b59
parentf64f620b074bec1bbcca0a5cbc9331ff8c323605 (diff)
work on public interface implementation
-rw-r--r--brandt.c92
-rw-r--r--brandt.h15
-rw-r--r--internals.h43
3 files changed, 132 insertions, 18 deletions
diff --git a/brandt.c b/brandt.c
index b175c3e..d71e7c9 100644
--- a/brandt.c
+++ b/brandt.c
@@ -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 */
diff --git a/brandt.h b/brandt.h
index ec3c959..318da4f 100644
--- a/brandt.h
+++ b/brandt.h
@@ -97,20 +97,21 @@ BRANDT_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx);
* @param[in] unicast Pointer to the unicast callback function
* @param[in] result Pointer to the result callback function
* @param[in] auction_closure Closure pointer representing the auction. This
- * will not be touched by libbrandt. It is only passed to the callbacks.
- * @param[in] auction_data The auction information data a an opaque data
- * structure. It will be parsed and checked by BRANDT_join().
+ * will not be touched by libbrandt itself. It is only passed to the callbacks.
+ * @param[in] auction_data The auction information data published by the seller.
+ * 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
* structure.
* @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
- * 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 *
BRANDT_join (BRANDT_CbBroadcast broadcast,
BRANDT_CbUnicast unicast,
BRANDT_CbResult result,
- const void *auction_closure,
+ void *auction_closure,
const void *auction_data,
size_t auction_data_len);
/* \todo: where do I specify my bid? */
@@ -149,7 +150,7 @@ BRANDT_join (BRANDT_CbBroadcast broadcast,
* winner and the seller.
* @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
- * 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 *
BRANDT_new (BRANDT_CbBroadcast broadcast,
@@ -157,6 +158,8 @@ BRANDT_new (BRANDT_CbBroadcast broadcast,
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);
diff --git a/internals.h b/internals.h
index ce67934..acb4845 100644
--- a/internals.h
+++ b/internals.h
@@ -29,6 +29,7 @@
enum rounds {
+ msg_join,
msg_init,
msg_bid,
msg_outcome,
@@ -51,33 +52,55 @@ enum outcome_type {
};
+GNUNET_NETWORK_STRUCT_BEGIN
+
/**
* 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
- * stored.
+ * stored. All fields are stored in network byte order.
*
* \todo: align to a multiple of 64bit */
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 */
- 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;
+ uint16_t m GNUNET_PACKED;
/** Outcome type. 0 means private outcome, everything else means public
* outcome. */
- uint16_t outcome_public;
-
- /** The amount of possible prices */
- uint16_t price_range;
-
- /** \todo: time */
+ uint16_t outcome_public GNUNET_PACKED;
};
+GNUNET_NETWORK_STRUCT_END
+
struct BRANDT_Auction {
- struct BRANDT_DescrP *desc; /** pointer to the auction information */
+ /** 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 with an amount of m items being sold. */
+ uint16_t m;
+
+ /** Outcome type. 0 means private outcome, everything else means public
+ * outcome. */
+ uint16_t outcome_public;
void *closure; /** auction closure given by the user */