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

#include <SocketConnection.h>

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

Public Types

using SocketAddress = typename Super::SocketAddress
 

Public Member Functions

 SocketConnection (const std::string &instanceName, PhysicalSocket &&physicalSocket, const std::function< void(SocketConnection *)> &onDisconnect, const std::string &configuredServer, const SocketAddress &localAddress, const SocketAddress &remoteAddress, const utils::Timeval &readTimeout, const utils::Timeval &writeTimeout, std::size_t readBlockSize, std::size_t writeBlockSize, const utils::Timeval &terminateTimeout)
 
SSL * getSSL () const
 

Private Types

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

Private Member Functions

SSL * startSSL (int fd, SSL_CTX *ctx, const utils::Timeval &sslInitTimeout, const utils::Timeval &sslShutdownTimeout, bool closeNotifyIsEOF)
 
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
 

Friends

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

Detailed Description

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

Definition at line 27 of file SocketAcceptor.h.

Member Typedef Documentation

◆ PhysicalSocket

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

Definition at line 48 of file SocketConnection.h.

◆ SocketAddress

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

Definition at line 53 of file SocketConnection.h.

◆ SocketReader

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

Definition at line 49 of file SocketConnection.h.

◆ SocketWriter

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

Definition at line 50 of file SocketConnection.h.

◆ Super

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

Definition at line 45 of file SocketConnection.h.

Constructor & Destructor Documentation

◆ SocketConnection()

template<typename PhysicalSocket >
core::socket::stream::tls::SocketConnection< PhysicalSocket >::SocketConnection ( const std::string & instanceName,
PhysicalSocket && physicalSocket,
const std::function< void(SocketConnection< PhysicalSocketT > *)> & onDisconnect,
const std::string & configuredServer,
const SocketAddress & localAddress,
const SocketAddress & remoteAddress,
const utils::Timeval & readTimeout,
const utils::Timeval & writeTimeout,
std::size_t readBlockSize,
std::size_t writeBlockSize,
const utils::Timeval & terminateTimeout )

Definition at line 39 of file SocketConnection.hpp.

50 : Super(
51 instanceName,
52 std::move(physicalSocket),
53 [onDisconnect, this]() {
54 onDisconnect(this);
55 },
56 configuredServer,
57 localAddress,
58 remoteAddress,
59 readTimeout,
60 writeTimeout,
61 readBlockSize,
62 writeBlockSize,
63 terminateTimeout) {
64 }
core::socket::stream:: SocketConnectionT< PhysicalSocketT, core::socket::stream::tls::SocketReader, core::socket::stream::tls::SocketWriter > Super

References core::socket::stream::tls::SocketConnection< PhysicalSocketT >::SocketConnection().

Referenced by core::socket::stream::tls::SocketConnection< PhysicalSocketT >::SocketConnection().

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

Member Function Documentation

◆ doSSLHandshake()

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

Definition at line 109 of file SocketConnection.hpp.

111 {
112 if (ssl != nullptr) {
115 }
118 }
119
121 Super::getConnectionName(),
122 ssl,
123 [onSuccess, this]() { // onSuccess
125 onSuccess();
126 },
127 [onTimeout]() { // onTimeout
128 onTimeout();
129 },
130 [onStatus](int sslErr) { // onStatus
131 onStatus(sslErr);
132 },
134 }
135
136 return ssl != nullptr;
137 }
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::SocketConnection< PhysicalSocketT >::ssl.

◆ doSSLShutdown()

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

Definition at line 140 of file SocketConnection.hpp.

140 {
141 bool resumeSocketReader = false;
142 bool resumeSocketWriter = false;
143
146 resumeSocketReader = true;
147 }
148
151 resumeSocketWriter = true;
152 }
153
155 Super::getConnectionName(),
156 ssl,
157 [this, resumeSocketReader, resumeSocketWriter]() { // onSuccess
158 if (resumeSocketReader) {
160 }
161 if (resumeSocketWriter) {
163 }
164 if (SSL_get_shutdown(ssl) == (SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN)) {
165 LOG(DEBUG) << Super::getConnectionName() << " SSL/TLS: Close_notify received and sent";
166 } else {
167 LOG(DEBUG) << Super::getConnectionName() << " SSL/TLS: Close_notify sent";
168
169 if (SSL_get_shutdown(ssl) == SSL_SENT_SHUTDOWN && SocketWriter::closeNotifyIsEOF) {
170 LOG(TRACE) << Super::getConnectionName() << " SSL/TLS: Close_notify is EOF: setting sslShutdownTimeout to "
171 << sslShutdownTimeout << " sec";
172 Super::setTimeout(sslShutdownTimeout);
173 }
174 }
175 },
176 [this, resumeSocketReader, resumeSocketWriter]() { // onTimeout
177 if (resumeSocketReader) {
179 }
180 if (resumeSocketWriter) {
182 }
183 LOG(ERROR) << Super::getConnectionName() << " SSL/TLS: Shutdown handshake timed out";
184 Super::doWriteShutdown([this]() {
186 });
187 },
188 [this, resumeSocketReader, resumeSocketWriter](int sslErr) { // onStatus
189 if (resumeSocketReader) {
191 }
192 if (resumeSocketWriter) {
194 }
195 ssl_log(Super::getConnectionName() + " SSL/TLS: Shutdown handshake failed", sslErr);
196 Super::doWriteShutdown([this]() {
198 });
199 },
201 }
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)

Referenced by core::socket::stream::tls::SocketConnection< PhysicalSocketT >::doWriteShutdown(), and core::socket::stream::tls::SocketConnection< PhysicalSocketT >::onReadShutdown().

Here is the caller graph for this function:

◆ doWriteShutdown()

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

Definition at line 224 of file SocketConnection.hpp.

224 {
225 if ((SSL_get_shutdown(ssl) & SSL_SENT_SHUTDOWN) == 0) {
226 LOG(DEBUG) << Super::getConnectionName() << " SSL/TLS: Send close_notify";
227
229 } else {
230 Super::doWriteShutdown(onShutdown);
231 }
232 }

References core::socket::stream::tls::SocketConnection< PhysicalSocketT >::doSSLShutdown(), and core::socket::stream::tls::SocketConnection< PhysicalSocketT >::ssl.

Here is the call graph for this function:

◆ getSSL()

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

Definition at line 67 of file SocketConnection.hpp.

67 {
68 return ssl;
69 }

References core::socket::stream::tls::SocketConnection< PhysicalSocketT >::ssl.

◆ onReadShutdown()

template<typename PhysicalSocket >
void core::socket::stream::tls::SocketConnection< PhysicalSocket >::onReadShutdown ( )
finalprivate

Definition at line 204 of file SocketConnection.hpp.

204 {
205 if ((SSL_get_shutdown(ssl) & SSL_RECEIVED_SHUTDOWN) != 0) {
206 if ((SSL_get_shutdown(ssl) & SSL_SENT_SHUTDOWN) != 0) {
207 LOG(DEBUG) << Super::getConnectionName() << " SSL/TLS: Close_notify sent and received";
208
210 } else {
211 LOG(DEBUG) << Super::getConnectionName() << " SSL/TLS: Close_notify received";
212
214 }
215 } else {
216 LOG(ERROR) << Super::getConnectionName() << " SSL/TLS: Unexpected EOF error";
217
219 SSL_set_shutdown(ssl, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);
220 }
221 }

References core::socket::stream::tls::SocketConnection< PhysicalSocketT >::doSSLShutdown(), and core::socket::stream::tls::SocketConnection< PhysicalSocketT >::ssl.

Here is the call graph for this function:

◆ startSSL()

template<typename PhysicalSocket >
SSL * core::socket::stream::tls::SocketConnection< PhysicalSocket >::startSSL ( int fd,
SSL_CTX * ctx,
const utils::Timeval & sslInitTimeout,
const utils::Timeval & sslShutdownTimeout,
bool closeNotifyIsEOF )
private

Definition at line 72 of file SocketConnection.hpp.

73 {
74 this->sslInitTimeout = sslInitTimeout;
75 this->sslShutdownTimeout = sslShutdownTimeout;
76 if (ctx != nullptr) {
77 ssl = SSL_new(ctx);
78
79 if (ssl != nullptr) {
80 SSL_set_ex_data(ssl, 0, const_cast<std::string*>(&Super::getConnectionName()));
81
82 if (SSL_set_fd(ssl, fd) == 1) {
85 SocketReader::closeNotifyIsEOF = closeNotifyIsEOF;
86 SocketWriter::closeNotifyIsEOF = closeNotifyIsEOF;
87 } else {
88 SSL_free(ssl);
89 ssl = nullptr;
90 }
91 }
92 }
93
94 return ssl;
95 }

References core::socket::stream::tls::SocketConnection< PhysicalSocketT >::ssl.

◆ stopSSL()

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

Definition at line 98 of file SocketConnection.hpp.

98 {
99 if (ssl != nullptr) {
100 SSL_free(ssl);
101
102 ssl = nullptr;
103 SocketReader::ssl = nullptr;
104 SocketWriter::ssl = nullptr;
105 }
106 }

References core::socket::stream::tls::SocketConnection< PhysicalSocketT >::ssl.

Friends And Related Symbol Documentation

◆ SocketAcceptor

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

Definition at line 91 of file SocketConnection.h.

◆ SocketConnector

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

Definition at line 94 of file SocketConnection.h.

Member Data Documentation

◆ ssl

◆ sslInitTimeout

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

Definition at line 87 of file SocketConnection.h.

◆ sslShutdownTimeout

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

Definition at line 88 of file SocketConnection.h.


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