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"
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 |
Session handle for connections. 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_MessageStreamTokenizer * | GNUNET_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_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. 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_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. 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_Session * | lookup_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_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. 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_Session * | tcp_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... | |
Implementation of the TCP transport service.
Definition in file plugin_transport_tcp.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "transport-tcp", __VA_ARGS__) |
Definition at line 38 of file plugin_transport_tcp.c.
#define PLUGIN_NAME "tcp" |
Definition at line 40 of file plugin_transport_tcp.c.
#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.
Definition at line 46 of file plugin_transport_tcp.c.
#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.
client | client to query |
type | expected return type (i.e. 'struct Foo') |
Definition at line 413 of file plugin_transport_tcp.c.
#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.
client | client to query |
value | pointer to user context |
Definition at line 422 of file plugin_transport_tcp.c.
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.
cls | closure |
size | number of bytes available in buf |
buf | where the callee should write the message |
Definition at line 99 of file plugin_transport_tcp.c.
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.
cls | closure |
client | identification of the client; NULL for the last call when the server is destroyed |
Definition at line 128 of file plugin_transport_tcp.c.
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.
cls | closure |
client | identification of the client |
Definition at line 140 of file plugin_transport_tcp.c.
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.
cls | closure |
ucred | credentials, if available, otherwise NULL |
addr | address |
addrlen | length of address |
Definition at line 155 of file plugin_transport_tcp.c.
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.
cls | closure |
buf | pointer to received data |
available | number of bytes available in "buf", possibly 0 (on errors) |
addr | address of the sender |
addrlen | size of addr |
errCode | value of errno (on errors receiving) |
Definition at line 173 of file plugin_transport_tcp.c.
typedef void*(* GNUNET_SERVER_MstCreateCallback) (void *cls, struct GNUNET_SERVER_Client *client) |
Signature of a function to create a custom tokenizer.
cls | closure from GNUNET_SERVER_set_callbacks |
client | handle to client the tokenzier will be used for |
Definition at line 199 of file plugin_transport_tcp.c.
typedef void(* GNUNET_SERVER_MstDestroyCallback) (void *cls, void *mst) |
Signature of a function to destroy a custom tokenizer.
cls | closure from GNUNET_SERVER_set_callbacks |
mst | custom tokenizer handle |
Definition at line 210 of file plugin_transport_tcp.c.
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.
cls | closure from GNUNET_SERVER_set_callbacks |
mst | custom tokenizer handle |
client_identity | ID of client for which this is a buffer, can be NULL (will be passed back to 'cb') |
buf | input data to add |
size | number of bytes in buf |
purge | should any excess bytes in the buffer be discarded (i.e. for packet-based services like UDP) |
one_shot | only call callback once, keep rest of message in buffer |
Definition at line 228 of file plugin_transport_tcp.c.
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.
cls | closure |
client | identification of the client |
message | the actual message |
Definition at line 244 of file plugin_transport_tcp.c.
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.
cls | closure |
client | identification of the client |
message | the actual message |
Definition at line 342 of file plugin_transport_tcp.c.
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.
cls | closure |
server | the initialized server |
cfg | configuration to use |
Definition at line 490 of file plugin_transport_tcp.c.
Options for the service (bitmask).
Definition at line 283 of file plugin_transport_tcp.c.
enum TcpAddressOptions |
Bits in the options
field of TCP addresses.
Enumerator | |
---|---|
TCP_OPTIONS_NONE | No bits set. |
TCP_OPTIONS_RESERVED | |
TCP_OPTIONS_TCP_STEALTH | Enable TCP Stealth-style port knocking. |
Definition at line 642 of file plugin_transport_tcp.c.
void LEGACY_SERVICE_stop | ( | struct LEGACY_SERVICE_Context * | sctx | ) |
Stops a service that was started with GNUNET_SERVICE_start().
srv | service to stop |
Stops a service that was started with GNUNET_SERVICE_start().
sctx | the service context returned from the start function |
Definition at line 1598 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_nz, 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().
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.
connection | connection to destroy |
Definition at line 1023 of file tcp_connection_legacy.c.
References GNUNET_CONNECTION_Handle::addr, GNUNET_CONNECTION_Handle::ap_head, GNUNET_CONNECTION_Handle::ap_tail, AddressProbe::connection, 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_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().
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.
client | the 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.
client | the client to disconnect from |
Definition at line 1497 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().
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).
client | client to query |
size | number of bytes in user context struct (for verification only) |
Definition at line 349 of file tcp_server_legacy.c.
References GNUNET_assert, size, GNUNET_SERVER_Client::user_context, and GNUNET_SERVER_Client::user_context_size.
struct GNUNET_SERVER_MessageStreamTokenizer* GNUNET_SERVER_mst_create | ( | GNUNET_SERVER_MessageTokenizerCallback | cb, |
void * | cb_cls | ||
) |
Create a message stream tokenizer.
cb | function to call on completed messages |
cb_cls | closure for cb |
Definition at line 83 of file tcp_server_mst_legacy.c.
References GNUNET_SERVER_MessageStreamTokenizer::cb, GNUNET_SERVER_MessageStreamTokenizer::cb_cls, GNUNET_malloc, GNUNET_MIN_MESSAGE_SIZE, GNUNET_new, and ret.
Referenced by GNUNET_SERVER_connect_socket().
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.
mst | tokenizer to use |
client_identity | ID of client for which this is a buffer, can be NULL (will be passed back to 'cb') |
buf | input data to add |
size | number of bytes in buf |
purge | should any excess bytes in the buffer be discarded (i.e. for packet-based services like UDP) |
one_shot | only call callback once, keep rest of message in buffer |
mst | tokenizer to use |
client_identity | ID of client for which this is a buffer |
buf | input data to add |
size | number of bytes in buf |
purge | should any excess bytes in the buffer be discarded (i.e. for packet-based services like UDP) |
one_shot | only call callback once, keep rest of message in buffer |
Definition at line 113 of file tcp_server_mst_legacy.c.
References ALIGN_FACTOR, buf, 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, GNUNET_MessageHeader::size, and size.
Referenced by handle_helper_message(), process_data(), process_incoming(), process_mst(), and wlan_data_message_handler().
void GNUNET_SERVER_mst_destroy | ( | struct GNUNET_SERVER_MessageStreamTokenizer * | mst | ) |
Destroys a tokenizer.
mst | tokenizer to destroy |
Definition at line 300 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().
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).
client | client to query |
ptr | pointer to user context |
size | number of bytes in user context struct (for verification only) |
Definition at line 369 of file tcp_server_legacy.c.
References size, GNUNET_SERVER_Client::user_context, and GNUNET_SERVER_Client::user_context_size.
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.
client | client to transmit message to |
size | requested amount of buffer space |
timeout | after how long should we give up (and call notify with buf NULL and size 0)? |
callback | function to call when space is available |
callback_cls | closure for callback |
Definition at line 1619 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(), size, GNUNET_SERVER_Client::th, timeout, and transmit_ready_callback_wrapper().
Referenced by process_pending_messages().
void GNUNET_SERVER_notify_transmit_ready_cancel | ( | struct GNUNET_SERVER_TransmitHandle * | th | ) |
Abort transmission request.
th | request to abort |
Definition at line 1646 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().
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).
client | the client to keep |
Definition at line 1331 of file tcp_server_legacy.c.
References GNUNET_SERVER_Client::reference_count.
Referenced by process_incoming(), and restart_processing().
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.
client | the client to drop |
Definition at line 1346 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().
void GNUNET_SERVER_suspend | ( | struct GNUNET_SERVER_Handle * | server | ) |
Suspend accepting connections from the listen socket temporarily.
Resume activity using GNUNET_SERVER_resume.
server | server to stop accepting connections. |
server | server to stop accepting connections. |
Definition at line 692 of file tcp_server_legacy.c.
References GNUNET_SCHEDULER_cancel(), GNUNET_SERVER_Handle::listen_task, and GNUNET_SERVER_Client::server.
Referenced by connect_notify().
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).
server | the server to use |
connection | the connection to manage (client must stop using this connection from now on) |
Definition at line 1271 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().
void GNUNET_SERVER_resume | ( | struct GNUNET_SERVER_Handle * | server | ) |
Resume accepting connections from the listen socket.
server | server to resume 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().
void GNUNET_SERVER_destroy | ( | struct GNUNET_SERVER_Handle * | server | ) |
Free resources held by this server.
server | server to destroy |
Definition at line 775 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().
|
static |
Get the list of addresses that a server for the given service should bind to.
service_name | name of the service |
cfg | configuration (which specifies the addresses) |
addrs | set (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_lens | set (call by reference) to an array of the lengths of the respective struct sockaddr struct in the addrs array (on success) |
*addrs
and *addr_lens
will be set to NULL). Definition at line 1053 of file plugin_transport_tcp.c.
References _, add_unixpath(), cfg, 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_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 service_name.
Referenced by libgnunet_plugin_transport_tcp_init().
|
static |
If a session monitor is attached, notify it about the new session state.
plugin | our plugin |
session | session that changed state |
state | new state of the session |
Definition at line 1394 of file plugin_transport_tcp.c.
References GNUNET_ATS_Session::address, GNUNET_ATS_Session::bytes_in_queue, GNUNET_HELLO_address_check_option(), GNUNET_HELLO_ADDRESS_INFO_INBOUND, info, GNUNET_ATS_Session::msgs_in_queue, plugin, GNUNET_ATS_Session::receive_delay, GNUNET_ATS_Session::receive_delay_task, 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().
|
static |
Our external IP address/port mapping has changed.
cls | closure, the struct Plugin | |
[in,out] | app_ctx | location where the app can store stuff on add and retrieve it on remove |
add_remove | GNUNET_YES to mean the new public IP address, GNUNET_NO to mean the previous (now invalid) one | |
ac | address class the address belongs to | |
addr | either the previous or the new public IP address | |
addrlen | actual length of addr |
Definition at line 1430 of file plugin_transport_tcp.c.
References address, find_typedefs::arg, consensus-simulation::args, 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, LOG, plugin, PLUGIN_NAME, t4, and t6.
Referenced by libgnunet_plugin_transport_tcp_init().
|
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.
cls | closure (struct Plugin* ) |
addr | binary address |
addrlen | length of addr |
Definition at line 1510 of file plugin_transport_tcp.c.
References buf, 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().
|
static |
Function called to convert a string address to a binary address.
cls | closure (struct Plugin* ) |
addr | string address |
addrlen | length of the address |
buf | location to store the buffer |
added | location to store the number of bytes in the buffer. If the function returns GNUNET_SYSERR, its contents are undefined. |
Definition at line 1578 of file plugin_transport_tcp.c.
References address, buf, GNUNET_break, GNUNET_free, GNUNET_new, GNUNET_OK, GNUNET_strdup, GNUNET_STRINGS_to_address_ip(), GNUNET_SYSERR, options, plugin, t4, and t6.
Referenced by libgnunet_plugin_transport_tcp_init().
|
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.
plugin | the plugin |
client | which client to find the session handle for |
Definition at line 1682 of file plugin_transport_tcp.c.
References GNUNET_ATS_Session::client, and GNUNET_SERVER_client_get_user_context.
Referenced by disconnect_notify(), handle_tcp_data(), and handle_tcp_welcome().
|
static |
Functions with this signature are called whenever we need to close a session due to a disconnect or failure to establish a connection.
cls | the struct Plugin |
session | session to close down |
Definition at line 1700 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, GNUNET_ATS_Session::msgs_in_queue, GNUNET_ATS_Session::nat_connection_timeout, 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, GNUNET_ATS_Session::target, tcp_plugin_address_to_string(), GNUNET_ATS_Session::timeout, GNUNET_ATS_Session::timeout_task, 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().
|
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.
cls | closure with the struct Plugin |
Definition at line 1818 of file plugin_transport_tcp.c.
Referenced by libgnunet_plugin_transport_tcp_init().
|
static |
Session was idle for too long, so disconnect it.
cls | the struct GNUNET_ATS_Session of the idle session |
Definition at line 1830 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().
|
static |
Increment session timeout due to activity.
s | session to increment timeout for |
Definition at line 1862 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().
|
static |
Create a new session.
Also queues a welcome message.
plugin | the plugin |
address | the address to create the session for |
scope | network scope the address is from |
client | client to use, reference counter must have already been increased |
is_nat | this a NAT session, we should wait for a client to connect to us from an address, then assign that to the session |
Definition at line 1883 of file plugin_transport_tcp.c.
References address, GNUNET_ATS_Session::address, GNUNET_ATS_Session::bytes_in_queue, PendingMessage::client, GNUNET_ATS_Session::client, 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, 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, pm, GNUNET_ATS_Session::scope, scope, session_timeout(), GNUNET_ATS_Session::target, tcp_plugin_address_to_string(), GNUNET_ATS_Session::timeout, and GNUNET_ATS_Session::timeout_task.
Referenced by handle_tcp_welcome(), and tcp_plugin_get_session().
|
static |
If we have pending messages, ask the server to transmit them (schedule the respective tasks, etc.)
session | for which session should we do this |
Definition at line 2125 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(), GNUNET_ATS_Session::pending_messages_head, pm, and GNUNET_ATS_Session::transmit_handle.
Referenced by do_transmit(), handle_tcp_nat_probe(), handle_tcp_welcome(), tcp_plugin_get_session(), and tcp_plugin_send().
|
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.
cls | closure |
size | number of bytes available in buf |
buf | where the callee should write the message |
Definition at line 1978 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, 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, pid, plugin, GNUNET_ATS_Session::plugin, process_pending_messages(), ret, size, 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().
|
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.
cls | closure |
session | which session must be used |
msgbuf | the message to transmit |
msgbuf_size | number of bytes in msgbuf |
priority | how important is the message (most plugins will ignore message priority and just FIFO) |
to | how 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) |
cont | continuation 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_cls | closure for cont |
Definition at line 2173 of file plugin_transport_tcp.c.
References GNUNET_ATS_Session::bytes_in_queue, GNUNET_ATS_Session::client, 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, 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, pm, process_pending_messages(), and GNUNET_ATS_Session::target.
Referenced by libgnunet_plugin_transport_tcp_init().
|
static |
Look for a session by address.
cls | the struct GNUNET_ATS_SessionItCtx |
key | unused |
value | a struct GNUNET_ATS_Session |
Definition at line 2282 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().
|
static |
Task cleaning up a NAT connection attempt after timeout.
cls | the struct GNUNET_ATS_Session |
Definition at line 2302 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().
|
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.
cls | closure |
peer | which peer was the session for |
session | which session is being updated |
Definition at line 2327 of file plugin_transport_tcp.c.
References reschedule_session_timeout().
Referenced by libgnunet_plugin_transport_tcp_init().
|
static |
Task to signal the server that we can continue receiving from the TCP client now.
cls | the struct GNUNET_ATS_Session * |
Definition at line 2342 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().
|
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.
cls | closure |
peer | which peer was the session for |
session | which session is being updated |
delay | new delay to use for receiving |
Definition at line 2363 of file plugin_transport_tcp.c.
References delay, 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().
|
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.
cls | closure |
address | the address to use |
Definition at line 2390 of file plugin_transport_tcp.c.
References address, GNUNET_ATS_SessionItCtx::address, GNUNET_NETWORK_Handle::addrlen, create_session(), 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, LOG, nat_connect_timeout(), GNUNET_ATS_Session::nat_connection_timeout, NAT_TIMEOUT, options, plugin, process_pending_messages(), GNUNET_ATS_SessionItCtx::result, session_lookup_it(), t4, t6, 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().
|
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.
cls | the struct Plugin * |
key | the peer which the session belongs to (unused) |
value | the struct GNUNET_ATS_Session |
Definition at line 2651 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().
|
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.
cls | closure |
target | peer for which the last transmission is to be cancelled |
Definition at line 2685 of file plugin_transport_tcp.c.
References GNUNET_CONTAINER_multipeermap_get_multiple(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), LOG, plugin, and session_disconnect_it().
Referenced by libgnunet_plugin_transport_tcp_init().
|
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).
cls | the struct PrettyPrinterContext * |
hostname | hostname part of the address |
Definition at line 2714 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, hostname, PrettyPrinterContext::ipv6, PrettyPrinterContext::options, plugin, PrettyPrinterContext::plugin, PLUGIN_NAME, PrettyPrinterContext::port, PrettyPrinterContext::resolver_handle, and ret.
Referenced by tcp_plugin_address_pretty_printer().
|
static |
Convert the transports address to a nice, human-readable format.
cls | closure with the struct Plugin |
type | name of the transport that generated the address |
addr | one of the addresses of the host, NULL for the last address the specific address format depends on the transport |
addrlen | length of the addr |
numeric | should (IP) addresses be displayed in numeric form? |
timeout | after how long should we give up? |
asc | function to call on each string |
asc_cls | closure for asc |
Definition at line 2767 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, PrettyPrinterContext::ipv6, LOG, numeric, options, PrettyPrinterContext::options, plugin, PrettyPrinterContext::plugin, port, PrettyPrinterContext::port, PrettyPrinterContext::resolver_handle, t4, t6, and timeout.
Referenced by libgnunet_plugin_transport_tcp_init().
|
static |
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).
Naturally, if absolutely necessary, plugins can be a bit conservative in their answer, but in general plugins should make sure that the address does not redirect traffic to a 3rd party that might try to man-in-the-middle our traffic.
cls | closure, our struct Plugin * |
addr | pointer to the address |
addrlen | length of addr |
Definition at line 2864 of file plugin_transport_tcp.c.
References GNUNET_break, GNUNET_break_op, GNUNET_NAT_test_address(), GNUNET_OK, GNUNET_SYSERR, and plugin.
Referenced by libgnunet_plugin_transport_tcp_init().
|
static |
We've received a nat probe from this peer via TCP.
Finish creating the client session and resume sending of queued messages.
cls | closure |
client | identification of the client |
message | the actual message |
Definition at line 2941 of file plugin_transport_tcp.c.
References GNUNET_ATS_Session::address, GNUNET_ATS_Session::client, TCP_NAT_ProbeMessage::clientIdentity, gettext_noop, GNUNET_a2s(), GNUNET_assert, GNUNET_break, GNUNET_break_op, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multipeermap_get(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_HELLO_address_allocate(), GNUNET_HELLO_ADDRESS_INFO_NONE, GNUNET_memcpy, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_SERVER_client_get_address(), GNUNET_SERVER_client_set_user_context, GNUNET_SERVER_receive_done(), GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_TIME_absolute_get(), GNUNET_YES, GNUNET_ATS_Session::last_activity, LOG, GNUNET_ATS_Session::nat_connection_timeout, plugin, PLUGIN_NAME, process_pending_messages(), GNUNET_MessageHeader::size, t4, t6, GNUNET_ATS_Session::target, TCP_OPTIONS_NONE, and tcp_plugin_disconnect_session().
Referenced by libgnunet_plugin_transport_tcp_init().
|
static |
We've received a welcome from this peer via TCP.
Possibly create a fresh client record and send back our welcome.
cls | closure |
client | identification of the client |
message | the actual message |
Definition at line 3075 of file plugin_transport_tcp.c.
References address, GNUNET_HELLO_Address::address, GNUNET_ATS_Session::address, GNUNET_HELLO_Address::address_length, WelcomeMessage::clientIdentity, create_session(), GNUNET_ATS_Session::expecting_welcome, gettext_noop, GNUNET_a2s(), GNUNET_break, GNUNET_break_op, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multipeermap_put(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_HELLO_address_allocate(), GNUNET_HELLO_address_check_option(), GNUNET_HELLO_address_free, GNUNET_HELLO_ADDRESS_INFO_INBOUND, GNUNET_i2s(), GNUNET_memcpy, GNUNET_NO, GNUNET_NT_UNSPECIFIED, GNUNET_OK, GNUNET_SERVER_client_get_address(), GNUNET_SERVER_client_set_timeout(), GNUNET_SERVER_receive_done(), GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_TIME_absolute_get(), GNUNET_YES, GNUNET_ATS_Session::last_activity, LOG, lookup_session_by_client(), plugin, PLUGIN_NAME, process_pending_messages(), GNUNET_ATS_Session::scope, t4, t6, GNUNET_ATS_Session::target, TCP_OPTIONS_NONE, and tcp_plugin_address_to_string().
Referenced by libgnunet_plugin_transport_tcp_init().
|
static |
We've received data for this peer via TCP.
Unbox, compute latency and forward.
cls | closure |
client | identification of the client |
message | the actual message |
Definition at line 3237 of file plugin_transport_tcp.c.
References GNUNET_ATS_Session::address, delay, delayed_done(), GNUNET_ATS_Session::expecting_welcome, gettext_noop, GNUNET_a2s(), GNUNET_assert, GNUNET_break_op, GNUNET_CONTAINER_multipeermap_contains_value(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_i2s(), GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SERVER_client_get_address(), GNUNET_SERVER_disable_receive_done_warning(), GNUNET_SERVER_receive_done(), GNUNET_STATISTICS_update(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_SYSERR, GNUNET_TIME_absolute_get(), GNUNET_YES, GNUNET_ATS_Session::last_activity, LOG, lookup_session_by_client(), plugin, GNUNET_ATS_Session::receive_delay_task, GNUNET_TIME_Relative::rel_value_us, reschedule_session_timeout(), GNUNET_MessageHeader::size, GNUNET_ATS_Session::target, GNUNET_MessageHeader::type, and type.
Referenced by libgnunet_plugin_transport_tcp_init().
|
static |
Function called whenever a peer is connected on the "SERVER" level.
Increments number of active connections and suspends server if we have reached the limit.
cls | closure |
client | identification of the client |
Definition at line 3345 of file plugin_transport_tcp.c.
References _, gettext_noop, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_NO, GNUNET_SERVER_suspend(), GNUNET_STATISTICS_set(), GNUNET_STATISTICS_update(), and plugin.
Referenced by libgnunet_plugin_transport_tcp_init().
|
static |
Function called whenever a peer is disconnected on the "SERVER" level.
Cleans up the connection, decrements number of active connections and if applicable resumes listening.
cls | closure |
client | identification of the client |
Definition at line 3382 of file plugin_transport_tcp.c.
References GNUNET_HELLO_Address::address, GNUNET_ATS_Session::address, GNUNET_HELLO_Address::address_length, GNUNET_ATS_Session::client, Plugin::env, gettext_noop, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_NO, GNUNET_SERVER_resume(), GNUNET_STATISTICS_set(), GNUNET_STATISTICS_update(), LOG, lookup_session_by_client(), plugin, GNUNET_ATS_Session::plugin, GNUNET_ATS_Session::target, tcp_plugin_address_to_string(), and tcp_plugin_disconnect_session().
Referenced by libgnunet_plugin_transport_tcp_init().
|
static |
We can now send a probe message, copy into buffer to really send.
cls | closure, a struct TCPProbeContext |
size | max size to copy |
buf | buffer to copy message to |
Definition at line 3431 of file plugin_transport_tcp.c.