aboutsummaryrefslogtreecommitdiff
path: root/test_brandt.c
diff options
context:
space:
mode:
authorMarkus Teich <markus.teich@stusta.mhn.de>2016-09-21 13:50:20 +0200
committerMarkus Teich <markus.teich@stusta.mhn.de>2016-09-21 13:50:20 +0200
commitb31da162a85e993e8bb4287db9b5d8bc6ef2e53f (patch)
treefca58833e5fd19b750ad1aa165661f0bc5200d1b /test_brandt.c
parent658cb968460233a04e77d37558275a894e9d345c (diff)
downloadlibbrandt-b31da162a85e993e8bb4287db9b5d8bc6ef2e53f.tar.gz
libbrandt-b31da162a85e993e8bb4287db9b5d8bc6ef2e53f.zip
coding style fixes
Diffstat (limited to 'test_brandt.c')
-rw-r--r--test_brandt.c104
1 files changed, 53 insertions, 51 deletions
diff --git a/test_brandt.c b/test_brandt.c
index fb0f2c9..077f6f1 100644
--- a/test_brandt.c
+++ b/test_brandt.c
@@ -30,19 +30,18 @@
30#include "util.h" 30#include "util.h"
31 31
32 32
33struct msg 33struct msg {
34{ 34 uint16_t sender;
35 uint16_t sender; 35 uint16_t receiver;
36 uint16_t receiver; 36 void *buf;
37 void *buf; 37 size_t buf_len;
38 size_t buf_len;
39}; 38};
40 39
41 40
42static uint16_t *id; 41static uint16_t *id;
43static struct BRANDT_Auction **ad; 42static struct BRANDT_Auction **ad;
44static uint16_t bidders = 3; 43static uint16_t bidders = 3;
45static uint16_t prizes = 8; 44static uint16_t prizes = 8;
46 45
47 46
48static void 47static void
@@ -50,7 +49,7 @@ bidder_start (void *arg)
50{ 49{
51 uint16_t i = *(uint16_t *)arg; 50 uint16_t i = *(uint16_t *)arg;
52 51
53 weprintf("starting bidder %d", i); 52 weprintf ("starting bidder %d", i);
54 BRANDT_bidder_start (ad[i], i, bidders); 53 BRANDT_bidder_start (ad[i], i, bidders);
55} 54}
56 55
@@ -58,10 +57,11 @@ bidder_start (void *arg)
58static void 57static void
59transfer_message (void *arg) 58transfer_message (void *arg)
60{ 59{
61 struct msg *m = (struct msg *)arg; 60 struct msg *m = (struct msg *)arg;
62 struct msg_head *h = (struct msg_head *)m->buf; 61 struct msg_head *h = (struct msg_head *)m->buf;
63 62
64 weprintf("xfer msg %d %x from %d to %d", ntohl(h->msg_type), arg, m->sender, m->receiver); 63 weprintf ("xfer msg %d %x from %d to %d", ntohl (
64 h->msg_type), arg, m->sender, m->receiver);
65 BRANDT_got_message (ad[m->receiver], m->sender, m->buf, m->buf_len); 65 BRANDT_got_message (ad[m->receiver], m->sender, m->buf, m->buf_len);
66 free (arg); 66 free (arg);
67} 67}
@@ -71,6 +71,7 @@ static uint16_t
71cb_start (void *auction_closure) 71cb_start (void *auction_closure)
72{ 72{
73 uint16_t *s = (uint16_t *)auction_closure; 73 uint16_t *s = (uint16_t *)auction_closure;
74
74 if (!s || bidders != *s) 75 if (!s || bidders != *s)
75 { 76 {
76 weprintf ("start callback called from bidder"); 77 weprintf ("start callback called from bidder");
@@ -89,7 +90,7 @@ cb_broadcast (void *auction_closure,
89 const void *msg, 90 const void *msg,
90 size_t msg_len) 91 size_t msg_len)
91{ 92{
92 uint16_t *s = (uint16_t *)auction_closure; 93 uint16_t *s = (uint16_t *)auction_closure;
93 struct msg *m; 94 struct msg *m;
94 95
95 for (uint16_t i = 0; i <= bidders; i++) 96 for (uint16_t i = 0; i <= bidders; i++)
@@ -113,7 +114,7 @@ cb_unicast (void *auction_closure,
113 const void *msg, 114 const void *msg,
114 size_t msg_len) 115 size_t msg_len)
115{ 116{
116 uint16_t *s = (uint16_t *)auction_closure; 117 uint16_t *s = (uint16_t *)auction_closure;
117 struct msg *m; 118 struct msg *m;
118 119
119 m = GNUNET_new (struct msg); 120 m = GNUNET_new (struct msg);
@@ -139,37 +140,38 @@ cb_result (void *auction_closure,
139 weprintf ("result determined by agent %d: none", *s); 140 weprintf ("result determined by agent %d: none", *s);
140 141
141 for (uint16_t i = 0; i < results_len; i++) 142 for (uint16_t i = 0; i < results_len; i++)
142 weprintf ("result determined by agent %d: bidder %d got status %d with price %d", 143 weprintf (
143 *s, 144 "result determined by agent %d: bidder %d got status %d with price %d",
144 results[i].bidder, 145 *s,
145 results[i].status, 146 results[i].bidder,
146 results[i].price); 147 results[i].status,
148 results[i].price);
147} 149}
148 150
149 151
150static void 152static void
151run_new_join (void *arg) 153run_new_join (void *arg)
152{ 154{
153 int *ret = arg; 155 int *ret = arg;
154 const char description[] = "test description for test_new_join"; 156 const char description[] = "test description for test_new_join";
155 void *desc; 157 void *desc;
156 size_t desc_len; 158 size_t desc_len;
157 159
158 ad = GNUNET_new_array (bidders + 1, struct BRANDT_Auction *); 160 ad = GNUNET_new_array (bidders + 1, struct BRANDT_Auction *);
159 161
160 ad[bidders] = BRANDT_new (&cb_result, 162 ad[bidders] = BRANDT_new (&cb_result,
161 &cb_broadcast, 163 &cb_broadcast,
162 &cb_start, 164 &cb_start,
163 &id[bidders], 165 &id[bidders],
164 &desc, 166 &desc,
165 &desc_len, 167 &desc_len,
166 description, 168 description,
167 sizeof (description), 169 sizeof (description),
168 GNUNET_TIME_absolute_get (), 170 GNUNET_TIME_absolute_get (),
169 GNUNET_TIME_UNIT_MINUTES, 171 GNUNET_TIME_UNIT_MINUTES,
170 prizes, /* amount of possible prizes */ 172 prizes, /* amount of possible prizes */
171 0, /* m */ 173 0, /* m */
172 1); /* outcome public */ 174 1); /* outcome public */
173 if (!ad[bidders]) 175 if (!ad[bidders])
174 { 176 {
175 weprintf ("BRANDT_new() failed."); 177 weprintf ("BRANDT_new() failed.");
@@ -179,14 +181,14 @@ run_new_join (void *arg)
179 for (uint16_t i = 0; i < bidders; i++) 181 for (uint16_t i = 0; i < bidders; i++)
180 { 182 {
181 ad[i] = BRANDT_join (&cb_result, 183 ad[i] = BRANDT_join (&cb_result,
182 &cb_broadcast, 184 &cb_broadcast,
183 &cb_unicast, 185 &cb_unicast,
184 &id[i], 186 &id[i],
185 desc, 187 desc,
186 desc_len, 188 desc_len,
187 description, 189 description,
188 sizeof (description), 190 sizeof (description),
189 3); /* bid */ 191 3); /* bid */
190 if (!ad[i]) 192 if (!ad[i])
191 { 193 {
192 weprintf ("BRANDT_join() failed."); 194 weprintf ("BRANDT_join() failed.");
@@ -194,14 +196,14 @@ run_new_join (void *arg)
194 } 196 }
195 197
196 if (ad[bidders]->k != ad[i]->k || 198 if (ad[bidders]->k != ad[i]->k ||
197 ad[bidders]->m != ad[i]->m || 199 ad[bidders]->m != ad[i]->m ||
198 ad[bidders]->outcome_public != ad[i]->outcome_public || 200 ad[bidders]->outcome_public != ad[i]->outcome_public ||
199 ad[bidders]->time_start.abs_value_us 201 ad[bidders]->time_start.abs_value_us
200 != ad[i]->time_start.abs_value_us || 202 != ad[i]->time_start.abs_value_us ||
201 ad[bidders]->time_round.rel_value_us 203 ad[bidders]->time_round.rel_value_us
202 != ad[i]->time_round.rel_value_us || 204 != ad[i]->time_round.rel_value_us ||
203 !ad[bidders]->seller_mode || /* todo: split out */ 205 !ad[bidders]->seller_mode || /* todo: split out */
204 ad[i]->seller_mode) 206 ad[i]->seller_mode)
205 { 207 {
206 weprintf ("error/mismatch in basic auction data"); 208 weprintf ("error/mismatch in basic auction data");
207 _exit (1); 209 _exit (1);