aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--brandt.c15
-rw-r--r--brandt.h27
-rw-r--r--internals.h22
-rw-r--r--platform.h2
-rw-r--r--test_brandt.c16
5 files changed, 61 insertions, 21 deletions
diff --git a/brandt.c b/brandt.c
index 03337c4..e90ec2f 100644
--- a/brandt.c
+++ b/brandt.c
@@ -60,8 +60,9 @@ start_auction (void *arg)
60 60
61 61
62struct BRANDT_Auction * 62struct BRANDT_Auction *
63BRANDT_new (BRANDT_CbBroadcast broadcast, 63BRANDT_new (BRANDT_CbResult result,
64 BRANDT_CbResult result, 64 BRANDT_CbBroadcast broadcast,
65 BRANDT_CbStart start,
65 void *auction_closure, 66 void *auction_closure,
66 void **auction_desc, 67 void **auction_desc,
67 size_t *auction_desc_len, 68 size_t *auction_desc_len,
@@ -97,7 +98,7 @@ BRANDT_new (BRANDT_CbBroadcast broadcast,
97 ret->k = num_prices; 98 ret->k = num_prices;
98 ret->m = m; 99 ret->m = m;
99 ret->outcome_public = outcome_public; 100 ret->outcome_public = outcome_public;
100 ret->cur_round = msg_join; 101 ret->cur_round = msg_init;
101 ret->round_progress = gcry_mpi_new (256); 102 ret->round_progress = gcry_mpi_new (256);
102 103
103 /* we are the seller */ 104 /* we are the seller */
@@ -107,9 +108,9 @@ BRANDT_new (BRANDT_CbBroadcast broadcast,
107 ret->closure = auction_closure; 108 ret->closure = auction_closure;
108 ret->bcast = broadcast; 109 ret->bcast = broadcast;
109 ret->result = result; 110 ret->result = result;
111 ret->start = start;
110 112
111 until_start = GNUNET_TIME_absolute_get_remaining (time_start); 113 until_start = GNUNET_TIME_absolute_get_remaining (time_start);
112 /* \todo: store returned task somewhere to cancel it on shutdown */
113 ret->task = GNUNET_SCHEDULER_add_delayed (until_start, 114 ret->task = GNUNET_SCHEDULER_add_delayed (until_start,
114 &start_auction, 115 &start_auction,
115 ret); 116 ret);
@@ -178,9 +179,9 @@ BRANDT_verify_desc (const void *auction_desc,
178 179
179 180
180struct BRANDT_Auction * 181struct BRANDT_Auction *
181BRANDT_join (BRANDT_CbBroadcast broadcast, 182BRANDT_join (BRANDT_CbResult result,
183 BRANDT_CbBroadcast broadcast,
182 BRANDT_CbUnicast unicast, 184 BRANDT_CbUnicast unicast,
183 BRANDT_CbResult result,
184 void *auction_closure, 185 void *auction_closure,
185 const void *auction_desc, 186 const void *auction_desc,
186 size_t auction_desc_len, 187 size_t auction_desc_len,
@@ -202,7 +203,7 @@ BRANDT_join (BRANDT_CbBroadcast broadcast,
202 weprintf ("failed to parse auction description blob"); 203 weprintf ("failed to parse auction description blob");
203 return NULL; 204 return NULL;
204 } 205 }
205 ret->cur_round = msg_join; 206 ret->cur_round = msg_init;
206 ret->round_progress = gcry_mpi_new (256); 207 ret->round_progress = gcry_mpi_new (256);
207 208
208 /* we are the seller */ 209 /* we are the seller */
diff --git a/brandt.h b/brandt.h
index dad324a..1903301 100644
--- a/brandt.h
+++ b/brandt.h
@@ -31,6 +31,22 @@
31/** defined in internals.h */ 31/** defined in internals.h */
32struct BRANDT_Auction; 32struct BRANDT_Auction;
33 33
34
35/**
36 * Functions of this type are called by libbrandt when the auction should be
37 * started. The application has to announce the ordered list of all bidders to
38 * them and must return the amount of bidders. After this function is called no
39 * more new bidders may be accepted by the application. This callback is only
40 * used if the auction is in seller mode.
41 *
42 * @param[in] auction_closure Closure pointer representing the respective
43 * auction. This is the Pointer given to BRANDT_new().
44 * @return The amount of bidders participating in the auction.
45 */
46typedef uint16_t
47(*BRANDT_CbStart)(void *auction_closure);
48
49
34/** 50/**
35 * Functions of this type are called by libbrandt to broadcast messages to the 51 * Functions of this type are called by libbrandt to broadcast messages to the
36 * blackboard of a specific auction. They have to be sent using authenticated 52 * blackboard of a specific auction. They have to be sent using authenticated
@@ -70,7 +86,7 @@ typedef int
70 * Functions of this type are called by libbrandt to report the auction outcome 86 * Functions of this type are called by libbrandt to report the auction outcome
71 * or malicious/erroneous participants. 87 * or malicious/erroneous participants.
72 * 88 *
73 * \todo: export proof of erroneous behaviour. 89 * \todo: export proof of erroneous behaviour / outcome.
74 * 90 *
75 * @param[in] auction_closure Closure pointer representing the respective 91 * @param[in] auction_closure Closure pointer representing the respective
76 * auction. This is the Pointer given to BRANDT_join() / BRANDT_new(). 92 * auction. This is the Pointer given to BRANDT_join() / BRANDT_new().
@@ -135,9 +151,9 @@ BRANDT_verify_desc (const void *auction_desc,
135 * black-box pointer, do NOT dereference/change it or the data it points to! 151 * black-box pointer, do NOT dereference/change it or the data it points to!
136 */ 152 */
137struct BRANDT_Auction * 153struct BRANDT_Auction *
138BRANDT_join (BRANDT_CbBroadcast broadcast, 154BRANDT_join (BRANDT_CbResult result,
155 BRANDT_CbBroadcast broadcast,
139 BRANDT_CbUnicast unicast, 156 BRANDT_CbUnicast unicast,
140 BRANDT_CbResult result,
141 void *auction_closure, 157 void *auction_closure,
142 const void *auction_desc, 158 const void *auction_desc,
143 size_t auction_desc_len, 159 size_t auction_desc_len,
@@ -182,8 +198,9 @@ BRANDT_join (BRANDT_CbBroadcast broadcast,
182 * black-box pointer, do NOT dereference/change it or the data it points to! 198 * black-box pointer, do NOT dereference/change it or the data it points to!
183 */ 199 */
184struct BRANDT_Auction * 200struct BRANDT_Auction *
185BRANDT_new (BRANDT_CbBroadcast broadcast, 201BRANDT_new (BRANDT_CbResult result,
186 BRANDT_CbResult result, 202 BRANDT_CbBroadcast broadcast,
203 BRANDT_CbStart start,
187 void *auction_closure, 204 void *auction_closure,
188 void **auction_desc, 205 void **auction_desc,
189 size_t *auction_desc_len, 206 size_t *auction_desc_len,
diff --git a/internals.h b/internals.h
index 23dab78..a1c939a 100644
--- a/internals.h
+++ b/internals.h
@@ -29,7 +29,6 @@
29 29
30 30
31enum rounds { 31enum rounds {
32 msg_join,
33 msg_init, 32 msg_init,
34 msg_bid, 33 msg_bid,
35 msg_outcome, 34 msg_outcome,
@@ -39,21 +38,27 @@ enum rounds {
39 38
40 39
41enum auction_type { 40enum auction_type {
42 auction_firstPrice, 41 auction_firstPrice = 0,
43 auction_mPlusFirstPrice, 42 auction_mPlusFirstPrice = 1,
44 auction_last 43 auction_last = 2
45}; 44};
46 45
47 46
48enum outcome_type { 47enum outcome_type {
49 outcome_private, 48 outcome_private = 0,
50 outcome_public, 49 outcome_public = 1,
51 outcome_last 50 outcome_last = 2
52}; 51};
53 52
54 53
55GNUNET_NETWORK_STRUCT_BEGIN 54GNUNET_NETWORK_STRUCT_BEGIN
56 55
56struct msg_head {
57 uint32_t prot_version GNUNET_PACKED;
58 uint32_t msg_type GNUNET_PACKED;
59};
60
61
57/** 62/**
58 * This struct describes an auction and is always linked to a description buffer 63 * This struct describes an auction and is always linked to a description buffer
59 * of #description_len bytes of arbitrary data where the description of the item 64 * of #description_len bytes of arbitrary data where the description of the item
@@ -121,9 +126,10 @@ struct BRANDT_Auction {
121 126
122 void *closure; /** auction closure given by the user */ 127 void *closure; /** auction closure given by the user */
123 128
129 BRANDT_CbResult result; /** result reporting callback */
124 BRANDT_CbBroadcast bcast; /** broadcast callback */ 130 BRANDT_CbBroadcast bcast; /** broadcast callback */
125 BRANDT_CbUnicast ucast; /** unicast callback */ 131 BRANDT_CbUnicast ucast; /** unicast callback */
126 BRANDT_CbResult result; /** result reporting callback */ 132 BRANDT_CbStart start; /** start callback */
127 133
128 int seller_mode; /** If 0 we are bidding, selling otherwise */ 134 int seller_mode; /** If 0 we are bidding, selling otherwise */
129 enum rounds cur_round; /** The round we expect messages from */ 135 enum rounds cur_round; /** The round we expect messages from */
diff --git a/platform.h b/platform.h
index e47c28c..4d454be 100644
--- a/platform.h
+++ b/platform.h
@@ -31,7 +31,7 @@
31# ifdef HAVE_CONFIG_H 31# ifdef HAVE_CONFIG_H
32# include "brandt_config.h" 32# include "brandt_config.h"
33# endif /* ifdef HAVE_CONFIG_H */ 33# endif /* ifdef HAVE_CONFIG_H */
34#endif /* ifndef HAVE_USED_CONFIG_H */ 34#endif /* ifndef HAVE_USED_CONFIG_H */
35 35
36/* Include GNUnet's platform file */ 36/* Include GNUnet's platform file */
37#include <gnunet/platform.h> 37#include <gnunet/platform.h>
diff --git a/test_brandt.c b/test_brandt.c
index 17f1d10..c5a8d3b 100644
--- a/test_brandt.c
+++ b/test_brandt.c
@@ -43,6 +43,7 @@ run_new_join (void *arg)
43 ad_seller = BRANDT_new (NULL, 43 ad_seller = BRANDT_new (NULL,
44 NULL, 44 NULL,
45 NULL, 45 NULL,
46 NULL,
46 &desc, 47 &desc,
47 &desc_len, 48 &desc_len,
48 description, 49 description,
@@ -75,6 +76,21 @@ run_new_join (void *arg)
75 return; 76 return;
76 } 77 }
77 78
79 if (ad_seller->k != ad_bidder->k ||
80 ad_seller->m != ad_bidder->m ||
81 ad_seller->outcome_public != ad_bidder->outcome_public ||
82 ad_seller->time_start.abs_value_us
83 != ad_bidder->time_start.abs_value_us ||
84 ad_seller->time_round.rel_value_us
85 != ad_bidder->time_round.rel_value_us ||
86 !ad_seller->seller_mode ||
87 ad_bidder->seller_mode)
88 {
89 weprintf ("error/mismatch in basic auction data");
90 *ret = 0;
91 return;
92 }
93
78 BRANDT_destroy (ad_seller); 94 BRANDT_destroy (ad_seller);
79 BRANDT_destroy (ad_bidder); 95 BRANDT_destroy (ad_bidder);
80 96