GNUnet  0.20.0
plugin_transport_http_client.c File Reference

HTTP/S client transport plugin. More...

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:484

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 849 of file plugin_transport_http_client.c.

851 {
852  struct HTTP_Client_Plugin *plugin = cls;
853 
855  "Session %p: notifying transport about ending session\n",
856  s);
857  plugin->env->session_end (plugin->env->cls,
858  s->address,
859  s);
861 
862  /* Re-schedule since handles have changed */
863  if (NULL != plugin->client_perform_task)
864  {
865  GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
866  plugin->client_perform_task = NULL;
867  }
869 
870  return GNUNET_OK;
871 }
struct TestcasePlugin * plugin
The process handle to the testbed service.
@ GNUNET_OK
@ 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:975
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.
Encapsulation of all of the state of the plugin.

References GNUNET_ATS_Session::address, client_delete_session(), client_schedule(), 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;
429  plugin->sic (plugin->sic_cls,
430  session,
431  &info);
432 }
enum State state
current state of profiling
#define info
@ GNUNET_NO
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.

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, 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 
501  GNUNET_STATISTICS_set (plugin->env->stats,
503  plugin->cur_requests,
504  GNUNET_NO);
505  next = s->msg_head;
506  while (NULL != (pos = next))
507  {
508  next = pos->next;
510  s->msg_tail,
511  pos);
512  GNUNET_assert (0 < s->msgs_in_queue);
513  s->msgs_in_queue--;
514  GNUNET_assert (pos->size <= s->bytes_in_queue);
515  s->bytes_in_queue -= pos->size;
516  if (NULL != pos->transmit_cont)
517  pos->transmit_cont (pos->transmit_cont_cls,
518  &s->address->peer,
520  pos->size,
521  pos->pos + s->overhead);
522  s->overhead = 0;
523  GNUNET_free (pos);
524  }
525  GNUNET_assert (0 == s->msgs_in_queue);
526  GNUNET_assert (0 == s->bytes_in_queue);
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
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:404
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
CURL * easyhandle
The curl easy handle.

References GNUNET_ATS_Session::address, GNUNET_ATS_Session::bytes_in_queue, RequestHandle::easyhandle, 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, 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:316

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

Definition at line 1292 of file plugin_transport_http_client.c.

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

574 {
575  fd_set rs;
576  fd_set ws;
577  fd_set es;
578  int max;
579  struct GNUNET_NETWORK_FDSet *grs;
580  struct GNUNET_NETWORK_FDSet *gws;
581  long to;
582  CURLMcode mret;
584 
585  /* Cancel previous scheduled task */
586  if (plugin->client_perform_task != NULL)
587  {
588  GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
589  plugin->client_perform_task = NULL;
590  }
591  max = -1;
592  FD_ZERO (&rs);
593  FD_ZERO (&ws);
594  FD_ZERO (&es);
595  mret = curl_multi_fdset (plugin->curl_multi_handle, &rs, &ws, &es, &max);
596  if (mret != CURLM_OK)
597  {
599  _ ("%s failed at %s:%d: `%s'\n"),
600  "curl_multi_fdset",
601  __FILE__,
602  __LINE__,
603  curl_multi_strerror (mret));
604  return GNUNET_SYSERR;
605  }
606  mret = curl_multi_timeout (plugin->curl_multi_handle, &to);
607  if (-1 == to)
609  else
611  if (now == GNUNET_YES)
613 
614  if (CURLM_OK != mret)
615  {
617  _ ("%s failed at %s:%d: `%s'\n"),
618  "curl_multi_timeout", __FILE__, __LINE__,
619  curl_multi_strerror (mret));
620  return GNUNET_SYSERR;
621  }
622 
625  GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
626  GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
627 
628  /* Schedule task to run when select is ready to read or write */
629  plugin->client_perform_task =
631  timeout, grs, gws,
632  &client_run, plugin);
635  return GNUNET_OK;
636 }
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:1171
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1187
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:1041
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:1830
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
#define max(x, y)
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
static void client_run(void *cls)
Task performing curl operations.
collection of IO descriptors
Time for relative time used by GNUnet, in microseconds.

References _, 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 1514 of file plugin_transport_http_client.c.

1515 {
1516  CURLMcode mret;
1517  struct HttpAddress *ha;
1518  uint32_t options;
1519 
1520  ha = (struct HttpAddress *) s->address->address;
1521  options = ntohl (ha->options);
1522  /* create get request */
1523  s->get.easyhandle = curl_easy_init ();
1524  s->get.s = s;
1525  if (0 != (options & HTTP_OPTIONS_TCP_STEALTH))
1526  {
1527 #ifdef TCP_STEALTH
1528  curl_easy_setopt (s->get.easyhandle,
1529  CURLOPT_OPENSOCKETFUNCTION,
1530  &open_tcp_stealth_socket_cb);
1531  curl_easy_setopt (s->get.easyhandle,
1532  CURLOPT_OPENSOCKETDATA,
1533  s);
1534 #else
1536  "Cannot connect, TCP STEALTH needed and not supported by kernel.\n");
1537  curl_easy_cleanup (s->get.easyhandle);
1538  s->get.easyhandle = NULL;
1539  s->get.s = NULL;
1540  return GNUNET_SYSERR;
1541 #endif
1542  }
1543 
1544 #if VERBOSE_CURL
1545  curl_easy_setopt (s->get.easyhandle,
1546  CURLOPT_VERBOSE,
1547  1L);
1548  curl_easy_setopt (s->get.easyhandle,
1549  CURLOPT_DEBUGFUNCTION,
1550  &client_log);
1551  curl_easy_setopt (s->get.easyhandle,
1552  CURLOPT_DEBUGDATA,
1553  &s->get);
1554 #endif
1555 #if BUILD_HTTPS
1556  curl_easy_setopt (s->get.easyhandle, CURLOPT_SSLVERSION,
1557  CURL_SSLVERSION_TLSv1);
1558  {
1561  {
1562  curl_easy_setopt (s->get.easyhandle,
1563  CURLOPT_SSL_VERIFYPEER, 1L);
1564  curl_easy_setopt (s->get.easyhandle,
1565  CURLOPT_SSL_VERIFYHOST,
1566  2L);
1567  }
1568  else
1569  {
1570  curl_easy_setopt (s->get.easyhandle,
1571  CURLOPT_SSL_VERIFYPEER,
1572  0L);
1573  curl_easy_setopt (s->get.easyhandle,
1574  CURLOPT_SSL_VERIFYHOST,
1575  0L);
1576  }
1577  }
1578  curl_easy_setopt (s->get.easyhandle,
1579  CURLOPT_PROTOCOLS,
1580  CURLPROTO_HTTPS);
1581  curl_easy_setopt (s->get.easyhandle,
1582  CURLOPT_REDIR_PROTOCOLS,
1583  CURLPROTO_HTTPS);
1584 #else
1585  curl_easy_setopt (s->get.easyhandle,
1586  CURLOPT_PROTOCOLS,
1587  CURLPROTO_HTTP);
1588  curl_easy_setopt (s->get.easyhandle,
1589  CURLOPT_REDIR_PROTOCOLS,
1590  CURLPROTO_HTTP);
1591 #endif
1592 
1593  if (NULL != s->plugin->proxy_hostname)
1594  {
1595  curl_easy_setopt (s->get.easyhandle,
1596  CURLOPT_PROXY,
1597  s->plugin->proxy_hostname);
1598  curl_easy_setopt (s->get.easyhandle,
1599  CURLOPT_PROXYTYPE,
1600  s->plugin->proxytype);
1601  if (NULL != s->plugin->proxy_username)
1602  curl_easy_setopt (s->get.easyhandle,
1603  CURLOPT_PROXYUSERNAME,
1604  s->plugin->proxy_username);
1605  if (NULL != s->plugin->proxy_password)
1606  curl_easy_setopt (s->get.easyhandle,
1607  CURLOPT_PROXYPASSWORD,
1608  s->plugin->proxy_password);
1609  if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel)
1610  curl_easy_setopt (s->get.easyhandle,
1611  CURLOPT_HTTPPROXYTUNNEL,
1612  s->plugin->proxy_use_httpproxytunnel);
1613  }
1614 
1615  if (GNUNET_YES == s->plugin->emulate_xhr)
1616  {
1617  char *url;
1618 
1619  GNUNET_asprintf (&url,
1620  "%s,1",
1621  s->url);
1622  curl_easy_setopt (s->get.easyhandle,
1623  CURLOPT_URL,
1624  url);
1625  GNUNET_free (url);
1626  }
1627  else
1628  {
1629  curl_easy_setopt (s->get.easyhandle,
1630  CURLOPT_URL,
1631  s->url);
1632  }
1633  curl_easy_setopt (s->get.easyhandle,
1634  CURLOPT_READFUNCTION,
1635  &client_send_cb);
1636  curl_easy_setopt (s->get.easyhandle,
1637  CURLOPT_READDATA,
1638  s);
1639  curl_easy_setopt (s->get.easyhandle,
1640  CURLOPT_WRITEFUNCTION,
1641  &client_receive);
1642  curl_easy_setopt (s->get.easyhandle,
1643  CURLOPT_WRITEDATA,
1644  s);
1645  /* No timeout by default, timeout done with session timeout */
1646  curl_easy_setopt (s->get.easyhandle,
1647  CURLOPT_TIMEOUT,
1648  0L);
1649  curl_easy_setopt (s->get.easyhandle,
1650  CURLOPT_PRIVATE, s);
1651  curl_easy_setopt (s->get.easyhandle,
1652  CURLOPT_CONNECTTIMEOUT_MS,
1653  (long) (HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us
1654  / 1000LL));
1655  curl_easy_setopt (s->get.easyhandle, CURLOPT_BUFFERSIZE,
1657 #if CURL_TCP_NODELAY
1658  curl_easy_setopt (ps->recv_endpoint,
1659  CURLOPT_TCP_NODELAY,
1660  1L);
1661 #endif
1662  curl_easy_setopt (s->get.easyhandle,
1663  CURLOPT_FOLLOWLOCATION,
1664  0L);
1665 
1666  mret = curl_multi_add_handle (s->plugin->curl_multi_handle,
1667  s->get.easyhandle);
1668  if (CURLM_OK != mret)
1669  {
1671  "Session %p : Failed to add GET handle to multihandle: `%s'\n",
1672  s,
1673  curl_multi_strerror (mret));
1674  curl_easy_cleanup (s->get.easyhandle);
1675  s->get.easyhandle = NULL;
1676  s->get.s = NULL;
1677  GNUNET_break (0);
1678  return GNUNET_SYSERR;
1679  }
1680  s->plugin->cur_requests++;
1682  "GET request `%s' established, number of requests increased to %u\n",
1683  s->url,
1684  s->plugin->cur_requests);
1685  return GNUNET_OK;
1686 }
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 1690 of file plugin_transport_http_client.c.

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

765 {
766  struct HTTP_Client_Plugin *plugin = cls;
767  struct HTTP_Message *msg;
768  char *stat_txt;
769 
771  "Session %p/request %p: Sending message with %lu to peer `%s' \n",
772  s,
773  s->put.easyhandle,
774  (unsigned long) msgbuf_size,
775  GNUNET_i2s (&s->address->peer));
776 
777  /* create new message and schedule */
778  msg = GNUNET_malloc (sizeof(struct HTTP_Message) + msgbuf_size);
779  msg->size = msgbuf_size;
780  msg->buf = (char *) &msg[1];
781  msg->transmit_cont = cont;
782  msg->transmit_cont_cls = cont_cls;
783  GNUNET_memcpy (msg->buf,
784  msgbuf,
785  msgbuf_size);
787  s->msg_tail,
788  msg);
789  s->msgs_in_queue++;
790  s->bytes_in_queue += msg->size;
791 
792  GNUNET_asprintf (&stat_txt,
793  "# bytes currently in %s_client buffers",
794  plugin->protocol);
795  GNUNET_STATISTICS_update (plugin->env->stats,
796  stat_txt, msgbuf_size, GNUNET_NO);
797  GNUNET_free (stat_txt);
799  s,
801  if (H_TMP_DISCONNECTING == s->put.state)
802  {
803  /* PUT request is currently getting disconnected */
806  "Session %p/request %p: currently disconnecting, reconnecting immediately\n",
807  s,
808  s->put.easyhandle);
809  return msgbuf_size;
810  }
811  if (H_PAUSED == s->put.state)
812  {
813  /* PUT request was paused, unpause */
814  GNUNET_assert (s->put_disconnect_task != NULL);
816  s->put_disconnect_task = NULL;
818  "Session %p/request %p: unpausing request\n",
819  s, s->put.easyhandle);
820  s->put.state = H_CONNECTED;
821  if (NULL != s->put.easyhandle)
822  curl_easy_pause (s->put.easyhandle, CURLPAUSE_CONT);
823  }
824  else if (H_TMP_DISCONNECTED == s->put.state)
825  {
826  /* PUT request was disconnected, reconnect */
827  LOG (GNUNET_ERROR_TYPE_DEBUG, "Session %p: Reconnecting PUT request\n", s);
828  GNUNET_break (NULL == s->put.easyhandle);
830  {
831  /* Could not reconnect */
833  return GNUNET_SYSERR;
834  }
835  }
837  return msgbuf_size;
838 }
#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.

References GNUNET_ATS_Session::address, GNUNET_ATS_Session::bytes_in_queue, client_connect_put(), client_schedule(), RequestHandle::easyhandle, 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, 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 883 of file plugin_transport_http_client.c.

884 {
885  return 3;
886 }

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 898 of file plugin_transport_http_client.c.

901 {
902  struct HTTP_Client_Plugin *plugin = cls;
903  struct GNUNET_ATS_Session *session = value;
904 
906  return GNUNET_OK;
907 }
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 919 of file plugin_transport_http_client.c.

921 {
922  struct HTTP_Client_Plugin *plugin = cls;
923 
925  "Transport tells me to disconnect `%s'\n",
926  GNUNET_i2s (target));
928  target,
930  plugin);
931 }
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, and plugin.

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 960 of file plugin_transport_http_client.c.

963 {
964  struct GNUNET_ATS_SessionClientCtx *sc_ctx = cls;
965  struct GNUNET_ATS_Session *s = value;
966 
967  if (0 == GNUNET_HELLO_address_cmp (sc_ctx->address,
968  s->address))
969  {
970  sc_ctx->ret = s;
971  return GNUNET_NO;
972  }
973  return GNUNET_YES;
974 }
int GNUNET_HELLO_address_cmp(const struct GNUNET_HELLO_Address *a1, const struct GNUNET_HELLO_Address *a2)
Compare two addresses.
Definition: address.c:112
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 985 of file plugin_transport_http_client.c.

987 {
988  struct GNUNET_ATS_SessionClientCtx sc_ctx;
989 
990  sc_ctx.address = address;
991  sc_ctx.ret = NULL;
994  &sc_ctx);
995  return sc_ctx.ret;
996 }
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, and session_lookup_client_by_address().

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 1007 of file plugin_transport_http_client.c.

1008 {
1009  struct GNUNET_ATS_Session *s = cls;
1010 
1011  s->put_disconnect_task = NULL;
1013  "Session %p/request %p: will be disconnected due to no activity\n",
1014  s, s->put.easyhandle);
1016  if (NULL != s->put.easyhandle)
1017  curl_easy_pause (s->put.easyhandle,
1018  CURLPAUSE_CONT);
1020 }

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 1034 of file plugin_transport_http_client.c.

1038 {
1039  struct GNUNET_ATS_Session *s = cls;
1040  struct HTTP_Client_Plugin *plugin = s->plugin;
1041  struct HTTP_Message *msg = s->msg_head;
1042  size_t len;
1043  char *stat_txt;
1044 
1045  if (H_TMP_DISCONNECTING == s->put.state)
1046  {
1048  "Session %p/request %p: disconnect due to inactivity\n",
1049  s, s->put.easyhandle);
1050  return 0;
1051  }
1052 
1053  if (NULL == msg)
1054  {
1055  if (GNUNET_YES == plugin->emulate_xhr)
1056  {
1058  "Session %p/request %p: PUT request finished\n",
1059  s,
1060  s->put.easyhandle);
1062  return 0;
1063  }
1064 
1065  /* We have nothing to send, so pause PUT request */
1067  "Session %p/request %p: nothing to send, suspending\n",
1068  s,
1069  s->put.easyhandle);
1073  s);
1074  s->put.state = H_PAUSED;
1075  return CURL_READFUNC_PAUSE;
1076  }
1077  /* data to send */
1078  GNUNET_assert (msg->pos < msg->size);
1079  /* calculate how much fits in buffer */
1080  len = GNUNET_MIN (msg->size - msg->pos,
1081  size * nmemb);
1082  GNUNET_memcpy (stream,
1083  &msg->buf[msg->pos],
1084  len);
1085  msg->pos += len;
1086  if (msg->pos == msg->size)
1087  {
1089  "Session %p/request %p: sent message with %lu bytes sent, removing message from queue\n",
1090  s,
1091  s->put.easyhandle,
1092  (unsigned long) msg->size);
1093  /* Calling transmit continuation */
1095  s->msg_tail,
1096  msg);
1097  GNUNET_assert (0 < s->msgs_in_queue);
1098  s->msgs_in_queue--;
1100  s->bytes_in_queue -= msg->size;
1101  if (NULL != msg->transmit_cont)
1102  msg->transmit_cont (msg->transmit_cont_cls,
1103  &s->address->peer,
1104  GNUNET_OK,
1105  msg->size,
1106  msg->size + s->overhead);
1107  s->overhead = 0;
1108  GNUNET_free (msg);
1109  }
1111  s,
1113  GNUNET_asprintf (&stat_txt,
1114  "# bytes currently in %s_client buffers",
1115  plugin->protocol);
1116  GNUNET_STATISTICS_update (plugin->env->stats,
1117  stat_txt,
1118  -len,
1119  GNUNET_NO);
1120  GNUNET_free (stat_txt);
1121  GNUNET_asprintf (&stat_txt,
1122  "# bytes transmitted via %s_client",
1123  plugin->protocol);
1124  GNUNET_STATISTICS_update (plugin->env->stats,
1125  stat_txt,
1126  len,
1127  GNUNET_NO);
1128  GNUNET_free (stat_txt);
1129  return len;
1130 }
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:1272
static unsigned int size
Size of the "table".
Definition: peer.c:68
#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, 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, 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 1139 of file plugin_transport_http_client.c.

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

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 1170 of file plugin_transport_http_client.c.

1172 {
1173  struct GNUNET_ATS_Session *s = cls;
1174  struct HTTP_Client_Plugin *plugin;
1175  struct GNUNET_TIME_Relative delay;
1176  char *stat_txt;
1177 
1178  plugin = s->plugin;
1179  delay = s->plugin->env->receive (plugin->env->cls,
1180  s->address,
1181  s,
1182  message);
1183  GNUNET_asprintf (&stat_txt,
1184  "# bytes received via %s_client",
1185  plugin->protocol);
1186  GNUNET_STATISTICS_update (plugin->env->stats,
1187  stat_txt,
1188  ntohs (message->size),
1189  GNUNET_NO);
1190  GNUNET_free (stat_txt);
1191 
1193  if (GNUNET_TIME_absolute_get ().abs_value_us < s->next_receive.abs_value_us)
1194  {
1196  "Client: peer `%s' address `%s' next read delayed for %s\n",
1197  GNUNET_i2s (&s->address->peer),
1199  s->address->address,
1200  s->address->address_length),
1202  GNUNET_YES));
1203  }
1205  return GNUNET_OK;
1206 }
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:111
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:569
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.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
char * protocol
Plugin protocol http, https.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_HELLO_Address::address, GNUNET_ATS_Session::address, GNUNET_HELLO_Address::address_length, client_reschedule_session_timeout(), 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 1220 of file plugin_transport_http_client.c.

1224 {
1225  return size * nmemb;
1226 }

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 1240 of file plugin_transport_http_client.c.

1244 {
1245  struct GNUNET_ATS_Session *s = cls;
1246  struct GNUNET_TIME_Absolute now;
1247  size_t len = size * nmemb;
1248 
1250  "Session %p / request %p: Received %lu bytes from peer `%s'\n",
1251  s,
1252  s->get.easyhandle,
1253  (unsigned long) len,
1254  GNUNET_i2s (&s->address->peer));
1255  now = GNUNET_TIME_absolute_get ();
1256  if (now.abs_value_us < s->next_receive.abs_value_us)
1257  {
1261 
1263  "Session %p / request %p: No inbound bandwidth available! Next read was delayed for %s\n",
1264  s,
1265  s->get.easyhandle,
1267  GNUNET_YES));
1268  if (s->recv_wakeup_task != NULL)
1269  {
1271  s->recv_wakeup_task = NULL;
1272  }
1273  s->recv_wakeup_task
1275  &client_wake_up,
1276  s);
1277  return CURL_WRITEFUNC_PAUSE;
1278  }
1279  if (NULL == s->msg_tk)
1281  s);
1283  stream,
1284  len,
1285  GNUNET_NO,
1286  GNUNET_NO);
1287  return len;
1288 }
enum GNUNET_GenericReturnValue 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:101
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Definition: mst.c:86
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:421
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:36
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 1863 of file plugin_transport_http_client.c.

1864 {
1865  struct HTTP_Client_Plugin *plugin = s->plugin;
1866  int res = GNUNET_OK;
1867 
1868  /* create url */
1869  if (NULL ==
1871  s->address->address,
1872  s->address->address_length))
1873  {
1875  "Invalid address peer `%s'\n",
1876  GNUNET_i2s (&s->address->peer));
1877  return GNUNET_SYSERR;
1878  }
1879 
1880  GNUNET_asprintf (&s->url,
1881  "%s/%s;%u",
1883  s->address->address,
1884  s->address->address_length),
1885  GNUNET_i2s_full (plugin->env->my_identity),
1886  plugin->last_tag);
1887 
1888  plugin->last_tag++;
1890  "Initiating outbound session peer `%s' using address `%s'\n",
1891  GNUNET_i2s (&s->address->peer), s->url);
1892 
1893  if (GNUNET_SYSERR == client_connect_get (s))
1894  return GNUNET_SYSERR;
1895  /* If we are emulating an XHR client then delay sending a PUT request until
1896  * there is something to send.
1897  */
1898  if (GNUNET_YES == plugin->emulate_xhr)
1899  {
1901  }
1902  else if (GNUNET_SYSERR == client_connect_put (s))
1903  return GNUNET_SYSERR;
1904 
1906  "Session %p: connected with GET %p and PUT %p\n",
1907  s, s->get.easyhandle,
1908  s->put.easyhandle);
1909  /* Perform connect */
1910  GNUNET_STATISTICS_set (plugin->env->stats,
1912  plugin->cur_requests,
1913  GNUNET_NO);
1914  /* Re-schedule since handles have changed */
1915  if (NULL != plugin->client_perform_task)
1916  {
1917  GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
1918  plugin->client_perform_task = NULL;
1919  }
1920 
1921  /* Schedule task to run immediately */
1922  plugin->client_perform_task = GNUNET_SCHEDULER_add_now (client_run,
1923  plugin);
1924  return res;
1925 }
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:1299
const char * http_common_plugin_address_to_url(void *cls, const void *addr, size_t addrlen)
FIXME.

References GNUNET_HELLO_Address::address, GNUNET_ATS_Session::address, GNUNET_HELLO_Address::address_length, client_connect_get(), client_connect_put(), client_run(), RequestHandle::easyhandle, 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, LOG, GNUNET_HELLO_Address::peer, plugin, GNUNET_ATS_Session::plugin, 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 1863 of file plugin_transport_http_client.c.

1938 {
1939  return session->scope;
1940 }
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 1863 of file plugin_transport_http_client.c.

1954 {
1955  struct HTTP_Client_Plugin *plugin = cls;
1956 
1958  address);
1959 }
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 1968 of file plugin_transport_http_client.c.

1969 {
1970  struct GNUNET_ATS_Session *s = cls;
1971  struct GNUNET_TIME_Relative left;
1972 
1973  s->timeout_task = NULL;
1975  if (0 != left.rel_value_us)
1976  {
1977  /* not actually our turn yet, but let's at least update
1978  the monitor, it may think we're about to die ... */
1980  s,
1984  s);
1985  return;
1986  }
1987  LOG (TIMEOUT_LOG,
1988  "Session %p was idle for %s, disconnecting\n",
1989  s,
1991  GNUNET_YES));
1994  s));
1995 }
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:405
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 2007 of file plugin_transport_http_client.c.

2009 {
2010  struct HTTP_Client_Plugin *plugin = cls;
2011  struct GNUNET_ATS_Session *s;
2012  struct sockaddr *sa;
2013  enum GNUNET_NetworkType net_type;
2014  size_t salen = 0;
2015  int res;
2016 
2017  GNUNET_assert (NULL != address->address);
2018 
2019  /* find existing session */
2021  if (NULL != s)
2022  return s;
2023 
2024  /* create a new session */
2025  if (plugin->max_requests <= plugin->cur_requests)
2026  {
2028  "Maximum number of requests (%u) reached: "
2029  "cannot connect to peer `%s'\n",
2030  plugin->max_requests,
2031  GNUNET_i2s (&address->peer));
2032  return NULL;
2033  }
2034 
2035  /* Determine network location */
2036  net_type = GNUNET_NT_UNSPECIFIED;
2038  address->address_length,
2039  &res);
2040  if (GNUNET_SYSERR == res)
2041  return NULL;
2042  if (GNUNET_YES == res)
2043  {
2044  GNUNET_assert (NULL != sa);
2045  if (AF_INET == sa->sa_family)
2046  {
2047  salen = sizeof(struct sockaddr_in);
2048  }
2049  else if (AF_INET6 == sa->sa_family)
2050  {
2051  salen = sizeof(struct sockaddr_in6);
2052  }
2053  net_type = plugin->env->get_address_type (plugin->env->cls, sa, salen);
2054  GNUNET_free (sa);
2055  }
2056  else if (GNUNET_NO == res)
2057  {
2058  /* Cannot convert to sockaddr -> is external hostname */
2059  net_type = GNUNET_NT_WAN;
2060  }
2061  if (GNUNET_NT_UNSPECIFIED == net_type)
2062  {
2063  GNUNET_break (0);
2064  return NULL;
2065  }
2066 
2067  s = GNUNET_new (struct GNUNET_ATS_Session);
2068  s->plugin = plugin;
2070  s->scope = net_type;
2071 
2072  s->put.state = H_NOT_CONNECTED;
2076  s);
2078  "Created new session %p for `%s' address `%s''\n",
2079  s,
2081  s->address->address,
2082  s->address->address_length),
2083  GNUNET_i2s (&s->address->peer));
2084 
2085  /* add new session */
2086  (void) GNUNET_CONTAINER_multipeermap_put (plugin->sessions,
2087  &s->address->peer,
2088  s,
2090  /* initiate new connection */
2091  if (GNUNET_SYSERR == client_connect (s))
2092  {
2094  "Cannot connect to peer `%s' address `%s''\n",
2096  s->address->address,
2097  s->address->address_length),
2098  GNUNET_i2s (&s->address->peer));
2100  return NULL;
2101  }
2103  s,
2106  s,
2107  GNUNET_TRANSPORT_SS_UP); /* or handshake? */
2108  return s;
2109 }
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:99
@ 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:39
@ GNUNET_NT_WAN
Wide area network (i.e.
Definition: gnunet_nt_lib.h:58
@ GNUNET_NT_UNSPECIFIED
Category of last resort.
Definition: gnunet_nt_lib.h:43
@ 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_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, GNUNET_ATS_Session::put, res, GNUNET_ATS_Session::scope, 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 2119 of file plugin_transport_http_client.c.

2120 {
2121  curl_global_init (CURL_GLOBAL_ALL);
2122  plugin->curl_multi_handle = curl_multi_init ();
2123 
2124  if (NULL == plugin->curl_multi_handle)
2125  {
2127  _ (
2128  "Could not initialize curl multi handle, failed to start %s plugin!\n"),
2129  plugin->name);
2130  return GNUNET_SYSERR;
2131  }
2132  return GNUNET_OK;
2133 }

References _, GNUNET_ERROR_TYPE_ERROR, GNUNET_OK, GNUNET_SYSERR, LOG, 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 2149 of file plugin_transport_http_client.c.

2152 {
2153  /* A HTTP/S client does not have any valid address so:*/
2154  return GNUNET_NO;
2155 }

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 2165 of file plugin_transport_http_client.c.

2166 {
2167  struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
2168  struct HTTP_Client_Plugin *plugin = api->cls;
2169 
2170  if (NULL == api->cls)
2171  {
2172  /* Stub shutdown */
2173  GNUNET_free (api);
2174  return NULL;
2175  }
2177  _ ("Shutting down plugin `%s'\n"),
2178  plugin->name);
2181  plugin);
2182  if (NULL != plugin->client_perform_task)
2183  {
2184  GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
2185  plugin->client_perform_task = NULL;
2186  }
2187  if (NULL != plugin->curl_multi_handle)
2188  {
2189  curl_multi_cleanup (plugin->curl_multi_handle);
2190  plugin->curl_multi_handle = NULL;
2191  }
2192  curl_global_cleanup ();
2194  _ ("Shutdown for plugin `%s' complete\n"),
2195  plugin->name);
2197  GNUNET_free (plugin->proxy_hostname);
2198  GNUNET_free (plugin->proxy_username);
2199  GNUNET_free (plugin->proxy_password);
2200  GNUNET_free (plugin);
2201  GNUNET_free (api);
2202  return NULL;
2203 }
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 _, 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, and plugin.

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 2213 of file plugin_transport_http_client.c.

2214 {
2215  unsigned long long max_requests;
2216  char *proxy_type;
2217 
2218  /* Optional parameters */
2219  if (GNUNET_OK !=
2221  plugin->name,
2222  "MAX_CONNECTIONS",
2223  &max_requests))
2224  max_requests = 128;
2225  plugin->max_requests = max_requests;
2226 
2228  _ ("Maximum number of requests is %u\n"),
2229  plugin->max_requests);
2230 
2231  /* Read proxy configuration */
2232  if (GNUNET_OK ==
2234  plugin->name,
2235  "PROXY",
2236  &plugin->proxy_hostname))
2237  {
2239  "Found proxy host: `%s'\n",
2240  plugin->proxy_hostname);
2241  /* proxy username */
2242  if (GNUNET_OK ==
2244  plugin->name,
2245  "PROXY_USERNAME",
2246  &plugin->proxy_username))
2247  {
2249  "Found proxy username name: `%s'\n",
2250  plugin->proxy_username);
2251  }
2252 
2253  /* proxy password */
2254  if (GNUNET_OK ==
2256  plugin->name,
2257  "PROXY_PASSWORD",
2258  &plugin->proxy_password))
2259  {
2261  "Found proxy password name: `%s'\n",
2262  plugin->proxy_password);
2263  }
2264 
2265  /* proxy type */
2266  if (GNUNET_OK ==
2268  plugin->name,
2269  "PROXY_TYPE",
2270  &proxy_type))
2271  {
2273 
2274  if (0 == strcmp (proxy_type, "HTTP"))
2275  plugin->proxytype = CURLPROXY_HTTP;
2276  else if (0 == strcmp (proxy_type, "SOCKS4"))
2277  plugin->proxytype = CURLPROXY_SOCKS4;
2278  else if (0 == strcmp (proxy_type, "SOCKS5"))
2279  plugin->proxytype = CURLPROXY_SOCKS5;
2280  else if (0 == strcmp (proxy_type, "SOCKS4A"))
2281  plugin->proxytype = CURLPROXY_SOCKS4A;
2282  else if (0 == strcmp (proxy_type, "SOCKS5_HOSTNAME "))
2283  plugin->proxytype = CURLPROXY_SOCKS5_HOSTNAME;
2284  else
2285  {
2287  _ (
2288  "Invalid proxy type: `%s', disabling proxy! Check configuration!\n"),
2289  proxy_type);
2290 
2292  GNUNET_free (plugin->proxy_hostname);
2293  plugin->proxy_hostname = NULL;
2294  GNUNET_free (plugin->proxy_username);
2295  plugin->proxy_username = NULL;
2296  GNUNET_free (plugin->proxy_password);
2297  plugin->proxy_password = NULL;
2298 
2299  return GNUNET_SYSERR;
2300  }
2301 
2303  "Found proxy type: `%s'\n",
2304  proxy_type);
2305  }
2306 
2307  /* proxy http tunneling */
2308  plugin->proxy_use_httpproxytunnel
2310  plugin->name,
2311  "PROXY_HTTP_TUNNELING");
2312  if (GNUNET_SYSERR == plugin->proxy_use_httpproxytunnel)
2313  plugin->proxy_use_httpproxytunnel = GNUNET_NO;
2314 
2316  }
2317 
2318  /* Should we emulate an XHR client for testing? */
2319  plugin->emulate_xhr
2321  plugin->name,
2322  "EMULATE_XHR");
2323  return GNUNET_OK;
2324 }
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:471

References _, 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, 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 2336 of file plugin_transport_http_client.c.

2339 {
2341  addr,
2342  addrlen);
2343 }
#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 2356 of file plugin_transport_http_client.c.

2360 {
2362 }

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 2376 of file plugin_transport_http_client.c.

2380 {
2383  "New inbound delay %s\n",
2385  GNUNET_NO));
2386  if (s->recv_wakeup_task != NULL)
2387  {
2389  s->recv_wakeup_task
2391  &client_wake_up,
2392  s);
2393  }
2394 }

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 2407 of file plugin_transport_http_client.c.

2410 {
2411  struct HTTP_Client_Plugin *plugin = cls;
2412  struct GNUNET_ATS_Session *session = value;
2413 
2415  session,
2418  session,
2419  GNUNET_TRANSPORT_SS_UP); /* FIXME: or handshake? */
2420  return GNUNET_OK;
2421 }

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 2437 of file plugin_transport_http_client.c.

2440 {
2441  struct HTTP_Client_Plugin *plugin = cls;
2442 
2443  plugin->sic = sic;
2444  plugin->sic_cls = sic_cls;
2445  if (NULL != sic)
2446  {
2449  plugin);
2450  /* signal end of first iteration */
2451  sic (sic_cls, NULL, NULL);
2452  }
2453 }
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(), HTTP_Client_Plugin::sic, and HTTP_Client_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 2460 of file plugin_transport_http_client.c.

2461 {
2464  struct HTTP_Client_Plugin *plugin;
2465 
2466  if (NULL == env->receive)
2467  {
2468  /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
2469  initialize the plugin or the API */
2471  api->cls = NULL;
2475  return api;
2476  }
2477 
2479  plugin->env = env;
2481  GNUNET_YES);
2483  api->cls = plugin;
2484  api->send = &http_client_plugin_send;
2498 #if BUILD_HTTPS
2499  plugin->name = "transport-https_client";
2500  plugin->protocol = "https";
2501 #else
2502  plugin->name = "transport-http_client";
2503  plugin->protocol = "http";
2504 #endif
2505  plugin->last_tag = 1;
2506 
2508  {
2510  return NULL;
2511  }
2512 
2513  /* Start client */
2515  {
2517  return NULL;
2518  }
2519  return api;
2520 }
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, 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(), LIBGNUNET_PLUGIN_TRANSPORT_DONE, plugin, GNUNET_TRANSPORT_PluginFunctions::query_keepalive_factor, GNUNET_TRANSPORT_PluginFunctions::send, 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: