aboutsummaryrefslogtreecommitdiff
path: root/brandt.c
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 /brandt.c
parentf64f620b074bec1bbcca0a5cbc9331ff8c323605 (diff)
downloadlibbrandt-a19b226167966952138a9905a78c5b29067717d0.tar.gz
libbrandt-a19b226167966952138a9905a78c5b29067717d0.zip
work on public interface implementation
Diffstat (limited to 'brandt.c')
-rw-r--r--brandt.c92
1 files changed, 90 insertions, 2 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)
50 50
51 51
52static void 52static void
53start_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
61struct BRANDT_Auction *
62BRANDT_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
104struct BRANDT_Auction *
105BRANDT_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
140static void
53advance_round (struct BRANDT_Auction *auction, enum auction_type atype, enum outcome_type outcome) 141advance_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