just to be sure curl is not causing the disconnects
[oweals/gnunet.git] / src / transport / plugin_transport_http_client.c
1 /*
2      This file is part of GNUnet
3      (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 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 /**
22  * @file transport/plugin_transport_http_client.c
23  * @brief http transport service plugin
24  * @author Matthias Wachs
25  */
26
27 #include "plugin_transport_http.h"
28
29 #if VERBOSE_CURL
30 /**
31  * Function to log curl debug messages with GNUNET_log
32  * @param curl handle
33  * @param type curl_infotype
34  * @param data data
35  * @param size size
36  * @param cls  closure
37  * @return 0
38  */
39 static int
40 client_log (CURL * curl, curl_infotype type, char *data, size_t size, void *cls)
41 {
42   if (type == CURLINFO_TEXT)
43   {
44     char text[size + 2];
45
46     memcpy (text, data, size);
47     if (text[size - 1] == '\n')
48       text[size] = '\0';
49     else
50     {
51       text[size] = '\n';
52       text[size + 1] = '\0';
53     }
54 #if BUILD_HTTPS
55     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-https", "Client: %X - %s", cls, text);
56 #else
57     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-http", "Client: %X - %s", cls, text);
58 #endif
59   }
60   return 0;
61 }
62 #endif
63
64 /**
65  * Task performing curl operations
66  * @param cls plugin as closure
67  * @param tc gnunet scheduler task context
68  */
69 static void
70 client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
71
72 /**
73  * Function setting up file descriptors and scheduling task to run
74  *
75  * @param  plugin plugin as closure
76  * @return GNUNET_SYSERR for hard failure, GNUNET_OK for ok
77  */
78 static int
79 client_schedule (struct Plugin *plugin)
80 {
81   fd_set rs;
82   fd_set ws;
83   fd_set es;
84   int max;
85   struct GNUNET_NETWORK_FDSet *grs;
86   struct GNUNET_NETWORK_FDSet *gws;
87   long to;
88   CURLMcode mret;
89   struct GNUNET_TIME_Relative timeout;
90
91   /* Cancel previous scheduled task */
92   if (plugin->client_perform_task!= GNUNET_SCHEDULER_NO_TASK)
93   {
94     GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
95     plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
96   }
97
98   max = -1;
99   FD_ZERO (&rs);
100   FD_ZERO (&ws);
101   FD_ZERO (&es);
102   mret = curl_multi_fdset (plugin->client_mh, &rs, &ws, &es, &max);
103   if (mret != CURLM_OK)
104   {
105     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
106                 "curl_multi_fdset", __FILE__, __LINE__,
107                 curl_multi_strerror (mret));
108     return GNUNET_SYSERR;
109   }
110   mret = curl_multi_timeout (plugin->client_mh, &to);
111   if (to == -1)
112     timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5);
113   else
114     timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, to);
115   if (mret != CURLM_OK)
116   {
117     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
118                 "curl_multi_timeout", __FILE__, __LINE__,
119                 curl_multi_strerror (mret));
120     return GNUNET_SYSERR;
121   }
122
123   grs = GNUNET_NETWORK_fdset_create ();
124   gws = GNUNET_NETWORK_fdset_create ();
125   GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
126   GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
127
128   plugin->client_perform_task =
129       GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
130                                    GNUNET_SCHEDULER_NO_TASK,
131                                    timeout,
132                                    grs,
133                                    gws,
134                                    &client_run,
135                                    plugin);
136   GNUNET_NETWORK_fdset_destroy (gws);
137   GNUNET_NETWORK_fdset_destroy (grs);
138   return GNUNET_OK;
139 }
140
141
142 int
143 client_send (struct Session *s, struct HTTP_Message *msg)
144 {
145   GNUNET_CONTAINER_DLL_insert (s->msg_head, s->msg_tail, msg);
146
147   if ((s != NULL) && (s->client_put_paused == GNUNET_YES))
148   {
149 #if VERBOSE_CLIENT
150     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, "Client: %X was suspended, unpausing\n", s->client_put);
151 #endif
152     s->client_put_paused = GNUNET_NO;
153     curl_easy_pause(s->client_put, CURLPAUSE_CONT);
154   }
155
156   client_schedule (s->plugin);
157
158   return GNUNET_OK;
159 }
160
161
162
163 /**
164  * Task performing curl operations
165  * @param cls plugin as closure
166  * @param tc gnunet scheduler task context
167  */
168 static void
169 client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
170 {
171   struct Plugin *plugin = cls;
172   int running;
173   CURLMcode mret;
174
175   GNUNET_assert (cls != NULL);
176
177   plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
178   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
179     return;
180
181   do
182   {
183     running = 0;
184     mret = curl_multi_perform (plugin->client_mh, &running);
185
186     CURLMsg * msg;
187     int msgs_left;
188     while ((msg = curl_multi_info_read(plugin->client_mh, &msgs_left)))
189     {
190        CURL *easy_h  = msg->easy_handle;
191        struct Session *s =  NULL;
192        char * d = (char *) s;
193        GNUNET_assert (easy_h != NULL);
194
195        GNUNET_assert (CURLE_OK == curl_easy_getinfo(easy_h, CURLINFO_PRIVATE, &d));
196        s = (struct Session *) d;
197        GNUNET_assert (s != NULL);
198
199        if (msg->msg == CURLMSG_DONE)
200        {
201 #if DEBUG_HTTP
202          GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
203                    "Client: %X connection to '%s'  %s ended\n", msg->easy_handle, GNUNET_i2s(&s->target), GNUNET_a2s (s->addr, s->addrlen));
204 #endif
205          client_disconnect(s);
206          //GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,"Notifying about ended session to peer `%s' `%s'\n", GNUNET_i2s (&s->target), http_plugin_address_to_string (plugin, s->addr, s->addrlen));
207          notify_session_end (plugin, &s->target, s);
208        }
209     }
210   }
211   while (mret == CURLM_CALL_MULTI_PERFORM);
212   client_schedule (plugin);
213 }
214
215 int
216 client_disconnect (struct Session *s)
217 {
218   int res = GNUNET_OK;
219   CURLMcode mret;
220   struct Plugin *plugin = s->plugin;
221   struct HTTP_Message * msg;
222   struct HTTP_Message * t;
223
224
225
226   if (s->client_put != NULL)
227   {
228 #if DEBUG_HTTP
229   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
230                    "Client: %X Deleting outbound PUT session to peer `%s'\n",
231                    s->client_put,
232                    GNUNET_i2s (&s->target));
233 #endif
234
235     mret = curl_multi_remove_handle (plugin->client_mh, s->client_put);
236     if (mret != CURLM_OK)
237     {
238       curl_easy_cleanup (s->client_put);
239       res = GNUNET_SYSERR;
240       GNUNET_break (0);
241     }
242     curl_easy_cleanup (s->client_put);
243     s->client_put = NULL;
244   }
245
246
247   if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK)
248   {
249    GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
250    s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK;
251   }
252
253   if (s->client_get != NULL)
254   {
255 #if DEBUG_HTTP
256   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
257                    "Client: %X Deleting outbound GET session to peer `%s'\n",
258                    s->client_get,
259                    GNUNET_i2s (&s->target));
260 #endif
261
262     mret = curl_multi_remove_handle (plugin->client_mh, s->client_get);
263     if (mret != CURLM_OK)
264     {
265       curl_easy_cleanup (s->client_get);
266       res = GNUNET_SYSERR;
267       GNUNET_break (0);
268     }
269     curl_easy_cleanup (s->client_get);
270     s->client_get = NULL;
271   }
272
273   msg = s->msg_head;
274   while (msg != NULL)
275   {
276     t = msg->next;
277     if (NULL != msg->transmit_cont)
278       msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR);
279     GNUNET_CONTAINER_DLL_remove(s->msg_head, s->msg_tail, msg);
280     GNUNET_free (msg);
281     msg = t;
282   }
283
284   plugin->cur_connections -= 2;
285   /* Re-schedule since handles have changed */
286   if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK)
287   {
288     GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
289     plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
290   }
291
292   plugin->client_perform_task = GNUNET_SCHEDULER_add_now(client_run, plugin);
293
294   return res;
295 }
296
297 static void
298 client_receive_mst_cb (void *cls, void *client,
299                      const struct GNUNET_MessageHeader *message)
300 {
301   struct Session *s = cls;
302   struct Plugin *plugin = s->plugin;
303   struct GNUNET_TIME_Relative delay;
304
305   delay = http_plugin_receive (s, &s->target, message, s, s->addr, s->addrlen);
306   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "CLIENT: CLIENT DELAY %llu ms\n",
307               delay.rel_value);
308
309
310   s->next_receive = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), delay);
311
312   if (GNUNET_TIME_absolute_get().abs_value < s->next_receive.abs_value)
313   {
314 #if VERBOSE_CLIENT
315     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Client: peer `%s' address `%s' next read delayed for %llu ms\n",
316                 GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen), delay);
317 #endif
318   }
319 }
320 static void
321 client_wake_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
322 {
323   struct Session *s = cls;
324
325   s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK;
326
327   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
328     return;
329
330   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name,
331       "Client: %X Waking up receive handle\n",
332               s->client_get);
333
334   if (s->client_get != NULL)
335     curl_easy_pause(s->client_get, CURLPAUSE_CONT);
336
337 }
338
339 /**
340 * Callback method used with libcurl
341 * Method is called when libcurl needs to write data during sending
342 * @param stream pointer where to write data
343 * @param size size of an individual element
344 * @param nmemb count of elements that can be written to the buffer
345 * @param ptr destination pointer, passed to the libcurl handle
346 * @return bytes read from stream
347 */
348 static size_t
349 client_receive (void *stream, size_t size, size_t nmemb, void *cls)
350 {
351   struct Session *s = cls;
352   struct GNUNET_TIME_Absolute now;
353   size_t len = size * nmemb;
354
355
356 #if VERBOSE_CLIENT
357   struct Plugin *plugin = s->plugin;
358   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Client: Received %Zu bytes from peer `%s'\n",
359                    len,
360                    GNUNET_i2s (&s->target));
361 #endif
362
363   now = GNUNET_TIME_absolute_get();
364   if (now.abs_value < s->next_receive.abs_value)
365   {
366     struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
367     struct GNUNET_TIME_Relative delta = GNUNET_TIME_absolute_get_difference(now, s->next_receive);
368 #if DEBUG_CLIENT
369     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
370         "Client: %X No inbound bandwidth available! Next read was delayed for %llu ms\n",
371                 s->client_get, delta.rel_value);
372 #endif
373     if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK)
374     {
375       GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
376       s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK;
377     }
378     s->recv_wakeup_task = GNUNET_SCHEDULER_add_delayed (delta, &client_wake_up, s);
379     return CURLPAUSE_ALL;
380   }
381
382
383   if (s->msg_tk == NULL)
384       s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, s);
385
386   GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, len, GNUNET_NO,
387                              GNUNET_NO);
388
389   return len;
390   client_wake_up(NULL,NULL);
391 }
392
393 /**
394  * Callback method used with libcurl
395  * Method is called when libcurl needs to read data during sending
396  * @param stream pointer where to write data
397  * @param size size of an individual element
398  * @param nmemb count of elements that can be written to the buffer
399  * @param ptr source pointer, passed to the libcurl handle
400  * @return bytes written to stream, returning 0 will terminate connection!
401  */
402 static size_t
403 client_send_cb (void *stream, size_t size, size_t nmemb, void *cls)
404 {
405   struct Session *s = cls;
406 #if VERBOSE_CLIENT
407   struct Plugin *plugin = s->plugin;
408 #endif
409   size_t bytes_sent = 0;
410   size_t len;
411
412   struct HTTP_Message *msg = s->msg_head;
413
414   if (msg == NULL)
415   {
416 #if VERBOSE_CLIENT
417     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Client: %X Nothing to send! Suspending PUT handle!\n", s->client_put);
418 #endif
419     s->client_put_paused = GNUNET_YES;
420     return CURL_READFUNC_PAUSE;
421   }
422
423   GNUNET_assert (msg != NULL);
424   /* data to send */
425   if (msg->pos < msg->size)
426   {
427     /* data fit in buffer */
428     if ((msg->size - msg->pos) <= (size * nmemb))
429     {
430       len = (msg->size - msg->pos);
431       memcpy (stream, &msg->buf[msg->pos], len);
432       msg->pos += len;
433       bytes_sent = len;
434     }
435     else
436     {
437       len = size * nmemb;
438       memcpy (stream, &msg->buf[msg->pos], len);
439       msg->pos += len;
440       bytes_sent = len;
441     }
442   }
443   /* no data to send */
444   else
445   {
446     GNUNET_assert (0);
447     bytes_sent = 0;
448   }
449
450   if (msg->pos == msg->size)
451   {
452 #if VERBOSE_CLIENT
453     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
454                 "Client: %X Message with %u bytes sent, removing message from queue\n",
455                 s->client_put, msg->size, msg->pos);
456 #endif
457     /* Calling transmit continuation  */
458     if (NULL != msg->transmit_cont)
459       msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK);
460     GNUNET_CONTAINER_DLL_remove(s->msg_head, s->msg_tail, msg);
461     GNUNET_free (msg);
462   }
463   return bytes_sent;
464 }
465
466 int
467 client_connect (struct Session *s)
468 {
469   struct Plugin *plugin = s->plugin;
470   int res = GNUNET_OK;
471   char *url;
472   CURLMcode mret;
473
474 #if VERBOSE_CLIENT
475   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
476                    "Initiating outbound session peer `%s'\n",
477                    GNUNET_i2s (&s->target));
478 #endif
479
480   s->inbound = GNUNET_NO;
481
482   plugin->last_tag++;
483   /* create url */
484   GNUNET_asprintf (&url, "%s%s;%u", http_plugin_address_to_string (plugin, s->addr, s->addrlen), GNUNET_h2s_full (&plugin->env->my_identity->hashPubKey),plugin->last_tag);
485 #if 0
486   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
487                    "URL `%s'\n",
488                    url);
489 #endif
490   /* create get connection */
491   s->client_get = curl_easy_init ();
492 #if VERBOSE_CURL
493   curl_easy_setopt (s->client_get, CURLOPT_VERBOSE, 1L);
494   curl_easy_setopt (s->client_get, CURLOPT_DEBUGFUNCTION, &client_log);
495   curl_easy_setopt (s->client_get, CURLOPT_DEBUGDATA, s->client_get);
496 #endif
497 #if BUILD_HTTPS
498   curl_easy_setopt (s->client_get, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
499   curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 0);
500   curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 0);
501 #endif
502   curl_easy_setopt (s->client_get, CURLOPT_URL, url);
503   //curl_easy_setopt (s->client_get, CURLOPT_HEADERFUNCTION, &curl_get_header_cb);
504   //curl_easy_setopt (s->client_get, CURLOPT_WRITEHEADER, ps);
505   curl_easy_setopt (s->client_get, CURLOPT_READFUNCTION, client_send_cb);
506   curl_easy_setopt (s->client_get, CURLOPT_READDATA, s);
507   curl_easy_setopt (s->client_get, CURLOPT_WRITEFUNCTION, client_receive);
508   curl_easy_setopt (s->client_get, CURLOPT_WRITEDATA, s);
509   curl_easy_setopt (s->client_get, CURLOPT_TIMEOUT_MS,
510       30000);
511                     //(long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
512   curl_easy_setopt (s->client_get, CURLOPT_PRIVATE, s);
513   curl_easy_setopt (s->client_get, CURLOPT_CONNECTTIMEOUT_MS,
514       30000);
515                     //(long) HTTP_NOT_VALIDATED_TIMEOUT.rel_value);
516   curl_easy_setopt (s->client_get, CURLOPT_BUFFERSIZE,
517                     2 * GNUNET_SERVER_MAX_MESSAGE_SIZE);
518 #if CURL_TCP_NODELAY
519   curl_easy_setopt (ps->recv_endpoint, CURLOPT_TCP_NODELAY, 1);
520 #endif
521
522   /* create put connection */
523   s->client_put = curl_easy_init ();
524 #if VERBOSE_CURL
525   curl_easy_setopt (s->client_put, CURLOPT_VERBOSE, 1L);
526   curl_easy_setopt (s->client_put, CURLOPT_DEBUGFUNCTION, &client_log);
527   curl_easy_setopt (s->client_put, CURLOPT_DEBUGDATA, s->client_put);
528 #endif
529 #if BUILD_HTTPS
530   curl_easy_setopt (s->client_put, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
531   curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 0);
532   curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 0);
533 #endif
534   curl_easy_setopt (s->client_put, CURLOPT_URL, url);
535   curl_easy_setopt (s->client_put, CURLOPT_PUT, 1L);
536   //curl_easy_setopt (s->client_put, CURLOPT_HEADERFUNCTION, &curl_put_header_cb);
537   //curl_easy_setopt (s->client_put, CURLOPT_WRITEHEADER, ps);
538   curl_easy_setopt (s->client_put, CURLOPT_READFUNCTION, client_send_cb);
539   curl_easy_setopt (s->client_put, CURLOPT_READDATA, s);
540   curl_easy_setopt (s->client_put, CURLOPT_WRITEFUNCTION, client_receive);
541   curl_easy_setopt (s->client_put, CURLOPT_WRITEDATA, s);
542   curl_easy_setopt (s->client_put, CURLOPT_TIMEOUT_MS,
543       300000);
544                     //(long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
545   curl_easy_setopt (s->client_put, CURLOPT_PRIVATE, s);
546   curl_easy_setopt (s->client_put, CURLOPT_CONNECTTIMEOUT_MS,
547       300000);
548                     //(long) HTTP_NOT_VALIDATED_TIMEOUT.rel_value);
549   curl_easy_setopt (s->client_put, CURLOPT_BUFFERSIZE,
550                     2 * GNUNET_SERVER_MAX_MESSAGE_SIZE);
551 #if CURL_TCP_NODELAY
552   curl_easy_setopt (s->client_put, CURLOPT_TCP_NODELAY, 1);
553 #endif
554
555   GNUNET_free (url);
556
557   mret = curl_multi_add_handle (plugin->client_mh, s->client_get);
558   if (mret != CURLM_OK)
559   {
560     curl_easy_cleanup (s->client_get);
561     res = GNUNET_SYSERR;
562     GNUNET_break (0);
563   }
564
565   mret = curl_multi_add_handle (plugin->client_mh, s->client_put);
566   if (mret != CURLM_OK)
567   {
568     curl_multi_remove_handle (plugin->client_mh, s->client_get);
569     curl_easy_cleanup (s->client_get);
570     curl_easy_cleanup (s->client_put);
571     res = GNUNET_SYSERR;
572     GNUNET_break (0);
573   }
574
575   /* Perform connect */
576   plugin->cur_connections += 2;
577
578   /* Re-schedule since handles have changed */
579   if (plugin->client_perform_task!= GNUNET_SCHEDULER_NO_TASK)
580   {
581     GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
582     plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
583   }
584   plugin->client_perform_task = GNUNET_SCHEDULER_add_now (client_run, plugin);
585
586   return res;
587 }
588
589 int
590 client_start (struct Plugin *plugin)
591 {
592   int res = GNUNET_OK;
593
594   curl_global_init (CURL_GLOBAL_ALL);
595   plugin->client_mh = curl_multi_init ();
596
597   if (NULL == plugin->client_mh)
598   {
599     GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
600                      _
601                      ("Could not initialize curl multi handle, failed to start %s plugin!\n"),
602                      plugin->name);
603     res = GNUNET_SYSERR;
604   }
605   return res;
606 }
607
608 void
609 client_stop (struct Plugin *plugin)
610 {
611   if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK)
612   {
613     GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
614     plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
615   }
616
617   curl_multi_cleanup (plugin->client_mh);
618   curl_global_cleanup ();
619 }
620
621
622
623 /* end of plugin_transport_http_client.c */