(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, 2)
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   pid_t arm_pid;
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 struct GNUNET_SCHEDULER_Handle *sched;
125
126 static int ok;
127
128 static int connected;
129 static int measurement_running;
130 static int send_running;
131 static int recv_running;
132
133 static unsigned long long total_bytes_sent;
134 static unsigned long long last_msg_sent;
135 static unsigned long long last_msg_recv;
136 static unsigned long long current_quota_p1;
137 static unsigned long long current_quota_p2;
138
139 static int is_tcp;
140 static int is_tcp_nat;
141 static int is_http;
142 static int is_https;
143 static int is_udp;
144 static int is_asymmetric_send_constant;
145 static int is_asymmetric_recv_constant;
146
147 static struct GNUNET_TIME_Absolute start_time;
148
149 static GNUNET_SCHEDULER_TaskIdentifier die_task;
150 static GNUNET_SCHEDULER_TaskIdentifier measurement_task;
151 static GNUNET_SCHEDULER_TaskIdentifier measurement_counter_task;
152
153 struct GNUNET_TRANSPORT_TransmitHandle * transmit_handle;
154
155 #define OKPP do { ok++; } while (0)
156
157
158
159 static void
160 end_send ()
161 {
162
163 }
164
165 static void
166 end ()
167 {
168   GNUNET_SCHEDULER_cancel (sched, die_task);
169   die_task = GNUNET_SCHEDULER_NO_TASK;
170
171   if (measurement_task != GNUNET_SCHEDULER_NO_TASK)
172   {
173             GNUNET_SCHEDULER_cancel (sched, measurement_task);
174             measurement_task = GNUNET_SCHEDULER_NO_TASK;
175   }
176   if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
177   {
178             GNUNET_SCHEDULER_cancel (sched, measurement_counter_task);
179             measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
180   }
181   GNUNET_SCHEDULER_shutdown (sched);
182 #if DEBUG_CONNECTIONS
183   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
184 #endif
185   GNUNET_TRANSPORT_disconnect (p1.th);
186   GNUNET_TRANSPORT_disconnect (p2.th);
187 #if DEBUG_CONNECTIONS
188   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
189               "Transports disconnected, returning success!\n");
190 #endif
191   GNUNET_SCHEDULER_shutdown (sched);
192 }
193
194
195
196 static void
197 stop_arm (struct PeerContext *p)
198 {
199 #if START_ARM
200   if (0 != PLIBC_KILL (p->arm_pid, SIGTERM))
201     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
202   GNUNET_OS_process_wait (p->arm_pid);
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 (sched, measurement_task);
215             measurement_task = GNUNET_SCHEDULER_NO_TASK;
216   }
217   if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
218   {
219             GNUNET_SCHEDULER_cancel (sched, 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 #if VERBOSE
354   fprintf(stderr,".");
355 #endif
356   measurement_counter_task = GNUNET_SCHEDULER_add_delayed (sched,
357                                                            GNUNET_TIME_UNIT_SECONDS,
358                                                            &measurement_counter,
359                                                            NULL);
360 }
361
362 static void
363 measurement_end (void *cls,
364            const struct GNUNET_SCHEDULER_TaskContext *tc)
365 {
366   static int strike_counter;
367   unsigned long long  quota_allowed = 0;
368   int delta = 0;
369
370   measurement_task  = GNUNET_SCHEDULER_NO_TASK;
371   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
372         return;
373
374   measurement_running = GNUNET_NO;
375   struct GNUNET_TIME_Relative duration = GNUNET_TIME_absolute_get_difference(start_time, GNUNET_TIME_absolute_get());
376
377
378   if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
379   {
380     GNUNET_SCHEDULER_cancel (sched, measurement_counter_task);
381     measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
382   }
383 #if VERBOSE
384   fprintf(stderr,"\n");
385 #endif
386
387   if (transmit_handle != NULL)
388   {
389           GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle);
390           transmit_handle = NULL;
391   }
392
393   if (current_quota_p1 < current_quota_p2)
394           quota_allowed = current_quota_p1;
395   else
396           quota_allowed = current_quota_p2;
397
398
399   if (MEASUREMENT_SOFT_LIMIT > (quota_allowed/10))
400           delta = MEASUREMENT_SOFT_LIMIT;
401   else
402           delta = (quota_allowed/10);
403
404   if ((total_bytes_sent/(duration.rel_value / 1000)) > (quota_allowed + delta))
405   {
406           GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
407                           "\nQuota compliance failed: \n"\
408                           "Hard quota limit allowed: %10llu kB/s (%llu B/s)\n"\
409                           "Soft quota limit allowed: %10llu kB/s (%llu B/s)\n"\
410                           "Throughput              : %10llu kB/s (%llu B/s)\n", 
411                           (quota_allowed / (1024)), quota_allowed, 
412                           ((quota_allowed+delta) / (1024)),  quota_allowed+delta, 
413                           (total_bytes_sent/(duration.rel_value / 1000)/1024), 
414                           total_bytes_sent/(duration.rel_value / 1000));
415           ok = 1;
416           end();
417           return;
418   }
419   else
420   {
421           GNUNET_log (GNUNET_ERROR_TYPE_INFO,
422                           "\nQuota compliance ok: \n"\
423                           "Quota allowed: %10llu kB/s\n"\
424                           "Throughput   : %10llu kB/s\n", (quota_allowed / (1024)) , (total_bytes_sent/(duration.rel_value / 1000)/1024));
425           ok = 0;
426   }
427
428   if ((quota_allowed) > (2 *(total_bytes_sent/(duration.rel_value / 1000))))
429   {
430           strike_counter++;
431           if (strike_counter == 2)
432           {
433                   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
434                                   "Maximum transmission rate reached, stopping test\n");
435                   end();
436                   return;
437           }
438   }
439   else
440   {
441           strike_counter = 0;
442   }
443
444   if (quota_allowed == MEASUREMENT_MAX_QUOTA)
445   {
446           end();
447           return;
448   }
449
450   if (is_asymmetric_send_constant == GNUNET_YES)
451   {
452    if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA)
453           measure (current_quota_p1 * 2, MEASUREMENT_MAX_QUOTA);
454    else
455            measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA);
456   }
457   else if (is_asymmetric_recv_constant == GNUNET_YES)
458   {
459    if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA)
460           measure (MEASUREMENT_MAX_QUOTA, current_quota_p2 * 2);
461    else
462            measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA);
463   }
464   else
465   {
466    if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA)
467           measure ((current_quota_p1) * 2, (current_quota_p2) * 2);
468    else
469            measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA);
470   }
471 }
472
473 static void measure (unsigned long long quota_p1, unsigned long long quota_p2 )
474 {
475           current_quota_p1 = quota_p1;
476           current_quota_p2 = quota_p2;
477 #if VERBOSE
478   if ((is_asymmetric_send_constant == GNUNET_YES) || (is_asymmetric_recv_constant == GNUNET_YES))
479           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
480               "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);
481   else
482           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
483               "Starting transport level measurement for %u seconds, symmetric quota %llu kB/s\n", MEASUREMENT_INTERVALL.rel_value / 1000 , current_quota_p2 / 1024);
484
485 #endif
486                 GNUNET_TRANSPORT_set_quota (p1.th,
487                           &p2.id,
488                           GNUNET_BANDWIDTH_value_init (current_quota_p1 ),
489                           GNUNET_BANDWIDTH_value_init (current_quota_p1 ),
490                           GNUNET_TIME_UNIT_FOREVER_REL,
491                           NULL, NULL);
492                 GNUNET_TRANSPORT_set_quota (p2.th,
493                           &p1.id,
494                           GNUNET_BANDWIDTH_value_init (current_quota_p2),
495                           GNUNET_BANDWIDTH_value_init (current_quota_p2),
496                           GNUNET_TIME_UNIT_FOREVER_REL,
497                           NULL, NULL);
498
499                 GNUNET_SCHEDULER_cancel (sched, die_task);
500                 die_task = GNUNET_SCHEDULER_add_delayed (sched,
501                                                    TIMEOUT,
502                                                    &end_badly,
503                                                    NULL);
504                 if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
505                   GNUNET_SCHEDULER_cancel (sched, measurement_counter_task);
506                 measurement_counter_task = GNUNET_SCHEDULER_add_delayed (sched,
507                                                                    GNUNET_TIME_UNIT_SECONDS,
508                                                                    &measurement_counter,
509                                                                    NULL);
510                 measurement_task = GNUNET_SCHEDULER_add_delayed (sched,
511                                                    MEASUREMENT_INTERVALL,
512                                                    &measurement_end,
513                                                    NULL);
514                 total_bytes_sent = 0;
515                 last_msg_sent = 0;
516                 last_msg_recv = 0;
517                 measurement_running = GNUNET_YES;
518                 start_time = GNUNET_TIME_absolute_get ();
519
520                 if (transmit_handle != NULL)
521                           GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle);
522                 transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
523                                                                                           &p1.id,
524                                                                                           get_size (), 0, SEND_TIMEOUT,
525                                                                                           &notify_ready,
526                                                                                           NULL);
527 }
528
529 static void
530 notify_connect (void *cls,
531                 const struct GNUNET_PeerIdentity *peer,
532                 struct GNUNET_TIME_Relative latency,
533                 uint32_t distance)
534 {
535   if (cls == &p1)
536     {
537 #if DEBUG_CONNECTIONS
538   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
539               "Peer 1 `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls);
540 #endif
541           connected++;
542     }
543   else
544     {
545 #if DEBUG_CONNECTIONS
546   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
547               "Peer 2 `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls);
548 #endif
549       connected++;
550     }
551   if (connected == 2)
552     {
553            if (is_asymmetric_send_constant == GNUNET_YES)
554                    measure (MEASUREMENT_MIN_QUOTA, MEASUREMENT_MAX_QUOTA);
555            else if (is_asymmetric_recv_constant == GNUNET_YES)
556                    measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MIN_QUOTA);
557            else
558                    measure (MEASUREMENT_MIN_QUOTA, MEASUREMENT_MIN_QUOTA);
559     }
560 }
561
562
563 static void
564 notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
565 {
566 #if DEBUG_CONNECTIONS
567   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
568               "Peer `%4s' disconnected (%p)!\n",
569               GNUNET_i2s (peer), cls);
570 #endif
571 }
572
573
574 static void
575 setup_peer (struct PeerContext *p, const char *cfgname)
576 {
577   p->cfg = GNUNET_CONFIGURATION_create ();
578 #if START_ARM
579   p->arm_pid = GNUNET_OS_start_process (NULL, NULL,
580                                         "gnunet-service-arm",
581                                         "gnunet-service-arm",
582 #if VERBOSE_ARM
583                                         "-L", "DEBUG",
584 #endif
585                                         "-c", cfgname, NULL);
586 #endif
587
588   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
589   p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, NULL,
590                                     p,
591                                     &notify_receive_new,
592                                     &notify_connect,
593                                     &notify_disconnect);
594   GNUNET_assert (p->th != NULL);
595 }
596
597
598 static void
599 exchange_hello_last (void *cls,
600                      const struct GNUNET_MessageHeader *message)
601 {
602   struct PeerContext *me = cls;
603
604   GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, me);
605
606   GNUNET_assert (ok >= 3);
607   OKPP;
608   GNUNET_assert (message != NULL);
609   GNUNET_assert (GNUNET_OK ==
610                  GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
611                                       message, &me->id));
612   /* both HELLOs exchanged, get ready to test transmission! */
613 }
614
615
616 static void
617 exchange_hello (void *cls,
618                 const struct GNUNET_MessageHeader *message)
619 {
620   struct PeerContext *me = cls;
621
622   GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, me);
623   GNUNET_assert (ok >= 2);
624   OKPP;
625   GNUNET_assert (message != NULL);
626   GNUNET_assert (GNUNET_OK ==
627                  GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
628                                       message, &me->id));
629   GNUNET_TRANSPORT_offer_hello (p2.th, message);
630   GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2);
631 }
632
633 static void
634 run (void *cls,
635      struct GNUNET_SCHEDULER_Handle *s,
636      char *const *args,
637      const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
638 {
639   GNUNET_assert (ok == 1);
640   OKPP;
641   sched = s;
642
643   die_task = GNUNET_SCHEDULER_add_delayed (sched,
644                                            TIMEOUT,
645                                            &end_badly,
646                                            NULL);
647   measurement_running = GNUNET_NO;
648   send_running = GNUNET_NO;
649   recv_running = GNUNET_NO;
650
651   if (is_tcp)
652     {
653           if (is_asymmetric_recv_constant == GNUNET_YES)
654                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (receiver quota constant) for TCP transport plugin\n");
655           else if (is_asymmetric_send_constant == GNUNET_YES)
656                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (sender quota constant) for TCP transport plugin\n");
657           else
658                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing symmetric quota compliance for TCP transport plugin\n");
659       setup_peer (&p1, "test_quota_compliance_tcp_peer1.conf");
660       setup_peer (&p2, "test_quota_compliance_tcp_peer2.conf");
661     }
662   else if (is_http)
663     {
664           if (is_asymmetric_recv_constant == GNUNET_YES)
665                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (receiver quota constant) for HTTP transport plugin\n");
666           else if (is_asymmetric_send_constant == GNUNET_YES)
667                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (sender quota constant) for HTTP transport plugin\n");
668           else
669                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing symmetric quota compliance for HTTP transport plugin\n");
670       setup_peer (&p1, "test_quota_compliance_http_peer1.conf");
671       setup_peer (&p2, "test_quota_compliance_http_peer2.conf");
672     }
673   else if (is_https)
674     {
675           if (is_asymmetric_recv_constant == GNUNET_YES)
676                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (receiver quota constant) for HTTPS transport plugin\n");
677           else if (is_asymmetric_send_constant == GNUNET_YES)
678                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (sender quota constant) for HTTPS transport plugin\n");
679           else
680                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing symmetric quota compliance for HTTPS transport plugin\n");
681       setup_peer (&p1, "test_quota_compliance_https_peer1.conf");
682       setup_peer (&p2, "test_quota_compliance_https_peer2.conf");
683     }
684   else if (is_udp)
685     {
686           if (is_asymmetric_recv_constant == GNUNET_YES)
687                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (receiver quota constant) for UDP transport plugin\n");
688           else if (is_asymmetric_send_constant == GNUNET_YES)
689                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (sender quota constant) for UDP transport plugin\n");
690           else
691                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing symmetric quota compliance for UDP transport plugin\n");
692       setup_peer (&p1, "test_quota_compliance_udp_peer1.conf");
693       setup_peer (&p2, "test_quota_compliance_udp_peer2.conf");
694     }
695   else if (is_tcp_nat)
696     {
697           if (is_asymmetric_recv_constant == GNUNET_YES)
698                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (receiver quota constant) for TCP NAT transport plugin\n");
699           else if (is_asymmetric_send_constant == GNUNET_YES)
700                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing asymmetric quota compliance (sender quota constant) for TCP NAT transport plugin\n");
701           else
702                   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing symmetric quota compliance for TCP NAT transport plugin\n");
703       setup_peer (&p1, "test_quota_compliance_tcp_peer1.conf");
704       setup_peer (&p2, "test_quota_compliance_tcp_peer2.conf");
705     }
706   else
707     GNUNET_assert (0);
708
709   GNUNET_assert(p1.th != NULL);
710   GNUNET_assert(p2.th != NULL);
711   GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
712 }
713
714 int
715 main (int argc, char *argv[])
716 {
717   int ret = 0;
718 #ifdef MINGW
719   return GNUNET_SYSERR;
720 #endif
721   if (strstr(argv[0], "tcp_nat") != NULL)
722     {
723       is_tcp_nat = GNUNET_YES;
724     }
725   else if (strstr(argv[0], "tcp") != NULL)
726     {
727       is_tcp = GNUNET_YES;
728     }
729   else if (strstr(argv[0], "https") != NULL)
730     {
731       is_https = GNUNET_YES;
732     }
733   else if (strstr(argv[0], "http") != NULL)
734     {
735       is_http = GNUNET_YES;
736     }
737   else if (strstr(argv[0], "udp") != NULL)
738     {
739       is_udp = GNUNET_YES;
740     }
741
742   if (strstr(argv[0], "asymmetric_recv") != NULL)
743   {
744       is_asymmetric_recv_constant = GNUNET_YES;
745   }
746   else
747           is_asymmetric_recv_constant = GNUNET_NO;
748   if (strstr(argv[0], "asymmetric_send") != NULL)
749   {
750       is_asymmetric_send_constant = GNUNET_YES;
751   }
752   else
753           is_asymmetric_send_constant = GNUNET_NO;
754
755   char * logger;
756   if (is_tcp == GNUNET_YES)
757   {
758           if (is_asymmetric_recv_constant == GNUNET_YES)
759                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","tcp","asymmetric_recv_constant");
760           else if (is_asymmetric_send_constant == GNUNET_YES)
761                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","tcp","asymmetric_send_constant");
762           else
763                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","tcp","symmetric");
764   }
765   if (is_udp == GNUNET_YES)
766   {
767           if (is_asymmetric_recv_constant == GNUNET_YES)
768                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","udp","asymmetric_recv_constant");
769           else if (is_asymmetric_send_constant == GNUNET_YES)
770                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","udp","asymmetric_send_constant");
771           else
772                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","udp","symmetric");
773   }
774   if (is_http == GNUNET_YES)
775   {
776           if (is_asymmetric_recv_constant == GNUNET_YES)
777                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","http","asymmetric_recv_constant");
778           else if (is_asymmetric_send_constant == GNUNET_YES)
779                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","http","asymmetric_send_constant");
780           else
781                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","http","symmetric");
782   }
783   if (is_https == GNUNET_YES)
784   {
785           if (is_asymmetric_recv_constant == GNUNET_YES)
786                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","https","asymmetric_recv_constant");
787           else if (is_asymmetric_send_constant == GNUNET_YES)
788                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","https","asymmetric_send_constant");
789           else
790                   GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","https","symmetric");
791   }
792   fprintf(stderr,  "Running `%s'\n", logger);
793   GNUNET_log_setup ("test-quota-compliance",
794 #if VERBOSE
795                     "DEBUG",
796 #else
797                     "WARNING",
798 #endif
799                     NULL);
800   char *const argv1[] = { "test-quota-compliance",
801     "-c",
802     "test_quota_compliance_data.conf",
803 #if VERBOSE
804     "-L", "DEBUG",
805 #endif
806     NULL
807   };
808   struct GNUNET_GETOPT_CommandLineOption options[] = {
809     GNUNET_GETOPT_OPTION_END
810   };
811   ok = 1;
812   GNUNET_PROGRAM_run ((sizeof (argv1) / sizeof (char *)) - 1,
813                       argv1, logger , "nohelp",
814                       options, &run, &ok);
815   ret = ok;
816   stop_arm (&p1);
817   stop_arm (&p2);
818   GNUNET_free(logger);
819   GNUNET_DISK_directory_remove ("/tmp/test_quota_compliance_peer1");
820   GNUNET_DISK_directory_remove ("/tmp/test_quota_compliance_peer2");
821   return ret;
822 }
823
824 /* end of test_quota_compliance.c */