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