22     : local_ip_address_{local_ip_address},
 
   23       local_port_num_{local_port_num},
 
   25       io_ssl_context_{boost::asio::ssl::context::tlsv13_server},
 
   26       tcp_acceptor_{io_context_, 
Tcp::endpoint(
Tcp::v4(), local_port_num_), true} {
 
   28       FILE_NAME, __LINE__, __func__, [&local_ip_address, &local_port_num](std::stringstream &msg) {
 
   29         msg << 
"Tcp Socket Acceptor created at " 
   30             << 
"<" << local_ip_address << 
"," << local_port_num << 
">";
 
   33   io_ssl_context_.use_certificate_chain_file(
"../../../openssl/DiagClientLib.crt");
 
   34   io_ssl_context_.use_private_key_file(
"../../../openssl/DiagClientLib.key",
 
   35                                        boost::asio::ssl::context::pem);
 
   37                            "TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256");
 
   42   std::optional<TcpServerConnection> tcp_connection{std::nullopt};
 
   44   Tcp::endpoint endpoint{};
 
   48   tcp_acceptor_.accept(tls_socket.lowest_layer(), endpoint, ec);
 
   49   if (ec.value() == boost::system::errc::success) {
 
   50     tcp_connection.emplace(std::move(tls_socket), std::move(tcp_handler_read));
 
   52         FILE_NAME, __LINE__, __func__, [&endpoint](std::stringstream &msg) {
 
   53           msg << 
"TLS Socket connection received from client " 
   54               << 
"<" << endpoint.address().to_string() << 
"," << endpoint.port() << 
">";
 
   58         FILE_NAME, __LINE__, __func__, [ec](std::stringstream &msg) {
 
   59           msg << 
"TLS Socket Connect to client failed with error: " << ec.message();
 
   62   return tcp_connection;
 
   66     : tls_socket_{std::move(tls_socket)},
 
   67       tcp_handler_read_{std::move(tcp_handler_read)} {}
 
   79                      boost::asio::buffer(tcp_tx_message->GetPayload().data(),
 
   80                                          std::size_t(tcp_tx_message->GetPayload().size())),
 
   83   if (ec.value() == boost::system::errc::success) {
 
   86         FILE_NAME, __LINE__, __func__, [endpoint_](std::stringstream &msg) {
 
   87           msg << 
"Tcp message sent to " 
   88               << 
"<" << endpoint_.address().to_string() << 
"," << endpoint_.port() << 
">";
 
   90     result.EmplaceValue();
 
   93         FILE_NAME, __LINE__, __func__, [ec](std::stringstream &msg) {
 
   94           msg << 
"Tcp message sending failed with error: " << ec.message();
 
  102   bool connection_closed{
false};
 
  105   tls_socket_.handshake(boost::asio::ssl::stream_base::server, ec);
 
  107   if (ec.value() == boost::system::errc::success) {
 
  115     if (ec.value() == boost::system::errc::success) {
 
  117       std::uint32_t 
const read_next_bytes = [&rx_buffer]() noexcept -> std::uint32_t {
 
  118         return static_cast<std::uint32_t
>(
 
  119             (
static_cast<std::uint32_t
>(rx_buffer[4u] << 24u) & 0xFF000000) |
 
  120             (
static_cast<std::uint32_t
>(rx_buffer[5u] << 16u) & 0x00FF0000) |
 
  121             (
static_cast<std::uint32_t
>(rx_buffer[6u] << 8u) & 0x0000FF00) |
 
  122             (
static_cast<std::uint32_t
>(rx_buffer[7u] & 0x000000FF)));
 
  133           endpoint_.address().to_string(), endpoint_.port(), std::move(rx_buffer))};
 
  135           FILE_NAME, __LINE__, __func__, [endpoint_](std::stringstream &msg) {
 
  136             msg << 
"Tcp Message received from " 
  137                 << 
"<" << endpoint_.address().to_string() << 
"," << endpoint_.port() << 
">";
 
  141     } 
else if (ec.value() == boost::asio::error::eof) {
 
  144           [ec](std::stringstream &msg) { msg << 
"Remote Disconnected with: " << ec.message(); });
 
  145       connection_closed = 
true;
 
  148           FILE_NAME, __LINE__, __func__, [ec](std::stringstream &msg) {
 
  149             msg << 
"Remote Disconnected with undefined error: " << ec.message();
 
  151       connection_closed = 
true;
 
  155         FILE_NAME, __LINE__, __func__, [ec](std::stringstream &msg) {
 
  156           msg << 
"Tls server handshake with host failed with error: " << ec.message();
 
  158     connection_closed = 
true;
 
  160   return connection_closed;
 
  173     if (ec.value() == boost::system::errc::success) {
 
  175       result.EmplaceValue();
 
  178           FILE_NAME, __LINE__, __func__, [ec](std::stringstream &msg) {
 
  179             msg << 
"Tcp Socket Disconnection failed with error: " << ec.message();
 
static auto GetLibBoostLogger() noexcept -> LibBoostLogger &
 
std::vector< std::uint8_t > BufferType
Type alias for underlying buffer.
 
boost::asio::ssl::stream< TcpSocket > TlsStream
Type alias for tls stream wrapping tcp socket.
 
core_type::Result< void, TcpErrorCode > Shutdown()
Function to shutdown the socket.
 
TcpServerConnection(TlsStream tls_socket, TcpHandlerRead tcp_handler_read)
Constructs an instance of TcpServerConnection.
 
std::function< void(message::tcp::TcpMessagePtr)> TcpHandlerRead
Tcp function template used for reception.
 
TlsStream::lowest_layer_type & GetNativeTcpSocket()
Function to get the native tcp socket under tls socket.
 
TcpHandlerRead tcp_handler_read_
Store the handler.
 
core_type::Result< void, TcpErrorCode > Transmit(message::tcp::TcpMessageConstPtr tcp_message)
Function to trigger transmission.
 
TlsStream tls_socket_
Store ssl socket.
 
bool TryReceivingMessage()
Function to initiate reception of tcp message.
 
boost::asio::ssl::context io_ssl_context_
boost io ssl context
 
TcpAcceptor tcp_acceptor_
Store tcp acceptor.
 
boost::asio::ip::tcp Tcp
Type alias for tcp protocol.
 
std::optional< TcpServerConnection > GetTcpServerConnection(TcpHandlerRead tcp_handler_read)
Get the tcp connection to communicate.
 
boost::asio::io_context io_context_
boost io context
 
std::function< void(message::tcp::TcpMessagePtr)> TcpHandlerRead
Tcp function template used for reception.
 
TlsServerSocket(std::string_view local_ip_address, std::uint16_t local_port_num)
Constructs an instance of TlsServerSocket.
 
Class type to contains a value (of type ValueType), or an error (of type ErrorType)
 
std::unique_ptr< TcpMessage > TcpMessagePtr
The unique pointer to TcpMessage.
 
std::unique_ptr< TcpMessage const  > TcpMessageConstPtr
The unique pointer to const TcpMessage.
 
constexpr std::uint8_t kDoipheadrSize
Doip HeaderSize.
 
boost::system::error_code TcpErrorCodeType