2 This file is part of GNUnet.
3 (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file transport/test_quota_compliance.c
22 * @brief base test case for transport implementations
24 * This test case tests quota compliance both on core and transport level
27 #include "gnunet_common.h"
28 #include "gnunet_hello_lib.h"
29 #include "gnunet_getopt_lib.h"
30 #include "gnunet_os_lib.h"
31 #include "gnunet_program_lib.h"
32 #include "gnunet_scheduler_lib.h"
33 #include "gnunet_server_lib.h"
34 #include "gnunet_transport_service.h"
35 #include "transport.h"
36 #include "transport-testing.h"
38 #define VERBOSE GNUNET_EXTRA_LOGGING
40 #define VERBOSE_ARM GNUNET_EXTRA_LOGGING
42 #define START_ARM GNUNET_YES
43 #define DEBUG_MEASUREMENT GNUNET_EXTRA_LOGGING
44 #define DEBUG_CONNECTIONS GNUNET_EXTRA_LOGGING
46 #define MEASUREMENT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
47 #define MEASUREMENT_MSG_SIZE 1024
48 #define MEASUREMENT_MSG_SIZE_BIG 32768
49 #define MEASUREMENT_MAX_QUOTA 1024 * 1024 * 1024
50 #define MEASUREMENT_MIN_QUOTA 1024
51 #define SEND_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
52 #define MEASUREMENT_SOFT_LIMIT 1024
57 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 200)
64 * Handle for a transmission-ready request.
66 struct GNUNET_TRANSPORT_TransmitHandle
70 * Neighbour for this handle, NULL for control-traffic.
72 struct NeighbourList *neighbour;
75 * Function to call when notify_size bytes are available
78 GNUNET_CONNECTION_TransmitReadyNotify notify;
86 * transmit_ready task Id. The task is used to introduce the
87 * artificial delay that may be required to maintain the bandwidth
88 * limits. Later, this will be the ID of the "transmit_timeout"
89 * task which is used to signal a timeout if the transmission could
90 * not be done in a timely fashion.
92 GNUNET_SCHEDULER_TaskIdentifier notify_delay_task;
95 * Timeout for this request.
97 struct GNUNET_TIME_Absolute timeout;
100 * How many bytes is our notify callback waiting for?
105 * How important is this message?
107 unsigned int priority;
111 static struct PeerContext p1;
113 static struct PeerContext p2;
117 static int connected;
118 static int measurement_running;
119 static int send_running;
120 static int recv_running;
122 static unsigned long long total_bytes_sent;
123 static unsigned long long last_msg_sent;
124 static unsigned long long last_msg_recv;
125 static unsigned long long current_quota_p1;
126 static unsigned long long current_quota_p2;
129 static int is_tcp_nat;
134 static int is_asymmetric_send_constant;
135 static int is_asymmetric_recv_constant;
137 static struct GNUNET_TIME_Absolute start_time;
139 static GNUNET_SCHEDULER_TaskIdentifier die_task;
140 static GNUNET_SCHEDULER_TaskIdentifier tct;
141 static GNUNET_SCHEDULER_TaskIdentifier measurement_task;
142 static GNUNET_SCHEDULER_TaskIdentifier measurement_counter_task;
144 static struct GNUNET_TRANSPORT_TransmitHandle *transmit_handle;
146 #define OKPP do { ok++; } while (0)
152 GNUNET_SCHEDULER_cancel (die_task);
153 die_task = GNUNET_SCHEDULER_NO_TASK;
155 if (measurement_task != GNUNET_SCHEDULER_NO_TASK)
157 GNUNET_SCHEDULER_cancel (measurement_task);
158 measurement_task = GNUNET_SCHEDULER_NO_TASK;
160 if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
162 GNUNET_SCHEDULER_cancel (measurement_counter_task);
163 measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
165 fprintf (stderr, "\n");
166 GNUNET_SCHEDULER_shutdown ();
167 #if DEBUG_CONNECTIONS
168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
170 GNUNET_TRANSPORT_disconnect (p1.th);
171 GNUNET_TRANSPORT_disconnect (p2.th);
172 #if DEBUG_CONNECTIONS
173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
174 "Transports disconnected, returning success!\n");
176 GNUNET_SCHEDULER_shutdown ();
182 stop_arm (struct PeerContext *p)
185 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
186 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
187 GNUNET_OS_process_wait (p->arm_proc);
188 GNUNET_OS_process_close (p->arm_proc);
191 GNUNET_CONFIGURATION_destroy (p->cfg);
196 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
198 if (measurement_task != GNUNET_SCHEDULER_NO_TASK)
200 GNUNET_SCHEDULER_cancel (measurement_task);
201 measurement_task = GNUNET_SCHEDULER_NO_TASK;
203 if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
205 GNUNET_SCHEDULER_cancel (measurement_counter_task);
206 measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
209 if (GNUNET_SCHEDULER_NO_TASK != tct)
211 GNUNET_SCHEDULER_cancel (tct);
212 tct = GNUNET_SCHEDULER_NO_TASK;
215 GNUNET_TRANSPORT_disconnect (p1.th);
217 GNUNET_TRANSPORT_disconnect (p2.th);
223 struct GNUNET_MessageHeader header;
231 return MEASUREMENT_MSG_SIZE + sizeof (struct TestMessage);
235 notify_receive_new (void *cls, const struct GNUNET_PeerIdentity *peer,
236 const struct GNUNET_MessageHeader *message,
237 const struct GNUNET_TRANSPORT_ATS_Information *ats,
240 const struct TestMessage *hdr;
242 GNUNET_assert (message != NULL);
243 hdr = (const struct TestMessage *) message;
244 if (measurement_running == GNUNET_NO)
246 if (MTYPE != ntohs (message->type))
249 #if DEBUG_MEASUREMENT
250 if (ntohl (hdr->num) % 5000 == 0)
252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got message %u of size %u\n",
253 ntohl (hdr->num), ntohs (message->size));
257 * GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
258 * "Got message %u\n",
259 * ntohl (hdr->num)); */
260 last_msg_recv = ntohl (hdr->num);
265 notify_ready (void *cls, size_t size, void *buf)
268 struct TestMessage hdr;
272 transmit_handle = NULL;
273 if (measurement_task == GNUNET_SCHEDULER_NO_TASK)
281 if (measurement_running != GNUNET_YES)
283 send_running = GNUNET_NO;
286 send_running = GNUNET_YES;
289 GNUNET_assert (size >= s);
290 GNUNET_assert (buf != NULL);
295 hdr.header.size = htons (s);
296 hdr.header.type = htons (MTYPE);
297 hdr.num = htonl (last_msg_sent);
298 memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
299 ret += sizeof (struct TestMessage);
300 memset (&cbuf[ret], last_msg_sent, s - sizeof (struct TestMessage));
301 ret += s - sizeof (struct TestMessage);
302 #if DEBUG_MEASUREMENT
303 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message %u\n", last_msg_sent);
306 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
307 break; /* sometimes pack buffer full, sometimes not */
309 while (size - ret >= s);
311 GNUNET_TRANSPORT_notify_transmit_ready (p2.th, &p1.id, s, 0, SEND_TIMEOUT,
312 ¬ify_ready, NULL);
313 total_bytes_sent += s;
319 measure (unsigned long long quota_p1, unsigned long long quota_p2);
322 measurement_counter (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
324 measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
325 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
328 fprintf (stderr, ".");
329 measurement_counter_task =
330 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
331 &measurement_counter, NULL);
336 measurement_end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
338 static int strike_counter;
339 static int failed_measurement_counter = 1;
340 unsigned long long quota_allowed = 0;
343 measurement_task = GNUNET_SCHEDULER_NO_TASK;
344 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
347 measurement_running = GNUNET_NO;
348 struct GNUNET_TIME_Relative duration =
349 GNUNET_TIME_absolute_get_difference (start_time,
350 GNUNET_TIME_absolute_get ());
353 if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
355 GNUNET_SCHEDULER_cancel (measurement_counter_task);
356 measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
359 if (transmit_handle != NULL)
361 GNUNET_TRANSPORT_notify_transmit_ready_cancel (transmit_handle);
362 transmit_handle = NULL;
365 if (current_quota_p1 < current_quota_p2)
366 quota_allowed = current_quota_p1;
368 quota_allowed = current_quota_p2;
371 if (MEASUREMENT_SOFT_LIMIT > (quota_allowed / 3))
372 delta = MEASUREMENT_SOFT_LIMIT;
374 delta = (quota_allowed / 3);
376 /* Throughput is far too slow. This is to prevent the test to exit with success when throughput is 0 */
377 if ((total_bytes_sent / (duration.rel_value / 1000)) < 100)
379 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
380 "\nQuota compliance failed: \n"
381 "Hard quota limit allowed: %10llu kB/s (%llu B/s)\n"
382 "Soft quota limit allowed: %10llu kB/s (%llu B/s)\n"
383 "Throughput : %10llu kB/s (%llu B/s)\n",
384 (quota_allowed / (1024)), quota_allowed,
385 ((quota_allowed + delta) / (1024)), quota_allowed + delta,
386 (total_bytes_sent / (duration.rel_value / 1000) / 1024),
387 total_bytes_sent / (duration.rel_value / 1000));
389 failed_measurement_counter--;
390 if (failed_measurement_counter < 0)
392 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
393 "\nQuota measurement failed and no free strike: %i\n",
394 failed_measurement_counter);
399 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
400 "\nQuota measurement failed and %i free strikes\n",
401 failed_measurement_counter);
404 /* Throughput is bigger than allowed quota + some extra */
405 if ((total_bytes_sent / (duration.rel_value / 1000)) >
406 (quota_allowed + delta))
408 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
409 "\nQuota compliance failed: \n"
410 "Hard quota limit allowed: %10llu kB/s (%llu B/s)\n"
411 "Soft quota limit allowed: %10llu kB/s (%llu B/s)\n"
412 "Throughput : %10llu kB/s (%llu B/s)\n",
413 (quota_allowed / (1024)), quota_allowed,
414 ((quota_allowed + delta) / (1024)), quota_allowed + delta,
415 (total_bytes_sent / (duration.rel_value / 1000) / 1024),
416 total_bytes_sent / (duration.rel_value / 1000));
418 failed_measurement_counter--;
419 if (failed_measurement_counter < 0)
421 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
422 "\nQuota measurement failed and no free strike: %i\n",
423 failed_measurement_counter);
428 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
429 "\nQuota measurement failed and %i free strikes\n",
430 failed_measurement_counter);
434 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
435 "\nQuota compliance ok: \n" "Quota allowed: %10llu kB/s\n"
436 "Throughput : %10llu kB/s\n", (quota_allowed / (1024)),
437 (total_bytes_sent / (duration.rel_value / 1000) / 1024));
438 if (failed_measurement_counter < 2)
439 failed_measurement_counter++;
443 if ((quota_allowed) > (2 * (total_bytes_sent / (duration.rel_value / 1000))))
445 if (failed_measurement_counter < 2)
446 failed_measurement_counter++;
447 if (strike_counter == 2)
449 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
450 "Maximum transmission rate reached, stopping test\n");
460 if (quota_allowed == MEASUREMENT_MAX_QUOTA)
465 if (is_asymmetric_send_constant == GNUNET_YES)
467 if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA)
468 measure (current_quota_p1 * 2, MEASUREMENT_MAX_QUOTA);
470 measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA);
472 else if (is_asymmetric_recv_constant == GNUNET_YES)
474 if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA)
475 measure (MEASUREMENT_MAX_QUOTA, current_quota_p2 * 2);
477 measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA);
481 if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA)
482 measure ((current_quota_p1) * 2, (current_quota_p2) * 2);
484 measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA);
489 measure (unsigned long long quota_p1, unsigned long long quota_p2)
491 current_quota_p1 = quota_p1;
492 current_quota_p2 = quota_p2;
494 if ((is_asymmetric_send_constant == GNUNET_YES) ||
495 (is_asymmetric_recv_constant == GNUNET_YES))
496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
497 "Starting transport level measurement for %u seconds, receiving peer quota %llu kB/s, sending peer quota %llu kB/s\n",
498 MEASUREMENT_INTERVALL.rel_value / 1000, current_quota_p1 / 1024,
499 current_quota_p2 / 1024);
501 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
502 "Starting transport level measurement for %u seconds, symmetric quota %llu kB/s\n",
503 MEASUREMENT_INTERVALL.rel_value / 1000,
504 current_quota_p2 / 1024);
507 GNUNET_TRANSPORT_set_quota (p1.th, &p2.id,
508 GNUNET_BANDWIDTH_value_init (current_quota_p1),
509 GNUNET_BANDWIDTH_value_init (current_quota_p1));
510 GNUNET_TRANSPORT_set_quota (p2.th, &p1.id,
511 GNUNET_BANDWIDTH_value_init (current_quota_p2),
512 GNUNET_BANDWIDTH_value_init (current_quota_p2));
513 GNUNET_SCHEDULER_cancel (die_task);
514 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
515 if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
516 GNUNET_SCHEDULER_cancel (measurement_counter_task);
517 measurement_counter_task =
518 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
519 &measurement_counter, NULL);
521 GNUNET_SCHEDULER_add_delayed (MEASUREMENT_INTERVALL, &measurement_end,
523 total_bytes_sent = 0;
526 measurement_running = GNUNET_YES;
527 start_time = GNUNET_TIME_absolute_get ();
529 if (transmit_handle != NULL)
530 GNUNET_TRANSPORT_notify_transmit_ready_cancel (transmit_handle);
532 GNUNET_TRANSPORT_notify_transmit_ready (p2.th, &p1.id, get_size (), 0,
533 SEND_TIMEOUT, ¬ify_ready,
539 exchange_hello_last (void *cls, const struct GNUNET_MessageHeader *message)
541 struct PeerContext *me = cls;
543 GNUNET_assert (message != NULL);
544 #if DEBUG_CONNECTIONS
545 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
546 "Exchanging HELLO of size %d with peer (%s)!\n",
547 (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
548 message), GNUNET_i2s (&me->id));
550 GNUNET_assert (GNUNET_OK ==
551 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
553 GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL);
559 exchange_hello (void *cls, const struct GNUNET_MessageHeader *message)
561 struct PeerContext *me = cls;
563 GNUNET_assert (message != NULL);
564 GNUNET_assert (GNUNET_OK ==
565 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
567 #if DEBUG_CONNECTIONS
568 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
569 "Exchanging HELLO of size %d from peer %s!\n",
570 (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
571 message), GNUNET_i2s (&me->id));
573 GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL);
578 notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
579 const struct GNUNET_TRANSPORT_ATS_Information *ats,
585 #if DEBUG_CONNECTIONS
586 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 1 `%4s' connected to us (%p)!\n",
587 GNUNET_i2s (peer), cls);
592 #if DEBUG_CONNECTIONS
593 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 2 `%4s' connected to us (%p)!\n",
594 GNUNET_i2s (peer), cls);
599 if (GNUNET_SCHEDULER_NO_TASK != tct)
601 GNUNET_SCHEDULER_cancel (tct);
602 tct = GNUNET_SCHEDULER_NO_TASK;
604 GNUNET_TRANSPORT_get_hello_cancel (p2.ghh);
605 GNUNET_TRANSPORT_get_hello_cancel (p1.ghh);
606 if (is_asymmetric_send_constant == GNUNET_YES)
607 measure (MEASUREMENT_MIN_QUOTA, MEASUREMENT_MAX_QUOTA);
608 else if (is_asymmetric_recv_constant == GNUNET_YES)
609 measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MIN_QUOTA);
611 measure (MEASUREMENT_MIN_QUOTA, MEASUREMENT_MIN_QUOTA);
617 notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
621 if (NULL != transmit_handle)
623 GNUNET_TRANSPORT_notify_transmit_ready_cancel (transmit_handle);
624 transmit_handle = NULL;
628 #if DEBUG_CONNECTIONS
629 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' disconnected (%p)!\n",
630 GNUNET_i2s (peer), cls);
636 setup_peer (struct PeerContext *p, const char *cfgname)
638 p->cfg = GNUNET_CONFIGURATION_create ();
639 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
640 if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME"))
642 GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME",
644 GNUNET_DISK_directory_remove (p->servicehome);
649 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
650 "gnunet-service-arm",
654 "-c", cfgname, NULL);
658 GNUNET_TRANSPORT_connect (p->cfg, NULL, p, ¬ify_receive_new,
659 ¬ify_connect, ¬ify_disconnect);
660 GNUNET_assert (p->th != NULL);
665 try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
667 #if DEBUG_CONNECTIONS
668 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking peers to connect...\n");
670 GNUNET_TRANSPORT_try_connect (p2.th, &p1.id);
671 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id);
673 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect,
679 run (void *cls, char *const *args, const char *cfgfile,
680 const struct GNUNET_CONFIGURATION_Handle *cfg)
682 GNUNET_assert (ok == 1);
685 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
686 measurement_running = GNUNET_NO;
687 send_running = GNUNET_NO;
688 recv_running = GNUNET_NO;
692 if (is_asymmetric_recv_constant == GNUNET_YES)
693 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
694 "Testing asymmetric quota compliance (receiver quota constant) for TCP transport plugin\n");
695 else if (is_asymmetric_send_constant == GNUNET_YES)
696 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
697 "Testing asymmetric quota compliance (sender quota constant) for TCP transport plugin\n");
699 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
700 "Testing symmetric quota compliance for TCP transport plugin\n");
701 setup_peer (&p1, "test_quota_compliance_tcp_peer1.conf");
702 setup_peer (&p2, "test_quota_compliance_tcp_peer2.conf");
706 if (is_asymmetric_recv_constant == GNUNET_YES)
707 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
708 "Testing asymmetric quota compliance (receiver quota constant) for HTTP transport plugin\n");
709 else if (is_asymmetric_send_constant == GNUNET_YES)
710 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
711 "Testing asymmetric quota compliance (sender quota constant) for HTTP transport plugin\n");
713 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
714 "Testing symmetric quota compliance for HTTP transport plugin\n");
715 setup_peer (&p1, "test_quota_compliance_http_peer1.conf");
716 setup_peer (&p2, "test_quota_compliance_http_peer2.conf");
720 if (is_asymmetric_recv_constant == GNUNET_YES)
721 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
722 "Testing asymmetric quota compliance (receiver quota constant) for HTTPS transport plugin\n");
723 else if (is_asymmetric_send_constant == GNUNET_YES)
724 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
725 "Testing asymmetric quota compliance (sender quota constant) for HTTPS transport plugin\n");
727 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
728 "Testing symmetric quota compliance for HTTPS transport plugin\n");
729 setup_peer (&p1, "test_quota_compliance_https_peer1.conf");
730 setup_peer (&p2, "test_quota_compliance_https_peer2.conf");
734 if (is_asymmetric_recv_constant == GNUNET_YES)
735 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
736 "Testing asymmetric quota compliance (receiver quota constant) for UDP transport plugin\n");
737 else if (is_asymmetric_send_constant == GNUNET_YES)
738 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
739 "Testing asymmetric quota compliance (sender quota constant) for UDP transport plugin\n");
741 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
742 "Testing symmetric quota compliance for UDP transport plugin\n");
743 setup_peer (&p1, "test_quota_compliance_udp_peer1.conf");
744 setup_peer (&p2, "test_quota_compliance_udp_peer2.conf");
748 if (is_asymmetric_recv_constant == GNUNET_YES)
749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
750 "Testing asymmetric quota compliance (receiver quota constant) for UNIX transport plugin\n");
751 else if (is_asymmetric_send_constant == GNUNET_YES)
752 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
753 "Testing asymmetric quota compliance (sender quota constant) for UNIX transport plugin\n");
755 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
756 "Testing symmetric quota compliance for UNIX transport plugin\n");
757 setup_peer (&p1, "test_quota_compliance_unix_peer1.conf");
758 setup_peer (&p2, "test_quota_compliance_unix_peer2.conf");
762 if (is_asymmetric_recv_constant == GNUNET_YES)
763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
764 "Testing asymmetric quota compliance (receiver quota constant) for TCP NAT transport plugin\n");
765 else if (is_asymmetric_send_constant == GNUNET_YES)
766 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
767 "Testing asymmetric quota compliance (sender quota constant) for TCP NAT transport plugin\n");
769 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
770 "Testing symmetric quota compliance for TCP NAT transport plugin\n");
771 setup_peer (&p1, "test_quota_compliance_tcp_peer1.conf");
772 setup_peer (&p2, "test_quota_compliance_tcp_peer2.conf");
777 GNUNET_assert (p1.th != NULL);
778 GNUNET_assert (p2.th != NULL);
779 p1.ghh = GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
780 p2.ghh = GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2);
781 tct = GNUNET_SCHEDULER_add_now (&try_connect, NULL);
786 main (int argc, char *argv[])
790 if (strstr (argv[0], "tcp_nat") != NULL)
792 is_tcp_nat = GNUNET_YES;
794 else if (strstr (argv[0], "tcp") != NULL)
798 else if (strstr (argv[0], "https") != NULL)
800 is_https = GNUNET_YES;
802 else if (strstr (argv[0], "http") != NULL)
804 is_http = GNUNET_YES;
806 else if (strstr (argv[0], "udp") != NULL)
810 else if (strstr (argv[0], "unix") != NULL)
812 is_unix = GNUNET_YES;
815 if (strstr (argv[0], "asymmetric_recv") != NULL)
817 is_asymmetric_recv_constant = GNUNET_YES;
820 is_asymmetric_recv_constant = GNUNET_NO;
821 if (strstr (argv[0], "asymmetric_send") != NULL)
823 is_asymmetric_send_constant = GNUNET_YES;
826 is_asymmetric_send_constant = GNUNET_NO;
830 if (is_tcp == GNUNET_YES)
832 if (is_asymmetric_recv_constant == GNUNET_YES)
833 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "tcp",
834 "asymmetric_recv_constant");
835 else if (is_asymmetric_send_constant == GNUNET_YES)
836 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "tcp",
837 "asymmetric_send_constant");
839 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "tcp",
842 else if (is_udp == GNUNET_YES)
844 if (is_asymmetric_recv_constant == GNUNET_YES)
845 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "udp",
846 "asymmetric_recv_constant");
847 else if (is_asymmetric_send_constant == GNUNET_YES)
848 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "udp",
849 "asymmetric_send_constant");
851 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "udp",
854 else if (is_unix == GNUNET_YES)
856 if (is_asymmetric_recv_constant == GNUNET_YES)
857 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "unix",
858 "asymmetric_recv_constant");
859 else if (is_asymmetric_send_constant == GNUNET_YES)
860 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "unix",
861 "asymmetric_send_constant");
863 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "unix",
866 else if (is_http == GNUNET_YES)
868 if (is_asymmetric_recv_constant == GNUNET_YES)
869 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "http",
870 "asymmetric_recv_constant");
871 else if (is_asymmetric_send_constant == GNUNET_YES)
872 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "http",
873 "asymmetric_send_constant");
875 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "http",
878 else if (is_https == GNUNET_YES)
880 if (is_asymmetric_recv_constant == GNUNET_YES)
881 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "https",
882 "asymmetric_recv_constant");
883 else if (is_asymmetric_send_constant == GNUNET_YES)
884 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "https",
885 "asymmetric_send_constant");
887 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "https",
892 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "noplugin",
896 fprintf (stderr, "Running `%s'\n", logger);
897 GNUNET_log_setup ("test-quota-compliance",
904 char *const argv1[] = { "test-quota-compliance",
906 "test_quota_compliance_data.conf",
912 struct GNUNET_GETOPT_CommandLineOption options[] = {
913 GNUNET_GETOPT_OPTION_END
916 GNUNET_PROGRAM_run ((sizeof (argv1) / sizeof (char *)) - 1, argv1, logger,
917 "nohelp", options, &run, &ok);
922 if (p1.servicehome != NULL)
924 GNUNET_DISK_directory_remove (p1.servicehome);
925 GNUNET_free (p1.servicehome);
927 if (p2.servicehome != NULL)
929 GNUNET_DISK_directory_remove (p2.servicehome);
930 GNUNET_free (p2.servicehome);
932 GNUNET_free (logger);
936 /* end of test_quota_compliance.c */