reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
reTurn::TlsConnection Class Reference

Represents a single connection from a client. More...

#include <TlsConnection.hxx>

Inheritance diagram for reTurn::TlsConnection:
[legend]

Public Member Functions

 TlsConnection (asio::io_context &ioService, ConnectionManager &manager, RequestHandler &handler, asio::ssl::context &context)
 Construct a connection with the given io_context.
 
 TlsConnection (const TlsConnection &)=delete
 
 TlsConnection (TlsConnection &&)=delete
 
 ~TlsConnection ()
 
TlsConnection & operator= (const TlsConnection &)=delete
 
TlsConnection & operator= (TlsConnection &&)=delete
 
ssl_socket::lowest_layer_type & socket ()
 Get the socket associated with the connection.
 
virtual void start ()
 Start the first asynchronous operation for the connection.
 
virtual void close ()
 Override close fn in AsyncTcpSocketBase so that we can remove ourselves from connection manager.
 
virtual void stop ()
 Stop all asynchronous operations associated with the connection.
 
- Public Member Functions inherited from reTurn::AsyncTlsSocketBase
 AsyncTlsSocketBase (asio::io_context &ioService, asio::ssl::context &context, bool validateServerCertificateHostname)
 
unsigned int getSocketDescriptor () override
 
asio::error_code bind (const asio::ip::address &address, unsigned short port) override
 Note: The following API's are thread safe and queue the request to be handled by the ioService thread.
 
void connect (const std::string &address, unsigned short port) override
 
void doHandshake (unsigned int timeoutSeconds=0)
 Starts the server side handshake.
 
void transportReceive () override
 
void transportFramedReceive () override
 
void transportSend (const StunTuple &destination, std::vector< asio::const_buffer > &buffers) override
 
void transportClose () override
 
asio::ip::address getSenderEndpointAddress () override
 
unsigned short getSenderEndpointPort () override
 
- Public Member Functions inherited from reTurn::AsyncSocketBase
 AsyncSocketBase (asio::io_context &ioService)
 
virtual ~AsyncSocketBase ()
 
virtual void registerAsyncSocketBaseHandler (AsyncSocketBaseHandler *handler)
 
virtual void send (const StunTuple &destination, const std::shared_ptr< DataBuffer > &data)
 Note: destination is ignored for TCP and TLS connections.
 
virtual void send (const StunTuple &destination, unsigned short channel, const std::shared_ptr< DataBuffer > &data)
 
virtual void receive ()
 Overlapped calls to receive functions have no effect.
 
virtual void framedReceive ()
 
bool isConnected () const noexcept
 
asio::ip::address & getConnectedAddress () noexcept
 
unsigned short getConnectedPort () const noexcept
 
virtual void setOnBeforeSocketClosedFp (BeforeClosedHandler fp)
 
virtual void doSend (const StunTuple &destination, unsigned short channel, const std::shared_ptr< DataBuffer > &data, const std::size_t bufferStartPos=0)
 Use these if you already operating within the ioService thread.
 
virtual void doSend (const StunTuple &destination, const std::shared_ptr< DataBuffer > &data, const std::size_t bufferStartPos=0)
 
virtual void doReceive ()
 
virtual void doFramedReceive ()
 
virtual void onConnectSuccess ()
 Class override callbacks.
 
virtual void onConnectFailure (const asio::error_code &e)
 
virtual void handleUdpResolve (const asio::error_code &ec, const asio::ip::udp::resolver::results_type &endpoints)
 

Protected Member Functions

virtual void onServerHandshakeSuccess ()
 Handle completion of a handshake operation.
 
virtual void onServerHandshakeFailure (const asio::error_code &e)
 
virtual void onReceiveSuccess (const asio::ip::address &address, unsigned short port, const std::shared_ptr< DataBuffer > &data)
 Handle completion of a receive operation.
 
virtual void onReceiveFailure (const asio::error_code &e)
 
virtual void onSendSuccess ()
 Handle completion of a send operation.
 
virtual void onSendFailure (const asio::error_code &e)
 
- Protected Member Functions inherited from reTurn::AsyncTlsSocketBase
void handleReadHeader (const asio::error_code &e) override
 
void handleServerHandshake (const asio::error_code &e) override
 
void handleTcpResolve (const asio::error_code &ec, const asio::ip::tcp::resolver::results_type &endpoints) override
 
void handleConnect (const asio::error_code &ec, const asio::ip::tcp::endpoint &endpoint) override
 
void handleClientHandshake (const asio::error_code &ec, const asio::ip::tcp::endpoint &endpoint) override
 
- Protected Member Functions inherited from reTurn::AsyncSocketBase
virtual void handleSend (const asio::error_code &e)
 Handle completion of a sendData operation.
 
virtual void handleReceive (const asio::error_code &e, size_t bytesTransferred)
 
asio::error_code openAndBind (asio::ip::tcp::socket &socket)
 For TCP and TLS client sockets.
 
void asyncConnect (asio::ip::tcp::socket &socket, const asio::ip::tcp::resolver::results_type &endpoints)
 
void startIdleTimer (unsigned int timeoutSeconds, std::function< bool()> inUse)
 For server connections (TcpConnectionIdleTimeout): the connection is closed, with close(), once nothing has been received on it for timeoutSeconds while inUse() is false - eg.
 
void noteReceived ()
 
void stopIdleTimer ()
 

Protected Attributes

ConnectionManager & mConnectionManager
 The manager for this connection.
 
TurnAllocationManager mTurnAllocationManager
 Manages turn allocations.
 
RequestHandler & mRequestHandler
 The handler used to process the incoming request.
 
asio::ip::address mLocalAddress
 
unsigned short mLocalPort
 
- Protected Attributes inherited from reTurn::AsyncTlsSocketBase
asio::ssl::stream< asio::ip::tcp::socket > mSocket
 
asio::ip::tcp::resolver mResolver
 
- Protected Attributes inherited from reTurn::AsyncSocketBase
asio::ip::tcp::endpoint mLocalTcpEndpoint
 
asio::io_context & mIOService
 The io_context used to perform asynchronous operations.
 
std::shared_ptr< DataBuffer > mReceiveBuffer
 Receive Buffer and state.
 
bool mReceiving
 
asio::ip::address mConnectedAddress
 Connected Info and State.
 
unsigned short mConnectedPort
 
bool mConnected
 
AsyncSocketBaseHandler * mAsyncSocketBaseHandler
 Handlers.
 
BeforeClosedHandler mOnBeforeSocketCloseFp
 Provides an opportunity for the app to clean up, e.g., QoS-related data or resources just before the socket is closed.
 

Additional Inherited Members

- Public Types inherited from reTurn::AsyncSocketBase
using BeforeClosedHandler = std::function< void(unsigned int)>
 
- Static Public Member Functions inherited from reTurn::AsyncTlsSocketBase
static bool setupClientSsl (SSL *ssl, const std::string &hostname, bool validateHostname)
 Sets up a client SSL to connect to hostname (a host name or IP address): SNI for a host name, and - when validateHostname - has OpenSSL check during the handshake that the server certificate is for hostname, so the handshake fails if it isn't.
 
static void logClientHandshakeResult (SSL *ssl, const std::string &hostname, const asio::error_code &ec)
 Logs a client handshake's outcome: the TLS version and cipher, or why the server certificate was rejected.
 
- Static Public Member Functions inherited from reTurn::AsyncSocketBase
static std::shared_ptr< DataBuffer > allocateBuffer (size_t size)
 Utility API.
 
static size_t channelDataPadding (size_t length)
 Over TCP and TLS, a TURN ChannelData message is padded to a multiple of 4 bytes, the padding not counted in its length (RFC 5766 11.5, RFC 8656 12.5): the padding after one of length bytes.
 
static void setExclusiveAddressUse (asio::ip::udp::socket &socket)
 For a UDP socket, between open() and bind().
 

Detailed Description

Represents a single connection from a client.

Definition at line 22 of file TlsConnection.hxx.

Constructor & Destructor Documentation

◆ TlsConnection() [1/3]

reTurn::TlsConnection::TlsConnection ( asio::io_context &  ioService,
ConnectionManager &  manager,
RequestHandler &  handler,
asio::ssl::context &  context 
)
explicit

Construct a connection with the given io_context.

Definition at line 25 of file TlsConnection.cxx.

◆ TlsConnection() [2/3]

reTurn::TlsConnection::TlsConnection ( const TlsConnection &  )
delete

◆ TlsConnection() [3/3]

reTurn::TlsConnection::TlsConnection ( TlsConnection &&  )
delete

◆ ~TlsConnection()

reTurn::TlsConnection::~TlsConnection ( )

Definition at line 35 of file TlsConnection.cxx.

Member Function Documentation

◆ close()

void reTurn::TlsConnection::close ( )
virtual

Override close fn in AsyncTcpSocketBase so that we can remove ourselves from connection manager.

Reimplemented from reTurn::AsyncSocketBase.

Definition at line 68 of file TlsConnection.cxx.

◆ onReceiveFailure()

void reTurn::TlsConnection::onReceiveFailure ( const asio::error_code &  e)
protectedvirtual

Implements reTurn::AsyncSocketBase.

Definition at line 173 of file TlsConnection.cxx.

◆ onReceiveSuccess()

void reTurn::TlsConnection::onReceiveSuccess ( const asio::ip::address &  address,
unsigned short  port,
const std::shared_ptr< DataBuffer > &  data 
)
protectedvirtual

Handle completion of a receive operation.

Implements reTurn::AsyncSocketBase.

Definition at line 94 of file TlsConnection.cxx.

◆ onSendFailure()

void reTurn::TlsConnection::onSendFailure ( const asio::error_code &  e)
protectedvirtual

Implements reTurn::AsyncSocketBase.

Definition at line 189 of file TlsConnection.cxx.

◆ onSendSuccess()

void reTurn::TlsConnection::onSendSuccess ( )
protectedvirtual

Handle completion of a send operation.

Implements reTurn::AsyncSocketBase.

Definition at line 184 of file TlsConnection.cxx.

◆ onServerHandshakeFailure()

void reTurn::TlsConnection::onServerHandshakeFailure ( const asio::error_code &  e)
protectedvirtual

Reimplemented from reTurn::AsyncTlsSocketBase.

Definition at line 87 of file TlsConnection.cxx.

◆ onServerHandshakeSuccess()

void reTurn::TlsConnection::onServerHandshakeSuccess ( )
protectedvirtual

Handle completion of a handshake operation.

Reimplemented from reTurn::AsyncTlsSocketBase.

Definition at line 74 of file TlsConnection.cxx.

◆ operator=() [1/2]

TlsConnection & reTurn::TlsConnection::operator= ( const TlsConnection &  )
delete

◆ operator=() [2/2]

TlsConnection & reTurn::TlsConnection::operator= ( TlsConnection &&  )
delete

◆ socket()

ssl_socket::lowest_layer_type & reTurn::TlsConnection::socket ( )

Get the socket associated with the connection.

Definition at line 41 of file TlsConnection.cxx.

◆ start()

void reTurn::TlsConnection::start ( )
virtual

Start the first asynchronous operation for the connection.

Reimplemented from reTurn::AsyncSocketBase.

Definition at line 47 of file TlsConnection.cxx.

◆ stop()

void reTurn::TlsConnection::stop ( )
virtual

Stop all asynchronous operations associated with the connection.

Reimplemented from reTurn::AsyncSocketBase.

Definition at line 55 of file TlsConnection.cxx.

Member Data Documentation

◆ mConnectionManager

ConnectionManager& reTurn::TlsConnection::mConnectionManager
protected

The manager for this connection.

Definition at line 61 of file TlsConnection.hxx.

◆ mLocalAddress

asio::ip::address reTurn::TlsConnection::mLocalAddress
protected

Definition at line 70 of file TlsConnection.hxx.

◆ mLocalPort

unsigned short reTurn::TlsConnection::mLocalPort
protected

Definition at line 71 of file TlsConnection.hxx.

◆ mRequestHandler

RequestHandler& reTurn::TlsConnection::mRequestHandler
protected

The handler used to process the incoming request.

Definition at line 67 of file TlsConnection.hxx.

◆ mTurnAllocationManager

TurnAllocationManager reTurn::TlsConnection::mTurnAllocationManager
protected

Manages turn allocations.

Definition at line 64 of file TlsConnection.hxx.


The documentation for this class was generated from the following files: