SNode.C
Loading...
Searching...
No Matches
ConfigTlsClient.h
Go to the documentation of this file.
1/*
2 * SNode.C - A Slim Toolkit for Network Communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025, 2026
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20/*
21 * MIT License
22 *
23 * Permission is hereby granted, free of charge, to any person obtaining a copy
24 * of this software and associated documentation files (the "Software"), to deal
25 * in the Software without restriction, including without limitation the rights
26 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27 * copies of the Software, and to permit persons to whom the Software is
28 * furnished to do so, subject to the following conditions:
29 *
30 * The above copyright notice and this permission notice shall be included in
31 * all copies or substantial portions of the Software.
32 *
33 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
39 * THE SOFTWARE.
40 */
41
42#ifndef NET_CONFIG_CONFIGTLSCLIENT_H
43#define NET_CONFIG_CONFIGTLSCLIENT_H
44
45#include "net/config/ConfigTls.h" // IWYU pragma: export
46
47// IWYU pragma: no_include "net/config/ConfigTls.hpp"
48
49namespace net::config {
50 class ConfigInstance;
51}
52
53#ifndef DOXYGEN_SHOULD_SKIP_THIS
54
55#include <string>
56
57#endif // DOXYGEN_SHOULD_SKIP_THIS
58
59namespace net::config {
60
61 class ConfigTlsClient : public ConfigTls {
62 private:
64
65 protected:
66 explicit ConfigTlsClient(ConfigInstance* instance);
67
68 ~ConfigTlsClient() override;
69
70 public:
71 ConfigTlsClient& setSni(const std::string& sni);
72 std::string getSni() const;
73
74 private:
75 CLI::Option* sniOpt = nullptr;
76 };
77
78} // namespace net::config
79
80#endif // NET_CONFIG_CONFIGTLSCLIENT_H
core::socket::stream::SocketContext * create(core::socket::stream::SocketConnection *socketConnection) override
web::http::client::ResponseParser * responseParser
SimpleSocketProtocol(core::socket::stream::SocketConnection *socketConnection)
void onReadError(int errnum) override
void onWriteError(int errnum) override
std::size_t onReceivedFromPeer() override
static void atNextTick(const std::function< void(void)> &callBack)
static void init(int argc, char *argv[])
Definition SNodeC.cpp:54
static State state()
Definition SNodeC.cpp:76
static int start(const utils::Timeval &timeOut={LONG_MAX, 0})
Definition SNodeC.cpp:60
ConnectEventReceiver(const std::string &name, const utils::Timeval &timeout)
Config & getConfig() const
Definition Socket.hpp:65
State & operator&=(int state)
Definition State.cpp:90
static constexpr int DISABLED
Definition State.h:56
bool operator==(const int &state) const
Definition State.cpp:74
State operator&(int state)
Definition State.cpp:106
static constexpr int ERROR
Definition State.h:57
std::string what() const
Definition State.cpp:114
static constexpr int FATAL
Definition State.h:58
static constexpr int OK
Definition State.h:55
static constexpr int NO_RETRY
Definition State.h:59
SocketClient(const std::string &name, const std::function< void(SocketConnection *)> &onConnect, const std::function< void(SocketConnection *)> &onConnected, const std::function< void(SocketConnection *)> &onDisconnect, Args &&... args)
const SocketClient & connect(const SocketAddress &remoteAddress, const SocketAddress &localAddress, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
SocketClient(const std::shared_ptr< Config > &config, const std::shared_ptr< SocketContextFactory > &socketContextFactory, const std::function< void(SocketConnection *)> &onConnect, const std::function< void(SocketConnection *)> &onConnected, const std::function< void(SocketConnection *)> &onDisconnect)
std::function< void(SocketConnection *)> & getOnDisconnect() const
SocketClient(const std::string &name, Args &&... args)
SocketContextFactoryT SocketContextFactory
std::function< void(const std::shared_ptr< AutoConnectControl > &)> & getOnAutoConnectControl()
const SocketClient & setOnInitState(const std::function< void(core::eventreceiver::ConnectEventReceiver *)> &onInitState, bool initialize=false) const
const SocketClient & connect(const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
typename SocketConnector::SocketAddress SocketAddress
const SocketClient & setOnConnect(const std::function< void(SocketConnection *)> &onConnect, bool initialize=false) const
std::function< void(SocketConnection *)> & getOnConnected() const
const SocketClient & realConnect(const std::function< void(const SocketAddress &, core::socket::State)> &onStatus, unsigned int tries, double retryTimeoutScale) const
typename SocketConnector::SocketConnection SocketConnection
std::shared_ptr< SocketContextFactory > getSocketContextFactory() const
SocketClient(const std::function< void(SocketConnection *)> &onConnect, const std::function< void(SocketConnection *)> &onConnected, const std::function< void(SocketConnection *)> &onDisconnect, Args &&... args)
typename SocketConnector::Config Config
const SocketClient & setOnDisconnect(const std::function< void(SocketConnection *)> &onDisconnect, bool initialize=false) const
const SocketClient & setOnAutoConnectControl(const std::function< void(const std::shared_ptr< AutoConnectControl > &)> &onAutoConnectControl, bool initialize=false) const
core::socket::Socket< typename SocketConnector::Config > Super
std::function< void(core::eventreceiver::ConnectEventReceiver *)> & getOnInitState() const
SocketClient(const std::shared_ptr< Config > &config, const std::shared_ptr< Context > &sharedContext)
std::function< void(SocketConnection *)> & getOnConnect()
const SocketClient & connect(const SocketAddress &remoteAddress, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
std::shared_ptr< Context > sharedContext
const SocketClient & setOnConnected(const std::function< void(SocketConnection *)> &onConnected, bool initialize=false) const
const SocketAddress & getRemoteAddress() const final
const SocketAddress & getLocalAddress() const final
void sendToPeer(const std::string &data)
SocketConnector(const std::function< void(SocketConnection *)> &onConnect, const std::function< void(SocketConnection *)> &onConnected, const std::function< void(SocketConnection *)> &onDisconnect, const std::function< void(core::eventreceiver::ConnectEventReceiver *)> &onInitState, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus, const std::shared_ptr< Config > &config)
typename PhysicalClientSocket::SocketAddress SocketAddress
SocketConnector(const SocketConnector &socketConnector)
std::function< void(const SocketAddress &, core::socket::State)> onStatus
SocketConnectionT< PhysicalClientSocket, Config > SocketConnection
std::function< void(SocketConnection *)> onConnected
std::function< void(SocketConnection *)> onDisconnect
PhysicalSocketClientT PhysicalClientSocket
std::function< void(core::eventreceiver::ConnectEventReceiver *)> onInitState
std::function< void(SocketConnection *)> onConnect
SocketContext(core::socket::stream::SocketConnection *socketConnection)
void onReadError(int errnum) override
void onWriteError(int errnum) override
typename Super::SocketAddress SocketAddress
SocketConnector(const std::shared_ptr< core::socket::stream::SocketContextFactory > &socketContextFactory, const std::function< void(SocketConnection *)> &onConnect, const std::function< void(SocketConnection *)> &onConnected, const std::function< void(SocketConnection *)> &onDisconnect, const std::function< void(core::eventreceiver::ConnectEventReceiver *)> &onInitState, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus, const std::shared_ptr< Config > &config)
core::socket::stream::SocketConnector< PhysicalClientSocketT, ConfigT, core::socket::stream::legacy::SocketConnection > Super
SocketConnector(const SocketConnector &socketConnector)
typename Super::SocketConnection SocketConnection
SocketConnection(PhysicalSocket &&physicalSocket, const std::function< void(SocketConnection *)> &onDisconnect, const std::shared_ptr< Config > &config)
typename Super::SocketReader SocketReader
core::socket::stream:: SocketConnectionT< PhysicalSocketT, core::socket::stream::tls::SocketReader, core::socket::stream::tls::SocketWriter, ConfigT > Super
typename Super::SocketAddress SocketAddress
void doWriteShutdown(const std::function< void()> &onShutdown) final
bool doSSLHandshake(const std::function< void()> &onSuccess, const std::function< void()> &onTimeout, const std::function< void(int)> &onStatus) final
typename Super::SocketWriter SocketWriter
core::socket::stream::SocketConnector< PhysicalSocketClientT, ConfigT, core::socket::stream::tls::SocketConnection > Super
typename Super::SocketAddress SocketAddress
SocketConnector(const SocketConnector &socketConnector)
typename Super::SocketConnection SocketConnection
SocketConnector(const std::shared_ptr< core::socket::stream::SocketContextFactory > &socketContextFactory, const std::function< void(SocketConnection *)> &onConnect, const std::function< void(SocketConnection *)> &onConnected, const std::function< void(SocketConnection *)> &onDisconnect, const std::function< void(core::eventreceiver::ConnectEventReceiver *)> &onInitState, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus, const std::shared_ptr< Config > &config)
virtual bool doSSLHandshake(const std::function< void()> &onSuccess, const std::function< void()> &onTimeout, const std::function< void(int)> &onStatus)=0
ssize_t read(char *chunk, std::size_t chunkLen) override
core::socket::stream::SocketReader Super
core::socket::stream::SocketWriter Super
virtual bool doSSLHandshake(const std::function< void()> &onSuccess, const std::function< void()> &onTimeout, const std::function< void(int)> &onStatus)=0
ssize_t write(const char *chunk, std::size_t chunkLen) override
const std::string & getInstanceName() const
ConfigPhysicalSocketClient & setReconnectTime(double time)
ConfigPhysicalSocketClient & setReconnect(bool reconnect=true)
ConfigPhysicalSocketClient & setConnectTimeout(const utils::Timeval &connectTimeout)
ConfigTlsClient & setSni(const std::string &sni)
ConfigTlsClient(ConfigInstance *instance)
ConfigAddressLocalT< net::config::ConfigAddressLocal > Local
ConfigAddressRemoteT< net::config::ConfigAddressRemote > Remote
ConfigSocketClient(net::config::ConfigInstance *instance)
net::config::ConfigPhysicalSocketClient Socket
net::config::ConfigConnection Connection
SocketAddress(const std::string &ipOrHostname, uint16_t port)
std::string getCanonName() const
std::string toString(bool expanded=true) const override
void init(const Hints &hints={.aiFlags=0,.aiSockType=0,.aiProtocol=0})
PhysicalSocketClient(PhysicalSocketClient &&) noexcept=default
net::in::phy::stream::PhysicalSocket< net::phy::stream::PhysicalSocketClient > Super
const Super & connect(const std::string &ipOrHostname, uint16_t port, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
core::socket::stream:: SocketClient< SocketConnectorT< net::in::phy::stream::PhysicalSocketClient, ConfigSocketClientT >, SocketContextFactoryT, Args... > Super
const Super & connect(const std::string &ipOrHostname, uint16_t port, const std::string &bindHost, uint16_t bindPort, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
const Super & connect(const std::string &ipOrHostname, uint16_t port, const std::string &bindHost, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
const Super & connect(const std::string &ipOrHostname, uint16_t port, uint16_t bindPort, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
ConfigSocketClient & setDisableNagleAlgorithm(bool disableNagleAlgorithm=true)
ConfigSocketClient(net::config::ConfigInstance *instance)
int connect(SocketAddress &remoteAddress)
net::phy::stream::PhysicalSocket< SocketAddressT > Super
static double getInRange(double ll, double ul)
Definition Random.cpp:52
std::size_t parse()
Definition Parser.cpp:125
ResponseParser(core::socket::stream::SocketContext *socketContext, const std::function< void()> &onResponseStart, const std::function< void(Response &)> &onResponseParsed, const std::function< void(int, const std::string &)> &onResponseParseError)
int main(int argc, char *argv[])
static web::http::client::ResponseParser * getResponseParser(core::socket::stream::SocketContext *socketContext)
SocketClient Client(const std::string &instanceName, Args &&... socketContextFactoryArgs)
SocketClient Client(const std::string &instanceName, const std::function< void(typename SocketClient::Config &)> &configurator, Args &&... socketContextFactoryArgs)
State
Definition State.h:51
@ RUNNING
Definition State.h:51
@ INITIALIZED
Definition State.h:51
State eventLoopState()
Definition State.cpp:52
net::in::stream::legacy::SocketClient< apps::http::SimpleSocketProtocolFactory > SocketClient
SocketClient::SocketAddress SocketAddress
SocketClient::SocketConnection SocketConnection
SocketClient getLegacyClient()
SocketClient< SocketContextFactory, SocketContextFactoryArgs... > Client(const std::string &instanceName, SocketContextFactoryArgs &&... socketContextFactoryArgs)
net::in::stream::SocketClient< core::socket::stream::legacy::SocketConnector, net::in::stream::legacy::config::ConfigSocketClient, SocketContextFactoryT, Args... > SocketClient
SocketClient< SocketContextFactory, SocketContextFactoryArgs... > Client(const std::string &instanceName, const std::function< void(net::in::stream::legacy::config::ConfigSocketClient &)> &configurator, SocketContextFactoryArgs &&... socketContextFactoryArgs)
net::in::stream::SocketClient< core::socket::stream::tls::SocketConnector, net::in::stream::tls::config::ConfigSocketClient, SocketContextFactoryT, Args... > SocketClient
SocketClient< SocketContextFactory, SocketContextFactoryArgs... > Client(const std::string &instanceName, const std::function< void(net::in::stream::tls::config::ConfigSocketClient &)> &configurator, SocketContextFactoryArgs &&... socketContextFactoryArgs)
SocketClient< SocketContextFactory, SocketContextFactoryArgs... > Client(const std::string &instanceName, SocketContextFactoryArgs &&... socketContextFactoryArgs)
net::in::stream::tls::SocketClient< apps::http::SimpleSocketProtocolFactory > SocketClient
SocketClient getClient()
SocketClient::SocketConnection SocketConnection
SocketClient::SocketAddress SocketAddress
std::function< void(SocketConnection *)> onConnect
std::shared_ptr< SocketContextFactory > socketContextFactory
std::function< void(const std::shared_ptr< AutoConnectControl > &)> onAutoConnectControl
std::function< void(core::eventreceiver::ConnectEventReceiver *)> onInitState
std::shared_ptr< AutoConnectControl > autoConnectControl
std::function< void(SocketConnection *)> onConnected
std::function< void(SocketConnection *)> onDisconnect
Context(const std::shared_ptr< SocketContextFactory > &socketContextFactory, const std::function< void(SocketConnection *)> &onConnect, const std::function< void(SocketConnection *)> &onConnected, const std::function< void(SocketConnection *)> &onDisconnect)