1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#pragma once
#include <Poco/Logger.h>
#include <Poco/Net/TCPServerConnection.h>
#include <Poco/Net/NetException.h>
#include <Poco/Util/LayeredConfiguration.h>
#include <Server/TLSHandler.h>
#include <Server/IServer.h>
#include <Server/TCPServer.h>
#include <Server/TCPProtocolStackData.h>
#include <Common/logger_useful.h>
namespace DB
{
class TLSHandlerFactory : public TCPServerConnectionFactory
{
private:
IServer & server;
Poco::Logger * log;
std::string conf_name;
class DummyTCPHandler : public Poco::Net::TCPServerConnection
{
public:
using Poco::Net::TCPServerConnection::TCPServerConnection;
void run() override {}
};
public:
explicit TLSHandlerFactory(IServer & server_, const std::string & conf_name_)
: server(server_), log(&Poco::Logger::get("TLSHandlerFactory")), conf_name(conf_name_)
{
}
Poco::Net::TCPServerConnection * createConnection(const Poco::Net::StreamSocket & socket, TCPServer & tcp_server) override
{
TCPProtocolStackData stack_data;
return createConnection(socket, tcp_server, stack_data);
}
Poco::Net::TCPServerConnection * createConnection(const Poco::Net::StreamSocket & socket, TCPServer &/* tcp_server*/, TCPProtocolStackData & stack_data) override
{
try
{
LOG_TRACE(log, "TCP Request. Address: {}", socket.peerAddress().toString());
return new TLSHandler(
socket,
server.config().getString(conf_name + ".privateKeyFile", ""),
server.config().getString(conf_name + ".certificateFile", ""),
stack_data);
}
catch (const Poco::Net::NetException &)
{
LOG_TRACE(log, "TCP Request. Client is not connected (most likely RST packet was sent).");
return new DummyTCPHandler(socket);
}
}
};
}
|