diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-26 21:12:56 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-26 21:12:56 +0000 |
commit | 8c2dc7d19810d58f23c43bf900e2fb3eebe06fed (patch) | |
tree | 9173a966e2f51a34d9259a0126484e05d44dcaac /src/core/test_core_quota_compliance.c | |
parent | a89ea716333ad5ad43757a946efc01cb5e95a0c0 (diff) | |
download | gnunet-8c2dc7d19810d58f23c43bf900e2fb3eebe06fed.tar.gz gnunet-8c2dc7d19810d58f23c43bf900e2fb3eebe06fed.zip |
-converting CORE service to new transport MQ API
Diffstat (limited to 'src/core/test_core_quota_compliance.c')
-rw-r--r-- | src/core/test_core_quota_compliance.c | 302 |
1 files changed, 203 insertions, 99 deletions
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c index a0c456cef..04f79b959 100644 --- a/src/core/test_core_quota_compliance.c +++ b/src/core/test_core_quota_compliance.c | |||
@@ -112,7 +112,7 @@ struct TestMessage | |||
112 | static void | 112 | static void |
113 | terminate_peer (struct PeerContext *p) | 113 | terminate_peer (struct PeerContext *p) |
114 | { | 114 | { |
115 | if (p->nth != NULL) | 115 | if (NULL != p->nth) |
116 | { | 116 | { |
117 | GNUNET_CORE_notify_transmit_ready_cancel (p->nth); | 117 | GNUNET_CORE_notify_transmit_ready_cancel (p->nth); |
118 | p->nth = NULL; | 118 | p->nth = NULL; |
@@ -156,9 +156,18 @@ terminate_peer (struct PeerContext *p) | |||
156 | 156 | ||
157 | 157 | ||
158 | static void | 158 | static void |
159 | terminate_task (void *cls) | 159 | shutdown_task (void *cls) |
160 | { | 160 | { |
161 | err_task = NULL; | 161 | if (NULL != err_task) |
162 | { | ||
163 | GNUNET_SCHEDULER_cancel (err_task); | ||
164 | err_task = NULL; | ||
165 | } | ||
166 | if (NULL != measure_task) | ||
167 | { | ||
168 | GNUNET_SCHEDULER_cancel (measure_task); | ||
169 | measure_task = NULL; | ||
170 | } | ||
162 | terminate_peer (&p1); | 171 | terminate_peer (&p1); |
163 | terminate_peer (&p2); | 172 | terminate_peer (&p2); |
164 | } | 173 | } |
@@ -169,15 +178,8 @@ terminate_task_error (void *cls) | |||
169 | { | 178 | { |
170 | err_task = NULL; | 179 | err_task = NULL; |
171 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 180 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
172 | "Testcase failed!\n"); | 181 | "Testcase failed (timeout)!\n"); |
173 | terminate_peer (&p1); | 182 | GNUNET_SCHEDULER_shutdown (); |
174 | terminate_peer (&p2); | ||
175 | //GNUNET_break (0); | ||
176 | if (NULL != measure_task) | ||
177 | { | ||
178 | GNUNET_SCHEDULER_cancel (measure_task); | ||
179 | measure_task = NULL; | ||
180 | } | ||
181 | ok = 42; | 183 | ok = 42; |
182 | } | 184 | } |
183 | 185 | ||
@@ -245,37 +247,63 @@ measurement_stop (void *cls) | |||
245 | ok = 1; /* fail */ | 247 | ok = 1; /* fail */ |
246 | else | 248 | else |
247 | ok = 0; /* pass */ | 249 | ok = 0; /* pass */ |
248 | GNUNET_STATISTICS_get (p1.stats, "core", "# discarded CORE_SEND requests", | 250 | GNUNET_STATISTICS_get (p1.stats, |
249 | NULL, &print_stat, &p1); | 251 | "core", |
250 | 252 | "# discarded CORE_SEND requests", | |
251 | GNUNET_STATISTICS_get (p1.stats, "core", | 253 | NULL, |
254 | &print_stat, | ||
255 | &p1); | ||
256 | GNUNET_STATISTICS_get (p1.stats, | ||
257 | "core", | ||
252 | "# discarded CORE_SEND request bytes", | 258 | "# discarded CORE_SEND request bytes", |
253 | NULL, &print_stat, &p1); | 259 | NULL, |
254 | GNUNET_STATISTICS_get (p1.stats, "core", | 260 | &print_stat, |
261 | &p1); | ||
262 | GNUNET_STATISTICS_get (p1.stats, | ||
263 | "core", | ||
255 | "# discarded lower priority CORE_SEND requests", | 264 | "# discarded lower priority CORE_SEND requests", |
256 | NULL, &print_stat, NULL); | 265 | NULL, |
257 | GNUNET_STATISTICS_get (p1.stats, "core", | 266 | &print_stat, |
267 | NULL); | ||
268 | GNUNET_STATISTICS_get (p1.stats, | ||
269 | "core", | ||
258 | "# discarded lower priority CORE_SEND request bytes", | 270 | "# discarded lower priority CORE_SEND request bytes", |
259 | NULL, &print_stat, &p1); | 271 | NULL, |
260 | GNUNET_STATISTICS_get (p2.stats, "core", "# discarded CORE_SEND requests", | 272 | &print_stat, |
261 | NULL, &print_stat, &p2); | 273 | &p1); |
262 | 274 | GNUNET_STATISTICS_get (p2.stats, | |
263 | GNUNET_STATISTICS_get (p2.stats, "core", | 275 | "core", |
276 | "# discarded CORE_SEND requests", | ||
277 | NULL, | ||
278 | &print_stat, | ||
279 | &p2); | ||
280 | |||
281 | GNUNET_STATISTICS_get (p2.stats, | ||
282 | "core", | ||
264 | "# discarded CORE_SEND request bytes", | 283 | "# discarded CORE_SEND request bytes", |
265 | NULL, &print_stat, &p2); | 284 | NULL, |
266 | GNUNET_STATISTICS_get (p2.stats, "core", | 285 | &print_stat, |
286 | &p2); | ||
287 | GNUNET_STATISTICS_get (p2.stats, | ||
288 | "core", | ||
267 | "# discarded lower priority CORE_SEND requests", | 289 | "# discarded lower priority CORE_SEND requests", |
268 | NULL, &print_stat, &p2); | 290 | NULL, |
269 | GNUNET_STATISTICS_get (p2.stats, "core", | 291 | &print_stat, |
292 | &p2); | ||
293 | GNUNET_STATISTICS_get (p2.stats, | ||
294 | "core", | ||
270 | "# discarded lower priority CORE_SEND request bytes", | 295 | "# discarded lower priority CORE_SEND request bytes", |
271 | NULL, &print_stat, &p2); | 296 | NULL, |
297 | &print_stat, | ||
298 | &p2); | ||
272 | 299 | ||
273 | if (ok != 0) | 300 | if (ok != 0) |
274 | kind = GNUNET_ERROR_TYPE_ERROR; | 301 | kind = GNUNET_ERROR_TYPE_ERROR; |
275 | switch (test) | 302 | switch (test) |
276 | { | 303 | { |
277 | case SYMMETRIC: | 304 | case SYMMETRIC: |
278 | GNUNET_log (kind, "Core quota compliance test with symmetric quotas: %s\n", | 305 | GNUNET_log (kind, |
306 | "Core quota compliance test with symmetric quotas: %s\n", | ||
279 | (0 == ok) ? "PASSED" : "FAILED"); | 307 | (0 == ok) ? "PASSED" : "FAILED"); |
280 | break; | 308 | break; |
281 | case ASYMMETRIC_SEND_LIMITED: | 309 | case ASYMMETRIC_SEND_LIMITED: |
@@ -289,23 +317,34 @@ measurement_stop (void *cls) | |||
289 | (0 == ok) ? "PASSED" : "FAILED"); | 317 | (0 == ok) ? "PASSED" : "FAILED"); |
290 | break; | 318 | break; |
291 | }; | 319 | }; |
292 | GNUNET_log (kind, "Peer 1 send rate: %llu b/s (%llu bytes in %llu ms)\n", | 320 | GNUNET_log (kind, |
293 | throughput_out, total_bytes_sent, delta); | 321 | "Peer 1 send rate: %llu b/s (%llu bytes in %llu ms)\n", |
294 | GNUNET_log (kind, "Peer 1 send quota: %llu b/s\n", current_quota_p1_out); | 322 | throughput_out, |
295 | GNUNET_log (kind, "Peer 2 receive rate: %llu b/s (%llu bytes in %llu ms)\n", | 323 | total_bytes_sent, |
296 | throughput_in, total_bytes_recv, delta); | 324 | delta); |
297 | GNUNET_log (kind, "Peer 2 receive quota: %llu b/s\n", current_quota_p2_in); | 325 | GNUNET_log (kind, |
326 | "Peer 1 send quota: %llu b/s\n", | ||
327 | current_quota_p1_out); | ||
328 | GNUNET_log (kind, | ||
329 | "Peer 2 receive rate: %llu b/s (%llu bytes in %llu ms)\n", | ||
330 | throughput_in, | ||
331 | total_bytes_recv, | ||
332 | delta); | ||
333 | GNUNET_log (kind, | ||
334 | "Peer 2 receive quota: %llu b/s\n", | ||
335 | current_quota_p2_in); | ||
298 | /* | 336 | /* |
299 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound quota allowed: %llu b/s\n",max_quota_in ); | 337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound quota allowed: %llu b/s\n",max_quota_in ); |
300 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu b/s\n",max_quota_out); | 338 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu b/s\n",max_quota_out); |
301 | */ | 339 | */ |
302 | GNUNET_SCHEDULER_cancel (err_task); | 340 | GNUNET_SCHEDULER_shutdown (); |
303 | err_task = GNUNET_SCHEDULER_add_now (&terminate_task, NULL); | ||
304 | } | 341 | } |
305 | 342 | ||
306 | 343 | ||
307 | static size_t | 344 | static size_t |
308 | transmit_ready (void *cls, size_t size, void *buf) | 345 | transmit_ready (void *cls, |
346 | size_t size, | ||
347 | void *buf) | ||
309 | { | 348 | { |
310 | char *cbuf = buf; | 349 | char *cbuf = buf; |
311 | struct TestMessage hdr; | 350 | struct TestMessage hdr; |
@@ -313,43 +352,56 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
313 | 352 | ||
314 | p1.nth = NULL; | 353 | p1.nth = NULL; |
315 | GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE); | 354 | GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE); |
316 | if (buf == NULL) | 355 | if (NULL == buf) |
317 | { | 356 | { |
318 | if ((p1.ch != NULL) && (p1.connect_status == 1)) | 357 | if ( (NULL != p1.ch) && |
358 | (1 == p1.connect_status) ) | ||
319 | GNUNET_break (NULL != | 359 | GNUNET_break (NULL != |
320 | (p1.nth = | 360 | (p1.nth = |
321 | GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, | 361 | GNUNET_CORE_notify_transmit_ready (p1.ch, |
362 | GNUNET_NO, | ||
322 | GNUNET_CORE_PRIO_BEST_EFFORT, | 363 | GNUNET_CORE_PRIO_BEST_EFFORT, |
323 | FAST_TIMEOUT, &p2.id, | 364 | FAST_TIMEOUT, |
365 | &p2.id, | ||
324 | MESSAGESIZE, | 366 | MESSAGESIZE, |
325 | &transmit_ready, &p1))); | 367 | &transmit_ready, |
368 | &p1))); | ||
326 | return 0; | 369 | return 0; |
327 | } | 370 | } |
328 | GNUNET_assert (tr_n < TOTAL_MSGS); | 371 | GNUNET_assert (tr_n < TOTAL_MSGS); |
329 | ret = 0; | 372 | ret = 0; |
330 | GNUNET_assert (size >= MESSAGESIZE); | 373 | GNUNET_assert (size >= MESSAGESIZE); |
331 | GNUNET_assert (buf != NULL); | 374 | GNUNET_assert (NULL != buf); |
332 | cbuf = buf; | 375 | cbuf = buf; |
333 | do | 376 | do |
334 | { | 377 | { |
335 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 378 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
336 | "Sending message %u of size %u at offset %u\n", tr_n, | 379 | "Sending message %u of size %u at offset %u\n", |
337 | MESSAGESIZE, ret); | 380 | tr_n, |
381 | MESSAGESIZE, | ||
382 | ret); | ||
338 | hdr.header.size = htons (MESSAGESIZE); | 383 | hdr.header.size = htons (MESSAGESIZE); |
339 | hdr.header.type = htons (MTYPE); | 384 | hdr.header.type = htons (MTYPE); |
340 | hdr.num = htonl (tr_n); | 385 | hdr.num = htonl (tr_n); |
341 | GNUNET_memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); | 386 | GNUNET_memcpy (&cbuf[ret], |
387 | &hdr, | ||
388 | sizeof (struct TestMessage)); | ||
342 | ret += sizeof (struct TestMessage); | 389 | ret += sizeof (struct TestMessage); |
343 | memset (&cbuf[ret], tr_n, MESSAGESIZE - sizeof (struct TestMessage)); | 390 | memset (&cbuf[ret], |
391 | tr_n, | ||
392 | MESSAGESIZE - sizeof (struct TestMessage)); | ||
344 | ret += MESSAGESIZE - sizeof (struct TestMessage); | 393 | ret += MESSAGESIZE - sizeof (struct TestMessage); |
345 | tr_n++; | 394 | tr_n++; |
346 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) | 395 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
396 | 16)) | ||
347 | break; /* sometimes pack buffer full, sometimes not */ | 397 | break; /* sometimes pack buffer full, sometimes not */ |
348 | } | 398 | } |
349 | while (size - ret >= MESSAGESIZE); | 399 | while (size - ret >= MESSAGESIZE); |
350 | GNUNET_SCHEDULER_cancel (err_task); | 400 | GNUNET_SCHEDULER_cancel (err_task); |
351 | err_task = | 401 | err_task = |
352 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL); | 402 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
403 | &terminate_task_error, | ||
404 | NULL); | ||
353 | 405 | ||
354 | total_bytes_sent += ret; | 406 | total_bytes_sent += ret; |
355 | return ret; | 407 | return ret; |
@@ -357,48 +409,60 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
357 | 409 | ||
358 | 410 | ||
359 | static void | 411 | static void |
360 | connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) | 412 | connect_notify (void *cls, |
413 | const struct GNUNET_PeerIdentity *peer) | ||
361 | { | 414 | { |
362 | struct PeerContext *pc = cls; | 415 | struct PeerContext *pc = cls; |
363 | 416 | ||
364 | if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) | 417 | if (0 == memcmp (&pc->id, |
418 | peer, | ||
419 | sizeof (struct GNUNET_PeerIdentity))) | ||
365 | return; /* loopback */ | 420 | return; /* loopback */ |
366 | GNUNET_assert (pc->connect_status == 0); | 421 | GNUNET_assert (0 == pc->connect_status); |
367 | pc->connect_status = 1; | 422 | pc->connect_status = 1; |
368 | if (pc == &p1) | 423 | if (pc == &p1) |
369 | { | 424 | { |
370 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 425 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
371 | "Encrypted connection established to peer `%4s'\n", | 426 | "Encrypted connection established to peer `%s'\n", |
372 | GNUNET_i2s (peer)); | 427 | GNUNET_i2s (peer)); |
373 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 428 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
374 | "Asking core (1) for transmission to peer `%4s'\n", | 429 | "Asking core (1) for transmission to peer `%s'\n", |
375 | GNUNET_i2s (&p2.id)); | 430 | GNUNET_i2s (&p2.id)); |
376 | GNUNET_SCHEDULER_cancel (err_task); | 431 | GNUNET_SCHEDULER_cancel (err_task); |
377 | err_task = | 432 | err_task = |
378 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL); | 433 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
434 | &terminate_task_error, | ||
435 | NULL); | ||
379 | start_time = GNUNET_TIME_absolute_get (); | 436 | start_time = GNUNET_TIME_absolute_get (); |
380 | running = GNUNET_YES; | 437 | running = GNUNET_YES; |
381 | measure_task = | 438 | measure_task = |
382 | GNUNET_SCHEDULER_add_delayed (MEASUREMENT_LENGTH, &measurement_stop, | 439 | GNUNET_SCHEDULER_add_delayed (MEASUREMENT_LENGTH, |
440 | &measurement_stop, | ||
383 | NULL); | 441 | NULL); |
384 | 442 | ||
385 | GNUNET_break (NULL != | 443 | GNUNET_break (NULL != |
386 | (p1.nth = | 444 | (p1.nth = |
387 | GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, | 445 | GNUNET_CORE_notify_transmit_ready (p1.ch, |
446 | GNUNET_NO, | ||
388 | GNUNET_CORE_PRIO_BEST_EFFORT, | 447 | GNUNET_CORE_PRIO_BEST_EFFORT, |
389 | TIMEOUT, &p2.id, | 448 | TIMEOUT, |
449 | &p2.id, | ||
390 | MESSAGESIZE, | 450 | MESSAGESIZE, |
391 | &transmit_ready, &p1))); | 451 | &transmit_ready, |
452 | &p1))); | ||
392 | } | 453 | } |
393 | } | 454 | } |
394 | 455 | ||
395 | 456 | ||
396 | static void | 457 | static void |
397 | disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) | 458 | disconnect_notify (void *cls, |
459 | const struct GNUNET_PeerIdentity *peer) | ||
398 | { | 460 | { |
399 | struct PeerContext *pc = cls; | 461 | struct PeerContext *pc = cls; |
400 | 462 | ||
401 | if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) | 463 | if (0 == memcmp (&pc->id, |
464 | peer, | ||
465 | sizeof (struct GNUNET_PeerIdentity))) | ||
402 | return; /* loopback */ | 466 | return; /* loopback */ |
403 | pc->connect_status = 0; | 467 | pc->connect_status = 0; |
404 | if (NULL != measure_task) | 468 | if (NULL != measure_task) |
@@ -408,12 +472,13 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
408 | GNUNET_SCHEDULER_cancel (measure_task); | 472 | GNUNET_SCHEDULER_cancel (measure_task); |
409 | measure_task = NULL; | 473 | measure_task = NULL; |
410 | } | 474 | } |
411 | if (pc->nth != NULL) | 475 | if (NULL != pc->nth) |
412 | { | 476 | { |
413 | GNUNET_CORE_notify_transmit_ready_cancel (pc->nth); | 477 | GNUNET_CORE_notify_transmit_ready_cancel (pc->nth); |
414 | pc->nth = NULL; | 478 | pc->nth = NULL; |
415 | } | 479 | } |
416 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted connection to `%4s' cut\n", | 480 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
481 | "Encrypted connection to `%s' cut\n", | ||
417 | GNUNET_i2s (peer)); | 482 | GNUNET_i2s (peer)); |
418 | } | 483 | } |
419 | 484 | ||
@@ -424,7 +489,7 @@ inbound_notify (void *cls, | |||
424 | const struct GNUNET_MessageHeader *message) | 489 | const struct GNUNET_MessageHeader *message) |
425 | { | 490 | { |
426 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 491 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
427 | "Core provides inbound data from `%4s' %u.\n", | 492 | "Core provides inbound data from `%s' %u.\n", |
428 | GNUNET_i2s (other), | 493 | GNUNET_i2s (other), |
429 | (unsigned int) ntohs (message->size)); | 494 | (unsigned int) ntohs (message->size)); |
430 | total_bytes_recv += ntohs (message->size); | 495 | total_bytes_recv += ntohs (message->size); |
@@ -438,7 +503,7 @@ outbound_notify (void *cls, | |||
438 | const struct GNUNET_MessageHeader *message) | 503 | const struct GNUNET_MessageHeader *message) |
439 | { | 504 | { |
440 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 505 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
441 | "Core notifies about outbound data for `%4s'.\n", | 506 | "Core notifies about outbound data for `%s'.\n", |
442 | GNUNET_i2s (other)); | 507 | GNUNET_i2s (other)); |
443 | return GNUNET_OK; | 508 | return GNUNET_OK; |
444 | } | 509 | } |
@@ -449,7 +514,8 @@ transmit_ready (void *cls, size_t size, void *buf); | |||
449 | 514 | ||
450 | 515 | ||
451 | static int | 516 | static int |
452 | process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer, | 517 | process_mtype (void *cls, |
518 | const struct GNUNET_PeerIdentity *peer, | ||
453 | const struct GNUNET_MessageHeader *message) | 519 | const struct GNUNET_MessageHeader *message) |
454 | { | 520 | { |
455 | static int n; | 521 | static int n; |
@@ -462,34 +528,46 @@ process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
462 | { | 528 | { |
463 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 529 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
464 | "Expected message %u of size %u, got %u bytes of message %u\n", | 530 | "Expected message %u of size %u, got %u bytes of message %u\n", |
465 | n, MESSAGESIZE, ntohs (message->size), ntohl (hdr->num)); | 531 | n, |
532 | MESSAGESIZE, | ||
533 | ntohs (message->size), | ||
534 | ntohl (hdr->num)); | ||
466 | GNUNET_SCHEDULER_cancel (err_task); | 535 | GNUNET_SCHEDULER_cancel (err_task); |
467 | err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL); | 536 | err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, |
537 | NULL); | ||
468 | return GNUNET_SYSERR; | 538 | return GNUNET_SYSERR; |
469 | } | 539 | } |
470 | if (ntohl (hdr->num) != n) | 540 | if (ntohl (hdr->num) != n) |
471 | { | 541 | { |
472 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 542 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
473 | "Expected message %u of size %u, got %u bytes of message %u\n", | 543 | "Expected message %u of size %u, got %u bytes of message %u\n", |
474 | n, MESSAGESIZE, ntohs (message->size), ntohl (hdr->num)); | 544 | n, |
545 | MESSAGESIZE, | ||
546 | ntohs (message->size), | ||
547 | ntohl (hdr->num)); | ||
475 | GNUNET_SCHEDULER_cancel (err_task); | 548 | GNUNET_SCHEDULER_cancel (err_task); |
476 | err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL); | 549 | err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, |
550 | NULL); | ||
477 | return GNUNET_SYSERR; | 551 | return GNUNET_SYSERR; |
478 | } | 552 | } |
479 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got message %u of size %u\n", | 553 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
480 | ntohl (hdr->num), ntohs (message->size)); | 554 | "Got message %u of size %u\n", |
555 | ntohl (hdr->num), | ||
556 | ntohs (message->size)); | ||
481 | n++; | 557 | n++; |
482 | if (0 == (n % 10)) | 558 | if (0 == (n % 10)) |
483 | FPRINTF (stderr, "%s", "."); | 559 | FPRINTF (stderr, "%s", "."); |
484 | 560 | ||
485 | 561 | if (GNUNET_YES == running) | |
486 | if (running == GNUNET_YES) | ||
487 | GNUNET_break (NULL != | 562 | GNUNET_break (NULL != |
488 | GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, | 563 | (p1.nth = GNUNET_CORE_notify_transmit_ready (p1.ch, |
489 | GNUNET_CORE_PRIO_BEST_EFFORT, | 564 | GNUNET_NO, |
490 | FAST_TIMEOUT, &p2.id, | 565 | GNUNET_CORE_PRIO_BEST_EFFORT, |
491 | MESSAGESIZE, | 566 | FAST_TIMEOUT, |
492 | &transmit_ready, &p1)); | 567 | &p2.id, |
568 | MESSAGESIZE, | ||
569 | &transmit_ready, | ||
570 | &p1))); | ||
493 | return GNUNET_OK; | 571 | return GNUNET_OK; |
494 | } | 572 | } |
495 | 573 | ||
@@ -518,9 +596,16 @@ init_notify (void *cls, | |||
518 | OKPP; | 596 | OKPP; |
519 | /* connect p2 */ | 597 | /* connect p2 */ |
520 | p2.ch = | 598 | p2.ch = |
521 | GNUNET_CORE_connect (p2.cfg, &p2, &init_notify, &connect_notify, | 599 | GNUNET_CORE_connect (p2.cfg, |
522 | &disconnect_notify, &inbound_notify, GNUNET_YES, | 600 | &p2, |
523 | &outbound_notify, GNUNET_YES, handlers); | 601 | &init_notify, |
602 | &connect_notify, | ||
603 | &disconnect_notify, | ||
604 | &inbound_notify, | ||
605 | GNUNET_YES, | ||
606 | &outbound_notify, | ||
607 | GNUNET_YES, | ||
608 | handlers); | ||
524 | } | 609 | } |
525 | else | 610 | else |
526 | { | 611 | { |
@@ -550,12 +635,13 @@ offer_hello_done (void *cls) | |||
550 | 635 | ||
551 | 636 | ||
552 | static void | 637 | static void |
553 | process_hello (void *cls, const struct GNUNET_MessageHeader *message) | 638 | process_hello (void *cls, |
639 | const struct GNUNET_MessageHeader *message) | ||
554 | { | 640 | { |
555 | struct PeerContext *p = cls; | 641 | struct PeerContext *p = cls; |
556 | 642 | ||
557 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 643 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
558 | "Received (my) `%s' from transport service\n", "HELLO"); | 644 | "Received (my) HELLO from transport service\n"); |
559 | GNUNET_assert (message != NULL); | 645 | GNUNET_assert (message != NULL); |
560 | p->hello = GNUNET_malloc (ntohs (message->size)); | 646 | p->hello = GNUNET_malloc (ntohs (message->size)); |
561 | GNUNET_memcpy (p->hello, message, ntohs (message->size)); | 647 | GNUNET_memcpy (p->hello, message, ntohs (message->size)); |
@@ -583,7 +669,8 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message) | |||
583 | 669 | ||
584 | 670 | ||
585 | static void | 671 | static void |
586 | setup_peer (struct PeerContext *p, const char *cfgname) | 672 | setup_peer (struct PeerContext *p, |
673 | const char *cfgname) | ||
587 | { | 674 | { |
588 | char *binary; | 675 | char *binary; |
589 | 676 | ||
@@ -606,13 +693,19 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
606 | 693 | ||
607 | 694 | ||
608 | static void | 695 | static void |
609 | run (void *cls, char *const *args, const char *cfgfile, | 696 | run (void *cls, |
697 | char *const *args, | ||
698 | const char *cfgfile, | ||
610 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 699 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
611 | { | 700 | { |
612 | GNUNET_assert (ok == 1); | 701 | GNUNET_assert (ok == 1); |
613 | OKPP; | 702 | OKPP; |
614 | err_task = | 703 | err_task = |
615 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL); | 704 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
705 | &terminate_task_error, | ||
706 | NULL); | ||
707 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
708 | NULL); | ||
616 | if (test == SYMMETRIC) | 709 | if (test == SYMMETRIC) |
617 | { | 710 | { |
618 | setup_peer (&p1, "test_core_quota_peer1.conf"); | 711 | setup_peer (&p1, "test_core_quota_peer1.conf"); |
@@ -657,11 +750,16 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
657 | static void | 750 | static void |
658 | stop_arm (struct PeerContext *p) | 751 | stop_arm (struct PeerContext *p) |
659 | { | 752 | { |
660 | if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG)) | 753 | if (0 != GNUNET_OS_process_kill (p->arm_proc, |
661 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 754 | GNUNET_TERM_SIG)) |
662 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) | 755 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
663 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 756 | "kill"); |
664 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", | 757 | if (GNUNET_OK != |
758 | GNUNET_OS_process_wait (p->arm_proc)) | ||
759 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | ||
760 | "waitpid"); | ||
761 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
762 | "ARM process %u stopped\n", | ||
665 | GNUNET_OS_process_get_pid (p->arm_proc)); | 763 | GNUNET_OS_process_get_pid (p->arm_proc)); |
666 | GNUNET_OS_process_destroy (p->arm_proc); | 764 | GNUNET_OS_process_destroy (p->arm_proc); |
667 | p->arm_proc = NULL; | 765 | p->arm_proc = NULL; |
@@ -672,7 +770,8 @@ stop_arm (struct PeerContext *p) | |||
672 | static int | 770 | static int |
673 | check () | 771 | check () |
674 | { | 772 | { |
675 | char *const argv[] = { "test-core-quota-compliance", | 773 | char *const argv[] = { |
774 | "test-core-quota-compliance", | ||
676 | "-c", | 775 | "-c", |
677 | "test_core_api_data.conf", | 776 | "test_core_api_data.conf", |
678 | NULL | 777 | NULL |
@@ -681,8 +780,12 @@ check () | |||
681 | GNUNET_GETOPT_OPTION_END | 780 | GNUNET_GETOPT_OPTION_END |
682 | }; | 781 | }; |
683 | ok = 1; | 782 | ok = 1; |
684 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, | 783 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
685 | "test-core-quota-compliance", "nohelp", options, &run, | 784 | argv, |
785 | "test-core-quota-compliance", | ||
786 | "nohelp", | ||
787 | options, | ||
788 | &run, | ||
686 | &ok); | 789 | &ok); |
687 | stop_arm (&p1); | 790 | stop_arm (&p1); |
688 | stop_arm (&p2); | 791 | stop_arm (&p2); |
@@ -691,7 +794,8 @@ check () | |||
691 | 794 | ||
692 | 795 | ||
693 | int | 796 | int |
694 | main (int argc, char *argv[]) | 797 | main (int argc, |
798 | char *argv[]) | ||
695 | { | 799 | { |
696 | int ret; | 800 | int ret; |
697 | 801 | ||