Skip to content

Commit 3665a29

Browse files
committed
Various corrections
1 parent f8bd6a3 commit 3665a29

File tree

8 files changed

+70
-8
lines changed

8 files changed

+70
-8
lines changed

src/MongoDB.Driver/ClusterKey.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ internal sealed class ClusterKey
4646
private readonly TimeSpan _maxConnectionLifeTime;
4747
private readonly int _maxConnectionPoolSize;
4848
private readonly int _minConnectionPoolSize;
49+
private readonly string _proxyHost;
50+
private readonly int? _proxyPort;
51+
private readonly string _proxyUsername;
52+
private readonly string _proxyPassword;
4953
private readonly int _receiveBufferSize;
5054
private readonly string _replicaSetName;
5155
private readonly ConnectionStringScheme _scheme;
@@ -84,6 +88,10 @@ public ClusterKey(
8488
TimeSpan maxConnectionLifeTime,
8589
int maxConnectionPoolSize,
8690
int minConnectionPoolSize,
91+
string proxyHost,
92+
int? proxyPort,
93+
string proxyUsername,
94+
string proxyPassword,
8795
int receiveBufferSize,
8896
string replicaSetName,
8997
ConnectionStringScheme scheme,
@@ -120,6 +128,10 @@ public ClusterKey(
120128
_maxConnectionLifeTime = maxConnectionLifeTime;
121129
_maxConnectionPoolSize = maxConnectionPoolSize;
122130
_minConnectionPoolSize = minConnectionPoolSize;
131+
_proxyHost = proxyHost;
132+
_proxyPort = proxyPort;
133+
_proxyUsername = proxyUsername;
134+
_proxyPassword = proxyPassword;
123135
_receiveBufferSize = receiveBufferSize;
124136
_replicaSetName = replicaSetName;
125137
_scheme = scheme;
@@ -160,6 +172,10 @@ public ClusterKey(
160172
public TimeSpan MaxConnectionLifeTime { get { return _maxConnectionLifeTime; } }
161173
public int MaxConnectionPoolSize { get { return _maxConnectionPoolSize; } }
162174
public int MinConnectionPoolSize { get { return _minConnectionPoolSize; } }
175+
public string ProxyHost { get { return _proxyHost; } }
176+
public int? ProxyPort { get { return _proxyPort; } }
177+
public string ProxyUsername { get { return _proxyUsername; } }
178+
public string ProxyPassword { get { return _proxyPassword; } }
163179
public int ReceiveBufferSize { get { return _receiveBufferSize; } }
164180
public string ReplicaSetName { get { return _replicaSetName; } }
165181
public ConnectionStringScheme Scheme { get { return _scheme; } }
@@ -215,6 +231,10 @@ public override bool Equals(object obj)
215231
_maxConnectionLifeTime == rhs._maxConnectionLifeTime &&
216232
_maxConnectionPoolSize == rhs._maxConnectionPoolSize &&
217233
_minConnectionPoolSize == rhs._minConnectionPoolSize &&
234+
_proxyHost == rhs._proxyHost &&
235+
_proxyPort == rhs._proxyPort &&
236+
_proxyUsername == rhs._proxyUsername &&
237+
_proxyPassword == rhs._proxyPassword &&
218238
_receiveBufferSize == rhs._receiveBufferSize &&
219239
_replicaSetName == rhs._replicaSetName &&
220240
_scheme == rhs._scheme &&

src/MongoDB.Driver/ClusterRegistry.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,11 @@ private TcpStreamSettings ConfigureTcp(TcpStreamSettings settings, ClusterKey cl
171171
readTimeout: clusterKey.SocketTimeout,
172172
receiveBufferSize: clusterKey.ReceiveBufferSize,
173173
sendBufferSize: clusterKey.SendBufferSize,
174-
writeTimeout: clusterKey.SocketTimeout);
175-
//TODO Maybe need to add proxy settings to clusterKey as well
174+
writeTimeout: clusterKey.SocketTimeout,
175+
proxyHost: clusterKey.ProxyHost,
176+
proxyPort: clusterKey.ProxyPort,
177+
proxyUsername: clusterKey.ProxyUsername,
178+
proxyPassword: clusterKey.ProxyPassword);
176179
}
177180

178181
internal IClusterInternal GetOrCreateCluster(ClusterKey clusterKey)

src/MongoDB.Driver/Core/Configuration/TcpStreamSettings.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,28 @@ public TcpStreamSettings(
7979
_proxyPassword = proxyPassword.WithDefault(null);
8080
}
8181

82+
// /// <summary>
83+
// ///
84+
// /// </summary>
85+
// /// <param name="addressFamily"></param>
86+
// /// <param name="connectTimeout"></param>
87+
// /// <param name="readTimeout"></param>
88+
// /// <param name="receiveBufferSize"></param>
89+
// /// <param name="sendBufferSize"></param>
90+
// /// <param name="socketConfigurator"></param>
91+
// /// <param name="writeTimeout"></param>
92+
// public TcpStreamSettings(
93+
// Optional<AddressFamily> addressFamily,
94+
// Optional<TimeSpan> connectTimeout,
95+
// Optional<TimeSpan?> readTimeout,
96+
// Optional<int> receiveBufferSize,
97+
// Optional<int> sendBufferSize,
98+
// Optional<Action<Socket>> socketConfigurator,
99+
// Optional<TimeSpan?> writeTimeout)
100+
// {
101+
//
102+
// }
103+
82104
internal TcpStreamSettings(TcpStreamSettings other)
83105
{
84106
_addressFamily = other.AddressFamily;

src/MongoDB.Driver/Core/Connections/Socks5Helper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ public static void PerformSocks5Handshake(Stream stream, EndPoint endPoint, stri
205205

206206
var skip = buffer[3] switch
207207
{
208-
AddressTypeIPv4 => 4 + 2,
209-
AddressTypeIPv6 => 16 + 2,
210-
AddressTypeDomain => buffer[4] + 1 + 2,
208+
AddressTypeIPv4 => 5,
209+
AddressTypeIPv6 => 17,
210+
AddressTypeDomain => buffer[4] + 2,
211211
_ => throw new IOException("Unknown address type in SOCKS5 reply.")
212212
};
213213

src/MongoDB.Driver/Core/Connections/TcpStreamFactory.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public Stream CreateStream(EndPoint endPoint, CancellationToken cancellationToke
7171
{
7272
Socks5Helper.PerformSocks5Handshake(stream, endPoint, _settings.ProxyUsername, _settings.ProxyPassword, cancellationToken);
7373
}
74+
75+
return stream;
7476
}
7577
catch
7678
{

src/MongoDB.Driver/MongoClientSettings.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,7 @@ public override int GetHashCode()
11881188
/// <returns>A string representation of the settings.</returns>
11891189
public override string ToString()
11901190
{
1191+
//TODO Need to add proxy here
11911192
if (_isFrozen)
11921193
{
11931194
return _frozenStringRepresentation;
@@ -1310,6 +1311,10 @@ internal ClusterKey ToClusterKey()
13101311
_maxConnectionLifeTime,
13111312
_maxConnectionPoolSize,
13121313
_minConnectionPoolSize,
1314+
_proxyHost,
1315+
_proxyPort,
1316+
_proxyUsername,
1317+
_proxyPassword,
13131318
MongoDefaults.TcpReceiveBufferSize, // TODO: add ReceiveBufferSize to MongoClientSettings?
13141319
_replicaSetName,
13151320
_scheme,

tests/MongoDB.Driver.Tests/ClusterKeyTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ private ClusterKey CreateSubject(string notEqualFieldName = null)
259259
maxConnectionLifeTime,
260260
maxConnectionPoolSize,
261261
minConnectionPoolSize,
262+
null, //TODO Need to add correct proxy for tests
263+
null,
264+
null,
265+
null,
262266
receiveBufferSize,
263267
replicaSetName,
264268
scheme,
@@ -344,6 +348,10 @@ internal ClusterKey CreateSubjectWith(
344348
maxConnectionLifeTime,
345349
maxConnectionPoolSize,
346350
minConnectionPoolSize,
351+
null, //TODO Add correct proxy for tests
352+
null,
353+
null,
354+
null,
347355
receiveBufferSize,
348356
replicaSetName,
349357
scheme,

tests/MongoDB.Driver.Tests/Specifications/socks5-support/Socks5SupportProseTests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ namespace MongoDB.Driver.Tests.Specifications.socks5_support
2525
public class Socks5SupportProseTests(ITestOutputHelper testOutputHelper) : LoggableTestClass(testOutputHelper)
2626
{
2727

28-
[Theory]
29-
[InlineData("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1080&directConnection=true", false)]
30-
[InlineData("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1081&directConnection=true", true)]
28+
// [Theory]
29+
// [InlineData("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1080&directConnection=true", false)]
30+
// [InlineData("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1081&directConnection=true", true)]
3131
// [InlineData("mongodb://<replicaset>/?proxyHost=localhost&proxyPort=1080", false)]
3232
// [InlineData("mongodb://<replicaset>/?proxyHost=localhost&proxyPort=1081", true)]
3333
// [InlineData("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1080&proxyUsername=nonexistentuser&proxyPassword=badauth&directConnection=true", false)]
@@ -39,11 +39,13 @@ public class Socks5SupportProseTests(ITestOutputHelper testOutputHelper) : Logga
3939
// [InlineData("mongodb://<replicaset>/?proxyHost=localhost&proxyPort=1081", true)]
4040
public void TestConnectionStrings(string connectionString, bool expectedResult)
4141
{
42+
connectionString = connectionString.Replace("<mappedhost>", "localhost:27017");
4243
var client = new MongoClient(connectionString);
4344
var database = client.GetDatabase("admin");
4445

4546
var command = new BsonDocument("hello", 1);
4647
var result = database.RunCommand<BsonDocument>(command);
48+
Assert.NotEmpty(result);
4749
}
4850

4951
}

0 commit comments

Comments
 (0)