ClickHouse/src/Server/TCPHandlerFactory.h

58 lines
1.8 KiB
C++
Raw Normal View History

2017-08-09 14:33:07 +00:00
#pragma once
2020-04-15 03:56:42 +00:00
#include <Poco/Net/NetException.h>
2021-10-02 07:13:14 +00:00
#include <base/logger_useful.h>
#include <Server/IServer.h>
#include <Server/TCPHandler.h>
#include <Server/TCPServerConnectionFactory.h>
2017-08-09 14:33:07 +00:00
2017-09-01 19:04:46 +00:00
namespace Poco { class Logger; }
2017-08-09 14:33:07 +00:00
namespace DB
{
class TCPHandlerFactory : public TCPServerConnectionFactory
2017-08-09 14:33:07 +00:00
{
private:
IServer & server;
2020-12-02 21:05:51 +00:00
bool parse_proxy_protocol = false;
2017-09-01 19:04:46 +00:00
Poco::Logger * log;
2021-01-31 07:41:24 +00:00
std::string server_display_name;
2017-08-09 14:33:07 +00:00
2020-04-15 03:56:42 +00:00
class DummyTCPHandler : public Poco::Net::TCPServerConnection
{
public:
using Poco::Net::TCPServerConnection::TCPServerConnection;
void run() override {}
};
2017-08-09 14:33:07 +00:00
public:
2020-12-02 21:05:51 +00:00
/** parse_proxy_protocol_ - if true, expect and parse the header of PROXY protocol in every connection
* and set the information about forwarded address accordingly.
* See https://github.com/wolfeidau/proxyv2/blob/master/docs/proxy-protocol.txt
*/
TCPHandlerFactory(IServer & server_, bool secure_, bool parse_proxy_protocol_)
2020-12-02 21:05:51 +00:00
: server(server_), parse_proxy_protocol(parse_proxy_protocol_)
2020-05-30 21:57:37 +00:00
, log(&Poco::Logger::get(std::string("TCP") + (secure_ ? "S" : "") + "HandlerFactory"))
2017-08-09 14:33:07 +00:00
{
2021-01-31 07:41:24 +00:00
server_display_name = server.config().getString("display_name", getFQDNOrHostName());
2017-08-09 14:33:07 +00:00
}
Poco::Net::TCPServerConnection * createConnection(const Poco::Net::StreamSocket & socket, TCPServer & tcp_server) override
2017-08-09 14:33:07 +00:00
{
2020-04-15 03:56:42 +00:00
try
{
2020-05-23 22:24:01 +00:00
LOG_TRACE(log, "TCP Request. Address: {}", socket.peerAddress().toString());
2020-10-30 14:16:47 +00:00
return new TCPHandler(server, tcp_server, socket, parse_proxy_protocol, server_display_name);
2020-04-15 03:56:42 +00:00
}
catch (const Poco::Net::NetException &)
2020-04-15 03:56:42 +00:00
{
2020-05-23 22:24:01 +00:00
LOG_TRACE(log, "TCP Request. Client is not connected (most likely RST packet was sent).");
2020-04-15 03:56:42 +00:00
return new DummyTCPHandler(socket);
}
2017-08-09 14:33:07 +00:00
}
};
}