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