(no commit message)
[oweals/gnunet.git] / src / transport / test_plugin_transport_http.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 2, 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_http.c
22  * @brief testcase for plugin_transport_http.c
23  * @author Matthias Wachs
24  */
25
26 #include "platform.h"
27 #include "gnunet_constants.h"
28 #include "gnunet_getopt_lib.h"
29 #include "gnunet_hello_lib.h"
30 #include "gnunet_os_lib.h"
31 #include "gnunet_peerinfo_service.h"
32 #include "gnunet_plugin_lib.h"
33 #include "gnunet_protocols.h"
34 #include "gnunet_program_lib.h"
35 #include "gnunet_signatures.h"
36 #include "gnunet_service_lib.h"
37 #include "plugin_transport.h"
38 #include "gnunet_statistics_service.h"
39 #include "transport.h"
40 #include <curl/curl.h>
41
42 #define VERBOSE GNUNET_YES
43 #define DEBUG GNUNET_YES
44 #define DEBUG_CURL GNUNET_NO
45
46 #define PLUGIN libgnunet_plugin_transport_template
47
48 /**
49  * How long until we give up on transmitting the message?
50  */
51 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90)
52
53 /**
54  * How long until we give up on transmitting the message?
55  */
56 #define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
57
58 /**
59  * How long between recieve and send?
60  */
61 #define WAIT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
62
63 /**
64  *  Message to send using http
65  */
66 struct HTTP_Message
67 {
68   char *buf;
69   size_t pos;
70   size_t size;
71   size_t len;
72 };
73
74 /**
75  * Our public key.
76  */
77 /* static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key; */
78
79 /**
80  * Our public key.
81  */
82 static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key;
83
84 /**
85  * Our identity.
86  */
87 static struct GNUNET_PeerIdentity my_identity;
88
89 /**
90  * Our private key.
91  */
92 static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
93
94
95 /**
96  * Our scheduler.
97  */
98 struct GNUNET_SCHEDULER_Handle *sched;
99
100 /**
101  * Our statistics handle.
102  */
103 struct GNUNET_STATISTICS_Handle *stats;
104
105
106 /**
107  * Our configuration.
108  */
109 const struct GNUNET_CONFIGURATION_Handle *cfg;
110
111 /**
112  * Number of neighbours we'd like to have.
113  */
114 static uint32_t max_connect_per_transport;
115
116 /**
117  * Environment for this plugin.
118  */
119 static struct GNUNET_TRANSPORT_PluginEnvironment env;
120
121 /**
122  *handle for the api provided by this plugin
123  */
124 static struct GNUNET_TRANSPORT_PluginFunctions *api;
125
126 /**
127  * ID of the task controlling the testcase timeout
128  */
129 static GNUNET_SCHEDULER_TaskIdentifier ti_timeout;
130
131 static GNUNET_SCHEDULER_TaskIdentifier ti_send;
132
133 const struct GNUNET_PeerIdentity * p;
134
135 /**
136  *  Struct for plugin addresses
137  */
138 struct Plugin_Address
139 {
140   /**
141    * Next field for linked list
142    */
143   struct Plugin_Address * next;
144
145   /**
146    * buffer containing data to send
147    */
148   void * addr;
149
150   /**
151    * amount of data to sent
152    */
153   size_t addrlen;
154 };
155
156 struct Plugin_Address * addr_head;
157
158 /**
159  * Did the test pass or fail?
160  */
161 static int fail_notify_address;
162 /**
163  * Did the test pass or fail?
164  */
165 static int fail_notify_address_count;
166
167 /**
168  * Did the test pass or fail?
169  */
170 static int fail_pretty_printer;
171
172 /**
173  * Did the test pass or fail?
174  */
175 static int fail_pretty_printer_count;
176
177 /**
178  * Did the test pass or fail?
179  */
180 static int fail_addr_to_str;
181
182 /**
183  * Did the test pass or fail?
184  */
185 static int fail;
186
187 /**
188  * Recieved message already returned to sender?
189  */
190 static int sent;
191
192 CURL *curl_handle;
193
194 /**
195  * cURL Multihandle
196  */
197 static CURLM *multi_handle;
198
199 /**
200  * Test message to send
201  */
202 struct HTTP_Message * msg;
203
204 /**
205  * The task sending data
206  */
207 static GNUNET_SCHEDULER_TaskIdentifier http_task_send;
208
209 /**
210  * Shutdown testcase
211  */
212 static void
213 shutdown_clean ()
214 {
215   curl_multi_cleanup(multi_handle);
216
217   if (NULL != curl_handle)
218     curl_easy_cleanup (curl_handle);
219
220
221   if (ti_send != GNUNET_SCHEDULER_NO_TASK)
222   {
223     GNUNET_SCHEDULER_cancel(sched,ti_send);
224     ti_send = GNUNET_SCHEDULER_NO_TASK;
225   }
226
227   if (http_task_send != GNUNET_SCHEDULER_NO_TASK)
228   {
229     GNUNET_SCHEDULER_cancel(sched,http_task_send);
230     http_task_send = GNUNET_SCHEDULER_NO_TASK;
231   }
232
233   if (ti_timeout != GNUNET_SCHEDULER_NO_TASK)
234   {
235     GNUNET_SCHEDULER_cancel(sched,ti_timeout);
236     ti_timeout = GNUNET_SCHEDULER_NO_TASK;
237   }
238   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unloading http plugin\n");
239   GNUNET_assert (NULL == GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_http", api));
240
241   GNUNET_SCHEDULER_shutdown(sched);
242
243   GNUNET_free(msg->buf);
244   GNUNET_free(msg);
245
246   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Exiting testcase\n");
247   exit(fail);
248   return;
249 }
250
251 /**
252  * Continuation called after plugin send message
253  * @cls closure
254  * @target target
255  * @result GNUNET_OK or GNUNET_SYSERR
256  */
257 static void task_send_cont (void *cls,
258                             const struct GNUNET_PeerIdentity * target,
259                             int result)
260 {
261   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message was sent!\n");
262   fail = GNUNET_NO;
263   shutdown_clean();
264 }
265
266 /**
267  * Task sending recieved message back to peer
268  * @cls closure
269  * @tc task context
270  */
271 static void
272 task_send (void *cls,
273             const struct GNUNET_SCHEDULER_TaskContext *tc)
274 {
275   ti_timeout = GNUNET_SCHEDULER_NO_TASK;
276   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
277     return;
278
279   if (GNUNET_YES==sent)
280     return;
281
282   struct GNUNET_MessageHeader * msg = cls;
283   unsigned int len = ntohs(msg->size);
284   const char * msgc = (const char *) msg;
285
286   api->send(api->cls, p, msgc, len, 0, TIMEOUT, NULL,NULL, 0, GNUNET_NO, &task_send_cont, NULL);
287   sent = GNUNET_YES;
288
289 }
290
291 /**
292  * Recieves messages from plugin, in real world transport
293  */
294 static struct GNUNET_TIME_Relative
295 receive (void *cls,
296          const struct GNUNET_PeerIdentity * peer,
297          const struct GNUNET_MessageHeader * message,
298          uint32_t distance,
299          struct Session *session,
300          const char *sender_address,
301          uint16_t sender_address_len)
302 {
303   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase recieved new message from peer `%s' with type %u and length %u\n",  GNUNET_i2s(peer),ntohs(message->type),ntohs(message->size));
304
305   /* take recieved message and send it back to peer */
306   p = peer;
307   void * c = (void *) message;
308   ti_send =GNUNET_SCHEDULER_add_delayed (sched, WAIT_INTERVALL, &task_send, c);
309
310   return GNUNET_TIME_UNIT_ZERO;
311 }
312
313  int done;
314 static size_t
315 putBuffer (void *stream, size_t size, size_t nmemb, void *ptr)
316 {
317   unsigned int len;
318   struct HTTP_Message  * cbc = ptr;
319
320   len = cbc->len;
321
322   if (( cbc->pos == len) && (len < (size * nmemb)))
323     return 0;
324   memcpy(stream, cbc->buf, len);
325   cbc->pos = len;
326   return len;
327 }
328
329 static size_t copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx)
330 {
331   struct HTTP_Message *cbc = ctx;
332
333   if (cbc->pos + size * nmemb > cbc->size)
334     return 0;                   /* overflow */
335   memcpy (&cbc->buf[cbc->pos], ptr, size * nmemb);
336   cbc->pos += size * nmemb;
337   return size * nmemb;
338 }
339
340 static size_t send_prepare( void );
341
342 static void send_execute (void *cls,
343              const struct GNUNET_SCHEDULER_TaskContext *tc)
344 {
345
346
347   int running;
348   struct CURLMsg *msg;
349   CURLMcode mret;
350
351   http_task_send = GNUNET_SCHEDULER_NO_TASK;
352   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
353     return;
354
355   do
356     {
357       running = 0;
358       mret = curl_multi_perform (multi_handle, &running);
359       if (running == 0)
360         {
361           do
362             {
363
364               msg = curl_multi_info_read (multi_handle, &running);
365               GNUNET_break (msg != NULL);
366               if (msg == NULL)
367                 break;
368               /* get session for affected curl handle */
369               //cs = find_session_by_curlhandle (msg->easy_handle);
370               //GNUNET_assert ( cs != NULL );
371               switch (msg->msg)
372                 {
373
374                 case CURLMSG_DONE:
375                   if ( (msg->data.result != CURLE_OK) &&
376                        (msg->data.result != CURLE_GOT_NOTHING) )
377                     {
378
379                     GNUNET_log(GNUNET_ERROR_TYPE_INFO,
380                                _("curl failed for `%s' at %s:%d: `%s'\n"),
381                                "curl_multi_perform",
382                                __FILE__,
383                                __LINE__,
384                                curl_easy_strerror (msg->data.result));
385                     /* sending msg failed*/
386                     }
387                   else
388                     {
389                     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
390                                 "Send completed.\n");
391                     /* sending completed */
392                     }
393                   curl_easy_cleanup(curl_handle);
394                   curl_handle=NULL;
395                   shutdown_clean();
396                   return;
397                 default:
398                   break;
399                 }
400
401             }
402           while ( (running > 0) );
403         }
404     }
405   while (mret == CURLM_CALL_MULTI_PERFORM);
406   send_prepare();
407 }
408
409 /**
410  * Function setting up file descriptors and scheduling task to run
411  * @param ses session to send data to
412  * @return bytes sent to peer
413  */
414 static size_t send_prepare( void )
415 {
416   fd_set rs;
417   fd_set ws;
418   fd_set es;
419   int max;
420   struct GNUNET_NETWORK_FDSet *grs;
421   struct GNUNET_NETWORK_FDSet *gws;
422   long to;
423   CURLMcode mret;
424
425   max = -1;
426   FD_ZERO (&rs);
427   FD_ZERO (&ws);
428   FD_ZERO (&es);
429   mret = curl_multi_fdset (multi_handle, &rs, &ws, &es, &max);
430   if (mret != CURLM_OK)
431     {
432       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
433                   _("%s failed at %s:%d: `%s'\n"),
434                   "curl_multi_fdset", __FILE__, __LINE__,
435                   curl_multi_strerror (mret));
436       return -1;
437     }
438   mret = curl_multi_timeout (multi_handle, &to);
439   if (mret != CURLM_OK)
440     {
441       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
442                   _("%s failed at %s:%d: `%s'\n"),
443                   "curl_multi_timeout", __FILE__, __LINE__,
444                   curl_multi_strerror (mret));
445       return -1;
446     }
447
448   grs = GNUNET_NETWORK_fdset_create ();
449   gws = GNUNET_NETWORK_fdset_create ();
450   GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
451   GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
452   http_task_send = GNUNET_SCHEDULER_add_select (sched,
453                                    GNUNET_SCHEDULER_PRIORITY_DEFAULT,
454                                    GNUNET_SCHEDULER_NO_TASK,
455                                    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 0),
456                                    grs,
457                                    gws,
458                                    &send_execute,
459                                    NULL);
460   GNUNET_NETWORK_fdset_destroy (gws);
461   GNUNET_NETWORK_fdset_destroy (grs);
462
463   /* FIXME: return bytes REALLY sent */
464   return 0;
465 }
466
467 /**
468  * function to send data to server
469  */
470 static int send_data(struct HTTP_Message *msg, char * url)
471 {
472
473   curl_handle = curl_easy_init();
474   if( NULL == curl_handle)
475   {
476     printf("easy_init failed \n");
477     return GNUNET_SYSERR;
478   }
479 #if DEBUG_CURL
480   curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L);
481 #endif
482   curl_easy_setopt(curl_handle, CURLOPT_URL, url);
483   curl_easy_setopt(curl_handle, CURLOPT_PUT, 1L);
484   curl_easy_setopt (curl_handle, CURLOPT_WRITEFUNCTION, &copyBuffer);
485   curl_easy_setopt (curl_handle, CURLOPT_WRITEDATA, msg);
486   curl_easy_setopt (curl_handle, CURLOPT_READFUNCTION, &putBuffer);
487   curl_easy_setopt (curl_handle, CURLOPT_READDATA, msg);
488   curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) msg->len);
489   curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 30);
490   curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 20);
491
492   curl_multi_add_handle(multi_handle, curl_handle);
493
494   send_prepare();
495
496   return GNUNET_OK;
497 }
498
499 /**
500  * Network format for IPv4 addresses.
501  */
502 struct IPv4HttpAddress
503 {
504   /**
505    * IPv4 address, in network byte order.
506    */
507   uint32_t ipv4_addr;
508
509   /**
510    * Port number, in network byte order.
511    */
512   uint16_t u_port;
513
514 };
515
516
517 /**
518  * Network format for IPv6 addresses.
519  */
520 struct IPv6HttpAddress
521 {
522   /**
523    * IPv6 address.
524    */
525   struct in6_addr ipv6_addr;
526
527   /**
528    * Port number, in network byte order.
529    */
530   uint16_t u6_port;
531
532 };
533
534 /**
535  * Plugin notifies transport (aka testcase) about its addresses
536  */
537 void
538 notify_address (void *cls,
539                 const char *name,
540                 const void *addr,
541                 uint16_t addrlen,
542                 struct GNUNET_TIME_Relative expires)
543 {
544   char * address = NULL;
545   unsigned int port;
546   struct Plugin_Address * pl_addr;
547   struct Plugin_Address * cur;
548
549   if (addrlen == (sizeof (struct IPv4HttpAddress)))
550   {
551     address = GNUNET_malloc (INET_ADDRSTRLEN);
552     inet_ntop(AF_INET, (struct in_addr *) addr,address,INET_ADDRSTRLEN);
553     port = ntohs(((struct IPv4HttpAddress *) addr)->u_port);
554   }
555
556   if (addrlen == (sizeof (struct IPv6HttpAddress)))
557   {
558     address = GNUNET_malloc (INET6_ADDRSTRLEN);
559     inet_ntop(AF_INET6, (struct in6_addr *) addr,address,INET6_ADDRSTRLEN);
560     port = ntohs(((struct IPv6HttpAddress *) addr)->u6_port);
561   }
562   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Transport plugin notification for address: `%s':%u\n"),address,port);
563
564   pl_addr = GNUNET_malloc (sizeof (struct Plugin_Address) );
565   pl_addr->addrlen = addrlen;
566   pl_addr->addr = GNUNET_malloc(addrlen);
567   memcpy(pl_addr->addr,addr,addrlen);
568   pl_addr->next = NULL;
569
570   if ( NULL == addr_head)
571   {
572     addr_head = pl_addr;
573   }
574   else
575   {
576     cur = addr_head;
577     while (NULL != cur->next)
578       {
579         cur = cur->next;
580       }
581     cur->next = pl_addr;
582   }
583
584   fail_notify_address_count++;
585   fail_notify_address = GNUNET_NO;
586 }
587
588 /**
589  * Setup plugin environment
590  */
591 static void
592 setup_plugin_environment ()
593 {
594   env.cfg = cfg;
595   env.sched = sched;
596   env.stats = stats;
597   env.my_identity = &my_identity;
598   env.cls = &env;
599   env.receive = &receive;
600   env.notify_address = &notify_address;
601   env.max_connections = max_connect_per_transport;
602 }
603
604
605 /**
606  * Task shutting down testcase if it a timeout occurs
607  */
608 static void
609 task_timeout (void *cls,
610             const struct GNUNET_SCHEDULER_TaskContext *tc)
611 {
612   ti_timeout = GNUNET_SCHEDULER_NO_TASK;
613   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
614     return;
615
616   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase timeout\n");
617   fail = GNUNET_YES;
618   shutdown_clean();
619   return;
620 }
621
622 static void pretty_printer_cb (void *cls,
623                                const char *address)
624 {
625   if (NULL==address)
626     return;
627   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Plugin returned pretty address: `%s'\n",address);
628   fail_pretty_printer_count++;
629 }
630
631
632 /**
633  * Runs the test.
634  *
635  * @param cls closure
636  * @param s scheduler to use
637  * @param c configuration to use
638  */
639 static void
640 run (void *cls,
641      struct GNUNET_SCHEDULER_Handle *s,
642      char *const *args,
643      const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
644 {
645   char * libname;
646   sched = s;
647   cfg = c;
648   char *keyfile;
649   unsigned long long tneigh;
650   struct Plugin_Address * cur;
651   struct Plugin_Address * tmp;
652   const char * addr_str;
653   unsigned int count_str_addr;
654   unsigned int suggest_res;
655   unsigned int res;
656
657   fail_pretty_printer = GNUNET_YES;
658   fail_notify_address = GNUNET_YES;
659   fail_addr_to_str = GNUNET_YES;
660   addr_head = NULL;
661   count_str_addr = 0;
662   /* parse configuration */
663   if ((GNUNET_OK !=
664        GNUNET_CONFIGURATION_get_value_number (c,
665                                               "TRANSPORT",
666                                               "NEIGHBOUR_LIMIT",
667                                               &tneigh)) ||
668       (GNUNET_OK !=
669        GNUNET_CONFIGURATION_get_value_filename (c,
670                                                 "GNUNETD",
671                                                 "HOSTKEY", &keyfile)))
672     {
673       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
674                   _
675                   ("Transport service is lacking key configuration settings.  Exiting.\n"));
676       GNUNET_SCHEDULER_shutdown (s);
677       fail = 1;
678       return;
679     }
680   max_connect_per_transport = (uint32_t) tneigh;
681   my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
682   GNUNET_free (keyfile);
683   if (my_private_key == NULL)
684     {
685       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
686                   _("Transport service could not access hostkey.  Exiting.\n"));
687       GNUNET_SCHEDULER_shutdown (s);
688       fail = 1;
689       return;
690     }
691   GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
692   GNUNET_CRYPTO_hash (&my_public_key,
693                       sizeof (my_public_key), &my_identity.hashPubKey);
694
695   /* load plugins... */
696   setup_plugin_environment ();
697   GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading HTTP transport plugin `%s'\n"),"libgnunet_plugin_transport_http");
698   GNUNET_asprintf (&libname, "libgnunet_plugin_transport_http");
699   api = GNUNET_PLUGIN_load (libname, &env);
700   GNUNET_free (libname);
701   if (api == NULL)
702   {
703     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
704                 _("Failed to load transport plugin for http\n"));
705     fail = 1;
706     return;
707   }
708
709   ti_timeout = GNUNET_SCHEDULER_add_delayed (sched, TEST_TIMEOUT, &task_timeout, NULL);
710
711   /* testing plugin functionality */
712   GNUNET_assert (0!=fail_notify_address_count);
713   GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transport plugin returned %u addresses to connect to\n"),  fail_notify_address_count);
714
715   /* testing pretty printer with all addresses obtained from the plugin*/
716   while (addr_head != NULL)
717   {
718     cur = addr_head;
719
720     api->address_pretty_printer (NULL,"http",cur->addr,cur->addrlen,GNUNET_NO,TEST_TIMEOUT,&pretty_printer_cb,NULL);
721     addr_str = api->address_to_string (NULL,cur->addr,cur->addrlen);
722     suggest_res = api->check_address (NULL,cur->addr,cur->addrlen);
723
724     GNUNET_assert (GNUNET_OK == suggest_res);
725     GNUNET_assert (NULL != addr_str);
726     count_str_addr++;
727
728     tmp = addr_head->next;
729     GNUNET_free (addr_head->addr);
730     GNUNET_free (addr_head);
731     GNUNET_free ((char *) addr_str);
732     addr_head=tmp;
733   }
734   GNUNET_assert (fail_pretty_printer_count==fail_notify_address_count);
735   GNUNET_assert (fail_pretty_printer_count==count_str_addr);
736   fail_pretty_printer=GNUNET_NO;
737   fail_addr_to_str=GNUNET_NO;
738
739   /* Suggesting addresses with wrong port*/
740   struct IPv4HttpAddress failing_addr;
741   failing_addr.ipv4_addr = INADDR_LOOPBACK;
742   failing_addr.u_port = 0;
743   suggest_res = api->check_address (NULL,&failing_addr,sizeof (struct IPv4HttpAddress));
744   GNUNET_assert (GNUNET_SYSERR == suggest_res);
745
746   /* Suggesting addresses with wrong size*/
747   failing_addr.ipv4_addr = INADDR_LOOPBACK;
748   failing_addr.u_port = 0;
749   suggest_res = api->check_address (NULL,&failing_addr,sizeof (struct IPv6HttpAddress));
750   GNUNET_assert (GNUNET_SYSERR == suggest_res);
751
752   /* Suggesting addresses with wrong address*/
753   failing_addr.ipv4_addr = 0;
754   failing_addr.u_port = 12389;
755   suggest_res = api->check_address (NULL,&failing_addr,sizeof (struct IPv4HttpAddress));
756   GNUNET_assert (GNUNET_SYSERR == suggest_res);
757
758   /* test sending to client */
759   multi_handle = curl_multi_init();
760
761   /*building messages */
762   msg = GNUNET_malloc (sizeof (struct HTTP_Message));
763   msg->size = 2048;
764   msg->pos = 0;
765   msg->buf = GNUNET_malloc (2048);
766
767   res = send_data (msg, "http://localhost:12389/");
768
769   /* testing finished, shutting down */
770   if ((fail_notify_address == GNUNET_NO) && (fail_pretty_printer == GNUNET_NO) && (fail_addr_to_str == GNUNET_NO) )
771     fail = 0;
772   else
773     fail = 1;
774   //shutdown_clean();
775   return;
776 }
777
778
779 /**
780  * The main function for the transport service.
781  *
782  * @param argc number of arguments from the command line
783  * @param argv command line arguments
784  * @return 0 ok, 1 on error
785  */
786 int
787 main (int argc, char *const *argv)
788 {
789
790   static struct GNUNET_GETOPT_CommandLineOption options[] = {
791     GNUNET_GETOPT_OPTION_END
792   };
793   int ret;
794   char *const argv_prog[] = {
795     "test_plugin_transport_http",
796     "-c",
797     "test_plugin_transport_data_http.conf",
798     "-L",
799 #if VERBOSE
800     "DEBUG",
801 #else
802     "WARNING",
803 #endif
804     NULL
805   };
806   GNUNET_log_setup ("test_plugin_transport_http",
807 #if VERBOSE
808                     "DEBUG",
809 #else
810                     "WARNING",
811 #endif
812                     NULL);
813
814   ret = (GNUNET_OK ==
815          GNUNET_PROGRAM_run (5,
816                              argv_prog,
817                              "test_plugin_transport_http",
818                              "testcase", options, &run, NULL)) ? GNUNET_NO : GNUNET_YES;
819
820     GNUNET_DISK_directory_remove ("/tmp/test_plugin_transport_http");
821
822   return fail;
823 }
824
825 /* end of test_plugin_transport_http.c */