getting plugins to work again
[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                 const char *name,
878                 const void *addr,
879                 uint16_t addrlen,
880                 struct GNUNET_TIME_Relative expires)
881 {
882   char address[INET6_ADDRSTRLEN];
883   unsigned int port;
884   struct Plugin_Address * pl_addr;
885   struct Plugin_Address * cur;
886
887   if (addrlen == (sizeof (struct IPv4HttpAddress)))
888     {
889       inet_ntop(AF_INET, (struct in_addr *) addr,address,INET_ADDRSTRLEN);
890       port = ntohs(((struct IPv4HttpAddress *) addr)->u_port);
891     }
892   else if (addrlen == (sizeof (struct IPv6HttpAddress)))
893     {
894       inet_ntop(AF_INET6, (struct in6_addr *) addr,address,INET6_ADDRSTRLEN);
895       port = ntohs(((struct IPv6HttpAddress *) addr)->u6_port);
896     }
897   else
898     {
899     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
900                 _("Unknown address size: ipv6 has %u ipv4 has %u but this has %u\n"),
901                 sizeof (struct IPv6HttpAddress),
902                 sizeof (struct IPv4HttpAddress),
903                 addrlen);
904       return;
905     }
906   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
907               _("Transport plugin notification for address: `%s':%u\n"),
908               address,
909               port);
910   pl_addr = GNUNET_malloc (sizeof (struct Plugin_Address) );
911   pl_addr->addrlen = addrlen;
912   pl_addr->addr = GNUNET_malloc(addrlen);
913   memcpy(pl_addr->addr,addr,addrlen);
914   pl_addr->next = NULL;
915
916   if ( NULL == addr_head)
917     {
918       addr_head = pl_addr;
919     }
920   else
921     {
922       cur = addr_head;
923       while (NULL != cur->next)
924         {
925           cur = cur->next;
926         }
927       cur->next = pl_addr;
928     }
929   fail_notify_address_count++;
930   fail_notify_address = GNUNET_NO;
931 }
932
933 static void
934 plugin_env_session_end (void *cls,
935                         const struct GNUNET_PeerIdentity *peer,
936                         struct Session *session)
937 {
938   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
939               "Pluging tells me: session %X to peer `%s' ended\n",
940               session,
941               GNUNET_i2s(peer));
942 }
943
944
945 /**
946  * Setup plugin environment
947  */
948 static void
949 setup_plugin_environment ()
950 {
951   env.cfg = cfg;
952   env.stats = stats;
953   env.my_identity = &my_identity;
954   env.cls = &env;
955   env.receive = &receive;
956   env.notify_address = &notify_address;
957   env.max_connections = max_connect_per_transport;
958   env.session_end = &plugin_env_session_end;
959 }
960
961
962 /**
963  * Task shutting down testcase if it a timeout occurs
964  */
965 static void
966 task_timeout (void *cls,
967             const struct GNUNET_SCHEDULER_TaskContext *tc)
968 {
969   ti_timeout = GNUNET_SCHEDULER_NO_TASK;
970   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
971     return;
972
973   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase timeout\n");
974   fail = GNUNET_YES;
975   shutdown_clean();
976   return;
977 }
978
979
980 static void 
981 pretty_printer_cb (void *cls,
982                    const char *address)
983 {
984   if (NULL==address)
985     return;
986   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
987               "Plugin returned pretty address: `%s'\n",
988               address);
989   fail_pretty_printer_count++;
990 }
991
992 /**
993  * Runs every single test to test the plugin
994  */
995 static void 
996 run_connection_tests( int phase , void * cls)
997 {
998   struct GNUNET_MessageHeader * msg;
999   unsigned int size;
1000
1001   if (phase==0)
1002   {
1003     char * host_str = NULL;
1004     /* resetting buffers */
1005     buffer_in.size = HTTP_BUFFER_SIZE;
1006     buffer_in.pos = 0;
1007     buffer_in.len = 0;
1008
1009     buffer_out.size = HTTP_BUFFER_SIZE;
1010     buffer_out.pos = 0;
1011     buffer_out.len = 0;
1012
1013     if (test_no_ident.test_executed == GNUNET_NO)
1014       {
1015         /* Connecting to peer without identification */
1016         const char * ident = "";
1017         GNUNET_asprintf (&host_str,
1018                          "%s://%s/%s",
1019                          PROTOCOL_PREFIX,
1020                          test_addr,ident);
1021         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1022                     _("Connecting to peer without any peer identification.\n"));
1023         test_no_ident.test_executed = GNUNET_YES;
1024         send_data ( &test_no_ident, host_str);
1025         GNUNET_free (host_str);
1026         return;
1027       }
1028     if (test_too_short_ident.test_executed == GNUNET_NO)
1029       {
1030         const char * ident = "AAAAAAAAAA";
1031         /* Connecting to peer with too short identification */
1032         GNUNET_asprintf (&host_str,
1033                          "%s://%s/%s",
1034                          PROTOCOL_PREFIX,
1035                          test_addr,
1036                          ident);
1037         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1038                     _("Connecting to peer with too short peer identification.\n"));
1039         test_too_short_ident.test_executed = GNUNET_YES;
1040         send_data ( &test_too_short_ident, host_str);
1041         GNUNET_free (host_str);
1042         return;
1043       }
1044
1045     if (test_too_long_ident.test_executed == GNUNET_NO)
1046       {
1047         const char * ident = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1048
1049         /* Connecting to peer with too long identification */
1050         GNUNET_asprintf (&host_str, "%s://%s/%s",PROTOCOL_PREFIX, test_addr,ident);
1051         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1052                     _("Connecting to peer with too long peer identification.\n"));
1053         test_too_long_ident.test_executed = GNUNET_YES;
1054         send_data ( &test_too_long_ident, host_str);
1055         GNUNET_free (host_str);
1056         return;
1057     }
1058     if (test_valid_ident.test_executed == GNUNET_NO)
1059       {
1060         struct GNUNET_CRYPTO_HashAsciiEncoded ident;
1061         GNUNET_CRYPTO_hash_to_enc(&my_identity.hashPubKey,&ident);
1062         GNUNET_asprintf (&host_str,
1063                          "%s://%s/%s%s",
1064                          PROTOCOL_PREFIX,
1065                          test_addr,
1066                          (char *) &ident,
1067                          ";0");
1068         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1069                     _("Connecting to peer with valid peer identification.\n"));
1070         test_valid_ident.test_executed = GNUNET_YES;
1071         send_data ( &test_valid_ident, host_str);
1072         GNUNET_free (host_str);
1073         return;
1074       }
1075   }
1076   if (phase==1)
1077     {
1078       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1079                   "\nPhase 1: transmit data to all suggested addresses\n\n");
1080       /* Using one of the addresses the plugin proposed */
1081       GNUNET_assert (addr_head->addr != NULL);
1082       
1083       struct Plugin_Address * tmp_addr;
1084       struct GNUNET_MessageHeader msg;
1085       char * tmp = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader));
1086       char address[INET6_ADDRSTRLEN];
1087       unsigned int port;
1088       unsigned int type = 10;
1089       
1090       msg.size=htons(sizeof(struct GNUNET_MessageHeader));
1091       tmp_addr = addr_head;
1092       /* send a message to all addresses advertised by plugin */
1093       
1094       int count = 0;
1095       while (tmp_addr != NULL)
1096         {
1097           if (tmp_addr->addrlen == (sizeof (struct IPv4HttpAddress)))
1098             {
1099               inet_ntop(AF_INET, (struct in_addr *) tmp_addr->addr,address,INET_ADDRSTRLEN);
1100               port = ntohs(((struct IPv4HttpAddress *) tmp_addr->addr)->u_port);
1101               GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1102                           "Sending message to addres no. %u: `%s':%u\n",
1103                           count,
1104                           address,
1105                           port);
1106             }
1107           if (tmp_addr->addrlen == (sizeof (struct IPv6HttpAddress)))
1108             {
1109               inet_ntop(AF_INET6, (struct in6_addr *) tmp_addr->addr,address,INET6_ADDRSTRLEN);
1110               port = ntohs(((struct IPv6HttpAddress *) tmp_addr->addr)->u6_port);
1111               GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1112                           "Sending message to addres no. %u: `%s':%u\n",
1113                           count,
1114                           address,
1115                           port);
1116             }
1117           msg.type=htons(type);
1118           memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader));
1119           api->send(api->cls,
1120                     &my_identity,
1121                     tmp, sizeof(struct GNUNET_MessageHeader),
1122                     0, TIMEOUT,
1123                     NULL,
1124                     tmp_addr->addr, tmp_addr->addrlen,
1125                     GNUNET_YES,
1126                     &task_send_cont, &fail_msgs_transmited_to_local_addrs);
1127           tmp_addr = tmp_addr->next;
1128           count++;
1129           type++;
1130         }
1131       GNUNET_free(tmp);
1132       return;
1133     }
1134
1135   if (phase==2)
1136     {
1137       struct Session * session = cls;
1138       msg = GNUNET_malloc (sizeof(struct GNUNET_MessageHeader));
1139       
1140       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
1141                   "Phase 2: session selection\n\n");
1142       size = sizeof(struct GNUNET_MessageHeader);
1143       msg->size=htons(size);
1144       msg->type = htons(20);
1145       api->send(api->cls, 
1146                 &my_identity,
1147                 (const char *) msg, size,
1148                 0, TIMEOUT, NULL, NULL, 0, GNUNET_NO,
1149                 &task_send_cont, NULL);
1150       
1151       msg->type = htons(21);
1152       api->send(api->cls, 
1153                 &my_identity,
1154                 (const char *) msg, size,
1155                 0, TIMEOUT, NULL, NULL, 0, GNUNET_SYSERR,
1156                 &task_send_cont, NULL);
1157       
1158       /* answer on session*/
1159       size = sizeof( struct GNUNET_MessageHeader);
1160       msg->size = htons(size);
1161       msg->type = htons(22);
1162       api->send(api->cls, 
1163                 &my_identity,
1164                 (const char *) msg, size,
1165                 0, TIMEOUT, session, NULL, 0, GNUNET_SYSERR,
1166                 &task_send_cont, NULL);
1167       GNUNET_free(msg);
1168       
1169       /* answer on session with big message not fitting in mhd send buffer*/
1170       size = GNUNET_SERVER_MAX_MESSAGE_SIZE-1;
1171       msg = GNUNET_malloc (size);
1172       msg->size=htons(size);
1173       msg->type = htons(23);
1174       api->send(api->cls,
1175                 &my_identity,
1176                 (const char *) msg, size,
1177                 0, TIMEOUT, session, NULL, 0, GNUNET_NO,
1178                 &task_send_cont, NULL);
1179       GNUNET_free(msg);
1180       return;
1181     }
1182   
1183   if (phase==3)
1184     {
1185       
1186     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
1187                 "Phase 3: send multiple or big messages after disconnect\n\n");
1188     /* disconnect from peer, so new connections are created */
1189     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Disconnect from peer: `%s'\n", GNUNET_i2s(&my_identity));
1190     api->disconnect(api->cls, &my_identity);
1191     
1192     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Phase 3: sending messages\n");
1193     /* send a multiple GNUNET_messages at a time*/
1194     size = 2 * sizeof(struct GNUNET_MessageHeader);
1195     msg = GNUNET_malloc( 2* size);
1196     msg->size = htons(size);
1197     msg->type = htons(30);
1198     struct GNUNET_MessageHeader * msg2 = &msg[2];
1199     msg2->size = htons(2 * sizeof(struct GNUNET_MessageHeader));
1200     msg2->type = htons(31);
1201     api->send(api->cls,
1202               &my_identity,
1203               (const char *) msg, 4 * sizeof(struct GNUNET_MessageHeader),
1204               0, TIMEOUT, NULL,
1205               addr_head->addr, addr_head->addrlen,
1206               GNUNET_NO,
1207               &task_send_cont, &fail_multiple_msgs_in_transmission);
1208     GNUNET_free(msg);
1209     /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1  */
1210
1211     size = GNUNET_SERVER_MAX_MESSAGE_SIZE-1;
1212     msg = GNUNET_malloc(size);
1213     msg->size = htons(size);
1214     msg->type = htons(32);
1215     api->send(api->cls,
1216               &my_identity,
1217               (const char *) msg, size,
1218               0, TIMEOUT, NULL,
1219               addr_head->addr, addr_head->addrlen,
1220               GNUNET_NO,
1221               &task_send_cont, &fail_msg_transmited_max_size);
1222     GNUNET_free(msg);
1223     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1224                 "No more tests to run\n");
1225   }
1226 }
1227
1228
1229 /**
1230  * Runs the test.
1231  *
1232  * @param cls closure
1233  * @param c configuration to use
1234  */
1235 static void
1236 run (void *cls,
1237      char *const *args,
1238      const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
1239 {
1240   char * libname;
1241   cfg = c;
1242   char *keyfile;
1243   unsigned long long tneigh;
1244   struct Plugin_Address * cur;
1245   const char * addr_str;
1246
1247
1248   unsigned int suggest_res;
1249
1250   fail_pretty_printer = GNUNET_YES;
1251   fail_notify_address = GNUNET_YES;
1252   fail_addr_to_str = GNUNET_YES;
1253   fail_msgs_transmited_to_local_addrs = 0;
1254   fail_msg_transmited_max_size = GNUNET_YES;
1255   fail_multiple_msgs_in_transmission = 0;
1256   fail_session_selection_reliable = GNUNET_YES;
1257   fail_session_selection_reliable = GNUNET_YES;
1258   fail_session_selection_session = GNUNET_YES;
1259   fail_session_selection_session_big = GNUNET_YES;
1260
1261   addr_head = NULL;
1262   count_str_addr = 0;
1263   /* parse configuration */
1264   if (GNUNET_CONFIGURATION_have_value (c,"PATHS", "SERVICEHOME"))
1265       GNUNET_CONFIGURATION_get_value_string (c, "PATHS", "SERVICEHOME", &servicehome);
1266
1267   if ((GNUNET_OK !=
1268        GNUNET_CONFIGURATION_get_value_number (c,
1269                                               "TRANSPORT",
1270                                               "NEIGHBOUR_LIMIT",
1271                                               &tneigh)) ||
1272       (GNUNET_OK !=
1273        GNUNET_CONFIGURATION_get_value_filename (c,
1274                                                 "GNUNETD",
1275                                                 "HOSTKEY", &keyfile)))
1276     {
1277       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1278                   _("Transport service is lacking key configuration settings.  Exiting.\n"));
1279       GNUNET_SCHEDULER_shutdown ();
1280       fail = 1;
1281       return;
1282     }
1283
1284   if ((GNUNET_OK !=
1285       GNUNET_CONFIGURATION_get_value_number (cfg,
1286                                              "transport-http",
1287                                              "PORT",
1288                                              &port)) ||
1289      (port > 65535) || (port == 0))
1290   {
1291     GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
1292                      "http",
1293                      _
1294                      ("Require valid port number for transport plugin `%s' in configuration!\n"),
1295                      "transport-http");
1296   }
1297
1298   max_connect_per_transport = (uint32_t) tneigh;
1299   my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
1300   GNUNET_free (keyfile);
1301   if (my_private_key == NULL)
1302     {
1303       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1304                   _("Transport service could not access hostkey.  Exiting.\n"));
1305       GNUNET_SCHEDULER_shutdown ();
1306       fail = 1;
1307       return;
1308     }
1309
1310   GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
1311   GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), &my_identity.hashPubKey);
1312
1313   /* assertions before start */
1314   GNUNET_assert ((port > 0) && (port <= 65535));
1315
1316   /* load plugins... */
1317   setup_plugin_environment ();
1318   GNUNET_asprintf (&libname, "libgnunet_plugin_transport_http");
1319   GNUNET_log (GNUNET_ERROR_TYPE_INFO, 
1320               _("Loading HTTP transport plugin `%s'\n"),
1321               libname);
1322   api = GNUNET_PLUGIN_load (libname, &env);
1323   GNUNET_free (libname);
1324   if (api == NULL)
1325   {
1326     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1327                 _("Failed to load transport plugin for http\n"));
1328     fail = 1;
1329     return;
1330   }
1331
1332
1333   ti_timeout = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &task_timeout, NULL);
1334
1335   /* testing plugin functionality */
1336   GNUNET_assert (0!=fail_notify_address_count);
1337   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
1338               "Transport plugin returned %u addresses to connect to\n",
1339               fail_notify_address_count);
1340
1341   /* testing pretty printer with all addresses obtained from the plugin*/
1342   cur = addr_head;
1343   while (cur != NULL)
1344   {
1345     api->address_pretty_printer (api->cls, "http",
1346                                  cur->addr,cur->addrlen, GNUNET_NO,TEST_TIMEOUT,
1347                                  &pretty_printer_cb, NULL);
1348     addr_str = api->address_to_string (api->cls, cur->addr, cur->addrlen);
1349     suggest_res = api->check_address (api->cls, cur->addr, cur->addrlen);
1350
1351     GNUNET_assert (GNUNET_OK == suggest_res);
1352     GNUNET_assert (NULL != addr_str);
1353     count_str_addr++;
1354     GNUNET_free ( (char *) addr_str);
1355     cur = cur->next;
1356   }
1357   GNUNET_assert (fail_pretty_printer_count > 0);
1358   GNUNET_assert (fail_pretty_printer_count==fail_notify_address_count);
1359   GNUNET_assert (fail_pretty_printer_count==count_str_addr);
1360   fail_pretty_printer=GNUNET_NO;
1361   fail_addr_to_str=GNUNET_NO;
1362
1363   struct IPv4HttpAddress failing_addr;
1364
1365   /* Suggesting addresses with wrong size*/
1366   failing_addr.ipv4_addr = htonl(INADDR_LOOPBACK);
1367   failing_addr.u_port = htons(0);
1368   suggest_res = api->check_address (api->cls,&failing_addr,sizeof (struct IPv6HttpAddress));
1369   GNUNET_assert (GNUNET_SYSERR == suggest_res);
1370
1371   /* Suggesting addresses with wrong address*/
1372   failing_addr.ipv4_addr = htonl(0xffc00000);
1373   failing_addr.u_port = htons(12389);
1374   suggest_res = api->check_address (api->cls,&failing_addr,100);
1375   GNUNET_assert (GNUNET_SYSERR == suggest_res);
1376
1377   /* test sending to client */
1378   multi_handle = curl_multi_init();
1379
1380   /* Setting up buffers */
1381   buffer_in.size = HTTP_BUFFER_SIZE;
1382   buffer_in.pos = 0;
1383   buffer_in.len = 0;
1384
1385   buffer_out.size = HTTP_BUFFER_SIZE;
1386   buffer_out.pos = 0;
1387   buffer_out.len = 0;
1388
1389   /* Setting up connection tests */
1390
1391   /* Test: connecting without a peer identification */
1392   test_no_ident.test_executed = GNUNET_NO;
1393   test_no_ident.test_failed = GNUNET_YES;
1394
1395   /* Test: connecting with too short peer identification */
1396   test_too_short_ident.test_executed = GNUNET_NO;
1397   test_too_short_ident.test_failed = GNUNET_YES;
1398
1399   /* Test: connecting with too long peer identification */
1400   test_too_long_ident.test_executed = GNUNET_NO;
1401   test_too_long_ident.test_failed = GNUNET_YES;
1402
1403   /* Test: connecting with valid identification */
1404   test_valid_ident.test_executed = GNUNET_NO;
1405   test_valid_ident.test_failed = GNUNET_YES;
1406
1407   test_addr = (char *) api->address_to_string (api->cls,addr_head->addr,addr_head->addrlen);
1408
1409   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Phase 0\n\n"));
1410   run_connection_tests(0, NULL);
1411   /* testing finished */
1412 }
1413
1414
1415 /**
1416  * The main function for the transport service.
1417  *
1418  * @param argc number of arguments from the command line
1419  * @param argv command line arguments
1420  * @return 0 ok, 1 on error
1421  */
1422 int
1423 main (int argc, char *const *argv)
1424 {
1425   static struct GNUNET_GETOPT_CommandLineOption options[] = {
1426     GNUNET_GETOPT_OPTION_END
1427   };
1428   int ret;
1429   char *const argv_prog[] = {
1430     "test_gnunet_transport_plugin_http",
1431     "-c",
1432     "test_plugin_transport_data_http.conf",
1433     "-L",
1434 #if VERBOSE
1435     "DEBUG",
1436 #else
1437     "WARNING",
1438 #endif
1439     NULL
1440   };
1441   GNUNET_log_setup ("test_gnunet_transport_plugin_http",
1442 #if VERBOSE
1443                     "DEBUG",
1444 #else
1445                     "WARNING",
1446 #endif
1447                     NULL);
1448
1449   struct GNUNET_CONFIGURATION_Handle *cfg;
1450   cfg = GNUNET_CONFIGURATION_create ();
1451
1452   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, "test_plugin_transport_data_http.conf"));
1453   if (GNUNET_CONFIGURATION_have_value (cfg,"PATHS", "SERVICEHOME"))
1454       GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME", &servicehome);
1455   GNUNET_DISK_directory_remove (servicehome);
1456   GNUNET_CONFIGURATION_destroy (cfg);
1457
1458   ret = (GNUNET_OK ==
1459          GNUNET_PROGRAM_run (5,
1460                              argv_prog,
1461                              "test_gnunet_transport_plugin_http",
1462                              "testcase", options, &run, NULL)) ? GNUNET_NO : GNUNET_YES;
1463
1464   if (servicehome != NULL)
1465   {
1466     GNUNET_DISK_directory_remove (servicehome);
1467     GNUNET_free (servicehome);
1468   }
1469   if (ret != GNUNET_OK)
1470     return 1;
1471   return fail;
1472 }
1473
1474 /* end of test_gnunet_transport_plugin_http.c */