mirror of
https://github.com/pocoproject/poco.git
synced 2025-12-10 18:14:58 +01:00
enh(MongoDB): Updates to use SSL socket factory.
This commit is contained in:
@@ -90,9 +90,21 @@ public:
|
|||||||
|
|
||||||
unsigned int connectTimeoutSeconds{10};
|
unsigned int connectTimeoutSeconds{10};
|
||||||
/// Connection timeout in seconds (default: 10)
|
/// Connection timeout in seconds (default: 10)
|
||||||
|
///
|
||||||
|
/// NOTE: This value is currently unused by ReplicaSet itself. It is intended
|
||||||
|
/// for use by custom SocketFactory implementations. Custom factories can
|
||||||
|
/// access this value via ReplicaSet::configuration() and use it when creating
|
||||||
|
/// sockets. Use ReplicaSet::setSocketFactory() to set a custom factory that
|
||||||
|
/// utilizes this timeout value.
|
||||||
|
|
||||||
unsigned int socketTimeoutSeconds{30};
|
unsigned int socketTimeoutSeconds{30};
|
||||||
/// Socket send/receive timeout in seconds (default: 30)
|
/// Socket send/receive timeout in seconds (default: 30)
|
||||||
|
///
|
||||||
|
/// NOTE: This value is currently unused by ReplicaSet itself. It is intended
|
||||||
|
/// for use by custom SocketFactory implementations. Custom factories can
|
||||||
|
/// access this value via ReplicaSet::configuration() and use it when creating
|
||||||
|
/// sockets. Use ReplicaSet::setSocketFactory() to set a custom factory that
|
||||||
|
/// utilizes this timeout value.
|
||||||
|
|
||||||
unsigned int heartbeatFrequencySeconds{10};
|
unsigned int heartbeatFrequencySeconds{10};
|
||||||
/// Topology monitoring interval in seconds (default: 10)
|
/// Topology monitoring interval in seconds (default: 10)
|
||||||
@@ -107,7 +119,9 @@ public:
|
|||||||
/// Enable background topology monitoring (default: true)
|
/// Enable background topology monitoring (default: true)
|
||||||
|
|
||||||
Connection::SocketFactory* socketFactory{nullptr};
|
Connection::SocketFactory* socketFactory{nullptr};
|
||||||
/// Optional socket factory for SSL/TLS connections
|
/// Optional socket factory for SSL/TLS connections.
|
||||||
|
/// Can be set via config or later using setSocketFactory().
|
||||||
|
/// Custom factories can access timeout config via ReplicaSet::configuration().
|
||||||
|
|
||||||
Logger::Ptr logger;
|
Logger::Ptr logger;
|
||||||
/// Optional logger to write important information about replica set activity
|
/// Optional logger to write important information about replica set activity
|
||||||
@@ -174,6 +188,14 @@ public:
|
|||||||
void setLogger(Logger::Ptr logger);
|
void setLogger(Logger::Ptr logger);
|
||||||
/// Sets the logger to log important replica set activity.
|
/// Sets the logger to log important replica set activity.
|
||||||
|
|
||||||
|
void setSocketFactory(Connection::SocketFactory* factory);
|
||||||
|
/// Sets the socket factory for creating connections.
|
||||||
|
/// The factory can access timeout configuration via configuration().connectTimeoutSeconds
|
||||||
|
/// and configuration().socketTimeoutSeconds.
|
||||||
|
///
|
||||||
|
/// Example:
|
||||||
|
/// rs.setSocketFactory(&myCustomFactory);
|
||||||
|
|
||||||
void setReadPreference(const ReadPreference& pref);
|
void setReadPreference(const ReadPreference& pref);
|
||||||
/// Sets the default read preference.
|
/// Sets the default read preference.
|
||||||
|
|
||||||
|
|||||||
@@ -196,6 +196,13 @@ void ReplicaSet::setLogger(Logger::Ptr logger)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ReplicaSet::setSocketFactory(Connection::SocketFactory* factory)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(_mutex);
|
||||||
|
_config.socketFactory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ReplicaSet::setReadPreference(const ReadPreference& pref)
|
void ReplicaSet::setReadPreference(const ReadPreference& pref)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(_mutex);
|
std::lock_guard<std::mutex> lock(_mutex);
|
||||||
@@ -290,7 +297,9 @@ Connection::Ptr ReplicaSet::createConnection(const Net::SocketAddress& address)
|
|||||||
if (_config.socketFactory != nullptr)
|
if (_config.socketFactory != nullptr)
|
||||||
{
|
{
|
||||||
// Use custom socket factory (e.g., for SSL/TLS)
|
// Use custom socket factory (e.g., for SSL/TLS)
|
||||||
// Note: Socket timeouts should be configured in the SocketFactory
|
// Custom factories can be set via Config or using setSocketFactory().
|
||||||
|
// They can access timeout values via configuration().connectTimeoutSeconds
|
||||||
|
// and configuration().socketTimeoutSeconds to properly configure sockets.
|
||||||
conn->connect(address.toString(), *_config.socketFactory);
|
conn->connect(address.toString(), *_config.socketFactory);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -298,8 +307,8 @@ Connection::Ptr ReplicaSet::createConnection(const Net::SocketAddress& address)
|
|||||||
conn->connect(address);
|
conn->connect(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: Socket timeouts are configured via URI or during socket creation
|
// Note: Connection class doesn't expose socket() accessor, so socket timeouts
|
||||||
// Connection class doesn't expose socket() accessor
|
// must be configured during socket creation via custom SocketFactory.
|
||||||
|
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
@@ -324,6 +333,8 @@ void ReplicaSet::updateTopologyFromHello(const Net::SocketAddress& address) noex
|
|||||||
|
|
||||||
if (_config.socketFactory != nullptr)
|
if (_config.socketFactory != nullptr)
|
||||||
{
|
{
|
||||||
|
// Custom factories can be set via Config or using setSocketFactory().
|
||||||
|
// They can access timeout values via configuration() to configure sockets.
|
||||||
conn->connect(address.toString(), *_config.socketFactory);
|
conn->connect(address.toString(), *_config.socketFactory);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -331,8 +342,8 @@ void ReplicaSet::updateTopologyFromHello(const Net::SocketAddress& address) noex
|
|||||||
conn->connect(address);
|
conn->connect(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: Socket timeouts are configured via URI or during socket creation
|
// Note: Connection class doesn't expose socket() accessor, so socket timeouts
|
||||||
// Connection class doesn't expose socket() accessor
|
// must be configured during socket creation via custom SocketFactory.
|
||||||
|
|
||||||
// Send hello command
|
// Send hello command
|
||||||
OpMsgMessage request("admin", "");
|
OpMsgMessage request("admin", "");
|
||||||
|
|||||||
Reference in New Issue
Block a user