Activated progress bar
[oweals/gnunet.git] / src / transport / test_quota_compliance.c
1 /*
2      This file is part of GNUnet.
3      (C) 2009, 2010 Christian Grothoff (and other contributing authors)
4
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.
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      General Public License for more details.
14
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.
19 */
20 /**
21  * @file transport/test_quota_compliance.c
22  * @brief base test case for transport implementations
23  *
24  * This test case tests quota compliance both on core and transport level
25  */
26 #include "platform.h"
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
37 #define VERBOSE GNUNET_NO
38
39 #define VERBOSE_ARM GNUNET_NO
40
41 #define START_ARM GNUNET_YES
42 #define DEBUG_MEASUREMENT GNUNET_NO
43 #define DEBUG_CONNECTIONS GNUNET_NO
44
45 #define MEASUREMENT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
46 #define MEASUREMENT_MSG_SIZE 1024
47 #define MEASUREMENT_MSG_SIZE_BIG 32768
48 #define MEASUREMENT_MAX_QUOTA 1024 * 1024 * 1024
49 #define MEASUREMENT_MIN_QUOTA 1024
50 #define SEND_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
51 #define MEASUREMENT_SOFT_LIMIT 1024
52
53 /**
54  * Testcase timeout
55  */
56 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 200)
57
58
59
60 #define MTYPE 11111
61
62 struct PeerContext
63 {
64   struct GNUNET_CONFIGURATION_Handle *cfg;
65   struct GNUNET_TRANSPORT_Handle *th;
66   struct GNUNET_PeerIdentity id;
67 #if START_ARM
68   struct GNUNET_OS_Process *arm_proc;
69 #endif
70 };
71
72 /**
73  * Handle for a transmission-ready request.
74  */
75 struct GNUNET_TRANSPORT_TransmitHandle
76 {
77
78   /**
79    * Neighbour for this handle, NULL for control-traffic.
80    */
81   struct NeighbourList *neighbour;
82
83   /**
84    * Function to call when notify_size bytes are available
85    * for transmission.
86    */
87   GNUNET_CONNECTION_TransmitReadyNotify notify;
88
89   /**
90    * Closure for notify.
91    */
92   void *notify_cls;
93
94   /**
95    * transmit_ready task Id.  The task is used to introduce the
96    * artificial delay that may be required to maintain the bandwidth
97    * limits.  Later, this will be the ID of the "transmit_timeout"
98    * task which is used to signal a timeout if the transmission could
99    * not be done in a timely fashion.
100    */
101   GNUNET_SCHEDULER_TaskIdentifier notify_delay_task;
102
103   /**
104    * Timeout for this request.
105    */
106   struct GNUNET_TIME_Absolute timeout;
107
108   /**
109    * How many bytes is our notify callback waiting for?
110    */
111   size_t notify_size;
112
113   /**
114    * How important is this message?
115    */
116   unsigned int priority;
117
118 };
119
120 static struct PeerContext p1;
121
122 static struct PeerContext p2;
123
124 static int ok;
125
126 static int connected;
127 static int measurement_running;
128 static int send_running;
129 static int recv_running;
130
131 static unsigned long long total_bytes_sent;
132 static unsigned long long last_msg_sent;
133 static unsigned long long last_msg_recv;
134 static unsigned long long current_quota_p1;
135 static unsigned long long current_quota_p2;
136
137 static int is_tcp;
138 static int is_tcp_nat;
139 static int is_http;
140 static int is_https;
141 static int is_udp;
142 static int is_asymmetric_send_constant;
143 static int is_asymmetric_recv_constant;
144
145 static struct GNUNET_TIME_Absolute start_time;
146
147 static GNUNET_SCHEDULER_TaskIdentifier die_task;
148 static GNUNET_SCHEDULER_TaskIdentifier measurement_task;
149 static GNUNET_SCHEDULER_TaskIdentifier measurement_counter_task;
150
151 struct GNUNET_TRANSPORT_TransmitHandle * transmit_handle;
152
153 #define OKPP do { ok++; } while (0)
154
155
156
157 static void
158 end_send ()
159 {
160
161 }
162
163 static void
164 end ()
165 {
166   GNUNET_SCHEDULER_cancel (die_task);
167   die_task = GNUNET_SCHEDULER_NO_TASK;
168
169   if (measurement_task != GNUNET_SCHEDULER_NO_TASK)
170   {
171             GNUNET_SCHEDULER_cancel (measurement_task);
172             measurement_task = GNUNET_SCHEDULER_NO_TASK;
173   }
174   if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
175   {
176             GNUNET_SCHEDULER_cancel (measurement_counter_task);
177             measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
178   }
179   GNUNET_SCHEDULER_shutdown ();
180 #if DEBUG_CONNECTIONS
181   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
182 #endif
183   GNUNET_TRANSPORT_disconnect (p1.th);
184   GNUNET_TRANSPORT_disconnect (p2.th);
185 #if DEBUG_CONNECTIONS
186   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
187               "Transports disconnected, returning success!\n");
188 #endif
189   GNUNET_SCHEDULER_shutdown ();
190 }
191
192
193
194 static void
195 stop_arm (struct PeerContext *p)
196 {
197 #if START_ARM
198   if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
199     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
200   GNUNET_OS_process_wait (p->arm_proc);
201   GNUNET_OS_process_close (p->arm_proc);
202   p->arm_proc = NULL;
203 #endif
204   GNUNET_CONFIGURATION_destroy (p->cfg);
205 }
206
207
208 static void
209 end_badly (void *cls,
210            const struct GNUNET_SCHEDULER_TaskContext *tc)
211 {
212   if (measurement_task != GNUNET_SCHEDULER_NO_TASK)
213   {
214             GNUNET_SCHEDULER_cancel (measurement_task);
215             measurement_task = GNUNET_SCHEDULER_NO_TASK;
216   }
217   if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
218   {
219             GNUNET_SCHEDULER_cancel (measurement_counter_task);
220             measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
221   }
222   GNUNET_break (0);
223   if (p1.th != NULL)
224           GNUNET_TRANSPORT_disconnect (p1.th);
225   if (p2.th != NULL)
226           GNUNET_TRANSPORT_disconnect (p2.th);
227   ok = 1;
228 }
229
230 struct TestMessage
231 {
232   struct GNUNET_MessageHeader header;
233   uint32_t num;
234 };
235
236 static unsigned int
237 get_size (void)
238 {
239   return MEASUREMENT_MSG_SIZE + sizeof (struct TestMessage);
240 }
241
242 static void
243 notify_receive_new (void *cls,
244                 const struct GNUNET_PeerIdentity *peer,
245                 const struct GNUNET_MessageHeader *message,
246                 struct GNUNET_TIME_Relative latency,
247                 uint32_t distance)
248 {
249   unsigned int s;
250   const struct TestMessage *hdr;
251
252   hdr = (const struct TestMessage*) message;
253   s = get_size ();
254   if (measurement_running == GNUNET_NO)
255           return;
256   if (MTYPE != ntohs (message->type))
257     return;
258
259 #if DEBUG_MEASUREMENT
260   if (ntohl(hdr->num) % 5000 == 0)
261     {
262       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
263                   "Got message %u of size %u\n",
264                   ntohl (hdr->num),
265                   ntohs (message->size));
266     }
267 #endif
268   /*
269   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
270               "Got message %u\n",
271               ntohl (hdr->num));*/
272   last_msg_recv = ntohl (hdr->num);
273 }
274
275 static size_t
276 notify_ready (void *cls, size_t size, void *buf)
277 {
278   char *cbuf = buf;
279   struct TestMessage hdr;
280   unsigned int s;
281   unsigned int ret;
282
283   transmit_handle = NULL;
284
285   if (measurement_task == GNUNET_SCHEDULER_NO_TASK)
286           return 0;
287
288   if (buf == NULL)
289     {
290       ok = 42;
291       return 0;
292     }
293
294   if (measurement_running != GNUNET_YES)
295   {
296           send_running = GNUNET_NO;
297           end_send();
298           return 0;
299   }
300
301   send_running = GNUNET_YES;
302   ret = 0;
303   s = get_size ();
304   GNUNET_assert (size >= s);
305   GNUNET_assert (buf != NULL);
306   last_msg_sent++;
307   cbuf = buf;
308   do
309     {
310       hdr.header.size = htons (s);
311       hdr.header.type = htons (MTYPE);
312       hdr.num = htonl (last_msg_sent);
313       memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
314       ret += sizeof (struct TestMessage);
315       memset (&cbuf[ret], last_msg_sent, s - sizeof (struct TestMessage));
316       ret += s - sizeof (struct TestMessage);
317 #if DEBUG_MEASUREMENT
318       if (n % 5000 == 0)
319        {
320           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
321                       "Sending message %u\n",n);
322        }
323 #endif
324
325     /*      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
326                       "Sending message %u\n",last_msg_sent);*/
327
328       s = get_size ();
329       if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
330         break; /* sometimes pack buffer full, sometimes not */
331     }
332   while (size - ret >= s);
333   transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
334                                             &p1.id,
335                                             s, 0, SEND_TIMEOUT,
336                                             &notify_ready,
337                                             NULL);
338   total_bytes_sent += s;
339   return ret;
340 }
341
342 static void measure (unsigned long long quota_p1, unsigned long long quota_p2 );
343
344 static void measurement_counter
345  (void *cls,
346            const struct GNUNET_SCHEDULER_TaskContext *tc)
347 {
348   measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
349
350   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
351         return;
352
353   fprintf(stderr,".");
354   measurement_counter_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
355                                                            &measurement_counter,
356                                                            NULL);
357 }
358
359 static void
360 measurement_end (void *cls,
361            const struct GNUNET_SCHEDULER_TaskContext *tc)
362 {
363   static int strike_counter;
364   unsigned long long  quota_allowed = 0;
365   int delta = 0;
366
367   measurement_task  = GNUNET_SCHEDULER_NO_TASK;
368   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
369         return;
370
371   measurement_running = GNUNET_NO;
372   struct GNUNET_TIME_Relative duration = GNUNET_TIME_absolute_get_difference(start_time, GNUNET_TIME_absolute_get());
373
374
375   if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
376   {
377     GNUNET_SCHEDULER_cancel (measurement_counter_task);
378     measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
379   }
380
381   fprintf(stderr,"\n");
382
383
384   if (transmit_handle != NULL)
385   {
386           GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle);
387           transmit_handle = NULL;
388   }
389
390   if (current_quota_p1 < current_quota_p2)
391           quota_allowed = current_quota_p1;
392   else
393           quota_allowed = current_quota_p2;
394
395
396   if (MEASUREMENT_SOFT_LIMIT > (quota_allowed/10))
397           delta = MEASUREMENT_SOFT_LIMIT;
398   else
399           delta = (quota_allowed/10);
400
401   /* Throughput is far too slow. This is to prevent the test to exit with success when throughput is 0 */
402   if ((total_bytes_sent/(duration.rel_value / 1000)) < 100)
403   {
404           GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
405                           "\nQuota compliance failed: \n"\
406                           "Hard quota limit allowed: %10llu kB/s (%llu B/s)\n"\
407                           "Soft quota limit allowed: %10llu kB/s (%llu B/s)\n"\
408                           "Throughput              : %10llu kB/s (%llu B/s)\n",
409                           (quota_allowed / (1024)), quota_allowed,
410                           ((quota_allowed+delta) / (1024)),  quota_allowed+delta,
411                           (total_bytes_sent/(duration.rel_value / 1000)/1024),
412                           total_bytes_sent/(duration.rel_value / 1000));
413           ok = 1;
414           end();
415   }
416
417   /* Throughput is bigger than allowed quota + some extra*/
418   if ((total_bytes_sent/(duration.rel_value / 1000)) > (quota_allowed + delta))
419   {
420           GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
421                           "\nQuota compliance failed: \n"\
422                           "Hard quota limit allowed: %10llu kB/s (%llu B/s)\n"\
423                           "Soft quota limit allowed: %10llu kB/s (%llu B/s)\n"\
424                           "Throughput              : %10llu kB/s (%llu B/s)\n", 
425                           (quota_allowed / (1024)), quota_allowed, 
426                           ((quota_allowed+delta) / (1024)),  quota_allowed+delta, 
427                           (total_bytes_sent/(duration.rel_value / 1000)/1024), 
428                           total_bytes_sent/(duration.rel_value / 1000));
429           ok = 1;
430           end();
431           return;
432   }
433   else
434   {
435           GNUNET_log (GNUNET_ERROR_TYPE_INFO,
436                           "\nQuota compliance ok: \n"\
437                           "Quota allowed: %10llu kB/s\n"\
438                           "Throughput   : %10llu kB/s\n", (quota_allowed / (1024)) , (total_bytes_sent/(duration.rel_value / 1000)/1024));
439           ok = 0;
440   }
441
442   if ((quota_allowed) > (2 *(total_bytes_sent/(duration.rel_value / 1000))))
443   {
444           strike_counter++;
445           if (strike_counter == 2)
446           {
447                   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
448                                   "Maximum transmission rate reached, stopping test\n");
449                   end();
450                   return;
451           }
452   }
453   else
454   {
455           strike_counter = 0;
456   }
457
458   if (quota_allowed == MEASUREMENT_MAX_QUOTA)
459   {
460           end();
461           return;
462   }
463
464   if (is_asymmetric_send_constant == GNUNET_YES)
465   {
466    if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA)
467           measure (current_quota_p1 * 2, MEASUREMENT_MAX_QUOTA);
468    else
469            measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA);
470   }
471   else if (is_asymmetric_recv_constant == GNUNET_YES)
472   {
473    if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA)
474           measure (MEASUREMENT_MAX_QUOTA, current_quota_p2 * 2);
475    else
476            measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA);
477   }
478   else
479   {
480    if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA)
481           measure ((current_quota_p1) * 2, (current_quota_p2) * 2);
482    else
483            measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA);
484   }
485 }
486
487 static void measure (unsigned long long quota_p1, unsigned long long quota_p2 )
488 {
489           current_quota_p1 = quota_p1;
490           current_quota_p2 = quota_p2;
491 #if VERBOSE
492   if ((is_asymmetric_send_constant == GNUNET_YES) || (is_asymmetric_recv_constant == GNUNET_YES))
493           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
494               "Starting transport level measurement for %u seconds, receiving peer quota %llu kB/s, sending peer quota %llu kB/s\n", MEASUREMENT_INTERVALL.rel_value / 1000 , current_quota_p1 / 1024, current_quota_p2 / 1024);
495   else
496           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
497               "Starting transport level measurement for %u seconds, symmetric quota %llu kB/s\n", MEASUREMENT_INTERVALL.rel_value / 1000 , current_quota_p2 / 1024);
498
499 #endif
500                 GNUNET_TRANSPORT_set_quota (p1.th,
501                           &p2.id,
502                           GNUNET_BANDWIDTH_value_init (current_quota_p1 ),
503                           GNUNET_BANDWIDTH_value_init (current_quota_p1 ),
504                           GNUNET_TIME_UNIT_FOREVER_REL,
505                           NULL, NULL);
506                 GNUNET_TRANSPORT_set_quota (p2.th,
507                           &p1.id,
508                           GNUNET_BANDWIDTH_value_init (current_quota_p2),
509                           GNUNET_BANDWIDTH_value_init (current_quota_p2),
510                           GNUNET_TIME_UNIT_FOREVER_REL,
511                           NULL, NULL);
512
513                 GNUNET_SCHEDULER_cancel (die_task);
514                 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
515                                                    &end_badly,
516                                                    NULL);
517                 if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
518                   GNUNET_SCHEDULER_cancel (measurement_counter_task);
519                 measurement_counter_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
520                                                                    &measurement_counter,
521                                                                    NULL);
522                 measurement_task = GNUNET_SCHEDULER_add_delayed (MEASUREMENT_INTERVALL,
523                                                    &measurement_end,
524                                                    NULL);
525                 total_bytes_sent = 0;
526                 last_msg_sent = 0;
527                 last_msg_recv = 0;
528                 measurement_running = GNUNET_YES;
529                 start_time = GNUNET_TIME_absolute_get ();
530
531                 if (transmit_handle != NULL)
532                           GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle);
533                 transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
534                                                                                           &p1.id,
535                                                                                           get_size (), 0, SEND_TIMEOUT,
536                                                                                           &notify_ready,
537                                                                                           NULL);
538 }
539
540 static void
541 notify_connect (void *cls,
542                 const struct GNUNET_PeerIdentity *peer,
543                 struct GNUNET_TIME_Relative latency,
544                 uint32_t distance)
545 {
546   if (cls == &p1)
547     {
548 #if DEBUG_CONNECTIONS
549   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
550               "Peer 1 `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls);
551 #endif
552           connected++;
553     }
554   else
555     {
556 #if DEBUG_CONNECTIONS
557   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
558               "Peer 2 `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls);
559 #endif
560       connected++;
561     }
562   if (connected == 2)
563     {
564            if (is_asymmetric_send_constant == GNUNET_YES)
565                    measure (MEASUREMENT_MIN_QUOTA, MEASUREMENT_MAX_QUOTA);
566            else if (is_asymmetric_recv_constant == GNUNET_YES)
567                    measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MIN_QUOTA);
568            else
569                    measure (MEASUREMENT_MIN_QUOTA, MEASUREMENT_MIN_QUOTA);
570     }
571 }
572
573
574 static void
575 notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
576 {
577 #if DEBUG_CONNECTIONS
578   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
579               "Peer `%4s' disconnected (%p)!\n",
580               GNUNET_i2s (peer), cls);
581 #endif
582 }
583
584
585 static void
586 setup_peer (struct PeerContext *p, const char *cfgname)
587 {
588   p->cfg = GNUNET_CONFIGURATION_create ();
589 #if START_ARM
590   p->arm_proc = GNUNET_OS_start_process (NULL, NULL,
591                                         "gnunet-service-arm",
592                                         "gnunet-service-arm",
593 #if VERBOSE_ARM
594                                         "-L", "DEBUG",
595 #endif
596                                         "-c", cfgname, NULL);
597 #endif
598
599   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
600   p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL,
601                                     p,
602                                     &notify_receive_new,
603                                     &notify_connect,
604                                     &notify_disconnect);
605   GNUNET_assert (p->th != NULL);
606 }
607
608
609 static void
610 exchange_hello_last (void *cls,
611                      const struct GNUNET_MessageHeader *message)
612 {
613   struct PeerContext *me = cls;
614
615   GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, me);
616
617   GNUNET_assert (ok >= 3);
618   OKPP;
619   GNUNET_assert (message != NULL);
620   GNUNET_assert (GNUNET_OK ==
621                  GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
622                                       message, &me->id));
623   /* both HELLOs exchanged, get ready to test transmission! */
624 }
625
626
627 static void
628 exchange_hello (void *cls,
629                 const struct GNUNET_MessageHeader *message)
630 {
631   struct PeerContext *me = cls;
632
633   GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, me);
634   GNUNET_assert (ok >= 2);
635   OKPP;
636   GNUNET_assert (message != NULL);
637   GNUNET_assert (GNUNET_OK ==
638                  GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
639                                       message, &me->id));
640   GNUNET_TRANSPORT_offer_hello (p2.th, message);
641   GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2);
642 }
643
644 static void
645 run (void *cls,
646      char *const *args,
647      const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
648 {
649   GNUNET_assert (ok == 1);
650   OKPP;
651
652   die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
653                                            &end_badly,
654                                            NULL);
655   measurement_running = GNUNET_NO;
656   send_running = GNUNET_NO;
657   recv_running = GNUNET_NO;
658
659   if (is_tcp)
660     {
661           if (is_asymmetric_recv_constant == GNUNET_YES)
662                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (receiver quota constant) for TCP transport plugin\n");
663           else if (is_asymmetric_send_constant == GNUNET_YES)
664                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (sender quota constant) for TCP transport plugin\n");
665           else
666                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing symmetric quota compliance for TCP transport plugin\n");
667       setup_peer (&p1, "test_quota_compliance_tcp_peer1.conf");
668       setup_peer (&p2, "test_quota_compliance_tcp_peer2.conf");
669     }
670   else if (is_http)
671     {
672           if (is_asymmetric_recv_constant == GNUNET_YES)
673                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (receiver quota constant) for HTTP transport plugin\n");
674           else if (is_asymmetric_send_constant == GNUNET_YES)
675                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (sender quota constant) for HTTP transport plugin\n");
676           else
677                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing symmetric quota compliance for HTTP transport plugin\n");
678       setup_peer (&p1, "test_quota_compliance_http_peer1.conf");
679       setup_peer (&p2, "test_quota_compliance_http_peer2.conf");
680     }
681   else if (is_https)
682     {
683           if (is_asymmetric_recv_constant == GNUNET_YES)
684                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (receiver quota constant) for HTTPS transport plugin\n");
685           else if (is_asymmetric_send_constant == GNUNET_YES)
686                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (sender quota constant) for HTTPS transport plugin\n");
687           else
688                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing symmetric quota compliance for HTTPS transport plugin\n");
689       setup_peer (&p1, "test_quota_compliance_https_peer1.conf");
690       setup_peer (&p2, "test_quota_compliance_https_peer2.conf");
691     }
692   else if (is_udp)
693     {
694           if (is_asymmetric_recv_constant == GNUNET_YES)
695                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (receiver quota constant) for UDP transport plugin\n");
696           else if (is_asymmetric_send_constant == GNUNET_YES)
697                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (sender quota constant) for UDP transport plugin\n");
698           else
699                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing symmetric quota compliance for UDP transport plugin\n");
700       setup_peer (&p1, "test_quota_compliance_udp_peer1.conf");
701       setup_peer (&p2, "test_quota_compliance_udp_peer2.conf");
702     }
703   else if (is_tcp_nat)
704     {
705           if (is_asymmetric_recv_constant == GNUNET_YES)
706                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (receiver quota constant) for TCP NAT transport plugin\n");
707           else if (is_asymmetric_send_constant == GNUNET_YES)
708                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (sender quota constant) for TCP NAT transport plugin\n");
709           else
710                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing symmetric quota compliance for TCP NAT transport plugin\n");
711       setup_peer (&p1, "test_quota_compliance_tcp_peer1.conf");
712       setup_peer (&p2, "test_quota_compliance_tcp_peer2.conf");
713     }
714   else
715     GNUNET_assert (0);
716
717   GNUNET_assert(p1.th != NULL);
718   GNUNET_assert(p2.th != NULL);
719   GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
720 }
721
722 int
723 main (int argc, char *argv[])
724 {
725   int ret = 0;
726 #ifdef MINGW
727   return GNUNET_SYSERR;
728 #endif
729   if (strstr(argv[0], "tcp_nat") != NULL)
730     {
731       is_tcp_nat = GNUNET_YES;
732     }
733   else if (strstr(argv[0], "tcp") != NULL)
734     {
735       is_tcp = GNUNET_YES;
736     }
737   else if (strstr(argv[0], "https") != NULL)
738     {
739       is_https = GNUNET_YES;
740     }
741   else if (strstr(argv[0], "http") != NULL)
742     {
743       is_http = GNUNET_YES;
744     }
745   else if (strstr(argv[0], "udp") != NULL)
746     {
747       is_udp = GNUNET_YES;
748     }
749
750   if (strstr(argv[0], "asymmetric_recv") != NULL)
751   {
752       is_asymmetric_recv_constant = GNUNET_YES;
753   }
754   else
755           is_asymmetric_recv_constant = GNUNET_NO;
756   if (strstr(argv[0], "asymmetric_send") != NULL)
757   {
758       is_asymmetric_send_constant = GNUNET_YES;
759   }
760   else
761           is_asymmetric_send_constant = GNUNET_NO;
762
763   char * logger;
764   if (is_tcp == GNUNET_YES)
765   {
766           if (is_asymmetric_recv_constant == GNUNET_YES)
767                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","tcp","asymmetric_recv_constant");
768           else if (is_asymmetric_send_constant == GNUNET_YES)
769                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","tcp","asymmetric_send_constant");
770           else
771                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","tcp","symmetric");
772   }
773   if (is_udp == GNUNET_YES)
774   {
775           if (is_asymmetric_recv_constant == GNUNET_YES)
776                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","udp","asymmetric_recv_constant");
777           else if (is_asymmetric_send_constant == GNUNET_YES)
778                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","udp","asymmetric_send_constant");
779           else
780                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","udp","symmetric");
781   }
782   if (is_http == GNUNET_YES)
783   {
784           if (is_asymmetric_recv_constant == GNUNET_YES)
785                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","http","asymmetric_recv_constant");
786           else if (is_asymmetric_send_constant == GNUNET_YES)
787                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","http","asymmetric_send_constant");
788           else
789                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","http","symmetric");
790   }
791   if (is_https == GNUNET_YES)
792   {
793           if (is_asymmetric_recv_constant == GNUNET_YES)
794                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","https","asymmetric_recv_constant");
795           else if (is_asymmetric_send_constant == GNUNET_YES)
796                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","https","asymmetric_send_constant");
797           else
798                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","https","symmetric");
799   }
800   fprintf(stderr,  "Running `%s'\n", logger);
801   GNUNET_log_setup ("test-quota-compliance",
802 #if VERBOSE
803                     "DEBUG",
804 #else
805                     "WARNING",
806 #endif
807                     NULL);
808   char *const argv1[] = { "test-quota-compliance",
809     "-c",
810     "test_quota_compliance_data.conf",
811 #if VERBOSE
812     "-L", "DEBUG",
813 #endif
814     NULL
815   };
816   struct GNUNET_GETOPT_CommandLineOption options[] = {
817     GNUNET_GETOPT_OPTION_END
818   };
819   ok = 1;
820   GNUNET_PROGRAM_run ((sizeof (argv1) / sizeof (char *)) - 1,
821                       argv1, logger , "nohelp",
822                       options, &run, &ok);
823   ret = ok;
824   stop_arm (&p1);
825   stop_arm (&p2);
826   GNUNET_free(logger);
827   GNUNET_DISK_directory_remove ("/tmp/test_quota_compliance_peer1");
828   GNUNET_DISK_directory_remove ("/tmp/test_quota_compliance_peer2");
829   return ret;
830 }
831
832 /* end of test_quota_compliance.c */