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