Skip to content

Commit

Permalink
Update IClientFactory.Default.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeeLyn committed Apr 26, 2019
1 parent 7db7221 commit c40e06a
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/Uragano.Remoting/IClientFactory.Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ public async Task<IClient> CreateClientAsync(string serviceName, ServiceNodeInfo
var pipeline = ch.Pipeline;
if (nodeInfo.EnableTls)
{

var cert = ClientSettings?.ServicesCert?.FirstOrDefault(p => p.Key == serviceName).Value ?? ClientSettings?.DefaultCert;
if (cert == null)
{
Logger.LogCritical($"Service {serviceName}[{nodeInfo.Address}:{nodeInfo.Port}] has TLS enabled, please configure the certificate.");
Logger.LogError($"Service {serviceName}[{nodeInfo.Address}:{nodeInfo.Port}] has TLS enabled, please configure the certificate.");
throw new InvalidOperationException(
$"Service {serviceName}[{nodeInfo.Address}:{nodeInfo.Port}] has TLS enabled, please configure the certificate.");
}
Expand All @@ -100,10 +99,10 @@ public async Task<IClient> CreateClientAsync(string serviceName, ServiceNodeInfo
return new SslStream(stream, true,
(sender, certificate, chain, errors) =>
{
var success = SslPolicyErrors.None == errors;
if (!success)
var successful = SslPolicyErrors.None == errors;
if (!successful)
Logger.LogError("The remote certificate is invalid according to the validation procedure:{0}.", errors);
return success;
return successful;
});
}, new ClientTlsSettings(targetHost)));
}
Expand All @@ -113,7 +112,7 @@ public async Task<IClient> CreateClientAsync(string serviceName, ServiceNodeInfo
pipeline.AddLast(new LengthFieldBasedFrameDecoder(int.MaxValue, 0, 4, 0, 4));
pipeline.AddLast(new MessageDecoder<IServiceResult>(Codec));
pipeline.AddLast(new MessageEncoder<IInvokeMessage>(Codec));
pipeline.AddLast(new ClientMessageHandler(this, Logger));
pipeline.AddLast(new ClientMessageHandler(this));
}));

EndPoint endPoint;
Expand Down Expand Up @@ -145,12 +144,9 @@ internal class ClientMessageHandler : ChannelHandlerAdapter

private IClientFactory ClientFactory { get; }

private ILogger Logger { get; }

public ClientMessageHandler(IClientFactory clientFactory, ILogger logger)
public ClientMessageHandler(IClientFactory clientFactory)
{
ClientFactory = clientFactory;
Logger = logger;
}

public override void ChannelRead(IChannelHandlerContext context, object message)
Expand All @@ -162,7 +158,7 @@ public override void ChannelRead(IChannelHandlerContext context, object message)

public override void ChannelInactive(IChannelHandlerContext context)
{
Logger.LogCritical("The status of client {0} is unavailable,Please check the network and certificate!", context.Channel.RemoteAddress);
//Logger.LogCritical("The status of client {0} is unavailable,Please check the network and certificate!", context.Channel.RemoteAddress);
var ctx = context.Channel.GetAttribute(TransportContextAttributeKey).Get();
ClientFactory.RemoveClient(ctx.Host, ctx.Port).GetAwaiter().GetResult();
base.ChannelInactive(context);
Expand Down

0 comments on commit c40e06a

Please sign in to comment.