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