16
16
using System ;
17
17
using System . Net . Sockets ;
18
18
using System . Threading ;
19
+ using MongoDB . Driver . Core . Connections ;
19
20
using MongoDB . Driver . Core . Misc ;
20
21
21
22
namespace MongoDB . Driver . Core . Configuration
@@ -32,11 +33,8 @@ public class TcpStreamSettings
32
33
private readonly int _receiveBufferSize ;
33
34
private readonly int _sendBufferSize ;
34
35
private readonly Action < Socket > _socketConfigurator ;
36
+ private readonly Socks5ProxySettings _socks5ProxySettings ;
35
37
private readonly TimeSpan ? _writeTimeout ;
36
- private readonly string _proxyHost ;
37
- private readonly int ? _proxyPort ;
38
- private readonly string _proxyUsername ;
39
- private readonly string _proxyPassword ;
40
38
41
39
// constructors
42
40
/// <summary>
@@ -48,11 +46,8 @@ public class TcpStreamSettings
48
46
/// <param name="receiveBufferSize">Size of the receive buffer.</param>
49
47
/// <param name="sendBufferSize">Size of the send buffer.</param>
50
48
/// <param name="socketConfigurator">The socket configurator.</param>
49
+ /// <param name="socks5ProxySettings">The SOCKS5 proxy settings.</param>
51
50
/// <param name="writeTimeout">The write timeout.</param>
52
- /// <param name="proxyHost">//TODO</param>
53
- /// <param name="proxyPort"></param>
54
- /// <param name="proxyUsername"></param>
55
- /// <param name="proxyPassword"></param>
56
51
public TcpStreamSettings (
57
52
Optional < AddressFamily > addressFamily = default ( Optional < AddressFamily > ) ,
58
53
Optional < TimeSpan > connectTimeout = default ( Optional < TimeSpan > ) ,
@@ -61,10 +56,7 @@ public TcpStreamSettings(
61
56
Optional < int > sendBufferSize = default ( Optional < int > ) ,
62
57
Optional < Action < Socket > > socketConfigurator = default ( Optional < Action < Socket > > ) ,
63
58
Optional < TimeSpan ? > writeTimeout = default ( Optional < TimeSpan ? > ) ,
64
- Optional < string > proxyHost = default ( Optional < string > ) ,
65
- Optional < int ? > proxyPort = default ( Optional < int ? > ) ,
66
- Optional < string > proxyUsername = default ( Optional < string > ) ,
67
- Optional < string > proxyPassword = default ( Optional < string > ) )
59
+ Optional < Socks5ProxySettings > socks5ProxySettings = default ( Optional < Socks5ProxySettings > ) )
68
60
{
69
61
_addressFamily = addressFamily . WithDefault ( AddressFamily . InterNetwork ) ;
70
62
_connectTimeout = Ensure . IsInfiniteOrGreaterThanOrEqualToZero ( connectTimeout . WithDefault ( Timeout . InfiniteTimeSpan ) , "connectTimeout" ) ;
@@ -73,10 +65,7 @@ public TcpStreamSettings(
73
65
_sendBufferSize = Ensure . IsGreaterThanZero ( sendBufferSize . WithDefault ( 64 * 1024 ) , "sendBufferSize" ) ;
74
66
_socketConfigurator = socketConfigurator . WithDefault ( null ) ;
75
67
_writeTimeout = Ensure . IsNullOrInfiniteOrGreaterThanOrEqualToZero ( writeTimeout . WithDefault ( null ) , "writeTimeout" ) ;
76
- _proxyHost = proxyHost . WithDefault ( null ) ;
77
- _proxyPort = proxyPort . WithDefault ( null ) ;
78
- _proxyUsername = proxyUsername . WithDefault ( null ) ;
79
- _proxyPassword = proxyPassword . WithDefault ( null ) ;
68
+ _socks5ProxySettings = socks5ProxySettings . WithDefault ( null ) ;
80
69
}
81
70
82
71
// /// <summary>
@@ -109,11 +98,8 @@ internal TcpStreamSettings(TcpStreamSettings other)
109
98
_receiveBufferSize = other . ReceiveBufferSize ;
110
99
_sendBufferSize = other . SendBufferSize ;
111
100
_socketConfigurator = other . SocketConfigurator ;
101
+ _socks5ProxySettings = other . _socks5ProxySettings ;
112
102
_writeTimeout = other . WriteTimeout ;
113
- _proxyHost = other . _proxyHost ;
114
- _proxyPort = other . _proxyPort ;
115
- _proxyUsername = other . _proxyUsername ;
116
- _proxyPassword = other . _proxyPassword ;
117
103
}
118
104
119
105
// properties
@@ -183,6 +169,11 @@ public Action<Socket> SocketConfigurator
183
169
get { return _socketConfigurator ; }
184
170
}
185
171
172
+ /// <summary>
173
+ /// Gets the SOCKS5 proxy settings.
174
+ /// </summary>
175
+ public Socks5ProxySettings Socks5ProxySettings => _socks5ProxySettings ;
176
+
186
177
/// <summary>
187
178
/// Gets the write timeout.
188
179
/// </summary>
@@ -194,28 +185,6 @@ public TimeSpan? WriteTimeout
194
185
get { return _writeTimeout ; }
195
186
}
196
187
197
- //TODO Add xml docs
198
- /// <summary>
199
- ///
200
- /// </summary>
201
- public string ProxyHost => _proxyHost ;
202
- /// <summary>
203
- ///
204
- /// </summary>
205
- public int ? ProxyPort => _proxyPort ;
206
- /// <summary>
207
- ///
208
- /// </summary>
209
- public string ProxyUsername => _proxyUsername ;
210
- /// <summary>
211
- ///
212
- /// </summary>
213
- public string ProxyPassword => _proxyPassword ;
214
-
215
- //TODO We can decide to remove this
216
- internal bool UseProxy => ! string . IsNullOrEmpty ( _proxyHost ) && _proxyPort . HasValue ;
217
-
218
-
219
188
// methods
220
189
/// <summary>
221
190
/// Returns a new TcpStreamSettings instance with some settings changed.
@@ -226,11 +195,8 @@ public TimeSpan? WriteTimeout
226
195
/// <param name="receiveBufferSize">Size of the receive buffer.</param>
227
196
/// <param name="sendBufferSize">Size of the send buffer.</param>
228
197
/// <param name="socketConfigurator">The socket configurator.</param>
198
+ /// <param name="socks5ProxySettings">The SOCKS5 proxy settings.</param>
229
199
/// <param name="writeTimeout">The write timeout.</param>
230
- /// <param name="proxyHost"> //TODO Add docs</param>
231
- /// <param name="proxyPort"></param>
232
- /// <param name="proxyUsername"></param>
233
- /// <param name="proxyPassword"></param>
234
200
/// <returns>A new TcpStreamSettings instance.</returns>
235
201
public TcpStreamSettings With (
236
202
Optional < AddressFamily > addressFamily = default ( Optional < AddressFamily > ) ,
@@ -240,10 +206,7 @@ public TcpStreamSettings With(
240
206
Optional < int > sendBufferSize = default ( Optional < int > ) ,
241
207
Optional < Action < Socket > > socketConfigurator = default ( Optional < Action < Socket > > ) ,
242
208
Optional < TimeSpan ? > writeTimeout = default ( Optional < TimeSpan ? > ) ,
243
- Optional < string > proxyHost = default ( Optional < string > ) ,
244
- Optional < int ? > proxyPort = default ( Optional < int ? > ) ,
245
- Optional < string > proxyUsername = default ( Optional < string > ) ,
246
- Optional < string > proxyPassword = default ( Optional < string > ) )
209
+ Optional < Socks5ProxySettings > socks5ProxySettings = default ( Optional < Socks5ProxySettings > ) )
247
210
{
248
211
return new TcpStreamSettings (
249
212
addressFamily : addressFamily . WithDefault ( _addressFamily ) ,
@@ -252,11 +215,8 @@ public TcpStreamSettings With(
252
215
receiveBufferSize : receiveBufferSize . WithDefault ( _receiveBufferSize ) ,
253
216
sendBufferSize : sendBufferSize . WithDefault ( _sendBufferSize ) ,
254
217
socketConfigurator : socketConfigurator . WithDefault ( _socketConfigurator ) ,
255
- writeTimeout : writeTimeout . WithDefault ( _writeTimeout ) ,
256
- proxyHost : proxyHost . WithDefault ( _proxyHost ) ,
257
- proxyPort : proxyPort . WithDefault ( _proxyPort ) ,
258
- proxyUsername : proxyUsername . WithDefault ( _proxyUsername ) ,
259
- proxyPassword : proxyPassword . WithDefault ( _proxyPassword ) ) ;
218
+ socks5ProxySettings : socks5ProxySettings . WithDefault ( _socks5ProxySettings ) ,
219
+ writeTimeout : writeTimeout . WithDefault ( _writeTimeout ) ) ;
260
220
}
261
221
}
262
222
}
0 commit comments