really reuse the dns-tunnel
[oweals/gnunet.git] / src / transport / test_plugin_transport_http.c
1 /*
2      This file is part of GNUnet.
3      (C) 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_plugin_transport_http.c
22  * @brief testcase for plugin_transport_http.c
23  * @author Matthias Wachs
24  */
25
26 #include "platform.h"
27 #include "gnunet_constants.h"
28 #include "gnunet_common.h"
29 #include "gnunet_getopt_lib.h"
30 #include "gnunet_hello_lib.h"
31 #include "gnunet_os_lib.h"
32 #include "gnunet_peerinfo_service.h"
33 #include "gnunet_plugin_lib.h"
34 #include "gnunet_protocols.h"
35 #include "gnunet_program_lib.h"
36 #include "gnunet_signatures.h"
37 #include "gnunet_service_lib.h"
38 #include "gnunet_crypto_lib.h"
39
40 #include "gnunet_transport_plugin.h"
41 #include "gnunet_statistics_service.h"
42 #include "transport.h"
43 #include <curl/curl.h>
44
45 #define VERBOSE GNUNET_NO
46 #define DEBUG_CURL GNUNET_NO
47 #define HTTP_BUFFER_SIZE 2048
48
49 #define PROTOCOL_PREFIX "http"
50
51 #define PLUGIN libgnunet_plugin_transport_template
52
53 /**
54  * How long until we give up on transmitting the message?
55  */
56 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
57
58 /**
59  * Testcase timeout
60  */
61 #define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20)
62
63 /**
64  * How long between recieve and send?
65  */
66 #define WAIT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
67
68
69
70 /**
71  *  Struct for plugin addresses
72  */
73 struct Plugin_Address
74 {
75   /**
76    * Next field for linked list
77    */
78   struct Plugin_Address * next;
79
80   /**
81    * buffer containing data to send
82    */
83   void * addr;
84
85   /**
86    * amount of data to sent
87    */
88   size_t addrlen;
89 };
90
91 /**
92  *  Message to send using http
93  */
94 struct HTTP_Message
95 {
96   /**
97    * buffer
98    */
99   unsigned char buf[HTTP_BUFFER_SIZE];
100
101   /**
102    * current position in buffer
103    */
104   size_t pos;
105
106   /**
107    * buffer size
108    */
109   size_t size;
110
111   /**
112    * data size
113    */
114   size_t len;
115 };
116
117
118 /**
119  *  Struct for plugin addresses
120  */
121 struct HTTP_Transfer
122 {
123   /**
124    * amount of bytes we recieved
125    */
126   size_t data_size;
127
128   /**
129    * buffer for http transfers
130    */
131   unsigned char buf[HTTP_BUFFER_SIZE];
132
133   /**
134    * buffer size this transfer
135    */
136   size_t size;
137
138   /**
139    * amount of bytes we recieved
140    */
141   size_t pos;
142
143   /**
144    * HTTP Header result for transfer
145    */
146   unsigned int http_result_code;
147
148   /**
149    * did the test fail?
150    */
151   unsigned int test_failed;
152
153   /**
154    * was this test already executed?
155    */
156   unsigned int test_executed;
157 };
158
159
160 /**
161  * Network format for IPv4 addresses.
162  */
163 struct IPv4HttpAddress
164 {
165   struct IPv4HttpAddress * next;
166
167   struct IPv4HttpAddress * prev;
168
169   /**
170    * IPv4 address, in network byte order.
171    */
172   uint32_t ipv4_addr GNUNET_PACKED;
173
174   /**
175    * Port number, in network byte order.
176    */
177   uint16_t u_port GNUNET_PACKED;
178
179 };
180
181
182 /**
183  * Network format for IPv6 addresses.
184  */
185 struct IPv6HttpAddress
186 {
187   struct IPv6HttpAddress * next;
188
189   struct IPv6HttpAddress * prev;
190
191   /**
192    * IPv6 address.
193    */
194   struct in6_addr ipv6_addr GNUNET_PACKED;
195
196   /**
197    * Port number, in network byte order.
198    */
199   uint16_t u6_port GNUNET_PACKED;
200
201 };
202
203
204 /**
205  * Our public key.
206  */
207 /* static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key; */
208
209 /**
210  * Our public key.
211  */
212 static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key;
213
214 /**
215  * Our identity.
216  */
217 static struct GNUNET_PeerIdentity my_identity;
218
219 /**
220  * Our private key.
221  */
222 static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
223
224 /**
225  * Peer's port
226  */
227 static long long unsigned int port;
228
229 /**
230  * Peer's addr
231  */
232 static char * test_addr;
233
234 /**
235  * Our statistics handle.
236  */
237 struct GNUNET_STATISTICS_Handle *stats;
238
239
240 /**
241  * Our configuration.
242  */
243 const struct GNUNET_CONFIGURATION_Handle *cfg;
244
245 /**
246  * Number of neighbours we'd like to have.
247  */
248 static uint32_t max_connect_per_transport;
249
250 /**
251  * Environment for this plugin.
252  */
253 static struct GNUNET_TRANSPORT_PluginEnvironment env;
254
255 /**
256  *handle for the api provided by this plugin
257  */
258 static struct GNUNET_TRANSPORT_PluginFunctions *api;
259
260 /**
261  * ID of the task controlling the testcase timeout
262  */
263 static GNUNET_SCHEDULER_TaskIdentifier ti_timeout;
264
265 static GNUNET_SCHEDULER_TaskIdentifier ti_send;
266
267 //const struct GNUNET_PeerIdentity * p;
268
269 /**
270  * buffer for data to send
271  */
272 static struct HTTP_Message buffer_out;
273
274 /**
275  * buffer for data to recieve
276  */
277 static struct HTTP_Message buffer_in;
278
279
280 struct Plugin_Address * addr_head;
281
282 /**
283  * Did the test pass or fail?
284  */
285 static int fail_notify_address;
286 /**
287  * Did the test pass or fail?
288  */
289 static int fail_notify_address_count;
290
291 /**
292  * Did the test pass or fail?
293  */
294 static int fail_pretty_printer;
295
296 /**
297  * Did the test pass or fail?
298  */
299 static int fail_pretty_printer_count;
300
301 /**
302  * Did the test pass or fail?
303  */
304 static int fail_addr_to_str;
305
306 /**
307  * No. of msgs transmitted successfully to local addresses
308  */
309 static int fail_msgs_transmited_to_local_addrs;
310
311 /**
312  * Test: transmit msg of max. size
313  */
314 static int fail_msg_transmited_bigger_max_size;
315
316 /**
317  * Test: transmit msg of max. size
318  */
319 static int fail_msg_transmited_max_size;
320
321 /**
322  * Test: transmit 2 msgs. in in send operation
323  */
324 static int fail_multiple_msgs_in_transmission;
325
326 /**
327  * Test: connect to peer without peer identification
328  */
329 static struct HTTP_Transfer test_no_ident;
330
331 /**
332  * Test: connect to peer without peer identification
333  */
334 static struct HTTP_Transfer test_too_short_ident;
335
336 /**
337  * Test: connect to peer without peer identification
338  */
339 static struct HTTP_Transfer test_too_long_ident;
340
341 /**
342  * Test: connect to peer with valid peer identification
343  */
344 static struct HTTP_Transfer test_valid_ident;
345
346 /**
347  * Test: session selection, use any existing
348  */
349 static int fail_session_selection_any;
350
351 /**
352  * Test: session selection, use existing inbound session
353  */
354 static int fail_session_selection_session;
355
356 /**
357  * Test: session selection, use existing inbound session
358  * max message, not fitting in send & recv buffers at one time
359  */
360 static int fail_session_selection_session_big;
361
362 /**
363 * Test: session selection, use reliable existing
364  */
365 static int fail_session_selection_reliable;
366
367 /**
368  * Did the test pass or fail?
369  */
370 static int fail;
371
372 /**
373  * Number of local addresses
374  */
375 static unsigned int count_str_addr;
376
377 CURL *curl_handle;
378
379 /**
380  * cURL Multihandle
381  */
382 static CURLM *multi_handle;
383
384 /**
385  * The task sending data
386  */
387 static GNUNET_SCHEDULER_TaskIdentifier http_task_send;
388
389 static char * servicehome;
390
391 /**
392  * Shutdown testcase
393  */
394 static void
395 shutdown_clean ()
396 {
397   struct Plugin_Address * tmp;
398
399   /* Evaluate results  */
400   fail = 0;
401   if ( (fail_notify_address == GNUNET_YES) || 
402        (fail_pretty_printer == GNUNET_YES) || 
403        (fail_addr_to_str == GNUNET_YES))
404     {
405       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
406                   "Phase 0: Test plugin functions failed\n");
407       fail = 1;
408     }
409   if ( (test_no_ident.test_failed == GNUNET_YES) || 
410        (test_too_short_ident.test_failed == GNUNET_YES) || 
411        (test_too_long_ident.test_failed == GNUNET_YES) || 
412        (test_valid_ident.test_failed == GNUNET_YES) )
413   {
414     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
415                 "Phase 1: Test connect with wrong data failed\n");
416     fail = 1;
417   }
418   if ( (fail_session_selection_any != GNUNET_NO) || 
419        (fail_session_selection_reliable != GNUNET_NO) ||
420        (fail_session_selection_session != GNUNET_NO) || 
421        (fail_session_selection_session_big != GNUNET_NO) )
422     {
423       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
424                   "Phase 2: Test session selection failed\n");
425       fail = 1;
426     }
427   if ( (fail_msgs_transmited_to_local_addrs != count_str_addr) ||
428        (fail_multiple_msgs_in_transmission != 2) || 
429        (fail_msg_transmited_max_size == GNUNET_YES) )
430     {
431       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
432                   "Phase 3: Test sending with plugin failed\n");
433       fail = 1;
434     }
435   if (fail != 1)
436     {
437       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
438                   "All tests successful\n");
439     }
440   
441   api->disconnect(api->cls,&my_identity);
442
443   curl_multi_cleanup(multi_handle);
444
445   if (NULL != curl_handle)
446     curl_easy_cleanup (curl_handle);
447
448   /* cleaning addresses */
449   while (addr_head != NULL)
450   {
451     tmp = addr_head->next;
452     GNUNET_free (addr_head->addr);
453     GNUNET_free (addr_head);
454     addr_head=tmp;
455   }
456
457   if (ti_send != GNUNET_SCHEDULER_NO_TASK)
458   {
459     GNUNET_SCHEDULER_cancel(ti_send);
460     ti_send = GNUNET_SCHEDULER_NO_TASK;
461   }
462
463   if (http_task_send != GNUNET_SCHEDULER_NO_TASK)
464   {
465     GNUNET_SCHEDULER_cancel(http_task_send);
466     http_task_send = GNUNET_SCHEDULER_NO_TASK;
467   }
468
469   if (ti_timeout != GNUNET_SCHEDULER_NO_TASK)
470   {
471     GNUNET_SCHEDULER_cancel(ti_timeout);
472     ti_timeout = GNUNET_SCHEDULER_NO_TASK;
473   }
474
475   GNUNET_free(test_addr);
476   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
477               "Unloading http plugin\n");
478   GNUNET_assert (NULL == GNUNET_PLUGIN_unload ("libgnunet_gnunet_transport_plugin_http", api));
479
480   GNUNET_SCHEDULER_shutdown();
481   GNUNET_DISK_directory_remove ("/tmp/test_gnunet_transport_plugin_http");
482
483   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
484               "Exiting testcase\n");
485
486   if (servicehome != NULL)
487   {
488     GNUNET_DISK_directory_remove (servicehome);
489     GNUNET_free (servicehome);
490   }
491
492   exit(fail);
493   return;
494 }
495
496
497 /**
498  * Continuation called after plugin send message
499  * @cls closure
500  * @target target
501  * @result GNUNET_OK or GNUNET_SYSERR
502  */
503
504 static void
505 task_send_cont (void *cls,
506                 const struct GNUNET_PeerIdentity * target,
507                 int result)
508 {
509   if ((cls == &fail_msg_transmited_bigger_max_size) && (result == GNUNET_SYSERR))
510     {
511       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
512                   "Message bigger max msg size was not sent!\n");
513       fail_msg_transmited_bigger_max_size = GNUNET_NO;
514       return;
515     }
516
517   if ((cls == &fail_msg_transmited_max_size) && (result == GNUNET_OK))
518     {
519       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
520                   "Message with max msg size succesfully sent!\n",
521                   fail_msgs_transmited_to_local_addrs);
522       fail_msg_transmited_max_size = GNUNET_NO;
523     }
524 }
525
526
527 static void run_connection_tests( int phase , void * cls);
528
529 /**
530  * Recieves messages from plugin, in real world transport
531  */
532 static struct GNUNET_TIME_Relative
533 receive (void *cls, const struct GNUNET_PeerIdentity *peer,
534         const struct GNUNET_MessageHeader *message,
535         const struct GNUNET_TRANSPORT_ATS_Information *ats,
536         uint32_t ats_count,
537         struct Session *session,
538         const char *sender_address,
539         uint16_t sender_address_len)
540 {
541   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
542               "Testcase recieved new message from peer `%s' with type %u and length %u, session %X\n",
543               GNUNET_i2s(peer),
544               ntohs(message->type),
545               ntohs(message->size),
546               session);
547
548   if ( (ntohs(message->type)>=10) && 
549        (ntohs(message->type)<20) )
550     {
551       fail_msgs_transmited_to_local_addrs++;
552       if (fail_msgs_transmited_to_local_addrs == count_str_addr)
553         run_connection_tests(2, session);
554     }
555   if ((ntohs(message->type)==20))
556     {
557       fail_session_selection_reliable = GNUNET_NO;
558     }  
559   if ((ntohs(message->type)==21))
560     {
561       fail_session_selection_any = GNUNET_NO;
562     }
563   if ((ntohs(message->type)==22))
564     {
565       fail_session_selection_session = GNUNET_NO;
566     }  
567   if ((ntohs(message->type)==23))
568     {
569       fail_session_selection_session_big = GNUNET_NO;
570       run_connection_tests(3, NULL);
571     }  
572   if ((ntohs(message->type)==30) || (ntohs(message->type)==31))
573     {
574       fail_multiple_msgs_in_transmission ++;
575     }  
576   if ((ntohs(message->type)==32) && (ntohs(message->size) == GNUNET_SERVER_MAX_MESSAGE_SIZE-1))
577     {
578       fail_msg_transmited_max_size = GNUNET_NO;
579       shutdown_clean();
580     }  
581   return GNUNET_TIME_UNIT_ZERO;
582 }
583
584
585 static size_t 
586 send_function (void *stream, size_t size, size_t nmemb, void *ptr)
587 {
588   unsigned int len;
589
590   len = buffer_out.len;
591
592   if (( buffer_out.pos == len) || (len > (size * nmemb)))
593     return 0;
594   memcpy(stream, buffer_out.buf, len);
595   buffer_out.pos = len;
596   return len;
597
598 }
599
600 static size_t 
601 recv_function (void *ptr, size_t size, size_t nmemb, void *ctx)
602 {
603
604   if (buffer_in.pos + size * nmemb > buffer_in.size)
605     return 0;                   /* overflow */
606
607   buffer_in.len = size * nmemb;
608   memcpy (&buffer_in.buf[buffer_in.pos], ptr, size * nmemb);
609   buffer_in.pos += size * nmemb;
610   buffer_in.len = buffer_in.pos;
611   buffer_in.buf[buffer_in.pos] = '\0';
612   return buffer_in.pos;
613 }
614
615 static size_t
616 header_function( void *ptr, size_t size, size_t nmemb, void *stream)
617 {
618   struct HTTP_Transfer * res = stream;
619   char * tmp;
620   unsigned int len = size * nmemb;
621
622   tmp = GNUNET_malloc (  len+1 );
623   memcpy(tmp,ptr,len);
624   if (tmp[len-2] == 13)
625     tmp[len-2]= '\0';
626 #if DEBUG_CURL
627   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
628               "Header: `%s'\n",
629               tmp);
630 #endif
631   if (0==strcmp (tmp,"HTTP/1.1 100 Continue"))
632     {
633       res->http_result_code=100;
634     }
635   if (0==strcmp (tmp,"HTTP/1.1 200 OK"))
636     {
637       res->http_result_code=200;
638     }
639   if (0==strcmp (tmp,"HTTP/1.1 400 Bad Request"))
640     {
641       res->http_result_code=400;
642     }
643   if (0==strcmp (tmp,"HTTP/1.1 404 Not Found"))
644     {
645       res->http_result_code=404;
646     }
647   if (0==strcmp (tmp,"HTTP/1.1 413 Request entity too large"))
648     {
649       res->http_result_code=413;
650     }
651   
652   GNUNET_free (tmp);
653   return size * nmemb;
654 }
655
656
657 static size_t 
658 send_prepare( struct HTTP_Transfer * result);
659
660
661 static void 
662 send_execute (void *cls,
663               const struct GNUNET_SCHEDULER_TaskContext *tc)
664 {
665   struct HTTP_Transfer *res;
666
667   int running;
668   struct CURLMsg *msg;
669   CURLMcode mret;
670
671   res = (struct HTTP_Transfer *) cls;
672   http_task_send = GNUNET_SCHEDULER_NO_TASK;
673   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
674     return;
675
676   do
677     {
678       running = 0;
679       mret = curl_multi_perform (multi_handle, &running);
680       if (running == 0)
681         {
682           do
683             {
684
685               msg = curl_multi_info_read (multi_handle, &running);
686               if (msg == NULL)
687                 break;
688               /* get session for affected curl handle */
689               //cs = find_session_by_curlhandle (msg->easy_handle);
690               //GNUNET_assert ( cs != NULL );
691               switch (msg->msg)
692                 {
693
694                 case CURLMSG_DONE:
695                   if ( (msg->data.result != CURLE_OK) &&
696                        (msg->data.result != CURLE_GOT_NOTHING) )
697                     {
698
699                     GNUNET_log(GNUNET_ERROR_TYPE_INFO,
700                                _("curl failed for `%s' at %s:%d: `%s'\n"),
701                                "curl_multi_perform",
702                                __FILE__,
703                                __LINE__,
704                                curl_easy_strerror (msg->data.result));
705                     /* sending msg failed*/
706                     curl_easy_cleanup(curl_handle);
707                     curl_handle=NULL;
708
709                     run_connection_tests(0, NULL);
710                     }
711                   if (res == &test_no_ident)
712                   {
713                     if  ((res->http_result_code==404) && (buffer_in.len==208))
714                       {
715                       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
716                                   "Connecting to peer without any peer identification: test passed\n");
717                       res->test_failed = GNUNET_NO;
718                     }
719                     else
720                       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
721                                   _("Connecting to peer without any peer identification: test failed\n"));
722                   }
723                   if (res == &test_too_short_ident)
724                   {
725                     if  ((res->http_result_code==404) && (buffer_in.len==208))
726                     {
727                       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
728                                   "Connecting to peer with too short peer identification: test passed\n");
729                       res->test_failed = GNUNET_NO;
730                     }
731                     else
732                       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
733                                   _("Connecting to peer with too short peer identification: test failed\n"));
734                   }
735                   if (res == &test_too_long_ident)
736                   {
737                     if  ((res->http_result_code==404) && (buffer_in.len==208))
738                       {
739                       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
740                                   "Connecting to peer with too long peer identification: test passed\n");
741                       res->test_failed = GNUNET_NO;
742                       }
743                     else
744                       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
745                                   _("Connecting to peer with too long peer identification: test failed\n"));
746                   }
747                   if (res == &test_valid_ident)
748                   {
749                     if  ((res->http_result_code==200))
750                     {
751                       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
752                                   "Connecting to peer with valid peer identification: test passed\n");
753                       res->test_failed = GNUNET_NO;
754                     }
755                     else
756                       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
757                                   "Connecting to peer with valid peer identification: test failed\n");
758                   }
759                   curl_easy_cleanup(curl_handle);
760                   curl_handle=NULL;
761                   if ((res == &test_valid_ident) && (res->test_failed == GNUNET_NO))
762                     run_connection_tests(1, NULL);
763                   run_connection_tests(0, NULL);
764                   return;
765                 default:
766                   break;
767                 }
768
769             }
770           while ( (running > 0) );
771         }
772     }
773   while (mret == CURLM_CALL_MULTI_PERFORM);
774   send_prepare(cls);
775 }
776
777
778 /**
779  * Function setting up file descriptors and scheduling task to run
780  * @param ses session to send data to
781  * @return bytes sent to peer
782  */
783 static size_t
784 send_prepare( struct HTTP_Transfer * result)
785 {
786   fd_set rs;
787   fd_set ws;
788   fd_set es;
789   int max;
790   struct GNUNET_NETWORK_FDSet *grs;
791   struct GNUNET_NETWORK_FDSet *gws;
792   long to;
793   CURLMcode mret;
794
795   max = -1;
796   FD_ZERO (&rs);
797   FD_ZERO (&ws);
798   FD_ZERO (&es);
799   mret = curl_multi_fdset (multi_handle, &rs, &ws, &es, &max);
800   if (mret != CURLM_OK)
801     {
802       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
803                   _("%s failed at %s:%d: `%s'\n"),
804                   "curl_multi_fdset", __FILE__, __LINE__,
805                   curl_multi_strerror (mret));
806       return -1;
807     }
808   mret = curl_multi_timeout (multi_handle, &to);
809   if (mret != CURLM_OK)
810     {
811       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
812                   _("%s failed at %s:%d: `%s'\n"),
813                   "curl_multi_timeout", __FILE__, __LINE__,
814                   curl_multi_strerror (mret));
815       return -1;
816     }
817
818   grs = GNUNET_NETWORK_fdset_create ();
819   gws = GNUNET_NETWORK_fdset_create ();
820   GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
821   GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
822   http_task_send = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
823                                                 GNUNET_SCHEDULER_NO_TASK,
824                                                 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 0),
825                                                 grs,
826                                                 gws,
827                                                 &send_execute,
828                                                 result);
829   GNUNET_NETWORK_fdset_destroy (gws);
830   GNUNET_NETWORK_fdset_destroy (grs);
831
832   /* FIXME: return bytes REALLY sent */
833   return 0;
834 }
835
836 /**
837  * function to send data to server
838  */
839 static int 
840 send_data(struct HTTP_Transfer * result,
841           char * url)
842 {
843
844   curl_handle = curl_easy_init();
845   if( NULL == curl_handle)
846     {
847       printf("easy_init failed \n");
848       return GNUNET_SYSERR;
849     }
850 #if DEBUG_CURL
851   curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L);
852 #endif
853   curl_easy_setopt(curl_handle, CURLOPT_URL, url);
854   curl_easy_setopt(curl_handle, CURLOPT_PUT, 1L);
855   curl_easy_setopt (curl_handle, CURLOPT_HEADERFUNCTION, &header_function);
856   curl_easy_setopt (curl_handle, CURLOPT_WRITEHEADER, result);
857   curl_easy_setopt (curl_handle, CURLOPT_WRITEFUNCTION, &recv_function);
858   curl_easy_setopt (curl_handle, CURLOPT_WRITEDATA, result);
859   curl_easy_setopt (curl_handle, CURLOPT_READFUNCTION, &send_function);
860   curl_easy_setopt (curl_handle, CURLOPT_READDATA, result);
861   curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) buffer_out.len);
862   curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 30);
863   curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 20);
864
865   curl_multi_add_handle(multi_handle, curl_handle);
866
867   send_prepare(result);
868
869   return GNUNET_OK;
870 }
871
872 /**
873  * Plugin notifies transport (aka testcase) about its addresses
874  */
875 static void
876 notify_address (void *cls,
877                 int add_remove,
878                 const void *addr,
879                 size_t addrlen)
880 {
881   char address[INET6_ADDRSTRLEN];
882   unsigned int port;
883   struct Plugin_Address * pl_addr;
884   struct Plugin_Address * cur;
885
886   if (addrlen == (sizeof (struct IPv4HttpAddress)))
887     {
888       inet_ntop(AF_INET, (struct in_addr *) addr,address,INET_ADDRSTRLEN);
889       port = ntohs(((struct IPv4HttpAddress *) addr)->u_port);
890     }
891   else if (addrlen == (sizeof (struct IPv6HttpAddress)))
892     {
893       inet_ntop(AF_INET6, (struct in6_addr *) addr,address,INET6_ADDRSTRLEN);
894       port = ntohs(((struct IPv6HttpAddress *) addr)->u6_port);
895     }
896   else
897     {
898     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
899                 _("Unknown address size: ipv6 has %u ipv4 has %u but this has %u\n"),
900                 sizeof (struct IPv6HttpAddress),
901                 sizeof (struct IPv4HttpAddress),
902                 addrlen);
903       return;
904     }
905   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
906               _("Transport plugin notification for address: `%s':%u\n"),
907               address,
908               port);
909   pl_addr = GNUNET_malloc (sizeof (struct Plugin_Address) );
910   pl_addr->addrlen = addrlen;
911   pl_addr->addr = GNUNET_malloc(addrlen);
912   memcpy(pl_addr->addr,addr,addrlen);
913   pl_addr->next = NULL;
914
915   if ( NULL == addr_head)
916     {
917       addr_head = pl_addr;
918     }
919   else
920     {
921       cur = addr_head;
922       while (NULL != cur->next)
923         {
924           cur = cur->next;
925         }
926       cur->next = pl_addr;
927     }
928   fail_notify_address_count++;
929   fail_notify_address = GNUNET_NO;
930 }
931
932 static void
933 plugin_env_session_end (void *cls,
934                         const struct GNUNET_PeerIdentity *peer,
935                         struct Session *session)
936 {
937   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
938               "Pluging tells me: session %X to peer `%s' ended\n",
939               session,
940               GNUNET_i2s(peer));
941 }
942
943
944 /**
945  * Setup plugin environment
946  */
947 static void
948 setup_plugin_environment ()
949 {
950   env.cfg = cfg;
951   env.stats = stats;
952   env.my_identity = &my_identity;
953   env.cls = &env;
954   env.receive = &receive;
955   env.notify_address = &notify_address;
956   env.max_connections = max_connect_per_transport;
957   env.session_end = &plugin_env_session_end;
958 }
959
960
961 /**
962  * Task shutting down testcase if it a timeout occurs
963  */
964 static void
965 task_timeout (void *cls,
966             const struct GNUNET_SCHEDULER_TaskContext *tc)
967 {
968   ti_timeout = GNUNET_SCHEDULER_NO_TASK;
969   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
970     return;
971
972   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase timeout\n");
973   fail = GNUNET_YES;
974   shutdown_clean();
975   return;
976 }
977
978
979 static void 
980 pretty_printer_cb (void *cls,
981                    const char *address)
982 {
983   if (NULL==address)
984     return;
985   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
986               "Plugin returned pretty address: `%s'\n",
987               address);
988   fail_pretty_printer_count++;
989 }
990
991 /**
992  * Runs every single test to test the plugin
993  */
994 static void 
995 run_connection_tests( int phase , void * cls)
996 {
997   struct GNUNET_MessageHeader * msg;
998   unsigned int size;
999
1000   if (phase==0)
1001   {
1002     char * host_str = NULL;
1003     /* resetting buffers */
1004     buffer_in.size = HTTP_BUFFER_SIZE;
1005     buffer_in.pos = 0;
1006     buffer_in.len = 0;
1007
1008     buffer_out.size = HTTP_BUFFER_SIZE;
1009     buffer_out.pos = 0;
1010     buffer_out.len = 0;
1011
1012     if (test_no_ident.test_executed == GNUNET_NO)
1013       {
1014         /* Connecting to peer without identification */
1015         const char * ident = "";
1016         GNUNET_asprintf (&host_str,
1017                          "%s://%s/%s",
1018                          PROTOCOL_PREFIX,
1019                          test_addr,ident);
1020         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1021                     _("Connecting to peer without any peer identification.\n"));
1022         test_no_ident.test_executed = GNUNET_YES;
1023         send_data ( &test_no_ident, host_str);
1024         GNUNET_free (host_str);
1025         return;
1026       }
1027     if (test_too_short_ident.test_executed == GNUNET_NO)
1028       {
1029         const char * ident = "AAAAAAAAAA";
1030         /* Connecting to peer with too short identification */
1031         GNUNET_asprintf (&host_str,
1032                          "%s://%s/%s",
1033                          PROTOCOL_PREFIX,
1034                          test_addr,
1035                          ident);
1036         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1037                     _("Connecting to peer with too short peer identification.\n"));
1038         test_too_short_ident.test_executed = GNUNET_YES;
1039         send_data ( &test_too_short_ident, host_str);
1040         GNUNET_free (host_str);
1041         return;
1042       }
1043
1044     if (test_too_long_ident.test_executed == GNUNET_NO)
1045       {
1046         const char * ident = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1047
1048         /* Connecting to peer with too long identification */
1049         GNUNET_asprintf (&host_str, "%s://%s/%s",PROTOCOL_PREFIX, test_addr,ident);
1050         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1051                     _("Connecting to peer with too long peer identification.\n"));
1052         test_too_long_ident.test_executed = GNUNET_YES;
1053         send_data ( &test_too_long_ident, host_str);
1054         GNUNET_free (host_str);
1055         return;
1056     }
1057     if (test_valid_ident.test_executed == GNUNET_NO)
1058       {
1059         struct GNUNET_CRYPTO_HashAsciiEncoded ident;
1060         GNUNET_CRYPTO_hash_to_enc(&my_identity.hashPubKey,&ident);
1061         GNUNET_asprintf (&host_str,
1062                          "%s://%s/%s%s",
1063                          PROTOCOL_PREFIX,
1064                          test_addr,
1065                          (char *) &ident,
1066                          ";0");
1067         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1068                     _("Connecting to peer with valid peer identification.\n"));
1069         test_valid_ident.test_executed = GNUNET_YES;
1070         send_data ( &test_valid_ident, host_str);
1071         GNUNET_free (host_str);
1072         return;
1073       }
1074   }
1075   if (phase==1)
1076     {
1077       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1078                   "\nPhase 1: transmit data to all suggested addresses\n\n");
1079       /* Using one of the addresses the plugin proposed */
1080       GNUNET_assert (addr_head->addr != NULL);
1081       
1082       struct Plugin_Address * tmp_addr;
1083       struct GNUNET_MessageHeader msg;
1084       char * tmp = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader));
1085       char address[INET6_ADDRSTRLEN];
1086       unsigned int port;
1087       unsigned int type = 10;
1088       
1089       msg.size=htons(sizeof(struct GNUNET_MessageHeader));
1090       tmp_addr = addr_head;
1091       /* send a message to all addresses advertised by plugin */
1092       
1093       int count = 0;
1094       while (tmp_addr != NULL)
1095         {
1096           if (tmp_addr->addrlen == (sizeof (struct IPv4HttpAddress)))
1097             {
1098               inet_ntop(AF_INET, (struct in_addr *) tmp_addr->addr,address,INET_ADDRSTRLEN);
1099               port = ntohs(((struct IPv4HttpAddress *) tmp_addr->addr)->u_port);
1100               GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1101                           "Sending message to addres no. %u: `%s':%u\n",
1102                           count,
1103                           address,
1104                           port);
1105             }
1106           if (tmp_addr->addrlen == (sizeof (struct IPv6HttpAddress)))
1107             {
1108               inet_ntop(AF_INET6, (struct in6_addr *) tmp_addr->addr,address,INET6_ADDRSTRLEN);
1109               port = ntohs(((struct IPv6HttpAddress *) tmp_addr->addr)->u6_port);
1110               GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1111                           "Sending message to addres no. %u: `%s':%u\n",
1112                           count,
1113                           address,
1114                           port);
1115             }
1116           msg.type=htons(type);
1117           memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader));
1118           api->send(api->cls,
1119                     &my_identity,
1120                     tmp, sizeof(struct GNUNET_MessageHeader),
1121                     0, TIMEOUT,
1122                     NULL,
1123                     tmp_addr->addr, tmp_addr->addrlen,
1124                     GNUNET_YES,
1125                     &task_send_cont, &fail_msgs_transmited_to_local_addrs);
1126           tmp_addr = tmp_addr->next;
1127           count++;
1128           type++;
1129         }
1130       GNUNET_free(tmp);
1131       return;
1132     }
1133
1134   if (phase==2)
1135     {
1136       struct Session * session = cls;
1137       msg = GNUNET_malloc (sizeof(struct GNUNET_MessageHeader));
1138       
1139       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
1140                   "Phase 2: session selection\n\n");
1141       size = sizeof(struct GNUNET_MessageHeader);
1142       msg->size=htons(size);
1143       msg->type = htons(20);
1144       api->send(api->cls, 
1145                 &my_identity,
1146                 (const char *) msg, size,
1147                 0, TIMEOUT, NULL, NULL, 0, GNUNET_NO,
1148                 &task_send_cont, NULL);
1149       
1150       msg->type = htons(21);
1151       api->send(api->cls, 
1152                 &my_identity,
1153                 (const char *) msg, size,
1154                 0, TIMEOUT, NULL, NULL, 0, GNUNET_SYSERR,
1155                 &task_send_cont, NULL);
1156       
1157       /* answer on session*/
1158       size = sizeof( struct GNUNET_MessageHeader);
1159       msg->size = htons(size);
1160       msg->type = htons(22);
1161       api->send(api->cls, 
1162                 &my_identity,
1163                 (const char *) msg, size,
1164                 0, TIMEOUT, session, NULL, 0, GNUNET_SYSERR,
1165                 &task_send_cont, NULL);
1166       GNUNET_free(msg);
1167       
1168       /* answer on session with big message not fitting in mhd send buffer*/
1169       size = GNUNET_SERVER_MAX_MESSAGE_SIZE-1;
1170       msg = GNUNET_malloc (size);
1171       msg->size=htons(size);
1172       msg->type = htons(23);
1173       api->send(api->cls,
1174                 &my_identity,
1175                 (const char *) msg, size,
1176                 0, TIMEOUT, session, NULL, 0, GNUNET_NO,
1177                 &task_send_cont, NULL);
1178       GNUNET_free(msg);
1179       return;
1180     }
1181   
1182   if (phase==3)
1183     {
1184       
1185     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
1186                 "Phase 3: send multiple or big messages after disconnect\n\n");
1187     /* disconnect from peer, so new connections are created */
1188     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Disconnect from peer: `%s'\n", GNUNET_i2s(&my_identity));
1189     api->disconnect(api->cls, &my_identity);
1190     
1191     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Phase 3: sending messages\n");
1192     /* send a multiple GNUNET_messages at a time*/
1193     size = 2 * sizeof(struct GNUNET_MessageHeader);
1194     msg = GNUNET_malloc( 2* size);
1195     msg->size = htons(size);
1196     msg->type = htons(30);
1197     struct GNUNET_MessageHeader * msg2 = &msg[2];
1198     msg2->size = htons(2 * sizeof(struct GNUNET_MessageHeader));
1199     msg2->type = htons(31);
1200     api->send(api->cls,
1201               &my_identity,
1202               (const char *) msg, 4 * sizeof(struct GNUNET_MessageHeader),
1203               0, TIMEOUT, NULL,
1204               addr_head->addr, addr_head->addrlen,
1205               GNUNET_NO,
1206               &task_send_cont, &fail_multiple_msgs_in_transmission);
1207     GNUNET_free(msg);
1208     /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1  */
1209
1210     size = GNUNET_SERVER_MAX_MESSAGE_SIZE-1;
1211     msg = GNUNET_malloc(size);
1212     msg->size = htons(size);
1213     msg->type = htons(32);
1214     api->send(api->cls,
1215               &my_identity,
1216               (const char *) msg, size,
1217               0, TIMEOUT, NULL,
1218               addr_head->addr, addr_head->addrlen,
1219               GNUNET_NO,
1220               &task_send_cont, &fail_msg_transmited_max_size);
1221     GNUNET_free(msg);
1222     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1223                 "No more tests to run\n");
1224   }
1225 }
1226
1227
1228 /**
1229  * Runs the test.
1230  *
1231  * @param cls closure
1232  * @param c configuration to use
1233  */
1234 static void
1235 run (void *cls,
1236      char *const *args,
1237      const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
1238 {
1239   char * libname;
1240   cfg = c;
1241   char *keyfile;
1242   unsigned long long tneigh;
1243   struct Plugin_Address * cur;
1244   const char * addr_str;
1245
1246
1247   unsigned int suggest_res;
1248
1249   fail_pretty_printer = GNUNET_YES;
1250   fail_notify_address = GNUNET_YES;
1251   fail_addr_to_str = GNUNET_YES;
1252   fail_msgs_transmited_to_local_addrs = 0;
1253   fail_msg_transmited_max_size = GNUNET_YES;
1254   fail_multiple_msgs_in_transmission = 0;
1255   fail_session_selection_reliable = GNUNET_YES;
1256   fail_session_selection_reliable = GNUNET_YES;
1257   fail_session_selection_session = GNUNET_YES;
1258   fail_session_selection_session_big = GNUNET_YES;
1259
1260   addr_head = NULL;
1261   count_str_addr = 0;
1262   /* parse configuration */
1263   if (GNUNET_CONFIGURATION_have_value (c,"PATHS", "SERVICEHOME"))
1264       GNUNET_CONFIGURATION_get_value_string (c, "PATHS", "SERVICEHOME", &servicehome);
1265
1266   if ((GNUNET_OK !=
1267        GNUNET_CONFIGURATION_get_value_number (c,
1268                                               "TRANSPORT",
1269                                               "NEIGHBOUR_LIMIT",
1270                                               &tneigh)) ||
1271       (GNUNET_OK !=
1272        GNUNET_CONFIGURATION_get_value_filename (c,
1273                                                 "GNUNETD",
1274                                                 "HOSTKEY", &keyfile)))
1275     {
1276       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1277                   _("Transport service is lacking key configuration settings.  Exiting.\n"));
1278       GNUNET_SCHEDULER_shutdown ();
1279       fail = 1;
1280       return;
1281     }
1282
1283   if ((GNUNET_OK !=
1284       GNUNET_CONFIGURATION_get_value_number (cfg,
1285                                              "transport-http",
1286                                              "PORT",
1287                                              &port)) ||
1288      (port > 65535) || (port == 0))
1289   {
1290     GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
1291                      "http",
1292                      _
1293                      ("Require valid port number for transport plugin `%s' in configuration!\n"),
1294                      "transport-http");
1295   }
1296
1297   max_connect_per_transport = (uint32_t) tneigh;
1298   my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
1299   GNUNET_free (keyfile);
1300   if (my_private_key == NULL)
1301     {
1302       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1303                   _("Transport service could not access hostkey.  Exiting.\n"));
1304       GNUNET_SCHEDULER_shutdown ();
1305       fail = 1;
1306       return;
1307     }
1308
1309   GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
1310   GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), &my_identity.hashPubKey);
1311
1312   /* assertions before start */
1313   GNUNET_assert ((port > 0) && (port <= 65535));
1314
1315   /* load plugins... */
1316   setup_plugin_environment ();
1317   GNUNET_asprintf (&libname, "libgnunet_plugin_transport_http");
1318   GNUNET_log (GNUNET_ERROR_TYPE_INFO, 
1319               _("Loading HTTP transport plugin `%s'\n"),
1320               libname);
1321   api = GNUNET_PLUGIN_load (libname, &env);
1322   GNUNET_free (libname);
1323   if (api == NULL)
1324   {
1325     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1326                 _("Failed to load transport plugin for http\n"));
1327     fail = 1;
1328     return;
1329   }
1330
1331
1332   ti_timeout = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &task_timeout, NULL);
1333
1334   /* testing plugin functionality */
1335   GNUNET_assert (0!=fail_notify_address_count);
1336   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
1337               "Transport plugin returned %u addresses to connect to\n",
1338               fail_notify_address_count);
1339
1340   /* testing pretty printer with all addresses obtained from the plugin*/
1341   cur = addr_head;
1342   while (cur != NULL)
1343   {
1344     api->address_pretty_printer (api->cls, "http",
1345                                  cur->addr,cur->addrlen, GNUNET_NO,TEST_TIMEOUT,
1346                                  &pretty_printer_cb, NULL);
1347     addr_str = api->address_to_string (api->cls, cur->addr, cur->addrlen);
1348     suggest_res = api->check_address (api->cls, cur->addr, cur->addrlen);
1349
1350     GNUNET_assert (GNUNET_OK == suggest_res);
1351     GNUNET_assert (NULL != addr_str);
1352     count_str_addr++;
1353     GNUNET_free ( (char *) addr_str);
1354     cur = cur->next;
1355   }
1356   GNUNET_assert (fail_pretty_printer_count > 0);
1357   GNUNET_assert (fail_pretty_printer_count==fail_notify_address_count);
1358   GNUNET_assert (fail_pretty_printer_count==count_str_addr);
1359   fail_pretty_printer=GNUNET_NO;
1360   fail_addr_to_str=GNUNET_NO;
1361
1362   struct IPv4HttpAddress failing_addr;
1363
1364   /* Suggesting addresses with wrong size*/
1365   failing_addr.ipv4_addr = htonl(INADDR_LOOPBACK);
1366   failing_addr.u_port = htons(0);
1367   suggest_res = api->check_address (api->cls,&failing_addr,sizeof (struct IPv6HttpAddress));
1368   GNUNET_assert (GNUNET_SYSERR == suggest_res);
1369
1370   /* Suggesting addresses with wrong address*/
1371   failing_addr.ipv4_addr = htonl(0xffc00000);
1372   failing_addr.u_port = htons(12389);
1373   suggest_res = api->check_address (api->cls,&failing_addr,100);
1374   GNUNET_assert (GNUNET_SYSERR == suggest_res);
1375
1376   /* test sending to client */
1377   multi_handle = curl_multi_init();
1378
1379   /* Setting up buffers */
1380   buffer_in.size = HTTP_BUFFER_SIZE;
1381   buffer_in.pos = 0;
1382   buffer_in.len = 0;
1383
1384   buffer_out.size = HTTP_BUFFER_SIZE;
1385   buffer_out.pos = 0;
1386   buffer_out.len = 0;
1387
1388   /* Setting up connection tests */
1389
1390   /* Test: connecting without a peer identification */
1391   test_no_ident.test_executed = GNUNET_NO;
1392   test_no_ident.test_failed = GNUNET_YES;
1393
1394   /* Test: connecting with too short peer identification */
1395   test_too_short_ident.test_executed = GNUNET_NO;
1396   test_too_short_ident.test_failed = GNUNET_YES;
1397
1398   /* Test: connecting with too long peer identification */
1399   test_too_long_ident.test_executed = GNUNET_NO;
1400   test_too_long_ident.test_failed = GNUNET_YES;
1401
1402   /* Test: connecting with valid identification */
1403   test_valid_ident.test_executed = GNUNET_NO;
1404   test_valid_ident.test_failed = GNUNET_YES;
1405
1406   test_addr = (char *) api->address_to_string (api->cls,addr_head->addr,addr_head->addrlen);
1407
1408   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Phase 0\n\n"));
1409   run_connection_tests(0, NULL);
1410   /* testing finished */
1411 }
1412
1413
1414 /**
1415  * The main function for the transport service.
1416  *
1417  * @param argc number of arguments from the command line
1418  * @param argv command line arguments
1419  * @return 0 ok, 1 on error
1420  */
1421 int
1422 main (int argc, char *const *argv)
1423 {
1424   static struct GNUNET_GETOPT_CommandLineOption options[] = {
1425     GNUNET_GETOPT_OPTION_END
1426   };
1427   int ret;
1428   char *const argv_prog[] = {
1429     "test_gnunet_transport_plugin_http",
1430     "-c",
1431     "test_plugin_transport_data_http.conf",
1432     "-L",
1433 #if VERBOSE
1434     "DEBUG",
1435 #else
1436     "WARNING",
1437 #endif
1438     NULL
1439   };
1440   GNUNET_log_setup ("test_gnunet_transport_plugin_http",
1441 #if VERBOSE
1442                     "DEBUG",
1443 #else
1444                     "WARNING",
1445 #endif
1446                     NULL);
1447
1448   struct GNUNET_CONFIGURATION_Handle *cfg;
1449   cfg = GNUNET_CONFIGURATION_create ();
1450
1451   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, "test_plugin_transport_data_http.conf"));
1452   if (GNUNET_CONFIGURATION_have_value (cfg,"PATHS", "SERVICEHOME"))
1453       GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME", &servicehome);
1454   GNUNET_DISK_directory_remove (servicehome);
1455   GNUNET_CONFIGURATION_destroy (cfg);
1456
1457   ret = (GNUNET_OK ==
1458          GNUNET_PROGRAM_run (5,
1459                              argv_prog,
1460                              "test_gnunet_transport_plugin_http",
1461                              "testcase", options, &run, NULL)) ? GNUNET_NO : GNUNET_YES;
1462
1463   if (servicehome != NULL)
1464   {
1465     GNUNET_DISK_directory_remove (servicehome);
1466     GNUNET_free (servicehome);
1467   }
1468   if (ret != GNUNET_OK)
1469     return 1;
1470   return fail;
1471 }
1472
1473 /* end of test_gnunet_transport_plugin_http.c */