Skip to content

Commit ca06495

Browse files
committed
Change DndEndPoint to EndPoint
1 parent 475a789 commit ca06495

File tree

7 files changed

+140
-140
lines changed

7 files changed

+140
-140
lines changed

Enyim.Caching/Configuration/IMemcachedClientConfiguration.cs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,44 @@
55

66
namespace Enyim.Caching.Configuration
77
{
8-
/// <summary>
9-
/// Defines an interface for configuring the <see cref="T:MemcachedClient"/>.
10-
/// </summary>
11-
public interface IMemcachedClientConfiguration
12-
{
13-
/// <summary>
14-
/// Gets a list of <see cref="T:IPEndPoint"/> each representing a Memcached server in the pool.
15-
/// </summary>
16-
IList<DnsEndPoint> Servers { get; }
8+
/// <summary>
9+
/// Defines an interface for configuring the <see cref="T:MemcachedClient"/>.
10+
/// </summary>
11+
public interface IMemcachedClientConfiguration
12+
{
13+
/// <summary>
14+
/// Gets a list of <see cref="T:IPEndPoint"/> each representing a Memcached server in the pool.
15+
/// </summary>
16+
IList<EndPoint> Servers { get; }
1717

18-
/// <summary>
19-
/// Gets the configuration of the socket pool.
20-
/// </summary>
21-
ISocketPoolConfiguration SocketPool { get; }
18+
/// <summary>
19+
/// Gets the configuration of the socket pool.
20+
/// </summary>
21+
ISocketPoolConfiguration SocketPool { get; }
2222

23-
/// <summary>
24-
/// Gets the authentication settings.
25-
/// </summary>
26-
IAuthenticationConfiguration Authentication { get; }
23+
/// <summary>
24+
/// Gets the authentication settings.
25+
/// </summary>
26+
IAuthenticationConfiguration Authentication { get; }
2727

28-
/// <summary>
29-
/// Creates an <see cref="T:Enyim.Caching.Memcached.IMemcachedKeyTransformer"/> instance which will be used to convert item keys for Memcached.
30-
/// </summary>
31-
IMemcachedKeyTransformer CreateKeyTransformer();
28+
/// <summary>
29+
/// Creates an <see cref="T:Enyim.Caching.Memcached.IMemcachedKeyTransformer"/> instance which will be used to convert item keys for Memcached.
30+
/// </summary>
31+
IMemcachedKeyTransformer CreateKeyTransformer();
3232

33-
/// <summary>
34-
/// Creates an <see cref="T:Enyim.Caching.Memcached.IMemcachedNodeLocator"/> instance which will be used to assign items to Memcached nodes.
35-
/// </summary>
36-
IMemcachedNodeLocator CreateNodeLocator();
33+
/// <summary>
34+
/// Creates an <see cref="T:Enyim.Caching.Memcached.IMemcachedNodeLocator"/> instance which will be used to assign items to Memcached nodes.
35+
/// </summary>
36+
IMemcachedNodeLocator CreateNodeLocator();
3737

38-
/// <summary>
39-
/// Creates an <see cref="T:Enyim.Caching.Memcached.ITranscoder"/> instance which will be used to serialize or deserialize items.
40-
/// </summary>
41-
ITranscoder CreateTranscoder();
38+
/// <summary>
39+
/// Creates an <see cref="T:Enyim.Caching.Memcached.ITranscoder"/> instance which will be used to serialize or deserialize items.
40+
/// </summary>
41+
ITranscoder CreateTranscoder();
4242

43-
IServerPool CreatePool();
43+
IServerPool CreatePool();
4444

45-
}
45+
}
4646
}
4747

4848
#region [ License information ]

Enyim.Caching/Configuration/MemcachedClientConfiguration.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,30 +172,29 @@ public MemcachedClientConfiguration(
172172

173173
private void ConfigureServers(MemcachedClientOptions options)
174174
{
175-
Servers = new List<DnsEndPoint>();
175+
Servers = new List<EndPoint>();
176176
foreach (var server in options.Servers)
177177
{
178178
if (!IPAddress.TryParse(server.Address, out var address))
179179
{
180-
var ip = Dns.GetHostAddresses(server.Address)
181-
.FirstOrDefault(i => i.AddressFamily == AddressFamily.InterNetwork)?.ToString();
180+
address = Dns.GetHostAddresses(server.Address)
181+
.FirstOrDefault(i => i.AddressFamily == AddressFamily.InterNetwork);
182182

183-
if (ip == null)
183+
if (address == null)
184184
{
185185
_logger.LogError($"Could not resolve host '{server.Address}'.");
186186
}
187187
else
188188
{
189-
_logger.LogInformation($"Memcached server address - {server.Address }({ip}):{server.Port}");
190-
server.Address = ip;
189+
_logger.LogInformation($"Memcached server address - {address}");
191190
}
192191
}
193192
else
194193
{
195194
_logger.LogInformation($"Memcached server address - {server.Address }:{server.Port}");
196195
}
197196

198-
Servers.Add(new DnsEndPoint(server.Address, server.Port));
197+
Servers.Add(new IPEndPoint(address, server.Port));
199198
}
200199
}
201200

@@ -221,7 +220,7 @@ public void AddServer(string host, int port)
221220
/// <summary>
222221
/// Gets a list of <see cref="T:IPEndPoint"/> each representing a Memcached server in the pool.
223222
/// </summary>
224-
public IList<DnsEndPoint> Servers { get; private set; }
223+
public IList<EndPoint> Servers { get; private set; }
225224

226225
/// <summary>
227226
/// Gets the configuration of the socket pool.
@@ -278,7 +277,7 @@ public ITranscoder Transcoder
278277

279278
#region [ interface ]
280279

281-
IList<System.Net.DnsEndPoint> IMemcachedClientConfiguration.Servers
280+
IList<EndPoint> IMemcachedClientConfiguration.Servers
282281
{
283282
get { return this.Servers; }
284283
}

Enyim.Caching/Memcached/DefaultServerPool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public DefaultServerPool(
4848
catch { }
4949
}
5050

51-
protected virtual IMemcachedNode CreateNode(DnsEndPoint endpoint)
51+
protected virtual IMemcachedNode CreateNode(EndPoint endpoint)
5252
{
5353
return new MemcachedNode(endpoint, this.configuration.SocketPool, _logger);
5454
}

Enyim.Caching/Memcached/MemcachedNode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ public class MemcachedNode : IMemcachedNode
2727

2828
private bool isDisposed;
2929

30-
private readonly DnsEndPoint endPoint;
30+
private readonly EndPoint endPoint;
3131
private readonly ISocketPoolConfiguration config;
3232
private InternalPoolImpl internalPoolImpl;
3333
private bool isInitialized;
3434

3535
public MemcachedNode(
36-
DnsEndPoint endpoint,
36+
EndPoint endpoint,
3737
ISocketPoolConfiguration socketPoolConfig,
3838
ILogger logger)
3939
{
@@ -289,7 +289,7 @@ public IPooledSocketResult Acquire()
289289
var result = new PooledSocketResult();
290290
var message = string.Empty;
291291

292-
if (_isDebugEnabled) _logger.LogDebug("Acquiring stream from pool. " + this.endPoint);
292+
if (_isDebugEnabled) _logger.LogDebug("Acquiring stream from pool on node " + this.endPoint);
293293

294294
if (!this.isAlive || this.isDisposed)
295295
{

Enyim.Caching/Memcached/PooledSocket.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public partial class PooledSocket : IDisposable
2424
private Stream inputStream;
2525
private AsyncSocketHelper helper;
2626

27-
public PooledSocket(DnsEndPoint endpoint, TimeSpan connectionTimeout, TimeSpan receiveTimeout, ILogger logger)
27+
public PooledSocket(EndPoint endpoint, TimeSpan connectionTimeout, TimeSpan receiveTimeout, ILogger logger)
2828
{
2929
_logger = logger;
3030

@@ -46,7 +46,7 @@ public PooledSocket(DnsEndPoint endpoint, TimeSpan connectionTimeout, TimeSpan r
4646

4747
if (!ConnectWithTimeout(socket, endpoint, timeout))
4848
{
49-
throw new TimeoutException($"Could not connect to {endpoint.Host}:{endpoint.Port}.");
49+
throw new TimeoutException($"Could not connect to {endpoint}.");
5050
}
5151

5252
this.socket = socket;
@@ -55,19 +55,21 @@ public PooledSocket(DnsEndPoint endpoint, TimeSpan connectionTimeout, TimeSpan r
5555
this.inputStream = new NetworkStream(socket);
5656
}
5757

58-
private bool ConnectWithTimeout(Socket socket, DnsEndPoint endpoint, int timeout)
58+
private bool ConnectWithTimeout(Socket socket, EndPoint endpoint, int timeout)
5959
{
6060
bool connected = false;
6161
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
6262
var args = new SocketAsyncEventArgs();
6363

6464
//Workaround for https://github.com/dotnet/corefx/issues/26840
65-
if (!IPAddress.TryParse(endpoint.Host, out var address))
65+
if (endpoint is DnsEndPoint)
6666
{
67-
address = Dns.GetHostAddresses(endpoint.Host)
68-
.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork);
67+
var dnsEndPoint = (DnsEndPoint)endpoint;
68+
var address = Dns.GetHostAddresses(dnsEndPoint.Host).FirstOrDefault(ip =>
69+
ip.AddressFamily == AddressFamily.InterNetwork);
6970
if (address == null)
70-
throw new ArgumentException(String.Format("Could not resolve host '{0}'.", endpoint.Host));
71+
throw new ArgumentException(String.Format("Could not resolve host '{0}'.", endpoint));
72+
endpoint = new IPEndPoint(address, dnsEndPoint.Port);
7173
}
7274

7375
//Learn from https://github.com/dotnet/corefx/blob/release/2.2/src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNITcpHandle.cs#L180
@@ -82,7 +84,7 @@ void Cancel()
8284
}
8385
cts.Token.Register(Cancel);
8486

85-
socket.Connect(address, endpoint.Port);
87+
socket.Connect(endpoint);
8688
if (socket.Connected)
8789
{
8890
connected = true;

Enyim.Caching/Memcached/Protocol/Binary/BinaryNode.cs

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -10,74 +10,73 @@
1010

1111
namespace Enyim.Caching.Memcached.Protocol.Binary
1212
{
13-
/// <summary>
14-
/// A node which is used by the BinaryPool. It implements the binary protocol's SASL auth. mechanism.
15-
/// </summary>
16-
public class BinaryNode : MemcachedNode
17-
{
13+
/// <summary>
14+
/// A node which is used by the BinaryPool. It implements the binary protocol's SASL auth. mechanism.
15+
/// </summary>
16+
public class BinaryNode : MemcachedNode
17+
{
1818
private readonly ILogger _logger;
19+
readonly ISaslAuthenticationProvider authenticationProvider;
1920

20-
ISaslAuthenticationProvider authenticationProvider;
21-
22-
public BinaryNode(
23-
DnsEndPoint endpoint,
24-
ISocketPoolConfiguration config,
21+
public BinaryNode(
22+
EndPoint endpoint,
23+
ISocketPoolConfiguration config,
2524
ISaslAuthenticationProvider authenticationProvider,
2625
ILogger logger)
27-
: base(endpoint, config, logger)
28-
{
29-
this.authenticationProvider = authenticationProvider;
26+
: base(endpoint, config, logger)
27+
{
28+
this.authenticationProvider = authenticationProvider;
3029
_logger = logger;
31-
}
30+
}
3231

33-
/// <summary>
34-
/// Authenticates the new socket before it is put into the pool.
35-
/// </summary>
36-
protected internal override PooledSocket CreateSocket()
37-
{
38-
var retval = base.CreateSocket();
32+
/// <summary>
33+
/// Authenticates the new socket before it is put into the pool.
34+
/// </summary>
35+
protected internal override PooledSocket CreateSocket()
36+
{
37+
var retval = base.CreateSocket();
3938

40-
if (this.authenticationProvider != null && !this.Auth(retval))
41-
{
42-
_logger.LogError("Authentication failed: " + this.EndPoint);
39+
if (this.authenticationProvider != null && !this.Auth(retval))
40+
{
41+
_logger.LogError("Authentication failed: " + this.EndPoint);
4342

44-
throw new SecurityException("auth failed: " + this.EndPoint);
45-
}
43+
throw new SecurityException("auth failed: " + this.EndPoint);
44+
}
4645

47-
return retval;
48-
}
46+
return retval;
47+
}
4948

50-
/// <summary>
51-
/// Implements memcached's SASL auth sequence. (See the protocol docs for more details.)
52-
/// </summary>
53-
/// <param name="socket"></param>
54-
/// <returns></returns>
55-
private bool Auth(PooledSocket socket)
56-
{
57-
SaslStep currentStep = new SaslStart(this.authenticationProvider);
49+
/// <summary>
50+
/// Implements memcached's SASL auth sequence. (See the protocol docs for more details.)
51+
/// </summary>
52+
/// <param name="socket"></param>
53+
/// <returns></returns>
54+
private bool Auth(PooledSocket socket)
55+
{
56+
SaslStep currentStep = new SaslStart(this.authenticationProvider);
5857

59-
socket.Write(currentStep.GetBuffer());
58+
socket.Write(currentStep.GetBuffer());
6059

61-
while (!currentStep.ReadResponse(socket).Success)
62-
{
63-
// challenge-response authentication
64-
if (currentStep.StatusCode == 0x21)
65-
{
66-
currentStep = new SaslContinue(this.authenticationProvider, currentStep.Data);
67-
socket.Write(currentStep.GetBuffer());
68-
}
69-
else
70-
{
71-
_logger.LogWarning("Authentication failed, return code: 0x{0:x}", currentStep.StatusCode);
60+
while (!currentStep.ReadResponse(socket).Success)
61+
{
62+
// challenge-response authentication
63+
if (currentStep.StatusCode == 0x21)
64+
{
65+
currentStep = new SaslContinue(this.authenticationProvider, currentStep.Data);
66+
socket.Write(currentStep.GetBuffer());
67+
}
68+
else
69+
{
70+
_logger.LogWarning("Authentication failed, return code: 0x{0:x}", currentStep.StatusCode);
7271

73-
// invalid credentials or other error
74-
return false;
75-
}
76-
}
72+
// invalid credentials or other error
73+
return false;
74+
}
75+
}
7776

78-
return true;
79-
}
80-
}
77+
return true;
78+
}
79+
}
8180
}
8281

8382
#region [ License information ]

0 commit comments

Comments
 (0)