Skip to content

Commit

Permalink
Merge pull request #541 from lable/master
Browse files Browse the repository at this point in the history
特殊处理 ::1
  • Loading branch information
maikebing committed Dec 1, 2021
2 parents a17b31a + e06897a commit 0871210
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions IoTSharp/Handlers/MQTTServerHandler.cs
Expand Up @@ -446,8 +446,19 @@ internal void Server_ClientConnectionValidator(object sender, MqttServerClientCo
using (var _dbContextcv = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>())
{
MqttConnectionValidatorContext obj = e.Context;
Uri uri = new Uri("mqtt://" + obj.Endpoint);
if (uri.IsLoopback && !string.IsNullOrEmpty(e.Context.ClientId) && e.Context.ClientId == _mcsetting.MqttBroker && !string.IsNullOrEmpty(e.Context.Username) && e.Context.Username == _mcsetting.UserName && e.Context.Password == _mcsetting.Password)

// jy 特殊处理 ::1
var isLoopback = false;
if (obj.Endpoint?.StartsWith("::1") == true)
{
isLoopback = true;
}
else
{
Uri uri = new Uri("mqtt://" + obj.Endpoint);
isLoopback = uri.IsLoopback;
}
if (isLoopback && !string.IsNullOrEmpty(e.Context.ClientId) && e.Context.ClientId == _mcsetting.MqttBroker && !string.IsNullOrEmpty(e.Context.Username) && e.Context.Username == _mcsetting.UserName && e.Context.Password == _mcsetting.Password)
{
e.Context.ReasonCode = MQTTnet.Protocol.MqttConnectReasonCode.Success;
}
Expand Down

0 comments on commit 0871210

Please sign in to comment.