mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-15 00:15:15 +08:00
Fix wrong usage of client session items for undelivered messages.
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
* [Server] Session takeover and keep alive timeout are now properly set in DISCONNECT packet.
|
||||
* [Server] Fixed bug in PubRel packet generation (MQTTv5 only).
|
||||
* [Server] Improved message processing performance (+ ~5%).
|
||||
* [Server] Fix wrong usage of client session items for undelivered messages.
|
||||
</releaseNotes>
|
||||
<copyright>Copyright Christian Kratky 2016-2020</copyright>
|
||||
<tags>MQTT Message Queue Telemetry Transport MQTTClient MQTTServer Server MQTTBroker Broker NETStandard IoT InternetOfThings Messaging Hardware Arduino Sensor Actuator M2M ESP Smart Home Cities Automation Xamarin Blazor</tags>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace MQTTnet
|
||||
{
|
||||
public class MqttApplicationMessageReceivedEventArgs : EventArgs
|
||||
public sealed class MqttApplicationMessageReceivedEventArgs : EventArgs
|
||||
{
|
||||
public MqttApplicationMessageReceivedEventArgs(string clientId, MqttApplicationMessage applicationMessage)
|
||||
{
|
||||
|
||||
@@ -287,21 +287,21 @@ namespace MQTTnet.Server
|
||||
return;
|
||||
}
|
||||
|
||||
var sender = queuedApplicationMessage.Sender;
|
||||
var senderClientId = sender?.ClientId ?? _options.ClientId;
|
||||
var clientConnection = queuedApplicationMessage.Sender;
|
||||
var senderClientId = clientConnection?.ClientId ?? _options.ClientId;
|
||||
var applicationMessage = queuedApplicationMessage.ApplicationMessage;
|
||||
|
||||
var interceptor = _options.ApplicationMessageInterceptor;
|
||||
if (interceptor != null)
|
||||
{
|
||||
var interceptorContext = await InterceptApplicationMessageAsync(interceptor, sender, applicationMessage).ConfigureAwait(false);
|
||||
var interceptorContext = await InterceptApplicationMessageAsync(interceptor, clientConnection, applicationMessage).ConfigureAwait(false);
|
||||
if (interceptorContext != null)
|
||||
{
|
||||
if (interceptorContext.CloseConnection)
|
||||
{
|
||||
if (sender != null)
|
||||
if (clientConnection != null)
|
||||
{
|
||||
await sender.StopAsync(MqttDisconnectReasonCode.NormalDisconnection).ConfigureAwait(false);
|
||||
await clientConnection.StopAsync(MqttDisconnectReasonCode.NormalDisconnection).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,7 +343,8 @@ namespace MQTTnet.Server
|
||||
return;
|
||||
}
|
||||
|
||||
await undeliveredMessageInterceptor.InterceptApplicationMessagePublishAsync(new MqttApplicationMessageInterceptorContext(senderClientId, sender?.Session?.Items, applicationMessage));
|
||||
// The delegate signature is the same as for regular message interceptor. So the call is fine and just uses a different interceptor.
|
||||
await InterceptApplicationMessageAsync(undeliveredMessageInterceptor, clientConnection, applicationMessage).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
@@ -427,12 +428,12 @@ namespace MQTTnet.Server
|
||||
}
|
||||
}
|
||||
|
||||
async Task<MqttApplicationMessageInterceptorContext> InterceptApplicationMessageAsync(IMqttServerApplicationMessageInterceptor interceptor, MqttClientConnection senderConnection, MqttApplicationMessage applicationMessage)
|
||||
async Task<MqttApplicationMessageInterceptorContext> InterceptApplicationMessageAsync(IMqttServerApplicationMessageInterceptor interceptor, MqttClientConnection clientConnection, MqttApplicationMessage applicationMessage)
|
||||
{
|
||||
string senderClientId;
|
||||
IDictionary<object, object> sessionItems;
|
||||
|
||||
var messageIsFromServer = senderConnection == null;
|
||||
var messageIsFromServer = clientConnection == null;
|
||||
if (messageIsFromServer)
|
||||
{
|
||||
senderClientId = _options.ClientId;
|
||||
@@ -440,8 +441,8 @@ namespace MQTTnet.Server
|
||||
}
|
||||
else
|
||||
{
|
||||
senderClientId = senderConnection.ClientId;
|
||||
sessionItems = senderConnection.Session.Items;
|
||||
senderClientId = clientConnection.ClientId;
|
||||
sessionItems = clientConnection.Session.Items;
|
||||
}
|
||||
|
||||
var interceptorContext = new MqttApplicationMessageInterceptorContext(senderClientId, sessionItems, applicationMessage);
|
||||
|
||||
Reference in New Issue
Block a user