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