SNode.C
Loading...
Searching...
No Matches
core::socket::stream::tls::SocketConnection< PhysicalSocketT, ConfigT > Class Template Referencefinal

#include <SocketConnection.h>

Inheritance diagram for core::socket::stream::tls::SocketConnection< PhysicalSocketT, ConfigT >:
Collaboration diagram for core::socket::stream::tls::SocketConnection< PhysicalSocketT, ConfigT >:

Public Types

using SocketAddress = typename Super::SocketAddress

Public Member Functions

 SocketConnection (PhysicalSocket &&physicalSocket, const std::function< void(SocketConnection *)> &onDisconnect, const std::shared_ptr< Config > &config)
SSL * getSSL () const
Public Member Functions inherited from core::socket::stream::SocketConnectionT< PhysicalSocketT, core::socket::stream::tls::SocketReader, core::socket::stream::tls::SocketWriter, ConfigT >
void sendToPeer (const std::string &data)
 SocketConnectionT ()=delete
int getFd () const final
void setTimeout (const utils::Timeval &timeout) final
void setReadTimeout (const utils::Timeval &timeout) final
void setWriteTimeout (const utils::Timeval &timeout) final
const SocketAddressgetBindAddress () const final
const SocketAddressgetLocalAddress () const final
const SocketAddressgetRemoteAddress () const final
std::size_t readFromPeer (char *chunk, std::size_t chunkLen) final
bool streamToPeer (core::pipe::Source *source) final
void streamEof () final
void shutdownRead () final
void shutdownWrite () final
void close () final
ConfiggetConfig () const
std::size_t getTotalSent () const override
std::size_t getTotalQueued () const override
std::size_t getTotalRead () const override
std::size_t getTotalProcessed () const override
Public Member Functions inherited from core::socket::stream::SocketConnection
 SocketConnection (int fd, const net::config::ConfigInstance *config)
 SocketConnection (const SocketConnection &)=delete
void setSocketContext (SocketContext *socketContext)
virtual void sendToPeer (const char *chunk, std::size_t chunkLen)=0
void sendToPeer (const std::string &data)
void sentToPeer (const std::vector< uint8_t > &data)
void sentToPeer (const std::vector< char > &data)
const std::string & getInstanceName () const
const std::string & getConnectionName () const
SocketContextgetSocketContext () const
std::string getOnlineSince () const
std::string getOnlineDuration () const
const net::config::ConfigInstancegetConfigInstance () const

Private Types

using Super
using Config = ConfigT
using PhysicalSocket = PhysicalSocketT
using SocketReader = typename Super::SocketReader
using SocketWriter = typename Super::SocketWriter

Private Member Functions

SSL * startSSL (int fd, SSL_CTX *ctx)
void stopSSL ()
bool doSSLHandshake (const std::function< void()> &onSuccess, const std::function< void()> &onTimeout, const std::function< void(int)> &onStatus) final
void doSSLShutdown ()
void onReadShutdown () final
void doWriteShutdown (const std::function< void()> &onShutdown) final

Private Attributes

SSL * ssl = nullptr
utils::Timeval sslInitTimeout
utils::Timeval sslShutdownTimeout
bool closeNotifyIsEOF

Friends

template<typename PhysicalSocket, typename Config>
class SocketAcceptor
template<typename PhysicalSocket, typename Config>
class SocketConnector

Additional Inherited Members

Protected Types inherited from core::socket::stream::SocketConnectionT< PhysicalSocketT, core::socket::stream::tls::SocketReader, core::socket::stream::tls::SocketWriter, ConfigT >
using Super
using Config
using PhysicalSocket
using SocketReader
using SocketWriter
using SocketAddress
Protected Member Functions inherited from core::socket::stream::SocketConnectionT< PhysicalSocketT, core::socket::stream::tls::SocketReader, core::socket::stream::tls::SocketWriter, ConfigT >
 ~SocketConnectionT () override
void doWriteShutdown (const std::function< void()> &onShutdown) override
void onWriteError (int errnum)
void onReadError (int errnum)
Protected Member Functions inherited from core::socket::stream::SocketConnection
virtual ~SocketConnection ()
void setSocketContext (const std::shared_ptr< SocketContextFactory > &socketContextFactory)
Protected Member Functions inherited from core::socket::stream::SocketReader
 SocketReader (const std::string &instanceName, const std::function< void(int)> &onStatus, const utils::Timeval &timeout, std::size_t blockSize, const utils::Timeval &terminateTimeout)
std::size_t getTotalRead () const
std::size_t getTotalProcessed () const
void setBlockSize (std::size_t readBlockSize)
std::size_t readFromPeer (char *chunk, std::size_t chunkLen)
void shutdownRead ()
 SocketReader ()=delete
Protected Member Functions inherited from core::eventreceiver::ReadEventReceiver
 ReadEventReceiver (const std::string &name, const utils::Timeval &timeout)
Protected Member Functions inherited from core::DescriptorEventReceiver
bool enable (int fd)
void disable ()
void suspend ()
void resume ()
 DescriptorEventReceiver (const std::string &name, DescriptorEventPublisher &descriptorEventPublisher, const utils::Timeval &timeout=TIMEOUT::DISABLE)
int getRegisteredFd () const
bool isEnabled () const
bool isSuspended () const
void setTimeout (const utils::Timeval &timeout)
utils::Timeval getTimeout (const utils::Timeval &currentTime) const
void checkTimeout (const utils::Timeval &currentTime)
Protected Member Functions inherited from core::Observer
void observed ()
void unObserved ()
 Observer ()=default
 Observer (Observer &)=delete
 Observer (Observer &&)=delete
virtual ~Observer ()
Protected Member Functions inherited from core::EventReceiver
virtual ~EventReceiver ()=default
 EventReceiver (const std::string &name)
 EventReceiver (EventReceiver &)=delete
 EventReceiver (EventReceiver &&)=delete
EventReceiveroperator= (EventReceiver &)=delete
EventReceiveroperator= (EventReceiver &&)=delete
virtual void destruct ()
void span ()
void relax ()
const std::string & getName () const
Protected Member Functions inherited from core::socket::stream::SocketWriter
 SocketWriter (const std::string &instanceName, const std::function< void(int)> &onStatus, const utils::Timeval &timeout, std::size_t blockSize, const utils::Timeval &terminateTimeout)
std::size_t getTotalSent () const
std::size_t getTotalQueued () const
void setBlockSize (std::size_t writeBlockSize)
void sendToPeer (const char *chunk, std::size_t chunkLen)
bool streamToPeer (core::pipe::Source *source)
void streamEof ()
void shutdownWrite (const std::function< void()> &onShutdown)
 SocketWriter ()=delete
Protected Member Functions inherited from core::eventreceiver::WriteEventReceiver
 WriteEventReceiver (const std::string &name, const utils::Timeval &timeout)
Static Protected Member Functions inherited from core::EventReceiver
static void atNextTick (const std::function< void(void)> &callBack)
Protected Attributes inherited from core::socket::stream::SocketConnection
core::socket::stream::SocketContextsocketContext = nullptr
core::socket::stream::SocketContextnewSocketContext = nullptr
std::string instanceName
std::string connectionName
std::chrono::time_point< std::chrono::system_clock > onlineSinceTimePoint
Protected Attributes inherited from core::socket::stream::tls::SocketReader
SSL * ssl = nullptr
Protected Attributes inherited from core::socket::stream::SocketReader
utils::Timeval terminateTimeout
Protected Attributes inherited from core::socket::stream::tls::SocketWriter
SSL * ssl = nullptr
Protected Attributes inherited from core::socket::stream::SocketWriter
bool markShutdown = false
std::function< void()> onShutdown
std::vector< char > writePuffer
bool shutdownInProgress = false
utils::Timeval terminateTimeout

Detailed Description

template<typename PhysicalSocketT, typename ConfigT>
class core::socket::stream::tls::SocketConnection< PhysicalSocketT, ConfigT >

Definition at line 60 of file SocketConnection.h.

Member Typedef Documentation

◆ Config

template<typename PhysicalSocketT, typename ConfigT>
using core::socket::stream::tls::SocketConnection< PhysicalSocketT, ConfigT >::Config = ConfigT
private

Definition at line 69 of file SocketConnection.h.

◆ PhysicalSocket

template<typename PhysicalSocketT, typename ConfigT>
using core::socket::stream::tls::SocketConnection< PhysicalSocketT, ConfigT >::PhysicalSocket = PhysicalSocketT
private

Definition at line 70 of file SocketConnection.h.

◆ SocketAddress

template<typename PhysicalSocketT, typename ConfigT>
using core::socket::stream::tls::SocketConnection< PhysicalSocketT, ConfigT >::SocketAddress = typename Super::SocketAddress

Definition at line 75 of file SocketConnection.h.

◆ SocketReader

template<typename PhysicalSocketT, typename ConfigT>
using core::socket::stream::tls::SocketConnection< PhysicalSocketT, ConfigT >::SocketReader = typename Super::SocketReader
private

Definition at line 71 of file SocketConnection.h.

◆ SocketWriter

template<typename PhysicalSocketT, typename ConfigT>
using core::socket::stream::tls::SocketConnection< PhysicalSocketT, ConfigT >::SocketWriter = typename Super::SocketWriter
private

Definition at line 72 of file SocketConnection.h.

◆ Super

template<typename PhysicalSocketT, typename ConfigT>
using core::socket::stream::tls::SocketConnection< PhysicalSocketT, ConfigT >::Super
private
Initial value:
core::socket::stream::
SocketConnectionT<PhysicalSocketT, core::socket::stream::tls::SocketReader, core::socket::stream::tls::SocketWriter, ConfigT>

Definition at line 66 of file SocketConnection.h.

Constructor & Destructor Documentation

◆ SocketConnection()

template<typename PhysicalSocket, typename Config>
core::socket::stream::tls::SocketConnection< PhysicalSocket, Config >::SocketConnection ( PhysicalSocket && physicalSocket,
const std::function< void(SocketConnection< PhysicalSocketT, ConfigT > *)> & onDisconnect,
const std::shared_ptr< Config > & config )

Definition at line 61 of file SocketConnection.hpp.

64 : Super(
66 [onDisconnect, this]() {
67 onDisconnect(this);
68 },
69 config)
70 , sslInitTimeout(config->getInitTimeout())
71 , sslShutdownTimeout(config->getShutdownTimeout())
72 , closeNotifyIsEOF(!config->getNoCloseNotifyIsEOF()) {
73 }
const net::config::ConfigInstance * config
core::socket::stream:: SocketConnectionT< PhysicalSocketT, core::socket::stream::tls::SocketReader, core::socket::stream::tls::SocketWriter, ConfigT > Super

Member Function Documentation

◆ doSSLHandshake()

template<typename PhysicalSocket, typename Config>
bool core::socket::stream::tls::SocketConnection< PhysicalSocket, Config >::doSSLHandshake ( const std::function< void()> & onSuccess,
const std::function< void()> & onTimeout,
const std::function< void(int)> & onStatus )
finalprivatevirtual

Implements core::socket::stream::tls::SocketReader.

Definition at line 113 of file SocketConnection.hpp.

115 {
116 if (ssl != nullptr) {
119 }
122 }
123
126 ssl,
127 [onSuccess, this]() { // onSuccess
129 onSuccess();
130 },
131 [onTimeout]() { // onTimeout
132 onTimeout();
133 },
134 [onStatus](int sslErr) { // onStatus
136 },
138 }
139
140 return ssl != nullptr;
141 }
std::function< void(int)> onStatus
static void doHandshake(const std::string &instanceName, SSL *ssl, const std::function< void(void)> &onSuccess, const std::function< void(void)> &onTimeout, const std::function< void(int)> &onStatus, const utils::Timeval &timeout)

References core::socket::stream::tls::TLSHandshake::doHandshake(), ssl, and sslInitTimeout.

Here is the call graph for this function:

◆ doSSLShutdown()

template<typename PhysicalSocket, typename Config>
void core::socket::stream::tls::SocketConnection< PhysicalSocket, Config >::doSSLShutdown ( )
private

Definition at line 144 of file SocketConnection.hpp.

144 {
145 bool resumeSocketReader = false;
146 bool resumeSocketWriter = false;
147
150 resumeSocketReader = true;
151 }
152
155 resumeSocketWriter = true;
156 }
157
160 ssl,
161 [this, resumeSocketReader, resumeSocketWriter]() { // onSuccess
162 if (resumeSocketReader) {
164 }
165 if (resumeSocketWriter) {
167 }
169 LOG(DEBUG) << Super::getConnectionName() << " SSL/TLS: Passive close_notify received and sent";
170 } else {
171 LOG(DEBUG) << Super::getConnectionName() << " SSL/TLS: Active close_notify sent";
172 }
173 },
174 [this, resumeSocketReader, resumeSocketWriter]() { // onTimeout
175 if (resumeSocketReader) {
177 }
178 if (resumeSocketWriter) {
180 }
181 LOG(ERROR) << Super::getConnectionName() << " SSL/TLS: Shutdown handshake timed out";
182 Super::doWriteShutdown([this]() {
184 });
185 },
186 [this, resumeSocketReader, resumeSocketWriter](int sslErr) { // onStatus
187 if (resumeSocketReader) {
189 }
190 if (resumeSocketWriter) {
192 }
193 ssl_log(Super::getConnectionName() + " SSL/TLS: Shutdown handshake failed", sslErr);
194 Super::doWriteShutdown([this]() {
196 });
197 },
199 }
static void doShutdown(const std::string &instanceName, SSL *ssl, const std::function< void(void)> &onSuccess, const std::function< void(void)> &onTimeout, const std::function< void(int)> &onStatus, const utils::Timeval &timeout)
void ssl_log(const std::string &message, int sslErr)

References core::socket::stream::tls::TLSShutdown::doShutdown(), ssl, and sslShutdownTimeout.

Referenced by doWriteShutdown(), and onReadShutdown().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ doWriteShutdown()

template<typename PhysicalSocket, typename Config>
void core::socket::stream::tls::SocketConnection< PhysicalSocket, Config >::doWriteShutdown ( const std::function< void()> & onShutdown)
finalprivatevirtual

Implements core::socket::stream::SocketWriter.

Definition at line 225 of file SocketConnection.hpp.

225 {
226 if ((SSL_get_shutdown(ssl) & SSL_SENT_SHUTDOWN) == 0) {
227 LOG(DEBUG) << Super::getConnectionName() << " SSL/TLS: Active send close_notify";
228
230 } else {
232 }
233 }
std::function< void()> onShutdown

References doSSLShutdown(), and ssl.

Here is the call graph for this function:

◆ getSSL()

template<typename PhysicalSocket, typename Config>
SSL * core::socket::stream::tls::SocketConnection< PhysicalSocket, Config >::getSSL ( ) const

Definition at line 76 of file SocketConnection.hpp.

76 {
77 return ssl;
78 }

References ssl.

Referenced by tls::getClient().

Here is the caller graph for this function:

◆ onReadShutdown()

template<typename PhysicalSocket, typename Config>
void core::socket::stream::tls::SocketConnection< PhysicalSocket, Config >::onReadShutdown ( )
finalprivatevirtual

Implements core::socket::stream::tls::SocketReader.

Definition at line 202 of file SocketConnection.hpp.

202 {
204 if ((SSL_get_shutdown(ssl) & SSL_SENT_SHUTDOWN) != 0) {
205 LOG(DEBUG) << Super::getConnectionName() << " SSL/TLS: Active close_notify sent and received";
207
208 if (closeNotifyIsEOF) {
209 this->onReadError(0);
210 }
211 } else {
212 LOG(DEBUG) << Super::getConnectionName() << " SSL/TLS: Passive close_notify received, answering with close_notify";
213
215 }
216 } else {
217 LOG(ERROR) << Super::getConnectionName() << " SSL/TLS: Unexpected EOF error";
218
221 }
222 }

References closeNotifyIsEOF, doSSLShutdown(), and ssl.

Here is the call graph for this function:

◆ startSSL()

template<typename PhysicalSocket, typename Config>
SSL * core::socket::stream::tls::SocketConnection< PhysicalSocket, Config >::startSSL ( int fd,
SSL_CTX * ctx )
private

Definition at line 81 of file SocketConnection.hpp.

81 {
82 if (ctx != nullptr) {
83 ssl = SSL_new(ctx);
84
85 if (ssl != nullptr) {
87
88 if (SSL_set_fd(ssl, fd) == 1) {
91 } else {
93 ssl = nullptr;
94 }
95 }
96 }
97
98 return ssl;
99 }

References ssl.

◆ stopSSL()

template<typename PhysicalSocket, typename Config>
void core::socket::stream::tls::SocketConnection< PhysicalSocket, Config >::stopSSL ( )
private

Definition at line 102 of file SocketConnection.hpp.

102 {
103 if (ssl != nullptr) {
104 SSL_free(ssl);
105
106 ssl = nullptr;
107 SocketReader::ssl = nullptr;
108 SocketWriter::ssl = nullptr;
109 }
110 }

References ssl.

◆ SocketAcceptor

template<typename PhysicalSocketT, typename ConfigT>
template<typename PhysicalSocket, typename Config>
friend class SocketAcceptor
friend

Definition at line 105 of file SocketConnection.h.

◆ SocketConnector

template<typename PhysicalSocketT, typename ConfigT>
template<typename PhysicalSocket, typename Config>
friend class SocketConnector
friend

Definition at line 108 of file SocketConnection.h.

Member Data Documentation

◆ closeNotifyIsEOF

template<typename PhysicalSocketT, typename ConfigT>
bool core::socket::stream::tls::SocketConnection< PhysicalSocketT, ConfigT >::closeNotifyIsEOF
private

Definition at line 102 of file SocketConnection.h.

Referenced by onReadShutdown().

◆ ssl

template<typename PhysicalSocketT, typename ConfigT>
SSL* core::socket::stream::tls::SocketConnection< PhysicalSocketT, ConfigT >::ssl = nullptr
private

◆ sslInitTimeout

template<typename PhysicalSocketT, typename ConfigT>
utils::Timeval core::socket::stream::tls::SocketConnection< PhysicalSocketT, ConfigT >::sslInitTimeout
private

Definition at line 100 of file SocketConnection.h.

Referenced by doSSLHandshake().

◆ sslShutdownTimeout

template<typename PhysicalSocketT, typename ConfigT>
utils::Timeval core::socket::stream::tls::SocketConnection< PhysicalSocketT, ConfigT >::sslShutdownTimeout
private

Definition at line 101 of file SocketConnection.h.

Referenced by doSSLShutdown().


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