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