diff options
author | Markus Teich <markus.teich@stusta.mhn.de> | 2016-08-31 14:37:22 +0200 |
---|---|---|
committer | Markus Teich <markus.teich@stusta.mhn.de> | 2016-08-31 14:37:22 +0200 |
commit | 9f0e72f1e8615c9c03222372b2c579471bcce602 (patch) | |
tree | a7fd357b79a9f939de5d5f67de1a030b59ff4418 /test_brandt.c | |
parent | 0d3b32b24881cb9ce89d0b6689ada53f88d0008e (diff) | |
download | libbrandt-9f0e72f1e8615c9c03222372b2c579471bcce602.tar.gz libbrandt-9f0e72f1e8615c9c03222372b2c579471bcce602.zip |
temporary dump for discussion
Diffstat (limited to 'test_brandt.c')
-rw-r--r-- | test_brandt.c | 182 |
1 files changed, 140 insertions, 42 deletions
diff --git a/test_brandt.c b/test_brandt.c index fa49007..274762d 100644 --- a/test_brandt.c +++ b/test_brandt.c | |||
@@ -30,70 +30,160 @@ | |||
30 | #include "util.h" | 30 | #include "util.h" |
31 | 31 | ||
32 | 32 | ||
33 | struct msg | ||
34 | { | ||
35 | uint16_t sender; | ||
36 | uint16_t receiver; | ||
37 | void *buf; | ||
38 | size_t buf_len; | ||
39 | }; | ||
40 | |||
41 | |||
42 | static uint16_t *id; | ||
43 | static struct BRANDT_Auction **ad; | ||
44 | static uint16_t bidders = 3; | ||
45 | static uint16_t prizes = 8; | ||
46 | |||
47 | |||
48 | static void | ||
49 | bidder_start (void *arg) | ||
50 | { | ||
51 | uint16_t i = *(uint16_t *)arg; | ||
52 | |||
53 | weprintf("starting bidder %d", i); | ||
54 | BRANDT_bidder_start (ad[i], i, bidders); | ||
55 | } | ||
56 | |||
57 | |||
58 | static void | ||
59 | transfer_message (void *arg) | ||
60 | { | ||
61 | struct msg *m = (struct msg *)arg; | ||
62 | struct msg_head *h = (struct msg_head *)m->buf; | ||
63 | |||
64 | weprintf("xfer msg %d %x from %d to %d", ntohl(h->msg_type), arg, m->sender, m->receiver); | ||
65 | BRANDT_got_message (ad[m->receiver], m->sender, m->buf, m->buf_len); | ||
66 | free (arg); | ||
67 | } | ||
68 | |||
69 | |||
70 | static uint16_t | ||
71 | cb_start (void *auction_closure) | ||
72 | { | ||
73 | uint16_t *s = (uint16_t *)auction_closure; | ||
74 | if (!s || bidders != *s) | ||
75 | { | ||
76 | weprintf ("start callback called from bidder"); | ||
77 | _exit (1); | ||
78 | } | ||
79 | |||
80 | for (uint16_t i = 0; i < bidders; i++) | ||
81 | GNUNET_SCHEDULER_add_now (&bidder_start, &id[i]); | ||
82 | |||
83 | return bidders; | ||
84 | } | ||
85 | |||
86 | |||
87 | static int | ||
88 | cb_broadcast (void *auction_closure, | ||
89 | const void *msg, | ||
90 | size_t msg_len) | ||
91 | { | ||
92 | uint16_t *s = (uint16_t *)auction_closure; | ||
93 | struct msg *m; | ||
94 | for (uint16_t i = 0; i <= bidders; i++) | ||
95 | { | ||
96 | if (i == *s) | ||
97 | continue; | ||
98 | m = GNUNET_new (struct msg); | ||
99 | m->sender = *s; | ||
100 | m->receiver = i; | ||
101 | m->buf = GNUNET_new_array (msg_len, unsigned char); | ||
102 | memcpy (m->buf, msg, msg_len); | ||
103 | m->buf_len = msg_len; | ||
104 | GNUNET_SCHEDULER_add_now (&transfer_message, m); | ||
105 | } | ||
106 | return 0; | ||
107 | } | ||
108 | |||
109 | |||
110 | static int | ||
111 | cb_unicast (void *auction_closure, | ||
112 | const void *msg, | ||
113 | size_t msg_len) | ||
114 | { | ||
115 | } | ||
116 | |||
117 | |||
118 | static void | ||
119 | cb_result (void *auction_closure, | ||
120 | struct BRANDT_Result results[], | ||
121 | uint16_t results_len) | ||
122 | { | ||
123 | } | ||
124 | |||
125 | |||
33 | static void | 126 | static void |
34 | run_new_join (void *arg) | 127 | run_new_join (void *arg) |
35 | { | 128 | { |
36 | int *ret = arg; | 129 | int *ret = arg; |
37 | const char description[] = "test description for test_new_join"; | 130 | const char description[] = "test description for test_new_join"; |
38 | struct BRANDT_Auction *ad_seller; | ||
39 | struct BRANDT_Auction *ad_bidder; | ||
40 | void *desc; | 131 | void *desc; |
41 | size_t desc_len; | 132 | size_t desc_len; |
42 | 133 | ||
43 | ad_seller = BRANDT_new (NULL, | 134 | ad = GNUNET_new_array (bidders + 1, struct BRANDT_Auction *); |
44 | NULL, | 135 | |
45 | NULL, | 136 | ad[bidders] = BRANDT_new (&cb_result, |
46 | NULL, | 137 | &cb_broadcast, |
138 | &cb_start, | ||
139 | &id[bidders], | ||
47 | &desc, | 140 | &desc, |
48 | &desc_len, | 141 | &desc_len, |
49 | description, | 142 | description, |
50 | sizeof (description), | 143 | sizeof (description), |
51 | GNUNET_TIME_absolute_get (), | 144 | GNUNET_TIME_absolute_get (), |
52 | GNUNET_TIME_UNIT_MINUTES, | 145 | GNUNET_TIME_UNIT_MINUTES, |
53 | 8, | 146 | prizes, /* amount of possible prizes */ |
54 | 0, | 147 | 0, /* m */ |
55 | 1); | 148 | 1); |
56 | if (!ad_seller) | 149 | if (!ad[bidders]) |
57 | { | 150 | { |
58 | weprintf ("BRANDT_new() failed."); | 151 | weprintf ("BRANDT_new() failed."); |
59 | *ret = 0; | 152 | _exit (1); |
60 | return; | ||
61 | } | ||
62 | |||
63 | |||
64 | ad_bidder = BRANDT_join (NULL, | ||
65 | NULL, | ||
66 | NULL, | ||
67 | NULL, | ||
68 | desc, | ||
69 | desc_len, | ||
70 | description, | ||
71 | sizeof (description)); | ||
72 | if (!ad_bidder) | ||
73 | { | ||
74 | weprintf ("BRANDT_join() failed."); | ||
75 | *ret = 0; | ||
76 | return; | ||
77 | } | 153 | } |
78 | 154 | ||
79 | if (ad_seller->k != ad_bidder->k || | 155 | for (uint16_t i = 0; i < bidders; i++) |
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 | { | 156 | { |
89 | weprintf ("error/mismatch in basic auction data"); | 157 | ad[i] = BRANDT_join (&cb_result, |
90 | *ret = 0; | 158 | &cb_broadcast, |
91 | return; | 159 | &cb_unicast, |
160 | &id[i], | ||
161 | desc, | ||
162 | desc_len, | ||
163 | description, | ||
164 | sizeof (description), | ||
165 | 3); /* bid */ | ||
166 | if (!ad[i]) | ||
167 | { | ||
168 | weprintf ("BRANDT_join() failed."); | ||
169 | _exit (1); | ||
170 | } | ||
171 | |||
172 | if (ad[bidders]->k != ad[i]->k || | ||
173 | ad[bidders]->m != ad[i]->m || | ||
174 | ad[bidders]->outcome_public != ad[i]->outcome_public || | ||
175 | ad[bidders]->time_start.abs_value_us | ||
176 | != ad[i]->time_start.abs_value_us || | ||
177 | ad[bidders]->time_round.rel_value_us | ||
178 | != ad[i]->time_round.rel_value_us || | ||
179 | !ad[bidders]->seller_mode || /* todo: split out */ | ||
180 | ad[i]->seller_mode) | ||
181 | { | ||
182 | weprintf ("error/mismatch in basic auction data"); | ||
183 | _exit (1); | ||
184 | } | ||
92 | } | 185 | } |
93 | 186 | ||
94 | BRANDT_destroy (ad_seller); | ||
95 | BRANDT_destroy (ad_bidder); | ||
96 | |||
97 | *ret = 1; | 187 | *ret = 1; |
98 | } | 188 | } |
99 | 189 | ||
@@ -103,7 +193,15 @@ test_new_join () | |||
103 | { | 193 | { |
104 | int ret = 0; | 194 | int ret = 0; |
105 | 195 | ||
196 | id = GNUNET_new_array (bidders + 1, uint16_t); | ||
197 | for (uint16_t i = 0; i <= bidders; i++) | ||
198 | id[i] = i; | ||
199 | |||
106 | GNUNET_SCHEDULER_run (&run_new_join, &ret); | 200 | GNUNET_SCHEDULER_run (&run_new_join, &ret); |
201 | |||
202 | for (uint16_t i = 0; i <= bidders; i++) | ||
203 | BRANDT_destroy (ad[i]); | ||
204 | |||
107 | return ret; | 205 | return ret; |
108 | } | 206 | } |
109 | 207 | ||