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