From a715feffde27322b61362e23b18603a743e8793f Mon Sep 17 00:00:00 2001 From: Ferdinando Papale <4850119+papafe@users.noreply.github.com> Date: Tue, 22 Jul 2025 09:45:06 +0200 Subject: [PATCH] First version of setting class --- src/MongoDB.Driver/ClusterKey.cs | 26 +--- src/MongoDB.Driver/ClusterRegistry.cs | 5 +- .../Core/Configuration/TcpStreamSettings.cs | 70 ++------- .../Core/Connections/Socks5ProxySettings.cs | 122 ++++++++++++++++ src/MongoDB.Driver/MongoClientSettings.cs | 133 +++--------------- 5 files changed, 161 insertions(+), 195 deletions(-) create mode 100644 src/MongoDB.Driver/Core/Connections/Socks5ProxySettings.cs diff --git a/src/MongoDB.Driver/ClusterKey.cs b/src/MongoDB.Driver/ClusterKey.cs index f0bc568ea6..dec3b93bad 100644 --- a/src/MongoDB.Driver/ClusterKey.cs +++ b/src/MongoDB.Driver/ClusterKey.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; using System.Linq; using MongoDB.Driver.Core.Configuration; +using MongoDB.Driver.Core.Connections; using MongoDB.Driver.Core.Servers; using MongoDB.Shared; @@ -46,10 +47,6 @@ namespace MongoDB.Driver private readonly TimeSpan _maxConnectionLifeTime; private readonly int _maxConnectionPoolSize; private readonly int _minConnectionPoolSize; - private readonly string _proxyHost; - private readonly int? _proxyPort; - private readonly string _proxyUsername; - private readonly string _proxyPassword; private readonly int _receiveBufferSize; private readonly string _replicaSetName; private readonly ConnectionStringScheme _scheme; @@ -59,6 +56,7 @@ namespace MongoDB.Driver private readonly ServerMonitoringMode _serverMonitoringMode; private readonly TimeSpan _serverSelectionTimeout; private readonly TimeSpan _socketTimeout; + private readonly Socks5ProxySettings _socks5ProxySettings; private readonly int _srvMaxHosts; private readonly string _srvServiceName; private readonly SslSettings _sslSettings; @@ -88,10 +86,6 @@ namespace MongoDB.Driver TimeSpan maxConnectionLifeTime, int maxConnectionPoolSize, int minConnectionPoolSize, - string proxyHost, - int? proxyPort, - string proxyUsername, - string proxyPassword, int receiveBufferSize, string replicaSetName, ConnectionStringScheme scheme, @@ -101,6 +95,7 @@ namespace MongoDB.Driver ServerMonitoringMode serverMonitoringMode, TimeSpan serverSelectionTimeout, TimeSpan socketTimeout, + Socks5ProxySettings socks5ProxySettings, int srvMaxHosts, string srvServiceName, SslSettings sslSettings, @@ -128,10 +123,6 @@ namespace MongoDB.Driver _maxConnectionLifeTime = maxConnectionLifeTime; _maxConnectionPoolSize = maxConnectionPoolSize; _minConnectionPoolSize = minConnectionPoolSize; - _proxyHost = proxyHost; - _proxyPort = proxyPort; - _proxyUsername = proxyUsername; - _proxyPassword = proxyPassword; _receiveBufferSize = receiveBufferSize; _replicaSetName = replicaSetName; _scheme = scheme; @@ -141,6 +132,7 @@ namespace MongoDB.Driver _serverMonitoringMode = serverMonitoringMode; _serverSelectionTimeout = serverSelectionTimeout; _socketTimeout = socketTimeout; + _socks5ProxySettings = socks5ProxySettings; _srvMaxHosts = srvMaxHosts; _srvServiceName = srvServiceName; _sslSettings = sslSettings; @@ -172,10 +164,6 @@ namespace MongoDB.Driver public TimeSpan MaxConnectionLifeTime { get { return _maxConnectionLifeTime; } } public int MaxConnectionPoolSize { get { return _maxConnectionPoolSize; } } public int MinConnectionPoolSize { get { return _minConnectionPoolSize; } } - public string ProxyHost { get { return _proxyHost; } } - public int? ProxyPort { get { return _proxyPort; } } - public string ProxyUsername { get { return _proxyUsername; } } - public string ProxyPassword { get { return _proxyPassword; } } public int ReceiveBufferSize { get { return _receiveBufferSize; } } public string ReplicaSetName { get { return _replicaSetName; } } public ConnectionStringScheme Scheme { get { return _scheme; } } @@ -185,6 +173,7 @@ namespace MongoDB.Driver public ServerMonitoringMode ServerMonitoringMode { get { return _serverMonitoringMode; } } public TimeSpan ServerSelectionTimeout { get { return _serverSelectionTimeout; } } public TimeSpan SocketTimeout { get { return _socketTimeout; } } + public Socks5ProxySettings Socks5ProxySettings { get { return _socks5ProxySettings; } } public int SrvMaxHosts { get { return _srvMaxHosts; } } public string SrvServiceName { get { return _srvServiceName; } } public SslSettings SslSettings { get { return _sslSettings; } } @@ -231,10 +220,6 @@ namespace MongoDB.Driver _maxConnectionLifeTime == rhs._maxConnectionLifeTime && _maxConnectionPoolSize == rhs._maxConnectionPoolSize && _minConnectionPoolSize == rhs._minConnectionPoolSize && - _proxyHost == rhs._proxyHost && - _proxyPort == rhs._proxyPort && - _proxyUsername == rhs._proxyUsername && - _proxyPassword == rhs._proxyPassword && _receiveBufferSize == rhs._receiveBufferSize && _replicaSetName == rhs._replicaSetName && _scheme == rhs._scheme && @@ -244,6 +229,7 @@ namespace MongoDB.Driver _serverMonitoringMode == rhs._serverMonitoringMode && _serverSelectionTimeout == rhs._serverSelectionTimeout && _socketTimeout == rhs._socketTimeout && + object.Equals(_socks5ProxySettings, rhs._socks5ProxySettings) && _srvMaxHosts == rhs._srvMaxHosts && _srvServiceName == rhs.SrvServiceName && object.Equals(_sslSettings, rhs._sslSettings) && diff --git a/src/MongoDB.Driver/ClusterRegistry.cs b/src/MongoDB.Driver/ClusterRegistry.cs index 5332811765..e6763cf0ba 100644 --- a/src/MongoDB.Driver/ClusterRegistry.cs +++ b/src/MongoDB.Driver/ClusterRegistry.cs @@ -172,10 +172,7 @@ namespace MongoDB.Driver receiveBufferSize: clusterKey.ReceiveBufferSize, sendBufferSize: clusterKey.SendBufferSize, writeTimeout: clusterKey.SocketTimeout, - proxyHost: clusterKey.ProxyHost, - proxyPort: clusterKey.ProxyPort, - proxyUsername: clusterKey.ProxyUsername, - proxyPassword: clusterKey.ProxyPassword); + socks5ProxySettings: clusterKey.Socks5ProxySettings); } internal IClusterInternal GetOrCreateCluster(ClusterKey clusterKey) diff --git a/src/MongoDB.Driver/Core/Configuration/TcpStreamSettings.cs b/src/MongoDB.Driver/Core/Configuration/TcpStreamSettings.cs index dbd0e77e22..1ba8f38a3c 100644 --- a/src/MongoDB.Driver/Core/Configuration/TcpStreamSettings.cs +++ b/src/MongoDB.Driver/Core/Configuration/TcpStreamSettings.cs @@ -16,6 +16,7 @@ using System; using System.Net.Sockets; using System.Threading; +using MongoDB.Driver.Core.Connections; using MongoDB.Driver.Core.Misc; namespace MongoDB.Driver.Core.Configuration @@ -32,11 +33,8 @@ namespace MongoDB.Driver.Core.Configuration private readonly int _receiveBufferSize; private readonly int _sendBufferSize; private readonly Action _socketConfigurator; + private readonly Socks5ProxySettings _socks5ProxySettings; private readonly TimeSpan? _writeTimeout; - private readonly string _proxyHost; - private readonly int? _proxyPort; - private readonly string _proxyUsername; - private readonly string _proxyPassword; // constructors /// @@ -48,11 +46,8 @@ namespace MongoDB.Driver.Core.Configuration /// Size of the receive buffer. /// Size of the send buffer. /// The socket configurator. + /// The SOCKS5 proxy settings. /// The write timeout. - /// //TODO - /// - /// - /// public TcpStreamSettings( Optional addressFamily = default(Optional), Optional connectTimeout = default(Optional), @@ -61,10 +56,7 @@ namespace MongoDB.Driver.Core.Configuration Optional sendBufferSize = default(Optional), Optional> socketConfigurator = default(Optional>), Optional writeTimeout = default(Optional), - Optional proxyHost = default(Optional), - Optional proxyPort = default(Optional), - Optional proxyUsername = default(Optional), - Optional proxyPassword = default(Optional)) + Optional socks5ProxySettings = default(Optional)) { _addressFamily = addressFamily.WithDefault(AddressFamily.InterNetwork); _connectTimeout = Ensure.IsInfiniteOrGreaterThanOrEqualToZero(connectTimeout.WithDefault(Timeout.InfiniteTimeSpan), "connectTimeout"); @@ -73,10 +65,7 @@ namespace MongoDB.Driver.Core.Configuration _sendBufferSize = Ensure.IsGreaterThanZero(sendBufferSize.WithDefault(64 * 1024), "sendBufferSize"); _socketConfigurator = socketConfigurator.WithDefault(null); _writeTimeout = Ensure.IsNullOrInfiniteOrGreaterThanOrEqualToZero(writeTimeout.WithDefault(null), "writeTimeout"); - _proxyHost = proxyHost.WithDefault(null); - _proxyPort = proxyPort.WithDefault(null); - _proxyUsername = proxyUsername.WithDefault(null); - _proxyPassword = proxyPassword.WithDefault(null); + _socks5ProxySettings = socks5ProxySettings.WithDefault(null); } // /// @@ -109,11 +98,8 @@ namespace MongoDB.Driver.Core.Configuration _receiveBufferSize = other.ReceiveBufferSize; _sendBufferSize = other.SendBufferSize; _socketConfigurator = other.SocketConfigurator; + _socks5ProxySettings = other._socks5ProxySettings; _writeTimeout = other.WriteTimeout; - _proxyHost = other._proxyHost; - _proxyPort = other._proxyPort; - _proxyUsername = other._proxyUsername; - _proxyPassword = other._proxyPassword; } // properties @@ -183,6 +169,11 @@ namespace MongoDB.Driver.Core.Configuration get { return _socketConfigurator; } } + /// + /// Gets the SOCKS5 proxy settings. + /// + public Socks5ProxySettings Socks5ProxySettings => _socks5ProxySettings; + /// /// Gets the write timeout. /// @@ -194,28 +185,6 @@ namespace MongoDB.Driver.Core.Configuration get { return _writeTimeout; } } - //TODO Add xml docs - /// - /// - /// - public string ProxyHost => _proxyHost; - /// - /// - /// - public int? ProxyPort => _proxyPort; - /// - /// - /// - public string ProxyUsername => _proxyUsername; - /// - /// - /// - public string ProxyPassword => _proxyPassword; - - //TODO We can decide to remove this - internal bool UseProxy => !string.IsNullOrEmpty(_proxyHost) && _proxyPort.HasValue; - - // methods /// /// Returns a new TcpStreamSettings instance with some settings changed. @@ -226,11 +195,8 @@ namespace MongoDB.Driver.Core.Configuration /// Size of the receive buffer. /// Size of the send buffer. /// The socket configurator. + /// The SOCKS5 proxy settings. /// The write timeout. - /// //TODO Add docs - /// - /// - /// /// A new TcpStreamSettings instance. public TcpStreamSettings With( Optional addressFamily = default(Optional), @@ -240,10 +206,7 @@ namespace MongoDB.Driver.Core.Configuration Optional sendBufferSize = default(Optional), Optional> socketConfigurator = default(Optional>), Optional writeTimeout = default(Optional), - Optional proxyHost = default(Optional), - Optional proxyPort = default(Optional), - Optional proxyUsername = default(Optional), - Optional proxyPassword = default(Optional)) + Optional socks5ProxySettings = default(Optional)) { return new TcpStreamSettings( addressFamily: addressFamily.WithDefault(_addressFamily), @@ -252,11 +215,8 @@ namespace MongoDB.Driver.Core.Configuration receiveBufferSize: receiveBufferSize.WithDefault(_receiveBufferSize), sendBufferSize: sendBufferSize.WithDefault(_sendBufferSize), socketConfigurator: socketConfigurator.WithDefault(_socketConfigurator), - writeTimeout: writeTimeout.WithDefault(_writeTimeout), - proxyHost: proxyHost.WithDefault(_proxyHost), - proxyPort: proxyPort.WithDefault(_proxyPort), - proxyUsername: proxyUsername.WithDefault(_proxyUsername), - proxyPassword: proxyPassword.WithDefault(_proxyPassword)); + socks5ProxySettings: socks5ProxySettings.WithDefault(_socks5ProxySettings), + writeTimeout: writeTimeout.WithDefault(_writeTimeout)); } } } diff --git a/src/MongoDB.Driver/Core/Connections/Socks5ProxySettings.cs b/src/MongoDB.Driver/Core/Connections/Socks5ProxySettings.cs new file mode 100644 index 0000000000..4350433b81 --- /dev/null +++ b/src/MongoDB.Driver/Core/Connections/Socks5ProxySettings.cs @@ -0,0 +1,122 @@ +/* Copyright 2010-present MongoDB Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using MongoDB.Driver.Core.Misc; + +namespace MongoDB.Driver.Core.Connections +{ + /// + /// Represents the settings for a SOCKS5 proxy connection. + /// + public class Socks5ProxySettings + { + /// + /// Gets the host of the SOCKS5 proxy. + /// + public string Host { get; } + + /// + /// Gets the port of the SOCKS5 proxy. + /// + public int Port { get; } + + /// + /// Gets the authentication settings of the SOCKS5 proxy. + /// + public Socks5AuthenticationSettings Authentication { get; } + + private Socks5ProxySettings(string host, int port, Socks5AuthenticationSettings authentication) + { + Host = Ensure.IsNotNullOrEmpty(host, nameof(host)); + Port = Ensure.IsBetween(port, 0, 65535, nameof(port)); + Authentication = Ensure.IsNotNull(authentication, nameof(authentication)); + } + + internal static Socks5ProxySettings Create(string host, int? port, string username, string password) + { + Socks5AuthenticationSettings authentication; + + if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password)) + { + authentication = Socks5AuthenticationSettings.UsernamePassword(username, password); + } + else + { + authentication = Socks5AuthenticationSettings.None; + } + + return new Socks5ProxySettings(host, port ?? 1080, authentication); + } + + /// + /// Creates a new instance of . + /// + /// The host. + /// The port + /// The authentication settings. + /// + public static Socks5ProxySettings Create(string host, int port = 1080, Socks5AuthenticationSettings authentication = null) + { + return new Socks5ProxySettings(host, port, authentication ?? Socks5AuthenticationSettings.None); + } + } + + internal enum Socks5AuthenticationType + { + None, + UsernamePassword + } + + /// + /// Represents the settings for SOCKS5 authentication. + /// + public abstract class Socks5AuthenticationSettings + { + internal abstract Socks5AuthenticationType Type { get; } + + /// + /// Creates authentication settings that do not require any authentication. + /// + public static Socks5AuthenticationSettings None => new NoAuthenticationSettings(); + + /// + /// Creates authentication settings for username and password. + /// + /// + /// + /// + public static Socks5AuthenticationSettings UsernamePassword(string username, string password) + => new UsernamePasswordAuthenticationSettings(username, password); + + private sealed class NoAuthenticationSettings : Socks5AuthenticationSettings + { + internal override Socks5AuthenticationType Type => Socks5AuthenticationType.None; + } + + private sealed class UsernamePasswordAuthenticationSettings : Socks5AuthenticationSettings + { + internal override Socks5AuthenticationType Type => Socks5AuthenticationType.UsernamePassword; + public string Username { get; } + public string Password { get; } + + internal UsernamePasswordAuthenticationSettings(string username, string password) + { + Username = Ensure.IsNotNullOrEmpty(username, nameof(username)); + Password = Ensure.IsNotNullOrEmpty(password, nameof(password)); + } + } + } +} \ No newline at end of file diff --git a/src/MongoDB.Driver/MongoClientSettings.cs b/src/MongoDB.Driver/MongoClientSettings.cs index ea2e5796ae..40c877b812 100644 --- a/src/MongoDB.Driver/MongoClientSettings.cs +++ b/src/MongoDB.Driver/MongoClientSettings.cs @@ -20,9 +20,9 @@ using System.Linq; using System.Text; using MongoDB.Driver.Core.Compression; using MongoDB.Driver.Core.Configuration; +using MongoDB.Driver.Core.Connections; using MongoDB.Driver.Core.Misc; using MongoDB.Driver.Core.Servers; -using MongoDB.Driver.Encryption; using MongoDB.Shared; namespace MongoDB.Driver @@ -59,10 +59,6 @@ namespace MongoDB.Driver private TimeSpan _maxConnectionLifeTime; private int _maxConnectionPoolSize; private int _minConnectionPoolSize; - private string _proxyHost; - private int? _proxyPort; - private string _proxyUsername; - private string _proxyPassword; private ReadConcern _readConcern; private UTF8Encoding _readEncoding; private ReadPreference _readPreference; @@ -75,6 +71,7 @@ namespace MongoDB.Driver private ServerMonitoringMode _serverMonitoringMode; private TimeSpan _serverSelectionTimeout; private TimeSpan _socketTimeout; + private Socks5ProxySettings _socks5ProxySettings; private int _srvMaxHosts; private string _srvServiceName; private SslSettings _sslSettings; @@ -114,10 +111,6 @@ namespace MongoDB.Driver _maxConnectionLifeTime = MongoDefaults.MaxConnectionLifeTime; _maxConnectionPoolSize = MongoDefaults.MaxConnectionPoolSize; _minConnectionPoolSize = MongoDefaults.MinConnectionPoolSize; - _proxyHost = null; - _proxyPort = null; - _proxyUsername = null; - _proxyPassword = null; _readConcern = ReadConcern.Default; _readEncoding = null; _readPreference = ReadPreference.Primary; @@ -130,6 +123,7 @@ namespace MongoDB.Driver _serverMonitoringMode = ServerMonitoringMode.Auto; _serverSelectionTimeout = MongoDefaults.ServerSelectionTimeout; _socketTimeout = MongoDefaults.SocketTimeout; + _socks5ProxySettings = null; _srvMaxHosts = 0; _srvServiceName = MongoInternalDefaults.MongoClientSettings.SrvServiceName; _sslSettings = null; @@ -437,60 +431,15 @@ namespace MongoDB.Driver } /// - /// Gets or sets the proxy host. + /// Gets or sets the SOCKS5 proxy settings. /// - public string ProxyHost + public Socks5ProxySettings Socks5ProxySettings { - get => _proxyHost; + get => _socks5ProxySettings; set { if (_isFrozen) { throw new InvalidOperationException("MongoClientSettings is frozen."); } - _proxyHost = value; - } - } - - /// - /// Gets or sets the proxy port. - /// - public int? ProxyPort - { - get => _proxyPort; - set - { - if (_isFrozen) { throw new InvalidOperationException("MongoClientSettings is frozen."); } - - if (value is < 0 or > 65535) - { - throw new MongoConfigurationException("ProxyPort must be between 0 and 65535."); - } - - _proxyPort = value; - } - } - - /// - /// Gets or sets the proxy username. - /// - public string ProxyUsername - { - get => _proxyUsername; - set - { - if (_isFrozen) { throw new InvalidOperationException("MongoClientSettings is frozen."); } - _proxyUsername = value; - } - } - - /// - /// Gets or sets the proxy password. - /// - public string ProxyPassword - { - get => _proxyPassword; - set - { - if (_isFrozen) { throw new InvalidOperationException("MongoClientSettings is frozen."); } - _proxyPassword = value; + _socks5ProxySettings = value; } } @@ -929,10 +878,6 @@ namespace MongoDB.Driver clientSettings.MaxConnectionLifeTime = url.MaxConnectionLifeTime; clientSettings.MaxConnectionPoolSize = ConnectionStringConversions.GetEffectiveMaxConnections(url.MaxConnectionPoolSize); clientSettings.MinConnectionPoolSize = url.MinConnectionPoolSize; - clientSettings.ProxyHost = url.ProxyHost; - clientSettings.ProxyPort = url.ProxyPort; - clientSettings.ProxyUsername = url.ProxyUsername; - clientSettings.ProxyPassword = url.ProxyPassword; clientSettings.ReadConcern = new ReadConcern(url.ReadConcernLevel); clientSettings.ReadEncoding = null; // ReadEncoding must be provided in code clientSettings.ReadPreference = (url.ReadPreference == null) ? ReadPreference.Primary : url.ReadPreference; @@ -944,6 +889,10 @@ namespace MongoDB.Driver clientSettings.ServerMonitoringMode = url.ServerMonitoringMode ?? ServerMonitoringMode.Auto; clientSettings.ServerSelectionTimeout = url.ServerSelectionTimeout; clientSettings.SocketTimeout = url.SocketTimeout; + if (!string.IsNullOrEmpty(url.ProxyHost)) + { + clientSettings.Socks5ProxySettings = Socks5ProxySettings.Create(url.ProxyHost, url.ProxyPort, url.ProxyUsername, url.ProxyPassword); + } clientSettings.SrvMaxHosts = url.SrvMaxHosts.GetValueOrDefault(0); clientSettings.SrvServiceName = url.SrvServiceName; clientSettings.SslSettings = null; @@ -990,10 +939,6 @@ namespace MongoDB.Driver clone._maxConnectionLifeTime = _maxConnectionLifeTime; clone._maxConnectionPoolSize = _maxConnectionPoolSize; clone._minConnectionPoolSize = _minConnectionPoolSize; - clone._proxyHost = _proxyHost; - clone._proxyPort = _proxyPort; - clone._proxyUsername = _proxyUsername; - clone._proxyPassword = _proxyPassword; clone._readConcern = _readConcern; clone._readEncoding = _readEncoding; clone._readPreference = _readPreference; @@ -1006,6 +951,7 @@ namespace MongoDB.Driver clone._serverMonitoringMode = _serverMonitoringMode; clone._serverSelectionTimeout = _serverSelectionTimeout; clone._socketTimeout = _socketTimeout; + clone._socks5ProxySettings = _socks5ProxySettings; clone._srvMaxHosts = _srvMaxHosts; clone._srvServiceName = _srvServiceName; clone._sslSettings = (_sslSettings == null) ? null : _sslSettings.Clone(); @@ -1063,10 +1009,6 @@ namespace MongoDB.Driver _maxConnectionLifeTime == rhs._maxConnectionLifeTime && _maxConnectionPoolSize == rhs._maxConnectionPoolSize && _minConnectionPoolSize == rhs._minConnectionPoolSize && - _proxyHost == rhs._proxyHost && - _proxyPort == rhs._proxyPort && - _proxyUsername == rhs._proxyUsername && - _proxyPassword == rhs._proxyPassword && object.Equals(_readEncoding, rhs._readEncoding) && object.Equals(_readConcern, rhs._readConcern) && object.Equals(_readPreference, rhs._readPreference) && @@ -1079,6 +1021,7 @@ namespace MongoDB.Driver _serverMonitoringMode == rhs._serverMonitoringMode && _serverSelectionTimeout == rhs._serverSelectionTimeout && _socketTimeout == rhs._socketTimeout && + object.Equals(_socks5ProxySettings, rhs._socks5ProxySettings) && _srvMaxHosts == rhs._srvMaxHosts && _srvServiceName == rhs._srvServiceName && _sslSettings == rhs._sslSettings && @@ -1154,10 +1097,6 @@ namespace MongoDB.Driver .Hash(_maxConnectionLifeTime) .Hash(_maxConnectionPoolSize) .Hash(_minConnectionPoolSize) - .Hash(_proxyHost) - .Hash(_proxyPort) - .Hash(_proxyUsername) - .Hash(_proxyPassword) .Hash(_readConcern) .Hash(_readEncoding) .Hash(_readPreference) @@ -1170,6 +1109,7 @@ namespace MongoDB.Driver .Hash(_serverMonitoringMode) .Hash(_serverSelectionTimeout) .Hash(_socketTimeout) + .Hash(_socks5ProxySettings) .Hash(_srvMaxHosts) .Hash(_srvServiceName) .Hash(_sslSettings) @@ -1188,7 +1128,6 @@ namespace MongoDB.Driver /// A string representation of the settings. public override string ToString() { - //TODO Need to add proxy here if (_isFrozen) { return _frozenStringRepresentation; @@ -1228,21 +1167,9 @@ namespace MongoDB.Driver sb.AppendFormat("MaxConnectionLifeTime={0};", _maxConnectionLifeTime); sb.AppendFormat("MaxConnectionPoolSize={0};", _maxConnectionPoolSize); sb.AppendFormat("MinConnectionPoolSize={0};", _minConnectionPoolSize); - if (_proxyHost != null) + if (_socks5ProxySettings!= null) { - sb.AppendFormat("ProxyHost={0};", _proxyHost); - } - if (_proxyPort != null) - { - sb.AppendFormat("ProxyPort={0};", _proxyPort.Value); - } - if (_proxyUsername != null) - { - sb.AppendFormat("ProxyUsername={0};", _proxyUsername); - } - if (_proxyPassword != null) - { - sb.AppendFormat("ProxyPassword={0};", _proxyPassword); + sb.AppendFormat("ProxyHost={0};", _socks5ProxySettings); } if (_readEncoding != null) { @@ -1311,10 +1238,6 @@ namespace MongoDB.Driver _maxConnectionLifeTime, _maxConnectionPoolSize, _minConnectionPoolSize, - _proxyHost, - _proxyPort, - _proxyUsername, - _proxyPassword, MongoDefaults.TcpReceiveBufferSize, // TODO: add ReceiveBufferSize to MongoClientSettings? _replicaSetName, _scheme, @@ -1324,6 +1247,7 @@ namespace MongoDB.Driver _serverMonitoringMode, _serverSelectionTimeout, _socketTimeout, + _socks5ProxySettings, _srvMaxHosts, _srvServiceName, _sslSettings, @@ -1400,29 +1324,6 @@ namespace MongoDB.Driver throw new InvalidOperationException("Load balanced mode cannot be used with direct connection."); } } - - if (string.IsNullOrEmpty(_proxyHost)) - { - if (_proxyPort is not null) - { - throw new InvalidOperationException("ProxyPort cannot be specified without ProxyHost."); - } - - if (!string.IsNullOrEmpty(_proxyUsername)) - { - throw new InvalidOperationException("ProxyUsername cannot be specified without ProxyHost."); - } - - if (!string.IsNullOrEmpty(_proxyPassword)) - { - throw new InvalidOperationException("ProxyPassword cannot be specified without ProxyHost."); - } - } - - if (string.IsNullOrEmpty(_proxyUsername) != string.IsNullOrEmpty(_proxyPassword)) - { - throw new InvalidOperationException("ProxyUsername and ProxyPassword must both be specified or neither."); - } } } }