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

Implementation of the TCP transport service. More...

#include "platform.h"
#include "gnunet_hello_lib.h"
#include "gnunet_constants.h"
#include "gnunet_util_lib.h"
#include "gnunet_nat_service.h"
#include "gnunet_protocols.h"
#include "gnunet_resolver_service.h"
#include "gnunet_signatures.h"
#include "gnunet_statistics_service.h"
#include "gnunet_transport_service.h"
#include "gnunet_transport_plugin.h"
#include "transport.h"
#include "tcp_connection_legacy.c"
#include "tcp_server_mst_legacy.c"
#include "tcp_server_legacy.c"
#include "tcp_service_legacy.c"
Include dependency graph for plugin_transport_tcp.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_CONNECTION_Credentials
 Credentials for UNIX domain sockets. More...
 
struct  GNUNET_SERVER_MessageHandler
 Message handler. More...
 
struct  WelcomeMessage
 Initial handshake message for a session. More...
 
struct  TCP_NAT_ProbeMessage
 Basically a WELCOME message, but with the purpose of giving the waiting peer a client handle to use. More...
 
struct  TCPProbeContext
 Context for sending a NAT probe via TCP. More...
 
struct  IPv4TcpAddress
 Network format for IPv4 addresses. More...
 
struct  IPv6TcpAddress
 Network format for IPv6 addresses. More...
 
struct  PendingMessage
 List containing all messages that are yet to be send. More...
 
struct  GNUNET_ATS_Session
 Information about ongoing sessions of the transport client. More...
 
struct  PrettyPrinterContext
 Closure for append_port(). More...
 
struct  Plugin
 Handle for a plugin. More...
 
struct  GNUNET_ATS_SessionItCtx
 Closure for session_lookup_it(). More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "transport-tcp",__VA_ARGS__)
 
#define PLUGIN_NAME   "tcp"
 
#define NAT_TIMEOUT   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
 How long until we give up on establishing an NAT connection? Must be > 4 RTT. More...
 
#define GNUNET_SERVER_client_get_user_context(client, type)   (type *) GNUNET_SERVER_client_get_user_context_ (client, sizeof (type))
 Return user context associated with the given client. More...
 
#define GNUNET_SERVER_client_set_user_context(client, value)   GNUNET_SERVER_client_set_user_context_ (client, value, sizeof (*value))
 Set user context to be associated with the given client. More...
 

Typedefs

typedef size_t(* GNUNET_CONNECTION_TransmitReadyNotify) (void *cls, size_t size, void *buf)
 Function called to notify a client about the connection begin ready to queue more data. More...
 
typedef void(* GNUNET_SERVER_DisconnectCallback) (void *cls, struct GNUNET_SERVER_Client *client)
 Functions with this signature are called whenever a client is disconnected on the network level. More...
 
typedef void(* GNUNET_SERVER_ConnectCallback) (void *cls, struct GNUNET_SERVER_Client *client)
 Functions with this signature are called whenever a client is connected on the network level. More...
 
typedef int(* GNUNET_CONNECTION_AccessCheck) (void *cls, const struct GNUNET_CONNECTION_Credentials *ucred, const struct sockaddr *addr, socklen_t addrlen)
 Function to call for access control checks. More...
 
typedef void(* GNUNET_CONNECTION_Receiver) (void *cls, const void *buf, size_t available, const struct sockaddr *addr, socklen_t addrlen, int errCode)
 Callback function for data received from the network. More...
 
typedef void *(* GNUNET_SERVER_MstCreateCallback) (void *cls, struct GNUNET_SERVER_Client *client)
 Signature of a function to create a custom tokenizer. More...
 
typedef void(* GNUNET_SERVER_MstDestroyCallback) (void *cls, void *mst)
 Signature of a function to destroy a custom tokenizer. More...
 
typedef int(* GNUNET_SERVER_MstReceiveCallback) (void *cls, void *mst, struct GNUNET_SERVER_Client *client, const char *buf, size_t size, int purge, int one_shot)
 Signature of a function to receive data for a custom tokenizer. More...
 
typedef void(* GNUNET_SERVER_MessageCallback) (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message)
 Functions with this signature are called whenever a message is received. More...
 
typedef int(* GNUNET_SERVER_MessageTokenizerCallback) (void *cls, void *client, const struct GNUNET_MessageHeader *message)
 Functions with this signature are called whenever a complete message is received by the tokenizer. More...
 
typedef void(* LEGACY_SERVICE_Main) (void *cls, struct GNUNET_SERVER_Handle *server, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Function called by the service's run method to run service-specific setup code. More...
 

Enumerations

enum  LEGACY_SERVICE_Options { LEGACY_SERVICE_OPTION_NONE = 0, LEGACY_SERVICE_OPTION_MANUAL_SHUTDOWN = 1, LEGACY_SERVICE_OPTION_SOFT_SHUTDOWN = 2 }
 Options for the service (bitmask). More...
 
enum  TcpAddressOptions { TCP_OPTIONS_NONE = 0, TCP_OPTIONS_RESERVED = 1, TCP_OPTIONS_TCP_STEALTH = 2 }
 Bits in the options field of TCP addresses. More...
 

Functions

void LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *srv)
 Stops a service that was started with GNUNET_SERVICE_start(). More...
 
void GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection)
 Close the connection and free associated resources. More...
 
void GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client)
 Ask the server to disconnect from the given client. More...
 
void * GNUNET_SERVER_client_get_user_context_ (struct GNUNET_SERVER_Client *client, size_t size)
 Return user context associated with the given client. More...
 
struct GNUNET_SERVER_MessageStreamTokenizerGNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls)
 Create a message stream tokenizer. More...
 
int GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, void *client_identity, 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. More...
 
void GNUNET_SERVER_mst_destroy (struct GNUNET_SERVER_MessageStreamTokenizer *mst)
 Destroys a tokenizer. More...
 
void GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client, void *ptr, size_t size)
 Set user context to be associated with the given client. More...
 
struct GNUNET_SERVER_TransmitHandleGNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client, size_t size, struct GNUNET_TIME_Relative timeout, GNUNET_CONNECTION_TransmitReadyNotify callback, void *callback_cls)
 Notify us when the server has enough space to transmit a message of the given size to the given client. More...
 
void GNUNET_SERVER_notify_transmit_ready_cancel (struct GNUNET_SERVER_TransmitHandle *th)
 Abort transmission request. More...
 
void GNUNET_SERVER_client_keep (struct GNUNET_SERVER_Client *client)
 Notify the server that the given client handle should be kept (keeps the connection up if possible, increments the internal reference counter). More...
 
void GNUNET_SERVER_client_drop (struct GNUNET_SERVER_Client *client)
 Notify the server that the given client handle is no longer required. More...
 
void GNUNET_SERVER_suspend (struct GNUNET_SERVER_Handle *server)
 Suspend accepting connections from the listen socket temporarily. More...
 
struct GNUNET_SERVER_ClientGNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server, struct GNUNET_CONNECTION_Handle *connection)
 Add a TCP socket-based connection to the set of handles managed by this server. More...
 
void GNUNET_SERVER_resume (struct GNUNET_SERVER_Handle *server)
 Resume accepting connections from the listen socket. More...
 
void GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *server)
 Free resources held by this server. More...
 
static int get_server_addresses (const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg, struct sockaddr ***addrs, socklen_t **addr_lens)
 Get the list of addresses that a server for the given service should bind to. More...
 
static void notify_session_monitor (struct 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 tcp_nat_port_map_callback (void *cls, void **app_ctx, int add_remove, enum GNUNET_NAT_AddressClass ac, const struct sockaddr *addr, socklen_t addrlen)
 Our external IP address/port mapping has changed. More...
 
static const char * tcp_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
 Function called for a quick conversion of the binary address to a numeric address. More...
 
static int tcp_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. More...
 
static struct GNUNET_ATS_Sessionlookup_session_by_client (struct Plugin *plugin, struct GNUNET_SERVER_Client *client)
 Find the session handle for the given client. More...
 
static int tcp_plugin_disconnect_session (void *cls, struct GNUNET_ATS_Session *session)
 Functions with this signature are called whenever we need to close a session due to a disconnect or failure to establish a connection. More...
 
static unsigned int tcp_plugin_query_keepalive_factor (void *cls)
 Function that is called to get the keepalive factor. More...
 
static void session_timeout (void *cls)
 Session was idle for too long, so disconnect it. More...
 
static void reschedule_session_timeout (struct GNUNET_ATS_Session *s)
 Increment session timeout due to activity. More...
 
static struct GNUNET_ATS_Sessioncreate_session (struct Plugin *plugin, const struct GNUNET_HELLO_Address *address, enum GNUNET_NetworkType scope, struct GNUNET_SERVER_Client *client, int is_nat)
 Create a new session. More...
 
static void process_pending_messages (struct GNUNET_ATS_Session *session)
 If we have pending messages, ask the server to transmit them (schedule the respective tasks, etc.) More...
 
static size_t do_transmit (void *cls, size_t size, void *buf)
 Function called to notify a client about the socket being ready to queue more data. More...
 
static ssize_t tcp_plugin_send (void *cls, struct GNUNET_ATS_Session *session, 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 int session_lookup_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Look for a session by address. More...
 
static void nat_connect_timeout (void *cls)
 Task cleaning up a NAT connection attempt after timeout. More...
 
static void tcp_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 delayed_done (void *cls)
 Task to signal the server that we can continue receiving from the TCP client now. More...
 
static void tcp_plugin_update_inbound_delay (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_ATS_Session *session, 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 struct GNUNET_ATS_Sessiontcp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
 Create a new session to transmit data to the target This session will used to send data to this peer and the plugin will notify us by calling the env->session_end function. More...
 
static int session_disconnect_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 We have been asked to destroy all connections to a particular peer. More...
 
static void tcp_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
 Function that can be called to force a disconnect from the specified neighbour. More...
 
static void append_port (void *cls, const char *hostname)
 We are processing an address pretty printing request and finished the IP resolution (if applicable). More...
 
static void tcp_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. More...
 
static int tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
 Function that will be called to check if a binary address for this plugin is well-formed and corresponds to an address for THIS peer (as per our configuration). More...
 
static void handle_tcp_nat_probe (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message)
 We've received a nat probe from this peer via TCP. More...
 
static void handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message)
 We've received a welcome from this peer via TCP. More...
 
static void handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message)
 We've received data for this peer via TCP. More...
 
static void connect_notify (void *cls, struct GNUNET_SERVER_Client *client)
 Function called whenever a peer is connected on the "SERVER" level. More...
 
static void disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client)
 Function called whenever a peer is disconnected on the "SERVER" level. More...
 
static size_t notify_send_probe (void *cls, size_t size, void *buf)
 We can now send a probe message, copy into buffer to really send. More...
 
static void try_connection_reversal (void *cls, const struct sockaddr *addr, socklen_t addrlen)
 Function called by the NAT subsystem suggesting another peer wants to connect to us via connection reversal. More...
 
static enum GNUNET_NetworkType tcp_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session)
 Function obtain the network type for a session. More...
 
static enum GNUNET_NetworkType tcp_plugin_get_network_for_address (void *cls, const struct GNUNET_HELLO_Address *address)
 Function obtain the network type for an address. 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 tcp_plugin_setup_monitor (void *cls, GNUNET_TRANSPORT_SessionInfoCallback sic, void *sic_cls)
 Begin monitoring sessions of a plugin. More...
 
void * libgnunet_plugin_transport_tcp_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_transport_tcp_done (void *cls)
 Exit point from the plugin. More...
 

Detailed Description

Implementation of the TCP transport service.

Author
Christian Grothoff

Definition in file plugin_transport_tcp.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "transport-tcp",__VA_ARGS__)

◆ PLUGIN_NAME

#define PLUGIN_NAME   "tcp"

◆ NAT_TIMEOUT

How long until we give up on establishing an NAT connection? Must be > 4 RTT.

Definition at line 46 of file plugin_transport_tcp.c.

Referenced by tcp_plugin_get_session().

◆ GNUNET_SERVER_client_get_user_context

#define GNUNET_SERVER_client_get_user_context (   client,
  type 
)    (type *) GNUNET_SERVER_client_get_user_context_ (client, sizeof (type))

Return user context associated with the given client.

Parameters
clientclient to query
typeexpected return type (i.e. 'struct Foo')
Returns
pointer to user context of type 'type *'.

Definition at line 420 of file plugin_transport_tcp.c.

Referenced by lookup_session_by_client().

◆ GNUNET_SERVER_client_set_user_context

#define GNUNET_SERVER_client_set_user_context (   client,
  value 
)    GNUNET_SERVER_client_set_user_context_ (client, value, sizeof (*value))

Set user context to be associated with the given client.

Parameters
clientclient to query
valuepointer to user context

Definition at line 429 of file plugin_transport_tcp.c.

Referenced by create_session(), handle_tcp_nat_probe(), and tcp_plugin_disconnect_session().

Typedef Documentation

◆ GNUNET_CONNECTION_TransmitReadyNotify

typedef size_t(* GNUNET_CONNECTION_TransmitReadyNotify) (void *cls, size_t size, void *buf)

Function called to notify a client about the connection begin ready to queue more data.

buf will be NULL and size zero if the connection was closed for writing in the meantime.

Parameters
clsclosure
sizenumber of bytes available in buf
bufwhere the callee should write the message
Returns
number of bytes written to buf

Definition at line 101 of file plugin_transport_tcp.c.

◆ GNUNET_SERVER_DisconnectCallback

typedef void(* GNUNET_SERVER_DisconnectCallback) (void *cls, struct GNUNET_SERVER_Client *client)

Functions with this signature are called whenever a client is disconnected on the network level.

Parameters
clsclosure
clientidentification of the client; NULL for the last call when the server is destroyed

Definition at line 131 of file plugin_transport_tcp.c.

◆ GNUNET_SERVER_ConnectCallback

typedef void(* GNUNET_SERVER_ConnectCallback) (void *cls, struct GNUNET_SERVER_Client *client)

Functions with this signature are called whenever a client is connected on the network level.

Parameters
clsclosure
clientidentification of the client

Definition at line 143 of file plugin_transport_tcp.c.

◆ GNUNET_CONNECTION_AccessCheck

typedef int(* GNUNET_CONNECTION_AccessCheck) (void *cls, const struct GNUNET_CONNECTION_Credentials *ucred, const struct sockaddr *addr, socklen_t addrlen)

Function to call for access control checks.

Parameters
clsclosure
ucredcredentials, if available, otherwise NULL
addraddress
addrlenlength of address
Returns
GNUNET_YES to allow, GNUNET_NO to deny, GNUNET_SYSERR for unknown address family (will be denied).

Definition at line 160 of file plugin_transport_tcp.c.

◆ GNUNET_CONNECTION_Receiver

typedef void(* GNUNET_CONNECTION_Receiver) (void *cls, const void *buf, size_t available, const struct sockaddr *addr, socklen_t addrlen, int errCode)

Callback function for data received from the network.

Note that both "available" and "err" would be 0 if the read simply timed out.

Parameters
clsclosure
bufpointer to received data
availablenumber of bytes availabe in "buf", possibly 0 (on errors)
addraddress of the sender
addrlensize of addr
errCodevalue of errno (on errors receiving)

Definition at line 180 of file plugin_transport_tcp.c.

◆ GNUNET_SERVER_MstCreateCallback

typedef void*(* GNUNET_SERVER_MstCreateCallback) (void *cls, struct GNUNET_SERVER_Client *client)

Signature of a function to create a custom tokenizer.

Parameters
clsclosure from GNUNET_SERVER_set_callbacks
clienthandle to client the tokenzier will be used for
Returns
handle to custom tokenizer ('mst')

Definition at line 206 of file plugin_transport_tcp.c.

◆ GNUNET_SERVER_MstDestroyCallback

typedef void(* GNUNET_SERVER_MstDestroyCallback) (void *cls, void *mst)

Signature of a function to destroy a custom tokenizer.

Parameters
clsclosure from GNUNET_SERVER_set_callbacks
mstcustom tokenizer handle

Definition at line 217 of file plugin_transport_tcp.c.

◆ GNUNET_SERVER_MstReceiveCallback

typedef int(* GNUNET_SERVER_MstReceiveCallback) (void *cls, void *mst, struct GNUNET_SERVER_Client *client, const char *buf, size_t size, int purge, int one_shot)

Signature of a function to receive data for a custom tokenizer.

Parameters
clsclosure from GNUNET_SERVER_set_callbacks
mstcustom tokenizer handle
client_identityID of client for which this is a buffer, can be NULL (will be passed back to 'cb')
bufinput data to add
sizenumber of bytes in buf
purgeshould any excess bytes in the buffer be discarded (i.e. for packet-based services like UDP)
one_shotonly call callback once, keep rest of message in buffer
Returns
GNUNET_OK if we are done processing (need more data) GNUNET_NO if one_shot was set and we have another message ready GNUNET_SYSERR if the data stream is corrupt

Definition at line 237 of file plugin_transport_tcp.c.

◆ GNUNET_SERVER_MessageCallback

typedef void(* GNUNET_SERVER_MessageCallback) (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message)

Functions with this signature are called whenever a message is received.

Parameters
clsclosure
clientidentification of the client
messagethe actual message

Definition at line 252 of file plugin_transport_tcp.c.

◆ GNUNET_SERVER_MessageTokenizerCallback

typedef int(* GNUNET_SERVER_MessageTokenizerCallback) (void *cls, void *client, const struct GNUNET_MessageHeader *message)

Functions with this signature are called whenever a complete message is received by the tokenizer.

Do not call GNUNET_SERVER_mst_destroy from within the scope of this callback.

Parameters
clsclosure
clientidentification of the client
messagethe actual message
Returns
GNUNET_OK on success, GNUNET_SYSERR to stop further processing

Definition at line 352 of file plugin_transport_tcp.c.

◆ LEGACY_SERVICE_Main

typedef void(* LEGACY_SERVICE_Main) (void *cls, struct GNUNET_SERVER_Handle *server, const struct GNUNET_CONFIGURATION_Handle *cfg)

Function called by the service's run method to run service-specific setup code.

Parameters
clsclosure
serverthe initialized server
cfgconfiguration to use

Definition at line 499 of file plugin_transport_tcp.c.

Enumeration Type Documentation

◆ LEGACY_SERVICE_Options

Options for the service (bitmask).

Enumerator
LEGACY_SERVICE_OPTION_NONE 

Use defaults.

Terminates all client connections and the listen sockets immediately upon receiving the shutdown signal.

LEGACY_SERVICE_OPTION_MANUAL_SHUTDOWN 

Do not trigger server shutdown on signal at all; instead, allow for the user to terminate the server explicitly when needed by calling #LEGACY_SERVICE_shutdown().

LEGACY_SERVICE_OPTION_SOFT_SHUTDOWN 

Trigger a SOFT server shutdown on signals, allowing active non-monitor clients to complete their transactions.

Definition at line 291 of file plugin_transport_tcp.c.

292 {
298 
305 
311 };
Do not trigger server shutdown on signal at all; instead, allow for the user to terminate the server ...
Trigger a SOFT server shutdown on signals, allowing active non-monitor clients to complete their tran...

◆ TcpAddressOptions

Bits in the options field of TCP addresses.

Enumerator
TCP_OPTIONS_NONE 

No bits set.

TCP_OPTIONS_RESERVED 

See HTTP_OPTIONS_VERIFY_CERTIFICATE.

TCP_OPTIONS_TCP_STEALTH 

Enable TCP Stealth-style port knocking.

Definition at line 655 of file plugin_transport_tcp.c.

656 {
657 
661  TCP_OPTIONS_NONE = 0,
662 
667 
672 };
See HTTP_OPTIONS_VERIFY_CERTIFICATE.
Enable TCP Stealth-style port knocking.

Function Documentation

◆ LEGACY_SERVICE_stop()

void LEGACY_SERVICE_stop ( struct LEGACY_SERVICE_Context sctx)

Stops a service that was started with GNUNET_SERVICE_start().

Parameters
srvservice to stop

Stops a service that was started with GNUNET_SERVICE_start().

Parameters
sctxthe service context returned from the start function

Definition at line 1640 of file tcp_service_legacy.c.

References LEGACY_SERVICE_Context::addrlens, LEGACY_SERVICE_Context::addrs, LEGACY_SERVICE_Context::cfg, GAUGER, GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_have_value(), GNUNET_free, GNUNET_free_non_null, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_SERVER_destroy(), GNUNET_YES, LEGACY_SERVICE_Context::my_handlers, LEGACY_SERVICE_Context::server, LEGACY_SERVICE_Context::service_name, LEGACY_SERVICE_Context::shutdown_task, LEGACY_SERVICE_Context::v4_allowed, LEGACY_SERVICE_Context::v4_denied, LEGACY_SERVICE_Context::v6_allowed, and LEGACY_SERVICE_Context::v6_denied.

Referenced by LEGACY_SERVICE_start(), libgnunet_plugin_transport_tcp_done(), and libgnunet_plugin_transport_tcp_init().

1641 {
1642  unsigned int i;
1643 
1644 #if HAVE_MALLINFO
1645  {
1646  char *counter;
1647 
1648  if ( (GNUNET_YES ==
1650  "GAUGER_HEAP")) &&
1651  (GNUNET_OK ==
1653  "GAUGER_HEAP",
1654  &counter)) )
1655  {
1656  struct mallinfo mi;
1657 
1658  mi = mallinfo ();
1659  GAUGER (sctx->service_name, counter, mi.usmblks, "blocks");
1660  GNUNET_free (counter);
1661  }
1662  }
1663 #endif
1664  if (NULL != sctx->shutdown_task)
1665  {
1667  sctx->shutdown_task = NULL;
1668  }
1669  if (NULL != sctx->server)
1670  GNUNET_SERVER_destroy (sctx->server);
1672  if (NULL != sctx->addrs)
1673  {
1674  i = 0;
1675  while (NULL != sctx->addrs[i])
1676  GNUNET_free (sctx->addrs[i++]);
1677  GNUNET_free (sctx->addrs);
1678  }
1684  GNUNET_free (sctx);
1685 }
socklen_t * addrlens
Array of the lengths of the entries in addrs.
const char * service_name
Name of our service.
struct GNUNET_SCHEDULER_Task * shutdown_task
Task ID of the shutdown task.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct sockaddr ** addrs
NULL-terminated array of addresses to bind to, NULL if we got pre-bound listen sockets.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
struct GNUNET_SERVER_MessageHandler * my_handlers
My (default) message handlers.
struct GNUNET_STRINGS_IPv6NetworkPolicy * v6_allowed
IPv6 addresses that are allowed to connect (if not set, all are allowed).
int GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
struct GNUNET_SERVER_Handle * server
Handle for the server.
struct GNUNET_STRINGS_IPv4NetworkPolicy * v4_allowed
IPv4 addresses that are allowed to connect (if not set, all are allowed).
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
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.
struct GNUNET_STRINGS_IPv6NetworkPolicy * v6_denied
IPv6 addresses that are not allowed to connect.
#define GAUGER(category, counter, value, unit)
Definition: gauger.h:20
struct GNUNET_STRINGS_IPv4NetworkPolicy * v4_denied
IPv4 addresses that are not allowed to connect.
#define GNUNET_YES
Definition: gnunet_common.h:80
void GNUNET_SERVER_destroy(struct GNUNET_SERVER_Handle *server)
Free resources held by this 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:
Here is the caller graph for this function:

◆ GNUNET_CONNECTION_destroy()

void GNUNET_CONNECTION_destroy ( struct GNUNET_CONNECTION_Handle connection)

Close the connection and free associated resources.

There must not be any pending requests for reading or writing to the connection at this time.

Parameters
connectionconnection to destroy

Definition at line 1061 of file tcp_connection_legacy.c.

References GNUNET_CONNECTION_Handle::addr, GNUNET_CONNECTION_Handle::ap_head, GNUNET_CONNECTION_Handle::ap_tail, GNUNET_CONNECTION_Handle::destroy_later, GNUNET_CONNECTION_Handle::dns_active, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_free_non_null, GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_free_memory_only_(), GNUNET_NETWORK_socket_shutdown(), GNUNET_OK, GNUNET_RESOLVER_request_cancel(), GNUNET_SCHEDULER_cancel(), GNUNET_YES, GNUNET_CONNECTION_Handle::hostname, LOG, LOG_STRERROR, GNUNET_CONNECTION_TransmitHandle::notify_ready, GNUNET_CONNECTION_Handle::nth, GNUNET_CONNECTION_Handle::persist, GNUNET_CONNECTION_Handle::proxy_handshake, GNUNET_CONNECTION_Handle::read_task, GNUNET_CONNECTION_Handle::receiver, AddressProbe::sock, GNUNET_CONNECTION_Handle::sock, AddressProbe::task, GNUNET_CONNECTION_TransmitHandle::timeout_task, GNUNET_CONNECTION_Handle::write_buffer, GNUNET_CONNECTION_Handle::write_buffer_off, and GNUNET_CONNECTION_Handle::write_task.

Referenced by connect_fail_continuation(), GNUNET_CONNECTION_acivate_proxied(), GNUNET_SERVER_client_disconnect(), libgnunet_plugin_transport_tcp_done(), and notify_send_probe().

1062 {
1063  struct AddressProbe *pos;
1064 
1065  if (0 != connection->destroy_later)
1066  {
1067  connection->destroy_later = -1;
1068  return;
1069  }
1071  "Shutting down connection (%p)\n",
1072  connection);
1073  GNUNET_assert (NULL == connection->nth.notify_ready);
1074  GNUNET_assert (NULL == connection->receiver);
1075  if (NULL != connection->write_task)
1076  {
1077  GNUNET_SCHEDULER_cancel (connection->write_task);
1078  connection->write_task = NULL;
1079  connection->write_buffer_off = 0;
1080  }
1081  if (NULL != connection->read_task)
1082  {
1083  GNUNET_SCHEDULER_cancel (connection->read_task);
1084  connection->read_task = NULL;
1085  }
1086  if (NULL != connection->nth.timeout_task)
1087  {
1089  connection->nth.timeout_task = NULL;
1090  }
1091  connection->nth.notify_ready = NULL;
1092  if (NULL != connection->dns_active)
1093  {
1095  connection->dns_active = NULL;
1096  }
1097  if (NULL != connection->proxy_handshake)
1098  {
1099  /* GNUNET_CONNECTION_destroy (connection->proxy_handshake); */
1100  connection->proxy_handshake->destroy_later = -1;
1101  connection->proxy_handshake = NULL; /* Not leaked ??? */
1102  }
1103  while (NULL != (pos = connection->ap_head))
1104  {
1107  GNUNET_CONTAINER_DLL_remove (connection->ap_head,
1108  connection->ap_tail,
1109  pos);
1110  GNUNET_free (pos);
1111  }
1112  if ( (NULL != connection->sock) &&
1113  (GNUNET_YES != connection->persist) )
1114  {
1115  if ((GNUNET_OK !=
1116  GNUNET_NETWORK_socket_shutdown (connection->sock,
1117  SHUT_RDWR)) &&
1118  (ENOTCONN != errno) &&
1119  (ECONNRESET != errno) )
1121  "shutdown");
1122  }
1123  if (NULL != connection->sock)
1124  {
1125  if (GNUNET_YES != connection->persist)
1126  {
1128  GNUNET_NETWORK_socket_close (connection->sock));
1129  }
1130  else
1131  {
1132  GNUNET_NETWORK_socket_free_memory_only_ (connection->sock); /* at least no memory leak (we deliberately
1133  * leak the socket in this special case) ... */
1134  }
1135  }
1136  GNUNET_free_non_null (connection->addr);
1137  GNUNET_free_non_null (connection->hostname);
1138  GNUNET_free (connection->write_buffer);
1139  GNUNET_free (connection);
1140 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_NETWORK_Handle * sock
Underlying OS's socket, set to NULL after fatal errors.
void GNUNET_RESOLVER_request_cancel(struct GNUNET_RESOLVER_RequestHandle *rh)
Cancel a request that is still pending with the resolver.
struct AddressProbe * ap_head
Linked list of sockets we are currently trying out (during connect).
struct GNUNET_CONNECTION_Handle * proxy_handshake
Handle to subsequent connection after proxy handshake completes,.
#define LOG(kind,...)
Definition: arm_api.c:33
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#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 AddressProbe * ap_tail
Linked list of sockets we are currently trying out (during connect).
struct GNUNET_SCHEDULER_Task * task
Task waiting for the connection to finish connecting.
int GNUNET_NETWORK_socket_shutdown(struct GNUNET_NETWORK_Handle *desc, int how)
Shut down socket operations.
Definition: network.c:1065
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void GNUNET_NETWORK_socket_free_memory_only_(struct GNUNET_NETWORK_Handle *desc)
Only free memory of a socket, keep the file descriptor untouched.
Definition: network.c:680
char * hostname
Pointer to the hostname if connection was created using DNS lookup, otherwise NULL.
struct GNUNET_SCHEDULER_Task * read_task
Read task that we may need to wait for.
struct sockaddr * addr
Network address of the other end-point, may be NULL.
struct GNUNET_RESOLVER_RequestHandle * dns_active
Handle to a pending DNS lookup request.
size_t write_buffer_off
Current write-offset in write_buffer (where would we write next).
struct GNUNET_NETWORK_Handle * sock
Underlying OS's socket.
int8_t persist
When shutdown, do not ever actually close the socket, but free resources.
struct GNUNET_CONNECTION_TransmitHandle nth
The handle we return for GNUNET_CONNECTION_notify_transmit_ready().
GNUNET_CONNECTION_Receiver receiver
Function to call on data received, NULL if no receive is pending.
struct GNUNET_SCHEDULER_Task * write_task
Write task that we may need to wait for.
#define GNUNET_YES
Definition: gnunet_common.h:80
char * write_buffer
Pointer to our write buffer.
GNUNET_CONNECTION_TransmitReadyNotify notify_ready
Function to call if the send buffer has notify_size bytes available.
#define LOG_STRERROR(kind, syscall)
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:604
During connect, we try multiple possible IP addresses to find out which one might work...
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_SCHEDULER_Task * timeout_task
Task called on timeout.
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:

◆ GNUNET_SERVER_client_disconnect()

void GNUNET_SERVER_client_disconnect ( struct GNUNET_SERVER_Client client)

Ask the server to disconnect from the given client.

This is the same as passing GNUNET_SYSERR to GNUNET_SERVER_receive_done, except that it allows dropping of a client even when not handling a message from that client.

Parameters
clientthe client to disconnect from

This is the same as returning GNUNET_SYSERR from a message handler, except that it allows dropping of a client even when not handling a message from that client.

Parameters
clientthe client to disconnect from

Definition at line 1492 of file tcp_server_legacy.c.

References NotifyList::callback, NotifyList::callback_cls, GNUNET_SERVER_Handle::clients_head, GNUNET_SERVER_Handle::clients_tail, GNUNET_SERVER_Client::connection, GNUNET_SERVER_TransmitHandle::cth, GNUNET_SERVER_Handle::disconnect_notify_list_head, GNUNET_CONNECTION_destroy(), GNUNET_CONNECTION_persist_(), GNUNET_CONNECTION_receive_cancel(), GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_SERVER_mst_destroy(), GNUNET_SERVER_notify_transmit_ready_cancel(), GNUNET_YES, GNUNET_SERVER_Client::in_process_client_buffer, LOG, GNUNET_SERVER_Client::mst, GNUNET_SERVER_Handle::mst_cls, GNUNET_SERVER_Handle::mst_destroy, NotifyList::next, GNUNET_SERVER_Client::persist, GNUNET_SERVER_Client::receive_pending, GNUNET_SERVER_Client::reference_count, GNUNET_SERVER_Client::restart_task, GNUNET_SERVER_Client::server, GNUNET_SERVER_Client::shutdown_now, test_monitor_clients(), GNUNET_SERVER_Client::th, and GNUNET_SERVER_Client::warn_task.

Referenced by client_message_tokenizer_callback(), GNUNET_SERVER_client_drop(), GNUNET_SERVER_destroy(), GNUNET_SERVER_receive_done(), process_incoming(), process_mst(), and tcp_plugin_disconnect_session().

1493 {
1494  struct GNUNET_SERVER_Handle *server = client->server;
1495  struct NotifyList *n;
1496 
1498  "Client is being disconnected from the server.\n");
1499  if (NULL != client->restart_task)
1500  {
1502  client->restart_task = NULL;
1503  }
1504  if (NULL != client->warn_task)
1505  {
1507  client->warn_task = NULL;
1508  }
1509  if (GNUNET_YES == client->receive_pending)
1510  {
1512  client->receive_pending = GNUNET_NO;
1513  }
1514  client->shutdown_now = GNUNET_YES;
1515  client->reference_count++; /* make sure nobody else clean up client... */
1516  if ( (NULL != client->mst) &&
1517  (NULL != server) )
1518  {
1520  server->clients_tail,
1521  client);
1522  if (NULL != server->mst_destroy)
1523  server->mst_destroy (server->mst_cls,
1524  client->mst);
1525  else
1526  GNUNET_SERVER_mst_destroy (client->mst);
1527  client->mst = NULL;
1528  for (n = server->disconnect_notify_list_head; NULL != n; n = n->next)
1529  n->callback (n->callback_cls,
1530  client);
1531  }
1532  client->reference_count--;
1533  if (client->reference_count > 0)
1534  {
1536  "RC of %p still positive, not destroying everything.\n",
1537  client);
1538  client->server = NULL;
1539  return;
1540  }
1541  if (GNUNET_YES == client->in_process_client_buffer)
1542  {
1544  "Still processing inputs of %p, not destroying everything.\n",
1545  client);
1546  return;
1547  }
1549  "RC of %p now zero, destroying everything.\n",
1550  client);
1551  if (GNUNET_YES == client->persist)
1553  if (NULL != client->th.cth)
1556  /* need to cancel again, as it might have been re-added
1557  in the meantime (i.e. during callbacks) */
1558  if (NULL != client->warn_task)
1559  {
1561  client->warn_task = NULL;
1562  }
1563  if (GNUNET_YES == client->receive_pending)
1564  {
1566  client->receive_pending = GNUNET_NO;
1567  }
1568  GNUNET_free (client);
1569  /* we might be in soft-shutdown, test if we're done */
1570  if (NULL != server)
1571  test_monitor_clients (server);
1572 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
void GNUNET_CONNECTION_persist_(struct GNUNET_CONNECTION_Handle *connection)
Set the persist option on this connection handle.
int in_process_client_buffer
Are we currently in the "process_client_buffer" function (and will hence restart the receive job on e...
List of arrays of message handlers.
struct GNUNET_SERVER_Client * clients_tail
Head of list of our current clients.
#define LOG(kind,...)
Definition: arm_api.c:33
GNUNET_SERVER_MstDestroyCallback mst_destroy
Alternative function to destroy a MST instance.
GNUNET_SERVER_DisconnectCallback callback
Function to call.
#define GNUNET_NO
Definition: gnunet_common.h:81
void * GNUNET_CONNECTION_receive_cancel(struct GNUNET_CONNECTION_Handle *connection)
Cancel receive job on the given connection.
void GNUNET_SERVER_mst_destroy(struct GNUNET_SERVER_MessageStreamTokenizer *mst)
Destroys a tokenizer.
int receive_pending
Are we currently trying to receive? (GNUNET_YES if we are, GNUNET_NO if we are not, GNUNET_SYSERR if data is already available in MST).
void * callback_cls
Closure for callback.
struct NotifyList * next
This is a doubly linked list.
struct GNUNET_CONNECTION_TransmitHandle * cth
Active connection transmission handle.
struct GNUNET_SERVER_TransmitHandle th
Transmission handle we return for this client from GNUNET_SERVER_notify_transmit_ready.
void GNUNET_SERVER_notify_transmit_ready_cancel(struct GNUNET_SERVER_TransmitHandle *th)
Abort transmission request.
struct NotifyList * disconnect_notify_list_head
Head of linked list of functions to call on disconnects by clients.
handle for a server
struct GNUNET_CONNECTION_Handle * connection
Client closure for callbacks.
int shutdown_now
We're about to close down this client.
unsigned int reference_count
Number of external entities with a reference to this client object.
void GNUNET_CONNECTION_destroy(struct GNUNET_CONNECTION_Handle *connection)
Close the connection and free associated resources.
int persist
Persist the file handle for this client no matter what happens, force the OS to close once the proces...
struct GNUNET_SCHEDULER_Task * warn_task
Task that warns about missing calls to GNUNET_SERVER_receive_done.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_SERVER_Client * clients_head
Head of list of our current clients.
static void test_monitor_clients(struct GNUNET_SERVER_Handle *server)
Check if only 'monitor' clients are left.
struct GNUNET_SERVER_Handle * server
Server that this client belongs to.
void * mst_cls
Closure for 'mst_'-callbacks.
void * mst
Processing of incoming data.
struct GNUNET_SCHEDULER_Task * restart_task
ID of task used to restart processing.
#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:

◆ GNUNET_SERVER_client_get_user_context_()

void* GNUNET_SERVER_client_get_user_context_ ( struct GNUNET_SERVER_Client client,
size_t  size 
)

Return user context associated with the given client.

Note: you should probably use the macro (call without the underscore).

Parameters
clientclient to query
sizenumber of bytes in user context struct (for verification only)
Returns
pointer to user context

Definition at line 348 of file tcp_server_legacy.c.

References GNUNET_assert, GNUNET_SERVER_Client::user_context, and GNUNET_SERVER_Client::user_context_size.

350 {
351  if ((0 == client->user_context_size) &&
352  (NULL == client->user_context))
353  return NULL; /* never set */
354  GNUNET_assert (size == client->user_context_size);
355  return client->user_context;
356 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void * user_context
User context value, manipulated using 'GNUNET_SERVER_client_{get/set}_user_context' functions...
size_t user_context_size
Last size given when user context was initialized; used for sanity check.
static unsigned int size
Size of the "table".
Definition: peer.c:67

◆ GNUNET_SERVER_mst_create()

struct GNUNET_SERVER_MessageStreamTokenizer* GNUNET_SERVER_mst_create ( GNUNET_SERVER_MessageTokenizerCallback  cb,
void *  cb_cls 
)

Create a message stream tokenizer.

Parameters
cbfunction to call on completed messages
cb_clsclosure for cb
Returns
handle to tokenizer

Definition at line 86 of file tcp_server_mst_legacy.c.

References GNUNET_SERVER_MessageStreamTokenizer::cb, GNUNET_SERVER_MessageStreamTokenizer::cb_cls, GNUNET_SERVER_MessageStreamTokenizer::curr_buf, GNUNET_malloc, GNUNET_MIN_MESSAGE_SIZE, GNUNET_new, GNUNET_SERVER_MessageStreamTokenizer::hdr, and ret.

Referenced by GNUNET_SERVER_connect_socket(), and LIBGNUNET_PLUGIN_TRANSPORT_INIT().

88 {
90 
94  ret->cb = cb;
95  ret->cb_cls = cb_cls;
96  return ret;
97 }
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int ret
Final status code.
Definition: gnunet-arm.c:89
Handle to a message stream tokenizer.
#define GNUNET_MIN_MESSAGE_SIZE
Smallest supported message.
struct GNUNET_MessageHeader * hdr
Beginning of the buffer.
GNUNET_SERVER_MessageTokenizerCallback cb
Function to call on completed messages.
size_t curr_buf
Size of the buffer (starting at hdr).
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the caller graph for this function:

◆ GNUNET_SERVER_mst_receive()

int GNUNET_SERVER_mst_receive ( struct GNUNET_SERVER_MessageStreamTokenizer mst,
void *  client_identity,
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.

Parameters
msttokenizer to use
client_identityID of client for which this is a buffer, can be NULL (will be passed back to 'cb')
bufinput data to add
sizenumber of bytes in buf
purgeshould any excess bytes in the buffer be discarded (i.e. for packet-based services like UDP)
one_shotonly call callback once, keep rest of message in buffer
Returns
GNUNET_OK if we are done processing (need more data) GNUNET_NO if one_shot was set and we have another message ready GNUNET_SYSERR if the data stream is corrupt
Parameters
msttokenizer to use
client_identityID of client for which this is a buffer
bufinput data to add
sizenumber of bytes in buf
purgeshould any excess bytes in the buffer be discarded (i.e. for packet-based services like UDP)
one_shotonly call callback once, keep rest of message in buffer
Returns
GNUNET_OK if we are done processing (need more data) GNUNET_NO if one_shot was set and we have another message ready GNUNET_SYSERR if the data stream is corrupt

Definition at line 116 of file tcp_server_mst_legacy.c.

References ALIGN_FACTOR, GNUNET_SERVER_MessageStreamTokenizer::cb, GNUNET_SERVER_MessageStreamTokenizer::cb_cls, GNUNET_SERVER_MessageStreamTokenizer::curr_buf, delta, do_align(), GNUNET_assert, GNUNET_break_op, GNUNET_ERROR_TYPE_DEBUG, GNUNET_memcpy, GNUNET_MIN, GNUNET_NO, GNUNET_OK, GNUNET_realloc, GNUNET_SYSERR, GNUNET_YES, GNUNET_SERVER_MessageStreamTokenizer::hdr, LOG, GNUNET_SERVER_MessageStreamTokenizer::off, GNUNET_SERVER_MessageStreamTokenizer::pos, ret, size, and GNUNET_MessageHeader::size.

Referenced by handle_helper_message(), process_data(), process_incoming(), process_mst(), and wlan_data_message_handler().

120 {
121  const struct GNUNET_MessageHeader *hdr;
122  size_t delta;
123  uint16_t want;
124  char *ibuf;
125  int need_align;
126  unsigned long offset;
127  int ret;
128 
129  GNUNET_assert (mst->off <= mst->pos);
130  GNUNET_assert (mst->pos <= mst->curr_buf);
132  "Server-mst receives %u bytes with %u bytes already in private buffer\n",
133  (unsigned int) size, (unsigned int) (mst->pos - mst->off));
134  ret = GNUNET_OK;
135  ibuf = (char *) mst->hdr;
136  while (mst->pos > 0)
137  {
138 do_align:
139  GNUNET_assert (mst->pos >= mst->off);
140  if ((mst->curr_buf - mst->off < sizeof (struct GNUNET_MessageHeader)) ||
141  (0 != (mst->off % ALIGN_FACTOR)))
142  {
143  /* need to align or need more space */
144  mst->pos -= mst->off;
145  memmove (ibuf, &ibuf[mst->off], mst->pos);
146  mst->off = 0;
147  }
148  if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader))
149  {
150  delta =
151  GNUNET_MIN (sizeof (struct GNUNET_MessageHeader) -
152  (mst->pos - mst->off), size);
153  GNUNET_memcpy (&ibuf[mst->pos], buf, delta);
154  mst->pos += delta;
155  buf += delta;
156  size -= delta;
157  }
158  if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader))
159  {
160  if (purge)
161  {
162  mst->off = 0;
163  mst->pos = 0;
164  }
165  return GNUNET_OK;
166  }
167  hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
168  want = ntohs (hdr->size);
169  if (want < sizeof (struct GNUNET_MessageHeader))
170  {
171  GNUNET_break_op (0);
172  return GNUNET_SYSERR;
173  }
174  if ( (mst->curr_buf - mst->off < want) &&
175  (mst->off > 0) )
176  {
177  /* can get more space by moving */
178  mst->pos -= mst->off;
179  memmove (ibuf, &ibuf[mst->off], mst->pos);
180  mst->off = 0;
181  }
182  if (mst->curr_buf < want)
183  {
184  /* need to get more space by growing buffer */
185  GNUNET_assert (0 == mst->off);
186  mst->hdr = GNUNET_realloc (mst->hdr, want);
187  ibuf = (char *) mst->hdr;
188  mst->curr_buf = want;
189  }
190  hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
191  if (mst->pos - mst->off < want)
192  {
193  delta = GNUNET_MIN (want - (mst->pos - mst->off), size);
194  GNUNET_assert (mst->pos + delta <= mst->curr_buf);
195  GNUNET_memcpy (&ibuf[mst->pos], buf, delta);
196  mst->pos += delta;
197  buf += delta;
198  size -= delta;
199  }
200  if (mst->pos - mst->off < want)
201  {
202  if (purge)
203  {
204  mst->off = 0;
205  mst->pos = 0;
206  }
207  return GNUNET_OK;
208  }
209  if (one_shot == GNUNET_SYSERR)
210  {
211  /* cannot call callback again, but return value saying that
212  * we have another full message in the buffer */
213  ret = GNUNET_NO;
214  goto copy;
215  }
216  if (one_shot == GNUNET_YES)
217  one_shot = GNUNET_SYSERR;
218  mst->off += want;
219  if (GNUNET_SYSERR == mst->cb (mst->cb_cls, client_identity, hdr))
220  return GNUNET_SYSERR;
221  if (mst->off == mst->pos)
222  {
223  /* reset to beginning of buffer, it's free right now! */
224  mst->off = 0;
225  mst->pos = 0;
226  }
227  }
228  GNUNET_assert (0 == mst->pos);
229  while (size > 0)
230  {
232  "Server-mst has %u bytes left in inbound buffer\n",
233  (unsigned int) size);
234  if (size < sizeof (struct GNUNET_MessageHeader))
235  break;
236  offset = (unsigned long) buf;
237  need_align = (0 != (offset % ALIGN_FACTOR)) ? GNUNET_YES : GNUNET_NO;
238  if (GNUNET_NO == need_align)
239  {
240  /* can try to do zero-copy and process directly from original buffer */
241  hdr = (const struct GNUNET_MessageHeader *) buf;
242  want = ntohs (hdr->size);
243  if (want < sizeof (struct GNUNET_MessageHeader))
244  {
245  GNUNET_break_op (0);
246  mst->off = 0;
247  return GNUNET_SYSERR;
248  }
249  if (size < want)
250  break; /* or not: buffer incomplete, so copy to private buffer... */
251  if (one_shot == GNUNET_SYSERR)
252  {
253  /* cannot call callback again, but return value saying that
254  * we have another full message in the buffer */
255  ret = GNUNET_NO;
256  goto copy;
257  }
258  if (one_shot == GNUNET_YES)
259  one_shot = GNUNET_SYSERR;
260  if (GNUNET_SYSERR == mst->cb (mst->cb_cls, client_identity, hdr))
261  return GNUNET_SYSERR;
262  buf += want;
263  size -= want;
264  }
265  else
266  {
267  /* need to copy to private buffer to align;
268  * yes, we go a bit more spagetti than usual here */
269  goto do_align;
270  }
271  }
272 copy:
273  if ((size > 0) && (!purge))
274  {
275  if (size + mst->pos > mst->curr_buf)
276  {
277  mst->hdr = GNUNET_realloc (mst->hdr, size + mst->pos);
278  ibuf = (char *) mst->hdr;
279  mst->curr_buf = size + mst->pos;
280  }
281  GNUNET_assert (size + mst->pos <= mst->curr_buf);
282  GNUNET_memcpy (&ibuf[mst->pos], buf, size);
283  mst->pos += size;
284  }
285  if (purge)
286  {
287  mst->off = 0;
288  mst->pos = 0;
289  }
291  "Server-mst leaves %u bytes in private buffer\n",
292  (unsigned int) (mst->pos - mst->off));
293  return ret;
294 }
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:35
#define ALIGN_FACTOR
static size_t do_align(size_t start_position, size_t end_position)
Given the start and end position of a block of data, return the end position of that data after align...
Definition: fs_directory.c:484
#define LOG(kind,...)
Definition: arm_api.c:33
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
size_t pos
How many bytes in buffer are valid right now?
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
static int ret
Final status code.
Definition: gnunet-arm.c:89
size_t off
How many bytes in buffer have we already processed?
#define GNUNET_memcpy(dst, src, n)
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:83
static char buf[2048]
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static unsigned int size
Size of the "table".
Definition: peer.c:67
struct GNUNET_MessageHeader * hdr
Beginning of the buffer.
GNUNET_SERVER_MessageTokenizerCallback cb
Function to call on completed messages.
size_t curr_buf
Size of the buffer (starting at hdr).
Header for all communications.
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_mst_destroy()

void GNUNET_SERVER_mst_destroy ( struct GNUNET_SERVER_MessageStreamTokenizer mst)

Destroys a tokenizer.

Parameters
msttokenizer to destroy

Definition at line 303 of file tcp_server_mst_legacy.c.

References GNUNET_free, and GNUNET_SERVER_MessageStreamTokenizer::hdr.

Referenced by GNUNET_SERVER_client_disconnect(), and LIBGNUNET_PLUGIN_TRANSPORT_DONE().

304 {
305  GNUNET_free (mst->hdr);
306  GNUNET_free (mst);
307 }
struct GNUNET_MessageHeader * hdr
Beginning of the buffer.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ GNUNET_SERVER_client_set_user_context_()

void GNUNET_SERVER_client_set_user_context_ ( struct GNUNET_SERVER_Client client,
void *  ptr,
size_t  size 
)

Set user context to be associated with the given client.

Note: you should probably use the macro (call without the underscore).

Parameters
clientclient to query
ptrpointer to user context
sizenumber of bytes in user context struct (for verification only)

Definition at line 368 of file tcp_server_legacy.c.

References size, GNUNET_SERVER_Client::user_context, and GNUNET_SERVER_Client::user_context_size.

371 {
372  if (NULL == ptr)
373  {
374  client->user_context_size = 0;
375  client->user_context = ptr;
376  return;
377  }
378  client->user_context_size = size;
379  client->user_context = ptr;
380 }
void * user_context
User context value, manipulated using &#39;GNUNET_SERVER_client_{get/set}_user_context&#39; functions...
size_t user_context_size
Last size given when user context was initialized; used for sanity check.
static unsigned int size
Size of the "table".
Definition: peer.c:67

◆ GNUNET_SERVER_notify_transmit_ready()

struct GNUNET_SERVER_TransmitHandle * GNUNET_SERVER_notify_transmit_ready ( struct GNUNET_SERVER_Client client,
size_t  size,
struct GNUNET_TIME_Relative  timeout,
GNUNET_CONNECTION_TransmitReadyNotify  callback,
void *  callback_cls 
)

Notify us when the server has enough space to transmit a message of the given size to the given client.

Parameters
clientclient to transmit message to
sizerequested amount of buffer space
timeoutafter how long should we give up (and call notify with buf NULL and size 0)?
callbackfunction to call when space is available
callback_clsclosure for callback
Returns
non-NULL if the notify callback was queued; can be used to cancel the request using GNUNET_SERVER_notify_transmit_ready_cancel. NULL if we are already going to notify someone else (busy)
Parameters
clientclient to transmit message to
sizerequested amount of buffer space
timeoutafter how long should we give up (and call notify with buf NULL and size 0)?
callbackfunction to call when space is available
callback_clsclosure for callback
Returns
non-NULL if the notify callback was queued; can be used to cancel the request using GNUNET_SERVER_notify_transmit_ready_cancel(). NULL if we are already going to notify someone else (busy)

Definition at line 1629 of file tcp_server_legacy.c.

References GNUNET_SERVER_TransmitHandle::callback, GNUNET_SERVER_TransmitHandle::callback_cls, GNUNET_SERVER_Client::connection, GNUNET_SERVER_TransmitHandle::cth, GNUNET_CONNECTION_notify_transmit_ready(), GNUNET_SERVER_Client::th, and transmit_ready_callback_wrapper().

Referenced by handle_test(), and process_pending_messages().

1634 {
1635  if (NULL != client->th.callback)
1636  return NULL;
1637  client->th.callback_cls = callback_cls;
1638  client->th.callback = callback;
1640  timeout,
1642  client);
1643  return &client->th;
1644 }
struct GNUNET_CONNECTION_TransmitHandle * cth
Active connection transmission handle.
struct GNUNET_SERVER_TransmitHandle th
Transmission handle we return for this client from GNUNET_SERVER_notify_transmit_ready.
struct GNUNET_CONNECTION_Handle * connection
Client closure for callbacks.
static unsigned int size
Size of the "table".
Definition: peer.c:67
GNUNET_CONNECTION_TransmitReadyNotify callback
Function to call to get the message.
struct GNUNET_CONNECTION_TransmitHandle * GNUNET_CONNECTION_notify_transmit_ready(struct GNUNET_CONNECTION_Handle *connection, size_t size, struct GNUNET_TIME_Relative timeout, GNUNET_CONNECTION_TransmitReadyNotify notify, void *notify_cls)
Ask the connection to call us once the specified number of bytes are free in the transmission buffer...
void * callback_cls
Closure for callback.
static size_t transmit_ready_callback_wrapper(void *cls, size_t size, void *buf)
Wrapper for transmission notification that calls the original callback and update the last activity t...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_notify_transmit_ready_cancel()

void GNUNET_SERVER_notify_transmit_ready_cancel ( struct GNUNET_SERVER_TransmitHandle th)

Abort transmission request.

Parameters
threquest to abort

Definition at line 1653 of file tcp_server_legacy.c.

References GNUNET_SERVER_TransmitHandle::callback, GNUNET_SERVER_TransmitHandle::cth, and GNUNET_CONNECTION_notify_transmit_ready_cancel().

Referenced by GNUNET_SERVER_client_disconnect(), and tcp_plugin_disconnect_session().

1654 {
1656  th->cth = NULL;
1657  th->callback = NULL;
1658 }
void GNUNET_CONNECTION_notify_transmit_ready_cancel(struct GNUNET_CONNECTION_TransmitHandle *th)
Cancel the specified transmission-ready notification.
struct GNUNET_CONNECTION_TransmitHandle * cth
Active connection transmission handle.
GNUNET_CONNECTION_TransmitReadyNotify callback
Function to call to get the message.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_client_keep()

void GNUNET_SERVER_client_keep ( struct GNUNET_SERVER_Client client)

Notify the server that the given client handle should be kept (keeps the connection up if possible, increments the internal reference counter).

Parameters
clientthe client to keep

Definition at line 1327 of file tcp_server_legacy.c.

References GNUNET_SERVER_Client::reference_count.

Referenced by process_incoming(), and restart_processing().

1328 {
1329  client->reference_count++;
1330 }
unsigned int reference_count
Number of external entities with a reference to this client object.
Here is the caller graph for this function:

◆ GNUNET_SERVER_client_drop()

void GNUNET_SERVER_client_drop ( struct GNUNET_SERVER_Client client)

Notify the server that the given client handle is no longer required.

Decrements the reference counter. If that counter reaches zero an inactive connection maybe closed.

Parameters
clientthe client to drop

Definition at line 1342 of file tcp_server_legacy.c.

References GNUNET_assert, GNUNET_SERVER_client_disconnect(), GNUNET_YES, GNUNET_SERVER_Client::reference_count, and GNUNET_SERVER_Client::shutdown_now.

Referenced by process_incoming(), and restart_processing().

1343 {
1344  GNUNET_assert (client->reference_count > 0);
1345  client->reference_count--;
1346  if ((GNUNET_YES == client->shutdown_now) && (0 == client->reference_count))
1348 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int shutdown_now
We&#39;re about to close down this client.
unsigned int reference_count
Number of external entities with a reference to this client object.
void GNUNET_SERVER_client_disconnect(struct GNUNET_SERVER_Client *client)
Ask the server to disconnect from the given client.
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_suspend()

void GNUNET_SERVER_suspend ( struct GNUNET_SERVER_Handle server)

Suspend accepting connections from the listen socket temporarily.

Resume activity using GNUNET_SERVER_resume.

Parameters
serverserver to stop accepting connections.
serverserver to stop accepting connections.

Definition at line 687 of file tcp_server_legacy.c.

References GNUNET_SCHEDULER_cancel(), and GNUNET_SERVER_Handle::listen_task.

Referenced by connect_notify().

688 {
689  if (NULL != server->listen_task)
690  {
692  server->listen_task = NULL;
693  }
694 }
struct GNUNET_SCHEDULER_Task * listen_task
Task scheduled to do the listening.
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:

◆ GNUNET_SERVER_connect_socket()

struct GNUNET_SERVER_Client* GNUNET_SERVER_connect_socket ( struct GNUNET_SERVER_Handle server,
struct GNUNET_CONNECTION_Handle connection 
)

Add a TCP socket-based connection to the set of handles managed by this server.

Use this function for outgoing (P2P) connections that we initiated (and where this server should process incoming messages).

Parameters
serverthe server to use
connectionthe connection to manage (client must stop using this connection from now on)
Returns
the client handle

Definition at line 1267 of file tcp_server_legacy.c.

References NotifyList::callback, NotifyList::callback_cls, client_message_tokenizer_callback(), GNUNET_SERVER_Handle::clients_head, GNUNET_SERVER_Handle::clients_tail, GNUNET_SERVER_Handle::connect_notify_list_head, GNUNET_SERVER_Client::connection, GNUNET_assert, GNUNET_CONNECTION_receive(), GNUNET_CONTAINER_DLL_insert, GNUNET_MAX_MESSAGE_SIZE, GNUNET_new, GNUNET_SERVER_mst_create(), GNUNET_SYSERR, GNUNET_TIME_absolute_get(), GNUNET_YES, GNUNET_SERVER_Handle::idle_timeout, GNUNET_SERVER_Client::idle_timeout, GNUNET_SERVER_Client::last_activity, GNUNET_SERVER_Client::mst, GNUNET_SERVER_Handle::mst_cls, GNUNET_SERVER_Handle::mst_create, NotifyList::next, process_incoming(), GNUNET_SERVER_Client::receive_pending, and GNUNET_SERVER_Client::server.

Referenced by notify_send_probe(), process_listen_socket(), and tcp_plugin_get_session().

1269 {
1270  struct GNUNET_SERVER_Client *client;
1271  struct NotifyList *n;
1272 
1273  client = GNUNET_new (struct GNUNET_SERVER_Client);
1274  client->connection = connection;
1275  client->server = server;
1277  client->idle_timeout = server->idle_timeout;
1279  server->clients_tail,
1280  client);
1281  if (NULL != server->mst_create)
1282  client->mst =
1283  server->mst_create (server->mst_cls, client);
1284  else
1285  client->mst =
1287  server);
1288  GNUNET_assert (NULL != client->mst);
1289  for (n = server->connect_notify_list_head; NULL != n; n = n->next)
1290  n->callback (n->callback_cls, client);
1291  client->receive_pending = GNUNET_YES;
1292  if (GNUNET_SYSERR ==
1295  client->idle_timeout,
1297  client))
1298  return NULL;
1299  return client;
1300 }
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct NotifyList * connect_notify_list_head
Head of linked list of functions to call on connects by clients.
List of arrays of message handlers.
struct GNUNET_SERVER_Client * clients_tail
Head of list of our current clients.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_TIME_Absolute last_activity
Last activity on this socket (used to time it out if reference_count == 0).
GNUNET_SERVER_DisconnectCallback callback
Function to call.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
int receive_pending
Are we currently trying to receive? (GNUNET_YES if we are, GNUNET_NO if we are not, GNUNET_SYSERR if data is already available in MST).
void * callback_cls
Closure for callback.
struct NotifyList * next
This is a doubly linked list.
struct GNUNET_TIME_Relative idle_timeout
After how long should an idle connection time out (on write).
struct GNUNET_TIME_Relative idle_timeout
After how long should an idle connection time out (on write).
int GNUNET_CONNECTION_receive(struct GNUNET_CONNECTION_Handle *connection, size_t max, struct GNUNET_TIME_Relative timeout, GNUNET_CONNECTION_Receiver receiver, void *receiver_cls)
Receive data from the given connection.
GNUNET_SERVER_MstCreateCallback mst_create
Alternative function to create a MST instance.
struct GNUNET_CONNECTION_Handle * connection
Client closure for callbacks.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
static void process_incoming(void *cls, const void *buf, size_t available, const struct sockaddr *addr, socklen_t addrlen, int errCode)
We are receiving an incoming message.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static int client_message_tokenizer_callback(void *cls, void *client, const struct GNUNET_MessageHeader *message)
This function is called whenever our inbound message tokenizer has received a complete message...
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
#define GNUNET_YES
Definition: gnunet_common.h:80
handle for a client of the server
struct GNUNET_SERVER_Client * clients_head
Head of list of our current clients.
struct GNUNET_SERVER_Handle * server
Server that this client belongs to.
void * mst_cls
Closure for &#39;mst_&#39;-callbacks.
void * mst
Processing of incoming data.
struct GNUNET_SERVER_MessageStreamTokenizer * GNUNET_SERVER_mst_create(GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_resume()

void GNUNET_SERVER_resume ( struct GNUNET_SERVER_Handle server)

Resume accepting connections from the listen socket.

Parameters
serverserver to resume accepting connections.
serverserver to stop accepting connections.

Definition at line 703 of file tcp_server_legacy.c.

References GNUNET_NETWORK_fdset_create(), GNUNET_NETWORK_fdset_destroy(), GNUNET_NETWORK_fdset_set(), GNUNET_SCHEDULER_add_read_net_with_priority(), GNUNET_SCHEDULER_add_select(), GNUNET_SCHEDULER_PRIORITY_HIGH, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_SERVER_Handle::listen_sockets, GNUNET_SERVER_Handle::listen_task, and process_listen_socket().

Referenced by disconnect_notify(), GNUNET_SERVER_create_with_sockets(), and process_listen_socket().

704 {
705  struct GNUNET_NETWORK_FDSet *r;
706  unsigned int i;
707 
708  if (NULL == server->listen_sockets)
709  return;
710  if (NULL == server->listen_sockets[0])
711  return; /* nothing to do, no listen sockets! */
712  if (NULL == server->listen_sockets[1])
713  {
714  /* simplified method: no fd set needed; this is then much simpler
715  and much more efficient */
716  server->listen_task =
719  server->listen_sockets[0],
720  &process_listen_socket, server);
721  return;
722  }
724  i = 0;
725  while (NULL != server->listen_sockets[i])
726  GNUNET_NETWORK_fdset_set (r, server->listen_sockets[i++]);
727  server->listen_task =
730  &process_listen_socket, server);
732 }
Run with high priority (important requests).
struct GNUNET_NETWORK_Handle ** listen_sockets
NULL-terminated array of sockets used to listen for new connections.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net_with_priority(struct GNUNET_TIME_Relative delay, enum GNUNET_SCHEDULER_Priority priority, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified priority and to be run after the specified delay or wh...
Definition: scheduler.c:1512
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
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
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static void process_listen_socket(void *cls)
Scheduler says our listen socket is ready.
void GNUNET_NETWORK_fdset_set(struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_NETWORK_Handle *desc)
Add a socket to the FD set.
Definition: network.c:1163
struct GNUNET_SCHEDULER_Task * listen_task
Task scheduled to do the listening.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_destroy()

void GNUNET_SERVER_destroy ( struct GNUNET_SERVER_Handle server)

Free resources held by this server.

Parameters
serverserver to destroy

Definition at line 774 of file tcp_server_legacy.c.

References NotifyList::callback, NotifyList::callback_cls, GNUNET_SERVER_Handle::clients_head, GNUNET_SERVER_Handle::connect_notify_list_head, GNUNET_SERVER_Handle::connect_notify_list_tail, GNUNET_SERVER_Handle::disconnect_notify_list_head, GNUNET_SERVER_Handle::disconnect_notify_list_tail, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_NETWORK_socket_close(), GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_SERVER_client_disconnect(), GNUNET_SERVER_Handle::handlers, GNUNET_SERVER_Handle::listen_sockets, GNUNET_SERVER_Handle::listen_task, LOG, and HandlerList::next.

Referenced by do_destroy(), LEGACY_SERVICE_stop(), libgnunet_plugin_transport_tcp_done(), and shutdown_task().

775 {
776  struct HandlerList *hpos;
777  struct NotifyList *npos;
778  unsigned int i;
779 
781  "Server shutting down.\n");
782  if (NULL != server->listen_task)
783  {
785  server->listen_task = NULL;
786  }
787  if (NULL != server->listen_sockets)
788  {
789  i = 0;
790  while (NULL != server->listen_sockets[i])
793  GNUNET_free (server->listen_sockets);
794  server->listen_sockets = NULL;
795  }
796  while (NULL != server->clients_head)
798  while (NULL != (hpos = server->handlers))
799  {
800  server->handlers = hpos->next;
801  GNUNET_free (hpos);
802  }
803  while (NULL != (npos = server->disconnect_notify_list_head))
804  {
805  npos->callback (npos->callback_cls,
806  NULL);
809  npos);
810  GNUNET_free (npos);
811  }
812  while (NULL != (npos = server->connect_notify_list_head))
813  {
814  npos->callback (npos->callback_cls,
815  NULL);
817  server->connect_notify_list_tail,
818  npos);
819  GNUNET_free (npos);
820  }
821  GNUNET_free (server);
822 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
List of arrays of message handlers.
struct NotifyList * connect_notify_list_head
Head of linked list of functions to call on connects by clients.
List of arrays of message handlers.
struct GNUNET_NETWORK_Handle ** listen_sockets
NULL-terminated array of sockets used to listen for new connections.
#define LOG(kind,...)
Definition: arm_api.c:33
GNUNET_SERVER_DisconnectCallback callback
Function to call.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
void * callback_cls
Closure for callback.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct HandlerList * handlers
List of handlers for incoming messages.
struct NotifyList * disconnect_notify_list_head
Head of linked list of functions to call on disconnects by clients.
void GNUNET_SERVER_client_disconnect(struct GNUNET_SERVER_Client *client)
Ask the server to disconnect from the given client.
struct GNUNET_SCHEDULER_Task * listen_task
Task scheduled to do the listening.
struct NotifyList * disconnect_notify_list_tail
Tail of linked list of functions to call on disconnects by clients.
struct NotifyList * connect_notify_list_tail
Tail of linked list of functions to call on connects by clients.
struct GNUNET_SERVER_Client * clients_head
Head of list of our current clients.
struct HandlerList * next
This is a linked list.
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:604
#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:

◆ get_server_addresses()

static int get_server_addresses ( const char *  service_name,
const struct GNUNET_CONFIGURATION_Handle cfg,
struct sockaddr ***  addrs,
socklen_t **  addr_lens 
)
static

Get the list of addresses that a server for the given service should bind to.

Parameters
service_namename of the service
cfgconfiguration (which specifies the addresses)
addrsset (call by reference) to an array of pointers to the addresses the server should bind to and listen on; the array will be NULL-terminated (on success)
addr_lensset (call by reference) to an array of the lengths of the respective struct sockaddr struct in the addrs array (on success)
Returns
number of addresses found on success, GNUNET_SYSERR if the configuration did not specify reasonable finding information or if it specified a hostname that could not be resolved; GNUNET_NO if the number of addresses configured is zero (in this case, *addrs and *addr_lens will be set to NULL).

Definition at line 1073 of file plugin_transport_tcp.c.

References _, add_unixpath(), GNUNET_a2s(), GNUNET_assert, GNUNET_break, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONFIGURATION_have_value(), GNUNET_DISK_directory_create_for_file(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_free_non_null, GNUNET_log_strerror, GNUNET_log_strerror_file, GNUNET_malloc, GNUNET_memcpy, GNUNET_NETWORK_shorten_unixpath(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_create(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, hostname, LOG, port, res, ret, and STRERROR.

Referenced by libgnunet_plugin_transport_tcp_init().

1077 {
1078  int disablev6;
1079  struct GNUNET_NETWORK_Handle *desc;
1080  unsigned long long port;
1081  char *unixpath;
1082  struct addrinfo hints;
1083  struct addrinfo *res;
1084  struct addrinfo *pos;
1085  struct addrinfo *next;
1086  unsigned int i;
1087  int resi;
1088  int ret;
1089  int abstract;
1090  struct sockaddr **saddrs;
1091  socklen_t *saddrlens;
1092  char *hostname;
1093 
1094  *addrs = NULL;
1095  *addr_lens = NULL;
1096  desc = NULL;
1097  if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6"))
1098  {
1099  if (GNUNET_SYSERR ==
1100  (disablev6 =
1102  return GNUNET_SYSERR;
1103  }
1104  else
1105  disablev6 = GNUNET_NO;
1106 
1107  if (! disablev6)
1108  {
1109  /* probe IPv6 support */
1110  desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
1111  if (NULL == desc)
1112  {
1113  if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
1114  (EACCES == errno))
1115  {
1117  return GNUNET_SYSERR;
1118  }
1120  _("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
1121  service_name, STRERROR (errno));
1122  disablev6 = GNUNET_YES;
1123  }
1124  else
1125  {
1127  desc = NULL;
1128  }
1129  }
1130 
1131  port = 0;
1132  if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT"))
1133  {
1134  if (GNUNET_OK !=
1136  "PORT", &port))
1137  {
1139  _("Require valid port number for service `%s' in configuration!\n"),
1140  service_name);
1141  }
1142  if (port > 65535)
1143  {
1145  _("Require valid port number for service `%s' in configuration!\n"),
1146  service_name);
1147  return GNUNET_SYSERR;
1148  }
1149  }
1150 
1151  if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO"))
1152  {
1155  "BINDTO", &hostname));
1156  }
1157  else
1158  hostname = NULL;
1159 
1160  unixpath = NULL;
1161  abstract = GNUNET_NO;
1162 #ifdef AF_UNIX
1163  if ((GNUNET_YES ==
1164  GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) &&
1165  (GNUNET_OK ==
1167  &unixpath)) &&
1168  (0 < strlen (unixpath)))
1169  {
1170  /* probe UNIX support */
1171  struct sockaddr_un s_un;
1172 
1173  if (strlen (unixpath) >= sizeof (s_un.sun_path))
1174  {
1176  _("UNIXPATH `%s' too long, maximum length is %llu\n"), unixpath,
1177  (unsigned long long) sizeof (s_un.sun_path));
1178  unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath);
1180  _("Using `%s' instead\n"),
1181  unixpath);
1182  }
1183 #ifdef LINUX
1184  abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
1185  "TESTING",
1186  "USE_ABSTRACT_SOCKETS");
1187  if (GNUNET_SYSERR == abstract)
1188  abstract = GNUNET_NO;
1189 #endif
1190  if ((GNUNET_YES != abstract)
1191  && (GNUNET_OK !=
1194  "mkdir",
1195  unixpath);
1196  }
1197  if (NULL != unixpath)
1198  {
1199  desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
1200  if (NULL == desc)
1201  {
1202  if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
1203  (EACCES == errno))
1204  {
1206  GNUNET_free_non_null (hostname);
1207  GNUNET_free (unixpath);
1208  return GNUNET_SYSERR;
1209  }
1211  _("Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
1212  service_name,
1213  STRERROR (errno));
1214  GNUNET_free (unixpath);
1215  unixpath = NULL;
1216  }
1217  else
1218  {
1220  desc = NULL;
1221  }
1222  }
1223 #endif
1224 
1225  if ((0 == port) && (NULL == unixpath))
1226  {
1228  _("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
1229  service_name);
1230  GNUNET_free_non_null (hostname);
1231  return GNUNET_SYSERR;
1232  }
1233  if (0 == port)
1234  {
1235  saddrs = GNUNET_malloc (2 * sizeof (struct sockaddr *));
1236  saddrlens = GNUNET_malloc (2 * sizeof (socklen_t));
1237  add_unixpath (saddrs, saddrlens, unixpath, abstract);
1238  GNUNET_free_non_null (unixpath);
1239  GNUNET_free_non_null (hostname);
1240  *addrs = saddrs;
1241  *addr_lens = saddrlens;
1242  return 1;
1243  }
1244 
1245  if (NULL != hostname)
1246  {
1248  "Resolving `%s' since that is where `%s' will bind to.\n",
1249  hostname,
1250  service_name);
1251  memset (&hints, 0, sizeof (struct addrinfo));
1252  if (disablev6)
1253  hints.ai_family = AF_INET;
1254  hints.ai_protocol = IPPROTO_TCP;
1255  if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
1256  (NULL == res))
1257  {
1259  _("Failed to resolve `%s': %s\n"),
1260  hostname,
1261  gai_strerror (ret));
1262  GNUNET_free (hostname);
1263  GNUNET_free_non_null (unixpath);
1264  return GNUNET_SYSERR;
1265  }
1266  next = res;
1267  i = 0;
1268  while (NULL != (pos = next))
1269  {
1270  next = pos->ai_next;
1271  if ((disablev6) && (pos->ai_family == AF_INET6))
1272  continue;
1273  i++;
1274  }
1275  if (0 == i)
1276  {
1278  _("Failed to find %saddress for `%s'.\n"),
1279  disablev6 ? "IPv4 " : "",
1280  hostname);
1281  freeaddrinfo (res);
1282  GNUNET_free (hostname);
1283  GNUNET_free_non_null (unixpath);
1284  return GNUNET_SYSERR;
1285  }
1286  resi = i;
1287  if (NULL != unixpath)
1288  resi++;
1289  saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
1290  saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
1291  i = 0;
1292  if (NULL != unixpath)
1293  {
1294  add_unixpath (saddrs, saddrlens, unixpath, abstract);
1295  i++;
1296  }
1297  next = res;
1298  while (NULL != (pos = next))
1299  {
1300  next = pos->ai_next;
1301  if ((disablev6) && (AF_INET6 == pos->ai_family))
1302  continue;
1303  if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
1304  continue; /* not TCP */
1305  if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
1306  continue; /* huh? */
1307  LOG (GNUNET_ERROR_TYPE_DEBUG, "Service `%s' will bind to `%s'\n",
1308  service_name, GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
1309  if (AF_INET == pos->ai_family)
1310  {
1311  GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen);
1312  saddrlens[i] = pos->ai_addrlen;
1313  saddrs[i] = GNUNET_malloc (saddrlens[i]);
1314  GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
1315  ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1316  }
1317  else
1318  {
1319  GNUNET_assert (AF_INET6 == pos->ai_family);
1320  GNUNET_assert (sizeof (struct sockaddr_in6) == pos->ai_addrlen);
1321  saddrlens[i] = pos->ai_addrlen;
1322  saddrs[i] = GNUNET_malloc (saddrlens[i]);
1323  GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
1324  ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
1325  }
1326  i++;
1327  }
1328  GNUNET_free (hostname);
1329  freeaddrinfo (res);
1330  resi = i;
1331  }
1332  else
1333  {
1334  /* will bind against everything, just set port */
1335  if (disablev6)
1336  {
1337  /* V4-only */
1338  resi = 1;
1339  if (NULL != unixpath)
1340  resi++;
1341  i = 0;
1342  saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
1343  saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
1344  if (NULL != unixpath)
1345  {
1346  add_unixpath (saddrs, saddrlens, unixpath, abstract);
1347  i++;
1348  }
1349  saddrlens[i] = sizeof (struct sockaddr_in);
1350  saddrs[i] = GNUNET_malloc (saddrlens[i]);
1351 #if HAVE_SOCKADDR_IN_SIN_LEN
1352  ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i];
1353 #endif
1354  ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
1355  ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1356  }
1357  else
1358  {
1359  /* dual stack */
1360  resi = 2;
1361  if (NULL != unixpath)
1362  resi++;
1363  saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
1364  saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
1365  i = 0;
1366  if (NULL != unixpath)
1367  {
1368  add_unixpath (saddrs, saddrlens, unixpath, abstract);
1369  i++;
1370  }
1371  saddrlens[i] = sizeof (struct sockaddr_in6);
1372  saddrs[i] = GNUNET_malloc (saddrlens[i]);
1373 #if HAVE_SOCKADDR_IN_SIN_LEN
1374  ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0];
1375 #endif
1376  ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6;
1377  ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
1378  i++;
1379  saddrlens[i] = sizeof (struct sockaddr_in);
1380  saddrs[i] = GNUNET_malloc (saddrlens[i]);
1381 #if HAVE_SOCKADDR_IN_SIN_LEN
1382  ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1];
1383 #endif
1384  ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
1385  ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1386  }
1387  }
1388  GNUNET_free_non_null (unixpath);
1389  *addrs = saddrs;
1390  *addr_lens = saddrlens;
1391  return resi;
1392 }
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.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define STRERROR(i)
Definition: plibc.h:676
int GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:833
#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.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
#define GNUNET_memcpy(dst, src, n)
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
int GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
static int res
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
static char * hostname
Our hostname; we give this to all the peers we start.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:79
int GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
handle to a socket
Definition: network.c:46
char * GNUNET_NETWORK_shorten_unixpath(char *unixpath)
Given a unixpath that is too long (larger than UNIX_PATH_MAX), shorten it to an acceptable length whi...
Definition: network.c:157
#define GNUNET_YES
Definition: gnunet_common.h:80
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".
#define LOG(kind,...)
static void add_unixpath(struct sockaddr **saddrs, socklen_t *saddrlens, const char *unixpath, int abstract)
Add the given UNIX domain path as an address to the list (as the first entry).
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:604
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:1037
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 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 1405 of file plugin_transport_tcp.c.

References GNUNET_ATS_Session::address, GNUNET_TRANSPORT_SessionInfo::address, GNUNET_ATS_Session::bytes_in_queue, GNUNET_HELLO_address_check_option(), GNUNET_HELLO_ADDRESS_INFO_INBOUND, GNUNET_TRANSPORT_SessionInfo::is_inbound, GNUNET_ATS_Session::msgs_in_queue, GNUNET_TRANSPORT_SessionInfo::num_bytes_pending, GNUNET_TRANSPORT_SessionInfo::num_msg_pending, GNUNET_TRANSPORT_SessionInfo::receive_delay, GNUNET_ATS_Session::receive_delay, GNUNET_ATS_Session::receive_delay_task, GNUNET_TRANSPORT_SessionInfo::session_timeout, Plugin::sic, Plugin::sic_cls, state, GNUNET_TRANSPORT_SessionInfo::state, and GNUNET_ATS_Session::timeout.

Referenced by create_session(), do_transmit(), send_session_info_iter(), session_timeout(), tcp_plugin_disconnect_session(), and tcp_plugin_send().

1408 {
1409  struct GNUNET_TRANSPORT_SessionInfo info;
1410 
1411  if (NULL == plugin->sic)
1412  return;
1413  memset (&info, 0, sizeof (info));
1414  info.state = state;
1415  info.is_inbound = GNUNET_HELLO_address_check_option (session->address,
1417  info.num_msg_pending = session->msgs_in_queue;
1418  info.num_bytes_pending = session->bytes_in_queue;
1419  if (NULL != session->receive_delay_task)
1420  info.receive_delay = session->receive_delay;
1421  info.session_timeout = session->timeout;
1422  info.address = session->address;
1423  plugin->sic (plugin->sic_cls,
1424  session,
1425  &info);
1426 }
GNUNET_TRANSPORT_SessionInfoCallback sic
Function to call about session status changes.
struct GNUNET_TIME_Absolute receive_delay
When will we continue to read from the socket? (used to enforce inbound quota).
unsigned int msgs_in_queue
Number of messages waiting for transmission to this peer.
struct GNUNET_SCHEDULER_Task * receive_delay_task
ID of task used to delay receiving more to throttle sender.
struct GNUNET_TIME_Absolute timeout
When does this session time out.
struct GNUNET_HELLO_Address * address
Address.
unsigned long long bytes_in_queue
Number of bytes waiting for transmission to this peer.
int GNUNET_HELLO_address_check_option(const struct GNUNET_HELLO_Address *address, enum GNUNET_HELLO_AddressInfo option)
Check if an address has a local option set.
Definition: address.c:39
Information about a plugin&#39;s session.
enum State state
current state of profiling
This is an inbound address and cannot be used to initiate an outbound connection to another peer...
void * sic_cls
Closure for sic.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcp_nat_port_map_callback()

static void tcp_nat_port_map_callback ( void *  cls,
void **  app_ctx,
int  add_remove,
enum GNUNET_NAT_AddressClass  ac,
const struct sockaddr *  addr,
socklen_t  addrlen 
)
static

Our external IP address/port mapping has changed.

Parameters
clsclosure, the struct Plugin
app_ctx[in,out]location where the app can store stuff on add and retrieve it on remove
add_removeGNUNET_YES to mean the new public IP address, GNUNET_NO to mean the previous (now invalid) one
acaddress class the address belongs to
addreither the previous or the new public IP address
addrlenactual length of addr

Definition at line 1442 of file plugin_transport_tcp.c.

References address, find_typedefs::arg, gnunet-chk::args, GNUNET_DATACACHE_PluginEnvironment::cls, Plugin::env, GNUNET_a2s(), GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_INFO, GNUNET_HELLO_address_allocate(), GNUNET_HELLO_address_free, GNUNET_HELLO_ADDRESS_INFO_NONE, GNUNET_memcpy, GNUNET_YES, IPv4TcpAddress::ipv4_addr, IPv6TcpAddress::ipv6_addr, LOG, Plugin::myoptions, IPv4TcpAddress::options, IPv6TcpAddress::options, plugin, PLUGIN_NAME, t4, IPv4TcpAddress::t4_port, t6, and IPv6TcpAddress::t6_port.

Referenced by libgnunet_plugin_transport_tcp_init().

1448 {
1449  struct Plugin *plugin = cls;
1450  struct GNUNET_HELLO_Address *address;
1451  struct IPv4TcpAddress t4;
1452  struct IPv6TcpAddress t6;
1453  void *arg;
1454  size_t args;
1455 
1456  (void) app_ctx;
1458  "NAT notification to %s address `%s'\n",
1459  (GNUNET_YES == add_remove) ? "add" : "remove",
1460  GNUNET_a2s (addr, addrlen));
1461  /* convert 'addr' to our internal format */
1462  switch (addr->sa_family)
1463  {
1464  case AF_INET:
1465  GNUNET_assert(addrlen == sizeof(struct sockaddr_in));
1466  memset (&t4, 0, sizeof(t4));
1467  t4.options = htonl (plugin->myoptions);
1468  t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
1469  t4.t4_port = ((struct sockaddr_in *) addr)->sin_port;
1470  arg = &t4;
1471  args = sizeof (t4);
1472  break;
1473  case AF_INET6:
1474  if (IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr))
1475  {
1476  /* skip link local, we don't allow them in
1477  #tcp_plugin_check_address() */
1478  return;
1479  }
1480  GNUNET_assert(addrlen == sizeof(struct sockaddr_in6));
1481  memset (&t6, 0, sizeof(t6));
1482  GNUNET_memcpy (&t6.ipv6_addr,
1483  &((struct sockaddr_in6 *) addr)->sin6_addr,
1484  sizeof(struct in6_addr));
1485  t6.options = htonl (plugin->myoptions);
1486  t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port;
1487  arg = &t6;
1488  args = sizeof (t6);
1489  break;
1490  default:
1491  GNUNET_break(0);
1492  return;
1493  }
1494  /* modify our published address list */
1495  GNUNET_assert ((args == sizeof (struct IPv4TcpAddress)) ||
1496  (args == sizeof (struct IPv6TcpAddress)));
1497  /* TODO: use 'ac' here in the future... */
1498  address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
1499  PLUGIN_NAME,
1500  arg,
1501  args,
1503  plugin->env->notify_address (plugin->env->cls,
1504  add_remove,
1505  address);
1506  GNUNET_HELLO_address_free (address);
1507 }
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_allocate(const struct GNUNET_PeerIdentity *peer, const char *transport_name, const void *address, size_t address_length, enum GNUNET_HELLO_AddressInfo local_info)
Allocate an address struct.
Definition: address.c:73
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
Network format for IPv4 addresses.
#define GNUNET_memcpy(dst, src, n)
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
static struct GNUNET_SCHEDULER_Task * t4
Task for IPv4 socket.
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
Network format for IPv6 addresses.
#define PLUGIN_NAME
No additional information.
Handle for a plugin.
Definition: block.c:37
An address for communicating with a peer.
void * cls
Closure to use for callbacks.
#define GNUNET_YES
Definition: gnunet_common.h:80
uint32_t myoptions
Address options.
#define LOG(kind,...)
static char * address
GNS address for this phone.
#define GNUNET_HELLO_address_free(addr)
Free an address.
static struct GNUNET_SCHEDULER_Task * t6
Task for IPv6 socket.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcp_plugin_address_to_string()

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

Function called for a quick conversion of the binary address to a numeric address.

Note that the caller must not free the address and that the next call to this function is allowed to override the address again.

Parameters
clsclosure (struct Plugin*)
addrbinary address
addrlenlength of addr
Returns
string representing the same address

Definition at line 1522 of file plugin_transport_tcp.c.

References GNUNET_ERROR_TYPE_WARNING, GNUNET_log_strerror, GNUNET_memcpy, GNUNET_snprintf(), IPv6TcpAddress::ipv6_addr, LOG, options, PLUGIN_NAME, port, t4, t6, and IPv6TcpAddress::t6_port.

Referenced by create_session(), disconnect_notify(), do_transmit(), handle_tcp_welcome(), libgnunet_plugin_transport_tcp_init(), nat_connect_timeout(), tcp_plugin_disconnect_session(), and tcp_plugin_get_session().

1525 {
1526  static char rbuf[INET6_ADDRSTRLEN + 12];
1527  char buf[INET6_ADDRSTRLEN];
1528  const void *sb;
1529  struct in_addr a4;
1530  struct in6_addr a6;
1531  const struct IPv4TcpAddress *t4;
1532  const struct IPv6TcpAddress *t6;
1533  int af;
1534  uint16_t port;
1535  uint32_t options;
1536 
1537  switch (addrlen)
1538  {
1539  case sizeof(struct IPv6TcpAddress):
1540  t6 = addr;
1541  af = AF_INET6;
1542  port = ntohs (t6->t6_port);
1543  options = ntohl (t6->options);
1544  GNUNET_memcpy (&a6, &t6->ipv6_addr, sizeof(a6));
1545  sb = &a6;
1546  break;
1547  case sizeof(struct IPv4TcpAddress):
1548  t4 = addr;
1549  af = AF_INET;
1550  port = ntohs (t4->t4_port);
1551  options = ntohl (t4->options);
1552  GNUNET_memcpy (&a4, &t4->ipv4_addr, sizeof(a4));
1553  sb = &a4;
1554  break;
1555  default:
1556  LOG (GNUNET_ERROR_TYPE_WARNING,
1557  _("Unexpected address length: %u bytes\n"),
1558  (unsigned int) addrlen);
1559  return NULL ;
1560  }
1561  if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN))
1562  {
1564  "inet_ntop");
1565  return NULL ;
1566  }
1567  GNUNET_snprintf (rbuf, sizeof(rbuf),
1568  (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u",
1569  PLUGIN_NAME,
1570  options,
1571  buf,
1572  port);
1573  return rbuf;
1574 }
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
Network format for IPv4 addresses.
#define GNUNET_memcpy(dst, src, n)
static struct GNUNET_SCHEDULER_Task * t4
Task for IPv4 socket.
static char buf[2048]
Network format for IPv6 addresses.
struct in6_addr ipv6_addr
IPv6 address.
#define PLUGIN_NAME
static uint16_t port
Port number.
Definition: gnunet-bcd.c:79
#define LOG(kind,...)
uint16_t t6_port
Port number, in network byte order.
static struct GNUNET_SCHEDULER_Task * t6
Task for IPv6 socket.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcp_plugin_string_to_address()

static int tcp_plugin_string_to_address ( void *  cls,
const char *  addr,
uint16_t  addrlen,
void **  buf,
size_t *  added 
)
static

Function called to convert a string address to a binary address.

Parameters
clsclosure (struct Plugin*)
addrstring address
addrlenlength of the address
buflocation to store the buffer
addedlocation to store the number of bytes in the buffer. If the function returns GNUNET_SYSERR, its contents are undefined.
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure

Definition at line 1590 of file plugin_transport_tcp.c.

References address, GNUNET_break, GNUNET_free, GNUNET_new, GNUNET_OK, GNUNET_strdup, GNUNET_STRINGS_to_address_ip(), GNUNET_SYSERR, IPv4TcpAddress::ipv4_addr, IPv6TcpAddress::ipv6_addr, options, IPv4TcpAddress::options, IPv6TcpAddress::options, plugin, t4, IPv4TcpAddress::t4_port, t6, and IPv6TcpAddress::t6_port.

Referenced by libgnunet_plugin_transport_tcp_init().

1595 {
1596  struct sockaddr_storage socket_address;
1597  char *address;
1598  char *plugin;
1599  char *optionstr;
1600  uint32_t options;
1601 
1602  /* Format tcp.options.address:port */
1603  address = NULL;
1604  plugin = NULL;
1605  optionstr = NULL;
1606  if ((NULL == addr) || (0 == addrlen))
1607  {
1608  GNUNET_break(0);
1609  return GNUNET_SYSERR;
1610  }
1611  if ('\0' != addr[addrlen - 1])
1612  {
1613  GNUNET_break(0);
1614  return GNUNET_SYSERR;
1615  }
1616  if (strlen (addr) != addrlen - 1)
1617  {
1618  GNUNET_break(0);
1619  return GNUNET_SYSERR;
1620  }
1621  plugin = GNUNET_strdup (addr);
1622  optionstr = strchr (plugin, '.');
1623  if (NULL == optionstr)
1624  {
1625  GNUNET_break(0);
1626  GNUNET_free(plugin);
1627  return GNUNET_SYSERR;
1628  }
1629  optionstr[0] = '\0';
1630  optionstr++;
1631  options = atol (optionstr);
1632  address = strchr (optionstr, '.');
1633  if (NULL == address)
1634  {
1635  GNUNET_break(0);
1636  GNUNET_free(plugin);
1637  return GNUNET_SYSERR;
1638  }
1639  address[0] = '\0';
1640  address++;
1641 
1642  if (GNUNET_OK !=
1644  strlen (address),
1645  &socket_address))
1646  {
1647  GNUNET_break(0);
1648  GNUNET_free(plugin);
1649  return GNUNET_SYSERR;
1650  }
1651 
1652  GNUNET_free(plugin);
1653  switch (socket_address.ss_family)
1654  {
1655  case AF_INET:
1656  {
1657  struct IPv4TcpAddress *t4;
1658  struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address;
1659  t4 = GNUNET_new (struct IPv4TcpAddress);
1660  t4->options = htonl (options);
1661  t4->ipv4_addr = in4->sin_addr.s_addr;
1662  t4->t4_port = in4->sin_port;
1663  *buf = t4;
1664  *added = sizeof(struct IPv4TcpAddress);
1665  return GNUNET_OK;
1666  }
1667  case AF_INET6:
1668  {
1669  struct IPv6TcpAddress *t6;
1670  struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address;
1671  t6 = GNUNET_new (struct IPv6TcpAddress);
1672  t6->options = htonl (options);
1673  t6->ipv6_addr = in6->sin6_addr;
1674  t6->t6_port = in6->sin6_port;
1675  *buf = t6;
1676  *added = sizeof(struct IPv6TcpAddress);
1677  return GNUNET_OK;
1678  }
1679  default:
1680  return GNUNET_SYSERR;
1681  }
1682 }
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_new(type)
Allocate a struct or union of the given type.
uint32_t options
Optional flags for this address see enum TcpAddressOptions
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#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.
Network format for IPv4 addresses.
uint32_t options
Optional options and flags for this address, see enum TcpAddressOptions
static struct GNUNET_SCHEDULER_Task * t4
Task for IPv4 socket.
static char buf[2048]
Network format for IPv6 addresses.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct in6_addr ipv6_addr
IPv6 address.
uint16_t t4_port
Port number, in network byte order.
uint32_t ipv4_addr
IPv4 address, in network byte order.
static char * address
GNS address for this phone.
int GNUNET_STRINGS_to_address_ip(const char *addr, uint16_t addrlen, struct sockaddr_storage *r_buf)
Tries to convert addr string to an IP (v4 or v6) address.
Definition: strings.c:1409
uint16_t t6_port
Port number, in network byte order.
#define GNUNET_free(ptr)
Wrapper around free.
static struct GNUNET_SCHEDULER_Task * t6
Task for IPv6 socket.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lookup_session_by_client()

static struct GNUNET_ATS_Session* lookup_session_by_client ( struct Plugin plugin,
struct GNUNET_SERVER_Client client 
)
static

Find the session handle for the given client.

Currently uses both the hashmap and the client context, as the client context is new and the logic still needs to be tested.

Parameters
pluginthe plugin
clientwhich client to find the session handle for
Returns
NULL if no matching session exists

Definition at line 1696 of file plugin_transport_tcp.c.

References GNUNET_SERVER_client_get_user_context.

Referenced by disconnect_notify(), handle_tcp_data(), and handle_tcp_welcome().

1698 {
1700  struct GNUNET_ATS_Session);
1701 }
#define GNUNET_SERVER_client_get_user_context(client, type)
Return user context associated with the given client.
Information about ongoing sessions of the transport client.
Here is the caller graph for this function:

◆ tcp_plugin_disconnect_session()

static int tcp_plugin_disconnect_session ( void *  cls,
struct GNUNET_ATS_Session session 
)
static

Functions with this signature are called whenever we need to close a session due to a disconnect or failure to establish a connection.

Parameters
clsthe struct Plugin
sessionsession to close down
Returns
GNUNET_OK on success

Definition at line 1714 of file plugin_transport_tcp.c.

References GNUNET_HELLO_Address::address, GNUNET_ATS_Session::address, GNUNET_HELLO_Address::address_length, GNUNET_ATS_Session::bytes_in_queue, GNUNET_ATS_Session::client, GNUNET_DATACACHE_PluginEnvironment::cls, Plugin::env, gettext_noop, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multipeermap_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_HELLO_address_free, GNUNET_i2s(), GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_SERVER_client_disconnect(), GNUNET_SERVER_client_set_user_context, GNUNET_SERVER_notify_transmit_ready_cancel(), GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_SS_DONE, GNUNET_YES, LOG, PendingMessage::message_size, GNUNET_ATS_Session::msgs_in_queue, GNUNET_ATS_Session::nat_connection_timeout, Plugin::nat_wait_conns, notify_session_monitor(), GNUNET_ATS_Session::pending_messages_head, GNUNET_ATS_Session::pending_messages_tail, plugin, GNUNET_ATS_Session::plugin, pm, GNUNET_ATS_Session::receive_delay_task, Plugin::sessionmap, GNUNET_ATS_Session::target, tcp_plugin_address_to_string(), GNUNET_ATS_Session::timeout, GNUNET_ATS_Session::timeout_task, PendingMessage::transmit_cont, PendingMessage::transmit_cont_cls, and GNUNET_ATS_Session::transmit_handle.

Referenced by disconnect_notify(), handle_tcp_nat_probe(), libgnunet_plugin_transport_tcp_init(), nat_connect_timeout(), session_disconnect_it(), session_timeout(), and tcp_plugin_get_session().

1716 {
1717  struct Plugin *plugin = cls;
1718  struct PendingMessage *pm;
1719 
1721  "Disconnecting session of peer `%s' address `%s'\n",
1722  GNUNET_i2s (&session->target),
1724  session->address->address,
1725  session->address->address_length));
1726 
1727  if (NULL != session->timeout_task)
1728  {
1730  session->timeout_task = NULL;
1732  }
1733 
1734  if (GNUNET_YES ==
1736  &session->target,
1737  session))
1738  {
1739  GNUNET_STATISTICS_update (session->plugin->env->stats,
1740  gettext_noop ("# TCP sessions active"),
1741  -1,
1742  GNUNET_NO);
1743  }
1744  else
1745  {
1748  &session->target,
1749  session));
1750  }
1751  if (NULL != session->client)
1753  NULL);
1754 
1755  /* clean up state */
1756  if (NULL != session->transmit_handle)
1757  {
1759  session->transmit_handle = NULL;
1760  }
1761  session->plugin->env->session_end (session->plugin->env->cls,
1762  session->address,
1763  session);
1764 
1765  if (NULL != session->nat_connection_timeout)
1766  {
1768  session->nat_connection_timeout = NULL;
1769  }
1770 
1771  while (NULL != (pm = session->pending_messages_head))
1772  {
1774  (NULL != pm->transmit_cont)
1775  ? "Could not deliver message to `%s' at %s.\n"
1776  : "Could not deliver message to `%s' at %s, notifying.\n",
1777  GNUNET_i2s (&session->target),
1779  session->address->address,
1780  session->address->address_length));
1781  GNUNET_STATISTICS_update (session->plugin->env->stats,
1782  gettext_noop ("# bytes currently in TCP buffers"),
1783  -(int64_t) pm->message_size, GNUNET_NO);
1784  GNUNET_STATISTICS_update (session->plugin->env->stats,
1785  gettext_noop ("# bytes discarded by TCP (disconnect)"),
1786  pm->message_size,
1787  GNUNET_NO);
1789  session->pending_messages_tail,
1790  pm);
1791  GNUNET_assert (0 < session->msgs_in_queue);
1792  session->msgs_in_queue--;
1793  GNUNET_assert (pm->message_size <= session->bytes_in_queue);
1794  session->bytes_in_queue -= pm->message_size;
1795  if (NULL != pm->transmit_cont)
1797  &session->target,
1798  GNUNET_SYSERR,
1799  pm->message_size,
1800  0);
1801  GNUNET_free (pm);
1802  }
1803  GNUNET_assert (0 == session->msgs_in_queue);
1804  GNUNET_assert (0 == session->bytes_in_queue);
1805  notify_session_monitor (session->plugin,
1806  session,
1808 
1809  if (NULL != session->receive_delay_task)
1810  {
1812  session->receive_delay_task = NULL;
1813  }
1814  if (NULL != session->client)
1815  {
1817  session->client = NULL;
1818  }
1820  GNUNET_assert (NULL == session->transmit_handle);
1821  GNUNET_free (session);
1822  return GNUNET_OK;
1823 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
size_t address_length
Number of bytes in address.
size_t message_size
So that the gnunet-service-transport can group messages together, these pending messages need to acce...
Session is being torn down and about to disappear.
struct GNUNET_CONTAINER_MultiPeerMap * sessionmap
Map from peer identities to sessions for the given peer.
GNUNET_TRANSPORT_TransmitContinuation transmit_cont
Continuation function to call once the message has been sent.
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
const void * address
Binary representation of the address (plugin-specific).
void * transmit_cont_cls
Closure for transmit_cont.
unsigned int msgs_in_queue
Number of messages waiting for transmission to this peer.
struct GNUNET_SCHEDULER_Task * timeout_task
Session timeout task.
struct Plugin * plugin
Pointer to the global plugin struct.
struct GNUNET_SERVER_TransmitHandle * transmit_handle
Handle for pending transmission request.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SCHEDULER_Task * nat_connection_timeout
Task cleaning up a NAT client connection establishment attempt;.
struct GNUNET_SCHEDULER_Task * receive_delay_task
ID of task used to delay receiving more to throttle sender.
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.
void GNUNET_SERVER_notify_transmit_ready_cancel(struct GNUNET_SERVER_TransmitHandle *th)
Abort transmission request.
#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.
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 GNUNET_SERVER_client_disconnect(struct GNUNET_SERVER_Client *client)
Ask the server to disconnect from the given client.
static void notify_session_monitor(struct 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 struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
struct PendingMessage * pending_messages_tail
Messages currently pending for transmission to this peer, if any.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
struct PendingMessage * pending_messages_head
Messages currently pending for transmission to this peer, if any.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static const char * tcp_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
Function called for a quick conversion of the binary address to a numeric address.
#define GNUNET_SERVER_client_set_user_context(client, value)
Set user context to be associated with the given client.
Handle for a plugin.
Definition: block.c:37
struct GNUNET_PeerIdentity target
To whom are we talking to.
List containing all messages that are yet to be send.
struct Client * client
The transport client that provided the session.
void * cls
Closure to use for callbacks.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_CONTAINER_MultiPeerMap * nat_wait_conns
Map of peers we have tried to contact behind a NAT.
#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_HELLO_address_free(addr)
Free an address.
#define GNUNET_free(ptr)
Wrapper around free.
static struct GNUNET_TRANSPORT_PluginMonitor * pm
Handle if we are monitoring plugin session activity.
#define gettext_noop(String)
Definition: gettext.h:69
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:

◆ tcp_plugin_query_keepalive_factor()

static unsigned int tcp_plugin_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 1835 of file plugin_transport_tcp.c.

Referenced by libgnunet_plugin_transport_tcp_init().

1836 {
1837  return 3;
1838 }
Here is the caller graph for this function:

◆ session_timeout()

static void session_timeout ( void *  cls)
static

Session was idle for too long, so disconnect it.

Parameters
clsthe struct GNUNET_ATS_Session of the idle session

Definition at line 1847 of file plugin_transport_tcp.c.

References GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_ERROR_TYPE_DEBUG, GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TRANSPORT_SS_UPDATE, GNUNET_YES, LOG, notify_session_monitor(), GNUNET_ATS_Session::plugin, GNUNET_TIME_Relative::rel_value_us, tcp_plugin_disconnect_session(), GNUNET_ATS_Session::timeout, and GNUNET_ATS_Session::timeout_task.

Referenced by create_session().

1848 {
1849  struct GNUNET_ATS_Session *s = cls;
1850  struct GNUNET_TIME_Relative left;
1851 
1852  s->timeout_task = NULL;
1854  if (0 != left.rel_value_us)
1855  {
1856  /* not actually our turn yet, but let's at least update
1857  the monitor, it may think we're about to die ... */
1859  s,
1862  &session_timeout,
1863  s);
1864  return;
1865  }
1867  "Session %p was idle for %s, disconnecting\n",
1868  s,
1870  GNUNET_YES));
1871  /* call session destroy function */
1873  s);
1874 }
struct GNUNET_SCHEDULER_Task * timeout_task
Session timeout task.
struct Plugin * plugin
Pointer to the global plugin struct.
struct GNUNET_TIME_Absolute timeout
When does this session time out.
static void notify_session_monitor(struct 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.
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 int tcp_plugin_disconnect_session(void *cls, struct GNUNET_ATS_Session *session)
Functions with this signature are called whenever we need to close a session due to a disconnect or f...
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
#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...
This is just an update about the session, the state did not change.
static void session_timeout(void *cls)
Session was idle for too long, so disconnect it.
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,...)
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:

◆ reschedule_session_timeout()

static void reschedule_session_timeout ( struct GNUNET_ATS_Session s)
static

Increment session timeout due to activity.

Parameters
ssession to increment timeout for

Definition at line 1883 of file plugin_transport_tcp.c.

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

Referenced by delayed_done(), handle_tcp_data(), and tcp_plugin_update_session_timeout().

1884 {
1885  GNUNET_assert (NULL != s->timeout_task);
1887 }
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:

◆ create_session()

static struct GNUNET_ATS_Session* create_session ( struct Plugin plugin,
const struct GNUNET_HELLO_Address address,
enum GNUNET_NetworkType  scope,
struct GNUNET_SERVER_Client client,
int  is_nat 
)
static

Create a new session.

Also queues a welcome message.

Parameters
pluginthe plugin
addressthe address to create the session for
scopenetwork scope the address is from
clientclient to use, reference counter must have already been increased
is_natthis a NAT session, we should wait for a client to connect to us from an address, then assign that to the session
Returns
new session object

Definition at line 1903 of file plugin_transport_tcp.c.

References GNUNET_HELLO_Address::address, GNUNET_ATS_Session::address, GNUNET_HELLO_Address::address_length, GNUNET_ATS_Session::bytes_in_queue, GNUNET_ATS_Session::client, PendingMessage::client, Plugin::env, GNUNET_ATS_Session::expecting_welcome, gettext_noop, GNUNET_assert, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_HELLO_address_copy(), GNUNET_i2s(), GNUNET_malloc, GNUNET_memcpy, GNUNET_new, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_SERVER_client_set_user_context, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_get(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TRANSPORT_SS_HANDSHAKE, GNUNET_TRANSPORT_SS_INIT, GNUNET_TRANSPORT_SS_UP, GNUNET_YES, GNUNET_ATS_Session::is_nat, GNUNET_ATS_Session::last_activity, LOG, PendingMessage::message_size, PendingMessage::msg, GNUNET_ATS_Session::msgs_in_queue, Plugin::my_welcome, notify_session_monitor(), GNUNET_HELLO_Address::peer, GNUNET_ATS_Session::pending_messages_head, GNUNET_ATS_Session::pending_messages_tail, plugin, GNUNET_ATS_Session::plugin, pm, process_pending_messages(), scope, GNUNET_ATS_Session::scope, session_timeout(), GNUNET_ATS_Session::target, tcp_plugin_address_to_string(), GNUNET_ATS_Session::timeout, PendingMessage::timeout, and GNUNET_ATS_Session::timeout_task.

Referenced by handle_tcp_welcome(), and tcp_plugin_get_session().

1908 {
1909  struct GNUNET_ATS_Session *session;
1910  struct PendingMessage *pm;
1911 
1912  if (GNUNET_YES != is_nat)
1913  GNUNET_assert (NULL != client);
1914  else
1915  GNUNET_assert (NULL == client);
1916 
1918  "Creating new session for peer `%s' at address %s\n",
1919  GNUNET_i2s (&address->peer),
1921  address->address,
1922  address->address_length));
1923  session = GNUNET_new (struct GNUNET_ATS_Session);
1925  session->plugin = plugin;
1926  session->is_nat = is_nat;
1927  if (NULL != client)
1928  {
1929  session->client = client;
1931  session);
1932  }
1933  session->address = GNUNET_HELLO_address_copy (address);
1934  session->target = address->peer;
1935  session->expecting_welcome = GNUNET_YES;
1936  session->scope = scope;
1937  pm = GNUNET_malloc (sizeof (struct PendingMessage) +
1938  sizeof (struct WelcomeMessage));
1939  pm->msg = (const char *) &pm[1];
1940  pm->message_size = sizeof(struct WelcomeMessage);
1941  GNUNET_memcpy (&pm[1],
1942  &plugin->my_welcome,
1943  sizeof(struct WelcomeMessage));
1945  GNUNET_STATISTICS_update (plugin->env->stats,
1946  gettext_noop ("# bytes currently in TCP buffers"),
1947  pm->message_size,
1948  GNUNET_NO);
1950  session->pending_messages_tail,
1951  pm);
1952  session->msgs_in_queue++;
1953  session->bytes_in_queue += pm->message_size;
1956  &session_timeout,
1957  session);
1958  notify_session_monitor (session->plugin,
1959  session,
1961  if (GNUNET_YES != is_nat)
1962  {
1963  GNUNET_STATISTICS_update (plugin->env->stats,
1964  gettext_noop ("# TCP sessions active"),
1965  1,
1966  GNUNET_NO);
1967  notify_session_monitor (session->plugin,
1968  session,
1970  }
1971  else
1972  {
1973  notify_session_monitor (session->plugin,
1974  session,
1976  }
1977  return session;
1978 }
size_t address_length
Number of bytes in address.
size_t message_size
So that the gnunet-service-transport can group messages together, these pending messages need to acce...
const void * address
Binary representation of the address (plugin-specific).
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
unsigned int msgs_in_queue
Number of messages waiting for transmission to this peer.
struct GNUNET_SCHEDULER_Task * timeout_task
Session timeout task.
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
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int is_nat
Was this session created using NAT traversal?
Initial session handshake is in progress.
struct GNUNET_TIME_Absolute timeout
When does this session time out.
#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.
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_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
static void notify_session_monitor(struct 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 struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
struct PendingMessage * pending_messages_tail
Messages currently pending for transmission to this peer, if any.
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
#define GNUNET_memcpy(dst, src, n)
Information about ongoing sessions of the transport client.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
static enum GNUNET_NetworkType scope
Which network scope do we belong to?
struct PendingMessage * pending_messages_head
Messages currently pending for transmission to this peer, if any.
struct TransportClient * client
Client that issued the transmission request, if pmt is PMT_CORE.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
struct GNUNET_TIME_Absolute timeout
At what time should we give up on the transmission (and no longer retry)?
static const char * tcp_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
Function called for a quick conversion of the binary address to a numeric address.
enum GNUNET_NetworkType scope
ATS network type.
struct GNUNET_PeerIdentity peer
For which peer is this an address?
int expecting_welcome
Are we still expecting the welcome message? (GNUNET_YES/GNUNET_NO)
#define GNUNET_SERVER_client_set_user_context(client, value)
Set user context to be associated with the given client.
#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...
static void session_timeout(void *cls)
Session was idle for too long, so disconnect it.
struct GNUNET_PeerIdentity target
To whom are we talking to.
Initial handshake message for a session.
struct WelcomeMessage my_welcome
Welcome message used by this peer.
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).
List containing all messages that are yet to be send.
const char * msg
The pending message.
struct Client * client
The transport client that provided the session.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_TIME_Absolute last_activity
Last activity on this connection.
#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_malloc(size)
Wrapper around malloc.
static struct GNUNET_TRANSPORT_PluginMonitor * pm
Handle if we are monitoring plugin session activity.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_pending_messages()

static void process_pending_messages ( struct GNUNET_ATS_Session session)
static

If we have pending messages, ask the server to transmit them (schedule the respective tasks, etc.)

Parameters
sessionfor which session should we do this

Definition at line 2161 of file plugin_transport_tcp.c.

References GNUNET_ATS_Session::client, do_transmit(), GNUNET_assert, GNUNET_SERVER_notify_transmit_ready(), GNUNET_TIME_absolute_get_remaining(), PendingMessage::message_size, GNUNET_ATS_Session::pending_messages_head, pm, PendingMessage::timeout, and GNUNET_ATS_Session::transmit_handle.

Referenced by create_session(), do_transmit(), handle_tcp_nat_probe(), handle_tcp_welcome(), tcp_plugin_get_session(), and tcp_plugin_send().

2162 {
2163  struct PendingMessage *pm;
2164 
2165  GNUNET_assert (NULL != session->client);
2166  if (NULL != session->transmit_handle)
2167  return;
2168  if (NULL == (pm = session->pending_messages_head))
2169  return;
2170 
2171  session->transmit_handle
2173  pm->message_size,
2175  &do_transmit,
2176  session);
2177 }
size_t message_size
So that the gnunet-service-transport can group messages together, these pending messages need to acce...
struct GNUNET_SERVER_TransmitHandle * transmit_handle
Handle for pending transmission request.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static size_t do_transmit(void *cls, size_t size, void *buf)
Function called to notify a client about the socket being ready to queue more data.
struct PendingMessage * pending_messages_head
Messages currently pending for transmission to this peer, if any.
struct GNUNET_TIME_Absolute timeout
At what time should we give up on the transmission (and no longer retry)?
struct GNUNET_SERVER_TransmitHandle * GNUNET_SERVER_notify_transmit_ready(struct GNUNET_SERVER_Client *client, size_t size, struct GNUNET_TIME_Relative timeout, GNUNET_CONNECTION_TransmitReadyNotify callback, void *callback_cls)
Notify us when the server has enough space to transmit a message of the given size to the given clien...
List containing all messages that are yet to be send.
struct Client * client
The transport client that provided the session.
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
static struct GNUNET_TRANSPORT_PluginMonitor * pm
Handle if we are monitoring plugin session activity.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_transmit()

static size_t do_transmit ( void *  cls,
size_t  size,
void *  buf 
)
static

Function called to notify a client about the socket being ready to queue more data.

"buf" will be NULL and "size" zero if the socket was closed for writing in the meantime.

Parameters
clsclosure
sizenumber of bytes available in buf
bufwhere the callee should write the message
Returns
number of bytes written to buf

Definition at line 2003 of file plugin_transport_tcp.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_HELLO_Address::address, GNUNET_ATS_Session::address, GNUNET_HELLO_Address::address_length, buf, GNUNET_ATS_Session::bytes_in_queue, Plugin::env, gettext_noop, GNUNET_assert, GNUNET_CONTAINER_DLL_insert_after, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_memcpy, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_TIME_absolute_get(), GNUNET_TRANSPORT_SS_UPDATE, GNUNET_ATS_Session::last_activity, LOG, PendingMessage::message_size, PendingMessage::msg, GNUNET_ATS_Session::msgs_in_queue, notify_session_monitor(), GNUNET_ATS_Session::pending_messages_head, GNUNET_ATS_Session::pending_messages_tail, plugin, GNUNET_ATS_Session::plugin, process_pending_messages(), ret, GNUNET_ATS_Session::target, tcp_plugin_address_to_string(), PendingMessage::timeout, PendingMessage::transmit_cont, PendingMessage::transmit_cont_cls, and GNUNET_ATS_Session::transmit_handle.

Referenced by process_pending_messages().

2006 {
2007  struct GNUNET_ATS_Session *session = cls;
2008  struct GNUNET_PeerIdentity pid;
2009  struct Plugin *plugin;
2010  struct PendingMessage *pos;
2011  struct PendingMessage *hd;
2012  struct PendingMessage *tl;
2013  struct GNUNET_TIME_Absolute now;
2014  char *cbuf;
2015  size_t ret;
2016 
2017  session->transmit_handle = NULL;
2018  plugin = session->plugin;
2019  if (NULL == buf)
2020  {
2022  "Timeout trying to transmit to peer `%s', discarding message queue.\n",
2023  GNUNET_i2s (&session->target));
2024  /* timeout; cancel all messages that have already expired */
2025  hd = NULL;
2026  tl = NULL;
2027  ret = 0;
2028  now = GNUNET_TIME_absolute_get ();
2029  while ( (NULL != (pos = session->pending_messages_head)) &&
2030  (pos->timeout.abs_value_us <= now.abs_value_us) )
2031  {
2033  session->pending_messages_tail,
2034  pos);
2035  GNUNET_assert (0 < session->msgs_in_queue);
2036  session->msgs_in_queue--;
2037  GNUNET_assert (pos->message_size <= session->bytes_in_queue);
2038  session->bytes_in_queue -= pos->message_size;
2040  "Failed to transmit %u byte message to `%s'.\n",
2041  pos->message_size,
2042  GNUNET_i2s (&session->target));
2043  ret += pos->message_size;
2045  tl,
2046  tl,
2047  pos);
2048  }
2049  /* do this call before callbacks (so that if callbacks destroy
2050  * session, they have a chance to cancel actions done by this
2051  * call) */
2052  process_pending_messages (session);
2053  pid = session->target;
2054  /* no do callbacks and do not use session again since
2055  * the callbacks may abort the session */
2056  while (NULL != (pos = hd))
2057  {
2059  tl,
2060  pos);
2061  if (NULL != pos->transmit_cont)
2062  pos->transmit_cont (pos->transmit_cont_cls,
2063  &pid,
2064  GNUNET_SYSERR,
2065  pos->message_size,
2066  0);
2067  GNUNET_free (pos);
2068  }
2069  GNUNET_STATISTICS_update (plugin->env->stats,
2070  gettext_noop ("# bytes currently in TCP buffers"), -(int64_t) ret,
2071  GNUNET_NO);
2072  GNUNET_STATISTICS_update (plugin->env->stats,
2073  gettext_noop ("# bytes discarded by TCP (timeout)"),
2074  ret,
2075  GNUNET_NO);
2076  if (0 < ret)
2077  notify_session_monitor (session->plugin,
2078  session,
2080  return 0;
2081  }
2082  /* copy all pending messages that would fit */
2083  ret = 0;
2084  cbuf = buf;
2085  hd = NULL;
2086  tl = NULL;
2087  while (NULL != (pos = session->pending_messages_head))
2088  {
2089  if (ret + pos->message_size > size)
2090  break;
2092  session->pending_messages_tail,
2093  pos);
2094  GNUNET_assert (0 < session->msgs_in_queue);
2095  session->msgs_in_queue--;
2096  GNUNET_assert (pos->message_size <= session->bytes_in_queue);
2097  session->bytes_in_queue -= pos->message_size;
2098  GNUNET_assert(size >= pos->message_size);
2100  "Transmitting message of type %u size %u to peer %s at %s\n",
2101  ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type),
2102  pos->message_size,
2103  GNUNET_i2s (&session->target),
2105  session->address->address,
2106  session->address->address_length));
2107  /* FIXME: this GNUNET_memcpy can be up to 7% of our total runtime */
2108  GNUNET_memcpy (cbuf,
2109  pos->msg,
2110  pos->message_size);
2111  cbuf += pos->message_size;
2112  ret += pos->message_size;
2113  size -= pos->message_size;
2115  tl,
2116  pos);
2117  }
2118  notify_session_monitor (session->plugin,
2119  session,
2121  /* schedule 'continuation' before callbacks so that callbacks that
2122  * cancel everything don't cause us to use a session that no longer
2123  * exists... */
2124  process_pending_messages (session);
2126  pid = session->target;
2127  /* we'll now call callbacks that may cancel the session; hence
2128  * we should not use 'session' after this point */
2129  while (NULL != (pos = hd))
2130  {
2131  GNUNET_CONTAINER_DLL_remove (hd, tl, pos);
2132  if (NULL != pos->transmit_cont)
2133  pos->transmit_cont (pos->transmit_cont_cls,
2134  &pid,
2135  GNUNET_OK,
2136  pos->message_size,
2137  pos->message_size); /* FIXME: include TCP overhead */
2138  GNUNET_free (pos);
2139  }
2140  GNUNET_assert (NULL == hd);
2141  GNUNET_assert (NULL == tl);
2142  GNUNET_STATISTICS_update (plugin->env->stats,
2143  gettext_noop ("# bytes currently in TCP buffers"),
2144  - (int64_t) ret,
2145  GNUNET_NO);
2146  GNUNET_STATISTICS_update (plugin->env->stats,
2147  gettext_noop ("# bytes transmitted via TCP"),
2148  ret,
2149  GNUNET_NO);
2150  return ret;
2151 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
size_t address_length
Number of bytes in address.
size_t message_size
So that the gnunet-service-transport can group messages together, these pending messages need to acce...
GNUNET_TRANSPORT_TransmitContinuation transmit_cont
Continuation function to call once the message has been sent.
const void * address
Binary representation of the address (plugin-specific).
void * transmit_cont_cls
Closure for transmit_cont.
unsigned int msgs_in_queue
Number of messages waiting for transmission to this peer.
struct Plugin * plugin
Pointer to the global plugin struct.
struct GNUNET_SERVER_TransmitHandle * transmit_handle
Handle for pending transmission request.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#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.
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.
static int ret
Final status code.
Definition: gnunet-arm.c:89
uint64_t abs_value_us
The actual value.
static void notify_session_monitor(struct 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 struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
struct PendingMessage * pending_messages_tail
Messages currently pending for transmission to this peer, if any.
#define GNUNET_memcpy(dst, src, n)
Information about ongoing sessions of the transport client.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
struct PendingMessage * pending_messages_head
Messages currently pending for transmission to this peer, if any.
static char buf[2048]
#define GNUNET_CONTAINER_DLL_insert_after(head, tail, other, element)
Insert an element into a DLL after the given other element.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
struct GNUNET_TIME_Absolute timeout
At what time should we give up on the transmission (and no longer retry)?
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static unsigned int size
Size of the "table".
Definition: peer.c:67
static const char * tcp_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
Function called for a quick conversion of the binary address to a numeric address.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
This is just an update about the session, the state did not change.
The identity of the host (wraps the signing key of the peer).
static void process_pending_messages(struct GNUNET_ATS_Session *session)
If we have pending messages, ask the server to transmit them (schedule the respective tasks...
Handle for a plugin.
Definition: block.c:37
struct GNUNET_PeerIdentity target
To whom are we talking to.
List containing all messages that are yet to be send.
const char * msg
The pending message.
Header for all communications.
Time for absolute times used by GNUnet, in microseconds.
struct GNUNET_TIME_Absolute last_activity
Last activity on this connection.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
#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.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcp_plugin_send()

static ssize_t tcp_plugin_send ( void *  cls,
struct GNUNET_ATS_Session session,
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
sessionwhich 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 2208 of file plugin_transport_tcp.c.

References GNUNET_ATS_Session::bytes_in_queue, GNUNET_ATS_Session::client, Plugin::env, gettext_noop, GNUNET_assert, GNUNET_break, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_multipeermap_contains_value(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_i2s(), GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, GNUNET_SERVER_client_set_timeout(), GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_TIME_relative_to_absolute(), GNUNET_TRANSPORT_SS_HANDSHAKE, GNUNET_TRANSPORT_SS_UPDATE, GNUNET_YES, LOG, PendingMessage::message_size, PendingMessage::msg, GNUNET_ATS_Session::msgs_in_queue, Plugin::nat_wait_conns, notify_session_monitor(), GNUNET_ATS_Session::pending_messages_head, GNUNET_ATS_Session::pending_messages_tail, plugin, GNUNET_ATS_Session::plugin, pm, process_pending_messages(), Plugin::sessionmap, GNUNET_ATS_Session::target, PendingMessage::timeout, PendingMessage::transmit_cont, and PendingMessage::transmit_cont_cls.

Referenced by libgnunet_plugin_transport_tcp_init().

2216 {
2217  struct Plugin * plugin = cls;
2218  struct PendingMessage *pm;
2219 
2220  /* create new message entry */
2221  pm = GNUNET_malloc (sizeof (struct PendingMessage) + msgbuf_size);
2222  pm->msg = (const char *) &pm[1];
2223  GNUNET_memcpy (&pm[1], msgbuf, msgbuf_size);
2224  pm->message_size = msgbuf_size;
2226  pm->transmit_cont = cont;
2227  pm->transmit_cont_cls = cont_cls;
2228 
2230  "Asked to transmit %u bytes to `%s', added message to list.\n",
2231  msgbuf_size,
2232  GNUNET_i2s (&session->target));
2233 
2234  if (GNUNET_YES ==
2236  &session->target,
2237  session))
2238  {
2239  GNUNET_assert (NULL != session->client);
2242  GNUNET_STATISTICS_update (plugin->env->stats,
2243  gettext_noop ("# bytes currently in TCP buffers"),
2244  msgbuf_size,
2245  GNUNET_NO);
2246 
2247  /* append pm to pending_messages list */
2249  session->pending_messages_tail,
2250  pm);
2251  notify_session_monitor (session->plugin,
2252  session,
2254  session->msgs_in_queue++;
2255  session->bytes_in_queue += pm->message_size;
2256  process_pending_messages (session);
2257  return msgbuf_size;
2258  }
2259  if (GNUNET_YES ==
2261  &session->target,
2262  session))
2263  {
2265  "This NAT WAIT session for peer `%s' is not yet ready!\n",
2266  GNUNET_i2s (&session->target));
2267  GNUNET_STATISTICS_update (plugin->env->stats,
2268  gettext_noop ("# bytes currently in TCP buffers"), msgbuf_size,
2269  GNUNET_NO);
2270  /* append pm to pending_messages list */
2272  session->pending_messages_tail,
2273  pm);
2274  session->msgs_in_queue++;
2275  session->bytes_in_queue += pm->message_size;
2276  notify_session_monitor (session->plugin,
2277  session,
2279  return msgbuf_size;
2280  }
2282  "Invalid session %p\n",
2283  session);
2284  if (NULL != cont)
2285  cont (cont_cls,
2286  &session->target,
2287  GNUNET_SYSERR,
2288  pm->message_size,
2289  0);
2290  GNUNET_break (0);
2291  GNUNET_free (pm);
2292  return GNUNET_SYSERR; /* session does not exist here */
2293 }
size_t message_size
So that the gnunet-service-transport can group messages together, these pending messages need to acce...
struct GNUNET_CONTAINER_MultiPeerMap * sessionmap
Map from peer identities to sessions for the given peer.
GNUNET_TRANSPORT_TransmitContinuation transmit_cont
Continuation function to call once the message has been sent.
void * transmit_cont_cls
Closure for transmit_cont.
unsigned int msgs_in_queue
Number of messages waiting for transmission to this peer.
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
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Initial session handshake is in progress.
#define GNUNET_NO
Definition: gnunet_common.h:81
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...
static void notify_session_monitor(struct 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 struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
struct PendingMessage * pending_messages_tail
Messages currently pending for transmission to this peer, if any.
#define GNUNET_memcpy(dst, src, n)
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
struct PendingMessage * pending_messages_head
Messages currently pending for transmission to this peer, if any.
void GNUNET_SERVER_client_set_timeout(struct GNUNET_SERVER_Client *client, struct GNUNET_TIME_Relative timeout)
Change the timeout for a particular client.
struct GNUNET_TIME_Absolute timeout
At what time should we give up on the transmission (and no longer retry)?
#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.
#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...
This is just an update about the session, the state did not change.
int GNUNET_CONTAINER_multipeermap_contains_value(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Check if the map contains the given value under the given key.
static void process_pending_messages(struct GNUNET_ATS_Session *session)
If we have pending messages, ask the server to transmit them (schedule the respective tasks...
Handle for a plugin.
Definition: block.c:37
struct GNUNET_PeerIdentity target
To whom are we talking to.
List containing all messages that are yet to be send.
const char * msg
The pending message.
struct Client * client
The transport client that provided the session.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_CONTAINER_MultiPeerMap * nat_wait_conns
Map of peers we have tried to contact behind a NAT.
#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_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
static struct GNUNET_TRANSPORT_PluginMonitor * pm
Handle if we are monitoring plugin session activity.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ session_lookup_it()

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

Look for a session by address.

Parameters
clsthe struct GNUNET_ATS_SessionItCtx
keyunused
valuea struct GNUNET_ATS_Session
Returns
GNUNET_YES to continue looking, GNUNET_NO if we found the session

Definition at line 2323 of file plugin_transport_tcp.c.

References GNUNET_ATS_Session::address, GNUNET_ATS_SessionItCtx::address, GNUNET_HELLO_address_cmp(), GNUNET_NO, GNUNET_YES, GNUNET_ATS_SessionItCtx::result, and value.

Referenced by tcp_plugin_get_session().

2326 {
2327  struct GNUNET_ATS_SessionItCtx *si_ctx = cls;
2328  struct GNUNET_ATS_Session *session = value;
2329 
2330  if (0 !=
2332  session->address))
2333  return GNUNET_YES;
2334  si_ctx->result = session;
2335  return GNUNET_NO;
2336 }
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GNUNET_HELLO_Address * address
Address.
struct GNUNET_ATS_Session * result
Where to store the session (if we found it).
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_it().
const struct GNUNET_HELLO_Address * address
Address we are looking for.
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nat_connect_timeout()

static void nat_connect_timeout ( void *  cls)
static

Task cleaning up a NAT connection attempt after timeout.

Parameters
clsthe struct GNUNET_ATS_Session

Definition at line 2345 of file plugin_transport_tcp.c.

References GNUNET_HELLO_Address::address, GNUNET_ATS_Session::address, GNUNET_HELLO_Address::address_length, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), LOG, GNUNET_ATS_Session::nat_connection_timeout, GNUNET_ATS_Session::plugin, GNUNET_ATS_Session::target, tcp_plugin_address_to_string(), and tcp_plugin_disconnect_session().

Referenced by tcp_plugin_get_session().

2346 {
2347  struct GNUNET_ATS_Session *session = cls;
2348 
2349  session->nat_connection_timeout = NULL;
2351  "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n",
2352  GNUNET_i2s (&session->target),
2354  session->address->address,
2355  session->address->address_length));
2357  session);
2358 }
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_SCHEDULER_Task * nat_connection_timeout
Task cleaning up a NAT client connection establishment attempt;.
struct GNUNET_HELLO_Address * address
Address.
static int tcp_plugin_disconnect_session(void *cls, struct GNUNET_ATS_Session *session)
Functions with this signature are called whenever we need to close a session due to a disconnect or f...
Information about ongoing sessions of the transport client.
static const char * tcp_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
Function called for a quick conversion of the binary address to a numeric address.
struct GNUNET_PeerIdentity target
To whom are we talking to.
#define LOG(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcp_plugin_update_session_timeout()

static void tcp_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 2371 of file plugin_transport_tcp.c.

References reschedule_session_timeout().

Referenced by libgnunet_plugin_transport_tcp_init().

2374 {
2375  reschedule_session_timeout (session);
2376 }
static void reschedule_session_timeout(struct GNUNET_ATS_Session *s)
Increment session timeout due to activity.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ delayed_done()

static void delayed_done ( void *  cls)
static

Task to signal the server that we can continue receiving from the TCP client now.

Parameters
clsthe struct GNUNET_ATS_Session *

Definition at line 2386 of file plugin_transport_tcp.c.

References GNUNET_ATS_Session::client, GNUNET_OK, GNUNET_SERVER_receive_done(), GNUNET_ATS_Session::receive_delay_task, and reschedule_session_timeout().

Referenced by handle_tcp_data(), and tcp_plugin_update_inbound_delay().

2387 {
2388  struct GNUNET_ATS_Session *session = cls;
2389 
2390  session->receive_delay_task = NULL;
2391  reschedule_session_timeout (session);
2393  GNUNET_OK);
2394 }
struct GNUNET_SCHEDULER_Task * receive_delay_task
ID of task used to delay receiving more to throttle sender.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Information about ongoing sessions of the transport client.
void GNUNET_SERVER_receive_done(struct GNUNET_SERVER_Client *client, int success)
Resume receiving from this client, we are done processing the current request.
struct Client * client
The transport client that provided the session.
static void reschedule_session_timeout(struct GNUNET_ATS_Session *s)
Increment session timeout due to activity.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcp_plugin_update_inbound_delay()

static void tcp_plugin_update_inbound_delay ( void *  cls,
const struct GNUNET_PeerIdentity peer,
struct GNUNET_ATS_Session session,
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
sessionwhich session is being updated
delaynew delay to use for receiving

Definition at line 2408 of file plugin_transport_tcp.c.

References delayed_done(), 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::receive_delay, and GNUNET_ATS_Session::receive_delay_task.

Referenced by libgnunet_plugin_transport_tcp_init().

2412 {
2413  if (NULL == session->receive_delay_task)
2414  return;
2416  "New inbound delay %s\n",
2418  GNUNET_NO));
2422  &delayed_done,
2423  session);
2424 }
struct GNUNET_TIME_Absolute receive_delay
When will we continue to read from the socket? (used to enforce inbound quota).
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
struct GNUNET_SCHEDULER_Task * receive_delay_task
ID of task used to delay receiving more to throttle sender.
static void delayed_done(void *cls)
Task to signal the server that we can continue receiving from the TCP client now. ...
#define GNUNET_NO
Definition: gnunet_common.h:81
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:

◆ tcp_plugin_get_session()

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

Create a new session to transmit data to the target This session will used to send data to this peer and the plugin will notify us by calling the env->session_end function.

Parameters
clsclosure
addressthe address to use
Returns
the session if the address is valid, NULL otherwise

Definition at line 2437 of file plugin_transport_tcp.c.

References GNUNET_HELLO_Address::address, address, GNUNET_ATS_SessionItCtx::address, GNUNET_HELLO_Address::address_length, GNUNET_DATACACHE_PluginEnvironment::cls, create_session(), Plugin::cur_connections, Plugin::env, gettext_noop, GNUNET_a2s(), GNUNET_assert, GNUNET_break, GNUNET_CONNECTION_connect_socket(), GNUNET_CONNECTION_create_from_sockaddr(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_contains(), GNUNET_CONTAINER_multipeermap_get_multiple(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_HELLO_address_check_option(), GNUNET_HELLO_ADDRESS_INFO_INBOUND, GNUNET_i2s(), GNUNET_log_strerror, GNUNET_memcpy, GNUNET_NAT_request_reversal(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_create(), GNUNET_NETWORK_socket_setsockopt(), GNUNET_NO, GNUNET_NT_UNSPECIFIED, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SERVER_connect_socket(), GNUNET_STATISTICS_update(), GNUNET_YES, IPv4TcpAddress::ipv4_addr, IPv6TcpAddress::ipv6_addr, LOG, Plugin::max_connections, Plugin::my_welcome, Plugin::nat, nat_connect_timeout(), GNUNET_ATS_Session::nat_connection_timeout, NAT_TIMEOUT, Plugin::nat_wait_conns, Plugin::open_port, options, IPv4TcpAddress::options, IPv6TcpAddress::options, GNUNET_HELLO_Address::peer, plugin, process_pending_messages(), GNUNET_ATS_SessionItCtx::result, Plugin::server, session_lookup_it(), Plugin::sessionmap, t4, IPv4TcpAddress::t4_port, t6, IPv6TcpAddress::t6_port, GNUNET_ATS_Session::target, TCP_OPTIONS_TCP_STEALTH, tcp_plugin_address_to_string(), and tcp_plugin_disconnect_session().

Referenced by libgnunet_plugin_transport_tcp_init().

2439 {
2440  struct Plugin *plugin = cls;
2441  struct GNUNET_ATS_Session *session = NULL;
2442  int af;
2443  const void *sb;
2444  size_t sbs;
2445  struct GNUNET_CONNECTION_Handle *sa;
2446  struct sockaddr_in a4;
2447  struct sockaddr_in6 a6;
2448  const struct IPv4TcpAddress *t4;
2449  const struct IPv6TcpAddress *t6;
2450  unsigned int options;
2451  enum GNUNET_NetworkType net_type;
2452  unsigned int is_natd = GNUNET_NO;
2453  size_t addrlen;
2454 #ifdef TCP_STEALTH
2455  struct GNUNET_NETWORK_Handle *s;
2456 #endif
2457 
2458  addrlen = address->address_length;
2460  "Trying to get session for `%s' address of peer `%s'\n",
2462  address->address,
2463  address->address_length),
2464  GNUNET_i2s (&address->peer));
2465 
2466  if (GNUNET_HELLO_address_check_option (address,
2468  {
2469  GNUNET_break (0);
2470  return NULL;
2471  }
2472 
2473  /* look for existing session */
2474  if (GNUNET_YES ==
2476  &address->peer))
2477  {
2478  struct GNUNET_ATS_SessionItCtx si_ctx;
2479 
2480  si_ctx.address = address;
2481  si_ctx.result = NULL;
2483  &address->peer,
2485  &si_ctx);
2486  if (NULL != si_ctx.result)
2487  {
2488  session = si_ctx.result;
2490  "Found existing session for `%s' address `%s'\n",
2491  GNUNET_i2s (&address->peer),
2493  address->address,
2494  address->address_length));
2495  return session;
2496  }
2497  /* This is a bit of a hack, limiting TCP to never allow more than
2498  one TCP connection to any given peer at the same time.
2499  Without this, peers sometimes disagree about which of the TCP
2500  connections they should use, causing one side to believe that
2501  they transmit successfully, while the other receives nothing. */
2502  return NULL; /* Refuse to have more than one TCP connection per
2503  peer pair at the same time. */
2504  }
2505 
2506  if (addrlen == sizeof(struct IPv6TcpAddress))
2507  {
2508  GNUNET_assert (NULL != address->address); /* make static analysis happy */
2509  t6 = address->address;
2510  options = t6->options;
2511  af = AF_INET6;
2512  memset (&a6, 0, sizeof(a6));
2513 #if HAVE_SOCKADDR_IN_SIN_LEN
2514  a6.sin6_len = sizeof (a6);
2515 #endif
2516  a6.sin6_family = AF_INET6;
2517  a6.sin6_port = t6->t6_port;
2518  if (t6->t6_port == 0)
2519  is_natd = GNUNET_YES;
2520  GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr));
2521  sb = &a6;
2522  sbs = sizeof(a6);
2523  }
2524  else if (addrlen == sizeof(struct IPv4TcpAddress))
2525  {
2526  GNUNET_assert(NULL != address->address); /* make static analysis happy */
2527  t4 = address->address;
2528  options = t4->options;
2529  af = AF_INET;
2530  memset (&a4, 0, sizeof(a4));
2531 #if HAVE_SOCKADDR_IN_SIN_LEN
2532  a4.sin_len = sizeof (a4);
2533 #endif
2534  a4.sin_family = AF_INET;
2535  a4.sin_port = t4->t4_port;
2536  if (t4->t4_port == 0)
2537  is_natd = GNUNET_YES;
2538  a4.sin_addr.s_addr = t4->ipv4_addr;
2539  sb = &a4;
2540  sbs = sizeof(a4);
2541  }
2542  else
2543  {
2544  GNUNET_STATISTICS_update (plugin->env->stats,
2545  gettext_noop ("# requests to create session with invalid address"),
2546  1,
2547  GNUNET_NO);
2548  return NULL;
2549  }
2550 
2551  net_type = plugin->env->get_address_type (plugin->env->cls,
2552  sb,
2553  sbs);
2554  GNUNET_break (net_type != GNUNET_NT_UNSPECIFIED);
2555 
2556  if ( (is_natd == GNUNET_YES) &&
2557  (addrlen == sizeof(struct IPv6TcpAddress)) )
2558  {
2559  /* NAT client only works with IPv4 addresses */
2560  return NULL;
2561  }
2562 
2563  if (plugin->cur_connections >= plugin->max_connections)
2564  {
2565  /* saturated */
2566  return NULL;
2567  }
2568 
2569  if ( (is_natd == GNUNET_YES) &&
2570  (GNUNET_YES ==
2572  &address->peer)))
2573  {
2574  /* Only do one NAT punch attempt per peer identity */
2575  return NULL;
2576  }
2577 
2578  if ( (is_natd == GNUNET_YES) &&
2579  (NULL != plugin->nat) &&
2580  (GNUNET_NO ==
2582  &address->peer)))
2583  {
2584  struct sockaddr_in local_sa;
2585 
2587  "Found valid IPv4 NAT address (creating session)!\n");
2588  session = create_session (plugin,
2589  address,
2590  net_type,
2591  NULL,
2592  GNUNET_YES);
2595  session);
2598  &session->target,
2599  session,
2601 
2603  "Created NAT WAIT connection to `%s' at `%s'\n",
2604  GNUNET_i2s (&session->target),
2605  GNUNET_a2s (sb, sbs));
2606  memset (&local_sa,
2607  0,
2608  sizeof (local_sa));
2609  local_sa.sin_family = AF_INET;
2610  local_sa.sin_port = htons (plugin->open_port);
2611  /* We leave sin_address at 0, let the kernel figure it out,
2612  even if our bind() is more specific. (May want to reconsider
2613  later.) */
2614  if (GNUNET_OK ==
2616  &local_sa,
2617  &a4))
2618  return session;
2620  "Running NAT client for `%s' at `%s' failed\n",
2621  GNUNET_i2s (&session->target),
2622  GNUNET_a2s (sb, sbs));
2624  session);
2625  return NULL;
2626  }
2627 
2628  /* create new outbound session */
2629  if (0 != (options & TCP_OPTIONS_TCP_STEALTH))
2630  {
2631 #ifdef TCP_STEALTH
2632  s = GNUNET_NETWORK_socket_create (af, SOCK_STREAM, 0);
2633  if (NULL == s)
2634  {
2636  "socket");
2637  sa = NULL;
2638  }
2639  else
2640  {
2641  if ( (GNUNET_OK !=
2643  IPPROTO_TCP,
2644  TCP_STEALTH,
2645  &session->target,
2646  sizeof (struct GNUNET_PeerIdentity))) ||
2647  (GNUNET_OK !=
2649  IPPROTO_TCP,
2650  TCP_STEALTH_INTEGRITY,
2651  &plugin->my_welcome,
2652  sizeof (struct WelcomeMessage))) )
2653  {
2654  /* TCP STEALTH not supported by kernel */
2657  sa = NULL;
2658  }
2659  else
2660  {
2661  sa = GNUNET_CONNECTION_connect_socket (s, sb, sbs);
2662  }
2663  }
2664 #else
2665  sa = NULL;
2666 #endif
2667  }
2668  else
2669  {
2670  sa = GNUNET_CONNECTION_create_from_sockaddr (af, sb, sbs);
2671  }
2672  if (NULL == sa)
2673  {
2675  "Failed to create connection to `%s' at `%s'\n",
2676  GNUNET_i2s (&address->peer),
2677  GNUNET_a2s (sb, sbs));
2678  return NULL;
2679  }
2681  "Asked to transmit to `%s', creating fresh session using address `%s'.\n",
2682  GNUNET_i2s (&address->peer),
2683  GNUNET_a2s (sb, sbs));
2684 
2685  session = create_session (plugin,
2686  address,
2687  net_type,
2689  sa),
2690  GNUNET_NO);
2692  &session->target,
2693  session,
2695  /* Send TCP Welcome */
2696  process_pending_messages (session);
2697 
2698  return session;
2699 }
size_t address_length
Number of bytes in address.
struct GNUNET_NAT_Handle * nat
NAT handle & address management.
int GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Handle *fd, int level, int option_name, const void *option_value, socklen_t option_len)
Set socket option.
Definition: network.c:1005
int max_connections
Maximum number of sockets the plugin can use Each http inbound /outbound connections are two connecti...
struct GNUNET_CONTAINER_MultiPeerMap * sessionmap
Map from peer identities to sessions for the given peer.
const void * address
Binary representation of the address (plugin-specific).
int GNUNET_NAT_request_reversal(struct GNUNET_NAT_Handle *nh, const struct sockaddr_in *local_sa, const struct sockaddr_in *remote_sa)
We learned about a peer (possibly behind NAT) so run the gnunet-nat-client to send dummy ICMP respons...
Definition: nat_api.c:655
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_connect_socket(struct GNUNET_NETWORK_Handle *s, const struct sockaddr *serv_addr, socklen_t addrlen)
Create a connection handle by (asynchronously) connecting to a host.
uint16_t open_port
Port that we are actually listening on.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SCHEDULER_Task * nat_connection_timeout
Task cleaning up a NAT client connection establishment attempt;.
static struct GNUNET_ATS_Session * create_session(struct Plugin *plugin, const struct GNUNET_HELLO_Address *address, enum GNUNET_NetworkType scope, struct GNUNET_SERVER_Client *client, int is_nat)
Create a new session.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
uint32_t options
Optional flags for this address see enum TcpAddressOptions
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
GNUNET_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...
int cur_connections
Current number of establishes connections.
int GNUNET_HELLO_address_check_option(const struct GNUNET_HELLO_Address *address, enum GNUNET_HELLO_AddressInfo option)
Check if an address has a local option set.
Definition: address.c:39
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
struct GNUNET_SERVER_Client * GNUNET_SERVER_connect_socket(struct GNUNET_SERVER_Handle *server, struct GNUNET_CONNECTION_Handle *connection)
Add a TCP socket-based connection to the set of handles managed by this server.
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
Network format for IPv4 addresses.
uint32_t options
Optional options and flags for this address, see enum TcpAddressOptions
static int tcp_plugin_disconnect_session(void *cls, struct GNUNET_ATS_Session *session)
Functions with this signature are called whenever we need to close a session due to a disconnect or f...
#define GNUNET_memcpy(dst, src, n)
Information about ongoing sessions of the transport client.
This is an inbound address and cannot be used to initiate an outbound connection to another peer...
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
static struct GNUNET_SCHEDULER_Task * t4
Task for IPv4 socket.
struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_sockaddr(int af_family, const struct sockaddr *serv_addr, socklen_t addrlen)
Create a connection handle by creating a socket and (asynchronously) connecting to a host...
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
Closure for session_lookup_it().
Network format for IPv6 addresses.
const struct GNUNET_HELLO_Address * address
Address we are looking for.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
struct in6_addr ipv6_addr
IPv6 address.
static const char * tcp_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
Function called for a quick conversion of the binary address to a numeric address.
static int session_lookup_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Look for a session by address.
struct GNUNET_PeerIdentity peer
For which peer is this an address?
Allow multiple values with the same key.
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.
The identity of the host (wraps the signing key of the peer).
static void process_pending_messages(struct GNUNET_ATS_Session *session)
If we have pending messages, ask the server to transmit them (schedule the respective tasks...
Handle for a plugin.
Definition: block.c:37
struct GNUNET_PeerIdentity target
To whom are we talking to.
Initial handshake message for a session.
struct WelcomeMessage my_welcome
Welcome message used by this peer.
uint16_t t4_port
Port number, in network byte order.
handle to a socket
Definition: network.c:46
void * cls
Closure to use for callbacks.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_CONTAINER_MultiPeerMap * nat_wait_conns
Map of peers we have tried to contact behind a NAT.
#define NAT_TIMEOUT
How long until we give up on establishing an NAT connection? Must be > 4 RTT.
Enable TCP Stealth-style port knocking.
uint32_t ipv4_addr
IPv4 address, in network byte order.
#define LOG(kind,...)
handle for a network connection
int GNUNET_CONTAINER_multipeermap_contains(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Check if the map contains any value under the given key (including values that are NULL)...
static char * address
GNS address for this phone.
struct GNUNET_SERVER_Handle * server
Handle to the server for this service.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:604
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.
uint16_t t6_port
Port number, in network byte order.
static struct GNUNET_SCHEDULER_Task * t6
Task for IPv6 socket.
#define gettext_noop(String)
Definition: gettext.h:69
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:1037
Category of last resort.
Definition: gnunet_nt_lib.h:40
static void nat_connect_timeout(void *cls)
Task cleaning up a NAT connection attempt after timeout.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ session_disconnect_it()

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

We have been asked to destroy all connections to a particular peer.

This function is called on each applicable session and must tear it down.

Parameters
clsthe struct Plugin *
keythe peer which the session belongs to (unused)
valuethe struct GNUNET_ATS_Session
Returns
GNUNET_YES (continue to iterate)

Definition at line 2713 of file plugin_transport_tcp.c.

References Plugin::env, gettext_noop, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_YES, plugin, GNUNET_ATS_Session::plugin, tcp_plugin_disconnect_session(), and value.

Referenced by libgnunet_plugin_transport_tcp_done(), and tcp_plugin_disconnect().

2716 {
2717  struct Plugin *plugin = cls;
2718  struct GNUNET_ATS_Session *session = value;
2719 
2720  GNUNET_STATISTICS_update (session->plugin->env->stats,
2721  gettext_noop ("# transport-service disconnect requests for TCP"),
2722  1,
2723  GNUNET_NO);
2725  session);
2726  return GNUNET_YES;
2727 }
struct Plugin * plugin
Pointer to the global plugin struct.
#define GNUNET_NO
Definition: gnunet_common.h:81
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
static int tcp_plugin_disconnect_session(void *cls, struct GNUNET_ATS_Session *session)
Functions with this signature are called whenever we need to close a session due to a disconnect or f...
static char * value
Value of the record to add/remove.
Information about ongoing sessions of the transport client.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
Handle for a plugin.
Definition: block.c:37
#define GNUNET_YES
Definition: gnunet_common.h:80
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcp_plugin_disconnect()

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

Function that can be called to force a disconnect from the specified neighbour.

This should also cancel all previously scheduled transmissions. Obviously the transmission may have been partially completed already, which is OK. The plugin is supposed to close the connection (if applicable) and no longer call the transmit continuation(s).

Finally, plugin MUST NOT call the services's receive function to notify the service that the connection to the specified target was closed after a getting this call.

Parameters
clsclosure
targetpeer for which the last transmission is to be cancelled

Definition at line 2747 of file plugin_transport_tcp.c.

References GNUNET_CONTAINER_multipeermap_get_multiple(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), LOG, Plugin::nat_wait_conns, plugin, session_disconnect_it(), and Plugin::sessionmap.

Referenced by libgnunet_plugin_transport_tcp_init().

2749 {
2750  struct Plugin *plugin = cls;
2751 
2753  "Disconnecting peer `%s'\n",
2754  GNUNET_i2s (target));
2756  target,
2758  plugin);
2760  target,
2762  plugin);
2763 }
struct GNUNET_CONTAINER_MultiPeerMap * sessionmap
Map from peer identities to sessions for the given peer.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
static int session_disconnect_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
We have been asked to destroy all connections to a particular peer.
Handle for a plugin.
Definition: block.c:37
struct GNUNET_CONTAINER_MultiPeerMap * nat_wait_conns
Map of peers we have tried to contact behind a NAT.
#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:

◆ append_port()

static void append_port ( void *  cls,
const char *  hostname 
)
static

We are processing an address pretty printing request and finished the IP resolution (if applicable).

Append our port and forward the result. If called with hostname NULL, we are done and should clean up the pretty printer (otherwise, there might be multiple hostnames for the IP address and we might receive more).

Parameters
clsthe struct PrettyPrinterContext *
hostnamehostname part of the address

Definition at line 2777 of file plugin_transport_tcp.c.

References PrettyPrinterContext::asc, PrettyPrinterContext::asc_cls, GNUNET_asprintf(), GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_YES, PrettyPrinterContext::ipv6, PrettyPrinterContext::options, plugin, PrettyPrinterContext::plugin, PLUGIN_NAME, PrettyPrinterContext::port, Plugin::ppc_dll_head, Plugin::ppc_dll_tail, PrettyPrinterContext::resolver_handle, and ret.

Referenced by tcp_plugin_address_pretty_printer().

2779 {
2780  struct PrettyPrinterContext *ppc = cls;
2781  struct Plugin *plugin = ppc->plugin;
2782  char *ret;
2783 
2785  "append_port called with hostname `%s'\n",
2786  hostname);
2787  if (NULL == hostname)
2788  {
2789  /* Final call, done */
2790  ppc->resolver_handle = NULL;
2792  plugin->ppc_dll_tail,
2793  ppc);
2794  ppc->asc (ppc->asc_cls,
2795  NULL,
2796  GNUNET_OK);
2797  GNUNET_free (ppc);
2798  return;
2799  }
2800  if (GNUNET_YES == ppc->ipv6)
2801  GNUNET_asprintf (&ret,
2802  "%s.%u.[%s]:%d",
2803  PLUGIN_NAME,
2804  ppc->options,
2805  hostname,
2806  ppc->port);
2807  else
2808  GNUNET_asprintf (&ret,
2809  "%s.%u.%s:%d",
2810  PLUGIN_NAME,
2811  ppc->options,
2812  hostname,
2813  ppc->port);
2814  ppc->asc (ppc->asc_cls,
2815  ret,
2816  GNUNET_OK);
2817  GNUNET_free (ret);
2818 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
GNUNET_TRANSPORT_AddressStringCallback asc
Function to call with the result.
struct PrettyPrinterContext * ppc_dll_tail
Running pretty printers: tail.
struct GNUNET_RESOLVER_RequestHandle * resolver_handle
Resolver handle.
Closure for append_port().
uint16_t port
Port to add after the IP address.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
void * asc_cls
Clsoure for asc.
static int ret
Final status code.
Definition: gnunet-arm.c:89
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
#define PLUGIN_NAME
static char * hostname
Our hostname; we give this to all the peers we start.
Handle for a plugin.
Definition: block.c:37
uint32_t options
Address options.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:80
struct PrettyPrinterContext * ppc_dll_head
Running pretty printers: head.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcp_plugin_address_pretty_printer()

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

Convert the transports address to a nice, human-readable format.

Parameters
clsclosure with the struct Plugin
typename of the transport that generated the address
addrone of the addresses of the host, NULL for the last address the specific address format depends on the transport
addrlenlength of the addr
numericshould (IP) addresses be displayed in numeric form?
timeoutafter how long should we give up?
ascfunction to call on each string
asc_clsclosure for asc

Definition at line 2835 of file plugin_transport_tcp.c.

References _, append_port(), PrettyPrinterContext::asc, PrettyPrinterContext::asc_cls, GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_memcpy, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_RESOLVER_hostname_get(), GNUNET_SYSERR, GNUNET_YES, IPv4TcpAddress::ipv4_addr, PrettyPrinterContext::ipv6, IPv6TcpAddress::ipv6_addr, LOG, options, PrettyPrinterContext::options, IPv4TcpAddress::options, IPv6TcpAddress::options, plugin, PrettyPrinterContext::plugin, port, PrettyPrinterContext::port, Plugin::ppc_dll_head, Plugin::ppc_dll_tail, PrettyPrinterContext::resolver_handle, t4, IPv4TcpAddress::t4_port, t6, and