test_core_quota_compliance.c 21 KB

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