2021-03-23 15:01:13 +00:00
|
|
|
#include "StorageMongoDBSocketFactory.h"
|
|
|
|
|
2021-08-02 12:34:50 +00:00
|
|
|
#include <Common/Exception.h>
|
|
|
|
|
2021-05-28 15:25:24 +00:00
|
|
|
#if !defined(ARCADIA_BUILD)
|
2021-08-02 13:11:49 +00:00
|
|
|
# include "config_core.h"
|
2021-05-28 15:25:24 +00:00
|
|
|
# include <Common/config.h>
|
|
|
|
#endif
|
|
|
|
|
2021-03-23 15:01:13 +00:00
|
|
|
#include <Poco/Net/IPAddress.h>
|
|
|
|
#include <Poco/Net/SocketAddress.h>
|
|
|
|
|
2021-05-24 12:11:03 +00:00
|
|
|
#if USE_SSL
|
|
|
|
# include <Poco/Net/SecureStreamSocket.h>
|
|
|
|
#endif
|
2021-03-23 15:01:13 +00:00
|
|
|
|
2021-08-02 13:11:49 +00:00
|
|
|
#ifdef __clang__
|
|
|
|
# pragma clang diagnostic ignored "-Wunused-parameter"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if USE_EMBEDDED_COMPILER
|
|
|
|
# pragma GCC diagnostic ignored "-Wunused-parameter"
|
|
|
|
#endif
|
|
|
|
|
2021-03-23 15:01:13 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-08-02 12:34:50 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int FEATURE_IS_NOT_ENABLED_AT_BUILD_TIME;
|
|
|
|
}
|
|
|
|
|
2021-03-23 15:01:13 +00:00
|
|
|
Poco::Net::StreamSocket StorageMongoDBSocketFactory::createSocket(const std::string & host, int port, Poco::Timespan connectTimeout, bool secure)
|
|
|
|
{
|
2021-07-28 14:08:57 +00:00
|
|
|
return secure ? createSecureSocket(host, port, connectTimeout) : createPlainSocket(host, port, connectTimeout);
|
2021-03-23 15:01:13 +00:00
|
|
|
}
|
|
|
|
|
2021-07-28 14:08:57 +00:00
|
|
|
Poco::Net::StreamSocket StorageMongoDBSocketFactory::createPlainSocket(const std::string & host, int port, Poco::Timespan connectTimeout)
|
2021-03-23 15:01:13 +00:00
|
|
|
{
|
|
|
|
Poco::Net::SocketAddress address(host, port);
|
2021-07-28 14:08:57 +00:00
|
|
|
Poco::Net::StreamSocket socket;
|
|
|
|
|
|
|
|
socket.connect(address, connectTimeout);
|
2021-03-23 15:01:13 +00:00
|
|
|
|
|
|
|
return socket;
|
|
|
|
}
|
|
|
|
|
2021-07-28 15:28:30 +00:00
|
|
|
|
2021-07-28 14:08:57 +00:00
|
|
|
Poco::Net::StreamSocket StorageMongoDBSocketFactory::createSecureSocket(const std::string & host, int port, Poco::Timespan connectTimeout)
|
2021-03-23 15:01:13 +00:00
|
|
|
{
|
2021-07-28 15:28:30 +00:00
|
|
|
#if USE_SSL
|
2021-03-23 15:01:13 +00:00
|
|
|
Poco::Net::SocketAddress address(host, port);
|
2021-07-28 14:08:57 +00:00
|
|
|
Poco::Net::SecureStreamSocket socket;
|
|
|
|
|
|
|
|
socket.connect(address, connectTimeout);
|
2021-03-23 15:01:13 +00:00
|
|
|
|
|
|
|
return socket;
|
2021-07-28 15:28:30 +00:00
|
|
|
#else
|
2021-08-02 12:34:50 +00:00
|
|
|
throw Exception("SSL is not enabled at build time.", ErrorCodes::FEATURE_IS_NOT_ENABLED_AT_BUILD_TIME);
|
2021-05-24 12:11:03 +00:00
|
|
|
#endif
|
2021-07-28 15:28:30 +00:00
|
|
|
}
|
2021-03-23 15:01:13 +00:00
|
|
|
|
|
|
|
}
|