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