From 9fa5e2dc1f794d0a215db8cc642f84711cce28b4 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Wed, 4 Jul 2018 21:57:51 +0200 Subject: [PATCH] Add the adapter Endpoint to the connection validator. --- Source/MQTTnet/Server/MqttClientSessionsManager.cs | 7 ++++--- Source/MQTTnet/Server/MqttConnectionValidatorContext.cs | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Source/MQTTnet/Server/MqttClientSessionsManager.cs b/Source/MQTTnet/Server/MqttClientSessionsManager.cs index a41be4f..34080a0 100644 --- a/Source/MQTTnet/Server/MqttClientSessionsManager.cs +++ b/Source/MQTTnet/Server/MqttClientSessionsManager.cs @@ -212,7 +212,7 @@ namespace MQTTnet.Server // Switch to the required protocol version before sending any response. clientAdapter.PacketSerializer.ProtocolVersion = connectPacket.ProtocolVersion; - var connectReturnCode = ValidateConnection(connectPacket); + var connectReturnCode = ValidateConnection(connectPacket, clientAdapter); if (connectReturnCode != MqttConnectReturnCode.ConnectionAccepted) { await clientAdapter.SendPacketAsync( @@ -268,7 +268,7 @@ namespace MQTTnet.Server } } - private MqttConnectReturnCode ValidateConnection(MqttConnectPacket connectPacket) + private MqttConnectReturnCode ValidateConnection(MqttConnectPacket connectPacket, IMqttChannelAdapter clientAdapter) { if (_options.ConnectionValidator == null) { @@ -279,7 +279,8 @@ namespace MQTTnet.Server connectPacket.ClientId, connectPacket.Username, connectPacket.Password, - connectPacket.WillMessage); + connectPacket.WillMessage, + clientAdapter.Endpoint); _options.ConnectionValidator(context); return context.ReturnCode; diff --git a/Source/MQTTnet/Server/MqttConnectionValidatorContext.cs b/Source/MQTTnet/Server/MqttConnectionValidatorContext.cs index a24d795..5857862 100644 --- a/Source/MQTTnet/Server/MqttConnectionValidatorContext.cs +++ b/Source/MQTTnet/Server/MqttConnectionValidatorContext.cs @@ -4,12 +4,13 @@ namespace MQTTnet.Server { public class MqttConnectionValidatorContext { - public MqttConnectionValidatorContext(string clientId, string username, string password, MqttApplicationMessage willMessage) + public MqttConnectionValidatorContext(string clientId, string username, string password, MqttApplicationMessage willMessage, string endpoint) { ClientId = clientId; Username = username; Password = password; WillMessage = willMessage; + Endpoint = endpoint; } public string ClientId { get; } @@ -20,6 +21,8 @@ namespace MQTTnet.Server public MqttApplicationMessage WillMessage { get; } + public string Endpoint { get; } + public MqttConnectReturnCode ReturnCode { get; set; } = MqttConnectReturnCode.ConnectionAccepted; } }