GNUnet  0.11.x
plugin_transport_http_client.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2002-2014 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your 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  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
28 #if BUILD_HTTPS
29 #define PLUGIN_NAME "https_client"
30 #define HTTP_STAT_STR_CONNECTIONS "# HTTPS client connections"
31 #define LIBGNUNET_PLUGIN_TRANSPORT_INIT \
32  libgnunet_plugin_transport_https_client_init
33 #define LIBGNUNET_PLUGIN_TRANSPORT_DONE \
34  libgnunet_plugin_transport_https_client_done
35 #else
36 #define PLUGIN_NAME "http_client"
37 #define HTTP_STAT_STR_CONNECTIONS "# HTTP client connections"
38 #define LIBGNUNET_PLUGIN_TRANSPORT_INIT \
39  libgnunet_plugin_transport_http_client_init
40 #define LIBGNUNET_PLUGIN_TRANSPORT_DONE \
41  libgnunet_plugin_transport_http_client_done
42 #endif
43 
44 #define VERBOSE_CURL GNUNET_NO
45 
46 #define PUT_DISCONNECT_TIMEOUT GNUNET_TIME_relative_multiply ( \
47  GNUNET_TIME_UNIT_SECONDS, 1)
48 
49 #define ENABLE_PUT GNUNET_YES
50 #define ENABLE_GET GNUNET_YES
51 
52 #include "platform.h"
53 #include "gnunet_util_lib.h"
54 #include "gnunet_protocols.h"
57 /* Just included for the right curl.h */
58 #include "gnunet_curl_lib.h"
59 
60 
61 #define LOG(kind, ...) GNUNET_log_from (kind, PLUGIN_NAME, __VA_ARGS__)
62 
66 struct HTTP_Client_Plugin;
67 
72 {
77 
82 
87 
92 
97 
102 
107 };
108 
112 struct HTTP_Message
113 {
117  struct HTTP_Message *next;
118 
122  struct HTTP_Message *prev;
123 
127  char *buf;
128 
135 
139  void *transmit_cont_cls;
140 
144  size_t pos;
145 
149  size_t size;
150 };
151 
152 
156 struct GNUNET_ATS_Session;
157 
158 
163 struct RequestHandle
164 {
169 
173  CURL *easyhandle;
174 
179 };
180 
181 
185 struct GNUNET_ATS_Session
186 {
190  char *url;
191 
196 
201 
205  struct RequestHandle put;
206 
210  struct RequestHandle get;
211 
215  struct HTTP_Message *msg_head;
216 
220  struct HTTP_Message *msg_tail;
221 
226 
231 
236 
240  struct GNUNET_SCHEDULER_Task *recv_wakeup_task;
241 
246  struct GNUNET_TIME_Absolute next_receive;
247 
252 
256  unsigned long long bytes_in_queue;
257 
262  size_t overhead;
263 
267  unsigned int msgs_in_queue;
268 
273 };
274 
275 
280 {
285 
290 
295 
299  void *sic_cls;
300 
304  char *name;
305 
309  char *protocol;
310 
315 
320 
325 
330 
335 
343  curl_proxytype proxytype;
344 
353 
357  uint32_t options;
358 
363  unsigned int max_requests;
364 
369  unsigned int cur_requests;
370 
374  uint32_t last_tag;
375 
379  uint16_t use_ipv6;
380 
384  uint16_t use_ipv4;
385 
390 };
391 
392 
400 static int
402 
403 
412 static void
414  struct GNUNET_ATS_Session *session,
416 {
417  struct GNUNET_TRANSPORT_SessionInfo info;
418 
419  if (NULL == plugin->sic)
420  return;
421  memset (&info, 0, sizeof(info));
422  info.state = state;
423  info.is_inbound = GNUNET_NO;
424  info.num_msg_pending = session->msgs_in_queue;
425  info.num_bytes_pending = session->bytes_in_queue;
426  info.receive_delay = session->next_receive;
427  info.session_timeout = session->timeout;
428  info.address = session->address;
429  plugin->sic (plugin->sic_cls,
430  session,
431  &info);
432 }
433 
434 
440 static void
442 {
443  struct HTTP_Client_Plugin *plugin = s->plugin;
444  struct HTTP_Message *pos;
445  struct HTTP_Message *next;
446  CURLMcode mret;
447 
448  if (NULL != s->timeout_task)
449  {
451  s->timeout_task = NULL;
453  }
454  if (NULL != s->put_disconnect_task)
455  {
457  s->put_disconnect_task = NULL;
458  }
459  if (NULL != s->recv_wakeup_task)
460  {
462  s->recv_wakeup_task = NULL;
463  }
466  &s->address->peer,
467  s));
468  if (NULL != s->put.easyhandle)
469  {
471  "Session %p/request %p: disconnecting PUT request to peer `%s'\n",
472  s,
473  s->put.easyhandle,
474  GNUNET_i2s (&s->address->peer));
475 
476  /* remove curl handle from multi handle */
477  mret = curl_multi_remove_handle (plugin->curl_multi_handle,
478  s->put.easyhandle);
479  GNUNET_break (CURLM_OK == mret);
480  curl_easy_cleanup (s->put.easyhandle);
481  GNUNET_assert (plugin->cur_requests > 0);
482  plugin->cur_requests--;
483  s->put.easyhandle = NULL;
484  }
485  if (NULL != s->get.easyhandle)
486  {
488  "Session %p/request %p: disconnecting GET request to peer `%s'\n",
489  s, s->get.easyhandle,
490  GNUNET_i2s (&s->address->peer));
491  /* remove curl handle from multi handle */
492  mret = curl_multi_remove_handle (plugin->curl_multi_handle,
493  s->get.easyhandle);
494  GNUNET_break (CURLM_OK == mret);
495  curl_easy_cleanup (s->get.easyhandle);
496  GNUNET_assert (plugin->cur_requests > 0);
497  plugin->cur_requests--;
498  s->get.easyhandle = NULL;
499  }
500 
501  GNUNET_STATISTICS_set (plugin->env->stats,
503  plugin->cur_requests,
504  GNUNET_NO);
505  next = s->msg_head;
506  while (NULL != (pos = next))
507  {
508  next = pos->next;
510  s->msg_tail,
511  pos);
512  GNUNET_assert (0 < s->msgs_in_queue);
513  s->msgs_in_queue--;
514  GNUNET_assert (pos->size <= s->bytes_in_queue);
515  s->bytes_in_queue -= pos->size;
516  if (NULL != pos->transmit_cont)
517  pos->transmit_cont (pos->transmit_cont_cls,
518  &s->address->peer,
520  pos->size,
521  pos->pos + s->overhead);
522  s->overhead = 0;
523  GNUNET_free (pos);
524  }
525  GNUNET_assert (0 == s->msgs_in_queue);
526  GNUNET_assert (0 == s->bytes_in_queue);
527  notify_session_monitor (plugin,
528  s,
530  if (NULL != s->msg_tk)
531  {
533  s->msg_tk = NULL;
534  }
536  GNUNET_free (s->url);
537  GNUNET_free (s);
538 }
539 
540 
546 static void
548 {
549  GNUNET_assert (NULL != s->timeout_task);
552 }
553 
554 
561 static void
562 client_run (void *cls);
563 
564 
572 static int
574  int now)
575 {
576  fd_set rs;
577  fd_set ws;
578  fd_set es;
579  int max;
580  struct GNUNET_NETWORK_FDSet *grs;
581  struct GNUNET_NETWORK_FDSet *gws;
582  long to;
583  CURLMcode mret;
584  struct GNUNET_TIME_Relative timeout;
585 
586  /* Cancel previous scheduled task */
587  if (plugin->client_perform_task != NULL)
588  {
590  plugin->client_perform_task = NULL;
591  }
592  max = -1;
593  FD_ZERO (&rs);
594  FD_ZERO (&ws);
595  FD_ZERO (&es);
596  mret = curl_multi_fdset (plugin->curl_multi_handle, &rs, &ws, &es, &max);
597  if (mret != CURLM_OK)
598  {
600  _ ("%s failed at %s:%d: `%s'\n"),
601  "curl_multi_fdset",
602  __FILE__,
603  __LINE__,
604  curl_multi_strerror (mret));
605  return GNUNET_SYSERR;
606  }
607  mret = curl_multi_timeout (plugin->curl_multi_handle, &to);
608  if (-1 == to)
610  else
612  if (now == GNUNET_YES)
614 
615  if (CURLM_OK != mret)
616  {
618  _ ("%s failed at %s:%d: `%s'\n"),
619  "curl_multi_timeout", __FILE__, __LINE__,
620  curl_multi_strerror (mret));
621  return GNUNET_SYSERR;
622  }
623 
626  GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
627  GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
628 
629  /* Schedule task to run when select is ready to read or write */
630  plugin->client_perform_task =
632  timeout, grs, gws,
633  &client_run, plugin);
636  return GNUNET_OK;
637 }
638 
639 
640 #if VERBOSE_CURL
641 
651 static int
652 client_log (CURL *curl,
653  curl_infotype type,
654  const char *data,
655  size_t size,
656  void *cls)
657 {
658  struct RequestHandle *ch = cls;
659  const char *ttype = "UNSPECIFIED";
660  char text[size + 2];
661 
662  if (! ((CURLINFO_TEXT == type) ||
663  (CURLINFO_HEADER_IN == type) ||
664  (CURLINFO_HEADER_OUT == type)))
665  return 0;
666  switch (type)
667  {
668  case CURLINFO_TEXT:
669  ttype = "TEXT";
670  break;
671 
672  case CURLINFO_HEADER_IN:
673  ttype = "HEADER_IN";
674  break;
675 
676  case CURLINFO_HEADER_OUT:
677  ttype = "HEADER_OUT";
678  /* Overhead*/
679  GNUNET_assert (NULL != ch);
680  GNUNET_assert (NULL != ch->easyhandle);
681  GNUNET_assert (NULL != ch->s);
682  ch->s->overhead += size;
683  break;
684 
685  default:
686  ttype = "UNSPECIFIED";
687  break;
688  }
689  GNUNET_memcpy (text, data, size);
690  if (text[size - 1] == '\n')
691  {
692  text[size] = '\0';
693  }
694  else
695  {
696  text[size] = '\n';
697  text[size + 1] = '\0';
698  }
700  "Request %p %s: %s",
701  ch->easyhandle,
702  ttype,
703  text);
704  return 0;
705 }
706 
707 
708 #endif
709 
716 static int
718 
719 
726 static int
728 
729 
757 static ssize_t
759  struct GNUNET_ATS_Session *s,
760  const char *msgbuf,
761  size_t msgbuf_size,
762  unsigned int priority,
763  struct GNUNET_TIME_Relative to,
765  void *cont_cls)
766 {
767  struct HTTP_Client_Plugin *plugin = cls;
768  struct HTTP_Message *msg;
769  char *stat_txt;
770 
772  "Session %p/request %p: Sending message with %u to peer `%s' \n",
773  s,
774  s->put.easyhandle,
775  msgbuf_size,
776  GNUNET_i2s (&s->address->peer));
777 
778  /* create new message and schedule */
779  msg = GNUNET_malloc (sizeof(struct HTTP_Message) + msgbuf_size);
780  msg->size = msgbuf_size;
781  msg->buf = (char *) &msg[1];
782  msg->transmit_cont = cont;
783  msg->transmit_cont_cls = cont_cls;
784  GNUNET_memcpy (msg->buf,
785  msgbuf,
786  msgbuf_size);
788  s->msg_tail,
789  msg);
790  s->msgs_in_queue++;
791  s->bytes_in_queue += msg->size;
792 
793  GNUNET_asprintf (&stat_txt,
794  "# bytes currently in %s_client buffers",
795  plugin->protocol);
797  stat_txt, msgbuf_size, GNUNET_NO);
798  GNUNET_free (stat_txt);
799  notify_session_monitor (plugin,
800  s,
802  if (H_TMP_DISCONNECTING == s->put.state)
803  {
804  /* PUT request is currently getting disconnected */
807  "Session %p/request %p: currently disconnecting, reconnecting immediately\n",
808  s,
809  s->put.easyhandle);
810  return msgbuf_size;
811  }
812  if (H_PAUSED == s->put.state)
813  {
814  /* PUT request was paused, unpause */
815  GNUNET_assert (s->put_disconnect_task != NULL);
817  s->put_disconnect_task = NULL;
819  "Session %p/request %p: unpausing request\n",
820  s, s->put.easyhandle);
821  s->put.state = H_CONNECTED;
822  if (NULL != s->put.easyhandle)
823  curl_easy_pause (s->put.easyhandle, CURLPAUSE_CONT);
824  }
825  else if (H_TMP_DISCONNECTED == s->put.state)
826  {
827  /* PUT request was disconnected, reconnect */
828  LOG (GNUNET_ERROR_TYPE_DEBUG, "Session %p: Reconnecting PUT request\n", s);
829  GNUNET_break (NULL == s->put.easyhandle);
831  {
832  /* Could not reconnect */
834  return GNUNET_SYSERR;
835  }
836  }
838  return msgbuf_size;
839 }
840 
841 
849 static int
851  struct GNUNET_ATS_Session *s)
852 {
853  struct HTTP_Client_Plugin *plugin = cls;
854 
856  "Session %p: notifying transport about ending session\n",
857  s);
858  plugin->env->session_end (plugin->env->cls,
859  s->address,
860  s);
862 
863  /* Re-schedule since handles have changed */
864  if (NULL != plugin->client_perform_task)
865  {
867  plugin->client_perform_task = NULL;
868  }
869  client_schedule (plugin, GNUNET_YES);
870 
871  return GNUNET_OK;
872 }
873 
874 
883 static unsigned int
885 {
886  return 3;
887 }
888 
889 
898 static int
900  const struct GNUNET_PeerIdentity *peer,
901  void *value)
902 {
903  struct HTTP_Client_Plugin *plugin = cls;
904  struct GNUNET_ATS_Session *session = value;
905 
906  http_client_plugin_session_disconnect (plugin, session);
907  return GNUNET_OK;
908 }
909 
910 
919 static void
921  const struct GNUNET_PeerIdentity *target)
922 {
923  struct HTTP_Client_Plugin *plugin = cls;
924 
926  "Transport tells me to disconnect `%s'\n",
927  GNUNET_i2s (target));
929  target,
931  plugin);
932 }
933 
934 
939 {
944 
949 };
950 
951 
960 static int
962  const struct GNUNET_PeerIdentity *key,
963  void *value)
964 {
965  struct GNUNET_ATS_SessionClientCtx *sc_ctx = cls;
966  struct GNUNET_ATS_Session *s = value;
967 
968  if (0 == GNUNET_HELLO_address_cmp (sc_ctx->address,
969  s->address))
970  {
971  sc_ctx->ret = s;
972  return GNUNET_NO;
973  }
974  return GNUNET_YES;
975 }
976 
977 
985 static struct GNUNET_ATS_Session *
987  const struct GNUNET_HELLO_Address *address)
988 {
989  struct GNUNET_ATS_SessionClientCtx sc_ctx;
990 
991  sc_ctx.address = address;
992  sc_ctx.ret = NULL;
995  &sc_ctx);
996  return sc_ctx.ret;
997 }
998 
999 
1007 static void
1009 {
1010  struct GNUNET_ATS_Session *s = cls;
1011 
1012  s->put_disconnect_task = NULL;
1014  "Session %p/request %p: will be disconnected due to no activity\n",
1015  s, s->put.easyhandle);
1017  if (NULL != s->put.easyhandle)
1018  curl_easy_pause (s->put.easyhandle,
1019  CURLPAUSE_CONT);
1021 }
1022 
1023 
1034 static size_t
1035 client_send_cb (void *stream,
1036  size_t size,
1037  size_t nmemb,
1038  void *cls)
1039 {
1040  struct GNUNET_ATS_Session *s = cls;
1041  struct HTTP_Client_Plugin *plugin = s->plugin;
1042  struct HTTP_Message *msg = s->msg_head;
1043  size_t len;
1044  char *stat_txt;
1045 
1046  if (H_TMP_DISCONNECTING == s->put.state)
1047  {
1049  "Session %p/request %p: disconnect due to inactivity\n",
1050  s, s->put.easyhandle);
1051  return 0;
1052  }
1053 
1054  if (NULL == msg)
1055  {
1056  if (GNUNET_YES == plugin->emulate_xhr)
1057  {
1059  "Session %p/request %p: PUT request finished\n",
1060  s,
1061  s->put.easyhandle);
1063  return 0;
1064  }
1065 
1066  /* We have nothing to send, so pause PUT request */
1068  "Session %p/request %p: nothing to send, suspending\n",
1069  s,
1070  s->put.easyhandle);
1074  s);
1075  s->put.state = H_PAUSED;
1076  return CURL_READFUNC_PAUSE;
1077  }
1078  /* data to send */
1079  GNUNET_assert (msg->pos < msg->size);
1080  /* calculate how much fits in buffer */
1081  len = GNUNET_MIN (msg->size - msg->pos,
1082  size * nmemb);
1083  GNUNET_memcpy (stream,
1084  &msg->buf[msg->pos],
1085  len);
1086  msg->pos += len;
1087  if (msg->pos == msg->size)
1088  {
1090  "Session %p/request %p: sent message with %u bytes sent, removing message from queue\n",
1091  s,
1092  s->put.easyhandle,
1093  msg->size,
1094  msg->pos);
1095  /* Calling transmit continuation */
1097  s->msg_tail,
1098  msg);
1099  GNUNET_assert (0 < s->msgs_in_queue);
1100  s->msgs_in_queue--;
1101  GNUNET_assert (msg->size <= s->bytes_in_queue);
1102  s->bytes_in_queue -= msg->size;
1103  if (NULL != msg->transmit_cont)
1104  msg->transmit_cont (msg->transmit_cont_cls,
1105  &s->address->peer,
1106  GNUNET_OK,
1107  msg->size,
1108  msg->size + s->overhead);
1109  s->overhead = 0;
1110  GNUNET_free (msg);
1111  }
1112  notify_session_monitor (plugin,
1113  s,
1115  GNUNET_asprintf (&stat_txt,
1116  "# bytes currently in %s_client buffers",
1117  plugin->protocol);
1119  stat_txt,
1120  -len,
1121  GNUNET_NO);
1122  GNUNET_free (stat_txt);
1123  GNUNET_asprintf (&stat_txt,
1124  "# bytes transmitted via %s_client",
1125  plugin->protocol);
1127  stat_txt,
1128  len,
1129  GNUNET_NO);
1130  GNUNET_free (stat_txt);
1131  return len;
1132 }
1133 
1134 
1140 static void
1141 client_wake_up (void *cls)
1142 {
1143  struct GNUNET_ATS_Session *s = cls;
1144 
1145  s->recv_wakeup_task = NULL;
1147  "Session %p/request %p: Waking up GET handle\n",
1148  s, s->get.easyhandle);
1149  if (H_PAUSED == s->put.state)
1150  {
1151  /* PUT request was paused, unpause */
1152  GNUNET_assert (s->put_disconnect_task != NULL);
1154  s->put_disconnect_task = NULL;
1155  s->put.state = H_CONNECTED;
1156  if (NULL != s->put.easyhandle)
1157  curl_easy_pause (s->put.easyhandle, CURLPAUSE_CONT);
1158  }
1159  if (NULL != s->get.easyhandle)
1160  curl_easy_pause (s->get.easyhandle, CURLPAUSE_CONT);
1161 }
1162 
1163 
1171 static int
1173  const struct GNUNET_MessageHeader *message)
1174 {
1175  struct GNUNET_ATS_Session *s = cls;
1176  struct HTTP_Client_Plugin *plugin;
1177  struct GNUNET_TIME_Relative delay;
1178  char *stat_txt;
1179 
1180  plugin = s->plugin;
1181  delay = s->plugin->env->receive (plugin->env->cls,
1182  s->address,
1183  s,
1184  message);
1185  GNUNET_asprintf (&stat_txt,
1186  "# bytes received via %s_client",
1187  plugin->protocol);
1189  stat_txt,
1190  ntohs (message->size),
1191  GNUNET_NO);
1192  GNUNET_free (stat_txt);
1193 
1195  if (GNUNET_TIME_absolute_get ().abs_value_us < s->next_receive.abs_value_us)
1196  {
1198  "Client: peer `%s' address `%s' next read delayed for %s\n",
1199  GNUNET_i2s (&s->address->peer),
1201  s->address->address,
1202  s->address->address_length),
1204  GNUNET_YES));
1205  }
1207  return GNUNET_OK;
1208 }
1209 
1210 
1221 static size_t
1222 client_receive_put (void *stream,
1223  size_t size,
1224  size_t nmemb,
1225  void *cls)
1226 {
1227  return size * nmemb;
1228 }
1229 
1230 
1241 static size_t
1242 client_receive (void *stream,
1243  size_t size,
1244  size_t nmemb,
1245  void *cls)
1246 {
1247  struct GNUNET_ATS_Session *s = cls;
1248  struct GNUNET_TIME_Absolute now;
1249  size_t len = size * nmemb;
1250 
1252  "Session %p / request %p: Received %u bytes from peer `%s'\n",
1253  s,
1254  s->get.easyhandle,
1255  len,
1256  GNUNET_i2s (&s->address->peer));
1257  now = GNUNET_TIME_absolute_get ();
1258  if (now.abs_value_us < s->next_receive.abs_value_us)
1259  {
1261  struct GNUNET_TIME_Relative delta
1263 
1265  "Session %p / request %p: No inbound bandwidth available! Next read was delayed for %s\n",
1266  s,
1267  s->get.easyhandle,
1269  GNUNET_YES));
1270  if (s->recv_wakeup_task != NULL)
1271  {
1273  s->recv_wakeup_task = NULL;
1274  }
1275  s->recv_wakeup_task
1277  &client_wake_up,
1278  s);
1279  return CURL_WRITEFUNC_PAUSE;
1280  }
1281  if (NULL == s->msg_tk)
1283  s);
1285  stream,
1286  len,
1287  GNUNET_NO,
1288  GNUNET_NO);
1289  return len;
1290 }
1291 
1292 
1298 static void
1299 client_run (void *cls)
1300 {
1301  struct HTTP_Client_Plugin *plugin = cls;
1302  int running;
1303  long http_statuscode;
1304  CURLMcode mret;
1305  CURLMsg *msg;
1306  int put_request; /* GNUNET_YES if easy handle is put, GNUNET_NO for get */
1307  int msgs_left;
1308 
1309  plugin->client_perform_task = NULL;
1310  /* While data are available or timeouts occured */
1311  do
1312  {
1313  running = 0;
1314  /* Perform operations for all handles */
1315  mret = curl_multi_perform (plugin->curl_multi_handle, &running);
1316 
1317  /* Get additional information for all handles */
1318  while (NULL != (msg = curl_multi_info_read (plugin->curl_multi_handle,
1319  &msgs_left)))
1320  {
1321  CURL *easy_h = msg->easy_handle;
1322  struct GNUNET_ATS_Session *s = NULL;
1323  char *d = NULL; /* curl requires 'd' to be a 'char *' */
1324 
1325  GNUNET_assert (NULL != easy_h);
1326 
1327  /* Obtain session from easy handle */
1328  GNUNET_assert (CURLE_OK == curl_easy_getinfo (easy_h, CURLINFO_PRIVATE,
1329  &d));
1330  s = (struct GNUNET_ATS_Session *) d;
1331  GNUNET_assert (NULL != s);
1332 
1333  if (msg->msg != CURLMSG_DONE)
1334  continue; /* This should not happen */
1335 
1336  /* Get HTTP response code */
1337  GNUNET_break (CURLE_OK == curl_easy_getinfo (easy_h,
1338  CURLINFO_RESPONSE_CODE,
1339  &http_statuscode));
1340 
1341  if (easy_h == s->put.easyhandle)
1342  put_request = GNUNET_YES;
1343  else
1344  put_request = GNUNET_NO;
1345 
1346  /* Log status of terminated request */
1347  if ((0 != msg->data.result) || (http_statuscode != 200))
1349  "Session %p/request %p: %s request to `%s' ended with status %i reason %i: `%s'\n",
1350  s, msg->easy_handle,
1351  (GNUNET_YES == put_request) ? "PUT" : "GET",
1352  GNUNET_i2s (&s->address->peer),
1353  http_statuscode,
1354  msg->data.result,
1355  curl_easy_strerror (msg->data.result));
1356  else
1358  "Session %p/request %p: %s request to `%s' ended normal\n",
1359  s, msg->easy_handle,
1360  (GNUNET_YES == put_request) ? "PUT" : "GET",
1361  GNUNET_i2s (&s->address->peer));
1362 
1363  /* Remove easy handle from multi handle */
1364  curl_multi_remove_handle (plugin->curl_multi_handle, easy_h);
1365 
1366  /* Clean up easy handle */
1367  curl_easy_cleanup (easy_h);
1368 
1369  /* Remove information */
1370  GNUNET_assert (plugin->cur_requests > 0);
1371  plugin->cur_requests--;
1373  "%s request to %s done, number of requests decreased to %u\n",
1374  (GNUNET_YES == put_request) ? "PUT" : "GET",
1375  s->url,
1376  plugin->cur_requests);
1377 
1378  if (GNUNET_YES == put_request)
1379  {
1380  /* Clean up a PUT request */
1381  s->put.easyhandle = NULL;
1382  s->put.s = NULL;
1383 
1384  switch (s->put.state)
1385  {
1386  case H_NOT_CONNECTED:
1387  case H_DISCONNECTED:
1388  case H_TMP_DISCONNECTED:
1389  /* This must not happen */
1390  GNUNET_break (0);
1391  break;
1392 
1394  /* Transport called send while disconnect in progess, reconnect */
1395  if (GNUNET_SYSERR == client_connect_put (s))
1396  {
1397  /* Reconnect failed, disconnect session */
1399  }
1400  break;
1401 
1402  case H_TMP_DISCONNECTING:
1403  /* PUT gets temporarily disconnected */
1405  break;
1406 
1407  case H_PAUSED:
1408  case H_CONNECTED:
1409  /* PUT gets permanently disconnected */
1410  s->put.state = H_DISCONNECTED;
1412  break;
1413 
1414  default:
1415  GNUNET_break (0);
1416  break;
1417  }
1418  }
1419  else if (GNUNET_NO == put_request)
1420  {
1421  /* Clean up a GET request */
1422  s->get.easyhandle = NULL;
1423  s->get.s = NULL;
1424 
1425  /* If we are emulating an XHR client we need to make another GET
1426  * request.
1427  */
1428  if (GNUNET_YES == plugin->emulate_xhr)
1429  {
1430  if (GNUNET_SYSERR == client_connect_get (s))
1432  }
1433  else
1434  {
1435  /* GET request was terminated, so disconnect session */
1437  }
1438  }
1439  else
1440  GNUNET_break (0); /* Must not happen */
1441 
1442  GNUNET_STATISTICS_set (plugin->env->stats,
1444  plugin->cur_requests,
1445  GNUNET_NO);
1446  }
1447  }
1448  while (mret == CURLM_CALL_MULTI_PERFORM);
1449  client_schedule (plugin, GNUNET_NO);
1450 }
1451 
1452 
1453 #ifdef TCP_STEALTH
1454 
1462 static curl_socket_t
1463 open_tcp_stealth_socket_cb (void *clientp,
1464  curlsocktype purpose,
1465  struct curl_sockaddr *address)
1466 {
1467  struct GNUNET_ATS_Session *s = clientp;
1468  int ret;
1469 
1470  switch (purpose)
1471  {
1472  case CURLSOCKTYPE_IPCXN:
1473  ret = socket (address->family,
1474  address->socktype,
1475  address->protocol);
1476  if (-1 == ret)
1477  return CURL_SOCKET_BAD;
1478  if (((SOCK_STREAM != address->socktype) ||
1479  ((0 != address->protocol) &&
1480  (IPPROTO_TCP != address->protocol))))
1481  return (curl_socket_t) ret;
1482  if ((0 != setsockopt (ret,
1483  IPPROTO_TCP,
1484  TCP_STEALTH,
1485  &s->address->peer,
1486  sizeof(struct GNUNET_PeerIdentity))))
1487  {
1489  _ ("TCP_STEALTH not supported on this platform.\n"));
1490  (void) close (ret);
1491  return CURL_SOCKET_BAD;
1492  }
1493  return (curl_socket_t) ret;
1494 
1495  case CURLSOCKTYPE_ACCEPT:
1496  GNUNET_break (0);
1497  return CURL_SOCKET_BAD;
1498  break;
1499 
1500  case CURLSOCKTYPE_LAST:
1501  GNUNET_break (0);
1502  return CURL_SOCKET_BAD;
1503 
1504  default:
1505  GNUNET_break (0);
1506  return CURL_SOCKET_BAD;
1507  }
1508 }
1509 
1510 
1511 #endif
1512 
1513 
1520 static int
1522 {
1523  CURLMcode mret;
1524  struct HttpAddress *ha;
1525  uint32_t options;
1526 
1527  ha = (struct HttpAddress *) s->address->address;
1528  options = ntohl (ha->options);
1529  /* create get request */
1530  s->get.easyhandle = curl_easy_init ();
1531  s->get.s = s;
1532  if (0 != (options & HTTP_OPTIONS_TCP_STEALTH))
1533  {
1534 #ifdef TCP_STEALTH
1535  curl_easy_setopt (s->get.easyhandle,
1536  CURLOPT_OPENSOCKETFUNCTION,
1537  &open_tcp_stealth_socket_cb);
1538  curl_easy_setopt (s->get.easyhandle,
1539  CURLOPT_OPENSOCKETDATA,
1540  s);
1541 #else
1543  "Cannot connect, TCP STEALTH needed and not supported by kernel.\n");
1544  curl_easy_cleanup (s->get.easyhandle);
1545  s->get.easyhandle = NULL;
1546  s->get.s = NULL;
1547  return GNUNET_SYSERR;
1548 #endif
1549  }
1550 
1551 #if VERBOSE_CURL
1552  curl_easy_setopt (s->get.easyhandle,
1553  CURLOPT_VERBOSE,
1554  1L);
1555  curl_easy_setopt (s->get.easyhandle,
1556  CURLOPT_DEBUGFUNCTION,
1557  &client_log);
1558  curl_easy_setopt (s->get.easyhandle,
1559  CURLOPT_DEBUGDATA,
1560  &s->get);
1561 #endif
1562 #if BUILD_HTTPS
1563  curl_easy_setopt (s->get.easyhandle, CURLOPT_SSLVERSION,
1564  CURL_SSLVERSION_TLSv1);
1565  {
1567  (options & HTTP_OPTIONS_VERIFY_CERTIFICATE))
1568  {
1569  curl_easy_setopt (s->get.easyhandle,
1570  CURLOPT_SSL_VERIFYPEER, 1L);
1571  curl_easy_setopt (s->get.easyhandle,
1572  CURLOPT_SSL_VERIFYHOST,
1573  2L);
1574  }
1575  else
1576  {
1577  curl_easy_setopt (s->get.easyhandle,
1578  CURLOPT_SSL_VERIFYPEER,
1579  0L);
1580  curl_easy_setopt (s->get.easyhandle,
1581  CURLOPT_SSL_VERIFYHOST,
1582  0L);
1583  }
1584  }
1585  curl_easy_setopt (s->get.easyhandle,
1586  CURLOPT_PROTOCOLS,
1587  CURLPROTO_HTTPS);
1588  curl_easy_setopt (s->get.easyhandle,
1589  CURLOPT_REDIR_PROTOCOLS,
1590  CURLPROTO_HTTPS);
1591 #else
1592  curl_easy_setopt (s->get.easyhandle,
1593  CURLOPT_PROTOCOLS,
1594  CURLPROTO_HTTP);
1595  curl_easy_setopt (s->get.easyhandle,
1596  CURLOPT_REDIR_PROTOCOLS,
1597  CURLPROTO_HTTP);
1598 #endif
1599 
1600  if (NULL != s->plugin->proxy_hostname)
1601  {
1602  curl_easy_setopt (s->get.easyhandle,
1603  CURLOPT_PROXY,
1604  s->plugin->proxy_hostname);
1605  curl_easy_setopt (s->get.easyhandle,
1606  CURLOPT_PROXYTYPE,
1607  s->plugin->proxytype);
1608  if (NULL != s->plugin->proxy_username)
1609  curl_easy_setopt (s->get.easyhandle,
1610  CURLOPT_PROXYUSERNAME,
1611  s->plugin->proxy_username);
1612  if (NULL != s->plugin->proxy_password)
1613  curl_easy_setopt (s->get.easyhandle,
1614  CURLOPT_PROXYPASSWORD,
1615  s->plugin->proxy_password);
1616  if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel)
1617  curl_easy_setopt (s->get.easyhandle,
1618  CURLOPT_HTTPPROXYTUNNEL,
1619  s->plugin->proxy_use_httpproxytunnel);
1620  }
1621 
1622  if (GNUNET_YES == s->plugin->emulate_xhr)
1623  {
1624  char *url;
1625 
1626  GNUNET_asprintf (&url,
1627  "%s,1",
1628  s->url);
1629  curl_easy_setopt (s->get.easyhandle,
1630  CURLOPT_URL,
1631  url);
1632  GNUNET_free (url);
1633  }
1634  else
1635  {
1636  curl_easy_setopt (s->get.easyhandle,
1637  CURLOPT_URL,
1638  s->url);
1639  }
1640  curl_easy_setopt (s->get.easyhandle,
1641  CURLOPT_READFUNCTION,
1642  &client_send_cb);
1643  curl_easy_setopt (s->get.easyhandle,
1644  CURLOPT_READDATA,
1645  s);
1646  curl_easy_setopt (s->get.easyhandle,
1647  CURLOPT_WRITEFUNCTION,
1648  &client_receive);
1649  curl_easy_setopt (s->get.easyhandle,
1650  CURLOPT_WRITEDATA,
1651  s);
1652  /* No timeout by default, timeout done with session timeout */
1653  curl_easy_setopt (s->get.easyhandle,
1654  CURLOPT_TIMEOUT,
1655  0L);
1656  curl_easy_setopt (s->get.easyhandle,
1657  CURLOPT_PRIVATE, s);
1658  curl_easy_setopt (s->get.easyhandle,
1659  CURLOPT_CONNECTTIMEOUT_MS,
1660  (long) (HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us
1661  / 1000LL));
1662  curl_easy_setopt (s->get.easyhandle, CURLOPT_BUFFERSIZE,
1664 #if CURL_TCP_NODELAY
1665  curl_easy_setopt (ps->recv_endpoint,
1666  CURLOPT_TCP_NODELAY,
1667  1L);
1668 #endif
1669  curl_easy_setopt (s->get.easyhandle,
1670  CURLOPT_FOLLOWLOCATION,
1671  0L);
1672 
1673  mret = curl_multi_add_handle (s->plugin->curl_multi_handle,
1674  s->get.easyhandle);
1675  if (CURLM_OK != mret)
1676  {
1678  "Session %p : Failed to add GET handle to multihandle: `%s'\n",
1679  s,
1680  curl_multi_strerror (mret));
1681  curl_easy_cleanup (s->get.easyhandle);
1682  s->get.easyhandle = NULL;
1683  s->get.s = NULL;
1684  GNUNET_break (0);
1685  return GNUNET_SYSERR;
1686  }
1687  s->plugin->cur_requests++;
1689  "GET request `%s' established, number of requests increased to %u\n",
1690  s->url,
1691  s->plugin->cur_requests);
1692  return GNUNET_OK;
1693 }
1694 
1695 
1702 static int
1704 {
1705  CURLMcode mret;
1706  struct HttpAddress *ha;
1707  uint32_t options;
1708 
1709  ha = (struct HttpAddress *) s->address->address;
1710  options = ntohl (ha->options);
1711  /* create put request */
1713  "Session %p: Init PUT handle\n",
1714  s);
1715  s->put.easyhandle = curl_easy_init ();
1716  s->put.s = s;
1717 #if VERBOSE_CURL
1718  curl_easy_setopt (s->put.easyhandle,
1719  CURLOPT_VERBOSE,
1720  1L);
1721  curl_easy_setopt (s->put.easyhandle,
1722  CURLOPT_DEBUGFUNCTION,
1723  &client_log);
1724  curl_easy_setopt (s->put.easyhandle,
1725  CURLOPT_DEBUGDATA,
1726  &s->put);
1727 #endif
1728  if (0 != (options & HTTP_OPTIONS_TCP_STEALTH))
1729  {
1730 #ifdef TCP_STEALTH
1731  curl_easy_setopt (s->put.easyhandle,
1732  CURLOPT_OPENSOCKETFUNCTION,
1733  &open_tcp_stealth_socket_cb);
1734  curl_easy_setopt (s->put.easyhandle,
1735  CURLOPT_OPENSOCKETDATA,
1736  s);
1737 #else
1739  "Cannot connect, TCP STEALTH needed and not supported by kernel.\n");
1740  curl_easy_cleanup (s->put.easyhandle);
1741  s->put.easyhandle = NULL;
1742  s->put.s = NULL;
1743  s->put.state = H_DISCONNECTED;
1744  return GNUNET_SYSERR;
1745 #endif
1746  }
1747 #if BUILD_HTTPS
1748  curl_easy_setopt (s->put.easyhandle,
1749  CURLOPT_SSLVERSION,
1750  CURL_SSLVERSION_TLSv1);
1751  {
1752  struct HttpAddress *ha;
1753  ha = (struct HttpAddress *) s->address->address;
1754 
1756  (ntohl (ha->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE))
1757  {
1758  curl_easy_setopt (s->put.easyhandle,
1759  CURLOPT_SSL_VERIFYPEER,
1760  1L);
1761  curl_easy_setopt (s->put.easyhandle,
1762  CURLOPT_SSL_VERIFYHOST,
1763  2L);
1764  }
1765  else
1766  {
1767  curl_easy_setopt (s->put.easyhandle,
1768  CURLOPT_SSL_VERIFYPEER,
1769  0L);
1770  curl_easy_setopt (s->put.easyhandle,
1771  CURLOPT_SSL_VERIFYHOST,
1772  0L);
1773  }
1774  }
1775  curl_easy_setopt (s->put.easyhandle,
1776  CURLOPT_PROTOCOLS,
1777  CURLPROTO_HTTPS);
1778  curl_easy_setopt (s->put.easyhandle,
1779  CURLOPT_REDIR_PROTOCOLS,
1780  CURLPROTO_HTTPS);
1781 #else
1782  curl_easy_setopt (s->put.easyhandle,
1783  CURLOPT_PROTOCOLS,
1784  CURLPROTO_HTTP);
1785  curl_easy_setopt (s->put.easyhandle,
1786  CURLOPT_REDIR_PROTOCOLS,
1787  CURLPROTO_HTTP);
1788 #endif
1789  if (NULL != s->plugin->proxy_hostname)
1790  {
1791  curl_easy_setopt (s->put.easyhandle,
1792  CURLOPT_PROXY,
1793  s->plugin->proxy_hostname);
1794  curl_easy_setopt (s->put.easyhandle,
1795  CURLOPT_PROXYTYPE,
1796  s->plugin->proxytype);
1797  if (NULL != s->plugin->proxy_username)
1798  curl_easy_setopt (s->put.easyhandle,
1799  CURLOPT_PROXYUSERNAME,
1800  s->plugin->proxy_username);
1801  if (NULL != s->plugin->proxy_password)
1802  curl_easy_setopt (s->put.easyhandle,
1803  CURLOPT_PROXYPASSWORD,
1804  s->plugin->proxy_password);
1805  if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel)
1806  curl_easy_setopt (s->put.easyhandle,
1807  CURLOPT_HTTPPROXYTUNNEL,
1808  s->plugin->proxy_use_httpproxytunnel);
1809  }
1810 
1811  curl_easy_setopt (s->put.easyhandle,
1812  CURLOPT_URL,
1813  s->url);
1814  curl_easy_setopt (s->put.easyhandle,
1815  CURLOPT_UPLOAD,
1816  1L);
1817  curl_easy_setopt (s->put.easyhandle,
1818  CURLOPT_READFUNCTION,
1819  &client_send_cb);
1820  curl_easy_setopt (s->put.easyhandle,
1821  CURLOPT_READDATA,
1822  s);
1823  curl_easy_setopt (s->put.easyhandle,
1824  CURLOPT_WRITEFUNCTION,
1826  curl_easy_setopt (s->put.easyhandle,
1827  CURLOPT_WRITEDATA,
1828  s);
1829  /* No timeout by default, timeout done with session timeout */
1830  curl_easy_setopt (s->put.easyhandle,
1831  CURLOPT_TIMEOUT,
1832  0L);
1833  curl_easy_setopt (s->put.easyhandle,
1834  CURLOPT_PRIVATE,
1835  s);
1836  curl_easy_setopt (s->put.easyhandle,
1837  CURLOPT_CONNECTTIMEOUT_MS,
1838  (long) (HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us
1839  / 1000LL));
1840  curl_easy_setopt (s->put.easyhandle, CURLOPT_BUFFERSIZE,
1842 #if CURL_TCP_NODELAY
1843  curl_easy_setopt (s->put.easyhandle, CURLOPT_TCP_NODELAY, 1);
1844 #endif
1845  mret = curl_multi_add_handle (s->plugin->curl_multi_handle,
1846  s->put.easyhandle);
1847  if (CURLM_OK != mret)
1848  {
1850  "Session %p : Failed to add PUT handle to multihandle: `%s'\n",
1851  s, curl_multi_strerror (mret));
1852  curl_easy_cleanup (s->put.easyhandle);
1853  s->put.easyhandle = NULL;
1854  s->put.s = NULL;
1855  s->put.state = H_DISCONNECTED;
1856  return GNUNET_SYSERR;
1857  }
1858  s->put.state = H_CONNECTED;
1859  s->plugin->cur_requests++;
1860 
1862  "PUT request `%s' established, number of requests increased to %u\n",
1863  s->url, s->plugin->cur_requests);
1864 
1865  return GNUNET_OK;
1866 }
1867 
1868 
1875 static int
1877 {
1878  struct HTTP_Client_Plugin *plugin = s->plugin;
1879  int res = GNUNET_OK;
1880 
1881  /* create url */
1882  if (NULL ==
1884  s->address->address,
1885  s->address->address_length))
1886  {
1888  "Invalid address peer `%s'\n",
1889  GNUNET_i2s (&s->address->peer));
1890  return GNUNET_SYSERR;
1891  }
1892 
1893  GNUNET_asprintf (&s->url,
1894  "%s/%s;%u",
1896  s->address->address,
1897  s->address->address_length),
1898  GNUNET_i2s_full (plugin->env->my_identity),
1899  plugin->last_tag);
1900 
1901  plugin->last_tag++;
1903  "Initiating outbound session peer `%s' using address `%s'\n",
1904  GNUNET_i2s (&s->address->peer), s->url);
1905 
1906  if (GNUNET_SYSERR == client_connect_get (s))
1907  return GNUNET_SYSERR;
1908  /* If we are emulating an XHR client then delay sending a PUT request until
1909  * there is something to send.
1910  */
1911  if (GNUNET_YES == plugin->emulate_xhr)
1912  {
1914  }
1915  else if (GNUNET_SYSERR == client_connect_put (s))
1916  return GNUNET_SYSERR;
1917 
1919  "Session %p: connected with GET %p and PUT %p\n",
1920  s, s->get.easyhandle,
1921  s->put.easyhandle);
1922  /* Perform connect */
1923  GNUNET_STATISTICS_set (plugin->env->stats,
1925  plugin->cur_requests,
1926  GNUNET_NO);
1927  /* Re-schedule since handles have changed */
1928  if (NULL != plugin->client_perform_task)
1929  {
1931  plugin->client_perform_task = NULL;
1932  }
1933 
1934  /* Schedule task to run immediately */
1936  plugin);
1937  return res;
1938 }
1939 
1940 
1948 static enum GNUNET_NetworkType
1950  struct GNUNET_ATS_Session *session)
1951 {
1952  return session->scope;
1953 }
1954 
1955 
1963 static enum GNUNET_NetworkType
1965  const struct
1967 {
1968  struct HTTP_Client_Plugin *plugin = cls;
1969 
1970  return http_common_get_network_for_address (plugin->env,
1971  address);
1972 }
1973 
1974 
1980 static void
1982 {
1983  struct GNUNET_ATS_Session *s = cls;
1984  struct GNUNET_TIME_Relative left;
1985 
1986  s->timeout_task = NULL;
1988  if (0 != left.rel_value_us)
1989  {
1990  /* not actually our turn yet, but let's at least update
1991  the monitor, it may think we're about to die ... */
1993  s,
1997  s);
1998  return;
1999  }
2000  LOG (TIMEOUT_LOG,
2001  "Session %p was idle for %s, disconnecting\n",
2002  s,
2004  GNUNET_YES));
2007  s));
2008 }
2009 
2010 
2019 static struct GNUNET_ATS_Session *
2021  const struct GNUNET_HELLO_Address *address)
2022 {
2023  struct HTTP_Client_Plugin *plugin = cls;
2024  struct GNUNET_ATS_Session *s;
2025  struct sockaddr *sa;
2026  enum GNUNET_NetworkType net_type;
2027  size_t salen = 0;
2028  int res;
2029 
2030  GNUNET_assert (NULL != address->address);
2031 
2032  /* find existing session */
2033  s = client_lookup_session (plugin, address);
2034  if (NULL != s)
2035  return s;
2036 
2037  /* create a new session */
2038  if (plugin->max_requests <= plugin->cur_requests)
2039  {
2041  "Maximum number of requests (%u) reached: "
2042  "cannot connect to peer `%s'\n",
2043  plugin->max_requests,
2044  GNUNET_i2s (&address->peer));
2045  return NULL;
2046  }
2047 
2048  /* Determine network location */
2049  net_type = GNUNET_NT_UNSPECIFIED;
2051  address->address_length,
2052  &res);
2053  if (GNUNET_SYSERR == res)
2054  return NULL;
2055  if (GNUNET_YES == res)
2056  {
2057  GNUNET_assert (NULL != sa);
2058  if (AF_INET == sa->sa_family)
2059  {
2060  salen = sizeof(struct sockaddr_in);
2061  }
2062  else if (AF_INET6 == sa->sa_family)
2063  {
2064  salen = sizeof(struct sockaddr_in6);
2065  }
2066  net_type = plugin->env->get_address_type (plugin->env->cls, sa, salen);
2067  GNUNET_free (sa);
2068  }
2069  else if (GNUNET_NO == res)
2070  {
2071  /* Cannot convert to sockaddr -> is external hostname */
2072  net_type = GNUNET_NT_WAN;
2073  }
2074  if (GNUNET_NT_UNSPECIFIED == net_type)
2075  {
2076  GNUNET_break (0);
2077  return NULL;
2078  }
2079 
2080  s = GNUNET_new (struct GNUNET_ATS_Session);
2081  s->plugin = plugin;
2082  s->address = GNUNET_HELLO_address_copy (address);
2083  s->scope = net_type;
2084 
2085  s->put.state = H_NOT_CONNECTED;
2089  s);
2091  "Created new session %p for `%s' address `%s''\n",
2092  s,
2094  s->address->address,
2095  s->address->address_length),
2096  GNUNET_i2s (&s->address->peer));
2097 
2098  /* add new session */
2100  &s->address->peer,
2101  s,
2103  /* initiate new connection */
2104  if (GNUNET_SYSERR == client_connect (s))
2105  {
2107  "Cannot connect to peer `%s' address `%s''\n",
2109  s->address->address,
2110  s->address->address_length),
2111  GNUNET_i2s (&s->address->peer));
2113  return NULL;
2114  }
2115  notify_session_monitor (plugin,
2116  s,
2118  notify_session_monitor (plugin,
2119  s,
2120  GNUNET_TRANSPORT_SS_UP); /* or handshake? */
2121  return s;
2122 }
2123 
2124 
2131 static int
2133 {
2134  curl_global_init (CURL_GLOBAL_ALL);
2135  plugin->curl_multi_handle = curl_multi_init ();
2136 
2137  if (NULL == plugin->curl_multi_handle)
2138  {
2140  _ (
2141  "Could not initialize curl multi handle, failed to start %s plugin!\n"),
2142  plugin->name);
2143  return GNUNET_SYSERR;
2144  }
2145  return GNUNET_OK;
2146 }
2147 
2148 
2161 static int
2163  const void *addr,
2164  size_t addrlen)
2165 {
2166  /* A HTTP/S client does not have any valid address so:*/
2167  return GNUNET_NO;
2168 }
2169 
2170 
2177 void *
2179 {
2180  struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
2181  struct HTTP_Client_Plugin *plugin = api->cls;
2182 
2183  if (NULL == api->cls)
2184  {
2185  /* Stub shutdown */
2186  GNUNET_free (api);
2187  return NULL;
2188  }
2190  _ ("Shutting down plugin `%s'\n"),
2191  plugin->name);
2194  plugin);
2195  if (NULL != plugin->client_perform_task)
2196  {
2198  plugin->client_perform_task = NULL;
2199  }
2200  if (NULL != plugin->curl_multi_handle)
2201  {
2202  curl_multi_cleanup (plugin->curl_multi_handle);
2203  plugin->curl_multi_handle = NULL;
2204  }
2205  curl_global_cleanup ();
2207  _ ("Shutdown for plugin `%s' complete\n"),
2208  plugin->name);
2213  GNUNET_free (plugin);
2214  GNUNET_free (api);
2215  return NULL;
2216 }
2217 
2218 
2225 static int
2227 {
2228  unsigned long long max_requests;
2229  char *proxy_type;
2230 
2231  /* Optional parameters */
2232  if (GNUNET_OK !=
2234  plugin->name,
2235  "MAX_CONNECTIONS",
2236  &max_requests))
2237  max_requests = 128;
2238  plugin->max_requests = max_requests;
2239 
2241  _ ("Maximum number of requests is %u\n"),
2242  plugin->max_requests);
2243 
2244  /* Read proxy configuration */
2245  if (GNUNET_OK ==
2247  plugin->name,
2248  "PROXY",
2249  &plugin->proxy_hostname))
2250  {
2252  "Found proxy host: `%s'\n",
2253  plugin->proxy_hostname);
2254  /* proxy username */
2255  if (GNUNET_OK ==
2257  plugin->name,
2258  "PROXY_USERNAME",
2259  &plugin->proxy_username))
2260  {
2262  "Found proxy username name: `%s'\n",
2263  plugin->proxy_username);
2264  }
2265 
2266  /* proxy password */
2267  if (GNUNET_OK ==
2269  plugin->name,
2270  "PROXY_PASSWORD",
2271  &plugin->proxy_password))
2272  {
2274  "Found proxy password name: `%s'\n",
2275  plugin->proxy_password);
2276  }
2277 
2278  /* proxy type */
2279  if (GNUNET_OK ==
2281  plugin->name,
2282  "PROXY_TYPE",
2283  &proxy_type))
2284  {
2285  GNUNET_STRINGS_utf8_toupper (proxy_type, proxy_type);
2286 
2287  if (0 == strcmp (proxy_type, "HTTP"))
2288  plugin->proxytype = CURLPROXY_HTTP;
2289  else if (0 == strcmp (proxy_type, "SOCKS4"))
2290  plugin->proxytype = CURLPROXY_SOCKS4;
2291  else if (0 == strcmp (proxy_type, "SOCKS5"))
2292  plugin->proxytype = CURLPROXY_SOCKS5;
2293  else if (0 == strcmp (proxy_type, "SOCKS4A"))
2294  plugin->proxytype = CURLPROXY_SOCKS4A;
2295  else if (0 == strcmp (proxy_type, "SOCKS5_HOSTNAME "))
2296  plugin->proxytype = CURLPROXY_SOCKS5_HOSTNAME;
2297  else
2298  {
2300  _ (
2301  "Invalid proxy type: `%s', disabling proxy! Check configuration!\n"),
2302  proxy_type);
2303 
2304  GNUNET_free (proxy_type);
2305  GNUNET_free (plugin->proxy_hostname);
2306  plugin->proxy_hostname = NULL;
2308  plugin->proxy_username = NULL;
2310  plugin->proxy_password = NULL;
2311 
2312  return GNUNET_SYSERR;
2313  }
2314 
2316  "Found proxy type: `%s'\n",
2317  proxy_type);
2318  }
2319 
2320  /* proxy http tunneling */
2323  plugin->name,
2324  "PROXY_HTTP_TUNNELING");
2327 
2328  GNUNET_free_non_null (proxy_type);
2329  }
2330 
2331  /* Should we emulate an XHR client for testing? */
2332  plugin->emulate_xhr
2334  plugin->name,
2335  "EMULATE_XHR");
2336  return GNUNET_OK;
2337 }
2338 
2339 
2348 static const char *
2350  const void *addr,
2351  size_t addrlen)
2352 {
2354  addr,
2355  addrlen);
2356 }
2357 
2358 
2368 static void
2370  const struct
2372  struct GNUNET_ATS_Session *session)
2373 {
2375 }
2376 
2377 
2388 static void
2390  const struct GNUNET_PeerIdentity *peer,
2391  struct GNUNET_ATS_Session *s,
2392  struct GNUNET_TIME_Relative delay)
2393 {
2396  "New inbound delay %s\n",
2398  GNUNET_NO));
2399  if (s->recv_wakeup_task != NULL)
2400  {
2402  s->recv_wakeup_task
2404  &client_wake_up,
2405  s);
2406  }
2407 }
2408 
2409 
2419 static int
2421  const struct GNUNET_PeerIdentity *peer,
2422  void *value)
2423 {
2424  struct HTTP_Client_Plugin *plugin = cls;
2425  struct GNUNET_ATS_Session *session = value;
2426 
2427  notify_session_monitor (plugin,
2428  session,
2430  notify_session_monitor (plugin,
2431  session,
2432  GNUNET_TRANSPORT_SS_UP); /* FIXME: or handshake? */
2433  return GNUNET_OK;
2434 }
2435 
2436 
2449 static void
2452  void *sic_cls)
2453 {
2454  struct HTTP_Client_Plugin *plugin = cls;
2455 
2456  plugin->sic = sic;
2457  plugin->sic_cls = sic_cls;
2458  if (NULL != sic)
2459  {
2462  plugin);
2463  /* signal end of first iteration */
2464  sic (sic_cls, NULL, NULL);
2465  }
2466 }
2467 
2468 
2472 void *
2474 {
2477  struct HTTP_Client_Plugin *plugin;
2478 
2479  if (NULL == env->receive)
2480  {
2481  /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
2482  initialze the plugin or the API */
2484  api->cls = NULL;
2488  return api;
2489  }
2490 
2491  plugin = GNUNET_new (struct HTTP_Client_Plugin);
2492  plugin->env = env;
2494  GNUNET_YES);
2496  api->cls = plugin;
2497  api->send = &http_client_plugin_send;
2511 #if BUILD_HTTPS
2512  plugin->name = "transport-https_client";
2513  plugin->protocol = "https";
2514 #else
2515  plugin->name = "transport-http_client";
2516  plugin->protocol = "http";
2517 #endif
2518  plugin->last_tag = 1;
2519 
2520  if (GNUNET_SYSERR == client_configure_plugin (plugin))
2521  {
2523  return NULL;
2524  }
2525 
2526  /* Start client */
2527  if (GNUNET_SYSERR == client_start (plugin))
2528  {
2530  return NULL;
2531  }
2532  return api;
2533 }
2534 
2535 
2536 /* end of plugin_transport_http_client.c */
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static enum GNUNET_NetworkType http_client_plugin_get_network_for_address(void *cls, const struct GNUNET_HELLO_Address *address)
Function obtain the network type for an address.
size_t address_length
Number of bytes in address.
static int http_client_plugin_address_suggested(void *cls, const void *addr, size_t addrlen)
Another peer has suggested an address for this peer and transport plugin.
Session is being torn down and about to disappear.
static struct GNUNET_CADET_Channel * ch
Channel handle.
Definition: gnunet-cadet.c:117
uint32_t num_bytes_pending
Number of bytes pending transmission for this session.
HTTP_PUT_REQUEST_STATE
State of a HTTP PUT request.
static int client_receive_mst_cb(void *cls, const struct GNUNET_MessageHeader *message)
Callback for message stream tokenizer.
#define HTTP_CLIENT_SESSION_TIMEOUT
static unsigned int http_client_query_keepalive_factor(void *cls)
Function that is called to get the keepalive factor.
struct GNUNET_MessageStreamTokenizer * msg_tk
Message stream tokenizer for incoming data.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
GNUNET_TRANSPORT_CreateSession get_session
Function that will be called tell the plugin to create a session object.
static int http_client_plugin_session_disconnect(void *cls, struct GNUNET_ATS_Session *s)
Disconnect a session.
uint32_t options
Address options see enum HttpAddressOptions
GNUNET_TRANSPORT_AddressToString address_to_string
Function that will be called to convert a binary address to a string (numeric conversion only)...
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
int GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
struct GNUNET_SCHEDULER_Task * recv_wakeup_task
Task to wake up client receive handle when receiving is allowed again.
uint64_t rel_value_us
The actual value.
static int client_configure_plugin(struct HTTP_Client_Plugin *plugin)
Configure plugin.
const void * address
Binary representation of the address (plugin-specific).
char * buf
buffer containing data to send
unsigned int msgs_in_queue
Number of messages waiting for transmission to this peer.
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct GNUNET_SCHEDULER_Task * timeout_task
Session timeout task.
struct HTTP_Message * msg_tail
previous pointer for double linked list
curl_proxytype proxytype
Type of proxy server:
uint32_t last_tag
Last used unique HTTP connection tag.
library to make it easy to download JSON replies over HTTP
struct Plugin * plugin
Pointer to the global plugin struct.
const char * http_common_plugin_address_to_url(void *cls, const void *addr, size_t addrlen)
FIXME.
int http_common_plugin_string_to_address(void *cls, const char *addr, uint16_t addrlen, void **buf, size_t *added)
Function called to convert a string address to a binary address.
struct HTTP_Client_Plugin * plugin
Pointer to the global plugin struct.
GNUNET_TRANSPORT_TransmitFunction send
Function that the transport service will use to transmit data to another peer.
GNUNET_TRANSPORT_DisconnectPeerFunction disconnect_peer
Function that can be used to force the plugin to disconnect from the given peer and cancel all previo...
#define PUT_DISCONNECT_TIMEOUT
GNUNET_TRANSPORT_AddressToType get_address_type
Function that will be called to figure if an address is an loopback, LAN, WAN etc.
int is_inbound
GNUNET_YES if this is an inbound connection, GNUNET_NO if this is an outbound connection, GNUNET_SYSERR if connections of this plugin are so fundamentally bidirectional that they have no &#39;initiator&#39;
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
char * proxy_username
Username for the proxy server.
enum GNUNET_TRANSPORT_SessionState state
New state of the session.
size_t pos
amount of data already sent
static int client_connect_get(struct GNUNET_ATS_Session *s)
Connect GET request.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
char * protocol
Plugin protocol http, https.
static int send_session_info_iter(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Return information about the given session to the monitor callback.
#define GNUNET_TIME_UNIT_SECONDS
One second.
GNUNET_TRANSPORT_DisconnectSessionFunction disconnect_session
Function that can be used to force the plugin to disconnect from the given peer and cancel all previo...
struct RequestHandle put
Handle for the HTTP PUT request.
Message to send using http.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
struct GNUNET_SERVER_MessageStreamTokenizer * msg_tk
Message stream tokenizer for incoming data.
GNUNET_TRANSPORT_SessionMonitorSetup setup_monitor
Function to monitor the sessions managed by the plugin.
struct HTTP_Message * next
next pointer for double linked list
static size_t client_receive_put(void *stream, size_t size, size_t nmemb, void *cls)
Callback method used with libcurl when data for a PUT request are received.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static curl_proxytype proxy_type
Proxy type we are using (can be NULL).
const struct GNUNET_PeerIdentity * my_identity
Identity of this peer.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static void client_session_timeout(void *cls)
Session was idle, so disconnect it.
struct GNUNET_TIME_Absolute timeout
When does this session time out.
static void http_client_plugin_update_session_timeout(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_ATS_Session *session)
Function that will be called whenever the transport service wants to notify the plugin that a session...
int GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
Wide area network (i.e.
Definition: gnunet_nt_lib.h:55
static struct GNUNET_ATS_Session * http_client_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address)
Creates a new outbound session the transport service will use to send data to the peer...
#define GNUNET_NO
Definition: gnunet_common.h:78
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static void client_run(void *cls)
Task performing curl operations.
struct GNUNET_HELLO_Address * address
Address.
static void client_wake_up(void *cls)
Wake up a curl handle which was suspended.
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
struct RequestHandle get
Handle for the HTTP GET request.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
struct HTTP_Message * msg_head
next pointer for double linked list
struct GNUNET_SCHEDULER_Task * put_disconnect_task
Session timeout task.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
const struct GNUNET_HELLO_Address * address
Address used by the session.
unsigned long long bytes_in_queue
Number of bytes waiting for transmission to this peer.
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
uint64_t abs_value_us
The actual value.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:35
uint32_t num_msg_pending
Number of messages pending transmission for this session.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void * transmit_cont_cls
Closure for transmit_cont.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
void GNUNET_NETWORK_fdset_copy_native(struct GNUNET_NETWORK_FDSet *to, const fd_set *from, int nfds)
Copy a native fd set into the GNUnet representation.
Definition: network.c:1120
struct GNUNET_TIME_Absolute receive_delay
Until when does this plugin refuse to receive to manage staying within the inbound quota...
The request handle.
GNUNET_TRANSPORT_TransmitContinuation transmit_cont
Continuation function to call once the transmission buffer has again space available.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
int proxy_use_httpproxytunnel
Use proxy tunneling: Tunnel all operations through a given HTTP instead of have the proxy evaluate th...
GNUNET_TRANSPORT_SessionEnd session_end
Function that must be called by the plugin when a non-NULL session handle stops being valid (is destr...
Paused, nothing to send.
GNUNET_TRANSPORT_PluginReceiveCallback receive
Function that should be called by the transport plugin whenever a message is received.
struct GNUNET_TIME_Absolute next_receive
Absolute time when to receive data again Used for receive throttling.
GNUNET_TRANSPORT_UpdateSessionTimeout update_session_timeout
Function that will be called whenever the transport service wants to notify the plugin that a session...
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1266
const struct GNUNET_HELLO_Address * address
Address we are looking for.
Information about a plugin&#39;s session.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
int GNUNET_HELLO_address_cmp(const struct GNUNET_HELLO_Address *a1, const struct GNUNET_HELLO_Address *a2)
Compare two addresses.
Definition: address.c:130
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1253
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1250
static void notify_session_monitor(struct HTTP_Client_Plugin *plugin, struct GNUNET_ATS_Session *session, enum GNUNET_TRANSPORT_SessionState state)
If a session monitor is attached, notify it about the new session state.
void GNUNET_STRINGS_utf8_toupper(const char *input, char *output)
Convert the utf-8 input string to upper case.
Definition: strings.c:578
void * cls
Closure for the various callbacks.
enum State state
current state of profiling
void * cls
Closure for all of the callbacks.
static void client_put_disconnect(void *cls)
When we have nothing to transmit, we pause the HTTP PUT after a while (so that gnurl stops asking)...
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
Temporarily disconnected.
#define LIBGNUNET_PLUGIN_TRANSPORT_INIT
static char * value
Value of the record to add/remove.
static int client_schedule(struct HTTP_Client_Plugin *plugin, int now)
Function setting up file descriptors and scheduling task to run.
GNUNET_TRANSPORT_StringToAddress string_to_address
Function that will be called to convert a string address to binary (numeric conversion only)...
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
Definition: mst.c:411
static struct GNUNET_ATS_Session * client_lookup_session(struct HTTP_Client_Plugin *plugin, const struct GNUNET_HELLO_Address *address)
Check if a sessions exists for an specific address.
Session handle for connections.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1280
The transport service will pass a pointer to a struct of this type as the first and only argument to ...
static enum GNUNET_NetworkType scope
Which network scope do we belong to?
GNUNET_TRANSPORT_GetNetworkType get_network
Function to obtain the network type for a session.
Handle to a message stream tokenizer.
Definition: mst.c:43
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:80
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:687
collection of IO descriptors
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_select(enum GNUNET_SCHEDULER_Priority prio, struct GNUNET_TIME_Relative delay, const struct GNUNET_NETWORK_FDSet *rs, const struct GNUNET_NETWORK_FDSet *ws, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when any of the specified file descriptor set...
Definition: scheduler.c:1810
void http_common_plugin_address_pretty_printer(void *cls, const char *type, const void *addr, size_t addrlen, int numeric, struct GNUNET_TIME_Relative timeout, GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls)
Convert the transports address to a nice, human-readable format.
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Definition: mst.c:85
uint32_t options
My options to be included in the address.
void(* GNUNET_TRANSPORT_SessionInfoCallback)(void *cls, struct GNUNET_ATS_Session *session, const struct GNUNET_TRANSPORT_SessionInfo *info)
Function called by the plugin with information about the current sessions managed by the plugin (for ...
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:442
int GNUNET_MST_from_buffer(struct GNUNET_MessageStreamTokenizer *mst, const char *buf, size_t size, int purge, int one_shot)
Add incoming data to the receive buffer and call the callback for all complete messages.
Definition: mst.c:114
struct GNUNET_TIME_Absolute session_timeout
At what time will this session timeout (unless activity happens)?
static int session_lookup_client_by_address(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Locate the seession object for a given address.
static ssize_t http_client_plugin_send(void *cls, struct GNUNET_ATS_Session *s, const char *msgbuf, size_t msgbuf_size, unsigned int priority, struct GNUNET_TIME_Relative to, GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
Function that can be used by the transport service to transmit a message using the plugin...
Internal representation of the hash map.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
GNUNET_TRANSPORT_UpdateInboundDelay update_inbound_delay
Function that will be called whenever the transport service wants to notify the plugin that the inbou...
Closure for session_lookup_client_by_address().
static int client_connect_put(struct GNUNET_ATS_Session *s)
Connect a HTTP put request.
int state
The processing state.
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
static int destroy_session_cb(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Callback to destroys all sessions on exit.
static int res
static char * plugin
Solver plugin name as string.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
static enum GNUNET_NetworkType http_client_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session)
Function obtain the network type for a session.
static void client_reschedule_session_timeout(struct GNUNET_ATS_Session *s)
Increment session timeout due to activity for session s.
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
static CURL * curl
Current CURL handle.
GNUNET_TRANSPORT_SessionInfoCallback sic
Function to call about session status changes.
static int client_connect(struct GNUNET_ATS_Session *s)
Connect both PUT and GET request for a session.
size_t size
buffer length
struct GNUNET_CONTAINER_MultiPeerMap * sessions
Open sessions.
static const char * http_client_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
Function to convert an address to a human-readable string.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_HashCode key
The key used in the DHT.
char * url
The URL to connect to.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT
static size_t client_receive(void *stream, size_t size, size_t nmemb, void *cls)
Callback method used with libcurl when data for a GET request are received.
int emulate_xhr
Should we emulate an XHR client for testing?
enum GNUNET_NetworkType scope
ATS network type.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
void(* GNUNET_TRANSPORT_TransmitContinuation)(void *cls, const struct GNUNET_PeerIdentity *target, int result, size_t size_payload, size_t size_on_wire)
Function called by the GNUNET_TRANSPORT_TransmitFunction upon "completion".
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
static struct GNUNET_SCHEDULER_Task * timeout_task
Task to be run on timeout.
Definition: gnunet-arm.c:124
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
struct GNUNET_PeerIdentity peer
For which peer is this an address?
Just created, not yet connected.
static void http_client_plugin_peer_disconnect(void *cls, const struct GNUNET_PeerIdentity *target)
Function that can be used to force the plugin to disconnect from the given peer and cancel all previo...
Enable TCP Stealth-style port knocking.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
void * sic_cls
Closure for sic.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
#define LIBGNUNET_PLUGIN_TRANSPORT_DONE
Encapsulation of all of the state of the plugin.
Allow multiple values with the same key.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don&#39;t receive messages from the peer...
const char * http_common_plugin_address_to_string(const char *plugin, const void *addr, size_t addrlen)
Function called for a quick conversion of the binary address to a numeric address.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
This is just an update about the session, the state did not change.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
enum GNUNET_NetworkType http_common_get_network_for_address(struct GNUNET_TRANSPORT_PluginEnvironment *env, const struct GNUNET_HELLO_Address *address)
Function obtain the network type for an address.
GNUNET_TRANSPORT_QueryKeepaliveFactorFunction query_keepalive_factor
Function that is used to query keepalive factor.
The identity of the host (wraps the signing key of the peer).
static void http_client_plugin_setup_monitor(void *cls, GNUNET_TRANSPORT_SessionInfoCallback sic, void *sic_cls)
Begin monitoring sessions of a plugin.
struct sockaddr * http_common_socket_from_address(const void *addr, size_t addrlen, int *res)
Create a socketaddr from a HTTP address.
struct GNUNET_SCHEDULER_Task * client_perform_task
curl perform task
unsigned int cur_requests
Current number of sockets the plugin can use Each http connections are two requests.
#define HTTP_STAT_STR_CONNECTIONS
struct GNUNET_PeerIdentity target
To whom are we talking to.
CURLM * curl_multi_handle
cURL Multihandle
#define PLUGIN_NAME
An address for communicating with a peer.
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_copy(const struct GNUNET_HELLO_Address *address)
Copy an address struct.
Definition: address.c:109
struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
struct GNUNET_ATS_Session * ret
Session that was found.
#define GNUNET_log(kind,...)
The session was created (first call for each session object).
Entry in list of pending tasks.
Definition: scheduler.c:134
static int client_start(struct HTTP_Client_Plugin *plugin)
Setup http_client plugin.
struct HTTP_Message * prev
previous pointer for double linked list
unsigned int max_requests
Maximum number of sockets the plugin can use Each http connections are two requests.
size_t overhead
Outbound overhead due to HTTP connection Add to next message of this session when calling callback...
Verify X509 server certificate, it should be valid.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
GNUNET_TRANSPORT_AddressPrettyPrinter address_pretty_printer
Function to pretty-print addresses.
Header for all communications.
Time for absolute times used by GNUnet, in microseconds.
#define GNUNET_YES
Definition: gnunet_common.h:77
char * proxy_hostname
Proxy configuration: hostname or ip of the proxy server.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute end)
Compute the time difference between the given start and end times.
Definition: time.c:354
#define LOG(kind,...)
Temporary disconnect in progress due to inactivity.
struct GNUNET_ATS_Session * s
The related session.
Run with the default priority (normal P2P operations).
GNUNET_TRANSPORT_CheckAddress check_address
Function that will be called to check if a binary address for this plugin is well-formed and correspo...
GNUNET_TRANSPORT_SessionState
Possible states of a session in a plugin.
int GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
uint32_t data
The data value.
static void http_client_plugin_update_inbound_delay(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_ATS_Session *s, struct GNUNET_TIME_Relative delay)
Function that will be called whenever the transport service wants to notify the plugin that the inbou...
static char * address
GNS address for this phone.
CURL * easyhandle
The curl easy handle.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_HELLO_address_free(addr)
Free an address.
HTTP addresses including a full URI.
int GNUNET_CONTAINER_multipeermap_get_multiple(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map that match a particular key.
#define TIMEOUT_LOG
#define GNUNET_malloc(size)
Wrapper around malloc.
char * proxy_password
Password for the proxy server.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
Send request while temporary disconnect, reconnect.
GNUNET_TRANSPORT_GetNetworkTypeForAddress get_network_for_address
Function to obtain the network type for an address.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Category of last resort.
Definition: gnunet_nt_lib.h:40
static size_t client_send_cb(void *stream, size_t size, size_t nmemb, void *cls)
Callback method used with libcurl Method is called when libcurl needs to read data during sending...
static void client_delete_session(struct GNUNET_ATS_Session *s)
Delete session s.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966