cd68a00693632f612822bbae90df6fce252eaadc
[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     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, "Client: %X was suspended, unpausing\n", s->client_put);
150     s->client_put_paused = GNUNET_NO;
151     curl_easy_pause(s->client_put, CURLPAUSE_CONT);
152   }
153
154   client_schedule (s->plugin);
155
156   return GNUNET_OK;
157 }
158
159
160
161 /**
162  * Task performing curl operations
163  * @param cls plugin as closure
164  * @param tc gnunet scheduler task context
165  */
166 static void
167 client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
168 {
169   struct Plugin *plugin = cls;
170   static unsigned int handles_last_run;
171   int running;
172   CURLMcode mret;
173
174   GNUNET_assert (cls != NULL);
175
176   plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
177   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
178     return;
179
180   do
181   {
182     running = 0;
183     mret = curl_multi_perform (plugin->client_mh, &running);
184
185     CURLMsg * msg;
186     int msgs_left;
187     while ((msg = curl_multi_info_read(plugin->client_mh, &msgs_left)))
188     {
189        CURL *easy_h  = msg->easy_handle;
190        struct Session *s =  NULL;
191        char * d = (char *) s;
192        GNUNET_assert (easy_h != NULL);
193
194        GNUNET_assert (CURLE_OK == curl_easy_getinfo(easy_h, CURLINFO_PRIVATE, &d));
195        s = (struct Session *) d;
196        GNUNET_assert (s != NULL);
197
198        if (msg->msg == CURLMSG_DONE)
199        {
200 #if DEBUG_HTTP
201          GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
202                    "Client: %X connection to '%s'  %s ended\n", msg->easy_handle, GNUNET_i2s(&s->target), GNUNET_a2s (s->addr, s->addrlen));
203 #endif
204          client_disconnect(s);
205          //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));
206          if (s->msg_tk != NULL)
207            GNUNET_SERVER_mst_destroy (s->msg_tk);
208          notify_session_end (plugin, &s->target, s);
209        }
210     }
211
212     handles_last_run = running;
213   }
214   while (mret == CURLM_CALL_MULTI_PERFORM);
215   client_schedule (plugin);
216 }
217
218 int
219 client_disconnect (struct Session *s)
220 {
221   int res = GNUNET_OK;
222   CURLMcode mret;
223   struct Plugin *plugin = s->plugin;
224   struct HTTP_Message * msg;
225   struct HTTP_Message * t;
226
227
228
229   if (s->client_put != NULL)
230   {
231 #if DEBUG_HTTP
232   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
233                    "Client: %X Deleting outbound PUT session to peer `%s'\n",
234                    s->client_put,
235                    GNUNET_i2s (&s->target));
236 #endif
237
238     mret = curl_multi_remove_handle (plugin->client_mh, s->client_put);
239     if (mret != CURLM_OK)
240     {
241       curl_easy_cleanup (s->client_put);
242       res = GNUNET_SYSERR;
243       GNUNET_break (0);
244     }
245     curl_easy_cleanup (s->client_put);
246     s->client_put = NULL;
247   }
248
249
250   if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK)
251   {
252    GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
253    s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK;
254   }
255
256   if (s->client_get != NULL)
257   {
258 #if DEBUG_HTTP
259   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
260                    "Client: %X Deleting outbound GET session to peer `%s'\n",
261                    s->client_get,
262                    GNUNET_i2s (&s->target));
263 #endif
264
265     mret = curl_multi_remove_handle (plugin->client_mh, s->client_get);
266     if (mret != CURLM_OK)
267     {
268       curl_easy_cleanup (s->client_get);
269       res = GNUNET_SYSERR;
270       GNUNET_break (0);
271     }
272     curl_easy_cleanup (s->client_get);
273     s->client_get = NULL;
274   }
275
276   msg = s->msg_head;
277   while (msg != NULL)
278   {
279     t = msg->next;
280     if (NULL != msg->transmit_cont)
281       msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR);
282     GNUNET_CONTAINER_DLL_remove(s->msg_head, s->msg_tail, msg);
283     GNUNET_free (msg);
284     msg = t;
285   }
286
287   plugin->cur_connections -= 2;
288   /* Re-schedule since handles have changed */
289   if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK)
290   {
291     GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
292     plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
293   }
294
295   plugin->client_perform_task = GNUNET_SCHEDULER_add_now(client_run, plugin);
296
297   return res;
298 }
299
300 static void
301 client_receive_mst_cb (void *cls, void *client,
302                      const struct GNUNET_MessageHeader *message)
303 {
304   struct Session *s = cls;
305   struct Plugin *plugin = s->plugin;
306   struct GNUNET_TIME_Relative delay;
307
308   delay = http_plugin_receive (s, &s->target, message, s, s->addr, s->addrlen);
309
310   s->delay = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), delay);
311
312   if (GNUNET_TIME_absolute_get().abs_value < s->delay.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   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
327     return;
328
329   if (s->client_get != NULL)
330     curl_easy_pause(s->client_get, CURLPAUSE_CONT);
331 }
332
333 /**
334 * Callback method used with libcurl
335 * Method is called when libcurl needs to write data during sending
336 * @param stream pointer where to write data
337 * @param size size of an individual element
338 * @param nmemb count of elements that can be written to the buffer
339 * @param ptr destination pointer, passed to the libcurl handle
340 * @return bytes read from stream
341 */
342 static size_t
343 client_receive (void *stream, size_t size, size_t nmemb, void *cls)
344 {
345   struct Session *s = cls;
346   struct Plugin *plugin = s->plugin;
347   struct GNUNET_TIME_Absolute now;
348   size_t len = size * nmemb;
349
350
351 #if VERBOSE_CLIENT
352   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Client: Received %Zu bytes from peer `%s'\n",
353                    len,
354                    GNUNET_i2s (&s->target));
355 #endif
356
357   now = GNUNET_TIME_absolute_get();
358   if (now.abs_value < s->delay.abs_value)
359   {
360 #if 0
361 #if DEBUG_CLIENT
362     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
363                 "No inbound bandwidth available! Next read was delayed for  %llu ms\n",
364                 s, GNUNET_TIME_absolute_get_difference(s->delay, GNUNET_TIME_absolute_get()).rel_value);
365 #endif
366     if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK)
367     {
368       GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
369       s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK;
370     }
371     s->recv_wakeup_task = GNUNET_SCHEDULER_add_delayed( GNUNET_TIME_absolute_get_difference(s->delay, now), &client_wake_up, s);
372     return CURLPAUSE_ALL;
373 #endif
374   }
375
376
377   if (s->msg_tk == NULL)
378       s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, s);
379
380   GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, len, GNUNET_NO,
381                              GNUNET_NO);
382
383   return len;
384
385   client_wake_up (NULL, NULL);
386 }
387
388 /**
389  * Callback method used with libcurl
390  * Method is called when libcurl needs to read data during sending
391  * @param stream pointer where to write data
392  * @param size size of an individual element
393  * @param nmemb count of elements that can be written to the buffer
394  * @param ptr source pointer, passed to the libcurl handle
395  * @return bytes written to stream, returning 0 will terminate connection!
396  */
397 static size_t
398 client_send_cb (void *stream, size_t size, size_t nmemb, void *cls)
399 {
400   struct Session *s = cls;
401   struct Plugin *plugin = s->plugin;
402   size_t bytes_sent = 0;
403   size_t len;
404
405   struct HTTP_Message *msg = s->msg_head;
406 /*
407   if (s->put_paused == GNUNET_NO)
408     return CURL_READFUNC_PAUSE;
409   if ((s->msg_head == NULL) && (s->put_paused == GNUNET_YES))
410   {
411 #if VERBOSE_CLIENT
412     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Suspending handle `%s' `%s'\n",
413                      GNUNET_i2s (&s->target),GNUNET_a2s (s->addr, s->addrlen));
414 #endif
415     s->put_paused = GNUNET_NO;
416     return CURL_READFUNC_PAUSE;
417   }
418 */
419   if (msg == NULL)
420   {
421     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Client: %X Nothing to send! Suspending PUT handle!\n", s->client_put);
422     s->client_put_paused = GNUNET_YES;
423     return CURL_READFUNC_PAUSE;
424   }
425
426   GNUNET_assert (msg != NULL);
427   /* data to send */
428   if (msg->pos < msg->size)
429   {
430     /* data fit in buffer */
431     if ((msg->size - msg->pos) <= (size * nmemb))
432     {
433       len = (msg->size - msg->pos);
434       memcpy (stream, &msg->buf[msg->pos], len);
435       msg->pos += len;
436       bytes_sent = len;
437     }
438     else
439     {
440       len = size * nmemb;
441       memcpy (stream, &msg->buf[msg->pos], len);
442       msg->pos += len;
443       bytes_sent = len;
444     }
445   }
446   /* no data to send */
447   else
448   {
449     GNUNET_assert (0);
450     bytes_sent = 0;
451   }
452
453   if (msg->pos == msg->size)
454   {
455 #if VERBOSE_CLIENT
456     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
457                 "Client: %X Message with %u bytes sent, removing message from queue\n",
458                 s->client_put, msg->size, msg->pos);
459 #endif
460     /* Calling transmit continuation  */
461     if (NULL != msg->transmit_cont)
462       msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK);
463     GNUNET_CONTAINER_DLL_remove(s->msg_head, s->msg_tail, msg);
464     GNUNET_free (msg);
465   }
466   return bytes_sent;
467 }
468
469 int
470 client_connect (struct Session *s)
471 {
472   struct Plugin *plugin = s->plugin;
473   int res = GNUNET_OK;
474   char *url;
475   CURLMcode mret;
476
477 #if VERBOSE_CLIENT
478   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
479                    "Initiating outbound session peer `%s'\n",
480                    GNUNET_i2s (&s->target));
481 #endif
482
483   s->inbound = GNUNET_NO;
484
485   plugin->last_tag++;
486   /* create url */
487   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);
488 #if 0
489   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
490                    "URL `%s'\n",
491                    url);
492 #endif
493   /* create get connection */
494   s->client_get = curl_easy_init ();
495 #if VERBOSE_CURL
496   curl_easy_setopt (s->client_get, CURLOPT_VERBOSE, 1L);
497   curl_easy_setopt (s->client_get, CURLOPT_DEBUGFUNCTION, &client_log);
498   curl_easy_setopt (s->client_get, CURLOPT_DEBUGDATA, s->client_get);
499 #endif
500 #if BUILD_HTTPS
501   curl_easy_setopt (s->client_get, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
502   curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 0);
503   curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 0);
504 #endif
505   curl_easy_setopt (s->client_get, CURLOPT_URL, url);
506   //curl_easy_setopt (s->client_get, CURLOPT_HEADERFUNCTION, &curl_get_header_cb);
507   //curl_easy_setopt (s->client_get, CURLOPT_WRITEHEADER, ps);
508   curl_easy_setopt (s->client_get, CURLOPT_READFUNCTION, client_send_cb);
509   curl_easy_setopt (s->client_get, CURLOPT_READDATA, s);
510   curl_easy_setopt (s->client_get, CURLOPT_WRITEFUNCTION, client_receive);
511   curl_easy_setopt (s->client_get, CURLOPT_WRITEDATA, s);
512   curl_easy_setopt (s->client_get, CURLOPT_TIMEOUT_MS,
513                     (long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
514   curl_easy_setopt (s->client_get, CURLOPT_PRIVATE, s);
515   curl_easy_setopt (s->client_get, CURLOPT_CONNECTTIMEOUT_MS,
516                     (long) HTTP_NOT_VALIDATED_TIMEOUT.rel_value);
517   curl_easy_setopt (s->client_get, CURLOPT_BUFFERSIZE,
518                     2 * GNUNET_SERVER_MAX_MESSAGE_SIZE);
519 #if CURL_TCP_NODELAY
520   curl_easy_setopt (ps->recv_endpoint, CURLOPT_TCP_NODELAY, 1);
521 #endif
522
523   /* create put connection */
524   s->client_put = curl_easy_init ();
525 #if VERBOSE_CURL
526   curl_easy_setopt (s->client_put, CURLOPT_VERBOSE, 1L);
527   curl_easy_setopt (s->client_put, CURLOPT_DEBUGFUNCTION, &client_log);
528   curl_easy_setopt (s->client_put, CURLOPT_DEBUGDATA, s->client_put);
529 #endif
530 #if BUILD_HTTPS
531   curl_easy_setopt (s->client_put, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
532   curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 0);
533   curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 0);
534 #endif
535   curl_easy_setopt (s->client_put, CURLOPT_URL, url);
536   curl_easy_setopt (s->client_put, CURLOPT_PUT, 1L);
537   //curl_easy_setopt (s->client_put, CURLOPT_HEADERFUNCTION, &curl_put_header_cb);
538   //curl_easy_setopt (s->client_put, CURLOPT_WRITEHEADER, ps);
539   curl_easy_setopt (s->client_put, CURLOPT_READFUNCTION, client_send_cb);
540   curl_easy_setopt (s->client_put, CURLOPT_READDATA, s);
541   curl_easy_setopt (s->client_put, CURLOPT_WRITEFUNCTION, client_receive);
542   curl_easy_setopt (s->client_put, CURLOPT_WRITEDATA, s);
543   curl_easy_setopt (s->client_put, CURLOPT_TIMEOUT_MS,
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                     (long) HTTP_NOT_VALIDATED_TIMEOUT.rel_value);
548   curl_easy_setopt (s->client_put, CURLOPT_BUFFERSIZE,
549                     2 * GNUNET_SERVER_MAX_MESSAGE_SIZE);
550 #if CURL_TCP_NODELAY
551   curl_easy_setopt (s->client_put, CURLOPT_TCP_NODELAY, 1);
552 #endif
553
554   GNUNET_free (url);
555
556   mret = curl_multi_add_handle (plugin->client_mh, s->client_get);
557   if (mret != CURLM_OK)
558   {
559     curl_easy_cleanup (s->client_get);
560     res = GNUNET_SYSERR;
561     GNUNET_break (0);
562   }
563
564   mret = curl_multi_add_handle (plugin->client_mh, s->client_put);
565   if (mret != CURLM_OK)
566   {
567     curl_multi_remove_handle (plugin->client_mh, s->client_get);
568     curl_easy_cleanup (s->client_get);
569     curl_easy_cleanup (s->client_put);
570     res = GNUNET_SYSERR;
571     GNUNET_break (0);
572   }
573
574   /* Perform connect */
575   plugin->cur_connections += 2;
576
577   /* Re-schedule since handles have changed */
578   if (plugin->client_perform_task!= GNUNET_SCHEDULER_NO_TASK)
579   {
580     GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
581     plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
582   }
583   plugin->client_perform_task = GNUNET_SCHEDULER_add_now (client_run, plugin);
584
585   return res;
586 }
587
588 int
589 client_start (struct Plugin *plugin)
590 {
591   int res = GNUNET_OK;
592
593   curl_global_init (CURL_GLOBAL_ALL);
594   plugin->client_mh = curl_multi_init ();
595
596   if (NULL == plugin->client_mh)
597   {
598     GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
599                      _
600                      ("Could not initialize curl multi handle, failed to start %s plugin!\n"),
601                      plugin->name);
602     res = GNUNET_SYSERR;
603   }
604   return res;
605 }
606
607 void
608 client_stop (struct Plugin *plugin)
609 {
610   if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK)
611   {
612     GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
613     plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK;
614   }
615
616   curl_multi_cleanup (plugin->client_mh);
617   curl_global_cleanup ();
618 }
619
620
621
622 /* end of plugin_transport_http_client.c */