aboutsummaryrefslogtreecommitdiff
path: root/src/rps
diff options
context:
space:
mode:
Diffstat (limited to 'src/rps')
-rw-r--r--src/rps/gnunet-rps-profiler.c3144
-rw-r--r--src/rps/gnunet-rps.c227
-rw-r--r--src/rps/gnunet-service-rps.c4251
-rw-r--r--src/rps/gnunet-service-rps_custommap.c253
-rw-r--r--src/rps/gnunet-service-rps_custommap.h28
-rw-r--r--src/rps/gnunet-service-rps_sampler.c67
-rw-r--r--src/rps/gnunet-service-rps_sampler.h32
-rw-r--r--src/rps/gnunet-service-rps_sampler_elem.c97
-rw-r--r--src/rps/gnunet-service-rps_sampler_elem.h20
-rw-r--r--src/rps/gnunet-service-rps_view.c194
-rw-r--r--src/rps/gnunet-service-rps_view.h30
-rw-r--r--src/rps/rps-sampler_client.c190
-rw-r--r--src/rps/rps-sampler_client.h32
-rw-r--r--src/rps/rps-sampler_common.c487
-rw-r--r--src/rps/rps-sampler_common.h62
-rw-r--r--src/rps/rps-test_util.c584
-rw-r--r--src/rps/rps-test_util.h87
-rw-r--r--src/rps/rps.h39
-rw-r--r--src/rps/rps_api.c925
-rw-r--r--src/rps/test_rps.c2917
-rw-r--r--src/rps/test_rps_api.c61
-rw-r--r--src/rps/test_service_rps_custommap.c151
-rw-r--r--src/rps/test_service_rps_sampler_elem.c224
-rw-r--r--src/rps/test_service_rps_view.c183
24 files changed, 7246 insertions, 7039 deletions
diff --git a/src/rps/gnunet-rps-profiler.c b/src/rps/gnunet-rps-profiler.c
index a963476cf..03b96f264 100644
--- a/src/rps/gnunet-rps-profiler.c
+++ b/src/rps/gnunet-rps-profiler.c
@@ -25,7 +25,7 @@
25 * for one message from each peer. 25 * for one message from each peer.
26 */ 26 */
27#include "platform.h" 27#include "platform.h"
28//#include "rps_test_lib.h" 28// #include "rps_test_lib.h"
29#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
30#include "gnunet_testbed_service.h" 30#include "gnunet_testbed_service.h"
31 31
@@ -74,7 +74,8 @@ static unsigned int mal_type = 0;
74 */ 74 */
75static struct GNUNET_TESTBED_Peer **testbed_peers; 75static struct GNUNET_TESTBED_Peer **testbed_peers;
76 76
77enum STAT_TYPE { 77enum STAT_TYPE
78{
78 STAT_TYPE_ROUNDS, /* 0 */ 79 STAT_TYPE_ROUNDS, /* 0 */
79 STAT_TYPE_BLOCKS, /* 1 */ 80 STAT_TYPE_BLOCKS, /* 1 */
80 STAT_TYPE_BLOCKS_MANY_PUSH, /* 2 */ 81 STAT_TYPE_BLOCKS_MANY_PUSH, /* 2 */
@@ -110,7 +111,7 @@ enum STAT_TYPE {
110 STAT_TYPE_MAX, /* 32 */ 111 STAT_TYPE_MAX, /* 32 */
111}; 112};
112 113
113static char* stat_type_strings[] = { 114static char*stat_type_strings[] = {
114 "# rounds", 115 "# rounds",
115 "# rounds blocked", 116 "# rounds blocked",
116 "# rounds blocked - too many pushes", 117 "# rounds blocked - too many pushes",
@@ -145,7 +146,8 @@ static char* stat_type_strings[] = {
145 "view size aim", 146 "view size aim",
146}; 147};
147 148
148struct STATcls { 149struct STATcls
150{
149 struct RPSPeer *rps_peer; 151 struct RPSPeer *rps_peer;
150 enum STAT_TYPE stat_type; 152 enum STAT_TYPE stat_type;
151}; 153};
@@ -158,200 +160,214 @@ struct STATcls {
158 * 160 *
159 * @return corresponding enum 161 * @return corresponding enum
160 */ 162 */
161enum STAT_TYPE stat_str_2_type(const char *stat_str) 163enum STAT_TYPE stat_str_2_type (const char *stat_str)
162{ 164{
163 if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS_NO_PULL], 165 if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_NO_PULL],
164 stat_str, 166 stat_str,
165 strlen(stat_type_strings[STAT_TYPE_BLOCKS_NO_PULL]))) 167 strlen (stat_type_strings[STAT_TYPE_BLOCKS_NO_PULL])))
166 { 168 {
167 return STAT_TYPE_BLOCKS_NO_PULL; 169 return STAT_TYPE_BLOCKS_NO_PULL;
168 } 170 }
169 else if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL], 171 else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL],
170 stat_str, 172 stat_str,
171 strlen(stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL]))) 173 strlen (
172 { 174 stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL])))
173 return STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL; 175 {
174 } 176 return STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL;
175 else if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH], 177 }
176 stat_str, 178 else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH],
177 strlen(stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH]))) 179 stat_str,
178 { 180 strlen (
179 return STAT_TYPE_BLOCKS_MANY_PUSH; 181 stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH])))
180 } 182 {
181 else if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL], 183 return STAT_TYPE_BLOCKS_MANY_PUSH;
182 stat_str, 184 }
183 strlen(stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL]))) 185 else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL],
184 { 186 stat_str,
185 return STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL; 187 strlen (
186 } 188 stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL])))
187 else if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH], 189 {
188 stat_str, 190 return STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL;
189 strlen(stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH]))) 191 }
190 { 192 else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH],
191 return STAT_TYPE_BLOCKS_NO_PUSH; 193 stat_str,
192 } 194 strlen (stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH])))
193 else if (0 == strncmp(stat_type_strings[STAT_TYPE_BLOCKS], 195 {
194 stat_str, 196 return STAT_TYPE_BLOCKS_NO_PUSH;
195 strlen(stat_type_strings[STAT_TYPE_BLOCKS]))) 197 }
196 { 198 else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS],
197 return STAT_TYPE_BLOCKS; 199 stat_str,
198 } 200 strlen (stat_type_strings[STAT_TYPE_BLOCKS])))
199 else if (0 == strncmp(stat_type_strings[STAT_TYPE_ROUNDS], 201 {
200 stat_str, 202 return STAT_TYPE_BLOCKS;
201 strlen(stat_type_strings[STAT_TYPE_ROUNDS]))) 203 }
202 { 204 else if (0 == strncmp (stat_type_strings[STAT_TYPE_ROUNDS],
203 return STAT_TYPE_ROUNDS; 205 stat_str,
204 } 206 strlen (stat_type_strings[STAT_TYPE_ROUNDS])))
205 else if (0 == strncmp(stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND], 207 {
206 stat_str, 208 return STAT_TYPE_ROUNDS;
207 strlen(stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND]))) 209 }
208 { 210 else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND],
209 return STAT_TYPE_ISSUED_PUSH_SEND; 211 stat_str,
210 } 212 strlen (
211 else if (0 == strncmp(stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND_MH], 213 stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND])))
212 stat_str, 214 {
213 strlen(stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND_MH]))) 215 return STAT_TYPE_ISSUED_PUSH_SEND;
214 { 216 }
215 return STAT_TYPE_ISSUED_PUSH_SEND_MH; 217 else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND_MH],
216 } 218 stat_str,
217 else if (0 == strncmp(stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ], 219 strlen (
218 stat_str, 220 stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND_MH])))
219 strlen(stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ]))) 221 {
220 { 222 return STAT_TYPE_ISSUED_PUSH_SEND_MH;
221 return STAT_TYPE_ISSUED_PULL_REQ; 223 }
222 } 224 else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ],
223 else if (0 == strncmp(stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ_MH], 225 stat_str,
224 stat_str, 226 strlen (stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ])))
225 strlen(stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ_MH]))) 227 {
226 { 228 return STAT_TYPE_ISSUED_PULL_REQ;
227 return STAT_TYPE_ISSUED_PULL_REQ_MH; 229 }
228 } 230 else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ_MH],
229 else if (0 == strncmp(stat_type_strings[STAT_TYPE_ISSUED_PULL_REP], 231 stat_str,
230 stat_str, 232 strlen (
231 strlen(stat_type_strings[STAT_TYPE_ISSUED_PULL_REP]))) 233 stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ_MH])))
232 { 234 {
233 return STAT_TYPE_ISSUED_PULL_REP; 235 return STAT_TYPE_ISSUED_PULL_REQ_MH;
234 } 236 }
235 else if (0 == strncmp(stat_type_strings[STAT_TYPE_SENT_PUSH_SEND], 237 else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PULL_REP],
236 stat_str, 238 stat_str,
237 strlen(stat_type_strings[STAT_TYPE_SENT_PUSH_SEND]))) 239 strlen (stat_type_strings[STAT_TYPE_ISSUED_PULL_REP])))
238 { 240 {
239 return STAT_TYPE_SENT_PUSH_SEND; 241 return STAT_TYPE_ISSUED_PULL_REP;
240 } 242 }
241 else if (0 == strncmp(stat_type_strings[STAT_TYPE_SENT_PULL_REQ], 243 else if (0 == strncmp (stat_type_strings[STAT_TYPE_SENT_PUSH_SEND],
242 stat_str, 244 stat_str,
243 strlen(stat_type_strings[STAT_TYPE_SENT_PULL_REQ]))) 245 strlen (stat_type_strings[STAT_TYPE_SENT_PUSH_SEND])))
244 { 246 {
245 return STAT_TYPE_SENT_PULL_REQ; 247 return STAT_TYPE_SENT_PUSH_SEND;
246 } 248 }
247 else if (0 == strncmp(stat_type_strings[STAT_TYPE_SENT_PULL_REQ_MH], 249 else if (0 == strncmp (stat_type_strings[STAT_TYPE_SENT_PULL_REQ],
248 stat_str, 250 stat_str,
249 strlen(stat_type_strings[STAT_TYPE_SENT_PULL_REQ_MH]))) 251 strlen (stat_type_strings[STAT_TYPE_SENT_PULL_REQ])))
250 { 252 {
251 return STAT_TYPE_SENT_PULL_REQ_MH; 253 return STAT_TYPE_SENT_PULL_REQ;
252 } 254 }
253 else if (0 == strncmp(stat_type_strings[STAT_TYPE_SENT_PULL_REP], 255 else if (0 == strncmp (stat_type_strings[STAT_TYPE_SENT_PULL_REQ_MH],
254 stat_str, 256 stat_str,
255 strlen(stat_type_strings[STAT_TYPE_SENT_PULL_REP]))) 257 strlen (
256 { 258 stat_type_strings[STAT_TYPE_SENT_PULL_REQ_MH])))
257 return STAT_TYPE_SENT_PULL_REP; 259 {
258 } 260 return STAT_TYPE_SENT_PULL_REQ_MH;
259 else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PUSH_SEND], 261 }
260 stat_str, 262 else if (0 == strncmp (stat_type_strings[STAT_TYPE_SENT_PULL_REP],
261 strlen(stat_type_strings[STAT_TYPE_RECV_PUSH_SEND]))) 263 stat_str,
262 { 264 strlen (stat_type_strings[STAT_TYPE_SENT_PULL_REP])))
263 return STAT_TYPE_RECV_PUSH_SEND; 265 {
264 } 266 return STAT_TYPE_SENT_PULL_REP;
265 else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PUSH_SEND_MH], 267 }
266 stat_str, 268 else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PUSH_SEND],
267 strlen(stat_type_strings[STAT_TYPE_RECV_PUSH_SEND_MH]))) 269 stat_str,
268 { 270 strlen (stat_type_strings[STAT_TYPE_RECV_PUSH_SEND])))
269 return STAT_TYPE_RECV_PUSH_SEND_MH; 271 {
270 } 272 return STAT_TYPE_RECV_PUSH_SEND;
271 else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PULL_REQ], 273 }
272 stat_str, 274 else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PUSH_SEND_MH],
273 strlen(stat_type_strings[STAT_TYPE_RECV_PULL_REQ]))) 275 stat_str,
274 { 276 strlen (
275 return STAT_TYPE_RECV_PULL_REQ; 277 stat_type_strings[STAT_TYPE_RECV_PUSH_SEND_MH])))
276 } 278 {
277 else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PULL_REQ_MH], 279 return STAT_TYPE_RECV_PUSH_SEND_MH;
278 stat_str, 280 }
279 strlen(stat_type_strings[STAT_TYPE_RECV_PULL_REQ_MH]))) 281 else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PULL_REQ],
280 { 282 stat_str,
281 return STAT_TYPE_RECV_PULL_REQ_MH; 283 strlen (stat_type_strings[STAT_TYPE_RECV_PULL_REQ])))
282 } 284 {
283 else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PULL_REP], 285 return STAT_TYPE_RECV_PULL_REQ;
284 stat_str, 286 }
285 strlen(stat_type_strings[STAT_TYPE_RECV_PULL_REP]))) 287 else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PULL_REQ_MH],
286 { 288 stat_str,
287 return STAT_TYPE_RECV_PULL_REP; 289 strlen (
288 } 290 stat_type_strings[STAT_TYPE_RECV_PULL_REQ_MH])))
289 else if (0 == strncmp(stat_type_strings[STAT_TYPE_RECV_PULL_REP_MH], 291 {
290 stat_str, 292 return STAT_TYPE_RECV_PULL_REQ_MH;
291 strlen(stat_type_strings[STAT_TYPE_RECV_PULL_REP_MH]))) 293 }
292 { 294 else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PULL_REP],
293 return STAT_TYPE_RECV_PULL_REP_MH; 295 stat_str,
294 } 296 strlen (stat_type_strings[STAT_TYPE_RECV_PULL_REP])))
295 else if (0 == strncmp(stat_type_strings[STAT_TYPE_VIEW_SIZE], 297 {
296 stat_str, 298 return STAT_TYPE_RECV_PULL_REP;
297 strlen(stat_type_strings[STAT_TYPE_VIEW_SIZE]))) 299 }
298 { 300 else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PULL_REP_MH],
299 return STAT_TYPE_VIEW_SIZE; 301 stat_str,
300 } 302 strlen (
301 else if (0 == strncmp(stat_type_strings[STAT_TYPE_KNOWN_PEERS], 303 stat_type_strings[STAT_TYPE_RECV_PULL_REP_MH])))
302 stat_str, 304 {
303 strlen(stat_type_strings[STAT_TYPE_KNOWN_PEERS]))) 305 return STAT_TYPE_RECV_PULL_REP_MH;
304 { 306 }
305 return STAT_TYPE_KNOWN_PEERS; 307 else if (0 == strncmp (stat_type_strings[STAT_TYPE_VIEW_SIZE],
306 } 308 stat_str,
307 else if (0 == strncmp(stat_type_strings[STAT_TYPE_VALID_PEERS], 309 strlen (stat_type_strings[STAT_TYPE_VIEW_SIZE])))
308 stat_str, 310 {
309 strlen(stat_type_strings[STAT_TYPE_VALID_PEERS]))) 311 return STAT_TYPE_VIEW_SIZE;
310 { 312 }
311 return STAT_TYPE_VALID_PEERS; 313 else if (0 == strncmp (stat_type_strings[STAT_TYPE_KNOWN_PEERS],
312 } 314 stat_str,
313 else if (0 == strncmp(stat_type_strings[STAT_TYPE_LEARND_PEERS], 315 strlen (stat_type_strings[STAT_TYPE_KNOWN_PEERS])))
314 stat_str, 316 {
315 strlen(stat_type_strings[STAT_TYPE_LEARND_PEERS]))) 317 return STAT_TYPE_KNOWN_PEERS;
316 { 318 }
317 return STAT_TYPE_LEARND_PEERS; 319 else if (0 == strncmp (stat_type_strings[STAT_TYPE_VALID_PEERS],
318 } 320 stat_str,
319 else if (0 == strncmp(stat_type_strings[STAT_TYPE_PENDING_ONLINE_CHECKS], 321 strlen (stat_type_strings[STAT_TYPE_VALID_PEERS])))
320 stat_str, 322 {
321 strlen(stat_type_strings[STAT_TYPE_PENDING_ONLINE_CHECKS]))) 323 return STAT_TYPE_VALID_PEERS;
322 { 324 }
323 return STAT_TYPE_PENDING_ONLINE_CHECKS; 325 else if (0 == strncmp (stat_type_strings[STAT_TYPE_LEARND_PEERS],
324 } 326 stat_str,
325 else if (0 == strncmp(stat_type_strings[STAT_TYPE_UNREQUESTED_PULL_REPLIES], 327 strlen (stat_type_strings[STAT_TYPE_LEARND_PEERS])))
326 stat_str, 328 {
327 strlen(stat_type_strings[STAT_TYPE_UNREQUESTED_PULL_REPLIES]))) 329 return STAT_TYPE_LEARND_PEERS;
328 { 330 }
329 return STAT_TYPE_UNREQUESTED_PULL_REPLIES; 331 else if (0 == strncmp (stat_type_strings[STAT_TYPE_PENDING_ONLINE_CHECKS],
330 } 332 stat_str,
331 else if (0 == strncmp(stat_type_strings[STAT_TYPE_PEERS_IN_PUSH_MAP], 333 strlen (
332 stat_str, 334 stat_type_strings[STAT_TYPE_PENDING_ONLINE_CHECKS])))
333 strlen(stat_type_strings[STAT_TYPE_PEERS_IN_PUSH_MAP]))) 335 {
334 { 336 return STAT_TYPE_PENDING_ONLINE_CHECKS;
335 return STAT_TYPE_PEERS_IN_PUSH_MAP; 337 }
336 } 338 else if (0 == strncmp (stat_type_strings[STAT_TYPE_UNREQUESTED_PULL_REPLIES],
337 else if (0 == strncmp(stat_type_strings[STAT_TYPE_PEERS_IN_PULL_MAP], 339 stat_str,
338 stat_str, 340 strlen (
339 strlen(stat_type_strings[STAT_TYPE_PEERS_IN_PULL_MAP]))) 341 stat_type_strings[STAT_TYPE_UNREQUESTED_PULL_REPLIES])))
340 { 342 {
341 return STAT_TYPE_PEERS_IN_PULL_MAP; 343 return STAT_TYPE_UNREQUESTED_PULL_REPLIES;
342 } 344 }
343 else if (0 == strncmp(stat_type_strings[STAT_TYPE_PEERS_IN_VIEW], 345 else if (0 == strncmp (stat_type_strings[STAT_TYPE_PEERS_IN_PUSH_MAP],
344 stat_str, 346 stat_str,
345 strlen(stat_type_strings[STAT_TYPE_PEERS_IN_VIEW]))) 347 strlen (
346 { 348 stat_type_strings[STAT_TYPE_PEERS_IN_PUSH_MAP])))
347 return STAT_TYPE_PEERS_IN_VIEW; 349 {
348 } 350 return STAT_TYPE_PEERS_IN_PUSH_MAP;
349 else if (0 == strncmp(stat_type_strings[STAT_TYPE_VIEW_SIZE_AIM], 351 }
350 stat_str, 352 else if (0 == strncmp (stat_type_strings[STAT_TYPE_PEERS_IN_PULL_MAP],
351 strlen(stat_type_strings[STAT_TYPE_VIEW_SIZE_AIM]))) 353 stat_str,
352 { 354 strlen (
353 return STAT_TYPE_VIEW_SIZE_AIM; 355 stat_type_strings[STAT_TYPE_PEERS_IN_PULL_MAP])))
354 } 356 {
357 return STAT_TYPE_PEERS_IN_PULL_MAP;
358 }
359 else if (0 == strncmp (stat_type_strings[STAT_TYPE_PEERS_IN_VIEW],
360 stat_str,
361 strlen (stat_type_strings[STAT_TYPE_PEERS_IN_VIEW])))
362 {
363 return STAT_TYPE_PEERS_IN_VIEW;
364 }
365 else if (0 == strncmp (stat_type_strings[STAT_TYPE_VIEW_SIZE_AIM],
366 stat_str,
367 strlen (stat_type_strings[STAT_TYPE_VIEW_SIZE_AIM])))
368 {
369 return STAT_TYPE_VIEW_SIZE_AIM;
370 }
355 return STAT_TYPE_MAX; 371 return STAT_TYPE_MAX;
356} 372}
357 373
@@ -359,7 +375,8 @@ enum STAT_TYPE stat_str_2_type(const char *stat_str)
359/** 375/**
360 * @brief Indicates whether peer should go off- or online 376 * @brief Indicates whether peer should go off- or online
361 */ 377 */
362enum PEER_ONLINE_DELTA { 378enum PEER_ONLINE_DELTA
379{
363 /** 380 /**
364 * @brief Indicates peer going online 381 * @brief Indicates peer going online
365 */ 382 */
@@ -373,7 +390,8 @@ enum PEER_ONLINE_DELTA {
373/** 390/**
374 * Operation map entry 391 * Operation map entry
375 */ 392 */
376struct OpListEntry { 393struct OpListEntry
394{
377 /** 395 /**
378 * DLL next ptr 396 * DLL next ptr
379 */ 397 */
@@ -415,7 +433,8 @@ static struct OpListEntry *oplist_tail;
415/** 433/**
416 * A pending reply: A request was sent and the reply is pending. 434 * A pending reply: A request was sent and the reply is pending.
417 */ 435 */
418struct PendingReply { 436struct PendingReply
437{
419 /** 438 /**
420 * DLL next,prev ptr 439 * DLL next,prev ptr
421 */ 440 */
@@ -437,7 +456,8 @@ struct PendingReply {
437/** 456/**
438 * A pending request: A request was not made yet but is scheduled for later. 457 * A pending request: A request was not made yet but is scheduled for later.
439 */ 458 */
440struct PendingRequest { 459struct PendingRequest
460{
441 /** 461 /**
442 * DLL next,prev ptr 462 * DLL next,prev ptr
443 */ 463 */
@@ -459,7 +479,8 @@ struct PendingRequest {
459/** 479/**
460 * Information we track for each peer. 480 * Information we track for each peer.
461 */ 481 */
462struct RPSPeer { 482struct RPSPeer
483{
463 /** 484 /**
464 * Index of the peer. 485 * Index of the peer.
465 */ 486 */
@@ -483,7 +504,7 @@ struct RPSPeer {
483 /** 504 /**
484 * A request handle to check for an request 505 * A request handle to check for an request
485 */ 506 */
486 //struct GNUNET_RPS_Request_Handle *req_handle; 507 // struct GNUNET_RPS_Request_Handle *req_handle;
487 508
488 /** 509 /**
489 * Peer on- or offline? 510 * Peer on- or offline?
@@ -685,7 +706,8 @@ typedef int (*EvaluationCallback) (void);
685/** 706/**
686 * @brief Do we have Churn? 707 * @brief Do we have Churn?
687 */ 708 */
688enum OPTION_CHURN { 709enum OPTION_CHURN
710{
689 /** 711 /**
690 * @brief If we have churn this is set 712 * @brief If we have churn this is set
691 */ 713 */
@@ -699,7 +721,8 @@ enum OPTION_CHURN {
699/** 721/**
700 * @brief Is it ok to quit the test before the timeout? 722 * @brief Is it ok to quit the test before the timeout?
701 */ 723 */
702enum OPTION_QUICK_QUIT { 724enum OPTION_QUICK_QUIT
725{
703 /** 726 /**
704 * @brief It is ok for the test to quit before the timeout triggers 727 * @brief It is ok for the test to quit before the timeout triggers
705 */ 728 */
@@ -714,7 +737,8 @@ enum OPTION_QUICK_QUIT {
714/** 737/**
715 * @brief Do we collect statistics at the end? 738 * @brief Do we collect statistics at the end?
716 */ 739 */
717enum OPTION_COLLECT_STATISTICS { 740enum OPTION_COLLECT_STATISTICS
741{
718 /** 742 /**
719 * @brief We collect statistics at the end 743 * @brief We collect statistics at the end
720 */ 744 */
@@ -729,7 +753,8 @@ enum OPTION_COLLECT_STATISTICS {
729/** 753/**
730 * @brief Do we collect views during run? 754 * @brief Do we collect views during run?
731 */ 755 */
732enum OPTION_COLLECT_VIEW { 756enum OPTION_COLLECT_VIEW
757{
733 /** 758 /**
734 * @brief We collect view during run 759 * @brief We collect view during run
735 */ 760 */
@@ -744,7 +769,8 @@ enum OPTION_COLLECT_VIEW {
744/** 769/**
745 * Structure to define a single test 770 * Structure to define a single test
746 */ 771 */
747struct SingleTestRun { 772struct SingleTestRun
773{
748 /** 774 /**
749 * Name of the test 775 * Name of the test
750 */ 776 */
@@ -831,7 +857,7 @@ static int in_shutdown;
831 * Append arguments to file 857 * Append arguments to file
832 */ 858 */
833static void 859static void
834tofile_(const char *file_name, const char *line) 860tofile_ (const char *file_name, const char *line)
835{ 861{
836 struct GNUNET_DISK_FileHandle *f; 862 struct GNUNET_DISK_FileHandle *f;
837 /* char output_buffer[512]; */ 863 /* char output_buffer[512]; */
@@ -839,20 +865,20 @@ tofile_(const char *file_name, const char *line)
839 /* int size; */ 865 /* int size; */
840 size_t size2; 866 size_t size2;
841 867
842 if (NULL == (f = GNUNET_DISK_file_open(file_name, 868 if (NULL == (f = GNUNET_DISK_file_open (file_name,
843 GNUNET_DISK_OPEN_APPEND | 869 GNUNET_DISK_OPEN_APPEND
844 GNUNET_DISK_OPEN_WRITE | 870 | GNUNET_DISK_OPEN_WRITE
845 GNUNET_DISK_OPEN_CREATE, 871 | GNUNET_DISK_OPEN_CREATE,
846 GNUNET_DISK_PERM_USER_READ | 872 GNUNET_DISK_PERM_USER_READ
847 GNUNET_DISK_PERM_USER_WRITE | 873 | GNUNET_DISK_PERM_USER_WRITE
848 GNUNET_DISK_PERM_GROUP_READ | 874 | GNUNET_DISK_PERM_GROUP_READ
849 GNUNET_DISK_PERM_OTHER_READ))) 875 | GNUNET_DISK_PERM_OTHER_READ)))
850 { 876 {
851 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 877 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
852 "Not able to open file %s\n", 878 "Not able to open file %s\n",
853 file_name); 879 file_name);
854 return; 880 return;
855 } 881 }
856 /* size = GNUNET_snprintf (output_buffer, 882 /* size = GNUNET_snprintf (output_buffer,
857 sizeof (output_buffer), 883 sizeof (output_buffer),
858 "%llu %s\n", 884 "%llu %s\n",
@@ -866,43 +892,43 @@ tofile_(const char *file_name, const char *line)
866 return; 892 return;
867 } */ 893 } */
868 894
869 size = strlen(line) * sizeof(char); 895 size = strlen (line) * sizeof(char);
870 896
871 size2 = GNUNET_DISK_file_write(f, line, size); 897 size2 = GNUNET_DISK_file_write (f, line, size);
872 if (size != size2) 898 if (size != size2)
899 {
900 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
901 "Unable to write to file! (Size: %lu, size2: %lu)\n",
902 size,
903 size2);
904 if (GNUNET_YES != GNUNET_DISK_file_close (f))
873 { 905 {
874 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 906 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
875 "Unable to write to file! (Size: %lu, size2: %lu)\n", 907 "Unable to close file\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;
884 } 908 }
909 return;
910 }
885 911
886 if (GNUNET_YES != GNUNET_DISK_file_close(f)) 912 if (GNUNET_YES != GNUNET_DISK_file_close (f))
887 { 913 {
888 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 914 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
889 "Unable to close file\n"); 915 "Unable to close file\n");
890 } 916 }
891} 917}
892 918
893/** 919/**
894 * This function is used to facilitate writing important information to disk 920 * This function is used to facilitate writing important information to disk
895 */ 921 */
896#define tofile(file_name, ...) do { \ 922#define tofile(file_name, ...) do { \
897 char tmp_buf[512]; \ 923 char tmp_buf[512]; \
898 int size; \ 924 int size; \
899 size = GNUNET_snprintf(tmp_buf, sizeof(tmp_buf), __VA_ARGS__); \ 925 size = GNUNET_snprintf (tmp_buf, sizeof(tmp_buf), __VA_ARGS__); \
900 if (0 > size) \ 926 if (0 > size) \
901 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \ 927 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \
902 "Failed to create tmp_buf\n"); \ 928 "Failed to create tmp_buf\n"); \
903 else \ 929 else \
904 tofile_ (file_name, tmp_buf); \ 930 tofile_ (file_name, tmp_buf); \
905 } while (0); 931} while (0);
906 932
907 933
908/** 934/**
@@ -929,7 +955,7 @@ tofile_(const char *file_name, const char *line)
929 * Test the success of a single test 955 * Test the success of a single test
930 */ 956 */
931static int 957static int
932evaluate(void) 958evaluate (void)
933{ 959{
934 unsigned int i; 960 unsigned int i;
935 int tmp_ok; 961 int tmp_ok;
@@ -937,16 +963,16 @@ evaluate(void)
937 tmp_ok = 1; 963 tmp_ok = 1;
938 964
939 for (i = 0; i < num_peers; i++) 965 for (i = 0; i < num_peers; i++)
940 { 966 {
941 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 967 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
942 "%u. peer [%s] received %u of %u expected peer_ids: %i\n", 968 "%u. peer [%s] received %u of %u expected peer_ids: %i\n",
943 i, 969 i,
944 GNUNET_i2s(rps_peers[i].peer_id), 970 GNUNET_i2s (rps_peers[i].peer_id),
945 rps_peers[i].num_recv_ids, 971 rps_peers[i].num_recv_ids,
946 rps_peers[i].num_ids_to_request, 972 rps_peers[i].num_ids_to_request,
947 (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids)); 973 (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); 974 tmp_ok &= (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids);
949 } 975 }
950 return tmp_ok ? 0 : 1; 976 return tmp_ok ? 0 : 1;
951} 977}
952 978
@@ -955,12 +981,12 @@ evaluate(void)
955 * Creates an oplist entry and adds it to the oplist DLL 981 * Creates an oplist entry and adds it to the oplist DLL
956 */ 982 */
957static struct OpListEntry * 983static struct OpListEntry *
958make_oplist_entry() 984make_oplist_entry ()
959{ 985{
960 struct OpListEntry *entry; 986 struct OpListEntry *entry;
961 987
962 entry = GNUNET_new(struct OpListEntry); 988 entry = GNUNET_new (struct OpListEntry);
963 GNUNET_CONTAINER_DLL_insert_tail(oplist_head, oplist_tail, entry); 989 GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry);
964 return entry; 990 return entry;
965} 991}
966 992
@@ -974,15 +1000,15 @@ make_oplist_entry()
974 * @return #GNUNET_YES if so 1000 * @return #GNUNET_YES if so
975 * #GNUNET_NO otherwise 1001 * #GNUNET_NO otherwise
976 */ 1002 */
977static int check_statistics_collect_completed_single_peer( 1003static int check_statistics_collect_completed_single_peer (
978 const struct RPSPeer *rps_peer) 1004 const struct RPSPeer *rps_peer)
979{ 1005{
980 if (cur_test_run.stat_collect_flags != 1006 if (cur_test_run.stat_collect_flags !=
981 (cur_test_run.stat_collect_flags & 1007 (cur_test_run.stat_collect_flags
982 rps_peer->stat_collected_flags)) 1008 & rps_peer->stat_collected_flags))
983 { 1009 {
984 return GNUNET_NO; 1010 return GNUNET_NO;
985 } 1011 }
986 return GNUNET_YES; 1012 return GNUNET_YES;
987} 1013}
988/** 1014/**
@@ -992,153 +1018,155 @@ static int check_statistics_collect_completed_single_peer(
992 * @return #GNUNET_YES if so 1018 * @return #GNUNET_YES if so
993 * #GNUNET_NO otherwise 1019 * #GNUNET_NO otherwise
994 */ 1020 */
995static int check_statistics_collect_completed() 1021static int check_statistics_collect_completed ()
996{ 1022{
997 uint32_t i; 1023 uint32_t i;
998 1024
999 for (i = 0; i < num_peers; i++) 1025 for (i = 0; i < num_peers; i++)
1000 { 1026 {
1001 if (GNUNET_NO == check_statistics_collect_completed_single_peer(&rps_peers[i])) 1027 if (GNUNET_NO == check_statistics_collect_completed_single_peer (
1002 { 1028 &rps_peers[i]))
1003 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1029 {
1004 "At least Peer %" PRIu32 " did not yet receive all statistics values\n", 1030 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1005 i); 1031 "At least Peer %" PRIu32
1006 return GNUNET_NO; 1032 " did not yet receive all statistics values\n",
1007 } 1033 i);
1034 return GNUNET_NO;
1008 } 1035 }
1009 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1036 }
1010 "All peers received their statistics values\n"); 1037 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1038 "All peers received their statistics values\n");
1011 return GNUNET_YES; 1039 return GNUNET_YES;
1012} 1040}
1013 1041
1014static void 1042static void
1015rps_disconnect_adapter(void *cls, 1043rps_disconnect_adapter (void *cls,
1016 void *op_result); 1044 void *op_result);
1017 1045
1018static void 1046static void
1019cancel_pending_req(struct PendingRequest *pending_req) 1047cancel_pending_req (struct PendingRequest *pending_req)
1020{ 1048{
1021 struct RPSPeer *rps_peer; 1049 struct RPSPeer *rps_peer;
1022 1050
1023 rps_peer = pending_req->rps_peer; 1051 rps_peer = pending_req->rps_peer;
1024 GNUNET_CONTAINER_DLL_remove(rps_peer->pending_req_head, 1052 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head,
1025 rps_peer->pending_req_tail, 1053 rps_peer->pending_req_tail,
1026 pending_req); 1054 pending_req);
1027 rps_peer->num_pending_reqs--; 1055 rps_peer->num_pending_reqs--;
1028 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1056 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1029 "Cancelling pending rps get request\n"); 1057 "Cancelling pending rps get request\n");
1030 GNUNET_SCHEDULER_cancel(pending_req->request_task); 1058 GNUNET_SCHEDULER_cancel (pending_req->request_task);
1031 GNUNET_free(pending_req); 1059 GNUNET_free (pending_req);
1032} 1060}
1033 1061
1034static void 1062static void
1035cancel_request(struct PendingReply *pending_rep) 1063cancel_request (struct PendingReply *pending_rep)
1036{ 1064{
1037 struct RPSPeer *rps_peer; 1065 struct RPSPeer *rps_peer;
1038 1066
1039 rps_peer = pending_rep->rps_peer; 1067 rps_peer = pending_rep->rps_peer;
1040 GNUNET_CONTAINER_DLL_remove(rps_peer->pending_rep_head, 1068 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head,
1041 rps_peer->pending_rep_tail, 1069 rps_peer->pending_rep_tail,
1042 pending_rep); 1070 pending_rep);
1043 rps_peer->num_pending_reps--; 1071 rps_peer->num_pending_reps--;
1044 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1072 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1045 "Cancelling rps get reply\n"); 1073 "Cancelling rps get reply\n");
1046 GNUNET_assert(NULL != pending_rep->req_handle); 1074 GNUNET_assert (NULL != pending_rep->req_handle);
1047 GNUNET_RPS_request_single_info_cancel(pending_rep->req_handle); 1075 GNUNET_RPS_request_single_info_cancel (pending_rep->req_handle);
1048 pending_rep->req_handle = NULL; 1076 pending_rep->req_handle = NULL;
1049 GNUNET_free(pending_rep); 1077 GNUNET_free (pending_rep);
1050 pending_rep = NULL; 1078 pending_rep = NULL;
1051} 1079}
1052 1080
1053void 1081void
1054clean_peer(unsigned peer_index) 1082clean_peer (unsigned peer_index)
1055{ 1083{
1056 struct PendingRequest *pending_req; 1084 struct PendingRequest *pending_req;
1057 1085
1058 while (NULL != (pending_req = rps_peers[peer_index].pending_req_head)) 1086 while (NULL != (pending_req = rps_peers[peer_index].pending_req_head))
1059 { 1087 {
1060 cancel_pending_req(pending_req); 1088 cancel_pending_req (pending_req);
1061 } 1089 }
1062 pending_req = rps_peers[peer_index].pending_req_head; 1090 pending_req = rps_peers[peer_index].pending_req_head;
1063 rps_disconnect_adapter(&rps_peers[peer_index], 1091 rps_disconnect_adapter (&rps_peers[peer_index],
1064 &rps_peers[peer_index].rps_handle); 1092 &rps_peers[peer_index].rps_handle);
1065 for (unsigned stat_type = STAT_TYPE_ROUNDS; 1093 for (unsigned stat_type = STAT_TYPE_ROUNDS;
1066 stat_type < STAT_TYPE_MAX; 1094 stat_type < STAT_TYPE_MAX;
1067 stat_type++) 1095 stat_type++)
1096 {
1097 if (NULL != rps_peers[peer_index].h_stat_get[stat_type])
1068 { 1098 {
1069 if (NULL != rps_peers[peer_index].h_stat_get[stat_type]) 1099 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1070 { 1100 "(%u) did not yet receive stat value for `%s'\n",
1071 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1101 rps_peers[peer_index].index,
1072 "(%u) did not yet receive stat value for `%s'\n", 1102 stat_type_strings[stat_type]);
1073 rps_peers[peer_index].index, 1103 GNUNET_STATISTICS_get_cancel (
1074 stat_type_strings[stat_type]); 1104 rps_peers[peer_index].h_stat_get[stat_type]);
1075 GNUNET_STATISTICS_get_cancel(
1076 rps_peers[peer_index].h_stat_get[stat_type]);
1077 }
1078 } 1105 }
1106 }
1079 if (NULL != rps_peers[peer_index].op) 1107 if (NULL != rps_peers[peer_index].op)
1080 { 1108 {
1081 GNUNET_TESTBED_operation_done(rps_peers[peer_index].op); 1109 GNUNET_TESTBED_operation_done (rps_peers[peer_index].op);
1082 rps_peers[peer_index].op = NULL; 1110 rps_peers[peer_index].op = NULL;
1083 } 1111 }
1084} 1112}
1085 1113
1086/** 1114/**
1087 * Task run on timeout to shut everything down. 1115 * Task run on timeout to shut everything down.
1088 */ 1116 */
1089static void 1117static void
1090shutdown_op(void *cls) 1118shutdown_op (void *cls)
1091{ 1119{
1092 unsigned int i; 1120 unsigned int i;
1093 struct OpListEntry *entry; 1121 struct OpListEntry *entry;
1094 1122
1095 (void)cls; 1123 (void) cls;
1096 1124
1097 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1125 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1098 "Shutdown task scheduled, going down.\n"); 1126 "Shutdown task scheduled, going down.\n");
1099 in_shutdown = GNUNET_YES; 1127 in_shutdown = GNUNET_YES;
1100 1128
1101 if (NULL != shutdown_task) 1129 if (NULL != shutdown_task)
1102 { 1130 {
1103 GNUNET_SCHEDULER_cancel(shutdown_task); 1131 GNUNET_SCHEDULER_cancel (shutdown_task);
1104 shutdown_task = NULL; 1132 shutdown_task = NULL;
1105 } 1133 }
1106 if (NULL != post_test_task) 1134 if (NULL != post_test_task)
1107 { 1135 {
1108 GNUNET_SCHEDULER_cancel(post_test_task); 1136 GNUNET_SCHEDULER_cancel (post_test_task);
1109 post_test_task = NULL; 1137 post_test_task = NULL;
1110 } 1138 }
1111 if (NULL != churn_task) 1139 if (NULL != churn_task)
1112 { 1140 {
1113 GNUNET_SCHEDULER_cancel(churn_task); 1141 GNUNET_SCHEDULER_cancel (churn_task);
1114 churn_task = NULL; 1142 churn_task = NULL;
1115 } 1143 }
1116 entry = oplist_head; 1144 entry = oplist_head;
1117 while (NULL != (entry = oplist_head)) 1145 while (NULL != (entry = oplist_head))
1118 { 1146 {
1119 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1147 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1120 "Operation still pending on shutdown (%u)\n", 1148 "Operation still pending on shutdown (%u)\n",
1121 entry->index); 1149 entry->index);
1122 GNUNET_TESTBED_operation_done(entry->op); 1150 GNUNET_TESTBED_operation_done (entry->op);
1123 GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, entry); 1151 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
1124 GNUNET_free(entry); 1152 GNUNET_free (entry);
1125 } 1153 }
1126 for (i = 0; i < num_peers; i++) 1154 for (i = 0; i < num_peers; i++)
1127 { 1155 {
1128 clean_peer(i); 1156 clean_peer (i);
1129 } 1157 }
1130 close_all_files(); 1158 close_all_files ();
1131} 1159}
1132 1160
1133static void 1161static void
1134trigger_shutdown(void *cls) 1162trigger_shutdown (void *cls)
1135{ 1163{
1136 (void)cls; 1164 (void) cls;
1137 1165
1138 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1166 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1139 "Shutdown was triggerd by timeout, going down.\n"); 1167 "Shutdown was triggerd by timeout, going down.\n");
1140 shutdown_task = NULL; 1168 shutdown_task = NULL;
1141 GNUNET_SCHEDULER_shutdown(); 1169 GNUNET_SCHEDULER_shutdown ();
1142} 1170}
1143 1171
1144 1172
@@ -1146,47 +1174,48 @@ trigger_shutdown(void *cls)
1146 * Task run after #duration to collect statistics and potentially shut down. 1174 * Task run after #duration to collect statistics and potentially shut down.
1147 */ 1175 */
1148static void 1176static void
1149post_test_op(void *cls) 1177post_test_op (void *cls)
1150{ 1178{
1151 unsigned int i; 1179 unsigned int i;
1152 1180
1153 (void)cls; 1181 (void) cls;
1154 1182
1155 post_test_task = NULL; 1183 post_test_task = NULL;
1156 post_test = GNUNET_YES; 1184 post_test = GNUNET_YES;
1157 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1158 "Executing post test op.\n"); 1186 "Executing post test op.\n");
1159 if (NULL != churn_task) 1187 if (NULL != churn_task)
1160 { 1188 {
1161 GNUNET_SCHEDULER_cancel(churn_task); 1189 GNUNET_SCHEDULER_cancel (churn_task);
1162 churn_task = NULL; 1190 churn_task = NULL;
1163 } 1191 }
1164 for (i = 0; i < num_peers; i++) 1192 for (i = 0; i < num_peers; i++)
1193 {
1194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1195 "Executing post test op. (peer %" PRIu32 ")\n",
1196 rps_peers[i].index);
1197 if (NULL != rps_peers[i].op)
1165 { 1198 {
1166 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1199 GNUNET_TESTBED_operation_done (rps_peers[i].op);
1167 "Executing post test op. (peer %" PRIu32 ")\n", 1200 rps_peers[i].op = NULL;
1168 rps_peers[i].index); 1201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1169 if (NULL != rps_peers[i].op) 1202 "Cancelled testbed operation\n");
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 }
1181 } 1203 }
1182 /* If we do not collect statistics, shut down directly */ 1204 if (NULL != cur_test_run.post_test)
1183 if (NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics ||
1184 GNUNET_YES == check_statistics_collect_completed())
1185 { 1205 {
1186 GNUNET_SCHEDULER_cancel(shutdown_task); 1206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n",
1187 shutdown_task = NULL; 1207 i);
1188 GNUNET_SCHEDULER_shutdown(); 1208 cur_test_run.post_test (&rps_peers[i]);
1189 } 1209 }
1210 }
1211 /* If we do not collect statistics, shut down directly */
1212 if ((NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics)||
1213 (GNUNET_YES == check_statistics_collect_completed ()) )
1214 {
1215 GNUNET_SCHEDULER_cancel (shutdown_task);
1216 shutdown_task = NULL;
1217 GNUNET_SCHEDULER_shutdown ();
1218 }
1190} 1219}
1191 1220
1192 1221
@@ -1194,22 +1223,22 @@ post_test_op(void *cls)
1194 * Seed peers. 1223 * Seed peers.
1195 */ 1224 */
1196static void 1225static void
1197seed_peers(void *cls) 1226seed_peers (void *cls)
1198{ 1227{
1199 struct RPSPeer *peer = cls; 1228 struct RPSPeer *peer = cls;
1200 unsigned int amount; 1229 unsigned int amount;
1201 unsigned int i; 1230 unsigned int i;
1202 1231
1203 // TODO if malicious don't seed mal peers 1232 // TODO if malicious don't seed mal peers
1204 amount = round(.5 * num_peers); 1233 amount = round (.5 * num_peers);
1205 1234
1206 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n"); 1235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n");
1207 for (i = 0; i < amount; i++) 1236 for (i = 0; i < amount; i++)
1208 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n", 1237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n",
1209 i, 1238 i,
1210 GNUNET_i2s(&rps_peer_ids[i])); 1239 GNUNET_i2s (&rps_peer_ids[i]));
1211 1240
1212 GNUNET_RPS_seed_ids(peer->rps_handle, amount, rps_peer_ids); 1241 GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids);
1213} 1242}
1214 1243
1215 1244
@@ -1217,48 +1246,48 @@ seed_peers(void *cls)
1217 * Get the id of peer i. 1246 * Get the id of peer i.
1218 */ 1247 */
1219void 1248void
1220info_cb(void *cb_cls, 1249info_cb (void *cb_cls,
1221 struct GNUNET_TESTBED_Operation *op, 1250 struct GNUNET_TESTBED_Operation *op,
1222 const struct GNUNET_TESTBED_PeerInformation *pinfo, 1251 const struct GNUNET_TESTBED_PeerInformation *pinfo,
1223 const char *emsg) 1252 const char *emsg)
1224{ 1253{
1225 struct OpListEntry *entry = (struct OpListEntry *)cb_cls; 1254 struct OpListEntry *entry = (struct OpListEntry *) cb_cls;
1226 1255
1227 (void)op; 1256 (void) op;
1228 1257
1229 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1258 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
1230 { 1259 {
1231 return; 1260 return;
1232 } 1261 }
1233 1262
1234 if (NULL == pinfo || NULL != emsg) 1263 if ((NULL == pinfo)||(NULL != emsg))
1235 { 1264 {
1236 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg); 1265 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg);
1237 GNUNET_TESTBED_operation_done(entry->op); 1266 GNUNET_TESTBED_operation_done (entry->op);
1238 return; 1267 return;
1239 } 1268 }
1240 1269
1241 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1242 "Peer %u is %s\n", 1271 "Peer %u is %s\n",
1243 entry->index, 1272 entry->index,
1244 GNUNET_i2s(pinfo->result.id)); 1273 GNUNET_i2s (pinfo->result.id));
1245 1274
1246 rps_peer_ids[entry->index] = *(pinfo->result.id); 1275 rps_peer_ids[entry->index] = *(pinfo->result.id);
1247 rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index]; 1276 rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index];
1248 1277
1249 GNUNET_assert(GNUNET_OK == 1278 GNUNET_assert (GNUNET_OK ==
1250 GNUNET_CONTAINER_multipeermap_put(peer_map, 1279 GNUNET_CONTAINER_multipeermap_put (peer_map,
1251 &rps_peer_ids[entry->index], 1280 &rps_peer_ids[entry->index],
1252 &rps_peers[entry->index], 1281 &rps_peers[entry->index],
1253 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1282 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1254 tofile("/tmp/rps/peer_ids", 1283 tofile ("/tmp/rps/peer_ids",
1255 "%u\t%s\n", 1284 "%u\t%s\n",
1256 entry->index, 1285 entry->index,
1257 GNUNET_i2s_full(&rps_peer_ids[entry->index])); 1286 GNUNET_i2s_full (&rps_peer_ids[entry->index]));
1258 1287
1259 GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, entry); 1288 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
1260 GNUNET_TESTBED_operation_done(entry->op); 1289 GNUNET_TESTBED_operation_done (entry->op);
1261 GNUNET_free(entry); 1290 GNUNET_free (entry);
1262} 1291}
1263 1292
1264 1293
@@ -1272,39 +1301,39 @@ info_cb(void *cb_cls,
1272 * operation has executed successfully. 1301 * operation has executed successfully.
1273 */ 1302 */
1274static void 1303static void
1275rps_connect_complete_cb(void *cls, 1304rps_connect_complete_cb (void *cls,
1276 struct GNUNET_TESTBED_Operation *op, 1305 struct GNUNET_TESTBED_Operation *op,
1277 void *ca_result, 1306 void *ca_result,
1278 const char *emsg) 1307 const char *emsg)
1279{ 1308{
1280 struct RPSPeer *rps_peer = cls; 1309 struct RPSPeer *rps_peer = cls;
1281 struct GNUNET_RPS_Handle *rps = ca_result; 1310 struct GNUNET_RPS_Handle *rps = ca_result;
1282 1311
1283 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1312 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
1284 { 1313 {
1285 return; 1314 return;
1286 } 1315 }
1287 1316
1288 rps_peer->rps_handle = rps; 1317 rps_peer->rps_handle = rps;
1289 rps_peer->online = GNUNET_YES; 1318 rps_peer->online = GNUNET_YES;
1290 num_peers_online++; 1319 num_peers_online++;
1291 1320
1292 GNUNET_assert(op == rps_peer->op); 1321 GNUNET_assert (op == rps_peer->op);
1293 if (NULL != emsg) 1322 if (NULL != emsg)
1294 { 1323 {
1295 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1324 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1296 "Failed to connect to RPS service: %s\n", 1325 "Failed to connect to RPS service: %s\n",
1297 emsg); 1326 emsg);
1298 ok = 1; 1327 ok = 1;
1299 GNUNET_SCHEDULER_shutdown(); 1328 GNUNET_SCHEDULER_shutdown ();
1300 return; 1329 return;
1301 } 1330 }
1302 1331
1303 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1304 "Started client successfully (%u)\n", 1333 "Started client successfully (%u)\n",
1305 rps_peer->index); 1334 rps_peer->index);
1306 1335
1307 cur_test_run.main_test(rps_peer); 1336 cur_test_run.main_test (rps_peer);
1308} 1337}
1309 1338
1310 1339
@@ -1319,15 +1348,15 @@ rps_connect_complete_cb(void *cls,
1319 * @return service handle to return in 'op_result', NULL on error 1348 * @return service handle to return in 'op_result', NULL on error
1320 */ 1349 */
1321static void * 1350static void *
1322rps_connect_adapter(void *cls, 1351rps_connect_adapter (void *cls,
1323 const struct GNUNET_CONFIGURATION_Handle *cfg) 1352 const struct GNUNET_CONFIGURATION_Handle *cfg)
1324{ 1353{
1325 struct GNUNET_RPS_Handle *h; 1354 struct GNUNET_RPS_Handle *h;
1326 1355
1327 h = GNUNET_RPS_connect(cfg); 1356 h = GNUNET_RPS_connect (cfg);
1328 1357
1329 if (NULL != cur_test_run.pre_test) 1358 if (NULL != cur_test_run.pre_test)
1330 cur_test_run.pre_test(cls, h); 1359 cur_test_run.pre_test (cls, h);
1331 1360
1332 return h; 1361 return h;
1333} 1362}
@@ -1342,12 +1371,12 @@ rps_connect_adapter(void *cls,
1342 * @return service handle to return in 'op_result', NULL on error 1371 * @return service handle to return in 'op_result', NULL on error
1343 */ 1372 */
1344static void * 1373static void *
1345stat_connect_adapter(void *cls, 1374stat_connect_adapter (void *cls,
1346 const struct GNUNET_CONFIGURATION_Handle *cfg) 1375 const struct GNUNET_CONFIGURATION_Handle *cfg)
1347{ 1376{
1348 struct RPSPeer *peer = cls; 1377 struct RPSPeer *peer = cls;
1349 1378
1350 peer->stats_h = GNUNET_STATISTICS_create("rps-profiler", cfg); 1379 peer->stats_h = GNUNET_STATISTICS_create ("rps-profiler", cfg);
1351 return peer->stats_h; 1380 return peer->stats_h;
1352} 1381}
1353 1382
@@ -1358,17 +1387,17 @@ stat_connect_adapter(void *cls,
1358 * @param op_result service handle returned from the connect adapter 1387 * @param op_result service handle returned from the connect adapter
1359 */ 1388 */
1360static void 1389static void
1361stat_disconnect_adapter(void *cls, void *op_result) 1390stat_disconnect_adapter (void *cls, void *op_result)
1362{ 1391{
1363 struct RPSPeer *peer = cls; 1392 struct RPSPeer *peer = cls;
1364 1393
1365 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel 1394 // GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
1366 // (peer->stats_h, "core", "# peers connected", 1395 // (peer->stats_h, "core", "# peers connected",
1367 // stat_iterator, peer)); 1396 // stat_iterator, peer));
1368 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel 1397 // GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
1369 // (peer->stats_h, "nse", "# peers connected", 1398 // (peer->stats_h, "nse", "# peers connected",
1370 // stat_iterator, peer)); 1399 // stat_iterator, peer));
1371 GNUNET_STATISTICS_destroy(op_result, GNUNET_NO); 1400 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
1372 peer->stats_h = NULL; 1401 peer->stats_h = NULL;
1373} 1402}
1374 1403
@@ -1383,26 +1412,26 @@ stat_disconnect_adapter(void *cls, void *op_result)
1383 * operation has executed successfully. 1412 * operation has executed successfully.
1384 */ 1413 */
1385static void 1414static void
1386stat_complete_cb(void *cls, 1415stat_complete_cb (void *cls,
1387 struct GNUNET_TESTBED_Operation *op, 1416 struct GNUNET_TESTBED_Operation *op,
1388 void *ca_result, 1417 void *ca_result,
1389 const char *emsg) 1418 const char *emsg)
1390{ 1419{
1391 //struct GNUNET_STATISTICS_Handle *sh = ca_result; 1420 // struct GNUNET_STATISTICS_Handle *sh = ca_result;
1392 //struct RPSPeer *peer = (struct RPSPeer *) cls; 1421 // struct RPSPeer *peer = (struct RPSPeer *) cls;
1393 (void)cls; 1422 (void) cls;
1394 (void)op; 1423 (void) op;
1395 (void)ca_result; 1424 (void) ca_result;
1396 1425
1397 if (NULL != emsg) 1426 if (NULL != emsg)
1398 { 1427 {
1399 GNUNET_break(0); 1428 GNUNET_break (0);
1400 return; 1429 return;
1401 } 1430 }
1402 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch 1431 // GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
1403 // (sh, "core", "# peers connected", 1432 // (sh, "core", "# peers connected",
1404 // stat_iterator, peer)); 1433 // stat_iterator, peer));
1405 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch 1434 // GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
1406 // (sh, "nse", "# peers connected", 1435 // (sh, "nse", "# peers connected",
1407 // stat_iterator, peer)); 1436 // stat_iterator, peer));
1408} 1437}
@@ -1416,31 +1445,31 @@ stat_complete_cb(void *cls,
1416 * @param op_result service handle returned from the connect adapter 1445 * @param op_result service handle returned from the connect adapter
1417 */ 1446 */
1418static void 1447static void
1419rps_disconnect_adapter(void *cls, 1448rps_disconnect_adapter (void *cls,
1420 void *op_result) 1449 void *op_result)
1421{ 1450{
1422 struct RPSPeer *peer = cls; 1451 struct RPSPeer *peer = cls;
1423 struct GNUNET_RPS_Handle *h = op_result; 1452 struct GNUNET_RPS_Handle *h = op_result;
1424 struct PendingReply *pending_rep; 1453 struct PendingReply *pending_rep;
1425 1454
1426 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1427 "disconnect_adapter (%u)\n", 1456 "disconnect_adapter (%u)\n",
1428 peer->index); 1457 peer->index);
1429 GNUNET_assert(NULL != peer); 1458 GNUNET_assert (NULL != peer);
1430 if (NULL != peer->rps_handle) 1459 if (NULL != peer->rps_handle)
1460 {
1461 while (NULL != (pending_rep = peer->pending_rep_head))
1462 {
1463 cancel_request (pending_rep);
1464 }
1465 GNUNET_assert (h == peer->rps_handle);
1466 if (NULL != h)
1431 { 1467 {
1432 while (NULL != (pending_rep = peer->pending_rep_head)) 1468 GNUNET_RPS_disconnect (h);
1433 { 1469 h = NULL;
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;
1443 } 1470 }
1471 peer->rps_handle = NULL;
1472 }
1444} 1473}
1445 1474
1446 1475
@@ -1456,88 +1485,88 @@ rps_disconnect_adapter(void *cls,
1456 * @param recv_peers the received peers 1485 * @param recv_peers the received peers
1457 */ 1486 */
1458static void 1487static void
1459default_reply_handle(void *cls, 1488default_reply_handle (void *cls,
1460 uint64_t n, 1489 uint64_t n,
1461 const struct GNUNET_PeerIdentity *recv_peers) 1490 const struct GNUNET_PeerIdentity *recv_peers)
1462{ 1491{
1463 struct RPSPeer *rps_peer; 1492 struct RPSPeer *rps_peer;
1464 struct PendingReply *pending_rep = (struct PendingReply *)cls; 1493 struct PendingReply *pending_rep = (struct PendingReply *) cls;
1465 unsigned int i; 1494 unsigned int i;
1466 1495
1467 rps_peer = pending_rep->rps_peer; 1496 rps_peer = pending_rep->rps_peer;
1468 GNUNET_CONTAINER_DLL_remove(rps_peer->pending_rep_head, 1497 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head,
1469 rps_peer->pending_rep_tail, 1498 rps_peer->pending_rep_tail,
1470 pending_rep); 1499 pending_rep);
1471 rps_peer->num_pending_reps--; 1500 rps_peer->num_pending_reps--;
1472 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1501 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1473 "[%s] got %" PRIu64 " peers:\n", 1502 "[%s] got %" PRIu64 " peers:\n",
1474 GNUNET_i2s(rps_peer->peer_id), 1503 GNUNET_i2s (rps_peer->peer_id),
1475 n); 1504 n);
1476 1505
1477 for (i = 0; i < n; i++) 1506 for (i = 0; i < n; i++)
1478 { 1507 {
1479 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1508 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1480 "%u: %s\n", 1509 "%u: %s\n",
1481 i, 1510 i,
1482 GNUNET_i2s(&recv_peers[i])); 1511 GNUNET_i2s (&recv_peers[i]));
1483 1512
1484 rps_peer->num_recv_ids++; 1513 rps_peer->num_recv_ids++;
1485 } 1514 }
1486 1515
1487 if (GNUNET_YES != post_test) 1516 if (GNUNET_YES != post_test)
1488 return; 1517 return;
1489 if (HAVE_QUICK_QUIT != cur_test_run.have_quick_quit) 1518 if (HAVE_QUICK_QUIT != cur_test_run.have_quick_quit)
1490 return; 1519 return;
1491 if (0 == evaluate()) 1520 if (0 == evaluate ())
1492 { 1521 {
1493 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1494 "Test succeeded before end of duration\n"); 1523 "Test succeeded before end of duration\n");
1495 if (NULL != post_test_task) 1524 if (NULL != post_test_task)
1496 GNUNET_SCHEDULER_cancel(post_test_task); 1525 GNUNET_SCHEDULER_cancel (post_test_task);
1497 post_test_task = GNUNET_SCHEDULER_add_now(&post_test_op, NULL); 1526 post_test_task = GNUNET_SCHEDULER_add_now (&post_test_op, NULL);
1498 GNUNET_assert(NULL != post_test_task); 1527 GNUNET_assert (NULL != post_test_task);
1499 } 1528 }
1500} 1529}
1501 1530
1502 1531
1503static void 1532static void
1504profiler_reply_handle_info(void *cls, 1533profiler_reply_handle_info (void *cls,
1505 const struct GNUNET_PeerIdentity *recv_peer, 1534 const struct GNUNET_PeerIdentity *recv_peer,
1506 double probability, 1535 double probability,
1507 uint32_t num_observed); 1536 uint32_t num_observed);
1508 1537
1509/** 1538/**
1510 * Request random peers. 1539 * Request random peers.
1511 */ 1540 */
1512static void 1541static void
1513request_peers(void *cls) 1542request_peers (void *cls)
1514{ 1543{
1515 struct PendingRequest *pending_req = cls; 1544 struct PendingRequest *pending_req = cls;
1516 struct RPSPeer *rps_peer; 1545 struct RPSPeer *rps_peer;
1517 struct PendingReply *pending_rep; 1546 struct PendingReply *pending_rep;
1518 1547
1519 rps_peer = pending_req->rps_peer; 1548 rps_peer = pending_req->rps_peer;
1520 GNUNET_assert(1 <= rps_peer->num_pending_reqs); 1549 GNUNET_assert (1 <= rps_peer->num_pending_reqs);
1521 GNUNET_CONTAINER_DLL_remove(rps_peer->pending_req_head, 1550 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head,
1522 rps_peer->pending_req_tail, 1551 rps_peer->pending_req_tail,
1523 pending_req); 1552 pending_req);
1524 rps_peer->num_pending_reqs--; 1553 rps_peer->num_pending_reqs--;
1525 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1554 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
1526 return; 1555 return;
1527 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1556 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1528 "Requesting one peer\n"); 1557 "Requesting one peer\n");
1529 pending_rep = GNUNET_new(struct PendingReply); 1558 pending_rep = GNUNET_new (struct PendingReply);
1530 pending_rep->rps_peer = rps_peer; 1559 pending_rep->rps_peer = rps_peer;
1531 //pending_rep->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle, 1560 // pending_rep->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle,
1532 // 1, 1561 // 1,
1533 // cur_test_run.reply_handle, 1562 // cur_test_run.reply_handle,
1534 // pending_rep); 1563 // pending_rep);
1535 pending_rep->req_handle = GNUNET_RPS_request_peer_info(rps_peer->rps_handle, 1564 pending_rep->req_handle = GNUNET_RPS_request_peer_info (rps_peer->rps_handle,
1536 profiler_reply_handle_info, 1565 profiler_reply_handle_info,
1537 pending_rep); 1566 pending_rep);
1538 GNUNET_CONTAINER_DLL_insert_tail(rps_peer->pending_rep_head, 1567 GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_rep_head,
1539 rps_peer->pending_rep_tail, 1568 rps_peer->pending_rep_tail,
1540 pending_rep); 1569 pending_rep);
1541 rps_peer->num_pending_reps++; 1570 rps_peer->num_pending_reps++;
1542} 1571}
1543 1572
@@ -1547,45 +1576,45 @@ request_peers(void *cls)
1547 * issued, nor replied 1576 * issued, nor replied
1548 */ 1577 */
1549void 1578void
1550schedule_missing_requests(struct RPSPeer *rps_peer) 1579schedule_missing_requests (struct RPSPeer *rps_peer)
1551{ 1580{
1552 unsigned int i; 1581 unsigned int i;
1553 struct PendingRequest *pending_req; 1582 struct PendingRequest *pending_req;
1554 1583
1555 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1584 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1556 "Scheduling %u - %u missing requests\n", 1585 "Scheduling %u - %u missing requests\n",
1557 rps_peer->num_ids_to_request, 1586 rps_peer->num_ids_to_request,
1558 rps_peer->num_pending_reqs + rps_peer->num_pending_reps); 1587 rps_peer->num_pending_reqs + rps_peer->num_pending_reps);
1559 GNUNET_assert(rps_peer->num_pending_reqs + rps_peer->num_pending_reps <= 1588 GNUNET_assert (rps_peer->num_pending_reqs + rps_peer->num_pending_reps <=
1560 rps_peer->num_ids_to_request); 1589 rps_peer->num_ids_to_request);
1561 for (i = rps_peer->num_pending_reqs + rps_peer->num_pending_reps; 1590 for (i = rps_peer->num_pending_reqs + rps_peer->num_pending_reps;
1562 i < rps_peer->num_ids_to_request; i++) 1591 i < rps_peer->num_ids_to_request; i++)
1563 { 1592 {
1564 pending_req = GNUNET_new(struct PendingRequest); 1593 pending_req = GNUNET_new (struct PendingRequest);
1565 pending_req->rps_peer = rps_peer; 1594 pending_req->rps_peer = rps_peer;
1566 pending_req->request_task = GNUNET_SCHEDULER_add_delayed( 1595 pending_req->request_task = GNUNET_SCHEDULER_add_delayed (
1567 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1596 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
1568 cur_test_run.request_interval * i), 1597 cur_test_run.request_interval * i),
1569 request_peers, 1598 request_peers,
1570 pending_req); 1599 pending_req);
1571 GNUNET_CONTAINER_DLL_insert_tail(rps_peer->pending_req_head, 1600 GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_req_head,
1572 rps_peer->pending_req_tail, 1601 rps_peer->pending_req_tail,
1573 pending_req); 1602 pending_req);
1574 rps_peer->num_pending_reqs++; 1603 rps_peer->num_pending_reqs++;
1575 } 1604 }
1576} 1605}
1577 1606
1578void 1607void
1579cancel_pending_req_rep(struct RPSPeer *rps_peer) 1608cancel_pending_req_rep (struct RPSPeer *rps_peer)
1580{ 1609{
1581 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1610 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1582 "Cancelling all (pending) requests.\n"); 1611 "Cancelling all (pending) requests.\n");
1583 while (NULL != rps_peer->pending_req_head) 1612 while (NULL != rps_peer->pending_req_head)
1584 cancel_pending_req(rps_peer->pending_req_head); 1613 cancel_pending_req (rps_peer->pending_req_head);
1585 GNUNET_assert(0 == rps_peer->num_pending_reqs); 1614 GNUNET_assert (0 == rps_peer->num_pending_reqs);
1586 while (NULL != rps_peer->pending_rep_head) 1615 while (NULL != rps_peer->pending_rep_head)
1587 cancel_request(rps_peer->pending_rep_head); 1616 cancel_request (rps_peer->pending_rep_head);
1588 GNUNET_assert(0 == rps_peer->num_pending_reps); 1617 GNUNET_assert (0 == rps_peer->num_pending_reps);
1589} 1618}
1590 1619
1591/*********************************** 1620/***********************************
@@ -1595,9 +1624,9 @@ cancel_pending_req_rep(struct RPSPeer *rps_peer)
1595/** 1624/**
1596 * Initialise only non-mal RPSPeers 1625 * Initialise only non-mal RPSPeers
1597 */ 1626 */
1598static void mal_init_peer(struct RPSPeer *rps_peer) 1627static void mal_init_peer (struct RPSPeer *rps_peer)
1599{ 1628{
1600 if (rps_peer->index >= round(portion * num_peers)) 1629 if (rps_peer->index >= round (portion * num_peers))
1601 rps_peer->num_ids_to_request = 1; 1630 rps_peer->num_ids_to_request = 1;
1602} 1631}
1603 1632
@@ -1611,51 +1640,53 @@ static void mal_init_peer(struct RPSPeer *rps_peer)
1611 * @param h the handle to the service 1640 * @param h the handle to the service
1612 */ 1641 */
1613static void 1642static void
1614mal_pre(struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) 1643mal_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
1615{ 1644{
1616 #if ENABLE_MALICIOUS 1645 #if ENABLE_MALICIOUS
1617 uint32_t num_mal_peers; 1646 uint32_t num_mal_peers;
1618 1647
1619 GNUNET_assert((1 >= portion) && 1648 GNUNET_assert ((1 >= portion) &&
1620 (0 < portion)); 1649 (0 < portion));
1621 num_mal_peers = round(portion * num_peers); 1650 num_mal_peers = round (portion * num_peers);
1622 1651
1623 if (rps_peer->index < num_mal_peers) 1652 if (rps_peer->index < num_mal_peers)
1624 { 1653 {
1625 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1654 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1626 "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n", 1655 "%u. peer [%s] of %" PRIu32
1627 rps_peer->index, 1656 " malicious peers turning malicious\n",
1628 GNUNET_i2s(rps_peer->peer_id), 1657 rps_peer->index,
1629 num_mal_peers); 1658 GNUNET_i2s (rps_peer->peer_id),
1630 1659 num_mal_peers);
1631 GNUNET_RPS_act_malicious(h, mal_type, num_mal_peers, 1660
1632 rps_peer_ids, target_peer); 1661 GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers,
1633 } 1662 rps_peer_ids, target_peer);
1663 }
1634 #endif /* ENABLE_MALICIOUS */ 1664 #endif /* ENABLE_MALICIOUS */
1635} 1665}
1636 1666
1637static void 1667static void
1638mal_cb(struct RPSPeer *rps_peer) 1668mal_cb (struct RPSPeer *rps_peer)
1639{ 1669{
1640 uint32_t num_mal_peers; 1670 uint32_t num_mal_peers;
1641 1671
1642 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1672 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
1643 { 1673 {
1644 return; 1674 return;
1645 } 1675 }
1646 1676
1647 #if ENABLE_MALICIOUS 1677 #if ENABLE_MALICIOUS
1648 GNUNET_assert((1 >= portion) && 1678 GNUNET_assert ((1 >= portion) &&
1649 (0 < portion)); 1679 (0 < portion));
1650 num_mal_peers = round(portion * num_peers); 1680 num_mal_peers = round (portion * num_peers);
1651 1681
1652 if (rps_peer->index >= num_mal_peers) 1682 if (rps_peer->index >= num_mal_peers)
1653 { /* It's useless to ask a malicious peer about a random sample - 1683 { /* It's useless to ask a malicious peer about a random sample -
1654 it's not sampling */ 1684 it's not sampling */
1655 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), 1685 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
1656 seed_peers, rps_peer); 1686 GNUNET_TIME_UNIT_SECONDS, 2),
1657 schedule_missing_requests(rps_peer); 1687 seed_peers, rps_peer);
1658 } 1688 schedule_missing_requests (rps_peer);
1689 }
1659 #endif /* ENABLE_MALICIOUS */ 1690 #endif /* ENABLE_MALICIOUS */
1660} 1691}
1661 1692
@@ -1664,7 +1695,7 @@ mal_cb(struct RPSPeer *rps_peer)
1664***********************************/ 1695***********************************/
1665 1696
1666static void 1697static void
1667churn(void *cls); 1698churn (void *cls);
1668 1699
1669/** 1700/**
1670 * @brief Starts churn 1701 * @brief Starts churn
@@ -1678,30 +1709,30 @@ churn(void *cls);
1678 * @param rps_peer The peer it's called for 1709 * @param rps_peer The peer it's called for
1679 */ 1710 */
1680static void 1711static void
1681churn_test_cb(struct RPSPeer *rps_peer) 1712churn_test_cb (struct RPSPeer *rps_peer)
1682{ 1713{
1683 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1714 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
1684 { 1715 {
1685 return; 1716 return;
1686 } 1717 }
1687 1718
1688 /* Start churn */ 1719 /* Start churn */
1689 if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) 1720 if ((HAVE_CHURN == cur_test_run.have_churn)&&(NULL == churn_task))
1690 { 1721 {
1691 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1722 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1692 "Starting churn task\n"); 1723 "Starting churn task\n");
1693 churn_task = GNUNET_SCHEDULER_add_delayed( 1724 churn_task = GNUNET_SCHEDULER_add_delayed (
1694 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), 1725 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
1695 churn, 1726 churn,
1696 NULL); 1727 NULL);
1697 } 1728 }
1698 else 1729 else
1699 { 1730 {
1700 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1731 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1701 "Not starting churn task\n"); 1732 "Not starting churn task\n");
1702 } 1733 }
1703 1734
1704 schedule_missing_requests(rps_peer); 1735 schedule_missing_requests (rps_peer);
1705} 1736}
1706 1737
1707/*********************************** 1738/***********************************
@@ -1716,83 +1747,84 @@ churn_test_cb(struct RPSPeer *rps_peer)
1716 * @param emsg NULL on success; otherwise an error description 1747 * @param emsg NULL on success; otherwise an error description
1717 */ 1748 */
1718static void 1749static void
1719churn_cb(void *cls, 1750churn_cb (void *cls,
1720 struct GNUNET_TESTBED_Operation *op, 1751 struct GNUNET_TESTBED_Operation *op,
1721 const char *emsg) 1752 const char *emsg)
1722{ 1753{
1723 // FIXME 1754 // FIXME
1724 struct OpListEntry *entry = cls; 1755 struct OpListEntry *entry = cls;
1725 1756
1726 (void)op; 1757 (void) op;
1727 1758
1728 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1759 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
1729 { 1760 {
1730 return; 1761 return;
1731 } 1762 }
1732 1763
1733 GNUNET_TESTBED_operation_done(entry->op); 1764 GNUNET_TESTBED_operation_done (entry->op);
1734 if (NULL != emsg) 1765 if (NULL != emsg)
1735 { 1766 {
1736 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n"); 1767 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1737 GNUNET_SCHEDULER_shutdown(); 1768 "Failed to start/stop RPS at a peer\n");
1738 return; 1769 GNUNET_SCHEDULER_shutdown ();
1739 } 1770 return;
1740 GNUNET_assert(0 != entry->delta); 1771 }
1772 GNUNET_assert (0 != entry->delta);
1741 1773
1742 num_peers_online += entry->delta; 1774 num_peers_online += entry->delta;
1743 1775
1744 if (PEER_GO_OFFLINE == entry->delta) 1776 if (PEER_GO_OFFLINE == entry->delta)
1745 { /* Peer hopefully just went offline */ 1777 { /* Peer hopefully just went offline */
1746 if (GNUNET_YES != rps_peers[entry->index].online) 1778 if (GNUNET_YES != rps_peers[entry->index].online)
1747 { 1779 {
1748 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1780 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1749 "peer %s was expected to go offline but is still marked as online\n", 1781 "peer %s was expected to go offline but is still marked as online\n",
1750 GNUNET_i2s(rps_peers[entry->index].peer_id)); 1782 GNUNET_i2s (rps_peers[entry->index].peer_id));
1751 GNUNET_break(0); 1783 GNUNET_break (0);
1752 } 1784 }
1753 else 1785 else
1754 { 1786 {
1755 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1787 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1756 "peer %s probably went offline as expected\n", 1788 "peer %s probably went offline as expected\n",
1757 GNUNET_i2s(rps_peers[entry->index].peer_id)); 1789 GNUNET_i2s (rps_peers[entry->index].peer_id));
1758 }
1759 rps_peers[entry->index].online = GNUNET_NO;
1760 } 1790 }
1791 rps_peers[entry->index].online = GNUNET_NO;
1792 }
1761 1793
1762 else if (PEER_GO_ONLINE < entry->delta) 1794 else if (PEER_GO_ONLINE < entry->delta)
1763 { /* Peer hopefully just went online */ 1795 { /* Peer hopefully just went online */
1764 if (GNUNET_NO != rps_peers[entry->index].online) 1796 if (GNUNET_NO != rps_peers[entry->index].online)
1765 { 1797 {
1766 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1798 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1767 "peer %s was expected to go online but is still marked as offline\n", 1799 "peer %s was expected to go online but is still marked as offline\n",
1768 GNUNET_i2s(rps_peers[entry->index].peer_id)); 1800 GNUNET_i2s (rps_peers[entry->index].peer_id));
1769 GNUNET_break(0); 1801 GNUNET_break (0);
1770 } 1802 }
1771 else 1803 else
1772 { 1804 {
1773 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1805 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1774 "peer %s probably went online as expected\n", 1806 "peer %s probably went online as expected\n",
1775 GNUNET_i2s(rps_peers[entry->index].peer_id)); 1807 GNUNET_i2s (rps_peers[entry->index].peer_id));
1776 if (NULL != cur_test_run.pre_test) 1808 if (NULL != cur_test_run.pre_test)
1777 { 1809 {
1778 cur_test_run.pre_test(&rps_peers[entry->index], 1810 cur_test_run.pre_test (&rps_peers[entry->index],
1779 rps_peers[entry->index].rps_handle); 1811 rps_peers[entry->index].rps_handle);
1780 schedule_missing_requests(&rps_peers[entry->index]); 1812 schedule_missing_requests (&rps_peers[entry->index]);
1781 } 1813 }
1782 } 1814 }
1783 rps_peers[entry->index].online = GNUNET_YES; 1815 rps_peers[entry->index].online = GNUNET_YES;
1784 } 1816 }
1785 else 1817 else
1786 { 1818 {
1787 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1819 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1788 "Invalid value for delta: %i\n", entry->delta); 1820 "Invalid value for delta: %i\n", entry->delta);
1789 GNUNET_break(0); 1821 GNUNET_break (0);
1790 } 1822 }
1791 1823
1792 GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, entry); 1824 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
1793 rps_peers[entry->index].entry_op_manage = NULL; 1825 rps_peers[entry->index].entry_op_manage = NULL;
1794 GNUNET_free(entry); 1826 GNUNET_free (entry);
1795 //if (num_peers_in_round[current_round] == peers_running) 1827 // if (num_peers_in_round[current_round] == peers_running)
1796 // run_round (); 1828 // run_round ();
1797} 1829}
1798 1830
@@ -1805,52 +1837,53 @@ churn_cb(void *cls,
1805 * @param prob_go_on_off the probability of the action 1837 * @param prob_go_on_off the probability of the action
1806 */ 1838 */
1807static void 1839static void
1808manage_service_wrapper(unsigned int i, unsigned int j, 1840manage_service_wrapper (unsigned int i, unsigned int j,
1809 enum PEER_ONLINE_DELTA delta, 1841 enum PEER_ONLINE_DELTA delta,
1810 double prob_go_on_off) 1842 double prob_go_on_off)
1811{ 1843{
1812 struct OpListEntry *entry = NULL; 1844 struct OpListEntry *entry = NULL;
1813 uint32_t prob; 1845 uint32_t prob;
1814 1846
1815 /* make sure that management operation is not already scheduled */ 1847 /* make sure that management operation is not already scheduled */
1816 if (NULL != rps_peers[j].entry_op_manage) 1848 if (NULL != rps_peers[j].entry_op_manage)
1817 { 1849 {
1818 return; 1850 return;
1819 } 1851 }
1820 1852
1821 prob = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 1853 prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1822 UINT32_MAX); 1854 UINT32_MAX);
1823 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1855 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1824 "%u. selected peer (%u: %s) is %s.\n", 1856 "%u. selected peer (%u: %s) is %s.\n",
1825 i, 1857 i,
1826 j, 1858 j,
1827 GNUNET_i2s(rps_peers[j].peer_id), 1859 GNUNET_i2s (rps_peers[j].peer_id),
1828 (PEER_GO_ONLINE == delta) ? "online" : "offline"); 1860 (PEER_GO_ONLINE == delta) ? "online" : "offline");
1829 if (prob < prob_go_on_off * UINT32_MAX) 1861 if (prob < prob_go_on_off * UINT32_MAX)
1830 { 1862 {
1831 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1863 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1832 "%s goes %s\n", 1864 "%s goes %s\n",
1833 GNUNET_i2s(rps_peers[j].peer_id), 1865 GNUNET_i2s (rps_peers[j].peer_id),
1834 (PEER_GO_OFFLINE == delta) ? "offline" : "online"); 1866 (PEER_GO_OFFLINE == delta) ? "offline" : "online");
1835 1867
1836 if (PEER_GO_OFFLINE == delta) 1868 if (PEER_GO_OFFLINE == delta)
1837 cancel_pending_req_rep(&rps_peers[j]); 1869 cancel_pending_req_rep (&rps_peers[j]);
1838 entry = make_oplist_entry(); 1870 entry = make_oplist_entry ();
1839 entry->delta = delta; 1871 entry->delta = delta;
1840 entry->index = j; 1872 entry->index = j;
1841 entry->op = GNUNET_TESTBED_peer_manage_service(NULL, 1873 entry->op = GNUNET_TESTBED_peer_manage_service (NULL,
1842 testbed_peers[j], 1874 testbed_peers[j],
1843 "rps", 1875 "rps",
1844 &churn_cb, 1876 &churn_cb,
1845 entry, 1877 entry,
1846 (PEER_GO_OFFLINE == delta) ? 0 : 1); 1878 (PEER_GO_OFFLINE == delta) ?
1847 rps_peers[j].entry_op_manage = entry; 1879 0 : 1);
1848 } 1880 rps_peers[j].entry_op_manage = entry;
1881 }
1849} 1882}
1850 1883
1851 1884
1852static void 1885static void
1853churn(void *cls) 1886churn (void *cls)
1854{ 1887{
1855 unsigned int i; 1888 unsigned int i;
1856 unsigned int j; 1889 unsigned int j;
@@ -1860,61 +1893,61 @@ churn(void *cls)
1860 double portion_go_online; 1893 double portion_go_online;
1861 double portion_go_offline; 1894 double portion_go_offline;
1862 1895
1863 (void)cls; 1896 (void) cls;
1864 1897
1865 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1898 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
1866 { 1899 {
1867 return; 1900 return;
1868 } 1901 }
1869 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1902 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1870 "Churn function executing\n"); 1903 "Churn function executing\n");
1871 1904
1872 churn_task = NULL; /* Should be invalid by now */ 1905 churn_task = NULL; /* Should be invalid by now */
1873 1906
1874 /* Compute the probability for an online peer to go offline 1907 /* Compute the probability for an online peer to go offline
1875 * this round */ 1908 * this round */
1876 portion_online = num_peers_online * 1.0 / num_peers; 1909 portion_online = num_peers_online * 1.0 / num_peers;
1877 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1910 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1878 "Portion online: %f\n", 1911 "Portion online: %f\n",
1879 portion_online); 1912 portion_online);
1880 portion_go_online = ((1 - portion_online) * .5 * .66); 1913 portion_go_online = ((1 - portion_online) * .5 * .66);
1881 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1882 "Portion that should go online: %f\n", 1915 "Portion that should go online: %f\n",
1883 portion_go_online); 1916 portion_go_online);
1884 portion_go_offline = (portion_online + portion_go_online) - .75; 1917 portion_go_offline = (portion_online + portion_go_online) - .75;
1885 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1918 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1886 "Portion that probably goes offline: %f\n", 1919 "Portion that probably goes offline: %f\n",
1887 portion_go_offline); 1920 portion_go_offline);
1888 prob_go_offline = portion_go_offline / (portion_online * .5); 1921 prob_go_offline = portion_go_offline / (portion_online * .5);
1889 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1922 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1890 "Probability of a selected online peer to go offline: %f\n", 1923 "Probability of a selected online peer to go offline: %f\n",
1891 prob_go_offline); 1924 prob_go_offline);
1892 1925
1893 permut = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_WEAK, 1926 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK,
1894 (unsigned int)num_peers); 1927 (unsigned int) num_peers);
1895 1928
1896 /* Go over 50% randomly chosen peers */ 1929 /* Go over 50% randomly chosen peers */
1897 for (i = 0; i < .5 * num_peers; i++) 1930 for (i = 0; i < .5 * num_peers; i++)
1931 {
1932 j = permut[i];
1933
1934 /* If online, shut down with certain probability */
1935 if (GNUNET_YES == rps_peers[j].online)
1898 { 1936 {
1899 j = permut[i]; 1937 manage_service_wrapper (i, j, -1, prob_go_offline);
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 }
1912 } 1938 }
1913 1939
1914 GNUNET_free(permut); 1940 /* If offline, restart with certain probability */
1941 else if (GNUNET_NO == rps_peers[j].online)
1942 {
1943 manage_service_wrapper (i, j, 1, 0.66);
1944 }
1945 }
1915 1946
1916 churn_task = GNUNET_SCHEDULER_add_delayed( 1947 GNUNET_free (permut);
1917 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), 1948
1949 churn_task = GNUNET_SCHEDULER_add_delayed (
1950 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
1918 churn, 1951 churn,
1919 NULL); 1952 NULL);
1920} 1953}
@@ -1923,11 +1956,11 @@ churn(void *cls)
1923/** 1956/**
1924 * Initialise given RPSPeer 1957 * Initialise given RPSPeer
1925 */ 1958 */
1926static void profiler_init_peer(struct RPSPeer *rps_peer) 1959static void profiler_init_peer (struct RPSPeer *rps_peer)
1927{ 1960{
1928 rps_peer->num_ids_to_request = cur_test_run.num_requests; 1961 rps_peer->num_ids_to_request = cur_test_run.num_requests;
1929 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "peer shall request %i peers\n", 1962 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "peer shall request %i peers\n",
1930 rps_peer->num_ids_to_request); 1963 rps_peer->num_ids_to_request);
1931} 1964}
1932 1965
1933 1966
@@ -1939,9 +1972,9 @@ static void profiler_init_peer(struct RPSPeer *rps_peer)
1939 * @param recv_peers the received peers 1972 * @param recv_peers the received peers
1940 */ 1973 */
1941static void 1974static void
1942profiler_reply_handle(void *cls, 1975profiler_reply_handle (void *cls,
1943 uint64_t n, 1976 uint64_t n,
1944 const struct GNUNET_PeerIdentity *recv_peers) 1977 const struct GNUNET_PeerIdentity *recv_peers)
1945{ 1978{
1946 struct RPSPeer *rps_peer; 1979 struct RPSPeer *rps_peer;
1947 struct RPSPeer *rcv_rps_peer; 1980 struct RPSPeer *rcv_rps_peer;
@@ -1954,53 +1987,53 @@ profiler_reply_handle(void *cls,
1954 char *file_name_dhr = file_name_dhr_buf; 1987 char *file_name_dhr = file_name_dhr_buf;
1955 char *file_name_dhru = file_name_dhru_buf; 1988 char *file_name_dhru = file_name_dhru_buf;
1956 unsigned int i; 1989 unsigned int i;
1957 struct PendingReply *pending_rep = (struct PendingReply *)cls; 1990 struct PendingReply *pending_rep = (struct PendingReply *) cls;
1958 1991
1959 pending_rep->req_handle = NULL; 1992 pending_rep->req_handle = NULL;
1960 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "profiler_reply_handle()\n"); 1993 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "profiler_reply_handle()\n");
1961 rps_peer = pending_rep->rps_peer; 1994 rps_peer = pending_rep->rps_peer;
1962 (void)GNUNET_asprintf(&file_name, 1995 (void) GNUNET_asprintf (&file_name,
1963 "/tmp/rps/received_ids-%u", 1996 "/tmp/rps/received_ids-%u",
1964 rps_peer->index); 1997 rps_peer->index);
1965 1998
1966 (void)GNUNET_asprintf(&file_name_dh, 1999 (void) GNUNET_asprintf (&file_name_dh,
1967 "/tmp/rps/diehard_input-%u", 2000 "/tmp/rps/diehard_input-%u",
1968 rps_peer->index); 2001 rps_peer->index);
1969 (void)GNUNET_asprintf(&file_name_dhr, 2002 (void) GNUNET_asprintf (&file_name_dhr,
1970 "/tmp/rps/diehard_input_raw-%u", 2003 "/tmp/rps/diehard_input_raw-%u",
1971 rps_peer->index); 2004 rps_peer->index);
1972 (void)GNUNET_asprintf(&file_name_dhru, 2005 (void) GNUNET_asprintf (&file_name_dhru,
1973 "/tmp/rps/diehard_input_raw_aligned-%u", 2006 "/tmp/rps/diehard_input_raw_aligned-%u",
1974 rps_peer->index); 2007 rps_peer->index);
1975 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2008 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1976 "[%s] got %" PRIu64 " peers:\n", 2009 "[%s] got %" PRIu64 " peers:\n",
1977 GNUNET_i2s(rps_peer->peer_id), 2010 GNUNET_i2s (rps_peer->peer_id),
1978 n); 2011 n);
1979 for (i = 0; i < n; i++) 2012 for (i = 0; i < n; i++)
1980 { 2013 {
1981 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2014 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1982 "%u: %s\n", 2015 "%u: %s\n",
1983 i, 2016 i,
1984 GNUNET_i2s(&recv_peers[i])); 2017 GNUNET_i2s (&recv_peers[i]));
1985 tofile(file_name, 2018 tofile (file_name,
1986 "%s\n", 2019 "%s\n",
1987 GNUNET_i2s_full(&recv_peers[i])); 2020 GNUNET_i2s_full (&recv_peers[i]));
1988 rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get(peer_map, &recv_peers[i]); 2021 rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get (peer_map, &recv_peers[i]);
1989 GNUNET_assert(NULL != rcv_rps_peer); 2022 GNUNET_assert (NULL != rcv_rps_peer);
1990 tofile(file_name_dh, 2023 tofile (file_name_dh,
1991 "%" PRIu32 "\n", 2024 "%" PRIu32 "\n",
1992 (uint32_t)rcv_rps_peer->index); 2025 (uint32_t) rcv_rps_peer->index);
1993#ifdef TO_FILE 2026#ifdef TO_FILE
1994 to_file_raw(file_name_dhr, 2027 to_file_raw (file_name_dhr,
1995 (char *)&rcv_rps_peer->index, 2028 (char *) &rcv_rps_peer->index,
1996 sizeof(uint32_t)); 2029 sizeof(uint32_t));
1997 to_file_raw_unaligned(file_name_dhru, 2030 to_file_raw_unaligned (file_name_dhru,
1998 (char *)&rcv_rps_peer->index, 2031 (char *) &rcv_rps_peer->index,
1999 sizeof(uint32_t), 2032 sizeof(uint32_t),
2000 bits_needed); 2033 bits_needed);
2001#endif /* TO_FILE */ 2034#endif /* TO_FILE */
2002 } 2035 }
2003 default_reply_handle(cls, n, recv_peers); 2036 default_reply_handle (cls, n, recv_peers);
2004} 2037}
2005 2038
2006 2039
@@ -2012,10 +2045,10 @@ profiler_reply_handle(void *cls,
2012 * @param recv_peers the received peers 2045 * @param recv_peers the received peers
2013 */ 2046 */
2014static void 2047static void
2015profiler_reply_handle_info(void *cls, 2048profiler_reply_handle_info (void *cls,
2016 const struct GNUNET_PeerIdentity *recv_peer, 2049 const struct GNUNET_PeerIdentity *recv_peer,
2017 double probability, 2050 double probability,
2018 uint32_t num_observed) 2051 uint32_t num_observed)
2019{ 2052{
2020 struct RPSPeer *rps_peer; 2053 struct RPSPeer *rps_peer;
2021 struct RPSPeer *rcv_rps_peer; 2054 struct RPSPeer *rcv_rps_peer;
@@ -2028,82 +2061,82 @@ profiler_reply_handle_info(void *cls,
2028 char *file_name_dhr = file_name_dhr_buf; 2061 char *file_name_dhr = file_name_dhr_buf;
2029 char *file_name_dhru = file_name_dhru_buf; 2062 char *file_name_dhru = file_name_dhru_buf;
2030 unsigned int i; 2063 unsigned int i;
2031 struct PendingReply *pending_rep = (struct PendingReply *)cls; 2064 struct PendingReply *pending_rep = (struct PendingReply *) cls;
2032 2065
2033 pending_rep->req_handle = NULL; 2066 pending_rep->req_handle = NULL;
2034 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "profiler_reply_handle()\n"); 2067 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "profiler_reply_handle()\n");
2035 rps_peer = pending_rep->rps_peer; 2068 rps_peer = pending_rep->rps_peer;
2036 (void)GNUNET_asprintf(&file_name, 2069 (void) GNUNET_asprintf (&file_name,
2037 "/tmp/rps/received_ids-%u", 2070 "/tmp/rps/received_ids-%u",
2038 rps_peer->index); 2071 rps_peer->index);
2039 2072
2040 (void)GNUNET_asprintf(&file_name_dh, 2073 (void) GNUNET_asprintf (&file_name_dh,
2041 "/tmp/rps/diehard_input-%u", 2074 "/tmp/rps/diehard_input-%u",
2042 rps_peer->index); 2075 rps_peer->index);
2043 (void)GNUNET_asprintf(&file_name_dhr, 2076 (void) GNUNET_asprintf (&file_name_dhr,
2044 "/tmp/rps/diehard_input_raw-%u", 2077 "/tmp/rps/diehard_input_raw-%u",
2045 rps_peer->index); 2078 rps_peer->index);
2046 (void)GNUNET_asprintf(&file_name_dhru, 2079 (void) GNUNET_asprintf (&file_name_dhru,
2047 "/tmp/rps/diehard_input_raw_aligned-%u", 2080 "/tmp/rps/diehard_input_raw_aligned-%u",
2048 rps_peer->index); 2081 rps_peer->index);
2049 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2082 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2050 "[%s] got peer with info:\n", 2083 "[%s] got peer with info:\n",
2051 GNUNET_i2s(rps_peer->peer_id)); 2084 GNUNET_i2s (rps_peer->peer_id));
2052 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2085 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2053 " %s\n", 2086 " %s\n",
2054 GNUNET_i2s(recv_peer)); 2087 GNUNET_i2s (recv_peer));
2055 tofile(file_name, 2088 tofile (file_name,
2056 "%s %d %" PRIu32 " \n", 2089 "%s %d %" PRIu32 " \n",
2057 GNUNET_i2s_full(recv_peer), 2090 GNUNET_i2s_full (recv_peer),
2058 probability, 2091 probability,
2059 num_observed); 2092 num_observed);
2060 rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get(peer_map, recv_peer); 2093 rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get (peer_map, recv_peer);
2061 GNUNET_assert(NULL != rcv_rps_peer); 2094 GNUNET_assert (NULL != rcv_rps_peer);
2062 tofile(file_name_dh, 2095 tofile (file_name_dh,
2063 "%" PRIu32 "\n", 2096 "%" PRIu32 "\n",
2064 (uint32_t)rcv_rps_peer->index); 2097 (uint32_t) rcv_rps_peer->index);
2065#ifdef TO_FILE 2098#ifdef TO_FILE
2066 to_file_raw(file_name_dhr, 2099 to_file_raw (file_name_dhr,
2067 (char *)&rcv_rps_peer->index, 2100 (char *) &rcv_rps_peer->index,
2068 sizeof(uint32_t)); 2101 sizeof(uint32_t));
2069 to_file_raw_unaligned(file_name_dhru, 2102 to_file_raw_unaligned (file_name_dhru,
2070 (char *)&rcv_rps_peer->index, 2103 (char *) &rcv_rps_peer->index,
2071 sizeof(uint32_t), 2104 sizeof(uint32_t),
2072 bits_needed); 2105 bits_needed);
2073#endif /* TO_FILE */ 2106#endif /* TO_FILE */
2074 default_reply_handle(cls, 1, recv_peer); 2107 default_reply_handle (cls, 1, recv_peer);
2075} 2108}
2076 2109
2077 2110
2078static void 2111static void
2079profiler_cb(struct RPSPeer *rps_peer) 2112profiler_cb (struct RPSPeer *rps_peer)
2080{ 2113{
2081 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 2114 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
2082 { 2115 {
2083 return; 2116 return;
2084 } 2117 }
2085 2118
2086 /* Start churn */ 2119 /* Start churn */
2087 if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) 2120 if ((HAVE_CHURN == cur_test_run.have_churn)&&(NULL == churn_task))
2088 { 2121 {
2089 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2122 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2090 "Starting churn task\n"); 2123 "Starting churn task\n");
2091 churn_task = GNUNET_SCHEDULER_add_delayed( 2124 churn_task = GNUNET_SCHEDULER_add_delayed (
2092 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), 2125 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
2093 churn, 2126 churn,
2094 NULL); 2127 NULL);
2095 } 2128 }
2096 else 2129 else
2097 { 2130 {
2098 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2099 "Not starting churn task\n"); 2132 "Not starting churn task\n");
2100 } 2133 }
2101 2134
2102 /* Only request peer ids at one peer. 2135 /* Only request peer ids at one peer.
2103 * (It's the before-last because last one is target of the focussed attack.) 2136 * (It's the before-last because last one is target of the focussed attack.)
2104 */ 2137 */
2105 if (0 < rps_peer->num_ids_to_request) 2138 if (0 < rps_peer->num_ids_to_request)
2106 schedule_missing_requests(rps_peer); 2139 schedule_missing_requests (rps_peer);
2107} 2140}
2108 2141
2109/** 2142/**
@@ -2116,29 +2149,29 @@ profiler_cb(struct RPSPeer *rps_peer)
2116 * #GNUNET_SYSERR to abort iteration with error! 2149 * #GNUNET_SYSERR to abort iteration with error!
2117 */ 2150 */
2118static int 2151static int
2119file_name_cb(void *cls, const char *filename) 2152file_name_cb (void *cls, const char *filename)
2120{ 2153{
2121 if (NULL != strstr(filename, "sampler_el")) 2154 if (NULL != strstr (filename, "sampler_el"))
2155 {
2156 struct RPS_SamplerElement *s_elem;
2157 struct GNUNET_CRYPTO_AuthKey auth_key;
2158 const char *key_char;
2159 uint32_t i;
2160 (void) cls;
2161
2162 key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */
2163 tofile (filename, "--------------------------\n");
2164
2165 auth_key = string_to_auth_key (key_char);
2166 s_elem = RPS_sampler_elem_create ();
2167 RPS_sampler_elem_set (s_elem, auth_key);
2168
2169 for (i = 0; i < num_peers; i++)
2122 { 2170 {
2123 struct RPS_SamplerElement *s_elem; 2171 RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]);
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);
2141 } 2172 }
2173 RPS_sampler_elem_destroy (s_elem);
2174 }
2142 return GNUNET_OK; 2175 return GNUNET_OK;
2143} 2176}
2144 2177
@@ -2148,17 +2181,17 @@ file_name_cb(void *cls, const char *filename)
2148 * Compute all perfect samples. 2181 * Compute all perfect samples.
2149 */ 2182 */
2150static int 2183static int
2151profiler_eval(void) 2184profiler_eval (void)
2152{ 2185{
2153#ifdef TO_FILE 2186#ifdef TO_FILE
2154 /* Compute perfect sample for each sampler element */ 2187 /* Compute perfect sample for each sampler element */
2155 if (-1 == GNUNET_DISK_directory_scan("/tmp/rps/", file_name_cb, NULL)) 2188 if (-1 == GNUNET_DISK_directory_scan ("/tmp/rps/", file_name_cb, NULL))
2156 { 2189 {
2157 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n"); 2190 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n");
2158 } 2191 }
2159#endif /* TO_FILE */ 2192#endif /* TO_FILE */
2160 2193
2161 return evaluate(); 2194 return evaluate ();
2162} 2195}
2163 2196
2164 2197
@@ -2169,40 +2202,40 @@ profiler_eval(void)
2169 * 2202 *
2170 * @return 2203 * @return
2171 */ 2204 */
2172static int is_in_view(uint32_t a, uint32_t b) 2205static int is_in_view (uint32_t a, uint32_t b)
2173{ 2206{
2174 uint32_t i; 2207 uint32_t i;
2175 2208
2176 for (i = 0; i < rps_peers[a].cur_view_count; i++) 2209 for (i = 0; i < rps_peers[a].cur_view_count; i++)
2210 {
2211 if (0 == memcmp (rps_peers[b].peer_id,
2212 &rps_peers[a].cur_view[i],
2213 sizeof(struct GNUNET_PeerIdentity)))
2177 { 2214 {
2178 if (0 == memcmp(rps_peers[b].peer_id, 2215 return GNUNET_YES;
2179 &rps_peers[a].cur_view[i],
2180 sizeof(struct GNUNET_PeerIdentity)))
2181 {
2182 return GNUNET_YES;
2183 }
2184 } 2216 }
2217 }
2185 return GNUNET_NO; 2218 return GNUNET_NO;
2186} 2219}
2187 2220
2188static uint32_t get_idx_of_pid(const struct GNUNET_PeerIdentity *pid) 2221static uint32_t get_idx_of_pid (const struct GNUNET_PeerIdentity *pid)
2189{ 2222{
2190 uint32_t i; 2223 uint32_t i;
2191 2224
2192 for (i = 0; i < num_peers; i++) 2225 for (i = 0; i < num_peers; i++)
2193 { 2226 {
2194 if (0 == memcmp(pid, 2227 if (0 == memcmp (pid,
2195 rps_peers[i].peer_id, 2228 rps_peers[i].peer_id,
2196 sizeof(struct GNUNET_PeerIdentity))) 2229 sizeof(struct GNUNET_PeerIdentity)))
2197 { 2230 {
2198 return i; 2231 return i;
2199 } 2232 }
2200 } 2233 }
2201 //return 0; /* Should not happen - make compiler happy */ 2234 // return 0; /* Should not happen - make compiler happy */
2202 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2235 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2203 "No known _PeerIdentity %s!\n", 2236 "No known _PeerIdentity %s!\n",
2204 GNUNET_i2s_full(pid)); 2237 GNUNET_i2s_full (pid));
2205 GNUNET_assert(0); 2238 GNUNET_assert (0);
2206} 2239}
2207 2240
2208/** 2241/**
@@ -2213,20 +2246,20 @@ static uint32_t get_idx_of_pid(const struct GNUNET_PeerIdentity *pid)
2213 * 2246 *
2214 * @return 2247 * @return
2215 */ 2248 */
2216static uint32_t count_containing_views(uint32_t a, uint32_t b) 2249static uint32_t count_containing_views (uint32_t a, uint32_t b)
2217{ 2250{
2218 uint32_t i; 2251 uint32_t i;
2219 uint32_t peer_idx; 2252 uint32_t peer_idx;
2220 uint32_t count = 0; 2253 uint32_t count = 0;
2221 2254
2222 for (i = 0; i < rps_peers[a].cur_view_count; i++) 2255 for (i = 0; i < rps_peers[a].cur_view_count; i++)
2256 {
2257 peer_idx = get_idx_of_pid (&rps_peers[a].cur_view[i]);
2258 if (GNUNET_YES == is_in_view (peer_idx, b))
2223 { 2259 {
2224 peer_idx = get_idx_of_pid(&rps_peers[a].cur_view[i]); 2260 count++;
2225 if (GNUNET_YES == is_in_view(peer_idx, b))
2226 {
2227 count++;
2228 }
2229 } 2261 }
2262 }
2230 return count; 2263 return count;
2231} 2264}
2232 2265
@@ -2236,13 +2269,13 @@ static uint32_t count_containing_views(uint32_t a, uint32_t b)
2236 * 2269 *
2237 * @param peer_idx index of the peer that is about to sample 2270 * @param peer_idx index of the peer that is about to sample
2238 */ 2271 */
2239static void compute_probabilities(uint32_t peer_idx) 2272static void compute_probabilities (uint32_t peer_idx)
2240{ 2273{
2241 //double probs[num_peers] = { 0 }; 2274 // double probs[num_peers] = { 0 };
2242 double probs[num_peers]; 2275 double probs[num_peers];
2243 double probs_hist[num_peers]; /* Probability respecting the history */ 2276 double probs_hist[num_peers]; /* Probability respecting the history */
2244 size_t probs_as_str_size = (num_peers * 10 + 2) * sizeof(char); 2277 size_t probs_as_str_size = (num_peers * 10 + 2) * sizeof(char);
2245 char *probs_as_str = GNUNET_malloc(probs_as_str_size); 2278 char *probs_as_str = GNUNET_malloc (probs_as_str_size);
2246 char *probs_as_str_cpy; 2279 char *probs_as_str_cpy;
2247 uint32_t i; 2280 uint32_t i;
2248 double prob_push; 2281 double prob_push;
@@ -2254,143 +2287,144 @@ static void compute_probabilities(uint32_t peer_idx)
2254 double sum_non_zero_prob = 0; 2287 double sum_non_zero_prob = 0;
2255 double sum_non_zero_prob_hist = 0; 2288 double sum_non_zero_prob_hist = 0;
2256 2289
2257 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2258 "Computing probabilities for peer %" PRIu32 "\n", peer_idx); 2291 "Computing probabilities for peer %" PRIu32 "\n", peer_idx);
2259 /* Firstly without knowledge of old views */ 2292 /* Firstly without knowledge of old views */
2260 for (i = 0; i < num_peers; i++) 2293 for (i = 0; i < num_peers; i++)
2261 { 2294 {
2262 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2263 "\tfor peer %" PRIu32 ":\n", i); 2296 "\tfor peer %" PRIu32 ":\n", i);
2264 view_size = rps_peers[i].cur_view_count; 2297 view_size = rps_peers[i].cur_view_count;
2265 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2266 "\t\tview_size: %" PRIu32 "\n", view_size); 2299 "\t\tview_size: %" PRIu32 "\n", view_size);
2267 /* For peer i the probability of being sampled is 2300 /* For peer i the probability of being sampled is
2268 * evenly distributed among all possibly observed peers. */ 2301 * evenly distributed among all possibly observed peers. */
2269 /* We could have observed a peer in three cases: 2302 /* We could have observed a peer in three cases:
2270 * 1. peer sent a push 2303 * 1. peer sent a push
2271 * 2. peer was contained in a pull reply 2304 * 2. peer was contained in a pull reply
2272 * 3. peer was in history (sampler) - ignored for now */ 2305 * 3. peer was in history (sampler) - ignored for now */
2273 /* 1. Probability of having received a push from peer i */ 2306 /* 1. Probability of having received a push from peer i */
2274 if ((GNUNET_YES == is_in_view(i, peer_idx)) && 2307 if ((GNUNET_YES == is_in_view (i, peer_idx)) &&
2275 (1 <= (0.45 * view_size))) 2308 (1 <= (0.45 * view_size)))
2276 { 2309 {
2277 if (0 == binom(view_size, 0.45 * view_size)) 2310 if (0 == binom (view_size, 0.45 * view_size))
2278 prob_push = 0; 2311 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 }
2315 else 2312 else
2316 { 2313 {
2317 prob_pull = 0; 2314 prob_push = 1.0 * binom (0.45 * view_size, 1)
2318 } 2315 /
2319 probs[i] = prob_push + prob_pull - (prob_push * prob_pull); 2316 binom (view_size, 0.45 * view_size);
2320 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2317 }
2321 "\t\t%" PRIu32 " has %" PRIu32 " of %" PRIu32 2318 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2322 " peers in its view who know %" PRIu32 " prob: %f\n", 2319 "\t\t%" PRIu32 " is in %" PRIu32 "'s view, prob: %f\n",
2323 peer_idx, 2320 peer_idx,
2324 cont_views, 2321 i,
2325 view_size, 2322 prob_push);
2326 i, 2323 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2327 prob_pull); 2324 "\t\tposs choices from view: %" PRIu32 ", containing i: %"
2328 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2325 PRIu32 "\n",
2329 "\t\tnumber of possible pull combinations: %" PRIu32 "\n", 2326 binom (view_size, 0.45 * view_size),
2330 binom(view_size, 0.45 * view_size)); 2327 binom (0.45 * view_size, 1));
2331 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2328 }
2332 "\t\tnumber of possible pull combinations without %" PRIu32 2329 else
2333 ": %" PRIu32 "\n", 2330 {
2334 i, 2331 prob_push = 0;
2335 binom(view_size - cont_views, 0.45 * view_size)); 2332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2336 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2333 "\t\t%" PRIu32 " is not in %" PRIu32 "'s view, prob: 0\n",
2337 "\t\tnumber of possible pull combinations with %" PRIu32 2334 peer_idx,
2338 ": %" PRIu32 "\n", 2335 i);
2339 i, 2336 }
2340 number_of_being_in_pull_events); 2337 /* 2. Probability of peer i being contained in pulls */
2341 2338 view_size = rps_peers[peer_idx].cur_view_count;
2342 probs_hist[i] = 0.9 * rps_peers[peer_idx].eval_probs_cache[i] + probs[i]; 2339 cont_views = count_containing_views (peer_idx, i);
2343 rps_peers[peer_idx].eval_probs_cache[i] = probs_hist[i]; 2340 number_of_being_in_pull_events =
2344 2341 (binom (view_size, 0.45 * view_size)
2345 sum_non_zero_prob += probs[i]; 2342 - binom (view_size - cont_views, 0.45 * view_size));
2346 sum_non_zero_prob_hist += probs_hist[i]; 2343 if (0 != number_of_being_in_pull_events)
2347 } 2344 {
2345 prob_pull = number_of_being_in_pull_events
2346 /
2347 (1.0 * binom (view_size, 0.45 * view_size));
2348 }
2349 else
2350 {
2351 prob_pull = 0;
2352 }
2353 probs[i] = prob_push + prob_pull - (prob_push * prob_pull);
2354 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2355 "\t\t%" PRIu32 " has %" PRIu32 " of %" PRIu32
2356 " peers in its view who know %" PRIu32 " prob: %f\n",
2357 peer_idx,
2358 cont_views,
2359 view_size,
2360 i,
2361 prob_pull);
2362 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2363 "\t\tnumber of possible pull combinations: %" PRIu32 "\n",
2364 binom (view_size, 0.45 * view_size));
2365 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2366 "\t\tnumber of possible pull combinations without %" PRIu32
2367 ": %" PRIu32 "\n",
2368 i,
2369 binom (view_size - cont_views, 0.45 * view_size));
2370 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2371 "\t\tnumber of possible pull combinations with %" PRIu32
2372 ": %" PRIu32 "\n",
2373 i,
2374 number_of_being_in_pull_events);
2375
2376 probs_hist[i] = 0.9 * rps_peers[peer_idx].eval_probs_cache[i] + probs[i];
2377 rps_peers[peer_idx].eval_probs_cache[i] = probs_hist[i];
2378
2379 sum_non_zero_prob += probs[i];
2380 sum_non_zero_prob_hist += probs_hist[i];
2381 }
2348 /* normalize */ 2382 /* normalize */
2349 if (0 != sum_non_zero_prob) 2383 if (0 != sum_non_zero_prob)
2384 {
2385 for (i = 0; i < num_peers; i++)
2350 { 2386 {
2351 for (i = 0; i < num_peers; i++) 2387 probs[i] = probs[i] * (1.0 / sum_non_zero_prob);
2352 {
2353 probs[i] = probs[i] * (1.0 / sum_non_zero_prob);
2354 }
2355 } 2388 }
2389 }
2356 if (0 != sum_non_zero_prob_hist) 2390 if (0 != sum_non_zero_prob_hist)
2391 {
2392 for (i = 0; i < num_peers; i++)
2357 { 2393 {
2358 for (i = 0; i < num_peers; i++) 2394 probs_hist[i] = probs_hist[i] * (1.0 / sum_non_zero_prob_hist);
2359 {
2360 probs_hist[i] = probs_hist[i] * (1.0 / sum_non_zero_prob_hist);
2361 }
2362 } 2395 }
2396 }
2363 2397
2364 /* str repr */ 2398 /* str repr */
2365 for (i = 0; i < num_peers; i++) 2399 for (i = 0; i < num_peers; i++)
2366 { 2400 {
2367 probs_as_str_cpy = GNUNET_strndup(probs_as_str, probs_as_str_size); 2401 probs_as_str_cpy = GNUNET_strndup (probs_as_str, probs_as_str_size);
2368 tmp = GNUNET_snprintf(probs_as_str, 2402 tmp = GNUNET_snprintf (probs_as_str,
2369 probs_as_str_size, 2403 probs_as_str_size,
2370 "%s %7.6f", probs_as_str_cpy, probs[i]); 2404 "%s %7.6f", probs_as_str_cpy, probs[i]);
2371 GNUNET_free(probs_as_str_cpy); 2405 GNUNET_free (probs_as_str_cpy);
2372 GNUNET_assert(0 <= tmp); 2406 GNUNET_assert (0 <= tmp);
2373 } 2407 }
2374 2408
2375 to_file_w_len(rps_peers[peer_idx].file_name_probs, 2409 to_file_w_len (rps_peers[peer_idx].file_name_probs,
2376 probs_as_str_size, 2410 probs_as_str_size,
2377 probs_as_str); 2411 probs_as_str);
2378 2412
2379 probs_as_str[0] = '\0'; 2413 probs_as_str[0] = '\0';
2380 for (i = 0; i < num_peers; i++) 2414 for (i = 0; i < num_peers; i++)
2381 { 2415 {
2382 probs_as_str_cpy = GNUNET_strndup(probs_as_str, probs_as_str_size); 2416 probs_as_str_cpy = GNUNET_strndup (probs_as_str, probs_as_str_size);
2383 tmp = GNUNET_snprintf(probs_as_str, 2417 tmp = GNUNET_snprintf (probs_as_str,
2384 probs_as_str_size, 2418 probs_as_str_size,
2385 "%s %7.6f", probs_as_str_cpy, probs_hist[i]); 2419 "%s %7.6f", probs_as_str_cpy, probs_hist[i]);
2386 GNUNET_free(probs_as_str_cpy); 2420 GNUNET_free (probs_as_str_cpy);
2387 GNUNET_assert(0 <= tmp); 2421 GNUNET_assert (0 <= tmp);
2388 } 2422 }
2389 2423
2390 to_file_w_len(rps_peers[peer_idx].file_name_probs_hist, 2424 to_file_w_len (rps_peers[peer_idx].file_name_probs_hist,
2391 probs_as_str_size, 2425 probs_as_str_size,
2392 probs_as_str); 2426 probs_as_str);
2393 GNUNET_free(probs_as_str); 2427 GNUNET_free (probs_as_str);
2394} 2428}
2395 2429
2396/** 2430/**
@@ -2402,295 +2436,300 @@ static void compute_probabilities(uint32_t peer_idx)
2402 * 2436 *
2403 * @return the number of occurrences 2437 * @return the number of occurrences
2404 */ 2438 */
2405static uint32_t count_peer_in_views_2(uint32_t peer_idx) 2439static uint32_t count_peer_in_views_2 (uint32_t peer_idx)
2406{ 2440{
2407 uint32_t i, j; 2441 uint32_t i, j;
2408 uint32_t count = 0; 2442 uint32_t count = 0;
2409 2443
2410 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ 2444 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */
2411 { 2445 {
2412 for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */ 2446 for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */
2413 { 2447 {
2414 if (0 == memcmp(rps_peers[peer_idx].peer_id, 2448 if (0 == memcmp (rps_peers[peer_idx].peer_id,
2415 &rps_peers[i].cur_view[j], 2449 &rps_peers[i].cur_view[j],
2416 sizeof(struct GNUNET_PeerIdentity))) 2450 sizeof(struct GNUNET_PeerIdentity)))
2417 { 2451 {
2418 count++; 2452 count++;
2419 break; 2453 break;
2420 } 2454 }
2421 } 2455 }
2422 } 2456 }
2423 rps_peers[peer_idx].count_in_views = count; 2457 rps_peers[peer_idx].count_in_views = count;
2424 return count; 2458 return count;
2425} 2459}
2426 2460
2427static uint32_t cumulated_view_sizes() 2461static uint32_t cumulated_view_sizes ()
2428{ 2462{
2429 uint32_t i; 2463 uint32_t i;
2430 2464
2431 view_sizes = 0; 2465 view_sizes = 0;
2432 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ 2466 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */
2433 { 2467 {
2434 view_sizes += rps_peers[i].cur_view_count; 2468 view_sizes += rps_peers[i].cur_view_count;
2435 } 2469 }
2436 return view_sizes; 2470 return view_sizes;
2437} 2471}
2438 2472
2439static void count_peer_in_views(uint32_t *count_peers) 2473static void count_peer_in_views (uint32_t *count_peers)
2440{ 2474{
2441 uint32_t i, j; 2475 uint32_t i, j;
2442 2476
2443 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ 2477 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */
2478 {
2479 for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */
2444 { 2480 {
2445 for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */ 2481 if (0 == memcmp (rps_peers[i].peer_id,
2446 { 2482 &rps_peers[i].cur_view[j],
2447 if (0 == memcmp(rps_peers[i].peer_id, 2483 sizeof(struct GNUNET_PeerIdentity)))
2448 &rps_peers[i].cur_view[j], 2484 {
2449 sizeof(struct GNUNET_PeerIdentity))) 2485 count_peers[i]++;
2450 { 2486 }
2451 count_peers[i]++;
2452 }
2453 }
2454 } 2487 }
2488 }
2455} 2489}
2456 2490
2457void compute_diversity() 2491void compute_diversity ()
2458{ 2492{
2459 uint32_t i; 2493 uint32_t i;
2460 /* ith entry represents the numer of occurrences in other peer's views */ 2494 /* ith entry represents the numer of occurrences in other peer's views */
2461 uint32_t *count_peers = GNUNET_new_array(num_peers, uint32_t); 2495 uint32_t *count_peers = GNUNET_new_array (num_peers, uint32_t);
2462 uint32_t views_total_size; 2496 uint32_t views_total_size;
2463 double expected; 2497 double expected;
2464 /* deviation from expected number of peers */ 2498 /* deviation from expected number of peers */
2465 double *deviation = GNUNET_new_array(num_peers, double); 2499 double *deviation = GNUNET_new_array (num_peers, double);
2466 2500
2467 views_total_size = 0; 2501 views_total_size = 0;
2468 expected = 0; 2502 expected = 0;
2469 2503
2470 /* For each peer count its representation in other peer's views*/ 2504 /* For each peer count its representation in other peer's views*/
2471 for (i = 0; i < num_peers; i++) /* Peer to count */ 2505 for (i = 0; i < num_peers; i++) /* Peer to count */
2472 { 2506 {
2473 views_total_size += rps_peers[i].cur_view_count; 2507 views_total_size += rps_peers[i].cur_view_count;
2474 count_peer_in_views(count_peers); 2508 count_peer_in_views (count_peers);
2475 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2509 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2476 "Counted representation of %" PRIu32 "th peer [%s]: %" PRIu32 "\n", 2510 "Counted representation of %" PRIu32 "th peer [%s]: %" PRIu32
2477 i, 2511 "\n",
2478 GNUNET_i2s(rps_peers[i].peer_id), 2512 i,
2479 count_peers[i]); 2513 GNUNET_i2s (rps_peers[i].peer_id),
2480 } 2514 count_peers[i]);
2481 2515 }
2482 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2516
2483 "size of all views combined: %" PRIu32 "\n", 2517 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2484 views_total_size); 2518 "size of all views combined: %" PRIu32 "\n",
2485 expected = ((double)1 / num_peers) * views_total_size; 2519 views_total_size);
2486 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2520 expected = ((double) 1 / num_peers) * views_total_size;
2487 "Expected number of occurrences of each peer in all views: %f\n", 2521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2488 expected); 2522 "Expected number of occurrences of each peer in all views: %f\n",
2523 expected);
2489 for (i = 0; i < num_peers; i++) /* Peer to count */ 2524 for (i = 0; i < num_peers; i++) /* Peer to count */
2490 { 2525 {
2491 deviation[i] = expected - count_peers[i]; 2526 deviation[i] = expected - count_peers[i];
2492 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2527 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2493 "Deviation from expectation: %f\n", deviation[i]); 2528 "Deviation from expectation: %f\n", deviation[i]);
2494 } 2529 }
2495 GNUNET_free(count_peers); 2530 GNUNET_free (count_peers);
2496 GNUNET_free(deviation); 2531 GNUNET_free (deviation);
2497} 2532}
2498 2533
2499void print_view_sizes() 2534void print_view_sizes ()
2500{ 2535{
2501 uint32_t i; 2536 uint32_t i;
2502 2537
2503 for (i = 0; i < num_peers; i++) /* Peer to count */ 2538 for (i = 0; i < num_peers; i++) /* Peer to count */
2504 { 2539 {
2505 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2540 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2506 "View size of %" PRIu32 ". [%s] is %" PRIu32 "\n", 2541 "View size of %" PRIu32 ". [%s] is %" PRIu32 "\n",
2507 i, 2542 i,
2508 GNUNET_i2s(rps_peers[i].peer_id), 2543 GNUNET_i2s (rps_peers[i].peer_id),
2509 rps_peers[i].cur_view_count); 2544 rps_peers[i].cur_view_count);
2510 } 2545 }
2511} 2546}
2512 2547
2513void all_views_updated_cb() 2548void all_views_updated_cb ()
2514{ 2549{
2515 compute_diversity(); 2550 compute_diversity ();
2516 print_view_sizes(); 2551 print_view_sizes ();
2517} 2552}
2518 2553
2519void view_update_cb(void *cls, 2554void view_update_cb (void *cls,
2520 uint64_t view_size, 2555 uint64_t view_size,
2521 const struct GNUNET_PeerIdentity *peers) 2556 const struct GNUNET_PeerIdentity *peers)
2522{ 2557{
2523 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2558 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2524 "View was updated (%" PRIu64 ")\n", view_size); 2559 "View was updated (%" PRIu64 ")\n", view_size);
2525 struct RPSPeer *rps_peer = (struct RPSPeer *)cls; 2560 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
2526 to_file("/tmp/rps/view_sizes.txt", 2561 to_file ("/tmp/rps/view_sizes.txt",
2527 "%" PRIu64 " %" PRIu32 "", 2562 "%" PRIu64 " %" PRIu32 "",
2528 rps_peer->index, 2563 rps_peer->index,
2529 view_size); 2564 view_size);
2530 for (uint64_t i = 0; i < view_size; i++) 2565 for (uint64_t i = 0; i < view_size; i++)
2531 { 2566 {
2532 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2533 "\t%s\n", GNUNET_i2s(&peers[i])); 2568 "\t%s\n", GNUNET_i2s (&peers[i]));
2534 } 2569 }
2535 GNUNET_array_grow(rps_peer->cur_view, 2570 GNUNET_array_grow (rps_peer->cur_view,
2536 rps_peer->cur_view_count, 2571 rps_peer->cur_view_count,
2537 view_size); 2572 view_size);
2538 //*rps_peer->cur_view = *peers; 2573 // *rps_peer->cur_view = *peers;
2539 GNUNET_memcpy(rps_peer->cur_view, 2574 GNUNET_memcpy (rps_peer->cur_view,
2540 peers, 2575 peers,
2541 view_size * sizeof(struct GNUNET_PeerIdentity)); 2576 view_size * sizeof(struct GNUNET_PeerIdentity));
2542 to_file("/tmp/rps/count_in_views.txt", 2577 to_file ("/tmp/rps/count_in_views.txt",
2543 "%" PRIu64 " %" PRIu32 "", 2578 "%" PRIu64 " %" PRIu32 "",
2544 rps_peer->index, 2579 rps_peer->index,
2545 count_peer_in_views_2(rps_peer->index)); 2580 count_peer_in_views_2 (rps_peer->index));
2546 cumulated_view_sizes(); 2581 cumulated_view_sizes ();
2547 if (0 != view_size) 2582 if (0 != view_size)
2548 { 2583 {
2549 to_file("/tmp/rps/repr.txt", 2584 to_file ("/tmp/rps/repr.txt",
2550 "%" PRIu64 /* index */ 2585 "%" PRIu64 /* index */
2551 " %" PRIu32 /* occurrence in views */ 2586 " %" PRIu32 /* occurrence in views */
2552 " %" PRIu32 /* view sizes */ 2587 " %" PRIu32 /* view sizes */
2553 " %f" /* fraction of repr in views */ 2588 " %f" /* fraction of repr in views */
2554 " %f" /* average view size */ 2589 " %f" /* average view size */
2555 " %f" /* prob of occurrence in view slot */ 2590 " %f" /* prob of occurrence in view slot */
2556 " %f" "", /* exp frac of repr in views */ 2591 " %f" "", /* exp frac of repr in views */
2557 rps_peer->index, 2592 rps_peer->index,
2558 count_peer_in_views_2(rps_peer->index), 2593 count_peer_in_views_2 (rps_peer->index),
2559 view_sizes, 2594 view_sizes,
2560 count_peer_in_views_2(rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */ 2595 count_peer_in_views_2 (rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */
2561 view_sizes / (view_size * 1.0), /* average view size */ 2596 view_sizes / (view_size * 1.0), /* average view size */
2562 1.0 / view_size, /* prob of occurrence in view slot */ 2597 1.0 / view_size, /* prob of occurrence in view slot */
2563 (1.0 / view_size) * (view_sizes / view_size) /* expected fraction of repr in views */ 2598 (1.0 / view_size) * (view_sizes / view_size) /* expected fraction of repr in views */
2564 ); 2599 );
2565 } 2600 }
2566 compute_probabilities(rps_peer->index); 2601 compute_probabilities (rps_peer->index);
2567 all_views_updated_cb(); 2602 all_views_updated_cb ();
2568} 2603}
2569 2604
2570static void 2605static void
2571pre_profiler(struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) 2606pre_profiler (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
2572{ 2607{
2573 rps_peer->file_name_probs = 2608 rps_peer->file_name_probs =
2574 store_prefix_file_name(rps_peer->index, "probs"); 2609 store_prefix_file_name (rps_peer->index, "probs");
2575 rps_peer->file_name_probs_hist = 2610 rps_peer->file_name_probs_hist =
2576 store_prefix_file_name(rps_peer->index, "probs_hist"); 2611 store_prefix_file_name (rps_peer->index, "probs_hist");
2577 GNUNET_RPS_view_request(h, 0, view_update_cb, rps_peer); 2612 GNUNET_RPS_view_request (h, 0, view_update_cb, rps_peer);
2578} 2613}
2579 2614
2580void write_final_stats(void) 2615void write_final_stats (void)
2581{ 2616{
2582 uint64_t sums[STAT_TYPE_MAX] = { 0 }; 2617 uint64_t sums[STAT_TYPE_MAX] = { 0 };
2583 2618
2584 for (uint32_t i = 0; i < num_peers; i++) 2619 for (uint32_t i = 0; i < num_peers; i++)
2585 { 2620 {
2586 to_file("/tmp/rps/final_stats.csv", 2621 to_file ("/tmp/rps/final_stats.csv",
2587 "%" PRIu32 ", " /* index */ 2622 "%" PRIu32 ", " /* index */
2588 "%s, %" /* id */ 2623 "%s, %" /* id */
2589 PRIu64 ", %" /* rounds */ 2624 PRIu64 ", %" /* rounds */
2590 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* blocking */ 2625 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %"
2591 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* issued */ 2626 PRIu64 ", %" /* blocking */
2592 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* sent */ 2627 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* issued */
2593 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* recv */ 2628 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* sent */
2594 PRIu64 ", %" /* view size */ 2629 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %"
2595 PRIu64 ", %" /* known peers */ 2630 PRIu64 ", %" /* recv */
2596 PRIu64 ", %" /* valid peers */ 2631 PRIu64 ", %" /* view size */
2597 PRIu64 ", %" /* learned peers */ 2632 PRIu64 ", %" /* known peers */
2598 PRIu64 ", %" /* pending online checks */ 2633 PRIu64 ", %" /* valid peers */
2599 PRIu64 ", %" /* unrequested pull replies */ 2634 PRIu64 ", %" /* learned peers */
2600 PRIu64 ", %" /* peers in push map */ 2635 PRIu64 ", %" /* pending online checks */
2601 PRIu64 ", %" /* peers in pull map */ 2636 PRIu64 ", %" /* unrequested pull replies */
2602 PRIu64 ", %" /* peers in view */ 2637 PRIu64 ", %" /* peers in push map */
2603 PRIu64 "\n" /* view size aim */, 2638 PRIu64 ", %" /* peers in pull map */
2604 i, 2639 PRIu64 ", %" /* peers in view */
2605 GNUNET_i2s(rps_peers[i].peer_id), 2640 PRIu64 "\n" /* view size aim */,
2606 rps_peers[i].stats[STAT_TYPE_ROUNDS], 2641 i,
2607 rps_peers[i].stats[STAT_TYPE_BLOCKS], 2642 GNUNET_i2s (rps_peers[i].peer_id),
2608 rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH], 2643 rps_peers[i].stats[STAT_TYPE_ROUNDS],
2609 rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH], 2644 rps_peers[i].stats[STAT_TYPE_BLOCKS],
2610 rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PULL], 2645 rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH],
2611 rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL], 2646 rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH],
2612 rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL], 2647 rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PULL],
2613 rps_peers[i].stats[STAT_TYPE_ISSUED_PUSH_SEND], 2648 rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL],
2614 rps_peers[i].stats[STAT_TYPE_ISSUED_PUSH_SEND_MH], 2649 rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL],
2615 rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REQ], 2650 rps_peers[i].stats[STAT_TYPE_ISSUED_PUSH_SEND],
2616 rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REQ_MH], 2651 rps_peers[i].stats[STAT_TYPE_ISSUED_PUSH_SEND_MH],
2617 rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REP], 2652 rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REQ],
2618 rps_peers[i].stats[STAT_TYPE_SENT_PUSH_SEND], 2653 rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REQ_MH],
2619 rps_peers[i].stats[STAT_TYPE_SENT_PULL_REQ], 2654 rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REP],
2620 rps_peers[i].stats[STAT_TYPE_SENT_PULL_REQ_MH], 2655 rps_peers[i].stats[STAT_TYPE_SENT_PUSH_SEND],
2621 rps_peers[i].stats[STAT_TYPE_SENT_PULL_REP], 2656 rps_peers[i].stats[STAT_TYPE_SENT_PULL_REQ],
2622 rps_peers[i].stats[STAT_TYPE_RECV_PUSH_SEND], 2657 rps_peers[i].stats[STAT_TYPE_SENT_PULL_REQ_MH],
2623 rps_peers[i].stats[STAT_TYPE_RECV_PUSH_SEND_MH], 2658 rps_peers[i].stats[STAT_TYPE_SENT_PULL_REP],
2624 rps_peers[i].stats[STAT_TYPE_RECV_PULL_REQ], 2659 rps_peers[i].stats[STAT_TYPE_RECV_PUSH_SEND],
2625 rps_peers[i].stats[STAT_TYPE_RECV_PULL_REQ_MH], 2660 rps_peers[i].stats[STAT_TYPE_RECV_PUSH_SEND_MH],
2626 rps_peers[i].stats[STAT_TYPE_RECV_PULL_REP_MH], 2661 rps_peers[i].stats[STAT_TYPE_RECV_PULL_REQ],
2627 rps_peers[i].stats[STAT_TYPE_RECV_PULL_REP], 2662 rps_peers[i].stats[STAT_TYPE_RECV_PULL_REQ_MH],
2628 rps_peers[i].stats[STAT_TYPE_VIEW_SIZE], 2663 rps_peers[i].stats[STAT_TYPE_RECV_PULL_REP_MH],
2629 rps_peers[i].stats[STAT_TYPE_KNOWN_PEERS], 2664 rps_peers[i].stats[STAT_TYPE_RECV_PULL_REP],
2630 rps_peers[i].stats[STAT_TYPE_VALID_PEERS], 2665 rps_peers[i].stats[STAT_TYPE_VIEW_SIZE],
2631 rps_peers[i].stats[STAT_TYPE_LEARND_PEERS], 2666 rps_peers[i].stats[STAT_TYPE_KNOWN_PEERS],
2632 rps_peers[i].stats[STAT_TYPE_PENDING_ONLINE_CHECKS], 2667 rps_peers[i].stats[STAT_TYPE_VALID_PEERS],
2633 rps_peers[i].stats[STAT_TYPE_UNREQUESTED_PULL_REPLIES], 2668 rps_peers[i].stats[STAT_TYPE_LEARND_PEERS],
2634 rps_peers[i].stats[STAT_TYPE_PEERS_IN_PUSH_MAP], 2669 rps_peers[i].stats[STAT_TYPE_PENDING_ONLINE_CHECKS],
2635 rps_peers[i].stats[STAT_TYPE_PEERS_IN_PULL_MAP], 2670 rps_peers[i].stats[STAT_TYPE_UNREQUESTED_PULL_REPLIES],
2636 rps_peers[i].stats[STAT_TYPE_PEERS_IN_VIEW], 2671 rps_peers[i].stats[STAT_TYPE_PEERS_IN_PUSH_MAP],
2637 rps_peers[i].stats[STAT_TYPE_VIEW_SIZE_AIM]); 2672 rps_peers[i].stats[STAT_TYPE_PEERS_IN_PULL_MAP],
2638 for (enum STAT_TYPE stat_type = STAT_TYPE_ROUNDS; 2673 rps_peers[i].stats[STAT_TYPE_PEERS_IN_VIEW],
2639 stat_type < STAT_TYPE_MAX; 2674 rps_peers[i].stats[STAT_TYPE_VIEW_SIZE_AIM]);
2640 stat_type++) 2675 for (enum STAT_TYPE stat_type = STAT_TYPE_ROUNDS;
2641 { 2676 stat_type < STAT_TYPE_MAX;
2642 sums[stat_type] += rps_peers[i].stats[stat_type]; 2677 stat_type++)
2643 } 2678 {
2644 } 2679 sums[stat_type] += rps_peers[i].stats[stat_type];
2645 to_file("/tmp/rps/final_stats.dat", 2680 }
2646 "SUM %" 2681 }
2647 PRIu64 " %" /* rounds */ 2682 to_file ("/tmp/rps/final_stats.dat",
2648 PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" /* blocking */ 2683 "SUM %"
2649 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* issued */ 2684 PRIu64 " %" /* rounds */
2650 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* sent */ 2685 PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64
2651 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* recv */ 2686 " %" /* blocking */
2652 PRIu64 ", %" /* view size */ 2687 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* issued */
2653 PRIu64 ", %" /* known peers */ 2688 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* sent */
2654 PRIu64 ", %" /* valid peers */ 2689 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %"
2655 PRIu64 ", %" /* learned peers */ 2690 PRIu64 ", %" /* recv */
2656 PRIu64 ", %" /* pending online checks */ 2691 PRIu64 ", %" /* view size */
2657 PRIu64 ", %" /* unrequested pull replies */ 2692 PRIu64 ", %" /* known peers */
2658 PRIu64 ", %" /* peers in push map */ 2693 PRIu64 ", %" /* valid peers */
2659 PRIu64 ", %" /* peers in pull map */ 2694 PRIu64 ", %" /* learned peers */
2660 PRIu64 ", %" /* peers in view */ 2695 PRIu64 ", %" /* pending online checks */
2661 PRIu64 "\n" /* view size aim */, 2696 PRIu64 ", %" /* unrequested pull replies */
2662 sums[STAT_TYPE_ROUNDS], 2697 PRIu64 ", %" /* peers in push map */
2663 sums[STAT_TYPE_BLOCKS], 2698 PRIu64 ", %" /* peers in pull map */
2664 sums[STAT_TYPE_BLOCKS_MANY_PUSH], 2699 PRIu64 ", %" /* peers in view */
2665 sums[STAT_TYPE_BLOCKS_NO_PUSH], 2700 PRIu64 "\n" /* view size aim */,
2666 sums[STAT_TYPE_BLOCKS_NO_PULL], 2701 sums[STAT_TYPE_ROUNDS],
2667 sums[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL], 2702 sums[STAT_TYPE_BLOCKS],
2668 sums[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL], 2703 sums[STAT_TYPE_BLOCKS_MANY_PUSH],
2669 sums[STAT_TYPE_ISSUED_PUSH_SEND], 2704 sums[STAT_TYPE_BLOCKS_NO_PUSH],
2670 sums[STAT_TYPE_ISSUED_PUSH_SEND_MH], 2705 sums[STAT_TYPE_BLOCKS_NO_PULL],
2671 sums[STAT_TYPE_ISSUED_PULL_REQ], 2706 sums[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL],
2672 sums[STAT_TYPE_ISSUED_PULL_REQ_MH], 2707 sums[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL],
2673 sums[STAT_TYPE_ISSUED_PULL_REP], 2708 sums[STAT_TYPE_ISSUED_PUSH_SEND],
2674 sums[STAT_TYPE_SENT_PUSH_SEND], 2709 sums[STAT_TYPE_ISSUED_PUSH_SEND_MH],
2675 sums[STAT_TYPE_SENT_PULL_REQ], 2710 sums[STAT_TYPE_ISSUED_PULL_REQ],
2676 sums[STAT_TYPE_SENT_PULL_REQ_MH], 2711 sums[STAT_TYPE_ISSUED_PULL_REQ_MH],
2677 sums[STAT_TYPE_SENT_PULL_REP], 2712 sums[STAT_TYPE_ISSUED_PULL_REP],
2678 sums[STAT_TYPE_RECV_PUSH_SEND], 2713 sums[STAT_TYPE_SENT_PUSH_SEND],
2679 sums[STAT_TYPE_RECV_PUSH_SEND_MH], 2714 sums[STAT_TYPE_SENT_PULL_REQ],
2680 sums[STAT_TYPE_RECV_PULL_REQ], 2715 sums[STAT_TYPE_SENT_PULL_REQ_MH],
2681 sums[STAT_TYPE_RECV_PULL_REQ_MH], 2716 sums[STAT_TYPE_SENT_PULL_REP],
2682 sums[STAT_TYPE_RECV_PULL_REP], 2717 sums[STAT_TYPE_RECV_PUSH_SEND],
2683 sums[STAT_TYPE_RECV_PULL_REP_MH], 2718 sums[STAT_TYPE_RECV_PUSH_SEND_MH],
2684 sums[STAT_TYPE_VIEW_SIZE], 2719 sums[STAT_TYPE_RECV_PULL_REQ],
2685 sums[STAT_TYPE_KNOWN_PEERS], 2720 sums[STAT_TYPE_RECV_PULL_REQ_MH],
2686 sums[STAT_TYPE_VALID_PEERS], 2721 sums[STAT_TYPE_RECV_PULL_REP],
2687 sums[STAT_TYPE_LEARND_PEERS], 2722 sums[STAT_TYPE_RECV_PULL_REP_MH],
2688 sums[STAT_TYPE_PENDING_ONLINE_CHECKS], 2723 sums[STAT_TYPE_VIEW_SIZE],
2689 sums[STAT_TYPE_UNREQUESTED_PULL_REPLIES], 2724 sums[STAT_TYPE_KNOWN_PEERS],
2690 sums[STAT_TYPE_PEERS_IN_PUSH_MAP], 2725 sums[STAT_TYPE_VALID_PEERS],
2691 sums[STAT_TYPE_PEERS_IN_PULL_MAP], 2726 sums[STAT_TYPE_LEARND_PEERS],
2692 sums[STAT_TYPE_PEERS_IN_VIEW], 2727 sums[STAT_TYPE_PENDING_ONLINE_CHECKS],
2693 sums[STAT_TYPE_VIEW_SIZE_AIM]); 2728 sums[STAT_TYPE_UNREQUESTED_PULL_REPLIES],
2729 sums[STAT_TYPE_PEERS_IN_PUSH_MAP],
2730 sums[STAT_TYPE_PEERS_IN_PULL_MAP],
2731 sums[STAT_TYPE_PEERS_IN_VIEW],
2732 sums[STAT_TYPE_VIEW_SIZE_AIM]);
2694} 2733}
2695 2734
2696/** 2735/**
@@ -2705,47 +2744,48 @@ void write_final_stats(void)
2705 * successfully obtained, #GNUNET_SYSERR if not. 2744 * successfully obtained, #GNUNET_SYSERR if not.
2706 */ 2745 */
2707void 2746void
2708post_test_shutdown_ready_cb(void *cls, 2747post_test_shutdown_ready_cb (void *cls,
2709 int success) 2748 int success)
2710{ 2749{
2711 struct STATcls *stat_cls = (struct STATcls *)cls; 2750 struct STATcls *stat_cls = (struct STATcls *) cls;
2712 struct RPSPeer *rps_peer = stat_cls->rps_peer; 2751 struct RPSPeer *rps_peer = stat_cls->rps_peer;
2713 2752
2714 rps_peer->h_stat_get[stat_cls->stat_type] = NULL; 2753 rps_peer->h_stat_get[stat_cls->stat_type] = NULL;
2715 if (GNUNET_OK == success) 2754 if (GNUNET_OK == success)
2716 { 2755 {
2717 /* set flag that we we got the value */ 2756 /* set flag that we we got the value */
2718 rps_peer->stat_collected_flags |= BIT(stat_cls->stat_type); 2757 rps_peer->stat_collected_flags |= BIT (stat_cls->stat_type);
2719 } 2758 }
2720 else 2759 else
2721 { 2760 {
2722 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2761 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2723 "Peer %u did not receive statistics value\n", 2762 "Peer %u did not receive statistics value\n",
2724 rps_peer->index); 2763 rps_peer->index);
2725 GNUNET_free(stat_cls); 2764 GNUNET_free (stat_cls);
2726 GNUNET_break(0); 2765 GNUNET_break (0);
2727 return; 2766 return;
2728 } 2767 }
2729 2768
2730 if (NULL != rps_peer->stat_op && 2769 if ((NULL != rps_peer->stat_op)&&
2731 GNUNET_YES == check_statistics_collect_completed_single_peer(rps_peer)) 2770 (GNUNET_YES == check_statistics_collect_completed_single_peer (
2732 { 2771 rps_peer)) )
2733 GNUNET_TESTBED_operation_done(rps_peer->stat_op); 2772 {
2734 } 2773 GNUNET_TESTBED_operation_done (rps_peer->stat_op);
2735 2774 }
2736 write_final_stats(); 2775
2737 if (GNUNET_YES == check_statistics_collect_completed()) 2776 write_final_stats ();
2738 { 2777 if (GNUNET_YES == check_statistics_collect_completed ())
2739 //write_final_stats (); 2778 {
2740 GNUNET_free(stat_cls); 2779 // write_final_stats ();
2741 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2780 GNUNET_free (stat_cls);
2742 "Shutting down\n"); 2781 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2743 GNUNET_SCHEDULER_shutdown(); 2782 "Shutting down\n");
2744 } 2783 GNUNET_SCHEDULER_shutdown ();
2784 }
2745 else 2785 else
2746 { 2786 {
2747 GNUNET_free(stat_cls); 2787 GNUNET_free (stat_cls);
2748 } 2788 }
2749} 2789}
2750 2790
2751/** 2791/**
@@ -2759,76 +2799,76 @@ post_test_shutdown_ready_cb(void *cls,
2759 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration 2799 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
2760 */ 2800 */
2761int 2801int
2762stat_iterator(void *cls, 2802stat_iterator (void *cls,
2763 const char *subsystem, 2803 const char *subsystem,
2764 const char *name, 2804 const char *name,
2765 uint64_t value, 2805 uint64_t value,
2766 int is_persistent) 2806 int is_persistent)
2767{ 2807{
2768 const struct STATcls *stat_cls = (const struct STATcls *)cls; 2808 const struct STATcls *stat_cls = (const struct STATcls *) cls;
2769 struct RPSPeer *rps_peer = (struct RPSPeer *)stat_cls->rps_peer; 2809 struct RPSPeer *rps_peer = (struct RPSPeer *) stat_cls->rps_peer;
2770 enum STAT_TYPE stat_type; 2810 enum STAT_TYPE stat_type;
2771 2811
2772 (void)subsystem; 2812 (void) subsystem;
2773 (void)is_persistent; 2813 (void) is_persistent;
2774 2814
2775 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2815 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2776 "Got stat value: %s - %" PRIu64 " (%u)\n", 2816 "Got stat value: %s - %" PRIu64 " (%u)\n",
2777 name, 2817 name,
2778 value, 2818 value,
2779 rps_peer->index); 2819 rps_peer->index);
2780 to_file(rps_peer->file_name_stats, 2820 to_file (rps_peer->file_name_stats,
2781 "%s: %" PRIu64 "\n", 2821 "%s: %" PRIu64 "\n",
2782 name, 2822 name,
2783 value); 2823 value);
2784 stat_type = stat_str_2_type(name); 2824 stat_type = stat_str_2_type (name);
2785 GNUNET_assert(STAT_TYPE_ROUNDS <= stat_type && 2825 GNUNET_assert (STAT_TYPE_ROUNDS <= stat_type &&
2786 STAT_TYPE_MAX > stat_type); 2826 STAT_TYPE_MAX > stat_type);
2787 rps_peer->stats[stat_type] = value; 2827 rps_peer->stats[stat_type] = value;
2788 return GNUNET_OK; 2828 return GNUNET_OK;
2789} 2829}
2790 2830
2791 2831
2792void 2832void
2793post_profiler(struct RPSPeer *rps_peer) 2833post_profiler (struct RPSPeer *rps_peer)
2794{ 2834{
2795 if (COLLECT_STATISTICS != cur_test_run.have_collect_statistics) 2835 if (COLLECT_STATISTICS != cur_test_run.have_collect_statistics)
2796 { 2836 {
2797 return; 2837 return;
2798 } 2838 }
2799 2839
2800 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2840 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2801 "Going to request statistic values with mask 0x%" PRIx32 "\n", 2841 "Going to request statistic values with mask 0x%" PRIx32 "\n",
2802 cur_test_run.stat_collect_flags); 2842 cur_test_run.stat_collect_flags);
2803 2843
2804 struct STATcls *stat_cls; 2844 struct STATcls *stat_cls;
2805 uint32_t stat_type; 2845 uint32_t stat_type;
2806 for (stat_type = STAT_TYPE_ROUNDS; 2846 for (stat_type = STAT_TYPE_ROUNDS;
2807 stat_type < STAT_TYPE_MAX; 2847 stat_type < STAT_TYPE_MAX;
2808 stat_type++) 2848 stat_type++)
2809 { 2849 {
2810 if (BIT(stat_type) & cur_test_run.stat_collect_flags) 2850 if (BIT (stat_type) & cur_test_run.stat_collect_flags)
2811 { 2851 {
2812 stat_cls = GNUNET_malloc(sizeof(struct STATcls)); 2852 stat_cls = GNUNET_malloc (sizeof(struct STATcls));
2813 stat_cls->rps_peer = rps_peer; 2853 stat_cls->rps_peer = rps_peer;
2814 stat_cls->stat_type = stat_type; 2854 stat_cls->stat_type = stat_type;
2815 rps_peer->file_name_stats = 2855 rps_peer->file_name_stats =
2816 store_prefix_file_name(rps_peer->peer_id, "stats"); 2856 store_prefix_file_name (rps_peer->peer_id, "stats");
2817 rps_peer->h_stat_get[stat_type] = 2857 rps_peer->h_stat_get[stat_type] =
2818 GNUNET_STATISTICS_get(rps_peer->stats_h, 2858 GNUNET_STATISTICS_get (rps_peer->stats_h,
2819 "rps", 2859 "rps",
2820 stat_type_strings [stat_type], 2860 stat_type_strings [stat_type],
2821 post_test_shutdown_ready_cb, 2861 post_test_shutdown_ready_cb,
2822 stat_iterator, 2862 stat_iterator,
2823 (struct STATcls *)stat_cls); 2863 (struct STATcls *) stat_cls);
2824 GNUNET_assert(NULL != rps_peer->h_stat_get); 2864 GNUNET_assert (NULL != rps_peer->h_stat_get);
2825 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2865 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2826 "Requested statistics for %s (peer %" PRIu32 ")\n", 2866 "Requested statistics for %s (peer %" PRIu32 ")\n",
2827 stat_type_strings [stat_type], 2867 stat_type_strings [stat_type],
2828 rps_peer->index); 2868 rps_peer->index);
2829 } 2869 }
2830 } 2870 }
2831 GNUNET_free(rps_peer->eval_probs_cache); 2871 GNUNET_free (rps_peer->eval_probs_cache);
2832} 2872}
2833 2873
2834 2874
@@ -2850,100 +2890,104 @@ post_profiler(struct RPSPeer *rps_peer)
2850 * failed 2890 * failed
2851 */ 2891 */
2852static void 2892static void
2853test_run(void *cls, 2893test_run (void *cls,
2854 struct GNUNET_TESTBED_RunHandle *h, 2894 struct GNUNET_TESTBED_RunHandle *h,
2855 unsigned int n_peers, 2895 unsigned int n_peers,
2856 struct GNUNET_TESTBED_Peer **peers, 2896 struct GNUNET_TESTBED_Peer **peers,
2857 unsigned int links_succeeded, 2897 unsigned int links_succeeded,
2858 unsigned int links_failed) 2898 unsigned int links_failed)
2859{ 2899{
2860 unsigned int i; 2900 unsigned int i;
2861 struct OpListEntry *entry; 2901 struct OpListEntry *entry;
2862 2902
2863 (void)cls; 2903 (void) cls;
2864 (void)h; 2904 (void) h;
2865 (void)links_failed; 2905 (void) links_failed;
2866 2906
2867 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "RUN was called\n"); 2907 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "RUN was called\n");
2868 2908
2869 /* Check whether we timed out */ 2909 /* Check whether we timed out */
2870 if (n_peers != num_peers || 2910 if ((n_peers != num_peers)||
2871 NULL == peers || 2911 (NULL == peers) ||
2872 0 == links_succeeded) 2912 (0 == links_succeeded) )
2873 { 2913 {
2874 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Going down due to args (eg. timeout)\n"); 2914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2875 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tn_peers: %u\n", n_peers); 2915 "Going down due to args (eg. timeout)\n");
2876 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tnum_peers: %" PRIu32 "\n", num_peers); 2916 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tn_peers: %u\n", n_peers);
2877 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tpeers: %p\n", peers); 2917 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tnum_peers: %" PRIu32 "\n",
2878 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tlinks_succeeded: %u\n", links_succeeded); 2918 num_peers);
2879 ok = 1; 2919 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tpeers: %p\n", peers);
2880 GNUNET_SCHEDULER_shutdown(); 2920 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tlinks_succeeded: %u\n",
2881 return; 2921 links_succeeded);
2882 } 2922 ok = 1;
2923 GNUNET_SCHEDULER_shutdown ();
2924 return;
2925 }
2883 2926
2884 2927
2885 /* Initialize peers */ 2928 /* Initialize peers */
2886 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "going to initialise peers\n"); 2929 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "going to initialise peers\n");
2887 testbed_peers = peers; 2930 testbed_peers = peers;
2888 num_peers_online = 0; 2931 num_peers_online = 0;
2889 for (i = 0; i < num_peers; i++) 2932 for (i = 0; i < num_peers; i++)
2890 { 2933 {
2891 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "initialising %u\n", i); 2934 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "initialising %u\n", i);
2892 entry = make_oplist_entry(); 2935 entry = make_oplist_entry ();
2893 entry->index = i; 2936 entry->index = i;
2894 rps_peers[i].index = i; 2937 rps_peers[i].index = i;
2895 if (NULL != cur_test_run.init_peer) 2938 if (NULL != cur_test_run.init_peer)
2896 cur_test_run.init_peer(&rps_peers[i]); 2939 cur_test_run.init_peer (&rps_peers[i]);
2897 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) 2940 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view)
2898 { 2941 {
2899 rps_peers->cur_view_count = 0; 2942 rps_peers->cur_view_count = 0;
2900 rps_peers->cur_view = NULL; 2943 rps_peers->cur_view = NULL;
2901 } 2944 }
2902 entry->op = GNUNET_TESTBED_peer_get_information(peers[i], 2945 entry->op = GNUNET_TESTBED_peer_get_information (peers[i],
2903 GNUNET_TESTBED_PIT_IDENTITY, 2946 GNUNET_TESTBED_PIT_IDENTITY,
2904 &info_cb, 2947 &info_cb,
2905 entry); 2948 entry);
2906 } 2949 }
2907 2950
2908 /* Bring peers up */ 2951 /* Bring peers up */
2909 GNUNET_assert(num_peers == n_peers); 2952 GNUNET_assert (num_peers == n_peers);
2910 for (i = 0; i < n_peers; i++) 2953 for (i = 0; i < n_peers; i++)
2911 { 2954 {
2912 rps_peers[i].index = i; 2955 rps_peers[i].index = i;
2913 rps_peers[i].op = 2956 rps_peers[i].op =
2914 GNUNET_TESTBED_service_connect(&rps_peers[i], 2957 GNUNET_TESTBED_service_connect (&rps_peers[i],
2915 peers[i], 2958 peers[i],
2916 "rps", 2959 "rps",
2917 &rps_connect_complete_cb, 2960 &rps_connect_complete_cb,
2918 &rps_peers[i], 2961 &rps_peers[i],
2919 &rps_connect_adapter, 2962 &rps_connect_adapter,
2920 &rps_disconnect_adapter, 2963 &rps_disconnect_adapter,
2921 &rps_peers[i]); 2964 &rps_peers[i]);
2922 /* Connect all peers to statistics service */ 2965 /* Connect all peers to statistics service */
2923 if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics) 2966 if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics)
2924 { 2967 {
2925 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2968 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2926 "Connecting to statistics service\n"); 2969 "Connecting to statistics service\n");
2927 rps_peers[i].stat_op = 2970 rps_peers[i].stat_op =
2928 GNUNET_TESTBED_service_connect(NULL, 2971 GNUNET_TESTBED_service_connect (NULL,
2929 peers[i], 2972 peers[i],
2930 "statistics", 2973 "statistics",
2931 stat_complete_cb, 2974 stat_complete_cb,
2932 &rps_peers[i], 2975 &rps_peers[i],
2933 &stat_connect_adapter, 2976 &stat_connect_adapter,
2934 &stat_disconnect_adapter, 2977 &stat_disconnect_adapter,
2935 &rps_peers[i]); 2978 &rps_peers[i]);
2936 } 2979 }
2937 } 2980 }
2938 2981
2939 if (NULL != churn_task) 2982 if (NULL != churn_task)
2940 GNUNET_SCHEDULER_cancel(churn_task); 2983 GNUNET_SCHEDULER_cancel (churn_task);
2941 post_test_task = GNUNET_SCHEDULER_add_delayed(duration, &post_test_op, NULL); 2984 post_test_task = GNUNET_SCHEDULER_add_delayed (duration, &post_test_op, NULL);
2942 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "timeout for shutdown is %lu\n", timeout.rel_value_us / 1000000); 2985 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "timeout for shutdown is %lu\n",
2943 shutdown_task = GNUNET_SCHEDULER_add_delayed(timeout, 2986 timeout.rel_value_us / 1000000);
2944 &trigger_shutdown, 2987 shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout,
2945 NULL); 2988 &trigger_shutdown,
2946 GNUNET_SCHEDULER_add_shutdown(shutdown_op, NULL); 2989 NULL);
2990 GNUNET_SCHEDULER_add_shutdown (shutdown_op, NULL);
2947} 2991}
2948 2992
2949 2993
@@ -2954,26 +2998,26 @@ test_run(void *cls,
2954 * @param argv unused 2998 * @param argv unused
2955 */ 2999 */
2956static void 3000static void
2957run(void *cls, 3001run (void *cls,
2958 char *const *args, 3002 char *const *args,
2959 const char *cfgfile, 3003 const char *cfgfile,
2960 const struct GNUNET_CONFIGURATION_Handle *cfg) 3004 const struct GNUNET_CONFIGURATION_Handle *cfg)
2961{ 3005{
2962 //int ret_value; 3006 // int ret_value;
2963 (void)cls; 3007 (void) cls;
2964 (void)args; 3008 (void) args;
2965 (void)cfgfile; 3009 (void) cfgfile;
2966 3010
2967 /* Defaults for tests */ 3011 /* Defaults for tests */
2968 churn_task = NULL; 3012 churn_task = NULL;
2969 3013
2970 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n"); 3014 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n");
2971 cur_test_run.name = "test-rps-profiler"; 3015 cur_test_run.name = "test-rps-profiler";
2972 if (0 == num_peers) 3016 if (0 == num_peers)
2973 num_peers = 10; 3017 num_peers = 10;
2974 mal_type = 3; 3018 mal_type = 3;
2975 cur_test_run.init_peer = profiler_init_peer; 3019 cur_test_run.init_peer = profiler_init_peer;
2976 //cur_test_run.pre_test = mal_pre; 3020 // cur_test_run.pre_test = mal_pre;
2977 cur_test_run.pre_test = pre_profiler; 3021 cur_test_run.pre_test = pre_profiler;
2978 cur_test_run.main_test = profiler_cb; 3022 cur_test_run.main_test = profiler_cb;
2979 cur_test_run.reply_handle = profiler_reply_handle; 3023 cur_test_run.reply_handle = profiler_reply_handle;
@@ -2982,104 +3026,105 @@ run(void *cls,
2982 cur_test_run.request_interval = 2; 3026 cur_test_run.request_interval = 2;
2983 if (0 == cur_test_run.num_requests) 3027 if (0 == cur_test_run.num_requests)
2984 cur_test_run.num_requests = 5; 3028 cur_test_run.num_requests = 5;
2985 //cur_test_run.have_churn = HAVE_CHURN; 3029 // cur_test_run.have_churn = HAVE_CHURN;
2986 cur_test_run.have_churn = HAVE_NO_CHURN; 3030 cur_test_run.have_churn = HAVE_NO_CHURN;
2987 cur_test_run.have_quick_quit = HAVE_QUICK_QUIT; 3031 cur_test_run.have_quick_quit = HAVE_QUICK_QUIT;
2988 cur_test_run.have_collect_statistics = COLLECT_STATISTICS; 3032 cur_test_run.have_collect_statistics = COLLECT_STATISTICS;
2989 cur_test_run.stat_collect_flags = BIT(STAT_TYPE_ROUNDS) | 3033 cur_test_run.stat_collect_flags = BIT (STAT_TYPE_ROUNDS)
2990 BIT(STAT_TYPE_BLOCKS) | 3034 | BIT (STAT_TYPE_BLOCKS)
2991 BIT(STAT_TYPE_BLOCKS_MANY_PUSH) | 3035 | BIT (STAT_TYPE_BLOCKS_MANY_PUSH)
2992 BIT(STAT_TYPE_BLOCKS_NO_PUSH) | 3036 | BIT (STAT_TYPE_BLOCKS_NO_PUSH)
2993 BIT(STAT_TYPE_BLOCKS_NO_PULL) | 3037 | BIT (STAT_TYPE_BLOCKS_NO_PULL)
2994 BIT(STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL) | 3038 | BIT (STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL)
2995 BIT(STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL) | 3039 | BIT (STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL)
2996 BIT(STAT_TYPE_ISSUED_PUSH_SEND) | 3040 | BIT (STAT_TYPE_ISSUED_PUSH_SEND)
2997 BIT(STAT_TYPE_ISSUED_PUSH_SEND_MH) | 3041 | BIT (STAT_TYPE_ISSUED_PUSH_SEND_MH)
2998 BIT(STAT_TYPE_ISSUED_PULL_REQ) | 3042 | BIT (STAT_TYPE_ISSUED_PULL_REQ)
2999 BIT(STAT_TYPE_ISSUED_PULL_REQ_MH) | 3043 | BIT (STAT_TYPE_ISSUED_PULL_REQ_MH)
3000 BIT(STAT_TYPE_ISSUED_PULL_REP) | 3044 | BIT (STAT_TYPE_ISSUED_PULL_REP)
3001 BIT(STAT_TYPE_SENT_PUSH_SEND) | 3045 | BIT (STAT_TYPE_SENT_PUSH_SEND)
3002 BIT(STAT_TYPE_SENT_PULL_REQ) | 3046 | BIT (STAT_TYPE_SENT_PULL_REQ)
3003 BIT(STAT_TYPE_SENT_PULL_REQ_MH) | 3047 | BIT (STAT_TYPE_SENT_PULL_REQ_MH)
3004 BIT(STAT_TYPE_SENT_PULL_REP) | 3048 | BIT (STAT_TYPE_SENT_PULL_REP)
3005 BIT(STAT_TYPE_RECV_PUSH_SEND) | 3049 | BIT (STAT_TYPE_RECV_PUSH_SEND)
3006 BIT(STAT_TYPE_RECV_PUSH_SEND_MH) | 3050 | BIT (STAT_TYPE_RECV_PUSH_SEND_MH)
3007 BIT(STAT_TYPE_RECV_PULL_REQ) | 3051 | BIT (STAT_TYPE_RECV_PULL_REQ)
3008 BIT(STAT_TYPE_RECV_PULL_REQ_MH) | 3052 | BIT (STAT_TYPE_RECV_PULL_REQ_MH)
3009 BIT(STAT_TYPE_RECV_PULL_REP) | 3053 | BIT (STAT_TYPE_RECV_PULL_REP)
3010 BIT(STAT_TYPE_RECV_PULL_REP_MH) | 3054 | BIT (STAT_TYPE_RECV_PULL_REP_MH)
3011 BIT(STAT_TYPE_VIEW_SIZE) | 3055 | BIT (STAT_TYPE_VIEW_SIZE)
3012 BIT(STAT_TYPE_KNOWN_PEERS) | 3056 | BIT (STAT_TYPE_KNOWN_PEERS)
3013 BIT(STAT_TYPE_VALID_PEERS) | 3057 | BIT (STAT_TYPE_VALID_PEERS)
3014 BIT(STAT_TYPE_LEARND_PEERS) | 3058 | BIT (STAT_TYPE_LEARND_PEERS)
3015 BIT(STAT_TYPE_PENDING_ONLINE_CHECKS) | 3059 | BIT (STAT_TYPE_PENDING_ONLINE_CHECKS)
3016 BIT(STAT_TYPE_UNREQUESTED_PULL_REPLIES) | 3060 | BIT (STAT_TYPE_UNREQUESTED_PULL_REPLIES)
3017 BIT(STAT_TYPE_PEERS_IN_PUSH_MAP) | 3061 | BIT (STAT_TYPE_PEERS_IN_PUSH_MAP)
3018 BIT(STAT_TYPE_PEERS_IN_PULL_MAP) | 3062 | BIT (STAT_TYPE_PEERS_IN_PULL_MAP)
3019 BIT(STAT_TYPE_PEERS_IN_VIEW) | 3063 | BIT (STAT_TYPE_PEERS_IN_VIEW)
3020 BIT(STAT_TYPE_VIEW_SIZE_AIM); 3064 | BIT (STAT_TYPE_VIEW_SIZE_AIM);
3021 cur_test_run.have_collect_view = COLLECT_VIEW; 3065 cur_test_run.have_collect_view = COLLECT_VIEW;
3022 3066
3023 /* 'Clean' directory */ 3067 /* 'Clean' directory */
3024 (void)GNUNET_DISK_directory_remove("/tmp/rps/"); 3068 (void) GNUNET_DISK_directory_remove ("/tmp/rps/");
3025 GNUNET_DISK_directory_create("/tmp/rps/"); 3069 GNUNET_DISK_directory_create ("/tmp/rps/");
3026 if (0 == duration.rel_value_us) 3070 if (0 == duration.rel_value_us)
3071 {
3072 if (0 == timeout.rel_value_us)
3027 { 3073 {
3028 if (0 == timeout.rel_value_us) 3074 duration = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90);
3029 { 3075 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
3030 duration = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90); 3076 (90 * 1.2)
3031 timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3077 + (0.01 * num_peers));
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 }
3041 } 3078 }
3042 else 3079 else
3043 { 3080 {
3044 if (0 == timeout.rel_value_us) 3081 duration = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
3045 { 3082 (timeout.rel_value_us / 1000000)
3046 timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3083 * 0.75);
3047 ((duration.rel_value_us / 1000000)
3048 * 1.2) + (0.01 * num_peers));
3049 }
3050 } 3084 }
3051 GNUNET_assert(duration.rel_value_us < timeout.rel_value_us); 3085 }
3052 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3086 else
3053 "duration is %lus\n", 3087 {
3054 duration.rel_value_us / 1000000); 3088 if (0 == timeout.rel_value_us)
3055 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3089 {
3056 "timeout is %lus\n", 3090 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
3057 timeout.rel_value_us / 1000000); 3091 ((duration.rel_value_us
3092 / 1000000)
3093 * 1.2) + (0.01 * num_peers));
3094 }
3095 }
3096 GNUNET_assert (duration.rel_value_us < timeout.rel_value_us);
3097 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3098 "duration is %lus\n",
3099 duration.rel_value_us / 1000000);
3100 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3101 "timeout is %lus\n",
3102 timeout.rel_value_us / 1000000);
3058 3103
3059 /* Compute number of bits for representing largest peer id */ 3104 /* Compute number of bits for representing largest peer id */
3060 for (bits_needed = 1; (1 << bits_needed) < num_peers; bits_needed++) 3105 for (bits_needed = 1; (1 << bits_needed) < num_peers; bits_needed++)
3061 ; 3106 ;
3062 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3063 "Need %u bits to represent %" PRIu32 " peers\n", 3108 "Need %u bits to represent %" PRIu32 " peers\n",
3064 bits_needed, 3109 bits_needed,
3065 num_peers); 3110 num_peers);
3066 3111
3067 rps_peers = GNUNET_new_array(num_peers, struct RPSPeer); 3112 rps_peers = GNUNET_new_array (num_peers, struct RPSPeer);
3068 peer_map = GNUNET_CONTAINER_multipeermap_create(num_peers, GNUNET_NO); 3113 peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO);
3069 rps_peer_ids = GNUNET_new_array(num_peers, struct GNUNET_PeerIdentity); 3114 rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
3070 if ((2 == mal_type) || 3115 if ((2 == mal_type) ||
3071 (3 == mal_type)) 3116 (3 == mal_type))
3072 target_peer = &rps_peer_ids[num_peers - 2]; 3117 target_peer = &rps_peer_ids[num_peers - 2];
3073 3118
3074 ok = 1; 3119 ok = 1;
3075 GNUNET_TESTBED_run(NULL, 3120 GNUNET_TESTBED_run (NULL,
3076 cfg, 3121 cfg,
3077 num_peers, 3122 num_peers,
3078 0, /* event mask */ 3123 0, /* event mask */
3079 NULL, 3124 NULL,
3080 NULL, 3125 NULL,
3081 &test_run, 3126 &test_run,
3082 NULL); 3127 NULL);
3083} 3128}
3084 3129
3085/** 3130/**
@@ -3090,69 +3135,72 @@ run(void *cls,
3090 * @return 0 on success 3135 * @return 0 on success
3091 */ 3136 */
3092int 3137int
3093main(int argc, char *argv[]) 3138main (int argc, char *argv[])
3094{ 3139{
3095 int ret_value; 3140 int ret_value;
3096 struct GNUNET_GETOPT_CommandLineOption options[] = { 3141 struct GNUNET_GETOPT_CommandLineOption options[] = {
3097 GNUNET_GETOPT_option_uint('n', 3142 GNUNET_GETOPT_option_uint ('n',
3098 "num-peers", 3143 "num-peers",
3099 "COUNT", 3144 "COUNT",
3100 gettext_noop("number of peers to start"), 3145 gettext_noop ("number of peers to start"),
3101 &num_peers), 3146 &num_peers),
3102 GNUNET_GETOPT_option_relative_time('d', 3147 GNUNET_GETOPT_option_relative_time ('d',
3103 "duration", 3148 "duration",
3104 "DURATION", 3149 "DURATION",
3105 gettext_noop("duration of the profiling"), 3150 gettext_noop (
3106 &duration), 3151 "duration of the profiling"),
3107 GNUNET_GETOPT_option_relative_time('t', 3152 &duration),
3108 "timeout", 3153 GNUNET_GETOPT_option_relative_time ('t',
3109 "TIMEOUT", 3154 "timeout",
3110 gettext_noop("timeout for the profiling"), 3155 "TIMEOUT",
3111 &timeout), 3156 gettext_noop (
3112 GNUNET_GETOPT_option_uint('r', 3157 "timeout for the profiling"),
3113 "num-requests", 3158 &timeout),
3114 "COUNT", 3159 GNUNET_GETOPT_option_uint ('r',
3115 gettext_noop("number of PeerIDs to request"), 3160 "num-requests",
3116 &cur_test_run.num_requests), 3161 "COUNT",
3162 gettext_noop ("number of PeerIDs to request"),
3163 &cur_test_run.num_requests),
3117 GNUNET_GETOPT_OPTION_END 3164 GNUNET_GETOPT_OPTION_END
3118 }; 3165 };
3119 3166
3120 unsetenv("XDG_DATA_HOME"); 3167 unsetenv ("XDG_DATA_HOME");
3121 unsetenv("XDG_CONFIG_HOME"); 3168 unsetenv ("XDG_CONFIG_HOME");
3122 //if (GNUNET_OK != 3169 // if (GNUNET_OK !=
3123 // GNUNET_STRINGS_get_utf8_args (argc, argv, 3170 // GNUNET_STRINGS_get_utf8_args (argc, argv,
3124 // &argc, &argv)) 3171 // &argc, &argv))
3125 // return 2; 3172 // return 2;
3126 ret_value = 0; 3173 ret_value = 0;
3127 if (GNUNET_OK != 3174 if (GNUNET_OK !=
3128 GNUNET_PROGRAM_run(argc, 3175 GNUNET_PROGRAM_run (argc,
3129 argv, 3176 argv,
3130 "gnunet-rps-profiler", 3177 "gnunet-rps-profiler",
3131 gettext_noop("Measure quality and performance of the RPS service."), 3178 gettext_noop (
3132 options, 3179 "Measure quality and performance of the RPS service."),
3133 &run, 3180 options,
3134 NULL)) 3181 &run,
3135 { 3182 NULL))
3136 ret_value = 1; 3183 {
3137 } 3184 ret_value = 1;
3185 }
3138 if (0 != ret_value) 3186 if (0 != ret_value)
3139 { 3187 {
3140 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 3188 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3141 "Test did not run successfully!\n"); 3189 "Test did not run successfully!\n");
3142 } 3190 }
3143 else 3191 else
3144 { 3192 {
3145 ret_value = cur_test_run.eval_cb(); 3193 ret_value = cur_test_run.eval_cb ();
3146 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) 3194 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view)
3147 { 3195 {
3148 GNUNET_array_grow(rps_peers->cur_view, 3196 GNUNET_array_grow (rps_peers->cur_view,
3149 rps_peers->cur_view_count, 3197 rps_peers->cur_view_count,
3150 0); 3198 0);
3151 } 3199 }
3152 GNUNET_free(rps_peers); 3200 GNUNET_free (rps_peers);
3153 GNUNET_free(rps_peer_ids); 3201 GNUNET_free (rps_peer_ids);
3154 GNUNET_CONTAINER_multipeermap_destroy(peer_map); 3202 GNUNET_CONTAINER_multipeermap_destroy (peer_map);
3155 } 3203 }
3156 return ret_value; 3204 return ret_value;
3157} 3205}
3158 3206
diff --git a/src/rps/gnunet-rps.c b/src/rps/gnunet-rps.c
index 84043341b..6c1c96cc9 100644
--- a/src/rps/gnunet-rps.c
+++ b/src/rps/gnunet-rps.c
@@ -68,13 +68,13 @@ static uint64_t num_view_updates;
68 * @param cls NULL 68 * @param cls NULL
69 */ 69 */
70static void 70static void
71do_shutdown(void *cls) 71do_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,23 +87,23 @@ do_shutdown(void *cls)
87 * @param recv_peers the received peers 87 * @param recv_peers the received peers
88 */ 88 */
89static void 89static void
90reply_handle(void *cls, 90reply_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 95
96 (void)cls; 96 (void) cls;
97 97
98 req_handle = NULL; 98 req_handle = NULL;
99 for (i = 0; i < n; i++) 99 for (i = 0; i < n; i++)
100 { 100 {
101 fprintf(stdout, "%s\n", 101 fprintf (stdout, "%s\n",
102 GNUNET_i2s_full(&recv_peers[i])); 102 GNUNET_i2s_full (&recv_peers[i]));
103 } 103 }
104 ret = 0; 104 ret = 0;
105 105
106 GNUNET_SCHEDULER_shutdown(); 106 GNUNET_SCHEDULER_shutdown ();
107} 107}
108 108
109/** 109/**
@@ -114,34 +114,34 @@ reply_handle(void *cls,
114 * @param recv_peers the received peers 114 * @param recv_peers the received peers
115 */ 115 */
116static void 116static void
117view_update_handle(void *cls, 117view_update_handle (void *cls,
118 uint64_t n, 118 uint64_t n,
119 const struct GNUNET_PeerIdentity *recv_peers) 119 const struct GNUNET_PeerIdentity *recv_peers)
120{ 120{
121 uint64_t i; 121 uint64_t i;
122 122
123 (void)cls; 123 (void) cls;
124 124
125 if (0 == n) 125 if (0 == n)
126 { 126 {
127 fprintf(stdout, "Empty view\n"); 127 fprintf (stdout, "Empty view\n");
128 } 128 }
129 req_handle = NULL; 129 req_handle = NULL;
130 for (i = 0; i < n; i++) 130 for (i = 0; i < n; i++)
131 { 131 {
132 fprintf(stdout, "%s\n", 132 fprintf (stdout, "%s\n",
133 GNUNET_i2s_full(&recv_peers[i])); 133 GNUNET_i2s_full (&recv_peers[i]));
134 } 134 }
135 135
136 if (1 == num_view_updates) 136 if (1 == num_view_updates)
137 { 137 {
138 ret = 0; 138 ret = 0;
139 GNUNET_SCHEDULER_shutdown(); 139 GNUNET_SCHEDULER_shutdown ();
140 } 140 }
141 else if (1 < num_view_updates) 141 else if (1 < num_view_updates)
142 { 142 {
143 num_view_updates--; 143 num_view_updates--;
144 } 144 }
145} 145}
146 146
147 147
@@ -152,24 +152,24 @@ view_update_handle(void *cls,
152 * @param recv_peers the received peers 152 * @param recv_peers the received peers
153 */ 153 */
154static void 154static void
155stream_input_handle(void *cls, 155stream_input_handle (void *cls,
156 uint64_t num_peers, 156 uint64_t num_peers,
157 const struct GNUNET_PeerIdentity *recv_peers) 157 const struct GNUNET_PeerIdentity *recv_peers)
158{ 158{
159 uint64_t i; 159 uint64_t i;
160 160
161 (void)cls; 161 (void) cls;
162 162
163 if (0 == num_peers) 163 if (0 == num_peers)
164 { 164 {
165 fprintf(stdout, "No peer was returned\n"); 165 fprintf (stdout, "No peer was returned\n");
166 } 166 }
167 req_handle = NULL; 167 req_handle = NULL;
168 for (i = 0; i < num_peers; i++) 168 for (i = 0; i < num_peers; i++)
169 { 169 {
170 fprintf(stdout, "%s\n", 170 fprintf (stdout, "%s\n",
171 GNUNET_i2s_full(&recv_peers[i])); 171 GNUNET_i2s_full (&recv_peers[i]));
172 } 172 }
173} 173}
174 174
175 175
@@ -182,69 +182,71 @@ stream_input_handle(void *cls,
182 * @param cfg configuration 182 * @param cfg configuration
183 */ 183 */
184static void 184static void
185run(void *cls, 185run (void *cls,
186 char *const *args, 186 char *const *args,
187 const char *cfgfile, 187 const char *cfgfile,
188 const struct GNUNET_CONFIGURATION_Handle *cfg) 188 const struct GNUNET_CONFIGURATION_Handle *cfg)
189{ 189{
190 static uint64_t num_peers; 190 static uint64_t num_peers;
191 static struct GNUNET_PeerIdentity zero_pid; 191 static struct GNUNET_PeerIdentity zero_pid;
192 192
193 (void)cls; 193 (void) cls;
194 (void)cfgfile; 194 (void) cfgfile;
195 195
196 rps_handle = GNUNET_RPS_connect(cfg); 196 rps_handle = GNUNET_RPS_connect (cfg);
197 if (NULL == rps_handle) 197 if (NULL == rps_handle)
198 { 198 {
199 fprintf(stderr, "Failed to connect to the rps service\n"); 199 fprintf (stderr, "Failed to connect to the rps service\n");
200 return; 200 return;
201 } 201 }
202 202
203 if ((0 == memcmp(&zero_pid, &peer_id, sizeof(peer_id))) && 203 if ((0 == memcmp (&zero_pid, &peer_id, sizeof(peer_id))) &&
204 (!view_update) && 204 (! view_update) &&
205 (!stream_input)) 205 (! stream_input))
206 { /* Request n PeerIDs */ 206 { /* Request n PeerIDs */
207 /* If number was specified use it, else request single peer. */ 207 /* If number was specified use it, else request single peer. */
208 if (NULL == args[0] || 208 if ((NULL == args[0]) ||
209 0 == sscanf(args[0], "%lu", &num_peers)) 209 (0 == sscanf (args[0], "%lu", &num_peers)) )
210 { 210 {
211 num_peers = 1; 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 } 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,
216 NULL);
217 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
218 }
218 else if (view_update) 219 else if (view_update)
220 {
221 /* Get updates of view */
222 if ((NULL == args[0]) ||
223 (0 == sscanf (args[0], "%lu", &num_view_updates)) )
219 { 224 {
220 /* Get updates of view */ 225 num_view_updates = 0;
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);
234 } 226 }
227 GNUNET_RPS_view_request (rps_handle, num_view_updates, view_update_handle,
228 NULL);
229 if (0 != num_view_updates)
230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
231 "Requesting %" PRIu64 " view updates\n", num_view_updates);
232 else
233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
234 "Requesting continuous view updates\n");
235 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
236 }
235 else if (stream_input) 237 else if (stream_input)
236 { 238 {
237 /* Get updates of view */ 239 /* Get updates of view */
238 GNUNET_RPS_stream_request(rps_handle, stream_input_handle, NULL); 240 GNUNET_RPS_stream_request (rps_handle, stream_input_handle, NULL);
239 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); 241 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
240 } 242 }
241 else 243 else
242 { /* Seed PeerID */ 244 { /* Seed PeerID */
243 GNUNET_RPS_seed_ids(rps_handle, 1, &peer_id); 245 GNUNET_RPS_seed_ids (rps_handle, 1, &peer_id);
244 fprintf(stdout, "Seeded PeerID %s\n", GNUNET_i2s_full(&peer_id)); 246 fprintf (stdout, "Seeded PeerID %s\n", GNUNET_i2s_full (&peer_id));
245 ret = 0; 247 ret = 0;
246 GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); 248 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
247 } 249 }
248} 250}
249 251
250/** 252/**
@@ -255,34 +257,35 @@ run(void *cls,
255 * @return 0 ok, 1 on error 257 * @return 0 ok, 1 on error
256 */ 258 */
257int 259int
258main(int argc, char *const *argv) 260main (int argc, char *const *argv)
259{ 261{
260 const char helpstr[] = 262 const char helpstr[] =
261 "Get random GNUnet peers. If none is specified a single is requested."; 263 "Get random GNUnet peers. If none is specified a single is requested.";
262 struct GNUNET_GETOPT_CommandLineOption options[] = { 264 struct GNUNET_GETOPT_CommandLineOption options[] = {
263 GNUNET_GETOPT_option_base32_auto('s', 265 GNUNET_GETOPT_option_base32_auto ('s',
264 "seed", 266 "seed",
265 "PEER_ID", 267 "PEER_ID",
266 gettext_noop("Seed a PeerID"), 268 gettext_noop ("Seed a PeerID"),
267 &peer_id), 269 &peer_id),
268 GNUNET_GETOPT_option_flag('V', 270 GNUNET_GETOPT_option_flag ('V',
269 "view", 271 "view",
270 gettext_noop("Get updates of view (0 for infinite updates)"), 272 gettext_noop (
271 &view_update), 273 "Get updates of view (0 for infinite updates)"),
272 GNUNET_GETOPT_option_flag('S', 274 &view_update),
273 "stream", 275 GNUNET_GETOPT_option_flag ('S',
274 gettext_noop("Get peers from biased stream"), 276 "stream",
275 &stream_input), 277 gettext_noop ("Get peers from biased stream"),
278 &stream_input),
276 GNUNET_GETOPT_OPTION_END 279 GNUNET_GETOPT_OPTION_END
277 }; 280 };
278 281
279 return (GNUNET_OK == 282 return (GNUNET_OK ==
280 GNUNET_PROGRAM_run(argc, 283 GNUNET_PROGRAM_run (argc,
281 argv, 284 argv,
282 "gnunet-rps [NUMBER_OF_PEERS]", 285 "gnunet-rps [NUMBER_OF_PEERS]",
283 gettext_noop 286 gettext_noop
284 (helpstr), 287 (helpstr),
285 options, &run, NULL)) ? ret : 1; 288 options, &run, NULL)) ? ret : 1;
286} 289}
287 290
288/* end of gnunet-rps.c */ 291/* end of gnunet-rps.c */
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 32f3103ed..66ffd173a 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -41,7 +41,7 @@
41#include <inttypes.h> 41#include <inttypes.h>
42#include <string.h> 42#include <string.h>
43 43
44#define LOG(kind, ...) GNUNET_log(kind, __VA_ARGS__) 44#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
45 45
46// TODO check for overflows 46// TODO check for overflows
47 47
@@ -92,7 +92,8 @@
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 */
95struct PeerPendingOp { 95struct PeerPendingOp
96{
96 /** 97 /**
97 * Callback 98 * Callback
98 */ 99 */
@@ -110,7 +111,8 @@ struct PeerPendingOp {
110 * This is used to keep track of all messages that have not been sent yet. When 111 * This is used to keep track of all messages that have not been sent yet. When
111 * a peer is to be removed the pending messages can be removed properly. 112 * a peer is to be removed the pending messages can be removed properly.
112 */ 113 */
113struct PendingMessage { 114struct PendingMessage
115{
114 /** 116 /**
115 * DLL next, prev 117 * DLL next, prev
116 */ 118 */
@@ -146,7 +148,8 @@ struct ChannelCtx;
146 * status about the channels, the pending operations on this peer and some flags 148 * status about the channels, the pending operations on this peer and some flags
147 * about the status of the peer itself. (online, valid, ...) 149 * about the status of the peer itself. (online, valid, ...)
148 */ 150 */
149struct PeerContext { 151struct PeerContext
152{
150 /** 153 /**
151 * The Sub this context belongs to. 154 * The Sub this context belongs to.
152 */ 155 */
@@ -221,7 +224,8 @@ struct PeerContext {
221/** 224/**
222 * @brief Closure to #valid_peer_iterator 225 * @brief Closure to #valid_peer_iterator
223 */ 226 */
224struct PeersIteratorCls { 227struct PeersIteratorCls
228{
225 /** 229 /**
226 * Iterator function 230 * Iterator function
227 */ 231 */
@@ -236,7 +240,8 @@ struct PeersIteratorCls {
236/** 240/**
237 * @brief Context for a channel 241 * @brief Context for a channel
238 */ 242 */
239struct ChannelCtx { 243struct ChannelCtx
244{
240 /** 245 /**
241 * @brief The channel itself 246 * @brief The channel itself
242 */ 247 */
@@ -261,7 +266,8 @@ struct ChannelCtx {
261/** 266/**
262 * If type is 2 This struct is used to store the attacked peers in a DLL 267 * If type is 2 This struct is used to store the attacked peers in a DLL
263 */ 268 */
264struct AttackedPeer { 269struct AttackedPeer
270{
265 /** 271 /**
266 * DLL 272 * DLL
267 */ 273 */
@@ -296,7 +302,8 @@ struct AttackedPeer {
296 * Essentially one instance of brahms that only connects to other instances 302 * Essentially one instance of brahms that only connects to other instances
297 * with the same (secret) value. 303 * with the same (secret) value.
298 */ 304 */
299struct Sub { 305struct Sub
306{
300 /** 307 /**
301 * @brief Hash of the shared value that defines Subs. 308 * @brief Hash of the shared value that defines Subs.
302 */ 309 */
@@ -588,10 +595,10 @@ static const uint32_t num_valid_peers_max = UINT32_MAX;
588 595
589 596
590static void 597static void
591do_round(void *cls); 598do_round (void *cls);
592 599
593static void 600static void
594do_mal_round(void *cls); 601do_mal_round (void *cls);
595 602
596 603
597/** 604/**
@@ -603,16 +610,16 @@ do_mal_round(void *cls);
603 * @return the #PeerContext 610 * @return the #PeerContext
604 */ 611 */
605static struct PeerContext * 612static struct PeerContext *
606get_peer_ctx(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, 613get_peer_ctx (const struct GNUNET_CONTAINER_MultiPeerMap *peer_map,
607 const struct GNUNET_PeerIdentity *peer) 614 const struct GNUNET_PeerIdentity *peer)
608{ 615{
609 struct PeerContext *ctx; 616 struct PeerContext *ctx;
610 int ret; 617 int ret;
611 618
612 ret = GNUNET_CONTAINER_multipeermap_contains(peer_map, peer); 619 ret = GNUNET_CONTAINER_multipeermap_contains (peer_map, peer);
613 GNUNET_assert(GNUNET_YES == ret); 620 GNUNET_assert (GNUNET_YES == ret);
614 ctx = GNUNET_CONTAINER_multipeermap_get(peer_map, peer); 621 ctx = GNUNET_CONTAINER_multipeermap_get (peer_map, peer);
615 GNUNET_assert(NULL != ctx); 622 GNUNET_assert (NULL != ctx);
616 return ctx; 623 return ctx;
617} 624}
618 625
@@ -628,17 +635,17 @@ get_peer_ctx(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map,
628 * #GNUNET_NO if peer is not knwon 635 * #GNUNET_NO if peer is not knwon
629 */ 636 */
630static int 637static int
631check_peer_known(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, 638check_peer_known (const struct GNUNET_CONTAINER_MultiPeerMap *peer_map,
632 const struct GNUNET_PeerIdentity *peer) 639 const struct GNUNET_PeerIdentity *peer)
633{ 640{
634 if (NULL != peer_map) 641 if (NULL != peer_map)
635 { 642 {
636 return GNUNET_CONTAINER_multipeermap_contains(peer_map, peer); 643 return GNUNET_CONTAINER_multipeermap_contains (peer_map, peer);
637 } 644 }
638 else 645 else
639 { 646 {
640 return GNUNET_NO; 647 return GNUNET_NO;
641 } 648 }
642} 649}
643 650
644 651
@@ -651,27 +658,27 @@ check_peer_known(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map,
651 * @return the #PeerContext 658 * @return the #PeerContext
652 */ 659 */
653static struct PeerContext * 660static struct PeerContext *
654create_peer_ctx(struct Sub *sub, 661create_peer_ctx (struct Sub *sub,
655 const struct GNUNET_PeerIdentity *peer) 662 const struct GNUNET_PeerIdentity *peer)
656{ 663{
657 struct PeerContext *ctx; 664 struct PeerContext *ctx;
658 int ret; 665 int ret;
659 666
660 GNUNET_assert(GNUNET_NO == check_peer_known(sub->peer_map, peer)); 667 GNUNET_assert (GNUNET_NO == check_peer_known (sub->peer_map, peer));
661 668
662 ctx = GNUNET_new(struct PeerContext); 669 ctx = GNUNET_new (struct PeerContext);
663 ctx->peer_id = *peer; 670 ctx->peer_id = *peer;
664 ctx->sub = sub; 671 ctx->sub = sub;
665 ret = GNUNET_CONTAINER_multipeermap_put(sub->peer_map, peer, ctx, 672 ret = GNUNET_CONTAINER_multipeermap_put (sub->peer_map, peer, ctx,
666 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 673 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
667 GNUNET_assert(GNUNET_OK == ret); 674 GNUNET_assert (GNUNET_OK == ret);
668 if (sub == msub) 675 if (sub == msub)
669 { 676 {
670 GNUNET_STATISTICS_set(stats, 677 GNUNET_STATISTICS_set (stats,
671 "# known peers", 678 "# known peers",
672 GNUNET_CONTAINER_multipeermap_size(sub->peer_map), 679 GNUNET_CONTAINER_multipeermap_size (sub->peer_map),
673 GNUNET_NO); 680 GNUNET_NO);
674 } 681 }
675 return ctx; 682 return ctx;
676} 683}
677 684
@@ -685,14 +692,14 @@ create_peer_ctx(struct Sub *sub,
685 * @return the context 692 * @return the context
686 */ 693 */
687static struct PeerContext * 694static struct PeerContext *
688create_or_get_peer_ctx(struct Sub *sub, 695create_or_get_peer_ctx (struct Sub *sub,
689 const struct GNUNET_PeerIdentity *peer) 696 const struct GNUNET_PeerIdentity *peer)
690{ 697{
691 if (GNUNET_NO == check_peer_known(sub->peer_map, peer)) 698 if (GNUNET_NO == check_peer_known (sub->peer_map, peer))
692 { 699 {
693 return create_peer_ctx(sub, peer); 700 return create_peer_ctx (sub, peer);
694 } 701 }
695 return get_peer_ctx(sub->peer_map, peer); 702 return get_peer_ctx (sub->peer_map, peer);
696} 703}
697 704
698 705
@@ -707,25 +714,25 @@ create_or_get_peer_ctx(struct Sub *sub,
707 * #GNUNET_NO otherwise 714 * #GNUNET_NO otherwise
708 */ 715 */
709static int 716static int
710check_connected(struct PeerContext *peer_ctx) 717check_connected (struct PeerContext *peer_ctx)
711{ 718{
712 /* If we don't know about this peer we don't know whether it's online */ 719 /* If we don't know about this peer we don't know whether it's online */
713 if (GNUNET_NO == check_peer_known(peer_ctx->sub->peer_map, 720 if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map,
714 &peer_ctx->peer_id)) 721 &peer_ctx->peer_id))
715 { 722 {
716 return GNUNET_NO; 723 return GNUNET_NO;
717 } 724 }
718 /* Get the context */ 725 /* Get the context */
719 peer_ctx = get_peer_ctx(peer_ctx->sub->peer_map, &peer_ctx->peer_id); 726 peer_ctx = get_peer_ctx (peer_ctx->sub->peer_map, &peer_ctx->peer_id);
720 /* If we have no channel to this peer we don't know whether it's online */ 727 /* If we have no channel to this peer we don't know whether it's online */
721 if ((NULL == peer_ctx->send_channel_ctx) && 728 if ((NULL == peer_ctx->send_channel_ctx) &&
722 (NULL == peer_ctx->recv_channel_ctx)) 729 (NULL == peer_ctx->recv_channel_ctx))
723 { 730 {
724 UNSET_PEER_FLAG(peer_ctx, Peers_ONLINE); 731 UNSET_PEER_FLAG (peer_ctx, Peers_ONLINE);
725 return GNUNET_NO; 732 return GNUNET_NO;
726 } 733 }
727 /* Otherwise (if we have a channel, we know that it's online */ 734 /* Otherwise (if we have a channel, we know that it's online */
728 SET_PEER_FLAG(peer_ctx, Peers_ONLINE); 735 SET_PEER_FLAG (peer_ctx, Peers_ONLINE);
729 return GNUNET_YES; 736 return GNUNET_YES;
730} 737}
731 738
@@ -733,7 +740,8 @@ check_connected(struct PeerContext *peer_ctx)
733/** 740/**
734 * @brief The closure to #get_rand_peer_iterator. 741 * @brief The closure to #get_rand_peer_iterator.
735 */ 742 */
736struct GetRandPeerIteratorCls { 743struct GetRandPeerIteratorCls
744{
737 /** 745 /**
738 * @brief The index of the peer to return. 746 * @brief The index of the peer to return.
739 * Will be decreased until 0. 747 * Will be decreased until 0.
@@ -764,19 +772,19 @@ struct GetRandPeerIteratorCls {
764 * #GNUNET_NO if not. 772 * #GNUNET_NO if not.
765 */ 773 */
766static int 774static int
767get_rand_peer_iterator(void *cls, 775get_rand_peer_iterator (void *cls,
768 const struct GNUNET_PeerIdentity *peer, 776 const struct GNUNET_PeerIdentity *peer,
769 void *value) 777 void *value)
770{ 778{
771 struct GetRandPeerIteratorCls *iterator_cls = cls; 779 struct GetRandPeerIteratorCls *iterator_cls = cls;
772 780
773 (void)value; 781 (void) value;
774 782
775 if (0 >= iterator_cls->index) 783 if (0 >= iterator_cls->index)
776 { 784 {
777 iterator_cls->peer = peer; 785 iterator_cls->peer = peer;
778 return GNUNET_NO; 786 return GNUNET_NO;
779 } 787 }
780 iterator_cls->index--; 788 iterator_cls->index--;
781 return GNUNET_YES; 789 return GNUNET_YES;
782} 790}
@@ -791,19 +799,20 @@ get_rand_peer_iterator(void *cls,
791 * @return a random peer 799 * @return a random peer
792 */ 800 */
793static const struct GNUNET_PeerIdentity * 801static const struct GNUNET_PeerIdentity *
794get_random_peer_from_peermap(struct GNUNET_CONTAINER_MultiPeerMap *valid_peers) 802get_random_peer_from_peermap (struct GNUNET_CONTAINER_MultiPeerMap *valid_peers)
795{ 803{
796 struct GetRandPeerIteratorCls *iterator_cls; 804 struct GetRandPeerIteratorCls *iterator_cls;
797 const struct GNUNET_PeerIdentity *ret; 805 const struct GNUNET_PeerIdentity *ret;
798 806
799 iterator_cls = GNUNET_new(struct GetRandPeerIteratorCls); 807 iterator_cls = GNUNET_new (struct GetRandPeerIteratorCls);
800 iterator_cls->index = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 808 iterator_cls->index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
801 GNUNET_CONTAINER_multipeermap_size(valid_peers)); 809 GNUNET_CONTAINER_multipeermap_size (
802 (void)GNUNET_CONTAINER_multipeermap_iterate(valid_peers, 810 valid_peers));
803 get_rand_peer_iterator, 811 (void) GNUNET_CONTAINER_multipeermap_iterate (valid_peers,
804 iterator_cls); 812 get_rand_peer_iterator,
813 iterator_cls);
805 ret = iterator_cls->peer; 814 ret = iterator_cls->peer;
806 GNUNET_free(iterator_cls); 815 GNUNET_free (iterator_cls);
807 return ret; 816 return ret;
808} 817}
809 818
@@ -820,8 +829,8 @@ get_random_peer_from_peermap(struct GNUNET_CONTAINER_MultiPeerMap *valid_peers)
820 * #GNUNET_NO otherwise 829 * #GNUNET_NO otherwise
821 */ 830 */
822static int 831static int
823add_valid_peer(const struct GNUNET_PeerIdentity *peer, 832add_valid_peer (const struct GNUNET_PeerIdentity *peer,
824 struct GNUNET_CONTAINER_MultiPeerMap *valid_peers) 833 struct GNUNET_CONTAINER_MultiPeerMap *valid_peers)
825{ 834{
826 const struct GNUNET_PeerIdentity *rand_peer; 835 const struct GNUNET_PeerIdentity *rand_peer;
827 int ret; 836 int ret;
@@ -829,26 +838,26 @@ add_valid_peer(const struct GNUNET_PeerIdentity *peer,
829 ret = GNUNET_YES; 838 ret = GNUNET_YES;
830 /* Remove random peers until there is space for a new one */ 839 /* Remove random peers until there is space for a new one */
831 while (num_valid_peers_max <= 840 while (num_valid_peers_max <=
832 GNUNET_CONTAINER_multipeermap_size(valid_peers)) 841 GNUNET_CONTAINER_multipeermap_size (valid_peers))
833 { 842 {
834 rand_peer = get_random_peer_from_peermap(valid_peers); 843 rand_peer = get_random_peer_from_peermap (valid_peers);
835 GNUNET_CONTAINER_multipeermap_remove_all(valid_peers, rand_peer); 844 GNUNET_CONTAINER_multipeermap_remove_all (valid_peers, rand_peer);
836 ret = GNUNET_NO; 845 ret = GNUNET_NO;
837 } 846 }
838 (void)GNUNET_CONTAINER_multipeermap_put(valid_peers, peer, NULL, 847 (void) GNUNET_CONTAINER_multipeermap_put (valid_peers, peer, NULL,
839 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 848 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
840 if (valid_peers == msub->valid_peers) 849 if (valid_peers == msub->valid_peers)
841 { 850 {
842 GNUNET_STATISTICS_set(stats, 851 GNUNET_STATISTICS_set (stats,
843 "# valid peers", 852 "# valid peers",
844 GNUNET_CONTAINER_multipeermap_size(valid_peers), 853 GNUNET_CONTAINER_multipeermap_size (valid_peers),
845 GNUNET_NO); 854 GNUNET_NO);
846 } 855 }
847 return ret; 856 return ret;
848} 857}
849 858
850static void 859static void
851remove_pending_message(struct PendingMessage *pending_msg, int cancel); 860remove_pending_message (struct PendingMessage *pending_msg, int cancel);
852 861
853/** 862/**
854 * @brief Set the peer flag to living and 863 * @brief Set the peer flag to living and
@@ -859,62 +868,62 @@ remove_pending_message(struct PendingMessage *pending_msg, int cancel);
859 * @param peer_ctx the #PeerContext of the peer to set online 868 * @param peer_ctx the #PeerContext of the peer to set online
860 */ 869 */
861static void 870static void
862set_peer_online(struct PeerContext *peer_ctx) 871set_peer_online (struct PeerContext *peer_ctx)
863{ 872{
864 struct GNUNET_PeerIdentity *peer; 873 struct GNUNET_PeerIdentity *peer;
865 unsigned int i; 874 unsigned int i;
866 875
867 peer = &peer_ctx->peer_id; 876 peer = &peer_ctx->peer_id;
868 LOG(GNUNET_ERROR_TYPE_DEBUG, 877 LOG (GNUNET_ERROR_TYPE_DEBUG,
869 "Peer %s is online and valid, calling %i pending operations on it\n", 878 "Peer %s is online and valid, calling %i pending operations on it\n",
870 GNUNET_i2s(peer), 879 GNUNET_i2s (peer),
871 peer_ctx->num_pending_ops); 880 peer_ctx->num_pending_ops);
872 881
873 if (NULL != peer_ctx->online_check_pending) 882 if (NULL != peer_ctx->online_check_pending)
874 { 883 {
875 LOG(GNUNET_ERROR_TYPE_DEBUG, 884 LOG (GNUNET_ERROR_TYPE_DEBUG,
876 "Removing pending online check for peer %s\n", 885 "Removing pending online check for peer %s\n",
877 GNUNET_i2s(&peer_ctx->peer_id)); 886 GNUNET_i2s (&peer_ctx->peer_id));
878 // TODO wait until cadet sets mq->cancel_impl 887 // TODO wait until cadet sets mq->cancel_impl
879 //GNUNET_MQ_send_cancel (peer_ctx->online_check_pending->ev); 888 // GNUNET_MQ_send_cancel (peer_ctx->online_check_pending->ev);
880 remove_pending_message(peer_ctx->online_check_pending, GNUNET_YES); 889 remove_pending_message (peer_ctx->online_check_pending, GNUNET_YES);
881 peer_ctx->online_check_pending = NULL; 890 peer_ctx->online_check_pending = NULL;
882 } 891 }
883 892
884 SET_PEER_FLAG(peer_ctx, Peers_ONLINE); 893 SET_PEER_FLAG (peer_ctx, Peers_ONLINE);
885 894
886 /* Call pending operations */ 895 /* Call pending operations */
887 for (i = 0; i < peer_ctx->num_pending_ops; i++) 896 for (i = 0; i < peer_ctx->num_pending_ops; i++)
888 { 897 {
889 peer_ctx->pending_ops[i].op(peer_ctx->pending_ops[i].op_cls, peer); 898 peer_ctx->pending_ops[i].op (peer_ctx->pending_ops[i].op_cls, peer);
890 } 899 }
891 GNUNET_array_grow(peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0); 900 GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0);
892} 901}
893 902
894static void 903static void
895cleanup_destroyed_channel(void *cls, 904cleanup_destroyed_channel (void *cls,
896 const struct GNUNET_CADET_Channel *channel); 905 const struct GNUNET_CADET_Channel *channel);
897 906
898/* Declaration of handlers */ 907/* Declaration of handlers */
899static void 908static void
900handle_peer_check(void *cls, 909handle_peer_check (void *cls,
901 const struct GNUNET_MessageHeader *msg); 910 const struct GNUNET_MessageHeader *msg);
902 911
903static void 912static void
904handle_peer_push(void *cls, 913handle_peer_push (void *cls,
905 const struct GNUNET_MessageHeader *msg); 914 const struct GNUNET_MessageHeader *msg);
906 915
907static void 916static void
908handle_peer_pull_request(void *cls, 917handle_peer_pull_request (void *cls,
909 const struct GNUNET_MessageHeader *msg); 918 const struct GNUNET_MessageHeader *msg);
910 919
911static int 920static int
912check_peer_pull_reply(void *cls, 921check_peer_pull_reply (void *cls,
913 const struct GNUNET_RPS_P2P_PullReplyMessage *msg); 922 const struct GNUNET_RPS_P2P_PullReplyMessage *msg);
914 923
915static void 924static void
916handle_peer_pull_reply(void *cls, 925handle_peer_pull_reply (void *cls,
917 const struct GNUNET_RPS_P2P_PullReplyMessage *msg); 926 const struct GNUNET_RPS_P2P_PullReplyMessage *msg);
918 927
919/* End declaration of handlers */ 928/* End declaration of handlers */
920 929
@@ -926,11 +935,11 @@ handle_peer_pull_reply(void *cls,
926 * @return The channel context 935 * @return The channel context
927 */ 936 */
928static struct ChannelCtx * 937static struct ChannelCtx *
929add_channel_ctx(struct PeerContext *peer_ctx) 938add_channel_ctx (struct PeerContext *peer_ctx)
930{ 939{
931 struct ChannelCtx *channel_ctx; 940 struct ChannelCtx *channel_ctx;
932 941
933 channel_ctx = GNUNET_new(struct ChannelCtx); 942 channel_ctx = GNUNET_new (struct ChannelCtx);
934 channel_ctx->peer_ctx = peer_ctx; 943 channel_ctx->peer_ctx = peer_ctx;
935 return channel_ctx; 944 return channel_ctx;
936} 945}
@@ -942,29 +951,29 @@ add_channel_ctx(struct PeerContext *peer_ctx)
942 * @param channel_ctx The channel context. 951 * @param channel_ctx The channel context.
943 */ 952 */
944static void 953static void
945remove_channel_ctx(struct ChannelCtx *channel_ctx) 954remove_channel_ctx (struct ChannelCtx *channel_ctx)
946{ 955{
947 struct PeerContext *peer_ctx = channel_ctx->peer_ctx; 956 struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
948 957
949 if (NULL != channel_ctx->destruction_task) 958 if (NULL != channel_ctx->destruction_task)
950 { 959 {
951 GNUNET_SCHEDULER_cancel(channel_ctx->destruction_task); 960 GNUNET_SCHEDULER_cancel (channel_ctx->destruction_task);
952 channel_ctx->destruction_task = NULL; 961 channel_ctx->destruction_task = NULL;
953 } 962 }
954 963
955 GNUNET_free(channel_ctx); 964 GNUNET_free (channel_ctx);
956 965
957 if (NULL == peer_ctx) 966 if (NULL == peer_ctx)
958 return; 967 return;
959 if (channel_ctx == peer_ctx->send_channel_ctx) 968 if (channel_ctx == peer_ctx->send_channel_ctx)
960 { 969 {
961 peer_ctx->send_channel_ctx = NULL; 970 peer_ctx->send_channel_ctx = NULL;
962 peer_ctx->mq = NULL; 971 peer_ctx->mq = NULL;
963 } 972 }
964 else if (channel_ctx == peer_ctx->recv_channel_ctx) 973 else if (channel_ctx == peer_ctx->recv_channel_ctx)
965 { 974 {
966 peer_ctx->recv_channel_ctx = NULL; 975 peer_ctx->recv_channel_ctx = NULL;
967 } 976 }
968} 977}
969 978
970 979
@@ -975,47 +984,47 @@ remove_channel_ctx(struct ChannelCtx *channel_ctx)
975 * @return the #GNUNET_CADET_Channel used to send data to @a peer_ctx 984 * @return the #GNUNET_CADET_Channel used to send data to @a peer_ctx
976 */ 985 */
977struct GNUNET_CADET_Channel * 986struct GNUNET_CADET_Channel *
978get_channel(struct PeerContext *peer_ctx) 987get_channel (struct PeerContext *peer_ctx)
979{ 988{
980 /* There exists a copy-paste-clone in run() */ 989 /* There exists a copy-paste-clone in run() */
981 struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 990 struct GNUNET_MQ_MessageHandler cadet_handlers[] = {
982 GNUNET_MQ_hd_fixed_size(peer_check, 991 GNUNET_MQ_hd_fixed_size (peer_check,
983 GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE, 992 GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE,
984 struct GNUNET_MessageHeader, 993 struct GNUNET_MessageHeader,
985 NULL), 994 NULL),
986 GNUNET_MQ_hd_fixed_size(peer_push, 995 GNUNET_MQ_hd_fixed_size (peer_push,
987 GNUNET_MESSAGE_TYPE_RPS_PP_PUSH, 996 GNUNET_MESSAGE_TYPE_RPS_PP_PUSH,
988 struct GNUNET_MessageHeader, 997 struct GNUNET_MessageHeader,
989 NULL), 998 NULL),
990 GNUNET_MQ_hd_fixed_size(peer_pull_request, 999 GNUNET_MQ_hd_fixed_size (peer_pull_request,
991 GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST, 1000 GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST,
992 struct GNUNET_MessageHeader, 1001 struct GNUNET_MessageHeader,
993 NULL), 1002 NULL),
994 GNUNET_MQ_hd_var_size(peer_pull_reply, 1003 GNUNET_MQ_hd_var_size (peer_pull_reply,
995 GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY, 1004 GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY,
996 struct GNUNET_RPS_P2P_PullReplyMessage, 1005 struct GNUNET_RPS_P2P_PullReplyMessage,
997 NULL), 1006 NULL),
998 GNUNET_MQ_handler_end() 1007 GNUNET_MQ_handler_end ()
999 }; 1008 };
1000 1009
1001 1010
1002 if (NULL == peer_ctx->send_channel_ctx) 1011 if (NULL == peer_ctx->send_channel_ctx)
1003 { 1012 {
1004 LOG(GNUNET_ERROR_TYPE_DEBUG, 1013 LOG (GNUNET_ERROR_TYPE_DEBUG,
1005 "Trying to establish channel to peer %s\n", 1014 "Trying to establish channel to peer %s\n",
1006 GNUNET_i2s(&peer_ctx->peer_id)); 1015 GNUNET_i2s (&peer_ctx->peer_id));
1007 peer_ctx->send_channel_ctx = add_channel_ctx(peer_ctx); 1016 peer_ctx->send_channel_ctx = add_channel_ctx (peer_ctx);
1008 peer_ctx->send_channel_ctx->channel = 1017 peer_ctx->send_channel_ctx->channel =
1009 GNUNET_CADET_channel_create(cadet_handle, 1018 GNUNET_CADET_channel_create (cadet_handle,
1010 peer_ctx->send_channel_ctx, /* context */ 1019 peer_ctx->send_channel_ctx, /* context */
1011 &peer_ctx->peer_id, 1020 &peer_ctx->peer_id,
1012 &peer_ctx->sub->hash, 1021 &peer_ctx->sub->hash,
1013 NULL, /* WindowSize handler */ 1022 NULL, /* WindowSize handler */
1014 &cleanup_destroyed_channel, /* Disconnect handler */ 1023 &cleanup_destroyed_channel, /* Disconnect handler */
1015 cadet_handlers); 1024 cadet_handlers);
1016 } 1025 }
1017 GNUNET_assert(NULL != peer_ctx->send_channel_ctx); 1026 GNUNET_assert (NULL != peer_ctx->send_channel_ctx);
1018 GNUNET_assert(NULL != peer_ctx->send_channel_ctx->channel); 1027 GNUNET_assert (NULL != peer_ctx->send_channel_ctx->channel);
1019 return peer_ctx->send_channel_ctx->channel; 1028 return peer_ctx->send_channel_ctx->channel;
1020} 1029}
1021 1030
@@ -1030,12 +1039,12 @@ get_channel(struct PeerContext *peer_ctx)
1030 * @return the #GNUNET_MQ_Handle 1039 * @return the #GNUNET_MQ_Handle
1031 */ 1040 */
1032static struct GNUNET_MQ_Handle * 1041static struct GNUNET_MQ_Handle *
1033get_mq(struct PeerContext *peer_ctx) 1042get_mq (struct PeerContext *peer_ctx)
1034{ 1043{
1035 if (NULL == peer_ctx->mq) 1044 if (NULL == peer_ctx->mq)
1036 { 1045 {
1037 peer_ctx->mq = GNUNET_CADET_get_mq(get_channel(peer_ctx)); 1046 peer_ctx->mq = GNUNET_CADET_get_mq (get_channel (peer_ctx));
1038 } 1047 }
1039 return peer_ctx->mq; 1048 return peer_ctx->mq;
1040} 1049}
1041 1050
@@ -1048,19 +1057,19 @@ get_mq(struct PeerContext *peer_ctx)
1048 * @return pointer to pending message 1057 * @return pointer to pending message
1049 */ 1058 */
1050static struct PendingMessage * 1059static struct PendingMessage *
1051insert_pending_message(struct PeerContext *peer_ctx, 1060insert_pending_message (struct PeerContext *peer_ctx,
1052 struct GNUNET_MQ_Envelope *ev, 1061 struct GNUNET_MQ_Envelope *ev,
1053 const char *type) 1062 const char *type)
1054{ 1063{
1055 struct PendingMessage *pending_msg; 1064 struct PendingMessage *pending_msg;
1056 1065
1057 pending_msg = GNUNET_new(struct PendingMessage); 1066 pending_msg = GNUNET_new (struct PendingMessage);
1058 pending_msg->ev = ev; 1067 pending_msg->ev = ev;
1059 pending_msg->peer_ctx = peer_ctx; 1068 pending_msg->peer_ctx = peer_ctx;
1060 pending_msg->type = type; 1069 pending_msg->type = type;
1061 GNUNET_CONTAINER_DLL_insert(peer_ctx->pending_messages_head, 1070 GNUNET_CONTAINER_DLL_insert (peer_ctx->pending_messages_head,
1062 peer_ctx->pending_messages_tail, 1071 peer_ctx->pending_messages_tail,
1063 pending_msg); 1072 pending_msg);
1064 return pending_msg; 1073 return pending_msg;
1065} 1074}
1066 1075
@@ -1072,23 +1081,23 @@ insert_pending_message(struct PeerContext *peer_ctx,
1072 * @param cancel whether to cancel the pending message, too 1081 * @param cancel whether to cancel the pending message, too
1073 */ 1082 */
1074static void 1083static void
1075remove_pending_message(struct PendingMessage *pending_msg, int cancel) 1084remove_pending_message (struct PendingMessage *pending_msg, int cancel)
1076{ 1085{
1077 struct PeerContext *peer_ctx; 1086 struct PeerContext *peer_ctx;
1078 1087
1079 (void)cancel; 1088 (void) cancel;
1080 1089
1081 peer_ctx = pending_msg->peer_ctx; 1090 peer_ctx = pending_msg->peer_ctx;
1082 GNUNET_assert(NULL != peer_ctx); 1091 GNUNET_assert (NULL != peer_ctx);
1083 GNUNET_CONTAINER_DLL_remove(peer_ctx->pending_messages_head, 1092 GNUNET_CONTAINER_DLL_remove (peer_ctx->pending_messages_head,
1084 peer_ctx->pending_messages_tail, 1093 peer_ctx->pending_messages_tail,
1085 pending_msg); 1094 pending_msg);
1086 // TODO wait for the cadet implementation of message cancellation 1095 // TODO wait for the cadet implementation of message cancellation
1087 //if (GNUNET_YES == cancel) 1096 // if (GNUNET_YES == cancel)
1088 //{ 1097 // {
1089 // GNUNET_MQ_send_cancel (pending_msg->ev); 1098 // GNUNET_MQ_send_cancel (pending_msg->ev);
1090 //} 1099 // }
1091 GNUNET_free(pending_msg); 1100 GNUNET_free (pending_msg);
1092} 1101}
1093 1102
1094 1103
@@ -1099,20 +1108,20 @@ remove_pending_message(struct PendingMessage *pending_msg, int cancel)
1099 * @param cls #PeerContext of peer with pending online check 1108 * @param cls #PeerContext of peer with pending online check
1100 */ 1109 */
1101static void 1110static void
1102mq_online_check_successful(void *cls) 1111mq_online_check_successful (void *cls)
1103{ 1112{
1104 struct PeerContext *peer_ctx = cls; 1113 struct PeerContext *peer_ctx = cls;
1105 1114
1106 if (NULL != peer_ctx->online_check_pending) 1115 if (NULL != peer_ctx->online_check_pending)
1107 { 1116 {
1108 LOG(GNUNET_ERROR_TYPE_DEBUG, 1117 LOG (GNUNET_ERROR_TYPE_DEBUG,
1109 "Online check for peer %s was successfull\n", 1118 "Online check for peer %s was successfull\n",
1110 GNUNET_i2s(&peer_ctx->peer_id)); 1119 GNUNET_i2s (&peer_ctx->peer_id));
1111 remove_pending_message(peer_ctx->online_check_pending, GNUNET_YES); 1120 remove_pending_message (peer_ctx->online_check_pending, GNUNET_YES);
1112 peer_ctx->online_check_pending = NULL; 1121 peer_ctx->online_check_pending = NULL;
1113 set_peer_online(peer_ctx); 1122 set_peer_online (peer_ctx);
1114 (void)add_valid_peer(&peer_ctx->peer_id, peer_ctx->sub->valid_peers); 1123 (void) add_valid_peer (&peer_ctx->peer_id, peer_ctx->sub->valid_peers);
1115 } 1124 }
1116} 1125}
1117 1126
1118/** 1127/**
@@ -1121,30 +1130,30 @@ mq_online_check_successful(void *cls)
1121 * @param peer_ctx the context of the peer 1130 * @param peer_ctx the context of the peer
1122 */ 1131 */
1123static void 1132static void
1124check_peer_online(struct PeerContext *peer_ctx) 1133check_peer_online (struct PeerContext *peer_ctx)
1125{ 1134{
1126 LOG(GNUNET_ERROR_TYPE_DEBUG, 1135 LOG (GNUNET_ERROR_TYPE_DEBUG,
1127 "Get informed about peer %s getting online\n", 1136 "Get informed about peer %s getting online\n",
1128 GNUNET_i2s(&peer_ctx->peer_id)); 1137 GNUNET_i2s (&peer_ctx->peer_id));
1129 1138
1130 struct GNUNET_MQ_Handle *mq; 1139 struct GNUNET_MQ_Handle *mq;
1131 struct GNUNET_MQ_Envelope *ev; 1140 struct GNUNET_MQ_Envelope *ev;
1132 1141
1133 ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE); 1142 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE);
1134 peer_ctx->online_check_pending = 1143 peer_ctx->online_check_pending =
1135 insert_pending_message(peer_ctx, ev, "Check online"); 1144 insert_pending_message (peer_ctx, ev, "Check online");
1136 mq = get_mq(peer_ctx); 1145 mq = get_mq (peer_ctx);
1137 GNUNET_MQ_notify_sent(ev, 1146 GNUNET_MQ_notify_sent (ev,
1138 mq_online_check_successful, 1147 mq_online_check_successful,
1139 peer_ctx); 1148 peer_ctx);
1140 GNUNET_MQ_send(mq, ev); 1149 GNUNET_MQ_send (mq, ev);
1141 if (peer_ctx->sub == msub) 1150 if (peer_ctx->sub == msub)
1142 { 1151 {
1143 GNUNET_STATISTICS_update(stats, 1152 GNUNET_STATISTICS_update (stats,
1144 "# pending online checks", 1153 "# pending online checks",
1145 1, 1154 1,
1146 GNUNET_NO); 1155 GNUNET_NO);
1147 } 1156 }
1148} 1157}
1149 1158
1150 1159
@@ -1161,8 +1170,8 @@ check_peer_online(struct PeerContext *peer_ctx)
1161 * #GNUNET_NO otherwise 1170 * #GNUNET_NO otherwise
1162 */ 1171 */
1163static int 1172static int
1164check_operation_scheduled(const struct PeerContext *peer_ctx, 1173check_operation_scheduled (const struct PeerContext *peer_ctx,
1165 const PeerOp peer_op) 1174 const PeerOp peer_op)
1166{ 1175{
1167 unsigned int i; 1176 unsigned int i;
1168 1177
@@ -1179,20 +1188,20 @@ check_operation_scheduled(const struct PeerContext *peer_ctx,
1179 * @param cls Context of the channel 1188 * @param cls Context of the channel
1180 */ 1189 */
1181static void 1190static void
1182destroy_channel(struct ChannelCtx *channel_ctx) 1191destroy_channel (struct ChannelCtx *channel_ctx)
1183{ 1192{
1184 struct GNUNET_CADET_Channel *channel; 1193 struct GNUNET_CADET_Channel *channel;
1185 1194
1186 if (NULL != channel_ctx->destruction_task) 1195 if (NULL != channel_ctx->destruction_task)
1187 { 1196 {
1188 GNUNET_SCHEDULER_cancel(channel_ctx->destruction_task); 1197 GNUNET_SCHEDULER_cancel (channel_ctx->destruction_task);
1189 channel_ctx->destruction_task = NULL; 1198 channel_ctx->destruction_task = NULL;
1190 } 1199 }
1191 GNUNET_assert(channel_ctx->channel != NULL); 1200 GNUNET_assert (channel_ctx->channel != NULL);
1192 channel = channel_ctx->channel; 1201 channel = channel_ctx->channel;
1193 channel_ctx->channel = NULL; 1202 channel_ctx->channel = NULL;
1194 GNUNET_CADET_channel_destroy(channel); 1203 GNUNET_CADET_channel_destroy (channel);
1195 remove_channel_ctx(channel_ctx); 1204 remove_channel_ctx (channel_ctx);
1196} 1205}
1197 1206
1198 1207
@@ -1204,12 +1213,12 @@ destroy_channel(struct ChannelCtx *channel_ctx)
1204 * @param cls 1213 * @param cls
1205 */ 1214 */
1206static void 1215static void
1207destroy_channel_cb(void *cls) 1216destroy_channel_cb (void *cls)
1208{ 1217{
1209 struct ChannelCtx *channel_ctx = cls; 1218 struct ChannelCtx *channel_ctx = cls;
1210 1219
1211 channel_ctx->destruction_task = NULL; 1220 channel_ctx->destruction_task = NULL;
1212 destroy_channel(channel_ctx); 1221 destroy_channel (channel_ctx);
1213} 1222}
1214 1223
1215 1224
@@ -1224,15 +1233,15 @@ destroy_channel_cb(void *cls)
1224 * @param channel_ctx channel to be destroyed. 1233 * @param channel_ctx channel to be destroyed.
1225 */ 1234 */
1226static void 1235static void
1227schedule_channel_destruction(struct ChannelCtx *channel_ctx) 1236schedule_channel_destruction (struct ChannelCtx *channel_ctx)
1228{ 1237{
1229 GNUNET_assert(NULL == 1238 GNUNET_assert (NULL ==
1230 channel_ctx->destruction_task); 1239 channel_ctx->destruction_task);
1231 GNUNET_assert(NULL != 1240 GNUNET_assert (NULL !=
1232 channel_ctx->channel); 1241 channel_ctx->channel);
1233 channel_ctx->destruction_task = 1242 channel_ctx->destruction_task =
1234 GNUNET_SCHEDULER_add_now(&destroy_channel_cb, 1243 GNUNET_SCHEDULER_add_now (&destroy_channel_cb,
1235 channel_ctx); 1244 channel_ctx);
1236} 1245}
1237 1246
1238 1247
@@ -1250,98 +1259,99 @@ schedule_channel_destruction(struct ChannelCtx *channel_ctx)
1250 * #GNUNET_NO otherwise 1259 * #GNUNET_NO otherwise
1251 */ 1260 */
1252static int 1261static int
1253destroy_peer(struct PeerContext *peer_ctx) 1262destroy_peer (struct PeerContext *peer_ctx)
1254{ 1263{
1255 GNUNET_assert(NULL != peer_ctx); 1264 GNUNET_assert (NULL != peer_ctx);
1256 GNUNET_assert(NULL != peer_ctx->sub->peer_map); 1265 GNUNET_assert (NULL != peer_ctx->sub->peer_map);
1257 if (GNUNET_NO == 1266 if (GNUNET_NO ==
1258 GNUNET_CONTAINER_multipeermap_contains(peer_ctx->sub->peer_map, 1267 GNUNET_CONTAINER_multipeermap_contains (peer_ctx->sub->peer_map,
1259 &peer_ctx->peer_id)) 1268 &peer_ctx->peer_id))
1260 { 1269 {
1261 return GNUNET_NO; 1270 return GNUNET_NO;
1262 } 1271 }
1263 SET_PEER_FLAG(peer_ctx, Peers_TO_DESTROY); 1272 SET_PEER_FLAG (peer_ctx, Peers_TO_DESTROY);
1264 LOG(GNUNET_ERROR_TYPE_DEBUG, 1273 LOG (GNUNET_ERROR_TYPE_DEBUG,
1265 "Going to remove peer %s\n", 1274 "Going to remove peer %s\n",
1266 GNUNET_i2s(&peer_ctx->peer_id)); 1275 GNUNET_i2s (&peer_ctx->peer_id));
1267 UNSET_PEER_FLAG(peer_ctx, Peers_ONLINE); 1276 UNSET_PEER_FLAG (peer_ctx, Peers_ONLINE);
1268 1277
1269 /* Clear list of pending operations */ 1278 /* Clear list of pending operations */
1270 // TODO this probably leaks memory 1279 // TODO this probably leaks memory
1271 // ('only' the cls to the function. Not sure what to do with it) 1280 // ('only' the cls to the function. Not sure what to do with it)
1272 GNUNET_array_grow(peer_ctx->pending_ops, 1281 GNUNET_array_grow (peer_ctx->pending_ops,
1273 peer_ctx->num_pending_ops, 1282 peer_ctx->num_pending_ops,
1274 0); 1283 0);
1275 /* Remove all pending messages */ 1284 /* Remove all pending messages */
1276 while (NULL != peer_ctx->pending_messages_head) 1285 while (NULL != peer_ctx->pending_messages_head)
1286 {
1287 LOG (GNUNET_ERROR_TYPE_DEBUG,
1288 "Removing unsent %s\n",
1289 peer_ctx->pending_messages_head->type);
1290 /* Cancle pending message, too */
1291 if ((NULL != peer_ctx->online_check_pending) &&
1292 (0 == memcmp (peer_ctx->pending_messages_head,
1293 peer_ctx->online_check_pending,
1294 sizeof(struct PendingMessage))))
1277 { 1295 {
1278 LOG(GNUNET_ERROR_TYPE_DEBUG, 1296 peer_ctx->online_check_pending = NULL;
1279 "Removing unsent %s\n", 1297 if (peer_ctx->sub == msub)
1280 peer_ctx->pending_messages_head->type); 1298 {
1281 /* Cancle pending message, too */ 1299 GNUNET_STATISTICS_update (stats,
1282 if ((NULL != peer_ctx->online_check_pending) && 1300 "# pending online checks",
1283 (0 == memcmp(peer_ctx->pending_messages_head, 1301 -1,
1284 peer_ctx->online_check_pending, 1302 GNUNET_NO);
1285 sizeof(struct PendingMessage)))) 1303 }
1286 { 1304 }
1287 peer_ctx->online_check_pending = NULL; 1305 remove_pending_message (peer_ctx->pending_messages_head,
1288 if (peer_ctx->sub == msub) 1306 GNUNET_YES);
1289 { 1307 }
1290 GNUNET_STATISTICS_update(stats,
1291 "# pending online checks",
1292 -1,
1293 GNUNET_NO);
1294 }
1295 }
1296 remove_pending_message(peer_ctx->pending_messages_head,
1297 GNUNET_YES);
1298 }
1299 1308
1300 /* If we are still waiting for notification whether this peer is online 1309 /* If we are still waiting for notification whether this peer is online
1301 * cancel the according task */ 1310 * cancel the according task */
1302 if (NULL != peer_ctx->online_check_pending) 1311 if (NULL != peer_ctx->online_check_pending)
1303 { 1312 {
1304 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1305 "Removing pending online check for peer %s\n", 1314 "Removing pending online check for peer %s\n",
1306 GNUNET_i2s(&peer_ctx->peer_id)); 1315 GNUNET_i2s (&peer_ctx->peer_id));
1307 // TODO wait until cadet sets mq->cancel_impl 1316 // TODO wait until cadet sets mq->cancel_impl
1308 //GNUNET_MQ_send_cancel (peer_ctx->online_check_pending->ev); 1317 // GNUNET_MQ_send_cancel (peer_ctx->online_check_pending->ev);
1309 remove_pending_message(peer_ctx->online_check_pending, 1318 remove_pending_message (peer_ctx->online_check_pending,
1310 GNUNET_YES); 1319 GNUNET_YES);
1311 peer_ctx->online_check_pending = NULL; 1320 peer_ctx->online_check_pending = NULL;
1312 } 1321 }
1313 1322
1314 if (NULL != peer_ctx->send_channel_ctx) 1323 if (NULL != peer_ctx->send_channel_ctx)
1315 { 1324 {
1316 /* This is possibly called from within channel destruction */ 1325 /* This is possibly called from within channel destruction */
1317 peer_ctx->send_channel_ctx->peer_ctx = NULL; 1326 peer_ctx->send_channel_ctx->peer_ctx = NULL;
1318 schedule_channel_destruction(peer_ctx->send_channel_ctx); 1327 schedule_channel_destruction (peer_ctx->send_channel_ctx);
1319 peer_ctx->send_channel_ctx = NULL; 1328 peer_ctx->send_channel_ctx = NULL;
1320 peer_ctx->mq = NULL; 1329 peer_ctx->mq = NULL;
1321 } 1330 }
1322 if (NULL != peer_ctx->recv_channel_ctx) 1331 if (NULL != peer_ctx->recv_channel_ctx)
1323 { 1332 {
1324 /* This is possibly called from within channel destruction */ 1333 /* This is possibly called from within channel destruction */
1325 peer_ctx->recv_channel_ctx->peer_ctx = NULL; 1334 peer_ctx->recv_channel_ctx->peer_ctx = NULL;
1326 schedule_channel_destruction(peer_ctx->recv_channel_ctx); 1335 schedule_channel_destruction (peer_ctx->recv_channel_ctx);
1327 peer_ctx->recv_channel_ctx = NULL; 1336 peer_ctx->recv_channel_ctx = NULL;
1328 } 1337 }
1329 1338
1330 if (GNUNET_YES != 1339 if (GNUNET_YES !=
1331 GNUNET_CONTAINER_multipeermap_remove_all(peer_ctx->sub->peer_map, 1340 GNUNET_CONTAINER_multipeermap_remove_all (peer_ctx->sub->peer_map,
1332 &peer_ctx->peer_id)) 1341 &peer_ctx->peer_id))
1333 { 1342 {
1334 LOG(GNUNET_ERROR_TYPE_WARNING, 1343 LOG (GNUNET_ERROR_TYPE_WARNING,
1335 "removing peer from peer_ctx->sub->peer_map failed\n"); 1344 "removing peer from peer_ctx->sub->peer_map failed\n");
1336 } 1345 }
1337 if (peer_ctx->sub == msub) 1346 if (peer_ctx->sub == msub)
1338 { 1347 {
1339 GNUNET_STATISTICS_set(stats, 1348 GNUNET_STATISTICS_set (stats,
1340 "# known peers", 1349 "# known peers",
1341 GNUNET_CONTAINER_multipeermap_size(peer_ctx->sub->peer_map), 1350 GNUNET_CONTAINER_multipeermap_size (
1342 GNUNET_NO); 1351 peer_ctx->sub->peer_map),
1343 } 1352 GNUNET_NO);
1344 GNUNET_free(peer_ctx); 1353 }
1354 GNUNET_free (peer_ctx);
1345 return GNUNET_YES; 1355 return GNUNET_YES;
1346} 1356}
1347 1357
@@ -1356,15 +1366,15 @@ destroy_peer(struct PeerContext *peer_ctx)
1356 * #GNUNET_NO if not. 1366 * #GNUNET_NO if not.
1357 */ 1367 */
1358static int 1368static int
1359peermap_clear_iterator(void *cls, 1369peermap_clear_iterator (void *cls,
1360 const struct GNUNET_PeerIdentity *key, 1370 const struct GNUNET_PeerIdentity *key,
1361 void *value) 1371 void *value)
1362{ 1372{
1363 struct Sub *sub = cls; 1373 struct Sub *sub = cls;
1364 1374
1365 (void)value; 1375 (void) value;
1366 1376
1367 destroy_peer(get_peer_ctx(sub->peer_map, key)); 1377 destroy_peer (get_peer_ctx (sub->peer_map, key));
1368 return GNUNET_YES; 1378 return GNUNET_YES;
1369} 1379}
1370 1380
@@ -1377,32 +1387,33 @@ peermap_clear_iterator(void *cls,
1377 * @param cls type of the message that was sent 1387 * @param cls type of the message that was sent
1378 */ 1388 */
1379static void 1389static void
1380mq_notify_sent_cb(void *cls) 1390mq_notify_sent_cb (void *cls)
1381{ 1391{
1382 struct PendingMessage *pending_msg = (struct PendingMessage *)cls; 1392 struct PendingMessage *pending_msg = (struct PendingMessage *) cls;
1383 1393
1384 LOG(GNUNET_ERROR_TYPE_DEBUG, 1394 LOG (GNUNET_ERROR_TYPE_DEBUG,
1385 "%s was sent.\n", 1395 "%s was sent.\n",
1386 pending_msg->type); 1396 pending_msg->type);
1387 if (pending_msg->peer_ctx->sub == msub) 1397 if (pending_msg->peer_ctx->sub == msub)
1388 { 1398 {
1389 if (0 == strncmp("PULL REPLY", pending_msg->type, 10)) 1399 if (0 == strncmp ("PULL REPLY", pending_msg->type, 10))
1390 GNUNET_STATISTICS_update(stats, "# pull replys sent", 1, GNUNET_NO); 1400 GNUNET_STATISTICS_update (stats, "# pull replys sent", 1, GNUNET_NO);
1391 if (0 == strncmp("PULL REQUEST", pending_msg->type, 12)) 1401 if (0 == strncmp ("PULL REQUEST", pending_msg->type, 12))
1392 GNUNET_STATISTICS_update(stats, "# pull requests sent", 1, GNUNET_NO); 1402 GNUNET_STATISTICS_update (stats, "# pull requests sent", 1, GNUNET_NO);
1393 if (0 == strncmp("PUSH", pending_msg->type, 4)) 1403 if (0 == strncmp ("PUSH", pending_msg->type, 4))
1394 GNUNET_STATISTICS_update(stats, "# pushes sent", 1, GNUNET_NO); 1404 GNUNET_STATISTICS_update (stats, "# pushes sent", 1, GNUNET_NO);
1395 if (0 == strncmp("PULL REQUEST", pending_msg->type, 12) && 1405 if ((0 == strncmp ("PULL REQUEST", pending_msg->type, 12)) &&
1396 NULL != map_single_hop && 1406 (NULL != map_single_hop) &&
1397 GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(map_single_hop, 1407 (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop,
1398 &pending_msg->peer_ctx->peer_id)) 1408 &pending_msg->
1399 GNUNET_STATISTICS_update(stats, 1409 peer_ctx->peer_id)) )
1400 "# pull requests sent (multi-hop peer)", 1410 GNUNET_STATISTICS_update (stats,
1401 1, 1411 "# pull requests sent (multi-hop peer)",
1402 GNUNET_NO); 1412 1,
1403 } 1413 GNUNET_NO);
1414 }
1404 /* Do not cancle message */ 1415 /* Do not cancle message */
1405 remove_pending_message(pending_msg, GNUNET_NO); 1416 remove_pending_message (pending_msg, GNUNET_NO);
1406} 1417}
1407 1418
1408 1419
@@ -1421,30 +1432,30 @@ mq_notify_sent_cb(void *cls)
1421 * #GNUNET_NO if not. 1432 * #GNUNET_NO if not.
1422 */ 1433 */
1423static int 1434static int
1424store_peer_presistently_iterator(void *cls, 1435store_peer_presistently_iterator (void *cls,
1425 const struct GNUNET_PeerIdentity *peer, 1436 const struct GNUNET_PeerIdentity *peer,
1426 void *value) 1437 void *value)
1427{ 1438{
1428 const struct GNUNET_DISK_FileHandle *fh = cls; 1439 const struct GNUNET_DISK_FileHandle *fh = cls;
1429 char peer_string[128]; 1440 char peer_string[128];
1430 int size; 1441 int size;
1431 ssize_t ret; 1442 ssize_t ret;
1432 1443
1433 (void)value; 1444 (void) value;
1434 1445
1435 if (NULL == peer) 1446 if (NULL == peer)
1436 { 1447 {
1437 return GNUNET_YES; 1448 return GNUNET_YES;
1438 } 1449 }
1439 size = GNUNET_snprintf(peer_string, 1450 size = GNUNET_snprintf (peer_string,
1440 sizeof(peer_string), 1451 sizeof(peer_string),
1441 "%s\n", 1452 "%s\n",
1442 GNUNET_i2s_full(peer)); 1453 GNUNET_i2s_full (peer));
1443 GNUNET_assert(53 == size); 1454 GNUNET_assert (53 == size);
1444 ret = GNUNET_DISK_file_write(fh, 1455 ret = GNUNET_DISK_file_write (fh,
1445 peer_string, 1456 peer_string,
1446 size); 1457 size);
1447 GNUNET_assert(size == ret); 1458 GNUNET_assert (size == ret);
1448 return GNUNET_YES; 1459 return GNUNET_YES;
1449} 1460}
1450 1461
@@ -1455,54 +1466,54 @@ store_peer_presistently_iterator(void *cls,
1455 * @param sub Sub for which to store the valid peers 1466 * @param sub Sub for which to store the valid peers
1456 */ 1467 */
1457static void 1468static void
1458store_valid_peers(const struct Sub *sub) 1469store_valid_peers (const struct Sub *sub)
1459{ 1470{
1460 struct GNUNET_DISK_FileHandle *fh; 1471 struct GNUNET_DISK_FileHandle *fh;
1461 uint32_t number_written_peers; 1472 uint32_t number_written_peers;
1462 int ret; 1473 int ret;
1463 1474
1464 if (0 == strncmp("DISABLE", sub->filename_valid_peers, 7)) 1475 if (0 == strncmp ("DISABLE", sub->filename_valid_peers, 7))
1465 { 1476 {
1466 return; 1477 return;
1467 } 1478 }
1468 1479
1469 ret = GNUNET_DISK_directory_create_for_file(sub->filename_valid_peers); 1480 ret = GNUNET_DISK_directory_create_for_file (sub->filename_valid_peers);
1470 if (GNUNET_SYSERR == ret) 1481 if (GNUNET_SYSERR == ret)
1471 { 1482 {
1472 LOG(GNUNET_ERROR_TYPE_WARNING, 1483 LOG (GNUNET_ERROR_TYPE_WARNING,
1473 "Not able to create directory for file `%s'\n", 1484 "Not able to create directory for file `%s'\n",
1474 sub->filename_valid_peers); 1485 sub->filename_valid_peers);
1475 GNUNET_break(0); 1486 GNUNET_break (0);
1476 } 1487 }
1477 else if (GNUNET_NO == ret) 1488 else if (GNUNET_NO == ret)
1478 { 1489 {
1479 LOG(GNUNET_ERROR_TYPE_WARNING, 1490 LOG (GNUNET_ERROR_TYPE_WARNING,
1480 "Directory for file `%s' exists but is not writable for us\n", 1491 "Directory for file `%s' exists but is not writable for us\n",
1481 sub->filename_valid_peers); 1492 sub->filename_valid_peers);
1482 GNUNET_break(0); 1493 GNUNET_break (0);
1483 } 1494 }
1484 fh = GNUNET_DISK_file_open(sub->filename_valid_peers, 1495 fh = GNUNET_DISK_file_open (sub->filename_valid_peers,
1485 GNUNET_DISK_OPEN_WRITE | 1496 GNUNET_DISK_OPEN_WRITE
1486 GNUNET_DISK_OPEN_CREATE, 1497 | GNUNET_DISK_OPEN_CREATE,
1487 GNUNET_DISK_PERM_USER_READ | 1498 GNUNET_DISK_PERM_USER_READ
1488 GNUNET_DISK_PERM_USER_WRITE); 1499 | GNUNET_DISK_PERM_USER_WRITE);
1489 if (NULL == fh) 1500 if (NULL == fh)
1490 { 1501 {
1491 LOG(GNUNET_ERROR_TYPE_WARNING, 1502 LOG (GNUNET_ERROR_TYPE_WARNING,
1492 "Not able to write valid peers to file `%s'\n", 1503 "Not able to write valid peers to file `%s'\n",
1493 sub->filename_valid_peers); 1504 sub->filename_valid_peers);
1494 return; 1505 return;
1495 } 1506 }
1496 LOG(GNUNET_ERROR_TYPE_DEBUG, 1507 LOG (GNUNET_ERROR_TYPE_DEBUG,
1497 "Writing %u valid peers to disk\n", 1508 "Writing %u valid peers to disk\n",
1498 GNUNET_CONTAINER_multipeermap_size(sub->valid_peers)); 1509 GNUNET_CONTAINER_multipeermap_size (sub->valid_peers));
1499 number_written_peers = 1510 number_written_peers =
1500 GNUNET_CONTAINER_multipeermap_iterate(sub->valid_peers, 1511 GNUNET_CONTAINER_multipeermap_iterate (sub->valid_peers,
1501 store_peer_presistently_iterator, 1512 store_peer_presistently_iterator,
1502 fh); 1513 fh);
1503 GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh)); 1514 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
1504 GNUNET_assert(number_written_peers == 1515 GNUNET_assert (number_written_peers ==
1505 GNUNET_CONTAINER_multipeermap_size(sub->valid_peers)); 1516 GNUNET_CONTAINER_multipeermap_size (sub->valid_peers));
1506} 1517}
1507 1518
1508 1519
@@ -1516,38 +1527,38 @@ store_valid_peers(const struct Sub *sub)
1516 * @return The peer id 1527 * @return The peer id
1517 */ 1528 */
1518static const struct GNUNET_PeerIdentity * 1529static const struct GNUNET_PeerIdentity *
1519s2i_full(const char *string_repr) 1530s2i_full (const char *string_repr)
1520{ 1531{
1521 struct GNUNET_PeerIdentity *peer; 1532 struct GNUNET_PeerIdentity *peer;
1522 size_t len; 1533 size_t len;
1523 int ret; 1534 int ret;
1524 1535
1525 peer = GNUNET_new(struct GNUNET_PeerIdentity); 1536 peer = GNUNET_new (struct GNUNET_PeerIdentity);
1526 len = strlen(string_repr); 1537 len = strlen (string_repr);
1527 if (52 > len) 1538 if (52 > len)
1528 { 1539 {
1529 LOG(GNUNET_ERROR_TYPE_WARNING, 1540 LOG (GNUNET_ERROR_TYPE_WARNING,
1530 "Not able to convert string representation of PeerID to PeerID\n" 1541 "Not able to convert string representation of PeerID to PeerID\n"
1531 "Sting representation: %s (len %lu) - too short\n", 1542 "Sting representation: %s (len %lu) - too short\n",
1532 string_repr, 1543 string_repr,
1533 len); 1544 len);
1534 GNUNET_break(0); 1545 GNUNET_break (0);
1535 } 1546 }
1536 else if (52 < len) 1547 else if (52 < len)
1537 { 1548 {
1538 len = 52; 1549 len = 52;
1539 } 1550 }
1540 ret = GNUNET_CRYPTO_eddsa_public_key_from_string(string_repr, 1551 ret = GNUNET_CRYPTO_eddsa_public_key_from_string (string_repr,
1541 len, 1552 len,
1542 &peer->public_key); 1553 &peer->public_key);
1543 if (GNUNET_OK != ret) 1554 if (GNUNET_OK != ret)
1544 { 1555 {
1545 LOG(GNUNET_ERROR_TYPE_WARNING, 1556 LOG (GNUNET_ERROR_TYPE_WARNING,
1546 "Not able to convert string representation of PeerID to PeerID\n" 1557 "Not able to convert string representation of PeerID to PeerID\n"
1547 "Sting representation: %s\n", 1558 "Sting representation: %s\n",
1548 string_repr); 1559 string_repr);
1549 GNUNET_break(0); 1560 GNUNET_break (0);
1550 } 1561 }
1551 return peer; 1562 return peer;
1552} 1563}
1553 1564
@@ -1558,7 +1569,7 @@ s2i_full(const char *string_repr)
1558 * @param sub Sub for which to restore the valid peers 1569 * @param sub Sub for which to restore the valid peers
1559 */ 1570 */
1560static void 1571static void
1561restore_valid_peers(const struct Sub *sub) 1572restore_valid_peers (const struct Sub *sub)
1562{ 1573{
1563 off_t file_size; 1574 off_t file_size;
1564 uint32_t num_peers; 1575 uint32_t num_peers;
@@ -1569,53 +1580,53 @@ restore_valid_peers(const struct Sub *sub)
1569 char *str_repr; 1580 char *str_repr;
1570 const struct GNUNET_PeerIdentity *peer; 1581 const struct GNUNET_PeerIdentity *peer;
1571 1582
1572 if (0 == strncmp("DISABLE", sub->filename_valid_peers, 7)) 1583 if (0 == strncmp ("DISABLE", sub->filename_valid_peers, 7))
1573 { 1584 {
1574 return; 1585 return;
1575 } 1586 }
1576 1587
1577 if (GNUNET_OK != GNUNET_DISK_file_test(sub->filename_valid_peers)) 1588 if (GNUNET_OK != GNUNET_DISK_file_test (sub->filename_valid_peers))
1578 { 1589 {
1579 return; 1590 return;
1580 } 1591 }
1581 fh = GNUNET_DISK_file_open(sub->filename_valid_peers, 1592 fh = GNUNET_DISK_file_open (sub->filename_valid_peers,
1582 GNUNET_DISK_OPEN_READ, 1593 GNUNET_DISK_OPEN_READ,
1583 GNUNET_DISK_PERM_NONE); 1594 GNUNET_DISK_PERM_NONE);
1584 GNUNET_assert(NULL != fh); 1595 GNUNET_assert (NULL != fh);
1585 GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_handle_size(fh, &file_size)); 1596 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_handle_size (fh, &file_size));
1586 num_peers = file_size / 53; 1597 num_peers = file_size / 53;
1587 buf = GNUNET_malloc(file_size); 1598 buf = GNUNET_malloc (file_size);
1588 size_read = GNUNET_DISK_file_read(fh, buf, file_size); 1599 size_read = GNUNET_DISK_file_read (fh, buf, file_size);
1589 GNUNET_assert(size_read == file_size); 1600 GNUNET_assert (size_read == file_size);
1590 LOG(GNUNET_ERROR_TYPE_DEBUG, 1601 LOG (GNUNET_ERROR_TYPE_DEBUG,
1591 "Restoring %" PRIu32 " peers from file `%s'\n", 1602 "Restoring %" PRIu32 " peers from file `%s'\n",
1592 num_peers, 1603 num_peers,
1593 sub->filename_valid_peers); 1604 sub->filename_valid_peers);
1594 for (iter_buf = buf; iter_buf < buf + file_size - 1; iter_buf += 53) 1605 for (iter_buf = buf; iter_buf < buf + file_size - 1; iter_buf += 53)
1595 { 1606 {
1596 str_repr = GNUNET_strndup(iter_buf, 53); 1607 str_repr = GNUNET_strndup (iter_buf, 53);
1597 peer = s2i_full(str_repr); 1608 peer = s2i_full (str_repr);
1598 GNUNET_free(str_repr); 1609 GNUNET_free (str_repr);
1599 add_valid_peer(peer, sub->valid_peers); 1610 add_valid_peer (peer, sub->valid_peers);
1600 LOG(GNUNET_ERROR_TYPE_DEBUG, 1611 LOG (GNUNET_ERROR_TYPE_DEBUG,
1601 "Restored valid peer %s from disk\n", 1612 "Restored valid peer %s from disk\n",
1602 GNUNET_i2s_full(peer)); 1613 GNUNET_i2s_full (peer));
1603 } 1614 }
1604 iter_buf = NULL; 1615 iter_buf = NULL;
1605 GNUNET_free(buf); 1616 GNUNET_free (buf);
1606 LOG(GNUNET_ERROR_TYPE_DEBUG, 1617 LOG (GNUNET_ERROR_TYPE_DEBUG,
1607 "num_peers: %" PRIu32 ", _size (sub->valid_peers): %u\n", 1618 "num_peers: %" PRIu32 ", _size (sub->valid_peers): %u\n",
1608 num_peers, 1619 num_peers,
1609 GNUNET_CONTAINER_multipeermap_size(sub->valid_peers)); 1620 GNUNET_CONTAINER_multipeermap_size (sub->valid_peers));
1610 if (num_peers != GNUNET_CONTAINER_multipeermap_size(sub->valid_peers)) 1621 if (num_peers != GNUNET_CONTAINER_multipeermap_size (sub->valid_peers))
1611 { 1622 {
1612 LOG(GNUNET_ERROR_TYPE_WARNING, 1623 LOG (GNUNET_ERROR_TYPE_WARNING,
1613 "Number of restored peers does not match file size. Have probably duplicates.\n"); 1624 "Number of restored peers does not match file size. Have probably duplicates.\n");
1614 } 1625 }
1615 GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh)); 1626 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
1616 LOG(GNUNET_ERROR_TYPE_DEBUG, 1627 LOG (GNUNET_ERROR_TYPE_DEBUG,
1617 "Restored %u valid peers from disk\n", 1628 "Restored %u valid peers from disk\n",
1618 GNUNET_CONTAINER_multipeermap_size(sub->valid_peers)); 1629 GNUNET_CONTAINER_multipeermap_size (sub->valid_peers));
1619} 1630}
1620 1631
1621 1632
@@ -1625,22 +1636,22 @@ restore_valid_peers(const struct Sub *sub)
1625 * @param sub Sub for which the storage is deleted 1636 * @param sub Sub for which the storage is deleted
1626 */ 1637 */
1627static void 1638static void
1628peers_terminate(struct Sub *sub) 1639peers_terminate (struct Sub *sub)
1629{ 1640{
1630 if (GNUNET_SYSERR == 1641 if (GNUNET_SYSERR ==
1631 GNUNET_CONTAINER_multipeermap_iterate(sub->peer_map, 1642 GNUNET_CONTAINER_multipeermap_iterate (sub->peer_map,
1632 &peermap_clear_iterator, 1643 &peermap_clear_iterator,
1633 sub)) 1644 sub))
1634 { 1645 {
1635 LOG(GNUNET_ERROR_TYPE_WARNING, 1646 LOG (GNUNET_ERROR_TYPE_WARNING,
1636 "Iteration destroying peers was aborted.\n"); 1647 "Iteration destroying peers was aborted.\n");
1637 } 1648 }
1638 GNUNET_CONTAINER_multipeermap_destroy(sub->peer_map); 1649 GNUNET_CONTAINER_multipeermap_destroy (sub->peer_map);
1639 sub->peer_map = NULL; 1650 sub->peer_map = NULL;
1640 store_valid_peers(sub); 1651 store_valid_peers (sub);
1641 GNUNET_free(sub->filename_valid_peers); 1652 GNUNET_free (sub->filename_valid_peers);
1642 sub->filename_valid_peers = NULL; 1653 sub->filename_valid_peers = NULL;
1643 GNUNET_CONTAINER_multipeermap_destroy(sub->valid_peers); 1654 GNUNET_CONTAINER_multipeermap_destroy (sub->valid_peers);
1644 sub->valid_peers = NULL; 1655 sub->valid_peers = NULL;
1645} 1656}
1646 1657
@@ -1656,15 +1667,15 @@ peers_terminate(struct Sub *sub)
1656 * #GNUNET_NO if not. 1667 * #GNUNET_NO if not.
1657 */ 1668 */
1658static int 1669static int
1659valid_peer_iterator(void *cls, 1670valid_peer_iterator (void *cls,
1660 const struct GNUNET_PeerIdentity *peer, 1671 const struct GNUNET_PeerIdentity *peer,
1661 void *value) 1672 void *value)
1662{ 1673{
1663 struct PeersIteratorCls *it_cls = cls; 1674 struct PeersIteratorCls *it_cls = cls;
1664 1675
1665 (void)value; 1676 (void) value;
1666 1677
1667 return it_cls->iterator(it_cls->cls, peer); 1678 return it_cls->iterator (it_cls->cls, peer);
1668} 1679}
1669 1680
1670 1681
@@ -1678,20 +1689,20 @@ valid_peer_iterator(void *cls,
1678 * #GNUNET_SYSERR if it aborted iteration 1689 * #GNUNET_SYSERR if it aborted iteration
1679 */ 1690 */
1680static int 1691static int
1681get_valid_peers(struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, 1692get_valid_peers (struct GNUNET_CONTAINER_MultiPeerMap *valid_peers,
1682 PeersIterator iterator, 1693 PeersIterator iterator,
1683 void *it_cls) 1694 void *it_cls)
1684{ 1695{
1685 struct PeersIteratorCls *cls; 1696 struct PeersIteratorCls *cls;
1686 int ret; 1697 int ret;
1687 1698
1688 cls = GNUNET_new(struct PeersIteratorCls); 1699 cls = GNUNET_new (struct PeersIteratorCls);
1689 cls->iterator = iterator; 1700 cls->iterator = iterator;
1690 cls->cls = it_cls; 1701 cls->cls = it_cls;
1691 ret = GNUNET_CONTAINER_multipeermap_iterate(valid_peers, 1702 ret = GNUNET_CONTAINER_multipeermap_iterate (valid_peers,
1692 valid_peer_iterator, 1703 valid_peer_iterator,
1693 cls); 1704 cls);
1694 GNUNET_free(cls); 1705 GNUNET_free (cls);
1695 return ret; 1706 return ret;
1696} 1707}
1697 1708
@@ -1709,14 +1720,14 @@ get_valid_peers(struct GNUNET_CONTAINER_MultiPeerMap *valid_peers,
1709 * #GNUNET_NO otherwise 1720 * #GNUNET_NO otherwise
1710 */ 1721 */
1711static int 1722static int
1712insert_peer(struct Sub *sub, 1723insert_peer (struct Sub *sub,
1713 const struct GNUNET_PeerIdentity *peer) 1724 const struct GNUNET_PeerIdentity *peer)
1714{ 1725{
1715 if (GNUNET_YES == check_peer_known(sub->peer_map, peer)) 1726 if (GNUNET_YES == check_peer_known (sub->peer_map, peer))
1716 { 1727 {
1717 return GNUNET_NO; /* We already know this peer - nothing to do */ 1728 return GNUNET_NO; /* We already know this peer - nothing to do */
1718 } 1729 }
1719 (void)create_peer_ctx(sub, peer); 1730 (void) create_peer_ctx (sub, peer);
1720 return GNUNET_YES; 1731 return GNUNET_YES;
1721} 1732}
1722 1733
@@ -1733,18 +1744,18 @@ insert_peer(struct Sub *sub,
1733 * #GNUNET_NO otherwise 1744 * #GNUNET_NO otherwise
1734 */ 1745 */
1735static int 1746static int
1736check_peer_flag(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map, 1747check_peer_flag (const struct GNUNET_CONTAINER_MultiPeerMap *peer_map,
1737 const struct GNUNET_PeerIdentity *peer, 1748 const struct GNUNET_PeerIdentity *peer,
1738 enum Peers_PeerFlags flags) 1749 enum Peers_PeerFlags flags)
1739{ 1750{
1740 struct PeerContext *peer_ctx; 1751 struct PeerContext *peer_ctx;
1741 1752
1742 if (GNUNET_NO == check_peer_known(peer_map, peer)) 1753 if (GNUNET_NO == check_peer_known (peer_map, peer))
1743 { 1754 {
1744 return GNUNET_SYSERR; 1755 return GNUNET_SYSERR;
1745 } 1756 }
1746 peer_ctx = get_peer_ctx(peer_map, peer); 1757 peer_ctx = get_peer_ctx (peer_map, peer);
1747 return check_peer_flag_set(peer_ctx, flags); 1758 return check_peer_flag_set (peer_ctx, flags);
1748} 1759}
1749 1760
1750/** 1761/**
@@ -1758,19 +1769,19 @@ check_peer_flag(const struct GNUNET_CONTAINER_MultiPeerMap *peer_map,
1758 * #GNUNET_NO otherwise 1769 * #GNUNET_NO otherwise
1759 */ 1770 */
1760static int 1771static int
1761issue_peer_online_check(struct Sub *sub, 1772issue_peer_online_check (struct Sub *sub,
1762 const struct GNUNET_PeerIdentity *peer) 1773 const struct GNUNET_PeerIdentity *peer)
1763{ 1774{
1764 struct PeerContext *peer_ctx; 1775 struct PeerContext *peer_ctx;
1765 1776
1766 (void)insert_peer(sub, peer); // TODO even needed? 1777 (void) insert_peer (sub, peer); // TODO even needed?
1767 peer_ctx = get_peer_ctx(sub->peer_map, peer); 1778 peer_ctx = get_peer_ctx (sub->peer_map, peer);
1768 if ((GNUNET_NO == check_peer_flag(sub->peer_map, peer, Peers_ONLINE)) && 1779 if ((GNUNET_NO == check_peer_flag (sub->peer_map, peer, Peers_ONLINE)) &&
1769 (NULL == peer_ctx->online_check_pending)) 1780 (NULL == peer_ctx->online_check_pending))
1770 { 1781 {
1771 check_peer_online(peer_ctx); 1782 check_peer_online (peer_ctx);
1772 return GNUNET_YES; 1783 return GNUNET_YES;
1773 } 1784 }
1774 return GNUNET_NO; 1785 return GNUNET_NO;
1775} 1786}
1776 1787
@@ -1789,20 +1800,21 @@ issue_peer_online_check(struct Sub *sub,
1789 * #GNUNET_SYSERR if peer is not known 1800 * #GNUNET_SYSERR if peer is not known
1790 */ 1801 */
1791static int 1802static int
1792check_removable(const struct PeerContext *peer_ctx) 1803check_removable (const struct PeerContext *peer_ctx)
1793{ 1804{
1794 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(peer_ctx->sub->peer_map, 1805 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (
1795 &peer_ctx->peer_id)) 1806 peer_ctx->sub->peer_map,
1796 { 1807 &peer_ctx->peer_id))
1797 return GNUNET_SYSERR; 1808 {
1798 } 1809 return GNUNET_SYSERR;
1810 }
1799 1811
1800 if ((NULL != peer_ctx->recv_channel_ctx) || 1812 if ((NULL != peer_ctx->recv_channel_ctx) ||
1801 (NULL != peer_ctx->pending_messages_head) || 1813 (NULL != peer_ctx->pending_messages_head) ||
1802 (GNUNET_YES == check_peer_flag_set(peer_ctx, Peers_PULL_REPLY_PENDING))) 1814 (GNUNET_YES == check_peer_flag_set (peer_ctx, Peers_PULL_REPLY_PENDING)))
1803 { 1815 {
1804 return GNUNET_NO; 1816 return GNUNET_NO;
1805 } 1817 }
1806 return GNUNET_YES; 1818 return GNUNET_YES;
1807} 1819}
1808 1820
@@ -1819,10 +1831,10 @@ check_removable(const struct PeerContext *peer_ctx)
1819 * #GNUNET_NO if peer is not valid 1831 * #GNUNET_NO if peer is not valid
1820 */ 1832 */
1821static int 1833static int
1822check_peer_valid(const struct GNUNET_CONTAINER_MultiPeerMap *valid_peers, 1834check_peer_valid (const struct GNUNET_CONTAINER_MultiPeerMap *valid_peers,
1823 const struct GNUNET_PeerIdentity *peer) 1835 const struct GNUNET_PeerIdentity *peer)
1824{ 1836{
1825 return GNUNET_CONTAINER_multipeermap_contains(valid_peers, peer); 1837 return GNUNET_CONTAINER_multipeermap_contains (valid_peers, peer);
1826} 1838}
1827 1839
1828 1840
@@ -1834,11 +1846,11 @@ check_peer_valid(const struct GNUNET_CONTAINER_MultiPeerMap *valid_peers,
1834 * @param peer_ctx Context of the target peer 1846 * @param peer_ctx Context of the target peer
1835 */ 1847 */
1836static void 1848static void
1837indicate_sending_intention(struct PeerContext *peer_ctx) 1849indicate_sending_intention (struct PeerContext *peer_ctx)
1838{ 1850{
1839 GNUNET_assert(GNUNET_YES == check_peer_known(peer_ctx->sub->peer_map, 1851 GNUNET_assert (GNUNET_YES == check_peer_known (peer_ctx->sub->peer_map,
1840 &peer_ctx->peer_id)); 1852 &peer_ctx->peer_id));
1841 (void)get_channel(peer_ctx); 1853 (void) get_channel (peer_ctx);
1842} 1854}
1843 1855
1844 1856
@@ -1852,12 +1864,12 @@ indicate_sending_intention(struct PeerContext *peer_ctx)
1852 * #GNUNET_NO otherwise 1864 * #GNUNET_NO otherwise
1853 */ 1865 */
1854static int 1866static int
1855check_peer_send_intention(const struct PeerContext *peer_ctx) 1867check_peer_send_intention (const struct PeerContext *peer_ctx)
1856{ 1868{
1857 if (NULL != peer_ctx->recv_channel_ctx) 1869 if (NULL != peer_ctx->recv_channel_ctx)
1858 { 1870 {
1859 return GNUNET_YES; 1871 return GNUNET_YES;
1860 } 1872 }
1861 return GNUNET_NO; 1873 return GNUNET_NO;
1862} 1874}
1863 1875
@@ -1873,36 +1885,36 @@ check_peer_send_intention(const struct PeerContext *peer_ctx)
1873 * (can be NULL -- that's not an error) 1885 * (can be NULL -- that's not an error)
1874 */ 1886 */
1875static void * 1887static void *
1876handle_inbound_channel(void *cls, 1888handle_inbound_channel (void *cls,
1877 struct GNUNET_CADET_Channel *channel, 1889 struct GNUNET_CADET_Channel *channel,
1878 const struct GNUNET_PeerIdentity *initiator) 1890 const struct GNUNET_PeerIdentity *initiator)
1879{ 1891{
1880 struct PeerContext *peer_ctx; 1892 struct PeerContext *peer_ctx;
1881 struct ChannelCtx *channel_ctx; 1893 struct ChannelCtx *channel_ctx;
1882 struct Sub *sub = cls; 1894 struct Sub *sub = cls;
1883 1895
1884 LOG(GNUNET_ERROR_TYPE_DEBUG, 1896 LOG (GNUNET_ERROR_TYPE_DEBUG,
1885 "New channel was established to us (Peer %s).\n", 1897 "New channel was established to us (Peer %s).\n",
1886 GNUNET_i2s(initiator)); 1898 GNUNET_i2s (initiator));
1887 GNUNET_assert(NULL != channel); /* according to cadet API */ 1899 GNUNET_assert (NULL != channel); /* according to cadet API */
1888 /* Make sure we 'know' about this peer */ 1900 /* Make sure we 'know' about this peer */
1889 peer_ctx = create_or_get_peer_ctx(sub, initiator); 1901 peer_ctx = create_or_get_peer_ctx (sub, initiator);
1890 set_peer_online(peer_ctx); 1902 set_peer_online (peer_ctx);
1891 (void)add_valid_peer(&peer_ctx->peer_id, peer_ctx->sub->valid_peers); 1903 (void) add_valid_peer (&peer_ctx->peer_id, peer_ctx->sub->valid_peers);
1892 channel_ctx = add_channel_ctx(peer_ctx); 1904 channel_ctx = add_channel_ctx (peer_ctx);
1893 channel_ctx->channel = channel; 1905 channel_ctx->channel = channel;
1894 /* We only accept one incoming channel per peer */ 1906 /* We only accept one incoming channel per peer */
1895 if (GNUNET_YES == check_peer_send_intention(get_peer_ctx(sub->peer_map, 1907 if (GNUNET_YES == check_peer_send_intention (get_peer_ctx (sub->peer_map,
1896 initiator))) 1908 initiator)))
1897 { 1909 {
1898 LOG(GNUNET_ERROR_TYPE_WARNING, 1910 LOG (GNUNET_ERROR_TYPE_WARNING,
1899 "Already got one receive channel. Destroying old one.\n"); 1911 "Already got one receive channel. Destroying old one.\n");
1900 GNUNET_break_op(0); 1912 GNUNET_break_op (0);
1901 destroy_channel(peer_ctx->recv_channel_ctx); 1913 destroy_channel (peer_ctx->recv_channel_ctx);
1902 peer_ctx->recv_channel_ctx = channel_ctx; 1914 peer_ctx->recv_channel_ctx = channel_ctx;
1903 /* return the channel context */ 1915 /* return the channel context */
1904 return channel_ctx; 1916 return channel_ctx;
1905 } 1917 }
1906 peer_ctx->recv_channel_ctx = channel_ctx; 1918 peer_ctx->recv_channel_ctx = channel_ctx;
1907 return channel_ctx; 1919 return channel_ctx;
1908} 1920}
@@ -1917,17 +1929,17 @@ handle_inbound_channel(void *cls,
1917 * #GNUNET_NO otherwise 1929 * #GNUNET_NO otherwise
1918 */ 1930 */
1919static int 1931static int
1920check_sending_channel_exists(const struct PeerContext *peer_ctx) 1932check_sending_channel_exists (const struct PeerContext *peer_ctx)
1921{ 1933{
1922 if (GNUNET_NO == check_peer_known(peer_ctx->sub->peer_map, 1934 if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map,
1923 &peer_ctx->peer_id)) 1935 &peer_ctx->peer_id))
1924 { /* If no such peer exists, there is no channel */ 1936 { /* If no such peer exists, there is no channel */
1925 return GNUNET_NO; 1937 return GNUNET_NO;
1926 } 1938 }
1927 if (NULL == peer_ctx->send_channel_ctx) 1939 if (NULL == peer_ctx->send_channel_ctx)
1928 { 1940 {
1929 return GNUNET_NO; 1941 return GNUNET_NO;
1930 } 1942 }
1931 return GNUNET_YES; 1943 return GNUNET_YES;
1932} 1944}
1933 1945
@@ -1941,19 +1953,19 @@ check_sending_channel_exists(const struct PeerContext *peer_ctx)
1941 * #GNUNET_NO otherwise 1953 * #GNUNET_NO otherwise
1942 */ 1954 */
1943static int 1955static int
1944destroy_sending_channel(struct PeerContext *peer_ctx) 1956destroy_sending_channel (struct PeerContext *peer_ctx)
1945{ 1957{
1946 if (GNUNET_NO == check_peer_known(peer_ctx->sub->peer_map, 1958 if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map,
1947 &peer_ctx->peer_id)) 1959 &peer_ctx->peer_id))
1948 { 1960 {
1949 return GNUNET_NO; 1961 return GNUNET_NO;
1950 } 1962 }
1951 if (NULL != peer_ctx->send_channel_ctx) 1963 if (NULL != peer_ctx->send_channel_ctx)
1952 { 1964 {
1953 destroy_channel(peer_ctx->send_channel_ctx); 1965 destroy_channel (peer_ctx->send_channel_ctx);
1954 (void)check_connected(peer_ctx); 1966 (void) check_connected (peer_ctx);
1955 return GNUNET_YES; 1967 return GNUNET_YES;
1956 } 1968 }
1957 return GNUNET_NO; 1969 return GNUNET_NO;
1958} 1970}
1959 1971
@@ -1968,23 +1980,23 @@ destroy_sending_channel(struct PeerContext *peer_ctx)
1968 * @param type type of the message 1980 * @param type type of the message
1969 */ 1981 */
1970static void 1982static void
1971send_message(struct PeerContext *peer_ctx, 1983send_message (struct PeerContext *peer_ctx,
1972 struct GNUNET_MQ_Envelope *ev, 1984 struct GNUNET_MQ_Envelope *ev,
1973 const char *type) 1985 const char *type)
1974{ 1986{
1975 struct PendingMessage *pending_msg; 1987 struct PendingMessage *pending_msg;
1976 struct GNUNET_MQ_Handle *mq; 1988 struct GNUNET_MQ_Handle *mq;
1977 1989
1978 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1990 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1979 "Sending message to %s of type %s\n", 1991 "Sending message to %s of type %s\n",
1980 GNUNET_i2s(&peer_ctx->peer_id), 1992 GNUNET_i2s (&peer_ctx->peer_id),
1981 type); 1993 type);
1982 pending_msg = insert_pending_message(peer_ctx, ev, type); 1994 pending_msg = insert_pending_message (peer_ctx, ev, type);
1983 mq = get_mq(peer_ctx); 1995 mq = get_mq (peer_ctx);
1984 GNUNET_MQ_notify_sent(ev, 1996 GNUNET_MQ_notify_sent (ev,
1985 mq_notify_sent_cb, 1997 mq_notify_sent_cb,
1986 pending_msg); 1998 pending_msg);
1987 GNUNET_MQ_send(mq, ev); 1999 GNUNET_MQ_send (mq, ev);
1988} 2000}
1989 2001
1990/** 2002/**
@@ -2000,26 +2012,26 @@ send_message(struct PeerContext *peer_ctx,
2000 * #GNUNET_NO otherwise 2012 * #GNUNET_NO otherwise
2001 */ 2013 */
2002static int 2014static int
2003schedule_operation(struct PeerContext *peer_ctx, 2015schedule_operation (struct PeerContext *peer_ctx,
2004 const PeerOp peer_op, 2016 const PeerOp peer_op,
2005 void *cls) 2017 void *cls)
2006{ 2018{
2007 struct PeerPendingOp pending_op; 2019 struct PeerPendingOp pending_op;
2008 2020
2009 GNUNET_assert(GNUNET_YES == check_peer_known(peer_ctx->sub->peer_map, 2021 GNUNET_assert (GNUNET_YES == check_peer_known (peer_ctx->sub->peer_map,
2010 &peer_ctx->peer_id)); 2022 &peer_ctx->peer_id));
2011 2023
2012 //TODO if ONLINE execute immediately 2024 // TODO if ONLINE execute immediately
2013 2025
2014 if (GNUNET_NO == check_operation_scheduled(peer_ctx, peer_op)) 2026 if (GNUNET_NO == check_operation_scheduled (peer_ctx, peer_op))
2015 { 2027 {
2016 pending_op.op = peer_op; 2028 pending_op.op = peer_op;
2017 pending_op.op_cls = cls; 2029 pending_op.op_cls = cls;
2018 GNUNET_array_append(peer_ctx->pending_ops, 2030 GNUNET_array_append (peer_ctx->pending_ops,
2019 peer_ctx->num_pending_ops, 2031 peer_ctx->num_pending_ops,
2020 pending_op); 2032 pending_op);
2021 return GNUNET_YES; 2033 return GNUNET_YES;
2022 } 2034 }
2023 return GNUNET_NO; 2035 return GNUNET_NO;
2024} 2036}
2025 2037
@@ -2036,7 +2048,8 @@ schedule_operation(struct PeerContext *peer_ctx,
2036 * Closure used to pass the client and the id to the callback 2048 * Closure used to pass the client and the id to the callback
2037 * that replies to a client's request 2049 * that replies to a client's request
2038 */ 2050 */
2039struct ReplyCls { 2051struct ReplyCls
2052{
2040 /** 2053 /**
2041 * DLL 2054 * DLL
2042 */ 2055 */
@@ -2063,7 +2076,8 @@ struct ReplyCls {
2063/** 2076/**
2064 * Struct used to store the context of a connected client. 2077 * Struct used to store the context of a connected client.
2065 */ 2078 */
2066struct ClientContext { 2079struct ClientContext
2080{
2067 /** 2081 /**
2068 * DLL 2082 * DLL
2069 */ 2083 */
@@ -2120,21 +2134,21 @@ struct ClientContext *cli_ctx_tail;
2120 * Print peerlist to log. 2134 * Print peerlist to log.
2121 */ 2135 */
2122static void 2136static void
2123print_peer_list(struct GNUNET_PeerIdentity *list, 2137print_peer_list (struct GNUNET_PeerIdentity *list,
2124 unsigned int len) 2138 unsigned int len)
2125{ 2139{
2126 unsigned int i; 2140 unsigned int i;
2127 2141
2128 LOG(GNUNET_ERROR_TYPE_DEBUG, 2142 LOG (GNUNET_ERROR_TYPE_DEBUG,
2129 "Printing peer list of length %u at %p:\n", 2143 "Printing peer list of length %u at %p:\n",
2130 len, 2144 len,
2131 list); 2145 list);
2132 for (i = 0; i < len; i++) 2146 for (i = 0; i < len; i++)
2133 { 2147 {
2134 LOG(GNUNET_ERROR_TYPE_DEBUG, 2148 LOG (GNUNET_ERROR_TYPE_DEBUG,
2135 "%u. peer: %s\n", 2149 "%u. peer: %s\n",
2136 i, GNUNET_i2s(&list[i])); 2150 i, GNUNET_i2s (&list[i]));
2137 } 2151 }
2138} 2152}
2139 2153
2140 2154
@@ -2142,33 +2156,33 @@ print_peer_list(struct GNUNET_PeerIdentity *list,
2142 * Remove peer from list. 2156 * Remove peer from list.
2143 */ 2157 */
2144static void 2158static void
2145rem_from_list(struct GNUNET_PeerIdentity **peer_list, 2159rem_from_list (struct GNUNET_PeerIdentity **peer_list,
2146 unsigned int *list_size, 2160 unsigned int *list_size,
2147 const struct GNUNET_PeerIdentity *peer) 2161 const struct GNUNET_PeerIdentity *peer)
2148{ 2162{
2149 unsigned int i; 2163 unsigned int i;
2150 struct GNUNET_PeerIdentity *tmp; 2164 struct GNUNET_PeerIdentity *tmp;
2151 2165
2152 tmp = *peer_list; 2166 tmp = *peer_list;
2153 2167
2154 LOG(GNUNET_ERROR_TYPE_DEBUG, 2168 LOG (GNUNET_ERROR_TYPE_DEBUG,
2155 "Removing peer %s from list at %p\n", 2169 "Removing peer %s from list at %p\n",
2156 GNUNET_i2s(peer), 2170 GNUNET_i2s (peer),
2157 tmp); 2171 tmp);
2158 2172
2159 for (i = 0; i < *list_size; i++) 2173 for (i = 0; i < *list_size; i++)
2174 {
2175 if (0 == GNUNET_memcmp (&tmp[i], peer))
2160 { 2176 {
2161 if (0 == GNUNET_memcmp(&tmp[i], peer)) 2177 if (i < *list_size - 1)
2162 { 2178 { /* Not at the last entry -- shift peers left */
2163 if (i < *list_size - 1) 2179 memmove (&tmp[i], &tmp[i + 1],
2164 { /* Not at the last entry -- shift peers left */ 2180 ((*list_size) - i - 1) * sizeof(struct GNUNET_PeerIdentity));
2165 memmove(&tmp[i], &tmp[i + 1], 2181 }
2166 ((*list_size) - i - 1) * sizeof(struct GNUNET_PeerIdentity)); 2182 /* Remove last entry (should be now useless PeerID) */
2167 } 2183 GNUNET_array_grow (tmp, *list_size, (*list_size) - 1);
2168 /* Remove last entry (should be now useless PeerID) */ 2184 }
2169 GNUNET_array_grow(tmp, *list_size, (*list_size) - 1); 2185 }
2170 }
2171 }
2172 *peer_list = tmp; 2186 *peer_list = tmp;
2173} 2187}
2174 2188
@@ -2183,8 +2197,8 @@ rem_from_list(struct GNUNET_PeerIdentity **peer_list,
2183 * GNUNET_NO if peer was not inserted 2197 * GNUNET_NO if peer was not inserted
2184 */ 2198 */
2185static void 2199static void
2186insert_in_view_op(void *cls, 2200insert_in_view_op (void *cls,
2187 const struct GNUNET_PeerIdentity *peer); 2201 const struct GNUNET_PeerIdentity *peer);
2188 2202
2189/** 2203/**
2190 * Insert PeerID in #view 2204 * Insert PeerID in #view
@@ -2198,32 +2212,32 @@ insert_in_view_op(void *cls,
2198 * GNUNET_NO if peer was not inserted 2212 * GNUNET_NO if peer was not inserted
2199 */ 2213 */
2200static int 2214static int
2201insert_in_view(struct Sub *sub, 2215insert_in_view (struct Sub *sub,
2202 const struct GNUNET_PeerIdentity *peer) 2216 const struct GNUNET_PeerIdentity *peer)
2203{ 2217{
2204 struct PeerContext *peer_ctx; 2218 struct PeerContext *peer_ctx;
2205 int online; 2219 int online;
2206 int ret; 2220 int ret;
2207 2221
2208 online = check_peer_flag(sub->peer_map, peer, Peers_ONLINE); 2222 online = check_peer_flag (sub->peer_map, peer, Peers_ONLINE);
2209 peer_ctx = get_peer_ctx(sub->peer_map, peer); // TODO indirection needed? 2223 peer_ctx = get_peer_ctx (sub->peer_map, peer); // TODO indirection needed?
2210 if ((GNUNET_NO == online) || 2224 if ((GNUNET_NO == online) ||
2211 (GNUNET_SYSERR == online)) /* peer is not even known */ 2225 (GNUNET_SYSERR == online)) /* peer is not even known */
2212 { 2226 {
2213 (void)issue_peer_online_check(sub, peer); 2227 (void) issue_peer_online_check (sub, peer);
2214 (void)schedule_operation(peer_ctx, insert_in_view_op, sub); 2228 (void) schedule_operation (peer_ctx, insert_in_view_op, sub);
2215 return GNUNET_NO; 2229 return GNUNET_NO;
2216 } 2230 }
2217 /* Open channel towards peer to keep connection open */ 2231 /* Open channel towards peer to keep connection open */
2218 indicate_sending_intention(peer_ctx); 2232 indicate_sending_intention (peer_ctx);
2219 ret = View_put(sub->view, peer); 2233 ret = View_put (sub->view, peer);
2220 if (peer_ctx->sub == msub) 2234 if (peer_ctx->sub == msub)
2221 { 2235 {
2222 GNUNET_STATISTICS_set(stats, 2236 GNUNET_STATISTICS_set (stats,
2223 "view size", 2237 "view size",
2224 View_size(peer_ctx->sub->view), 2238 View_size (peer_ctx->sub->view),
2225 GNUNET_NO); 2239 GNUNET_NO);
2226 } 2240 }
2227 return ret; 2241 return ret;
2228} 2242}
2229 2243
@@ -2236,33 +2250,33 @@ insert_in_view(struct Sub *sub,
2236 * @param view_size the size of the view array (can be 0) 2250 * @param view_size the size of the view array (can be 0)
2237 */ 2251 */
2238static void 2252static void
2239send_view(const struct ClientContext *cli_ctx, 2253send_view (const struct ClientContext *cli_ctx,
2240 const struct GNUNET_PeerIdentity *view_array, 2254 const struct GNUNET_PeerIdentity *view_array,
2241 uint64_t view_size) 2255 uint64_t view_size)
2242{ 2256{
2243 struct GNUNET_MQ_Envelope *ev; 2257 struct GNUNET_MQ_Envelope *ev;
2244 struct GNUNET_RPS_CS_DEBUG_ViewReply *out_msg; 2258 struct GNUNET_RPS_CS_DEBUG_ViewReply *out_msg;
2245 struct Sub *sub; 2259 struct Sub *sub;
2246 2260
2247 if (NULL == view_array) 2261 if (NULL == view_array)
2248 { 2262 {
2249 if (NULL == cli_ctx->sub) 2263 if (NULL == cli_ctx->sub)
2250 sub = msub; 2264 sub = msub;
2251 else 2265 else
2252 sub = cli_ctx->sub; 2266 sub = cli_ctx->sub;
2253 view_size = View_size(sub->view); 2267 view_size = View_size (sub->view);
2254 view_array = View_get_as_array(sub->view); 2268 view_array = View_get_as_array (sub->view);
2255 } 2269 }
2256 2270
2257 ev = GNUNET_MQ_msg_extra(out_msg, 2271 ev = GNUNET_MQ_msg_extra (out_msg,
2258 view_size * sizeof(struct GNUNET_PeerIdentity), 2272 view_size * sizeof(struct GNUNET_PeerIdentity),
2259 GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY); 2273 GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY);
2260 out_msg->num_peers = htonl(view_size); 2274 out_msg->num_peers = htonl (view_size);
2261 2275
2262 GNUNET_memcpy(&out_msg[1], 2276 GNUNET_memcpy (&out_msg[1],
2263 view_array, 2277 view_array,
2264 view_size * sizeof(struct GNUNET_PeerIdentity)); 2278 view_size * sizeof(struct GNUNET_PeerIdentity));
2265 GNUNET_MQ_send(cli_ctx->mq, ev); 2279 GNUNET_MQ_send (cli_ctx->mq, ev);
2266} 2280}
2267 2281
2268 2282
@@ -2276,24 +2290,24 @@ send_view(const struct ClientContext *cli_ctx,
2276 * @param view_size the size of the view array (can be 0) 2290 * @param view_size the size of the view array (can be 0)
2277 */ 2291 */
2278static void 2292static void
2279send_stream_peers(const struct ClientContext *cli_ctx, 2293send_stream_peers (const struct ClientContext *cli_ctx,
2280 uint64_t num_peers, 2294 uint64_t num_peers,
2281 const struct GNUNET_PeerIdentity *peers) 2295 const struct GNUNET_PeerIdentity *peers)
2282{ 2296{
2283 struct GNUNET_MQ_Envelope *ev; 2297 struct GNUNET_MQ_Envelope *ev;
2284 struct GNUNET_RPS_CS_DEBUG_StreamReply *out_msg; 2298 struct GNUNET_RPS_CS_DEBUG_StreamReply *out_msg;
2285 2299
2286 GNUNET_assert(NULL != peers); 2300 GNUNET_assert (NULL != peers);
2287 2301
2288 ev = GNUNET_MQ_msg_extra(out_msg, 2302 ev = GNUNET_MQ_msg_extra (out_msg,
2289 num_peers * sizeof(struct GNUNET_PeerIdentity), 2303 num_peers * sizeof(struct GNUNET_PeerIdentity),
2290 GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY); 2304 GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY);
2291 out_msg->num_peers = htonl(num_peers); 2305 out_msg->num_peers = htonl (num_peers);
2292 2306
2293 GNUNET_memcpy(&out_msg[1], 2307 GNUNET_memcpy (&out_msg[1],
2294 peers, 2308 peers,
2295 num_peers * sizeof(struct GNUNET_PeerIdentity)); 2309 num_peers * sizeof(struct GNUNET_PeerIdentity));
2296 GNUNET_MQ_send(cli_ctx->mq, ev); 2310 GNUNET_MQ_send (cli_ctx->mq, ev);
2297} 2311}
2298 2312
2299 2313
@@ -2303,46 +2317,46 @@ send_stream_peers(const struct ClientContext *cli_ctx,
2303 * @param sub Sub for which to notify clients 2317 * @param sub Sub for which to notify clients
2304 */ 2318 */
2305static void 2319static void
2306clients_notify_view_update(const struct Sub *sub) 2320clients_notify_view_update (const struct Sub *sub)
2307{ 2321{
2308 struct ClientContext *cli_ctx_iter; 2322 struct ClientContext *cli_ctx_iter;
2309 uint64_t num_peers; 2323 uint64_t num_peers;
2310 const struct GNUNET_PeerIdentity *view_array; 2324 const struct GNUNET_PeerIdentity *view_array;
2311 2325
2312 num_peers = View_size(sub->view); 2326 num_peers = View_size (sub->view);
2313 view_array = View_get_as_array(sub->view); 2327 view_array = View_get_as_array (sub->view);
2314 /* check size of view is small enough */ 2328 /* check size of view is small enough */
2315 if (GNUNET_MAX_MESSAGE_SIZE < num_peers) 2329 if (GNUNET_MAX_MESSAGE_SIZE < num_peers)
2316 { 2330 {
2317 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2331 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2318 "View is too big to send\n"); 2332 "View is too big to send\n");
2319 return; 2333 return;
2320 } 2334 }
2321 2335
2322 for (cli_ctx_iter = cli_ctx_head; 2336 for (cli_ctx_iter = cli_ctx_head;
2323 NULL != cli_ctx_iter; 2337 NULL != cli_ctx_iter;
2324 cli_ctx_iter = cli_ctx_iter->next) 2338 cli_ctx_iter = cli_ctx_iter->next)
2339 {
2340 if (1 < cli_ctx_iter->view_updates_left)
2325 { 2341 {
2326 if (1 < cli_ctx_iter->view_updates_left) 2342 /* Client wants to receive limited amount of updates */
2327 { 2343 cli_ctx_iter->view_updates_left -= 1;
2328 /* Client wants to receive limited amount of updates */
2329 cli_ctx_iter->view_updates_left -= 1;
2330 }
2331 else if (1 == cli_ctx_iter->view_updates_left)
2332 {
2333 /* Last update of view for client */
2334 cli_ctx_iter->view_updates_left = -1;
2335 }
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 */
2342
2343 /* send view */
2344 send_view(cli_ctx_iter, view_array, num_peers);
2345 } 2344 }
2345 else if (1 == cli_ctx_iter->view_updates_left)
2346 {
2347 /* Last update of view for client */
2348 cli_ctx_iter->view_updates_left = -1;
2349 }
2350 else if (0 > cli_ctx_iter->view_updates_left)
2351 {
2352 /* Client is not interested in updates */
2353 continue;
2354 }
2355 /* else _updates_left == 0 - infinite amount of updates */
2356
2357 /* send view */
2358 send_view (cli_ctx_iter, view_array, num_peers);
2359 }
2346} 2360}
2347 2361
2348 2362
@@ -2353,27 +2367,27 @@ clients_notify_view_update(const struct Sub *sub)
2353 * @param peers the array of peers to send 2367 * @param peers the array of peers to send
2354 */ 2368 */
2355static void 2369static void
2356clients_notify_stream_peer(const struct Sub *sub, 2370clients_notify_stream_peer (const struct Sub *sub,
2357 uint64_t num_peers, 2371 uint64_t num_peers,
2358 const struct GNUNET_PeerIdentity *peers) 2372 const struct GNUNET_PeerIdentity *peers)
2359// TODO enum StreamPeerSource) 2373// TODO enum StreamPeerSource)
2360{ 2374{
2361 struct ClientContext *cli_ctx_iter; 2375 struct ClientContext *cli_ctx_iter;
2362 2376
2363 LOG(GNUNET_ERROR_TYPE_DEBUG, 2377 LOG (GNUNET_ERROR_TYPE_DEBUG,
2364 "Got peer (%s) from biased stream - update all clients\n", 2378 "Got peer (%s) from biased stream - update all clients\n",
2365 GNUNET_i2s(peers)); 2379 GNUNET_i2s (peers));
2366 2380
2367 for (cli_ctx_iter = cli_ctx_head; 2381 for (cli_ctx_iter = cli_ctx_head;
2368 NULL != cli_ctx_iter; 2382 NULL != cli_ctx_iter;
2369 cli_ctx_iter = cli_ctx_iter->next) 2383 cli_ctx_iter = cli_ctx_iter->next)
2384 {
2385 if ((GNUNET_YES == cli_ctx_iter->stream_update) &&
2386 ((sub == cli_ctx_iter->sub) ||(sub == msub) ))
2370 { 2387 {
2371 if (GNUNET_YES == cli_ctx_iter->stream_update && 2388 send_stream_peers (cli_ctx_iter, num_peers, peers);
2372 (sub == cli_ctx_iter->sub || sub == msub))
2373 {
2374 send_stream_peers(cli_ctx_iter, num_peers, peers);
2375 }
2376 } 2389 }
2390 }
2377} 2391}
2378 2392
2379 2393
@@ -2385,34 +2399,34 @@ clients_notify_stream_peer(const struct Sub *sub,
2385 * @param cls Closure - The Sub for which this is to be done 2399 * @param cls Closure - The Sub for which this is to be done
2386 */ 2400 */
2387static void 2401static void
2388hist_update(const struct GNUNET_PeerIdentity *ids, 2402hist_update (const struct GNUNET_PeerIdentity *ids,
2389 uint32_t num_peers, 2403 uint32_t num_peers,
2390 void *cls) 2404 void *cls)
2391{ 2405{
2392 unsigned int i; 2406 unsigned int i;
2393 struct Sub *sub = cls; 2407 struct Sub *sub = cls;
2394 2408
2395 for (i = 0; i < num_peers; i++) 2409 for (i = 0; i < num_peers; i++)
2410 {
2411 int inserted;
2412 if (GNUNET_YES != check_peer_known (sub->peer_map, &ids[i]))
2396 { 2413 {
2397 int inserted; 2414 LOG (GNUNET_ERROR_TYPE_WARNING,
2398 if (GNUNET_YES != check_peer_known(sub->peer_map, &ids[i])) 2415 "Peer in history update not known!\n");
2399 { 2416 continue;
2400 LOG(GNUNET_ERROR_TYPE_WARNING, 2417 }
2401 "Peer in history update not known!\n"); 2418 inserted = insert_in_view (sub, &ids[i]);
2402 continue; 2419 if (GNUNET_OK == inserted)
2403 } 2420 {
2404 inserted = insert_in_view(sub, &ids[i]); 2421 clients_notify_stream_peer (sub, 1, &ids[i]);
2405 if (GNUNET_OK == inserted) 2422 }
2406 {
2407 clients_notify_stream_peer(sub, 1, &ids[i]);
2408 }
2409#ifdef TO_FILE_FULL 2423#ifdef TO_FILE_FULL
2410 to_file(sub->file_name_view_log, 2424 to_file (sub->file_name_view_log,
2411 "+%s\t(hist)", 2425 "+%s\t(hist)",
2412 GNUNET_i2s_full(ids)); 2426 GNUNET_i2s_full (ids));
2413#endif /* TO_FILE_FULL */ 2427#endif /* TO_FILE_FULL */
2414 } 2428 }
2415 clients_notify_view_update(sub); 2429 clients_notify_view_update (sub);
2416} 2430}
2417 2431
2418 2432
@@ -2426,22 +2440,22 @@ hist_update(const struct GNUNET_PeerIdentity *ids,
2426 * @param new_size New size to which to resize 2440 * @param new_size New size to which to resize
2427 */ 2441 */
2428static void 2442static void
2429resize_wrapper(struct RPS_Sampler *sampler, uint32_t new_size) 2443resize_wrapper (struct RPS_Sampler *sampler, uint32_t new_size)
2430{ 2444{
2431 unsigned int sampler_size; 2445 unsigned int sampler_size;
2432 2446
2433 // TODO statistics 2447 // TODO statistics
2434 // TODO respect the min, max 2448 // TODO respect the min, max
2435 sampler_size = RPS_sampler_get_size(sampler); 2449 sampler_size = RPS_sampler_get_size (sampler);
2436 if (sampler_size > new_size * 4) 2450 if (sampler_size > new_size * 4)
2437 { /* Shrinking */ 2451 { /* Shrinking */
2438 RPS_sampler_resize(sampler, sampler_size / 2); 2452 RPS_sampler_resize (sampler, sampler_size / 2);
2439 } 2453 }
2440 else if (sampler_size < new_size) 2454 else if (sampler_size < new_size)
2441 { /* Growing */ 2455 { /* Growing */
2442 RPS_sampler_resize(sampler, sampler_size * 2); 2456 RPS_sampler_resize (sampler, sampler_size * 2);
2443 } 2457 }
2444 LOG(GNUNET_ERROR_TYPE_DEBUG, "sampler_size is now %u\n", sampler_size); 2458 LOG (GNUNET_ERROR_TYPE_DEBUG, "sampler_size is now %u\n", sampler_size);
2445} 2459}
2446 2460
2447 2461
@@ -2453,33 +2467,33 @@ resize_wrapper(struct RPS_Sampler *sampler, uint32_t new_size)
2453 * @param peer_map the peermap to use as set 2467 * @param peer_map the peermap to use as set
2454 */ 2468 */
2455static void 2469static void
2456add_peer_array_to_set(const struct GNUNET_PeerIdentity *peer_array, 2470add_peer_array_to_set (const struct GNUNET_PeerIdentity *peer_array,
2457 unsigned int num_peers, 2471 unsigned int num_peers,
2458 struct GNUNET_CONTAINER_MultiPeerMap *peer_map) 2472 struct GNUNET_CONTAINER_MultiPeerMap *peer_map)
2459{ 2473{
2460 unsigned int i; 2474 unsigned int i;
2461 2475
2462 if (NULL == peer_map) 2476 if (NULL == peer_map)
2463 { 2477 {
2464 LOG(GNUNET_ERROR_TYPE_WARNING, 2478 LOG (GNUNET_ERROR_TYPE_WARNING,
2465 "Trying to add peers to non-existing peermap.\n"); 2479 "Trying to add peers to non-existing peermap.\n");
2466 return; 2480 return;
2467 } 2481 }
2468 2482
2469 for (i = 0; i < num_peers; i++) 2483 for (i = 0; i < num_peers; i++)
2484 {
2485 GNUNET_CONTAINER_multipeermap_put (peer_map,
2486 &peer_array[i],
2487 NULL,
2488 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
2489 if (msub->peer_map == peer_map)
2470 { 2490 {
2471 GNUNET_CONTAINER_multipeermap_put(peer_map, 2491 GNUNET_STATISTICS_set (stats,
2472 &peer_array[i], 2492 "# known peers",
2473 NULL, 2493 GNUNET_CONTAINER_multipeermap_size (peer_map),
2474 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 2494 GNUNET_NO);
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 }
2482 } 2495 }
2496 }
2483} 2497}
2484 2498
2485 2499
@@ -2491,17 +2505,17 @@ add_peer_array_to_set(const struct GNUNET_PeerIdentity *peer_array,
2491 * @param num_peer_ids the number of peers to send to @a peer_id 2505 * @param num_peer_ids the number of peers to send to @a peer_id
2492 */ 2506 */
2493static void 2507static void
2494send_pull_reply(struct PeerContext *peer_ctx, 2508send_pull_reply (struct PeerContext *peer_ctx,
2495 const struct GNUNET_PeerIdentity *peer_ids, 2509 const struct GNUNET_PeerIdentity *peer_ids,
2496 unsigned int num_peer_ids) 2510 unsigned int num_peer_ids)
2497{ 2511{
2498 uint32_t send_size; 2512 uint32_t send_size;
2499 struct GNUNET_MQ_Envelope *ev; 2513 struct GNUNET_MQ_Envelope *ev;
2500 struct GNUNET_RPS_P2P_PullReplyMessage *out_msg; 2514 struct GNUNET_RPS_P2P_PullReplyMessage *out_msg;
2501 2515
2502 /* Compute actual size */ 2516 /* Compute actual size */
2503 send_size = sizeof(struct GNUNET_RPS_P2P_PullReplyMessage) + 2517 send_size = sizeof(struct GNUNET_RPS_P2P_PullReplyMessage)
2504 num_peer_ids * sizeof(struct GNUNET_PeerIdentity); 2518 + num_peer_ids * sizeof(struct GNUNET_PeerIdentity);
2505 2519
2506 if (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE < send_size) 2520 if (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE < send_size)
2507 /* Compute number of peers to send 2521 /* Compute number of peers to send
@@ -2509,28 +2523,28 @@ send_pull_reply(struct PeerContext *peer_ctx,
2509 // TODO select random ones via permutation 2523 // TODO select random ones via permutation
2510 // or even better: do good protocol design 2524 // or even better: do good protocol design
2511 send_size = 2525 send_size =
2512 (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 2526 (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE
2513 sizeof(struct GNUNET_RPS_P2P_PullReplyMessage)) / 2527 - sizeof(struct GNUNET_RPS_P2P_PullReplyMessage))
2514 sizeof(struct GNUNET_PeerIdentity); 2528 / sizeof(struct GNUNET_PeerIdentity);
2515 else 2529 else
2516 send_size = num_peer_ids; 2530 send_size = num_peer_ids;
2517 2531
2518 LOG(GNUNET_ERROR_TYPE_DEBUG, 2532 LOG (GNUNET_ERROR_TYPE_DEBUG,
2519 "Going to send PULL REPLY with %u peers to %s\n", 2533 "Going to send PULL REPLY with %u peers to %s\n",
2520 send_size, GNUNET_i2s(&peer_ctx->peer_id)); 2534 send_size, GNUNET_i2s (&peer_ctx->peer_id));
2521 2535
2522 ev = GNUNET_MQ_msg_extra(out_msg, 2536 ev = GNUNET_MQ_msg_extra (out_msg,
2523 send_size * sizeof(struct GNUNET_PeerIdentity), 2537 send_size * sizeof(struct GNUNET_PeerIdentity),
2524 GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY); 2538 GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY);
2525 out_msg->num_peers = htonl(send_size); 2539 out_msg->num_peers = htonl (send_size);
2526 GNUNET_memcpy(&out_msg[1], peer_ids, 2540 GNUNET_memcpy (&out_msg[1], peer_ids,
2527 send_size * sizeof(struct GNUNET_PeerIdentity)); 2541 send_size * sizeof(struct GNUNET_PeerIdentity));
2528 2542
2529 send_message(peer_ctx, ev, "PULL REPLY"); 2543 send_message (peer_ctx, ev, "PULL REPLY");
2530 if (peer_ctx->sub == msub) 2544 if (peer_ctx->sub == msub)
2531 { 2545 {
2532 GNUNET_STATISTICS_update(stats, "# pull reply send issued", 1, GNUNET_NO); 2546 GNUNET_STATISTICS_update (stats, "# pull reply send issued", 1, GNUNET_NO);
2533 } 2547 }
2534 // TODO check with send intention: as send_channel is used/opened we indicate 2548 // TODO check with send intention: as send_channel is used/opened we indicate
2535 // a sending intention without intending it. 2549 // a sending intention without intending it.
2536 // -> clean peer afterwards? 2550 // -> clean peer afterwards?
@@ -2547,12 +2561,12 @@ send_pull_reply(struct PeerContext *peer_ctx,
2547 * @param peer Peer to insert 2561 * @param peer Peer to insert
2548 */ 2562 */
2549static void 2563static void
2550insert_in_pull_map(void *cls, 2564insert_in_pull_map (void *cls,
2551 const struct GNUNET_PeerIdentity *peer) 2565 const struct GNUNET_PeerIdentity *peer)
2552{ 2566{
2553 struct Sub *sub = cls; 2567 struct Sub *sub = cls;
2554 2568
2555 CustomPeerMap_put(sub->pull_map, peer); 2569 CustomPeerMap_put (sub->pull_map, peer);
2556} 2570}
2557 2571
2558 2572
@@ -2566,17 +2580,17 @@ insert_in_pull_map(void *cls,
2566 * @param peer the peer to insert 2580 * @param peer the peer to insert
2567 */ 2581 */
2568static void 2582static void
2569insert_in_view_op(void *cls, 2583insert_in_view_op (void *cls,
2570 const struct GNUNET_PeerIdentity *peer) 2584 const struct GNUNET_PeerIdentity *peer)
2571{ 2585{
2572 struct Sub *sub = cls; 2586 struct Sub *sub = cls;
2573 int inserted; 2587 int inserted;
2574 2588
2575 inserted = insert_in_view(sub, peer); 2589 inserted = insert_in_view (sub, peer);
2576 if (GNUNET_OK == inserted) 2590 if (GNUNET_OK == inserted)
2577 { 2591 {
2578 clients_notify_stream_peer(sub, 1, peer); 2592 clients_notify_stream_peer (sub, 1, peer);
2579 } 2593 }
2580} 2594}
2581 2595
2582 2596
@@ -2588,30 +2602,30 @@ insert_in_view_op(void *cls,
2588 * @param peer Peer to insert 2602 * @param peer Peer to insert
2589 */ 2603 */
2590static void 2604static void
2591insert_in_sampler(void *cls, 2605insert_in_sampler (void *cls,
2592 const struct GNUNET_PeerIdentity *peer) 2606 const struct GNUNET_PeerIdentity *peer)
2593{ 2607{
2594 struct Sub *sub = cls; 2608 struct Sub *sub = cls;
2595 2609
2596 LOG(GNUNET_ERROR_TYPE_DEBUG, 2610 LOG (GNUNET_ERROR_TYPE_DEBUG,
2597 "Updating samplers with peer %s from insert_in_sampler()\n", 2611 "Updating samplers with peer %s from insert_in_sampler()\n",
2598 GNUNET_i2s(peer)); 2612 GNUNET_i2s (peer));
2599 RPS_sampler_update(sub->sampler, peer); 2613 RPS_sampler_update (sub->sampler, peer);
2600 if (0 < RPS_sampler_count_id(sub->sampler, peer)) 2614 if (0 < RPS_sampler_count_id (sub->sampler, peer))
2601 { 2615 {
2602 /* Make sure we 'know' about this peer */ 2616 /* Make sure we 'know' about this peer */
2603 (void)issue_peer_online_check(sub, peer); 2617 (void) issue_peer_online_check (sub, peer);
2604 /* Establish a channel towards that peer to indicate we are going to send 2618 /* Establish a channel towards that peer to indicate we are going to send
2605 * messages to it */ 2619 * messages to it */
2606 //indicate_sending_intention (peer); 2620 // indicate_sending_intention (peer);
2607 } 2621 }
2608 if (sub == msub) 2622 if (sub == msub)
2609 { 2623 {
2610 GNUNET_STATISTICS_update(stats, 2624 GNUNET_STATISTICS_update (stats,
2611 "# observed peers in gossip", 2625 "# observed peers in gossip",
2612 1, 2626 1,
2613 GNUNET_NO); 2627 GNUNET_NO);
2614 } 2628 }
2615#ifdef TO_FILE 2629#ifdef TO_FILE
2616 sub->num_observed_peers++; 2630 sub->num_observed_peers++;
2617 GNUNET_CONTAINER_multipeermap_put 2631 GNUNET_CONTAINER_multipeermap_put
@@ -2620,17 +2634,17 @@ insert_in_sampler(void *cls,
2620 NULL, 2634 NULL,
2621 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 2635 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
2622 uint32_t num_observed_unique_peers = 2636 uint32_t num_observed_unique_peers =
2623 GNUNET_CONTAINER_multipeermap_size(sub->observed_unique_peers); 2637 GNUNET_CONTAINER_multipeermap_size (sub->observed_unique_peers);
2624 GNUNET_STATISTICS_set(stats, 2638 GNUNET_STATISTICS_set (stats,
2625 "# unique peers in gossip", 2639 "# unique peers in gossip",
2626 num_observed_unique_peers, 2640 num_observed_unique_peers,
2627 GNUNET_NO); 2641 GNUNET_NO);
2628#ifdef TO_FILE_FULL 2642#ifdef TO_FILE_FULL
2629 to_file(sub->file_name_observed_log, 2643 to_file (sub->file_name_observed_log,
2630 "%" PRIu32 " %" PRIu32 " %f\n", 2644 "%" PRIu32 " %" PRIu32 " %f\n",
2631 sub->num_observed_peers, 2645 sub->num_observed_peers,
2632 num_observed_unique_peers, 2646 num_observed_unique_peers,
2633 1.0 * num_observed_unique_peers / sub->num_observed_peers) 2647 1.0 * num_observed_unique_peers / sub->num_observed_peers)
2634#endif /* TO_FILE_FULL */ 2648#endif /* TO_FILE_FULL */
2635#endif /* TO_FILE */ 2649#endif /* TO_FILE */
2636} 2650}
@@ -2647,24 +2661,24 @@ insert_in_sampler(void *cls,
2647 * @param peer peer to insert/peer received 2661 * @param peer peer to insert/peer received
2648 */ 2662 */
2649static void 2663static void
2650got_peer(struct Sub *sub, 2664got_peer (struct Sub *sub,
2651 const struct GNUNET_PeerIdentity *peer) 2665 const struct GNUNET_PeerIdentity *peer)
2652{ 2666{
2653 /* If we did not know this peer already, insert it into sampler and view */ 2667 /* If we did not know this peer already, insert it into sampler and view */
2654 if (GNUNET_YES == issue_peer_online_check(sub, peer)) 2668 if (GNUNET_YES == issue_peer_online_check (sub, peer))
2655 { 2669 {
2656 schedule_operation(get_peer_ctx(sub->peer_map, peer), 2670 schedule_operation (get_peer_ctx (sub->peer_map, peer),
2657 &insert_in_sampler, sub); 2671 &insert_in_sampler, sub);
2658 schedule_operation(get_peer_ctx(sub->peer_map, peer), 2672 schedule_operation (get_peer_ctx (sub->peer_map, peer),
2659 &insert_in_view_op, sub); 2673 &insert_in_view_op, sub);
2660 } 2674 }
2661 if (sub == msub) 2675 if (sub == msub)
2662 { 2676 {
2663 GNUNET_STATISTICS_update(stats, 2677 GNUNET_STATISTICS_update (stats,
2664 "# learnd peers", 2678 "# learnd peers",
2665 1, 2679 1,
2666 GNUNET_NO); 2680 GNUNET_NO);
2667 } 2681 }
2668} 2682}
2669 2683
2670 2684
@@ -2676,32 +2690,32 @@ got_peer(struct Sub *sub,
2676 * GNUNET_NO otherwise 2690 * GNUNET_NO otherwise
2677 */ 2691 */
2678static int 2692static int
2679check_sending_channel_needed(const struct PeerContext *peer_ctx) 2693check_sending_channel_needed (const struct PeerContext *peer_ctx)
2680{ 2694{
2681 /* struct GNUNET_CADET_Channel *channel; */ 2695 /* struct GNUNET_CADET_Channel *channel; */
2682 if (GNUNET_NO == check_peer_known(peer_ctx->sub->peer_map, 2696 if (GNUNET_NO == check_peer_known (peer_ctx->sub->peer_map,
2683 &peer_ctx->peer_id)) 2697 &peer_ctx->peer_id))
2684 { 2698 {
2685 return GNUNET_NO; 2699 return GNUNET_NO;
2686 } 2700 }
2687 if (GNUNET_YES == check_sending_channel_exists(peer_ctx)) 2701 if (GNUNET_YES == check_sending_channel_exists (peer_ctx))
2688 { 2702 {
2689 if ((0 < RPS_sampler_count_id(peer_ctx->sub->sampler, 2703 if ((0 < RPS_sampler_count_id (peer_ctx->sub->sampler,
2690 &peer_ctx->peer_id)) || 2704 &peer_ctx->peer_id)) ||
2691 (GNUNET_YES == View_contains_peer(peer_ctx->sub->view, 2705 (GNUNET_YES == View_contains_peer (peer_ctx->sub->view,
2692 &peer_ctx->peer_id)) || 2706 &peer_ctx->peer_id)) ||
2693 (GNUNET_YES == CustomPeerMap_contains_peer(peer_ctx->sub->push_map, 2707 (GNUNET_YES == CustomPeerMap_contains_peer (peer_ctx->sub->push_map,
2694 &peer_ctx->peer_id)) || 2708 &peer_ctx->peer_id)) ||
2695 (GNUNET_YES == CustomPeerMap_contains_peer(peer_ctx->sub->pull_map, 2709 (GNUNET_YES == CustomPeerMap_contains_peer (peer_ctx->sub->pull_map,
2696 &peer_ctx->peer_id)) || 2710 &peer_ctx->peer_id)) ||
2697 (GNUNET_YES == check_peer_flag(peer_ctx->sub->peer_map, 2711 (GNUNET_YES == check_peer_flag (peer_ctx->sub->peer_map,
2698 &peer_ctx->peer_id, 2712 &peer_ctx->peer_id,
2699 Peers_PULL_REPLY_PENDING))) 2713 Peers_PULL_REPLY_PENDING)))
2700 { /* If we want to keep the connection to peer open */ 2714 { /* If we want to keep the connection to peer open */
2701 return GNUNET_YES; 2715 return GNUNET_YES;
2702 }
2703 return GNUNET_NO;
2704 } 2716 }
2717 return GNUNET_NO;
2718 }
2705 return GNUNET_NO; 2719 return GNUNET_NO;
2706} 2720}
2707 2721
@@ -2714,26 +2728,26 @@ check_sending_channel_needed(const struct PeerContext *peer_ctx)
2714 * @param peer the peer to remove 2728 * @param peer the peer to remove
2715 */ 2729 */
2716static void 2730static void
2717remove_peer(struct Sub *sub, 2731remove_peer (struct Sub *sub,
2718 const struct GNUNET_PeerIdentity *peer) 2732 const struct GNUNET_PeerIdentity *peer)
2719{ 2733{
2720 (void)View_remove_peer(sub->view, 2734 (void) View_remove_peer (sub->view,
2721 peer); 2735 peer);
2722 CustomPeerMap_remove_peer(sub->pull_map, 2736 CustomPeerMap_remove_peer (sub->pull_map,
2723 peer); 2737 peer);
2724 CustomPeerMap_remove_peer(sub->push_map, 2738 CustomPeerMap_remove_peer (sub->push_map,
2725 peer); 2739 peer);
2726 RPS_sampler_reinitialise_by_value(sub->sampler, 2740 RPS_sampler_reinitialise_by_value (sub->sampler,
2727 peer); 2741 peer);
2728 /* We want to destroy the peer now. 2742 /* We want to destroy the peer now.
2729 * Sometimes, it just seems that it's already been removed from the peer_map, 2743 * Sometimes, it just seems that it's already been removed from the peer_map,
2730 * so check the peer_map first. */ 2744 * so check the peer_map first. */
2731 if (GNUNET_YES == check_peer_known(sub->peer_map, 2745 if (GNUNET_YES == check_peer_known (sub->peer_map,
2732 peer)) 2746 peer))
2733 { 2747 {
2734 destroy_peer(get_peer_ctx(sub->peer_map, 2748 destroy_peer (get_peer_ctx (sub->peer_map,
2735 peer)); 2749 peer));
2736 } 2750 }
2737} 2751}
2738 2752
2739 2753
@@ -2746,49 +2760,49 @@ remove_peer(struct Sub *sub,
2746 * @param peer the peer whose data is about to be cleaned 2760 * @param peer the peer whose data is about to be cleaned
2747 */ 2761 */
2748static void 2762static void
2749clean_peer(struct Sub *sub, 2763clean_peer (struct Sub *sub,
2750 const struct GNUNET_PeerIdentity *peer) 2764 const struct GNUNET_PeerIdentity *peer)
2751{ 2765{
2752 if (GNUNET_NO == check_sending_channel_needed(get_peer_ctx(sub->peer_map, 2766 if (GNUNET_NO == check_sending_channel_needed (get_peer_ctx (sub->peer_map,
2753 peer))) 2767 peer)))
2754 { 2768 {
2755 LOG(GNUNET_ERROR_TYPE_DEBUG, 2769 LOG (GNUNET_ERROR_TYPE_DEBUG,
2756 "Going to remove send channel to peer %s\n", 2770 "Going to remove send channel to peer %s\n",
2757 GNUNET_i2s(peer)); 2771 GNUNET_i2s (peer));
2758 #if ENABLE_MALICIOUS 2772 #if ENABLE_MALICIOUS
2759 if (0 != GNUNET_memcmp(&attacked_peer, 2773 if (0 != GNUNET_memcmp (&attacked_peer,
2760 peer)) 2774 peer))
2761 (void)destroy_sending_channel(get_peer_ctx(sub->peer_map, 2775 (void) destroy_sending_channel (get_peer_ctx (sub->peer_map,
2762 peer)); 2776 peer));
2763 #else /* ENABLE_MALICIOUS */ 2777 #else /* ENABLE_MALICIOUS */
2764 (void)destroy_sending_channel(get_peer_ctx(sub->peer_map, 2778 (void) destroy_sending_channel (get_peer_ctx (sub->peer_map,
2765 peer)); 2779 peer));
2766 #endif /* ENABLE_MALICIOUS */ 2780 #endif /* ENABLE_MALICIOUS */
2767 } 2781 }
2768 2782
2769 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(sub->peer_map, 2783 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (sub->peer_map,
2770 peer)) 2784 peer))
2771 { 2785 {
2772 /* Peer was already removed by callback on destroyed channel */ 2786 /* Peer was already removed by callback on destroyed channel */
2773 LOG(GNUNET_ERROR_TYPE_WARNING, 2787 LOG (GNUNET_ERROR_TYPE_WARNING,
2774 "Peer was removed from our knowledge during cleanup\n"); 2788 "Peer was removed from our knowledge during cleanup\n");
2775 return; 2789 return;
2776 } 2790 }
2777 2791
2778 if ((GNUNET_NO == check_peer_send_intention(get_peer_ctx(sub->peer_map, 2792 if ((GNUNET_NO == check_peer_send_intention (get_peer_ctx (sub->peer_map,
2779 peer))) && 2793 peer))) &&
2780 (GNUNET_NO == View_contains_peer(sub->view, peer)) && 2794 (GNUNET_NO == View_contains_peer (sub->view, peer)) &&
2781 (GNUNET_NO == CustomPeerMap_contains_peer(sub->push_map, peer)) && 2795 (GNUNET_NO == CustomPeerMap_contains_peer (sub->push_map, peer)) &&
2782 (GNUNET_NO == CustomPeerMap_contains_peer(sub->push_map, peer)) && 2796 (GNUNET_NO == CustomPeerMap_contains_peer (sub->push_map, peer)) &&
2783 (0 == RPS_sampler_count_id(sub->sampler, peer)) && 2797 (0 == RPS_sampler_count_id (sub->sampler, peer)) &&
2784 (GNUNET_YES == check_removable(get_peer_ctx(sub->peer_map, peer)))) 2798 (GNUNET_YES == check_removable (get_peer_ctx (sub->peer_map, peer))))
2785 { /* We can safely remove this peer */ 2799 { /* We can safely remove this peer */
2786 LOG(GNUNET_ERROR_TYPE_DEBUG, 2800 LOG (GNUNET_ERROR_TYPE_DEBUG,
2787 "Going to remove peer %s\n", 2801 "Going to remove peer %s\n",
2788 GNUNET_i2s(peer)); 2802 GNUNET_i2s (peer));
2789 remove_peer(sub, peer); 2803 remove_peer (sub, peer);
2790 return; 2804 return;
2791 } 2805 }
2792} 2806}
2793 2807
2794 2808
@@ -2804,22 +2818,22 @@ clean_peer(struct Sub *sub,
2804 * @param channel The channel being closed 2818 * @param channel The channel being closed
2805 */ 2819 */
2806static void 2820static void
2807cleanup_destroyed_channel(void *cls, 2821cleanup_destroyed_channel (void *cls,
2808 const struct GNUNET_CADET_Channel *channel) 2822 const struct GNUNET_CADET_Channel *channel)
2809{ 2823{
2810 struct ChannelCtx *channel_ctx = cls; 2824 struct ChannelCtx *channel_ctx = cls;
2811 struct PeerContext *peer_ctx = channel_ctx->peer_ctx; 2825 struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
2812 2826
2813 (void)channel; 2827 (void) channel;
2814 2828
2815 channel_ctx->channel = NULL; 2829 channel_ctx->channel = NULL;
2816 remove_channel_ctx(channel_ctx); 2830 remove_channel_ctx (channel_ctx);
2817 if (NULL != peer_ctx && 2831 if ((NULL != peer_ctx)&&
2818 peer_ctx->send_channel_ctx == channel_ctx && 2832 (peer_ctx->send_channel_ctx == channel_ctx) &&
2819 GNUNET_YES == check_sending_channel_needed(channel_ctx->peer_ctx)) 2833 (GNUNET_YES == check_sending_channel_needed (channel_ctx->peer_ctx)) )
2820 { 2834 {
2821 remove_peer(peer_ctx->sub, &peer_ctx->peer_id); 2835 remove_peer (peer_ctx->sub, &peer_ctx->peer_id);
2822 } 2836 }
2823} 2837}
2824 2838
2825/*********************************************************************** 2839/***********************************************************************
@@ -2843,119 +2857,119 @@ cleanup_destroyed_channel(void *cls,
2843 * @return Sub 2857 * @return Sub
2844 */ 2858 */
2845struct Sub * 2859struct Sub *
2846new_sub(const struct GNUNET_HashCode *hash, 2860new_sub (const struct GNUNET_HashCode *hash,
2847 uint32_t sampler_size, 2861 uint32_t sampler_size,
2848 struct GNUNET_TIME_Relative round_interval) 2862 struct GNUNET_TIME_Relative round_interval)
2849{ 2863{
2850 struct Sub *sub; 2864 struct Sub *sub;
2851 2865
2852 sub = GNUNET_new(struct Sub); 2866 sub = GNUNET_new (struct Sub);
2853 2867
2854 /* With the hash generated from the secret value this service only connects 2868 /* With the hash generated from the secret value this service only connects
2855 * to rps instances that share the value */ 2869 * to rps instances that share the value */
2856 struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 2870 struct GNUNET_MQ_MessageHandler cadet_handlers[] = {
2857 GNUNET_MQ_hd_fixed_size(peer_check, 2871 GNUNET_MQ_hd_fixed_size (peer_check,
2858 GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE, 2872 GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE,
2859 struct GNUNET_MessageHeader, 2873 struct GNUNET_MessageHeader,
2860 NULL), 2874 NULL),
2861 GNUNET_MQ_hd_fixed_size(peer_push, 2875 GNUNET_MQ_hd_fixed_size (peer_push,
2862 GNUNET_MESSAGE_TYPE_RPS_PP_PUSH, 2876 GNUNET_MESSAGE_TYPE_RPS_PP_PUSH,
2863 struct GNUNET_MessageHeader, 2877 struct GNUNET_MessageHeader,
2864 NULL), 2878 NULL),
2865 GNUNET_MQ_hd_fixed_size(peer_pull_request, 2879 GNUNET_MQ_hd_fixed_size (peer_pull_request,
2866 GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST, 2880 GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST,
2867 struct GNUNET_MessageHeader, 2881 struct GNUNET_MessageHeader,
2868 NULL), 2882 NULL),
2869 GNUNET_MQ_hd_var_size(peer_pull_reply, 2883 GNUNET_MQ_hd_var_size (peer_pull_reply,
2870 GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY, 2884 GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY,
2871 struct GNUNET_RPS_P2P_PullReplyMessage, 2885 struct GNUNET_RPS_P2P_PullReplyMessage,
2872 NULL), 2886 NULL),
2873 GNUNET_MQ_handler_end() 2887 GNUNET_MQ_handler_end ()
2874 }; 2888 };
2875 sub->hash = *hash; 2889 sub->hash = *hash;
2876 sub->cadet_port = 2890 sub->cadet_port =
2877 GNUNET_CADET_open_port(cadet_handle, 2891 GNUNET_CADET_open_port (cadet_handle,
2878 &sub->hash, 2892 &sub->hash,
2879 &handle_inbound_channel, /* Connect handler */ 2893 &handle_inbound_channel, /* Connect handler */
2880 sub, /* cls */ 2894 sub, /* cls */
2881 NULL, /* WindowSize handler */ 2895 NULL, /* WindowSize handler */
2882 &cleanup_destroyed_channel, /* Disconnect handler */ 2896 &cleanup_destroyed_channel, /* Disconnect handler */
2883 cadet_handlers); 2897 cadet_handlers);
2884 if (NULL == sub->cadet_port) 2898 if (NULL == sub->cadet_port)
2885 { 2899 {
2886 LOG(GNUNET_ERROR_TYPE_ERROR, 2900 LOG (GNUNET_ERROR_TYPE_ERROR,
2887 "Cadet port `%s' is already in use.\n", 2901 "Cadet port `%s' is already in use.\n",
2888 GNUNET_APPLICATION_PORT_RPS); 2902 GNUNET_APPLICATION_PORT_RPS);
2889 GNUNET_assert(0); 2903 GNUNET_assert (0);
2890 } 2904 }
2891 2905
2892 /* Set up general data structure to keep track about peers */ 2906 /* Set up general data structure to keep track about peers */
2893 sub->valid_peers = GNUNET_CONTAINER_multipeermap_create(4, GNUNET_NO); 2907 sub->valid_peers = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO);
2894 if (GNUNET_OK != 2908 if (GNUNET_OK !=
2895 GNUNET_CONFIGURATION_get_value_filename(cfg, 2909 GNUNET_CONFIGURATION_get_value_filename (cfg,
2896 "rps", 2910 "rps",
2897 "FILENAME_VALID_PEERS", 2911 "FILENAME_VALID_PEERS",
2898 &sub->filename_valid_peers)) 2912 &sub->filename_valid_peers))
2899 { 2913 {
2900 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, 2914 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
2901 "rps", 2915 "rps",
2902 "FILENAME_VALID_PEERS"); 2916 "FILENAME_VALID_PEERS");
2903 } 2917 }
2904 if (0 != strncmp("DISABLE", sub->filename_valid_peers, 7)) 2918 if (0 != strncmp ("DISABLE", sub->filename_valid_peers, 7))
2905 { 2919 {
2906 char *tmp_filename_valid_peers; 2920 char *tmp_filename_valid_peers;
2907 char str_hash[105]; 2921 char str_hash[105];
2908 2922
2909 GNUNET_snprintf(str_hash, 2923 GNUNET_snprintf (str_hash,
2910 sizeof(str_hash), 2924 sizeof(str_hash),
2911 GNUNET_h2s_full(hash)); 2925 GNUNET_h2s_full (hash));
2912 tmp_filename_valid_peers = sub->filename_valid_peers; 2926 tmp_filename_valid_peers = sub->filename_valid_peers;
2913 GNUNET_asprintf(&sub->filename_valid_peers, 2927 GNUNET_asprintf (&sub->filename_valid_peers,
2914 "%s%s", 2928 "%s%s",
2915 tmp_filename_valid_peers, 2929 tmp_filename_valid_peers,
2916 str_hash); 2930 str_hash);
2917 GNUNET_free(tmp_filename_valid_peers); 2931 GNUNET_free (tmp_filename_valid_peers);
2918 } 2932 }
2919 sub->peer_map = GNUNET_CONTAINER_multipeermap_create(4, GNUNET_NO); 2933 sub->peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO);
2920 2934
2921 /* Set up the sampler */ 2935 /* Set up the sampler */
2922 sub->sampler_size_est_min = sampler_size; 2936 sub->sampler_size_est_min = sampler_size;
2923 sub->sampler_size_est_need = sampler_size;; 2937 sub->sampler_size_est_need = sampler_size;;
2924 LOG(GNUNET_ERROR_TYPE_DEBUG, "MINSIZE is %u\n", sub->sampler_size_est_min); 2938 LOG (GNUNET_ERROR_TYPE_DEBUG, "MINSIZE is %u\n", sub->sampler_size_est_min);
2925 GNUNET_assert(0 != round_interval.rel_value_us); 2939 GNUNET_assert (0 != round_interval.rel_value_us);
2926 sub->round_interval = round_interval; 2940 sub->round_interval = round_interval;
2927 sub->sampler = RPS_sampler_init(sampler_size, 2941 sub->sampler = RPS_sampler_init (sampler_size,
2928 round_interval); 2942 round_interval);
2929 2943
2930 /* Logging of internals */ 2944 /* Logging of internals */
2931#ifdef TO_FILE_FULL 2945#ifdef TO_FILE_FULL
2932 sub->file_name_view_log = store_prefix_file_name(&own_identity, "view"); 2946 sub->file_name_view_log = store_prefix_file_name (&own_identity, "view");
2933#endif /* TO_FILE_FULL */ 2947#endif /* TO_FILE_FULL */
2934#ifdef TO_FILE 2948#ifdef TO_FILE
2935#ifdef TO_FILE_FULL 2949#ifdef TO_FILE_FULL
2936 sub->file_name_observed_log = store_prefix_file_name(&own_identity, 2950 sub->file_name_observed_log = store_prefix_file_name (&own_identity,
2937 "observed"); 2951 "observed");
2938#endif /* TO_FILE_FULL */ 2952#endif /* TO_FILE_FULL */
2939 sub->num_observed_peers = 0; 2953 sub->num_observed_peers = 0;
2940 sub->observed_unique_peers = GNUNET_CONTAINER_multipeermap_create(1, 2954 sub->observed_unique_peers = GNUNET_CONTAINER_multipeermap_create (1,
2941 GNUNET_NO); 2955 GNUNET_NO);
2942#endif /* TO_FILE */ 2956#endif /* TO_FILE */
2943 2957
2944 /* Set up data structures for gossip */ 2958 /* Set up data structures for gossip */
2945 sub->push_map = CustomPeerMap_create(4); 2959 sub->push_map = CustomPeerMap_create (4);
2946 sub->pull_map = CustomPeerMap_create(4); 2960 sub->pull_map = CustomPeerMap_create (4);
2947 sub->view_size_est_min = sampler_size;; 2961 sub->view_size_est_min = sampler_size;;
2948 sub->view = View_create(sub->view_size_est_min); 2962 sub->view = View_create (sub->view_size_est_min);
2949 if (sub == msub) 2963 if (sub == msub)
2950 { 2964 {
2951 GNUNET_STATISTICS_set(stats, 2965 GNUNET_STATISTICS_set (stats,
2952 "view size aim", 2966 "view size aim",
2953 sub->view_size_est_min, 2967 sub->view_size_est_min,
2954 GNUNET_NO); 2968 GNUNET_NO);
2955 } 2969 }
2956 2970
2957 /* Start executing rounds */ 2971 /* Start executing rounds */
2958 sub->do_round_task = GNUNET_SCHEDULER_add_now(&do_round, sub); 2972 sub->do_round_task = GNUNET_SCHEDULER_add_now (&do_round, sub);
2959 2973
2960 return sub; 2974 return sub;
2961} 2975}
@@ -2971,36 +2985,36 @@ new_sub(const struct GNUNET_HashCode *hash,
2971 * @param file_name file to dump into 2985 * @param file_name file to dump into
2972 */ 2986 */
2973static void 2987static void
2974write_histogram_to_file(const uint32_t hist_array[], 2988write_histogram_to_file (const uint32_t hist_array[],
2975 const char *file_name) 2989 const char *file_name)
2976{ 2990{
2977 char collect_str[SIZE_DUMP_FILE + 1] = ""; 2991 char collect_str[SIZE_DUMP_FILE + 1] = "";
2978 char *recv_str_iter; 2992 char *recv_str_iter;
2979 char *file_name_full; 2993 char *file_name_full;
2980 2994
2981 recv_str_iter = collect_str; 2995 recv_str_iter = collect_str;
2982 file_name_full = store_prefix_file_name(&own_identity, 2996 file_name_full = store_prefix_file_name (&own_identity,
2983 file_name); 2997 file_name);
2984 for (uint32_t i = 0; i < HISTOGRAM_FILE_SLOTS; i++) 2998 for (uint32_t i = 0; i < HISTOGRAM_FILE_SLOTS; i++)
2985 { 2999 {
2986 char collect_str_tmp[8]; 3000 char collect_str_tmp[8];
2987 3001
2988 GNUNET_snprintf(collect_str_tmp, 3002 GNUNET_snprintf (collect_str_tmp,
2989 sizeof(collect_str_tmp), 3003 sizeof(collect_str_tmp),
2990 "%" PRIu32 "\n", 3004 "%" PRIu32 "\n",
2991 hist_array[i]); 3005 hist_array[i]);
2992 recv_str_iter = stpncpy(recv_str_iter, 3006 recv_str_iter = stpncpy (recv_str_iter,
2993 collect_str_tmp, 3007 collect_str_tmp,
2994 6); 3008 6);
2995 } 3009 }
2996 (void)stpcpy(recv_str_iter, 3010 (void) stpcpy (recv_str_iter,
2997 "\n"); 3011 "\n");
2998 LOG(GNUNET_ERROR_TYPE_DEBUG, 3012 LOG (GNUNET_ERROR_TYPE_DEBUG,
2999 "Writing push stats to disk\n"); 3013 "Writing push stats to disk\n");
3000 to_file_w_len(file_name_full, 3014 to_file_w_len (file_name_full,
3001 SIZE_DUMP_FILE, 3015 SIZE_DUMP_FILE,
3002 collect_str); 3016 collect_str);
3003 GNUNET_free(file_name_full); 3017 GNUNET_free (file_name_full);
3004} 3018}
3005#endif /* TO_FILE */ 3019#endif /* TO_FILE */
3006 3020
@@ -3011,56 +3025,56 @@ write_histogram_to_file(const uint32_t hist_array[],
3011 * @param sub Sub to destroy 3025 * @param sub Sub to destroy
3012 */ 3026 */
3013static void 3027static void
3014destroy_sub(struct Sub *sub) 3028destroy_sub (struct Sub *sub)
3015{ 3029{
3016 GNUNET_assert(NULL != sub); 3030 GNUNET_assert (NULL != sub);
3017 GNUNET_assert(NULL != sub->do_round_task); 3031 GNUNET_assert (NULL != sub->do_round_task);
3018 GNUNET_SCHEDULER_cancel(sub->do_round_task); 3032 GNUNET_SCHEDULER_cancel (sub->do_round_task);
3019 sub->do_round_task = NULL; 3033 sub->do_round_task = NULL;
3020 3034
3021 /* Disconnect from cadet */ 3035 /* Disconnect from cadet */
3022 GNUNET_CADET_close_port(sub->cadet_port); 3036 GNUNET_CADET_close_port (sub->cadet_port);
3023 sub->cadet_port = NULL; 3037 sub->cadet_port = NULL;
3024 3038
3025 /* Clean up data structures for peers */ 3039 /* Clean up data structures for peers */
3026 RPS_sampler_destroy(sub->sampler); 3040 RPS_sampler_destroy (sub->sampler);
3027 sub->sampler = NULL; 3041 sub->sampler = NULL;
3028 View_destroy(sub->view); 3042 View_destroy (sub->view);
3029 sub->view = NULL; 3043 sub->view = NULL;
3030 CustomPeerMap_destroy(sub->push_map); 3044 CustomPeerMap_destroy (sub->push_map);
3031 sub->push_map = NULL; 3045 sub->push_map = NULL;
3032 CustomPeerMap_destroy(sub->pull_map); 3046 CustomPeerMap_destroy (sub->pull_map);
3033 sub->pull_map = NULL; 3047 sub->pull_map = NULL;
3034 peers_terminate(sub); 3048 peers_terminate (sub);
3035 3049
3036 /* Free leftover data structures */ 3050 /* Free leftover data structures */
3037#ifdef TO_FILE_FULL 3051#ifdef TO_FILE_FULL
3038 GNUNET_free(sub->file_name_view_log); 3052 GNUNET_free (sub->file_name_view_log);
3039 sub->file_name_view_log = NULL; 3053 sub->file_name_view_log = NULL;
3040#endif /* TO_FILE_FULL */ 3054#endif /* TO_FILE_FULL */
3041#ifdef TO_FILE 3055#ifdef TO_FILE
3042#ifdef TO_FILE_FULL 3056#ifdef TO_FILE_FULL
3043 GNUNET_free(sub->file_name_observed_log); 3057 GNUNET_free (sub->file_name_observed_log);
3044 sub->file_name_observed_log = NULL; 3058 sub->file_name_observed_log = NULL;
3045#endif /* TO_FILE_FULL */ 3059#endif /* TO_FILE_FULL */
3046 3060
3047 /* Write push frequencies to disk */ 3061 /* Write push frequencies to disk */
3048 write_histogram_to_file(sub->push_recv, 3062 write_histogram_to_file (sub->push_recv,
3049 "push_recv"); 3063 "push_recv");
3050 3064
3051 /* Write push deltas to disk */ 3065 /* Write push deltas to disk */
3052 write_histogram_to_file(sub->push_delta, 3066 write_histogram_to_file (sub->push_delta,
3053 "push_delta"); 3067 "push_delta");
3054 3068
3055 /* Write pull delays to disk */ 3069 /* Write pull delays to disk */
3056 write_histogram_to_file(sub->pull_delays, 3070 write_histogram_to_file (sub->pull_delays,
3057 "pull_delays"); 3071 "pull_delays");
3058 3072
3059 GNUNET_CONTAINER_multipeermap_destroy(sub->observed_unique_peers); 3073 GNUNET_CONTAINER_multipeermap_destroy (sub->observed_unique_peers);
3060 sub->observed_unique_peers = NULL; 3074 sub->observed_unique_peers = NULL;
3061#endif /* TO_FILE */ 3075#endif /* TO_FILE */
3062 3076
3063 GNUNET_free(sub); 3077 GNUNET_free (sub);
3064} 3078}
3065 3079
3066 3080
@@ -3080,13 +3094,13 @@ destroy_sub(struct Sub *sub)
3080 * @param my_identity - unused 3094 * @param my_identity - unused
3081 */ 3095 */
3082void 3096void
3083core_init(void *cls, 3097core_init (void *cls,
3084 const struct GNUNET_PeerIdentity *my_identity) 3098 const struct GNUNET_PeerIdentity *my_identity)
3085{ 3099{
3086 (void)cls; 3100 (void) cls;
3087 (void)my_identity; 3101 (void) my_identity;
3088 3102
3089 map_single_hop = GNUNET_CONTAINER_multipeermap_create(4, GNUNET_NO); 3103 map_single_hop = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO);
3090} 3104}
3091 3105
3092 3106
@@ -3099,18 +3113,18 @@ core_init(void *cls,
3099 * @return closure given to #core_disconnects as peer_cls 3113 * @return closure given to #core_disconnects as peer_cls
3100 */ 3114 */
3101void * 3115void *
3102core_connects(void *cls, 3116core_connects (void *cls,
3103 const struct GNUNET_PeerIdentity *peer, 3117 const struct GNUNET_PeerIdentity *peer,
3104 struct GNUNET_MQ_Handle *mq) 3118 struct GNUNET_MQ_Handle *mq)
3105{ 3119{
3106 (void)cls; 3120 (void) cls;
3107 (void)mq; 3121 (void) mq;
3108 3122
3109 GNUNET_assert(GNUNET_YES == 3123 GNUNET_assert (GNUNET_YES ==
3110 GNUNET_CONTAINER_multipeermap_put(map_single_hop, 3124 GNUNET_CONTAINER_multipeermap_put (map_single_hop,
3111 peer, 3125 peer,
3112 NULL, 3126 NULL,
3113 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 3127 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
3114 return NULL; 3128 return NULL;
3115} 3129}
3116 3130
@@ -3124,14 +3138,14 @@ core_connects(void *cls,
3124 * @param peer_cls closure given in #core_connects - unused 3138 * @param peer_cls closure given in #core_connects - unused
3125 */ 3139 */
3126void 3140void
3127core_disconnects(void *cls, 3141core_disconnects (void *cls,
3128 const struct GNUNET_PeerIdentity *peer, 3142 const struct GNUNET_PeerIdentity *peer,
3129 void *peer_cls) 3143 void *peer_cls)
3130{ 3144{
3131 (void)cls; 3145 (void) cls;
3132 (void)peer_cls; 3146 (void) peer_cls;
3133 3147
3134 GNUNET_CONTAINER_multipeermap_remove_all(map_single_hop, peer); 3148 GNUNET_CONTAINER_multipeermap_remove_all (map_single_hop, peer);
3135} 3149}
3136 3150
3137/*********************************************************************** 3151/***********************************************************************
@@ -3145,18 +3159,18 @@ core_disconnects(void *cls,
3145 * @param cli_ctx Context to destroy 3159 * @param cli_ctx Context to destroy
3146 */ 3160 */
3147static void 3161static void
3148destroy_cli_ctx(struct ClientContext *cli_ctx) 3162destroy_cli_ctx (struct ClientContext *cli_ctx)
3149{ 3163{
3150 GNUNET_assert(NULL != cli_ctx); 3164 GNUNET_assert (NULL != cli_ctx);
3151 GNUNET_CONTAINER_DLL_remove(cli_ctx_head, 3165 GNUNET_CONTAINER_DLL_remove (cli_ctx_head,
3152 cli_ctx_tail, 3166 cli_ctx_tail,
3153 cli_ctx); 3167 cli_ctx);
3154 if (NULL != cli_ctx->sub) 3168 if (NULL != cli_ctx->sub)
3155 { 3169 {
3156 destroy_sub(cli_ctx->sub); 3170 destroy_sub (cli_ctx->sub);
3157 cli_ctx->sub = NULL; 3171 cli_ctx->sub = NULL;
3158 } 3172 }
3159 GNUNET_free(cli_ctx); 3173 GNUNET_free (cli_ctx);
3160} 3174}
3161 3175
3162 3176
@@ -3168,44 +3182,44 @@ destroy_cli_ctx(struct ClientContext *cli_ctx)
3168 * @param std_dev standard deviation for the estimate 3182 * @param std_dev standard deviation for the estimate
3169 */ 3183 */
3170static void 3184static void
3171adapt_sizes(struct Sub *sub, double logestimate, double std_dev) 3185adapt_sizes (struct Sub *sub, double logestimate, double std_dev)
3172{ 3186{
3173 double estimate; 3187 double estimate;
3174 3188
3175 //double scale; // TODO this might go gloabal/config 3189 // double scale; // TODO this might go gloabal/config
3176 3190
3177 LOG(GNUNET_ERROR_TYPE_DEBUG, 3191 LOG (GNUNET_ERROR_TYPE_DEBUG,
3178 "Received a ns estimate - logest: %f, std_dev: %f (old_size: %u)\n", 3192 "Received a ns estimate - logest: %f, std_dev: %f (old_size: %u)\n",
3179 logestimate, std_dev, RPS_sampler_get_size(sub->sampler)); 3193 logestimate, std_dev, RPS_sampler_get_size (sub->sampler));
3180 //scale = .01; 3194 // scale = .01;
3181 estimate = GNUNET_NSE_log_estimate_to_n(logestimate); 3195 estimate = GNUNET_NSE_log_estimate_to_n (logestimate);
3182 // GNUNET_NSE_log_estimate_to_n (logestimate); 3196 // GNUNET_NSE_log_estimate_to_n (logestimate);
3183 estimate = pow(estimate, 1.0 / 3); 3197 estimate = pow (estimate, 1.0 / 3);
3184 // TODO add if std_dev is a number 3198 // TODO add if std_dev is a number
3185 // estimate += (std_dev * scale); 3199 // estimate += (std_dev * scale);
3186 if (sub->view_size_est_min < ceil(estimate)) 3200 if (sub->view_size_est_min < ceil (estimate))
3187 { 3201 {
3188 LOG(GNUNET_ERROR_TYPE_DEBUG, "Changing estimate to %f\n", estimate); 3202 LOG (GNUNET_ERROR_TYPE_DEBUG, "Changing estimate to %f\n", estimate);
3189 sub->sampler_size_est_need = estimate; 3203 sub->sampler_size_est_need = estimate;
3190 sub->view_size_est_need = estimate; 3204 sub->view_size_est_need = estimate;
3191 } 3205 }
3192 else 3206 else
3193 { 3207 {
3194 LOG(GNUNET_ERROR_TYPE_DEBUG, "Not using estimate %f\n", estimate); 3208 LOG (GNUNET_ERROR_TYPE_DEBUG, "Not using estimate %f\n", estimate);
3195 //sub->sampler_size_est_need = sub->view_size_est_min; 3209 // sub->sampler_size_est_need = sub->view_size_est_min;
3196 sub->view_size_est_need = sub->view_size_est_min; 3210 sub->view_size_est_need = sub->view_size_est_min;
3197 } 3211 }
3198 if (sub == msub) 3212 if (sub == msub)
3199 { 3213 {
3200 GNUNET_STATISTICS_set(stats, 3214 GNUNET_STATISTICS_set (stats,
3201 "view size aim", 3215 "view size aim",
3202 sub->view_size_est_need, 3216 sub->view_size_est_need,
3203 GNUNET_NO); 3217 GNUNET_NO);
3204 } 3218 }
3205 3219
3206 /* If the NSE has changed adapt the lists accordingly */ 3220 /* If the NSE has changed adapt the lists accordingly */
3207 resize_wrapper(sub->sampler, sub->sampler_size_est_need); 3221 resize_wrapper (sub->sampler, sub->sampler_size_est_need);
3208 View_change_len(sub->view, sub->view_size_est_need); 3222 View_change_len (sub->view, sub->view_size_est_need);
3209} 3223}
3210 3224
3211 3225
@@ -3223,24 +3237,24 @@ adapt_sizes(struct Sub *sub, double logestimate, double std_dev)
3223 * @param std_dev standard deviation for the estimate 3237 * @param std_dev standard deviation for the estimate
3224 */ 3238 */
3225static void 3239static void
3226nse_callback(void *cls, 3240nse_callback (void *cls,
3227 struct GNUNET_TIME_Absolute timestamp, 3241 struct GNUNET_TIME_Absolute timestamp,
3228 double logestimate, double std_dev) 3242 double logestimate, double std_dev)
3229{ 3243{
3230 (void)cls; 3244 (void) cls;
3231 (void)timestamp; 3245 (void) timestamp;
3232 struct ClientContext *cli_ctx_iter; 3246 struct ClientContext *cli_ctx_iter;
3233 3247
3234 adapt_sizes(msub, logestimate, std_dev); 3248 adapt_sizes (msub, logestimate, std_dev);
3235 for (cli_ctx_iter = cli_ctx_head; 3249 for (cli_ctx_iter = cli_ctx_head;
3236 NULL != cli_ctx_iter; 3250 NULL != cli_ctx_iter;
3237 cli_ctx_iter = cli_ctx_iter->next) 3251 cli_ctx_iter = cli_ctx_iter->next)
3252 {
3253 if (NULL != cli_ctx_iter->sub)
3238 { 3254 {
3239 if (NULL != cli_ctx_iter->sub) 3255 adapt_sizes (cli_ctx_iter->sub, logestimate, std_dev);
3240 {
3241 adapt_sizes(cli_ctx_iter->sub, logestimate, std_dev);
3242 }
3243 } 3256 }
3257 }
3244} 3258}
3245 3259
3246 3260
@@ -3254,24 +3268,24 @@ nse_callback(void *cls,
3254 * #GNUNET_SYSERR otherwise 3268 * #GNUNET_SYSERR otherwise
3255 */ 3269 */
3256static int 3270static int
3257check_client_seed(void *cls, const struct GNUNET_RPS_CS_SeedMessage *msg) 3271check_client_seed (void *cls, const struct GNUNET_RPS_CS_SeedMessage *msg)
3258{ 3272{
3259 struct ClientContext *cli_ctx = cls; 3273 struct ClientContext *cli_ctx = cls;
3260 uint16_t msize = ntohs(msg->header.size); 3274 uint16_t msize = ntohs (msg->header.size);
3261 uint32_t num_peers = ntohl(msg->num_peers); 3275 uint32_t num_peers = ntohl (msg->num_peers);
3262 3276
3263 msize -= sizeof(struct GNUNET_RPS_CS_SeedMessage); 3277 msize -= sizeof(struct GNUNET_RPS_CS_SeedMessage);
3264 if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) || 3278 if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) ||
3265 (msize % sizeof(struct GNUNET_PeerIdentity) != 0)) 3279 (msize % sizeof(struct GNUNET_PeerIdentity) != 0))
3266 { 3280 {
3267 LOG(GNUNET_ERROR_TYPE_ERROR, 3281 LOG (GNUNET_ERROR_TYPE_ERROR,
3268 "message says it sends %" PRIu32 " peers, have space for %lu peers\n", 3282 "message says it sends %" PRIu32 " peers, have space for %lu peers\n",
3269 ntohl(msg->num_peers), 3283 ntohl (msg->num_peers),
3270 (msize / sizeof(struct GNUNET_PeerIdentity))); 3284 (msize / sizeof(struct GNUNET_PeerIdentity)));
3271 GNUNET_break(0); 3285 GNUNET_break (0);
3272 GNUNET_SERVICE_client_drop(cli_ctx->client); 3286 GNUNET_SERVICE_client_drop (cli_ctx->client);
3273 return GNUNET_SYSERR; 3287 return GNUNET_SYSERR;
3274 } 3288 }
3275 return GNUNET_OK; 3289 return GNUNET_OK;
3276} 3290}
3277 3291
@@ -3283,34 +3297,34 @@ check_client_seed(void *cls, const struct GNUNET_RPS_CS_SeedMessage *msg)
3283 * @param message the actual message 3297 * @param message the actual message
3284 */ 3298 */
3285static void 3299static void
3286handle_client_seed(void *cls, 3300handle_client_seed (void *cls,
3287 const struct GNUNET_RPS_CS_SeedMessage *msg) 3301 const struct GNUNET_RPS_CS_SeedMessage *msg)
3288{ 3302{
3289 struct ClientContext *cli_ctx = cls; 3303 struct ClientContext *cli_ctx = cls;
3290 struct GNUNET_PeerIdentity *peers; 3304 struct GNUNET_PeerIdentity *peers;
3291 uint32_t num_peers; 3305 uint32_t num_peers;
3292 uint32_t i; 3306 uint32_t i;
3293 3307
3294 num_peers = ntohl(msg->num_peers); 3308 num_peers = ntohl (msg->num_peers);
3295 peers = (struct GNUNET_PeerIdentity *)&msg[1]; 3309 peers = (struct GNUNET_PeerIdentity *) &msg[1];
3296 3310
3297 LOG(GNUNET_ERROR_TYPE_DEBUG, 3311 LOG (GNUNET_ERROR_TYPE_DEBUG,
3298 "Client seeded peers:\n"); 3312 "Client seeded peers:\n");
3299 print_peer_list(peers, num_peers); 3313 print_peer_list (peers, num_peers);
3300 3314
3301 for (i = 0; i < num_peers; i++) 3315 for (i = 0; i < num_peers; i++)
3302 { 3316 {
3303 LOG(GNUNET_ERROR_TYPE_DEBUG, 3317 LOG (GNUNET_ERROR_TYPE_DEBUG,
3304 "Updating samplers with seed %" PRIu32 ": %s\n", 3318 "Updating samplers with seed %" PRIu32 ": %s\n",
3305 i, 3319 i,
3306 GNUNET_i2s(&peers[i])); 3320 GNUNET_i2s (&peers[i]));
3307 3321
3308 if (NULL != msub) 3322 if (NULL != msub)
3309 got_peer(msub, &peers[i]); /* Condition needed? */ 3323 got_peer (msub, &peers[i]); /* Condition needed? */
3310 if (NULL != cli_ctx->sub) 3324 if (NULL != cli_ctx->sub)
3311 got_peer(cli_ctx->sub, &peers[i]); 3325 got_peer (cli_ctx->sub, &peers[i]);
3312 } 3326 }
3313 GNUNET_SERVICE_client_continue(cli_ctx->client); 3327 GNUNET_SERVICE_client_continue (cli_ctx->client);
3314} 3328}
3315 3329
3316 3330
@@ -3322,22 +3336,22 @@ handle_client_seed(void *cls,
3322 * receive 3336 * receive
3323 */ 3337 */
3324static void 3338static void
3325handle_client_view_request(void *cls, 3339handle_client_view_request (void *cls,
3326 const struct GNUNET_RPS_CS_DEBUG_ViewRequest *msg) 3340 const struct GNUNET_RPS_CS_DEBUG_ViewRequest *msg)
3327{ 3341{
3328 struct ClientContext *cli_ctx = cls; 3342 struct ClientContext *cli_ctx = cls;
3329 uint64_t num_updates; 3343 uint64_t num_updates;
3330 3344
3331 num_updates = ntohl(msg->num_updates); 3345 num_updates = ntohl (msg->num_updates);
3332 3346
3333 LOG(GNUNET_ERROR_TYPE_DEBUG, 3347 LOG (GNUNET_ERROR_TYPE_DEBUG,
3334 "Client requested %" PRIu64 " updates of view.\n", 3348 "Client requested %" PRIu64 " updates of view.\n",
3335 num_updates); 3349 num_updates);
3336 3350
3337 GNUNET_assert(NULL != cli_ctx); 3351 GNUNET_assert (NULL != cli_ctx);
3338 cli_ctx->view_updates_left = num_updates; 3352 cli_ctx->view_updates_left = num_updates;
3339 send_view(cli_ctx, NULL, 0); 3353 send_view (cli_ctx, NULL, 0);
3340 GNUNET_SERVICE_client_continue(cli_ctx->client); 3354 GNUNET_SERVICE_client_continue (cli_ctx->client);
3341} 3355}
3342 3356
3343 3357
@@ -3348,23 +3362,23 @@ handle_client_view_request(void *cls,
3348 * @param msg Unused 3362 * @param msg Unused
3349 */ 3363 */
3350static void 3364static void
3351handle_client_view_cancel(void *cls, 3365handle_client_view_cancel (void *cls,
3352 const struct GNUNET_MessageHeader *msg) 3366 const struct GNUNET_MessageHeader *msg)
3353{ 3367{
3354 struct ClientContext *cli_ctx = cls; 3368 struct ClientContext *cli_ctx = cls;
3355 3369
3356 (void)msg; 3370 (void) msg;
3357 3371
3358 LOG(GNUNET_ERROR_TYPE_DEBUG, 3372 LOG (GNUNET_ERROR_TYPE_DEBUG,
3359 "Client does not want to receive updates of view any more.\n"); 3373 "Client does not want to receive updates of view any more.\n");
3360 3374
3361 GNUNET_assert(NULL != cli_ctx); 3375 GNUNET_assert (NULL != cli_ctx);
3362 cli_ctx->view_updates_left = 0; 3376 cli_ctx->view_updates_left = 0;
3363 GNUNET_SERVICE_client_continue(cli_ctx->client); 3377 GNUNET_SERVICE_client_continue (cli_ctx->client);
3364 if (GNUNET_YES == cli_ctx->stream_update) 3378 if (GNUNET_YES == cli_ctx->stream_update)
3365 { 3379 {
3366 destroy_cli_ctx(cli_ctx); 3380 destroy_cli_ctx (cli_ctx);
3367 } 3381 }
3368} 3382}
3369 3383
3370 3384
@@ -3375,19 +3389,20 @@ handle_client_view_cancel(void *cls,
3375 * @param message unused 3389 * @param message unused
3376 */ 3390 */
3377static void 3391static void
3378handle_client_stream_request(void *cls, 3392handle_client_stream_request (void *cls,
3379 const struct GNUNET_RPS_CS_DEBUG_StreamRequest *msg) 3393 const struct
3394 GNUNET_RPS_CS_DEBUG_StreamRequest *msg)
3380{ 3395{
3381 struct ClientContext *cli_ctx = cls; 3396 struct ClientContext *cli_ctx = cls;
3382 3397
3383 (void)msg; 3398 (void) msg;
3384 3399
3385 LOG(GNUNET_ERROR_TYPE_DEBUG, 3400 LOG (GNUNET_ERROR_TYPE_DEBUG,
3386 "Client requested peers from biased stream.\n"); 3401 "Client requested peers from biased stream.\n");
3387 cli_ctx->stream_update = GNUNET_YES; 3402 cli_ctx->stream_update = GNUNET_YES;
3388 3403
3389 GNUNET_assert(NULL != cli_ctx); 3404 GNUNET_assert (NULL != cli_ctx);
3390 GNUNET_SERVICE_client_continue(cli_ctx->client); 3405 GNUNET_SERVICE_client_continue (cli_ctx->client);
3391} 3406}
3392 3407
3393 3408
@@ -3398,19 +3413,19 @@ handle_client_stream_request(void *cls,
3398 * @param msg unused 3413 * @param msg unused
3399 */ 3414 */
3400static void 3415static void
3401handle_client_stream_cancel(void *cls, 3416handle_client_stream_cancel (void *cls,
3402 const struct GNUNET_MessageHeader *msg) 3417 const struct GNUNET_MessageHeader *msg)
3403{ 3418{
3404 struct ClientContext *cli_ctx = cls; 3419 struct ClientContext *cli_ctx = cls;
3405 3420
3406 (void)msg; 3421 (void) msg;
3407 3422
3408 LOG(GNUNET_ERROR_TYPE_DEBUG, 3423 LOG (GNUNET_ERROR_TYPE_DEBUG,
3409 "Client canceled receiving peers from biased stream.\n"); 3424 "Client canceled receiving peers from biased stream.\n");
3410 cli_ctx->stream_update = GNUNET_NO; 3425 cli_ctx->stream_update = GNUNET_NO;
3411 3426
3412 GNUNET_assert(NULL != cli_ctx); 3427 GNUNET_assert (NULL != cli_ctx);
3413 GNUNET_SERVICE_client_continue(cli_ctx->client); 3428 GNUNET_SERVICE_client_continue (cli_ctx->client);
3414} 3429}
3415 3430
3416 3431
@@ -3421,25 +3436,26 @@ handle_client_stream_cancel(void *cls,
3421 * @param msg Message containing the necessary information 3436 * @param msg Message containing the necessary information
3422 */ 3437 */
3423static void 3438static void
3424handle_client_start_sub(void *cls, 3439handle_client_start_sub (void *cls,
3425 const struct GNUNET_RPS_CS_SubStartMessage *msg) 3440 const struct GNUNET_RPS_CS_SubStartMessage *msg)
3426{ 3441{
3427 struct ClientContext *cli_ctx = cls; 3442 struct ClientContext *cli_ctx = cls;
3428 3443
3429 LOG(GNUNET_ERROR_TYPE_DEBUG, "Client requested start of a new sub.\n"); 3444 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client requested start of a new sub.\n");
3430 if (NULL != cli_ctx->sub && 3445 if ((NULL != cli_ctx->sub)&&
3431 0 != memcmp(&cli_ctx->sub->hash, 3446 (0 != memcmp (&cli_ctx->sub->hash,
3432 &msg->hash, 3447 &msg->hash,
3433 sizeof(struct GNUNET_HashCode))) 3448 sizeof(struct GNUNET_HashCode))) )
3434 { 3449 {
3435 LOG(GNUNET_ERROR_TYPE_WARNING, "Already have a Sub with different share for this client. Remove old one, add new.\n"); 3450 LOG (GNUNET_ERROR_TYPE_WARNING,
3436 destroy_sub(cli_ctx->sub); 3451 "Already have a Sub with different share for this client. Remove old one, add new.\n");
3437 cli_ctx->sub = NULL; 3452 destroy_sub (cli_ctx->sub);
3438 } 3453 cli_ctx->sub = NULL;
3439 cli_ctx->sub = new_sub(&msg->hash, 3454 }
3440 msub->sampler_size_est_min, // TODO make api input? 3455 cli_ctx->sub = new_sub (&msg->hash,
3441 GNUNET_TIME_relative_ntoh(msg->round_interval)); 3456 msub->sampler_size_est_min, // TODO make api input?
3442 GNUNET_SERVICE_client_continue(cli_ctx->client); 3457 GNUNET_TIME_relative_ntoh (msg->round_interval));
3458 GNUNET_SERVICE_client_continue (cli_ctx->client);
3443} 3459}
3444 3460
3445 3461
@@ -3450,19 +3466,21 @@ handle_client_start_sub(void *cls,
3450 * @param msg Message containing the hash that identifies the Sub 3466 * @param msg Message containing the hash that identifies the Sub
3451 */ 3467 */
3452static void 3468static void
3453handle_client_stop_sub(void *cls, 3469handle_client_stop_sub (void *cls,
3454 const struct GNUNET_RPS_CS_SubStopMessage *msg) 3470 const struct GNUNET_RPS_CS_SubStopMessage *msg)
3455{ 3471{
3456 struct ClientContext *cli_ctx = cls; 3472 struct ClientContext *cli_ctx = cls;
3457 3473
3458 GNUNET_assert(NULL != cli_ctx->sub); 3474 GNUNET_assert (NULL != cli_ctx->sub);
3459 if (0 != memcmp(&cli_ctx->sub->hash, &msg->hash, sizeof(struct GNUNET_HashCode))) 3475 if (0 != memcmp (&cli_ctx->sub->hash, &msg->hash, sizeof(struct
3460 { 3476 GNUNET_HashCode)))
3461 LOG(GNUNET_ERROR_TYPE_WARNING, "Share of current sub and request differ!\n"); 3477 {
3462 } 3478 LOG (GNUNET_ERROR_TYPE_WARNING,
3463 destroy_sub(cli_ctx->sub); 3479 "Share of current sub and request differ!\n");
3480 }
3481 destroy_sub (cli_ctx->sub);
3464 cli_ctx->sub = NULL; 3482 cli_ctx->sub = NULL;
3465 GNUNET_SERVICE_client_continue(cli_ctx->client); 3483 GNUNET_SERVICE_client_continue (cli_ctx->client);
3466} 3484}
3467 3485
3468 3486
@@ -3476,25 +3494,25 @@ handle_client_stop_sub(void *cls,
3476 * @param msg Message - unused 3494 * @param msg Message - unused
3477 */ 3495 */
3478static void 3496static void
3479handle_peer_check(void *cls, 3497handle_peer_check (void *cls,
3480 const struct GNUNET_MessageHeader *msg) 3498 const struct GNUNET_MessageHeader *msg)
3481{ 3499{
3482 const struct ChannelCtx *channel_ctx = cls; 3500 const struct ChannelCtx *channel_ctx = cls;
3483 const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; 3501 const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id;
3484 3502
3485 (void)msg; 3503 (void) msg;
3486 3504
3487 LOG(GNUNET_ERROR_TYPE_DEBUG, 3505 LOG (GNUNET_ERROR_TYPE_DEBUG,
3488 "Received CHECK_LIVE (%s)\n", GNUNET_i2s(peer)); 3506 "Received CHECK_LIVE (%s)\n", GNUNET_i2s (peer));
3489 if (channel_ctx->peer_ctx->sub == msub) 3507 if (channel_ctx->peer_ctx->sub == msub)
3490 { 3508 {
3491 GNUNET_STATISTICS_update(stats, 3509 GNUNET_STATISTICS_update (stats,
3492 "# pending online checks", 3510 "# pending online checks",
3493 -1, 3511 -1,
3494 GNUNET_NO); 3512 GNUNET_NO);
3495 } 3513 }
3496 3514
3497 GNUNET_CADET_receive_done(channel_ctx->channel); 3515 GNUNET_CADET_receive_done (channel_ctx->channel);
3498} 3516}
3499 3517
3500 3518
@@ -3508,70 +3526,70 @@ handle_peer_check(void *cls,
3508 * @param msg Message - unused 3526 * @param msg Message - unused
3509 */ 3527 */
3510static void 3528static void
3511handle_peer_push(void *cls, 3529handle_peer_push (void *cls,
3512 const struct GNUNET_MessageHeader *msg) 3530 const struct GNUNET_MessageHeader *msg)
3513{ 3531{
3514 const struct ChannelCtx *channel_ctx = cls; 3532 const struct ChannelCtx *channel_ctx = cls;
3515 const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; 3533 const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id;
3516 3534
3517 (void)msg; 3535 (void) msg;
3518 3536
3519 // (check the proof of work (?)) 3537 // (check the proof of work (?))
3520 3538
3521 LOG(GNUNET_ERROR_TYPE_DEBUG, 3539 LOG (GNUNET_ERROR_TYPE_DEBUG,
3522 "Received PUSH (%s)\n", 3540 "Received PUSH (%s)\n",
3523 GNUNET_i2s(peer)); 3541 GNUNET_i2s (peer));
3524 if (channel_ctx->peer_ctx->sub == msub) 3542 if (channel_ctx->peer_ctx->sub == msub)
3543 {
3544 GNUNET_STATISTICS_update (stats, "# push message received", 1, GNUNET_NO);
3545 if ((NULL != map_single_hop) &&
3546 (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop,
3547 peer)))
3525 { 3548 {
3526 GNUNET_STATISTICS_update(stats, "# push message received", 1, GNUNET_NO); 3549 GNUNET_STATISTICS_update (stats,
3527 if (NULL != map_single_hop && 3550 "# push message received (multi-hop peer)",
3528 GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(map_single_hop, 3551 1,
3529 peer)) 3552 GNUNET_NO);
3530 {
3531 GNUNET_STATISTICS_update(stats,
3532 "# push message received (multi-hop peer)",
3533 1,
3534 GNUNET_NO);
3535 }
3536 } 3553 }
3554 }
3537 3555
3538 #if ENABLE_MALICIOUS 3556 #if ENABLE_MALICIOUS
3539 struct AttackedPeer *tmp_att_peer; 3557 struct AttackedPeer *tmp_att_peer;
3540 3558
3541 if ((1 == mal_type) || 3559 if ((1 == mal_type) ||
3542 (3 == mal_type)) 3560 (3 == mal_type))
3543 { /* Try to maximise representation */ 3561 { /* Try to maximise representation */
3544 tmp_att_peer = GNUNET_new(struct AttackedPeer); 3562 tmp_att_peer = GNUNET_new (struct AttackedPeer);
3545 tmp_att_peer->peer_id = *peer; 3563 tmp_att_peer->peer_id = *peer;
3546 if (NULL == att_peer_set) 3564 if (NULL == att_peer_set)
3547 att_peer_set = GNUNET_CONTAINER_multipeermap_create(1, GNUNET_NO); 3565 att_peer_set = GNUNET_CONTAINER_multipeermap_create (1, GNUNET_NO);
3548 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(att_peer_set, 3566 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set,
3549 peer)) 3567 peer))
3550 { 3568 {
3551 GNUNET_CONTAINER_DLL_insert(att_peers_head, 3569 GNUNET_CONTAINER_DLL_insert (att_peers_head,
3552 att_peers_tail, 3570 att_peers_tail,
3553 tmp_att_peer); 3571 tmp_att_peer);
3554 add_peer_array_to_set(peer, 1, att_peer_set); 3572 add_peer_array_to_set (peer, 1, att_peer_set);
3555 }
3556 else
3557 {
3558 GNUNET_free(tmp_att_peer);
3559 }
3560 } 3573 }
3574 else
3575 {
3576 GNUNET_free (tmp_att_peer);
3577 }
3578 }
3561 3579
3562 3580
3563 else if (2 == mal_type) 3581 else if (2 == mal_type)
3564 { 3582 {
3565 /* We attack one single well-known peer - simply ignore */ 3583 /* We attack one single well-known peer - simply ignore */
3566 } 3584 }
3567 #endif /* ENABLE_MALICIOUS */ 3585 #endif /* ENABLE_MALICIOUS */
3568 3586
3569 /* Add the sending peer to the push_map */ 3587 /* Add the sending peer to the push_map */
3570 CustomPeerMap_put(channel_ctx->peer_ctx->sub->push_map, peer); 3588 CustomPeerMap_put (channel_ctx->peer_ctx->sub->push_map, peer);
3571 3589
3572 GNUNET_break_op(check_peer_known(channel_ctx->peer_ctx->sub->peer_map, 3590 GNUNET_break_op (check_peer_known (channel_ctx->peer_ctx->sub->peer_map,
3573 &channel_ctx->peer_ctx->peer_id)); 3591 &channel_ctx->peer_ctx->peer_id));
3574 GNUNET_CADET_receive_done(channel_ctx->channel); 3592 GNUNET_CADET_receive_done (channel_ctx->channel);
3575} 3593}
3576 3594
3577 3595
@@ -3584,57 +3602,58 @@ handle_peer_push(void *cls,
3584 * @param msg Message - unused 3602 * @param msg Message - unused
3585 */ 3603 */
3586static void 3604static void
3587handle_peer_pull_request(void *cls, 3605handle_peer_pull_request (void *cls,
3588 const struct GNUNET_MessageHeader *msg) 3606 const struct GNUNET_MessageHeader *msg)
3589{ 3607{
3590 const struct ChannelCtx *channel_ctx = cls; 3608 const struct ChannelCtx *channel_ctx = cls;
3591 struct PeerContext *peer_ctx = channel_ctx->peer_ctx; 3609 struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
3592 const struct GNUNET_PeerIdentity *peer = &peer_ctx->peer_id; 3610 const struct GNUNET_PeerIdentity *peer = &peer_ctx->peer_id;
3593 const struct GNUNET_PeerIdentity *view_array; 3611 const struct GNUNET_PeerIdentity *view_array;
3594 3612
3595 (void)msg; 3613 (void) msg;
3596 3614
3597 LOG(GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s(peer)); 3615 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s (
3616 peer));
3598 if (peer_ctx->sub == msub) 3617 if (peer_ctx->sub == msub)
3618 {
3619 GNUNET_STATISTICS_update (stats,
3620 "# pull request message received",
3621 1,
3622 GNUNET_NO);
3623 if ((NULL != map_single_hop) &&
3624 (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop,
3625 &peer_ctx->peer_id)))
3599 { 3626 {
3600 GNUNET_STATISTICS_update(stats, 3627 GNUNET_STATISTICS_update (stats,
3601 "# pull request message received", 3628 "# pull request message received (multi-hop peer)",
3602 1, 3629 1,
3603 GNUNET_NO); 3630 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 }
3613 } 3631 }
3632 }
3614 3633
3615 #if ENABLE_MALICIOUS 3634 #if ENABLE_MALICIOUS
3616 if (1 == mal_type 3635 if ((1 == mal_type)
3617 || 3 == mal_type) 3636 ||(3 == mal_type))
3618 { /* Try to maximise representation */ 3637 { /* Try to maximise representation */
3619 send_pull_reply(peer_ctx, mal_peers, num_mal_peers); 3638 send_pull_reply (peer_ctx, mal_peers, num_mal_peers);
3620 } 3639 }
3621 3640
3622 else if (2 == mal_type) 3641 else if (2 == mal_type)
3623 { /* Try to partition network */ 3642 { /* Try to partition network */
3624 if (0 == GNUNET_memcmp(&attacked_peer, peer)) 3643 if (0 == GNUNET_memcmp (&attacked_peer, peer))
3625 { 3644 {
3626 send_pull_reply(peer_ctx, mal_peers, num_mal_peers); 3645 send_pull_reply (peer_ctx, mal_peers, num_mal_peers);
3627 }
3628 } 3646 }
3647 }
3629 #endif /* ENABLE_MALICIOUS */ 3648 #endif /* ENABLE_MALICIOUS */
3630 3649
3631 GNUNET_break_op(check_peer_known(channel_ctx->peer_ctx->sub->peer_map, 3650 GNUNET_break_op (check_peer_known (channel_ctx->peer_ctx->sub->peer_map,
3632 &channel_ctx->peer_ctx->peer_id)); 3651 &channel_ctx->peer_ctx->peer_id));
3633 GNUNET_CADET_receive_done(channel_ctx->channel); 3652 GNUNET_CADET_receive_done (channel_ctx->channel);
3634 view_array = View_get_as_array(channel_ctx->peer_ctx->sub->view); 3653 view_array = View_get_as_array (channel_ctx->peer_ctx->sub->view);
3635 send_pull_reply(peer_ctx, 3654 send_pull_reply (peer_ctx,
3636 view_array, 3655 view_array,
3637 View_size(channel_ctx->peer_ctx->sub->view)); 3656 View_size (channel_ctx->peer_ctx->sub->view));
3638} 3657}
3639 3658
3640 3659
@@ -3646,45 +3665,47 @@ handle_peer_pull_request(void *cls,
3646 * @param msg Message containing the replied peers 3665 * @param msg Message containing the replied peers
3647 */ 3666 */
3648static int 3667static int
3649check_peer_pull_reply(void *cls, 3668check_peer_pull_reply (void *cls,
3650 const struct GNUNET_RPS_P2P_PullReplyMessage *msg) 3669 const struct GNUNET_RPS_P2P_PullReplyMessage *msg)
3651{ 3670{
3652 struct ChannelCtx *channel_ctx = cls; 3671 struct ChannelCtx *channel_ctx = cls;
3653 struct PeerContext *sender_ctx = channel_ctx->peer_ctx; 3672 struct PeerContext *sender_ctx = channel_ctx->peer_ctx;
3654 3673
3655 if (sizeof(struct GNUNET_RPS_P2P_PullReplyMessage) > ntohs(msg->header.size)) 3674 if (sizeof(struct GNUNET_RPS_P2P_PullReplyMessage) > ntohs (msg->header.size))
3656 { 3675 {
3657 GNUNET_break_op(0); 3676 GNUNET_break_op (0);
3658 return GNUNET_SYSERR; 3677 return GNUNET_SYSERR;
3659 } 3678 }
3660 3679
3661 if ((ntohs(msg->header.size) - sizeof(struct GNUNET_RPS_P2P_PullReplyMessage)) / 3680 if ((ntohs (msg->header.size) - sizeof(struct
3662 sizeof(struct GNUNET_PeerIdentity) != ntohl(msg->num_peers)) 3681 GNUNET_RPS_P2P_PullReplyMessage))
3663 { 3682 / sizeof(struct GNUNET_PeerIdentity) != ntohl (msg->num_peers))
3664 LOG(GNUNET_ERROR_TYPE_ERROR, 3683 {
3665 "message says it sends %" PRIu32 " peers, have space for %lu peers\n", 3684 LOG (GNUNET_ERROR_TYPE_ERROR,
3666 ntohl(msg->num_peers), 3685 "message says it sends %" PRIu32 " peers, have space for %lu peers\n",
3667 (ntohs(msg->header.size) - sizeof(struct GNUNET_RPS_P2P_PullReplyMessage)) / 3686 ntohl (msg->num_peers),
3668 sizeof(struct GNUNET_PeerIdentity)); 3687 (ntohs (msg->header.size) - sizeof(struct
3669 GNUNET_break_op(0); 3688 GNUNET_RPS_P2P_PullReplyMessage))
3670 return GNUNET_SYSERR; 3689 / sizeof(struct GNUNET_PeerIdentity));
3671 } 3690 GNUNET_break_op (0);
3672 3691 return GNUNET_SYSERR;
3673 if (GNUNET_YES != check_peer_flag(sender_ctx->sub->peer_map, 3692 }
3674 &sender_ctx->peer_id, 3693
3675 Peers_PULL_REPLY_PENDING)) 3694 if (GNUNET_YES != check_peer_flag (sender_ctx->sub->peer_map,
3695 &sender_ctx->peer_id,
3696 Peers_PULL_REPLY_PENDING))
3697 {
3698 LOG (GNUNET_ERROR_TYPE_WARNING,
3699 "Received a pull reply from a peer (%s) we didn't request one from!\n",
3700 GNUNET_i2s (&sender_ctx->peer_id));
3701 if (sender_ctx->sub == msub)
3676 { 3702 {
3677 LOG(GNUNET_ERROR_TYPE_WARNING, 3703 GNUNET_STATISTICS_update (stats,
3678 "Received a pull reply from a peer (%s) we didn't request one from!\n", 3704 "# unrequested pull replies",
3679 GNUNET_i2s(&sender_ctx->peer_id)); 3705 1,
3680 if (sender_ctx->sub == msub) 3706 GNUNET_NO);
3681 {
3682 GNUNET_STATISTICS_update(stats,
3683 "# unrequested pull replies",
3684 1,
3685 GNUNET_NO);
3686 }
3687 } 3707 }
3708 }
3688 return GNUNET_OK; 3709 return GNUNET_OK;
3689} 3710}
3690 3711
@@ -3696,8 +3717,8 @@ check_peer_pull_reply(void *cls,
3696 * @param msg The message header 3717 * @param msg The message header
3697 */ 3718 */
3698static void 3719static void
3699handle_peer_pull_reply(void *cls, 3720handle_peer_pull_reply (void *cls,
3700 const struct GNUNET_RPS_P2P_PullReplyMessage *msg) 3721 const struct GNUNET_RPS_P2P_PullReplyMessage *msg)
3701{ 3722{
3702 const struct ChannelCtx *channel_ctx = cls; 3723 const struct ChannelCtx *channel_ctx = cls;
3703 const struct GNUNET_PeerIdentity *sender = &channel_ctx->peer_ctx->peer_id; 3724 const struct GNUNET_PeerIdentity *sender = &channel_ctx->peer_ctx->peer_id;
@@ -3710,94 +3731,96 @@ handle_peer_pull_reply(void *cls,
3710#endif /* ENABLE_MALICIOUS */ 3731#endif /* ENABLE_MALICIOUS */
3711 3732
3712 sub->pull_delays[sub->num_rounds - channel_ctx->peer_ctx->round_pull_req]++; 3733 sub->pull_delays[sub->num_rounds - channel_ctx->peer_ctx->round_pull_req]++;
3713 LOG(GNUNET_ERROR_TYPE_DEBUG, "Received PULL REPLY (%s)\n", GNUNET_i2s(sender)); 3734 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REPLY (%s)\n", GNUNET_i2s (
3735 sender));
3714 if (channel_ctx->peer_ctx->sub == msub) 3736 if (channel_ctx->peer_ctx->sub == msub)
3737 {
3738 GNUNET_STATISTICS_update (stats,
3739 "# pull reply messages received",
3740 1,
3741 GNUNET_NO);
3742 if ((NULL != map_single_hop) &&
3743 (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop,
3744 &channel_ctx->
3745 peer_ctx->peer_id)) )
3715 { 3746 {
3716 GNUNET_STATISTICS_update(stats, 3747 GNUNET_STATISTICS_update (stats,
3717 "# pull reply messages received", 3748 "# pull reply messages received (multi-hop peer)",
3718 1, 3749 1,
3719 GNUNET_NO); 3750 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 }
3729 } 3751 }
3752 }
3730 3753
3731 #if ENABLE_MALICIOUS 3754 #if ENABLE_MALICIOUS
3732 // We shouldn't even receive pull replies as we're not sending 3755 // We shouldn't even receive pull replies as we're not sending
3733 if (2 == mal_type) 3756 if (2 == mal_type)
3734 { 3757 {
3735 } 3758 }
3736 #endif /* ENABLE_MALICIOUS */ 3759 #endif /* ENABLE_MALICIOUS */
3737 3760
3738 /* Do actual logic */ 3761 /* Do actual logic */
3739 peers = (const struct GNUNET_PeerIdentity *)&msg[1]; 3762 peers = (const struct GNUNET_PeerIdentity *) &msg[1];
3740 3763
3741 LOG(GNUNET_ERROR_TYPE_DEBUG, 3764 LOG (GNUNET_ERROR_TYPE_DEBUG,
3742 "PULL REPLY received, got following %u peers:\n", 3765 "PULL REPLY received, got following %u peers:\n",
3743 ntohl(msg->num_peers)); 3766 ntohl (msg->num_peers));
3744 3767
3745 for (i = 0; i < ntohl(msg->num_peers); i++) 3768 for (i = 0; i < ntohl (msg->num_peers); i++)
3746 { 3769 {
3747 LOG(GNUNET_ERROR_TYPE_DEBUG, 3770 LOG (GNUNET_ERROR_TYPE_DEBUG,
3748 "%u. %s\n", 3771 "%u. %s\n",
3749 i, 3772 i,
3750 GNUNET_i2s(&peers[i])); 3773 GNUNET_i2s (&peers[i]));
3751 3774
3752 #if ENABLE_MALICIOUS 3775 #if ENABLE_MALICIOUS
3753 if ((NULL != att_peer_set) && 3776 if ((NULL != att_peer_set) &&
3754 (1 == mal_type || 3 == mal_type)) 3777 ((1 == mal_type) ||(3 == mal_type) ))
3755 { /* Add attacked peer to local list */ 3778 { /* Add attacked peer to local list */
3756 // TODO check if we sent a request and this was the first reply 3779 // TODO check if we sent a request and this was the first reply
3757 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(att_peer_set, 3780 if ((GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set,
3758 &peers[i]) 3781 &peers[i]))
3759 && GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(mal_peer_set, 3782 &&(GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mal_peer_set,
3760 &peers[i])) 3783 &peers[i])) )
3761 { 3784 {
3762 tmp_att_peer = GNUNET_new(struct AttackedPeer); 3785 tmp_att_peer = GNUNET_new (struct AttackedPeer);
3763 tmp_att_peer->peer_id = peers[i]; 3786 tmp_att_peer->peer_id = peers[i];
3764 GNUNET_CONTAINER_DLL_insert(att_peers_head, 3787 GNUNET_CONTAINER_DLL_insert (att_peers_head,
3765 att_peers_tail, 3788 att_peers_tail,
3766 tmp_att_peer); 3789 tmp_att_peer);
3767 add_peer_array_to_set(&peers[i], 1, att_peer_set); 3790 add_peer_array_to_set (&peers[i], 1, att_peer_set);
3768 } 3791 }
3769 continue; 3792 continue;
3770 } 3793 }
3771 #endif /* ENABLE_MALICIOUS */ 3794 #endif /* ENABLE_MALICIOUS */
3772 /* Make sure we 'know' about this peer */ 3795 /* Make sure we 'know' about this peer */
3773 (void)insert_peer(channel_ctx->peer_ctx->sub, 3796 (void) insert_peer (channel_ctx->peer_ctx->sub,
3774 &peers[i]); 3797 &peers[i]);
3775 3798
3776 if (GNUNET_YES == check_peer_valid(channel_ctx->peer_ctx->sub->valid_peers, 3799 if (GNUNET_YES == check_peer_valid (channel_ctx->peer_ctx->sub->valid_peers,
3777 &peers[i])) 3800 &peers[i]))
3778 { 3801 {
3779 CustomPeerMap_put(channel_ctx->peer_ctx->sub->pull_map, 3802 CustomPeerMap_put (channel_ctx->peer_ctx->sub->pull_map,
3780 &peers[i]); 3803 &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 }
3790 } 3804 }
3791 3805 else
3792 UNSET_PEER_FLAG(get_peer_ctx(channel_ctx->peer_ctx->sub->peer_map, 3806 {
3793 sender), 3807 schedule_operation (channel_ctx->peer_ctx,
3794 Peers_PULL_REPLY_PENDING); 3808 insert_in_pull_map,
3795 clean_peer(channel_ctx->peer_ctx->sub, 3809 channel_ctx->peer_ctx->sub); /* cls */
3796 sender); 3810 (void) issue_peer_online_check (channel_ctx->peer_ctx->sub,
3797 3811 &peers[i]);
3798 GNUNET_break_op(check_peer_known(channel_ctx->peer_ctx->sub->peer_map, 3812 }
3799 sender)); 3813 }
3800 GNUNET_CADET_receive_done(channel_ctx->channel); 3814
3815 UNSET_PEER_FLAG (get_peer_ctx (channel_ctx->peer_ctx->sub->peer_map,
3816 sender),
3817 Peers_PULL_REPLY_PENDING);
3818 clean_peer (channel_ctx->peer_ctx->sub,
3819 sender);
3820
3821 GNUNET_break_op (check_peer_known (channel_ctx->peer_ctx->sub->peer_map,
3822 sender));
3823 GNUNET_CADET_receive_done (channel_ctx->channel);
3801} 3824}
3802 3825
3803 3826
@@ -3812,8 +3835,8 @@ handle_peer_pull_reply(void *cls,
3812 * @param spread the inverse amount of deviation from the mean 3835 * @param spread the inverse amount of deviation from the mean
3813 */ 3836 */
3814static struct GNUNET_TIME_Relative 3837static struct GNUNET_TIME_Relative
3815compute_rand_delay(struct GNUNET_TIME_Relative mean, 3838compute_rand_delay (struct GNUNET_TIME_Relative mean,
3816 unsigned int spread) 3839 unsigned int spread)
3817{ 3840{
3818 struct GNUNET_TIME_Relative half_interval; 3841 struct GNUNET_TIME_Relative half_interval;
3819 struct GNUNET_TIME_Relative ret; 3842 struct GNUNET_TIME_Relative ret;
@@ -3821,30 +3844,32 @@ compute_rand_delay(struct GNUNET_TIME_Relative mean,
3821 unsigned int max_rand_delay; 3844 unsigned int max_rand_delay;
3822 3845
3823 if (0 == spread) 3846 if (0 == spread)
3824 { 3847 {
3825 LOG(GNUNET_ERROR_TYPE_WARNING, 3848 LOG (GNUNET_ERROR_TYPE_WARNING,
3826 "Not accepting spread of 0\n"); 3849 "Not accepting spread of 0\n");
3827 GNUNET_break(0); 3850 GNUNET_break (0);
3828 GNUNET_assert(0); 3851 GNUNET_assert (0);
3829 } 3852 }
3830 GNUNET_assert(0 != mean.rel_value_us); 3853 GNUNET_assert (0 != mean.rel_value_us);
3831 3854
3832 /* Compute random time value between spread * mean and spread * mean */ 3855 /* Compute random time value between spread * mean and spread * mean */
3833 half_interval = GNUNET_TIME_relative_divide(mean, spread); 3856 half_interval = GNUNET_TIME_relative_divide (mean, spread);
3834 3857
3835 max_rand_delay = GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us / mean.rel_value_us * (2 / spread); 3858 max_rand_delay = GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us
3859 / mean.rel_value_us * (2 / spread);
3836 /** 3860 /**
3837 * Compute random value between (0 and 1) * round_interval 3861 * Compute random value between (0 and 1) * round_interval
3838 * via multiplying round_interval with a 'fraction' (0 to value)/value 3862 * via multiplying round_interval with a 'fraction' (0 to value)/value
3839 */ 3863 */
3840 rand_delay = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, max_rand_delay); 3864 rand_delay = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
3841 ret = GNUNET_TIME_relative_saturating_multiply(mean, rand_delay); 3865 max_rand_delay);
3842 ret = GNUNET_TIME_relative_divide(ret, max_rand_delay); 3866 ret = GNUNET_TIME_relative_saturating_multiply (mean, rand_delay);
3843 ret = GNUNET_TIME_relative_add(ret, half_interval); 3867 ret = GNUNET_TIME_relative_divide (ret, max_rand_delay);
3868 ret = GNUNET_TIME_relative_add (ret, half_interval);
3844 3869
3845 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == ret.rel_value_us) 3870 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == ret.rel_value_us)
3846 LOG(GNUNET_ERROR_TYPE_WARNING, 3871 LOG (GNUNET_ERROR_TYPE_WARNING,
3847 "Returning FOREVER_REL\n"); 3872 "Returning FOREVER_REL\n");
3848 3873
3849 return ret; 3874 return ret;
3850} 3875}
@@ -3856,41 +3881,41 @@ compute_rand_delay(struct GNUNET_TIME_Relative mean,
3856 * @param peer_ctx Context to the peer to send request to 3881 * @param peer_ctx Context to the peer to send request to
3857 */ 3882 */
3858static void 3883static void
3859send_pull_request(struct PeerContext *peer_ctx) 3884send_pull_request (struct PeerContext *peer_ctx)
3860{ 3885{
3861 struct GNUNET_MQ_Envelope *ev; 3886 struct GNUNET_MQ_Envelope *ev;
3862 3887
3863 GNUNET_assert(GNUNET_NO == check_peer_flag(peer_ctx->sub->peer_map, 3888 GNUNET_assert (GNUNET_NO == check_peer_flag (peer_ctx->sub->peer_map,
3864 &peer_ctx->peer_id, 3889 &peer_ctx->peer_id,
3865 Peers_PULL_REPLY_PENDING)); 3890 Peers_PULL_REPLY_PENDING));
3866 SET_PEER_FLAG(peer_ctx, 3891 SET_PEER_FLAG (peer_ctx,
3867 Peers_PULL_REPLY_PENDING); 3892 Peers_PULL_REPLY_PENDING);
3868 peer_ctx->round_pull_req = peer_ctx->sub->num_rounds; 3893 peer_ctx->round_pull_req = peer_ctx->sub->num_rounds;
3869 3894
3870 LOG(GNUNET_ERROR_TYPE_DEBUG, 3895 LOG (GNUNET_ERROR_TYPE_DEBUG,
3871 "Going to send PULL REQUEST to peer %s.\n", 3896 "Going to send PULL REQUEST to peer %s.\n",
3872 GNUNET_i2s(&peer_ctx->peer_id)); 3897 GNUNET_i2s (&peer_ctx->peer_id));
3873 3898
3874 ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST); 3899 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST);
3875 send_message(peer_ctx, 3900 send_message (peer_ctx,
3876 ev, 3901 ev,
3877 "PULL REQUEST"); 3902 "PULL REQUEST");
3878 if (peer_ctx->sub) 3903 if (peer_ctx->sub)
3904 {
3905 GNUNET_STATISTICS_update (stats,
3906 "# pull request send issued",
3907 1,
3908 GNUNET_NO);
3909 if ((NULL != map_single_hop) &&
3910 (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop,
3911 &peer_ctx->peer_id)))
3879 { 3912 {
3880 GNUNET_STATISTICS_update(stats, 3913 GNUNET_STATISTICS_update (stats,
3881 "# pull request send issued", 3914 "# pull request send issued (multi-hop peer)",
3882 1, 3915 1,
3883 GNUNET_NO); 3916 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 }
3893 } 3917 }
3918 }
3894} 3919}
3895 3920
3896 3921
@@ -3900,32 +3925,32 @@ send_pull_request(struct PeerContext *peer_ctx)
3900 * @param peer_ctx Context of peer to send push to 3925 * @param peer_ctx Context of peer to send push to
3901 */ 3926 */
3902static void 3927static void
3903send_push(struct PeerContext *peer_ctx) 3928send_push (struct PeerContext *peer_ctx)
3904{ 3929{
3905 struct GNUNET_MQ_Envelope *ev; 3930 struct GNUNET_MQ_Envelope *ev;
3906 3931
3907 LOG(GNUNET_ERROR_TYPE_DEBUG, 3932 LOG (GNUNET_ERROR_TYPE_DEBUG,
3908 "Going to send PUSH to peer %s.\n", 3933 "Going to send PUSH to peer %s.\n",
3909 GNUNET_i2s(&peer_ctx->peer_id)); 3934 GNUNET_i2s (&peer_ctx->peer_id));
3910 3935
3911 ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_RPS_PP_PUSH); 3936 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PUSH);
3912 send_message(peer_ctx, ev, "PUSH"); 3937 send_message (peer_ctx, ev, "PUSH");
3913 if (peer_ctx->sub) 3938 if (peer_ctx->sub)
3939 {
3940 GNUNET_STATISTICS_update (stats,
3941 "# push send issued",
3942 1,
3943 GNUNET_NO);
3944 if ((NULL != map_single_hop) &&
3945 (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop,
3946 &peer_ctx->peer_id)))
3914 { 3947 {
3915 GNUNET_STATISTICS_update(stats, 3948 GNUNET_STATISTICS_update (stats,
3916 "# push send issued", 3949 "# push send issued (multi-hop peer)",
3917 1, 3950 1,
3918 GNUNET_NO); 3951 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 }
3928 } 3952 }
3953 }
3929} 3954}
3930 3955
3931 3956
@@ -3941,25 +3966,25 @@ send_push(struct PeerContext *peer_ctx)
3941 * @return #GNUNET_OK if @a msg is well-formed 3966 * @return #GNUNET_OK if @a msg is well-formed
3942 */ 3967 */
3943static int 3968static int
3944check_client_act_malicious(void *cls, 3969check_client_act_malicious (void *cls,
3945 const struct GNUNET_RPS_CS_ActMaliciousMessage *msg) 3970 const struct GNUNET_RPS_CS_ActMaliciousMessage *msg)
3946{ 3971{
3947 struct ClientContext *cli_ctx = cls; 3972 struct ClientContext *cli_ctx = cls;
3948 uint16_t msize = ntohs(msg->header.size); 3973 uint16_t msize = ntohs (msg->header.size);
3949 uint32_t num_peers = ntohl(msg->num_peers); 3974 uint32_t num_peers = ntohl (msg->num_peers);
3950 3975
3951 msize -= sizeof(struct GNUNET_RPS_CS_ActMaliciousMessage); 3976 msize -= sizeof(struct GNUNET_RPS_CS_ActMaliciousMessage);
3952 if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) || 3977 if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) ||
3953 (msize % sizeof(struct GNUNET_PeerIdentity) != 0)) 3978 (msize % sizeof(struct GNUNET_PeerIdentity) != 0))
3954 { 3979 {
3955 LOG(GNUNET_ERROR_TYPE_ERROR, 3980 LOG (GNUNET_ERROR_TYPE_ERROR,
3956 "message says it sends %" PRIu32 " peers, have space for %lu peers\n", 3981 "message says it sends %" PRIu32 " peers, have space for %lu peers\n",
3957 ntohl(msg->num_peers), 3982 ntohl (msg->num_peers),
3958 (msize / sizeof(struct GNUNET_PeerIdentity))); 3983 (msize / sizeof(struct GNUNET_PeerIdentity)));
3959 GNUNET_break(0); 3984 GNUNET_break (0);
3960 GNUNET_SERVICE_client_drop(cli_ctx->client); 3985 GNUNET_SERVICE_client_drop (cli_ctx->client);
3961 return GNUNET_SYSERR; 3986 return GNUNET_SYSERR;
3962 } 3987 }
3963 return GNUNET_OK; 3988 return GNUNET_OK;
3964} 3989}
3965 3990
@@ -3971,8 +3996,9 @@ check_client_act_malicious(void *cls,
3971 * @param msg The message header 3996 * @param msg The message header
3972 */ 3997 */
3973static void 3998static void
3974handle_client_act_malicious(void *cls, 3999handle_client_act_malicious (void *cls,
3975 const struct GNUNET_RPS_CS_ActMaliciousMessage *msg) 4000 const struct
4001 GNUNET_RPS_CS_ActMaliciousMessage *msg)
3976{ 4002{
3977 struct ClientContext *cli_ctx = cls; 4003 struct ClientContext *cli_ctx = cls;
3978 struct GNUNET_PeerIdentity *peers; 4004 struct GNUNET_PeerIdentity *peers;
@@ -3983,100 +4009,100 @@ handle_client_act_malicious(void *cls,
3983 if (NULL == sub) 4009 if (NULL == sub)
3984 sub = msub; 4010 sub = msub;
3985 /* Do actual logic */ 4011 /* Do actual logic */
3986 peers = (struct GNUNET_PeerIdentity *)&msg[1]; 4012 peers = (struct GNUNET_PeerIdentity *) &msg[1];
3987 mal_type = ntohl(msg->type); 4013 mal_type = ntohl (msg->type);
3988 if (NULL == mal_peer_set) 4014 if (NULL == mal_peer_set)
3989 mal_peer_set = GNUNET_CONTAINER_multipeermap_create(1, GNUNET_NO); 4015 mal_peer_set = GNUNET_CONTAINER_multipeermap_create (1, GNUNET_NO);
3990 4016
3991 LOG(GNUNET_ERROR_TYPE_DEBUG, 4017 LOG (GNUNET_ERROR_TYPE_DEBUG,
3992 "Now acting malicious type %" PRIu32 ", got %" PRIu32 " peers.\n", 4018 "Now acting malicious type %" PRIu32 ", got %" PRIu32 " peers.\n",
3993 mal_type, 4019 mal_type,
3994 ntohl(msg->num_peers)); 4020 ntohl (msg->num_peers));
3995 4021
3996 if (1 == mal_type) 4022 if (1 == mal_type)
3997 { /* Try to maximise representation */ 4023 { /* Try to maximise representation */
3998 /* Add other malicious peers to those we already know */ 4024 /* Add other malicious peers to those we already know */
3999 4025
4000 num_mal_peers_sent = ntohl(msg->num_peers); 4026 num_mal_peers_sent = ntohl (msg->num_peers);
4001 num_mal_peers_old = num_mal_peers; 4027 num_mal_peers_old = num_mal_peers;
4002 GNUNET_array_grow(mal_peers, 4028 GNUNET_array_grow (mal_peers,
4003 num_mal_peers, 4029 num_mal_peers,
4004 num_mal_peers + num_mal_peers_sent); 4030 num_mal_peers + num_mal_peers_sent);
4005 GNUNET_memcpy(&mal_peers[num_mal_peers_old], 4031 GNUNET_memcpy (&mal_peers[num_mal_peers_old],
4006 peers, 4032 peers,
4007 num_mal_peers_sent * sizeof(struct GNUNET_PeerIdentity)); 4033 num_mal_peers_sent * sizeof(struct GNUNET_PeerIdentity));
4008 4034
4009 /* Add all mal peers to mal_peer_set */ 4035 /* Add all mal peers to mal_peer_set */
4010 add_peer_array_to_set(&mal_peers[num_mal_peers_old], 4036 add_peer_array_to_set (&mal_peers[num_mal_peers_old],
4011 num_mal_peers_sent, 4037 num_mal_peers_sent,
4012 mal_peer_set); 4038 mal_peer_set);
4013 4039
4014 /* Substitute do_round () with do_mal_round () */ 4040 /* Substitute do_round () with do_mal_round () */
4015 GNUNET_assert(NULL != sub->do_round_task); 4041 GNUNET_assert (NULL != sub->do_round_task);
4016 GNUNET_SCHEDULER_cancel(sub->do_round_task); 4042 GNUNET_SCHEDULER_cancel (sub->do_round_task);
4017 sub->do_round_task = GNUNET_SCHEDULER_add_now(&do_mal_round, sub); 4043 sub->do_round_task = GNUNET_SCHEDULER_add_now (&do_mal_round, sub);
4018 } 4044 }
4019 4045
4020 else if ((2 == mal_type) || 4046 else if ((2 == mal_type) ||
4021 (3 == mal_type)) 4047 (3 == mal_type))
4022 { /* Try to partition the network */ 4048 { /* Try to partition the network */
4023 /* Add other malicious peers to those we already know */ 4049 /* Add other malicious peers to those we already know */
4024 4050
4025 num_mal_peers_sent = ntohl(msg->num_peers) - 1; 4051 num_mal_peers_sent = ntohl (msg->num_peers) - 1;
4026 num_mal_peers_old = num_mal_peers; 4052 num_mal_peers_old = num_mal_peers;
4027 GNUNET_assert(GNUNET_MAX_MALLOC_CHECKED > num_mal_peers_sent); 4053 GNUNET_assert (GNUNET_MAX_MALLOC_CHECKED > num_mal_peers_sent);
4028 GNUNET_array_grow(mal_peers, 4054 GNUNET_array_grow (mal_peers,
4029 num_mal_peers, 4055 num_mal_peers,
4030 num_mal_peers + num_mal_peers_sent); 4056 num_mal_peers + num_mal_peers_sent);
4031 if (NULL != mal_peers && 4057 if ((NULL != mal_peers) &&
4032 0 != num_mal_peers) 4058 (0 != num_mal_peers) )
4033 { 4059 {
4034 GNUNET_memcpy(&mal_peers[num_mal_peers_old], 4060 GNUNET_memcpy (&mal_peers[num_mal_peers_old],
4035 peers, 4061 peers,
4036 num_mal_peers_sent * sizeof(struct GNUNET_PeerIdentity)); 4062 num_mal_peers_sent * sizeof(struct GNUNET_PeerIdentity));
4037 4063
4038 /* Add all mal peers to mal_peer_set */ 4064 /* Add all mal peers to mal_peer_set */
4039 add_peer_array_to_set(&mal_peers[num_mal_peers_old], 4065 add_peer_array_to_set (&mal_peers[num_mal_peers_old],
4040 num_mal_peers_sent, 4066 num_mal_peers_sent,
4041 mal_peer_set); 4067 mal_peer_set);
4042 }
4043
4044 /* Store the one attacked peer */
4045 GNUNET_memcpy(&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 }
4053
4054 LOG(GNUNET_ERROR_TYPE_DEBUG,
4055 "Attacked peer is %s\n",
4056 GNUNET_i2s(&attacked_peer));
4057
4058 /* Substitute do_round () with do_mal_round () */
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 }
4065 } 4068 }
4066 else if (0 == mal_type)
4067 { /* Stop acting malicious */
4068 GNUNET_array_grow(mal_peers, num_mal_peers, 0);
4069 4069
4070 /* Substitute do_mal_round () with do_round () */ 4070 /* Store the one attacked peer */
4071 GNUNET_SCHEDULER_cancel(sub->do_round_task); 4071 GNUNET_memcpy (&attacked_peer,
4072 sub->do_round_task = GNUNET_SCHEDULER_add_now(&do_round, sub); 4072 &msg->attacked_peer,
4073 sizeof(struct GNUNET_PeerIdentity));
4074 /* Set the flag of the attacked peer to valid to avoid problems */
4075 if (GNUNET_NO == check_peer_known (sub->peer_map, &attacked_peer))
4076 {
4077 (void) issue_peer_online_check (sub, &attacked_peer);
4073 } 4078 }
4074 else 4079
4080 LOG (GNUNET_ERROR_TYPE_DEBUG,
4081 "Attacked peer is %s\n",
4082 GNUNET_i2s (&attacked_peer));
4083
4084 /* Substitute do_round () with do_mal_round () */
4085 if (NULL != sub->do_round_task)
4075 { 4086 {
4076 GNUNET_break(0); 4087 /* Probably in shutdown */
4077 GNUNET_SERVICE_client_continue(cli_ctx->client); 4088 GNUNET_SCHEDULER_cancel (sub->do_round_task);
4089 sub->do_round_task = GNUNET_SCHEDULER_add_now (&do_mal_round, sub);
4078 } 4090 }
4079 GNUNET_SERVICE_client_continue(cli_ctx->client); 4091 }
4092 else if (0 == mal_type)
4093 { /* Stop acting malicious */
4094 GNUNET_array_grow (mal_peers, num_mal_peers, 0);
4095
4096 /* Substitute do_mal_round () with do_round () */
4097 GNUNET_SCHEDULER_cancel (sub->do_round_task);
4098 sub->do_round_task = GNUNET_SCHEDULER_add_now (&do_round, sub);
4099 }
4100 else
4101 {
4102 GNUNET_break (0);
4103 GNUNET_SERVICE_client_continue (cli_ctx->client);
4104 }
4105 GNUNET_SERVICE_client_continue (cli_ctx->client);
4080} 4106}
4081 4107
4082 4108
@@ -4088,7 +4114,7 @@ handle_client_act_malicious(void *cls,
4088 * @param cls Closure - Sub 4114 * @param cls Closure - Sub
4089 */ 4115 */
4090static void 4116static void
4091do_mal_round(void *cls) 4117do_mal_round (void *cls)
4092{ 4118{
4093 uint32_t num_pushes; 4119 uint32_t num_pushes;
4094 uint32_t i; 4120 uint32_t i;
@@ -4096,119 +4122,119 @@ do_mal_round(void *cls)
4096 struct AttackedPeer *tmp_att_peer; 4122 struct AttackedPeer *tmp_att_peer;
4097 struct Sub *sub = cls; 4123 struct Sub *sub = cls;
4098 4124
4099 LOG(GNUNET_ERROR_TYPE_DEBUG, 4125 LOG (GNUNET_ERROR_TYPE_DEBUG,
4100 "Going to execute next round maliciously type %" PRIu32 ".\n", 4126 "Going to execute next round maliciously type %" PRIu32 ".\n",
4101 mal_type); 4127 mal_type);
4102 sub->do_round_task = NULL; 4128 sub->do_round_task = NULL;
4103 GNUNET_assert(mal_type <= 3); 4129 GNUNET_assert (mal_type <= 3);
4104 /* Do malicious actions */ 4130 /* Do malicious actions */
4105 if (1 == mal_type) 4131 if (1 == mal_type)
4106 { /* Try to maximise representation */ 4132 { /* Try to maximise representation */
4107 /* The maximum of pushes we're going to send this round */ 4133 /* The maximum of pushes we're going to send this round */
4108 num_pushes = GNUNET_MIN(GNUNET_MIN(push_limit, 4134 num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit,
4109 num_attacked_peers), 4135 num_attacked_peers),
4110 GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE); 4136 GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE);
4111 4137
4112 LOG(GNUNET_ERROR_TYPE_DEBUG, 4138 LOG (GNUNET_ERROR_TYPE_DEBUG,
4113 "Going to send %" PRIu32 " pushes\n", 4139 "Going to send %" PRIu32 " pushes\n",
4114 num_pushes); 4140 num_pushes);
4115 4141
4116 /* Send PUSHes to attacked peers */ 4142 /* Send PUSHes to attacked peers */
4117 for (i = 0; i < num_pushes; i++) 4143 for (i = 0; i < num_pushes; i++)
4118 { 4144 {
4119 if (att_peers_tail == att_peer_index) 4145 if (att_peers_tail == att_peer_index)
4120 att_peer_index = att_peers_head; 4146 att_peer_index = att_peers_head;
4121 else 4147 else
4122 att_peer_index = att_peer_index->next; 4148 att_peer_index = att_peer_index->next;
4123 4149
4124 send_push(get_peer_ctx(sub->peer_map, &att_peer_index->peer_id)); 4150 send_push (get_peer_ctx (sub->peer_map, &att_peer_index->peer_id));
4125 } 4151 }
4126 4152
4127 /* Send PULLs to some peers to learn about additional peers to attack */ 4153 /* Send PULLs to some peers to learn about additional peers to attack */
4128 tmp_att_peer = att_peer_index; 4154 tmp_att_peer = att_peer_index;
4129 for (i = 0; i < num_pushes * alpha; i++) 4155 for (i = 0; i < num_pushes * alpha; i++)
4130 { 4156 {
4131 if (att_peers_tail == tmp_att_peer) 4157 if (att_peers_tail == tmp_att_peer)
4132 tmp_att_peer = att_peers_head; 4158 tmp_att_peer = att_peers_head;
4133 else 4159 else
4134 att_peer_index = tmp_att_peer->next; 4160 att_peer_index = tmp_att_peer->next;
4135 4161
4136 send_pull_request(get_peer_ctx(sub->peer_map, &tmp_att_peer->peer_id)); 4162 send_pull_request (get_peer_ctx (sub->peer_map, &tmp_att_peer->peer_id));
4137 }
4138 } 4163 }
4164 }
4139 4165
4140 4166
4141 else if (2 == mal_type) 4167 else if (2 == mal_type)
4142 { /** 4168 { /**
4143 * Try to partition the network 4169 * Try to partition the network
4144 * Send as many pushes to the attacked peer as possible 4170 * Send as many pushes to the attacked peer as possible
4145 * That is one push per round as it will ignore more. 4171 * That is one push per round as it will ignore more.
4146 */ 4172 */
4147 (void)issue_peer_online_check(sub, &attacked_peer); 4173 (void) issue_peer_online_check (sub, &attacked_peer);
4148 if (GNUNET_YES == check_peer_flag(sub->peer_map, 4174 if (GNUNET_YES == check_peer_flag (sub->peer_map,
4149 &attacked_peer, 4175 &attacked_peer,
4150 Peers_ONLINE)) 4176 Peers_ONLINE))
4151 send_push(get_peer_ctx(sub->peer_map, &attacked_peer)); 4177 send_push (get_peer_ctx (sub->peer_map, &attacked_peer));
4152 } 4178 }
4153 4179
4154 4180
4155 if (3 == mal_type) 4181 if (3 == mal_type)
4156 { /* Combined attack */ 4182 { /* Combined attack */
4157 /* Send PUSH to attacked peers */ 4183 /* Send PUSH to attacked peers */
4158 if (GNUNET_YES == check_peer_known(sub->peer_map, &attacked_peer)) 4184 if (GNUNET_YES == check_peer_known (sub->peer_map, &attacked_peer))
4159 { 4185 {
4160 (void)issue_peer_online_check(sub, &attacked_peer); 4186 (void) issue_peer_online_check (sub, &attacked_peer);
4161 if (GNUNET_YES == check_peer_flag(sub->peer_map, 4187 if (GNUNET_YES == check_peer_flag (sub->peer_map,
4162 &attacked_peer, 4188 &attacked_peer,
4163 Peers_ONLINE)) 4189 Peers_ONLINE))
4164 { 4190 {
4165 LOG(GNUNET_ERROR_TYPE_DEBUG, 4191 LOG (GNUNET_ERROR_TYPE_DEBUG,
4166 "Goding to send push to attacked peer (%s)\n", 4192 "Goding to send push to attacked peer (%s)\n",
4167 GNUNET_i2s(&attacked_peer)); 4193 GNUNET_i2s (&attacked_peer));
4168 send_push(get_peer_ctx(sub->peer_map, &attacked_peer)); 4194 send_push (get_peer_ctx (sub->peer_map, &attacked_peer));
4169 } 4195 }
4170 } 4196 }
4171 (void)issue_peer_online_check(sub, &attacked_peer); 4197 (void) issue_peer_online_check (sub, &attacked_peer);
4172 4198
4173 /* The maximum of pushes we're going to send this round */ 4199 /* The maximum of pushes we're going to send this round */
4174 num_pushes = GNUNET_MIN(GNUNET_MIN(push_limit - 1, 4200 num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit - 1,
4175 num_attacked_peers), 4201 num_attacked_peers),
4176 GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE); 4202 GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE);
4177 4203
4178 LOG(GNUNET_ERROR_TYPE_DEBUG, 4204 LOG (GNUNET_ERROR_TYPE_DEBUG,
4179 "Going to send %" PRIu32 " pushes\n", 4205 "Going to send %" PRIu32 " pushes\n",
4180 num_pushes); 4206 num_pushes);
4181 4207
4182 for (i = 0; i < num_pushes; i++) 4208 for (i = 0; i < num_pushes; i++)
4183 { 4209 {
4184 if (att_peers_tail == att_peer_index) 4210 if (att_peers_tail == att_peer_index)
4185 att_peer_index = att_peers_head; 4211 att_peer_index = att_peers_head;
4186 else 4212 else
4187 att_peer_index = att_peer_index->next; 4213 att_peer_index = att_peer_index->next;
4188 4214
4189 send_push(get_peer_ctx(sub->peer_map, &att_peer_index->peer_id)); 4215 send_push (get_peer_ctx (sub->peer_map, &att_peer_index->peer_id));
4190 }
4191
4192 /* Send PULLs to some peers to learn about additional peers to attack */
4193 tmp_att_peer = att_peer_index;
4194 for (i = 0; i < num_pushes * alpha; i++)
4195 {
4196 if (att_peers_tail == tmp_att_peer)
4197 tmp_att_peer = att_peers_head;
4198 else
4199 att_peer_index = tmp_att_peer->next;
4200
4201 send_pull_request(get_peer_ctx(sub->peer_map, &tmp_att_peer->peer_id));
4202 }
4203 } 4216 }
4204 4217
4218 /* Send PULLs to some peers to learn about additional peers to attack */
4219 tmp_att_peer = att_peer_index;
4220 for (i = 0; i < num_pushes * alpha; i++)
4221 {
4222 if (att_peers_tail == tmp_att_peer)
4223 tmp_att_peer = att_peers_head;
4224 else
4225 att_peer_index = tmp_att_peer->next;
4226
4227 send_pull_request (get_peer_ctx (sub->peer_map, &tmp_att_peer->peer_id));
4228 }
4229 }
4230
4205 /* Schedule next round */ 4231 /* Schedule next round */
4206 time_next_round = compute_rand_delay(sub->round_interval, 2); 4232 time_next_round = compute_rand_delay (sub->round_interval, 2);
4207 4233
4208 GNUNET_assert(NULL == sub->do_round_task); 4234 GNUNET_assert (NULL == sub->do_round_task);
4209 sub->do_round_task = GNUNET_SCHEDULER_add_delayed(time_next_round, 4235 sub->do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round,
4210 &do_mal_round, sub); 4236 &do_mal_round, sub);
4211 LOG(GNUNET_ERROR_TYPE_DEBUG, "Finished round\n"); 4237 LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n");
4212} 4238}
4213#endif /* ENABLE_MALICIOUS */ 4239#endif /* ENABLE_MALICIOUS */
4214 4240
@@ -4221,7 +4247,7 @@ do_mal_round(void *cls)
4221 * @param cls Closure - Sub 4247 * @param cls Closure - Sub
4222 */ 4248 */
4223static void 4249static void
4224do_round(void *cls) 4250do_round (void *cls)
4225{ 4251{
4226 unsigned int i; 4252 unsigned int i;
4227 const struct GNUNET_PeerIdentity *view_array; 4253 const struct GNUNET_PeerIdentity *view_array;
@@ -4235,308 +4261,327 @@ do_round(void *cls)
4235 struct Sub *sub = cls; 4261 struct Sub *sub = cls;
4236 4262
4237 sub->num_rounds++; 4263 sub->num_rounds++;
4238 LOG(GNUNET_ERROR_TYPE_DEBUG, 4264 LOG (GNUNET_ERROR_TYPE_DEBUG,
4239 "Going to execute next round.\n"); 4265 "Going to execute next round.\n");
4240 if (sub == msub) 4266 if (sub == msub)
4241 { 4267 {
4242 GNUNET_STATISTICS_update(stats, "# rounds", 1, GNUNET_NO); 4268 GNUNET_STATISTICS_update (stats, "# rounds", 1, GNUNET_NO);
4243 } 4269 }
4244 sub->do_round_task = NULL; 4270 sub->do_round_task = NULL;
4245#ifdef TO_FILE_FULL 4271#ifdef TO_FILE_FULL
4246 to_file(sub->file_name_view_log, 4272 to_file (sub->file_name_view_log,
4247 "___ new round ___"); 4273 "___ new round ___");
4248#endif /* TO_FILE_FULL */ 4274#endif /* TO_FILE_FULL */
4249 view_array = View_get_as_array(sub->view); 4275 view_array = View_get_as_array (sub->view);
4250 for (i = 0; i < View_size(sub->view); i++) 4276 for (i = 0; i < View_size (sub->view); i++)
4251 { 4277 {
4252 LOG(GNUNET_ERROR_TYPE_DEBUG, 4278 LOG (GNUNET_ERROR_TYPE_DEBUG,
4253 "\t%s\n", GNUNET_i2s(&view_array[i])); 4279 "\t%s\n", GNUNET_i2s (&view_array[i]));
4254#ifdef TO_FILE_FULL 4280#ifdef TO_FILE_FULL
4255 to_file(sub->file_name_view_log, 4281 to_file (sub->file_name_view_log,
4256 "=%s\t(do round)", 4282 "=%s\t(do round)",
4257 GNUNET_i2s_full(&view_array[i])); 4283 GNUNET_i2s_full (&view_array[i]));
4258#endif /* TO_FILE_FULL */ 4284#endif /* TO_FILE_FULL */
4259 } 4285 }
4260 4286
4261 4287
4262 /* Send pushes and pull requests */ 4288 /* Send pushes and pull requests */
4263 if (0 < View_size(sub->view)) 4289 if (0 < View_size (sub->view))
4290 {
4291 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG,
4292 View_size (sub->view));
4293
4294 /* Send PUSHes */
4295 a_peers = ceil (alpha * View_size (sub->view));
4296
4297 LOG (GNUNET_ERROR_TYPE_DEBUG,
4298 "Going to send pushes to %u (ceil (%f * %u)) peers.\n",
4299 a_peers, alpha, View_size (sub->view));
4300 for (i = 0; i < a_peers; i++)
4264 { 4301 {
4265 permut = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_STRONG, 4302 peer = view_array[permut[i]];
4266 View_size(sub->view)); 4303 // FIXME if this fails schedule/loop this for later
4267 4304 send_push (get_peer_ctx (sub->peer_map, &peer));
4268 /* Send PUSHes */
4269 a_peers = ceil(alpha * View_size(sub->view));
4270
4271 LOG(GNUNET_ERROR_TYPE_DEBUG,
4272 "Going to send pushes to %u (ceil (%f * %u)) peers.\n",
4273 a_peers, alpha, View_size(sub->view));
4274 for (i = 0; i < a_peers; i++)
4275 {
4276 peer = view_array[permut[i]];
4277 // FIXME if this fails schedule/loop this for later
4278 send_push(get_peer_ctx(sub->peer_map, &peer));
4279 }
4280
4281 /* Send PULL requests */
4282 b_peers = ceil(beta * View_size(sub->view));
4283 first_border = a_peers;
4284 second_border = a_peers + b_peers;
4285 if (second_border > View_size(sub->view))
4286 {
4287 first_border = View_size(sub->view) - b_peers;
4288 second_border = View_size(sub->view);
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 }
4303
4304 GNUNET_free(permut);
4305 permut = NULL;
4306 } 4305 }
4307 4306
4307 /* Send PULL requests */
4308 b_peers = ceil (beta * View_size (sub->view));
4309 first_border = a_peers;
4310 second_border = a_peers + b_peers;
4311 if (second_border > View_size (sub->view))
4312 {
4313 first_border = View_size (sub->view) - b_peers;
4314 second_border = View_size (sub->view);
4315 }
4316 LOG (GNUNET_ERROR_TYPE_DEBUG,
4317 "Going to send pulls to %u (ceil (%f * %u)) peers.\n",
4318 b_peers, beta, View_size (sub->view));
4319 for (i = first_border; i < second_border; i++)
4320 {
4321 peer = view_array[permut[i]];
4322 if (GNUNET_NO == check_peer_flag (sub->peer_map,
4323 &peer,
4324 Peers_PULL_REPLY_PENDING))
4325 { // FIXME if this fails schedule/loop this for later
4326 send_pull_request (get_peer_ctx (sub->peer_map, &peer));
4327 }
4328 }
4329
4330 GNUNET_free (permut);
4331 permut = NULL;
4332 }
4333
4308 4334
4309 /* Update view */ 4335 /* Update view */
4310 /* TODO see how many peers are in push-/pull- list! */ 4336 /* TODO see how many peers are in push-/pull- list! */
4311 4337
4312 if ((CustomPeerMap_size(sub->push_map) <= alpha * sub->view_size_est_need) && 4338 if ((CustomPeerMap_size (sub->push_map) <= alpha * sub->view_size_est_need) &&
4313 (0 < CustomPeerMap_size(sub->push_map)) && 4339 (0 < CustomPeerMap_size (sub->push_map)) &&
4314 (0 < CustomPeerMap_size(sub->pull_map))) 4340 (0 < CustomPeerMap_size (sub->pull_map)))
4315 { /* If conditions for update are fulfilled, update */ 4341 { /* If conditions for update are fulfilled, update */
4316 LOG(GNUNET_ERROR_TYPE_DEBUG, "Update of the view.\n"); 4342 LOG (GNUNET_ERROR_TYPE_DEBUG, "Update of the view.\n");
4317 4343
4318 uint32_t final_size; 4344 uint32_t final_size;
4319 uint32_t peers_to_clean_size; 4345 uint32_t peers_to_clean_size;
4320 struct GNUNET_PeerIdentity *peers_to_clean; 4346 struct GNUNET_PeerIdentity *peers_to_clean;
4321 4347
4322 peers_to_clean = NULL; 4348 peers_to_clean = NULL;
4323 peers_to_clean_size = 0; 4349 peers_to_clean_size = 0;
4324 GNUNET_array_grow(peers_to_clean, 4350 GNUNET_array_grow (peers_to_clean,
4325 peers_to_clean_size, 4351 peers_to_clean_size,
4326 View_size(sub->view)); 4352 View_size (sub->view));
4327 GNUNET_memcpy(peers_to_clean, 4353 GNUNET_memcpy (peers_to_clean,
4328 view_array, 4354 view_array,
4329 View_size(sub->view) * sizeof(struct GNUNET_PeerIdentity)); 4355 View_size (sub->view) * sizeof(struct GNUNET_PeerIdentity));
4330 4356
4331 /* Seems like recreating is the easiest way of emptying the peermap */ 4357 /* Seems like recreating is the easiest way of emptying the peermap */
4332 View_clear(sub->view); 4358 View_clear (sub->view);
4333#ifdef TO_FILE_FULL 4359#ifdef TO_FILE_FULL
4334 to_file(sub->file_name_view_log, 4360 to_file (sub->file_name_view_log,
4335 "--- emptied ---"); 4361 "--- emptied ---");
4336#endif /* TO_FILE_FULL */ 4362#endif /* TO_FILE_FULL */
4337 4363
4338 first_border = GNUNET_MIN(ceil(alpha * sub->view_size_est_need), 4364 first_border = GNUNET_MIN (ceil (alpha * sub->view_size_est_need),
4339 CustomPeerMap_size(sub->push_map)); 4365 CustomPeerMap_size (sub->push_map));
4340 second_border = first_border + 4366 second_border = first_border
4341 GNUNET_MIN(floor(beta * sub->view_size_est_need), 4367 + GNUNET_MIN (floor (beta * sub->view_size_est_need),
4342 CustomPeerMap_size(sub->pull_map)); 4368 CustomPeerMap_size (sub->pull_map));
4343 final_size = second_border + 4369 final_size = second_border
4344 ceil((1 - (alpha + beta)) * sub->view_size_est_need); 4370 + ceil ((1 - (alpha + beta)) * sub->view_size_est_need);
4345 LOG(GNUNET_ERROR_TYPE_DEBUG, 4371 LOG (GNUNET_ERROR_TYPE_DEBUG,
4346 "first border: %" PRIu32 ", second border: %" PRIu32 ", final size: %" PRIu32 "\n", 4372 "first border: %" PRIu32 ", second border: %" PRIu32 ", final size: %"
4347 first_border, 4373 PRIu32 "\n",
4348 second_border, 4374 first_border,
4349 final_size); 4375 second_border,
4350 4376 final_size);
4351 /* Update view with peers received through PUSHes */ 4377
4352 permut = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_STRONG, 4378 /* Update view with peers received through PUSHes */
4353 CustomPeerMap_size(sub->push_map)); 4379 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG,
4354 for (i = 0; i < first_border; i++) 4380 CustomPeerMap_size (sub->push_map));
4355 { 4381 for (i = 0; i < first_border; i++)
4356 int inserted; 4382 {
4357 inserted = insert_in_view(sub, 4383 int inserted;
4358 CustomPeerMap_get_peer_by_index(sub->push_map, 4384 inserted = insert_in_view (sub,
4359 permut[i])); 4385 CustomPeerMap_get_peer_by_index (sub->push_map,
4360 if (GNUNET_OK == inserted) 4386 permut[i]));
4361 { 4387 if (GNUNET_OK == inserted)
4362 clients_notify_stream_peer(sub, 4388 {
4363 1, 4389 clients_notify_stream_peer (sub,
4364 CustomPeerMap_get_peer_by_index(sub->push_map, permut[i])); 4390 1,
4365 } 4391 CustomPeerMap_get_peer_by_index (
4392 sub->push_map, permut[i]));
4393 }
4366#ifdef TO_FILE_FULL 4394#ifdef TO_FILE_FULL
4367 to_file(sub->file_name_view_log, 4395 to_file (sub->file_name_view_log,
4368 "+%s\t(push list)", 4396 "+%s\t(push list)",
4369 GNUNET_i2s_full(&view_array[i])); 4397 GNUNET_i2s_full (&view_array[i]));
4370#endif /* TO_FILE_FULL */ 4398#endif /* TO_FILE_FULL */
4371 // TODO change the peer_flags accordingly 4399 // TODO change the peer_flags accordingly
4372 } 4400 }
4373 GNUNET_free(permut); 4401 GNUNET_free (permut);
4374 permut = NULL; 4402 permut = NULL;
4375 4403
4376 /* Update view with peers received through PULLs */ 4404 /* Update view with peers received through PULLs */
4377 permut = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_STRONG, 4405 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG,
4378 CustomPeerMap_size(sub->pull_map)); 4406 CustomPeerMap_size (sub->pull_map));
4379 for (i = first_border; i < second_border; i++) 4407 for (i = first_border; i < second_border; i++)
4380 { 4408 {
4381 int inserted; 4409 int inserted;
4382 inserted = insert_in_view(sub, 4410 inserted = insert_in_view (sub,
4383 CustomPeerMap_get_peer_by_index(sub->pull_map, 4411 CustomPeerMap_get_peer_by_index (sub->pull_map,
4384 permut[i - first_border])); 4412 permut[i
4385 if (GNUNET_OK == inserted) 4413 -
4386 { 4414 first_border
4387 clients_notify_stream_peer(sub, 4415 ]));
4388 1, 4416 if (GNUNET_OK == inserted)
4389 CustomPeerMap_get_peer_by_index(sub->pull_map, 4417 {
4390 permut[i - first_border])); 4418 clients_notify_stream_peer (sub,
4391 } 4419 1,
4420 CustomPeerMap_get_peer_by_index (
4421 sub->pull_map,
4422 permut[i
4423 - first_border]));
4424 }
4392#ifdef TO_FILE_FULL 4425#ifdef TO_FILE_FULL
4393 to_file(sub->file_name_view_log, 4426 to_file (sub->file_name_view_log,
4394 "+%s\t(pull list)", 4427 "+%s\t(pull list)",
4395 GNUNET_i2s_full(&view_array[i])); 4428 GNUNET_i2s_full (&view_array[i]));
4396#endif /* TO_FILE_FULL */ 4429#endif /* TO_FILE_FULL */
4397 // TODO change the peer_flags accordingly 4430 // TODO change the peer_flags accordingly
4398 } 4431 }
4399 GNUNET_free(permut); 4432 GNUNET_free (permut);
4400 permut = NULL; 4433 permut = NULL;
4401 4434
4402 /* Update view with peers from history */ 4435 /* Update view with peers from history */
4403 RPS_sampler_get_n_rand_peers(sub->sampler, 4436 RPS_sampler_get_n_rand_peers (sub->sampler,
4404 final_size - second_border, 4437 final_size - second_border,
4405 hist_update, 4438 hist_update,
4406 sub); 4439 sub);
4407 // TODO change the peer_flags accordingly 4440 // TODO change the peer_flags accordingly
4408 4441
4409 for (i = 0; i < View_size(sub->view); i++) 4442 for (i = 0; i < View_size (sub->view); i++)
4410 rem_from_list(&peers_to_clean, &peers_to_clean_size, &view_array[i]); 4443 rem_from_list (&peers_to_clean, &peers_to_clean_size, &view_array[i]);
4411 4444
4412 /* Clean peers that were removed from the view */ 4445 /* Clean peers that were removed from the view */
4413 for (i = 0; i < peers_to_clean_size; i++) 4446 for (i = 0; i < peers_to_clean_size; i++)
4414 { 4447 {
4415#ifdef TO_FILE_FULL 4448#ifdef TO_FILE_FULL
4416 to_file(sub->file_name_view_log, 4449 to_file (sub->file_name_view_log,
4417 "-%s", 4450 "-%s",
4418 GNUNET_i2s_full(&peers_to_clean[i])); 4451 GNUNET_i2s_full (&peers_to_clean[i]));
4419#endif /* TO_FILE_FULL */ 4452#endif /* TO_FILE_FULL */
4420 clean_peer(sub, &peers_to_clean[i]); 4453 clean_peer (sub, &peers_to_clean[i]);
4421 }
4422
4423 GNUNET_array_grow(peers_to_clean, peers_to_clean_size, 0);
4424 clients_notify_view_update(sub);
4425 } 4454 }
4455
4456 GNUNET_array_grow (peers_to_clean, peers_to_clean_size, 0);
4457 clients_notify_view_update (sub);
4458 }
4426 else 4459 else
4460 {
4461 LOG (GNUNET_ERROR_TYPE_DEBUG, "No update of the view.\n");
4462 if (sub == msub)
4427 { 4463 {
4428 LOG(GNUNET_ERROR_TYPE_DEBUG, "No update of the view.\n"); 4464 GNUNET_STATISTICS_update (stats, "# rounds blocked", 1, GNUNET_NO);
4429 if (sub == msub) 4465 if ((CustomPeerMap_size (sub->push_map) > alpha
4430 { 4466 * sub->view_size_est_need) &&
4431 GNUNET_STATISTICS_update(stats, "# rounds blocked", 1, GNUNET_NO); 4467 ! (0 >= CustomPeerMap_size (sub->pull_map)))
4432 if (CustomPeerMap_size(sub->push_map) > alpha * sub->view_size_est_need && 4468 GNUNET_STATISTICS_update (stats, "# rounds blocked - too many pushes",
4433 !(0 >= CustomPeerMap_size(sub->pull_map))) 4469 1, GNUNET_NO);
4434 GNUNET_STATISTICS_update(stats, "# rounds blocked - too many pushes", 1, GNUNET_NO); 4470 if ((CustomPeerMap_size (sub->push_map) > alpha
4435 if (CustomPeerMap_size(sub->push_map) > alpha * sub->view_size_est_need && 4471 * sub->view_size_est_need) &&
4436 (0 >= CustomPeerMap_size(sub->pull_map))) 4472 (0 >= CustomPeerMap_size (sub->pull_map)))
4437 GNUNET_STATISTICS_update(stats, "# rounds blocked - too many pushes, no pull replies", 1, GNUNET_NO); 4473 GNUNET_STATISTICS_update (stats,
4438 if (0 >= CustomPeerMap_size(sub->push_map) && 4474 "# rounds blocked - too many pushes, no pull replies",
4439 !(0 >= CustomPeerMap_size(sub->pull_map))) 4475 1, GNUNET_NO);
4440 GNUNET_STATISTICS_update(stats, "# rounds blocked - no pushes", 1, GNUNET_NO); 4476 if ((0 >= CustomPeerMap_size (sub->push_map)) &&
4441 if (0 >= CustomPeerMap_size(sub->push_map) && 4477 ! (0 >= CustomPeerMap_size (sub->pull_map)))
4442 (0 >= CustomPeerMap_size(sub->pull_map))) 4478 GNUNET_STATISTICS_update (stats, "# rounds blocked - no pushes", 1,
4443 GNUNET_STATISTICS_update(stats, "# rounds blocked - no pushes, no pull replies", 1, GNUNET_NO); 4479 GNUNET_NO);
4444 if (0 >= CustomPeerMap_size(sub->pull_map) && 4480 if ((0 >= CustomPeerMap_size (sub->push_map)) &&
4445 CustomPeerMap_size(sub->push_map) > alpha * sub->view_size_est_need && 4481 (0 >= CustomPeerMap_size (sub->pull_map)))
4446 0 >= CustomPeerMap_size(sub->push_map)) 4482 GNUNET_STATISTICS_update (stats,
4447 GNUNET_STATISTICS_update(stats, "# rounds blocked - no pull replies", 1, GNUNET_NO); 4483 "# rounds blocked - no pushes, no pull replies",
4448 } 4484 1, GNUNET_NO);
4449 } 4485 if ((0 >= CustomPeerMap_size (sub->pull_map)) &&
4486 (CustomPeerMap_size (sub->push_map) > alpha
4487 * sub->view_size_est_need) &&
4488 (0 >= CustomPeerMap_size (sub->push_map)) )
4489 GNUNET_STATISTICS_update (stats, "# rounds blocked - no pull replies",
4490 1, GNUNET_NO);
4491 }
4492 }
4450 // TODO independent of that also get some peers from CADET_get_peers()? 4493 // TODO independent of that also get some peers from CADET_get_peers()?
4451 if (CustomPeerMap_size(sub->push_map) < HISTOGRAM_FILE_SLOTS) 4494 if (CustomPeerMap_size (sub->push_map) < HISTOGRAM_FILE_SLOTS)
4452 { 4495 {
4453 sub->push_recv[CustomPeerMap_size(sub->push_map)]++; 4496 sub->push_recv[CustomPeerMap_size (sub->push_map)]++;
4454 } 4497 }
4455 else 4498 else
4456 { 4499 {
4457 LOG(GNUNET_ERROR_TYPE_WARNING, 4500 LOG (GNUNET_ERROR_TYPE_WARNING,
4458 "Push map size too big for histogram (%u, %u)\n", 4501 "Push map size too big for histogram (%u, %u)\n",
4459 CustomPeerMap_size(sub->push_map), 4502 CustomPeerMap_size (sub->push_map),
4460 HISTOGRAM_FILE_SLOTS); 4503 HISTOGRAM_FILE_SLOTS);
4461 } 4504 }
4462 // FIXME check bounds of histogram 4505 // FIXME check bounds of histogram
4463 sub->push_delta[(int32_t)(CustomPeerMap_size(sub->push_map) - 4506 sub->push_delta[(int32_t) (CustomPeerMap_size (sub->push_map)
4464 (alpha * sub->view_size_est_need)) + 4507 - (alpha * sub->view_size_est_need))
4465 (HISTOGRAM_FILE_SLOTS / 2)]++; 4508 + (HISTOGRAM_FILE_SLOTS / 2)]++;
4466 if (sub == msub) 4509 if (sub == msub)
4467 { 4510 {
4468 GNUNET_STATISTICS_set(stats, 4511 GNUNET_STATISTICS_set (stats,
4469 "# peers in push map at end of round", 4512 "# peers in push map at end of round",
4470 CustomPeerMap_size(sub->push_map), 4513 CustomPeerMap_size (sub->push_map),
4471 GNUNET_NO); 4514 GNUNET_NO);
4472 GNUNET_STATISTICS_set(stats, 4515 GNUNET_STATISTICS_set (stats,
4473 "# peers in pull map at end of round", 4516 "# peers in pull map at end of round",
4474 CustomPeerMap_size(sub->pull_map), 4517 CustomPeerMap_size (sub->pull_map),
4475 GNUNET_NO); 4518 GNUNET_NO);
4476 GNUNET_STATISTICS_set(stats, 4519 GNUNET_STATISTICS_set (stats,
4477 "# peers in view at end of round", 4520 "# peers in view at end of round",
4478 View_size(sub->view), 4521 View_size (sub->view),
4479 GNUNET_NO); 4522 GNUNET_NO);
4480 GNUNET_STATISTICS_set(stats, 4523 GNUNET_STATISTICS_set (stats,
4481 "# expected pushes", 4524 "# expected pushes",
4482 alpha * sub->view_size_est_need, 4525 alpha * sub->view_size_est_need,
4483 GNUNET_NO); 4526 GNUNET_NO);
4484 GNUNET_STATISTICS_set(stats, 4527 GNUNET_STATISTICS_set (stats,
4485 "delta expected - received pushes", 4528 "delta expected - received pushes",
4486 CustomPeerMap_size(sub->push_map) - (alpha * sub->view_size_est_need), 4529 CustomPeerMap_size (sub->push_map) - (alpha
4487 GNUNET_NO); 4530 * sub->
4488 } 4531 view_size_est_need),
4489 4532 GNUNET_NO);
4490 LOG(GNUNET_ERROR_TYPE_DEBUG, 4533 }
4491 "Received %u pushes and %u pulls last round (alpha (%.2f) * view_size (sub->view%u) = %.2f)\n", 4534
4492 CustomPeerMap_size(sub->push_map), 4535 LOG (GNUNET_ERROR_TYPE_DEBUG,
4493 CustomPeerMap_size(sub->pull_map), 4536 "Received %u pushes and %u pulls last round (alpha (%.2f) * view_size (sub->view%u) = %.2f)\n",
4494 alpha, 4537 CustomPeerMap_size (sub->push_map),
4495 View_size(sub->view), 4538 CustomPeerMap_size (sub->pull_map),
4496 alpha * View_size(sub->view)); 4539 alpha,
4540 View_size (sub->view),
4541 alpha * View_size (sub->view));
4497 4542
4498 /* Update samplers */ 4543 /* Update samplers */
4499 for (i = 0; i < CustomPeerMap_size(sub->push_map); i++) 4544 for (i = 0; i < CustomPeerMap_size (sub->push_map); i++)
4500 { 4545 {
4501 update_peer = CustomPeerMap_get_peer_by_index(sub->push_map, i); 4546 update_peer = CustomPeerMap_get_peer_by_index (sub->push_map, i);
4502 LOG(GNUNET_ERROR_TYPE_DEBUG, 4547 LOG (GNUNET_ERROR_TYPE_DEBUG,
4503 "Updating with peer %s from push list\n", 4548 "Updating with peer %s from push list\n",
4504 GNUNET_i2s(update_peer)); 4549 GNUNET_i2s (update_peer));
4505 insert_in_sampler(sub, update_peer); 4550 insert_in_sampler (sub, update_peer);
4506 clean_peer(sub, update_peer); /* This cleans only if it is not in the view */ 4551 clean_peer (sub, update_peer); /* This cleans only if it is not in the view */
4507 } 4552 }
4508 4553
4509 for (i = 0; i < CustomPeerMap_size(sub->pull_map); i++) 4554 for (i = 0; i < CustomPeerMap_size (sub->pull_map); i++)
4510 { 4555 {
4511 LOG(GNUNET_ERROR_TYPE_DEBUG, 4556 LOG (GNUNET_ERROR_TYPE_DEBUG,
4512 "Updating with peer %s from pull list\n", 4557 "Updating with peer %s from pull list\n",
4513 GNUNET_i2s(CustomPeerMap_get_peer_by_index(sub->pull_map, i))); 4558 GNUNET_i2s (CustomPeerMap_get_peer_by_index (sub->pull_map, i)));
4514 insert_in_sampler(sub, CustomPeerMap_get_peer_by_index(sub->pull_map, i)); 4559 insert_in_sampler (sub, CustomPeerMap_get_peer_by_index (sub->pull_map, i));
4515 /* This cleans only if it is not in the view */ 4560 /* This cleans only if it is not in the view */
4516 clean_peer(sub, CustomPeerMap_get_peer_by_index(sub->pull_map, i)); 4561 clean_peer (sub, CustomPeerMap_get_peer_by_index (sub->pull_map, i));
4517 } 4562 }
4518 4563
4519 4564
4520 /* Empty push/pull lists */ 4565 /* Empty push/pull lists */
4521 CustomPeerMap_clear(sub->push_map); 4566 CustomPeerMap_clear (sub->push_map);
4522 CustomPeerMap_clear(sub->pull_map); 4567 CustomPeerMap_clear (sub->pull_map);
4523 4568
4524 if (sub == msub) 4569 if (sub == msub)
4525 { 4570 {
4526 GNUNET_STATISTICS_set(stats, 4571 GNUNET_STATISTICS_set (stats,
4527 "view size", 4572 "view size",
4528 View_size(sub->view), 4573 View_size (sub->view),
4529 GNUNET_NO); 4574 GNUNET_NO);
4530 } 4575 }
4531 4576
4532 struct GNUNET_TIME_Relative time_next_round; 4577 struct GNUNET_TIME_Relative time_next_round;
4533 4578
4534 time_next_round = compute_rand_delay(sub->round_interval, 2); 4579 time_next_round = compute_rand_delay (sub->round_interval, 2);
4535 4580
4536 /* Schedule next round */ 4581 /* Schedule next round */
4537 sub->do_round_task = GNUNET_SCHEDULER_add_delayed(time_next_round, 4582 sub->do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round,
4538 &do_round, sub); 4583 &do_round, sub);
4539 LOG(GNUNET_ERROR_TYPE_DEBUG, "Finished round\n"); 4584 LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n");
4540} 4585}
4541 4586
4542 4587
@@ -4556,26 +4601,26 @@ do_round(void *cls)
4556 * (0 = unknown, 1 = ourselves, 2 = neighbor) 4601 * (0 = unknown, 1 = ourselves, 2 = neighbor)
4557 */ 4602 */
4558void 4603void
4559init_peer_cb(void *cls, 4604init_peer_cb (void *cls,
4560 const struct GNUNET_PeerIdentity *peer, 4605 const struct GNUNET_PeerIdentity *peer,
4561 int tunnel, /* "Do we have a tunnel towards this peer?" */ 4606 int tunnel, /* "Do we have a tunnel towards this peer?" */
4562 unsigned int n_paths, /* "Number of known paths towards this peer" */ 4607 unsigned int n_paths, /* "Number of known paths towards this peer" */
4563 unsigned int best_path) /* "How long is the best path? 4608 unsigned int best_path) /* "How long is the best path?
4564 * (0 = unknown, 1 = ourselves, 2 = neighbor)" */ 4609 * (0 = unknown, 1 = ourselves, 2 = neighbor)" */
4565{ 4610{
4566 struct Sub *sub = cls; 4611 struct Sub *sub = cls;
4567 4612
4568 (void)tunnel; 4613 (void) tunnel;
4569 (void)n_paths; 4614 (void) n_paths;
4570 (void)best_path; 4615 (void) best_path;
4571 4616
4572 if (NULL != peer) 4617 if (NULL != peer)
4573 { 4618 {
4574 LOG(GNUNET_ERROR_TYPE_DEBUG, 4619 LOG (GNUNET_ERROR_TYPE_DEBUG,
4575 "Got peer_id %s from cadet\n", 4620 "Got peer_id %s from cadet\n",
4576 GNUNET_i2s(peer)); 4621 GNUNET_i2s (peer));
4577 got_peer(sub, peer); 4622 got_peer (sub, peer);
4578 } 4623 }
4579} 4624}
4580 4625
4581 4626
@@ -4591,18 +4636,18 @@ init_peer_cb(void *cls,
4591 * #GNUNET_NO if not. 4636 * #GNUNET_NO if not.
4592 */ 4637 */
4593static int 4638static int
4594valid_peers_iterator(void *cls, 4639valid_peers_iterator (void *cls,
4595 const struct GNUNET_PeerIdentity *peer) 4640 const struct GNUNET_PeerIdentity *peer)
4596{ 4641{
4597 struct Sub *sub = cls; 4642 struct Sub *sub = cls;
4598 4643
4599 if (NULL != peer) 4644 if (NULL != peer)
4600 { 4645 {
4601 LOG(GNUNET_ERROR_TYPE_DEBUG, 4646 LOG (GNUNET_ERROR_TYPE_DEBUG,
4602 "Got stored, valid peer %s\n", 4647 "Got stored, valid peer %s\n",
4603 GNUNET_i2s(peer)); 4648 GNUNET_i2s (peer));
4604 got_peer(sub, peer); 4649 got_peer (sub, peer);
4605 } 4650 }
4606 return GNUNET_YES; 4651 return GNUNET_YES;
4607} 4652}
4608 4653
@@ -4616,23 +4661,23 @@ valid_peers_iterator(void *cls,
4616 * @param error message 4661 * @param error message
4617 */ 4662 */
4618void 4663void
4619process_peerinfo_peers(void *cls, 4664process_peerinfo_peers (void *cls,
4620 const struct GNUNET_PeerIdentity *peer, 4665 const struct GNUNET_PeerIdentity *peer,
4621 const struct GNUNET_HELLO_Message *hello, 4666 const struct GNUNET_HELLO_Message *hello,
4622 const char *err_msg) 4667 const char *err_msg)
4623{ 4668{
4624 struct Sub *sub = cls; 4669 struct Sub *sub = cls;
4625 4670
4626 (void)hello; 4671 (void) hello;
4627 (void)err_msg; 4672 (void) err_msg;
4628 4673
4629 if (NULL != peer) 4674 if (NULL != peer)
4630 { 4675 {
4631 LOG(GNUNET_ERROR_TYPE_DEBUG, 4676 LOG (GNUNET_ERROR_TYPE_DEBUG,
4632 "Got peer_id %s from peerinfo\n", 4677 "Got peer_id %s from peerinfo\n",
4633 GNUNET_i2s(peer)); 4678 GNUNET_i2s (peer));
4634 got_peer(sub, peer); 4679 got_peer (sub, peer);
4635 } 4680 }
4636} 4681}
4637 4682
4638 4683
@@ -4642,69 +4687,69 @@ process_peerinfo_peers(void *cls,
4642 * @param cls Closure - unused 4687 * @param cls Closure - unused
4643 */ 4688 */
4644static void 4689static void
4645shutdown_task(void *cls) 4690shutdown_task (void *cls)
4646{ 4691{
4647 (void)cls; 4692 (void) cls;
4648 struct ClientContext *client_ctx; 4693 struct ClientContext *client_ctx;
4649 4694
4650 LOG(GNUNET_ERROR_TYPE_DEBUG, 4695 LOG (GNUNET_ERROR_TYPE_DEBUG,
4651 "RPS service is going down\n"); 4696 "RPS service is going down\n");
4652 4697
4653 /* Clean all clients */ 4698 /* Clean all clients */
4654 for (client_ctx = cli_ctx_head; 4699 for (client_ctx = cli_ctx_head;
4655 NULL != cli_ctx_head; 4700 NULL != cli_ctx_head;
4656 client_ctx = cli_ctx_head) 4701 client_ctx = cli_ctx_head)
4657 { 4702 {
4658 destroy_cli_ctx(client_ctx); 4703 destroy_cli_ctx (client_ctx);
4659 } 4704 }
4660 if (NULL != msub) 4705 if (NULL != msub)
4661 { 4706 {
4662 destroy_sub(msub); 4707 destroy_sub (msub);
4663 msub = NULL; 4708 msub = NULL;
4664 } 4709 }
4665 4710
4666 /* Disconnect from other services */ 4711 /* Disconnect from other services */
4667 GNUNET_PEERINFO_notify_cancel(peerinfo_notify_handle); 4712 GNUNET_PEERINFO_notify_cancel (peerinfo_notify_handle);
4668 GNUNET_PEERINFO_disconnect(peerinfo_handle); 4713 GNUNET_PEERINFO_disconnect (peerinfo_handle);
4669 peerinfo_handle = NULL; 4714 peerinfo_handle = NULL;
4670 GNUNET_NSE_disconnect(nse); 4715 GNUNET_NSE_disconnect (nse);
4671 if (NULL != map_single_hop) 4716 if (NULL != map_single_hop)
4672 { 4717 {
4673 /* core_init was called - core was initialised */ 4718 /* core_init was called - core was initialised */
4674 /* disconnect first, so no callback tries to access missing peermap */ 4719 /* disconnect first, so no callback tries to access missing peermap */
4675 GNUNET_CORE_disconnect(core_handle); 4720 GNUNET_CORE_disconnect (core_handle);
4676 core_handle = NULL; 4721 core_handle = NULL;
4677 GNUNET_CONTAINER_multipeermap_destroy(map_single_hop); 4722 GNUNET_CONTAINER_multipeermap_destroy (map_single_hop);
4678 map_single_hop = NULL; 4723 map_single_hop = NULL;
4679 } 4724 }
4680 4725
4681 if (NULL != stats) 4726 if (NULL != stats)
4682 { 4727 {
4683 GNUNET_STATISTICS_destroy(stats, 4728 GNUNET_STATISTICS_destroy (stats,
4684 GNUNET_NO); 4729 GNUNET_NO);
4685 stats = NULL; 4730 stats = NULL;
4686 } 4731 }
4687 GNUNET_CADET_disconnect(cadet_handle); 4732 GNUNET_CADET_disconnect (cadet_handle);
4688 cadet_handle = NULL; 4733 cadet_handle = NULL;
4689#if ENABLE_MALICIOUS 4734#if ENABLE_MALICIOUS
4690 struct AttackedPeer *tmp_att_peer; 4735 struct AttackedPeer *tmp_att_peer;
4691 GNUNET_array_grow(mal_peers, 4736 GNUNET_array_grow (mal_peers,
4692 num_mal_peers, 4737 num_mal_peers,
4693 0); 4738 0);
4694 if (NULL != mal_peer_set) 4739 if (NULL != mal_peer_set)
4695 GNUNET_CONTAINER_multipeermap_destroy(mal_peer_set); 4740 GNUNET_CONTAINER_multipeermap_destroy (mal_peer_set);
4696 if (NULL != att_peer_set) 4741 if (NULL != att_peer_set)
4697 GNUNET_CONTAINER_multipeermap_destroy(att_peer_set); 4742 GNUNET_CONTAINER_multipeermap_destroy (att_peer_set);
4698 while (NULL != att_peers_head) 4743 while (NULL != att_peers_head)
4699 { 4744 {
4700 tmp_att_peer = att_peers_head; 4745 tmp_att_peer = att_peers_head;
4701 GNUNET_CONTAINER_DLL_remove(att_peers_head, 4746 GNUNET_CONTAINER_DLL_remove (att_peers_head,
4702 att_peers_tail, 4747 att_peers_tail,
4703 tmp_att_peer); 4748 tmp_att_peer);
4704 GNUNET_free(tmp_att_peer); 4749 GNUNET_free (tmp_att_peer);
4705 } 4750 }
4706#endif /* ENABLE_MALICIOUS */ 4751#endif /* ENABLE_MALICIOUS */
4707 close_all_files(); 4752 close_all_files ();
4708} 4753}
4709 4754
4710 4755
@@ -4717,26 +4762,26 @@ shutdown_task(void *cls)
4717 * @return @a client 4762 * @return @a client
4718 */ 4763 */
4719static void * 4764static void *
4720client_connect_cb(void *cls, 4765client_connect_cb (void *cls,
4721 struct GNUNET_SERVICE_Client *client, 4766 struct GNUNET_SERVICE_Client *client,
4722 struct GNUNET_MQ_Handle *mq) 4767 struct GNUNET_MQ_Handle *mq)
4723{ 4768{
4724 struct ClientContext *cli_ctx; 4769 struct ClientContext *cli_ctx;
4725 4770
4726 (void)cls; 4771 (void) cls;
4727 4772
4728 LOG(GNUNET_ERROR_TYPE_DEBUG, 4773 LOG (GNUNET_ERROR_TYPE_DEBUG,
4729 "Client connected\n"); 4774 "Client connected\n");
4730 if (NULL == client) 4775 if (NULL == client)
4731 return client; /* Server was destroyed before a client connected. Shutting down */ 4776 return client; /* Server was destroyed before a client connected. Shutting down */
4732 cli_ctx = GNUNET_new(struct ClientContext); 4777 cli_ctx = GNUNET_new (struct ClientContext);
4733 cli_ctx->mq = mq; 4778 cli_ctx->mq = mq;
4734 cli_ctx->view_updates_left = -1; 4779 cli_ctx->view_updates_left = -1;
4735 cli_ctx->stream_update = GNUNET_NO; 4780 cli_ctx->stream_update = GNUNET_NO;
4736 cli_ctx->client = client; 4781 cli_ctx->client = client;
4737 GNUNET_CONTAINER_DLL_insert(cli_ctx_head, 4782 GNUNET_CONTAINER_DLL_insert (cli_ctx_head,
4738 cli_ctx_tail, 4783 cli_ctx_tail,
4739 cli_ctx); 4784 cli_ctx);
4740 return cli_ctx; 4785 return cli_ctx;
4741} 4786}
4742 4787
@@ -4748,25 +4793,25 @@ client_connect_cb(void *cls,
4748 * @param internal_cls should be equal to @a c 4793 * @param internal_cls should be equal to @a c
4749 */ 4794 */
4750static void 4795static void
4751client_disconnect_cb(void *cls, 4796client_disconnect_cb (void *cls,
4752 struct GNUNET_SERVICE_Client *client, 4797 struct GNUNET_SERVICE_Client *client,
4753 void *internal_cls) 4798 void *internal_cls)
4754{ 4799{
4755 struct ClientContext *cli_ctx = internal_cls; 4800 struct ClientContext *cli_ctx = internal_cls;
4756 4801
4757 (void)cls; 4802 (void) cls;
4758 GNUNET_assert(client == cli_ctx->client); 4803 GNUNET_assert (client == cli_ctx->client);
4759 if (NULL == client) 4804 if (NULL == client)
4760 {/* shutdown task - destroy all clients */ 4805 { /* shutdown task - destroy all clients */
4761 while (NULL != cli_ctx_head) 4806 while (NULL != cli_ctx_head)
4762 destroy_cli_ctx(cli_ctx_head); 4807 destroy_cli_ctx (cli_ctx_head);
4763 } 4808 }
4764 else 4809 else
4765 { /* destroy this client */ 4810 { /* destroy this client */
4766 LOG(GNUNET_ERROR_TYPE_DEBUG, 4811 LOG (GNUNET_ERROR_TYPE_DEBUG,
4767 "Client disconnected. Destroy its context.\n"); 4812 "Client disconnected. Destroy its context.\n");
4768 destroy_cli_ctx(cli_ctx); 4813 destroy_cli_ctx (cli_ctx);
4769 } 4814 }
4770} 4815}
4771 4816
4772 4817
@@ -4778,68 +4823,68 @@ client_disconnect_cb(void *cls,
4778 * @param service the initialized service 4823 * @param service the initialized service
4779 */ 4824 */
4780static void 4825static void
4781run(void *cls, 4826run (void *cls,
4782 const struct GNUNET_CONFIGURATION_Handle *c, 4827 const struct GNUNET_CONFIGURATION_Handle *c,
4783 struct GNUNET_SERVICE_Handle *service) 4828 struct GNUNET_SERVICE_Handle *service)
4784{ 4829{
4785 struct GNUNET_TIME_Relative round_interval; 4830 struct GNUNET_TIME_Relative round_interval;
4786 long long unsigned int sampler_size; 4831 long long unsigned int sampler_size;
4787 char hash_port_string[] = GNUNET_APPLICATION_PORT_RPS; 4832 char hash_port_string[] = GNUNET_APPLICATION_PORT_RPS;
4788 struct GNUNET_HashCode hash; 4833 struct GNUNET_HashCode hash;
4789 4834
4790 (void)cls; 4835 (void) cls;
4791 (void)service; 4836 (void) service;
4792 4837
4793 GNUNET_log_setup("rps", 4838 GNUNET_log_setup ("rps",
4794 GNUNET_error_type_to_string(GNUNET_ERROR_TYPE_DEBUG), 4839 GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_DEBUG),
4795 NULL); 4840 NULL);
4796 cfg = c; 4841 cfg = c;
4797 /* Get own ID */ 4842 /* Get own ID */
4798 GNUNET_CRYPTO_get_peer_identity(cfg, 4843 GNUNET_CRYPTO_get_peer_identity (cfg,
4799 &own_identity); // TODO check return value 4844 &own_identity); // TODO check return value
4800 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 4845 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
4801 "STARTING SERVICE (rps) for peer [%s]\n", 4846 "STARTING SERVICE (rps) for peer [%s]\n",
4802 GNUNET_i2s(&own_identity)); 4847 GNUNET_i2s (&own_identity));
4803#if ENABLE_MALICIOUS 4848#if ENABLE_MALICIOUS
4804 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 4849 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
4805 "Malicious execution compiled in.\n"); 4850 "Malicious execution compiled in.\n");
4806#endif /* ENABLE_MALICIOUS */ 4851#endif /* ENABLE_MALICIOUS */
4807 4852
4808 /* Get time interval from the configuration */ 4853 /* Get time interval from the configuration */
4809 if (GNUNET_OK != 4854 if (GNUNET_OK !=
4810 GNUNET_CONFIGURATION_get_value_time(cfg, 4855 GNUNET_CONFIGURATION_get_value_time (cfg,
4811 "RPS", 4856 "RPS",
4812 "ROUNDINTERVAL", 4857 "ROUNDINTERVAL",
4813 &round_interval)) 4858 &round_interval))
4814 { 4859 {
4815 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, 4860 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
4816 "RPS", "ROUNDINTERVAL"); 4861 "RPS", "ROUNDINTERVAL");
4817 GNUNET_SCHEDULER_shutdown(); 4862 GNUNET_SCHEDULER_shutdown ();
4818 return; 4863 return;
4819 } 4864 }
4820 4865
4821 /* Get initial size of sampler/view from the configuration */ 4866 /* Get initial size of sampler/view from the configuration */
4822 if (GNUNET_OK != 4867 if (GNUNET_OK !=
4823 GNUNET_CONFIGURATION_get_value_number(cfg, 4868 GNUNET_CONFIGURATION_get_value_number (cfg,
4824 "RPS", 4869 "RPS",
4825 "MINSIZE", 4870 "MINSIZE",
4826 &sampler_size)) 4871 &sampler_size))
4827 { 4872 {
4828 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, 4873 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
4829 "RPS", "MINSIZE"); 4874 "RPS", "MINSIZE");
4830 GNUNET_SCHEDULER_shutdown(); 4875 GNUNET_SCHEDULER_shutdown ();
4831 return; 4876 return;
4832 } 4877 }
4833 4878
4834 cadet_handle = GNUNET_CADET_connect(cfg); 4879 cadet_handle = GNUNET_CADET_connect (cfg);
4835 GNUNET_assert(NULL != cadet_handle); 4880 GNUNET_assert (NULL != cadet_handle);
4836 core_handle = GNUNET_CORE_connect(cfg, 4881 core_handle = GNUNET_CORE_connect (cfg,
4837 NULL, /* cls */ 4882 NULL, /* cls */
4838 core_init, /* init */ 4883 core_init, /* init */
4839 core_connects, /* connects */ 4884 core_connects, /* connects */
4840 core_disconnects, /* disconnects */ 4885 core_disconnects, /* disconnects */
4841 NULL); /* handlers */ 4886 NULL); /* handlers */
4842 GNUNET_assert(NULL != core_handle); 4887 GNUNET_assert (NULL != core_handle);
4843 4888
4844 4889
4845 alpha = 0.45; 4890 alpha = 0.45;
@@ -4847,35 +4892,35 @@ run(void *cls,
4847 4892
4848 4893
4849 /* Set up main Sub */ 4894 /* Set up main Sub */
4850 GNUNET_CRYPTO_hash(hash_port_string, 4895 GNUNET_CRYPTO_hash (hash_port_string,
4851 strlen(hash_port_string), 4896 strlen (hash_port_string),
4852 &hash); 4897 &hash);
4853 msub = new_sub(&hash, 4898 msub = new_sub (&hash,
4854 sampler_size, /* Will be overwritten by config */ 4899 sampler_size, /* Will be overwritten by config */
4855 round_interval); 4900 round_interval);
4856 4901
4857 4902
4858 peerinfo_handle = GNUNET_PEERINFO_connect(cfg); 4903 peerinfo_handle = GNUNET_PEERINFO_connect (cfg);
4859 4904
4860 /* connect to NSE */ 4905 /* connect to NSE */
4861 nse = GNUNET_NSE_connect(cfg, nse_callback, NULL); 4906 nse = GNUNET_NSE_connect (cfg, nse_callback, NULL);
4862 4907
4863 //LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting peers from CADET\n"); 4908 // LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting peers from CADET\n");
4864 //GNUNET_CADET_get_peers (cadet_handle, &init_peer_cb, msub); 4909 // GNUNET_CADET_get_peers (cadet_handle, &init_peer_cb, msub);
4865 // TODO send push/pull to each of those peers? 4910 // TODO send push/pull to each of those peers?
4866 LOG(GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n"); 4911 LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n");
4867 restore_valid_peers(msub); 4912 restore_valid_peers (msub);
4868 get_valid_peers(msub->valid_peers, valid_peers_iterator, msub); 4913 get_valid_peers (msub->valid_peers, valid_peers_iterator, msub);
4869 4914
4870 peerinfo_notify_handle = GNUNET_PEERINFO_notify(cfg, 4915 peerinfo_notify_handle = GNUNET_PEERINFO_notify (cfg,
4871 GNUNET_NO, 4916 GNUNET_NO,
4872 process_peerinfo_peers, 4917 process_peerinfo_peers,
4873 msub); 4918 msub);
4874 4919
4875 LOG(GNUNET_ERROR_TYPE_INFO, "Ready to receive requests from clients\n"); 4920 LOG (GNUNET_ERROR_TYPE_INFO, "Ready to receive requests from clients\n");
4876 4921
4877 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); 4922 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
4878 stats = GNUNET_STATISTICS_create("rps", cfg); 4923 stats = GNUNET_STATISTICS_create ("rps", cfg);
4879} 4924}
4880 4925
4881 4926
@@ -4889,40 +4934,40 @@ GNUNET_SERVICE_MAIN
4889 &client_connect_cb, 4934 &client_connect_cb,
4890 &client_disconnect_cb, 4935 &client_disconnect_cb,
4891 NULL, 4936 NULL,
4892 GNUNET_MQ_hd_var_size(client_seed, 4937 GNUNET_MQ_hd_var_size (client_seed,
4893 GNUNET_MESSAGE_TYPE_RPS_CS_SEED, 4938 GNUNET_MESSAGE_TYPE_RPS_CS_SEED,
4894 struct GNUNET_RPS_CS_SeedMessage, 4939 struct GNUNET_RPS_CS_SeedMessage,
4895 NULL), 4940 NULL),
4896#if ENABLE_MALICIOUS 4941#if ENABLE_MALICIOUS
4897 GNUNET_MQ_hd_var_size(client_act_malicious, 4942 GNUNET_MQ_hd_var_size (client_act_malicious,
4898 GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS, 4943 GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS,
4899 struct GNUNET_RPS_CS_ActMaliciousMessage, 4944 struct GNUNET_RPS_CS_ActMaliciousMessage,
4900 NULL), 4945 NULL),
4901#endif /* ENABLE_MALICIOUS */ 4946#endif /* ENABLE_MALICIOUS */
4902 GNUNET_MQ_hd_fixed_size(client_view_request, 4947 GNUNET_MQ_hd_fixed_size (client_view_request,
4903 GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST, 4948 GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST,
4904 struct GNUNET_RPS_CS_DEBUG_ViewRequest, 4949 struct GNUNET_RPS_CS_DEBUG_ViewRequest,
4905 NULL), 4950 NULL),
4906 GNUNET_MQ_hd_fixed_size(client_view_cancel, 4951 GNUNET_MQ_hd_fixed_size (client_view_cancel,
4907 GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL, 4952 GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL,
4908 struct GNUNET_MessageHeader, 4953 struct GNUNET_MessageHeader,
4909 NULL), 4954 NULL),
4910 GNUNET_MQ_hd_fixed_size(client_stream_request, 4955 GNUNET_MQ_hd_fixed_size (client_stream_request,
4911 GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST, 4956 GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST,
4912 struct GNUNET_RPS_CS_DEBUG_StreamRequest, 4957 struct GNUNET_RPS_CS_DEBUG_StreamRequest,
4913 NULL), 4958 NULL),
4914 GNUNET_MQ_hd_fixed_size(client_stream_cancel, 4959 GNUNET_MQ_hd_fixed_size (client_stream_cancel,
4915 GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_CANCEL, 4960 GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_CANCEL,
4916 struct GNUNET_MessageHeader, 4961 struct GNUNET_MessageHeader,
4917 NULL), 4962 NULL),
4918 GNUNET_MQ_hd_fixed_size(client_start_sub, 4963 GNUNET_MQ_hd_fixed_size (client_start_sub,
4919 GNUNET_MESSAGE_TYPE_RPS_CS_SUB_START, 4964 GNUNET_MESSAGE_TYPE_RPS_CS_SUB_START,
4920 struct GNUNET_RPS_CS_SubStartMessage, 4965 struct GNUNET_RPS_CS_SubStartMessage,
4921 NULL), 4966 NULL),
4922 GNUNET_MQ_hd_fixed_size(client_stop_sub, 4967 GNUNET_MQ_hd_fixed_size (client_stop_sub,
4923 GNUNET_MESSAGE_TYPE_RPS_CS_SUB_STOP, 4968 GNUNET_MESSAGE_TYPE_RPS_CS_SUB_STOP,
4924 struct GNUNET_RPS_CS_SubStopMessage, 4969 struct GNUNET_RPS_CS_SubStopMessage,
4925 NULL), 4970 NULL),
4926 GNUNET_MQ_handler_end()); 4971 GNUNET_MQ_handler_end ());
4927 4972
4928/* end of gnunet-service-rps.c */ 4973/* 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 b842bc0a5..8fcfc5558 100644
--- a/src/rps/gnunet-service-rps_custommap.c
+++ b/src/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,7 +54,8 @@
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 */
57struct CustomPeerMap { 57struct CustomPeerMap
58{
58 /** 59 /**
59 * Multihashmap to be able to access a random index 60 * Multihashmap to be able to access a random index
60 */ 61 */
@@ -75,14 +76,14 @@ struct CustomPeerMap {
75 * @return the newly created custom peer map 76 * @return the newly created custom peer map
76 */ 77 */
77struct CustomPeerMap * 78struct CustomPeerMap *
78CustomPeerMap_create(unsigned int len) 79CustomPeerMap_create (unsigned int len)
79{ 80{
80 struct CustomPeerMap *c_peer_map; 81 struct CustomPeerMap *c_peer_map;
81 82
82 c_peer_map = GNUNET_new(struct CustomPeerMap); 83 c_peer_map = GNUNET_new (struct CustomPeerMap);
83 c_peer_map->hash_map = GNUNET_CONTAINER_multihashmap32_create(len); 84 c_peer_map->hash_map = GNUNET_CONTAINER_multihashmap32_create (len);
84 c_peer_map->peer_map = GNUNET_CONTAINER_multipeermap_create(len, 85 c_peer_map->peer_map = GNUNET_CONTAINER_multipeermap_create (len,
85 GNUNET_NO); 86 GNUNET_NO);
86 return c_peer_map; 87 return c_peer_map;
87} 88}
88 89
@@ -94,11 +95,11 @@ CustomPeerMap_create(unsigned int len)
94 * @return size of the map 95 * @return size of the map
95 */ 96 */
96unsigned int 97unsigned int
97CustomPeerMap_size(const struct CustomPeerMap *c_peer_map) 98CustomPeerMap_size (const struct CustomPeerMap *c_peer_map)
98{ 99{
99 GNUNET_assert(GNUNET_CONTAINER_multihashmap32_size(c_peer_map->hash_map) == 100 GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size (c_peer_map->hash_map) ==
100 GNUNET_CONTAINER_multipeermap_size(c_peer_map->peer_map)); 101 GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map));
101 return GNUNET_CONTAINER_multipeermap_size(c_peer_map->peer_map); 102 return GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map);
102} 103}
103 104
104/** 105/**
@@ -111,39 +112,40 @@ CustomPeerMap_size(const struct CustomPeerMap *c_peer_map)
111 * GNUNET_NO if map did contain peer previously 112 * GNUNET_NO if map did contain peer previously
112 */ 113 */
113int 114int
114CustomPeerMap_put(const struct CustomPeerMap *c_peer_map, 115CustomPeerMap_put (const struct CustomPeerMap *c_peer_map,
115 const struct GNUNET_PeerIdentity *peer) 116 const struct GNUNET_PeerIdentity *peer)
116{ 117{
117 uint32_t *index; 118 uint32_t *index;
118 struct GNUNET_PeerIdentity *p; 119 struct GNUNET_PeerIdentity *p;
119 120
120 GNUNET_assert(GNUNET_CONTAINER_multihashmap32_size(c_peer_map->hash_map) == 121 GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size (c_peer_map->hash_map) ==
121 GNUNET_CONTAINER_multipeermap_size(c_peer_map->peer_map)); 122 GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map));
122 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(c_peer_map->peer_map, 123 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (c_peer_map->peer_map,
123 peer)) 124 peer))
124 { 125 {
125 /* Need to store the index of the peer in the peermap to be able to remove 126 /* Need to store the index of the peer in the peermap to be able to remove
126 * it properly */ 127 * it properly */
127 index = GNUNET_new(uint32_t); 128 index = GNUNET_new (uint32_t);
128 *index = CustomPeerMap_size(c_peer_map); 129 *index = CustomPeerMap_size (c_peer_map);
129 p = GNUNET_new(struct GNUNET_PeerIdentity); 130 p = GNUNET_new (struct GNUNET_PeerIdentity);
130 *p = *peer; 131 *p = *peer;
131 GNUNET_assert(p != peer); 132 GNUNET_assert (p != peer);
132 GNUNET_assert(0 == memcmp(p, 133 GNUNET_assert (0 == memcmp (p,
133 peer, 134 peer,
134 sizeof(struct GNUNET_PeerIdentity))); 135 sizeof(struct GNUNET_PeerIdentity)));
135 GNUNET_CONTAINER_multipeermap_put(c_peer_map->peer_map, 136 GNUNET_CONTAINER_multipeermap_put (c_peer_map->peer_map,
136 p, 137 p,
137 index, 138 index,
138 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 139 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
139 GNUNET_CONTAINER_multihashmap32_put(c_peer_map->hash_map, 140 GNUNET_CONTAINER_multihashmap32_put (c_peer_map->hash_map,
140 *index, 141 *index,
141 p, 142 p,
142 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 143 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
143 GNUNET_assert(GNUNET_CONTAINER_multihashmap32_size(c_peer_map->hash_map) == 144 GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size (
144 GNUNET_CONTAINER_multipeermap_size(c_peer_map->peer_map)); 145 c_peer_map->hash_map) ==
145 return GNUNET_OK; 146 GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map));
146 } 147 return GNUNET_OK;
148 }
147 return GNUNET_NO; 149 return GNUNET_NO;
148} 150}
149 151
@@ -157,10 +159,10 @@ CustomPeerMap_put(const struct CustomPeerMap *c_peer_map,
157 * GNUNET_NO otherwise 159 * GNUNET_NO otherwise
158 */ 160 */
159int 161int
160CustomPeerMap_contains_peer(const struct CustomPeerMap *c_peer_map, 162CustomPeerMap_contains_peer (const struct CustomPeerMap *c_peer_map,
161 const struct GNUNET_PeerIdentity *peer) 163 const struct GNUNET_PeerIdentity *peer)
162{ 164{
163 return GNUNET_CONTAINER_multipeermap_contains(c_peer_map->peer_map, peer); 165 return GNUNET_CONTAINER_multipeermap_contains (c_peer_map->peer_map, peer);
164} 166}
165 167
166/** 168/**
@@ -172,13 +174,13 @@ CustomPeerMap_contains_peer(const struct CustomPeerMap *c_peer_map,
172 * @return the index 174 * @return the index
173 */ 175 */
174static uint32_t * 176static uint32_t *
175CustomPeerMap_get_index_pointer(const struct CustomPeerMap *c_peer_map, 177CustomPeerMap_get_index_pointer (const struct CustomPeerMap *c_peer_map,
176 const struct GNUNET_PeerIdentity *peer) 178 const struct GNUNET_PeerIdentity *peer)
177{ 179{
178 uint32_t *index; 180 uint32_t *index;
179 181
180 GNUNET_assert(GNUNET_YES == CustomPeerMap_contains_peer(c_peer_map, peer)); 182 GNUNET_assert (GNUNET_YES == CustomPeerMap_contains_peer (c_peer_map, peer));
181 index = GNUNET_CONTAINER_multipeermap_get(c_peer_map->peer_map, peer); 183 index = GNUNET_CONTAINER_multipeermap_get (c_peer_map->peer_map, peer);
182 return index; 184 return index;
183} 185}
184 186
@@ -192,52 +194,52 @@ CustomPeerMap_get_index_pointer(const struct CustomPeerMap *c_peer_map,
192 * GNUNET_NO if map does not contain peer 194 * GNUNET_NO if map does not contain peer
193 */ 195 */
194int 196int
195CustomPeerMap_remove_peer(const struct CustomPeerMap *c_peer_map, 197CustomPeerMap_remove_peer (const struct CustomPeerMap *c_peer_map,
196 const struct GNUNET_PeerIdentity *peer) 198 const struct GNUNET_PeerIdentity *peer)
197{ 199{
198 uint32_t *index; 200 uint32_t *index;
199 struct GNUNET_PeerIdentity *p; 201 struct GNUNET_PeerIdentity *p;
200 uint32_t *last_index; 202 uint32_t *last_index;
201 struct GNUNET_PeerIdentity *last_p; 203 struct GNUNET_PeerIdentity *last_p;
202 204
203 if (GNUNET_NO == CustomPeerMap_contains_peer(c_peer_map, 205 if (GNUNET_NO == CustomPeerMap_contains_peer (c_peer_map,
204 peer)) 206 peer))
205 { 207 {
206 return GNUNET_NO; 208 return GNUNET_NO;
207 } 209 }
208 index = CustomPeerMap_get_index_pointer(c_peer_map, 210 index = CustomPeerMap_get_index_pointer (c_peer_map,
209 peer); 211 peer);
210 GNUNET_assert(*index < CustomPeerMap_size(c_peer_map)); 212 GNUNET_assert (*index < CustomPeerMap_size (c_peer_map));
211 /* Need to get the pointer stored in the hashmap to free it */ 213 /* Need to get the pointer stored in the hashmap to free it */
212 p = GNUNET_CONTAINER_multihashmap32_get(c_peer_map->hash_map, 214 p = GNUNET_CONTAINER_multihashmap32_get (c_peer_map->hash_map,
213 *index); 215 *index);
214 GNUNET_assert(NULL != p); 216 GNUNET_assert (NULL != p);
215 GNUNET_CONTAINER_multihashmap32_remove_all(c_peer_map->hash_map, 217 GNUNET_CONTAINER_multihashmap32_remove_all (c_peer_map->hash_map,
216 *index); 218 *index);
217 // TODO wrong peerid? 219 // TODO wrong peerid?
218 GNUNET_CONTAINER_multipeermap_remove_all(c_peer_map->peer_map, 220 GNUNET_CONTAINER_multipeermap_remove_all (c_peer_map->peer_map,
219 peer); 221 peer);
220 if (*index != CustomPeerMap_size(c_peer_map)) 222 if (*index != CustomPeerMap_size (c_peer_map))
221 { /* fill 'gap' with peer at last index */ 223 { /* fill 'gap' with peer at last index */
222 last_p = 224 last_p =
223 GNUNET_CONTAINER_multihashmap32_get(c_peer_map->hash_map, 225 GNUNET_CONTAINER_multihashmap32_get (c_peer_map->hash_map,
224 CustomPeerMap_size(c_peer_map)); 226 CustomPeerMap_size (c_peer_map));
225 GNUNET_assert(NULL != last_p); 227 GNUNET_assert (NULL != last_p);
226 last_index = GNUNET_CONTAINER_multipeermap_get(c_peer_map->peer_map, 228 last_index = GNUNET_CONTAINER_multipeermap_get (c_peer_map->peer_map,
227 last_p); 229 last_p);
228 GNUNET_assert(NULL != last_index); 230 GNUNET_assert (NULL != last_index);
229 GNUNET_assert(CustomPeerMap_size(c_peer_map) == *last_index); 231 GNUNET_assert (CustomPeerMap_size (c_peer_map) == *last_index);
230 GNUNET_CONTAINER_multihashmap32_put(c_peer_map->hash_map, 232 GNUNET_CONTAINER_multihashmap32_put (c_peer_map->hash_map,
231 *index, last_p, 233 *index, last_p,
232 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 234 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
233 GNUNET_CONTAINER_multihashmap32_remove_all(c_peer_map->hash_map, 235 GNUNET_CONTAINER_multihashmap32_remove_all (c_peer_map->hash_map,
234 *last_index); 236 *last_index);
235 *last_index = *index; 237 *last_index = *index;
236 } 238 }
237 GNUNET_free(index); 239 GNUNET_free (index);
238 GNUNET_assert(GNUNET_CONTAINER_multihashmap32_size(c_peer_map->hash_map) == 240 GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size (c_peer_map->hash_map) ==
239 GNUNET_CONTAINER_multipeermap_size(c_peer_map->peer_map)); 241 GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map));
240 GNUNET_free(p); 242 GNUNET_free (p);
241 return GNUNET_OK; 243 return GNUNET_OK;
242} 244}
243 245
@@ -251,14 +253,14 @@ CustomPeerMap_remove_peer(const struct CustomPeerMap *c_peer_map,
251 * if this index is not known, return NULL 253 * if this index is not known, return NULL
252 */ 254 */
253struct GNUNET_PeerIdentity * 255struct GNUNET_PeerIdentity *
254CustomPeerMap_get_peer_by_index(const struct CustomPeerMap *c_peer_map, 256CustomPeerMap_get_peer_by_index (const struct CustomPeerMap *c_peer_map,
255 uint32_t index) 257 uint32_t index)
256{ 258{
257 if (GNUNET_YES == 259 if (GNUNET_YES ==
258 GNUNET_CONTAINER_multihashmap32_contains(c_peer_map->hash_map, index)) 260 GNUNET_CONTAINER_multihashmap32_contains (c_peer_map->hash_map, index))
259 { 261 {
260 return GNUNET_CONTAINER_multihashmap32_get(c_peer_map->hash_map, index); 262 return GNUNET_CONTAINER_multihashmap32_get (c_peer_map->hash_map, index);
261 } 263 }
262 return NULL; 264 return NULL;
263} 265}
264 266
@@ -272,30 +274,30 @@ CustomPeerMap_get_peer_by_index(const struct CustomPeerMap *c_peer_map,
272 * GNUNET_NO if map does not contain (index of) peer 274 * GNUNET_NO if map does not contain (index of) peer
273 */ 275 */
274int 276int
275CustomPeerMap_remove_peer_by_index(const struct CustomPeerMap *c_peer_map, 277CustomPeerMap_remove_peer_by_index (const struct CustomPeerMap *c_peer_map,
276 uint32_t index) 278 uint32_t index)
277{ 279{
278 uint32_t *index_p; 280 uint32_t *index_p;
279 struct GNUNET_PeerIdentity *peer; 281 struct GNUNET_PeerIdentity *peer;
280 282
281 if (index >= CustomPeerMap_size(c_peer_map)) 283 if (index >= CustomPeerMap_size (c_peer_map))
282 { 284 {
283 return GNUNET_NO; 285 return GNUNET_NO;
284 } 286 }
285 GNUNET_assert(GNUNET_CONTAINER_multihashmap32_size(c_peer_map->hash_map) == 287 GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size (c_peer_map->hash_map) ==
286 GNUNET_CONTAINER_multipeermap_size(c_peer_map->peer_map)); 288 GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map));
287 if (GNUNET_NO == 289 if (GNUNET_NO ==
288 GNUNET_CONTAINER_multihashmap32_contains(c_peer_map->hash_map, index)) 290 GNUNET_CONTAINER_multihashmap32_contains (c_peer_map->hash_map, index))
289 { 291 {
290 return GNUNET_NO; 292 return GNUNET_NO;
291 } 293 }
292 peer = CustomPeerMap_get_peer_by_index(c_peer_map, index); 294 peer = CustomPeerMap_get_peer_by_index (c_peer_map, index);
293 GNUNET_assert(NULL != peer); 295 GNUNET_assert (NULL != peer);
294 index_p = CustomPeerMap_get_index_pointer(c_peer_map, peer); 296 index_p = CustomPeerMap_get_index_pointer (c_peer_map, peer);
295 GNUNET_assert(index == *index_p); 297 GNUNET_assert (index == *index_p);
296 CustomPeerMap_remove_peer(c_peer_map, peer); 298 CustomPeerMap_remove_peer (c_peer_map, peer);
297 GNUNET_assert(GNUNET_CONTAINER_multihashmap32_size(c_peer_map->hash_map) == 299 GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size (c_peer_map->hash_map) ==
298 GNUNET_CONTAINER_multipeermap_size(c_peer_map->peer_map)); 300 GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map));
299 return GNUNET_OK; 301 return GNUNET_OK;
300} 302}
301 303
@@ -307,18 +309,21 @@ CustomPeerMap_remove_peer_by_index(const struct CustomPeerMap *c_peer_map,
307 * @return size of the map 309 * @return size of the map
308 */ 310 */
309void 311void
310CustomPeerMap_clear(const struct CustomPeerMap *c_peer_map) 312CustomPeerMap_clear (const struct CustomPeerMap *c_peer_map)
311{ 313{
312 while (0 < CustomPeerMap_size(c_peer_map)) 314 while (0 < CustomPeerMap_size (c_peer_map))
313 { 315 {
314 GNUNET_assert(GNUNET_YES == 316 GNUNET_assert (GNUNET_YES ==
315 GNUNET_CONTAINER_multihashmap32_contains(c_peer_map->hash_map, 317 GNUNET_CONTAINER_multihashmap32_contains (
316 CustomPeerMap_size(c_peer_map) - 1)); 318 c_peer_map->hash_map,
317 GNUNET_assert(GNUNET_OK == 319 CustomPeerMap_size (
318 CustomPeerMap_remove_peer_by_index(c_peer_map, 320 c_peer_map) - 1));
319 CustomPeerMap_size(c_peer_map) - 1)); 321 GNUNET_assert (GNUNET_OK ==
320 } 322 CustomPeerMap_remove_peer_by_index (c_peer_map,
321 GNUNET_assert(0 == CustomPeerMap_size(c_peer_map)); 323 CustomPeerMap_size (
324 c_peer_map) - 1));
325 }
326 GNUNET_assert (0 == CustomPeerMap_size (c_peer_map));
322} 327}
323 328
324/** 329/**
@@ -327,12 +332,12 @@ CustomPeerMap_clear(const struct CustomPeerMap *c_peer_map)
327 * @param c_peer_map the map to destroy 332 * @param c_peer_map the map to destroy
328 */ 333 */
329void 334void
330CustomPeerMap_destroy(struct CustomPeerMap *c_peer_map) 335CustomPeerMap_destroy (struct CustomPeerMap *c_peer_map)
331{ 336{
332 CustomPeerMap_clear(c_peer_map); 337 CustomPeerMap_clear (c_peer_map);
333 GNUNET_CONTAINER_multihashmap32_destroy(c_peer_map->hash_map); 338 GNUNET_CONTAINER_multihashmap32_destroy (c_peer_map->hash_map);
334 GNUNET_CONTAINER_multipeermap_destroy(c_peer_map->peer_map); 339 GNUNET_CONTAINER_multipeermap_destroy (c_peer_map->peer_map);
335 GNUNET_free(c_peer_map); 340 GNUNET_free (c_peer_map);
336} 341}
337 342
338/* end of gnunet-service-rps_custommap.c */ 343/* 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 210ab56c6..15591b67a 100644
--- a/src/rps/gnunet-service-rps_custommap.h
+++ b/src/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 */
63struct CustomPeerMap * 63struct CustomPeerMap *
64CustomPeerMap_create(unsigned int len); 64CustomPeerMap_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 */
73unsigned int 73unsigned int
74CustomPeerMap_size(const struct CustomPeerMap *c_peer_map); 74CustomPeerMap_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 */
85int 85int
86CustomPeerMap_put(const struct CustomPeerMap *c_peer_map, 86CustomPeerMap_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 */
98int 98int
99CustomPeerMap_contains_peer(const struct CustomPeerMap *c_peer_map, 99CustomPeerMap_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 */
111int 111int
112CustomPeerMap_remove_peer(const struct CustomPeerMap *c_peer_map, 112CustomPeerMap_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 */
124struct GNUNET_PeerIdentity * 124struct GNUNET_PeerIdentity *
125CustomPeerMap_get_peer_by_index(const struct CustomPeerMap *c_peer_map, 125CustomPeerMap_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 */
137int 137int
138CustomPeerMap_remove_peer_by_index(const struct CustomPeerMap *c_peer_map, 138CustomPeerMap_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 */
148void 148void
149CustomPeerMap_clear(const struct CustomPeerMap *c_peer_map); 149CustomPeerMap_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 */
156void 156void
157CustomPeerMap_destroy(struct CustomPeerMap *c_peer_map); 157CustomPeerMap_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 a3f778979..7573fd4eb 100644
--- a/src/rps/gnunet-service-rps_sampler.c
+++ b/src/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'?
@@ -68,7 +68,8 @@ typedef void
68 * 68 *
69 * Meant to be an entry in an DLL. 69 * Meant to be an entry in an DLL.
70 */ 70 */
71struct SamplerNotifyUpdateCTX { 71struct SamplerNotifyUpdateCTX
72{
72 /** 73 /**
73 * @brief The Callback to call on updates 74 * @brief The Callback to call on updates
74 */ 75 */
@@ -106,13 +107,14 @@ typedef void
106 * Only used internally 107 * Only used internally
107 */ 108 */
108static void 109static void
109sampler_get_rand_peer(void *cls); 110sampler_get_rand_peer (void *cls);
110 111
111 112
112/** 113/**
113 * Closure to _get_n_rand_peers_ready_cb() 114 * Closure to _get_n_rand_peers_ready_cb()
114 */ 115 */
115struct RPS_SamplerRequestHandle { 116struct RPS_SamplerRequestHandle
117{
116 /** 118 /**
117 * DLL 119 * DLL
118 */ 120 */
@@ -159,7 +161,7 @@ struct RPS_SamplerRequestHandle {
159///** 161///**
160// * Global sampler variable. 162// * Global sampler variable.
161// */ 163// */
162//struct RPS_Sampler *sampler; 164// struct RPS_Sampler *sampler;
163 165
164 166
165/** 167/**
@@ -175,7 +177,7 @@ static size_t max_size;
175/** 177/**
176 * The size the extended sampler elements currently have. 178 * The size the extended sampler elements currently have.
177 */ 179 */
178//static size_t extra_size; 180// static size_t extra_size;
179 181
180/** 182/**
181 * Inedex to the sampler element that is the next to be returned 183 * Inedex to the sampler element that is the next to be returned
@@ -191,8 +193,8 @@ static uint32_t client_get_index;
191 * @return a handle to a sampler that consists of sampler elements. 193 * @return a handle to a sampler that consists of sampler elements.
192 */ 194 */
193struct RPS_Sampler * 195struct RPS_Sampler *
194RPS_sampler_init(size_t init_size, 196RPS_sampler_init (size_t init_size,
195 struct GNUNET_TIME_Relative max_round_interval) 197 struct GNUNET_TIME_Relative max_round_interval)
196{ 198{
197 struct RPS_Sampler *sampler; 199 struct RPS_Sampler *sampler;
198 200
@@ -200,17 +202,17 @@ RPS_sampler_init(size_t init_size,
200 min_size = 10; // TODO make input to _samplers_init() 202 min_size = 10; // TODO make input to _samplers_init()
201 max_size = 1000; // TODO make input to _samplers_init() 203 max_size = 1000; // TODO make input to _samplers_init()
202 204
203 sampler = GNUNET_new(struct RPS_Sampler); 205 sampler = GNUNET_new (struct RPS_Sampler);
204 206
205 sampler->max_round_interval = max_round_interval; 207 sampler->max_round_interval = max_round_interval;
206 sampler->get_peers = sampler_get_rand_peer; 208 sampler->get_peers = sampler_get_rand_peer;
207 //sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity); 209 // sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity);
208 //GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, min_size); 210 // GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, min_size);
209 RPS_sampler_resize(sampler, init_size); 211 RPS_sampler_resize (sampler, init_size);
210 212
211 client_get_index = 0; 213 client_get_index = 0;
212 214
213 //GNUNET_assert (init_size == sampler->sampler_size); 215 // GNUNET_assert (init_size == sampler->sampler_size);
214 return sampler; 216 return sampler;
215} 217}
216 218
@@ -222,7 +224,7 @@ RPS_sampler_init(size_t init_size,
222 * Only used internally 224 * Only used internally
223 */ 225 */
224static void 226static void
225sampler_get_rand_peer(void *cls) 227sampler_get_rand_peer (void *cls)
226{ 228{
227 struct GetPeerCls *gpc = cls; 229 struct GetPeerCls *gpc = cls;
228 uint32_t r_index; 230 uint32_t r_index;
@@ -236,28 +238,29 @@ sampler_get_rand_peer(void *cls)
236 * Choose the r_index of the peer we want to return 238 * Choose the r_index of the peer we want to return
237 * at random from the interval of the gossip list 239 * at random from the interval of the gossip list
238 */ 240 */
239 r_index = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG, 241 r_index = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
240 sampler->sampler_size); 242 sampler->sampler_size);
241 243
242 if (EMPTY == sampler->sampler_elements[r_index]->is_empty) 244 if (EMPTY == sampler->sampler_elements[r_index]->is_empty)
243 { 245 {
244 //LOG (GNUNET_ERROR_TYPE_DEBUG, 246 // LOG (GNUNET_ERROR_TYPE_DEBUG,
245 // "Not returning randomly selected, empty PeerID. - Rescheduling.\n"); 247 // "Not returning randomly selected, empty PeerID. - Rescheduling.\n");
246 248
247 gpc->notify_ctx = 249 gpc->notify_ctx =
248 sampler_notify_on_update(sampler, 250 sampler_notify_on_update (sampler,
249 &sampler_get_rand_peer, 251 &sampler_get_rand_peer,
250 gpc); 252 gpc);
251 return; 253 return;
252 } 254 }
253 255
254 GNUNET_CONTAINER_DLL_remove(gpc->req_handle->gpc_head, 256 GNUNET_CONTAINER_DLL_remove (gpc->req_handle->gpc_head,
255 gpc->req_handle->gpc_tail, 257 gpc->req_handle->gpc_tail,
256 gpc); 258 gpc);
257 *gpc->id = sampler->sampler_elements[r_index]->peer_id; 259 *gpc->id = sampler->sampler_elements[r_index]->peer_id;
258 gpc->cont(gpc->cont_cls, gpc->id, 0, sampler->sampler_elements[r_index]->num_peers); 260 gpc->cont (gpc->cont_cls, gpc->id, 0,
261 sampler->sampler_elements[r_index]->num_peers);
259 262
260 GNUNET_free(gpc); 263 GNUNET_free (gpc);
261} 264}
262 265
263 266
diff --git a/src/rps/gnunet-service-rps_sampler.h b/src/rps/gnunet-service-rps_sampler.h
index 8bccb8431..f3a8c9763 100644
--- a/src/rps/gnunet-service-rps_sampler.h
+++ b/src/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 */
50unsigned int 50unsigned int
51RPS_sampler_get_size(struct RPS_Sampler *sampler); 51RPS_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 */
60void 60void
61RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size); 61RPS_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 */
71struct RPS_Sampler * 71struct RPS_Sampler *
72RPS_sampler_init(size_t init_size, 72RPS_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/**
@@ -80,8 +80,8 @@ RPS_sampler_init(size_t init_size,
80 * @param id the PeerID that is put in the sampler 80 * @param id the PeerID that is put in the sampler
81 */ 81 */
82void 82void
83RPS_sampler_update(struct RPS_Sampler *sampler, 83RPS_sampler_update (struct RPS_Sampler *sampler,
84 const struct GNUNET_PeerIdentity *id); 84 const struct GNUNET_PeerIdentity *id);
85 85
86 86
87/** 87/**
@@ -100,8 +100,8 @@ RPS_sampler_update(struct RPS_Sampler *sampler,
100 * @param id the id of the samplers to update. 100 * @param id the id of the samplers to update.
101 */ 101 */
102void 102void
103RPS_sampler_reinitialise_by_value(struct RPS_Sampler *sampler, 103RPS_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 */
121struct RPS_SamplerRequestHandle * 121struct RPS_SamplerRequestHandle *
122RPS_sampler_get_n_rand_peers(struct RPS_Sampler *sampler, 122RPS_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 */
132void 132void
133RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle); 133RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle);
134 134
135 135
136/** 136/**
@@ -142,8 +142,8 @@ RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle);
142 * @return the number of occurrences of id. 142 * @return the number of occurrences of id.
143 */ 143 */
144uint32_t 144uint32_t
145RPS_sampler_count_id(struct RPS_Sampler *sampler, 145RPS_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/**
@@ -152,7 +152,7 @@ RPS_sampler_count_id(struct RPS_Sampler *sampler,
152 * @param sampler the sampler to destroy. 152 * @param sampler the sampler to destroy.
153 */ 153 */
154void 154void
155RPS_sampler_destroy(struct RPS_Sampler *sampler); 155RPS_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 6d5305f03..17b3be6d2 100644
--- a/src/rps/gnunet-service-rps_sampler_elem.c
+++ b/src/rps/gnunet-service-rps_sampler_elem.c
@@ -32,7 +32,7 @@
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/***********************************************************************
@@ -47,18 +47,18 @@
47 * @param sampler_el The sampler element to (re-) initialise 47 * @param sampler_el The sampler element to (re-) initialise
48 */ 48 */
49void 49void
50RPS_sampler_elem_reinit(struct RPS_SamplerElement *sampler_elem) 50RPS_sampler_elem_reinit (struct RPS_SamplerElement *sampler_elem)
51{ 51{
52 sampler_elem->is_empty = EMPTY; 52 sampler_elem->is_empty = EMPTY;
53 53
54 // I guess I don't need to call GNUNET_CRYPTO_hmac_derive_key()... 54 // I guess I don't need to call GNUNET_CRYPTO_hmac_derive_key()...
55 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_STRONG, 55 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
56 &(sampler_elem->auth_key.key), 56 &(sampler_elem->auth_key.key),
57 GNUNET_CRYPTO_HASH_LENGTH); 57 GNUNET_CRYPTO_HASH_LENGTH);
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 */
75struct RPS_SamplerElement * 75struct RPS_SamplerElement *
76RPS_sampler_elem_create(void) 76RPS_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 */
93void 93void
94RPS_sampler_elem_destroy(struct RPS_SamplerElement *sampler_elem) 94RPS_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,51 @@ 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 */
106void 106void
107RPS_sampler_elem_next(struct RPS_SamplerElement *sampler_elem, 107RPS_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)
115 { 127 {
116 LOG(GNUNET_ERROR_TYPE_DEBUG, "Have already PeerID %s\n", 128 LOG (GNUNET_ERROR_TYPE_DEBUG,
117 GNUNET_i2s(&(sampler_elem->peer_id))); 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++;
118 } 135 }
119 else 136 else if (0 > GNUNET_CRYPTO_hash_cmp (&other_hash,
137 &sampler_elem->peer_id_hash))
138 {
139 LOG (GNUNET_ERROR_TYPE_DEBUG, "Discarding old PeerID %s\n",
140 GNUNET_i2s (&sampler_elem->peer_id));
141 sampler_elem->peer_id = *new_ID;
142 sampler_elem->peer_id_hash = other_hash;
143
144 sampler_elem->num_change++;
145 }
146 else
120 { 147 {
121 GNUNET_CRYPTO_hmac(&sampler_elem->auth_key, 148 LOG (GNUNET_ERROR_TYPE_DEBUG, "Keeping old PeerID %s\n",
122 new_ID, 149 GNUNET_i2s (&sampler_elem->peer_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 }
150 } 150 }
151 }
151 sampler_elem->is_empty = NOT_EMPTY; 152 sampler_elem->is_empty = NOT_EMPTY;
152} 153}
153 154
@@ -158,8 +159,8 @@ RPS_sampler_elem_next(struct RPS_SamplerElement *sampler_elem,
158 * @param auth_key the key to use 159 * @param auth_key the key to use
159 */ 160 */
160void 161void
161RPS_sampler_elem_set(struct RPS_SamplerElement *sampler_elem, 162RPS_sampler_elem_set (struct RPS_SamplerElement *sampler_elem,
162 struct GNUNET_CRYPTO_AuthKey auth_key) 163 struct GNUNET_CRYPTO_AuthKey auth_key)
163{ 164{
164 sampler_elem->auth_key = auth_key; 165 sampler_elem->auth_key = auth_key;
165} 166}
diff --git a/src/rps/gnunet-service-rps_sampler_elem.h b/src/rps/gnunet-service-rps_sampler_elem.h
index c22b7413c..98959a88f 100644
--- a/src/rps/gnunet-service-rps_sampler_elem.h
+++ b/src/rps/gnunet-service-rps_sampler_elem.h
@@ -37,7 +37,8 @@
37/** 37/**
38 * Used to indicate whether a sampler element is empty. 38 * Used to indicate whether a sampler element is empty.
39 */ 39 */
40enum RPS_SamplerEmpty { 40enum RPS_SamplerEmpty
41{
41 NOT_EMPTY = 0x0, 42 NOT_EMPTY = 0x0,
42 EMPTY = 0x1 43 EMPTY = 0x1
43}; 44};
@@ -45,7 +46,8 @@ enum RPS_SamplerEmpty {
45/** 46/**
46 * A sampler element sampling one PeerID at a time. 47 * A sampler element sampling one PeerID at a time.
47 */ 48 */
48struct RPS_SamplerElement { 49struct RPS_SamplerElement
50{
49 /** 51 /**
50 * Min-wise linear permutation used by this sampler. 52 * Min-wise linear permutation used by this sampler.
51 * 53 *
@@ -102,7 +104,7 @@ struct RPS_SamplerElement {
102 * @param sampler_el The sampler element to (re-) initialise 104 * @param sampler_el The sampler element to (re-) initialise
103 */ 105 */
104void 106void
105RPS_sampler_elem_reinit(struct RPS_SamplerElement *sampler_elem); 107RPS_sampler_elem_reinit (struct RPS_SamplerElement *sampler_elem);
106 108
107 109
108/** 110/**
@@ -114,7 +116,7 @@ RPS_sampler_elem_reinit(struct RPS_SamplerElement *sampler_elem);
114 * @return a newly created RPS_SamplerElement which currently holds no id. 116 * @return a newly created RPS_SamplerElement which currently holds no id.
115 */ 117 */
116struct RPS_SamplerElement * 118struct RPS_SamplerElement *
117RPS_sampler_elem_create(void); 119RPS_sampler_elem_create (void);
118 120
119 121
120/** 122/**
@@ -123,7 +125,7 @@ RPS_sampler_elem_create(void);
123 * @param sampler_elem the element to destroy 125 * @param sampler_elem the element to destroy
124 */ 126 */
125void 127void
126RPS_sampler_elem_destroy(struct RPS_SamplerElement *sampler_elem); 128RPS_sampler_elem_destroy (struct RPS_SamplerElement *sampler_elem);
127 129
128 130
129/** 131/**
@@ -133,8 +135,8 @@ RPS_sampler_elem_destroy(struct RPS_SamplerElement *sampler_elem);
133 * @param new_ID The PeerID to update with 135 * @param new_ID The PeerID to update with
134 */ 136 */
135void 137void
136RPS_sampler_elem_next(struct RPS_SamplerElement *sampler_elem, 138RPS_sampler_elem_next (struct RPS_SamplerElement *sampler_elem,
137 const struct GNUNET_PeerIdentity *new_ID); 139 const struct GNUNET_PeerIdentity *new_ID);
138 140
139/** 141/**
140 * Set the min-wise independent function of the given sampler element. 142 * Set the min-wise independent function of the given sampler element.
@@ -143,8 +145,8 @@ RPS_sampler_elem_next(struct RPS_SamplerElement *sampler_elem,
143 * @param auth_key the key to use 145 * @param auth_key the key to use
144 */ 146 */
145void 147void
146RPS_sampler_elem_set(struct RPS_SamplerElement *sampler_elem, 148RPS_sampler_elem_set (struct RPS_SamplerElement *sampler_elem,
147 struct GNUNET_CRYPTO_AuthKey auth_key); 149 struct GNUNET_CRYPTO_AuthKey auth_key);
148 150
149 151
150#endif /* RPS_SAMPLER_ELEM_H */ 152#endif /* RPS_SAMPLER_ELEM_H */
diff --git a/src/rps/gnunet-service-rps_view.c b/src/rps/gnunet-service-rps_view.c
index bedd2ae6c..5de7c84dc 100644
--- a/src/rps/gnunet-service-rps_view.c
+++ b/src/rps/gnunet-service-rps_view.c
@@ -28,7 +28,8 @@
28#include "gnunet-service-rps_view.h" 28#include "gnunet-service-rps_view.h"
29#include <inttypes.h> 29#include <inttypes.h>
30 30
31struct View { 31struct View
32{
32 /** 33 /**
33 * Array containing the peers 34 * Array containing the peers
34 */ 35 */
@@ -53,15 +54,15 @@ struct View {
53 * @return The newly created view 54 * @return The newly created view
54 */ 55 */
55struct View * 56struct View *
56View_create(uint32_t len) 57View_create (uint32_t len)
57{ 58{
58 struct View *view; 59 struct View *view;
59 60
60 view = GNUNET_new(struct View); 61 view = GNUNET_new (struct View);
61 view->length = len; 62 view->length = len;
62 view->array = GNUNET_new_array(len, struct GNUNET_PeerIdentity); 63 view->array = GNUNET_new_array (len, struct GNUNET_PeerIdentity);
63 view->mpm = 64 view->mpm =
64 GNUNET_CONTAINER_multipeermap_create(len, GNUNET_NO); /* might even be 65 GNUNET_CONTAINER_multipeermap_create (len, GNUNET_NO); /* might even be
65 * set to _YES */ 66 * set to _YES */
66 return view; 67 return view;
67} 68}
@@ -76,38 +77,38 @@ View_create(uint32_t len)
76 * @param len the (maximum) length for the view 77 * @param len the (maximum) length for the view
77 */ 78 */
78void 79void
79View_change_len(struct View *view, 80View_change_len (struct View *view,
80 uint32_t len) 81 uint32_t len)
81{ 82{
82 uint32_t i; 83 uint32_t i;
83 uint32_t *index; 84 uint32_t *index;
84 85
85 if (GNUNET_CONTAINER_multipeermap_size(view->mpm) < len) 86 if (GNUNET_CONTAINER_multipeermap_size (view->mpm) < len)
86 { /* Simply shrink */ 87 { /* Simply shrink */
87 /* We might simply clear and free the left over space */ 88 /* We might simply clear and free the left over space */
88 GNUNET_array_grow(view->array, view->length, len); 89 GNUNET_array_grow (view->array, view->length, len);
89 } 90 }
90 else /* We have to remove elements */ 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 }
100 GNUNET_array_grow (view->array, view->length, len);
101 GNUNET_CONTAINER_multipeermap_destroy (view->mpm);
102 view->mpm = GNUNET_CONTAINER_multipeermap_create (len, GNUNET_NO);
103 for (i = 0; i < len; i++)
91 { 104 {
92 /* TODO find a way to preserve indices */ 105 index = GNUNET_new (uint32_t);
93 for (i = 0; i < len; i++) 106 *index = i;
94 { 107 GNUNET_CONTAINER_multipeermap_put (view->mpm, &view->array[i], index,
95 index = GNUNET_CONTAINER_multipeermap_get(view->mpm, &view->array[i]); 108 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
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 GNUNET_assert(view->length == len); 110 }
111 GNUNET_assert (view->length == len);
111} 112}
112 113
113 114
@@ -118,7 +119,7 @@ View_change_len(struct View *view,
118 * @return the view in array representation 119 * @return the view in array representation
119 */ 120 */
120const struct GNUNET_PeerIdentity * 121const struct GNUNET_PeerIdentity *
121View_get_as_array(const struct View *view) 122View_get_as_array (const struct View *view)
122{ 123{
123 return view->array; 124 return view->array;
124} 125}
@@ -131,9 +132,9 @@ View_get_as_array(const struct View *view)
131 * @return current number of actually contained peers 132 * @return current number of actually contained peers
132 */ 133 */
133unsigned int 134unsigned int
134View_size(const struct View *view) 135View_size (const struct View *view)
135{ 136{
136 return GNUNET_CONTAINER_multipeermap_size(view->mpm); 137 return GNUNET_CONTAINER_multipeermap_size (view->mpm);
137} 138}
138 139
139 140
@@ -147,25 +148,25 @@ View_size(const struct View *view)
147 * GNUNET_NO if peer was not inserted 148 * GNUNET_NO if peer was not inserted
148 */ 149 */
149int 150int
150View_put(struct View *view, 151View_put (struct View *view,
151 const struct GNUNET_PeerIdentity *peer) 152 const struct GNUNET_PeerIdentity *peer)
152{ 153{
153 uint32_t *index; 154 uint32_t *index;
154 155
155 if ((view->length <= View_size(view)) || /* If array is 'full' */ 156 if ((view->length <= View_size (view)) || /* If array is 'full' */
156 (GNUNET_YES == View_contains_peer(view, peer))) 157 (GNUNET_YES == View_contains_peer (view, peer)))
157 { 158 {
158 return GNUNET_NO; 159 return GNUNET_NO;
159 } 160 }
160 else 161 else
161 { 162 {
162 index = GNUNET_new(uint32_t); 163 index = GNUNET_new (uint32_t);
163 *index = (uint32_t)View_size(view); 164 *index = (uint32_t) View_size (view);
164 view->array[*index] = *peer; 165 view->array[*index] = *peer;
165 GNUNET_CONTAINER_multipeermap_put(view->mpm, peer, index, 166 GNUNET_CONTAINER_multipeermap_put (view->mpm, peer, index,
166 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 167 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
167 return GNUNET_OK; 168 return GNUNET_OK;
168 } 169 }
169} 170}
170 171
171 172
@@ -179,10 +180,10 @@ View_put(struct View *view,
179 * GNUNET_NO otherwise 180 * GNUNET_NO otherwise
180 */ 181 */
181int 182int
182View_contains_peer(const struct View *view, 183View_contains_peer (const struct View *view,
183 const struct GNUNET_PeerIdentity *peer) 184 const struct GNUNET_PeerIdentity *peer)
184{ 185{
185 return GNUNET_CONTAINER_multipeermap_contains(view->mpm, peer); 186 return GNUNET_CONTAINER_multipeermap_contains (view->mpm, peer);
186} 187}
187 188
188 189
@@ -196,32 +197,32 @@ View_contains_peer(const struct View *view,
196 * GNUNET_NO if view does not contain peer 197 * GNUNET_NO if view does not contain peer
197 */ 198 */
198int 199int
199View_remove_peer(struct View *view, 200View_remove_peer (struct View *view,
200 const struct GNUNET_PeerIdentity *peer) 201 const struct GNUNET_PeerIdentity *peer)
201{ 202{
202 uint32_t *index; 203 uint32_t *index;
203 uint32_t *swap_index; 204 uint32_t *swap_index;
204 uint32_t last_index; 205 uint32_t last_index;
205 206
206 if (GNUNET_NO == View_contains_peer(view, peer)) 207 if (GNUNET_NO == View_contains_peer (view, peer))
207 { 208 {
208 return GNUNET_NO; 209 return GNUNET_NO;
209 } 210 }
210 index = GNUNET_CONTAINER_multipeermap_get(view->mpm, peer); 211 index = GNUNET_CONTAINER_multipeermap_get (view->mpm, peer);
211 GNUNET_assert(NULL != index); 212 GNUNET_assert (NULL != index);
212 last_index = View_size(view) - 1; 213 last_index = View_size (view) - 1;
213 if (*index < last_index) 214 if (*index < last_index)
214 { /* Fill the 'gap' in the array with the last peer */ 215 { /* Fill the 'gap' in the array with the last peer */
215 view->array[*index] = view->array[last_index]; 216 view->array[*index] = view->array[last_index];
216 GNUNET_assert(GNUNET_YES == View_contains_peer(view, 217 GNUNET_assert (GNUNET_YES == View_contains_peer (view,
217 &view->array[last_index])); 218 &view->array[last_index]));
218 swap_index = GNUNET_CONTAINER_multipeermap_get(view->mpm, 219 swap_index = GNUNET_CONTAINER_multipeermap_get (view->mpm,
219 &view->array[last_index]); 220 &view->array[last_index]);
220 GNUNET_assert(NULL != swap_index); 221 GNUNET_assert (NULL != swap_index);
221 *swap_index = *index; 222 *swap_index = *index;
222 GNUNET_free(index); 223 GNUNET_free (index);
223 } 224 }
224 GNUNET_CONTAINER_multipeermap_remove_all(view->mpm, peer); 225 GNUNET_CONTAINER_multipeermap_remove_all (view->mpm, peer);
225 return GNUNET_OK; 226 return GNUNET_OK;
226} 227}
227 228
@@ -236,17 +237,17 @@ View_remove_peer(struct View *view,
236 * NULL if this index is not known 237 * NULL if this index is not known
237 */ 238 */
238const struct GNUNET_PeerIdentity * 239const struct GNUNET_PeerIdentity *
239View_get_peer_by_index(const struct View *view, 240View_get_peer_by_index (const struct View *view,
240 uint32_t index) 241 uint32_t index)
241{ 242{
242 if (index < GNUNET_CONTAINER_multipeermap_size(view->mpm)) 243 if (index < GNUNET_CONTAINER_multipeermap_size (view->mpm))
243 { 244 {
244 return &view->array[index]; 245 return &view->array[index];
245 } 246 }
246 else 247 else
247 { 248 {
248 return NULL; 249 return NULL;
249 } 250 }
250} 251}
251 252
252 253
@@ -256,20 +257,21 @@ View_get_peer_by_index(const struct View *view,
256 * @param view The view to clear 257 * @param view The view to clear
257 */ 258 */
258void 259void
259View_clear(struct View *view) 260View_clear (struct View *view)
260{ 261{
261 for (uint32_t i = 0; 0 < View_size(view); i++) 262 for (uint32_t i = 0; 0 < View_size (view); i++)
262 { /* Need to free indices stored at peers */ 263 { /* Need to free indices stored at peers */
263 uint32_t *index; 264 uint32_t *index;
264 265
265 GNUNET_assert(GNUNET_YES == 266 GNUNET_assert (GNUNET_YES ==
266 GNUNET_CONTAINER_multipeermap_contains(view->mpm, &view->array[i])); 267 GNUNET_CONTAINER_multipeermap_contains (view->mpm,
267 index = GNUNET_CONTAINER_multipeermap_get(view->mpm, &view->array[i]); 268 &view->array[i]));
268 GNUNET_assert(NULL != index); 269 index = GNUNET_CONTAINER_multipeermap_get (view->mpm, &view->array[i]);
269 GNUNET_free(index); 270 GNUNET_assert (NULL != index);
270 GNUNET_CONTAINER_multipeermap_remove_all(view->mpm, &view->array[i]); 271 GNUNET_free (index);
271 } 272 GNUNET_CONTAINER_multipeermap_remove_all (view->mpm, &view->array[i]);
272 GNUNET_assert(0 == View_size(view)); 273 }
274 GNUNET_assert (0 == View_size (view));
273} 275}
274 276
275 277
@@ -279,13 +281,13 @@ View_clear(struct View *view)
279 * @param view the view to destroy 281 * @param view the view to destroy
280 */ 282 */
281void 283void
282View_destroy(struct View *view) 284View_destroy (struct View *view)
283{ 285{
284 View_clear(view); 286 View_clear (view);
285 GNUNET_free(view->array); 287 GNUNET_free (view->array);
286 view->array = NULL; 288 view->array = NULL;
287 GNUNET_CONTAINER_multipeermap_destroy(view->mpm); 289 GNUNET_CONTAINER_multipeermap_destroy (view->mpm);
288 GNUNET_free(view); 290 GNUNET_free (view);
289} 291}
290 292
291/* end of gnunet-service-rps_view.c */ 293/* 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 0ceed5432..4d42272c1 100644
--- a/src/rps/gnunet-service-rps_view.h
+++ b/src/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 */
37struct View * 37struct View *
38View_create(unsigned int len); 38View_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 */
49void 49void
50View_change_len(struct View *view, 50View_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 */
58const struct GNUNET_PeerIdentity * 58const struct GNUNET_PeerIdentity *
59View_get_as_array(const struct View *view); 59View_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 */
68unsigned int 68unsigned int
69View_size(const struct View *view); 69View_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 */
81int 81int
82View_put(struct View *view, 82View_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 */
95int 95int
96View_contains_peer(const struct View *view, 96View_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 */
109int 109int
110View_remove_peer(struct View *view, 110View_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 */
123const struct GNUNET_PeerIdentity * 123const struct GNUNET_PeerIdentity *
124View_get_peer_by_index(const struct View *view, 124View_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 */
133void 133void
134View_clear(struct View *view); 134View_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 */
142void 142void
143View_destroy(struct View *view); 143View_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 b4ac5f6f8..5ab854e01 100644
--- a/src/rps/rps-sampler_client.c
+++ b/src/rps/rps-sampler_client.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'?
@@ -68,7 +68,8 @@ typedef void
68 * 68 *
69 * Meant to be an entry in an DLL. 69 * Meant to be an entry in an DLL.
70 */ 70 */
71struct SamplerNotifyUpdateCTX { 71struct SamplerNotifyUpdateCTX
72{
72 /** 73 /**
73 * @brief The Callback to call on updates 74 * @brief The Callback to call on updates
74 */ 75 */
@@ -106,13 +107,14 @@ typedef void
106 * corrsponding peer to the client. 107 * corrsponding peer to the client.
107 */ 108 */
108static void 109static void
109sampler_mod_get_rand_peer(void *cls); 110sampler_mod_get_rand_peer (void *cls);
110 111
111 112
112/** 113/**
113 * Closure to _get_n_rand_peers_ready_cb() 114 * Closure to _get_n_rand_peers_ready_cb()
114 */ 115 */
115struct RPS_SamplerRequestHandle { 116struct RPS_SamplerRequestHandle
117{
116 /** 118 /**
117 * DLL 119 * DLL
118 */ 120 */
@@ -160,7 +162,8 @@ struct RPS_SamplerRequestHandle {
160/** 162/**
161 * Closure to _get_rand_peer_info() 163 * Closure to _get_rand_peer_info()
162 */ 164 */
163struct RPS_SamplerRequestHandleSingleInfo { 165struct RPS_SamplerRequestHandleSingleInfo
166{
164 /** 167 /**
165 * DLL 168 * DLL
166 */ 169 */
@@ -198,7 +201,7 @@ struct RPS_SamplerRequestHandleSingleInfo {
198///** 201///**
199// * Global sampler variable. 202// * Global sampler variable.
200// */ 203// */
201//struct RPS_Sampler *sampler; 204// struct RPS_Sampler *sampler;
202 205
203 206
204/** 207/**
@@ -214,7 +217,7 @@ static size_t max_size;
214/** 217/**
215 * The size the extended sampler elements currently have. 218 * The size the extended sampler elements currently have.
216 */ 219 */
217//static size_t extra_size; 220// static size_t extra_size;
218 221
219/** 222/**
220 * Inedex to the sampler element that is the next to be returned 223 * Inedex to the sampler element that is the next to be returned
@@ -230,8 +233,8 @@ static uint32_t client_get_index;
230 * @return a handle to a sampler that consists of sampler elements. 233 * @return a handle to a sampler that consists of sampler elements.
231 */ 234 */
232struct RPS_Sampler * 235struct RPS_Sampler *
233RPS_sampler_mod_init(size_t init_size, 236RPS_sampler_mod_init (size_t init_size,
234 struct GNUNET_TIME_Relative max_round_interval) 237 struct GNUNET_TIME_Relative max_round_interval)
235{ 238{
236 struct RPS_Sampler *sampler; 239 struct RPS_Sampler *sampler;
237 240
@@ -239,17 +242,17 @@ RPS_sampler_mod_init(size_t init_size,
239 min_size = 10; // TODO make input to _samplers_init() 242 min_size = 10; // TODO make input to _samplers_init()
240 max_size = 1000; // TODO make input to _samplers_init() 243 max_size = 1000; // TODO make input to _samplers_init()
241 244
242 sampler = GNUNET_new(struct RPS_Sampler); 245 sampler = GNUNET_new (struct RPS_Sampler);
243 sampler->max_round_interval = max_round_interval; 246 sampler->max_round_interval = max_round_interval;
244 sampler->get_peers = sampler_mod_get_rand_peer; 247 sampler->get_peers = sampler_mod_get_rand_peer;
245 //sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity); 248 // sampler->sampler_elements = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity);
246 //GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, min_size); 249 // GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, min_size);
247 250
248 client_get_index = 0; 251 client_get_index = 0;
249 252
250 //GNUNET_assert (init_size == sampler->sampler_size); 253 // GNUNET_assert (init_size == sampler->sampler_size);
251 254
252 RPS_sampler_resize(sampler, init_size); 255 RPS_sampler_resize (sampler, init_size);
253 256
254 return sampler; 257 return sampler;
255} 258}
@@ -271,22 +274,22 @@ RPS_sampler_mod_init(size_t init_size,
271 * @return The estimated probability 274 * @return The estimated probability
272 */ 275 */
273static double 276static double
274prob_observed_n_peers(uint32_t num_peers_estim, 277prob_observed_n_peers (uint32_t num_peers_estim,
275 uint32_t num_peers_observed, 278 uint32_t num_peers_observed,
276 double deficiency_factor) 279 double deficiency_factor)
277{ 280{
278 uint32_t num_peers = num_peers_estim * (1 / deficiency_factor); 281 uint32_t num_peers = num_peers_estim * (1 / deficiency_factor);
279 uint64_t sum = 0; 282 uint64_t sum = 0;
280 283
281 for (uint32_t i = 0; i < num_peers; i++) 284 for (uint32_t i = 0; i < num_peers; i++)
282 { 285 {
283 uint64_t a = pow(-1, num_peers - i); 286 uint64_t a = pow (-1, num_peers - i);
284 uint64_t b = binom(num_peers, i); 287 uint64_t b = binom (num_peers, i);
285 uint64_t c = pow(i, num_peers_observed); 288 uint64_t c = pow (i, num_peers_observed);
286 sum += a * b * c; 289 sum += a * b * c;
287 } 290 }
288 291
289 return sum / (double)pow(num_peers, num_peers_observed); 292 return sum / (double) pow (num_peers, num_peers_observed);
290} 293}
291 294
292 295
@@ -296,7 +299,7 @@ prob_observed_n_peers(uint32_t num_peers_estim,
296 * This reinitialises the queried sampler element. 299 * This reinitialises the queried sampler element.
297 */ 300 */
298static void 301static void
299sampler_mod_get_rand_peer(void *cls) 302sampler_mod_get_rand_peer (void *cls)
300{ 303{
301 struct GetPeerCls *gpc = cls; 304 struct GetPeerCls *gpc = cls;
302 struct RPS_SamplerElement *s_elem; 305 struct RPS_SamplerElement *s_elem;
@@ -307,86 +310,88 @@ sampler_mod_get_rand_peer(void *cls)
307 310
308 gpc->get_peer_task = NULL; 311 gpc->get_peer_task = NULL;
309 gpc->notify_ctx = NULL; 312 gpc->notify_ctx = NULL;
310 GNUNET_assert((NULL != gpc->req_handle) || 313 GNUNET_assert ((NULL != gpc->req_handle) ||
311 (NULL != gpc->req_single_info_handle)); 314 (NULL != gpc->req_single_info_handle));
312 if (NULL != gpc->req_handle) 315 if (NULL != gpc->req_handle)
313 sampler = gpc->req_handle->sampler; 316 sampler = gpc->req_handle->sampler;
314 else 317 else
315 sampler = gpc->req_single_info_handle->sampler; 318 sampler = gpc->req_single_info_handle->sampler;
316 319
317 LOG(GNUNET_ERROR_TYPE_DEBUG, "Single peer was requested\n"); 320 LOG (GNUNET_ERROR_TYPE_DEBUG, "Single peer was requested\n");
318 321
319 /* Cycle the #client_get_index one step further */ 322 /* Cycle the #client_get_index one step further */
320 client_get_index = (client_get_index + 1) % sampler->sampler_size; 323 client_get_index = (client_get_index + 1) % sampler->sampler_size;
321 324
322 s_elem = sampler->sampler_elements[client_get_index]; 325 s_elem = sampler->sampler_elements[client_get_index];
323 *gpc->id = s_elem->peer_id; 326 *gpc->id = s_elem->peer_id;
324 GNUNET_assert(NULL != s_elem); 327 GNUNET_assert (NULL != s_elem);
325 328
326 if (EMPTY == s_elem->is_empty) 329 if (EMPTY == s_elem->is_empty)
327 { 330 {
328 LOG(GNUNET_ERROR_TYPE_DEBUG, 331 LOG (GNUNET_ERROR_TYPE_DEBUG,
329 "Sampler_mod element empty, rescheduling.\n"); 332 "Sampler_mod element empty, rescheduling.\n");
330 GNUNET_assert(NULL == gpc->notify_ctx); 333 GNUNET_assert (NULL == gpc->notify_ctx);
331 gpc->notify_ctx = 334 gpc->notify_ctx =
332 sampler_notify_on_update(sampler, 335 sampler_notify_on_update (sampler,
333 &sampler_mod_get_rand_peer, 336 &sampler_mod_get_rand_peer,
334 gpc); 337 gpc);
335 return; 338 return;
336 } 339 }
337 340
338 /* Check whether we may use this sampler to give it back to the client */ 341 /* Check whether we may use this sampler to give it back to the client */
339 if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != s_elem->last_client_request.abs_value_us) 342 if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us !=
340 { 343 s_elem->last_client_request.abs_value_us)
341 // TODO remove this condition at least for the client sampler 344 {
342 last_request_diff = 345 // TODO remove this condition at least for the client sampler
343 GNUNET_TIME_absolute_get_difference(s_elem->last_client_request, 346 last_request_diff =
344 GNUNET_TIME_absolute_get()); 347 GNUNET_TIME_absolute_get_difference (s_elem->last_client_request,
345 /* We're not going to give it back now if it was 348 GNUNET_TIME_absolute_get ());
346 * already requested by a client this round */ 349 /* We're not going to give it back now if it was
347 if (last_request_diff.rel_value_us < sampler->max_round_interval.rel_value_us) 350 * already requested by a client this round */
348 { 351 if (last_request_diff.rel_value_us <
349 LOG(GNUNET_ERROR_TYPE_DEBUG, 352 sampler->max_round_interval.rel_value_us)
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 { 353 {
367 LOG(GNUNET_ERROR_TYPE_DEBUG, 354 LOG (GNUNET_ERROR_TYPE_DEBUG,
368 "This s_elem saw less than two peers -- scheduling for later\n"); 355 "Last client request on this sampler was less than max round interval ago -- scheduling for later\n");
369 GNUNET_assert(NULL == gpc->notify_ctx); 356 ///* How many time remains untile the next round has started? */
357 // inv_last_request_diff =
358 // GNUNET_TIME_absolute_get_difference (last_request_diff,
359 // sampler->max_round_interval);
360 // add a little delay
361 /* Schedule it one round later */
362 GNUNET_assert (NULL == gpc->notify_ctx);
370 gpc->notify_ctx = 363 gpc->notify_ctx =
371 sampler_notify_on_update(sampler, 364 sampler_notify_on_update (sampler,
372 &sampler_mod_get_rand_peer, 365 &sampler_mod_get_rand_peer,
373 gpc); 366 gpc);
374 return; 367 return;
375 } 368 }
369 }
370 if (2 > s_elem->num_peers)
371 {
372 LOG (GNUNET_ERROR_TYPE_DEBUG,
373 "This s_elem saw less than two peers -- scheduling for later\n");
374 GNUNET_assert (NULL == gpc->notify_ctx);
375 gpc->notify_ctx =
376 sampler_notify_on_update (sampler,
377 &sampler_mod_get_rand_peer,
378 gpc);
379 return;
380 }
376 /* compute probability */ 381 /* compute probability */
377 /* Currently disabled due to numerical limitations */ 382 /* Currently disabled due to numerical limitations */
378 //prob_observed_n = prob_observed_n_peers (sampler->num_peers_estim, 383 // prob_observed_n = prob_observed_n_peers (sampler->num_peers_estim,
379 // s_elem->num_peers, 384 // s_elem->num_peers,
380 // sampler->deficiency_factor); 385 // sampler->deficiency_factor);
381 //LOG (GNUNET_ERROR_TYPE_DEBUG, 386 // LOG (GNUNET_ERROR_TYPE_DEBUG,
382 // "Computed sample - prob %f, %" PRIu32 " peers, n: %" PRIu32 ", roh: %f\n", 387 // "Computed sample - prob %f, %" PRIu32 " peers, n: %" PRIu32 ", roh: %f\n",
383 // prob_observed_n, 388 // prob_observed_n,
384 // s_elem->num_peers, 389 // s_elem->num_peers,
385 // sampler->num_peers_estim, 390 // sampler->num_peers_estim,
386 // sampler->deficiency_factor); 391 // sampler->deficiency_factor);
387 ///* check if probability is above desired */ 392 ///* check if probability is above desired */
388 //if (prob_observed_n < sampler->desired_probability) 393 // if (prob_observed_n < sampler->desired_probability)
389 //{ 394 // {
390 // LOG (GNUNET_ERROR_TYPE_DEBUG, 395 // LOG (GNUNET_ERROR_TYPE_DEBUG,
391 // "Probability of having observed all peers (%f) too small ( < %f).\n", 396 // "Probability of having observed all peers (%f) too small ( < %f).\n",
392 // prob_observed_n, 397 // prob_observed_n,
@@ -397,7 +402,7 @@ sampler_mod_get_rand_peer(void *cls)
397 // &sampler_mod_get_rand_peer, 402 // &sampler_mod_get_rand_peer,
398 // gpc); 403 // gpc);
399 // return; 404 // return;
400 //} 405 // }
401 /* More reasons to wait could be added here */ 406 /* More reasons to wait could be added here */
402 407
403// GNUNET_STATISTICS_set (stats, 408// GNUNET_STATISTICS_set (stats,
@@ -410,25 +415,24 @@ sampler_mod_get_rand_peer(void *cls)
410// GNUNET_NO); 415// GNUNET_NO);
411 416
412 num_observed = s_elem->num_peers; 417 num_observed = s_elem->num_peers;
413 RPS_sampler_elem_reinit(s_elem); 418 RPS_sampler_elem_reinit (s_elem);
414 s_elem->last_client_request = GNUNET_TIME_absolute_get(); 419 s_elem->last_client_request = GNUNET_TIME_absolute_get ();
415 420
416 if (NULL != gpc->req_handle) 421 if (NULL != gpc->req_handle)
417 { 422 {
418 GNUNET_CONTAINER_DLL_remove(gpc->req_handle->gpc_head, 423 GNUNET_CONTAINER_DLL_remove (gpc->req_handle->gpc_head,
419 gpc->req_handle->gpc_tail, 424 gpc->req_handle->gpc_tail,
420 gpc); 425 gpc);
421 } 426 }
422 else 427 else
423 { 428 {
424 GNUNET_CONTAINER_DLL_remove(gpc->req_single_info_handle->gpc_head, 429 GNUNET_CONTAINER_DLL_remove (gpc->req_single_info_handle->gpc_head,
425 gpc->req_single_info_handle->gpc_tail, 430 gpc->req_single_info_handle->gpc_tail,
426 gpc); 431 gpc);
427 } 432 }
428 gpc->cont(gpc->cont_cls, gpc->id, prob_observed_n, num_observed); 433 gpc->cont (gpc->cont_cls, gpc->id, prob_observed_n, num_observed);
429 GNUNET_free(gpc); 434 GNUNET_free (gpc);
430} 435}
431 436
432 437
433/* end of gnunet-service-rps.c */ 438/* end of gnunet-service-rps.c */
434
diff --git a/src/rps/rps-sampler_client.h b/src/rps/rps-sampler_client.h
index db8087795..e6b808650 100644
--- a/src/rps/rps-sampler_client.h
+++ b/src/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 */
55unsigned int 55unsigned int
56RPS_sampler_get_size(struct RPS_Sampler *sampler); 56RPS_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 */
65void 65void
66RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size); 66RPS_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 */
76struct RPS_Sampler * 76struct RPS_Sampler *
77RPS_sampler_mod_init(size_t init_size, 77RPS_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/**
@@ -85,8 +85,8 @@ RPS_sampler_mod_init(size_t init_size,
85 * @param id the PeerID that is put in the sampler 85 * @param id the PeerID that is put in the sampler
86 */ 86 */
87void 87void
88RPS_sampler_update(struct RPS_Sampler *sampler, 88RPS_sampler_update (struct RPS_Sampler *sampler,
89 const struct GNUNET_PeerIdentity *id); 89 const struct GNUNET_PeerIdentity *id);
90 90
91 91
92/** 92/**
@@ -99,8 +99,8 @@ RPS_sampler_update(struct RPS_Sampler *sampler,
99 * @param id the id of the samplers to update. 99 * @param id the id of the samplers to update.
100 */ 100 */
101void 101void
102RPS_sampler_reinitialise_by_value(struct RPS_Sampler *sampler, 102RPS_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 */
118struct RPS_SamplerRequestHandle * 118struct RPS_SamplerRequestHandle *
119RPS_sampler_get_n_rand_peers(struct RPS_Sampler *sampler, 119RPS_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 */
130void 130void
131RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle); 131RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle);
132 132
133 133
134/** 134/**
@@ -140,8 +140,8 @@ RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle);
140 * @return the number of occurrences of id. 140 * @return the number of occurrences of id.
141 */ 141 */
142uint32_t 142uint32_t
143RPS_sampler_count_id(struct RPS_Sampler *sampler, 143RPS_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/**
@@ -150,7 +150,7 @@ RPS_sampler_count_id(struct RPS_Sampler *sampler,
150 * @param sampler the sampler to destroy. 150 * @param sampler the sampler to destroy.
151 */ 151 */
152void 152void
153RPS_sampler_destroy(struct RPS_Sampler *sampler); 153RPS_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 48fa121b7..ab8c65f17 100644
--- a/src/rps/rps-sampler_common.c
+++ b/src/rps/rps-sampler_common.c
@@ -35,14 +35,15 @@
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 */
45struct SamplerNotifyUpdateCTX { 45struct SamplerNotifyUpdateCTX
46{
46 /** 47 /**
47 * @brief The Callback to call on updates 48 * @brief The Callback to call on updates
48 */ 49 */
@@ -68,7 +69,8 @@ struct SamplerNotifyUpdateCTX {
68/** 69/**
69 * Closure to _get_n_rand_peers_ready_cb() 70 * Closure to _get_n_rand_peers_ready_cb()
70 */ 71 */
71struct RPS_SamplerRequestHandle { 72struct RPS_SamplerRequestHandle
73{
72 /** 74 /**
73 * DLL 75 * DLL
74 */ 76 */
@@ -116,7 +118,8 @@ struct RPS_SamplerRequestHandle {
116/** 118/**
117 * Closure to _get_rand_peer_info() 119 * Closure to _get_rand_peer_info()
118 */ 120 */
119struct RPS_SamplerRequestHandleSingleInfo { 121struct RPS_SamplerRequestHandleSingleInfo
122{
120 /** 123 /**
121 * DLL 124 * DLL
122 */ 125 */
@@ -163,8 +166,8 @@ struct RPS_SamplerRequestHandleSingleInfo {
163 * @param num_peers The estimated value 166 * @param num_peers The estimated value
164 */ 167 */
165void 168void
166RPS_sampler_update_with_nw_size(struct RPS_Sampler *sampler, 169RPS_sampler_update_with_nw_size (struct RPS_Sampler *sampler,
167 uint32_t num_peers) 170 uint32_t num_peers)
168{ 171{
169 sampler->num_peers_estim = num_peers; 172 sampler->num_peers_estim = num_peers;
170} 173}
@@ -181,8 +184,8 @@ RPS_sampler_update_with_nw_size(struct RPS_Sampler *sampler,
181 * @param desired_probability 184 * @param desired_probability
182 */ 185 */
183void 186void
184RPS_sampler_set_desired_probability(struct RPS_Sampler *sampler, 187RPS_sampler_set_desired_probability (struct RPS_Sampler *sampler,
185 double desired_probability) 188 double desired_probability)
186{ 189{
187 sampler->desired_probability = desired_probability; 190 sampler->desired_probability = desired_probability;
188} 191}
@@ -198,8 +201,8 @@ RPS_sampler_set_desired_probability(struct RPS_Sampler *sampler,
198 * @param desired_probability 201 * @param desired_probability
199 */ 202 */
200void 203void
201RPS_sampler_set_deficiency_factor(struct RPS_Sampler *sampler, 204RPS_sampler_set_deficiency_factor (struct RPS_Sampler *sampler,
202 double deficiency_factor) 205 double deficiency_factor)
203{ 206{
204 sampler->deficiency_factor = deficiency_factor; 207 sampler->deficiency_factor = deficiency_factor;
205} 208}
@@ -216,20 +219,20 @@ RPS_sampler_set_deficiency_factor(struct RPS_Sampler *sampler,
216 * @return The context containing callback and closure 219 * @return The context containing callback and closure
217 */ 220 */
218struct SamplerNotifyUpdateCTX * 221struct SamplerNotifyUpdateCTX *
219sampler_notify_on_update(struct RPS_Sampler *sampler, 222sampler_notify_on_update (struct RPS_Sampler *sampler,
220 SamplerNotifyUpdateCB notify_cb, 223 SamplerNotifyUpdateCB notify_cb,
221 void *cls) 224 void *cls)
222{ 225{
223 struct SamplerNotifyUpdateCTX *notify_ctx; 226 struct SamplerNotifyUpdateCTX *notify_ctx;
224 227
225 LOG(GNUNET_ERROR_TYPE_DEBUG, 228 LOG (GNUNET_ERROR_TYPE_DEBUG,
226 "Inserting new context for notification\n"); 229 "Inserting new context for notification\n");
227 notify_ctx = GNUNET_new(struct SamplerNotifyUpdateCTX); 230 notify_ctx = GNUNET_new (struct SamplerNotifyUpdateCTX);
228 notify_ctx->notify_cb = notify_cb; 231 notify_ctx->notify_cb = notify_cb;
229 notify_ctx->cls = cls; 232 notify_ctx->cls = cls;
230 GNUNET_CONTAINER_DLL_insert(sampler->notify_ctx_head, 233 GNUNET_CONTAINER_DLL_insert (sampler->notify_ctx_head,
231 sampler->notify_ctx_tail, 234 sampler->notify_ctx_tail,
232 notify_ctx); 235 notify_ctx);
233 return notify_ctx; 236 return notify_ctx;
234} 237}
235 238
@@ -241,7 +244,7 @@ sampler_notify_on_update(struct RPS_Sampler *sampler,
241 * @return the size of the sampler 244 * @return the size of the sampler
242 */ 245 */
243unsigned int 246unsigned int
244RPS_sampler_get_size(struct RPS_Sampler *sampler) 247RPS_sampler_get_size (struct RPS_Sampler *sampler)
245{ 248{
246 return sampler->sampler_size; 249 return sampler->sampler_size;
247} 250}
@@ -256,13 +259,13 @@ RPS_sampler_get_size(struct RPS_Sampler *sampler)
256 * @param sampler The sampler the updates are waiting for 259 * @param sampler The sampler the updates are waiting for
257 */ 260 */
258static void 261static void
259notify_update(struct RPS_Sampler *sampler) 262notify_update (struct RPS_Sampler *sampler)
260{ 263{
261 struct SamplerNotifyUpdateCTX *tmp_notify_head; 264 struct SamplerNotifyUpdateCTX *tmp_notify_head;
262 struct SamplerNotifyUpdateCTX *tmp_notify_tail; 265 struct SamplerNotifyUpdateCTX *tmp_notify_tail;
263 266
264 LOG(GNUNET_ERROR_TYPE_DEBUG, 267 LOG (GNUNET_ERROR_TYPE_DEBUG,
265 "Calling callbacks waiting for update notification.\n"); 268 "Calling callbacks waiting for update notification.\n");
266 tmp_notify_head = sampler->notify_ctx_head; 269 tmp_notify_head = sampler->notify_ctx_head;
267 tmp_notify_tail = sampler->notify_ctx_tail; 270 tmp_notify_tail = sampler->notify_ctx_tail;
268 sampler->notify_ctx_head = NULL; 271 sampler->notify_ctx_head = NULL;
@@ -270,14 +273,14 @@ notify_update(struct RPS_Sampler *sampler)
270 for (struct SamplerNotifyUpdateCTX *notify_iter = tmp_notify_head; 273 for (struct SamplerNotifyUpdateCTX *notify_iter = tmp_notify_head;
271 NULL != tmp_notify_head; 274 NULL != tmp_notify_head;
272 notify_iter = tmp_notify_head) 275 notify_iter = tmp_notify_head)
273 { 276 {
274 GNUNET_assert(NULL != notify_iter->notify_cb); 277 GNUNET_assert (NULL != notify_iter->notify_cb);
275 GNUNET_CONTAINER_DLL_remove(tmp_notify_head, 278 GNUNET_CONTAINER_DLL_remove (tmp_notify_head,
276 tmp_notify_tail, 279 tmp_notify_tail,
277 notify_iter); 280 notify_iter);
278 notify_iter->notify_cb(notify_iter->cls); 281 notify_iter->notify_cb (notify_iter->cls);
279 GNUNET_free(notify_iter); 282 GNUNET_free (notify_iter);
280 } 283 }
281} 284}
282 285
283 286
@@ -288,15 +291,15 @@ notify_update(struct RPS_Sampler *sampler)
288 * @param id the PeerID that is put in the sampler 291 * @param id the PeerID that is put in the sampler
289 */ 292 */
290void 293void
291RPS_sampler_update(struct RPS_Sampler *sampler, 294RPS_sampler_update (struct RPS_Sampler *sampler,
292 const struct GNUNET_PeerIdentity *id) 295 const struct GNUNET_PeerIdentity *id)
293{ 296{
294 for (uint32_t i = 0; i < sampler->sampler_size; i++) 297 for (uint32_t i = 0; i < sampler->sampler_size; i++)
295 { 298 {
296 RPS_sampler_elem_next(sampler->sampler_elements[i], 299 RPS_sampler_elem_next (sampler->sampler_elements[i],
297 id); 300 id);
298 } 301 }
299 notify_update(sampler); 302 notify_update (sampler);
300} 303}
301 304
302 305
@@ -315,20 +318,20 @@ RPS_sampler_update(struct RPS_Sampler *sampler,
315 * @param id the id of the sampler elements to update. 318 * @param id the id of the sampler elements to update.
316 */ 319 */
317void 320void
318RPS_sampler_reinitialise_by_value(struct RPS_Sampler *sampler, 321RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler,
319 const struct GNUNET_PeerIdentity *id) 322 const struct GNUNET_PeerIdentity *id)
320{ 323{
321 uint32_t i; 324 uint32_t i;
322 325
323 for (i = 0; i < sampler->sampler_size; i++) 326 for (i = 0; i < sampler->sampler_size; i++)
327 {
328 if (0 == GNUNET_memcmp (id,
329 &(sampler->sampler_elements[i]->peer_id)))
324 { 330 {
325 if (0 == GNUNET_memcmp(id, 331 LOG (GNUNET_ERROR_TYPE_DEBUG, "Reinitialising sampler\n");
326 &(sampler->sampler_elements[i]->peer_id))) 332 RPS_sampler_elem_reinit (sampler->sampler_elements[i]);
327 {
328 LOG(GNUNET_ERROR_TYPE_DEBUG, "Reinitialising sampler\n");
329 RPS_sampler_elem_reinit(sampler->sampler_elements[i]);
330 }
331 } 333 }
334 }
332} 335}
333 336
334 337
@@ -341,19 +344,19 @@ RPS_sampler_reinitialise_by_value(struct RPS_Sampler *sampler,
341 * @return the number of occurrences of id. 344 * @return the number of occurrences of id.
342 */ 345 */
343uint32_t 346uint32_t
344RPS_sampler_count_id(struct RPS_Sampler *sampler, 347RPS_sampler_count_id (struct RPS_Sampler *sampler,
345 const struct GNUNET_PeerIdentity *id) 348 const struct GNUNET_PeerIdentity *id)
346{ 349{
347 uint32_t count; 350 uint32_t count;
348 uint32_t i; 351 uint32_t i;
349 352
350 count = 0; 353 count = 0;
351 for (i = 0; i < sampler->sampler_size; i++) 354 for (i = 0; i < sampler->sampler_size; i++)
352 { 355 {
353 if (0 == GNUNET_memcmp(&sampler->sampler_elements[i]->peer_id, id) 356 if ((0 == GNUNET_memcmp (&sampler->sampler_elements[i]->peer_id, id))
354 && EMPTY != sampler->sampler_elements[i]->is_empty) 357 &&(EMPTY != sampler->sampler_elements[i]->is_empty) )
355 count++; 358 count++;
356 } 359 }
357 return count; 360 return count;
358} 361}
359 362
@@ -365,7 +368,7 @@ RPS_sampler_count_id(struct RPS_Sampler *sampler,
365 * @param new_size the new size of the sampler 368 * @param new_size the new size of the sampler
366 */ 369 */
367static void 370static void
368sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size) 371sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size)
369{ 372{
370 unsigned int old_size; 373 unsigned int old_size;
371 uint32_t i; 374 uint32_t i;
@@ -375,47 +378,47 @@ sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size)
375 old_size = sampler->sampler_size; 378 old_size = sampler->sampler_size;
376 379
377 if (old_size > new_size) 380 if (old_size > new_size)
378 { /* Shrinking */ 381 { /* Shrinking */
379 LOG(GNUNET_ERROR_TYPE_DEBUG, 382 LOG (GNUNET_ERROR_TYPE_DEBUG,
380 "Shrinking sampler %d -> %d\n", 383 "Shrinking sampler %d -> %d\n",
381 old_size, 384 old_size,
382 new_size); 385 new_size);
383 386
384 for (i = new_size; i < old_size; i++) 387 for (i = new_size; i < old_size; i++)
385 { 388 {
386 RPS_sampler_elem_destroy(sampler->sampler_elements[i]); 389 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);
395 } 390 }
391
392 GNUNET_array_grow (sampler->sampler_elements,
393 sampler->sampler_size,
394 new_size);
395 LOG (GNUNET_ERROR_TYPE_DEBUG,
396 "sampler->sampler_elements now points to %p\n",
397 sampler->sampler_elements);
398 }
396 else if (old_size < new_size) 399 else if (old_size < new_size)
397 { /* Growing */ 400 { /* Growing */
398 LOG(GNUNET_ERROR_TYPE_DEBUG, 401 LOG (GNUNET_ERROR_TYPE_DEBUG,
399 "Growing sampler %d -> %d\n", 402 "Growing sampler %d -> %d\n",
400 old_size, 403 old_size,
401 new_size); 404 new_size);
402 405
403 GNUNET_array_grow(sampler->sampler_elements, 406 GNUNET_array_grow (sampler->sampler_elements,
404 sampler->sampler_size, 407 sampler->sampler_size,
405 new_size); 408 new_size);
406 409
407 for (i = old_size; i < new_size; i++) 410 for (i = old_size; i < new_size; i++)
408 { /* Add new sampler elements */ 411 { /* Add new sampler elements */
409 sampler->sampler_elements[i] = RPS_sampler_elem_create(); 412 sampler->sampler_elements[i] = RPS_sampler_elem_create ();
410 }
411 } 413 }
414 }
412 else 415 else
413 { 416 {
414 LOG(GNUNET_ERROR_TYPE_DEBUG, "Size remains the same -- nothing to do\n"); 417 LOG (GNUNET_ERROR_TYPE_DEBUG, "Size remains the same -- nothing to do\n");
415 return; 418 return;
416 } 419 }
417 420
418 GNUNET_assert(sampler->sampler_size == new_size); 421 GNUNET_assert (sampler->sampler_size == new_size);
419} 422}
420 423
421 424
@@ -426,10 +429,10 @@ sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size)
426 * @param new_size the new size of the sampler 429 * @param new_size the new size of the sampler
427 */ 430 */
428void 431void
429RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size) 432RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size)
430{ 433{
431 GNUNET_assert(0 < new_size); 434 GNUNET_assert (0 < new_size);
432 sampler_resize(sampler, new_size); 435 sampler_resize (sampler, new_size);
433} 436}
434 437
435 438
@@ -440,9 +443,9 @@ RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size)
440 * @param new_size the new size of the sampler 443 * @param new_size the new size of the sampler
441 */ 444 */
442static void 445static void
443sampler_empty(struct RPS_Sampler *sampler) 446sampler_empty (struct RPS_Sampler *sampler)
444{ 447{
445 sampler_resize(sampler, 0); 448 sampler_resize (sampler, 0);
446} 449}
447 450
448 451
@@ -459,48 +462,48 @@ sampler_empty(struct RPS_Sampler *sampler)
459 * @param num_observed How many ids this sampler has observed 462 * @param num_observed How many ids this sampler has observed
460 */ 463 */
461static void 464static void
462check_n_peers_ready(void *cls, 465check_n_peers_ready (void *cls,
463 const struct GNUNET_PeerIdentity *id, 466 const struct GNUNET_PeerIdentity *id,
464 double probability, 467 double probability,
465 uint32_t num_observed) 468 uint32_t num_observed)
466{ 469{
467 struct RPS_SamplerRequestHandle *req_handle = cls; 470 struct RPS_SamplerRequestHandle *req_handle = cls;
468 471
469 (void)id; 472 (void) id;
470 RPS_sampler_n_rand_peers_ready_cb tmp_cb; 473 RPS_sampler_n_rand_peers_ready_cb tmp_cb;
471 struct GNUNET_PeerIdentity *peers; 474 struct GNUNET_PeerIdentity *peers;
472 uint32_t num_peers; 475 uint32_t num_peers;
473 void *cb_cls; 476 void *cb_cls;
474 (void)probability; 477 (void) probability;
475 (void)num_observed; 478 (void) num_observed;
476 479
477 req_handle->cur_num_peers++; 480 req_handle->cur_num_peers++;
478 LOG(GNUNET_ERROR_TYPE_DEBUG, 481 LOG (GNUNET_ERROR_TYPE_DEBUG,
479 "Got %" PRIX32 ". of %" PRIX32 " peers\n", 482 "Got %" PRIX32 ". of %" PRIX32 " peers\n",
480 req_handle->cur_num_peers, req_handle->num_peers); 483 req_handle->cur_num_peers, req_handle->num_peers);
481 484
482 if (req_handle->num_peers == req_handle->cur_num_peers) 485 if (req_handle->num_peers == req_handle->cur_num_peers)
483 { /* All peers are ready -- return those to the client */ 486 { /* All peers are ready -- return those to the client */
484 GNUNET_assert(NULL != req_handle->callback); 487 GNUNET_assert (NULL != req_handle->callback);
485 488
486 LOG(GNUNET_ERROR_TYPE_DEBUG, 489 LOG (GNUNET_ERROR_TYPE_DEBUG,
487 "returning %" PRIX32 " peers to the client\n", 490 "returning %" PRIX32 " peers to the client\n",
488 req_handle->num_peers); 491 req_handle->num_peers);
489 492
490 /* Copy pointers and peers temporarily as they 493 /* Copy pointers and peers temporarily as they
491 * might be deleted from within the callback */ 494 * might be deleted from within the callback */
492 tmp_cb = req_handle->callback; 495 tmp_cb = req_handle->callback;
493 num_peers = req_handle->num_peers; 496 num_peers = req_handle->num_peers;
494 peers = GNUNET_new_array(num_peers, struct GNUNET_PeerIdentity); 497 peers = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
495 GNUNET_memcpy(peers, 498 GNUNET_memcpy (peers,
496 req_handle->ids, 499 req_handle->ids,
497 num_peers * sizeof(struct GNUNET_PeerIdentity)); 500 num_peers * sizeof(struct GNUNET_PeerIdentity));
498 cb_cls = req_handle->cls; 501 cb_cls = req_handle->cls;
499 RPS_sampler_request_cancel(req_handle); 502 RPS_sampler_request_cancel (req_handle);
500 req_handle = NULL; 503 req_handle = NULL;
501 tmp_cb(peers, num_peers, cb_cls); 504 tmp_cb (peers, num_peers, cb_cls);
502 GNUNET_free(peers); 505 GNUNET_free (peers);
503 } 506 }
504} 507}
505 508
506 509
@@ -515,40 +518,40 @@ check_n_peers_ready(void *cls,
515 * @param num_observed How many ids this sampler has observed 518 * @param num_observed How many ids this sampler has observed
516 */ 519 */
517static void 520static void
518check_peer_info_ready(void *cls, 521check_peer_info_ready (void *cls,
519 const struct GNUNET_PeerIdentity *id, 522 const struct GNUNET_PeerIdentity *id,
520 double probability, 523 double probability,
521 uint32_t num_observed) 524 uint32_t num_observed)
522{ 525{
523 struct RPS_SamplerRequestHandleSingleInfo *req_handle = cls; 526 struct RPS_SamplerRequestHandleSingleInfo *req_handle = cls;
524 527
525 (void)id; 528 (void) id;
526 RPS_sampler_sinlge_info_ready_cb tmp_cb; 529 RPS_sampler_sinlge_info_ready_cb tmp_cb;
527 struct GNUNET_PeerIdentity *peer; 530 struct GNUNET_PeerIdentity *peer;
528 void *cb_cls; 531 void *cb_cls;
529 (void)probability; 532 (void) probability;
530 (void)num_observed; 533 (void) num_observed;
531 534
532 LOG(GNUNET_ERROR_TYPE_DEBUG, 535 LOG (GNUNET_ERROR_TYPE_DEBUG,
533 "Got single peer with additional info\n"); 536 "Got single peer with additional info\n");
534 537
535 GNUNET_assert(NULL != req_handle->callback); 538 GNUNET_assert (NULL != req_handle->callback);
536 539
537 LOG(GNUNET_ERROR_TYPE_DEBUG, 540 LOG (GNUNET_ERROR_TYPE_DEBUG,
538 "returning single peer with info to the client\n"); 541 "returning single peer with info to the client\n");
539 542
540 /* Copy pointers and peers temporarily as they 543 /* Copy pointers and peers temporarily as they
541 * might be deleted from within the callback */ 544 * might be deleted from within the callback */
542 tmp_cb = req_handle->callback; 545 tmp_cb = req_handle->callback;
543 peer = GNUNET_new(struct GNUNET_PeerIdentity); 546 peer = GNUNET_new (struct GNUNET_PeerIdentity);
544 GNUNET_memcpy(peer, 547 GNUNET_memcpy (peer,
545 req_handle->id, 548 req_handle->id,
546 sizeof(struct GNUNET_PeerIdentity)); 549 sizeof(struct GNUNET_PeerIdentity));
547 cb_cls = req_handle->cls; 550 cb_cls = req_handle->cls;
548 RPS_sampler_request_single_info_cancel(req_handle); 551 RPS_sampler_request_single_info_cancel (req_handle);
549 req_handle = NULL; 552 req_handle = NULL;
550 tmp_cb(peer, cb_cls, probability, num_observed); 553 tmp_cb (peer, cb_cls, probability, num_observed);
551 GNUNET_free(peer); 554 GNUNET_free (peer);
552} 555}
553 556
554 557
@@ -565,50 +568,50 @@ check_peer_info_ready(void *cls,
565 * @param num_peers the number of peers requested 568 * @param num_peers the number of peers requested
566 */ 569 */
567struct RPS_SamplerRequestHandle * 570struct RPS_SamplerRequestHandle *
568RPS_sampler_get_n_rand_peers(struct RPS_Sampler *sampler, 571RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler,
569 uint32_t num_peers, 572 uint32_t num_peers,
570 RPS_sampler_n_rand_peers_ready_cb cb, 573 RPS_sampler_n_rand_peers_ready_cb cb,
571 void *cls) 574 void *cls)
572{ 575{
573 uint32_t i; 576 uint32_t i;
574 struct RPS_SamplerRequestHandle *req_handle; 577 struct RPS_SamplerRequestHandle *req_handle;
575 struct GetPeerCls *gpc; 578 struct GetPeerCls *gpc;
576 579
577 GNUNET_assert(0 != sampler->sampler_size); 580 GNUNET_assert (0 != sampler->sampler_size);
578 if (0 == num_peers) 581 if (0 == num_peers)
579 return NULL; 582 return NULL;
580 583
581 // TODO check if we have too much (distinct) sampled peers 584 // TODO check if we have too much (distinct) sampled peers
582 req_handle = GNUNET_new(struct RPS_SamplerRequestHandle); 585 req_handle = GNUNET_new (struct RPS_SamplerRequestHandle);
583 req_handle->num_peers = num_peers; 586 req_handle->num_peers = num_peers;
584 req_handle->cur_num_peers = 0; 587 req_handle->cur_num_peers = 0;
585 req_handle->ids = GNUNET_new_array(num_peers, struct GNUNET_PeerIdentity); 588 req_handle->ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
586 req_handle->sampler = sampler; 589 req_handle->sampler = sampler;
587 req_handle->callback = cb; 590 req_handle->callback = cb;
588 req_handle->cls = cls; 591 req_handle->cls = cls;
589 GNUNET_CONTAINER_DLL_insert(sampler->req_handle_head, 592 GNUNET_CONTAINER_DLL_insert (sampler->req_handle_head,
590 sampler->req_handle_tail, 593 sampler->req_handle_tail,
591 req_handle); 594 req_handle);
592 595
593 LOG(GNUNET_ERROR_TYPE_DEBUG, 596 LOG (GNUNET_ERROR_TYPE_DEBUG,
594 "Scheduling requests for %" PRIu32 " peers\n", num_peers); 597 "Scheduling requests for %" PRIu32 " peers\n", num_peers);
595 598
596 for (i = 0; i < num_peers; i++) 599 for (i = 0; i < num_peers; i++)
597 { 600 {
598 gpc = GNUNET_new(struct GetPeerCls); 601 gpc = GNUNET_new (struct GetPeerCls);
599 gpc->req_handle = req_handle; 602 gpc->req_handle = req_handle;
600 gpc->req_single_info_handle = NULL; 603 gpc->req_single_info_handle = NULL;
601 gpc->cont = check_n_peers_ready; 604 gpc->cont = check_n_peers_ready;
602 gpc->cont_cls = req_handle; 605 gpc->cont_cls = req_handle;
603 gpc->id = &req_handle->ids[i]; 606 gpc->id = &req_handle->ids[i];
604 607
605 GNUNET_CONTAINER_DLL_insert(req_handle->gpc_head, 608 GNUNET_CONTAINER_DLL_insert (req_handle->gpc_head,
606 req_handle->gpc_tail, 609 req_handle->gpc_tail,
607 gpc); 610 gpc);
608 // maybe add a little delay 611 // maybe add a little delay
609 gpc->get_peer_task = GNUNET_SCHEDULER_add_now(sampler->get_peers, 612 gpc->get_peer_task = GNUNET_SCHEDULER_add_now (sampler->get_peers,
610 gpc); 613 gpc);
611 } 614 }
612 return req_handle; 615 return req_handle;
613} 616}
614 617
@@ -621,38 +624,38 @@ RPS_sampler_get_n_rand_peers(struct RPS_Sampler *sampler,
621 * @param cls closure given to @a cb 624 * @param cls closure given to @a cb
622 */ 625 */
623struct RPS_SamplerRequestHandleSingleInfo * 626struct RPS_SamplerRequestHandleSingleInfo *
624RPS_sampler_get_rand_peer_info(struct RPS_Sampler *sampler, 627RPS_sampler_get_rand_peer_info (struct RPS_Sampler *sampler,
625 RPS_sampler_sinlge_info_ready_cb cb, 628 RPS_sampler_sinlge_info_ready_cb cb,
626 void *cls) 629 void *cls)
627{ 630{
628 struct RPS_SamplerRequestHandleSingleInfo *req_handle; 631 struct RPS_SamplerRequestHandleSingleInfo *req_handle;
629 struct GetPeerCls *gpc; 632 struct GetPeerCls *gpc;
630 633
631 GNUNET_assert(0 != sampler->sampler_size); 634 GNUNET_assert (0 != sampler->sampler_size);
632 635
633 // TODO check if we have too much (distinct) sampled peers 636 // TODO check if we have too much (distinct) sampled peers
634 req_handle = GNUNET_new(struct RPS_SamplerRequestHandleSingleInfo); 637 req_handle = GNUNET_new (struct RPS_SamplerRequestHandleSingleInfo);
635 req_handle->id = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); 638 req_handle->id = GNUNET_malloc (sizeof(struct GNUNET_PeerIdentity));
636 req_handle->sampler = sampler; 639 req_handle->sampler = sampler;
637 req_handle->callback = cb; 640 req_handle->callback = cb;
638 req_handle->cls = cls; 641 req_handle->cls = cls;
639 GNUNET_CONTAINER_DLL_insert(sampler->req_handle_single_head, 642 GNUNET_CONTAINER_DLL_insert (sampler->req_handle_single_head,
640 sampler->req_handle_single_tail, 643 sampler->req_handle_single_tail,
641 req_handle); 644 req_handle);
642 645
643 gpc = GNUNET_new(struct GetPeerCls); 646 gpc = GNUNET_new (struct GetPeerCls);
644 gpc->req_handle = NULL; 647 gpc->req_handle = NULL;
645 gpc->req_single_info_handle = req_handle; 648 gpc->req_single_info_handle = req_handle;
646 gpc->cont = check_peer_info_ready; 649 gpc->cont = check_peer_info_ready;
647 gpc->cont_cls = req_handle; 650 gpc->cont_cls = req_handle;
648 gpc->id = req_handle->id; 651 gpc->id = req_handle->id;
649 652
650 GNUNET_CONTAINER_DLL_insert(req_handle->gpc_head, 653 GNUNET_CONTAINER_DLL_insert (req_handle->gpc_head,
651 req_handle->gpc_tail, 654 req_handle->gpc_tail,
652 gpc); 655 gpc);
653 // maybe add a little delay 656 // maybe add a little delay
654 gpc->get_peer_task = GNUNET_SCHEDULER_add_now(sampler->get_peers, 657 gpc->get_peer_task = GNUNET_SCHEDULER_add_now (sampler->get_peers,
655 gpc); 658 gpc);
656 return req_handle; 659 return req_handle;
657} 660}
658 661
@@ -663,35 +666,35 @@ RPS_sampler_get_rand_peer_info(struct RPS_Sampler *sampler,
663 * @param req_handle the handle to the request 666 * @param req_handle the handle to the request
664 */ 667 */
665void 668void
666RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle) 669RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle)
667{ 670{
668 struct GetPeerCls *i; 671 struct GetPeerCls *i;
669 672
670 while (NULL != (i = req_handle->gpc_head)) 673 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)
671 { 683 {
672 GNUNET_CONTAINER_DLL_remove(req_handle->gpc_head, 684 GNUNET_CONTAINER_DLL_remove (req_handle->sampler->notify_ctx_head,
673 req_handle->gpc_tail, 685 req_handle->sampler->notify_ctx_tail,
674 i); 686 i->notify_ctx);
675 if (NULL != i->get_peer_task) 687 GNUNET_free (i->notify_ctx);
676 { 688 i->notify_ctx = NULL;
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);
688 } 689 }
689 GNUNET_free(req_handle->ids); 690 GNUNET_free (i);
691 }
692 GNUNET_free (req_handle->ids);
690 req_handle->ids = NULL; 693 req_handle->ids = NULL;
691 GNUNET_CONTAINER_DLL_remove(req_handle->sampler->req_handle_head, 694 GNUNET_CONTAINER_DLL_remove (req_handle->sampler->req_handle_head,
692 req_handle->sampler->req_handle_tail, 695 req_handle->sampler->req_handle_tail,
693 req_handle); 696 req_handle);
694 GNUNET_free(req_handle); 697 GNUNET_free (req_handle);
695} 698}
696 699
697 700
@@ -701,36 +704,40 @@ RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle)
701 * @param req_handle the handle to the request 704 * @param req_handle the handle to the request
702 */ 705 */
703void 706void
704RPS_sampler_request_single_info_cancel( 707RPS_sampler_request_single_info_cancel (
705 struct RPS_SamplerRequestHandleSingleInfo *req_single_info_handle) 708 struct RPS_SamplerRequestHandleSingleInfo *req_single_info_handle)
706{ 709{
707 struct GetPeerCls *i; 710 struct GetPeerCls *i;
708 711
709 while (NULL != (i = req_single_info_handle->gpc_head)) 712 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 {
719 GNUNET_SCHEDULER_cancel (i->get_peer_task);
720 }
721 if (NULL != i->notify_ctx)
710 { 722 {
711 GNUNET_CONTAINER_DLL_remove(req_single_info_handle->gpc_head, 723 GNUNET_CONTAINER_DLL_remove (
712 req_single_info_handle->gpc_tail, 724 req_single_info_handle->sampler->notify_ctx_head,
713 i); 725 req_single_info_handle->sampler->
714 if (NULL != i->get_peer_task) 726 notify_ctx_tail,
715 { 727 i->notify_ctx);
716 GNUNET_SCHEDULER_cancel(i->get_peer_task); 728 GNUNET_free (i->notify_ctx);
717 } 729 i->notify_ctx = NULL;
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);
727 } 730 }
728 GNUNET_free(req_single_info_handle->id); 731 GNUNET_free (i);
732 }
733 GNUNET_free (req_single_info_handle->id);
729 req_single_info_handle->id = NULL; 734 req_single_info_handle->id = NULL;
730 GNUNET_CONTAINER_DLL_remove(req_single_info_handle->sampler->req_handle_single_head, 735 GNUNET_CONTAINER_DLL_remove (
731 req_single_info_handle->sampler->req_handle_single_tail, 736 req_single_info_handle->sampler->req_handle_single_head,
732 req_single_info_handle); 737 req_single_info_handle->sampler->
733 GNUNET_free(req_single_info_handle); 738 req_handle_single_tail,
739 req_single_info_handle);
740 GNUNET_free (req_single_info_handle);
734} 741}
735 742
736 743
@@ -738,19 +745,19 @@ RPS_sampler_request_single_info_cancel(
738 * Cleans the sampler. 745 * Cleans the sampler.
739 */ 746 */
740void 747void
741RPS_sampler_destroy(struct RPS_Sampler *sampler) 748RPS_sampler_destroy (struct RPS_Sampler *sampler)
742{ 749{
743 if (NULL != sampler->req_handle_head) 750 if (NULL != sampler->req_handle_head)
751 {
752 LOG (GNUNET_ERROR_TYPE_WARNING,
753 "There are still pending requests. Going to remove them.\n");
754 while (NULL != sampler->req_handle_head)
744 { 755 {
745 LOG(GNUNET_ERROR_TYPE_WARNING, 756 RPS_sampler_request_cancel (sampler->req_handle_head);
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 }
751 } 757 }
752 sampler_empty(sampler); 758 }
753 GNUNET_free(sampler); 759 sampler_empty (sampler);
760 GNUNET_free (sampler);
754} 761}
755 762
756 763
diff --git a/src/rps/rps-sampler_common.h b/src/rps/rps-sampler_common.h
index 4a45c0193..72202dc93 100644
--- a/src/rps/rps-sampler_common.h
+++ b/src/rps/rps-sampler_common.h
@@ -103,7 +103,8 @@ 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 */
106struct GetPeerCls { 106struct GetPeerCls
107{
107 /** 108 /**
108 * DLL 109 * DLL
109 */ 110 */
@@ -150,12 +151,13 @@ struct GetPeerCls {
150/** 151/**
151 * Sampler with its own array of SamplerElements 152 * Sampler with its own array of SamplerElements
152 */ 153 */
153struct RPS_Sampler { 154struct RPS_Sampler
155{
154 /** 156 /**
155 * Number of sampler elements we hold. 157 * Number of sampler elements we hold.
156 */ 158 */
157 unsigned int sampler_size; 159 unsigned int sampler_size;
158 //size_t size; 160 // size_t size;
159 161
160 /** 162 /**
161 * All sampler elements in one array. 163 * All sampler elements in one array.
@@ -220,8 +222,8 @@ struct RPS_Sampler {
220 * @param num_peers The estimated value 222 * @param num_peers The estimated value
221 */ 223 */
222void 224void
223RPS_sampler_update_with_nw_size(struct RPS_Sampler *sampler, 225RPS_sampler_update_with_nw_size (struct RPS_Sampler *sampler,
224 uint32_t num_peers); 226 uint32_t num_peers);
225 227
226 228
227/** 229/**
@@ -235,8 +237,8 @@ RPS_sampler_update_with_nw_size(struct RPS_Sampler *sampler,
235 * @param desired_probability 237 * @param desired_probability
236 */ 238 */
237void 239void
238RPS_sampler_set_desired_probability(struct RPS_Sampler *sampler, 240RPS_sampler_set_desired_probability (struct RPS_Sampler *sampler,
239 double desired_probability); 241 double desired_probability);
240 242
241 243
242/** 244/**
@@ -249,8 +251,8 @@ RPS_sampler_set_desired_probability(struct RPS_Sampler *sampler,
249 * @param desired_probability 251 * @param desired_probability
250 */ 252 */
251void 253void
252RPS_sampler_set_deficiency_factor(struct RPS_Sampler *sampler, 254RPS_sampler_set_deficiency_factor (struct RPS_Sampler *sampler,
253 double deficiency_factor); 255 double deficiency_factor);
254 256
255 257
256/** 258/**
@@ -264,9 +266,9 @@ RPS_sampler_set_deficiency_factor(struct RPS_Sampler *sampler,
264 * @return The context containing callback and closure 266 * @return The context containing callback and closure
265 */ 267 */
266struct SamplerNotifyUpdateCTX * 268struct SamplerNotifyUpdateCTX *
267sampler_notify_on_update(struct RPS_Sampler *sampler, 269sampler_notify_on_update (struct RPS_Sampler *sampler,
268 SamplerNotifyUpdateCB notify_cb, 270 SamplerNotifyUpdateCB notify_cb,
269 void *cls); 271 void *cls);
270 272
271 273
272/** 274/**
@@ -276,8 +278,8 @@ sampler_notify_on_update(struct RPS_Sampler *sampler,
276 * @param id the PeerID that is put in the sampler 278 * @param id the PeerID that is put in the sampler
277 */ 279 */
278void 280void
279RPS_sampler_update(struct RPS_Sampler *sampler, 281RPS_sampler_update (struct RPS_Sampler *sampler,
280 const struct GNUNET_PeerIdentity *id); 282 const struct GNUNET_PeerIdentity *id);
281 283
282 284
283/** 285/**
@@ -289,8 +291,8 @@ RPS_sampler_update(struct RPS_Sampler *sampler,
289 * @param id the id of the sampler elements to update. 291 * @param id the id of the sampler elements to update.
290 */ 292 */
291void 293void
292RPS_sampler_reinitialise_by_value(struct RPS_Sampler *sampler, 294RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler,
293 const struct GNUNET_PeerIdentity *id); 295 const struct GNUNET_PeerIdentity *id);
294 296
295 297
296/** 298/**
@@ -300,7 +302,7 @@ RPS_sampler_reinitialise_by_value(struct RPS_Sampler *sampler,
300 * @return the size of the sampler 302 * @return the size of the sampler
301 */ 303 */
302unsigned int 304unsigned int
303RPS_sampler_get_size(struct RPS_Sampler *sampler); 305RPS_sampler_get_size (struct RPS_Sampler *sampler);
304 306
305 307
306/** 308/**
@@ -310,7 +312,7 @@ RPS_sampler_get_size(struct RPS_Sampler *sampler);
310 * @param new_size the new size of the sampler 312 * @param new_size the new size of the sampler
311 */ 313 */
312void 314void
313RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size); 315RPS_sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size);
314 316
315 317
316/** 318/**
@@ -328,10 +330,10 @@ RPS_sampler_resize(struct RPS_Sampler *sampler, unsigned int new_size);
328 * @param num_peers the number of peers requested 330 * @param num_peers the number of peers requested
329 */ 331 */
330struct RPS_SamplerRequestHandle * 332struct RPS_SamplerRequestHandle *
331RPS_sampler_get_n_rand_peers(struct RPS_Sampler *sampler, 333RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler,
332 uint32_t num_peers, 334 uint32_t num_peers,
333 RPS_sampler_n_rand_peers_ready_cb cb, 335 RPS_sampler_n_rand_peers_ready_cb cb,
334 void *cls); 336 void *cls);
335 337
336 338
337/** 339/**
@@ -342,9 +344,9 @@ RPS_sampler_get_n_rand_peers(struct RPS_Sampler *sampler,
342 * @param cls closure given to @a cb 344 * @param cls closure given to @a cb
343 */ 345 */
344struct RPS_SamplerRequestHandleSingleInfo * 346struct RPS_SamplerRequestHandleSingleInfo *
345RPS_sampler_get_rand_peer_info(struct RPS_Sampler *sampler, 347RPS_sampler_get_rand_peer_info (struct RPS_Sampler *sampler,
346 RPS_sampler_sinlge_info_ready_cb cb, 348 RPS_sampler_sinlge_info_ready_cb cb,
347 void *cls); 349 void *cls);
348 350
349 351
350/** 352/**
@@ -356,8 +358,8 @@ RPS_sampler_get_rand_peer_info(struct RPS_Sampler *sampler,
356 * @return the number of occurrences of id. 358 * @return the number of occurrences of id.
357 */ 359 */
358uint32_t 360uint32_t
359RPS_sampler_count_id(struct RPS_Sampler *sampler, 361RPS_sampler_count_id (struct RPS_Sampler *sampler,
360 const struct GNUNET_PeerIdentity *id); 362 const struct GNUNET_PeerIdentity *id);
361 363
362 364
363/** 365/**
@@ -366,7 +368,7 @@ RPS_sampler_count_id(struct RPS_Sampler *sampler,
366 * @param req_handle the handle to the request 368 * @param req_handle the handle to the request
367 */ 369 */
368void 370void
369RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle); 371RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle);
370 372
371 373
372/** 374/**
@@ -375,7 +377,7 @@ RPS_sampler_request_cancel(struct RPS_SamplerRequestHandle *req_handle);
375 * @param req_handle the handle to the request 377 * @param req_handle the handle to the request
376 */ 378 */
377void 379void
378RPS_sampler_request_single_info_cancel( 380RPS_sampler_request_single_info_cancel (
379 struct RPS_SamplerRequestHandleSingleInfo *req_single_info_handle); 381 struct RPS_SamplerRequestHandleSingleInfo *req_single_info_handle);
380 382
381 383
@@ -383,7 +385,7 @@ RPS_sampler_request_single_info_cancel(
383 * Cleans the sampler. 385 * Cleans the sampler.
384 */ 386 */
385void 387void
386RPS_sampler_destroy(struct RPS_Sampler *sampler); 388RPS_sampler_destroy (struct RPS_Sampler *sampler);
387 389
388#endif /* RPS_SAMPLER_COMMON_H */ 390#endif /* RPS_SAMPLER_COMMON_H */
389/* end of rps-sampler_common.h */ 391/* end of rps-sampler_common.h */
diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c
index 8680494f8..66f93d86f 100644
--- a/src/rps/rps-test_util.c
+++ b/src/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 */
74struct GNUNET_DISK_FileHandle * 74struct GNUNET_DISK_FileHandle *
75get_file_handle(const char *name) 75get_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 */
129int 129int
130close_files_iter(void *cls, 130close_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 */
151int 151int
152close_all_files() 152close_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,58 +164,58 @@ close_all_files()
164 164
165 165
166void 166void
167to_file_raw(const char *file_name, const char *buf, size_t size_buf) 167to_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
209void 209void
210to_file_raw_unaligned(const char *file_name, 210to_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))
220 // { 220 // {
221 // to_file_raw (file_name, buf, size_buf); 221 // to_file_raw (file_name, buf, size_buf);
@@ -225,9 +225,9 @@ to_file_raw_unaligned(const char *file_name,
225 // buf_unaligned = buf[size_buf - 1]; 225 // buf_unaligned = buf[size_buf - 1];
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 ?
@@ -235,145 +235,145 @@ to_file_raw_unaligned(const char *file_name,
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)
249 { 337 {
250 /* Number of bits needed in this iteration - 8 for all except last iter */ 338 /* buf_unaligned was aligned by filling
251 unsigned num_bits_needed_iter; 339 * -> can be written to storage */
252 /* Mask for bits to actually use */ 340 buf_write[i] = byte_to_fill;
253 unsigned mask_bits_needed_iter; 341 size_buf_write++;
254 char byte_input; 342
255 /* Number of bits needed to align unaligned byte */ 343 /* store the leftover, unaligned bits in buffer */
256 unsigned num_bits_to_align; 344 mask_input_leftover = mask_bits_needed_iter & (~mask_input_to_move);
257 /* Number of bits that are to be moved */ 345 LOG (GNUNET_ERROR_TYPE_DEBUG,
258 unsigned num_bits_to_move; 346 "mask of leftover bits of new byte: "B2B_PAT "\n",
259 /* Mask for bytes to be moved */ 347 B2B (mask_input_leftover));
260 char mask_input_to_move; 348 byte_input_leftover = byte_input & mask_input_leftover;
261 /* Masked bits to be moved */ 349 LOG (GNUNET_ERROR_TYPE_DEBUG,
262 char bits_to_move; 350 "masked, leftover bits of new byte: "B2B_PAT "\n",
263 /* The amount of bits needed to fit the bits to shift to the nearest spot */ 351 B2B (byte_input_leftover));
264 unsigned distance_shift_bits; 352 num_bits_leftover = num_bits_needed_iter - num_bits_to_move;
265 /* Shifted bits on the move */ 353 LOG (GNUNET_ERROR_TYPE_DEBUG,
266 char bits_moving; 354 "number of unaligned bits left: %u\n",
267 /* (unaligned) byte being filled with bits */ 355 num_bits_leftover);
268 char byte_to_fill; 356 // num_bits_discard = 8 - num_bits_needed_iter;
269 /* mask for needed bits of the input byte that have not been moved */ 357 byte_unaligned_new = byte_input_leftover >> num_bits_to_move;
270 char mask_input_leftover; 358 LOG (GNUNET_ERROR_TYPE_DEBUG,
271 /* needed bits of the input byte that have not been moved */ 359 "new unaligned byte: "B2B_PAT "\n",
272 char byte_input_leftover; 360 B2B (byte_unaligned_new));
273 unsigned num_bits_leftover; 361 buf_unaligned = byte_unaligned_new;
274 //unsigned num_bits_discard; 362 num_bits_buf_unaligned = num_bits_leftover % 8;
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 }
370 } 363 }
371 to_file_raw(file_name, buf_write, size_buf_write); 364 else
372 LOG(GNUNET_ERROR_TYPE_DEBUG, "\n"); 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 }
370 }
371 to_file_raw (file_name, buf_write, size_buf_write);
372 LOG (GNUNET_ERROR_TYPE_DEBUG, "\n");
373} 373}
374 374
375char * 375char *
376auth_key_to_string(struct GNUNET_CRYPTO_AuthKey auth_key) 376auth_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;
@@ -383,33 +383,33 @@ auth_key_to_string(struct GNUNET_CRYPTO_AuthKey auth_key)
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
420struct GNUNET_CRYPTO_AuthKey 420struct GNUNET_CRYPTO_AuthKey
421string_to_auth_key(const char *str) 421string_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,60 +442,60 @@ string_to_auth_key(const char *str)
442 * #GNUNET_SYSERR on failure 442 * #GNUNET_SYSERR on failure
443 */ 443 */
444static int 444static int
445ensure_folder_exist(void) 445ensure_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
458char * 458char *
459store_prefix_file_name(const unsigned int index, 459store_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()) 467 if (GNUNET_SYSERR == ensure_folder_exist ())
468 return NULL; 468 return NULL;
469 out_size = GNUNET_snprintf(index_str, 469 out_size = GNUNET_snprintf (index_str,
470 64, 470 64,
471 "%u", 471 "%u",
472 index); 472 index);
473 if (64 < out_size || 473 if ((64 < out_size)||
474 0 > out_size) 474 (0 > out_size) )
475 { 475 {
476 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 476 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
477 "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",
478 64, 478 64,
479 out_size); 479 out_size);
480 } 480 }
481 len_file_name = (strlen(prefix) + 481 len_file_name = (strlen (prefix)
482 strlen(index_str) + 482 + strlen (index_str)
483 11) 483 + 11)
484 * sizeof(char); 484 * sizeof(char);
485 file_name = GNUNET_malloc(len_file_name); 485 file_name = GNUNET_malloc (len_file_name);
486 out_size = GNUNET_snprintf(file_name, 486 out_size = GNUNET_snprintf (file_name,
487 len_file_name, 487 len_file_name,
488 "/tmp/rps/%s-%s", 488 "/tmp/rps/%s-%s",
489 prefix, 489 prefix,
490 index_str); 490 index_str);
491 if (len_file_name < out_size || 491 if ((len_file_name < out_size)||
492 0 > out_size) 492 (0 > out_size) )
493 { 493 {
494 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 494 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
495 "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",
496 len_file_name, 496 len_file_name,
497 out_size); 497 out_size);
498 } 498 }
499 return file_name; 499 return file_name;
500} 500}
501 501
@@ -507,13 +507,13 @@ store_prefix_file_name(const unsigned int index,
507 * 507 *
508 * @return Factorial of @a x 508 * @return Factorial of @a x
509 */ 509 */
510uint32_t fac(uint32_t x) 510uint32_t fac (uint32_t x)
511{ 511{
512 if (1 >= x) 512 if (1 >= x)
513 { 513 {
514 return x; 514 return x;
515 } 515 }
516 return x * fac(x - 1); 516 return x * fac (x - 1);
517} 517}
518 518
519/** 519/**
@@ -524,18 +524,18 @@ uint32_t fac(uint32_t x)
524 * 524 *
525 * @return Binomial coefficient of @a n and @a k 525 * @return Binomial coefficient of @a n and @a k
526 */ 526 */
527uint32_t binom(uint32_t n, uint32_t k) 527uint32_t binom (uint32_t n, uint32_t k)
528{ 528{
529 //GNUNET_assert (n >= k); 529 // GNUNET_assert (n >= k);
530 if (k > n) 530 if (k > n)
531 return 0; 531 return 0;
532 /* if (0 > n) return 0; - always false */ 532 /* if (0 > n) return 0; - always false */
533 /* if (0 > k) return 0; - always false */ 533 /* if (0 > k) return 0; - always false */
534 if (0 == k) 534 if (0 == k)
535 return 1; 535 return 1;
536 return fac(n) 536 return fac (n)
537 / 537 /
538 fac(k) * fac(n - k); 538 fac (k) * fac (n - k);
539} 539}
540 540
541 541
diff --git a/src/rps/rps-test_util.h b/src/rps/rps-test_util.h
index f978059c3..2f11f0105 100644
--- a/src/rps/rps-test_util.h
+++ b/src/rps/rps-test_util.h
@@ -32,10 +32,10 @@
32 32
33 33
34char * 34char *
35auth_key_to_string(struct GNUNET_CRYPTO_AuthKey auth_key); 35auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key);
36 36
37struct GNUNET_CRYPTO_AuthKey 37struct GNUNET_CRYPTO_AuthKey
38string_to_auth_key(const char *str); 38string_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 */
50struct GNUNET_DISK_FileHandle * 50struct GNUNET_DISK_FileHandle *
51get_file_handle(const char *name); 51get_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,62 +56,69 @@ get_file_handle(const char *name);
56 * @return Success of iterating over files 56 * @return Success of iterating over files
57 */ 57 */
58int 58int
59close_all_files(); 59close_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, \
87 sizeof( \
88 tmp_buf), \
89 __VA_ARGS__); \
87 if (0 > size) \ 90 if (0 > size) \
88 { \ 91 { \
89 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, \ 92 GNUNET_log ( \
90 "Failed to create tmp_buf\n"); \ 93 GNUNET_ERROR_TYPE_WARNING, \
91 break; \ 94 "Failed to create tmp_buf\n"); \
92 } \ 95 break; \
93 (void)strncat(tmp_buf, "\n", len); \ 96 } \
94 GNUNET_DISK_file_write(get_file_handle(file_name), \ 97 (void) strncat (tmp_buf, "\n", \
95 tmp_buf, \ 98 len); \
96 strnlen(tmp_buf, len)); \ 99 GNUNET_DISK_file_write ( \
97 } while (0); 100 get_file_handle (file_name), \
101 tmp_buf, \
102 strnlen ( \
103 tmp_buf, len)); \
104} while (0);
98#else /* TO_FILE */ 105#else /* TO_FILE */
99# define to_file(file_name, ...) 106# define to_file(file_name, ...)
100# define to_file_w_len(file_name, len, ...) 107# define to_file_w_len(file_name, len, ...)
101#endif /* TO_FILE */ 108#endif /* TO_FILE */
102 109
103char * 110char *
104store_prefix_file_name(const unsigned int index, 111store_prefix_file_name (const unsigned int index,
105 const char *prefix); 112 const char *prefix);
106 113
107void 114void
108to_file_raw(const char *file_name, const char *buf, size_t size_buf); 115to_file_raw (const char *file_name, const char *buf, size_t size_buf);
109 116
110void 117void
111to_file_raw_unaligned(const char *file_name, 118to_file_raw_unaligned (const char *file_name,
112 const char *buf, 119 const char *buf,
113 size_t size_buf, 120 size_t size_buf,
114 unsigned bits_needed); 121 unsigned bits_needed);
115 122
116 123
117/** 124/**
@@ -121,7 +128,7 @@ to_file_raw_unaligned(const char *file_name,
121 * 128 *
122 * @return Factorial of @a x 129 * @return Factorial of @a x
123 */ 130 */
124uint32_t fac(uint32_t x); 131uint32_t fac (uint32_t x);
125 132
126 133
127/** 134/**
@@ -132,7 +139,7 @@ uint32_t fac(uint32_t x);
132 * 139 *
133 * @return Binomial coefficient of @a n and @a k 140 * @return Binomial coefficient of @a n and @a k
134 */ 141 */
135uint32_t binom(uint32_t n, uint32_t k); 142uint32_t binom (uint32_t n, uint32_t k);
136 143
137#endif /* RPS_TEST_UTIL_H */ 144#endif /* RPS_TEST_UTIL_H */
138/* end of gnunet-service-rps.c */ 145/* end of gnunet-service-rps.c */
diff --git a/src/rps/rps.h b/src/rps/rps.h
index dee6162be..32e5d07af 100644
--- a/src/rps/rps.h
+++ b/src/rps/rps.h
@@ -40,7 +40,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
40/** 40/**
41 * P2P Message to send PeerIDs to other peer. 41 * P2P Message to send PeerIDs to other peer.
42 */ 42 */
43struct GNUNET_RPS_P2P_PullReplyMessage { 43struct GNUNET_RPS_P2P_PullReplyMessage
44{
44 /** 45 /**
45 * Header including size and type in NBO 46 * Header including size and type in NBO
46 */ 47 */
@@ -63,7 +64,8 @@ struct GNUNET_RPS_P2P_PullReplyMessage {
63/** 64/**
64 * Message from client to service with seed of peers. 65 * Message from client to service with seed of peers.
65 */ 66 */
66struct GNUNET_RPS_CS_SeedMessage { 67struct GNUNET_RPS_CS_SeedMessage
68{
67 /** 69 /**
68 * Header including size and type in NBO 70 * Header including size and type in NBO
69 */ 71 */
@@ -81,7 +83,8 @@ struct GNUNET_RPS_CS_SeedMessage {
81/** 83/**
82 * Message from client to service to turn service malicious. 84 * Message from client to service to turn service malicious.
83 */ 85 */
84struct GNUNET_RPS_CS_ActMaliciousMessage { 86struct GNUNET_RPS_CS_ActMaliciousMessage
87{
85 /** 88 /**
86 * Header including size and type in NBO 89 * Header including size and type in NBO
87 */ 90 */
@@ -116,7 +119,8 @@ struct GNUNET_RPS_CS_ActMaliciousMessage {
116/** 119/**
117 * Message from client to service telling it to start a new sub 120 * Message from client to service telling it to start a new sub
118 */ 121 */
119struct GNUNET_RPS_CS_SubStartMessage { 122struct GNUNET_RPS_CS_SubStartMessage
123{
120 /** 124 /**
121 * Header including size and type in NBO 125 * Header including size and type in NBO
122 */ 126 */
@@ -142,7 +146,8 @@ struct GNUNET_RPS_CS_SubStartMessage {
142/** 146/**
143 * Message from client to service telling it to stop a new sub 147 * Message from client to service telling it to stop a new sub
144 */ 148 */
145struct GNUNET_RPS_CS_SubStopMessage { 149struct GNUNET_RPS_CS_SubStopMessage
150{
146 /** 151 /**
147 * Header including size and type in NBO 152 * Header including size and type in NBO
148 */ 153 */
@@ -161,7 +166,8 @@ struct GNUNET_RPS_CS_SubStopMessage {
161 * Message from client to service indicating that 166 * Message from client to service indicating that
162 * clients wants to get updates of the view 167 * clients wants to get updates of the view
163 */ 168 */
164struct GNUNET_RPS_CS_DEBUG_ViewRequest { 169struct GNUNET_RPS_CS_DEBUG_ViewRequest
170{
165 /** 171 /**
166 * Header including size and type in NBO 172 * Header including size and type in NBO
167 */ 173 */
@@ -177,7 +183,8 @@ struct GNUNET_RPS_CS_DEBUG_ViewRequest {
177/** 183/**
178 * Message from service to client containing current update of view 184 * Message from service to client containing current update of view
179 */ 185 */
180struct GNUNET_RPS_CS_DEBUG_ViewReply { 186struct GNUNET_RPS_CS_DEBUG_ViewReply
187{
181 /** 188 /**
182 * Header including size and type in NBO 189 * Header including size and type in NBO
183 */ 190 */
@@ -199,7 +206,8 @@ struct GNUNET_RPS_CS_DEBUG_ViewReply {
199 * Message from client to service indicating that 206 * Message from client to service indicating that
200 * clients wants to get stream of biased peers 207 * clients wants to get stream of biased peers
201 */ 208 */
202struct GNUNET_RPS_CS_DEBUG_StreamRequest { 209struct GNUNET_RPS_CS_DEBUG_StreamRequest
210{
203 /** 211 /**
204 * Header including size and type in NBO 212 * Header including size and type in NBO
205 */ 213 */
@@ -209,7 +217,8 @@ struct GNUNET_RPS_CS_DEBUG_StreamRequest {
209/** 217/**
210 * Message from service to client containing peer from biased stream 218 * Message from service to client containing peer from biased stream
211 */ 219 */
212struct GNUNET_RPS_CS_DEBUG_StreamReply { 220struct GNUNET_RPS_CS_DEBUG_StreamReply
221{
213 /** 222 /**
214 * Header including size and type in NBO 223 * Header including size and type in NBO
215 */ 224 */
@@ -234,7 +243,8 @@ GNUNET_NETWORK_STRUCT_END
234/** 243/**
235 * Different flags indicating the status of another peer. 244 * Different flags indicating the status of another peer.
236 */ 245 */
237enum Peers_PeerFlags { 246enum Peers_PeerFlags
247{
238 /** 248 /**
239 * If we are waiting for a reply from that peer (sent a pull request). 249 * If we are waiting for a reply from that peer (sent a pull request).
240 */ 250 */
@@ -263,7 +273,8 @@ enum Peers_PeerFlags {
263 * This is needed in order to know what to do with a channel when it's 273 * This is needed in order to know what to do with a channel when it's
264 * destroyed. 274 * destroyed.
265 */ 275 */
266enum Peers_ChannelFlags { 276enum Peers_ChannelFlags
277{
267 /** 278 /**
268 * We destroyed the channel because the other peer established a second one. 279 * We destroyed the channel because the other peer established a second one.
269 */ 280 */
@@ -285,7 +296,8 @@ enum Peers_ChannelFlags {
285/** 296/**
286 * @brief The role of a channel. Sending or receiving. 297 * @brief The role of a channel. Sending or receiving.
287 */ 298 */
288enum Peers_ChannelRole { 299enum Peers_ChannelRole
300{
289 /** 301 /**
290 * Channel is used for sending 302 * Channel is used for sending
291 */ 303 */
@@ -303,7 +315,7 @@ enum Peers_ChannelRole {
303 * @param cls closure 315 * @param cls closure
304 * @param peer peer to execute function on 316 * @param peer peer to execute function on
305 */ 317 */
306typedef void (* PeerOp) (void *cls, const struct GNUNET_PeerIdentity *peer); 318typedef void (*PeerOp) (void *cls, const struct GNUNET_PeerIdentity *peer);
307 319
308/** 320/**
309 * @brief Iterator over valid peers. 321 * @brief Iterator over valid peers.
@@ -323,4 +335,3 @@ typedef int
323 * Handle to the statistics service. 335 * Handle to the statistics service.
324 */ 336 */
325extern struct GNUNET_STATISTICS_Handle *stats; 337extern struct GNUNET_STATISTICS_Handle *stats;
326
diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c
index 2b54297c3..19cbdcf8a 100644
--- a/src/rps/rps_api.c
+++ b/src/rps/rps_api.c
@@ -33,12 +33,13 @@
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 */
41struct GNUNET_RPS_StreamRequestHandle { 41struct GNUNET_RPS_StreamRequestHandle
42{
42 /** 43 /**
43 * The client issuing the request. 44 * The client issuing the request.
44 */ 45 */
@@ -74,7 +75,8 @@ struct GNUNET_RPS_StreamRequestHandle {
74/** 75/**
75 * Handler to handle requests from a client. 76 * Handler to handle requests from a client.
76 */ 77 */
77struct GNUNET_RPS_Handle { 78struct GNUNET_RPS_Handle
79{
78 /** 80 /**
79 * The handle to the client configuration. 81 * The handle to the client configuration.
80 */ 82 */
@@ -154,7 +156,8 @@ struct GNUNET_RPS_Handle {
154/** 156/**
155 * Handler for a single request from a client. 157 * Handler for a single request from a client.
156 */ 158 */
157struct GNUNET_RPS_Request_Handle { 159struct GNUNET_RPS_Request_Handle
160{
158 /** 161 /**
159 * The client issuing the request. 162 * The client issuing the request.
160 */ 163 */
@@ -206,7 +209,8 @@ struct GNUNET_RPS_Request_Handle {
206/** 209/**
207 * Handler for a single request from a client. 210 * Handler for a single request from a client.
208 */ 211 */
209struct GNUNET_RPS_Request_Handle_Single_Info { 212struct GNUNET_RPS_Request_Handle_Single_Info
213{
210 /** 214 /**
211 * The client issuing the request. 215 * The client issuing the request.
212 */ 216 */
@@ -254,7 +258,8 @@ struct GNUNET_RPS_Request_Handle_Single_Info {
254 * Struct used to pack the callback, its closure (provided by the caller) 258 * Struct used to pack the callback, its closure (provided by the caller)
255 * and the connection handler to the service to pass it to a callback function. 259 * and the connection handler to the service to pass it to a callback function.
256 */ 260 */
257struct cb_cls_pack { 261struct cb_cls_pack
262{
258 /** 263 /**
259 * Callback provided by the client 264 * Callback provided by the client
260 */ 265 */
@@ -296,19 +301,19 @@ static uint64_t srh_callback_num_peers;
296 * @return The handle to the stream request 301 * @return The handle to the stream request
297 */ 302 */
298static struct GNUNET_RPS_StreamRequestHandle * 303static struct GNUNET_RPS_StreamRequestHandle *
299new_stream_request(struct GNUNET_RPS_Handle *rps_handle, 304new_stream_request (struct GNUNET_RPS_Handle *rps_handle,
300 GNUNET_RPS_NotifyReadyCB ready_cb, 305 GNUNET_RPS_NotifyReadyCB ready_cb,
301 void *cls) 306 void *cls)
302{ 307{
303 struct GNUNET_RPS_StreamRequestHandle *srh; 308 struct GNUNET_RPS_StreamRequestHandle *srh;
304 309
305 srh = GNUNET_new(struct GNUNET_RPS_StreamRequestHandle); 310 srh = GNUNET_new (struct GNUNET_RPS_StreamRequestHandle);
306 srh->rps_handle = rps_handle; 311 srh->rps_handle = rps_handle;
307 srh->ready_cb = ready_cb; 312 srh->ready_cb = ready_cb;
308 srh->ready_cb_cls = cls; 313 srh->ready_cb_cls = cls;
309 GNUNET_CONTAINER_DLL_insert(rps_handle->stream_requests_head, 314 GNUNET_CONTAINER_DLL_insert (rps_handle->stream_requests_head,
310 rps_handle->stream_requests_tail, 315 rps_handle->stream_requests_tail,
311 srh); 316 srh);
312 317
313 return srh; 318 return srh;
314} 319}
@@ -320,20 +325,20 @@ new_stream_request(struct GNUNET_RPS_Handle *rps_handle,
320 * @param srh The request to be removed 325 * @param srh The request to be removed
321 */ 326 */
322static void 327static void
323remove_stream_request(struct GNUNET_RPS_StreamRequestHandle *srh) 328remove_stream_request (struct GNUNET_RPS_StreamRequestHandle *srh)
324{ 329{
325 struct GNUNET_RPS_Handle *rps_handle = srh->rps_handle; 330 struct GNUNET_RPS_Handle *rps_handle = srh->rps_handle;
326 331
327 GNUNET_assert(NULL != srh); 332 GNUNET_assert (NULL != srh);
328 if (NULL != srh->callback_task) 333 if (NULL != srh->callback_task)
329 { 334 {
330 GNUNET_SCHEDULER_cancel(srh->callback_task); 335 GNUNET_SCHEDULER_cancel (srh->callback_task);
331 srh->callback_task = NULL; 336 srh->callback_task = NULL;
332 } 337 }
333 GNUNET_CONTAINER_DLL_remove(rps_handle->stream_requests_head, 338 GNUNET_CONTAINER_DLL_remove (rps_handle->stream_requests_head,
334 rps_handle->stream_requests_tail, 339 rps_handle->stream_requests_tail,
335 srh); 340 srh);
336 GNUNET_free(srh); 341 GNUNET_free (srh);
337} 342}
338 343
339 344
@@ -347,17 +352,17 @@ remove_stream_request(struct GNUNET_RPS_StreamRequestHandle *srh)
347 * @param cls The #GNUNET_RPS_Request_Handle 352 * @param cls The #GNUNET_RPS_Request_Handle
348 */ 353 */
349static void 354static void
350peers_ready_cb(const struct GNUNET_PeerIdentity *peers, 355peers_ready_cb (const struct GNUNET_PeerIdentity *peers,
351 uint32_t num_peers, 356 uint32_t num_peers,
352 void *cls) 357 void *cls)
353{ 358{
354 struct GNUNET_RPS_Request_Handle *rh = cls; 359 struct GNUNET_RPS_Request_Handle *rh = cls;
355 360
356 rh->sampler_rh = NULL; 361 rh->sampler_rh = NULL;
357 rh->ready_cb(rh->ready_cb_cls, 362 rh->ready_cb (rh->ready_cb_cls,
358 num_peers, 363 num_peers,
359 peers); 364 peers);
360 GNUNET_RPS_request_cancel(rh); 365 GNUNET_RPS_request_cancel (rh);
361} 366}
362 367
363 368
@@ -373,19 +378,19 @@ peers_ready_cb(const struct GNUNET_PeerIdentity *peers,
373 * @param num_observed Number of observed IDs 378 * @param num_observed Number of observed IDs
374 */ 379 */
375static void 380static void
376peer_info_ready_cb(const struct GNUNET_PeerIdentity *peers, 381peer_info_ready_cb (const struct GNUNET_PeerIdentity *peers,
377 void *cls, 382 void *cls,
378 double probability, 383 double probability,
379 uint32_t num_observed) 384 uint32_t num_observed)
380{ 385{
381 struct GNUNET_RPS_Request_Handle_Single_Info *rh = cls; 386 struct GNUNET_RPS_Request_Handle_Single_Info *rh = cls;
382 387
383 rh->sampler_rh = NULL; 388 rh->sampler_rh = NULL;
384 rh->ready_cb(rh->ready_cb_cls, 389 rh->ready_cb (rh->ready_cb_cls,
385 peers, 390 peers,
386 probability, 391 probability,
387 num_observed); 392 num_observed);
388 GNUNET_RPS_request_single_info_cancel(rh); 393 GNUNET_RPS_request_single_info_cancel (rh);
389} 394}
390 395
391 396
@@ -398,19 +403,19 @@ peer_info_ready_cb(const struct GNUNET_PeerIdentity *peers,
398 * @param peers The array of @a num_peers that have been returned 403 * @param peers The array of @a num_peers that have been returned
399 */ 404 */
400static void 405static void
401collect_peers_cb(void *cls, 406collect_peers_cb (void *cls,
402 uint64_t num_peers, 407 uint64_t num_peers,
403 const struct GNUNET_PeerIdentity *peers) 408 const struct GNUNET_PeerIdentity *peers)
404{ 409{
405 struct GNUNET_RPS_Request_Handle *rh = cls; 410 struct GNUNET_RPS_Request_Handle *rh = cls;
406 411
407 LOG(GNUNET_ERROR_TYPE_DEBUG, 412 LOG (GNUNET_ERROR_TYPE_DEBUG,
408 "Service sent %" PRIu64 " peers from stream\n", 413 "Service sent %" PRIu64 " peers from stream\n",
409 num_peers); 414 num_peers);
410 for (uint64_t i = 0; i < num_peers; i++) 415 for (uint64_t i = 0; i < num_peers; i++)
411 { 416 {
412 RPS_sampler_update(rh->sampler, &peers[i]); 417 RPS_sampler_update (rh->sampler, &peers[i]);
413 } 418 }
414} 419}
415 420
416 421
@@ -425,19 +430,19 @@ collect_peers_cb(void *cls,
425 * @param peers The array of @a num_peers that have been returned 430 * @param peers The array of @a num_peers that have been returned
426 */ 431 */
427static void 432static void
428collect_peers_info_cb(void *cls, 433collect_peers_info_cb (void *cls,
429 uint64_t num_peers, 434 uint64_t num_peers,
430 const struct GNUNET_PeerIdentity *peers) 435 const struct GNUNET_PeerIdentity *peers)
431{ 436{
432 struct GNUNET_RPS_Request_Handle_Single_Info *rhs = cls; 437 struct GNUNET_RPS_Request_Handle_Single_Info *rhs = cls;
433 438
434 LOG(GNUNET_ERROR_TYPE_DEBUG, 439 LOG (GNUNET_ERROR_TYPE_DEBUG,
435 "Service sent %" PRIu64 " peers from stream\n", 440 "Service sent %" PRIu64 " peers from stream\n",
436 num_peers); 441 num_peers);
437 for (uint64_t i = 0; i < num_peers; i++) 442 for (uint64_t i = 0; i < num_peers; i++)
438 { 443 {
439 RPS_sampler_update(rhs->sampler, &peers[i]); 444 RPS_sampler_update (rhs->sampler, &peers[i]);
440 } 445 }
441} 446}
442 447
443 448
@@ -453,37 +458,37 @@ collect_peers_info_cb(void *cls,
453 * @param ready_cb the callback called when the peers are available 458 * @param ready_cb the callback called when the peers are available
454 */ 459 */
455void 460void
456GNUNET_RPS_view_request(struct GNUNET_RPS_Handle *rps_handle, 461GNUNET_RPS_view_request (struct GNUNET_RPS_Handle *rps_handle,
457 uint32_t num_updates, 462 uint32_t num_updates,
458 GNUNET_RPS_NotifyReadyCB view_update_cb, 463 GNUNET_RPS_NotifyReadyCB view_update_cb,
459 void *cls) 464 void *cls)
460{ 465{
461 struct GNUNET_MQ_Envelope *ev; 466 struct GNUNET_MQ_Envelope *ev;
462 struct GNUNET_RPS_CS_DEBUG_ViewRequest *msg; 467 struct GNUNET_RPS_CS_DEBUG_ViewRequest *msg;
463 468
464 LOG(GNUNET_ERROR_TYPE_DEBUG, 469 LOG (GNUNET_ERROR_TYPE_DEBUG,
465 "Client requests %" PRIu32 " view updates\n", 470 "Client requests %" PRIu32 " view updates\n",
466 num_updates); 471 num_updates);
467 rps_handle->view_update_cb = view_update_cb; 472 rps_handle->view_update_cb = view_update_cb;
468 rps_handle->view_update_cls = cls; 473 rps_handle->view_update_cls = cls;
469 474
470 ev = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST); 475 ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REQUEST);
471 msg->num_updates = htonl(num_updates); 476 msg->num_updates = htonl (num_updates);
472 GNUNET_MQ_send(rps_handle->mq, ev); 477 GNUNET_MQ_send (rps_handle->mq, ev);
473} 478}
474 479
475 480
476void 481void
477GNUNET_RPS_view_request_cancel(struct GNUNET_RPS_Handle *rps_handle) 482GNUNET_RPS_view_request_cancel (struct GNUNET_RPS_Handle *rps_handle)
478{ 483{
479 struct GNUNET_MQ_Envelope *ev; 484 struct GNUNET_MQ_Envelope *ev;
480 485
481 GNUNET_assert(NULL != rps_handle->view_update_cb); 486 GNUNET_assert (NULL != rps_handle->view_update_cb);
482 487
483 rps_handle->view_update_cb = NULL; 488 rps_handle->view_update_cb = NULL;
484 489
485 ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL); 490 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_CANCEL);
486 GNUNET_MQ_send(rps_handle->mq, ev); 491 GNUNET_MQ_send (rps_handle->mq, ev);
487} 492}
488 493
489 494
@@ -495,21 +500,21 @@ GNUNET_RPS_view_request_cancel(struct GNUNET_RPS_Handle *rps_handle)
495 * @param ready_cb the callback called when the peers are available 500 * @param ready_cb the callback called when the peers are available
496 */ 501 */
497struct GNUNET_RPS_StreamRequestHandle * 502struct GNUNET_RPS_StreamRequestHandle *
498GNUNET_RPS_stream_request(struct GNUNET_RPS_Handle *rps_handle, 503GNUNET_RPS_stream_request (struct GNUNET_RPS_Handle *rps_handle,
499 GNUNET_RPS_NotifyReadyCB stream_input_cb, 504 GNUNET_RPS_NotifyReadyCB stream_input_cb,
500 void *cls) 505 void *cls)
501{ 506{
502 struct GNUNET_RPS_StreamRequestHandle *srh; 507 struct GNUNET_RPS_StreamRequestHandle *srh;
503 struct GNUNET_MQ_Envelope *ev; 508 struct GNUNET_MQ_Envelope *ev;
504 struct GNUNET_RPS_CS_DEBUG_StreamRequest *msg; 509 struct GNUNET_RPS_CS_DEBUG_StreamRequest *msg;
505 510
506 srh = new_stream_request(rps_handle, 511 srh = new_stream_request (rps_handle,
507 stream_input_cb, 512 stream_input_cb,
508 cls); 513 cls);
509 LOG(GNUNET_ERROR_TYPE_DEBUG, "Client requests biased stream updates\n"); 514 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client requests biased stream updates\n");
510 515
511 ev = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST); 516 ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REQUEST);
512 GNUNET_MQ_send(rps_handle->mq, ev); 517 GNUNET_MQ_send (rps_handle->mq, ev);
513 return srh; 518 return srh;
514} 519}
515 520
@@ -523,21 +528,21 @@ GNUNET_RPS_stream_request(struct GNUNET_RPS_Handle *rps_handle,
523 * @return #GNUNET_OK if @a msg is well-formed 528 * @return #GNUNET_OK if @a msg is well-formed
524 */ 529 */
525static int 530static int
526check_view_update(void *cls, 531check_view_update (void *cls,
527 const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg) 532 const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg)
528{ 533{
529 uint16_t msize = ntohs(msg->header.size); 534 uint16_t msize = ntohs (msg->header.size);
530 uint32_t num_peers = ntohl(msg->num_peers); 535 uint32_t num_peers = ntohl (msg->num_peers);
531 536
532 (void)cls; 537 (void) cls;
533 538
534 msize -= sizeof(struct GNUNET_RPS_CS_DEBUG_ViewReply); 539 msize -= sizeof(struct GNUNET_RPS_CS_DEBUG_ViewReply);
535 if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) || 540 if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) ||
536 (msize % sizeof(struct GNUNET_PeerIdentity) != 0)) 541 (msize % sizeof(struct GNUNET_PeerIdentity) != 0))
537 { 542 {
538 GNUNET_break(0); 543 GNUNET_break (0);
539 return GNUNET_SYSERR; 544 return GNUNET_SYSERR;
540 } 545 }
541 return GNUNET_OK; 546 return GNUNET_OK;
542} 547}
543 548
@@ -550,21 +555,21 @@ check_view_update(void *cls,
550 * @param msg the message 555 * @param msg the message
551 */ 556 */
552static void 557static void
553handle_view_update(void *cls, 558handle_view_update (void *cls,
554 const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg) 559 const struct GNUNET_RPS_CS_DEBUG_ViewReply *msg)
555{ 560{
556 struct GNUNET_RPS_Handle *h = cls; 561 struct GNUNET_RPS_Handle *h = cls;
557 struct GNUNET_PeerIdentity *peers; 562 struct GNUNET_PeerIdentity *peers;
558 563
559 /* Give the peers back */ 564 /* Give the peers back */
560 LOG(GNUNET_ERROR_TYPE_DEBUG, 565 LOG (GNUNET_ERROR_TYPE_DEBUG,
561 "New view of %" PRIu32 " peers:\n", 566 "New view of %" PRIu32 " peers:\n",
562 ntohl(msg->num_peers)); 567 ntohl (msg->num_peers));
563 568
564 peers = (struct GNUNET_PeerIdentity *)&msg[1]; 569 peers = (struct GNUNET_PeerIdentity *) &msg[1];
565 GNUNET_assert(NULL != h); 570 GNUNET_assert (NULL != h);
566 GNUNET_assert(NULL != h->view_update_cb); 571 GNUNET_assert (NULL != h->view_update_cb);
567 h->view_update_cb(h->view_update_cls, ntohl(msg->num_peers), peers); 572 h->view_update_cb (h->view_update_cls, ntohl (msg->num_peers), peers);
568} 573}
569 574
570 575
@@ -575,12 +580,12 @@ handle_view_update(void *cls,
575 * @param rps_handle The handle representing the service to the client 580 * @param rps_handle The handle representing the service to the client
576 */ 581 */
577static void 582static void
578cancel_stream(struct GNUNET_RPS_Handle *rps_handle) 583cancel_stream (struct GNUNET_RPS_Handle *rps_handle)
579{ 584{
580 struct GNUNET_MQ_Envelope *ev; 585 struct GNUNET_MQ_Envelope *ev;
581 586
582 ev = GNUNET_MQ_msg_header(GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_CANCEL); 587 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_CANCEL);
583 GNUNET_MQ_send(rps_handle->mq, ev); 588 GNUNET_MQ_send (rps_handle->mq, ev);
584} 589}
585 590
586 591
@@ -590,14 +595,14 @@ cancel_stream(struct GNUNET_RPS_Handle *rps_handle)
590 * @param srh The request handle to cancel 595 * @param srh The request handle to cancel
591 */ 596 */
592void 597void
593GNUNET_RPS_stream_cancel(struct GNUNET_RPS_StreamRequestHandle *srh) 598GNUNET_RPS_stream_cancel (struct GNUNET_RPS_StreamRequestHandle *srh)
594{ 599{
595 struct GNUNET_RPS_Handle *rps_handle; 600 struct GNUNET_RPS_Handle *rps_handle;
596 601
597 rps_handle = srh->rps_handle; 602 rps_handle = srh->rps_handle;
598 remove_stream_request(srh); 603 remove_stream_request (srh);
599 if (NULL == rps_handle->stream_requests_head) 604 if (NULL == rps_handle->stream_requests_head)
600 cancel_stream(rps_handle); 605 cancel_stream (rps_handle);
601} 606}
602 607
603 608
@@ -612,21 +617,21 @@ GNUNET_RPS_stream_cancel(struct GNUNET_RPS_StreamRequestHandle *srh)
612 * @param msg the message 617 * @param msg the message
613 */ 618 */
614static int 619static int
615check_stream_input(void *cls, 620check_stream_input (void *cls,
616 const struct GNUNET_RPS_CS_DEBUG_StreamReply *msg) 621 const struct GNUNET_RPS_CS_DEBUG_StreamReply *msg)
617{ 622{
618 uint16_t msize = ntohs(msg->header.size); 623 uint16_t msize = ntohs (msg->header.size);
619 uint32_t num_peers = ntohl(msg->num_peers); 624 uint32_t num_peers = ntohl (msg->num_peers);
620 625
621 (void)cls; 626 (void) cls;
622 627
623 msize -= sizeof(struct GNUNET_RPS_CS_DEBUG_StreamReply); 628 msize -= sizeof(struct GNUNET_RPS_CS_DEBUG_StreamReply);
624 if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) || 629 if ((msize / sizeof(struct GNUNET_PeerIdentity) != num_peers) ||
625 (msize % sizeof(struct GNUNET_PeerIdentity) != 0)) 630 (msize % sizeof(struct GNUNET_PeerIdentity) != 0))
626 { 631 {
627 GNUNET_break(0); 632 GNUNET_break (0);
628 return GNUNET_SYSERR; 633 return GNUNET_SYSERR;
629 } 634 }
630 return GNUNET_OK; 635 return GNUNET_OK;
631} 636}
632 637
@@ -637,14 +642,14 @@ check_stream_input(void *cls,
637 * @param cls Stream request handle 642 * @param cls Stream request handle
638 */ 643 */
639static void 644static void
640srh_callback_scheduled(void *cls) 645srh_callback_scheduled (void *cls)
641{ 646{
642 struct GNUNET_RPS_StreamRequestHandle *srh = cls; 647 struct GNUNET_RPS_StreamRequestHandle *srh = cls;
643 648
644 srh->callback_task = NULL; 649 srh->callback_task = NULL;
645 srh->ready_cb(srh->ready_cb_cls, 650 srh->ready_cb (srh->ready_cb_cls,
646 srh_callback_num_peers, 651 srh_callback_num_peers,
647 srh_callback_peers); 652 srh_callback_peers);
648} 653}
649 654
650 655
@@ -657,45 +662,45 @@ srh_callback_scheduled(void *cls)
657 * @param msg the message 662 * @param msg the message
658 */ 663 */
659static void 664static void
660handle_stream_input(void *cls, 665handle_stream_input (void *cls,
661 const struct GNUNET_RPS_CS_DEBUG_StreamReply *msg) 666 const struct GNUNET_RPS_CS_DEBUG_StreamReply *msg)
662{ 667{
663 struct GNUNET_RPS_Handle *h = cls; 668 struct GNUNET_RPS_Handle *h = cls;
664 //const struct GNUNET_PeerIdentity *peers; 669 // const struct GNUNET_PeerIdentity *peers;
665 uint64_t num_peers; 670 uint64_t num_peers;
666 struct GNUNET_RPS_StreamRequestHandle *srh_iter; 671 struct GNUNET_RPS_StreamRequestHandle *srh_iter;
667 struct GNUNET_RPS_StreamRequestHandle *srh_next; 672 struct GNUNET_RPS_StreamRequestHandle *srh_next;
668 673
669 //peers = (struct GNUNET_PeerIdentity *) &msg[1]; 674 // peers = (struct GNUNET_PeerIdentity *) &msg[1];
670 num_peers = ntohl(msg->num_peers); 675 num_peers = ntohl (msg->num_peers);
671 srh_callback_num_peers = num_peers; 676 srh_callback_num_peers = num_peers;
672 GNUNET_free_non_null(srh_callback_peers); 677 GNUNET_free_non_null (srh_callback_peers);
673 srh_callback_peers = GNUNET_new_array(num_peers, 678 srh_callback_peers = GNUNET_new_array (num_peers,
674 struct GNUNET_PeerIdentity); 679 struct GNUNET_PeerIdentity);
675 GNUNET_memcpy(srh_callback_peers, 680 GNUNET_memcpy (srh_callback_peers,
676 &msg[1], 681 &msg[1],
677 num_peers * sizeof(struct GNUNET_PeerIdentity)); 682 num_peers * sizeof(struct GNUNET_PeerIdentity));
678 LOG(GNUNET_ERROR_TYPE_DEBUG, 683 LOG (GNUNET_ERROR_TYPE_DEBUG,
679 "Received %" PRIu64 " peer(s) from stream input.\n", 684 "Received %" PRIu64 " peer(s) from stream input.\n",
680 num_peers); 685 num_peers);
681 for (srh_iter = h->stream_requests_head; 686 for (srh_iter = h->stream_requests_head;
682 NULL != srh_iter; 687 NULL != srh_iter;
683 srh_iter = srh_next) 688 srh_iter = srh_next)
684 { 689 {
685 LOG(GNUNET_ERROR_TYPE_DEBUG, "Calling srh \n"); 690 LOG (GNUNET_ERROR_TYPE_DEBUG, "Calling srh \n");
686 /* Store next pointer - srh might be removed/freed in callback */ 691 /* Store next pointer - srh might be removed/freed in callback */
687 srh_next = srh_iter->next; 692 srh_next = srh_iter->next;
688 if (NULL != srh_iter->callback_task) 693 if (NULL != srh_iter->callback_task)
689 GNUNET_SCHEDULER_cancel(srh_iter->callback_task); 694 GNUNET_SCHEDULER_cancel (srh_iter->callback_task);
690 srh_iter->callback_task = 695 srh_iter->callback_task =
691 GNUNET_SCHEDULER_add_now(&srh_callback_scheduled, 696 GNUNET_SCHEDULER_add_now (&srh_callback_scheduled,
692 srh_iter); 697 srh_iter);
693 } 698 }
694 699
695 if (NULL == h->stream_requests_head) 700 if (NULL == h->stream_requests_head)
696 { 701 {
697 cancel_stream(h); 702 cancel_stream (h);
698 } 703 }
699} 704}
700 705
701 706
@@ -703,7 +708,7 @@ handle_stream_input(void *cls,
703 * Reconnect to the service 708 * Reconnect to the service
704 */ 709 */
705static void 710static void
706reconnect(struct GNUNET_RPS_Handle *h); 711reconnect (struct GNUNET_RPS_Handle *h);
707 712
708 713
709/** 714/**
@@ -716,19 +721,20 @@ reconnect(struct GNUNET_RPS_Handle *h);
716 * @param error error code without specyfied meaning 721 * @param error error code without specyfied meaning
717 */ 722 */
718static void 723static void
719mq_error_handler(void *cls, 724mq_error_handler (void *cls,
720 enum GNUNET_MQ_Error error) 725 enum GNUNET_MQ_Error error)
721{ 726{
722 struct GNUNET_RPS_Handle *h = cls; 727 struct GNUNET_RPS_Handle *h = cls;
723 728
724 //TODO LOG 729 // TODO LOG
725 LOG(GNUNET_ERROR_TYPE_WARNING, "Problem with message queue. error: %i\n\ 730 LOG (GNUNET_ERROR_TYPE_WARNING,
731 "Problem with message queue. error: %i\n\
726 1: READ,\n\ 732 1: READ,\n\
727 2: WRITE,\n\ 733 2: WRITE,\n\
728 4: TIMEOUT\n", 734 4: TIMEOUT\n",
729 // TODO: write GNUNET_MQ_strerror (error) 735 // TODO: write GNUNET_MQ_strerror (error)
730 error); 736 error);
731 reconnect(h); 737 reconnect (h);
732 /* Resend all pending request as the service destroyed its knowledge 738 /* Resend all pending request as the service destroyed its knowledge
733 * about them */ 739 * about them */
734} 740}
@@ -742,16 +748,16 @@ mq_error_handler(void *cls,
742 * @param hash[out] Pointer to the location in which the hash will be stored. 748 * @param hash[out] Pointer to the location in which the hash will be stored.
743 */ 749 */
744static void 750static void
745hash_from_share_val(const char *share_val, 751hash_from_share_val (const char *share_val,
746 struct GNUNET_HashCode *hash) 752 struct GNUNET_HashCode *hash)
747{ 753{
748 GNUNET_CRYPTO_kdf(hash, 754 GNUNET_CRYPTO_kdf (hash,
749 sizeof(struct GNUNET_HashCode), 755 sizeof(struct GNUNET_HashCode),
750 "rps", 756 "rps",
751 strlen("rps"), 757 strlen ("rps"),
752 share_val, 758 share_val,
753 strlen(share_val), 759 strlen (share_val),
754 NULL, 0); 760 NULL, 0);
755} 761}
756 762
757 763
@@ -767,30 +773,32 @@ hash_from_share_val(const char *share_val,
767 * @param std_dev the standard distribution 773 * @param std_dev the standard distribution
768 */ 774 */
769static void 775static void
770nse_cb(void *cls, 776nse_cb (void *cls,
771 struct GNUNET_TIME_Absolute timestamp, 777 struct GNUNET_TIME_Absolute timestamp,
772 double logestimate, 778 double logestimate,
773 double std_dev) 779 double std_dev)
774{ 780{
775 struct GNUNET_RPS_Handle *h = cls; 781 struct GNUNET_RPS_Handle *h = cls;
776 782
777 (void)timestamp; 783 (void) timestamp;
778 (void)std_dev; 784 (void) std_dev;
779 785
780 for (struct GNUNET_RPS_Request_Handle *rh_iter = h->rh_head; 786 for (struct GNUNET_RPS_Request_Handle *rh_iter = h->rh_head;
781 NULL != rh_iter && NULL != rh_iter->next; 787 NULL != rh_iter && NULL != rh_iter->next;
782 rh_iter = rh_iter->next) 788 rh_iter = rh_iter->next)
783 { 789 {
784 RPS_sampler_update_with_nw_size(rh_iter->sampler, 790 RPS_sampler_update_with_nw_size (rh_iter->sampler,
785 GNUNET_NSE_log_estimate_to_n(logestimate)); 791 GNUNET_NSE_log_estimate_to_n (
786 } 792 logestimate));
793 }
787 for (struct GNUNET_RPS_Request_Handle_Single_Info *rhs_iter = h->rhs_head; 794 for (struct GNUNET_RPS_Request_Handle_Single_Info *rhs_iter = h->rhs_head;
788 NULL != rhs_iter && NULL != rhs_iter->next; 795 NULL != rhs_iter && NULL != rhs_iter->next;
789 rhs_iter = rhs_iter->next) 796 rhs_iter = rhs_iter->next)
790 { 797 {
791 RPS_sampler_update_with_nw_size(rhs_iter->sampler, 798 RPS_sampler_update_with_nw_size (rhs_iter->sampler,
792 GNUNET_NSE_log_estimate_to_n(logestimate)); 799 GNUNET_NSE_log_estimate_to_n (
793 } 800 logestimate));
801 }
794} 802}
795 803
796 804
@@ -798,30 +806,30 @@ nse_cb(void *cls,
798 * Reconnect to the service 806 * Reconnect to the service
799 */ 807 */
800static void 808static void
801reconnect(struct GNUNET_RPS_Handle *h) 809reconnect (struct GNUNET_RPS_Handle *h)
802{ 810{
803 struct GNUNET_MQ_MessageHandler mq_handlers[] = { 811 struct GNUNET_MQ_MessageHandler mq_handlers[] = {
804 GNUNET_MQ_hd_var_size(view_update, 812 GNUNET_MQ_hd_var_size (view_update,
805 GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY, 813 GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_VIEW_REPLY,
806 struct GNUNET_RPS_CS_DEBUG_ViewReply, 814 struct GNUNET_RPS_CS_DEBUG_ViewReply,
807 h), 815 h),
808 GNUNET_MQ_hd_var_size(stream_input, 816 GNUNET_MQ_hd_var_size (stream_input,
809 GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY, 817 GNUNET_MESSAGE_TYPE_RPS_CS_DEBUG_STREAM_REPLY,
810 struct GNUNET_RPS_CS_DEBUG_StreamReply, 818 struct GNUNET_RPS_CS_DEBUG_StreamReply,
811 h), 819 h),
812 GNUNET_MQ_handler_end() 820 GNUNET_MQ_handler_end ()
813 }; 821 };
814 822
815 if (NULL != h->mq) 823 if (NULL != h->mq)
816 GNUNET_MQ_destroy(h->mq); 824 GNUNET_MQ_destroy (h->mq);
817 h->mq = GNUNET_CLIENT_connect(h->cfg, 825 h->mq = GNUNET_CLIENT_connect (h->cfg,
818 "rps", 826 "rps",
819 mq_handlers, 827 mq_handlers,
820 &mq_error_handler, 828 &mq_error_handler,
821 h); 829 h);
822 if (NULL != h->nse) 830 if (NULL != h->nse)
823 GNUNET_NSE_disconnect(h->nse); 831 GNUNET_NSE_disconnect (h->nse);
824 h->nse = GNUNET_NSE_connect(h->cfg, &nse_cb, h); 832 h->nse = GNUNET_NSE_connect (h->cfg, &nse_cb, h);
825} 833}
826 834
827 835
@@ -832,56 +840,56 @@ reconnect(struct GNUNET_RPS_Handle *h)
832 * @return a handle to the service, NULL on error 840 * @return a handle to the service, NULL on error
833 */ 841 */
834struct GNUNET_RPS_Handle * 842struct GNUNET_RPS_Handle *
835GNUNET_RPS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) 843GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
836{ 844{
837 struct GNUNET_RPS_Handle *h; 845 struct GNUNET_RPS_Handle *h;
838 846
839 h = GNUNET_new(struct GNUNET_RPS_Handle); 847 h = GNUNET_new (struct GNUNET_RPS_Handle);
840 h->cfg = cfg; 848 h->cfg = cfg;
841 if (GNUNET_OK != 849 if (GNUNET_OK !=
842 GNUNET_CONFIGURATION_get_value_float(cfg, 850 GNUNET_CONFIGURATION_get_value_float (cfg,
843 "RPS", 851 "RPS",
844 "DESIRED_PROBABILITY", 852 "DESIRED_PROBABILITY",
845 &h->desired_probability)) 853 &h->desired_probability))
846 { 854 {
847 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, 855 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
848 "RPS", "DESIRED_PROBABILITY"); 856 "RPS", "DESIRED_PROBABILITY");
849 GNUNET_free(h); 857 GNUNET_free (h);
850 return NULL; 858 return NULL;
851 } 859 }
852 if (0 > h->desired_probability || 860 if ((0 > h->desired_probability)||
853 1 < h->desired_probability) 861 (1 < h->desired_probability) )
854 { 862 {
855 LOG(GNUNET_ERROR_TYPE_ERROR, 863 LOG (GNUNET_ERROR_TYPE_ERROR,
856 "The desired probability must be in the interval [0;1]\n"); 864 "The desired probability must be in the interval [0;1]\n");
857 GNUNET_free(h); 865 GNUNET_free (h);
858 return NULL; 866 return NULL;
859 } 867 }
860 if (GNUNET_OK != 868 if (GNUNET_OK !=
861 GNUNET_CONFIGURATION_get_value_float(cfg, 869 GNUNET_CONFIGURATION_get_value_float (cfg,
862 "RPS", 870 "RPS",
863 "DEFICIENCY_FACTOR", 871 "DEFICIENCY_FACTOR",
864 &h->deficiency_factor)) 872 &h->deficiency_factor))
865 { 873 {
866 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, 874 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
867 "RPS", "DEFICIENCY_FACTOR"); 875 "RPS", "DEFICIENCY_FACTOR");
868 GNUNET_free(h); 876 GNUNET_free (h);
869 return NULL; 877 return NULL;
870 } 878 }
871 if (0 > h->desired_probability || 879 if ((0 > h->desired_probability)||
872 1 < h->desired_probability) 880 (1 < h->desired_probability) )
873 { 881 {
874 LOG(GNUNET_ERROR_TYPE_ERROR, 882 LOG (GNUNET_ERROR_TYPE_ERROR,
875 "The deficiency factor must be in the interval [0;1]\n"); 883 "The deficiency factor must be in the interval [0;1]\n");
876 GNUNET_free(h); 884 GNUNET_free (h);
877 return NULL; 885 return NULL;
878 } 886 }
879 reconnect(h); 887 reconnect (h);
880 if (NULL == h->mq) 888 if (NULL == h->mq)
881 { 889 {
882 GNUNET_free(h); 890 GNUNET_free (h);
883 return NULL; 891 return NULL;
884 } 892 }
885 return h; 893 return h;
886} 894}
887 895
@@ -893,19 +901,19 @@ GNUNET_RPS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
893 * @param shared_value The shared value that defines the members of the sub (-gorup) 901 * @param shared_value The shared value that defines the members of the sub (-gorup)
894 */ 902 */
895void 903void
896GNUNET_RPS_sub_start(struct GNUNET_RPS_Handle *h, 904GNUNET_RPS_sub_start (struct GNUNET_RPS_Handle *h,
897 const char *shared_value) 905 const char *shared_value)
898{ 906{
899 struct GNUNET_RPS_CS_SubStartMessage *msg; 907 struct GNUNET_RPS_CS_SubStartMessage *msg;
900 struct GNUNET_MQ_Envelope *ev; 908 struct GNUNET_MQ_Envelope *ev;
901 909
902 ev = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_RPS_CS_SUB_START); 910 ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_SUB_START);
903 hash_from_share_val(shared_value, &msg->hash); 911 hash_from_share_val (shared_value, &msg->hash);
904 msg->round_interval = GNUNET_TIME_relative_hton( // TODO read from config! 912 msg->round_interval = GNUNET_TIME_relative_hton ( // TODO read from config!
905 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)); 913 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30));
906 GNUNET_assert(0 != msg->round_interval.rel_value_us__); 914 GNUNET_assert (0 != msg->round_interval.rel_value_us__);
907 915
908 GNUNET_MQ_send(h->mq, ev); 916 GNUNET_MQ_send (h->mq, ev);
909} 917}
910 918
911 919
@@ -916,16 +924,16 @@ GNUNET_RPS_sub_start(struct GNUNET_RPS_Handle *h,
916 * @param shared_value The shared value that defines the members of the sub (-gorup) 924 * @param shared_value The shared value that defines the members of the sub (-gorup)
917 */ 925 */
918void 926void
919GNUNET_RPS_sub_stop(struct GNUNET_RPS_Handle *h, 927GNUNET_RPS_sub_stop (struct GNUNET_RPS_Handle *h,
920 const char *shared_value) 928 const char *shared_value)
921{ 929{
922 struct GNUNET_RPS_CS_SubStopMessage *msg; 930 struct GNUNET_RPS_CS_SubStopMessage *msg;
923 struct GNUNET_MQ_Envelope *ev; 931 struct GNUNET_MQ_Envelope *ev;
924 932
925 ev = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_RPS_CS_SUB_STOP); 933 ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_SUB_STOP);
926 hash_from_share_val(shared_value, &msg->hash); 934 hash_from_share_val (shared_value, &msg->hash);
927 935
928 GNUNET_MQ_send(h->mq, ev); 936 GNUNET_MQ_send (h->mq, ev);
929} 937}
930 938
931 939
@@ -939,37 +947,37 @@ GNUNET_RPS_sub_stop(struct GNUNET_RPS_Handle *h,
939 * @return a handle to cancel this request 947 * @return a handle to cancel this request
940 */ 948 */
941struct GNUNET_RPS_Request_Handle * 949struct GNUNET_RPS_Request_Handle *
942GNUNET_RPS_request_peers(struct GNUNET_RPS_Handle *rps_handle, 950GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle,
943 uint32_t num_req_peers, 951 uint32_t num_req_peers,
944 GNUNET_RPS_NotifyReadyCB ready_cb, 952 GNUNET_RPS_NotifyReadyCB ready_cb,
945 void *cls) 953 void *cls)
946{ 954{
947 struct GNUNET_RPS_Request_Handle *rh; 955 struct GNUNET_RPS_Request_Handle *rh;
948 956
949 LOG(GNUNET_ERROR_TYPE_INFO, 957 LOG (GNUNET_ERROR_TYPE_INFO,
950 "Client requested %" PRIu32 " peers\n", 958 "Client requested %" PRIu32 " peers\n",
951 num_req_peers); 959 num_req_peers);
952 rh = GNUNET_new(struct GNUNET_RPS_Request_Handle); 960 rh = GNUNET_new (struct GNUNET_RPS_Request_Handle);
953 rh->rps_handle = rps_handle; 961 rh->rps_handle = rps_handle;
954 rh->num_requests = num_req_peers; 962 rh->num_requests = num_req_peers;
955 rh->sampler = RPS_sampler_mod_init(num_req_peers, 963 rh->sampler = RPS_sampler_mod_init (num_req_peers,
956 GNUNET_TIME_UNIT_SECONDS); // TODO remove this time-stuff 964 GNUNET_TIME_UNIT_SECONDS); // TODO remove this time-stuff
957 RPS_sampler_set_desired_probability(rh->sampler, 965 RPS_sampler_set_desired_probability (rh->sampler,
958 rps_handle->desired_probability); 966 rps_handle->desired_probability);
959 RPS_sampler_set_deficiency_factor(rh->sampler, 967 RPS_sampler_set_deficiency_factor (rh->sampler,
960 rps_handle->deficiency_factor); 968 rps_handle->deficiency_factor);
961 rh->sampler_rh = RPS_sampler_get_n_rand_peers(rh->sampler, 969 rh->sampler_rh = RPS_sampler_get_n_rand_peers (rh->sampler,
962 num_req_peers, 970 num_req_peers,
963 peers_ready_cb, 971 peers_ready_cb,
964 rh); 972 rh);
965 rh->srh = GNUNET_RPS_stream_request(rps_handle, 973 rh->srh = GNUNET_RPS_stream_request (rps_handle,
966 collect_peers_cb, 974 collect_peers_cb,
967 rh); /* cls */ 975 rh); /* cls */
968 rh->ready_cb = ready_cb; 976 rh->ready_cb = ready_cb;
969 rh->ready_cb_cls = cls; 977 rh->ready_cb_cls = cls;
970 GNUNET_CONTAINER_DLL_insert(rps_handle->rh_head, 978 GNUNET_CONTAINER_DLL_insert (rps_handle->rh_head,
971 rps_handle->rh_tail, 979 rps_handle->rh_tail,
972 rh); 980 rh);
973 981
974 return rh; 982 return rh;
975} 983}
@@ -984,34 +992,34 @@ GNUNET_RPS_request_peers(struct GNUNET_RPS_Handle *rps_handle,
984 * @return a handle to cancel this request 992 * @return a handle to cancel this request
985 */ 993 */
986struct GNUNET_RPS_Request_Handle_Single_Info * 994struct GNUNET_RPS_Request_Handle_Single_Info *
987GNUNET_RPS_request_peer_info(struct GNUNET_RPS_Handle *rps_handle, 995GNUNET_RPS_request_peer_info (struct GNUNET_RPS_Handle *rps_handle,
988 GNUNET_RPS_NotifyReadySingleInfoCB ready_cb, 996 GNUNET_RPS_NotifyReadySingleInfoCB ready_cb,
989 void *cls) 997 void *cls)
990{ 998{
991 struct GNUNET_RPS_Request_Handle_Single_Info *rhs; 999 struct GNUNET_RPS_Request_Handle_Single_Info *rhs;
992 uint32_t num_req_peers = 1; 1000 uint32_t num_req_peers = 1;
993 1001
994 LOG(GNUNET_ERROR_TYPE_INFO, 1002 LOG (GNUNET_ERROR_TYPE_INFO,
995 "Client requested peer with additional info\n"); 1003 "Client requested peer with additional info\n");
996 rhs = GNUNET_new(struct GNUNET_RPS_Request_Handle_Single_Info); 1004 rhs = GNUNET_new (struct GNUNET_RPS_Request_Handle_Single_Info);
997 rhs->rps_handle = rps_handle; 1005 rhs->rps_handle = rps_handle;
998 rhs->sampler = RPS_sampler_mod_init(num_req_peers, 1006 rhs->sampler = RPS_sampler_mod_init (num_req_peers,
999 GNUNET_TIME_UNIT_SECONDS); // TODO remove this time-stuff 1007 GNUNET_TIME_UNIT_SECONDS); // TODO remove this time-stuff
1000 RPS_sampler_set_desired_probability(rhs->sampler, 1008 RPS_sampler_set_desired_probability (rhs->sampler,
1001 rps_handle->desired_probability); 1009 rps_handle->desired_probability);
1002 RPS_sampler_set_deficiency_factor(rhs->sampler, 1010 RPS_sampler_set_deficiency_factor (rhs->sampler,
1003 rps_handle->deficiency_factor); 1011 rps_handle->deficiency_factor);
1004 rhs->sampler_rh = RPS_sampler_get_rand_peer_info(rhs->sampler, 1012 rhs->sampler_rh = RPS_sampler_get_rand_peer_info (rhs->sampler,
1005 peer_info_ready_cb, 1013 peer_info_ready_cb,
1006 rhs); 1014 rhs);
1007 rhs->srh = GNUNET_RPS_stream_request(rps_handle, 1015 rhs->srh = GNUNET_RPS_stream_request (rps_handle,
1008 collect_peers_info_cb, 1016 collect_peers_info_cb,
1009 rhs); /* cls */ 1017 rhs); /* cls */
1010 rhs->ready_cb = ready_cb; 1018 rhs->ready_cb = ready_cb;
1011 rhs->ready_cb_cls = cls; 1019 rhs->ready_cb_cls = cls;
1012 GNUNET_CONTAINER_DLL_insert(rps_handle->rhs_head, 1020 GNUNET_CONTAINER_DLL_insert (rps_handle->rhs_head,
1013 rps_handle->rhs_tail, 1021 rps_handle->rhs_tail,
1014 rhs); 1022 rhs);
1015 1023
1016 return rhs; 1024 return rhs;
1017} 1025}
@@ -1025,9 +1033,9 @@ GNUNET_RPS_request_peer_info(struct GNUNET_RPS_Handle *rps_handle,
1025 * @param ids the ids of the peers seeded 1033 * @param ids the ids of the peers seeded
1026 */ 1034 */
1027void 1035void
1028GNUNET_RPS_seed_ids(struct GNUNET_RPS_Handle *h, 1036GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h,
1029 uint32_t n, 1037 uint32_t n,
1030 const struct GNUNET_PeerIdentity *ids) 1038 const struct GNUNET_PeerIdentity *ids)
1031{ 1039{
1032 size_t size_needed; 1040 size_t size_needed;
1033 uint32_t num_peers_max; 1041 uint32_t num_peers_max;
@@ -1035,52 +1043,53 @@ GNUNET_RPS_seed_ids(struct GNUNET_RPS_Handle *h,
1035 struct GNUNET_MQ_Envelope *ev; 1043 struct GNUNET_MQ_Envelope *ev;
1036 struct GNUNET_RPS_CS_SeedMessage *msg; 1044 struct GNUNET_RPS_CS_SeedMessage *msg;
1037 1045
1038 LOG(GNUNET_ERROR_TYPE_DEBUG, 1046 LOG (GNUNET_ERROR_TYPE_DEBUG,
1039 "Client wants to seed %" PRIu32 " peers:\n", 1047 "Client wants to seed %" PRIu32 " peers:\n",
1040 n); 1048 n);
1041 for (unsigned int i = 0; i < n; i++) 1049 for (unsigned int i = 0; i < n; i++)
1042 LOG(GNUNET_ERROR_TYPE_DEBUG, 1050 LOG (GNUNET_ERROR_TYPE_DEBUG,
1043 "%u. peer: %s\n", 1051 "%u. peer: %s\n",
1044 i, 1052 i,
1045 GNUNET_i2s(&ids[i])); 1053 GNUNET_i2s (&ids[i]));
1046 1054
1047 /* The actual size the message occupies */ 1055 /* The actual size the message occupies */
1048 size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage) + 1056 size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage)
1049 n * sizeof(struct GNUNET_PeerIdentity); 1057 + n * sizeof(struct GNUNET_PeerIdentity);
1050 /* The number of peers that fits in one message together with 1058 /* The number of peers that fits in one message together with
1051 * the respective header */ 1059 * the respective header */
1052 num_peers_max = (GNUNET_MAX_MESSAGE_SIZE - 1060 num_peers_max = (GNUNET_MAX_MESSAGE_SIZE
1053 sizeof(struct GNUNET_RPS_CS_SeedMessage)) / 1061 - sizeof(struct GNUNET_RPS_CS_SeedMessage))
1054 sizeof(struct GNUNET_PeerIdentity); 1062 / sizeof(struct GNUNET_PeerIdentity);
1055 tmp_peer_pointer = ids; 1063 tmp_peer_pointer = ids;
1056 1064
1057 while (GNUNET_MAX_MESSAGE_SIZE < size_needed) 1065 while (GNUNET_MAX_MESSAGE_SIZE < size_needed)
1058 { 1066 {
1059 ev = GNUNET_MQ_msg_extra(msg, 1067 ev = GNUNET_MQ_msg_extra (msg,
1060 num_peers_max * sizeof(struct GNUNET_PeerIdentity), 1068 num_peers_max * sizeof(struct
1061 GNUNET_MESSAGE_TYPE_RPS_CS_SEED); 1069 GNUNET_PeerIdentity),
1062 msg->num_peers = htonl(num_peers_max); 1070 GNUNET_MESSAGE_TYPE_RPS_CS_SEED);
1063 GNUNET_memcpy(&msg[1], 1071 msg->num_peers = htonl (num_peers_max);
1064 tmp_peer_pointer, 1072 GNUNET_memcpy (&msg[1],
1065 num_peers_max * sizeof(struct GNUNET_PeerIdentity)); 1073 tmp_peer_pointer,
1066 GNUNET_MQ_send(h->mq, 1074 num_peers_max * sizeof(struct GNUNET_PeerIdentity));
1067 ev); 1075 GNUNET_MQ_send (h->mq,
1068 n -= num_peers_max; 1076 ev);
1069 size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage) + 1077 n -= num_peers_max;
1070 n * sizeof(struct GNUNET_PeerIdentity); 1078 size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage)
1071 /* Set pointer to beginning of next block of num_peers_max peers */ 1079 + n * sizeof(struct GNUNET_PeerIdentity);
1072 tmp_peer_pointer = &ids[num_peers_max]; 1080 /* Set pointer to beginning of next block of num_peers_max peers */
1073 } 1081 tmp_peer_pointer = &ids[num_peers_max];
1074 1082 }
1075 ev = GNUNET_MQ_msg_extra(msg, 1083
1076 n * sizeof(struct GNUNET_PeerIdentity), 1084 ev = GNUNET_MQ_msg_extra (msg,
1077 GNUNET_MESSAGE_TYPE_RPS_CS_SEED); 1085 n * sizeof(struct GNUNET_PeerIdentity),
1078 msg->num_peers = htonl(n); 1086 GNUNET_MESSAGE_TYPE_RPS_CS_SEED);
1079 GNUNET_memcpy(&msg[1], 1087 msg->num_peers = htonl (n);
1080 tmp_peer_pointer, 1088 GNUNET_memcpy (&msg[1],
1081 n * sizeof(struct GNUNET_PeerIdentity)); 1089 tmp_peer_pointer,
1082 GNUNET_MQ_send(h->mq, 1090 n * sizeof(struct GNUNET_PeerIdentity));
1083 ev); 1091 GNUNET_MQ_send (h->mq,
1092 ev);
1084} 1093}
1085 1094
1086 1095
@@ -1100,11 +1109,11 @@ GNUNET_RPS_seed_ids(struct GNUNET_RPS_Handle *h,
1100 * peer to be isolated from the rest 1109 * peer to be isolated from the rest
1101 */ 1110 */
1102void 1111void
1103GNUNET_RPS_act_malicious(struct GNUNET_RPS_Handle *h, 1112GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h,
1104 uint32_t type, 1113 uint32_t type,
1105 uint32_t num_peers, 1114 uint32_t num_peers,
1106 const struct GNUNET_PeerIdentity *peer_ids, 1115 const struct GNUNET_PeerIdentity *peer_ids,
1107 const struct GNUNET_PeerIdentity *target_peer) 1116 const struct GNUNET_PeerIdentity *target_peer)
1108{ 1117{
1109 size_t size_needed; 1118 size_t size_needed;
1110 uint32_t num_peers_max; 1119 uint32_t num_peers_max;
@@ -1114,65 +1123,68 @@ GNUNET_RPS_act_malicious(struct GNUNET_RPS_Handle *h,
1114 1123
1115 unsigned int i; 1124 unsigned int i;
1116 1125
1117 LOG(GNUNET_ERROR_TYPE_DEBUG, 1126 LOG (GNUNET_ERROR_TYPE_DEBUG,
1118 "Client turns malicious (type %" PRIu32 ") with %" PRIu32 " other peers:\n", 1127 "Client turns malicious (type %" PRIu32 ") with %" PRIu32
1119 type, 1128 " other peers:\n",
1120 num_peers); 1129 type,
1130 num_peers);
1121 for (i = 0; i < num_peers; i++) 1131 for (i = 0; i < num_peers; i++)
1122 LOG(GNUNET_ERROR_TYPE_DEBUG, 1132 LOG (GNUNET_ERROR_TYPE_DEBUG,
1123 "%u. peer: %s\n", 1133 "%u. peer: %s\n",
1124 i, 1134 i,
1125 GNUNET_i2s(&peer_ids[i])); 1135 GNUNET_i2s (&peer_ids[i]));
1126 1136
1127 /* The actual size the message would occupy */ 1137 /* The actual size the message would occupy */
1128 size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage) + 1138 size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage)
1129 num_peers * sizeof(struct GNUNET_PeerIdentity); 1139 + num_peers * sizeof(struct GNUNET_PeerIdentity);
1130 /* The number of peers that fit in one message together with 1140 /* The number of peers that fit in one message together with
1131 * the respective header */ 1141 * the respective header */
1132 num_peers_max = (GNUNET_MAX_MESSAGE_SIZE - 1142 num_peers_max = (GNUNET_MAX_MESSAGE_SIZE
1133 sizeof(struct GNUNET_RPS_CS_SeedMessage)) / 1143 - sizeof(struct GNUNET_RPS_CS_SeedMessage))
1134 sizeof(struct GNUNET_PeerIdentity); 1144 / sizeof(struct GNUNET_PeerIdentity);
1135 tmp_peer_pointer = peer_ids; 1145 tmp_peer_pointer = peer_ids;
1136 1146
1137 while (GNUNET_MAX_MESSAGE_SIZE < size_needed) 1147 while (GNUNET_MAX_MESSAGE_SIZE < size_needed)
1138 { 1148 {
1139 LOG(GNUNET_ERROR_TYPE_DEBUG, 1149 LOG (GNUNET_ERROR_TYPE_DEBUG,
1140 "Too many peers to send at once, sending %" PRIu32 " (all we can so far)\n", 1150 "Too many peers to send at once, sending %" PRIu32
1141 num_peers_max); 1151 " (all we can so far)\n",
1142 ev = GNUNET_MQ_msg_extra(msg, 1152 num_peers_max);
1143 num_peers_max * sizeof(struct GNUNET_PeerIdentity), 1153 ev = GNUNET_MQ_msg_extra (msg,
1144 GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS); 1154 num_peers_max * sizeof(struct
1145 msg->type = htonl(type); 1155 GNUNET_PeerIdentity),
1146 msg->num_peers = htonl(num_peers_max); 1156 GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS);
1147 if ((2 == type) || 1157 msg->type = htonl (type);
1148 (3 == type)) 1158 msg->num_peers = htonl (num_peers_max);
1149 msg->attacked_peer = peer_ids[num_peers]; 1159 if ((2 == type) ||
1150 GNUNET_memcpy(&msg[1], 1160 (3 == type))
1151 tmp_peer_pointer, 1161 msg->attacked_peer = peer_ids[num_peers];
1152 num_peers_max * sizeof(struct GNUNET_PeerIdentity)); 1162 GNUNET_memcpy (&msg[1],
1153 1163 tmp_peer_pointer,
1154 GNUNET_MQ_send(h->mq, ev); 1164 num_peers_max * sizeof(struct GNUNET_PeerIdentity));
1155 1165
1156 num_peers -= num_peers_max; 1166 GNUNET_MQ_send (h->mq, ev);
1157 size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage) + 1167
1158 num_peers * sizeof(struct GNUNET_PeerIdentity); 1168 num_peers -= num_peers_max;
1159 /* Set pointer to beginning of next block of num_peers_max peers */ 1169 size_needed = sizeof(struct GNUNET_RPS_CS_SeedMessage)
1160 tmp_peer_pointer = &peer_ids[num_peers_max]; 1170 + num_peers * sizeof(struct GNUNET_PeerIdentity);
1161 } 1171 /* Set pointer to beginning of next block of num_peers_max peers */
1162 1172 tmp_peer_pointer = &peer_ids[num_peers_max];
1163 ev = GNUNET_MQ_msg_extra(msg, 1173 }
1164 num_peers * sizeof(struct GNUNET_PeerIdentity), 1174
1165 GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS); 1175 ev = GNUNET_MQ_msg_extra (msg,
1166 msg->type = htonl(type); 1176 num_peers * sizeof(struct GNUNET_PeerIdentity),
1167 msg->num_peers = htonl(num_peers); 1177 GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS);
1178 msg->type = htonl (type);
1179 msg->num_peers = htonl (num_peers);
1168 if ((2 == type) || 1180 if ((2 == type) ||
1169 (3 == type)) 1181 (3 == type))
1170 msg->attacked_peer = *target_peer; 1182 msg->attacked_peer = *target_peer;
1171 GNUNET_memcpy(&msg[1], 1183 GNUNET_memcpy (&msg[1],
1172 tmp_peer_pointer, 1184 tmp_peer_pointer,
1173 num_peers * sizeof(struct GNUNET_PeerIdentity)); 1185 num_peers * sizeof(struct GNUNET_PeerIdentity));
1174 1186
1175 GNUNET_MQ_send(h->mq, ev); 1187 GNUNET_MQ_send (h->mq, ev);
1176} 1188}
1177#endif /* ENABLE_MALICIOUS */ 1189#endif /* ENABLE_MALICIOUS */
1178 1190
@@ -1183,28 +1195,28 @@ GNUNET_RPS_act_malicious(struct GNUNET_RPS_Handle *h,
1183 * @param rh request handle of request to cancle 1195 * @param rh request handle of request to cancle
1184 */ 1196 */
1185void 1197void
1186GNUNET_RPS_request_cancel(struct GNUNET_RPS_Request_Handle *rh) 1198GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh)
1187{ 1199{
1188 struct GNUNET_RPS_Handle *h; 1200 struct GNUNET_RPS_Handle *h;
1189 1201
1190 h = rh->rps_handle; 1202 h = rh->rps_handle;
1191 GNUNET_assert(NULL != rh); 1203 GNUNET_assert (NULL != rh);
1192 GNUNET_assert(NULL != rh->srh); 1204 GNUNET_assert (NULL != rh->srh);
1193 GNUNET_assert(h == rh->srh->rps_handle); 1205 GNUNET_assert (h == rh->srh->rps_handle);
1194 GNUNET_RPS_stream_cancel(rh->srh); 1206 GNUNET_RPS_stream_cancel (rh->srh);
1195 rh->srh = NULL; 1207 rh->srh = NULL;
1196 if (NULL == h->stream_requests_head) 1208 if (NULL == h->stream_requests_head)
1197 cancel_stream(h); 1209 cancel_stream (h);
1198 if (NULL != rh->sampler_rh) 1210 if (NULL != rh->sampler_rh)
1199 { 1211 {
1200 RPS_sampler_request_cancel(rh->sampler_rh); 1212 RPS_sampler_request_cancel (rh->sampler_rh);
1201 } 1213 }
1202 RPS_sampler_destroy(rh->sampler); 1214 RPS_sampler_destroy (rh->sampler);
1203 rh->sampler = NULL; 1215 rh->sampler = NULL;
1204 GNUNET_CONTAINER_DLL_remove(h->rh_head, 1216 GNUNET_CONTAINER_DLL_remove (h->rh_head,
1205 h->rh_tail, 1217 h->rh_tail,
1206 rh); 1218 rh);
1207 GNUNET_free(rh); 1219 GNUNET_free (rh);
1208} 1220}
1209 1221
1210 1222
@@ -1214,29 +1226,29 @@ GNUNET_RPS_request_cancel(struct GNUNET_RPS_Request_Handle *rh)
1214 * @param rhs request handle of request to cancle 1226 * @param rhs request handle of request to cancle
1215 */ 1227 */
1216void 1228void
1217GNUNET_RPS_request_single_info_cancel( 1229GNUNET_RPS_request_single_info_cancel (
1218 struct GNUNET_RPS_Request_Handle_Single_Info *rhs) 1230 struct GNUNET_RPS_Request_Handle_Single_Info *rhs)
1219{ 1231{
1220 struct GNUNET_RPS_Handle *h; 1232 struct GNUNET_RPS_Handle *h;
1221 1233
1222 h = rhs->rps_handle; 1234 h = rhs->rps_handle;
1223 GNUNET_assert(NULL != rhs); 1235 GNUNET_assert (NULL != rhs);
1224 GNUNET_assert(NULL != rhs->srh); 1236 GNUNET_assert (NULL != rhs->srh);
1225 GNUNET_assert(h == rhs->srh->rps_handle); 1237 GNUNET_assert (h == rhs->srh->rps_handle);
1226 GNUNET_RPS_stream_cancel(rhs->srh); 1238 GNUNET_RPS_stream_cancel (rhs->srh);
1227 rhs->srh = NULL; 1239 rhs->srh = NULL;
1228 if (NULL == h->stream_requests_head) 1240 if (NULL == h->stream_requests_head)
1229 cancel_stream(h); 1241 cancel_stream (h);
1230 if (NULL != rhs->sampler_rh) 1242 if (NULL != rhs->sampler_rh)
1231 { 1243 {
1232 RPS_sampler_request_single_info_cancel(rhs->sampler_rh); 1244 RPS_sampler_request_single_info_cancel (rhs->sampler_rh);
1233 } 1245 }
1234 RPS_sampler_destroy(rhs->sampler); 1246 RPS_sampler_destroy (rhs->sampler);
1235 rhs->sampler = NULL; 1247 rhs->sampler = NULL;
1236 GNUNET_CONTAINER_DLL_remove(h->rhs_head, 1248 GNUNET_CONTAINER_DLL_remove (h->rhs_head,
1237 h->rhs_tail, 1249 h->rhs_tail,
1238 rhs); 1250 rhs);
1239 GNUNET_free(rhs); 1251 GNUNET_free (rhs);
1240} 1252}
1241 1253
1242 1254
@@ -1246,59 +1258,60 @@ GNUNET_RPS_request_single_info_cancel(
1246 * @param h the handle to the rps service 1258 * @param h the handle to the rps service
1247 */ 1259 */
1248void 1260void
1249GNUNET_RPS_disconnect(struct GNUNET_RPS_Handle *h) 1261GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h)
1250{ 1262{
1251 if (NULL != h->stream_requests_head) 1263 if (NULL != h->stream_requests_head)
1264 {
1265 struct GNUNET_RPS_StreamRequestHandle *srh_next;
1266
1267 LOG (GNUNET_ERROR_TYPE_WARNING,
1268 "Still waiting for replies\n");
1269 for (struct GNUNET_RPS_StreamRequestHandle *srh_iter =
1270 h->stream_requests_head;
1271 NULL != srh_iter;
1272 srh_iter = srh_next)
1252 { 1273 {
1253 struct GNUNET_RPS_StreamRequestHandle *srh_next; 1274 srh_next = srh_iter->next;
1254 1275 GNUNET_RPS_stream_cancel (srh_iter);
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 }
1264 } 1276 }
1277 }
1265 if (NULL != h->rh_head) 1278 if (NULL != h->rh_head)
1279 {
1280 LOG (GNUNET_ERROR_TYPE_WARNING,
1281 "Not all requests were cancelled!\n");
1282 for (struct GNUNET_RPS_Request_Handle *rh_iter = h->rh_head;
1283 h->rh_head != NULL;
1284 rh_iter = h->rh_head)
1266 { 1285 {
1267 LOG(GNUNET_ERROR_TYPE_WARNING, 1286 GNUNET_RPS_request_cancel (rh_iter);
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 }
1275 } 1287 }
1288 }
1276 if (NULL != h->rhs_head) 1289 if (NULL != h->rhs_head)
1290 {
1291 LOG (GNUNET_ERROR_TYPE_WARNING,
1292 "Not all requests were cancelled!\n");
1293 for (struct GNUNET_RPS_Request_Handle_Single_Info *rhs_iter = h->rhs_head;
1294 h->rhs_head != NULL;
1295 rhs_iter = h->rhs_head)
1277 { 1296 {
1278 LOG(GNUNET_ERROR_TYPE_WARNING, 1297 GNUNET_RPS_request_single_info_cancel (rhs_iter);
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 }
1286 } 1298 }
1299 }
1287 if (NULL != srh_callback_peers) 1300 if (NULL != srh_callback_peers)
1288 { 1301 {
1289 GNUNET_free(srh_callback_peers); 1302 GNUNET_free (srh_callback_peers);
1290 srh_callback_peers = NULL; 1303 srh_callback_peers = NULL;
1291 } 1304 }
1292 if (NULL != h->view_update_cb) 1305 if (NULL != h->view_update_cb)
1293 { 1306 {
1294 LOG(GNUNET_ERROR_TYPE_WARNING, 1307 LOG (GNUNET_ERROR_TYPE_WARNING,
1295 "Still waiting for view updates\n"); 1308 "Still waiting for view updates\n");
1296 GNUNET_RPS_view_request_cancel(h); 1309 GNUNET_RPS_view_request_cancel (h);
1297 } 1310 }
1298 if (NULL != h->nse) 1311 if (NULL != h->nse)
1299 GNUNET_NSE_disconnect(h->nse); 1312 GNUNET_NSE_disconnect (h->nse);
1300 GNUNET_MQ_destroy(h->mq); 1313 GNUNET_MQ_destroy (h->mq);
1301 GNUNET_free(h); 1314 GNUNET_free (h);
1302} 1315}
1303 1316
1304 1317
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c
index 6bbb4c6ac..3a01e73ff 100644
--- a/src/rps/test_rps.c
+++ b/src/rps/test_rps.c
@@ -49,7 +49,7 @@ static uint32_t timeout_s;
49/** 49/**
50 * How long do we run the test? 50 * How long do we run the test?
51 */ 51 */
52//#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 52// #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
53static struct GNUNET_TIME_Relative timeout; 53static struct GNUNET_TIME_Relative timeout;
54 54
55 55
@@ -71,7 +71,8 @@ static struct GNUNET_TESTBED_Peer **testbed_peers;
71/** 71/**
72 * @brief Indicates whether peer should go off- or online 72 * @brief Indicates whether peer should go off- or online
73 */ 73 */
74enum PEER_ONLINE_DELTA { 74enum PEER_ONLINE_DELTA
75{
75 /** 76 /**
76 * @brief Indicates peer going online 77 * @brief Indicates peer going online
77 */ 78 */
@@ -85,7 +86,8 @@ enum PEER_ONLINE_DELTA {
85/** 86/**
86 * Operation map entry 87 * Operation map entry
87 */ 88 */
88struct OpListEntry { 89struct OpListEntry
90{
89 /** 91 /**
90 * DLL next ptr 92 * DLL next ptr
91 */ 93 */
@@ -127,7 +129,8 @@ static struct OpListEntry *oplist_tail;
127/** 129/**
128 * A pending reply: A request was sent and the reply is pending. 130 * A pending reply: A request was sent and the reply is pending.
129 */ 131 */
130struct PendingReply { 132struct PendingReply
133{
131 /** 134 /**
132 * DLL next,prev ptr 135 * DLL next,prev ptr
133 */ 136 */
@@ -149,7 +152,8 @@ struct PendingReply {
149/** 152/**
150 * A pending request: A request was not made yet but is scheduled for later. 153 * A pending request: A request was not made yet but is scheduled for later.
151 */ 154 */
152struct PendingRequest { 155struct PendingRequest
156{
153 /** 157 /**
154 * DLL next,prev ptr 158 * DLL next,prev ptr
155 */ 159 */
@@ -171,7 +175,8 @@ struct PendingRequest {
171/** 175/**
172 * Information we track for each peer. 176 * Information we track for each peer.
173 */ 177 */
174struct RPSPeer { 178struct RPSPeer
179{
175 /** 180 /**
176 * Index of the peer. 181 * Index of the peer.
177 */ 182 */
@@ -200,7 +205,7 @@ struct RPSPeer {
200 /** 205 /**
201 * A request handle to check for an request 206 * A request handle to check for an request
202 */ 207 */
203 //struct GNUNET_RPS_Request_Handle *req_handle; 208 // struct GNUNET_RPS_Request_Handle *req_handle;
204 209
205 /** 210 /**
206 * Peer on- or offline? 211 * Peer on- or offline?
@@ -307,7 +312,8 @@ struct RPSPeer {
307 uint64_t num_recv_pull_rep; 312 uint64_t num_recv_pull_rep;
308}; 313};
309 314
310enum STAT_TYPE { 315enum STAT_TYPE
316{
311 STAT_TYPE_ROUNDS = 0x1, /* 1 */ 317 STAT_TYPE_ROUNDS = 0x1, /* 1 */
312 STAT_TYPE_BLOCKS = 0x2, /* 2 */ 318 STAT_TYPE_BLOCKS = 0x2, /* 2 */
313 STAT_TYPE_BLOCKS_MANY_PUSH = 0x4, /* 3 */ 319 STAT_TYPE_BLOCKS_MANY_PUSH = 0x4, /* 3 */
@@ -327,7 +333,8 @@ enum STAT_TYPE {
327 STAT_TYPE_MAX = 0x80000000, /* 32 */ 333 STAT_TYPE_MAX = 0x80000000, /* 32 */
328}; 334};
329 335
330struct STATcls { 336struct STATcls
337{
331 struct RPSPeer *rps_peer; 338 struct RPSPeer *rps_peer;
332 enum STAT_TYPE stat_type; 339 enum STAT_TYPE stat_type;
333}; 340};
@@ -432,7 +439,8 @@ typedef int (*EvaluationCallback) (void);
432/** 439/**
433 * @brief Do we have Churn? 440 * @brief Do we have Churn?
434 */ 441 */
435enum OPTION_CHURN { 442enum OPTION_CHURN
443{
436 /** 444 /**
437 * @brief If we have churn this is set 445 * @brief If we have churn this is set
438 */ 446 */
@@ -446,7 +454,8 @@ enum OPTION_CHURN {
446/** 454/**
447 * @brief Is it ok to quit the test before the timeout? 455 * @brief Is it ok to quit the test before the timeout?
448 */ 456 */
449enum OPTION_QUICK_QUIT { 457enum OPTION_QUICK_QUIT
458{
450 /** 459 /**
451 * @brief It is ok for the test to quit before the timeout triggers 460 * @brief It is ok for the test to quit before the timeout triggers
452 */ 461 */
@@ -461,7 +470,8 @@ enum OPTION_QUICK_QUIT {
461/** 470/**
462 * @brief Do we collect statistics at the end? 471 * @brief Do we collect statistics at the end?
463 */ 472 */
464enum OPTION_COLLECT_STATISTICS { 473enum OPTION_COLLECT_STATISTICS
474{
465 /** 475 /**
466 * @brief We collect statistics at the end 476 * @brief We collect statistics at the end
467 */ 477 */
@@ -476,7 +486,8 @@ enum OPTION_COLLECT_STATISTICS {
476/** 486/**
477 * @brief Do we collect views during run? 487 * @brief Do we collect views during run?
478 */ 488 */
479enum OPTION_COLLECT_VIEW { 489enum OPTION_COLLECT_VIEW
490{
480 /** 491 /**
481 * @brief We collect view during run 492 * @brief We collect view during run
482 */ 493 */
@@ -491,7 +502,8 @@ enum OPTION_COLLECT_VIEW {
491/** 502/**
492 * Structure to define a single test 503 * Structure to define a single test
493 */ 504 */
494struct SingleTestRun { 505struct SingleTestRun
506{
495 /** 507 /**
496 * Name of the test 508 * Name of the test
497 */ 509 */
@@ -578,7 +590,7 @@ static int in_shutdown;
578 * Append arguments to file 590 * Append arguments to file
579 */ 591 */
580static void 592static void
581tofile_(const char *file_name, const char *line) 593tofile_ (const char *file_name, const char *line)
582{ 594{
583 struct GNUNET_DISK_FileHandle *f; 595 struct GNUNET_DISK_FileHandle *f;
584 /* char output_buffer[512]; */ 596 /* char output_buffer[512]; */
@@ -586,20 +598,20 @@ tofile_(const char *file_name, const char *line)
586 /* int size; */ 598 /* int size; */
587 size_t size2; 599 size_t size2;
588 600
589 if (NULL == (f = GNUNET_DISK_file_open(file_name, 601 if (NULL == (f = GNUNET_DISK_file_open (file_name,
590 GNUNET_DISK_OPEN_APPEND | 602 GNUNET_DISK_OPEN_APPEND
591 GNUNET_DISK_OPEN_WRITE | 603 | GNUNET_DISK_OPEN_WRITE
592 GNUNET_DISK_OPEN_CREATE, 604 | GNUNET_DISK_OPEN_CREATE,
593 GNUNET_DISK_PERM_USER_READ | 605 GNUNET_DISK_PERM_USER_READ
594 GNUNET_DISK_PERM_USER_WRITE | 606 | GNUNET_DISK_PERM_USER_WRITE
595 GNUNET_DISK_PERM_GROUP_READ | 607 | GNUNET_DISK_PERM_GROUP_READ
596 GNUNET_DISK_PERM_OTHER_READ))) 608 | GNUNET_DISK_PERM_OTHER_READ)))
597 { 609 {
598 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 610 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
599 "Not able to open file %s\n", 611 "Not able to open file %s\n",
600 file_name); 612 file_name);
601 return; 613 return;
602 } 614 }
603 /* size = GNUNET_snprintf (output_buffer, 615 /* size = GNUNET_snprintf (output_buffer,
604 sizeof (output_buffer), 616 sizeof (output_buffer),
605 "%llu %s\n", 617 "%llu %s\n",
@@ -613,43 +625,43 @@ tofile_(const char *file_name, const char *line)
613 return; 625 return;
614 } */ 626 } */
615 627
616 size = strlen(line) * sizeof(char); 628 size = strlen (line) * sizeof(char);
617 629
618 size2 = GNUNET_DISK_file_write(f, line, size); 630 size2 = GNUNET_DISK_file_write (f, line, size);
619 if (size != size2) 631 if (size != size2)
632 {
633 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
634 "Unable to write to file! (Size: %lu, size2: %lu)\n",
635 size,
636 size2);
637 if (GNUNET_YES != GNUNET_DISK_file_close (f))
620 { 638 {
621 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 639 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
622 "Unable to write to file! (Size: %lu, size2: %lu)\n", 640 "Unable to close file\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;
631 } 641 }
642 return;
643 }
632 644
633 if (GNUNET_YES != GNUNET_DISK_file_close(f)) 645 if (GNUNET_YES != GNUNET_DISK_file_close (f))
634 { 646 {
635 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 647 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
636 "Unable to close file\n"); 648 "Unable to close file\n");
637 } 649 }
638} 650}
639 651
640/** 652/**
641 * This function is used to facilitate writing important information to disk 653 * This function is used to facilitate writing important information to disk
642 */ 654 */
643#define tofile(file_name, ...) do { \ 655#define tofile(file_name, ...) do { \
644 char tmp_buf[512]; \ 656 char tmp_buf[512]; \
645 int size; \ 657 int size; \
646 size = GNUNET_snprintf(tmp_buf, sizeof(tmp_buf), __VA_ARGS__); \ 658 size = GNUNET_snprintf (tmp_buf, sizeof(tmp_buf), __VA_ARGS__); \
647 if (0 > size) \ 659 if (0 > size) \
648 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \ 660 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \
649 "Failed to create tmp_buf\n"); \ 661 "Failed to create tmp_buf\n"); \
650 else \ 662 else \
651 tofile_ (file_name, tmp_buf); \ 663 tofile_ (file_name, tmp_buf); \
652 } while (0); 664} while (0);
653 665
654 666
655/** 667/**
@@ -676,14 +688,14 @@ tofile_(const char *file_name, const char *line)
676 * Task run on timeout to collect statistics and potentially shut down. 688 * Task run on timeout to collect statistics and potentially shut down.
677 */ 689 */
678static void 690static void
679post_test_op(void *cls); 691post_test_op (void *cls);
680 692
681 693
682/** 694/**
683 * Test the success of a single test 695 * Test the success of a single test
684 */ 696 */
685static int 697static int
686evaluate(void) 698evaluate (void)
687{ 699{
688 unsigned int i; 700 unsigned int i;
689 int tmp_ok; 701 int tmp_ok;
@@ -691,16 +703,16 @@ evaluate(void)
691 tmp_ok = 1; 703 tmp_ok = 1;
692 704
693 for (i = 0; i < num_peers; i++) 705 for (i = 0; i < num_peers; i++)
694 { 706 {
695 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 707 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
696 "%u. peer [%s] received %u of %u expected peer_ids: %i\n", 708 "%u. peer [%s] received %u of %u expected peer_ids: %i\n",
697 i, 709 i,
698 GNUNET_i2s(rps_peers[i].peer_id), 710 GNUNET_i2s (rps_peers[i].peer_id),
699 rps_peers[i].num_recv_ids, 711 rps_peers[i].num_recv_ids,
700 rps_peers[i].num_ids_to_request, 712 rps_peers[i].num_ids_to_request,
701 (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids)); 713 (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); 714 tmp_ok &= (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids);
703 } 715 }
704 return tmp_ok ? 0 : 1; 716 return tmp_ok ? 0 : 1;
705} 717}
706 718
@@ -709,12 +721,12 @@ evaluate(void)
709 * Creates an oplist entry and adds it to the oplist DLL 721 * Creates an oplist entry and adds it to the oplist DLL
710 */ 722 */
711static struct OpListEntry * 723static struct OpListEntry *
712make_oplist_entry() 724make_oplist_entry ()
713{ 725{
714 struct OpListEntry *entry; 726 struct OpListEntry *entry;
715 727
716 entry = GNUNET_new(struct OpListEntry); 728 entry = GNUNET_new (struct OpListEntry);
717 GNUNET_CONTAINER_DLL_insert_tail(oplist_head, oplist_tail, entry); 729 GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry);
718 return entry; 730 return entry;
719} 731}
720 732
@@ -728,15 +740,15 @@ make_oplist_entry()
728 * @return #GNUNET_YES if so 740 * @return #GNUNET_YES if so
729 * #GNUNET_NO otherwise 741 * #GNUNET_NO otherwise
730 */ 742 */
731static int check_statistics_collect_completed_single_peer( 743static int check_statistics_collect_completed_single_peer (
732 const struct RPSPeer *rps_peer) 744 const struct RPSPeer *rps_peer)
733{ 745{
734 if (cur_test_run.stat_collect_flags != 746 if (cur_test_run.stat_collect_flags !=
735 (cur_test_run.stat_collect_flags & 747 (cur_test_run.stat_collect_flags
736 rps_peer->stat_collected_flags)) 748 & rps_peer->stat_collected_flags))
737 { 749 {
738 return GNUNET_NO; 750 return GNUNET_NO;
739 } 751 }
740 return GNUNET_YES; 752 return GNUNET_YES;
741} 753}
742 754
@@ -748,22 +760,24 @@ static int check_statistics_collect_completed_single_peer(
748 * @return #GNUNET_YES if so 760 * @return #GNUNET_YES if so
749 * #GNUNET_NO otherwise 761 * #GNUNET_NO otherwise
750 */ 762 */
751static int check_statistics_collect_completed() 763static int check_statistics_collect_completed ()
752{ 764{
753 uint32_t i; 765 uint32_t i;
754 766
755 for (i = 0; i < num_peers; i++) 767 for (i = 0; i < num_peers; i++)
756 { 768 {
757 if (GNUNET_NO == check_statistics_collect_completed_single_peer(&rps_peers[i])) 769 if (GNUNET_NO == check_statistics_collect_completed_single_peer (
758 { 770 &rps_peers[i]))
759 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 771 {
760 "At least Peer %" PRIu32 " did not yet receive all statistics values\n", 772 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
761 i); 773 "At least Peer %" PRIu32
762 return GNUNET_NO; 774 " did not yet receive all statistics values\n",
763 } 775 i);
776 return GNUNET_NO;
764 } 777 }
765 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 778 }
766 "All peers received their statistics values\n"); 779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
780 "All peers received their statistics values\n");
767 return GNUNET_YES; 781 return GNUNET_YES;
768} 782}
769 783
@@ -772,36 +786,36 @@ static int check_statistics_collect_completed()
772 * Task run on timeout to shut everything down. 786 * Task run on timeout to shut everything down.
773 */ 787 */
774static void 788static void
775shutdown_op(void *cls) 789shutdown_op (void *cls)
776{ 790{
777 unsigned int i; 791 unsigned int i;
778 792
779 (void)cls; 793 (void) cls;
780 794
781 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 795 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
782 "Shutdown task scheduled, going down.\n"); 796 "Shutdown task scheduled, going down.\n");
783 in_shutdown = GNUNET_YES; 797 in_shutdown = GNUNET_YES;
784 if (NULL != post_test_task) 798 if (NULL != post_test_task)
785 { 799 {
786 GNUNET_SCHEDULER_cancel(post_test_task); 800 GNUNET_SCHEDULER_cancel (post_test_task);
787 post_test_op(NULL); 801 post_test_op (NULL);
788 } 802 }
789 if (NULL != churn_task) 803 if (NULL != churn_task)
804 {
805 GNUNET_SCHEDULER_cancel (churn_task);
806 churn_task = NULL;
807 }
808 for (i = 0; i < num_peers; i++)
809 {
810 if (NULL != rps_peers[i].rps_handle)
790 { 811 {
791 GNUNET_SCHEDULER_cancel(churn_task); 812 GNUNET_RPS_disconnect (rps_peers[i].rps_handle);
792 churn_task = NULL;
793 } 813 }
794 for (i = 0; i < num_peers; i++) 814 if (NULL != rps_peers[i].op)
795 { 815 {
796 if (NULL != rps_peers[i].rps_handle) 816 GNUNET_TESTBED_operation_done (rps_peers[i].op);
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 }
804 } 817 }
818 }
805} 819}
806 820
807 821
@@ -809,40 +823,41 @@ shutdown_op(void *cls)
809 * Task run on timeout to collect statistics and potentially shut down. 823 * Task run on timeout to collect statistics and potentially shut down.
810 */ 824 */
811static void 825static void
812post_test_op(void *cls) 826post_test_op (void *cls)
813{ 827{
814 unsigned int i; 828 unsigned int i;
815 829
816 (void)cls; 830 (void) cls;
817 831
818 post_test_task = NULL; 832 post_test_task = NULL;
819 post_test = GNUNET_YES; 833 post_test = GNUNET_YES;
820 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 834 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
821 "Post test task scheduled, going down.\n"); 835 "Post test task scheduled, going down.\n");
822 if (NULL != churn_task) 836 if (NULL != churn_task)
823 { 837 {
824 GNUNET_SCHEDULER_cancel(churn_task); 838 GNUNET_SCHEDULER_cancel (churn_task);
825 churn_task = NULL; 839 churn_task = NULL;
826 } 840 }
827 for (i = 0; i < num_peers; i++) 841 for (i = 0; i < num_peers; i++)
842 {
843 if (NULL != cur_test_run.post_test)
828 { 844 {
829 if (NULL != cur_test_run.post_test) 845 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n",
830 { 846 i);
831 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i); 847 cur_test_run.post_test (&rps_peers[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 }
839 } 848 }
840 /* If we do not collect statistics, shut down directly */ 849 if (NULL != rps_peers[i].op)
841 if (NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics ||
842 GNUNET_YES == check_statistics_collect_completed())
843 { 850 {
844 GNUNET_SCHEDULER_shutdown(); 851 GNUNET_TESTBED_operation_done (rps_peers[i].op);
852 rps_peers[i].op = NULL;
845 } 853 }
854 }
855 /* If we do not collect statistics, shut down directly */
856 if ((NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics)||
857 (GNUNET_YES == check_statistics_collect_completed ()) )
858 {
859 GNUNET_SCHEDULER_shutdown ();
860 }
846} 861}
847 862
848 863
@@ -850,29 +865,29 @@ post_test_op(void *cls)
850 * Seed peers. 865 * Seed peers.
851 */ 866 */
852static void 867static void
853seed_peers(void *cls) 868seed_peers (void *cls)
854{ 869{
855 struct RPSPeer *peer = cls; 870 struct RPSPeer *peer = cls;
856 unsigned int amount; 871 unsigned int amount;
857 unsigned int i; 872 unsigned int i;
858 873
859 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 874 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
860 { 875 {
861 return; 876 return;
862 } 877 }
863 878
864 GNUNET_assert(NULL != peer->rps_handle); 879 GNUNET_assert (NULL != peer->rps_handle);
865 880
866 // TODO if malicious don't seed mal peers 881 // TODO if malicious don't seed mal peers
867 amount = round(.5 * num_peers); 882 amount = round (.5 * num_peers);
868 883
869 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n"); 884 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n");
870 for (i = 0; i < amount; i++) 885 for (i = 0; i < amount; i++)
871 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n", 886 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n",
872 i, 887 i,
873 GNUNET_i2s(&rps_peer_ids[i])); 888 GNUNET_i2s (&rps_peer_ids[i]));
874 889
875 GNUNET_RPS_seed_ids(peer->rps_handle, amount, rps_peer_ids); 890 GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids);
876} 891}
877 892
878 893
@@ -880,7 +895,7 @@ seed_peers(void *cls)
880 * Seed peers. 895 * Seed peers.
881 */ 896 */
882static void 897static void
883seed_peers_big(void *cls) 898seed_peers_big (void *cls)
884{ 899{
885 struct RPSPeer *peer = cls; 900 struct RPSPeer *peer = cls;
886 unsigned int seed_msg_size; 901 unsigned int seed_msg_size;
@@ -889,73 +904,73 @@ seed_peers_big(void *cls)
889 unsigned int i; 904 unsigned int i;
890 905
891 seed_msg_size = 8; /* sizeof (struct GNUNET_RPS_CS_SeedMessage) */ 906 seed_msg_size = 8; /* sizeof (struct GNUNET_RPS_CS_SeedMessage) */
892 num_peers_max = (GNUNET_MAX_MESSAGE_SIZE - seed_msg_size) / 907 num_peers_max = (GNUNET_MAX_MESSAGE_SIZE - seed_msg_size)
893 sizeof(struct GNUNET_PeerIdentity); 908 / sizeof(struct GNUNET_PeerIdentity);
894 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 909 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
895 "Peers that fit in one seed msg; %u\n", 910 "Peers that fit in one seed msg; %u\n",
896 num_peers_max); 911 num_peers_max);
897 amount = num_peers_max + (0.5 * num_peers_max); 912 amount = num_peers_max + (0.5 * num_peers_max);
898 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 913 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
899 "Seeding many (%u) peers:\n", 914 "Seeding many (%u) peers:\n",
900 amount); 915 amount);
901 struct GNUNET_PeerIdentity ids_to_seed[amount]; 916 struct GNUNET_PeerIdentity ids_to_seed[amount];
902 for (i = 0; i < amount; i++) 917 for (i = 0; i < amount; i++)
903 { 918 {
904 ids_to_seed[i] = *peer->peer_id; 919 ids_to_seed[i] = *peer->peer_id;
905 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n", 920 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n",
906 i, 921 i,
907 GNUNET_i2s(&ids_to_seed[i])); 922 GNUNET_i2s (&ids_to_seed[i]));
908 } 923 }
909 924
910 GNUNET_RPS_seed_ids(peer->rps_handle, amount, ids_to_seed); 925 GNUNET_RPS_seed_ids (peer->rps_handle, amount, ids_to_seed);
911} 926}
912 927
913/** 928/**
914 * Get the id of peer i. 929 * Get the id of peer i.
915 */ 930 */
916void 931void
917info_cb(void *cb_cls, 932info_cb (void *cb_cls,
918 struct GNUNET_TESTBED_Operation *op, 933 struct GNUNET_TESTBED_Operation *op,
919 const struct GNUNET_TESTBED_PeerInformation *pinfo, 934 const struct GNUNET_TESTBED_PeerInformation *pinfo,
920 const char *emsg) 935 const char *emsg)
921{ 936{
922 struct OpListEntry *entry = (struct OpListEntry *)cb_cls; 937 struct OpListEntry *entry = (struct OpListEntry *) cb_cls;
923 938
924 (void)op; 939 (void) op;
925 940
926 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 941 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
927 { 942 {
928 return; 943 return;
929 } 944 }
930 945
931 if (NULL == pinfo || NULL != emsg) 946 if ((NULL == pinfo)||(NULL != emsg))
932 { 947 {
933 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg); 948 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg);
934 GNUNET_TESTBED_operation_done(entry->op); 949 GNUNET_TESTBED_operation_done (entry->op);
935 return; 950 return;
936 } 951 }
937 952
938 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 953 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
939 "Peer %u is %s\n", 954 "Peer %u is %s\n",
940 entry->index, 955 entry->index,
941 GNUNET_i2s(pinfo->result.id)); 956 GNUNET_i2s (pinfo->result.id));
942 957
943 rps_peer_ids[entry->index] = *(pinfo->result.id); 958 rps_peer_ids[entry->index] = *(pinfo->result.id);
944 rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index]; 959 rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index];
945 960
946 GNUNET_assert(GNUNET_OK == 961 GNUNET_assert (GNUNET_OK ==
947 GNUNET_CONTAINER_multipeermap_put(peer_map, 962 GNUNET_CONTAINER_multipeermap_put (peer_map,
948 &rps_peer_ids[entry->index], 963 &rps_peer_ids[entry->index],
949 &rps_peers[entry->index], 964 &rps_peers[entry->index],
950 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 965 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
951 tofile("/tmp/rps/peer_ids", 966 tofile ("/tmp/rps/peer_ids",
952 "%u\t%s\n", 967 "%u\t%s\n",
953 entry->index, 968 entry->index,
954 GNUNET_i2s_full(&rps_peer_ids[entry->index])); 969 GNUNET_i2s_full (&rps_peer_ids[entry->index]));
955 970
956 GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, entry); 971 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
957 GNUNET_TESTBED_operation_done(entry->op); 972 GNUNET_TESTBED_operation_done (entry->op);
958 GNUNET_free(entry); 973 GNUNET_free (entry);
959} 974}
960 975
961 976
@@ -969,39 +984,39 @@ info_cb(void *cb_cls,
969 * operation has executed successfully. 984 * operation has executed successfully.
970 */ 985 */
971static void 986static void
972rps_connect_complete_cb(void *cls, 987rps_connect_complete_cb (void *cls,
973 struct GNUNET_TESTBED_Operation *op, 988 struct GNUNET_TESTBED_Operation *op,
974 void *ca_result, 989 void *ca_result,
975 const char *emsg) 990 const char *emsg)
976{ 991{
977 struct RPSPeer *rps_peer = cls; 992 struct RPSPeer *rps_peer = cls;
978 struct GNUNET_RPS_Handle *rps = ca_result; 993 struct GNUNET_RPS_Handle *rps = ca_result;
979 994
980 GNUNET_assert(NULL != ca_result); 995 GNUNET_assert (NULL != ca_result);
981 996
982 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 997 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
983 { 998 {
984 return; 999 return;
985 } 1000 }
986 1001
987 rps_peer->rps_handle = rps; 1002 rps_peer->rps_handle = rps;
988 rps_peer->online = GNUNET_YES; 1003 rps_peer->online = GNUNET_YES;
989 num_peers_online++; 1004 num_peers_online++;
990 1005
991 GNUNET_assert(op == rps_peer->op); 1006 GNUNET_assert (op == rps_peer->op);
992 if (NULL != emsg) 1007 if (NULL != emsg)
993 { 1008 {
994 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1009 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
995 "Failed to connect to RPS service: %s\n", 1010 "Failed to connect to RPS service: %s\n",
996 emsg); 1011 emsg);
997 ok = 1; 1012 ok = 1;
998 GNUNET_SCHEDULER_shutdown(); 1013 GNUNET_SCHEDULER_shutdown ();
999 return; 1014 return;
1000 } 1015 }
1001 1016
1002 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n"); 1017 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n");
1003 1018
1004 cur_test_run.main_test(rps_peer); 1019 cur_test_run.main_test (rps_peer);
1005} 1020}
1006 1021
1007 1022
@@ -1016,17 +1031,17 @@ rps_connect_complete_cb(void *cls,
1016 * @return service handle to return in 'op_result', NULL on error 1031 * @return service handle to return in 'op_result', NULL on error
1017 */ 1032 */
1018static void * 1033static void *
1019rps_connect_adapter(void *cls, 1034rps_connect_adapter (void *cls,
1020 const struct GNUNET_CONFIGURATION_Handle *cfg) 1035 const struct GNUNET_CONFIGURATION_Handle *cfg)
1021{ 1036{
1022 struct GNUNET_RPS_Handle *h; 1037 struct GNUNET_RPS_Handle *h;
1023 1038
1024 h = GNUNET_RPS_connect(cfg); 1039 h = GNUNET_RPS_connect (cfg);
1025 GNUNET_assert(NULL != h); 1040 GNUNET_assert (NULL != h);
1026 1041
1027 if (NULL != cur_test_run.pre_test) 1042 if (NULL != cur_test_run.pre_test)
1028 cur_test_run.pre_test(cls, h); 1043 cur_test_run.pre_test (cls, h);
1029 GNUNET_assert(NULL != h); 1044 GNUNET_assert (NULL != h);
1030 1045
1031 return h; 1046 return h;
1032} 1047}
@@ -1041,12 +1056,12 @@ rps_connect_adapter(void *cls,
1041 * @return service handle to return in 'op_result', NULL on error 1056 * @return service handle to return in 'op_result', NULL on error
1042 */ 1057 */
1043static void * 1058static void *
1044stat_connect_adapter(void *cls, 1059stat_connect_adapter (void *cls,
1045 const struct GNUNET_CONFIGURATION_Handle *cfg) 1060 const struct GNUNET_CONFIGURATION_Handle *cfg)
1046{ 1061{
1047 struct RPSPeer *peer = cls; 1062 struct RPSPeer *peer = cls;
1048 1063
1049 peer->stats_h = GNUNET_STATISTICS_create("rps-profiler", cfg); 1064 peer->stats_h = GNUNET_STATISTICS_create ("rps-profiler", cfg);
1050 return peer->stats_h; 1065 return peer->stats_h;
1051} 1066}
1052 1067
@@ -1057,17 +1072,17 @@ stat_connect_adapter(void *cls,
1057 * @param op_result service handle returned from the connect adapter 1072 * @param op_result service handle returned from the connect adapter
1058 */ 1073 */
1059static void 1074static void
1060stat_disconnect_adapter(void *cls, void *op_result) 1075stat_disconnect_adapter (void *cls, void *op_result)
1061{ 1076{
1062 struct RPSPeer *peer = cls; 1077 struct RPSPeer *peer = cls;
1063 1078
1064 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel 1079 // GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
1065 // (peer->stats_h, "core", "# peers connected", 1080 // (peer->stats_h, "core", "# peers connected",
1066 // stat_iterator, peer)); 1081 // stat_iterator, peer));
1067 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel 1082 // GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
1068 // (peer->stats_h, "nse", "# peers connected", 1083 // (peer->stats_h, "nse", "# peers connected",
1069 // stat_iterator, peer)); 1084 // stat_iterator, peer));
1070 GNUNET_STATISTICS_destroy(op_result, GNUNET_NO); 1085 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
1071 peer->stats_h = NULL; 1086 peer->stats_h = NULL;
1072} 1087}
1073 1088
@@ -1082,24 +1097,24 @@ stat_disconnect_adapter(void *cls, void *op_result)
1082 * operation has executed successfully. 1097 * operation has executed successfully.
1083 */ 1098 */
1084static void 1099static void
1085stat_complete_cb(void *cls, struct GNUNET_TESTBED_Operation *op, 1100stat_complete_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
1086 void *ca_result, const char *emsg) 1101 void *ca_result, const char *emsg)
1087{ 1102{
1088 //struct GNUNET_STATISTICS_Handle *sh = ca_result; 1103 // struct GNUNET_STATISTICS_Handle *sh = ca_result;
1089 //struct RPSPeer *peer = (struct RPSPeer *) cls; 1104 // struct RPSPeer *peer = (struct RPSPeer *) cls;
1090 (void)cls; 1105 (void) cls;
1091 (void)op; 1106 (void) op;
1092 (void)ca_result; 1107 (void) ca_result;
1093 1108
1094 if (NULL != emsg) 1109 if (NULL != emsg)
1095 { 1110 {
1096 GNUNET_break(0); 1111 GNUNET_break (0);
1097 return; 1112 return;
1098 } 1113 }
1099 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch 1114 // GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
1100 // (sh, "core", "# peers connected", 1115 // (sh, "core", "# peers connected",
1101 // stat_iterator, peer)); 1116 // stat_iterator, peer));
1102 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch 1117 // GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
1103 // (sh, "nse", "# peers connected", 1118 // (sh, "nse", "# peers connected",
1104 // stat_iterator, peer)); 1119 // stat_iterator, peer));
1105} 1120}
@@ -1113,19 +1128,19 @@ stat_complete_cb(void *cls, struct GNUNET_TESTBED_Operation *op,
1113 * @param op_result service handle returned from the connect adapter 1128 * @param op_result service handle returned from the connect adapter
1114 */ 1129 */
1115static void 1130static void
1116rps_disconnect_adapter(void *cls, 1131rps_disconnect_adapter (void *cls,
1117 void *op_result) 1132 void *op_result)
1118{ 1133{
1119 struct RPSPeer *peer = cls; 1134 struct RPSPeer *peer = cls;
1120 struct GNUNET_RPS_Handle *h = op_result; 1135 struct GNUNET_RPS_Handle *h = op_result;
1121 1136
1122 if (NULL != peer->rps_srh) 1137 if (NULL != peer->rps_srh)
1123 { 1138 {
1124 GNUNET_RPS_stream_cancel(peer->rps_srh); 1139 GNUNET_RPS_stream_cancel (peer->rps_srh);
1125 peer->rps_srh = NULL; 1140 peer->rps_srh = NULL;
1126 } 1141 }
1127 GNUNET_assert(NULL != peer); 1142 GNUNET_assert (NULL != peer);
1128 GNUNET_RPS_disconnect(h); 1143 GNUNET_RPS_disconnect (h);
1129 peer->rps_handle = NULL; 1144 peer->rps_handle = NULL;
1130} 1145}
1131 1146
@@ -1136,13 +1151,13 @@ rps_disconnect_adapter(void *cls,
1136 1151
1137// TODO check whether tests can be stopped earlier 1152// TODO check whether tests can be stopped earlier
1138static int 1153static int
1139default_eval_cb(void) 1154default_eval_cb (void)
1140{ 1155{
1141 return evaluate(); 1156 return evaluate ();
1142} 1157}
1143 1158
1144static int 1159static int
1145no_eval(void) 1160no_eval (void)
1146{ 1161{
1147 return 0; 1162 return 0;
1148} 1163}
@@ -1150,7 +1165,7 @@ no_eval(void)
1150/** 1165/**
1151 * Initialise given RPSPeer 1166 * Initialise given RPSPeer
1152 */ 1167 */
1153static void default_init_peer(struct RPSPeer *rps_peer) 1168static void default_init_peer (struct RPSPeer *rps_peer)
1154{ 1169{
1155 rps_peer->num_ids_to_request = 1; 1170 rps_peer->num_ids_to_request = 1;
1156} 1171}
@@ -1163,122 +1178,122 @@ static void default_init_peer(struct RPSPeer *rps_peer)
1163 * @param recv_peers the received peers 1178 * @param recv_peers the received peers
1164 */ 1179 */
1165static void 1180static void
1166default_reply_handle(void *cls, 1181default_reply_handle (void *cls,
1167 uint64_t n, 1182 uint64_t n,
1168 const struct GNUNET_PeerIdentity *recv_peers) 1183 const struct GNUNET_PeerIdentity *recv_peers)
1169{ 1184{
1170 struct RPSPeer *rps_peer; 1185 struct RPSPeer *rps_peer;
1171 struct PendingReply *pending_rep = (struct PendingReply *)cls; 1186 struct PendingReply *pending_rep = (struct PendingReply *) cls;
1172 unsigned int i; 1187 unsigned int i;
1173 1188
1174 rps_peer = pending_rep->rps_peer; 1189 rps_peer = pending_rep->rps_peer;
1175 GNUNET_CONTAINER_DLL_remove(rps_peer->pending_rep_head, 1190 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head,
1176 rps_peer->pending_rep_tail, 1191 rps_peer->pending_rep_tail,
1177 pending_rep); 1192 pending_rep);
1178 rps_peer->num_pending_reps--; 1193 rps_peer->num_pending_reps--;
1179 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1180 "[%s] got %" PRIu64 " peers:\n", 1195 "[%s] got %" PRIu64 " peers:\n",
1181 GNUNET_i2s(rps_peer->peer_id), 1196 GNUNET_i2s (rps_peer->peer_id),
1182 n); 1197 n);
1183 1198
1184 for (i = 0; i < n; i++) 1199 for (i = 0; i < n; i++)
1185 { 1200 {
1186 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1187 "%u: %s\n", 1202 "%u: %s\n",
1188 i, 1203 i,
1189 GNUNET_i2s(&recv_peers[i])); 1204 GNUNET_i2s (&recv_peers[i]));
1190 1205
1191 rps_peer->num_recv_ids++; 1206 rps_peer->num_recv_ids++;
1192 } 1207 }
1193 1208
1194 if (0 == evaluate() && HAVE_QUICK_QUIT == cur_test_run.have_quick_quit) 1209 if ((0 == evaluate ())&&(HAVE_QUICK_QUIT == cur_test_run.have_quick_quit))
1195 { 1210 {
1196 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test succeeded before timeout\n"); 1211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test succeeded before timeout\n");
1197 GNUNET_assert(NULL != post_test_task); 1212 GNUNET_assert (NULL != post_test_task);
1198 GNUNET_SCHEDULER_cancel(post_test_task); 1213 GNUNET_SCHEDULER_cancel (post_test_task);
1199 post_test_task = GNUNET_SCHEDULER_add_now(&post_test_op, NULL); 1214 post_test_task = GNUNET_SCHEDULER_add_now (&post_test_op, NULL);
1200 GNUNET_assert(NULL != post_test_task); 1215 GNUNET_assert (NULL != post_test_task);
1201 } 1216 }
1202} 1217}
1203 1218
1204/** 1219/**
1205 * Request random peers. 1220 * Request random peers.
1206 */ 1221 */
1207static void 1222static void
1208request_peers(void *cls) 1223request_peers (void *cls)
1209{ 1224{
1210 struct PendingRequest *pending_req = cls; 1225 struct PendingRequest *pending_req = cls;
1211 struct RPSPeer *rps_peer; 1226 struct RPSPeer *rps_peer;
1212 struct PendingReply *pending_rep; 1227 struct PendingReply *pending_rep;
1213 1228
1214 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1229 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
1215 return; 1230 return;
1216 rps_peer = pending_req->rps_peer; 1231 rps_peer = pending_req->rps_peer;
1217 GNUNET_assert(1 <= rps_peer->num_pending_reqs); 1232 GNUNET_assert (1 <= rps_peer->num_pending_reqs);
1218 GNUNET_CONTAINER_DLL_remove(rps_peer->pending_req_head, 1233 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head,
1219 rps_peer->pending_req_tail, 1234 rps_peer->pending_req_tail,
1220 pending_req); 1235 pending_req);
1221 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1222 "Requesting one peer\n"); 1237 "Requesting one peer\n");
1223 pending_rep = GNUNET_new(struct PendingReply); 1238 pending_rep = GNUNET_new (struct PendingReply);
1224 pending_rep->rps_peer = rps_peer; 1239 pending_rep->rps_peer = rps_peer;
1225 pending_rep->req_handle = GNUNET_RPS_request_peers(rps_peer->rps_handle, 1240 pending_rep->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle,
1226 1, 1241 1,
1227 cur_test_run.reply_handle, 1242 cur_test_run.reply_handle,
1228 pending_rep); 1243 pending_rep);
1229 GNUNET_CONTAINER_DLL_insert_tail(rps_peer->pending_rep_head, 1244 GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_rep_head,
1230 rps_peer->pending_rep_tail, 1245 rps_peer->pending_rep_tail,
1231 pending_rep); 1246 pending_rep);
1232 rps_peer->num_pending_reps++; 1247 rps_peer->num_pending_reps++;
1233 rps_peer->num_pending_reqs--; 1248 rps_peer->num_pending_reqs--;
1234} 1249}
1235 1250
1236static void 1251static void
1237cancel_pending_req(struct PendingRequest *pending_req) 1252cancel_pending_req (struct PendingRequest *pending_req)
1238{ 1253{
1239 struct RPSPeer *rps_peer; 1254 struct RPSPeer *rps_peer;
1240 1255
1241 rps_peer = pending_req->rps_peer; 1256 rps_peer = pending_req->rps_peer;
1242 GNUNET_CONTAINER_DLL_remove(rps_peer->pending_req_head, 1257 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head,
1243 rps_peer->pending_req_tail, 1258 rps_peer->pending_req_tail,
1244 pending_req); 1259 pending_req);
1245 rps_peer->num_pending_reqs--; 1260 rps_peer->num_pending_reqs--;
1246 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1247 "Cancelling pending request\n"); 1262 "Cancelling pending request\n");
1248 GNUNET_SCHEDULER_cancel(pending_req->request_task); 1263 GNUNET_SCHEDULER_cancel (pending_req->request_task);
1249 GNUNET_free(pending_req); 1264 GNUNET_free (pending_req);
1250} 1265}
1251 1266
1252static void 1267static void
1253cancel_request(struct PendingReply *pending_rep) 1268cancel_request (struct PendingReply *pending_rep)
1254{ 1269{
1255 struct RPSPeer *rps_peer; 1270 struct RPSPeer *rps_peer;
1256 1271
1257 rps_peer = pending_rep->rps_peer; 1272 rps_peer = pending_rep->rps_peer;
1258 GNUNET_CONTAINER_DLL_remove(rps_peer->pending_rep_head, 1273 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head,
1259 rps_peer->pending_rep_tail, 1274 rps_peer->pending_rep_tail,
1260 pending_rep); 1275 pending_rep);
1261 rps_peer->num_pending_reps--; 1276 rps_peer->num_pending_reps--;
1262 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1263 "Cancelling request\n"); 1278 "Cancelling request\n");
1264 GNUNET_RPS_request_cancel(pending_rep->req_handle); 1279 GNUNET_RPS_request_cancel (pending_rep->req_handle);
1265 GNUNET_free(pending_rep); 1280 GNUNET_free (pending_rep);
1266} 1281}
1267 1282
1268/** 1283/**
1269 * Cancel a request. 1284 * Cancel a request.
1270 */ 1285 */
1271static void 1286static void
1272cancel_request_cb(void *cls) 1287cancel_request_cb (void *cls)
1273{ 1288{
1274 struct RPSPeer *rps_peer = cls; 1289 struct RPSPeer *rps_peer = cls;
1275 struct PendingReply *pending_rep; 1290 struct PendingReply *pending_rep;
1276 1291
1277 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1292 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
1278 return; 1293 return;
1279 pending_rep = rps_peer->pending_rep_head; 1294 pending_rep = rps_peer->pending_rep_head;
1280 GNUNET_assert(1 <= rps_peer->num_pending_reps); 1295 GNUNET_assert (1 <= rps_peer->num_pending_reps);
1281 cancel_request(pending_rep); 1296 cancel_request (pending_rep);
1282} 1297}
1283 1298
1284 1299
@@ -1287,45 +1302,45 @@ cancel_request_cb(void *cls)
1287 * issued, nor replied 1302 * issued, nor replied
1288 */ 1303 */
1289void 1304void
1290schedule_missing_requests(struct RPSPeer *rps_peer) 1305schedule_missing_requests (struct RPSPeer *rps_peer)
1291{ 1306{
1292 unsigned int i; 1307 unsigned int i;
1293 struct PendingRequest *pending_req; 1308 struct PendingRequest *pending_req;
1294 1309
1295 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1310 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1296 "Scheduling %u - %u missing requests\n", 1311 "Scheduling %u - %u missing requests\n",
1297 rps_peer->num_ids_to_request, 1312 rps_peer->num_ids_to_request,
1298 rps_peer->num_pending_reqs + rps_peer->num_pending_reps); 1313 rps_peer->num_pending_reqs + rps_peer->num_pending_reps);
1299 GNUNET_assert(rps_peer->num_pending_reqs + rps_peer->num_pending_reps <= 1314 GNUNET_assert (rps_peer->num_pending_reqs + rps_peer->num_pending_reps <=
1300 rps_peer->num_ids_to_request); 1315 rps_peer->num_ids_to_request);
1301 for (i = rps_peer->num_pending_reqs + rps_peer->num_pending_reps; 1316 for (i = rps_peer->num_pending_reqs + rps_peer->num_pending_reps;
1302 i < rps_peer->num_ids_to_request; i++) 1317 i < rps_peer->num_ids_to_request; i++)
1303 { 1318 {
1304 pending_req = GNUNET_new(struct PendingRequest); 1319 pending_req = GNUNET_new (struct PendingRequest);
1305 pending_req->rps_peer = rps_peer; 1320 pending_req->rps_peer = rps_peer;
1306 pending_req->request_task = GNUNET_SCHEDULER_add_delayed( 1321 pending_req->request_task = GNUNET_SCHEDULER_add_delayed (
1307 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1322 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
1308 cur_test_run.request_interval * i), 1323 cur_test_run.request_interval * i),
1309 request_peers, 1324 request_peers,
1310 pending_req); 1325 pending_req);
1311 GNUNET_CONTAINER_DLL_insert_tail(rps_peer->pending_req_head, 1326 GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_req_head,
1312 rps_peer->pending_req_tail, 1327 rps_peer->pending_req_tail,
1313 pending_req); 1328 pending_req);
1314 rps_peer->num_pending_reqs++; 1329 rps_peer->num_pending_reqs++;
1315 } 1330 }
1316} 1331}
1317 1332
1318void 1333void
1319cancel_pending_req_rep(struct RPSPeer *rps_peer) 1334cancel_pending_req_rep (struct RPSPeer *rps_peer)
1320{ 1335{
1321 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1322 "Cancelling all (pending) requests.\n"); 1337 "Cancelling all (pending) requests.\n");
1323 while (NULL != rps_peer->pending_req_head) 1338 while (NULL != rps_peer->pending_req_head)
1324 cancel_pending_req(rps_peer->pending_req_head); 1339 cancel_pending_req (rps_peer->pending_req_head);
1325 GNUNET_assert(0 == rps_peer->num_pending_reqs); 1340 GNUNET_assert (0 == rps_peer->num_pending_reqs);
1326 while (NULL != rps_peer->pending_rep_head) 1341 while (NULL != rps_peer->pending_rep_head)
1327 cancel_request(rps_peer->pending_rep_head); 1342 cancel_request (rps_peer->pending_rep_head);
1328 GNUNET_assert(0 == rps_peer->num_pending_reps); 1343 GNUNET_assert (0 == rps_peer->num_pending_reps);
1329} 1344}
1330 1345
1331/*********************************** 1346/***********************************
@@ -1335,9 +1350,9 @@ cancel_pending_req_rep(struct RPSPeer *rps_peer)
1335/** 1350/**
1336 * Initialise only non-mal RPSPeers 1351 * Initialise only non-mal RPSPeers
1337 */ 1352 */
1338static void mal_init_peer(struct RPSPeer *rps_peer) 1353static void mal_init_peer (struct RPSPeer *rps_peer)
1339{ 1354{
1340 if (rps_peer->index >= round(portion * num_peers)) 1355 if (rps_peer->index >= round (portion * num_peers))
1341 rps_peer->num_ids_to_request = 1; 1356 rps_peer->num_ids_to_request = 1;
1342} 1357}
1343 1358
@@ -1351,51 +1366,53 @@ static void mal_init_peer(struct RPSPeer *rps_peer)
1351 * @param h the handle to the service 1366 * @param h the handle to the service
1352 */ 1367 */
1353static void 1368static void
1354mal_pre(struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) 1369mal_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
1355{ 1370{
1356 #if ENABLE_MALICIOUS 1371 #if ENABLE_MALICIOUS
1357 uint32_t num_mal_peers; 1372 uint32_t num_mal_peers;
1358 1373
1359 GNUNET_assert((1 >= portion) && 1374 GNUNET_assert ((1 >= portion) &&
1360 (0 < portion)); 1375 (0 < portion));
1361 num_mal_peers = round(portion * num_peers); 1376 num_mal_peers = round (portion * num_peers);
1362 1377
1363 if (rps_peer->index < num_mal_peers) 1378 if (rps_peer->index < num_mal_peers)
1364 { 1379 {
1365 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1380 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1366 "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n", 1381 "%u. peer [%s] of %" PRIu32
1367 rps_peer->index, 1382 " malicious peers turning malicious\n",
1368 GNUNET_i2s(rps_peer->peer_id), 1383 rps_peer->index,
1369 num_mal_peers); 1384 GNUNET_i2s (rps_peer->peer_id),
1370 1385 num_mal_peers);
1371 GNUNET_RPS_act_malicious(h, mal_type, num_mal_peers, 1386
1372 rps_peer_ids, target_peer); 1387 GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers,
1373 } 1388 rps_peer_ids, target_peer);
1389 }
1374 #endif /* ENABLE_MALICIOUS */ 1390 #endif /* ENABLE_MALICIOUS */
1375} 1391}
1376 1392
1377static void 1393static void
1378mal_cb(struct RPSPeer *rps_peer) 1394mal_cb (struct RPSPeer *rps_peer)
1379{ 1395{
1380 uint32_t num_mal_peers; 1396 uint32_t num_mal_peers;
1381 1397
1382 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1398 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
1383 { 1399 {
1384 return; 1400 return;
1385 } 1401 }
1386 1402
1387 #if ENABLE_MALICIOUS 1403 #if ENABLE_MALICIOUS
1388 GNUNET_assert((1 >= portion) && 1404 GNUNET_assert ((1 >= portion) &&
1389 (0 < portion)); 1405 (0 < portion));
1390 num_mal_peers = round(portion * num_peers); 1406 num_mal_peers = round (portion * num_peers);
1391 1407
1392 if (rps_peer->index >= num_mal_peers) 1408 if (rps_peer->index >= num_mal_peers)
1393 { /* It's useless to ask a malicious peer about a random sample - 1409 { /* It's useless to ask a malicious peer about a random sample -
1394 it's not sampling */ 1410 it's not sampling */
1395 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), 1411 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
1396 seed_peers, rps_peer); 1412 GNUNET_TIME_UNIT_SECONDS, 2),
1397 schedule_missing_requests(rps_peer); 1413 seed_peers, rps_peer);
1398 } 1414 schedule_missing_requests (rps_peer);
1415 }
1399 #endif /* ENABLE_MALICIOUS */ 1416 #endif /* ENABLE_MALICIOUS */
1400} 1417}
1401 1418
@@ -1404,43 +1421,43 @@ mal_cb(struct RPSPeer *rps_peer)
1404* SINGLE_REQUEST 1421* SINGLE_REQUEST
1405***********************************/ 1422***********************************/
1406static void 1423static void
1407single_req_cb(struct RPSPeer *rps_peer) 1424single_req_cb (struct RPSPeer *rps_peer)
1408{ 1425{
1409 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1426 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
1410 { 1427 {
1411 return; 1428 return;
1412 } 1429 }
1413 1430
1414 schedule_missing_requests(rps_peer); 1431 schedule_missing_requests (rps_peer);
1415} 1432}
1416 1433
1417/*********************************** 1434/***********************************
1418* DELAYED_REQUESTS 1435* DELAYED_REQUESTS
1419***********************************/ 1436***********************************/
1420static void 1437static void
1421delay_req_cb(struct RPSPeer *rps_peer) 1438delay_req_cb (struct RPSPeer *rps_peer)
1422{ 1439{
1423 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1440 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
1424 { 1441 {
1425 return; 1442 return;
1426 } 1443 }
1427 1444
1428 schedule_missing_requests(rps_peer); 1445 schedule_missing_requests (rps_peer);
1429} 1446}
1430 1447
1431/*********************************** 1448/***********************************
1432* SEED 1449* SEED
1433***********************************/ 1450***********************************/
1434static void 1451static void
1435seed_cb(struct RPSPeer *rps_peer) 1452seed_cb (struct RPSPeer *rps_peer)
1436{ 1453{
1437 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1454 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
1438 { 1455 {
1439 return; 1456 return;
1440 } 1457 }
1441 1458
1442 GNUNET_SCHEDULER_add_delayed( 1459 GNUNET_SCHEDULER_add_delayed (
1443 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), 1460 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
1444 seed_peers, rps_peer); 1461 seed_peers, rps_peer);
1445} 1462}
1446 1463
@@ -1448,16 +1465,16 @@ seed_cb(struct RPSPeer *rps_peer)
1448* SEED_BIG 1465* SEED_BIG
1449***********************************/ 1466***********************************/
1450static void 1467static void
1451seed_big_cb(struct RPSPeer *rps_peer) 1468seed_big_cb (struct RPSPeer *rps_peer)
1452{ 1469{
1453 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1470 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
1454 { 1471 {
1455 return; 1472 return;
1456 } 1473 }
1457 1474
1458 // TODO test seeding > GNUNET_MAX_MESSAGE_SIZE peers 1475 // TODO test seeding > GNUNET_MAX_MESSAGE_SIZE peers
1459 GNUNET_SCHEDULER_add_delayed( 1476 GNUNET_SCHEDULER_add_delayed (
1460 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), 1477 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
1461 seed_peers_big, rps_peer); 1478 seed_peers_big, rps_peer);
1462} 1479}
1463 1480
@@ -1465,9 +1482,9 @@ seed_big_cb(struct RPSPeer *rps_peer)
1465* SINGLE_PEER_SEED 1482* SINGLE_PEER_SEED
1466***********************************/ 1483***********************************/
1467static void 1484static void
1468single_peer_seed_cb(struct RPSPeer *rps_peer) 1485single_peer_seed_cb (struct RPSPeer *rps_peer)
1469{ 1486{
1470 (void)rps_peer; 1487 (void) rps_peer;
1471 // TODO 1488 // TODO
1472} 1489}
1473 1490
@@ -1475,36 +1492,36 @@ single_peer_seed_cb(struct RPSPeer *rps_peer)
1475* SEED_REQUEST 1492* SEED_REQUEST
1476***********************************/ 1493***********************************/
1477static void 1494static void
1478seed_req_cb(struct RPSPeer *rps_peer) 1495seed_req_cb (struct RPSPeer *rps_peer)
1479{ 1496{
1480 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1497 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
1481 { 1498 {
1482 return; 1499 return;
1483 } 1500 }
1484 1501
1485 GNUNET_SCHEDULER_add_delayed( 1502 GNUNET_SCHEDULER_add_delayed (
1486 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), 1503 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
1487 seed_peers, rps_peer); 1504 seed_peers, rps_peer);
1488 schedule_missing_requests(rps_peer); 1505 schedule_missing_requests (rps_peer);
1489} 1506}
1490 1507
1491//TODO start big mal 1508// TODO start big mal
1492 1509
1493/*********************************** 1510/***********************************
1494* REQUEST_CANCEL 1511* REQUEST_CANCEL
1495***********************************/ 1512***********************************/
1496static void 1513static void
1497req_cancel_cb(struct RPSPeer *rps_peer) 1514req_cancel_cb (struct RPSPeer *rps_peer)
1498{ 1515{
1499 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1516 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
1500 { 1517 {
1501 return; 1518 return;
1502 } 1519 }
1503 1520
1504 schedule_missing_requests(rps_peer); 1521 schedule_missing_requests (rps_peer);
1505 GNUNET_SCHEDULER_add_delayed( 1522 GNUNET_SCHEDULER_add_delayed (
1506 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1523 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
1507 (cur_test_run.request_interval + 1)), 1524 (cur_test_run.request_interval + 1)),
1508 cancel_request_cb, rps_peer); 1525 cancel_request_cb, rps_peer);
1509} 1526}
1510 1527
@@ -1513,7 +1530,7 @@ req_cancel_cb(struct RPSPeer *rps_peer)
1513***********************************/ 1530***********************************/
1514 1531
1515static void 1532static void
1516churn(void *cls); 1533churn (void *cls);
1517 1534
1518/** 1535/**
1519 * @brief Starts churn 1536 * @brief Starts churn
@@ -1527,30 +1544,30 @@ churn(void *cls);
1527 * @param rps_peer The peer it's called for 1544 * @param rps_peer The peer it's called for
1528 */ 1545 */
1529static void 1546static void
1530churn_test_cb(struct RPSPeer *rps_peer) 1547churn_test_cb (struct RPSPeer *rps_peer)
1531{ 1548{
1532 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1549 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
1533 { 1550 {
1534 return; 1551 return;
1535 } 1552 }
1536 1553
1537 /* Start churn */ 1554 /* Start churn */
1538 if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) 1555 if ((HAVE_CHURN == cur_test_run.have_churn)&&(NULL == churn_task))
1539 { 1556 {
1540 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1557 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1541 "Starting churn task\n"); 1558 "Starting churn task\n");
1542 churn_task = GNUNET_SCHEDULER_add_delayed( 1559 churn_task = GNUNET_SCHEDULER_add_delayed (
1543 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), 1560 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
1544 churn, 1561 churn,
1545 NULL); 1562 NULL);
1546 } 1563 }
1547 else 1564 else
1548 { 1565 {
1549 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1566 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1550 "Not starting churn task\n"); 1567 "Not starting churn task\n");
1551 } 1568 }
1552 1569
1553 schedule_missing_requests(rps_peer); 1570 schedule_missing_requests (rps_peer);
1554} 1571}
1555 1572
1556/*********************************** 1573/***********************************
@@ -1558,60 +1575,62 @@ churn_test_cb(struct RPSPeer *rps_peer)
1558***********************************/ 1575***********************************/
1559 1576
1560static void 1577static void
1561got_stream_peer_cb(void *cls, 1578got_stream_peer_cb (void *cls,
1562 uint64_t num_peers, 1579 uint64_t num_peers,
1563 const struct GNUNET_PeerIdentity *peers) 1580 const struct GNUNET_PeerIdentity *peers)
1564{ 1581{
1565 const struct RPSPeer *rps_peer = cls; 1582 const struct RPSPeer *rps_peer = cls;
1566 1583
1567 for (uint64_t i = 0; i < num_peers; i++) 1584 for (uint64_t i = 0; i < num_peers; i++)
1568 { 1585 {
1569 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1586 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1570 "Peer %" PRIu32 " received [%s] from stream.\n", 1587 "Peer %" PRIu32 " received [%s] from stream.\n",
1571 rps_peer->index, 1588 rps_peer->index,
1572 GNUNET_i2s(&peers[i])); 1589 GNUNET_i2s (&peers[i]));
1573 if (0 != rps_peer->index && 1590 if ((0 != rps_peer->index) &&
1574 0 == memcmp(&peers[i], 1591 (0 == memcmp (&peers[i],
1575 &rps_peers[0].peer_id, 1592 &rps_peers[0].peer_id,
1576 sizeof(struct GNUNET_PeerIdentity))) 1593 sizeof(struct GNUNET_PeerIdentity))))
1577 { 1594 {
1578 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Received a peer id outside sub\n"); 1595 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1579 ok = 1; 1596 "Received a peer id outside sub\n");
1580 } 1597 ok = 1;
1581 else if (0 == rps_peer->index && 1598 }
1582 0 != memcmp(&peers[i], 1599 else if ((0 == rps_peer->index) &&
1600 (0 != memcmp (&peers[i],
1583 &rps_peers[0].peer_id, 1601 &rps_peers[0].peer_id,
1584 sizeof(struct GNUNET_PeerIdentity))) 1602 sizeof(struct GNUNET_PeerIdentity))))
1585 { 1603 {
1586 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Received a peer id outside sub (lonely)\n"); 1604 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1587 ok = 1; 1605 "Received a peer id outside sub (lonely)\n");
1588 } 1606 ok = 1;
1589 } 1607 }
1608 }
1590} 1609}
1591 1610
1592 1611
1593static void 1612static void
1594sub_post(struct RPSPeer *rps_peer) 1613sub_post (struct RPSPeer *rps_peer)
1595{ 1614{
1596 if (0 != rps_peer->index) 1615 if (0 != rps_peer->index)
1597 GNUNET_RPS_sub_stop(rps_peer->rps_handle, "test"); 1616 GNUNET_RPS_sub_stop (rps_peer->rps_handle, "test");
1598 else 1617 else
1599 GNUNET_RPS_sub_stop(rps_peer->rps_handle, "lonely"); 1618 GNUNET_RPS_sub_stop (rps_peer->rps_handle, "lonely");
1600} 1619}
1601 1620
1602 1621
1603static void 1622static void
1604sub_pre(struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) 1623sub_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
1605{ 1624{
1606 (void)rps_peer; 1625 (void) rps_peer;
1607 1626
1608 if (0 != rps_peer->index) 1627 if (0 != rps_peer->index)
1609 GNUNET_RPS_sub_start(h, "test"); 1628 GNUNET_RPS_sub_start (h, "test");
1610 else 1629 else
1611 GNUNET_RPS_sub_start(h, "lonely"); /* have a group of one */ 1630 GNUNET_RPS_sub_start (h, "lonely"); /* have a group of one */
1612 rps_peer->rps_srh = GNUNET_RPS_stream_request(h, 1631 rps_peer->rps_srh = GNUNET_RPS_stream_request (h,
1613 &got_stream_peer_cb, 1632 &got_stream_peer_cb,
1614 rps_peer); 1633 rps_peer);
1615} 1634}
1616 1635
1617/*********************************** 1636/***********************************
@@ -1626,82 +1645,83 @@ sub_pre(struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
1626 * @param emsg NULL on success; otherwise an error description 1645 * @param emsg NULL on success; otherwise an error description
1627 */ 1646 */
1628static void 1647static void
1629churn_cb(void *cls, 1648churn_cb (void *cls,
1630 struct GNUNET_TESTBED_Operation *op, 1649 struct GNUNET_TESTBED_Operation *op,
1631 const char *emsg) 1650 const char *emsg)
1632{ 1651{
1633 (void)op; 1652 (void) op;
1634 // FIXME 1653 // FIXME
1635 struct OpListEntry *entry = cls; 1654 struct OpListEntry *entry = cls;
1636 1655
1637 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1656 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
1638 { 1657 {
1639 return; 1658 return;
1640 } 1659 }
1641 1660
1642 GNUNET_TESTBED_operation_done(entry->op); 1661 GNUNET_TESTBED_operation_done (entry->op);
1643 if (NULL != emsg) 1662 if (NULL != emsg)
1644 { 1663 {
1645 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n"); 1664 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1646 GNUNET_SCHEDULER_shutdown(); 1665 "Failed to start/stop RPS at a peer\n");
1647 return; 1666 GNUNET_SCHEDULER_shutdown ();
1648 } 1667 return;
1649 GNUNET_assert(0 != entry->delta); 1668 }
1669 GNUNET_assert (0 != entry->delta);
1650 1670
1651 num_peers_online += entry->delta; 1671 num_peers_online += entry->delta;
1652 1672
1653 if (PEER_GO_OFFLINE == entry->delta) 1673 if (PEER_GO_OFFLINE == entry->delta)
1654 { /* Peer hopefully just went offline */ 1674 { /* Peer hopefully just went offline */
1655 if (GNUNET_YES != rps_peers[entry->index].online) 1675 if (GNUNET_YES != rps_peers[entry->index].online)
1656 { 1676 {
1657 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1677 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1658 "peer %s was expected to go offline but is still marked as online\n", 1678 "peer %s was expected to go offline but is still marked as online\n",
1659 GNUNET_i2s(rps_peers[entry->index].peer_id)); 1679 GNUNET_i2s (rps_peers[entry->index].peer_id));
1660 GNUNET_break(0); 1680 GNUNET_break (0);
1661 }
1662 else
1663 {
1664 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1665 "peer %s probably went offline as expected\n",
1666 GNUNET_i2s(rps_peers[entry->index].peer_id));
1667 }
1668 rps_peers[entry->index].online = GNUNET_NO;
1669 } 1681 }
1682 else
1683 {
1684 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1685 "peer %s probably went offline as expected\n",
1686 GNUNET_i2s (rps_peers[entry->index].peer_id));
1687 }
1688 rps_peers[entry->index].online = GNUNET_NO;
1689 }
1670 1690
1671 else if (PEER_GO_ONLINE < entry->delta) 1691 else if (PEER_GO_ONLINE < entry->delta)
1672 { /* Peer hopefully just went online */ 1692 { /* Peer hopefully just went online */
1673 if (GNUNET_NO != rps_peers[entry->index].online) 1693 if (GNUNET_NO != rps_peers[entry->index].online)
1674 { 1694 {
1675 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1695 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1676 "peer %s was expected to go online but is still marked as offline\n", 1696 "peer %s was expected to go online but is still marked as offline\n",
1677 GNUNET_i2s(rps_peers[entry->index].peer_id)); 1697 GNUNET_i2s (rps_peers[entry->index].peer_id));
1678 GNUNET_break(0); 1698 GNUNET_break (0);
1679 } 1699 }
1680 else 1700 else
1681 { 1701 {
1682 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1702 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1683 "peer %s probably went online as expected\n", 1703 "peer %s probably went online as expected\n",
1684 GNUNET_i2s(rps_peers[entry->index].peer_id)); 1704 GNUNET_i2s (rps_peers[entry->index].peer_id));
1685 if (NULL != cur_test_run.pre_test) 1705 if (NULL != cur_test_run.pre_test)
1686 { 1706 {
1687 cur_test_run.pre_test(&rps_peers[entry->index], 1707 cur_test_run.pre_test (&rps_peers[entry->index],
1688 rps_peers[entry->index].rps_handle); 1708 rps_peers[entry->index].rps_handle);
1689 schedule_missing_requests(&rps_peers[entry->index]); 1709 schedule_missing_requests (&rps_peers[entry->index]);
1690 } 1710 }
1691 } 1711 }
1692 rps_peers[entry->index].online = GNUNET_YES; 1712 rps_peers[entry->index].online = GNUNET_YES;
1693 } 1713 }
1694 else 1714 else
1695 { 1715 {
1696 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1716 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1697 "Invalid value for delta: %i\n", entry->delta); 1717 "Invalid value for delta: %i\n", entry->delta);
1698 GNUNET_break(0); 1718 GNUNET_break (0);
1699 } 1719 }
1700 1720
1701 GNUNET_CONTAINER_DLL_remove(oplist_head, oplist_tail, entry); 1721 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
1702 rps_peers[entry->index].entry_op_manage = NULL; 1722 rps_peers[entry->index].entry_op_manage = NULL;
1703 GNUNET_free(entry); 1723 GNUNET_free (entry);
1704 //if (num_peers_in_round[current_round] == peers_running) 1724 // if (num_peers_in_round[current_round] == peers_running)
1705 // run_round (); 1725 // run_round ();
1706} 1726}
1707 1727
@@ -1714,54 +1734,55 @@ churn_cb(void *cls,
1714 * @param prob_go_on_off the probability of the action 1734 * @param prob_go_on_off the probability of the action
1715 */ 1735 */
1716static void 1736static void
1717manage_service_wrapper(unsigned int i, unsigned int j, 1737manage_service_wrapper (unsigned int i, unsigned int j,
1718 enum PEER_ONLINE_DELTA delta, 1738 enum PEER_ONLINE_DELTA delta,
1719 double prob_go_on_off) 1739 double prob_go_on_off)
1720{ 1740{
1721 struct OpListEntry *entry = NULL; 1741 struct OpListEntry *entry = NULL;
1722 uint32_t prob; 1742 uint32_t prob;
1723 1743
1724 /* make sure that management operation is not already scheduled */ 1744 /* make sure that management operation is not already scheduled */
1725 if (NULL != rps_peers[j].entry_op_manage) 1745 if (NULL != rps_peers[j].entry_op_manage)
1726 { 1746 {
1727 return; 1747 return;
1728 } 1748 }
1729 1749
1730 prob = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 1750 prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1731 UINT32_MAX); 1751 UINT32_MAX);
1732 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1752 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1733 "%u. selected peer (%u: %s) is %s.\n", 1753 "%u. selected peer (%u: %s) is %s.\n",
1734 i, 1754 i,
1735 j, 1755 j,
1736 GNUNET_i2s(rps_peers[j].peer_id), 1756 GNUNET_i2s (rps_peers[j].peer_id),
1737 (PEER_GO_ONLINE == delta) ? "online" : "offline"); 1757 (PEER_GO_ONLINE == delta) ? "online" : "offline");
1738 if (prob < prob_go_on_off * UINT32_MAX) 1758 if (prob < prob_go_on_off * UINT32_MAX)
1739 { 1759 {
1740 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1760 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1741 "%s goes %s\n", 1761 "%s goes %s\n",
1742 GNUNET_i2s(rps_peers[j].peer_id), 1762 GNUNET_i2s (rps_peers[j].peer_id),
1743 (PEER_GO_OFFLINE == delta) ? "offline" : "online"); 1763 (PEER_GO_OFFLINE == delta) ? "offline" : "online");
1744 1764
1745 if (PEER_GO_OFFLINE == delta) 1765 if (PEER_GO_OFFLINE == delta)
1746 cancel_pending_req_rep(&rps_peers[j]); 1766 cancel_pending_req_rep (&rps_peers[j]);
1747 entry = make_oplist_entry(); 1767 entry = make_oplist_entry ();
1748 entry->delta = delta; 1768 entry->delta = delta;
1749 entry->index = j; 1769 entry->index = j;
1750 entry->op = GNUNET_TESTBED_peer_manage_service(NULL, 1770 entry->op = GNUNET_TESTBED_peer_manage_service (NULL,
1751 testbed_peers[j], 1771 testbed_peers[j],
1752 "rps", 1772 "rps",
1753 &churn_cb, 1773 &churn_cb,
1754 entry, 1774 entry,
1755 (PEER_GO_OFFLINE == delta) ? 0 : 1); 1775 (PEER_GO_OFFLINE == delta) ?
1756 rps_peers[j].entry_op_manage = entry; 1776 0 : 1);
1757 } 1777 rps_peers[j].entry_op_manage = entry;
1778 }
1758} 1779}
1759 1780
1760 1781
1761static void 1782static void
1762churn(void *cls) 1783churn (void *cls)
1763{ 1784{
1764 (void)cls; 1785 (void) cls;
1765 unsigned int i; 1786 unsigned int i;
1766 unsigned int j; 1787 unsigned int j;
1767 double portion_online; 1788 double portion_online;
@@ -1770,59 +1791,59 @@ churn(void *cls)
1770 double portion_go_online; 1791 double portion_go_online;
1771 double portion_go_offline; 1792 double portion_go_offline;
1772 1793
1773 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1794 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
1774 { 1795 {
1775 return; 1796 return;
1776 } 1797 }
1777 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1798 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1778 "Churn function executing\n"); 1799 "Churn function executing\n");
1779 1800
1780 churn_task = NULL; /* Should be invalid by now */ 1801 churn_task = NULL; /* Should be invalid by now */
1781 1802
1782 /* Compute the probability for an online peer to go offline 1803 /* Compute the probability for an online peer to go offline
1783 * this round */ 1804 * this round */
1784 portion_online = num_peers_online * 1.0 / num_peers; 1805 portion_online = num_peers_online * 1.0 / num_peers;
1785 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1806 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1786 "Portion online: %f\n", 1807 "Portion online: %f\n",
1787 portion_online); 1808 portion_online);
1788 portion_go_online = ((1 - portion_online) * .5 * .66); 1809 portion_go_online = ((1 - portion_online) * .5 * .66);
1789 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1810 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1790 "Portion that should go online: %f\n", 1811 "Portion that should go online: %f\n",
1791 portion_go_online); 1812 portion_go_online);
1792 portion_go_offline = (portion_online + portion_go_online) - .75; 1813 portion_go_offline = (portion_online + portion_go_online) - .75;
1793 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1814 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1794 "Portion that probably goes offline: %f\n", 1815 "Portion that probably goes offline: %f\n",
1795 portion_go_offline); 1816 portion_go_offline);
1796 prob_go_offline = portion_go_offline / (portion_online * .5); 1817 prob_go_offline = portion_go_offline / (portion_online * .5);
1797 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1818 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1798 "Probability of a selected online peer to go offline: %f\n", 1819 "Probability of a selected online peer to go offline: %f\n",
1799 prob_go_offline); 1820 prob_go_offline);
1800 1821
1801 permut = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_WEAK, 1822 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK,
1802 (unsigned int)num_peers); 1823 (unsigned int) num_peers);
1803 1824
1804 /* Go over 50% randomly chosen peers */ 1825 /* Go over 50% randomly chosen peers */
1805 for (i = 0; i < .5 * num_peers; i++) 1826 for (i = 0; i < .5 * num_peers; i++)
1827 {
1828 j = permut[i];
1829
1830 /* If online, shut down with certain probability */
1831 if (GNUNET_YES == rps_peers[j].online)
1806 { 1832 {
1807 j = permut[i]; 1833 manage_service_wrapper (i, j, -1, prob_go_offline);
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 }
1820 } 1834 }
1821 1835
1822 GNUNET_free(permut); 1836 /* If offline, restart with certain probability */
1837 else if (GNUNET_NO == rps_peers[j].online)
1838 {
1839 manage_service_wrapper (i, j, 1, 0.66);
1840 }
1841 }
1842
1843 GNUNET_free (permut);
1823 1844
1824 churn_task = GNUNET_SCHEDULER_add_delayed( 1845 churn_task = GNUNET_SCHEDULER_add_delayed (
1825 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), 1846 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
1826 churn, 1847 churn,
1827 NULL); 1848 NULL);
1828} 1849}
@@ -1831,7 +1852,7 @@ churn(void *cls)
1831/** 1852/**
1832 * Initialise given RPSPeer 1853 * Initialise given RPSPeer
1833 */ 1854 */
1834static void profiler_init_peer(struct RPSPeer *rps_peer) 1855static void profiler_init_peer (struct RPSPeer *rps_peer)
1835{ 1856{
1836 if (num_peers - 1 == rps_peer->index) 1857 if (num_peers - 1 == rps_peer->index)
1837 rps_peer->num_ids_to_request = cur_test_run.num_requests; 1858 rps_peer->num_ids_to_request = cur_test_run.num_requests;
@@ -1846,72 +1867,72 @@ static void profiler_init_peer(struct RPSPeer *rps_peer)
1846 * @param recv_peers the received peers 1867 * @param recv_peers the received peers
1847 */ 1868 */
1848static void 1869static void
1849profiler_reply_handle(void *cls, 1870profiler_reply_handle (void *cls,
1850 uint64_t n, 1871 uint64_t n,
1851 const struct GNUNET_PeerIdentity *recv_peers) 1872 const struct GNUNET_PeerIdentity *recv_peers)
1852{ 1873{
1853 struct RPSPeer *rps_peer; 1874 struct RPSPeer *rps_peer;
1854 struct RPSPeer *rcv_rps_peer; 1875 struct RPSPeer *rcv_rps_peer;
1855 char *file_name; 1876 char *file_name;
1856 char *file_name_dh; 1877 char *file_name_dh;
1857 unsigned int i; 1878 unsigned int i;
1858 struct PendingReply *pending_rep = (struct PendingReply *)cls; 1879 struct PendingReply *pending_rep = (struct PendingReply *) cls;
1859 1880
1860 rps_peer = pending_rep->rps_peer; 1881 rps_peer = pending_rep->rps_peer;
1861 file_name = "/tmp/rps/received_ids"; 1882 file_name = "/tmp/rps/received_ids";
1862 file_name_dh = "/tmp/rps/diehard_input"; 1883 file_name_dh = "/tmp/rps/diehard_input";
1863 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1884 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1864 "[%s] got %" PRIu64 " peers:\n", 1885 "[%s] got %" PRIu64 " peers:\n",
1865 GNUNET_i2s(rps_peer->peer_id), 1886 GNUNET_i2s (rps_peer->peer_id),
1866 n); 1887 n);
1867 for (i = 0; i < n; i++) 1888 for (i = 0; i < n; i++)
1868 { 1889 {
1869 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1890 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1870 "%u: %s\n", 1891 "%u: %s\n",
1871 i, 1892 i,
1872 GNUNET_i2s(&recv_peers[i])); 1893 GNUNET_i2s (&recv_peers[i]));
1873 tofile(file_name, 1894 tofile (file_name,
1874 "%s\n", 1895 "%s\n",
1875 GNUNET_i2s_full(&recv_peers[i])); 1896 GNUNET_i2s_full (&recv_peers[i]));
1876 rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get(peer_map, &recv_peers[i]); 1897 rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get (peer_map, &recv_peers[i]);
1877 GNUNET_assert(NULL != rcv_rps_peer); 1898 GNUNET_assert (NULL != rcv_rps_peer);
1878 tofile(file_name_dh, 1899 tofile (file_name_dh,
1879 "%" PRIu32 "\n", 1900 "%" PRIu32 "\n",
1880 (uint32_t)rcv_rps_peer->index); 1901 (uint32_t) rcv_rps_peer->index);
1881 } 1902 }
1882 default_reply_handle(cls, n, recv_peers); 1903 default_reply_handle (cls, n, recv_peers);
1883} 1904}
1884 1905
1885 1906
1886static void 1907static void
1887profiler_cb(struct RPSPeer *rps_peer) 1908profiler_cb (struct RPSPeer *rps_peer)
1888{ 1909{
1889 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) 1910 if ((GNUNET_YES == in_shutdown)||(GNUNET_YES == post_test))
1890 { 1911 {
1891 return; 1912 return;
1892 } 1913 }
1893 1914
1894 /* Start churn */ 1915 /* Start churn */
1895 if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) 1916 if ((HAVE_CHURN == cur_test_run.have_churn)&&(NULL == churn_task))
1896 { 1917 {
1897 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1918 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1898 "Starting churn task\n"); 1919 "Starting churn task\n");
1899 churn_task = GNUNET_SCHEDULER_add_delayed( 1920 churn_task = GNUNET_SCHEDULER_add_delayed (
1900 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), 1921 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
1901 churn, 1922 churn,
1902 NULL); 1923 NULL);
1903 } 1924 }
1904 else 1925 else
1905 { 1926 {
1906 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1927 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1907 "Not starting churn task\n"); 1928 "Not starting churn task\n");
1908 } 1929 }
1909 1930
1910 /* Only request peer ids at one peer. 1931 /* Only request peer ids at one peer.
1911 * (It's the before-last because last one is target of the focussed attack.) 1932 * (It's the before-last because last one is target of the focussed attack.)
1912 */ 1933 */
1913 if (eval_peer == rps_peer) 1934 if (eval_peer == rps_peer)
1914 schedule_missing_requests(rps_peer); 1935 schedule_missing_requests (rps_peer);
1915} 1936}
1916 1937
1917/** 1938/**
@@ -1924,30 +1945,30 @@ profiler_cb(struct RPSPeer *rps_peer)
1924 * #GNUNET_SYSERR to abort iteration with error! 1945 * #GNUNET_SYSERR to abort iteration with error!
1925 */ 1946 */
1926int 1947int
1927file_name_cb(void *cls, const char *filename) 1948file_name_cb (void *cls, const char *filename)
1928{ 1949{
1929 (void)cls; 1950 (void) cls;
1930 1951
1931 if (NULL != strstr(filename, "sampler_el")) 1952 if (NULL != strstr (filename, "sampler_el"))
1953 {
1954 struct RPS_SamplerElement *s_elem;
1955 struct GNUNET_CRYPTO_AuthKey auth_key;
1956 const char *key_char;
1957 uint32_t i;
1958
1959 key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */
1960 tofile (filename, "--------------------------\n");
1961
1962 auth_key = string_to_auth_key (key_char);
1963 s_elem = RPS_sampler_elem_create ();
1964 RPS_sampler_elem_set (s_elem, auth_key);
1965
1966 for (i = 0; i < num_peers; i++)
1932 { 1967 {
1933 struct RPS_SamplerElement *s_elem; 1968 RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]);
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);
1950 } 1969 }
1970 RPS_sampler_elem_destroy (s_elem);
1971 }
1951 return GNUNET_OK; 1972 return GNUNET_OK;
1952} 1973}
1953 1974
@@ -1957,15 +1978,15 @@ file_name_cb(void *cls, const char *filename)
1957 * Compute all perfect samples. 1978 * Compute all perfect samples.
1958 */ 1979 */
1959int 1980int
1960profiler_eval(void) 1981profiler_eval (void)
1961{ 1982{
1962 /* Compute perfect sample for each sampler element */ 1983 /* Compute perfect sample for each sampler element */
1963 if (-1 == GNUNET_DISK_directory_scan("/tmp/rps/", file_name_cb, NULL)) 1984 if (-1 == GNUNET_DISK_directory_scan ("/tmp/rps/", file_name_cb, NULL))
1964 { 1985 {
1965 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n"); 1986 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n");
1966 } 1987 }
1967 1988
1968 return evaluate(); 1989 return evaluate ();
1969} 1990}
1970 1991
1971 1992
@@ -1977,40 +1998,40 @@ profiler_eval(void)
1977 * 1998 *
1978 * @return 1999 * @return
1979 */ 2000 */
1980static int is_in_view(uint32_t a, uint32_t b) 2001static int is_in_view (uint32_t a, uint32_t b)
1981{ 2002{
1982 uint32_t i; 2003 uint32_t i;
1983 2004
1984 for (i = 0; i < rps_peers[a].cur_view_count; i++) 2005 for (i = 0; i < rps_peers[a].cur_view_count; i++)
2006 {
2007 if (0 == memcmp (rps_peers[b].peer_id,
2008 &rps_peers[a].cur_view[i],
2009 sizeof(struct GNUNET_PeerIdentity)))
1985 { 2010 {
1986 if (0 == memcmp(rps_peers[b].peer_id, 2011 return GNUNET_YES;
1987 &rps_peers[a].cur_view[i],
1988 sizeof(struct GNUNET_PeerIdentity)))
1989 {
1990 return GNUNET_YES;
1991 }
1992 } 2012 }
2013 }
1993 return GNUNET_NO; 2014 return GNUNET_NO;
1994} 2015}
1995 2016
1996static uint32_t get_idx_of_pid(const struct GNUNET_PeerIdentity *pid) 2017static uint32_t get_idx_of_pid (const struct GNUNET_PeerIdentity *pid)
1997{ 2018{
1998 uint32_t i; 2019 uint32_t i;
1999 2020
2000 for (i = 0; i < num_peers; i++) 2021 for (i = 0; i < num_peers; i++)
2022 {
2023 if (0 == memcmp (pid,
2024 rps_peers[i].peer_id,
2025 sizeof(struct GNUNET_PeerIdentity)))
2001 { 2026 {
2002 if (0 == memcmp(pid, 2027 return i;
2003 rps_peers[i].peer_id,
2004 sizeof(struct GNUNET_PeerIdentity)))
2005 {
2006 return i;
2007 }
2008 } 2028 }
2009 //return 0; /* Should not happen - make compiler happy */ 2029 }
2010 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2030 // return 0; /* Should not happen - make compiler happy */
2011 "No known _PeerIdentity %s!\n", 2031 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2012 GNUNET_i2s_full(pid)); 2032 "No known _PeerIdentity %s!\n",
2013 GNUNET_assert(0); 2033 GNUNET_i2s_full (pid));
2034 GNUNET_assert (0);
2014} 2035}
2015 2036
2016/** 2037/**
@@ -2021,20 +2042,20 @@ static uint32_t get_idx_of_pid(const struct GNUNET_PeerIdentity *pid)
2021 * 2042 *
2022 * @return 2043 * @return
2023 */ 2044 */
2024static uint32_t count_containing_views(uint32_t a, uint32_t b) 2045static uint32_t count_containing_views (uint32_t a, uint32_t b)
2025{ 2046{
2026 uint32_t i; 2047 uint32_t i;
2027 uint32_t peer_idx; 2048 uint32_t peer_idx;
2028 uint32_t count = 0; 2049 uint32_t count = 0;
2029 2050
2030 for (i = 0; i < rps_peers[a].cur_view_count; i++) 2051 for (i = 0; i < rps_peers[a].cur_view_count; i++)
2052 {
2053 peer_idx = get_idx_of_pid (&rps_peers[a].cur_view[i]);
2054 if (GNUNET_YES == is_in_view (peer_idx, b))
2031 { 2055 {
2032 peer_idx = get_idx_of_pid(&rps_peers[a].cur_view[i]); 2056 count++;
2033 if (GNUNET_YES == is_in_view(peer_idx, b))
2034 {
2035 count++;
2036 }
2037 } 2057 }
2058 }
2038 return count; 2059 return count;
2039} 2060}
2040 2061
@@ -2044,12 +2065,12 @@ static uint32_t count_containing_views(uint32_t a, uint32_t b)
2044 * 2065 *
2045 * @param peer_idx index of the peer that is about to sample 2066 * @param peer_idx index of the peer that is about to sample
2046 */ 2067 */
2047static void compute_probabilities(uint32_t peer_idx) 2068static void compute_probabilities (uint32_t peer_idx)
2048{ 2069{
2049 //double probs[num_peers] = { 0 }; 2070 // double probs[num_peers] = { 0 };
2050 double probs[num_peers]; 2071 double probs[num_peers];
2051 size_t probs_as_str_size = (num_peers * 10 + 1) * sizeof(char); 2072 size_t probs_as_str_size = (num_peers * 10 + 1) * sizeof(char);
2052 char *probs_as_str = GNUNET_malloc(probs_as_str_size); 2073 char *probs_as_str = GNUNET_malloc (probs_as_str_size);
2053 char *probs_as_str_cpy; 2074 char *probs_as_str_cpy;
2054 uint32_t i; 2075 uint32_t i;
2055 double prob_push; 2076 double prob_push;
@@ -2060,119 +2081,120 @@ static void compute_probabilities(uint32_t peer_idx)
2060 int tmp; 2081 int tmp;
2061 uint32_t count_non_zero_prob = 0; 2082 uint32_t count_non_zero_prob = 0;
2062 2083
2063 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2084 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2064 "Computing probabilities for peer %" PRIu32 "\n", peer_idx); 2085 "Computing probabilities for peer %" PRIu32 "\n", peer_idx);
2065 /* Firstly without knowledge of old views */ 2086 /* Firstly without knowledge of old views */
2066 for (i = 0; i < num_peers; i++) 2087 for (i = 0; i < num_peers; i++)
2067 { 2088 {
2068 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2089 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2069 "\tfor peer %" PRIu32 ":\n", i); 2090 "\tfor peer %" PRIu32 ":\n", i);
2070 view_size = rps_peers[i].cur_view_count; 2091 view_size = rps_peers[i].cur_view_count;
2071 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2092 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2072 "\t\tview_size: %" PRIu32 "\n", view_size); 2093 "\t\tview_size: %" PRIu32 "\n", view_size);
2073 /* For peer i the probability of being sampled is 2094 /* For peer i the probability of being sampled is
2074 * evenly distributed among all possibly observed peers. */ 2095 * evenly distributed among all possibly observed peers. */
2075 /* We could have observed a peer in three cases: 2096 /* We could have observed a peer in three cases:
2076 * 1. peer sent a push 2097 * 1. peer sent a push
2077 * 2. peer was contained in a pull reply 2098 * 2. peer was contained in a pull reply
2078 * 3. peer was in history (sampler) - ignored for now */ 2099 * 3. peer was in history (sampler) - ignored for now */
2079 /* 1. Probability of having received a push from peer i */ 2100 /* 1. Probability of having received a push from peer i */
2080 if ((GNUNET_YES == is_in_view(i, peer_idx)) && 2101 if ((GNUNET_YES == is_in_view (i, peer_idx)) &&
2081 (1 <= (0.45 * view_size))) 2102 (1 <= (0.45 * view_size)))
2082 { 2103 {
2083 prob_push = 1.0 * binom(0.45 * view_size, 1) 2104 prob_push = 1.0 * binom (0.45 * view_size, 1)
2084 / 2105 /
2085 binom(view_size, 0.45 * view_size); 2106 binom (view_size, 0.45 * view_size);
2086 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2087 "\t\t%" PRIu32 " is in %" PRIu32 "'s view, prob: %f\n", 2108 "\t\t%" PRIu32 " is in %" PRIu32 "'s view, prob: %f\n",
2088 peer_idx, 2109 peer_idx,
2089 i, 2110 i,
2090 prob_push); 2111 prob_push);
2091 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2092 "\t\tposs choices from view: %" PRIu32 ", containing i: %" PRIu32 "\n", 2113 "\t\tposs choices from view: %" PRIu32 ", containing i: %"
2093 binom(view_size, 0.45 * view_size), 2114 PRIu32 "\n",
2094 binom(0.45 * view_size, 1)); 2115 binom (view_size, 0.45 * view_size),
2095 } 2116 binom (0.45 * view_size, 1));
2096 else 2117 }
2097 { 2118 else
2098 prob_push = 0; 2119 {
2099 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2120 prob_push = 0;
2100 "\t\t%" PRIu32 " is not in %" PRIu32 "'s view, prob: 0\n", 2121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2101 peer_idx, 2122 "\t\t%" PRIu32 " is not in %" PRIu32 "'s view, prob: 0\n",
2102 i); 2123 peer_idx,
2103 } 2124 i);
2104 /* 2. Probability of peer i being contained in pulls */ 2125 }
2105 view_size = rps_peers[peer_idx].cur_view_count; 2126 /* 2. Probability of peer i being contained in pulls */
2106 cont_views = count_containing_views(peer_idx, i); 2127 view_size = rps_peers[peer_idx].cur_view_count;
2107 number_of_being_in_pull_events = 2128 cont_views = count_containing_views (peer_idx, i);
2108 (binom(view_size, 0.45 * view_size) - 2129 number_of_being_in_pull_events =
2109 binom(view_size - cont_views, 0.45 * view_size)); 2130 (binom (view_size, 0.45 * view_size)
2110 if (0 != number_of_being_in_pull_events) 2131 - binom (view_size - cont_views, 0.45 * view_size));
2111 { 2132 if (0 != number_of_being_in_pull_events)
2112 prob_pull = number_of_being_in_pull_events 2133 {
2113 / 2134 prob_pull = number_of_being_in_pull_events
2114 (1.0 * binom(view_size, 0.45 * view_size)); 2135 /
2115 } 2136 (1.0 * binom (view_size, 0.45 * view_size));
2116 else 2137 }
2117 { 2138 else
2118 prob_pull = 0; 2139 {
2119 } 2140 prob_pull = 0;
2120 probs[i] = prob_push + prob_pull - (prob_push * prob_pull); 2141 }
2121 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2142 probs[i] = prob_push + prob_pull - (prob_push * prob_pull);
2122 "\t\t%" PRIu32 " has %" PRIu32 " of %" PRIu32 2143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2123 " peers in its view who know %" PRIu32 " prob: %f\n", 2144 "\t\t%" PRIu32 " has %" PRIu32 " of %" PRIu32
2124 peer_idx, 2145 " peers in its view who know %" PRIu32 " prob: %f\n",
2125 cont_views, 2146 peer_idx,
2126 view_size, 2147 cont_views,
2127 i, 2148 view_size,
2128 prob_pull); 2149 i,
2129 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2150 prob_pull);
2130 "\t\tnumber of possible pull combinations: %" PRIu32 "\n", 2151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2131 binom(view_size, 0.45 * view_size)); 2152 "\t\tnumber of possible pull combinations: %" PRIu32 "\n",
2132 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2153 binom (view_size, 0.45 * view_size));
2133 "\t\tnumber of possible pull combinations without %" PRIu32 2154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2134 ": %" PRIu32 "\n", 2155 "\t\tnumber of possible pull combinations without %" PRIu32
2135 i, 2156 ": %" PRIu32 "\n",
2136 binom(view_size - cont_views, 0.45 * view_size)); 2157 i,
2137 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2158 binom (view_size - cont_views, 0.45 * view_size));
2138 "\t\tnumber of possible pull combinations with %" PRIu32 2159 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2139 ": %" PRIu32 "\n", 2160 "\t\tnumber of possible pull combinations with %" PRIu32
2140 i, 2161 ": %" PRIu32 "\n",
2141 number_of_being_in_pull_events); 2162 i,
2142 2163 number_of_being_in_pull_events);
2143 if (0 != probs[i]) 2164
2144 count_non_zero_prob++; 2165 if (0 != probs[i])
2145 } 2166 count_non_zero_prob++;
2167 }
2146 /* normalize */ 2168 /* normalize */
2147 if (0 != count_non_zero_prob) 2169 if (0 != count_non_zero_prob)
2170 {
2171 for (i = 0; i < num_peers; i++)
2148 { 2172 {
2149 for (i = 0; i < num_peers; i++) 2173 probs[i] = probs[i] * (1.0 / count_non_zero_prob);
2150 {
2151 probs[i] = probs[i] * (1.0 / count_non_zero_prob);
2152 }
2153 } 2174 }
2175 }
2154 else 2176 else
2177 {
2178 for (i = 0; i < num_peers; i++)
2155 { 2179 {
2156 for (i = 0; i < num_peers; i++) 2180 probs[i] = 0;
2157 {
2158 probs[i] = 0;
2159 }
2160 } 2181 }
2182 }
2161 /* str repr */ 2183 /* str repr */
2162 for (i = 0; i < num_peers; i++) 2184 for (i = 0; i < num_peers; i++)
2163 { 2185 {
2164 probs_as_str_cpy = GNUNET_strndup(probs_as_str, probs_as_str_size); 2186 probs_as_str_cpy = GNUNET_strndup (probs_as_str, probs_as_str_size);
2165 tmp = GNUNET_snprintf(probs_as_str, 2187 tmp = GNUNET_snprintf (probs_as_str,
2166 probs_as_str_size, 2188 probs_as_str_size,
2167 "%s %7.6f", probs_as_str_cpy, probs[i]); 2189 "%s %7.6f", probs_as_str_cpy, probs[i]);
2168 GNUNET_free(probs_as_str_cpy); 2190 GNUNET_free (probs_as_str_cpy);
2169 GNUNET_assert(0 <= tmp); 2191 GNUNET_assert (0 <= tmp);
2170 } 2192 }
2171 2193
2172 to_file_w_len(rps_peers[peer_idx].file_name_probs, 2194 to_file_w_len (rps_peers[peer_idx].file_name_probs,
2173 probs_as_str_size, 2195 probs_as_str_size,
2174 probs_as_str); 2196 probs_as_str);
2175 GNUNET_free(probs_as_str); 2197 GNUNET_free (probs_as_str);
2176} 2198}
2177 2199
2178/** 2200/**
@@ -2184,212 +2206,214 @@ static void compute_probabilities(uint32_t peer_idx)
2184 * 2206 *
2185 * @return the number of occurrences 2207 * @return the number of occurrences
2186 */ 2208 */
2187static uint32_t count_peer_in_views_2(uint32_t peer_idx) 2209static uint32_t count_peer_in_views_2 (uint32_t peer_idx)
2188{ 2210{
2189 uint32_t i, j; 2211 uint32_t i, j;
2190 uint32_t count = 0; 2212 uint32_t count = 0;
2191 2213
2192 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 */
2193 { 2215 {
2194 for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */ 2216 for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */
2195 { 2217 {
2196 if (0 == memcmp(rps_peers[peer_idx].peer_id, 2218 if (0 == memcmp (rps_peers[peer_idx].peer_id,
2197 &rps_peers[i].cur_view[j], 2219 &rps_peers[i].cur_view[j],
2198 sizeof(struct GNUNET_PeerIdentity))) 2220 sizeof(struct GNUNET_PeerIdentity)))
2199 { 2221 {
2200 count++; 2222 count++;
2201 break; 2223 break;
2202 } 2224 }
2203 } 2225 }
2204 } 2226 }
2205 rps_peers[peer_idx].count_in_views = count; 2227 rps_peers[peer_idx].count_in_views = count;
2206 return count; 2228 return count;
2207} 2229}
2208 2230
2209static uint32_t cumulated_view_sizes() 2231static uint32_t cumulated_view_sizes ()
2210{ 2232{
2211 uint32_t i; 2233 uint32_t i;
2212 2234
2213 view_sizes = 0; 2235 view_sizes = 0;
2214 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ 2236 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */
2215 { 2237 {
2216 view_sizes += rps_peers[i].cur_view_count; 2238 view_sizes += rps_peers[i].cur_view_count;
2217 } 2239 }
2218 return view_sizes; 2240 return view_sizes;
2219} 2241}
2220 2242
2221static void count_peer_in_views(uint32_t *count_peers) 2243static void count_peer_in_views (uint32_t *count_peers)
2222{ 2244{
2223 uint32_t i, j; 2245 uint32_t i, j;
2224 2246
2225 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ 2247 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */
2248 {
2249 for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */
2226 { 2250 {
2227 for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */ 2251 if (0 == memcmp (rps_peers[i].peer_id,
2228 { 2252 &rps_peers[i].cur_view[j],
2229 if (0 == memcmp(rps_peers[i].peer_id, 2253 sizeof(struct GNUNET_PeerIdentity)))
2230 &rps_peers[i].cur_view[j], 2254 {
2231 sizeof(struct GNUNET_PeerIdentity))) 2255 count_peers[i]++;
2232 { 2256 }
2233 count_peers[i]++;
2234 }
2235 }
2236 } 2257 }
2258 }
2237} 2259}
2238 2260
2239void compute_diversity() 2261void compute_diversity ()
2240{ 2262{
2241 uint32_t i; 2263 uint32_t i;
2242 /* ith entry represents the numer of occurrences in other peer's views */ 2264 /* ith entry represents the numer of occurrences in other peer's views */
2243 uint32_t *count_peers = GNUNET_new_array(num_peers, uint32_t); 2265 uint32_t *count_peers = GNUNET_new_array (num_peers, uint32_t);
2244 uint32_t views_total_size; 2266 uint32_t views_total_size;
2245 double expected; 2267 double expected;
2246 /* deviation from expected number of peers */ 2268 /* deviation from expected number of peers */
2247 double *deviation = GNUNET_new_array(num_peers, double); 2269 double *deviation = GNUNET_new_array (num_peers, double);
2248 2270
2249 views_total_size = 0; 2271 views_total_size = 0;
2250 expected = 0; 2272 expected = 0;
2251 2273
2252 /* For each peer count its representation in other peer's views*/ 2274 /* For each peer count its representation in other peer's views*/
2253 for (i = 0; i < num_peers; i++) /* Peer to count */ 2275 for (i = 0; i < num_peers; i++) /* Peer to count */
2254 { 2276 {
2255 views_total_size += rps_peers[i].cur_view_count; 2277 views_total_size += rps_peers[i].cur_view_count;
2256 count_peer_in_views(count_peers); 2278 count_peer_in_views (count_peers);
2257 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2258 "Counted representation of %" PRIu32 "th peer [%s]: %" PRIu32 "\n", 2280 "Counted representation of %" PRIu32 "th peer [%s]: %" PRIu32
2259 i, 2281 "\n",
2260 GNUNET_i2s(rps_peers[i].peer_id), 2282 i,
2261 count_peers[i]); 2283 GNUNET_i2s (rps_peers[i].peer_id),
2262 } 2284 count_peers[i]);
2263 2285 }
2264 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2286
2265 "size of all views combined: %" PRIu32 "\n", 2287 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2266 views_total_size); 2288 "size of all views combined: %" PRIu32 "\n",
2267 expected = ((double)1 / num_peers) * views_total_size; 2289 views_total_size);
2268 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2290 expected = ((double) 1 / num_peers) * views_total_size;
2269 "Expected number of occurrences of each peer in all views: %f\n", 2291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2270 expected); 2292 "Expected number of occurrences of each peer in all views: %f\n",
2293 expected);
2271 for (i = 0; i < num_peers; i++) /* Peer to count */ 2294 for (i = 0; i < num_peers; i++) /* Peer to count */
2272 { 2295 {
2273 deviation[i] = expected - count_peers[i]; 2296 deviation[i] = expected - count_peers[i];
2274 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2275 "Deviation from expectation: %f\n", deviation[i]); 2298 "Deviation from expectation: %f\n", deviation[i]);
2276 } 2299 }
2277 GNUNET_free(count_peers); 2300 GNUNET_free (count_peers);
2278 GNUNET_free(deviation); 2301 GNUNET_free (deviation);
2279} 2302}
2280 2303
2281void print_view_sizes() 2304void print_view_sizes ()
2282{ 2305{
2283 uint32_t i; 2306 uint32_t i;
2284 2307
2285 for (i = 0; i < num_peers; i++) /* Peer to count */ 2308 for (i = 0; i < num_peers; i++) /* Peer to count */
2286 { 2309 {
2287 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2310 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2288 "View size of %" PRIu32 ". [%s] is %" PRIu32 "\n", 2311 "View size of %" PRIu32 ". [%s] is %" PRIu32 "\n",
2289 i, 2312 i,
2290 GNUNET_i2s(rps_peers[i].peer_id), 2313 GNUNET_i2s (rps_peers[i].peer_id),
2291 rps_peers[i].cur_view_count); 2314 rps_peers[i].cur_view_count);
2292 } 2315 }
2293} 2316}
2294 2317
2295void all_views_updated_cb() 2318void all_views_updated_cb ()
2296{ 2319{
2297 compute_diversity(); 2320 compute_diversity ();
2298 print_view_sizes(); 2321 print_view_sizes ();
2299} 2322}
2300 2323
2301void view_update_cb(void *cls, 2324void view_update_cb (void *cls,
2302 uint64_t view_size, 2325 uint64_t view_size,
2303 const struct GNUNET_PeerIdentity *peers) 2326 const struct GNUNET_PeerIdentity *peers)
2304{ 2327{
2305 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2306 "View was updated (%" PRIu64 ")\n", view_size); 2329 "View was updated (%" PRIu64 ")\n", view_size);
2307 struct RPSPeer *rps_peer = (struct RPSPeer *)cls; 2330 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
2308 to_file("/tmp/rps/view_sizes.txt", 2331 to_file ("/tmp/rps/view_sizes.txt",
2309 "%" PRIu64 " %" PRIu32 "", 2332 "%" PRIu64 " %" PRIu32 "",
2310 rps_peer->index, 2333 rps_peer->index,
2311 view_size); 2334 view_size);
2312 for (int i = 0; i < view_size; i++) 2335 for (int i = 0; i < view_size; i++)
2313 { 2336 {
2314 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2315 "\t%s\n", GNUNET_i2s(&peers[i])); 2338 "\t%s\n", GNUNET_i2s (&peers[i]));
2316 } 2339 }
2317 GNUNET_array_grow(rps_peer->cur_view, 2340 GNUNET_array_grow (rps_peer->cur_view,
2318 rps_peer->cur_view_count, 2341 rps_peer->cur_view_count,
2319 view_size); 2342 view_size);
2320 //*rps_peer->cur_view = *peers; 2343 // *rps_peer->cur_view = *peers;
2321 GNUNET_memcpy(rps_peer->cur_view, 2344 GNUNET_memcpy (rps_peer->cur_view,
2322 peers, 2345 peers,
2323 view_size * sizeof(struct GNUNET_PeerIdentity)); 2346 view_size * sizeof(struct GNUNET_PeerIdentity));
2324 to_file("/tmp/rps/count_in_views.txt", 2347 to_file ("/tmp/rps/count_in_views.txt",
2325 "%" PRIu64 " %" PRIu32 "", 2348 "%" PRIu64 " %" PRIu32 "",
2326 rps_peer->index, 2349 rps_peer->index,
2327 count_peer_in_views_2(rps_peer->index)); 2350 count_peer_in_views_2 (rps_peer->index));
2328 cumulated_view_sizes(); 2351 cumulated_view_sizes ();
2329 if (0 != view_size) 2352 if (0 != view_size)
2330 { 2353 {
2331 to_file("/tmp/rps/repr.txt", 2354 to_file ("/tmp/rps/repr.txt",
2332 "%" PRIu64 /* index */ 2355 "%" PRIu64 /* index */
2333 " %" PRIu32 /* occurrence in views */ 2356 " %" PRIu32 /* occurrence in views */
2334 " %" PRIu32 /* view sizes */ 2357 " %" PRIu32 /* view sizes */
2335 " %f" /* fraction of repr in views */ 2358 " %f" /* fraction of repr in views */
2336 " %f" /* average view size */ 2359 " %f" /* average view size */
2337 " %f" /* prob of occurrence in view slot */ 2360 " %f" /* prob of occurrence in view slot */
2338 " %f" "", /* exp frac of repr in views */ 2361 " %f" "", /* exp frac of repr in views */
2339 rps_peer->index, 2362 rps_peer->index,
2340 count_peer_in_views_2(rps_peer->index), 2363 count_peer_in_views_2 (rps_peer->index),
2341 view_sizes, 2364 view_sizes,
2342 count_peer_in_views_2(rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */ 2365 count_peer_in_views_2 (rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */
2343 view_sizes / (view_size * 1.0), /* average view size */ 2366 view_sizes / (view_size * 1.0), /* average view size */
2344 1.0 / view_size, /* prob of occurrence in view slot */ 2367 1.0 / view_size, /* prob of occurrence in view slot */
2345 (1.0 / view_size) * (view_sizes / view_size) /* expected fraction of repr in views */ 2368 (1.0 / view_size) * (view_sizes / view_size) /* expected fraction of repr in views */
2346 ); 2369 );
2347 } 2370 }
2348 compute_probabilities(rps_peer->index); 2371 compute_probabilities (rps_peer->index);
2349 all_views_updated_cb(); 2372 all_views_updated_cb ();
2350} 2373}
2351 2374
2352static void 2375static void
2353pre_profiler(struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) 2376pre_profiler (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
2354{ 2377{
2355 rps_peer->file_name_probs = 2378 rps_peer->file_name_probs =
2356 store_prefix_file_name(rps_peer->peer_id, "probs"); 2379 store_prefix_file_name (rps_peer->peer_id, "probs");
2357 GNUNET_RPS_view_request(h, 0, view_update_cb, rps_peer); 2380 GNUNET_RPS_view_request (h, 0, view_update_cb, rps_peer);
2358} 2381}
2359 2382
2360void write_final_stats(void) 2383void write_final_stats (void)
2361{ 2384{
2362 uint32_t i; 2385 uint32_t i;
2363 2386
2364 for (i = 0; i < num_peers; i++) 2387 for (i = 0; i < num_peers; i++)
2365 { 2388 {
2366 to_file("/tmp/rps/final_stats.dat", 2389 to_file ("/tmp/rps/final_stats.dat",
2367 "%" PRIu32 " " /* index */ 2390 "%" PRIu32 " " /* index */
2368 "%s %" /* id */ 2391 "%s %" /* id */
2369 PRIu64 " %" /* rounds */ 2392 PRIu64 " %" /* rounds */
2370 PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" /* blocking */ 2393 PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64
2371 PRIu64 " %" PRIu64 " %" PRIu64 " %" /* issued */ 2394 " %" /* blocking */
2372 PRIu64 " %" PRIu64 " %" PRIu64 " %" /* sent */ 2395 PRIu64 " %" PRIu64 " %" PRIu64 " %" /* issued */
2373 PRIu64 " %" PRIu64 " %" PRIu64 /* recv */, 2396 PRIu64 " %" PRIu64 " %" PRIu64 " %" /* sent */
2374 i, 2397 PRIu64 " %" PRIu64 " %" PRIu64 /* recv */,
2375 GNUNET_i2s(rps_peers[i].peer_id), 2398 i,
2376 rps_peers[i].num_rounds, 2399 GNUNET_i2s (rps_peers[i].peer_id),
2377 rps_peers[i].num_blocks, 2400 rps_peers[i].num_rounds,
2378 rps_peers[i].num_blocks_many_push, 2401 rps_peers[i].num_blocks,
2379 rps_peers[i].num_blocks_no_push, 2402 rps_peers[i].num_blocks_many_push,
2380 rps_peers[i].num_blocks_no_pull, 2403 rps_peers[i].num_blocks_no_push,
2381 rps_peers[i].num_blocks_many_push_no_pull, 2404 rps_peers[i].num_blocks_no_pull,
2382 rps_peers[i].num_blocks_no_push_no_pull, 2405 rps_peers[i].num_blocks_many_push_no_pull,
2383 rps_peers[i].num_issued_push, 2406 rps_peers[i].num_blocks_no_push_no_pull,
2384 rps_peers[i].num_issued_pull_req, 2407 rps_peers[i].num_issued_push,
2385 rps_peers[i].num_issued_pull_rep, 2408 rps_peers[i].num_issued_pull_req,
2386 rps_peers[i].num_sent_push, 2409 rps_peers[i].num_issued_pull_rep,
2387 rps_peers[i].num_sent_pull_req, 2410 rps_peers[i].num_sent_push,
2388 rps_peers[i].num_sent_pull_rep, 2411 rps_peers[i].num_sent_pull_req,
2389 rps_peers[i].num_recv_push, 2412 rps_peers[i].num_sent_pull_rep,
2390 rps_peers[i].num_recv_pull_req, 2413 rps_peers[i].num_recv_push,
2391 rps_peers[i].num_recv_pull_rep); 2414 rps_peers[i].num_recv_pull_req,
2392 } 2415 rps_peers[i].num_recv_pull_rep);
2416 }
2393} 2417}
2394 2418
2395/** 2419/**
@@ -2404,45 +2428,46 @@ void write_final_stats(void)
2404 * successfully obtained, #GNUNET_SYSERR if not. 2428 * successfully obtained, #GNUNET_SYSERR if not.
2405 */ 2429 */
2406void 2430void
2407post_test_shutdown_ready_cb(void *cls, 2431post_test_shutdown_ready_cb (void *cls,
2408 int success) 2432 int success)
2409{ 2433{
2410 struct STATcls *stat_cls = (struct STATcls *)cls; 2434 struct STATcls *stat_cls = (struct STATcls *) cls;
2411 struct RPSPeer *rps_peer = stat_cls->rps_peer; 2435 struct RPSPeer *rps_peer = stat_cls->rps_peer;
2412 2436
2413 if (GNUNET_OK == success) 2437 if (GNUNET_OK == success)
2414 { 2438 {
2415 /* set flag that we we got the value */ 2439 /* set flag that we we got the value */
2416 rps_peer->stat_collected_flags |= stat_cls->stat_type; 2440 rps_peer->stat_collected_flags |= stat_cls->stat_type;
2417 } 2441 }
2418 else 2442 else
2419 { 2443 {
2420 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2444 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2421 "Peer %u did not receive statistics value\n", 2445 "Peer %u did not receive statistics value\n",
2422 rps_peer->index); 2446 rps_peer->index);
2423 GNUNET_free(stat_cls); 2447 GNUNET_free (stat_cls);
2424 GNUNET_break(0); 2448 GNUNET_break (0);
2425 } 2449 }
2426 2450
2427 if (NULL != rps_peer->stat_op && 2451 if ((NULL != rps_peer->stat_op)&&
2428 GNUNET_YES == check_statistics_collect_completed_single_peer(rps_peer)) 2452 (GNUNET_YES == check_statistics_collect_completed_single_peer (
2429 { 2453 rps_peer)) )
2430 GNUNET_TESTBED_operation_done(rps_peer->stat_op); 2454 {
2431 } 2455 GNUNET_TESTBED_operation_done (rps_peer->stat_op);
2432 2456 }
2433 write_final_stats(); 2457
2434 if (GNUNET_YES == check_statistics_collect_completed()) 2458 write_final_stats ();
2435 { 2459 if (GNUNET_YES == check_statistics_collect_completed ())
2436 //write_final_stats (); 2460 {
2437 GNUNET_free(stat_cls); 2461 // write_final_stats ();
2438 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2462 GNUNET_free (stat_cls);
2439 "Shutting down\n"); 2463 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2440 GNUNET_SCHEDULER_shutdown(); 2464 "Shutting down\n");
2441 } 2465 GNUNET_SCHEDULER_shutdown ();
2466 }
2442 else 2467 else
2443 { 2468 {
2444 GNUNET_free(stat_cls); 2469 GNUNET_free (stat_cls);
2445 } 2470 }
2446} 2471}
2447 2472
2448/** 2473/**
@@ -2452,72 +2477,88 @@ post_test_shutdown_ready_cb(void *cls,
2452 * 2477 *
2453 * @return corresponding enum 2478 * @return corresponding enum
2454 */ 2479 */
2455enum STAT_TYPE stat_str_2_type(const char *stat_str) 2480enum STAT_TYPE stat_str_2_type (const char *stat_str)
2456{ 2481{
2457 if (0 == strncmp("# rounds blocked - no pull replies", stat_str, strlen("# rounds blocked - no pull replies"))) 2482 if (0 == strncmp ("# rounds blocked - no pull replies", stat_str, strlen (
2458 { 2483 "# rounds blocked - no pull replies")))
2459 return STAT_TYPE_BLOCKS_NO_PULL; 2484 {
2460 } 2485 return STAT_TYPE_BLOCKS_NO_PULL;
2461 else if (0 == strncmp("# rounds blocked - too many pushes, no pull replies", stat_str, strlen("# rounds blocked - too many pushes, no pull replies"))) 2486 }
2462 { 2487 else if (0 == strncmp ("# rounds blocked - too many pushes, no pull replies",
2463 return STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL; 2488 stat_str, strlen (
2464 } 2489 "# rounds blocked - too many pushes, no pull replies")))
2465 else if (0 == strncmp("# rounds blocked - too many pushes", stat_str, strlen("# rounds blocked - too many pushes"))) 2490 {
2466 { 2491 return STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL;
2467 return STAT_TYPE_BLOCKS_MANY_PUSH; 2492 }
2468 } 2493 else if (0 == strncmp ("# rounds blocked - too many pushes", stat_str,
2469 else if (0 == strncmp("# rounds blocked - no pushes, no pull replies", stat_str, strlen("# rounds blocked - no pushes, no pull replies"))) 2494 strlen ("# rounds blocked - too many pushes")))
2470 { 2495 {
2471 return STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL; 2496 return STAT_TYPE_BLOCKS_MANY_PUSH;
2472 } 2497 }
2473 else if (0 == strncmp("# rounds blocked - no pushes", stat_str, strlen("# rounds blocked - no pushes"))) 2498 else if (0 == strncmp ("# rounds blocked - no pushes, no pull replies",
2474 { 2499 stat_str, strlen (
2475 return STAT_TYPE_BLOCKS_NO_PUSH; 2500 "# rounds blocked - no pushes, no pull replies")))
2476 } 2501 {
2477 else if (0 == strncmp("# rounds blocked", stat_str, strlen("# rounds blocked"))) 2502 return STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL;
2478 { 2503 }
2479 return STAT_TYPE_BLOCKS; 2504 else if (0 == strncmp ("# rounds blocked - no pushes", stat_str, strlen (
2480 } 2505 "# rounds blocked - no pushes")))
2481 else if (0 == strncmp("# rounds", stat_str, strlen("# rounds"))) 2506 {
2482 { 2507 return STAT_TYPE_BLOCKS_NO_PUSH;
2483 return STAT_TYPE_ROUNDS; 2508 }
2484 } 2509 else if (0 == strncmp ("# rounds blocked", stat_str, strlen (
2485 else if (0 == strncmp("# push send issued", stat_str, strlen("# push send issued"))) 2510 "# rounds blocked")))
2486 { 2511 {
2487 return STAT_TYPE_ISSUED_PUSH_SEND; 2512 return STAT_TYPE_BLOCKS;
2488 } 2513 }
2489 else if (0 == strncmp("# pull request send issued", stat_str, strlen("# pull request send issued"))) 2514 else if (0 == strncmp ("# rounds", stat_str, strlen ("# rounds")))
2490 { 2515 {
2491 return STAT_TYPE_ISSUED_PULL_REQ; 2516 return STAT_TYPE_ROUNDS;
2492 } 2517 }
2493 else if (0 == strncmp("# pull reply send issued", stat_str, strlen("# pull reply send issued"))) 2518 else if (0 == strncmp ("# push send issued", stat_str, strlen (
2494 { 2519 "# push send issued")))
2495 return STAT_TYPE_ISSUED_PULL_REP; 2520 {
2496 } 2521 return STAT_TYPE_ISSUED_PUSH_SEND;
2497 else if (0 == strncmp("# pushes sent", stat_str, strlen("# pushes sent"))) 2522 }
2498 { 2523 else if (0 == strncmp ("# pull request send issued", stat_str, strlen (
2499 return STAT_TYPE_SENT_PUSH_SEND; 2524 "# pull request send issued")))
2500 } 2525 {
2501 else if (0 == strncmp("# pull requests sent", stat_str, strlen("# pull requests sent"))) 2526 return STAT_TYPE_ISSUED_PULL_REQ;
2502 { 2527 }
2503 return STAT_TYPE_SENT_PULL_REQ; 2528 else if (0 == strncmp ("# pull reply send issued", stat_str, strlen (
2504 } 2529 "# pull reply send issued")))
2505 else if (0 == strncmp("# pull replys sent", stat_str, strlen("# pull replys sent"))) 2530 {
2506 { 2531 return STAT_TYPE_ISSUED_PULL_REP;
2507 return STAT_TYPE_SENT_PULL_REP; 2532 }
2508 } 2533 else if (0 == strncmp ("# pushes sent", stat_str, strlen ("# pushes sent")))
2509 else if (0 == strncmp("# push message received", stat_str, strlen("# push message received"))) 2534 {
2510 { 2535 return STAT_TYPE_SENT_PUSH_SEND;
2511 return STAT_TYPE_RECV_PUSH_SEND; 2536 }
2512 } 2537 else if (0 == strncmp ("# pull requests sent", stat_str, strlen (
2513 else if (0 == strncmp("# pull request message received", stat_str, strlen("# pull request message received"))) 2538 "# pull requests sent")))
2514 { 2539 {
2515 return STAT_TYPE_RECV_PULL_REQ; 2540 return STAT_TYPE_SENT_PULL_REQ;
2516 } 2541 }
2517 else if (0 == strncmp("# pull reply messages received", stat_str, strlen("# pull reply messages received"))) 2542 else if (0 == strncmp ("# pull replys sent", stat_str, strlen (
2518 { 2543 "# pull replys sent")))
2519 return STAT_TYPE_RECV_PULL_REP; 2544 {
2520 } 2545 return STAT_TYPE_SENT_PULL_REP;
2546 }
2547 else if (0 == strncmp ("# push message received", stat_str, strlen (
2548 "# push message received")))
2549 {
2550 return STAT_TYPE_RECV_PUSH_SEND;
2551 }
2552 else if (0 == strncmp ("# pull request message received", stat_str, strlen (
2553 "# pull request message received")))
2554 {
2555 return STAT_TYPE_RECV_PULL_REQ;
2556 }
2557 else if (0 == strncmp ("# pull reply messages received", stat_str, strlen (
2558 "# pull reply messages received")))
2559 {
2560 return STAT_TYPE_RECV_PULL_REP;
2561 }
2521 return STAT_TYPE_MAX; 2562 return STAT_TYPE_MAX;
2522} 2563}
2523 2564
@@ -2530,63 +2571,63 @@ enum STAT_TYPE stat_str_2_type(const char *stat_str)
2530 * 2571 *
2531 * @return string representation that matches statistics value 2572 * @return string representation that matches statistics value
2532 */ 2573 */
2533char* stat_type_2_str(enum STAT_TYPE stat_type) 2574char*stat_type_2_str (enum STAT_TYPE stat_type)
2534{ 2575{
2535 switch (stat_type) 2576 switch (stat_type)
2536 { 2577 {
2537 case STAT_TYPE_ROUNDS: 2578 case STAT_TYPE_ROUNDS:
2538 return "# rounds"; 2579 return "# rounds";
2539 2580
2540 case STAT_TYPE_BLOCKS: 2581 case STAT_TYPE_BLOCKS:
2541 return "# rounds blocked"; 2582 return "# rounds blocked";
2542 2583
2543 case STAT_TYPE_BLOCKS_MANY_PUSH: 2584 case STAT_TYPE_BLOCKS_MANY_PUSH:
2544 return "# rounds blocked - too many pushes"; 2585 return "# rounds blocked - too many pushes";
2545 2586
2546 case STAT_TYPE_BLOCKS_NO_PUSH: 2587 case STAT_TYPE_BLOCKS_NO_PUSH:
2547 return "# rounds blocked - no pushes"; 2588 return "# rounds blocked - no pushes";
2548 2589
2549 case STAT_TYPE_BLOCKS_NO_PULL: 2590 case STAT_TYPE_BLOCKS_NO_PULL:
2550 return "# rounds blocked - no pull replies"; 2591 return "# rounds blocked - no pull replies";
2551 2592
2552 case STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL: 2593 case STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL:
2553 return "# rounds blocked - too many pushes, no pull replies"; 2594 return "# rounds blocked - too many pushes, no pull replies";
2554 2595
2555 case STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL: 2596 case STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL:
2556 return "# rounds blocked - no pushes, no pull replies"; 2597 return "# rounds blocked - no pushes, no pull replies";
2557 2598
2558 case STAT_TYPE_ISSUED_PUSH_SEND: 2599 case STAT_TYPE_ISSUED_PUSH_SEND:
2559 return "# push send issued"; 2600 return "# push send issued";
2560 2601
2561 case STAT_TYPE_ISSUED_PULL_REQ: 2602 case STAT_TYPE_ISSUED_PULL_REQ:
2562 return "# pull request send issued"; 2603 return "# pull request send issued";
2563 2604
2564 case STAT_TYPE_ISSUED_PULL_REP: 2605 case STAT_TYPE_ISSUED_PULL_REP:
2565 return "# pull reply send issued"; 2606 return "# pull reply send issued";
2566 2607
2567 case STAT_TYPE_SENT_PUSH_SEND: 2608 case STAT_TYPE_SENT_PUSH_SEND:
2568 return "# pushes sent"; 2609 return "# pushes sent";
2569 2610
2570 case STAT_TYPE_SENT_PULL_REQ: 2611 case STAT_TYPE_SENT_PULL_REQ:
2571 return "# pull requests sent"; 2612 return "# pull requests sent";
2572 2613
2573 case STAT_TYPE_SENT_PULL_REP: 2614 case STAT_TYPE_SENT_PULL_REP:
2574 return "# pull replys sent"; 2615 return "# pull replys sent";
2575 2616
2576 case STAT_TYPE_RECV_PUSH_SEND: 2617 case STAT_TYPE_RECV_PUSH_SEND:
2577 return "# push message received"; 2618 return "# push message received";
2578 2619
2579 case STAT_TYPE_RECV_PULL_REQ: 2620 case STAT_TYPE_RECV_PULL_REQ:
2580 return "# pull request message received"; 2621 return "# pull request message received";
2581 2622
2582 case STAT_TYPE_RECV_PULL_REP: 2623 case STAT_TYPE_RECV_PULL_REP:
2583 return "# pull reply messages received"; 2624 return "# pull reply messages received";
2584 2625
2585 case STAT_TYPE_MAX: 2626 case STAT_TYPE_MAX:
2586 default: 2627 default:
2587 return "ERROR"; 2628 return "ERROR";
2588 ; 2629 ;
2589 } 2630 }
2590} 2631}
2591 2632
2592/** 2633/**
@@ -2600,136 +2641,136 @@ char* stat_type_2_str(enum STAT_TYPE stat_type)
2600 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration 2641 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
2601 */ 2642 */
2602int 2643int
2603stat_iterator(void *cls, 2644stat_iterator (void *cls,
2604 const char *subsystem, 2645 const char *subsystem,
2605 const char *name, 2646 const char *name,
2606 uint64_t value, 2647 uint64_t value,
2607 int is_persistent) 2648 int is_persistent)
2608{ 2649{
2609 (void)subsystem; 2650 (void) subsystem;
2610 (void)is_persistent; 2651 (void) is_persistent;
2611 const struct STATcls *stat_cls = (const struct STATcls *)cls; 2652 const struct STATcls *stat_cls = (const struct STATcls *) cls;
2612 struct RPSPeer *rps_peer = (struct RPSPeer *)stat_cls->rps_peer; 2653 struct RPSPeer *rps_peer = (struct RPSPeer *) stat_cls->rps_peer;
2613 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %s - %" PRIu64 "\n", 2654 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %s - %" PRIu64 "\n",
2614 //stat_type_2_str (stat_cls->stat_type), 2655 // stat_type_2_str (stat_cls->stat_type),
2615 name, 2656 name,
2616 value); 2657 value);
2617 to_file(rps_peer->file_name_stats, 2658 to_file (rps_peer->file_name_stats,
2618 "%s: %" PRIu64 "\n", 2659 "%s: %" PRIu64 "\n",
2619 name, 2660 name,
2620 value); 2661 value);
2621 switch (stat_str_2_type(name)) 2662 switch (stat_str_2_type (name))
2622 { 2663 {
2623 case STAT_TYPE_ROUNDS: 2664 case STAT_TYPE_ROUNDS:
2624 rps_peer->num_rounds = value; 2665 rps_peer->num_rounds = value;
2625 break; 2666 break;
2626 2667
2627 case STAT_TYPE_BLOCKS: 2668 case STAT_TYPE_BLOCKS:
2628 rps_peer->num_blocks = value; 2669 rps_peer->num_blocks = value;
2629 break; 2670 break;
2630 2671
2631 case STAT_TYPE_BLOCKS_MANY_PUSH: 2672 case STAT_TYPE_BLOCKS_MANY_PUSH:
2632 rps_peer->num_blocks_many_push = value; 2673 rps_peer->num_blocks_many_push = value;
2633 break; 2674 break;
2634 2675
2635 case STAT_TYPE_BLOCKS_NO_PUSH: 2676 case STAT_TYPE_BLOCKS_NO_PUSH:
2636 rps_peer->num_blocks_no_push = value; 2677 rps_peer->num_blocks_no_push = value;
2637 break; 2678 break;
2638 2679
2639 case STAT_TYPE_BLOCKS_NO_PULL: 2680 case STAT_TYPE_BLOCKS_NO_PULL:
2640 rps_peer->num_blocks_no_pull = value; 2681 rps_peer->num_blocks_no_pull = value;
2641 break; 2682 break;
2642 2683
2643 case STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL: 2684 case STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL:
2644 rps_peer->num_blocks_many_push_no_pull = value; 2685 rps_peer->num_blocks_many_push_no_pull = value;
2645 break; 2686 break;
2646 2687
2647 case STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL: 2688 case STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL:
2648 rps_peer->num_blocks_no_push_no_pull = value; 2689 rps_peer->num_blocks_no_push_no_pull = value;
2649 break; 2690 break;
2650 2691
2651 case STAT_TYPE_ISSUED_PUSH_SEND: 2692 case STAT_TYPE_ISSUED_PUSH_SEND:
2652 rps_peer->num_issued_push = value; 2693 rps_peer->num_issued_push = value;
2653 break; 2694 break;
2654 2695
2655 case STAT_TYPE_ISSUED_PULL_REQ: 2696 case STAT_TYPE_ISSUED_PULL_REQ:
2656 rps_peer->num_issued_pull_req = value; 2697 rps_peer->num_issued_pull_req = value;
2657 break; 2698 break;
2658 2699
2659 case STAT_TYPE_ISSUED_PULL_REP: 2700 case STAT_TYPE_ISSUED_PULL_REP:
2660 rps_peer->num_issued_pull_rep = value; 2701 rps_peer->num_issued_pull_rep = value;
2661 break; 2702 break;
2662 2703
2663 case STAT_TYPE_SENT_PUSH_SEND: 2704 case STAT_TYPE_SENT_PUSH_SEND:
2664 rps_peer->num_sent_push = value; 2705 rps_peer->num_sent_push = value;
2665 break; 2706 break;
2666 2707
2667 case STAT_TYPE_SENT_PULL_REQ: 2708 case STAT_TYPE_SENT_PULL_REQ:
2668 rps_peer->num_sent_pull_req = value; 2709 rps_peer->num_sent_pull_req = value;
2669 break; 2710 break;
2670 2711
2671 case STAT_TYPE_SENT_PULL_REP: 2712 case STAT_TYPE_SENT_PULL_REP:
2672 rps_peer->num_sent_pull_rep = value; 2713 rps_peer->num_sent_pull_rep = value;
2673 break; 2714 break;
2674 2715
2675 case STAT_TYPE_RECV_PUSH_SEND: 2716 case STAT_TYPE_RECV_PUSH_SEND:
2676 rps_peer->num_recv_push = value; 2717 rps_peer->num_recv_push = value;
2677 break; 2718 break;
2678 2719
2679 case STAT_TYPE_RECV_PULL_REQ: 2720 case STAT_TYPE_RECV_PULL_REQ:
2680 rps_peer->num_recv_pull_req = value; 2721 rps_peer->num_recv_pull_req = value;
2681 break; 2722 break;
2682 2723
2683 case STAT_TYPE_RECV_PULL_REP: 2724 case STAT_TYPE_RECV_PULL_REP:
2684 rps_peer->num_recv_pull_rep = value; 2725 rps_peer->num_recv_pull_rep = value;
2685 break; 2726 break;
2686 2727
2687 case STAT_TYPE_MAX: 2728 case STAT_TYPE_MAX:
2688 default: 2729 default:
2689 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 2730 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2690 "Unknown statistics string: %s\n", 2731 "Unknown statistics string: %s\n",
2691 name); 2732 name);
2692 break; 2733 break;
2693 } 2734 }
2694 return GNUNET_OK; 2735 return GNUNET_OK;
2695} 2736}
2696 2737
2697void post_profiler(struct RPSPeer *rps_peer) 2738void post_profiler (struct RPSPeer *rps_peer)
2698{ 2739{
2699 if (COLLECT_STATISTICS != cur_test_run.have_collect_statistics) 2740 if (COLLECT_STATISTICS != cur_test_run.have_collect_statistics)
2700 { 2741 {
2701 return; 2742 return;
2702 } 2743 }
2703 2744
2704 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2745 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2705 "Going to request statistic values with mask 0x%" PRIx32 "\n", 2746 "Going to request statistic values with mask 0x%" PRIx32 "\n",
2706 cur_test_run.stat_collect_flags); 2747 cur_test_run.stat_collect_flags);
2707 2748
2708 struct STATcls *stat_cls; 2749 struct STATcls *stat_cls;
2709 uint32_t stat_type; 2750 uint32_t stat_type;
2710 for (stat_type = STAT_TYPE_ROUNDS; 2751 for (stat_type = STAT_TYPE_ROUNDS;
2711 stat_type < STAT_TYPE_MAX; 2752 stat_type < STAT_TYPE_MAX;
2712 stat_type = stat_type << 1) 2753 stat_type = stat_type << 1)
2754 {
2755 if (stat_type & cur_test_run.stat_collect_flags)
2713 { 2756 {
2714 if (stat_type & cur_test_run.stat_collect_flags) 2757 stat_cls = GNUNET_malloc (sizeof(struct STATcls));
2715 { 2758 stat_cls->rps_peer = rps_peer;
2716 stat_cls = GNUNET_malloc(sizeof(struct STATcls)); 2759 stat_cls->stat_type = stat_type;
2717 stat_cls->rps_peer = rps_peer; 2760 rps_peer->file_name_stats =
2718 stat_cls->stat_type = stat_type; 2761 store_prefix_file_name (rps_peer->peer_id, "stats");
2719 rps_peer->file_name_stats = 2762 GNUNET_STATISTICS_get (rps_peer->stats_h,
2720 store_prefix_file_name(rps_peer->peer_id, "stats"); 2763 "rps",
2721 GNUNET_STATISTICS_get(rps_peer->stats_h, 2764 stat_type_2_str (stat_type),
2722 "rps", 2765 post_test_shutdown_ready_cb,
2723 stat_type_2_str(stat_type), 2766 stat_iterator,
2724 post_test_shutdown_ready_cb, 2767 (struct STATcls *) stat_cls);
2725 stat_iterator, 2768 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2726 (struct STATcls *)stat_cls); 2769 "Requested statistics for %s (peer %" PRIu32 ")\n",
2727 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2770 stat_type_2_str (stat_type),
2728 "Requested statistics for %s (peer %" PRIu32 ")\n", 2771 rps_peer->index);
2729 stat_type_2_str(stat_type),
2730 rps_peer->index);
2731 }
2732 } 2772 }
2773 }
2733} 2774}
2734 2775
2735 2776
@@ -2751,92 +2792,95 @@ void post_profiler(struct RPSPeer *rps_peer)
2751 * failed 2792 * failed
2752 */ 2793 */
2753static void 2794static void
2754run(void *cls, 2795run (void *cls,
2755 struct GNUNET_TESTBED_RunHandle *h, 2796 struct GNUNET_TESTBED_RunHandle *h,
2756 unsigned int n_peers, 2797 unsigned int n_peers,
2757 struct GNUNET_TESTBED_Peer **peers, 2798 struct GNUNET_TESTBED_Peer **peers,
2758 unsigned int links_succeeded, 2799 unsigned int links_succeeded,
2759 unsigned int links_failed) 2800 unsigned int links_failed)
2760{ 2801{
2761 (void)cls; 2802 (void) cls;
2762 (void)h; 2803 (void) h;
2763 (void)links_failed; 2804 (void) links_failed;
2764 unsigned int i; 2805 unsigned int i;
2765 struct OpListEntry *entry; 2806 struct OpListEntry *entry;
2766 2807
2767 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "RUN was called\n"); 2808 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "RUN was called\n");
2768 2809
2769 /* Check whether we timed out */ 2810 /* Check whether we timed out */
2770 if (n_peers != num_peers || 2811 if ((n_peers != num_peers)||
2771 NULL == peers || 2812 (NULL == peers) ||
2772 0 == links_succeeded) 2813 (0 == links_succeeded) )
2773 { 2814 {
2774 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Going down due to args (eg. timeout)\n"); 2815 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2775 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tn_peers: %u\n", n_peers); 2816 "Going down due to args (eg. timeout)\n");
2776 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tnum_peers: %" PRIu32 "\n", num_peers); 2817 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tn_peers: %u\n", n_peers);
2777 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tpeers: %p\n", peers); 2818 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tnum_peers: %" PRIu32 "\n",
2778 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\tlinks_succeeded: %u\n", links_succeeded); 2819 num_peers);
2779 GNUNET_SCHEDULER_shutdown(); 2820 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tpeers: %p\n", peers);
2780 return; 2821 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tlinks_succeeded: %u\n",
2781 } 2822 links_succeeded);
2823 GNUNET_SCHEDULER_shutdown ();
2824 return;
2825 }
2782 2826
2783 2827
2784 /* Initialize peers */ 2828 /* Initialize peers */
2785 testbed_peers = peers; 2829 testbed_peers = peers;
2786 num_peers_online = 0; 2830 num_peers_online = 0;
2787 for (i = 0; i < num_peers; i++) 2831 for (i = 0; i < num_peers; i++)
2788 { 2832 {
2789 entry = make_oplist_entry(); 2833 entry = make_oplist_entry ();
2790 entry->index = i; 2834 entry->index = i;
2791 rps_peers[i].index = i; 2835 rps_peers[i].index = i;
2792 if (NULL != cur_test_run.init_peer) 2836 if (NULL != cur_test_run.init_peer)
2793 cur_test_run.init_peer(&rps_peers[i]); 2837 cur_test_run.init_peer (&rps_peers[i]);
2794 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) 2838 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view)
2795 { 2839 {
2796 rps_peers->cur_view_count = 0; 2840 rps_peers->cur_view_count = 0;
2797 rps_peers->cur_view = NULL; 2841 rps_peers->cur_view = NULL;
2798 } 2842 }
2799 entry->op = GNUNET_TESTBED_peer_get_information(peers[i], 2843 entry->op = GNUNET_TESTBED_peer_get_information (peers[i],
2800 GNUNET_TESTBED_PIT_IDENTITY, 2844 GNUNET_TESTBED_PIT_IDENTITY,
2801 &info_cb, 2845 &info_cb,
2802 entry); 2846 entry);
2803 } 2847 }
2804 2848
2805 /* Bring peers up */ 2849 /* Bring peers up */
2806 GNUNET_assert(num_peers == n_peers); 2850 GNUNET_assert (num_peers == n_peers);
2807 for (i = 0; i < n_peers; i++) 2851 for (i = 0; i < n_peers; i++)
2808 { 2852 {
2809 rps_peers[i].index = i; 2853 rps_peers[i].index = i;
2810 rps_peers[i].op = 2854 rps_peers[i].op =
2811 GNUNET_TESTBED_service_connect(&rps_peers[i], 2855 GNUNET_TESTBED_service_connect (&rps_peers[i],
2812 peers[i], 2856 peers[i],
2813 "rps", 2857 "rps",
2814 &rps_connect_complete_cb, 2858 &rps_connect_complete_cb,
2815 &rps_peers[i], 2859 &rps_peers[i],
2816 &rps_connect_adapter, 2860 &rps_connect_adapter,
2817 &rps_disconnect_adapter, 2861 &rps_disconnect_adapter,
2818 &rps_peers[i]); 2862 &rps_peers[i]);
2819 /* Connect all peers to statistics service */ 2863 /* Connect all peers to statistics service */
2820 if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics) 2864 if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics)
2821 { 2865 {
2822 rps_peers[i].stat_op = 2866 rps_peers[i].stat_op =
2823 GNUNET_TESTBED_service_connect(NULL, 2867 GNUNET_TESTBED_service_connect (NULL,
2824 peers[i], 2868 peers[i],
2825 "statistics", 2869 "statistics",
2826 stat_complete_cb, 2870 stat_complete_cb,
2827 &rps_peers[i], 2871 &rps_peers[i],
2828 &stat_connect_adapter, 2872 &stat_connect_adapter,
2829 &stat_disconnect_adapter, 2873 &stat_disconnect_adapter,
2830 &rps_peers[i]); 2874 &rps_peers[i]);
2831 } 2875 }
2832 } 2876 }
2833 2877
2834 if (NULL != churn_task) 2878 if (NULL != churn_task)
2835 GNUNET_SCHEDULER_cancel(churn_task); 2879 GNUNET_SCHEDULER_cancel (churn_task);
2836 post_test_task = GNUNET_SCHEDULER_add_delayed(timeout, &post_test_op, NULL); 2880 post_test_task = GNUNET_SCHEDULER_add_delayed (timeout, &post_test_op, NULL);
2837 timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2881 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
2838 (timeout_s * 1.2) + 0.1 * num_peers); 2882 (timeout_s * 1.2) + 0.1 * num_peers);
2839 shutdown_task = GNUNET_SCHEDULER_add_delayed(timeout, &shutdown_op, NULL); 2883 shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL);
2840} 2884}
2841 2885
2842 2886
@@ -2848,11 +2892,11 @@ run(void *cls,
2848 * @return 0 on success 2892 * @return 0 on success
2849 */ 2893 */
2850int 2894int
2851main(int argc, char *argv[]) 2895main (int argc, char *argv[])
2852{ 2896{
2853 int ret_value; 2897 int ret_value;
2854 2898
2855 (void)argc; 2899 (void) argc;
2856 2900
2857 /* Defaults for tests */ 2901 /* Defaults for tests */
2858 num_peers = 5; 2902 num_peers = 5;
@@ -2869,172 +2913,175 @@ main(int argc, char *argv[])
2869 churn_task = NULL; 2913 churn_task = NULL;
2870 timeout_s = 30; 2914 timeout_s = 30;
2871 2915
2872 if (strstr(argv[0], "malicious") != NULL) 2916 if (strstr (argv[0], "malicious") != NULL)
2873 { 2917 {
2874 cur_test_run.pre_test = mal_pre; 2918 cur_test_run.pre_test = mal_pre;
2875 cur_test_run.main_test = mal_cb; 2919 cur_test_run.main_test = mal_cb;
2876 cur_test_run.init_peer = mal_init_peer; 2920 cur_test_run.init_peer = mal_init_peer;
2877 timeout_s = 40; 2921 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 }
2961 2922
2962 else if (strstr(argv[0], "_churn") != NULL) 2923 if (strstr (argv[0], "_1") != NULL)
2963 { 2924 {
2964 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test churn\n"); 2925 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 1\n");
2965 cur_test_run.name = "test-rps-churn"; 2926 cur_test_run.name = "test-rps-malicious_1";
2966 num_peers = 5; 2927 mal_type = 1;
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;
2974 } 2928 }
2975 2929 else if (strstr (argv[0], "_2") != NULL)
2976 else if (strstr(argv[0], "_sub") != NULL)
2977 { 2930 {
2978 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Test subs\n"); 2931 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 2\n");
2979 cur_test_run.name = "test-rps-sub"; 2932 cur_test_run.name = "test-rps-malicious_2";
2980 num_peers = 5; 2933 mal_type = 2;
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;
2989 } 2934 }
2990 2935 else if (strstr (argv[0], "_3") != NULL)
2991 else if (strstr(argv[0], "profiler") != NULL)
2992 { 2936 {
2993 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n"); 2937 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test malicious peer type 3\n");
2994 cur_test_run.name = "test-rps-profiler"; 2938 cur_test_run.name = "test-rps-malicious_3";
2995 num_peers = 16;
2996 mal_type = 3; 2939 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/");
3032 } 2940 }
3033 timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, timeout_s); 2941 }
3034 2942
3035 rps_peers = GNUNET_new_array(num_peers, struct RPSPeer); 2943 else if (strstr (argv[0], "_single_req") != NULL)
3036 peer_map = GNUNET_CONTAINER_multipeermap_create(num_peers, GNUNET_NO); 2944 {
3037 rps_peer_ids = GNUNET_new_array(num_peers, struct GNUNET_PeerIdentity); 2945 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test single request\n");
2946 cur_test_run.name = "test-rps-single-req";
2947 cur_test_run.main_test = single_req_cb;
2948 cur_test_run.have_churn = HAVE_NO_CHURN;
2949 }
2950
2951 else if (strstr (argv[0], "_delayed_reqs") != NULL)
2952 {
2953 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test delayed requests\n");
2954 cur_test_run.name = "test-rps-delayed-reqs";
2955 cur_test_run.main_test = delay_req_cb;
2956 cur_test_run.have_churn = HAVE_NO_CHURN;
2957 }
2958
2959 else if (strstr (argv[0], "_seed_big") != NULL)
2960 {
2961 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2962 "Test seeding (num_peers > GNUNET_MAX_MESSAGE_SIZE)\n");
2963 num_peers = 1;
2964 cur_test_run.name = "test-rps-seed-big";
2965 cur_test_run.main_test = seed_big_cb;
2966 cur_test_run.eval_cb = no_eval;
2967 cur_test_run.have_churn = HAVE_NO_CHURN;
2968 timeout_s = 10;
2969 }
2970
2971 else if (strstr (argv[0], "_single_peer_seed") != NULL)
2972 {
2973 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2974 "Test seeding and requesting on a single peer\n");
2975 cur_test_run.name = "test-rps-single-peer-seed";
2976 cur_test_run.main_test = single_peer_seed_cb;
2977 cur_test_run.have_churn = HAVE_NO_CHURN;
2978 }
2979
2980 else if (strstr (argv[0], "_seed_request") != NULL)
2981 {
2982 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2983 "Test seeding and requesting on multiple peers\n");
2984 cur_test_run.name = "test-rps-seed-request";
2985 cur_test_run.main_test = seed_req_cb;
2986 cur_test_run.have_churn = HAVE_NO_CHURN;
2987 }
2988
2989 else if (strstr (argv[0], "_seed") != NULL)
2990 {
2991 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test seeding\n");
2992 cur_test_run.name = "test-rps-seed";
2993 cur_test_run.main_test = seed_cb;
2994 cur_test_run.eval_cb = no_eval;
2995 cur_test_run.have_churn = HAVE_NO_CHURN;
2996 }
2997
2998 else if (strstr (argv[0], "_req_cancel") != NULL)
2999 {
3000 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test cancelling a request\n");
3001 cur_test_run.name = "test-rps-req-cancel";
3002 num_peers = 1;
3003 cur_test_run.main_test = req_cancel_cb;
3004 cur_test_run.eval_cb = no_eval;
3005 cur_test_run.have_churn = HAVE_NO_CHURN;
3006 timeout_s = 10;
3007 }
3008
3009 else if (strstr (argv[0], "_churn") != NULL)
3010 {
3011 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test churn\n");
3012 cur_test_run.name = "test-rps-churn";
3013 num_peers = 5;
3014 cur_test_run.init_peer = default_init_peer;
3015 cur_test_run.main_test = churn_test_cb;
3016 cur_test_run.reply_handle = default_reply_handle;
3017 cur_test_run.eval_cb = default_eval_cb;
3018 cur_test_run.have_churn = HAVE_NO_CHURN;
3019 cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT;
3020 timeout_s = 40;
3021 }
3022
3023 else if (strstr (argv[0], "_sub") != NULL)
3024 {
3025 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test subs\n");
3026 cur_test_run.name = "test-rps-sub";
3027 num_peers = 5;
3028 // cur_test_run.init_peer = &default_init_peer;
3029 cur_test_run.pre_test = &sub_pre;
3030 cur_test_run.main_test = &single_req_cb;
3031 // cur_test_run.reply_handle = default_reply_handle;
3032 cur_test_run.post_test = &sub_post;
3033 // cur_test_run.eval_cb = default_eval_cb;
3034 cur_test_run.have_churn = HAVE_NO_CHURN;
3035 cur_test_run.have_quick_quit = HAVE_QUICK_QUIT;
3036 }
3037
3038 else if (strstr (argv[0], "profiler") != NULL)
3039 {
3040 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n");
3041 cur_test_run.name = "test-rps-profiler";
3042 num_peers = 16;
3043 mal_type = 3;
3044 cur_test_run.init_peer = profiler_init_peer;
3045 // cur_test_run.pre_test = mal_pre;
3046 cur_test_run.pre_test = pre_profiler;
3047 cur_test_run.main_test = profiler_cb;
3048 cur_test_run.reply_handle = profiler_reply_handle;
3049 cur_test_run.eval_cb = profiler_eval;
3050 cur_test_run.post_test = post_profiler;
3051 cur_test_run.request_interval = 2;
3052 cur_test_run.num_requests = 5;
3053 // cur_test_run.have_churn = HAVE_CHURN;
3054 cur_test_run.have_churn = HAVE_NO_CHURN;
3055 cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT;
3056 cur_test_run.have_collect_statistics = COLLECT_STATISTICS;
3057 cur_test_run.stat_collect_flags = STAT_TYPE_ROUNDS
3058 | STAT_TYPE_BLOCKS
3059 | STAT_TYPE_BLOCKS_MANY_PUSH
3060 | STAT_TYPE_BLOCKS_NO_PUSH
3061 | STAT_TYPE_BLOCKS_NO_PULL
3062 | STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL
3063 | STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL
3064 | STAT_TYPE_ISSUED_PUSH_SEND
3065 | STAT_TYPE_ISSUED_PULL_REQ
3066 | STAT_TYPE_ISSUED_PULL_REP
3067 | STAT_TYPE_SENT_PUSH_SEND
3068 | STAT_TYPE_SENT_PULL_REQ
3069 | STAT_TYPE_SENT_PULL_REP
3070 | STAT_TYPE_RECV_PUSH_SEND
3071 | STAT_TYPE_RECV_PULL_REQ
3072 | STAT_TYPE_RECV_PULL_REP;
3073 cur_test_run.have_collect_view = COLLECT_VIEW;
3074 timeout_s = 150;
3075
3076 /* 'Clean' directory */
3077 (void) GNUNET_DISK_directory_remove ("/tmp/rps/");
3078 GNUNET_DISK_directory_create ("/tmp/rps/");
3079 }
3080 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_s);
3081
3082 rps_peers = GNUNET_new_array (num_peers, struct RPSPeer);
3083 peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO);
3084 rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
3038 if ((2 == mal_type) || 3085 if ((2 == mal_type) ||
3039 (3 == mal_type)) 3086 (3 == mal_type))
3040 target_peer = &rps_peer_ids[num_peers - 2]; 3087 target_peer = &rps_peer_ids[num_peers - 2];
@@ -3044,30 +3091,30 @@ main(int argc, char *argv[])
3044 with the malicious portion */ 3091 with the malicious portion */
3045 3092
3046 ok = 1; 3093 ok = 1;
3047 ret_value = GNUNET_TESTBED_test_run(cur_test_run.name, 3094 ret_value = GNUNET_TESTBED_test_run (cur_test_run.name,
3048 "test_rps.conf", 3095 "test_rps.conf",
3049 num_peers, 3096 num_peers,
3050 0, NULL, NULL, 3097 0, NULL, NULL,
3051 &run, NULL); 3098 &run, NULL);
3052 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 3099 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3053 "_test_run returned.\n"); 3100 "_test_run returned.\n");
3054 if (GNUNET_OK != ret_value) 3101 if (GNUNET_OK != ret_value)
3055 { 3102 {
3056 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 3103 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3057 "Test did not run successfully!\n"); 3104 "Test did not run successfully!\n");
3058 } 3105 }
3059 3106
3060 ret_value = cur_test_run.eval_cb(); 3107 ret_value = cur_test_run.eval_cb ();
3061 3108
3062 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) 3109 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view)
3063 { 3110 {
3064 GNUNET_array_grow(rps_peers->cur_view, 3111 GNUNET_array_grow (rps_peers->cur_view,
3065 rps_peers->cur_view_count, 3112 rps_peers->cur_view_count,
3066 0); 3113 0);
3067 } 3114 }
3068 GNUNET_free(rps_peers); 3115 GNUNET_free (rps_peers);
3069 GNUNET_free(rps_peer_ids); 3116 GNUNET_free (rps_peer_ids);
3070 GNUNET_CONTAINER_multipeermap_destroy(peer_map); 3117 GNUNET_CONTAINER_multipeermap_destroy (peer_map);
3071 return ret_value; 3118 return ret_value;
3072} 3119}
3073 3120
diff --git a/src/rps/test_rps_api.c b/src/rps/test_rps_api.c
index 97dccd789..6fca7ea12 100644
--- a/src/rps/test_rps_api.c
+++ b/src/rps/test_rps_api.c
@@ -30,56 +30,57 @@ static int ok = 1;
30 30
31 31
32static void 32static void
33run(void *cls, 33run (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
42static int 42static int
43check() 43check ()
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
52 if (NULL == path) 52 if (NULL == path)
53 { 53 {
54 fprintf(stderr, "Service executable not found `%s'\n", "gnunet-service-rps"); 54 fprintf (stderr, "Service executable not found `%s'\n",
55 return; 55 "gnunet-service-rps");
56 } 56 return;
57 57 }
58 proc = GNUNET_OS_start_process(GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL, 58
59 NULL, NULL, path, "gnunet-service-rps", NULL); 59 proc = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL,
60 60 NULL, NULL, path, "gnunet-service-rps", NULL);
61 GNUNET_free(path); 61
62 GNUNET_assert(NULL != proc); 62 GNUNET_free (path);
63 GNUNET_PROGRAM_run(1, argv, "test-rps-api", "nohelp", 63 GNUNET_assert (NULL != proc);
64 options, &run, &ok); 64 GNUNET_PROGRAM_run (1, argv, "test-rps-api", "nohelp",
65 if (0 != GNUNET_OS_process_kill(proc, SIGTERM)) 65 options, &run, &ok);
66 { 66 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
67 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); 67 {
68 ok = 1; 68 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
69 } 69 ok = 1;
70 GNUNET_OS_process_wait(proc); 70 }
71 GNUNET_OS_process_destroy(proc); 71 GNUNET_OS_process_wait (proc);
72 GNUNET_OS_process_destroy (proc);
72 return ok; 73 return ok;
73} 74}
74 75
75 76
76int 77int
77main(int argc, char *argv[]) 78main (int argc, char *argv[])
78{ 79{
79 GNUNET_log_setup("test_statistics_api", 80 GNUNET_log_setup ("test_statistics_api",
80 "WARNING", 81 "WARNING",
81 NULL); 82 NULL);
82 return check(); 83 return check ();
83} 84}
84 85
85/* end of test_rps_api.c */ 86/* 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 796c46d30..6f6f6b0d3 100644
--- a/src/rps/test_service_rps_custommap.c
+++ b/src/rps/test_service_rps_custommap.c
@@ -24,102 +24,103 @@
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__); \
28#define CHECK(c) { if (!(c)) ABORT (); } 28 if (NULL != c_m) CustomPeerMap_destroy (c_m); return 1; }
29#define CHECK(c) { if (! (c)) ABORT (); }
29 30
30 31
31static int 32static int
32check() 33check ()
33{ 34{
34 struct CustomPeerMap *c_m; 35 struct CustomPeerMap *c_m;
35 struct GNUNET_PeerIdentity k1; 36 struct GNUNET_PeerIdentity k1;
36 struct GNUNET_PeerIdentity k2; 37 struct GNUNET_PeerIdentity k2;
37 int j; 38 int j;
38 39
39 CHECK(NULL != (c_m = CustomPeerMap_create(4))); 40 CHECK (NULL != (c_m = CustomPeerMap_create (4)));
40 memset(&k1, 0, sizeof(k1)); 41 memset (&k1, 0, sizeof(k1));
41 memset(&k2, 1, sizeof(k2)); 42 memset (&k2, 1, sizeof(k2));
42 CHECK(GNUNET_NO == CustomPeerMap_contains_peer(c_m, &k1)); 43 CHECK (GNUNET_NO == CustomPeerMap_contains_peer (c_m, &k1));
43 CHECK(GNUNET_NO == CustomPeerMap_contains_peer(c_m, &k2)); 44 CHECK (GNUNET_NO == CustomPeerMap_contains_peer (c_m, &k2));
44 CHECK(GNUNET_NO == CustomPeerMap_remove_peer(c_m, &k1)); 45 CHECK (GNUNET_NO == CustomPeerMap_remove_peer (c_m, &k1));
45 CHECK(GNUNET_NO == CustomPeerMap_remove_peer(c_m, &k2)); 46 CHECK (GNUNET_NO == CustomPeerMap_remove_peer (c_m, &k2));
46 CHECK(GNUNET_NO == CustomPeerMap_remove_peer_by_index(c_m, 0)); 47 CHECK (GNUNET_NO == CustomPeerMap_remove_peer_by_index (c_m, 0));
47 CHECK(GNUNET_NO == CustomPeerMap_remove_peer_by_index(c_m, 0)); 48 CHECK (GNUNET_NO == CustomPeerMap_remove_peer_by_index (c_m, 0));
48 CHECK(GNUNET_NO == CustomPeerMap_remove_peer_by_index(c_m, 1)); 49 CHECK (GNUNET_NO == CustomPeerMap_remove_peer_by_index (c_m, 1));
49 CHECK(GNUNET_NO == CustomPeerMap_remove_peer_by_index(c_m, 1)); 50 CHECK (GNUNET_NO == CustomPeerMap_remove_peer_by_index (c_m, 1));
50 CHECK(NULL == CustomPeerMap_get_peer_by_index(c_m, 0)); 51 CHECK (NULL == CustomPeerMap_get_peer_by_index (c_m, 0));
51 CHECK(NULL == CustomPeerMap_get_peer_by_index(c_m, 0)); 52 CHECK (NULL == CustomPeerMap_get_peer_by_index (c_m, 0));
52 CHECK(NULL == CustomPeerMap_get_peer_by_index(c_m, 1)); 53 CHECK (NULL == CustomPeerMap_get_peer_by_index (c_m, 1));
53 CHECK(NULL == CustomPeerMap_get_peer_by_index(c_m, 1)); 54 CHECK (NULL == CustomPeerMap_get_peer_by_index (c_m, 1));
54 CustomPeerMap_clear(c_m); /* See if assertions trigger */ 55 CustomPeerMap_clear (c_m); /* See if assertions trigger */
55 CHECK(0 == CustomPeerMap_size(c_m)); 56 CHECK (0 == CustomPeerMap_size (c_m));
56 57
57 CHECK(GNUNET_OK == CustomPeerMap_put(c_m, &k1)); 58 CHECK (GNUNET_OK == CustomPeerMap_put (c_m, &k1));
58 CHECK(1 == CustomPeerMap_size(c_m)); 59 CHECK (1 == CustomPeerMap_size (c_m));
59 CHECK(GNUNET_NO == CustomPeerMap_put(c_m, &k1)); 60 CHECK (GNUNET_NO == CustomPeerMap_put (c_m, &k1));
60 CHECK(1 == CustomPeerMap_size(c_m)); 61 CHECK (1 == CustomPeerMap_size (c_m));
61 CHECK(GNUNET_YES == CustomPeerMap_contains_peer(c_m, &k1)); 62 CHECK (GNUNET_YES == CustomPeerMap_contains_peer (c_m, &k1));
62 CHECK(GNUNET_OK == CustomPeerMap_remove_peer(c_m, &k1)); 63 CHECK (GNUNET_OK == CustomPeerMap_remove_peer (c_m, &k1));
63 CHECK(0 == CustomPeerMap_size(c_m)); 64 CHECK (0 == CustomPeerMap_size (c_m));
64 CHECK(GNUNET_NO == CustomPeerMap_contains_peer(c_m, &k1)); 65 CHECK (GNUNET_NO == CustomPeerMap_contains_peer (c_m, &k1));
65 CHECK(GNUNET_NO == CustomPeerMap_contains_peer(c_m, &k2)); 66 CHECK (GNUNET_NO == CustomPeerMap_contains_peer (c_m, &k2));
66 67
67 CHECK(GNUNET_OK == CustomPeerMap_put(c_m, &k1)); 68 CHECK (GNUNET_OK == CustomPeerMap_put (c_m, &k1));
68 CHECK(1 == CustomPeerMap_size(c_m)); 69 CHECK (1 == CustomPeerMap_size (c_m));
69 for (j = 0; j < 16; j++) 70 for (j = 0; j < 16; j++)
70 { 71 {
71 CHECK(GNUNET_NO == CustomPeerMap_put(c_m, &k1)); 72 CHECK (GNUNET_NO == CustomPeerMap_put (c_m, &k1));
72 } 73 }
73 CHECK(1 == CustomPeerMap_size(c_m)); 74 CHECK (1 == CustomPeerMap_size (c_m));
74 CHECK(GNUNET_OK == CustomPeerMap_put(c_m, &k2)); 75 CHECK (GNUNET_OK == CustomPeerMap_put (c_m, &k2));
75 CHECK(2 == CustomPeerMap_size(c_m)); 76 CHECK (2 == CustomPeerMap_size (c_m));
76 for (j = 0; j < 16; j++) 77 for (j = 0; j < 16; j++)
77 { 78 {
78 CHECK(GNUNET_NO == CustomPeerMap_put(c_m, &k2)); 79 CHECK (GNUNET_NO == CustomPeerMap_put (c_m, &k2));
79 } 80 }
80 CHECK(2 == CustomPeerMap_size(c_m)); 81 CHECK (2 == CustomPeerMap_size (c_m));
81 82
82 /* iterate */ 83 /* iterate */
83 for (j = 0; j < CustomPeerMap_size(c_m); j++) 84 for (j = 0; j < CustomPeerMap_size (c_m); j++)
84 { 85 {
85 CHECK(NULL != CustomPeerMap_get_peer_by_index(c_m, j)); 86 CHECK (NULL != CustomPeerMap_get_peer_by_index (c_m, j));
86 } 87 }
87 CHECK((0 == memcmp(CustomPeerMap_get_peer_by_index(c_m, 0), 88 CHECK ((0 == memcmp (CustomPeerMap_get_peer_by_index (c_m, 0),
88 &k1, sizeof(k1)))); 89 &k1, sizeof(k1))));
89 CHECK((0 == memcmp(CustomPeerMap_get_peer_by_index(c_m, 1), 90 CHECK ((0 == memcmp (CustomPeerMap_get_peer_by_index (c_m, 1),
90 &k2, sizeof(k2)))); 91 &k2, sizeof(k2))));
91 CHECK(GNUNET_OK == CustomPeerMap_remove_peer(c_m, &k1)); 92 CHECK (GNUNET_OK == CustomPeerMap_remove_peer (c_m, &k1));
92 CHECK(1 == CustomPeerMap_size(c_m)); 93 CHECK (1 == CustomPeerMap_size (c_m));
93 CHECK(GNUNET_NO == CustomPeerMap_contains_peer(c_m, &k1)); 94 CHECK (GNUNET_NO == CustomPeerMap_contains_peer (c_m, &k1));
94 CHECK(GNUNET_YES == CustomPeerMap_contains_peer(c_m, &k2)); 95 CHECK (GNUNET_YES == CustomPeerMap_contains_peer (c_m, &k2));
95 CHECK(NULL != CustomPeerMap_get_peer_by_index(c_m, 0)); 96 CHECK (NULL != CustomPeerMap_get_peer_by_index (c_m, 0));
96 97
97 CustomPeerMap_clear(c_m); 98 CustomPeerMap_clear (c_m);
98 CHECK(0 == CustomPeerMap_size(c_m)); 99 CHECK (0 == CustomPeerMap_size (c_m));
99 100
100 CHECK(GNUNET_OK == CustomPeerMap_put(c_m, &k1)); 101 CHECK (GNUNET_OK == CustomPeerMap_put (c_m, &k1));
101 CHECK(1 == CustomPeerMap_size(c_m)); 102 CHECK (1 == CustomPeerMap_size (c_m));
102 CHECK(GNUNET_OK == CustomPeerMap_put(c_m, &k2)); 103 CHECK (GNUNET_OK == CustomPeerMap_put (c_m, &k2));
103 CHECK(2 == CustomPeerMap_size(c_m)); 104 CHECK (2 == CustomPeerMap_size (c_m));
104 CustomPeerMap_clear(c_m); 105 CustomPeerMap_clear (c_m);
105 CHECK(0 == CustomPeerMap_size(c_m)); 106 CHECK (0 == CustomPeerMap_size (c_m));
106 107
107 CustomPeerMap_destroy(c_m); 108 CustomPeerMap_destroy (c_m);
108 109
109 return 0; 110 return 0;
110} 111}
111 112
112 113
113int 114int
114main(int argc, char *argv[]) 115main (int argc, char *argv[])
115{ 116{
116 (void)argc; 117 (void) argc;
117 (void)argv; 118 (void) argv;
118 119
119 GNUNET_log_setup("test_service_rps_peers", 120 GNUNET_log_setup ("test_service_rps_peers",
120 "WARNING", 121 "WARNING",
121 NULL); 122 NULL);
122 return check(); 123 return check ();
123} 124}
124 125
125/* end of test_service_rps_custommap.c */ 126/* 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 b6e3e36bf..706abf4f9 100644
--- a/src/rps/test_service_rps_sampler_elem.c
+++ b/src/rps/test_service_rps_sampler_elem.c
@@ -25,12 +25,13 @@
25#include "gnunet_util_lib.h" 25#include "gnunet_util_lib.h"
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__); \
29#define CHECK(c) { if (!(c)) ABORT (); } 29 return 1; }
30#define CHECK(c) { if (! (c)) ABORT (); }
30 31
31 32
32static int 33static int
33check() 34check ()
34{ 35{
35 struct GNUNET_PeerIdentity pid0; 36 struct GNUNET_PeerIdentity pid0;
36 struct GNUNET_PeerIdentity pid1; 37 struct GNUNET_PeerIdentity pid1;
@@ -40,152 +41,155 @@ check()
40 struct GNUNET_HashCode hash_code; 41 struct GNUNET_HashCode hash_code;
41 struct GNUNET_HashCode hash_code2; 42 struct GNUNET_HashCode hash_code2;
42 43
43 memset(&pid0, 1, sizeof(pid0)); 44 memset (&pid0, 1, sizeof(pid0));
44 memset(&pid1, 0, sizeof(pid1)); 45 memset (&pid1, 0, sizeof(pid1));
45 46
46 /* Check if creation and destruction of an 47 /* Check if creation and destruction of an
47 * (empty) sampler element works */ 48 * (empty) sampler element works */
48 s_elem = RPS_sampler_elem_create(); 49 s_elem = RPS_sampler_elem_create ();
49 CHECK(NULL != s_elem); 50 CHECK (NULL != s_elem);
50 CHECK(EMPTY == s_elem->is_empty); 51 CHECK (EMPTY == s_elem->is_empty);
51 CHECK(NULL != &s_elem->auth_key); 52 CHECK (NULL != &s_elem->auth_key);
52 auth_key = s_elem->auth_key; 53 auth_key = s_elem->auth_key;
53 RPS_sampler_elem_destroy(s_elem); 54 RPS_sampler_elem_destroy (s_elem);
54 55
55 56
56 /* Check creation of another sampler element 57 /* Check creation of another sampler element
57 * yields another (random) key */ 58 * yields another (random) key */
58 s_elem = RPS_sampler_elem_create(); 59 s_elem = RPS_sampler_elem_create ();
59 CHECK(NULL != s_elem); 60 CHECK (NULL != s_elem);
60 CHECK(EMPTY == s_elem->is_empty); 61 CHECK (EMPTY == s_elem->is_empty);
61 CHECK(NULL != &s_elem->auth_key); 62 CHECK (NULL != &s_elem->auth_key);
62 CHECK(auth_key.key != s_elem->auth_key.key); 63 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)); 64 CHECK (0 != memcmp (auth_key.key, s_elem->auth_key.key,
65 GNUNET_CRYPTO_HASH_LENGTH));
64 auth_key = s_elem->auth_key; 66 auth_key = s_elem->auth_key;
65 67
66 /* Check that reinitialisation 68 /* Check that reinitialisation
67 * yields another (random) key */ 69 * yields another (random) key */
68 RPS_sampler_elem_reinit(s_elem); 70 RPS_sampler_elem_reinit (s_elem);
69 CHECK(NULL != s_elem); 71 CHECK (NULL != s_elem);
70 CHECK(EMPTY == s_elem->is_empty); 72 CHECK (EMPTY == s_elem->is_empty);
71 CHECK(NULL != &s_elem->auth_key); 73 CHECK (NULL != &s_elem->auth_key);
72 CHECK(auth_key.key != s_elem->auth_key.key); 74 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)); 75 CHECK (0 != memcmp (auth_key.key, s_elem->auth_key.key,
74 RPS_sampler_elem_destroy(s_elem); 76 GNUNET_CRYPTO_HASH_LENGTH));
77 RPS_sampler_elem_destroy (s_elem);
75 78
76 79
77 /* Check that input of single peer id 80 /* Check that input of single peer id
78 * sets valid values */ 81 * sets valid values */
79 s_elem = RPS_sampler_elem_create(); 82 s_elem = RPS_sampler_elem_create ();
80 CHECK(EMPTY == s_elem->is_empty); 83 CHECK (EMPTY == s_elem->is_empty);
81 CHECK(NULL != &s_elem->auth_key); 84 CHECK (NULL != &s_elem->auth_key);
82 CHECK(auth_key.key != s_elem->auth_key.key); 85 CHECK (auth_key.key != s_elem->auth_key.key);
83 /* This fails only with minimal chance */ 86 /* This fails only with minimal chance */
84 CHECK(0 != memcmp(auth_key.key, s_elem->auth_key.key, GNUNET_CRYPTO_HASH_LENGTH)); 87 CHECK (0 != memcmp (auth_key.key, s_elem->auth_key.key,
88 GNUNET_CRYPTO_HASH_LENGTH));
85 auth_key = s_elem->auth_key; 89 auth_key = s_elem->auth_key;
86 90
87 /* Check also that the hash of the peer id changed 91 /* Check also that the hash of the peer id changed
88 * Also fails with minimal probability */ 92 * Also fails with minimal probability */
89 hash_code = s_elem->peer_id_hash; 93 hash_code = s_elem->peer_id_hash;
90 RPS_sampler_elem_next(s_elem, &pid0); 94 RPS_sampler_elem_next (s_elem, &pid0);
91 CHECK(0 == memcmp(&pid0, 95 CHECK (0 == memcmp (&pid0,
92 &s_elem->peer_id, 96 &s_elem->peer_id,
93 sizeof(struct GNUNET_PeerIdentity))); 97 sizeof(struct GNUNET_PeerIdentity)));
94 CHECK(0 != memcmp(&hash_code, 98 CHECK (0 != memcmp (&hash_code,
95 &s_elem->peer_id_hash, 99 &s_elem->peer_id_hash,
96 sizeof(struct GNUNET_HashCode))); 100 sizeof(struct GNUNET_HashCode)));
97 hash_code = s_elem->peer_id_hash; 101 hash_code = s_elem->peer_id_hash;
98 102
99 /* We can only check that the peer id is one of both inputs */ 103 /* We can only check that the peer id is one of both inputs */
100 RPS_sampler_elem_next(s_elem, &pid1); 104 RPS_sampler_elem_next (s_elem, &pid1);
101 CHECK((0 == memcmp(&pid0, 105 CHECK ((0 == memcmp (&pid0,
102 &s_elem->peer_id, 106 &s_elem->peer_id,
103 sizeof(struct GNUNET_PeerIdentity))) || 107 sizeof(struct GNUNET_PeerIdentity))) ||
104 (0 == memcmp(&pid1, 108 (0 == memcmp (&pid1,
105 &s_elem->peer_id, 109 &s_elem->peer_id,
106 sizeof(struct GNUNET_PeerIdentity)))); 110 sizeof(struct GNUNET_PeerIdentity))));
107 111
108 /* Check that hash stayed the same when peer id did not change */ 112 /* Check that hash stayed the same when peer id did not change */
109 if (0 == memcmp(&pid0, 113 if (0 == memcmp (&pid0,
110 &s_elem->peer_id, 114 &s_elem->peer_id,
111 sizeof(struct GNUNET_PeerIdentity))) 115 sizeof(struct GNUNET_PeerIdentity)))
112 { 116 {
113 CHECK(0 == memcmp(&hash_code, 117 CHECK (0 == memcmp (&hash_code,
114 &s_elem->peer_id_hash, 118 &s_elem->peer_id_hash,
115 sizeof(struct GNUNET_HashCode))); 119 sizeof(struct GNUNET_HashCode)));
116 } 120 }
117 else /* Check that hash changed */ 121 else /* Check that hash changed */
118 { 122 {
119 CHECK(0 != memcmp(&hash_code, 123 CHECK (0 != memcmp (&hash_code,
120 &s_elem->peer_id_hash, 124 &s_elem->peer_id_hash,
121 sizeof(struct GNUNET_HashCode))); 125 sizeof(struct GNUNET_HashCode)));
122 } 126 }
123 127
124 /* Check multiple inputs of same id 128 /* Check multiple inputs of same id
125 * hash should not change anymore */ 129 * hash should not change anymore */
126 hash_code2 = s_elem->peer_id_hash; 130 hash_code2 = s_elem->peer_id_hash;
127 RPS_sampler_elem_next(s_elem, &pid0); 131 RPS_sampler_elem_next (s_elem, &pid0);
128 CHECK(0 == memcmp(&hash_code2, 132 CHECK (0 == memcmp (&hash_code2,
129 &s_elem->peer_id_hash, 133 &s_elem->peer_id_hash,
130 sizeof(struct GNUNET_HashCode))); 134 sizeof(struct GNUNET_HashCode)));
131 RPS_sampler_elem_next(s_elem, &pid1); 135 RPS_sampler_elem_next (s_elem, &pid1);
132 CHECK(0 == memcmp(&hash_code2, 136 CHECK (0 == memcmp (&hash_code2,
133 &s_elem->peer_id_hash, 137 &s_elem->peer_id_hash,
134 sizeof(struct GNUNET_HashCode))); 138 sizeof(struct GNUNET_HashCode)));
135 RPS_sampler_elem_next(s_elem, &pid0); 139 RPS_sampler_elem_next (s_elem, &pid0);
136 CHECK(0 == memcmp(&hash_code2, 140 CHECK (0 == memcmp (&hash_code2,
137 &s_elem->peer_id_hash, 141 &s_elem->peer_id_hash,
138 sizeof(struct GNUNET_HashCode))); 142 sizeof(struct GNUNET_HashCode)));
139 RPS_sampler_elem_next(s_elem, &pid0); 143 RPS_sampler_elem_next (s_elem, &pid0);
140 CHECK(0 == memcmp(&hash_code2, 144 CHECK (0 == memcmp (&hash_code2,
141 &s_elem->peer_id_hash, 145 &s_elem->peer_id_hash,
142 sizeof(struct GNUNET_HashCode))); 146 sizeof(struct GNUNET_HashCode)));
143 RPS_sampler_elem_next(s_elem, &pid0); 147 RPS_sampler_elem_next (s_elem, &pid0);
144 CHECK(0 == memcmp(&hash_code2, 148 CHECK (0 == memcmp (&hash_code2,
145 &s_elem->peer_id_hash, 149 &s_elem->peer_id_hash,
146 sizeof(struct GNUNET_HashCode))); 150 sizeof(struct GNUNET_HashCode)));
147 RPS_sampler_elem_next(s_elem, &pid1); 151 RPS_sampler_elem_next (s_elem, &pid1);
148 CHECK(0 == memcmp(&hash_code2, 152 CHECK (0 == memcmp (&hash_code2,
149 &s_elem->peer_id_hash, 153 &s_elem->peer_id_hash,
150 sizeof(struct GNUNET_HashCode))); 154 sizeof(struct GNUNET_HashCode)));
151 RPS_sampler_elem_next(s_elem, &pid1); 155 RPS_sampler_elem_next (s_elem, &pid1);
152 CHECK(0 == memcmp(&hash_code2, 156 CHECK (0 == memcmp (&hash_code2,
153 &s_elem->peer_id_hash, 157 &s_elem->peer_id_hash,
154 sizeof(struct GNUNET_HashCode))); 158 sizeof(struct GNUNET_HashCode)));
155 RPS_sampler_elem_next(s_elem, &pid1); 159 RPS_sampler_elem_next (s_elem, &pid1);
156 CHECK(0 == memcmp(&hash_code2, 160 CHECK (0 == memcmp (&hash_code2,
157 &s_elem->peer_id_hash, 161 &s_elem->peer_id_hash,
158 sizeof(struct GNUNET_HashCode))); 162 sizeof(struct GNUNET_HashCode)));
159 163
160 /* Check whether pid stayed the same all the time */ 164 /* Check whether pid stayed the same all the time */
161 if (0 == memcmp(&hash_code, 165 if (0 == memcmp (&hash_code,
162 &hash_code2, 166 &hash_code2,
163 sizeof(struct GNUNET_HashCode))) 167 sizeof(struct GNUNET_HashCode)))
164 { 168 {
165 CHECK(0 == memcmp(&pid0, 169 CHECK (0 == memcmp (&pid0,
166 &s_elem->peer_id, 170 &s_elem->peer_id,
167 sizeof(struct GNUNET_PeerIdentity))); 171 sizeof(struct GNUNET_PeerIdentity)));
168 } 172 }
169 else 173 else
170 { 174 {
171 CHECK(0 == memcmp(&pid1, 175 CHECK (0 == memcmp (&pid1,
172 &s_elem->peer_id, 176 &s_elem->peer_id,
173 sizeof(struct GNUNET_PeerIdentity))); 177 sizeof(struct GNUNET_PeerIdentity)));
174 } 178 }
175 RPS_sampler_elem_destroy(s_elem); 179 RPS_sampler_elem_destroy (s_elem);
176 180
177 /* Check _set() */ 181 /* Check _set() */
178 s_elem = RPS_sampler_elem_create(); 182 s_elem = RPS_sampler_elem_create ();
179 CHECK(NULL != s_elem); 183 CHECK (NULL != s_elem);
180 CHECK(EMPTY == s_elem->is_empty); 184 CHECK (EMPTY == s_elem->is_empty);
181 CHECK(NULL != &s_elem->auth_key); 185 CHECK (NULL != &s_elem->auth_key);
182 auth_key = s_elem->auth_key; 186 auth_key = s_elem->auth_key;
183 memset(&auth_key2, 0, sizeof(auth_key2)); 187 memset (&auth_key2, 0, sizeof(auth_key2));
184 RPS_sampler_elem_set(s_elem, auth_key2); 188 RPS_sampler_elem_set (s_elem, auth_key2);
185 CHECK(0 == memcmp(auth_key2.key, 189 CHECK (0 == memcmp (auth_key2.key,
186 s_elem->auth_key.key, 190 s_elem->auth_key.key,
187 GNUNET_CRYPTO_HASH_LENGTH)); 191 GNUNET_CRYPTO_HASH_LENGTH));
188 RPS_sampler_elem_destroy(s_elem); 192 RPS_sampler_elem_destroy (s_elem);
189 193
190 194
191 /* TODO: deterministic tests (use _set() to set auth_key) */ 195 /* TODO: deterministic tests (use _set() to set auth_key) */
@@ -194,15 +198,15 @@ check()
194 198
195 199
196int 200int
197main(int argc, char *argv[]) 201main (int argc, char *argv[])
198{ 202{
199 (void)argc; 203 (void) argc;
200 (void)argv; 204 (void) argv;
201 205
202 GNUNET_log_setup("test_service_rps_peers", 206 GNUNET_log_setup ("test_service_rps_peers",
203 "WARNING", 207 "WARNING",
204 NULL); 208 NULL);
205 return check(); 209 return check ();
206} 210}
207 211
208/* end of test_service_rps_peers.c */ 212/* 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 31aa8cf0b..5b668efe1 100644
--- a/src/rps/test_service_rps_view.c
+++ b/src/rps/test_service_rps_view.c
@@ -24,12 +24,13 @@
24#include <platform.h> 24#include <platform.h>
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__); \
28#define CHECK(c) { if (!(c)) ABORT (); } 28 View_destroy (view); return 1; }
29#define CHECK(c) { if (! (c)) ABORT (); }
29 30
30 31
31static int 32static int
32check() 33check ()
33{ 34{
34 struct View *view; 35 struct View *view;
35 struct GNUNET_PeerIdentity k1; 36 struct GNUNET_PeerIdentity k1;
@@ -37,107 +38,107 @@ check()
37 const struct GNUNET_PeerIdentity *array; 38 const struct GNUNET_PeerIdentity *array;
38 unsigned int j; 39 unsigned int j;
39 40
40 view = View_create(3); 41 view = View_create (3);
41 memset(&k1, 0, sizeof(k1)); 42 memset (&k1, 0, sizeof(k1));
42 memset(&k2, 1, sizeof(k2)); 43 memset (&k2, 1, sizeof(k2));
43 CHECK(GNUNET_NO == View_contains_peer(view, &k1)); 44 CHECK (GNUNET_NO == View_contains_peer (view, &k1));
44 CHECK(GNUNET_NO == View_contains_peer(view, &k2)); 45 CHECK (GNUNET_NO == View_contains_peer (view, &k2));
45 CHECK(GNUNET_NO == View_remove_peer(view, &k1)); 46 CHECK (GNUNET_NO == View_remove_peer (view, &k1));
46 CHECK(GNUNET_NO == View_remove_peer(view, &k2)); 47 CHECK (GNUNET_NO == View_remove_peer (view, &k2));
47 CHECK(NULL == View_get_peer_by_index(view, 0)); 48 CHECK (NULL == View_get_peer_by_index (view, 0));
48 CHECK(NULL == View_get_peer_by_index(view, 1)); 49 CHECK (NULL == View_get_peer_by_index (view, 1));
49 View_clear(view); /* See if assertions trigger */ 50 View_clear (view); /* See if assertions trigger */
50 CHECK(0 == View_size(view)); 51 CHECK (0 == View_size (view));
51 52
52 CHECK(GNUNET_OK == View_put(view, &k1)); 53 CHECK (GNUNET_OK == View_put (view, &k1));
53 CHECK(1 == View_size(view)); 54 CHECK (1 == View_size (view));
54 CHECK(GNUNET_NO == View_put(view, &k1)); 55 CHECK (GNUNET_NO == View_put (view, &k1));
55 CHECK(1 == View_size(view)); 56 CHECK (1 == View_size (view));
56 CHECK(GNUNET_YES == View_contains_peer(view, &k1)); 57 CHECK (GNUNET_YES == View_contains_peer (view, &k1));
57 CHECK(GNUNET_OK == View_remove_peer(view, &k1)); 58 CHECK (GNUNET_OK == View_remove_peer (view, &k1));
58 CHECK(0 == View_size(view)); 59 CHECK (0 == View_size (view));
59 CHECK(GNUNET_NO == View_contains_peer(view, &k1)); 60 CHECK (GNUNET_NO == View_contains_peer (view, &k1));
60 CHECK(GNUNET_NO == View_contains_peer(view, &k2)); 61 CHECK (GNUNET_NO == View_contains_peer (view, &k2));
61 62
62 CHECK(GNUNET_OK == View_put(view, &k1)); 63 CHECK (GNUNET_OK == View_put (view, &k1));
63 CHECK(1 == View_size(view)); 64 CHECK (1 == View_size (view));
64 for (j = 0; j < 16; j++) 65 for (j = 0; j < 16; j++)
65 { 66 {
66 CHECK(GNUNET_NO == View_put(view, &k1)); 67 CHECK (GNUNET_NO == View_put (view, &k1));
67 } 68 }
68 CHECK(1 == View_size(view)); 69 CHECK (1 == View_size (view));
69 CHECK(GNUNET_OK == View_put(view, &k2)); 70 CHECK (GNUNET_OK == View_put (view, &k2));
70 CHECK(2 == View_size(view)); 71 CHECK (2 == View_size (view));
71 for (j = 0; j < 16; j++) 72 for (j = 0; j < 16; j++)
72 { 73 {
73 CHECK(GNUNET_NO == View_put(view, &k2)); 74 CHECK (GNUNET_NO == View_put (view, &k2));
74 } 75 }
75 CHECK(2 == View_size(view)); 76 CHECK (2 == View_size (view));
76 77
77 /* iterate */ 78 /* iterate */
78 for (j = 0; j < View_size(view); j++) 79 for (j = 0; j < View_size (view); j++)
79 { 80 {
80 CHECK(NULL != View_get_peer_by_index(view, j)); 81 CHECK (NULL != View_get_peer_by_index (view, j));
81 } 82 }
82 CHECK((0 == memcmp(View_get_peer_by_index(view, 0), 83 CHECK ((0 == memcmp (View_get_peer_by_index (view, 0),
83 &k1, sizeof(k1)))); 84 &k1, sizeof(k1))));
84 CHECK((0 == memcmp(View_get_peer_by_index(view, 1), 85 CHECK ((0 == memcmp (View_get_peer_by_index (view, 1),
85 &k2, sizeof(k2)))); 86 &k2, sizeof(k2))));
86 CHECK(GNUNET_OK == View_remove_peer(view, &k1)); 87 CHECK (GNUNET_OK == View_remove_peer (view, &k1));
87 CHECK(1 == View_size(view)); 88 CHECK (1 == View_size (view));
88 CHECK(GNUNET_NO == View_contains_peer(view, &k1)); 89 CHECK (GNUNET_NO == View_contains_peer (view, &k1));
89 CHECK(GNUNET_YES == View_contains_peer(view, &k2)); 90 CHECK (GNUNET_YES == View_contains_peer (view, &k2));
90 CHECK(NULL != View_get_peer_by_index(view, 0)); 91 CHECK (NULL != View_get_peer_by_index (view, 0));
91 CHECK(NULL == View_get_peer_by_index(view, 1)); 92 CHECK (NULL == View_get_peer_by_index (view, 1));
92 93
93 View_clear(view); 94 View_clear (view);
94 CHECK(0 == View_size(view)); 95 CHECK (0 == View_size (view));
95 96
96 CHECK(GNUNET_OK == View_put(view, &k1)); 97 CHECK (GNUNET_OK == View_put (view, &k1));
97 CHECK(1 == View_size(view)); 98 CHECK (1 == View_size (view));
98 CHECK(GNUNET_YES == View_contains_peer(view, &k1)); 99 CHECK (GNUNET_YES == View_contains_peer (view, &k1));
99 CHECK(GNUNET_OK == View_put(view, &k2)); 100 CHECK (GNUNET_OK == View_put (view, &k2));
100 CHECK(2 == View_size(view)); 101 CHECK (2 == View_size (view));
101 CHECK(GNUNET_YES == View_contains_peer(view, &k2)); 102 CHECK (GNUNET_YES == View_contains_peer (view, &k2));
102 array = View_get_as_array(view); 103 array = View_get_as_array (view);
103 CHECK(0 == memcmp(&array[0], &k1, sizeof(k1))); 104 CHECK (0 == memcmp (&array[0], &k1, sizeof(k1)));
104 CHECK(0 == memcmp(&array[1], &k2, sizeof(k2))); 105 CHECK (0 == memcmp (&array[1], &k2, sizeof(k2)));
105 View_clear(view); 106 View_clear (view);
106 CHECK(0 == View_size(view)); 107 CHECK (0 == View_size (view));
107 108
108 /*View_change_len () */ 109 /*View_change_len () */
109 CHECK(GNUNET_OK == View_put(view, &k1)); 110 CHECK (GNUNET_OK == View_put (view, &k1));
110 CHECK(GNUNET_OK == View_put(view, &k2)); 111 CHECK (GNUNET_OK == View_put (view, &k2));
111 CHECK(2 == View_size(view)); 112 CHECK (2 == View_size (view));
112 View_change_len(view, 4); 113 View_change_len (view, 4);
113 CHECK(2 == View_size(view)); 114 CHECK (2 == View_size (view));
114 CHECK(GNUNET_YES == View_contains_peer(view, &k1)); 115 CHECK (GNUNET_YES == View_contains_peer (view, &k1));
115 CHECK(GNUNET_YES == View_contains_peer(view, &k2)); 116 CHECK (GNUNET_YES == View_contains_peer (view, &k2));
116 array = View_get_as_array(view); 117 array = View_get_as_array (view);
117 CHECK(0 == memcmp(&array[0], &k1, sizeof(k1))); 118 CHECK (0 == memcmp (&array[0], &k1, sizeof(k1)));
118 CHECK(0 == memcmp(&array[1], &k2, sizeof(k2))); 119 CHECK (0 == memcmp (&array[1], &k2, sizeof(k2)));
119 View_change_len(view, 1); 120 View_change_len (view, 1);
120 CHECK(1 == View_size(view)); 121 CHECK (1 == View_size (view));
121 CHECK(GNUNET_YES == View_contains_peer(view, &k1)); 122 CHECK (GNUNET_YES == View_contains_peer (view, &k1));
122 CHECK(GNUNET_NO == View_contains_peer(view, &k2)); 123 CHECK (GNUNET_NO == View_contains_peer (view, &k2));
123 array = View_get_as_array(view); 124 array = View_get_as_array (view);
124 CHECK(0 == memcmp(&array[0], &k1, sizeof(k1))); 125 CHECK (0 == memcmp (&array[0], &k1, sizeof(k1)));
125 View_clear(view); 126 View_clear (view);
126 CHECK(0 == View_size(view)); 127 CHECK (0 == View_size (view));
127 128
128 View_destroy(view); 129 View_destroy (view);
129 130
130 return 0; 131 return 0;
131} 132}
132 133
133 134
134int 135int
135main() 136main ()
136{ 137{
137 GNUNET_log_setup("test_service_rps_peers", 138 GNUNET_log_setup ("test_service_rps_peers",
138 "WARNING", 139 "WARNING",
139 NULL); 140 NULL);
140 return check(); 141 return check ();
141} 142}
142 143
143/* end of test_service_rps_view.c */ 144/* end of test_service_rps_view.c */