GNUnet  0.17.6
Data Structures | Macros | Enumerations | Functions
plugin_transport_http_client.c File Reference

HTTP/S client transport plugin. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_transport_plugin.h"
#include "plugin_transport_http_common.h"
#include "gnunet_curl_lib.h"
Include dependency graph for plugin_transport_http_client.c:

Go to the source code of this file.

Data Structures

struct  HTTP_Message
 Message to send using http. More...
 
struct  RequestHandle
 The request handle. More...
 
struct  GNUNET_ATS_Session
 Session handle for connections. More...
 
struct  HTTP_Client_Plugin
 Encapsulation of all of the state of the plugin. More...
 
struct  GNUNET_ATS_SessionClientCtx
 Closure for session_lookup_client_by_address(). More...
 

Macros

#define PLUGIN_NAME   "http_client"
 
#define HTTP_STAT_STR_CONNECTIONS   "# HTTP client connections"
 
#define LIBGNUNET_PLUGIN_TRANSPORT_INIT    libgnunet_plugin_transport_http_client_init
 
#define LIBGNUNET_PLUGIN_TRANSPORT_DONE    libgnunet_plugin_transport_http_client_done
 
#define VERBOSE_CURL   GNUNET_NO
 
#define PUT_DISCONNECT_TIMEOUT
 
#define ENABLE_PUT   GNUNET_YES
 
#define ENABLE_GET   GNUNET_YES
 
#define LOG(kind, ...)   GNUNET_log_from (kind, PLUGIN_NAME, __VA_ARGS__)
 

Enumerations

enum  HTTP_PUT_REQUEST_STATE {
  H_NOT_CONNECTED , H_CONNECTED , H_PAUSED , H_TMP_DISCONNECTING ,
  H_TMP_RECONNECT_REQUIRED , H_TMP_DISCONNECTED , H_DISCONNECTED
}
 State of a HTTP PUT request. More...
 

Functions

static int http_client_plugin_session_disconnect (void *cls, struct GNUNET_ATS_Session *s)
 Disconnect a session. More...
 
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. More...
 
static void client_delete_session (struct GNUNET_ATS_Session *s)
 Delete session s. More...
 
static void client_reschedule_session_timeout (struct GNUNET_ATS_Session *s)
 Increment session timeout due to activity for session s. More...
 
static void client_run (void *cls)
 Task performing curl operations. More...
 
static int client_schedule (struct HTTP_Client_Plugin *plugin, int now)
 Function setting up file descriptors and scheduling task to run. More...
 
static int client_connect_get (struct GNUNET_ATS_Session *s)
 Connect GET request. More...
 
static int client_connect_put (struct GNUNET_ATS_Session *s)
 Connect a HTTP put request. More...
 
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. More...
 
static unsigned int http_client_query_keepalive_factor (void *cls)
 Function that is called to get the keepalive factor. More...
 
static int destroy_session_cb (void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
 Callback to destroys all sessions on exit. More...
 
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 previous transmissions (and their continuationc). More...
 
static int session_lookup_client_by_address (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Locate the seession object for a given address. More...
 
static struct GNUNET_ATS_Sessionclient_lookup_session (struct HTTP_Client_Plugin *plugin, const struct GNUNET_HELLO_Address *address)
 Check if a sessions exists for an specific address. More...
 
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). More...
 
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. More...
 
static void client_wake_up (void *cls)
 Wake up a curl handle which was suspended. More...
 
static int client_receive_mst_cb (void *cls, const struct GNUNET_MessageHeader *message)
 Callback for message stream tokenizer. More...
 
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. More...
 
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. More...
 
static int client_connect (struct GNUNET_ATS_Session *s)
 Connect both PUT and GET request for a session. More...
 
static enum GNUNET_NetworkType http_client_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session)
 Function obtain the network type for a session. More...
 
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. More...
 
static void client_session_timeout (void *cls)
 Session was idle, so disconnect it. More...
 
static struct GNUNET_ATS_Sessionhttp_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. More...
 
static int client_start (struct HTTP_Client_Plugin *plugin)
 Setup http_client plugin. More...
 
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. More...
 
void * libgnunet_plugin_transport_http_client_done (void *cls)
 Exit point from the plugin. More...
 
static int client_configure_plugin (struct HTTP_Client_Plugin *plugin)
 Configure plugin. More...
 
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. More...
 
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 is still active and in use and therefore the session timeout for this session has to be updated. More...
 
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 inbound quota changed and that the plugin should update it's delay for the next receive value. More...
 
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. More...
 
static void http_client_plugin_setup_monitor (void *cls, GNUNET_TRANSPORT_SessionInfoCallback sic, void *sic_cls)
 Begin monitoring sessions of a plugin. More...
 
void * libgnunet_plugin_transport_http_client_init (void *cls)
 Entry point for the plugin. More...
 

Detailed Description

HTTP/S client transport plugin.

Author
Matthias Wachs
Christian Grothoff

Definition in file plugin_transport_http_client.c.

Macro Definition Documentation

◆ PLUGIN_NAME

#define PLUGIN_NAME   "http_client"

Definition at line 36 of file plugin_transport_http_client.c.

◆ HTTP_STAT_STR_CONNECTIONS

#define HTTP_STAT_STR_CONNECTIONS   "# HTTP client connections"

Definition at line 37 of file plugin_transport_http_client.c.

◆ LIBGNUNET_PLUGIN_TRANSPORT_INIT

#define LIBGNUNET_PLUGIN_TRANSPORT_INIT    libgnunet_plugin_transport_http_client_init

Definition at line 38 of file plugin_transport_http_client.c.

◆ LIBGNUNET_PLUGIN_TRANSPORT_DONE

#define LIBGNUNET_PLUGIN_TRANSPORT_DONE    libgnunet_plugin_transport_http_client_done

Definition at line 40 of file plugin_transport_http_client.c.

◆ VERBOSE_CURL

#define VERBOSE_CURL   GNUNET_NO

Definition at line 44 of file plugin_transport_http_client.c.

◆ PUT_DISCONNECT_TIMEOUT

#define PUT_DISCONNECT_TIMEOUT
Value:
#define GNUNET_TIME_UNIT_SECONDS
One second.
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:483

Definition at line 46 of file plugin_transport_http_client.c.

◆ ENABLE_PUT

#define ENABLE_PUT   GNUNET_YES

Definition at line 49 of file plugin_transport_http_client.c.

◆ ENABLE_GET

#define ENABLE_GET   GNUNET_YES

Definition at line 50 of file plugin_transport_http_client.c.

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, PLUGIN_NAME, __VA_ARGS__)

Definition at line 61 of file plugin_transport_http_client.c.

Enumeration Type Documentation

◆ HTTP_PUT_REQUEST_STATE

State of a HTTP PUT request.

Enumerator
H_NOT_CONNECTED 

Just created, not yet connected.

H_CONNECTED 

Connected.

H_PAUSED 

Paused, nothing to send.

H_TMP_DISCONNECTING 

Temporary disconnect in progress due to inactivity.

H_TMP_RECONNECT_REQUIRED 

Send request while temporary disconnect, reconnect.

H_TMP_DISCONNECTED 

Temporarily disconnected.

H_DISCONNECTED 

Disconnected.

Definition at line 71 of file plugin_transport_http_client.c.

72 {
77 
82 
86  H_PAUSED,
87 
92 
97 
102 
107 };
@ H_TMP_RECONNECT_REQUIRED
Send request while temporary disconnect, reconnect.
@ H_PAUSED
Paused, nothing to send.
@ H_DISCONNECTED
Disconnected.
@ H_CONNECTED
Connected.
@ H_TMP_DISCONNECTING
Temporary disconnect in progress due to inactivity.
@ H_NOT_CONNECTED
Just created, not yet connected.
@ H_TMP_DISCONNECTED
Temporarily disconnected.

Function Documentation

◆ http_client_plugin_session_disconnect()

static int http_client_plugin_session_disconnect ( void *  cls,
struct GNUNET_ATS_Session s 
)
static

Disconnect a session.

Parameters
clsthe struct HTTP_Client_Plugin *
ssession
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 850 of file plugin_transport_http_client.c.

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  }
870 
871  return GNUNET_OK;
872 }
struct Plugin * plugin
The process handle to the testbed service.
@ GNUNET_OK
Definition: gnunet_common.h:99
@ GNUNET_YES
@ GNUNET_ERROR_TYPE_DEBUG
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:957
static int client_schedule(struct HTTP_Client_Plugin *plugin, int now)
Function setting up file descriptors and scheduling task to run.
#define LOG(kind,...)
static void client_delete_session(struct GNUNET_ATS_Session *s)
Delete session s.
struct GNUNET_HELLO_Address * address
Address.
void * cls
Closure to use for callbacks.
Encapsulation of all of the state of the plugin.
struct GNUNET_SCHEDULER_Task * client_perform_task
curl perform task
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.

References GNUNET_ATS_Session::address, client_delete_session(), Plugin::client_perform_task, client_schedule(), GNUNET_DATACACHE_PluginEnvironment::cls, Plugin::env, GNUNET_ERROR_TYPE_DEBUG, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_YES, LOG, and plugin.

Referenced by client_run(), client_session_timeout(), destroy_session_cb(), http_client_plugin_send(), and libgnunet_plugin_transport_http_client_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ notify_session_monitor()

static void notify_session_monitor ( struct HTTP_Client_Plugin plugin,
struct GNUNET_ATS_Session session,
enum GNUNET_TRANSPORT_SessionState  state 
)
static

If a session monitor is attached, notify it about the new session state.

Parameters
pluginour plugin
sessionsession that changed state
statenew state of the session

Definition at line 413 of file plugin_transport_http_client.c.

416 {
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;
430  session,
431  &info);
432 }
enum State state
current state of profiling
#define info
@ GNUNET_NO
Definition: gnunet_common.h:98
unsigned int msgs_in_queue
Number of messages waiting for transmission to this peer.
struct GNUNET_TIME_Absolute timeout
When does this session time out.
unsigned long long bytes_in_queue
Number of bytes waiting for transmission to this peer.
struct GNUNET_TIME_Absolute next_receive
Absolute time when to receive data again Used for receive throttling.
Information about a plugin's session.
void * sic_cls
Closure for sic.
GNUNET_TRANSPORT_SessionInfoCallback sic
Function to call about session status changes.

References GNUNET_ATS_Session::address, GNUNET_ATS_Session::bytes_in_queue, GNUNET_NO, info, GNUNET_ATS_Session::msgs_in_queue, GNUNET_ATS_Session::next_receive, plugin, Plugin::sic, Plugin::sic_cls, state, and GNUNET_ATS_Session::timeout.

Referenced by client_delete_session(), client_send_cb(), client_session_timeout(), http_client_plugin_get_session(), http_client_plugin_send(), and send_session_info_iter().

Here is the caller graph for this function:

◆ client_delete_session()

static void client_delete_session ( struct GNUNET_ATS_Session s)
static

Delete session s.

Parameters
sthe session to delete

Definition at line 441 of file plugin_transport_http_client.c.

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 
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);
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 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
enum GNUNET_GenericReturnValue 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.
#define GNUNET_HELLO_address_free(addr)
Free an address.
@ GNUNET_SYSERR
Definition: gnunet_common.h:97
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
Definition: mst.c:418
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
@ GNUNET_TRANSPORT_SS_DONE
Session is being torn down and about to disappear.
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.
#define HTTP_STAT_STR_CONNECTIONS
struct Plugin * plugin
Pointer to the global plugin struct.
struct HTTP_Message * msg_tail
previous pointer for double linked list
struct HTTP_Message * msg_head
next pointer for double linked list
struct RequestHandle get
Handle for the HTTP GET request.
char * url
The URL to connect to.
struct RequestHandle put
Handle for the HTTP PUT request.
size_t overhead
Outbound overhead due to HTTP connection Add to next message of this session when calling callback.
struct GNUNET_SCHEDULER_Task * recv_wakeup_task
Task to wake up client receive handle when receiving is allowed again.
struct GNUNET_SCHEDULER_Task * put_disconnect_task
Session timeout task.
struct GNUNET_SCHEDULER_Task * timeout_task
Session timeout task.
struct GNUNET_SERVER_MessageStreamTokenizer * msg_tk
Message stream tokenizer for incoming data.
struct GNUNET_PeerIdentity peer
For which peer is this an address?
Message to send using http.
struct HTTP_Message * next
next pointer for double linked list
size_t pos
amount of data already sent
struct GNUNET_ATS_Session * sessions
List of open sessions (or peer map, or...)
CURL * easyhandle
The curl easy handle.

References GNUNET_ATS_Session::address, GNUNET_ATS_Session::bytes_in_queue, RequestHandle::easyhandle, Plugin::env, GNUNET_ATS_Session::get, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multipeermap_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_HELLO_address_free, GNUNET_i2s(), GNUNET_MST_destroy(), GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_set(), GNUNET_SYSERR, GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_SS_DONE, HTTP_STAT_STR_CONNECTIONS, LOG, GNUNET_ATS_Session::msg_head, GNUNET_ATS_Session::msg_tail, GNUNET_ATS_Session::msg_tk, GNUNET_ATS_Session::msgs_in_queue, HTTP_Message::next, notify_session_monitor(), GNUNET_ATS_Session::overhead, GNUNET_HELLO_Address::peer, plugin, GNUNET_ATS_Session::plugin, HTTP_Message::pos, GNUNET_ATS_Session::put, GNUNET_ATS_Session::put_disconnect_task, GNUNET_ATS_Session::recv_wakeup_task, Plugin::sessions, GNUNET_ATS_Session::timeout, GNUNET_ATS_Session::timeout_task, and GNUNET_ATS_Session::url.

Referenced by http_client_plugin_get_session(), and http_client_plugin_session_disconnect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_reschedule_session_timeout()

static void client_reschedule_session_timeout ( struct GNUNET_ATS_Session s)
static

Increment session timeout due to activity for session s.

Parameters
sthe session

Definition at line 547 of file plugin_transport_http_client.c.

548 {
549  GNUNET_assert (NULL != s->timeout_task);
552 }
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don't receive messages from the peer?
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:315

References GNUNET_assert, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_TIME_relative_to_absolute(), GNUNET_ATS_Session::timeout, and GNUNET_ATS_Session::timeout_task.

Referenced by client_receive_mst_cb(), and http_client_plugin_update_session_timeout().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_run()

static void client_run ( void *  cls)
static

Task performing curl operations.

Parameters
clsplugin as closure
tcgnunet scheduler task context
clsplugin as closure

Definition at line 1298 of file plugin_transport_http_client.c.

1299 {
1300  struct HTTP_Client_Plugin *plugin = cls;
1301  int running;
1302  long http_statuscode;
1303  CURLMcode mret;
1304  CURLMsg *msg;
1305  int put_request; /* GNUNET_YES if easy handle is put, GNUNET_NO for get */
1306  int msgs_left;
1307 
1308  plugin->client_perform_task = NULL;
1309  /* While data are available or timeouts occurred */
1310  do
1311  {
1312  running = 0;
1313  /* Perform operations for all handles */
1314  mret = curl_multi_perform (plugin->curl_multi_handle, &running);
1315 
1316  /* Get additional information for all handles */
1317  while (NULL != (msg = curl_multi_info_read (plugin->curl_multi_handle,
1318  &msgs_left)))
1319  {
1320  CURL *easy_h = msg->easy_handle;
1321  struct GNUNET_ATS_Session *s = NULL;
1322  char *d = NULL; /* curl requires 'd' to be a 'char *' */
1323 
1324  GNUNET_assert (NULL != easy_h);
1325 
1326  /* Obtain session from easy handle */
1327  GNUNET_assert (CURLE_OK == curl_easy_getinfo (easy_h, CURLINFO_PRIVATE,
1328  &d));
1329  s = (struct GNUNET_ATS_Session *) d;
1330  GNUNET_assert (NULL != s);
1331 
1332  if (msg->msg != CURLMSG_DONE)
1333  continue; /* This should not happen */
1334 
1335  /* Get HTTP response code */
1336  GNUNET_break (CURLE_OK == curl_easy_getinfo (easy_h,
1337  CURLINFO_RESPONSE_CODE,
1338  &http_statuscode));
1339 
1340  if (easy_h == s->put.easyhandle)
1341  put_request = GNUNET_YES;
1342  else
1343  put_request = GNUNET_NO;
1344 
1345  /* Log status of terminated request */
1346  if ((0 != msg->data.result) || (http_statuscode != 200))
1348  "Session %p/request %p: %s request to `%s' ended with status %li reason %i: `%s'\n",
1349  s, msg->easy_handle,
1350  (GNUNET_YES == put_request) ? "PUT" : "GET",
1351  GNUNET_i2s (&s->address->peer),
1352  http_statuscode,
1353  msg->data.result,
1354  curl_easy_strerror (msg->data.result));
1355  else
1357  "Session %p/request %p: %s request to `%s' ended normal\n",
1358  s, msg->easy_handle,
1359  (GNUNET_YES == put_request) ? "PUT" : "GET",
1360  GNUNET_i2s (&s->address->peer));
1361 
1362  /* Remove easy handle from multi handle */
1363  curl_multi_remove_handle (plugin->curl_multi_handle, easy_h);
1364 
1365  /* Clean up easy handle */
1366  curl_easy_cleanup (easy_h);
1367 
1368  /* Remove information */
1369  GNUNET_assert (plugin->cur_requests > 0);
1370  plugin->cur_requests--;
1372  "%s request to %s done, number of requests decreased to %u\n",
1373  (GNUNET_YES == put_request) ? "PUT" : "GET",
1374  s->url,
1375  plugin->cur_requests);
1376 
1377  if (GNUNET_YES == put_request)
1378  {
1379  /* Clean up a PUT request */
1380  s->put.easyhandle = NULL;
1381  s->put.s = NULL;
1382 
1383  switch (s->put.state)
1384  {
1385  case H_NOT_CONNECTED:
1386  case H_DISCONNECTED:
1387  case H_TMP_DISCONNECTED:
1388  /* This must not happen */
1389  GNUNET_break (0);
1390  break;
1391 
1393  /* Transport called send while disconnect in progress, reconnect */
1394  if (GNUNET_SYSERR == client_connect_put (s))
1395  {
1396  /* Reconnect failed, disconnect session */
1398  }
1399  break;
1400 
1401  case H_TMP_DISCONNECTING:
1402  /* PUT gets temporarily disconnected */
1404  break;
1405 
1406  case H_PAUSED:
1407  case H_CONNECTED:
1408  /* PUT gets permanently disconnected */
1409  s->put.state = H_DISCONNECTED;
1411  break;
1412 
1413  default:
1414  GNUNET_break (0);
1415  break;
1416  }
1417  }
1418  else if (GNUNET_NO == put_request)
1419  {
1420  /* Clean up a GET request */
1421  s->get.easyhandle = NULL;
1422  s->get.s = NULL;
1423 
1424  /* If we are emulating an XHR client we need to make another GET
1425  * request.
1426  */
1427  if (GNUNET_YES == plugin->emulate_xhr)
1428  {
1429  if (GNUNET_SYSERR == client_connect_get (s))
1431  }
1432  else
1433  {
1434  /* GET request was terminated, so disconnect session */
1436  }
1437  }
1438  else
1439  GNUNET_break (0); /* Must not happen */
1440 
1441  GNUNET_STATISTICS_set (plugin->env->stats,
1443  plugin->cur_requests,
1444  GNUNET_NO);
1445  }
1446  }
1447  while (mret == CURLM_CALL_MULTI_PERFORM);
1449 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
@ GNUNET_ERROR_TYPE_INFO
static int client_connect_put(struct GNUNET_ATS_Session *s)
Connect a HTTP put request.
static int http_client_plugin_session_disconnect(void *cls, struct GNUNET_ATS_Session *s)
Disconnect a session.
static int client_connect_get(struct GNUNET_ATS_Session *s)
Connect GET request.
Session handle for connections.
enum HTTP_PUT_REQUEST_STATE state
Current state of this request.
struct GNUNET_ATS_Session * s
The related session.

References GNUNET_ATS_Session::address, client_connect_get(), client_connect_put(), Plugin::client_perform_task, client_schedule(), RequestHandle::easyhandle, Plugin::env, GNUNET_ATS_Session::get, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_NO, GNUNET_STATISTICS_set(), GNUNET_SYSERR, GNUNET_YES, H_CONNECTED, H_DISCONNECTED, H_NOT_CONNECTED, H_PAUSED, H_TMP_DISCONNECTED, H_TMP_DISCONNECTING, H_TMP_RECONNECT_REQUIRED, http_client_plugin_session_disconnect(), HTTP_STAT_STR_CONNECTIONS, LOG, msg, GNUNET_HELLO_Address::peer, plugin, GNUNET_ATS_Session::put, RequestHandle::s, RequestHandle::state, and GNUNET_ATS_Session::url.

Referenced by client_connect(), and client_schedule().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_schedule()

static int client_schedule ( struct HTTP_Client_Plugin plugin,
int  now 
)
static

Function setting up file descriptors and scheduling task to run.

Parameters
pluginthe plugin as closure
nowschedule task in 1ms, regardless of what curl may say
Returns
GNUNET_SYSERR for hard failure, GNUNET_OK for ok

Definition at line 573 of file plugin_transport_http_client.c.

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;
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 */
632  timeout, grs, gws,
633  &client_run, plugin);
636  return GNUNET_OK;
637 }
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
@ GNUNET_SCHEDULER_PRIORITY_DEFAULT
Run with the default priority (normal P2P operations).
@ GNUNET_ERROR_TYPE_ERROR
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1193
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1209
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:1063
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:1826
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
#define max(x, y)
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
static void client_run(void *cls)
Task performing curl operations.
collection of IO descriptors
Time for relative time used by GNUnet, in microseconds.

References _, Plugin::client_perform_task, client_run(), GNUNET_ERROR_TYPE_ERROR, GNUNET_NETWORK_fdset_copy_native(), GNUNET_NETWORK_fdset_create(), GNUNET_NETWORK_fdset_destroy(), GNUNET_OK, GNUNET_SCHEDULER_add_select(), GNUNET_SCHEDULER_cancel(), GNUNET_SCHEDULER_PRIORITY_DEFAULT, GNUNET_SYSERR, GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_MILLISECONDS, GNUNET_TIME_UNIT_SECONDS, GNUNET_YES, LOG, max, plugin, and timeout.

Referenced by client_put_disconnect(), client_run(), http_client_plugin_send(), and http_client_plugin_session_disconnect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_connect_get()

static int client_connect_get ( struct GNUNET_ATS_Session s)
static

Connect GET request.

Connect GET request for a session.

Parameters
sthe session to connect
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise

Definition at line 1520 of file plugin_transport_http_client.c.

1521 {
1522  CURLMcode mret;
1523  struct HttpAddress *ha;
1524  uint32_t options;
1525 
1526  ha = (struct HttpAddress *) s->address->address;
1527  options = ntohl (ha->options);
1528  /* create get request */
1529  s->get.easyhandle = curl_easy_init ();
1530  s->get.s = s;
1531  if (0 != (options & HTTP_OPTIONS_TCP_STEALTH))
1532  {
1533 #ifdef TCP_STEALTH
1534  curl_easy_setopt (s->get.easyhandle,
1535  CURLOPT_OPENSOCKETFUNCTION,
1536  &open_tcp_stealth_socket_cb);
1537  curl_easy_setopt (s->get.easyhandle,
1538  CURLOPT_OPENSOCKETDATA,
1539  s);
1540 #else
1542  "Cannot connect, TCP STEALTH needed and not supported by kernel.\n");
1543  curl_easy_cleanup (s->get.easyhandle);
1544  s->get.easyhandle = NULL;
1545  s->get.s = NULL;
1546  return GNUNET_SYSERR;
1547 #endif
1548  }
1549 
1550 #if VERBOSE_CURL
1551  curl_easy_setopt (s->get.easyhandle,
1552  CURLOPT_VERBOSE,
1553  1L);
1554  curl_easy_setopt (s->get.easyhandle,
1555  CURLOPT_DEBUGFUNCTION,
1556  &client_log);
1557  curl_easy_setopt (s->get.easyhandle,
1558  CURLOPT_DEBUGDATA,
1559  &s->get);
1560 #endif
1561 #if BUILD_HTTPS
1562  curl_easy_setopt (s->get.easyhandle, CURLOPT_SSLVERSION,
1563  CURL_SSLVERSION_TLSv1);
1564  {
1567  {
1568  curl_easy_setopt (s->get.easyhandle,
1569  CURLOPT_SSL_VERIFYPEER, 1L);
1570  curl_easy_setopt (s->get.easyhandle,
1571  CURLOPT_SSL_VERIFYHOST,
1572  2L);
1573  }
1574  else
1575  {
1576  curl_easy_setopt (s->get.easyhandle,
1577  CURLOPT_SSL_VERIFYPEER,
1578  0L);
1579  curl_easy_setopt (s->get.easyhandle,
1580  CURLOPT_SSL_VERIFYHOST,
1581  0L);
1582  }
1583  }
1584  curl_easy_setopt (s->get.easyhandle,
1585  CURLOPT_PROTOCOLS,
1586  CURLPROTO_HTTPS);
1587  curl_easy_setopt (s->get.easyhandle,
1588  CURLOPT_REDIR_PROTOCOLS,
1589  CURLPROTO_HTTPS);
1590 #else
1591  curl_easy_setopt (s->get.easyhandle,
1592  CURLOPT_PROTOCOLS,
1593  CURLPROTO_HTTP);
1594  curl_easy_setopt (s->get.easyhandle,
1595  CURLOPT_REDIR_PROTOCOLS,
1596  CURLPROTO_HTTP);
1597 #endif
1598 
1599  if (NULL != s->plugin->proxy_hostname)
1600  {
1601  curl_easy_setopt (s->get.easyhandle,
1602  CURLOPT_PROXY,
1603  s->plugin->proxy_hostname);
1604  curl_easy_setopt (s->get.easyhandle,
1605  CURLOPT_PROXYTYPE,
1606  s->plugin->proxytype);
1607  if (NULL != s->plugin->proxy_username)
1608  curl_easy_setopt (s->get.easyhandle,
1609  CURLOPT_PROXYUSERNAME,
1610  s->plugin->proxy_username);
1611  if (NULL != s->plugin->proxy_password)
1612  curl_easy_setopt (s->get.easyhandle,
1613  CURLOPT_PROXYPASSWORD,
1614  s->plugin->proxy_password);
1615  if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel)
1616  curl_easy_setopt (s->get.easyhandle,
1617  CURLOPT_HTTPPROXYTUNNEL,
1618  s->plugin->proxy_use_httpproxytunnel);
1619  }
1620 
1621  if (GNUNET_YES == s->plugin->emulate_xhr)
1622  {
1623  char *url;
1624 
1625  GNUNET_asprintf (&url,
1626  "%s,1",
1627  s->url);
1628  curl_easy_setopt (s->get.easyhandle,
1629  CURLOPT_URL,
1630  url);
1631  GNUNET_free (url);
1632  }
1633  else
1634  {
1635  curl_easy_setopt (s->get.easyhandle,
1636  CURLOPT_URL,
1637  s->url);
1638  }
1639  curl_easy_setopt (s->get.easyhandle,
1640  CURLOPT_READFUNCTION,
1641  &client_send_cb);
1642  curl_easy_setopt (s->get.easyhandle,
1643  CURLOPT_READDATA,
1644  s);
1645  curl_easy_setopt (s->get.easyhandle,
1646  CURLOPT_WRITEFUNCTION,
1647  &client_receive);
1648  curl_easy_setopt (s->get.easyhandle,
1649  CURLOPT_WRITEDATA,
1650  s);
1651  /* No timeout by default, timeout done with session timeout */
1652  curl_easy_setopt (s->get.easyhandle,
1653  CURLOPT_TIMEOUT,
1654  0L);
1655  curl_easy_setopt (s->get.easyhandle,
1656  CURLOPT_PRIVATE, s);
1657  curl_easy_setopt (s->get.easyhandle,
1658  CURLOPT_CONNECTTIMEOUT_MS,
1659  (long) (HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us
1660  / 1000LL));
1661  curl_easy_setopt (s->get.easyhandle, CURLOPT_BUFFERSIZE,
1663 #if CURL_TCP_NODELAY
1664  curl_easy_setopt (ps->recv_endpoint,
1665  CURLOPT_TCP_NODELAY,
1666  1L);
1667 #endif
1668  curl_easy_setopt (s->get.easyhandle,
1669  CURLOPT_FOLLOWLOCATION,
1670  0L);
1671 
1672  mret = curl_multi_add_handle (s->plugin->curl_multi_handle,
1673  s->get.easyhandle);
1674  if (CURLM_OK != mret)
1675  {
1677  "Session %p : Failed to add GET handle to multihandle: `%s'\n",
1678  s,
1679  curl_multi_strerror (mret));
1680  curl_easy_cleanup (s->get.easyhandle);
1681  s->get.easyhandle = NULL;
1682  s->get.s = NULL;
1683  GNUNET_break (0);
1684  return GNUNET_SYSERR;
1685  }
1686  s->plugin->cur_requests++;
1688  "GET request `%s' established, number of requests increased to %u\n",
1689  s->url,
1690  s->plugin->cur_requests);
1691  return GNUNET_OK;
1692 }
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
#define GNUNET_log(kind,...)
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
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.
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.
@ HTTP_OPTIONS_VERIFY_CERTIFICATE
Verify X509 server certificate, it should be valid.
@ HTTP_OPTIONS_TCP_STEALTH
Enable TCP Stealth-style port knocking.
#define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT
const void * address
Binary representation of the address (plugin-specific).
HTTP addresses including a full URI.
uint32_t options
Address options see enum HttpAddressOptions

References GNUNET_HELLO_Address::address, GNUNET_ATS_Session::address, client_receive(), client_send_cb(), RequestHandle::easyhandle, GNUNET_ATS_Session::get, GNUNET_asprintf(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, HTTP_CLIENT_NOT_VALIDATED_TIMEOUT, HTTP_OPTIONS_TCP_STEALTH, HTTP_OPTIONS_VERIFY_CERTIFICATE, LOG, options, HttpAddress::options, GNUNET_ATS_Session::plugin, RequestHandle::s, and GNUNET_ATS_Session::url.

Referenced by client_connect(), and client_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_connect_put()

static int client_connect_put ( struct GNUNET_ATS_Session s)
static

Connect a HTTP put request.

Parameters
sthe session to connect
Returns
GNUNET_SYSERR for hard failure, GNUNET_OK for success

Definition at line 1696 of file plugin_transport_http_client.c.

1697 {
1698  CURLMcode mret;
1699  struct HttpAddress *ha;
1700  uint32_t options;
1701 
1702  ha = (struct HttpAddress *) s->address->address;
1703  options = ntohl (ha->options);
1704  /* create put request */
1706  "Session %p: Init PUT handle\n",
1707  s);
1708  s->put.easyhandle = curl_easy_init ();
1709  s->put.s = s;
1710 #if VERBOSE_CURL
1711  curl_easy_setopt (s->put.easyhandle,
1712  CURLOPT_VERBOSE,
1713  1L);
1714  curl_easy_setopt (s->put.easyhandle,
1715  CURLOPT_DEBUGFUNCTION,
1716  &client_log);
1717  curl_easy_setopt (s->put.easyhandle,
1718  CURLOPT_DEBUGDATA,
1719  &s->put);
1720 #endif
1721  if (0 != (options & HTTP_OPTIONS_TCP_STEALTH))
1722  {
1723 #ifdef TCP_STEALTH
1724  curl_easy_setopt (s->put.easyhandle,
1725  CURLOPT_OPENSOCKETFUNCTION,
1726  &open_tcp_stealth_socket_cb);
1727  curl_easy_setopt (s->put.easyhandle,
1728  CURLOPT_OPENSOCKETDATA,
1729  s);
1730 #else
1732  "Cannot connect, TCP STEALTH needed and not supported by kernel.\n");
1733  curl_easy_cleanup (s->put.easyhandle);
1734  s->put.easyhandle = NULL;
1735  s->put.s = NULL;
1736  s->put.state = H_DISCONNECTED;
1737  return GNUNET_SYSERR;
1738 #endif
1739  }
1740 #if BUILD_HTTPS
1741  curl_easy_setopt (s->put.easyhandle,
1742  CURLOPT_SSLVERSION,
1743  CURL_SSLVERSION_TLSv1);
1744  {
1745  struct HttpAddress *ha;
1746  ha = (struct HttpAddress *) s->address->address;
1747 
1749  (ntohl (ha->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE))
1750  {
1751  curl_easy_setopt (s->put.easyhandle,
1752  CURLOPT_SSL_VERIFYPEER,
1753  1L);
1754  curl_easy_setopt (s->put.easyhandle,
1755  CURLOPT_SSL_VERIFYHOST,
1756  2L);
1757  }
1758  else
1759  {
1760  curl_easy_setopt (s->put.easyhandle,
1761  CURLOPT_SSL_VERIFYPEER,
1762  0L);
1763  curl_easy_setopt (s->put.easyhandle,
1764  CURLOPT_SSL_VERIFYHOST,
1765  0L);
1766  }
1767  }
1768  curl_easy_setopt (s->put.easyhandle,
1769  CURLOPT_PROTOCOLS,
1770  CURLPROTO_HTTPS);
1771  curl_easy_setopt (s->put.easyhandle,
1772  CURLOPT_REDIR_PROTOCOLS,
1773  CURLPROTO_HTTPS);
1774 #else
1775  curl_easy_setopt (s->put.easyhandle,
1776  CURLOPT_PROTOCOLS,
1777  CURLPROTO_HTTP);
1778  curl_easy_setopt (s->put.easyhandle,
1779  CURLOPT_REDIR_PROTOCOLS,
1780  CURLPROTO_HTTP);
1781 #endif
1782  if (NULL != s->plugin->proxy_hostname)
1783  {
1784  curl_easy_setopt (s->put.easyhandle,
1785  CURLOPT_PROXY,
1786  s->plugin->proxy_hostname);
1787  curl_easy_setopt (s->put.easyhandle,
1788  CURLOPT_PROXYTYPE,
1789  s->plugin->proxytype);
1790  if (NULL != s->plugin->proxy_username)
1791  curl_easy_setopt (s->put.easyhandle,
1792  CURLOPT_PROXYUSERNAME,
1793  s->plugin->proxy_username);
1794  if (NULL != s->plugin->proxy_password)
1795  curl_easy_setopt (s->put.easyhandle,
1796  CURLOPT_PROXYPASSWORD,
1797  s->plugin->proxy_password);
1798  if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel)
1799  curl_easy_setopt (s->put.easyhandle,
1800  CURLOPT_HTTPPROXYTUNNEL,
1801  s->plugin->proxy_use_httpproxytunnel);
1802  }
1803 
1804  curl_easy_setopt (s->put.easyhandle,
1805  CURLOPT_URL,
1806  s->url);
1807  curl_easy_setopt (s->put.easyhandle,
1808  CURLOPT_UPLOAD,
1809  1L);
1810  curl_easy_setopt (s->put.easyhandle,
1811  CURLOPT_READFUNCTION,
1812  &client_send_cb);
1813  curl_easy_setopt (s->put.easyhandle,
1814  CURLOPT_READDATA,
1815  s);
1816  curl_easy_setopt (s->put.easyhandle,
1817  CURLOPT_WRITEFUNCTION,
1819  curl_easy_setopt (s->put.easyhandle,
1820  CURLOPT_WRITEDATA,
1821  s);
1822  /* No timeout by default, timeout done with session timeout */
1823  curl_easy_setopt (s->put.easyhandle,
1824  CURLOPT_TIMEOUT,
1825  0L);
1826  curl_easy_setopt (s->put.easyhandle,
1827  CURLOPT_PRIVATE,
1828  s);
1829  curl_easy_setopt (s->put.easyhandle,
1830  CURLOPT_CONNECTTIMEOUT_MS,
1831  (long) (HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us
1832  / 1000LL));
1833  curl_easy_setopt (s->put.easyhandle, CURLOPT_BUFFERSIZE,
1835 #if CURL_TCP_NODELAY
1836  curl_easy_setopt (s->put.easyhandle, CURLOPT_TCP_NODELAY, 1);
1837 #endif
1838  mret = curl_multi_add_handle (s->plugin->curl_multi_handle,
1839  s->put.easyhandle);
1840  if (CURLM_OK != mret)
1841  {
1843  "Session %p : Failed to add PUT handle to multihandle: `%s'\n",
1844  s, curl_multi_strerror (mret));
1845  curl_easy_cleanup (s->put.easyhandle);
1846  s->put.easyhandle = NULL;
1847  s->put.s = NULL;
1848  s->put.state = H_DISCONNECTED;
1849  return GNUNET_SYSERR;
1850  }
1851  s->put.state = H_CONNECTED;
1852  s->plugin->cur_requests++;
1853 
1855  "PUT request `%s' established, number of requests increased to %u\n",
1856  s->url, s->plugin->cur_requests);
1857 
1858  return GNUNET_OK;
1859 }
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.

References GNUNET_HELLO_Address::address, GNUNET_ATS_Session::address, client_receive_put(), client_send_cb(), RequestHandle::easyhandle, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, H_CONNECTED, H_DISCONNECTED, HTTP_CLIENT_NOT_VALIDATED_TIMEOUT, HTTP_OPTIONS_TCP_STEALTH, HTTP_OPTIONS_VERIFY_CERTIFICATE, LOG, options, HttpAddress::options, GNUNET_ATS_Session::plugin, GNUNET_ATS_Session::put, RequestHandle::s, RequestHandle::state, and GNUNET_ATS_Session::url.

Referenced by client_connect(), client_run(), and http_client_plugin_send().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ http_client_plugin_send()

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 
)
static

Function that can be used by the transport service to transmit a message using the plugin.

Note that in the case of a peer disconnecting, the continuation MUST be called prior to the disconnect notification itself. This function will be called with this peer's HELLO message to initiate a fresh connection to another peer.

Parameters
clsclosure
swhich session must be used
msgbufthe message to transmit
msgbuf_sizenumber of bytes in msgbuf
priorityhow important is the message (most plugins will ignore message priority and just FIFO)
tohow long to wait at most for the transmission (does not require plugins to discard the message after the timeout, just advisory for the desired delay; most plugins will ignore this as well)
contcontinuation to call once the message has been transmitted (or if the transport is ready for the next transmission call; or if the peer disconnected...); can be NULL
cont_clsclosure for cont
Returns
number of bytes used (on the physical network, with overheads); -1 on hard errors (i.e. address invalid); 0 is a legal value and does NOT mean that the message was not transmitted (DV)

Definition at line 758 of file plugin_transport_http_client.c.

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 %lu to peer `%s' \n",
773  s,
774  s->put.easyhandle,
775  (unsigned long) 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);
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 }
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_malloc(size)
Wrapper around malloc.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
@ GNUNET_TRANSPORT_SS_UPDATE
This is just an update about the session, the state did not change.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
char * protocol
Plugin protocol http, https.

References GNUNET_ATS_Session::address, GNUNET_ATS_Session::bytes_in_queue, client_connect_put(), client_schedule(), RequestHandle::easyhandle, Plugin::env, GNUNET_asprintf(), GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_TRANSPORT_SS_UPDATE, GNUNET_YES, H_CONNECTED, H_PAUSED, H_TMP_DISCONNECTED, H_TMP_DISCONNECTING, H_TMP_RECONNECT_REQUIRED, http_client_plugin_session_disconnect(), LOG, msg, GNUNET_ATS_Session::msg_head, GNUNET_ATS_Session::msg_tail, GNUNET_ATS_Session::msgs_in_queue, notify_session_monitor(), GNUNET_HELLO_Address::peer, plugin, GNUNET_ATS_Session::plugin, Plugin::protocol, GNUNET_ATS_Session::put, GNUNET_ATS_Session::put_disconnect_task, GNUNET_MessageHeader::size, and RequestHandle::state.

Referenced by libgnunet_plugin_transport_http_client_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ http_client_query_keepalive_factor()

static unsigned int http_client_query_keepalive_factor ( void *  cls)
static

Function that is called to get the keepalive factor.

GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to calculate the interval between keepalive packets.

Parameters
clsclosure with the struct Plugin
Returns
keepalive factor

Definition at line 884 of file plugin_transport_http_client.c.

885 {
886  return 3;
887 }

Referenced by libgnunet_plugin_transport_http_client_init().

Here is the caller graph for this function:

◆ destroy_session_cb()

static int destroy_session_cb ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  value 
)
static

Callback to destroys all sessions on exit.

Parameters
clsthe struct HTTP_Client_Plugin *
peeridentity of the peer
valuethe struct GNUNET_ATS_Session *
Returns
GNUNET_OK (continue iterating)

Definition at line 899 of file plugin_transport_http_client.c.

902 {
903  struct HTTP_Client_Plugin *plugin = cls;
904  struct GNUNET_ATS_Session *session = value;
905 
907  return GNUNET_OK;
908 }
static char * value
Value of the record to add/remove.

References GNUNET_OK, http_client_plugin_session_disconnect(), plugin, and value.

Referenced by http_client_plugin_peer_disconnect(), and libgnunet_plugin_transport_http_client_done().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ http_client_plugin_peer_disconnect()

static void http_client_plugin_peer_disconnect ( void *  cls,
const struct GNUNET_PeerIdentity target 
)
static

Function that can be used to force the plugin to disconnect from the given peer and cancel all previous transmissions (and their continuationc).

Parameters
clsclosure
targetpeer from which to disconnect

Definition at line 920 of file plugin_transport_http_client.c.

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 }
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.
static int destroy_session_cb(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Callback to destroys all sessions on exit.

References destroy_session_cb(), GNUNET_CONTAINER_multipeermap_get_multiple(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), LOG, plugin, and Plugin::sessions.

Referenced by libgnunet_plugin_transport_http_client_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ session_lookup_client_by_address()

static int session_lookup_client_by_address ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Locate the seession object for a given address.

Parameters
clsthe struct GNUNET_ATS_SessionClientCtx *
keypeer identity
valuethe struct GNUNET_ATS_Session to check
Returns
GNUNET_NO if found, GNUNET_OK if not

Definition at line 961 of file plugin_transport_http_client.c.

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 }
int GNUNET_HELLO_address_cmp(const struct GNUNET_HELLO_Address *a1, const struct GNUNET_HELLO_Address *a2)
Compare two addresses.
Definition: address.c:130
Closure for session_lookup_client_by_address().
const struct GNUNET_HELLO_Address * address
Address we are looking for.
struct GNUNET_ATS_Session * ret
Session that was found.

References GNUNET_ATS_Session::address, GNUNET_ATS_SessionClientCtx::address, GNUNET_HELLO_address_cmp(), GNUNET_NO, GNUNET_YES, GNUNET_ATS_SessionClientCtx::ret, and value.

Referenced by client_lookup_session().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_lookup_session()

static struct GNUNET_ATS_Session* client_lookup_session ( struct HTTP_Client_Plugin plugin,
const struct GNUNET_HELLO_Address address 
)
static

Check if a sessions exists for an specific address.

Parameters
pluginthe plugin
addressthe address
Returns
the session or NULL

Definition at line 986 of file plugin_transport_http_client.c.

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 }
static char * address
GNS address for this phone.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static int session_lookup_client_by_address(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Locate the seession object for a given address.

References address, GNUNET_ATS_SessionClientCtx::address, GNUNET_CONTAINER_multipeermap_iterate(), plugin, GNUNET_ATS_SessionClientCtx::ret, session_lookup_client_by_address(), and Plugin::sessions.

Referenced by http_client_plugin_get_session().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_put_disconnect()

static void client_put_disconnect ( void *  cls)
static

When we have nothing to transmit, we pause the HTTP PUT after a while (so that gnurl stops asking).

This task is the delayed task that actually disconnects the PUT.

Parameters
clsthe struct GNUNET_ATS_Session * with the put

Definition at line 1008 of file plugin_transport_http_client.c.

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 }

References client_schedule(), RequestHandle::easyhandle, GNUNET_ERROR_TYPE_DEBUG, GNUNET_YES, H_TMP_DISCONNECTING, LOG, GNUNET_ATS_Session::plugin, GNUNET_ATS_Session::put, GNUNET_ATS_Session::put_disconnect_task, and RequestHandle::state.

Referenced by client_send_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_send_cb()

static size_t client_send_cb ( void *  stream,
size_t  size,
size_t  nmemb,
void *  cls 
)
static

Callback method used with libcurl Method is called when libcurl needs to read data during sending.

Parameters
streampointer where to write data
sizesize of an individual element
nmembcount of elements that can be written to the buffer
clsour struct GNUNET_ATS_Session
Returns
bytes written to stream, returning 0 will terminate request!

Definition at line 1035 of file plugin_transport_http_client.c.

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 %lu bytes sent, removing message from queue\n",
1091  s,
1092  s->put.easyhandle,
1093  (unsigned long) msg->size);
1094  /* Calling transmit continuation */
1096  s->msg_tail,
1097  msg);
1098  GNUNET_assert (0 < s->msgs_in_queue);
1099  s->msgs_in_queue--;
1101  s->bytes_in_queue -= msg->size;
1102  if (NULL != msg->transmit_cont)
1103  msg->transmit_cont (msg->transmit_cont_cls,
1104  &s->address->peer,
1105  GNUNET_OK,
1106  msg->size,
1107  msg->size + s->overhead);
1108  s->overhead = 0;
1109  GNUNET_free (msg);
1110  }
1112  s,
1114  GNUNET_asprintf (&stat_txt,
1115  "# bytes currently in %s_client buffers",
1116  plugin->protocol);
1118  stat_txt,
1119  -len,
1120  GNUNET_NO);
1121  GNUNET_free (stat_txt);
1122  GNUNET_asprintf (&stat_txt,
1123  "# bytes transmitted via %s_client",
1124  plugin->protocol);
1126  stat_txt,
1127  len,
1128  GNUNET_NO);
1129  GNUNET_free (stat_txt);
1130  return len;
1131 }
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
#define GNUNET_MIN(a, b)
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:1254
static unsigned int size
Size of the "table".
Definition: peer.c:67
#define PUT_DISCONNECT_TIMEOUT
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).

References GNUNET_ATS_Session::address, GNUNET_ATS_Session::bytes_in_queue, client_put_disconnect(), RequestHandle::easyhandle, Plugin::env, GNUNET_asprintf(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_memcpy, GNUNET_MIN, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_STATISTICS_update(), GNUNET_TRANSPORT_SS_UPDATE, GNUNET_YES, H_PAUSED, H_TMP_DISCONNECTING, len, LOG, msg, GNUNET_ATS_Session::msg_head, GNUNET_ATS_Session::msg_tail, GNUNET_ATS_Session::msgs_in_queue, notify_session_monitor(), GNUNET_ATS_Session::overhead, GNUNET_HELLO_Address::peer, plugin, GNUNET_ATS_Session::plugin, Plugin::protocol, GNUNET_ATS_Session::put, GNUNET_ATS_Session::put_disconnect_task, PUT_DISCONNECT_TIMEOUT, GNUNET_MessageHeader::size, size, and RequestHandle::state.

Referenced by client_connect_get(), and client_connect_put().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_wake_up()

static void client_wake_up ( void *  cls)
static

Wake up a curl handle which was suspended.

Parameters
clsthe session

Definition at line 1140 of file plugin_transport_http_client.c.

1141 {
1142  struct GNUNET_ATS_Session *s = cls;
1143 
1144  s->recv_wakeup_task = NULL;
1146  "Session %p/request %p: Waking up GET handle\n",
1147  s, s->get.easyhandle);
1148  if (H_PAUSED == s->put.state)
1149  {
1150  /* PUT request was paused, unpause */
1151  GNUNET_assert (s->put_disconnect_task != NULL);
1153  s->put_disconnect_task = NULL;
1154  s->put.state = H_CONNECTED;
1155  if (NULL != s->put.easyhandle)
1156  curl_easy_pause (s->put.easyhandle, CURLPAUSE_CONT);
1157  }
1158  if (NULL != s->get.easyhandle)
1159  curl_easy_pause (s->get.easyhandle, CURLPAUSE_CONT);
1160 }

References RequestHandle::easyhandle, GNUNET_ATS_Session::get, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_SCHEDULER_cancel(), H_CONNECTED, H_PAUSED, LOG, GNUNET_ATS_Session::put, GNUNET_ATS_Session::put_disconnect_task, GNUNET_ATS_Session::recv_wakeup_task, and RequestHandle::state.

Referenced by client_receive(), and http_client_plugin_update_inbound_delay().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_receive_mst_cb()

static int client_receive_mst_cb ( void *  cls,
const struct GNUNET_MessageHeader message 
)
static

Callback for message stream tokenizer.

Parameters
clsthe session
messagethe message received
Returns
always GNUNET_OK

Definition at line 1171 of file plugin_transport_http_client.c.

1173 {
1174  struct GNUNET_ATS_Session *s = cls;
1175  struct HTTP_Client_Plugin *plugin;
1176  struct GNUNET_TIME_Relative delay;
1177  char *stat_txt;
1178 
1179  plugin = s->plugin;
1180  delay = s->plugin->env->receive (plugin->env->cls,
1181  s->address,
1182  s,
1183  message);
1184  GNUNET_asprintf (&stat_txt,
1185  "# bytes received via %s_client",
1186  plugin->protocol);
1188  stat_txt,
1189  ntohs (message->size),
1190  GNUNET_NO);
1191  GNUNET_free (stat_txt);
1192 
1194  if (GNUNET_TIME_absolute_get ().abs_value_us < s->next_receive.abs_value_us)
1195  {
1197  "Client: peer `%s' address `%s' next read delayed for %s\n",
1198  GNUNET_i2s (&s->address->peer),
1200  s->address->address,
1201  s->address->address_length),
1203  GNUNET_YES));
1204  }
1206  return GNUNET_OK;
1207 }
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:110
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:570
static void client_reschedule_session_timeout(struct GNUNET_ATS_Session *s)
Increment session timeout due to activity for session s.
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.
size_t address_length
Number of bytes in address.
uint64_t abs_value_us
The actual value.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_HELLO_Address::address, GNUNET_ATS_Session::address, GNUNET_HELLO_Address::address_length, client_reschedule_session_timeout(), GNUNET_DATACACHE_PluginEnvironment::cls, delay, Plugin::env, GNUNET_asprintf(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get(), GNUNET_TIME_relative_to_absolute(), GNUNET_YES, http_common_plugin_address_to_string(), LOG, GNUNET_ATS_Session::next_receive, GNUNET_HELLO_Address::peer, plugin, GNUNET_ATS_Session::plugin, Plugin::protocol, and GNUNET_MessageHeader::size.

Referenced by client_receive().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_receive_put()

static size_t client_receive_put ( void *  stream,
size_t  size,
size_t  nmemb,
void *  cls 
)
static

Callback method used with libcurl when data for a PUT request are received.

We do not expect data here, so we just discard it.

Parameters
streampointer where to write data
sizesize of an individual element
nmembcount of elements that can be written to the buffer
clsdestination pointer, passed to the libcurl handle
Returns
bytes read from stream

Definition at line 1221 of file plugin_transport_http_client.c.

1225 {
1226  return size * nmemb;
1227 }

References size.

Referenced by client_connect_put().

Here is the caller graph for this function:

◆ client_receive()

static size_t client_receive ( void *  stream,
size_t  size,
size_t  nmemb,
void *  cls 
)
static

Callback method used with libcurl when data for a GET request are received.

Forward to MST

Parameters
streampointer where to write data
sizesize of an individual element
nmembcount of elements that can be written to the buffer
clsdestination pointer, passed to the libcurl handle
Returns
bytes read from stream

Definition at line 1241 of file plugin_transport_http_client.c.

1245 {
1246  struct GNUNET_ATS_Session *s = cls;
1247  struct GNUNET_TIME_Absolute now;
1248  size_t len = size * nmemb;
1249 
1251  "Session %p / request %p: Received %lu bytes from peer `%s'\n",
1252  s,
1253  s->get.easyhandle,
1254  (unsigned long) len,
1255  GNUNET_i2s (&s->address->peer));
1256  now = GNUNET_TIME_absolute_get ();
1257  if (now.abs_value_us < s->next_receive.abs_value_us)
1258  {
1262 
1264  "Session %p / request %p: No inbound bandwidth available! Next read was delayed for %s\n",
1265  s,
1266  s->get.easyhandle,
1268  GNUNET_YES));
1269  if (s->recv_wakeup_task != NULL)
1270  {
1272  s->recv_wakeup_task = NULL;
1273  }
1274  s->recv_wakeup_task
1276  &client_wake_up,
1277  s);
1278  return CURL_WRITEFUNC_PAUSE;
1279  }
1280  if (NULL == s->msg_tk)
1282  s);
1284  stream,
1285  len,
1286  GNUNET_NO,
1287  GNUNET_NO);
1288  return len;
1289 }
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Definition: mst.c:85
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_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:420
static int client_receive_mst_cb(void *cls, const struct GNUNET_MessageHeader *message)
Callback for message stream tokenizer.
static void client_wake_up(void *cls)
Wake up a curl handle which was suspended.
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:35
Time for absolute times used by GNUnet, in microseconds.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_ATS_Session::address, client_receive_mst_cb(), client_wake_up(), delta, RequestHandle::easyhandle, GNUNET_ATS_Session::get, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_MST_create(), GNUNET_MST_from_buffer(), GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_difference(), GNUNET_YES, len, LOG, GNUNET_ATS_Session::msg_tk, GNUNET_ATS_Session::next_receive, GNUNET_HELLO_Address::peer, GNUNET_ATS_Session::recv_wakeup_task, and size.

Referenced by client_connect_get().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_connect()

static int client_connect ( struct GNUNET_ATS_Session s)
static

Connect both PUT and GET request for a session.

Parameters
sthe session to connect
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise

Definition at line 1869 of file plugin_transport_http_client.c.

1870 {
1871  struct HTTP_Client_Plugin *plugin = s->plugin;
1872  int res = GNUNET_OK;
1873 
1874  /* create url */
1875  if (NULL ==
1877  s->address->address,
1878  s->address->address_length))
1879  {
1881  "Invalid address peer `%s'\n",
1882  GNUNET_i2s (&s->address->peer));
1883  return GNUNET_SYSERR;
1884  }
1885 
1886  GNUNET_asprintf (&s->url,
1887  "%s/%s;%u",
1889  s->address->address,
1890  s->address->address_length),
1891  GNUNET_i2s_full (plugin->env->my_identity),
1892  plugin->last_tag);
1893 
1894  plugin->last_tag++;
1896  "Initiating outbound session peer `%s' using address `%s'\n",
1897  GNUNET_i2s (&s->address->peer), s->url);
1898 
1899  if (GNUNET_SYSERR == client_connect_get (s))
1900  return GNUNET_SYSERR;
1901  /* If we are emulating an XHR client then delay sending a PUT request until
1902  * there is something to send.
1903  */
1904  if (GNUNET_YES == plugin->emulate_xhr)
1905  {
1907  }
1908  else if (GNUNET_SYSERR == client_connect_put (s))
1909  return GNUNET_SYSERR;
1910 
1912  "Session %p: connected with GET %p and PUT %p\n",
1913  s, s->get.easyhandle,
1914  s->put.easyhandle);
1915  /* Perform connect */
1916  GNUNET_STATISTICS_set (plugin->env->stats,
1918  plugin->cur_requests,
1919  GNUNET_NO);
1920  /* Re-schedule since handles have changed */
1921  if (NULL != plugin->client_perform_task)
1922  {
1924  plugin->client_perform_task = NULL;
1925  }
1926 
1927  /* Schedule task to run immediately */
1929  plugin);
1930  return res;
1931 }
static int res
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
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:1281
const char * http_common_plugin_address_to_url(void *cls, const void *addr, size_t addrlen)
FIXME.
uint32_t last_tag
Last used unique HTTP connection tag.

References GNUNET_HELLO_Address::address, GNUNET_ATS_Session::address, GNUNET_HELLO_Address::address_length, client_connect_get(), client_connect_put(), Plugin::client_perform_task, client_run(), RequestHandle::easyhandle, Plugin::env, GNUNET_ATS_Session::get, GNUNET_asprintf(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_i2s_full(), GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_set(), GNUNET_SYSERR, GNUNET_YES, H_TMP_DISCONNECTED, http_common_plugin_address_to_string(), http_common_plugin_address_to_url(), HTTP_STAT_STR_CONNECTIONS, Plugin::last_tag, LOG, GNUNET_HELLO_Address::peer, plugin, GNUNET_ATS_Session::plugin, Plugin::protocol, GNUNET_ATS_Session::put, res, RequestHandle::state, and GNUNET_ATS_Session::url.

Referenced by http_client_plugin_get_session().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ http_client_plugin_get_network()

static enum GNUNET_NetworkType http_client_plugin_get_network ( void *  cls,
struct GNUNET_ATS_Session session 
)
static

Function obtain the network type for a session.

Parameters
clsclosure (struct Plugin*)
sessionthe session
Returns
the network type

Definition at line 1869 of file plugin_transport_http_client.c.

1944 {
1945  return session->scope;
1946 }
enum GNUNET_NetworkType scope
ATS network type.

Referenced by libgnunet_plugin_transport_http_client_init().

Here is the caller graph for this function:

◆ http_client_plugin_get_network_for_address()

static enum GNUNET_NetworkType http_client_plugin_get_network_for_address ( void *  cls,
const struct GNUNET_HELLO_Address address 
)
static

Function obtain the network type for an address.

Parameters
clsclosure (struct Plugin *)
addressthe address
Returns
the network type

Definition at line 1869 of file plugin_transport_http_client.c.

1960 {
1961  struct HTTP_Client_Plugin *plugin = cls;
1962 
1964  address);
1965 }
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.

Referenced by libgnunet_plugin_transport_http_client_init().

Here is the caller graph for this function:

◆ client_session_timeout()

static void client_session_timeout ( void *  cls)
static

Session was idle, so disconnect it.

Parameters
clsthe struct GNUNET_ATS_Session of the idle session

Definition at line 1974 of file plugin_transport_http_client.c.

1975 {
1976  struct GNUNET_ATS_Session *s = cls;
1977  struct GNUNET_TIME_Relative left;
1978 
1979  s->timeout_task = NULL;
1981  if (0 != left.rel_value_us)
1982  {
1983  /* not actually our turn yet, but let's at least update
1984  the monitor, it may think we're about to die ... */
1986  s,
1990  s);
1991  return;
1992  }
1993  LOG (TIMEOUT_LOG,
1994  "Session %p was idle for %s, disconnecting\n",
1995  s,
1997  GNUNET_YES));
2000  s));
2001 }
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:404
static void client_session_timeout(void *cls)
Session was idle, so disconnect it.
#define HTTP_CLIENT_SESSION_TIMEOUT
#define TIMEOUT_LOG

References GNUNET_assert, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TRANSPORT_SS_UPDATE, GNUNET_YES, http_client_plugin_session_disconnect(), HTTP_CLIENT_SESSION_TIMEOUT, LOG, notify_session_monitor(), GNUNET_ATS_Session::plugin, GNUNET_TIME_Relative::rel_value_us, GNUNET_ATS_Session::timeout, TIMEOUT_LOG, and GNUNET_ATS_Session::timeout_task.

Referenced by http_client_plugin_get_session().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ http_client_plugin_get_session()

static struct GNUNET_ATS_Session* http_client_plugin_get_session ( void *  cls,
const struct GNUNET_HELLO_Address address 
)
static

Creates a new outbound session the transport service will use to send data to the peer.

Parameters
clsthe plugin
addressthe address
Returns
the session or NULL of max connections exceeded

Definition at line 2013 of file plugin_transport_http_client.c.

2015 {
2016  struct HTTP_Client_Plugin *plugin = cls;
2017  struct GNUNET_ATS_Session *s;
2018  struct sockaddr *sa;
2019  enum GNUNET_NetworkType net_type;
2020  size_t salen = 0;
2021  int res;
2022 
2023  GNUNET_assert (NULL != address->address);
2024 
2025  /* find existing session */
2027  if (NULL != s)
2028  return s;
2029 
2030  /* create a new session */
2031  if (plugin->max_requests <= plugin->cur_requests)
2032  {
2034  "Maximum number of requests (%u) reached: "
2035  "cannot connect to peer `%s'\n",
2036  plugin->max_requests,
2037  GNUNET_i2s (&address->peer));
2038  return NULL;
2039  }
2040 
2041  /* Determine network location */
2042  net_type = GNUNET_NT_UNSPECIFIED;
2044  address->address_length,
2045  &res);
2046  if (GNUNET_SYSERR == res)
2047  return NULL;
2048  if (GNUNET_YES == res)
2049  {
2050  GNUNET_assert (NULL != sa);
2051  if (AF_INET == sa->sa_family)
2052  {
2053  salen = sizeof(struct sockaddr_in);
2054  }
2055  else if (AF_INET6 == sa->sa_family)
2056  {
2057  salen = sizeof(struct sockaddr_in6);
2058  }
2059  net_type = plugin->env->get_address_type (plugin->env->cls, sa, salen);
2060  GNUNET_free (sa);
2061  }
2062  else if (GNUNET_NO == res)
2063  {
2064  /* Cannot convert to sockaddr -> is external hostname */
2065  net_type = GNUNET_NT_WAN;
2066  }
2067  if (GNUNET_NT_UNSPECIFIED == net_type)
2068  {
2069  GNUNET_break (0);
2070  return NULL;
2071  }
2072 
2073  s = GNUNET_new (struct GNUNET_ATS_Session);
2074  s->plugin = plugin;
2076  s->scope = net_type;
2077 
2078  s->put.state = H_NOT_CONNECTED;
2082  s);
2084  "Created new session %p for `%s' address `%s''\n",
2085  s,
2087  s->address->address,
2088  s->address->address_length),
2089  GNUNET_i2s (&s->address->peer));
2090 
2091  /* add new session */
2093  &s->address->peer,
2094  s,
2096  /* initiate new connection */
2097  if (GNUNET_SYSERR == client_connect (s))
2098  {
2100  "Cannot connect to peer `%s' address `%s''\n",
2102  s->address->address,
2103  s->address->address_length),
2104  GNUNET_i2s (&s->address->peer));
2106  return NULL;
2107  }
2109  s,
2112  s,
2113  GNUNET_TRANSPORT_SS_UP); /* or handshake? */
2114  return s;
2115 }
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.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_copy(const struct GNUNET_HELLO_Address *address)
Copy an address struct.
Definition: address.c:109
@ GNUNET_ERROR_TYPE_WARNING
#define GNUNET_new(type)
Allocate a struct or union of the given type.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:36
@ GNUNET_NT_WAN
Wide area network (i.e.
Definition: gnunet_nt_lib.h:55
@ GNUNET_NT_UNSPECIFIED
Category of last resort.
Definition: gnunet_nt_lib.h:40
@ GNUNET_TRANSPORT_SS_INIT
The session was created (first call for each session object).
@ GNUNET_TRANSPORT_SS_UP
Session is fully UP.
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.
static int client_connect(struct GNUNET_ATS_Session *s)
Connect both PUT and GET request for a session.
struct sockaddr * http_common_socket_from_address(const void *addr, size_t addrlen, int *res)
Create a socketaddr from a HTTP address.

References address, GNUNET_HELLO_Address::address, GNUNET_ATS_Session::address, GNUNET_HELLO_Address::address_length, client_connect(), client_delete_session(), client_lookup_session(), client_session_timeout(), GNUNET_DATACACHE_PluginEnvironment::cls, Plugin::env, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multipeermap_put(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_HELLO_address_copy(), GNUNET_i2s(), GNUNET_new, GNUNET_NO, GNUNET_NT_UNSPECIFIED, GNUNET_NT_WAN, GNUNET_SCHEDULER_add_delayed(), GNUNET_SYSERR, GNUNET_TIME_relative_to_absolute(), GNUNET_TRANSPORT_SS_INIT, GNUNET_TRANSPORT_SS_UP, GNUNET_YES, H_NOT_CONNECTED, HTTP_CLIENT_SESSION_TIMEOUT, http_common_plugin_address_to_string(), http_common_socket_from_address(), LOG, notify_session_monitor(), GNUNET_HELLO_Address::peer, plugin, GNUNET_ATS_Session::plugin, Plugin::protocol, GNUNET_ATS_Session::put, res, GNUNET_ATS_Session::scope, Plugin::sessions, RequestHandle::state, GNUNET_ATS_Session::timeout, and GNUNET_ATS_Session::timeout_task.

Referenced by libgnunet_plugin_transport_http_client_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_start()

static int client_start ( struct HTTP_Client_Plugin plugin)
static

Setup http_client plugin.

Parameters
pluginthe plugin handle
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 2125 of file plugin_transport_http_client.c.

2126 {
2127  curl_global_init (CURL_GLOBAL_ALL);
2128  plugin->curl_multi_handle = curl_multi_init ();
2129 
2130  if (NULL == plugin->curl_multi_handle)
2131  {
2133  _ (
2134  "Could not initialize curl multi handle, failed to start %s plugin!\n"),
2135  plugin->name);
2136  return GNUNET_SYSERR;
2137  }
2138  return GNUNET_OK;
2139 }
char * name
Plugin name.

References _, GNUNET_ERROR_TYPE_ERROR, GNUNET_OK, GNUNET_SYSERR, LOG, Plugin::name, and plugin.

Referenced by libgnunet_plugin_transport_http_client_init().

Here is the caller graph for this function:

◆ http_client_plugin_address_suggested()

static int http_client_plugin_address_suggested ( void *  cls,
const void *  addr,
size_t  addrlen 
)
static

Another peer has suggested an address for this peer and transport plugin.

Check that this could be a valid address. If so, consider adding it to the list of addresses.

Parameters
clsclosure with the struct Plugin
addrpointer to the address
addrlenlength of addr
Returns
GNUNET_OK if this is a plausible address for this peer and transport; always returns GNUNET_NO (this is the client!)

Definition at line 2155 of file plugin_transport_http_client.c.

2158 {
2159  /* A HTTP/S client does not have any valid address so:*/
2160  return GNUNET_NO;
2161 }

References GNUNET_NO.

Referenced by libgnunet_plugin_transport_http_client_init().

Here is the caller graph for this function:

◆ libgnunet_plugin_transport_http_client_done()

void* libgnunet_plugin_transport_http_client_done ( void *  cls)

Exit point from the plugin.

Parameters
clsapi as closure
Returns
NULL

Definition at line 2171 of file plugin_transport_http_client.c.

2172 {
2173  struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
2174  struct HTTP_Client_Plugin *plugin = api->cls;
2175 
2176  if (NULL == api->cls)
2177  {
2178  /* Stub shutdown */
2179  GNUNET_free (api);
2180  return NULL;
2181  }
2183  _ ("Shutting down plugin `%s'\n"),
2184  plugin->name);
2187  plugin);
2188  if (NULL != plugin->client_perform_task)
2189  {
2191  plugin->client_perform_task = NULL;
2192  }
2193  if (NULL != plugin->curl_multi_handle)
2194  {
2195  curl_multi_cleanup (plugin->curl_multi_handle);
2196  plugin->curl_multi_handle = NULL;
2197  }
2198  curl_global_cleanup ();
2200  _ ("Shutdown for plugin `%s' complete\n"),
2201  plugin->name);
2203  GNUNET_free (plugin->proxy_hostname);
2204  GNUNET_free (plugin->proxy_username);
2205  GNUNET_free (plugin->proxy_password);
2206  GNUNET_free (plugin);
2207  GNUNET_free (api);
2208  return NULL;
2209 }
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
void * cls
Closure for all of the callbacks.

References _, Plugin::client_perform_task, GNUNET_TRANSPORT_PluginFunctions::cls, destroy_session_cb(), GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_SCHEDULER_cancel(), LOG, Plugin::name, plugin, and Plugin::sessions.

Here is the call graph for this function:

◆ client_configure_plugin()

static int client_configure_plugin ( struct HTTP_Client_Plugin plugin)
static

Configure plugin.

Parameters
pluginthe plugin handle
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure

Definition at line 2219 of file plugin_transport_http_client.c.

2220 {
2221  unsigned long long max_requests;
2222  char *proxy_type;
2223 
2224  /* Optional parameters */
2225  if (GNUNET_OK !=
2227  plugin->name,
2228  "MAX_CONNECTIONS",
2229  &max_requests))
2230  max_requests = 128;
2231  plugin->max_requests = max_requests;
2232 
2234  _ ("Maximum number of requests is %u\n"),
2235  plugin->max_requests);
2236 
2237  /* Read proxy configuration */
2238  if (GNUNET_OK ==
2240  plugin->name,
2241  "PROXY",
2242  &plugin->proxy_hostname))
2243  {
2245  "Found proxy host: `%s'\n",
2246  plugin->proxy_hostname);
2247  /* proxy username */
2248  if (GNUNET_OK ==
2250  plugin->name,
2251  "PROXY_USERNAME",
2252  &plugin->proxy_username))
2253  {
2255  "Found proxy username name: `%s'\n",
2256  plugin->proxy_username);
2257  }
2258 
2259  /* proxy password */
2260  if (GNUNET_OK ==
2262  plugin->name,
2263  "PROXY_PASSWORD",
2264  &plugin->proxy_password))
2265  {
2267  "Found proxy password name: `%s'\n",
2268  plugin->proxy_password);
2269  }
2270 
2271  /* proxy type */
2272  if (GNUNET_OK ==
2274  plugin->name,
2275  "PROXY_TYPE",
2276  &proxy_type))
2277  {
2279 
2280  if (0 == strcmp (proxy_type, "HTTP"))
2281  plugin->proxytype = CURLPROXY_HTTP;
2282  else if (0 == strcmp (proxy_type, "SOCKS4"))
2283  plugin->proxytype = CURLPROXY_SOCKS4;
2284  else if (0 == strcmp (proxy_type, "SOCKS5"))
2285  plugin->proxytype = CURLPROXY_SOCKS5;
2286  else if (0 == strcmp (proxy_type, "SOCKS4A"))
2287  plugin->proxytype = CURLPROXY_SOCKS4A;
2288  else if (0 == strcmp (proxy_type, "SOCKS5_HOSTNAME "))
2289  plugin->proxytype = CURLPROXY_SOCKS5_HOSTNAME;
2290  else
2291  {
2293  _ (
2294  "Invalid proxy type: `%s', disabling proxy! Check configuration!\n"),
2295  proxy_type);
2296 
2298  GNUNET_free (plugin->proxy_hostname);
2299  plugin->proxy_hostname = NULL;
2300  GNUNET_free (plugin->proxy_username);
2301  plugin->proxy_username = NULL;
2302  GNUNET_free (plugin->proxy_password);
2303  plugin->proxy_password = NULL;
2304 
2305  return GNUNET_SYSERR;
2306  }
2307 
2309  "Found proxy type: `%s'\n",
2310  proxy_type);
2311  }
2312 
2313  /* proxy http tunneling */
2314  plugin->proxy_use_httpproxytunnel
2316  plugin->name,
2317  "PROXY_HTTP_TUNNELING");
2318  if (GNUNET_SYSERR == plugin->proxy_use_httpproxytunnel)
2319  plugin->proxy_use_httpproxytunnel = GNUNET_NO;
2320 
2322  }
2323 
2324  /* Should we emulate an XHR client for testing? */
2325  plugin->emulate_xhr
2327  plugin->name,
2328  "EMULATE_XHR");
2329  return GNUNET_OK;
2330 }
static curl_proxytype proxy_type
Proxy type we are using (can be NULL).
enum GNUNET_GenericReturnValue 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.
enum GNUNET_GenericReturnValue 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".
enum GNUNET_GenericReturnValue 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.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_utf8_toupper(const char *input, char *output)
Convert the utf-8 input string to upper case.
Definition: strings.c:472
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.

References _, GNUNET_DATACACHE_PluginEnvironment::cfg, Plugin::env, GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_NO, GNUNET_OK, GNUNET_STRINGS_utf8_toupper(), GNUNET_SYSERR, LOG, HTTP_Client_Plugin::max_requests, Plugin::name, plugin, and proxy_type.

Referenced by libgnunet_plugin_transport_http_client_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ http_client_plugin_address_to_string()

static const char* http_client_plugin_address_to_string ( void *  cls,
const void *  addr,
size_t  addrlen 
)
static

Function to convert an address to a human-readable string.

Parameters
clsclosure
addraddress to convert
addrlenaddress length
Returns
res string if conversion was successful, NULL otherwise

Definition at line 2342 of file plugin_transport_http_client.c.

2345 {
2347  addr,
2348  addrlen);
2349 }
#define PLUGIN_NAME

References http_common_plugin_address_to_string(), and PLUGIN_NAME.

Referenced by libgnunet_plugin_transport_http_client_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ http_client_plugin_update_session_timeout()

static void http_client_plugin_update_session_timeout ( void *  cls,
const struct GNUNET_PeerIdentity peer,
struct GNUNET_ATS_Session session 
)
static

Function that will be called whenever the transport service wants to notify the plugin that a session is still active and in use and therefore the session timeout for this session has to be updated.

Parameters
clsclosure
peerwhich peer was the session for
sessionwhich session is being updated

Definition at line 2362 of file plugin_transport_http_client.c.

2366 {
2368 }

References client_reschedule_session_timeout().

Referenced by libgnunet_plugin_transport_http_client_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ http_client_plugin_update_inbound_delay()

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 
)
static

Function that will be called whenever the transport service wants to notify the plugin that the inbound quota changed and that the plugin should update it's delay for the next receive value.

Parameters
clsclosure
peerwhich peer was the session for
swhich session is being updated
delaynew delay to use for receiving

Definition at line 2382 of file plugin_transport_http_client.c.

2386 {
2389  "New inbound delay %s\n",
2391  GNUNET_NO));
2392  if (s->recv_wakeup_task != NULL)
2393  {
2395  s->recv_wakeup_task
2397  &client_wake_up,
2398  s);
2399  }
2400 }

References client_wake_up(), delay, GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_relative_to_absolute(), LOG, GNUNET_ATS_Session::next_receive, and GNUNET_ATS_Session::recv_wakeup_task.

Referenced by libgnunet_plugin_transport_http_client_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_session_info_iter()

static int send_session_info_iter ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  value 
)
static

Return information about the given session to the monitor callback.

Parameters
clsthe struct Plugin with the monitor callback (sic)
peerpeer we send information about
valueour struct GNUNET_ATS_Session to send information about
Returns
GNUNET_OK (continue to iterate)

Definition at line 2413 of file plugin_transport_http_client.c.

2416 {
2417  struct HTTP_Client_Plugin *plugin = cls;
2418  struct GNUNET_ATS_Session *session = value;
2419 
2421  session,
2424  session,
2425  GNUNET_TRANSPORT_SS_UP); /* FIXME: or handshake? */
2426  return GNUNET_OK;
2427 }

References GNUNET_OK, GNUNET_TRANSPORT_SS_INIT, GNUNET_TRANSPORT_SS_UP, notify_session_monitor(), plugin, and value.

Referenced by http_client_plugin_setup_monitor(), and template_plugin_setup_monitor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ http_client_plugin_setup_monitor()

static void http_client_plugin_setup_monitor ( void *  cls,
GNUNET_TRANSPORT_SessionInfoCallback  sic,
void *  sic_cls 
)
static

Begin monitoring sessions of a plugin.

There can only be one active monitor per plugin (i.e. if there are multiple monitors, the transport service needs to multiplex the generated events over all of them).

Parameters
clsclosure of the plugin
siccallback to invoke, NULL to disable monitor; plugin will being by iterating over all active sessions immediately and then enter monitor mode
sic_clsclosure for sic

Definition at line 2443 of file plugin_transport_http_client.c.

2446 {
2447  struct HTTP_Client_Plugin *plugin = cls;
2448 
2449  plugin->sic = sic;
2450  plugin->sic_cls = sic_cls;
2451  if (NULL != sic)
2452  {
2455  plugin);
2456  /* signal end of first iteration */
2457  sic (sic_cls, NULL, NULL);
2458  }
2459 }
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.
GNUNET_TRANSPORT_SessionInfoCallback sic
Function to call about session status changes.
void * sic_cls
Closure for sic.

References GNUNET_CONTAINER_multipeermap_iterate(), plugin, send_session_info_iter(), Plugin::sessions, HTTP_Client_Plugin::sic, Plugin::sic, HTTP_Client_Plugin::sic_cls, and Plugin::sic_cls.

Referenced by libgnunet_plugin_transport_http_client_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ libgnunet_plugin_transport_http_client_init()

void* libgnunet_plugin_transport_http_client_init ( void *  cls)

Entry point for the plugin.

Definition at line 2466 of file plugin_transport_http_client.c.

2467 {
2470  struct HTTP_Client_Plugin *plugin;
2471 
2472  if (NULL == env->receive)
2473  {
2474  /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
2475  initialize the plugin or the API */
2477  api->cls = NULL;
2481  return api;
2482  }
2483 
2485  plugin->env = env;
2487  GNUNET_YES);
2489  api->cls = plugin;
2490  api->send = &http_client_plugin_send;
2504 #if BUILD_HTTPS
2505  plugin->name = "transport-https_client";
2506  plugin->protocol = "https";
2507 #else
2508  plugin->name = "transport-http_client";
2509  plugin->protocol = "http";
2510 #endif
2511  plugin->last_tag = 1;
2512 
2514  {
2516  return NULL;
2517  }
2518 
2519  /* Start client */
2521  {
2523  return NULL;
2524  }
2525  return api;
2526 }
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
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).
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.
static enum GNUNET_NetworkType http_client_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session)
Function obtain the network type for a session.
#define LIBGNUNET_PLUGIN_TRANSPORT_DONE
static int client_configure_plugin(struct HTTP_Client_Plugin *plugin)
Configure plugin.
static int client_start(struct HTTP_Client_Plugin *plugin)
Setup http_client plugin.
static unsigned int http_client_query_keepalive_factor(void *cls)
Function that is called to get the keepalive factor.
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.
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.
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...
static void http_client_plugin_setup_monitor(void *cls, GNUNET_TRANSPORT_SessionInfoCallback sic, void *sic_cls)
Begin monitoring sessions of a plugin.
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...
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 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.
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.
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.
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.
The transport service will pass a pointer to a struct of this type as the first and only argument to ...
void * cls
Closure for the various callbacks.
GNUNET_TRANSPORT_TransmitFunction send
Function that the transport service will use to transmit data to another peer.
GNUNET_TRANSPORT_UpdateInboundDelay update_inbound_delay
Function that will be called whenever the transport service wants to notify the plugin that the inbou...
GNUNET_TRANSPORT_SessionMonitorSetup setup_monitor
Function to monitor the sessions managed by the plugin.
GNUNET_TRANSPORT_DisconnectPeerFunction disconnect_peer
Function that can be used to force the plugin to disconnect from the given peer and cancel all previo...
GNUNET_TRANSPORT_GetNetworkTypeForAddress get_network_for_address
Function to obtain the network type for an address.
GNUNET_TRANSPORT_DisconnectSessionFunction disconnect_session
Function that can be used to force the plugin to disconnect from the given peer and cancel all previo...
GNUNET_TRANSPORT_QueryKeepaliveFactorFunction query_keepalive_factor
Function that is used to query keepalive factor.
GNUNET_TRANSPORT_AddressPrettyPrinter address_pretty_printer
Function to pretty-print addresses.
GNUNET_TRANSPORT_AddressToString address_to_string
Function that will be called to convert a binary address to a string (numeric conversion only).
GNUNET_TRANSPORT_GetNetworkType get_network
Function to obtain the network type for a session.
GNUNET_TRANSPORT_CreateSession get_session
Function that will be called tell the plugin to create a session object.
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_StringToAddress string_to_address
Function that will be called to convert a string address to binary (numeric conversion only).
GNUNET_TRANSPORT_UpdateSessionTimeout update_session_timeout
Function that will be called whenever the transport service wants to notify the plugin that a session...

References GNUNET_TRANSPORT_PluginFunctions::address_pretty_printer, GNUNET_TRANSPORT_PluginFunctions::address_to_string, GNUNET_TRANSPORT_PluginFunctions::check_address, client_configure_plugin(), client_start(), GNUNET_TRANSPORT_PluginEnvironment::cls, GNUNET_TRANSPORT_PluginFunctions::cls, GNUNET_TRANSPORT_PluginFunctions::disconnect_peer, GNUNET_TRANSPORT_PluginFunctions::disconnect_session, env, Plugin::env, GNUNET_TRANSPORT_PluginFunctions::get_network, GNUNET_TRANSPORT_PluginFunctions::get_network_for_address, GNUNET_TRANSPORT_PluginFunctions::get_session, GNUNET_CONTAINER_multipeermap_create(), GNUNET_new, GNUNET_SYSERR, GNUNET_YES, http_client_plugin_address_suggested(), http_client_plugin_address_to_string(), http_client_plugin_get_network(), http_client_plugin_get_network_for_address(), http_client_plugin_get_session(), http_client_plugin_peer_disconnect(), http_client_plugin_send(), http_client_plugin_session_disconnect(), http_client_plugin_setup_monitor(), http_client_plugin_update_inbound_delay(), http_client_plugin_update_session_timeout(), http_client_query_keepalive_factor(), http_common_plugin_address_pretty_printer(), http_common_plugin_string_to_address(), Plugin::last_tag, LIBGNUNET_PLUGIN_TRANSPORT_DONE, Plugin::name, plugin, Plugin::protocol, GNUNET_TRANSPORT_PluginFunctions::query_keepalive_factor, GNUNET_TRANSPORT_PluginFunctions::send, Plugin::sessions, GNUNET_TRANSPORT_PluginFunctions::setup_monitor, GNUNET_TRANSPORT_PluginFunctions::string_to_address, GNUNET_TRANSPORT_PluginFunctions::update_inbound_delay, and GNUNET_TRANSPORT_PluginFunctions::update_session_timeout.

Here is the call graph for this function: