diff options
Diffstat (limited to 'src/core/test_core_quota_compliance.c')
-rw-r--r-- | src/core/test_core_quota_compliance.c | 779 |
1 files changed, 0 insertions, 779 deletions
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c deleted file mode 100644 index cf2da3d97..000000000 --- a/src/core/test_core_quota_compliance.c +++ /dev/null | |||
@@ -1,779 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009, 2010, 2015, 2016 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @file core/test_core_quota_compliance.c | ||
22 | * @brief testcase for core_api.c focusing quota compliance on core level | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "gnunet_arm_service.h" | ||
27 | #include "gnunet_core_service.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_ats_service.h" | ||
30 | #include "gnunet_transport_service.h" | ||
31 | #include "gnunet_transport_hello_service.h" | ||
32 | #include "gnunet_statistics_service.h" | ||
33 | |||
34 | |||
35 | #define SYMMETRIC 0 | ||
36 | #define ASYMMETRIC_SEND_LIMITED 1 | ||
37 | #define ASYMMETRIC_RECV_LIMITED 2 | ||
38 | |||
39 | /** | ||
40 | * Note that this value must not significantly exceed | ||
41 | * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise | ||
42 | * messages may be dropped even for a reliable transport. | ||
43 | */ | ||
44 | #define TOTAL_MSGS (60000 * 10) | ||
45 | |||
46 | /** | ||
47 | * How long until we give up on transmitting the message? | ||
48 | */ | ||
49 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) | ||
50 | |||
51 | /** | ||
52 | * What delay do we request from the core service for transmission? | ||
53 | */ | ||
54 | #define FAST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ | ||
55 | 150) | ||
56 | |||
57 | #define MTYPE 12345 | ||
58 | #define MESSAGESIZE (1024 - 8) | ||
59 | #define MEASUREMENT_LENGTH GNUNET_TIME_relative_multiply ( \ | ||
60 | GNUNET_TIME_UNIT_SECONDS, 30) | ||
61 | |||
62 | static unsigned long long total_bytes_sent; | ||
63 | static unsigned long long total_bytes_recv; | ||
64 | |||
65 | static struct GNUNET_TIME_Absolute start_time; | ||
66 | |||
67 | static struct GNUNET_SCHEDULER_Task *err_task; | ||
68 | |||
69 | static struct GNUNET_SCHEDULER_Task *measure_task; | ||
70 | |||
71 | |||
72 | struct PeerContext | ||
73 | { | ||
74 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
75 | struct GNUNET_CORE_Handle *ch; | ||
76 | struct GNUNET_MQ_Handle *mq; | ||
77 | struct GNUNET_TRANSPORT_OfferHelloHandle *oh; | ||
78 | struct GNUNET_PeerIdentity id; | ||
79 | struct GNUNET_MessageHeader *hello; | ||
80 | struct GNUNET_STATISTICS_Handle *stats; | ||
81 | struct GNUNET_TRANSPORT_HelloGetHandle *ghh; | ||
82 | struct GNUNET_ATS_ConnectivityHandle *ats; | ||
83 | struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; | ||
84 | int connect_status; | ||
85 | struct GNUNET_OS_Process *arm_proc; | ||
86 | }; | ||
87 | |||
88 | static struct PeerContext p1; | ||
89 | static struct PeerContext p2; | ||
90 | |||
91 | static unsigned long long current_quota_p1_in; | ||
92 | static unsigned long long current_quota_p1_out; | ||
93 | static unsigned long long current_quota_p2_in; | ||
94 | static unsigned long long current_quota_p2_out; | ||
95 | |||
96 | static int ok; | ||
97 | static int test; | ||
98 | static int32_t tr_n; | ||
99 | |||
100 | static int running; | ||
101 | |||
102 | |||
103 | #if VERBOSE | ||
104 | #define OKPP do { ok++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, \ | ||
105 | "Now at stage %u at %s:%u\n", ok, __FILE__, \ | ||
106 | __LINE__); } while (0) | ||
107 | #else | ||
108 | #define OKPP do { ok++; } while (0) | ||
109 | #endif | ||
110 | |||
111 | struct TestMessage | ||
112 | { | ||
113 | struct GNUNET_MessageHeader header; | ||
114 | uint32_t num GNUNET_PACKED; | ||
115 | uint8_t pad[MESSAGESIZE]; | ||
116 | }; | ||
117 | |||
118 | |||
119 | static void | ||
120 | terminate_peer (struct PeerContext *p) | ||
121 | { | ||
122 | if (NULL != p->ch) | ||
123 | { | ||
124 | GNUNET_CORE_disconnect (p->ch); | ||
125 | p->ch = NULL; | ||
126 | } | ||
127 | if (NULL != p->ghh) | ||
128 | { | ||
129 | GNUNET_TRANSPORT_hello_get_cancel (p->ghh); | ||
130 | p->ghh = NULL; | ||
131 | } | ||
132 | if (NULL != p->oh) | ||
133 | { | ||
134 | GNUNET_TRANSPORT_offer_hello_cancel (p->oh); | ||
135 | p->oh = NULL; | ||
136 | } | ||
137 | if (NULL != p->ats_sh) | ||
138 | { | ||
139 | GNUNET_ATS_connectivity_suggest_cancel (p->ats_sh); | ||
140 | p->ats_sh = NULL; | ||
141 | } | ||
142 | if (NULL != p->ats) | ||
143 | { | ||
144 | GNUNET_ATS_connectivity_done (p->ats); | ||
145 | p->ats = NULL; | ||
146 | } | ||
147 | if (NULL != p->stats) | ||
148 | { | ||
149 | GNUNET_STATISTICS_destroy (p->stats, GNUNET_NO); | ||
150 | p->stats = NULL; | ||
151 | } | ||
152 | if (NULL != p->hello) | ||
153 | { | ||
154 | GNUNET_free (p->hello); | ||
155 | p->hello = NULL; | ||
156 | } | ||
157 | } | ||
158 | |||
159 | |||
160 | static void | ||
161 | shutdown_task (void *cls) | ||
162 | { | ||
163 | if (NULL != err_task) | ||
164 | { | ||
165 | GNUNET_SCHEDULER_cancel (err_task); | ||
166 | err_task = NULL; | ||
167 | } | ||
168 | if (NULL != measure_task) | ||
169 | { | ||
170 | GNUNET_SCHEDULER_cancel (measure_task); | ||
171 | measure_task = NULL; | ||
172 | } | ||
173 | terminate_peer (&p1); | ||
174 | terminate_peer (&p2); | ||
175 | } | ||
176 | |||
177 | |||
178 | static void | ||
179 | terminate_task_error (void *cls) | ||
180 | { | ||
181 | err_task = NULL; | ||
182 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
183 | "Testcase failed (timeout)!\n"); | ||
184 | GNUNET_SCHEDULER_shutdown (); | ||
185 | ok = 42; | ||
186 | } | ||
187 | |||
188 | |||
189 | /** | ||
190 | * Callback function to process statistic values. | ||
191 | * | ||
192 | * @param cls closure | ||
193 | * @param subsystem name of subsystem that created the statistic | ||
194 | * @param name the name of the datum | ||
195 | * @param value the current value | ||
196 | * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not | ||
197 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | ||
198 | */ | ||
199 | static int | ||
200 | print_stat (void *cls, | ||
201 | const char *subsystem, | ||
202 | const char *name, | ||
203 | uint64_t value, | ||
204 | int is_persistent) | ||
205 | { | ||
206 | if (cls == &p1) | ||
207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
208 | "Peer1 %50s = %12llu\n", | ||
209 | name, | ||
210 | (unsigned long long) value); | ||
211 | if (cls == &p2) | ||
212 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
213 | "Peer2 %50s = %12llu\n", | ||
214 | name, | ||
215 | (unsigned long long) value); | ||
216 | return GNUNET_OK; | ||
217 | } | ||
218 | |||
219 | |||
220 | static void | ||
221 | measurement_stop (void *cls) | ||
222 | { | ||
223 | unsigned long long delta; | ||
224 | unsigned long long throughput_out; | ||
225 | unsigned long long throughput_in; | ||
226 | unsigned long long max_quota_in; | ||
227 | unsigned long long max_quota_out; | ||
228 | unsigned long long quota_delta; | ||
229 | enum GNUNET_ErrorType kind = GNUNET_ERROR_TYPE_DEBUG; | ||
230 | |||
231 | measure_task = NULL; | ||
232 | fprintf (stdout, "%s", "\n"); | ||
233 | running = GNUNET_NO; | ||
234 | |||
235 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; | ||
236 | if (0 == delta) | ||
237 | delta = 1; | ||
238 | throughput_out = total_bytes_sent * 1000000LL / delta; /* convert to bytes/s */ | ||
239 | throughput_in = total_bytes_recv * 1000000LL / delta; /* convert to bytes/s */ | ||
240 | |||
241 | max_quota_in = GNUNET_MIN (current_quota_p1_in, current_quota_p2_in); | ||
242 | max_quota_out = GNUNET_MIN (current_quota_p1_out, current_quota_p2_out); | ||
243 | if (max_quota_out < max_quota_in) | ||
244 | quota_delta = max_quota_in / 3; | ||
245 | else | ||
246 | quota_delta = max_quota_out / 3; | ||
247 | |||
248 | if ((throughput_out > (max_quota_out + quota_delta)) || | ||
249 | (throughput_in > (max_quota_in + quota_delta))) | ||
250 | ok = 1; /* fail */ | ||
251 | else | ||
252 | ok = 0; /* pass */ | ||
253 | GNUNET_STATISTICS_get (p1.stats, | ||
254 | "core", | ||
255 | "# discarded CORE_SEND requests", | ||
256 | NULL, | ||
257 | &print_stat, | ||
258 | &p1); | ||
259 | GNUNET_STATISTICS_get (p1.stats, | ||
260 | "core", | ||
261 | "# discarded CORE_SEND request bytes", | ||
262 | NULL, | ||
263 | &print_stat, | ||
264 | &p1); | ||
265 | GNUNET_STATISTICS_get (p1.stats, | ||
266 | "core", | ||
267 | "# discarded lower priority CORE_SEND requests", | ||
268 | NULL, | ||
269 | &print_stat, | ||
270 | NULL); | ||
271 | GNUNET_STATISTICS_get (p1.stats, | ||
272 | "core", | ||
273 | "# discarded lower priority CORE_SEND request bytes", | ||
274 | NULL, | ||
275 | &print_stat, | ||
276 | &p1); | ||
277 | GNUNET_STATISTICS_get (p2.stats, | ||
278 | "core", | ||
279 | "# discarded CORE_SEND requests", | ||
280 | NULL, | ||
281 | &print_stat, | ||
282 | &p2); | ||
283 | |||
284 | GNUNET_STATISTICS_get (p2.stats, | ||
285 | "core", | ||
286 | "# discarded CORE_SEND request bytes", | ||
287 | NULL, | ||
288 | &print_stat, | ||
289 | &p2); | ||
290 | GNUNET_STATISTICS_get (p2.stats, | ||
291 | "core", | ||
292 | "# discarded lower priority CORE_SEND requests", | ||
293 | NULL, | ||
294 | &print_stat, | ||
295 | &p2); | ||
296 | GNUNET_STATISTICS_get (p2.stats, | ||
297 | "core", | ||
298 | "# discarded lower priority CORE_SEND request bytes", | ||
299 | NULL, | ||
300 | &print_stat, | ||
301 | &p2); | ||
302 | |||
303 | if (ok != 0) | ||
304 | kind = GNUNET_ERROR_TYPE_ERROR; | ||
305 | switch (test) | ||
306 | { | ||
307 | case SYMMETRIC: | ||
308 | GNUNET_log (kind, | ||
309 | "Core quota compliance test with symmetric quotas: %s\n", | ||
310 | (0 == ok) ? "PASSED" : "FAILED"); | ||
311 | break; | ||
312 | |||
313 | case ASYMMETRIC_SEND_LIMITED: | ||
314 | GNUNET_log (kind, | ||
315 | "Core quota compliance test with limited sender quota: %s\n", | ||
316 | (0 == ok) ? "PASSED" : "FAILED"); | ||
317 | break; | ||
318 | |||
319 | case ASYMMETRIC_RECV_LIMITED: | ||
320 | GNUNET_log (kind, | ||
321 | "Core quota compliance test with limited receiver quota: %s\n", | ||
322 | (0 == ok) ? "PASSED" : "FAILED"); | ||
323 | break; | ||
324 | } | ||
325 | ; | ||
326 | GNUNET_log (kind, | ||
327 | "Peer 1 send rate: %llu b/s (%llu bytes in %llu ms)\n", | ||
328 | throughput_out, | ||
329 | total_bytes_sent, | ||
330 | delta); | ||
331 | GNUNET_log (kind, | ||
332 | "Peer 1 send quota: %llu b/s\n", | ||
333 | current_quota_p1_out); | ||
334 | GNUNET_log (kind, | ||
335 | "Peer 2 receive rate: %llu b/s (%llu bytes in %llu ms)\n", | ||
336 | throughput_in, | ||
337 | total_bytes_recv, | ||
338 | delta); | ||
339 | GNUNET_log (kind, | ||
340 | "Peer 2 receive quota: %llu b/s\n", | ||
341 | current_quota_p2_in); | ||
342 | /* | ||
343 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound quota allowed: %llu b/s\n",max_quota_in ); | ||
344 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu b/s\n",max_quota_out); | ||
345 | */ | ||
346 | GNUNET_SCHEDULER_shutdown (); | ||
347 | } | ||
348 | |||
349 | |||
350 | static void | ||
351 | do_transmit (void *cls) | ||
352 | { | ||
353 | struct TestMessage *hdr; | ||
354 | struct GNUNET_MQ_Envelope *env; | ||
355 | |||
356 | env = GNUNET_MQ_msg (hdr, | ||
357 | MTYPE); | ||
358 | hdr->num = htonl (tr_n); | ||
359 | memset (&hdr->pad, | ||
360 | tr_n, | ||
361 | MESSAGESIZE); | ||
362 | tr_n++; | ||
363 | GNUNET_SCHEDULER_cancel (err_task); | ||
364 | err_task = | ||
365 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
366 | &terminate_task_error, | ||
367 | NULL); | ||
368 | total_bytes_sent += sizeof(struct TestMessage); | ||
369 | GNUNET_MQ_send (p1.mq, | ||
370 | env); | ||
371 | } | ||
372 | |||
373 | |||
374 | static void * | ||
375 | connect_notify (void *cls, | ||
376 | const struct GNUNET_PeerIdentity *peer, | ||
377 | struct GNUNET_MQ_Handle *mq) | ||
378 | { | ||
379 | struct PeerContext *pc = cls; | ||
380 | |||
381 | if (0 == memcmp (&pc->id, | ||
382 | peer, | ||
383 | sizeof(struct GNUNET_PeerIdentity))) | ||
384 | return NULL; /* loopback */ | ||
385 | GNUNET_assert (0 == pc->connect_status); | ||
386 | pc->connect_status = 1; | ||
387 | pc->mq = mq; | ||
388 | if (pc == &p1) | ||
389 | { | ||
390 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
391 | "Encrypted connection established to peer `%s'\n", | ||
392 | GNUNET_i2s (peer)); | ||
393 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
394 | "Asking core (1) for transmission to peer `%s'\n", | ||
395 | GNUNET_i2s (&p2.id)); | ||
396 | GNUNET_SCHEDULER_cancel (err_task); | ||
397 | err_task = | ||
398 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
399 | &terminate_task_error, | ||
400 | NULL); | ||
401 | start_time = GNUNET_TIME_absolute_get (); | ||
402 | running = GNUNET_YES; | ||
403 | measure_task = | ||
404 | GNUNET_SCHEDULER_add_delayed (MEASUREMENT_LENGTH, | ||
405 | &measurement_stop, | ||
406 | NULL); | ||
407 | do_transmit (NULL); | ||
408 | } | ||
409 | return pc; | ||
410 | } | ||
411 | |||
412 | |||
413 | static void | ||
414 | disconnect_notify (void *cls, | ||
415 | const struct GNUNET_PeerIdentity *peer, | ||
416 | void *internal_cls) | ||
417 | { | ||
418 | struct PeerContext *pc = cls; | ||
419 | |||
420 | if (NULL == internal_cls) | ||
421 | return; /* loopback */ | ||
422 | pc->connect_status = 0; | ||
423 | pc->mq = NULL; | ||
424 | if (NULL != measure_task) | ||
425 | { | ||
426 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
427 | "Measurement aborted due to disconnect!\n"); | ||
428 | GNUNET_SCHEDULER_cancel (measure_task); | ||
429 | measure_task = NULL; | ||
430 | } | ||
431 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
432 | "Encrypted connection to `%s' cut\n", | ||
433 | GNUNET_i2s (peer)); | ||
434 | } | ||
435 | |||
436 | |||
437 | static void | ||
438 | handle_test (void *cls, | ||
439 | const struct TestMessage *hdr) | ||
440 | { | ||
441 | static int n; | ||
442 | |||
443 | total_bytes_recv += sizeof(struct TestMessage); | ||
444 | if (ntohl (hdr->num) != n) | ||
445 | { | ||
446 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
447 | "Expected message %u, got message %u\n", | ||
448 | n, | ||
449 | ntohl (hdr->num)); | ||
450 | GNUNET_SCHEDULER_cancel (err_task); | ||
451 | err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, | ||
452 | NULL); | ||
453 | return; | ||
454 | } | ||
455 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
456 | "Got message %u\n", | ||
457 | ntohl (hdr->num)); | ||
458 | n++; | ||
459 | if (0 == (n % 10)) | ||
460 | fprintf (stderr, "%s", "."); | ||
461 | |||
462 | if (GNUNET_YES == running) | ||
463 | do_transmit (NULL); | ||
464 | } | ||
465 | |||
466 | |||
467 | static void | ||
468 | init_notify (void *cls, | ||
469 | const struct GNUNET_PeerIdentity *my_identity) | ||
470 | { | ||
471 | struct PeerContext *p = cls; | ||
472 | struct GNUNET_MQ_MessageHandler handlers[] = { | ||
473 | GNUNET_MQ_hd_fixed_size (test, | ||
474 | MTYPE, | ||
475 | struct TestMessage, | ||
476 | NULL), | ||
477 | GNUNET_MQ_handler_end () | ||
478 | }; | ||
479 | |||
480 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
481 | "Connection to CORE service of `%s' established\n", | ||
482 | GNUNET_i2s (my_identity)); | ||
483 | GNUNET_assert (NULL != my_identity); | ||
484 | p->id = *my_identity; | ||
485 | if (cls == &p1) | ||
486 | { | ||
487 | GNUNET_assert (ok == 2); | ||
488 | OKPP; | ||
489 | /* connect p2 */ | ||
490 | p2.ch = GNUNET_CORE_connect (p2.cfg, | ||
491 | &p2, | ||
492 | &init_notify, | ||
493 | &connect_notify, | ||
494 | &disconnect_notify, | ||
495 | handlers); | ||
496 | } | ||
497 | else | ||
498 | { | ||
499 | GNUNET_assert (ok == 3); | ||
500 | OKPP; | ||
501 | GNUNET_assert (cls == &p2); | ||
502 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
503 | "Asking core (1) to connect to peer `%s' and vice-versa\n", | ||
504 | GNUNET_i2s (&p2.id)); | ||
505 | p1.ats_sh = GNUNET_ATS_connectivity_suggest (p1.ats, | ||
506 | &p2.id, | ||
507 | 1); | ||
508 | p2.ats_sh = GNUNET_ATS_connectivity_suggest (p2.ats, | ||
509 | &p1.id, | ||
510 | 1); | ||
511 | } | ||
512 | } | ||
513 | |||
514 | |||
515 | static void | ||
516 | offer_hello_done (void *cls) | ||
517 | { | ||
518 | struct PeerContext *p = cls; | ||
519 | |||
520 | p->oh = NULL; | ||
521 | } | ||
522 | |||
523 | |||
524 | static void | ||
525 | process_hello (void *cls, | ||
526 | const struct GNUNET_MessageHeader *message) | ||
527 | { | ||
528 | struct PeerContext *p = cls; | ||
529 | |||
530 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
531 | "Received (my) HELLO from transport service\n"); | ||
532 | GNUNET_assert (message != NULL); | ||
533 | p->hello = GNUNET_malloc (ntohs (message->size)); | ||
534 | GNUNET_memcpy (p->hello, message, ntohs (message->size)); | ||
535 | if ((p == &p1) && | ||
536 | (NULL == p2.oh)) | ||
537 | p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, | ||
538 | message, | ||
539 | &offer_hello_done, | ||
540 | &p2); | ||
541 | if ((p == &p2) && | ||
542 | (NULL == p1.oh)) | ||
543 | p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, message, | ||
544 | &offer_hello_done, | ||
545 | &p1); | ||
546 | |||
547 | if ((p == &p1) && | ||
548 | (NULL != p2.hello) && | ||
549 | (NULL == p1.oh)) | ||
550 | p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, | ||
551 | p2.hello, | ||
552 | &offer_hello_done, | ||
553 | &p1); | ||
554 | if ((p == &p2) && | ||
555 | (NULL != p1.hello) && | ||
556 | (NULL == p2.oh)) | ||
557 | p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, | ||
558 | p1.hello, | ||
559 | &offer_hello_done, | ||
560 | &p2); | ||
561 | } | ||
562 | |||
563 | |||
564 | static void | ||
565 | setup_peer (struct PeerContext *p, | ||
566 | const char *cfgname) | ||
567 | { | ||
568 | char *binary; | ||
569 | |||
570 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); | ||
571 | p->cfg = GNUNET_CONFIGURATION_create (); | ||
572 | p->arm_proc = | ||
573 | GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_OUT_AND_ERR | ||
574 | | GNUNET_OS_USE_PIPE_CONTROL, | ||
575 | NULL, NULL, NULL, | ||
576 | binary, | ||
577 | "gnunet-service-arm", | ||
578 | "-c", | ||
579 | cfgname, | ||
580 | NULL); | ||
581 | GNUNET_assert (GNUNET_OK == | ||
582 | GNUNET_CONFIGURATION_load (p->cfg, | ||
583 | cfgname)); | ||
584 | p->stats = GNUNET_STATISTICS_create ("core", | ||
585 | p->cfg); | ||
586 | GNUNET_assert (NULL != p->stats); | ||
587 | p->ats = GNUNET_ATS_connectivity_init (p->cfg); | ||
588 | GNUNET_assert (NULL != p->ats); | ||
589 | p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, | ||
590 | GNUNET_TRANSPORT_AC_ANY, | ||
591 | &process_hello, | ||
592 | p); | ||
593 | GNUNET_free (binary); | ||
594 | } | ||
595 | |||
596 | |||
597 | static void | ||
598 | run (void *cls, | ||
599 | char *const *args, | ||
600 | const char *cfgfile, | ||
601 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
602 | { | ||
603 | struct GNUNET_MQ_MessageHandler handlers[] = { | ||
604 | GNUNET_MQ_hd_fixed_size (test, | ||
605 | MTYPE, | ||
606 | struct TestMessage, | ||
607 | NULL), | ||
608 | GNUNET_MQ_handler_end () | ||
609 | }; | ||
610 | |||
611 | GNUNET_assert (ok == 1); | ||
612 | OKPP; | ||
613 | err_task = | ||
614 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
615 | &terminate_task_error, | ||
616 | NULL); | ||
617 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
618 | NULL); | ||
619 | if (test == SYMMETRIC) | ||
620 | { | ||
621 | setup_peer (&p1, | ||
622 | "test_core_quota_peer1.conf"); | ||
623 | setup_peer (&p2, | ||
624 | "test_core_quota_peer2.conf"); | ||
625 | } | ||
626 | else if (test == ASYMMETRIC_SEND_LIMITED) | ||
627 | { | ||
628 | setup_peer (&p1, | ||
629 | "test_core_quota_asymmetric_send_limit_peer1.conf"); | ||
630 | setup_peer (&p2, | ||
631 | "test_core_quota_asymmetric_send_limit_peer2.conf"); | ||
632 | } | ||
633 | else if (test == ASYMMETRIC_RECV_LIMITED) | ||
634 | { | ||
635 | setup_peer (&p1, | ||
636 | "test_core_quota_asymmetric_recv_limited_peer1.conf"); | ||
637 | setup_peer (&p2, | ||
638 | "test_core_quota_asymmetric_recv_limited_peer2.conf"); | ||
639 | } | ||
640 | |||
641 | GNUNET_assert (test != -1); | ||
642 | GNUNET_assert (GNUNET_SYSERR != | ||
643 | GNUNET_CONFIGURATION_get_value_size (p1.cfg, | ||
644 | "ATS", | ||
645 | "WAN_QUOTA_IN", | ||
646 | ¤t_quota_p1_in)); | ||
647 | GNUNET_assert (GNUNET_SYSERR != | ||
648 | GNUNET_CONFIGURATION_get_value_size (p2.cfg, | ||
649 | "ATS", | ||
650 | "WAN_QUOTA_IN", | ||
651 | ¤t_quota_p2_in)); | ||
652 | GNUNET_assert (GNUNET_SYSERR != | ||
653 | GNUNET_CONFIGURATION_get_value_size (p1.cfg, | ||
654 | "ATS", | ||
655 | "WAN_QUOTA_OUT", | ||
656 | ¤t_quota_p1_out)); | ||
657 | GNUNET_assert (GNUNET_SYSERR != | ||
658 | GNUNET_CONFIGURATION_get_value_size (p2.cfg, | ||
659 | "ATS", | ||
660 | "WAN_QUOTA_OUT", | ||
661 | ¤t_quota_p2_out)); | ||
662 | |||
663 | p1.ch = GNUNET_CORE_connect (p1.cfg, | ||
664 | &p1, | ||
665 | &init_notify, | ||
666 | &connect_notify, | ||
667 | &disconnect_notify, | ||
668 | handlers); | ||
669 | } | ||
670 | |||
671 | |||
672 | static void | ||
673 | stop_arm (struct PeerContext *p) | ||
674 | { | ||
675 | if (0 != GNUNET_OS_process_kill (p->arm_proc, | ||
676 | GNUNET_TERM_SIG)) | ||
677 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | ||
678 | "kill"); | ||
679 | if (GNUNET_OK != | ||
680 | GNUNET_OS_process_wait (p->arm_proc)) | ||
681 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | ||
682 | "waitpid"); | ||
683 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
684 | "ARM process %u stopped\n", | ||
685 | GNUNET_OS_process_get_pid (p->arm_proc)); | ||
686 | GNUNET_OS_process_destroy (p->arm_proc); | ||
687 | p->arm_proc = NULL; | ||
688 | GNUNET_CONFIGURATION_destroy (p->cfg); | ||
689 | } | ||
690 | |||
691 | |||
692 | static int | ||
693 | check () | ||
694 | { | ||
695 | char *const argv[] = { | ||
696 | "test-core-quota-compliance", | ||
697 | "-c", | ||
698 | "test_core_api_data.conf", | ||
699 | NULL | ||
700 | }; | ||
701 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
702 | GNUNET_GETOPT_OPTION_END | ||
703 | }; | ||
704 | |||
705 | ok = 1; | ||
706 | GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1, | ||
707 | argv, | ||
708 | "test-core-quota-compliance", | ||
709 | "nohelp", | ||
710 | options, | ||
711 | &run, | ||
712 | &ok); | ||
713 | stop_arm (&p1); | ||
714 | stop_arm (&p2); | ||
715 | return ok; | ||
716 | } | ||
717 | |||
718 | |||
719 | static void | ||
720 | cleanup_directory (int test) | ||
721 | { | ||
722 | switch (test) | ||
723 | { | ||
724 | case SYMMETRIC: | ||
725 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-1/"); | ||
726 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-2/"); | ||
727 | break; | ||
728 | |||
729 | case ASYMMETRIC_SEND_LIMITED: | ||
730 | GNUNET_DISK_directory_remove | ||
731 | ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-1/"); | ||
732 | GNUNET_DISK_directory_remove | ||
733 | ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-2/"); | ||
734 | break; | ||
735 | |||
736 | case ASYMMETRIC_RECV_LIMITED: | ||
737 | GNUNET_DISK_directory_remove | ||
738 | ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-1/"); | ||
739 | GNUNET_DISK_directory_remove | ||
740 | ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-2/"); | ||
741 | break; | ||
742 | } | ||
743 | } | ||
744 | |||
745 | |||
746 | int | ||
747 | main (int argc, | ||
748 | char *argv[]) | ||
749 | { | ||
750 | int ret; | ||
751 | |||
752 | test = -1; | ||
753 | if (NULL != strstr (argv[0], | ||
754 | "_symmetric")) | ||
755 | { | ||
756 | test = SYMMETRIC; | ||
757 | } | ||
758 | else if (NULL != strstr (argv[0], | ||
759 | "_asymmetric_send")) | ||
760 | { | ||
761 | test = ASYMMETRIC_SEND_LIMITED; | ||
762 | } | ||
763 | else if (NULL != strstr (argv[0], | ||
764 | "_asymmetric_recv")) | ||
765 | { | ||
766 | test = ASYMMETRIC_RECV_LIMITED; | ||
767 | } | ||
768 | GNUNET_assert (test != -1); | ||
769 | cleanup_directory (test); | ||
770 | GNUNET_log_setup ("test-core-quota-compliance", | ||
771 | "WARNING", | ||
772 | NULL); | ||
773 | ret = check (); | ||
774 | cleanup_directory (test); | ||
775 | return ret; | ||
776 | } | ||
777 | |||
778 | |||
779 | /* end of test_core_quota_compliance.c */ | ||