2020-12-09 08:45:36 +00:00
|
|
|
#pragma once
|
2021-02-01 13:18:17 +00:00
|
|
|
|
2021-03-29 08:24:56 +00:00
|
|
|
#include <Server/KeeperTCPHandler.h>
|
2021-10-22 07:15:34 +00:00
|
|
|
#include <Server/TCPServerConnectionFactory.h>
|
2020-12-09 08:45:36 +00:00
|
|
|
#include <Poco/Net/NetException.h>
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/logger_useful.h>
|
2020-12-09 08:45:36 +00:00
|
|
|
#include <Server/IServer.h>
|
2021-04-12 12:25:52 +00:00
|
|
|
#include <string>
|
2020-12-09 08:45:36 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2022-03-03 20:27:46 +00:00
|
|
|
using ConfigGetter = std::function<const Poco::Util::AbstractConfiguration & ()>;
|
|
|
|
|
2021-10-22 07:15:34 +00:00
|
|
|
class KeeperTCPHandlerFactory : public TCPServerConnectionFactory
|
2020-12-09 08:45:36 +00:00
|
|
|
{
|
|
|
|
private:
|
2022-03-03 20:27:46 +00:00
|
|
|
ConfigGetter config_getter;
|
|
|
|
std::shared_ptr<KeeperDispatcher> keeper_dispatcher;
|
2020-12-09 08:45:36 +00:00
|
|
|
Poco::Logger * log;
|
2022-03-03 20:27:46 +00:00
|
|
|
Poco::Timespan receive_timeout;
|
|
|
|
Poco::Timespan send_timeout;
|
|
|
|
|
2020-12-09 08:45:36 +00:00
|
|
|
class DummyTCPHandler : public Poco::Net::TCPServerConnection
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using Poco::Net::TCPServerConnection::TCPServerConnection;
|
|
|
|
void run() override {}
|
|
|
|
};
|
2021-11-18 20:17:22 +00:00
|
|
|
|
2020-12-09 08:45:36 +00:00
|
|
|
public:
|
2022-03-03 20:27:46 +00:00
|
|
|
KeeperTCPHandlerFactory(
|
|
|
|
ConfigGetter config_getter_,
|
|
|
|
std::shared_ptr<KeeperDispatcher> keeper_dispatcher_,
|
|
|
|
Poco::Timespan receive_timeout_,
|
|
|
|
Poco::Timespan send_timeout_,
|
|
|
|
bool secure)
|
|
|
|
: config_getter(config_getter_)
|
|
|
|
, keeper_dispatcher(keeper_dispatcher_)
|
2021-04-12 12:25:52 +00:00
|
|
|
, log(&Poco::Logger::get(std::string{"KeeperTCP"} + (secure ? "S" : "") + "HandlerFactory"))
|
2022-03-03 20:27:46 +00:00
|
|
|
, receive_timeout(receive_timeout_)
|
|
|
|
, send_timeout(send_timeout_)
|
2020-12-09 08:45:36 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-10-22 07:15:34 +00:00
|
|
|
Poco::Net::TCPServerConnection * createConnection(const Poco::Net::StreamSocket & socket, TCPServer &) override
|
2020-12-09 08:45:36 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-03-29 08:24:56 +00:00
|
|
|
LOG_TRACE(log, "Keeper request. Address: {}", socket.peerAddress().toString());
|
2022-03-03 20:27:46 +00:00
|
|
|
return new KeeperTCPHandler(config_getter(), keeper_dispatcher, receive_timeout, send_timeout, socket);
|
2020-12-09 08:45:36 +00:00
|
|
|
}
|
|
|
|
catch (const Poco::Net::NetException &)
|
|
|
|
{
|
|
|
|
LOG_TRACE(log, "TCP Request. Client is not connected (most likely RST packet was sent).");
|
|
|
|
return new DummyTCPHandler(socket);
|
|
|
|
}
|
|
|
|
}
|
2021-11-18 20:17:22 +00:00
|
|
|
|
2020-12-09 08:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|