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