From ff22c34bb2342de52c25dc794bdcb6dada987c64 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Fri, 12 Jul 2019 20:36:46 +0200 Subject: [PATCH] Add first classes for persisted session support. --- Source/MQTTnet/Server/IMqttServerOptions.cs | 4 +++- .../Server/IMqttServerPersistedSession.cs | 22 +++++++++++++++++++ .../IMqttServerPersistedSessionsStorage.cs | 11 ++++++++++ Source/MQTTnet/Server/MqttClientConnection.cs | 2 +- .../Server/MqttClientSubscriptionsManager.cs | 8 +++---- 5 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 Source/MQTTnet/Server/IMqttServerPersistedSession.cs create mode 100644 Source/MQTTnet/Server/IMqttServerPersistedSessionsStorage.cs diff --git a/Source/MQTTnet/Server/IMqttServerOptions.cs b/Source/MQTTnet/Server/IMqttServerOptions.cs index 3a24289..7c5fde4 100644 --- a/Source/MQTTnet/Server/IMqttServerOptions.cs +++ b/Source/MQTTnet/Server/IMqttServerOptions.cs @@ -21,6 +21,8 @@ namespace MQTTnet.Server MqttServerTcpEndpointOptions DefaultEndpointOptions { get; } MqttServerTlsTcpEndpointOptions TlsEndpointOptions { get; } - IMqttServerStorage Storage { get; } + IMqttServerStorage Storage { get; } + + } } \ No newline at end of file diff --git a/Source/MQTTnet/Server/IMqttServerPersistedSession.cs b/Source/MQTTnet/Server/IMqttServerPersistedSession.cs new file mode 100644 index 0000000..18f7165 --- /dev/null +++ b/Source/MQTTnet/Server/IMqttServerPersistedSession.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; + +namespace MQTTnet.Server +{ + public interface IMqttServerPersistedSession + { + string ClientId { get; } + + IDictionary Items { get; } + + IList Subscriptions { get; } + + MqttApplicationMessage WillMessage { get; } + + uint? WillDelayInterval { get; } + + DateTime? SessionExpiryTimestamp { get; } + + IList PendingApplicationMessages { get; } + } +} diff --git a/Source/MQTTnet/Server/IMqttServerPersistedSessionsStorage.cs b/Source/MQTTnet/Server/IMqttServerPersistedSessionsStorage.cs new file mode 100644 index 0000000..fa2a4cb --- /dev/null +++ b/Source/MQTTnet/Server/IMqttServerPersistedSessionsStorage.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace MQTTnet.Server +{ + public interface IMqttServerPersistedSessionsStorage + { + Task> LoadPersistedSessionsAsync(); + } +} diff --git a/Source/MQTTnet/Server/MqttClientConnection.cs b/Source/MQTTnet/Server/MqttClientConnection.cs index a34f28b..e71d1a8 100644 --- a/Source/MQTTnet/Server/MqttClientConnection.cs +++ b/Source/MQTTnet/Server/MqttClientConnection.cs @@ -229,7 +229,7 @@ namespace MQTTnet.Server } else { - _logger.Error(exception, "Client '{0}': Unhandled exception while receiving client packets.", ClientId); + _logger.Error(exception, "Client '{0}': Error while receiving client packets.", ClientId); } StopInternal(); diff --git a/Source/MQTTnet/Server/MqttClientSubscriptionsManager.cs b/Source/MQTTnet/Server/MqttClientSubscriptionsManager.cs index 59eafe5..c84a018 100644 --- a/Source/MQTTnet/Server/MqttClientSubscriptionsManager.cs +++ b/Source/MQTTnet/Server/MqttClientSubscriptionsManager.cs @@ -9,7 +9,7 @@ namespace MQTTnet.Server { public class MqttClientSubscriptionsManager { - private readonly Dictionary _subscriptions = new Dictionary(); + private readonly Dictionary _subscriptions = new Dictionary(); private readonly MqttClientSession _clientSession; private readonly IMqttServerOptions _serverOptions; private readonly MqttServerEventDispatcher _eventDispatcher; @@ -64,7 +64,7 @@ namespace MQTTnet.Server { lock (_subscriptions) { - _subscriptions[finalTopicFilter.Topic] = finalTopicFilter.QualityOfServiceLevel; + _subscriptions[finalTopicFilter.Topic] = finalTopicFilter; } await _eventDispatcher.HandleClientSubscribedTopicAsync(_clientSession.ClientId, finalTopicFilter).ConfigureAwait(false); @@ -90,7 +90,7 @@ namespace MQTTnet.Server { lock (_subscriptions) { - _subscriptions[topicFilter.Topic] = topicFilter.QualityOfServiceLevel; + _subscriptions[topicFilter.Topic] = topicFilter; } await _eventDispatcher.HandleClientSubscribedTopicAsync(_clientSession.ClientId, topicFilter).ConfigureAwait(false); @@ -158,7 +158,7 @@ namespace MQTTnet.Server continue; } - qosLevels.Add(subscription.Value); + qosLevels.Add(subscription.Value.QualityOfServiceLevel); } }