diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/rps | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/rps')
24 files changed, 6977 insertions, 6903 deletions
diff --git a/src/rps/gnunet-rps-profiler.c b/src/rps/gnunet-rps-profiler.c index bd68b905b..a963476cf 100644 --- a/src/rps/gnunet-rps-profiler.c +++ b/src/rps/gnunet-rps-profiler.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file rps/test_rps.c | 21 | * @file rps/test_rps.c |
22 | * @brief Testcase for the random peer sampling service. Starts | 22 | * @brief Testcase for the random peer sampling service. Starts |
@@ -74,8 +74,7 @@ static unsigned int mal_type = 0; | |||
74 | */ | 74 | */ |
75 | static struct GNUNET_TESTBED_Peer **testbed_peers; | 75 | static struct GNUNET_TESTBED_Peer **testbed_peers; |
76 | 76 | ||
77 | enum STAT_TYPE | 77 | enum STAT_TYPE { |
78 | { | ||
79 | STAT_TYPE_ROUNDS, /* 0 */ | 78 | STAT_TYPE_ROUNDS, /* 0 */ |
80 | STAT_TYPE_BLOCKS, /* 1 */ | 79 | STAT_TYPE_BLOCKS, /* 1 */ |
81 | STAT_TYPE_BLOCKS_MANY_PUSH, /* 2 */ | 80 | STAT_TYPE_BLOCKS_MANY_PUSH, /* 2 */ |
@@ -146,8 +145,7 @@ static char* stat_type_strings[] = { | |||
146 | "view size aim", | 145 | "view size aim", |
147 | }; | 146 | }; |
148 | 147 | ||
149 | struct STATcls | 148 | struct STATcls { |
150 | { | ||
151 | struct RPSPeer *rps_peer; | 149 | struct RPSPeer *rps_peer; |
152 | enum STAT_TYPE stat_type; | 150 | enum STAT_TYPE stat_type; |
153 | }; | 151 | }; |
@@ -160,200 +158,200 @@ struct STATcls | |||
160 | * | 158 | * |
161 | * @return corresponding enum | 159 | * @return corresponding enum |
162 | */ | 160 | */ |
163 | enum STAT_TYPE stat_str_2_type (const char *stat_str) | 161 | enum STAT_TYPE stat_str_2_type(const char *stat_str) |
164 | { | 162 | { |
165 | if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_NO_PULL], | 163 | if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS_NO_PULL], |
166 | stat_str, | 164 | stat_str, |
167 | strlen (stat_type_strings[STAT_TYPE_BLOCKS_NO_PULL]))) | 165 | strlen(stat_type_strings[STAT_TYPE_BLOCKS_NO_PULL]))) |
168 | { | 166 | { |
169 | return STAT_TYPE_BLOCKS_NO_PULL; | 167 | return STAT_TYPE_BLOCKS_NO_PULL; |
170 | } | 168 | } |
171 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL], | 169 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL], |
172 | stat_str, | 170 | stat_str, |
173 | strlen (stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL]))) | 171 | strlen(stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL]))) |
174 | { | 172 | { |
175 | return STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL; | 173 | return STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL; |
176 | } | 174 | } |
177 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH], | 175 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH], |
178 | stat_str, | 176 | stat_str, |
179 | strlen (stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH]))) | 177 | strlen(stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH]))) |
180 | { | 178 | { |
181 | return STAT_TYPE_BLOCKS_MANY_PUSH; | 179 | return STAT_TYPE_BLOCKS_MANY_PUSH; |
182 | } | 180 | } |
183 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL], | 181 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL], |
184 | stat_str, | 182 | stat_str, |
185 | strlen (stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL]))) | 183 | strlen(stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL]))) |
186 | { | 184 | { |
187 | return STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL; | 185 | return STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL; |
188 | } | 186 | } |
189 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH], | 187 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH], |
190 | stat_str, | 188 | stat_str, |
191 | strlen (stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH]))) | 189 | strlen(stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH]))) |
192 | { | 190 | { |
193 | return STAT_TYPE_BLOCKS_NO_PUSH; | 191 | return STAT_TYPE_BLOCKS_NO_PUSH; |
194 | } | 192 | } |
195 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS], | 193 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS], |
196 | stat_str, | 194 | stat_str, |
197 | strlen (stat_type_strings[STAT_TYPE_BLOCKS]))) | 195 | strlen(stat_type_strings[STAT_TYPE_BLOCKS]))) |
198 | { | 196 | { |
199 | return STAT_TYPE_BLOCKS; | 197 | return STAT_TYPE_BLOCKS; |
200 | } | 198 | } |
201 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_ROUNDS], | 199 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_ROUNDS], |
202 | stat_str, | 200 | stat_str, |
203 | strlen (stat_type_strings[STAT_TYPE_ROUNDS]))) | 201 | strlen(stat_type_strings[STAT_TYPE_ROUNDS]))) |
204 | { | 202 | { |
205 | return STAT_TYPE_ROUNDS; | 203 | return STAT_TYPE_ROUNDS; |
206 | } | 204 | } |
207 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND], | 205 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND], |
208 | stat_str, | 206 | stat_str, |
209 | strlen (stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND]))) | 207 | strlen(stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND]))) |
210 | { | 208 | { |
211 | return STAT_TYPE_ISSUED_PUSH_SEND; | 209 | return STAT_TYPE_ISSUED_PUSH_SEND; |
212 | } | 210 | } |
213 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND_MH], | 211 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND_MH], |
214 | stat_str, | 212 | stat_str, |
215 | strlen (stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND_MH]))) | 213 | strlen(stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND_MH]))) |
216 | { | 214 | { |
217 | return STAT_TYPE_ISSUED_PUSH_SEND_MH; | 215 | return STAT_TYPE_ISSUED_PUSH_SEND_MH; |
218 | } | 216 | } |
219 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ], | 217 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ], |
220 | stat_str, | 218 | stat_str, |
221 | strlen (stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ]))) | 219 | strlen(stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ]))) |
222 | { | 220 | { |
223 | return STAT_TYPE_ISSUED_PULL_REQ; | 221 | return STAT_TYPE_ISSUED_PULL_REQ; |
224 | } | 222 | } |
225 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ_MH], | 223 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ_MH], |
226 | stat_str, | 224 | stat_str, |
227 | strlen (stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ_MH]))) | 225 | strlen(stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ_MH]))) |
228 | { | 226 | { |
229 | return STAT_TYPE_ISSUED_PULL_REQ_MH; | 227 | return STAT_TYPE_ISSUED_PULL_REQ_MH; |
230 | } | 228 | } |
231 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PULL_REP], | 229 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_ISSUED_PULL_REP], |
232 | stat_str, | 230 | stat_str, |
233 | strlen (stat_type_strings[STAT_TYPE_ISSUED_PULL_REP]))) | 231 | strlen(stat_type_strings[STAT_TYPE_ISSUED_PULL_REP]))) |
234 | { | 232 | { |
235 | return STAT_TYPE_ISSUED_PULL_REP; | 233 | return STAT_TYPE_ISSUED_PULL_REP; |
236 | } | 234 | } |
237 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_SENT_PUSH_SEND], | 235 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_SENT_PUSH_SEND], |
238 | stat_str, | 236 | stat_str, |
239 | strlen (stat_type_strings[STAT_TYPE_SENT_PUSH_SEND]))) | 237 | strlen(stat_type_strings[STAT_TYPE_SENT_PUSH_SEND]))) |
240 | { | 238 | { |
241 | return STAT_TYPE_SENT_PUSH_SEND; | 239 | return STAT_TYPE_SENT_PUSH_SEND; |
242 | } | 240 | } |
243 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_SENT_PULL_REQ], | 241 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_SENT_PULL_REQ], |
244 | stat_str, | 242 | stat_str, |
245 | strlen (stat_type_strings[STAT_TYPE_SENT_PULL_REQ]))) | 243 | strlen(stat_type_strings[STAT_TYPE_SENT_PULL_REQ]))) |
246 | { | 244 | { |
247 | return STAT_TYPE_SENT_PULL_REQ; | 245 | return STAT_TYPE_SENT_PULL_REQ; |
248 | } | 246 | } |
249 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_SENT_PULL_REQ_MH], | 247 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_SENT_PULL_REQ_MH], |
250 | stat_str, | 248 | stat_str, |
251 | strlen (stat_type_strings[STAT_TYPE_SENT_PULL_REQ_MH]))) | 249 | strlen(stat_type_strings[STAT_TYPE_SENT_PULL_REQ_MH]))) |
252 | { | 250 | { |
253 | return STAT_TYPE_SENT_PULL_REQ_MH; | 251 | return STAT_TYPE_SENT_PULL_REQ_MH; |
254 | } | 252 | } |
255 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_SENT_PULL_REP], | 253 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_SENT_PULL_REP], |
256 | stat_str, | 254 | stat_str, |
257 | strlen (stat_type_strings[STAT_TYPE_SENT_PULL_REP]))) | 255 | strlen(stat_type_strings[STAT_TYPE_SENT_PULL_REP]))) |
258 | { | 256 | { |
259 | return STAT_TYPE_SENT_PULL_REP; | 257 | return STAT_TYPE_SENT_PULL_REP; |
260 | } | 258 | } |
261 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PUSH_SEND], | 259 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PUSH_SEND], |
262 | stat_str, | 260 | stat_str, |
263 | strlen (stat_type_strings[STAT_TYPE_RECV_PUSH_SEND]))) | 261 | strlen(stat_type_strings[STAT_TYPE_RECV_PUSH_SEND]))) |
264 | { | 262 | { |
265 | return STAT_TYPE_RECV_PUSH_SEND; | 263 | return STAT_TYPE_RECV_PUSH_SEND; |
266 | } | 264 | } |
267 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PUSH_SEND_MH], | 265 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PUSH_SEND_MH], |
268 | stat_str, | 266 | stat_str, |
269 | strlen (stat_type_strings[STAT_TYPE_RECV_PUSH_SEND_MH]))) | 267 | strlen(stat_type_strings[STAT_TYPE_RECV_PUSH_SEND_MH]))) |
270 | { | 268 | { |
271 | return STAT_TYPE_RECV_PUSH_SEND_MH; | 269 | return STAT_TYPE_RECV_PUSH_SEND_MH; |
272 | } | 270 | } |
273 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PULL_REQ], | 271 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PULL_REQ], |
274 | stat_str, | 272 | stat_str, |
275 | strlen (stat_type_strings[STAT_TYPE_RECV_PULL_REQ]))) | 273 | strlen(stat_type_strings[STAT_TYPE_RECV_PULL_REQ]))) |
276 | { | 274 | { |
277 | return STAT_TYPE_RECV_PULL_REQ; | 275 | return STAT_TYPE_RECV_PULL_REQ; |
278 | } | 276 | } |
279 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PULL_REQ_MH], | 277 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PULL_REQ_MH], |
280 | stat_str, | 278 | stat_str, |
281 | strlen (stat_type_strings[STAT_TYPE_RECV_PULL_REQ_MH]))) | 279 | strlen(stat_type_strings[STAT_TYPE_RECV_PULL_REQ_MH]))) |
282 | { | 280 | { |
283 | return STAT_TYPE_RECV_PULL_REQ_MH; | 281 | return STAT_TYPE_RECV_PULL_REQ_MH; |
284 | } | 282 | } |
285 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PULL_REP], | 283 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PULL_REP], |
286 | stat_str, | 284 | stat_str, |
287 | strlen (stat_type_strings[STAT_TYPE_RECV_PULL_REP]))) | 285 | strlen(stat_type_strings[STAT_TYPE_RECV_PULL_REP]))) |
288 | { | 286 | { |
289 | return STAT_TYPE_RECV_PULL_REP; | 287 | return STAT_TYPE_RECV_PULL_REP; |
290 | } | 288 | } |
291 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PULL_REP_MH], | 289 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PULL_REP_MH], |
292 | stat_str, | 290 | stat_str, |
293 | strlen (stat_type_strings[STAT_TYPE_RECV_PULL_REP_MH]))) | 291 | strlen(stat_type_strings[STAT_TYPE_RECV_PULL_REP_MH]))) |
294 | { | 292 | { |
295 | return STAT_TYPE_RECV_PULL_REP_MH; | 293 | return STAT_TYPE_RECV_PULL_REP_MH; |
296 | } | 294 | } |
297 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_VIEW_SIZE], | 295 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_VIEW_SIZE], |
298 | stat_str, | 296 | stat_str, |
299 | strlen (stat_type_strings[STAT_TYPE_VIEW_SIZE]))) | 297 | strlen(stat_type_strings[STAT_TYPE_VIEW_SIZE]))) |
300 | { | 298 | { |
301 | return STAT_TYPE_VIEW_SIZE; | 299 | return STAT_TYPE_VIEW_SIZE; |
302 | } | 300 | } |
303 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_KNOWN_PEERS], | 301 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_KNOWN_PEERS], |
304 | stat_str, | 302 | stat_str, |
305 | strlen (stat_type_strings[STAT_TYPE_KNOWN_PEERS]))) | 303 | strlen(stat_type_strings[STAT_TYPE_KNOWN_PEERS]))) |
306 | { | 304 | { |
307 | return STAT_TYPE_KNOWN_PEERS; | 305 | return STAT_TYPE_KNOWN_PEERS; |
308 | } | 306 | } |
309 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_VALID_PEERS], | 307 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_VALID_PEERS], |
310 | stat_str, | 308 | stat_str, |
311 | strlen (stat_type_strings[STAT_TYPE_VALID_PEERS]))) | 309 | strlen(stat_type_strings[STAT_TYPE_VALID_PEERS]))) |
312 | { | 310 | { |
313 | return STAT_TYPE_VALID_PEERS; | 311 | return STAT_TYPE_VALID_PEERS; |
314 | } | 312 | } |
315 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_LEARND_PEERS], | 313 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_LEARND_PEERS], |
316 | stat_str, | 314 | stat_str, |
317 | strlen (stat_type_strings[STAT_TYPE_LEARND_PEERS]))) | 315 | strlen(stat_type_strings[STAT_TYPE_LEARND_PEERS]))) |
318 | { | 316 | { |
319 | return STAT_TYPE_LEARND_PEERS; | 317 | return STAT_TYPE_LEARND_PEERS; |
320 | } | 318 | } |
321 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_PENDING_ONLINE_CHECKS], | 319 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_PENDING_ONLINE_CHECKS], |
322 | stat_str, | 320 | stat_str, |
323 | strlen (stat_type_strings[STAT_TYPE_PENDING_ONLINE_CHECKS]))) | 321 | strlen(stat_type_strings[STAT_TYPE_PENDING_ONLINE_CHECKS]))) |
324 | { | 322 | { |
325 | return STAT_TYPE_PENDING_ONLINE_CHECKS; | 323 | return STAT_TYPE_PENDING_ONLINE_CHECKS; |
326 | } | 324 | } |
327 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_UNREQUESTED_PULL_REPLIES], | 325 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_UNREQUESTED_PULL_REPLIES], |
328 | stat_str, | 326 | stat_str, |
329 | strlen (stat_type_strings[STAT_TYPE_UNREQUESTED_PULL_REPLIES]))) | 327 | strlen(stat_type_strings[STAT_TYPE_UNREQUESTED_PULL_REPLIES]))) |
330 | { | 328 | { |
331 | return STAT_TYPE_UNREQUESTED_PULL_REPLIES; | 329 | return STAT_TYPE_UNREQUESTED_PULL_REPLIES; |
332 | } | 330 | } |
333 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_PEERS_IN_PUSH_MAP], | 331 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_PEERS_IN_PUSH_MAP], |
334 | stat_str, | 332 | stat_str, |
335 | strlen (stat_type_strings[STAT_TYPE_PEERS_IN_PUSH_MAP]))) | 333 | strlen(stat_type_strings[STAT_TYPE_PEERS_IN_PUSH_MAP]))) |
336 | { | 334 | { |
337 | return STAT_TYPE_PEERS_IN_PUSH_MAP; | 335 | return STAT_TYPE_PEERS_IN_PUSH_MAP; |
338 | } | 336 | } |
339 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_PEERS_IN_PULL_MAP], | 337 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_PEERS_IN_PULL_MAP], |
340 | stat_str, | 338 | stat_str, |
341 | strlen (stat_type_strings[STAT_TYPE_PEERS_IN_PULL_MAP]))) | 339 | strlen(stat_type_strings[STAT_TYPE_PEERS_IN_PULL_MAP]))) |
342 | { | 340 | { |
343 | return STAT_TYPE_PEERS_IN_PULL_MAP; | 341 | return STAT_TYPE_PEERS_IN_PULL_MAP; |
344 | } | 342 | } |
345 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_PEERS_IN_VIEW], | 343 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_PEERS_IN_VIEW], |
346 | stat_str, | 344 | stat_str, |
347 | strlen (stat_type_strings[STAT_TYPE_PEERS_IN_VIEW]))) | 345 | strlen(stat_type_strings[STAT_TYPE_PEERS_IN_VIEW]))) |
348 | { | 346 | { |
349 | return STAT_TYPE_PEERS_IN_VIEW; | 347 | return STAT_TYPE_PEERS_IN_VIEW; |
350 | } | 348 | } |
351 | else if (0 == strncmp (stat_type_strings[STAT_TYPE_VIEW_SIZE_AIM], | 349 | else if (0 == strncmp(stat_type_strings[STAT_TYPE_VIEW_SIZE_AIM], |
352 | stat_str, | 350 | stat_str, |
353 | strlen (stat_type_strings[STAT_TYPE_VIEW_SIZE_AIM]))) | 351 | strlen(stat_type_strings[STAT_TYPE_VIEW_SIZE_AIM]))) |
354 | { | 352 | { |
355 | return STAT_TYPE_VIEW_SIZE_AIM; | 353 | return STAT_TYPE_VIEW_SIZE_AIM; |
356 | } | 354 | } |
357 | return STAT_TYPE_MAX; | 355 | return STAT_TYPE_MAX; |
358 | } | 356 | } |
359 | 357 | ||
@@ -375,8 +373,7 @@ enum PEER_ONLINE_DELTA { | |||
375 | /** | 373 | /** |
376 | * Operation map entry | 374 | * Operation map entry |
377 | */ | 375 | */ |
378 | struct OpListEntry | 376 | struct OpListEntry { |
379 | { | ||
380 | /** | 377 | /** |
381 | * DLL next ptr | 378 | * DLL next ptr |
382 | */ | 379 | */ |
@@ -418,8 +415,7 @@ static struct OpListEntry *oplist_tail; | |||
418 | /** | 415 | /** |
419 | * A pending reply: A request was sent and the reply is pending. | 416 | * A pending reply: A request was sent and the reply is pending. |
420 | */ | 417 | */ |
421 | struct PendingReply | 418 | struct PendingReply { |
422 | { | ||
423 | /** | 419 | /** |
424 | * DLL next,prev ptr | 420 | * DLL next,prev ptr |
425 | */ | 421 | */ |
@@ -441,8 +437,7 @@ struct PendingReply | |||
441 | /** | 437 | /** |
442 | * A pending request: A request was not made yet but is scheduled for later. | 438 | * A pending request: A request was not made yet but is scheduled for later. |
443 | */ | 439 | */ |
444 | struct PendingRequest | 440 | struct PendingRequest { |
445 | { | ||
446 | /** | 441 | /** |
447 | * DLL next,prev ptr | 442 | * DLL next,prev ptr |
448 | */ | 443 | */ |
@@ -464,8 +459,7 @@ struct PendingRequest | |||
464 | /** | 459 | /** |
465 | * Information we track for each peer. | 460 | * Information we track for each peer. |
466 | */ | 461 | */ |
467 | struct RPSPeer | 462 | struct RPSPeer { |
468 | { | ||
469 | /** | 463 | /** |
470 | * Index of the peer. | 464 | * Index of the peer. |
471 | */ | 465 | */ |
@@ -750,8 +744,7 @@ enum OPTION_COLLECT_VIEW { | |||
750 | /** | 744 | /** |
751 | * Structure to define a single test | 745 | * Structure to define a single test |
752 | */ | 746 | */ |
753 | struct SingleTestRun | 747 | struct SingleTestRun { |
754 | { | ||
755 | /** | 748 | /** |
756 | * Name of the test | 749 | * Name of the test |
757 | */ | 750 | */ |
@@ -838,7 +831,7 @@ static int in_shutdown; | |||
838 | * Append arguments to file | 831 | * Append arguments to file |
839 | */ | 832 | */ |
840 | static void | 833 | static void |
841 | tofile_ (const char *file_name, const char *line) | 834 | tofile_(const char *file_name, const char *line) |
842 | { | 835 | { |
843 | struct GNUNET_DISK_FileHandle *f; | 836 | struct GNUNET_DISK_FileHandle *f; |
844 | /* char output_buffer[512]; */ | 837 | /* char output_buffer[512]; */ |
@@ -846,69 +839,69 @@ tofile_ (const char *file_name, const char *line) | |||
846 | /* int size; */ | 839 | /* int size; */ |
847 | size_t size2; | 840 | size_t size2; |
848 | 841 | ||
849 | if (NULL == (f = GNUNET_DISK_file_open (file_name, | 842 | if (NULL == (f = GNUNET_DISK_file_open(file_name, |
850 | GNUNET_DISK_OPEN_APPEND | | 843 | GNUNET_DISK_OPEN_APPEND | |
851 | GNUNET_DISK_OPEN_WRITE | | 844 | GNUNET_DISK_OPEN_WRITE | |
852 | GNUNET_DISK_OPEN_CREATE, | 845 | GNUNET_DISK_OPEN_CREATE, |
853 | GNUNET_DISK_PERM_USER_READ | | 846 | GNUNET_DISK_PERM_USER_READ | |
854 | GNUNET_DISK_PERM_USER_WRITE | | 847 | GNUNET_DISK_PERM_USER_WRITE | |
855 | GNUNET_DISK_PERM_GROUP_READ | | 848 | GNUNET_DISK_PERM_GROUP_READ | |
856 | GNUNET_DISK_PERM_OTHER_READ))) | 849 | GNUNET_DISK_PERM_OTHER_READ))) |
857 | { | 850 | { |
858 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 851 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
859 | "Not able to open file %s\n", | 852 | "Not able to open file %s\n", |
860 | file_name); | 853 | file_name); |
861 | return; | 854 | return; |
862 | } | 855 | } |
863 | /* size = GNUNET_snprintf (output_buffer, | 856 | /* size = GNUNET_snprintf (output_buffer, |
864 | sizeof (output_buffer), | 857 | sizeof (output_buffer), |
865 | "%llu %s\n", | 858 | "%llu %s\n", |
866 | GNUNET_TIME_absolute_get ().abs_value_us, | 859 | GNUNET_TIME_absolute_get ().abs_value_us, |
867 | line); | 860 | line); |
868 | if (0 > size) | 861 | if (0 > size) |
869 | { | 862 | { |
870 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 863 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
871 | "Failed to write string to buffer (size: %i)\n", | 864 | "Failed to write string to buffer (size: %i)\n", |
872 | size); | 865 | size); |
873 | return; | 866 | return; |
874 | } */ | 867 | } */ |
875 | 868 | ||
876 | size = strlen (line) * sizeof (char); | 869 | size = strlen(line) * sizeof(char); |
877 | 870 | ||
878 | size2 = GNUNET_DISK_file_write (f, line, size); | 871 | size2 = GNUNET_DISK_file_write(f, line, size); |
879 | if (size != size2) | 872 | if (size != size2) |
880 | { | ||
881 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
882 | "Unable to write to file! (Size: %lu, size2: %lu)\n", | ||
883 | size, | ||
884 | size2); | ||
885 | if (GNUNET_YES != GNUNET_DISK_file_close (f)) | ||
886 | { | 873 | { |
887 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 874 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
888 | "Unable to close file\n"); | 875 | "Unable to write to file! (Size: %lu, size2: %lu)\n", |
876 | size, | ||
877 | size2); | ||
878 | if (GNUNET_YES != GNUNET_DISK_file_close(f)) | ||
879 | { | ||
880 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
881 | "Unable to close file\n"); | ||
882 | } | ||
883 | return; | ||
889 | } | 884 | } |
890 | return; | ||
891 | } | ||
892 | 885 | ||
893 | if (GNUNET_YES != GNUNET_DISK_file_close (f)) | 886 | if (GNUNET_YES != GNUNET_DISK_file_close(f)) |
894 | { | 887 | { |
895 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 888 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
896 | "Unable to close file\n"); | 889 | "Unable to close file\n"); |
897 | } | 890 | } |
898 | } | 891 | } |
899 | 892 | ||
900 | /** | 893 | /** |
901 | * This function is used to facilitate writing important information to disk | 894 | * This function is used to facilitate writing important information to disk |
902 | */ | 895 | */ |
903 | #define tofile(file_name, ...) do {\ | 896 | #define tofile(file_name, ...) do { \ |
904 | char tmp_buf[512];\ | 897 | char tmp_buf[512]; \ |
905 | int size;\ | 898 | int size; \ |
906 | size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\ | 899 | size = GNUNET_snprintf(tmp_buf, sizeof(tmp_buf), __VA_ARGS__); \ |
907 | if (0 > size)\ | 900 | if (0 > size) \ |
908 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\ | 901 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \ |
909 | "Failed to create tmp_buf\n");\ | 902 | "Failed to create tmp_buf\n"); \ |
910 | else\ | 903 | else \ |
911 | tofile_(file_name,tmp_buf);\ | 904 | tofile_ (file_name, tmp_buf); \ |
912 | } while (0); | 905 | } while (0); |
913 | 906 | ||
914 | 907 | ||
@@ -917,26 +910,26 @@ tofile_ (const char *file_name, const char *line) | |||
917 | * Unused | 910 | * Unused |
918 | */ | 911 | */ |
919 | /* static void | 912 | /* static void |
920 | ids_to_file (char *file_name, | 913 | ids_to_file (char *file_name, |
921 | struct GNUNET_PeerIdentity *peer_ids, | 914 | struct GNUNET_PeerIdentity *peer_ids, |
922 | unsigned int num_peer_ids) | 915 | unsigned int num_peer_ids) |
923 | { | 916 | { |
924 | unsigned int i; | 917 | unsigned int i; |
925 | 918 | ||
926 | for (i=0 ; i < num_peer_ids ; i++) | 919 | for (i=0 ; i < num_peer_ids ; i++) |
927 | { | 920 | { |
928 | to_file (file_name, | 921 | to_file (file_name, |
929 | "%u\t%s", | 922 | "%u\t%s", |
930 | i, | 923 | i, |
931 | GNUNET_i2s_full (&peer_ids[i])); | 924 | GNUNET_i2s_full (&peer_ids[i])); |
932 | } | 925 | } |
933 | } */ | 926 | } */ |
934 | 927 | ||
935 | /** | 928 | /** |
936 | * Test the success of a single test | 929 | * Test the success of a single test |
937 | */ | 930 | */ |
938 | static int | 931 | static int |
939 | evaluate (void) | 932 | evaluate(void) |
940 | { | 933 | { |
941 | unsigned int i; | 934 | unsigned int i; |
942 | int tmp_ok; | 935 | int tmp_ok; |
@@ -944,17 +937,17 @@ evaluate (void) | |||
944 | tmp_ok = 1; | 937 | tmp_ok = 1; |
945 | 938 | ||
946 | for (i = 0; i < num_peers; i++) | 939 | for (i = 0; i < num_peers; i++) |
947 | { | 940 | { |
948 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 941 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
949 | "%u. peer [%s] received %u of %u expected peer_ids: %i\n", | 942 | "%u. peer [%s] received %u of %u expected peer_ids: %i\n", |
950 | i, | 943 | i, |
951 | GNUNET_i2s (rps_peers[i].peer_id), | 944 | GNUNET_i2s(rps_peers[i].peer_id), |
952 | rps_peers[i].num_recv_ids, | 945 | rps_peers[i].num_recv_ids, |
953 | rps_peers[i].num_ids_to_request, | 946 | rps_peers[i].num_ids_to_request, |
954 | (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids)); | 947 | (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids)); |
955 | tmp_ok &= (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids); | 948 | tmp_ok &= (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids); |
956 | } | 949 | } |
957 | return tmp_ok? 0 : 1; | 950 | return tmp_ok ? 0 : 1; |
958 | } | 951 | } |
959 | 952 | ||
960 | 953 | ||
@@ -962,12 +955,12 @@ evaluate (void) | |||
962 | * Creates an oplist entry and adds it to the oplist DLL | 955 | * Creates an oplist entry and adds it to the oplist DLL |
963 | */ | 956 | */ |
964 | static struct OpListEntry * | 957 | static struct OpListEntry * |
965 | make_oplist_entry () | 958 | make_oplist_entry() |
966 | { | 959 | { |
967 | struct OpListEntry *entry; | 960 | struct OpListEntry *entry; |
968 | 961 | ||
969 | entry = GNUNET_new (struct OpListEntry); | 962 | entry = GNUNET_new(struct OpListEntry); |
970 | GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry); | 963 | GNUNET_CONTAINER_DLL_insert_tail(oplist_head, oplist_tail, entry); |
971 | return entry; | 964 | return entry; |
972 | } | 965 | } |
973 | 966 | ||
@@ -981,15 +974,15 @@ make_oplist_entry () | |||
981 | * @return #GNUNET_YES if so | 974 | * @return #GNUNET_YES if so |
982 | * #GNUNET_NO otherwise | 975 | * #GNUNET_NO otherwise |
983 | */ | 976 | */ |
984 | static int check_statistics_collect_completed_single_peer ( | 977 | static int check_statistics_collect_completed_single_peer( |
985 | const struct RPSPeer *rps_peer) | 978 | const struct RPSPeer *rps_peer) |
986 | { | 979 | { |
987 | if (cur_test_run.stat_collect_flags != | 980 | if (cur_test_run.stat_collect_flags != |
988 | (cur_test_run.stat_collect_flags & | 981 | (cur_test_run.stat_collect_flags & |
989 | rps_peer->stat_collected_flags)) | 982 | rps_peer->stat_collected_flags)) |
990 | { | 983 | { |
991 | return GNUNET_NO; | 984 | return GNUNET_NO; |
992 | } | 985 | } |
993 | return GNUNET_YES; | 986 | return GNUNET_YES; |
994 | } | 987 | } |
995 | /** | 988 | /** |
@@ -999,152 +992,153 @@ static int check_statistics_collect_completed_single_peer ( | |||
999 | * @return #GNUNET_YES if so | 992 | * @return #GNUNET_YES if so |
1000 | * #GNUNET_NO otherwise | 993 | * #GNUNET_NO otherwise |
1001 | */ | 994 | */ |
1002 | static int check_statistics_collect_completed () | 995 | static int check_statistics_collect_completed() |
1003 | { | 996 | { |
1004 | uint32_t i; | 997 | uint32_t i; |
1005 | 998 | ||
1006 | for (i = 0; i < num_peers; i++) | 999 | for (i = 0; i < num_peers; i++) |
1007 | { | ||
1008 | if (GNUNET_NO == check_statistics_collect_completed_single_peer (&rps_peers[i])) | ||
1009 | { | 1000 | { |
1010 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1001 | if (GNUNET_NO == check_statistics_collect_completed_single_peer(&rps_peers[i])) |
1011 | "At least Peer %" PRIu32 " did not yet receive all statistics values\n", | 1002 | { |
1012 | i); | 1003 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1013 | return GNUNET_NO; | 1004 | "At least Peer %" PRIu32 " did not yet receive all statistics values\n", |
1005 | i); | ||
1006 | return GNUNET_NO; | ||
1007 | } | ||
1014 | } | 1008 | } |
1015 | } | 1009 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1016 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1010 | "All peers received their statistics values\n"); |
1017 | "All peers received their statistics values\n"); | ||
1018 | return GNUNET_YES; | 1011 | return GNUNET_YES; |
1019 | } | 1012 | } |
1020 | 1013 | ||
1021 | static void | 1014 | static void |
1022 | rps_disconnect_adapter (void *cls, | 1015 | rps_disconnect_adapter(void *cls, |
1023 | void *op_result); | 1016 | void *op_result); |
1024 | 1017 | ||
1025 | static void | 1018 | static void |
1026 | cancel_pending_req (struct PendingRequest *pending_req) | 1019 | cancel_pending_req(struct PendingRequest *pending_req) |
1027 | { | 1020 | { |
1028 | struct RPSPeer *rps_peer; | 1021 | struct RPSPeer *rps_peer; |
1029 | 1022 | ||
1030 | rps_peer = pending_req->rps_peer; | 1023 | rps_peer = pending_req->rps_peer; |
1031 | GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head, | 1024 | GNUNET_CONTAINER_DLL_remove(rps_peer->pending_req_head, |
1032 | rps_peer->pending_req_tail, | 1025 | rps_peer->pending_req_tail, |
1033 | pending_req); | 1026 | pending_req); |
1034 | rps_peer->num_pending_reqs--; | 1027 | rps_peer->num_pending_reqs--; |
1035 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1028 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1036 | "Cancelling pending rps get request\n"); | 1029 | "Cancelling pending rps get request\n"); |
1037 | GNUNET_SCHEDULER_cancel (pending_req->request_task); | 1030 | GNUNET_SCHEDULER_cancel(pending_req->request_task); |
1038 | GNUNET_free (pending_req); | 1031 | GNUNET_free(pending_req); |
1039 | } | 1032 | } |
1040 | 1033 | ||
1041 | static void | 1034 | static void |
1042 | cancel_request (struct PendingReply *pending_rep) | 1035 | cancel_request(struct PendingReply *pending_rep) |
1043 | { | 1036 | { |
1044 | struct RPSPeer *rps_peer; | 1037 | struct RPSPeer *rps_peer; |
1045 | 1038 | ||
1046 | rps_peer = pending_rep->rps_peer; | 1039 | rps_peer = pending_rep->rps_peer; |
1047 | GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head, | 1040 | GNUNET_CONTAINER_DLL_remove(rps_peer->pending_rep_head, |
1048 | rps_peer->pending_rep_tail, | 1041 | rps_peer->pending_rep_tail, |
1049 | pending_rep); | 1042 | pending_rep); |
1050 | rps_peer->num_pending_reps--; | 1043 | rps_peer->num_pending_reps--; |
1051 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1044 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1052 | "Cancelling rps get reply\n"); | 1045 | "Cancelling rps get reply\n"); |
1053 | GNUNET_assert (NULL != pending_rep->req_handle); | 1046 | GNUNET_assert(NULL != pending_rep->req_handle); |
1054 | GNUNET_RPS_request_single_info_cancel (pending_rep->req_handle); | 1047 | GNUNET_RPS_request_single_info_cancel(pending_rep->req_handle); |
1055 | pending_rep->req_handle = NULL; | 1048 | pending_rep->req_handle = NULL; |
1056 | GNUNET_free (pending_rep); | 1049 | GNUNET_free(pending_rep); |
1057 | pending_rep = NULL; | 1050 | pending_rep = NULL; |
1058 | } | 1051 | } |
1059 | 1052 | ||
1060 | void | 1053 | void |
1061 | clean_peer (unsigned peer_index) | 1054 | clean_peer(unsigned peer_index) |
1062 | { | 1055 | { |
1063 | struct PendingRequest *pending_req; | 1056 | struct PendingRequest *pending_req; |
1064 | 1057 | ||
1065 | while (NULL != (pending_req = rps_peers[peer_index].pending_req_head)) | 1058 | while (NULL != (pending_req = rps_peers[peer_index].pending_req_head)) |
1066 | { | 1059 | { |
1067 | cancel_pending_req (pending_req); | 1060 | cancel_pending_req(pending_req); |
1068 | } | 1061 | } |
1069 | pending_req = rps_peers[peer_index].pending_req_head; | 1062 | pending_req = rps_peers[peer_index].pending_req_head; |
1070 | rps_disconnect_adapter (&rps_peers[peer_index], | 1063 | rps_disconnect_adapter(&rps_peers[peer_index], |
1071 | &rps_peers[peer_index].rps_handle); | 1064 | &rps_peers[peer_index].rps_handle); |
1072 | for (unsigned stat_type = STAT_TYPE_ROUNDS; | 1065 | for (unsigned stat_type = STAT_TYPE_ROUNDS; |
1073 | stat_type < STAT_TYPE_MAX; | 1066 | stat_type < STAT_TYPE_MAX; |
1074 | stat_type++) | 1067 | stat_type++) |
1075 | { | ||
1076 | if (NULL != rps_peers[peer_index].h_stat_get[stat_type]) | ||
1077 | { | 1068 | { |
1078 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1069 | if (NULL != rps_peers[peer_index].h_stat_get[stat_type]) |
1079 | "(%u) did not yet receive stat value for `%s'\n", | 1070 | { |
1080 | rps_peers[peer_index].index, | 1071 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1081 | stat_type_strings[stat_type]); | 1072 | "(%u) did not yet receive stat value for `%s'\n", |
1082 | GNUNET_STATISTICS_get_cancel ( | 1073 | rps_peers[peer_index].index, |
1083 | rps_peers[peer_index].h_stat_get[stat_type]); | 1074 | stat_type_strings[stat_type]); |
1075 | GNUNET_STATISTICS_get_cancel( | ||
1076 | rps_peers[peer_index].h_stat_get[stat_type]); | ||
1077 | } | ||
1084 | } | 1078 | } |
1085 | } | ||
1086 | if (NULL != rps_peers[peer_index].op) | 1079 | if (NULL != rps_peers[peer_index].op) |
1087 | { | 1080 | { |
1088 | GNUNET_TESTBED_operation_done (rps_peers[peer_index].op); | 1081 | GNUNET_TESTBED_operation_done(rps_peers[peer_index].op); |
1089 | rps_peers[peer_index].op = NULL; | 1082 | rps_peers[peer_index].op = NULL; |
1090 | } | 1083 | } |
1091 | } | 1084 | } |
1092 | 1085 | ||
1093 | /** | 1086 | /** |
1094 | * Task run on timeout to shut everything down. | 1087 | * Task run on timeout to shut everything down. |
1095 | */ | 1088 | */ |
1096 | static void | 1089 | static void |
1097 | shutdown_op (void *cls) | 1090 | shutdown_op(void *cls) |
1098 | { | 1091 | { |
1099 | unsigned int i; | 1092 | unsigned int i; |
1100 | struct OpListEntry *entry; | 1093 | struct OpListEntry *entry; |
1101 | (void) cls; | ||
1102 | 1094 | ||
1103 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1095 | (void)cls; |
1104 | "Shutdown task scheduled, going down.\n"); | 1096 | |
1097 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1098 | "Shutdown task scheduled, going down.\n"); | ||
1105 | in_shutdown = GNUNET_YES; | 1099 | in_shutdown = GNUNET_YES; |
1106 | 1100 | ||
1107 | if (NULL != shutdown_task) | 1101 | if (NULL != shutdown_task) |
1108 | { | 1102 | { |
1109 | GNUNET_SCHEDULER_cancel (shutdown_task); | 1103 | GNUNET_SCHEDULER_cancel(shutdown_task); |
1110 | shutdown_task = NULL; | 1104 | shutdown_task = NULL; |
1111 | } | 1105 | } |
1112 | if (NULL != post_test_task) | 1106 | if (NULL != post_test_task) |
1113 | { | 1107 | { |
1114 | GNUNET_SCHEDULER_cancel (post_test_task); | 1108 | GNUNET_SCHEDULER_cancel(post_test_task); |
1115 | post_test_task = NULL; | 1109 | post_test_task = NULL; |
1116 | } | 1110 | } |
1117 | if (NULL != churn_task) | 1111 | if (NULL != churn_task) |
1118 | { | 1112 | { |
1119 | GNUNET_SCHEDULER_cancel (churn_task); | 1113 | GNUNET_SCHEDULER_cancel(churn_task); |
1120 | churn_task = NULL; | 1114 | churn_task = NULL; |
1121 | } | 1115 | } |
1122 | entry = oplist_head; | 1116 | entry = oplist_head; |
1123 | while (NULL != (entry = oplist_head)) | 1117 | while (NULL != (entry = oplist_head)) |
1124 | { | 1118 | { |
1125 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1119 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1126 | "Operation still pending on shutdown (%u)\n", | 1120 | "Operation still pending on shutdown (%u)\n", |
1127 | entry->index); | 1121 | entry->index); |
1128 | GNUNET_TESTBED_operation_done (entry->op); | 1122 | GNUNET_TESTBED_operation_done(entry->op); |
1129 | GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); | 1123 | GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, entry); |
1130 | GNUNET_free (entry); | 1124 | GNUNET_free(entry); |
1131 | } | 1125 | } |
1132 | for (i = 0; i < num_peers; i++) | 1126 | for (i = 0; i < num_peers; i++) |
1133 | { | 1127 | { |
1134 | clean_peer (i); | 1128 | clean_peer(i); |
1135 | } | 1129 | } |
1136 | close_all_files(); | 1130 | close_all_files(); |
1137 | } | 1131 | } |
1138 | 1132 | ||
1139 | static void | 1133 | static void |
1140 | trigger_shutdown (void *cls) | 1134 | trigger_shutdown(void *cls) |
1141 | { | 1135 | { |
1142 | (void) cls; | 1136 | (void)cls; |
1143 | 1137 | ||
1144 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1138 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1145 | "Shutdown was triggerd by timeout, going down.\n"); | 1139 | "Shutdown was triggerd by timeout, going down.\n"); |
1146 | shutdown_task = NULL; | 1140 | shutdown_task = NULL; |
1147 | GNUNET_SCHEDULER_shutdown (); | 1141 | GNUNET_SCHEDULER_shutdown(); |
1148 | } | 1142 | } |
1149 | 1143 | ||
1150 | 1144 | ||
@@ -1152,46 +1146,47 @@ trigger_shutdown (void *cls) | |||
1152 | * Task run after #duration to collect statistics and potentially shut down. | 1146 | * Task run after #duration to collect statistics and potentially shut down. |
1153 | */ | 1147 | */ |
1154 | static void | 1148 | static void |
1155 | post_test_op (void *cls) | 1149 | post_test_op(void *cls) |
1156 | { | 1150 | { |
1157 | unsigned int i; | 1151 | unsigned int i; |
1158 | (void) cls; | 1152 | |
1153 | (void)cls; | ||
1159 | 1154 | ||
1160 | post_test_task = NULL; | 1155 | post_test_task = NULL; |
1161 | post_test = GNUNET_YES; | 1156 | post_test = GNUNET_YES; |
1162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1157 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1163 | "Executing post test op.\n"); | 1158 | "Executing post test op.\n"); |
1164 | if (NULL != churn_task) | 1159 | if (NULL != churn_task) |
1165 | { | ||
1166 | GNUNET_SCHEDULER_cancel (churn_task); | ||
1167 | churn_task = NULL; | ||
1168 | } | ||
1169 | for (i = 0; i < num_peers; i++) | ||
1170 | { | ||
1171 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1172 | "Executing post test op. (peer %" PRIu32 ")\n", | ||
1173 | rps_peers[i].index); | ||
1174 | if (NULL != rps_peers[i].op) | ||
1175 | { | 1160 | { |
1176 | GNUNET_TESTBED_operation_done (rps_peers[i].op); | 1161 | GNUNET_SCHEDULER_cancel(churn_task); |
1177 | rps_peers[i].op = NULL; | 1162 | churn_task = NULL; |
1178 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1179 | "Cancelled testbed operation\n"); | ||
1180 | } | 1163 | } |
1181 | if (NULL != cur_test_run.post_test) | 1164 | for (i = 0; i < num_peers; i++) |
1182 | { | 1165 | { |
1183 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i); | 1166 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1184 | cur_test_run.post_test (&rps_peers[i]); | 1167 | "Executing post test op. (peer %" PRIu32 ")\n", |
1168 | rps_peers[i].index); | ||
1169 | if (NULL != rps_peers[i].op) | ||
1170 | { | ||
1171 | GNUNET_TESTBED_operation_done(rps_peers[i].op); | ||
1172 | rps_peers[i].op = NULL; | ||
1173 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1174 | "Cancelled testbed operation\n"); | ||
1175 | } | ||
1176 | if (NULL != cur_test_run.post_test) | ||
1177 | { | ||
1178 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i); | ||
1179 | cur_test_run.post_test(&rps_peers[i]); | ||
1180 | } | ||
1185 | } | 1181 | } |
1186 | } | ||
1187 | /* If we do not collect statistics, shut down directly */ | 1182 | /* If we do not collect statistics, shut down directly */ |
1188 | if (NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics || | 1183 | if (NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics || |
1189 | GNUNET_YES == check_statistics_collect_completed()) | 1184 | GNUNET_YES == check_statistics_collect_completed()) |
1190 | { | 1185 | { |
1191 | GNUNET_SCHEDULER_cancel (shutdown_task); | 1186 | GNUNET_SCHEDULER_cancel(shutdown_task); |
1192 | shutdown_task = NULL; | 1187 | shutdown_task = NULL; |
1193 | GNUNET_SCHEDULER_shutdown (); | 1188 | GNUNET_SCHEDULER_shutdown(); |
1194 | } | 1189 | } |
1195 | } | 1190 | } |
1196 | 1191 | ||
1197 | 1192 | ||
@@ -1199,70 +1194,71 @@ post_test_op (void *cls) | |||
1199 | * Seed peers. | 1194 | * Seed peers. |
1200 | */ | 1195 | */ |
1201 | static void | 1196 | static void |
1202 | seed_peers (void *cls) | 1197 | seed_peers(void *cls) |
1203 | { | 1198 | { |
1204 | struct RPSPeer *peer = cls; | 1199 | struct RPSPeer *peer = cls; |
1205 | unsigned int amount; | 1200 | unsigned int amount; |
1206 | unsigned int i; | 1201 | unsigned int i; |
1207 | 1202 | ||
1208 | // TODO if malicious don't seed mal peers | 1203 | // TODO if malicious don't seed mal peers |
1209 | amount = round (.5 * num_peers); | 1204 | amount = round(.5 * num_peers); |
1210 | 1205 | ||
1211 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n"); | 1206 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n"); |
1212 | for (i = 0 ; i < amount ; i++) | 1207 | for (i = 0; i < amount; i++) |
1213 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n", | 1208 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n", |
1214 | i, | 1209 | i, |
1215 | GNUNET_i2s (&rps_peer_ids[i])); | 1210 | GNUNET_i2s(&rps_peer_ids[i])); |
1216 | 1211 | ||
1217 | GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids); | 1212 | GNUNET_RPS_seed_ids(peer->rps_handle, amount, rps_peer_ids); |
1218 | } | 1213 | } |
1219 | 1214 | ||
1220 | 1215 | ||
1221 | /** | 1216 | /** |
1222 | * Get the id of peer i. | 1217 | * Get the id of peer i. |
1223 | */ | 1218 | */ |
1224 | void | 1219 | void |
1225 | info_cb (void *cb_cls, | 1220 | info_cb(void *cb_cls, |
1226 | struct GNUNET_TESTBED_Operation *op, | 1221 | struct GNUNET_TESTBED_Operation *op, |
1227 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | 1222 | const struct GNUNET_TESTBED_PeerInformation *pinfo, |
1228 | const char *emsg) | 1223 | const char *emsg) |
1229 | { | 1224 | { |
1230 | struct OpListEntry *entry = (struct OpListEntry *) cb_cls; | 1225 | struct OpListEntry *entry = (struct OpListEntry *)cb_cls; |
1231 | (void) op; | 1226 | |
1227 | (void)op; | ||
1232 | 1228 | ||
1233 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | 1229 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1234 | { | 1230 | { |
1235 | return; | 1231 | return; |
1236 | } | 1232 | } |
1237 | 1233 | ||
1238 | if (NULL == pinfo || NULL != emsg) | 1234 | if (NULL == pinfo || NULL != emsg) |
1239 | { | 1235 | { |
1240 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg); | 1236 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg); |
1241 | GNUNET_TESTBED_operation_done (entry->op); | 1237 | GNUNET_TESTBED_operation_done(entry->op); |
1242 | return; | 1238 | return; |
1243 | } | 1239 | } |
1244 | 1240 | ||
1245 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1241 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1246 | "Peer %u is %s\n", | 1242 | "Peer %u is %s\n", |
1247 | entry->index, | 1243 | entry->index, |
1248 | GNUNET_i2s (pinfo->result.id)); | 1244 | GNUNET_i2s(pinfo->result.id)); |
1249 | 1245 | ||
1250 | rps_peer_ids[entry->index] = *(pinfo->result.id); | 1246 | rps_peer_ids[entry->index] = *(pinfo->result.id); |
1251 | rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index]; | 1247 | rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index]; |
1252 | 1248 | ||
1253 | GNUNET_assert (GNUNET_OK == | 1249 | GNUNET_assert(GNUNET_OK == |
1254 | GNUNET_CONTAINER_multipeermap_put (peer_map, | 1250 | GNUNET_CONTAINER_multipeermap_put(peer_map, |
1255 | &rps_peer_ids[entry->index], | 1251 | &rps_peer_ids[entry->index], |
1256 | &rps_peers[entry->index], | 1252 | &rps_peers[entry->index], |
1257 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1253 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1258 | tofile ("/tmp/rps/peer_ids", | 1254 | tofile("/tmp/rps/peer_ids", |
1259 | "%u\t%s\n", | 1255 | "%u\t%s\n", |
1260 | entry->index, | 1256 | entry->index, |
1261 | GNUNET_i2s_full (&rps_peer_ids[entry->index])); | 1257 | GNUNET_i2s_full(&rps_peer_ids[entry->index])); |
1262 | 1258 | ||
1263 | GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); | 1259 | GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, entry); |
1264 | GNUNET_TESTBED_operation_done (entry->op); | 1260 | GNUNET_TESTBED_operation_done(entry->op); |
1265 | GNUNET_free (entry); | 1261 | GNUNET_free(entry); |
1266 | } | 1262 | } |
1267 | 1263 | ||
1268 | 1264 | ||
@@ -1276,39 +1272,39 @@ info_cb (void *cb_cls, | |||
1276 | * operation has executed successfully. | 1272 | * operation has executed successfully. |
1277 | */ | 1273 | */ |
1278 | static void | 1274 | static void |
1279 | rps_connect_complete_cb (void *cls, | 1275 | rps_connect_complete_cb(void *cls, |
1280 | struct GNUNET_TESTBED_Operation *op, | 1276 | struct GNUNET_TESTBED_Operation *op, |
1281 | void *ca_result, | 1277 | void *ca_result, |
1282 | const char *emsg) | 1278 | const char *emsg) |
1283 | { | 1279 | { |
1284 | struct RPSPeer *rps_peer = cls; | 1280 | struct RPSPeer *rps_peer = cls; |
1285 | struct GNUNET_RPS_Handle *rps = ca_result; | 1281 | struct GNUNET_RPS_Handle *rps = ca_result; |
1286 | 1282 | ||
1287 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | 1283 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1288 | { | 1284 | { |
1289 | return; | 1285 | return; |
1290 | } | 1286 | } |
1291 | 1287 | ||
1292 | rps_peer->rps_handle = rps; | 1288 | rps_peer->rps_handle = rps; |
1293 | rps_peer->online = GNUNET_YES; | 1289 | rps_peer->online = GNUNET_YES; |
1294 | num_peers_online++; | 1290 | num_peers_online++; |
1295 | 1291 | ||
1296 | GNUNET_assert (op == rps_peer->op); | 1292 | GNUNET_assert(op == rps_peer->op); |
1297 | if (NULL != emsg) | 1293 | if (NULL != emsg) |
1298 | { | 1294 | { |
1299 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1295 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1300 | "Failed to connect to RPS service: %s\n", | 1296 | "Failed to connect to RPS service: %s\n", |
1301 | emsg); | 1297 | emsg); |
1302 | ok = 1; | 1298 | ok = 1; |
1303 | GNUNET_SCHEDULER_shutdown (); | 1299 | GNUNET_SCHEDULER_shutdown(); |
1304 | return; | 1300 | return; |
1305 | } | 1301 | } |
1306 | 1302 | ||
1307 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1303 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1308 | "Started client successfully (%u)\n", | 1304 | "Started client successfully (%u)\n", |
1309 | rps_peer->index); | 1305 | rps_peer->index); |
1310 | 1306 | ||
1311 | cur_test_run.main_test (rps_peer); | 1307 | cur_test_run.main_test(rps_peer); |
1312 | } | 1308 | } |
1313 | 1309 | ||
1314 | 1310 | ||
@@ -1323,15 +1319,15 @@ rps_connect_complete_cb (void *cls, | |||
1323 | * @return service handle to return in 'op_result', NULL on error | 1319 | * @return service handle to return in 'op_result', NULL on error |
1324 | */ | 1320 | */ |
1325 | static void * | 1321 | static void * |
1326 | rps_connect_adapter (void *cls, | 1322 | rps_connect_adapter(void *cls, |
1327 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 1323 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
1328 | { | 1324 | { |
1329 | struct GNUNET_RPS_Handle *h; | 1325 | struct GNUNET_RPS_Handle *h; |
1330 | 1326 | ||
1331 | h = GNUNET_RPS_connect (cfg); | 1327 | h = GNUNET_RPS_connect(cfg); |
1332 | 1328 | ||
1333 | if (NULL != cur_test_run.pre_test) | 1329 | if (NULL != cur_test_run.pre_test) |
1334 | cur_test_run.pre_test (cls, h); | 1330 | cur_test_run.pre_test(cls, h); |
1335 | 1331 | ||
1336 | return h; | 1332 | return h; |
1337 | } | 1333 | } |
@@ -1346,12 +1342,12 @@ rps_connect_adapter (void *cls, | |||
1346 | * @return service handle to return in 'op_result', NULL on error | 1342 | * @return service handle to return in 'op_result', NULL on error |
1347 | */ | 1343 | */ |
1348 | static void * | 1344 | static void * |
1349 | stat_connect_adapter (void *cls, | 1345 | stat_connect_adapter(void *cls, |
1350 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 1346 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
1351 | { | 1347 | { |
1352 | struct RPSPeer *peer = cls; | 1348 | struct RPSPeer *peer = cls; |
1353 | 1349 | ||
1354 | peer->stats_h = GNUNET_STATISTICS_create ("rps-profiler", cfg); | 1350 | peer->stats_h = GNUNET_STATISTICS_create("rps-profiler", cfg); |
1355 | return peer->stats_h; | 1351 | return peer->stats_h; |
1356 | } | 1352 | } |
1357 | 1353 | ||
@@ -1362,7 +1358,7 @@ stat_connect_adapter (void *cls, | |||
1362 | * @param op_result service handle returned from the connect adapter | 1358 | * @param op_result service handle returned from the connect adapter |
1363 | */ | 1359 | */ |
1364 | static void | 1360 | static void |
1365 | stat_disconnect_adapter (void *cls, void *op_result) | 1361 | stat_disconnect_adapter(void *cls, void *op_result) |
1366 | { | 1362 | { |
1367 | struct RPSPeer *peer = cls; | 1363 | struct RPSPeer *peer = cls; |
1368 | 1364 | ||
@@ -1372,7 +1368,7 @@ stat_disconnect_adapter (void *cls, void *op_result) | |||
1372 | //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel | 1368 | //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel |
1373 | // (peer->stats_h, "nse", "# peers connected", | 1369 | // (peer->stats_h, "nse", "# peers connected", |
1374 | // stat_iterator, peer)); | 1370 | // stat_iterator, peer)); |
1375 | GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); | 1371 | GNUNET_STATISTICS_destroy(op_result, GNUNET_NO); |
1376 | peer->stats_h = NULL; | 1372 | peer->stats_h = NULL; |
1377 | } | 1373 | } |
1378 | 1374 | ||
@@ -1387,22 +1383,22 @@ stat_disconnect_adapter (void *cls, void *op_result) | |||
1387 | * operation has executed successfully. | 1383 | * operation has executed successfully. |
1388 | */ | 1384 | */ |
1389 | static void | 1385 | static void |
1390 | stat_complete_cb (void *cls, | 1386 | stat_complete_cb(void *cls, |
1391 | struct GNUNET_TESTBED_Operation *op, | 1387 | struct GNUNET_TESTBED_Operation *op, |
1392 | void *ca_result, | 1388 | void *ca_result, |
1393 | const char *emsg ) | 1389 | const char *emsg) |
1394 | { | 1390 | { |
1395 | //struct GNUNET_STATISTICS_Handle *sh = ca_result; | 1391 | //struct GNUNET_STATISTICS_Handle *sh = ca_result; |
1396 | //struct RPSPeer *peer = (struct RPSPeer *) cls; | 1392 | //struct RPSPeer *peer = (struct RPSPeer *) cls; |
1397 | (void) cls; | 1393 | (void)cls; |
1398 | (void) op; | 1394 | (void)op; |
1399 | (void) ca_result; | 1395 | (void)ca_result; |
1400 | 1396 | ||
1401 | if (NULL != emsg) | 1397 | if (NULL != emsg) |
1402 | { | 1398 | { |
1403 | GNUNET_break (0); | 1399 | GNUNET_break(0); |
1404 | return; | 1400 | return; |
1405 | } | 1401 | } |
1406 | //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch | 1402 | //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch |
1407 | // (sh, "core", "# peers connected", | 1403 | // (sh, "core", "# peers connected", |
1408 | // stat_iterator, peer)); | 1404 | // stat_iterator, peer)); |
@@ -1420,36 +1416,36 @@ stat_complete_cb (void *cls, | |||
1420 | * @param op_result service handle returned from the connect adapter | 1416 | * @param op_result service handle returned from the connect adapter |
1421 | */ | 1417 | */ |
1422 | static void | 1418 | static void |
1423 | rps_disconnect_adapter (void *cls, | 1419 | rps_disconnect_adapter(void *cls, |
1424 | void *op_result) | 1420 | void *op_result) |
1425 | { | 1421 | { |
1426 | struct RPSPeer *peer = cls; | 1422 | struct RPSPeer *peer = cls; |
1427 | struct GNUNET_RPS_Handle *h = op_result; | 1423 | struct GNUNET_RPS_Handle *h = op_result; |
1428 | struct PendingReply *pending_rep; | 1424 | struct PendingReply *pending_rep; |
1429 | 1425 | ||
1430 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1426 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1431 | "disconnect_adapter (%u)\n", | 1427 | "disconnect_adapter (%u)\n", |
1432 | peer->index); | 1428 | peer->index); |
1433 | GNUNET_assert (NULL != peer); | 1429 | GNUNET_assert(NULL != peer); |
1434 | if (NULL != peer->rps_handle) | 1430 | if (NULL != peer->rps_handle) |
1435 | { | ||
1436 | while (NULL != (pending_rep = peer->pending_rep_head)) | ||
1437 | { | 1431 | { |
1438 | cancel_request (pending_rep); | 1432 | while (NULL != (pending_rep = peer->pending_rep_head)) |
1433 | { | ||
1434 | cancel_request(pending_rep); | ||
1435 | } | ||
1436 | GNUNET_assert(h == peer->rps_handle); | ||
1437 | if (NULL != h) | ||
1438 | { | ||
1439 | GNUNET_RPS_disconnect(h); | ||
1440 | h = NULL; | ||
1441 | } | ||
1442 | peer->rps_handle = NULL; | ||
1439 | } | 1443 | } |
1440 | GNUNET_assert (h == peer->rps_handle); | ||
1441 | if (NULL != h) | ||
1442 | { | ||
1443 | GNUNET_RPS_disconnect (h); | ||
1444 | h = NULL; | ||
1445 | } | ||
1446 | peer->rps_handle = NULL; | ||
1447 | } | ||
1448 | } | 1444 | } |
1449 | 1445 | ||
1450 | 1446 | ||
1451 | /*********************************************************************** | 1447 | /*********************************************************************** |
1452 | * Definition of tests | 1448 | * Definition of tests |
1453 | ***********************************************************************/ | 1449 | ***********************************************************************/ |
1454 | 1450 | ||
1455 | /** | 1451 | /** |
@@ -1460,84 +1456,88 @@ rps_disconnect_adapter (void *cls, | |||
1460 | * @param recv_peers the received peers | 1456 | * @param recv_peers the received peers |
1461 | */ | 1457 | */ |
1462 | static void | 1458 | static void |
1463 | default_reply_handle (void *cls, | 1459 | default_reply_handle(void *cls, |
1464 | uint64_t n, | 1460 | uint64_t n, |
1465 | const struct GNUNET_PeerIdentity *recv_peers) | 1461 | const struct GNUNET_PeerIdentity *recv_peers) |
1466 | { | 1462 | { |
1467 | struct RPSPeer *rps_peer; | 1463 | struct RPSPeer *rps_peer; |
1468 | struct PendingReply *pending_rep = (struct PendingReply *) cls; | 1464 | struct PendingReply *pending_rep = (struct PendingReply *)cls; |
1469 | unsigned int i; | 1465 | unsigned int i; |
1470 | 1466 | ||
1471 | rps_peer = pending_rep->rps_peer; | 1467 | rps_peer = pending_rep->rps_peer; |
1472 | GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head, | 1468 | GNUNET_CONTAINER_DLL_remove(rps_peer->pending_rep_head, |
1473 | rps_peer->pending_rep_tail, | 1469 | rps_peer->pending_rep_tail, |
1474 | pending_rep); | 1470 | pending_rep); |
1475 | rps_peer->num_pending_reps--; | 1471 | rps_peer->num_pending_reps--; |
1476 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1472 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1477 | "[%s] got %" PRIu64 " peers:\n", | 1473 | "[%s] got %" PRIu64 " peers:\n", |
1478 | GNUNET_i2s (rps_peer->peer_id), | 1474 | GNUNET_i2s(rps_peer->peer_id), |
1479 | n); | 1475 | n); |
1480 | 1476 | ||
1481 | for (i = 0; i < n; i++) | 1477 | for (i = 0; i < n; i++) |
1482 | { | 1478 | { |
1483 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1479 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1484 | "%u: %s\n", | 1480 | "%u: %s\n", |
1485 | i, | 1481 | i, |
1486 | GNUNET_i2s (&recv_peers[i])); | 1482 | GNUNET_i2s(&recv_peers[i])); |
1487 | 1483 | ||
1488 | rps_peer->num_recv_ids++; | 1484 | rps_peer->num_recv_ids++; |
1489 | } | 1485 | } |
1490 | 1486 | ||
1491 | if (GNUNET_YES != post_test) return; | 1487 | if (GNUNET_YES != post_test) |
1492 | if (HAVE_QUICK_QUIT != cur_test_run.have_quick_quit) return; | 1488 | return; |
1489 | if (HAVE_QUICK_QUIT != cur_test_run.have_quick_quit) | ||
1490 | return; | ||
1493 | if (0 == evaluate()) | 1491 | if (0 == evaluate()) |
1494 | { | 1492 | { |
1495 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1493 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1496 | "Test succeeded before end of duration\n"); | 1494 | "Test succeeded before end of duration\n"); |
1497 | if (NULL != post_test_task) GNUNET_SCHEDULER_cancel (post_test_task); | 1495 | if (NULL != post_test_task) |
1498 | post_test_task = GNUNET_SCHEDULER_add_now (&post_test_op, NULL); | 1496 | GNUNET_SCHEDULER_cancel(post_test_task); |
1499 | GNUNET_assert (NULL != post_test_task); | 1497 | post_test_task = GNUNET_SCHEDULER_add_now(&post_test_op, NULL); |
1500 | } | 1498 | GNUNET_assert(NULL != post_test_task); |
1499 | } | ||
1501 | } | 1500 | } |
1502 | 1501 | ||
1503 | 1502 | ||
1504 | static void | 1503 | static void |
1505 | profiler_reply_handle_info (void *cls, | 1504 | profiler_reply_handle_info(void *cls, |
1506 | const struct GNUNET_PeerIdentity *recv_peer, | 1505 | const struct GNUNET_PeerIdentity *recv_peer, |
1507 | double probability, | 1506 | double probability, |
1508 | uint32_t num_observed); | 1507 | uint32_t num_observed); |
1509 | 1508 | ||
1510 | /** | 1509 | /** |
1511 | * Request random peers. | 1510 | * Request random peers. |
1512 | */ | 1511 | */ |
1513 | static void | 1512 | static void |
1514 | request_peers (void *cls) | 1513 | request_peers(void *cls) |
1515 | { | 1514 | { |
1516 | struct PendingRequest *pending_req = cls; | 1515 | struct PendingRequest *pending_req = cls; |
1517 | struct RPSPeer *rps_peer; | 1516 | struct RPSPeer *rps_peer; |
1518 | struct PendingReply *pending_rep; | 1517 | struct PendingReply *pending_rep; |
1519 | 1518 | ||
1520 | rps_peer = pending_req->rps_peer; | 1519 | rps_peer = pending_req->rps_peer; |
1521 | GNUNET_assert (1 <= rps_peer->num_pending_reqs); | 1520 | GNUNET_assert(1 <= rps_peer->num_pending_reqs); |
1522 | GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head, | 1521 | GNUNET_CONTAINER_DLL_remove(rps_peer->pending_req_head, |
1523 | rps_peer->pending_req_tail, | 1522 | rps_peer->pending_req_tail, |
1524 | pending_req); | 1523 | pending_req); |
1525 | rps_peer->num_pending_reqs--; | 1524 | rps_peer->num_pending_reqs--; |
1526 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) return; | 1525 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1527 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1526 | return; |
1528 | "Requesting one peer\n"); | 1527 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1529 | pending_rep = GNUNET_new (struct PendingReply); | 1528 | "Requesting one peer\n"); |
1529 | pending_rep = GNUNET_new(struct PendingReply); | ||
1530 | pending_rep->rps_peer = rps_peer; | 1530 | pending_rep->rps_peer = rps_peer; |
1531 | //pending_rep->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle, | 1531 | //pending_rep->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle, |
1532 | // 1, | 1532 | // 1, |
1533 | // cur_test_run.reply_handle, | 1533 | // cur_test_run.reply_handle, |
1534 | // pending_rep); | 1534 | // pending_rep); |
1535 | pending_rep->req_handle = GNUNET_RPS_request_peer_info (rps_peer->rps_handle, | 1535 | pending_rep->req_handle = GNUNET_RPS_request_peer_info(rps_peer->rps_handle, |
1536 | profiler_reply_handle_info, | 1536 | profiler_reply_handle_info, |
1537 | pending_rep); | 1537 | pending_rep); |
1538 | GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_rep_head, | 1538 | GNUNET_CONTAINER_DLL_insert_tail(rps_peer->pending_rep_head, |
1539 | rps_peer->pending_rep_tail, | 1539 | rps_peer->pending_rep_tail, |
1540 | pending_rep); | 1540 | pending_rep); |
1541 | rps_peer->num_pending_reps++; | 1541 | rps_peer->num_pending_reps++; |
1542 | } | 1542 | } |
1543 | 1543 | ||
@@ -1547,57 +1547,57 @@ request_peers (void *cls) | |||
1547 | * issued, nor replied | 1547 | * issued, nor replied |
1548 | */ | 1548 | */ |
1549 | void | 1549 | void |
1550 | schedule_missing_requests (struct RPSPeer *rps_peer) | 1550 | schedule_missing_requests(struct RPSPeer *rps_peer) |
1551 | { | 1551 | { |
1552 | unsigned int i; | 1552 | unsigned int i; |
1553 | struct PendingRequest *pending_req; | 1553 | struct PendingRequest *pending_req; |
1554 | 1554 | ||
1555 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1555 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1556 | "Scheduling %u - %u missing requests\n", | 1556 | "Scheduling %u - %u missing requests\n", |
1557 | rps_peer->num_ids_to_request, | 1557 | rps_peer->num_ids_to_request, |
1558 | rps_peer->num_pending_reqs + rps_peer->num_pending_reps); | 1558 | rps_peer->num_pending_reqs + rps_peer->num_pending_reps); |
1559 | GNUNET_assert (rps_peer->num_pending_reqs + rps_peer->num_pending_reps <= | 1559 | GNUNET_assert(rps_peer->num_pending_reqs + rps_peer->num_pending_reps <= |
1560 | rps_peer->num_ids_to_request); | 1560 | rps_peer->num_ids_to_request); |
1561 | for (i = rps_peer->num_pending_reqs + rps_peer->num_pending_reps; | 1561 | for (i = rps_peer->num_pending_reqs + rps_peer->num_pending_reps; |
1562 | i < rps_peer->num_ids_to_request; i++) | 1562 | i < rps_peer->num_ids_to_request; i++) |
1563 | { | 1563 | { |
1564 | pending_req = GNUNET_new (struct PendingRequest); | 1564 | pending_req = GNUNET_new(struct PendingRequest); |
1565 | pending_req->rps_peer = rps_peer; | 1565 | pending_req->rps_peer = rps_peer; |
1566 | pending_req->request_task = GNUNET_SCHEDULER_add_delayed ( | 1566 | pending_req->request_task = GNUNET_SCHEDULER_add_delayed( |
1567 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 1567 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
1568 | cur_test_run.request_interval * i), | 1568 | cur_test_run.request_interval * i), |
1569 | request_peers, | 1569 | request_peers, |
1570 | pending_req); | 1570 | pending_req); |
1571 | GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_req_head, | 1571 | GNUNET_CONTAINER_DLL_insert_tail(rps_peer->pending_req_head, |
1572 | rps_peer->pending_req_tail, | 1572 | rps_peer->pending_req_tail, |
1573 | pending_req); | 1573 | pending_req); |
1574 | rps_peer->num_pending_reqs++; | 1574 | rps_peer->num_pending_reqs++; |
1575 | } | 1575 | } |
1576 | } | 1576 | } |
1577 | 1577 | ||
1578 | void | 1578 | void |
1579 | cancel_pending_req_rep (struct RPSPeer *rps_peer) | 1579 | cancel_pending_req_rep(struct RPSPeer *rps_peer) |
1580 | { | 1580 | { |
1581 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1581 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1582 | "Cancelling all (pending) requests.\n"); | 1582 | "Cancelling all (pending) requests.\n"); |
1583 | while (NULL != rps_peer->pending_req_head) | 1583 | while (NULL != rps_peer->pending_req_head) |
1584 | cancel_pending_req (rps_peer->pending_req_head); | 1584 | cancel_pending_req(rps_peer->pending_req_head); |
1585 | GNUNET_assert (0 == rps_peer->num_pending_reqs); | 1585 | GNUNET_assert(0 == rps_peer->num_pending_reqs); |
1586 | while (NULL != rps_peer->pending_rep_head) | 1586 | while (NULL != rps_peer->pending_rep_head) |
1587 | cancel_request (rps_peer->pending_rep_head); | 1587 | cancel_request(rps_peer->pending_rep_head); |
1588 | GNUNET_assert (0 == rps_peer->num_pending_reps); | 1588 | GNUNET_assert(0 == rps_peer->num_pending_reps); |
1589 | } | 1589 | } |
1590 | 1590 | ||
1591 | /*********************************** | 1591 | /*********************************** |
1592 | * MALICIOUS | 1592 | * MALICIOUS |
1593 | ***********************************/ | 1593 | ***********************************/ |
1594 | 1594 | ||
1595 | /** | 1595 | /** |
1596 | * Initialise only non-mal RPSPeers | 1596 | * Initialise only non-mal RPSPeers |
1597 | */ | 1597 | */ |
1598 | static void mal_init_peer (struct RPSPeer *rps_peer) | 1598 | static void mal_init_peer(struct RPSPeer *rps_peer) |
1599 | { | 1599 | { |
1600 | if (rps_peer->index >= round (portion * num_peers)) | 1600 | if (rps_peer->index >= round(portion * num_peers)) |
1601 | rps_peer->num_ids_to_request = 1; | 1601 | rps_peer->num_ids_to_request = 1; |
1602 | } | 1602 | } |
1603 | 1603 | ||
@@ -1611,60 +1611,60 @@ static void mal_init_peer (struct RPSPeer *rps_peer) | |||
1611 | * @param h the handle to the service | 1611 | * @param h the handle to the service |
1612 | */ | 1612 | */ |
1613 | static void | 1613 | static void |
1614 | mal_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) | 1614 | mal_pre(struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) |
1615 | { | 1615 | { |
1616 | #if ENABLE_MALICIOUS | 1616 | #if ENABLE_MALICIOUS |
1617 | uint32_t num_mal_peers; | 1617 | uint32_t num_mal_peers; |
1618 | 1618 | ||
1619 | GNUNET_assert ( (1 >= portion) && | 1619 | GNUNET_assert((1 >= portion) && |
1620 | (0 < portion) ); | 1620 | (0 < portion)); |
1621 | num_mal_peers = round (portion * num_peers); | 1621 | num_mal_peers = round(portion * num_peers); |
1622 | 1622 | ||
1623 | if (rps_peer->index < num_mal_peers) | 1623 | if (rps_peer->index < num_mal_peers) |
1624 | { | 1624 | { |
1625 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1625 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1626 | "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n", | 1626 | "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n", |
1627 | rps_peer->index, | 1627 | rps_peer->index, |
1628 | GNUNET_i2s (rps_peer->peer_id), | 1628 | GNUNET_i2s(rps_peer->peer_id), |
1629 | num_mal_peers); | 1629 | num_mal_peers); |
1630 | 1630 | ||
1631 | GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers, | 1631 | GNUNET_RPS_act_malicious(h, mal_type, num_mal_peers, |
1632 | rps_peer_ids, target_peer); | 1632 | rps_peer_ids, target_peer); |
1633 | } | 1633 | } |
1634 | #endif /* ENABLE_MALICIOUS */ | 1634 | #endif /* ENABLE_MALICIOUS */ |
1635 | } | 1635 | } |
1636 | 1636 | ||
1637 | static void | 1637 | static void |
1638 | mal_cb (struct RPSPeer *rps_peer) | 1638 | mal_cb(struct RPSPeer *rps_peer) |
1639 | { | 1639 | { |
1640 | uint32_t num_mal_peers; | 1640 | uint32_t num_mal_peers; |
1641 | 1641 | ||
1642 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | 1642 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1643 | { | 1643 | { |
1644 | return; | 1644 | return; |
1645 | } | 1645 | } |
1646 | 1646 | ||
1647 | #if ENABLE_MALICIOUS | 1647 | #if ENABLE_MALICIOUS |
1648 | GNUNET_assert ( (1 >= portion) && | 1648 | GNUNET_assert((1 >= portion) && |
1649 | (0 < portion) ); | 1649 | (0 < portion)); |
1650 | num_mal_peers = round (portion * num_peers); | 1650 | num_mal_peers = round(portion * num_peers); |
1651 | 1651 | ||
1652 | if (rps_peer->index >= num_mal_peers) | 1652 | if (rps_peer->index >= num_mal_peers) |
1653 | { /* It's useless to ask a malicious peer about a random sample - | 1653 | { /* It's useless to ask a malicious peer about a random sample - |
1654 | it's not sampling */ | 1654 | it's not sampling */ |
1655 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), | 1655 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), |
1656 | seed_peers, rps_peer); | 1656 | seed_peers, rps_peer); |
1657 | schedule_missing_requests (rps_peer); | 1657 | schedule_missing_requests(rps_peer); |
1658 | } | 1658 | } |
1659 | #endif /* ENABLE_MALICIOUS */ | 1659 | #endif /* ENABLE_MALICIOUS */ |
1660 | } | 1660 | } |
1661 | 1661 | ||
1662 | /*********************************** | 1662 | /*********************************** |
1663 | * CHURN | 1663 | * CHURN |
1664 | ***********************************/ | 1664 | ***********************************/ |
1665 | 1665 | ||
1666 | static void | 1666 | static void |
1667 | churn (void *cls); | 1667 | churn(void *cls); |
1668 | 1668 | ||
1669 | /** | 1669 | /** |
1670 | * @brief Starts churn | 1670 | * @brief Starts churn |
@@ -1678,32 +1678,34 @@ churn (void *cls); | |||
1678 | * @param rps_peer The peer it's called for | 1678 | * @param rps_peer The peer it's called for |
1679 | */ | 1679 | */ |
1680 | static void | 1680 | static void |
1681 | churn_test_cb (struct RPSPeer *rps_peer) | 1681 | churn_test_cb(struct RPSPeer *rps_peer) |
1682 | { | 1682 | { |
1683 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | 1683 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1684 | { | 1684 | { |
1685 | return; | 1685 | return; |
1686 | } | 1686 | } |
1687 | 1687 | ||
1688 | /* Start churn */ | 1688 | /* Start churn */ |
1689 | if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) | 1689 | if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) |
1690 | { | 1690 | { |
1691 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1691 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1692 | "Starting churn task\n"); | 1692 | "Starting churn task\n"); |
1693 | churn_task = GNUNET_SCHEDULER_add_delayed ( | 1693 | churn_task = GNUNET_SCHEDULER_add_delayed( |
1694 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), | 1694 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), |
1695 | churn, | 1695 | churn, |
1696 | NULL); | 1696 | NULL); |
1697 | } else { | 1697 | } |
1698 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1698 | else |
1699 | "Not starting churn task\n"); | 1699 | { |
1700 | } | 1700 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1701 | 1701 | "Not starting churn task\n"); | |
1702 | schedule_missing_requests (rps_peer); | 1702 | } |
1703 | |||
1704 | schedule_missing_requests(rps_peer); | ||
1703 | } | 1705 | } |
1704 | 1706 | ||
1705 | /*********************************** | 1707 | /*********************************** |
1706 | * PROFILER | 1708 | * PROFILER |
1707 | ***********************************/ | 1709 | ***********************************/ |
1708 | 1710 | ||
1709 | /** | 1711 | /** |
@@ -1714,81 +1716,82 @@ churn_test_cb (struct RPSPeer *rps_peer) | |||
1714 | * @param emsg NULL on success; otherwise an error description | 1716 | * @param emsg NULL on success; otherwise an error description |
1715 | */ | 1717 | */ |
1716 | static void | 1718 | static void |
1717 | churn_cb (void *cls, | 1719 | churn_cb(void *cls, |
1718 | struct GNUNET_TESTBED_Operation *op, | 1720 | struct GNUNET_TESTBED_Operation *op, |
1719 | const char *emsg) | 1721 | const char *emsg) |
1720 | { | 1722 | { |
1721 | // FIXME | 1723 | // FIXME |
1722 | struct OpListEntry *entry = cls; | 1724 | struct OpListEntry *entry = cls; |
1723 | (void) op; | 1725 | |
1726 | (void)op; | ||
1724 | 1727 | ||
1725 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | 1728 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1726 | { | 1729 | { |
1727 | return; | 1730 | return; |
1728 | } | 1731 | } |
1729 | 1732 | ||
1730 | GNUNET_TESTBED_operation_done (entry->op); | 1733 | GNUNET_TESTBED_operation_done(entry->op); |
1731 | if (NULL != emsg) | 1734 | if (NULL != emsg) |
1732 | { | 1735 | { |
1733 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n"); | 1736 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n"); |
1734 | GNUNET_SCHEDULER_shutdown (); | 1737 | GNUNET_SCHEDULER_shutdown(); |
1735 | return; | 1738 | return; |
1736 | } | 1739 | } |
1737 | GNUNET_assert (0 != entry->delta); | 1740 | GNUNET_assert(0 != entry->delta); |
1738 | 1741 | ||
1739 | num_peers_online += entry->delta; | 1742 | num_peers_online += entry->delta; |
1740 | 1743 | ||
1741 | if (PEER_GO_OFFLINE == entry->delta) | 1744 | if (PEER_GO_OFFLINE == entry->delta) |
1742 | { /* Peer hopefully just went offline */ | 1745 | { /* Peer hopefully just went offline */ |
1743 | if (GNUNET_YES != rps_peers[entry->index].online) | 1746 | if (GNUNET_YES != rps_peers[entry->index].online) |
1744 | { | 1747 | { |
1745 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1748 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1746 | "peer %s was expected to go offline but is still marked as online\n", | 1749 | "peer %s was expected to go offline but is still marked as online\n", |
1747 | GNUNET_i2s (rps_peers[entry->index].peer_id)); | 1750 | GNUNET_i2s(rps_peers[entry->index].peer_id)); |
1748 | GNUNET_break (0); | 1751 | GNUNET_break(0); |
1749 | } | 1752 | } |
1750 | else | 1753 | else |
1751 | { | 1754 | { |
1752 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1755 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1753 | "peer %s probably went offline as expected\n", | 1756 | "peer %s probably went offline as expected\n", |
1754 | GNUNET_i2s (rps_peers[entry->index].peer_id)); | 1757 | GNUNET_i2s(rps_peers[entry->index].peer_id)); |
1758 | } | ||
1759 | rps_peers[entry->index].online = GNUNET_NO; | ||
1755 | } | 1760 | } |
1756 | rps_peers[entry->index].online = GNUNET_NO; | ||
1757 | } | ||
1758 | 1761 | ||
1759 | else if (PEER_GO_ONLINE < entry->delta) | 1762 | else if (PEER_GO_ONLINE < entry->delta) |
1760 | { /* Peer hopefully just went online */ | 1763 | { /* Peer hopefully just went online */ |
1761 | if (GNUNET_NO != rps_peers[entry->index].online) | 1764 | if (GNUNET_NO != rps_peers[entry->index].online) |
1762 | { | 1765 | { |
1763 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1766 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1764 | "peer %s was expected to go online but is still marked as offline\n", | 1767 | "peer %s was expected to go online but is still marked as offline\n", |
1765 | GNUNET_i2s (rps_peers[entry->index].peer_id)); | 1768 | GNUNET_i2s(rps_peers[entry->index].peer_id)); |
1766 | GNUNET_break (0); | 1769 | GNUNET_break(0); |
1767 | } | 1770 | } |
1768 | else | 1771 | else |
1769 | { | 1772 | { |
1770 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1773 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1771 | "peer %s probably went online as expected\n", | 1774 | "peer %s probably went online as expected\n", |
1772 | GNUNET_i2s (rps_peers[entry->index].peer_id)); | 1775 | GNUNET_i2s(rps_peers[entry->index].peer_id)); |
1773 | if (NULL != cur_test_run.pre_test) | 1776 | if (NULL != cur_test_run.pre_test) |
1774 | { | 1777 | { |
1775 | cur_test_run.pre_test (&rps_peers[entry->index], | 1778 | cur_test_run.pre_test(&rps_peers[entry->index], |
1776 | rps_peers[entry->index].rps_handle); | 1779 | rps_peers[entry->index].rps_handle); |
1777 | schedule_missing_requests (&rps_peers[entry->index]); | 1780 | schedule_missing_requests(&rps_peers[entry->index]); |
1778 | } | 1781 | } |
1779 | } | 1782 | } |
1780 | rps_peers[entry->index].online = GNUNET_YES; | 1783 | rps_peers[entry->index].online = GNUNET_YES; |
1781 | } | 1784 | } |
1782 | else | 1785 | else |
1783 | { | 1786 | { |
1784 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1787 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1785 | "Invalid value for delta: %i\n", entry->delta); | 1788 | "Invalid value for delta: %i\n", entry->delta); |
1786 | GNUNET_break (0); | 1789 | GNUNET_break(0); |
1787 | } | 1790 | } |
1788 | 1791 | ||
1789 | GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); | 1792 | GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, entry); |
1790 | rps_peers[entry->index].entry_op_manage = NULL; | 1793 | rps_peers[entry->index].entry_op_manage = NULL; |
1791 | GNUNET_free (entry); | 1794 | GNUNET_free(entry); |
1792 | //if (num_peers_in_round[current_round] == peers_running) | 1795 | //if (num_peers_in_round[current_round] == peers_running) |
1793 | // run_round (); | 1796 | // run_round (); |
1794 | } | 1797 | } |
@@ -1802,52 +1805,52 @@ churn_cb (void *cls, | |||
1802 | * @param prob_go_on_off the probability of the action | 1805 | * @param prob_go_on_off the probability of the action |
1803 | */ | 1806 | */ |
1804 | static void | 1807 | static void |
1805 | manage_service_wrapper (unsigned int i, unsigned int j, | 1808 | manage_service_wrapper(unsigned int i, unsigned int j, |
1806 | enum PEER_ONLINE_DELTA delta, | 1809 | enum PEER_ONLINE_DELTA delta, |
1807 | double prob_go_on_off) | 1810 | double prob_go_on_off) |
1808 | { | 1811 | { |
1809 | struct OpListEntry *entry = NULL; | 1812 | struct OpListEntry *entry = NULL; |
1810 | uint32_t prob; | 1813 | uint32_t prob; |
1811 | 1814 | ||
1812 | /* make sure that management operation is not already scheduled */ | 1815 | /* make sure that management operation is not already scheduled */ |
1813 | if (NULL != rps_peers[j].entry_op_manage) | 1816 | if (NULL != rps_peers[j].entry_op_manage) |
1814 | { | 1817 | { |
1815 | return; | 1818 | return; |
1816 | } | 1819 | } |
1817 | 1820 | ||
1818 | prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 1821 | prob = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
1819 | UINT32_MAX); | 1822 | UINT32_MAX); |
1820 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1823 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1821 | "%u. selected peer (%u: %s) is %s.\n", | 1824 | "%u. selected peer (%u: %s) is %s.\n", |
1822 | i, | 1825 | i, |
1823 | j, | 1826 | j, |
1824 | GNUNET_i2s (rps_peers[j].peer_id), | 1827 | GNUNET_i2s(rps_peers[j].peer_id), |
1825 | (PEER_GO_ONLINE == delta) ? "online" : "offline"); | 1828 | (PEER_GO_ONLINE == delta) ? "online" : "offline"); |
1826 | if (prob < prob_go_on_off * UINT32_MAX) | 1829 | if (prob < prob_go_on_off * UINT32_MAX) |
1827 | { | 1830 | { |
1828 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1831 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1829 | "%s goes %s\n", | 1832 | "%s goes %s\n", |
1830 | GNUNET_i2s (rps_peers[j].peer_id), | 1833 | GNUNET_i2s(rps_peers[j].peer_id), |
1831 | (PEER_GO_OFFLINE == delta) ? "offline" : "online"); | 1834 | (PEER_GO_OFFLINE == delta) ? "offline" : "online"); |
1832 | 1835 | ||
1833 | if (PEER_GO_OFFLINE == delta) | 1836 | if (PEER_GO_OFFLINE == delta) |
1834 | cancel_pending_req_rep (&rps_peers[j]); | 1837 | cancel_pending_req_rep(&rps_peers[j]); |
1835 | entry = make_oplist_entry (); | 1838 | entry = make_oplist_entry(); |
1836 | entry->delta = delta; | 1839 | entry->delta = delta; |
1837 | entry->index = j; | 1840 | entry->index = j; |
1838 | entry->op = GNUNET_TESTBED_peer_manage_service (NULL, | 1841 | entry->op = GNUNET_TESTBED_peer_manage_service(NULL, |
1839 | testbed_peers[j], | 1842 | testbed_peers[j], |
1840 | "rps", | 1843 | "rps", |
1841 | &churn_cb, | 1844 | &churn_cb, |
1842 | entry, | 1845 | entry, |
1843 | (PEER_GO_OFFLINE == delta) ? 0 : 1); | 1846 | (PEER_GO_OFFLINE == delta) ? 0 : 1); |
1844 | rps_peers[j].entry_op_manage = entry; | 1847 | rps_peers[j].entry_op_manage = entry; |
1845 | } | 1848 | } |
1846 | } | 1849 | } |
1847 | 1850 | ||
1848 | 1851 | ||
1849 | static void | 1852 | static void |
1850 | churn (void *cls) | 1853 | churn(void *cls) |
1851 | { | 1854 | { |
1852 | unsigned int i; | 1855 | unsigned int i; |
1853 | unsigned int j; | 1856 | unsigned int j; |
@@ -1856,74 +1859,75 @@ churn (void *cls) | |||
1856 | double prob_go_offline; | 1859 | double prob_go_offline; |
1857 | double portion_go_online; | 1860 | double portion_go_online; |
1858 | double portion_go_offline; | 1861 | double portion_go_offline; |
1859 | (void) cls; | 1862 | |
1863 | (void)cls; | ||
1860 | 1864 | ||
1861 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | 1865 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1862 | { | 1866 | { |
1863 | return; | 1867 | return; |
1864 | } | 1868 | } |
1865 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1869 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1866 | "Churn function executing\n"); | 1870 | "Churn function executing\n"); |
1867 | 1871 | ||
1868 | churn_task = NULL; /* Should be invalid by now */ | 1872 | churn_task = NULL; /* Should be invalid by now */ |
1869 | 1873 | ||
1870 | /* Compute the probability for an online peer to go offline | 1874 | /* Compute the probability for an online peer to go offline |
1871 | * this round */ | 1875 | * this round */ |
1872 | portion_online = num_peers_online * 1.0 / num_peers; | 1876 | portion_online = num_peers_online * 1.0 / num_peers; |
1873 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1877 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1874 | "Portion online: %f\n", | 1878 | "Portion online: %f\n", |
1875 | portion_online); | 1879 | portion_online); |
1876 | portion_go_online = ((1 - portion_online) * .5 * .66); | 1880 | portion_go_online = ((1 - portion_online) * .5 * .66); |
1877 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1881 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1878 | "Portion that should go online: %f\n", | 1882 | "Portion that should go online: %f\n", |
1879 | portion_go_online); | 1883 | portion_go_online); |
1880 | portion_go_offline = (portion_online + portion_go_online) - .75; | 1884 | portion_go_offline = (portion_online + portion_go_online) - .75; |
1881 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1885 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1882 | "Portion that probably goes offline: %f\n", | 1886 | "Portion that probably goes offline: %f\n", |
1883 | portion_go_offline); | 1887 | portion_go_offline); |
1884 | prob_go_offline = portion_go_offline / (portion_online * .5); | 1888 | prob_go_offline = portion_go_offline / (portion_online * .5); |
1885 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1889 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1886 | "Probability of a selected online peer to go offline: %f\n", | 1890 | "Probability of a selected online peer to go offline: %f\n", |
1887 | prob_go_offline); | 1891 | prob_go_offline); |
1888 | 1892 | ||
1889 | permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, | 1893 | permut = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_WEAK, |
1890 | (unsigned int) num_peers); | 1894 | (unsigned int)num_peers); |
1891 | 1895 | ||
1892 | /* Go over 50% randomly chosen peers */ | 1896 | /* Go over 50% randomly chosen peers */ |
1893 | for (i = 0; i < .5 * num_peers; i++) | 1897 | for (i = 0; i < .5 * num_peers; i++) |
1894 | { | ||
1895 | j = permut[i]; | ||
1896 | |||
1897 | /* If online, shut down with certain probability */ | ||
1898 | if (GNUNET_YES == rps_peers[j].online) | ||
1899 | { | ||
1900 | manage_service_wrapper (i, j, -1, prob_go_offline); | ||
1901 | } | ||
1902 | |||
1903 | /* If offline, restart with certain probability */ | ||
1904 | else if (GNUNET_NO == rps_peers[j].online) | ||
1905 | { | 1898 | { |
1906 | manage_service_wrapper (i, j, 1, 0.66); | 1899 | j = permut[i]; |
1900 | |||
1901 | /* If online, shut down with certain probability */ | ||
1902 | if (GNUNET_YES == rps_peers[j].online) | ||
1903 | { | ||
1904 | manage_service_wrapper(i, j, -1, prob_go_offline); | ||
1905 | } | ||
1906 | |||
1907 | /* If offline, restart with certain probability */ | ||
1908 | else if (GNUNET_NO == rps_peers[j].online) | ||
1909 | { | ||
1910 | manage_service_wrapper(i, j, 1, 0.66); | ||
1911 | } | ||
1907 | } | 1912 | } |
1908 | } | ||
1909 | 1913 | ||
1910 | GNUNET_free (permut); | 1914 | GNUNET_free(permut); |
1911 | 1915 | ||
1912 | churn_task = GNUNET_SCHEDULER_add_delayed ( | 1916 | churn_task = GNUNET_SCHEDULER_add_delayed( |
1913 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), | 1917 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), |
1914 | churn, | 1918 | churn, |
1915 | NULL); | 1919 | NULL); |
1916 | } | 1920 | } |
1917 | 1921 | ||
1918 | 1922 | ||
1919 | /** | 1923 | /** |
1920 | * Initialise given RPSPeer | 1924 | * Initialise given RPSPeer |
1921 | */ | 1925 | */ |
1922 | static void profiler_init_peer (struct RPSPeer *rps_peer) | 1926 | static void profiler_init_peer(struct RPSPeer *rps_peer) |
1923 | { | 1927 | { |
1924 | rps_peer->num_ids_to_request = cur_test_run.num_requests; | 1928 | rps_peer->num_ids_to_request = cur_test_run.num_requests; |
1925 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "peer shall request %i peers\n", | 1929 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "peer shall request %i peers\n", |
1926 | rps_peer->num_ids_to_request); | 1930 | rps_peer->num_ids_to_request); |
1927 | } | 1931 | } |
1928 | 1932 | ||
1929 | 1933 | ||
@@ -1935,7 +1939,7 @@ static void profiler_init_peer (struct RPSPeer *rps_peer) | |||
1935 | * @param recv_peers the received peers | 1939 | * @param recv_peers the received peers |
1936 | */ | 1940 | */ |
1937 | static void | 1941 | static void |
1938 | profiler_reply_handle (void *cls, | 1942 | profiler_reply_handle(void *cls, |
1939 | uint64_t n, | 1943 | uint64_t n, |
1940 | const struct GNUNET_PeerIdentity *recv_peers) | 1944 | const struct GNUNET_PeerIdentity *recv_peers) |
1941 | { | 1945 | { |
@@ -1950,53 +1954,53 @@ profiler_reply_handle (void *cls, | |||
1950 | char *file_name_dhr = file_name_dhr_buf; | 1954 | char *file_name_dhr = file_name_dhr_buf; |
1951 | char *file_name_dhru = file_name_dhru_buf; | 1955 | char *file_name_dhru = file_name_dhru_buf; |
1952 | unsigned int i; | 1956 | unsigned int i; |
1953 | struct PendingReply *pending_rep = (struct PendingReply *) cls; | 1957 | struct PendingReply *pending_rep = (struct PendingReply *)cls; |
1954 | 1958 | ||
1955 | pending_rep->req_handle = NULL; | 1959 | pending_rep->req_handle = NULL; |
1956 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "profiler_reply_handle()\n"); | 1960 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "profiler_reply_handle()\n"); |
1957 | rps_peer = pending_rep->rps_peer; | 1961 | rps_peer = pending_rep->rps_peer; |
1958 | (void) GNUNET_asprintf (&file_name, | 1962 | (void)GNUNET_asprintf(&file_name, |
1959 | "/tmp/rps/received_ids-%u", | 1963 | "/tmp/rps/received_ids-%u", |
1960 | rps_peer->index); | 1964 | rps_peer->index); |
1961 | 1965 | ||
1962 | (void) GNUNET_asprintf (&file_name_dh, | 1966 | (void)GNUNET_asprintf(&file_name_dh, |
1963 | "/tmp/rps/diehard_input-%u", | 1967 | "/tmp/rps/diehard_input-%u", |
1964 | rps_peer->index); | 1968 | rps_peer->index); |
1965 | (void) GNUNET_asprintf (&file_name_dhr, | 1969 | (void)GNUNET_asprintf(&file_name_dhr, |
1966 | "/tmp/rps/diehard_input_raw-%u", | 1970 | "/tmp/rps/diehard_input_raw-%u", |
1967 | rps_peer->index); | 1971 | rps_peer->index); |
1968 | (void) GNUNET_asprintf (&file_name_dhru, | 1972 | (void)GNUNET_asprintf(&file_name_dhru, |
1969 | "/tmp/rps/diehard_input_raw_aligned-%u", | 1973 | "/tmp/rps/diehard_input_raw_aligned-%u", |
1970 | rps_peer->index); | 1974 | rps_peer->index); |
1971 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1975 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1972 | "[%s] got %" PRIu64 " peers:\n", | 1976 | "[%s] got %" PRIu64 " peers:\n", |
1973 | GNUNET_i2s (rps_peer->peer_id), | 1977 | GNUNET_i2s(rps_peer->peer_id), |
1974 | n); | 1978 | n); |
1975 | for (i = 0; i < n; i++) | 1979 | for (i = 0; i < n; i++) |
1976 | { | 1980 | { |
1977 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1981 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1978 | "%u: %s\n", | 1982 | "%u: %s\n", |
1979 | i, | 1983 | i, |
1980 | GNUNET_i2s (&recv_peers[i])); | 1984 | GNUNET_i2s(&recv_peers[i])); |
1981 | tofile (file_name, | 1985 | tofile(file_name, |
1982 | "%s\n", | 1986 | "%s\n", |
1983 | GNUNET_i2s_full (&recv_peers[i])); | 1987 | GNUNET_i2s_full(&recv_peers[i])); |
1984 | rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get (peer_map, &recv_peers[i]); | 1988 | rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get(peer_map, &recv_peers[i]); |
1985 | GNUNET_assert (NULL != rcv_rps_peer); | 1989 | GNUNET_assert(NULL != rcv_rps_peer); |
1986 | tofile (file_name_dh, | 1990 | tofile(file_name_dh, |
1987 | "%" PRIu32 "\n", | 1991 | "%" PRIu32 "\n", |
1988 | (uint32_t) rcv_rps_peer->index); | 1992 | (uint32_t)rcv_rps_peer->index); |
1989 | #ifdef TO_FILE | 1993 | #ifdef TO_FILE |
1990 | to_file_raw (file_name_dhr, | 1994 | to_file_raw(file_name_dhr, |
1991 | (char *) &rcv_rps_peer->index, | 1995 | (char *)&rcv_rps_peer->index, |
1992 | sizeof (uint32_t)); | 1996 | sizeof(uint32_t)); |
1993 | to_file_raw_unaligned (file_name_dhru, | 1997 | to_file_raw_unaligned(file_name_dhru, |
1994 | (char *) &rcv_rps_peer->index, | 1998 | (char *)&rcv_rps_peer->index, |
1995 | sizeof (uint32_t), | 1999 | sizeof(uint32_t), |
1996 | bits_needed); | 2000 | bits_needed); |
1997 | #endif /* TO_FILE */ | 2001 | #endif /* TO_FILE */ |
1998 | } | 2002 | } |
1999 | default_reply_handle (cls, n, recv_peers); | 2003 | default_reply_handle(cls, n, recv_peers); |
2000 | } | 2004 | } |
2001 | 2005 | ||
2002 | 2006 | ||
@@ -2008,10 +2012,10 @@ profiler_reply_handle (void *cls, | |||
2008 | * @param recv_peers the received peers | 2012 | * @param recv_peers the received peers |
2009 | */ | 2013 | */ |
2010 | static void | 2014 | static void |
2011 | profiler_reply_handle_info (void *cls, | 2015 | profiler_reply_handle_info(void *cls, |
2012 | const struct GNUNET_PeerIdentity *recv_peer, | 2016 | const struct GNUNET_PeerIdentity *recv_peer, |
2013 | double probability, | 2017 | double probability, |
2014 | uint32_t num_observed) | 2018 | uint32_t num_observed) |
2015 | { | 2019 | { |
2016 | struct RPSPeer *rps_peer; | 2020 | struct RPSPeer *rps_peer; |
2017 | struct RPSPeer *rcv_rps_peer; | 2021 | struct RPSPeer *rcv_rps_peer; |
@@ -2024,80 +2028,82 @@ profiler_reply_handle_info (void *cls, | |||
2024 | char *file_name_dhr = file_name_dhr_buf; | 2028 | char *file_name_dhr = file_name_dhr_buf; |
2025 | char *file_name_dhru = file_name_dhru_buf; | 2029 | char *file_name_dhru = file_name_dhru_buf; |
2026 | unsigned int i; | 2030 | unsigned int i; |
2027 | struct PendingReply *pending_rep = (struct PendingReply *) cls; | 2031 | struct PendingReply *pending_rep = (struct PendingReply *)cls; |
2028 | 2032 | ||
2029 | pending_rep->req_handle = NULL; | 2033 | pending_rep->req_handle = NULL; |
2030 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "profiler_reply_handle()\n"); | 2034 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "profiler_reply_handle()\n"); |
2031 | rps_peer = pending_rep->rps_peer; | 2035 | rps_peer = pending_rep->rps_peer; |
2032 | (void) GNUNET_asprintf (&file_name, | 2036 | (void)GNUNET_asprintf(&file_name, |
2033 | "/tmp/rps/received_ids-%u", | 2037 | "/tmp/rps/received_ids-%u", |
2034 | rps_peer->index); | 2038 | rps_peer->index); |
2035 | 2039 | ||
2036 | (void) GNUNET_asprintf (&file_name_dh, | 2040 | (void)GNUNET_asprintf(&file_name_dh, |
2037 | "/tmp/rps/diehard_input-%u", | 2041 | "/tmp/rps/diehard_input-%u", |
2038 | rps_peer->index); | 2042 | rps_peer->index); |
2039 | (void) GNUNET_asprintf (&file_name_dhr, | 2043 | (void)GNUNET_asprintf(&file_name_dhr, |
2040 | "/tmp/rps/diehard_input_raw-%u", | 2044 | "/tmp/rps/diehard_input_raw-%u", |
2041 | rps_peer->index); | 2045 | rps_peer->index); |
2042 | (void) GNUNET_asprintf (&file_name_dhru, | 2046 | (void)GNUNET_asprintf(&file_name_dhru, |
2043 | "/tmp/rps/diehard_input_raw_aligned-%u", | 2047 | "/tmp/rps/diehard_input_raw_aligned-%u", |
2044 | rps_peer->index); | 2048 | rps_peer->index); |
2045 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2049 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2046 | "[%s] got peer with info:\n", | 2050 | "[%s] got peer with info:\n", |
2047 | GNUNET_i2s (rps_peer->peer_id)); | 2051 | GNUNET_i2s(rps_peer->peer_id)); |
2048 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2052 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2049 | " %s\n", | 2053 | " %s\n", |
2050 | GNUNET_i2s (recv_peer)); | 2054 | GNUNET_i2s(recv_peer)); |
2051 | tofile (file_name, | 2055 | tofile(file_name, |
2052 | "%s %d %" PRIu32 " \n", | 2056 | "%s %d %" PRIu32 " \n", |
2053 | GNUNET_i2s_full (recv_peer), | 2057 | GNUNET_i2s_full(recv_peer), |
2054 | probability, | 2058 | probability, |
2055 | num_observed); | 2059 | num_observed); |
2056 | rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get (peer_map, recv_peer); | 2060 | rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get(peer_map, recv_peer); |
2057 | GNUNET_assert (NULL != rcv_rps_peer); | 2061 | GNUNET_assert(NULL != rcv_rps_peer); |
2058 | tofile (file_name_dh, | 2062 | tofile(file_name_dh, |
2059 | "%" PRIu32 "\n", | 2063 | "%" PRIu32 "\n", |
2060 | (uint32_t) rcv_rps_peer->index); | 2064 | (uint32_t)rcv_rps_peer->index); |
2061 | #ifdef TO_FILE | 2065 | #ifdef TO_FILE |
2062 | to_file_raw (file_name_dhr, | 2066 | to_file_raw(file_name_dhr, |
2063 | (char *) &rcv_rps_peer->index, | 2067 | (char *)&rcv_rps_peer->index, |
2064 | sizeof (uint32_t)); | 2068 | sizeof(uint32_t)); |
2065 | to_file_raw_unaligned (file_name_dhru, | 2069 | to_file_raw_unaligned(file_name_dhru, |
2066 | (char *) &rcv_rps_peer->index, | 2070 | (char *)&rcv_rps_peer->index, |
2067 | sizeof (uint32_t), | 2071 | sizeof(uint32_t), |
2068 | bits_needed); | 2072 | bits_needed); |
2069 | #endif /* TO_FILE */ | 2073 | #endif /* TO_FILE */ |
2070 | default_reply_handle (cls, 1, recv_peer); | 2074 | default_reply_handle(cls, 1, recv_peer); |
2071 | } | 2075 | } |
2072 | 2076 | ||
2073 | 2077 | ||
2074 | static void | 2078 | static void |
2075 | profiler_cb (struct RPSPeer *rps_peer) | 2079 | profiler_cb(struct RPSPeer *rps_peer) |
2076 | { | 2080 | { |
2077 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | 2081 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
2078 | { | 2082 | { |
2079 | return; | 2083 | return; |
2080 | } | 2084 | } |
2081 | 2085 | ||
2082 | /* Start churn */ | 2086 | /* Start churn */ |
2083 | if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) | 2087 | if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) |
2084 | { | 2088 | { |
2085 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2089 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2086 | "Starting churn task\n"); | 2090 | "Starting churn task\n"); |
2087 | churn_task = GNUNET_SCHEDULER_add_delayed ( | 2091 | churn_task = GNUNET_SCHEDULER_add_delayed( |
2088 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), | 2092 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), |
2089 | churn, | 2093 | churn, |
2090 | NULL); | 2094 | NULL); |
2091 | } else { | 2095 | } |
2092 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2096 | else |
2093 | "Not starting churn task\n"); | 2097 | { |
2094 | } | 2098 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2099 | "Not starting churn task\n"); | ||
2100 | } | ||
2095 | 2101 | ||
2096 | /* Only request peer ids at one peer. | 2102 | /* Only request peer ids at one peer. |
2097 | * (It's the before-last because last one is target of the focussed attack.) | 2103 | * (It's the before-last because last one is target of the focussed attack.) |
2098 | */ | 2104 | */ |
2099 | if (0 < rps_peer->num_ids_to_request) | 2105 | if (0 < rps_peer->num_ids_to_request) |
2100 | schedule_missing_requests (rps_peer); | 2106 | schedule_missing_requests(rps_peer); |
2101 | } | 2107 | } |
2102 | 2108 | ||
2103 | /** | 2109 | /** |
@@ -2110,29 +2116,29 @@ profiler_cb (struct RPSPeer *rps_peer) | |||
2110 | * #GNUNET_SYSERR to abort iteration with error! | 2116 | * #GNUNET_SYSERR to abort iteration with error! |
2111 | */ | 2117 | */ |
2112 | static int | 2118 | static int |
2113 | file_name_cb (void *cls, const char *filename) | 2119 | file_name_cb(void *cls, const char *filename) |
2114 | { | 2120 | { |
2115 | if (NULL != strstr (filename, "sampler_el")) | 2121 | if (NULL != strstr(filename, "sampler_el")) |
2116 | { | ||
2117 | struct RPS_SamplerElement *s_elem; | ||
2118 | struct GNUNET_CRYPTO_AuthKey auth_key; | ||
2119 | const char *key_char; | ||
2120 | uint32_t i; | ||
2121 | (void) cls; | ||
2122 | |||
2123 | key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */ | ||
2124 | tofile (filename, "--------------------------\n"); | ||
2125 | |||
2126 | auth_key = string_to_auth_key (key_char); | ||
2127 | s_elem = RPS_sampler_elem_create (); | ||
2128 | RPS_sampler_elem_set (s_elem, auth_key); | ||
2129 | |||
2130 | for (i = 0; i < num_peers; i++) | ||
2131 | { | 2122 | { |
2132 | RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]); | 2123 | struct RPS_SamplerElement *s_elem; |
2124 | struct GNUNET_CRYPTO_AuthKey auth_key; | ||
2125 | const char *key_char; | ||
2126 | uint32_t i; | ||
2127 | (void)cls; | ||
2128 | |||
2129 | key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */ | ||
2130 | tofile(filename, "--------------------------\n"); | ||
2131 | |||
2132 | auth_key = string_to_auth_key(key_char); | ||
2133 | s_elem = RPS_sampler_elem_create(); | ||
2134 | RPS_sampler_elem_set(s_elem, auth_key); | ||
2135 | |||
2136 | for (i = 0; i < num_peers; i++) | ||
2137 | { | ||
2138 | RPS_sampler_elem_next(s_elem, &rps_peer_ids[i]); | ||
2139 | } | ||
2140 | RPS_sampler_elem_destroy(s_elem); | ||
2133 | } | 2141 | } |
2134 | RPS_sampler_elem_destroy (s_elem); | ||
2135 | } | ||
2136 | return GNUNET_OK; | 2142 | return GNUNET_OK; |
2137 | } | 2143 | } |
2138 | 2144 | ||
@@ -2142,17 +2148,17 @@ file_name_cb (void *cls, const char *filename) | |||
2142 | * Compute all perfect samples. | 2148 | * Compute all perfect samples. |
2143 | */ | 2149 | */ |
2144 | static int | 2150 | static int |
2145 | profiler_eval (void) | 2151 | profiler_eval(void) |
2146 | { | 2152 | { |
2147 | #ifdef TO_FILE | 2153 | #ifdef TO_FILE |
2148 | /* Compute perfect sample for each sampler element */ | 2154 | /* Compute perfect sample for each sampler element */ |
2149 | if (-1 == GNUNET_DISK_directory_scan ("/tmp/rps/", file_name_cb, NULL)) | 2155 | if (-1 == GNUNET_DISK_directory_scan("/tmp/rps/", file_name_cb, NULL)) |
2150 | { | 2156 | { |
2151 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n"); | 2157 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n"); |
2152 | } | 2158 | } |
2153 | #endif /* TO_FILE */ | 2159 | #endif /* TO_FILE */ |
2154 | 2160 | ||
2155 | return evaluate (); | 2161 | return evaluate(); |
2156 | } | 2162 | } |
2157 | 2163 | ||
2158 | 2164 | ||
@@ -2163,39 +2169,40 @@ profiler_eval (void) | |||
2163 | * | 2169 | * |
2164 | * @return | 2170 | * @return |
2165 | */ | 2171 | */ |
2166 | static int is_in_view (uint32_t a, uint32_t b) | 2172 | static int is_in_view(uint32_t a, uint32_t b) |
2167 | { | 2173 | { |
2168 | uint32_t i; | 2174 | uint32_t i; |
2175 | |||
2169 | for (i = 0; i < rps_peers[a].cur_view_count; i++) | 2176 | for (i = 0; i < rps_peers[a].cur_view_count; i++) |
2170 | { | ||
2171 | if (0 == memcmp (rps_peers[b].peer_id, | ||
2172 | &rps_peers[a].cur_view[i], | ||
2173 | sizeof (struct GNUNET_PeerIdentity))) | ||
2174 | { | 2177 | { |
2175 | return GNUNET_YES; | 2178 | if (0 == memcmp(rps_peers[b].peer_id, |
2179 | &rps_peers[a].cur_view[i], | ||
2180 | sizeof(struct GNUNET_PeerIdentity))) | ||
2181 | { | ||
2182 | return GNUNET_YES; | ||
2183 | } | ||
2176 | } | 2184 | } |
2177 | } | ||
2178 | return GNUNET_NO; | 2185 | return GNUNET_NO; |
2179 | } | 2186 | } |
2180 | 2187 | ||
2181 | static uint32_t get_idx_of_pid (const struct GNUNET_PeerIdentity *pid) | 2188 | static uint32_t get_idx_of_pid(const struct GNUNET_PeerIdentity *pid) |
2182 | { | 2189 | { |
2183 | uint32_t i; | 2190 | uint32_t i; |
2184 | 2191 | ||
2185 | for (i = 0; i < num_peers; i++) | 2192 | for (i = 0; i < num_peers; i++) |
2186 | { | ||
2187 | if (0 == memcmp (pid, | ||
2188 | rps_peers[i].peer_id, | ||
2189 | sizeof (struct GNUNET_PeerIdentity))) | ||
2190 | { | 2193 | { |
2191 | return i; | 2194 | if (0 == memcmp(pid, |
2195 | rps_peers[i].peer_id, | ||
2196 | sizeof(struct GNUNET_PeerIdentity))) | ||
2197 | { | ||
2198 | return i; | ||
2199 | } | ||
2192 | } | 2200 | } |
2193 | } | ||
2194 | //return 0; /* Should not happen - make compiler happy */ | 2201 | //return 0; /* Should not happen - make compiler happy */ |
2195 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2202 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2196 | "No known _PeerIdentity %s!\n", | 2203 | "No known _PeerIdentity %s!\n", |
2197 | GNUNET_i2s_full (pid)); | 2204 | GNUNET_i2s_full(pid)); |
2198 | GNUNET_assert (0); | 2205 | GNUNET_assert(0); |
2199 | } | 2206 | } |
2200 | 2207 | ||
2201 | /** | 2208 | /** |
@@ -2206,20 +2213,20 @@ static uint32_t get_idx_of_pid (const struct GNUNET_PeerIdentity *pid) | |||
2206 | * | 2213 | * |
2207 | * @return | 2214 | * @return |
2208 | */ | 2215 | */ |
2209 | static uint32_t count_containing_views (uint32_t a, uint32_t b) | 2216 | static uint32_t count_containing_views(uint32_t a, uint32_t b) |
2210 | { | 2217 | { |
2211 | uint32_t i; | 2218 | uint32_t i; |
2212 | uint32_t peer_idx; | 2219 | uint32_t peer_idx; |
2213 | uint32_t count = 0; | 2220 | uint32_t count = 0; |
2214 | 2221 | ||
2215 | for (i = 0; i < rps_peers[a].cur_view_count; i++) | 2222 | for (i = 0; i < rps_peers[a].cur_view_count; i++) |
2216 | { | ||
2217 | peer_idx = get_idx_of_pid (&rps_peers[a].cur_view[i]); | ||
2218 | if (GNUNET_YES == is_in_view (peer_idx, b)) | ||
2219 | { | 2223 | { |
2220 | count++; | 2224 | peer_idx = get_idx_of_pid(&rps_peers[a].cur_view[i]); |
2225 | if (GNUNET_YES == is_in_view(peer_idx, b)) | ||
2226 | { | ||
2227 | count++; | ||
2228 | } | ||
2221 | } | 2229 | } |
2222 | } | ||
2223 | return count; | 2230 | return count; |
2224 | } | 2231 | } |
2225 | 2232 | ||
@@ -2229,13 +2236,13 @@ static uint32_t count_containing_views (uint32_t a, uint32_t b) | |||
2229 | * | 2236 | * |
2230 | * @param peer_idx index of the peer that is about to sample | 2237 | * @param peer_idx index of the peer that is about to sample |
2231 | */ | 2238 | */ |
2232 | static void compute_probabilities (uint32_t peer_idx) | 2239 | static void compute_probabilities(uint32_t peer_idx) |
2233 | { | 2240 | { |
2234 | //double probs[num_peers] = { 0 }; | 2241 | //double probs[num_peers] = { 0 }; |
2235 | double probs[num_peers]; | 2242 | double probs[num_peers]; |
2236 | double probs_hist[num_peers]; /* Probability respecting the history */ | 2243 | double probs_hist[num_peers]; /* Probability respecting the history */ |
2237 | size_t probs_as_str_size = (num_peers * 10 + 2) * sizeof (char); | 2244 | size_t probs_as_str_size = (num_peers * 10 + 2) * sizeof(char); |
2238 | char *probs_as_str = GNUNET_malloc (probs_as_str_size); | 2245 | char *probs_as_str = GNUNET_malloc(probs_as_str_size); |
2239 | char *probs_as_str_cpy; | 2246 | char *probs_as_str_cpy; |
2240 | uint32_t i; | 2247 | uint32_t i; |
2241 | double prob_push; | 2248 | double prob_push; |
@@ -2247,139 +2254,143 @@ static void compute_probabilities (uint32_t peer_idx) | |||
2247 | double sum_non_zero_prob = 0; | 2254 | double sum_non_zero_prob = 0; |
2248 | double sum_non_zero_prob_hist = 0; | 2255 | double sum_non_zero_prob_hist = 0; |
2249 | 2256 | ||
2250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2257 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2251 | "Computing probabilities for peer %" PRIu32 "\n", peer_idx); | 2258 | "Computing probabilities for peer %" PRIu32 "\n", peer_idx); |
2252 | /* Firstly without knowledge of old views */ | 2259 | /* Firstly without knowledge of old views */ |
2253 | for (i = 0; i < num_peers; i++) | 2260 | for (i = 0; i < num_peers; i++) |
2254 | { | 2261 | { |
2255 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2262 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2256 | "\tfor peer %" PRIu32 ":\n", i); | 2263 | "\tfor peer %" PRIu32 ":\n", i); |
2257 | view_size = rps_peers[i].cur_view_count; | 2264 | view_size = rps_peers[i].cur_view_count; |
2258 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2265 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2259 | "\t\tview_size: %" PRIu32 "\n", view_size); | 2266 | "\t\tview_size: %" PRIu32 "\n", view_size); |
2260 | /* For peer i the probability of being sampled is | 2267 | /* For peer i the probability of being sampled is |
2261 | * evenly distributed among all possibly observed peers. */ | 2268 | * evenly distributed among all possibly observed peers. */ |
2262 | /* We could have observed a peer in three cases: | 2269 | /* We could have observed a peer in three cases: |
2263 | * 1. peer sent a push | 2270 | * 1. peer sent a push |
2264 | * 2. peer was contained in a pull reply | 2271 | * 2. peer was contained in a pull reply |
2265 | * 3. peer was in history (sampler) - ignored for now */ | 2272 | * 3. peer was in history (sampler) - ignored for now */ |
2266 | /* 1. Probability of having received a push from peer i */ | 2273 | /* 1. Probability of having received a push from peer i */ |
2267 | if ((GNUNET_YES == is_in_view (i, peer_idx)) && | 2274 | if ((GNUNET_YES == is_in_view(i, peer_idx)) && |
2268 | (1 <= (0.45 * view_size))) | 2275 | (1 <= (0.45 * view_size))) |
2269 | { | 2276 | { |
2270 | if (0 == binom (view_size, 0.45 * view_size)) prob_push = 0; | 2277 | if (0 == binom(view_size, 0.45 * view_size)) |
2278 | prob_push = 0; | ||
2279 | else | ||
2280 | { | ||
2281 | prob_push = 1.0 * binom(0.45 * view_size, 1) | ||
2282 | / | ||
2283 | binom(view_size, 0.45 * view_size); | ||
2284 | } | ||
2285 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2286 | "\t\t%" PRIu32 " is in %" PRIu32 "'s view, prob: %f\n", | ||
2287 | peer_idx, | ||
2288 | i, | ||
2289 | prob_push); | ||
2290 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2291 | "\t\tposs choices from view: %" PRIu32 ", containing i: %" PRIu32 "\n", | ||
2292 | binom(view_size, 0.45 * view_size), | ||
2293 | binom(0.45 * view_size, 1)); | ||
2294 | } | ||
2295 | else | ||
2296 | { | ||
2297 | prob_push = 0; | ||
2298 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2299 | "\t\t%" PRIu32 " is not in %" PRIu32 "'s view, prob: 0\n", | ||
2300 | peer_idx, | ||
2301 | i); | ||
2302 | } | ||
2303 | /* 2. Probability of peer i being contained in pulls */ | ||
2304 | view_size = rps_peers[peer_idx].cur_view_count; | ||
2305 | cont_views = count_containing_views(peer_idx, i); | ||
2306 | number_of_being_in_pull_events = | ||
2307 | (binom(view_size, 0.45 * view_size) - | ||
2308 | binom(view_size - cont_views, 0.45 * view_size)); | ||
2309 | if (0 != number_of_being_in_pull_events) | ||
2310 | { | ||
2311 | prob_pull = number_of_being_in_pull_events | ||
2312 | / | ||
2313 | (1.0 * binom(view_size, 0.45 * view_size)); | ||
2314 | } | ||
2271 | else | 2315 | else |
2272 | { | 2316 | { |
2273 | prob_push = 1.0 * binom (0.45 * view_size, 1) | 2317 | prob_pull = 0; |
2274 | / | 2318 | } |
2275 | binom (view_size, 0.45 * view_size); | 2319 | probs[i] = prob_push + prob_pull - (prob_push * prob_pull); |
2276 | } | 2320 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2277 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2321 | "\t\t%" PRIu32 " has %" PRIu32 " of %" PRIu32 |
2278 | "\t\t%" PRIu32 " is in %" PRIu32 "'s view, prob: %f\n", | 2322 | " peers in its view who know %" PRIu32 " prob: %f\n", |
2279 | peer_idx, | 2323 | peer_idx, |
2324 | cont_views, | ||
2325 | view_size, | ||
2280 | i, | 2326 | i, |
2281 | prob_push); | 2327 | prob_pull); |
2282 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2328 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2283 | "\t\tposs choices from view: %" PRIu32 ", containing i: %" PRIu32 "\n", | 2329 | "\t\tnumber of possible pull combinations: %" PRIu32 "\n", |
2284 | binom (view_size, 0.45 * view_size), | 2330 | binom(view_size, 0.45 * view_size)); |
2285 | binom (0.45 * view_size, 1)); | 2331 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2286 | } else { | 2332 | "\t\tnumber of possible pull combinations without %" PRIu32 |
2287 | prob_push = 0; | 2333 | ": %" PRIu32 "\n", |
2288 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2334 | i, |
2289 | "\t\t%" PRIu32 " is not in %" PRIu32 "'s view, prob: 0\n", | 2335 | binom(view_size - cont_views, 0.45 * view_size)); |
2290 | peer_idx, | 2336 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2291 | i); | 2337 | "\t\tnumber of possible pull combinations with %" PRIu32 |
2292 | } | 2338 | ": %" PRIu32 "\n", |
2293 | /* 2. Probability of peer i being contained in pulls */ | 2339 | i, |
2294 | view_size = rps_peers[peer_idx].cur_view_count; | 2340 | number_of_being_in_pull_events); |
2295 | cont_views = count_containing_views (peer_idx, i); | ||
2296 | number_of_being_in_pull_events = | ||
2297 | (binom (view_size, 0.45 * view_size) - | ||
2298 | binom (view_size - cont_views, 0.45 * view_size)); | ||
2299 | if (0 != number_of_being_in_pull_events) | ||
2300 | { | ||
2301 | prob_pull = number_of_being_in_pull_events | ||
2302 | / | ||
2303 | (1.0 * binom (view_size, 0.45 * view_size)); | ||
2304 | } else | ||
2305 | { | ||
2306 | prob_pull = 0; | ||
2307 | } | ||
2308 | probs[i] = prob_push + prob_pull - (prob_push * prob_pull); | ||
2309 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2310 | "\t\t%" PRIu32 " has %" PRIu32 " of %" PRIu32 | ||
2311 | " peers in its view who know %" PRIu32 " prob: %f\n", | ||
2312 | peer_idx, | ||
2313 | cont_views, | ||
2314 | view_size, | ||
2315 | i, | ||
2316 | prob_pull); | ||
2317 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2318 | "\t\tnumber of possible pull combinations: %" PRIu32 "\n", | ||
2319 | binom (view_size, 0.45 * view_size)); | ||
2320 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2321 | "\t\tnumber of possible pull combinations without %" PRIu32 | ||
2322 | ": %" PRIu32 "\n", | ||
2323 | i, | ||
2324 | binom (view_size - cont_views, 0.45 * view_size)); | ||
2325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2326 | "\t\tnumber of possible pull combinations with %" PRIu32 | ||
2327 | ": %" PRIu32 "\n", | ||
2328 | i, | ||
2329 | number_of_being_in_pull_events); | ||
2330 | 2341 | ||
2331 | probs_hist[i] = 0.9 * rps_peers[peer_idx].eval_probs_cache[i] + probs[i]; | 2342 | probs_hist[i] = 0.9 * rps_peers[peer_idx].eval_probs_cache[i] + probs[i]; |
2332 | rps_peers[peer_idx].eval_probs_cache[i] = probs_hist[i]; | 2343 | rps_peers[peer_idx].eval_probs_cache[i] = probs_hist[i]; |
2333 | 2344 | ||
2334 | sum_non_zero_prob += probs[i]; | 2345 | sum_non_zero_prob += probs[i]; |
2335 | sum_non_zero_prob_hist += probs_hist[i]; | 2346 | sum_non_zero_prob_hist += probs_hist[i]; |
2336 | } | 2347 | } |
2337 | /* normalize */ | 2348 | /* normalize */ |
2338 | if (0 != sum_non_zero_prob) | 2349 | if (0 != sum_non_zero_prob) |
2339 | { | ||
2340 | for (i = 0; i < num_peers; i++) | ||
2341 | { | 2350 | { |
2342 | probs[i] = probs[i] * (1.0 / sum_non_zero_prob); | 2351 | for (i = 0; i < num_peers; i++) |
2352 | { | ||
2353 | probs[i] = probs[i] * (1.0 / sum_non_zero_prob); | ||
2354 | } | ||
2343 | } | 2355 | } |
2344 | } | ||
2345 | if (0 != sum_non_zero_prob_hist) | 2356 | if (0 != sum_non_zero_prob_hist) |
2346 | { | ||
2347 | for (i = 0; i < num_peers; i++) | ||
2348 | { | 2357 | { |
2349 | probs_hist[i] = probs_hist[i] * (1.0 / sum_non_zero_prob_hist); | 2358 | for (i = 0; i < num_peers; i++) |
2359 | { | ||
2360 | probs_hist[i] = probs_hist[i] * (1.0 / sum_non_zero_prob_hist); | ||
2361 | } | ||
2350 | } | 2362 | } |
2351 | } | ||
2352 | 2363 | ||
2353 | /* str repr */ | 2364 | /* str repr */ |
2354 | for (i = 0; i < num_peers; i++) | 2365 | for (i = 0; i < num_peers; i++) |
2355 | { | 2366 | { |
2356 | probs_as_str_cpy = GNUNET_strndup (probs_as_str, probs_as_str_size); | 2367 | probs_as_str_cpy = GNUNET_strndup(probs_as_str, probs_as_str_size); |
2357 | tmp = GNUNET_snprintf (probs_as_str, | 2368 | tmp = GNUNET_snprintf(probs_as_str, |
2358 | probs_as_str_size, | 2369 | probs_as_str_size, |
2359 | "%s %7.6f", probs_as_str_cpy, probs[i]); | 2370 | "%s %7.6f", probs_as_str_cpy, probs[i]); |
2360 | GNUNET_free (probs_as_str_cpy); | 2371 | GNUNET_free(probs_as_str_cpy); |
2361 | GNUNET_assert (0 <= tmp); | 2372 | GNUNET_assert(0 <= tmp); |
2362 | } | 2373 | } |
2363 | 2374 | ||
2364 | to_file_w_len (rps_peers[peer_idx].file_name_probs, | 2375 | to_file_w_len(rps_peers[peer_idx].file_name_probs, |
2365 | probs_as_str_size, | 2376 | probs_as_str_size, |
2366 | probs_as_str); | 2377 | probs_as_str); |
2367 | 2378 | ||
2368 | probs_as_str[0] = '\0'; | 2379 | probs_as_str[0] = '\0'; |
2369 | for (i = 0; i < num_peers; i++) | 2380 | for (i = 0; i < num_peers; i++) |
2370 | { | 2381 | { |
2371 | probs_as_str_cpy = GNUNET_strndup (probs_as_str, probs_as_str_size); | 2382 | probs_as_str_cpy = GNUNET_strndup(probs_as_str, probs_as_str_size); |
2372 | tmp = GNUNET_snprintf (probs_as_str, | 2383 | tmp = GNUNET_snprintf(probs_as_str, |
2373 | probs_as_str_size, | 2384 | probs_as_str_size, |
2374 | "%s %7.6f", probs_as_str_cpy, probs_hist[i]); | 2385 | "%s %7.6f", probs_as_str_cpy, probs_hist[i]); |
2375 | GNUNET_free (probs_as_str_cpy); | 2386 | GNUNET_free(probs_as_str_cpy); |
2376 | GNUNET_assert (0 <= tmp); | 2387 | GNUNET_assert(0 <= tmp); |
2377 | } | 2388 | } |
2378 | 2389 | ||
2379 | to_file_w_len (rps_peers[peer_idx].file_name_probs_hist, | 2390 | to_file_w_len(rps_peers[peer_idx].file_name_probs_hist, |
2380 | probs_as_str_size, | 2391 | probs_as_str_size, |
2381 | probs_as_str); | 2392 | probs_as_str); |
2382 | GNUNET_free (probs_as_str); | 2393 | GNUNET_free(probs_as_str); |
2383 | } | 2394 | } |
2384 | 2395 | ||
2385 | /** | 2396 | /** |
@@ -2391,98 +2402,98 @@ static void compute_probabilities (uint32_t peer_idx) | |||
2391 | * | 2402 | * |
2392 | * @return the number of occurrences | 2403 | * @return the number of occurrences |
2393 | */ | 2404 | */ |
2394 | static uint32_t count_peer_in_views_2 (uint32_t peer_idx) | 2405 | static uint32_t count_peer_in_views_2(uint32_t peer_idx) |
2395 | { | 2406 | { |
2396 | uint32_t i, j; | 2407 | uint32_t i, j; |
2397 | uint32_t count = 0; | 2408 | uint32_t count = 0; |
2398 | 2409 | ||
2399 | for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ | 2410 | for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ |
2400 | { | 2411 | { |
2401 | for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */ | 2412 | for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */ |
2402 | { | 2413 | { |
2403 | if (0 == memcmp (rps_peers[peer_idx].peer_id, | 2414 | if (0 == memcmp(rps_peers[peer_idx].peer_id, |
2404 | &rps_peers[i].cur_view[j], | 2415 | &rps_peers[i].cur_view[j], |
2405 | sizeof (struct GNUNET_PeerIdentity))) | 2416 | sizeof(struct GNUNET_PeerIdentity))) |
2406 | { | 2417 | { |
2407 | count++; | 2418 | count++; |
2408 | break; | 2419 | break; |
2409 | } | 2420 | } |
2410 | } | 2421 | } |
2411 | } | 2422 | } |
2412 | rps_peers[peer_idx].count_in_views = count; | 2423 | rps_peers[peer_idx].count_in_views = count; |
2413 | return count; | 2424 | return count; |
2414 | } | 2425 | } |
2415 | 2426 | ||
2416 | static uint32_t cumulated_view_sizes () | 2427 | static uint32_t cumulated_view_sizes() |
2417 | { | 2428 | { |
2418 | uint32_t i; | 2429 | uint32_t i; |
2419 | 2430 | ||
2420 | view_sizes = 0; | 2431 | view_sizes = 0; |
2421 | for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ | 2432 | for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ |
2422 | { | 2433 | { |
2423 | view_sizes += rps_peers[i].cur_view_count; | 2434 | view_sizes += rps_peers[i].cur_view_count; |
2424 | } | 2435 | } |
2425 | return view_sizes; | 2436 | return view_sizes; |
2426 | } | 2437 | } |
2427 | 2438 | ||
2428 | static void count_peer_in_views (uint32_t *count_peers) | 2439 | static void count_peer_in_views(uint32_t *count_peers) |
2429 | { | 2440 | { |
2430 | uint32_t i, j; | 2441 | uint32_t i, j; |
2431 | 2442 | ||
2432 | for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ | 2443 | for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ |
2433 | { | ||
2434 | for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */ | ||
2435 | { | 2444 | { |
2436 | if (0 == memcmp (rps_peers[i].peer_id, | 2445 | for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */ |
2437 | &rps_peers[i].cur_view[j], | 2446 | { |
2438 | sizeof (struct GNUNET_PeerIdentity))) | 2447 | if (0 == memcmp(rps_peers[i].peer_id, |
2439 | { | 2448 | &rps_peers[i].cur_view[j], |
2440 | count_peers[i]++; | 2449 | sizeof(struct GNUNET_PeerIdentity))) |
2441 | } | 2450 | { |
2451 | count_peers[i]++; | ||
2452 | } | ||
2453 | } | ||
2442 | } | 2454 | } |
2443 | } | ||
2444 | } | 2455 | } |
2445 | 2456 | ||
2446 | void compute_diversity () | 2457 | void compute_diversity() |
2447 | { | 2458 | { |
2448 | uint32_t i; | 2459 | uint32_t i; |
2449 | /* ith entry represents the numer of occurrences in other peer's views */ | 2460 | /* ith entry represents the numer of occurrences in other peer's views */ |
2450 | uint32_t *count_peers = GNUNET_new_array (num_peers, uint32_t); | 2461 | uint32_t *count_peers = GNUNET_new_array(num_peers, uint32_t); |
2451 | uint32_t views_total_size; | 2462 | uint32_t views_total_size; |
2452 | double expected; | 2463 | double expected; |
2453 | /* deviation from expected number of peers */ | 2464 | /* deviation from expected number of peers */ |
2454 | double *deviation = GNUNET_new_array (num_peers, double); | 2465 | double *deviation = GNUNET_new_array(num_peers, double); |
2455 | 2466 | ||
2456 | views_total_size = 0; | 2467 | views_total_size = 0; |
2457 | expected = 0; | 2468 | expected = 0; |
2458 | 2469 | ||
2459 | /* For each peer count its representation in other peer's views*/ | 2470 | /* For each peer count its representation in other peer's views*/ |
2460 | for (i = 0; i < num_peers; i++) /* Peer to count */ | 2471 | for (i = 0; i < num_peers; i++) /* Peer to count */ |
2461 | { | 2472 | { |
2462 | views_total_size += rps_peers[i].cur_view_count; | 2473 | views_total_size += rps_peers[i].cur_view_count; |
2463 | count_peer_in_views (count_peers); | 2474 | count_peer_in_views(count_peers); |
2464 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2475 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2465 | "Counted representation of %" PRIu32 "th peer [%s]: %" PRIu32"\n", | 2476 | "Counted representation of %" PRIu32 "th peer [%s]: %" PRIu32 "\n", |
2466 | i, | 2477 | i, |
2467 | GNUNET_i2s (rps_peers[i].peer_id), | 2478 | GNUNET_i2s(rps_peers[i].peer_id), |
2468 | count_peers[i]); | 2479 | count_peers[i]); |
2469 | } | 2480 | } |
2470 | 2481 | ||
2471 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2482 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2472 | "size of all views combined: %" PRIu32 "\n", | 2483 | "size of all views combined: %" PRIu32 "\n", |
2473 | views_total_size); | 2484 | views_total_size); |
2474 | expected = ((double) 1/num_peers) * views_total_size; | 2485 | expected = ((double)1 / num_peers) * views_total_size; |
2475 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2486 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2476 | "Expected number of occurrences of each peer in all views: %f\n", | 2487 | "Expected number of occurrences of each peer in all views: %f\n", |
2477 | expected); | 2488 | expected); |
2478 | for (i = 0; i < num_peers; i++) /* Peer to count */ | 2489 | for (i = 0; i < num_peers; i++) /* Peer to count */ |
2479 | { | 2490 | { |
2480 | deviation[i] = expected - count_peers[i]; | 2491 | deviation[i] = expected - count_peers[i]; |
2481 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2492 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2482 | "Deviation from expectation: %f\n", deviation[i]); | 2493 | "Deviation from expectation: %f\n", deviation[i]); |
2483 | } | 2494 | } |
2484 | GNUNET_free (count_peers); | 2495 | GNUNET_free(count_peers); |
2485 | GNUNET_free (deviation); | 2496 | GNUNET_free(deviation); |
2486 | } | 2497 | } |
2487 | 2498 | ||
2488 | void print_view_sizes() | 2499 | void print_view_sizes() |
@@ -2490,13 +2501,13 @@ void print_view_sizes() | |||
2490 | uint32_t i; | 2501 | uint32_t i; |
2491 | 2502 | ||
2492 | for (i = 0; i < num_peers; i++) /* Peer to count */ | 2503 | for (i = 0; i < num_peers; i++) /* Peer to count */ |
2493 | { | 2504 | { |
2494 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2505 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2495 | "View size of %" PRIu32 ". [%s] is %" PRIu32 "\n", | 2506 | "View size of %" PRIu32 ". [%s] is %" PRIu32 "\n", |
2496 | i, | 2507 | i, |
2497 | GNUNET_i2s (rps_peers[i].peer_id), | 2508 | GNUNET_i2s(rps_peers[i].peer_id), |
2498 | rps_peers[i].cur_view_count); | 2509 | rps_peers[i].cur_view_count); |
2499 | } | 2510 | } |
2500 | } | 2511 | } |
2501 | 2512 | ||
2502 | void all_views_updated_cb() | 2513 | void all_views_updated_cb() |
@@ -2505,180 +2516,181 @@ void all_views_updated_cb() | |||
2505 | print_view_sizes(); | 2516 | print_view_sizes(); |
2506 | } | 2517 | } |
2507 | 2518 | ||
2508 | void view_update_cb (void *cls, | 2519 | void view_update_cb(void *cls, |
2509 | uint64_t view_size, | 2520 | uint64_t view_size, |
2510 | const struct GNUNET_PeerIdentity *peers) | 2521 | const struct GNUNET_PeerIdentity *peers) |
2511 | { | 2522 | { |
2512 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2523 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2513 | "View was updated (%" PRIu64 ")\n", view_size); | 2524 | "View was updated (%" PRIu64 ")\n", view_size); |
2514 | struct RPSPeer *rps_peer = (struct RPSPeer *) cls; | 2525 | struct RPSPeer *rps_peer = (struct RPSPeer *)cls; |
2515 | to_file ("/tmp/rps/view_sizes.txt", | 2526 | to_file("/tmp/rps/view_sizes.txt", |
2516 | "%" PRIu64 " %" PRIu32 "", | 2527 | "%" PRIu64 " %" PRIu32 "", |
2517 | rps_peer->index, | 2528 | rps_peer->index, |
2518 | view_size); | 2529 | view_size); |
2519 | for (uint64_t i = 0; i < view_size; i++) | 2530 | for (uint64_t i = 0; i < view_size; i++) |
2520 | { | 2531 | { |
2521 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2532 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2522 | "\t%s\n", GNUNET_i2s (&peers[i])); | 2533 | "\t%s\n", GNUNET_i2s(&peers[i])); |
2523 | } | 2534 | } |
2524 | GNUNET_array_grow (rps_peer->cur_view, | 2535 | GNUNET_array_grow(rps_peer->cur_view, |
2525 | rps_peer->cur_view_count, | 2536 | rps_peer->cur_view_count, |
2526 | view_size); | 2537 | view_size); |
2527 | //*rps_peer->cur_view = *peers; | 2538 | //*rps_peer->cur_view = *peers; |
2528 | GNUNET_memcpy (rps_peer->cur_view, | 2539 | GNUNET_memcpy(rps_peer->cur_view, |
2529 | peers, | 2540 | peers, |
2530 | view_size * sizeof (struct GNUNET_PeerIdentity)); | 2541 | view_size * sizeof(struct GNUNET_PeerIdentity)); |
2531 | to_file ("/tmp/rps/count_in_views.txt", | 2542 | to_file("/tmp/rps/count_in_views.txt", |
2532 | "%" PRIu64 " %" PRIu32 "", | 2543 | "%" PRIu64 " %" PRIu32 "", |
2533 | rps_peer->index, | 2544 | rps_peer->index, |
2534 | count_peer_in_views_2 (rps_peer->index)); | 2545 | count_peer_in_views_2(rps_peer->index)); |
2535 | cumulated_view_sizes(); | 2546 | cumulated_view_sizes(); |
2536 | if (0 != view_size) | 2547 | if (0 != view_size) |
2537 | { | 2548 | { |
2538 | to_file ("/tmp/rps/repr.txt", | 2549 | to_file("/tmp/rps/repr.txt", |
2539 | "%" PRIu64 /* index */ | 2550 | "%" PRIu64 /* index */ |
2540 | " %" PRIu32 /* occurrence in views */ | 2551 | " %" PRIu32 /* occurrence in views */ |
2541 | " %" PRIu32 /* view sizes */ | 2552 | " %" PRIu32 /* view sizes */ |
2542 | " %f" /* fraction of repr in views */ | 2553 | " %f" /* fraction of repr in views */ |
2543 | " %f" /* average view size */ | 2554 | " %f" /* average view size */ |
2544 | " %f" /* prob of occurrence in view slot */ | 2555 | " %f" /* prob of occurrence in view slot */ |
2545 | " %f" "", /* exp frac of repr in views */ | 2556 | " %f" "", /* exp frac of repr in views */ |
2546 | rps_peer->index, | 2557 | rps_peer->index, |
2547 | count_peer_in_views_2 (rps_peer->index), | 2558 | count_peer_in_views_2(rps_peer->index), |
2548 | view_sizes, | 2559 | view_sizes, |
2549 | count_peer_in_views_2 (rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */ | 2560 | count_peer_in_views_2(rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */ |
2550 | view_sizes / (view_size * 1.0), /* average view size */ | 2561 | view_sizes / (view_size * 1.0), /* average view size */ |
2551 | 1.0 /view_size, /* prob of occurrence in view slot */ | 2562 | 1.0 / view_size, /* prob of occurrence in view slot */ |
2552 | (1.0/view_size) * (view_sizes/view_size) /* expected fraction of repr in views */ | 2563 | (1.0 / view_size) * (view_sizes / view_size) /* expected fraction of repr in views */ |
2553 | ); | 2564 | ); |
2554 | } | 2565 | } |
2555 | compute_probabilities (rps_peer->index); | 2566 | compute_probabilities(rps_peer->index); |
2556 | all_views_updated_cb(); | 2567 | all_views_updated_cb(); |
2557 | } | 2568 | } |
2558 | 2569 | ||
2559 | static void | 2570 | static void |
2560 | pre_profiler (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) | 2571 | pre_profiler(struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) |
2561 | { | 2572 | { |
2562 | rps_peer->file_name_probs = | 2573 | rps_peer->file_name_probs = |
2563 | store_prefix_file_name (rps_peer->index, "probs"); | 2574 | store_prefix_file_name(rps_peer->index, "probs"); |
2564 | rps_peer->file_name_probs_hist = | 2575 | rps_peer->file_name_probs_hist = |
2565 | store_prefix_file_name (rps_peer->index, "probs_hist"); | 2576 | store_prefix_file_name(rps_peer->index, "probs_hist"); |
2566 | GNUNET_RPS_view_request (h, 0, view_update_cb, rps_peer); | 2577 | GNUNET_RPS_view_request(h, 0, view_update_cb, rps_peer); |
2567 | } | 2578 | } |
2568 | 2579 | ||
2569 | void write_final_stats (void){ | 2580 | void write_final_stats(void) |
2581 | { | ||
2570 | uint64_t sums[STAT_TYPE_MAX] = { 0 }; | 2582 | uint64_t sums[STAT_TYPE_MAX] = { 0 }; |
2571 | 2583 | ||
2572 | for (uint32_t i = 0; i < num_peers; i++) | 2584 | for (uint32_t i = 0; i < num_peers; i++) |
2573 | { | 2585 | { |
2574 | to_file ("/tmp/rps/final_stats.csv", | 2586 | to_file("/tmp/rps/final_stats.csv", |
2575 | "%" PRIu32 ", " /* index */ | 2587 | "%" PRIu32 ", " /* index */ |
2576 | "%s, %" /* id */ | 2588 | "%s, %" /* id */ |
2577 | PRIu64 ", %" /* rounds */ | 2589 | PRIu64 ", %" /* rounds */ |
2578 | PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* blocking */ | 2590 | PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* blocking */ |
2579 | PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* issued */ | 2591 | PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* issued */ |
2580 | PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* sent */ | 2592 | PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* sent */ |
2581 | PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* recv */ | 2593 | PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* recv */ |
2582 | PRIu64 ", %" /* view size */ | 2594 | PRIu64 ", %" /* view size */ |
2583 | PRIu64 ", %" /* known peers */ | 2595 | PRIu64 ", %" /* known peers */ |
2584 | PRIu64 ", %" /* valid peers */ | 2596 | PRIu64 ", %" /* valid peers */ |
2585 | PRIu64 ", %" /* learned peers */ | 2597 | PRIu64 ", %" /* learned peers */ |
2586 | PRIu64 ", %" /* pending online checks */ | 2598 | PRIu64 ", %" /* pending online checks */ |
2587 | PRIu64 ", %" /* unrequested pull replies */ | 2599 | PRIu64 ", %" /* unrequested pull replies */ |
2588 | PRIu64 ", %" /* peers in push map */ | 2600 | PRIu64 ", %" /* peers in push map */ |
2589 | PRIu64 ", %" /* peers in pull map */ | 2601 | PRIu64 ", %" /* peers in pull map */ |
2590 | PRIu64 ", %" /* peers in view */ | 2602 | PRIu64 ", %" /* peers in view */ |
2591 | PRIu64 "\n"/* view size aim */, | 2603 | PRIu64 "\n" /* view size aim */, |
2592 | i, | 2604 | i, |
2593 | GNUNET_i2s (rps_peers[i].peer_id), | 2605 | GNUNET_i2s(rps_peers[i].peer_id), |
2594 | rps_peers[i].stats[STAT_TYPE_ROUNDS], | 2606 | rps_peers[i].stats[STAT_TYPE_ROUNDS], |
2595 | rps_peers[i].stats[STAT_TYPE_BLOCKS], | 2607 | rps_peers[i].stats[STAT_TYPE_BLOCKS], |
2596 | rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH], | 2608 | rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH], |
2597 | rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH], | 2609 | rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH], |
2598 | rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PULL], | 2610 | rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PULL], |
2599 | rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL], | 2611 | rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL], |
2600 | rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL], | 2612 | rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL], |
2601 | rps_peers[i].stats[STAT_TYPE_ISSUED_PUSH_SEND], | 2613 | rps_peers[i].stats[STAT_TYPE_ISSUED_PUSH_SEND], |
2602 | rps_peers[i].stats[STAT_TYPE_ISSUED_PUSH_SEND_MH], | 2614 | rps_peers[i].stats[STAT_TYPE_ISSUED_PUSH_SEND_MH], |
2603 | rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REQ], | 2615 | rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REQ], |
2604 | rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REQ_MH], | 2616 | rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REQ_MH], |
2605 | rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REP], | 2617 | rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REP], |
2606 | rps_peers[i].stats[STAT_TYPE_SENT_PUSH_SEND], | 2618 | rps_peers[i].stats[STAT_TYPE_SENT_PUSH_SEND], |
2607 | rps_peers[i].stats[STAT_TYPE_SENT_PULL_REQ], | 2619 | rps_peers[i].stats[STAT_TYPE_SENT_PULL_REQ], |
2608 | rps_peers[i].stats[STAT_TYPE_SENT_PULL_REQ_MH], | 2620 | rps_peers[i].stats[STAT_TYPE_SENT_PULL_REQ_MH], |
2609 | rps_peers[i].stats[STAT_TYPE_SENT_PULL_REP], | 2621 | rps_peers[i].stats[STAT_TYPE_SENT_PULL_REP], |
2610 | rps_peers[i].stats[STAT_TYPE_RECV_PUSH_SEND], | 2622 | rps_peers[i].stats[STAT_TYPE_RECV_PUSH_SEND], |
2611 | rps_peers[i].stats[STAT_TYPE_RECV_PUSH_SEND_MH], | 2623 | rps_peers[i].stats[STAT_TYPE_RECV_PUSH_SEND_MH], |
2612 | rps_peers[i].stats[STAT_TYPE_RECV_PULL_REQ], | 2624 | rps_peers[i].stats[STAT_TYPE_RECV_PULL_REQ], |
2613 | rps_peers[i].stats[STAT_TYPE_RECV_PULL_REQ_MH], | 2625 | rps_peers[i].stats[STAT_TYPE_RECV_PULL_REQ_MH], |
2614 | rps_peers[i].stats[STAT_TYPE_RECV_PULL_REP_MH], | 2626 | rps_peers[i].stats[STAT_TYPE_RECV_PULL_REP_MH], |
2615 | rps_peers[i].stats[STAT_TYPE_RECV_PULL_REP], | 2627 | rps_peers[i].stats[STAT_TYPE_RECV_PULL_REP], |
2616 | rps_peers[i].stats[STAT_TYPE_VIEW_SIZE], | 2628 | rps_peers[i].stats[STAT_TYPE_VIEW_SIZE], |
2617 | rps_peers[i].stats[STAT_TYPE_KNOWN_PEERS], | 2629 | rps_peers[i].stats[STAT_TYPE_KNOWN_PEERS], |
2618 | rps_peers[i].stats[STAT_TYPE_VALID_PEERS], | 2630 | rps_peers[i].stats[STAT_TYPE_VALID_PEERS], |
2619 | rps_peers[i].stats[STAT_TYPE_LEARND_PEERS], | 2631 | rps_peers[i].stats[STAT_TYPE_LEARND_PEERS], |
2620 | rps_peers[i].stats[STAT_TYPE_PENDING_ONLINE_CHECKS], | 2632 | rps_peers[i].stats[STAT_TYPE_PENDING_ONLINE_CHECKS], |
2621 | rps_peers[i].stats[STAT_TYPE_UNREQUESTED_PULL_REPLIES], | 2633 | rps_peers[i].stats[STAT_TYPE_UNREQUESTED_PULL_REPLIES], |
2622 | rps_peers[i].stats[STAT_TYPE_PEERS_IN_PUSH_MAP], | 2634 | rps_peers[i].stats[STAT_TYPE_PEERS_IN_PUSH_MAP], |
2623 | rps_peers[i].stats[STAT_TYPE_PEERS_IN_PULL_MAP], | 2635 | rps_peers[i].stats[STAT_TYPE_PEERS_IN_PULL_MAP], |
2624 | rps_peers[i].stats[STAT_TYPE_PEERS_IN_VIEW], | 2636 | rps_peers[i].stats[STAT_TYPE_PEERS_IN_VIEW], |
2625 | rps_peers[i].stats[STAT_TYPE_VIEW_SIZE_AIM]); | 2637 | rps_peers[i].stats[STAT_TYPE_VIEW_SIZE_AIM]); |
2626 | for (enum STAT_TYPE stat_type = STAT_TYPE_ROUNDS; | 2638 | for (enum STAT_TYPE stat_type = STAT_TYPE_ROUNDS; |
2627 | stat_type < STAT_TYPE_MAX; | 2639 | stat_type < STAT_TYPE_MAX; |
2628 | stat_type++) | 2640 | stat_type++) |
2629 | { | 2641 | { |
2630 | sums[stat_type] += rps_peers[i].stats[stat_type]; | 2642 | sums[stat_type] += rps_peers[i].stats[stat_type]; |
2631 | } | 2643 | } |
2632 | } | 2644 | } |
2633 | to_file ("/tmp/rps/final_stats.dat", | 2645 | to_file("/tmp/rps/final_stats.dat", |
2634 | "SUM %" | 2646 | "SUM %" |
2635 | PRIu64 " %" /* rounds */ | 2647 | PRIu64 " %" /* rounds */ |
2636 | PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" /* blocking */ | 2648 | PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" /* blocking */ |
2637 | PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* issued */ | 2649 | PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* issued */ |
2638 | PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* sent */ | 2650 | PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* sent */ |
2639 | PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* recv */ | 2651 | PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* recv */ |
2640 | PRIu64 ", %" /* view size */ | 2652 | PRIu64 ", %" /* view size */ |
2641 | PRIu64 ", %" /* known peers */ | 2653 | PRIu64 ", %" /* known peers */ |
2642 | PRIu64 ", %" /* valid peers */ | 2654 | PRIu64 ", %" /* valid peers */ |
2643 | PRIu64 ", %" /* learned peers */ | 2655 | PRIu64 ", %" /* learned peers */ |
2644 | PRIu64 ", %" /* pending online checks */ | 2656 | PRIu64 ", %" /* pending online checks */ |
2645 | PRIu64 ", %" /* unrequested pull replies */ | 2657 | PRIu64 ", %" /* unrequested pull replies */ |
2646 | PRIu64 ", %" /* peers in push map */ | 2658 | PRIu64 ", %" /* peers in push map */ |
2647 | PRIu64 ", %" /* peers in pull map */ | 2659 | PRIu64 ", %" /* peers in pull map */ |
2648 | PRIu64 ", %" /* peers in view */ | 2660 | PRIu64 ", %" /* peers in view */ |
2649 | PRIu64 "\n"/* view size aim */, | 2661 | PRIu64 "\n" /* view size aim */, |
2650 | sums[STAT_TYPE_ROUNDS], | 2662 | sums[STAT_TYPE_ROUNDS], |
2651 | sums[STAT_TYPE_BLOCKS], | 2663 | sums[STAT_TYPE_BLOCKS], |
2652 | sums[STAT_TYPE_BLOCKS_MANY_PUSH], | 2664 | sums[STAT_TYPE_BLOCKS_MANY_PUSH], |
2653 | sums[STAT_TYPE_BLOCKS_NO_PUSH], | 2665 | sums[STAT_TYPE_BLOCKS_NO_PUSH], |
2654 | sums[STAT_TYPE_BLOCKS_NO_PULL], | 2666 | sums[STAT_TYPE_BLOCKS_NO_PULL], |
2655 | sums[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL], | 2667 | sums[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL], |
2656 | sums[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL], | 2668 | sums[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL], |
2657 | sums[STAT_TYPE_ISSUED_PUSH_SEND], | 2669 | sums[STAT_TYPE_ISSUED_PUSH_SEND], |
2658 | sums[STAT_TYPE_ISSUED_PUSH_SEND_MH], | 2670 | sums[STAT_TYPE_ISSUED_PUSH_SEND_MH], |
2659 | sums[STAT_TYPE_ISSUED_PULL_REQ], | 2671 | sums[STAT_TYPE_ISSUED_PULL_REQ], |
2660 | sums[STAT_TYPE_ISSUED_PULL_REQ_MH], | 2672 | sums[STAT_TYPE_ISSUED_PULL_REQ_MH], |
2661 | sums[STAT_TYPE_ISSUED_PULL_REP], | 2673 | sums[STAT_TYPE_ISSUED_PULL_REP], |
2662 | sums[STAT_TYPE_SENT_PUSH_SEND], | 2674 | sums[STAT_TYPE_SENT_PUSH_SEND], |
2663 | sums[STAT_TYPE_SENT_PULL_REQ], | 2675 | sums[STAT_TYPE_SENT_PULL_REQ], |
2664 | sums[STAT_TYPE_SENT_PULL_REQ_MH], | 2676 | sums[STAT_TYPE_SENT_PULL_REQ_MH], |
2665 | sums[STAT_TYPE_SENT_PULL_REP], | 2677 | sums[STAT_TYPE_SENT_PULL_REP], |
2666 | sums[STAT_TYPE_RECV_PUSH_SEND], | 2678 | sums[STAT_TYPE_RECV_PUSH_SEND], |
2667 | sums[STAT_TYPE_RECV_PUSH_SEND_MH], | 2679 | sums[STAT_TYPE_RECV_PUSH_SEND_MH], |
2668 | sums[STAT_TYPE_RECV_PULL_REQ], | 2680 | sums[STAT_TYPE_RECV_PULL_REQ], |
2669 | sums[STAT_TYPE_RECV_PULL_REQ_MH], | 2681 | sums[STAT_TYPE_RECV_PULL_REQ_MH], |
2670 | sums[STAT_TYPE_RECV_PULL_REP], | 2682 | sums[STAT_TYPE_RECV_PULL_REP], |
2671 | sums[STAT_TYPE_RECV_PULL_REP_MH], | 2683 | sums[STAT_TYPE_RECV_PULL_REP_MH], |
2672 | sums[STAT_TYPE_VIEW_SIZE], | 2684 | sums[STAT_TYPE_VIEW_SIZE], |
2673 | sums[STAT_TYPE_KNOWN_PEERS], | 2685 | sums[STAT_TYPE_KNOWN_PEERS], |
2674 | sums[STAT_TYPE_VALID_PEERS], | 2686 | sums[STAT_TYPE_VALID_PEERS], |
2675 | sums[STAT_TYPE_LEARND_PEERS], | 2687 | sums[STAT_TYPE_LEARND_PEERS], |
2676 | sums[STAT_TYPE_PENDING_ONLINE_CHECKS], | 2688 | sums[STAT_TYPE_PENDING_ONLINE_CHECKS], |
2677 | sums[STAT_TYPE_UNREQUESTED_PULL_REPLIES], | 2689 | sums[STAT_TYPE_UNREQUESTED_PULL_REPLIES], |
2678 | sums[STAT_TYPE_PEERS_IN_PUSH_MAP], | 2690 | sums[STAT_TYPE_PEERS_IN_PUSH_MAP], |
2679 | sums[STAT_TYPE_PEERS_IN_PULL_MAP], | 2691 | sums[STAT_TYPE_PEERS_IN_PULL_MAP], |
2680 | sums[STAT_TYPE_PEERS_IN_VIEW], | 2692 | sums[STAT_TYPE_PEERS_IN_VIEW], |
2681 | sums[STAT_TYPE_VIEW_SIZE_AIM]); | 2693 | sums[STAT_TYPE_VIEW_SIZE_AIM]); |
2682 | } | 2694 | } |
2683 | 2695 | ||
2684 | /** | 2696 | /** |
@@ -2693,43 +2705,47 @@ void write_final_stats (void){ | |||
2693 | * successfully obtained, #GNUNET_SYSERR if not. | 2705 | * successfully obtained, #GNUNET_SYSERR if not. |
2694 | */ | 2706 | */ |
2695 | void | 2707 | void |
2696 | post_test_shutdown_ready_cb (void *cls, | 2708 | post_test_shutdown_ready_cb(void *cls, |
2697 | int success) | 2709 | int success) |
2698 | { | 2710 | { |
2699 | struct STATcls *stat_cls = (struct STATcls *) cls; | 2711 | struct STATcls *stat_cls = (struct STATcls *)cls; |
2700 | struct RPSPeer *rps_peer = stat_cls->rps_peer; | 2712 | struct RPSPeer *rps_peer = stat_cls->rps_peer; |
2701 | 2713 | ||
2702 | rps_peer->h_stat_get[stat_cls->stat_type] = NULL; | 2714 | rps_peer->h_stat_get[stat_cls->stat_type] = NULL; |
2703 | if (GNUNET_OK == success) | 2715 | if (GNUNET_OK == success) |
2704 | { | 2716 | { |
2705 | /* set flag that we we got the value */ | 2717 | /* set flag that we we got the value */ |
2706 | rps_peer->stat_collected_flags |= BIT(stat_cls->stat_type); | 2718 | rps_peer->stat_collected_flags |= BIT(stat_cls->stat_type); |
2707 | } else { | 2719 | } |
2708 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2720 | else |
2709 | "Peer %u did not receive statistics value\n", | 2721 | { |
2710 | rps_peer->index); | 2722 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2711 | GNUNET_free (stat_cls); | 2723 | "Peer %u did not receive statistics value\n", |
2712 | GNUNET_break (0); | 2724 | rps_peer->index); |
2713 | return; | 2725 | GNUNET_free(stat_cls); |
2714 | } | 2726 | GNUNET_break(0); |
2727 | return; | ||
2728 | } | ||
2715 | 2729 | ||
2716 | if (NULL != rps_peer->stat_op && | 2730 | if (NULL != rps_peer->stat_op && |
2717 | GNUNET_YES == check_statistics_collect_completed_single_peer (rps_peer)) | 2731 | GNUNET_YES == check_statistics_collect_completed_single_peer(rps_peer)) |
2718 | { | 2732 | { |
2719 | GNUNET_TESTBED_operation_done (rps_peer->stat_op); | 2733 | GNUNET_TESTBED_operation_done(rps_peer->stat_op); |
2720 | } | 2734 | } |
2721 | 2735 | ||
2722 | write_final_stats (); | 2736 | write_final_stats(); |
2723 | if (GNUNET_YES == check_statistics_collect_completed()) | 2737 | if (GNUNET_YES == check_statistics_collect_completed()) |
2724 | { | 2738 | { |
2725 | //write_final_stats (); | 2739 | //write_final_stats (); |
2726 | GNUNET_free (stat_cls); | 2740 | GNUNET_free(stat_cls); |
2727 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2741 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2728 | "Shutting down\n"); | 2742 | "Shutting down\n"); |
2729 | GNUNET_SCHEDULER_shutdown (); | 2743 | GNUNET_SCHEDULER_shutdown(); |
2730 | } else { | 2744 | } |
2731 | GNUNET_free (stat_cls); | 2745 | else |
2732 | } | 2746 | { |
2747 | GNUNET_free(stat_cls); | ||
2748 | } | ||
2733 | } | 2749 | } |
2734 | 2750 | ||
2735 | /** | 2751 | /** |
@@ -2743,80 +2759,81 @@ post_test_shutdown_ready_cb (void *cls, | |||
2743 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | 2759 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration |
2744 | */ | 2760 | */ |
2745 | int | 2761 | int |
2746 | stat_iterator (void *cls, | 2762 | stat_iterator(void *cls, |
2747 | const char *subsystem, | 2763 | const char *subsystem, |
2748 | const char *name, | 2764 | const char *name, |
2749 | uint64_t value, | 2765 | uint64_t value, |
2750 | int is_persistent) | 2766 | int is_persistent) |
2751 | { | 2767 | { |
2752 | const struct STATcls *stat_cls = (const struct STATcls *) cls; | 2768 | const struct STATcls *stat_cls = (const struct STATcls *)cls; |
2753 | struct RPSPeer *rps_peer = (struct RPSPeer *) stat_cls->rps_peer; | 2769 | struct RPSPeer *rps_peer = (struct RPSPeer *)stat_cls->rps_peer; |
2754 | enum STAT_TYPE stat_type; | 2770 | enum STAT_TYPE stat_type; |
2755 | (void) subsystem; | 2771 | |
2756 | (void) is_persistent; | 2772 | (void)subsystem; |
2757 | 2773 | (void)is_persistent; | |
2758 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2774 | |
2759 | "Got stat value: %s - %" PRIu64 " (%u)\n", | 2775 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2760 | name, | 2776 | "Got stat value: %s - %" PRIu64 " (%u)\n", |
2761 | value, | 2777 | name, |
2762 | rps_peer->index); | 2778 | value, |
2763 | to_file (rps_peer->file_name_stats, | 2779 | rps_peer->index); |
2780 | to_file(rps_peer->file_name_stats, | ||
2764 | "%s: %" PRIu64 "\n", | 2781 | "%s: %" PRIu64 "\n", |
2765 | name, | 2782 | name, |
2766 | value); | 2783 | value); |
2767 | stat_type = stat_str_2_type (name); | 2784 | stat_type = stat_str_2_type(name); |
2768 | GNUNET_assert (STAT_TYPE_ROUNDS <= stat_type && | 2785 | GNUNET_assert(STAT_TYPE_ROUNDS <= stat_type && |
2769 | STAT_TYPE_MAX > stat_type); | 2786 | STAT_TYPE_MAX > stat_type); |
2770 | rps_peer->stats[stat_type] = value; | 2787 | rps_peer->stats[stat_type] = value; |
2771 | return GNUNET_OK; | 2788 | return GNUNET_OK; |
2772 | } | 2789 | } |
2773 | 2790 | ||
2774 | 2791 | ||
2775 | void | 2792 | void |
2776 | post_profiler (struct RPSPeer *rps_peer) | 2793 | post_profiler(struct RPSPeer *rps_peer) |
2777 | { | 2794 | { |
2778 | if (COLLECT_STATISTICS != cur_test_run.have_collect_statistics) | 2795 | if (COLLECT_STATISTICS != cur_test_run.have_collect_statistics) |
2779 | { | 2796 | { |
2780 | return; | 2797 | return; |
2781 | } | 2798 | } |
2782 | 2799 | ||
2783 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2800 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2784 | "Going to request statistic values with mask 0x%" PRIx32 "\n", | 2801 | "Going to request statistic values with mask 0x%" PRIx32 "\n", |
2785 | cur_test_run.stat_collect_flags); | 2802 | cur_test_run.stat_collect_flags); |
2786 | 2803 | ||
2787 | struct STATcls *stat_cls; | 2804 | struct STATcls *stat_cls; |
2788 | uint32_t stat_type; | 2805 | uint32_t stat_type; |
2789 | for (stat_type = STAT_TYPE_ROUNDS; | 2806 | for (stat_type = STAT_TYPE_ROUNDS; |
2790 | stat_type < STAT_TYPE_MAX; | 2807 | stat_type < STAT_TYPE_MAX; |
2791 | stat_type++) | 2808 | stat_type++) |
2792 | { | 2809 | { |
2793 | if (BIT(stat_type) & cur_test_run.stat_collect_flags) | 2810 | if (BIT(stat_type) & cur_test_run.stat_collect_flags) |
2794 | { | 2811 | { |
2795 | stat_cls = GNUNET_malloc (sizeof (struct STATcls)); | 2812 | stat_cls = GNUNET_malloc(sizeof(struct STATcls)); |
2796 | stat_cls->rps_peer = rps_peer; | 2813 | stat_cls->rps_peer = rps_peer; |
2797 | stat_cls->stat_type = stat_type; | 2814 | stat_cls->stat_type = stat_type; |
2798 | rps_peer->file_name_stats = | 2815 | rps_peer->file_name_stats = |
2799 | store_prefix_file_name (rps_peer->peer_id, "stats"); | 2816 | store_prefix_file_name(rps_peer->peer_id, "stats"); |
2800 | rps_peer->h_stat_get[stat_type] = | 2817 | rps_peer->h_stat_get[stat_type] = |
2801 | GNUNET_STATISTICS_get (rps_peer->stats_h, | 2818 | GNUNET_STATISTICS_get(rps_peer->stats_h, |
2802 | "rps", | 2819 | "rps", |
2803 | stat_type_strings [stat_type], | 2820 | stat_type_strings [stat_type], |
2804 | post_test_shutdown_ready_cb, | 2821 | post_test_shutdown_ready_cb, |
2805 | stat_iterator, | 2822 | stat_iterator, |
2806 | (struct STATcls *) stat_cls); | 2823 | (struct STATcls *)stat_cls); |
2807 | GNUNET_assert (NULL != rps_peer->h_stat_get); | 2824 | GNUNET_assert(NULL != rps_peer->h_stat_get); |
2808 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2825 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2809 | "Requested statistics for %s (peer %" PRIu32 ")\n", | 2826 | "Requested statistics for %s (peer %" PRIu32 ")\n", |
2810 | stat_type_strings [stat_type], | 2827 | stat_type_strings [stat_type], |
2811 | rps_peer->index); | 2828 | rps_peer->index); |
2812 | } | 2829 | } |
2813 | } | 2830 | } |
2814 | GNUNET_free (rps_peer->eval_probs_cache); | 2831 | GNUNET_free(rps_peer->eval_probs_cache); |
2815 | } | 2832 | } |
2816 | 2833 | ||
2817 | 2834 | ||
2818 | /*********************************************************************** | 2835 | /*********************************************************************** |
2819 | * /Definition of tests | 2836 | * /Definition of tests |
2820 | ***********************************************************************/ | 2837 | ***********************************************************************/ |
2821 | 2838 | ||
2822 | 2839 | ||
@@ -2833,99 +2850,100 @@ post_profiler (struct RPSPeer *rps_peer) | |||
2833 | * failed | 2850 | * failed |
2834 | */ | 2851 | */ |
2835 | static void | 2852 | static void |
2836 | test_run (void *cls, | 2853 | test_run(void *cls, |
2837 | struct GNUNET_TESTBED_RunHandle *h, | 2854 | struct GNUNET_TESTBED_RunHandle *h, |
2838 | unsigned int n_peers, | 2855 | unsigned int n_peers, |
2839 | struct GNUNET_TESTBED_Peer **peers, | 2856 | struct GNUNET_TESTBED_Peer **peers, |
2840 | unsigned int links_succeeded, | 2857 | unsigned int links_succeeded, |
2841 | unsigned int links_failed) | 2858 | unsigned int links_failed) |
2842 | { | 2859 | { |
2843 | unsigned int i; | 2860 | unsigned int i; |
2844 | struct OpListEntry *entry; | 2861 | struct OpListEntry *entry; |
2845 | (void) cls; | ||
2846 | (void) h; | ||
2847 | (void) links_failed; | ||
2848 | 2862 | ||
2849 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "RUN was called\n"); | 2863 | (void)cls; |
2864 | (void)h; | ||
2865 | (void)links_failed; | ||
2866 | |||
2867 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "RUN was called\n"); | ||
2850 | 2868 | ||
2851 | /* Check whether we timed out */ | 2869 | /* Check whether we timed out */ |
2852 | if (n_peers != num_peers || | 2870 | if (n_peers != num_peers || |
2853 | NULL == peers || | 2871 | NULL == peers || |
2854 | 0 == links_succeeded) | 2872 | 0 == links_succeeded) |
2855 | { | 2873 | { |
2856 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Going down due to args (eg. timeout)\n"); | 2874 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Going down due to args (eg. timeout)\n"); |
2857 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tn_peers: %u\n", n_peers); | 2875 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tn_peers: %u\n", n_peers); |
2858 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tnum_peers: %" PRIu32 "\n", num_peers); | 2876 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tnum_peers: %" PRIu32 "\n", num_peers); |
2859 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tpeers: %p\n", peers); | 2877 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tpeers: %p\n", peers); |
2860 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tlinks_succeeded: %u\n", links_succeeded); | 2878 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tlinks_succeeded: %u\n", links_succeeded); |
2861 | ok = 1; | 2879 | ok = 1; |
2862 | GNUNET_SCHEDULER_shutdown (); | 2880 | GNUNET_SCHEDULER_shutdown(); |
2863 | return; | 2881 | return; |
2864 | } | 2882 | } |
2865 | 2883 | ||
2866 | 2884 | ||
2867 | /* Initialize peers */ | 2885 | /* Initialize peers */ |
2868 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "going to initialise peers\n"); | 2886 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "going to initialise peers\n"); |
2869 | testbed_peers = peers; | 2887 | testbed_peers = peers; |
2870 | num_peers_online = 0; | 2888 | num_peers_online = 0; |
2871 | for (i = 0; i < num_peers; i++) | 2889 | for (i = 0; i < num_peers; i++) |
2872 | { | 2890 | { |
2873 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "initialising %u\n", i); | 2891 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "initialising %u\n", i); |
2874 | entry = make_oplist_entry (); | 2892 | entry = make_oplist_entry(); |
2875 | entry->index = i; | 2893 | entry->index = i; |
2876 | rps_peers[i].index = i; | 2894 | rps_peers[i].index = i; |
2877 | if (NULL != cur_test_run.init_peer) | 2895 | if (NULL != cur_test_run.init_peer) |
2878 | cur_test_run.init_peer (&rps_peers[i]); | 2896 | cur_test_run.init_peer(&rps_peers[i]); |
2879 | if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) | 2897 | if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) |
2880 | { | 2898 | { |
2881 | rps_peers->cur_view_count = 0; | 2899 | rps_peers->cur_view_count = 0; |
2882 | rps_peers->cur_view = NULL; | 2900 | rps_peers->cur_view = NULL; |
2883 | } | 2901 | } |
2884 | entry->op = GNUNET_TESTBED_peer_get_information (peers[i], | 2902 | entry->op = GNUNET_TESTBED_peer_get_information(peers[i], |
2885 | GNUNET_TESTBED_PIT_IDENTITY, | 2903 | GNUNET_TESTBED_PIT_IDENTITY, |
2886 | &info_cb, | 2904 | &info_cb, |
2887 | entry); | 2905 | entry); |
2888 | } | 2906 | } |
2889 | 2907 | ||
2890 | /* Bring peers up */ | 2908 | /* Bring peers up */ |
2891 | GNUNET_assert (num_peers == n_peers); | 2909 | GNUNET_assert(num_peers == n_peers); |
2892 | for (i = 0; i < n_peers; i++) | 2910 | for (i = 0; i < n_peers; i++) |
2893 | { | 2911 | { |
2894 | rps_peers[i].index = i; | 2912 | rps_peers[i].index = i; |
2895 | rps_peers[i].op = | 2913 | rps_peers[i].op = |
2896 | GNUNET_TESTBED_service_connect (&rps_peers[i], | 2914 | GNUNET_TESTBED_service_connect(&rps_peers[i], |
2897 | peers[i], | 2915 | peers[i], |
2898 | "rps", | 2916 | "rps", |
2899 | &rps_connect_complete_cb, | 2917 | &rps_connect_complete_cb, |
2900 | &rps_peers[i], | 2918 | &rps_peers[i], |
2901 | &rps_connect_adapter, | 2919 | &rps_connect_adapter, |
2902 | &rps_disconnect_adapter, | 2920 | &rps_disconnect_adapter, |
2903 | &rps_peers[i]); | 2921 | &rps_peers[i]); |
2904 | /* Connect all peers to statistics service */ | 2922 | /* Connect all peers to statistics service */ |
2905 | if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics) | 2923 | if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics) |
2906 | { | 2924 | { |
2907 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2925 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2908 | "Connecting to statistics service\n"); | 2926 | "Connecting to statistics service\n"); |
2909 | rps_peers[i].stat_op = | 2927 | rps_peers[i].stat_op = |
2910 | GNUNET_TESTBED_service_connect (NULL, | 2928 | GNUNET_TESTBED_service_connect(NULL, |
2911 | peers[i], | 2929 | peers[i], |
2912 | "statistics", | 2930 | "statistics", |
2913 | stat_complete_cb, | 2931 | stat_complete_cb, |
2914 | &rps_peers[i], | 2932 | &rps_peers[i], |
2915 | &stat_connect_adapter, | 2933 | &stat_connect_adapter, |
2916 | &stat_disconnect_adapter, | 2934 | &stat_disconnect_adapter, |
2917 | &rps_peers[i]); | 2935 | &rps_peers[i]); |
2918 | } | 2936 | } |
2919 | } | 2937 | } |
2920 | 2938 | ||
2921 | if (NULL != churn_task) | 2939 | if (NULL != churn_task) |
2922 | GNUNET_SCHEDULER_cancel (churn_task); | 2940 | GNUNET_SCHEDULER_cancel(churn_task); |
2923 | post_test_task = GNUNET_SCHEDULER_add_delayed (duration, &post_test_op, NULL); | 2941 | post_test_task = GNUNET_SCHEDULER_add_delayed(duration, &post_test_op, NULL); |
2924 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "timeout for shutdown is %lu\n", timeout.rel_value_us/1000000); | 2942 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "timeout for shutdown is %lu\n", timeout.rel_value_us / 1000000); |
2925 | shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, | 2943 | shutdown_task = GNUNET_SCHEDULER_add_delayed(timeout, |
2926 | &trigger_shutdown, | 2944 | &trigger_shutdown, |
2927 | NULL); | 2945 | NULL); |
2928 | GNUNET_SCHEDULER_add_shutdown (shutdown_op, NULL); | 2946 | GNUNET_SCHEDULER_add_shutdown(shutdown_op, NULL); |
2929 | } | 2947 | } |
2930 | 2948 | ||
2931 | 2949 | ||
@@ -2936,20 +2954,20 @@ test_run (void *cls, | |||
2936 | * @param argv unused | 2954 | * @param argv unused |
2937 | */ | 2955 | */ |
2938 | static void | 2956 | static void |
2939 | run (void *cls, | 2957 | run(void *cls, |
2940 | char *const *args, | 2958 | char *const *args, |
2941 | const char *cfgfile, | 2959 | const char *cfgfile, |
2942 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 2960 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
2943 | { | 2961 | { |
2944 | //int ret_value; | 2962 | //int ret_value; |
2945 | (void) cls; | 2963 | (void)cls; |
2946 | (void) args; | 2964 | (void)args; |
2947 | (void) cfgfile; | 2965 | (void)cfgfile; |
2948 | 2966 | ||
2949 | /* Defaults for tests */ | 2967 | /* Defaults for tests */ |
2950 | churn_task = NULL; | 2968 | churn_task = NULL; |
2951 | 2969 | ||
2952 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n"); | 2970 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n"); |
2953 | cur_test_run.name = "test-rps-profiler"; | 2971 | cur_test_run.name = "test-rps-profiler"; |
2954 | if (0 == num_peers) | 2972 | if (0 == num_peers) |
2955 | num_peers = 10; | 2973 | num_peers = 10; |
@@ -2962,7 +2980,8 @@ run (void *cls, | |||
2962 | cur_test_run.eval_cb = profiler_eval; | 2980 | cur_test_run.eval_cb = profiler_eval; |
2963 | cur_test_run.post_test = post_profiler; | 2981 | cur_test_run.post_test = post_profiler; |
2964 | cur_test_run.request_interval = 2; | 2982 | cur_test_run.request_interval = 2; |
2965 | if (0 == cur_test_run.num_requests) cur_test_run.num_requests = 5; | 2983 | if (0 == cur_test_run.num_requests) |
2984 | cur_test_run.num_requests = 5; | ||
2966 | //cur_test_run.have_churn = HAVE_CHURN; | 2985 | //cur_test_run.have_churn = HAVE_CHURN; |
2967 | cur_test_run.have_churn = HAVE_NO_CHURN; | 2986 | cur_test_run.have_churn = HAVE_NO_CHURN; |
2968 | cur_test_run.have_quick_quit = HAVE_QUICK_QUIT; | 2987 | cur_test_run.have_quick_quit = HAVE_QUICK_QUIT; |
@@ -3002,65 +3021,65 @@ run (void *cls, | |||
3002 | cur_test_run.have_collect_view = COLLECT_VIEW; | 3021 | cur_test_run.have_collect_view = COLLECT_VIEW; |
3003 | 3022 | ||
3004 | /* 'Clean' directory */ | 3023 | /* 'Clean' directory */ |
3005 | (void) GNUNET_DISK_directory_remove ("/tmp/rps/"); | 3024 | (void)GNUNET_DISK_directory_remove("/tmp/rps/"); |
3006 | GNUNET_DISK_directory_create ("/tmp/rps/"); | 3025 | GNUNET_DISK_directory_create("/tmp/rps/"); |
3007 | if (0 == duration.rel_value_us) | 3026 | if (0 == duration.rel_value_us) |
3008 | { | ||
3009 | if (0 == timeout.rel_value_us) | ||
3010 | { | 3027 | { |
3011 | duration = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90); | 3028 | if (0 == timeout.rel_value_us) |
3012 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 3029 | { |
3013 | (90 * 1.2) + | 3030 | duration = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90); |
3014 | (0.01 * num_peers)); | 3031 | timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
3032 | (90 * 1.2) + | ||
3033 | (0.01 * num_peers)); | ||
3034 | } | ||
3035 | else | ||
3036 | { | ||
3037 | duration = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | ||
3038 | (timeout.rel_value_us / 1000000) | ||
3039 | * 0.75); | ||
3040 | } | ||
3015 | } | 3041 | } |
3016 | else | 3042 | else |
3017 | { | 3043 | { |
3018 | duration = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 3044 | if (0 == timeout.rel_value_us) |
3019 | (timeout.rel_value_us/1000000) | 3045 | { |
3020 | * 0.75); | 3046 | timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
3047 | ((duration.rel_value_us / 1000000) | ||
3048 | * 1.2) + (0.01 * num_peers)); | ||
3049 | } | ||
3021 | } | 3050 | } |
3022 | } | 3051 | GNUNET_assert(duration.rel_value_us < timeout.rel_value_us); |
3023 | else | 3052 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3024 | { | 3053 | "duration is %lus\n", |
3025 | if (0 == timeout.rel_value_us) | 3054 | duration.rel_value_us / 1000000); |
3026 | { | 3055 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3027 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 3056 | "timeout is %lus\n", |
3028 | ((duration.rel_value_us/1000000) | 3057 | timeout.rel_value_us / 1000000); |
3029 | * 1.2) + (0.01 * num_peers)); | ||
3030 | } | ||
3031 | } | ||
3032 | GNUNET_assert (duration.rel_value_us < timeout.rel_value_us); | ||
3033 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3034 | "duration is %lus\n", | ||
3035 | duration.rel_value_us/1000000); | ||
3036 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3037 | "timeout is %lus\n", | ||
3038 | timeout.rel_value_us/1000000); | ||
3039 | 3058 | ||
3040 | /* Compute number of bits for representing largest peer id */ | 3059 | /* Compute number of bits for representing largest peer id */ |
3041 | for (bits_needed = 1; (1 << bits_needed) < num_peers; bits_needed++) | 3060 | for (bits_needed = 1; (1 << bits_needed) < num_peers; bits_needed++) |
3042 | ; | 3061 | ; |
3043 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3062 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
3044 | "Need %u bits to represent %" PRIu32 " peers\n", | 3063 | "Need %u bits to represent %" PRIu32 " peers\n", |
3045 | bits_needed, | 3064 | bits_needed, |
3046 | num_peers); | 3065 | num_peers); |
3047 | 3066 | ||
3048 | rps_peers = GNUNET_new_array (num_peers, struct RPSPeer); | 3067 | rps_peers = GNUNET_new_array(num_peers, struct RPSPeer); |
3049 | peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO); | 3068 | peer_map = GNUNET_CONTAINER_multipeermap_create(num_peers, GNUNET_NO); |
3050 | rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity); | 3069 | rps_peer_ids = GNUNET_new_array(num_peers, struct GNUNET_PeerIdentity); |
3051 | if ( (2 == mal_type) || | 3070 | if ((2 == mal_type) || |
3052 | (3 == mal_type)) | 3071 | (3 == mal_type)) |
3053 | target_peer = &rps_peer_ids[num_peers - 2]; | 3072 | target_peer = &rps_peer_ids[num_peers - 2]; |
3054 | 3073 | ||
3055 | ok = 1; | 3074 | ok = 1; |
3056 | GNUNET_TESTBED_run (NULL, | 3075 | GNUNET_TESTBED_run(NULL, |
3057 | cfg, | 3076 | cfg, |
3058 | num_peers, | 3077 | num_peers, |
3059 | 0, /* event mask */ | 3078 | 0, /* event mask */ |
3060 | NULL, | 3079 | NULL, |
3061 | NULL, | 3080 | NULL, |
3062 | &test_run, | 3081 | &test_run, |
3063 | NULL); | 3082 | NULL); |
3064 | } | 3083 | } |
3065 | 3084 | ||
3066 | /** | 3085 | /** |
@@ -3071,69 +3090,69 @@ run (void *cls, | |||
3071 | * @return 0 on success | 3090 | * @return 0 on success |
3072 | */ | 3091 | */ |
3073 | int | 3092 | int |
3074 | main (int argc, char *argv[]) | 3093 | main(int argc, char *argv[]) |
3075 | { | 3094 | { |
3076 | int ret_value; | 3095 | int ret_value; |
3077 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 3096 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
3078 | GNUNET_GETOPT_option_uint ('n', | 3097 | GNUNET_GETOPT_option_uint('n', |
3079 | "num-peers", | 3098 | "num-peers", |
3080 | "COUNT", | 3099 | "COUNT", |
3081 | gettext_noop ("number of peers to start"), | 3100 | gettext_noop("number of peers to start"), |
3082 | &num_peers), | 3101 | &num_peers), |
3083 | GNUNET_GETOPT_option_relative_time ('d', | 3102 | GNUNET_GETOPT_option_relative_time('d', |
3084 | "duration", | 3103 | "duration", |
3085 | "DURATION", | 3104 | "DURATION", |
3086 | gettext_noop ("duration of the profiling"), | 3105 | gettext_noop("duration of the profiling"), |
3087 | &duration), | 3106 | &duration), |
3088 | GNUNET_GETOPT_option_relative_time ('t', | 3107 | GNUNET_GETOPT_option_relative_time('t', |
3089 | "timeout", | 3108 | "timeout", |
3090 | "TIMEOUT", | 3109 | "TIMEOUT", |
3091 | gettext_noop ("timeout for the profiling"), | 3110 | gettext_noop("timeout for the profiling"), |
3092 | &timeout), | 3111 | &timeout), |
3093 | GNUNET_GETOPT_option_uint ('r', | 3112 | GNUNET_GETOPT_option_uint('r', |
3094 | "num-requests", | 3113 | "num-requests", |
3095 | "COUNT", | 3114 | "COUNT", |
3096 | gettext_noop ("number of PeerIDs to request"), | 3115 | gettext_noop("number of PeerIDs to request"), |
3097 | &cur_test_run.num_requests), | 3116 | &cur_test_run.num_requests), |
3098 | GNUNET_GETOPT_OPTION_END | 3117 | GNUNET_GETOPT_OPTION_END |
3099 | }; | 3118 | }; |
3100 | 3119 | ||
3101 | unsetenv ("XDG_DATA_HOME"); | 3120 | unsetenv("XDG_DATA_HOME"); |
3102 | unsetenv ("XDG_CONFIG_HOME"); | 3121 | unsetenv("XDG_CONFIG_HOME"); |
3103 | //if (GNUNET_OK != | 3122 | //if (GNUNET_OK != |
3104 | // GNUNET_STRINGS_get_utf8_args (argc, argv, | 3123 | // GNUNET_STRINGS_get_utf8_args (argc, argv, |
3105 | // &argc, &argv)) | 3124 | // &argc, &argv)) |
3106 | // return 2; | 3125 | // return 2; |
3107 | ret_value = 0; | 3126 | ret_value = 0; |
3108 | if (GNUNET_OK != | 3127 | if (GNUNET_OK != |
3109 | GNUNET_PROGRAM_run (argc, | 3128 | GNUNET_PROGRAM_run(argc, |
3110 | argv, | 3129 | argv, |
3111 | "gnunet-rps-profiler", | 3130 | "gnunet-rps-profiler", |
3112 | gettext_noop ("Measure quality and performance of the RPS service."), | 3131 | gettext_noop("Measure quality and performance of the RPS service."), |
3113 | options, | 3132 | options, |
3114 | &run, | 3133 | &run, |
3115 | NULL)) | 3134 | NULL)) |
3116 | { | 3135 | { |
3117 | ret_value = 1; | 3136 | ret_value = 1; |
3118 | } | 3137 | } |
3119 | if (0 != ret_value) | 3138 | if (0 != ret_value) |
3120 | { | 3139 | { |
3121 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3140 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
3122 | "Test did not run successfully!\n"); | 3141 | "Test did not run successfully!\n"); |
3123 | } | 3142 | } |
3124 | else | 3143 | else |
3125 | { | 3144 | { |
3126 | ret_value = cur_test_run.eval_cb(); | 3145 | ret_value = cur_test_run.eval_cb(); |
3127 | if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) | 3146 | if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) |
3128 | { | 3147 | { |
3129 | GNUNET_array_grow (rps_peers->cur_view, | 3148 | GNUNET_array_grow(rps_peers->cur_view, |
3130 | rps_peers->cur_view_count, | 3149 | rps_peers->cur_view_count, |
3131 | 0); | 3150 | 0); |
3132 | } | 3151 | } |
3133 | GNUNET_free (rps_peers); | 3152 | GNUNET_free(rps_peers); |
3134 | GNUNET_free (rps_peer_ids); | 3153 | GNUNET_free(rps_peer_ids); |
3135 | GNUNET_CONTAINER_multipeermap_destroy (peer_map); | 3154 | GNUNET_CONTAINER_multipeermap_destroy(peer_map); |
3136 | } | 3155 | } |
3137 | return ret_value; | 3156 | return ret_value; |
3138 | } | 3157 | } |
3139 | 3158 | ||
diff --git a/src/rps/gnunet-rps.c b/src/rps/gnunet-rps.c index d731ffa55..84043341b 100644 --- a/src/rps/gnunet-rps.c +++ b/src/rps/gnunet-rps.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file rps/gnunet-rps.c | 22 | * @file rps/gnunet-rps.c |
@@ -68,13 +68,13 @@ static uint64_t num_view_updates; | |||
68 | * @param cls NULL | 68 | * @param cls NULL |
69 | */ | 69 | */ |
70 | static void | 70 | static void |
71 | do_shutdown (void *cls) | 71 | do_shutdown(void *cls) |
72 | { | 72 | { |
73 | (void) cls; | 73 | (void)cls; |
74 | 74 | ||
75 | if (NULL != req_handle) | 75 | if (NULL != req_handle) |
76 | GNUNET_RPS_request_cancel (req_handle); | 76 | GNUNET_RPS_request_cancel(req_handle); |
77 | GNUNET_RPS_disconnect (rps_handle); | 77 | GNUNET_RPS_disconnect(rps_handle); |
78 | } | 78 | } |
79 | 79 | ||
80 | 80 | ||
@@ -87,22 +87,23 @@ do_shutdown (void *cls) | |||
87 | * @param recv_peers the received peers | 87 | * @param recv_peers the received peers |
88 | */ | 88 | */ |
89 | static void | 89 | static void |
90 | reply_handle (void *cls, | 90 | reply_handle(void *cls, |
91 | uint64_t n, | 91 | uint64_t n, |
92 | const struct GNUNET_PeerIdentity *recv_peers) | 92 | const struct GNUNET_PeerIdentity *recv_peers) |
93 | { | 93 | { |
94 | uint64_t i; | 94 | uint64_t i; |
95 | (void) cls; | 95 | |
96 | (void)cls; | ||
96 | 97 | ||
97 | req_handle = NULL; | 98 | req_handle = NULL; |
98 | for (i = 0; i < n; i++) | 99 | for (i = 0; i < n; i++) |
99 | { | 100 | { |
100 | fprintf (stdout, "%s\n", | 101 | fprintf(stdout, "%s\n", |
101 | GNUNET_i2s_full (&recv_peers[i])); | 102 | GNUNET_i2s_full(&recv_peers[i])); |
102 | } | 103 | } |
103 | ret = 0; | 104 | ret = 0; |
104 | 105 | ||
105 | GNUNET_SCHEDULER_shutdown (); | 106 | GNUNET_SCHEDULER_shutdown(); |
106 | } | 107 | } |
107 | 108 | ||
108 | /** | 109 | /** |
@@ -113,33 +114,34 @@ reply_handle (void *cls, | |||
113 | * @param recv_peers the received peers | 114 | * @param recv_peers the received peers |
114 | */ | 115 | */ |
115 | static void | 116 | static void |
116 | view_update_handle (void *cls, | 117 | view_update_handle(void *cls, |
117 | uint64_t n, | 118 | uint64_t n, |
118 | const struct GNUNET_PeerIdentity *recv_peers) | 119 | const struct GNUNET_PeerIdentity *recv_peers) |
119 | { | 120 | { |
120 | uint64_t i; | 121 | uint64_t i; |
121 | (void) cls; | 122 | |
123 | (void)cls; | ||
122 | 124 | ||
123 | if (0 == n) | 125 | if (0 == n) |
124 | { | 126 | { |
125 | fprintf (stdout, "Empty view\n"); | 127 | fprintf(stdout, "Empty view\n"); |
126 | } | 128 | } |
127 | req_handle = NULL; | 129 | req_handle = NULL; |
128 | for (i = 0; i < n; i++) | 130 | for (i = 0; i < n; i++) |
129 | { | 131 | { |
130 | fprintf (stdout, "%s\n", | 132 | fprintf(stdout, "%s\n", |
131 | GNUNET_i2s_full (&recv_peers[i])); | 133 | GNUNET_i2s_full(&recv_peers[i])); |
132 | } | 134 | } |
133 | 135 | ||
134 | if (1 == num_view_updates) | 136 | if (1 == num_view_updates) |
135 | { | 137 | { |
136 | ret = 0; | 138 | ret = 0; |
137 | GNUNET_SCHEDULER_shutdown (); | 139 | GNUNET_SCHEDULER_shutdown(); |
138 | } | 140 | } |
139 | else if (1 < num_view_updates) | 141 | else if (1 < num_view_updates) |
140 | { | 142 | { |
141 | num_view_updates--; | 143 | num_view_updates--; |
142 | } | 144 | } |
143 | } | 145 | } |
144 | 146 | ||
145 | 147 | ||
@@ -150,23 +152,24 @@ view_update_handle (void *cls, | |||
150 | * @param recv_peers the received peers | 152 | * @param recv_peers the received peers |
151 | */ | 153 | */ |
152 | static void | 154 | static void |
153 | stream_input_handle (void *cls, | 155 | stream_input_handle(void *cls, |
154 | uint64_t num_peers, | 156 | uint64_t num_peers, |
155 | const struct GNUNET_PeerIdentity *recv_peers) | 157 | const struct GNUNET_PeerIdentity *recv_peers) |
156 | { | 158 | { |
157 | uint64_t i; | 159 | uint64_t i; |
158 | (void) cls; | 160 | |
161 | (void)cls; | ||
159 | 162 | ||
160 | if (0 == num_peers) | 163 | if (0 == num_peers) |
161 | { | 164 | { |
162 | fprintf (stdout, "No peer was returned\n"); | 165 | fprintf(stdout, "No peer was returned\n"); |
163 | } | 166 | } |
164 | req_handle = NULL; | 167 | req_handle = NULL; |
165 | for (i = 0; i < num_peers; i++) | 168 | for (i = 0; i < num_peers; i++) |
166 | { | 169 | { |
167 | fprintf (stdout, "%s\n", | 170 | fprintf(stdout, "%s\n", |
168 | GNUNET_i2s_full (&recv_peers[i])); | 171 | GNUNET_i2s_full(&recv_peers[i])); |
169 | } | 172 | } |
170 | } | 173 | } |
171 | 174 | ||
172 | 175 | ||
@@ -179,66 +182,69 @@ stream_input_handle (void *cls, | |||
179 | * @param cfg configuration | 182 | * @param cfg configuration |
180 | */ | 183 | */ |
181 | static void | 184 | static void |
182 | run (void *cls, | 185 | run(void *cls, |
183 | char *const *args, | 186 | char *const *args, |
184 | const char *cfgfile, | 187 | const char *cfgfile, |
185 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 188 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
186 | { | 189 | { |
187 | static uint64_t num_peers; | 190 | static uint64_t num_peers; |
188 | static struct GNUNET_PeerIdentity zero_pid; | 191 | static struct GNUNET_PeerIdentity zero_pid; |
189 | (void) cls; | ||
190 | (void) cfgfile; | ||
191 | 192 | ||
192 | rps_handle = GNUNET_RPS_connect (cfg); | 193 | (void)cls; |
194 | (void)cfgfile; | ||
195 | |||
196 | rps_handle = GNUNET_RPS_connect(cfg); | ||
193 | if (NULL == rps_handle) | 197 | if (NULL == rps_handle) |
194 | { | 198 | { |
195 | fprintf (stderr, "Failed to connect to the rps service\n"); | 199 | fprintf(stderr, "Failed to connect to the rps service\n"); |
196 | return; | 200 | return; |
197 | } | 201 | } |
198 | 202 | ||
199 | if ((0 == memcmp (&zero_pid, &peer_id, sizeof (peer_id))) && | 203 | if ((0 == memcmp(&zero_pid, &peer_id, sizeof(peer_id))) && |
200 | (!view_update) && | 204 | (!view_update) && |
201 | (!stream_input)) | 205 | (!stream_input)) |
202 | { /* Request n PeerIDs */ | 206 | { /* Request n PeerIDs */ |
203 | /* If number was specified use it, else request single peer. */ | 207 | /* If number was specified use it, else request single peer. */ |
204 | if (NULL == args[0] || | 208 | if (NULL == args[0] || |
205 | 0 == sscanf (args[0], "%lu", &num_peers)) | 209 | 0 == sscanf(args[0], "%lu", &num_peers)) |
210 | { | ||
211 | num_peers = 1; | ||
212 | } | ||
213 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
214 | "Requesting %" PRIu64 " PeerIDs\n", num_peers); | ||
215 | req_handle = GNUNET_RPS_request_peers(rps_handle, num_peers, reply_handle, NULL); | ||
216 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); | ||
217 | } | ||
218 | else if (view_update) | ||
206 | { | 219 | { |
207 | num_peers = 1; | 220 | /* Get updates of view */ |
221 | if (NULL == args[0] || | ||
222 | 0 == sscanf(args[0], "%lu", &num_view_updates)) | ||
223 | { | ||
224 | num_view_updates = 0; | ||
225 | } | ||
226 | GNUNET_RPS_view_request(rps_handle, num_view_updates, view_update_handle, NULL); | ||
227 | if (0 != num_view_updates) | ||
228 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
229 | "Requesting %" PRIu64 " view updates\n", num_view_updates); | ||
230 | else | ||
231 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
232 | "Requesting continuous view updates\n"); | ||
233 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); | ||
208 | } | 234 | } |
209 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 235 | else if (stream_input) |
210 | "Requesting %" PRIu64 " PeerIDs\n", num_peers); | ||
211 | req_handle = GNUNET_RPS_request_peers (rps_handle, num_peers, reply_handle, NULL); | ||
212 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | ||
213 | } else if (view_update) | ||
214 | { | ||
215 | /* Get updates of view */ | ||
216 | if (NULL == args[0] || | ||
217 | 0 == sscanf (args[0], "%lu", &num_view_updates)) | ||
218 | { | 236 | { |
219 | num_view_updates = 0; | 237 | /* Get updates of view */ |
238 | GNUNET_RPS_stream_request(rps_handle, stream_input_handle, NULL); | ||
239 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); | ||
220 | } | 240 | } |
221 | GNUNET_RPS_view_request (rps_handle, num_view_updates, view_update_handle, NULL); | ||
222 | if (0 != num_view_updates) | ||
223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
224 | "Requesting %" PRIu64 " view updates\n", num_view_updates); | ||
225 | else | ||
226 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
227 | "Requesting continuous view updates\n"); | ||
228 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | ||
229 | } else if (stream_input) | ||
230 | { | ||
231 | /* Get updates of view */ | ||
232 | GNUNET_RPS_stream_request (rps_handle, stream_input_handle, NULL); | ||
233 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | ||
234 | } | ||
235 | else | 241 | else |
236 | { /* Seed PeerID */ | 242 | { /* Seed PeerID */ |
237 | GNUNET_RPS_seed_ids (rps_handle, 1, &peer_id); | 243 | GNUNET_RPS_seed_ids(rps_handle, 1, &peer_id); |
238 | fprintf (stdout, "Seeded PeerID %s\n", GNUNET_i2s_full (&peer_id)); | 244 | fprintf(stdout, "Seeded PeerID %s\n", GNUNET_i2s_full(&peer_id)); |
239 | ret = 0; | 245 | ret = 0; |
240 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 246 | GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); |
241 | } | 247 | } |
242 | } | 248 | } |
243 | 249 | ||
244 | /** | 250 | /** |
@@ -249,33 +255,34 @@ run (void *cls, | |||
249 | * @return 0 ok, 1 on error | 255 | * @return 0 ok, 1 on error |
250 | */ | 256 | */ |
251 | int | 257 | int |
252 | main (int argc, char *const *argv) | 258 | main(int argc, char *const *argv) |
253 | { | 259 | { |
254 | const char helpstr[] = | 260 | const char helpstr[] = |
255 | "Get random GNUnet peers. If none is specified a single is requested."; | 261 | "Get random GNUnet peers. If none is specified a single is requested."; |
256 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 262 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
257 | GNUNET_GETOPT_option_base32_auto ('s', | 263 | GNUNET_GETOPT_option_base32_auto('s', |
258 | "seed", | 264 | "seed", |
259 | "PEER_ID", | 265 | "PEER_ID", |
260 | gettext_noop ("Seed a PeerID"), | 266 | gettext_noop("Seed a PeerID"), |
261 | &peer_id), | 267 | &peer_id), |
262 | GNUNET_GETOPT_option_flag ('V', | 268 | GNUNET_GETOPT_option_flag('V', |
263 | "view", | 269 | "view", |
264 | gettext_noop ("Get updates of view (0 for infinite updates)"), | 270 | gettext_noop("Get updates of view (0 for infinite updates)"), |
265 | &view_update), | 271 | &view_update), |
266 | GNUNET_GETOPT_option_flag ('S', | 272 | GNUNET_GETOPT_option_flag('S', |
267 | "stream", | 273 | "stream", |
268 | gettext_noop ("Get peers from biased stream"), | 274 | gettext_noop("Get peers from biased stream"), |
269 | &stream_input), | 275 | &stream_input), |
270 | GNUNET_GETOPT_OPTION_END | 276 | GNUNET_GETOPT_OPTION_END |
271 | }; | 277 | }; |
278 | |||
272 | return (GNUNET_OK == | 279 | return (GNUNET_OK == |
273 | GNUNET_PROGRAM_run (argc, | 280 | GNUNET_PROGRAM_run(argc, |
274 | argv, | 281 | argv, |
275 | "gnunet-rps [NUMBER_OF_PEERS]", | 282 | "gnunet-rps [NUMBER_OF_PEERS]", |
276 | gettext_noop | 283 | gettext_noop |
277 | (helpstr), | 284 | (helpstr), |
278 | options, &run, NULL)) ? ret : 1; | 285 | options, &run, NULL)) ? ret : 1; |
279 | } | 286 | } |
280 | 287 | ||
281 | /* end of gnunet-rps.c */ | 288 | /* end of gnunet-rps.c */ |
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index bbfdba3ac..32f3103ed 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file rps/gnunet-service-rps.c | 22 | * @file rps/gnunet-service-rps.c |
@@ -54,7 +54,7 @@ | |||
54 | // hist_size_init, hist_size_max | 54 | // hist_size_init, hist_size_max |
55 | 55 | ||
56 | /*********************************************************************** | 56 | /*********************************************************************** |
57 | * Old gnunet-service-rps_peers.c | 57 | * Old gnunet-service-rps_peers.c |
58 | ***********************************************************************/ | 58 | ***********************************************************************/ |
59 | 59 | ||
60 | /** | 60 | /** |
@@ -65,7 +65,7 @@ | |||
65 | /** | 65 | /** |
66 | * Get peer flag of given peer context. | 66 | * Get peer flag of given peer context. |
67 | */ | 67 | */ |
68 | #define check_peer_flag_set(peer_ctx, mask)\ | 68 | #define check_peer_flag_set(peer_ctx, mask) \ |
69 | ((peer_ctx->peer_flags) & (mask) ? GNUNET_YES : GNUNET_NO) | 69 | ((peer_ctx->peer_flags) & (mask) ? GNUNET_YES : GNUNET_NO) |
70 | 70 | ||
71 | /** | 71 | /** |
@@ -76,7 +76,7 @@ | |||
76 | /** | 76 | /** |
77 | * Get channel flag of given channel context. | 77 | * Get channel flag of given channel context. |
78 | */ | 78 | */ |
79 | #define check_channel_flag_set(channel_flags, mask)\ | 79 | #define check_channel_flag_set(channel_flags, mask) \ |
80 | ((*channel_flags) & (mask) ? GNUNET_YES : GNUNET_NO) | 80 | ((*channel_flags) & (mask) ? GNUNET_YES : GNUNET_NO) |
81 | 81 | ||
82 | /** | 82 | /** |
@@ -92,8 +92,7 @@ | |||
92 | * When an operation cannot be executed right now this struct is used to store | 92 | * When an operation cannot be executed right now this struct is used to store |
93 | * the callback and closure for later execution. | 93 | * the callback and closure for later execution. |
94 | */ | 94 | */ |
95 | struct PeerPendingOp | 95 | struct PeerPendingOp { |
96 | { | ||
97 | /** | 96 | /** |
98 | * Callback | 97 | * Callback |
99 | */ | 98 | */ |
@@ -111,8 +110,7 @@ struct PeerPendingOp | |||
111 | * This is used to keep track of all messages that have not been sent yet. When | 110 | * This is used to keep track of all messages that have not been sent yet. When |
112 | * a peer is to be removed the pending messages can be removed properly. | 111 | * a peer is to be removed the pending messages can be removed properly. |
113 | */ | 112 | */ |
114 | struct PendingMessage | 113 | struct PendingMessage { |
115 | { | ||
116 | /** | 114 | /** |
117 | * DLL next, prev | 115 | * DLL next, prev |
118 | */ | 116 | */ |
@@ -148,8 +146,7 @@ struct ChannelCtx; | |||
148 | * status about the channels, the pending operations on this peer and some flags | 146 | * status about the channels, the pending operations on this peer and some flags |
149 | * about the status of the peer itself. (online, valid, ...) | 147 | * about the status of the peer itself. (online, valid, ...) |
150 | */ | 148 | */ |
151 | struct PeerContext | 149 | struct PeerContext { |
152 | { | ||
153 | /** | 150 | /** |
154 | * The Sub this context belongs to. | 151 | * The Sub this context belongs to. |
155 | */ | 152 | */ |
@@ -224,8 +221,7 @@ struct PeerContext | |||
224 | /** | 221 | /** |
225 | * @brief Closure to #valid_peer_iterator | 222 | * @brief Closure to #valid_peer_iterator |
226 | */ | 223 | */ |
227 | struct PeersIteratorCls | 224 | struct PeersIteratorCls { |
228 | { | ||
229 | /** | 225 | /** |
230 | * Iterator function | 226 | * Iterator function |
231 | */ | 227 | */ |
@@ -240,8 +236,7 @@ struct PeersIteratorCls | |||
240 | /** | 236 | /** |
241 | * @brief Context for a channel | 237 | * @brief Context for a channel |
242 | */ | 238 | */ |
243 | struct ChannelCtx | 239 | struct ChannelCtx { |
244 | { | ||
245 | /** | 240 | /** |
246 | * @brief The channel itself | 241 | * @brief The channel itself |
247 | */ | 242 | */ |
@@ -266,8 +261,7 @@ struct ChannelCtx | |||
266 | /** | 261 | /** |
267 | * If type is 2 This struct is used to store the attacked peers in a DLL | 262 | * If type is 2 This struct is used to store the attacked peers in a DLL |
268 | */ | 263 | */ |
269 | struct AttackedPeer | 264 | struct AttackedPeer { |
270 | { | ||
271 | /** | 265 | /** |
272 | * DLL | 266 | * DLL |
273 | */ | 267 | */ |
@@ -302,8 +296,7 @@ struct AttackedPeer | |||
302 | * Essentially one instance of brahms that only connects to other instances | 296 | * Essentially one instance of brahms that only connects to other instances |
303 | * with the same (secret) value. | 297 | * with the same (secret) value. |
304 | */ | 298 | */ |
305 | struct Sub | 299 | struct Sub { |
306 | { | ||
307 | /** | 300 | /** |
308 | * @brief Hash of the shared value that defines Subs. | 301 | * @brief Hash of the shared value that defines Subs. |
309 | */ | 302 | */ |
@@ -448,7 +441,7 @@ struct Sub | |||
448 | 441 | ||
449 | 442 | ||
450 | /*********************************************************************** | 443 | /*********************************************************************** |
451 | * Globals | 444 | * Globals |
452 | ***********************************************************************/ | 445 | ***********************************************************************/ |
453 | 446 | ||
454 | /** | 447 | /** |
@@ -590,15 +583,15 @@ static struct Sub *msub; | |||
590 | static const uint32_t num_valid_peers_max = UINT32_MAX; | 583 | static const uint32_t num_valid_peers_max = UINT32_MAX; |
591 | 584 | ||
592 | /*********************************************************************** | 585 | /*********************************************************************** |
593 | * /Globals | 586 | * /Globals |
594 | ***********************************************************************/ | 587 | ***********************************************************************/ |
595 | 588 | ||
596 | 589 | ||
597 | static void | 590 | static void |
598 | do_round (void *cls); | 591 | do_round(void *cls); |
599 | 592 | ||
600 | static void | 593 | static void |
601 | do_mal_round (void *cls); | 594 | do_mal_round(void *cls); |
602 | 595 | ||
603 | 596 | ||
604 | /** | 597 | /** |
@@ -610,16 +603,16 @@ do_mal_round (void *cls); | |||
610 | * @return the #PeerContext | 603 | * @return the #PeerContext |
611 | */ | 604 | */ |
612 | static struct PeerContext * | 605 | static struct PeerContext * |
613 | get_peer_ctx (const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, | 606 | get_peer_ctx(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, |
614 | const struct GNUNET_PeerIdentity *peer) | 607 | const struct GNUNET_PeerIdentity *peer) |
615 | { | 608 | { |
616 | struct PeerContext *ctx; | 609 | struct PeerContext *ctx; |
617 | int ret; | 610 | int ret; |
618 | 611 | ||
619 | ret = GNUNET_CONTAINER_multipeermap_contains (peer_map, peer); | 612 | ret = GNUNET_CONTAINER_multipeermap_contains(peer_map, peer); |
620 | GNUNET_assert (GNUNET_YES == ret); | 613 | GNUNET_assert(GNUNET_YES == ret); |
621 | ctx = GNUNET_CONTAINER_multipeermap_get (peer_map, peer); | 614 | ctx = GNUNET_CONTAINER_multipeermap_get(peer_map, peer); |
622 | GNUNET_assert (NULL != ctx); | 615 | GNUNET_assert(NULL != ctx); |
623 | return ctx; | 616 | return ctx; |
624 | } | 617 | } |
625 | 618 | ||
@@ -635,17 +628,17 @@ get_peer_ctx (const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, | |||
635 | * #GNUNET_NO if peer is not knwon | 628 | * #GNUNET_NO if peer is not knwon |
636 | */ | 629 | */ |
637 | static int | 630 | static int |
638 | check_peer_known (const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, | 631 | check_peer_known(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, |
639 | const struct GNUNET_PeerIdentity *peer) | 632 | const struct GNUNET_PeerIdentity *peer) |
640 | { | 633 | { |
641 | if (NULL != peer_map) | 634 | if (NULL != peer_map) |
642 | { | 635 | { |
643 | return GNUNET_CONTAINER_multipeermap_contains (peer_map, peer); | 636 | return GNUNET_CONTAINER_multipeermap_contains(peer_map, peer); |
644 | } | 637 | } |
645 | else | 638 | else |
646 | { | 639 | { |
647 | return GNUNET_NO; | 640 | return GNUNET_NO; |
648 | } | 641 | } |
649 | } | 642 | } |
650 | 643 | ||
651 | 644 | ||
@@ -658,27 +651,27 @@ check_peer_known (const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, | |||
658 | * @return the #PeerContext | 651 | * @return the #PeerContext |
659 | */ | 652 | */ |
660 | static struct PeerContext * | 653 | static struct PeerContext * |
661 | create_peer_ctx (struct Sub *sub, | 654 | create_peer_ctx(struct Sub *sub, |
662 | const struct GNUNET_PeerIdentity *peer) | 655 | const struct GNUNET_PeerIdentity *peer) |
663 | { | 656 | { |
664 | struct PeerContext *ctx; | 657 | struct PeerContext *ctx; |
665 | int ret; | 658 | int ret; |
666 | 659 | ||
667 | GNUNET_assert (GNUNET_NO == check_peer_known (sub->peer_map, peer)); | 660 | GNUNET_assert(GNUNET_NO == check_peer_known(sub->peer_map, peer)); |
668 | 661 | ||
669 | ctx = GNUNET_new (struct PeerContext); | 662 | ctx = GNUNET_new(struct PeerContext); |
670 | ctx->peer_id = *peer; | 663 | ctx->peer_id = *peer; |
671 | ctx->sub = sub; | 664 | ctx->sub = sub; |
672 | ret = GNUNET_CONTAINER_multipeermap_put (sub->peer_map, peer, ctx, | 665 | ret = GNUNET_CONTAINER_multipeermap_put(sub->peer_map, peer, ctx, |
673 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 666 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
674 | GNUNET_assert (GNUNET_OK == ret); | 667 | GNUNET_assert(GNUNET_OK == ret); |
675 | if (sub == msub) | 668 | if (sub == msub) |
676 | { | 669 | { |
677 | GNUNET_STATISTICS_set (stats, | 670 | GNUNET_STATISTICS_set(stats, |
678 | "# known peers", | 671 | "# known peers", |
679 | GNUNET_CONTAINER_multipeermap_size (sub->peer_map), | 672 | GNUNET_CONTAINER_multipeermap_size(sub->peer_map), |
680 | GNUNET_NO); | 673 | GNUNET_NO); |
681 | } | 674 | } |
682 | return ctx; | 675 | return ctx; |
683 | } | 676 | } |
684 | 677 | ||
@@ -692,14 +685,14 @@ create_peer_ctx (struct Sub *sub, | |||
692 | * @return the context | 685 | * @return the context |
693 | */ | 686 | */ |
694 | static struct PeerContext * | 687 | static struct PeerContext * |
695 | create_or_get_peer_ctx (struct Sub *sub, | 688 | create_or_get_peer_ctx(struct Sub *sub, |
696 | const struct GNUNET_PeerIdentity *peer) | 689 | const struct GNUNET_PeerIdentity *peer) |
697 | { | 690 | { |
698 | if (GNUNET_NO == check_peer_known (sub->peer_map, peer)) | 691 | if (GNUNET_NO == check_peer_known(sub->peer_map, peer)) |
699 | { | 692 | { |
700 | return create_peer_ctx (sub, peer); | 693 | return create_peer_ctx(sub, peer); |
701 | } | 694 | } |
702 | return get_peer_ctx (sub->peer_map, peer); | 695 | return get_peer_ctx(sub->peer_map, peer); |
703 | } | 696 | } |
704 | 697 | ||
705 | 698 | ||
@@ -714,25 +707,25 @@ create_or_get_peer_ctx (struct Sub *sub, | |||
714 | * #GNUNET_NO otherwise | 707 | * #GNUNET_NO otherwise |
715 | */ | 708 | */ |
716 | static int | 709 | static int |
717 | check_connected (struct PeerContext *peer_ctx) | 710 | check_connected(struct PeerContext *peer_ctx) |
718 | { | 711 | { |
719 | /* If we don't know about this peer we don't know whether it's online */ | 712 | /* If we don't know about this peer we don't know whether it's online */ |
720 | if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map, | 713 | if (GNUNET_NO == check_peer_known(peer_ctx->sub->peer_map, |
721 | &peer_ctx->peer_id)) | 714 | &peer_ctx->peer_id)) |
722 | { | 715 | { |
723 | return GNUNET_NO; | 716 | return GNUNET_NO; |
724 | } | 717 | } |
725 | /* Get the context */ | 718 | /* Get the context */ |
726 | peer_ctx = get_peer_ctx (peer_ctx->sub->peer_map, &peer_ctx->peer_id); | 719 | peer_ctx = get_peer_ctx(peer_ctx->sub->peer_map, &peer_ctx->peer_id); |
727 | /* If we have no channel to this peer we don't know whether it's online */ | 720 | /* If we have no channel to this peer we don't know whether it's online */ |
728 | if ( (NULL == peer_ctx->send_channel_ctx) && | 721 | if ((NULL == peer_ctx->send_channel_ctx) && |
729 | (NULL == peer_ctx->recv_channel_ctx) ) | 722 | (NULL == peer_ctx->recv_channel_ctx)) |
730 | { | 723 | { |
731 | UNSET_PEER_FLAG (peer_ctx, Peers_ONLINE); | 724 | UNSET_PEER_FLAG(peer_ctx, Peers_ONLINE); |
732 | return GNUNET_NO; | 725 | return GNUNET_NO; |
733 | } | 726 | } |
734 | /* Otherwise (if we have a channel, we know that it's online */ | 727 | /* Otherwise (if we have a channel, we know that it's online */ |
735 | SET_PEER_FLAG (peer_ctx, Peers_ONLINE); | 728 | SET_PEER_FLAG(peer_ctx, Peers_ONLINE); |
736 | return GNUNET_YES; | 729 | return GNUNET_YES; |
737 | } | 730 | } |
738 | 731 | ||
@@ -740,8 +733,7 @@ check_connected (struct PeerContext *peer_ctx) | |||
740 | /** | 733 | /** |
741 | * @brief The closure to #get_rand_peer_iterator. | 734 | * @brief The closure to #get_rand_peer_iterator. |
742 | */ | 735 | */ |
743 | struct GetRandPeerIteratorCls | 736 | struct GetRandPeerIteratorCls { |
744 | { | ||
745 | /** | 737 | /** |
746 | * @brief The index of the peer to return. | 738 | * @brief The index of the peer to return. |
747 | * Will be decreased until 0. | 739 | * Will be decreased until 0. |
@@ -772,18 +764,19 @@ struct GetRandPeerIteratorCls | |||
772 | * #GNUNET_NO if not. | 764 | * #GNUNET_NO if not. |
773 | */ | 765 | */ |
774 | static int | 766 | static int |
775 | get_rand_peer_iterator (void *cls, | 767 | get_rand_peer_iterator(void *cls, |
776 | const struct GNUNET_PeerIdentity *peer, | 768 | const struct GNUNET_PeerIdentity *peer, |
777 | void *value) | 769 | void *value) |
778 | { | 770 | { |
779 | struct GetRandPeerIteratorCls *iterator_cls = cls; | 771 | struct GetRandPeerIteratorCls *iterator_cls = cls; |
780 | (void) value; | 772 | |
773 | (void)value; | ||
781 | 774 | ||
782 | if (0 >= iterator_cls->index) | 775 | if (0 >= iterator_cls->index) |
783 | { | 776 | { |
784 | iterator_cls->peer = peer; | 777 | iterator_cls->peer = peer; |
785 | return GNUNET_NO; | 778 | return GNUNET_NO; |
786 | } | 779 | } |
787 | iterator_cls->index--; | 780 | iterator_cls->index--; |
788 | return GNUNET_YES; | 781 | return GNUNET_YES; |
789 | } | 782 | } |
@@ -798,19 +791,19 @@ get_rand_peer_iterator (void *cls, | |||
798 | * @return a random peer | 791 | * @return a random peer |
799 | */ | 792 | */ |
800 | static const struct GNUNET_PeerIdentity * | 793 | static const struct GNUNET_PeerIdentity * |
801 | get_random_peer_from_peermap (struct GNUNET_CONTAINER_MultiPeerMap *valid_peers) | 794 | get_random_peer_from_peermap(struct GNUNET_CONTAINER_MultiPeerMap *valid_peers) |
802 | { | 795 | { |
803 | struct GetRandPeerIteratorCls *iterator_cls; | 796 | struct GetRandPeerIteratorCls *iterator_cls; |
804 | const struct GNUNET_PeerIdentity *ret; | 797 | const struct GNUNET_PeerIdentity *ret; |
805 | 798 | ||
806 | iterator_cls = GNUNET_new (struct GetRandPeerIteratorCls); | 799 | iterator_cls = GNUNET_new(struct GetRandPeerIteratorCls); |
807 | iterator_cls->index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 800 | iterator_cls->index = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
808 | GNUNET_CONTAINER_multipeermap_size (valid_peers)); | 801 | GNUNET_CONTAINER_multipeermap_size(valid_peers)); |
809 | (void) GNUNET_CONTAINER_multipeermap_iterate (valid_peers, | 802 | (void)GNUNET_CONTAINER_multipeermap_iterate(valid_peers, |
810 | get_rand_peer_iterator, | 803 | get_rand_peer_iterator, |
811 | iterator_cls); | 804 | iterator_cls); |
812 | ret = iterator_cls->peer; | 805 | ret = iterator_cls->peer; |
813 | GNUNET_free (iterator_cls); | 806 | GNUNET_free(iterator_cls); |
814 | return ret; | 807 | return ret; |
815 | } | 808 | } |
816 | 809 | ||
@@ -827,8 +820,8 @@ get_random_peer_from_peermap (struct GNUNET_CONTAINER_MultiPeerMap *valid_peers) | |||
827 | * #GNUNET_NO otherwise | 820 | * #GNUNET_NO otherwise |
828 | */ | 821 | */ |
829 | static int | 822 | static int |
830 | add_valid_peer (const struct GNUNET_PeerIdentity *peer, | 823 | add_valid_peer(const struct GNUNET_PeerIdentity *peer, |
831 | struct GNUNET_CONTAINER_MultiPeerMap *valid_peers) | 824 | struct GNUNET_CONTAINER_MultiPeerMap *valid_peers) |
832 | { | 825 | { |
833 | const struct GNUNET_PeerIdentity *rand_peer; | 826 | const struct GNUNET_PeerIdentity *rand_peer; |
834 | int ret; | 827 | int ret; |
@@ -836,26 +829,26 @@ add_valid_peer (const struct GNUNET_PeerIdentity *peer, | |||
836 | ret = GNUNET_YES; | 829 | ret = GNUNET_YES; |
837 | /* Remove random peers until there is space for a new one */ | 830 | /* Remove random peers until there is space for a new one */ |
838 | while (num_valid_peers_max <= | 831 | while (num_valid_peers_max <= |
839 | GNUNET_CONTAINER_multipeermap_size (valid_peers)) | 832 | GNUNET_CONTAINER_multipeermap_size(valid_peers)) |
840 | { | 833 | { |
841 | rand_peer = get_random_peer_from_peermap (valid_peers); | 834 | rand_peer = get_random_peer_from_peermap(valid_peers); |
842 | GNUNET_CONTAINER_multipeermap_remove_all (valid_peers, rand_peer); | 835 | GNUNET_CONTAINER_multipeermap_remove_all(valid_peers, rand_peer); |
843 | ret = GNUNET_NO; | 836 | ret = GNUNET_NO; |
844 | } | 837 | } |
845 | (void) GNUNET_CONTAINER_multipeermap_put (valid_peers, peer, NULL, | 838 | (void)GNUNET_CONTAINER_multipeermap_put(valid_peers, peer, NULL, |
846 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 839 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
847 | if (valid_peers == msub->valid_peers) | 840 | if (valid_peers == msub->valid_peers) |
848 | { | 841 | { |
849 | GNUNET_STATISTICS_set (stats, | 842 | GNUNET_STATISTICS_set(stats, |
850 | "# valid peers", | 843 | "# valid peers", |
851 | GNUNET_CONTAINER_multipeermap_size (valid_peers), | 844 | GNUNET_CONTAINER_multipeermap_size(valid_peers), |
852 | GNUNET_NO); | 845 | GNUNET_NO); |
853 | } | 846 | } |
854 | return ret; | 847 | return ret; |
855 | } | 848 | } |
856 | 849 | ||
857 | static void | 850 | static void |
858 | remove_pending_message (struct PendingMessage *pending_msg, int cancel); | 851 | remove_pending_message(struct PendingMessage *pending_msg, int cancel); |
859 | 852 | ||
860 | /** | 853 | /** |
861 | * @brief Set the peer flag to living and | 854 | * @brief Set the peer flag to living and |
@@ -866,62 +859,62 @@ remove_pending_message (struct PendingMessage *pending_msg, int cancel); | |||
866 | * @param peer_ctx the #PeerContext of the peer to set online | 859 | * @param peer_ctx the #PeerContext of the peer to set online |
867 | */ | 860 | */ |
868 | static void | 861 | static void |
869 | set_peer_online (struct PeerContext *peer_ctx) | 862 | set_peer_online(struct PeerContext *peer_ctx) |
870 | { | 863 | { |
871 | struct GNUNET_PeerIdentity *peer; | 864 | struct GNUNET_PeerIdentity *peer; |
872 | unsigned int i; | 865 | unsigned int i; |
873 | 866 | ||
874 | peer = &peer_ctx->peer_id; | 867 | peer = &peer_ctx->peer_id; |
875 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 868 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
876 | "Peer %s is online and valid, calling %i pending operations on it\n", | 869 | "Peer %s is online and valid, calling %i pending operations on it\n", |
877 | GNUNET_i2s (peer), | 870 | GNUNET_i2s(peer), |
878 | peer_ctx->num_pending_ops); | 871 | peer_ctx->num_pending_ops); |
879 | 872 | ||
880 | if (NULL != peer_ctx->online_check_pending) | 873 | if (NULL != peer_ctx->online_check_pending) |
881 | { | 874 | { |
882 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 875 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
883 | "Removing pending online check for peer %s\n", | 876 | "Removing pending online check for peer %s\n", |
884 | GNUNET_i2s (&peer_ctx->peer_id)); | 877 | GNUNET_i2s(&peer_ctx->peer_id)); |
885 | // TODO wait until cadet sets mq->cancel_impl | 878 | // TODO wait until cadet sets mq->cancel_impl |
886 | //GNUNET_MQ_send_cancel (peer_ctx->online_check_pending->ev); | 879 | //GNUNET_MQ_send_cancel (peer_ctx->online_check_pending->ev); |
887 | remove_pending_message (peer_ctx->online_check_pending, GNUNET_YES); | 880 | remove_pending_message(peer_ctx->online_check_pending, GNUNET_YES); |
888 | peer_ctx->online_check_pending = NULL; | 881 | peer_ctx->online_check_pending = NULL; |
889 | } | 882 | } |
890 | 883 | ||
891 | SET_PEER_FLAG (peer_ctx, Peers_ONLINE); | 884 | SET_PEER_FLAG(peer_ctx, Peers_ONLINE); |
892 | 885 | ||
893 | /* Call pending operations */ | 886 | /* Call pending operations */ |
894 | for (i = 0; i < peer_ctx->num_pending_ops; i++) | 887 | for (i = 0; i < peer_ctx->num_pending_ops; i++) |
895 | { | 888 | { |
896 | peer_ctx->pending_ops[i].op (peer_ctx->pending_ops[i].op_cls, peer); | 889 | peer_ctx->pending_ops[i].op(peer_ctx->pending_ops[i].op_cls, peer); |
897 | } | 890 | } |
898 | GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0); | 891 | GNUNET_array_grow(peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0); |
899 | } | 892 | } |
900 | 893 | ||
901 | static void | 894 | static void |
902 | cleanup_destroyed_channel (void *cls, | 895 | cleanup_destroyed_channel(void *cls, |
903 | const struct GNUNET_CADET_Channel *channel); | 896 | const struct GNUNET_CADET_Channel *channel); |
904 | 897 | ||
905 | /* Declaration of handlers */ | 898 | /* Declaration of handlers */ |
906 | static void | 899 | static void |
907 | handle_peer_check (void *cls, | 900 | handle_peer_check(void *cls, |
908 | const struct GNUNET_MessageHeader *msg); | 901 | const struct GNUNET_MessageHeader *msg); |
909 | 902 | ||
910 | static void | 903 | static void |
911 | handle_peer_push (void *cls, | 904 | handle_peer_push(void *cls, |
912 | const struct GNUNET_MessageHeader *msg); | 905 | const struct GNUNET_MessageHeader *msg); |
913 | 906 | ||
914 | static void | 907 | static void |
915 | handle_peer_pull_request (void *cls, | 908 | handle_peer_pull_request(void *cls, |
916 | const struct GNUNET_MessageHeader *msg); | 909 | const struct GNUNET_MessageHeader *msg); |
917 | 910 | ||
918 | static int | 911 | static int |
919 | check_peer_pull_reply (void *cls, | 912 | check_peer_pull_reply(void *cls, |
920 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg); | 913 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg); |
921 | 914 | ||
922 | static void | 915 | static void |
923 | handle_peer_pull_reply (void *cls, | 916 | handle_peer_pull_reply(void *cls, |
924 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg); | 917 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg); |
925 | 918 | ||
926 | /* End declaration of handlers */ | 919 | /* End declaration of handlers */ |
927 | 920 | ||
@@ -933,10 +926,11 @@ handle_peer_pull_reply (void *cls, | |||
933 | * @return The channel context | 926 | * @return The channel context |
934 | */ | 927 | */ |
935 | static struct ChannelCtx * | 928 | static struct ChannelCtx * |
936 | add_channel_ctx (struct PeerContext *peer_ctx) | 929 | add_channel_ctx(struct PeerContext *peer_ctx) |
937 | { | 930 | { |
938 | struct ChannelCtx *channel_ctx; | 931 | struct ChannelCtx *channel_ctx; |
939 | channel_ctx = GNUNET_new (struct ChannelCtx); | 932 | |
933 | channel_ctx = GNUNET_new(struct ChannelCtx); | ||
940 | channel_ctx->peer_ctx = peer_ctx; | 934 | channel_ctx->peer_ctx = peer_ctx; |
941 | return channel_ctx; | 935 | return channel_ctx; |
942 | } | 936 | } |
@@ -948,28 +942,29 @@ add_channel_ctx (struct PeerContext *peer_ctx) | |||
948 | * @param channel_ctx The channel context. | 942 | * @param channel_ctx The channel context. |
949 | */ | 943 | */ |
950 | static void | 944 | static void |
951 | remove_channel_ctx (struct ChannelCtx *channel_ctx) | 945 | remove_channel_ctx(struct ChannelCtx *channel_ctx) |
952 | { | 946 | { |
953 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; | 947 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; |
954 | 948 | ||
955 | if (NULL != channel_ctx->destruction_task) | 949 | if (NULL != channel_ctx->destruction_task) |
956 | { | 950 | { |
957 | GNUNET_SCHEDULER_cancel (channel_ctx->destruction_task); | 951 | GNUNET_SCHEDULER_cancel(channel_ctx->destruction_task); |
958 | channel_ctx->destruction_task = NULL; | 952 | channel_ctx->destruction_task = NULL; |
959 | } | 953 | } |
960 | 954 | ||
961 | GNUNET_free (channel_ctx); | 955 | GNUNET_free(channel_ctx); |
962 | 956 | ||
963 | if (NULL == peer_ctx) return; | 957 | if (NULL == peer_ctx) |
958 | return; | ||
964 | if (channel_ctx == peer_ctx->send_channel_ctx) | 959 | if (channel_ctx == peer_ctx->send_channel_ctx) |
965 | { | 960 | { |
966 | peer_ctx->send_channel_ctx = NULL; | 961 | peer_ctx->send_channel_ctx = NULL; |
967 | peer_ctx->mq = NULL; | 962 | peer_ctx->mq = NULL; |
968 | } | 963 | } |
969 | else if (channel_ctx == peer_ctx->recv_channel_ctx) | 964 | else if (channel_ctx == peer_ctx->recv_channel_ctx) |
970 | { | 965 | { |
971 | peer_ctx->recv_channel_ctx = NULL; | 966 | peer_ctx->recv_channel_ctx = NULL; |
972 | } | 967 | } |
973 | } | 968 | } |
974 | 969 | ||
975 | 970 | ||
@@ -980,47 +975,47 @@ remove_channel_ctx (struct ChannelCtx *channel_ctx) | |||
980 | * @return the #GNUNET_CADET_Channel used to send data to @a peer_ctx | 975 | * @return the #GNUNET_CADET_Channel used to send data to @a peer_ctx |
981 | */ | 976 | */ |
982 | struct GNUNET_CADET_Channel * | 977 | struct GNUNET_CADET_Channel * |
983 | get_channel (struct PeerContext *peer_ctx) | 978 | get_channel(struct PeerContext *peer_ctx) |
984 | { | 979 | { |
985 | /* There exists a copy-paste-clone in run() */ | 980 | /* There exists a copy-paste-clone in run() */ |
986 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { | 981 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { |
987 | GNUNET_MQ_hd_fixed_size (peer_check, | 982 | GNUNET_MQ_hd_fixed_size(peer_check, |
988 | GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE, | 983 | GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE, |
989 | struct GNUNET_MessageHeader, | 984 | struct GNUNET_MessageHeader, |
990 | NULL), | 985 | NULL), |
991 | GNUNET_MQ_hd_fixed_size (peer_push, | 986 | GNUNET_MQ_hd_fixed_size(peer_push, |
992 | GNUNET_MESSAGE_TYPE_RPS_PP_PUSH, | 987 | GNUNET_MESSAGE_TYPE_RPS_PP_PUSH, |
993 | struct GNUNET_MessageHeader, | 988 | struct GNUNET_MessageHeader, |
994 | NULL), | 989 | NULL), |
995 | GNUNET_MQ_hd_fixed_size (peer_pull_request, | 990 | GNUNET_MQ_hd_fixed_size(peer_pull_request, |
996 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST, | 991 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST, |
997 | struct GNUNET_MessageHeader, | 992 | struct GNUNET_MessageHeader, |
998 | NULL), | 993 | NULL), |
999 | GNUNET_MQ_hd_var_size (peer_pull_reply, | 994 | GNUNET_MQ_hd_var_size(peer_pull_reply, |
1000 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY, | 995 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY, |
1001 | struct GNUNET_RPS_P2P_PullReplyMessage, | 996 | struct GNUNET_RPS_P2P_PullReplyMessage, |
1002 | NULL), | 997 | NULL), |
1003 | GNUNET_MQ_handler_end () | 998 | GNUNET_MQ_handler_end() |
1004 | }; | 999 | }; |
1005 | 1000 | ||
1006 | 1001 | ||
1007 | if (NULL == peer_ctx->send_channel_ctx) | 1002 | if (NULL == peer_ctx->send_channel_ctx) |
1008 | { | 1003 | { |
1009 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1004 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1010 | "Trying to establish channel to peer %s\n", | 1005 | "Trying to establish channel to peer %s\n", |
1011 | GNUNET_i2s (&peer_ctx->peer_id)); | 1006 | GNUNET_i2s(&peer_ctx->peer_id)); |
1012 | peer_ctx->send_channel_ctx = add_channel_ctx (peer_ctx); | 1007 | peer_ctx->send_channel_ctx = add_channel_ctx(peer_ctx); |
1013 | peer_ctx->send_channel_ctx->channel = | 1008 | peer_ctx->send_channel_ctx->channel = |
1014 | GNUNET_CADET_channel_create (cadet_handle, | 1009 | GNUNET_CADET_channel_create(cadet_handle, |
1015 | peer_ctx->send_channel_ctx, /* context */ | 1010 | peer_ctx->send_channel_ctx, /* context */ |
1016 | &peer_ctx->peer_id, | 1011 | &peer_ctx->peer_id, |
1017 | &peer_ctx->sub->hash, | 1012 | &peer_ctx->sub->hash, |
1018 | NULL, /* WindowSize handler */ | 1013 | NULL, /* WindowSize handler */ |
1019 | &cleanup_destroyed_channel, /* Disconnect handler */ | 1014 | &cleanup_destroyed_channel, /* Disconnect handler */ |
1020 | cadet_handlers); | 1015 | cadet_handlers); |
1021 | } | 1016 | } |
1022 | GNUNET_assert (NULL != peer_ctx->send_channel_ctx); | 1017 | GNUNET_assert(NULL != peer_ctx->send_channel_ctx); |
1023 | GNUNET_assert (NULL != peer_ctx->send_channel_ctx->channel); | 1018 | GNUNET_assert(NULL != peer_ctx->send_channel_ctx->channel); |
1024 | return peer_ctx->send_channel_ctx->channel; | 1019 | return peer_ctx->send_channel_ctx->channel; |
1025 | } | 1020 | } |
1026 | 1021 | ||
@@ -1035,12 +1030,12 @@ get_channel (struct PeerContext *peer_ctx) | |||
1035 | * @return the #GNUNET_MQ_Handle | 1030 | * @return the #GNUNET_MQ_Handle |
1036 | */ | 1031 | */ |
1037 | static struct GNUNET_MQ_Handle * | 1032 | static struct GNUNET_MQ_Handle * |
1038 | get_mq (struct PeerContext *peer_ctx) | 1033 | get_mq(struct PeerContext *peer_ctx) |
1039 | { | 1034 | { |
1040 | if (NULL == peer_ctx->mq) | 1035 | if (NULL == peer_ctx->mq) |
1041 | { | 1036 | { |
1042 | peer_ctx->mq = GNUNET_CADET_get_mq (get_channel (peer_ctx)); | 1037 | peer_ctx->mq = GNUNET_CADET_get_mq(get_channel(peer_ctx)); |
1043 | } | 1038 | } |
1044 | return peer_ctx->mq; | 1039 | return peer_ctx->mq; |
1045 | } | 1040 | } |
1046 | 1041 | ||
@@ -1053,19 +1048,19 @@ get_mq (struct PeerContext *peer_ctx) | |||
1053 | * @return pointer to pending message | 1048 | * @return pointer to pending message |
1054 | */ | 1049 | */ |
1055 | static struct PendingMessage * | 1050 | static struct PendingMessage * |
1056 | insert_pending_message (struct PeerContext *peer_ctx, | 1051 | insert_pending_message(struct PeerContext *peer_ctx, |
1057 | struct GNUNET_MQ_Envelope *ev, | 1052 | struct GNUNET_MQ_Envelope *ev, |
1058 | const char *type) | 1053 | const char *type) |
1059 | { | 1054 | { |
1060 | struct PendingMessage *pending_msg; | 1055 | struct PendingMessage *pending_msg; |
1061 | 1056 | ||
1062 | pending_msg = GNUNET_new (struct PendingMessage); | 1057 | pending_msg = GNUNET_new(struct PendingMessage); |
1063 | pending_msg->ev = ev; | 1058 | pending_msg->ev = ev; |
1064 | pending_msg->peer_ctx = peer_ctx; | 1059 | pending_msg->peer_ctx = peer_ctx; |
1065 | pending_msg->type = type; | 1060 | pending_msg->type = type; |
1066 | GNUNET_CONTAINER_DLL_insert (peer_ctx->pending_messages_head, | 1061 | GNUNET_CONTAINER_DLL_insert(peer_ctx->pending_messages_head, |
1067 | peer_ctx->pending_messages_tail, | 1062 | peer_ctx->pending_messages_tail, |
1068 | pending_msg); | 1063 | pending_msg); |
1069 | return pending_msg; | 1064 | return pending_msg; |
1070 | } | 1065 | } |
1071 | 1066 | ||
@@ -1077,22 +1072,23 @@ insert_pending_message (struct PeerContext *peer_ctx, | |||
1077 | * @param cancel whether to cancel the pending message, too | 1072 | * @param cancel whether to cancel the pending message, too |
1078 | */ | 1073 | */ |
1079 | static void | 1074 | static void |
1080 | remove_pending_message (struct PendingMessage *pending_msg, int cancel) | 1075 | remove_pending_message(struct PendingMessage *pending_msg, int cancel) |
1081 | { | 1076 | { |
1082 | struct PeerContext *peer_ctx; | 1077 | struct PeerContext *peer_ctx; |
1083 | (void) cancel; | 1078 | |
1079 | (void)cancel; | ||
1084 | 1080 | ||
1085 | peer_ctx = pending_msg->peer_ctx; | 1081 | peer_ctx = pending_msg->peer_ctx; |
1086 | GNUNET_assert (NULL != peer_ctx); | 1082 | GNUNET_assert(NULL != peer_ctx); |
1087 | GNUNET_CONTAINER_DLL_remove (peer_ctx->pending_messages_head, | 1083 | GNUNET_CONTAINER_DLL_remove(peer_ctx->pending_messages_head, |
1088 | peer_ctx->pending_messages_tail, | 1084 | peer_ctx->pending_messages_tail, |
1089 | pending_msg); | 1085 | pending_msg); |
1090 | // TODO wait for the cadet implementation of message cancellation | 1086 | // TODO wait for the cadet implementation of message cancellation |
1091 | //if (GNUNET_YES == cancel) | 1087 | //if (GNUNET_YES == cancel) |
1092 | //{ | 1088 | //{ |
1093 | // GNUNET_MQ_send_cancel (pending_msg->ev); | 1089 | // GNUNET_MQ_send_cancel (pending_msg->ev); |
1094 | //} | 1090 | //} |
1095 | GNUNET_free (pending_msg); | 1091 | GNUNET_free(pending_msg); |
1096 | } | 1092 | } |
1097 | 1093 | ||
1098 | 1094 | ||
@@ -1103,20 +1099,20 @@ remove_pending_message (struct PendingMessage *pending_msg, int cancel) | |||
1103 | * @param cls #PeerContext of peer with pending online check | 1099 | * @param cls #PeerContext of peer with pending online check |
1104 | */ | 1100 | */ |
1105 | static void | 1101 | static void |
1106 | mq_online_check_successful (void *cls) | 1102 | mq_online_check_successful(void *cls) |
1107 | { | 1103 | { |
1108 | struct PeerContext *peer_ctx = cls; | 1104 | struct PeerContext *peer_ctx = cls; |
1109 | 1105 | ||
1110 | if (NULL != peer_ctx->online_check_pending) | 1106 | if (NULL != peer_ctx->online_check_pending) |
1111 | { | 1107 | { |
1112 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1108 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1113 | "Online check for peer %s was successfull\n", | 1109 | "Online check for peer %s was successfull\n", |
1114 | GNUNET_i2s (&peer_ctx->peer_id)); | 1110 | GNUNET_i2s(&peer_ctx->peer_id)); |
1115 | remove_pending_message (peer_ctx->online_check_pending, GNUNET_YES); | 1111 | remove_pending_message(peer_ctx->online_check_pending, GNUNET_YES); |
1116 | peer_ctx->online_check_pending = NULL; | 1112 | peer_ctx->online_check_pending = NULL; |
1117 | set_peer_online (peer_ctx); | 1113 | set_peer_online(peer_ctx); |
1118 | (void) add_valid_peer (&peer_ctx->peer_id, peer_ctx->sub->valid_peers); | 1114 | (void)add_valid_peer(&peer_ctx->peer_id, peer_ctx->sub->valid_peers); |
1119 | } | 1115 | } |
1120 | } | 1116 | } |
1121 | 1117 | ||
1122 | /** | 1118 | /** |
@@ -1125,30 +1121,30 @@ mq_online_check_successful (void *cls) | |||
1125 | * @param peer_ctx the context of the peer | 1121 | * @param peer_ctx the context of the peer |
1126 | */ | 1122 | */ |
1127 | static void | 1123 | static void |
1128 | check_peer_online (struct PeerContext *peer_ctx) | 1124 | check_peer_online(struct PeerContext *peer_ctx) |
1129 | { | 1125 | { |
1130 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1126 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1131 | "Get informed about peer %s getting online\n", | 1127 | "Get informed about peer %s getting online\n", |
1132 | GNUNET_i2s (&peer_ctx->peer_id)); | 1128 | GNUNET_i2s(&peer_ctx->peer_id)); |
1133 | 1129 | ||
1134 | struct GNUNET_MQ_Handle *mq; | 1130 | struct GNUNET_MQ_Handle *mq; |
1135 | struct GNUNET_MQ_Envelope *ev; | 1131 | struct GNUNET_MQ_Envelope *ev; |
1136 | 1132 | ||
1137 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE); | 1133 | ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE); |
1138 | peer_ctx->online_check_pending = | 1134 | peer_ctx->online_check_pending = |
1139 | insert_pending_message (peer_ctx, ev, "Check online"); | 1135 | insert_pending_message(peer_ctx, ev, "Check online"); |
1140 | mq = get_mq (peer_ctx); | 1136 | mq = get_mq(peer_ctx); |
1141 | GNUNET_MQ_notify_sent (ev, | 1137 | GNUNET_MQ_notify_sent(ev, |
1142 | mq_online_check_successful, | 1138 | mq_online_check_successful, |
1143 | peer_ctx); | 1139 | peer_ctx); |
1144 | GNUNET_MQ_send (mq, ev); | 1140 | GNUNET_MQ_send(mq, ev); |
1145 | if (peer_ctx->sub == msub) | 1141 | if (peer_ctx->sub == msub) |
1146 | { | 1142 | { |
1147 | GNUNET_STATISTICS_update (stats, | 1143 | GNUNET_STATISTICS_update(stats, |
1148 | "# pending online checks", | 1144 | "# pending online checks", |
1149 | 1, | 1145 | 1, |
1150 | GNUNET_NO); | 1146 | GNUNET_NO); |
1151 | } | 1147 | } |
1152 | } | 1148 | } |
1153 | 1149 | ||
1154 | 1150 | ||
@@ -1165,8 +1161,8 @@ check_peer_online (struct PeerContext *peer_ctx) | |||
1165 | * #GNUNET_NO otherwise | 1161 | * #GNUNET_NO otherwise |
1166 | */ | 1162 | */ |
1167 | static int | 1163 | static int |
1168 | check_operation_scheduled (const struct PeerContext *peer_ctx, | 1164 | check_operation_scheduled(const struct PeerContext *peer_ctx, |
1169 | const PeerOp peer_op) | 1165 | const PeerOp peer_op) |
1170 | { | 1166 | { |
1171 | unsigned int i; | 1167 | unsigned int i; |
1172 | 1168 | ||
@@ -1183,20 +1179,20 @@ check_operation_scheduled (const struct PeerContext *peer_ctx, | |||
1183 | * @param cls Context of the channel | 1179 | * @param cls Context of the channel |
1184 | */ | 1180 | */ |
1185 | static void | 1181 | static void |
1186 | destroy_channel (struct ChannelCtx *channel_ctx) | 1182 | destroy_channel(struct ChannelCtx *channel_ctx) |
1187 | { | 1183 | { |
1188 | struct GNUNET_CADET_Channel *channel; | 1184 | struct GNUNET_CADET_Channel *channel; |
1189 | 1185 | ||
1190 | if (NULL != channel_ctx->destruction_task) | 1186 | if (NULL != channel_ctx->destruction_task) |
1191 | { | 1187 | { |
1192 | GNUNET_SCHEDULER_cancel (channel_ctx->destruction_task); | 1188 | GNUNET_SCHEDULER_cancel(channel_ctx->destruction_task); |
1193 | channel_ctx->destruction_task = NULL; | 1189 | channel_ctx->destruction_task = NULL; |
1194 | } | 1190 | } |
1195 | GNUNET_assert (channel_ctx->channel != NULL); | 1191 | GNUNET_assert(channel_ctx->channel != NULL); |
1196 | channel = channel_ctx->channel; | 1192 | channel = channel_ctx->channel; |
1197 | channel_ctx->channel = NULL; | 1193 | channel_ctx->channel = NULL; |
1198 | GNUNET_CADET_channel_destroy (channel); | 1194 | GNUNET_CADET_channel_destroy(channel); |
1199 | remove_channel_ctx (channel_ctx); | 1195 | remove_channel_ctx(channel_ctx); |
1200 | } | 1196 | } |
1201 | 1197 | ||
1202 | 1198 | ||
@@ -1208,12 +1204,12 @@ destroy_channel (struct ChannelCtx *channel_ctx) | |||
1208 | * @param cls | 1204 | * @param cls |
1209 | */ | 1205 | */ |
1210 | static void | 1206 | static void |
1211 | destroy_channel_cb (void *cls) | 1207 | destroy_channel_cb(void *cls) |
1212 | { | 1208 | { |
1213 | struct ChannelCtx *channel_ctx = cls; | 1209 | struct ChannelCtx *channel_ctx = cls; |
1214 | 1210 | ||
1215 | channel_ctx->destruction_task = NULL; | 1211 | channel_ctx->destruction_task = NULL; |
1216 | destroy_channel (channel_ctx); | 1212 | destroy_channel(channel_ctx); |
1217 | } | 1213 | } |
1218 | 1214 | ||
1219 | 1215 | ||
@@ -1228,15 +1224,15 @@ destroy_channel_cb (void *cls) | |||
1228 | * @param channel_ctx channel to be destroyed. | 1224 | * @param channel_ctx channel to be destroyed. |
1229 | */ | 1225 | */ |
1230 | static void | 1226 | static void |
1231 | schedule_channel_destruction (struct ChannelCtx *channel_ctx) | 1227 | schedule_channel_destruction(struct ChannelCtx *channel_ctx) |
1232 | { | 1228 | { |
1233 | GNUNET_assert (NULL == | 1229 | GNUNET_assert(NULL == |
1234 | channel_ctx->destruction_task); | 1230 | channel_ctx->destruction_task); |
1235 | GNUNET_assert (NULL != | 1231 | GNUNET_assert(NULL != |
1236 | channel_ctx->channel); | 1232 | channel_ctx->channel); |
1237 | channel_ctx->destruction_task = | 1233 | channel_ctx->destruction_task = |
1238 | GNUNET_SCHEDULER_add_now (&destroy_channel_cb, | 1234 | GNUNET_SCHEDULER_add_now(&destroy_channel_cb, |
1239 | channel_ctx); | 1235 | channel_ctx); |
1240 | } | 1236 | } |
1241 | 1237 | ||
1242 | 1238 | ||
@@ -1254,98 +1250,98 @@ schedule_channel_destruction (struct ChannelCtx *channel_ctx) | |||
1254 | * #GNUNET_NO otherwise | 1250 | * #GNUNET_NO otherwise |
1255 | */ | 1251 | */ |
1256 | static int | 1252 | static int |
1257 | destroy_peer (struct PeerContext *peer_ctx) | 1253 | destroy_peer(struct PeerContext *peer_ctx) |
1258 | { | 1254 | { |
1259 | GNUNET_assert (NULL != peer_ctx); | 1255 | GNUNET_assert(NULL != peer_ctx); |
1260 | GNUNET_assert (NULL != peer_ctx->sub->peer_map); | 1256 | GNUNET_assert(NULL != peer_ctx->sub->peer_map); |
1261 | if (GNUNET_NO == | 1257 | if (GNUNET_NO == |
1262 | GNUNET_CONTAINER_multipeermap_contains (peer_ctx->sub->peer_map, | 1258 | GNUNET_CONTAINER_multipeermap_contains(peer_ctx->sub->peer_map, |
1263 | &peer_ctx->peer_id)) | 1259 | &peer_ctx->peer_id)) |
1264 | { | 1260 | { |
1265 | return GNUNET_NO; | 1261 | return GNUNET_NO; |
1266 | } | 1262 | } |
1267 | SET_PEER_FLAG (peer_ctx, Peers_TO_DESTROY); | 1263 | SET_PEER_FLAG(peer_ctx, Peers_TO_DESTROY); |
1268 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1264 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1269 | "Going to remove peer %s\n", | 1265 | "Going to remove peer %s\n", |
1270 | GNUNET_i2s (&peer_ctx->peer_id)); | 1266 | GNUNET_i2s(&peer_ctx->peer_id)); |
1271 | UNSET_PEER_FLAG (peer_ctx, Peers_ONLINE); | 1267 | UNSET_PEER_FLAG(peer_ctx, Peers_ONLINE); |
1272 | 1268 | ||
1273 | /* Clear list of pending operations */ | 1269 | /* Clear list of pending operations */ |
1274 | // TODO this probably leaks memory | 1270 | // TODO this probably leaks memory |
1275 | // ('only' the cls to the function. Not sure what to do with it) | 1271 | // ('only' the cls to the function. Not sure what to do with it) |
1276 | GNUNET_array_grow (peer_ctx->pending_ops, | 1272 | GNUNET_array_grow(peer_ctx->pending_ops, |
1277 | peer_ctx->num_pending_ops, | 1273 | peer_ctx->num_pending_ops, |
1278 | 0); | 1274 | 0); |
1279 | /* Remove all pending messages */ | 1275 | /* Remove all pending messages */ |
1280 | while (NULL != peer_ctx->pending_messages_head) | 1276 | while (NULL != peer_ctx->pending_messages_head) |
1281 | { | 1277 | { |
1282 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1278 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1283 | "Removing unsent %s\n", | 1279 | "Removing unsent %s\n", |
1284 | peer_ctx->pending_messages_head->type); | 1280 | peer_ctx->pending_messages_head->type); |
1285 | /* Cancle pending message, too */ | 1281 | /* Cancle pending message, too */ |
1286 | if ( (NULL != peer_ctx->online_check_pending) && | 1282 | if ((NULL != peer_ctx->online_check_pending) && |
1287 | (0 == memcmp (peer_ctx->pending_messages_head, | 1283 | (0 == memcmp(peer_ctx->pending_messages_head, |
1288 | peer_ctx->online_check_pending, | 1284 | peer_ctx->online_check_pending, |
1289 | sizeof (struct PendingMessage))) ) | 1285 | sizeof(struct PendingMessage)))) |
1290 | { | ||
1291 | peer_ctx->online_check_pending = NULL; | ||
1292 | if (peer_ctx->sub == msub) | ||
1293 | { | 1286 | { |
1294 | GNUNET_STATISTICS_update (stats, | 1287 | peer_ctx->online_check_pending = NULL; |
1295 | "# pending online checks", | 1288 | if (peer_ctx->sub == msub) |
1296 | -1, | 1289 | { |
1297 | GNUNET_NO); | 1290 | GNUNET_STATISTICS_update(stats, |
1291 | "# pending online checks", | ||
1292 | -1, | ||
1293 | GNUNET_NO); | ||
1294 | } | ||
1298 | } | 1295 | } |
1299 | } | 1296 | remove_pending_message(peer_ctx->pending_messages_head, |
1300 | remove_pending_message (peer_ctx->pending_messages_head, | 1297 | GNUNET_YES); |
1301 | GNUNET_YES); | 1298 | } |
1302 | } | ||
1303 | 1299 | ||
1304 | /* If we are still waiting for notification whether this peer is online | 1300 | /* If we are still waiting for notification whether this peer is online |
1305 | * cancel the according task */ | 1301 | * cancel the according task */ |
1306 | if (NULL != peer_ctx->online_check_pending) | 1302 | if (NULL != peer_ctx->online_check_pending) |
1307 | { | 1303 | { |
1308 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1304 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1309 | "Removing pending online check for peer %s\n", | 1305 | "Removing pending online check for peer %s\n", |
1310 | GNUNET_i2s (&peer_ctx->peer_id)); | 1306 | GNUNET_i2s(&peer_ctx->peer_id)); |
1311 | // TODO wait until cadet sets mq->cancel_impl | 1307 | // TODO wait until cadet sets mq->cancel_impl |
1312 | //GNUNET_MQ_send_cancel (peer_ctx->online_check_pending->ev); | 1308 | //GNUNET_MQ_send_cancel (peer_ctx->online_check_pending->ev); |
1313 | remove_pending_message (peer_ctx->online_check_pending, | 1309 | remove_pending_message(peer_ctx->online_check_pending, |
1314 | GNUNET_YES); | 1310 | GNUNET_YES); |
1315 | peer_ctx->online_check_pending = NULL; | 1311 | peer_ctx->online_check_pending = NULL; |
1316 | } | 1312 | } |
1317 | 1313 | ||
1318 | if (NULL != peer_ctx->send_channel_ctx) | 1314 | if (NULL != peer_ctx->send_channel_ctx) |
1319 | { | 1315 | { |
1320 | /* This is possibly called from within channel destruction */ | 1316 | /* This is possibly called from within channel destruction */ |
1321 | peer_ctx->send_channel_ctx->peer_ctx = NULL; | 1317 | peer_ctx->send_channel_ctx->peer_ctx = NULL; |
1322 | schedule_channel_destruction (peer_ctx->send_channel_ctx); | 1318 | schedule_channel_destruction(peer_ctx->send_channel_ctx); |
1323 | peer_ctx->send_channel_ctx = NULL; | 1319 | peer_ctx->send_channel_ctx = NULL; |
1324 | peer_ctx->mq = NULL; | 1320 | peer_ctx->mq = NULL; |
1325 | } | 1321 | } |
1326 | if (NULL != peer_ctx->recv_channel_ctx) | 1322 | if (NULL != peer_ctx->recv_channel_ctx) |
1327 | { | 1323 | { |
1328 | /* This is possibly called from within channel destruction */ | 1324 | /* This is possibly called from within channel destruction */ |
1329 | peer_ctx->recv_channel_ctx->peer_ctx = NULL; | 1325 | peer_ctx->recv_channel_ctx->peer_ctx = NULL; |
1330 | schedule_channel_destruction (peer_ctx->recv_channel_ctx); | 1326 | schedule_channel_destruction(peer_ctx->recv_channel_ctx); |
1331 | peer_ctx->recv_channel_ctx = NULL; | 1327 | peer_ctx->recv_channel_ctx = NULL; |
1332 | } | 1328 | } |
1333 | 1329 | ||
1334 | if (GNUNET_YES != | 1330 | if (GNUNET_YES != |
1335 | GNUNET_CONTAINER_multipeermap_remove_all (peer_ctx->sub->peer_map, | 1331 | GNUNET_CONTAINER_multipeermap_remove_all(peer_ctx->sub->peer_map, |
1336 | &peer_ctx->peer_id)) | 1332 | &peer_ctx->peer_id)) |
1337 | { | 1333 | { |
1338 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1334 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1339 | "removing peer from peer_ctx->sub->peer_map failed\n"); | 1335 | "removing peer from peer_ctx->sub->peer_map failed\n"); |
1340 | } | 1336 | } |
1341 | if (peer_ctx->sub == msub) | 1337 | if (peer_ctx->sub == msub) |
1342 | { | 1338 | { |
1343 | GNUNET_STATISTICS_set (stats, | 1339 | GNUNET_STATISTICS_set(stats, |
1344 | "# known peers", | 1340 | "# known peers", |
1345 | GNUNET_CONTAINER_multipeermap_size (peer_ctx->sub->peer_map), | 1341 | GNUNET_CONTAINER_multipeermap_size(peer_ctx->sub->peer_map), |
1346 | GNUNET_NO); | 1342 | GNUNET_NO); |
1347 | } | 1343 | } |
1348 | GNUNET_free (peer_ctx); | 1344 | GNUNET_free(peer_ctx); |
1349 | return GNUNET_YES; | 1345 | return GNUNET_YES; |
1350 | } | 1346 | } |
1351 | 1347 | ||
@@ -1360,14 +1356,15 @@ destroy_peer (struct PeerContext *peer_ctx) | |||
1360 | * #GNUNET_NO if not. | 1356 | * #GNUNET_NO if not. |
1361 | */ | 1357 | */ |
1362 | static int | 1358 | static int |
1363 | peermap_clear_iterator (void *cls, | 1359 | peermap_clear_iterator(void *cls, |
1364 | const struct GNUNET_PeerIdentity *key, | 1360 | const struct GNUNET_PeerIdentity *key, |
1365 | void *value) | 1361 | void *value) |
1366 | { | 1362 | { |
1367 | struct Sub *sub = cls; | 1363 | struct Sub *sub = cls; |
1368 | (void) value; | ||
1369 | 1364 | ||
1370 | destroy_peer (get_peer_ctx (sub->peer_map, key)); | 1365 | (void)value; |
1366 | |||
1367 | destroy_peer(get_peer_ctx(sub->peer_map, key)); | ||
1371 | return GNUNET_YES; | 1368 | return GNUNET_YES; |
1372 | } | 1369 | } |
1373 | 1370 | ||
@@ -1380,31 +1377,32 @@ peermap_clear_iterator (void *cls, | |||
1380 | * @param cls type of the message that was sent | 1377 | * @param cls type of the message that was sent |
1381 | */ | 1378 | */ |
1382 | static void | 1379 | static void |
1383 | mq_notify_sent_cb (void *cls) | 1380 | mq_notify_sent_cb(void *cls) |
1384 | { | 1381 | { |
1385 | struct PendingMessage *pending_msg = (struct PendingMessage *) cls; | 1382 | struct PendingMessage *pending_msg = (struct PendingMessage *)cls; |
1386 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1383 | |
1384 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1387 | "%s was sent.\n", | 1385 | "%s was sent.\n", |
1388 | pending_msg->type); | 1386 | pending_msg->type); |
1389 | if (pending_msg->peer_ctx->sub == msub) | 1387 | if (pending_msg->peer_ctx->sub == msub) |
1390 | { | 1388 | { |
1391 | if (0 == strncmp ("PULL REPLY", pending_msg->type, 10)) | 1389 | if (0 == strncmp("PULL REPLY", pending_msg->type, 10)) |
1392 | GNUNET_STATISTICS_update(stats, "# pull replys sent", 1, GNUNET_NO); | 1390 | GNUNET_STATISTICS_update(stats, "# pull replys sent", 1, GNUNET_NO); |
1393 | if (0 == strncmp ("PULL REQUEST", pending_msg->type, 12)) | 1391 | if (0 == strncmp("PULL REQUEST", pending_msg->type, 12)) |
1394 | GNUNET_STATISTICS_update(stats, "# pull requests sent", 1, GNUNET_NO); | 1392 | GNUNET_STATISTICS_update(stats, "# pull requests sent", 1, GNUNET_NO); |
1395 | if (0 == strncmp ("PUSH", pending_msg->type, 4)) | 1393 | if (0 == strncmp("PUSH", pending_msg->type, 4)) |
1396 | GNUNET_STATISTICS_update(stats, "# pushes sent", 1, GNUNET_NO); | 1394 | GNUNET_STATISTICS_update(stats, "# pushes sent", 1, GNUNET_NO); |
1397 | if (0 == strncmp ("PULL REQUEST", pending_msg->type, 12) && | 1395 | if (0 == strncmp("PULL REQUEST", pending_msg->type, 12) && |
1398 | NULL != map_single_hop && | 1396 | NULL != map_single_hop && |
1399 | GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, | 1397 | GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(map_single_hop, |
1400 | &pending_msg->peer_ctx->peer_id)) | 1398 | &pending_msg->peer_ctx->peer_id)) |
1401 | GNUNET_STATISTICS_update(stats, | 1399 | GNUNET_STATISTICS_update(stats, |
1402 | "# pull requests sent (multi-hop peer)", | 1400 | "# pull requests sent (multi-hop peer)", |
1403 | 1, | 1401 | 1, |
1404 | GNUNET_NO); | 1402 | GNUNET_NO); |
1405 | } | 1403 | } |
1406 | /* Do not cancle message */ | 1404 | /* Do not cancle message */ |
1407 | remove_pending_message (pending_msg, GNUNET_NO); | 1405 | remove_pending_message(pending_msg, GNUNET_NO); |
1408 | } | 1406 | } |
1409 | 1407 | ||
1410 | 1408 | ||
@@ -1423,29 +1421,30 @@ mq_notify_sent_cb (void *cls) | |||
1423 | * #GNUNET_NO if not. | 1421 | * #GNUNET_NO if not. |
1424 | */ | 1422 | */ |
1425 | static int | 1423 | static int |
1426 | store_peer_presistently_iterator (void *cls, | 1424 | store_peer_presistently_iterator(void *cls, |
1427 | const struct GNUNET_PeerIdentity *peer, | 1425 | const struct GNUNET_PeerIdentity *peer, |
1428 | void *value) | 1426 | void *value) |
1429 | { | 1427 | { |
1430 | const struct GNUNET_DISK_FileHandle *fh = cls; | 1428 | const struct GNUNET_DISK_FileHandle *fh = cls; |
1431 | char peer_string[128]; | 1429 | char peer_string[128]; |
1432 | int size; | 1430 | int size; |
1433 | ssize_t ret; | 1431 | ssize_t ret; |
1434 | (void) value; | 1432 | |
1433 | (void)value; | ||
1435 | 1434 | ||
1436 | if (NULL == peer) | 1435 | if (NULL == peer) |
1437 | { | 1436 | { |
1438 | return GNUNET_YES; | 1437 | return GNUNET_YES; |
1439 | } | 1438 | } |
1440 | size = GNUNET_snprintf (peer_string, | 1439 | size = GNUNET_snprintf(peer_string, |
1441 | sizeof (peer_string), | 1440 | sizeof(peer_string), |
1442 | "%s\n", | 1441 | "%s\n", |
1443 | GNUNET_i2s_full (peer)); | 1442 | GNUNET_i2s_full(peer)); |
1444 | GNUNET_assert (53 == size); | 1443 | GNUNET_assert(53 == size); |
1445 | ret = GNUNET_DISK_file_write (fh, | 1444 | ret = GNUNET_DISK_file_write(fh, |
1446 | peer_string, | 1445 | peer_string, |
1447 | size); | 1446 | size); |
1448 | GNUNET_assert (size == ret); | 1447 | GNUNET_assert(size == ret); |
1449 | return GNUNET_YES; | 1448 | return GNUNET_YES; |
1450 | } | 1449 | } |
1451 | 1450 | ||
@@ -1456,54 +1455,54 @@ store_peer_presistently_iterator (void *cls, | |||
1456 | * @param sub Sub for which to store the valid peers | 1455 | * @param sub Sub for which to store the valid peers |
1457 | */ | 1456 | */ |
1458 | static void | 1457 | static void |
1459 | store_valid_peers (const struct Sub *sub) | 1458 | store_valid_peers(const struct Sub *sub) |
1460 | { | 1459 | { |
1461 | struct GNUNET_DISK_FileHandle *fh; | 1460 | struct GNUNET_DISK_FileHandle *fh; |
1462 | uint32_t number_written_peers; | 1461 | uint32_t number_written_peers; |
1463 | int ret; | 1462 | int ret; |
1464 | 1463 | ||
1465 | if (0 == strncmp ("DISABLE", sub->filename_valid_peers, 7)) | 1464 | if (0 == strncmp("DISABLE", sub->filename_valid_peers, 7)) |
1466 | { | 1465 | { |
1467 | return; | 1466 | return; |
1468 | } | 1467 | } |
1469 | 1468 | ||
1470 | ret = GNUNET_DISK_directory_create_for_file (sub->filename_valid_peers); | 1469 | ret = GNUNET_DISK_directory_create_for_file(sub->filename_valid_peers); |
1471 | if (GNUNET_SYSERR == ret) | 1470 | if (GNUNET_SYSERR == ret) |
1472 | { | 1471 | { |
1473 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1472 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1474 | "Not able to create directory for file `%s'\n", | 1473 | "Not able to create directory for file `%s'\n", |
1475 | sub->filename_valid_peers); | 1474 | sub->filename_valid_peers); |
1476 | GNUNET_break (0); | 1475 | GNUNET_break(0); |
1477 | } | 1476 | } |
1478 | else if (GNUNET_NO == ret) | 1477 | else if (GNUNET_NO == ret) |
1479 | { | 1478 | { |
1480 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1479 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1481 | "Directory for file `%s' exists but is not writable for us\n", | 1480 | "Directory for file `%s' exists but is not writable for us\n", |
1482 | sub->filename_valid_peers); | 1481 | sub->filename_valid_peers); |
1483 | GNUNET_break (0); | 1482 | GNUNET_break(0); |
1484 | } | 1483 | } |
1485 | fh = GNUNET_DISK_file_open (sub->filename_valid_peers, | 1484 | fh = GNUNET_DISK_file_open(sub->filename_valid_peers, |
1486 | GNUNET_DISK_OPEN_WRITE | | 1485 | GNUNET_DISK_OPEN_WRITE | |
1487 | GNUNET_DISK_OPEN_CREATE, | 1486 | GNUNET_DISK_OPEN_CREATE, |
1488 | GNUNET_DISK_PERM_USER_READ | | 1487 | GNUNET_DISK_PERM_USER_READ | |
1489 | GNUNET_DISK_PERM_USER_WRITE); | 1488 | GNUNET_DISK_PERM_USER_WRITE); |
1490 | if (NULL == fh) | 1489 | if (NULL == fh) |
1491 | { | 1490 | { |
1492 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1491 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1493 | "Not able to write valid peers to file `%s'\n", | 1492 | "Not able to write valid peers to file `%s'\n", |
1494 | sub->filename_valid_peers); | 1493 | sub->filename_valid_peers); |
1495 | return; | 1494 | return; |
1496 | } | 1495 | } |
1497 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1496 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1498 | "Writing %u valid peers to disk\n", | 1497 | "Writing %u valid peers to disk\n", |
1499 | GNUNET_CONTAINER_multipeermap_size (sub->valid_peers)); | 1498 | GNUNET_CONTAINER_multipeermap_size(sub->valid_peers)); |
1500 | number_written_peers = | 1499 | number_written_peers = |
1501 | GNUNET_CONTAINER_multipeermap_iterate (sub->valid_peers, | 1500 | GNUNET_CONTAINER_multipeermap_iterate(sub->valid_peers, |
1502 | store_peer_presistently_iterator, | 1501 | store_peer_presistently_iterator, |
1503 | fh); | 1502 | fh); |
1504 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); | 1503 | GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh)); |
1505 | GNUNET_assert (number_written_peers == | 1504 | GNUNET_assert(number_written_peers == |
1506 | GNUNET_CONTAINER_multipeermap_size (sub->valid_peers)); | 1505 | GNUNET_CONTAINER_multipeermap_size(sub->valid_peers)); |
1507 | } | 1506 | } |
1508 | 1507 | ||
1509 | 1508 | ||
@@ -1517,38 +1516,38 @@ store_valid_peers (const struct Sub *sub) | |||
1517 | * @return The peer id | 1516 | * @return The peer id |
1518 | */ | 1517 | */ |
1519 | static const struct GNUNET_PeerIdentity * | 1518 | static const struct GNUNET_PeerIdentity * |
1520 | s2i_full (const char *string_repr) | 1519 | s2i_full(const char *string_repr) |
1521 | { | 1520 | { |
1522 | struct GNUNET_PeerIdentity *peer; | 1521 | struct GNUNET_PeerIdentity *peer; |
1523 | size_t len; | 1522 | size_t len; |
1524 | int ret; | 1523 | int ret; |
1525 | 1524 | ||
1526 | peer = GNUNET_new (struct GNUNET_PeerIdentity); | 1525 | peer = GNUNET_new(struct GNUNET_PeerIdentity); |
1527 | len = strlen (string_repr); | 1526 | len = strlen(string_repr); |
1528 | if (52 > len) | 1527 | if (52 > len) |
1529 | { | 1528 | { |
1530 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1529 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1531 | "Not able to convert string representation of PeerID to PeerID\n" | 1530 | "Not able to convert string representation of PeerID to PeerID\n" |
1532 | "Sting representation: %s (len %lu) - too short\n", | 1531 | "Sting representation: %s (len %lu) - too short\n", |
1533 | string_repr, | 1532 | string_repr, |
1534 | len); | 1533 | len); |
1535 | GNUNET_break (0); | 1534 | GNUNET_break(0); |
1536 | } | 1535 | } |
1537 | else if (52 < len) | 1536 | else if (52 < len) |
1538 | { | 1537 | { |
1539 | len = 52; | 1538 | len = 52; |
1540 | } | 1539 | } |
1541 | ret = GNUNET_CRYPTO_eddsa_public_key_from_string (string_repr, | 1540 | ret = GNUNET_CRYPTO_eddsa_public_key_from_string(string_repr, |
1542 | len, | 1541 | len, |
1543 | &peer->public_key); | 1542 | &peer->public_key); |
1544 | if (GNUNET_OK != ret) | 1543 | if (GNUNET_OK != ret) |
1545 | { | 1544 | { |
1546 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1545 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1547 | "Not able to convert string representation of PeerID to PeerID\n" | 1546 | "Not able to convert string representation of PeerID to PeerID\n" |
1548 | "Sting representation: %s\n", | 1547 | "Sting representation: %s\n", |
1549 | string_repr); | 1548 | string_repr); |
1550 | GNUNET_break (0); | 1549 | GNUNET_break(0); |
1551 | } | 1550 | } |
1552 | return peer; | 1551 | return peer; |
1553 | } | 1552 | } |
1554 | 1553 | ||
@@ -1559,7 +1558,7 @@ s2i_full (const char *string_repr) | |||
1559 | * @param sub Sub for which to restore the valid peers | 1558 | * @param sub Sub for which to restore the valid peers |
1560 | */ | 1559 | */ |
1561 | static void | 1560 | static void |
1562 | restore_valid_peers (const struct Sub *sub) | 1561 | restore_valid_peers(const struct Sub *sub) |
1563 | { | 1562 | { |
1564 | off_t file_size; | 1563 | off_t file_size; |
1565 | uint32_t num_peers; | 1564 | uint32_t num_peers; |
@@ -1570,53 +1569,53 @@ restore_valid_peers (const struct Sub *sub) | |||
1570 | char *str_repr; | 1569 | char *str_repr; |
1571 | const struct GNUNET_PeerIdentity *peer; | 1570 | const struct GNUNET_PeerIdentity *peer; |
1572 | 1571 | ||
1573 | if (0 == strncmp ("DISABLE", sub->filename_valid_peers, 7)) | 1572 | if (0 == strncmp("DISABLE", sub->filename_valid_peers, 7)) |
1574 | { | 1573 | { |
1575 | return; | 1574 | return; |
1576 | } | 1575 | } |
1577 | 1576 | ||
1578 | if (GNUNET_OK != GNUNET_DISK_file_test (sub->filename_valid_peers)) | 1577 | if (GNUNET_OK != GNUNET_DISK_file_test(sub->filename_valid_peers)) |
1579 | { | 1578 | { |
1580 | return; | 1579 | return; |
1581 | } | 1580 | } |
1582 | fh = GNUNET_DISK_file_open (sub->filename_valid_peers, | 1581 | fh = GNUNET_DISK_file_open(sub->filename_valid_peers, |
1583 | GNUNET_DISK_OPEN_READ, | 1582 | GNUNET_DISK_OPEN_READ, |
1584 | GNUNET_DISK_PERM_NONE); | 1583 | GNUNET_DISK_PERM_NONE); |
1585 | GNUNET_assert (NULL != fh); | 1584 | GNUNET_assert(NULL != fh); |
1586 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_handle_size (fh, &file_size)); | 1585 | GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_handle_size(fh, &file_size)); |
1587 | num_peers = file_size / 53; | 1586 | num_peers = file_size / 53; |
1588 | buf = GNUNET_malloc (file_size); | 1587 | buf = GNUNET_malloc(file_size); |
1589 | size_read = GNUNET_DISK_file_read (fh, buf, file_size); | 1588 | size_read = GNUNET_DISK_file_read(fh, buf, file_size); |
1590 | GNUNET_assert (size_read == file_size); | 1589 | GNUNET_assert(size_read == file_size); |
1591 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1590 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1592 | "Restoring %" PRIu32 " peers from file `%s'\n", | 1591 | "Restoring %" PRIu32 " peers from file `%s'\n", |
1593 | num_peers, | 1592 | num_peers, |
1594 | sub->filename_valid_peers); | 1593 | sub->filename_valid_peers); |
1595 | for (iter_buf = buf; iter_buf < buf + file_size - 1; iter_buf += 53) | 1594 | for (iter_buf = buf; iter_buf < buf + file_size - 1; iter_buf += 53) |
1596 | { | 1595 | { |
1597 | str_repr = GNUNET_strndup (iter_buf, 53); | 1596 | str_repr = GNUNET_strndup(iter_buf, 53); |
1598 | peer = s2i_full (str_repr); | 1597 | peer = s2i_full(str_repr); |
1599 | GNUNET_free (str_repr); | 1598 | GNUNET_free(str_repr); |
1600 | add_valid_peer (peer, sub->valid_peers); | 1599 | add_valid_peer(peer, sub->valid_peers); |
1601 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1600 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1602 | "Restored valid peer %s from disk\n", | 1601 | "Restored valid peer %s from disk\n", |
1603 | GNUNET_i2s_full (peer)); | 1602 | GNUNET_i2s_full(peer)); |
1604 | } | 1603 | } |
1605 | iter_buf = NULL; | 1604 | iter_buf = NULL; |
1606 | GNUNET_free (buf); | 1605 | GNUNET_free(buf); |
1607 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1606 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1608 | "num_peers: %" PRIu32 ", _size (sub->valid_peers): %u\n", | 1607 | "num_peers: %" PRIu32 ", _size (sub->valid_peers): %u\n", |
1609 | num_peers, | 1608 | num_peers, |
1610 | GNUNET_CONTAINER_multipeermap_size (sub->valid_peers)); | 1609 | GNUNET_CONTAINER_multipeermap_size(sub->valid_peers)); |
1611 | if (num_peers != GNUNET_CONTAINER_multipeermap_size (sub->valid_peers)) | 1610 | if (num_peers != GNUNET_CONTAINER_multipeermap_size(sub->valid_peers)) |
1612 | { | 1611 | { |
1613 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1612 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1614 | "Number of restored peers does not match file size. Have probably duplicates.\n"); | 1613 | "Number of restored peers does not match file size. Have probably duplicates.\n"); |
1615 | } | 1614 | } |
1616 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); | 1615 | GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh)); |
1617 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1616 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1618 | "Restored %u valid peers from disk\n", | 1617 | "Restored %u valid peers from disk\n", |
1619 | GNUNET_CONTAINER_multipeermap_size (sub->valid_peers)); | 1618 | GNUNET_CONTAINER_multipeermap_size(sub->valid_peers)); |
1620 | } | 1619 | } |
1621 | 1620 | ||
1622 | 1621 | ||
@@ -1626,22 +1625,22 @@ restore_valid_peers (const struct Sub *sub) | |||
1626 | * @param sub Sub for which the storage is deleted | 1625 | * @param sub Sub for which the storage is deleted |
1627 | */ | 1626 | */ |
1628 | static void | 1627 | static void |
1629 | peers_terminate (struct Sub *sub) | 1628 | peers_terminate(struct Sub *sub) |
1630 | { | 1629 | { |
1631 | if (GNUNET_SYSERR == | 1630 | if (GNUNET_SYSERR == |
1632 | GNUNET_CONTAINER_multipeermap_iterate (sub->peer_map, | 1631 | GNUNET_CONTAINER_multipeermap_iterate(sub->peer_map, |
1633 | &peermap_clear_iterator, | 1632 | &peermap_clear_iterator, |
1634 | sub)) | 1633 | sub)) |
1635 | { | 1634 | { |
1636 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1635 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1637 | "Iteration destroying peers was aborted.\n"); | 1636 | "Iteration destroying peers was aborted.\n"); |
1638 | } | 1637 | } |
1639 | GNUNET_CONTAINER_multipeermap_destroy (sub->peer_map); | 1638 | GNUNET_CONTAINER_multipeermap_destroy(sub->peer_map); |
1640 | sub->peer_map = NULL; | 1639 | sub->peer_map = NULL; |
1641 | store_valid_peers (sub); | 1640 | store_valid_peers(sub); |
1642 | GNUNET_free (sub->filename_valid_peers); | 1641 | GNUNET_free(sub->filename_valid_peers); |
1643 | sub->filename_valid_peers = NULL; | 1642 | sub->filename_valid_peers = NULL; |
1644 | GNUNET_CONTAINER_multipeermap_destroy (sub->valid_peers); | 1643 | GNUNET_CONTAINER_multipeermap_destroy(sub->valid_peers); |
1645 | sub->valid_peers = NULL; | 1644 | sub->valid_peers = NULL; |
1646 | } | 1645 | } |
1647 | 1646 | ||
@@ -1657,14 +1656,15 @@ peers_terminate (struct Sub *sub) | |||
1657 | * #GNUNET_NO if not. | 1656 | * #GNUNET_NO if not. |
1658 | */ | 1657 | */ |
1659 | static int | 1658 | static int |
1660 | valid_peer_iterator (void *cls, | 1659 | valid_peer_iterator(void *cls, |
1661 | const struct GNUNET_PeerIdentity *peer, | 1660 | const struct GNUNET_PeerIdentity *peer, |
1662 | void *value) | 1661 | void *value) |
1663 | { | 1662 | { |
1664 | struct PeersIteratorCls *it_cls = cls; | 1663 | struct PeersIteratorCls *it_cls = cls; |
1665 | (void) value; | ||
1666 | 1664 | ||
1667 | return it_cls->iterator (it_cls->cls, peer); | 1665 | (void)value; |
1666 | |||
1667 | return it_cls->iterator(it_cls->cls, peer); | ||
1668 | } | 1668 | } |
1669 | 1669 | ||
1670 | 1670 | ||
@@ -1678,20 +1678,20 @@ valid_peer_iterator (void *cls, | |||
1678 | * #GNUNET_SYSERR if it aborted iteration | 1678 | * #GNUNET_SYSERR if it aborted iteration |
1679 | */ | 1679 | */ |
1680 | static int | 1680 | static int |
1681 | get_valid_peers (struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, | 1681 | get_valid_peers(struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, |
1682 | PeersIterator iterator, | 1682 | PeersIterator iterator, |
1683 | void *it_cls) | 1683 | void *it_cls) |
1684 | { | 1684 | { |
1685 | struct PeersIteratorCls *cls; | 1685 | struct PeersIteratorCls *cls; |
1686 | int ret; | 1686 | int ret; |
1687 | 1687 | ||
1688 | cls = GNUNET_new (struct PeersIteratorCls); | 1688 | cls = GNUNET_new(struct PeersIteratorCls); |
1689 | cls->iterator = iterator; | 1689 | cls->iterator = iterator; |
1690 | cls->cls = it_cls; | 1690 | cls->cls = it_cls; |
1691 | ret = GNUNET_CONTAINER_multipeermap_iterate (valid_peers, | 1691 | ret = GNUNET_CONTAINER_multipeermap_iterate(valid_peers, |
1692 | valid_peer_iterator, | 1692 | valid_peer_iterator, |
1693 | cls); | 1693 | cls); |
1694 | GNUNET_free (cls); | 1694 | GNUNET_free(cls); |
1695 | return ret; | 1695 | return ret; |
1696 | } | 1696 | } |
1697 | 1697 | ||
@@ -1709,14 +1709,14 @@ get_valid_peers (struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, | |||
1709 | * #GNUNET_NO otherwise | 1709 | * #GNUNET_NO otherwise |
1710 | */ | 1710 | */ |
1711 | static int | 1711 | static int |
1712 | insert_peer (struct Sub *sub, | 1712 | insert_peer(struct Sub *sub, |
1713 | const struct GNUNET_PeerIdentity *peer) | 1713 | const struct GNUNET_PeerIdentity *peer) |
1714 | { | 1714 | { |
1715 | if (GNUNET_YES == check_peer_known (sub->peer_map, peer)) | 1715 | if (GNUNET_YES == check_peer_known(sub->peer_map, peer)) |
1716 | { | 1716 | { |
1717 | return GNUNET_NO; /* We already know this peer - nothing to do */ | 1717 | return GNUNET_NO; /* We already know this peer - nothing to do */ |
1718 | } | 1718 | } |
1719 | (void) create_peer_ctx (sub, peer); | 1719 | (void)create_peer_ctx(sub, peer); |
1720 | return GNUNET_YES; | 1720 | return GNUNET_YES; |
1721 | } | 1721 | } |
1722 | 1722 | ||
@@ -1733,18 +1733,18 @@ insert_peer (struct Sub *sub, | |||
1733 | * #GNUNET_NO otherwise | 1733 | * #GNUNET_NO otherwise |
1734 | */ | 1734 | */ |
1735 | static int | 1735 | static int |
1736 | check_peer_flag (const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, | 1736 | check_peer_flag(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, |
1737 | const struct GNUNET_PeerIdentity *peer, | 1737 | const struct GNUNET_PeerIdentity *peer, |
1738 | enum Peers_PeerFlags flags) | 1738 | enum Peers_PeerFlags flags) |
1739 | { | 1739 | { |
1740 | struct PeerContext *peer_ctx; | 1740 | struct PeerContext *peer_ctx; |
1741 | 1741 | ||
1742 | if (GNUNET_NO == check_peer_known (peer_map, peer)) | 1742 | if (GNUNET_NO == check_peer_known(peer_map, peer)) |
1743 | { | 1743 | { |
1744 | return GNUNET_SYSERR; | 1744 | return GNUNET_SYSERR; |
1745 | } | 1745 | } |
1746 | peer_ctx = get_peer_ctx (peer_map, peer); | 1746 | peer_ctx = get_peer_ctx(peer_map, peer); |
1747 | return check_peer_flag_set (peer_ctx, flags); | 1747 | return check_peer_flag_set(peer_ctx, flags); |
1748 | } | 1748 | } |
1749 | 1749 | ||
1750 | /** | 1750 | /** |
@@ -1758,19 +1758,19 @@ check_peer_flag (const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, | |||
1758 | * #GNUNET_NO otherwise | 1758 | * #GNUNET_NO otherwise |
1759 | */ | 1759 | */ |
1760 | static int | 1760 | static int |
1761 | issue_peer_online_check (struct Sub *sub, | 1761 | issue_peer_online_check(struct Sub *sub, |
1762 | const struct GNUNET_PeerIdentity *peer) | 1762 | const struct GNUNET_PeerIdentity *peer) |
1763 | { | 1763 | { |
1764 | struct PeerContext *peer_ctx; | 1764 | struct PeerContext *peer_ctx; |
1765 | 1765 | ||
1766 | (void) insert_peer (sub, peer); // TODO even needed? | 1766 | (void)insert_peer(sub, peer); // TODO even needed? |
1767 | peer_ctx = get_peer_ctx (sub->peer_map, peer); | 1767 | peer_ctx = get_peer_ctx(sub->peer_map, peer); |
1768 | if ( (GNUNET_NO == check_peer_flag (sub->peer_map, peer, Peers_ONLINE)) && | 1768 | if ((GNUNET_NO == check_peer_flag(sub->peer_map, peer, Peers_ONLINE)) && |
1769 | (NULL == peer_ctx->online_check_pending) ) | 1769 | (NULL == peer_ctx->online_check_pending)) |
1770 | { | 1770 | { |
1771 | check_peer_online (peer_ctx); | 1771 | check_peer_online(peer_ctx); |
1772 | return GNUNET_YES; | 1772 | return GNUNET_YES; |
1773 | } | 1773 | } |
1774 | return GNUNET_NO; | 1774 | return GNUNET_NO; |
1775 | } | 1775 | } |
1776 | 1776 | ||
@@ -1789,20 +1789,20 @@ issue_peer_online_check (struct Sub *sub, | |||
1789 | * #GNUNET_SYSERR if peer is not known | 1789 | * #GNUNET_SYSERR if peer is not known |
1790 | */ | 1790 | */ |
1791 | static int | 1791 | static int |
1792 | check_removable (const struct PeerContext *peer_ctx) | 1792 | check_removable(const struct PeerContext *peer_ctx) |
1793 | { | 1793 | { |
1794 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (peer_ctx->sub->peer_map, | 1794 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(peer_ctx->sub->peer_map, |
1795 | &peer_ctx->peer_id)) | 1795 | &peer_ctx->peer_id)) |
1796 | { | 1796 | { |
1797 | return GNUNET_SYSERR; | 1797 | return GNUNET_SYSERR; |
1798 | } | 1798 | } |
1799 | 1799 | ||
1800 | if ( (NULL != peer_ctx->recv_channel_ctx) || | 1800 | if ((NULL != peer_ctx->recv_channel_ctx) || |
1801 | (NULL != peer_ctx->pending_messages_head) || | 1801 | (NULL != peer_ctx->pending_messages_head) || |
1802 | (GNUNET_YES == check_peer_flag_set (peer_ctx, Peers_PULL_REPLY_PENDING)) ) | 1802 | (GNUNET_YES == check_peer_flag_set(peer_ctx, Peers_PULL_REPLY_PENDING))) |
1803 | { | 1803 | { |
1804 | return GNUNET_NO; | 1804 | return GNUNET_NO; |
1805 | } | 1805 | } |
1806 | return GNUNET_YES; | 1806 | return GNUNET_YES; |
1807 | } | 1807 | } |
1808 | 1808 | ||
@@ -1819,10 +1819,10 @@ check_removable (const struct PeerContext *peer_ctx) | |||
1819 | * #GNUNET_NO if peer is not valid | 1819 | * #GNUNET_NO if peer is not valid |
1820 | */ | 1820 | */ |
1821 | static int | 1821 | static int |
1822 | check_peer_valid (const struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, | 1822 | check_peer_valid(const struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, |
1823 | const struct GNUNET_PeerIdentity *peer) | 1823 | const struct GNUNET_PeerIdentity *peer) |
1824 | { | 1824 | { |
1825 | return GNUNET_CONTAINER_multipeermap_contains (valid_peers, peer); | 1825 | return GNUNET_CONTAINER_multipeermap_contains(valid_peers, peer); |
1826 | } | 1826 | } |
1827 | 1827 | ||
1828 | 1828 | ||
@@ -1834,11 +1834,11 @@ check_peer_valid (const struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, | |||
1834 | * @param peer_ctx Context of the target peer | 1834 | * @param peer_ctx Context of the target peer |
1835 | */ | 1835 | */ |
1836 | static void | 1836 | static void |
1837 | indicate_sending_intention (struct PeerContext *peer_ctx) | 1837 | indicate_sending_intention(struct PeerContext *peer_ctx) |
1838 | { | 1838 | { |
1839 | GNUNET_assert (GNUNET_YES == check_peer_known (peer_ctx->sub->peer_map, | 1839 | GNUNET_assert(GNUNET_YES == check_peer_known(peer_ctx->sub->peer_map, |
1840 | &peer_ctx->peer_id)); | 1840 | &peer_ctx->peer_id)); |
1841 | (void) get_channel (peer_ctx); | 1841 | (void)get_channel(peer_ctx); |
1842 | } | 1842 | } |
1843 | 1843 | ||
1844 | 1844 | ||
@@ -1852,12 +1852,12 @@ indicate_sending_intention (struct PeerContext *peer_ctx) | |||
1852 | * #GNUNET_NO otherwise | 1852 | * #GNUNET_NO otherwise |
1853 | */ | 1853 | */ |
1854 | static int | 1854 | static int |
1855 | check_peer_send_intention (const struct PeerContext *peer_ctx) | 1855 | check_peer_send_intention(const struct PeerContext *peer_ctx) |
1856 | { | 1856 | { |
1857 | if (NULL != peer_ctx->recv_channel_ctx) | 1857 | if (NULL != peer_ctx->recv_channel_ctx) |
1858 | { | 1858 | { |
1859 | return GNUNET_YES; | 1859 | return GNUNET_YES; |
1860 | } | 1860 | } |
1861 | return GNUNET_NO; | 1861 | return GNUNET_NO; |
1862 | } | 1862 | } |
1863 | 1863 | ||
@@ -1873,36 +1873,36 @@ check_peer_send_intention (const struct PeerContext *peer_ctx) | |||
1873 | * (can be NULL -- that's not an error) | 1873 | * (can be NULL -- that's not an error) |
1874 | */ | 1874 | */ |
1875 | static void * | 1875 | static void * |
1876 | handle_inbound_channel (void *cls, | 1876 | handle_inbound_channel(void *cls, |
1877 | struct GNUNET_CADET_Channel *channel, | 1877 | struct GNUNET_CADET_Channel *channel, |
1878 | const struct GNUNET_PeerIdentity *initiator) | 1878 | const struct GNUNET_PeerIdentity *initiator) |
1879 | { | 1879 | { |
1880 | struct PeerContext *peer_ctx; | 1880 | struct PeerContext *peer_ctx; |
1881 | struct ChannelCtx *channel_ctx; | 1881 | struct ChannelCtx *channel_ctx; |
1882 | struct Sub *sub = cls; | 1882 | struct Sub *sub = cls; |
1883 | 1883 | ||
1884 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1884 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1885 | "New channel was established to us (Peer %s).\n", | 1885 | "New channel was established to us (Peer %s).\n", |
1886 | GNUNET_i2s (initiator)); | 1886 | GNUNET_i2s(initiator)); |
1887 | GNUNET_assert (NULL != channel); /* according to cadet API */ | 1887 | GNUNET_assert(NULL != channel); /* according to cadet API */ |
1888 | /* Make sure we 'know' about this peer */ | 1888 | /* Make sure we 'know' about this peer */ |
1889 | peer_ctx = create_or_get_peer_ctx (sub, initiator); | 1889 | peer_ctx = create_or_get_peer_ctx(sub, initiator); |
1890 | set_peer_online (peer_ctx); | 1890 | set_peer_online(peer_ctx); |
1891 | (void) add_valid_peer (&peer_ctx->peer_id, peer_ctx->sub->valid_peers); | 1891 | (void)add_valid_peer(&peer_ctx->peer_id, peer_ctx->sub->valid_peers); |
1892 | channel_ctx = add_channel_ctx (peer_ctx); | 1892 | channel_ctx = add_channel_ctx(peer_ctx); |
1893 | channel_ctx->channel = channel; | 1893 | channel_ctx->channel = channel; |
1894 | /* We only accept one incoming channel per peer */ | 1894 | /* We only accept one incoming channel per peer */ |
1895 | if (GNUNET_YES == check_peer_send_intention (get_peer_ctx (sub->peer_map, | 1895 | if (GNUNET_YES == check_peer_send_intention(get_peer_ctx(sub->peer_map, |
1896 | initiator))) | 1896 | initiator))) |
1897 | { | 1897 | { |
1898 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1898 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1899 | "Already got one receive channel. Destroying old one.\n"); | 1899 | "Already got one receive channel. Destroying old one.\n"); |
1900 | GNUNET_break_op (0); | 1900 | GNUNET_break_op(0); |
1901 | destroy_channel (peer_ctx->recv_channel_ctx); | 1901 | destroy_channel(peer_ctx->recv_channel_ctx); |
1902 | peer_ctx->recv_channel_ctx = channel_ctx; | 1902 | peer_ctx->recv_channel_ctx = channel_ctx; |
1903 | /* return the channel context */ | 1903 | /* return the channel context */ |
1904 | return channel_ctx; | 1904 | return channel_ctx; |
1905 | } | 1905 | } |
1906 | peer_ctx->recv_channel_ctx = channel_ctx; | 1906 | peer_ctx->recv_channel_ctx = channel_ctx; |
1907 | return channel_ctx; | 1907 | return channel_ctx; |
1908 | } | 1908 | } |
@@ -1917,17 +1917,17 @@ handle_inbound_channel (void *cls, | |||
1917 | * #GNUNET_NO otherwise | 1917 | * #GNUNET_NO otherwise |
1918 | */ | 1918 | */ |
1919 | static int | 1919 | static int |
1920 | check_sending_channel_exists (const struct PeerContext *peer_ctx) | 1920 | check_sending_channel_exists(const struct PeerContext *peer_ctx) |
1921 | { | 1921 | { |
1922 | if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map, | 1922 | if (GNUNET_NO == check_peer_known(peer_ctx->sub->peer_map, |
1923 | &peer_ctx->peer_id)) | 1923 | &peer_ctx->peer_id)) |
1924 | { /* If no such peer exists, there is no channel */ | 1924 | { /* If no such peer exists, there is no channel */ |
1925 | return GNUNET_NO; | 1925 | return GNUNET_NO; |
1926 | } | 1926 | } |
1927 | if (NULL == peer_ctx->send_channel_ctx) | 1927 | if (NULL == peer_ctx->send_channel_ctx) |
1928 | { | 1928 | { |
1929 | return GNUNET_NO; | 1929 | return GNUNET_NO; |
1930 | } | 1930 | } |
1931 | return GNUNET_YES; | 1931 | return GNUNET_YES; |
1932 | } | 1932 | } |
1933 | 1933 | ||
@@ -1941,19 +1941,19 @@ check_sending_channel_exists (const struct PeerContext *peer_ctx) | |||
1941 | * #GNUNET_NO otherwise | 1941 | * #GNUNET_NO otherwise |
1942 | */ | 1942 | */ |
1943 | static int | 1943 | static int |
1944 | destroy_sending_channel (struct PeerContext *peer_ctx) | 1944 | destroy_sending_channel(struct PeerContext *peer_ctx) |
1945 | { | 1945 | { |
1946 | if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map, | 1946 | if (GNUNET_NO == check_peer_known(peer_ctx->sub->peer_map, |
1947 | &peer_ctx->peer_id)) | 1947 | &peer_ctx->peer_id)) |
1948 | { | 1948 | { |
1949 | return GNUNET_NO; | 1949 | return GNUNET_NO; |
1950 | } | 1950 | } |
1951 | if (NULL != peer_ctx->send_channel_ctx) | 1951 | if (NULL != peer_ctx->send_channel_ctx) |
1952 | { | 1952 | { |
1953 | destroy_channel (peer_ctx->send_channel_ctx); | 1953 | destroy_channel(peer_ctx->send_channel_ctx); |
1954 | (void) check_connected (peer_ctx); | 1954 | (void)check_connected(peer_ctx); |
1955 | return GNUNET_YES; | 1955 | return GNUNET_YES; |
1956 | } | 1956 | } |
1957 | return GNUNET_NO; | 1957 | return GNUNET_NO; |
1958 | } | 1958 | } |
1959 | 1959 | ||
@@ -1968,23 +1968,23 @@ destroy_sending_channel (struct PeerContext *peer_ctx) | |||
1968 | * @param type type of the message | 1968 | * @param type type of the message |
1969 | */ | 1969 | */ |
1970 | static void | 1970 | static void |
1971 | send_message (struct PeerContext *peer_ctx, | 1971 | send_message(struct PeerContext *peer_ctx, |
1972 | struct GNUNET_MQ_Envelope *ev, | 1972 | struct GNUNET_MQ_Envelope *ev, |
1973 | const char *type) | 1973 | const char *type) |
1974 | { | 1974 | { |
1975 | struct PendingMessage *pending_msg; | 1975 | struct PendingMessage *pending_msg; |
1976 | struct GNUNET_MQ_Handle *mq; | 1976 | struct GNUNET_MQ_Handle *mq; |
1977 | 1977 | ||
1978 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1978 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1979 | "Sending message to %s of type %s\n", | 1979 | "Sending message to %s of type %s\n", |
1980 | GNUNET_i2s (&peer_ctx->peer_id), | 1980 | GNUNET_i2s(&peer_ctx->peer_id), |
1981 | type); | 1981 | type); |
1982 | pending_msg = insert_pending_message (peer_ctx, ev, type); | 1982 | pending_msg = insert_pending_message(peer_ctx, ev, type); |
1983 | mq = get_mq (peer_ctx); | 1983 | mq = get_mq(peer_ctx); |
1984 | GNUNET_MQ_notify_sent (ev, | 1984 | GNUNET_MQ_notify_sent(ev, |
1985 | mq_notify_sent_cb, | 1985 | mq_notify_sent_cb, |
1986 | pending_msg); | 1986 | pending_msg); |
1987 | GNUNET_MQ_send (mq, ev); | 1987 | GNUNET_MQ_send(mq, ev); |
1988 | } | 1988 | } |
1989 | 1989 | ||
1990 | /** | 1990 | /** |
@@ -2000,44 +2000,43 @@ send_message (struct PeerContext *peer_ctx, | |||
2000 | * #GNUNET_NO otherwise | 2000 | * #GNUNET_NO otherwise |
2001 | */ | 2001 | */ |
2002 | static int | 2002 | static int |
2003 | schedule_operation (struct PeerContext *peer_ctx, | 2003 | schedule_operation(struct PeerContext *peer_ctx, |
2004 | const PeerOp peer_op, | 2004 | const PeerOp peer_op, |
2005 | void *cls) | 2005 | void *cls) |
2006 | { | 2006 | { |
2007 | struct PeerPendingOp pending_op; | 2007 | struct PeerPendingOp pending_op; |
2008 | 2008 | ||
2009 | GNUNET_assert (GNUNET_YES == check_peer_known (peer_ctx->sub->peer_map, | 2009 | GNUNET_assert(GNUNET_YES == check_peer_known(peer_ctx->sub->peer_map, |
2010 | &peer_ctx->peer_id)); | 2010 | &peer_ctx->peer_id)); |
2011 | 2011 | ||
2012 | //TODO if ONLINE execute immediately | 2012 | //TODO if ONLINE execute immediately |
2013 | 2013 | ||
2014 | if (GNUNET_NO == check_operation_scheduled (peer_ctx, peer_op)) | 2014 | if (GNUNET_NO == check_operation_scheduled(peer_ctx, peer_op)) |
2015 | { | 2015 | { |
2016 | pending_op.op = peer_op; | 2016 | pending_op.op = peer_op; |
2017 | pending_op.op_cls = cls; | 2017 | pending_op.op_cls = cls; |
2018 | GNUNET_array_append (peer_ctx->pending_ops, | 2018 | GNUNET_array_append(peer_ctx->pending_ops, |
2019 | peer_ctx->num_pending_ops, | 2019 | peer_ctx->num_pending_ops, |
2020 | pending_op); | 2020 | pending_op); |
2021 | return GNUNET_YES; | 2021 | return GNUNET_YES; |
2022 | } | 2022 | } |
2023 | return GNUNET_NO; | 2023 | return GNUNET_NO; |
2024 | } | 2024 | } |
2025 | 2025 | ||
2026 | /*********************************************************************** | 2026 | /*********************************************************************** |
2027 | * /Old gnunet-service-rps_peers.c | 2027 | * /Old gnunet-service-rps_peers.c |
2028 | ***********************************************************************/ | 2028 | ***********************************************************************/ |
2029 | 2029 | ||
2030 | 2030 | ||
2031 | /*********************************************************************** | 2031 | /*********************************************************************** |
2032 | * Housekeeping with clients | 2032 | * Housekeeping with clients |
2033 | ***********************************************************************/ | 2033 | ***********************************************************************/ |
2034 | 2034 | ||
2035 | /** | 2035 | /** |
2036 | * Closure used to pass the client and the id to the callback | 2036 | * Closure used to pass the client and the id to the callback |
2037 | * that replies to a client's request | 2037 | * that replies to a client's request |
2038 | */ | 2038 | */ |
2039 | struct ReplyCls | 2039 | struct ReplyCls { |
2040 | { | ||
2041 | /** | 2040 | /** |
2042 | * DLL | 2041 | * DLL |
2043 | */ | 2042 | */ |
@@ -2064,8 +2063,7 @@ struct ReplyCls | |||
2064 | /** | 2063 | /** |
2065 | * Struct used to store the context of a connected client. | 2064 | * Struct used to store the context of a connected client. |
2066 | */ | 2065 | */ |
2067 | struct ClientContext | 2066 | struct ClientContext { |
2068 | { | ||
2069 | /** | 2067 | /** |
2070 | * DLL | 2068 | * DLL |
2071 | */ | 2069 | */ |
@@ -2106,7 +2104,7 @@ struct ClientContext *cli_ctx_head; | |||
2106 | struct ClientContext *cli_ctx_tail; | 2104 | struct ClientContext *cli_ctx_tail; |
2107 | 2105 | ||
2108 | /*********************************************************************** | 2106 | /*********************************************************************** |
2109 | * /Housekeeping with clients | 2107 | * /Housekeeping with clients |
2110 | ***********************************************************************/ | 2108 | ***********************************************************************/ |
2111 | 2109 | ||
2112 | 2110 | ||
@@ -2114,7 +2112,7 @@ struct ClientContext *cli_ctx_tail; | |||
2114 | 2112 | ||
2115 | 2113 | ||
2116 | /*********************************************************************** | 2114 | /*********************************************************************** |
2117 | * Util functions | 2115 | * Util functions |
2118 | ***********************************************************************/ | 2116 | ***********************************************************************/ |
2119 | 2117 | ||
2120 | 2118 | ||
@@ -2122,21 +2120,21 @@ struct ClientContext *cli_ctx_tail; | |||
2122 | * Print peerlist to log. | 2120 | * Print peerlist to log. |
2123 | */ | 2121 | */ |
2124 | static void | 2122 | static void |
2125 | print_peer_list (struct GNUNET_PeerIdentity *list, | 2123 | print_peer_list(struct GNUNET_PeerIdentity *list, |
2126 | unsigned int len) | 2124 | unsigned int len) |
2127 | { | 2125 | { |
2128 | unsigned int i; | 2126 | unsigned int i; |
2129 | 2127 | ||
2130 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2128 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2131 | "Printing peer list of length %u at %p:\n", | 2129 | "Printing peer list of length %u at %p:\n", |
2132 | len, | 2130 | len, |
2133 | list); | 2131 | list); |
2134 | for (i = 0 ; i < len ; i++) | 2132 | for (i = 0; i < len; i++) |
2135 | { | 2133 | { |
2136 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2134 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2137 | "%u. peer: %s\n", | 2135 | "%u. peer: %s\n", |
2138 | i, GNUNET_i2s (&list[i])); | 2136 | i, GNUNET_i2s(&list[i])); |
2139 | } | 2137 | } |
2140 | } | 2138 | } |
2141 | 2139 | ||
2142 | 2140 | ||
@@ -2144,33 +2142,33 @@ print_peer_list (struct GNUNET_PeerIdentity *list, | |||
2144 | * Remove peer from list. | 2142 | * Remove peer from list. |
2145 | */ | 2143 | */ |
2146 | static void | 2144 | static void |
2147 | rem_from_list (struct GNUNET_PeerIdentity **peer_list, | 2145 | rem_from_list(struct GNUNET_PeerIdentity **peer_list, |
2148 | unsigned int *list_size, | 2146 | unsigned int *list_size, |
2149 | const struct GNUNET_PeerIdentity *peer) | 2147 | const struct GNUNET_PeerIdentity *peer) |
2150 | { | 2148 | { |
2151 | unsigned int i; | 2149 | unsigned int i; |
2152 | struct GNUNET_PeerIdentity *tmp; | 2150 | struct GNUNET_PeerIdentity *tmp; |
2153 | 2151 | ||
2154 | tmp = *peer_list; | 2152 | tmp = *peer_list; |
2155 | 2153 | ||
2156 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2154 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2157 | "Removing peer %s from list at %p\n", | 2155 | "Removing peer %s from list at %p\n", |
2158 | GNUNET_i2s (peer), | 2156 | GNUNET_i2s(peer), |
2159 | tmp); | 2157 | tmp); |
2160 | 2158 | ||
2161 | for ( i = 0 ; i < *list_size ; i++ ) | 2159 | for (i = 0; i < *list_size; i++) |
2162 | { | ||
2163 | if (0 == GNUNET_memcmp (&tmp[i], peer)) | ||
2164 | { | 2160 | { |
2165 | if (i < *list_size -1) | 2161 | if (0 == GNUNET_memcmp(&tmp[i], peer)) |
2166 | { /* Not at the last entry -- shift peers left */ | 2162 | { |
2167 | memmove (&tmp[i], &tmp[i +1], | 2163 | if (i < *list_size - 1) |
2168 | ((*list_size) - i -1) * sizeof (struct GNUNET_PeerIdentity)); | 2164 | { /* Not at the last entry -- shift peers left */ |
2169 | } | 2165 | memmove(&tmp[i], &tmp[i + 1], |
2170 | /* Remove last entry (should be now useless PeerID) */ | 2166 | ((*list_size) - i - 1) * sizeof(struct GNUNET_PeerIdentity)); |
2171 | GNUNET_array_grow (tmp, *list_size, (*list_size) -1); | 2167 | } |
2172 | } | 2168 | /* Remove last entry (should be now useless PeerID) */ |
2173 | } | 2169 | GNUNET_array_grow(tmp, *list_size, (*list_size) - 1); |
2170 | } | ||
2171 | } | ||
2174 | *peer_list = tmp; | 2172 | *peer_list = tmp; |
2175 | } | 2173 | } |
2176 | 2174 | ||
@@ -2185,8 +2183,8 @@ rem_from_list (struct GNUNET_PeerIdentity **peer_list, | |||
2185 | * GNUNET_NO if peer was not inserted | 2183 | * GNUNET_NO if peer was not inserted |
2186 | */ | 2184 | */ |
2187 | static void | 2185 | static void |
2188 | insert_in_view_op (void *cls, | 2186 | insert_in_view_op(void *cls, |
2189 | const struct GNUNET_PeerIdentity *peer); | 2187 | const struct GNUNET_PeerIdentity *peer); |
2190 | 2188 | ||
2191 | /** | 2189 | /** |
2192 | * Insert PeerID in #view | 2190 | * Insert PeerID in #view |
@@ -2200,32 +2198,32 @@ insert_in_view_op (void *cls, | |||
2200 | * GNUNET_NO if peer was not inserted | 2198 | * GNUNET_NO if peer was not inserted |
2201 | */ | 2199 | */ |
2202 | static int | 2200 | static int |
2203 | insert_in_view (struct Sub *sub, | 2201 | insert_in_view(struct Sub *sub, |
2204 | const struct GNUNET_PeerIdentity *peer) | 2202 | const struct GNUNET_PeerIdentity *peer) |
2205 | { | 2203 | { |
2206 | struct PeerContext *peer_ctx; | 2204 | struct PeerContext *peer_ctx; |
2207 | int online; | 2205 | int online; |
2208 | int ret; | 2206 | int ret; |
2209 | 2207 | ||
2210 | online = check_peer_flag (sub->peer_map, peer, Peers_ONLINE); | 2208 | online = check_peer_flag(sub->peer_map, peer, Peers_ONLINE); |
2211 | peer_ctx = get_peer_ctx (sub->peer_map, peer); // TODO indirection needed? | 2209 | peer_ctx = get_peer_ctx(sub->peer_map, peer); // TODO indirection needed? |
2212 | if ( (GNUNET_NO == online) || | 2210 | if ((GNUNET_NO == online) || |
2213 | (GNUNET_SYSERR == online) ) /* peer is not even known */ | 2211 | (GNUNET_SYSERR == online)) /* peer is not even known */ |
2214 | { | 2212 | { |
2215 | (void) issue_peer_online_check (sub, peer); | 2213 | (void)issue_peer_online_check(sub, peer); |
2216 | (void) schedule_operation (peer_ctx, insert_in_view_op, sub); | 2214 | (void)schedule_operation(peer_ctx, insert_in_view_op, sub); |
2217 | return GNUNET_NO; | 2215 | return GNUNET_NO; |
2218 | } | 2216 | } |
2219 | /* Open channel towards peer to keep connection open */ | 2217 | /* Open channel towards peer to keep connection open */ |
2220 | indicate_sending_intention (peer_ctx); | 2218 | indicate_sending_intention(peer_ctx); |
2221 | ret = View_put (sub->view, peer); | 2219 | ret = View_put(sub->view, peer); |
2222 | if (peer_ctx->sub == msub) | 2220 | if (peer_ctx->sub == msub) |
2223 | { | 2221 | { |
2224 | GNUNET_STATISTICS_set (stats, | 2222 | GNUNET_STATISTICS_set(stats, |
2225 | "view size", | 2223 | "view size", |
2226 | View_size (peer_ctx->sub->view), | 2224 | View_size(peer_ctx->sub->view), |
2227 | GNUNET_NO); | 2225 | GNUNET_NO); |
2228 | } | 2226 | } |
2229 | return ret; | 2227 | return ret; |
2230 | } | 2228 | } |
2231 | 2229 | ||
@@ -2238,31 +2236,33 @@ insert_in_view (struct Sub *sub, | |||
2238 | * @param view_size the size of the view array (can be 0) | 2236 | * @param view_size the size of the view array (can be 0) |
2239 | */ | 2237 | */ |
2240 | static void | 2238 | static void |
2241 | send_view (const struct ClientContext *cli_ctx, | 2239 | send_view(const struct ClientContext *cli_ctx, |
2242 | const struct GNUNET_PeerIdentity *view_array, | 2240 | const struct GNUNET_PeerIdentity *view_array, |
2243 | uint64_t view_size) | 2241 | uint64_t view_size) |
2244 | { | 2242 | { |
2245 | struct GNUNET_MQ_Envelope *ev; | 2243 | struct GNUNET_MQ_Envelope *ev; |
2246 | struct GNUNET_RPS_CS_DEBUG_ViewReply *out_msg; | 2244 | struct GNUNET_RPS_CS_DEBUG_ViewReply *out_msg; |
2247 | struct Sub *sub; | 2245 | struct Sub *sub; |
2248 | 2246 | ||
2249 | if (NULL == view_array) | 2247 | if (NULL == view_array) |
2250 | { | 2248 | { |
2251 | if (NULL == cli_ctx->sub) sub = msub; | 2249 | if (NULL == cli_ctx->sub) |
2252 | else sub = cli_ctx->sub; | 2250 | sub = msub; |
2253 | view_size = View_size (sub->view); | 2251 | else |
2254 | view_array = View_get_as_array (sub->view); | 2252 | sub = cli_ctx->sub; |
2255 | } | 2253 | view_size = View_size(sub->view); |
2256 | 2254 | view_array = View_get_as_array(sub->view); | |
2257 | ev = GNUNET_MQ_msg_extra (out_msg, | 2255 | } |
2258 | view_size * sizeof (struct GNUNET_PeerIdentity), | 2256 | |
2259 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY); | 2257 | ev = GNUNET_MQ_msg_extra(out_msg, |
2260 | out_msg->num_peers = htonl (view_size); | 2258 | view_size * sizeof(struct GNUNET_PeerIdentity), |
2261 | 2259 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY); | |
2262 | GNUNET_memcpy (&out_msg[1], | 2260 | out_msg->num_peers = htonl(view_size); |
2263 | view_array, | 2261 | |
2264 | view_size * sizeof (struct GNUNET_PeerIdentity)); | 2262 | GNUNET_memcpy(&out_msg[1], |
2265 | GNUNET_MQ_send (cli_ctx->mq, ev); | 2263 | view_array, |
2264 | view_size * sizeof(struct GNUNET_PeerIdentity)); | ||
2265 | GNUNET_MQ_send(cli_ctx->mq, ev); | ||
2266 | } | 2266 | } |
2267 | 2267 | ||
2268 | 2268 | ||
@@ -2276,24 +2276,24 @@ send_view (const struct ClientContext *cli_ctx, | |||
2276 | * @param view_size the size of the view array (can be 0) | 2276 | * @param view_size the size of the view array (can be 0) |
2277 | */ | 2277 | */ |
2278 | static void | 2278 | static void |
2279 | send_stream_peers (const struct ClientContext *cli_ctx, | 2279 | send_stream_peers(const struct ClientContext *cli_ctx, |
2280 | uint64_t num_peers, | 2280 | uint64_t num_peers, |
2281 | const struct GNUNET_PeerIdentity *peers) | 2281 | const struct GNUNET_PeerIdentity *peers) |
2282 | { | 2282 | { |
2283 | struct GNUNET_MQ_Envelope *ev; | 2283 | struct GNUNET_MQ_Envelope *ev; |
2284 | struct GNUNET_RPS_CS_DEBUG_StreamReply *out_msg; | 2284 | struct GNUNET_RPS_CS_DEBUG_StreamReply *out_msg; |
2285 | 2285 | ||
2286 | GNUNET_assert (NULL != peers); | 2286 | GNUNET_assert(NULL != peers); |
2287 | 2287 | ||
2288 | ev = GNUNET_MQ_msg_extra (out_msg, | 2288 | ev = GNUNET_MQ_msg_extra(out_msg, |
2289 | num_peers * sizeof (struct GNUNET_PeerIdentity), | 2289 | num_peers * sizeof(struct GNUNET_PeerIdentity), |
2290 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY); | 2290 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY); |
2291 | out_msg->num_peers = htonl (num_peers); | 2291 | out_msg->num_peers = htonl(num_peers); |
2292 | 2292 | ||
2293 | GNUNET_memcpy (&out_msg[1], | 2293 | GNUNET_memcpy(&out_msg[1], |
2294 | peers, | 2294 | peers, |
2295 | num_peers * sizeof (struct GNUNET_PeerIdentity)); | 2295 | num_peers * sizeof(struct GNUNET_PeerIdentity)); |
2296 | GNUNET_MQ_send (cli_ctx->mq, ev); | 2296 | GNUNET_MQ_send(cli_ctx->mq, ev); |
2297 | } | 2297 | } |
2298 | 2298 | ||
2299 | 2299 | ||
@@ -2303,43 +2303,46 @@ send_stream_peers (const struct ClientContext *cli_ctx, | |||
2303 | * @param sub Sub for which to notify clients | 2303 | * @param sub Sub for which to notify clients |
2304 | */ | 2304 | */ |
2305 | static void | 2305 | static void |
2306 | clients_notify_view_update (const struct Sub *sub) | 2306 | clients_notify_view_update(const struct Sub *sub) |
2307 | { | 2307 | { |
2308 | struct ClientContext *cli_ctx_iter; | 2308 | struct ClientContext *cli_ctx_iter; |
2309 | uint64_t num_peers; | 2309 | uint64_t num_peers; |
2310 | const struct GNUNET_PeerIdentity *view_array; | 2310 | const struct GNUNET_PeerIdentity *view_array; |
2311 | 2311 | ||
2312 | num_peers = View_size (sub->view); | 2312 | num_peers = View_size(sub->view); |
2313 | view_array = View_get_as_array(sub->view); | 2313 | view_array = View_get_as_array(sub->view); |
2314 | /* check size of view is small enough */ | 2314 | /* check size of view is small enough */ |
2315 | if (GNUNET_MAX_MESSAGE_SIZE < num_peers) | 2315 | if (GNUNET_MAX_MESSAGE_SIZE < num_peers) |
2316 | { | 2316 | { |
2317 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2317 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2318 | "View is too big to send\n"); | 2318 | "View is too big to send\n"); |
2319 | return; | 2319 | return; |
2320 | } | 2320 | } |
2321 | 2321 | ||
2322 | for (cli_ctx_iter = cli_ctx_head; | 2322 | for (cli_ctx_iter = cli_ctx_head; |
2323 | NULL != cli_ctx_iter; | 2323 | NULL != cli_ctx_iter; |
2324 | cli_ctx_iter = cli_ctx_iter->next) | 2324 | cli_ctx_iter = cli_ctx_iter->next) |
2325 | { | ||
2326 | if (1 < cli_ctx_iter->view_updates_left) | ||
2327 | { | 2325 | { |
2328 | /* Client wants to receive limited amount of updates */ | 2326 | if (1 < cli_ctx_iter->view_updates_left) |
2329 | cli_ctx_iter->view_updates_left -= 1; | 2327 | { |
2330 | } else if (1 == cli_ctx_iter->view_updates_left) | 2328 | /* Client wants to receive limited amount of updates */ |
2331 | { | 2329 | cli_ctx_iter->view_updates_left -= 1; |
2332 | /* Last update of view for client */ | 2330 | } |
2333 | cli_ctx_iter->view_updates_left = -1; | 2331 | else if (1 == cli_ctx_iter->view_updates_left) |
2334 | } else if (0 > cli_ctx_iter->view_updates_left) { | 2332 | { |
2335 | /* Client is not interested in updates */ | 2333 | /* Last update of view for client */ |
2336 | continue; | 2334 | cli_ctx_iter->view_updates_left = -1; |
2337 | } | 2335 | } |
2338 | /* else _updates_left == 0 - infinite amount of updates */ | 2336 | else if (0 > cli_ctx_iter->view_updates_left) |
2337 | { | ||
2338 | /* Client is not interested in updates */ | ||
2339 | continue; | ||
2340 | } | ||
2341 | /* else _updates_left == 0 - infinite amount of updates */ | ||
2339 | 2342 | ||
2340 | /* send view */ | 2343 | /* send view */ |
2341 | send_view (cli_ctx_iter, view_array, num_peers); | 2344 | send_view(cli_ctx_iter, view_array, num_peers); |
2342 | } | 2345 | } |
2343 | } | 2346 | } |
2344 | 2347 | ||
2345 | 2348 | ||
@@ -2350,27 +2353,27 @@ clients_notify_view_update (const struct Sub *sub) | |||
2350 | * @param peers the array of peers to send | 2353 | * @param peers the array of peers to send |
2351 | */ | 2354 | */ |
2352 | static void | 2355 | static void |
2353 | clients_notify_stream_peer (const struct Sub *sub, | 2356 | clients_notify_stream_peer(const struct Sub *sub, |
2354 | uint64_t num_peers, | 2357 | uint64_t num_peers, |
2355 | const struct GNUNET_PeerIdentity *peers) | 2358 | const struct GNUNET_PeerIdentity *peers) |
2356 | // TODO enum StreamPeerSource) | 2359 | // TODO enum StreamPeerSource) |
2357 | { | 2360 | { |
2358 | struct ClientContext *cli_ctx_iter; | 2361 | struct ClientContext *cli_ctx_iter; |
2359 | 2362 | ||
2360 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2363 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2361 | "Got peer (%s) from biased stream - update all clients\n", | 2364 | "Got peer (%s) from biased stream - update all clients\n", |
2362 | GNUNET_i2s (peers)); | 2365 | GNUNET_i2s(peers)); |
2363 | 2366 | ||
2364 | for (cli_ctx_iter = cli_ctx_head; | 2367 | for (cli_ctx_iter = cli_ctx_head; |
2365 | NULL != cli_ctx_iter; | 2368 | NULL != cli_ctx_iter; |
2366 | cli_ctx_iter = cli_ctx_iter->next) | 2369 | cli_ctx_iter = cli_ctx_iter->next) |
2367 | { | ||
2368 | if (GNUNET_YES == cli_ctx_iter->stream_update && | ||
2369 | (sub == cli_ctx_iter->sub || sub == msub)) | ||
2370 | { | 2370 | { |
2371 | send_stream_peers (cli_ctx_iter, num_peers, peers); | 2371 | if (GNUNET_YES == cli_ctx_iter->stream_update && |
2372 | (sub == cli_ctx_iter->sub || sub == msub)) | ||
2373 | { | ||
2374 | send_stream_peers(cli_ctx_iter, num_peers, peers); | ||
2375 | } | ||
2372 | } | 2376 | } |
2373 | } | ||
2374 | } | 2377 | } |
2375 | 2378 | ||
2376 | 2379 | ||
@@ -2382,34 +2385,34 @@ clients_notify_stream_peer (const struct Sub *sub, | |||
2382 | * @param cls Closure - The Sub for which this is to be done | 2385 | * @param cls Closure - The Sub for which this is to be done |
2383 | */ | 2386 | */ |
2384 | static void | 2387 | static void |
2385 | hist_update (const struct GNUNET_PeerIdentity *ids, | 2388 | hist_update(const struct GNUNET_PeerIdentity *ids, |
2386 | uint32_t num_peers, | 2389 | uint32_t num_peers, |
2387 | void *cls) | 2390 | void *cls) |
2388 | { | 2391 | { |
2389 | unsigned int i; | 2392 | unsigned int i; |
2390 | struct Sub *sub = cls; | 2393 | struct Sub *sub = cls; |
2391 | 2394 | ||
2392 | for (i = 0; i < num_peers; i++) | 2395 | for (i = 0; i < num_peers; i++) |
2393 | { | ||
2394 | int inserted; | ||
2395 | if (GNUNET_YES != check_peer_known (sub->peer_map, &ids[i])) | ||
2396 | { | 2396 | { |
2397 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2397 | int inserted; |
2398 | "Peer in history update not known!\n"); | 2398 | if (GNUNET_YES != check_peer_known(sub->peer_map, &ids[i])) |
2399 | continue; | 2399 | { |
2400 | } | 2400 | LOG(GNUNET_ERROR_TYPE_WARNING, |
2401 | inserted = insert_in_view (sub, &ids[i]); | 2401 | "Peer in history update not known!\n"); |
2402 | if (GNUNET_OK == inserted) | 2402 | continue; |
2403 | { | 2403 | } |
2404 | clients_notify_stream_peer (sub, 1, &ids[i]); | 2404 | inserted = insert_in_view(sub, &ids[i]); |
2405 | } | 2405 | if (GNUNET_OK == inserted) |
2406 | { | ||
2407 | clients_notify_stream_peer(sub, 1, &ids[i]); | ||
2408 | } | ||
2406 | #ifdef TO_FILE_FULL | 2409 | #ifdef TO_FILE_FULL |
2407 | to_file (sub->file_name_view_log, | 2410 | to_file(sub->file_name_view_log, |
2408 | "+%s\t(hist)", | 2411 | "+%s\t(hist)", |
2409 | GNUNET_i2s_full (ids)); | 2412 | GNUNET_i2s_full(ids)); |
2410 | #endif /* TO_FILE_FULL */ | 2413 | #endif /* TO_FILE_FULL */ |
2411 | } | 2414 | } |
2412 | clients_notify_view_update (sub); | 2415 | clients_notify_view_update(sub); |
2413 | } | 2416 | } |
2414 | 2417 | ||
2415 | 2418 | ||
@@ -2423,22 +2426,22 @@ hist_update (const struct GNUNET_PeerIdentity *ids, | |||
2423 | * @param new_size New size to which to resize | 2426 | * @param new_size New size to which to resize |
2424 | */ | 2427 | */ |
2425 | static void | 2428 | static void |
2426 | resize_wrapper (struct RPS_Sampler *sampler, uint32_t new_size) | 2429 | resize_wrapper(struct RPS_Sampler *sampler, uint32_t new_size) |
2427 | { | 2430 | { |
2428 | unsigned int sampler_size; | 2431 | unsigned int sampler_size; |
2429 | 2432 | ||
2430 | // TODO statistics | 2433 | // TODO statistics |
2431 | // TODO respect the min, max | 2434 | // TODO respect the min, max |
2432 | sampler_size = RPS_sampler_get_size (sampler); | 2435 | sampler_size = RPS_sampler_get_size(sampler); |
2433 | if (sampler_size > new_size * 4) | 2436 | if (sampler_size > new_size * 4) |
2434 | { /* Shrinking */ | 2437 | { /* Shrinking */ |
2435 | RPS_sampler_resize (sampler, sampler_size / 2); | 2438 | RPS_sampler_resize(sampler, sampler_size / 2); |
2436 | } | 2439 | } |
2437 | else if (sampler_size < new_size) | 2440 | else if (sampler_size < new_size) |
2438 | { /* Growing */ | 2441 | { /* Growing */ |
2439 | RPS_sampler_resize (sampler, sampler_size * 2); | 2442 | RPS_sampler_resize(sampler, sampler_size * 2); |
2440 | } | 2443 | } |
2441 | LOG (GNUNET_ERROR_TYPE_DEBUG, "sampler_size is now %u\n", sampler_size); | 2444 | LOG(GNUNET_ERROR_TYPE_DEBUG, "sampler_size is now %u\n", sampler_size); |
2442 | } | 2445 | } |
2443 | 2446 | ||
2444 | 2447 | ||
@@ -2450,32 +2453,33 @@ resize_wrapper (struct RPS_Sampler *sampler, uint32_t new_size) | |||
2450 | * @param peer_map the peermap to use as set | 2453 | * @param peer_map the peermap to use as set |
2451 | */ | 2454 | */ |
2452 | static void | 2455 | static void |
2453 | add_peer_array_to_set (const struct GNUNET_PeerIdentity *peer_array, | 2456 | add_peer_array_to_set(const struct GNUNET_PeerIdentity *peer_array, |
2454 | unsigned int num_peers, | 2457 | unsigned int num_peers, |
2455 | struct GNUNET_CONTAINER_MultiPeerMap *peer_map) | 2458 | struct GNUNET_CONTAINER_MultiPeerMap *peer_map) |
2456 | { | 2459 | { |
2457 | unsigned int i; | 2460 | unsigned int i; |
2461 | |||
2458 | if (NULL == peer_map) | 2462 | if (NULL == peer_map) |
2459 | { | 2463 | { |
2460 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2464 | LOG(GNUNET_ERROR_TYPE_WARNING, |
2461 | "Trying to add peers to non-existing peermap.\n"); | 2465 | "Trying to add peers to non-existing peermap.\n"); |
2462 | return; | 2466 | return; |
2463 | } | 2467 | } |
2464 | 2468 | ||
2465 | for (i = 0; i < num_peers; i++) | 2469 | for (i = 0; i < num_peers; i++) |
2466 | { | ||
2467 | GNUNET_CONTAINER_multipeermap_put (peer_map, | ||
2468 | &peer_array[i], | ||
2469 | NULL, | ||
2470 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
2471 | if (msub->peer_map == peer_map) | ||
2472 | { | 2470 | { |
2473 | GNUNET_STATISTICS_set (stats, | 2471 | GNUNET_CONTAINER_multipeermap_put(peer_map, |
2474 | "# known peers", | 2472 | &peer_array[i], |
2475 | GNUNET_CONTAINER_multipeermap_size (peer_map), | 2473 | NULL, |
2476 | GNUNET_NO); | 2474 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
2475 | if (msub->peer_map == peer_map) | ||
2476 | { | ||
2477 | GNUNET_STATISTICS_set(stats, | ||
2478 | "# known peers", | ||
2479 | GNUNET_CONTAINER_multipeermap_size(peer_map), | ||
2480 | GNUNET_NO); | ||
2481 | } | ||
2477 | } | 2482 | } |
2478 | } | ||
2479 | } | 2483 | } |
2480 | 2484 | ||
2481 | 2485 | ||
@@ -2487,17 +2491,17 @@ add_peer_array_to_set (const struct GNUNET_PeerIdentity *peer_array, | |||
2487 | * @param num_peer_ids the number of peers to send to @a peer_id | 2491 | * @param num_peer_ids the number of peers to send to @a peer_id |
2488 | */ | 2492 | */ |
2489 | static void | 2493 | static void |
2490 | send_pull_reply (struct PeerContext *peer_ctx, | 2494 | send_pull_reply(struct PeerContext *peer_ctx, |
2491 | const struct GNUNET_PeerIdentity *peer_ids, | 2495 | const struct GNUNET_PeerIdentity *peer_ids, |
2492 | unsigned int num_peer_ids) | 2496 | unsigned int num_peer_ids) |
2493 | { | 2497 | { |
2494 | uint32_t send_size; | 2498 | uint32_t send_size; |
2495 | struct GNUNET_MQ_Envelope *ev; | 2499 | struct GNUNET_MQ_Envelope *ev; |
2496 | struct GNUNET_RPS_P2P_PullReplyMessage *out_msg; | 2500 | struct GNUNET_RPS_P2P_PullReplyMessage *out_msg; |
2497 | 2501 | ||
2498 | /* Compute actual size */ | 2502 | /* Compute actual size */ |
2499 | send_size = sizeof (struct GNUNET_RPS_P2P_PullReplyMessage) + | 2503 | send_size = sizeof(struct GNUNET_RPS_P2P_PullReplyMessage) + |
2500 | num_peer_ids * sizeof (struct GNUNET_PeerIdentity); | 2504 | num_peer_ids * sizeof(struct GNUNET_PeerIdentity); |
2501 | 2505 | ||
2502 | if (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE < send_size) | 2506 | if (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE < send_size) |
2503 | /* Compute number of peers to send | 2507 | /* Compute number of peers to send |
@@ -2506,27 +2510,27 @@ send_pull_reply (struct PeerContext *peer_ctx, | |||
2506 | // or even better: do good protocol design | 2510 | // or even better: do good protocol design |
2507 | send_size = | 2511 | send_size = |
2508 | (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - | 2512 | (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - |
2509 | sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) / | 2513 | sizeof(struct GNUNET_RPS_P2P_PullReplyMessage)) / |
2510 | sizeof (struct GNUNET_PeerIdentity); | 2514 | sizeof(struct GNUNET_PeerIdentity); |
2511 | else | 2515 | else |
2512 | send_size = num_peer_ids; | 2516 | send_size = num_peer_ids; |
2513 | 2517 | ||
2514 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2518 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2515 | "Going to send PULL REPLY with %u peers to %s\n", | 2519 | "Going to send PULL REPLY with %u peers to %s\n", |
2516 | send_size, GNUNET_i2s (&peer_ctx->peer_id)); | 2520 | send_size, GNUNET_i2s(&peer_ctx->peer_id)); |
2517 | 2521 | ||
2518 | ev = GNUNET_MQ_msg_extra (out_msg, | 2522 | ev = GNUNET_MQ_msg_extra(out_msg, |
2519 | send_size * sizeof (struct GNUNET_PeerIdentity), | 2523 | send_size * sizeof(struct GNUNET_PeerIdentity), |
2520 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY); | 2524 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY); |
2521 | out_msg->num_peers = htonl (send_size); | 2525 | out_msg->num_peers = htonl(send_size); |
2522 | GNUNET_memcpy (&out_msg[1], peer_ids, | 2526 | GNUNET_memcpy(&out_msg[1], peer_ids, |
2523 | send_size * sizeof (struct GNUNET_PeerIdentity)); | 2527 | send_size * sizeof(struct GNUNET_PeerIdentity)); |
2524 | 2528 | ||
2525 | send_message (peer_ctx, ev, "PULL REPLY"); | 2529 | send_message(peer_ctx, ev, "PULL REPLY"); |
2526 | if (peer_ctx->sub == msub) | 2530 | if (peer_ctx->sub == msub) |
2527 | { | 2531 | { |
2528 | GNUNET_STATISTICS_update(stats, "# pull reply send issued", 1, GNUNET_NO); | 2532 | GNUNET_STATISTICS_update(stats, "# pull reply send issued", 1, GNUNET_NO); |
2529 | } | 2533 | } |
2530 | // TODO check with send intention: as send_channel is used/opened we indicate | 2534 | // TODO check with send intention: as send_channel is used/opened we indicate |
2531 | // a sending intention without intending it. | 2535 | // a sending intention without intending it. |
2532 | // -> clean peer afterwards? | 2536 | // -> clean peer afterwards? |
@@ -2543,12 +2547,12 @@ send_pull_reply (struct PeerContext *peer_ctx, | |||
2543 | * @param peer Peer to insert | 2547 | * @param peer Peer to insert |
2544 | */ | 2548 | */ |
2545 | static void | 2549 | static void |
2546 | insert_in_pull_map (void *cls, | 2550 | insert_in_pull_map(void *cls, |
2547 | const struct GNUNET_PeerIdentity *peer) | 2551 | const struct GNUNET_PeerIdentity *peer) |
2548 | { | 2552 | { |
2549 | struct Sub *sub = cls; | 2553 | struct Sub *sub = cls; |
2550 | 2554 | ||
2551 | CustomPeerMap_put (sub->pull_map, peer); | 2555 | CustomPeerMap_put(sub->pull_map, peer); |
2552 | } | 2556 | } |
2553 | 2557 | ||
2554 | 2558 | ||
@@ -2562,17 +2566,17 @@ insert_in_pull_map (void *cls, | |||
2562 | * @param peer the peer to insert | 2566 | * @param peer the peer to insert |
2563 | */ | 2567 | */ |
2564 | static void | 2568 | static void |
2565 | insert_in_view_op (void *cls, | 2569 | insert_in_view_op(void *cls, |
2566 | const struct GNUNET_PeerIdentity *peer) | 2570 | const struct GNUNET_PeerIdentity *peer) |
2567 | { | 2571 | { |
2568 | struct Sub *sub = cls; | 2572 | struct Sub *sub = cls; |
2569 | int inserted; | 2573 | int inserted; |
2570 | 2574 | ||
2571 | inserted = insert_in_view (sub, peer); | 2575 | inserted = insert_in_view(sub, peer); |
2572 | if (GNUNET_OK == inserted) | 2576 | if (GNUNET_OK == inserted) |
2573 | { | 2577 | { |
2574 | clients_notify_stream_peer (sub, 1, peer); | 2578 | clients_notify_stream_peer(sub, 1, peer); |
2575 | } | 2579 | } |
2576 | } | 2580 | } |
2577 | 2581 | ||
2578 | 2582 | ||
@@ -2584,49 +2588,49 @@ insert_in_view_op (void *cls, | |||
2584 | * @param peer Peer to insert | 2588 | * @param peer Peer to insert |
2585 | */ | 2589 | */ |
2586 | static void | 2590 | static void |
2587 | insert_in_sampler (void *cls, | 2591 | insert_in_sampler(void *cls, |
2588 | const struct GNUNET_PeerIdentity *peer) | 2592 | const struct GNUNET_PeerIdentity *peer) |
2589 | { | 2593 | { |
2590 | struct Sub *sub = cls; | 2594 | struct Sub *sub = cls; |
2591 | 2595 | ||
2592 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2596 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2593 | "Updating samplers with peer %s from insert_in_sampler()\n", | 2597 | "Updating samplers with peer %s from insert_in_sampler()\n", |
2594 | GNUNET_i2s (peer)); | 2598 | GNUNET_i2s(peer)); |
2595 | RPS_sampler_update (sub->sampler, peer); | 2599 | RPS_sampler_update(sub->sampler, peer); |
2596 | if (0 < RPS_sampler_count_id (sub->sampler, peer)) | 2600 | if (0 < RPS_sampler_count_id(sub->sampler, peer)) |
2597 | { | 2601 | { |
2598 | /* Make sure we 'know' about this peer */ | 2602 | /* Make sure we 'know' about this peer */ |
2599 | (void) issue_peer_online_check (sub, peer); | 2603 | (void)issue_peer_online_check(sub, peer); |
2600 | /* Establish a channel towards that peer to indicate we are going to send | 2604 | /* Establish a channel towards that peer to indicate we are going to send |
2601 | * messages to it */ | 2605 | * messages to it */ |
2602 | //indicate_sending_intention (peer); | 2606 | //indicate_sending_intention (peer); |
2603 | } | 2607 | } |
2604 | if (sub == msub) | 2608 | if (sub == msub) |
2605 | { | 2609 | { |
2606 | GNUNET_STATISTICS_update (stats, | 2610 | GNUNET_STATISTICS_update(stats, |
2607 | "# observed peers in gossip", | 2611 | "# observed peers in gossip", |
2608 | 1, | 2612 | 1, |
2609 | GNUNET_NO); | 2613 | GNUNET_NO); |
2610 | } | 2614 | } |
2611 | #ifdef TO_FILE | 2615 | #ifdef TO_FILE |
2612 | sub->num_observed_peers++; | 2616 | sub->num_observed_peers++; |
2613 | GNUNET_CONTAINER_multipeermap_put | 2617 | GNUNET_CONTAINER_multipeermap_put |
2614 | (sub->observed_unique_peers, | 2618 | (sub->observed_unique_peers, |
2615 | peer, | 2619 | peer, |
2616 | NULL, | 2620 | NULL, |
2617 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 2621 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
2618 | uint32_t num_observed_unique_peers = | 2622 | uint32_t num_observed_unique_peers = |
2619 | GNUNET_CONTAINER_multipeermap_size (sub->observed_unique_peers); | 2623 | GNUNET_CONTAINER_multipeermap_size(sub->observed_unique_peers); |
2620 | GNUNET_STATISTICS_set (stats, | 2624 | GNUNET_STATISTICS_set(stats, |
2621 | "# unique peers in gossip", | 2625 | "# unique peers in gossip", |
2622 | num_observed_unique_peers, | 2626 | num_observed_unique_peers, |
2623 | GNUNET_NO); | 2627 | GNUNET_NO); |
2624 | #ifdef TO_FILE_FULL | 2628 | #ifdef TO_FILE_FULL |
2625 | to_file (sub->file_name_observed_log, | 2629 | to_file(sub->file_name_observed_log, |
2626 | "%" PRIu32 " %" PRIu32 " %f\n", | 2630 | "%" PRIu32 " %" PRIu32 " %f\n", |
2627 | sub->num_observed_peers, | 2631 | sub->num_observed_peers, |
2628 | num_observed_unique_peers, | 2632 | num_observed_unique_peers, |
2629 | 1.0*num_observed_unique_peers/sub->num_observed_peers) | 2633 | 1.0 * num_observed_unique_peers / sub->num_observed_peers) |
2630 | #endif /* TO_FILE_FULL */ | 2634 | #endif /* TO_FILE_FULL */ |
2631 | #endif /* TO_FILE */ | 2635 | #endif /* TO_FILE */ |
2632 | } | 2636 | } |
@@ -2643,24 +2647,24 @@ insert_in_sampler (void *cls, | |||
2643 | * @param peer peer to insert/peer received | 2647 | * @param peer peer to insert/peer received |
2644 | */ | 2648 | */ |
2645 | static void | 2649 | static void |
2646 | got_peer (struct Sub *sub, | 2650 | got_peer(struct Sub *sub, |
2647 | const struct GNUNET_PeerIdentity *peer) | 2651 | const struct GNUNET_PeerIdentity *peer) |
2648 | { | 2652 | { |
2649 | /* If we did not know this peer already, insert it into sampler and view */ | 2653 | /* If we did not know this peer already, insert it into sampler and view */ |
2650 | if (GNUNET_YES == issue_peer_online_check (sub, peer)) | 2654 | if (GNUNET_YES == issue_peer_online_check(sub, peer)) |
2651 | { | 2655 | { |
2652 | schedule_operation (get_peer_ctx (sub->peer_map, peer), | 2656 | schedule_operation(get_peer_ctx(sub->peer_map, peer), |
2653 | &insert_in_sampler, sub); | 2657 | &insert_in_sampler, sub); |
2654 | schedule_operation (get_peer_ctx (sub->peer_map, peer), | 2658 | schedule_operation(get_peer_ctx(sub->peer_map, peer), |
2655 | &insert_in_view_op, sub); | 2659 | &insert_in_view_op, sub); |
2656 | } | 2660 | } |
2657 | if (sub == msub) | 2661 | if (sub == msub) |
2658 | { | 2662 | { |
2659 | GNUNET_STATISTICS_update (stats, | 2663 | GNUNET_STATISTICS_update(stats, |
2660 | "# learnd peers", | 2664 | "# learnd peers", |
2661 | 1, | 2665 | 1, |
2662 | GNUNET_NO); | 2666 | GNUNET_NO); |
2663 | } | 2667 | } |
2664 | } | 2668 | } |
2665 | 2669 | ||
2666 | 2670 | ||
@@ -2672,32 +2676,32 @@ got_peer (struct Sub *sub, | |||
2672 | * GNUNET_NO otherwise | 2676 | * GNUNET_NO otherwise |
2673 | */ | 2677 | */ |
2674 | static int | 2678 | static int |
2675 | check_sending_channel_needed (const struct PeerContext *peer_ctx) | 2679 | check_sending_channel_needed(const struct PeerContext *peer_ctx) |
2676 | { | 2680 | { |
2677 | /* struct GNUNET_CADET_Channel *channel; */ | 2681 | /* struct GNUNET_CADET_Channel *channel; */ |
2678 | if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map, | 2682 | if (GNUNET_NO == check_peer_known(peer_ctx->sub->peer_map, |
2679 | &peer_ctx->peer_id)) | 2683 | &peer_ctx->peer_id)) |
2680 | { | 2684 | { |
2681 | return GNUNET_NO; | 2685 | return GNUNET_NO; |
2682 | } | 2686 | } |
2683 | if (GNUNET_YES == check_sending_channel_exists (peer_ctx)) | 2687 | if (GNUNET_YES == check_sending_channel_exists(peer_ctx)) |
2684 | { | 2688 | { |
2685 | if ( (0 < RPS_sampler_count_id (peer_ctx->sub->sampler, | 2689 | if ((0 < RPS_sampler_count_id(peer_ctx->sub->sampler, |
2686 | &peer_ctx->peer_id)) || | 2690 | &peer_ctx->peer_id)) || |
2687 | (GNUNET_YES == View_contains_peer (peer_ctx->sub->view, | 2691 | (GNUNET_YES == View_contains_peer(peer_ctx->sub->view, |
2688 | &peer_ctx->peer_id)) || | 2692 | &peer_ctx->peer_id)) || |
2689 | (GNUNET_YES == CustomPeerMap_contains_peer (peer_ctx->sub->push_map, | 2693 | (GNUNET_YES == CustomPeerMap_contains_peer(peer_ctx->sub->push_map, |
2690 | &peer_ctx->peer_id)) || | 2694 | &peer_ctx->peer_id)) || |
2691 | (GNUNET_YES == CustomPeerMap_contains_peer (peer_ctx->sub->pull_map, | 2695 | (GNUNET_YES == CustomPeerMap_contains_peer(peer_ctx->sub->pull_map, |
2692 | &peer_ctx->peer_id)) || | 2696 | &peer_ctx->peer_id)) || |
2693 | (GNUNET_YES == check_peer_flag (peer_ctx->sub->peer_map, | 2697 | (GNUNET_YES == check_peer_flag(peer_ctx->sub->peer_map, |
2694 | &peer_ctx->peer_id, | 2698 | &peer_ctx->peer_id, |
2695 | Peers_PULL_REPLY_PENDING))) | 2699 | Peers_PULL_REPLY_PENDING))) |
2696 | { /* If we want to keep the connection to peer open */ | 2700 | { /* If we want to keep the connection to peer open */ |
2697 | return GNUNET_YES; | 2701 | return GNUNET_YES; |
2702 | } | ||
2703 | return GNUNET_NO; | ||
2698 | } | 2704 | } |
2699 | return GNUNET_NO; | ||
2700 | } | ||
2701 | return GNUNET_NO; | 2705 | return GNUNET_NO; |
2702 | } | 2706 | } |
2703 | 2707 | ||
@@ -2710,26 +2714,26 @@ check_sending_channel_needed (const struct PeerContext *peer_ctx) | |||
2710 | * @param peer the peer to remove | 2714 | * @param peer the peer to remove |
2711 | */ | 2715 | */ |
2712 | static void | 2716 | static void |
2713 | remove_peer (struct Sub *sub, | 2717 | remove_peer(struct Sub *sub, |
2714 | const struct GNUNET_PeerIdentity *peer) | 2718 | const struct GNUNET_PeerIdentity *peer) |
2715 | { | 2719 | { |
2716 | (void) View_remove_peer (sub->view, | 2720 | (void)View_remove_peer(sub->view, |
2717 | peer); | 2721 | peer); |
2718 | CustomPeerMap_remove_peer (sub->pull_map, | 2722 | CustomPeerMap_remove_peer(sub->pull_map, |
2719 | peer); | 2723 | peer); |
2720 | CustomPeerMap_remove_peer (sub->push_map, | 2724 | CustomPeerMap_remove_peer(sub->push_map, |
2721 | peer); | 2725 | peer); |
2722 | RPS_sampler_reinitialise_by_value (sub->sampler, | 2726 | RPS_sampler_reinitialise_by_value(sub->sampler, |
2723 | peer); | 2727 | peer); |
2724 | /* We want to destroy the peer now. | 2728 | /* We want to destroy the peer now. |
2725 | * Sometimes, it just seems that it's already been removed from the peer_map, | 2729 | * Sometimes, it just seems that it's already been removed from the peer_map, |
2726 | * so check the peer_map first. */ | 2730 | * so check the peer_map first. */ |
2727 | if (GNUNET_YES == check_peer_known (sub->peer_map, | 2731 | if (GNUNET_YES == check_peer_known(sub->peer_map, |
2728 | peer)) | 2732 | peer)) |
2729 | { | 2733 | { |
2730 | destroy_peer (get_peer_ctx (sub->peer_map, | 2734 | destroy_peer(get_peer_ctx(sub->peer_map, |
2731 | peer)); | 2735 | peer)); |
2732 | } | 2736 | } |
2733 | } | 2737 | } |
2734 | 2738 | ||
2735 | 2739 | ||
@@ -2742,49 +2746,49 @@ remove_peer (struct Sub *sub, | |||
2742 | * @param peer the peer whose data is about to be cleaned | 2746 | * @param peer the peer whose data is about to be cleaned |
2743 | */ | 2747 | */ |
2744 | static void | 2748 | static void |
2745 | clean_peer (struct Sub *sub, | 2749 | clean_peer(struct Sub *sub, |
2746 | const struct GNUNET_PeerIdentity *peer) | 2750 | const struct GNUNET_PeerIdentity *peer) |
2747 | { | 2751 | { |
2748 | if (GNUNET_NO == check_sending_channel_needed (get_peer_ctx (sub->peer_map, | 2752 | if (GNUNET_NO == check_sending_channel_needed(get_peer_ctx(sub->peer_map, |
2749 | peer))) | 2753 | peer))) |
2750 | { | 2754 | { |
2751 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2755 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2752 | "Going to remove send channel to peer %s\n", | 2756 | "Going to remove send channel to peer %s\n", |
2753 | GNUNET_i2s (peer)); | 2757 | GNUNET_i2s(peer)); |
2754 | #if ENABLE_MALICIOUS | 2758 | #if ENABLE_MALICIOUS |
2755 | if (0 != GNUNET_memcmp (&attacked_peer, | 2759 | if (0 != GNUNET_memcmp(&attacked_peer, |
2756 | peer)) | 2760 | peer)) |
2757 | (void) destroy_sending_channel (get_peer_ctx (sub->peer_map, | 2761 | (void)destroy_sending_channel(get_peer_ctx(sub->peer_map, |
2758 | peer)); | 2762 | peer)); |
2759 | #else /* ENABLE_MALICIOUS */ | 2763 | #else /* ENABLE_MALICIOUS */ |
2760 | (void) destroy_sending_channel (get_peer_ctx (sub->peer_map, | 2764 | (void)destroy_sending_channel(get_peer_ctx(sub->peer_map, |
2761 | peer)); | 2765 | peer)); |
2762 | #endif /* ENABLE_MALICIOUS */ | 2766 | #endif /* ENABLE_MALICIOUS */ |
2763 | } | 2767 | } |
2764 | 2768 | ||
2765 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (sub->peer_map, | 2769 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(sub->peer_map, |
2766 | peer)) | 2770 | peer)) |
2767 | { | 2771 | { |
2768 | /* Peer was already removed by callback on destroyed channel */ | 2772 | /* Peer was already removed by callback on destroyed channel */ |
2769 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2773 | LOG(GNUNET_ERROR_TYPE_WARNING, |
2770 | "Peer was removed from our knowledge during cleanup\n"); | 2774 | "Peer was removed from our knowledge during cleanup\n"); |
2771 | return; | 2775 | return; |
2772 | } | 2776 | } |
2773 | 2777 | ||
2774 | if ( (GNUNET_NO == check_peer_send_intention (get_peer_ctx (sub->peer_map, | 2778 | if ((GNUNET_NO == check_peer_send_intention(get_peer_ctx(sub->peer_map, |
2775 | peer))) && | 2779 | peer))) && |
2776 | (GNUNET_NO == View_contains_peer (sub->view, peer)) && | 2780 | (GNUNET_NO == View_contains_peer(sub->view, peer)) && |
2777 | (GNUNET_NO == CustomPeerMap_contains_peer (sub->push_map, peer)) && | 2781 | (GNUNET_NO == CustomPeerMap_contains_peer(sub->push_map, peer)) && |
2778 | (GNUNET_NO == CustomPeerMap_contains_peer (sub->push_map, peer)) && | 2782 | (GNUNET_NO == CustomPeerMap_contains_peer(sub->push_map, peer)) && |
2779 | (0 == RPS_sampler_count_id (sub->sampler, peer)) && | 2783 | (0 == RPS_sampler_count_id(sub->sampler, peer)) && |
2780 | (GNUNET_YES == check_removable (get_peer_ctx (sub->peer_map, peer))) ) | 2784 | (GNUNET_YES == check_removable(get_peer_ctx(sub->peer_map, peer)))) |
2781 | { /* We can safely remove this peer */ | 2785 | { /* We can safely remove this peer */ |
2782 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2786 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2783 | "Going to remove peer %s\n", | 2787 | "Going to remove peer %s\n", |
2784 | GNUNET_i2s (peer)); | 2788 | GNUNET_i2s(peer)); |
2785 | remove_peer (sub, peer); | 2789 | remove_peer(sub, peer); |
2786 | return; | 2790 | return; |
2787 | } | 2791 | } |
2788 | } | 2792 | } |
2789 | 2793 | ||
2790 | 2794 | ||
@@ -2800,31 +2804,32 @@ clean_peer (struct Sub *sub, | |||
2800 | * @param channel The channel being closed | 2804 | * @param channel The channel being closed |
2801 | */ | 2805 | */ |
2802 | static void | 2806 | static void |
2803 | cleanup_destroyed_channel (void *cls, | 2807 | cleanup_destroyed_channel(void *cls, |
2804 | const struct GNUNET_CADET_Channel *channel) | 2808 | const struct GNUNET_CADET_Channel *channel) |
2805 | { | 2809 | { |
2806 | struct ChannelCtx *channel_ctx = cls; | 2810 | struct ChannelCtx *channel_ctx = cls; |
2807 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; | 2811 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; |
2808 | (void) channel; | 2812 | |
2813 | (void)channel; | ||
2809 | 2814 | ||
2810 | channel_ctx->channel = NULL; | 2815 | channel_ctx->channel = NULL; |
2811 | remove_channel_ctx (channel_ctx); | 2816 | remove_channel_ctx(channel_ctx); |
2812 | if (NULL != peer_ctx && | 2817 | if (NULL != peer_ctx && |
2813 | peer_ctx->send_channel_ctx == channel_ctx && | 2818 | peer_ctx->send_channel_ctx == channel_ctx && |
2814 | GNUNET_YES == check_sending_channel_needed (channel_ctx->peer_ctx)) | 2819 | GNUNET_YES == check_sending_channel_needed(channel_ctx->peer_ctx)) |
2815 | { | 2820 | { |
2816 | remove_peer (peer_ctx->sub, &peer_ctx->peer_id); | 2821 | remove_peer(peer_ctx->sub, &peer_ctx->peer_id); |
2817 | } | 2822 | } |
2818 | } | 2823 | } |
2819 | 2824 | ||
2820 | /*********************************************************************** | 2825 | /*********************************************************************** |
2821 | * /Util functions | 2826 | * /Util functions |
2822 | ***********************************************************************/ | 2827 | ***********************************************************************/ |
2823 | 2828 | ||
2824 | 2829 | ||
2825 | 2830 | ||
2826 | /*********************************************************************** | 2831 | /*********************************************************************** |
2827 | * Sub | 2832 | * Sub |
2828 | ***********************************************************************/ | 2833 | ***********************************************************************/ |
2829 | 2834 | ||
2830 | /** | 2835 | /** |
@@ -2838,119 +2843,119 @@ cleanup_destroyed_channel (void *cls, | |||
2838 | * @return Sub | 2843 | * @return Sub |
2839 | */ | 2844 | */ |
2840 | struct Sub * | 2845 | struct Sub * |
2841 | new_sub (const struct GNUNET_HashCode *hash, | 2846 | new_sub(const struct GNUNET_HashCode *hash, |
2842 | uint32_t sampler_size, | 2847 | uint32_t sampler_size, |
2843 | struct GNUNET_TIME_Relative round_interval) | 2848 | struct GNUNET_TIME_Relative round_interval) |
2844 | { | 2849 | { |
2845 | struct Sub *sub; | 2850 | struct Sub *sub; |
2846 | 2851 | ||
2847 | sub = GNUNET_new (struct Sub); | 2852 | sub = GNUNET_new(struct Sub); |
2848 | 2853 | ||
2849 | /* With the hash generated from the secret value this service only connects | 2854 | /* With the hash generated from the secret value this service only connects |
2850 | * to rps instances that share the value */ | 2855 | * to rps instances that share the value */ |
2851 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { | 2856 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { |
2852 | GNUNET_MQ_hd_fixed_size (peer_check, | 2857 | GNUNET_MQ_hd_fixed_size(peer_check, |
2853 | GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE, | 2858 | GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE, |
2854 | struct GNUNET_MessageHeader, | 2859 | struct GNUNET_MessageHeader, |
2855 | NULL), | 2860 | NULL), |
2856 | GNUNET_MQ_hd_fixed_size (peer_push, | 2861 | GNUNET_MQ_hd_fixed_size(peer_push, |
2857 | GNUNET_MESSAGE_TYPE_RPS_PP_PUSH, | 2862 | GNUNET_MESSAGE_TYPE_RPS_PP_PUSH, |
2858 | struct GNUNET_MessageHeader, | 2863 | struct GNUNET_MessageHeader, |
2859 | NULL), | 2864 | NULL), |
2860 | GNUNET_MQ_hd_fixed_size (peer_pull_request, | 2865 | GNUNET_MQ_hd_fixed_size(peer_pull_request, |
2861 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST, | 2866 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST, |
2862 | struct GNUNET_MessageHeader, | 2867 | struct GNUNET_MessageHeader, |
2863 | NULL), | 2868 | NULL), |
2864 | GNUNET_MQ_hd_var_size (peer_pull_reply, | 2869 | GNUNET_MQ_hd_var_size(peer_pull_reply, |
2865 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY, | 2870 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY, |
2866 | struct GNUNET_RPS_P2P_PullReplyMessage, | 2871 | struct GNUNET_RPS_P2P_PullReplyMessage, |
2867 | NULL), | 2872 | NULL), |
2868 | GNUNET_MQ_handler_end () | 2873 | GNUNET_MQ_handler_end() |
2869 | }; | 2874 | }; |
2870 | sub->hash = *hash; | 2875 | sub->hash = *hash; |
2871 | sub->cadet_port = | 2876 | sub->cadet_port = |
2872 | GNUNET_CADET_open_port (cadet_handle, | 2877 | GNUNET_CADET_open_port(cadet_handle, |
2873 | &sub->hash, | 2878 | &sub->hash, |
2874 | &handle_inbound_channel, /* Connect handler */ | 2879 | &handle_inbound_channel, /* Connect handler */ |
2875 | sub, /* cls */ | 2880 | sub, /* cls */ |
2876 | NULL, /* WindowSize handler */ | 2881 | NULL, /* WindowSize handler */ |
2877 | &cleanup_destroyed_channel, /* Disconnect handler */ | 2882 | &cleanup_destroyed_channel, /* Disconnect handler */ |
2878 | cadet_handlers); | 2883 | cadet_handlers); |
2879 | if (NULL == sub->cadet_port) | 2884 | if (NULL == sub->cadet_port) |
2880 | { | 2885 | { |
2881 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2886 | LOG(GNUNET_ERROR_TYPE_ERROR, |
2882 | "Cadet port `%s' is already in use.\n", | 2887 | "Cadet port `%s' is already in use.\n", |
2883 | GNUNET_APPLICATION_PORT_RPS); | 2888 | GNUNET_APPLICATION_PORT_RPS); |
2884 | GNUNET_assert (0); | 2889 | GNUNET_assert(0); |
2885 | } | 2890 | } |
2886 | 2891 | ||
2887 | /* Set up general data structure to keep track about peers */ | 2892 | /* Set up general data structure to keep track about peers */ |
2888 | sub->valid_peers = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); | 2893 | sub->valid_peers = GNUNET_CONTAINER_multipeermap_create(4, GNUNET_NO); |
2889 | if (GNUNET_OK != | 2894 | if (GNUNET_OK != |
2890 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 2895 | GNUNET_CONFIGURATION_get_value_filename(cfg, |
2891 | "rps", | 2896 | "rps", |
2892 | "FILENAME_VALID_PEERS", | 2897 | "FILENAME_VALID_PEERS", |
2893 | &sub->filename_valid_peers)) | 2898 | &sub->filename_valid_peers)) |
2894 | { | 2899 | { |
2895 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 2900 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
2896 | "rps", | 2901 | "rps", |
2897 | "FILENAME_VALID_PEERS"); | 2902 | "FILENAME_VALID_PEERS"); |
2898 | } | 2903 | } |
2899 | if (0 != strncmp ("DISABLE", sub->filename_valid_peers, 7)) | 2904 | if (0 != strncmp("DISABLE", sub->filename_valid_peers, 7)) |
2900 | { | 2905 | { |
2901 | char *tmp_filename_valid_peers; | 2906 | char *tmp_filename_valid_peers; |
2902 | char str_hash[105]; | 2907 | char str_hash[105]; |
2903 | 2908 | ||
2904 | GNUNET_snprintf (str_hash, | 2909 | GNUNET_snprintf(str_hash, |
2905 | sizeof (str_hash), | 2910 | sizeof(str_hash), |
2906 | GNUNET_h2s_full (hash)); | 2911 | GNUNET_h2s_full(hash)); |
2907 | tmp_filename_valid_peers = sub->filename_valid_peers; | 2912 | tmp_filename_valid_peers = sub->filename_valid_peers; |
2908 | GNUNET_asprintf (&sub->filename_valid_peers, | 2913 | GNUNET_asprintf(&sub->filename_valid_peers, |
2909 | "%s%s", | 2914 | "%s%s", |
2910 | tmp_filename_valid_peers, | 2915 | tmp_filename_valid_peers, |
2911 | str_hash); | 2916 | str_hash); |
2912 | GNUNET_free (tmp_filename_valid_peers); | 2917 | GNUNET_free(tmp_filename_valid_peers); |
2913 | } | 2918 | } |
2914 | sub->peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); | 2919 | sub->peer_map = GNUNET_CONTAINER_multipeermap_create(4, GNUNET_NO); |
2915 | 2920 | ||
2916 | /* Set up the sampler */ | 2921 | /* Set up the sampler */ |
2917 | sub->sampler_size_est_min = sampler_size; | 2922 | sub->sampler_size_est_min = sampler_size; |
2918 | sub->sampler_size_est_need = sampler_size;; | 2923 | sub->sampler_size_est_need = sampler_size;; |
2919 | LOG (GNUNET_ERROR_TYPE_DEBUG, "MINSIZE is %u\n", sub->sampler_size_est_min); | 2924 | LOG(GNUNET_ERROR_TYPE_DEBUG, "MINSIZE is %u\n", sub->sampler_size_est_min); |
2920 | GNUNET_assert (0 != round_interval.rel_value_us); | 2925 | GNUNET_assert(0 != round_interval.rel_value_us); |
2921 | sub->round_interval = round_interval; | 2926 | sub->round_interval = round_interval; |
2922 | sub->sampler = RPS_sampler_init (sampler_size, | 2927 | sub->sampler = RPS_sampler_init(sampler_size, |
2923 | round_interval); | 2928 | round_interval); |
2924 | 2929 | ||
2925 | /* Logging of internals */ | 2930 | /* Logging of internals */ |
2926 | #ifdef TO_FILE_FULL | 2931 | #ifdef TO_FILE_FULL |
2927 | sub->file_name_view_log = store_prefix_file_name (&own_identity, "view"); | 2932 | sub->file_name_view_log = store_prefix_file_name(&own_identity, "view"); |
2928 | #endif /* TO_FILE_FULL */ | 2933 | #endif /* TO_FILE_FULL */ |
2929 | #ifdef TO_FILE | 2934 | #ifdef TO_FILE |
2930 | #ifdef TO_FILE_FULL | 2935 | #ifdef TO_FILE_FULL |
2931 | sub->file_name_observed_log = store_prefix_file_name (&own_identity, | 2936 | sub->file_name_observed_log = store_prefix_file_name(&own_identity, |
2932 | "observed"); | 2937 | "observed"); |
2933 | #endif /* TO_FILE_FULL */ | 2938 | #endif /* TO_FILE_FULL */ |
2934 | sub->num_observed_peers = 0; | 2939 | sub->num_observed_peers = 0; |
2935 | sub->observed_unique_peers = GNUNET_CONTAINER_multipeermap_create (1, | 2940 | sub->observed_unique_peers = GNUNET_CONTAINER_multipeermap_create(1, |
2936 | GNUNET_NO); | 2941 | GNUNET_NO); |
2937 | #endif /* TO_FILE */ | 2942 | #endif /* TO_FILE */ |
2938 | 2943 | ||
2939 | /* Set up data structures for gossip */ | 2944 | /* Set up data structures for gossip */ |
2940 | sub->push_map = CustomPeerMap_create (4); | 2945 | sub->push_map = CustomPeerMap_create(4); |
2941 | sub->pull_map = CustomPeerMap_create (4); | 2946 | sub->pull_map = CustomPeerMap_create(4); |
2942 | sub->view_size_est_min = sampler_size;; | 2947 | sub->view_size_est_min = sampler_size;; |
2943 | sub->view = View_create (sub->view_size_est_min); | 2948 | sub->view = View_create(sub->view_size_est_min); |
2944 | if (sub == msub) | 2949 | if (sub == msub) |
2945 | { | 2950 | { |
2946 | GNUNET_STATISTICS_set (stats, | 2951 | GNUNET_STATISTICS_set(stats, |
2947 | "view size aim", | 2952 | "view size aim", |
2948 | sub->view_size_est_min, | 2953 | sub->view_size_est_min, |
2949 | GNUNET_NO); | 2954 | GNUNET_NO); |
2950 | } | 2955 | } |
2951 | 2956 | ||
2952 | /* Start executing rounds */ | 2957 | /* Start executing rounds */ |
2953 | sub->do_round_task = GNUNET_SCHEDULER_add_now (&do_round, sub); | 2958 | sub->do_round_task = GNUNET_SCHEDULER_add_now(&do_round, sub); |
2954 | 2959 | ||
2955 | return sub; | 2960 | return sub; |
2956 | } | 2961 | } |
@@ -2966,36 +2971,36 @@ new_sub (const struct GNUNET_HashCode *hash, | |||
2966 | * @param file_name file to dump into | 2971 | * @param file_name file to dump into |
2967 | */ | 2972 | */ |
2968 | static void | 2973 | static void |
2969 | write_histogram_to_file (const uint32_t hist_array[], | 2974 | write_histogram_to_file(const uint32_t hist_array[], |
2970 | const char *file_name) | 2975 | const char *file_name) |
2971 | { | 2976 | { |
2972 | char collect_str[SIZE_DUMP_FILE + 1] = ""; | 2977 | char collect_str[SIZE_DUMP_FILE + 1] = ""; |
2973 | char *recv_str_iter; | 2978 | char *recv_str_iter; |
2974 | char *file_name_full; | 2979 | char *file_name_full; |
2975 | 2980 | ||
2976 | recv_str_iter = collect_str; | 2981 | recv_str_iter = collect_str; |
2977 | file_name_full = store_prefix_file_name (&own_identity, | 2982 | file_name_full = store_prefix_file_name(&own_identity, |
2978 | file_name); | 2983 | file_name); |
2979 | for (uint32_t i = 0; i < HISTOGRAM_FILE_SLOTS; i++) | 2984 | for (uint32_t i = 0; i < HISTOGRAM_FILE_SLOTS; i++) |
2980 | { | 2985 | { |
2981 | char collect_str_tmp[8]; | 2986 | char collect_str_tmp[8]; |
2982 | 2987 | ||
2983 | GNUNET_snprintf (collect_str_tmp, | 2988 | GNUNET_snprintf(collect_str_tmp, |
2984 | sizeof (collect_str_tmp), | 2989 | sizeof(collect_str_tmp), |
2985 | "%" PRIu32 "\n", | 2990 | "%" PRIu32 "\n", |
2986 | hist_array[i]); | 2991 | hist_array[i]); |
2987 | recv_str_iter = stpncpy (recv_str_iter, | 2992 | recv_str_iter = stpncpy(recv_str_iter, |
2988 | collect_str_tmp, | 2993 | collect_str_tmp, |
2989 | 6); | 2994 | 6); |
2990 | } | 2995 | } |
2991 | (void) stpcpy (recv_str_iter, | 2996 | (void)stpcpy(recv_str_iter, |
2992 | "\n"); | 2997 | "\n"); |
2993 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2998 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2994 | "Writing push stats to disk\n"); | 2999 | "Writing push stats to disk\n"); |
2995 | to_file_w_len (file_name_full, | 3000 | to_file_w_len(file_name_full, |
2996 | SIZE_DUMP_FILE, | 3001 | SIZE_DUMP_FILE, |
2997 | collect_str); | 3002 | collect_str); |
2998 | GNUNET_free (file_name_full); | 3003 | GNUNET_free(file_name_full); |
2999 | } | 3004 | } |
3000 | #endif /* TO_FILE */ | 3005 | #endif /* TO_FILE */ |
3001 | 3006 | ||
@@ -3006,66 +3011,66 @@ write_histogram_to_file (const uint32_t hist_array[], | |||
3006 | * @param sub Sub to destroy | 3011 | * @param sub Sub to destroy |
3007 | */ | 3012 | */ |
3008 | static void | 3013 | static void |
3009 | destroy_sub (struct Sub *sub) | 3014 | destroy_sub(struct Sub *sub) |
3010 | { | 3015 | { |
3011 | GNUNET_assert (NULL != sub); | 3016 | GNUNET_assert(NULL != sub); |
3012 | GNUNET_assert (NULL != sub->do_round_task); | 3017 | GNUNET_assert(NULL != sub->do_round_task); |
3013 | GNUNET_SCHEDULER_cancel (sub->do_round_task); | 3018 | GNUNET_SCHEDULER_cancel(sub->do_round_task); |
3014 | sub->do_round_task = NULL; | 3019 | sub->do_round_task = NULL; |
3015 | 3020 | ||
3016 | /* Disconnect from cadet */ | 3021 | /* Disconnect from cadet */ |
3017 | GNUNET_CADET_close_port (sub->cadet_port); | 3022 | GNUNET_CADET_close_port(sub->cadet_port); |
3018 | sub->cadet_port= NULL; | 3023 | sub->cadet_port = NULL; |
3019 | 3024 | ||
3020 | /* Clean up data structures for peers */ | 3025 | /* Clean up data structures for peers */ |
3021 | RPS_sampler_destroy (sub->sampler); | 3026 | RPS_sampler_destroy(sub->sampler); |
3022 | sub->sampler = NULL; | 3027 | sub->sampler = NULL; |
3023 | View_destroy (sub->view); | 3028 | View_destroy(sub->view); |
3024 | sub->view = NULL; | 3029 | sub->view = NULL; |
3025 | CustomPeerMap_destroy (sub->push_map); | 3030 | CustomPeerMap_destroy(sub->push_map); |
3026 | sub->push_map = NULL; | 3031 | sub->push_map = NULL; |
3027 | CustomPeerMap_destroy (sub->pull_map); | 3032 | CustomPeerMap_destroy(sub->pull_map); |
3028 | sub->pull_map = NULL; | 3033 | sub->pull_map = NULL; |
3029 | peers_terminate (sub); | 3034 | peers_terminate(sub); |
3030 | 3035 | ||
3031 | /* Free leftover data structures */ | 3036 | /* Free leftover data structures */ |
3032 | #ifdef TO_FILE_FULL | 3037 | #ifdef TO_FILE_FULL |
3033 | GNUNET_free (sub->file_name_view_log); | 3038 | GNUNET_free(sub->file_name_view_log); |
3034 | sub->file_name_view_log = NULL; | 3039 | sub->file_name_view_log = NULL; |
3035 | #endif /* TO_FILE_FULL */ | 3040 | #endif /* TO_FILE_FULL */ |
3036 | #ifdef TO_FILE | 3041 | #ifdef TO_FILE |
3037 | #ifdef TO_FILE_FULL | 3042 | #ifdef TO_FILE_FULL |
3038 | GNUNET_free (sub->file_name_observed_log); | 3043 | GNUNET_free(sub->file_name_observed_log); |
3039 | sub->file_name_observed_log = NULL; | 3044 | sub->file_name_observed_log = NULL; |
3040 | #endif /* TO_FILE_FULL */ | 3045 | #endif /* TO_FILE_FULL */ |
3041 | 3046 | ||
3042 | /* Write push frequencies to disk */ | 3047 | /* Write push frequencies to disk */ |
3043 | write_histogram_to_file (sub->push_recv, | 3048 | write_histogram_to_file(sub->push_recv, |
3044 | "push_recv"); | 3049 | "push_recv"); |
3045 | 3050 | ||
3046 | /* Write push deltas to disk */ | 3051 | /* Write push deltas to disk */ |
3047 | write_histogram_to_file (sub->push_delta, | 3052 | write_histogram_to_file(sub->push_delta, |
3048 | "push_delta"); | 3053 | "push_delta"); |
3049 | 3054 | ||
3050 | /* Write pull delays to disk */ | 3055 | /* Write pull delays to disk */ |
3051 | write_histogram_to_file (sub->pull_delays, | 3056 | write_histogram_to_file(sub->pull_delays, |
3052 | "pull_delays"); | 3057 | "pull_delays"); |
3053 | 3058 | ||
3054 | GNUNET_CONTAINER_multipeermap_destroy (sub->observed_unique_peers); | 3059 | GNUNET_CONTAINER_multipeermap_destroy(sub->observed_unique_peers); |
3055 | sub->observed_unique_peers = NULL; | 3060 | sub->observed_unique_peers = NULL; |
3056 | #endif /* TO_FILE */ | 3061 | #endif /* TO_FILE */ |
3057 | 3062 | ||
3058 | GNUNET_free (sub); | 3063 | GNUNET_free(sub); |
3059 | } | 3064 | } |
3060 | 3065 | ||
3061 | 3066 | ||
3062 | /*********************************************************************** | 3067 | /*********************************************************************** |
3063 | * /Sub | 3068 | * /Sub |
3064 | ***********************************************************************/ | 3069 | ***********************************************************************/ |
3065 | 3070 | ||
3066 | 3071 | ||
3067 | /*********************************************************************** | 3072 | /*********************************************************************** |
3068 | * Core handlers | 3073 | * Core handlers |
3069 | ***********************************************************************/ | 3074 | ***********************************************************************/ |
3070 | 3075 | ||
3071 | /** | 3076 | /** |
@@ -3075,13 +3080,13 @@ destroy_sub (struct Sub *sub) | |||
3075 | * @param my_identity - unused | 3080 | * @param my_identity - unused |
3076 | */ | 3081 | */ |
3077 | void | 3082 | void |
3078 | core_init (void *cls, | 3083 | core_init(void *cls, |
3079 | const struct GNUNET_PeerIdentity *my_identity) | 3084 | const struct GNUNET_PeerIdentity *my_identity) |
3080 | { | 3085 | { |
3081 | (void) cls; | 3086 | (void)cls; |
3082 | (void) my_identity; | 3087 | (void)my_identity; |
3083 | 3088 | ||
3084 | map_single_hop = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); | 3089 | map_single_hop = GNUNET_CONTAINER_multipeermap_create(4, GNUNET_NO); |
3085 | } | 3090 | } |
3086 | 3091 | ||
3087 | 3092 | ||
@@ -3094,18 +3099,18 @@ core_init (void *cls, | |||
3094 | * @return closure given to #core_disconnects as peer_cls | 3099 | * @return closure given to #core_disconnects as peer_cls |
3095 | */ | 3100 | */ |
3096 | void * | 3101 | void * |
3097 | core_connects (void *cls, | 3102 | core_connects(void *cls, |
3098 | const struct GNUNET_PeerIdentity *peer, | 3103 | const struct GNUNET_PeerIdentity *peer, |
3099 | struct GNUNET_MQ_Handle *mq) | 3104 | struct GNUNET_MQ_Handle *mq) |
3100 | { | 3105 | { |
3101 | (void) cls; | 3106 | (void)cls; |
3102 | (void) mq; | 3107 | (void)mq; |
3103 | 3108 | ||
3104 | GNUNET_assert (GNUNET_YES == | 3109 | GNUNET_assert(GNUNET_YES == |
3105 | GNUNET_CONTAINER_multipeermap_put (map_single_hop, | 3110 | GNUNET_CONTAINER_multipeermap_put(map_single_hop, |
3106 | peer, | 3111 | peer, |
3107 | NULL, | 3112 | NULL, |
3108 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 3113 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
3109 | return NULL; | 3114 | return NULL; |
3110 | } | 3115 | } |
3111 | 3116 | ||
@@ -3119,18 +3124,18 @@ core_connects (void *cls, | |||
3119 | * @param peer_cls closure given in #core_connects - unused | 3124 | * @param peer_cls closure given in #core_connects - unused |
3120 | */ | 3125 | */ |
3121 | void | 3126 | void |
3122 | core_disconnects (void *cls, | 3127 | core_disconnects(void *cls, |
3123 | const struct GNUNET_PeerIdentity *peer, | 3128 | const struct GNUNET_PeerIdentity *peer, |
3124 | void *peer_cls) | 3129 | void *peer_cls) |
3125 | { | 3130 | { |
3126 | (void) cls; | 3131 | (void)cls; |
3127 | (void) peer_cls; | 3132 | (void)peer_cls; |
3128 | 3133 | ||
3129 | GNUNET_CONTAINER_multipeermap_remove_all (map_single_hop, peer); | 3134 | GNUNET_CONTAINER_multipeermap_remove_all(map_single_hop, peer); |
3130 | } | 3135 | } |
3131 | 3136 | ||
3132 | /*********************************************************************** | 3137 | /*********************************************************************** |
3133 | * /Core handlers | 3138 | * /Core handlers |
3134 | ***********************************************************************/ | 3139 | ***********************************************************************/ |
3135 | 3140 | ||
3136 | 3141 | ||
@@ -3140,18 +3145,18 @@ core_disconnects (void *cls, | |||
3140 | * @param cli_ctx Context to destroy | 3145 | * @param cli_ctx Context to destroy |
3141 | */ | 3146 | */ |
3142 | static void | 3147 | static void |
3143 | destroy_cli_ctx (struct ClientContext *cli_ctx) | 3148 | destroy_cli_ctx(struct ClientContext *cli_ctx) |
3144 | { | 3149 | { |
3145 | GNUNET_assert (NULL != cli_ctx); | 3150 | GNUNET_assert(NULL != cli_ctx); |
3146 | GNUNET_CONTAINER_DLL_remove (cli_ctx_head, | 3151 | GNUNET_CONTAINER_DLL_remove(cli_ctx_head, |
3147 | cli_ctx_tail, | 3152 | cli_ctx_tail, |
3148 | cli_ctx); | 3153 | cli_ctx); |
3149 | if (NULL != cli_ctx->sub) | 3154 | if (NULL != cli_ctx->sub) |
3150 | { | 3155 | { |
3151 | destroy_sub (cli_ctx->sub); | 3156 | destroy_sub(cli_ctx->sub); |
3152 | cli_ctx->sub = NULL; | 3157 | cli_ctx->sub = NULL; |
3153 | } | 3158 | } |
3154 | GNUNET_free (cli_ctx); | 3159 | GNUNET_free(cli_ctx); |
3155 | } | 3160 | } |
3156 | 3161 | ||
3157 | 3162 | ||
@@ -3163,42 +3168,44 @@ destroy_cli_ctx (struct ClientContext *cli_ctx) | |||
3163 | * @param std_dev standard deviation for the estimate | 3168 | * @param std_dev standard deviation for the estimate |
3164 | */ | 3169 | */ |
3165 | static void | 3170 | static void |
3166 | adapt_sizes (struct Sub *sub, double logestimate, double std_dev) | 3171 | adapt_sizes(struct Sub *sub, double logestimate, double std_dev) |
3167 | { | 3172 | { |
3168 | double estimate; | 3173 | double estimate; |
3174 | |||
3169 | //double scale; // TODO this might go gloabal/config | 3175 | //double scale; // TODO this might go gloabal/config |
3170 | 3176 | ||
3171 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3177 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3172 | "Received a ns estimate - logest: %f, std_dev: %f (old_size: %u)\n", | 3178 | "Received a ns estimate - logest: %f, std_dev: %f (old_size: %u)\n", |
3173 | logestimate, std_dev, RPS_sampler_get_size (sub->sampler)); | 3179 | logestimate, std_dev, RPS_sampler_get_size(sub->sampler)); |
3174 | //scale = .01; | 3180 | //scale = .01; |
3175 | estimate = GNUNET_NSE_log_estimate_to_n (logestimate); | 3181 | estimate = GNUNET_NSE_log_estimate_to_n(logestimate); |
3176 | // GNUNET_NSE_log_estimate_to_n (logestimate); | 3182 | // GNUNET_NSE_log_estimate_to_n (logestimate); |
3177 | estimate = pow (estimate, 1.0 / 3); | 3183 | estimate = pow(estimate, 1.0 / 3); |
3178 | // TODO add if std_dev is a number | 3184 | // TODO add if std_dev is a number |
3179 | // estimate += (std_dev * scale); | 3185 | // estimate += (std_dev * scale); |
3180 | if (sub->view_size_est_min < ceil (estimate)) | 3186 | if (sub->view_size_est_min < ceil(estimate)) |
3181 | { | 3187 | { |
3182 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Changing estimate to %f\n", estimate); | 3188 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Changing estimate to %f\n", estimate); |
3183 | sub->sampler_size_est_need = estimate; | 3189 | sub->sampler_size_est_need = estimate; |
3184 | sub->view_size_est_need = estimate; | 3190 | sub->view_size_est_need = estimate; |
3185 | } else | 3191 | } |
3186 | { | 3192 | else |
3187 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Not using estimate %f\n", estimate); | 3193 | { |
3188 | //sub->sampler_size_est_need = sub->view_size_est_min; | 3194 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Not using estimate %f\n", estimate); |
3189 | sub->view_size_est_need = sub->view_size_est_min; | 3195 | //sub->sampler_size_est_need = sub->view_size_est_min; |
3190 | } | 3196 | sub->view_size_est_need = sub->view_size_est_min; |
3197 | } | ||
3191 | if (sub == msub) | 3198 | if (sub == msub) |
3192 | { | 3199 | { |
3193 | GNUNET_STATISTICS_set (stats, | 3200 | GNUNET_STATISTICS_set(stats, |
3194 | "view size aim", | 3201 | "view size aim", |
3195 | sub->view_size_est_need, | 3202 | sub->view_size_est_need, |
3196 | GNUNET_NO); | 3203 | GNUNET_NO); |
3197 | } | 3204 | } |
3198 | 3205 | ||
3199 | /* If the NSE has changed adapt the lists accordingly */ | 3206 | /* If the NSE has changed adapt the lists accordingly */ |
3200 | resize_wrapper (sub->sampler, sub->sampler_size_est_need); | 3207 | resize_wrapper(sub->sampler, sub->sampler_size_est_need); |
3201 | View_change_len (sub->view, sub->view_size_est_need); | 3208 | View_change_len(sub->view, sub->view_size_est_need); |
3202 | } | 3209 | } |
3203 | 3210 | ||
3204 | 3211 | ||
@@ -3216,24 +3223,24 @@ adapt_sizes (struct Sub *sub, double logestimate, double std_dev) | |||
3216 | * @param std_dev standard deviation for the estimate | 3223 | * @param std_dev standard deviation for the estimate |
3217 | */ | 3224 | */ |
3218 | static void | 3225 | static void |
3219 | nse_callback (void *cls, | 3226 | nse_callback(void *cls, |
3220 | struct GNUNET_TIME_Absolute timestamp, | 3227 | struct GNUNET_TIME_Absolute timestamp, |
3221 | double logestimate, double std_dev) | 3228 | double logestimate, double std_dev) |
3222 | { | 3229 | { |
3223 | (void) cls; | 3230 | (void)cls; |
3224 | (void) timestamp; | 3231 | (void)timestamp; |
3225 | struct ClientContext *cli_ctx_iter; | 3232 | struct ClientContext *cli_ctx_iter; |
3226 | 3233 | ||
3227 | adapt_sizes (msub, logestimate, std_dev); | 3234 | adapt_sizes(msub, logestimate, std_dev); |
3228 | for (cli_ctx_iter = cli_ctx_head; | 3235 | for (cli_ctx_iter = cli_ctx_head; |
3229 | NULL != cli_ctx_iter; | 3236 | NULL != cli_ctx_iter; |
3230 | cli_ctx_iter = cli_ctx_iter->next) | 3237 | cli_ctx_iter = cli_ctx_iter->next) |
3231 | { | ||
3232 | if (NULL != cli_ctx_iter->sub) | ||
3233 | { | 3238 | { |
3234 | adapt_sizes (cli_ctx_iter->sub, logestimate, std_dev); | 3239 | if (NULL != cli_ctx_iter->sub) |
3240 | { | ||
3241 | adapt_sizes(cli_ctx_iter->sub, logestimate, std_dev); | ||
3242 | } | ||
3235 | } | 3243 | } |
3236 | } | ||
3237 | } | 3244 | } |
3238 | 3245 | ||
3239 | 3246 | ||
@@ -3247,24 +3254,24 @@ nse_callback (void *cls, | |||
3247 | * #GNUNET_SYSERR otherwise | 3254 | * #GNUNET_SYSERR otherwise |
3248 | */ | 3255 | */ |
3249 | static int | 3256 | static int |
3250 | check_client_seed (void *cls, const struct GNUNET_RPS_CS_SeedMessage *msg) | 3257 | check_client_seed(void *cls, const struct GNUNET_RPS_CS_SeedMessage *msg) |
3251 | { | 3258 | { |
3252 | struct ClientContext *cli_ctx = cls; | 3259 | struct ClientContext *cli_ctx = cls; |
3253 | uint16_t msize = ntohs (msg->header.size); | 3260 | uint16_t msize = ntohs(msg->header.size); |
3254 | uint32_t num_peers = ntohl (msg->num_peers); | 3261 | uint32_t num_peers = ntohl(msg->num_peers); |
3255 | 3262 | ||
3256 | msize -= sizeof (struct GNUNET_RPS_CS_SeedMessage); | 3263 | msize -= sizeof(struct GNUNET_RPS_CS_SeedMessage); |
3257 | if ( (msize / sizeof (struct GNUNET_PeerIdentity) != num_peers) || | 3264 | if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) || |
3258 | (msize % sizeof (struct GNUNET_PeerIdentity) != 0) ) | 3265 | (msize % sizeof(struct GNUNET_PeerIdentity) != 0)) |
3259 | { | 3266 | { |
3260 | LOG (GNUNET_ERROR_TYPE_ERROR, | 3267 | LOG(GNUNET_ERROR_TYPE_ERROR, |
3261 | "message says it sends %" PRIu32 " peers, have space for %lu peers\n", | 3268 | "message says it sends %" PRIu32 " peers, have space for %lu peers\n", |
3262 | ntohl (msg->num_peers), | 3269 | ntohl(msg->num_peers), |
3263 | (msize / sizeof (struct GNUNET_PeerIdentity))); | 3270 | (msize / sizeof(struct GNUNET_PeerIdentity))); |
3264 | GNUNET_break (0); | 3271 | GNUNET_break(0); |
3265 | GNUNET_SERVICE_client_drop (cli_ctx->client); | 3272 | GNUNET_SERVICE_client_drop(cli_ctx->client); |
3266 | return GNUNET_SYSERR; | 3273 | return GNUNET_SYSERR; |
3267 | } | 3274 | } |
3268 | return GNUNET_OK; | 3275 | return GNUNET_OK; |
3269 | } | 3276 | } |
3270 | 3277 | ||
@@ -3276,32 +3283,34 @@ check_client_seed (void *cls, const struct GNUNET_RPS_CS_SeedMessage *msg) | |||
3276 | * @param message the actual message | 3283 | * @param message the actual message |
3277 | */ | 3284 | */ |
3278 | static void | 3285 | static void |
3279 | handle_client_seed (void *cls, | 3286 | handle_client_seed(void *cls, |
3280 | const struct GNUNET_RPS_CS_SeedMessage *msg) | 3287 | const struct GNUNET_RPS_CS_SeedMessage *msg) |
3281 | { | 3288 | { |
3282 | struct ClientContext *cli_ctx = cls; | 3289 | struct ClientContext *cli_ctx = cls; |
3283 | struct GNUNET_PeerIdentity *peers; | 3290 | struct GNUNET_PeerIdentity *peers; |
3284 | uint32_t num_peers; | 3291 | uint32_t num_peers; |
3285 | uint32_t i; | 3292 | uint32_t i; |
3286 | 3293 | ||
3287 | num_peers = ntohl (msg->num_peers); | 3294 | num_peers = ntohl(msg->num_peers); |
3288 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; | 3295 | peers = (struct GNUNET_PeerIdentity *)&msg[1]; |
3289 | 3296 | ||
3290 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3297 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3291 | "Client seeded peers:\n"); | 3298 | "Client seeded peers:\n"); |
3292 | print_peer_list (peers, num_peers); | 3299 | print_peer_list(peers, num_peers); |
3293 | 3300 | ||
3294 | for (i = 0; i < num_peers; i++) | 3301 | for (i = 0; i < num_peers; i++) |
3295 | { | 3302 | { |
3296 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3303 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3297 | "Updating samplers with seed %" PRIu32 ": %s\n", | 3304 | "Updating samplers with seed %" PRIu32 ": %s\n", |
3298 | i, | 3305 | i, |
3299 | GNUNET_i2s (&peers[i])); | 3306 | GNUNET_i2s(&peers[i])); |
3300 | 3307 | ||
3301 | if (NULL != msub) got_peer (msub, &peers[i]); /* Condition needed? */ | 3308 | if (NULL != msub) |
3302 | if (NULL != cli_ctx->sub) got_peer (cli_ctx->sub, &peers[i]); | 3309 | got_peer(msub, &peers[i]); /* Condition needed? */ |
3303 | } | 3310 | if (NULL != cli_ctx->sub) |
3304 | GNUNET_SERVICE_client_continue (cli_ctx->client); | 3311 | got_peer(cli_ctx->sub, &peers[i]); |
3312 | } | ||
3313 | GNUNET_SERVICE_client_continue(cli_ctx->client); | ||
3305 | } | 3314 | } |
3306 | 3315 | ||
3307 | 3316 | ||
@@ -3313,22 +3322,22 @@ handle_client_seed (void *cls, | |||
3313 | * receive | 3322 | * receive |
3314 | */ | 3323 | */ |
3315 | static void | 3324 | static void |
3316 | handle_client_view_request (void *cls, | 3325 | handle_client_view_request(void *cls, |
3317 | const struct GNUNET_RPS_CS_DEBUG_ViewRequest *msg) | 3326 | const struct GNUNET_RPS_CS_DEBUG_ViewRequest *msg) |
3318 | { | 3327 | { |
3319 | struct ClientContext *cli_ctx = cls; | 3328 | struct ClientContext *cli_ctx = cls; |
3320 | uint64_t num_updates; | 3329 | uint64_t num_updates; |
3321 | 3330 | ||
3322 | num_updates = ntohl (msg->num_updates); | 3331 | num_updates = ntohl(msg->num_updates); |
3323 | 3332 | ||
3324 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3333 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3325 | "Client requested %" PRIu64 " updates of view.\n", | 3334 | "Client requested %" PRIu64 " updates of view.\n", |
3326 | num_updates); | 3335 | num_updates); |
3327 | 3336 | ||
3328 | GNUNET_assert (NULL != cli_ctx); | 3337 | GNUNET_assert(NULL != cli_ctx); |
3329 | cli_ctx->view_updates_left = num_updates; | 3338 | cli_ctx->view_updates_left = num_updates; |
3330 | send_view (cli_ctx, NULL, 0); | 3339 | send_view(cli_ctx, NULL, 0); |
3331 | GNUNET_SERVICE_client_continue (cli_ctx->client); | 3340 | GNUNET_SERVICE_client_continue(cli_ctx->client); |
3332 | } | 3341 | } |
3333 | 3342 | ||
3334 | 3343 | ||
@@ -3339,22 +3348,23 @@ handle_client_view_request (void *cls, | |||
3339 | * @param msg Unused | 3348 | * @param msg Unused |
3340 | */ | 3349 | */ |
3341 | static void | 3350 | static void |
3342 | handle_client_view_cancel (void *cls, | 3351 | handle_client_view_cancel(void *cls, |
3343 | const struct GNUNET_MessageHeader *msg) | 3352 | const struct GNUNET_MessageHeader *msg) |
3344 | { | 3353 | { |
3345 | struct ClientContext *cli_ctx = cls; | 3354 | struct ClientContext *cli_ctx = cls; |
3346 | (void) msg; | ||
3347 | 3355 | ||
3348 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3356 | (void)msg; |
3349 | "Client does not want to receive updates of view any more.\n"); | ||
3350 | 3357 | ||
3351 | GNUNET_assert (NULL != cli_ctx); | 3358 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3359 | "Client does not want to receive updates of view any more.\n"); | ||
3360 | |||
3361 | GNUNET_assert(NULL != cli_ctx); | ||
3352 | cli_ctx->view_updates_left = 0; | 3362 | cli_ctx->view_updates_left = 0; |
3353 | GNUNET_SERVICE_client_continue (cli_ctx->client); | 3363 | GNUNET_SERVICE_client_continue(cli_ctx->client); |
3354 | if (GNUNET_YES == cli_ctx->stream_update) | 3364 | if (GNUNET_YES == cli_ctx->stream_update) |
3355 | { | 3365 | { |
3356 | destroy_cli_ctx (cli_ctx); | 3366 | destroy_cli_ctx(cli_ctx); |
3357 | } | 3367 | } |
3358 | } | 3368 | } |
3359 | 3369 | ||
3360 | 3370 | ||
@@ -3365,18 +3375,19 @@ handle_client_view_cancel (void *cls, | |||
3365 | * @param message unused | 3375 | * @param message unused |
3366 | */ | 3376 | */ |
3367 | static void | 3377 | static void |
3368 | handle_client_stream_request (void *cls, | 3378 | handle_client_stream_request(void *cls, |
3369 | const struct GNUNET_RPS_CS_DEBUG_StreamRequest *msg) | 3379 | const struct GNUNET_RPS_CS_DEBUG_StreamRequest *msg) |
3370 | { | 3380 | { |
3371 | struct ClientContext *cli_ctx = cls; | 3381 | struct ClientContext *cli_ctx = cls; |
3372 | (void) msg; | ||
3373 | 3382 | ||
3374 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3383 | (void)msg; |
3375 | "Client requested peers from biased stream.\n"); | 3384 | |
3385 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
3386 | "Client requested peers from biased stream.\n"); | ||
3376 | cli_ctx->stream_update = GNUNET_YES; | 3387 | cli_ctx->stream_update = GNUNET_YES; |
3377 | 3388 | ||
3378 | GNUNET_assert (NULL != cli_ctx); | 3389 | GNUNET_assert(NULL != cli_ctx); |
3379 | GNUNET_SERVICE_client_continue (cli_ctx->client); | 3390 | GNUNET_SERVICE_client_continue(cli_ctx->client); |
3380 | } | 3391 | } |
3381 | 3392 | ||
3382 | 3393 | ||
@@ -3387,18 +3398,19 @@ handle_client_stream_request (void *cls, | |||
3387 | * @param msg unused | 3398 | * @param msg unused |
3388 | */ | 3399 | */ |
3389 | static void | 3400 | static void |
3390 | handle_client_stream_cancel (void *cls, | 3401 | handle_client_stream_cancel(void *cls, |
3391 | const struct GNUNET_MessageHeader *msg) | 3402 | const struct GNUNET_MessageHeader *msg) |
3392 | { | 3403 | { |
3393 | struct ClientContext *cli_ctx = cls; | 3404 | struct ClientContext *cli_ctx = cls; |
3394 | (void) msg; | ||
3395 | 3405 | ||
3396 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3406 | (void)msg; |
3397 | "Client canceled receiving peers from biased stream.\n"); | 3407 | |
3408 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
3409 | "Client canceled receiving peers from biased stream.\n"); | ||
3398 | cli_ctx->stream_update = GNUNET_NO; | 3410 | cli_ctx->stream_update = GNUNET_NO; |
3399 | 3411 | ||
3400 | GNUNET_assert (NULL != cli_ctx); | 3412 | GNUNET_assert(NULL != cli_ctx); |
3401 | GNUNET_SERVICE_client_continue (cli_ctx->client); | 3413 | GNUNET_SERVICE_client_continue(cli_ctx->client); |
3402 | } | 3414 | } |
3403 | 3415 | ||
3404 | 3416 | ||
@@ -3409,25 +3421,25 @@ handle_client_stream_cancel (void *cls, | |||
3409 | * @param msg Message containing the necessary information | 3421 | * @param msg Message containing the necessary information |
3410 | */ | 3422 | */ |
3411 | static void | 3423 | static void |
3412 | handle_client_start_sub (void *cls, | 3424 | handle_client_start_sub(void *cls, |
3413 | const struct GNUNET_RPS_CS_SubStartMessage *msg) | 3425 | const struct GNUNET_RPS_CS_SubStartMessage *msg) |
3414 | { | 3426 | { |
3415 | struct ClientContext *cli_ctx = cls; | 3427 | struct ClientContext *cli_ctx = cls; |
3416 | 3428 | ||
3417 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Client requested start of a new sub.\n"); | 3429 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Client requested start of a new sub.\n"); |
3418 | if (NULL != cli_ctx->sub && | 3430 | if (NULL != cli_ctx->sub && |
3419 | 0 != memcmp (&cli_ctx->sub->hash, | 3431 | 0 != memcmp(&cli_ctx->sub->hash, |
3420 | &msg->hash, | 3432 | &msg->hash, |
3421 | sizeof (struct GNUNET_HashCode))) | 3433 | sizeof(struct GNUNET_HashCode))) |
3422 | { | 3434 | { |
3423 | LOG (GNUNET_ERROR_TYPE_WARNING, "Already have a Sub with different share for this client. Remove old one, add new.\n"); | 3435 | LOG(GNUNET_ERROR_TYPE_WARNING, "Already have a Sub with different share for this client. Remove old one, add new.\n"); |
3424 | destroy_sub (cli_ctx->sub); | 3436 | destroy_sub(cli_ctx->sub); |
3425 | cli_ctx->sub = NULL; | 3437 | cli_ctx->sub = NULL; |
3426 | } | 3438 | } |
3427 | cli_ctx->sub = new_sub (&msg->hash, | 3439 | cli_ctx->sub = new_sub(&msg->hash, |
3428 | msub->sampler_size_est_min, // TODO make api input? | 3440 | msub->sampler_size_est_min, // TODO make api input? |
3429 | GNUNET_TIME_relative_ntoh (msg->round_interval)); | 3441 | GNUNET_TIME_relative_ntoh(msg->round_interval)); |
3430 | GNUNET_SERVICE_client_continue (cli_ctx->client); | 3442 | GNUNET_SERVICE_client_continue(cli_ctx->client); |
3431 | } | 3443 | } |
3432 | 3444 | ||
3433 | 3445 | ||
@@ -3438,19 +3450,19 @@ handle_client_start_sub (void *cls, | |||
3438 | * @param msg Message containing the hash that identifies the Sub | 3450 | * @param msg Message containing the hash that identifies the Sub |
3439 | */ | 3451 | */ |
3440 | static void | 3452 | static void |
3441 | handle_client_stop_sub (void *cls, | 3453 | handle_client_stop_sub(void *cls, |
3442 | const struct GNUNET_RPS_CS_SubStopMessage *msg) | 3454 | const struct GNUNET_RPS_CS_SubStopMessage *msg) |
3443 | { | 3455 | { |
3444 | struct ClientContext *cli_ctx = cls; | 3456 | struct ClientContext *cli_ctx = cls; |
3445 | 3457 | ||
3446 | GNUNET_assert (NULL != cli_ctx->sub); | 3458 | GNUNET_assert(NULL != cli_ctx->sub); |
3447 | if (0 != memcmp (&cli_ctx->sub->hash, &msg->hash, sizeof (struct GNUNET_HashCode))) | 3459 | if (0 != memcmp(&cli_ctx->sub->hash, &msg->hash, sizeof(struct GNUNET_HashCode))) |
3448 | { | 3460 | { |
3449 | LOG (GNUNET_ERROR_TYPE_WARNING, "Share of current sub and request differ!\n"); | 3461 | LOG(GNUNET_ERROR_TYPE_WARNING, "Share of current sub and request differ!\n"); |
3450 | } | 3462 | } |
3451 | destroy_sub (cli_ctx->sub); | 3463 | destroy_sub(cli_ctx->sub); |
3452 | cli_ctx->sub = NULL; | 3464 | cli_ctx->sub = NULL; |
3453 | GNUNET_SERVICE_client_continue (cli_ctx->client); | 3465 | GNUNET_SERVICE_client_continue(cli_ctx->client); |
3454 | } | 3466 | } |
3455 | 3467 | ||
3456 | 3468 | ||
@@ -3464,24 +3476,25 @@ handle_client_stop_sub (void *cls, | |||
3464 | * @param msg Message - unused | 3476 | * @param msg Message - unused |
3465 | */ | 3477 | */ |
3466 | static void | 3478 | static void |
3467 | handle_peer_check (void *cls, | 3479 | handle_peer_check(void *cls, |
3468 | const struct GNUNET_MessageHeader *msg) | 3480 | const struct GNUNET_MessageHeader *msg) |
3469 | { | 3481 | { |
3470 | const struct ChannelCtx *channel_ctx = cls; | 3482 | const struct ChannelCtx *channel_ctx = cls; |
3471 | const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; | 3483 | const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; |
3472 | (void) msg; | ||
3473 | 3484 | ||
3474 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3485 | (void)msg; |
3475 | "Received CHECK_LIVE (%s)\n", GNUNET_i2s (peer)); | 3486 | |
3487 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
3488 | "Received CHECK_LIVE (%s)\n", GNUNET_i2s(peer)); | ||
3476 | if (channel_ctx->peer_ctx->sub == msub) | 3489 | if (channel_ctx->peer_ctx->sub == msub) |
3477 | { | 3490 | { |
3478 | GNUNET_STATISTICS_update (stats, | 3491 | GNUNET_STATISTICS_update(stats, |
3479 | "# pending online checks", | 3492 | "# pending online checks", |
3480 | -1, | 3493 | -1, |
3481 | GNUNET_NO); | 3494 | GNUNET_NO); |
3482 | } | 3495 | } |
3483 | 3496 | ||
3484 | GNUNET_CADET_receive_done (channel_ctx->channel); | 3497 | GNUNET_CADET_receive_done(channel_ctx->channel); |
3485 | } | 3498 | } |
3486 | 3499 | ||
3487 | 3500 | ||
@@ -3495,69 +3508,70 @@ handle_peer_check (void *cls, | |||
3495 | * @param msg Message - unused | 3508 | * @param msg Message - unused |
3496 | */ | 3509 | */ |
3497 | static void | 3510 | static void |
3498 | handle_peer_push (void *cls, | 3511 | handle_peer_push(void *cls, |
3499 | const struct GNUNET_MessageHeader *msg) | 3512 | const struct GNUNET_MessageHeader *msg) |
3500 | { | 3513 | { |
3501 | const struct ChannelCtx *channel_ctx = cls; | 3514 | const struct ChannelCtx *channel_ctx = cls; |
3502 | const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; | 3515 | const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; |
3503 | (void) msg; | 3516 | |
3517 | (void)msg; | ||
3504 | 3518 | ||
3505 | // (check the proof of work (?)) | 3519 | // (check the proof of work (?)) |
3506 | 3520 | ||
3507 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3521 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3508 | "Received PUSH (%s)\n", | 3522 | "Received PUSH (%s)\n", |
3509 | GNUNET_i2s (peer)); | 3523 | GNUNET_i2s(peer)); |
3510 | if (channel_ctx->peer_ctx->sub == msub) | 3524 | if (channel_ctx->peer_ctx->sub == msub) |
3511 | { | ||
3512 | GNUNET_STATISTICS_update(stats, "# push message received", 1, GNUNET_NO); | ||
3513 | if (NULL != map_single_hop && | ||
3514 | GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, | ||
3515 | peer)) | ||
3516 | { | 3525 | { |
3517 | GNUNET_STATISTICS_update (stats, | 3526 | GNUNET_STATISTICS_update(stats, "# push message received", 1, GNUNET_NO); |
3518 | "# push message received (multi-hop peer)", | 3527 | if (NULL != map_single_hop && |
3519 | 1, | 3528 | GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(map_single_hop, |
3520 | GNUNET_NO); | 3529 | peer)) |
3530 | { | ||
3531 | GNUNET_STATISTICS_update(stats, | ||
3532 | "# push message received (multi-hop peer)", | ||
3533 | 1, | ||
3534 | GNUNET_NO); | ||
3535 | } | ||
3521 | } | 3536 | } |
3522 | } | ||
3523 | 3537 | ||
3524 | #if ENABLE_MALICIOUS | 3538 | #if ENABLE_MALICIOUS |
3525 | struct AttackedPeer *tmp_att_peer; | 3539 | struct AttackedPeer *tmp_att_peer; |
3526 | 3540 | ||
3527 | if ( (1 == mal_type) || | 3541 | if ((1 == mal_type) || |
3528 | (3 == mal_type) ) | 3542 | (3 == mal_type)) |
3529 | { /* Try to maximise representation */ | 3543 | { /* Try to maximise representation */ |
3530 | tmp_att_peer = GNUNET_new (struct AttackedPeer); | 3544 | tmp_att_peer = GNUNET_new(struct AttackedPeer); |
3531 | tmp_att_peer->peer_id = *peer; | 3545 | tmp_att_peer->peer_id = *peer; |
3532 | if (NULL == att_peer_set) | 3546 | if (NULL == att_peer_set) |
3533 | att_peer_set = GNUNET_CONTAINER_multipeermap_create (1, GNUNET_NO); | 3547 | att_peer_set = GNUNET_CONTAINER_multipeermap_create(1, GNUNET_NO); |
3534 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set, | 3548 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(att_peer_set, |
3535 | peer)) | 3549 | peer)) |
3536 | { | 3550 | { |
3537 | GNUNET_CONTAINER_DLL_insert (att_peers_head, | 3551 | GNUNET_CONTAINER_DLL_insert(att_peers_head, |
3538 | att_peers_tail, | 3552 | att_peers_tail, |
3539 | tmp_att_peer); | 3553 | tmp_att_peer); |
3540 | add_peer_array_to_set (peer, 1, att_peer_set); | 3554 | add_peer_array_to_set(peer, 1, att_peer_set); |
3541 | } | 3555 | } |
3542 | else | 3556 | else |
3543 | { | 3557 | { |
3544 | GNUNET_free (tmp_att_peer); | 3558 | GNUNET_free(tmp_att_peer); |
3559 | } | ||
3545 | } | 3560 | } |
3546 | } | ||
3547 | 3561 | ||
3548 | 3562 | ||
3549 | else if (2 == mal_type) | 3563 | else if (2 == mal_type) |
3550 | { | 3564 | { |
3551 | /* We attack one single well-known peer - simply ignore */ | 3565 | /* We attack one single well-known peer - simply ignore */ |
3552 | } | 3566 | } |
3553 | #endif /* ENABLE_MALICIOUS */ | 3567 | #endif /* ENABLE_MALICIOUS */ |
3554 | 3568 | ||
3555 | /* Add the sending peer to the push_map */ | 3569 | /* Add the sending peer to the push_map */ |
3556 | CustomPeerMap_put (channel_ctx->peer_ctx->sub->push_map, peer); | 3570 | CustomPeerMap_put(channel_ctx->peer_ctx->sub->push_map, peer); |
3557 | 3571 | ||
3558 | GNUNET_break_op (check_peer_known (channel_ctx->peer_ctx->sub->peer_map, | 3572 | GNUNET_break_op(check_peer_known(channel_ctx->peer_ctx->sub->peer_map, |
3559 | &channel_ctx->peer_ctx->peer_id)); | 3573 | &channel_ctx->peer_ctx->peer_id)); |
3560 | GNUNET_CADET_receive_done (channel_ctx->channel); | 3574 | GNUNET_CADET_receive_done(channel_ctx->channel); |
3561 | } | 3575 | } |
3562 | 3576 | ||
3563 | 3577 | ||
@@ -3570,56 +3584,57 @@ handle_peer_push (void *cls, | |||
3570 | * @param msg Message - unused | 3584 | * @param msg Message - unused |
3571 | */ | 3585 | */ |
3572 | static void | 3586 | static void |
3573 | handle_peer_pull_request (void *cls, | 3587 | handle_peer_pull_request(void *cls, |
3574 | const struct GNUNET_MessageHeader *msg) | 3588 | const struct GNUNET_MessageHeader *msg) |
3575 | { | 3589 | { |
3576 | const struct ChannelCtx *channel_ctx = cls; | 3590 | const struct ChannelCtx *channel_ctx = cls; |
3577 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; | 3591 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; |
3578 | const struct GNUNET_PeerIdentity *peer = &peer_ctx->peer_id; | 3592 | const struct GNUNET_PeerIdentity *peer = &peer_ctx->peer_id; |
3579 | const struct GNUNET_PeerIdentity *view_array; | 3593 | const struct GNUNET_PeerIdentity *view_array; |
3580 | (void) msg; | ||
3581 | 3594 | ||
3582 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s (peer)); | 3595 | (void)msg; |
3596 | |||
3597 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s(peer)); | ||
3583 | if (peer_ctx->sub == msub) | 3598 | if (peer_ctx->sub == msub) |
3584 | { | ||
3585 | GNUNET_STATISTICS_update(stats, | ||
3586 | "# pull request message received", | ||
3587 | 1, | ||
3588 | GNUNET_NO); | ||
3589 | if (NULL != map_single_hop && | ||
3590 | GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, | ||
3591 | &peer_ctx->peer_id)) | ||
3592 | { | 3599 | { |
3593 | GNUNET_STATISTICS_update (stats, | 3600 | GNUNET_STATISTICS_update(stats, |
3594 | "# pull request message received (multi-hop peer)", | 3601 | "# pull request message received", |
3595 | 1, | 3602 | 1, |
3596 | GNUNET_NO); | 3603 | GNUNET_NO); |
3604 | if (NULL != map_single_hop && | ||
3605 | GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(map_single_hop, | ||
3606 | &peer_ctx->peer_id)) | ||
3607 | { | ||
3608 | GNUNET_STATISTICS_update(stats, | ||
3609 | "# pull request message received (multi-hop peer)", | ||
3610 | 1, | ||
3611 | GNUNET_NO); | ||
3612 | } | ||
3597 | } | 3613 | } |
3598 | } | ||
3599 | 3614 | ||
3600 | #if ENABLE_MALICIOUS | 3615 | #if ENABLE_MALICIOUS |
3601 | if (1 == mal_type | 3616 | if (1 == mal_type |
3602 | || 3 == mal_type) | 3617 | || 3 == mal_type) |
3603 | { /* Try to maximise representation */ | 3618 | { /* Try to maximise representation */ |
3604 | send_pull_reply (peer_ctx, mal_peers, num_mal_peers); | 3619 | send_pull_reply(peer_ctx, mal_peers, num_mal_peers); |
3605 | } | 3620 | } |
3606 | 3621 | ||
3607 | else if (2 == mal_type) | 3622 | else if (2 == mal_type) |
3608 | { /* Try to partition network */ | 3623 | { /* Try to partition network */ |
3609 | if (0 == GNUNET_memcmp (&attacked_peer, peer)) | 3624 | if (0 == GNUNET_memcmp(&attacked_peer, peer)) |
3610 | { | 3625 | { |
3611 | send_pull_reply (peer_ctx, mal_peers, num_mal_peers); | 3626 | send_pull_reply(peer_ctx, mal_peers, num_mal_peers); |
3627 | } | ||
3612 | } | 3628 | } |
3613 | } | ||
3614 | #endif /* ENABLE_MALICIOUS */ | 3629 | #endif /* ENABLE_MALICIOUS */ |
3615 | 3630 | ||
3616 | GNUNET_break_op (check_peer_known (channel_ctx->peer_ctx->sub->peer_map, | 3631 | GNUNET_break_op(check_peer_known(channel_ctx->peer_ctx->sub->peer_map, |
3617 | &channel_ctx->peer_ctx->peer_id)); | 3632 | &channel_ctx->peer_ctx->peer_id)); |
3618 | GNUNET_CADET_receive_done (channel_ctx->channel); | 3633 | GNUNET_CADET_receive_done(channel_ctx->channel); |
3619 | view_array = View_get_as_array (channel_ctx->peer_ctx->sub->view); | 3634 | view_array = View_get_as_array(channel_ctx->peer_ctx->sub->view); |
3620 | send_pull_reply (peer_ctx, | 3635 | send_pull_reply(peer_ctx, |
3621 | view_array, | 3636 | view_array, |
3622 | View_size (channel_ctx->peer_ctx->sub->view)); | 3637 | View_size(channel_ctx->peer_ctx->sub->view)); |
3623 | } | 3638 | } |
3624 | 3639 | ||
3625 | 3640 | ||
@@ -3631,45 +3646,45 @@ handle_peer_pull_request (void *cls, | |||
3631 | * @param msg Message containing the replied peers | 3646 | * @param msg Message containing the replied peers |
3632 | */ | 3647 | */ |
3633 | static int | 3648 | static int |
3634 | check_peer_pull_reply (void *cls, | 3649 | check_peer_pull_reply(void *cls, |
3635 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg) | 3650 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg) |
3636 | { | 3651 | { |
3637 | struct ChannelCtx *channel_ctx = cls; | 3652 | struct ChannelCtx *channel_ctx = cls; |
3638 | struct PeerContext *sender_ctx = channel_ctx->peer_ctx; | 3653 | struct PeerContext *sender_ctx = channel_ctx->peer_ctx; |
3639 | 3654 | ||
3640 | if (sizeof (struct GNUNET_RPS_P2P_PullReplyMessage) > ntohs (msg->header.size)) | 3655 | if (sizeof(struct GNUNET_RPS_P2P_PullReplyMessage) > ntohs(msg->header.size)) |
3641 | { | ||
3642 | GNUNET_break_op (0); | ||
3643 | return GNUNET_SYSERR; | ||
3644 | } | ||
3645 | |||
3646 | if ((ntohs (msg->header.size) - sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) / | ||
3647 | sizeof (struct GNUNET_PeerIdentity) != ntohl (msg->num_peers)) | ||
3648 | { | ||
3649 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
3650 | "message says it sends %" PRIu32 " peers, have space for %lu peers\n", | ||
3651 | ntohl (msg->num_peers), | ||
3652 | (ntohs (msg->header.size) - sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) / | ||
3653 | sizeof (struct GNUNET_PeerIdentity)); | ||
3654 | GNUNET_break_op (0); | ||
3655 | return GNUNET_SYSERR; | ||
3656 | } | ||
3657 | |||
3658 | if (GNUNET_YES != check_peer_flag (sender_ctx->sub->peer_map, | ||
3659 | &sender_ctx->peer_id, | ||
3660 | Peers_PULL_REPLY_PENDING)) | ||
3661 | { | ||
3662 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
3663 | "Received a pull reply from a peer (%s) we didn't request one from!\n", | ||
3664 | GNUNET_i2s (&sender_ctx->peer_id)); | ||
3665 | if (sender_ctx->sub == msub) | ||
3666 | { | 3656 | { |
3667 | GNUNET_STATISTICS_update (stats, | 3657 | GNUNET_break_op(0); |
3668 | "# unrequested pull replies", | 3658 | return GNUNET_SYSERR; |
3669 | 1, | 3659 | } |
3670 | GNUNET_NO); | 3660 | |
3661 | if ((ntohs(msg->header.size) - sizeof(struct GNUNET_RPS_P2P_PullReplyMessage)) / | ||
3662 | sizeof(struct GNUNET_PeerIdentity) != ntohl(msg->num_peers)) | ||
3663 | { | ||
3664 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
3665 | "message says it sends %" PRIu32 " peers, have space for %lu peers\n", | ||
3666 | ntohl(msg->num_peers), | ||
3667 | (ntohs(msg->header.size) - sizeof(struct GNUNET_RPS_P2P_PullReplyMessage)) / | ||
3668 | sizeof(struct GNUNET_PeerIdentity)); | ||
3669 | GNUNET_break_op(0); | ||
3670 | return GNUNET_SYSERR; | ||
3671 | } | ||
3672 | |||
3673 | if (GNUNET_YES != check_peer_flag(sender_ctx->sub->peer_map, | ||
3674 | &sender_ctx->peer_id, | ||
3675 | Peers_PULL_REPLY_PENDING)) | ||
3676 | { | ||
3677 | LOG(GNUNET_ERROR_TYPE_WARNING, | ||
3678 | "Received a pull reply from a peer (%s) we didn't request one from!\n", | ||
3679 | GNUNET_i2s(&sender_ctx->peer_id)); | ||
3680 | if (sender_ctx->sub == msub) | ||
3681 | { | ||
3682 | GNUNET_STATISTICS_update(stats, | ||
3683 | "# unrequested pull replies", | ||
3684 | 1, | ||
3685 | GNUNET_NO); | ||
3686 | } | ||
3671 | } | 3687 | } |
3672 | } | ||
3673 | return GNUNET_OK; | 3688 | return GNUNET_OK; |
3674 | } | 3689 | } |
3675 | 3690 | ||
@@ -3681,107 +3696,108 @@ check_peer_pull_reply (void *cls, | |||
3681 | * @param msg The message header | 3696 | * @param msg The message header |
3682 | */ | 3697 | */ |
3683 | static void | 3698 | static void |
3684 | handle_peer_pull_reply (void *cls, | 3699 | handle_peer_pull_reply(void *cls, |
3685 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg) | 3700 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg) |
3686 | { | 3701 | { |
3687 | const struct ChannelCtx *channel_ctx = cls; | 3702 | const struct ChannelCtx *channel_ctx = cls; |
3688 | const struct GNUNET_PeerIdentity *sender = &channel_ctx->peer_ctx->peer_id; | 3703 | const struct GNUNET_PeerIdentity *sender = &channel_ctx->peer_ctx->peer_id; |
3689 | const struct GNUNET_PeerIdentity *peers; | 3704 | const struct GNUNET_PeerIdentity *peers; |
3690 | struct Sub *sub = channel_ctx->peer_ctx->sub; | 3705 | struct Sub *sub = channel_ctx->peer_ctx->sub; |
3691 | uint32_t i; | 3706 | uint32_t i; |
3707 | |||
3692 | #if ENABLE_MALICIOUS | 3708 | #if ENABLE_MALICIOUS |
3693 | struct AttackedPeer *tmp_att_peer; | 3709 | struct AttackedPeer *tmp_att_peer; |
3694 | #endif /* ENABLE_MALICIOUS */ | 3710 | #endif /* ENABLE_MALICIOUS */ |
3695 | 3711 | ||
3696 | sub->pull_delays[sub->num_rounds - channel_ctx->peer_ctx->round_pull_req]++; | 3712 | sub->pull_delays[sub->num_rounds - channel_ctx->peer_ctx->round_pull_req]++; |
3697 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REPLY (%s)\n", GNUNET_i2s (sender)); | 3713 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Received PULL REPLY (%s)\n", GNUNET_i2s(sender)); |
3698 | if (channel_ctx->peer_ctx->sub == msub) | 3714 | if (channel_ctx->peer_ctx->sub == msub) |
3699 | { | ||
3700 | GNUNET_STATISTICS_update (stats, | ||
3701 | "# pull reply messages received", | ||
3702 | 1, | ||
3703 | GNUNET_NO); | ||
3704 | if (NULL != map_single_hop && | ||
3705 | GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, | ||
3706 | &channel_ctx->peer_ctx->peer_id)) | ||
3707 | { | 3715 | { |
3708 | GNUNET_STATISTICS_update (stats, | 3716 | GNUNET_STATISTICS_update(stats, |
3709 | "# pull reply messages received (multi-hop peer)", | 3717 | "# pull reply messages received", |
3710 | 1, | 3718 | 1, |
3711 | GNUNET_NO); | 3719 | GNUNET_NO); |
3720 | if (NULL != map_single_hop && | ||
3721 | GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(map_single_hop, | ||
3722 | &channel_ctx->peer_ctx->peer_id)) | ||
3723 | { | ||
3724 | GNUNET_STATISTICS_update(stats, | ||
3725 | "# pull reply messages received (multi-hop peer)", | ||
3726 | 1, | ||
3727 | GNUNET_NO); | ||
3728 | } | ||
3712 | } | 3729 | } |
3713 | } | ||
3714 | 3730 | ||
3715 | #if ENABLE_MALICIOUS | 3731 | #if ENABLE_MALICIOUS |
3716 | // We shouldn't even receive pull replies as we're not sending | 3732 | // We shouldn't even receive pull replies as we're not sending |
3717 | if (2 == mal_type) | 3733 | if (2 == mal_type) |
3718 | { | 3734 | { |
3719 | } | 3735 | } |
3720 | #endif /* ENABLE_MALICIOUS */ | 3736 | #endif /* ENABLE_MALICIOUS */ |
3721 | 3737 | ||
3722 | /* Do actual logic */ | 3738 | /* Do actual logic */ |
3723 | peers = (const struct GNUNET_PeerIdentity *) &msg[1]; | 3739 | peers = (const struct GNUNET_PeerIdentity *)&msg[1]; |
3724 | 3740 | ||
3725 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3741 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3726 | "PULL REPLY received, got following %u peers:\n", | 3742 | "PULL REPLY received, got following %u peers:\n", |
3727 | ntohl (msg->num_peers)); | 3743 | ntohl(msg->num_peers)); |
3728 | 3744 | ||
3729 | for (i = 0; i < ntohl (msg->num_peers); i++) | 3745 | for (i = 0; i < ntohl(msg->num_peers); i++) |
3730 | { | 3746 | { |
3731 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3747 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3732 | "%u. %s\n", | 3748 | "%u. %s\n", |
3733 | i, | 3749 | i, |
3734 | GNUNET_i2s (&peers[i])); | 3750 | GNUNET_i2s(&peers[i])); |
3735 | 3751 | ||
3736 | #if ENABLE_MALICIOUS | 3752 | #if ENABLE_MALICIOUS |
3737 | if ((NULL != att_peer_set) && | 3753 | if ((NULL != att_peer_set) && |
3738 | (1 == mal_type || 3 == mal_type)) | 3754 | (1 == mal_type || 3 == mal_type)) |
3739 | { /* Add attacked peer to local list */ | 3755 | { /* Add attacked peer to local list */ |
3740 | // TODO check if we sent a request and this was the first reply | 3756 | // TODO check if we sent a request and this was the first reply |
3741 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set, | 3757 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(att_peer_set, |
3742 | &peers[i]) | 3758 | &peers[i]) |
3743 | && GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mal_peer_set, | 3759 | && GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(mal_peer_set, |
3744 | &peers[i])) | 3760 | &peers[i])) |
3745 | { | 3761 | { |
3746 | tmp_att_peer = GNUNET_new (struct AttackedPeer); | 3762 | tmp_att_peer = GNUNET_new(struct AttackedPeer); |
3747 | tmp_att_peer->peer_id = peers[i]; | 3763 | tmp_att_peer->peer_id = peers[i]; |
3748 | GNUNET_CONTAINER_DLL_insert (att_peers_head, | 3764 | GNUNET_CONTAINER_DLL_insert(att_peers_head, |
3749 | att_peers_tail, | 3765 | att_peers_tail, |
3750 | tmp_att_peer); | 3766 | tmp_att_peer); |
3751 | add_peer_array_to_set (&peers[i], 1, att_peer_set); | 3767 | add_peer_array_to_set(&peers[i], 1, att_peer_set); |
3752 | } | 3768 | } |
3753 | continue; | 3769 | continue; |
3754 | } | 3770 | } |
3755 | #endif /* ENABLE_MALICIOUS */ | 3771 | #endif /* ENABLE_MALICIOUS */ |
3756 | /* Make sure we 'know' about this peer */ | 3772 | /* Make sure we 'know' about this peer */ |
3757 | (void) insert_peer (channel_ctx->peer_ctx->sub, | 3773 | (void)insert_peer(channel_ctx->peer_ctx->sub, |
3758 | &peers[i]); | 3774 | &peers[i]); |
3759 | 3775 | ||
3760 | if (GNUNET_YES == check_peer_valid (channel_ctx->peer_ctx->sub->valid_peers, | 3776 | if (GNUNET_YES == check_peer_valid(channel_ctx->peer_ctx->sub->valid_peers, |
3761 | &peers[i])) | 3777 | &peers[i])) |
3762 | { | 3778 | { |
3763 | CustomPeerMap_put (channel_ctx->peer_ctx->sub->pull_map, | 3779 | CustomPeerMap_put(channel_ctx->peer_ctx->sub->pull_map, |
3764 | &peers[i]); | 3780 | &peers[i]); |
3781 | } | ||
3782 | else | ||
3783 | { | ||
3784 | schedule_operation(channel_ctx->peer_ctx, | ||
3785 | insert_in_pull_map, | ||
3786 | channel_ctx->peer_ctx->sub); /* cls */ | ||
3787 | (void)issue_peer_online_check(channel_ctx->peer_ctx->sub, | ||
3788 | &peers[i]); | ||
3789 | } | ||
3765 | } | 3790 | } |
3766 | else | 3791 | |
3767 | { | 3792 | UNSET_PEER_FLAG(get_peer_ctx(channel_ctx->peer_ctx->sub->peer_map, |
3768 | schedule_operation (channel_ctx->peer_ctx, | 3793 | sender), |
3769 | insert_in_pull_map, | 3794 | Peers_PULL_REPLY_PENDING); |
3770 | channel_ctx->peer_ctx->sub); /* cls */ | 3795 | clean_peer(channel_ctx->peer_ctx->sub, |
3771 | (void) issue_peer_online_check (channel_ctx->peer_ctx->sub, | 3796 | sender); |
3772 | &peers[i]); | 3797 | |
3773 | } | 3798 | GNUNET_break_op(check_peer_known(channel_ctx->peer_ctx->sub->peer_map, |
3774 | } | 3799 | sender)); |
3775 | 3800 | GNUNET_CADET_receive_done(channel_ctx->channel); | |
3776 | UNSET_PEER_FLAG (get_peer_ctx (channel_ctx->peer_ctx->sub->peer_map, | ||
3777 | sender), | ||
3778 | Peers_PULL_REPLY_PENDING); | ||
3779 | clean_peer (channel_ctx->peer_ctx->sub, | ||
3780 | sender); | ||
3781 | |||
3782 | GNUNET_break_op (check_peer_known (channel_ctx->peer_ctx->sub->peer_map, | ||
3783 | sender)); | ||
3784 | GNUNET_CADET_receive_done (channel_ctx->channel); | ||
3785 | } | 3801 | } |
3786 | 3802 | ||
3787 | 3803 | ||
@@ -3796,8 +3812,8 @@ handle_peer_pull_reply (void *cls, | |||
3796 | * @param spread the inverse amount of deviation from the mean | 3812 | * @param spread the inverse amount of deviation from the mean |
3797 | */ | 3813 | */ |
3798 | static struct GNUNET_TIME_Relative | 3814 | static struct GNUNET_TIME_Relative |
3799 | compute_rand_delay (struct GNUNET_TIME_Relative mean, | 3815 | compute_rand_delay(struct GNUNET_TIME_Relative mean, |
3800 | unsigned int spread) | 3816 | unsigned int spread) |
3801 | { | 3817 | { |
3802 | struct GNUNET_TIME_Relative half_interval; | 3818 | struct GNUNET_TIME_Relative half_interval; |
3803 | struct GNUNET_TIME_Relative ret; | 3819 | struct GNUNET_TIME_Relative ret; |
@@ -3805,30 +3821,30 @@ compute_rand_delay (struct GNUNET_TIME_Relative mean, | |||
3805 | unsigned int max_rand_delay; | 3821 | unsigned int max_rand_delay; |
3806 | 3822 | ||
3807 | if (0 == spread) | 3823 | if (0 == spread) |
3808 | { | 3824 | { |
3809 | LOG (GNUNET_ERROR_TYPE_WARNING, | 3825 | LOG(GNUNET_ERROR_TYPE_WARNING, |
3810 | "Not accepting spread of 0\n"); | 3826 | "Not accepting spread of 0\n"); |
3811 | GNUNET_break (0); | 3827 | GNUNET_break(0); |
3812 | GNUNET_assert (0); | 3828 | GNUNET_assert(0); |
3813 | } | 3829 | } |
3814 | GNUNET_assert (0 != mean.rel_value_us); | 3830 | GNUNET_assert(0 != mean.rel_value_us); |
3815 | 3831 | ||
3816 | /* Compute random time value between spread * mean and spread * mean */ | 3832 | /* Compute random time value between spread * mean and spread * mean */ |
3817 | half_interval = GNUNET_TIME_relative_divide (mean, spread); | 3833 | half_interval = GNUNET_TIME_relative_divide(mean, spread); |
3818 | 3834 | ||
3819 | max_rand_delay = GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us / mean.rel_value_us * (2/spread); | 3835 | max_rand_delay = GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us / mean.rel_value_us * (2 / spread); |
3820 | /** | 3836 | /** |
3821 | * Compute random value between (0 and 1) * round_interval | 3837 | * Compute random value between (0 and 1) * round_interval |
3822 | * via multiplying round_interval with a 'fraction' (0 to value)/value | 3838 | * via multiplying round_interval with a 'fraction' (0 to value)/value |
3823 | */ | 3839 | */ |
3824 | rand_delay = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, max_rand_delay); | 3840 | rand_delay = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, max_rand_delay); |
3825 | ret = GNUNET_TIME_relative_saturating_multiply (mean, rand_delay); | 3841 | ret = GNUNET_TIME_relative_saturating_multiply(mean, rand_delay); |
3826 | ret = GNUNET_TIME_relative_divide (ret, max_rand_delay); | 3842 | ret = GNUNET_TIME_relative_divide(ret, max_rand_delay); |
3827 | ret = GNUNET_TIME_relative_add (ret, half_interval); | 3843 | ret = GNUNET_TIME_relative_add(ret, half_interval); |
3828 | 3844 | ||
3829 | if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == ret.rel_value_us) | 3845 | if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == ret.rel_value_us) |
3830 | LOG (GNUNET_ERROR_TYPE_WARNING, | 3846 | LOG(GNUNET_ERROR_TYPE_WARNING, |
3831 | "Returning FOREVER_REL\n"); | 3847 | "Returning FOREVER_REL\n"); |
3832 | 3848 | ||
3833 | return ret; | 3849 | return ret; |
3834 | } | 3850 | } |
@@ -3840,41 +3856,41 @@ compute_rand_delay (struct GNUNET_TIME_Relative mean, | |||
3840 | * @param peer_ctx Context to the peer to send request to | 3856 | * @param peer_ctx Context to the peer to send request to |
3841 | */ | 3857 | */ |
3842 | static void | 3858 | static void |
3843 | send_pull_request (struct PeerContext *peer_ctx) | 3859 | send_pull_request(struct PeerContext *peer_ctx) |
3844 | { | 3860 | { |
3845 | struct GNUNET_MQ_Envelope *ev; | 3861 | struct GNUNET_MQ_Envelope *ev; |
3846 | 3862 | ||
3847 | GNUNET_assert (GNUNET_NO == check_peer_flag (peer_ctx->sub->peer_map, | 3863 | GNUNET_assert(GNUNET_NO == check_peer_flag(peer_ctx->sub->peer_map, |
3848 | &peer_ctx->peer_id, | 3864 | &peer_ctx->peer_id, |
3849 | Peers_PULL_REPLY_PENDING)); | 3865 | Peers_PULL_REPLY_PENDING)); |
3850 | SET_PEER_FLAG (peer_ctx, | 3866 | SET_PEER_FLAG(peer_ctx, |
3851 | Peers_PULL_REPLY_PENDING); | 3867 | Peers_PULL_REPLY_PENDING); |
3852 | peer_ctx->round_pull_req = peer_ctx->sub->num_rounds; | 3868 | peer_ctx->round_pull_req = peer_ctx->sub->num_rounds; |
3853 | 3869 | ||
3854 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3870 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3855 | "Going to send PULL REQUEST to peer %s.\n", | 3871 | "Going to send PULL REQUEST to peer %s.\n", |
3856 | GNUNET_i2s (&peer_ctx->peer_id)); | 3872 | GNUNET_i2s(&peer_ctx->peer_id)); |
3857 | 3873 | ||
3858 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST); | 3874 | ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST); |
3859 | send_message (peer_ctx, | 3875 | send_message(peer_ctx, |
3860 | ev, | 3876 | ev, |
3861 | "PULL REQUEST"); | 3877 | "PULL REQUEST"); |
3862 | if (peer_ctx->sub) | 3878 | if (peer_ctx->sub) |
3863 | { | ||
3864 | GNUNET_STATISTICS_update (stats, | ||
3865 | "# pull request send issued", | ||
3866 | 1, | ||
3867 | GNUNET_NO); | ||
3868 | if (NULL != map_single_hop && | ||
3869 | GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, | ||
3870 | &peer_ctx->peer_id)) | ||
3871 | { | 3879 | { |
3872 | GNUNET_STATISTICS_update (stats, | 3880 | GNUNET_STATISTICS_update(stats, |
3873 | "# pull request send issued (multi-hop peer)", | 3881 | "# pull request send issued", |
3874 | 1, | 3882 | 1, |
3875 | GNUNET_NO); | 3883 | GNUNET_NO); |
3884 | if (NULL != map_single_hop && | ||
3885 | GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(map_single_hop, | ||
3886 | &peer_ctx->peer_id)) | ||
3887 | { | ||
3888 | GNUNET_STATISTICS_update(stats, | ||
3889 | "# pull request send issued (multi-hop peer)", | ||
3890 | 1, | ||
3891 | GNUNET_NO); | ||
3892 | } | ||
3876 | } | 3893 | } |
3877 | } | ||
3878 | } | 3894 | } |
3879 | 3895 | ||
3880 | 3896 | ||
@@ -3884,32 +3900,32 @@ send_pull_request (struct PeerContext *peer_ctx) | |||
3884 | * @param peer_ctx Context of peer to send push to | 3900 | * @param peer_ctx Context of peer to send push to |
3885 | */ | 3901 | */ |
3886 | static void | 3902 | static void |
3887 | send_push (struct PeerContext *peer_ctx) | 3903 | send_push(struct PeerContext *peer_ctx) |
3888 | { | 3904 | { |
3889 | struct GNUNET_MQ_Envelope *ev; | 3905 | struct GNUNET_MQ_Envelope *ev; |
3890 | 3906 | ||
3891 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3907 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3892 | "Going to send PUSH to peer %s.\n", | 3908 | "Going to send PUSH to peer %s.\n", |
3893 | GNUNET_i2s (&peer_ctx->peer_id)); | 3909 | GNUNET_i2s(&peer_ctx->peer_id)); |
3894 | 3910 | ||
3895 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PUSH); | 3911 | ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_RPS_PP_PUSH); |
3896 | send_message (peer_ctx, ev, "PUSH"); | 3912 | send_message(peer_ctx, ev, "PUSH"); |
3897 | if (peer_ctx->sub) | 3913 | if (peer_ctx->sub) |
3898 | { | ||
3899 | GNUNET_STATISTICS_update (stats, | ||
3900 | "# push send issued", | ||
3901 | 1, | ||
3902 | GNUNET_NO); | ||
3903 | if (NULL != map_single_hop && | ||
3904 | GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, | ||
3905 | &peer_ctx->peer_id)) | ||
3906 | { | 3914 | { |
3907 | GNUNET_STATISTICS_update (stats, | 3915 | GNUNET_STATISTICS_update(stats, |
3908 | "# push send issued (multi-hop peer)", | 3916 | "# push send issued", |
3909 | 1, | 3917 | 1, |
3910 | GNUNET_NO); | 3918 | GNUNET_NO); |
3919 | if (NULL != map_single_hop && | ||
3920 | GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(map_single_hop, | ||
3921 | &peer_ctx->peer_id)) | ||
3922 | { | ||
3923 | GNUNET_STATISTICS_update(stats, | ||
3924 | "# push send issued (multi-hop peer)", | ||
3925 | 1, | ||
3926 | GNUNET_NO); | ||
3927 | } | ||
3911 | } | 3928 | } |
3912 | } | ||
3913 | } | 3929 | } |
3914 | 3930 | ||
3915 | 3931 | ||
@@ -3925,25 +3941,25 @@ send_push (struct PeerContext *peer_ctx) | |||
3925 | * @return #GNUNET_OK if @a msg is well-formed | 3941 | * @return #GNUNET_OK if @a msg is well-formed |
3926 | */ | 3942 | */ |
3927 | static int | 3943 | static int |
3928 | check_client_act_malicious (void *cls, | 3944 | check_client_act_malicious(void *cls, |
3929 | const struct GNUNET_RPS_CS_ActMaliciousMessage *msg) | 3945 | const struct GNUNET_RPS_CS_ActMaliciousMessage *msg) |
3930 | { | 3946 | { |
3931 | struct ClientContext *cli_ctx = cls; | 3947 | struct ClientContext *cli_ctx = cls; |
3932 | uint16_t msize = ntohs (msg->header.size); | 3948 | uint16_t msize = ntohs(msg->header.size); |
3933 | uint32_t num_peers = ntohl (msg->num_peers); | 3949 | uint32_t num_peers = ntohl(msg->num_peers); |
3934 | 3950 | ||
3935 | msize -= sizeof (struct GNUNET_RPS_CS_ActMaliciousMessage); | 3951 | msize -= sizeof(struct GNUNET_RPS_CS_ActMaliciousMessage); |
3936 | if ( (msize / sizeof (struct GNUNET_PeerIdentity) != num_peers) || | 3952 | if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) || |
3937 | (msize % sizeof (struct GNUNET_PeerIdentity) != 0) ) | 3953 | (msize % sizeof(struct GNUNET_PeerIdentity) != 0)) |
3938 | { | 3954 | { |
3939 | LOG (GNUNET_ERROR_TYPE_ERROR, | 3955 | LOG(GNUNET_ERROR_TYPE_ERROR, |
3940 | "message says it sends %" PRIu32 " peers, have space for %lu peers\n", | 3956 | "message says it sends %" PRIu32 " peers, have space for %lu peers\n", |
3941 | ntohl (msg->num_peers), | 3957 | ntohl(msg->num_peers), |
3942 | (msize / sizeof (struct GNUNET_PeerIdentity))); | 3958 | (msize / sizeof(struct GNUNET_PeerIdentity))); |
3943 | GNUNET_break (0); | 3959 | GNUNET_break(0); |
3944 | GNUNET_SERVICE_client_drop (cli_ctx->client); | 3960 | GNUNET_SERVICE_client_drop(cli_ctx->client); |
3945 | return GNUNET_SYSERR; | 3961 | return GNUNET_SYSERR; |
3946 | } | 3962 | } |
3947 | return GNUNET_OK; | 3963 | return GNUNET_OK; |
3948 | } | 3964 | } |
3949 | 3965 | ||
@@ -3955,8 +3971,8 @@ check_client_act_malicious (void *cls, | |||
3955 | * @param msg The message header | 3971 | * @param msg The message header |
3956 | */ | 3972 | */ |
3957 | static void | 3973 | static void |
3958 | handle_client_act_malicious (void *cls, | 3974 | handle_client_act_malicious(void *cls, |
3959 | const struct GNUNET_RPS_CS_ActMaliciousMessage *msg) | 3975 | const struct GNUNET_RPS_CS_ActMaliciousMessage *msg) |
3960 | { | 3976 | { |
3961 | struct ClientContext *cli_ctx = cls; | 3977 | struct ClientContext *cli_ctx = cls; |
3962 | struct GNUNET_PeerIdentity *peers; | 3978 | struct GNUNET_PeerIdentity *peers; |
@@ -3964,102 +3980,103 @@ handle_client_act_malicious (void *cls, | |||
3964 | uint32_t num_mal_peers_old; | 3980 | uint32_t num_mal_peers_old; |
3965 | struct Sub *sub = cli_ctx->sub; | 3981 | struct Sub *sub = cli_ctx->sub; |
3966 | 3982 | ||
3967 | if (NULL == sub) sub = msub; | 3983 | if (NULL == sub) |
3984 | sub = msub; | ||
3968 | /* Do actual logic */ | 3985 | /* Do actual logic */ |
3969 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; | 3986 | peers = (struct GNUNET_PeerIdentity *)&msg[1]; |
3970 | mal_type = ntohl (msg->type); | 3987 | mal_type = ntohl(msg->type); |
3971 | if (NULL == mal_peer_set) | 3988 | if (NULL == mal_peer_set) |
3972 | mal_peer_set = GNUNET_CONTAINER_multipeermap_create (1, GNUNET_NO); | 3989 | mal_peer_set = GNUNET_CONTAINER_multipeermap_create(1, GNUNET_NO); |
3973 | 3990 | ||
3974 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3991 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3975 | "Now acting malicious type %" PRIu32 ", got %" PRIu32 " peers.\n", | 3992 | "Now acting malicious type %" PRIu32 ", got %" PRIu32 " peers.\n", |
3976 | mal_type, | 3993 | mal_type, |
3977 | ntohl (msg->num_peers)); | 3994 | ntohl(msg->num_peers)); |
3978 | 3995 | ||
3979 | if (1 == mal_type) | 3996 | if (1 == mal_type) |
3980 | { /* Try to maximise representation */ | 3997 | { /* Try to maximise representation */ |
3981 | /* Add other malicious peers to those we already know */ | 3998 | /* Add other malicious peers to those we already know */ |
3982 | 3999 | ||
3983 | num_mal_peers_sent = ntohl (msg->num_peers); | 4000 | num_mal_peers_sent = ntohl(msg->num_peers); |
3984 | num_mal_peers_old = num_mal_peers; | 4001 | num_mal_peers_old = num_mal_peers; |
3985 | GNUNET_array_grow (mal_peers, | 4002 | GNUNET_array_grow(mal_peers, |
3986 | num_mal_peers, | 4003 | num_mal_peers, |
3987 | num_mal_peers + num_mal_peers_sent); | 4004 | num_mal_peers + num_mal_peers_sent); |
3988 | GNUNET_memcpy (&mal_peers[num_mal_peers_old], | 4005 | GNUNET_memcpy(&mal_peers[num_mal_peers_old], |
3989 | peers, | 4006 | peers, |
3990 | num_mal_peers_sent * sizeof (struct GNUNET_PeerIdentity)); | 4007 | num_mal_peers_sent * sizeof(struct GNUNET_PeerIdentity)); |
3991 | |||
3992 | /* Add all mal peers to mal_peer_set */ | ||
3993 | add_peer_array_to_set (&mal_peers[num_mal_peers_old], | ||
3994 | num_mal_peers_sent, | ||
3995 | mal_peer_set); | ||
3996 | |||
3997 | /* Substitute do_round () with do_mal_round () */ | ||
3998 | GNUNET_assert (NULL != sub->do_round_task); | ||
3999 | GNUNET_SCHEDULER_cancel (sub->do_round_task); | ||
4000 | sub->do_round_task = GNUNET_SCHEDULER_add_now (&do_mal_round, sub); | ||
4001 | } | ||
4002 | |||
4003 | else if ( (2 == mal_type) || | ||
4004 | (3 == mal_type) ) | ||
4005 | { /* Try to partition the network */ | ||
4006 | /* Add other malicious peers to those we already know */ | ||
4007 | |||
4008 | num_mal_peers_sent = ntohl (msg->num_peers) - 1; | ||
4009 | num_mal_peers_old = num_mal_peers; | ||
4010 | GNUNET_assert (GNUNET_MAX_MALLOC_CHECKED > num_mal_peers_sent); | ||
4011 | GNUNET_array_grow (mal_peers, | ||
4012 | num_mal_peers, | ||
4013 | num_mal_peers + num_mal_peers_sent); | ||
4014 | if (NULL != mal_peers && | ||
4015 | 0 != num_mal_peers) | ||
4016 | { | ||
4017 | GNUNET_memcpy (&mal_peers[num_mal_peers_old], | ||
4018 | peers, | ||
4019 | num_mal_peers_sent * sizeof (struct GNUNET_PeerIdentity)); | ||
4020 | 4008 | ||
4021 | /* Add all mal peers to mal_peer_set */ | 4009 | /* Add all mal peers to mal_peer_set */ |
4022 | add_peer_array_to_set (&mal_peers[num_mal_peers_old], | 4010 | add_peer_array_to_set(&mal_peers[num_mal_peers_old], |
4023 | num_mal_peers_sent, | 4011 | num_mal_peers_sent, |
4024 | mal_peer_set); | 4012 | mal_peer_set); |
4013 | |||
4014 | /* Substitute do_round () with do_mal_round () */ | ||
4015 | GNUNET_assert(NULL != sub->do_round_task); | ||
4016 | GNUNET_SCHEDULER_cancel(sub->do_round_task); | ||
4017 | sub->do_round_task = GNUNET_SCHEDULER_add_now(&do_mal_round, sub); | ||
4025 | } | 4018 | } |
4026 | 4019 | ||
4027 | /* Store the one attacked peer */ | 4020 | else if ((2 == mal_type) || |
4028 | GNUNET_memcpy (&attacked_peer, | 4021 | (3 == mal_type)) |
4029 | &msg->attacked_peer, | 4022 | { /* Try to partition the network */ |
4030 | sizeof (struct GNUNET_PeerIdentity)); | 4023 | /* Add other malicious peers to those we already know */ |
4031 | /* Set the flag of the attacked peer to valid to avoid problems */ | 4024 | |
4032 | if (GNUNET_NO == check_peer_known (sub->peer_map, &attacked_peer)) | 4025 | num_mal_peers_sent = ntohl(msg->num_peers) - 1; |
4033 | { | 4026 | num_mal_peers_old = num_mal_peers; |
4034 | (void) issue_peer_online_check (sub, &attacked_peer); | 4027 | GNUNET_assert(GNUNET_MAX_MALLOC_CHECKED > num_mal_peers_sent); |
4035 | } | 4028 | GNUNET_array_grow(mal_peers, |
4029 | num_mal_peers, | ||
4030 | num_mal_peers + num_mal_peers_sent); | ||
4031 | if (NULL != mal_peers && | ||
4032 | 0 != num_mal_peers) | ||
4033 | { | ||
4034 | GNUNET_memcpy(&mal_peers[num_mal_peers_old], | ||
4035 | peers, | ||
4036 | num_mal_peers_sent * sizeof(struct GNUNET_PeerIdentity)); | ||
4037 | |||
4038 | /* Add all mal peers to mal_peer_set */ | ||
4039 | add_peer_array_to_set(&mal_peers[num_mal_peers_old], | ||
4040 | num_mal_peers_sent, | ||
4041 | mal_peer_set); | ||
4042 | } | ||
4036 | 4043 | ||
4037 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 4044 | /* Store the one attacked peer */ |
4038 | "Attacked peer is %s\n", | 4045 | GNUNET_memcpy(&attacked_peer, |
4039 | GNUNET_i2s (&attacked_peer)); | 4046 | &msg->attacked_peer, |
4047 | sizeof(struct GNUNET_PeerIdentity)); | ||
4048 | /* Set the flag of the attacked peer to valid to avoid problems */ | ||
4049 | if (GNUNET_NO == check_peer_known(sub->peer_map, &attacked_peer)) | ||
4050 | { | ||
4051 | (void)issue_peer_online_check(sub, &attacked_peer); | ||
4052 | } | ||
4040 | 4053 | ||
4041 | /* Substitute do_round () with do_mal_round () */ | 4054 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
4042 | if (NULL != sub->do_round_task) | 4055 | "Attacked peer is %s\n", |
4043 | { | 4056 | GNUNET_i2s(&attacked_peer)); |
4044 | /* Probably in shutdown */ | 4057 | |
4045 | GNUNET_SCHEDULER_cancel (sub->do_round_task); | 4058 | /* Substitute do_round () with do_mal_round () */ |
4046 | sub->do_round_task = GNUNET_SCHEDULER_add_now (&do_mal_round, sub); | 4059 | if (NULL != sub->do_round_task) |
4060 | { | ||
4061 | /* Probably in shutdown */ | ||
4062 | GNUNET_SCHEDULER_cancel(sub->do_round_task); | ||
4063 | sub->do_round_task = GNUNET_SCHEDULER_add_now(&do_mal_round, sub); | ||
4064 | } | ||
4047 | } | 4065 | } |
4048 | } | ||
4049 | else if (0 == mal_type) | 4066 | else if (0 == mal_type) |
4050 | { /* Stop acting malicious */ | 4067 | { /* Stop acting malicious */ |
4051 | GNUNET_array_grow (mal_peers, num_mal_peers, 0); | 4068 | GNUNET_array_grow(mal_peers, num_mal_peers, 0); |
4052 | 4069 | ||
4053 | /* Substitute do_mal_round () with do_round () */ | 4070 | /* Substitute do_mal_round () with do_round () */ |
4054 | GNUNET_SCHEDULER_cancel (sub->do_round_task); | 4071 | GNUNET_SCHEDULER_cancel(sub->do_round_task); |
4055 | sub->do_round_task = GNUNET_SCHEDULER_add_now (&do_round, sub); | 4072 | sub->do_round_task = GNUNET_SCHEDULER_add_now(&do_round, sub); |
4056 | } | 4073 | } |
4057 | else | 4074 | else |
4058 | { | 4075 | { |
4059 | GNUNET_break (0); | 4076 | GNUNET_break(0); |
4060 | GNUNET_SERVICE_client_continue (cli_ctx->client); | 4077 | GNUNET_SERVICE_client_continue(cli_ctx->client); |
4061 | } | 4078 | } |
4062 | GNUNET_SERVICE_client_continue (cli_ctx->client); | 4079 | GNUNET_SERVICE_client_continue(cli_ctx->client); |
4063 | } | 4080 | } |
4064 | 4081 | ||
4065 | 4082 | ||
@@ -4071,7 +4088,7 @@ handle_client_act_malicious (void *cls, | |||
4071 | * @param cls Closure - Sub | 4088 | * @param cls Closure - Sub |
4072 | */ | 4089 | */ |
4073 | static void | 4090 | static void |
4074 | do_mal_round (void *cls) | 4091 | do_mal_round(void *cls) |
4075 | { | 4092 | { |
4076 | uint32_t num_pushes; | 4093 | uint32_t num_pushes; |
4077 | uint32_t i; | 4094 | uint32_t i; |
@@ -4079,121 +4096,119 @@ do_mal_round (void *cls) | |||
4079 | struct AttackedPeer *tmp_att_peer; | 4096 | struct AttackedPeer *tmp_att_peer; |
4080 | struct Sub *sub = cls; | 4097 | struct Sub *sub = cls; |
4081 | 4098 | ||
4082 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 4099 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
4083 | "Going to execute next round maliciously type %" PRIu32 ".\n", | 4100 | "Going to execute next round maliciously type %" PRIu32 ".\n", |
4084 | mal_type); | 4101 | mal_type); |
4085 | sub->do_round_task = NULL; | 4102 | sub->do_round_task = NULL; |
4086 | GNUNET_assert (mal_type <= 3); | 4103 | GNUNET_assert(mal_type <= 3); |
4087 | /* Do malicious actions */ | 4104 | /* Do malicious actions */ |
4088 | if (1 == mal_type) | 4105 | if (1 == mal_type) |
4089 | { /* Try to maximise representation */ | 4106 | { /* Try to maximise representation */ |
4090 | 4107 | /* The maximum of pushes we're going to send this round */ | |
4091 | /* The maximum of pushes we're going to send this round */ | 4108 | num_pushes = GNUNET_MIN(GNUNET_MIN(push_limit, |
4092 | num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit, | ||
4093 | num_attacked_peers), | 4109 | num_attacked_peers), |
4094 | GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE); | 4110 | GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE); |
4095 | 4111 | ||
4096 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 4112 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
4097 | "Going to send %" PRIu32 " pushes\n", | 4113 | "Going to send %" PRIu32 " pushes\n", |
4098 | num_pushes); | 4114 | num_pushes); |
4099 | 4115 | ||
4100 | /* Send PUSHes to attacked peers */ | 4116 | /* Send PUSHes to attacked peers */ |
4101 | for (i = 0 ; i < num_pushes ; i++) | 4117 | for (i = 0; i < num_pushes; i++) |
4102 | { | 4118 | { |
4103 | if (att_peers_tail == att_peer_index) | 4119 | if (att_peers_tail == att_peer_index) |
4104 | att_peer_index = att_peers_head; | 4120 | att_peer_index = att_peers_head; |
4105 | else | 4121 | else |
4106 | att_peer_index = att_peer_index->next; | 4122 | att_peer_index = att_peer_index->next; |
4107 | 4123 | ||
4108 | send_push (get_peer_ctx (sub->peer_map, &att_peer_index->peer_id)); | 4124 | send_push(get_peer_ctx(sub->peer_map, &att_peer_index->peer_id)); |
4109 | } | 4125 | } |
4110 | 4126 | ||
4111 | /* Send PULLs to some peers to learn about additional peers to attack */ | 4127 | /* Send PULLs to some peers to learn about additional peers to attack */ |
4112 | tmp_att_peer = att_peer_index; | 4128 | tmp_att_peer = att_peer_index; |
4113 | for (i = 0 ; i < num_pushes * alpha ; i++) | 4129 | for (i = 0; i < num_pushes * alpha; i++) |
4114 | { | 4130 | { |
4115 | if (att_peers_tail == tmp_att_peer) | 4131 | if (att_peers_tail == tmp_att_peer) |
4116 | tmp_att_peer = att_peers_head; | 4132 | tmp_att_peer = att_peers_head; |
4117 | else | 4133 | else |
4118 | att_peer_index = tmp_att_peer->next; | 4134 | att_peer_index = tmp_att_peer->next; |
4119 | 4135 | ||
4120 | send_pull_request (get_peer_ctx (sub->peer_map, &tmp_att_peer->peer_id)); | 4136 | send_pull_request(get_peer_ctx(sub->peer_map, &tmp_att_peer->peer_id)); |
4137 | } | ||
4121 | } | 4138 | } |
4122 | } | ||
4123 | 4139 | ||
4124 | 4140 | ||
4125 | else if (2 == mal_type) | 4141 | else if (2 == mal_type) |
4126 | { /** | 4142 | { /** |
4127 | * Try to partition the network | 4143 | * Try to partition the network |
4128 | * Send as many pushes to the attacked peer as possible | 4144 | * Send as many pushes to the attacked peer as possible |
4129 | * That is one push per round as it will ignore more. | 4145 | * That is one push per round as it will ignore more. |
4130 | */ | 4146 | */ |
4131 | (void) issue_peer_online_check (sub, &attacked_peer); | 4147 | (void)issue_peer_online_check(sub, &attacked_peer); |
4132 | if (GNUNET_YES == check_peer_flag (sub->peer_map, | 4148 | if (GNUNET_YES == check_peer_flag(sub->peer_map, |
4133 | &attacked_peer, | 4149 | &attacked_peer, |
4134 | Peers_ONLINE)) | 4150 | Peers_ONLINE)) |
4135 | send_push (get_peer_ctx (sub->peer_map, &attacked_peer)); | 4151 | send_push(get_peer_ctx(sub->peer_map, &attacked_peer)); |
4136 | } | 4152 | } |
4137 | 4153 | ||
4138 | 4154 | ||
4139 | if (3 == mal_type) | 4155 | if (3 == mal_type) |
4140 | { /* Combined attack */ | 4156 | { /* Combined attack */ |
4157 | /* Send PUSH to attacked peers */ | ||
4158 | if (GNUNET_YES == check_peer_known(sub->peer_map, &attacked_peer)) | ||
4159 | { | ||
4160 | (void)issue_peer_online_check(sub, &attacked_peer); | ||
4161 | if (GNUNET_YES == check_peer_flag(sub->peer_map, | ||
4162 | &attacked_peer, | ||
4163 | Peers_ONLINE)) | ||
4164 | { | ||
4165 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
4166 | "Goding to send push to attacked peer (%s)\n", | ||
4167 | GNUNET_i2s(&attacked_peer)); | ||
4168 | send_push(get_peer_ctx(sub->peer_map, &attacked_peer)); | ||
4169 | } | ||
4170 | } | ||
4171 | (void)issue_peer_online_check(sub, &attacked_peer); | ||
4141 | 4172 | ||
4142 | /* Send PUSH to attacked peers */ | 4173 | /* The maximum of pushes we're going to send this round */ |
4143 | if (GNUNET_YES == check_peer_known (sub->peer_map, &attacked_peer)) | 4174 | num_pushes = GNUNET_MIN(GNUNET_MIN(push_limit - 1, |
4144 | { | ||
4145 | (void) issue_peer_online_check (sub, &attacked_peer); | ||
4146 | if (GNUNET_YES == check_peer_flag (sub->peer_map, | ||
4147 | &attacked_peer, | ||
4148 | Peers_ONLINE)) | ||
4149 | { | ||
4150 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
4151 | "Goding to send push to attacked peer (%s)\n", | ||
4152 | GNUNET_i2s (&attacked_peer)); | ||
4153 | send_push (get_peer_ctx (sub->peer_map, &attacked_peer)); | ||
4154 | } | ||
4155 | } | ||
4156 | (void) issue_peer_online_check (sub, &attacked_peer); | ||
4157 | |||
4158 | /* The maximum of pushes we're going to send this round */ | ||
4159 | num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit - 1, | ||
4160 | num_attacked_peers), | 4175 | num_attacked_peers), |
4161 | GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE); | 4176 | GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE); |
4162 | 4177 | ||
4163 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 4178 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
4164 | "Going to send %" PRIu32 " pushes\n", | 4179 | "Going to send %" PRIu32 " pushes\n", |
4165 | num_pushes); | 4180 | num_pushes); |
4166 | 4181 | ||
4167 | for (i = 0; i < num_pushes; i++) | 4182 | for (i = 0; i < num_pushes; i++) |
4168 | { | 4183 | { |
4169 | if (att_peers_tail == att_peer_index) | 4184 | if (att_peers_tail == att_peer_index) |
4170 | att_peer_index = att_peers_head; | 4185 | att_peer_index = att_peers_head; |
4171 | else | 4186 | else |
4172 | att_peer_index = att_peer_index->next; | 4187 | att_peer_index = att_peer_index->next; |
4173 | 4188 | ||
4174 | send_push (get_peer_ctx (sub->peer_map, &att_peer_index->peer_id)); | 4189 | send_push(get_peer_ctx(sub->peer_map, &att_peer_index->peer_id)); |
4175 | } | 4190 | } |
4176 | 4191 | ||
4177 | /* Send PULLs to some peers to learn about additional peers to attack */ | 4192 | /* Send PULLs to some peers to learn about additional peers to attack */ |
4178 | tmp_att_peer = att_peer_index; | 4193 | tmp_att_peer = att_peer_index; |
4179 | for (i = 0; i < num_pushes * alpha; i++) | 4194 | for (i = 0; i < num_pushes * alpha; i++) |
4180 | { | 4195 | { |
4181 | if (att_peers_tail == tmp_att_peer) | 4196 | if (att_peers_tail == tmp_att_peer) |
4182 | tmp_att_peer = att_peers_head; | 4197 | tmp_att_peer = att_peers_head; |
4183 | else | 4198 | else |
4184 | att_peer_index = tmp_att_peer->next; | 4199 | att_peer_index = tmp_att_peer->next; |
4185 | 4200 | ||
4186 | send_pull_request (get_peer_ctx (sub->peer_map, &tmp_att_peer->peer_id)); | 4201 | send_pull_request(get_peer_ctx(sub->peer_map, &tmp_att_peer->peer_id)); |
4202 | } | ||
4187 | } | 4203 | } |
4188 | } | ||
4189 | 4204 | ||
4190 | /* Schedule next round */ | 4205 | /* Schedule next round */ |
4191 | time_next_round = compute_rand_delay (sub->round_interval, 2); | 4206 | time_next_round = compute_rand_delay(sub->round_interval, 2); |
4192 | 4207 | ||
4193 | GNUNET_assert (NULL == sub->do_round_task); | 4208 | GNUNET_assert(NULL == sub->do_round_task); |
4194 | sub->do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round, | 4209 | sub->do_round_task = GNUNET_SCHEDULER_add_delayed(time_next_round, |
4195 | &do_mal_round, sub); | 4210 | &do_mal_round, sub); |
4196 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n"); | 4211 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Finished round\n"); |
4197 | } | 4212 | } |
4198 | #endif /* ENABLE_MALICIOUS */ | 4213 | #endif /* ENABLE_MALICIOUS */ |
4199 | 4214 | ||
@@ -4206,7 +4221,7 @@ do_mal_round (void *cls) | |||
4206 | * @param cls Closure - Sub | 4221 | * @param cls Closure - Sub |
4207 | */ | 4222 | */ |
4208 | static void | 4223 | static void |
4209 | do_round (void *cls) | 4224 | do_round(void *cls) |
4210 | { | 4225 | { |
4211 | unsigned int i; | 4226 | unsigned int i; |
4212 | const struct GNUNET_PeerIdentity *view_array; | 4227 | const struct GNUNET_PeerIdentity *view_array; |
@@ -4220,306 +4235,308 @@ do_round (void *cls) | |||
4220 | struct Sub *sub = cls; | 4235 | struct Sub *sub = cls; |
4221 | 4236 | ||
4222 | sub->num_rounds++; | 4237 | sub->num_rounds++; |
4223 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 4238 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
4224 | "Going to execute next round.\n"); | 4239 | "Going to execute next round.\n"); |
4225 | if (sub == msub) | 4240 | if (sub == msub) |
4226 | { | 4241 | { |
4227 | GNUNET_STATISTICS_update (stats, "# rounds", 1, GNUNET_NO); | 4242 | GNUNET_STATISTICS_update(stats, "# rounds", 1, GNUNET_NO); |
4228 | } | 4243 | } |
4229 | sub->do_round_task = NULL; | 4244 | sub->do_round_task = NULL; |
4230 | #ifdef TO_FILE_FULL | 4245 | #ifdef TO_FILE_FULL |
4231 | to_file (sub->file_name_view_log, | 4246 | to_file(sub->file_name_view_log, |
4232 | "___ new round ___"); | 4247 | "___ new round ___"); |
4233 | #endif /* TO_FILE_FULL */ | 4248 | #endif /* TO_FILE_FULL */ |
4234 | view_array = View_get_as_array (sub->view); | 4249 | view_array = View_get_as_array(sub->view); |
4235 | for (i = 0; i < View_size (sub->view); i++) | 4250 | for (i = 0; i < View_size(sub->view); i++) |
4236 | { | 4251 | { |
4237 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 4252 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
4238 | "\t%s\n", GNUNET_i2s (&view_array[i])); | 4253 | "\t%s\n", GNUNET_i2s(&view_array[i])); |
4239 | #ifdef TO_FILE_FULL | 4254 | #ifdef TO_FILE_FULL |
4240 | to_file (sub->file_name_view_log, | 4255 | to_file(sub->file_name_view_log, |
4241 | "=%s\t(do round)", | 4256 | "=%s\t(do round)", |
4242 | GNUNET_i2s_full (&view_array[i])); | 4257 | GNUNET_i2s_full(&view_array[i])); |
4243 | #endif /* TO_FILE_FULL */ | 4258 | #endif /* TO_FILE_FULL */ |
4244 | } | 4259 | } |
4245 | 4260 | ||
4246 | 4261 | ||
4247 | /* Send pushes and pull requests */ | 4262 | /* Send pushes and pull requests */ |
4248 | if (0 < View_size (sub->view)) | 4263 | if (0 < View_size(sub->view)) |
4249 | { | ||
4250 | permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG, | ||
4251 | View_size (sub->view)); | ||
4252 | |||
4253 | /* Send PUSHes */ | ||
4254 | a_peers = ceil (alpha * View_size (sub->view)); | ||
4255 | |||
4256 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
4257 | "Going to send pushes to %u (ceil (%f * %u)) peers.\n", | ||
4258 | a_peers, alpha, View_size (sub->view)); | ||
4259 | for (i = 0; i < a_peers; i++) | ||
4260 | { | 4264 | { |
4261 | peer = view_array[permut[i]]; | 4265 | permut = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_STRONG, |
4262 | // FIXME if this fails schedule/loop this for later | 4266 | View_size(sub->view)); |
4263 | send_push (get_peer_ctx (sub->peer_map, &peer)); | ||
4264 | } | ||
4265 | 4267 | ||
4266 | /* Send PULL requests */ | 4268 | /* Send PUSHes */ |
4267 | b_peers = ceil (beta * View_size (sub->view)); | 4269 | a_peers = ceil(alpha * View_size(sub->view)); |
4268 | first_border = a_peers; | 4270 | |
4269 | second_border = a_peers + b_peers; | 4271 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
4270 | if (second_border > View_size (sub->view)) | 4272 | "Going to send pushes to %u (ceil (%f * %u)) peers.\n", |
4271 | { | 4273 | a_peers, alpha, View_size(sub->view)); |
4272 | first_border = View_size (sub->view) - b_peers; | 4274 | for (i = 0; i < a_peers; i++) |
4273 | second_border = View_size (sub->view); | 4275 | { |
4274 | } | 4276 | peer = view_array[permut[i]]; |
4275 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 4277 | // FIXME if this fails schedule/loop this for later |
4276 | "Going to send pulls to %u (ceil (%f * %u)) peers.\n", | 4278 | send_push(get_peer_ctx(sub->peer_map, &peer)); |
4277 | b_peers, beta, View_size (sub->view)); | 4279 | } |
4278 | for (i = first_border; i < second_border; i++) | 4280 | |
4279 | { | 4281 | /* Send PULL requests */ |
4280 | peer = view_array[permut[i]]; | 4282 | b_peers = ceil(beta * View_size(sub->view)); |
4281 | if ( GNUNET_NO == check_peer_flag (sub->peer_map, | 4283 | first_border = a_peers; |
4282 | &peer, | 4284 | second_border = a_peers + b_peers; |
4283 | Peers_PULL_REPLY_PENDING)) | 4285 | if (second_border > View_size(sub->view)) |
4284 | { // FIXME if this fails schedule/loop this for later | 4286 | { |
4285 | send_pull_request (get_peer_ctx (sub->peer_map, &peer)); | 4287 | first_border = View_size(sub->view) - b_peers; |
4286 | } | 4288 | second_border = View_size(sub->view); |
4287 | } | 4289 | } |
4290 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
4291 | "Going to send pulls to %u (ceil (%f * %u)) peers.\n", | ||
4292 | b_peers, beta, View_size(sub->view)); | ||
4293 | for (i = first_border; i < second_border; i++) | ||
4294 | { | ||
4295 | peer = view_array[permut[i]]; | ||
4296 | if (GNUNET_NO == check_peer_flag(sub->peer_map, | ||
4297 | &peer, | ||
4298 | Peers_PULL_REPLY_PENDING)) | ||
4299 | { // FIXME if this fails schedule/loop this for later | ||
4300 | send_pull_request(get_peer_ctx(sub->peer_map, &peer)); | ||
4301 | } | ||
4302 | } | ||
4288 | 4303 | ||
4289 | GNUNET_free (permut); | 4304 | GNUNET_free(permut); |
4290 | permut = NULL; | 4305 | permut = NULL; |
4291 | } | 4306 | } |
4292 | 4307 | ||
4293 | 4308 | ||
4294 | /* Update view */ | 4309 | /* Update view */ |
4295 | /* TODO see how many peers are in push-/pull- list! */ | 4310 | /* TODO see how many peers are in push-/pull- list! */ |
4296 | 4311 | ||
4297 | if ((CustomPeerMap_size (sub->push_map) <= alpha * sub->view_size_est_need) && | 4312 | if ((CustomPeerMap_size(sub->push_map) <= alpha * sub->view_size_est_need) && |
4298 | (0 < CustomPeerMap_size (sub->push_map)) && | 4313 | (0 < CustomPeerMap_size(sub->push_map)) && |
4299 | (0 < CustomPeerMap_size (sub->pull_map))) | 4314 | (0 < CustomPeerMap_size(sub->pull_map))) |
4300 | { /* If conditions for update are fulfilled, update */ | 4315 | { /* If conditions for update are fulfilled, update */ |
4301 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Update of the view.\n"); | 4316 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Update of the view.\n"); |
4302 | 4317 | ||
4303 | uint32_t final_size; | 4318 | uint32_t final_size; |
4304 | uint32_t peers_to_clean_size; | 4319 | uint32_t peers_to_clean_size; |
4305 | struct GNUNET_PeerIdentity *peers_to_clean; | 4320 | struct GNUNET_PeerIdentity *peers_to_clean; |
4306 | 4321 | ||
4307 | peers_to_clean = NULL; | 4322 | peers_to_clean = NULL; |
4308 | peers_to_clean_size = 0; | 4323 | peers_to_clean_size = 0; |
4309 | GNUNET_array_grow (peers_to_clean, | 4324 | GNUNET_array_grow(peers_to_clean, |
4310 | peers_to_clean_size, | 4325 | peers_to_clean_size, |
4311 | View_size (sub->view)); | 4326 | View_size(sub->view)); |
4312 | GNUNET_memcpy (peers_to_clean, | 4327 | GNUNET_memcpy(peers_to_clean, |
4313 | view_array, | 4328 | view_array, |
4314 | View_size (sub->view) * sizeof (struct GNUNET_PeerIdentity)); | 4329 | View_size(sub->view) * sizeof(struct GNUNET_PeerIdentity)); |
4315 | 4330 | ||
4316 | /* Seems like recreating is the easiest way of emptying the peermap */ | 4331 | /* Seems like recreating is the easiest way of emptying the peermap */ |
4317 | View_clear (sub->view); | 4332 | View_clear(sub->view); |
4318 | #ifdef TO_FILE_FULL | 4333 | #ifdef TO_FILE_FULL |
4319 | to_file (sub->file_name_view_log, | 4334 | to_file(sub->file_name_view_log, |
4320 | "--- emptied ---"); | 4335 | "--- emptied ---"); |
4321 | #endif /* TO_FILE_FULL */ | 4336 | #endif /* TO_FILE_FULL */ |
4322 | 4337 | ||
4323 | first_border = GNUNET_MIN (ceil (alpha * sub->view_size_est_need), | 4338 | first_border = GNUNET_MIN(ceil(alpha * sub->view_size_est_need), |
4324 | CustomPeerMap_size (sub->push_map)); | 4339 | CustomPeerMap_size(sub->push_map)); |
4325 | second_border = first_border + | 4340 | second_border = first_border + |
4326 | GNUNET_MIN (floor (beta * sub->view_size_est_need), | 4341 | GNUNET_MIN(floor(beta * sub->view_size_est_need), |
4327 | CustomPeerMap_size (sub->pull_map)); | 4342 | CustomPeerMap_size(sub->pull_map)); |
4328 | final_size = second_border + | 4343 | final_size = second_border + |
4329 | ceil ((1 - (alpha + beta)) * sub->view_size_est_need); | 4344 | ceil((1 - (alpha + beta)) * sub->view_size_est_need); |
4330 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 4345 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
4331 | "first border: %" PRIu32 ", second border: %" PRIu32 ", final size: %"PRIu32 "\n", | 4346 | "first border: %" PRIu32 ", second border: %" PRIu32 ", final size: %" PRIu32 "\n", |
4332 | first_border, | 4347 | first_border, |
4333 | second_border, | 4348 | second_border, |
4334 | final_size); | 4349 | final_size); |
4335 | 4350 | ||
4336 | /* Update view with peers received through PUSHes */ | 4351 | /* Update view with peers received through PUSHes */ |
4337 | permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG, | 4352 | permut = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_STRONG, |
4338 | CustomPeerMap_size (sub->push_map)); | 4353 | CustomPeerMap_size(sub->push_map)); |
4339 | for (i = 0; i < first_border; i++) | 4354 | for (i = 0; i < first_border; i++) |
4340 | { | 4355 | { |
4341 | int inserted; | 4356 | int inserted; |
4342 | inserted = insert_in_view (sub, | 4357 | inserted = insert_in_view(sub, |
4343 | CustomPeerMap_get_peer_by_index (sub->push_map, | 4358 | CustomPeerMap_get_peer_by_index(sub->push_map, |
4344 | permut[i])); | 4359 | permut[i])); |
4345 | if (GNUNET_OK == inserted) | 4360 | if (GNUNET_OK == inserted) |
4346 | { | 4361 | { |
4347 | clients_notify_stream_peer (sub, | 4362 | clients_notify_stream_peer(sub, |
4348 | 1, | 4363 | 1, |
4349 | CustomPeerMap_get_peer_by_index (sub->push_map, permut[i])); | 4364 | CustomPeerMap_get_peer_by_index(sub->push_map, permut[i])); |
4350 | } | 4365 | } |
4351 | #ifdef TO_FILE_FULL | 4366 | #ifdef TO_FILE_FULL |
4352 | to_file (sub->file_name_view_log, | 4367 | to_file(sub->file_name_view_log, |
4353 | "+%s\t(push list)", | 4368 | "+%s\t(push list)", |
4354 | GNUNET_i2s_full (&view_array[i])); | 4369 | GNUNET_i2s_full(&view_array[i])); |
4355 | #endif /* TO_FILE_FULL */ | 4370 | #endif /* TO_FILE_FULL */ |
4356 | // TODO change the peer_flags accordingly | 4371 | // TODO change the peer_flags accordingly |
4357 | } | 4372 | } |
4358 | GNUNET_free (permut); | 4373 | GNUNET_free(permut); |
4359 | permut = NULL; | 4374 | permut = NULL; |
4360 | 4375 | ||
4361 | /* Update view with peers received through PULLs */ | 4376 | /* Update view with peers received through PULLs */ |
4362 | permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG, | 4377 | permut = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_STRONG, |
4363 | CustomPeerMap_size (sub->pull_map)); | 4378 | CustomPeerMap_size(sub->pull_map)); |
4364 | for (i = first_border; i < second_border; i++) | 4379 | for (i = first_border; i < second_border; i++) |
4365 | { | 4380 | { |
4366 | int inserted; | 4381 | int inserted; |
4367 | inserted = insert_in_view (sub, | 4382 | inserted = insert_in_view(sub, |
4368 | CustomPeerMap_get_peer_by_index (sub->pull_map, | 4383 | CustomPeerMap_get_peer_by_index(sub->pull_map, |
4369 | permut[i - first_border])); | 4384 | permut[i - first_border])); |
4370 | if (GNUNET_OK == inserted) | 4385 | if (GNUNET_OK == inserted) |
4371 | { | 4386 | { |
4372 | clients_notify_stream_peer (sub, | 4387 | clients_notify_stream_peer(sub, |
4373 | 1, | 4388 | 1, |
4374 | CustomPeerMap_get_peer_by_index (sub->pull_map, | 4389 | CustomPeerMap_get_peer_by_index(sub->pull_map, |
4375 | permut[i - first_border])); | 4390 | permut[i - first_border])); |
4376 | } | 4391 | } |
4377 | #ifdef TO_FILE_FULL | 4392 | #ifdef TO_FILE_FULL |
4378 | to_file (sub->file_name_view_log, | 4393 | to_file(sub->file_name_view_log, |
4379 | "+%s\t(pull list)", | 4394 | "+%s\t(pull list)", |
4380 | GNUNET_i2s_full (&view_array[i])); | 4395 | GNUNET_i2s_full(&view_array[i])); |
4381 | #endif /* TO_FILE_FULL */ | 4396 | #endif /* TO_FILE_FULL */ |
4397 | // TODO change the peer_flags accordingly | ||
4398 | } | ||
4399 | GNUNET_free(permut); | ||
4400 | permut = NULL; | ||
4401 | |||
4402 | /* Update view with peers from history */ | ||
4403 | RPS_sampler_get_n_rand_peers(sub->sampler, | ||
4404 | final_size - second_border, | ||
4405 | hist_update, | ||
4406 | sub); | ||
4382 | // TODO change the peer_flags accordingly | 4407 | // TODO change the peer_flags accordingly |
4383 | } | ||
4384 | GNUNET_free (permut); | ||
4385 | permut = NULL; | ||
4386 | 4408 | ||
4387 | /* Update view with peers from history */ | 4409 | for (i = 0; i < View_size(sub->view); i++) |
4388 | RPS_sampler_get_n_rand_peers (sub->sampler, | 4410 | rem_from_list(&peers_to_clean, &peers_to_clean_size, &view_array[i]); |
4389 | final_size - second_border, | ||
4390 | hist_update, | ||
4391 | sub); | ||
4392 | // TODO change the peer_flags accordingly | ||
4393 | 4411 | ||
4394 | for (i = 0; i < View_size (sub->view); i++) | 4412 | /* Clean peers that were removed from the view */ |
4395 | rem_from_list (&peers_to_clean, &peers_to_clean_size, &view_array[i]); | 4413 | for (i = 0; i < peers_to_clean_size; i++) |
4396 | 4414 | { | |
4397 | /* Clean peers that were removed from the view */ | ||
4398 | for (i = 0; i < peers_to_clean_size; i++) | ||
4399 | { | ||
4400 | #ifdef TO_FILE_FULL | 4415 | #ifdef TO_FILE_FULL |
4401 | to_file (sub->file_name_view_log, | 4416 | to_file(sub->file_name_view_log, |
4402 | "-%s", | 4417 | "-%s", |
4403 | GNUNET_i2s_full (&peers_to_clean[i])); | 4418 | GNUNET_i2s_full(&peers_to_clean[i])); |
4404 | #endif /* TO_FILE_FULL */ | 4419 | #endif /* TO_FILE_FULL */ |
4405 | clean_peer (sub, &peers_to_clean[i]); | 4420 | clean_peer(sub, &peers_to_clean[i]); |
4406 | } | 4421 | } |
4407 | 4422 | ||
4408 | GNUNET_array_grow (peers_to_clean, peers_to_clean_size, 0); | 4423 | GNUNET_array_grow(peers_to_clean, peers_to_clean_size, 0); |
4409 | clients_notify_view_update (sub); | 4424 | clients_notify_view_update(sub); |
4410 | } else { | 4425 | } |
4411 | LOG (GNUNET_ERROR_TYPE_DEBUG, "No update of the view.\n"); | 4426 | else |
4412 | if (sub == msub) | ||
4413 | { | 4427 | { |
4414 | GNUNET_STATISTICS_update(stats, "# rounds blocked", 1, GNUNET_NO); | 4428 | LOG(GNUNET_ERROR_TYPE_DEBUG, "No update of the view.\n"); |
4415 | if (CustomPeerMap_size (sub->push_map) > alpha * sub->view_size_est_need && | 4429 | if (sub == msub) |
4416 | !(0 >= CustomPeerMap_size (sub->pull_map))) | 4430 | { |
4417 | GNUNET_STATISTICS_update(stats, "# rounds blocked - too many pushes", 1, GNUNET_NO); | 4431 | GNUNET_STATISTICS_update(stats, "# rounds blocked", 1, GNUNET_NO); |
4418 | if (CustomPeerMap_size (sub->push_map) > alpha * sub->view_size_est_need && | 4432 | if (CustomPeerMap_size(sub->push_map) > alpha * sub->view_size_est_need && |
4419 | (0 >= CustomPeerMap_size (sub->pull_map))) | 4433 | !(0 >= CustomPeerMap_size(sub->pull_map))) |
4420 | GNUNET_STATISTICS_update(stats, "# rounds blocked - too many pushes, no pull replies", 1, GNUNET_NO); | 4434 | GNUNET_STATISTICS_update(stats, "# rounds blocked - too many pushes", 1, GNUNET_NO); |
4421 | if (0 >= CustomPeerMap_size (sub->push_map) && | 4435 | if (CustomPeerMap_size(sub->push_map) > alpha * sub->view_size_est_need && |
4422 | !(0 >= CustomPeerMap_size (sub->pull_map))) | 4436 | (0 >= CustomPeerMap_size(sub->pull_map))) |
4423 | GNUNET_STATISTICS_update(stats, "# rounds blocked - no pushes", 1, GNUNET_NO); | 4437 | GNUNET_STATISTICS_update(stats, "# rounds blocked - too many pushes, no pull replies", 1, GNUNET_NO); |
4424 | if (0 >= CustomPeerMap_size (sub->push_map) && | 4438 | if (0 >= CustomPeerMap_size(sub->push_map) && |
4425 | (0 >= CustomPeerMap_size (sub->pull_map))) | 4439 | !(0 >= CustomPeerMap_size(sub->pull_map))) |
4426 | GNUNET_STATISTICS_update(stats, "# rounds blocked - no pushes, no pull replies", 1, GNUNET_NO); | 4440 | GNUNET_STATISTICS_update(stats, "# rounds blocked - no pushes", 1, GNUNET_NO); |
4427 | if (0 >= CustomPeerMap_size (sub->pull_map) && | 4441 | if (0 >= CustomPeerMap_size(sub->push_map) && |
4428 | CustomPeerMap_size (sub->push_map) > alpha * sub->view_size_est_need && | 4442 | (0 >= CustomPeerMap_size(sub->pull_map))) |
4429 | 0 >= CustomPeerMap_size (sub->push_map)) | 4443 | GNUNET_STATISTICS_update(stats, "# rounds blocked - no pushes, no pull replies", 1, GNUNET_NO); |
4430 | GNUNET_STATISTICS_update(stats, "# rounds blocked - no pull replies", 1, GNUNET_NO); | 4444 | if (0 >= CustomPeerMap_size(sub->pull_map) && |
4431 | } | 4445 | CustomPeerMap_size(sub->push_map) > alpha * sub->view_size_est_need && |
4432 | } | 4446 | 0 >= CustomPeerMap_size(sub->push_map)) |
4447 | GNUNET_STATISTICS_update(stats, "# rounds blocked - no pull replies", 1, GNUNET_NO); | ||
4448 | } | ||
4449 | } | ||
4433 | // TODO independent of that also get some peers from CADET_get_peers()? | 4450 | // TODO independent of that also get some peers from CADET_get_peers()? |
4434 | if (CustomPeerMap_size (sub->push_map) < HISTOGRAM_FILE_SLOTS) | 4451 | if (CustomPeerMap_size(sub->push_map) < HISTOGRAM_FILE_SLOTS) |
4435 | { | 4452 | { |
4436 | sub->push_recv[CustomPeerMap_size (sub->push_map)]++; | 4453 | sub->push_recv[CustomPeerMap_size(sub->push_map)]++; |
4437 | } | 4454 | } |
4438 | else | 4455 | else |
4439 | { | 4456 | { |
4440 | LOG (GNUNET_ERROR_TYPE_WARNING, | 4457 | LOG(GNUNET_ERROR_TYPE_WARNING, |
4441 | "Push map size too big for histogram (%u, %u)\n", | 4458 | "Push map size too big for histogram (%u, %u)\n", |
4442 | CustomPeerMap_size (sub->push_map), | 4459 | CustomPeerMap_size(sub->push_map), |
4443 | HISTOGRAM_FILE_SLOTS); | 4460 | HISTOGRAM_FILE_SLOTS); |
4444 | } | 4461 | } |
4445 | // FIXME check bounds of histogram | 4462 | // FIXME check bounds of histogram |
4446 | sub->push_delta[(int32_t) (CustomPeerMap_size (sub->push_map) - | 4463 | sub->push_delta[(int32_t)(CustomPeerMap_size(sub->push_map) - |
4447 | (alpha * sub->view_size_est_need)) + | 4464 | (alpha * sub->view_size_est_need)) + |
4448 | (HISTOGRAM_FILE_SLOTS/2)]++; | 4465 | (HISTOGRAM_FILE_SLOTS / 2)]++; |
4449 | if (sub == msub) | 4466 | if (sub == msub) |
4450 | { | 4467 | { |
4451 | GNUNET_STATISTICS_set (stats, | 4468 | GNUNET_STATISTICS_set(stats, |
4452 | "# peers in push map at end of round", | 4469 | "# peers in push map at end of round", |
4453 | CustomPeerMap_size (sub->push_map), | 4470 | CustomPeerMap_size(sub->push_map), |
4454 | GNUNET_NO); | 4471 | GNUNET_NO); |
4455 | GNUNET_STATISTICS_set (stats, | 4472 | GNUNET_STATISTICS_set(stats, |
4456 | "# peers in pull map at end of round", | 4473 | "# peers in pull map at end of round", |
4457 | CustomPeerMap_size (sub->pull_map), | 4474 | CustomPeerMap_size(sub->pull_map), |
4458 | GNUNET_NO); | 4475 | GNUNET_NO); |
4459 | GNUNET_STATISTICS_set (stats, | 4476 | GNUNET_STATISTICS_set(stats, |
4460 | "# peers in view at end of round", | 4477 | "# peers in view at end of round", |
4461 | View_size (sub->view), | 4478 | View_size(sub->view), |
4462 | GNUNET_NO); | 4479 | GNUNET_NO); |
4463 | GNUNET_STATISTICS_set (stats, | 4480 | GNUNET_STATISTICS_set(stats, |
4464 | "# expected pushes", | 4481 | "# expected pushes", |
4465 | alpha * sub->view_size_est_need, | 4482 | alpha * sub->view_size_est_need, |
4466 | GNUNET_NO); | 4483 | GNUNET_NO); |
4467 | GNUNET_STATISTICS_set (stats, | 4484 | GNUNET_STATISTICS_set(stats, |
4468 | "delta expected - received pushes", | 4485 | "delta expected - received pushes", |
4469 | CustomPeerMap_size (sub->push_map) - (alpha * sub->view_size_est_need), | 4486 | CustomPeerMap_size(sub->push_map) - (alpha * sub->view_size_est_need), |
4470 | GNUNET_NO); | 4487 | GNUNET_NO); |
4471 | } | 4488 | } |
4472 | 4489 | ||
4473 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 4490 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
4474 | "Received %u pushes and %u pulls last round (alpha (%.2f) * view_size (sub->view%u) = %.2f)\n", | 4491 | "Received %u pushes and %u pulls last round (alpha (%.2f) * view_size (sub->view%u) = %.2f)\n", |
4475 | CustomPeerMap_size (sub->push_map), | 4492 | CustomPeerMap_size(sub->push_map), |
4476 | CustomPeerMap_size (sub->pull_map), | 4493 | CustomPeerMap_size(sub->pull_map), |
4477 | alpha, | 4494 | alpha, |
4478 | View_size (sub->view), | 4495 | View_size(sub->view), |
4479 | alpha * View_size (sub->view)); | 4496 | alpha * View_size(sub->view)); |
4480 | 4497 | ||
4481 | /* Update samplers */ | 4498 | /* Update samplers */ |
4482 | for (i = 0; i < CustomPeerMap_size (sub->push_map); i++) | 4499 | for (i = 0; i < CustomPeerMap_size(sub->push_map); i++) |
4483 | { | 4500 | { |
4484 | update_peer = CustomPeerMap_get_peer_by_index (sub->push_map, i); | 4501 | update_peer = CustomPeerMap_get_peer_by_index(sub->push_map, i); |
4485 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 4502 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
4486 | "Updating with peer %s from push list\n", | 4503 | "Updating with peer %s from push list\n", |
4487 | GNUNET_i2s (update_peer)); | 4504 | GNUNET_i2s(update_peer)); |
4488 | insert_in_sampler (sub, update_peer); | 4505 | insert_in_sampler(sub, update_peer); |
4489 | clean_peer (sub, update_peer); /* This cleans only if it is not in the view */ | 4506 | clean_peer(sub, update_peer); /* This cleans only if it is not in the view */ |
4490 | } | 4507 | } |
4491 | 4508 | ||
4492 | for (i = 0; i < CustomPeerMap_size (sub->pull_map); i++) | 4509 | for (i = 0; i < CustomPeerMap_size(sub->pull_map); i++) |
4493 | { | 4510 | { |
4494 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 4511 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
4495 | "Updating with peer %s from pull list\n", | 4512 | "Updating with peer %s from pull list\n", |
4496 | GNUNET_i2s (CustomPeerMap_get_peer_by_index (sub->pull_map, i))); | 4513 | GNUNET_i2s(CustomPeerMap_get_peer_by_index(sub->pull_map, i))); |
4497 | insert_in_sampler (sub, CustomPeerMap_get_peer_by_index (sub->pull_map, i)); | 4514 | insert_in_sampler(sub, CustomPeerMap_get_peer_by_index(sub->pull_map, i)); |
4498 | /* This cleans only if it is not in the view */ | 4515 | /* This cleans only if it is not in the view */ |
4499 | clean_peer (sub, CustomPeerMap_get_peer_by_index (sub->pull_map, i)); | 4516 | clean_peer(sub, CustomPeerMap_get_peer_by_index(sub->pull_map, i)); |
4500 | } | 4517 | } |
4501 | 4518 | ||
4502 | 4519 | ||
4503 | /* Empty push/pull lists */ | 4520 | /* Empty push/pull lists */ |
4504 | CustomPeerMap_clear (sub->push_map); | 4521 | CustomPeerMap_clear(sub->push_map); |
4505 | CustomPeerMap_clear (sub->pull_map); | 4522 | CustomPeerMap_clear(sub->pull_map); |
4506 | 4523 | ||
4507 | if (sub == msub) | 4524 | if (sub == msub) |
4508 | { | 4525 | { |
4509 | GNUNET_STATISTICS_set (stats, | 4526 | GNUNET_STATISTICS_set(stats, |
4510 | "view size", | 4527 | "view size", |
4511 | View_size(sub->view), | 4528 | View_size(sub->view), |
4512 | GNUNET_NO); | 4529 | GNUNET_NO); |
4513 | } | 4530 | } |
4514 | 4531 | ||
4515 | struct GNUNET_TIME_Relative time_next_round; | 4532 | struct GNUNET_TIME_Relative time_next_round; |
4516 | 4533 | ||
4517 | time_next_round = compute_rand_delay (sub->round_interval, 2); | 4534 | time_next_round = compute_rand_delay(sub->round_interval, 2); |
4518 | 4535 | ||
4519 | /* Schedule next round */ | 4536 | /* Schedule next round */ |
4520 | sub->do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round, | 4537 | sub->do_round_task = GNUNET_SCHEDULER_add_delayed(time_next_round, |
4521 | &do_round, sub); | 4538 | &do_round, sub); |
4522 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n"); | 4539 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Finished round\n"); |
4523 | } | 4540 | } |
4524 | 4541 | ||
4525 | 4542 | ||
@@ -4539,25 +4556,26 @@ do_round (void *cls) | |||
4539 | * (0 = unknown, 1 = ourselves, 2 = neighbor) | 4556 | * (0 = unknown, 1 = ourselves, 2 = neighbor) |
4540 | */ | 4557 | */ |
4541 | void | 4558 | void |
4542 | init_peer_cb (void *cls, | 4559 | init_peer_cb(void *cls, |
4543 | const struct GNUNET_PeerIdentity *peer, | 4560 | const struct GNUNET_PeerIdentity *peer, |
4544 | int tunnel, /* "Do we have a tunnel towards this peer?" */ | 4561 | int tunnel, /* "Do we have a tunnel towards this peer?" */ |
4545 | unsigned int n_paths, /* "Number of known paths towards this peer" */ | 4562 | unsigned int n_paths, /* "Number of known paths towards this peer" */ |
4546 | unsigned int best_path) /* "How long is the best path? | 4563 | unsigned int best_path) /* "How long is the best path? |
4547 | * (0 = unknown, 1 = ourselves, 2 = neighbor)" */ | 4564 | * (0 = unknown, 1 = ourselves, 2 = neighbor)" */ |
4548 | { | 4565 | { |
4549 | struct Sub *sub = cls; | 4566 | struct Sub *sub = cls; |
4550 | (void) tunnel; | 4567 | |
4551 | (void) n_paths; | 4568 | (void)tunnel; |
4552 | (void) best_path; | 4569 | (void)n_paths; |
4570 | (void)best_path; | ||
4553 | 4571 | ||
4554 | if (NULL != peer) | 4572 | if (NULL != peer) |
4555 | { | 4573 | { |
4556 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 4574 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
4557 | "Got peer_id %s from cadet\n", | 4575 | "Got peer_id %s from cadet\n", |
4558 | GNUNET_i2s (peer)); | 4576 | GNUNET_i2s(peer)); |
4559 | got_peer (sub, peer); | 4577 | got_peer(sub, peer); |
4560 | } | 4578 | } |
4561 | } | 4579 | } |
4562 | 4580 | ||
4563 | 4581 | ||
@@ -4573,18 +4591,18 @@ init_peer_cb (void *cls, | |||
4573 | * #GNUNET_NO if not. | 4591 | * #GNUNET_NO if not. |
4574 | */ | 4592 | */ |
4575 | static int | 4593 | static int |
4576 | valid_peers_iterator (void *cls, | 4594 | valid_peers_iterator(void *cls, |
4577 | const struct GNUNET_PeerIdentity *peer) | 4595 | const struct GNUNET_PeerIdentity *peer) |
4578 | { | 4596 | { |
4579 | struct Sub *sub = cls; | 4597 | struct Sub *sub = cls; |
4580 | 4598 | ||
4581 | if (NULL != peer) | 4599 | if (NULL != peer) |
4582 | { | 4600 | { |
4583 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 4601 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
4584 | "Got stored, valid peer %s\n", | 4602 | "Got stored, valid peer %s\n", |
4585 | GNUNET_i2s (peer)); | 4603 | GNUNET_i2s(peer)); |
4586 | got_peer (sub, peer); | 4604 | got_peer(sub, peer); |
4587 | } | 4605 | } |
4588 | return GNUNET_YES; | 4606 | return GNUNET_YES; |
4589 | } | 4607 | } |
4590 | 4608 | ||
@@ -4598,22 +4616,23 @@ valid_peers_iterator (void *cls, | |||
4598 | * @param error message | 4616 | * @param error message |
4599 | */ | 4617 | */ |
4600 | void | 4618 | void |
4601 | process_peerinfo_peers (void *cls, | 4619 | process_peerinfo_peers(void *cls, |
4602 | const struct GNUNET_PeerIdentity *peer, | 4620 | const struct GNUNET_PeerIdentity *peer, |
4603 | const struct GNUNET_HELLO_Message *hello, | 4621 | const struct GNUNET_HELLO_Message *hello, |
4604 | const char *err_msg) | 4622 | const char *err_msg) |
4605 | { | 4623 | { |
4606 | struct Sub *sub = cls; | 4624 | struct Sub *sub = cls; |
4607 | (void) hello; | 4625 | |
4608 | (void) err_msg; | 4626 | (void)hello; |
4627 | (void)err_msg; | ||
4609 | 4628 | ||
4610 | if (NULL != peer) | 4629 | if (NULL != peer) |
4611 | { | 4630 | { |
4612 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 4631 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
4613 | "Got peer_id %s from peerinfo\n", | 4632 | "Got peer_id %s from peerinfo\n", |
4614 | GNUNET_i2s (peer)); | 4633 | GNUNET_i2s(peer)); |
4615 | got_peer (sub, peer); | 4634 | got_peer(sub, peer); |
4616 | } | 4635 | } |
4617 | } | 4636 | } |
4618 | 4637 | ||
4619 | 4638 | ||
@@ -4623,67 +4642,67 @@ process_peerinfo_peers (void *cls, | |||
4623 | * @param cls Closure - unused | 4642 | * @param cls Closure - unused |
4624 | */ | 4643 | */ |
4625 | static void | 4644 | static void |
4626 | shutdown_task (void *cls) | 4645 | shutdown_task(void *cls) |
4627 | { | 4646 | { |
4628 | (void) cls; | 4647 | (void)cls; |
4629 | struct ClientContext *client_ctx; | 4648 | struct ClientContext *client_ctx; |
4630 | 4649 | ||
4631 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 4650 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
4632 | "RPS service is going down\n"); | 4651 | "RPS service is going down\n"); |
4633 | 4652 | ||
4634 | /* Clean all clients */ | 4653 | /* Clean all clients */ |
4635 | for (client_ctx = cli_ctx_head; | 4654 | for (client_ctx = cli_ctx_head; |
4636 | NULL != cli_ctx_head; | 4655 | NULL != cli_ctx_head; |
4637 | client_ctx = cli_ctx_head) | 4656 | client_ctx = cli_ctx_head) |
4638 | { | 4657 | { |
4639 | destroy_cli_ctx (client_ctx); | 4658 | destroy_cli_ctx(client_ctx); |
4640 | } | 4659 | } |
4641 | if (NULL != msub) | 4660 | if (NULL != msub) |
4642 | { | 4661 | { |
4643 | destroy_sub (msub); | 4662 | destroy_sub(msub); |
4644 | msub = NULL; | 4663 | msub = NULL; |
4645 | } | 4664 | } |
4646 | 4665 | ||
4647 | /* Disconnect from other services */ | 4666 | /* Disconnect from other services */ |
4648 | GNUNET_PEERINFO_notify_cancel (peerinfo_notify_handle); | 4667 | GNUNET_PEERINFO_notify_cancel(peerinfo_notify_handle); |
4649 | GNUNET_PEERINFO_disconnect (peerinfo_handle); | 4668 | GNUNET_PEERINFO_disconnect(peerinfo_handle); |
4650 | peerinfo_handle = NULL; | 4669 | peerinfo_handle = NULL; |
4651 | GNUNET_NSE_disconnect (nse); | 4670 | GNUNET_NSE_disconnect(nse); |
4652 | if (NULL != map_single_hop) | 4671 | if (NULL != map_single_hop) |
4653 | { | 4672 | { |
4654 | /* core_init was called - core was initialised */ | 4673 | /* core_init was called - core was initialised */ |
4655 | /* disconnect first, so no callback tries to access missing peermap */ | 4674 | /* disconnect first, so no callback tries to access missing peermap */ |
4656 | GNUNET_CORE_disconnect (core_handle); | 4675 | GNUNET_CORE_disconnect(core_handle); |
4657 | core_handle = NULL; | 4676 | core_handle = NULL; |
4658 | GNUNET_CONTAINER_multipeermap_destroy (map_single_hop); | 4677 | GNUNET_CONTAINER_multipeermap_destroy(map_single_hop); |
4659 | map_single_hop = NULL; | 4678 | map_single_hop = NULL; |
4660 | } | 4679 | } |
4661 | 4680 | ||
4662 | if (NULL != stats) | 4681 | if (NULL != stats) |
4663 | { | 4682 | { |
4664 | GNUNET_STATISTICS_destroy (stats, | 4683 | GNUNET_STATISTICS_destroy(stats, |
4665 | GNUNET_NO); | 4684 | GNUNET_NO); |
4666 | stats = NULL; | 4685 | stats = NULL; |
4667 | } | 4686 | } |
4668 | GNUNET_CADET_disconnect (cadet_handle); | 4687 | GNUNET_CADET_disconnect(cadet_handle); |
4669 | cadet_handle = NULL; | 4688 | cadet_handle = NULL; |
4670 | #if ENABLE_MALICIOUS | 4689 | #if ENABLE_MALICIOUS |
4671 | struct AttackedPeer *tmp_att_peer; | 4690 | struct AttackedPeer *tmp_att_peer; |
4672 | GNUNET_array_grow (mal_peers, | 4691 | GNUNET_array_grow(mal_peers, |
4673 | num_mal_peers, | 4692 | num_mal_peers, |
4674 | 0); | 4693 | 0); |
4675 | if (NULL != mal_peer_set) | 4694 | if (NULL != mal_peer_set) |
4676 | GNUNET_CONTAINER_multipeermap_destroy (mal_peer_set); | 4695 | GNUNET_CONTAINER_multipeermap_destroy(mal_peer_set); |
4677 | if (NULL != att_peer_set) | 4696 | if (NULL != att_peer_set) |
4678 | GNUNET_CONTAINER_multipeermap_destroy (att_peer_set); | 4697 | GNUNET_CONTAINER_multipeermap_destroy(att_peer_set); |
4679 | while (NULL != att_peers_head) | 4698 | while (NULL != att_peers_head) |
4680 | { | 4699 | { |
4681 | tmp_att_peer = att_peers_head; | 4700 | tmp_att_peer = att_peers_head; |
4682 | GNUNET_CONTAINER_DLL_remove (att_peers_head, | 4701 | GNUNET_CONTAINER_DLL_remove(att_peers_head, |
4683 | att_peers_tail, | 4702 | att_peers_tail, |
4684 | tmp_att_peer); | 4703 | tmp_att_peer); |
4685 | GNUNET_free (tmp_att_peer); | 4704 | GNUNET_free(tmp_att_peer); |
4686 | } | 4705 | } |
4687 | #endif /* ENABLE_MALICIOUS */ | 4706 | #endif /* ENABLE_MALICIOUS */ |
4688 | close_all_files(); | 4707 | close_all_files(); |
4689 | } | 4708 | } |
@@ -4698,25 +4717,26 @@ shutdown_task (void *cls) | |||
4698 | * @return @a client | 4717 | * @return @a client |
4699 | */ | 4718 | */ |
4700 | static void * | 4719 | static void * |
4701 | client_connect_cb (void *cls, | 4720 | client_connect_cb(void *cls, |
4702 | struct GNUNET_SERVICE_Client *client, | 4721 | struct GNUNET_SERVICE_Client *client, |
4703 | struct GNUNET_MQ_Handle *mq) | 4722 | struct GNUNET_MQ_Handle *mq) |
4704 | { | 4723 | { |
4705 | struct ClientContext *cli_ctx; | 4724 | struct ClientContext *cli_ctx; |
4706 | (void) cls; | ||
4707 | 4725 | ||
4708 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 4726 | (void)cls; |
4709 | "Client connected\n"); | 4727 | |
4728 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
4729 | "Client connected\n"); | ||
4710 | if (NULL == client) | 4730 | if (NULL == client) |
4711 | return client; /* Server was destroyed before a client connected. Shutting down */ | 4731 | return client; /* Server was destroyed before a client connected. Shutting down */ |
4712 | cli_ctx = GNUNET_new (struct ClientContext); | 4732 | cli_ctx = GNUNET_new(struct ClientContext); |
4713 | cli_ctx->mq = mq; | 4733 | cli_ctx->mq = mq; |
4714 | cli_ctx->view_updates_left = -1; | 4734 | cli_ctx->view_updates_left = -1; |
4715 | cli_ctx->stream_update = GNUNET_NO; | 4735 | cli_ctx->stream_update = GNUNET_NO; |
4716 | cli_ctx->client = client; | 4736 | cli_ctx->client = client; |
4717 | GNUNET_CONTAINER_DLL_insert (cli_ctx_head, | 4737 | GNUNET_CONTAINER_DLL_insert(cli_ctx_head, |
4718 | cli_ctx_tail, | 4738 | cli_ctx_tail, |
4719 | cli_ctx); | 4739 | cli_ctx); |
4720 | return cli_ctx; | 4740 | return cli_ctx; |
4721 | } | 4741 | } |
4722 | 4742 | ||
@@ -4728,25 +4748,25 @@ client_connect_cb (void *cls, | |||
4728 | * @param internal_cls should be equal to @a c | 4748 | * @param internal_cls should be equal to @a c |
4729 | */ | 4749 | */ |
4730 | static void | 4750 | static void |
4731 | client_disconnect_cb (void *cls, | 4751 | client_disconnect_cb(void *cls, |
4732 | struct GNUNET_SERVICE_Client *client, | 4752 | struct GNUNET_SERVICE_Client *client, |
4733 | void *internal_cls) | 4753 | void *internal_cls) |
4734 | { | 4754 | { |
4735 | struct ClientContext *cli_ctx = internal_cls; | 4755 | struct ClientContext *cli_ctx = internal_cls; |
4736 | 4756 | ||
4737 | (void) cls; | 4757 | (void)cls; |
4738 | GNUNET_assert (client == cli_ctx->client); | 4758 | GNUNET_assert(client == cli_ctx->client); |
4739 | if (NULL == client) | 4759 | if (NULL == client) |
4740 | {/* shutdown task - destroy all clients */ | 4760 | {/* shutdown task - destroy all clients */ |
4741 | while (NULL != cli_ctx_head) | 4761 | while (NULL != cli_ctx_head) |
4742 | destroy_cli_ctx (cli_ctx_head); | 4762 | destroy_cli_ctx(cli_ctx_head); |
4743 | } | 4763 | } |
4744 | else | 4764 | else |
4745 | { /* destroy this client */ | 4765 | { /* destroy this client */ |
4746 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 4766 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
4747 | "Client disconnected. Destroy its context.\n"); | 4767 | "Client disconnected. Destroy its context.\n"); |
4748 | destroy_cli_ctx (cli_ctx); | 4768 | destroy_cli_ctx(cli_ctx); |
4749 | } | 4769 | } |
4750 | } | 4770 | } |
4751 | 4771 | ||
4752 | 4772 | ||
@@ -4758,104 +4778,104 @@ client_disconnect_cb (void *cls, | |||
4758 | * @param service the initialized service | 4778 | * @param service the initialized service |
4759 | */ | 4779 | */ |
4760 | static void | 4780 | static void |
4761 | run (void *cls, | 4781 | run(void *cls, |
4762 | const struct GNUNET_CONFIGURATION_Handle *c, | 4782 | const struct GNUNET_CONFIGURATION_Handle *c, |
4763 | struct GNUNET_SERVICE_Handle *service) | 4783 | struct GNUNET_SERVICE_Handle *service) |
4764 | { | 4784 | { |
4765 | struct GNUNET_TIME_Relative round_interval; | 4785 | struct GNUNET_TIME_Relative round_interval; |
4766 | long long unsigned int sampler_size; | 4786 | long long unsigned int sampler_size; |
4767 | char hash_port_string[] = GNUNET_APPLICATION_PORT_RPS; | 4787 | char hash_port_string[] = GNUNET_APPLICATION_PORT_RPS; |
4768 | struct GNUNET_HashCode hash; | 4788 | struct GNUNET_HashCode hash; |
4769 | 4789 | ||
4770 | (void) cls; | 4790 | (void)cls; |
4771 | (void) service; | 4791 | (void)service; |
4772 | 4792 | ||
4773 | GNUNET_log_setup ("rps", | 4793 | GNUNET_log_setup("rps", |
4774 | GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_DEBUG), | 4794 | GNUNET_error_type_to_string(GNUNET_ERROR_TYPE_DEBUG), |
4775 | NULL); | 4795 | NULL); |
4776 | cfg = c; | 4796 | cfg = c; |
4777 | /* Get own ID */ | 4797 | /* Get own ID */ |
4778 | GNUNET_CRYPTO_get_peer_identity (cfg, | 4798 | GNUNET_CRYPTO_get_peer_identity(cfg, |
4779 | &own_identity); // TODO check return value | 4799 | &own_identity); // TODO check return value |
4780 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 4800 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
4781 | "STARTING SERVICE (rps) for peer [%s]\n", | 4801 | "STARTING SERVICE (rps) for peer [%s]\n", |
4782 | GNUNET_i2s (&own_identity)); | 4802 | GNUNET_i2s(&own_identity)); |
4783 | #if ENABLE_MALICIOUS | 4803 | #if ENABLE_MALICIOUS |
4784 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 4804 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
4785 | "Malicious execution compiled in.\n"); | 4805 | "Malicious execution compiled in.\n"); |
4786 | #endif /* ENABLE_MALICIOUS */ | 4806 | #endif /* ENABLE_MALICIOUS */ |
4787 | 4807 | ||
4788 | /* Get time interval from the configuration */ | 4808 | /* Get time interval from the configuration */ |
4789 | if (GNUNET_OK != | 4809 | if (GNUNET_OK != |
4790 | GNUNET_CONFIGURATION_get_value_time (cfg, | 4810 | GNUNET_CONFIGURATION_get_value_time(cfg, |
4791 | "RPS", | 4811 | "RPS", |
4792 | "ROUNDINTERVAL", | 4812 | "ROUNDINTERVAL", |
4793 | &round_interval)) | 4813 | &round_interval)) |
4794 | { | 4814 | { |
4795 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 4815 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
4796 | "RPS", "ROUNDINTERVAL"); | 4816 | "RPS", "ROUNDINTERVAL"); |
4797 | GNUNET_SCHEDULER_shutdown (); | 4817 | GNUNET_SCHEDULER_shutdown(); |
4798 | return; | 4818 | return; |
4799 | } | 4819 | } |
4800 | 4820 | ||
4801 | /* Get initial size of sampler/view from the configuration */ | 4821 | /* Get initial size of sampler/view from the configuration */ |
4802 | if (GNUNET_OK != | 4822 | if (GNUNET_OK != |
4803 | GNUNET_CONFIGURATION_get_value_number (cfg, | 4823 | GNUNET_CONFIGURATION_get_value_number(cfg, |
4804 | "RPS", | 4824 | "RPS", |
4805 | "MINSIZE", | 4825 | "MINSIZE", |
4806 | &sampler_size)) | 4826 | &sampler_size)) |
4807 | { | 4827 | { |
4808 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 4828 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
4809 | "RPS", "MINSIZE"); | 4829 | "RPS", "MINSIZE"); |
4810 | GNUNET_SCHEDULER_shutdown (); | 4830 | GNUNET_SCHEDULER_shutdown(); |
4811 | return; | 4831 | return; |
4812 | } | 4832 | } |
4813 | 4833 | ||
4814 | cadet_handle = GNUNET_CADET_connect (cfg); | 4834 | cadet_handle = GNUNET_CADET_connect(cfg); |
4815 | GNUNET_assert (NULL != cadet_handle); | 4835 | GNUNET_assert(NULL != cadet_handle); |
4816 | core_handle = GNUNET_CORE_connect (cfg, | 4836 | core_handle = GNUNET_CORE_connect(cfg, |
4817 | NULL, /* cls */ | 4837 | NULL, /* cls */ |
4818 | core_init, /* init */ | 4838 | core_init, /* init */ |
4819 | core_connects, /* connects */ | 4839 | core_connects, /* connects */ |
4820 | core_disconnects, /* disconnects */ | 4840 | core_disconnects, /* disconnects */ |
4821 | NULL); /* handlers */ | 4841 | NULL); /* handlers */ |
4822 | GNUNET_assert (NULL != core_handle); | 4842 | GNUNET_assert(NULL != core_handle); |
4823 | 4843 | ||
4824 | 4844 | ||
4825 | alpha = 0.45; | 4845 | alpha = 0.45; |
4826 | beta = 0.45; | 4846 | beta = 0.45; |
4827 | 4847 | ||
4828 | 4848 | ||
4829 | /* Set up main Sub */ | 4849 | /* Set up main Sub */ |
4830 | GNUNET_CRYPTO_hash (hash_port_string, | 4850 | GNUNET_CRYPTO_hash(hash_port_string, |
4831 | strlen (hash_port_string), | 4851 | strlen(hash_port_string), |
4832 | &hash); | 4852 | &hash); |
4833 | msub = new_sub (&hash, | 4853 | msub = new_sub(&hash, |
4834 | sampler_size, /* Will be overwritten by config */ | 4854 | sampler_size, /* Will be overwritten by config */ |
4835 | round_interval); | 4855 | round_interval); |
4836 | 4856 | ||
4837 | 4857 | ||
4838 | peerinfo_handle = GNUNET_PEERINFO_connect (cfg); | 4858 | peerinfo_handle = GNUNET_PEERINFO_connect(cfg); |
4839 | 4859 | ||
4840 | /* connect to NSE */ | 4860 | /* connect to NSE */ |
4841 | nse = GNUNET_NSE_connect (cfg, nse_callback, NULL); | 4861 | nse = GNUNET_NSE_connect(cfg, nse_callback, NULL); |
4842 | 4862 | ||
4843 | //LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting peers from CADET\n"); | 4863 | //LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting peers from CADET\n"); |
4844 | //GNUNET_CADET_get_peers (cadet_handle, &init_peer_cb, msub); | 4864 | //GNUNET_CADET_get_peers (cadet_handle, &init_peer_cb, msub); |
4845 | // TODO send push/pull to each of those peers? | 4865 | // TODO send push/pull to each of those peers? |
4846 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n"); | 4866 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n"); |
4847 | restore_valid_peers (msub); | 4867 | restore_valid_peers(msub); |
4848 | get_valid_peers (msub->valid_peers, valid_peers_iterator, msub); | 4868 | get_valid_peers(msub->valid_peers, valid_peers_iterator, msub); |
4849 | 4869 | ||
4850 | peerinfo_notify_handle = GNUNET_PEERINFO_notify (cfg, | 4870 | peerinfo_notify_handle = GNUNET_PEERINFO_notify(cfg, |
4851 | GNUNET_NO, | 4871 | GNUNET_NO, |
4852 | process_peerinfo_peers, | 4872 | process_peerinfo_peers, |
4853 | msub); | 4873 | msub); |
4854 | 4874 | ||
4855 | LOG (GNUNET_ERROR_TYPE_INFO, "Ready to receive requests from clients\n"); | 4875 | LOG(GNUNET_ERROR_TYPE_INFO, "Ready to receive requests from clients\n"); |
4856 | 4876 | ||
4857 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 4877 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
4858 | stats = GNUNET_STATISTICS_create ("rps", cfg); | 4878 | stats = GNUNET_STATISTICS_create("rps", cfg); |
4859 | } | 4879 | } |
4860 | 4880 | ||
4861 | 4881 | ||
@@ -4863,46 +4883,46 @@ run (void *cls, | |||
4863 | * Define "main" method using service macro. | 4883 | * Define "main" method using service macro. |
4864 | */ | 4884 | */ |
4865 | GNUNET_SERVICE_MAIN | 4885 | GNUNET_SERVICE_MAIN |
4866 | ("rps", | 4886 | ("rps", |
4867 | GNUNET_SERVICE_OPTION_NONE, | 4887 | GNUNET_SERVICE_OPTION_NONE, |
4868 | &run, | 4888 | &run, |
4869 | &client_connect_cb, | 4889 | &client_connect_cb, |
4870 | &client_disconnect_cb, | 4890 | &client_disconnect_cb, |
4871 | NULL, | 4891 | NULL, |
4872 | GNUNET_MQ_hd_var_size (client_seed, | 4892 | GNUNET_MQ_hd_var_size(client_seed, |
4873 | GNUNET_MESSAGE_TYPE_RPS_CS_SEED, | 4893 | GNUNET_MESSAGE_TYPE_RPS_CS_SEED, |
4874 | struct GNUNET_RPS_CS_SeedMessage, | 4894 | struct GNUNET_RPS_CS_SeedMessage, |
4875 | NULL), | 4895 | NULL), |
4876 | #if ENABLE_MALICIOUS | 4896 | #if ENABLE_MALICIOUS |
4877 | GNUNET_MQ_hd_var_size (client_act_malicious, | 4897 | GNUNET_MQ_hd_var_size(client_act_malicious, |
4878 | GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS, | 4898 | GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS, |
4879 | struct GNUNET_RPS_CS_ActMaliciousMessage, | 4899 | struct GNUNET_RPS_CS_ActMaliciousMessage, |
4880 | NULL), | 4900 | NULL), |
4881 | #endif /* ENABLE_MALICIOUS */ | 4901 | #endif /* ENABLE_MALICIOUS */ |
4882 | GNUNET_MQ_hd_fixed_size (client_view_request, | 4902 | GNUNET_MQ_hd_fixed_size(client_view_request, |
4883 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST, | 4903 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST, |
4884 | struct GNUNET_RPS_CS_DEBUG_ViewRequest, | 4904 | struct GNUNET_RPS_CS_DEBUG_ViewRequest, |
4885 | NULL), | 4905 | NULL), |
4886 | GNUNET_MQ_hd_fixed_size (client_view_cancel, | 4906 | GNUNET_MQ_hd_fixed_size(client_view_cancel, |
4887 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL, | 4907 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL, |
4888 | struct GNUNET_MessageHeader, | 4908 | struct GNUNET_MessageHeader, |
4889 | NULL), | 4909 | NULL), |
4890 | GNUNET_MQ_hd_fixed_size (client_stream_request, | 4910 | GNUNET_MQ_hd_fixed_size(client_stream_request, |
4891 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST, | 4911 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST, |
4892 | struct GNUNET_RPS_CS_DEBUG_StreamRequest, | 4912 | struct GNUNET_RPS_CS_DEBUG_StreamRequest, |
4893 | NULL), | 4913 | NULL), |
4894 | GNUNET_MQ_hd_fixed_size (client_stream_cancel, | 4914 | GNUNET_MQ_hd_fixed_size(client_stream_cancel, |
4895 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_CANCEL, | 4915 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_CANCEL, |
4896 | struct GNUNET_MessageHeader, | 4916 | struct GNUNET_MessageHeader, |
4897 | NULL), | 4917 | NULL), |
4898 | GNUNET_MQ_hd_fixed_size (client_start_sub, | 4918 | GNUNET_MQ_hd_fixed_size(client_start_sub, |
4899 | GNUNET_MESSAGE_TYPE_RPS_CS_SUB_START, | 4919 | GNUNET_MESSAGE_TYPE_RPS_CS_SUB_START, |
4900 | struct GNUNET_RPS_CS_SubStartMessage, | 4920 | struct GNUNET_RPS_CS_SubStartMessage, |
4901 | NULL), | 4921 | NULL), |
4902 | GNUNET_MQ_hd_fixed_size (client_stop_sub, | 4922 | GNUNET_MQ_hd_fixed_size(client_stop_sub, |
4903 | GNUNET_MESSAGE_TYPE_RPS_CS_SUB_STOP, | 4923 | GNUNET_MESSAGE_TYPE_RPS_CS_SUB_STOP, |
4904 | struct GNUNET_RPS_CS_SubStopMessage, | 4924 | struct GNUNET_RPS_CS_SubStopMessage, |
4905 | NULL), | 4925 | NULL), |
4906 | GNUNET_MQ_handler_end()); | 4926 | GNUNET_MQ_handler_end()); |
4907 | 4927 | ||
4908 | /* end of gnunet-service-rps.c */ | 4928 | /* end of gnunet-service-rps.c */ |
diff --git a/src/rps/gnunet-service-rps_custommap.c b/src/rps/gnunet-service-rps_custommap.c index d3cc8d104..b842bc0a5 100644 --- a/src/rps/gnunet-service-rps_custommap.c +++ b/src/rps/gnunet-service-rps_custommap.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file rps/gnunet-service-rps_custommap.c | 22 | * @file rps/gnunet-service-rps_custommap.c |
@@ -28,7 +28,7 @@ | |||
28 | #include "gnunet-service-rps_custommap.h" | 28 | #include "gnunet-service-rps_custommap.h" |
29 | #include <inttypes.h> | 29 | #include <inttypes.h> |
30 | 30 | ||
31 | #define LOG(kind, ...) GNUNET_log_from(kind,"rps-peers",__VA_ARGS__) | 31 | #define LOG(kind, ...) GNUNET_log_from(kind, "rps-peers", __VA_ARGS__) |
32 | 32 | ||
33 | 33 | ||
34 | /** | 34 | /** |
@@ -54,8 +54,7 @@ | |||
54 | * - contain continous indices 0 <= i < len | 54 | * - contain continous indices 0 <= i < len |
55 | * - not contain duplicate peers | 55 | * - not contain duplicate peers |
56 | */ | 56 | */ |
57 | struct CustomPeerMap | 57 | struct CustomPeerMap { |
58 | { | ||
59 | /** | 58 | /** |
60 | * Multihashmap to be able to access a random index | 59 | * Multihashmap to be able to access a random index |
61 | */ | 60 | */ |
@@ -76,14 +75,14 @@ struct CustomPeerMap | |||
76 | * @return the newly created custom peer map | 75 | * @return the newly created custom peer map |
77 | */ | 76 | */ |
78 | struct CustomPeerMap * | 77 | struct CustomPeerMap * |
79 | CustomPeerMap_create (unsigned int len) | 78 | CustomPeerMap_create(unsigned int len) |
80 | { | 79 | { |
81 | struct CustomPeerMap *c_peer_map; | 80 | struct CustomPeerMap *c_peer_map; |
82 | 81 | ||
83 | c_peer_map = GNUNET_new (struct CustomPeerMap); | 82 | c_peer_map = GNUNET_new(struct CustomPeerMap); |
84 | c_peer_map->hash_map = GNUNET_CONTAINER_multihashmap32_create (len); | 83 | c_peer_map->hash_map = GNUNET_CONTAINER_multihashmap32_create(len); |
85 | c_peer_map->peer_map = GNUNET_CONTAINER_multipeermap_create (len, | 84 | c_peer_map->peer_map = GNUNET_CONTAINER_multipeermap_create(len, |
86 | GNUNET_NO); | 85 | GNUNET_NO); |
87 | return c_peer_map; | 86 | return c_peer_map; |
88 | } | 87 | } |
89 | 88 | ||
@@ -95,11 +94,11 @@ CustomPeerMap_create (unsigned int len) | |||
95 | * @return size of the map | 94 | * @return size of the map |
96 | */ | 95 | */ |
97 | unsigned int | 96 | unsigned int |
98 | CustomPeerMap_size (const struct CustomPeerMap *c_peer_map) | 97 | CustomPeerMap_size(const struct CustomPeerMap *c_peer_map) |
99 | { | 98 | { |
100 | GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size (c_peer_map->hash_map) == | 99 | GNUNET_assert(GNUNET_CONTAINER_multihashmap32_size(c_peer_map->hash_map) == |
101 | GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map)); | 100 | GNUNET_CONTAINER_multipeermap_size(c_peer_map->peer_map)); |
102 | return GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map); | 101 | return GNUNET_CONTAINER_multipeermap_size(c_peer_map->peer_map); |
103 | } | 102 | } |
104 | 103 | ||
105 | /** | 104 | /** |
@@ -112,39 +111,39 @@ CustomPeerMap_size (const struct CustomPeerMap *c_peer_map) | |||
112 | * GNUNET_NO if map did contain peer previously | 111 | * GNUNET_NO if map did contain peer previously |
113 | */ | 112 | */ |
114 | int | 113 | int |
115 | CustomPeerMap_put (const struct CustomPeerMap *c_peer_map, | 114 | CustomPeerMap_put(const struct CustomPeerMap *c_peer_map, |
116 | const struct GNUNET_PeerIdentity *peer) | 115 | const struct GNUNET_PeerIdentity *peer) |
117 | { | 116 | { |
118 | uint32_t *index; | 117 | uint32_t *index; |
119 | struct GNUNET_PeerIdentity *p; | 118 | struct GNUNET_PeerIdentity *p; |
120 | 119 | ||
121 | GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size (c_peer_map->hash_map) == | 120 | GNUNET_assert(GNUNET_CONTAINER_multihashmap32_size(c_peer_map->hash_map) == |
122 | GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map)); | 121 | GNUNET_CONTAINER_multipeermap_size(c_peer_map->peer_map)); |
123 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (c_peer_map->peer_map, | 122 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(c_peer_map->peer_map, |
124 | peer)) | 123 | peer)) |
125 | { | 124 | { |
126 | /* Need to store the index of the peer in the peermap to be able to remove | 125 | /* Need to store the index of the peer in the peermap to be able to remove |
127 | * it properly */ | 126 | * it properly */ |
128 | index = GNUNET_new (uint32_t); | 127 | index = GNUNET_new(uint32_t); |
129 | *index = CustomPeerMap_size (c_peer_map); | 128 | *index = CustomPeerMap_size(c_peer_map); |
130 | p = GNUNET_new (struct GNUNET_PeerIdentity); | 129 | p = GNUNET_new(struct GNUNET_PeerIdentity); |
131 | *p = *peer; | 130 | *p = *peer; |
132 | GNUNET_assert (p != peer); | 131 | GNUNET_assert(p != peer); |
133 | GNUNET_assert (0 == memcmp (p, | 132 | GNUNET_assert(0 == memcmp(p, |
134 | peer, | 133 | peer, |
135 | sizeof(struct GNUNET_PeerIdentity))); | 134 | sizeof(struct GNUNET_PeerIdentity))); |
136 | GNUNET_CONTAINER_multipeermap_put (c_peer_map->peer_map, | 135 | GNUNET_CONTAINER_multipeermap_put(c_peer_map->peer_map, |
137 | p, | 136 | p, |
138 | index, | 137 | index, |
139 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 138 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
140 | GNUNET_CONTAINER_multihashmap32_put (c_peer_map->hash_map, | 139 | GNUNET_CONTAINER_multihashmap32_put(c_peer_map->hash_map, |
141 | *index, | 140 | *index, |
142 | p, | 141 | p, |
143 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 142 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
144 | GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size (c_peer_map->hash_map) == | 143 | GNUNET_assert(GNUNET_CONTAINER_multihashmap32_size(c_peer_map->hash_map) == |
145 | GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map)); | 144 | GNUNET_CONTAINER_multipeermap_size(c_peer_map->peer_map)); |
146 | return GNUNET_OK; | 145 | return GNUNET_OK; |
147 | } | 146 | } |
148 | return GNUNET_NO; | 147 | return GNUNET_NO; |
149 | } | 148 | } |
150 | 149 | ||
@@ -158,10 +157,10 @@ CustomPeerMap_put (const struct CustomPeerMap *c_peer_map, | |||
158 | * GNUNET_NO otherwise | 157 | * GNUNET_NO otherwise |
159 | */ | 158 | */ |
160 | int | 159 | int |
161 | CustomPeerMap_contains_peer (const struct CustomPeerMap *c_peer_map, | 160 | CustomPeerMap_contains_peer(const struct CustomPeerMap *c_peer_map, |
162 | const struct GNUNET_PeerIdentity *peer) | 161 | const struct GNUNET_PeerIdentity *peer) |
163 | { | 162 | { |
164 | return GNUNET_CONTAINER_multipeermap_contains (c_peer_map->peer_map, peer); | 163 | return GNUNET_CONTAINER_multipeermap_contains(c_peer_map->peer_map, peer); |
165 | } | 164 | } |
166 | 165 | ||
167 | /** | 166 | /** |
@@ -173,13 +172,13 @@ CustomPeerMap_contains_peer (const struct CustomPeerMap *c_peer_map, | |||
173 | * @return the index | 172 | * @return the index |
174 | */ | 173 | */ |
175 | static uint32_t * | 174 | static uint32_t * |
176 | CustomPeerMap_get_index_pointer (const struct CustomPeerMap *c_peer_map, | 175 | CustomPeerMap_get_index_pointer(const struct CustomPeerMap *c_peer_map, |
177 | const struct GNUNET_PeerIdentity *peer) | 176 | const struct GNUNET_PeerIdentity *peer) |
178 | { | 177 | { |
179 | uint32_t *index; | 178 | uint32_t *index; |
180 | 179 | ||
181 | GNUNET_assert (GNUNET_YES == CustomPeerMap_contains_peer (c_peer_map, peer)); | 180 | GNUNET_assert(GNUNET_YES == CustomPeerMap_contains_peer(c_peer_map, peer)); |
182 | index = GNUNET_CONTAINER_multipeermap_get (c_peer_map->peer_map, peer); | 181 | index = GNUNET_CONTAINER_multipeermap_get(c_peer_map->peer_map, peer); |
183 | return index; | 182 | return index; |
184 | } | 183 | } |
185 | 184 | ||
@@ -193,52 +192,52 @@ CustomPeerMap_get_index_pointer (const struct CustomPeerMap *c_peer_map, | |||
193 | * GNUNET_NO if map does not contain peer | 192 | * GNUNET_NO if map does not contain peer |
194 | */ | 193 | */ |
195 | int | 194 | int |
196 | CustomPeerMap_remove_peer (const struct CustomPeerMap *c_peer_map, | 195 | CustomPeerMap_remove_peer(const struct CustomPeerMap *c_peer_map, |
197 | const struct GNUNET_PeerIdentity *peer) | 196 | const struct GNUNET_PeerIdentity *peer) |
198 | { | 197 | { |
199 | uint32_t *index; | 198 | uint32_t *index; |
200 | struct GNUNET_PeerIdentity *p; | 199 | struct GNUNET_PeerIdentity *p; |
201 | uint32_t *last_index; | 200 | uint32_t *last_index; |
202 | struct GNUNET_PeerIdentity *last_p; | 201 | struct GNUNET_PeerIdentity *last_p; |
203 | 202 | ||
204 | if (GNUNET_NO == CustomPeerMap_contains_peer (c_peer_map, | 203 | if (GNUNET_NO == CustomPeerMap_contains_peer(c_peer_map, |
205 | peer)) | 204 | peer)) |
206 | { | 205 | { |
207 | return GNUNET_NO; | 206 | return GNUNET_NO; |
208 | } | 207 | } |
209 | index = CustomPeerMap_get_index_pointer (c_peer_map, | 208 | index = CustomPeerMap_get_index_pointer(c_peer_map, |
210 | peer); | 209 | peer); |
211 | GNUNET_assert (*index < CustomPeerMap_size (c_peer_map)); | 210 | GNUNET_assert(*index < CustomPeerMap_size(c_peer_map)); |
212 | /* Need to get the pointer stored in the hashmap to free it */ | 211 | /* Need to get the pointer stored in the hashmap to free it */ |
213 | p = GNUNET_CONTAINER_multihashmap32_get (c_peer_map->hash_map, | 212 | p = GNUNET_CONTAINER_multihashmap32_get(c_peer_map->hash_map, |
214 | *index); | 213 | *index); |
215 | GNUNET_assert (NULL != p); | 214 | GNUNET_assert(NULL != p); |
216 | GNUNET_CONTAINER_multihashmap32_remove_all (c_peer_map->hash_map, | 215 | GNUNET_CONTAINER_multihashmap32_remove_all(c_peer_map->hash_map, |
217 | *index); | 216 | *index); |
218 | // TODO wrong peerid? | 217 | // TODO wrong peerid? |
219 | GNUNET_CONTAINER_multipeermap_remove_all (c_peer_map->peer_map, | 218 | GNUNET_CONTAINER_multipeermap_remove_all(c_peer_map->peer_map, |
220 | peer); | 219 | peer); |
221 | if (*index != CustomPeerMap_size (c_peer_map)) | 220 | if (*index != CustomPeerMap_size(c_peer_map)) |
222 | { /* fill 'gap' with peer at last index */ | 221 | { /* fill 'gap' with peer at last index */ |
223 | last_p = | 222 | last_p = |
224 | GNUNET_CONTAINER_multihashmap32_get (c_peer_map->hash_map, | 223 | GNUNET_CONTAINER_multihashmap32_get(c_peer_map->hash_map, |
225 | CustomPeerMap_size (c_peer_map)); | 224 | CustomPeerMap_size(c_peer_map)); |
226 | GNUNET_assert (NULL != last_p); | 225 | GNUNET_assert(NULL != last_p); |
227 | last_index = GNUNET_CONTAINER_multipeermap_get (c_peer_map->peer_map, | 226 | last_index = GNUNET_CONTAINER_multipeermap_get(c_peer_map->peer_map, |
228 | last_p); | 227 | last_p); |
229 | GNUNET_assert (NULL != last_index); | 228 | GNUNET_assert(NULL != last_index); |
230 | GNUNET_assert (CustomPeerMap_size (c_peer_map) == *last_index); | 229 | GNUNET_assert(CustomPeerMap_size(c_peer_map) == *last_index); |
231 | GNUNET_CONTAINER_multihashmap32_put (c_peer_map->hash_map, | 230 | GNUNET_CONTAINER_multihashmap32_put(c_peer_map->hash_map, |
232 | *index, last_p, | 231 | *index, last_p, |
233 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 232 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
234 | GNUNET_CONTAINER_multihashmap32_remove_all (c_peer_map->hash_map, | 233 | GNUNET_CONTAINER_multihashmap32_remove_all(c_peer_map->hash_map, |
235 | *last_index); | 234 | *last_index); |
236 | *last_index = *index; | 235 | *last_index = *index; |
237 | } | 236 | } |
238 | GNUNET_free (index); | 237 | GNUNET_free(index); |
239 | GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size (c_peer_map->hash_map) == | 238 | GNUNET_assert(GNUNET_CONTAINER_multihashmap32_size(c_peer_map->hash_map) == |
240 | GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map)); | 239 | GNUNET_CONTAINER_multipeermap_size(c_peer_map->peer_map)); |
241 | GNUNET_free (p); | 240 | GNUNET_free(p); |
242 | return GNUNET_OK; | 241 | return GNUNET_OK; |
243 | } | 242 | } |
244 | 243 | ||
@@ -252,14 +251,14 @@ CustomPeerMap_remove_peer (const struct CustomPeerMap *c_peer_map, | |||
252 | * if this index is not known, return NULL | 251 | * if this index is not known, return NULL |
253 | */ | 252 | */ |
254 | struct GNUNET_PeerIdentity * | 253 | struct GNUNET_PeerIdentity * |
255 | CustomPeerMap_get_peer_by_index (const struct CustomPeerMap *c_peer_map, | 254 | CustomPeerMap_get_peer_by_index(const struct CustomPeerMap *c_peer_map, |
256 | uint32_t index) | 255 | uint32_t index) |
257 | { | 256 | { |
258 | if (GNUNET_YES == | 257 | if (GNUNET_YES == |
259 | GNUNET_CONTAINER_multihashmap32_contains (c_peer_map->hash_map, index)) | 258 | GNUNET_CONTAINER_multihashmap32_contains(c_peer_map->hash_map, index)) |
260 | { | 259 | { |
261 | return GNUNET_CONTAINER_multihashmap32_get (c_peer_map->hash_map, index); | 260 | return GNUNET_CONTAINER_multihashmap32_get(c_peer_map->hash_map, index); |
262 | } | 261 | } |
263 | return NULL; | 262 | return NULL; |
264 | } | 263 | } |
265 | 264 | ||
@@ -273,30 +272,30 @@ CustomPeerMap_get_peer_by_index (const struct CustomPeerMap *c_peer_map, | |||
273 | * GNUNET_NO if map does not contain (index of) peer | 272 | * GNUNET_NO if map does not contain (index of) peer |
274 | */ | 273 | */ |
275 | int | 274 | int |
276 | CustomPeerMap_remove_peer_by_index (const struct CustomPeerMap *c_peer_map, | 275 | CustomPeerMap_remove_peer_by_index(const struct CustomPeerMap *c_peer_map, |
277 | uint32_t index) | 276 | uint32_t index) |
278 | { | 277 | { |
279 | uint32_t *index_p; | 278 | uint32_t *index_p; |
280 | struct GNUNET_PeerIdentity *peer; | 279 | struct GNUNET_PeerIdentity *peer; |
281 | 280 | ||
282 | if (index >= CustomPeerMap_size (c_peer_map)) | 281 | if (index >= CustomPeerMap_size(c_peer_map)) |
283 | { | 282 | { |
284 | return GNUNET_NO; | 283 | return GNUNET_NO; |
285 | } | 284 | } |
286 | GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size (c_peer_map->hash_map) == | 285 | GNUNET_assert(GNUNET_CONTAINER_multihashmap32_size(c_peer_map->hash_map) == |
287 | GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map)); | 286 | GNUNET_CONTAINER_multipeermap_size(c_peer_map->peer_map)); |
288 | if (GNUNET_NO == | 287 | if (GNUNET_NO == |
289 | GNUNET_CONTAINER_multihashmap32_contains (c_peer_map->hash_map, index)) | 288 | GNUNET_CONTAINER_multihashmap32_contains(c_peer_map->hash_map, index)) |
290 | { | 289 | { |
291 | return GNUNET_NO; | 290 | return GNUNET_NO; |
292 | } | 291 | } |
293 | peer = CustomPeerMap_get_peer_by_index (c_peer_map, index); | 292 | peer = CustomPeerMap_get_peer_by_index(c_peer_map, index); |
294 | GNUNET_assert (NULL != peer); | 293 | GNUNET_assert(NULL != peer); |
295 | index_p = CustomPeerMap_get_index_pointer (c_peer_map, peer); | 294 | index_p = CustomPeerMap_get_index_pointer(c_peer_map, peer); |
296 | GNUNET_assert (index == *index_p); | 295 | GNUNET_assert(index == *index_p); |
297 | CustomPeerMap_remove_peer (c_peer_map, peer); | 296 | CustomPeerMap_remove_peer(c_peer_map, peer); |
298 | GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size (c_peer_map->hash_map) == | 297 | GNUNET_assert(GNUNET_CONTAINER_multihashmap32_size(c_peer_map->hash_map) == |
299 | GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map)); | 298 | GNUNET_CONTAINER_multipeermap_size(c_peer_map->peer_map)); |
300 | return GNUNET_OK; | 299 | return GNUNET_OK; |
301 | } | 300 | } |
302 | 301 | ||
@@ -308,18 +307,18 @@ CustomPeerMap_remove_peer_by_index (const struct CustomPeerMap *c_peer_map, | |||
308 | * @return size of the map | 307 | * @return size of the map |
309 | */ | 308 | */ |
310 | void | 309 | void |
311 | CustomPeerMap_clear (const struct CustomPeerMap *c_peer_map) | 310 | CustomPeerMap_clear(const struct CustomPeerMap *c_peer_map) |
312 | { | 311 | { |
313 | while (0 < CustomPeerMap_size (c_peer_map)) | 312 | while (0 < CustomPeerMap_size(c_peer_map)) |
314 | { | 313 | { |
315 | GNUNET_assert (GNUNET_YES == | 314 | GNUNET_assert(GNUNET_YES == |
316 | GNUNET_CONTAINER_multihashmap32_contains (c_peer_map->hash_map, | 315 | GNUNET_CONTAINER_multihashmap32_contains(c_peer_map->hash_map, |
317 | CustomPeerMap_size (c_peer_map) -1)); | 316 | CustomPeerMap_size(c_peer_map) - 1)); |
318 | GNUNET_assert (GNUNET_OK == | 317 | GNUNET_assert(GNUNET_OK == |
319 | CustomPeerMap_remove_peer_by_index (c_peer_map, | 318 | CustomPeerMap_remove_peer_by_index(c_peer_map, |
320 | CustomPeerMap_size (c_peer_map) -1)); | 319 | CustomPeerMap_size(c_peer_map) - 1)); |
321 | } | 320 | } |
322 | GNUNET_assert (0 == CustomPeerMap_size (c_peer_map)); | 321 | GNUNET_assert(0 == CustomPeerMap_size(c_peer_map)); |
323 | } | 322 | } |
324 | 323 | ||
325 | /** | 324 | /** |
@@ -328,12 +327,12 @@ CustomPeerMap_clear (const struct CustomPeerMap *c_peer_map) | |||
328 | * @param c_peer_map the map to destroy | 327 | * @param c_peer_map the map to destroy |
329 | */ | 328 | */ |
330 | void | 329 | void |
331 | CustomPeerMap_destroy (struct CustomPeerMap *c_peer_map) | 330 | CustomPeerMap_destroy(struct CustomPeerMap *c_peer_map) |
332 | { | 331 | { |
333 | CustomPeerMap_clear (c_peer_map); | 332 | CustomPeerMap_clear(c_peer_map); |
334 | GNUNET_CONTAINER_multihashmap32_destroy (c_peer_map->hash_map); | 333 | GNUNET_CONTAINER_multihashmap32_destroy(c_peer_map->hash_map); |
335 | GNUNET_CONTAINER_multipeermap_destroy (c_peer_map->peer_map); | 334 | GNUNET_CONTAINER_multipeermap_destroy(c_peer_map->peer_map); |
336 | GNUNET_free (c_peer_map); | 335 | GNUNET_free(c_peer_map); |
337 | } | 336 | } |
338 | 337 | ||
339 | /* end of gnunet-service-rps_custommap.c */ | 338 | /* end of gnunet-service-rps_custommap.c */ |
diff --git a/src/rps/gnunet-service-rps_custommap.h b/src/rps/gnunet-service-rps_custommap.h index 53d256487..210ab56c6 100644 --- a/src/rps/gnunet-service-rps_custommap.h +++ b/src/rps/gnunet-service-rps_custommap.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file rps/gnunet-service-rps_custommap.h | 22 | * @file rps/gnunet-service-rps_custommap.h |
@@ -61,7 +61,7 @@ struct CustomPeerMap; | |||
61 | * @return the newly created custom peer map | 61 | * @return the newly created custom peer map |
62 | */ | 62 | */ |
63 | struct CustomPeerMap * | 63 | struct CustomPeerMap * |
64 | CustomPeerMap_create (unsigned int len); | 64 | CustomPeerMap_create(unsigned int len); |
65 | 65 | ||
66 | /** | 66 | /** |
67 | * Get the size of the custom peer map | 67 | * Get the size of the custom peer map |
@@ -71,7 +71,7 @@ CustomPeerMap_create (unsigned int len); | |||
71 | * @return size of the map | 71 | * @return size of the map |
72 | */ | 72 | */ |
73 | unsigned int | 73 | unsigned int |
74 | CustomPeerMap_size (const struct CustomPeerMap *c_peer_map); | 74 | CustomPeerMap_size(const struct CustomPeerMap *c_peer_map); |
75 | 75 | ||
76 | /** | 76 | /** |
77 | * Insert peer into the custom peer map | 77 | * Insert peer into the custom peer map |
@@ -83,8 +83,8 @@ CustomPeerMap_size (const struct CustomPeerMap *c_peer_map); | |||
83 | * GNUNET_NO if map did contain peer previously | 83 | * GNUNET_NO if map did contain peer previously |
84 | */ | 84 | */ |
85 | int | 85 | int |
86 | CustomPeerMap_put (const struct CustomPeerMap *c_peer_map, | 86 | CustomPeerMap_put(const struct CustomPeerMap *c_peer_map, |
87 | const struct GNUNET_PeerIdentity *peer); | 87 | const struct GNUNET_PeerIdentity *peer); |
88 | 88 | ||
89 | /** | 89 | /** |
90 | * Check whether custom peer map contains a peer | 90 | * Check whether custom peer map contains a peer |
@@ -96,8 +96,8 @@ CustomPeerMap_put (const struct CustomPeerMap *c_peer_map, | |||
96 | * GNUNET_NO otherwise | 96 | * GNUNET_NO otherwise |
97 | */ | 97 | */ |
98 | int | 98 | int |
99 | CustomPeerMap_contains_peer (const struct CustomPeerMap *c_peer_map, | 99 | CustomPeerMap_contains_peer(const struct CustomPeerMap *c_peer_map, |
100 | const struct GNUNET_PeerIdentity *peer); | 100 | const struct GNUNET_PeerIdentity *peer); |
101 | 101 | ||
102 | /** | 102 | /** |
103 | * Remove peer from custom peer map | 103 | * Remove peer from custom peer map |
@@ -109,8 +109,8 @@ CustomPeerMap_contains_peer (const struct CustomPeerMap *c_peer_map, | |||
109 | * GNUNET_NO if map does not contain peer | 109 | * GNUNET_NO if map does not contain peer |
110 | */ | 110 | */ |
111 | int | 111 | int |
112 | CustomPeerMap_remove_peer (const struct CustomPeerMap *c_peer_map, | 112 | CustomPeerMap_remove_peer(const struct CustomPeerMap *c_peer_map, |
113 | const struct GNUNET_PeerIdentity *peer); | 113 | const struct GNUNET_PeerIdentity *peer); |
114 | 114 | ||
115 | /** | 115 | /** |
116 | * Get a peer by index | 116 | * Get a peer by index |
@@ -122,8 +122,8 @@ CustomPeerMap_remove_peer (const struct CustomPeerMap *c_peer_map, | |||
122 | * if this index is not known, return NULL | 122 | * if this index is not known, return NULL |
123 | */ | 123 | */ |
124 | struct GNUNET_PeerIdentity * | 124 | struct GNUNET_PeerIdentity * |
125 | CustomPeerMap_get_peer_by_index (const struct CustomPeerMap *c_peer_map, | 125 | CustomPeerMap_get_peer_by_index(const struct CustomPeerMap *c_peer_map, |
126 | uint32_t index); | 126 | uint32_t index); |
127 | 127 | ||
128 | /** | 128 | /** |
129 | * Remove peer from custom peer map by index | 129 | * Remove peer from custom peer map by index |
@@ -135,8 +135,8 @@ CustomPeerMap_get_peer_by_index (const struct CustomPeerMap *c_peer_map, | |||
135 | * GNUNET_NO if map does not contain (index of) peer | 135 | * GNUNET_NO if map does not contain (index of) peer |
136 | */ | 136 | */ |
137 | int | 137 | int |
138 | CustomPeerMap_remove_peer_by_index (const struct CustomPeerMap *c_peer_map, | 138 | CustomPeerMap_remove_peer_by_index(const struct CustomPeerMap *c_peer_map, |
139 | uint32_t index); | 139 | uint32_t index); |
140 | 140 | ||
141 | /** | 141 | /** |
142 | * Clear the custom peer map | 142 | * Clear the custom peer map |
@@ -146,7 +146,7 @@ CustomPeerMap_remove_peer_by_index (const struct CustomPeerMap *c_peer_map, | |||
146 | * @return size of the map | 146 | * @return size of the map |
147 | */ | 147 | */ |
148 | void | 148 | void |
149 | CustomPeerMap_clear (const struct CustomPeerMap *c_peer_map); | 149 | CustomPeerMap_clear(const struct CustomPeerMap *c_peer_map); |
150 | 150 | ||
151 | /** | 151 | /** |
152 | * Destroy peermap. | 152 | * Destroy peermap. |
@@ -154,6 +154,6 @@ CustomPeerMap_clear (const struct CustomPeerMap *c_peer_map); | |||
154 | * @param c_peer_map the map to destroy | 154 | * @param c_peer_map the map to destroy |
155 | */ | 155 | */ |
156 | void | 156 | void |
157 | CustomPeerMap_destroy (struct CustomPeerMap *c_peer_map); | 157 | CustomPeerMap_destroy(struct CustomPeerMap *c_peer_map); |
158 | 158 | ||
159 | /* end of gnunet-service-rps_custommap.h */ | 159 | /* end of gnunet-service-rps_custommap.h */ |
diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c index e17b154ca..a3f778979 100644 --- a/src/rps/gnunet-service-rps_sampler.c +++ b/src/rps/gnunet-service-rps_sampler.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file rps/gnunet-service-rps_sampler.c | 22 | * @file rps/gnunet-service-rps_sampler.c |
@@ -37,7 +37,7 @@ | |||
37 | 37 | ||
38 | #include "rps-test_util.h" | 38 | #include "rps-test_util.h" |
39 | 39 | ||
40 | #define LOG(kind, ...) GNUNET_log_from(kind,"rps-sampler",__VA_ARGS__) | 40 | #define LOG(kind, ...) GNUNET_log_from(kind, "rps-sampler", __VA_ARGS__) |
41 | 41 | ||
42 | 42 | ||
43 | // multiple 'clients'? | 43 | // multiple 'clients'? |
@@ -49,8 +49,8 @@ | |||
49 | // hist_size_init, hist_size_max | 49 | // hist_size_init, hist_size_max |
50 | 50 | ||
51 | /*********************************************************************** | 51 | /*********************************************************************** |
52 | * WARNING: This section needs to be reviewed regarding the use of | 52 | * WARNING: This section needs to be reviewed regarding the use of |
53 | * functions providing (pseudo)randomness! | 53 | * functions providing (pseudo)randomness! |
54 | ***********************************************************************/ | 54 | ***********************************************************************/ |
55 | 55 | ||
56 | // TODO care about invalid input of the caller (size 0 or less...) | 56 | // TODO care about invalid input of the caller (size 0 or less...) |
@@ -68,8 +68,7 @@ typedef void | |||
68 | * | 68 | * |
69 | * Meant to be an entry in an DLL. | 69 | * Meant to be an entry in an DLL. |
70 | */ | 70 | */ |
71 | struct SamplerNotifyUpdateCTX | 71 | struct SamplerNotifyUpdateCTX { |
72 | { | ||
73 | /** | 72 | /** |
74 | * @brief The Callback to call on updates | 73 | * @brief The Callback to call on updates |
75 | */ | 74 | */ |
@@ -107,14 +106,13 @@ typedef void | |||
107 | * Only used internally | 106 | * Only used internally |
108 | */ | 107 | */ |
109 | static void | 108 | static void |
110 | sampler_get_rand_peer (void *cls); | 109 | sampler_get_rand_peer(void *cls); |
111 | 110 | ||
112 | 111 | ||
113 | /** | 112 | /** |
114 | * Closure to _get_n_rand_peers_ready_cb() | 113 | * Closure to _get_n_rand_peers_ready_cb() |
115 | */ | 114 | */ |
116 | struct RPS_SamplerRequestHandle | 115 | struct RPS_SamplerRequestHandle { |
117 | { | ||
118 | /** | 116 | /** |
119 | * DLL | 117 | * DLL |
120 | */ | 118 | */ |
@@ -193,8 +191,8 @@ static uint32_t client_get_index; | |||
193 | * @return a handle to a sampler that consists of sampler elements. | 191 | * @return a handle to a sampler that consists of sampler elements. |
194 | */ | 192 | */ |
195 | struct RPS_Sampler * | 193 | struct RPS_Sampler * |
196 | RPS_sampler_init (size_t init_size, | 194 | RPS_sampler_init(size_t init_size, |
197 | struct GNUNET_TIME_Relative max_round_interval) | 195 | struct GNUNET_TIME_Relative max_round_interval) |
198 | { | 196 | { |
199 | struct RPS_Sampler *sampler; | 197 | struct RPS_Sampler *sampler; |
200 | 198 | ||
@@ -202,13 +200,13 @@ RPS_sampler_init (size_t init_size, | |||
202 | min_size = 10; // TODO make input to _samplers_init() | 200 | min_size = 10; // TODO make input to _samplers_init() |
203 | max_size = 1000; // TODO make input to _samplers_init() | 201 | max_size = 1000; // TODO make input to _samplers_init() |
204 | 202 | ||
205 | sampler = GNUNET_new (struct RPS_Sampler); | 203 | sampler = GNUNET_new(struct RPS_Sampler); |
206 | 204 | ||
207 | sampler->max_round_interval = max_round_interval; | 205 | sampler->max_round_interval = max_round_interval; |
208 | sampler->get_peers = sampler_get_rand_peer; | 206 | sampler->get_peers = sampler_get_rand_peer; |
209 | //sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity); | 207 | //sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity); |
210 | //GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, min_size); | 208 | //GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, min_size); |
211 | RPS_sampler_resize (sampler, init_size); | 209 | RPS_sampler_resize(sampler, init_size); |
212 | 210 | ||
213 | client_get_index = 0; | 211 | client_get_index = 0; |
214 | 212 | ||
@@ -224,7 +222,7 @@ RPS_sampler_init (size_t init_size, | |||
224 | * Only used internally | 222 | * Only used internally |
225 | */ | 223 | */ |
226 | static void | 224 | static void |
227 | sampler_get_rand_peer (void *cls) | 225 | sampler_get_rand_peer(void *cls) |
228 | { | 226 | { |
229 | struct GetPeerCls *gpc = cls; | 227 | struct GetPeerCls *gpc = cls; |
230 | uint32_t r_index; | 228 | uint32_t r_index; |
@@ -238,28 +236,28 @@ sampler_get_rand_peer (void *cls) | |||
238 | * Choose the r_index of the peer we want to return | 236 | * Choose the r_index of the peer we want to return |
239 | * at random from the interval of the gossip list | 237 | * at random from the interval of the gossip list |
240 | */ | 238 | */ |
241 | r_index = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, | 239 | r_index = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG, |
242 | sampler->sampler_size); | 240 | sampler->sampler_size); |
243 | 241 | ||
244 | if (EMPTY == sampler->sampler_elements[r_index]->is_empty) | 242 | if (EMPTY == sampler->sampler_elements[r_index]->is_empty) |
245 | { | 243 | { |
246 | //LOG (GNUNET_ERROR_TYPE_DEBUG, | 244 | //LOG (GNUNET_ERROR_TYPE_DEBUG, |
247 | // "Not returning randomly selected, empty PeerID. - Rescheduling.\n"); | 245 | // "Not returning randomly selected, empty PeerID. - Rescheduling.\n"); |
248 | 246 | ||
249 | gpc->notify_ctx = | 247 | gpc->notify_ctx = |
250 | sampler_notify_on_update (sampler, | 248 | sampler_notify_on_update(sampler, |
251 | &sampler_get_rand_peer, | 249 | &sampler_get_rand_peer, |
252 | gpc); | 250 | gpc); |
253 | return; | 251 | return; |
254 | } | 252 | } |
255 | 253 | ||
256 | GNUNET_CONTAINER_DLL_remove (gpc->req_handle->gpc_head, | 254 | GNUNET_CONTAINER_DLL_remove(gpc->req_handle->gpc_head, |
257 | gpc->req_handle->gpc_tail, | 255 | gpc->req_handle->gpc_tail, |
258 | gpc); | 256 | gpc); |
259 | *gpc->id = sampler->sampler_elements[r_index]->peer_id; | 257 | *gpc->id = sampler->sampler_elements[r_index]->peer_id; |
260 | gpc->cont (gpc->cont_cls, gpc->id, 0, sampler->sampler_elements[r_index]->num_peers); | 258 | gpc->cont(gpc->cont_cls, gpc->id, 0, sampler->sampler_elements[r_index]->num_peers); |
261 | 259 | ||
262 | GNUNET_free (gpc); | 260 | GNUNET_free(gpc); |
263 | } | 261 | } |
264 | 262 | ||
265 | 263 | ||
diff --git a/src/rps/gnunet-service-rps_sampler.h b/src/rps/gnunet-service-rps_sampler.h index d8e5f3efd..8bccb8431 100644 --- a/src/rps/gnunet-service-rps_sampler.h +++ b/src/rps/gnunet-service-rps_sampler.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file rps/gnunet-service-rps_sampler.h | 22 | * @file rps/gnunet-service-rps_sampler.h |
@@ -48,7 +48,7 @@ struct RPS_SamplerRequestHandle; | |||
48 | * @return the size of the sampler | 48 | * @return the size of the sampler |
49 | */ | 49 | */ |
50 | unsigned int | 50 | unsigned int |
51 | RPS_sampler_get_size (struct RPS_Sampler *sampler); | 51 | RPS_sampler_get_size(struct RPS_Sampler *sampler); |
52 | 52 | ||
53 | 53 | ||
54 | /** | 54 | /** |
@@ -58,7 +58,7 @@ RPS_sampler_get_size (struct RPS_Sampler *sampler); | |||
58 | * @param new_size the new size of the sampler (not 0) | 58 | * @param new_size the new size of the sampler (not 0) |
59 | */ | 59 | */ |
60 | void | 60 | void |
61 | RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size); | 61 | RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size); |
62 | 62 | ||
63 | 63 | ||
64 | /** | 64 | /** |
@@ -69,8 +69,8 @@ RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size); | |||
69 | * @return a handle to a sampler that consists of sampler elements. | 69 | * @return a handle to a sampler that consists of sampler elements. |
70 | */ | 70 | */ |
71 | struct RPS_Sampler * | 71 | struct RPS_Sampler * |
72 | RPS_sampler_init (size_t init_size, | 72 | RPS_sampler_init(size_t init_size, |
73 | struct GNUNET_TIME_Relative max_round_interval); | 73 | struct GNUNET_TIME_Relative max_round_interval); |
74 | 74 | ||
75 | 75 | ||
76 | /** | 76 | /** |
@@ -79,9 +79,9 @@ RPS_sampler_init (size_t init_size, | |||
79 | * @param sampler the sampler to update. | 79 | * @param sampler the sampler to update. |
80 | * @param id the PeerID that is put in the sampler | 80 | * @param id the PeerID that is put in the sampler |
81 | */ | 81 | */ |
82 | void | 82 | void |
83 | RPS_sampler_update (struct RPS_Sampler *sampler, | 83 | RPS_sampler_update(struct RPS_Sampler *sampler, |
84 | const struct GNUNET_PeerIdentity *id); | 84 | const struct GNUNET_PeerIdentity *id); |
85 | 85 | ||
86 | 86 | ||
87 | /** | 87 | /** |
@@ -99,9 +99,9 @@ RPS_sampler_update (struct RPS_Sampler *sampler, | |||
99 | * @param sampler the sampler to reinitialise a sampler in. | 99 | * @param sampler the sampler to reinitialise a sampler in. |
100 | * @param id the id of the samplers to update. | 100 | * @param id the id of the samplers to update. |
101 | */ | 101 | */ |
102 | void | 102 | void |
103 | RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler, | 103 | RPS_sampler_reinitialise_by_value(struct RPS_Sampler *sampler, |
104 | const struct GNUNET_PeerIdentity *id); | 104 | const struct GNUNET_PeerIdentity *id); |
105 | 105 | ||
106 | 106 | ||
107 | /** | 107 | /** |
@@ -119,10 +119,10 @@ RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler, | |||
119 | * @param num_peers the number of peers requested | 119 | * @param num_peers the number of peers requested |
120 | */ | 120 | */ |
121 | struct RPS_SamplerRequestHandle * | 121 | struct RPS_SamplerRequestHandle * |
122 | RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler, | 122 | RPS_sampler_get_n_rand_peers(struct RPS_Sampler *sampler, |
123 | uint32_t num_peers, | 123 | uint32_t num_peers, |
124 | RPS_sampler_n_rand_peers_ready_cb cb, | 124 | RPS_sampler_n_rand_peers_ready_cb cb, |
125 | void *cls); | 125 | void *cls); |
126 | 126 | ||
127 | /** | 127 | /** |
128 | * Cancle a request issued through #RPS_sampler_n_rand_peers_ready_cb. | 128 | * Cancle a request issued through #RPS_sampler_n_rand_peers_ready_cb. |
@@ -130,7 +130,7 @@ RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler, | |||
130 | * @param req_handle the handle to the request | 130 | * @param req_handle the handle to the request |
131 | */ | 131 | */ |
132 | void | 132 | void |
133 | RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle); | 133 | RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle); |
134 | 134 | ||
135 | 135 | ||
136 | /** | 136 | /** |
@@ -141,9 +141,9 @@ RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle); | |||
141 | * | 141 | * |
142 | * @return the number of occurrences of id. | 142 | * @return the number of occurrences of id. |
143 | */ | 143 | */ |
144 | uint32_t | 144 | uint32_t |
145 | RPS_sampler_count_id (struct RPS_Sampler *sampler, | 145 | RPS_sampler_count_id(struct RPS_Sampler *sampler, |
146 | const struct GNUNET_PeerIdentity *id); | 146 | const struct GNUNET_PeerIdentity *id); |
147 | 147 | ||
148 | 148 | ||
149 | /** | 149 | /** |
@@ -151,8 +151,8 @@ RPS_sampler_count_id (struct RPS_Sampler *sampler, | |||
151 | * | 151 | * |
152 | * @param sampler the sampler to destroy. | 152 | * @param sampler the sampler to destroy. |
153 | */ | 153 | */ |
154 | void | 154 | void |
155 | RPS_sampler_destroy (struct RPS_Sampler *sampler); | 155 | RPS_sampler_destroy(struct RPS_Sampler *sampler); |
156 | 156 | ||
157 | #endif | 157 | #endif |
158 | /* end of gnunet-service-rps.c */ | 158 | /* end of gnunet-service-rps.c */ |
diff --git a/src/rps/gnunet-service-rps_sampler_elem.c b/src/rps/gnunet-service-rps_sampler_elem.c index 9487c5f2e..6d5305f03 100644 --- a/src/rps/gnunet-service-rps_sampler_elem.c +++ b/src/rps/gnunet-service-rps_sampler_elem.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file rps/gnunet-service-rps_sampler.c | 22 | * @file rps/gnunet-service-rps_sampler.c |
@@ -32,12 +32,12 @@ | |||
32 | 32 | ||
33 | #include "rps-test_util.h" | 33 | #include "rps-test_util.h" |
34 | 34 | ||
35 | #define LOG(kind, ...) GNUNET_log_from(kind,"rps-sampler_elem",__VA_ARGS__) | 35 | #define LOG(kind, ...) GNUNET_log_from(kind, "rps-sampler_elem", __VA_ARGS__) |
36 | 36 | ||
37 | 37 | ||
38 | /*********************************************************************** | 38 | /*********************************************************************** |
39 | * WARNING: This section needs to be reviewed regarding the use of | 39 | * WARNING: This section needs to be reviewed regarding the use of |
40 | * functions providing (pseudo)randomness! | 40 | * functions providing (pseudo)randomness! |
41 | ***********************************************************************/ | 41 | ***********************************************************************/ |
42 | 42 | ||
43 | 43 | ||
@@ -47,7 +47,7 @@ | |||
47 | * @param sampler_el The sampler element to (re-) initialise | 47 | * @param sampler_el The sampler element to (re-) initialise |
48 | */ | 48 | */ |
49 | void | 49 | void |
50 | RPS_sampler_elem_reinit (struct RPS_SamplerElement *sampler_elem) | 50 | RPS_sampler_elem_reinit(struct RPS_SamplerElement *sampler_elem) |
51 | { | 51 | { |
52 | sampler_elem->is_empty = EMPTY; | 52 | sampler_elem->is_empty = EMPTY; |
53 | 53 | ||
@@ -58,7 +58,7 @@ RPS_sampler_elem_reinit (struct RPS_SamplerElement *sampler_elem) | |||
58 | 58 | ||
59 | sampler_elem->last_client_request = GNUNET_TIME_UNIT_FOREVER_ABS; | 59 | sampler_elem->last_client_request = GNUNET_TIME_UNIT_FOREVER_ABS; |
60 | 60 | ||
61 | sampler_elem->birth = GNUNET_TIME_absolute_get (); | 61 | sampler_elem->birth = GNUNET_TIME_absolute_get(); |
62 | sampler_elem->num_peers = 0; | 62 | sampler_elem->num_peers = 0; |
63 | sampler_elem->num_change = 0; | 63 | sampler_elem->num_change = 0; |
64 | } | 64 | } |
@@ -73,13 +73,13 @@ RPS_sampler_elem_reinit (struct RPS_SamplerElement *sampler_elem) | |||
73 | * @return a newly created RPS_SamplerElement which currently holds no id. | 73 | * @return a newly created RPS_SamplerElement which currently holds no id. |
74 | */ | 74 | */ |
75 | struct RPS_SamplerElement * | 75 | struct RPS_SamplerElement * |
76 | RPS_sampler_elem_create (void) | 76 | RPS_sampler_elem_create(void) |
77 | { | 77 | { |
78 | struct RPS_SamplerElement *s; | 78 | struct RPS_SamplerElement *s; |
79 | 79 | ||
80 | s = GNUNET_new (struct RPS_SamplerElement); | 80 | s = GNUNET_new(struct RPS_SamplerElement); |
81 | 81 | ||
82 | RPS_sampler_elem_reinit (s); | 82 | RPS_sampler_elem_reinit(s); |
83 | 83 | ||
84 | return s; | 84 | return s; |
85 | } | 85 | } |
@@ -91,9 +91,9 @@ RPS_sampler_elem_create (void) | |||
91 | * @param sampler_elem the element to destroy | 91 | * @param sampler_elem the element to destroy |
92 | */ | 92 | */ |
93 | void | 93 | void |
94 | RPS_sampler_elem_destroy (struct RPS_SamplerElement *sampler_elem) | 94 | RPS_sampler_elem_destroy(struct RPS_SamplerElement *sampler_elem) |
95 | { | 95 | { |
96 | GNUNET_free (sampler_elem); | 96 | GNUNET_free(sampler_elem); |
97 | } | 97 | } |
98 | 98 | ||
99 | 99 | ||
@@ -104,50 +104,50 @@ RPS_sampler_elem_destroy (struct RPS_SamplerElement *sampler_elem) | |||
104 | * @param new_ID The PeerID to update with | 104 | * @param new_ID The PeerID to update with |
105 | */ | 105 | */ |
106 | void | 106 | void |
107 | RPS_sampler_elem_next (struct RPS_SamplerElement *sampler_elem, | 107 | RPS_sampler_elem_next(struct RPS_SamplerElement *sampler_elem, |
108 | const struct GNUNET_PeerIdentity *new_ID) | 108 | const struct GNUNET_PeerIdentity *new_ID) |
109 | { | 109 | { |
110 | struct GNUNET_HashCode other_hash; | 110 | struct GNUNET_HashCode other_hash; |
111 | 111 | ||
112 | sampler_elem->num_peers++; | 112 | sampler_elem->num_peers++; |
113 | 113 | ||
114 | if (0 == GNUNET_memcmp (new_ID, &(sampler_elem->peer_id))) | 114 | if (0 == GNUNET_memcmp(new_ID, &(sampler_elem->peer_id))) |
115 | { | ||
116 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Have already PeerID %s\n", | ||
117 | GNUNET_i2s (&(sampler_elem->peer_id))); | ||
118 | } | ||
119 | else | ||
120 | { | ||
121 | GNUNET_CRYPTO_hmac(&sampler_elem->auth_key, | ||
122 | new_ID, | ||
123 | sizeof(struct GNUNET_PeerIdentity), | ||
124 | &other_hash); | ||
125 | |||
126 | if (EMPTY == sampler_elem->is_empty) | ||
127 | { | 115 | { |
128 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 116 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Have already PeerID %s\n", |
129 | "Got PeerID %s; Simply accepting (was empty previously).\n", | 117 | GNUNET_i2s(&(sampler_elem->peer_id))); |
130 | GNUNET_i2s(new_ID)); | ||
131 | sampler_elem->peer_id = *new_ID; | ||
132 | sampler_elem->peer_id_hash = other_hash; | ||
133 | |||
134 | sampler_elem->num_change++; | ||
135 | } | 118 | } |
136 | else if (0 > GNUNET_CRYPTO_hash_cmp (&other_hash, &sampler_elem->peer_id_hash)) | 119 | else |
137 | { | ||
138 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Discarding old PeerID %s\n", | ||
139 | GNUNET_i2s (&sampler_elem->peer_id)); | ||
140 | sampler_elem->peer_id = *new_ID; | ||
141 | sampler_elem->peer_id_hash = other_hash; | ||
142 | |||
143 | sampler_elem->num_change++; | ||
144 | } | ||
145 | else | ||
146 | { | 120 | { |
147 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Keeping old PeerID %s\n", | 121 | GNUNET_CRYPTO_hmac(&sampler_elem->auth_key, |
148 | GNUNET_i2s (&sampler_elem->peer_id)); | 122 | new_ID, |
123 | sizeof(struct GNUNET_PeerIdentity), | ||
124 | &other_hash); | ||
125 | |||
126 | if (EMPTY == sampler_elem->is_empty) | ||
127 | { | ||
128 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
129 | "Got PeerID %s; Simply accepting (was empty previously).\n", | ||
130 | GNUNET_i2s(new_ID)); | ||
131 | sampler_elem->peer_id = *new_ID; | ||
132 | sampler_elem->peer_id_hash = other_hash; | ||
133 | |||
134 | sampler_elem->num_change++; | ||
135 | } | ||
136 | else if (0 > GNUNET_CRYPTO_hash_cmp(&other_hash, &sampler_elem->peer_id_hash)) | ||
137 | { | ||
138 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Discarding old PeerID %s\n", | ||
139 | GNUNET_i2s(&sampler_elem->peer_id)); | ||
140 | sampler_elem->peer_id = *new_ID; | ||
141 | sampler_elem->peer_id_hash = other_hash; | ||
142 | |||
143 | sampler_elem->num_change++; | ||
144 | } | ||
145 | else | ||
146 | { | ||
147 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Keeping old PeerID %s\n", | ||
148 | GNUNET_i2s(&sampler_elem->peer_id)); | ||
149 | } | ||
149 | } | 150 | } |
150 | } | ||
151 | sampler_elem->is_empty = NOT_EMPTY; | 151 | sampler_elem->is_empty = NOT_EMPTY; |
152 | } | 152 | } |
153 | 153 | ||
@@ -158,8 +158,8 @@ RPS_sampler_elem_next (struct RPS_SamplerElement *sampler_elem, | |||
158 | * @param auth_key the key to use | 158 | * @param auth_key the key to use |
159 | */ | 159 | */ |
160 | void | 160 | void |
161 | RPS_sampler_elem_set (struct RPS_SamplerElement *sampler_elem, | 161 | RPS_sampler_elem_set(struct RPS_SamplerElement *sampler_elem, |
162 | struct GNUNET_CRYPTO_AuthKey auth_key) | 162 | struct GNUNET_CRYPTO_AuthKey auth_key) |
163 | { | 163 | { |
164 | sampler_elem->auth_key = auth_key; | 164 | sampler_elem->auth_key = auth_key; |
165 | } | 165 | } |
diff --git a/src/rps/gnunet-service-rps_sampler_elem.h b/src/rps/gnunet-service-rps_sampler_elem.h index 3f33a6816..c22b7413c 100644 --- a/src/rps/gnunet-service-rps_sampler_elem.h +++ b/src/rps/gnunet-service-rps_sampler_elem.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file rps/gnunet-service-rps_sampler_elem.h | 22 | * @file rps/gnunet-service-rps_sampler_elem.h |
@@ -30,15 +30,14 @@ | |||
30 | 30 | ||
31 | 31 | ||
32 | /*********************************************************************** | 32 | /*********************************************************************** |
33 | * WARNING: This section needs to be reviewed regarding the use of | 33 | * WARNING: This section needs to be reviewed regarding the use of |
34 | * functions providing (pseudo)randomness! | 34 | * functions providing (pseudo)randomness! |
35 | ***********************************************************************/ | 35 | ***********************************************************************/ |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Used to indicate whether a sampler element is empty. | 38 | * Used to indicate whether a sampler element is empty. |
39 | */ | 39 | */ |
40 | enum RPS_SamplerEmpty | 40 | enum RPS_SamplerEmpty { |
41 | { | ||
42 | NOT_EMPTY = 0x0, | 41 | NOT_EMPTY = 0x0, |
43 | EMPTY = 0x1 | 42 | EMPTY = 0x1 |
44 | }; | 43 | }; |
@@ -46,8 +45,7 @@ enum RPS_SamplerEmpty | |||
46 | /** | 45 | /** |
47 | * A sampler element sampling one PeerID at a time. | 46 | * A sampler element sampling one PeerID at a time. |
48 | */ | 47 | */ |
49 | struct RPS_SamplerElement | 48 | struct RPS_SamplerElement { |
50 | { | ||
51 | /** | 49 | /** |
52 | * Min-wise linear permutation used by this sampler. | 50 | * Min-wise linear permutation used by this sampler. |
53 | * | 51 | * |
@@ -104,7 +102,7 @@ struct RPS_SamplerElement | |||
104 | * @param sampler_el The sampler element to (re-) initialise | 102 | * @param sampler_el The sampler element to (re-) initialise |
105 | */ | 103 | */ |
106 | void | 104 | void |
107 | RPS_sampler_elem_reinit (struct RPS_SamplerElement *sampler_elem); | 105 | RPS_sampler_elem_reinit(struct RPS_SamplerElement *sampler_elem); |
108 | 106 | ||
109 | 107 | ||
110 | /** | 108 | /** |
@@ -116,7 +114,7 @@ RPS_sampler_elem_reinit (struct RPS_SamplerElement *sampler_elem); | |||
116 | * @return a newly created RPS_SamplerElement which currently holds no id. | 114 | * @return a newly created RPS_SamplerElement which currently holds no id. |
117 | */ | 115 | */ |
118 | struct RPS_SamplerElement * | 116 | struct RPS_SamplerElement * |
119 | RPS_sampler_elem_create (void); | 117 | RPS_sampler_elem_create(void); |
120 | 118 | ||
121 | 119 | ||
122 | /** | 120 | /** |
@@ -125,7 +123,7 @@ RPS_sampler_elem_create (void); | |||
125 | * @param sampler_elem the element to destroy | 123 | * @param sampler_elem the element to destroy |
126 | */ | 124 | */ |
127 | void | 125 | void |
128 | RPS_sampler_elem_destroy (struct RPS_SamplerElement *sampler_elem); | 126 | RPS_sampler_elem_destroy(struct RPS_SamplerElement *sampler_elem); |
129 | 127 | ||
130 | 128 | ||
131 | /** | 129 | /** |
@@ -135,8 +133,8 @@ RPS_sampler_elem_destroy (struct RPS_SamplerElement *sampler_elem); | |||
135 | * @param new_ID The PeerID to update with | 133 | * @param new_ID The PeerID to update with |
136 | */ | 134 | */ |
137 | void | 135 | void |
138 | RPS_sampler_elem_next (struct RPS_SamplerElement *sampler_elem, | 136 | RPS_sampler_elem_next(struct RPS_SamplerElement *sampler_elem, |
139 | const struct GNUNET_PeerIdentity *new_ID); | 137 | const struct GNUNET_PeerIdentity *new_ID); |
140 | 138 | ||
141 | /** | 139 | /** |
142 | * Set the min-wise independent function of the given sampler element. | 140 | * Set the min-wise independent function of the given sampler element. |
@@ -145,8 +143,8 @@ RPS_sampler_elem_next (struct RPS_SamplerElement *sampler_elem, | |||
145 | * @param auth_key the key to use | 143 | * @param auth_key the key to use |
146 | */ | 144 | */ |
147 | void | 145 | void |
148 | RPS_sampler_elem_set (struct RPS_SamplerElement *sampler_elem, | 146 | RPS_sampler_elem_set(struct RPS_SamplerElement *sampler_elem, |
149 | struct GNUNET_CRYPTO_AuthKey auth_key); | 147 | struct GNUNET_CRYPTO_AuthKey auth_key); |
150 | 148 | ||
151 | 149 | ||
152 | #endif /* RPS_SAMPLER_ELEM_H */ | 150 | #endif /* RPS_SAMPLER_ELEM_H */ |
diff --git a/src/rps/gnunet-service-rps_view.c b/src/rps/gnunet-service-rps_view.c index 8a0cae21e..bedd2ae6c 100644 --- a/src/rps/gnunet-service-rps_view.c +++ b/src/rps/gnunet-service-rps_view.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file rps/gnunet-service-rps_view.c | 22 | * @file rps/gnunet-service-rps_view.c |
@@ -28,8 +28,7 @@ | |||
28 | #include "gnunet-service-rps_view.h" | 28 | #include "gnunet-service-rps_view.h" |
29 | #include <inttypes.h> | 29 | #include <inttypes.h> |
30 | 30 | ||
31 | struct View | 31 | struct View { |
32 | { | ||
33 | /** | 32 | /** |
34 | * Array containing the peers | 33 | * Array containing the peers |
35 | */ | 34 | */ |
@@ -54,16 +53,16 @@ struct View | |||
54 | * @return The newly created view | 53 | * @return The newly created view |
55 | */ | 54 | */ |
56 | struct View * | 55 | struct View * |
57 | View_create (uint32_t len) | 56 | View_create(uint32_t len) |
58 | { | 57 | { |
59 | struct View *view; | 58 | struct View *view; |
60 | 59 | ||
61 | view = GNUNET_new (struct View); | 60 | view = GNUNET_new(struct View); |
62 | view->length = len; | 61 | view->length = len; |
63 | view->array = GNUNET_new_array (len, struct GNUNET_PeerIdentity); | 62 | view->array = GNUNET_new_array(len, struct GNUNET_PeerIdentity); |
64 | view->mpm = | 63 | view->mpm = |
65 | GNUNET_CONTAINER_multipeermap_create (len, GNUNET_NO); /* might even be | 64 | GNUNET_CONTAINER_multipeermap_create(len, GNUNET_NO); /* might even be |
66 | * set to _YES */ | 65 | * set to _YES */ |
67 | return view; | 66 | return view; |
68 | } | 67 | } |
69 | 68 | ||
@@ -77,38 +76,38 @@ View_create (uint32_t len) | |||
77 | * @param len the (maximum) length for the view | 76 | * @param len the (maximum) length for the view |
78 | */ | 77 | */ |
79 | void | 78 | void |
80 | View_change_len (struct View *view, | 79 | View_change_len(struct View *view, |
81 | uint32_t len) | 80 | uint32_t len) |
82 | { | 81 | { |
83 | uint32_t i; | 82 | uint32_t i; |
84 | uint32_t *index; | 83 | uint32_t *index; |
85 | 84 | ||
86 | if (GNUNET_CONTAINER_multipeermap_size (view->mpm) < len) | 85 | if (GNUNET_CONTAINER_multipeermap_size(view->mpm) < len) |
87 | { /* Simply shrink */ | 86 | { /* Simply shrink */ |
88 | /* We might simply clear and free the left over space */ | 87 | /* We might simply clear and free the left over space */ |
89 | GNUNET_array_grow (view->array, view->length, len); | 88 | GNUNET_array_grow(view->array, view->length, len); |
90 | } | ||
91 | else /* We have to remove elements */ | ||
92 | { | ||
93 | /* TODO find a way to preserve indices */ | ||
94 | for (i = 0; i < len; i++) | ||
95 | { | ||
96 | index = GNUNET_CONTAINER_multipeermap_get (view->mpm, &view->array[i]); | ||
97 | GNUNET_assert (NULL != index); | ||
98 | GNUNET_free (index); | ||
99 | } | 89 | } |
100 | GNUNET_array_grow (view->array, view->length, len); | 90 | else /* We have to remove elements */ |
101 | GNUNET_CONTAINER_multipeermap_destroy (view->mpm); | ||
102 | view->mpm = GNUNET_CONTAINER_multipeermap_create (len, GNUNET_NO); | ||
103 | for (i = 0; i < len; i++) | ||
104 | { | 91 | { |
105 | index = GNUNET_new (uint32_t); | 92 | /* TODO find a way to preserve indices */ |
106 | *index = i; | 93 | for (i = 0; i < len; i++) |
107 | GNUNET_CONTAINER_multipeermap_put (view->mpm, &view->array[i], index, | 94 | { |
108 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 95 | index = GNUNET_CONTAINER_multipeermap_get(view->mpm, &view->array[i]); |
96 | GNUNET_assert(NULL != index); | ||
97 | GNUNET_free(index); | ||
98 | } | ||
99 | GNUNET_array_grow(view->array, view->length, len); | ||
100 | GNUNET_CONTAINER_multipeermap_destroy(view->mpm); | ||
101 | view->mpm = GNUNET_CONTAINER_multipeermap_create(len, GNUNET_NO); | ||
102 | for (i = 0; i < len; i++) | ||
103 | { | ||
104 | index = GNUNET_new(uint32_t); | ||
105 | *index = i; | ||
106 | GNUNET_CONTAINER_multipeermap_put(view->mpm, &view->array[i], index, | ||
107 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
108 | } | ||
109 | } | 109 | } |
110 | } | 110 | GNUNET_assert(view->length == len); |
111 | GNUNET_assert (view->length == len); | ||
112 | } | 111 | } |
113 | 112 | ||
114 | 113 | ||
@@ -119,7 +118,7 @@ View_change_len (struct View *view, | |||
119 | * @return the view in array representation | 118 | * @return the view in array representation |
120 | */ | 119 | */ |
121 | const struct GNUNET_PeerIdentity * | 120 | const struct GNUNET_PeerIdentity * |
122 | View_get_as_array (const struct View *view) | 121 | View_get_as_array(const struct View *view) |
123 | { | 122 | { |
124 | return view->array; | 123 | return view->array; |
125 | } | 124 | } |
@@ -132,9 +131,9 @@ View_get_as_array (const struct View *view) | |||
132 | * @return current number of actually contained peers | 131 | * @return current number of actually contained peers |
133 | */ | 132 | */ |
134 | unsigned int | 133 | unsigned int |
135 | View_size (const struct View *view) | 134 | View_size(const struct View *view) |
136 | { | 135 | { |
137 | return GNUNET_CONTAINER_multipeermap_size (view->mpm); | 136 | return GNUNET_CONTAINER_multipeermap_size(view->mpm); |
138 | } | 137 | } |
139 | 138 | ||
140 | 139 | ||
@@ -148,25 +147,25 @@ View_size (const struct View *view) | |||
148 | * GNUNET_NO if peer was not inserted | 147 | * GNUNET_NO if peer was not inserted |
149 | */ | 148 | */ |
150 | int | 149 | int |
151 | View_put (struct View *view, | 150 | View_put(struct View *view, |
152 | const struct GNUNET_PeerIdentity *peer) | 151 | const struct GNUNET_PeerIdentity *peer) |
153 | { | 152 | { |
154 | uint32_t *index; | 153 | uint32_t *index; |
155 | 154 | ||
156 | if ((view->length <= View_size (view)) || /* If array is 'full' */ | 155 | if ((view->length <= View_size(view)) || /* If array is 'full' */ |
157 | (GNUNET_YES == View_contains_peer (view, peer))) | 156 | (GNUNET_YES == View_contains_peer(view, peer))) |
158 | { | 157 | { |
159 | return GNUNET_NO; | 158 | return GNUNET_NO; |
160 | } | 159 | } |
161 | else | 160 | else |
162 | { | 161 | { |
163 | index = GNUNET_new (uint32_t); | 162 | index = GNUNET_new(uint32_t); |
164 | *index = (uint32_t) View_size (view); | 163 | *index = (uint32_t)View_size(view); |
165 | view->array[*index] = *peer; | 164 | view->array[*index] = *peer; |
166 | GNUNET_CONTAINER_multipeermap_put (view->mpm, peer, index, | 165 | GNUNET_CONTAINER_multipeermap_put(view->mpm, peer, index, |
167 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 166 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
168 | return GNUNET_OK; | 167 | return GNUNET_OK; |
169 | } | 168 | } |
170 | } | 169 | } |
171 | 170 | ||
172 | 171 | ||
@@ -180,10 +179,10 @@ View_put (struct View *view, | |||
180 | * GNUNET_NO otherwise | 179 | * GNUNET_NO otherwise |
181 | */ | 180 | */ |
182 | int | 181 | int |
183 | View_contains_peer (const struct View *view, | 182 | View_contains_peer(const struct View *view, |
184 | const struct GNUNET_PeerIdentity *peer) | 183 | const struct GNUNET_PeerIdentity *peer) |
185 | { | 184 | { |
186 | return GNUNET_CONTAINER_multipeermap_contains (view->mpm, peer); | 185 | return GNUNET_CONTAINER_multipeermap_contains(view->mpm, peer); |
187 | } | 186 | } |
188 | 187 | ||
189 | 188 | ||
@@ -197,32 +196,32 @@ View_contains_peer (const struct View *view, | |||
197 | * GNUNET_NO if view does not contain peer | 196 | * GNUNET_NO if view does not contain peer |
198 | */ | 197 | */ |
199 | int | 198 | int |
200 | View_remove_peer (struct View *view, | 199 | View_remove_peer(struct View *view, |
201 | const struct GNUNET_PeerIdentity *peer) | 200 | const struct GNUNET_PeerIdentity *peer) |
202 | { | 201 | { |
203 | uint32_t *index; | 202 | uint32_t *index; |
204 | uint32_t *swap_index; | 203 | uint32_t *swap_index; |
205 | uint32_t last_index; | 204 | uint32_t last_index; |
206 | 205 | ||
207 | if (GNUNET_NO == View_contains_peer (view, peer)) | 206 | if (GNUNET_NO == View_contains_peer(view, peer)) |
208 | { | 207 | { |
209 | return GNUNET_NO; | 208 | return GNUNET_NO; |
210 | } | 209 | } |
211 | index = GNUNET_CONTAINER_multipeermap_get (view->mpm, peer); | 210 | index = GNUNET_CONTAINER_multipeermap_get(view->mpm, peer); |
212 | GNUNET_assert (NULL != index); | 211 | GNUNET_assert(NULL != index); |
213 | last_index = View_size (view) - 1; | 212 | last_index = View_size(view) - 1; |
214 | if (*index < last_index) | 213 | if (*index < last_index) |
215 | { /* Fill the 'gap' in the array with the last peer */ | 214 | { /* Fill the 'gap' in the array with the last peer */ |
216 | view->array[*index] = view->array[last_index]; | 215 | view->array[*index] = view->array[last_index]; |
217 | GNUNET_assert (GNUNET_YES == View_contains_peer (view, | 216 | GNUNET_assert(GNUNET_YES == View_contains_peer(view, |
218 | &view->array[last_index])); | 217 | &view->array[last_index])); |
219 | swap_index = GNUNET_CONTAINER_multipeermap_get (view->mpm, | 218 | swap_index = GNUNET_CONTAINER_multipeermap_get(view->mpm, |
220 | &view->array[last_index]); | 219 | &view->array[last_index]); |
221 | GNUNET_assert (NULL != swap_index); | 220 | GNUNET_assert(NULL != swap_index); |
222 | *swap_index = *index; | 221 | *swap_index = *index; |
223 | GNUNET_free (index); | 222 | GNUNET_free(index); |
224 | } | 223 | } |
225 | GNUNET_CONTAINER_multipeermap_remove_all (view->mpm, peer); | 224 | GNUNET_CONTAINER_multipeermap_remove_all(view->mpm, peer); |
226 | return GNUNET_OK; | 225 | return GNUNET_OK; |
227 | } | 226 | } |
228 | 227 | ||
@@ -237,17 +236,17 @@ View_remove_peer (struct View *view, | |||
237 | * NULL if this index is not known | 236 | * NULL if this index is not known |
238 | */ | 237 | */ |
239 | const struct GNUNET_PeerIdentity * | 238 | const struct GNUNET_PeerIdentity * |
240 | View_get_peer_by_index (const struct View *view, | 239 | View_get_peer_by_index(const struct View *view, |
241 | uint32_t index) | 240 | uint32_t index) |
242 | { | 241 | { |
243 | if (index < GNUNET_CONTAINER_multipeermap_size (view->mpm)) | 242 | if (index < GNUNET_CONTAINER_multipeermap_size(view->mpm)) |
244 | { | 243 | { |
245 | return &view->array[index]; | 244 | return &view->array[index]; |
246 | } | 245 | } |
247 | else | 246 | else |
248 | { | 247 | { |
249 | return NULL; | 248 | return NULL; |
250 | } | 249 | } |
251 | } | 250 | } |
252 | 251 | ||
253 | 252 | ||
@@ -257,20 +256,20 @@ View_get_peer_by_index (const struct View *view, | |||
257 | * @param view The view to clear | 256 | * @param view The view to clear |
258 | */ | 257 | */ |
259 | void | 258 | void |
260 | View_clear (struct View *view) | 259 | View_clear(struct View *view) |
261 | { | 260 | { |
262 | for (uint32_t i = 0; 0 < View_size (view); i++) | 261 | for (uint32_t i = 0; 0 < View_size(view); i++) |
263 | { /* Need to free indices stored at peers */ | 262 | { /* Need to free indices stored at peers */ |
264 | uint32_t *index; | 263 | uint32_t *index; |
265 | 264 | ||
266 | GNUNET_assert (GNUNET_YES == | 265 | GNUNET_assert(GNUNET_YES == |
267 | GNUNET_CONTAINER_multipeermap_contains (view->mpm, &view->array[i])); | 266 | GNUNET_CONTAINER_multipeermap_contains(view->mpm, &view->array[i])); |
268 | index = GNUNET_CONTAINER_multipeermap_get (view->mpm, &view->array[i]); | 267 | index = GNUNET_CONTAINER_multipeermap_get(view->mpm, &view->array[i]); |
269 | GNUNET_assert (NULL != index); | 268 | GNUNET_assert(NULL != index); |
270 | GNUNET_free (index); | 269 | GNUNET_free(index); |
271 | GNUNET_CONTAINER_multipeermap_remove_all (view->mpm, &view->array[i]); | 270 | GNUNET_CONTAINER_multipeermap_remove_all(view->mpm, &view->array[i]); |
272 | } | 271 | } |
273 | GNUNET_assert (0 == View_size (view)); | 272 | GNUNET_assert(0 == View_size(view)); |
274 | } | 273 | } |
275 | 274 | ||
276 | 275 | ||
@@ -280,13 +279,13 @@ View_clear (struct View *view) | |||
280 | * @param view the view to destroy | 279 | * @param view the view to destroy |
281 | */ | 280 | */ |
282 | void | 281 | void |
283 | View_destroy (struct View *view) | 282 | View_destroy(struct View *view) |
284 | { | 283 | { |
285 | View_clear (view); | 284 | View_clear(view); |
286 | GNUNET_free (view->array); | 285 | GNUNET_free(view->array); |
287 | view->array = NULL; | 286 | view->array = NULL; |
288 | GNUNET_CONTAINER_multipeermap_destroy (view->mpm); | 287 | GNUNET_CONTAINER_multipeermap_destroy(view->mpm); |
289 | GNUNET_free (view); | 288 | GNUNET_free(view); |
290 | } | 289 | } |
291 | 290 | ||
292 | /* end of gnunet-service-rps_view.c */ | 291 | /* end of gnunet-service-rps_view.c */ |
diff --git a/src/rps/gnunet-service-rps_view.h b/src/rps/gnunet-service-rps_view.h index 4339b6d4e..0ceed5432 100644 --- a/src/rps/gnunet-service-rps_view.h +++ b/src/rps/gnunet-service-rps_view.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file rps/gnunet-service-rps_view.h | 22 | * @file rps/gnunet-service-rps_view.h |
@@ -35,7 +35,7 @@ struct View; | |||
35 | * @return The newly created view | 35 | * @return The newly created view |
36 | */ | 36 | */ |
37 | struct View * | 37 | struct View * |
38 | View_create (unsigned int len); | 38 | View_create(unsigned int len); |
39 | 39 | ||
40 | 40 | ||
41 | /** | 41 | /** |
@@ -47,8 +47,8 @@ View_create (unsigned int len); | |||
47 | * @param len the (maximum) length for the view | 47 | * @param len the (maximum) length for the view |
48 | */ | 48 | */ |
49 | void | 49 | void |
50 | View_change_len (struct View *view, | 50 | View_change_len(struct View *view, |
51 | unsigned int len); | 51 | unsigned int len); |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * Get the view as an array | 54 | * Get the view as an array |
@@ -56,7 +56,7 @@ View_change_len (struct View *view, | |||
56 | * @return the view in array representation | 56 | * @return the view in array representation |
57 | */ | 57 | */ |
58 | const struct GNUNET_PeerIdentity * | 58 | const struct GNUNET_PeerIdentity * |
59 | View_get_as_array (const struct View *view); | 59 | View_get_as_array(const struct View *view); |
60 | 60 | ||
61 | 61 | ||
62 | /** | 62 | /** |
@@ -66,7 +66,7 @@ View_get_as_array (const struct View *view); | |||
66 | * @return current number of actually contained peers | 66 | * @return current number of actually contained peers |
67 | */ | 67 | */ |
68 | unsigned int | 68 | unsigned int |
69 | View_size (const struct View *view); | 69 | View_size(const struct View *view); |
70 | 70 | ||
71 | 71 | ||
72 | /** | 72 | /** |
@@ -79,8 +79,8 @@ View_size (const struct View *view); | |||
79 | * GNUNET_NO if peer was not inserted | 79 | * GNUNET_NO if peer was not inserted |
80 | */ | 80 | */ |
81 | int | 81 | int |
82 | View_put (struct View *view, | 82 | View_put(struct View *view, |
83 | const struct GNUNET_PeerIdentity *peer); | 83 | const struct GNUNET_PeerIdentity *peer); |
84 | 84 | ||
85 | 85 | ||
86 | /** | 86 | /** |
@@ -93,8 +93,8 @@ View_put (struct View *view, | |||
93 | * GNUNET_NO otherwise | 93 | * GNUNET_NO otherwise |
94 | */ | 94 | */ |
95 | int | 95 | int |
96 | View_contains_peer (const struct View *view, | 96 | View_contains_peer(const struct View *view, |
97 | const struct GNUNET_PeerIdentity *peer); | 97 | const struct GNUNET_PeerIdentity *peer); |
98 | 98 | ||
99 | 99 | ||
100 | /** | 100 | /** |
@@ -107,8 +107,8 @@ View_contains_peer (const struct View *view, | |||
107 | * GNUNET_NO if view does not contain peer | 107 | * GNUNET_NO if view does not contain peer |
108 | */ | 108 | */ |
109 | int | 109 | int |
110 | View_remove_peer (struct View *view, | 110 | View_remove_peer(struct View *view, |
111 | const struct GNUNET_PeerIdentity *peer); | 111 | const struct GNUNET_PeerIdentity *peer); |
112 | 112 | ||
113 | 113 | ||
114 | /** | 114 | /** |
@@ -121,8 +121,8 @@ View_remove_peer (struct View *view, | |||
121 | * NULL if this index is not known | 121 | * NULL if this index is not known |
122 | */ | 122 | */ |
123 | const struct GNUNET_PeerIdentity * | 123 | const struct GNUNET_PeerIdentity * |
124 | View_get_peer_by_index (const struct View *view, | 124 | View_get_peer_by_index(const struct View *view, |
125 | uint32_t index); | 125 | uint32_t index); |
126 | 126 | ||
127 | 127 | ||
128 | /** | 128 | /** |
@@ -131,7 +131,7 @@ View_get_peer_by_index (const struct View *view, | |||
131 | * @param view The view to clear | 131 | * @param view The view to clear |
132 | */ | 132 | */ |
133 | void | 133 | void |
134 | View_clear (struct View *view); | 134 | View_clear(struct View *view); |
135 | 135 | ||
136 | 136 | ||
137 | /** | 137 | /** |
@@ -140,6 +140,6 @@ View_clear (struct View *view); | |||
140 | * @param view the view to destroy | 140 | * @param view the view to destroy |
141 | */ | 141 | */ |
142 | void | 142 | void |
143 | View_destroy (struct View *view); | 143 | View_destroy(struct View *view); |
144 | 144 | ||
145 | /* end of gnunet-service-rps_view.h */ | 145 | /* end of gnunet-service-rps_view.h */ |
diff --git a/src/rps/rps-sampler_client.c b/src/rps/rps-sampler_client.c index 64ae2dedd..b4ac5f6f8 100644 --- a/src/rps/rps-sampler_client.c +++ b/src/rps/rps-sampler_client.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file rps/gnunet-service-rps_sampler.c | 22 | * @file rps/gnunet-service-rps_sampler.c |
@@ -37,7 +37,7 @@ | |||
37 | 37 | ||
38 | #include "rps-test_util.h" | 38 | #include "rps-test_util.h" |
39 | 39 | ||
40 | #define LOG(kind, ...) GNUNET_log_from(kind,"rps-sampler",__VA_ARGS__) | 40 | #define LOG(kind, ...) GNUNET_log_from(kind, "rps-sampler", __VA_ARGS__) |
41 | 41 | ||
42 | 42 | ||
43 | // multiple 'clients'? | 43 | // multiple 'clients'? |
@@ -49,8 +49,8 @@ | |||
49 | // hist_size_init, hist_size_max | 49 | // hist_size_init, hist_size_max |
50 | 50 | ||
51 | /*********************************************************************** | 51 | /*********************************************************************** |
52 | * WARNING: This section needs to be reviewed regarding the use of | 52 | * WARNING: This section needs to be reviewed regarding the use of |
53 | * functions providing (pseudo)randomness! | 53 | * functions providing (pseudo)randomness! |
54 | ***********************************************************************/ | 54 | ***********************************************************************/ |
55 | 55 | ||
56 | // TODO care about invalid input of the caller (size 0 or less...) | 56 | // TODO care about invalid input of the caller (size 0 or less...) |
@@ -68,8 +68,7 @@ typedef void | |||
68 | * | 68 | * |
69 | * Meant to be an entry in an DLL. | 69 | * Meant to be an entry in an DLL. |
70 | */ | 70 | */ |
71 | struct SamplerNotifyUpdateCTX | 71 | struct SamplerNotifyUpdateCTX { |
72 | { | ||
73 | /** | 72 | /** |
74 | * @brief The Callback to call on updates | 73 | * @brief The Callback to call on updates |
75 | */ | 74 | */ |
@@ -107,14 +106,13 @@ typedef void | |||
107 | * corrsponding peer to the client. | 106 | * corrsponding peer to the client. |
108 | */ | 107 | */ |
109 | static void | 108 | static void |
110 | sampler_mod_get_rand_peer (void *cls); | 109 | sampler_mod_get_rand_peer(void *cls); |
111 | 110 | ||
112 | 111 | ||
113 | /** | 112 | /** |
114 | * Closure to _get_n_rand_peers_ready_cb() | 113 | * Closure to _get_n_rand_peers_ready_cb() |
115 | */ | 114 | */ |
116 | struct RPS_SamplerRequestHandle | 115 | struct RPS_SamplerRequestHandle { |
117 | { | ||
118 | /** | 116 | /** |
119 | * DLL | 117 | * DLL |
120 | */ | 118 | */ |
@@ -162,8 +160,7 @@ struct RPS_SamplerRequestHandle | |||
162 | /** | 160 | /** |
163 | * Closure to _get_rand_peer_info() | 161 | * Closure to _get_rand_peer_info() |
164 | */ | 162 | */ |
165 | struct RPS_SamplerRequestHandleSingleInfo | 163 | struct RPS_SamplerRequestHandleSingleInfo { |
166 | { | ||
167 | /** | 164 | /** |
168 | * DLL | 165 | * DLL |
169 | */ | 166 | */ |
@@ -233,8 +230,8 @@ static uint32_t client_get_index; | |||
233 | * @return a handle to a sampler that consists of sampler elements. | 230 | * @return a handle to a sampler that consists of sampler elements. |
234 | */ | 231 | */ |
235 | struct RPS_Sampler * | 232 | struct RPS_Sampler * |
236 | RPS_sampler_mod_init (size_t init_size, | 233 | RPS_sampler_mod_init(size_t init_size, |
237 | struct GNUNET_TIME_Relative max_round_interval) | 234 | struct GNUNET_TIME_Relative max_round_interval) |
238 | { | 235 | { |
239 | struct RPS_Sampler *sampler; | 236 | struct RPS_Sampler *sampler; |
240 | 237 | ||
@@ -242,7 +239,7 @@ RPS_sampler_mod_init (size_t init_size, | |||
242 | min_size = 10; // TODO make input to _samplers_init() | 239 | min_size = 10; // TODO make input to _samplers_init() |
243 | max_size = 1000; // TODO make input to _samplers_init() | 240 | max_size = 1000; // TODO make input to _samplers_init() |
244 | 241 | ||
245 | sampler = GNUNET_new (struct RPS_Sampler); | 242 | sampler = GNUNET_new(struct RPS_Sampler); |
246 | sampler->max_round_interval = max_round_interval; | 243 | sampler->max_round_interval = max_round_interval; |
247 | sampler->get_peers = sampler_mod_get_rand_peer; | 244 | sampler->get_peers = sampler_mod_get_rand_peer; |
248 | //sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity); | 245 | //sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity); |
@@ -252,7 +249,7 @@ RPS_sampler_mod_init (size_t init_size, | |||
252 | 249 | ||
253 | //GNUNET_assert (init_size == sampler->sampler_size); | 250 | //GNUNET_assert (init_size == sampler->sampler_size); |
254 | 251 | ||
255 | RPS_sampler_resize (sampler, init_size); | 252 | RPS_sampler_resize(sampler, init_size); |
256 | 253 | ||
257 | return sampler; | 254 | return sampler; |
258 | } | 255 | } |
@@ -274,22 +271,22 @@ RPS_sampler_mod_init (size_t init_size, | |||
274 | * @return The estimated probability | 271 | * @return The estimated probability |
275 | */ | 272 | */ |
276 | static double | 273 | static double |
277 | prob_observed_n_peers (uint32_t num_peers_estim, | 274 | prob_observed_n_peers(uint32_t num_peers_estim, |
278 | uint32_t num_peers_observed, | 275 | uint32_t num_peers_observed, |
279 | double deficiency_factor) | 276 | double deficiency_factor) |
280 | { | 277 | { |
281 | uint32_t num_peers = num_peers_estim * (1/deficiency_factor); | 278 | uint32_t num_peers = num_peers_estim * (1 / deficiency_factor); |
282 | uint64_t sum = 0; | 279 | uint64_t sum = 0; |
283 | 280 | ||
284 | for (uint32_t i = 0; i < num_peers; i++) | 281 | for (uint32_t i = 0; i < num_peers; i++) |
285 | { | 282 | { |
286 | uint64_t a = pow (-1, num_peers-i); | 283 | uint64_t a = pow(-1, num_peers - i); |
287 | uint64_t b = binom (num_peers, i); | 284 | uint64_t b = binom(num_peers, i); |
288 | uint64_t c = pow (i, num_peers_observed); | 285 | uint64_t c = pow(i, num_peers_observed); |
289 | sum += a * b * c; | 286 | sum += a * b * c; |
290 | } | 287 | } |
291 | 288 | ||
292 | return sum / (double) pow (num_peers, num_peers_observed); | 289 | return sum / (double)pow(num_peers, num_peers_observed); |
293 | } | 290 | } |
294 | 291 | ||
295 | 292 | ||
@@ -299,7 +296,7 @@ prob_observed_n_peers (uint32_t num_peers_estim, | |||
299 | * This reinitialises the queried sampler element. | 296 | * This reinitialises the queried sampler element. |
300 | */ | 297 | */ |
301 | static void | 298 | static void |
302 | sampler_mod_get_rand_peer (void *cls) | 299 | sampler_mod_get_rand_peer(void *cls) |
303 | { | 300 | { |
304 | struct GetPeerCls *gpc = cls; | 301 | struct GetPeerCls *gpc = cls; |
305 | struct RPS_SamplerElement *s_elem; | 302 | struct RPS_SamplerElement *s_elem; |
@@ -310,72 +307,72 @@ sampler_mod_get_rand_peer (void *cls) | |||
310 | 307 | ||
311 | gpc->get_peer_task = NULL; | 308 | gpc->get_peer_task = NULL; |
312 | gpc->notify_ctx = NULL; | 309 | gpc->notify_ctx = NULL; |
313 | GNUNET_assert ( (NULL != gpc->req_handle) || | 310 | GNUNET_assert((NULL != gpc->req_handle) || |
314 | (NULL != gpc->req_single_info_handle) ); | 311 | (NULL != gpc->req_single_info_handle)); |
315 | if (NULL != gpc->req_handle) | 312 | if (NULL != gpc->req_handle) |
316 | sampler = gpc->req_handle->sampler; | 313 | sampler = gpc->req_handle->sampler; |
317 | else | 314 | else |
318 | sampler = gpc->req_single_info_handle->sampler; | 315 | sampler = gpc->req_single_info_handle->sampler; |
319 | 316 | ||
320 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Single peer was requested\n"); | 317 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Single peer was requested\n"); |
321 | 318 | ||
322 | /* Cycle the #client_get_index one step further */ | 319 | /* Cycle the #client_get_index one step further */ |
323 | client_get_index = (client_get_index + 1) % sampler->sampler_size; | 320 | client_get_index = (client_get_index + 1) % sampler->sampler_size; |
324 | 321 | ||
325 | s_elem = sampler->sampler_elements[client_get_index]; | 322 | s_elem = sampler->sampler_elements[client_get_index]; |
326 | *gpc->id = s_elem->peer_id; | 323 | *gpc->id = s_elem->peer_id; |
327 | GNUNET_assert (NULL != s_elem); | 324 | GNUNET_assert(NULL != s_elem); |
328 | 325 | ||
329 | if (EMPTY == s_elem->is_empty) | 326 | if (EMPTY == s_elem->is_empty) |
330 | { | 327 | { |
331 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 328 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
332 | "Sampler_mod element empty, rescheduling.\n"); | 329 | "Sampler_mod element empty, rescheduling.\n"); |
333 | GNUNET_assert (NULL == gpc->notify_ctx); | 330 | GNUNET_assert(NULL == gpc->notify_ctx); |
334 | gpc->notify_ctx = | 331 | gpc->notify_ctx = |
335 | sampler_notify_on_update (sampler, | 332 | sampler_notify_on_update(sampler, |
336 | &sampler_mod_get_rand_peer, | 333 | &sampler_mod_get_rand_peer, |
337 | gpc); | 334 | gpc); |
338 | return; | 335 | return; |
339 | } | 336 | } |
340 | 337 | ||
341 | /* Check whether we may use this sampler to give it back to the client */ | 338 | /* Check whether we may use this sampler to give it back to the client */ |
342 | if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != s_elem->last_client_request.abs_value_us) | 339 | if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != s_elem->last_client_request.abs_value_us) |
343 | { | ||
344 | // TODO remove this condition at least for the client sampler | ||
345 | last_request_diff = | ||
346 | GNUNET_TIME_absolute_get_difference (s_elem->last_client_request, | ||
347 | GNUNET_TIME_absolute_get ()); | ||
348 | /* We're not going to give it back now if it was | ||
349 | * already requested by a client this round */ | ||
350 | if (last_request_diff.rel_value_us < sampler->max_round_interval.rel_value_us) | ||
351 | { | 340 | { |
352 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 341 | // TODO remove this condition at least for the client sampler |
353 | "Last client request on this sampler was less than max round interval ago -- scheduling for later\n"); | 342 | last_request_diff = |
354 | ///* How many time remains untile the next round has started? */ | 343 | GNUNET_TIME_absolute_get_difference(s_elem->last_client_request, |
355 | //inv_last_request_diff = | 344 | GNUNET_TIME_absolute_get()); |
356 | // GNUNET_TIME_absolute_get_difference (last_request_diff, | 345 | /* We're not going to give it back now if it was |
357 | // sampler->max_round_interval); | 346 | * already requested by a client this round */ |
358 | // add a little delay | 347 | if (last_request_diff.rel_value_us < sampler->max_round_interval.rel_value_us) |
359 | /* Schedule it one round later */ | 348 | { |
360 | GNUNET_assert (NULL == gpc->notify_ctx); | 349 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
350 | "Last client request on this sampler was less than max round interval ago -- scheduling for later\n"); | ||
351 | ///* How many time remains untile the next round has started? */ | ||
352 | //inv_last_request_diff = | ||
353 | // GNUNET_TIME_absolute_get_difference (last_request_diff, | ||
354 | // sampler->max_round_interval); | ||
355 | // add a little delay | ||
356 | /* Schedule it one round later */ | ||
357 | GNUNET_assert(NULL == gpc->notify_ctx); | ||
358 | gpc->notify_ctx = | ||
359 | sampler_notify_on_update(sampler, | ||
360 | &sampler_mod_get_rand_peer, | ||
361 | gpc); | ||
362 | return; | ||
363 | } | ||
364 | } | ||
365 | if (2 > s_elem->num_peers) | ||
366 | { | ||
367 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
368 | "This s_elem saw less than two peers -- scheduling for later\n"); | ||
369 | GNUNET_assert(NULL == gpc->notify_ctx); | ||
361 | gpc->notify_ctx = | 370 | gpc->notify_ctx = |
362 | sampler_notify_on_update (sampler, | 371 | sampler_notify_on_update(sampler, |
363 | &sampler_mod_get_rand_peer, | 372 | &sampler_mod_get_rand_peer, |
364 | gpc); | 373 | gpc); |
365 | return; | 374 | return; |
366 | } | 375 | } |
367 | } | ||
368 | if (2 > s_elem->num_peers) | ||
369 | { | ||
370 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
371 | "This s_elem saw less than two peers -- scheduling for later\n"); | ||
372 | GNUNET_assert (NULL == gpc->notify_ctx); | ||
373 | gpc->notify_ctx = | ||
374 | sampler_notify_on_update (sampler, | ||
375 | &sampler_mod_get_rand_peer, | ||
376 | gpc); | ||
377 | return; | ||
378 | } | ||
379 | /* compute probability */ | 376 | /* compute probability */ |
380 | /* Currently disabled due to numerical limitations */ | 377 | /* Currently disabled due to numerical limitations */ |
381 | //prob_observed_n = prob_observed_n_peers (sampler->num_peers_estim, | 378 | //prob_observed_n = prob_observed_n_peers (sampler->num_peers_estim, |
@@ -413,23 +410,23 @@ sampler_mod_get_rand_peer (void *cls) | |||
413 | // GNUNET_NO); | 410 | // GNUNET_NO); |
414 | 411 | ||
415 | num_observed = s_elem->num_peers; | 412 | num_observed = s_elem->num_peers; |
416 | RPS_sampler_elem_reinit (s_elem); | 413 | RPS_sampler_elem_reinit(s_elem); |
417 | s_elem->last_client_request = GNUNET_TIME_absolute_get (); | 414 | s_elem->last_client_request = GNUNET_TIME_absolute_get(); |
418 | 415 | ||
419 | if (NULL != gpc->req_handle) | 416 | if (NULL != gpc->req_handle) |
420 | { | 417 | { |
421 | GNUNET_CONTAINER_DLL_remove (gpc->req_handle->gpc_head, | 418 | GNUNET_CONTAINER_DLL_remove(gpc->req_handle->gpc_head, |
422 | gpc->req_handle->gpc_tail, | 419 | gpc->req_handle->gpc_tail, |
423 | gpc); | 420 | gpc); |
424 | } | 421 | } |
425 | else | 422 | else |
426 | { | 423 | { |
427 | GNUNET_CONTAINER_DLL_remove (gpc->req_single_info_handle->gpc_head, | 424 | GNUNET_CONTAINER_DLL_remove(gpc->req_single_info_handle->gpc_head, |
428 | gpc->req_single_info_handle->gpc_tail, | 425 | gpc->req_single_info_handle->gpc_tail, |
429 | gpc); | 426 | gpc); |
430 | } | 427 | } |
431 | gpc->cont (gpc->cont_cls, gpc->id, prob_observed_n, num_observed); | 428 | gpc->cont(gpc->cont_cls, gpc->id, prob_observed_n, num_observed); |
432 | GNUNET_free (gpc); | 429 | GNUNET_free(gpc); |
433 | } | 430 | } |
434 | 431 | ||
435 | 432 | ||
diff --git a/src/rps/rps-sampler_client.h b/src/rps/rps-sampler_client.h index 680fabfda..db8087795 100644 --- a/src/rps/rps-sampler_client.h +++ b/src/rps/rps-sampler_client.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file rps/rps-sampler_client.h | 22 | * @file rps/rps-sampler_client.h |
@@ -53,7 +53,7 @@ struct RPS_SamplerRequestHandleSingleInfo; | |||
53 | * @return the size of the sampler | 53 | * @return the size of the sampler |
54 | */ | 54 | */ |
55 | unsigned int | 55 | unsigned int |
56 | RPS_sampler_get_size (struct RPS_Sampler *sampler); | 56 | RPS_sampler_get_size(struct RPS_Sampler *sampler); |
57 | 57 | ||
58 | 58 | ||
59 | /** | 59 | /** |
@@ -63,7 +63,7 @@ RPS_sampler_get_size (struct RPS_Sampler *sampler); | |||
63 | * @param new_size the new size of the sampler (not 0) | 63 | * @param new_size the new size of the sampler (not 0) |
64 | */ | 64 | */ |
65 | void | 65 | void |
66 | RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size); | 66 | RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size); |
67 | 67 | ||
68 | 68 | ||
69 | /** | 69 | /** |
@@ -74,8 +74,8 @@ RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size); | |||
74 | * @return a handle to a sampler that consists of sampler elements. | 74 | * @return a handle to a sampler that consists of sampler elements. |
75 | */ | 75 | */ |
76 | struct RPS_Sampler * | 76 | struct RPS_Sampler * |
77 | RPS_sampler_mod_init (size_t init_size, | 77 | RPS_sampler_mod_init(size_t init_size, |
78 | struct GNUNET_TIME_Relative max_round_interval); | 78 | struct GNUNET_TIME_Relative max_round_interval); |
79 | 79 | ||
80 | 80 | ||
81 | /** | 81 | /** |
@@ -84,9 +84,9 @@ RPS_sampler_mod_init (size_t init_size, | |||
84 | * @param sampler the sampler to update. | 84 | * @param sampler the sampler to update. |
85 | * @param id the PeerID that is put in the sampler | 85 | * @param id the PeerID that is put in the sampler |
86 | */ | 86 | */ |
87 | void | 87 | void |
88 | RPS_sampler_update (struct RPS_Sampler *sampler, | 88 | RPS_sampler_update(struct RPS_Sampler *sampler, |
89 | const struct GNUNET_PeerIdentity *id); | 89 | const struct GNUNET_PeerIdentity *id); |
90 | 90 | ||
91 | 91 | ||
92 | /** | 92 | /** |
@@ -98,9 +98,9 @@ RPS_sampler_update (struct RPS_Sampler *sampler, | |||
98 | * @param sampler the sampler to reinitialise a sampler in. | 98 | * @param sampler the sampler to reinitialise a sampler in. |
99 | * @param id the id of the samplers to update. | 99 | * @param id the id of the samplers to update. |
100 | */ | 100 | */ |
101 | void | 101 | void |
102 | RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler, | 102 | RPS_sampler_reinitialise_by_value(struct RPS_Sampler *sampler, |
103 | const struct GNUNET_PeerIdentity *id); | 103 | const struct GNUNET_PeerIdentity *id); |
104 | 104 | ||
105 | 105 | ||
106 | /** | 106 | /** |
@@ -116,10 +116,10 @@ RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler, | |||
116 | * @param num_peers the number of peers requested | 116 | * @param num_peers the number of peers requested |
117 | */ | 117 | */ |
118 | struct RPS_SamplerRequestHandle * | 118 | struct RPS_SamplerRequestHandle * |
119 | RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler, | 119 | RPS_sampler_get_n_rand_peers(struct RPS_Sampler *sampler, |
120 | uint32_t num_peers, | 120 | uint32_t num_peers, |
121 | RPS_sampler_n_rand_peers_ready_cb cb, | 121 | RPS_sampler_n_rand_peers_ready_cb cb, |
122 | void *cls); | 122 | void *cls); |
123 | 123 | ||
124 | 124 | ||
125 | /** | 125 | /** |
@@ -128,7 +128,7 @@ RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler, | |||
128 | * @param req_handle the handle to the request | 128 | * @param req_handle the handle to the request |
129 | */ | 129 | */ |
130 | void | 130 | void |
131 | RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle); | 131 | RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle); |
132 | 132 | ||
133 | 133 | ||
134 | /** | 134 | /** |
@@ -139,9 +139,9 @@ RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle); | |||
139 | * | 139 | * |
140 | * @return the number of occurrences of id. | 140 | * @return the number of occurrences of id. |
141 | */ | 141 | */ |
142 | uint32_t | 142 | uint32_t |
143 | RPS_sampler_count_id (struct RPS_Sampler *sampler, | 143 | RPS_sampler_count_id(struct RPS_Sampler *sampler, |
144 | const struct GNUNET_PeerIdentity *id); | 144 | const struct GNUNET_PeerIdentity *id); |
145 | 145 | ||
146 | 146 | ||
147 | /** | 147 | /** |
@@ -149,8 +149,8 @@ RPS_sampler_count_id (struct RPS_Sampler *sampler, | |||
149 | * | 149 | * |
150 | * @param sampler the sampler to destroy. | 150 | * @param sampler the sampler to destroy. |
151 | */ | 151 | */ |
152 | void | 152 | void |
153 | RPS_sampler_destroy (struct RPS_Sampler *sampler); | 153 | RPS_sampler_destroy(struct RPS_Sampler *sampler); |
154 | 154 | ||
155 | #endif /* RPS_SAMPLER_CLIENT_H */ | 155 | #endif /* RPS_SAMPLER_CLIENT_H */ |
156 | /* end of gnunet-service-rps.c */ | 156 | /* end of gnunet-service-rps.c */ |
diff --git a/src/rps/rps-sampler_common.c b/src/rps/rps-sampler_common.c index adb69e1b5..48fa121b7 100644 --- a/src/rps/rps-sampler_common.c +++ b/src/rps/rps-sampler_common.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file rps/rps-sampler_common.c | 22 | * @file rps/rps-sampler_common.c |
@@ -35,15 +35,14 @@ | |||
35 | 35 | ||
36 | #include "rps-test_util.h" | 36 | #include "rps-test_util.h" |
37 | 37 | ||
38 | #define LOG(kind, ...) GNUNET_log_from(kind,"rps-sampler_common",__VA_ARGS__) | 38 | #define LOG(kind, ...) GNUNET_log_from(kind, "rps-sampler_common", __VA_ARGS__) |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * @brief Context for a callback. Contains callback and closure. | 41 | * @brief Context for a callback. Contains callback and closure. |
42 | * | 42 | * |
43 | * Meant to be an entry in an DLL. | 43 | * Meant to be an entry in an DLL. |
44 | */ | 44 | */ |
45 | struct SamplerNotifyUpdateCTX | 45 | struct SamplerNotifyUpdateCTX { |
46 | { | ||
47 | /** | 46 | /** |
48 | * @brief The Callback to call on updates | 47 | * @brief The Callback to call on updates |
49 | */ | 48 | */ |
@@ -69,8 +68,7 @@ struct SamplerNotifyUpdateCTX | |||
69 | /** | 68 | /** |
70 | * Closure to _get_n_rand_peers_ready_cb() | 69 | * Closure to _get_n_rand_peers_ready_cb() |
71 | */ | 70 | */ |
72 | struct RPS_SamplerRequestHandle | 71 | struct RPS_SamplerRequestHandle { |
73 | { | ||
74 | /** | 72 | /** |
75 | * DLL | 73 | * DLL |
76 | */ | 74 | */ |
@@ -118,8 +116,7 @@ struct RPS_SamplerRequestHandle | |||
118 | /** | 116 | /** |
119 | * Closure to _get_rand_peer_info() | 117 | * Closure to _get_rand_peer_info() |
120 | */ | 118 | */ |
121 | struct RPS_SamplerRequestHandleSingleInfo | 119 | struct RPS_SamplerRequestHandleSingleInfo { |
122 | { | ||
123 | /** | 120 | /** |
124 | * DLL | 121 | * DLL |
125 | */ | 122 | */ |
@@ -166,8 +163,8 @@ struct RPS_SamplerRequestHandleSingleInfo | |||
166 | * @param num_peers The estimated value | 163 | * @param num_peers The estimated value |
167 | */ | 164 | */ |
168 | void | 165 | void |
169 | RPS_sampler_update_with_nw_size (struct RPS_Sampler *sampler, | 166 | RPS_sampler_update_with_nw_size(struct RPS_Sampler *sampler, |
170 | uint32_t num_peers) | 167 | uint32_t num_peers) |
171 | { | 168 | { |
172 | sampler->num_peers_estim = num_peers; | 169 | sampler->num_peers_estim = num_peers; |
173 | } | 170 | } |
@@ -184,8 +181,8 @@ RPS_sampler_update_with_nw_size (struct RPS_Sampler *sampler, | |||
184 | * @param desired_probability | 181 | * @param desired_probability |
185 | */ | 182 | */ |
186 | void | 183 | void |
187 | RPS_sampler_set_desired_probability (struct RPS_Sampler *sampler, | 184 | RPS_sampler_set_desired_probability(struct RPS_Sampler *sampler, |
188 | double desired_probability) | 185 | double desired_probability) |
189 | { | 186 | { |
190 | sampler->desired_probability = desired_probability; | 187 | sampler->desired_probability = desired_probability; |
191 | } | 188 | } |
@@ -201,8 +198,8 @@ RPS_sampler_set_desired_probability (struct RPS_Sampler *sampler, | |||
201 | * @param desired_probability | 198 | * @param desired_probability |
202 | */ | 199 | */ |
203 | void | 200 | void |
204 | RPS_sampler_set_deficiency_factor (struct RPS_Sampler *sampler, | 201 | RPS_sampler_set_deficiency_factor(struct RPS_Sampler *sampler, |
205 | double deficiency_factor) | 202 | double deficiency_factor) |
206 | { | 203 | { |
207 | sampler->deficiency_factor = deficiency_factor; | 204 | sampler->deficiency_factor = deficiency_factor; |
208 | } | 205 | } |
@@ -219,20 +216,20 @@ RPS_sampler_set_deficiency_factor (struct RPS_Sampler *sampler, | |||
219 | * @return The context containing callback and closure | 216 | * @return The context containing callback and closure |
220 | */ | 217 | */ |
221 | struct SamplerNotifyUpdateCTX * | 218 | struct SamplerNotifyUpdateCTX * |
222 | sampler_notify_on_update (struct RPS_Sampler *sampler, | 219 | sampler_notify_on_update(struct RPS_Sampler *sampler, |
223 | SamplerNotifyUpdateCB notify_cb, | 220 | SamplerNotifyUpdateCB notify_cb, |
224 | void *cls) | 221 | void *cls) |
225 | { | 222 | { |
226 | struct SamplerNotifyUpdateCTX *notify_ctx; | 223 | struct SamplerNotifyUpdateCTX *notify_ctx; |
227 | 224 | ||
228 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 225 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
229 | "Inserting new context for notification\n"); | 226 | "Inserting new context for notification\n"); |
230 | notify_ctx = GNUNET_new (struct SamplerNotifyUpdateCTX); | 227 | notify_ctx = GNUNET_new(struct SamplerNotifyUpdateCTX); |
231 | notify_ctx->notify_cb = notify_cb; | 228 | notify_ctx->notify_cb = notify_cb; |
232 | notify_ctx->cls = cls; | 229 | notify_ctx->cls = cls; |
233 | GNUNET_CONTAINER_DLL_insert (sampler->notify_ctx_head, | 230 | GNUNET_CONTAINER_DLL_insert(sampler->notify_ctx_head, |
234 | sampler->notify_ctx_tail, | 231 | sampler->notify_ctx_tail, |
235 | notify_ctx); | 232 | notify_ctx); |
236 | return notify_ctx; | 233 | return notify_ctx; |
237 | } | 234 | } |
238 | 235 | ||
@@ -244,7 +241,7 @@ sampler_notify_on_update (struct RPS_Sampler *sampler, | |||
244 | * @return the size of the sampler | 241 | * @return the size of the sampler |
245 | */ | 242 | */ |
246 | unsigned int | 243 | unsigned int |
247 | RPS_sampler_get_size (struct RPS_Sampler *sampler) | 244 | RPS_sampler_get_size(struct RPS_Sampler *sampler) |
248 | { | 245 | { |
249 | return sampler->sampler_size; | 246 | return sampler->sampler_size; |
250 | } | 247 | } |
@@ -259,12 +256,12 @@ RPS_sampler_get_size (struct RPS_Sampler *sampler) | |||
259 | * @param sampler The sampler the updates are waiting for | 256 | * @param sampler The sampler the updates are waiting for |
260 | */ | 257 | */ |
261 | static void | 258 | static void |
262 | notify_update (struct RPS_Sampler *sampler) | 259 | notify_update(struct RPS_Sampler *sampler) |
263 | { | 260 | { |
264 | struct SamplerNotifyUpdateCTX *tmp_notify_head; | 261 | struct SamplerNotifyUpdateCTX *tmp_notify_head; |
265 | struct SamplerNotifyUpdateCTX *tmp_notify_tail; | 262 | struct SamplerNotifyUpdateCTX *tmp_notify_tail; |
266 | 263 | ||
267 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 264 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
268 | "Calling callbacks waiting for update notification.\n"); | 265 | "Calling callbacks waiting for update notification.\n"); |
269 | tmp_notify_head = sampler->notify_ctx_head; | 266 | tmp_notify_head = sampler->notify_ctx_head; |
270 | tmp_notify_tail = sampler->notify_ctx_tail; | 267 | tmp_notify_tail = sampler->notify_ctx_tail; |
@@ -273,14 +270,14 @@ notify_update (struct RPS_Sampler *sampler) | |||
273 | for (struct SamplerNotifyUpdateCTX *notify_iter = tmp_notify_head; | 270 | for (struct SamplerNotifyUpdateCTX *notify_iter = tmp_notify_head; |
274 | NULL != tmp_notify_head; | 271 | NULL != tmp_notify_head; |
275 | notify_iter = tmp_notify_head) | 272 | notify_iter = tmp_notify_head) |
276 | { | 273 | { |
277 | GNUNET_assert (NULL != notify_iter->notify_cb); | 274 | GNUNET_assert(NULL != notify_iter->notify_cb); |
278 | GNUNET_CONTAINER_DLL_remove (tmp_notify_head, | 275 | GNUNET_CONTAINER_DLL_remove(tmp_notify_head, |
279 | tmp_notify_tail, | 276 | tmp_notify_tail, |
280 | notify_iter); | 277 | notify_iter); |
281 | notify_iter->notify_cb (notify_iter->cls); | 278 | notify_iter->notify_cb(notify_iter->cls); |
282 | GNUNET_free (notify_iter); | 279 | GNUNET_free(notify_iter); |
283 | } | 280 | } |
284 | } | 281 | } |
285 | 282 | ||
286 | 283 | ||
@@ -290,16 +287,16 @@ notify_update (struct RPS_Sampler *sampler) | |||
290 | * @param sampler the sampler to update. | 287 | * @param sampler the sampler to update. |
291 | * @param id the PeerID that is put in the sampler | 288 | * @param id the PeerID that is put in the sampler |
292 | */ | 289 | */ |
293 | void | 290 | void |
294 | RPS_sampler_update (struct RPS_Sampler *sampler, | 291 | RPS_sampler_update(struct RPS_Sampler *sampler, |
295 | const struct GNUNET_PeerIdentity *id) | 292 | const struct GNUNET_PeerIdentity *id) |
296 | { | 293 | { |
297 | for (uint32_t i = 0; i < sampler->sampler_size; i++) | 294 | for (uint32_t i = 0; i < sampler->sampler_size; i++) |
298 | { | 295 | { |
299 | RPS_sampler_elem_next (sampler->sampler_elements[i], | 296 | RPS_sampler_elem_next(sampler->sampler_elements[i], |
300 | id); | 297 | id); |
301 | } | 298 | } |
302 | notify_update (sampler); | 299 | notify_update(sampler); |
303 | } | 300 | } |
304 | 301 | ||
305 | 302 | ||
@@ -317,21 +314,21 @@ RPS_sampler_update (struct RPS_Sampler *sampler, | |||
317 | * @param sampler the sampler to reinitialise a sampler element in. | 314 | * @param sampler the sampler to reinitialise a sampler element in. |
318 | * @param id the id of the sampler elements to update. | 315 | * @param id the id of the sampler elements to update. |
319 | */ | 316 | */ |
320 | void | 317 | void |
321 | RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler, | 318 | RPS_sampler_reinitialise_by_value(struct RPS_Sampler *sampler, |
322 | const struct GNUNET_PeerIdentity *id) | 319 | const struct GNUNET_PeerIdentity *id) |
323 | { | 320 | { |
324 | uint32_t i; | 321 | uint32_t i; |
325 | 322 | ||
326 | for (i = 0; i < sampler->sampler_size; i++) | 323 | for (i = 0; i < sampler->sampler_size; i++) |
327 | { | ||
328 | if (0 == GNUNET_memcmp(id, | ||
329 | &(sampler->sampler_elements[i]->peer_id)) ) | ||
330 | { | 324 | { |
331 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Reinitialising sampler\n"); | 325 | if (0 == GNUNET_memcmp(id, |
332 | RPS_sampler_elem_reinit (sampler->sampler_elements[i]); | 326 | &(sampler->sampler_elements[i]->peer_id))) |
327 | { | ||
328 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Reinitialising sampler\n"); | ||
329 | RPS_sampler_elem_reinit(sampler->sampler_elements[i]); | ||
330 | } | ||
333 | } | 331 | } |
334 | } | ||
335 | } | 332 | } |
336 | 333 | ||
337 | 334 | ||
@@ -343,20 +340,20 @@ RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler, | |||
343 | * | 340 | * |
344 | * @return the number of occurrences of id. | 341 | * @return the number of occurrences of id. |
345 | */ | 342 | */ |
346 | uint32_t | 343 | uint32_t |
347 | RPS_sampler_count_id (struct RPS_Sampler *sampler, | 344 | RPS_sampler_count_id(struct RPS_Sampler *sampler, |
348 | const struct GNUNET_PeerIdentity *id) | 345 | const struct GNUNET_PeerIdentity *id) |
349 | { | 346 | { |
350 | uint32_t count; | 347 | uint32_t count; |
351 | uint32_t i; | 348 | uint32_t i; |
352 | 349 | ||
353 | count = 0; | 350 | count = 0; |
354 | for ( i = 0 ; i < sampler->sampler_size ; i++ ) | 351 | for (i = 0; i < sampler->sampler_size; i++) |
355 | { | 352 | { |
356 | if ( 0 == GNUNET_memcmp (&sampler->sampler_elements[i]->peer_id, id) | 353 | if (0 == GNUNET_memcmp(&sampler->sampler_elements[i]->peer_id, id) |
357 | && EMPTY != sampler->sampler_elements[i]->is_empty) | 354 | && EMPTY != sampler->sampler_elements[i]->is_empty) |
358 | count++; | 355 | count++; |
359 | } | 356 | } |
360 | return count; | 357 | return count; |
361 | } | 358 | } |
362 | 359 | ||
@@ -368,7 +365,7 @@ RPS_sampler_count_id (struct RPS_Sampler *sampler, | |||
368 | * @param new_size the new size of the sampler | 365 | * @param new_size the new size of the sampler |
369 | */ | 366 | */ |
370 | static void | 367 | static void |
371 | sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size) | 368 | sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size) |
372 | { | 369 | { |
373 | unsigned int old_size; | 370 | unsigned int old_size; |
374 | uint32_t i; | 371 | uint32_t i; |
@@ -378,49 +375,47 @@ sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size) | |||
378 | old_size = sampler->sampler_size; | 375 | old_size = sampler->sampler_size; |
379 | 376 | ||
380 | if (old_size > new_size) | 377 | if (old_size > new_size) |
381 | { /* Shrinking */ | 378 | { /* Shrinking */ |
382 | 379 | LOG(GNUNET_ERROR_TYPE_DEBUG, | |
383 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 380 | "Shrinking sampler %d -> %d\n", |
384 | "Shrinking sampler %d -> %d\n", | 381 | old_size, |
385 | old_size, | 382 | new_size); |
386 | new_size); | 383 | |
387 | 384 | for (i = new_size; i < old_size; i++) | |
388 | for (i = new_size ; i < old_size ; i++) | 385 | { |
389 | { | 386 | RPS_sampler_elem_destroy(sampler->sampler_elements[i]); |
390 | RPS_sampler_elem_destroy (sampler->sampler_elements[i]); | 387 | } |
388 | |||
389 | GNUNET_array_grow(sampler->sampler_elements, | ||
390 | sampler->sampler_size, | ||
391 | new_size); | ||
392 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
393 | "sampler->sampler_elements now points to %p\n", | ||
394 | sampler->sampler_elements); | ||
391 | } | 395 | } |
392 | |||
393 | GNUNET_array_grow (sampler->sampler_elements, | ||
394 | sampler->sampler_size, | ||
395 | new_size); | ||
396 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
397 | "sampler->sampler_elements now points to %p\n", | ||
398 | sampler->sampler_elements); | ||
399 | |||
400 | } | ||
401 | else if (old_size < new_size) | 396 | else if (old_size < new_size) |
402 | { /* Growing */ | 397 | { /* Growing */ |
403 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 398 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
404 | "Growing sampler %d -> %d\n", | 399 | "Growing sampler %d -> %d\n", |
405 | old_size, | 400 | old_size, |
406 | new_size); | 401 | new_size); |
407 | 402 | ||
408 | GNUNET_array_grow (sampler->sampler_elements, | 403 | GNUNET_array_grow(sampler->sampler_elements, |
409 | sampler->sampler_size, | 404 | sampler->sampler_size, |
410 | new_size); | 405 | new_size); |
411 | 406 | ||
412 | for (i = old_size ; i < new_size ; i++) | 407 | for (i = old_size; i < new_size; i++) |
413 | { /* Add new sampler elements */ | 408 | { /* Add new sampler elements */ |
414 | sampler->sampler_elements[i] = RPS_sampler_elem_create (); | 409 | sampler->sampler_elements[i] = RPS_sampler_elem_create(); |
410 | } | ||
415 | } | 411 | } |
416 | } | ||
417 | else | 412 | else |
418 | { | 413 | { |
419 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Size remains the same -- nothing to do\n"); | 414 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Size remains the same -- nothing to do\n"); |
420 | return; | 415 | return; |
421 | } | 416 | } |
422 | 417 | ||
423 | GNUNET_assert (sampler->sampler_size == new_size); | 418 | GNUNET_assert(sampler->sampler_size == new_size); |
424 | } | 419 | } |
425 | 420 | ||
426 | 421 | ||
@@ -431,10 +426,10 @@ sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size) | |||
431 | * @param new_size the new size of the sampler | 426 | * @param new_size the new size of the sampler |
432 | */ | 427 | */ |
433 | void | 428 | void |
434 | RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size) | 429 | RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size) |
435 | { | 430 | { |
436 | GNUNET_assert (0 < new_size); | 431 | GNUNET_assert(0 < new_size); |
437 | sampler_resize (sampler, new_size); | 432 | sampler_resize(sampler, new_size); |
438 | } | 433 | } |
439 | 434 | ||
440 | 435 | ||
@@ -445,9 +440,9 @@ RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size) | |||
445 | * @param new_size the new size of the sampler | 440 | * @param new_size the new size of the sampler |
446 | */ | 441 | */ |
447 | static void | 442 | static void |
448 | sampler_empty (struct RPS_Sampler *sampler) | 443 | sampler_empty(struct RPS_Sampler *sampler) |
449 | { | 444 | { |
450 | sampler_resize (sampler, 0); | 445 | sampler_resize(sampler, 0); |
451 | } | 446 | } |
452 | 447 | ||
453 | 448 | ||
@@ -464,47 +459,48 @@ sampler_empty (struct RPS_Sampler *sampler) | |||
464 | * @param num_observed How many ids this sampler has observed | 459 | * @param num_observed How many ids this sampler has observed |
465 | */ | 460 | */ |
466 | static void | 461 | static void |
467 | check_n_peers_ready (void *cls, | 462 | check_n_peers_ready(void *cls, |
468 | const struct GNUNET_PeerIdentity *id, | 463 | const struct GNUNET_PeerIdentity *id, |
469 | double probability, | 464 | double probability, |
470 | uint32_t num_observed) | 465 | uint32_t num_observed) |
471 | { | 466 | { |
472 | struct RPS_SamplerRequestHandle *req_handle = cls; | 467 | struct RPS_SamplerRequestHandle *req_handle = cls; |
473 | (void) id; | 468 | |
469 | (void)id; | ||
474 | RPS_sampler_n_rand_peers_ready_cb tmp_cb; | 470 | RPS_sampler_n_rand_peers_ready_cb tmp_cb; |
475 | struct GNUNET_PeerIdentity *peers; | 471 | struct GNUNET_PeerIdentity *peers; |
476 | uint32_t num_peers; | 472 | uint32_t num_peers; |
477 | void *cb_cls; | 473 | void *cb_cls; |
478 | (void) probability; | 474 | (void)probability; |
479 | (void) num_observed; | 475 | (void)num_observed; |
480 | 476 | ||
481 | req_handle->cur_num_peers++; | 477 | req_handle->cur_num_peers++; |
482 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 478 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
483 | "Got %" PRIX32 ". of %" PRIX32 " peers\n", | 479 | "Got %" PRIX32 ". of %" PRIX32 " peers\n", |
484 | req_handle->cur_num_peers, req_handle->num_peers); | 480 | req_handle->cur_num_peers, req_handle->num_peers); |
485 | 481 | ||
486 | if (req_handle->num_peers == req_handle->cur_num_peers) | 482 | if (req_handle->num_peers == req_handle->cur_num_peers) |
487 | { /* All peers are ready -- return those to the client */ | 483 | { /* All peers are ready -- return those to the client */ |
488 | GNUNET_assert (NULL != req_handle->callback); | 484 | GNUNET_assert(NULL != req_handle->callback); |
489 | 485 | ||
490 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 486 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
491 | "returning %" PRIX32 " peers to the client\n", | 487 | "returning %" PRIX32 " peers to the client\n", |
492 | req_handle->num_peers); | 488 | req_handle->num_peers); |
493 | 489 | ||
494 | /* Copy pointers and peers temporarily as they | 490 | /* Copy pointers and peers temporarily as they |
495 | * might be deleted from within the callback */ | 491 | * might be deleted from within the callback */ |
496 | tmp_cb = req_handle->callback; | 492 | tmp_cb = req_handle->callback; |
497 | num_peers = req_handle->num_peers; | 493 | num_peers = req_handle->num_peers; |
498 | peers = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity); | 494 | peers = GNUNET_new_array(num_peers, struct GNUNET_PeerIdentity); |
499 | GNUNET_memcpy (peers, | 495 | GNUNET_memcpy(peers, |
500 | req_handle->ids, | 496 | req_handle->ids, |
501 | num_peers * sizeof (struct GNUNET_PeerIdentity)); | 497 | num_peers * sizeof(struct GNUNET_PeerIdentity)); |
502 | cb_cls = req_handle->cls; | 498 | cb_cls = req_handle->cls; |
503 | RPS_sampler_request_cancel (req_handle); | 499 | RPS_sampler_request_cancel(req_handle); |
504 | req_handle = NULL; | 500 | req_handle = NULL; |
505 | tmp_cb (peers, num_peers, cb_cls); | 501 | tmp_cb(peers, num_peers, cb_cls); |
506 | GNUNET_free (peers); | 502 | GNUNET_free(peers); |
507 | } | 503 | } |
508 | } | 504 | } |
509 | 505 | ||
510 | 506 | ||
@@ -519,39 +515,40 @@ check_n_peers_ready (void *cls, | |||
519 | * @param num_observed How many ids this sampler has observed | 515 | * @param num_observed How many ids this sampler has observed |
520 | */ | 516 | */ |
521 | static void | 517 | static void |
522 | check_peer_info_ready (void *cls, | 518 | check_peer_info_ready(void *cls, |
523 | const struct GNUNET_PeerIdentity *id, | 519 | const struct GNUNET_PeerIdentity *id, |
524 | double probability, | 520 | double probability, |
525 | uint32_t num_observed) | 521 | uint32_t num_observed) |
526 | { | 522 | { |
527 | struct RPS_SamplerRequestHandleSingleInfo *req_handle = cls; | 523 | struct RPS_SamplerRequestHandleSingleInfo *req_handle = cls; |
528 | (void) id; | 524 | |
525 | (void)id; | ||
529 | RPS_sampler_sinlge_info_ready_cb tmp_cb; | 526 | RPS_sampler_sinlge_info_ready_cb tmp_cb; |
530 | struct GNUNET_PeerIdentity *peer; | 527 | struct GNUNET_PeerIdentity *peer; |
531 | void *cb_cls; | 528 | void *cb_cls; |
532 | (void) probability; | 529 | (void)probability; |
533 | (void) num_observed; | 530 | (void)num_observed; |
534 | 531 | ||
535 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 532 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
536 | "Got single peer with additional info\n"); | 533 | "Got single peer with additional info\n"); |
537 | 534 | ||
538 | GNUNET_assert (NULL != req_handle->callback); | 535 | GNUNET_assert(NULL != req_handle->callback); |
539 | 536 | ||
540 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 537 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
541 | "returning single peer with info to the client\n"); | 538 | "returning single peer with info to the client\n"); |
542 | 539 | ||
543 | /* Copy pointers and peers temporarily as they | 540 | /* Copy pointers and peers temporarily as they |
544 | * might be deleted from within the callback */ | 541 | * might be deleted from within the callback */ |
545 | tmp_cb = req_handle->callback; | 542 | tmp_cb = req_handle->callback; |
546 | peer = GNUNET_new (struct GNUNET_PeerIdentity); | 543 | peer = GNUNET_new(struct GNUNET_PeerIdentity); |
547 | GNUNET_memcpy (peer, | 544 | GNUNET_memcpy(peer, |
548 | req_handle->id, | 545 | req_handle->id, |
549 | sizeof (struct GNUNET_PeerIdentity)); | 546 | sizeof(struct GNUNET_PeerIdentity)); |
550 | cb_cls = req_handle->cls; | 547 | cb_cls = req_handle->cls; |
551 | RPS_sampler_request_single_info_cancel (req_handle); | 548 | RPS_sampler_request_single_info_cancel(req_handle); |
552 | req_handle = NULL; | 549 | req_handle = NULL; |
553 | tmp_cb (peer, cb_cls, probability, num_observed); | 550 | tmp_cb(peer, cb_cls, probability, num_observed); |
554 | GNUNET_free (peer); | 551 | GNUNET_free(peer); |
555 | } | 552 | } |
556 | 553 | ||
557 | 554 | ||
@@ -568,50 +565,50 @@ check_peer_info_ready (void *cls, | |||
568 | * @param num_peers the number of peers requested | 565 | * @param num_peers the number of peers requested |
569 | */ | 566 | */ |
570 | struct RPS_SamplerRequestHandle * | 567 | struct RPS_SamplerRequestHandle * |
571 | RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler, | 568 | RPS_sampler_get_n_rand_peers(struct RPS_Sampler *sampler, |
572 | uint32_t num_peers, | 569 | uint32_t num_peers, |
573 | RPS_sampler_n_rand_peers_ready_cb cb, | 570 | RPS_sampler_n_rand_peers_ready_cb cb, |
574 | void *cls) | 571 | void *cls) |
575 | { | 572 | { |
576 | uint32_t i; | 573 | uint32_t i; |
577 | struct RPS_SamplerRequestHandle *req_handle; | 574 | struct RPS_SamplerRequestHandle *req_handle; |
578 | struct GetPeerCls *gpc; | 575 | struct GetPeerCls *gpc; |
579 | 576 | ||
580 | GNUNET_assert (0 != sampler->sampler_size); | 577 | GNUNET_assert(0 != sampler->sampler_size); |
581 | if (0 == num_peers) | 578 | if (0 == num_peers) |
582 | return NULL; | 579 | return NULL; |
583 | 580 | ||
584 | // TODO check if we have too much (distinct) sampled peers | 581 | // TODO check if we have too much (distinct) sampled peers |
585 | req_handle = GNUNET_new (struct RPS_SamplerRequestHandle); | 582 | req_handle = GNUNET_new(struct RPS_SamplerRequestHandle); |
586 | req_handle->num_peers = num_peers; | 583 | req_handle->num_peers = num_peers; |
587 | req_handle->cur_num_peers = 0; | 584 | req_handle->cur_num_peers = 0; |
588 | req_handle->ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity); | 585 | req_handle->ids = GNUNET_new_array(num_peers, struct GNUNET_PeerIdentity); |
589 | req_handle->sampler = sampler; | 586 | req_handle->sampler = sampler; |
590 | req_handle->callback = cb; | 587 | req_handle->callback = cb; |
591 | req_handle->cls = cls; | 588 | req_handle->cls = cls; |
592 | GNUNET_CONTAINER_DLL_insert (sampler->req_handle_head, | 589 | GNUNET_CONTAINER_DLL_insert(sampler->req_handle_head, |
593 | sampler->req_handle_tail, | 590 | sampler->req_handle_tail, |
594 | req_handle); | 591 | req_handle); |
595 | 592 | ||
596 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 593 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
597 | "Scheduling requests for %" PRIu32 " peers\n", num_peers); | 594 | "Scheduling requests for %" PRIu32 " peers\n", num_peers); |
598 | 595 | ||
599 | for (i = 0; i < num_peers; i++) | 596 | for (i = 0; i < num_peers; i++) |
600 | { | 597 | { |
601 | gpc = GNUNET_new (struct GetPeerCls); | 598 | gpc = GNUNET_new(struct GetPeerCls); |
602 | gpc->req_handle = req_handle; | 599 | gpc->req_handle = req_handle; |
603 | gpc->req_single_info_handle = NULL; | 600 | gpc->req_single_info_handle = NULL; |
604 | gpc->cont = check_n_peers_ready; | 601 | gpc->cont = check_n_peers_ready; |
605 | gpc->cont_cls = req_handle; | 602 | gpc->cont_cls = req_handle; |
606 | gpc->id = &req_handle->ids[i]; | 603 | gpc->id = &req_handle->ids[i]; |
607 | 604 | ||
608 | GNUNET_CONTAINER_DLL_insert (req_handle->gpc_head, | 605 | GNUNET_CONTAINER_DLL_insert(req_handle->gpc_head, |
609 | req_handle->gpc_tail, | 606 | req_handle->gpc_tail, |
610 | gpc); | 607 | gpc); |
611 | // maybe add a little delay | 608 | // maybe add a little delay |
612 | gpc->get_peer_task = GNUNET_SCHEDULER_add_now (sampler->get_peers, | 609 | gpc->get_peer_task = GNUNET_SCHEDULER_add_now(sampler->get_peers, |
613 | gpc); | 610 | gpc); |
614 | } | 611 | } |
615 | return req_handle; | 612 | return req_handle; |
616 | } | 613 | } |
617 | 614 | ||
@@ -624,38 +621,38 @@ RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler, | |||
624 | * @param cls closure given to @a cb | 621 | * @param cls closure given to @a cb |
625 | */ | 622 | */ |
626 | struct RPS_SamplerRequestHandleSingleInfo * | 623 | struct RPS_SamplerRequestHandleSingleInfo * |
627 | RPS_sampler_get_rand_peer_info (struct RPS_Sampler *sampler, | 624 | RPS_sampler_get_rand_peer_info(struct RPS_Sampler *sampler, |
628 | RPS_sampler_sinlge_info_ready_cb cb, | 625 | RPS_sampler_sinlge_info_ready_cb cb, |
629 | void *cls) | 626 | void *cls) |
630 | { | 627 | { |
631 | struct RPS_SamplerRequestHandleSingleInfo *req_handle; | 628 | struct RPS_SamplerRequestHandleSingleInfo *req_handle; |
632 | struct GetPeerCls *gpc; | 629 | struct GetPeerCls *gpc; |
633 | 630 | ||
634 | GNUNET_assert (0 != sampler->sampler_size); | 631 | GNUNET_assert(0 != sampler->sampler_size); |
635 | 632 | ||
636 | // TODO check if we have too much (distinct) sampled peers | 633 | // TODO check if we have too much (distinct) sampled peers |
637 | req_handle = GNUNET_new (struct RPS_SamplerRequestHandleSingleInfo); | 634 | req_handle = GNUNET_new(struct RPS_SamplerRequestHandleSingleInfo); |
638 | req_handle->id = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 635 | req_handle->id = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); |
639 | req_handle->sampler = sampler; | 636 | req_handle->sampler = sampler; |
640 | req_handle->callback = cb; | 637 | req_handle->callback = cb; |
641 | req_handle->cls = cls; | 638 | req_handle->cls = cls; |
642 | GNUNET_CONTAINER_DLL_insert (sampler->req_handle_single_head, | 639 | GNUNET_CONTAINER_DLL_insert(sampler->req_handle_single_head, |
643 | sampler->req_handle_single_tail, | 640 | sampler->req_handle_single_tail, |
644 | req_handle); | 641 | req_handle); |
645 | 642 | ||
646 | gpc = GNUNET_new (struct GetPeerCls); | 643 | gpc = GNUNET_new(struct GetPeerCls); |
647 | gpc->req_handle = NULL; | 644 | gpc->req_handle = NULL; |
648 | gpc->req_single_info_handle = req_handle; | 645 | gpc->req_single_info_handle = req_handle; |
649 | gpc->cont = check_peer_info_ready; | 646 | gpc->cont = check_peer_info_ready; |
650 | gpc->cont_cls = req_handle; | 647 | gpc->cont_cls = req_handle; |
651 | gpc->id = req_handle->id; | 648 | gpc->id = req_handle->id; |
652 | 649 | ||
653 | GNUNET_CONTAINER_DLL_insert (req_handle->gpc_head, | 650 | GNUNET_CONTAINER_DLL_insert(req_handle->gpc_head, |
654 | req_handle->gpc_tail, | 651 | req_handle->gpc_tail, |
655 | gpc); | 652 | gpc); |
656 | // maybe add a little delay | 653 | // maybe add a little delay |
657 | gpc->get_peer_task = GNUNET_SCHEDULER_add_now (sampler->get_peers, | 654 | gpc->get_peer_task = GNUNET_SCHEDULER_add_now(sampler->get_peers, |
658 | gpc); | 655 | gpc); |
659 | return req_handle; | 656 | return req_handle; |
660 | } | 657 | } |
661 | 658 | ||
@@ -666,35 +663,35 @@ RPS_sampler_get_rand_peer_info (struct RPS_Sampler *sampler, | |||
666 | * @param req_handle the handle to the request | 663 | * @param req_handle the handle to the request |
667 | */ | 664 | */ |
668 | void | 665 | void |
669 | RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle) | 666 | RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle) |
670 | { | 667 | { |
671 | struct GetPeerCls *i; | 668 | struct GetPeerCls *i; |
672 | 669 | ||
673 | while (NULL != (i = req_handle->gpc_head) ) | 670 | while (NULL != (i = req_handle->gpc_head)) |
674 | { | ||
675 | GNUNET_CONTAINER_DLL_remove (req_handle->gpc_head, | ||
676 | req_handle->gpc_tail, | ||
677 | i); | ||
678 | if (NULL != i->get_peer_task) | ||
679 | { | ||
680 | GNUNET_SCHEDULER_cancel (i->get_peer_task); | ||
681 | } | ||
682 | if (NULL != i->notify_ctx) | ||
683 | { | 671 | { |
684 | GNUNET_CONTAINER_DLL_remove (req_handle->sampler->notify_ctx_head, | 672 | GNUNET_CONTAINER_DLL_remove(req_handle->gpc_head, |
685 | req_handle->sampler->notify_ctx_tail, | 673 | req_handle->gpc_tail, |
686 | i->notify_ctx); | 674 | i); |
687 | GNUNET_free (i->notify_ctx); | 675 | if (NULL != i->get_peer_task) |
688 | i->notify_ctx = NULL; | 676 | { |
677 | GNUNET_SCHEDULER_cancel(i->get_peer_task); | ||
678 | } | ||
679 | if (NULL != i->notify_ctx) | ||
680 | { | ||
681 | GNUNET_CONTAINER_DLL_remove(req_handle->sampler->notify_ctx_head, | ||
682 | req_handle->sampler->notify_ctx_tail, | ||
683 | i->notify_ctx); | ||
684 | GNUNET_free(i->notify_ctx); | ||
685 | i->notify_ctx = NULL; | ||
686 | } | ||
687 | GNUNET_free(i); | ||
689 | } | 688 | } |
690 | GNUNET_free (i); | 689 | GNUNET_free(req_handle->ids); |
691 | } | ||
692 | GNUNET_free (req_handle->ids); | ||
693 | req_handle->ids = NULL; | 690 | req_handle->ids = NULL; |
694 | GNUNET_CONTAINER_DLL_remove (req_handle->sampler->req_handle_head, | 691 | GNUNET_CONTAINER_DLL_remove(req_handle->sampler->req_handle_head, |
695 | req_handle->sampler->req_handle_tail, | 692 | req_handle->sampler->req_handle_tail, |
696 | req_handle); | 693 | req_handle); |
697 | GNUNET_free (req_handle); | 694 | GNUNET_free(req_handle); |
698 | } | 695 | } |
699 | 696 | ||
700 | 697 | ||
@@ -704,56 +701,56 @@ RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle) | |||
704 | * @param req_handle the handle to the request | 701 | * @param req_handle the handle to the request |
705 | */ | 702 | */ |
706 | void | 703 | void |
707 | RPS_sampler_request_single_info_cancel ( | 704 | RPS_sampler_request_single_info_cancel( |
708 | struct RPS_SamplerRequestHandleSingleInfo *req_single_info_handle) | 705 | struct RPS_SamplerRequestHandleSingleInfo *req_single_info_handle) |
709 | { | 706 | { |
710 | struct GetPeerCls *i; | 707 | struct GetPeerCls *i; |
711 | 708 | ||
712 | while (NULL != (i = req_single_info_handle->gpc_head) ) | 709 | while (NULL != (i = req_single_info_handle->gpc_head)) |
713 | { | ||
714 | GNUNET_CONTAINER_DLL_remove (req_single_info_handle->gpc_head, | ||
715 | req_single_info_handle->gpc_tail, | ||
716 | i); | ||
717 | if (NULL != i->get_peer_task) | ||
718 | { | 710 | { |
719 | GNUNET_SCHEDULER_cancel (i->get_peer_task); | 711 | GNUNET_CONTAINER_DLL_remove(req_single_info_handle->gpc_head, |
712 | req_single_info_handle->gpc_tail, | ||
713 | i); | ||
714 | if (NULL != i->get_peer_task) | ||
715 | { | ||
716 | GNUNET_SCHEDULER_cancel(i->get_peer_task); | ||
717 | } | ||
718 | if (NULL != i->notify_ctx) | ||
719 | { | ||
720 | GNUNET_CONTAINER_DLL_remove(req_single_info_handle->sampler->notify_ctx_head, | ||
721 | req_single_info_handle->sampler->notify_ctx_tail, | ||
722 | i->notify_ctx); | ||
723 | GNUNET_free(i->notify_ctx); | ||
724 | i->notify_ctx = NULL; | ||
725 | } | ||
726 | GNUNET_free(i); | ||
720 | } | 727 | } |
721 | if (NULL != i->notify_ctx) | 728 | GNUNET_free(req_single_info_handle->id); |
722 | { | ||
723 | GNUNET_CONTAINER_DLL_remove (req_single_info_handle->sampler->notify_ctx_head, | ||
724 | req_single_info_handle->sampler->notify_ctx_tail, | ||
725 | i->notify_ctx); | ||
726 | GNUNET_free (i->notify_ctx); | ||
727 | i->notify_ctx = NULL; | ||
728 | } | ||
729 | GNUNET_free (i); | ||
730 | } | ||
731 | GNUNET_free (req_single_info_handle->id); | ||
732 | req_single_info_handle->id = NULL; | 729 | req_single_info_handle->id = NULL; |
733 | GNUNET_CONTAINER_DLL_remove (req_single_info_handle->sampler->req_handle_single_head, | 730 | GNUNET_CONTAINER_DLL_remove(req_single_info_handle->sampler->req_handle_single_head, |
734 | req_single_info_handle->sampler->req_handle_single_tail, | 731 | req_single_info_handle->sampler->req_handle_single_tail, |
735 | req_single_info_handle); | 732 | req_single_info_handle); |
736 | GNUNET_free (req_single_info_handle); | 733 | GNUNET_free(req_single_info_handle); |
737 | } | 734 | } |
738 | 735 | ||
739 | 736 | ||
740 | /** | 737 | /** |
741 | * Cleans the sampler. | 738 | * Cleans the sampler. |
742 | */ | 739 | */ |
743 | void | 740 | void |
744 | RPS_sampler_destroy (struct RPS_Sampler *sampler) | 741 | RPS_sampler_destroy(struct RPS_Sampler *sampler) |
745 | { | 742 | { |
746 | if (NULL != sampler->req_handle_head) | 743 | if (NULL != sampler->req_handle_head) |
747 | { | ||
748 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
749 | "There are still pending requests. Going to remove them.\n"); | ||
750 | while (NULL != sampler->req_handle_head) | ||
751 | { | 744 | { |
752 | RPS_sampler_request_cancel (sampler->req_handle_head); | 745 | LOG(GNUNET_ERROR_TYPE_WARNING, |
746 | "There are still pending requests. Going to remove them.\n"); | ||
747 | while (NULL != sampler->req_handle_head) | ||
748 | { | ||
749 | RPS_sampler_request_cancel(sampler->req_handle_head); | ||
750 | } | ||
753 | } | 751 | } |
754 | } | 752 | sampler_empty(sampler); |
755 | sampler_empty (sampler); | 753 | GNUNET_free(sampler); |
756 | GNUNET_free (sampler); | ||
757 | } | 754 | } |
758 | 755 | ||
759 | 756 | ||
diff --git a/src/rps/rps-sampler_common.h b/src/rps/rps-sampler_common.h index 321efaf1e..4a45c0193 100644 --- a/src/rps/rps-sampler_common.h +++ b/src/rps/rps-sampler_common.h | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file rps/rps-sampler_common.h | 22 | * @file rps/rps-sampler_common.h |
@@ -69,7 +69,7 @@ typedef void | |||
69 | * @param ids the PeerIDs that were returned | 69 | * @param ids the PeerIDs that were returned |
70 | * to be freed | 70 | * to be freed |
71 | */ | 71 | */ |
72 | typedef void | 72 | typedef void |
73 | (*RPS_sampler_n_rand_peers_ready_cb) (const struct GNUNET_PeerIdentity *ids, | 73 | (*RPS_sampler_n_rand_peers_ready_cb) (const struct GNUNET_PeerIdentity *ids, |
74 | uint32_t num_peers, | 74 | uint32_t num_peers, |
75 | void *cls); | 75 | void *cls); |
@@ -84,7 +84,7 @@ typedef void | |||
84 | * @param ids the PeerIDs that were returned | 84 | * @param ids the PeerIDs that were returned |
85 | * to be freed | 85 | * to be freed |
86 | */ | 86 | */ |
87 | typedef void | 87 | typedef void |
88 | (*RPS_sampler_sinlge_info_ready_cb) (const struct GNUNET_PeerIdentity *ids, | 88 | (*RPS_sampler_sinlge_info_ready_cb) (const struct GNUNET_PeerIdentity *ids, |
89 | void *cls, | 89 | void *cls, |
90 | double probability, | 90 | double probability, |
@@ -103,8 +103,7 @@ typedef void | |||
103 | /** | 103 | /** |
104 | * Closure for #sampler_mod_get_rand_peer() and #sampler_get_rand_peer | 104 | * Closure for #sampler_mod_get_rand_peer() and #sampler_get_rand_peer |
105 | */ | 105 | */ |
106 | struct GetPeerCls | 106 | struct GetPeerCls { |
107 | { | ||
108 | /** | 107 | /** |
109 | * DLL | 108 | * DLL |
110 | */ | 109 | */ |
@@ -151,8 +150,7 @@ struct GetPeerCls | |||
151 | /** | 150 | /** |
152 | * Sampler with its own array of SamplerElements | 151 | * Sampler with its own array of SamplerElements |
153 | */ | 152 | */ |
154 | struct RPS_Sampler | 153 | struct RPS_Sampler { |
155 | { | ||
156 | /** | 154 | /** |
157 | * Number of sampler elements we hold. | 155 | * Number of sampler elements we hold. |
158 | */ | 156 | */ |
@@ -222,8 +220,8 @@ struct RPS_Sampler | |||
222 | * @param num_peers The estimated value | 220 | * @param num_peers The estimated value |
223 | */ | 221 | */ |
224 | void | 222 | void |
225 | RPS_sampler_update_with_nw_size (struct RPS_Sampler *sampler, | 223 | RPS_sampler_update_with_nw_size(struct RPS_Sampler *sampler, |
226 | uint32_t num_peers); | 224 | uint32_t num_peers); |
227 | 225 | ||
228 | 226 | ||
229 | /** | 227 | /** |
@@ -237,8 +235,8 @@ RPS_sampler_update_with_nw_size (struct RPS_Sampler *sampler, | |||
237 | * @param desired_probability | 235 | * @param desired_probability |
238 | */ | 236 | */ |
239 | void | 237 | void |
240 | RPS_sampler_set_desired_probability (struct RPS_Sampler *sampler, | 238 | RPS_sampler_set_desired_probability(struct RPS_Sampler *sampler, |
241 | double desired_probability); | 239 | double desired_probability); |
242 | 240 | ||
243 | 241 | ||
244 | /** | 242 | /** |
@@ -251,8 +249,8 @@ RPS_sampler_set_desired_probability (struct RPS_Sampler *sampler, | |||
251 | * @param desired_probability | 249 | * @param desired_probability |
252 | */ | 250 | */ |
253 | void | 251 | void |
254 | RPS_sampler_set_deficiency_factor (struct RPS_Sampler *sampler, | 252 | RPS_sampler_set_deficiency_factor(struct RPS_Sampler *sampler, |
255 | double deficiency_factor); | 253 | double deficiency_factor); |
256 | 254 | ||
257 | 255 | ||
258 | /** | 256 | /** |
@@ -266,9 +264,9 @@ RPS_sampler_set_deficiency_factor (struct RPS_Sampler *sampler, | |||
266 | * @return The context containing callback and closure | 264 | * @return The context containing callback and closure |
267 | */ | 265 | */ |
268 | struct SamplerNotifyUpdateCTX * | 266 | struct SamplerNotifyUpdateCTX * |
269 | sampler_notify_on_update (struct RPS_Sampler *sampler, | 267 | sampler_notify_on_update(struct RPS_Sampler *sampler, |
270 | SamplerNotifyUpdateCB notify_cb, | 268 | SamplerNotifyUpdateCB notify_cb, |
271 | void *cls); | 269 | void *cls); |
272 | 270 | ||
273 | 271 | ||
274 | /** | 272 | /** |
@@ -277,9 +275,9 @@ sampler_notify_on_update (struct RPS_Sampler *sampler, | |||
277 | * @param sampler the sampler to update. | 275 | * @param sampler the sampler to update. |
278 | * @param id the PeerID that is put in the sampler | 276 | * @param id the PeerID that is put in the sampler |
279 | */ | 277 | */ |
280 | void | 278 | void |
281 | RPS_sampler_update (struct RPS_Sampler *sampler, | 279 | RPS_sampler_update(struct RPS_Sampler *sampler, |
282 | const struct GNUNET_PeerIdentity *id); | 280 | const struct GNUNET_PeerIdentity *id); |
283 | 281 | ||
284 | 282 | ||
285 | /** | 283 | /** |
@@ -290,9 +288,9 @@ RPS_sampler_update (struct RPS_Sampler *sampler, | |||
290 | * @param sampler the sampler to reinitialise a sampler element in. | 288 | * @param sampler the sampler to reinitialise a sampler element in. |
291 | * @param id the id of the sampler elements to update. | 289 | * @param id the id of the sampler elements to update. |
292 | */ | 290 | */ |
293 | void | 291 | void |
294 | RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler, | 292 | RPS_sampler_reinitialise_by_value(struct RPS_Sampler *sampler, |
295 | const struct GNUNET_PeerIdentity *id); | 293 | const struct GNUNET_PeerIdentity *id); |
296 | 294 | ||
297 | 295 | ||
298 | /** | 296 | /** |
@@ -302,7 +300,7 @@ RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler, | |||
302 | * @return the size of the sampler | 300 | * @return the size of the sampler |
303 | */ | 301 | */ |
304 | unsigned int | 302 | unsigned int |
305 | RPS_sampler_get_size (struct RPS_Sampler *sampler); | 303 | RPS_sampler_get_size(struct RPS_Sampler *sampler); |
306 | 304 | ||
307 | 305 | ||
308 | /** | 306 | /** |
@@ -312,7 +310,7 @@ RPS_sampler_get_size (struct RPS_Sampler *sampler); | |||
312 | * @param new_size the new size of the sampler | 310 | * @param new_size the new size of the sampler |
313 | */ | 311 | */ |
314 | void | 312 | void |
315 | RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size); | 313 | RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size); |
316 | 314 | ||
317 | 315 | ||
318 | /** | 316 | /** |
@@ -330,10 +328,10 @@ RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size); | |||
330 | * @param num_peers the number of peers requested | 328 | * @param num_peers the number of peers requested |
331 | */ | 329 | */ |
332 | struct RPS_SamplerRequestHandle * | 330 | struct RPS_SamplerRequestHandle * |
333 | RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler, | 331 | RPS_sampler_get_n_rand_peers(struct RPS_Sampler *sampler, |
334 | uint32_t num_peers, | 332 | uint32_t num_peers, |
335 | RPS_sampler_n_rand_peers_ready_cb cb, | 333 | RPS_sampler_n_rand_peers_ready_cb cb, |
336 | void *cls); | 334 | void *cls); |
337 | 335 | ||
338 | 336 | ||
339 | /** | 337 | /** |
@@ -344,9 +342,9 @@ RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler, | |||
344 | * @param cls closure given to @a cb | 342 | * @param cls closure given to @a cb |
345 | */ | 343 | */ |
346 | struct RPS_SamplerRequestHandleSingleInfo * | 344 | struct RPS_SamplerRequestHandleSingleInfo * |
347 | RPS_sampler_get_rand_peer_info (struct RPS_Sampler *sampler, | 345 | RPS_sampler_get_rand_peer_info(struct RPS_Sampler *sampler, |
348 | RPS_sampler_sinlge_info_ready_cb cb, | 346 | RPS_sampler_sinlge_info_ready_cb cb, |
349 | void *cls); | 347 | void *cls); |
350 | 348 | ||
351 | 349 | ||
352 | /** | 350 | /** |
@@ -357,9 +355,9 @@ RPS_sampler_get_rand_peer_info (struct RPS_Sampler *sampler, | |||
357 | * | 355 | * |
358 | * @return the number of occurrences of id. | 356 | * @return the number of occurrences of id. |
359 | */ | 357 | */ |
360 | uint32_t | 358 | uint32_t |
361 | RPS_sampler_count_id (struct RPS_Sampler *sampler, | 359 | RPS_sampler_count_id(struct RPS_Sampler *sampler, |
362 | const struct GNUNET_PeerIdentity *id); | 360 | const struct GNUNET_PeerIdentity *id); |
363 | 361 | ||
364 | 362 | ||
365 | /** | 363 | /** |
@@ -368,7 +366,7 @@ RPS_sampler_count_id (struct RPS_Sampler *sampler, | |||
368 | * @param req_handle the handle to the request | 366 | * @param req_handle the handle to the request |
369 | */ | 367 | */ |
370 | void | 368 | void |
371 | RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle); | 369 | RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle); |
372 | 370 | ||
373 | 371 | ||
374 | /** | 372 | /** |
@@ -377,15 +375,15 @@ RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle); | |||
377 | * @param req_handle the handle to the request | 375 | * @param req_handle the handle to the request |
378 | */ | 376 | */ |
379 | void | 377 | void |
380 | RPS_sampler_request_single_info_cancel ( | 378 | RPS_sampler_request_single_info_cancel( |
381 | struct RPS_SamplerRequestHandleSingleInfo *req_single_info_handle); | 379 | struct RPS_SamplerRequestHandleSingleInfo *req_single_info_handle); |
382 | 380 | ||
383 | 381 | ||
384 | /** | 382 | /** |
385 | * Cleans the sampler. | 383 | * Cleans the sampler. |
386 | */ | 384 | */ |
387 | void | 385 | void |
388 | RPS_sampler_destroy (struct RPS_Sampler *sampler); | 386 | RPS_sampler_destroy(struct RPS_Sampler *sampler); |
389 | 387 | ||
390 | #endif /* RPS_SAMPLER_COMMON_H */ | 388 | #endif /* RPS_SAMPLER_COMMON_H */ |
391 | /* end of rps-sampler_common.h */ | 389 | /* end of rps-sampler_common.h */ |
diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c index ab023a7a6..8680494f8 100644 --- a/src/rps/rps-test_util.c +++ b/src/rps/rps-test_util.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file rps/rps-test_util.c | 22 | * @file rps/rps-test_util.c |
@@ -32,7 +32,7 @@ | |||
32 | 32 | ||
33 | #include <inttypes.h> | 33 | #include <inttypes.h> |
34 | 34 | ||
35 | #define LOG(kind, ...) GNUNET_log_from(kind,"rps-test_util",__VA_ARGS__) | 35 | #define LOG(kind, ...) GNUNET_log_from(kind, "rps-test_util", __VA_ARGS__) |
36 | 36 | ||
37 | #define B2B_PAT "%c%c%c%c%c%c%c%c" | 37 | #define B2B_PAT "%c%c%c%c%c%c%c%c" |
38 | #define B2B(byte) \ | 38 | #define B2B(byte) \ |
@@ -72,43 +72,43 @@ static struct GNUNET_CONTAINER_MultiHashMap *open_files; | |||
72 | * @return File handle | 72 | * @return File handle |
73 | */ | 73 | */ |
74 | struct GNUNET_DISK_FileHandle * | 74 | struct GNUNET_DISK_FileHandle * |
75 | get_file_handle (const char *name) | 75 | get_file_handle(const char *name) |
76 | { | 76 | { |
77 | struct GNUNET_HashCode hash; | 77 | struct GNUNET_HashCode hash; |
78 | struct GNUNET_DISK_FileHandle *fh; | 78 | struct GNUNET_DISK_FileHandle *fh; |
79 | 79 | ||
80 | if (NULL == open_files) | 80 | if (NULL == open_files) |
81 | { | 81 | { |
82 | open_files = GNUNET_CONTAINER_multihashmap_create (16, | 82 | open_files = GNUNET_CONTAINER_multihashmap_create(16, |
83 | GNUNET_NO); | 83 | GNUNET_NO); |
84 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 84 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
85 | "Created map of open files.\n"); | 85 | "Created map of open files.\n"); |
86 | } | 86 | } |
87 | GNUNET_CRYPTO_hash (name, | 87 | GNUNET_CRYPTO_hash(name, |
88 | strlen (name), | 88 | strlen(name), |
89 | &hash); | 89 | &hash); |
90 | if (NULL != (fh = GNUNET_CONTAINER_multihashmap_get (open_files, | 90 | if (NULL != (fh = GNUNET_CONTAINER_multihashmap_get(open_files, |
91 | &hash))) | 91 | &hash))) |
92 | return fh; | 92 | return fh; |
93 | fh = GNUNET_DISK_file_open (name, | 93 | fh = GNUNET_DISK_file_open(name, |
94 | GNUNET_DISK_OPEN_WRITE | | 94 | GNUNET_DISK_OPEN_WRITE | |
95 | GNUNET_DISK_OPEN_CREATE | | 95 | GNUNET_DISK_OPEN_CREATE | |
96 | GNUNET_DISK_OPEN_APPEND, | 96 | GNUNET_DISK_OPEN_APPEND, |
97 | GNUNET_DISK_PERM_USER_READ | | 97 | GNUNET_DISK_PERM_USER_READ | |
98 | GNUNET_DISK_PERM_USER_WRITE | | 98 | GNUNET_DISK_PERM_USER_WRITE | |
99 | GNUNET_DISK_PERM_GROUP_READ); | 99 | GNUNET_DISK_PERM_GROUP_READ); |
100 | if (NULL == fh) | 100 | if (NULL == fh) |
101 | { | 101 | { |
102 | LOG (GNUNET_ERROR_TYPE_ERROR, | 102 | LOG(GNUNET_ERROR_TYPE_ERROR, |
103 | "Opening file `%s' failed.\n", | 103 | "Opening file `%s' failed.\n", |
104 | name); | 104 | name); |
105 | GNUNET_assert (0); | 105 | GNUNET_assert(0); |
106 | } | 106 | } |
107 | GNUNET_assert (GNUNET_YES == | 107 | GNUNET_assert(GNUNET_YES == |
108 | GNUNET_CONTAINER_multihashmap_put (open_files, | 108 | GNUNET_CONTAINER_multihashmap_put(open_files, |
109 | &hash, | 109 | &hash, |
110 | fh, | 110 | fh, |
111 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 111 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
112 | return fh; | 112 | return fh; |
113 | } | 113 | } |
114 | 114 | ||
@@ -127,18 +127,18 @@ get_file_handle (const char *name) | |||
127 | * #GNUNET_NO if not. | 127 | * #GNUNET_NO if not. |
128 | */ | 128 | */ |
129 | int | 129 | int |
130 | close_files_iter (void *cls, | 130 | close_files_iter(void *cls, |
131 | const struct GNUNET_HashCode *key, | 131 | const struct GNUNET_HashCode *key, |
132 | void *value) | 132 | void *value) |
133 | { | 133 | { |
134 | (void) cls; | 134 | (void)cls; |
135 | (void) key; | 135 | (void)key; |
136 | struct GNUNET_DISK_FileHandle *fh = value; | 136 | struct GNUNET_DISK_FileHandle *fh = value; |
137 | 137 | ||
138 | if (NULL != fh) | 138 | if (NULL != fh) |
139 | { | 139 | { |
140 | GNUNET_DISK_file_close (fh); | 140 | GNUNET_DISK_file_close(fh); |
141 | } | 141 | } |
142 | return GNUNET_YES; | 142 | return GNUNET_YES; |
143 | } | 143 | } |
144 | 144 | ||
@@ -149,14 +149,14 @@ close_files_iter (void *cls, | |||
149 | * @return Success of iterating over files | 149 | * @return Success of iterating over files |
150 | */ | 150 | */ |
151 | int | 151 | int |
152 | close_all_files () | 152 | close_all_files() |
153 | { | 153 | { |
154 | int ret; | 154 | int ret; |
155 | 155 | ||
156 | ret = GNUNET_CONTAINER_multihashmap_iterate (open_files, | 156 | ret = GNUNET_CONTAINER_multihashmap_iterate(open_files, |
157 | close_files_iter, | 157 | close_files_iter, |
158 | NULL); | 158 | NULL); |
159 | GNUNET_CONTAINER_multihashmap_destroy (open_files); | 159 | GNUNET_CONTAINER_multihashmap_destroy(open_files); |
160 | open_files = NULL; | 160 | open_files = NULL; |
161 | return ret; | 161 | return ret; |
162 | } | 162 | } |
@@ -164,56 +164,56 @@ close_all_files () | |||
164 | 164 | ||
165 | 165 | ||
166 | void | 166 | void |
167 | to_file_raw (const char *file_name, const char *buf, size_t size_buf) | 167 | to_file_raw(const char *file_name, const char *buf, size_t size_buf) |
168 | { | 168 | { |
169 | struct GNUNET_DISK_FileHandle *f; | 169 | struct GNUNET_DISK_FileHandle *f; |
170 | size_t size_written; | 170 | size_t size_written; |
171 | 171 | ||
172 | if (NULL == (f = GNUNET_DISK_file_open (file_name, | 172 | if (NULL == (f = GNUNET_DISK_file_open(file_name, |
173 | GNUNET_DISK_OPEN_APPEND | | 173 | GNUNET_DISK_OPEN_APPEND | |
174 | GNUNET_DISK_OPEN_WRITE | | 174 | GNUNET_DISK_OPEN_WRITE | |
175 | GNUNET_DISK_OPEN_CREATE, | 175 | GNUNET_DISK_OPEN_CREATE, |
176 | GNUNET_DISK_PERM_USER_READ | | 176 | GNUNET_DISK_PERM_USER_READ | |
177 | GNUNET_DISK_PERM_USER_WRITE | | 177 | GNUNET_DISK_PERM_USER_WRITE | |
178 | GNUNET_DISK_PERM_GROUP_READ | | 178 | GNUNET_DISK_PERM_GROUP_READ | |
179 | GNUNET_DISK_PERM_OTHER_READ))) | 179 | GNUNET_DISK_PERM_OTHER_READ))) |
180 | { | 180 | { |
181 | LOG (GNUNET_ERROR_TYPE_WARNING, | 181 | LOG(GNUNET_ERROR_TYPE_WARNING, |
182 | "Not able to open file %s\n", | 182 | "Not able to open file %s\n", |
183 | file_name); | 183 | file_name); |
184 | return; | 184 | return; |
185 | } | 185 | } |
186 | 186 | ||
187 | size_written = GNUNET_DISK_file_write (f, buf, size_buf); | 187 | size_written = GNUNET_DISK_file_write(f, buf, size_buf); |
188 | if (size_buf != size_written) | 188 | if (size_buf != size_written) |
189 | { | 189 | { |
190 | LOG (GNUNET_ERROR_TYPE_WARNING, | 190 | LOG(GNUNET_ERROR_TYPE_WARNING, |
191 | "Unable to write to file! (Size: %u, size_written: %u)\n", | 191 | "Unable to write to file! (Size: %u, size_written: %u)\n", |
192 | size_buf, | 192 | size_buf, |
193 | size_written); | 193 | size_written); |
194 | 194 | ||
195 | if (GNUNET_YES != GNUNET_DISK_file_close (f)) | 195 | if (GNUNET_YES != GNUNET_DISK_file_close(f)) |
196 | LOG (GNUNET_ERROR_TYPE_WARNING, | 196 | LOG(GNUNET_ERROR_TYPE_WARNING, |
197 | "Unable to close file\n"); | 197 | "Unable to close file\n"); |
198 | 198 | ||
199 | return; | 199 | return; |
200 | } | 200 | } |
201 | LOG (GNUNET_ERROR_TYPE_WARNING, | 201 | LOG(GNUNET_ERROR_TYPE_WARNING, |
202 | "Wrote %u bytes raw.\n", | 202 | "Wrote %u bytes raw.\n", |
203 | size_written); | 203 | size_written); |
204 | if (GNUNET_YES != GNUNET_DISK_file_close (f)) | 204 | if (GNUNET_YES != GNUNET_DISK_file_close(f)) |
205 | LOG (GNUNET_ERROR_TYPE_WARNING, | 205 | LOG(GNUNET_ERROR_TYPE_WARNING, |
206 | "Unable to close file\n"); | 206 | "Unable to close file\n"); |
207 | } | 207 | } |
208 | 208 | ||
209 | void | 209 | void |
210 | to_file_raw_unaligned (const char *file_name, | 210 | to_file_raw_unaligned(const char *file_name, |
211 | const char *buf, | 211 | const char *buf, |
212 | size_t size_buf, | 212 | size_t size_buf, |
213 | unsigned bits_needed) | 213 | unsigned bits_needed) |
214 | { | 214 | { |
215 | // TODO endianness! | 215 | // TODO endianness! |
216 | GNUNET_assert (size_buf >= (bits_needed/8)); | 216 | GNUNET_assert(size_buf >= (bits_needed / 8)); |
217 | //if (0 == num_bits_buf_unaligned) | 217 | //if (0 == num_bits_buf_unaligned) |
218 | //{ | 218 | //{ |
219 | // if (0 == (bits_needed % 8)) | 219 | // if (0 == (bits_needed % 8)) |
@@ -226,190 +226,190 @@ to_file_raw_unaligned (const char *file_name, | |||
226 | // num_bits_buf_unaligned = bits_needed % 8; | 226 | // num_bits_buf_unaligned = bits_needed % 8; |
227 | // return; | 227 | // return; |
228 | //} | 228 | //} |
229 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 229 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
230 | "Was asked to write %u bits\n", bits_needed); | 230 | "Was asked to write %u bits\n", bits_needed); |
231 | 231 | ||
232 | char buf_write[size_buf + 1]; | 232 | char buf_write[size_buf + 1]; |
233 | const unsigned bytes_iter = (0 != bits_needed % 8? | 233 | const unsigned bytes_iter = (0 != bits_needed % 8 ? |
234 | (bits_needed/8)+1: | 234 | (bits_needed / 8) + 1 : |
235 | bits_needed/8); | 235 | bits_needed / 8); |
236 | // TODO what if no iteration happens? | 236 | // TODO what if no iteration happens? |
237 | unsigned size_buf_write = 0; | 237 | unsigned size_buf_write = 0; |
238 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 238 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
239 | "num_bits_buf_unaligned: %u\n", | 239 | "num_bits_buf_unaligned: %u\n", |
240 | num_bits_buf_unaligned); | 240 | num_bits_buf_unaligned); |
241 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 241 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
242 | "ua args: size_buf: %u, bits_needed: %u -> iter: %u\n", | 242 | "ua args: size_buf: %u, bits_needed: %u -> iter: %u\n", |
243 | size_buf, | 243 | size_buf, |
244 | bits_needed, | 244 | bits_needed, |
245 | bytes_iter); | 245 | bytes_iter); |
246 | buf_write[0] = buf_unaligned; | 246 | buf_write[0] = buf_unaligned; |
247 | /* Iterate over input bytes */ | 247 | /* Iterate over input bytes */ |
248 | for (unsigned i = 0; i < bytes_iter; i++) | 248 | for (unsigned i = 0; i < bytes_iter; i++) |
249 | { | ||
250 | /* Number of bits needed in this iteration - 8 for all except last iter */ | ||
251 | unsigned num_bits_needed_iter; | ||
252 | /* Mask for bits to actually use */ | ||
253 | unsigned mask_bits_needed_iter; | ||
254 | char byte_input; | ||
255 | /* Number of bits needed to align unaligned byte */ | ||
256 | unsigned num_bits_to_align; | ||
257 | /* Number of bits that are to be moved */ | ||
258 | unsigned num_bits_to_move; | ||
259 | /* Mask for bytes to be moved */ | ||
260 | char mask_input_to_move; | ||
261 | /* Masked bits to be moved */ | ||
262 | char bits_to_move; | ||
263 | /* The amount of bits needed to fit the bits to shift to the nearest spot */ | ||
264 | unsigned distance_shift_bits; | ||
265 | /* Shifted bits on the move */ | ||
266 | char bits_moving; | ||
267 | /* (unaligned) byte being filled with bits */ | ||
268 | char byte_to_fill; | ||
269 | /* mask for needed bits of the input byte that have not been moved */ | ||
270 | char mask_input_leftover; | ||
271 | /* needed bits of the input byte that have not been moved */ | ||
272 | char byte_input_leftover; | ||
273 | unsigned num_bits_leftover; | ||
274 | //unsigned num_bits_discard; | ||
275 | char byte_unaligned_new; | ||
276 | |||
277 | if ( (bits_needed - (i * 8)) <= 8) | ||
278 | { | ||
279 | /* last iteration */ | ||
280 | num_bits_needed_iter = bits_needed - (i * 8); | ||
281 | } | ||
282 | else | ||
283 | { | ||
284 | num_bits_needed_iter = 8; | ||
285 | } | ||
286 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
287 | "number of bits needed in this iteration: %u\n", | ||
288 | num_bits_needed_iter); | ||
289 | mask_bits_needed_iter = ((char) 1 << num_bits_needed_iter) - 1; | ||
290 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
291 | "mask needed bits (current iter): "B2B_PAT"\n", | ||
292 | B2B(mask_bits_needed_iter)); | ||
293 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
294 | "Unaligned byte: "B2B_PAT" (%u bits)\n", | ||
295 | B2B(buf_unaligned), | ||
296 | num_bits_buf_unaligned); | ||
297 | byte_input = buf[i]; | ||
298 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
299 | "next whole input byte: "B2B_PAT"\n", | ||
300 | B2B(byte_input)); | ||
301 | byte_input &= mask_bits_needed_iter; | ||
302 | num_bits_to_align = 8 - num_bits_buf_unaligned; | ||
303 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
304 | "input byte, needed bits: "B2B_PAT"\n", | ||
305 | B2B(byte_input)); | ||
306 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
307 | "number of bits needed to align unaligned bit: %u\n", | ||
308 | num_bits_to_align); | ||
309 | num_bits_to_move = GNUNET_MIN (num_bits_to_align, num_bits_needed_iter); | ||
310 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
311 | "number of bits of new byte to move: %u\n", | ||
312 | num_bits_to_move); | ||
313 | mask_input_to_move = ((char) 1 << num_bits_to_move) - 1; | ||
314 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
315 | "mask of bits of new byte to take for moving: "B2B_PAT"\n", | ||
316 | B2B(mask_input_to_move)); | ||
317 | bits_to_move = byte_input & mask_input_to_move; | ||
318 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
319 | "masked bits of new byte to take for moving: "B2B_PAT"\n", | ||
320 | B2B(bits_to_move)); | ||
321 | distance_shift_bits = num_bits_buf_unaligned; | ||
322 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
323 | "distance needed to shift bits to their correct spot: %u\n", | ||
324 | distance_shift_bits); | ||
325 | bits_moving = bits_to_move << distance_shift_bits; | ||
326 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
327 | "shifted, masked bits of new byte being moved: "B2B_PAT"\n", | ||
328 | B2B(bits_moving)); | ||
329 | byte_to_fill = buf_unaligned | bits_moving; | ||
330 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
331 | "byte being filled: "B2B_PAT"\n", | ||
332 | B2B(byte_to_fill)); | ||
333 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
334 | "pending bytes: %u\n", | ||
335 | num_bits_buf_unaligned + num_bits_needed_iter); | ||
336 | if (num_bits_buf_unaligned + num_bits_needed_iter >= 8) | ||
337 | { | ||
338 | /* buf_unaligned was aligned by filling | ||
339 | * -> can be written to storage */ | ||
340 | buf_write[i] = byte_to_fill; | ||
341 | size_buf_write++; | ||
342 | |||
343 | /* store the leftover, unaligned bits in buffer */ | ||
344 | mask_input_leftover = mask_bits_needed_iter & (~ mask_input_to_move); | ||
345 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
346 | "mask of leftover bits of new byte: "B2B_PAT"\n", | ||
347 | B2B(mask_input_leftover)); | ||
348 | byte_input_leftover = byte_input & mask_input_leftover; | ||
349 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
350 | "masked, leftover bits of new byte: "B2B_PAT"\n", | ||
351 | B2B(byte_input_leftover)); | ||
352 | num_bits_leftover = num_bits_needed_iter - num_bits_to_move; | ||
353 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
354 | "number of unaligned bits left: %u\n", | ||
355 | num_bits_leftover); | ||
356 | //num_bits_discard = 8 - num_bits_needed_iter; | ||
357 | byte_unaligned_new = byte_input_leftover >> num_bits_to_move; | ||
358 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
359 | "new unaligned byte: "B2B_PAT"\n", | ||
360 | B2B(byte_unaligned_new)); | ||
361 | buf_unaligned = byte_unaligned_new; | ||
362 | num_bits_buf_unaligned = num_bits_leftover % 8; | ||
363 | } | ||
364 | else | ||
365 | { | 249 | { |
366 | /* unaligned buffer still unaligned but 'fuller' */ | 250 | /* Number of bits needed in this iteration - 8 for all except last iter */ |
367 | buf_unaligned = byte_to_fill; | 251 | unsigned num_bits_needed_iter; |
368 | num_bits_buf_unaligned = (num_bits_buf_unaligned + bits_needed) % 8; | 252 | /* Mask for bits to actually use */ |
253 | unsigned mask_bits_needed_iter; | ||
254 | char byte_input; | ||
255 | /* Number of bits needed to align unaligned byte */ | ||
256 | unsigned num_bits_to_align; | ||
257 | /* Number of bits that are to be moved */ | ||
258 | unsigned num_bits_to_move; | ||
259 | /* Mask for bytes to be moved */ | ||
260 | char mask_input_to_move; | ||
261 | /* Masked bits to be moved */ | ||
262 | char bits_to_move; | ||
263 | /* The amount of bits needed to fit the bits to shift to the nearest spot */ | ||
264 | unsigned distance_shift_bits; | ||
265 | /* Shifted bits on the move */ | ||
266 | char bits_moving; | ||
267 | /* (unaligned) byte being filled with bits */ | ||
268 | char byte_to_fill; | ||
269 | /* mask for needed bits of the input byte that have not been moved */ | ||
270 | char mask_input_leftover; | ||
271 | /* needed bits of the input byte that have not been moved */ | ||
272 | char byte_input_leftover; | ||
273 | unsigned num_bits_leftover; | ||
274 | //unsigned num_bits_discard; | ||
275 | char byte_unaligned_new; | ||
276 | |||
277 | if ((bits_needed - (i * 8)) <= 8) | ||
278 | { | ||
279 | /* last iteration */ | ||
280 | num_bits_needed_iter = bits_needed - (i * 8); | ||
281 | } | ||
282 | else | ||
283 | { | ||
284 | num_bits_needed_iter = 8; | ||
285 | } | ||
286 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
287 | "number of bits needed in this iteration: %u\n", | ||
288 | num_bits_needed_iter); | ||
289 | mask_bits_needed_iter = ((char)1 << num_bits_needed_iter) - 1; | ||
290 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
291 | "mask needed bits (current iter): "B2B_PAT "\n", | ||
292 | B2B(mask_bits_needed_iter)); | ||
293 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
294 | "Unaligned byte: "B2B_PAT " (%u bits)\n", | ||
295 | B2B(buf_unaligned), | ||
296 | num_bits_buf_unaligned); | ||
297 | byte_input = buf[i]; | ||
298 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
299 | "next whole input byte: "B2B_PAT "\n", | ||
300 | B2B(byte_input)); | ||
301 | byte_input &= mask_bits_needed_iter; | ||
302 | num_bits_to_align = 8 - num_bits_buf_unaligned; | ||
303 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
304 | "input byte, needed bits: "B2B_PAT "\n", | ||
305 | B2B(byte_input)); | ||
306 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
307 | "number of bits needed to align unaligned bit: %u\n", | ||
308 | num_bits_to_align); | ||
309 | num_bits_to_move = GNUNET_MIN(num_bits_to_align, num_bits_needed_iter); | ||
310 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
311 | "number of bits of new byte to move: %u\n", | ||
312 | num_bits_to_move); | ||
313 | mask_input_to_move = ((char)1 << num_bits_to_move) - 1; | ||
314 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
315 | "mask of bits of new byte to take for moving: "B2B_PAT "\n", | ||
316 | B2B(mask_input_to_move)); | ||
317 | bits_to_move = byte_input & mask_input_to_move; | ||
318 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
319 | "masked bits of new byte to take for moving: "B2B_PAT "\n", | ||
320 | B2B(bits_to_move)); | ||
321 | distance_shift_bits = num_bits_buf_unaligned; | ||
322 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
323 | "distance needed to shift bits to their correct spot: %u\n", | ||
324 | distance_shift_bits); | ||
325 | bits_moving = bits_to_move << distance_shift_bits; | ||
326 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
327 | "shifted, masked bits of new byte being moved: "B2B_PAT "\n", | ||
328 | B2B(bits_moving)); | ||
329 | byte_to_fill = buf_unaligned | bits_moving; | ||
330 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
331 | "byte being filled: "B2B_PAT "\n", | ||
332 | B2B(byte_to_fill)); | ||
333 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
334 | "pending bytes: %u\n", | ||
335 | num_bits_buf_unaligned + num_bits_needed_iter); | ||
336 | if (num_bits_buf_unaligned + num_bits_needed_iter >= 8) | ||
337 | { | ||
338 | /* buf_unaligned was aligned by filling | ||
339 | * -> can be written to storage */ | ||
340 | buf_write[i] = byte_to_fill; | ||
341 | size_buf_write++; | ||
342 | |||
343 | /* store the leftover, unaligned bits in buffer */ | ||
344 | mask_input_leftover = mask_bits_needed_iter & (~mask_input_to_move); | ||
345 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
346 | "mask of leftover bits of new byte: "B2B_PAT "\n", | ||
347 | B2B(mask_input_leftover)); | ||
348 | byte_input_leftover = byte_input & mask_input_leftover; | ||
349 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
350 | "masked, leftover bits of new byte: "B2B_PAT "\n", | ||
351 | B2B(byte_input_leftover)); | ||
352 | num_bits_leftover = num_bits_needed_iter - num_bits_to_move; | ||
353 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
354 | "number of unaligned bits left: %u\n", | ||
355 | num_bits_leftover); | ||
356 | //num_bits_discard = 8 - num_bits_needed_iter; | ||
357 | byte_unaligned_new = byte_input_leftover >> num_bits_to_move; | ||
358 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
359 | "new unaligned byte: "B2B_PAT "\n", | ||
360 | B2B(byte_unaligned_new)); | ||
361 | buf_unaligned = byte_unaligned_new; | ||
362 | num_bits_buf_unaligned = num_bits_leftover % 8; | ||
363 | } | ||
364 | else | ||
365 | { | ||
366 | /* unaligned buffer still unaligned but 'fuller' */ | ||
367 | buf_unaligned = byte_to_fill; | ||
368 | num_bits_buf_unaligned = (num_bits_buf_unaligned + bits_needed) % 8; | ||
369 | } | ||
369 | } | 370 | } |
370 | } | 371 | to_file_raw(file_name, buf_write, size_buf_write); |
371 | to_file_raw (file_name, buf_write, size_buf_write); | 372 | LOG(GNUNET_ERROR_TYPE_DEBUG, "\n"); |
372 | LOG (GNUNET_ERROR_TYPE_DEBUG, "\n"); | ||
373 | } | 373 | } |
374 | 374 | ||
375 | char * | 375 | char * |
376 | auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key) | 376 | auth_key_to_string(struct GNUNET_CRYPTO_AuthKey auth_key) |
377 | { | 377 | { |
378 | int size; | 378 | int size; |
379 | size_t name_buf_size; | 379 | size_t name_buf_size; |
380 | char *end; | 380 | char *end; |
381 | char *buf; | 381 | char *buf; |
382 | char *name_buf; | 382 | char *name_buf; |
383 | size_t keylen = (sizeof (struct GNUNET_CRYPTO_AuthKey)) * 8; | 383 | size_t keylen = (sizeof(struct GNUNET_CRYPTO_AuthKey)) * 8; |
384 | 384 | ||
385 | name_buf_size = 512 * sizeof (char); | 385 | name_buf_size = 512 * sizeof(char); |
386 | name_buf = GNUNET_malloc (name_buf_size); | 386 | name_buf = GNUNET_malloc(name_buf_size); |
387 | 387 | ||
388 | if (keylen % 5 > 0) | 388 | if (keylen % 5 > 0) |
389 | keylen += 5 - keylen % 5; | 389 | keylen += 5 - keylen % 5; |
390 | keylen /= 5; | 390 | keylen /= 5; |
391 | buf = GNUNET_malloc (keylen + 1); | 391 | buf = GNUNET_malloc(keylen + 1); |
392 | 392 | ||
393 | end = GNUNET_STRINGS_data_to_string (&(auth_key.key), | 393 | end = GNUNET_STRINGS_data_to_string(&(auth_key.key), |
394 | sizeof (struct GNUNET_CRYPTO_AuthKey), | 394 | sizeof(struct GNUNET_CRYPTO_AuthKey), |
395 | buf, | 395 | buf, |
396 | keylen); | 396 | keylen); |
397 | 397 | ||
398 | if (NULL == end) | 398 | if (NULL == end) |
399 | { | 399 | { |
400 | GNUNET_free (buf); | 400 | GNUNET_free(buf); |
401 | GNUNET_break (0); | 401 | GNUNET_break(0); |
402 | } | 402 | } |
403 | else | 403 | else |
404 | { | 404 | { |
405 | *end = '\0'; | 405 | *end = '\0'; |
406 | } | 406 | } |
407 | 407 | ||
408 | size = GNUNET_snprintf (name_buf, name_buf_size, "sampler_el-%s", buf); | 408 | size = GNUNET_snprintf(name_buf, name_buf_size, "sampler_el-%s", buf); |
409 | if (0 > size) | 409 | if (0 > size) |
410 | LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to create name_buf\n"); | 410 | LOG(GNUNET_ERROR_TYPE_WARNING, "Failed to create name_buf\n"); |
411 | 411 | ||
412 | GNUNET_free (buf); | 412 | GNUNET_free(buf); |
413 | 413 | ||
414 | return name_buf; | 414 | return name_buf; |
415 | } | 415 | } |
@@ -418,18 +418,18 @@ auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key) | |||
418 | 418 | ||
419 | 419 | ||
420 | struct GNUNET_CRYPTO_AuthKey | 420 | struct GNUNET_CRYPTO_AuthKey |
421 | string_to_auth_key (const char *str) | 421 | string_to_auth_key(const char *str) |
422 | { | 422 | { |
423 | struct GNUNET_CRYPTO_AuthKey auth_key; | 423 | struct GNUNET_CRYPTO_AuthKey auth_key; |
424 | 424 | ||
425 | if (GNUNET_OK != | 425 | if (GNUNET_OK != |
426 | GNUNET_STRINGS_string_to_data (str, | 426 | GNUNET_STRINGS_string_to_data(str, |
427 | strlen (str), | 427 | strlen(str), |
428 | &auth_key.key, | 428 | &auth_key.key, |
429 | sizeof (struct GNUNET_CRYPTO_AuthKey))) | 429 | sizeof(struct GNUNET_CRYPTO_AuthKey))) |
430 | { | 430 | { |
431 | LOG (GNUNET_ERROR_TYPE_WARNING, "Failed to convert string to data\n"); | 431 | LOG(GNUNET_ERROR_TYPE_WARNING, "Failed to convert string to data\n"); |
432 | } | 432 | } |
433 | 433 | ||
434 | return auth_key; | 434 | return auth_key; |
435 | } | 435 | } |
@@ -442,59 +442,60 @@ string_to_auth_key (const char *str) | |||
442 | * #GNUNET_SYSERR on failure | 442 | * #GNUNET_SYSERR on failure |
443 | */ | 443 | */ |
444 | static int | 444 | static int |
445 | ensure_folder_exist (void) | 445 | ensure_folder_exist(void) |
446 | { | 446 | { |
447 | if (GNUNET_OK != | 447 | if (GNUNET_OK != |
448 | GNUNET_DISK_directory_create ("/tmp/rps")) | 448 | GNUNET_DISK_directory_create("/tmp/rps")) |
449 | { | 449 | { |
450 | LOG (GNUNET_ERROR_TYPE_ERROR, | 450 | LOG(GNUNET_ERROR_TYPE_ERROR, |
451 | "Could not create directory `/tmp/rps'\n"); | 451 | "Could not create directory `/tmp/rps'\n"); |
452 | return GNUNET_SYSERR; | 452 | return GNUNET_SYSERR; |
453 | } | 453 | } |
454 | return GNUNET_YES; | 454 | return GNUNET_YES; |
455 | } | 455 | } |
456 | 456 | ||
457 | 457 | ||
458 | char * | 458 | char * |
459 | store_prefix_file_name (const unsigned int index, | 459 | store_prefix_file_name(const unsigned int index, |
460 | const char *prefix) | 460 | const char *prefix) |
461 | { | 461 | { |
462 | int len_file_name; | 462 | int len_file_name; |
463 | int out_size; | 463 | int out_size; |
464 | char *file_name; | 464 | char *file_name; |
465 | char index_str[64]; | 465 | char index_str[64]; |
466 | 466 | ||
467 | if (GNUNET_SYSERR == ensure_folder_exist()) return NULL; | 467 | if (GNUNET_SYSERR == ensure_folder_exist()) |
468 | out_size = GNUNET_snprintf (index_str, | 468 | return NULL; |
469 | 64, | 469 | out_size = GNUNET_snprintf(index_str, |
470 | "%u", | 470 | 64, |
471 | index); | 471 | "%u", |
472 | index); | ||
472 | if (64 < out_size || | 473 | if (64 < out_size || |
473 | 0 > out_size) | 474 | 0 > out_size) |
474 | { | 475 | { |
475 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 476 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
476 | "Failed to write string to buffer (size: %i, out_size: %i)\n", | 477 | "Failed to write string to buffer (size: %i, out_size: %i)\n", |
477 | 64, | 478 | 64, |
478 | out_size); | 479 | out_size); |
479 | } | 480 | } |
480 | len_file_name = (strlen (prefix) + | 481 | len_file_name = (strlen(prefix) + |
481 | strlen (index_str) + | 482 | strlen(index_str) + |
482 | 11) | 483 | 11) |
483 | * sizeof (char); | 484 | * sizeof(char); |
484 | file_name = GNUNET_malloc (len_file_name); | 485 | file_name = GNUNET_malloc(len_file_name); |
485 | out_size = GNUNET_snprintf (file_name, | 486 | out_size = GNUNET_snprintf(file_name, |
486 | len_file_name, | 487 | len_file_name, |
487 | "/tmp/rps/%s-%s", | 488 | "/tmp/rps/%s-%s", |
488 | prefix, | 489 | prefix, |
489 | index_str); | 490 | index_str); |
490 | if (len_file_name < out_size || | 491 | if (len_file_name < out_size || |
491 | 0 > out_size) | 492 | 0 > out_size) |
492 | { | 493 | { |
493 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 494 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
494 | "Failed to write string to buffer (size: %i, out_size: %i)\n", | 495 | "Failed to write string to buffer (size: %i, out_size: %i)\n", |
495 | len_file_name, | 496 | len_file_name, |
496 | out_size); | 497 | out_size); |
497 | } | 498 | } |
498 | return file_name; | 499 | return file_name; |
499 | } | 500 | } |
500 | 501 | ||
@@ -506,13 +507,13 @@ store_prefix_file_name (const unsigned int index, | |||
506 | * | 507 | * |
507 | * @return Factorial of @a x | 508 | * @return Factorial of @a x |
508 | */ | 509 | */ |
509 | uint32_t fac (uint32_t x) | 510 | uint32_t fac(uint32_t x) |
510 | { | 511 | { |
511 | if (1 >= x) | 512 | if (1 >= x) |
512 | { | 513 | { |
513 | return x; | 514 | return x; |
514 | } | 515 | } |
515 | return x * fac (x - 1); | 516 | return x * fac(x - 1); |
516 | } | 517 | } |
517 | 518 | ||
518 | /** | 519 | /** |
@@ -523,16 +524,18 @@ uint32_t fac (uint32_t x) | |||
523 | * | 524 | * |
524 | * @return Binomial coefficient of @a n and @a k | 525 | * @return Binomial coefficient of @a n and @a k |
525 | */ | 526 | */ |
526 | uint32_t binom (uint32_t n, uint32_t k) | 527 | uint32_t binom(uint32_t n, uint32_t k) |
527 | { | 528 | { |
528 | //GNUNET_assert (n >= k); | 529 | //GNUNET_assert (n >= k); |
529 | if (k > n) return 0; | 530 | if (k > n) |
531 | return 0; | ||
530 | /* if (0 > n) return 0; - always false */ | 532 | /* if (0 > n) return 0; - always false */ |
531 | /* if (0 > k) return 0; - always false */ | 533 | /* if (0 > k) return 0; - always false */ |
532 | if (0 == k) return 1; | 534 | if (0 == k) |
533 | return fac (n) | 535 | return 1; |
534 | / | 536 | return fac(n) |
535 | fac(k) * fac(n - k); | 537 | / |
538 | fac(k) * fac(n - k); | ||
536 | } | 539 | } |
537 | 540 | ||
538 | 541 | ||
diff --git a/src/rps/rps-test_util.h b/src/rps/rps-test_util.h index 5aa0688d5..f978059c3 100644 --- a/src/rps/rps-test_util.h +++ b/src/rps/rps-test_util.h | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file rps/rps-test_util.h | 22 | * @file rps/rps-test_util.h |
@@ -32,10 +32,10 @@ | |||
32 | 32 | ||
33 | 33 | ||
34 | char * | 34 | char * |
35 | auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key); | 35 | auth_key_to_string(struct GNUNET_CRYPTO_AuthKey auth_key); |
36 | 36 | ||
37 | struct GNUNET_CRYPTO_AuthKey | 37 | struct GNUNET_CRYPTO_AuthKey |
38 | string_to_auth_key (const char *str); | 38 | string_to_auth_key(const char *str); |
39 | 39 | ||
40 | 40 | ||
41 | /** | 41 | /** |
@@ -48,7 +48,7 @@ string_to_auth_key (const char *str); | |||
48 | * @return File handle | 48 | * @return File handle |
49 | */ | 49 | */ |
50 | struct GNUNET_DISK_FileHandle * | 50 | struct GNUNET_DISK_FileHandle * |
51 | get_file_handle (const char *name); | 51 | get_file_handle(const char *name); |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * @brief Close all files that were opened with #get_file_handle | 54 | * @brief Close all files that were opened with #get_file_handle |
@@ -56,44 +56,44 @@ get_file_handle (const char *name); | |||
56 | * @return Success of iterating over files | 56 | * @return Success of iterating over files |
57 | */ | 57 | */ |
58 | int | 58 | int |
59 | close_all_files (); | 59 | close_all_files(); |
60 | 60 | ||
61 | /** | 61 | /** |
62 | * This function is used to facilitate writing important information to disk | 62 | * This function is used to facilitate writing important information to disk |
63 | */ | 63 | */ |
64 | #ifdef TO_FILE | 64 | #ifdef TO_FILE |
65 | #define to_file(file_name, ...) do { \ | 65 | #define to_file(file_name, ...) do { \ |
66 | char tmp_buf[512] = "";\ | 66 | char tmp_buf[512] = ""; \ |
67 | int size;\ | 67 | int size; \ |
68 | if (NULL == file_name) break; \ | 68 | if (NULL == file_name) break; \ |
69 | size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\ | 69 | size = GNUNET_snprintf (tmp_buf, sizeof(tmp_buf), __VA_ARGS__); \ |
70 | if (0 > size)\ | 70 | if (0 > size) \ |
71 | {\ | 71 | { \ |
72 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\ | 72 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, \ |
73 | "Failed to create tmp_buf\n");\ | 73 | "Failed to create tmp_buf\n"); \ |
74 | break;\ | 74 | break; \ |
75 | }\ | 75 | } \ |
76 | (void) strncat(tmp_buf,"\n",512);\ | 76 | (void)strncat(tmp_buf, "\n", 512); \ |
77 | GNUNET_DISK_file_write (get_file_handle (file_name),\ | 77 | GNUNET_DISK_file_write(get_file_handle(file_name), \ |
78 | tmp_buf,\ | 78 | tmp_buf, \ |
79 | strnlen (tmp_buf, 512));\ | 79 | strnlen(tmp_buf, 512)); \ |
80 | } while (0); | 80 | } while (0); |
81 | 81 | ||
82 | 82 | ||
83 | #define to_file_w_len(file_name, len, ...) do {char tmp_buf[len];\ | 83 | #define to_file_w_len(file_name, len, ...) do { char tmp_buf [len]; \ |
84 | int size;\ | 84 | int size; \ |
85 | memset (tmp_buf, 0, len);\ | 85 | memset(tmp_buf, 0, len); \ |
86 | size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\ | 86 | size = GNUNET_snprintf(tmp_buf, sizeof(tmp_buf), __VA_ARGS__); \ |
87 | if (0 > size)\ | 87 | if (0 > size) \ |
88 | {\ | 88 | { \ |
89 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\ | 89 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, \ |
90 | "Failed to create tmp_buf\n");\ | 90 | "Failed to create tmp_buf\n"); \ |
91 | break;\ | 91 | break; \ |
92 | }\ | 92 | } \ |
93 | (void) strncat(tmp_buf,"\n",len);\ | 93 | (void)strncat(tmp_buf, "\n", len); \ |
94 | GNUNET_DISK_file_write (get_file_handle (file_name),\ | 94 | GNUNET_DISK_file_write(get_file_handle(file_name), \ |
95 | tmp_buf,\ | 95 | tmp_buf, \ |
96 | strnlen (tmp_buf, len));\ | 96 | strnlen(tmp_buf, len)); \ |
97 | } while (0); | 97 | } while (0); |
98 | #else /* TO_FILE */ | 98 | #else /* TO_FILE */ |
99 | # define to_file(file_name, ...) | 99 | # define to_file(file_name, ...) |
@@ -101,17 +101,17 @@ close_all_files (); | |||
101 | #endif /* TO_FILE */ | 101 | #endif /* TO_FILE */ |
102 | 102 | ||
103 | char * | 103 | char * |
104 | store_prefix_file_name (const unsigned int index, | 104 | store_prefix_file_name(const unsigned int index, |
105 | const char *prefix); | 105 | const char *prefix); |
106 | 106 | ||
107 | void | 107 | void |
108 | to_file_raw (const char *file_name, const char *buf, size_t size_buf); | 108 | to_file_raw(const char *file_name, const char *buf, size_t size_buf); |
109 | 109 | ||
110 | void | 110 | void |
111 | to_file_raw_unaligned (const char *file_name, | 111 | to_file_raw_unaligned(const char *file_name, |
112 | const char *buf, | 112 | const char *buf, |
113 | size_t size_buf, | 113 | size_t size_buf, |
114 | unsigned bits_needed); | 114 | unsigned bits_needed); |
115 | 115 | ||
116 | 116 | ||
117 | /** | 117 | /** |
@@ -121,7 +121,7 @@ to_file_raw_unaligned (const char *file_name, | |||
121 | * | 121 | * |
122 | * @return Factorial of @a x | 122 | * @return Factorial of @a x |
123 | */ | 123 | */ |
124 | uint32_t fac (uint32_t x); | 124 | uint32_t fac(uint32_t x); |
125 | 125 | ||
126 | 126 | ||
127 | /** | 127 | /** |
@@ -132,7 +132,7 @@ uint32_t fac (uint32_t x); | |||
132 | * | 132 | * |
133 | * @return Binomial coefficient of @a n and @a k | 133 | * @return Binomial coefficient of @a n and @a k |
134 | */ | 134 | */ |
135 | uint32_t binom (uint32_t n, uint32_t k); | 135 | uint32_t binom(uint32_t n, uint32_t k); |
136 | 136 | ||
137 | #endif /* RPS_TEST_UTIL_H */ | 137 | #endif /* RPS_TEST_UTIL_H */ |
138 | /* end of gnunet-service-rps.c */ | 138 | /* end of gnunet-service-rps.c */ |
diff --git a/src/rps/rps.h b/src/rps/rps.h index 5bfef93b0..dee6162be 100644 --- a/src/rps/rps.h +++ b/src/rps/rps.h | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -34,14 +34,13 @@ | |||
34 | GNUNET_NETWORK_STRUCT_BEGIN | 34 | GNUNET_NETWORK_STRUCT_BEGIN |
35 | 35 | ||
36 | /*********************************************************************** | 36 | /*********************************************************************** |
37 | * P2P Messages | 37 | * P2P Messages |
38 | ***********************************************************************/ | 38 | ***********************************************************************/ |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * P2P Message to send PeerIDs to other peer. | 41 | * P2P Message to send PeerIDs to other peer. |
42 | */ | 42 | */ |
43 | struct GNUNET_RPS_P2P_PullReplyMessage | 43 | struct GNUNET_RPS_P2P_PullReplyMessage { |
44 | { | ||
45 | /** | 44 | /** |
46 | * Header including size and type in NBO | 45 | * Header including size and type in NBO |
47 | */ | 46 | */ |
@@ -58,14 +57,13 @@ struct GNUNET_RPS_P2P_PullReplyMessage | |||
58 | 57 | ||
59 | 58 | ||
60 | /*********************************************************************** | 59 | /*********************************************************************** |
61 | * Client-Service Messages | 60 | * Client-Service Messages |
62 | ***********************************************************************/ | 61 | ***********************************************************************/ |
63 | 62 | ||
64 | /** | 63 | /** |
65 | * Message from client to service with seed of peers. | 64 | * Message from client to service with seed of peers. |
66 | */ | 65 | */ |
67 | struct GNUNET_RPS_CS_SeedMessage | 66 | struct GNUNET_RPS_CS_SeedMessage { |
68 | { | ||
69 | /** | 67 | /** |
70 | * Header including size and type in NBO | 68 | * Header including size and type in NBO |
71 | */ | 69 | */ |
@@ -83,8 +81,7 @@ struct GNUNET_RPS_CS_SeedMessage | |||
83 | /** | 81 | /** |
84 | * Message from client to service to turn service malicious. | 82 | * Message from client to service to turn service malicious. |
85 | */ | 83 | */ |
86 | struct GNUNET_RPS_CS_ActMaliciousMessage | 84 | struct GNUNET_RPS_CS_ActMaliciousMessage { |
87 | { | ||
88 | /** | 85 | /** |
89 | * Header including size and type in NBO | 86 | * Header including size and type in NBO |
90 | */ | 87 | */ |
@@ -119,8 +116,7 @@ struct GNUNET_RPS_CS_ActMaliciousMessage | |||
119 | /** | 116 | /** |
120 | * Message from client to service telling it to start a new sub | 117 | * Message from client to service telling it to start a new sub |
121 | */ | 118 | */ |
122 | struct GNUNET_RPS_CS_SubStartMessage | 119 | struct GNUNET_RPS_CS_SubStartMessage { |
123 | { | ||
124 | /** | 120 | /** |
125 | * Header including size and type in NBO | 121 | * Header including size and type in NBO |
126 | */ | 122 | */ |
@@ -146,8 +142,7 @@ struct GNUNET_RPS_CS_SubStartMessage | |||
146 | /** | 142 | /** |
147 | * Message from client to service telling it to stop a new sub | 143 | * Message from client to service telling it to stop a new sub |
148 | */ | 144 | */ |
149 | struct GNUNET_RPS_CS_SubStopMessage | 145 | struct GNUNET_RPS_CS_SubStopMessage { |
150 | { | ||
151 | /** | 146 | /** |
152 | * Header including size and type in NBO | 147 | * Header including size and type in NBO |
153 | */ | 148 | */ |
@@ -166,8 +161,7 @@ struct GNUNET_RPS_CS_SubStopMessage | |||
166 | * Message from client to service indicating that | 161 | * Message from client to service indicating that |
167 | * clients wants to get updates of the view | 162 | * clients wants to get updates of the view |
168 | */ | 163 | */ |
169 | struct GNUNET_RPS_CS_DEBUG_ViewRequest | 164 | struct GNUNET_RPS_CS_DEBUG_ViewRequest { |
170 | { | ||
171 | /** | 165 | /** |
172 | * Header including size and type in NBO | 166 | * Header including size and type in NBO |
173 | */ | 167 | */ |
@@ -183,8 +177,7 @@ struct GNUNET_RPS_CS_DEBUG_ViewRequest | |||
183 | /** | 177 | /** |
184 | * Message from service to client containing current update of view | 178 | * Message from service to client containing current update of view |
185 | */ | 179 | */ |
186 | struct GNUNET_RPS_CS_DEBUG_ViewReply | 180 | struct GNUNET_RPS_CS_DEBUG_ViewReply { |
187 | { | ||
188 | /** | 181 | /** |
189 | * Header including size and type in NBO | 182 | * Header including size and type in NBO |
190 | */ | 183 | */ |
@@ -200,14 +193,13 @@ struct GNUNET_RPS_CS_DEBUG_ViewReply | |||
200 | */ | 193 | */ |
201 | uint64_t num_peers GNUNET_PACKED; | 194 | uint64_t num_peers GNUNET_PACKED; |
202 | }; | 195 | }; |
203 | /* Followed by num_peers * GNUNET_PeerIdentity */ | 196 | /* Followed by num_peers * GNUNET_PeerIdentity */ |
204 | 197 | ||
205 | /** | 198 | /** |
206 | * Message from client to service indicating that | 199 | * Message from client to service indicating that |
207 | * clients wants to get stream of biased peers | 200 | * clients wants to get stream of biased peers |
208 | */ | 201 | */ |
209 | struct GNUNET_RPS_CS_DEBUG_StreamRequest | 202 | struct GNUNET_RPS_CS_DEBUG_StreamRequest { |
210 | { | ||
211 | /** | 203 | /** |
212 | * Header including size and type in NBO | 204 | * Header including size and type in NBO |
213 | */ | 205 | */ |
@@ -217,8 +209,7 @@ struct GNUNET_RPS_CS_DEBUG_StreamRequest | |||
217 | /** | 209 | /** |
218 | * Message from service to client containing peer from biased stream | 210 | * Message from service to client containing peer from biased stream |
219 | */ | 211 | */ |
220 | struct GNUNET_RPS_CS_DEBUG_StreamReply | 212 | struct GNUNET_RPS_CS_DEBUG_StreamReply { |
221 | { | ||
222 | /** | 213 | /** |
223 | * Header including size and type in NBO | 214 | * Header including size and type in NBO |
224 | */ | 215 | */ |
@@ -237,14 +228,13 @@ struct GNUNET_RPS_CS_DEBUG_StreamReply | |||
237 | GNUNET_NETWORK_STRUCT_END | 228 | GNUNET_NETWORK_STRUCT_END |
238 | 229 | ||
239 | /*********************************************************************** | 230 | /*********************************************************************** |
240 | * Defines from old gnunet-service-rps_peers.h | 231 | * Defines from old gnunet-service-rps_peers.h |
241 | ***********************************************************************/ | 232 | ***********************************************************************/ |
242 | 233 | ||
243 | /** | 234 | /** |
244 | * Different flags indicating the status of another peer. | 235 | * Different flags indicating the status of another peer. |
245 | */ | 236 | */ |
246 | enum Peers_PeerFlags | 237 | enum Peers_PeerFlags { |
247 | { | ||
248 | /** | 238 | /** |
249 | * If we are waiting for a reply from that peer (sent a pull request). | 239 | * If we are waiting for a reply from that peer (sent a pull request). |
250 | */ | 240 | */ |
@@ -273,8 +263,7 @@ enum Peers_PeerFlags | |||
273 | * This is needed in order to know what to do with a channel when it's | 263 | * This is needed in order to know what to do with a channel when it's |
274 | * destroyed. | 264 | * destroyed. |
275 | */ | 265 | */ |
276 | enum Peers_ChannelFlags | 266 | enum Peers_ChannelFlags { |
277 | { | ||
278 | /** | 267 | /** |
279 | * We destroyed the channel because the other peer established a second one. | 268 | * We destroyed the channel because the other peer established a second one. |
280 | */ | 269 | */ |
@@ -296,8 +285,7 @@ enum Peers_ChannelFlags | |||
296 | /** | 285 | /** |
297 | * @brief The role of a channel. Sending or receiving. | 286 | * @brief The role of a channel. Sending or receiving. |
298 | */ | 287 | */ |
299 | enum Peers_ChannelRole | 288 | enum Peers_ChannelRole { |
300 | { | ||
301 | /** | 289 | /** |
302 | * Channel is used for sending | 290 | * Channel is used for sending |
303 | */ | 291 | */ |
diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c index 9e405fdef..2b54297c3 100644 --- a/src/rps/rps_api.c +++ b/src/rps/rps_api.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file rps/rps_api.c | 22 | * @file rps/rps_api.c |
@@ -33,13 +33,12 @@ | |||
33 | 33 | ||
34 | #include <inttypes.h> | 34 | #include <inttypes.h> |
35 | 35 | ||
36 | #define LOG(kind,...) GNUNET_log_from (kind, "rps-api",__VA_ARGS__) | 36 | #define LOG(kind, ...) GNUNET_log_from(kind, "rps-api", __VA_ARGS__) |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * Handle for a request to get peers from biased stream of ids | 39 | * Handle for a request to get peers from biased stream of ids |
40 | */ | 40 | */ |
41 | struct GNUNET_RPS_StreamRequestHandle | 41 | struct GNUNET_RPS_StreamRequestHandle { |
42 | { | ||
43 | /** | 42 | /** |
44 | * The client issuing the request. | 43 | * The client issuing the request. |
45 | */ | 44 | */ |
@@ -75,8 +74,7 @@ struct GNUNET_RPS_StreamRequestHandle | |||
75 | /** | 74 | /** |
76 | * Handler to handle requests from a client. | 75 | * Handler to handle requests from a client. |
77 | */ | 76 | */ |
78 | struct GNUNET_RPS_Handle | 77 | struct GNUNET_RPS_Handle { |
79 | { | ||
80 | /** | 78 | /** |
81 | * The handle to the client configuration. | 79 | * The handle to the client configuration. |
82 | */ | 80 | */ |
@@ -156,8 +154,7 @@ struct GNUNET_RPS_Handle | |||
156 | /** | 154 | /** |
157 | * Handler for a single request from a client. | 155 | * Handler for a single request from a client. |
158 | */ | 156 | */ |
159 | struct GNUNET_RPS_Request_Handle | 157 | struct GNUNET_RPS_Request_Handle { |
160 | { | ||
161 | /** | 158 | /** |
162 | * The client issuing the request. | 159 | * The client issuing the request. |
163 | */ | 160 | */ |
@@ -209,8 +206,7 @@ struct GNUNET_RPS_Request_Handle | |||
209 | /** | 206 | /** |
210 | * Handler for a single request from a client. | 207 | * Handler for a single request from a client. |
211 | */ | 208 | */ |
212 | struct GNUNET_RPS_Request_Handle_Single_Info | 209 | struct GNUNET_RPS_Request_Handle_Single_Info { |
213 | { | ||
214 | /** | 210 | /** |
215 | * The client issuing the request. | 211 | * The client issuing the request. |
216 | */ | 212 | */ |
@@ -258,8 +254,7 @@ struct GNUNET_RPS_Request_Handle_Single_Info | |||
258 | * Struct used to pack the callback, its closure (provided by the caller) | 254 | * Struct used to pack the callback, its closure (provided by the caller) |
259 | * and the connection handler to the service to pass it to a callback function. | 255 | * and the connection handler to the service to pass it to a callback function. |
260 | */ | 256 | */ |
261 | struct cb_cls_pack | 257 | struct cb_cls_pack { |
262 | { | ||
263 | /** | 258 | /** |
264 | * Callback provided by the client | 259 | * Callback provided by the client |
265 | */ | 260 | */ |
@@ -273,7 +268,7 @@ struct cb_cls_pack | |||
273 | /** | 268 | /** |
274 | * Handle to the service connection | 269 | * Handle to the service connection |
275 | */ | 270 | */ |
276 | struct GNUNET_CLIENT_Connection *service_conn; | 271 | struct GNUNET_CLIENT_Connection *service_conn; |
277 | }; | 272 | }; |
278 | 273 | ||
279 | 274 | ||
@@ -301,19 +296,19 @@ static uint64_t srh_callback_num_peers; | |||
301 | * @return The handle to the stream request | 296 | * @return The handle to the stream request |
302 | */ | 297 | */ |
303 | static struct GNUNET_RPS_StreamRequestHandle * | 298 | static struct GNUNET_RPS_StreamRequestHandle * |
304 | new_stream_request (struct GNUNET_RPS_Handle *rps_handle, | 299 | new_stream_request(struct GNUNET_RPS_Handle *rps_handle, |
305 | GNUNET_RPS_NotifyReadyCB ready_cb, | 300 | GNUNET_RPS_NotifyReadyCB ready_cb, |
306 | void *cls) | 301 | void *cls) |
307 | { | 302 | { |
308 | struct GNUNET_RPS_StreamRequestHandle *srh; | 303 | struct GNUNET_RPS_StreamRequestHandle *srh; |
309 | 304 | ||
310 | srh = GNUNET_new (struct GNUNET_RPS_StreamRequestHandle); | 305 | srh = GNUNET_new(struct GNUNET_RPS_StreamRequestHandle); |
311 | srh->rps_handle = rps_handle; | 306 | srh->rps_handle = rps_handle; |
312 | srh->ready_cb = ready_cb; | 307 | srh->ready_cb = ready_cb; |
313 | srh->ready_cb_cls = cls; | 308 | srh->ready_cb_cls = cls; |
314 | GNUNET_CONTAINER_DLL_insert (rps_handle->stream_requests_head, | 309 | GNUNET_CONTAINER_DLL_insert(rps_handle->stream_requests_head, |
315 | rps_handle->stream_requests_tail, | 310 | rps_handle->stream_requests_tail, |
316 | srh); | 311 | srh); |
317 | 312 | ||
318 | return srh; | 313 | return srh; |
319 | } | 314 | } |
@@ -325,20 +320,20 @@ new_stream_request (struct GNUNET_RPS_Handle *rps_handle, | |||
325 | * @param srh The request to be removed | 320 | * @param srh The request to be removed |
326 | */ | 321 | */ |
327 | static void | 322 | static void |
328 | remove_stream_request (struct GNUNET_RPS_StreamRequestHandle *srh) | 323 | remove_stream_request(struct GNUNET_RPS_StreamRequestHandle *srh) |
329 | { | 324 | { |
330 | struct GNUNET_RPS_Handle *rps_handle = srh->rps_handle; | 325 | struct GNUNET_RPS_Handle *rps_handle = srh->rps_handle; |
331 | 326 | ||
332 | GNUNET_assert (NULL != srh); | 327 | GNUNET_assert(NULL != srh); |
333 | if (NULL != srh->callback_task) | 328 | if (NULL != srh->callback_task) |
334 | { | 329 | { |
335 | GNUNET_SCHEDULER_cancel (srh->callback_task); | 330 | GNUNET_SCHEDULER_cancel(srh->callback_task); |
336 | srh->callback_task = NULL; | 331 | srh->callback_task = NULL; |
337 | } | 332 | } |
338 | GNUNET_CONTAINER_DLL_remove (rps_handle->stream_requests_head, | 333 | GNUNET_CONTAINER_DLL_remove(rps_handle->stream_requests_head, |
339 | rps_handle->stream_requests_tail, | 334 | rps_handle->stream_requests_tail, |
340 | srh); | 335 | srh); |
341 | GNUNET_free (srh); | 336 | GNUNET_free(srh); |
342 | } | 337 | } |
343 | 338 | ||
344 | 339 | ||
@@ -352,17 +347,17 @@ remove_stream_request (struct GNUNET_RPS_StreamRequestHandle *srh) | |||
352 | * @param cls The #GNUNET_RPS_Request_Handle | 347 | * @param cls The #GNUNET_RPS_Request_Handle |
353 | */ | 348 | */ |
354 | static void | 349 | static void |
355 | peers_ready_cb (const struct GNUNET_PeerIdentity *peers, | 350 | peers_ready_cb(const struct GNUNET_PeerIdentity *peers, |
356 | uint32_t num_peers, | 351 | uint32_t num_peers, |
357 | void *cls) | 352 | void *cls) |
358 | { | 353 | { |
359 | struct GNUNET_RPS_Request_Handle *rh = cls; | 354 | struct GNUNET_RPS_Request_Handle *rh = cls; |
360 | 355 | ||
361 | rh->sampler_rh = NULL; | 356 | rh->sampler_rh = NULL; |
362 | rh->ready_cb (rh->ready_cb_cls, | 357 | rh->ready_cb(rh->ready_cb_cls, |
363 | num_peers, | 358 | num_peers, |
364 | peers); | 359 | peers); |
365 | GNUNET_RPS_request_cancel (rh); | 360 | GNUNET_RPS_request_cancel(rh); |
366 | } | 361 | } |
367 | 362 | ||
368 | 363 | ||
@@ -378,19 +373,19 @@ peers_ready_cb (const struct GNUNET_PeerIdentity *peers, | |||
378 | * @param num_observed Number of observed IDs | 373 | * @param num_observed Number of observed IDs |
379 | */ | 374 | */ |
380 | static void | 375 | static void |
381 | peer_info_ready_cb (const struct GNUNET_PeerIdentity *peers, | 376 | peer_info_ready_cb(const struct GNUNET_PeerIdentity *peers, |
382 | void *cls, | 377 | void *cls, |
383 | double probability, | 378 | double probability, |
384 | uint32_t num_observed) | 379 | uint32_t num_observed) |
385 | { | 380 | { |
386 | struct GNUNET_RPS_Request_Handle_Single_Info *rh = cls; | 381 | struct GNUNET_RPS_Request_Handle_Single_Info *rh = cls; |
387 | 382 | ||
388 | rh->sampler_rh = NULL; | 383 | rh->sampler_rh = NULL; |
389 | rh->ready_cb (rh->ready_cb_cls, | 384 | rh->ready_cb(rh->ready_cb_cls, |
390 | peers, | 385 | peers, |
391 | probability, | 386 | probability, |
392 | num_observed); | 387 | num_observed); |
393 | GNUNET_RPS_request_single_info_cancel (rh); | 388 | GNUNET_RPS_request_single_info_cancel(rh); |
394 | } | 389 | } |
395 | 390 | ||
396 | 391 | ||
@@ -403,19 +398,19 @@ peer_info_ready_cb (const struct GNUNET_PeerIdentity *peers, | |||
403 | * @param peers The array of @a num_peers that have been returned | 398 | * @param peers The array of @a num_peers that have been returned |
404 | */ | 399 | */ |
405 | static void | 400 | static void |
406 | collect_peers_cb (void *cls, | 401 | collect_peers_cb(void *cls, |
407 | uint64_t num_peers, | 402 | uint64_t num_peers, |
408 | const struct GNUNET_PeerIdentity *peers) | 403 | const struct GNUNET_PeerIdentity *peers) |
409 | { | 404 | { |
410 | struct GNUNET_RPS_Request_Handle *rh = cls; | 405 | struct GNUNET_RPS_Request_Handle *rh = cls; |
411 | 406 | ||
412 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 407 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
413 | "Service sent %" PRIu64 " peers from stream\n", | 408 | "Service sent %" PRIu64 " peers from stream\n", |
414 | num_peers); | 409 | num_peers); |
415 | for (uint64_t i = 0; i < num_peers; i++) | 410 | for (uint64_t i = 0; i < num_peers; i++) |
416 | { | 411 | { |
417 | RPS_sampler_update (rh->sampler, &peers[i]); | 412 | RPS_sampler_update(rh->sampler, &peers[i]); |
418 | } | 413 | } |
419 | } | 414 | } |
420 | 415 | ||
421 | 416 | ||
@@ -430,19 +425,19 @@ collect_peers_cb (void *cls, | |||
430 | * @param peers The array of @a num_peers that have been returned | 425 | * @param peers The array of @a num_peers that have been returned |
431 | */ | 426 | */ |
432 | static void | 427 | static void |
433 | collect_peers_info_cb (void *cls, | 428 | collect_peers_info_cb(void *cls, |
434 | uint64_t num_peers, | 429 | uint64_t num_peers, |
435 | const struct GNUNET_PeerIdentity *peers) | 430 | const struct GNUNET_PeerIdentity *peers) |
436 | { | 431 | { |
437 | struct GNUNET_RPS_Request_Handle_Single_Info *rhs = cls; | 432 | struct GNUNET_RPS_Request_Handle_Single_Info *rhs = cls; |
438 | 433 | ||
439 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 434 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
440 | "Service sent %" PRIu64 " peers from stream\n", | 435 | "Service sent %" PRIu64 " peers from stream\n", |
441 | num_peers); | 436 | num_peers); |
442 | for (uint64_t i = 0; i < num_peers; i++) | 437 | for (uint64_t i = 0; i < num_peers; i++) |
443 | { | 438 | { |
444 | RPS_sampler_update (rhs->sampler, &peers[i]); | 439 | RPS_sampler_update(rhs->sampler, &peers[i]); |
445 | } | 440 | } |
446 | } | 441 | } |
447 | 442 | ||
448 | 443 | ||
@@ -458,37 +453,37 @@ collect_peers_info_cb (void *cls, | |||
458 | * @param ready_cb the callback called when the peers are available | 453 | * @param ready_cb the callback called when the peers are available |
459 | */ | 454 | */ |
460 | void | 455 | void |
461 | GNUNET_RPS_view_request (struct GNUNET_RPS_Handle *rps_handle, | 456 | GNUNET_RPS_view_request(struct GNUNET_RPS_Handle *rps_handle, |
462 | uint32_t num_updates, | 457 | uint32_t num_updates, |
463 | GNUNET_RPS_NotifyReadyCB view_update_cb, | 458 | GNUNET_RPS_NotifyReadyCB view_update_cb, |
464 | void *cls) | 459 | void *cls) |
465 | { | 460 | { |
466 | struct GNUNET_MQ_Envelope *ev; | 461 | struct GNUNET_MQ_Envelope *ev; |
467 | struct GNUNET_RPS_CS_DEBUG_ViewRequest *msg; | 462 | struct GNUNET_RPS_CS_DEBUG_ViewRequest *msg; |
468 | 463 | ||
469 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 464 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
470 | "Client requests %" PRIu32 " view updates\n", | 465 | "Client requests %" PRIu32 " view updates\n", |
471 | num_updates); | 466 | num_updates); |
472 | rps_handle->view_update_cb = view_update_cb; | 467 | rps_handle->view_update_cb = view_update_cb; |
473 | rps_handle->view_update_cls = cls; | 468 | rps_handle->view_update_cls = cls; |
474 | 469 | ||
475 | ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST); | 470 | ev = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST); |
476 | msg->num_updates = htonl (num_updates); | 471 | msg->num_updates = htonl(num_updates); |
477 | GNUNET_MQ_send (rps_handle->mq, ev); | 472 | GNUNET_MQ_send(rps_handle->mq, ev); |
478 | } | 473 | } |
479 | 474 | ||
480 | 475 | ||
481 | void | 476 | void |
482 | GNUNET_RPS_view_request_cancel (struct GNUNET_RPS_Handle *rps_handle) | 477 | GNUNET_RPS_view_request_cancel(struct GNUNET_RPS_Handle *rps_handle) |
483 | { | 478 | { |
484 | struct GNUNET_MQ_Envelope *ev; | 479 | struct GNUNET_MQ_Envelope *ev; |
485 | 480 | ||
486 | GNUNET_assert (NULL != rps_handle->view_update_cb); | 481 | GNUNET_assert(NULL != rps_handle->view_update_cb); |
487 | 482 | ||
488 | rps_handle->view_update_cb = NULL; | 483 | rps_handle->view_update_cb = NULL; |
489 | 484 | ||
490 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL); | 485 | ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL); |
491 | GNUNET_MQ_send (rps_handle->mq, ev); | 486 | GNUNET_MQ_send(rps_handle->mq, ev); |
492 | } | 487 | } |
493 | 488 | ||
494 | 489 | ||
@@ -500,21 +495,21 @@ GNUNET_RPS_view_request_cancel (struct GNUNET_RPS_Handle *rps_handle) | |||
500 | * @param ready_cb the callback called when the peers are available | 495 | * @param ready_cb the callback called when the peers are available |
501 | */ | 496 | */ |
502 | struct GNUNET_RPS_StreamRequestHandle * | 497 | struct GNUNET_RPS_StreamRequestHandle * |
503 | GNUNET_RPS_stream_request (struct GNUNET_RPS_Handle *rps_handle, | 498 | GNUNET_RPS_stream_request(struct GNUNET_RPS_Handle *rps_handle, |
504 | GNUNET_RPS_NotifyReadyCB stream_input_cb, | 499 | GNUNET_RPS_NotifyReadyCB stream_input_cb, |
505 | void *cls) | 500 | void *cls) |
506 | { | 501 | { |
507 | struct GNUNET_RPS_StreamRequestHandle *srh; | 502 | struct GNUNET_RPS_StreamRequestHandle *srh; |
508 | struct GNUNET_MQ_Envelope *ev; | 503 | struct GNUNET_MQ_Envelope *ev; |
509 | struct GNUNET_RPS_CS_DEBUG_StreamRequest *msg; | 504 | struct GNUNET_RPS_CS_DEBUG_StreamRequest *msg; |
510 | 505 | ||
511 | srh = new_stream_request (rps_handle, | 506 | srh = new_stream_request(rps_handle, |
512 | stream_input_cb, | 507 | stream_input_cb, |
513 | cls); | 508 | cls); |
514 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Client requests biased stream updates\n"); | 509 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Client requests biased stream updates\n"); |
515 | 510 | ||
516 | ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST); | 511 | ev = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST); |
517 | GNUNET_MQ_send (rps_handle->mq, ev); | 512 | GNUNET_MQ_send(rps_handle->mq, ev); |
518 | return srh; | 513 | return srh; |
519 | } | 514 | } |
520 | 515 | ||
@@ -528,20 +523,21 @@ GNUNET_RPS_stream_request (struct GNUNET_RPS_Handle *rps_handle, | |||
528 | * @return #GNUNET_OK if @a msg is well-formed | 523 | * @return #GNUNET_OK if @a msg is well-formed |
529 | */ | 524 | */ |
530 | static int | 525 | static int |
531 | check_view_update (void *cls, | 526 | check_view_update(void *cls, |
532 | const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg) | 527 | const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg) |
533 | { | 528 | { |
534 | uint16_t msize = ntohs (msg->header.size); | 529 | uint16_t msize = ntohs(msg->header.size); |
535 | uint32_t num_peers = ntohl (msg->num_peers); | 530 | uint32_t num_peers = ntohl(msg->num_peers); |
536 | (void) cls; | 531 | |
537 | 532 | (void)cls; | |
538 | msize -= sizeof (struct GNUNET_RPS_CS_DEBUG_ViewReply); | 533 | |
539 | if ( (msize / sizeof (struct GNUNET_PeerIdentity) != num_peers) || | 534 | msize -= sizeof(struct GNUNET_RPS_CS_DEBUG_ViewReply); |
540 | (msize % sizeof (struct GNUNET_PeerIdentity) != 0) ) | 535 | if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) || |
541 | { | 536 | (msize % sizeof(struct GNUNET_PeerIdentity) != 0)) |
542 | GNUNET_break (0); | 537 | { |
543 | return GNUNET_SYSERR; | 538 | GNUNET_break(0); |
544 | } | 539 | return GNUNET_SYSERR; |
540 | } | ||
545 | return GNUNET_OK; | 541 | return GNUNET_OK; |
546 | } | 542 | } |
547 | 543 | ||
@@ -554,21 +550,21 @@ check_view_update (void *cls, | |||
554 | * @param msg the message | 550 | * @param msg the message |
555 | */ | 551 | */ |
556 | static void | 552 | static void |
557 | handle_view_update (void *cls, | 553 | handle_view_update(void *cls, |
558 | const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg) | 554 | const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg) |
559 | { | 555 | { |
560 | struct GNUNET_RPS_Handle *h = cls; | 556 | struct GNUNET_RPS_Handle *h = cls; |
561 | struct GNUNET_PeerIdentity *peers; | 557 | struct GNUNET_PeerIdentity *peers; |
562 | 558 | ||
563 | /* Give the peers back */ | 559 | /* Give the peers back */ |
564 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 560 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
565 | "New view of %" PRIu32 " peers:\n", | 561 | "New view of %" PRIu32 " peers:\n", |
566 | ntohl (msg->num_peers)); | 562 | ntohl(msg->num_peers)); |
567 | 563 | ||
568 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; | 564 | peers = (struct GNUNET_PeerIdentity *)&msg[1]; |
569 | GNUNET_assert (NULL != h); | 565 | GNUNET_assert(NULL != h); |
570 | GNUNET_assert (NULL != h->view_update_cb); | 566 | GNUNET_assert(NULL != h->view_update_cb); |
571 | h->view_update_cb (h->view_update_cls, ntohl (msg->num_peers), peers); | 567 | h->view_update_cb(h->view_update_cls, ntohl(msg->num_peers), peers); |
572 | } | 568 | } |
573 | 569 | ||
574 | 570 | ||
@@ -579,12 +575,12 @@ handle_view_update (void *cls, | |||
579 | * @param rps_handle The handle representing the service to the client | 575 | * @param rps_handle The handle representing the service to the client |
580 | */ | 576 | */ |
581 | static void | 577 | static void |
582 | cancel_stream (struct GNUNET_RPS_Handle *rps_handle) | 578 | cancel_stream(struct GNUNET_RPS_Handle *rps_handle) |
583 | { | 579 | { |
584 | struct GNUNET_MQ_Envelope *ev; | 580 | struct GNUNET_MQ_Envelope *ev; |
585 | 581 | ||
586 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_CANCEL); | 582 | ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_CANCEL); |
587 | GNUNET_MQ_send (rps_handle->mq, ev); | 583 | GNUNET_MQ_send(rps_handle->mq, ev); |
588 | } | 584 | } |
589 | 585 | ||
590 | 586 | ||
@@ -594,14 +590,14 @@ cancel_stream (struct GNUNET_RPS_Handle *rps_handle) | |||
594 | * @param srh The request handle to cancel | 590 | * @param srh The request handle to cancel |
595 | */ | 591 | */ |
596 | void | 592 | void |
597 | GNUNET_RPS_stream_cancel (struct GNUNET_RPS_StreamRequestHandle *srh) | 593 | GNUNET_RPS_stream_cancel(struct GNUNET_RPS_StreamRequestHandle *srh) |
598 | { | 594 | { |
599 | struct GNUNET_RPS_Handle *rps_handle; | 595 | struct GNUNET_RPS_Handle *rps_handle; |
600 | 596 | ||
601 | rps_handle = srh->rps_handle; | 597 | rps_handle = srh->rps_handle; |
602 | remove_stream_request (srh); | 598 | remove_stream_request(srh); |
603 | if (NULL == rps_handle->stream_requests_head) | 599 | if (NULL == rps_handle->stream_requests_head) |
604 | cancel_stream (rps_handle); | 600 | cancel_stream(rps_handle); |
605 | } | 601 | } |
606 | 602 | ||
607 | 603 | ||
@@ -616,20 +612,21 @@ GNUNET_RPS_stream_cancel (struct GNUNET_RPS_StreamRequestHandle *srh) | |||
616 | * @param msg the message | 612 | * @param msg the message |
617 | */ | 613 | */ |
618 | static int | 614 | static int |
619 | check_stream_input (void *cls, | 615 | check_stream_input(void *cls, |
620 | const struct GNUNET_RPS_CS_DEBUG_StreamReply *msg) | 616 | const struct GNUNET_RPS_CS_DEBUG_StreamReply *msg) |
621 | { | 617 | { |
622 | uint16_t msize = ntohs (msg->header.size); | 618 | uint16_t msize = ntohs(msg->header.size); |
623 | uint32_t num_peers = ntohl (msg->num_peers); | 619 | uint32_t num_peers = ntohl(msg->num_peers); |
624 | (void) cls; | 620 | |
625 | 621 | (void)cls; | |
626 | msize -= sizeof (struct GNUNET_RPS_CS_DEBUG_StreamReply); | 622 | |
627 | if ( (msize / sizeof (struct GNUNET_PeerIdentity) != num_peers) || | 623 | msize -= sizeof(struct GNUNET_RPS_CS_DEBUG_StreamReply); |
628 | (msize % sizeof (struct GNUNET_PeerIdentity) != 0) ) | 624 | if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) || |
629 | { | 625 | (msize % sizeof(struct GNUNET_PeerIdentity) != 0)) |
630 | GNUNET_break (0); | 626 | { |
631 | return GNUNET_SYSERR; | 627 | GNUNET_break(0); |
632 | } | 628 | return GNUNET_SYSERR; |
629 | } | ||
633 | return GNUNET_OK; | 630 | return GNUNET_OK; |
634 | } | 631 | } |
635 | 632 | ||
@@ -640,14 +637,14 @@ check_stream_input (void *cls, | |||
640 | * @param cls Stream request handle | 637 | * @param cls Stream request handle |
641 | */ | 638 | */ |
642 | static void | 639 | static void |
643 | srh_callback_scheduled (void *cls) | 640 | srh_callback_scheduled(void *cls) |
644 | { | 641 | { |
645 | struct GNUNET_RPS_StreamRequestHandle *srh = cls; | 642 | struct GNUNET_RPS_StreamRequestHandle *srh = cls; |
646 | 643 | ||
647 | srh->callback_task = NULL; | 644 | srh->callback_task = NULL; |
648 | srh->ready_cb (srh->ready_cb_cls, | 645 | srh->ready_cb(srh->ready_cb_cls, |
649 | srh_callback_num_peers, | 646 | srh_callback_num_peers, |
650 | srh_callback_peers); | 647 | srh_callback_peers); |
651 | } | 648 | } |
652 | 649 | ||
653 | 650 | ||
@@ -660,8 +657,8 @@ srh_callback_scheduled (void *cls) | |||
660 | * @param msg the message | 657 | * @param msg the message |
661 | */ | 658 | */ |
662 | static void | 659 | static void |
663 | handle_stream_input (void *cls, | 660 | handle_stream_input(void *cls, |
664 | const struct GNUNET_RPS_CS_DEBUG_StreamReply *msg) | 661 | const struct GNUNET_RPS_CS_DEBUG_StreamReply *msg) |
665 | { | 662 | { |
666 | struct GNUNET_RPS_Handle *h = cls; | 663 | struct GNUNET_RPS_Handle *h = cls; |
667 | //const struct GNUNET_PeerIdentity *peers; | 664 | //const struct GNUNET_PeerIdentity *peers; |
@@ -670,35 +667,35 @@ handle_stream_input (void *cls, | |||
670 | struct GNUNET_RPS_StreamRequestHandle *srh_next; | 667 | struct GNUNET_RPS_StreamRequestHandle *srh_next; |
671 | 668 | ||
672 | //peers = (struct GNUNET_PeerIdentity *) &msg[1]; | 669 | //peers = (struct GNUNET_PeerIdentity *) &msg[1]; |
673 | num_peers = ntohl (msg->num_peers); | 670 | num_peers = ntohl(msg->num_peers); |
674 | srh_callback_num_peers = num_peers; | 671 | srh_callback_num_peers = num_peers; |
675 | GNUNET_free_non_null (srh_callback_peers); | 672 | GNUNET_free_non_null(srh_callback_peers); |
676 | srh_callback_peers = GNUNET_new_array (num_peers, | 673 | srh_callback_peers = GNUNET_new_array(num_peers, |
677 | struct GNUNET_PeerIdentity); | 674 | struct GNUNET_PeerIdentity); |
678 | GNUNET_memcpy (srh_callback_peers, | 675 | GNUNET_memcpy(srh_callback_peers, |
679 | &msg[1], | 676 | &msg[1], |
680 | num_peers * sizeof (struct GNUNET_PeerIdentity)); | 677 | num_peers * sizeof(struct GNUNET_PeerIdentity)); |
681 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 678 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
682 | "Received %" PRIu64 " peer(s) from stream input.\n", | 679 | "Received %" PRIu64 " peer(s) from stream input.\n", |
683 | num_peers); | 680 | num_peers); |
684 | for (srh_iter = h->stream_requests_head; | 681 | for (srh_iter = h->stream_requests_head; |
685 | NULL != srh_iter; | 682 | NULL != srh_iter; |
686 | srh_iter = srh_next) | 683 | srh_iter = srh_next) |
687 | { | 684 | { |
688 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Calling srh \n"); | 685 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Calling srh \n"); |
689 | /* Store next pointer - srh might be removed/freed in callback */ | 686 | /* Store next pointer - srh might be removed/freed in callback */ |
690 | srh_next = srh_iter->next; | 687 | srh_next = srh_iter->next; |
691 | if (NULL != srh_iter->callback_task) | 688 | if (NULL != srh_iter->callback_task) |
692 | GNUNET_SCHEDULER_cancel (srh_iter->callback_task); | 689 | GNUNET_SCHEDULER_cancel(srh_iter->callback_task); |
693 | srh_iter->callback_task = | 690 | srh_iter->callback_task = |
694 | GNUNET_SCHEDULER_add_now (&srh_callback_scheduled, | 691 | GNUNET_SCHEDULER_add_now(&srh_callback_scheduled, |
695 | srh_iter); | 692 | srh_iter); |
696 | } | 693 | } |
697 | 694 | ||
698 | if (NULL == h->stream_requests_head) | 695 | if (NULL == h->stream_requests_head) |
699 | { | 696 | { |
700 | cancel_stream (h); | 697 | cancel_stream(h); |
701 | } | 698 | } |
702 | } | 699 | } |
703 | 700 | ||
704 | 701 | ||
@@ -706,7 +703,7 @@ handle_stream_input (void *cls, | |||
706 | * Reconnect to the service | 703 | * Reconnect to the service |
707 | */ | 704 | */ |
708 | static void | 705 | static void |
709 | reconnect (struct GNUNET_RPS_Handle *h); | 706 | reconnect(struct GNUNET_RPS_Handle *h); |
710 | 707 | ||
711 | 708 | ||
712 | /** | 709 | /** |
@@ -719,18 +716,19 @@ reconnect (struct GNUNET_RPS_Handle *h); | |||
719 | * @param error error code without specyfied meaning | 716 | * @param error error code without specyfied meaning |
720 | */ | 717 | */ |
721 | static void | 718 | static void |
722 | mq_error_handler (void *cls, | 719 | mq_error_handler(void *cls, |
723 | enum GNUNET_MQ_Error error) | 720 | enum GNUNET_MQ_Error error) |
724 | { | 721 | { |
725 | struct GNUNET_RPS_Handle *h = cls; | 722 | struct GNUNET_RPS_Handle *h = cls; |
723 | |||
726 | //TODO LOG | 724 | //TODO LOG |
727 | LOG (GNUNET_ERROR_TYPE_WARNING, "Problem with message queue. error: %i\n\ | 725 | LOG(GNUNET_ERROR_TYPE_WARNING, "Problem with message queue. error: %i\n\ |
728 | 1: READ,\n\ | 726 | 1: READ,\n\ |
729 | 2: WRITE,\n\ | 727 | 2: WRITE,\n\ |
730 | 4: TIMEOUT\n", | 728 | 4: TIMEOUT\n", |
731 | // TODO: write GNUNET_MQ_strerror (error) | 729 | // TODO: write GNUNET_MQ_strerror (error) |
732 | error); | 730 | error); |
733 | reconnect (h); | 731 | reconnect(h); |
734 | /* Resend all pending request as the service destroyed its knowledge | 732 | /* Resend all pending request as the service destroyed its knowledge |
735 | * about them */ | 733 | * about them */ |
736 | } | 734 | } |
@@ -744,16 +742,16 @@ mq_error_handler (void *cls, | |||
744 | * @param hash[out] Pointer to the location in which the hash will be stored. | 742 | * @param hash[out] Pointer to the location in which the hash will be stored. |
745 | */ | 743 | */ |
746 | static void | 744 | static void |
747 | hash_from_share_val (const char *share_val, | 745 | hash_from_share_val(const char *share_val, |
748 | struct GNUNET_HashCode *hash) | 746 | struct GNUNET_HashCode *hash) |
749 | { | 747 | { |
750 | GNUNET_CRYPTO_kdf (hash, | 748 | GNUNET_CRYPTO_kdf(hash, |
751 | sizeof (struct GNUNET_HashCode), | 749 | sizeof(struct GNUNET_HashCode), |
752 | "rps", | 750 | "rps", |
753 | strlen ("rps"), | 751 | strlen("rps"), |
754 | share_val, | 752 | share_val, |
755 | strlen (share_val), | 753 | strlen(share_val), |
756 | NULL, 0); | 754 | NULL, 0); |
757 | } | 755 | } |
758 | 756 | ||
759 | 757 | ||
@@ -769,29 +767,30 @@ hash_from_share_val (const char *share_val, | |||
769 | * @param std_dev the standard distribution | 767 | * @param std_dev the standard distribution |
770 | */ | 768 | */ |
771 | static void | 769 | static void |
772 | nse_cb (void *cls, | 770 | nse_cb(void *cls, |
773 | struct GNUNET_TIME_Absolute timestamp, | 771 | struct GNUNET_TIME_Absolute timestamp, |
774 | double logestimate, | 772 | double logestimate, |
775 | double std_dev) | 773 | double std_dev) |
776 | { | 774 | { |
777 | struct GNUNET_RPS_Handle *h = cls; | 775 | struct GNUNET_RPS_Handle *h = cls; |
778 | (void) timestamp; | 776 | |
779 | (void) std_dev; | 777 | (void)timestamp; |
778 | (void)std_dev; | ||
780 | 779 | ||
781 | for (struct GNUNET_RPS_Request_Handle *rh_iter = h->rh_head; | 780 | for (struct GNUNET_RPS_Request_Handle *rh_iter = h->rh_head; |
782 | NULL != rh_iter && NULL != rh_iter->next; | 781 | NULL != rh_iter && NULL != rh_iter->next; |
783 | rh_iter = rh_iter->next) | 782 | rh_iter = rh_iter->next) |
784 | { | 783 | { |
785 | RPS_sampler_update_with_nw_size (rh_iter->sampler, | 784 | RPS_sampler_update_with_nw_size(rh_iter->sampler, |
786 | GNUNET_NSE_log_estimate_to_n (logestimate)); | 785 | GNUNET_NSE_log_estimate_to_n(logestimate)); |
787 | } | 786 | } |
788 | for (struct GNUNET_RPS_Request_Handle_Single_Info *rhs_iter = h->rhs_head; | 787 | for (struct GNUNET_RPS_Request_Handle_Single_Info *rhs_iter = h->rhs_head; |
789 | NULL != rhs_iter && NULL != rhs_iter->next; | 788 | NULL != rhs_iter && NULL != rhs_iter->next; |
790 | rhs_iter = rhs_iter->next) | 789 | rhs_iter = rhs_iter->next) |
791 | { | 790 | { |
792 | RPS_sampler_update_with_nw_size (rhs_iter->sampler, | 791 | RPS_sampler_update_with_nw_size(rhs_iter->sampler, |
793 | GNUNET_NSE_log_estimate_to_n (logestimate)); | 792 | GNUNET_NSE_log_estimate_to_n(logestimate)); |
794 | } | 793 | } |
795 | } | 794 | } |
796 | 795 | ||
797 | 796 | ||
@@ -799,30 +798,30 @@ nse_cb (void *cls, | |||
799 | * Reconnect to the service | 798 | * Reconnect to the service |
800 | */ | 799 | */ |
801 | static void | 800 | static void |
802 | reconnect (struct GNUNET_RPS_Handle *h) | 801 | reconnect(struct GNUNET_RPS_Handle *h) |
803 | { | 802 | { |
804 | struct GNUNET_MQ_MessageHandler mq_handlers[] = { | 803 | struct GNUNET_MQ_MessageHandler mq_handlers[] = { |
805 | GNUNET_MQ_hd_var_size (view_update, | 804 | GNUNET_MQ_hd_var_size(view_update, |
806 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY, | 805 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY, |
807 | struct GNUNET_RPS_CS_DEBUG_ViewReply, | 806 | struct GNUNET_RPS_CS_DEBUG_ViewReply, |
808 | h), | 807 | h), |
809 | GNUNET_MQ_hd_var_size (stream_input, | 808 | GNUNET_MQ_hd_var_size(stream_input, |
810 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY, | 809 | GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY, |
811 | struct GNUNET_RPS_CS_DEBUG_StreamReply, | 810 | struct GNUNET_RPS_CS_DEBUG_StreamReply, |
812 | h), | 811 | h), |
813 | GNUNET_MQ_handler_end () | 812 | GNUNET_MQ_handler_end() |
814 | }; | 813 | }; |
815 | 814 | ||
816 | if (NULL != h->mq) | 815 | if (NULL != h->mq) |
817 | GNUNET_MQ_destroy (h->mq); | 816 | GNUNET_MQ_destroy(h->mq); |
818 | h->mq = GNUNET_CLIENT_connect (h->cfg, | 817 | h->mq = GNUNET_CLIENT_connect(h->cfg, |
819 | "rps", | 818 | "rps", |
820 | mq_handlers, | 819 | mq_handlers, |
821 | &mq_error_handler, | 820 | &mq_error_handler, |
822 | h); | 821 | h); |
823 | if (NULL != h->nse) | 822 | if (NULL != h->nse) |
824 | GNUNET_NSE_disconnect (h->nse); | 823 | GNUNET_NSE_disconnect(h->nse); |
825 | h->nse = GNUNET_NSE_connect (h->cfg, &nse_cb, h); | 824 | h->nse = GNUNET_NSE_connect(h->cfg, &nse_cb, h); |
826 | } | 825 | } |
827 | 826 | ||
828 | 827 | ||
@@ -833,56 +832,56 @@ reconnect (struct GNUNET_RPS_Handle *h) | |||
833 | * @return a handle to the service, NULL on error | 832 | * @return a handle to the service, NULL on error |
834 | */ | 833 | */ |
835 | struct GNUNET_RPS_Handle * | 834 | struct GNUNET_RPS_Handle * |
836 | GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | 835 | GNUNET_RPS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) |
837 | { | 836 | { |
838 | struct GNUNET_RPS_Handle *h; | 837 | struct GNUNET_RPS_Handle *h; |
839 | 838 | ||
840 | h = GNUNET_new (struct GNUNET_RPS_Handle); | 839 | h = GNUNET_new(struct GNUNET_RPS_Handle); |
841 | h->cfg = cfg; | 840 | h->cfg = cfg; |
842 | if (GNUNET_OK != | 841 | if (GNUNET_OK != |
843 | GNUNET_CONFIGURATION_get_value_float (cfg, | 842 | GNUNET_CONFIGURATION_get_value_float(cfg, |
844 | "RPS", | 843 | "RPS", |
845 | "DESIRED_PROBABILITY", | 844 | "DESIRED_PROBABILITY", |
846 | &h->desired_probability)) | 845 | &h->desired_probability)) |
847 | { | 846 | { |
848 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 847 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
849 | "RPS", "DESIRED_PROBABILITY"); | 848 | "RPS", "DESIRED_PROBABILITY"); |
850 | GNUNET_free (h); | 849 | GNUNET_free(h); |
851 | return NULL; | 850 | return NULL; |
852 | } | 851 | } |
853 | if (0 > h->desired_probability || | 852 | if (0 > h->desired_probability || |
854 | 1 < h->desired_probability) | 853 | 1 < h->desired_probability) |
855 | { | 854 | { |
856 | LOG (GNUNET_ERROR_TYPE_ERROR, | 855 | LOG(GNUNET_ERROR_TYPE_ERROR, |
857 | "The desired probability must be in the interval [0;1]\n"); | 856 | "The desired probability must be in the interval [0;1]\n"); |
858 | GNUNET_free (h); | 857 | GNUNET_free(h); |
859 | return NULL; | 858 | return NULL; |
860 | } | 859 | } |
861 | if (GNUNET_OK != | 860 | if (GNUNET_OK != |
862 | GNUNET_CONFIGURATION_get_value_float (cfg, | 861 | GNUNET_CONFIGURATION_get_value_float(cfg, |
863 | "RPS", | 862 | "RPS", |
864 | "DEFICIENCY_FACTOR", | 863 | "DEFICIENCY_FACTOR", |
865 | &h->deficiency_factor)) | 864 | &h->deficiency_factor)) |
866 | { | 865 | { |
867 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 866 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
868 | "RPS", "DEFICIENCY_FACTOR"); | 867 | "RPS", "DEFICIENCY_FACTOR"); |
869 | GNUNET_free (h); | 868 | GNUNET_free(h); |
870 | return NULL; | 869 | return NULL; |
871 | } | 870 | } |
872 | if (0 > h->desired_probability || | 871 | if (0 > h->desired_probability || |
873 | 1 < h->desired_probability) | 872 | 1 < h->desired_probability) |
874 | { | 873 | { |
875 | LOG (GNUNET_ERROR_TYPE_ERROR, | 874 | LOG(GNUNET_ERROR_TYPE_ERROR, |
876 | "The deficiency factor must be in the interval [0;1]\n"); | 875 | "The deficiency factor must be in the interval [0;1]\n"); |
877 | GNUNET_free (h); | 876 | GNUNET_free(h); |
878 | return NULL; | 877 | return NULL; |
879 | } | 878 | } |
880 | reconnect (h); | 879 | reconnect(h); |
881 | if (NULL == h->mq) | 880 | if (NULL == h->mq) |
882 | { | 881 | { |
883 | GNUNET_free (h); | 882 | GNUNET_free(h); |
884 | return NULL; | 883 | return NULL; |
885 | } | 884 | } |
886 | return h; | 885 | return h; |
887 | } | 886 | } |
888 | 887 | ||
@@ -894,19 +893,19 @@ GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
894 | * @param shared_value The shared value that defines the members of the sub (-gorup) | 893 | * @param shared_value The shared value that defines the members of the sub (-gorup) |
895 | */ | 894 | */ |
896 | void | 895 | void |
897 | GNUNET_RPS_sub_start (struct GNUNET_RPS_Handle *h, | 896 | GNUNET_RPS_sub_start(struct GNUNET_RPS_Handle *h, |
898 | const char *shared_value) | 897 | const char *shared_value) |
899 | { | 898 | { |
900 | struct GNUNET_RPS_CS_SubStartMessage *msg; | 899 | struct GNUNET_RPS_CS_SubStartMessage *msg; |
901 | struct GNUNET_MQ_Envelope *ev; | 900 | struct GNUNET_MQ_Envelope *ev; |
902 | 901 | ||
903 | ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_SUB_START); | 902 | ev = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_RPS_CS_SUB_START); |
904 | hash_from_share_val (shared_value, &msg->hash); | 903 | hash_from_share_val(shared_value, &msg->hash); |
905 | msg->round_interval = GNUNET_TIME_relative_hton (// TODO read from config! | 904 | msg->round_interval = GNUNET_TIME_relative_hton( // TODO read from config! |
906 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)); | 905 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)); |
907 | GNUNET_assert (0 != msg->round_interval.rel_value_us__); | 906 | GNUNET_assert(0 != msg->round_interval.rel_value_us__); |
908 | 907 | ||
909 | GNUNET_MQ_send (h->mq, ev); | 908 | GNUNET_MQ_send(h->mq, ev); |
910 | } | 909 | } |
911 | 910 | ||
912 | 911 | ||
@@ -917,16 +916,16 @@ GNUNET_RPS_sub_start (struct GNUNET_RPS_Handle *h, | |||
917 | * @param shared_value The shared value that defines the members of the sub (-gorup) | 916 | * @param shared_value The shared value that defines the members of the sub (-gorup) |
918 | */ | 917 | */ |
919 | void | 918 | void |
920 | GNUNET_RPS_sub_stop (struct GNUNET_RPS_Handle *h, | 919 | GNUNET_RPS_sub_stop(struct GNUNET_RPS_Handle *h, |
921 | const char *shared_value) | 920 | const char *shared_value) |
922 | { | 921 | { |
923 | struct GNUNET_RPS_CS_SubStopMessage *msg; | 922 | struct GNUNET_RPS_CS_SubStopMessage *msg; |
924 | struct GNUNET_MQ_Envelope *ev; | 923 | struct GNUNET_MQ_Envelope *ev; |
925 | 924 | ||
926 | ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_SUB_STOP); | 925 | ev = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_RPS_CS_SUB_STOP); |
927 | hash_from_share_val (shared_value, &msg->hash); | 926 | hash_from_share_val(shared_value, &msg->hash); |
928 | 927 | ||
929 | GNUNET_MQ_send (h->mq, ev); | 928 | GNUNET_MQ_send(h->mq, ev); |
930 | } | 929 | } |
931 | 930 | ||
932 | 931 | ||
@@ -940,37 +939,37 @@ GNUNET_RPS_sub_stop (struct GNUNET_RPS_Handle *h, | |||
940 | * @return a handle to cancel this request | 939 | * @return a handle to cancel this request |
941 | */ | 940 | */ |
942 | struct GNUNET_RPS_Request_Handle * | 941 | struct GNUNET_RPS_Request_Handle * |
943 | GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle, | 942 | GNUNET_RPS_request_peers(struct GNUNET_RPS_Handle *rps_handle, |
944 | uint32_t num_req_peers, | 943 | uint32_t num_req_peers, |
945 | GNUNET_RPS_NotifyReadyCB ready_cb, | 944 | GNUNET_RPS_NotifyReadyCB ready_cb, |
946 | void *cls) | 945 | void *cls) |
947 | { | 946 | { |
948 | struct GNUNET_RPS_Request_Handle *rh; | 947 | struct GNUNET_RPS_Request_Handle *rh; |
949 | 948 | ||
950 | LOG (GNUNET_ERROR_TYPE_INFO, | 949 | LOG(GNUNET_ERROR_TYPE_INFO, |
951 | "Client requested %" PRIu32 " peers\n", | 950 | "Client requested %" PRIu32 " peers\n", |
952 | num_req_peers); | 951 | num_req_peers); |
953 | rh = GNUNET_new (struct GNUNET_RPS_Request_Handle); | 952 | rh = GNUNET_new(struct GNUNET_RPS_Request_Handle); |
954 | rh->rps_handle = rps_handle; | 953 | rh->rps_handle = rps_handle; |
955 | rh->num_requests = num_req_peers; | 954 | rh->num_requests = num_req_peers; |
956 | rh->sampler = RPS_sampler_mod_init (num_req_peers, | 955 | rh->sampler = RPS_sampler_mod_init(num_req_peers, |
957 | GNUNET_TIME_UNIT_SECONDS); // TODO remove this time-stuff | 956 | GNUNET_TIME_UNIT_SECONDS); // TODO remove this time-stuff |
958 | RPS_sampler_set_desired_probability (rh->sampler, | 957 | RPS_sampler_set_desired_probability(rh->sampler, |
959 | rps_handle->desired_probability); | 958 | rps_handle->desired_probability); |
960 | RPS_sampler_set_deficiency_factor (rh->sampler, | 959 | RPS_sampler_set_deficiency_factor(rh->sampler, |
961 | rps_handle->deficiency_factor); | 960 | rps_handle->deficiency_factor); |
962 | rh->sampler_rh = RPS_sampler_get_n_rand_peers (rh->sampler, | 961 | rh->sampler_rh = RPS_sampler_get_n_rand_peers(rh->sampler, |
963 | num_req_peers, | 962 | num_req_peers, |
964 | peers_ready_cb, | 963 | peers_ready_cb, |
965 | rh); | 964 | rh); |
966 | rh->srh = GNUNET_RPS_stream_request (rps_handle, | 965 | rh->srh = GNUNET_RPS_stream_request(rps_handle, |
967 | collect_peers_cb, | 966 | collect_peers_cb, |
968 | rh); /* cls */ | 967 | rh); /* cls */ |
969 | rh->ready_cb = ready_cb; | 968 | rh->ready_cb = ready_cb; |
970 | rh->ready_cb_cls = cls; | 969 | rh->ready_cb_cls = cls; |
971 | GNUNET_CONTAINER_DLL_insert (rps_handle->rh_head, | 970 | GNUNET_CONTAINER_DLL_insert(rps_handle->rh_head, |
972 | rps_handle->rh_tail, | 971 | rps_handle->rh_tail, |
973 | rh); | 972 | rh); |
974 | 973 | ||
975 | return rh; | 974 | return rh; |
976 | } | 975 | } |
@@ -985,34 +984,34 @@ GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle, | |||
985 | * @return a handle to cancel this request | 984 | * @return a handle to cancel this request |
986 | */ | 985 | */ |
987 | struct GNUNET_RPS_Request_Handle_Single_Info * | 986 | struct GNUNET_RPS_Request_Handle_Single_Info * |
988 | GNUNET_RPS_request_peer_info (struct GNUNET_RPS_Handle *rps_handle, | 987 | GNUNET_RPS_request_peer_info(struct GNUNET_RPS_Handle *rps_handle, |
989 | GNUNET_RPS_NotifyReadySingleInfoCB ready_cb, | 988 | GNUNET_RPS_NotifyReadySingleInfoCB ready_cb, |
990 | void *cls) | 989 | void *cls) |
991 | { | 990 | { |
992 | struct GNUNET_RPS_Request_Handle_Single_Info *rhs; | 991 | struct GNUNET_RPS_Request_Handle_Single_Info *rhs; |
993 | uint32_t num_req_peers = 1; | 992 | uint32_t num_req_peers = 1; |
994 | 993 | ||
995 | LOG (GNUNET_ERROR_TYPE_INFO, | 994 | LOG(GNUNET_ERROR_TYPE_INFO, |
996 | "Client requested peer with additional info\n"); | 995 | "Client requested peer with additional info\n"); |
997 | rhs = GNUNET_new (struct GNUNET_RPS_Request_Handle_Single_Info); | 996 | rhs = GNUNET_new(struct GNUNET_RPS_Request_Handle_Single_Info); |
998 | rhs->rps_handle = rps_handle; | 997 | rhs->rps_handle = rps_handle; |
999 | rhs->sampler = RPS_sampler_mod_init (num_req_peers, | 998 | rhs->sampler = RPS_sampler_mod_init(num_req_peers, |
1000 | GNUNET_TIME_UNIT_SECONDS); // TODO remove this time-stuff | 999 | GNUNET_TIME_UNIT_SECONDS); // TODO remove this time-stuff |
1001 | RPS_sampler_set_desired_probability (rhs->sampler, | 1000 | RPS_sampler_set_desired_probability(rhs->sampler, |
1002 | rps_handle->desired_probability); | 1001 | rps_handle->desired_probability); |
1003 | RPS_sampler_set_deficiency_factor (rhs->sampler, | 1002 | RPS_sampler_set_deficiency_factor(rhs->sampler, |
1004 | rps_handle->deficiency_factor); | 1003 | rps_handle->deficiency_factor); |
1005 | rhs->sampler_rh = RPS_sampler_get_rand_peer_info (rhs->sampler, | 1004 | rhs->sampler_rh = RPS_sampler_get_rand_peer_info(rhs->sampler, |
1006 | peer_info_ready_cb, | 1005 | peer_info_ready_cb, |
1007 | rhs); | 1006 | rhs); |
1008 | rhs->srh = GNUNET_RPS_stream_request (rps_handle, | 1007 | rhs->srh = GNUNET_RPS_stream_request(rps_handle, |
1009 | collect_peers_info_cb, | 1008 | collect_peers_info_cb, |
1010 | rhs); /* cls */ | 1009 | rhs); /* cls */ |
1011 | rhs->ready_cb = ready_cb; | 1010 | rhs->ready_cb = ready_cb; |
1012 | rhs->ready_cb_cls = cls; | 1011 | rhs->ready_cb_cls = cls; |
1013 | GNUNET_CONTAINER_DLL_insert (rps_handle->rhs_head, | 1012 | GNUNET_CONTAINER_DLL_insert(rps_handle->rhs_head, |
1014 | rps_handle->rhs_tail, | 1013 | rps_handle->rhs_tail, |
1015 | rhs); | 1014 | rhs); |
1016 | 1015 | ||
1017 | return rhs; | 1016 | return rhs; |
1018 | } | 1017 | } |
@@ -1026,9 +1025,9 @@ GNUNET_RPS_request_peer_info (struct GNUNET_RPS_Handle *rps_handle, | |||
1026 | * @param ids the ids of the peers seeded | 1025 | * @param ids the ids of the peers seeded |
1027 | */ | 1026 | */ |
1028 | void | 1027 | void |
1029 | GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, | 1028 | GNUNET_RPS_seed_ids(struct GNUNET_RPS_Handle *h, |
1030 | uint32_t n, | 1029 | uint32_t n, |
1031 | const struct GNUNET_PeerIdentity *ids) | 1030 | const struct GNUNET_PeerIdentity *ids) |
1032 | { | 1031 | { |
1033 | size_t size_needed; | 1032 | size_t size_needed; |
1034 | uint32_t num_peers_max; | 1033 | uint32_t num_peers_max; |
@@ -1036,52 +1035,52 @@ GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, | |||
1036 | struct GNUNET_MQ_Envelope *ev; | 1035 | struct GNUNET_MQ_Envelope *ev; |
1037 | struct GNUNET_RPS_CS_SeedMessage *msg; | 1036 | struct GNUNET_RPS_CS_SeedMessage *msg; |
1038 | 1037 | ||
1039 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1038 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1040 | "Client wants to seed %" PRIu32 " peers:\n", | 1039 | "Client wants to seed %" PRIu32 " peers:\n", |
1041 | n); | 1040 | n); |
1042 | for (unsigned int i = 0 ; i < n ; i++) | 1041 | for (unsigned int i = 0; i < n; i++) |
1043 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1042 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1044 | "%u. peer: %s\n", | 1043 | "%u. peer: %s\n", |
1045 | i, | 1044 | i, |
1046 | GNUNET_i2s (&ids[i])); | 1045 | GNUNET_i2s(&ids[i])); |
1047 | 1046 | ||
1048 | /* The actual size the message occupies */ | 1047 | /* The actual size the message occupies */ |
1049 | size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) + | 1048 | size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage) + |
1050 | n * sizeof (struct GNUNET_PeerIdentity); | 1049 | n * sizeof(struct GNUNET_PeerIdentity); |
1051 | /* The number of peers that fits in one message together with | 1050 | /* The number of peers that fits in one message together with |
1052 | * the respective header */ | 1051 | * the respective header */ |
1053 | num_peers_max = (GNUNET_MAX_MESSAGE_SIZE - | 1052 | num_peers_max = (GNUNET_MAX_MESSAGE_SIZE - |
1054 | sizeof (struct GNUNET_RPS_CS_SeedMessage)) / | 1053 | sizeof(struct GNUNET_RPS_CS_SeedMessage)) / |
1055 | sizeof (struct GNUNET_PeerIdentity); | 1054 | sizeof(struct GNUNET_PeerIdentity); |
1056 | tmp_peer_pointer = ids; | 1055 | tmp_peer_pointer = ids; |
1057 | 1056 | ||
1058 | while (GNUNET_MAX_MESSAGE_SIZE < size_needed) | 1057 | while (GNUNET_MAX_MESSAGE_SIZE < size_needed) |
1059 | { | 1058 | { |
1060 | ev = GNUNET_MQ_msg_extra (msg, | 1059 | ev = GNUNET_MQ_msg_extra(msg, |
1061 | num_peers_max * sizeof (struct GNUNET_PeerIdentity), | 1060 | num_peers_max * sizeof(struct GNUNET_PeerIdentity), |
1062 | GNUNET_MESSAGE_TYPE_RPS_CS_SEED); | 1061 | GNUNET_MESSAGE_TYPE_RPS_CS_SEED); |
1063 | msg->num_peers = htonl (num_peers_max); | 1062 | msg->num_peers = htonl(num_peers_max); |
1064 | GNUNET_memcpy (&msg[1], | 1063 | GNUNET_memcpy(&msg[1], |
1065 | tmp_peer_pointer, | 1064 | tmp_peer_pointer, |
1066 | num_peers_max * sizeof (struct GNUNET_PeerIdentity)); | 1065 | num_peers_max * sizeof(struct GNUNET_PeerIdentity)); |
1067 | GNUNET_MQ_send (h->mq, | 1066 | GNUNET_MQ_send(h->mq, |
1068 | ev); | 1067 | ev); |
1069 | n -= num_peers_max; | 1068 | n -= num_peers_max; |
1070 | size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) + | 1069 | size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage) + |
1071 | n * sizeof (struct GNUNET_PeerIdentity); | 1070 | n * sizeof(struct GNUNET_PeerIdentity); |
1072 | /* Set pointer to beginning of next block of num_peers_max peers */ | 1071 | /* Set pointer to beginning of next block of num_peers_max peers */ |
1073 | tmp_peer_pointer = &ids[num_peers_max]; | 1072 | tmp_peer_pointer = &ids[num_peers_max]; |
1074 | } | 1073 | } |
1075 | 1074 | ||
1076 | ev = GNUNET_MQ_msg_extra (msg, | 1075 | ev = GNUNET_MQ_msg_extra(msg, |
1077 | n * sizeof (struct GNUNET_PeerIdentity), | 1076 | n * sizeof(struct GNUNET_PeerIdentity), |
1078 | GNUNET_MESSAGE_TYPE_RPS_CS_SEED); | 1077 | GNUNET_MESSAGE_TYPE_RPS_CS_SEED); |
1079 | msg->num_peers = htonl (n); | 1078 | msg->num_peers = htonl(n); |
1080 | GNUNET_memcpy (&msg[1], | 1079 | GNUNET_memcpy(&msg[1], |
1081 | tmp_peer_pointer, | 1080 | tmp_peer_pointer, |
1082 | n * sizeof (struct GNUNET_PeerIdentity)); | 1081 | n * sizeof(struct GNUNET_PeerIdentity)); |
1083 | GNUNET_MQ_send (h->mq, | 1082 | GNUNET_MQ_send(h->mq, |
1084 | ev); | 1083 | ev); |
1085 | } | 1084 | } |
1086 | 1085 | ||
1087 | 1086 | ||
@@ -1101,11 +1100,11 @@ GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, | |||
1101 | * peer to be isolated from the rest | 1100 | * peer to be isolated from the rest |
1102 | */ | 1101 | */ |
1103 | void | 1102 | void |
1104 | GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h, | 1103 | GNUNET_RPS_act_malicious(struct GNUNET_RPS_Handle *h, |
1105 | uint32_t type, | 1104 | uint32_t type, |
1106 | uint32_t num_peers, | 1105 | uint32_t num_peers, |
1107 | const struct GNUNET_PeerIdentity *peer_ids, | 1106 | const struct GNUNET_PeerIdentity *peer_ids, |
1108 | const struct GNUNET_PeerIdentity *target_peer) | 1107 | const struct GNUNET_PeerIdentity *target_peer) |
1109 | { | 1108 | { |
1110 | size_t size_needed; | 1109 | size_t size_needed; |
1111 | uint32_t num_peers_max; | 1110 | uint32_t num_peers_max; |
@@ -1115,65 +1114,65 @@ GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h, | |||
1115 | 1114 | ||
1116 | unsigned int i; | 1115 | unsigned int i; |
1117 | 1116 | ||
1118 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1117 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1119 | "Client turns malicious (type %" PRIu32 ") with %" PRIu32 " other peers:\n", | 1118 | "Client turns malicious (type %" PRIu32 ") with %" PRIu32 " other peers:\n", |
1120 | type, | 1119 | type, |
1121 | num_peers); | 1120 | num_peers); |
1122 | for (i = 0 ; i < num_peers ; i++) | 1121 | for (i = 0; i < num_peers; i++) |
1123 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1122 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1124 | "%u. peer: %s\n", | 1123 | "%u. peer: %s\n", |
1125 | i, | 1124 | i, |
1126 | GNUNET_i2s (&peer_ids[i])); | 1125 | GNUNET_i2s(&peer_ids[i])); |
1127 | 1126 | ||
1128 | /* The actual size the message would occupy */ | 1127 | /* The actual size the message would occupy */ |
1129 | size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) + | 1128 | size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage) + |
1130 | num_peers * sizeof (struct GNUNET_PeerIdentity); | 1129 | num_peers * sizeof(struct GNUNET_PeerIdentity); |
1131 | /* The number of peers that fit in one message together with | 1130 | /* The number of peers that fit in one message together with |
1132 | * the respective header */ | 1131 | * the respective header */ |
1133 | num_peers_max = (GNUNET_MAX_MESSAGE_SIZE - | 1132 | num_peers_max = (GNUNET_MAX_MESSAGE_SIZE - |
1134 | sizeof (struct GNUNET_RPS_CS_SeedMessage)) / | 1133 | sizeof(struct GNUNET_RPS_CS_SeedMessage)) / |
1135 | sizeof (struct GNUNET_PeerIdentity); | 1134 | sizeof(struct GNUNET_PeerIdentity); |
1136 | tmp_peer_pointer = peer_ids; | 1135 | tmp_peer_pointer = peer_ids; |
1137 | 1136 | ||
1138 | while (GNUNET_MAX_MESSAGE_SIZE < size_needed) | 1137 | while (GNUNET_MAX_MESSAGE_SIZE < size_needed) |
1139 | { | 1138 | { |
1140 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1139 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1141 | "Too many peers to send at once, sending %" PRIu32 " (all we can so far)\n", | 1140 | "Too many peers to send at once, sending %" PRIu32 " (all we can so far)\n", |
1142 | num_peers_max); | 1141 | num_peers_max); |
1143 | ev = GNUNET_MQ_msg_extra (msg, | 1142 | ev = GNUNET_MQ_msg_extra(msg, |
1144 | num_peers_max * sizeof (struct GNUNET_PeerIdentity), | 1143 | num_peers_max * sizeof(struct GNUNET_PeerIdentity), |
1145 | GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS); | 1144 | GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS); |
1146 | msg->type = htonl (type); | 1145 | msg->type = htonl(type); |
1147 | msg->num_peers = htonl (num_peers_max); | 1146 | msg->num_peers = htonl(num_peers_max); |
1148 | if ( (2 == type) || | 1147 | if ((2 == type) || |
1149 | (3 == type) ) | 1148 | (3 == type)) |
1150 | msg->attacked_peer = peer_ids[num_peers]; | 1149 | msg->attacked_peer = peer_ids[num_peers]; |
1151 | GNUNET_memcpy (&msg[1], | 1150 | GNUNET_memcpy(&msg[1], |
1152 | tmp_peer_pointer, | 1151 | tmp_peer_pointer, |
1153 | num_peers_max * sizeof (struct GNUNET_PeerIdentity)); | 1152 | num_peers_max * sizeof(struct GNUNET_PeerIdentity)); |
1154 | 1153 | ||
1155 | GNUNET_MQ_send (h->mq, ev); | 1154 | GNUNET_MQ_send(h->mq, ev); |
1156 | 1155 | ||
1157 | num_peers -= num_peers_max; | 1156 | num_peers -= num_peers_max; |
1158 | size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) + | 1157 | size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage) + |
1159 | num_peers * sizeof (struct GNUNET_PeerIdentity); | 1158 | num_peers * sizeof(struct GNUNET_PeerIdentity); |
1160 | /* Set pointer to beginning of next block of num_peers_max peers */ | 1159 | /* Set pointer to beginning of next block of num_peers_max peers */ |
1161 | tmp_peer_pointer = &peer_ids[num_peers_max]; | 1160 | tmp_peer_pointer = &peer_ids[num_peers_max]; |
1162 | } | 1161 | } |
1163 | 1162 | ||
1164 | ev = GNUNET_MQ_msg_extra (msg, | 1163 | ev = GNUNET_MQ_msg_extra(msg, |
1165 | num_peers * sizeof (struct GNUNET_PeerIdentity), | 1164 | num_peers * sizeof(struct GNUNET_PeerIdentity), |
1166 | GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS); | 1165 | GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS); |
1167 | msg->type = htonl (type); | 1166 | msg->type = htonl(type); |
1168 | msg->num_peers = htonl (num_peers); | 1167 | msg->num_peers = htonl(num_peers); |
1169 | if ( (2 == type) || | 1168 | if ((2 == type) || |
1170 | (3 == type) ) | 1169 | (3 == type)) |
1171 | msg->attacked_peer = *target_peer; | 1170 | msg->attacked_peer = *target_peer; |
1172 | GNUNET_memcpy (&msg[1], | 1171 | GNUNET_memcpy(&msg[1], |
1173 | tmp_peer_pointer, | 1172 | tmp_peer_pointer, |
1174 | num_peers * sizeof (struct GNUNET_PeerIdentity)); | 1173 | num_peers * sizeof(struct GNUNET_PeerIdentity)); |
1175 | 1174 | ||
1176 | GNUNET_MQ_send (h->mq, ev); | 1175 | GNUNET_MQ_send(h->mq, ev); |
1177 | } | 1176 | } |
1178 | #endif /* ENABLE_MALICIOUS */ | 1177 | #endif /* ENABLE_MALICIOUS */ |
1179 | 1178 | ||
@@ -1184,27 +1183,28 @@ GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h, | |||
1184 | * @param rh request handle of request to cancle | 1183 | * @param rh request handle of request to cancle |
1185 | */ | 1184 | */ |
1186 | void | 1185 | void |
1187 | GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh) | 1186 | GNUNET_RPS_request_cancel(struct GNUNET_RPS_Request_Handle *rh) |
1188 | { | 1187 | { |
1189 | struct GNUNET_RPS_Handle *h; | 1188 | struct GNUNET_RPS_Handle *h; |
1190 | 1189 | ||
1191 | h = rh->rps_handle; | 1190 | h = rh->rps_handle; |
1192 | GNUNET_assert (NULL != rh); | 1191 | GNUNET_assert(NULL != rh); |
1193 | GNUNET_assert (NULL != rh->srh); | 1192 | GNUNET_assert(NULL != rh->srh); |
1194 | GNUNET_assert (h == rh->srh->rps_handle); | 1193 | GNUNET_assert(h == rh->srh->rps_handle); |
1195 | GNUNET_RPS_stream_cancel (rh->srh); | 1194 | GNUNET_RPS_stream_cancel(rh->srh); |
1196 | rh->srh = NULL; | 1195 | rh->srh = NULL; |
1197 | if (NULL == h->stream_requests_head) cancel_stream(h); | 1196 | if (NULL == h->stream_requests_head) |
1197 | cancel_stream(h); | ||
1198 | if (NULL != rh->sampler_rh) | 1198 | if (NULL != rh->sampler_rh) |
1199 | { | 1199 | { |
1200 | RPS_sampler_request_cancel (rh->sampler_rh); | 1200 | RPS_sampler_request_cancel(rh->sampler_rh); |
1201 | } | 1201 | } |
1202 | RPS_sampler_destroy (rh->sampler); | 1202 | RPS_sampler_destroy(rh->sampler); |
1203 | rh->sampler = NULL; | 1203 | rh->sampler = NULL; |
1204 | GNUNET_CONTAINER_DLL_remove (h->rh_head, | 1204 | GNUNET_CONTAINER_DLL_remove(h->rh_head, |
1205 | h->rh_tail, | 1205 | h->rh_tail, |
1206 | rh); | 1206 | rh); |
1207 | GNUNET_free (rh); | 1207 | GNUNET_free(rh); |
1208 | } | 1208 | } |
1209 | 1209 | ||
1210 | 1210 | ||
@@ -1214,28 +1214,29 @@ GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh) | |||
1214 | * @param rhs request handle of request to cancle | 1214 | * @param rhs request handle of request to cancle |
1215 | */ | 1215 | */ |
1216 | void | 1216 | void |
1217 | GNUNET_RPS_request_single_info_cancel ( | 1217 | GNUNET_RPS_request_single_info_cancel( |
1218 | struct GNUNET_RPS_Request_Handle_Single_Info *rhs) | 1218 | struct GNUNET_RPS_Request_Handle_Single_Info *rhs) |
1219 | { | 1219 | { |
1220 | struct GNUNET_RPS_Handle *h; | 1220 | struct GNUNET_RPS_Handle *h; |
1221 | 1221 | ||
1222 | h = rhs->rps_handle; | 1222 | h = rhs->rps_handle; |
1223 | GNUNET_assert (NULL != rhs); | 1223 | GNUNET_assert(NULL != rhs); |
1224 | GNUNET_assert (NULL != rhs->srh); | 1224 | GNUNET_assert(NULL != rhs->srh); |
1225 | GNUNET_assert (h == rhs->srh->rps_handle); | 1225 | GNUNET_assert(h == rhs->srh->rps_handle); |
1226 | GNUNET_RPS_stream_cancel (rhs->srh); | 1226 | GNUNET_RPS_stream_cancel(rhs->srh); |
1227 | rhs->srh = NULL; | 1227 | rhs->srh = NULL; |
1228 | if (NULL == h->stream_requests_head) cancel_stream(h); | 1228 | if (NULL == h->stream_requests_head) |
1229 | cancel_stream(h); | ||
1229 | if (NULL != rhs->sampler_rh) | 1230 | if (NULL != rhs->sampler_rh) |
1230 | { | 1231 | { |
1231 | RPS_sampler_request_single_info_cancel (rhs->sampler_rh); | 1232 | RPS_sampler_request_single_info_cancel(rhs->sampler_rh); |
1232 | } | 1233 | } |
1233 | RPS_sampler_destroy (rhs->sampler); | 1234 | RPS_sampler_destroy(rhs->sampler); |
1234 | rhs->sampler = NULL; | 1235 | rhs->sampler = NULL; |
1235 | GNUNET_CONTAINER_DLL_remove (h->rhs_head, | 1236 | GNUNET_CONTAINER_DLL_remove(h->rhs_head, |
1236 | h->rhs_tail, | 1237 | h->rhs_tail, |
1237 | rhs); | 1238 | rhs); |
1238 | GNUNET_free (rhs); | 1239 | GNUNET_free(rhs); |
1239 | } | 1240 | } |
1240 | 1241 | ||
1241 | 1242 | ||
@@ -1245,59 +1246,59 @@ GNUNET_RPS_request_single_info_cancel ( | |||
1245 | * @param h the handle to the rps service | 1246 | * @param h the handle to the rps service |
1246 | */ | 1247 | */ |
1247 | void | 1248 | void |
1248 | GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h) | 1249 | GNUNET_RPS_disconnect(struct GNUNET_RPS_Handle *h) |
1249 | { | 1250 | { |
1250 | if (NULL != h->stream_requests_head) | 1251 | if (NULL != h->stream_requests_head) |
1251 | { | ||
1252 | struct GNUNET_RPS_StreamRequestHandle *srh_next; | ||
1253 | |||
1254 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1255 | "Still waiting for replies\n"); | ||
1256 | for (struct GNUNET_RPS_StreamRequestHandle *srh_iter = h->stream_requests_head; | ||
1257 | NULL != srh_iter; | ||
1258 | srh_iter = srh_next) | ||
1259 | { | 1252 | { |
1260 | srh_next = srh_iter->next; | 1253 | struct GNUNET_RPS_StreamRequestHandle *srh_next; |
1261 | GNUNET_RPS_stream_cancel (srh_iter); | 1254 | |
1255 | LOG(GNUNET_ERROR_TYPE_WARNING, | ||
1256 | "Still waiting for replies\n"); | ||
1257 | for (struct GNUNET_RPS_StreamRequestHandle *srh_iter = h->stream_requests_head; | ||
1258 | NULL != srh_iter; | ||
1259 | srh_iter = srh_next) | ||
1260 | { | ||
1261 | srh_next = srh_iter->next; | ||
1262 | GNUNET_RPS_stream_cancel(srh_iter); | ||
1263 | } | ||
1262 | } | 1264 | } |
1263 | } | ||
1264 | if (NULL != h->rh_head) | 1265 | if (NULL != h->rh_head) |
1265 | { | ||
1266 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1267 | "Not all requests were cancelled!\n"); | ||
1268 | for (struct GNUNET_RPS_Request_Handle *rh_iter = h->rh_head; | ||
1269 | h->rh_head != NULL; | ||
1270 | rh_iter = h->rh_head) | ||
1271 | { | 1266 | { |
1272 | GNUNET_RPS_request_cancel (rh_iter); | 1267 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1268 | "Not all requests were cancelled!\n"); | ||
1269 | for (struct GNUNET_RPS_Request_Handle *rh_iter = h->rh_head; | ||
1270 | h->rh_head != NULL; | ||
1271 | rh_iter = h->rh_head) | ||
1272 | { | ||
1273 | GNUNET_RPS_request_cancel(rh_iter); | ||
1274 | } | ||
1273 | } | 1275 | } |
1274 | } | ||
1275 | if (NULL != h->rhs_head) | 1276 | if (NULL != h->rhs_head) |
1276 | { | ||
1277 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1278 | "Not all requests were cancelled!\n"); | ||
1279 | for (struct GNUNET_RPS_Request_Handle_Single_Info *rhs_iter = h->rhs_head; | ||
1280 | h->rhs_head != NULL; | ||
1281 | rhs_iter = h->rhs_head) | ||
1282 | { | 1277 | { |
1283 | GNUNET_RPS_request_single_info_cancel (rhs_iter); | 1278 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1279 | "Not all requests were cancelled!\n"); | ||
1280 | for (struct GNUNET_RPS_Request_Handle_Single_Info *rhs_iter = h->rhs_head; | ||
1281 | h->rhs_head != NULL; | ||
1282 | rhs_iter = h->rhs_head) | ||
1283 | { | ||
1284 | GNUNET_RPS_request_single_info_cancel(rhs_iter); | ||
1285 | } | ||
1284 | } | 1286 | } |
1285 | } | ||
1286 | if (NULL != srh_callback_peers) | 1287 | if (NULL != srh_callback_peers) |
1287 | { | 1288 | { |
1288 | GNUNET_free (srh_callback_peers); | 1289 | GNUNET_free(srh_callback_peers); |
1289 | srh_callback_peers = NULL; | 1290 | srh_callback_peers = NULL; |
1290 | } | 1291 | } |
1291 | if (NULL != h->view_update_cb) | 1292 | if (NULL != h->view_update_cb) |
1292 | { | 1293 | { |
1293 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1294 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1294 | "Still waiting for view updates\n"); | 1295 | "Still waiting for view updates\n"); |
1295 | GNUNET_RPS_view_request_cancel (h); | 1296 | GNUNET_RPS_view_request_cancel(h); |
1296 | } | 1297 | } |
1297 | if (NULL != h->nse) | 1298 | if (NULL != h->nse) |
1298 | GNUNET_NSE_disconnect (h->nse); | 1299 | GNUNET_NSE_disconnect(h->nse); |
1299 | GNUNET_MQ_destroy (h->mq); | 1300 | GNUNET_MQ_destroy(h->mq); |
1300 | GNUNET_free (h); | 1301 | GNUNET_free(h); |
1301 | } | 1302 | } |
1302 | 1303 | ||
1303 | 1304 | ||
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c index 7fc91743b..6bbb4c6ac 100644 --- a/src/rps/test_rps.c +++ b/src/rps/test_rps.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file rps/test_rps.c | 21 | * @file rps/test_rps.c |
22 | * @brief Testcase for the random peer sampling service. Starts | 22 | * @brief Testcase for the random peer sampling service. Starts |
@@ -85,8 +85,7 @@ enum PEER_ONLINE_DELTA { | |||
85 | /** | 85 | /** |
86 | * Operation map entry | 86 | * Operation map entry |
87 | */ | 87 | */ |
88 | struct OpListEntry | 88 | struct OpListEntry { |
89 | { | ||
90 | /** | 89 | /** |
91 | * DLL next ptr | 90 | * DLL next ptr |
92 | */ | 91 | */ |
@@ -128,8 +127,7 @@ static struct OpListEntry *oplist_tail; | |||
128 | /** | 127 | /** |
129 | * A pending reply: A request was sent and the reply is pending. | 128 | * A pending reply: A request was sent and the reply is pending. |
130 | */ | 129 | */ |
131 | struct PendingReply | 130 | struct PendingReply { |
132 | { | ||
133 | /** | 131 | /** |
134 | * DLL next,prev ptr | 132 | * DLL next,prev ptr |
135 | */ | 133 | */ |
@@ -151,8 +149,7 @@ struct PendingReply | |||
151 | /** | 149 | /** |
152 | * A pending request: A request was not made yet but is scheduled for later. | 150 | * A pending request: A request was not made yet but is scheduled for later. |
153 | */ | 151 | */ |
154 | struct PendingRequest | 152 | struct PendingRequest { |
155 | { | ||
156 | /** | 153 | /** |
157 | * DLL next,prev ptr | 154 | * DLL next,prev ptr |
158 | */ | 155 | */ |
@@ -174,8 +171,7 @@ struct PendingRequest | |||
174 | /** | 171 | /** |
175 | * Information we track for each peer. | 172 | * Information we track for each peer. |
176 | */ | 173 | */ |
177 | struct RPSPeer | 174 | struct RPSPeer { |
178 | { | ||
179 | /** | 175 | /** |
180 | * Index of the peer. | 176 | * Index of the peer. |
181 | */ | 177 | */ |
@@ -311,8 +307,7 @@ struct RPSPeer | |||
311 | uint64_t num_recv_pull_rep; | 307 | uint64_t num_recv_pull_rep; |
312 | }; | 308 | }; |
313 | 309 | ||
314 | enum STAT_TYPE | 310 | enum STAT_TYPE { |
315 | { | ||
316 | STAT_TYPE_ROUNDS = 0x1, /* 1 */ | 311 | STAT_TYPE_ROUNDS = 0x1, /* 1 */ |
317 | STAT_TYPE_BLOCKS = 0x2, /* 2 */ | 312 | STAT_TYPE_BLOCKS = 0x2, /* 2 */ |
318 | STAT_TYPE_BLOCKS_MANY_PUSH = 0x4, /* 3 */ | 313 | STAT_TYPE_BLOCKS_MANY_PUSH = 0x4, /* 3 */ |
@@ -332,8 +327,7 @@ enum STAT_TYPE | |||
332 | STAT_TYPE_MAX = 0x80000000, /* 32 */ | 327 | STAT_TYPE_MAX = 0x80000000, /* 32 */ |
333 | }; | 328 | }; |
334 | 329 | ||
335 | struct STATcls | 330 | struct STATcls { |
336 | { | ||
337 | struct RPSPeer *rps_peer; | 331 | struct RPSPeer *rps_peer; |
338 | enum STAT_TYPE stat_type; | 332 | enum STAT_TYPE stat_type; |
339 | }; | 333 | }; |
@@ -497,8 +491,7 @@ enum OPTION_COLLECT_VIEW { | |||
497 | /** | 491 | /** |
498 | * Structure to define a single test | 492 | * Structure to define a single test |
499 | */ | 493 | */ |
500 | struct SingleTestRun | 494 | struct SingleTestRun { |
501 | { | ||
502 | /** | 495 | /** |
503 | * Name of the test | 496 | * Name of the test |
504 | */ | 497 | */ |
@@ -585,7 +578,7 @@ static int in_shutdown; | |||
585 | * Append arguments to file | 578 | * Append arguments to file |
586 | */ | 579 | */ |
587 | static void | 580 | static void |
588 | tofile_ (const char *file_name, const char *line) | 581 | tofile_(const char *file_name, const char *line) |
589 | { | 582 | { |
590 | struct GNUNET_DISK_FileHandle *f; | 583 | struct GNUNET_DISK_FileHandle *f; |
591 | /* char output_buffer[512]; */ | 584 | /* char output_buffer[512]; */ |
@@ -593,69 +586,69 @@ tofile_ (const char *file_name, const char *line) | |||
593 | /* int size; */ | 586 | /* int size; */ |
594 | size_t size2; | 587 | size_t size2; |
595 | 588 | ||
596 | if (NULL == (f = GNUNET_DISK_file_open (file_name, | 589 | if (NULL == (f = GNUNET_DISK_file_open(file_name, |
597 | GNUNET_DISK_OPEN_APPEND | | 590 | GNUNET_DISK_OPEN_APPEND | |
598 | GNUNET_DISK_OPEN_WRITE | | 591 | GNUNET_DISK_OPEN_WRITE | |
599 | GNUNET_DISK_OPEN_CREATE, | 592 | GNUNET_DISK_OPEN_CREATE, |
600 | GNUNET_DISK_PERM_USER_READ | | 593 | GNUNET_DISK_PERM_USER_READ | |
601 | GNUNET_DISK_PERM_USER_WRITE | | 594 | GNUNET_DISK_PERM_USER_WRITE | |
602 | GNUNET_DISK_PERM_GROUP_READ | | 595 | GNUNET_DISK_PERM_GROUP_READ | |
603 | GNUNET_DISK_PERM_OTHER_READ))) | 596 | GNUNET_DISK_PERM_OTHER_READ))) |
604 | { | 597 | { |
605 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 598 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
606 | "Not able to open file %s\n", | 599 | "Not able to open file %s\n", |
607 | file_name); | 600 | file_name); |
608 | return; | 601 | return; |
609 | } | 602 | } |
610 | /* size = GNUNET_snprintf (output_buffer, | 603 | /* size = GNUNET_snprintf (output_buffer, |
611 | sizeof (output_buffer), | 604 | sizeof (output_buffer), |
612 | "%llu %s\n", | 605 | "%llu %s\n", |
613 | GNUNET_TIME_absolute_get ().abs_value_us, | 606 | GNUNET_TIME_absolute_get ().abs_value_us, |
614 | line); | 607 | line); |
615 | if (0 > size) | 608 | if (0 > size) |
616 | { | 609 | { |
617 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 610 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
618 | "Failed to write string to buffer (size: %i)\n", | 611 | "Failed to write string to buffer (size: %i)\n", |
619 | size); | 612 | size); |
620 | return; | 613 | return; |
621 | } */ | 614 | } */ |
622 | 615 | ||
623 | size = strlen (line) * sizeof (char); | 616 | size = strlen(line) * sizeof(char); |
624 | 617 | ||
625 | size2 = GNUNET_DISK_file_write (f, line, size); | 618 | size2 = GNUNET_DISK_file_write(f, line, size); |
626 | if (size != size2) | 619 | if (size != size2) |
627 | { | ||
628 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
629 | "Unable to write to file! (Size: %lu, size2: %lu)\n", | ||
630 | size, | ||
631 | size2); | ||
632 | if (GNUNET_YES != GNUNET_DISK_file_close (f)) | ||
633 | { | 620 | { |
634 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 621 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
635 | "Unable to close file\n"); | 622 | "Unable to write to file! (Size: %lu, size2: %lu)\n", |
623 | size, | ||
624 | size2); | ||
625 | if (GNUNET_YES != GNUNET_DISK_file_close(f)) | ||
626 | { | ||
627 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
628 | "Unable to close file\n"); | ||
629 | } | ||
630 | return; | ||
636 | } | 631 | } |
637 | return; | ||
638 | } | ||
639 | 632 | ||
640 | if (GNUNET_YES != GNUNET_DISK_file_close (f)) | 633 | if (GNUNET_YES != GNUNET_DISK_file_close(f)) |
641 | { | 634 | { |
642 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 635 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
643 | "Unable to close file\n"); | 636 | "Unable to close file\n"); |
644 | } | 637 | } |
645 | } | 638 | } |
646 | 639 | ||
647 | /** | 640 | /** |
648 | * This function is used to facilitate writing important information to disk | 641 | * This function is used to facilitate writing important information to disk |
649 | */ | 642 | */ |
650 | #define tofile(file_name, ...) do {\ | 643 | #define tofile(file_name, ...) do { \ |
651 | char tmp_buf[512];\ | 644 | char tmp_buf[512]; \ |
652 | int size;\ | 645 | int size; \ |
653 | size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\ | 646 | size = GNUNET_snprintf(tmp_buf, sizeof(tmp_buf), __VA_ARGS__); \ |
654 | if (0 > size)\ | 647 | if (0 > size) \ |
655 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\ | 648 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \ |
656 | "Failed to create tmp_buf\n");\ | 649 | "Failed to create tmp_buf\n"); \ |
657 | else\ | 650 | else \ |
658 | tofile_(file_name,tmp_buf);\ | 651 | tofile_ (file_name, tmp_buf); \ |
659 | } while (0); | 652 | } while (0); |
660 | 653 | ||
661 | 654 | ||
@@ -664,33 +657,33 @@ tofile_ (const char *file_name, const char *line) | |||
664 | * Unused | 657 | * Unused |
665 | */ | 658 | */ |
666 | /* static void | 659 | /* static void |
667 | ids_to_file (char *file_name, | 660 | ids_to_file (char *file_name, |
668 | struct GNUNET_PeerIdentity *peer_ids, | 661 | struct GNUNET_PeerIdentity *peer_ids, |
669 | unsigned int num_peer_ids) | 662 | unsigned int num_peer_ids) |
670 | { | 663 | { |
671 | unsigned int i; | 664 | unsigned int i; |
672 | 665 | ||
673 | for (i=0 ; i < num_peer_ids ; i++) | 666 | for (i=0 ; i < num_peer_ids ; i++) |
674 | { | 667 | { |
675 | to_file (file_name, | 668 | to_file (file_name, |
676 | "%u\t%s", | 669 | "%u\t%s", |
677 | i, | 670 | i, |
678 | GNUNET_i2s_full (&peer_ids[i])); | 671 | GNUNET_i2s_full (&peer_ids[i])); |
679 | } | 672 | } |
680 | } */ | 673 | } */ |
681 | 674 | ||
682 | /** | 675 | /** |
683 | * Task run on timeout to collect statistics and potentially shut down. | 676 | * Task run on timeout to collect statistics and potentially shut down. |
684 | */ | 677 | */ |
685 | static void | 678 | static void |
686 | post_test_op (void *cls); | 679 | post_test_op(void *cls); |
687 | 680 | ||
688 | 681 | ||
689 | /** | 682 | /** |
690 | * Test the success of a single test | 683 | * Test the success of a single test |
691 | */ | 684 | */ |
692 | static int | 685 | static int |
693 | evaluate (void) | 686 | evaluate(void) |
694 | { | 687 | { |
695 | unsigned int i; | 688 | unsigned int i; |
696 | int tmp_ok; | 689 | int tmp_ok; |
@@ -698,17 +691,17 @@ evaluate (void) | |||
698 | tmp_ok = 1; | 691 | tmp_ok = 1; |
699 | 692 | ||
700 | for (i = 0; i < num_peers; i++) | 693 | for (i = 0; i < num_peers; i++) |
701 | { | 694 | { |
702 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 695 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
703 | "%u. peer [%s] received %u of %u expected peer_ids: %i\n", | 696 | "%u. peer [%s] received %u of %u expected peer_ids: %i\n", |
704 | i, | 697 | i, |
705 | GNUNET_i2s (rps_peers[i].peer_id), | 698 | GNUNET_i2s(rps_peers[i].peer_id), |
706 | rps_peers[i].num_recv_ids, | 699 | rps_peers[i].num_recv_ids, |
707 | rps_peers[i].num_ids_to_request, | 700 | rps_peers[i].num_ids_to_request, |
708 | (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids)); | 701 | (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids)); |
709 | tmp_ok &= (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids); | 702 | tmp_ok &= (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids); |
710 | } | 703 | } |
711 | return tmp_ok? 0 : 1; | 704 | return tmp_ok ? 0 : 1; |
712 | } | 705 | } |
713 | 706 | ||
714 | 707 | ||
@@ -716,12 +709,12 @@ evaluate (void) | |||
716 | * Creates an oplist entry and adds it to the oplist DLL | 709 | * Creates an oplist entry and adds it to the oplist DLL |
717 | */ | 710 | */ |
718 | static struct OpListEntry * | 711 | static struct OpListEntry * |
719 | make_oplist_entry () | 712 | make_oplist_entry() |
720 | { | 713 | { |
721 | struct OpListEntry *entry; | 714 | struct OpListEntry *entry; |
722 | 715 | ||
723 | entry = GNUNET_new (struct OpListEntry); | 716 | entry = GNUNET_new(struct OpListEntry); |
724 | GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry); | 717 | GNUNET_CONTAINER_DLL_insert_tail(oplist_head, oplist_tail, entry); |
725 | return entry; | 718 | return entry; |
726 | } | 719 | } |
727 | 720 | ||
@@ -735,15 +728,15 @@ make_oplist_entry () | |||
735 | * @return #GNUNET_YES if so | 728 | * @return #GNUNET_YES if so |
736 | * #GNUNET_NO otherwise | 729 | * #GNUNET_NO otherwise |
737 | */ | 730 | */ |
738 | static int check_statistics_collect_completed_single_peer ( | 731 | static int check_statistics_collect_completed_single_peer( |
739 | const struct RPSPeer *rps_peer) | 732 | const struct RPSPeer *rps_peer) |
740 | { | 733 | { |
741 | if (cur_test_run.stat_collect_flags != | 734 | if (cur_test_run.stat_collect_flags != |
742 | (cur_test_run.stat_collect_flags & | 735 | (cur_test_run.stat_collect_flags & |
743 | rps_peer->stat_collected_flags)) | 736 | rps_peer->stat_collected_flags)) |
744 | { | 737 | { |
745 | return GNUNET_NO; | 738 | return GNUNET_NO; |
746 | } | 739 | } |
747 | return GNUNET_YES; | 740 | return GNUNET_YES; |
748 | } | 741 | } |
749 | 742 | ||
@@ -755,22 +748,22 @@ static int check_statistics_collect_completed_single_peer ( | |||
755 | * @return #GNUNET_YES if so | 748 | * @return #GNUNET_YES if so |
756 | * #GNUNET_NO otherwise | 749 | * #GNUNET_NO otherwise |
757 | */ | 750 | */ |
758 | static int check_statistics_collect_completed () | 751 | static int check_statistics_collect_completed() |
759 | { | 752 | { |
760 | uint32_t i; | 753 | uint32_t i; |
761 | 754 | ||
762 | for (i = 0; i < num_peers; i++) | 755 | for (i = 0; i < num_peers; i++) |
763 | { | ||
764 | if (GNUNET_NO == check_statistics_collect_completed_single_peer (&rps_peers[i])) | ||
765 | { | 756 | { |
766 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 757 | if (GNUNET_NO == check_statistics_collect_completed_single_peer(&rps_peers[i])) |
767 | "At least Peer %" PRIu32 " did not yet receive all statistics values\n", | 758 | { |
768 | i); | 759 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
769 | return GNUNET_NO; | 760 | "At least Peer %" PRIu32 " did not yet receive all statistics values\n", |
761 | i); | ||
762 | return GNUNET_NO; | ||
763 | } | ||
770 | } | 764 | } |
771 | } | 765 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
772 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 766 | "All peers received their statistics values\n"); |
773 | "All peers received their statistics values\n"); | ||
774 | return GNUNET_YES; | 767 | return GNUNET_YES; |
775 | } | 768 | } |
776 | 769 | ||
@@ -779,35 +772,36 @@ static int check_statistics_collect_completed () | |||
779 | * Task run on timeout to shut everything down. | 772 | * Task run on timeout to shut everything down. |
780 | */ | 773 | */ |
781 | static void | 774 | static void |
782 | shutdown_op (void *cls) | 775 | shutdown_op(void *cls) |
783 | { | 776 | { |
784 | unsigned int i; | 777 | unsigned int i; |
785 | (void) cls; | ||
786 | 778 | ||
787 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 779 | (void)cls; |
788 | "Shutdown task scheduled, going down.\n"); | 780 | |
781 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
782 | "Shutdown task scheduled, going down.\n"); | ||
789 | in_shutdown = GNUNET_YES; | 783 | in_shutdown = GNUNET_YES; |
790 | if (NULL != post_test_task) | 784 | if (NULL != post_test_task) |
791 | { | 785 | { |
792 | GNUNET_SCHEDULER_cancel (post_test_task); | 786 | GNUNET_SCHEDULER_cancel(post_test_task); |
793 | post_test_op (NULL); | 787 | post_test_op(NULL); |
794 | } | 788 | } |
795 | if (NULL != churn_task) | 789 | if (NULL != churn_task) |
796 | { | ||
797 | GNUNET_SCHEDULER_cancel (churn_task); | ||
798 | churn_task = NULL; | ||
799 | } | ||
800 | for (i = 0; i < num_peers; i++) | ||
801 | { | ||
802 | if (NULL != rps_peers[i].rps_handle) | ||
803 | { | 790 | { |
804 | GNUNET_RPS_disconnect (rps_peers[i].rps_handle); | 791 | GNUNET_SCHEDULER_cancel(churn_task); |
792 | churn_task = NULL; | ||
805 | } | 793 | } |
806 | if (NULL != rps_peers[i].op) | 794 | for (i = 0; i < num_peers; i++) |
807 | { | 795 | { |
808 | GNUNET_TESTBED_operation_done (rps_peers[i].op); | 796 | if (NULL != rps_peers[i].rps_handle) |
797 | { | ||
798 | GNUNET_RPS_disconnect(rps_peers[i].rps_handle); | ||
799 | } | ||
800 | if (NULL != rps_peers[i].op) | ||
801 | { | ||
802 | GNUNET_TESTBED_operation_done(rps_peers[i].op); | ||
803 | } | ||
809 | } | 804 | } |
810 | } | ||
811 | } | 805 | } |
812 | 806 | ||
813 | 807 | ||
@@ -815,39 +809,40 @@ shutdown_op (void *cls) | |||
815 | * Task run on timeout to collect statistics and potentially shut down. | 809 | * Task run on timeout to collect statistics and potentially shut down. |
816 | */ | 810 | */ |
817 | static void | 811 | static void |
818 | post_test_op (void *cls) | 812 | post_test_op(void *cls) |
819 | { | 813 | { |
820 | unsigned int i; | 814 | unsigned int i; |
821 | (void) cls; | 815 | |
816 | (void)cls; | ||
822 | 817 | ||
823 | post_test_task = NULL; | 818 | post_test_task = NULL; |
824 | post_test = GNUNET_YES; | 819 | post_test = GNUNET_YES; |
825 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 820 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
826 | "Post test task scheduled, going down.\n"); | 821 | "Post test task scheduled, going down.\n"); |
827 | if (NULL != churn_task) | 822 | if (NULL != churn_task) |
828 | { | ||
829 | GNUNET_SCHEDULER_cancel (churn_task); | ||
830 | churn_task = NULL; | ||
831 | } | ||
832 | for (i = 0; i < num_peers; i++) | ||
833 | { | ||
834 | if (NULL != cur_test_run.post_test) | ||
835 | { | 823 | { |
836 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i); | 824 | GNUNET_SCHEDULER_cancel(churn_task); |
837 | cur_test_run.post_test (&rps_peers[i]); | 825 | churn_task = NULL; |
838 | } | 826 | } |
839 | if (NULL != rps_peers[i].op) | 827 | for (i = 0; i < num_peers; i++) |
840 | { | 828 | { |
841 | GNUNET_TESTBED_operation_done (rps_peers[i].op); | 829 | if (NULL != cur_test_run.post_test) |
842 | rps_peers[i].op = NULL; | 830 | { |
831 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i); | ||
832 | cur_test_run.post_test(&rps_peers[i]); | ||
833 | } | ||
834 | if (NULL != rps_peers[i].op) | ||
835 | { | ||
836 | GNUNET_TESTBED_operation_done(rps_peers[i].op); | ||
837 | rps_peers[i].op = NULL; | ||
838 | } | ||
843 | } | 839 | } |
844 | } | ||
845 | /* If we do not collect statistics, shut down directly */ | 840 | /* If we do not collect statistics, shut down directly */ |
846 | if (NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics || | 841 | if (NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics || |
847 | GNUNET_YES == check_statistics_collect_completed()) | 842 | GNUNET_YES == check_statistics_collect_completed()) |
848 | { | 843 | { |
849 | GNUNET_SCHEDULER_shutdown (); | 844 | GNUNET_SCHEDULER_shutdown(); |
850 | } | 845 | } |
851 | } | 846 | } |
852 | 847 | ||
853 | 848 | ||
@@ -855,29 +850,29 @@ post_test_op (void *cls) | |||
855 | * Seed peers. | 850 | * Seed peers. |
856 | */ | 851 | */ |
857 | static void | 852 | static void |
858 | seed_peers (void *cls) | 853 | seed_peers(void *cls) |
859 | { | 854 | { |
860 | struct RPSPeer *peer = cls; | 855 | struct RPSPeer *peer = cls; |
861 | unsigned int amount; | 856 | unsigned int amount; |
862 | unsigned int i; | 857 | unsigned int i; |
863 | 858 | ||
864 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | 859 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
865 | { | 860 | { |
866 | return; | 861 | return; |
867 | } | 862 | } |
868 | 863 | ||
869 | GNUNET_assert (NULL != peer->rps_handle); | 864 | GNUNET_assert(NULL != peer->rps_handle); |
870 | 865 | ||
871 | // TODO if malicious don't seed mal peers | 866 | // TODO if malicious don't seed mal peers |
872 | amount = round (.5 * num_peers); | 867 | amount = round(.5 * num_peers); |
873 | 868 | ||
874 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n"); | 869 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n"); |
875 | for (i = 0 ; i < amount ; i++) | 870 | for (i = 0; i < amount; i++) |
876 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n", | 871 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n", |
877 | i, | 872 | i, |
878 | GNUNET_i2s (&rps_peer_ids[i])); | 873 | GNUNET_i2s(&rps_peer_ids[i])); |
879 | 874 | ||
880 | GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids); | 875 | GNUNET_RPS_seed_ids(peer->rps_handle, amount, rps_peer_ids); |
881 | } | 876 | } |
882 | 877 | ||
883 | 878 | ||
@@ -885,7 +880,7 @@ seed_peers (void *cls) | |||
885 | * Seed peers. | 880 | * Seed peers. |
886 | */ | 881 | */ |
887 | static void | 882 | static void |
888 | seed_peers_big (void *cls) | 883 | seed_peers_big(void *cls) |
889 | { | 884 | { |
890 | struct RPSPeer *peer = cls; | 885 | struct RPSPeer *peer = cls; |
891 | unsigned int seed_msg_size; | 886 | unsigned int seed_msg_size; |
@@ -895,71 +890,72 @@ seed_peers_big (void *cls) | |||
895 | 890 | ||
896 | seed_msg_size = 8; /* sizeof (struct GNUNET_RPS_CS_SeedMessage) */ | 891 | seed_msg_size = 8; /* sizeof (struct GNUNET_RPS_CS_SeedMessage) */ |
897 | num_peers_max = (GNUNET_MAX_MESSAGE_SIZE - seed_msg_size) / | 892 | num_peers_max = (GNUNET_MAX_MESSAGE_SIZE - seed_msg_size) / |
898 | sizeof (struct GNUNET_PeerIdentity); | 893 | sizeof(struct GNUNET_PeerIdentity); |
899 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 894 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
900 | "Peers that fit in one seed msg; %u\n", | 895 | "Peers that fit in one seed msg; %u\n", |
901 | num_peers_max); | 896 | num_peers_max); |
902 | amount = num_peers_max + (0.5 * num_peers_max); | 897 | amount = num_peers_max + (0.5 * num_peers_max); |
903 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 898 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
904 | "Seeding many (%u) peers:\n", | 899 | "Seeding many (%u) peers:\n", |
905 | amount); | 900 | amount); |
906 | struct GNUNET_PeerIdentity ids_to_seed[amount]; | 901 | struct GNUNET_PeerIdentity ids_to_seed[amount]; |
907 | for (i = 0; i < amount; i++) | 902 | for (i = 0; i < amount; i++) |
908 | { | 903 | { |
909 | ids_to_seed[i] = *peer->peer_id; | 904 | ids_to_seed[i] = *peer->peer_id; |
910 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n", | 905 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n", |
911 | i, | 906 | i, |
912 | GNUNET_i2s (&ids_to_seed[i])); | 907 | GNUNET_i2s(&ids_to_seed[i])); |
913 | } | 908 | } |
914 | 909 | ||
915 | GNUNET_RPS_seed_ids (peer->rps_handle, amount, ids_to_seed); | 910 | GNUNET_RPS_seed_ids(peer->rps_handle, amount, ids_to_seed); |
916 | } | 911 | } |
917 | 912 | ||
918 | /** | 913 | /** |
919 | * Get the id of peer i. | 914 | * Get the id of peer i. |
920 | */ | 915 | */ |
921 | void | 916 | void |
922 | info_cb (void *cb_cls, | 917 | info_cb(void *cb_cls, |
923 | struct GNUNET_TESTBED_Operation *op, | 918 | struct GNUNET_TESTBED_Operation *op, |
924 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | 919 | const struct GNUNET_TESTBED_PeerInformation *pinfo, |
925 | const char *emsg) | 920 | const char *emsg) |
926 | { | 921 | { |
927 | struct OpListEntry *entry = (struct OpListEntry *) cb_cls; | 922 | struct OpListEntry *entry = (struct OpListEntry *)cb_cls; |
928 | (void) op; | 923 | |
924 | (void)op; | ||
929 | 925 | ||
930 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | 926 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
931 | { | 927 | { |
932 | return; | 928 | return; |
933 | } | 929 | } |
934 | 930 | ||
935 | if (NULL == pinfo || NULL != emsg) | 931 | if (NULL == pinfo || NULL != emsg) |
936 | { | 932 | { |
937 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg); | 933 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg); |
938 | GNUNET_TESTBED_operation_done (entry->op); | 934 | GNUNET_TESTBED_operation_done(entry->op); |
939 | return; | 935 | return; |
940 | } | 936 | } |
941 | 937 | ||
942 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 938 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
943 | "Peer %u is %s\n", | 939 | "Peer %u is %s\n", |
944 | entry->index, | 940 | entry->index, |
945 | GNUNET_i2s (pinfo->result.id)); | 941 | GNUNET_i2s(pinfo->result.id)); |
946 | 942 | ||
947 | rps_peer_ids[entry->index] = *(pinfo->result.id); | 943 | rps_peer_ids[entry->index] = *(pinfo->result.id); |
948 | rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index]; | 944 | rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index]; |
949 | 945 | ||
950 | GNUNET_assert (GNUNET_OK == | 946 | GNUNET_assert(GNUNET_OK == |
951 | GNUNET_CONTAINER_multipeermap_put (peer_map, | 947 | GNUNET_CONTAINER_multipeermap_put(peer_map, |
952 | &rps_peer_ids[entry->index], | 948 | &rps_peer_ids[entry->index], |
953 | &rps_peers[entry->index], | 949 | &rps_peers[entry->index], |
954 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 950 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
955 | tofile ("/tmp/rps/peer_ids", | 951 | tofile("/tmp/rps/peer_ids", |
956 | "%u\t%s\n", | 952 | "%u\t%s\n", |
957 | entry->index, | 953 | entry->index, |
958 | GNUNET_i2s_full (&rps_peer_ids[entry->index])); | 954 | GNUNET_i2s_full(&rps_peer_ids[entry->index])); |
959 | 955 | ||
960 | GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); | 956 | GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, entry); |
961 | GNUNET_TESTBED_operation_done (entry->op); | 957 | GNUNET_TESTBED_operation_done(entry->op); |
962 | GNUNET_free (entry); | 958 | GNUNET_free(entry); |
963 | } | 959 | } |
964 | 960 | ||
965 | 961 | ||
@@ -973,39 +969,39 @@ info_cb (void *cb_cls, | |||
973 | * operation has executed successfully. | 969 | * operation has executed successfully. |
974 | */ | 970 | */ |
975 | static void | 971 | static void |
976 | rps_connect_complete_cb (void *cls, | 972 | rps_connect_complete_cb(void *cls, |
977 | struct GNUNET_TESTBED_Operation *op, | 973 | struct GNUNET_TESTBED_Operation *op, |
978 | void *ca_result, | 974 | void *ca_result, |
979 | const char *emsg) | 975 | const char *emsg) |
980 | { | 976 | { |
981 | struct RPSPeer *rps_peer = cls; | 977 | struct RPSPeer *rps_peer = cls; |
982 | struct GNUNET_RPS_Handle *rps = ca_result; | 978 | struct GNUNET_RPS_Handle *rps = ca_result; |
983 | 979 | ||
984 | GNUNET_assert (NULL != ca_result); | 980 | GNUNET_assert(NULL != ca_result); |
985 | 981 | ||
986 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | 982 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
987 | { | 983 | { |
988 | return; | 984 | return; |
989 | } | 985 | } |
990 | 986 | ||
991 | rps_peer->rps_handle = rps; | 987 | rps_peer->rps_handle = rps; |
992 | rps_peer->online = GNUNET_YES; | 988 | rps_peer->online = GNUNET_YES; |
993 | num_peers_online++; | 989 | num_peers_online++; |
994 | 990 | ||
995 | GNUNET_assert (op == rps_peer->op); | 991 | GNUNET_assert(op == rps_peer->op); |
996 | if (NULL != emsg) | 992 | if (NULL != emsg) |
997 | { | 993 | { |
998 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 994 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
999 | "Failed to connect to RPS service: %s\n", | 995 | "Failed to connect to RPS service: %s\n", |
1000 | emsg); | 996 | emsg); |
1001 | ok = 1; | 997 | ok = 1; |
1002 | GNUNET_SCHEDULER_shutdown (); | 998 | GNUNET_SCHEDULER_shutdown(); |
1003 | return; | 999 | return; |
1004 | } | 1000 | } |
1005 | 1001 | ||
1006 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n"); | 1002 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n"); |
1007 | 1003 | ||
1008 | cur_test_run.main_test (rps_peer); | 1004 | cur_test_run.main_test(rps_peer); |
1009 | } | 1005 | } |
1010 | 1006 | ||
1011 | 1007 | ||
@@ -1020,17 +1016,17 @@ rps_connect_complete_cb (void *cls, | |||
1020 | * @return service handle to return in 'op_result', NULL on error | 1016 | * @return service handle to return in 'op_result', NULL on error |
1021 | */ | 1017 | */ |
1022 | static void * | 1018 | static void * |
1023 | rps_connect_adapter (void *cls, | 1019 | rps_connect_adapter(void *cls, |
1024 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 1020 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
1025 | { | 1021 | { |
1026 | struct GNUNET_RPS_Handle *h; | 1022 | struct GNUNET_RPS_Handle *h; |
1027 | 1023 | ||
1028 | h = GNUNET_RPS_connect (cfg); | 1024 | h = GNUNET_RPS_connect(cfg); |
1029 | GNUNET_assert (NULL != h); | 1025 | GNUNET_assert(NULL != h); |
1030 | 1026 | ||
1031 | if (NULL != cur_test_run.pre_test) | 1027 | if (NULL != cur_test_run.pre_test) |
1032 | cur_test_run.pre_test (cls, h); | 1028 | cur_test_run.pre_test(cls, h); |
1033 | GNUNET_assert (NULL != h); | 1029 | GNUNET_assert(NULL != h); |
1034 | 1030 | ||
1035 | return h; | 1031 | return h; |
1036 | } | 1032 | } |
@@ -1045,12 +1041,12 @@ rps_connect_adapter (void *cls, | |||
1045 | * @return service handle to return in 'op_result', NULL on error | 1041 | * @return service handle to return in 'op_result', NULL on error |
1046 | */ | 1042 | */ |
1047 | static void * | 1043 | static void * |
1048 | stat_connect_adapter (void *cls, | 1044 | stat_connect_adapter(void *cls, |
1049 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 1045 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
1050 | { | 1046 | { |
1051 | struct RPSPeer *peer = cls; | 1047 | struct RPSPeer *peer = cls; |
1052 | 1048 | ||
1053 | peer->stats_h = GNUNET_STATISTICS_create ("rps-profiler", cfg); | 1049 | peer->stats_h = GNUNET_STATISTICS_create("rps-profiler", cfg); |
1054 | return peer->stats_h; | 1050 | return peer->stats_h; |
1055 | } | 1051 | } |
1056 | 1052 | ||
@@ -1061,7 +1057,7 @@ stat_connect_adapter (void *cls, | |||
1061 | * @param op_result service handle returned from the connect adapter | 1057 | * @param op_result service handle returned from the connect adapter |
1062 | */ | 1058 | */ |
1063 | static void | 1059 | static void |
1064 | stat_disconnect_adapter (void *cls, void *op_result) | 1060 | stat_disconnect_adapter(void *cls, void *op_result) |
1065 | { | 1061 | { |
1066 | struct RPSPeer *peer = cls; | 1062 | struct RPSPeer *peer = cls; |
1067 | 1063 | ||
@@ -1071,7 +1067,7 @@ stat_disconnect_adapter (void *cls, void *op_result) | |||
1071 | //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel | 1067 | //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel |
1072 | // (peer->stats_h, "nse", "# peers connected", | 1068 | // (peer->stats_h, "nse", "# peers connected", |
1073 | // stat_iterator, peer)); | 1069 | // stat_iterator, peer)); |
1074 | GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); | 1070 | GNUNET_STATISTICS_destroy(op_result, GNUNET_NO); |
1075 | peer->stats_h = NULL; | 1071 | peer->stats_h = NULL; |
1076 | } | 1072 | } |
1077 | 1073 | ||
@@ -1086,20 +1082,20 @@ stat_disconnect_adapter (void *cls, void *op_result) | |||
1086 | * operation has executed successfully. | 1082 | * operation has executed successfully. |
1087 | */ | 1083 | */ |
1088 | static void | 1084 | static void |
1089 | stat_complete_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | 1085 | stat_complete_cb(void *cls, struct GNUNET_TESTBED_Operation *op, |
1090 | void *ca_result, const char *emsg ) | 1086 | void *ca_result, const char *emsg) |
1091 | { | 1087 | { |
1092 | //struct GNUNET_STATISTICS_Handle *sh = ca_result; | 1088 | //struct GNUNET_STATISTICS_Handle *sh = ca_result; |
1093 | //struct RPSPeer *peer = (struct RPSPeer *) cls; | 1089 | //struct RPSPeer *peer = (struct RPSPeer *) cls; |
1094 | (void) cls; | 1090 | (void)cls; |
1095 | (void) op; | 1091 | (void)op; |
1096 | (void) ca_result; | 1092 | (void)ca_result; |
1097 | 1093 | ||
1098 | if (NULL != emsg) | 1094 | if (NULL != emsg) |
1099 | { | 1095 | { |
1100 | GNUNET_break (0); | 1096 | GNUNET_break(0); |
1101 | return; | 1097 | return; |
1102 | } | 1098 | } |
1103 | //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch | 1099 | //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch |
1104 | // (sh, "core", "# peers connected", | 1100 | // (sh, "core", "# peers connected", |
1105 | // stat_iterator, peer)); | 1101 | // stat_iterator, peer)); |
@@ -1117,36 +1113,36 @@ stat_complete_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
1117 | * @param op_result service handle returned from the connect adapter | 1113 | * @param op_result service handle returned from the connect adapter |
1118 | */ | 1114 | */ |
1119 | static void | 1115 | static void |
1120 | rps_disconnect_adapter (void *cls, | 1116 | rps_disconnect_adapter(void *cls, |
1121 | void *op_result) | 1117 | void *op_result) |
1122 | { | 1118 | { |
1123 | struct RPSPeer *peer = cls; | 1119 | struct RPSPeer *peer = cls; |
1124 | struct GNUNET_RPS_Handle *h = op_result; | 1120 | struct GNUNET_RPS_Handle *h = op_result; |
1125 | 1121 | ||
1126 | if (NULL != peer->rps_srh) | 1122 | if (NULL != peer->rps_srh) |
1127 | { | 1123 | { |
1128 | GNUNET_RPS_stream_cancel (peer->rps_srh); | 1124 | GNUNET_RPS_stream_cancel(peer->rps_srh); |
1129 | peer->rps_srh = NULL; | 1125 | peer->rps_srh = NULL; |
1130 | } | 1126 | } |
1131 | GNUNET_assert (NULL != peer); | 1127 | GNUNET_assert(NULL != peer); |
1132 | GNUNET_RPS_disconnect (h); | 1128 | GNUNET_RPS_disconnect(h); |
1133 | peer->rps_handle = NULL; | 1129 | peer->rps_handle = NULL; |
1134 | } | 1130 | } |
1135 | 1131 | ||
1136 | 1132 | ||
1137 | /*********************************************************************** | 1133 | /*********************************************************************** |
1138 | * Definition of tests | 1134 | * Definition of tests |
1139 | ***********************************************************************/ | 1135 | ***********************************************************************/ |
1140 | 1136 | ||
1141 | // TODO check whether tests can be stopped earlier | 1137 | // TODO check whether tests can be stopped earlier |
1142 | static int | 1138 | static int |
1143 | default_eval_cb (void) | 1139 | default_eval_cb(void) |
1144 | { | 1140 | { |
1145 | return evaluate (); | 1141 | return evaluate(); |
1146 | } | 1142 | } |
1147 | 1143 | ||
1148 | static int | 1144 | static int |
1149 | no_eval (void) | 1145 | no_eval(void) |
1150 | { | 1146 | { |
1151 | return 0; | 1147 | return 0; |
1152 | } | 1148 | } |
@@ -1154,7 +1150,7 @@ no_eval (void) | |||
1154 | /** | 1150 | /** |
1155 | * Initialise given RPSPeer | 1151 | * Initialise given RPSPeer |
1156 | */ | 1152 | */ |
1157 | static void default_init_peer (struct RPSPeer *rps_peer) | 1153 | static void default_init_peer(struct RPSPeer *rps_peer) |
1158 | { | 1154 | { |
1159 | rps_peer->num_ids_to_request = 1; | 1155 | rps_peer->num_ids_to_request = 1; |
1160 | } | 1156 | } |
@@ -1167,49 +1163,49 @@ static void default_init_peer (struct RPSPeer *rps_peer) | |||
1167 | * @param recv_peers the received peers | 1163 | * @param recv_peers the received peers |
1168 | */ | 1164 | */ |
1169 | static void | 1165 | static void |
1170 | default_reply_handle (void *cls, | 1166 | default_reply_handle(void *cls, |
1171 | uint64_t n, | 1167 | uint64_t n, |
1172 | const struct GNUNET_PeerIdentity *recv_peers) | 1168 | const struct GNUNET_PeerIdentity *recv_peers) |
1173 | { | 1169 | { |
1174 | struct RPSPeer *rps_peer; | 1170 | struct RPSPeer *rps_peer; |
1175 | struct PendingReply *pending_rep = (struct PendingReply *) cls; | 1171 | struct PendingReply *pending_rep = (struct PendingReply *)cls; |
1176 | unsigned int i; | 1172 | unsigned int i; |
1177 | 1173 | ||
1178 | rps_peer = pending_rep->rps_peer; | 1174 | rps_peer = pending_rep->rps_peer; |
1179 | GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head, | 1175 | GNUNET_CONTAINER_DLL_remove(rps_peer->pending_rep_head, |
1180 | rps_peer->pending_rep_tail, | 1176 | rps_peer->pending_rep_tail, |
1181 | pending_rep); | 1177 | pending_rep); |
1182 | rps_peer->num_pending_reps--; | 1178 | rps_peer->num_pending_reps--; |
1183 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1179 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1184 | "[%s] got %" PRIu64 " peers:\n", | 1180 | "[%s] got %" PRIu64 " peers:\n", |
1185 | GNUNET_i2s (rps_peer->peer_id), | 1181 | GNUNET_i2s(rps_peer->peer_id), |
1186 | n); | 1182 | n); |
1187 | 1183 | ||
1188 | for (i = 0; i < n; i++) | 1184 | for (i = 0; i < n; i++) |
1189 | { | 1185 | { |
1190 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1186 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1191 | "%u: %s\n", | 1187 | "%u: %s\n", |
1192 | i, | 1188 | i, |
1193 | GNUNET_i2s (&recv_peers[i])); | 1189 | GNUNET_i2s(&recv_peers[i])); |
1194 | 1190 | ||
1195 | rps_peer->num_recv_ids++; | 1191 | rps_peer->num_recv_ids++; |
1196 | } | 1192 | } |
1197 | 1193 | ||
1198 | if (0 == evaluate () && HAVE_QUICK_QUIT == cur_test_run.have_quick_quit) | 1194 | if (0 == evaluate() && HAVE_QUICK_QUIT == cur_test_run.have_quick_quit) |
1199 | { | 1195 | { |
1200 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test succeeded before timeout\n"); | 1196 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test succeeded before timeout\n"); |
1201 | GNUNET_assert (NULL != post_test_task); | 1197 | GNUNET_assert(NULL != post_test_task); |
1202 | GNUNET_SCHEDULER_cancel (post_test_task); | 1198 | GNUNET_SCHEDULER_cancel(post_test_task); |
1203 | post_test_task = GNUNET_SCHEDULER_add_now (&post_test_op, NULL); | 1199 | post_test_task = GNUNET_SCHEDULER_add_now(&post_test_op, NULL); |
1204 | GNUNET_assert (NULL!= post_test_task); | 1200 | GNUNET_assert(NULL != post_test_task); |
1205 | } | 1201 | } |
1206 | } | 1202 | } |
1207 | 1203 | ||
1208 | /** | 1204 | /** |
1209 | * Request random peers. | 1205 | * Request random peers. |
1210 | */ | 1206 | */ |
1211 | static void | 1207 | static void |
1212 | request_peers (void *cls) | 1208 | request_peers(void *cls) |
1213 | { | 1209 | { |
1214 | struct PendingRequest *pending_req = cls; | 1210 | struct PendingRequest *pending_req = cls; |
1215 | struct RPSPeer *rps_peer; | 1211 | struct RPSPeer *rps_peer; |
@@ -1218,62 +1214,62 @@ request_peers (void *cls) | |||
1218 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | 1214 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1219 | return; | 1215 | return; |
1220 | rps_peer = pending_req->rps_peer; | 1216 | rps_peer = pending_req->rps_peer; |
1221 | GNUNET_assert (1 <= rps_peer->num_pending_reqs); | 1217 | GNUNET_assert(1 <= rps_peer->num_pending_reqs); |
1222 | GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head, | 1218 | GNUNET_CONTAINER_DLL_remove(rps_peer->pending_req_head, |
1223 | rps_peer->pending_req_tail, | 1219 | rps_peer->pending_req_tail, |
1224 | pending_req); | 1220 | pending_req); |
1225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1221 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1226 | "Requesting one peer\n"); | 1222 | "Requesting one peer\n"); |
1227 | pending_rep = GNUNET_new (struct PendingReply); | 1223 | pending_rep = GNUNET_new(struct PendingReply); |
1228 | pending_rep->rps_peer = rps_peer; | 1224 | pending_rep->rps_peer = rps_peer; |
1229 | pending_rep->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle, | 1225 | pending_rep->req_handle = GNUNET_RPS_request_peers(rps_peer->rps_handle, |
1230 | 1, | 1226 | 1, |
1231 | cur_test_run.reply_handle, | 1227 | cur_test_run.reply_handle, |
1232 | pending_rep); | 1228 | pending_rep); |
1233 | GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_rep_head, | 1229 | GNUNET_CONTAINER_DLL_insert_tail(rps_peer->pending_rep_head, |
1234 | rps_peer->pending_rep_tail, | 1230 | rps_peer->pending_rep_tail, |
1235 | pending_rep); | 1231 | pending_rep); |
1236 | rps_peer->num_pending_reps++; | 1232 | rps_peer->num_pending_reps++; |
1237 | rps_peer->num_pending_reqs--; | 1233 | rps_peer->num_pending_reqs--; |
1238 | } | 1234 | } |
1239 | 1235 | ||
1240 | static void | 1236 | static void |
1241 | cancel_pending_req (struct PendingRequest *pending_req) | 1237 | cancel_pending_req(struct PendingRequest *pending_req) |
1242 | { | 1238 | { |
1243 | struct RPSPeer *rps_peer; | 1239 | struct RPSPeer *rps_peer; |
1244 | 1240 | ||
1245 | rps_peer = pending_req->rps_peer; | 1241 | rps_peer = pending_req->rps_peer; |
1246 | GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head, | 1242 | GNUNET_CONTAINER_DLL_remove(rps_peer->pending_req_head, |
1247 | rps_peer->pending_req_tail, | 1243 | rps_peer->pending_req_tail, |
1248 | pending_req); | 1244 | pending_req); |
1249 | rps_peer->num_pending_reqs--; | 1245 | rps_peer->num_pending_reqs--; |
1250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1246 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1251 | "Cancelling pending request\n"); | 1247 | "Cancelling pending request\n"); |
1252 | GNUNET_SCHEDULER_cancel (pending_req->request_task); | 1248 | GNUNET_SCHEDULER_cancel(pending_req->request_task); |
1253 | GNUNET_free (pending_req); | 1249 | GNUNET_free(pending_req); |
1254 | } | 1250 | } |
1255 | 1251 | ||
1256 | static void | 1252 | static void |
1257 | cancel_request (struct PendingReply *pending_rep) | 1253 | cancel_request(struct PendingReply *pending_rep) |
1258 | { | 1254 | { |
1259 | struct RPSPeer *rps_peer; | 1255 | struct RPSPeer *rps_peer; |
1260 | 1256 | ||
1261 | rps_peer = pending_rep->rps_peer; | 1257 | rps_peer = pending_rep->rps_peer; |
1262 | GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head, | 1258 | GNUNET_CONTAINER_DLL_remove(rps_peer->pending_rep_head, |
1263 | rps_peer->pending_rep_tail, | 1259 | rps_peer->pending_rep_tail, |
1264 | pending_rep); | 1260 | pending_rep); |
1265 | rps_peer->num_pending_reps--; | 1261 | rps_peer->num_pending_reps--; |
1266 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1262 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1267 | "Cancelling request\n"); | 1263 | "Cancelling request\n"); |
1268 | GNUNET_RPS_request_cancel (pending_rep->req_handle); | 1264 | GNUNET_RPS_request_cancel(pending_rep->req_handle); |
1269 | GNUNET_free (pending_rep); | 1265 | GNUNET_free(pending_rep); |
1270 | } | 1266 | } |
1271 | 1267 | ||
1272 | /** | 1268 | /** |
1273 | * Cancel a request. | 1269 | * Cancel a request. |
1274 | */ | 1270 | */ |
1275 | static void | 1271 | static void |
1276 | cancel_request_cb (void *cls) | 1272 | cancel_request_cb(void *cls) |
1277 | { | 1273 | { |
1278 | struct RPSPeer *rps_peer = cls; | 1274 | struct RPSPeer *rps_peer = cls; |
1279 | struct PendingReply *pending_rep; | 1275 | struct PendingReply *pending_rep; |
@@ -1281,8 +1277,8 @@ cancel_request_cb (void *cls) | |||
1281 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | 1277 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1282 | return; | 1278 | return; |
1283 | pending_rep = rps_peer->pending_rep_head; | 1279 | pending_rep = rps_peer->pending_rep_head; |
1284 | GNUNET_assert (1 <= rps_peer->num_pending_reps); | 1280 | GNUNET_assert(1 <= rps_peer->num_pending_reps); |
1285 | cancel_request (pending_rep); | 1281 | cancel_request(pending_rep); |
1286 | } | 1282 | } |
1287 | 1283 | ||
1288 | 1284 | ||
@@ -1291,57 +1287,57 @@ cancel_request_cb (void *cls) | |||
1291 | * issued, nor replied | 1287 | * issued, nor replied |
1292 | */ | 1288 | */ |
1293 | void | 1289 | void |
1294 | schedule_missing_requests (struct RPSPeer *rps_peer) | 1290 | schedule_missing_requests(struct RPSPeer *rps_peer) |
1295 | { | 1291 | { |
1296 | unsigned int i; | 1292 | unsigned int i; |
1297 | struct PendingRequest *pending_req; | 1293 | struct PendingRequest *pending_req; |
1298 | 1294 | ||
1299 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1295 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1300 | "Scheduling %u - %u missing requests\n", | 1296 | "Scheduling %u - %u missing requests\n", |
1301 | rps_peer->num_ids_to_request, | 1297 | rps_peer->num_ids_to_request, |
1302 | rps_peer->num_pending_reqs + rps_peer->num_pending_reps); | 1298 | rps_peer->num_pending_reqs + rps_peer->num_pending_reps); |
1303 | GNUNET_assert (rps_peer->num_pending_reqs + rps_peer->num_pending_reps <= | 1299 | GNUNET_assert(rps_peer->num_pending_reqs + rps_peer->num_pending_reps <= |
1304 | rps_peer->num_ids_to_request); | 1300 | rps_peer->num_ids_to_request); |
1305 | for (i = rps_peer->num_pending_reqs + rps_peer->num_pending_reps; | 1301 | for (i = rps_peer->num_pending_reqs + rps_peer->num_pending_reps; |
1306 | i < rps_peer->num_ids_to_request; i++) | 1302 | i < rps_peer->num_ids_to_request; i++) |
1307 | { | 1303 | { |
1308 | pending_req = GNUNET_new (struct PendingRequest); | 1304 | pending_req = GNUNET_new(struct PendingRequest); |
1309 | pending_req->rps_peer = rps_peer; | 1305 | pending_req->rps_peer = rps_peer; |
1310 | pending_req->request_task = GNUNET_SCHEDULER_add_delayed ( | 1306 | pending_req->request_task = GNUNET_SCHEDULER_add_delayed( |
1311 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 1307 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
1312 | cur_test_run.request_interval * i), | 1308 | cur_test_run.request_interval * i), |
1313 | request_peers, | 1309 | request_peers, |
1314 | pending_req); | 1310 | pending_req); |
1315 | GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_req_head, | 1311 | GNUNET_CONTAINER_DLL_insert_tail(rps_peer->pending_req_head, |
1316 | rps_peer->pending_req_tail, | 1312 | rps_peer->pending_req_tail, |
1317 | pending_req); | 1313 | pending_req); |
1318 | rps_peer->num_pending_reqs++; | 1314 | rps_peer->num_pending_reqs++; |
1319 | } | 1315 | } |
1320 | } | 1316 | } |
1321 | 1317 | ||
1322 | void | 1318 | void |
1323 | cancel_pending_req_rep (struct RPSPeer *rps_peer) | 1319 | cancel_pending_req_rep(struct RPSPeer *rps_peer) |
1324 | { | 1320 | { |
1325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1321 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1326 | "Cancelling all (pending) requests.\n"); | 1322 | "Cancelling all (pending) requests.\n"); |
1327 | while (NULL != rps_peer->pending_req_head) | 1323 | while (NULL != rps_peer->pending_req_head) |
1328 | cancel_pending_req (rps_peer->pending_req_head); | 1324 | cancel_pending_req(rps_peer->pending_req_head); |
1329 | GNUNET_assert (0 == rps_peer->num_pending_reqs); | 1325 | GNUNET_assert(0 == rps_peer->num_pending_reqs); |
1330 | while (NULL != rps_peer->pending_rep_head) | 1326 | while (NULL != rps_peer->pending_rep_head) |
1331 | cancel_request (rps_peer->pending_rep_head); | 1327 | cancel_request(rps_peer->pending_rep_head); |
1332 | GNUNET_assert (0 == rps_peer->num_pending_reps); | 1328 | GNUNET_assert(0 == rps_peer->num_pending_reps); |
1333 | } | 1329 | } |
1334 | 1330 | ||
1335 | /*********************************** | 1331 | /*********************************** |
1336 | * MALICIOUS | 1332 | * MALICIOUS |
1337 | ***********************************/ | 1333 | ***********************************/ |
1338 | 1334 | ||
1339 | /** | 1335 | /** |
1340 | * Initialise only non-mal RPSPeers | 1336 | * Initialise only non-mal RPSPeers |
1341 | */ | 1337 | */ |
1342 | static void mal_init_peer (struct RPSPeer *rps_peer) | 1338 | static void mal_init_peer(struct RPSPeer *rps_peer) |
1343 | { | 1339 | { |
1344 | if (rps_peer->index >= round (portion * num_peers)) | 1340 | if (rps_peer->index >= round(portion * num_peers)) |
1345 | rps_peer->num_ids_to_request = 1; | 1341 | rps_peer->num_ids_to_request = 1; |
1346 | } | 1342 | } |
1347 | 1343 | ||
@@ -1355,169 +1351,169 @@ static void mal_init_peer (struct RPSPeer *rps_peer) | |||
1355 | * @param h the handle to the service | 1351 | * @param h the handle to the service |
1356 | */ | 1352 | */ |
1357 | static void | 1353 | static void |
1358 | mal_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) | 1354 | mal_pre(struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) |
1359 | { | 1355 | { |
1360 | #if ENABLE_MALICIOUS | 1356 | #if ENABLE_MALICIOUS |
1361 | uint32_t num_mal_peers; | 1357 | uint32_t num_mal_peers; |
1362 | 1358 | ||
1363 | GNUNET_assert ( (1 >= portion) && | 1359 | GNUNET_assert((1 >= portion) && |
1364 | (0 < portion) ); | 1360 | (0 < portion)); |
1365 | num_mal_peers = round (portion * num_peers); | 1361 | num_mal_peers = round(portion * num_peers); |
1366 | 1362 | ||
1367 | if (rps_peer->index < num_mal_peers) | 1363 | if (rps_peer->index < num_mal_peers) |
1368 | { | 1364 | { |
1369 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1365 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1370 | "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n", | 1366 | "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n", |
1371 | rps_peer->index, | 1367 | rps_peer->index, |
1372 | GNUNET_i2s (rps_peer->peer_id), | 1368 | GNUNET_i2s(rps_peer->peer_id), |
1373 | num_mal_peers); | 1369 | num_mal_peers); |
1374 | 1370 | ||
1375 | GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers, | 1371 | GNUNET_RPS_act_malicious(h, mal_type, num_mal_peers, |
1376 | rps_peer_ids, target_peer); | 1372 | rps_peer_ids, target_peer); |
1377 | } | 1373 | } |
1378 | #endif /* ENABLE_MALICIOUS */ | 1374 | #endif /* ENABLE_MALICIOUS */ |
1379 | } | 1375 | } |
1380 | 1376 | ||
1381 | static void | 1377 | static void |
1382 | mal_cb (struct RPSPeer *rps_peer) | 1378 | mal_cb(struct RPSPeer *rps_peer) |
1383 | { | 1379 | { |
1384 | uint32_t num_mal_peers; | 1380 | uint32_t num_mal_peers; |
1385 | 1381 | ||
1386 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | 1382 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1387 | { | 1383 | { |
1388 | return; | 1384 | return; |
1389 | } | 1385 | } |
1390 | 1386 | ||
1391 | #if ENABLE_MALICIOUS | 1387 | #if ENABLE_MALICIOUS |
1392 | GNUNET_assert ( (1 >= portion) && | 1388 | GNUNET_assert((1 >= portion) && |
1393 | (0 < portion) ); | 1389 | (0 < portion)); |
1394 | num_mal_peers = round (portion * num_peers); | 1390 | num_mal_peers = round(portion * num_peers); |
1395 | 1391 | ||
1396 | if (rps_peer->index >= num_mal_peers) | 1392 | if (rps_peer->index >= num_mal_peers) |
1397 | { /* It's useless to ask a malicious peer about a random sample - | 1393 | { /* It's useless to ask a malicious peer about a random sample - |
1398 | it's not sampling */ | 1394 | it's not sampling */ |
1399 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), | 1395 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), |
1400 | seed_peers, rps_peer); | 1396 | seed_peers, rps_peer); |
1401 | schedule_missing_requests (rps_peer); | 1397 | schedule_missing_requests(rps_peer); |
1402 | } | 1398 | } |
1403 | #endif /* ENABLE_MALICIOUS */ | 1399 | #endif /* ENABLE_MALICIOUS */ |
1404 | } | 1400 | } |
1405 | 1401 | ||
1406 | 1402 | ||
1407 | /*********************************** | 1403 | /*********************************** |
1408 | * SINGLE_REQUEST | 1404 | * SINGLE_REQUEST |
1409 | ***********************************/ | 1405 | ***********************************/ |
1410 | static void | 1406 | static void |
1411 | single_req_cb (struct RPSPeer *rps_peer) | 1407 | single_req_cb(struct RPSPeer *rps_peer) |
1412 | { | 1408 | { |
1413 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | 1409 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1414 | { | 1410 | { |
1415 | return; | 1411 | return; |
1416 | } | 1412 | } |
1417 | 1413 | ||
1418 | schedule_missing_requests (rps_peer); | 1414 | schedule_missing_requests(rps_peer); |
1419 | } | 1415 | } |
1420 | 1416 | ||
1421 | /*********************************** | 1417 | /*********************************** |
1422 | * DELAYED_REQUESTS | 1418 | * DELAYED_REQUESTS |
1423 | ***********************************/ | 1419 | ***********************************/ |
1424 | static void | 1420 | static void |
1425 | delay_req_cb (struct RPSPeer *rps_peer) | 1421 | delay_req_cb(struct RPSPeer *rps_peer) |
1426 | { | 1422 | { |
1427 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | 1423 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1428 | { | 1424 | { |
1429 | return; | 1425 | return; |
1430 | } | 1426 | } |
1431 | 1427 | ||
1432 | schedule_missing_requests (rps_peer); | 1428 | schedule_missing_requests(rps_peer); |
1433 | } | 1429 | } |
1434 | 1430 | ||
1435 | /*********************************** | 1431 | /*********************************** |
1436 | * SEED | 1432 | * SEED |
1437 | ***********************************/ | 1433 | ***********************************/ |
1438 | static void | 1434 | static void |
1439 | seed_cb (struct RPSPeer *rps_peer) | 1435 | seed_cb(struct RPSPeer *rps_peer) |
1440 | { | 1436 | { |
1441 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | 1437 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1442 | { | 1438 | { |
1443 | return; | 1439 | return; |
1444 | } | 1440 | } |
1445 | 1441 | ||
1446 | GNUNET_SCHEDULER_add_delayed ( | 1442 | GNUNET_SCHEDULER_add_delayed( |
1447 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), | 1443 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), |
1448 | seed_peers, rps_peer); | 1444 | seed_peers, rps_peer); |
1449 | } | 1445 | } |
1450 | 1446 | ||
1451 | /*********************************** | 1447 | /*********************************** |
1452 | * SEED_BIG | 1448 | * SEED_BIG |
1453 | ***********************************/ | 1449 | ***********************************/ |
1454 | static void | 1450 | static void |
1455 | seed_big_cb (struct RPSPeer *rps_peer) | 1451 | seed_big_cb(struct RPSPeer *rps_peer) |
1456 | { | 1452 | { |
1457 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | 1453 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1458 | { | 1454 | { |
1459 | return; | 1455 | return; |
1460 | } | 1456 | } |
1461 | 1457 | ||
1462 | // TODO test seeding > GNUNET_MAX_MESSAGE_SIZE peers | 1458 | // TODO test seeding > GNUNET_MAX_MESSAGE_SIZE peers |
1463 | GNUNET_SCHEDULER_add_delayed ( | 1459 | GNUNET_SCHEDULER_add_delayed( |
1464 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), | 1460 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), |
1465 | seed_peers_big, rps_peer); | 1461 | seed_peers_big, rps_peer); |
1466 | } | 1462 | } |
1467 | 1463 | ||
1468 | /*********************************** | 1464 | /*********************************** |
1469 | * SINGLE_PEER_SEED | 1465 | * SINGLE_PEER_SEED |
1470 | ***********************************/ | 1466 | ***********************************/ |
1471 | static void | 1467 | static void |
1472 | single_peer_seed_cb (struct RPSPeer *rps_peer) | 1468 | single_peer_seed_cb(struct RPSPeer *rps_peer) |
1473 | { | 1469 | { |
1474 | (void) rps_peer; | 1470 | (void)rps_peer; |
1475 | // TODO | 1471 | // TODO |
1476 | } | 1472 | } |
1477 | 1473 | ||
1478 | /*********************************** | 1474 | /*********************************** |
1479 | * SEED_REQUEST | 1475 | * SEED_REQUEST |
1480 | ***********************************/ | 1476 | ***********************************/ |
1481 | static void | 1477 | static void |
1482 | seed_req_cb (struct RPSPeer *rps_peer) | 1478 | seed_req_cb(struct RPSPeer *rps_peer) |
1483 | { | 1479 | { |
1484 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | 1480 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1485 | { | 1481 | { |
1486 | return; | 1482 | return; |
1487 | } | 1483 | } |
1488 | 1484 | ||
1489 | GNUNET_SCHEDULER_add_delayed ( | 1485 | GNUNET_SCHEDULER_add_delayed( |
1490 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), | 1486 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), |
1491 | seed_peers, rps_peer); | 1487 | seed_peers, rps_peer); |
1492 | schedule_missing_requests (rps_peer); | 1488 | schedule_missing_requests(rps_peer); |
1493 | } | 1489 | } |
1494 | 1490 | ||
1495 | //TODO start big mal | 1491 | //TODO start big mal |
1496 | 1492 | ||
1497 | /*********************************** | 1493 | /*********************************** |
1498 | * REQUEST_CANCEL | 1494 | * REQUEST_CANCEL |
1499 | ***********************************/ | 1495 | ***********************************/ |
1500 | static void | 1496 | static void |
1501 | req_cancel_cb (struct RPSPeer *rps_peer) | 1497 | req_cancel_cb(struct RPSPeer *rps_peer) |
1502 | { | 1498 | { |
1503 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | 1499 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1504 | { | 1500 | { |
1505 | return; | 1501 | return; |
1506 | } | 1502 | } |
1507 | 1503 | ||
1508 | schedule_missing_requests (rps_peer); | 1504 | schedule_missing_requests(rps_peer); |
1509 | GNUNET_SCHEDULER_add_delayed ( | 1505 | GNUNET_SCHEDULER_add_delayed( |
1510 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 1506 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
1511 | (cur_test_run.request_interval + 1)), | 1507 | (cur_test_run.request_interval + 1)), |
1512 | cancel_request_cb, rps_peer); | 1508 | cancel_request_cb, rps_peer); |
1513 | } | 1509 | } |
1514 | 1510 | ||
1515 | /*********************************** | 1511 | /*********************************** |
1516 | * CHURN | 1512 | * CHURN |
1517 | ***********************************/ | 1513 | ***********************************/ |
1518 | 1514 | ||
1519 | static void | 1515 | static void |
1520 | churn (void *cls); | 1516 | churn(void *cls); |
1521 | 1517 | ||
1522 | /** | 1518 | /** |
1523 | * @brief Starts churn | 1519 | * @brief Starts churn |
@@ -1531,89 +1527,95 @@ churn (void *cls); | |||
1531 | * @param rps_peer The peer it's called for | 1527 | * @param rps_peer The peer it's called for |
1532 | */ | 1528 | */ |
1533 | static void | 1529 | static void |
1534 | churn_test_cb (struct RPSPeer *rps_peer) | 1530 | churn_test_cb(struct RPSPeer *rps_peer) |
1535 | { | 1531 | { |
1536 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | 1532 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1537 | { | 1533 | { |
1538 | return; | 1534 | return; |
1539 | } | 1535 | } |
1540 | 1536 | ||
1541 | /* Start churn */ | 1537 | /* Start churn */ |
1542 | if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) | 1538 | if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) |
1543 | { | 1539 | { |
1544 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1540 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1545 | "Starting churn task\n"); | 1541 | "Starting churn task\n"); |
1546 | churn_task = GNUNET_SCHEDULER_add_delayed ( | 1542 | churn_task = GNUNET_SCHEDULER_add_delayed( |
1547 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), | 1543 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), |
1548 | churn, | 1544 | churn, |
1549 | NULL); | 1545 | NULL); |
1550 | } else { | 1546 | } |
1551 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1547 | else |
1552 | "Not starting churn task\n"); | 1548 | { |
1553 | } | 1549 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1550 | "Not starting churn task\n"); | ||
1551 | } | ||
1554 | 1552 | ||
1555 | schedule_missing_requests (rps_peer); | 1553 | schedule_missing_requests(rps_peer); |
1556 | } | 1554 | } |
1557 | 1555 | ||
1558 | /*********************************** | 1556 | /*********************************** |
1559 | * SUB | 1557 | * SUB |
1560 | ***********************************/ | 1558 | ***********************************/ |
1561 | 1559 | ||
1562 | static void | 1560 | static void |
1563 | got_stream_peer_cb (void *cls, | 1561 | got_stream_peer_cb(void *cls, |
1564 | uint64_t num_peers, | 1562 | uint64_t num_peers, |
1565 | const struct GNUNET_PeerIdentity *peers) | 1563 | const struct GNUNET_PeerIdentity *peers) |
1566 | { | 1564 | { |
1567 | const struct RPSPeer *rps_peer = cls; | 1565 | const struct RPSPeer *rps_peer = cls; |
1568 | 1566 | ||
1569 | for (uint64_t i = 0; i < num_peers; i++) | 1567 | for (uint64_t i = 0; i < num_peers; i++) |
1570 | { | ||
1571 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1572 | "Peer %" PRIu32 " received [%s] from stream.\n", | ||
1573 | rps_peer->index, | ||
1574 | GNUNET_i2s (&peers[i])); | ||
1575 | if (0 != rps_peer->index && | ||
1576 | 0 == memcmp (&peers[i], | ||
1577 | &rps_peers[0].peer_id, | ||
1578 | sizeof (struct GNUNET_PeerIdentity))) | ||
1579 | { | ||
1580 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Received a peer id outside sub\n"); | ||
1581 | ok = 1; | ||
1582 | } | ||
1583 | else if (0 == rps_peer->index && | ||
1584 | 0 != memcmp (&peers[i], | ||
1585 | &rps_peers[0].peer_id, | ||
1586 | sizeof (struct GNUNET_PeerIdentity))) | ||
1587 | { | 1568 | { |
1588 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Received a peer id outside sub (lonely)\n"); | 1569 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1589 | ok = 1; | 1570 | "Peer %" PRIu32 " received [%s] from stream.\n", |
1571 | rps_peer->index, | ||
1572 | GNUNET_i2s(&peers[i])); | ||
1573 | if (0 != rps_peer->index && | ||
1574 | 0 == memcmp(&peers[i], | ||
1575 | &rps_peers[0].peer_id, | ||
1576 | sizeof(struct GNUNET_PeerIdentity))) | ||
1577 | { | ||
1578 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Received a peer id outside sub\n"); | ||
1579 | ok = 1; | ||
1580 | } | ||
1581 | else if (0 == rps_peer->index && | ||
1582 | 0 != memcmp(&peers[i], | ||
1583 | &rps_peers[0].peer_id, | ||
1584 | sizeof(struct GNUNET_PeerIdentity))) | ||
1585 | { | ||
1586 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Received a peer id outside sub (lonely)\n"); | ||
1587 | ok = 1; | ||
1588 | } | ||
1590 | } | 1589 | } |
1591 | } | ||
1592 | } | 1590 | } |
1593 | 1591 | ||
1594 | 1592 | ||
1595 | static void | 1593 | static void |
1596 | sub_post (struct RPSPeer *rps_peer) | 1594 | sub_post(struct RPSPeer *rps_peer) |
1597 | { | 1595 | { |
1598 | if (0 != rps_peer->index) GNUNET_RPS_sub_stop (rps_peer->rps_handle, "test"); | 1596 | if (0 != rps_peer->index) |
1599 | else GNUNET_RPS_sub_stop (rps_peer->rps_handle, "lonely"); | 1597 | GNUNET_RPS_sub_stop(rps_peer->rps_handle, "test"); |
1598 | else | ||
1599 | GNUNET_RPS_sub_stop(rps_peer->rps_handle, "lonely"); | ||
1600 | } | 1600 | } |
1601 | 1601 | ||
1602 | 1602 | ||
1603 | static void | 1603 | static void |
1604 | sub_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) | 1604 | sub_pre(struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) |
1605 | { | 1605 | { |
1606 | (void) rps_peer; | 1606 | (void)rps_peer; |
1607 | 1607 | ||
1608 | if (0 != rps_peer->index) GNUNET_RPS_sub_start (h, "test"); | 1608 | if (0 != rps_peer->index) |
1609 | else GNUNET_RPS_sub_start (h, "lonely"); /* have a group of one */ | 1609 | GNUNET_RPS_sub_start(h, "test"); |
1610 | rps_peer->rps_srh = GNUNET_RPS_stream_request (h, | 1610 | else |
1611 | &got_stream_peer_cb, | 1611 | GNUNET_RPS_sub_start(h, "lonely"); /* have a group of one */ |
1612 | rps_peer); | 1612 | rps_peer->rps_srh = GNUNET_RPS_stream_request(h, |
1613 | &got_stream_peer_cb, | ||
1614 | rps_peer); | ||
1613 | } | 1615 | } |
1614 | 1616 | ||
1615 | /*********************************** | 1617 | /*********************************** |
1616 | * PROFILER | 1618 | * PROFILER |
1617 | ***********************************/ | 1619 | ***********************************/ |
1618 | 1620 | ||
1619 | /** | 1621 | /** |
@@ -1624,81 +1626,81 @@ sub_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) | |||
1624 | * @param emsg NULL on success; otherwise an error description | 1626 | * @param emsg NULL on success; otherwise an error description |
1625 | */ | 1627 | */ |
1626 | static void | 1628 | static void |
1627 | churn_cb (void *cls, | 1629 | churn_cb(void *cls, |
1628 | struct GNUNET_TESTBED_Operation *op, | 1630 | struct GNUNET_TESTBED_Operation *op, |
1629 | const char *emsg) | 1631 | const char *emsg) |
1630 | { | 1632 | { |
1631 | (void) op; | 1633 | (void)op; |
1632 | // FIXME | 1634 | // FIXME |
1633 | struct OpListEntry *entry = cls; | 1635 | struct OpListEntry *entry = cls; |
1634 | 1636 | ||
1635 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | 1637 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1636 | { | 1638 | { |
1637 | return; | 1639 | return; |
1638 | } | 1640 | } |
1639 | 1641 | ||
1640 | GNUNET_TESTBED_operation_done (entry->op); | 1642 | GNUNET_TESTBED_operation_done(entry->op); |
1641 | if (NULL != emsg) | 1643 | if (NULL != emsg) |
1642 | { | 1644 | { |
1643 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n"); | 1645 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n"); |
1644 | GNUNET_SCHEDULER_shutdown (); | 1646 | GNUNET_SCHEDULER_shutdown(); |
1645 | return; | 1647 | return; |
1646 | } | 1648 | } |
1647 | GNUNET_assert (0 != entry->delta); | 1649 | GNUNET_assert(0 != entry->delta); |
1648 | 1650 | ||
1649 | num_peers_online += entry->delta; | 1651 | num_peers_online += entry->delta; |
1650 | 1652 | ||
1651 | if (PEER_GO_OFFLINE == entry->delta) | 1653 | if (PEER_GO_OFFLINE == entry->delta) |
1652 | { /* Peer hopefully just went offline */ | 1654 | { /* Peer hopefully just went offline */ |
1653 | if (GNUNET_YES != rps_peers[entry->index].online) | 1655 | if (GNUNET_YES != rps_peers[entry->index].online) |
1654 | { | 1656 | { |
1655 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1657 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1656 | "peer %s was expected to go offline but is still marked as online\n", | 1658 | "peer %s was expected to go offline but is still marked as online\n", |
1657 | GNUNET_i2s (rps_peers[entry->index].peer_id)); | 1659 | GNUNET_i2s(rps_peers[entry->index].peer_id)); |
1658 | GNUNET_break (0); | 1660 | GNUNET_break(0); |
1659 | } | 1661 | } |
1660 | else | 1662 | else |
1661 | { | 1663 | { |
1662 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1664 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1663 | "peer %s probably went offline as expected\n", | 1665 | "peer %s probably went offline as expected\n", |
1664 | GNUNET_i2s (rps_peers[entry->index].peer_id)); | 1666 | GNUNET_i2s(rps_peers[entry->index].peer_id)); |
1667 | } | ||
1668 | rps_peers[entry->index].online = GNUNET_NO; | ||
1665 | } | 1669 | } |
1666 | rps_peers[entry->index].online = GNUNET_NO; | ||
1667 | } | ||
1668 | 1670 | ||
1669 | else if (PEER_GO_ONLINE < entry->delta) | 1671 | else if (PEER_GO_ONLINE < entry->delta) |
1670 | { /* Peer hopefully just went online */ | 1672 | { /* Peer hopefully just went online */ |
1671 | if (GNUNET_NO != rps_peers[entry->index].online) | 1673 | if (GNUNET_NO != rps_peers[entry->index].online) |
1672 | { | 1674 | { |
1673 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1675 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1674 | "peer %s was expected to go online but is still marked as offline\n", | 1676 | "peer %s was expected to go online but is still marked as offline\n", |
1675 | GNUNET_i2s (rps_peers[entry->index].peer_id)); | 1677 | GNUNET_i2s(rps_peers[entry->index].peer_id)); |
1676 | GNUNET_break (0); | 1678 | GNUNET_break(0); |
1677 | } | 1679 | } |
1678 | else | 1680 | else |
1679 | { | 1681 | { |
1680 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1682 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1681 | "peer %s probably went online as expected\n", | 1683 | "peer %s probably went online as expected\n", |
1682 | GNUNET_i2s (rps_peers[entry->index].peer_id)); | 1684 | GNUNET_i2s(rps_peers[entry->index].peer_id)); |
1683 | if (NULL != cur_test_run.pre_test) | 1685 | if (NULL != cur_test_run.pre_test) |
1684 | { | 1686 | { |
1685 | cur_test_run.pre_test (&rps_peers[entry->index], | 1687 | cur_test_run.pre_test(&rps_peers[entry->index], |
1686 | rps_peers[entry->index].rps_handle); | 1688 | rps_peers[entry->index].rps_handle); |
1687 | schedule_missing_requests (&rps_peers[entry->index]); | 1689 | schedule_missing_requests(&rps_peers[entry->index]); |
1688 | } | 1690 | } |
1689 | } | 1691 | } |
1690 | rps_peers[entry->index].online = GNUNET_YES; | 1692 | rps_peers[entry->index].online = GNUNET_YES; |
1691 | } | 1693 | } |
1692 | else | 1694 | else |
1693 | { | 1695 | { |
1694 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1696 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1695 | "Invalid value for delta: %i\n", entry->delta); | 1697 | "Invalid value for delta: %i\n", entry->delta); |
1696 | GNUNET_break (0); | 1698 | GNUNET_break(0); |
1697 | } | 1699 | } |
1698 | 1700 | ||
1699 | GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); | 1701 | GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, entry); |
1700 | rps_peers[entry->index].entry_op_manage = NULL; | 1702 | rps_peers[entry->index].entry_op_manage = NULL; |
1701 | GNUNET_free (entry); | 1703 | GNUNET_free(entry); |
1702 | //if (num_peers_in_round[current_round] == peers_running) | 1704 | //if (num_peers_in_round[current_round] == peers_running) |
1703 | // run_round (); | 1705 | // run_round (); |
1704 | } | 1706 | } |
@@ -1712,54 +1714,54 @@ churn_cb (void *cls, | |||
1712 | * @param prob_go_on_off the probability of the action | 1714 | * @param prob_go_on_off the probability of the action |
1713 | */ | 1715 | */ |
1714 | static void | 1716 | static void |
1715 | manage_service_wrapper (unsigned int i, unsigned int j, | 1717 | manage_service_wrapper(unsigned int i, unsigned int j, |
1716 | enum PEER_ONLINE_DELTA delta, | 1718 | enum PEER_ONLINE_DELTA delta, |
1717 | double prob_go_on_off) | 1719 | double prob_go_on_off) |
1718 | { | 1720 | { |
1719 | struct OpListEntry *entry = NULL; | 1721 | struct OpListEntry *entry = NULL; |
1720 | uint32_t prob; | 1722 | uint32_t prob; |
1721 | 1723 | ||
1722 | /* make sure that management operation is not already scheduled */ | 1724 | /* make sure that management operation is not already scheduled */ |
1723 | if (NULL != rps_peers[j].entry_op_manage) | 1725 | if (NULL != rps_peers[j].entry_op_manage) |
1724 | { | 1726 | { |
1725 | return; | 1727 | return; |
1726 | } | 1728 | } |
1727 | 1729 | ||
1728 | prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 1730 | prob = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
1729 | UINT32_MAX); | 1731 | UINT32_MAX); |
1730 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1732 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1731 | "%u. selected peer (%u: %s) is %s.\n", | 1733 | "%u. selected peer (%u: %s) is %s.\n", |
1732 | i, | 1734 | i, |
1733 | j, | 1735 | j, |
1734 | GNUNET_i2s (rps_peers[j].peer_id), | 1736 | GNUNET_i2s(rps_peers[j].peer_id), |
1735 | (PEER_GO_ONLINE == delta) ? "online" : "offline"); | 1737 | (PEER_GO_ONLINE == delta) ? "online" : "offline"); |
1736 | if (prob < prob_go_on_off * UINT32_MAX) | 1738 | if (prob < prob_go_on_off * UINT32_MAX) |
1737 | { | 1739 | { |
1738 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1740 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1739 | "%s goes %s\n", | 1741 | "%s goes %s\n", |
1740 | GNUNET_i2s (rps_peers[j].peer_id), | 1742 | GNUNET_i2s(rps_peers[j].peer_id), |
1741 | (PEER_GO_OFFLINE == delta) ? "offline" : "online"); | 1743 | (PEER_GO_OFFLINE == delta) ? "offline" : "online"); |
1742 | 1744 | ||
1743 | if (PEER_GO_OFFLINE == delta) | 1745 | if (PEER_GO_OFFLINE == delta) |
1744 | cancel_pending_req_rep (&rps_peers[j]); | 1746 | cancel_pending_req_rep(&rps_peers[j]); |
1745 | entry = make_oplist_entry (); | 1747 | entry = make_oplist_entry(); |
1746 | entry->delta = delta; | 1748 | entry->delta = delta; |
1747 | entry->index = j; | 1749 | entry->index = j; |
1748 | entry->op = GNUNET_TESTBED_peer_manage_service (NULL, | 1750 | entry->op = GNUNET_TESTBED_peer_manage_service(NULL, |
1749 | testbed_peers[j], | 1751 | testbed_peers[j], |
1750 | "rps", | 1752 | "rps", |
1751 | &churn_cb, | 1753 | &churn_cb, |
1752 | entry, | 1754 | entry, |
1753 | (PEER_GO_OFFLINE == delta) ? 0 : 1); | 1755 | (PEER_GO_OFFLINE == delta) ? 0 : 1); |
1754 | rps_peers[j].entry_op_manage = entry; | 1756 | rps_peers[j].entry_op_manage = entry; |
1755 | } | 1757 | } |
1756 | } | 1758 | } |
1757 | 1759 | ||
1758 | 1760 | ||
1759 | static void | 1761 | static void |
1760 | churn (void *cls) | 1762 | churn(void *cls) |
1761 | { | 1763 | { |
1762 | (void) cls; | 1764 | (void)cls; |
1763 | unsigned int i; | 1765 | unsigned int i; |
1764 | unsigned int j; | 1766 | unsigned int j; |
1765 | double portion_online; | 1767 | double portion_online; |
@@ -1769,67 +1771,67 @@ churn (void *cls) | |||
1769 | double portion_go_offline; | 1771 | double portion_go_offline; |
1770 | 1772 | ||
1771 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | 1773 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1772 | { | 1774 | { |
1773 | return; | 1775 | return; |
1774 | } | 1776 | } |
1775 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1777 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1776 | "Churn function executing\n"); | 1778 | "Churn function executing\n"); |
1777 | 1779 | ||
1778 | churn_task = NULL; /* Should be invalid by now */ | 1780 | churn_task = NULL; /* Should be invalid by now */ |
1779 | 1781 | ||
1780 | /* Compute the probability for an online peer to go offline | 1782 | /* Compute the probability for an online peer to go offline |
1781 | * this round */ | 1783 | * this round */ |
1782 | portion_online = num_peers_online * 1.0 / num_peers; | 1784 | portion_online = num_peers_online * 1.0 / num_peers; |
1783 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1785 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1784 | "Portion online: %f\n", | 1786 | "Portion online: %f\n", |
1785 | portion_online); | 1787 | portion_online); |
1786 | portion_go_online = ((1 - portion_online) * .5 * .66); | 1788 | portion_go_online = ((1 - portion_online) * .5 * .66); |
1787 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1789 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1788 | "Portion that should go online: %f\n", | 1790 | "Portion that should go online: %f\n", |
1789 | portion_go_online); | 1791 | portion_go_online); |
1790 | portion_go_offline = (portion_online + portion_go_online) - .75; | 1792 | portion_go_offline = (portion_online + portion_go_online) - .75; |
1791 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1793 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1792 | "Portion that probably goes offline: %f\n", | 1794 | "Portion that probably goes offline: %f\n", |
1793 | portion_go_offline); | 1795 | portion_go_offline); |
1794 | prob_go_offline = portion_go_offline / (portion_online * .5); | 1796 | prob_go_offline = portion_go_offline / (portion_online * .5); |
1795 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1797 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1796 | "Probability of a selected online peer to go offline: %f\n", | 1798 | "Probability of a selected online peer to go offline: %f\n", |
1797 | prob_go_offline); | 1799 | prob_go_offline); |
1798 | 1800 | ||
1799 | permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, | 1801 | permut = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_WEAK, |
1800 | (unsigned int) num_peers); | 1802 | (unsigned int)num_peers); |
1801 | 1803 | ||
1802 | /* Go over 50% randomly chosen peers */ | 1804 | /* Go over 50% randomly chosen peers */ |
1803 | for (i = 0; i < .5 * num_peers; i++) | 1805 | for (i = 0; i < .5 * num_peers; i++) |
1804 | { | ||
1805 | j = permut[i]; | ||
1806 | |||
1807 | /* If online, shut down with certain probability */ | ||
1808 | if (GNUNET_YES == rps_peers[j].online) | ||
1809 | { | ||
1810 | manage_service_wrapper (i, j, -1, prob_go_offline); | ||
1811 | } | ||
1812 | |||
1813 | /* If offline, restart with certain probability */ | ||
1814 | else if (GNUNET_NO == rps_peers[j].online) | ||
1815 | { | 1806 | { |
1816 | manage_service_wrapper (i, j, 1, 0.66); | 1807 | j = permut[i]; |
1808 | |||
1809 | /* If online, shut down with certain probability */ | ||
1810 | if (GNUNET_YES == rps_peers[j].online) | ||
1811 | { | ||
1812 | manage_service_wrapper(i, j, -1, prob_go_offline); | ||
1813 | } | ||
1814 | |||
1815 | /* If offline, restart with certain probability */ | ||
1816 | else if (GNUNET_NO == rps_peers[j].online) | ||
1817 | { | ||
1818 | manage_service_wrapper(i, j, 1, 0.66); | ||
1819 | } | ||
1817 | } | 1820 | } |
1818 | } | ||
1819 | 1821 | ||
1820 | GNUNET_free (permut); | 1822 | GNUNET_free(permut); |
1821 | 1823 | ||
1822 | churn_task = GNUNET_SCHEDULER_add_delayed ( | 1824 | churn_task = GNUNET_SCHEDULER_add_delayed( |
1823 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), | 1825 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), |
1824 | churn, | 1826 | churn, |
1825 | NULL); | 1827 | NULL); |
1826 | } | 1828 | } |
1827 | 1829 | ||
1828 | 1830 | ||
1829 | /** | 1831 | /** |
1830 | * Initialise given RPSPeer | 1832 | * Initialise given RPSPeer |
1831 | */ | 1833 | */ |
1832 | static void profiler_init_peer (struct RPSPeer *rps_peer) | 1834 | static void profiler_init_peer(struct RPSPeer *rps_peer) |
1833 | { | 1835 | { |
1834 | if (num_peers - 1 == rps_peer->index) | 1836 | if (num_peers - 1 == rps_peer->index) |
1835 | rps_peer->num_ids_to_request = cur_test_run.num_requests; | 1837 | rps_peer->num_ids_to_request = cur_test_run.num_requests; |
@@ -1844,7 +1846,7 @@ static void profiler_init_peer (struct RPSPeer *rps_peer) | |||
1844 | * @param recv_peers the received peers | 1846 | * @param recv_peers the received peers |
1845 | */ | 1847 | */ |
1846 | static void | 1848 | static void |
1847 | profiler_reply_handle (void *cls, | 1849 | profiler_reply_handle(void *cls, |
1848 | uint64_t n, | 1850 | uint64_t n, |
1849 | const struct GNUNET_PeerIdentity *recv_peers) | 1851 | const struct GNUNET_PeerIdentity *recv_peers) |
1850 | { | 1852 | { |
@@ -1853,61 +1855,63 @@ profiler_reply_handle (void *cls, | |||
1853 | char *file_name; | 1855 | char *file_name; |
1854 | char *file_name_dh; | 1856 | char *file_name_dh; |
1855 | unsigned int i; | 1857 | unsigned int i; |
1856 | struct PendingReply *pending_rep = (struct PendingReply *) cls; | 1858 | struct PendingReply *pending_rep = (struct PendingReply *)cls; |
1857 | 1859 | ||
1858 | rps_peer = pending_rep->rps_peer; | 1860 | rps_peer = pending_rep->rps_peer; |
1859 | file_name = "/tmp/rps/received_ids"; | 1861 | file_name = "/tmp/rps/received_ids"; |
1860 | file_name_dh = "/tmp/rps/diehard_input"; | 1862 | file_name_dh = "/tmp/rps/diehard_input"; |
1861 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1863 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1862 | "[%s] got %" PRIu64 " peers:\n", | 1864 | "[%s] got %" PRIu64 " peers:\n", |
1863 | GNUNET_i2s (rps_peer->peer_id), | 1865 | GNUNET_i2s(rps_peer->peer_id), |
1864 | n); | 1866 | n); |
1865 | for (i = 0; i < n; i++) | 1867 | for (i = 0; i < n; i++) |
1866 | { | 1868 | { |
1867 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1869 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1868 | "%u: %s\n", | 1870 | "%u: %s\n", |
1869 | i, | 1871 | i, |
1870 | GNUNET_i2s (&recv_peers[i])); | 1872 | GNUNET_i2s(&recv_peers[i])); |
1871 | tofile (file_name, | 1873 | tofile(file_name, |
1872 | "%s\n", | 1874 | "%s\n", |
1873 | GNUNET_i2s_full (&recv_peers[i])); | 1875 | GNUNET_i2s_full(&recv_peers[i])); |
1874 | rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get (peer_map, &recv_peers[i]); | 1876 | rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get(peer_map, &recv_peers[i]); |
1875 | GNUNET_assert (NULL != rcv_rps_peer); | 1877 | GNUNET_assert(NULL != rcv_rps_peer); |
1876 | tofile (file_name_dh, | 1878 | tofile(file_name_dh, |
1877 | "%" PRIu32 "\n", | 1879 | "%" PRIu32 "\n", |
1878 | (uint32_t) rcv_rps_peer->index); | 1880 | (uint32_t)rcv_rps_peer->index); |
1879 | } | 1881 | } |
1880 | default_reply_handle (cls, n, recv_peers); | 1882 | default_reply_handle(cls, n, recv_peers); |
1881 | } | 1883 | } |
1882 | 1884 | ||
1883 | 1885 | ||
1884 | static void | 1886 | static void |
1885 | profiler_cb (struct RPSPeer *rps_peer) | 1887 | profiler_cb(struct RPSPeer *rps_peer) |
1886 | { | 1888 | { |
1887 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | 1889 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1888 | { | 1890 | { |
1889 | return; | 1891 | return; |
1890 | } | 1892 | } |
1891 | 1893 | ||
1892 | /* Start churn */ | 1894 | /* Start churn */ |
1893 | if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) | 1895 | if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) |
1894 | { | 1896 | { |
1895 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1897 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1896 | "Starting churn task\n"); | 1898 | "Starting churn task\n"); |
1897 | churn_task = GNUNET_SCHEDULER_add_delayed ( | 1899 | churn_task = GNUNET_SCHEDULER_add_delayed( |
1898 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), | 1900 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), |
1899 | churn, | 1901 | churn, |
1900 | NULL); | 1902 | NULL); |
1901 | } else { | 1903 | } |
1902 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1904 | else |
1903 | "Not starting churn task\n"); | 1905 | { |
1904 | } | 1906 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1907 | "Not starting churn task\n"); | ||
1908 | } | ||
1905 | 1909 | ||
1906 | /* Only request peer ids at one peer. | 1910 | /* Only request peer ids at one peer. |
1907 | * (It's the before-last because last one is target of the focussed attack.) | 1911 | * (It's the before-last because last one is target of the focussed attack.) |
1908 | */ | 1912 | */ |
1909 | if (eval_peer == rps_peer) | 1913 | if (eval_peer == rps_peer) |
1910 | schedule_missing_requests (rps_peer); | 1914 | schedule_missing_requests(rps_peer); |
1911 | } | 1915 | } |
1912 | 1916 | ||
1913 | /** | 1917 | /** |
@@ -1920,30 +1924,30 @@ profiler_cb (struct RPSPeer *rps_peer) | |||
1920 | * #GNUNET_SYSERR to abort iteration with error! | 1924 | * #GNUNET_SYSERR to abort iteration with error! |
1921 | */ | 1925 | */ |
1922 | int | 1926 | int |
1923 | file_name_cb (void *cls, const char *filename) | 1927 | file_name_cb(void *cls, const char *filename) |
1924 | { | 1928 | { |
1925 | (void) cls; | 1929 | (void)cls; |
1926 | 1930 | ||
1927 | if (NULL != strstr (filename, "sampler_el")) | 1931 | if (NULL != strstr(filename, "sampler_el")) |
1928 | { | ||
1929 | struct RPS_SamplerElement *s_elem; | ||
1930 | struct GNUNET_CRYPTO_AuthKey auth_key; | ||
1931 | const char *key_char; | ||
1932 | uint32_t i; | ||
1933 | |||
1934 | key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */ | ||
1935 | tofile (filename, "--------------------------\n"); | ||
1936 | |||
1937 | auth_key = string_to_auth_key (key_char); | ||
1938 | s_elem = RPS_sampler_elem_create (); | ||
1939 | RPS_sampler_elem_set (s_elem, auth_key); | ||
1940 | |||
1941 | for (i = 0; i < num_peers; i++) | ||
1942 | { | 1932 | { |
1943 | RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]); | 1933 | struct RPS_SamplerElement *s_elem; |
1934 | struct GNUNET_CRYPTO_AuthKey auth_key; | ||
1935 | const char *key_char; | ||
1936 | uint32_t i; | ||
1937 | |||
1938 | key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */ | ||
1939 | tofile(filename, "--------------------------\n"); | ||
1940 | |||
1941 | auth_key = string_to_auth_key(key_char); | ||
1942 | s_elem = RPS_sampler_elem_create(); | ||
1943 | RPS_sampler_elem_set(s_elem, auth_key); | ||
1944 | |||
1945 | for (i = 0; i < num_peers; i++) | ||
1946 | { | ||
1947 | RPS_sampler_elem_next(s_elem, &rps_peer_ids[i]); | ||
1948 | } | ||
1949 | RPS_sampler_elem_destroy(s_elem); | ||
1944 | } | 1950 | } |
1945 | RPS_sampler_elem_destroy (s_elem); | ||
1946 | } | ||
1947 | return GNUNET_OK; | 1951 | return GNUNET_OK; |
1948 | } | 1952 | } |
1949 | 1953 | ||
@@ -1953,15 +1957,15 @@ file_name_cb (void *cls, const char *filename) | |||
1953 | * Compute all perfect samples. | 1957 | * Compute all perfect samples. |
1954 | */ | 1958 | */ |
1955 | int | 1959 | int |
1956 | profiler_eval (void) | 1960 | profiler_eval(void) |
1957 | { | 1961 | { |
1958 | /* Compute perfect sample for each sampler element */ | 1962 | /* Compute perfect sample for each sampler element */ |
1959 | if (-1 == GNUNET_DISK_directory_scan ("/tmp/rps/", file_name_cb, NULL)) | 1963 | if (-1 == GNUNET_DISK_directory_scan("/tmp/rps/", file_name_cb, NULL)) |
1960 | { | 1964 | { |
1961 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n"); | 1965 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n"); |
1962 | } | 1966 | } |
1963 | 1967 | ||
1964 | return evaluate (); | 1968 | return evaluate(); |
1965 | } | 1969 | } |
1966 | 1970 | ||
1967 | 1971 | ||
@@ -1973,39 +1977,40 @@ profiler_eval (void) | |||
1973 | * | 1977 | * |
1974 | * @return | 1978 | * @return |
1975 | */ | 1979 | */ |
1976 | static int is_in_view (uint32_t a, uint32_t b) | 1980 | static int is_in_view(uint32_t a, uint32_t b) |
1977 | { | 1981 | { |
1978 | uint32_t i; | 1982 | uint32_t i; |
1983 | |||
1979 | for (i = 0; i < rps_peers[a].cur_view_count; i++) | 1984 | for (i = 0; i < rps_peers[a].cur_view_count; i++) |
1980 | { | ||
1981 | if (0 == memcmp (rps_peers[b].peer_id, | ||
1982 | &rps_peers[a].cur_view[i], | ||
1983 | sizeof (struct GNUNET_PeerIdentity))) | ||
1984 | { | 1985 | { |
1985 | return GNUNET_YES; | 1986 | if (0 == memcmp(rps_peers[b].peer_id, |
1987 | &rps_peers[a].cur_view[i], | ||
1988 | sizeof(struct GNUNET_PeerIdentity))) | ||
1989 | { | ||
1990 | return GNUNET_YES; | ||
1991 | } | ||
1986 | } | 1992 | } |
1987 | } | ||
1988 | return GNUNET_NO; | 1993 | return GNUNET_NO; |
1989 | } | 1994 | } |
1990 | 1995 | ||
1991 | static uint32_t get_idx_of_pid (const struct GNUNET_PeerIdentity *pid) | 1996 | static uint32_t get_idx_of_pid(const struct GNUNET_PeerIdentity *pid) |
1992 | { | 1997 | { |
1993 | uint32_t i; | 1998 | uint32_t i; |
1994 | 1999 | ||
1995 | for (i = 0; i < num_peers; i++) | 2000 | for (i = 0; i < num_peers; i++) |
1996 | { | ||
1997 | if (0 == memcmp (pid, | ||
1998 | rps_peers[i].peer_id, | ||
1999 | sizeof (struct GNUNET_PeerIdentity))) | ||
2000 | { | 2001 | { |
2001 | return i; | 2002 | if (0 == memcmp(pid, |
2003 | rps_peers[i].peer_id, | ||
2004 | sizeof(struct GNUNET_PeerIdentity))) | ||
2005 | { | ||
2006 | return i; | ||
2007 | } | ||
2002 | } | 2008 | } |
2003 | } | ||
2004 | //return 0; /* Should not happen - make compiler happy */ | 2009 | //return 0; /* Should not happen - make compiler happy */ |
2005 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2010 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2006 | "No known _PeerIdentity %s!\n", | 2011 | "No known _PeerIdentity %s!\n", |
2007 | GNUNET_i2s_full (pid)); | 2012 | GNUNET_i2s_full(pid)); |
2008 | GNUNET_assert (0); | 2013 | GNUNET_assert(0); |
2009 | } | 2014 | } |
2010 | 2015 | ||
2011 | /** | 2016 | /** |
@@ -2016,20 +2021,20 @@ static uint32_t get_idx_of_pid (const struct GNUNET_PeerIdentity *pid) | |||
2016 | * | 2021 | * |
2017 | * @return | 2022 | * @return |
2018 | */ | 2023 | */ |
2019 | static uint32_t count_containing_views (uint32_t a, uint32_t b) | 2024 | static uint32_t count_containing_views(uint32_t a, uint32_t b) |
2020 | { | 2025 | { |
2021 | uint32_t i; | 2026 | uint32_t i; |
2022 | uint32_t peer_idx; | 2027 | uint32_t peer_idx; |
2023 | uint32_t count = 0; | 2028 | uint32_t count = 0; |
2024 | 2029 | ||
2025 | for (i = 0; i < rps_peers[a].cur_view_count; i++) | 2030 | for (i = 0; i < rps_peers[a].cur_view_count; i++) |
2026 | { | ||
2027 | peer_idx = get_idx_of_pid (&rps_peers[a].cur_view[i]); | ||
2028 | if (GNUNET_YES == is_in_view (peer_idx, b)) | ||
2029 | { | 2031 | { |
2030 | count++; | 2032 | peer_idx = get_idx_of_pid(&rps_peers[a].cur_view[i]); |
2033 | if (GNUNET_YES == is_in_view(peer_idx, b)) | ||
2034 | { | ||
2035 | count++; | ||
2036 | } | ||
2031 | } | 2037 | } |
2032 | } | ||
2033 | return count; | 2038 | return count; |
2034 | } | 2039 | } |
2035 | 2040 | ||
@@ -2039,12 +2044,12 @@ static uint32_t count_containing_views (uint32_t a, uint32_t b) | |||
2039 | * | 2044 | * |
2040 | * @param peer_idx index of the peer that is about to sample | 2045 | * @param peer_idx index of the peer that is about to sample |
2041 | */ | 2046 | */ |
2042 | static void compute_probabilities (uint32_t peer_idx) | 2047 | static void compute_probabilities(uint32_t peer_idx) |
2043 | { | 2048 | { |
2044 | //double probs[num_peers] = { 0 }; | 2049 | //double probs[num_peers] = { 0 }; |
2045 | double probs[num_peers]; | 2050 | double probs[num_peers]; |
2046 | size_t probs_as_str_size = (num_peers * 10 + 1) * sizeof (char); | 2051 | size_t probs_as_str_size = (num_peers * 10 + 1) * sizeof(char); |
2047 | char *probs_as_str = GNUNET_malloc (probs_as_str_size); | 2052 | char *probs_as_str = GNUNET_malloc(probs_as_str_size); |
2048 | char *probs_as_str_cpy; | 2053 | char *probs_as_str_cpy; |
2049 | uint32_t i; | 2054 | uint32_t i; |
2050 | double prob_push; | 2055 | double prob_push; |
@@ -2055,113 +2060,119 @@ static void compute_probabilities (uint32_t peer_idx) | |||
2055 | int tmp; | 2060 | int tmp; |
2056 | uint32_t count_non_zero_prob = 0; | 2061 | uint32_t count_non_zero_prob = 0; |
2057 | 2062 | ||
2058 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2063 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2059 | "Computing probabilities for peer %" PRIu32 "\n", peer_idx); | 2064 | "Computing probabilities for peer %" PRIu32 "\n", peer_idx); |
2060 | /* Firstly without knowledge of old views */ | 2065 | /* Firstly without knowledge of old views */ |
2061 | for (i = 0; i < num_peers; i++) | 2066 | for (i = 0; i < num_peers; i++) |
2062 | { | 2067 | { |
2063 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2068 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2064 | "\tfor peer %" PRIu32 ":\n", i); | 2069 | "\tfor peer %" PRIu32 ":\n", i); |
2065 | view_size = rps_peers[i].cur_view_count; | 2070 | view_size = rps_peers[i].cur_view_count; |
2066 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2071 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2067 | "\t\tview_size: %" PRIu32 "\n", view_size); | 2072 | "\t\tview_size: %" PRIu32 "\n", view_size); |
2068 | /* For peer i the probability of being sampled is | 2073 | /* For peer i the probability of being sampled is |
2069 | * evenly distributed among all possibly observed peers. */ | 2074 | * evenly distributed among all possibly observed peers. */ |
2070 | /* We could have observed a peer in three cases: | 2075 | /* We could have observed a peer in three cases: |
2071 | * 1. peer sent a push | 2076 | * 1. peer sent a push |
2072 | * 2. peer was contained in a pull reply | 2077 | * 2. peer was contained in a pull reply |
2073 | * 3. peer was in history (sampler) - ignored for now */ | 2078 | * 3. peer was in history (sampler) - ignored for now */ |
2074 | /* 1. Probability of having received a push from peer i */ | 2079 | /* 1. Probability of having received a push from peer i */ |
2075 | if ((GNUNET_YES == is_in_view (i, peer_idx)) && | 2080 | if ((GNUNET_YES == is_in_view(i, peer_idx)) && |
2076 | (1 <= (0.45 * view_size))) | 2081 | (1 <= (0.45 * view_size))) |
2077 | { | 2082 | { |
2078 | prob_push = 1.0 * binom (0.45 * view_size, 1) | 2083 | prob_push = 1.0 * binom(0.45 * view_size, 1) |
2079 | / | 2084 | / |
2080 | binom (view_size, 0.45 * view_size); | 2085 | binom(view_size, 0.45 * view_size); |
2081 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2086 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2082 | "\t\t%" PRIu32 " is in %" PRIu32 "'s view, prob: %f\n", | 2087 | "\t\t%" PRIu32 " is in %" PRIu32 "'s view, prob: %f\n", |
2088 | peer_idx, | ||
2089 | i, | ||
2090 | prob_push); | ||
2091 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2092 | "\t\tposs choices from view: %" PRIu32 ", containing i: %" PRIu32 "\n", | ||
2093 | binom(view_size, 0.45 * view_size), | ||
2094 | binom(0.45 * view_size, 1)); | ||
2095 | } | ||
2096 | else | ||
2097 | { | ||
2098 | prob_push = 0; | ||
2099 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2100 | "\t\t%" PRIu32 " is not in %" PRIu32 "'s view, prob: 0\n", | ||
2101 | peer_idx, | ||
2102 | i); | ||
2103 | } | ||
2104 | /* 2. Probability of peer i being contained in pulls */ | ||
2105 | view_size = rps_peers[peer_idx].cur_view_count; | ||
2106 | cont_views = count_containing_views(peer_idx, i); | ||
2107 | number_of_being_in_pull_events = | ||
2108 | (binom(view_size, 0.45 * view_size) - | ||
2109 | binom(view_size - cont_views, 0.45 * view_size)); | ||
2110 | if (0 != number_of_being_in_pull_events) | ||
2111 | { | ||
2112 | prob_pull = number_of_being_in_pull_events | ||
2113 | / | ||
2114 | (1.0 * binom(view_size, 0.45 * view_size)); | ||
2115 | } | ||
2116 | else | ||
2117 | { | ||
2118 | prob_pull = 0; | ||
2119 | } | ||
2120 | probs[i] = prob_push + prob_pull - (prob_push * prob_pull); | ||
2121 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2122 | "\t\t%" PRIu32 " has %" PRIu32 " of %" PRIu32 | ||
2123 | " peers in its view who know %" PRIu32 " prob: %f\n", | ||
2083 | peer_idx, | 2124 | peer_idx, |
2125 | cont_views, | ||
2126 | view_size, | ||
2084 | i, | 2127 | i, |
2085 | prob_push); | 2128 | prob_pull); |
2086 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2129 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2087 | "\t\tposs choices from view: %" PRIu32 ", containing i: %" PRIu32 "\n", | 2130 | "\t\tnumber of possible pull combinations: %" PRIu32 "\n", |
2088 | binom (view_size, 0.45 * view_size), | 2131 | binom(view_size, 0.45 * view_size)); |
2089 | binom (0.45 * view_size, 1)); | 2132 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2090 | } else { | 2133 | "\t\tnumber of possible pull combinations without %" PRIu32 |
2091 | prob_push = 0; | 2134 | ": %" PRIu32 "\n", |
2092 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2135 | i, |
2093 | "\t\t%" PRIu32 " is not in %" PRIu32 "'s view, prob: 0\n", | 2136 | binom(view_size - cont_views, 0.45 * view_size)); |
2094 | peer_idx, | 2137 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2095 | i); | 2138 | "\t\tnumber of possible pull combinations with %" PRIu32 |
2096 | } | 2139 | ": %" PRIu32 "\n", |
2097 | /* 2. Probability of peer i being contained in pulls */ | 2140 | i, |
2098 | view_size = rps_peers[peer_idx].cur_view_count; | 2141 | number_of_being_in_pull_events); |
2099 | cont_views = count_containing_views (peer_idx, i); | ||
2100 | number_of_being_in_pull_events = | ||
2101 | (binom (view_size, 0.45 * view_size) - | ||
2102 | binom (view_size - cont_views, 0.45 * view_size)); | ||
2103 | if (0 != number_of_being_in_pull_events) | ||
2104 | { | ||
2105 | prob_pull = number_of_being_in_pull_events | ||
2106 | / | ||
2107 | (1.0 * binom (view_size, 0.45 * view_size)); | ||
2108 | } else | ||
2109 | { | ||
2110 | prob_pull = 0; | ||
2111 | } | ||
2112 | probs[i] = prob_push + prob_pull - (prob_push * prob_pull); | ||
2113 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2114 | "\t\t%" PRIu32 " has %" PRIu32 " of %" PRIu32 | ||
2115 | " peers in its view who know %" PRIu32 " prob: %f\n", | ||
2116 | peer_idx, | ||
2117 | cont_views, | ||
2118 | view_size, | ||
2119 | i, | ||
2120 | prob_pull); | ||
2121 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2122 | "\t\tnumber of possible pull combinations: %" PRIu32 "\n", | ||
2123 | binom (view_size, 0.45 * view_size)); | ||
2124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2125 | "\t\tnumber of possible pull combinations without %" PRIu32 | ||
2126 | ": %" PRIu32 "\n", | ||
2127 | i, | ||
2128 | binom (view_size - cont_views, 0.45 * view_size)); | ||
2129 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2130 | "\t\tnumber of possible pull combinations with %" PRIu32 | ||
2131 | ": %" PRIu32 "\n", | ||
2132 | i, | ||
2133 | number_of_being_in_pull_events); | ||
2134 | 2142 | ||
2135 | if (0 != probs[i]) count_non_zero_prob++; | 2143 | if (0 != probs[i]) |
2136 | } | 2144 | count_non_zero_prob++; |
2145 | } | ||
2137 | /* normalize */ | 2146 | /* normalize */ |
2138 | if (0 != count_non_zero_prob) | 2147 | if (0 != count_non_zero_prob) |
2139 | { | ||
2140 | for (i = 0; i < num_peers; i++) | ||
2141 | { | 2148 | { |
2142 | probs[i] = probs[i] * (1.0 / count_non_zero_prob); | 2149 | for (i = 0; i < num_peers; i++) |
2150 | { | ||
2151 | probs[i] = probs[i] * (1.0 / count_non_zero_prob); | ||
2152 | } | ||
2143 | } | 2153 | } |
2144 | } else { | 2154 | else |
2145 | for (i = 0; i < num_peers; i++) | ||
2146 | { | 2155 | { |
2147 | probs[i] = 0; | 2156 | for (i = 0; i < num_peers; i++) |
2157 | { | ||
2158 | probs[i] = 0; | ||
2159 | } | ||
2148 | } | 2160 | } |
2149 | } | ||
2150 | /* str repr */ | 2161 | /* str repr */ |
2151 | for (i = 0; i < num_peers; i++) | 2162 | for (i = 0; i < num_peers; i++) |
2152 | { | 2163 | { |
2153 | probs_as_str_cpy = GNUNET_strndup (probs_as_str, probs_as_str_size); | 2164 | probs_as_str_cpy = GNUNET_strndup(probs_as_str, probs_as_str_size); |
2154 | tmp = GNUNET_snprintf (probs_as_str, | 2165 | tmp = GNUNET_snprintf(probs_as_str, |
2155 | probs_as_str_size, | 2166 | probs_as_str_size, |
2156 | "%s %7.6f", probs_as_str_cpy, probs[i]); | 2167 | "%s %7.6f", probs_as_str_cpy, probs[i]); |
2157 | GNUNET_free (probs_as_str_cpy); | 2168 | GNUNET_free(probs_as_str_cpy); |
2158 | GNUNET_assert (0 <= tmp); | 2169 | GNUNET_assert(0 <= tmp); |
2159 | } | 2170 | } |
2160 | 2171 | ||
2161 | to_file_w_len (rps_peers[peer_idx].file_name_probs, | 2172 | to_file_w_len(rps_peers[peer_idx].file_name_probs, |
2162 | probs_as_str_size, | 2173 | probs_as_str_size, |
2163 | probs_as_str); | 2174 | probs_as_str); |
2164 | GNUNET_free (probs_as_str); | 2175 | GNUNET_free(probs_as_str); |
2165 | } | 2176 | } |
2166 | 2177 | ||
2167 | /** | 2178 | /** |
@@ -2173,98 +2184,98 @@ static void compute_probabilities (uint32_t peer_idx) | |||
2173 | * | 2184 | * |
2174 | * @return the number of occurrences | 2185 | * @return the number of occurrences |
2175 | */ | 2186 | */ |
2176 | static uint32_t count_peer_in_views_2 (uint32_t peer_idx) | 2187 | static uint32_t count_peer_in_views_2(uint32_t peer_idx) |
2177 | { | 2188 | { |
2178 | uint32_t i, j; | 2189 | uint32_t i, j; |
2179 | uint32_t count = 0; | 2190 | uint32_t count = 0; |
2180 | 2191 | ||
2181 | for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ | 2192 | for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ |
2182 | { | 2193 | { |
2183 | for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */ | 2194 | for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */ |
2184 | { | 2195 | { |
2185 | if (0 == memcmp (rps_peers[peer_idx].peer_id, | 2196 | if (0 == memcmp(rps_peers[peer_idx].peer_id, |
2186 | &rps_peers[i].cur_view[j], | 2197 | &rps_peers[i].cur_view[j], |
2187 | sizeof (struct GNUNET_PeerIdentity))) | 2198 | sizeof(struct GNUNET_PeerIdentity))) |
2188 | { | 2199 | { |
2189 | count++; | 2200 | count++; |
2190 | break; | 2201 | break; |
2191 | } | 2202 | } |
2192 | } | 2203 | } |
2193 | } | 2204 | } |
2194 | rps_peers[peer_idx].count_in_views = count; | 2205 | rps_peers[peer_idx].count_in_views = count; |
2195 | return count; | 2206 | return count; |
2196 | } | 2207 | } |
2197 | 2208 | ||
2198 | static uint32_t cumulated_view_sizes () | 2209 | static uint32_t cumulated_view_sizes() |
2199 | { | 2210 | { |
2200 | uint32_t i; | 2211 | uint32_t i; |
2201 | 2212 | ||
2202 | view_sizes = 0; | 2213 | view_sizes = 0; |
2203 | for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ | 2214 | for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ |
2204 | { | 2215 | { |
2205 | view_sizes += rps_peers[i].cur_view_count; | 2216 | view_sizes += rps_peers[i].cur_view_count; |
2206 | } | 2217 | } |
2207 | return view_sizes; | 2218 | return view_sizes; |
2208 | } | 2219 | } |
2209 | 2220 | ||
2210 | static void count_peer_in_views (uint32_t *count_peers) | 2221 | static void count_peer_in_views(uint32_t *count_peers) |
2211 | { | 2222 | { |
2212 | uint32_t i, j; | 2223 | uint32_t i, j; |
2213 | 2224 | ||
2214 | for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ | 2225 | for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ |
2215 | { | ||
2216 | for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */ | ||
2217 | { | 2226 | { |
2218 | if (0 == memcmp (rps_peers[i].peer_id, | 2227 | for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */ |
2219 | &rps_peers[i].cur_view[j], | 2228 | { |
2220 | sizeof (struct GNUNET_PeerIdentity))) | 2229 | if (0 == memcmp(rps_peers[i].peer_id, |
2221 | { | 2230 | &rps_peers[i].cur_view[j], |
2222 | count_peers[i]++; | 2231 | sizeof(struct GNUNET_PeerIdentity))) |
2223 | } | 2232 | { |
2233 | count_peers[i]++; | ||
2234 | } | ||
2235 | } | ||
2224 | } | 2236 | } |
2225 | } | ||
2226 | } | 2237 | } |
2227 | 2238 | ||
2228 | void compute_diversity () | 2239 | void compute_diversity() |
2229 | { | 2240 | { |
2230 | uint32_t i; | 2241 | uint32_t i; |
2231 | /* ith entry represents the numer of occurrences in other peer's views */ | 2242 | /* ith entry represents the numer of occurrences in other peer's views */ |
2232 | uint32_t *count_peers = GNUNET_new_array (num_peers, uint32_t); | 2243 | uint32_t *count_peers = GNUNET_new_array(num_peers, uint32_t); |
2233 | uint32_t views_total_size; | 2244 | uint32_t views_total_size; |
2234 | double expected; | 2245 | double expected; |
2235 | /* deviation from expected number of peers */ | 2246 | /* deviation from expected number of peers */ |
2236 | double *deviation = GNUNET_new_array (num_peers, double); | 2247 | double *deviation = GNUNET_new_array(num_peers, double); |
2237 | 2248 | ||
2238 | views_total_size = 0; | 2249 | views_total_size = 0; |
2239 | expected = 0; | 2250 | expected = 0; |
2240 | 2251 | ||
2241 | /* For each peer count its representation in other peer's views*/ | 2252 | /* For each peer count its representation in other peer's views*/ |
2242 | for (i = 0; i < num_peers; i++) /* Peer to count */ | 2253 | for (i = 0; i < num_peers; i++) /* Peer to count */ |
2243 | { | 2254 | { |
2244 | views_total_size += rps_peers[i].cur_view_count; | 2255 | views_total_size += rps_peers[i].cur_view_count; |
2245 | count_peer_in_views (count_peers); | 2256 | count_peer_in_views(count_peers); |
2246 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2257 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2247 | "Counted representation of %" PRIu32 "th peer [%s]: %" PRIu32"\n", | 2258 | "Counted representation of %" PRIu32 "th peer [%s]: %" PRIu32 "\n", |
2248 | i, | 2259 | i, |
2249 | GNUNET_i2s (rps_peers[i].peer_id), | 2260 | GNUNET_i2s(rps_peers[i].peer_id), |
2250 | count_peers[i]); | 2261 | count_peers[i]); |
2251 | } | 2262 | } |
2252 | 2263 | ||
2253 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2264 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2254 | "size of all views combined: %" PRIu32 "\n", | 2265 | "size of all views combined: %" PRIu32 "\n", |
2255 | views_total_size); | 2266 | views_total_size); |
2256 | expected = ((double) 1/num_peers) * views_total_size; | 2267 | expected = ((double)1 / num_peers) * views_total_size; |
2257 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2268 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2258 | "Expected number of occurrences of each peer in all views: %f\n", | 2269 | "Expected number of occurrences of each peer in all views: %f\n", |
2259 | expected); | 2270 | expected); |
2260 | for (i = 0; i < num_peers; i++) /* Peer to count */ | 2271 | for (i = 0; i < num_peers; i++) /* Peer to count */ |
2261 | { | 2272 | { |
2262 | deviation[i] = expected - count_peers[i]; | 2273 | deviation[i] = expected - count_peers[i]; |
2263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2274 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2264 | "Deviation from expectation: %f\n", deviation[i]); | 2275 | "Deviation from expectation: %f\n", deviation[i]); |
2265 | } | 2276 | } |
2266 | GNUNET_free (count_peers); | 2277 | GNUNET_free(count_peers); |
2267 | GNUNET_free (deviation); | 2278 | GNUNET_free(deviation); |
2268 | } | 2279 | } |
2269 | 2280 | ||
2270 | void print_view_sizes() | 2281 | void print_view_sizes() |
@@ -2272,13 +2283,13 @@ void print_view_sizes() | |||
2272 | uint32_t i; | 2283 | uint32_t i; |
2273 | 2284 | ||
2274 | for (i = 0; i < num_peers; i++) /* Peer to count */ | 2285 | for (i = 0; i < num_peers; i++) /* Peer to count */ |
2275 | { | 2286 | { |
2276 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2287 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2277 | "View size of %" PRIu32 ". [%s] is %" PRIu32 "\n", | 2288 | "View size of %" PRIu32 ". [%s] is %" PRIu32 "\n", |
2278 | i, | 2289 | i, |
2279 | GNUNET_i2s (rps_peers[i].peer_id), | 2290 | GNUNET_i2s(rps_peers[i].peer_id), |
2280 | rps_peers[i].cur_view_count); | 2291 | rps_peers[i].cur_view_count); |
2281 | } | 2292 | } |
2282 | } | 2293 | } |
2283 | 2294 | ||
2284 | void all_views_updated_cb() | 2295 | void all_views_updated_cb() |
@@ -2287,97 +2298,98 @@ void all_views_updated_cb() | |||
2287 | print_view_sizes(); | 2298 | print_view_sizes(); |
2288 | } | 2299 | } |
2289 | 2300 | ||
2290 | void view_update_cb (void *cls, | 2301 | void view_update_cb(void *cls, |
2291 | uint64_t view_size, | 2302 | uint64_t view_size, |
2292 | const struct GNUNET_PeerIdentity *peers) | 2303 | const struct GNUNET_PeerIdentity *peers) |
2293 | { | 2304 | { |
2294 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2305 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2295 | "View was updated (%" PRIu64 ")\n", view_size); | 2306 | "View was updated (%" PRIu64 ")\n", view_size); |
2296 | struct RPSPeer *rps_peer = (struct RPSPeer *) cls; | 2307 | struct RPSPeer *rps_peer = (struct RPSPeer *)cls; |
2297 | to_file ("/tmp/rps/view_sizes.txt", | 2308 | to_file("/tmp/rps/view_sizes.txt", |
2298 | "%" PRIu64 " %" PRIu32 "", | 2309 | "%" PRIu64 " %" PRIu32 "", |
2299 | rps_peer->index, | 2310 | rps_peer->index, |
2300 | view_size); | 2311 | view_size); |
2301 | for (int i = 0; i < view_size; i++) | 2312 | for (int i = 0; i < view_size; i++) |
2302 | { | 2313 | { |
2303 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2314 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2304 | "\t%s\n", GNUNET_i2s (&peers[i])); | 2315 | "\t%s\n", GNUNET_i2s(&peers[i])); |
2305 | } | 2316 | } |
2306 | GNUNET_array_grow (rps_peer->cur_view, | 2317 | GNUNET_array_grow(rps_peer->cur_view, |
2307 | rps_peer->cur_view_count, | 2318 | rps_peer->cur_view_count, |
2308 | view_size); | 2319 | view_size); |
2309 | //*rps_peer->cur_view = *peers; | 2320 | //*rps_peer->cur_view = *peers; |
2310 | GNUNET_memcpy (rps_peer->cur_view, | 2321 | GNUNET_memcpy(rps_peer->cur_view, |
2311 | peers, | 2322 | peers, |
2312 | view_size * sizeof (struct GNUNET_PeerIdentity)); | 2323 | view_size * sizeof(struct GNUNET_PeerIdentity)); |
2313 | to_file ("/tmp/rps/count_in_views.txt", | 2324 | to_file("/tmp/rps/count_in_views.txt", |
2314 | "%" PRIu64 " %" PRIu32 "", | 2325 | "%" PRIu64 " %" PRIu32 "", |
2315 | rps_peer->index, | 2326 | rps_peer->index, |
2316 | count_peer_in_views_2 (rps_peer->index)); | 2327 | count_peer_in_views_2(rps_peer->index)); |
2317 | cumulated_view_sizes(); | 2328 | cumulated_view_sizes(); |
2318 | if (0 != view_size) | 2329 | if (0 != view_size) |
2319 | { | 2330 | { |
2320 | to_file ("/tmp/rps/repr.txt", | 2331 | to_file("/tmp/rps/repr.txt", |
2321 | "%" PRIu64 /* index */ | 2332 | "%" PRIu64 /* index */ |
2322 | " %" PRIu32 /* occurrence in views */ | 2333 | " %" PRIu32 /* occurrence in views */ |
2323 | " %" PRIu32 /* view sizes */ | 2334 | " %" PRIu32 /* view sizes */ |
2324 | " %f" /* fraction of repr in views */ | 2335 | " %f" /* fraction of repr in views */ |
2325 | " %f" /* average view size */ | 2336 | " %f" /* average view size */ |
2326 | " %f" /* prob of occurrence in view slot */ | 2337 | " %f" /* prob of occurrence in view slot */ |
2327 | " %f" "", /* exp frac of repr in views */ | 2338 | " %f" "", /* exp frac of repr in views */ |
2328 | rps_peer->index, | 2339 | rps_peer->index, |
2329 | count_peer_in_views_2 (rps_peer->index), | 2340 | count_peer_in_views_2(rps_peer->index), |
2330 | view_sizes, | 2341 | view_sizes, |
2331 | count_peer_in_views_2 (rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */ | 2342 | count_peer_in_views_2(rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */ |
2332 | view_sizes / (view_size * 1.0), /* average view size */ | 2343 | view_sizes / (view_size * 1.0), /* average view size */ |
2333 | 1.0 /view_size, /* prob of occurrence in view slot */ | 2344 | 1.0 / view_size, /* prob of occurrence in view slot */ |
2334 | (1.0/view_size) * (view_sizes/view_size) /* expected fraction of repr in views */ | 2345 | (1.0 / view_size) * (view_sizes / view_size) /* expected fraction of repr in views */ |
2335 | ); | 2346 | ); |
2336 | } | 2347 | } |
2337 | compute_probabilities (rps_peer->index); | 2348 | compute_probabilities(rps_peer->index); |
2338 | all_views_updated_cb(); | 2349 | all_views_updated_cb(); |
2339 | } | 2350 | } |
2340 | 2351 | ||
2341 | static void | 2352 | static void |
2342 | pre_profiler (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) | 2353 | pre_profiler(struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) |
2343 | { | 2354 | { |
2344 | rps_peer->file_name_probs = | 2355 | rps_peer->file_name_probs = |
2345 | store_prefix_file_name (rps_peer->peer_id, "probs"); | 2356 | store_prefix_file_name(rps_peer->peer_id, "probs"); |
2346 | GNUNET_RPS_view_request (h, 0, view_update_cb, rps_peer); | 2357 | GNUNET_RPS_view_request(h, 0, view_update_cb, rps_peer); |
2347 | } | 2358 | } |
2348 | 2359 | ||
2349 | void write_final_stats (void){ | 2360 | void write_final_stats(void) |
2361 | { | ||
2350 | uint32_t i; | 2362 | uint32_t i; |
2351 | 2363 | ||
2352 | for (i = 0; i < num_peers; i++) | 2364 | for (i = 0; i < num_peers; i++) |
2353 | { | 2365 | { |
2354 | to_file ("/tmp/rps/final_stats.dat", | 2366 | to_file("/tmp/rps/final_stats.dat", |
2355 | "%" PRIu32 " " /* index */ | 2367 | "%" PRIu32 " " /* index */ |
2356 | "%s %" /* id */ | 2368 | "%s %" /* id */ |
2357 | PRIu64 " %" /* rounds */ | 2369 | PRIu64 " %" /* rounds */ |
2358 | PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" /* blocking */ | 2370 | PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" /* blocking */ |
2359 | PRIu64 " %" PRIu64 " %" PRIu64 " %" /* issued */ | 2371 | PRIu64 " %" PRIu64 " %" PRIu64 " %" /* issued */ |
2360 | PRIu64 " %" PRIu64 " %" PRIu64 " %" /* sent */ | 2372 | PRIu64 " %" PRIu64 " %" PRIu64 " %" /* sent */ |
2361 | PRIu64 " %" PRIu64 " %" PRIu64 /* recv */, | 2373 | PRIu64 " %" PRIu64 " %" PRIu64 /* recv */, |
2362 | i, | 2374 | i, |
2363 | GNUNET_i2s (rps_peers[i].peer_id), | 2375 | GNUNET_i2s(rps_peers[i].peer_id), |
2364 | rps_peers[i].num_rounds, | 2376 | rps_peers[i].num_rounds, |
2365 | rps_peers[i].num_blocks, | 2377 | rps_peers[i].num_blocks, |
2366 | rps_peers[i].num_blocks_many_push, | 2378 | rps_peers[i].num_blocks_many_push, |
2367 | rps_peers[i].num_blocks_no_push, | 2379 | rps_peers[i].num_blocks_no_push, |
2368 | rps_peers[i].num_blocks_no_pull, | 2380 | rps_peers[i].num_blocks_no_pull, |
2369 | rps_peers[i].num_blocks_many_push_no_pull, | 2381 | rps_peers[i].num_blocks_many_push_no_pull, |
2370 | rps_peers[i].num_blocks_no_push_no_pull, | 2382 | rps_peers[i].num_blocks_no_push_no_pull, |
2371 | rps_peers[i].num_issued_push, | 2383 | rps_peers[i].num_issued_push, |
2372 | rps_peers[i].num_issued_pull_req, | 2384 | rps_peers[i].num_issued_pull_req, |
2373 | rps_peers[i].num_issued_pull_rep, | 2385 | rps_peers[i].num_issued_pull_rep, |
2374 | rps_peers[i].num_sent_push, | 2386 | rps_peers[i].num_sent_push, |
2375 | rps_peers[i].num_sent_pull_req, | 2387 | rps_peers[i].num_sent_pull_req, |
2376 | rps_peers[i].num_sent_pull_rep, | 2388 | rps_peers[i].num_sent_pull_rep, |
2377 | rps_peers[i].num_recv_push, | 2389 | rps_peers[i].num_recv_push, |
2378 | rps_peers[i].num_recv_pull_req, | 2390 | rps_peers[i].num_recv_pull_req, |
2379 | rps_peers[i].num_recv_pull_rep); | 2391 | rps_peers[i].num_recv_pull_rep); |
2380 | } | 2392 | } |
2381 | } | 2393 | } |
2382 | 2394 | ||
2383 | /** | 2395 | /** |
@@ -2392,40 +2404,45 @@ void write_final_stats (void){ | |||
2392 | * successfully obtained, #GNUNET_SYSERR if not. | 2404 | * successfully obtained, #GNUNET_SYSERR if not. |
2393 | */ | 2405 | */ |
2394 | void | 2406 | void |
2395 | post_test_shutdown_ready_cb (void *cls, | 2407 | post_test_shutdown_ready_cb(void *cls, |
2396 | int success) | 2408 | int success) |
2397 | { | 2409 | { |
2398 | struct STATcls *stat_cls = (struct STATcls *) cls; | 2410 | struct STATcls *stat_cls = (struct STATcls *)cls; |
2399 | struct RPSPeer *rps_peer = stat_cls->rps_peer; | 2411 | struct RPSPeer *rps_peer = stat_cls->rps_peer; |
2412 | |||
2400 | if (GNUNET_OK == success) | 2413 | if (GNUNET_OK == success) |
2401 | { | 2414 | { |
2402 | /* set flag that we we got the value */ | 2415 | /* set flag that we we got the value */ |
2403 | rps_peer->stat_collected_flags |= stat_cls->stat_type; | 2416 | rps_peer->stat_collected_flags |= stat_cls->stat_type; |
2404 | } else { | 2417 | } |
2405 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2418 | else |
2406 | "Peer %u did not receive statistics value\n", | 2419 | { |
2407 | rps_peer->index); | 2420 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2408 | GNUNET_free (stat_cls); | 2421 | "Peer %u did not receive statistics value\n", |
2409 | GNUNET_break (0); | 2422 | rps_peer->index); |
2410 | } | 2423 | GNUNET_free(stat_cls); |
2424 | GNUNET_break(0); | ||
2425 | } | ||
2411 | 2426 | ||
2412 | if (NULL != rps_peer->stat_op && | 2427 | if (NULL != rps_peer->stat_op && |
2413 | GNUNET_YES == check_statistics_collect_completed_single_peer (rps_peer)) | 2428 | GNUNET_YES == check_statistics_collect_completed_single_peer(rps_peer)) |
2414 | { | 2429 | { |
2415 | GNUNET_TESTBED_operation_done (rps_peer->stat_op); | 2430 | GNUNET_TESTBED_operation_done(rps_peer->stat_op); |
2416 | } | 2431 | } |
2417 | 2432 | ||
2418 | write_final_stats (); | 2433 | write_final_stats(); |
2419 | if (GNUNET_YES == check_statistics_collect_completed()) | 2434 | if (GNUNET_YES == check_statistics_collect_completed()) |
2420 | { | 2435 | { |
2421 | //write_final_stats (); | 2436 | //write_final_stats (); |
2422 | GNUNET_free (stat_cls); | 2437 | GNUNET_free(stat_cls); |
2423 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2438 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2424 | "Shutting down\n"); | 2439 | "Shutting down\n"); |
2425 | GNUNET_SCHEDULER_shutdown (); | 2440 | GNUNET_SCHEDULER_shutdown(); |
2426 | } else { | 2441 | } |
2427 | GNUNET_free (stat_cls); | 2442 | else |
2428 | } | 2443 | { |
2444 | GNUNET_free(stat_cls); | ||
2445 | } | ||
2429 | } | 2446 | } |
2430 | 2447 | ||
2431 | /** | 2448 | /** |
@@ -2435,72 +2452,72 @@ post_test_shutdown_ready_cb (void *cls, | |||
2435 | * | 2452 | * |
2436 | * @return corresponding enum | 2453 | * @return corresponding enum |
2437 | */ | 2454 | */ |
2438 | enum STAT_TYPE stat_str_2_type (const char *stat_str) | 2455 | enum STAT_TYPE stat_str_2_type(const char *stat_str) |
2439 | { | 2456 | { |
2440 | if (0 == strncmp ("# rounds blocked - no pull replies", stat_str, strlen ("# rounds blocked - no pull replies"))) | 2457 | if (0 == strncmp("# rounds blocked - no pull replies", stat_str, strlen("# rounds blocked - no pull replies"))) |
2441 | { | 2458 | { |
2442 | return STAT_TYPE_BLOCKS_NO_PULL; | 2459 | return STAT_TYPE_BLOCKS_NO_PULL; |
2443 | } | 2460 | } |
2444 | else if (0 == strncmp ("# rounds blocked - too many pushes, no pull replies", stat_str, strlen ("# rounds blocked - too many pushes, no pull replies"))) | 2461 | else if (0 == strncmp("# rounds blocked - too many pushes, no pull replies", stat_str, strlen("# rounds blocked - too many pushes, no pull replies"))) |
2445 | { | 2462 | { |
2446 | return STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL; | 2463 | return STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL; |
2447 | } | 2464 | } |
2448 | else if (0 == strncmp ("# rounds blocked - too many pushes", stat_str, strlen ("# rounds blocked - too many pushes"))) | 2465 | else if (0 == strncmp("# rounds blocked - too many pushes", stat_str, strlen("# rounds blocked - too many pushes"))) |
2449 | { | 2466 | { |
2450 | return STAT_TYPE_BLOCKS_MANY_PUSH; | 2467 | return STAT_TYPE_BLOCKS_MANY_PUSH; |
2451 | } | 2468 | } |
2452 | else if (0 == strncmp ("# rounds blocked - no pushes, no pull replies", stat_str, strlen ("# rounds blocked - no pushes, no pull replies"))) | 2469 | else if (0 == strncmp("# rounds blocked - no pushes, no pull replies", stat_str, strlen("# rounds blocked - no pushes, no pull replies"))) |
2453 | { | 2470 | { |
2454 | return STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL; | 2471 | return STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL; |
2455 | } | 2472 | } |
2456 | else if (0 == strncmp ("# rounds blocked - no pushes", stat_str, strlen ("# rounds blocked - no pushes"))) | 2473 | else if (0 == strncmp("# rounds blocked - no pushes", stat_str, strlen("# rounds blocked - no pushes"))) |
2457 | { | 2474 | { |
2458 | return STAT_TYPE_BLOCKS_NO_PUSH; | 2475 | return STAT_TYPE_BLOCKS_NO_PUSH; |
2459 | } | 2476 | } |
2460 | else if (0 == strncmp ("# rounds blocked", stat_str, strlen ("# rounds blocked"))) | 2477 | else if (0 == strncmp("# rounds blocked", stat_str, strlen("# rounds blocked"))) |
2461 | { | 2478 | { |
2462 | return STAT_TYPE_BLOCKS; | 2479 | return STAT_TYPE_BLOCKS; |
2463 | } | 2480 | } |
2464 | else if (0 == strncmp ("# rounds", stat_str, strlen ("# rounds"))) | 2481 | else if (0 == strncmp("# rounds", stat_str, strlen("# rounds"))) |
2465 | { | 2482 | { |
2466 | return STAT_TYPE_ROUNDS; | 2483 | return STAT_TYPE_ROUNDS; |
2467 | } | 2484 | } |
2468 | else if (0 == strncmp ("# push send issued", stat_str, strlen ("# push send issued"))) | 2485 | else if (0 == strncmp("# push send issued", stat_str, strlen("# push send issued"))) |
2469 | { | 2486 | { |
2470 | return STAT_TYPE_ISSUED_PUSH_SEND; | 2487 | return STAT_TYPE_ISSUED_PUSH_SEND; |
2471 | } | 2488 | } |
2472 | else if (0 == strncmp ("# pull request send issued", stat_str, strlen ("# pull request send issued"))) | 2489 | else if (0 == strncmp("# pull request send issued", stat_str, strlen("# pull request send issued"))) |
2473 | { | 2490 | { |
2474 | return STAT_TYPE_ISSUED_PULL_REQ; | 2491 | return STAT_TYPE_ISSUED_PULL_REQ; |
2475 | } | 2492 | } |
2476 | else if (0 == strncmp ("# pull reply send issued", stat_str, strlen ("# pull reply send issued"))) | 2493 | else if (0 == strncmp("# pull reply send issued", stat_str, strlen("# pull reply send issued"))) |
2477 | { | 2494 | { |
2478 | return STAT_TYPE_ISSUED_PULL_REP; | 2495 | return STAT_TYPE_ISSUED_PULL_REP; |
2479 | } | 2496 | } |
2480 | else if (0 == strncmp ("# pushes sent", stat_str, strlen ("# pushes sent"))) | 2497 | else if (0 == strncmp("# pushes sent", stat_str, strlen("# pushes sent"))) |
2481 | { | 2498 | { |
2482 | return STAT_TYPE_SENT_PUSH_SEND; | 2499 | return STAT_TYPE_SENT_PUSH_SEND; |
2483 | } | 2500 | } |
2484 | else if (0 == strncmp ("# pull requests sent", stat_str, strlen ("# pull requests sent"))) | 2501 | else if (0 == strncmp("# pull requests sent", stat_str, strlen("# pull requests sent"))) |
2485 | { | 2502 | { |
2486 | return STAT_TYPE_SENT_PULL_REQ; | 2503 | return STAT_TYPE_SENT_PULL_REQ; |
2487 | } | 2504 | } |
2488 | else if (0 == strncmp ("# pull replys sent", stat_str, strlen ("# pull replys sent"))) | 2505 | else if (0 == strncmp("# pull replys sent", stat_str, strlen("# pull replys sent"))) |
2489 | { | 2506 | { |
2490 | return STAT_TYPE_SENT_PULL_REP; | 2507 | return STAT_TYPE_SENT_PULL_REP; |
2491 | } | 2508 | } |
2492 | else if (0 == strncmp ("# push message received", stat_str, strlen ("# push message received"))) | 2509 | else if (0 == strncmp("# push message received", stat_str, strlen("# push message received"))) |
2493 | { | 2510 | { |
2494 | return STAT_TYPE_RECV_PUSH_SEND; | 2511 | return STAT_TYPE_RECV_PUSH_SEND; |
2495 | } | 2512 | } |
2496 | else if (0 == strncmp ("# pull request message received", stat_str, strlen ("# pull request message received"))) | 2513 | else if (0 == strncmp("# pull request message received", stat_str, strlen("# pull request message received"))) |
2497 | { | 2514 | { |
2498 | return STAT_TYPE_RECV_PULL_REQ; | 2515 | return STAT_TYPE_RECV_PULL_REQ; |
2499 | } | 2516 | } |
2500 | else if (0 == strncmp ("# pull reply messages received", stat_str, strlen ("# pull reply messages received"))) | 2517 | else if (0 == strncmp("# pull reply messages received", stat_str, strlen("# pull reply messages received"))) |
2501 | { | 2518 | { |
2502 | return STAT_TYPE_RECV_PULL_REP; | 2519 | return STAT_TYPE_RECV_PULL_REP; |
2503 | } | 2520 | } |
2504 | return STAT_TYPE_MAX; | 2521 | return STAT_TYPE_MAX; |
2505 | } | 2522 | } |
2506 | 2523 | ||
@@ -2513,47 +2530,63 @@ enum STAT_TYPE stat_str_2_type (const char *stat_str) | |||
2513 | * | 2530 | * |
2514 | * @return string representation that matches statistics value | 2531 | * @return string representation that matches statistics value |
2515 | */ | 2532 | */ |
2516 | char* stat_type_2_str (enum STAT_TYPE stat_type) | 2533 | char* stat_type_2_str(enum STAT_TYPE stat_type) |
2517 | { | 2534 | { |
2518 | switch (stat_type) | 2535 | switch (stat_type) |
2519 | { | 2536 | { |
2520 | case STAT_TYPE_ROUNDS: | 2537 | case STAT_TYPE_ROUNDS: |
2521 | return "# rounds"; | 2538 | return "# rounds"; |
2539 | |||
2522 | case STAT_TYPE_BLOCKS: | 2540 | case STAT_TYPE_BLOCKS: |
2523 | return "# rounds blocked"; | 2541 | return "# rounds blocked"; |
2542 | |||
2524 | case STAT_TYPE_BLOCKS_MANY_PUSH: | 2543 | case STAT_TYPE_BLOCKS_MANY_PUSH: |
2525 | return "# rounds blocked - too many pushes"; | 2544 | return "# rounds blocked - too many pushes"; |
2545 | |||
2526 | case STAT_TYPE_BLOCKS_NO_PUSH: | 2546 | case STAT_TYPE_BLOCKS_NO_PUSH: |
2527 | return "# rounds blocked - no pushes"; | 2547 | return "# rounds blocked - no pushes"; |
2548 | |||
2528 | case STAT_TYPE_BLOCKS_NO_PULL: | 2549 | case STAT_TYPE_BLOCKS_NO_PULL: |
2529 | return "# rounds blocked - no pull replies"; | 2550 | return "# rounds blocked - no pull replies"; |
2551 | |||
2530 | case STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL: | 2552 | case STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL: |
2531 | return "# rounds blocked - too many pushes, no pull replies"; | 2553 | return "# rounds blocked - too many pushes, no pull replies"; |
2554 | |||
2532 | case STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL: | 2555 | case STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL: |
2533 | return "# rounds blocked - no pushes, no pull replies"; | 2556 | return "# rounds blocked - no pushes, no pull replies"; |
2557 | |||
2534 | case STAT_TYPE_ISSUED_PUSH_SEND: | 2558 | case STAT_TYPE_ISSUED_PUSH_SEND: |
2535 | return "# push send issued"; | 2559 | return "# push send issued"; |
2560 | |||
2536 | case STAT_TYPE_ISSUED_PULL_REQ: | 2561 | case STAT_TYPE_ISSUED_PULL_REQ: |
2537 | return "# pull request send issued"; | 2562 | return "# pull request send issued"; |
2563 | |||
2538 | case STAT_TYPE_ISSUED_PULL_REP: | 2564 | case STAT_TYPE_ISSUED_PULL_REP: |
2539 | return "# pull reply send issued"; | 2565 | return "# pull reply send issued"; |
2566 | |||
2540 | case STAT_TYPE_SENT_PUSH_SEND: | 2567 | case STAT_TYPE_SENT_PUSH_SEND: |
2541 | return "# pushes sent"; | 2568 | return "# pushes sent"; |
2569 | |||
2542 | case STAT_TYPE_SENT_PULL_REQ: | 2570 | case STAT_TYPE_SENT_PULL_REQ: |
2543 | return "# pull requests sent"; | 2571 | return "# pull requests sent"; |
2572 | |||
2544 | case STAT_TYPE_SENT_PULL_REP: | 2573 | case STAT_TYPE_SENT_PULL_REP: |
2545 | return "# pull replys sent"; | 2574 | return "# pull replys sent"; |
2575 | |||
2546 | case STAT_TYPE_RECV_PUSH_SEND: | 2576 | case STAT_TYPE_RECV_PUSH_SEND: |
2547 | return "# push message received"; | 2577 | return "# push message received"; |
2578 | |||
2548 | case STAT_TYPE_RECV_PULL_REQ: | 2579 | case STAT_TYPE_RECV_PULL_REQ: |
2549 | return "# pull request message received"; | 2580 | return "# pull request message received"; |
2581 | |||
2550 | case STAT_TYPE_RECV_PULL_REP: | 2582 | case STAT_TYPE_RECV_PULL_REP: |
2551 | return "# pull reply messages received"; | 2583 | return "# pull reply messages received"; |
2584 | |||
2552 | case STAT_TYPE_MAX: | 2585 | case STAT_TYPE_MAX: |
2553 | default: | 2586 | default: |
2554 | return "ERROR"; | 2587 | return "ERROR"; |
2555 | ; | 2588 | ; |
2556 | } | 2589 | } |
2557 | } | 2590 | } |
2558 | 2591 | ||
2559 | /** | 2592 | /** |
@@ -2567,125 +2600,141 @@ char* stat_type_2_str (enum STAT_TYPE stat_type) | |||
2567 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | 2600 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration |
2568 | */ | 2601 | */ |
2569 | int | 2602 | int |
2570 | stat_iterator (void *cls, | 2603 | stat_iterator(void *cls, |
2571 | const char *subsystem, | 2604 | const char *subsystem, |
2572 | const char *name, | 2605 | const char *name, |
2573 | uint64_t value, | 2606 | uint64_t value, |
2574 | int is_persistent) | 2607 | int is_persistent) |
2575 | { | 2608 | { |
2576 | (void) subsystem; | 2609 | (void)subsystem; |
2577 | (void) is_persistent; | 2610 | (void)is_persistent; |
2578 | const struct STATcls *stat_cls = (const struct STATcls *) cls; | 2611 | const struct STATcls *stat_cls = (const struct STATcls *)cls; |
2579 | struct RPSPeer *rps_peer = (struct RPSPeer *) stat_cls->rps_peer; | 2612 | struct RPSPeer *rps_peer = (struct RPSPeer *)stat_cls->rps_peer; |
2580 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %s - %" PRIu64 "\n", | 2613 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %s - %" PRIu64 "\n", |
2581 | //stat_type_2_str (stat_cls->stat_type), | 2614 | //stat_type_2_str (stat_cls->stat_type), |
2582 | name, | 2615 | name, |
2583 | value); | 2616 | value); |
2584 | to_file (rps_peer->file_name_stats, | 2617 | to_file(rps_peer->file_name_stats, |
2585 | "%s: %" PRIu64 "\n", | 2618 | "%s: %" PRIu64 "\n", |
2586 | name, | 2619 | name, |
2587 | value); | 2620 | value); |
2588 | switch (stat_str_2_type (name)) | 2621 | switch (stat_str_2_type(name)) |
2589 | { | 2622 | { |
2590 | case STAT_TYPE_ROUNDS: | 2623 | case STAT_TYPE_ROUNDS: |
2591 | rps_peer->num_rounds = value; | 2624 | rps_peer->num_rounds = value; |
2592 | break; | 2625 | break; |
2626 | |||
2593 | case STAT_TYPE_BLOCKS: | 2627 | case STAT_TYPE_BLOCKS: |
2594 | rps_peer->num_blocks = value; | 2628 | rps_peer->num_blocks = value; |
2595 | break; | 2629 | break; |
2630 | |||
2596 | case STAT_TYPE_BLOCKS_MANY_PUSH: | 2631 | case STAT_TYPE_BLOCKS_MANY_PUSH: |
2597 | rps_peer->num_blocks_many_push = value; | 2632 | rps_peer->num_blocks_many_push = value; |
2598 | break; | 2633 | break; |
2634 | |||
2599 | case STAT_TYPE_BLOCKS_NO_PUSH: | 2635 | case STAT_TYPE_BLOCKS_NO_PUSH: |
2600 | rps_peer->num_blocks_no_push = value; | 2636 | rps_peer->num_blocks_no_push = value; |
2601 | break; | 2637 | break; |
2638 | |||
2602 | case STAT_TYPE_BLOCKS_NO_PULL: | 2639 | case STAT_TYPE_BLOCKS_NO_PULL: |
2603 | rps_peer->num_blocks_no_pull = value; | 2640 | rps_peer->num_blocks_no_pull = value; |
2604 | break; | 2641 | break; |
2642 | |||
2605 | case STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL: | 2643 | case STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL: |
2606 | rps_peer->num_blocks_many_push_no_pull = value; | 2644 | rps_peer->num_blocks_many_push_no_pull = value; |
2607 | break; | 2645 | break; |
2646 | |||
2608 | case STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL: | 2647 | case STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL: |
2609 | rps_peer->num_blocks_no_push_no_pull = value; | 2648 | rps_peer->num_blocks_no_push_no_pull = value; |
2610 | break; | 2649 | break; |
2650 | |||
2611 | case STAT_TYPE_ISSUED_PUSH_SEND: | 2651 | case STAT_TYPE_ISSUED_PUSH_SEND: |
2612 | rps_peer->num_issued_push = value; | 2652 | rps_peer->num_issued_push = value; |
2613 | break; | 2653 | break; |
2654 | |||
2614 | case STAT_TYPE_ISSUED_PULL_REQ: | 2655 | case STAT_TYPE_ISSUED_PULL_REQ: |
2615 | rps_peer->num_issued_pull_req = value; | 2656 | rps_peer->num_issued_pull_req = value; |
2616 | break; | 2657 | break; |
2658 | |||
2617 | case STAT_TYPE_ISSUED_PULL_REP: | 2659 | case STAT_TYPE_ISSUED_PULL_REP: |
2618 | rps_peer->num_issued_pull_rep = value; | 2660 | rps_peer->num_issued_pull_rep = value; |
2619 | break; | 2661 | break; |
2662 | |||
2620 | case STAT_TYPE_SENT_PUSH_SEND: | 2663 | case STAT_TYPE_SENT_PUSH_SEND: |
2621 | rps_peer->num_sent_push = value; | 2664 | rps_peer->num_sent_push = value; |
2622 | break; | 2665 | break; |
2666 | |||
2623 | case STAT_TYPE_SENT_PULL_REQ: | 2667 | case STAT_TYPE_SENT_PULL_REQ: |
2624 | rps_peer->num_sent_pull_req = value; | 2668 | rps_peer->num_sent_pull_req = value; |
2625 | break; | 2669 | break; |
2670 | |||
2626 | case STAT_TYPE_SENT_PULL_REP: | 2671 | case STAT_TYPE_SENT_PULL_REP: |
2627 | rps_peer->num_sent_pull_rep = value; | 2672 | rps_peer->num_sent_pull_rep = value; |
2628 | break; | 2673 | break; |
2674 | |||
2629 | case STAT_TYPE_RECV_PUSH_SEND: | 2675 | case STAT_TYPE_RECV_PUSH_SEND: |
2630 | rps_peer->num_recv_push = value; | 2676 | rps_peer->num_recv_push = value; |
2631 | break; | 2677 | break; |
2678 | |||
2632 | case STAT_TYPE_RECV_PULL_REQ: | 2679 | case STAT_TYPE_RECV_PULL_REQ: |
2633 | rps_peer->num_recv_pull_req = value; | 2680 | rps_peer->num_recv_pull_req = value; |
2634 | break; | 2681 | break; |
2682 | |||
2635 | case STAT_TYPE_RECV_PULL_REP: | 2683 | case STAT_TYPE_RECV_PULL_REP: |
2636 | rps_peer->num_recv_pull_rep = value; | 2684 | rps_peer->num_recv_pull_rep = value; |
2637 | break; | 2685 | break; |
2686 | |||
2638 | case STAT_TYPE_MAX: | 2687 | case STAT_TYPE_MAX: |
2639 | default: | 2688 | default: |
2640 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2689 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2641 | "Unknown statistics string: %s\n", | 2690 | "Unknown statistics string: %s\n", |
2642 | name); | 2691 | name); |
2643 | break; | 2692 | break; |
2644 | } | 2693 | } |
2645 | return GNUNET_OK; | 2694 | return GNUNET_OK; |
2646 | } | 2695 | } |
2647 | 2696 | ||
2648 | void post_profiler (struct RPSPeer *rps_peer) | 2697 | void post_profiler(struct RPSPeer *rps_peer) |
2649 | { | 2698 | { |
2650 | if (COLLECT_STATISTICS != cur_test_run.have_collect_statistics) | 2699 | if (COLLECT_STATISTICS != cur_test_run.have_collect_statistics) |
2651 | { | 2700 | { |
2652 | return; | 2701 | return; |
2653 | } | 2702 | } |
2654 | 2703 | ||
2655 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2704 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2656 | "Going to request statistic values with mask 0x%" PRIx32 "\n", | 2705 | "Going to request statistic values with mask 0x%" PRIx32 "\n", |
2657 | cur_test_run.stat_collect_flags); | 2706 | cur_test_run.stat_collect_flags); |
2658 | 2707 | ||
2659 | struct STATcls *stat_cls; | 2708 | struct STATcls *stat_cls; |
2660 | uint32_t stat_type; | 2709 | uint32_t stat_type; |
2661 | for (stat_type = STAT_TYPE_ROUNDS; | 2710 | for (stat_type = STAT_TYPE_ROUNDS; |
2662 | stat_type < STAT_TYPE_MAX; | 2711 | stat_type < STAT_TYPE_MAX; |
2663 | stat_type = stat_type <<1) | 2712 | stat_type = stat_type << 1) |
2664 | { | 2713 | { |
2665 | if (stat_type & cur_test_run.stat_collect_flags) | 2714 | if (stat_type & cur_test_run.stat_collect_flags) |
2666 | { | 2715 | { |
2667 | stat_cls = GNUNET_malloc (sizeof (struct STATcls)); | 2716 | stat_cls = GNUNET_malloc(sizeof(struct STATcls)); |
2668 | stat_cls->rps_peer = rps_peer; | 2717 | stat_cls->rps_peer = rps_peer; |
2669 | stat_cls->stat_type = stat_type; | 2718 | stat_cls->stat_type = stat_type; |
2670 | rps_peer->file_name_stats = | 2719 | rps_peer->file_name_stats = |
2671 | store_prefix_file_name (rps_peer->peer_id, "stats"); | 2720 | store_prefix_file_name(rps_peer->peer_id, "stats"); |
2672 | GNUNET_STATISTICS_get (rps_peer->stats_h, | 2721 | GNUNET_STATISTICS_get(rps_peer->stats_h, |
2673 | "rps", | 2722 | "rps", |
2674 | stat_type_2_str (stat_type), | 2723 | stat_type_2_str(stat_type), |
2675 | post_test_shutdown_ready_cb, | 2724 | post_test_shutdown_ready_cb, |
2676 | stat_iterator, | 2725 | stat_iterator, |
2677 | (struct STATcls *) stat_cls); | 2726 | (struct STATcls *)stat_cls); |
2678 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2727 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2679 | "Requested statistics for %s (peer %" PRIu32 ")\n", | 2728 | "Requested statistics for %s (peer %" PRIu32 ")\n", |
2680 | stat_type_2_str (stat_type), | 2729 | stat_type_2_str(stat_type), |
2681 | rps_peer->index); | 2730 | rps_peer->index); |
2682 | } | 2731 | } |
2683 | } | 2732 | } |
2684 | } | 2733 | } |
2685 | 2734 | ||
2686 | 2735 | ||
2687 | /*********************************************************************** | 2736 | /*********************************************************************** |
2688 | * /Definition of tests | 2737 | * /Definition of tests |
2689 | ***********************************************************************/ | 2738 | ***********************************************************************/ |
2690 | 2739 | ||
2691 | 2740 | ||
@@ -2702,92 +2751,92 @@ void post_profiler (struct RPSPeer *rps_peer) | |||
2702 | * failed | 2751 | * failed |
2703 | */ | 2752 | */ |
2704 | static void | 2753 | static void |
2705 | run (void *cls, | 2754 | run(void *cls, |
2706 | struct GNUNET_TESTBED_RunHandle *h, | 2755 | struct GNUNET_TESTBED_RunHandle *h, |
2707 | unsigned int n_peers, | 2756 | unsigned int n_peers, |
2708 | struct GNUNET_TESTBED_Peer **peers, | 2757 | struct GNUNET_TESTBED_Peer **peers, |
2709 | unsigned int links_succeeded, | 2758 | unsigned int links_succeeded, |
2710 | unsigned int links_failed) | 2759 | unsigned int links_failed) |
2711 | { | 2760 | { |
2712 | (void) cls; | 2761 | (void)cls; |
2713 | (void) h; | 2762 | (void)h; |
2714 | (void) links_failed; | 2763 | (void)links_failed; |
2715 | unsigned int i; | 2764 | unsigned int i; |
2716 | struct OpListEntry *entry; | 2765 | struct OpListEntry *entry; |
2717 | 2766 | ||
2718 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "RUN was called\n"); | 2767 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "RUN was called\n"); |
2719 | 2768 | ||
2720 | /* Check whether we timed out */ | 2769 | /* Check whether we timed out */ |
2721 | if (n_peers != num_peers || | 2770 | if (n_peers != num_peers || |
2722 | NULL == peers || | 2771 | NULL == peers || |
2723 | 0 == links_succeeded) | 2772 | 0 == links_succeeded) |
2724 | { | 2773 | { |
2725 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Going down due to args (eg. timeout)\n"); | 2774 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Going down due to args (eg. timeout)\n"); |
2726 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tn_peers: %u\n", n_peers); | 2775 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tn_peers: %u\n", n_peers); |
2727 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tnum_peers: %" PRIu32 "\n", num_peers); | 2776 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tnum_peers: %" PRIu32 "\n", num_peers); |
2728 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tpeers: %p\n", peers); | 2777 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tpeers: %p\n", peers); |
2729 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tlinks_succeeded: %u\n", links_succeeded); | 2778 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tlinks_succeeded: %u\n", links_succeeded); |
2730 | GNUNET_SCHEDULER_shutdown (); | 2779 | GNUNET_SCHEDULER_shutdown(); |
2731 | return; | 2780 | return; |
2732 | } | 2781 | } |
2733 | 2782 | ||
2734 | 2783 | ||
2735 | /* Initialize peers */ | 2784 | /* Initialize peers */ |
2736 | testbed_peers = peers; | 2785 | testbed_peers = peers; |
2737 | num_peers_online = 0; | 2786 | num_peers_online = 0; |
2738 | for (i = 0; i < num_peers; i++) | 2787 | for (i = 0; i < num_peers; i++) |
2739 | { | 2788 | { |
2740 | entry = make_oplist_entry (); | 2789 | entry = make_oplist_entry(); |
2741 | entry->index = i; | 2790 | entry->index = i; |
2742 | rps_peers[i].index = i; | 2791 | rps_peers[i].index = i; |
2743 | if (NULL != cur_test_run.init_peer) | 2792 | if (NULL != cur_test_run.init_peer) |
2744 | cur_test_run.init_peer (&rps_peers[i]); | 2793 | cur_test_run.init_peer(&rps_peers[i]); |
2745 | if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) | 2794 | if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) |
2746 | { | 2795 | { |
2747 | rps_peers->cur_view_count = 0; | 2796 | rps_peers->cur_view_count = 0; |
2748 | rps_peers->cur_view = NULL; | 2797 | rps_peers->cur_view = NULL; |
2749 | } | 2798 | } |
2750 | entry->op = GNUNET_TESTBED_peer_get_information (peers[i], | 2799 | entry->op = GNUNET_TESTBED_peer_get_information(peers[i], |
2751 | GNUNET_TESTBED_PIT_IDENTITY, | 2800 | GNUNET_TESTBED_PIT_IDENTITY, |
2752 | &info_cb, | 2801 | &info_cb, |
2753 | entry); | 2802 | entry); |
2754 | } | 2803 | } |
2755 | 2804 | ||
2756 | /* Bring peers up */ | 2805 | /* Bring peers up */ |
2757 | GNUNET_assert (num_peers == n_peers); | 2806 | GNUNET_assert(num_peers == n_peers); |
2758 | for (i = 0; i < n_peers; i++) | 2807 | for (i = 0; i < n_peers; i++) |
2759 | { | 2808 | { |
2760 | rps_peers[i].index = i; | 2809 | rps_peers[i].index = i; |
2761 | rps_peers[i].op = | 2810 | rps_peers[i].op = |
2762 | GNUNET_TESTBED_service_connect (&rps_peers[i], | 2811 | GNUNET_TESTBED_service_connect(&rps_peers[i], |
2763 | peers[i], | 2812 | peers[i], |
2764 | "rps", | 2813 | "rps", |
2765 | &rps_connect_complete_cb, | 2814 | &rps_connect_complete_cb, |
2766 | &rps_peers[i], | 2815 | &rps_peers[i], |
2767 | &rps_connect_adapter, | 2816 | &rps_connect_adapter, |
2768 | &rps_disconnect_adapter, | 2817 | &rps_disconnect_adapter, |
2769 | &rps_peers[i]); | 2818 | &rps_peers[i]); |
2770 | /* Connect all peers to statistics service */ | 2819 | /* Connect all peers to statistics service */ |
2771 | if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics) | 2820 | if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics) |
2772 | { | 2821 | { |
2773 | rps_peers[i].stat_op = | 2822 | rps_peers[i].stat_op = |
2774 | GNUNET_TESTBED_service_connect (NULL, | 2823 | GNUNET_TESTBED_service_connect(NULL, |
2775 | peers[i], | 2824 | peers[i], |
2776 | "statistics", | 2825 | "statistics", |
2777 | stat_complete_cb, | 2826 | stat_complete_cb, |
2778 | &rps_peers[i], | 2827 | &rps_peers[i], |
2779 | &stat_connect_adapter, | 2828 | &stat_connect_adapter, |
2780 | &stat_disconnect_adapter, | 2829 | &stat_disconnect_adapter, |
2781 | &rps_peers[i]); | 2830 | &rps_peers[i]); |
2782 | } | 2831 | } |
2783 | } | 2832 | } |
2784 | 2833 | ||
2785 | if (NULL != churn_task) | 2834 | if (NULL != churn_task) |
2786 | GNUNET_SCHEDULER_cancel (churn_task); | 2835 | GNUNET_SCHEDULER_cancel(churn_task); |
2787 | post_test_task = GNUNET_SCHEDULER_add_delayed (timeout, &post_test_op, NULL); | 2836 | post_test_task = GNUNET_SCHEDULER_add_delayed(timeout, &post_test_op, NULL); |
2788 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 2837 | timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
2789 | (timeout_s * 1.2) + 0.1 * num_peers); | 2838 | (timeout_s * 1.2) + 0.1 * num_peers); |
2790 | shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL); | 2839 | shutdown_task = GNUNET_SCHEDULER_add_delayed(timeout, &shutdown_op, NULL); |
2791 | } | 2840 | } |
2792 | 2841 | ||
2793 | 2842 | ||
@@ -2799,10 +2848,11 @@ run (void *cls, | |||
2799 | * @return 0 on success | 2848 | * @return 0 on success |
2800 | */ | 2849 | */ |
2801 | int | 2850 | int |
2802 | main (int argc, char *argv[]) | 2851 | main(int argc, char *argv[]) |
2803 | { | 2852 | { |
2804 | int ret_value; | 2853 | int ret_value; |
2805 | (void) argc; | 2854 | |
2855 | (void)argc; | ||
2806 | 2856 | ||
2807 | /* Defaults for tests */ | 2857 | /* Defaults for tests */ |
2808 | num_peers = 5; | 2858 | num_peers = 5; |
@@ -2819,174 +2869,174 @@ main (int argc, char *argv[]) | |||
2819 | churn_task = NULL; | 2869 | churn_task = NULL; |
2820 | timeout_s = 30; | 2870 | timeout_s = 30; |
2821 | 2871 | ||
2822 | if (strstr (argv[0], "malicious") != NULL) | 2872 | if (strstr(argv[0], "malicious") != NULL) |
2823 | { | 2873 | { |
2824 | cur_test_run.pre_test = mal_pre; | 2874 | cur_test_run.pre_test = mal_pre; |
2825 | cur_test_run.main_test = mal_cb; | 2875 | cur_test_run.main_test = mal_cb; |
2826 | cur_test_run.init_peer = mal_init_peer; | 2876 | cur_test_run.init_peer = mal_init_peer; |
2827 | timeout_s = 40; | 2877 | timeout_s = 40; |
2878 | |||
2879 | if (strstr(argv[0], "_1") != NULL) | ||
2880 | { | ||
2881 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 1\n"); | ||
2882 | cur_test_run.name = "test-rps-malicious_1"; | ||
2883 | mal_type = 1; | ||
2884 | } | ||
2885 | else if (strstr(argv[0], "_2") != NULL) | ||
2886 | { | ||
2887 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 2\n"); | ||
2888 | cur_test_run.name = "test-rps-malicious_2"; | ||
2889 | mal_type = 2; | ||
2890 | } | ||
2891 | else if (strstr(argv[0], "_3") != NULL) | ||
2892 | { | ||
2893 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 3\n"); | ||
2894 | cur_test_run.name = "test-rps-malicious_3"; | ||
2895 | mal_type = 3; | ||
2896 | } | ||
2897 | } | ||
2898 | |||
2899 | else if (strstr(argv[0], "_single_req") != NULL) | ||
2900 | { | ||
2901 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Test single request\n"); | ||
2902 | cur_test_run.name = "test-rps-single-req"; | ||
2903 | cur_test_run.main_test = single_req_cb; | ||
2904 | cur_test_run.have_churn = HAVE_NO_CHURN; | ||
2905 | } | ||
2906 | |||
2907 | else if (strstr(argv[0], "_delayed_reqs") != NULL) | ||
2908 | { | ||
2909 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test delayed requests\n"); | ||
2910 | cur_test_run.name = "test-rps-delayed-reqs"; | ||
2911 | cur_test_run.main_test = delay_req_cb; | ||
2912 | cur_test_run.have_churn = HAVE_NO_CHURN; | ||
2913 | } | ||
2914 | |||
2915 | else if (strstr(argv[0], "_seed_big") != NULL) | ||
2916 | { | ||
2917 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test seeding (num_peers > GNUNET_MAX_MESSAGE_SIZE)\n"); | ||
2918 | num_peers = 1; | ||
2919 | cur_test_run.name = "test-rps-seed-big"; | ||
2920 | cur_test_run.main_test = seed_big_cb; | ||
2921 | cur_test_run.eval_cb = no_eval; | ||
2922 | cur_test_run.have_churn = HAVE_NO_CHURN; | ||
2923 | timeout_s = 10; | ||
2924 | } | ||
2925 | |||
2926 | else if (strstr(argv[0], "_single_peer_seed") != NULL) | ||
2927 | { | ||
2928 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on a single peer\n"); | ||
2929 | cur_test_run.name = "test-rps-single-peer-seed"; | ||
2930 | cur_test_run.main_test = single_peer_seed_cb; | ||
2931 | cur_test_run.have_churn = HAVE_NO_CHURN; | ||
2932 | } | ||
2933 | |||
2934 | else if (strstr(argv[0], "_seed_request") != NULL) | ||
2935 | { | ||
2936 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on multiple peers\n"); | ||
2937 | cur_test_run.name = "test-rps-seed-request"; | ||
2938 | cur_test_run.main_test = seed_req_cb; | ||
2939 | cur_test_run.have_churn = HAVE_NO_CHURN; | ||
2940 | } | ||
2941 | |||
2942 | else if (strstr(argv[0], "_seed") != NULL) | ||
2943 | { | ||
2944 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test seeding\n"); | ||
2945 | cur_test_run.name = "test-rps-seed"; | ||
2946 | cur_test_run.main_test = seed_cb; | ||
2947 | cur_test_run.eval_cb = no_eval; | ||
2948 | cur_test_run.have_churn = HAVE_NO_CHURN; | ||
2949 | } | ||
2950 | |||
2951 | else if (strstr(argv[0], "_req_cancel") != NULL) | ||
2952 | { | ||
2953 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test cancelling a request\n"); | ||
2954 | cur_test_run.name = "test-rps-req-cancel"; | ||
2955 | num_peers = 1; | ||
2956 | cur_test_run.main_test = req_cancel_cb; | ||
2957 | cur_test_run.eval_cb = no_eval; | ||
2958 | cur_test_run.have_churn = HAVE_NO_CHURN; | ||
2959 | timeout_s = 10; | ||
2960 | } | ||
2828 | 2961 | ||
2829 | if (strstr (argv[0], "_1") != NULL) | 2962 | else if (strstr(argv[0], "_churn") != NULL) |
2830 | { | 2963 | { |
2831 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 1\n"); | 2964 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test churn\n"); |
2832 | cur_test_run.name = "test-rps-malicious_1"; | 2965 | cur_test_run.name = "test-rps-churn"; |
2833 | mal_type = 1; | 2966 | num_peers = 5; |
2967 | cur_test_run.init_peer = default_init_peer; | ||
2968 | cur_test_run.main_test = churn_test_cb; | ||
2969 | cur_test_run.reply_handle = default_reply_handle; | ||
2970 | cur_test_run.eval_cb = default_eval_cb; | ||
2971 | cur_test_run.have_churn = HAVE_NO_CHURN; | ||
2972 | cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT; | ||
2973 | timeout_s = 40; | ||
2834 | } | 2974 | } |
2835 | else if (strstr (argv[0], "_2") != NULL) | 2975 | |
2976 | else if (strstr(argv[0], "_sub") != NULL) | ||
2836 | { | 2977 | { |
2837 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 2\n"); | 2978 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test subs\n"); |
2838 | cur_test_run.name = "test-rps-malicious_2"; | 2979 | cur_test_run.name = "test-rps-sub"; |
2839 | mal_type = 2; | 2980 | num_peers = 5; |
2981 | //cur_test_run.init_peer = &default_init_peer; | ||
2982 | cur_test_run.pre_test = &sub_pre; | ||
2983 | cur_test_run.main_test = &single_req_cb; | ||
2984 | //cur_test_run.reply_handle = default_reply_handle; | ||
2985 | cur_test_run.post_test = &sub_post; | ||
2986 | //cur_test_run.eval_cb = default_eval_cb; | ||
2987 | cur_test_run.have_churn = HAVE_NO_CHURN; | ||
2988 | cur_test_run.have_quick_quit = HAVE_QUICK_QUIT; | ||
2840 | } | 2989 | } |
2841 | else if (strstr (argv[0], "_3") != NULL) | 2990 | |
2991 | else if (strstr(argv[0], "profiler") != NULL) | ||
2842 | { | 2992 | { |
2843 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 3\n"); | 2993 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n"); |
2844 | cur_test_run.name = "test-rps-malicious_3"; | 2994 | cur_test_run.name = "test-rps-profiler"; |
2995 | num_peers = 16; | ||
2845 | mal_type = 3; | 2996 | mal_type = 3; |
2997 | cur_test_run.init_peer = profiler_init_peer; | ||
2998 | //cur_test_run.pre_test = mal_pre; | ||
2999 | cur_test_run.pre_test = pre_profiler; | ||
3000 | cur_test_run.main_test = profiler_cb; | ||
3001 | cur_test_run.reply_handle = profiler_reply_handle; | ||
3002 | cur_test_run.eval_cb = profiler_eval; | ||
3003 | cur_test_run.post_test = post_profiler; | ||
3004 | cur_test_run.request_interval = 2; | ||
3005 | cur_test_run.num_requests = 5; | ||
3006 | //cur_test_run.have_churn = HAVE_CHURN; | ||
3007 | cur_test_run.have_churn = HAVE_NO_CHURN; | ||
3008 | cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT; | ||
3009 | cur_test_run.have_collect_statistics = COLLECT_STATISTICS; | ||
3010 | cur_test_run.stat_collect_flags = STAT_TYPE_ROUNDS | | ||
3011 | STAT_TYPE_BLOCKS | | ||
3012 | STAT_TYPE_BLOCKS_MANY_PUSH | | ||
3013 | STAT_TYPE_BLOCKS_NO_PUSH | | ||
3014 | STAT_TYPE_BLOCKS_NO_PULL | | ||
3015 | STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL | | ||
3016 | STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL | | ||
3017 | STAT_TYPE_ISSUED_PUSH_SEND | | ||
3018 | STAT_TYPE_ISSUED_PULL_REQ | | ||
3019 | STAT_TYPE_ISSUED_PULL_REP | | ||
3020 | STAT_TYPE_SENT_PUSH_SEND | | ||
3021 | STAT_TYPE_SENT_PULL_REQ | | ||
3022 | STAT_TYPE_SENT_PULL_REP | | ||
3023 | STAT_TYPE_RECV_PUSH_SEND | | ||
3024 | STAT_TYPE_RECV_PULL_REQ | | ||
3025 | STAT_TYPE_RECV_PULL_REP; | ||
3026 | cur_test_run.have_collect_view = COLLECT_VIEW; | ||
3027 | timeout_s = 150; | ||
3028 | |||
3029 | /* 'Clean' directory */ | ||
3030 | (void)GNUNET_DISK_directory_remove("/tmp/rps/"); | ||
3031 | GNUNET_DISK_directory_create("/tmp/rps/"); | ||
2846 | } | 3032 | } |
2847 | } | 3033 | timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, timeout_s); |
2848 | 3034 | ||
2849 | else if (strstr (argv[0], "_single_req") != NULL) | 3035 | rps_peers = GNUNET_new_array(num_peers, struct RPSPeer); |
2850 | { | 3036 | peer_map = GNUNET_CONTAINER_multipeermap_create(num_peers, GNUNET_NO); |
2851 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test single request\n"); | 3037 | rps_peer_ids = GNUNET_new_array(num_peers, struct GNUNET_PeerIdentity); |
2852 | cur_test_run.name = "test-rps-single-req"; | 3038 | if ((2 == mal_type) || |
2853 | cur_test_run.main_test = single_req_cb; | 3039 | (3 == mal_type)) |
2854 | cur_test_run.have_churn = HAVE_NO_CHURN; | ||
2855 | } | ||
2856 | |||
2857 | else if (strstr (argv[0], "_delayed_reqs") != NULL) | ||
2858 | { | ||
2859 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test delayed requests\n"); | ||
2860 | cur_test_run.name = "test-rps-delayed-reqs"; | ||
2861 | cur_test_run.main_test = delay_req_cb; | ||
2862 | cur_test_run.have_churn = HAVE_NO_CHURN; | ||
2863 | } | ||
2864 | |||
2865 | else if (strstr (argv[0], "_seed_big") != NULL) | ||
2866 | { | ||
2867 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding (num_peers > GNUNET_MAX_MESSAGE_SIZE)\n"); | ||
2868 | num_peers = 1; | ||
2869 | cur_test_run.name = "test-rps-seed-big"; | ||
2870 | cur_test_run.main_test = seed_big_cb; | ||
2871 | cur_test_run.eval_cb = no_eval; | ||
2872 | cur_test_run.have_churn = HAVE_NO_CHURN; | ||
2873 | timeout_s = 10; | ||
2874 | } | ||
2875 | |||
2876 | else if (strstr (argv[0], "_single_peer_seed") != NULL) | ||
2877 | { | ||
2878 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on a single peer\n"); | ||
2879 | cur_test_run.name = "test-rps-single-peer-seed"; | ||
2880 | cur_test_run.main_test = single_peer_seed_cb; | ||
2881 | cur_test_run.have_churn = HAVE_NO_CHURN; | ||
2882 | } | ||
2883 | |||
2884 | else if (strstr (argv[0], "_seed_request") != NULL) | ||
2885 | { | ||
2886 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding and requesting on multiple peers\n"); | ||
2887 | cur_test_run.name = "test-rps-seed-request"; | ||
2888 | cur_test_run.main_test = seed_req_cb; | ||
2889 | cur_test_run.have_churn = HAVE_NO_CHURN; | ||
2890 | } | ||
2891 | |||
2892 | else if (strstr (argv[0], "_seed") != NULL) | ||
2893 | { | ||
2894 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding\n"); | ||
2895 | cur_test_run.name = "test-rps-seed"; | ||
2896 | cur_test_run.main_test = seed_cb; | ||
2897 | cur_test_run.eval_cb = no_eval; | ||
2898 | cur_test_run.have_churn = HAVE_NO_CHURN; | ||
2899 | } | ||
2900 | |||
2901 | else if (strstr (argv[0], "_req_cancel") != NULL) | ||
2902 | { | ||
2903 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test cancelling a request\n"); | ||
2904 | cur_test_run.name = "test-rps-req-cancel"; | ||
2905 | num_peers = 1; | ||
2906 | cur_test_run.main_test = req_cancel_cb; | ||
2907 | cur_test_run.eval_cb = no_eval; | ||
2908 | cur_test_run.have_churn = HAVE_NO_CHURN; | ||
2909 | timeout_s = 10; | ||
2910 | } | ||
2911 | |||
2912 | else if (strstr (argv[0], "_churn") != NULL) | ||
2913 | { | ||
2914 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test churn\n"); | ||
2915 | cur_test_run.name = "test-rps-churn"; | ||
2916 | num_peers = 5; | ||
2917 | cur_test_run.init_peer = default_init_peer; | ||
2918 | cur_test_run.main_test = churn_test_cb; | ||
2919 | cur_test_run.reply_handle = default_reply_handle; | ||
2920 | cur_test_run.eval_cb = default_eval_cb; | ||
2921 | cur_test_run.have_churn = HAVE_NO_CHURN; | ||
2922 | cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT; | ||
2923 | timeout_s = 40; | ||
2924 | } | ||
2925 | |||
2926 | else if (strstr (argv[0], "_sub") != NULL) | ||
2927 | { | ||
2928 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test subs\n"); | ||
2929 | cur_test_run.name = "test-rps-sub"; | ||
2930 | num_peers = 5; | ||
2931 | //cur_test_run.init_peer = &default_init_peer; | ||
2932 | cur_test_run.pre_test = &sub_pre; | ||
2933 | cur_test_run.main_test = &single_req_cb; | ||
2934 | //cur_test_run.reply_handle = default_reply_handle; | ||
2935 | cur_test_run.post_test = &sub_post; | ||
2936 | //cur_test_run.eval_cb = default_eval_cb; | ||
2937 | cur_test_run.have_churn = HAVE_NO_CHURN; | ||
2938 | cur_test_run.have_quick_quit = HAVE_QUICK_QUIT; | ||
2939 | } | ||
2940 | |||
2941 | else if (strstr (argv[0], "profiler") != NULL) | ||
2942 | { | ||
2943 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n"); | ||
2944 | cur_test_run.name = "test-rps-profiler"; | ||
2945 | num_peers = 16; | ||
2946 | mal_type = 3; | ||
2947 | cur_test_run.init_peer = profiler_init_peer; | ||
2948 | //cur_test_run.pre_test = mal_pre; | ||
2949 | cur_test_run.pre_test = pre_profiler; | ||
2950 | cur_test_run.main_test = profiler_cb; | ||
2951 | cur_test_run.reply_handle = profiler_reply_handle; | ||
2952 | cur_test_run.eval_cb = profiler_eval; | ||
2953 | cur_test_run.post_test = post_profiler; | ||
2954 | cur_test_run.request_interval = 2; | ||
2955 | cur_test_run.num_requests = 5; | ||
2956 | //cur_test_run.have_churn = HAVE_CHURN; | ||
2957 | cur_test_run.have_churn = HAVE_NO_CHURN; | ||
2958 | cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT; | ||
2959 | cur_test_run.have_collect_statistics = COLLECT_STATISTICS; | ||
2960 | cur_test_run.stat_collect_flags = STAT_TYPE_ROUNDS | | ||
2961 | STAT_TYPE_BLOCKS | | ||
2962 | STAT_TYPE_BLOCKS_MANY_PUSH | | ||
2963 | STAT_TYPE_BLOCKS_NO_PUSH | | ||
2964 | STAT_TYPE_BLOCKS_NO_PULL | | ||
2965 | STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL | | ||
2966 | STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL | | ||
2967 | STAT_TYPE_ISSUED_PUSH_SEND | | ||
2968 | STAT_TYPE_ISSUED_PULL_REQ | | ||
2969 | STAT_TYPE_ISSUED_PULL_REP | | ||
2970 | STAT_TYPE_SENT_PUSH_SEND | | ||
2971 | STAT_TYPE_SENT_PULL_REQ | | ||
2972 | STAT_TYPE_SENT_PULL_REP | | ||
2973 | STAT_TYPE_RECV_PUSH_SEND | | ||
2974 | STAT_TYPE_RECV_PULL_REQ | | ||
2975 | STAT_TYPE_RECV_PULL_REP; | ||
2976 | cur_test_run.have_collect_view = COLLECT_VIEW; | ||
2977 | timeout_s = 150; | ||
2978 | |||
2979 | /* 'Clean' directory */ | ||
2980 | (void) GNUNET_DISK_directory_remove ("/tmp/rps/"); | ||
2981 | GNUNET_DISK_directory_create ("/tmp/rps/"); | ||
2982 | } | ||
2983 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_s); | ||
2984 | |||
2985 | rps_peers = GNUNET_new_array (num_peers, struct RPSPeer); | ||
2986 | peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO); | ||
2987 | rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity); | ||
2988 | if ( (2 == mal_type) || | ||
2989 | (3 == mal_type)) | ||
2990 | target_peer = &rps_peer_ids[num_peers - 2]; | 3040 | target_peer = &rps_peer_ids[num_peers - 2]; |
2991 | if (profiler_eval == cur_test_run.eval_cb) | 3041 | if (profiler_eval == cur_test_run.eval_cb) |
2992 | eval_peer = &rps_peers[num_peers - 1]; /* FIXME: eval_peer could be a | 3042 | eval_peer = &rps_peers[num_peers - 1]; /* FIXME: eval_peer could be a |
@@ -2994,30 +3044,30 @@ main (int argc, char *argv[]) | |||
2994 | with the malicious portion */ | 3044 | with the malicious portion */ |
2995 | 3045 | ||
2996 | ok = 1; | 3046 | ok = 1; |
2997 | ret_value = GNUNET_TESTBED_test_run (cur_test_run.name, | 3047 | ret_value = GNUNET_TESTBED_test_run(cur_test_run.name, |
2998 | "test_rps.conf", | 3048 | "test_rps.conf", |
2999 | num_peers, | 3049 | num_peers, |
3000 | 0, NULL, NULL, | 3050 | 0, NULL, NULL, |
3001 | &run, NULL); | 3051 | &run, NULL); |
3002 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3052 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
3003 | "_test_run returned.\n"); | 3053 | "_test_run returned.\n"); |
3004 | if (GNUNET_OK != ret_value) | 3054 | if (GNUNET_OK != ret_value) |
3005 | { | 3055 | { |
3006 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3056 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
3007 | "Test did not run successfully!\n"); | 3057 | "Test did not run successfully!\n"); |
3008 | } | 3058 | } |
3009 | 3059 | ||
3010 | ret_value = cur_test_run.eval_cb(); | 3060 | ret_value = cur_test_run.eval_cb(); |
3011 | 3061 | ||
3012 | if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) | 3062 | if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) |
3013 | { | 3063 | { |
3014 | GNUNET_array_grow (rps_peers->cur_view, | 3064 | GNUNET_array_grow(rps_peers->cur_view, |
3015 | rps_peers->cur_view_count, | 3065 | rps_peers->cur_view_count, |
3016 | 0); | 3066 | 0); |
3017 | } | 3067 | } |
3018 | GNUNET_free (rps_peers); | 3068 | GNUNET_free(rps_peers); |
3019 | GNUNET_free (rps_peer_ids); | 3069 | GNUNET_free(rps_peer_ids); |
3020 | GNUNET_CONTAINER_multipeermap_destroy (peer_map); | 3070 | GNUNET_CONTAINER_multipeermap_destroy(peer_map); |
3021 | return ret_value; | 3071 | return ret_value; |
3022 | } | 3072 | } |
3023 | 3073 | ||
diff --git a/src/rps/test_rps_api.c b/src/rps/test_rps_api.c index c0ebac6c4..97dccd789 100644 --- a/src/rps/test_rps_api.c +++ b/src/rps/test_rps_api.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file rps/test_rps_api.c | 21 | * @file rps/test_rps_api.c |
22 | * @brief testcase for rps_api.c | 22 | * @brief testcase for rps_api.c |
@@ -30,55 +30,56 @@ static int ok = 1; | |||
30 | 30 | ||
31 | 31 | ||
32 | static void | 32 | static void |
33 | run (void *cls, | 33 | run(void *cls, |
34 | char *const *args, | 34 | char *const *args, |
35 | const char *cfgfile, | 35 | const char *cfgfile, |
36 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 36 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
37 | { | 37 | { |
38 | ok = 0; | 38 | ok = 0; |
39 | } | 39 | } |
40 | 40 | ||
41 | 41 | ||
42 | static int | 42 | static int |
43 | check () | 43 | check() |
44 | { | 44 | { |
45 | char *const argv[] = { "test-rps-api", NULL }; | 45 | char *const argv[] = { "test-rps-api", NULL }; |
46 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 46 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
47 | GNUNET_GETOPT_OPTION_END | 47 | GNUNET_GETOPT_OPTION_END |
48 | }; | 48 | }; |
49 | struct GNUNET_OS_Process *proc; | 49 | struct GNUNET_OS_Process *proc; |
50 | char *path = GNUNET_OS_get_libexec_binary_path ( "gnunet-service-rps"); | 50 | char *path = GNUNET_OS_get_libexec_binary_path("gnunet-service-rps"); |
51 | |||
51 | if (NULL == path) | 52 | if (NULL == path) |
52 | { | ||
53 | fprintf (stderr, "Service executable not found `%s'\n", "gnunet-service-rps"); | ||
54 | return; | ||
55 | } | ||
56 | |||
57 | proc = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL, | ||
58 | NULL, NULL, path, "gnunet-service-rps", NULL); | ||
59 | |||
60 | GNUNET_free (path); | ||
61 | GNUNET_assert (NULL != proc); | ||
62 | GNUNET_PROGRAM_run (1, argv, "test-rps-api", "nohelp", | ||
63 | options, &run, &ok); | ||
64 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | ||
65 | { | 53 | { |
66 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 54 | fprintf(stderr, "Service executable not found `%s'\n", "gnunet-service-rps"); |
55 | return; | ||
56 | } | ||
57 | |||
58 | proc = GNUNET_OS_start_process(GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL, | ||
59 | NULL, NULL, path, "gnunet-service-rps", NULL); | ||
60 | |||
61 | GNUNET_free(path); | ||
62 | GNUNET_assert(NULL != proc); | ||
63 | GNUNET_PROGRAM_run(1, argv, "test-rps-api", "nohelp", | ||
64 | options, &run, &ok); | ||
65 | if (0 != GNUNET_OS_process_kill(proc, SIGTERM)) | ||
66 | { | ||
67 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
67 | ok = 1; | 68 | ok = 1; |
68 | } | 69 | } |
69 | GNUNET_OS_process_wait (proc); | 70 | GNUNET_OS_process_wait(proc); |
70 | GNUNET_OS_process_destroy (proc); | 71 | GNUNET_OS_process_destroy(proc); |
71 | return ok; | 72 | return ok; |
72 | } | 73 | } |
73 | 74 | ||
74 | 75 | ||
75 | int | 76 | int |
76 | main (int argc, char *argv[]) | 77 | main(int argc, char *argv[]) |
77 | { | 78 | { |
78 | GNUNET_log_setup ("test_statistics_api", | 79 | GNUNET_log_setup("test_statistics_api", |
79 | "WARNING", | 80 | "WARNING", |
80 | NULL); | 81 | NULL); |
81 | return check (); | 82 | return check(); |
82 | } | 83 | } |
83 | 84 | ||
84 | /* end of test_rps_api.c */ | 85 | /* end of test_rps_api.c */ |
diff --git a/src/rps/test_service_rps_custommap.c b/src/rps/test_service_rps_custommap.c index d2061d4ec..796c46d30 100644 --- a/src/rps/test_service_rps_custommap.c +++ b/src/rps/test_service_rps_custommap.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file rps/test_service_rps_custommap.c | 21 | * @file rps/test_service_rps_custommap.c |
22 | * @brief testcase for gnunet-service-rps_peers.c | 22 | * @brief testcase for gnunet-service-rps_peers.c |
@@ -24,103 +24,102 @@ | |||
24 | #include <platform.h> | 24 | #include <platform.h> |
25 | #include "gnunet-service-rps_custommap.h" | 25 | #include "gnunet-service-rps_custommap.h" |
26 | 26 | ||
27 | #define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); if (NULL != c_m) CustomPeerMap_destroy(c_m); return 1; } | 27 | #define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); if (NULL != c_m) CustomPeerMap_destroy (c_m); return 1; } |
28 | #define CHECK(c) { if (! (c)) ABORT(); } | 28 | #define CHECK(c) { if (!(c)) ABORT (); } |
29 | 29 | ||
30 | 30 | ||
31 | static int | 31 | static int |
32 | check () | 32 | check() |
33 | { | 33 | { |
34 | |||
35 | struct CustomPeerMap *c_m; | 34 | struct CustomPeerMap *c_m; |
36 | struct GNUNET_PeerIdentity k1; | 35 | struct GNUNET_PeerIdentity k1; |
37 | struct GNUNET_PeerIdentity k2; | 36 | struct GNUNET_PeerIdentity k2; |
38 | int j; | 37 | int j; |
39 | 38 | ||
40 | CHECK (NULL != (c_m = CustomPeerMap_create (4))); | 39 | CHECK(NULL != (c_m = CustomPeerMap_create(4))); |
41 | memset (&k1, 0, sizeof (k1)); | 40 | memset(&k1, 0, sizeof(k1)); |
42 | memset (&k2, 1, sizeof (k2)); | 41 | memset(&k2, 1, sizeof(k2)); |
43 | CHECK (GNUNET_NO == CustomPeerMap_contains_peer (c_m, &k1)); | 42 | CHECK(GNUNET_NO == CustomPeerMap_contains_peer(c_m, &k1)); |
44 | CHECK (GNUNET_NO == CustomPeerMap_contains_peer (c_m, &k2)); | 43 | CHECK(GNUNET_NO == CustomPeerMap_contains_peer(c_m, &k2)); |
45 | CHECK (GNUNET_NO == CustomPeerMap_remove_peer (c_m, &k1)); | 44 | CHECK(GNUNET_NO == CustomPeerMap_remove_peer(c_m, &k1)); |
46 | CHECK (GNUNET_NO == CustomPeerMap_remove_peer (c_m, &k2)); | 45 | CHECK(GNUNET_NO == CustomPeerMap_remove_peer(c_m, &k2)); |
47 | CHECK (GNUNET_NO == CustomPeerMap_remove_peer_by_index (c_m, 0)); | 46 | CHECK(GNUNET_NO == CustomPeerMap_remove_peer_by_index(c_m, 0)); |
48 | CHECK (GNUNET_NO == CustomPeerMap_remove_peer_by_index (c_m, 0)); | 47 | CHECK(GNUNET_NO == CustomPeerMap_remove_peer_by_index(c_m, 0)); |
49 | CHECK (GNUNET_NO == CustomPeerMap_remove_peer_by_index (c_m, 1)); | 48 | CHECK(GNUNET_NO == CustomPeerMap_remove_peer_by_index(c_m, 1)); |
50 | CHECK (GNUNET_NO == CustomPeerMap_remove_peer_by_index (c_m, 1)); | 49 | CHECK(GNUNET_NO == CustomPeerMap_remove_peer_by_index(c_m, 1)); |
51 | CHECK (NULL == CustomPeerMap_get_peer_by_index (c_m, 0)); | 50 | CHECK(NULL == CustomPeerMap_get_peer_by_index(c_m, 0)); |
52 | CHECK (NULL == CustomPeerMap_get_peer_by_index (c_m, 0)); | 51 | CHECK(NULL == CustomPeerMap_get_peer_by_index(c_m, 0)); |
53 | CHECK (NULL == CustomPeerMap_get_peer_by_index (c_m, 1)); | 52 | CHECK(NULL == CustomPeerMap_get_peer_by_index(c_m, 1)); |
54 | CHECK (NULL == CustomPeerMap_get_peer_by_index (c_m, 1)); | 53 | CHECK(NULL == CustomPeerMap_get_peer_by_index(c_m, 1)); |
55 | CustomPeerMap_clear (c_m); /* See if assertions trigger */ | 54 | CustomPeerMap_clear(c_m); /* See if assertions trigger */ |
56 | CHECK (0 == CustomPeerMap_size (c_m)); | 55 | CHECK(0 == CustomPeerMap_size(c_m)); |
57 | 56 | ||
58 | CHECK (GNUNET_OK == CustomPeerMap_put (c_m, &k1)); | 57 | CHECK(GNUNET_OK == CustomPeerMap_put(c_m, &k1)); |
59 | CHECK (1 == CustomPeerMap_size (c_m)); | 58 | CHECK(1 == CustomPeerMap_size(c_m)); |
60 | CHECK (GNUNET_NO == CustomPeerMap_put (c_m, &k1)); | 59 | CHECK(GNUNET_NO == CustomPeerMap_put(c_m, &k1)); |
61 | CHECK (1 == CustomPeerMap_size (c_m)); | 60 | CHECK(1 == CustomPeerMap_size(c_m)); |
62 | CHECK (GNUNET_YES == CustomPeerMap_contains_peer (c_m, &k1)); | 61 | CHECK(GNUNET_YES == CustomPeerMap_contains_peer(c_m, &k1)); |
63 | CHECK (GNUNET_OK == CustomPeerMap_remove_peer (c_m, &k1)); | 62 | CHECK(GNUNET_OK == CustomPeerMap_remove_peer(c_m, &k1)); |
64 | CHECK (0 == CustomPeerMap_size (c_m)); | 63 | CHECK(0 == CustomPeerMap_size(c_m)); |
65 | CHECK (GNUNET_NO == CustomPeerMap_contains_peer (c_m, &k1)); | 64 | CHECK(GNUNET_NO == CustomPeerMap_contains_peer(c_m, &k1)); |
66 | CHECK (GNUNET_NO == CustomPeerMap_contains_peer (c_m, &k2)); | 65 | CHECK(GNUNET_NO == CustomPeerMap_contains_peer(c_m, &k2)); |
67 | 66 | ||
68 | CHECK (GNUNET_OK == CustomPeerMap_put (c_m, &k1)); | 67 | CHECK(GNUNET_OK == CustomPeerMap_put(c_m, &k1)); |
69 | CHECK (1 == CustomPeerMap_size (c_m)); | 68 | CHECK(1 == CustomPeerMap_size(c_m)); |
70 | for (j = 0; j < 16; j++) | 69 | for (j = 0; j < 16; j++) |
71 | { | 70 | { |
72 | CHECK (GNUNET_NO == CustomPeerMap_put (c_m, &k1)); | 71 | CHECK(GNUNET_NO == CustomPeerMap_put(c_m, &k1)); |
73 | } | 72 | } |
74 | CHECK (1 == CustomPeerMap_size (c_m)); | 73 | CHECK(1 == CustomPeerMap_size(c_m)); |
75 | CHECK (GNUNET_OK == CustomPeerMap_put (c_m, &k2)); | 74 | CHECK(GNUNET_OK == CustomPeerMap_put(c_m, &k2)); |
76 | CHECK (2 == CustomPeerMap_size (c_m)); | 75 | CHECK(2 == CustomPeerMap_size(c_m)); |
77 | for (j = 0; j < 16; j++) | 76 | for (j = 0; j < 16; j++) |
78 | { | 77 | { |
79 | CHECK (GNUNET_NO == CustomPeerMap_put (c_m, &k2)); | 78 | CHECK(GNUNET_NO == CustomPeerMap_put(c_m, &k2)); |
80 | } | 79 | } |
81 | CHECK (2 == CustomPeerMap_size (c_m)); | 80 | CHECK(2 == CustomPeerMap_size(c_m)); |
82 | 81 | ||
83 | /* iterate */ | 82 | /* iterate */ |
84 | for (j = 0; j < CustomPeerMap_size (c_m); j++) | 83 | for (j = 0; j < CustomPeerMap_size(c_m); j++) |
85 | { | 84 | { |
86 | CHECK (NULL != CustomPeerMap_get_peer_by_index (c_m, j)); | 85 | CHECK(NULL != CustomPeerMap_get_peer_by_index(c_m, j)); |
87 | } | 86 | } |
88 | CHECK ((0 == memcmp (CustomPeerMap_get_peer_by_index (c_m, 0), | 87 | CHECK((0 == memcmp(CustomPeerMap_get_peer_by_index(c_m, 0), |
89 | &k1, sizeof (k1)))); | 88 | &k1, sizeof(k1)))); |
90 | CHECK ((0 == memcmp (CustomPeerMap_get_peer_by_index (c_m, 1), | 89 | CHECK((0 == memcmp(CustomPeerMap_get_peer_by_index(c_m, 1), |
91 | &k2, sizeof (k2)))); | 90 | &k2, sizeof(k2)))); |
92 | CHECK (GNUNET_OK == CustomPeerMap_remove_peer (c_m, &k1)); | 91 | CHECK(GNUNET_OK == CustomPeerMap_remove_peer(c_m, &k1)); |
93 | CHECK (1 == CustomPeerMap_size (c_m)); | 92 | CHECK(1 == CustomPeerMap_size(c_m)); |
94 | CHECK (GNUNET_NO == CustomPeerMap_contains_peer (c_m, &k1)); | 93 | CHECK(GNUNET_NO == CustomPeerMap_contains_peer(c_m, &k1)); |
95 | CHECK (GNUNET_YES == CustomPeerMap_contains_peer (c_m, &k2)); | 94 | CHECK(GNUNET_YES == CustomPeerMap_contains_peer(c_m, &k2)); |
96 | CHECK (NULL != CustomPeerMap_get_peer_by_index (c_m, 0)); | 95 | CHECK(NULL != CustomPeerMap_get_peer_by_index(c_m, 0)); |
97 | 96 | ||
98 | CustomPeerMap_clear (c_m); | 97 | CustomPeerMap_clear(c_m); |
99 | CHECK (0 == CustomPeerMap_size (c_m)); | 98 | CHECK(0 == CustomPeerMap_size(c_m)); |
100 | 99 | ||
101 | CHECK (GNUNET_OK == CustomPeerMap_put (c_m, &k1)); | 100 | CHECK(GNUNET_OK == CustomPeerMap_put(c_m, &k1)); |
102 | CHECK (1 == CustomPeerMap_size (c_m)); | 101 | CHECK(1 == CustomPeerMap_size(c_m)); |
103 | CHECK (GNUNET_OK == CustomPeerMap_put (c_m, &k2)); | 102 | CHECK(GNUNET_OK == CustomPeerMap_put(c_m, &k2)); |
104 | CHECK (2 == CustomPeerMap_size (c_m)); | 103 | CHECK(2 == CustomPeerMap_size(c_m)); |
105 | CustomPeerMap_clear (c_m); | 104 | CustomPeerMap_clear(c_m); |
106 | CHECK (0 == CustomPeerMap_size (c_m)); | 105 | CHECK(0 == CustomPeerMap_size(c_m)); |
107 | 106 | ||
108 | CustomPeerMap_destroy (c_m); | 107 | CustomPeerMap_destroy(c_m); |
109 | 108 | ||
110 | return 0; | 109 | return 0; |
111 | } | 110 | } |
112 | 111 | ||
113 | 112 | ||
114 | int | 113 | int |
115 | main (int argc, char *argv[]) | 114 | main(int argc, char *argv[]) |
116 | { | 115 | { |
117 | (void) argc; | 116 | (void)argc; |
118 | (void) argv; | 117 | (void)argv; |
119 | 118 | ||
120 | GNUNET_log_setup ("test_service_rps_peers", | 119 | GNUNET_log_setup("test_service_rps_peers", |
121 | "WARNING", | 120 | "WARNING", |
122 | NULL); | 121 | NULL); |
123 | return check (); | 122 | return check(); |
124 | } | 123 | } |
125 | 124 | ||
126 | /* end of test_service_rps_custommap.c */ | 125 | /* end of test_service_rps_custommap.c */ |
diff --git a/src/rps/test_service_rps_sampler_elem.c b/src/rps/test_service_rps_sampler_elem.c index 4e96b9bd1..b6e3e36bf 100644 --- a/src/rps/test_service_rps_sampler_elem.c +++ b/src/rps/test_service_rps_sampler_elem.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file rps/test_service_rps_sampler_elem.c | 21 | * @file rps/test_service_rps_sampler_elem.c |
22 | * @brief testcase for gnunet-service-rps_sampler_elem.c | 22 | * @brief testcase for gnunet-service-rps_sampler_elem.c |
@@ -26,11 +26,11 @@ | |||
26 | #include "gnunet-service-rps_sampler_elem.h" | 26 | #include "gnunet-service-rps_sampler_elem.h" |
27 | 27 | ||
28 | #define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); return 1; } | 28 | #define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); return 1; } |
29 | #define CHECK(c) { if (! (c)) ABORT(); } | 29 | #define CHECK(c) { if (!(c)) ABORT (); } |
30 | 30 | ||
31 | 31 | ||
32 | static int | 32 | static int |
33 | check () | 33 | check() |
34 | { | 34 | { |
35 | struct GNUNET_PeerIdentity pid0; | 35 | struct GNUNET_PeerIdentity pid0; |
36 | struct GNUNET_PeerIdentity pid1; | 36 | struct GNUNET_PeerIdentity pid1; |
@@ -40,152 +40,152 @@ check () | |||
40 | struct GNUNET_HashCode hash_code; | 40 | struct GNUNET_HashCode hash_code; |
41 | struct GNUNET_HashCode hash_code2; | 41 | struct GNUNET_HashCode hash_code2; |
42 | 42 | ||
43 | memset (&pid0, 1, sizeof (pid0)); | 43 | memset(&pid0, 1, sizeof(pid0)); |
44 | memset (&pid1, 0, sizeof (pid1)); | 44 | memset(&pid1, 0, sizeof(pid1)); |
45 | 45 | ||
46 | /* Check if creation and destruction of an | 46 | /* Check if creation and destruction of an |
47 | * (empty) sampler element works */ | 47 | * (empty) sampler element works */ |
48 | s_elem = RPS_sampler_elem_create (); | 48 | s_elem = RPS_sampler_elem_create(); |
49 | CHECK (NULL != s_elem); | 49 | CHECK(NULL != s_elem); |
50 | CHECK (EMPTY == s_elem->is_empty); | 50 | CHECK(EMPTY == s_elem->is_empty); |
51 | CHECK (NULL != &s_elem->auth_key); | 51 | CHECK(NULL != &s_elem->auth_key); |
52 | auth_key = s_elem->auth_key; | 52 | auth_key = s_elem->auth_key; |
53 | RPS_sampler_elem_destroy (s_elem); | 53 | RPS_sampler_elem_destroy(s_elem); |
54 | 54 | ||
55 | 55 | ||
56 | /* Check creation of another sampler element | 56 | /* Check creation of another sampler element |
57 | * yields another (random) key */ | 57 | * yields another (random) key */ |
58 | s_elem = RPS_sampler_elem_create (); | 58 | s_elem = RPS_sampler_elem_create(); |
59 | CHECK (NULL != s_elem); | 59 | CHECK(NULL != s_elem); |
60 | CHECK (EMPTY == s_elem->is_empty); | 60 | CHECK(EMPTY == s_elem->is_empty); |
61 | CHECK (NULL != &s_elem->auth_key); | 61 | CHECK(NULL != &s_elem->auth_key); |
62 | CHECK (auth_key.key != s_elem->auth_key.key); | 62 | CHECK(auth_key.key != s_elem->auth_key.key); |
63 | CHECK (0 != memcmp (auth_key.key, s_elem->auth_key.key, GNUNET_CRYPTO_HASH_LENGTH)); | 63 | CHECK(0 != memcmp(auth_key.key, s_elem->auth_key.key, GNUNET_CRYPTO_HASH_LENGTH)); |
64 | auth_key = s_elem->auth_key; | 64 | auth_key = s_elem->auth_key; |
65 | 65 | ||
66 | /* Check that reinitialisation | 66 | /* Check that reinitialisation |
67 | * yields another (random) key */ | 67 | * yields another (random) key */ |
68 | RPS_sampler_elem_reinit (s_elem); | 68 | RPS_sampler_elem_reinit(s_elem); |
69 | CHECK (NULL != s_elem); | 69 | CHECK(NULL != s_elem); |
70 | CHECK (EMPTY == s_elem->is_empty); | 70 | CHECK(EMPTY == s_elem->is_empty); |
71 | CHECK (NULL != &s_elem->auth_key); | 71 | CHECK(NULL != &s_elem->auth_key); |
72 | CHECK (auth_key.key != s_elem->auth_key.key); | 72 | CHECK(auth_key.key != s_elem->auth_key.key); |
73 | CHECK (0 != memcmp (auth_key.key, s_elem->auth_key.key, GNUNET_CRYPTO_HASH_LENGTH)); | 73 | CHECK(0 != memcmp(auth_key.key, s_elem->auth_key.key, GNUNET_CRYPTO_HASH_LENGTH)); |
74 | RPS_sampler_elem_destroy (s_elem); | 74 | RPS_sampler_elem_destroy(s_elem); |
75 | 75 | ||
76 | 76 | ||
77 | /* Check that input of single peer id | 77 | /* Check that input of single peer id |
78 | * sets valid values */ | 78 | * sets valid values */ |
79 | s_elem = RPS_sampler_elem_create (); | 79 | s_elem = RPS_sampler_elem_create(); |
80 | CHECK (EMPTY == s_elem->is_empty); | 80 | CHECK(EMPTY == s_elem->is_empty); |
81 | CHECK (NULL != &s_elem->auth_key); | 81 | CHECK(NULL != &s_elem->auth_key); |
82 | CHECK (auth_key.key != s_elem->auth_key.key); | 82 | CHECK(auth_key.key != s_elem->auth_key.key); |
83 | /* This fails only with minimal chance */ | 83 | /* This fails only with minimal chance */ |
84 | CHECK (0 != memcmp (auth_key.key, s_elem->auth_key.key, GNUNET_CRYPTO_HASH_LENGTH)); | 84 | CHECK(0 != memcmp(auth_key.key, s_elem->auth_key.key, GNUNET_CRYPTO_HASH_LENGTH)); |
85 | auth_key = s_elem->auth_key; | 85 | auth_key = s_elem->auth_key; |
86 | 86 | ||
87 | /* Check also that the hash of the peer id changed | 87 | /* Check also that the hash of the peer id changed |
88 | * Also fails with minimal probability */ | 88 | * Also fails with minimal probability */ |
89 | hash_code = s_elem->peer_id_hash; | 89 | hash_code = s_elem->peer_id_hash; |
90 | RPS_sampler_elem_next (s_elem, &pid0); | 90 | RPS_sampler_elem_next(s_elem, &pid0); |
91 | CHECK (0 == memcmp (&pid0, | 91 | CHECK(0 == memcmp(&pid0, |
92 | &s_elem->peer_id, | 92 | &s_elem->peer_id, |
93 | sizeof (struct GNUNET_PeerIdentity))); | 93 | sizeof(struct GNUNET_PeerIdentity))); |
94 | CHECK (0 != memcmp (&hash_code, | 94 | CHECK(0 != memcmp(&hash_code, |
95 | &s_elem->peer_id_hash, | 95 | &s_elem->peer_id_hash, |
96 | sizeof (struct GNUNET_HashCode))); | 96 | sizeof(struct GNUNET_HashCode))); |
97 | hash_code = s_elem->peer_id_hash; | 97 | hash_code = s_elem->peer_id_hash; |
98 | 98 | ||
99 | /* We can only check that the peer id is one of both inputs */ | 99 | /* We can only check that the peer id is one of both inputs */ |
100 | RPS_sampler_elem_next (s_elem, &pid1); | 100 | RPS_sampler_elem_next(s_elem, &pid1); |
101 | CHECK ( (0 == memcmp (&pid0, | 101 | CHECK((0 == memcmp(&pid0, |
102 | &s_elem->peer_id, | 102 | &s_elem->peer_id, |
103 | sizeof (struct GNUNET_PeerIdentity))) || | 103 | sizeof(struct GNUNET_PeerIdentity))) || |
104 | (0 == memcmp (&pid1, | 104 | (0 == memcmp(&pid1, |
105 | &s_elem->peer_id, | 105 | &s_elem->peer_id, |
106 | sizeof (struct GNUNET_PeerIdentity))) ); | 106 | sizeof(struct GNUNET_PeerIdentity)))); |
107 | 107 | ||
108 | /* Check that hash stayed the same when peer id did not change */ | 108 | /* Check that hash stayed the same when peer id did not change */ |
109 | if (0 == memcmp (&pid0, | 109 | if (0 == memcmp(&pid0, |
110 | &s_elem->peer_id, | 110 | &s_elem->peer_id, |
111 | sizeof (struct GNUNET_PeerIdentity))) | 111 | sizeof(struct GNUNET_PeerIdentity))) |
112 | { | 112 | { |
113 | CHECK (0 == memcmp (&hash_code, | 113 | CHECK(0 == memcmp(&hash_code, |
114 | &s_elem->peer_id_hash, | 114 | &s_elem->peer_id_hash, |
115 | sizeof (struct GNUNET_HashCode))); | 115 | sizeof(struct GNUNET_HashCode))); |
116 | } | 116 | } |
117 | else /* Check that hash changed */ | 117 | else /* Check that hash changed */ |
118 | { | 118 | { |
119 | CHECK (0 != memcmp (&hash_code, | 119 | CHECK(0 != memcmp(&hash_code, |
120 | &s_elem->peer_id_hash, | 120 | &s_elem->peer_id_hash, |
121 | sizeof (struct GNUNET_HashCode))); | 121 | sizeof(struct GNUNET_HashCode))); |
122 | } | 122 | } |
123 | 123 | ||
124 | /* Check multiple inputs of same id | 124 | /* Check multiple inputs of same id |
125 | * hash should not change anymore */ | 125 | * hash should not change anymore */ |
126 | hash_code2 = s_elem->peer_id_hash; | 126 | hash_code2 = s_elem->peer_id_hash; |
127 | RPS_sampler_elem_next (s_elem, &pid0); | 127 | RPS_sampler_elem_next(s_elem, &pid0); |
128 | CHECK (0 == memcmp (&hash_code2, | 128 | CHECK(0 == memcmp(&hash_code2, |
129 | &s_elem->peer_id_hash, | 129 | &s_elem->peer_id_hash, |
130 | sizeof (struct GNUNET_HashCode))); | 130 | sizeof(struct GNUNET_HashCode))); |
131 | RPS_sampler_elem_next (s_elem, &pid1); | 131 | RPS_sampler_elem_next(s_elem, &pid1); |
132 | CHECK (0 == memcmp (&hash_code2, | 132 | CHECK(0 == memcmp(&hash_code2, |
133 | &s_elem->peer_id_hash, | 133 | &s_elem->peer_id_hash, |
134 | sizeof (struct GNUNET_HashCode))); | 134 | sizeof(struct GNUNET_HashCode))); |
135 | RPS_sampler_elem_next (s_elem, &pid0); | 135 | RPS_sampler_elem_next(s_elem, &pid0); |
136 | CHECK (0 == memcmp (&hash_code2, | 136 | CHECK(0 == memcmp(&hash_code2, |
137 | &s_elem->peer_id_hash, | 137 | &s_elem->peer_id_hash, |
138 | sizeof (struct GNUNET_HashCode))); | 138 | sizeof(struct GNUNET_HashCode))); |
139 | RPS_sampler_elem_next (s_elem, &pid0); | 139 | RPS_sampler_elem_next(s_elem, &pid0); |
140 | CHECK (0 == memcmp (&hash_code2, | 140 | CHECK(0 == memcmp(&hash_code2, |
141 | &s_elem->peer_id_hash, | 141 | &s_elem->peer_id_hash, |
142 | sizeof (struct GNUNET_HashCode))); | 142 | sizeof(struct GNUNET_HashCode))); |
143 | RPS_sampler_elem_next (s_elem, &pid0); | 143 | RPS_sampler_elem_next(s_elem, &pid0); |
144 | CHECK (0 == memcmp (&hash_code2, | 144 | CHECK(0 == memcmp(&hash_code2, |
145 | &s_elem->peer_id_hash, | 145 | &s_elem->peer_id_hash, |
146 | sizeof (struct GNUNET_HashCode))); | 146 | sizeof(struct GNUNET_HashCode))); |
147 | RPS_sampler_elem_next (s_elem, &pid1); | 147 | RPS_sampler_elem_next(s_elem, &pid1); |
148 | CHECK (0 == memcmp (&hash_code2, | 148 | CHECK(0 == memcmp(&hash_code2, |
149 | &s_elem->peer_id_hash, | 149 | &s_elem->peer_id_hash, |
150 | sizeof (struct GNUNET_HashCode))); | 150 | sizeof(struct GNUNET_HashCode))); |
151 | RPS_sampler_elem_next (s_elem, &pid1); | 151 | RPS_sampler_elem_next(s_elem, &pid1); |
152 | CHECK (0 == memcmp (&hash_code2, | 152 | CHECK(0 == memcmp(&hash_code2, |
153 | &s_elem->peer_id_hash, | 153 | &s_elem->peer_id_hash, |
154 | sizeof (struct GNUNET_HashCode))); | 154 | sizeof(struct GNUNET_HashCode))); |
155 | RPS_sampler_elem_next (s_elem, &pid1); | 155 | RPS_sampler_elem_next(s_elem, &pid1); |
156 | CHECK (0 == memcmp (&hash_code2, | 156 | CHECK(0 == memcmp(&hash_code2, |
157 | &s_elem->peer_id_hash, | 157 | &s_elem->peer_id_hash, |
158 | sizeof (struct GNUNET_HashCode))); | 158 | sizeof(struct GNUNET_HashCode))); |
159 | 159 | ||
160 | /* Check whether pid stayed the same all the time */ | 160 | /* Check whether pid stayed the same all the time */ |
161 | if (0 == memcmp (&hash_code, | 161 | if (0 == memcmp(&hash_code, |
162 | &hash_code2, | 162 | &hash_code2, |
163 | sizeof (struct GNUNET_HashCode))) | 163 | sizeof(struct GNUNET_HashCode))) |
164 | { | 164 | { |
165 | CHECK (0 == memcmp (&pid0, | 165 | CHECK(0 == memcmp(&pid0, |
166 | &s_elem->peer_id, | 166 | &s_elem->peer_id, |
167 | sizeof (struct GNUNET_PeerIdentity))); | 167 | sizeof(struct GNUNET_PeerIdentity))); |
168 | } | 168 | } |
169 | else | 169 | else |
170 | { | 170 | { |
171 | CHECK (0 == memcmp (&pid1, | 171 | CHECK(0 == memcmp(&pid1, |
172 | &s_elem->peer_id, | 172 | &s_elem->peer_id, |
173 | sizeof (struct GNUNET_PeerIdentity))); | 173 | sizeof(struct GNUNET_PeerIdentity))); |
174 | } | 174 | } |
175 | RPS_sampler_elem_destroy (s_elem); | 175 | RPS_sampler_elem_destroy(s_elem); |
176 | 176 | ||
177 | /* Check _set() */ | 177 | /* Check _set() */ |
178 | s_elem = RPS_sampler_elem_create (); | 178 | s_elem = RPS_sampler_elem_create(); |
179 | CHECK (NULL != s_elem); | 179 | CHECK(NULL != s_elem); |
180 | CHECK (EMPTY == s_elem->is_empty); | 180 | CHECK(EMPTY == s_elem->is_empty); |
181 | CHECK (NULL != &s_elem->auth_key); | 181 | CHECK(NULL != &s_elem->auth_key); |
182 | auth_key = s_elem->auth_key; | 182 | auth_key = s_elem->auth_key; |
183 | memset (&auth_key2, 0, sizeof (auth_key2)); | 183 | memset(&auth_key2, 0, sizeof(auth_key2)); |
184 | RPS_sampler_elem_set (s_elem, auth_key2); | 184 | RPS_sampler_elem_set(s_elem, auth_key2); |
185 | CHECK (0 == memcmp (auth_key2.key, | 185 | CHECK(0 == memcmp(auth_key2.key, |
186 | s_elem->auth_key.key, | 186 | s_elem->auth_key.key, |
187 | GNUNET_CRYPTO_HASH_LENGTH)); | 187 | GNUNET_CRYPTO_HASH_LENGTH)); |
188 | RPS_sampler_elem_destroy (s_elem); | 188 | RPS_sampler_elem_destroy(s_elem); |
189 | 189 | ||
190 | 190 | ||
191 | /* TODO: deterministic tests (use _set() to set auth_key) */ | 191 | /* TODO: deterministic tests (use _set() to set auth_key) */ |
@@ -194,15 +194,15 @@ check () | |||
194 | 194 | ||
195 | 195 | ||
196 | int | 196 | int |
197 | main (int argc, char *argv[]) | 197 | main(int argc, char *argv[]) |
198 | { | 198 | { |
199 | (void) argc; | 199 | (void)argc; |
200 | (void) argv; | 200 | (void)argv; |
201 | 201 | ||
202 | GNUNET_log_setup ("test_service_rps_peers", | 202 | GNUNET_log_setup("test_service_rps_peers", |
203 | "WARNING", | 203 | "WARNING", |
204 | NULL); | 204 | NULL); |
205 | return check (); | 205 | return check(); |
206 | } | 206 | } |
207 | 207 | ||
208 | /* end of test_service_rps_peers.c */ | 208 | /* end of test_service_rps_peers.c */ |
diff --git a/src/rps/test_service_rps_view.c b/src/rps/test_service_rps_view.c index c366b407b..31aa8cf0b 100644 --- a/src/rps/test_service_rps_view.c +++ b/src/rps/test_service_rps_view.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file rps/test_service_rps_view.c | 21 | * @file rps/test_service_rps_view.c |
22 | * @brief testcase for gnunet-service-rps_view.c | 22 | * @brief testcase for gnunet-service-rps_view.c |
@@ -25,11 +25,11 @@ | |||
25 | #include "gnunet-service-rps_view.h" | 25 | #include "gnunet-service-rps_view.h" |
26 | 26 | ||
27 | #define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); View_destroy(view); return 1; } | 27 | #define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); View_destroy(view); return 1; } |
28 | #define CHECK(c) { if (! (c)) ABORT(); } | 28 | #define CHECK(c) { if (!(c)) ABORT (); } |
29 | 29 | ||
30 | 30 | ||
31 | static int | 31 | static int |
32 | check () | 32 | check() |
33 | { | 33 | { |
34 | struct View *view; | 34 | struct View *view; |
35 | struct GNUNET_PeerIdentity k1; | 35 | struct GNUNET_PeerIdentity k1; |
@@ -37,107 +37,107 @@ check () | |||
37 | const struct GNUNET_PeerIdentity *array; | 37 | const struct GNUNET_PeerIdentity *array; |
38 | unsigned int j; | 38 | unsigned int j; |
39 | 39 | ||
40 | view = View_create (3); | 40 | view = View_create(3); |
41 | memset (&k1, 0, sizeof (k1)); | 41 | memset(&k1, 0, sizeof(k1)); |
42 | memset (&k2, 1, sizeof (k2)); | 42 | memset(&k2, 1, sizeof(k2)); |
43 | CHECK (GNUNET_NO == View_contains_peer (view, &k1)); | 43 | CHECK(GNUNET_NO == View_contains_peer(view, &k1)); |
44 | CHECK (GNUNET_NO == View_contains_peer (view, &k2)); | 44 | CHECK(GNUNET_NO == View_contains_peer(view, &k2)); |
45 | CHECK (GNUNET_NO == View_remove_peer (view, &k1)); | 45 | CHECK(GNUNET_NO == View_remove_peer(view, &k1)); |
46 | CHECK (GNUNET_NO == View_remove_peer (view, &k2)); | 46 | CHECK(GNUNET_NO == View_remove_peer(view, &k2)); |
47 | CHECK (NULL == View_get_peer_by_index (view, 0)); | 47 | CHECK(NULL == View_get_peer_by_index(view, 0)); |
48 | CHECK (NULL == View_get_peer_by_index (view, 1)); | 48 | CHECK(NULL == View_get_peer_by_index(view, 1)); |
49 | View_clear (view); /* See if assertions trigger */ | 49 | View_clear(view); /* See if assertions trigger */ |
50 | CHECK (0 == View_size (view)); | 50 | CHECK(0 == View_size(view)); |
51 | 51 | ||
52 | CHECK (GNUNET_OK == View_put (view, &k1)); | 52 | CHECK(GNUNET_OK == View_put(view, &k1)); |
53 | CHECK (1 == View_size (view)); | 53 | CHECK(1 == View_size(view)); |
54 | CHECK (GNUNET_NO == View_put (view, &k1)); | 54 | CHECK(GNUNET_NO == View_put(view, &k1)); |
55 | CHECK (1 == View_size (view)); | 55 | CHECK(1 == View_size(view)); |
56 | CHECK (GNUNET_YES == View_contains_peer (view, &k1)); | 56 | CHECK(GNUNET_YES == View_contains_peer(view, &k1)); |
57 | CHECK (GNUNET_OK == View_remove_peer (view, &k1)); | 57 | CHECK(GNUNET_OK == View_remove_peer(view, &k1)); |
58 | CHECK (0 == View_size (view)); | 58 | CHECK(0 == View_size(view)); |
59 | CHECK (GNUNET_NO == View_contains_peer (view, &k1)); | 59 | CHECK(GNUNET_NO == View_contains_peer(view, &k1)); |
60 | CHECK (GNUNET_NO == View_contains_peer (view, &k2)); | 60 | CHECK(GNUNET_NO == View_contains_peer(view, &k2)); |
61 | 61 | ||
62 | CHECK (GNUNET_OK == View_put (view, &k1)); | 62 | CHECK(GNUNET_OK == View_put(view, &k1)); |
63 | CHECK (1 == View_size (view)); | 63 | CHECK(1 == View_size(view)); |
64 | for (j = 0; j < 16; j++) | 64 | for (j = 0; j < 16; j++) |
65 | { | 65 | { |
66 | CHECK (GNUNET_NO == View_put (view, &k1)); | 66 | CHECK(GNUNET_NO == View_put(view, &k1)); |
67 | } | 67 | } |
68 | CHECK (1 == View_size (view)); | 68 | CHECK(1 == View_size(view)); |
69 | CHECK (GNUNET_OK == View_put (view, &k2)); | 69 | CHECK(GNUNET_OK == View_put(view, &k2)); |
70 | CHECK (2 == View_size (view)); | 70 | CHECK(2 == View_size(view)); |
71 | for (j = 0; j < 16; j++) | 71 | for (j = 0; j < 16; j++) |
72 | { | 72 | { |
73 | CHECK (GNUNET_NO == View_put (view, &k2)); | 73 | CHECK(GNUNET_NO == View_put(view, &k2)); |
74 | } | 74 | } |
75 | CHECK (2 == View_size (view)); | 75 | CHECK(2 == View_size(view)); |
76 | 76 | ||
77 | /* iterate */ | 77 | /* iterate */ |
78 | for (j = 0; j < View_size (view); j++) | 78 | for (j = 0; j < View_size(view); j++) |
79 | { | 79 | { |
80 | CHECK (NULL != View_get_peer_by_index (view, j)); | 80 | CHECK(NULL != View_get_peer_by_index(view, j)); |
81 | } | 81 | } |
82 | CHECK ((0 == memcmp (View_get_peer_by_index (view, 0), | 82 | CHECK((0 == memcmp(View_get_peer_by_index(view, 0), |
83 | &k1, sizeof (k1)))); | 83 | &k1, sizeof(k1)))); |
84 | CHECK ((0 == memcmp (View_get_peer_by_index (view, 1), | 84 | CHECK((0 == memcmp(View_get_peer_by_index(view, 1), |
85 | &k2, sizeof (k2)))); | 85 | &k2, sizeof(k2)))); |
86 | CHECK (GNUNET_OK == View_remove_peer (view, &k1)); | 86 | CHECK(GNUNET_OK == View_remove_peer(view, &k1)); |
87 | CHECK (1 == View_size (view)); | 87 | CHECK(1 == View_size(view)); |
88 | CHECK (GNUNET_NO == View_contains_peer (view, &k1)); | 88 | CHECK(GNUNET_NO == View_contains_peer(view, &k1)); |
89 | CHECK (GNUNET_YES == View_contains_peer (view, &k2)); | 89 | CHECK(GNUNET_YES == View_contains_peer(view, &k2)); |
90 | CHECK (NULL != View_get_peer_by_index (view, 0)); | 90 | CHECK(NULL != View_get_peer_by_index(view, 0)); |
91 | CHECK (NULL == View_get_peer_by_index (view, 1)); | 91 | CHECK(NULL == View_get_peer_by_index(view, 1)); |
92 | 92 | ||
93 | View_clear (view); | 93 | View_clear(view); |
94 | CHECK (0 == View_size (view)); | 94 | CHECK(0 == View_size(view)); |
95 | 95 | ||
96 | CHECK (GNUNET_OK == View_put (view, &k1)); | 96 | CHECK(GNUNET_OK == View_put(view, &k1)); |
97 | CHECK (1 == View_size (view)); | 97 | CHECK(1 == View_size(view)); |
98 | CHECK (GNUNET_YES == View_contains_peer (view, &k1)); | 98 | CHECK(GNUNET_YES == View_contains_peer(view, &k1)); |
99 | CHECK (GNUNET_OK == View_put (view, &k2)); | 99 | CHECK(GNUNET_OK == View_put(view, &k2)); |
100 | CHECK (2 == View_size (view)); | 100 | CHECK(2 == View_size(view)); |
101 | CHECK (GNUNET_YES == View_contains_peer (view, &k2)); | 101 | CHECK(GNUNET_YES == View_contains_peer(view, &k2)); |
102 | array = View_get_as_array (view); | 102 | array = View_get_as_array(view); |
103 | CHECK (0 == memcmp (&array[0], &k1, sizeof (k1))); | 103 | CHECK(0 == memcmp(&array[0], &k1, sizeof(k1))); |
104 | CHECK (0 == memcmp (&array[1], &k2, sizeof (k2))); | 104 | CHECK(0 == memcmp(&array[1], &k2, sizeof(k2))); |
105 | View_clear (view); | 105 | View_clear(view); |
106 | CHECK (0 == View_size (view)); | 106 | CHECK(0 == View_size(view)); |
107 | 107 | ||
108 | /*View_change_len () */ | 108 | /*View_change_len () */ |
109 | CHECK (GNUNET_OK == View_put (view, &k1)); | 109 | CHECK(GNUNET_OK == View_put(view, &k1)); |
110 | CHECK (GNUNET_OK == View_put (view, &k2)); | 110 | CHECK(GNUNET_OK == View_put(view, &k2)); |
111 | CHECK (2 == View_size (view)); | 111 | CHECK(2 == View_size(view)); |
112 | View_change_len (view, 4); | 112 | View_change_len(view, 4); |
113 | CHECK (2 == View_size (view)); | 113 | CHECK(2 == View_size(view)); |
114 | CHECK (GNUNET_YES == View_contains_peer (view, &k1)); | 114 | CHECK(GNUNET_YES == View_contains_peer(view, &k1)); |
115 | CHECK (GNUNET_YES == View_contains_peer (view, &k2)); | 115 | CHECK(GNUNET_YES == View_contains_peer(view, &k2)); |
116 | array = View_get_as_array (view); | 116 | array = View_get_as_array(view); |
117 | CHECK (0 == memcmp (&array[0], &k1, sizeof (k1))); | 117 | CHECK(0 == memcmp(&array[0], &k1, sizeof(k1))); |
118 | CHECK (0 == memcmp (&array[1], &k2, sizeof (k2))); | 118 | CHECK(0 == memcmp(&array[1], &k2, sizeof(k2))); |
119 | View_change_len (view, 1); | 119 | View_change_len(view, 1); |
120 | CHECK (1 == View_size (view)); | 120 | CHECK(1 == View_size(view)); |
121 | CHECK (GNUNET_YES == View_contains_peer (view, &k1)); | 121 | CHECK(GNUNET_YES == View_contains_peer(view, &k1)); |
122 | CHECK (GNUNET_NO == View_contains_peer (view, &k2)); | 122 | CHECK(GNUNET_NO == View_contains_peer(view, &k2)); |
123 | array = View_get_as_array (view); | 123 | array = View_get_as_array(view); |
124 | CHECK (0 == memcmp (&array[0], &k1, sizeof (k1))); | 124 | CHECK(0 == memcmp(&array[0], &k1, sizeof(k1))); |
125 | View_clear (view); | 125 | View_clear(view); |
126 | CHECK (0 == View_size (view)); | 126 | CHECK(0 == View_size(view)); |
127 | 127 | ||
128 | View_destroy (view); | 128 | View_destroy(view); |
129 | 129 | ||
130 | return 0; | 130 | return 0; |
131 | } | 131 | } |
132 | 132 | ||
133 | 133 | ||
134 | int | 134 | int |
135 | main () | 135 | main() |
136 | { | 136 | { |
137 | GNUNET_log_setup ("test_service_rps_peers", | 137 | GNUNET_log_setup("test_service_rps_peers", |
138 | "WARNING", | 138 | "WARNING", |
139 | NULL); | 139 | NULL); |
140 | return check (); | 140 | return check(); |
141 | } | 141 | } |
142 | 142 | ||
143 | /* end of test_service_rps_view.c */ | 143 | /* end of test_service_rps_view.c */ |