(no commit message)
[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   fprintf(stderr,"\n");
180   GNUNET_SCHEDULER_shutdown ();
181 #if DEBUG_CONNECTIONS
182   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
183 #endif
184   GNUNET_TRANSPORT_disconnect (p1.th);
185   GNUNET_TRANSPORT_disconnect (p2.th);
186 #if DEBUG_CONNECTIONS
187   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
188               "Transports disconnected, returning success!\n");
189 #endif
190   GNUNET_SCHEDULER_shutdown ();
191 }
192
193
194
195 static void
196 stop_arm (struct PeerContext *p)
197 {
198 #if START_ARM
199   if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
200     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
201   GNUNET_OS_process_wait (p->arm_proc);
202   GNUNET_OS_process_close (p->arm_proc);
203   p->arm_proc = NULL;
204 #endif
205   GNUNET_CONFIGURATION_destroy (p->cfg);
206 }
207
208
209 static void
210 end_badly (void *cls,
211            const struct GNUNET_SCHEDULER_TaskContext *tc)
212 {
213   if (measurement_task != GNUNET_SCHEDULER_NO_TASK)
214   {
215             GNUNET_SCHEDULER_cancel (measurement_task);
216             measurement_task = GNUNET_SCHEDULER_NO_TASK;
217   }
218   if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
219   {
220             GNUNET_SCHEDULER_cancel (measurement_counter_task);
221             measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
222   }
223   GNUNET_break (0);
224   if (p1.th != NULL)
225           GNUNET_TRANSPORT_disconnect (p1.th);
226   if (p2.th != NULL)
227           GNUNET_TRANSPORT_disconnect (p2.th);
228   ok = 1;
229 }
230
231 struct TestMessage
232 {
233   struct GNUNET_MessageHeader header;
234   uint32_t num;
235 };
236
237 static unsigned int
238 get_size (void)
239 {
240   return MEASUREMENT_MSG_SIZE + sizeof (struct TestMessage);
241 }
242
243 static void
244 notify_receive_new (void *cls,
245                 const struct GNUNET_PeerIdentity *peer,
246                 const struct GNUNET_MessageHeader *message,
247                 struct GNUNET_TIME_Relative latency,
248                 uint32_t distance)
249 {
250   unsigned int s;
251   const struct TestMessage *hdr;
252
253   hdr = (const struct TestMessage*) message;
254   s = get_size ();
255   if (measurement_running == GNUNET_NO)
256           return;
257   if (MTYPE != ntohs (message->type))
258     return;
259
260 #if DEBUG_MEASUREMENT
261   if (ntohl(hdr->num) % 5000 == 0)
262     {
263       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
264                   "Got message %u of size %u\n",
265                   ntohl (hdr->num),
266                   ntohs (message->size));
267     }
268 #endif
269   /*
270   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
271               "Got message %u\n",
272               ntohl (hdr->num));*/
273   last_msg_recv = ntohl (hdr->num);
274 }
275
276 static size_t
277 notify_ready (void *cls, size_t size, void *buf)
278 {
279   char *cbuf = buf;
280   struct TestMessage hdr;
281   unsigned int s;
282   unsigned int ret;
283
284   transmit_handle = NULL;
285
286   if (measurement_task == GNUNET_SCHEDULER_NO_TASK)
287           return 0;
288
289   if (buf == NULL)
290     {
291       ok = 42;
292       return 0;
293     }
294
295   if (measurement_running != GNUNET_YES)
296   {
297           send_running = GNUNET_NO;
298           end_send();
299           return 0;
300   }
301
302   send_running = GNUNET_YES;
303   ret = 0;
304   s = get_size ();
305   GNUNET_assert (size >= s);
306   GNUNET_assert (buf != NULL);
307   last_msg_sent++;
308   cbuf = buf;
309   do
310     {
311       hdr.header.size = htons (s);
312       hdr.header.type = htons (MTYPE);
313       hdr.num = htonl (last_msg_sent);
314       memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
315       ret += sizeof (struct TestMessage);
316       memset (&cbuf[ret], last_msg_sent, s - sizeof (struct TestMessage));
317       ret += s - sizeof (struct TestMessage);
318 #if DEBUG_MEASUREMENT
319       if (n % 5000 == 0)
320        {
321           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
322                       "Sending message %u\n",n);
323        }
324 #endif
325
326     /*      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
327                       "Sending message %u\n",last_msg_sent);*/
328
329       s = get_size ();
330       if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
331         break; /* sometimes pack buffer full, sometimes not */
332     }
333   while (size - ret >= s);
334   transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
335                                             &p1.id,
336                                             s, 0, SEND_TIMEOUT,
337                                             &notify_ready,
338                                             NULL);
339   total_bytes_sent += s;
340   return ret;
341 }
342
343 static void measure (unsigned long long quota_p1, unsigned long long quota_p2 );
344
345 static void measurement_counter
346  (void *cls,
347            const struct GNUNET_SCHEDULER_TaskContext *tc)
348 {
349   measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
350
351   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
352         return;
353
354   fprintf(stderr,".");
355   measurement_counter_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
356                                                            &measurement_counter,
357                                                            NULL);
358 }
359
360 static void
361 measurement_end (void *cls,
362            const struct GNUNET_SCHEDULER_TaskContext *tc)
363 {
364   static int strike_counter;
365   unsigned long long  quota_allowed = 0;
366   int delta = 0;
367
368   measurement_task  = GNUNET_SCHEDULER_NO_TASK;
369   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
370         return;
371
372   measurement_running = GNUNET_NO;
373   struct GNUNET_TIME_Relative duration = GNUNET_TIME_absolute_get_difference(start_time, GNUNET_TIME_absolute_get());
374
375
376   if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
377   {
378     GNUNET_SCHEDULER_cancel (measurement_counter_task);
379     measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
380   }
381
382   if (transmit_handle != NULL)
383   {
384           GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle);
385           transmit_handle = NULL;
386   }
387
388   if (current_quota_p1 < current_quota_p2)
389           quota_allowed = current_quota_p1;
390   else
391           quota_allowed = current_quota_p2;
392
393
394   if (MEASUREMENT_SOFT_LIMIT > (quota_allowed/10))
395           delta = MEASUREMENT_SOFT_LIMIT;
396   else
397           delta = (quota_allowed/10);
398
399   /* Throughput is far too slow. This is to prevent the test to exit with success when throughput is 0 */
400   if ((total_bytes_sent/(duration.rel_value / 1000)) < 100)
401   {
402           GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
403                           "\nQuota compliance failed: \n"\
404                           "Hard quota limit allowed: %10llu kB/s (%llu B/s)\n"\
405                           "Soft quota limit allowed: %10llu kB/s (%llu B/s)\n"\
406                           "Throughput              : %10llu kB/s (%llu B/s)\n",
407                           (quota_allowed / (1024)), quota_allowed,
408                           ((quota_allowed+delta) / (1024)),  quota_allowed+delta,
409                           (total_bytes_sent/(duration.rel_value / 1000)/1024),
410                           total_bytes_sent/(duration.rel_value / 1000));
411           ok = 1;
412           end();
413   }
414
415   /* Throughput is bigger than allowed quota + some extra*/
416   if ((total_bytes_sent/(duration.rel_value / 1000)) > (quota_allowed + delta))
417   {
418           GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
419                           "\nQuota compliance failed: \n"\
420                           "Hard quota limit allowed: %10llu kB/s (%llu B/s)\n"\
421                           "Soft quota limit allowed: %10llu kB/s (%llu B/s)\n"\
422                           "Throughput              : %10llu kB/s (%llu B/s)\n", 
423                           (quota_allowed / (1024)), quota_allowed, 
424                           ((quota_allowed+delta) / (1024)),  quota_allowed+delta, 
425                           (total_bytes_sent/(duration.rel_value / 1000)/1024), 
426                           total_bytes_sent/(duration.rel_value / 1000));
427           ok = 1;
428           end();
429           return;
430   }
431   else
432   {
433           GNUNET_log (GNUNET_ERROR_TYPE_INFO,
434                           "\nQuota compliance ok: \n"\
435                           "Quota allowed: %10llu kB/s\n"\
436                           "Throughput   : %10llu kB/s\n", (quota_allowed / (1024)) , (total_bytes_sent/(duration.rel_value / 1000)/1024));
437           ok = 0;
438   }
439
440   if ((quota_allowed) > (2 *(total_bytes_sent/(duration.rel_value / 1000))))
441   {
442           strike_counter++;
443           if (strike_counter == 2)
444           {
445                   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
446                                   "Maximum transmission rate reached, stopping test\n");
447                   end();
448                   return;
449           }
450   }
451   else
452   {
453           strike_counter = 0;
454   }
455
456   if (quota_allowed == MEASUREMENT_MAX_QUOTA)
457   {
458           end();
459           return;
460   }
461
462   if (is_asymmetric_send_constant == GNUNET_YES)
463   {
464    if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA)
465           measure (current_quota_p1 * 2, MEASUREMENT_MAX_QUOTA);
466    else
467            measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA);
468   }
469   else if (is_asymmetric_recv_constant == GNUNET_YES)
470   {
471    if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA)
472           measure (MEASUREMENT_MAX_QUOTA, current_quota_p2 * 2);
473    else
474            measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA);
475   }
476   else
477   {
478    if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA)
479           measure ((current_quota_p1) * 2, (current_quota_p2) * 2);
480    else
481            measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA);
482   }
483 }
484
485 static void measure (unsigned long long quota_p1, unsigned long long quota_p2 )
486 {
487           current_quota_p1 = quota_p1;
488           current_quota_p2 = quota_p2;
489 #if VERBOSE
490   if ((is_asymmetric_send_constant == GNUNET_YES) || (is_asymmetric_recv_constant == GNUNET_YES))
491           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
492               "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);
493   else
494           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
495               "Starting transport level measurement for %u seconds, symmetric quota %llu kB/s\n", MEASUREMENT_INTERVALL.rel_value / 1000 , current_quota_p2 / 1024);
496
497 #endif
498                 GNUNET_TRANSPORT_set_quota (p1.th,
499                           &p2.id,
500                           GNUNET_BANDWIDTH_value_init (current_quota_p1 ),
501                           GNUNET_BANDWIDTH_value_init (current_quota_p1 ),
502                           GNUNET_TIME_UNIT_FOREVER_REL,
503                           NULL, NULL);
504                 GNUNET_TRANSPORT_set_quota (p2.th,
505                           &p1.id,
506                           GNUNET_BANDWIDTH_value_init (current_quota_p2),
507                           GNUNET_BANDWIDTH_value_init (current_quota_p2),
508                           GNUNET_TIME_UNIT_FOREVER_REL,
509                           NULL, NULL);
510
511                 GNUNET_SCHEDULER_cancel (die_task);
512                 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
513                                                    &end_badly,
514                                                    NULL);
515                 if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
516                   GNUNET_SCHEDULER_cancel (measurement_counter_task);
517                 measurement_counter_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
518                                                                    &measurement_counter,
519                                                                    NULL);
520                 measurement_task = GNUNET_SCHEDULER_add_delayed (MEASUREMENT_INTERVALL,
521                                                    &measurement_end,
522                                                    NULL);
523                 total_bytes_sent = 0;
524                 last_msg_sent = 0;
525                 last_msg_recv = 0;
526                 measurement_running = GNUNET_YES;
527                 start_time = GNUNET_TIME_absolute_get ();
528
529                 if (transmit_handle != NULL)
530                           GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle);
531                 transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
532                                                                                           &p1.id,
533                                                                                           get_size (), 0, SEND_TIMEOUT,
534                                                                                           &notify_ready,
535                                                                                           NULL);
536 }
537
538 static void
539 notify_connect (void *cls,
540                 const struct GNUNET_PeerIdentity *peer,
541                 struct GNUNET_TIME_Relative latency,
542                 uint32_t distance)
543 {
544   if (cls == &p1)
545     {
546 #if DEBUG_CONNECTIONS
547   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
548               "Peer 1 `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls);
549 #endif
550           connected++;
551     }
552   else
553     {
554 #if DEBUG_CONNECTIONS
555   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
556               "Peer 2 `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls);
557 #endif
558       connected++;
559     }
560   if (connected == 2)
561     {
562            if (is_asymmetric_send_constant == GNUNET_YES)
563                    measure (MEASUREMENT_MIN_QUOTA, MEASUREMENT_MAX_QUOTA);
564            else if (is_asymmetric_recv_constant == GNUNET_YES)
565                    measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MIN_QUOTA);
566            else
567                    measure (MEASUREMENT_MIN_QUOTA, MEASUREMENT_MIN_QUOTA);
568     }
569 }
570
571
572 static void
573 notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
574 {
575 #if DEBUG_CONNECTIONS
576   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
577               "Peer `%4s' disconnected (%p)!\n",
578               GNUNET_i2s (peer), cls);
579 #endif
580 }
581
582
583 static void
584 setup_peer (struct PeerContext *p, const char *cfgname)
585 {
586   p->cfg = GNUNET_CONFIGURATION_create ();
587 #if START_ARM
588   p->arm_proc = GNUNET_OS_start_process (NULL, NULL,
589                                         "gnunet-service-arm",
590                                         "gnunet-service-arm",
591 #if VERBOSE_ARM
592                                         "-L", "DEBUG",
593 #endif
594                                         "-c", cfgname, NULL);
595 #endif
596
597   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
598   p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL,
599                                     p,
600                                     &notify_receive_new,
601                                     &notify_connect,
602                                     &notify_disconnect);
603   GNUNET_assert (p->th != NULL);
604 }
605
606
607 static void
608 exchange_hello_last (void *cls,
609                      const struct GNUNET_MessageHeader *message)
610 {
611   struct PeerContext *me = cls;
612
613   GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, me);
614
615   GNUNET_assert (ok >= 3);
616   OKPP;
617   GNUNET_assert (message != NULL);
618   GNUNET_assert (GNUNET_OK ==
619                  GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
620                                       message, &me->id));
621   /* both HELLOs exchanged, get ready to test transmission! */
622 }
623
624
625 static void
626 exchange_hello (void *cls,
627                 const struct GNUNET_MessageHeader *message)
628 {
629   struct PeerContext *me = cls;
630
631   GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, me);
632   GNUNET_assert (ok >= 2);
633   OKPP;
634   GNUNET_assert (message != NULL);
635   GNUNET_assert (GNUNET_OK ==
636                  GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
637                                       message, &me->id));
638   GNUNET_TRANSPORT_offer_hello (p2.th, message);
639   GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2);
640 }
641
642 static void
643 run (void *cls,
644      char *const *args,
645      const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
646 {
647   GNUNET_assert (ok == 1);
648   OKPP;
649
650   die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
651                                            &end_badly,
652                                            NULL);
653   measurement_running = GNUNET_NO;
654   send_running = GNUNET_NO;
655   recv_running = GNUNET_NO;
656
657   if (is_tcp)
658     {
659           if (is_asymmetric_recv_constant == GNUNET_YES)
660                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (receiver quota constant) for TCP transport plugin\n");
661           else if (is_asymmetric_send_constant == GNUNET_YES)
662                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (sender quota constant) for TCP transport plugin\n");
663           else
664                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing symmetric quota compliance for TCP transport plugin\n");
665       setup_peer (&p1, "test_quota_compliance_tcp_peer1.conf");
666       setup_peer (&p2, "test_quota_compliance_tcp_peer2.conf");
667     }
668   else if (is_http)
669     {
670           if (is_asymmetric_recv_constant == GNUNET_YES)
671                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (receiver quota constant) for HTTP transport plugin\n");
672           else if (is_asymmetric_send_constant == GNUNET_YES)
673                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (sender quota constant) for HTTP transport plugin\n");
674           else
675                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing symmetric quota compliance for HTTP transport plugin\n");
676       setup_peer (&p1, "test_quota_compliance_http_peer1.conf");
677       setup_peer (&p2, "test_quota_compliance_http_peer2.conf");
678     }
679   else if (is_https)
680     {
681           if (is_asymmetric_recv_constant == GNUNET_YES)
682                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (receiver quota constant) for HTTPS transport plugin\n");
683           else if (is_asymmetric_send_constant == GNUNET_YES)
684                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (sender quota constant) for HTTPS transport plugin\n");
685           else
686                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing symmetric quota compliance for HTTPS transport plugin\n");
687       setup_peer (&p1, "test_quota_compliance_https_peer1.conf");
688       setup_peer (&p2, "test_quota_compliance_https_peer2.conf");
689     }
690   else if (is_udp)
691     {
692           if (is_asymmetric_recv_constant == GNUNET_YES)
693                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (receiver quota constant) for UDP transport plugin\n");
694           else if (is_asymmetric_send_constant == GNUNET_YES)
695                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (sender quota constant) for UDP transport plugin\n");
696           else
697                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing symmetric quota compliance for UDP transport plugin\n");
698       setup_peer (&p1, "test_quota_compliance_udp_peer1.conf");
699       setup_peer (&p2, "test_quota_compliance_udp_peer2.conf");
700     }
701   else if (is_tcp_nat)
702     {
703           if (is_asymmetric_recv_constant == GNUNET_YES)
704                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (receiver quota constant) for TCP NAT transport plugin\n");
705           else if (is_asymmetric_send_constant == GNUNET_YES)
706                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (sender quota constant) for TCP NAT transport plugin\n");
707           else
708                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing symmetric quota compliance for TCP NAT transport plugin\n");
709       setup_peer (&p1, "test_quota_compliance_tcp_peer1.conf");
710       setup_peer (&p2, "test_quota_compliance_tcp_peer2.conf");
711     }
712   else
713     GNUNET_assert (0);
714
715   GNUNET_assert(p1.th != NULL);
716   GNUNET_assert(p2.th != NULL);
717   GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
718 }
719
720 int
721 main (int argc, char *argv[])
722 {
723   int ret = 0;
724 #ifdef MINGW
725   return GNUNET_SYSERR;
726 #endif
727   if (strstr(argv[0], "tcp_nat") != NULL)
728     {
729       is_tcp_nat = GNUNET_YES;
730     }
731   else if (strstr(argv[0], "tcp") != NULL)
732     {
733       is_tcp = GNUNET_YES;
734     }
735   else if (strstr(argv[0], "https") != NULL)
736     {
737       is_https = GNUNET_YES;
738     }
739   else if (strstr(argv[0], "http") != NULL)
740     {
741       is_http = GNUNET_YES;
742     }
743   else if (strstr(argv[0], "udp") != NULL)
744     {
745       is_udp = GNUNET_YES;
746     }
747
748   if (strstr(argv[0], "asymmetric_recv") != NULL)
749   {
750       is_asymmetric_recv_constant = GNUNET_YES;
751   }
752   else
753           is_asymmetric_recv_constant = GNUNET_NO;
754   if (strstr(argv[0], "asymmetric_send") != NULL)
755   {
756       is_asymmetric_send_constant = GNUNET_YES;
757   }
758   else
759           is_asymmetric_send_constant = GNUNET_NO;
760
761   char * logger;
762   if (is_tcp == GNUNET_YES)
763   {
764           if (is_asymmetric_recv_constant == GNUNET_YES)
765                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","tcp","asymmetric_recv_constant");
766           else if (is_asymmetric_send_constant == GNUNET_YES)
767                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","tcp","asymmetric_send_constant");
768           else
769                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","tcp","symmetric");
770   }
771   if (is_udp == GNUNET_YES)
772   {
773           if (is_asymmetric_recv_constant == GNUNET_YES)
774                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","udp","asymmetric_recv_constant");
775           else if (is_asymmetric_send_constant == GNUNET_YES)
776                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","udp","asymmetric_send_constant");
777           else
778                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","udp","symmetric");
779   }
780   if (is_http == GNUNET_YES)
781   {
782           if (is_asymmetric_recv_constant == GNUNET_YES)
783                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","http","asymmetric_recv_constant");
784           else if (is_asymmetric_send_constant == GNUNET_YES)
785                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","http","asymmetric_send_constant");
786           else
787                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","http","symmetric");
788   }
789   if (is_https == GNUNET_YES)
790   {
791           if (is_asymmetric_recv_constant == GNUNET_YES)
792                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","https","asymmetric_recv_constant");
793           else if (is_asymmetric_send_constant == GNUNET_YES)
794                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","https","asymmetric_send_constant");
795           else
796                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","https","symmetric");
797   }
798   fprintf(stderr,  "Running `%s'\n", logger);
799   GNUNET_log_setup ("test-quota-compliance",
800 #if VERBOSE
801                     "DEBUG",
802 #else
803                     "WARNING",
804 #endif
805                     NULL);
806   char *const argv1[] = { "test-quota-compliance",
807     "-c",
808     "test_quota_compliance_data.conf",
809 #if VERBOSE
810     "-L", "DEBUG",
811 #endif
812     NULL
813   };
814   struct GNUNET_GETOPT_CommandLineOption options[] = {
815     GNUNET_GETOPT_OPTION_END
816   };
817   ok = 1;
818   GNUNET_PROGRAM_run ((sizeof (argv1) / sizeof (char *)) - 1,
819                       argv1, logger , "nohelp",
820                       options, &run, &ok);
821   ret = ok;
822   stop_arm (&p1);
823   stop_arm (&p2);
824   GNUNET_free(logger);
825   GNUNET_DISK_directory_remove ("/tmp/test_quota_compliance_peer1");
826   GNUNET_DISK_directory_remove ("/tmp/test_quota_compliance_peer2");
827   return ret;
828 }
829
830 /* end of test_quota_compliance.c */