diff options
-rw-r--r-- | brandt.c | 92 | ||||
-rw-r--r-- | brandt.h | 15 | ||||
-rw-r--r-- | internals.h | 43 |
3 files changed, 132 insertions, 18 deletions
@@ -50,6 +50,94 @@ BRANDT_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx) | |||
50 | 50 | ||
51 | 51 | ||
52 | static void | 52 | static void |
53 | start_auction (void *arg) | ||
54 | { | ||
55 | struct BRANDT_Auction *ad = (struct BRANDT_Auction *)arg; | ||
56 | |||
57 | /* \todo: broadcast start message to all participants */ | ||
58 | } | ||
59 | |||
60 | |||
61 | struct BRANDT_Auction * | ||
62 | BRANDT_new (BRANDT_CbBroadcast broadcast, | ||
63 | BRANDT_CbResult result, | ||
64 | void *auction_closure, | ||
65 | void **auction_data, | ||
66 | size_t *auction_data_len, | ||
67 | struct GNUNET_TIME_Absolute time_start, | ||
68 | struct GNUNET_TIME_Relative time_round, | ||
69 | uint16_t num_prices, | ||
70 | uint16_t m, | ||
71 | int outcome_public) | ||
72 | { | ||
73 | struct BRANDT_Auction *ret; | ||
74 | |||
75 | ret = GNUNET_new (struct BRANDT_Auction); | ||
76 | |||
77 | ret->time_start = time_start; | ||
78 | ret->time_round = time_round; | ||
79 | |||
80 | ret->k = num_prices; | ||
81 | ret->m = m; | ||
82 | ret->outcome_public = outcome_public; | ||
83 | |||
84 | /* we are the seller */ | ||
85 | ret->seller_mode = 1; | ||
86 | |||
87 | /* interface with application */ | ||
88 | ret->closure = auction_closure; | ||
89 | ret->bcast = broadcast; | ||
90 | ret->result = result; | ||
91 | |||
92 | ret->cur_round = msg_join; | ||
93 | ret->round_progress = gcry_mpi_new (256); | ||
94 | |||
95 | /* \todo: store returned task somewhere to cancel it on shutdown */ | ||
96 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (time_start), | ||
97 | &start_auction, | ||
98 | ret); | ||
99 | |||
100 | return ret; | ||
101 | } | ||
102 | |||
103 | |||
104 | struct BRANDT_Auction * | ||
105 | BRANDT_join (BRANDT_CbBroadcast broadcast, | ||
106 | BRANDT_CbUnicast unicast, | ||
107 | BRANDT_CbResult result, | ||
108 | void *auction_closure, | ||
109 | const void *auction_data, | ||
110 | size_t auction_data_len) | ||
111 | { | ||
112 | struct BRANDT_Auction *ret; | ||
113 | struct BRANDT_DescrP *desc = (struct BRANDT_DescrP *)auction_data; | ||
114 | |||
115 | ret = GNUNET_new (struct BRANDT_Auction); | ||
116 | |||
117 | ret->time_start = GNUNET_TIME_absolute_ntoh(desc->time_start); | ||
118 | ret->time_round = GNUNET_TIME_relative_ntoh(desc->time_round); | ||
119 | |||
120 | ret->k = ntohs(desc->k); | ||
121 | ret->m = ntohs(desc->m); | ||
122 | ret->outcome_public = ntohs(desc->outcome_public); | ||
123 | |||
124 | /* we are the seller */ | ||
125 | ret->seller_mode = 0; | ||
126 | |||
127 | /* interface with application */ | ||
128 | ret->closure = auction_closure; | ||
129 | ret->bcast = broadcast; | ||
130 | ret->ucast = unicast; | ||
131 | ret->result = result; | ||
132 | |||
133 | ret->cur_round = msg_join; | ||
134 | ret->round_progress = gcry_mpi_new (256); | ||
135 | |||
136 | return ret; | ||
137 | } | ||
138 | |||
139 | |||
140 | static void | ||
53 | advance_round (struct BRANDT_Auction *auction, enum auction_type atype, enum outcome_type outcome) | 141 | advance_round (struct BRANDT_Auction *auction, enum auction_type atype, enum outcome_type outcome) |
54 | { | 142 | { |
55 | unsigned char *buf; | 143 | unsigned char *buf; |
@@ -95,8 +183,8 @@ BRANDT_got_message (struct BRANDT_Auction *auction, | |||
95 | enum outcome_type outcome; | 183 | enum outcome_type outcome; |
96 | enum rounds round = auction->cur_round; | 184 | enum rounds round = auction->cur_round; |
97 | 185 | ||
98 | atype = auction->desc->m > 0 ? auction_mPlusFirstPrice : auction_firstPrice; | 186 | atype = auction->m > 0 ? auction_mPlusFirstPrice : auction_firstPrice; |
99 | outcome = auction->desc->outcome_public ? outcome_public : outcome_private; | 187 | outcome = auction->outcome_public ? outcome_public : outcome_private; |
100 | 188 | ||
101 | /** \todo: cache out of order messages */ | 189 | /** \todo: cache out of order messages */ |
102 | 190 | ||
@@ -97,20 +97,21 @@ BRANDT_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx); | |||
97 | * @param[in] unicast Pointer to the unicast callback function | 97 | * @param[in] unicast Pointer to the unicast callback function |
98 | * @param[in] result Pointer to the result callback function | 98 | * @param[in] result Pointer to the result callback function |
99 | * @param[in] auction_closure Closure pointer representing the auction. This | 99 | * @param[in] auction_closure Closure pointer representing the auction. This |
100 | * will not be touched by libbrandt. It is only passed to the callbacks. | 100 | * will not be touched by libbrandt itself. It is only passed to the callbacks. |
101 | * @param[in] auction_data The auction information data a an opaque data | 101 | * @param[in] auction_data The auction information data published by the seller. |
102 | * structure. It will be parsed and checked by BRANDT_join(). | 102 | * This is an opaque data structure. It will be parsed and checked by |
103 | * BRANDT_join(). | ||
103 | * @param[in] auction_data_len The length in bytes of the @a auction_data | 104 | * @param[in] auction_data_len The length in bytes of the @a auction_data |
104 | * structure. | 105 | * structure. |
105 | * @return A pointer, which should only be remembered and passed to | 106 | * @return A pointer, which should only be remembered and passed to |
106 | * libbrandt functions when the client needs to refer to this auction. This is a | 107 | * libbrandt functions when the client needs to refer to this auction. This is a |
107 | * black-box pointer, do NOT access/change it or the data it points to! | 108 | * black-box pointer, do NOT dereference/change it or the data it points to! |
108 | */ | 109 | */ |
109 | struct BRANDT_Auction * | 110 | struct BRANDT_Auction * |
110 | BRANDT_join (BRANDT_CbBroadcast broadcast, | 111 | BRANDT_join (BRANDT_CbBroadcast broadcast, |
111 | BRANDT_CbUnicast unicast, | 112 | BRANDT_CbUnicast unicast, |
112 | BRANDT_CbResult result, | 113 | BRANDT_CbResult result, |
113 | const void *auction_closure, | 114 | void *auction_closure, |
114 | const void *auction_data, | 115 | const void *auction_data, |
115 | size_t auction_data_len); | 116 | size_t auction_data_len); |
116 | /* \todo: where do I specify my bid? */ | 117 | /* \todo: where do I specify my bid? */ |
@@ -149,7 +150,7 @@ BRANDT_join (BRANDT_CbBroadcast broadcast, | |||
149 | * winner and the seller. | 150 | * winner and the seller. |
150 | * @return A pointer, which should only be remembered and passed to | 151 | * @return A pointer, which should only be remembered and passed to |
151 | * libbrandt functions when the client needs to refer to this auction. This is a | 152 | * libbrandt functions when the client needs to refer to this auction. This is a |
152 | * black-box pointer, do NOT access/change it or the data it points to! | 153 | * black-box pointer, do NOT dereference/change it or the data it points to! |
153 | */ | 154 | */ |
154 | struct BRANDT_Auction * | 155 | struct BRANDT_Auction * |
155 | BRANDT_new (BRANDT_CbBroadcast broadcast, | 156 | BRANDT_new (BRANDT_CbBroadcast broadcast, |
@@ -157,6 +158,8 @@ BRANDT_new (BRANDT_CbBroadcast broadcast, | |||
157 | void *auction_closure, | 158 | void *auction_closure, |
158 | void **auction_data, | 159 | void **auction_data, |
159 | size_t *auction_data_len, | 160 | size_t *auction_data_len, |
161 | struct GNUNET_TIME_Absolute time_start, | ||
162 | struct GNUNET_TIME_Relative time_round, | ||
160 | uint16_t num_prices, | 163 | uint16_t num_prices, |
161 | uint16_t m, | 164 | uint16_t m, |
162 | int outcome_public); | 165 | 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 @@ | |||
29 | 29 | ||
30 | 30 | ||
31 | enum rounds { | 31 | enum rounds { |
32 | msg_join, | ||
32 | msg_init, | 33 | msg_init, |
33 | msg_bid, | 34 | msg_bid, |
34 | msg_outcome, | 35 | msg_outcome, |
@@ -51,33 +52,55 @@ enum outcome_type { | |||
51 | }; | 52 | }; |
52 | 53 | ||
53 | 54 | ||
55 | GNUNET_NETWORK_STRUCT_BEGIN | ||
56 | |||
54 | /** | 57 | /** |
55 | * This struct describes an auction and has to be followed by #description_len | 58 | * This struct describes an auction and has to be followed by #description_len |
56 | * bytes of arbitrary data where the description of the item to be sold is | 59 | * bytes of arbitrary data where the description of the item to be sold is |
57 | * stored. | 60 | * stored. All fields are stored in network byte order. |
58 | * | 61 | * |
59 | * \todo: align to a multiple of 64bit */ | 62 | * \todo: align to a multiple of 64bit */ |
60 | struct BRANDT_DescrP { | 63 | struct BRANDT_DescrP { |
64 | /** Starting time of the auction. Bidders have to join the auction via | ||
65 | * BRANDT_join until this time */ | ||
66 | struct GNUNET_TIME_AbsoluteNBO time_start; | ||
67 | |||
68 | /** The maximum duration the participants have to complete each round. */ | ||
69 | struct GNUNET_TIME_RelativeNBO time_round; | ||
70 | |||
61 | /** The length of the description in bytes directly following this struct */ | 71 | /** The length of the description in bytes directly following this struct */ |
62 | uint32_t description_len; | 72 | uint32_t description_len GNUNET_PACKED; |
73 | |||
74 | /** The amount of possible prices */ | ||
75 | uint16_t k GNUNET_PACKED; | ||
63 | 76 | ||
64 | /** Auction type. 0 means first price Auction, >= 0 means M+1st price | 77 | /** Auction type. 0 means first price Auction, >= 0 means M+1st price |
65 | * auction with an amount of m items being sold. */ | 78 | * auction with an amount of m items being sold. */ |
66 | uint16_t m; | 79 | uint16_t m GNUNET_PACKED; |
67 | 80 | ||
68 | /** Outcome type. 0 means private outcome, everything else means public | 81 | /** Outcome type. 0 means private outcome, everything else means public |
69 | * outcome. */ | 82 | * outcome. */ |
70 | uint16_t outcome_public; | 83 | uint16_t outcome_public GNUNET_PACKED; |
71 | |||
72 | /** The amount of possible prices */ | ||
73 | uint16_t price_range; | ||
74 | |||
75 | /** \todo: time */ | ||
76 | }; | 84 | }; |
77 | 85 | ||
86 | GNUNET_NETWORK_STRUCT_END | ||
87 | |||
78 | 88 | ||
79 | struct BRANDT_Auction { | 89 | struct BRANDT_Auction { |
80 | struct BRANDT_DescrP *desc; /** pointer to the auction information */ | 90 | /** Starting time of the auction. Bidders have to join the auction via |
91 | * BRANDT_join until this time */ | ||
92 | struct GNUNET_TIME_Absolute time_start; | ||
93 | |||
94 | /** The maximum duration the participants have to complete each round. */ | ||
95 | struct GNUNET_TIME_Relative time_round; | ||
96 | |||
97 | /** Auction type. 0 means first price Auction, >= 0 means M+1st price | ||
98 | * auction with an amount of m items being sold. */ | ||
99 | uint16_t m; | ||
100 | |||
101 | /** Outcome type. 0 means private outcome, everything else means public | ||
102 | * outcome. */ | ||
103 | uint16_t outcome_public; | ||
81 | 104 | ||
82 | void *closure; /** auction closure given by the user */ | 105 | void *closure; /** auction closure given by the user */ |
83 | 106 | ||