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

HTTP/S client transport plugin. More...

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

Go to the source code of this file.

Data Structures

struct  HTTP_Message
 Message to send using http. More...
 
struct  RequestHandle
 The request handle. More...
 
struct  GNUNET_ATS_Session
 Information about ongoing sessions of the transport client. 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   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
 
#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"

◆ HTTP_STAT_STR_CONNECTIONS

#define HTTP_STAT_STR_CONNECTIONS   "# HTTP client connections"

◆ LIBGNUNET_PLUGIN_TRANSPORT_INIT

#define LIBGNUNET_PLUGIN_TRANSPORT_INIT   libgnunet_plugin_transport_http_client_init

Definition at line 36 of file plugin_transport_http_client.c.

◆ LIBGNUNET_PLUGIN_TRANSPORT_DONE

#define LIBGNUNET_PLUGIN_TRANSPORT_DONE   libgnunet_plugin_transport_http_client_done

◆ VERBOSE_CURL

#define VERBOSE_CURL   GNUNET_NO

Definition at line 40 of file plugin_transport_http_client.c.

◆ PUT_DISCONNECT_TIMEOUT

#define PUT_DISCONNECT_TIMEOUT   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)

Definition at line 42 of file plugin_transport_http_client.c.

Referenced by client_send_cb().

◆ ENABLE_PUT

#define ENABLE_PUT   GNUNET_YES

Definition at line 44 of file plugin_transport_http_client.c.

◆ ENABLE_GET

#define ENABLE_GET   GNUNET_YES

Definition at line 45 of file plugin_transport_http_client.c.

◆ LOG

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

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

67 {
72 
77 
81  H_PAUSED,
82 
87 
92 
97 
102 };
Paused, nothing to send.
Temporarily disconnected.
Just created, not yet connected.
Temporary disconnect in progress due to inactivity.
Send request while temporary disconnect, reconnect.

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

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

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

842 {
843  struct HTTP_Client_Plugin *plugin = cls;
844 
846  "Session %p: notifying transport about ending session\n",
847  s);
848  plugin->env->session_end (plugin->env->cls,
849  s->address,
850  s);
852 
853  /* Re-schedule since handles have changed */
854  if (NULL != plugin->client_perform_task)
855  {
857  plugin->client_perform_task = NULL;
858  }
859  client_schedule (plugin, GNUNET_YES);
860 
861  return GNUNET_OK;
862 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GNUNET_HELLO_Address * address
Address.
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
GNUNET_TRANSPORT_SessionEnd session_end
Function that must be called by the plugin when a non-NULL session handle stops being valid (is destr...
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
void * cls
Closure for the various callbacks.
static int client_schedule(struct HTTP_Client_Plugin *plugin, int now)
Function setting up file descriptors and scheduling task to run.
Encapsulation of all of the state of the plugin.
struct GNUNET_SCHEDULER_Task * client_perform_task
curl perform task
#define GNUNET_YES
Definition: gnunet_common.h:80
#define LOG(kind,...)
static void client_delete_session(struct GNUNET_ATS_Session *s)
Delete session s.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
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 409 of file plugin_transport_http_client.c.

References GNUNET_ATS_Session::address, GNUNET_TRANSPORT_SessionInfo::address, GNUNET_ATS_Session::bytes_in_queue, GNUNET_NO, GNUNET_TRANSPORT_SessionInfo::is_inbound, GNUNET_ATS_Session::msgs_in_queue, GNUNET_ATS_Session::next_receive, GNUNET_TRANSPORT_SessionInfo::num_bytes_pending, GNUNET_TRANSPORT_SessionInfo::num_msg_pending, GNUNET_TRANSPORT_SessionInfo::receive_delay, GNUNET_TRANSPORT_SessionInfo::session_timeout, HTTP_Client_Plugin::sic, HTTP_Client_Plugin::sic_cls, state, GNUNET_TRANSPORT_SessionInfo::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(), send_session_info_iter(), and template_plugin_update_session_timeout().

412 {
413  struct GNUNET_TRANSPORT_SessionInfo info;
414 
415  if (NULL == plugin->sic)
416  return;
417  memset (&info, 0, sizeof (info));
418  info.state = state;
419  info.is_inbound = GNUNET_NO;
420  info.num_msg_pending = session->msgs_in_queue;
421  info.num_bytes_pending = session->bytes_in_queue;
422  info.receive_delay = session->next_receive;
423  info.session_timeout = session->timeout;
424  info.address = session->address;
425  plugin->sic (plugin->sic_cls,
426  session,
427  &info);
428 }
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.
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GNUNET_HELLO_Address * address
Address.
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.
enum State state
current state of profiling
GNUNET_TRANSPORT_SessionInfoCallback sic
Function to call about session status changes.
void * sic_cls
Closure for sic.
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 437 of file plugin_transport_http_client.c.

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

Referenced by http_client_plugin_get_session(), and http_client_plugin_session_disconnect().

438 {
439  struct HTTP_Client_Plugin *plugin = s->plugin;
440  struct HTTP_Message *pos;
441  struct HTTP_Message *next;
442  CURLMcode mret;
443 
444  if (NULL != s->timeout_task)
445  {
447  s->timeout_task = NULL;
449  }
450  if (NULL != s->put_disconnect_task)
451  {
453  s->put_disconnect_task = NULL;
454  }
455  if (NULL != s->recv_wakeup_task)
456  {
458  s->recv_wakeup_task = NULL;
459  }
462  &s->address->peer,
463  s));
464  if (NULL != s->put.easyhandle)
465  {
467  "Session %p/request %p: disconnecting PUT request to peer `%s'\n",
468  s,
469  s->put.easyhandle,
470  GNUNET_i2s (&s->address->peer));
471 
472  /* remove curl handle from multi handle */
473  mret = curl_multi_remove_handle (plugin->curl_multi_handle,
474  s->put.easyhandle);
475  GNUNET_break (CURLM_OK == mret);
476  curl_easy_cleanup (s->put.easyhandle);
477  GNUNET_assert (plugin->cur_requests > 0);
478  plugin->cur_requests--;
479  s->put.easyhandle = NULL;
480  }
481  if (NULL != s->get.easyhandle)
482  {
484  "Session %p/request %p: disconnecting GET request to peer `%s'\n",
485  s, s->get.easyhandle,
486  GNUNET_i2s (&s->address->peer));
487  /* remove curl handle from multi handle */
488  mret = curl_multi_remove_handle (plugin->curl_multi_handle,
489  s->get.easyhandle);
490  GNUNET_break (CURLM_OK == mret);
491  curl_easy_cleanup (s->get.easyhandle);
492  GNUNET_assert (plugin->cur_requests > 0);
493  plugin->cur_requests--;
494  s->get.easyhandle = NULL;
495  }
496 
497  GNUNET_STATISTICS_set (plugin->env->stats,
499  plugin->cur_requests,
500  GNUNET_NO);
501  next = s->msg_head;
502  while (NULL != (pos = next))
503  {
504  next = pos->next;
506  s->msg_tail,
507  pos);
508  GNUNET_assert (0 < s->msgs_in_queue);
509  s->msgs_in_queue--;
510  GNUNET_assert (pos->size <= s->bytes_in_queue);
511  s->bytes_in_queue -= pos->size;
512  if (NULL != pos->transmit_cont)
513  pos->transmit_cont (pos->transmit_cont_cls,
514  &s->address->peer,
516  pos->size,
517  pos->pos + s->overhead);
518  s->overhead = 0;
519  GNUNET_free (pos);
520  }
521  GNUNET_assert (0 == s->msgs_in_queue);
522  GNUNET_assert (0 == s->bytes_in_queue);
523  notify_session_monitor (plugin,
524  s,
526  if (NULL != s->msg_tk)
527  {
529  s->msg_tk = NULL;
530  }
532  GNUNET_free (s->url);
533  GNUNET_free (s);
534 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
Session is being torn down and about to disappear.
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
struct GNUNET_SCHEDULER_Task * recv_wakeup_task
Task to wake up client receive handle when receiving is allowed again.
unsigned int msgs_in_queue
Number of messages waiting for transmission to this peer.
struct GNUNET_SCHEDULER_Task * timeout_task
Session timeout task.
struct HTTP_Message * msg_tail
previous pointer for double linked list
struct Plugin * plugin
Pointer to the global plugin struct.
size_t pos
amount of data already sent
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct RequestHandle put
Handle for the HTTP PUT request.
Message to send using http.
struct GNUNET_SERVER_MessageStreamTokenizer * msg_tk
Message stream tokenizer for incoming data.
struct HTTP_Message * next
next pointer for double linked list
struct GNUNET_TIME_Absolute timeout
When does this session time out.
int GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GNUNET_HELLO_Address * address
Address.
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
struct RequestHandle get
Handle for the HTTP GET request.
struct HTTP_Message * msg_head
next pointer for double linked list
struct GNUNET_SCHEDULER_Task * put_disconnect_task
Session timeout task.
unsigned long long bytes_in_queue
Number of bytes waiting for transmission to this peer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void * transmit_cont_cls
Closure for transmit_cont.
GNUNET_TRANSPORT_TransmitContinuation transmit_cont
Continuation function to call once the transmission buffer has again space available.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
static void notify_session_monitor(struct HTTP_Client_Plugin *plugin, struct GNUNET_ATS_Session *session, enum GNUNET_TRANSPORT_SessionState state)
If a session monitor is attached, notify it about the new session state.
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
Definition: mst.c:413
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
size_t size
buffer length
struct GNUNET_CONTAINER_MultiPeerMap * sessions
Open sessions.
char * url
The URL to connect to.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct GNUNET_PeerIdentity peer
For which peer is this an address?
Encapsulation of all of the state of the plugin.
unsigned int cur_requests
Current number of sockets the plugin can use Each http connections are two requests.
#define HTTP_STAT_STR_CONNECTIONS
CURLM * curl_multi_handle
cURL Multihandle
struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
size_t overhead
Outbound overhead due to HTTP connection Add to next message of this session when calling callback...
#define LOG(kind,...)
CURL * easyhandle
The curl easy handle.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_HELLO_address_free(addr)
Free an address.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
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 543 of file plugin_transport_http_client.c.

References client_run(), 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().

544 {
545  GNUNET_assert (NULL != s->timeout_task);
547 }
struct GNUNET_SCHEDULER_Task * timeout_task
Session timeout task.
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:245
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_TIME_Absolute timeout
When does this session time out.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don&#39;t receive messages from the peer...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_run()

static void client_run ( void *  cls)
static

Task performing curl operations.

Parameters
clsplugin as closure
tcgnunet scheduler task context
clsplugin as closure

Definition at line 1289 of file plugin_transport_http_client.c.

References _, GNUNET_ATS_Session::address, address, client_connect_get(), client_connect_put(), HTTP_Client_Plugin::client_perform_task, client_schedule(), HTTP_Client_Plugin::cur_requests, HTTP_Client_Plugin::curl_multi_handle, RequestHandle::easyhandle, HTTP_Client_Plugin::emulate_xhr, HTTP_Client_Plugin::env, GNUNET_ATS_Session::get, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_log, 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, ret, RequestHandle::s, RequestHandle::state, GNUNET_TRANSPORT_PluginEnvironment::stats, and GNUNET_ATS_Session::url.

Referenced by client_connect(), client_reschedule_session_timeout(), and client_schedule().

1290 {
1291  struct HTTP_Client_Plugin *plugin = cls;
1292  int running;
1293  long http_statuscode;
1294  CURLMcode mret;
1295  CURLMsg *msg;
1296  int put_request; /* GNUNET_YES if easy handle is put, GNUNET_NO for get */
1297  int msgs_left;
1298 
1299  plugin->client_perform_task = NULL;
1300  /* While data are available or timeouts occured */
1301  do
1302  {
1303  running = 0;
1304  /* Perform operations for all handles */
1305  mret = curl_multi_perform (plugin->curl_multi_handle, &running);
1306 
1307  /* Get additional information for all handles */
1308  while (NULL != (msg = curl_multi_info_read (plugin->curl_multi_handle, &msgs_left)))
1309  {
1310  CURL *easy_h = msg->easy_handle;
1311  struct GNUNET_ATS_Session *s = NULL;
1312  char *d = NULL; /* curl requires 'd' to be a 'char *' */
1313 
1314  GNUNET_assert (NULL != easy_h);
1315 
1316  /* Obtain session from easy handle */
1317  GNUNET_assert (CURLE_OK == curl_easy_getinfo (easy_h, CURLINFO_PRIVATE, &d));
1318  s = (struct GNUNET_ATS_Session *) d;
1319  GNUNET_assert (NULL != s);
1320 
1321  if (msg->msg != CURLMSG_DONE)
1322  continue; /* This should not happen */
1323 
1324  /* Get HTTP response code */
1325  GNUNET_break (CURLE_OK == curl_easy_getinfo (easy_h,
1326  CURLINFO_RESPONSE_CODE, &http_statuscode));
1327 
1328  if (easy_h == s->put.easyhandle)
1329  put_request = GNUNET_YES;
1330  else
1331  put_request = GNUNET_NO;
1332 
1333  /* Log status of terminated request */
1334  if ((0 != msg->data.result) || (http_statuscode != 200))
1336  "Session %p/request %p: %s request to `%s' ended with status %i reason %i: `%s'\n",
1337  s, msg->easy_handle,
1338  (GNUNET_YES == put_request) ? "PUT" : "GET",
1339  GNUNET_i2s (&s->address->peer),
1340  http_statuscode,
1341  msg->data.result,
1342  curl_easy_strerror (msg->data.result));
1343  else
1345  "Session %p/request %p: %s request to `%s' ended normal\n",
1346  s, msg->easy_handle,
1347  (GNUNET_YES == put_request) ? "PUT" : "GET",
1348  GNUNET_i2s (&s->address->peer));
1349 
1350  /* Remove easy handle from multi handle */
1351  curl_multi_remove_handle (plugin->curl_multi_handle, easy_h);
1352 
1353  /* Clean up easy handle */
1354  curl_easy_cleanup (easy_h);
1355 
1356  /* Remove information */
1357  GNUNET_assert (plugin->cur_requests > 0);
1358  plugin->cur_requests--;
1360  "%s request to %s done, number of requests decreased to %u\n",
1361  (GNUNET_YES == put_request) ? "PUT" : "GET",
1362  s->url,
1363  plugin->cur_requests);
1364 
1365  if (GNUNET_YES == put_request)
1366  {
1367  /* Clean up a PUT request */
1368  s->put.easyhandle = NULL;
1369  s->put.s = NULL;
1370 
1371  switch (s->put.state) {
1372  case H_NOT_CONNECTED:
1373  case H_DISCONNECTED:
1374  case H_TMP_DISCONNECTED:
1375  /* This must not happen */
1376  GNUNET_break (0);
1377  break;
1379  /* Transport called send while disconnect in progess, reconnect */
1380  if (GNUNET_SYSERR == client_connect_put (s))
1381  {
1382  /* Reconnect failed, disconnect session */
1384  }
1385  break;
1386  case H_TMP_DISCONNECTING:
1387  /* PUT gets temporarily disconnected */
1389  break;
1390  case H_PAUSED:
1391  case H_CONNECTED:
1392  /* PUT gets permanently disconnected */
1393  s->put.state = H_DISCONNECTED;
1395  break;
1396  default:
1397  GNUNET_break (0);
1398  break;
1399  }
1400  }
1401  else if (GNUNET_NO == put_request)
1402  {
1403  /* Clean up a GET request */
1404  s->get.easyhandle = NULL;
1405  s->get.s = NULL;
1406 
1407  /* If we are emulating an XHR client we need to make another GET
1408  * request.
1409  */
1410  if (GNUNET_YES == plugin->emulate_xhr)
1411  {
1412  if (GNUNET_SYSERR == client_connect_get (s))
1414  }
1415  else
1416  {
1417  /* GET request was terminated, so disconnect session */
1419  }
1420  }
1421  else
1422  GNUNET_break (0); /* Must not happen */
1423 
1424  GNUNET_STATISTICS_set (plugin->env->stats,
1426  plugin->cur_requests,
1427  GNUNET_NO);
1428  }
1429  }
1430  while (mret == CURLM_CALL_MULTI_PERFORM);
1431  client_schedule (plugin, GNUNET_NO);
1432 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
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.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct RequestHandle put
Handle for the HTTP PUT request.
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GNUNET_HELLO_Address * address
Address.
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
struct RequestHandle get
Handle for the HTTP GET request.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Paused, nothing to send.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
Temporarily disconnected.
static int client_schedule(struct HTTP_Client_Plugin *plugin, int now)
Function setting up file descriptors and scheduling task to run.
Information about ongoing sessions of the transport client.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
static int client_connect_put(struct GNUNET_ATS_Session *s)
Connect a HTTP put request.
int state
The processing state.
char * url
The URL to connect to.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
int emulate_xhr
Should we emulate an XHR client for testing?
struct GNUNET_PeerIdentity peer
For which peer is this an address?
Just created, not yet connected.
Encapsulation of all of the state of the plugin.
struct GNUNET_SCHEDULER_Task * client_perform_task
curl perform task
unsigned int cur_requests
Current number of sockets the plugin can use Each http connections are two requests.
#define HTTP_STAT_STR_CONNECTIONS
CURLM * curl_multi_handle
cURL Multihandle
struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
#define GNUNET_YES
Definition: gnunet_common.h:80
#define LOG(kind,...)
Temporary disconnect in progress due to inactivity.
struct GNUNET_ATS_Session * s
The related session.
CURL * easyhandle
The curl easy handle.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Send request while temporary disconnect, reconnect.
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 568 of file plugin_transport_http_client.c.

References _, ch, client_connect_get(), client_connect_put(), HTTP_Client_Plugin::client_perform_task, client_run(), curl, HTTP_Client_Plugin::curl_multi_handle, data, RequestHandle::easyhandle, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_memcpy, 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, GNUNET_ATS_Session::overhead, RequestHandle::s, HTTP_Message::size, and type.

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

570 {
571  fd_set rs;
572  fd_set ws;
573  fd_set es;
574  int max;
575  struct GNUNET_NETWORK_FDSet *grs;
576  struct GNUNET_NETWORK_FDSet *gws;
577  long to;
578  CURLMcode mret;
580 
581  /* Cancel previous scheduled task */
582  if (plugin->client_perform_task != NULL)
583  {
585  plugin->client_perform_task = NULL;
586  }
587  max = -1;
588  FD_ZERO (&rs);
589  FD_ZERO (&ws);
590  FD_ZERO (&es);
591  mret = curl_multi_fdset (plugin->curl_multi_handle, &rs, &ws, &es, &max);
592  if (mret != CURLM_OK)
593  {
595  _("%s failed at %s:%d: `%s'\n"),
596  "curl_multi_fdset",
597  __FILE__,
598  __LINE__,
599  curl_multi_strerror (mret));
600  return GNUNET_SYSERR;
601  }
602  mret = curl_multi_timeout (plugin->curl_multi_handle, &to);
603  if (-1 == to)
605  else
607  if (now == GNUNET_YES)
609 
610  if (CURLM_OK != mret)
611  {
613  _("%s failed at %s:%d: `%s'\n"),
614  "curl_multi_timeout", __FILE__, __LINE__,
615  curl_multi_strerror (mret));
616  return GNUNET_SYSERR;
617  }
618 
621  GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
622  GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
623 
624  /* Schedule task to run when select is ready to read or write */
625  plugin->client_perform_task =
627  timeout, grs, gws,
628  &client_run, plugin);
631  return GNUNET_OK;
632 }
#define GNUNET_TIME_UNIT_SECONDS
One second.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static void client_run(void *cls)
Task performing curl operations.
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:1308
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1554
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1538
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:114
collection of IO descriptors
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_select(enum GNUNET_SCHEDULER_Priority prio, struct GNUNET_TIME_Relative delay, const struct GNUNET_NETWORK_FDSet *rs, const struct GNUNET_NETWORK_FDSet *ws, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when any of the specified file descriptor set...
Definition: scheduler.c:1829
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:439
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct GNUNET_SCHEDULER_Task * client_perform_task
curl perform task
CURLM * curl_multi_handle
cURL Multihandle
#define GNUNET_YES
Definition: gnunet_common.h:80
#define LOG(kind,...)
Run with the default priority (normal P2P operations).
Time for relative time used by GNUnet, in microseconds.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
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 1498 of file plugin_transport_http_client.c.

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(), client_run(), and client_schedule().

1499 {
1500  CURLMcode mret;
1501  struct HttpAddress *ha;
1502  uint32_t options;
1503 
1504  ha = (struct HttpAddress *) s->address->address;
1505  options = ntohl (ha->options);
1506  /* create get request */
1507  s->get.easyhandle = curl_easy_init ();
1508  s->get.s = s;
1509  if (0 != (options & HTTP_OPTIONS_TCP_STEALTH))
1510  {
1511 #ifdef TCP_STEALTH
1512  curl_easy_setopt (s->get.easyhandle,
1513  CURLOPT_OPENSOCKETFUNCTION,
1514  &open_tcp_stealth_socket_cb);
1515  curl_easy_setopt (s->get.easyhandle,
1516  CURLOPT_OPENSOCKETDATA,
1517  s);
1518 #else
1520  "Cannot connect, TCP STEALTH needed and not supported by kernel.\n");
1521  curl_easy_cleanup (s->get.easyhandle);
1522  s->get.easyhandle = NULL;
1523  s->get.s = NULL;
1524  return GNUNET_SYSERR;
1525 #endif
1526  }
1527 
1528 #if VERBOSE_CURL
1529  curl_easy_setopt (s->get.easyhandle,
1530  CURLOPT_VERBOSE,
1531  1L);
1532  curl_easy_setopt (s->get.easyhandle,
1533  CURLOPT_DEBUGFUNCTION,
1534  &client_log);
1535  curl_easy_setopt (s->get.easyhandle,
1536  CURLOPT_DEBUGDATA,
1537  &s->get);
1538 #endif
1539 #if BUILD_HTTPS
1540  curl_easy_setopt (s->get.easyhandle, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
1541  {
1543  (options & HTTP_OPTIONS_VERIFY_CERTIFICATE))
1544  {
1545  curl_easy_setopt (s->get.easyhandle,
1546  CURLOPT_SSL_VERIFYPEER, 1L);
1547  curl_easy_setopt (s->get.easyhandle,
1548  CURLOPT_SSL_VERIFYHOST,
1549  2L);
1550  }
1551  else
1552  {
1553  curl_easy_setopt (s->get.easyhandle,
1554  CURLOPT_SSL_VERIFYPEER,
1555  0L);
1556  curl_easy_setopt (s->get.easyhandle,
1557  CURLOPT_SSL_VERIFYHOST,
1558  0L);
1559  }
1560  }
1561  curl_easy_setopt (s->get.easyhandle,
1562  CURLOPT_PROTOCOLS,
1563  CURLPROTO_HTTPS);
1564  curl_easy_setopt (s->get.easyhandle,
1565  CURLOPT_REDIR_PROTOCOLS,
1566  CURLPROTO_HTTPS);
1567 #else
1568  curl_easy_setopt (s->get.easyhandle,
1569  CURLOPT_PROTOCOLS,
1570  CURLPROTO_HTTP);
1571  curl_easy_setopt (s->get.easyhandle,
1572  CURLOPT_REDIR_PROTOCOLS,
1573  CURLPROTO_HTTP);
1574 #endif
1575 
1576  if (NULL != s->plugin->proxy_hostname)
1577  {
1578  curl_easy_setopt (s->get.easyhandle,
1579  CURLOPT_PROXY,
1580  s->plugin->proxy_hostname);
1581  curl_easy_setopt (s->get.easyhandle,
1582  CURLOPT_PROXYTYPE,
1583  s->plugin->proxytype);
1584  if (NULL != s->plugin->proxy_username)
1585  curl_easy_setopt (s->get.easyhandle,
1586  CURLOPT_PROXYUSERNAME,
1587  s->plugin->proxy_username);
1588  if (NULL != s->plugin->proxy_password)
1589  curl_easy_setopt (s->get.easyhandle,
1590  CURLOPT_PROXYPASSWORD,
1591  s->plugin->proxy_password);
1592  if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel)
1593  curl_easy_setopt (s->get.easyhandle,
1594  CURLOPT_HTTPPROXYTUNNEL,
1595  s->plugin->proxy_use_httpproxytunnel);
1596  }
1597 
1598  if (GNUNET_YES == s->plugin->emulate_xhr)
1599  {
1600  char *url;
1601 
1602  GNUNET_asprintf (&url,
1603  "%s,1",
1604  s->url);
1605  curl_easy_setopt (s->get.easyhandle,
1606  CURLOPT_URL,
1607  url);
1608  GNUNET_free(url);
1609  }
1610  else
1611  {
1612  curl_easy_setopt (s->get.easyhandle,
1613  CURLOPT_URL,
1614  s->url);
1615  }
1616  curl_easy_setopt (s->get.easyhandle,
1617  CURLOPT_READFUNCTION,
1618  &client_send_cb);
1619  curl_easy_setopt (s->get.easyhandle,
1620  CURLOPT_READDATA,
1621  s);
1622  curl_easy_setopt (s->get.easyhandle,
1623  CURLOPT_WRITEFUNCTION,
1624  &client_receive);
1625  curl_easy_setopt (s->get.easyhandle,
1626  CURLOPT_WRITEDATA,
1627  s);
1628  /* No timeout by default, timeout done with session timeout */
1629  curl_easy_setopt (s->get.easyhandle,
1630  CURLOPT_TIMEOUT,
1631  0L);
1632  curl_easy_setopt (s->get.easyhandle,
1633  CURLOPT_PRIVATE, s);
1634  curl_easy_setopt (s->get.easyhandle,
1635  CURLOPT_CONNECTTIMEOUT_MS,
1636  (long) (HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL));
1637  curl_easy_setopt (s->get.easyhandle, CURLOPT_BUFFERSIZE,
1639 #if CURL_TCP_NODELAY
1640  curl_easy_setopt (ps->recv_endpoint,
1641  CURLOPT_TCP_NODELAY,
1642  1L);
1643 #endif
1644  curl_easy_setopt (s->get.easyhandle,
1645  CURLOPT_FOLLOWLOCATION,
1646  0L);
1647 
1648  mret = curl_multi_add_handle (s->plugin->curl_multi_handle,
1649  s->get.easyhandle);
1650  if (CURLM_OK != mret)
1651  {
1653  "Session %p : Failed to add GET handle to multihandle: `%s'\n",
1654  s,
1655  curl_multi_strerror (mret));
1656  curl_easy_cleanup (s->get.easyhandle);
1657  s->get.easyhandle = NULL;
1658  s->get.s = NULL;
1659  GNUNET_break (0);
1660  return GNUNET_SYSERR;
1661  }
1662  s->plugin->cur_requests++;
1664  "GET request `%s' established, number of requests increased to %u\n",
1665  s->url,
1666  s->plugin->cur_requests);
1667  return GNUNET_OK;
1668 }
uint32_t options
Address options see enum HttpAddressOptions
const void * address
Binary representation of the address (plugin-specific).
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct Plugin * plugin
Pointer to the global plugin struct.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GNUNET_HELLO_Address * address
Address.
struct RequestHandle get
Handle for the HTTP GET request.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
char * url
The URL to connect to.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT
static size_t client_receive(void *stream, size_t size, size_t nmemb, void *cls)
Callback method used with libcurl when data for a GET request are received.
Enable TCP Stealth-style port knocking.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
#define GNUNET_log(kind,...)
Verify X509 server certificate, it should be valid.
#define GNUNET_YES
Definition: gnunet_common.h:80
#define LOG(kind,...)
struct GNUNET_ATS_Session * s
The related session.
CURL * easyhandle
The curl easy handle.
HTTP addresses including a full URI.
#define GNUNET_free(ptr)
Wrapper around free.
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...
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
Parameters
sthe session to connect
Returns
GNUNET_SYSERR for hard failure, GNUNET_OK for ok

Definition at line 1678 of file plugin_transport_http_client.c.

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(), client_schedule(), and http_client_plugin_send().

1679 {
1680  CURLMcode mret;
1681  struct HttpAddress *ha;
1682  uint32_t options;
1683 
1684  ha = (struct HttpAddress *) s->address->address;
1685  options = ntohl (ha->options);
1686  /* create put request */
1688  "Session %p: Init PUT handle\n",
1689  s);
1690  s->put.easyhandle = curl_easy_init ();
1691  s->put.s = s;
1692 #if VERBOSE_CURL
1693  curl_easy_setopt (s->put.easyhandle,
1694  CURLOPT_VERBOSE,
1695  1L);
1696  curl_easy_setopt (s->put.easyhandle,
1697  CURLOPT_DEBUGFUNCTION,
1698  &client_log);
1699  curl_easy_setopt (s->put.easyhandle,
1700  CURLOPT_DEBUGDATA,
1701  &s->put);
1702 #endif
1703  if (0 != (options & HTTP_OPTIONS_TCP_STEALTH))
1704  {
1705 #ifdef TCP_STEALTH
1706  curl_easy_setopt (s->put.easyhandle,
1707  CURLOPT_OPENSOCKETFUNCTION,
1708  &open_tcp_stealth_socket_cb);
1709  curl_easy_setopt (s->put.easyhandle,
1710  CURLOPT_OPENSOCKETDATA,
1711  s);
1712 #else
1714  "Cannot connect, TCP STEALTH needed and not supported by kernel.\n");
1715  curl_easy_cleanup (s->put.easyhandle);
1716  s->put.easyhandle = NULL;
1717  s->put.s = NULL;
1718  s->put.state = H_DISCONNECTED;
1719  return GNUNET_SYSERR;
1720 #endif
1721  }
1722 #if BUILD_HTTPS
1723  curl_easy_setopt (s->put.easyhandle,
1724  CURLOPT_SSLVERSION,
1725  CURL_SSLVERSION_TLSv1);
1726  {
1727  struct HttpAddress *ha;
1728  ha = (struct HttpAddress *) s->address->address;
1729 
1731  (ntohl (ha->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE))
1732  {
1733  curl_easy_setopt (s->put.easyhandle,
1734  CURLOPT_SSL_VERIFYPEER,
1735  1L);
1736  curl_easy_setopt (s->put.easyhandle,
1737  CURLOPT_SSL_VERIFYHOST,
1738  2L);
1739  }
1740  else
1741  {
1742  curl_easy_setopt (s->put.easyhandle,
1743  CURLOPT_SSL_VERIFYPEER,
1744  0L);
1745  curl_easy_setopt (s->put.easyhandle,
1746  CURLOPT_SSL_VERIFYHOST,
1747  0L);
1748  }
1749  }
1750  curl_easy_setopt (s->put.easyhandle,
1751  CURLOPT_PROTOCOLS,
1752  CURLPROTO_HTTPS);
1753  curl_easy_setopt (s->put.easyhandle,
1754  CURLOPT_REDIR_PROTOCOLS,
1755  CURLPROTO_HTTPS);
1756 #else
1757  curl_easy_setopt (s->put.easyhandle,
1758  CURLOPT_PROTOCOLS,
1759  CURLPROTO_HTTP);
1760  curl_easy_setopt (s->put.easyhandle,
1761  CURLOPT_REDIR_PROTOCOLS,
1762  CURLPROTO_HTTP);
1763 #endif
1764  if (NULL != s->plugin->proxy_hostname)
1765  {
1766  curl_easy_setopt (s->put.easyhandle,
1767  CURLOPT_PROXY,
1768  s->plugin->proxy_hostname);
1769  curl_easy_setopt (s->put.easyhandle,
1770  CURLOPT_PROXYTYPE,
1771  s->plugin->proxytype);
1772  if (NULL != s->plugin->proxy_username)
1773  curl_easy_setopt (s->put.easyhandle,
1774  CURLOPT_PROXYUSERNAME,
1775  s->plugin->proxy_username);
1776  if (NULL != s->plugin->proxy_password)
1777  curl_easy_setopt (s->put.easyhandle,
1778  CURLOPT_PROXYPASSWORD,
1779  s->plugin->proxy_password);
1780  if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel)
1781  curl_easy_setopt (s->put.easyhandle,
1782  CURLOPT_HTTPPROXYTUNNEL,
1783  s->plugin->proxy_use_httpproxytunnel);
1784  }
1785 
1786  curl_easy_setopt (s->put.easyhandle,
1787  CURLOPT_URL,
1788  s->url);
1789  curl_easy_setopt (s->put.easyhandle,
1790  CURLOPT_UPLOAD,
1791  1L);
1792  curl_easy_setopt (s->put.easyhandle,
1793  CURLOPT_READFUNCTION,
1794  &client_send_cb);
1795  curl_easy_setopt (s->put.easyhandle,
1796  CURLOPT_READDATA,
1797  s);
1798  curl_easy_setopt (s->put.easyhandle,
1799  CURLOPT_WRITEFUNCTION,
1801  curl_easy_setopt (s->put.easyhandle,
1802  CURLOPT_WRITEDATA,
1803  s);
1804  /* No timeout by default, timeout done with session timeout */
1805  curl_easy_setopt (s->put.easyhandle,
1806  CURLOPT_TIMEOUT,
1807  0L);
1808  curl_easy_setopt (s->put.easyhandle,
1809  CURLOPT_PRIVATE,
1810  s);
1811  curl_easy_setopt (s->put.easyhandle,
1812  CURLOPT_CONNECTTIMEOUT_MS,
1813  (long) (HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL));
1814  curl_easy_setopt (s->put.easyhandle, CURLOPT_BUFFERSIZE,
1816 #if CURL_TCP_NODELAY
1817  curl_easy_setopt (s->put.easyhandle, CURLOPT_TCP_NODELAY, 1);
1818 #endif
1819  mret = curl_multi_add_handle (s->plugin->curl_multi_handle,
1820  s->put.easyhandle);
1821  if (CURLM_OK != mret)
1822  {
1824  "Session %p : Failed to add PUT handle to multihandle: `%s'\n",
1825  s, curl_multi_strerror (mret));
1826  curl_easy_cleanup (s->put.easyhandle);
1827  s->put.easyhandle = NULL;
1828  s->put.s = NULL;
1829  s->put.state = H_DISCONNECTED;
1830  return GNUNET_SYSERR;
1831  }
1832  s->put.state = H_CONNECTED;
1833  s->plugin->cur_requests++;
1834 
1836  "PUT request `%s' established, number of requests increased to %u\n",
1837  s->url, s->plugin->cur_requests);
1838 
1839  return GNUNET_OK;
1840 }
uint32_t options
Address options see enum HttpAddressOptions
const void * address
Binary representation of the address (plugin-specific).
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct Plugin * plugin
Pointer to the global plugin struct.
struct RequestHandle put
Handle for the HTTP PUT request.
static size_t client_receive_put(void *stream, size_t size, size_t nmemb, void *cls)
Callback method used with libcurl when data for a PUT request are received.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GNUNET_HELLO_Address * address
Address.
int state
The processing state.
char * url
The URL to connect to.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT
Enable TCP Stealth-style port knocking.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
#define GNUNET_log(kind,...)
Verify X509 server certificate, it should be valid.
#define GNUNET_YES
Definition: gnunet_common.h:80
#define LOG(kind,...)
struct GNUNET_ATS_Session * s
The related session.
CURL * easyhandle
The curl easy handle.
HTTP addresses including a full URI.
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...
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 748 of file plugin_transport_http_client.c.

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

Referenced by libgnunet_plugin_transport_http_client_init().

756 {
757  struct HTTP_Client_Plugin *plugin = cls;
758  struct HTTP_Message *msg;
759  char *stat_txt;
760 
762  "Session %p/request %p: Sending message with %u to peer `%s' \n",
763  s,
764  s->put.easyhandle,
765  msgbuf_size,
766  GNUNET_i2s (&s->address->peer));
767 
768  /* create new message and schedule */
769  msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size);
770  msg->size = msgbuf_size;
771  msg->buf = (char *) &msg[1];
772  msg->transmit_cont = cont;
773  msg->transmit_cont_cls = cont_cls;
774  GNUNET_memcpy (msg->buf,
775  msgbuf,
776  msgbuf_size);
778  s->msg_tail,
779  msg);
780  s->msgs_in_queue++;
781  s->bytes_in_queue += msg->size;
782 
783  GNUNET_asprintf (&stat_txt,
784  "# bytes currently in %s_client buffers",
785  plugin->protocol);
787  stat_txt, msgbuf_size, GNUNET_NO);
788  GNUNET_free (stat_txt);
789  notify_session_monitor (plugin,
790  s,
792  if (H_TMP_DISCONNECTING == s->put.state)
793  {
794  /* PUT request is currently getting disconnected */
797  "Session %p/request %p: currently disconnecting, reconnecting immediately\n",
798  s,
799  s->put.easyhandle);
800  return msgbuf_size;
801  }
802  if (H_PAUSED == s->put.state)
803  {
804  /* PUT request was paused, unpause */
805  GNUNET_assert (s->put_disconnect_task != NULL);
807  s->put_disconnect_task = NULL;
809  "Session %p/request %p: unpausing request\n",
810  s, s->put.easyhandle);
811  s->put.state = H_CONNECTED;
812  if (NULL != s->put.easyhandle)
813  curl_easy_pause (s->put.easyhandle, CURLPAUSE_CONT);
814  }
815  else if (H_TMP_DISCONNECTED == s->put.state)
816  {
817  /* PUT request was disconnected, reconnect */
818  LOG (GNUNET_ERROR_TYPE_DEBUG, "Session %p: Reconnecting PUT request\n", s);
819  GNUNET_break (NULL == s->put.easyhandle);
821  {
822  /* Could not reconnect */
824  return GNUNET_SYSERR;
825  }
826  }
828  return msgbuf_size;
829 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static int http_client_plugin_session_disconnect(void *cls, struct GNUNET_ATS_Session *s)
Disconnect a session.
char * buf
buffer containing data to send
unsigned int msgs_in_queue
Number of messages waiting for transmission to this peer.
struct HTTP_Message * msg_tail
previous pointer for double linked list
struct Plugin * plugin
Pointer to the global plugin struct.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct RequestHandle put
Handle for the HTTP PUT request.
Message to send using http.
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GNUNET_HELLO_Address * address
Address.
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
struct HTTP_Message * msg_head
next pointer for double linked list
struct GNUNET_SCHEDULER_Task * put_disconnect_task
Session timeout task.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
unsigned long long bytes_in_queue
Number of bytes waiting for transmission to this peer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void * transmit_cont_cls
Closure for transmit_cont.
GNUNET_TRANSPORT_TransmitContinuation transmit_cont
Continuation function to call once the transmission buffer has again space available.
Paused, nothing to send.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
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.
Temporarily disconnected.
#define GNUNET_memcpy(dst, src, n)
static int client_schedule(struct HTTP_Client_Plugin *plugin, int now)
Function setting up file descriptors and scheduling task to run.
static int client_connect_put(struct GNUNET_ATS_Session *s)
Connect a HTTP put request.
int state
The processing state.
size_t size
buffer length
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
struct GNUNET_PeerIdentity peer
For which peer is this an address?
Encapsulation of all of the state of the plugin.
This is just an update about the session, the state did not change.
struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
#define GNUNET_YES
Definition: gnunet_common.h:80
#define LOG(kind,...)
Temporary disconnect in progress due to inactivity.
CURL * easyhandle
The curl easy handle.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Send request while temporary disconnect, reconnect.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
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 874 of file plugin_transport_http_client.c.

Referenced by libgnunet_plugin_transport_http_client_init().

875 {
876  return 3;
877 }
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 889 of file plugin_transport_http_client.c.

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().

892 {
893  struct HTTP_Client_Plugin *plugin = cls;
894  struct GNUNET_ATS_Session *session = value;
895 
896  http_client_plugin_session_disconnect (plugin, session);
897  return GNUNET_OK;
898 }
static int http_client_plugin_session_disconnect(void *cls, struct GNUNET_ATS_Session *s)
Disconnect a session.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
static char * value
Value of the record to add/remove.
Information about ongoing sessions of the transport client.
Encapsulation of all of the state of the plugin.
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 910 of file plugin_transport_http_client.c.

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

Referenced by libgnunet_plugin_transport_http_client_init().

912 {
913  struct HTTP_Client_Plugin *plugin = cls;
914 
916  "Transport tells me to disconnect `%s'\n",
917  GNUNET_i2s (target));
919  target,
921  plugin);
922 }
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
static int destroy_session_cb(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Callback to destroys all sessions on exit.
struct GNUNET_CONTAINER_MultiPeerMap * sessions
Open sessions.
Encapsulation of all of the state of the plugin.
#define LOG(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
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.
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 951 of file plugin_transport_http_client.c.

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().

954 {
955  struct GNUNET_ATS_SessionClientCtx *sc_ctx = cls;
956  struct GNUNET_ATS_Session *s = value;
957 
958  if (0 == GNUNET_HELLO_address_cmp (sc_ctx->address,
959  s->address))
960  {
961  sc_ctx->ret = s;
962  return GNUNET_NO;
963  }
964  return GNUNET_YES;
965 }
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GNUNET_HELLO_Address * address
Address.
const struct GNUNET_HELLO_Address * address
Address we are looking for.
int GNUNET_HELLO_address_cmp(const struct GNUNET_HELLO_Address *a1, const struct GNUNET_HELLO_Address *a2)
Compare two addresses.
Definition: address.c:130
static char * value
Value of the record to add/remove.
Information about ongoing sessions of the transport client.
Closure for session_lookup_client_by_address().
struct GNUNET_ATS_Session * ret
Session that was found.
#define GNUNET_YES
Definition: gnunet_common.h:80
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 976 of file plugin_transport_http_client.c.

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

Referenced by http_client_plugin_get_session().

978 {
979  struct GNUNET_ATS_SessionClientCtx sc_ctx;
980 
981  sc_ctx.address = address;
982  sc_ctx.ret = NULL;
985  &sc_ctx);
986  return sc_ctx.ret;
987 }
const struct GNUNET_HELLO_Address * address
Address we are looking for.
static int session_lookup_client_by_address(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Locate the seession object for a given address.
Closure for session_lookup_client_by_address().
struct GNUNET_CONTAINER_MultiPeerMap * sessions
Open sessions.
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 char * address
GNS address for this phone.
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 998 of file plugin_transport_http_client.c.

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().

999 {
1000  struct GNUNET_ATS_Session *s = cls;
1001 
1002  s->put_disconnect_task = NULL;
1004  "Session %p/request %p: will be disconnected due to no activity\n",
1005  s, s->put.easyhandle);
1007  if (NULL != s->put.easyhandle)
1008  curl_easy_pause (s->put.easyhandle,
1009  CURLPAUSE_CONT);
1011 }
struct Plugin * plugin
Pointer to the global plugin struct.
struct RequestHandle put
Handle for the HTTP PUT request.
struct GNUNET_SCHEDULER_Task * put_disconnect_task
Session timeout task.
static int client_schedule(struct HTTP_Client_Plugin *plugin, int now)
Function setting up file descriptors and scheduling task to run.
Information about ongoing sessions of the transport client.
int state
The processing state.
#define GNUNET_YES
Definition: gnunet_common.h:80
#define LOG(kind,...)
Temporary disconnect in progress due to inactivity.
CURL * easyhandle
The curl easy handle.
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 1025 of file plugin_transport_http_client.c.

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

Referenced by client_connect_get(), and client_connect_put().

1029 {
1030  struct GNUNET_ATS_Session *s = cls;
1031  struct HTTP_Client_Plugin *plugin = s->plugin;
1032  struct HTTP_Message *msg = s->msg_head;
1033  size_t len;
1034  char *stat_txt;
1035 
1036  if (H_TMP_DISCONNECTING == s->put.state)
1037  {
1039  "Session %p/request %p: disconnect due to inactivity\n",
1040  s, s->put.easyhandle);
1041  return 0;
1042  }
1043 
1044  if (NULL == msg)
1045  {
1046  if (GNUNET_YES == plugin->emulate_xhr)
1047  {
1049  "Session %p/request %p: PUT request finished\n",
1050  s,
1051  s->put.easyhandle);
1053  return 0;
1054  }
1055 
1056  /* We have nothing to send, so pause PUT request */
1058  "Session %p/request %p: nothing to send, suspending\n",
1059  s,
1060  s->put.easyhandle);
1064  s);
1065  s->put.state = H_PAUSED;
1066  return CURL_READFUNC_PAUSE;
1067  }
1068  /* data to send */
1069  GNUNET_assert (msg->pos < msg->size);
1070  /* calculate how much fits in buffer */
1071  len = GNUNET_MIN (msg->size - msg->pos,
1072  size * nmemb);
1073  GNUNET_memcpy (stream,
1074  &msg->buf[msg->pos],
1075  len);
1076  msg->pos += len;
1077  if (msg->pos == msg->size)
1078  {
1080  "Session %p/request %p: sent message with %u bytes sent, removing message from queue\n",
1081  s,
1082  s->put.easyhandle,
1083  msg->size,
1084  msg->pos);
1085  /* Calling transmit continuation */
1087  s->msg_tail,
1088  msg);
1089  GNUNET_assert (0 < s->msgs_in_queue);
1090  s->msgs_in_queue--;
1091  GNUNET_assert (msg->size <= s->bytes_in_queue);
1092  s->bytes_in_queue -= msg->size;
1093  if (NULL != msg->transmit_cont)
1094  msg->transmit_cont (msg->transmit_cont_cls,
1095  &s->address->peer,
1096  GNUNET_OK,
1097  msg->size,
1098  msg->size + s->overhead);
1099  s->overhead = 0;
1100  GNUNET_free (msg);
1101  }
1102  notify_session_monitor (plugin,
1103  s,
1105  GNUNET_asprintf (&stat_txt,
1106  "# bytes currently in %s_client buffers",
1107  plugin->protocol);
1109  stat_txt,
1110  - len,
1111  GNUNET_NO);
1112  GNUNET_free (stat_txt);
1113  GNUNET_asprintf (&stat_txt,
1114  "# bytes transmitted via %s_client",
1115  plugin->protocol);
1117  stat_txt,
1118  len,
1119  GNUNET_NO);
1120  GNUNET_free (stat_txt);
1121  return len;
1122 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
char * buf
buffer containing data to send
unsigned int msgs_in_queue
Number of messages waiting for transmission to this peer.
struct HTTP_Message * msg_tail
previous pointer for double linked list
struct Plugin * plugin
Pointer to the global plugin struct.
#define PUT_DISCONNECT_TIMEOUT
size_t pos
amount of data already sent
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct RequestHandle put
Handle for the HTTP PUT request.
Message to send using http.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GNUNET_HELLO_Address * address
Address.
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
struct HTTP_Message * msg_head
next pointer for double linked list
struct GNUNET_SCHEDULER_Task * put_disconnect_task
Session timeout task.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
unsigned long long bytes_in_queue
Number of bytes waiting for transmission to this peer.
void * transmit_cont_cls
Closure for transmit_cont.
GNUNET_TRANSPORT_TransmitContinuation transmit_cont
Continuation function to call once the transmission buffer has again space available.
Paused, nothing to send.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
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:1246
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.
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)...
#define GNUNET_memcpy(dst, src, n)
Information about ongoing sessions of the transport client.
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:83
int state
The processing state.
size_t size
buffer length
static unsigned int size
Size of the "table".
Definition: peer.c:67
int emulate_xhr
Should we emulate an XHR client for testing?
struct GNUNET_PeerIdentity peer
For which peer is this an address?
Encapsulation of all of the state of the plugin.
This is just an update about the session, the state did not change.
struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
size_t overhead
Outbound overhead due to HTTP connection Add to next message of this session when calling callback...
#define GNUNET_YES
Definition: gnunet_common.h:80
#define LOG(kind,...)
Temporary disconnect in progress due to inactivity.
CURL * easyhandle
The curl easy handle.
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
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 1131 of file plugin_transport_http_client.c.

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().

1132 {
1133  struct GNUNET_ATS_Session *s = cls;
1134 
1135  s->recv_wakeup_task = NULL;
1137  "Session %p/request %p: Waking up GET handle\n",
1138  s, s->get.easyhandle);
1139  if (H_PAUSED == s->put.state)
1140  {
1141  /* PUT request was paused, unpause */
1142  GNUNET_assert (s->put_disconnect_task != NULL);
1144  s->put_disconnect_task = NULL;
1145  s->put.state = H_CONNECTED;
1146  if (NULL != s->put.easyhandle)
1147  curl_easy_pause (s->put.easyhandle, CURLPAUSE_CONT);
1148  }
1149  if (NULL != s->get.easyhandle)
1150  curl_easy_pause (s->get.easyhandle, CURLPAUSE_CONT);
1151 }
struct GNUNET_SCHEDULER_Task * recv_wakeup_task
Task to wake up client receive handle when receiving is allowed again.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct RequestHandle put
Handle for the HTTP PUT request.
struct RequestHandle get
Handle for the HTTP GET request.
struct GNUNET_SCHEDULER_Task * put_disconnect_task
Session timeout task.
Paused, nothing to send.
Information about ongoing sessions of the transport client.
int state
The processing state.
#define LOG(kind,...)
CURL * easyhandle
The curl easy handle.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
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 1162 of file plugin_transport_http_client.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_HELLO_Address::address, GNUNET_ATS_Session::address, GNUNET_HELLO_Address::address_length, client_reschedule_session_timeout(), GNUNET_TRANSPORT_PluginEnvironment::cls, Plugin::env, HTTP_Client_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, HTTP_Client_Plugin::protocol, GNUNET_MessageHeader::size, and GNUNET_TRANSPORT_PluginEnvironment::stats.

Referenced by client_receive().

1164 {
1165  struct GNUNET_ATS_Session *s = cls;
1166  struct HTTP_Client_Plugin *plugin;
1167  struct GNUNET_TIME_Relative delay;
1168  char *stat_txt;
1169 
1170  plugin = s->plugin;
1171  delay = s->plugin->env->receive (plugin->env->cls,
1172  s->address,
1173  s,
1174  message);
1175  GNUNET_asprintf (&stat_txt,
1176  "# bytes received via %s_client",
1177  plugin->protocol);
1179  stat_txt,
1180  ntohs (message->size),
1181  GNUNET_NO);
1182  GNUNET_free (stat_txt);
1183 
1185  if (GNUNET_TIME_absolute_get ().abs_value_us < s->next_receive.abs_value_us)
1186  {
1188  "Client: peer `%s' address `%s' next read delayed for %s\n",
1189  GNUNET_i2s (&s->address->peer),
1191  s->address->address,
1192  s->address->address_length),
1194  GNUNET_YES));
1195  }
1197  return GNUNET_OK;
1198 }
size_t address_length
Number of bytes in address.
const void * address
Binary representation of the address (plugin-specific).
struct Plugin * plugin
Pointer to the global plugin struct.
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:245
char * protocol
Plugin protocol http, https.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GNUNET_HELLO_Address * address
Address.
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
uint64_t abs_value_us
The actual value.
struct GNUNET_TIME_Absolute next_receive
Absolute time when to receive data again Used for receive throttling.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
void * cls
Closure for the various callbacks.
Information about ongoing sessions of the transport client.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
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:727
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
static void client_reschedule_session_timeout(struct GNUNET_ATS_Session *s)
Increment session timeout due to activity for session s.
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
struct GNUNET_PeerIdentity peer
For which peer is this an address?
Encapsulation of all of the state of the plugin.
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.
struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
#define GNUNET_YES
Definition: gnunet_common.h:80
#define LOG(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
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 1212 of file plugin_transport_http_client.c.

Referenced by client_connect_put().

1216 {
1217  return size * nmemb;
1218 }
static unsigned int size
Size of the "table".
Definition: peer.c:67
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 1232 of file plugin_transport_http_client.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_ATS_Session::address, client_receive_mst_cb(), client_wake_up(), 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, and GNUNET_ATS_Session::recv_wakeup_task.

Referenced by client_connect_get().

1236 {
1237  struct GNUNET_ATS_Session *s = cls;
1238  struct GNUNET_TIME_Absolute now;
1239  size_t len = size * nmemb;
1240 
1242  "Session %p / request %p: Received %u bytes from peer `%s'\n",
1243  s,
1244  s->get.easyhandle,
1245  len,
1246  GNUNET_i2s (&s->address->peer));
1247  now = GNUNET_TIME_absolute_get ();
1248  if (now.abs_value_us < s->next_receive.abs_value_us)
1249  {
1253 
1255  "Session %p / request %p: No inbound bandwidth available! Next read was delayed for %s\n",
1256  s,
1257  s->get.easyhandle,
1259  GNUNET_YES));
1260  if (s->recv_wakeup_task != NULL)
1261  {
1263  s->recv_wakeup_task = NULL;
1264  }
1265  s->recv_wakeup_task
1267  &client_wake_up,
1268  s);
1269  return CURL_WRITEFUNC_PAUSE;
1270  }
1271  if (NULL == s->msg_tk)
1273  s);
1275  stream,
1276  len,
1277  GNUNET_NO,
1278  GNUNET_NO);
1279  return len;
1280 }
static int client_receive_mst_cb(void *cls, const struct GNUNET_MessageHeader *message)
Callback for message stream tokenizer.
struct GNUNET_SCHEDULER_Task * recv_wakeup_task
Task to wake up client receive handle when receiving is allowed again.
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:35
struct GNUNET_SERVER_MessageStreamTokenizer * msg_tk
Message stream tokenizer for incoming data.
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GNUNET_HELLO_Address * address
Address.
static void client_wake_up(void *cls)
Wake up a curl handle which was suspended.
struct RequestHandle get
Handle for the HTTP GET request.
uint64_t abs_value_us
The actual value.
struct GNUNET_TIME_Absolute next_receive
Absolute time when to receive data again Used for receive throttling.
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:1246
Information about ongoing sessions of the transport client.
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:727
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Definition: mst.c:87
int GNUNET_MST_from_buffer(struct GNUNET_MessageStreamTokenizer *mst, const char *buf, size_t size, int purge, int one_shot)
Add incoming data to the receive buffer and call the callback for all complete messages.
Definition: mst.c:116
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
static unsigned int size
Size of the "table".
Definition: peer.c:67
struct GNUNET_PeerIdentity peer
For which peer is this an address?
Time for absolute times used by GNUnet, in microseconds.
#define GNUNET_YES
Definition: gnunet_common.h:80
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:353
#define LOG(kind,...)
CURL * easyhandle
The curl easy handle.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Time for relative time used by GNUnet, in microseconds.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
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 1850 of file plugin_transport_http_client.c.

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

Referenced by http_client_plugin_get_session().

1851 {
1852  struct HTTP_Client_Plugin *plugin = s->plugin;
1853  int res = GNUNET_OK;
1854 
1855  /* create url */
1856  if (NULL ==
1858  s->address->address,
1859  s->address->address_length))
1860  {
1862  "Invalid address peer `%s'\n",
1863  GNUNET_i2s(&s->address->peer));
1864  return GNUNET_SYSERR;
1865  }
1866 
1867  GNUNET_asprintf (&s->url,
1868  "%s/%s;%u",
1870  s->address->address,
1871  s->address->address_length),
1872  GNUNET_i2s_full (plugin->env->my_identity),
1873  plugin->last_tag);
1874 
1875  plugin->last_tag++;
1877  "Initiating outbound session peer `%s' using address `%s'\n",
1878  GNUNET_i2s (&s->address->peer), s->url);
1879 
1880  if (GNUNET_SYSERR == client_connect_get (s))
1881  return GNUNET_SYSERR;
1882  /* If we are emulating an XHR client then delay sending a PUT request until
1883  * there is something to send.
1884  */
1885  if (GNUNET_YES == plugin->emulate_xhr)
1886  {
1888  }
1889  else if (GNUNET_SYSERR == client_connect_put (s))
1890  return GNUNET_SYSERR;
1891 
1893  "Session %p: connected with GET %p and PUT %p\n",
1894  s, s->get.easyhandle,
1895  s->put.easyhandle);
1896  /* Perform connect */
1897  GNUNET_STATISTICS_set (plugin->env->stats,
1899  plugin->cur_requests,
1900  GNUNET_NO);
1901  /* Re-schedule since handles have changed */
1902  if (NULL != plugin->client_perform_task)
1903  {
1905  plugin->client_perform_task = NULL;
1906  }
1907 
1908  /* Schedule task to run immediately */
1910  plugin);
1911  return res;
1912 }
size_t address_length
Number of bytes in address.
const void * address
Binary representation of the address (plugin-specific).
uint32_t last_tag
Last used unique HTTP connection tag.
struct Plugin * plugin
Pointer to the global plugin struct.
const char * http_common_plugin_address_to_url(void *cls, const void *addr, size_t addrlen)
FIXME.
static int client_connect_get(struct GNUNET_ATS_Session *s)
Connect GET request.
struct RequestHandle put
Handle for the HTTP PUT request.
const struct GNUNET_PeerIdentity * my_identity
Identity of this peer.
#define GNUNET_NO
Definition: gnunet_common.h:81
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static void client_run(void *cls)
Task performing curl operations.
struct GNUNET_HELLO_Address * address
Address.
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
struct RequestHandle get
Handle for the HTTP GET request.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
Temporarily disconnected.
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:1273
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
static int client_connect_put(struct GNUNET_ATS_Session *s)
Connect a HTTP put request.
int state
The processing state.
static int res
char * url
The URL to connect to.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
int emulate_xhr
Should we emulate an XHR client for testing?
struct GNUNET_PeerIdentity peer
For which peer is this an address?
Encapsulation of all of the state of the plugin.
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.
struct GNUNET_SCHEDULER_Task * client_perform_task
curl perform task
unsigned int cur_requests
Current number of sockets the plugin can use Each http connections are two requests.
#define HTTP_STAT_STR_CONNECTIONS
struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
#define GNUNET_YES
Definition: gnunet_common.h:80
#define LOG(kind,...)
CURL * easyhandle
The curl easy handle.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
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 1923 of file plugin_transport_http_client.c.

References GNUNET_ATS_Session::scope.

Referenced by libgnunet_plugin_transport_http_client_init().

1925 {
1926  return session->scope;
1927 }
enum GNUNET_NetworkType scope
ATS network type.
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 1938 of file plugin_transport_http_client.c.

References HTTP_Client_Plugin::env, http_common_get_network_for_address(), and plugin.

Referenced by libgnunet_plugin_transport_http_client_init().

1940 {
1941  struct HTTP_Client_Plugin *plugin = cls;
1942 
1943  return http_common_get_network_for_address (plugin->env,
1944  address);
1945 }
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
Encapsulation of all of the state of the plugin.
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.
Here is the call graph for this function:
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 1954 of file plugin_transport_http_client.c.

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().

1955 {
1956  struct GNUNET_ATS_Session *s = cls;
1957  struct GNUNET_TIME_Relative left;
1958 
1959  s->timeout_task = NULL;
1961  if (0 != left.rel_value_us)
1962  {
1963  /* not actually our turn yet, but let's at least update
1964  the monitor, it may think we're about to die ... */
1966  s,
1970  s);
1971  return;
1972  }
1973  LOG (TIMEOUT_LOG,
1974  "Session %p was idle for %s, disconnecting\n",
1975  s,
1977  GNUNET_YES));
1980  s));
1981 }
#define HTTP_CLIENT_SESSION_TIMEOUT
static int http_client_plugin_session_disconnect(void *cls, struct GNUNET_ATS_Session *s)
Disconnect a session.
struct GNUNET_SCHEDULER_Task * timeout_task
Session timeout task.
struct Plugin * plugin
Pointer to the global plugin struct.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void client_session_timeout(void *cls)
Session was idle, so disconnect it.
struct GNUNET_TIME_Absolute timeout
When does this session time out.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
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:1246
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.
Information about ongoing sessions of the transport client.
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:727
This is just an update about the session, the state did not change.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
#define GNUNET_YES
Definition: gnunet_common.h:80
#define LOG(kind,...)
#define TIMEOUT_LOG
Time for relative time used by GNUnet, in microseconds.
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 1993 of file plugin_transport_http_client.c.

References 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_TRANSPORT_PluginEnvironment::cls, HTTP_Client_Plugin::cur_requests, HTTP_Client_Plugin::env, GNUNET_TRANSPORT_PluginEnvironment::get_address_type, 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, HTTP_Client_Plugin::max_requests, notify_session_monitor(), GNUNET_HELLO_Address::peer, plugin, GNUNET_ATS_Session::plugin, HTTP_Client_Plugin::protocol, GNUNET_ATS_Session::put, res, GNUNET_ATS_Session::scope, HTTP_Client_Plugin::sessions, RequestHandle::state, GNUNET_ATS_Session::timeout, and GNUNET_ATS_Session::timeout_task.

Referenced by libgnunet_plugin_transport_http_client_init().

1995 {
1996  struct HTTP_Client_Plugin *plugin = cls;
1997  struct GNUNET_ATS_Session *s;
1998  struct sockaddr *sa;
1999  enum GNUNET_NetworkType net_type;
2000  size_t salen = 0;
2001  int res;
2002 
2003  GNUNET_assert (NULL != address->address);
2004 
2005  /* find existing session */
2006  s = client_lookup_session (plugin, address);
2007  if (NULL != s)
2008  return s;
2009 
2010  /* create a new session */
2011  if (plugin->max_requests <= plugin->cur_requests)
2012  {
2014  "Maximum number of requests (%u) reached: "
2015  "cannot connect to peer `%s'\n",
2016  plugin->max_requests,
2017  GNUNET_i2s (&address->peer));
2018  return NULL;
2019  }
2020 
2021  /* Determine network location */
2022  net_type = GNUNET_NT_UNSPECIFIED;
2024  address->address_length,
2025  &res);
2026  if (GNUNET_SYSERR == res)
2027  return NULL;
2028  if (GNUNET_YES == res)
2029  {
2030  GNUNET_assert (NULL != sa);
2031  if (AF_INET == sa->sa_family)
2032  {
2033  salen = sizeof (struct sockaddr_in);
2034  }
2035  else if (AF_INET6 == sa->sa_family)
2036  {
2037  salen = sizeof (struct sockaddr_in6);
2038  }
2039  net_type = plugin->env->get_address_type (plugin->env->cls, sa, salen);
2040  GNUNET_free (sa);
2041  }
2042  else if (GNUNET_NO == res)
2043  {
2044  /* Cannot convert to sockaddr -> is external hostname */
2045  net_type = GNUNET_NT_WAN;
2046  }
2047  if (GNUNET_NT_UNSPECIFIED == net_type)
2048  {
2049  GNUNET_break (0);
2050  return NULL;
2051  }
2052 
2053  s = GNUNET_new (struct GNUNET_ATS_Session);
2054  s->plugin = plugin;
2055  s->address = GNUNET_HELLO_address_copy (address);
2056  s->scope = net_type;
2057 
2058  s->put.state = H_NOT_CONNECTED;
2062  s);
2064  "Created new session %p for `%s' address `%s''\n",
2065  s,
2067  s->address->address,
2068  s->address->address_length),
2069  GNUNET_i2s (&s->address->peer));
2070 
2071  /* add new session */
2073  &s->address->peer,
2074  s,
2076  /* initiate new connection */
2077  if (GNUNET_SYSERR == client_connect (s))
2078  {
2080  "Cannot connect to peer `%s' address `%s''\n",
2083  GNUNET_i2s (&s->address->peer));
2085  return NULL;
2086  }
2087  notify_session_monitor (plugin,
2088  s,
2090  notify_session_monitor (plugin,
2091  s,
2092  GNUNET_TRANSPORT_SS_UP); /* or handshake? */
2093  return s;
2094 }
size_t address_length
Number of bytes in address.
#define HTTP_CLIENT_SESSION_TIMEOUT
const void * address
Binary representation of the address (plugin-specific).
struct GNUNET_SCHEDULER_Task * timeout_task
Session timeout task.
struct Plugin * plugin
Pointer to the global plugin struct.
GNUNET_TRANSPORT_AddressToType get_address_type
Function that will be called to figure if an address is an loopback, LAN, WAN etc.
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:245
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct RequestHandle put
Handle for the HTTP PUT request.
static void client_session_timeout(void *cls)
Session was idle, so disconnect it.
struct GNUNET_TIME_Absolute timeout
When does this session time out.
Wide area network (i.e.
Definition: gnunet_nt_lib.h:55
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_HELLO_Address * address
Address.
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:35
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
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:1246
static void notify_session_monitor(struct HTTP_Client_Plugin *plugin, struct GNUNET_ATS_Session *session, enum GNUNET_TRANSPORT_SessionState state)
If a session monitor is attached, notify it about the new session state.
void * cls
Closure for the various callbacks.
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.
Information about ongoing sessions of the transport client.
int state
The processing state.
static int res
static int client_connect(struct GNUNET_ATS_Session *s)
Connect both PUT and GET request for a session.
struct GNUNET_CONTAINER_MultiPeerMap * sessions
Open sessions.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
enum GNUNET_NetworkType scope
ATS network type.
struct GNUNET_PeerIdentity peer
For which peer is this an address?
Just created, not yet connected.
Encapsulation of all of the state of the plugin.
Allow multiple values with the same key.
const char * http_common_plugin_address_to_string(const char *plugin, const void *addr, size_t addrlen)
Function called for a quick conversion of the binary address to a numeric address.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct sockaddr * http_common_socket_from_address(const void *addr, size_t addrlen, int *res)
Create a socketaddr from a HTTP address.
unsigned int cur_requests
Current number of sockets the plugin can use Each http connections are two requests.
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_copy(const struct GNUNET_HELLO_Address *address)
Copy an address struct.
Definition: address.c:109
The session was created (first call for each session object).
unsigned int max_requests
Maximum number of sockets the plugin can use Each http connections are two requests.
#define GNUNET_YES
Definition: gnunet_common.h:80
#define LOG(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_free(ptr)
Wrapper around free.
Category of last resort.
Definition: gnunet_nt_lib.h:40
static void client_delete_session(struct GNUNET_ATS_Session *s)
Delete session s.
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 2104 of file plugin_transport_http_client.c.

References _, HTTP_Client_Plugin::curl_multi_handle, GNUNET_ERROR_TYPE_ERROR, GNUNET_OK, GNUNET_SYSERR, LOG, and HTTP_Client_Plugin::name.

Referenced by libgnunet_plugin_transport_http_client_init().

2105 {
2106  curl_global_init (CURL_GLOBAL_ALL);
2107  plugin->curl_multi_handle = curl_multi_init ();
2108 
2109  if (NULL == plugin->curl_multi_handle)
2110  {
2112  _("Could not initialize curl multi handle, failed to start %s plugin!\n"),
2113  plugin->name);
2114  return GNUNET_SYSERR;
2115  }
2116  return GNUNET_OK;
2117 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
CURLM * curl_multi_handle
cURL Multihandle
#define LOG(kind,...)
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 2133 of file plugin_transport_http_client.c.

References GNUNET_NO.

Referenced by libgnunet_plugin_transport_http_client_init().

2136 {
2137  /* A HTTP/S client does not have any valid address so:*/
2138  return GNUNET_NO;
2139 }
#define GNUNET_NO
Definition: gnunet_common.h:81
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 2149 of file plugin_transport_http_client.c.

References _, HTTP_Client_Plugin::client_perform_task, GNUNET_TRANSPORT_PluginFunctions::cls, HTTP_Client_Plugin::curl_multi_handle, destroy_session_cb(), GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_free_non_null, GNUNET_SCHEDULER_cancel(), LOG, HTTP_Client_Plugin::name, plugin, HTTP_Client_Plugin::proxy_hostname, HTTP_Client_Plugin::proxy_password, HTTP_Client_Plugin::proxy_username, and HTTP_Client_Plugin::sessions.

2150 {
2151  struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
2152  struct HTTP_Client_Plugin *plugin = api->cls;
2153 
2154  if (NULL == api->cls)
2155  {
2156  /* Stub shutdown */
2157  GNUNET_free (api);
2158  return NULL;
2159  }
2161  _("Shutting down plugin `%s'\n"),
2162  plugin->name);
2165  plugin);
2166  if (NULL != plugin->client_perform_task)
2167  {
2169  plugin->client_perform_task = NULL;
2170  }
2171  if (NULL != plugin->curl_multi_handle)
2172  {
2173  curl_multi_cleanup (plugin->curl_multi_handle);
2174  plugin->curl_multi_handle = NULL;
2175  }
2176  curl_global_cleanup ();
2178  _("Shutdown for plugin `%s' complete\n"),
2179  plugin->name);
2184  GNUNET_free (plugin);
2185  GNUNET_free (api);
2186  return NULL;
2187 }
char * proxy_username
Username for the proxy server.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
void * cls
Closure for all of the callbacks.
static int destroy_session_cb(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Callback to destroys all sessions on exit.
struct GNUNET_CONTAINER_MultiPeerMap * sessions
Open sessions.
Encapsulation of all of the state of the plugin.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
struct GNUNET_SCHEDULER_Task * client_perform_task
curl perform task
CURLM * curl_multi_handle
cURL Multihandle
char * proxy_hostname
Proxy configuration: hostname or ip of the proxy server.
#define LOG(kind,...)
char * proxy_password
Password for the proxy server.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
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 2197 of file plugin_transport_http_client.c.

References _, GNUNET_TRANSPORT_PluginEnvironment::cfg, HTTP_Client_Plugin::emulate_xhr, HTTP_Client_Plugin::env, GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_free_non_null, GNUNET_NO, GNUNET_OK, GNUNET_STRINGS_utf8_toupper(), GNUNET_SYSERR, LOG, HTTP_Client_Plugin::max_requests, HTTP_Client_Plugin::name, HTTP_Client_Plugin::proxy_hostname, HTTP_Client_Plugin::proxy_password, proxy_type, HTTP_Client_Plugin::proxy_use_httpproxytunnel, HTTP_Client_Plugin::proxy_username, and HTTP_Client_Plugin::proxytype.

Referenced by libgnunet_plugin_transport_http_client_init().

2198 {
2199  unsigned long long max_requests;
2200  char *proxy_type;
2201 
2202  /* Optional parameters */
2203  if (GNUNET_OK !=
2205  plugin->name,
2206  "MAX_CONNECTIONS",
2207  &max_requests))
2208  max_requests = 128;
2209  plugin->max_requests = max_requests;
2210 
2212  _("Maximum number of requests is %u\n"),
2213  plugin->max_requests);
2214 
2215  /* Read proxy configuration */
2216  if (GNUNET_OK ==
2218  plugin->name,
2219  "PROXY",
2220  &plugin->proxy_hostname))
2221  {
2223  "Found proxy host: `%s'\n",
2224  plugin->proxy_hostname);
2225  /* proxy username */
2226  if (GNUNET_OK ==
2228  plugin->name,
2229  "PROXY_USERNAME",
2230  &plugin->proxy_username))
2231  {
2233  "Found proxy username name: `%s'\n",
2234  plugin->proxy_username);
2235  }
2236 
2237  /* proxy password */
2238  if (GNUNET_OK ==
2240  plugin->name,
2241  "PROXY_PASSWORD",
2242  &plugin->proxy_password))
2243  {
2245  "Found proxy password name: `%s'\n",
2246  plugin->proxy_password);
2247  }
2248 
2249  /* proxy type */
2250  if (GNUNET_OK ==
2252  plugin->name,
2253  "PROXY_TYPE",
2254  &proxy_type))
2255  {
2256  GNUNET_STRINGS_utf8_toupper (proxy_type, proxy_type);
2257 
2258  if (0 == strcmp(proxy_type, "HTTP"))
2259  plugin->proxytype = CURLPROXY_HTTP;
2260  else if (0 == strcmp(proxy_type, "SOCKS4"))
2261  plugin->proxytype = CURLPROXY_SOCKS4;
2262  else if (0 == strcmp(proxy_type, "SOCKS5"))
2263  plugin->proxytype = CURLPROXY_SOCKS5;
2264  else if (0 == strcmp(proxy_type, "SOCKS4A"))
2265  plugin->proxytype = CURLPROXY_SOCKS4A;
2266  else if (0 == strcmp(proxy_type, "SOCKS5_HOSTNAME "))
2267  plugin->proxytype = CURLPROXY_SOCKS5_HOSTNAME ;
2268  else
2269  {
2271  _("Invalid proxy type: `%s', disabling proxy! Check configuration!\n"),
2272  proxy_type);
2273 
2274  GNUNET_free (proxy_type);
2275  GNUNET_free (plugin->proxy_hostname);
2276  plugin->proxy_hostname = NULL;
2278  plugin->proxy_username = NULL;
2280  plugin->proxy_password = NULL;
2281 
2282  return GNUNET_SYSERR;
2283  }
2284 
2286  "Found proxy type: `%s'\n",
2287  proxy_type);
2288  }
2289 
2290  /* proxy http tunneling */
2293  plugin->name,
2294  "PROXY_HTTP_TUNNELING");
2297 
2298  GNUNET_free_non_null (proxy_type);
2299  }
2300 
2301  /* Should we emulate an XHR client for testing? */
2302  plugin->emulate_xhr
2304  plugin->name,
2305  "EMULATE_XHR");
2306  return GNUNET_OK;
2307 }
int GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
curl_proxytype proxytype
Type of proxy server:
char * proxy_username
Username for the proxy server.
static curl_proxytype proxy_type
Proxy type we are using (can be NULL).
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
int proxy_use_httpproxytunnel
Use proxy tunneling: Tunnel all operations through a given HTTP instead of have the proxy evaluate th...
void GNUNET_STRINGS_utf8_toupper(const char *input, char *output)
Convert the utf-8 input string to upper case.
Definition: strings.c:580
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
int emulate_xhr
Should we emulate an XHR client for testing?
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
unsigned int max_requests
Maximum number of sockets the plugin can use Each http connections are two requests.
char * proxy_hostname
Proxy configuration: hostname or ip of the proxy server.
#define LOG(kind,...)
int GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
char * proxy_password
Password for the proxy server.
#define GNUNET_free(ptr)
Wrapper around free.
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 2319 of file plugin_transport_http_client.c.

References http_common_plugin_address_to_string(), and PLUGIN_NAME.

Referenced by libgnunet_plugin_transport_http_client_init().

2322 {
2324  addr,
2325  addrlen);
2326 }
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.
#define PLUGIN_NAME
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 2339 of file plugin_transport_http_client.c.

References client_reschedule_session_timeout().

Referenced by libgnunet_plugin_transport_http_client_init().

2342 {
2344 }
static void client_reschedule_session_timeout(struct GNUNET_ATS_Session *s)
Increment session timeout due to activity for session s.
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 2358 of file plugin_transport_http_client.c.

References client_wake_up(), 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().

2362 {
2365  "New inbound delay %s\n",
2367  GNUNET_NO));
2368  if (s->recv_wakeup_task != NULL)
2369  {
2371  s->recv_wakeup_task
2373  &client_wake_up,
2374  s);
2375  }
2376 }
struct GNUNET_SCHEDULER_Task * recv_wakeup_task
Task to wake up client receive handle when receiving is allowed again.
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:245
#define GNUNET_NO
Definition: gnunet_common.h:81
static void client_wake_up(void *cls)
Wake up a curl handle which was suspended.
struct GNUNET_TIME_Absolute next_receive
Absolute time when to receive data again Used for receive throttling.
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:1246
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:727
#define LOG(kind,...)
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
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 2389 of file plugin_transport_http_client.c.

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

Referenced by http_client_plugin_setup_monitor(), template_plugin_setup_monitor(), and template_plugin_update_session_timeout().

2392 {
2393  struct HTTP_Client_Plugin *plugin = cls;
2394  struct GNUNET_ATS_Session *session = value;
2395 
2396  notify_session_monitor (plugin,
2397  session,
2399  notify_session_monitor (plugin,
2400  session,
2401  GNUNET_TRANSPORT_SS_UP); /* FIXME: or handshake? */
2402  return GNUNET_OK;
2403 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
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.
static char * value
Value of the record to add/remove.
Information about ongoing sessions of the transport client.
Encapsulation of all of the state of the plugin.
The session was created (first call for each session object).
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 2419 of file plugin_transport_http_client.c.

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

Referenced by libgnunet_plugin_transport_http_client_init().

2422 {
2423  struct HTTP_Client_Plugin *plugin = cls;
2424 
2425  plugin->sic = sic;
2426  plugin->sic_cls = sic_cls;
2427  if (NULL != sic)
2428  {
2431  plugin);
2432  /* signal end of first iteration */
2433  sic (sic_cls, NULL, NULL);
2434  }
2435 }
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.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
GNUNET_TRANSPORT_SessionInfoCallback sic
Function to call about session status changes.
struct GNUNET_CONTAINER_MultiPeerMap * sessions
Open sessions.
void * sic_cls
Closure for sic.
Encapsulation of all of the state of the plugin.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
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 2442 of file plugin_transport_http_client.c.

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, HTTP_Client_Plugin::env, GNUNET_TRANSPORT_PluginFunctions::get_network, GNUNET_TRANSPORT_PluginFunctions::get_network_for_address, GNUNET_TRANSPORT_PluginFunctions::get_session, GNUNET_CONTAINER_multipeermap_create(), GNUNET_new, GNUNET_SYSERR, GNUNET_YES, http_client_plugin_address_suggested(), http_client_plugin_address_to_string(), http_client_plugin_get_network(), http_client_plugin_get_network_for_address(), http_client_plugin_get_session(), http_client_plugin_peer_disconnect(), http_client_plugin_send(), http_client_plugin_session_disconnect(), http_client_plugin_setup_monitor(), http_client_plugin_update_inbound_delay(), http_client_plugin_update_session_timeout(), http_client_query_keepalive_factor(), http_common_plugin_address_pretty_printer(), http_common_plugin_string_to_address(), HTTP_Client_Plugin::last_tag, LIBGNUNET_PLUGIN_TRANSPORT_DONE, HTTP_Client_Plugin::name, plugin, HTTP_Client_Plugin::protocol, GNUNET_TRANSPORT_PluginFunctions::query_keepalive_factor, GNUNET_TRANSPORT_PluginEnvironment::receive, GNUNET_TRANSPORT_PluginFunctions::send, HTTP_Client_Plugin::sessions, GNUNET_TRANSPORT_PluginFunctions::setup_monitor, GNUNET_TRANSPORT_PluginFunctions::string_to_address, GNUNET_TRANSPORT_PluginFunctions::update_inbound_delay, and GNUNET_TRANSPORT_PluginFunctions::update_session_timeout.

2443 {
2446  struct HTTP_Client_Plugin *plugin;
2447 
2448  if (NULL == env->receive)
2449  {
2450  /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
2451  initialze the plugin or the API */
2453  api->cls = NULL;
2457  return api;
2458  }
2459 
2460  plugin = GNUNET_new (struct HTTP_Client_Plugin);
2461  plugin->env = env;
2463  GNUNET_YES);
2465  api->cls = plugin;
2466  api->send = &http_client_plugin_send;
2480 #if BUILD_HTTPS
2481  plugin->name = "transport-https_client";
2482  plugin->protocol = "https";
2483 #else
2484  plugin->name = "transport-http_client";
2485  plugin->protocol = "http";
2486 #endif
2487  plugin->last_tag = 1;
2488 
2489  if (GNUNET_SYSERR == client_configure_plugin (plugin))
2490  {
2492  return NULL;
2493  }
2494 
2495  /* Start client */
2496  if (GNUNET_SYSERR == client_start (plugin))
2497  {
2499  return NULL;
2500  }
2501  return api;
2502 }
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 unsigned int http_client_query_keepalive_factor(void *cls)
Function that is called to get the keepalive factor.
GNUNET_TRANSPORT_CreateSession get_session
Function that will be called tell the plugin to create a session object.
static int http_client_plugin_session_disconnect(void *cls, struct GNUNET_ATS_Session *s)
Disconnect a session.
GNUNET_TRANSPORT_AddressToString address_to_string
Function that will be called to convert a binary address to a string (numeric conversion only)...
static int client_configure_plugin(struct HTTP_Client_Plugin *plugin)
Configure plugin.
uint32_t last_tag
Last used unique HTTP connection tag.
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.
GNUNET_TRANSPORT_TransmitFunction send
Function that the transport service will use to transmit data to another peer.
GNUNET_TRANSPORT_DisconnectPeerFunction disconnect_peer
Function that can be used to force the plugin to disconnect from the given peer and cancel all previo...
GNUNET_TRANSPORT_DisconnectSessionFunction disconnect_session
Function that can be used to force the plugin to disconnect from the given peer and cancel all previo...
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
GNUNET_TRANSPORT_SessionMonitorSetup setup_monitor
Function to monitor the sessions managed by the 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 struct GNUNET_ATS_Session * http_client_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address)
Creates a new outbound session the transport service will use to send data to the peer...
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_TRANSPORT_PluginEnvironment * env
Our environment.
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).
GNUNET_TRANSPORT_PluginReceiveCallback receive
Function that should be called by the transport plugin whenever a message is received.
GNUNET_TRANSPORT_UpdateSessionTimeout update_session_timeout
Function that will be called whenever the transport service wants to notify the plugin that a session...
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
void * cls
Closure for the various callbacks.
void * cls
Closure for all of the callbacks.
GNUNET_TRANSPORT_StringToAddress string_to_address
Function that will be called to convert a string address to binary (numeric conversion only)...
The transport service will pass a pointer to a struct of this type as the first and only argument to ...
GNUNET_TRANSPORT_GetNetworkType get_network
Function to obtain the network type for a session.
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.
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...
GNUNET_TRANSPORT_UpdateInboundDelay update_inbound_delay
Function that will be called whenever the transport service wants to notify the plugin that the inbou...
static enum GNUNET_NetworkType http_client_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session)
Function obtain the network type for a session.
struct GNUNET_CONTAINER_MultiPeerMap * sessions
Open sessions.
static const char * http_client_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
Function to convert an address to a human-readable string.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
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...
#define LIBGNUNET_PLUGIN_TRANSPORT_DONE
Encapsulation of all of the state of the plugin.
GNUNET_TRANSPORT_QueryKeepaliveFactorFunction query_keepalive_factor
Function that is used to query keepalive factor.
static void http_client_plugin_setup_monitor(void *cls, GNUNET_TRANSPORT_SessionInfoCallback sic, void *sic_cls)
Begin monitoring sessions of a plugin.
static int client_start(struct HTTP_Client_Plugin *plugin)
Setup http_client plugin.
GNUNET_TRANSPORT_AddressPrettyPrinter address_pretty_printer
Function to pretty-print addresses.
#define GNUNET_YES
Definition: gnunet_common.h:80
GNUNET_TRANSPORT_CheckAddress check_address
Function that will be called to check if a binary address for this plugin is well-formed and correspo...
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...
GNUNET_TRANSPORT_GetNetworkTypeForAddress get_network_for_address
Function to obtain the network type for an address.
Here is the call graph for this function: