From a72516fdcc20105e5a808242acf63cc747620633 Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 25 Nov 2017 19:50:31 +0100 Subject: [PATCH 01/22] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 57dfce2..92520be 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ MQTTnet is a high performance .NET library for MQTT based communication. It prov * .NET Standard 1.3+ * .NET Core 1.1+ * .NET Core App 1.1+ -* Universal Windows Platform (UWP) 10.0.10240+ (x86, x64, ARM, AnyCPU, WIndows IoT Core) +* Universal Windows Platform (UWP) 10.0.10240+ (x86, x64, ARM, AnyCPU, Windows 10 IoT Core) * .NET Framework 4.5.2+ (x86, x64, AnyCPU) * Mono 5.2+ * Xamarin.Android 7.5+ From f9d67e2cd2420e3c4a8c445b1ca962bb5f49e354 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Sat, 25 Nov 2017 19:55:26 +0100 Subject: [PATCH 02/22] Merge proces, enable signing of the assembly. --- .gitignore | 2 ++ Build/MQTTnet.nuspec | 14 ++++------- .../ApplicationBuilderExtensions.cs | 2 +- .../MQTTnet.AspnetCore/MqttHostedServer.cs | 6 ++--- .../MqttWebSocketServerAdapter.cs | 8 +++--- .../MqttWebSocketServerChannel.cs | 2 +- .../ServiceCollectionExtensions.cs | 6 ++--- .../Adapter/IMqttChannelAdapter.cs | 6 ++--- .../Adapter/IMqttServerAdapter.cs | 4 +-- .../Adapter/MqttChannelAdapter.cs | 16 ++++++------ .../Adapter/MqttChannelAdapterExtensions.cs | 4 +-- .../Adapter/MqttConnectingFailedException.cs | 6 ++--- ...qttServerAdapterClientAcceptedEventArgs.cs | 2 +- .../Adapter/ReceivedMqttPacket.cs | 4 +-- .../ApplicationMessagePublisherExtensions.cs | 2 +- .../Channel/IMqttChannel.cs | 6 ++--- .../Client/IMqttClient.cs | 3 +-- .../Client/IMqttClientAdapterFactory.cs | 6 ++--- .../Client/IMqttClientChannelOptions.cs | 2 +- .../Client/IMqttClientCredentials.cs | 2 +- .../Client/IMqttClientFactory.cs | 6 ++--- .../Client/IMqttClientOptions.cs | 4 +-- .../MQTTnet.NetStandard}/Client/MqttClient.cs | 16 ++++++------ .../Client/MqttClientConnectResult.cs | 2 +- .../Client/MqttClientConnectedEventArgs.cs | 2 +- .../Client/MqttClientCredentials.cs | 2 +- .../Client/MqttClientDisconnectedEventArgs.cs | 2 +- .../Client/MqttClientExtensions.cs | 2 +- .../Client/MqttClientOptions.cs | 4 +-- .../Client/MqttClientOptionsBuilder.cs | 4 +-- .../Client/MqttClientTcpOptions.cs | 2 +- .../Client/MqttClientTcpOptionsExtensions.cs | 2 +- .../Client/MqttClientTlsOptions.cs | 2 +- .../Client/MqttClientWebSocketOptions.cs | 2 +- .../Client/MqttPacketDispatcher.cs | 10 ++++---- .../Client/MqttSubscribeResult.cs | 5 ++-- .../Diagnostics/IMqttNetLogger.cs | 2 +- .../Diagnostics/MqttNetGlobalLogger.cs | 4 +-- .../Diagnostics/MqttNetLogLevel.cs | 2 +- .../Diagnostics/MqttNetLogMessage.cs | 2 +- .../MqttNetLogMessagePublishedEventArgs.cs | 2 +- .../Diagnostics/MqttNetLogger.cs | 6 ++--- .../TargetFrameworkInfoProvider.cs | 2 +- .../Exceptions/MqttCommunicationException.cs | 2 +- .../MqttCommunicationTimedOutException.cs | 2 +- .../MqttProtocolViolationException.cs | 2 +- .../IApplicationMessagePublisher.cs | 2 +- .../IApplicationMessageReceiver.cs | 3 +-- .../MqttClientAdapterFactory.cs | 8 +++--- .../Implementations/MqttServerAdapter.Uwp.cs | 8 +++--- .../Implementations/MqttServerAdapter.cs | 8 +++--- .../Implementations/MqttTcpChannel.Uwp.cs | 4 +-- .../Implementations/MqttTcpChannel.cs | 4 +-- .../Implementations/MqttWebSocketChannel.cs | 6 ++--- .../Implementations/WebSocketStream.cs | 2 +- .../MqttApplicationMessageExtensions.cs | 4 +-- .../Internal/TaskExtensions.cs | 4 +-- .../MQTTnet.Netstandard.csproj | 6 ++--- .../ManagedClient/IManagedMqttClient.cs | 4 +-- .../IManagedMqttClientOptions.cs | 4 +-- .../IManagedMqttClientStorage.cs | 2 +- .../ManagedClient/ManagedMqttClient.cs | 10 ++++---- .../ManagedMqttClientExtensions.cs | 2 +- .../ManagedClient/ManagedMqttClientOptions.cs | 4 +-- .../ManagedMqttClientOptionsBuilder.cs | 4 +-- .../ManagedMqttClientStorageManager.cs | 2 +- .../ManagedClient/ReconnectionResult.cs | 2 +- .../MqttApplicationMessage.cs | 4 +-- .../MqttApplicationMessageBuilder.cs | 6 ++--- ...MqttApplicationMessageReceivedEventArgs.cs | 2 +- Frameworks/MQTTnet.NetStandard/MqttFactory.cs | 10 ++++---- .../Packets/IMqttPacketWithIdentifier.cs | 2 +- .../Packets/MqttBasePacket.cs | 2 +- .../Packets/MqttBasePublishPacket.cs | 2 +- .../Packets/MqttConnAckPacket.cs | 4 +-- .../Packets/MqttConnectPacket.cs | 4 +-- .../Packets/MqttDisconnectPacket.cs | 2 +- .../Packets/MqttPacketExtensions.cs | 2 +- .../Packets/MqttPacketHeader.cs | 4 +-- .../Packets/MqttPingReqPacket.cs | 2 +- .../Packets/MqttPingRespPacket.cs | 2 +- .../Packets/MqttPubAckPacket.cs | 2 +- .../Packets/MqttPubCompPacket.cs | 2 +- .../Packets/MqttPubRecPacket.cs | 2 +- .../Packets/MqttPubRelPacket.cs | 2 +- .../Packets/MqttPublishPacket.cs | 4 +-- .../Packets/MqttSubAckPacket.cs | 4 +-- .../Packets/MqttSubscribePacket.cs | 2 +- .../Packets/MqttUnsubAckPacket.cs | 2 +- .../Packets/MqttUnsubscribe.cs | 2 +- .../Protocol/MqttConnectReturnCode.cs | 2 +- .../Protocol/MqttControlPacketType.cs | 2 +- .../Protocol/MqttQualityOfServiceLevel.cs | 2 +- .../Protocol/MqttSubscribeReturnCode.cs | 2 +- .../Serializer/ByteReader.cs | 2 +- .../Serializer/ByteWriter.cs | 2 +- .../Serializer/IMqttPacketSerializer.cs | 6 ++--- .../Serializer/MqttPacketReader.cs | 10 ++++---- .../Serializer/MqttPacketSerializer.cs | 10 ++++---- .../Serializer/MqttPacketWriter.cs | 6 ++--- .../Serializer/MqttProtocolVersion.cs | 2 +- .../Server/CheckSubscriptionsResult.cs | 4 +-- .../Server/ConnectedMqttClient.cs | 4 +-- .../Server/GetOrCreateClientSessionResult.cs | 2 +- .../Server/IMqttServer.cs | 2 +- .../Server/IMqttServerFactory.cs | 6 ++--- .../Server/IMqttServerStorage.cs | 2 +- ...qttApplicationMessageInterceptorContext.cs | 2 +- .../Server/MqttClientConnectedEventArgs.cs | 2 +- .../Server/MqttClientDisconnectedEventArgs.cs | 2 +- .../Server/MqttClientPendingMessagesQueue.cs | 12 ++++----- .../Server/MqttClientSession.cs | 18 ++++++------- .../Server/MqttClientSessionsManager.cs | 18 ++++++------- .../Server/MqttClientSubscribeResult.cs | 4 +-- .../Server/MqttClientSubscriptionsManager.cs | 6 ++--- .../Server/MqttConnectionValidatorContext.cs | 4 +-- .../Server/MqttRetainedMessagesManager.cs | 6 ++--- .../MQTTnet.NetStandard}/Server/MqttServer.cs | 8 +++--- .../MqttServerDefaultEndpointOptions.cs | 2 +- .../Server/MqttServerOptions.cs | 6 ++--- .../Server/MqttServerOptionsBuilder.cs | 6 ++--- .../Server/MqttServerOptionsExtensions.cs | 2 +- .../Server/MqttServerStartedEventArgs.cs | 2 +- .../Server/MqttServerTlsEndpointOptions.cs | 2 +- .../Server/MqttSubscribeResult.cs | 4 +-- .../MqttSubscriptionInterceptorContext.cs | 2 +- .../Server/MqttTopicFilterComparer.cs | 2 +- .../MQTTnet.NetStandard}/TopicFilter.cs | 4 +-- .../TopicFilterBuilder.cs | 6 ++--- MQTTnet.Core/MQTTnet.Core.csproj | 25 ------------------- MQTTnet.sln | 20 +-------------- Tests/MQTTnet.Core.Tests/ByteReaderTests.cs | 2 +- Tests/MQTTnet.Core.Tests/ByteWriterTests.cs | 2 +- Tests/MQTTnet.Core.Tests/ExtensionTests.cs | 4 +-- .../MqttApplicationMessageBuilderTests.cs | 2 +- .../MqttPacketReaderTests.cs | 2 +- .../MqttPacketSerializerTests.cs | 8 +++--- Tests/MQTTnet.Core.Tests/MqttServerTests.cs | 8 +++--- .../MqttSubscriptionsManagerTests.cs | 6 ++--- .../TestMqttCommunicationAdapter.cs | 6 ++--- .../TestMqttCommunicationAdapterFactory.cs | 6 ++--- .../TestMqttServerAdapter.cs | 12 ++++----- .../TopicFilterComparerTests.cs | 2 +- Tests/MQTTnet.TestApp.AspNetCore2/Startup.cs | 3 +-- Tests/MQTTnet.TestApp.NetCore/ClientTest.cs | 3 +-- .../ManagedClientTest.cs | 7 +++--- .../MqttNetConsoleLogger.cs | 8 +++--- .../PerformanceTest.cs | 9 +++---- Tests/MQTTnet.TestApp.NetCore/Program.cs | 8 +++--- Tests/MQTTnet.TestApp.NetCore/ServerTest.cs | 4 +-- .../JsonServerStorage.cs | 3 +-- .../MQTTnet.TestApp.UniversalWindows.csproj | 4 --- .../MainPage.xaml.cs | 15 ++++++----- 153 files changed, 327 insertions(+), 387 deletions(-) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Adapter/IMqttChannelAdapter.cs (85%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Adapter/IMqttServerAdapter.cs (82%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Adapter/MqttChannelAdapter.cs (96%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Adapter/MqttChannelAdapterExtensions.cs (89%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Adapter/MqttConnectingFailedException.cs (79%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Adapter/MqttServerAdapterClientAcceptedEventArgs.cs (93%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Adapter/ReceivedMqttPacket.cs (90%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/ApplicationMessagePublisherExtensions.cs (95%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Channel/IMqttChannel.cs (69%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Client/IMqttClient.cs (91%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Client/IMqttClientAdapterFactory.cs (64%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Client/IMqttClientChannelOptions.cs (77%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Client/IMqttClientCredentials.cs (78%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Client/IMqttClientFactory.cs (74%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Client/IMqttClientOptions.cs (88%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Client/MqttClient.cs (98%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Client/MqttClientConnectResult.cs (87%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Client/MqttClientConnectedEventArgs.cs (90%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Client/MqttClientCredentials.cs (83%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Client/MqttClientDisconnectedEventArgs.cs (90%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Client/MqttClientExtensions.cs (96%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Client/MqttClientOptions.cs (92%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Client/MqttClientOptionsBuilder.cs (98%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Client/MqttClientTcpOptions.cs (88%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Client/MqttClientTcpOptionsExtensions.cs (93%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Client/MqttClientTlsOptions.cs (92%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Client/MqttClientWebSocketOptions.cs (94%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Client/MqttPacketDispatcher.cs (96%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Client/MqttSubscribeResult.cs (79%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Diagnostics/IMqttNetLogger.cs (94%) rename MQTTnet.Core/Diagnostics/MqttNetGlobalLog.cs => Frameworks/MQTTnet.NetStandard/Diagnostics/MqttNetGlobalLogger.cs (86%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Diagnostics/MqttNetLogLevel.cs (74%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Diagnostics/MqttNetLogMessage.cs (95%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Diagnostics/MqttNetLogMessagePublishedEventArgs.cs (91%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Diagnostics/MqttNetLogger.cs (93%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Exceptions/MqttCommunicationException.cs (92%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Exceptions/MqttCommunicationTimedOutException.cs (73%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Exceptions/MqttProtocolViolationException.cs (86%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/IApplicationMessagePublisher.cs (90%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/IApplicationMessageReceiver.cs (78%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Internal/MqttApplicationMessageExtensions.cs (94%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Internal/TaskExtensions.cs (97%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/ManagedClient/IManagedMqttClient.cs (90%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/ManagedClient/IManagedMqttClientOptions.cs (77%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/ManagedClient/IManagedMqttClientStorage.cs (88%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/ManagedClient/ManagedMqttClient.cs (98%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/ManagedClient/ManagedMqttClientExtensions.cs (95%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/ManagedClient/ManagedMqttClientOptions.cs (83%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/ManagedClient/ManagedMqttClientOptionsBuilder.cs (95%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/ManagedClient/ManagedMqttClientStorageManager.cs (98%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/ManagedClient/ReconnectionResult.cs (74%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/MqttApplicationMessage.cs (94%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/MqttApplicationMessageBuilder.cs (97%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/MqttApplicationMessageReceivedEventArgs.cs (95%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Packets/IMqttPacketWithIdentifier.cs (76%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Packets/MqttBasePacket.cs (62%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Packets/MqttBasePublishPacket.cs (81%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Packets/MqttConnAckPacket.cs (85%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Packets/MqttConnectPacket.cs (91%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Packets/MqttDisconnectPacket.cs (83%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Packets/MqttPacketExtensions.cs (96%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Packets/MqttPacketHeader.cs (77%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Packets/MqttPingReqPacket.cs (83%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Packets/MqttPingRespPacket.cs (83%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Packets/MqttPubAckPacket.cs (83%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Packets/MqttPubCompPacket.cs (83%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Packets/MqttPubRecPacket.cs (83%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Packets/MqttPubRelPacket.cs (83%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Packets/MqttPublishPacket.cs (91%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Packets/MqttSubAckPacket.cs (91%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Packets/MqttSubscribePacket.cs (95%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Packets/MqttUnsubAckPacket.cs (89%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Packets/MqttUnsubscribe.cs (94%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Protocol/MqttConnectReturnCode.cs (91%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Protocol/MqttControlPacketType.cs (91%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Protocol/MqttQualityOfServiceLevel.cs (80%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Protocol/MqttSubscribeReturnCode.cs (84%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Serializer/ByteReader.cs (96%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Serializer/ByteWriter.cs (95%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Serializer/IMqttPacketSerializer.cs (72%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Serializer/MqttPacketReader.cs (95%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Serializer/MqttPacketSerializer.cs (99%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Serializer/MqttPacketWriter.cs (96%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Serializer/MqttProtocolVersion.cs (68%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/CheckSubscriptionsResult.cs (74%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/ConnectedMqttClient.cs (72%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/GetOrCreateClientSessionResult.cs (84%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/IMqttServer.cs (94%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/IMqttServerFactory.cs (72%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/IMqttServerStorage.cs (90%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/MqttApplicationMessageInterceptorContext.cs (81%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/MqttClientConnectedEventArgs.cs (91%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/MqttClientDisconnectedEventArgs.cs (91%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/MqttClientPendingMessagesQueue.cs (95%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/MqttClientSession.cs (97%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/MqttClientSessionsManager.cs (97%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/MqttClientSubscribeResult.cs (73%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/MqttClientSubscriptionsManager.cs (97%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/MqttConnectionValidatorContext.cs (91%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/MqttRetainedMessagesManager.cs (98%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/MqttServer.cs (98%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/MqttServerDefaultEndpointOptions.cs (83%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/MqttServerOptions.cs (90%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/MqttServerOptionsBuilder.cs (96%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/MqttServerOptionsExtensions.cs (96%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/MqttServerStartedEventArgs.cs (75%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/MqttServerTlsEndpointOptions.cs (85%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/MqttSubscribeResult.cs (73%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/MqttSubscriptionInterceptorContext.cs (93%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/Server/MqttTopicFilterComparer.cs (97%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/TopicFilter.cs (92%) rename {MQTTnet.Core => Frameworks/MQTTnet.NetStandard}/TopicFilterBuilder.cs (93%) delete mode 100644 MQTTnet.Core/MQTTnet.Core.csproj rename {Frameworks/MQTTnet.NetStandard/Diagnostics => Tests/MQTTnet.TestApp.NetCore}/MqttNetConsoleLogger.cs (88%) diff --git a/.gitignore b/.gitignore index 4372f8e..7c38d7d 100644 --- a/.gitignore +++ b/.gitignore @@ -291,3 +291,5 @@ __pycache__/ Build/nuget.exe *.js *.map + +*codeSigningKey.pfx diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec index 8dd284e..2ebe29d 100644 --- a/Build/MQTTnet.nuspec +++ b/Build/MQTTnet.nuspec @@ -2,7 +2,7 @@ MQTTnet - 2.5.3 + 2.6.0 Christian Kratky Christian Kratky https://github.com/chkr1011/MQTTnet/blob/master/LICENSE @@ -10,9 +10,9 @@ https://raw.githubusercontent.com/chkr1011/MQTTnet/master/Images/Logo_128x128.png false MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). - * [Core] Removed all dependencies to other libraries (BREAKING CHANGE!). -* [Core] Updated SDK libraries. -* [Client] Fixed broken support for WebSocketSecure connections (Thanks to @StAI). + * Merged projects. +* Added a strong name for the assembly. + Copyright Christian Kratky 2016-2017 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 @@ -46,23 +46,19 @@ + - - - - - diff --git a/Frameworks/MQTTnet.AspnetCore/ApplicationBuilderExtensions.cs b/Frameworks/MQTTnet.AspnetCore/ApplicationBuilderExtensions.cs index 831392d..5a25712 100644 --- a/Frameworks/MQTTnet.AspnetCore/ApplicationBuilderExtensions.cs +++ b/Frameworks/MQTTnet.AspnetCore/ApplicationBuilderExtensions.cs @@ -1,8 +1,8 @@ using System; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; -using MQTTnet.Core.Server; using System.Linq; +using MQTTnet.Server; namespace MQTTnet.AspNetCore { diff --git a/Frameworks/MQTTnet.AspnetCore/MqttHostedServer.cs b/Frameworks/MQTTnet.AspnetCore/MqttHostedServer.cs index a806105..7c7d304 100644 --- a/Frameworks/MQTTnet.AspnetCore/MqttHostedServer.cs +++ b/Frameworks/MQTTnet.AspnetCore/MqttHostedServer.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Hosting; -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Diagnostics; -using MQTTnet.Core.Server; +using MQTTnet.Adapter; +using MQTTnet.Diagnostics; +using MQTTnet.Server; namespace MQTTnet.AspNetCore { diff --git a/Frameworks/MQTTnet.AspnetCore/MqttWebSocketServerAdapter.cs b/Frameworks/MQTTnet.AspnetCore/MqttWebSocketServerAdapter.cs index 2781092..5af8b64 100644 --- a/Frameworks/MQTTnet.AspnetCore/MqttWebSocketServerAdapter.cs +++ b/Frameworks/MQTTnet.AspnetCore/MqttWebSocketServerAdapter.cs @@ -1,10 +1,10 @@ using System; using System.Net.WebSockets; using System.Threading.Tasks; -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Diagnostics; -using MQTTnet.Core.Serializer; -using MQTTnet.Core.Server; +using MQTTnet.Adapter; +using MQTTnet.Diagnostics; +using MQTTnet.Serializer; +using MQTTnet.Server; namespace MQTTnet.AspNetCore { diff --git a/Frameworks/MQTTnet.AspnetCore/MqttWebSocketServerChannel.cs b/Frameworks/MQTTnet.AspnetCore/MqttWebSocketServerChannel.cs index 55b4940..7325a5f 100644 --- a/Frameworks/MQTTnet.AspnetCore/MqttWebSocketServerChannel.cs +++ b/Frameworks/MQTTnet.AspnetCore/MqttWebSocketServerChannel.cs @@ -3,7 +3,7 @@ using System.IO; using System.Net.WebSockets; using System.Threading; using System.Threading.Tasks; -using MQTTnet.Core.Channel; +using MQTTnet.Channel; using MQTTnet.Implementations; namespace MQTTnet.AspNetCore diff --git a/Frameworks/MQTTnet.AspnetCore/ServiceCollectionExtensions.cs b/Frameworks/MQTTnet.AspnetCore/ServiceCollectionExtensions.cs index 236d44d..a6af6eb 100644 --- a/Frameworks/MQTTnet.AspnetCore/ServiceCollectionExtensions.cs +++ b/Frameworks/MQTTnet.AspnetCore/ServiceCollectionExtensions.cs @@ -1,9 +1,9 @@ using System; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Diagnostics; -using MQTTnet.Core.Server; +using MQTTnet.Adapter; +using MQTTnet.Diagnostics; +using MQTTnet.Server; namespace MQTTnet.AspNetCore { diff --git a/MQTTnet.Core/Adapter/IMqttChannelAdapter.cs b/Frameworks/MQTTnet.NetStandard/Adapter/IMqttChannelAdapter.cs similarity index 85% rename from MQTTnet.Core/Adapter/IMqttChannelAdapter.cs rename to Frameworks/MQTTnet.NetStandard/Adapter/IMqttChannelAdapter.cs index 13908f6..5f58d0c 100644 --- a/MQTTnet.Core/Adapter/IMqttChannelAdapter.cs +++ b/Frameworks/MQTTnet.NetStandard/Adapter/IMqttChannelAdapter.cs @@ -2,10 +2,10 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using MQTTnet.Core.Packets; -using MQTTnet.Core.Serializer; +using MQTTnet.Packets; +using MQTTnet.Serializer; -namespace MQTTnet.Core.Adapter +namespace MQTTnet.Adapter { public interface IMqttChannelAdapter { diff --git a/MQTTnet.Core/Adapter/IMqttServerAdapter.cs b/Frameworks/MQTTnet.NetStandard/Adapter/IMqttServerAdapter.cs similarity index 82% rename from MQTTnet.Core/Adapter/IMqttServerAdapter.cs rename to Frameworks/MQTTnet.NetStandard/Adapter/IMqttServerAdapter.cs index 9209185..d4ea941 100644 --- a/MQTTnet.Core/Adapter/IMqttServerAdapter.cs +++ b/Frameworks/MQTTnet.NetStandard/Adapter/IMqttServerAdapter.cs @@ -1,8 +1,8 @@ using System; using System.Threading.Tasks; -using MQTTnet.Core.Server; +using MQTTnet.Server; -namespace MQTTnet.Core.Adapter +namespace MQTTnet.Adapter { public interface IMqttServerAdapter { diff --git a/MQTTnet.Core/Adapter/MqttChannelAdapter.cs b/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs similarity index 96% rename from MQTTnet.Core/Adapter/MqttChannelAdapter.cs rename to Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs index 5dfcfc0..53603fa 100644 --- a/MQTTnet.Core/Adapter/MqttChannelAdapter.cs +++ b/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs @@ -4,14 +4,14 @@ using System.IO; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; -using MQTTnet.Core.Channel; -using MQTTnet.Core.Diagnostics; -using MQTTnet.Core.Exceptions; -using MQTTnet.Core.Internal; -using MQTTnet.Core.Packets; -using MQTTnet.Core.Serializer; - -namespace MQTTnet.Core.Adapter +using MQTTnet.Channel; +using MQTTnet.Diagnostics; +using MQTTnet.Exceptions; +using MQTTnet.Internal; +using MQTTnet.Packets; +using MQTTnet.Serializer; + +namespace MQTTnet.Adapter { public class MqttChannelAdapter : IMqttChannelAdapter { diff --git a/MQTTnet.Core/Adapter/MqttChannelAdapterExtensions.cs b/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapterExtensions.cs similarity index 89% rename from MQTTnet.Core/Adapter/MqttChannelAdapterExtensions.cs rename to Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapterExtensions.cs index f271248..58258ab 100644 --- a/MQTTnet.Core/Adapter/MqttChannelAdapterExtensions.cs +++ b/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapterExtensions.cs @@ -1,9 +1,9 @@ using System; using System.Threading; using System.Threading.Tasks; -using MQTTnet.Core.Packets; +using MQTTnet.Packets; -namespace MQTTnet.Core.Adapter +namespace MQTTnet.Adapter { public static class MqttChannelAdapterExtensions { diff --git a/MQTTnet.Core/Adapter/MqttConnectingFailedException.cs b/Frameworks/MQTTnet.NetStandard/Adapter/MqttConnectingFailedException.cs similarity index 79% rename from MQTTnet.Core/Adapter/MqttConnectingFailedException.cs rename to Frameworks/MQTTnet.NetStandard/Adapter/MqttConnectingFailedException.cs index 045d0d1..68445cf 100644 --- a/MQTTnet.Core/Adapter/MqttConnectingFailedException.cs +++ b/Frameworks/MQTTnet.NetStandard/Adapter/MqttConnectingFailedException.cs @@ -1,7 +1,7 @@ -using MQTTnet.Core.Exceptions; -using MQTTnet.Core.Protocol; +using MQTTnet.Exceptions; +using MQTTnet.Protocol; -namespace MQTTnet.Core.Adapter +namespace MQTTnet.Adapter { public class MqttConnectingFailedException : MqttCommunicationException { diff --git a/MQTTnet.Core/Adapter/MqttServerAdapterClientAcceptedEventArgs.cs b/Frameworks/MQTTnet.NetStandard/Adapter/MqttServerAdapterClientAcceptedEventArgs.cs similarity index 93% rename from MQTTnet.Core/Adapter/MqttServerAdapterClientAcceptedEventArgs.cs rename to Frameworks/MQTTnet.NetStandard/Adapter/MqttServerAdapterClientAcceptedEventArgs.cs index 341f632..4285249 100644 --- a/MQTTnet.Core/Adapter/MqttServerAdapterClientAcceptedEventArgs.cs +++ b/Frameworks/MQTTnet.NetStandard/Adapter/MqttServerAdapterClientAcceptedEventArgs.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; -namespace MQTTnet.Core.Adapter +namespace MQTTnet.Adapter { public class MqttServerAdapterClientAcceptedEventArgs : EventArgs { diff --git a/MQTTnet.Core/Adapter/ReceivedMqttPacket.cs b/Frameworks/MQTTnet.NetStandard/Adapter/ReceivedMqttPacket.cs similarity index 90% rename from MQTTnet.Core/Adapter/ReceivedMqttPacket.cs rename to Frameworks/MQTTnet.NetStandard/Adapter/ReceivedMqttPacket.cs index f7fdbcc..a44fb54 100644 --- a/MQTTnet.Core/Adapter/ReceivedMqttPacket.cs +++ b/Frameworks/MQTTnet.NetStandard/Adapter/ReceivedMqttPacket.cs @@ -1,8 +1,8 @@ using System; using System.IO; -using MQTTnet.Core.Packets; +using MQTTnet.Packets; -namespace MQTTnet.Core.Adapter +namespace MQTTnet.Adapter { public sealed class ReceivedMqttPacket : IDisposable { diff --git a/MQTTnet.Core/ApplicationMessagePublisherExtensions.cs b/Frameworks/MQTTnet.NetStandard/ApplicationMessagePublisherExtensions.cs similarity index 95% rename from MQTTnet.Core/ApplicationMessagePublisherExtensions.cs rename to Frameworks/MQTTnet.NetStandard/ApplicationMessagePublisherExtensions.cs index 6893a1b..73328de 100644 --- a/MQTTnet.Core/ApplicationMessagePublisherExtensions.cs +++ b/Frameworks/MQTTnet.NetStandard/ApplicationMessagePublisherExtensions.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; -namespace MQTTnet.Core +namespace MQTTnet { public static class ApplicationMessagePublisherExtensions { diff --git a/MQTTnet.Core/Channel/IMqttChannel.cs b/Frameworks/MQTTnet.NetStandard/Channel/IMqttChannel.cs similarity index 69% rename from MQTTnet.Core/Channel/IMqttChannel.cs rename to Frameworks/MQTTnet.NetStandard/Channel/IMqttChannel.cs index 92c0681..809b0b0 100644 --- a/MQTTnet.Core/Channel/IMqttChannel.cs +++ b/Frameworks/MQTTnet.NetStandard/Channel/IMqttChannel.cs @@ -1,7 +1,7 @@ -using System.Threading.Tasks; -using System.IO; +using System.IO; +using System.Threading.Tasks; -namespace MQTTnet.Core.Channel +namespace MQTTnet.Channel { public interface IMqttChannel { diff --git a/MQTTnet.Core/Client/IMqttClient.cs b/Frameworks/MQTTnet.NetStandard/Client/IMqttClient.cs similarity index 91% rename from MQTTnet.Core/Client/IMqttClient.cs rename to Frameworks/MQTTnet.NetStandard/Client/IMqttClient.cs index 6a39e21..0ac2f49 100644 --- a/MQTTnet.Core/Client/IMqttClient.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/IMqttClient.cs @@ -1,9 +1,8 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using MQTTnet.Core.Packets; -namespace MQTTnet.Core.Client +namespace MQTTnet.Client { public interface IMqttClient : IApplicationMessageReceiver, IApplicationMessagePublisher { diff --git a/MQTTnet.Core/Client/IMqttClientAdapterFactory.cs b/Frameworks/MQTTnet.NetStandard/Client/IMqttClientAdapterFactory.cs similarity index 64% rename from MQTTnet.Core/Client/IMqttClientAdapterFactory.cs rename to Frameworks/MQTTnet.NetStandard/Client/IMqttClientAdapterFactory.cs index 3bd6143..8b14481 100644 --- a/MQTTnet.Core/Client/IMqttClientAdapterFactory.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/IMqttClientAdapterFactory.cs @@ -1,7 +1,7 @@ -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Diagnostics; +using MQTTnet.Adapter; +using MQTTnet.Diagnostics; -namespace MQTTnet.Core.Client +namespace MQTTnet.Client { public interface IMqttClientAdapterFactory { diff --git a/MQTTnet.Core/Client/IMqttClientChannelOptions.cs b/Frameworks/MQTTnet.NetStandard/Client/IMqttClientChannelOptions.cs similarity index 77% rename from MQTTnet.Core/Client/IMqttClientChannelOptions.cs rename to Frameworks/MQTTnet.NetStandard/Client/IMqttClientChannelOptions.cs index 004430f..2224963 100644 --- a/MQTTnet.Core/Client/IMqttClientChannelOptions.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/IMqttClientChannelOptions.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Client +namespace MQTTnet.Client { public interface IMqttClientChannelOptions { diff --git a/MQTTnet.Core/Client/IMqttClientCredentials.cs b/Frameworks/MQTTnet.NetStandard/Client/IMqttClientCredentials.cs similarity index 78% rename from MQTTnet.Core/Client/IMqttClientCredentials.cs rename to Frameworks/MQTTnet.NetStandard/Client/IMqttClientCredentials.cs index c4dfc12..d214d64 100644 --- a/MQTTnet.Core/Client/IMqttClientCredentials.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/IMqttClientCredentials.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Client +namespace MQTTnet.Client { public interface IMqttClientCredentials { diff --git a/MQTTnet.Core/Client/IMqttClientFactory.cs b/Frameworks/MQTTnet.NetStandard/Client/IMqttClientFactory.cs similarity index 74% rename from MQTTnet.Core/Client/IMqttClientFactory.cs rename to Frameworks/MQTTnet.NetStandard/Client/IMqttClientFactory.cs index 8acdb91..444c16f 100644 --- a/MQTTnet.Core/Client/IMqttClientFactory.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/IMqttClientFactory.cs @@ -1,7 +1,7 @@ -using MQTTnet.Core.Diagnostics; -using MQTTnet.Core.ManagedClient; +using MQTTnet.Diagnostics; +using MQTTnet.ManagedClient; -namespace MQTTnet.Core.Client +namespace MQTTnet.Client { public interface IMqttClientFactory { diff --git a/MQTTnet.Core/Client/IMqttClientOptions.cs b/Frameworks/MQTTnet.NetStandard/Client/IMqttClientOptions.cs similarity index 88% rename from MQTTnet.Core/Client/IMqttClientOptions.cs rename to Frameworks/MQTTnet.NetStandard/Client/IMqttClientOptions.cs index 9139d5c..035dba1 100644 --- a/MQTTnet.Core/Client/IMqttClientOptions.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/IMqttClientOptions.cs @@ -1,7 +1,7 @@ using System; -using MQTTnet.Core.Serializer; +using MQTTnet.Serializer; -namespace MQTTnet.Core.Client +namespace MQTTnet.Client { public interface IMqttClientOptions { diff --git a/MQTTnet.Core/Client/MqttClient.cs b/Frameworks/MQTTnet.NetStandard/Client/MqttClient.cs similarity index 98% rename from MQTTnet.Core/Client/MqttClient.cs rename to Frameworks/MQTTnet.NetStandard/Client/MqttClient.cs index f270a38..a24fbff 100644 --- a/MQTTnet.Core/Client/MqttClient.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/MqttClient.cs @@ -3,14 +3,14 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Diagnostics; -using MQTTnet.Core.Exceptions; -using MQTTnet.Core.Internal; -using MQTTnet.Core.Packets; -using MQTTnet.Core.Protocol; - -namespace MQTTnet.Core.Client +using MQTTnet.Adapter; +using MQTTnet.Diagnostics; +using MQTTnet.Exceptions; +using MQTTnet.Internal; +using MQTTnet.Packets; +using MQTTnet.Protocol; + +namespace MQTTnet.Client { public class MqttClient : IMqttClient { diff --git a/MQTTnet.Core/Client/MqttClientConnectResult.cs b/Frameworks/MQTTnet.NetStandard/Client/MqttClientConnectResult.cs similarity index 87% rename from MQTTnet.Core/Client/MqttClientConnectResult.cs rename to Frameworks/MQTTnet.NetStandard/Client/MqttClientConnectResult.cs index 57db57d..6044bf5 100644 --- a/MQTTnet.Core/Client/MqttClientConnectResult.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/MqttClientConnectResult.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Client +namespace MQTTnet.Client { public class MqttClientConnectResult { diff --git a/MQTTnet.Core/Client/MqttClientConnectedEventArgs.cs b/Frameworks/MQTTnet.NetStandard/Client/MqttClientConnectedEventArgs.cs similarity index 90% rename from MQTTnet.Core/Client/MqttClientConnectedEventArgs.cs rename to Frameworks/MQTTnet.NetStandard/Client/MqttClientConnectedEventArgs.cs index 107a2c9..c8c6ce5 100644 --- a/MQTTnet.Core/Client/MqttClientConnectedEventArgs.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/MqttClientConnectedEventArgs.cs @@ -1,6 +1,6 @@ using System; -namespace MQTTnet.Core.Client +namespace MQTTnet.Client { public class MqttClientConnectedEventArgs : EventArgs { diff --git a/MQTTnet.Core/Client/MqttClientCredentials.cs b/Frameworks/MQTTnet.NetStandard/Client/MqttClientCredentials.cs similarity index 83% rename from MQTTnet.Core/Client/MqttClientCredentials.cs rename to Frameworks/MQTTnet.NetStandard/Client/MqttClientCredentials.cs index 085778a..feaa1e6 100644 --- a/MQTTnet.Core/Client/MqttClientCredentials.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/MqttClientCredentials.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Client +namespace MQTTnet.Client { public class MqttClientCredentials : IMqttClientCredentials { diff --git a/MQTTnet.Core/Client/MqttClientDisconnectedEventArgs.cs b/Frameworks/MQTTnet.NetStandard/Client/MqttClientDisconnectedEventArgs.cs similarity index 90% rename from MQTTnet.Core/Client/MqttClientDisconnectedEventArgs.cs rename to Frameworks/MQTTnet.NetStandard/Client/MqttClientDisconnectedEventArgs.cs index 1e9609e..26125b9 100644 --- a/MQTTnet.Core/Client/MqttClientDisconnectedEventArgs.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/MqttClientDisconnectedEventArgs.cs @@ -1,6 +1,6 @@ using System; -namespace MQTTnet.Core.Client +namespace MQTTnet.Client { public class MqttClientDisconnectedEventArgs : EventArgs { diff --git a/MQTTnet.Core/Client/MqttClientExtensions.cs b/Frameworks/MQTTnet.NetStandard/Client/MqttClientExtensions.cs similarity index 96% rename from MQTTnet.Core/Client/MqttClientExtensions.cs rename to Frameworks/MQTTnet.NetStandard/Client/MqttClientExtensions.cs index 567184d..a1a89e3 100644 --- a/MQTTnet.Core/Client/MqttClientExtensions.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/MqttClientExtensions.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -namespace MQTTnet.Core.Client +namespace MQTTnet.Client { public static class MqttClientExtensions { diff --git a/MQTTnet.Core/Client/MqttClientOptions.cs b/Frameworks/MQTTnet.NetStandard/Client/MqttClientOptions.cs similarity index 92% rename from MQTTnet.Core/Client/MqttClientOptions.cs rename to Frameworks/MQTTnet.NetStandard/Client/MqttClientOptions.cs index 04cf8bd..20e711f 100644 --- a/MQTTnet.Core/Client/MqttClientOptions.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/MqttClientOptions.cs @@ -1,7 +1,7 @@ using System; -using MQTTnet.Core.Serializer; +using MQTTnet.Serializer; -namespace MQTTnet.Core.Client +namespace MQTTnet.Client { public class MqttClientOptions : IMqttClientOptions { diff --git a/MQTTnet.Core/Client/MqttClientOptionsBuilder.cs b/Frameworks/MQTTnet.NetStandard/Client/MqttClientOptionsBuilder.cs similarity index 98% rename from MQTTnet.Core/Client/MqttClientOptionsBuilder.cs rename to Frameworks/MQTTnet.NetStandard/Client/MqttClientOptionsBuilder.cs index 429a3fa..079e635 100644 --- a/MQTTnet.Core/Client/MqttClientOptionsBuilder.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/MqttClientOptionsBuilder.cs @@ -1,8 +1,8 @@ using System; using System.Linq; -using MQTTnet.Core.Serializer; +using MQTTnet.Serializer; -namespace MQTTnet.Core.Client +namespace MQTTnet.Client { public class MqttClientOptionsBuilder { diff --git a/MQTTnet.Core/Client/MqttClientTcpOptions.cs b/Frameworks/MQTTnet.NetStandard/Client/MqttClientTcpOptions.cs similarity index 88% rename from MQTTnet.Core/Client/MqttClientTcpOptions.cs rename to Frameworks/MQTTnet.NetStandard/Client/MqttClientTcpOptions.cs index e5cf8d6..f44d424 100644 --- a/MQTTnet.Core/Client/MqttClientTcpOptions.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/MqttClientTcpOptions.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Client +namespace MQTTnet.Client { public class MqttClientTcpOptions : IMqttClientChannelOptions { diff --git a/MQTTnet.Core/Client/MqttClientTcpOptionsExtensions.cs b/Frameworks/MQTTnet.NetStandard/Client/MqttClientTcpOptionsExtensions.cs similarity index 93% rename from MQTTnet.Core/Client/MqttClientTcpOptionsExtensions.cs rename to Frameworks/MQTTnet.NetStandard/Client/MqttClientTcpOptionsExtensions.cs index cada6f8..460069a 100644 --- a/MQTTnet.Core/Client/MqttClientTcpOptionsExtensions.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/MqttClientTcpOptionsExtensions.cs @@ -1,6 +1,6 @@ using System; -namespace MQTTnet.Core.Client +namespace MQTTnet.Client { public static class MqttClientTcpOptionsExtensions { diff --git a/MQTTnet.Core/Client/MqttClientTlsOptions.cs b/Frameworks/MQTTnet.NetStandard/Client/MqttClientTlsOptions.cs similarity index 92% rename from MQTTnet.Core/Client/MqttClientTlsOptions.cs rename to Frameworks/MQTTnet.NetStandard/Client/MqttClientTlsOptions.cs index 33cd691..6478b26 100644 --- a/MQTTnet.Core/Client/MqttClientTlsOptions.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/MqttClientTlsOptions.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace MQTTnet.Core.Client +namespace MQTTnet.Client { public class MqttClientTlsOptions { diff --git a/MQTTnet.Core/Client/MqttClientWebSocketOptions.cs b/Frameworks/MQTTnet.NetStandard/Client/MqttClientWebSocketOptions.cs similarity index 94% rename from MQTTnet.Core/Client/MqttClientWebSocketOptions.cs rename to Frameworks/MQTTnet.NetStandard/Client/MqttClientWebSocketOptions.cs index 25e4ae8..1819daa 100644 --- a/MQTTnet.Core/Client/MqttClientWebSocketOptions.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/MqttClientWebSocketOptions.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Net; -namespace MQTTnet.Core.Client +namespace MQTTnet.Client { public class MqttClientWebSocketOptions : IMqttClientChannelOptions { diff --git a/MQTTnet.Core/Client/MqttPacketDispatcher.cs b/Frameworks/MQTTnet.NetStandard/Client/MqttPacketDispatcher.cs similarity index 96% rename from MQTTnet.Core/Client/MqttPacketDispatcher.cs rename to Frameworks/MQTTnet.NetStandard/Client/MqttPacketDispatcher.cs index dd9c714..4875589 100644 --- a/MQTTnet.Core/Client/MqttPacketDispatcher.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/MqttPacketDispatcher.cs @@ -1,12 +1,12 @@ using System; using System.Collections.Concurrent; using System.Threading.Tasks; -using MQTTnet.Core.Diagnostics; -using MQTTnet.Core.Exceptions; -using MQTTnet.Core.Internal; -using MQTTnet.Core.Packets; +using MQTTnet.Diagnostics; +using MQTTnet.Exceptions; +using MQTTnet.Internal; +using MQTTnet.Packets; -namespace MQTTnet.Core.Client +namespace MQTTnet.Client { public class MqttPacketDispatcher { diff --git a/MQTTnet.Core/Client/MqttSubscribeResult.cs b/Frameworks/MQTTnet.NetStandard/Client/MqttSubscribeResult.cs similarity index 79% rename from MQTTnet.Core/Client/MqttSubscribeResult.cs rename to Frameworks/MQTTnet.NetStandard/Client/MqttSubscribeResult.cs index 9dd4944..2b7c46d 100644 --- a/MQTTnet.Core/Client/MqttSubscribeResult.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/MqttSubscribeResult.cs @@ -1,7 +1,6 @@ -using MQTTnet.Core.Packets; -using MQTTnet.Core.Protocol; +using MQTTnet.Protocol; -namespace MQTTnet.Core.Client +namespace MQTTnet.Client { public class MqttSubscribeResult { diff --git a/MQTTnet.Core/Diagnostics/IMqttNetLogger.cs b/Frameworks/MQTTnet.NetStandard/Diagnostics/IMqttNetLogger.cs similarity index 94% rename from MQTTnet.Core/Diagnostics/IMqttNetLogger.cs rename to Frameworks/MQTTnet.NetStandard/Diagnostics/IMqttNetLogger.cs index 99f7b19..a65207b 100644 --- a/MQTTnet.Core/Diagnostics/IMqttNetLogger.cs +++ b/Frameworks/MQTTnet.NetStandard/Diagnostics/IMqttNetLogger.cs @@ -1,6 +1,6 @@ using System; -namespace MQTTnet.Core.Diagnostics +namespace MQTTnet.Diagnostics { public interface IMqttNetLogger { diff --git a/MQTTnet.Core/Diagnostics/MqttNetGlobalLog.cs b/Frameworks/MQTTnet.NetStandard/Diagnostics/MqttNetGlobalLogger.cs similarity index 86% rename from MQTTnet.Core/Diagnostics/MqttNetGlobalLog.cs rename to Frameworks/MQTTnet.NetStandard/Diagnostics/MqttNetGlobalLogger.cs index 6432682..a42857e 100644 --- a/MQTTnet.Core/Diagnostics/MqttNetGlobalLog.cs +++ b/Frameworks/MQTTnet.NetStandard/Diagnostics/MqttNetGlobalLogger.cs @@ -1,8 +1,8 @@ using System; -namespace MQTTnet.Core.Diagnostics +namespace MQTTnet.Diagnostics { - public static class MqttNetGlobalLog + public static class MqttNetGlobalLogger { public static event EventHandler LogMessagePublished; diff --git a/MQTTnet.Core/Diagnostics/MqttNetLogLevel.cs b/Frameworks/MQTTnet.NetStandard/Diagnostics/MqttNetLogLevel.cs similarity index 74% rename from MQTTnet.Core/Diagnostics/MqttNetLogLevel.cs rename to Frameworks/MQTTnet.NetStandard/Diagnostics/MqttNetLogLevel.cs index 32e5de1..cdc7a78 100644 --- a/MQTTnet.Core/Diagnostics/MqttNetLogLevel.cs +++ b/Frameworks/MQTTnet.NetStandard/Diagnostics/MqttNetLogLevel.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Diagnostics +namespace MQTTnet.Diagnostics { public enum MqttNetLogLevel { diff --git a/MQTTnet.Core/Diagnostics/MqttNetLogMessage.cs b/Frameworks/MQTTnet.NetStandard/Diagnostics/MqttNetLogMessage.cs similarity index 95% rename from MQTTnet.Core/Diagnostics/MqttNetLogMessage.cs rename to Frameworks/MQTTnet.NetStandard/Diagnostics/MqttNetLogMessage.cs index e1598eb..d118fd0 100644 --- a/MQTTnet.Core/Diagnostics/MqttNetLogMessage.cs +++ b/Frameworks/MQTTnet.NetStandard/Diagnostics/MqttNetLogMessage.cs @@ -1,6 +1,6 @@ using System; -namespace MQTTnet.Core.Diagnostics +namespace MQTTnet.Diagnostics { public sealed class MqttNetLogMessage { diff --git a/MQTTnet.Core/Diagnostics/MqttNetLogMessagePublishedEventArgs.cs b/Frameworks/MQTTnet.NetStandard/Diagnostics/MqttNetLogMessagePublishedEventArgs.cs similarity index 91% rename from MQTTnet.Core/Diagnostics/MqttNetLogMessagePublishedEventArgs.cs rename to Frameworks/MQTTnet.NetStandard/Diagnostics/MqttNetLogMessagePublishedEventArgs.cs index 46c5468..2407752 100644 --- a/MQTTnet.Core/Diagnostics/MqttNetLogMessagePublishedEventArgs.cs +++ b/Frameworks/MQTTnet.NetStandard/Diagnostics/MqttNetLogMessagePublishedEventArgs.cs @@ -1,6 +1,6 @@ using System; -namespace MQTTnet.Core.Diagnostics +namespace MQTTnet.Diagnostics { public sealed class MqttNetLogMessagePublishedEventArgs : EventArgs { diff --git a/MQTTnet.Core/Diagnostics/MqttNetLogger.cs b/Frameworks/MQTTnet.NetStandard/Diagnostics/MqttNetLogger.cs similarity index 93% rename from MQTTnet.Core/Diagnostics/MqttNetLogger.cs rename to Frameworks/MQTTnet.NetStandard/Diagnostics/MqttNetLogger.cs index a879af1..7d9b290 100644 --- a/MQTTnet.Core/Diagnostics/MqttNetLogger.cs +++ b/Frameworks/MQTTnet.NetStandard/Diagnostics/MqttNetLogger.cs @@ -1,6 +1,6 @@ using System; -namespace MQTTnet.Core.Diagnostics +namespace MQTTnet.Diagnostics { public class MqttNetLogger : IMqttNetLogger { @@ -46,7 +46,7 @@ namespace MQTTnet.Core.Diagnostics private void Publish(MqttNetLogLevel logLevel, Exception exception, string message, object[] parameters) { var hasLocalListeners = LogMessagePublished != null; - var hasGlobalListeners = MqttNetGlobalLog.HasListeners; + var hasGlobalListeners = MqttNetGlobalLogger.HasListeners; if (!hasLocalListeners && !hasGlobalListeners) { @@ -62,7 +62,7 @@ namespace MQTTnet.Core.Diagnostics if (hasGlobalListeners) { - MqttNetGlobalLog.Publish(traceMessage); + MqttNetGlobalLogger.Publish(traceMessage); } if (hasLocalListeners) diff --git a/Frameworks/MQTTnet.NetStandard/Diagnostics/TargetFrameworkInfoProvider.cs b/Frameworks/MQTTnet.NetStandard/Diagnostics/TargetFrameworkInfoProvider.cs index 22369d9..5258276 100644 --- a/Frameworks/MQTTnet.NetStandard/Diagnostics/TargetFrameworkInfoProvider.cs +++ b/Frameworks/MQTTnet.NetStandard/Diagnostics/TargetFrameworkInfoProvider.cs @@ -1,4 +1,4 @@ -namespace MQTTnet +namespace MQTTnet.Diagnostics { public static class TargetFrameworkInfoProvider { diff --git a/MQTTnet.Core/Exceptions/MqttCommunicationException.cs b/Frameworks/MQTTnet.NetStandard/Exceptions/MqttCommunicationException.cs similarity index 92% rename from MQTTnet.Core/Exceptions/MqttCommunicationException.cs rename to Frameworks/MQTTnet.NetStandard/Exceptions/MqttCommunicationException.cs index e019f4e..4631de8 100644 --- a/MQTTnet.Core/Exceptions/MqttCommunicationException.cs +++ b/Frameworks/MQTTnet.NetStandard/Exceptions/MqttCommunicationException.cs @@ -1,6 +1,6 @@ using System; -namespace MQTTnet.Core.Exceptions +namespace MQTTnet.Exceptions { public class MqttCommunicationException : Exception { diff --git a/MQTTnet.Core/Exceptions/MqttCommunicationTimedOutException.cs b/Frameworks/MQTTnet.NetStandard/Exceptions/MqttCommunicationTimedOutException.cs similarity index 73% rename from MQTTnet.Core/Exceptions/MqttCommunicationTimedOutException.cs rename to Frameworks/MQTTnet.NetStandard/Exceptions/MqttCommunicationTimedOutException.cs index e724007..7d0adcd 100644 --- a/MQTTnet.Core/Exceptions/MqttCommunicationTimedOutException.cs +++ b/Frameworks/MQTTnet.NetStandard/Exceptions/MqttCommunicationTimedOutException.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Exceptions +namespace MQTTnet.Exceptions { public sealed class MqttCommunicationTimedOutException : MqttCommunicationException { diff --git a/MQTTnet.Core/Exceptions/MqttProtocolViolationException.cs b/Frameworks/MQTTnet.NetStandard/Exceptions/MqttProtocolViolationException.cs similarity index 86% rename from MQTTnet.Core/Exceptions/MqttProtocolViolationException.cs rename to Frameworks/MQTTnet.NetStandard/Exceptions/MqttProtocolViolationException.cs index cef43f5..8756b3f 100644 --- a/MQTTnet.Core/Exceptions/MqttProtocolViolationException.cs +++ b/Frameworks/MQTTnet.NetStandard/Exceptions/MqttProtocolViolationException.cs @@ -1,6 +1,6 @@ using System; -namespace MQTTnet.Core.Exceptions +namespace MQTTnet.Exceptions { public sealed class MqttProtocolViolationException : Exception { diff --git a/MQTTnet.Core/IApplicationMessagePublisher.cs b/Frameworks/MQTTnet.NetStandard/IApplicationMessagePublisher.cs similarity index 90% rename from MQTTnet.Core/IApplicationMessagePublisher.cs rename to Frameworks/MQTTnet.NetStandard/IApplicationMessagePublisher.cs index 2f6715b..e137669 100644 --- a/MQTTnet.Core/IApplicationMessagePublisher.cs +++ b/Frameworks/MQTTnet.NetStandard/IApplicationMessagePublisher.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace MQTTnet.Core +namespace MQTTnet { public interface IApplicationMessagePublisher { diff --git a/MQTTnet.Core/IApplicationMessageReceiver.cs b/Frameworks/MQTTnet.NetStandard/IApplicationMessageReceiver.cs similarity index 78% rename from MQTTnet.Core/IApplicationMessageReceiver.cs rename to Frameworks/MQTTnet.NetStandard/IApplicationMessageReceiver.cs index 379ba69..b315067 100644 --- a/MQTTnet.Core/IApplicationMessageReceiver.cs +++ b/Frameworks/MQTTnet.NetStandard/IApplicationMessageReceiver.cs @@ -1,7 +1,6 @@ using System; -using MQTTnet.Core.Client; -namespace MQTTnet.Core +namespace MQTTnet { public interface IApplicationMessageReceiver { diff --git a/Frameworks/MQTTnet.NetStandard/Implementations/MqttClientAdapterFactory.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttClientAdapterFactory.cs index 9884c86..f8f0e99 100644 --- a/Frameworks/MQTTnet.NetStandard/Implementations/MqttClientAdapterFactory.cs +++ b/Frameworks/MQTTnet.NetStandard/Implementations/MqttClientAdapterFactory.cs @@ -1,8 +1,8 @@ using System; -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Client; -using MQTTnet.Core.Diagnostics; -using MQTTnet.Core.Serializer; +using MQTTnet.Adapter; +using MQTTnet.Client; +using MQTTnet.Diagnostics; +using MQTTnet.Serializer; namespace MQTTnet.Implementations { diff --git a/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.Uwp.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.Uwp.cs index 1b8a43c..3966edc 100644 --- a/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.Uwp.cs +++ b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.Uwp.cs @@ -1,11 +1,11 @@ #if WINDOWS_UWP using System; using System.Threading.Tasks; -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Server; using Windows.Networking.Sockets; -using MQTTnet.Core.Diagnostics; -using MQTTnet.Core.Serializer; +using MQTTnet.Adapter; +using MQTTnet.Diagnostics; +using MQTTnet.Serializer; +using MQTTnet.Server; namespace MQTTnet.Implementations { diff --git a/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs index 3b8515c..dadca44 100644 --- a/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs +++ b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs @@ -7,10 +7,10 @@ using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; using System.Threading; using System.Threading.Tasks; -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Server; -using MQTTnet.Core.Diagnostics; -using MQTTnet.Core.Serializer; +using MQTTnet.Adapter; +using MQTTnet.Diagnostics; +using MQTTnet.Serializer; +using MQTTnet.Server; namespace MQTTnet.Implementations { diff --git a/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.Uwp.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.Uwp.cs index 964bfbf..fa96a8f 100644 --- a/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.Uwp.cs +++ b/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.Uwp.cs @@ -8,8 +8,8 @@ using System.Threading.Tasks; using Windows.Networking; using Windows.Networking.Sockets; using Windows.Security.Cryptography.Certificates; -using MQTTnet.Core.Channel; -using MQTTnet.Core.Client; +using MQTTnet.Channel; +using MQTTnet.Client; namespace MQTTnet.Implementations { diff --git a/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs index ce9dcf6..7e23fdb 100644 --- a/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs +++ b/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs @@ -5,10 +5,10 @@ using System.Net.Sockets; using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; using System.Threading.Tasks; -using MQTTnet.Core.Channel; -using MQTTnet.Core.Client; using System.IO; using System.Linq; +using MQTTnet.Channel; +using MQTTnet.Client; namespace MQTTnet.Implementations { diff --git a/Frameworks/MQTTnet.NetStandard/Implementations/MqttWebSocketChannel.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttWebSocketChannel.cs index d8e24a4..77d99a8 100644 --- a/Frameworks/MQTTnet.NetStandard/Implementations/MqttWebSocketChannel.cs +++ b/Frameworks/MQTTnet.NetStandard/Implementations/MqttWebSocketChannel.cs @@ -1,11 +1,11 @@ -using MQTTnet.Core.Channel; -using MQTTnet.Core.Client; -using System; +using System; using System.IO; using System.Net.WebSockets; using System.Security.Cryptography.X509Certificates; using System.Threading; using System.Threading.Tasks; +using MQTTnet.Channel; +using MQTTnet.Client; namespace MQTTnet.Implementations { diff --git a/Frameworks/MQTTnet.NetStandard/Implementations/WebSocketStream.cs b/Frameworks/MQTTnet.NetStandard/Implementations/WebSocketStream.cs index 4ff11da..1aa02a6 100644 --- a/Frameworks/MQTTnet.NetStandard/Implementations/WebSocketStream.cs +++ b/Frameworks/MQTTnet.NetStandard/Implementations/WebSocketStream.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Net.WebSockets; using System.Threading; using System.Threading.Tasks; -using MQTTnet.Core.Exceptions; +using MQTTnet.Exceptions; namespace MQTTnet.Implementations { diff --git a/MQTTnet.Core/Internal/MqttApplicationMessageExtensions.cs b/Frameworks/MQTTnet.NetStandard/Internal/MqttApplicationMessageExtensions.cs similarity index 94% rename from MQTTnet.Core/Internal/MqttApplicationMessageExtensions.cs rename to Frameworks/MQTTnet.NetStandard/Internal/MqttApplicationMessageExtensions.cs index 7ca7d00..b1d1a38 100644 --- a/MQTTnet.Core/Internal/MqttApplicationMessageExtensions.cs +++ b/Frameworks/MQTTnet.NetStandard/Internal/MqttApplicationMessageExtensions.cs @@ -1,6 +1,6 @@ -using MQTTnet.Core.Packets; +using MQTTnet.Packets; -namespace MQTTnet.Core.Internal +namespace MQTTnet.Internal { internal static class MqttApplicationMessageExtensions { diff --git a/MQTTnet.Core/Internal/TaskExtensions.cs b/Frameworks/MQTTnet.NetStandard/Internal/TaskExtensions.cs similarity index 97% rename from MQTTnet.Core/Internal/TaskExtensions.cs rename to Frameworks/MQTTnet.NetStandard/Internal/TaskExtensions.cs index 45b3510..6acb71e 100644 --- a/MQTTnet.Core/Internal/TaskExtensions.cs +++ b/Frameworks/MQTTnet.NetStandard/Internal/TaskExtensions.cs @@ -1,9 +1,9 @@ using System; using System.Threading; using System.Threading.Tasks; -using MQTTnet.Core.Exceptions; +using MQTTnet.Exceptions; -namespace MQTTnet.Core.Internal +namespace MQTTnet.Internal { public static class TaskExtensions { diff --git a/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj b/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj index 9b6211d..752ba94 100644 --- a/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj +++ b/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj @@ -14,6 +14,8 @@ + true + codeSigningKey.pfx @@ -33,10 +35,6 @@ - - - - diff --git a/MQTTnet.Core/ManagedClient/IManagedMqttClient.cs b/Frameworks/MQTTnet.NetStandard/ManagedClient/IManagedMqttClient.cs similarity index 90% rename from MQTTnet.Core/ManagedClient/IManagedMqttClient.cs rename to Frameworks/MQTTnet.NetStandard/ManagedClient/IManagedMqttClient.cs index 8d2ac8c..41c0ce3 100644 --- a/MQTTnet.Core/ManagedClient/IManagedMqttClient.cs +++ b/Frameworks/MQTTnet.NetStandard/ManagedClient/IManagedMqttClient.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using MQTTnet.Core.Client; +using MQTTnet.Client; -namespace MQTTnet.Core.ManagedClient +namespace MQTTnet.ManagedClient { public interface IManagedMqttClient : IApplicationMessageReceiver, IApplicationMessagePublisher { diff --git a/MQTTnet.Core/ManagedClient/IManagedMqttClientOptions.cs b/Frameworks/MQTTnet.NetStandard/ManagedClient/IManagedMqttClientOptions.cs similarity index 77% rename from MQTTnet.Core/ManagedClient/IManagedMqttClientOptions.cs rename to Frameworks/MQTTnet.NetStandard/ManagedClient/IManagedMqttClientOptions.cs index 298de9a..fbb87b7 100644 --- a/MQTTnet.Core/ManagedClient/IManagedMqttClientOptions.cs +++ b/Frameworks/MQTTnet.NetStandard/ManagedClient/IManagedMqttClientOptions.cs @@ -1,7 +1,7 @@ using System; -using MQTTnet.Core.Client; +using MQTTnet.Client; -namespace MQTTnet.Core.ManagedClient +namespace MQTTnet.ManagedClient { public interface IManagedMqttClientOptions { diff --git a/MQTTnet.Core/ManagedClient/IManagedMqttClientStorage.cs b/Frameworks/MQTTnet.NetStandard/ManagedClient/IManagedMqttClientStorage.cs similarity index 88% rename from MQTTnet.Core/ManagedClient/IManagedMqttClientStorage.cs rename to Frameworks/MQTTnet.NetStandard/ManagedClient/IManagedMqttClientStorage.cs index 39ea89c..28bf570 100644 --- a/MQTTnet.Core/ManagedClient/IManagedMqttClientStorage.cs +++ b/Frameworks/MQTTnet.NetStandard/ManagedClient/IManagedMqttClientStorage.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace MQTTnet.Core.ManagedClient +namespace MQTTnet.ManagedClient { public interface IManagedMqttClientStorage { diff --git a/MQTTnet.Core/ManagedClient/ManagedMqttClient.cs b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs similarity index 98% rename from MQTTnet.Core/ManagedClient/ManagedMqttClient.cs rename to Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs index c2e4077..90db1dc 100644 --- a/MQTTnet.Core/ManagedClient/ManagedMqttClient.cs +++ b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs @@ -4,12 +4,12 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; -using MQTTnet.Core.Client; -using MQTTnet.Core.Diagnostics; -using MQTTnet.Core.Exceptions; -using MQTTnet.Core.Protocol; +using MQTTnet.Client; +using MQTTnet.Diagnostics; +using MQTTnet.Exceptions; +using MQTTnet.Protocol; -namespace MQTTnet.Core.ManagedClient +namespace MQTTnet.ManagedClient { public class ManagedMqttClient : IManagedMqttClient { diff --git a/MQTTnet.Core/ManagedClient/ManagedMqttClientExtensions.cs b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientExtensions.cs similarity index 95% rename from MQTTnet.Core/ManagedClient/ManagedMqttClientExtensions.cs rename to Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientExtensions.cs index a9984c4..e134667 100644 --- a/MQTTnet.Core/ManagedClient/ManagedMqttClientExtensions.cs +++ b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientExtensions.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; -namespace MQTTnet.Core.ManagedClient +namespace MQTTnet.ManagedClient { public static class ManagedMqttClientExtensions { diff --git a/MQTTnet.Core/ManagedClient/ManagedMqttClientOptions.cs b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientOptions.cs similarity index 83% rename from MQTTnet.Core/ManagedClient/ManagedMqttClientOptions.cs rename to Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientOptions.cs index 2e24fd0..813aee8 100644 --- a/MQTTnet.Core/ManagedClient/ManagedMqttClientOptions.cs +++ b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientOptions.cs @@ -1,7 +1,7 @@ using System; -using MQTTnet.Core.Client; +using MQTTnet.Client; -namespace MQTTnet.Core.ManagedClient +namespace MQTTnet.ManagedClient { public class ManagedMqttClientOptions : IManagedMqttClientOptions { diff --git a/MQTTnet.Core/ManagedClient/ManagedMqttClientOptionsBuilder.cs b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientOptionsBuilder.cs similarity index 95% rename from MQTTnet.Core/ManagedClient/ManagedMqttClientOptionsBuilder.cs rename to Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientOptionsBuilder.cs index 3972dcd..7c75306 100644 --- a/MQTTnet.Core/ManagedClient/ManagedMqttClientOptionsBuilder.cs +++ b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientOptionsBuilder.cs @@ -1,7 +1,7 @@ using System; -using MQTTnet.Core.Client; +using MQTTnet.Client; -namespace MQTTnet.Core.ManagedClient +namespace MQTTnet.ManagedClient { public class ManagedMqttClientOptionsBuilder { diff --git a/MQTTnet.Core/ManagedClient/ManagedMqttClientStorageManager.cs b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientStorageManager.cs similarity index 98% rename from MQTTnet.Core/ManagedClient/ManagedMqttClientStorageManager.cs rename to Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientStorageManager.cs index 0810f36..d55f137 100644 --- a/MQTTnet.Core/ManagedClient/ManagedMqttClientStorageManager.cs +++ b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientStorageManager.cs @@ -2,7 +2,7 @@ using System.Threading; using System.Threading.Tasks; -namespace MQTTnet.Core.ManagedClient +namespace MQTTnet.ManagedClient { public class ManagedMqttClientStorageManager { diff --git a/MQTTnet.Core/ManagedClient/ReconnectionResult.cs b/Frameworks/MQTTnet.NetStandard/ManagedClient/ReconnectionResult.cs similarity index 74% rename from MQTTnet.Core/ManagedClient/ReconnectionResult.cs rename to Frameworks/MQTTnet.NetStandard/ManagedClient/ReconnectionResult.cs index fae0770..42566e3 100644 --- a/MQTTnet.Core/ManagedClient/ReconnectionResult.cs +++ b/Frameworks/MQTTnet.NetStandard/ManagedClient/ReconnectionResult.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.ManagedClient +namespace MQTTnet.ManagedClient { public enum ReconnectionResult { diff --git a/MQTTnet.Core/MqttApplicationMessage.cs b/Frameworks/MQTTnet.NetStandard/MqttApplicationMessage.cs similarity index 94% rename from MQTTnet.Core/MqttApplicationMessage.cs rename to Frameworks/MQTTnet.NetStandard/MqttApplicationMessage.cs index b07ee18..387acb2 100644 --- a/MQTTnet.Core/MqttApplicationMessage.cs +++ b/Frameworks/MQTTnet.NetStandard/MqttApplicationMessage.cs @@ -1,7 +1,7 @@ using System; -using MQTTnet.Core.Protocol; +using MQTTnet.Protocol; -namespace MQTTnet.Core +namespace MQTTnet { public sealed class MqttApplicationMessage { diff --git a/MQTTnet.Core/MqttApplicationMessageBuilder.cs b/Frameworks/MQTTnet.NetStandard/MqttApplicationMessageBuilder.cs similarity index 97% rename from MQTTnet.Core/MqttApplicationMessageBuilder.cs rename to Frameworks/MQTTnet.NetStandard/MqttApplicationMessageBuilder.cs index c2e0431..ce949b8 100644 --- a/MQTTnet.Core/MqttApplicationMessageBuilder.cs +++ b/Frameworks/MQTTnet.NetStandard/MqttApplicationMessageBuilder.cs @@ -2,10 +2,10 @@ using System.IO; using System.Linq; using System.Text; -using MQTTnet.Core.Exceptions; -using MQTTnet.Core.Protocol; +using MQTTnet.Exceptions; +using MQTTnet.Protocol; -namespace MQTTnet.Core +namespace MQTTnet { public class MqttApplicationMessageBuilder { diff --git a/MQTTnet.Core/MqttApplicationMessageReceivedEventArgs.cs b/Frameworks/MQTTnet.NetStandard/MqttApplicationMessageReceivedEventArgs.cs similarity index 95% rename from MQTTnet.Core/MqttApplicationMessageReceivedEventArgs.cs rename to Frameworks/MQTTnet.NetStandard/MqttApplicationMessageReceivedEventArgs.cs index 3de0db5..a16a81d 100644 --- a/MQTTnet.Core/MqttApplicationMessageReceivedEventArgs.cs +++ b/Frameworks/MQTTnet.NetStandard/MqttApplicationMessageReceivedEventArgs.cs @@ -1,6 +1,6 @@ using System; -namespace MQTTnet.Core +namespace MQTTnet { public sealed class MqttApplicationMessageReceivedEventArgs : EventArgs { diff --git a/Frameworks/MQTTnet.NetStandard/MqttFactory.cs b/Frameworks/MQTTnet.NetStandard/MqttFactory.cs index 99e57af..5b0174b 100644 --- a/Frameworks/MQTTnet.NetStandard/MqttFactory.cs +++ b/Frameworks/MQTTnet.NetStandard/MqttFactory.cs @@ -1,11 +1,11 @@ using System; using System.Collections.Generic; -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Client; +using MQTTnet.Adapter; +using MQTTnet.Client; +using MQTTnet.Diagnostics; using MQTTnet.Implementations; -using MQTTnet.Core.ManagedClient; -using MQTTnet.Core.Server; -using MQTTnet.Core.Diagnostics; +using MQTTnet.ManagedClient; +using MQTTnet.Server; namespace MQTTnet { diff --git a/MQTTnet.Core/Packets/IMqttPacketWithIdentifier.cs b/Frameworks/MQTTnet.NetStandard/Packets/IMqttPacketWithIdentifier.cs similarity index 76% rename from MQTTnet.Core/Packets/IMqttPacketWithIdentifier.cs rename to Frameworks/MQTTnet.NetStandard/Packets/IMqttPacketWithIdentifier.cs index 420955c..5f7f8e9 100644 --- a/MQTTnet.Core/Packets/IMqttPacketWithIdentifier.cs +++ b/Frameworks/MQTTnet.NetStandard/Packets/IMqttPacketWithIdentifier.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Packets +namespace MQTTnet.Packets { public interface IMqttPacketWithIdentifier { diff --git a/MQTTnet.Core/Packets/MqttBasePacket.cs b/Frameworks/MQTTnet.NetStandard/Packets/MqttBasePacket.cs similarity index 62% rename from MQTTnet.Core/Packets/MqttBasePacket.cs rename to Frameworks/MQTTnet.NetStandard/Packets/MqttBasePacket.cs index 41901e5..d964056 100644 --- a/MQTTnet.Core/Packets/MqttBasePacket.cs +++ b/Frameworks/MQTTnet.NetStandard/Packets/MqttBasePacket.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Packets +namespace MQTTnet.Packets { public abstract class MqttBasePacket { diff --git a/MQTTnet.Core/Packets/MqttBasePublishPacket.cs b/Frameworks/MQTTnet.NetStandard/Packets/MqttBasePublishPacket.cs similarity index 81% rename from MQTTnet.Core/Packets/MqttBasePublishPacket.cs rename to Frameworks/MQTTnet.NetStandard/Packets/MqttBasePublishPacket.cs index 67d55b9..6218c15 100644 --- a/MQTTnet.Core/Packets/MqttBasePublishPacket.cs +++ b/Frameworks/MQTTnet.NetStandard/Packets/MqttBasePublishPacket.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Packets +namespace MQTTnet.Packets { public class MqttBasePublishPacket : MqttBasePacket, IMqttPacketWithIdentifier { diff --git a/MQTTnet.Core/Packets/MqttConnAckPacket.cs b/Frameworks/MQTTnet.NetStandard/Packets/MqttConnAckPacket.cs similarity index 85% rename from MQTTnet.Core/Packets/MqttConnAckPacket.cs rename to Frameworks/MQTTnet.NetStandard/Packets/MqttConnAckPacket.cs index 0410e66..9cf0adf 100644 --- a/MQTTnet.Core/Packets/MqttConnAckPacket.cs +++ b/Frameworks/MQTTnet.NetStandard/Packets/MqttConnAckPacket.cs @@ -1,6 +1,6 @@ -using MQTTnet.Core.Protocol; +using MQTTnet.Protocol; -namespace MQTTnet.Core.Packets +namespace MQTTnet.Packets { public sealed class MqttConnAckPacket : MqttBasePacket { diff --git a/MQTTnet.Core/Packets/MqttConnectPacket.cs b/Frameworks/MQTTnet.NetStandard/Packets/MqttConnectPacket.cs similarity index 91% rename from MQTTnet.Core/Packets/MqttConnectPacket.cs rename to Frameworks/MQTTnet.NetStandard/Packets/MqttConnectPacket.cs index 4881712..b1943ce 100644 --- a/MQTTnet.Core/Packets/MqttConnectPacket.cs +++ b/Frameworks/MQTTnet.NetStandard/Packets/MqttConnectPacket.cs @@ -1,6 +1,6 @@ -using MQTTnet.Core.Serializer; +using MQTTnet.Serializer; -namespace MQTTnet.Core.Packets +namespace MQTTnet.Packets { public sealed class MqttConnectPacket : MqttBasePacket { diff --git a/MQTTnet.Core/Packets/MqttDisconnectPacket.cs b/Frameworks/MQTTnet.NetStandard/Packets/MqttDisconnectPacket.cs similarity index 83% rename from MQTTnet.Core/Packets/MqttDisconnectPacket.cs rename to Frameworks/MQTTnet.NetStandard/Packets/MqttDisconnectPacket.cs index 4db7f79..46c3270 100644 --- a/MQTTnet.Core/Packets/MqttDisconnectPacket.cs +++ b/Frameworks/MQTTnet.NetStandard/Packets/MqttDisconnectPacket.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Packets +namespace MQTTnet.Packets { public sealed class MqttDisconnectPacket : MqttBasePacket { diff --git a/MQTTnet.Core/Packets/MqttPacketExtensions.cs b/Frameworks/MQTTnet.NetStandard/Packets/MqttPacketExtensions.cs similarity index 96% rename from MQTTnet.Core/Packets/MqttPacketExtensions.cs rename to Frameworks/MQTTnet.NetStandard/Packets/MqttPacketExtensions.cs index 6a7e0ce..a3df53c 100644 --- a/MQTTnet.Core/Packets/MqttPacketExtensions.cs +++ b/Frameworks/MQTTnet.NetStandard/Packets/MqttPacketExtensions.cs @@ -1,6 +1,6 @@ using System; -namespace MQTTnet.Core.Packets +namespace MQTTnet.Packets { public static class MqttPacketExtensions { diff --git a/MQTTnet.Core/Packets/MqttPacketHeader.cs b/Frameworks/MQTTnet.NetStandard/Packets/MqttPacketHeader.cs similarity index 77% rename from MQTTnet.Core/Packets/MqttPacketHeader.cs rename to Frameworks/MQTTnet.NetStandard/Packets/MqttPacketHeader.cs index 41646df..01c26ec 100644 --- a/MQTTnet.Core/Packets/MqttPacketHeader.cs +++ b/Frameworks/MQTTnet.NetStandard/Packets/MqttPacketHeader.cs @@ -1,6 +1,6 @@ -using MQTTnet.Core.Protocol; +using MQTTnet.Protocol; -namespace MQTTnet.Core.Packets +namespace MQTTnet.Packets { public class MqttPacketHeader { diff --git a/MQTTnet.Core/Packets/MqttPingReqPacket.cs b/Frameworks/MQTTnet.NetStandard/Packets/MqttPingReqPacket.cs similarity index 83% rename from MQTTnet.Core/Packets/MqttPingReqPacket.cs rename to Frameworks/MQTTnet.NetStandard/Packets/MqttPingReqPacket.cs index 9836b5a..fee9926 100644 --- a/MQTTnet.Core/Packets/MqttPingReqPacket.cs +++ b/Frameworks/MQTTnet.NetStandard/Packets/MqttPingReqPacket.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Packets +namespace MQTTnet.Packets { public sealed class MqttPingReqPacket : MqttBasePacket { diff --git a/MQTTnet.Core/Packets/MqttPingRespPacket.cs b/Frameworks/MQTTnet.NetStandard/Packets/MqttPingRespPacket.cs similarity index 83% rename from MQTTnet.Core/Packets/MqttPingRespPacket.cs rename to Frameworks/MQTTnet.NetStandard/Packets/MqttPingRespPacket.cs index eff12b8..c5f82a3 100644 --- a/MQTTnet.Core/Packets/MqttPingRespPacket.cs +++ b/Frameworks/MQTTnet.NetStandard/Packets/MqttPingRespPacket.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Packets +namespace MQTTnet.Packets { public sealed class MqttPingRespPacket : MqttBasePacket { diff --git a/MQTTnet.Core/Packets/MqttPubAckPacket.cs b/Frameworks/MQTTnet.NetStandard/Packets/MqttPubAckPacket.cs similarity index 83% rename from MQTTnet.Core/Packets/MqttPubAckPacket.cs rename to Frameworks/MQTTnet.NetStandard/Packets/MqttPubAckPacket.cs index 9e07cd3..e7fe57b 100644 --- a/MQTTnet.Core/Packets/MqttPubAckPacket.cs +++ b/Frameworks/MQTTnet.NetStandard/Packets/MqttPubAckPacket.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Packets +namespace MQTTnet.Packets { public sealed class MqttPubAckPacket : MqttBasePublishPacket { diff --git a/MQTTnet.Core/Packets/MqttPubCompPacket.cs b/Frameworks/MQTTnet.NetStandard/Packets/MqttPubCompPacket.cs similarity index 83% rename from MQTTnet.Core/Packets/MqttPubCompPacket.cs rename to Frameworks/MQTTnet.NetStandard/Packets/MqttPubCompPacket.cs index 9b819fd..98dace7 100644 --- a/MQTTnet.Core/Packets/MqttPubCompPacket.cs +++ b/Frameworks/MQTTnet.NetStandard/Packets/MqttPubCompPacket.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Packets +namespace MQTTnet.Packets { public sealed class MqttPubCompPacket : MqttBasePublishPacket { diff --git a/MQTTnet.Core/Packets/MqttPubRecPacket.cs b/Frameworks/MQTTnet.NetStandard/Packets/MqttPubRecPacket.cs similarity index 83% rename from MQTTnet.Core/Packets/MqttPubRecPacket.cs rename to Frameworks/MQTTnet.NetStandard/Packets/MqttPubRecPacket.cs index 3b87655..86cd4b4 100644 --- a/MQTTnet.Core/Packets/MqttPubRecPacket.cs +++ b/Frameworks/MQTTnet.NetStandard/Packets/MqttPubRecPacket.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Packets +namespace MQTTnet.Packets { public sealed class MqttPubRecPacket : MqttBasePublishPacket { diff --git a/MQTTnet.Core/Packets/MqttPubRelPacket.cs b/Frameworks/MQTTnet.NetStandard/Packets/MqttPubRelPacket.cs similarity index 83% rename from MQTTnet.Core/Packets/MqttPubRelPacket.cs rename to Frameworks/MQTTnet.NetStandard/Packets/MqttPubRelPacket.cs index 9d92689..ed1d933 100644 --- a/MQTTnet.Core/Packets/MqttPubRelPacket.cs +++ b/Frameworks/MQTTnet.NetStandard/Packets/MqttPubRelPacket.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Packets +namespace MQTTnet.Packets { public sealed class MqttPubRelPacket : MqttBasePublishPacket { diff --git a/MQTTnet.Core/Packets/MqttPublishPacket.cs b/Frameworks/MQTTnet.NetStandard/Packets/MqttPublishPacket.cs similarity index 91% rename from MQTTnet.Core/Packets/MqttPublishPacket.cs rename to Frameworks/MQTTnet.NetStandard/Packets/MqttPublishPacket.cs index 573ff69..52fccee 100644 --- a/MQTTnet.Core/Packets/MqttPublishPacket.cs +++ b/Frameworks/MQTTnet.NetStandard/Packets/MqttPublishPacket.cs @@ -1,6 +1,6 @@ -using MQTTnet.Core.Protocol; +using MQTTnet.Protocol; -namespace MQTTnet.Core.Packets +namespace MQTTnet.Packets { public sealed class MqttPublishPacket : MqttBasePublishPacket { diff --git a/MQTTnet.Core/Packets/MqttSubAckPacket.cs b/Frameworks/MQTTnet.NetStandard/Packets/MqttSubAckPacket.cs similarity index 91% rename from MQTTnet.Core/Packets/MqttSubAckPacket.cs rename to Frameworks/MQTTnet.NetStandard/Packets/MqttSubAckPacket.cs index 05431a3..c4c1a88 100644 --- a/MQTTnet.Core/Packets/MqttSubAckPacket.cs +++ b/Frameworks/MQTTnet.NetStandard/Packets/MqttSubAckPacket.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; using System.Linq; -using MQTTnet.Core.Protocol; +using MQTTnet.Protocol; -namespace MQTTnet.Core.Packets +namespace MQTTnet.Packets { public sealed class MqttSubAckPacket : MqttBasePacket, IMqttPacketWithIdentifier { diff --git a/MQTTnet.Core/Packets/MqttSubscribePacket.cs b/Frameworks/MQTTnet.NetStandard/Packets/MqttSubscribePacket.cs similarity index 95% rename from MQTTnet.Core/Packets/MqttSubscribePacket.cs rename to Frameworks/MQTTnet.NetStandard/Packets/MqttSubscribePacket.cs index c911efc..25536e3 100644 --- a/MQTTnet.Core/Packets/MqttSubscribePacket.cs +++ b/Frameworks/MQTTnet.NetStandard/Packets/MqttSubscribePacket.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Linq; -namespace MQTTnet.Core.Packets +namespace MQTTnet.Packets { public sealed class MqttSubscribePacket : MqttBasePacket, IMqttPacketWithIdentifier { diff --git a/MQTTnet.Core/Packets/MqttUnsubAckPacket.cs b/Frameworks/MQTTnet.NetStandard/Packets/MqttUnsubAckPacket.cs similarity index 89% rename from MQTTnet.Core/Packets/MqttUnsubAckPacket.cs rename to Frameworks/MQTTnet.NetStandard/Packets/MqttUnsubAckPacket.cs index 3554fa9..4797d0a 100644 --- a/MQTTnet.Core/Packets/MqttUnsubAckPacket.cs +++ b/Frameworks/MQTTnet.NetStandard/Packets/MqttUnsubAckPacket.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Packets +namespace MQTTnet.Packets { public sealed class MqttUnsubAckPacket : MqttBasePacket, IMqttPacketWithIdentifier { diff --git a/MQTTnet.Core/Packets/MqttUnsubscribe.cs b/Frameworks/MQTTnet.NetStandard/Packets/MqttUnsubscribe.cs similarity index 94% rename from MQTTnet.Core/Packets/MqttUnsubscribe.cs rename to Frameworks/MQTTnet.NetStandard/Packets/MqttUnsubscribe.cs index 1e06e50..2c47cbb 100644 --- a/MQTTnet.Core/Packets/MqttUnsubscribe.cs +++ b/Frameworks/MQTTnet.NetStandard/Packets/MqttUnsubscribe.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace MQTTnet.Core.Packets +namespace MQTTnet.Packets { public sealed class MqttUnsubscribePacket : MqttBasePacket, IMqttPacketWithIdentifier { diff --git a/MQTTnet.Core/Protocol/MqttConnectReturnCode.cs b/Frameworks/MQTTnet.NetStandard/Protocol/MqttConnectReturnCode.cs similarity index 91% rename from MQTTnet.Core/Protocol/MqttConnectReturnCode.cs rename to Frameworks/MQTTnet.NetStandard/Protocol/MqttConnectReturnCode.cs index 604cd48..bffc4dc 100644 --- a/MQTTnet.Core/Protocol/MqttConnectReturnCode.cs +++ b/Frameworks/MQTTnet.NetStandard/Protocol/MqttConnectReturnCode.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Protocol +namespace MQTTnet.Protocol { public enum MqttConnectReturnCode { diff --git a/MQTTnet.Core/Protocol/MqttControlPacketType.cs b/Frameworks/MQTTnet.NetStandard/Protocol/MqttControlPacketType.cs similarity index 91% rename from MQTTnet.Core/Protocol/MqttControlPacketType.cs rename to Frameworks/MQTTnet.NetStandard/Protocol/MqttControlPacketType.cs index aa46b9d..adb58b6 100644 --- a/MQTTnet.Core/Protocol/MqttControlPacketType.cs +++ b/Frameworks/MQTTnet.NetStandard/Protocol/MqttControlPacketType.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Protocol +namespace MQTTnet.Protocol { public enum MqttControlPacketType { diff --git a/MQTTnet.Core/Protocol/MqttQualityOfServiceLevel.cs b/Frameworks/MQTTnet.NetStandard/Protocol/MqttQualityOfServiceLevel.cs similarity index 80% rename from MQTTnet.Core/Protocol/MqttQualityOfServiceLevel.cs rename to Frameworks/MQTTnet.NetStandard/Protocol/MqttQualityOfServiceLevel.cs index c19496a..579f72e 100644 --- a/MQTTnet.Core/Protocol/MqttQualityOfServiceLevel.cs +++ b/Frameworks/MQTTnet.NetStandard/Protocol/MqttQualityOfServiceLevel.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Protocol +namespace MQTTnet.Protocol { public enum MqttQualityOfServiceLevel { diff --git a/MQTTnet.Core/Protocol/MqttSubscribeReturnCode.cs b/Frameworks/MQTTnet.NetStandard/Protocol/MqttSubscribeReturnCode.cs similarity index 84% rename from MQTTnet.Core/Protocol/MqttSubscribeReturnCode.cs rename to Frameworks/MQTTnet.NetStandard/Protocol/MqttSubscribeReturnCode.cs index a561423..b256962 100644 --- a/MQTTnet.Core/Protocol/MqttSubscribeReturnCode.cs +++ b/Frameworks/MQTTnet.NetStandard/Protocol/MqttSubscribeReturnCode.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Protocol +namespace MQTTnet.Protocol { public enum MqttSubscribeReturnCode { diff --git a/MQTTnet.Core/Serializer/ByteReader.cs b/Frameworks/MQTTnet.NetStandard/Serializer/ByteReader.cs similarity index 96% rename from MQTTnet.Core/Serializer/ByteReader.cs rename to Frameworks/MQTTnet.NetStandard/Serializer/ByteReader.cs index ce7f709..ec1e3ea 100644 --- a/MQTTnet.Core/Serializer/ByteReader.cs +++ b/Frameworks/MQTTnet.NetStandard/Serializer/ByteReader.cs @@ -1,6 +1,6 @@ using System; -namespace MQTTnet.Core.Serializer +namespace MQTTnet.Serializer { public sealed class ByteReader { diff --git a/MQTTnet.Core/Serializer/ByteWriter.cs b/Frameworks/MQTTnet.NetStandard/Serializer/ByteWriter.cs similarity index 95% rename from MQTTnet.Core/Serializer/ByteWriter.cs rename to Frameworks/MQTTnet.NetStandard/Serializer/ByteWriter.cs index d6abec9..af961e1 100644 --- a/MQTTnet.Core/Serializer/ByteWriter.cs +++ b/Frameworks/MQTTnet.NetStandard/Serializer/ByteWriter.cs @@ -1,6 +1,6 @@ using System; -namespace MQTTnet.Core.Serializer +namespace MQTTnet.Serializer { public sealed class ByteWriter { diff --git a/MQTTnet.Core/Serializer/IMqttPacketSerializer.cs b/Frameworks/MQTTnet.NetStandard/Serializer/IMqttPacketSerializer.cs similarity index 72% rename from MQTTnet.Core/Serializer/IMqttPacketSerializer.cs rename to Frameworks/MQTTnet.NetStandard/Serializer/IMqttPacketSerializer.cs index 5834c53..6b46b52 100644 --- a/MQTTnet.Core/Serializer/IMqttPacketSerializer.cs +++ b/Frameworks/MQTTnet.NetStandard/Serializer/IMqttPacketSerializer.cs @@ -1,7 +1,7 @@ -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Packets; +using MQTTnet.Adapter; +using MQTTnet.Packets; -namespace MQTTnet.Core.Serializer +namespace MQTTnet.Serializer { public interface IMqttPacketSerializer { diff --git a/MQTTnet.Core/Serializer/MqttPacketReader.cs b/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketReader.cs similarity index 95% rename from MQTTnet.Core/Serializer/MqttPacketReader.cs rename to Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketReader.cs index 9fcae9e..caf2881 100644 --- a/MQTTnet.Core/Serializer/MqttPacketReader.cs +++ b/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketReader.cs @@ -4,12 +4,12 @@ using System.IO; using System.Text; using System.Threading; using System.Threading.Tasks; -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Exceptions; -using MQTTnet.Core.Protocol; -using MQTTnet.Core.Packets; +using MQTTnet.Adapter; +using MQTTnet.Exceptions; +using MQTTnet.Packets; +using MQTTnet.Protocol; -namespace MQTTnet.Core.Serializer +namespace MQTTnet.Serializer { public sealed class MqttPacketReader : BinaryReader { diff --git a/MQTTnet.Core/Serializer/MqttPacketSerializer.cs b/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketSerializer.cs similarity index 99% rename from MQTTnet.Core/Serializer/MqttPacketSerializer.cs rename to Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketSerializer.cs index 6c2fc56..ce45b3e 100644 --- a/MQTTnet.Core/Serializer/MqttPacketSerializer.cs +++ b/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketSerializer.cs @@ -3,12 +3,12 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Exceptions; -using MQTTnet.Core.Packets; -using MQTTnet.Core.Protocol; +using MQTTnet.Adapter; +using MQTTnet.Exceptions; +using MQTTnet.Packets; +using MQTTnet.Protocol; -namespace MQTTnet.Core.Serializer +namespace MQTTnet.Serializer { public sealed class MqttPacketSerializer : IMqttPacketSerializer { diff --git a/MQTTnet.Core/Serializer/MqttPacketWriter.cs b/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketWriter.cs similarity index 96% rename from MQTTnet.Core/Serializer/MqttPacketWriter.cs rename to Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketWriter.cs index 4c86f96..cdf7915 100644 --- a/MQTTnet.Core/Serializer/MqttPacketWriter.cs +++ b/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketWriter.cs @@ -1,10 +1,10 @@ using System; +using System.Collections.Generic; using System.IO; using System.Text; -using MQTTnet.Core.Protocol; -using System.Collections.Generic; +using MQTTnet.Protocol; -namespace MQTTnet.Core.Serializer +namespace MQTTnet.Serializer { public sealed class MqttPacketWriter : BinaryWriter { diff --git a/MQTTnet.Core/Serializer/MqttProtocolVersion.cs b/Frameworks/MQTTnet.NetStandard/Serializer/MqttProtocolVersion.cs similarity index 68% rename from MQTTnet.Core/Serializer/MqttProtocolVersion.cs rename to Frameworks/MQTTnet.NetStandard/Serializer/MqttProtocolVersion.cs index 6b8814a..15e698d 100644 --- a/MQTTnet.Core/Serializer/MqttProtocolVersion.cs +++ b/Frameworks/MQTTnet.NetStandard/Serializer/MqttProtocolVersion.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Serializer +namespace MQTTnet.Serializer { public enum MqttProtocolVersion { diff --git a/MQTTnet.Core/Server/CheckSubscriptionsResult.cs b/Frameworks/MQTTnet.NetStandard/Server/CheckSubscriptionsResult.cs similarity index 74% rename from MQTTnet.Core/Server/CheckSubscriptionsResult.cs rename to Frameworks/MQTTnet.NetStandard/Server/CheckSubscriptionsResult.cs index 625457f..9e2d1f0 100644 --- a/MQTTnet.Core/Server/CheckSubscriptionsResult.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/CheckSubscriptionsResult.cs @@ -1,6 +1,6 @@ -using MQTTnet.Core.Protocol; +using MQTTnet.Protocol; -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public class CheckSubscriptionsResult { diff --git a/MQTTnet.Core/Server/ConnectedMqttClient.cs b/Frameworks/MQTTnet.NetStandard/Server/ConnectedMqttClient.cs similarity index 72% rename from MQTTnet.Core/Server/ConnectedMqttClient.cs rename to Frameworks/MQTTnet.NetStandard/Server/ConnectedMqttClient.cs index d363351..ea1c746 100644 --- a/MQTTnet.Core/Server/ConnectedMqttClient.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/ConnectedMqttClient.cs @@ -1,6 +1,6 @@ -using MQTTnet.Core.Serializer; +using MQTTnet.Serializer; -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public class ConnectedMqttClient { diff --git a/MQTTnet.Core/Server/GetOrCreateClientSessionResult.cs b/Frameworks/MQTTnet.NetStandard/Server/GetOrCreateClientSessionResult.cs similarity index 84% rename from MQTTnet.Core/Server/GetOrCreateClientSessionResult.cs rename to Frameworks/MQTTnet.NetStandard/Server/GetOrCreateClientSessionResult.cs index 8f80272..8f5f085 100644 --- a/MQTTnet.Core/Server/GetOrCreateClientSessionResult.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/GetOrCreateClientSessionResult.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public sealed class GetOrCreateClientSessionResult { diff --git a/MQTTnet.Core/Server/IMqttServer.cs b/Frameworks/MQTTnet.NetStandard/Server/IMqttServer.cs similarity index 94% rename from MQTTnet.Core/Server/IMqttServer.cs rename to Frameworks/MQTTnet.NetStandard/Server/IMqttServer.cs index 936e897..3d0ccda 100644 --- a/MQTTnet.Core/Server/IMqttServer.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/IMqttServer.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public interface IMqttServer : IApplicationMessageReceiver, IApplicationMessagePublisher { diff --git a/MQTTnet.Core/Server/IMqttServerFactory.cs b/Frameworks/MQTTnet.NetStandard/Server/IMqttServerFactory.cs similarity index 72% rename from MQTTnet.Core/Server/IMqttServerFactory.cs rename to Frameworks/MQTTnet.NetStandard/Server/IMqttServerFactory.cs index 378dfb0..6e399ca 100644 --- a/MQTTnet.Core/Server/IMqttServerFactory.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/IMqttServerFactory.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Diagnostics; +using MQTTnet.Adapter; +using MQTTnet.Diagnostics; -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public interface IMqttServerFactory { diff --git a/MQTTnet.Core/Server/IMqttServerStorage.cs b/Frameworks/MQTTnet.NetStandard/Server/IMqttServerStorage.cs similarity index 90% rename from MQTTnet.Core/Server/IMqttServerStorage.cs rename to Frameworks/MQTTnet.NetStandard/Server/IMqttServerStorage.cs index 3cb518c..da6e6e2 100644 --- a/MQTTnet.Core/Server/IMqttServerStorage.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/IMqttServerStorage.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public interface IMqttServerStorage { diff --git a/MQTTnet.Core/Server/MqttApplicationMessageInterceptorContext.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttApplicationMessageInterceptorContext.cs similarity index 81% rename from MQTTnet.Core/Server/MqttApplicationMessageInterceptorContext.cs rename to Frameworks/MQTTnet.NetStandard/Server/MqttApplicationMessageInterceptorContext.cs index 218a02d..e5f8c3f 100644 --- a/MQTTnet.Core/Server/MqttApplicationMessageInterceptorContext.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttApplicationMessageInterceptorContext.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public class MqttApplicationMessageInterceptorContext { diff --git a/MQTTnet.Core/Server/MqttClientConnectedEventArgs.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientConnectedEventArgs.cs similarity index 91% rename from MQTTnet.Core/Server/MqttClientConnectedEventArgs.cs rename to Frameworks/MQTTnet.NetStandard/Server/MqttClientConnectedEventArgs.cs index 282e0f8..1ca3f40 100644 --- a/MQTTnet.Core/Server/MqttClientConnectedEventArgs.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientConnectedEventArgs.cs @@ -1,6 +1,6 @@ using System; -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public class MqttClientConnectedEventArgs : EventArgs { diff --git a/MQTTnet.Core/Server/MqttClientDisconnectedEventArgs.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientDisconnectedEventArgs.cs similarity index 91% rename from MQTTnet.Core/Server/MqttClientDisconnectedEventArgs.cs rename to Frameworks/MQTTnet.NetStandard/Server/MqttClientDisconnectedEventArgs.cs index b1e3d15..78372bc 100644 --- a/MQTTnet.Core/Server/MqttClientDisconnectedEventArgs.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientDisconnectedEventArgs.cs @@ -1,6 +1,6 @@ using System; -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public class MqttClientDisconnectedEventArgs : EventArgs { diff --git a/MQTTnet.Core/Server/MqttClientPendingMessagesQueue.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientPendingMessagesQueue.cs similarity index 95% rename from MQTTnet.Core/Server/MqttClientPendingMessagesQueue.cs rename to Frameworks/MQTTnet.NetStandard/Server/MqttClientPendingMessagesQueue.cs index bea6039..9e1a2cd 100644 --- a/MQTTnet.Core/Server/MqttClientPendingMessagesQueue.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientPendingMessagesQueue.cs @@ -2,13 +2,13 @@ using System.Collections.Concurrent; using System.Threading; using System.Threading.Tasks; -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Diagnostics; -using MQTTnet.Core.Exceptions; -using MQTTnet.Core.Packets; -using MQTTnet.Core.Protocol; +using MQTTnet.Adapter; +using MQTTnet.Diagnostics; +using MQTTnet.Exceptions; +using MQTTnet.Packets; +using MQTTnet.Protocol; -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public sealed class MqttClientPendingMessagesQueue { diff --git a/MQTTnet.Core/Server/MqttClientSession.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs similarity index 97% rename from MQTTnet.Core/Server/MqttClientSession.cs rename to Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs index 3646c40..cc88964 100644 --- a/MQTTnet.Core/Server/MqttClientSession.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs @@ -2,15 +2,15 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Diagnostics; -using MQTTnet.Core.Exceptions; -using MQTTnet.Core.Internal; -using MQTTnet.Core.Packets; -using MQTTnet.Core.Protocol; -using MQTTnet.Core.Serializer; - -namespace MQTTnet.Core.Server +using MQTTnet.Adapter; +using MQTTnet.Diagnostics; +using MQTTnet.Exceptions; +using MQTTnet.Internal; +using MQTTnet.Packets; +using MQTTnet.Protocol; +using MQTTnet.Serializer; + +namespace MQTTnet.Server { public sealed class MqttClientSession { diff --git a/MQTTnet.Core/Server/MqttClientSessionsManager.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs similarity index 97% rename from MQTTnet.Core/Server/MqttClientSessionsManager.cs rename to Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs index 6323522..61e19f7 100644 --- a/MQTTnet.Core/Server/MqttClientSessionsManager.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs @@ -3,15 +3,15 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Diagnostics; -using MQTTnet.Core.Exceptions; -using MQTTnet.Core.Internal; -using MQTTnet.Core.Packets; -using MQTTnet.Core.Protocol; -using MQTTnet.Core.Serializer; - -namespace MQTTnet.Core.Server +using MQTTnet.Adapter; +using MQTTnet.Diagnostics; +using MQTTnet.Exceptions; +using MQTTnet.Internal; +using MQTTnet.Packets; +using MQTTnet.Protocol; +using MQTTnet.Serializer; + +namespace MQTTnet.Server { public sealed class MqttClientSessionsManager { diff --git a/MQTTnet.Core/Server/MqttClientSubscribeResult.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSubscribeResult.cs similarity index 73% rename from MQTTnet.Core/Server/MqttClientSubscribeResult.cs rename to Frameworks/MQTTnet.NetStandard/Server/MqttClientSubscribeResult.cs index 17bfe9a..fe75c3b 100644 --- a/MQTTnet.Core/Server/MqttClientSubscribeResult.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSubscribeResult.cs @@ -1,6 +1,6 @@ -using MQTTnet.Core.Packets; +using MQTTnet.Packets; -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public class MqttClientSubscribeResult { diff --git a/MQTTnet.Core/Server/MqttClientSubscriptionsManager.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSubscriptionsManager.cs similarity index 97% rename from MQTTnet.Core/Server/MqttClientSubscriptionsManager.cs rename to Frameworks/MQTTnet.NetStandard/Server/MqttClientSubscriptionsManager.cs index 8d88ddc..8615630 100644 --- a/MQTTnet.Core/Server/MqttClientSubscriptionsManager.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSubscriptionsManager.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; -using MQTTnet.Core.Packets; -using MQTTnet.Core.Protocol; +using MQTTnet.Packets; +using MQTTnet.Protocol; -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public sealed class MqttClientSubscriptionsManager { diff --git a/MQTTnet.Core/Server/MqttConnectionValidatorContext.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttConnectionValidatorContext.cs similarity index 91% rename from MQTTnet.Core/Server/MqttConnectionValidatorContext.cs rename to Frameworks/MQTTnet.NetStandard/Server/MqttConnectionValidatorContext.cs index 83a1eab..a24d795 100644 --- a/MQTTnet.Core/Server/MqttConnectionValidatorContext.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttConnectionValidatorContext.cs @@ -1,6 +1,6 @@ -using MQTTnet.Core.Protocol; +using MQTTnet.Protocol; -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public class MqttConnectionValidatorContext { diff --git a/MQTTnet.Core/Server/MqttRetainedMessagesManager.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttRetainedMessagesManager.cs similarity index 98% rename from MQTTnet.Core/Server/MqttRetainedMessagesManager.cs rename to Frameworks/MQTTnet.NetStandard/Server/MqttRetainedMessagesManager.cs index cf66723..c837769 100644 --- a/MQTTnet.Core/Server/MqttRetainedMessagesManager.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttRetainedMessagesManager.cs @@ -3,10 +3,10 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; -using MQTTnet.Core.Packets; -using MQTTnet.Core.Diagnostics; +using MQTTnet.Diagnostics; +using MQTTnet.Packets; -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public sealed class MqttRetainedMessagesManager { diff --git a/MQTTnet.Core/Server/MqttServer.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttServer.cs similarity index 98% rename from MQTTnet.Core/Server/MqttServer.cs rename to Frameworks/MQTTnet.NetStandard/Server/MqttServer.cs index f934928..25dc2d3 100644 --- a/MQTTnet.Core/Server/MqttServer.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttServer.cs @@ -1,12 +1,12 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading; using System.Threading.Tasks; -using MQTTnet.Core.Adapter; -using System.Linq; -using MQTTnet.Core.Diagnostics; +using MQTTnet.Adapter; +using MQTTnet.Diagnostics; -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public class MqttServer : IMqttServer { diff --git a/MQTTnet.Core/Server/MqttServerDefaultEndpointOptions.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttServerDefaultEndpointOptions.cs similarity index 83% rename from MQTTnet.Core/Server/MqttServerDefaultEndpointOptions.cs rename to Frameworks/MQTTnet.NetStandard/Server/MqttServerDefaultEndpointOptions.cs index 04c4d73..6dc21b3 100644 --- a/MQTTnet.Core/Server/MqttServerDefaultEndpointOptions.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttServerDefaultEndpointOptions.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public sealed class MqttServerDefaultEndpointOptions { diff --git a/MQTTnet.Core/Server/MqttServerOptions.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttServerOptions.cs similarity index 90% rename from MQTTnet.Core/Server/MqttServerOptions.cs rename to Frameworks/MQTTnet.NetStandard/Server/MqttServerOptions.cs index 8988b11..d04725e 100644 --- a/MQTTnet.Core/Server/MqttServerOptions.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttServerOptions.cs @@ -1,8 +1,8 @@ using System; -using MQTTnet.Core.Packets; -using MQTTnet.Core.Protocol; +using MQTTnet.Packets; +using MQTTnet.Protocol; -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public class MqttServerOptions { diff --git a/MQTTnet.Core/Server/MqttServerOptionsBuilder.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttServerOptionsBuilder.cs similarity index 96% rename from MQTTnet.Core/Server/MqttServerOptionsBuilder.cs rename to Frameworks/MQTTnet.NetStandard/Server/MqttServerOptionsBuilder.cs index 692f7c1..f6cb0bb 100644 --- a/MQTTnet.Core/Server/MqttServerOptionsBuilder.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttServerOptionsBuilder.cs @@ -1,8 +1,8 @@ using System; -using MQTTnet.Core.Packets; -using MQTTnet.Core.Protocol; +using MQTTnet.Packets; +using MQTTnet.Protocol; -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public class MqttServerOptionsBuilder { diff --git a/MQTTnet.Core/Server/MqttServerOptionsExtensions.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttServerOptionsExtensions.cs similarity index 96% rename from MQTTnet.Core/Server/MqttServerOptionsExtensions.cs rename to Frameworks/MQTTnet.NetStandard/Server/MqttServerOptionsExtensions.cs index 4917018..0324624 100644 --- a/MQTTnet.Core/Server/MqttServerOptionsExtensions.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttServerOptionsExtensions.cs @@ -1,6 +1,6 @@ using System; -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public static class MqttServerOptionsExtensions { diff --git a/MQTTnet.Core/Server/MqttServerStartedEventArgs.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttServerStartedEventArgs.cs similarity index 75% rename from MQTTnet.Core/Server/MqttServerStartedEventArgs.cs rename to Frameworks/MQTTnet.NetStandard/Server/MqttServerStartedEventArgs.cs index 8f46bde..0820299 100644 --- a/MQTTnet.Core/Server/MqttServerStartedEventArgs.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttServerStartedEventArgs.cs @@ -1,6 +1,6 @@ using System; -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public class MqttServerStartedEventArgs : EventArgs { diff --git a/MQTTnet.Core/Server/MqttServerTlsEndpointOptions.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttServerTlsEndpointOptions.cs similarity index 85% rename from MQTTnet.Core/Server/MqttServerTlsEndpointOptions.cs rename to Frameworks/MQTTnet.NetStandard/Server/MqttServerTlsEndpointOptions.cs index 0fb3839..6c90a44 100644 --- a/MQTTnet.Core/Server/MqttServerTlsEndpointOptions.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttServerTlsEndpointOptions.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public sealed class MqttServerTlsEndpointOptions { diff --git a/MQTTnet.Core/Server/MqttSubscribeResult.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttSubscribeResult.cs similarity index 73% rename from MQTTnet.Core/Server/MqttSubscribeResult.cs rename to Frameworks/MQTTnet.NetStandard/Server/MqttSubscribeResult.cs index ef80af4..2de4004 100644 --- a/MQTTnet.Core/Server/MqttSubscribeResult.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttSubscribeResult.cs @@ -1,6 +1,6 @@ -using MQTTnet.Core.Packets; +using MQTTnet.Packets; -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public class MqttSubscribeResult { diff --git a/MQTTnet.Core/Server/MqttSubscriptionInterceptorContext.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttSubscriptionInterceptorContext.cs similarity index 93% rename from MQTTnet.Core/Server/MqttSubscriptionInterceptorContext.cs rename to Frameworks/MQTTnet.NetStandard/Server/MqttSubscriptionInterceptorContext.cs index 93282d3..e05dd21 100644 --- a/MQTTnet.Core/Server/MqttSubscriptionInterceptorContext.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttSubscriptionInterceptorContext.cs @@ -1,4 +1,4 @@ -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public class MqttSubscriptionInterceptorContext { diff --git a/MQTTnet.Core/Server/MqttTopicFilterComparer.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttTopicFilterComparer.cs similarity index 97% rename from MQTTnet.Core/Server/MqttTopicFilterComparer.cs rename to Frameworks/MQTTnet.NetStandard/Server/MqttTopicFilterComparer.cs index 987a71f..8244415 100644 --- a/MQTTnet.Core/Server/MqttTopicFilterComparer.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttTopicFilterComparer.cs @@ -1,6 +1,6 @@ using System; -namespace MQTTnet.Core.Server +namespace MQTTnet.Server { public static class MqttTopicFilterComparer { diff --git a/MQTTnet.Core/TopicFilter.cs b/Frameworks/MQTTnet.NetStandard/TopicFilter.cs similarity index 92% rename from MQTTnet.Core/TopicFilter.cs rename to Frameworks/MQTTnet.NetStandard/TopicFilter.cs index 6d5258f..b82fc71 100644 --- a/MQTTnet.Core/TopicFilter.cs +++ b/Frameworks/MQTTnet.NetStandard/TopicFilter.cs @@ -1,6 +1,6 @@ -using MQTTnet.Core.Protocol; +using MQTTnet.Protocol; -namespace MQTTnet.Core +namespace MQTTnet { public sealed class TopicFilter { diff --git a/MQTTnet.Core/TopicFilterBuilder.cs b/Frameworks/MQTTnet.NetStandard/TopicFilterBuilder.cs similarity index 93% rename from MQTTnet.Core/TopicFilterBuilder.cs rename to Frameworks/MQTTnet.NetStandard/TopicFilterBuilder.cs index bb8416c..38c8fbc 100644 --- a/MQTTnet.Core/TopicFilterBuilder.cs +++ b/Frameworks/MQTTnet.NetStandard/TopicFilterBuilder.cs @@ -1,7 +1,7 @@ -using MQTTnet.Core.Protocol; -using MQTTnet.Core.Exceptions; +using MQTTnet.Exceptions; +using MQTTnet.Protocol; -namespace MQTTnet.Core +namespace MQTTnet { public class TopicFilterBuilder { diff --git a/MQTTnet.Core/MQTTnet.Core.csproj b/MQTTnet.Core/MQTTnet.Core.csproj deleted file mode 100644 index 60afc30..0000000 --- a/MQTTnet.Core/MQTTnet.Core.csproj +++ /dev/null @@ -1,25 +0,0 @@ - - - - netstandard1.1 - MQTTnet.Core - MQTTnet.Core - False - Full - - - - - 0.0.0.0 - - - - - - - 2.5.3.0 - 2.5.3.0 - - - - \ No newline at end of file diff --git a/MQTTnet.sln b/MQTTnet.sln index 326fe7e..ceaa04f 100644 --- a/MQTTnet.sln +++ b/MQTTnet.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.27004.2008 +VisualStudioVersion = 15.0.27004.2009 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.Core.Tests", "Tests\MQTTnet.Core.Tests\MQTTnet.Core.Tests.csproj", "{A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}" EndProject @@ -9,8 +9,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{9248C2E1 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Frameworks", "Frameworks", "{32A630A7-2598-41D7-B625-204CD906F5FB}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.Core", "MQTTnet.Core\MQTTnet.Core.csproj", "{2ECB99E4-72D0-4C23-99BA-93D511D3967D}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MQTTnet.TestApp.UniversalWindows", "Tests\MQTTnet.TestApp.UniversalWindows\MQTTnet.TestApp.UniversalWindows.csproj", "{FF1F72D6-9524-4422-9497-3CC0002216ED}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.NetStandard", "Frameworks\MQTTnet.Netstandard\MQTTnet.NetStandard.csproj", "{3587E506-55A2-4EB3-99C7-DC01E42D25D2}" @@ -63,22 +61,6 @@ Global {A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}.Release|x64.Build.0 = Release|Any CPU {A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}.Release|x86.ActiveCfg = Release|Any CPU {A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}.Release|x86.Build.0 = Release|Any CPU - {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Debug|ARM.ActiveCfg = Debug|Any CPU - {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Debug|ARM.Build.0 = Debug|Any CPU - {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Debug|x64.ActiveCfg = Debug|Any CPU - {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Debug|x64.Build.0 = Debug|Any CPU - {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Debug|x86.ActiveCfg = Debug|Any CPU - {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Debug|x86.Build.0 = Debug|Any CPU - {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Release|Any CPU.Build.0 = Release|Any CPU - {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Release|ARM.ActiveCfg = Release|Any CPU - {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Release|ARM.Build.0 = Release|Any CPU - {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Release|x64.ActiveCfg = Release|Any CPU - {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Release|x64.Build.0 = Release|Any CPU - {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Release|x86.ActiveCfg = Release|Any CPU - {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Release|x86.Build.0 = Release|Any CPU {FF1F72D6-9524-4422-9497-3CC0002216ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {FF1F72D6-9524-4422-9497-3CC0002216ED}.Debug|Any CPU.Build.0 = Debug|Any CPU {FF1F72D6-9524-4422-9497-3CC0002216ED}.Debug|ARM.ActiveCfg = Debug|ARM diff --git a/Tests/MQTTnet.Core.Tests/ByteReaderTests.cs b/Tests/MQTTnet.Core.Tests/ByteReaderTests.cs index 76ff90b..e2173cb 100644 --- a/Tests/MQTTnet.Core.Tests/ByteReaderTests.cs +++ b/Tests/MQTTnet.Core.Tests/ByteReaderTests.cs @@ -1,5 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using MQTTnet.Core.Serializer; +using MQTTnet.Serializer; namespace MQTTnet.Core.Tests { diff --git a/Tests/MQTTnet.Core.Tests/ByteWriterTests.cs b/Tests/MQTTnet.Core.Tests/ByteWriterTests.cs index 6599193..881df5c 100644 --- a/Tests/MQTTnet.Core.Tests/ByteWriterTests.cs +++ b/Tests/MQTTnet.Core.Tests/ByteWriterTests.cs @@ -1,5 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using MQTTnet.Core.Serializer; +using MQTTnet.Serializer; namespace MQTTnet.Core.Tests { diff --git a/Tests/MQTTnet.Core.Tests/ExtensionTests.cs b/Tests/MQTTnet.Core.Tests/ExtensionTests.cs index 2f0966f..053b0ca 100644 --- a/Tests/MQTTnet.Core.Tests/ExtensionTests.cs +++ b/Tests/MQTTnet.Core.Tests/ExtensionTests.cs @@ -2,8 +2,8 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; -using MQTTnet.Core.Exceptions; -using MQTTnet.Core.Internal; +using MQTTnet.Exceptions; +using MQTTnet.Internal; namespace MQTTnet.Core.Tests { diff --git a/Tests/MQTTnet.Core.Tests/MqttApplicationMessageBuilderTests.cs b/Tests/MQTTnet.Core.Tests/MqttApplicationMessageBuilderTests.cs index c6a7017..59afcd6 100644 --- a/Tests/MQTTnet.Core.Tests/MqttApplicationMessageBuilderTests.cs +++ b/Tests/MQTTnet.Core.Tests/MqttApplicationMessageBuilderTests.cs @@ -2,7 +2,7 @@ using System.IO; using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; -using MQTTnet.Core.Protocol; +using MQTTnet.Protocol; namespace MQTTnet.Core.Tests { diff --git a/Tests/MQTTnet.Core.Tests/MqttPacketReaderTests.cs b/Tests/MQTTnet.Core.Tests/MqttPacketReaderTests.cs index 6800e6c..606d1da 100644 --- a/Tests/MQTTnet.Core.Tests/MqttPacketReaderTests.cs +++ b/Tests/MQTTnet.Core.Tests/MqttPacketReaderTests.cs @@ -1,7 +1,7 @@ using System.IO; using System.Threading; using Microsoft.VisualStudio.TestTools.UnitTesting; -using MQTTnet.Core.Serializer; +using MQTTnet.Serializer; namespace MQTTnet.Core.Tests { diff --git a/Tests/MQTTnet.Core.Tests/MqttPacketSerializerTests.cs b/Tests/MQTTnet.Core.Tests/MqttPacketSerializerTests.cs index bdd0751..01d19f1 100644 --- a/Tests/MQTTnet.Core.Tests/MqttPacketSerializerTests.cs +++ b/Tests/MQTTnet.Core.Tests/MqttPacketSerializerTests.cs @@ -3,10 +3,10 @@ using System.IO; using System.Text; using System.Threading; using Microsoft.VisualStudio.TestTools.UnitTesting; -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Packets; -using MQTTnet.Core.Protocol; -using MQTTnet.Core.Serializer; +using MQTTnet.Adapter; +using MQTTnet.Packets; +using MQTTnet.Protocol; +using MQTTnet.Serializer; namespace MQTTnet.Core.Tests { diff --git a/Tests/MQTTnet.Core.Tests/MqttServerTests.cs b/Tests/MQTTnet.Core.Tests/MqttServerTests.cs index 89cae3b..f1c8ff0 100644 --- a/Tests/MQTTnet.Core.Tests/MqttServerTests.cs +++ b/Tests/MQTTnet.Core.Tests/MqttServerTests.cs @@ -3,10 +3,10 @@ using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; -using MQTTnet.Core.Client; -using MQTTnet.Core.Diagnostics; -using MQTTnet.Core.Protocol; -using MQTTnet.Core.Server; +using MQTTnet.Diagnostics; +using MQTTnet.Protocol; +using MQTTnet.Server; +using MQTTnet.Client; namespace MQTTnet.Core.Tests { diff --git a/Tests/MQTTnet.Core.Tests/MqttSubscriptionsManagerTests.cs b/Tests/MQTTnet.Core.Tests/MqttSubscriptionsManagerTests.cs index f488543..2c24c48 100644 --- a/Tests/MQTTnet.Core.Tests/MqttSubscriptionsManagerTests.cs +++ b/Tests/MQTTnet.Core.Tests/MqttSubscriptionsManagerTests.cs @@ -1,7 +1,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using MQTTnet.Core.Packets; -using MQTTnet.Core.Protocol; -using MQTTnet.Core.Server; +using MQTTnet.Packets; +using MQTTnet.Protocol; +using MQTTnet.Server; namespace MQTTnet.Core.Tests { diff --git a/Tests/MQTTnet.Core.Tests/TestMqttCommunicationAdapter.cs b/Tests/MQTTnet.Core.Tests/TestMqttCommunicationAdapter.cs index 53a6f0f..2bac46b 100644 --- a/Tests/MQTTnet.Core.Tests/TestMqttCommunicationAdapter.cs +++ b/Tests/MQTTnet.Core.Tests/TestMqttCommunicationAdapter.cs @@ -3,9 +3,9 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Packets; -using MQTTnet.Core.Serializer; +using MQTTnet.Adapter; +using MQTTnet.Packets; +using MQTTnet.Serializer; namespace MQTTnet.Core.Tests { diff --git a/Tests/MQTTnet.Core.Tests/TestMqttCommunicationAdapterFactory.cs b/Tests/MQTTnet.Core.Tests/TestMqttCommunicationAdapterFactory.cs index 7da1e16..eb291f9 100644 --- a/Tests/MQTTnet.Core.Tests/TestMqttCommunicationAdapterFactory.cs +++ b/Tests/MQTTnet.Core.Tests/TestMqttCommunicationAdapterFactory.cs @@ -1,6 +1,6 @@ -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Client; -using MQTTnet.Core.Diagnostics; +using MQTTnet.Adapter; +using MQTTnet.Client; +using MQTTnet.Diagnostics; namespace MQTTnet.Core.Tests { diff --git a/Tests/MQTTnet.Core.Tests/TestMqttServerAdapter.cs b/Tests/MQTTnet.Core.Tests/TestMqttServerAdapter.cs index e65d9f8..ea53512 100644 --- a/Tests/MQTTnet.Core.Tests/TestMqttServerAdapter.cs +++ b/Tests/MQTTnet.Core.Tests/TestMqttServerAdapter.cs @@ -1,17 +1,17 @@ using System; using System.Threading.Tasks; -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Server; -using MQTTnet.Core.Client; -using MQTTnet.Core.Diagnostics; +using MQTTnet.Adapter; +using MQTTnet.Client; +using MQTTnet.Diagnostics; +using MQTTnet.Server; namespace MQTTnet.Core.Tests { public class TestMqttServerAdapter : IMqttServerAdapter { public event EventHandler ClientAccepted; - - public async Task ConnectTestClient(IMqttServer server, string clientId, MqttApplicationMessage willMessage = null) + + public async Task ConnectTestClient(IMqttServer server, string clientId, MqttApplicationMessage willMessage = null) { var adapterA = new TestMqttCommunicationAdapter(); var adapterB = new TestMqttCommunicationAdapter(); diff --git a/Tests/MQTTnet.Core.Tests/TopicFilterComparerTests.cs b/Tests/MQTTnet.Core.Tests/TopicFilterComparerTests.cs index c65dcab..be16921 100644 --- a/Tests/MQTTnet.Core.Tests/TopicFilterComparerTests.cs +++ b/Tests/MQTTnet.Core.Tests/TopicFilterComparerTests.cs @@ -1,5 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using MQTTnet.Core.Server; +using MQTTnet.Server; namespace MQTTnet.Core.Tests { diff --git a/Tests/MQTTnet.TestApp.AspNetCore2/Startup.cs b/Tests/MQTTnet.TestApp.AspNetCore2/Startup.cs index 5c9b32e..9e5f90a 100644 --- a/Tests/MQTTnet.TestApp.AspNetCore2/Startup.cs +++ b/Tests/MQTTnet.TestApp.AspNetCore2/Startup.cs @@ -6,8 +6,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; using MQTTnet.AspNetCore; -using MQTTnet.Core; -using MQTTnet.Core.Server; +using MQTTnet.Server; namespace MQTTnet.TestApp.AspNetCore2 { diff --git a/Tests/MQTTnet.TestApp.NetCore/ClientTest.cs b/Tests/MQTTnet.TestApp.NetCore/ClientTest.cs index dfd7d0d..09788cc 100644 --- a/Tests/MQTTnet.TestApp.NetCore/ClientTest.cs +++ b/Tests/MQTTnet.TestApp.NetCore/ClientTest.cs @@ -1,8 +1,7 @@ using System; using System.Text; using System.Threading.Tasks; -using MQTTnet.Core; -using MQTTnet.Core.Client; +using MQTTnet.Client; namespace MQTTnet.TestApp.NetCore { diff --git a/Tests/MQTTnet.TestApp.NetCore/ManagedClientTest.cs b/Tests/MQTTnet.TestApp.NetCore/ManagedClientTest.cs index 7f76b65..21d1fdf 100644 --- a/Tests/MQTTnet.TestApp.NetCore/ManagedClientTest.cs +++ b/Tests/MQTTnet.TestApp.NetCore/ManagedClientTest.cs @@ -1,12 +1,11 @@ using System; using System.Threading.Tasks; -using MQTTnet.Core; -using MQTTnet.Core.Client; -using MQTTnet.Core.ManagedClient; -using MQTTnet.Core.Protocol; using System.IO; using Newtonsoft.Json; using System.Collections.Generic; +using MQTTnet.Client; +using MQTTnet.ManagedClient; +using MQTTnet.Protocol; namespace MQTTnet.TestApp.NetCore { diff --git a/Frameworks/MQTTnet.NetStandard/Diagnostics/MqttNetConsoleLogger.cs b/Tests/MQTTnet.TestApp.NetCore/MqttNetConsoleLogger.cs similarity index 88% rename from Frameworks/MQTTnet.NetStandard/Diagnostics/MqttNetConsoleLogger.cs rename to Tests/MQTTnet.TestApp.NetCore/MqttNetConsoleLogger.cs index 3cc13c3..67eb69e 100644 --- a/Frameworks/MQTTnet.NetStandard/Diagnostics/MqttNetConsoleLogger.cs +++ b/Tests/MQTTnet.TestApp.NetCore/MqttNetConsoleLogger.cs @@ -1,8 +1,8 @@ using System; using System.Text; -using MQTTnet.Core.Diagnostics; +using MQTTnet.Diagnostics; -namespace MQTTnet.Diagnostics +namespace MQTTnet.TestApp.NetCore { public static class MqttNetConsoleLogger { @@ -10,8 +10,8 @@ namespace MQTTnet.Diagnostics public static void ForwardToConsole() { - MqttNetGlobalLog.LogMessagePublished -= PrintToConsole; - MqttNetGlobalLog.LogMessagePublished += PrintToConsole; + MqttNetGlobalLogger.LogMessagePublished -= PrintToConsole; + MqttNetGlobalLogger.LogMessagePublished += PrintToConsole; } private static void PrintToConsole(object sender, MqttNetLogMessagePublishedEventArgs e) diff --git a/Tests/MQTTnet.TestApp.NetCore/PerformanceTest.cs b/Tests/MQTTnet.TestApp.NetCore/PerformanceTest.cs index c6bbe04..3aba3c1 100644 --- a/Tests/MQTTnet.TestApp.NetCore/PerformanceTest.cs +++ b/Tests/MQTTnet.TestApp.NetCore/PerformanceTest.cs @@ -1,14 +1,13 @@ -using MQTTnet.Core; -using MQTTnet.Core.Client; -using MQTTnet.Core.Protocol; -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; -using MQTTnet.Core.Server; +using MQTTnet.Client; +using MQTTnet.Protocol; +using MQTTnet.Server; namespace MQTTnet.TestApp.NetCore { diff --git a/Tests/MQTTnet.TestApp.NetCore/Program.cs b/Tests/MQTTnet.TestApp.NetCore/Program.cs index fb02de8..0e4868a 100644 --- a/Tests/MQTTnet.TestApp.NetCore/Program.cs +++ b/Tests/MQTTnet.TestApp.NetCore/Program.cs @@ -1,11 +1,11 @@ -using MQTTnet.Core; -using MQTTnet.Core.Client; -using MQTTnet.Core.Server; -using System; +using System; using System.Collections.Generic; using System.IO; using System.Threading; using System.Threading.Tasks; +using MQTTnet.Client; +using MQTTnet.Diagnostics; +using MQTTnet.Server; using Newtonsoft.Json; namespace MQTTnet.TestApp.NetCore diff --git a/Tests/MQTTnet.TestApp.NetCore/ServerTest.cs b/Tests/MQTTnet.TestApp.NetCore/ServerTest.cs index 2328292..767db08 100644 --- a/Tests/MQTTnet.TestApp.NetCore/ServerTest.cs +++ b/Tests/MQTTnet.TestApp.NetCore/ServerTest.cs @@ -1,9 +1,9 @@ using System; using System.Text; using System.Threading.Tasks; -using MQTTnet.Core.Protocol; -using MQTTnet.Core.Server; using MQTTnet.Diagnostics; +using MQTTnet.Protocol; +using MQTTnet.Server; namespace MQTTnet.TestApp.NetCore { diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/JsonServerStorage.cs b/Tests/MQTTnet.TestApp.UniversalWindows/JsonServerStorage.cs index 9baafec..fbf5b66 100644 --- a/Tests/MQTTnet.TestApp.UniversalWindows/JsonServerStorage.cs +++ b/Tests/MQTTnet.TestApp.UniversalWindows/JsonServerStorage.cs @@ -1,8 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Threading.Tasks; -using MQTTnet.Core; -using MQTTnet.Core.Server; +using MQTTnet.Server; using Newtonsoft.Json; namespace MQTTnet.TestApp.UniversalWindows diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/MQTTnet.TestApp.UniversalWindows.csproj b/Tests/MQTTnet.TestApp.UniversalWindows/MQTTnet.TestApp.UniversalWindows.csproj index fa0763c..4445af3 100644 --- a/Tests/MQTTnet.TestApp.UniversalWindows/MQTTnet.TestApp.UniversalWindows.csproj +++ b/Tests/MQTTnet.TestApp.UniversalWindows/MQTTnet.TestApp.UniversalWindows.csproj @@ -131,10 +131,6 @@ {3587e506-55a2-4eb3-99c7-dc01e42d25d2} MQTTnet.NetStandard - - {2ecb99e4-72d0-4c23-99ba-93d511d3967d} - MQTTnet.Core - diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs b/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs index 6c7258b..5d943be 100644 --- a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs +++ b/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs @@ -5,13 +5,12 @@ using System.Threading.Tasks; using Windows.Security.Cryptography.Certificates; using Windows.UI.Core; using Windows.UI.Xaml; -using MQTTnet.Core; -using MQTTnet.Core.Client; -using MQTTnet.Core.Diagnostics; -using MQTTnet.Core.ManagedClient; -using MQTTnet.Core.Protocol; -using MQTTnet.Core.Server; +using MQTTnet.Client; +using MQTTnet.Diagnostics; using MQTTnet.Implementations; +using MQTTnet.ManagedClient; +using MQTTnet.Protocol; +using MQTTnet.Server; namespace MQTTnet.TestApp.UniversalWindows { @@ -26,7 +25,7 @@ namespace MQTTnet.TestApp.UniversalWindows { InitializeComponent(); - MqttNetGlobalLog.LogMessagePublished += OnTraceMessagePublished; + MqttNetGlobalLogger.LogMessagePublished += OnTraceMessagePublished; } private async void OnTraceMessagePublished(object sender, MqttNetLogMessagePublishedEventArgs e) @@ -250,7 +249,7 @@ namespace MQTTnet.TestApp.UniversalWindows { { // Write all trace messages to the console window. - MqttNetGlobalLog.LogMessagePublished += (s, e) => + MqttNetGlobalLogger.LogMessagePublished += (s, e) => { Console.WriteLine($">> [{e.TraceMessage.Timestamp:O}] [{e.TraceMessage.ThreadId}] [{e.TraceMessage.Source}] [{e.TraceMessage.Level}]: {e.TraceMessage.Message}"); if (e.TraceMessage.Exception != null) From ee6ec14bf8f69c9db7ff1ffe5c57f730c7d82ef1 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Sat, 25 Nov 2017 20:12:50 +0100 Subject: [PATCH 03/22] Add interface for server options. Add context class for connection validator (hide internal packets). --- Build/MQTTnet.AspNetCore.nuspec | 6 ++-- .../MqttWebSocketServerAdapter.cs | 2 +- .../ServiceCollectionExtensions.cs | 2 +- .../Adapter/IMqttServerAdapter.cs | 2 +- .../Implementations/MqttServerAdapter.Uwp.cs | 2 +- .../Implementations/MqttServerAdapter.cs | 2 +- .../MQTTnet.NetStandard/Server/IMqttServer.cs | 2 +- .../Server/IMqttServerOptions.cs | 16 ++++++++++ .../Server/MqttClientPendingMessagesQueue.cs | 4 +-- .../Server/MqttClientSession.cs | 4 +-- .../Server/MqttClientSessionsManager.cs | 19 ++++++++---- .../Server/MqttClientSubscriptionsManager.cs | 4 +-- .../Server/MqttRetainedMessagesManager.cs | 4 +-- .../MQTTnet.NetStandard/Server/MqttServer.cs | 4 +-- .../Server/MqttServerOptions.cs | 6 ++-- .../Server/MqttServerOptionsBuilder.cs | 6 ++-- .../Server/MqttServerOptionsExtensions.cs | 4 +-- .../TestMqttServerAdapter.cs | 2 +- Tests/MQTTnet.TestApp.NetCore/ServerTest.cs | 4 +-- .../MainPage.xaml.cs | 31 ++++++++++++------- 20 files changed, 75 insertions(+), 51 deletions(-) create mode 100644 Frameworks/MQTTnet.NetStandard/Server/IMqttServerOptions.cs diff --git a/Build/MQTTnet.AspNetCore.nuspec b/Build/MQTTnet.AspNetCore.nuspec index 3a862ba..1510b2d 100644 --- a/Build/MQTTnet.AspNetCore.nuspec +++ b/Build/MQTTnet.AspNetCore.nuspec @@ -2,7 +2,7 @@ MQTTnet.AspNetCore - 2.5.3 + 2.6.0 Christian Kratky Christian Kratky https://github.com/chkr1011/MQTTnet/blob/master/LICENSE @@ -10,13 +10,13 @@ https://raw.githubusercontent.com/chkr1011/MQTTnet/master/Images/Logo_128x128.png false This is a support library to integrate MQTTnet into AspNetCore. - * Updated to MQTTnet 2.5.3. + * Updated to MQTTnet 2.6.0. Copyright Christian Kratky 2016-2017 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 - + diff --git a/Frameworks/MQTTnet.AspnetCore/MqttWebSocketServerAdapter.cs b/Frameworks/MQTTnet.AspnetCore/MqttWebSocketServerAdapter.cs index 5af8b64..a2ca627 100644 --- a/Frameworks/MQTTnet.AspnetCore/MqttWebSocketServerAdapter.cs +++ b/Frameworks/MQTTnet.AspnetCore/MqttWebSocketServerAdapter.cs @@ -12,7 +12,7 @@ namespace MQTTnet.AspNetCore { public event EventHandler ClientAccepted; - public Task StartAsync(MqttServerOptions options) + public Task StartAsync(IMqttServerOptions options) { return Task.CompletedTask; } diff --git a/Frameworks/MQTTnet.AspnetCore/ServiceCollectionExtensions.cs b/Frameworks/MQTTnet.AspnetCore/ServiceCollectionExtensions.cs index a6af6eb..d4bdf39 100644 --- a/Frameworks/MQTTnet.AspnetCore/ServiceCollectionExtensions.cs +++ b/Frameworks/MQTTnet.AspnetCore/ServiceCollectionExtensions.cs @@ -9,7 +9,7 @@ namespace MQTTnet.AspNetCore { public static class ServiceCollectionExtensions { - public static IServiceCollection AddHostedMqttServer(this IServiceCollection services, MqttServerOptions options) + public static IServiceCollection AddHostedMqttServer(this IServiceCollection services, IMqttServerOptions options) { if (options == null) throw new ArgumentNullException(nameof(options)); diff --git a/Frameworks/MQTTnet.NetStandard/Adapter/IMqttServerAdapter.cs b/Frameworks/MQTTnet.NetStandard/Adapter/IMqttServerAdapter.cs index d4ea941..bd583f5 100644 --- a/Frameworks/MQTTnet.NetStandard/Adapter/IMqttServerAdapter.cs +++ b/Frameworks/MQTTnet.NetStandard/Adapter/IMqttServerAdapter.cs @@ -8,7 +8,7 @@ namespace MQTTnet.Adapter { event EventHandler ClientAccepted; - Task StartAsync(MqttServerOptions options); + Task StartAsync(IMqttServerOptions options); Task StopAsync(); } } diff --git a/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.Uwp.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.Uwp.cs index 3966edc..96fbae4 100644 --- a/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.Uwp.cs +++ b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.Uwp.cs @@ -21,7 +21,7 @@ namespace MQTTnet.Implementations public event EventHandler ClientAccepted; - public async Task StartAsync(MqttServerOptions options) + public async Task StartAsync(IMqttServerOptions options) { if (options == null) throw new ArgumentNullException(nameof(options)); diff --git a/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs index dadca44..d4ab095 100644 --- a/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs +++ b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs @@ -30,7 +30,7 @@ namespace MQTTnet.Implementations public event EventHandler ClientAccepted; - public Task StartAsync(MqttServerOptions options) + public Task StartAsync(IMqttServerOptions options) { if (_cancellationTokenSource != null) throw new InvalidOperationException("Server is already started."); diff --git a/Frameworks/MQTTnet.NetStandard/Server/IMqttServer.cs b/Frameworks/MQTTnet.NetStandard/Server/IMqttServer.cs index 3d0ccda..926ab9d 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/IMqttServer.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/IMqttServer.cs @@ -12,7 +12,7 @@ namespace MQTTnet.Server Task> GetConnectedClientsAsync(); - Task StartAsync(MqttServerOptions options); + Task StartAsync(IMqttServerOptions options); Task StopAsync(); } } \ No newline at end of file diff --git a/Frameworks/MQTTnet.NetStandard/Server/IMqttServerOptions.cs b/Frameworks/MQTTnet.NetStandard/Server/IMqttServerOptions.cs new file mode 100644 index 0000000..92c1bfb --- /dev/null +++ b/Frameworks/MQTTnet.NetStandard/Server/IMqttServerOptions.cs @@ -0,0 +1,16 @@ +using System; + +namespace MQTTnet.Server +{ + public interface IMqttServerOptions + { + Action ApplicationMessageInterceptor { get; } + int ConnectionBacklog { get; } + Action ConnectionValidator { get; } + TimeSpan DefaultCommunicationTimeout { get; } + MqttServerDefaultEndpointOptions DefaultEndpointOptions { get; } + IMqttServerStorage Storage { get; } + Action SubscriptionInterceptor { get; } + MqttServerTlsEndpointOptions TlsEndpointOptions { get; } + } +} \ No newline at end of file diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttClientPendingMessagesQueue.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientPendingMessagesQueue.cs index 9e1a2cd..a64dfbf 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttClientPendingMessagesQueue.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientPendingMessagesQueue.cs @@ -13,11 +13,11 @@ namespace MQTTnet.Server public sealed class MqttClientPendingMessagesQueue { private readonly BlockingCollection _pendingPublishPackets = new BlockingCollection(); - private readonly MqttServerOptions _options; + private readonly IMqttServerOptions _options; private readonly MqttClientSession _session; private readonly IMqttNetLogger _logger; - public MqttClientPendingMessagesQueue(MqttServerOptions options, MqttClientSession session, IMqttNetLogger logger) + public MqttClientPendingMessagesQueue(IMqttServerOptions options, MqttClientSession session, IMqttNetLogger logger) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _session = session ?? throw new ArgumentNullException(nameof(session)); diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs index cc88964..f871ad3 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs @@ -19,7 +19,7 @@ namespace MQTTnet.Server private readonly MqttClientSubscriptionsManager _subscriptionsManager; private readonly MqttClientSessionsManager _sessionsManager; private readonly MqttClientPendingMessagesQueue _pendingMessagesQueue; - private readonly MqttServerOptions _options; + private readonly IMqttServerOptions _options; private readonly IMqttNetLogger _logger; private IMqttChannelAdapter _adapter; @@ -28,7 +28,7 @@ namespace MQTTnet.Server public MqttClientSession( string clientId, - MqttServerOptions options, + IMqttServerOptions options, MqttClientSessionsManager sessionsManager, IMqttNetLogger logger) { diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs index 61e19f7..7d647d9 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs @@ -18,11 +18,11 @@ namespace MQTTnet.Server private readonly Dictionary _sessions = new Dictionary(); private readonly SemaphoreSlim _sessionsSemaphore = new SemaphoreSlim(1, 1); - private readonly MqttServerOptions _options; + private readonly IMqttServerOptions _options; private readonly MqttRetainedMessagesManager _retainedMessagesManager; private readonly IMqttNetLogger _logger; - public MqttClientSessionsManager(MqttServerOptions options, MqttRetainedMessagesManager retainedMessagesManager, IMqttNetLogger logger) + public MqttClientSessionsManager(IMqttServerOptions options, MqttRetainedMessagesManager retainedMessagesManager, IMqttNetLogger logger) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _options = options ?? throw new ArgumentNullException(nameof(options)); @@ -174,12 +174,19 @@ namespace MQTTnet.Server private MqttConnectReturnCode ValidateConnection(MqttConnectPacket connectPacket) { - if (_options.ConnectionValidator != null) + if (_options.ConnectionValidator == null) { - return _options.ConnectionValidator(connectPacket); + return MqttConnectReturnCode.ConnectionAccepted; } - - return MqttConnectReturnCode.ConnectionAccepted; + + var context = new MqttConnectionValidatorContext( + connectPacket.ClientId, + connectPacket.Username, + connectPacket.Password, + connectPacket.WillMessage); + + _options.ConnectionValidator(context); + return context.ReturnCode; } private async Task GetOrCreateClientSessionAsync(MqttConnectPacket connectPacket) diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSubscriptionsManager.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSubscriptionsManager.cs index 8615630..1276b06 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSubscriptionsManager.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSubscriptionsManager.cs @@ -8,9 +8,9 @@ namespace MQTTnet.Server public sealed class MqttClientSubscriptionsManager { private readonly Dictionary _subscriptions = new Dictionary(); - private readonly MqttServerOptions _options; + private readonly IMqttServerOptions _options; - public MqttClientSubscriptionsManager(MqttServerOptions options) + public MqttClientSubscriptionsManager(IMqttServerOptions options) { _options = options ?? throw new ArgumentNullException(nameof(options)); } diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttRetainedMessagesManager.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttRetainedMessagesManager.cs index c837769..0b8d669 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttRetainedMessagesManager.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttRetainedMessagesManager.cs @@ -13,9 +13,9 @@ namespace MQTTnet.Server private readonly Dictionary _retainedMessages = new Dictionary(); private readonly SemaphoreSlim _gate = new SemaphoreSlim(1, 1); private readonly IMqttNetLogger _logger; - private readonly MqttServerOptions _options; + private readonly IMqttServerOptions _options; - public MqttRetainedMessagesManager(MqttServerOptions options, IMqttNetLogger logger) + public MqttRetainedMessagesManager(IMqttServerOptions options, IMqttNetLogger logger) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _options = options ?? throw new ArgumentNullException(nameof(options)); diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttServer.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttServer.cs index 25dc2d3..42c6854 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttServer.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttServer.cs @@ -16,7 +16,7 @@ namespace MQTTnet.Server private MqttClientSessionsManager _clientSessionsManager; private MqttRetainedMessagesManager _retainedMessagesManager; private CancellationTokenSource _cancellationTokenSource; - private MqttServerOptions _options; + private IMqttServerOptions _options; public MqttServer(IEnumerable adapters, IMqttNetLogger logger) { @@ -52,7 +52,7 @@ namespace MQTTnet.Server } } - public async Task StartAsync(MqttServerOptions options) + public async Task StartAsync(IMqttServerOptions options) { _options = options ?? throw new ArgumentNullException(nameof(options)); diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttServerOptions.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttServerOptions.cs index d04725e..2b0a9a0 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttServerOptions.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttServerOptions.cs @@ -1,10 +1,8 @@ using System; -using MQTTnet.Packets; -using MQTTnet.Protocol; namespace MQTTnet.Server { - public class MqttServerOptions + public class MqttServerOptions : IMqttServerOptions { public MqttServerDefaultEndpointOptions DefaultEndpointOptions { get; } = new MqttServerDefaultEndpointOptions(); @@ -14,7 +12,7 @@ namespace MQTTnet.Server public TimeSpan DefaultCommunicationTimeout { get; set; } = TimeSpan.FromSeconds(15); - public Func ConnectionValidator { get; set; } + public Action ConnectionValidator { get; set; } public Action ApplicationMessageInterceptor { get; set; } diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttServerOptionsBuilder.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttServerOptionsBuilder.cs index f6cb0bb..34f36a9 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttServerOptionsBuilder.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttServerOptionsBuilder.cs @@ -1,6 +1,4 @@ using System; -using MQTTnet.Packets; -using MQTTnet.Protocol; namespace MQTTnet.Server { @@ -62,7 +60,7 @@ namespace MQTTnet.Server return this; } - public MqttServerOptionsBuilder WithConnectionValidator(Func value) + public MqttServerOptionsBuilder WithConnectionValidator(Action value) { _options.ConnectionValidator = value; return this; @@ -80,7 +78,7 @@ namespace MQTTnet.Server return this; } - public MqttServerOptions Build() + public IMqttServerOptions Build() { return _options; } diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttServerOptionsExtensions.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttServerOptionsExtensions.cs index 0324624..db93ef1 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttServerOptionsExtensions.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttServerOptionsExtensions.cs @@ -4,7 +4,7 @@ namespace MQTTnet.Server { public static class MqttServerOptionsExtensions { - public static int GetTlsEndpointPort(this MqttServerOptions options) + public static int GetTlsEndpointPort(this IMqttServerOptions options) { if (options == null) throw new ArgumentNullException(nameof(options)); @@ -16,7 +16,7 @@ namespace MQTTnet.Server return options.TlsEndpointOptions.Port.Value; } - public static int GetDefaultEndpointPort(this MqttServerOptions options) + public static int GetDefaultEndpointPort(this IMqttServerOptions options) { if (options == null) throw new ArgumentNullException(nameof(options)); diff --git a/Tests/MQTTnet.Core.Tests/TestMqttServerAdapter.cs b/Tests/MQTTnet.Core.Tests/TestMqttServerAdapter.cs index ea53512..a2fec80 100644 --- a/Tests/MQTTnet.Core.Tests/TestMqttServerAdapter.cs +++ b/Tests/MQTTnet.Core.Tests/TestMqttServerAdapter.cs @@ -62,7 +62,7 @@ namespace MQTTnet.Core.Tests ClientAccepted?.Invoke(this, new MqttServerAdapterClientAcceptedEventArgs(adapter)); } - public Task StartAsync(MqttServerOptions options) + public Task StartAsync(IMqttServerOptions options) { return Task.FromResult(0); } diff --git a/Tests/MQTTnet.TestApp.NetCore/ServerTest.cs b/Tests/MQTTnet.TestApp.NetCore/ServerTest.cs index 767db08..d4960d0 100644 --- a/Tests/MQTTnet.TestApp.NetCore/ServerTest.cs +++ b/Tests/MQTTnet.TestApp.NetCore/ServerTest.cs @@ -23,11 +23,9 @@ namespace MQTTnet.TestApp.NetCore { if (p.Username != "USER" || p.Password != "PASS") { - return MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword; + p.ReturnCode = MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword; } } - - return MqttConnectReturnCode.ConnectionAccepted; }, Storage = new RetainedMessageHandler(), diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs b/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs index 5d943be..a750b27 100644 --- a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs +++ b/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs @@ -354,20 +354,23 @@ namespace MQTTnet.TestApp.UniversalWindows { if (c.ClientId.Length < 10) { - return MqttConnectReturnCode.ConnectionRefusedIdentifierRejected; + c.ReturnCode = MqttConnectReturnCode.ConnectionRefusedIdentifierRejected; + return; } if (c.Username != "mySecretUser") { - return MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword; + c.ReturnCode = MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword; + return; } if (c.Password != "mySecretPassword") { - return MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword; + c.ReturnCode = MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword; + return; } - return MqttConnectReturnCode.ConnectionAccepted; + c.ReturnCode = MqttConnectReturnCode.ConnectionAccepted; }; var factory = new MqttFactory(); @@ -410,14 +413,15 @@ namespace MQTTnet.TestApp.UniversalWindows }; options.DefaultEndpointOptions.Port = 1884; - options.ConnectionValidator = packet => + options.ConnectionValidator = c => { - if (packet.ClientId != "Highlander") + if (c.ClientId != "Highlander") { - return MqttConnectReturnCode.ConnectionRefusedIdentifierRejected; + c.ReturnCode = MqttConnectReturnCode.ConnectionRefusedIdentifierRejected; + return; } - return MqttConnectReturnCode.ConnectionAccepted; + c.ReturnCode = MqttConnectReturnCode.ConnectionAccepted; }; var mqttServer = new MqttFactory().CreateMqttServer(); @@ -432,20 +436,23 @@ namespace MQTTnet.TestApp.UniversalWindows { if (c.ClientId.Length < 10) { - return MqttConnectReturnCode.ConnectionRefusedIdentifierRejected; + c.ReturnCode = MqttConnectReturnCode.ConnectionRefusedIdentifierRejected; + return; } if (c.Username != "mySecretUser") { - return MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword; + c.ReturnCode = MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword; + return; } if (c.Password != "mySecretPassword") { - return MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword; + c.ReturnCode = MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword; + return; } - return MqttConnectReturnCode.ConnectionAccepted; + c.ReturnCode = MqttConnectReturnCode.ConnectionAccepted; } }; } From 24ab285066e4761b4485ebd11f6c7c40a47d8b5e Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Sat, 25 Nov 2017 20:33:04 +0100 Subject: [PATCH 04/22] Update project settings --- Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj b/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj index 752ba94..f4018cb 100644 --- a/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj +++ b/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj @@ -16,6 +16,7 @@ true codeSigningKey.pfx + false From 611fabcd012d06a4698b90bddaeadf7587a5d2c0 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Sat, 25 Nov 2017 23:10:48 +0100 Subject: [PATCH 05/22] Performance optimizations --- .../Adapter/MqttChannelAdapter.cs | 13 +++--- .../Serializer/IMqttPacketSerializer.cs | 6 ++- .../Serializer/MqttPacketReader.cs | 22 +++++++--- .../Serializer/MqttPacketSerializer.cs | 40 ++++++++++--------- .../Serializer/MqttPacketWriter.cs | 7 ++-- .../Server/MqttClientSession.cs | 38 ++++++------------ .../Server/MqttClientSessionsManager.cs | 9 ++--- .../Server/MqttClientSubscriptionsManager.cs | 10 ++--- .../MqttPacketSerializerTests.cs | 24 ++++++++--- .../MqttSubscriptionsManagerTests.cs | 6 +-- .../PerformanceTest.cs | 20 +++++----- 11 files changed, 106 insertions(+), 89 deletions(-) diff --git a/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs b/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs index 53603fa..58ab452 100644 --- a/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs +++ b/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs @@ -60,8 +60,11 @@ namespace MQTTnet.Adapter _logger.Trace("TX >>> {0} [Timeout={1}]", packet, timeout); - var writeBuffer = PacketSerializer.Serialize(packet); - await _channel.SendStream.WriteAsync(writeBuffer, 0, writeBuffer.Length, cancellationToken).ConfigureAwait(false); + var chunks = PacketSerializer.Serialize(packet); + foreach (var chunk in chunks) + { + await _channel.SendStream.WriteAsync(chunk.Array, chunk.Offset, chunk.Count, cancellationToken).ConfigureAwait(false); + } } if (timeout > TimeSpan.Zero) @@ -114,7 +117,7 @@ namespace MQTTnet.Adapter { receivedMqttPacket?.Dispose(); } - }); + }).ConfigureAwait(false); return packet; } @@ -140,8 +143,8 @@ namespace MQTTnet.Adapter var readBytesCount = await stream.ReadAsync(body, offset, body.Length - offset, cancellationToken).ConfigureAwait(false); offset += readBytesCount; } while (offset < header.BodyLength); - - return new ReceivedMqttPacket(header, new MemoryStream(body, 0, body.Length)); + + return new ReceivedMqttPacket(header, new MemoryStream(body, 0, body.Length, false, true)); } private static async Task ExecuteAndWrapExceptionAsync(Func action) diff --git a/Frameworks/MQTTnet.NetStandard/Serializer/IMqttPacketSerializer.cs b/Frameworks/MQTTnet.NetStandard/Serializer/IMqttPacketSerializer.cs index 6b46b52..439460d 100644 --- a/Frameworks/MQTTnet.NetStandard/Serializer/IMqttPacketSerializer.cs +++ b/Frameworks/MQTTnet.NetStandard/Serializer/IMqttPacketSerializer.cs @@ -1,4 +1,6 @@ -using MQTTnet.Adapter; +using System; +using System.Collections.Generic; +using MQTTnet.Adapter; using MQTTnet.Packets; namespace MQTTnet.Serializer @@ -7,7 +9,7 @@ namespace MQTTnet.Serializer { MqttProtocolVersion ProtocolVersion { get; set; } - byte[] Serialize(MqttBasePacket mqttPacket); + IEnumerable> Serialize(MqttBasePacket mqttPacket); MqttBasePacket Deserialize(ReceivedMqttPacket receivedMqttPacket); } diff --git a/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketReader.cs b/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketReader.cs index caf2881..04ee01f 100644 --- a/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketReader.cs +++ b/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketReader.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.IO; using System.Text; using System.Threading; @@ -30,7 +29,7 @@ namespace MQTTnet.Serializer { return null; } - + var fixedHeader = (byte)buffer; var controlPacketType = (MqttControlPacketType)(fixedHeader >> 4); var bodyLength = ReadBodyLengthFromSource(stream, cancellationToken); @@ -57,12 +56,22 @@ namespace MQTTnet.Serializer public string ReadStringWithLengthPrefix() { var buffer = ReadWithLengthPrefix(); + if (buffer.Length == 0) + { + return string.Empty; + } + return Encoding.UTF8.GetString(buffer, 0, buffer.Length); } public byte[] ReadWithLengthPrefix() { var length = ReadUInt16(); + if (length == 0) + { + return new byte[0]; + } + return ReadBytes(length); } @@ -78,7 +87,7 @@ namespace MQTTnet.Serializer var value = 0; byte encodedByte; - var readBytes = new List(); + ////var readBytes = new List(); do { if (cancellationToken.IsCancellationRequested) @@ -87,19 +96,20 @@ namespace MQTTnet.Serializer } var buffer = stream.ReadByte(); - readBytes.Add(buffer); - if (buffer == -1) { throw new MqttCommunicationException("Connection closed while reading remaining length data."); } + ////readBytes.Add(buffer); + encodedByte = (byte)buffer; value += (byte)(encodedByte & 127) * multiplier; multiplier *= 128; if (multiplier > 128 * 128 * 128) { - throw new MqttProtocolViolationException($"Remaining length is invalid (Data={string.Join(",", readBytes)})."); + //throw new MqttProtocolViolationException($"Remaining length is invalid (Data={string.Join(",", readBytes)})."); + throw new MqttProtocolViolationException("Remaining length is invalid."); } } while ((encodedByte & 128) != 0); diff --git a/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketSerializer.cs b/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketSerializer.cs index ce45b3e..0b04114 100644 --- a/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketSerializer.cs +++ b/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketSerializer.cs @@ -1,12 +1,12 @@ -using System; +using MQTTnet.Adapter; +using MQTTnet.Exceptions; +using MQTTnet.Packets; +using MQTTnet.Protocol; +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; -using MQTTnet.Adapter; -using MQTTnet.Exceptions; -using MQTTnet.Packets; -using MQTTnet.Protocol; namespace MQTTnet.Serializer { @@ -17,25 +17,29 @@ namespace MQTTnet.Serializer public MqttProtocolVersion ProtocolVersion { get; set; } = MqttProtocolVersion.V311; - public byte[] Serialize(MqttBasePacket packet) + public IEnumerable> Serialize(MqttBasePacket packet) { if (packet == null) throw new ArgumentNullException(nameof(packet)); - using (var stream = new MemoryStream()) + using (var stream = new MemoryStream(128)) using (var writer = new MqttPacketWriter(stream)) { var fixedHeader = SerializePacket(packet, writer); - var headerBuffer = new List { fixedHeader }; - MqttPacketWriter.WriteRemainingLength((int)stream.Length, headerBuffer); - - var header = headerBuffer.ToArray(); - var body = stream.ToArray(); - - var buffer = new byte[header.Length + body.Length]; - Buffer.BlockCopy(header, 0, buffer, 0, header.Length); - Buffer.BlockCopy(body, 0, buffer, header.Length, body.Length); - - return buffer; + var remainingLength = (int)stream.Length; + writer.Write(fixedHeader); + MqttPacketWriter.WriteRemainingLength(remainingLength, writer); + var headerLength = (int)stream.Length - remainingLength; + +#if NET461 || NET452 || NETSTANDARD2_0 + var buffer = stream.GetBuffer(); +#else + var buffer = stream.ToArray(); +#endif + return new List> + { + new ArraySegment(buffer, remainingLength, headerLength), + new ArraySegment(buffer, 0, remainingLength) + }; } } diff --git a/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketWriter.cs b/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketWriter.cs index cdf7915..cb3d458 100644 --- a/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketWriter.cs +++ b/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketWriter.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.IO; using System.Text; using MQTTnet.Protocol; @@ -56,11 +55,11 @@ namespace MQTTnet.Serializer Write(value); } - public static void WriteRemainingLength(int length, List target) + public static void WriteRemainingLength(int length, BinaryWriter target) { if (length == 0) { - target.Add(0); + target.Write((byte)0); return; } @@ -75,7 +74,7 @@ namespace MQTTnet.Serializer encodedByte = encodedByte | 128; } - target.Add((byte)encodedByte); + target.Write((byte)encodedByte); } while (x > 0); } } diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs index f871ad3..275fcb1 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using MQTTnet.Adapter; @@ -14,8 +13,6 @@ namespace MQTTnet.Server { public sealed class MqttClientSession { - private readonly HashSet _unacknowledgedPublishPackets = new HashSet(); - private readonly MqttClientSubscriptionsManager _subscriptionsManager; private readonly MqttClientSessionsManager _sessionsManager; private readonly MqttClientPendingMessagesQueue _pendingMessagesQueue; @@ -99,21 +96,22 @@ namespace MQTTnet.Server if (willMessage != null) { _willMessage = null; //clear willmessage so it is send just once - await _sessionsManager.DispatchApplicationMessageAsync(this, willMessage); + await _sessionsManager.DispatchApplicationMessageAsync(this, willMessage).ConfigureAwait(false); } } } - public void EnqueuePublishPacket(MqttPublishPacket publishPacket) + public void EnqueueApplicationMessage(MqttApplicationMessage applicationMessage) { - if (publishPacket == null) throw new ArgumentNullException(nameof(publishPacket)); + if (applicationMessage == null) throw new ArgumentNullException(nameof(applicationMessage)); - var result = _subscriptionsManager.CheckSubscriptions(publishPacket); + var result = _subscriptionsManager.CheckSubscriptions(applicationMessage); if (!result.IsSubscribed) { return; } + var publishPacket = applicationMessage.ToPublishPacket(); publishPacket.QualityOfServiceLevel = result.QualityOfServiceLevel; _pendingMessagesQueue.Enqueue(publishPacket); } @@ -134,12 +132,12 @@ namespace MQTTnet.Server catch (MqttCommunicationException exception) { _logger.Warning(exception, "Client '{0}': Communication exception while processing client packets.", ClientId); - await StopAsync(); + await StopAsync().ConfigureAwait(false); } catch (Exception exception) { _logger.Error(exception, "Client '{0}': Unhandled exception while processing client packets.", ClientId); - await StopAsync(); + await StopAsync().ConfigureAwait(false); } } @@ -200,7 +198,7 @@ namespace MQTTnet.Server if (subscribeResult.CloseConnection) { await adapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, new MqttDisconnectPacket()).ConfigureAwait(false); - await StopAsync(); + await StopAsync().ConfigureAwait(false); } } @@ -209,7 +207,7 @@ namespace MQTTnet.Server var retainedMessages = await _sessionsManager.GetRetainedMessagesAsync(subscribePacket).ConfigureAwait(false); foreach (var publishPacket in retainedMessages) { - EnqueuePublishPacket(publishPacket.ToPublishPacket()); + EnqueueApplicationMessage(publishPacket); } } @@ -221,27 +219,22 @@ namespace MQTTnet.Server { case MqttQualityOfServiceLevel.AtMostOnce: { - await _sessionsManager.DispatchApplicationMessageAsync(this, applicationMessage); + await _sessionsManager.DispatchApplicationMessageAsync(this, applicationMessage).ConfigureAwait(false); return; } case MqttQualityOfServiceLevel.AtLeastOnce: { - await _sessionsManager.DispatchApplicationMessageAsync(this, applicationMessage); + await _sessionsManager.DispatchApplicationMessageAsync(this, applicationMessage).ConfigureAwait(false); await adapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, - new MqttPubAckPacket { PacketIdentifier = publishPacket.PacketIdentifier }); + new MqttPubAckPacket { PacketIdentifier = publishPacket.PacketIdentifier }).ConfigureAwait(false); return; } case MqttQualityOfServiceLevel.ExactlyOnce: { // QoS 2 is implement as method "B" [4.3.3 QoS 2: Exactly once delivery] - lock (_unacknowledgedPublishPackets) - { - _unacknowledgedPublishPackets.Add(publishPacket.PacketIdentifier); - } - - await _sessionsManager.DispatchApplicationMessageAsync(this, applicationMessage); + await _sessionsManager.DispatchApplicationMessageAsync(this, applicationMessage).ConfigureAwait(false); await adapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, new MqttPubRecPacket { PacketIdentifier = publishPacket.PacketIdentifier }).ConfigureAwait(false); @@ -255,11 +248,6 @@ namespace MQTTnet.Server private Task HandleIncomingPubRelPacketAsync(IMqttChannelAdapter adapter, MqttPubRelPacket pubRelPacket, CancellationToken cancellationToken) { - lock (_unacknowledgedPublishPackets) - { - _unacknowledgedPublishPackets.Remove(pubRelPacket.PacketIdentifier); - } - return adapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, new MqttPubCompPacket { PacketIdentifier = pubRelPacket.PacketIdentifier }); } } diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs index 7d647d9..defe5eb 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; using MQTTnet.Adapter; using MQTTnet.Diagnostics; using MQTTnet.Exceptions; -using MQTTnet.Internal; using MQTTnet.Packets; using MQTTnet.Protocol; using MQTTnet.Serializer; @@ -59,7 +58,7 @@ namespace MQTTnet.Server return; } - var clientSession = await GetOrCreateClientSessionAsync(connectPacket); + var clientSession = await GetOrCreateClientSessionAsync(connectPacket).ConfigureAwait(false); await clientAdapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, new MqttConnAckPacket { @@ -105,7 +104,7 @@ namespace MQTTnet.Server { foreach (var session in _sessions) { - await session.Value.StopAsync(); + await session.Value.StopAsync().ConfigureAwait(false); } _sessions.Clear(); @@ -162,7 +161,7 @@ namespace MQTTnet.Server { foreach (var clientSession in _sessions.Values.ToList()) { - clientSession.EnqueuePublishPacket(applicationMessage.ToPublishPacket()); + clientSession.EnqueueApplicationMessage(applicationMessage); } } } @@ -200,7 +199,7 @@ namespace MQTTnet.Server if (connectPacket.CleanSession) { _sessions.Remove(connectPacket.ClientId); - await clientSession.StopAsync(); + await clientSession.StopAsync().ConfigureAwait(false); clientSession = null; _logger.Trace("Stopped existing session of client '{0}'.", connectPacket.ClientId); diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSubscriptionsManager.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSubscriptionsManager.cs index 1276b06..73548ce 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSubscriptionsManager.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSubscriptionsManager.cs @@ -64,23 +64,23 @@ namespace MQTTnet.Server return unsubscribePacket.CreateResponse(); } - public CheckSubscriptionsResult CheckSubscriptions(MqttPublishPacket publishPacket) + public CheckSubscriptionsResult CheckSubscriptions(MqttApplicationMessage applicationMessage) { - if (publishPacket == null) throw new ArgumentNullException(nameof(publishPacket)); + if (applicationMessage == null) throw new ArgumentNullException(nameof(applicationMessage)); lock (_subscriptions) { foreach (var subscription in _subscriptions) { - if (!MqttTopicFilterComparer.IsMatch(publishPacket.Topic, subscription.Key)) + if (!MqttTopicFilterComparer.IsMatch(applicationMessage.Topic, subscription.Key)) { continue; } var effectiveQos = subscription.Value; - if (publishPacket.QualityOfServiceLevel < effectiveQos) + if (applicationMessage.QualityOfServiceLevel < effectiveQos) { - effectiveQos = publishPacket.QualityOfServiceLevel; + effectiveQos = applicationMessage.QualityOfServiceLevel; } return new CheckSubscriptionsResult diff --git a/Tests/MQTTnet.Core.Tests/MqttPacketSerializerTests.cs b/Tests/MQTTnet.Core.Tests/MqttPacketSerializerTests.cs index 01d19f1..25c9352 100644 --- a/Tests/MQTTnet.Core.Tests/MqttPacketSerializerTests.cs +++ b/Tests/MQTTnet.Core.Tests/MqttPacketSerializerTests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.Text; using System.Threading; @@ -392,9 +393,9 @@ namespace MQTTnet.Core.Tests private static void SerializeAndCompare(MqttBasePacket packet, string expectedBase64Value, MqttProtocolVersion protocolVersion = MqttProtocolVersion.V311) { var serializer = new MqttPacketSerializer { ProtocolVersion = protocolVersion }; - var buffer = serializer.Serialize(packet); - - Assert.AreEqual(expectedBase64Value, Convert.ToBase64String(buffer)); + var chunks = serializer.Serialize(packet); + + Assert.AreEqual(expectedBase64Value, Convert.ToBase64String(Join(chunks))); } private static void DeserializeAndCompare(MqttBasePacket packet, string expectedBase64Value) @@ -403,18 +404,29 @@ namespace MQTTnet.Core.Tests var buffer1 = serializer.Serialize(packet); - using (var headerStream = new MemoryStream(buffer1)) + using (var headerStream = new MemoryStream(Join(buffer1))) { var header = MqttPacketReader.ReadHeaderFromSource(headerStream, CancellationToken.None); - using (var bodyStream = new MemoryStream(buffer1, (int)headerStream.Position, header.BodyLength)) + using (var bodyStream = new MemoryStream(Join(buffer1), (int)headerStream.Position, header.BodyLength)) { var deserializedPacket = serializer.Deserialize(new ReceivedMqttPacket(header, bodyStream)); var buffer2 = serializer.Serialize(deserializedPacket); - Assert.AreEqual(expectedBase64Value, Convert.ToBase64String(buffer2)); + Assert.AreEqual(expectedBase64Value, Convert.ToBase64String(Join(buffer2))); } } } + + private static byte[] Join(IEnumerable> chunks) + { + var buffer = new MemoryStream(); + foreach (var chunk in chunks) + { + buffer.Write(chunk.Array, chunk.Offset, chunk.Count); + } + + return buffer.ToArray(); + } } } diff --git a/Tests/MQTTnet.Core.Tests/MqttSubscriptionsManagerTests.cs b/Tests/MQTTnet.Core.Tests/MqttSubscriptionsManagerTests.cs index 2c24c48..b6b68dc 100644 --- a/Tests/MQTTnet.Core.Tests/MqttSubscriptionsManagerTests.cs +++ b/Tests/MQTTnet.Core.Tests/MqttSubscriptionsManagerTests.cs @@ -18,7 +18,7 @@ namespace MQTTnet.Core.Tests sm.Subscribe(sp, ""); - var pp = new MqttPublishPacket + var pp = new MqttApplicationMessage { Topic = "A/B/C", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce @@ -37,7 +37,7 @@ namespace MQTTnet.Core.Tests sm.Subscribe(sp, ""); - var pp = new MqttPublishPacket + var pp = new MqttApplicationMessage { Topic = "A/B/X", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce @@ -56,7 +56,7 @@ namespace MQTTnet.Core.Tests sm.Subscribe(sp, ""); - var pp = new MqttPublishPacket + var pp = new MqttApplicationMessage { Topic = "A/B/C", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce diff --git a/Tests/MQTTnet.TestApp.NetCore/PerformanceTest.cs b/Tests/MQTTnet.TestApp.NetCore/PerformanceTest.cs index 3aba3c1..301e0fe 100644 --- a/Tests/MQTTnet.TestApp.NetCore/PerformanceTest.cs +++ b/Tests/MQTTnet.TestApp.NetCore/PerformanceTest.cs @@ -171,16 +171,16 @@ namespace MQTTnet.TestApp.NetCore var msgs = 0; var stopwatch = Stopwatch.StartNew(); - mqttServer.ApplicationMessageReceived += (sender, args) => - { - msgs++; - if (stopwatch.ElapsedMilliseconds > 1000) - { - Console.WriteLine($"received {msgs}"); - msgs = 0; - stopwatch.Restart(); - } - }; + ////mqttServer.ApplicationMessageReceived += (sender, args) => + ////{ + //// msgs++; + //// if (stopwatch.ElapsedMilliseconds > 1000) + //// { + //// Console.WriteLine($"received {msgs}"); + //// msgs = 0; + //// stopwatch.Restart(); + //// } + ////}; await mqttServer.StartAsync(new MqttServerOptions()); Console.WriteLine("Press any key to exit."); From 69781d822a73fd921869ffce337438be62ce728a Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Sun, 26 Nov 2017 22:57:56 +0100 Subject: [PATCH 06/22] Update docs, fix managed client connection issue --- Build/MQTTnet.nuspec | 11 ++- .../Adapter/MqttChannelAdapter.cs | 15 +++- .../ManagedClient/ManagedMqttClient.cs | 73 ++++++++++++------- .../Server/ConnectedMqttClient.cs | 7 +- .../Server/MqttClientSessionsManager.cs | 19 +++-- .../MqttNetConsoleLogger.cs | 47 +++++++----- Tests/MQTTnet.TestApp.NetCore/ServerTest.cs | 21 +++++- .../MainPage.xaml.cs | 8 +- 8 files changed, 140 insertions(+), 61 deletions(-) diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec index 2ebe29d..71a9d55 100644 --- a/Build/MQTTnet.nuspec +++ b/Build/MQTTnet.nuspec @@ -10,9 +10,14 @@ https://raw.githubusercontent.com/chkr1011/MQTTnet/master/Images/Logo_128x128.png false MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). - * Merged projects. -* Added a strong name for the assembly. - + * [Core] Merged projects (BREAKING CHANGE! But only namespace changes). +* [Core] Added a strong name for the assembly. +* [Core] Performance optimizations. +* [Core] Fixed a logging issue when dealing with IOExceptions. +* [Client] Fixed an issue in _ManagedClient_ which can cause the client to stop when publishing subscriptions. +* [Server] The application message interceptor can now delete any received application message. +* [Server] Added a ConnectionValidator context to align with other APIs. +* [Server] Added an interface for the _MqttServerOptions_. Copyright Christian Kratky 2016-2017 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 diff --git a/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs b/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs index 58ab452..bf89fab 100644 --- a/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs +++ b/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Net.Sockets; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -171,13 +172,25 @@ namespace MQTTnet.Adapter } catch (COMException comException) { - if ((uint)comException.HResult == ErrorOperationAborted) + if ((uint) comException.HResult == ErrorOperationAborted) { throw new OperationCanceledException(); } throw new MqttCommunicationException(comException); } + catch (IOException exception) + { + if (exception.InnerException is SocketException socketException) + { + if (socketException.SocketErrorCode == SocketError.ConnectionAborted) + { + throw new OperationCanceledException(); + } + } + + throw new MqttCommunicationException(exception); + } catch (Exception exception) { throw new MqttCommunicationException(exception); diff --git a/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs index 90db1dc..7ae7250 100644 --- a/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs +++ b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs @@ -142,33 +142,53 @@ namespace MQTTnet.ManagedClient { while (!cancellationToken.IsCancellationRequested) { - var connectionState = await ReconnectIfRequiredAsync().ConfigureAwait(false); - if (connectionState == ReconnectionResult.NotConnected) - { - _publishingCancellationToken?.Cancel(false); - _publishingCancellationToken = null; + await TryMaintainConnectionAsync(cancellationToken); + } + } + catch (OperationCanceledException) + { + } + catch (Exception exception) + { + _logger.Error(exception, "Unhandled exception while maintaining connection."); + } + finally + { + await _mqttClient.DisconnectAsync().ConfigureAwait(false); + _logger.Info("Stopped"); + } + } - await Task.Delay(_options.AutoReconnectDelay, cancellationToken).ConfigureAwait(false); - continue; - } + private async Task TryMaintainConnectionAsync(CancellationToken cancellationToken) + { + try + { + var connectionState = await ReconnectIfRequiredAsync().ConfigureAwait(false); + if (connectionState == ReconnectionResult.NotConnected) + { + _publishingCancellationToken?.Cancel(false); + _publishingCancellationToken = null; - if (connectionState == ReconnectionResult.Reconnected || _subscriptionsNotPushed) - { - await PushSubscriptionsAsync(); + await Task.Delay(_options.AutoReconnectDelay, cancellationToken).ConfigureAwait(false); + return; + } + + if (connectionState == ReconnectionResult.Reconnected || _subscriptionsNotPushed) + { + await PushSubscriptionsAsync().ConfigureAwait(false); - _publishingCancellationToken = new CancellationTokenSource(); + _publishingCancellationToken = new CancellationTokenSource(); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed - Task.Run(async () => await PublishQueuedMessagesAsync(_publishingCancellationToken.Token), _publishingCancellationToken.Token).ConfigureAwait(false); + Task.Run(async () => await PublishQueuedMessagesAsync(_publishingCancellationToken.Token).ConfigureAwait(false), _publishingCancellationToken.Token).ConfigureAwait(false); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed - continue; - } + return; + } - if (connectionState == ReconnectionResult.StillConnected) - { - await Task.Delay(TimeSpan.FromSeconds(1), _connectionCancellationToken.Token).ConfigureAwait(false); - } + if (connectionState == ReconnectionResult.StillConnected) + { + await Task.Delay(TimeSpan.FromSeconds(1), _connectionCancellationToken.Token).ConfigureAwait(false); } } catch (OperationCanceledException) @@ -182,11 +202,6 @@ namespace MQTTnet.ManagedClient { _logger.Error(exception, "Unhandled exception while maintaining connection."); } - finally - { - await _mqttClient.DisconnectAsync().ConfigureAwait(false); - _logger.Info("Stopped"); - } } private async Task PublishQueuedMessagesAsync(CancellationToken cancellationToken) @@ -206,16 +221,19 @@ namespace MQTTnet.ManagedClient continue; } - await TryPublishQueuedMessageAsync(message).ConfigureAwait(false); - await _storageManager.RemoveAsync(message).ConfigureAwait(false); + await TryPublishQueuedMessageAsync(message).ConfigureAwait(false); } } catch (OperationCanceledException) { } + catch (Exception exception) + { + _logger.Error(exception, "Unhandled exception while publishing queued application messages."); + } finally { - _logger.Info("Stopped publishing messages"); + _logger.Trace("Stopped publishing messages."); } } @@ -224,6 +242,7 @@ namespace MQTTnet.ManagedClient try { await _mqttClient.PublishAsync(message).ConfigureAwait(false); + await _storageManager.RemoveAsync(message).ConfigureAwait(false); } catch (MqttCommunicationException exception) { diff --git a/Frameworks/MQTTnet.NetStandard/Server/ConnectedMqttClient.cs b/Frameworks/MQTTnet.NetStandard/Server/ConnectedMqttClient.cs index ea1c746..ee3a55f 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/ConnectedMqttClient.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/ConnectedMqttClient.cs @@ -1,4 +1,5 @@ -using MQTTnet.Serializer; +using System; +using MQTTnet.Serializer; namespace MQTTnet.Server { @@ -7,5 +8,9 @@ namespace MQTTnet.Server public string ClientId { get; set; } public MqttProtocolVersion ProtocolVersion { get; set; } + + public TimeSpan LastPacketReceivedDuration { get; set; } + + public TimeSpan LastNonKeepAlivePacketReceivedDuration{ get; set; } } } diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs index defe5eb..870e5e0 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs @@ -120,6 +120,7 @@ namespace MQTTnet.Server await _sessionsSemaphore.WaitAsync().ConfigureAwait(false); try { + var now = DateTime.UtcNow; return _sessions.Where(s => s.Value.IsConnected).Select(s => new ConnectedMqttClient { ClientId = s.Value.ClientId, @@ -136,13 +137,21 @@ namespace MQTTnet.Server { try { - var interceptorContext = new MqttApplicationMessageInterceptorContext + if (_options.ApplicationMessageInterceptor != null) { - ApplicationMessage = applicationMessage - }; + var interceptorContext = new MqttApplicationMessageInterceptorContext + { + ApplicationMessage = applicationMessage + }; + + _options.ApplicationMessageInterceptor(interceptorContext); + applicationMessage = interceptorContext.ApplicationMessage; + } - _options.ApplicationMessageInterceptor?.Invoke(interceptorContext); - applicationMessage = interceptorContext.ApplicationMessage; + if (applicationMessage == null) + { + return; + } if (applicationMessage.Retain) { diff --git a/Tests/MQTTnet.TestApp.NetCore/MqttNetConsoleLogger.cs b/Tests/MQTTnet.TestApp.NetCore/MqttNetConsoleLogger.cs index 67eb69e..2713aa3 100644 --- a/Tests/MQTTnet.TestApp.NetCore/MqttNetConsoleLogger.cs +++ b/Tests/MQTTnet.TestApp.NetCore/MqttNetConsoleLogger.cs @@ -14,6 +14,17 @@ namespace MQTTnet.TestApp.NetCore MqttNetGlobalLogger.LogMessagePublished += PrintToConsole; } + public static void PrintToConsole(string message, ConsoleColor color) + { + lock (Lock) + { + var backupColor = Console.ForegroundColor; + Console.ForegroundColor = color; + Console.Write(message); + Console.ForegroundColor = backupColor; + } + } + private static void PrintToConsole(object sender, MqttNetLogMessagePublishedEventArgs e) { var output = new StringBuilder(); @@ -23,28 +34,24 @@ namespace MQTTnet.TestApp.NetCore output.AppendLine(e.TraceMessage.Exception.ToString()); } - lock (Lock) + var color = ConsoleColor.Red; + switch (e.TraceMessage.Level) { - var backupColor = Console.ForegroundColor; - switch (e.TraceMessage.Level) - { - case MqttNetLogLevel.Error: - Console.ForegroundColor = ConsoleColor.Red; - break; - case MqttNetLogLevel.Warning: - Console.ForegroundColor = ConsoleColor.Yellow; - break; - case MqttNetLogLevel.Info: - Console.ForegroundColor = ConsoleColor.Green; - break; - case MqttNetLogLevel.Verbose: - Console.ForegroundColor = ConsoleColor.Gray; - break; - } - - Console.Write(output); - Console.ForegroundColor = backupColor; + case MqttNetLogLevel.Error: + color = ConsoleColor.Red; + break; + case MqttNetLogLevel.Warning: + color = ConsoleColor.Yellow; + break; + case MqttNetLogLevel.Info: + color = ConsoleColor.Green; + break; + case MqttNetLogLevel.Verbose: + color = ConsoleColor.Gray; + break; } + + PrintToConsole(output.ToString(), color); } } } \ No newline at end of file diff --git a/Tests/MQTTnet.TestApp.NetCore/ServerTest.cs b/Tests/MQTTnet.TestApp.NetCore/ServerTest.cs index d4960d0..8f89176 100644 --- a/Tests/MQTTnet.TestApp.NetCore/ServerTest.cs +++ b/Tests/MQTTnet.TestApp.NetCore/ServerTest.cs @@ -1,9 +1,9 @@ using System; using System.Text; using System.Threading.Tasks; -using MQTTnet.Diagnostics; using MQTTnet.Protocol; using MQTTnet.Server; +using Newtonsoft.Json.Linq; namespace MQTTnet.TestApp.NetCore { @@ -63,6 +63,25 @@ namespace MQTTnet.TestApp.NetCore //options.TlsEndpointOptions.IsEnabled = false; var mqttServer = new MqttFactory().CreateMqttServer(); + + mqttServer.ApplicationMessageReceived += (s, e) => + { + MqttNetConsoleLogger.PrintToConsole( + $"'{e.ClientId}' reported '{e.ApplicationMessage.Topic}' > '{Encoding.UTF8.GetString(e.ApplicationMessage.Payload)}'", + ConsoleColor.Magenta); + }; + + options.ApplicationMessageInterceptor = c => + { + var content = JObject.Parse(Encoding.UTF8.GetString(c.ApplicationMessage.Payload)); + var timestampProperty = content.Property("timestamp"); + if (timestampProperty != null && timestampProperty.Value.Type == JTokenType.Null) + { + timestampProperty.Value = DateTime.Now.ToString("O"); + c.ApplicationMessage.Payload = Encoding.UTF8.GetBytes(content.ToString()); + } + }; + mqttServer.ClientDisconnected += (s, e) => { Console.Write("Client disconnected event fired."); diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs b/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs index a750b27..00c6ffa 100644 --- a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs +++ b/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs @@ -407,12 +407,14 @@ namespace MQTTnet.TestApp.UniversalWindows { // Configure MQTT server. + var optionsBuilder = new MqttServerOptionsBuilder() + .WithConnectionBacklog(100) + .WithDefaultEndpointPort(1884); + var options = new MqttServerOptions { - ConnectionBacklog = 100 }; - options.DefaultEndpointOptions.Port = 1884; options.ConnectionValidator = c => { if (c.ClientId != "Highlander") @@ -425,7 +427,7 @@ namespace MQTTnet.TestApp.UniversalWindows }; var mqttServer = new MqttFactory().CreateMqttServer(); - await mqttServer.StartAsync(options); + await mqttServer.StartAsync(optionsBuilder.Build()); } { From bc959a8c3dcb676b72ae40768cc58da54d587090 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Mon, 27 Nov 2017 00:25:45 +0100 Subject: [PATCH 07/22] Performance optimizations --- .../MQTTnet.AspnetCore.csproj | 4 ++ .../Adapter/MqttChannelAdapter.cs | 12 ++--- .../Internal/TaskExtensions.cs | 18 ++++--- .../MQTTnet.Netstandard.csproj | 4 ++ .../Server/MqttClientSession.cs | 8 +-- .../Server/MqttClientSessionsManager.cs | 2 +- README.md | 2 +- .../PerformanceTest.cs | 54 +++++-------------- 8 files changed, 44 insertions(+), 60 deletions(-) diff --git a/Frameworks/MQTTnet.AspnetCore/MQTTnet.AspnetCore.csproj b/Frameworks/MQTTnet.AspnetCore/MQTTnet.AspnetCore.csproj index 5556b11..fbde3f2 100644 --- a/Frameworks/MQTTnet.AspnetCore/MQTTnet.AspnetCore.csproj +++ b/Frameworks/MQTTnet.AspnetCore/MQTTnet.AspnetCore.csproj @@ -6,6 +6,10 @@ 2.5.2.0 + + RELEASE;NETSTANDARD2_0 + + diff --git a/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs b/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs index bf89fab..2a9815d 100644 --- a/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs +++ b/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs @@ -31,23 +31,23 @@ namespace MQTTnet.Adapter public IMqttPacketSerializer PacketSerializer { get; } - public async Task ConnectAsync(TimeSpan timeout) + public Task ConnectAsync(TimeSpan timeout) { _logger.Info("Connecting [Timeout={0}]", timeout); - await ExecuteAndWrapExceptionAsync(() => _channel.ConnectAsync().TimeoutAfter(timeout)); + return ExecuteAndWrapExceptionAsync(() => _channel.ConnectAsync().TimeoutAfter(timeout)); } - public async Task DisconnectAsync(TimeSpan timeout) + public Task DisconnectAsync(TimeSpan timeout) { _logger.Info("Disconnecting [Timeout={0}]", timeout); - await ExecuteAndWrapExceptionAsync(() => _channel.DisconnectAsync().TimeoutAfter(timeout)); + return ExecuteAndWrapExceptionAsync(() => _channel.DisconnectAsync().TimeoutAfter(timeout)); } - public async Task SendPacketsAsync(TimeSpan timeout, CancellationToken cancellationToken, IEnumerable packets) + public Task SendPacketsAsync(TimeSpan timeout, CancellationToken cancellationToken, IEnumerable packets) { - await ExecuteAndWrapExceptionAsync(async () => + return ExecuteAndWrapExceptionAsync(async () => { await _semaphore.WaitAsync(cancellationToken).ConfigureAwait(false); try diff --git a/Frameworks/MQTTnet.NetStandard/Internal/TaskExtensions.cs b/Frameworks/MQTTnet.NetStandard/Internal/TaskExtensions.cs index 6acb71e..bfa01bd 100644 --- a/Frameworks/MQTTnet.NetStandard/Internal/TaskExtensions.cs +++ b/Frameworks/MQTTnet.NetStandard/Internal/TaskExtensions.cs @@ -9,13 +9,15 @@ namespace MQTTnet.Internal { public static async Task TimeoutAfter(this Task task, TimeSpan timeout) { - using (var cancellationTokenSource = new CancellationTokenSource()) + if (task == null) throw new ArgumentNullException(nameof(task)); + + using (var timeoutCts = new CancellationTokenSource()) { try { - var timeoutTask = Task.Delay(timeout, cancellationTokenSource.Token); + var timeoutTask = Task.Delay(timeout, timeoutCts.Token); var finishedTask = await Task.WhenAny(timeoutTask, task).ConfigureAwait(false); - + if (finishedTask == timeoutTask) { throw new MqttCommunicationTimedOutException(); @@ -33,18 +35,20 @@ namespace MQTTnet.Internal } finally { - cancellationTokenSource.Cancel(); + timeoutCts.Cancel(); } } } public static async Task TimeoutAfter(this Task task, TimeSpan timeout) { - using (var cancellationTokenSource = new CancellationTokenSource()) + if (task == null) throw new ArgumentNullException(nameof(task)); + + using (var timeoutCts = new CancellationTokenSource()) { try { - var timeoutTask = Task.Delay(timeout, cancellationTokenSource.Token); + var timeoutTask = Task.Delay(timeout, timeoutCts.Token); var finishedTask = await Task.WhenAny(timeoutTask, task).ConfigureAwait(false); if (finishedTask == timeoutTask) @@ -66,7 +70,7 @@ namespace MQTTnet.Internal } finally { - cancellationTokenSource.Cancel(); + timeoutCts.Cancel(); } } } diff --git a/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj b/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj index f4018cb..abcc865 100644 --- a/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj +++ b/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj @@ -36,6 +36,10 @@ + + RELEASE;NETSTANDARD1_3 + + diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs index 275fcb1..c5f16a9 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs @@ -143,14 +143,14 @@ namespace MQTTnet.Server private Task ProcessReceivedPacketAsync(IMqttChannelAdapter adapter, MqttBasePacket packet, CancellationToken cancellationToken) { - if (packet is MqttPingReqPacket) + if (packet is MqttPublishPacket publishPacket) { - return adapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, new MqttPingRespPacket()); + return HandleIncomingPublishPacketAsync(adapter, publishPacket, cancellationToken); } - if (packet is MqttPublishPacket publishPacket) + if (packet is MqttPingReqPacket) { - return HandleIncomingPublishPacketAsync(adapter, publishPacket, cancellationToken); + return adapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, new MqttPingRespPacket()); } if (packet is MqttPubRelPacket pubRelPacket) diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs index 870e5e0..f65ed2b 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs @@ -168,7 +168,7 @@ namespace MQTTnet.Server lock (_sessions) { - foreach (var clientSession in _sessions.Values.ToList()) + foreach (var clientSession in _sessions.Values) { clientSession.EnqueueApplicationMessage(applicationMessage); } diff --git a/README.md b/README.md index 57dfce2..5d3e186 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ MQTTnet is a high performance .NET library for MQTT based communication. It prov * TLS 1.2 support for client and server (but not UWP servers) * Extensible communication channels (i.e. In-Memory, TCP, TCP+TLS, WS) * Lightweight (only the low level implementation of MQTT, no overhead) -* Performance optimized (processing ~27.000 messages / second)* +* Performance optimized (processing ~30.000 messages / second)* * Interfaces included for mocking and testing * Access to internal trace messages * Unit tested (70+ tests) diff --git a/Tests/MQTTnet.TestApp.NetCore/PerformanceTest.cs b/Tests/MQTTnet.TestApp.NetCore/PerformanceTest.cs index 301e0fe..1c72b06 100644 --- a/Tests/MQTTnet.TestApp.NetCore/PerformanceTest.cs +++ b/Tests/MQTTnet.TestApp.NetCore/PerformanceTest.cs @@ -43,33 +43,6 @@ namespace MQTTnet.TestApp.NetCore var client = new MqttFactory().CreateMqttClient(); - client.Connected += async (s, e) => - { - Console.WriteLine("### CONNECTED WITH SERVER ###"); - - await client.SubscribeAsync(new List - { - new TopicFilter("#") - }); - - Console.WriteLine("### SUBSCRIBED ###"); - }; - - client.Disconnected += async (s, e) => - { - Console.WriteLine("### DISCONNECTED FROM SERVER ###"); - await Task.Delay(TimeSpan.FromSeconds(5)); - - try - { - await client.ConnectAsync(options); - } - catch - { - Console.WriteLine("### RECONNECTING FAILED ###"); - } - }; - try { await client.ConnectAsync(options); @@ -79,24 +52,12 @@ namespace MQTTnet.TestApp.NetCore Console.WriteLine("### CONNECTING FAILED ###" + Environment.NewLine + exception); } - Console.WriteLine("### WAITING FOR APPLICATION MESSAGES ###"); - - var testMessageCount = 10000; var message = CreateMessage(); - var stopwatch = Stopwatch.StartNew(); - for (var i = 0; i < testMessageCount; i++) - { - await client.PublishAsync(message); - } - - stopwatch.Stop(); - Console.WriteLine($"Sent 10.000 messages within {stopwatch.ElapsedMilliseconds} ms ({stopwatch.ElapsedMilliseconds / (float)testMessageCount} ms / message)."); - var messages = new[] { message }; - var sentMessagesCount = 0; - stopwatch.Restart(); + var stopwatch = Stopwatch.StartNew(); + var sentMessagesCount = 0; while (stopwatch.ElapsedMilliseconds < 1000) { await client.PublishAsync(messages).ConfigureAwait(false); @@ -104,6 +65,17 @@ namespace MQTTnet.TestApp.NetCore } Console.WriteLine($"Sending {sentMessagesCount} messages per second."); + + stopwatch.Restart(); + + var testMessageCount = 10000; + for (var i = 0; i < testMessageCount; i++) + { + await client.PublishAsync(message); + } + + stopwatch.Stop(); + Console.WriteLine($"Sent 10.000 messages within {stopwatch.ElapsedMilliseconds} ms ({stopwatch.ElapsedMilliseconds / (float)testMessageCount} ms / message)."); var last = DateTime.Now; var msgCount = 0; From 0ee3c8e135261567ac5755aa262c586039e4a3e9 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Tue, 28 Nov 2017 21:19:30 +0100 Subject: [PATCH 08/22] Add statistics of last sent packets to the _ConnectedClient_. --- .../Adapter/MqttChannelAdapter.cs | 4 +- .../MQTTnet.NetStandard/Client/MqttClient.cs | 56 ++++++--------- .../Diagnostics/MqttNetLogger.cs | 2 +- .../Implementations/MqttServerAdapter.cs | 39 +++++++++-- .../Server/ConnectedMqttClient.cs | 4 +- .../Server/MqttClientSession.cs | 69 ++++++++++++++----- .../Server/MqttClientSessionsManager.cs | 5 +- Tests/MQTTnet.TestApp.NetCore/Program.cs | 24 ++++++- 8 files changed, 136 insertions(+), 67 deletions(-) diff --git a/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs b/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs index 2a9815d..af39958 100644 --- a/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs +++ b/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs @@ -33,14 +33,14 @@ namespace MQTTnet.Adapter public Task ConnectAsync(TimeSpan timeout) { - _logger.Info("Connecting [Timeout={0}]", timeout); + _logger.Trace("Connecting [Timeout={0}]", timeout); return ExecuteAndWrapExceptionAsync(() => _channel.ConnectAsync().TimeoutAfter(timeout)); } public Task DisconnectAsync(TimeSpan timeout) { - _logger.Info("Disconnecting [Timeout={0}]", timeout); + _logger.Trace("Disconnecting [Timeout={0}]", timeout); return ExecuteAndWrapExceptionAsync(() => _channel.DisconnectAsync().TimeoutAfter(timeout)); } diff --git a/Frameworks/MQTTnet.NetStandard/Client/MqttClient.cs b/Frameworks/MQTTnet.NetStandard/Client/MqttClient.cs index a24fbff..b765870 100644 --- a/Frameworks/MQTTnet.NetStandard/Client/MqttClient.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/MqttClient.cs @@ -14,8 +14,6 @@ namespace MQTTnet.Client { public class MqttClient : IMqttClient { - private readonly HashSet _unacknowledgedPublishPackets = new HashSet(); - private readonly IMqttClientAdapterFactory _adapterFactory; private readonly MqttPacketDispatcher _packetDispatcher; private readonly IMqttNetLogger _logger; @@ -133,7 +131,7 @@ namespace MQTTnet.Client TopicFilters = topicFilters.ToList() }; - await SendAndReceiveAsync(unsubscribePacket); + await SendAndReceiveAsync(unsubscribePacket).ConfigureAwait(false); } public async Task PublishAsync(IEnumerable applicationMessages) @@ -141,21 +139,21 @@ namespace MQTTnet.Client ThrowIfNotConnected(); var publishPackets = applicationMessages.Select(m => m.ToPublishPacket()); + var packetGroups = publishPackets.GroupBy(p => p.QualityOfServiceLevel).OrderBy(g => g.Key); - foreach (var qosGroup in publishPackets.GroupBy(p => p.QualityOfServiceLevel)) + foreach (var qosGroup in packetGroups) { - var qosPackets = qosGroup.ToArray(); switch (qosGroup.Key) { case MqttQualityOfServiceLevel.AtMostOnce: { // No packet identifier is used for QoS 0 [3.3.2.2 Packet Identifier] - await _adapter.SendPacketsAsync(_options.CommunicationTimeout, _cancellationTokenSource.Token, qosPackets).ConfigureAwait(false); + await _adapter.SendPacketsAsync(_options.CommunicationTimeout, _cancellationTokenSource.Token, qosGroup).ConfigureAwait(false); break; } case MqttQualityOfServiceLevel.AtLeastOnce: { - foreach (var publishPacket in qosPackets) + foreach (var publishPacket in qosGroup) { publishPacket.PacketIdentifier = GetNewPacketIdentifier(); await SendAndReceiveAsync(publishPacket).ConfigureAwait(false); @@ -165,7 +163,7 @@ namespace MQTTnet.Client } case MqttQualityOfServiceLevel.ExactlyOnce: { - foreach (var publishPacket in qosPackets) + foreach (var publishPacket in qosGroup) { publishPacket.PacketIdentifier = GetNewPacketIdentifier(); var pubRecPacket = await SendAndReceiveAsync(publishPacket).ConfigureAwait(false); @@ -249,28 +247,28 @@ namespace MQTTnet.Client try { _logger.Info("Received <<< {0}", packet); - - if (packet is MqttPingReqPacket) + + if (packet is MqttPublishPacket publishPacket) { - await SendAsync(new MqttPingRespPacket()); + await ProcessReceivedPublishPacketAsync(publishPacket).ConfigureAwait(false); return; } - if (packet is MqttDisconnectPacket) + if (packet is MqttPingReqPacket) { - await DisconnectAsync(); + await SendAsync(new MqttPingRespPacket()).ConfigureAwait(false); return; } - if (packet is MqttPublishPacket publishPacket) + if (packet is MqttDisconnectPacket) { - await ProcessReceivedPublishPacket(publishPacket); + await DisconnectAsync().ConfigureAwait(false); return; } if (packet is MqttPubRelPacket pubRelPacket) { - await ProcessReceivedPubRelPacket(pubRelPacket); + await ProcessReceivedPubRelPacket(pubRelPacket).ConfigureAwait(false); return; } @@ -295,32 +293,25 @@ namespace MQTTnet.Client } } - private async Task ProcessReceivedPublishPacket(MqttPublishPacket publishPacket) + private Task ProcessReceivedPublishPacketAsync(MqttPublishPacket publishPacket) { if (publishPacket.QualityOfServiceLevel == MqttQualityOfServiceLevel.AtMostOnce) { FireApplicationMessageReceivedEvent(publishPacket); - return; + return Task.FromResult(0); } if (publishPacket.QualityOfServiceLevel == MqttQualityOfServiceLevel.AtLeastOnce) { FireApplicationMessageReceivedEvent(publishPacket); - await SendAsync(new MqttPubAckPacket { PacketIdentifier = publishPacket.PacketIdentifier }); - return; + return SendAsync(new MqttPubAckPacket { PacketIdentifier = publishPacket.PacketIdentifier }); } if (publishPacket.QualityOfServiceLevel == MqttQualityOfServiceLevel.ExactlyOnce) { // QoS 2 is implement as method "B" [4.3.3 QoS 2: Exactly once delivery] - lock (_unacknowledgedPublishPackets) - { - _unacknowledgedPublishPackets.Add(publishPacket.PacketIdentifier); - } - FireApplicationMessageReceivedEvent(publishPacket); - await SendAsync(new MqttPubRecPacket { PacketIdentifier = publishPacket.PacketIdentifier }); - return; + return SendAsync(new MqttPubRecPacket { PacketIdentifier = publishPacket.PacketIdentifier }); } throw new MqttCommunicationException("Received a not supported QoS level."); @@ -328,11 +319,6 @@ namespace MQTTnet.Client private Task ProcessReceivedPubRelPacket(MqttPubRelPacket pubRelPacket) { - lock (_unacknowledgedPublishPackets) - { - _unacknowledgedPublishPackets.Remove(pubRelPacket.PacketIdentifier); - } - return SendAsync(pubRelPacket.CreateResponse()); } @@ -454,7 +440,7 @@ namespace MQTTnet.Client { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run( - () => ProcessReceivedPacketAsync(packet), + async () => await ProcessReceivedPacketAsync(packet).ConfigureAwait(false), cancellationToken).ConfigureAwait(false); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } @@ -465,7 +451,7 @@ namespace MQTTnet.Client #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run( - async () => await ReceivePacketsAsync(cancellationToken), + async () => await ReceivePacketsAsync(cancellationToken).ConfigureAwait(false), cancellationToken).ConfigureAwait(false); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed @@ -479,7 +465,7 @@ namespace MQTTnet.Client { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run( - async () => await SendKeepAliveMessagesAsync(cancellationToken), + async () => await SendKeepAliveMessagesAsync(cancellationToken).ConfigureAwait(false), cancellationToken).ConfigureAwait(false); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } diff --git a/Frameworks/MQTTnet.NetStandard/Diagnostics/MqttNetLogger.cs b/Frameworks/MQTTnet.NetStandard/Diagnostics/MqttNetLogger.cs index 7d9b290..8ad1d4c 100644 --- a/Frameworks/MQTTnet.NetStandard/Diagnostics/MqttNetLogger.cs +++ b/Frameworks/MQTTnet.NetStandard/Diagnostics/MqttNetLogger.cs @@ -10,7 +10,7 @@ namespace MQTTnet.Diagnostics { _logId = logId; } - + public event EventHandler LogMessagePublished; public void Trace(string message, params object[] parameters) diff --git a/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs index d4ab095..a0441bc 100644 --- a/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs +++ b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs @@ -42,7 +42,7 @@ namespace MQTTnet.Implementations _defaultEndpointSocket.Bind(new IPEndPoint(IPAddress.Any, options.GetDefaultEndpointPort())); _defaultEndpointSocket.Listen(options.ConnectionBacklog); - Task.Run(() => AcceptDefaultEndpointConnectionsAsync(_cancellationTokenSource.Token), _cancellationTokenSource.Token); + Task.Run(async () => await AcceptDefaultEndpointConnectionsAsync(_cancellationTokenSource.Token).ConfigureAwait(false), _cancellationTokenSource.Token).ConfigureAwait(false); } if (options.TlsEndpointOptions.IsEnabled) @@ -62,7 +62,7 @@ namespace MQTTnet.Implementations _tlsEndpointSocket.Bind(new IPEndPoint(IPAddress.Any, options.GetTlsEndpointPort())); _tlsEndpointSocket.Listen(options.ConnectionBacklog); - Task.Run(() => AcceptTlsEndpointConnectionsAsync(_cancellationTokenSource.Token), _cancellationTokenSource.Token); + Task.Run(async () => await AcceptTlsEndpointConnectionsAsync(_cancellationTokenSource.Token).ConfigureAwait(false), _cancellationTokenSource.Token).ConfigureAwait(false); } return Task.FromResult(0); @@ -102,13 +102,29 @@ namespace MQTTnet.Implementations #else var clientSocket = await _defaultEndpointSocket.AcceptAsync().ConfigureAwait(false); #endif + var clientAdapter = new MqttChannelAdapter(new MqttTcpChannel(clientSocket, null), new MqttPacketSerializer(), _logger); ClientAccepted?.Invoke(this, new MqttServerAdapterClientAcceptedEventArgs(clientAdapter)); } + catch (ObjectDisposedException) + { + // It can happen that the listener socket is accessed after the cancellation token is already set and the listener socket is disposed. + } + catch (SocketException exception) + { + if (exception.SocketErrorCode == SocketError.OperationAborted) + { + return; + } + + _logger.Error(exception, "Error while accepting connection at default endpoint."); + } catch (Exception exception) { _logger.Error(exception, "Error while accepting connection at default endpoint."); - + } + finally + { //excessive CPU consumed if in endless loop of socket errors await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false); } @@ -133,10 +149,25 @@ namespace MQTTnet.Implementations var clientAdapter = new MqttChannelAdapter(new MqttTcpChannel(clientSocket, sslStream), new MqttPacketSerializer(), _logger); ClientAccepted?.Invoke(this, new MqttServerAdapterClientAcceptedEventArgs(clientAdapter)); } + catch (ObjectDisposedException) + { + // It can happen that the listener socket is accessed after the cancellation token is already set and the listener socket is disposed. + } + catch (SocketException exception) + { + if (exception.SocketErrorCode == SocketError.OperationAborted) + { + return; + } + + _logger.Error(exception, "Error while accepting connection at default endpoint."); + } catch (Exception exception) { _logger.Error(exception, "Error while accepting connection at TLS endpoint."); - + } + finally + { //excessive CPU consumed if in endless loop of socket errors await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false); } diff --git a/Frameworks/MQTTnet.NetStandard/Server/ConnectedMqttClient.cs b/Frameworks/MQTTnet.NetStandard/Server/ConnectedMqttClient.cs index ee3a55f..cd94193 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/ConnectedMqttClient.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/ConnectedMqttClient.cs @@ -9,8 +9,8 @@ namespace MQTTnet.Server public MqttProtocolVersion ProtocolVersion { get; set; } - public TimeSpan LastPacketReceivedDuration { get; set; } + public TimeSpan LastPacketReceived { get; set; } - public TimeSpan LastNonKeepAlivePacketReceivedDuration{ get; set; } + public TimeSpan LastNonKeepAlivePacketReceived { get; set; } } } diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs index c5f16a9..12ef891 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Threading; using System.Threading.Tasks; using MQTTnet.Adapter; @@ -13,6 +14,9 @@ namespace MQTTnet.Server { public sealed class MqttClientSession { + private readonly Stopwatch _lastPacketReceivedTracker = new Stopwatch(); + private readonly Stopwatch _lastNonKeepAlivePacketReceivedTracker = new Stopwatch(); + private readonly MqttClientSubscriptionsManager _subscriptionsManager; private readonly MqttClientSessionsManager _sessionsManager; private readonly MqttClientPendingMessagesQueue _pendingMessagesQueue; @@ -44,6 +48,10 @@ namespace MQTTnet.Server public MqttProtocolVersion? ProtocolVersion => _adapter?.PacketSerializer.ProtocolVersion; + public TimeSpan LastPacketReceived => _lastPacketReceivedTracker.Elapsed; + + public TimeSpan LastNonKeepAlivePacketReceived => _lastNonKeepAlivePacketReceivedTracker.Elapsed; + public bool IsConnected => _adapter != null; public async Task RunAsync(MqttApplicationMessage willMessage, IMqttChannelAdapter adapter) @@ -52,6 +60,9 @@ namespace MQTTnet.Server try { + _lastPacketReceivedTracker.Restart(); + _lastNonKeepAlivePacketReceivedTracker.Restart(); + var cancellationTokenSource = new CancellationTokenSource(); _willMessage = willMessage; @@ -78,6 +89,11 @@ namespace MQTTnet.Server { try { + if (_cancellationTokenSource == null) + { + return; + } + _cancellationTokenSource?.Cancel(false); _cancellationTokenSource?.Dispose(); _cancellationTokenSource = null; @@ -143,6 +159,13 @@ namespace MQTTnet.Server private Task ProcessReceivedPacketAsync(IMqttChannelAdapter adapter, MqttBasePacket packet, CancellationToken cancellationToken) { + _lastPacketReceivedTracker.Restart(); + + if (!(packet is MqttPingReqPacket)) + { + _lastNonKeepAlivePacketReceivedTracker.Restart(); + } + if (packet is MqttPublishPacket publishPacket) { return HandleIncomingPublishPacketAsync(adapter, publishPacket, cancellationToken); @@ -185,7 +208,7 @@ namespace MQTTnet.Server } _logger.Warning("Client '{0}': Received not supported packet ({1}). Closing connection.", ClientId, packet); - return StopAsync(); + return StopAsync(); } private async Task HandleIncomingSubscribePacketAsync(IMqttChannelAdapter adapter, MqttSubscribePacket subscribePacket, CancellationToken cancellationToken) @@ -211,7 +234,7 @@ namespace MQTTnet.Server } } - private async Task HandleIncomingPublishPacketAsync(IMqttChannelAdapter adapter, MqttPublishPacket publishPacket, CancellationToken cancellationToken) + private Task HandleIncomingPublishPacketAsync(IMqttChannelAdapter adapter, MqttPublishPacket publishPacket, CancellationToken cancellationToken) { var applicationMessage = publishPacket.ToApplicationMessage(); @@ -219,36 +242,44 @@ namespace MQTTnet.Server { case MqttQualityOfServiceLevel.AtMostOnce: { - await _sessionsManager.DispatchApplicationMessageAsync(this, applicationMessage).ConfigureAwait(false); - return; + return _sessionsManager.DispatchApplicationMessageAsync(this, applicationMessage); } case MqttQualityOfServiceLevel.AtLeastOnce: { - await _sessionsManager.DispatchApplicationMessageAsync(this, applicationMessage).ConfigureAwait(false); - - await adapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, - new MqttPubAckPacket { PacketIdentifier = publishPacket.PacketIdentifier }).ConfigureAwait(false); - - return; + return HandleIncomingPublishPacketWithQoS1(adapter, applicationMessage, publishPacket, cancellationToken); } case MqttQualityOfServiceLevel.ExactlyOnce: { - // QoS 2 is implement as method "B" [4.3.3 QoS 2: Exactly once delivery] - await _sessionsManager.DispatchApplicationMessageAsync(this, applicationMessage).ConfigureAwait(false); - - await adapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, - new MqttPubRecPacket { PacketIdentifier = publishPacket.PacketIdentifier }).ConfigureAwait(false); - - return; + return HandleIncomingPublishPacketWithQoS2(adapter, applicationMessage, publishPacket, cancellationToken); } default: - throw new MqttCommunicationException("Received a not supported QoS level."); + { + throw new MqttCommunicationException("Received a not supported QoS level."); + } } } + private async Task HandleIncomingPublishPacketWithQoS1(IMqttChannelAdapter adapter, MqttApplicationMessage applicationMessage, MqttPublishPacket publishPacket, CancellationToken cancellationToken) + { + await _sessionsManager.DispatchApplicationMessageAsync(this, applicationMessage).ConfigureAwait(false); + + var response = new MqttPubAckPacket { PacketIdentifier = publishPacket.PacketIdentifier }; + await adapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, response).ConfigureAwait(false); + } + + private async Task HandleIncomingPublishPacketWithQoS2(IMqttChannelAdapter adapter, MqttApplicationMessage applicationMessage, MqttPublishPacket publishPacket, CancellationToken cancellationToken) + { + // QoS 2 is implement as method "B" [4.3.3 QoS 2: Exactly once delivery] + await _sessionsManager.DispatchApplicationMessageAsync(this, applicationMessage).ConfigureAwait(false); + + var response = new MqttPubRecPacket { PacketIdentifier = publishPacket.PacketIdentifier }; + await adapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, response).ConfigureAwait(false); + } + private Task HandleIncomingPubRelPacketAsync(IMqttChannelAdapter adapter, MqttPubRelPacket pubRelPacket, CancellationToken cancellationToken) { - return adapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, new MqttPubCompPacket { PacketIdentifier = pubRelPacket.PacketIdentifier }); + var response = new MqttPubCompPacket { PacketIdentifier = pubRelPacket.PacketIdentifier }; + return adapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, response); } } } diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs index f65ed2b..5bb6598 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs @@ -120,11 +120,12 @@ namespace MQTTnet.Server await _sessionsSemaphore.WaitAsync().ConfigureAwait(false); try { - var now = DateTime.UtcNow; return _sessions.Where(s => s.Value.IsConnected).Select(s => new ConnectedMqttClient { ClientId = s.Value.ClientId, - ProtocolVersion = s.Value.ProtocolVersion ?? MqttProtocolVersion.V311 + ProtocolVersion = s.Value.ProtocolVersion ?? MqttProtocolVersion.V311, + LastPacketReceived = s.Value.LastPacketReceived, + LastNonKeepAlivePacketReceived = s.Value.LastNonKeepAlivePacketReceived }).ToList(); } finally diff --git a/Tests/MQTTnet.TestApp.NetCore/Program.cs b/Tests/MQTTnet.TestApp.NetCore/Program.cs index 0e4868a..77b9ea6 100644 --- a/Tests/MQTTnet.TestApp.NetCore/Program.cs +++ b/Tests/MQTTnet.TestApp.NetCore/Program.cs @@ -40,7 +40,7 @@ namespace MQTTnet.TestApp.NetCore Thread.Sleep(Timeout.Infinite); } - + // This code is used at the Wiki on GitHub! // ReSharper disable once UnusedMember.Local private static async void WikiCode() @@ -71,6 +71,26 @@ namespace MQTTnet.TestApp.NetCore var factory = new MqttFactory(); var client = factory.CreateMqttClient(); } + + { + // Write all trace messages to the console window. + MqttNetGlobalLogger.LogMessagePublished += (s, e) => + { + var trace = $">> [{e.TraceMessage.Timestamp:O}] [{e.TraceMessage.ThreadId}] [{e.TraceMessage.Source}] [{e.TraceMessage.Level}]: {e.TraceMessage.Message}"; + if (e.TraceMessage.Exception != null) + { + trace += Environment.NewLine + e.TraceMessage.Exception.ToString(); + } + + Console.WriteLine(trace); + }; + } + + { + // Use a custom log ID for the logger. + var factory = new MqttFactory(); + var mqttClient = factory.CreateMqttClient(new MqttNetLogger("MyCustomId")); + } } } @@ -106,4 +126,4 @@ namespace MQTTnet.TestApp.NetCore return Task.FromResult(retainedMessages); } } -} +} \ No newline at end of file From d12d2648b7eed47ca839550e0e6dfd4ea9a446f4 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Mon, 4 Dec 2017 10:21:37 +0100 Subject: [PATCH 09/22] Add extension for RPC calls; replace locks; Refactored storage in Managed Client --- Build/MQTTnet.nuspec | 6 +- .../MQTTnet.Extensions.Rpc.csproj | 30 ++++ .../MQTTnet.Extensions.Rpc/MqttRpcClient.cs | 101 +++++++++++++ .../MQTTnet.AspnetCore.csproj | 9 +- .../Adapter/MqttChannelAdapter.cs | 47 +++--- .../Adapter/ReceivedMqttPacket.cs | 12 +- .../Implementations/MqttTcpChannel.cs | 7 +- .../MQTTnet.Netstandard.csproj | 5 +- .../ManagedClient/ManagedMqttClient.cs | 57 ++++--- .../ManagedMqttClientStorageManager.cs | 32 ++-- .../Serializer/IMqttPacketSerializer.cs | 5 +- .../Serializer/MqttPacketReader.cs | 25 ++-- .../Serializer/MqttPacketSerializer.cs | 15 +- .../Server/MqttClientSession.cs | 43 ++++-- .../Server/MqttClientSessionsManager.cs | 71 ++++----- .../Server/MqttClientSubscriptionsManager.cs | 113 ++++++++++---- .../Server/MqttRetainedMessagesManager.cs | 14 +- .../MQTTnet.NetStandard/Server/MqttServer.cs | 43 +++--- .../MqttSubscriptionInterceptorContext.cs | 8 +- Frameworks/MQTTnet.NetStandard/TopicFilter.cs | 2 +- MQTTnet.sln | 23 ++- .../MqttPacketSerializerTests.cs | 3 +- Tests/MQTTnet.Core.Tests/MqttServerTests.cs | 8 +- .../MqttSubscriptionsManagerTests.cs | 67 +++++++-- Tests/MQTTnet.TestApp.NetCore/ClientTest.cs | 6 +- .../MQTTnet.TestApp.NetCore.csproj | 4 + .../PerformanceTest.cs | 17 ++- Tests/MQTTnet.TestApp.NetCore/ServerTest.cs | 24 ++- .../MQTTnet.TestApp.UniversalWindows.csproj | 4 + .../MainPage.xaml | 38 ++++- .../MainPage.xaml.cs | 140 ++++++++++++------ 31 files changed, 681 insertions(+), 298 deletions(-) create mode 100644 Extensions/MQTTnet.Extensions.Rpc/MQTTnet.Extensions.Rpc.csproj create mode 100644 Extensions/MQTTnet.Extensions.Rpc/MqttRpcClient.cs diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec index 71a9d55..302b128 100644 --- a/Build/MQTTnet.nuspec +++ b/Build/MQTTnet.nuspec @@ -14,10 +14,14 @@ * [Core] Added a strong name for the assembly. * [Core] Performance optimizations. * [Core] Fixed a logging issue when dealing with IOExceptions. +* [Core] Fixed a typo in the global logger class (BREAKING CHANGE! Please find new example in Wiki). * [Client] Fixed an issue in _ManagedClient_ which can cause the client to stop when publishing subscriptions. * [Server] The application message interceptor can now delete any received application message. -* [Server] Added a ConnectionValidator context to align with other APIs. +* [Server] Added a ConnectionValidator context to align with other APIs (BREAKING CHANGE! Please find new example in Wiki). * [Server] Added an interface for the _MqttServerOptions_. +* [Server] Added packet statistics for the connected clients. +* [Server] Fixed a security issue which sends retained packages to a failed subscription. +* [Server] Fixed the response (MaximumQoS) of a subscription (Thanks to @redbeans2017). Copyright Christian Kratky 2016-2017 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 diff --git a/Extensions/MQTTnet.Extensions.Rpc/MQTTnet.Extensions.Rpc.csproj b/Extensions/MQTTnet.Extensions.Rpc/MQTTnet.Extensions.Rpc.csproj new file mode 100644 index 0000000..fd16072 --- /dev/null +++ b/Extensions/MQTTnet.Extensions.Rpc/MQTTnet.Extensions.Rpc.csproj @@ -0,0 +1,30 @@ + + + + netstandard1.3;netstandard2.0;net452;net461;uap10.0 + 0.0.0.0 + 0.0.0.0 + + + + + 0.0.0.0 + + + + false + UAP,Version=v10.0 + UAP + 10.0.16299.0 + 10.0.10240.0 + .NETCore + v5.0 + $(DefineConstants);WINDOWS_UWP + $(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets + + + + + + + diff --git a/Extensions/MQTTnet.Extensions.Rpc/MqttRpcClient.cs b/Extensions/MQTTnet.Extensions.Rpc/MqttRpcClient.cs new file mode 100644 index 0000000..6a9d1c1 --- /dev/null +++ b/Extensions/MQTTnet.Extensions.Rpc/MqttRpcClient.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Concurrent; +using System.Threading.Tasks; +using MQTTnet.Client; +using MQTTnet.Internal; +using MQTTnet.Protocol; + +namespace MQTTnet.Extensions.Rpc +{ + public sealed class MqttRpcClient : IDisposable + { + private const string ResponseTopic = "$RPC/+/+/response"; + private readonly ConcurrentDictionary> _waitingCalls = new ConcurrentDictionary>(); + private readonly IMqttClient _mqttClient; + private bool _isEnabled; + + public MqttRpcClient(IMqttClient mqttClient) + { + _mqttClient = mqttClient ?? throw new ArgumentNullException(nameof(mqttClient)); + + _mqttClient.ApplicationMessageReceived += OnApplicationMessageReceived; + } + + public async Task EnableAsync() + { + await _mqttClient.SubscribeAsync(new TopicFilterBuilder().WithTopic(ResponseTopic).WithAtLeastOnceQoS().Build()); + _isEnabled = true; + } + + public async Task DisableAsync() + { + await _mqttClient.UnsubscribeAsync(ResponseTopic); + _isEnabled = false; + } + + public async Task ExecuteAsync(TimeSpan timeout, string methodName, byte[] payload, MqttQualityOfServiceLevel qualityOfServiceLevel) + { + if (methodName == null) throw new ArgumentNullException(nameof(methodName)); + + if (methodName.Contains("/") || methodName.Contains("+") || methodName.Contains("#")) + { + throw new ArgumentException("The method name cannot contain /, + or #."); + } + + if (!_isEnabled) + { + throw new InvalidOperationException("The RPC client is not enabled."); + } + + var requestTopic = $"$MQTTnet.RPC/{Guid.NewGuid():N}/{methodName}"; + var responseTopic = requestTopic + "/response"; + + var requestMessage = new MqttApplicationMessageBuilder() + .WithTopic(requestTopic) + .WithPayload(payload) + .WithQualityOfServiceLevel(qualityOfServiceLevel) + .Build(); + + try + { + var tcs = new TaskCompletionSource(); + if (!_waitingCalls.TryAdd(responseTopic, tcs)) + { + throw new InvalidOperationException(); + } + + await _mqttClient.PublishAsync(requestMessage); + return await tcs.Task.TimeoutAfter(timeout); + } + finally + { + _waitingCalls.TryRemove(responseTopic, out _); + } + } + + private void OnApplicationMessageReceived(object sender, MqttApplicationMessageReceivedEventArgs eventArgs) + { + if (!_waitingCalls.TryRemove(eventArgs.ApplicationMessage.Topic, out TaskCompletionSource tcs)) + { + return; + } + + if (tcs.Task.IsCompleted || tcs.Task.IsCanceled) + { + return; + } + + tcs.TrySetResult(eventArgs.ApplicationMessage.Payload); + } + + public void Dispose() + { + foreach (var tcs in _waitingCalls) + { + tcs.Value.SetCanceled(); + } + + _waitingCalls.Clear(); + } + } +} diff --git a/Frameworks/MQTTnet.AspnetCore/MQTTnet.AspnetCore.csproj b/Frameworks/MQTTnet.AspnetCore/MQTTnet.AspnetCore.csproj index fbde3f2..1f23602 100644 --- a/Frameworks/MQTTnet.AspnetCore/MQTTnet.AspnetCore.csproj +++ b/Frameworks/MQTTnet.AspnetCore/MQTTnet.AspnetCore.csproj @@ -2,8 +2,13 @@ netstandard2.0 - 2.5.2.0 - 2.5.2.0 + 0.0.0.0 + 0.0.0.0 + 0.0.0.0 + + + + diff --git a/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs b/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs index af39958..0cbcc93 100644 --- a/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs +++ b/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs @@ -18,6 +18,8 @@ namespace MQTTnet.Adapter { private const uint ErrorOperationAborted = 0x800703E3; + private static readonly byte[] EmptyBody = new byte[0]; + private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1); private readonly IMqttNetLogger _logger; private readonly IMqttChannel _channel; @@ -89,35 +91,28 @@ namespace MQTTnet.Adapter MqttBasePacket packet = null; await ExecuteAndWrapExceptionAsync(async () => { - ReceivedMqttPacket receivedMqttPacket = null; - try + ReceivedMqttPacket receivedMqttPacket; + if (timeout > TimeSpan.Zero) { - if (timeout > TimeSpan.Zero) - { - receivedMqttPacket = await ReceiveAsync(_channel.ReceiveStream, cancellationToken).TimeoutAfter(timeout).ConfigureAwait(false); - } - else - { - receivedMqttPacket = await ReceiveAsync(_channel.ReceiveStream, cancellationToken).ConfigureAwait(false); - } - - if (receivedMqttPacket == null || cancellationToken.IsCancellationRequested) - { - throw new TaskCanceledException(); - } - - packet = PacketSerializer.Deserialize(receivedMqttPacket); - if (packet == null) - { - throw new MqttProtocolViolationException("Received malformed packet."); - } + receivedMqttPacket = await ReceiveAsync(_channel.ReceiveStream, cancellationToken).TimeoutAfter(timeout).ConfigureAwait(false); + } + else + { + receivedMqttPacket = await ReceiveAsync(_channel.ReceiveStream, cancellationToken).ConfigureAwait(false); + } - _logger.Trace("RX <<< {0}", packet); + if (receivedMqttPacket == null || cancellationToken.IsCancellationRequested) + { + throw new TaskCanceledException(); } - finally + + packet = PacketSerializer.Deserialize(receivedMqttPacket.Header, receivedMqttPacket.Body); + if (packet == null) { - receivedMqttPacket?.Dispose(); + throw new MqttProtocolViolationException("Received malformed packet."); } + + _logger.Trace("RX <<< {0}", packet); }).ConfigureAwait(false); return packet; @@ -133,7 +128,7 @@ namespace MQTTnet.Adapter if (header.BodyLength == 0) { - return new ReceivedMqttPacket(header, new MemoryStream(0)); + return new ReceivedMqttPacket(header, EmptyBody); } var body = new byte[header.BodyLength]; @@ -145,7 +140,7 @@ namespace MQTTnet.Adapter offset += readBytesCount; } while (offset < header.BodyLength); - return new ReceivedMqttPacket(header, new MemoryStream(body, 0, body.Length, false, true)); + return new ReceivedMqttPacket(header, body); } private static async Task ExecuteAndWrapExceptionAsync(Func action) diff --git a/Frameworks/MQTTnet.NetStandard/Adapter/ReceivedMqttPacket.cs b/Frameworks/MQTTnet.NetStandard/Adapter/ReceivedMqttPacket.cs index a44fb54..c92f9d0 100644 --- a/Frameworks/MQTTnet.NetStandard/Adapter/ReceivedMqttPacket.cs +++ b/Frameworks/MQTTnet.NetStandard/Adapter/ReceivedMqttPacket.cs @@ -1,12 +1,11 @@ using System; -using System.IO; using MQTTnet.Packets; namespace MQTTnet.Adapter { - public sealed class ReceivedMqttPacket : IDisposable + public class ReceivedMqttPacket { - public ReceivedMqttPacket(MqttPacketHeader header, MemoryStream body) + public ReceivedMqttPacket(MqttPacketHeader header, byte[] body) { Header = header ?? throw new ArgumentNullException(nameof(header)); Body = body ?? throw new ArgumentNullException(nameof(body)); @@ -14,11 +13,6 @@ namespace MQTTnet.Adapter public MqttPacketHeader Header { get; } - public MemoryStream Body { get; } - - public void Dispose() - { - Body?.Dispose(); - } + public byte[] Body { get; } } } diff --git a/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs index 7e23fdb..7e6f663 100644 --- a/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs +++ b/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs @@ -70,7 +70,7 @@ namespace MQTTnet.Implementations _sslStream = new SslStream(new NetworkStream(_socket, true), false, InternalUserCertificateValidationCallback); await _sslStream.AuthenticateAsClientAsync(_options.Server, LoadCertificates(_options), SslProtocols.Tls12, _options.TlsOptions.IgnoreCertificateRevocationErrors).ConfigureAwait(false); } - + CreateStreams(_socket, _sslStream); } @@ -139,10 +139,7 @@ namespace MQTTnet.Implementations private void CreateStreams(Socket socket, Stream sslStream) { var stream = sslStream ?? new NetworkStream(socket); - - //cannot use this as default buffering prevents from receiving the first connect message - //need two streams otherwise read and write have to be synchronized - + //todo: if branch can be used with min dependency NetStandard1.6 #if NET452 || NET461 SendStream = new BufferedStream(stream, BufferSize); diff --git a/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj b/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj index abcc865..92920cd 100644 --- a/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj +++ b/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj @@ -6,8 +6,8 @@ MQTTnet False Full - 2.5.3.0 - 2.5.3.0 + 0.0.0.0 + 0.0.0.0 0.0.0.0 @@ -29,7 +29,6 @@ v5.0 $(DefineConstants);WINDOWS_UWP $(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets - diff --git a/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs index 7ae7250..9b01156 100644 --- a/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs +++ b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs @@ -13,9 +13,9 @@ namespace MQTTnet.ManagedClient { public class ManagedMqttClient : IManagedMqttClient { - private readonly ManagedMqttClientStorageManager _storageManager = new ManagedMqttClientStorageManager(); private readonly BlockingCollection _messageQueue = new BlockingCollection(); private readonly HashSet _subscriptions = new HashSet(); + private readonly SemaphoreSlim _subscriptionsSemaphore = new SemaphoreSlim(1, 1); private readonly IMqttClient _mqttClient; private readonly IMqttNetLogger _logger; @@ -23,7 +23,9 @@ namespace MQTTnet.ManagedClient private CancellationTokenSource _connectionCancellationToken; private CancellationTokenSource _publishingCancellationToken; + private ManagedMqttClientStorageManager _storageManager; private IManagedMqttClientOptions _options; + private bool _subscriptionsNotPushed; public ManagedMqttClient(IMqttClient mqttClient, IMqttNetLogger logger) @@ -55,15 +57,11 @@ namespace MQTTnet.ManagedClient if (_connectionCancellationToken != null) throw new InvalidOperationException("The managed client is already started."); _options = options; - await _storageManager.SetStorageAsync(_options.Storage).ConfigureAwait(false); - + if (_options.Storage != null) { - var loadedMessages = await _options.Storage.LoadQueuedMessagesAsync().ConfigureAwait(false); - foreach (var loadedMessage in loadedMessages) - { - _messageQueue.Add(loadedMessage); - } + _storageManager = new ManagedMqttClientStorageManager(_options.Storage); + await _storageManager.LoadQueuedMessagesAsync().ConfigureAwait(false); } _connectionCancellationToken = new CancellationTokenSource(); @@ -97,16 +95,21 @@ namespace MQTTnet.ManagedClient foreach (var applicationMessage in applicationMessages) { - await _storageManager.AddAsync(applicationMessage).ConfigureAwait(false); + if (_storageManager != null) + { + await _storageManager.AddAsync(applicationMessage).ConfigureAwait(false); + } + _messageQueue.Add(applicationMessage); } } - public Task SubscribeAsync(IEnumerable topicFilters) + public async Task SubscribeAsync(IEnumerable topicFilters) { if (topicFilters == null) throw new ArgumentNullException(nameof(topicFilters)); - lock (_subscriptions) + await _subscriptionsSemaphore.WaitAsync().ConfigureAwait(false); + try { foreach (var topicFilter in topicFilters) { @@ -116,13 +119,16 @@ namespace MQTTnet.ManagedClient } } } - - return Task.FromResult(0); + finally + { + _subscriptionsSemaphore.Release(); + } } - public Task UnsubscribeAsync(IEnumerable topicFilters) + public async Task UnsubscribeAsync(IEnumerable topicFilters) { - lock (_subscriptions) + await _subscriptionsSemaphore.WaitAsync().ConfigureAwait(false); + try { foreach (var topicFilter in topicFilters) { @@ -132,8 +138,10 @@ namespace MQTTnet.ManagedClient } } } - - return Task.FromResult(0); + finally + { + _subscriptionsSemaphore.Release(); + } } private async Task MaintainConnectionAsync(CancellationToken cancellationToken) @@ -242,7 +250,11 @@ namespace MQTTnet.ManagedClient try { await _mqttClient.PublishAsync(message).ConfigureAwait(false); - await _storageManager.RemoveAsync(message).ConfigureAwait(false); + + if (_storageManager != null) + { + await _storageManager.RemoveAsync(message).ConfigureAwait(false); + } } catch (MqttCommunicationException exception) { @@ -264,13 +276,18 @@ namespace MQTTnet.ManagedClient _logger.Info(nameof(ManagedMqttClient), "Synchronizing subscriptions"); List subscriptions; - lock (_subscriptions) + await _subscriptionsSemaphore.WaitAsync().ConfigureAwait(false); + try { subscriptions = _subscriptions.ToList(); _subscriptionsNotPushed = false; } + finally + { + _subscriptionsSemaphore.Release(); + } - if (!_subscriptions.Any()) + if (!subscriptions.Any()) { return; } diff --git a/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientStorageManager.cs b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientStorageManager.cs index d55f137..0e71776 100644 --- a/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientStorageManager.cs +++ b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientStorageManager.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -8,18 +9,19 @@ namespace MQTTnet.ManagedClient { private readonly List _applicationMessages = new List(); private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1); - private IManagedMqttClientStorage _storage; + private readonly IManagedMqttClientStorage _storage; - public async Task SetStorageAsync(IManagedMqttClientStorage storage) + public ManagedMqttClientStorageManager(IManagedMqttClientStorage storage) { - await _semaphore.WaitAsync().ConfigureAwait(false); - try - { - _storage = storage; - } - finally + _storage = storage ?? throw new ArgumentNullException(nameof(storage)); + } + + public async Task LoadQueuedMessagesAsync() + { + var loadedMessages = await _storage.LoadQueuedMessagesAsync().ConfigureAwait(false); + foreach (var loadedMessage in loadedMessages) { - _semaphore.Release(); + _applicationMessages.Add(loadedMessage); } } @@ -28,11 +30,6 @@ namespace MQTTnet.ManagedClient await _semaphore.WaitAsync().ConfigureAwait(false); try { - if (_storage == null) - { - return; - } - _applicationMessages.Add(applicationMessage); await SaveAsync().ConfigureAwait(false); } @@ -47,11 +44,6 @@ namespace MQTTnet.ManagedClient await _semaphore.WaitAsync().ConfigureAwait(false); try { - if (_storage == null) - { - return; - } - var index = _applicationMessages.IndexOf(applicationMessage); if (index == -1) { diff --git a/Frameworks/MQTTnet.NetStandard/Serializer/IMqttPacketSerializer.cs b/Frameworks/MQTTnet.NetStandard/Serializer/IMqttPacketSerializer.cs index 439460d..2068641 100644 --- a/Frameworks/MQTTnet.NetStandard/Serializer/IMqttPacketSerializer.cs +++ b/Frameworks/MQTTnet.NetStandard/Serializer/IMqttPacketSerializer.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using MQTTnet.Adapter; using MQTTnet.Packets; namespace MQTTnet.Serializer @@ -9,8 +8,8 @@ namespace MQTTnet.Serializer { MqttProtocolVersion ProtocolVersion { get; set; } - IEnumerable> Serialize(MqttBasePacket mqttPacket); + ICollection> Serialize(MqttBasePacket mqttPacket); - MqttBasePacket Deserialize(ReceivedMqttPacket receivedMqttPacket); + MqttBasePacket Deserialize(MqttPacketHeader header, byte[] body); } } \ No newline at end of file diff --git a/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketReader.cs b/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketReader.cs index 04ee01f..a22707c 100644 --- a/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketReader.cs +++ b/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketReader.cs @@ -1,9 +1,9 @@ using System; +using System.Collections.Generic; using System.IO; using System.Text; using System.Threading; using System.Threading.Tasks; -using MQTTnet.Adapter; using MQTTnet.Exceptions; using MQTTnet.Packets; using MQTTnet.Protocol; @@ -12,15 +12,15 @@ namespace MQTTnet.Serializer { public sealed class MqttPacketReader : BinaryReader { - private readonly ReceivedMqttPacket _receivedMqttPacket; - - public MqttPacketReader(ReceivedMqttPacket receivedMqttPacket) - : base(receivedMqttPacket.Body, Encoding.UTF8, true) + private readonly MqttPacketHeader _header; + + public MqttPacketReader(MqttPacketHeader header, Stream bodyStream) + : base(bodyStream, Encoding.UTF8, true) { - _receivedMqttPacket = receivedMqttPacket; + _header = header; } - public bool EndOfRemainingData => BaseStream.Position == _receivedMqttPacket.Header.BodyLength; + public bool EndOfRemainingData => BaseStream.Position == _header.BodyLength; public static MqttPacketHeader ReadHeaderFromSource(Stream stream, CancellationToken cancellationToken) { @@ -77,7 +77,7 @@ namespace MQTTnet.Serializer public byte[] ReadRemainingData() { - return ReadBytes(_receivedMqttPacket.Header.BodyLength - (int)BaseStream.Position); + return ReadBytes(_header.BodyLength - (int)BaseStream.Position); } private static int ReadBodyLengthFromSource(Stream stream, CancellationToken cancellationToken) @@ -87,7 +87,7 @@ namespace MQTTnet.Serializer var value = 0; byte encodedByte; - ////var readBytes = new List(); + var readBytes = new List(); do { if (cancellationToken.IsCancellationRequested) @@ -101,15 +101,14 @@ namespace MQTTnet.Serializer throw new MqttCommunicationException("Connection closed while reading remaining length data."); } - ////readBytes.Add(buffer); - encodedByte = (byte)buffer; + readBytes.Add(encodedByte); + value += (byte)(encodedByte & 127) * multiplier; multiplier *= 128; if (multiplier > 128 * 128 * 128) { - //throw new MqttProtocolViolationException($"Remaining length is invalid (Data={string.Join(",", readBytes)})."); - throw new MqttProtocolViolationException("Remaining length is invalid."); + throw new MqttProtocolViolationException($"Remaining length is invalid (Data={string.Join(",", readBytes)})."); } } while ((encodedByte & 128) != 0); diff --git a/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketSerializer.cs b/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketSerializer.cs index 0b04114..88414d5 100644 --- a/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketSerializer.cs +++ b/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketSerializer.cs @@ -1,5 +1,4 @@ -using MQTTnet.Adapter; -using MQTTnet.Exceptions; +using MQTTnet.Exceptions; using MQTTnet.Packets; using MQTTnet.Protocol; using System; @@ -17,7 +16,7 @@ namespace MQTTnet.Serializer public MqttProtocolVersion ProtocolVersion { get; set; } = MqttProtocolVersion.V311; - public IEnumerable> Serialize(MqttBasePacket packet) + public ICollection> Serialize(MqttBasePacket packet) { if (packet == null) throw new ArgumentNullException(nameof(packet)); @@ -43,13 +42,15 @@ namespace MQTTnet.Serializer } } - public MqttBasePacket Deserialize(ReceivedMqttPacket receivedMqttPacket) + public MqttBasePacket Deserialize(MqttPacketHeader header, byte[] body) { - if (receivedMqttPacket == null) throw new ArgumentNullException(nameof(receivedMqttPacket)); + if (header == null) throw new ArgumentNullException(nameof(header)); + if (body == null) throw new ArgumentNullException(nameof(body)); - using (var reader = new MqttPacketReader(receivedMqttPacket)) + using (var bodyStream = new MemoryStream(body)) + using (var reader = new MqttPacketReader(header, bodyStream)) { - return Deserialize(receivedMqttPacket.Header, reader); + return Deserialize(header, reader); } } diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs index 12ef891..8f7199a 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs @@ -14,15 +14,17 @@ namespace MQTTnet.Server { public sealed class MqttClientSession { - private readonly Stopwatch _lastPacketReceivedTracker = new Stopwatch(); - private readonly Stopwatch _lastNonKeepAlivePacketReceivedTracker = new Stopwatch(); + private readonly Stopwatch _lastPacketReceivedTracker = Stopwatch.StartNew(); + private readonly Stopwatch _lastNonKeepAlivePacketReceivedTracker = Stopwatch.StartNew(); - private readonly MqttClientSubscriptionsManager _subscriptionsManager; - private readonly MqttClientSessionsManager _sessionsManager; - private readonly MqttClientPendingMessagesQueue _pendingMessagesQueue; private readonly IMqttServerOptions _options; private readonly IMqttNetLogger _logger; + private readonly MqttClientSessionsManager _sessionsManager; + private readonly MqttRetainedMessagesManager _retainedMessagesManager; + private readonly MqttClientSubscriptionsManager _subscriptionsManager; + private readonly MqttClientPendingMessagesQueue _pendingMessagesQueue; + private IMqttChannelAdapter _adapter; private CancellationTokenSource _cancellationTokenSource; private MqttApplicationMessage _willMessage; @@ -30,16 +32,17 @@ namespace MQTTnet.Server public MqttClientSession( string clientId, IMqttServerOptions options, + MqttRetainedMessagesManager retainedMessagesManager, MqttClientSessionsManager sessionsManager, IMqttNetLogger logger) { + _options = options ?? throw new ArgumentNullException(nameof(options)); + _retainedMessagesManager = retainedMessagesManager ?? throw new ArgumentNullException(nameof(retainedMessagesManager)); _sessionsManager = sessionsManager ?? throw new ArgumentNullException(nameof(sessionsManager)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); ClientId = clientId; - - _options = options; - + _subscriptionsManager = new MqttClientSubscriptionsManager(_options); _pendingMessagesQueue = new MqttClientPendingMessagesQueue(_options, this, _logger); } @@ -117,11 +120,11 @@ namespace MQTTnet.Server } } - public void EnqueueApplicationMessage(MqttApplicationMessage applicationMessage) + public async Task EnqueueApplicationMessageAsync(MqttApplicationMessage applicationMessage) { if (applicationMessage == null) throw new ArgumentNullException(nameof(applicationMessage)); - var result = _subscriptionsManager.CheckSubscriptions(applicationMessage); + var result = await _subscriptionsManager.CheckSubscriptionsAsync(applicationMessage); if (!result.IsSubscribed) { return; @@ -129,6 +132,7 @@ namespace MQTTnet.Server var publishPacket = applicationMessage.ToPublishPacket(); publishPacket.QualityOfServiceLevel = result.QualityOfServiceLevel; + _pendingMessagesQueue.Enqueue(publishPacket); } @@ -199,7 +203,7 @@ namespace MQTTnet.Server if (packet is MqttUnsubscribePacket unsubscribePacket) { - return adapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, _subscriptionsManager.Unsubscribe(unsubscribePacket)); + return HandleIncomingUnsubscribePacketAsync(adapter, unsubscribePacket, cancellationToken); } if (packet is MqttDisconnectPacket || packet is MqttConnectPacket) @@ -213,24 +217,31 @@ namespace MQTTnet.Server private async Task HandleIncomingSubscribePacketAsync(IMqttChannelAdapter adapter, MqttSubscribePacket subscribePacket, CancellationToken cancellationToken) { - var subscribeResult = _subscriptionsManager.Subscribe(subscribePacket, ClientId); + var subscribeResult = await _subscriptionsManager.SubscribeAsync(subscribePacket, ClientId); await adapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, subscribeResult.ResponsePacket).ConfigureAwait(false); - await EnqueueSubscribedRetainedMessagesAsync(subscribePacket).ConfigureAwait(false); - if (subscribeResult.CloseConnection) { await adapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, new MqttDisconnectPacket()).ConfigureAwait(false); await StopAsync().ConfigureAwait(false); } + + await EnqueueSubscribedRetainedMessagesAsync(subscribePacket).ConfigureAwait(false); + } + + private async Task HandleIncomingUnsubscribePacketAsync(IMqttChannelAdapter adapter, MqttUnsubscribePacket unsubscribePacket, CancellationToken cancellationToken) + { + var unsubscribeResult = await _subscriptionsManager.UnsubscribeAsync(unsubscribePacket); + + await adapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, unsubscribeResult); } private async Task EnqueueSubscribedRetainedMessagesAsync(MqttSubscribePacket subscribePacket) { - var retainedMessages = await _sessionsManager.GetRetainedMessagesAsync(subscribePacket).ConfigureAwait(false); + var retainedMessages = await _retainedMessagesManager.GetSubscribedMessagesAsync(subscribePacket); foreach (var publishPacket in retainedMessages) { - EnqueueApplicationMessage(publishPacket); + await EnqueueApplicationMessageAsync(publishPacket); } } diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs index 5bb6598..739f964 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs @@ -15,23 +15,21 @@ namespace MQTTnet.Server public sealed class MqttClientSessionsManager { private readonly Dictionary _sessions = new Dictionary(); - private readonly SemaphoreSlim _sessionsSemaphore = new SemaphoreSlim(1, 1); + private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1); private readonly IMqttServerOptions _options; + private readonly MqttServer _server; private readonly MqttRetainedMessagesManager _retainedMessagesManager; private readonly IMqttNetLogger _logger; - public MqttClientSessionsManager(IMqttServerOptions options, MqttRetainedMessagesManager retainedMessagesManager, IMqttNetLogger logger) + public MqttClientSessionsManager(IMqttServerOptions options, MqttRetainedMessagesManager retainedMessagesManager, MqttServer server, IMqttNetLogger logger) { + _server = server ?? throw new ArgumentNullException(nameof(server)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _options = options ?? throw new ArgumentNullException(nameof(options)); _retainedMessagesManager = retainedMessagesManager ?? throw new ArgumentNullException(nameof(retainedMessagesManager)); } - public event EventHandler ClientConnected; - public event EventHandler ClientDisconnected; - public event EventHandler ApplicationMessageReceived; - public async Task RunClientSessionAsync(IMqttChannelAdapter clientAdapter, CancellationToken cancellationToken) { var clientId = string.Empty; @@ -66,11 +64,11 @@ namespace MQTTnet.Server IsSessionPresent = clientSession.IsExistingSession }).ConfigureAwait(false); - ClientConnected?.Invoke(this, new MqttClientConnectedEventArgs(new ConnectedMqttClient + _server.OnClientConnected(new ConnectedMqttClient { ClientId = clientId, ProtocolVersion = clientAdapter.PacketSerializer.ProtocolVersion - })); + }); await clientSession.Session.RunAsync(connectPacket.WillMessage, clientAdapter).ConfigureAwait(false); } @@ -89,17 +87,17 @@ namespace MQTTnet.Server // ignored } - ClientDisconnected?.Invoke(this, new MqttClientDisconnectedEventArgs(new ConnectedMqttClient + _server.OnClientDisconnected(new ConnectedMqttClient { ClientId = clientId, ProtocolVersion = clientAdapter.PacketSerializer.ProtocolVersion - })); + }); } } public async Task StopAsync() { - await _sessionsSemaphore.WaitAsync().ConfigureAwait(false); + await _semaphore.WaitAsync().ConfigureAwait(false); try { foreach (var session in _sessions) @@ -111,13 +109,13 @@ namespace MQTTnet.Server } finally { - _sessionsSemaphore.Release(); + _semaphore.Release(); } } public async Task> GetConnectedClientsAsync() { - await _sessionsSemaphore.WaitAsync().ConfigureAwait(false); + await _semaphore.WaitAsync().ConfigureAwait(false); try { return _sessions.Where(s => s.Value.IsConnected).Select(s => new ConnectedMqttClient @@ -130,7 +128,7 @@ namespace MQTTnet.Server } finally { - _sessionsSemaphore.Release(); + _semaphore.Release(); } } @@ -138,17 +136,7 @@ namespace MQTTnet.Server { try { - if (_options.ApplicationMessageInterceptor != null) - { - var interceptorContext = new MqttApplicationMessageInterceptorContext - { - ApplicationMessage = applicationMessage - }; - - _options.ApplicationMessageInterceptor(interceptorContext); - applicationMessage = interceptorContext.ApplicationMessage; - } - + applicationMessage = InterceptApplicationMessage(applicationMessage); if (applicationMessage == null) { return; @@ -159,26 +147,41 @@ namespace MQTTnet.Server await _retainedMessagesManager.HandleMessageAsync(senderClientSession?.ClientId, applicationMessage).ConfigureAwait(false); } - var eventArgs = new MqttApplicationMessageReceivedEventArgs(senderClientSession?.ClientId, applicationMessage); - ApplicationMessageReceived?.Invoke(this, eventArgs); + _server.OnApplicationMessageReceived(senderClientSession?.ClientId, applicationMessage); } catch (Exception exception) { _logger.Error(exception, "Error while processing application message"); } - lock (_sessions) + await _semaphore.WaitAsync().ConfigureAwait(false); + try { foreach (var clientSession in _sessions.Values) { - clientSession.EnqueueApplicationMessage(applicationMessage); + await clientSession.EnqueueApplicationMessageAsync(applicationMessage); } } + finally + { + _semaphore.Release(); + } } - public Task> GetRetainedMessagesAsync(MqttSubscribePacket subscribePacket) + private MqttApplicationMessage InterceptApplicationMessage(MqttApplicationMessage applicationMessage) { - return _retainedMessagesManager.GetSubscribedMessagesAsync(subscribePacket); + if (_options.ApplicationMessageInterceptor == null) + { + return applicationMessage; + } + + var interceptorContext = new MqttApplicationMessageInterceptorContext + { + ApplicationMessage = applicationMessage + }; + + _options.ApplicationMessageInterceptor(interceptorContext); + return interceptorContext.ApplicationMessage; } private MqttConnectReturnCode ValidateConnection(MqttConnectPacket connectPacket) @@ -200,7 +203,7 @@ namespace MQTTnet.Server private async Task GetOrCreateClientSessionAsync(MqttConnectPacket connectPacket) { - await _sessionsSemaphore.WaitAsync().ConfigureAwait(false); + await _semaphore.WaitAsync().ConfigureAwait(false); try { var isSessionPresent = _sessions.TryGetValue(connectPacket.ClientId, out var clientSession); @@ -225,7 +228,7 @@ namespace MQTTnet.Server { isExistingSession = false; - clientSession = new MqttClientSession(connectPacket.ClientId, _options, this, _logger); + clientSession = new MqttClientSession(connectPacket.ClientId, _options, _retainedMessagesManager, this, _logger); _sessions[connectPacket.ClientId] = clientSession; _logger.Trace("Created a new session for client '{0}'.", connectPacket.ClientId); @@ -235,7 +238,7 @@ namespace MQTTnet.Server } finally { - _sessionsSemaphore.Release(); + _semaphore.Release(); } } } diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSubscriptionsManager.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSubscriptionsManager.cs index 73548ce..2151f77 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSubscriptionsManager.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSubscriptionsManager.cs @@ -1,5 +1,8 @@ using System; using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; using MQTTnet.Packets; using MQTTnet.Protocol; @@ -7,6 +10,7 @@ namespace MQTTnet.Server { public sealed class MqttClientSubscriptionsManager { + private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1); private readonly Dictionary _subscriptions = new Dictionary(); private readonly IMqttServerOptions _options; @@ -15,24 +19,34 @@ namespace MQTTnet.Server _options = options ?? throw new ArgumentNullException(nameof(options)); } - public MqttClientSubscribeResult Subscribe(MqttSubscribePacket subscribePacket, string clientId) + public async Task SubscribeAsync(MqttSubscribePacket subscribePacket, string clientId) { if (subscribePacket == null) throw new ArgumentNullException(nameof(subscribePacket)); - var responsePacket = subscribePacket.CreateResponse(); - var closeConnection = false; + var result = new MqttClientSubscribeResult + { + ResponsePacket = subscribePacket.CreateResponse(), + CloseConnection = false + }; - lock (_subscriptions) + await _semaphore.WaitAsync().ConfigureAwait(false); + try { foreach (var topicFilter in subscribePacket.TopicFilters) { - var interceptorContext = new MqttSubscriptionInterceptorContext(clientId, topicFilter); - _options.SubscriptionInterceptor?.Invoke(interceptorContext); - responsePacket.SubscribeReturnCodes.Add(interceptorContext.AcceptSubscription ? MqttSubscribeReturnCode.SuccessMaximumQoS1 : MqttSubscribeReturnCode.Failure); - + var interceptorContext = InterceptSubscribe(clientId, topicFilter); + if (!interceptorContext.AcceptSubscription) + { + result.ResponsePacket.SubscribeReturnCodes.Add(MqttSubscribeReturnCode.Failure); + } + else + { + result.ResponsePacket.SubscribeReturnCodes.Add(ConvertToMaximumQoS(topicFilter.QualityOfServiceLevel)); + } + if (interceptorContext.CloseConnection) { - closeConnection = true; + result.CloseConnection = true; } if (interceptorContext.AcceptSubscription) @@ -41,35 +55,42 @@ namespace MQTTnet.Server } } } - - return new MqttClientSubscribeResult + finally { - ResponsePacket = responsePacket, - CloseConnection = closeConnection - }; + _semaphore.Release(); + } + + return result; } - public MqttUnsubAckPacket Unsubscribe(MqttUnsubscribePacket unsubscribePacket) + public async Task UnsubscribeAsync(MqttUnsubscribePacket unsubscribePacket) { if (unsubscribePacket == null) throw new ArgumentNullException(nameof(unsubscribePacket)); - lock (_subscriptions) + await _semaphore.WaitAsync().ConfigureAwait(false); + try { foreach (var topicFilter in unsubscribePacket.TopicFilters) { _subscriptions.Remove(topicFilter); } } + finally + { + _semaphore.Release(); + } return unsubscribePacket.CreateResponse(); } - public CheckSubscriptionsResult CheckSubscriptions(MqttApplicationMessage applicationMessage) + public async Task CheckSubscriptionsAsync(MqttApplicationMessage applicationMessage) { if (applicationMessage == null) throw new ArgumentNullException(nameof(applicationMessage)); - lock (_subscriptions) + await _semaphore.WaitAsync().ConfigureAwait(false); + try { + var qosLevels = new HashSet(); foreach (var subscription in _subscriptions) { if (!MqttTopicFilterComparer.IsMatch(applicationMessage.Topic, subscription.Key)) @@ -77,24 +98,64 @@ namespace MQTTnet.Server continue; } - var effectiveQos = subscription.Value; - if (applicationMessage.QualityOfServiceLevel < effectiveQos) - { - effectiveQos = applicationMessage.QualityOfServiceLevel; - } + qosLevels.Add(subscription.Value); + } + if (qosLevels.Count == 0) + { return new CheckSubscriptionsResult { - IsSubscribed = true, - QualityOfServiceLevel = effectiveQos + IsSubscribed = false }; } + + return CreateSubscriptionResult(applicationMessage, qosLevels); + } + finally + { + _semaphore.Release(); + } + } + + private MqttSubscriptionInterceptorContext InterceptSubscribe(string clientId, TopicFilter topicFilter) + { + var interceptorContext = new MqttSubscriptionInterceptorContext(clientId, topicFilter); + _options.SubscriptionInterceptor?.Invoke(interceptorContext); + return interceptorContext; + } + + private static CheckSubscriptionsResult CreateSubscriptionResult(MqttApplicationMessage applicationMessage, HashSet subscribedQoSLevels) + { + MqttQualityOfServiceLevel effectiveQoS; + if (subscribedQoSLevels.Contains(applicationMessage.QualityOfServiceLevel)) + { + effectiveQoS = applicationMessage.QualityOfServiceLevel; + } + else if (subscribedQoSLevels.Count == 1) + { + effectiveQoS = subscribedQoSLevels.First(); + } + else + { + effectiveQoS = subscribedQoSLevels.Max(); } return new CheckSubscriptionsResult { - IsSubscribed = false + IsSubscribed = true, + QualityOfServiceLevel = effectiveQoS }; } + + private static MqttSubscribeReturnCode ConvertToMaximumQoS(MqttQualityOfServiceLevel qualityOfServiceLevel) + { + switch (qualityOfServiceLevel) + { + case MqttQualityOfServiceLevel.AtMostOnce: return MqttSubscribeReturnCode.SuccessMaximumQoS0; + case MqttQualityOfServiceLevel.AtLeastOnce: return MqttSubscribeReturnCode.SuccessMaximumQoS1; + case MqttQualityOfServiceLevel.ExactlyOnce: return MqttSubscribeReturnCode.SuccessMaximumQoS2; + default: return MqttSubscribeReturnCode.Failure; + } + } } } diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttRetainedMessagesManager.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttRetainedMessagesManager.cs index 0b8d669..2c0b260 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttRetainedMessagesManager.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttRetainedMessagesManager.cs @@ -11,7 +11,7 @@ namespace MQTTnet.Server public sealed class MqttRetainedMessagesManager { private readonly Dictionary _retainedMessages = new Dictionary(); - private readonly SemaphoreSlim _gate = new SemaphoreSlim(1, 1); + private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1); private readonly IMqttNetLogger _logger; private readonly IMqttServerOptions _options; @@ -28,7 +28,7 @@ namespace MQTTnet.Server return; } - await _gate.WaitAsync(); + await _semaphore.WaitAsync().ConfigureAwait(false); try { var retainedMessages = await _options.Storage.LoadRetainedMessagesAsync(); @@ -45,7 +45,7 @@ namespace MQTTnet.Server } finally { - _gate.Release(); + _semaphore.Release(); } } @@ -53,7 +53,7 @@ namespace MQTTnet.Server { if (applicationMessage == null) throw new ArgumentNullException(nameof(applicationMessage)); - await _gate.WaitAsync().ConfigureAwait(false); + await _semaphore.WaitAsync().ConfigureAwait(false); try { await HandleMessageInternalAsync(clientId, applicationMessage); @@ -64,7 +64,7 @@ namespace MQTTnet.Server } finally { - _gate.Release(); + _semaphore.Release(); } } @@ -72,7 +72,7 @@ namespace MQTTnet.Server { var retainedMessages = new List(); - await _gate.WaitAsync().ConfigureAwait(false); + await _semaphore.WaitAsync().ConfigureAwait(false); try { foreach (var retainedMessage in _retainedMessages.Values) @@ -96,7 +96,7 @@ namespace MQTTnet.Server } finally { - _gate.Release(); + _semaphore.Release(); } return retainedMessages; diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttServer.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttServer.cs index 42c6854..888dd42 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttServer.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttServer.cs @@ -60,11 +60,7 @@ namespace MQTTnet.Server _cancellationTokenSource = new CancellationTokenSource(); _retainedMessagesManager = new MqttRetainedMessagesManager(_options, _logger); - - _clientSessionsManager = new MqttClientSessionsManager(_options, _retainedMessagesManager, _logger); - _clientSessionsManager.ApplicationMessageReceived += OnApplicationMessageReceived; - _clientSessionsManager.ClientConnected += OnClientConnected; - _clientSessionsManager.ClientDisconnected += OnClientDisconnected; + _clientSessionsManager = new MqttClientSessionsManager(_options, _retainedMessagesManager, this, _logger); await _retainedMessagesManager.LoadMessagesAsync(); @@ -104,40 +100,39 @@ namespace MQTTnet.Server finally { _cancellationTokenSource = null; - _retainedMessagesManager = null; - - if (_clientSessionsManager != null) - { - _clientSessionsManager.ApplicationMessageReceived -= OnApplicationMessageReceived; - _clientSessionsManager.ClientConnected -= OnClientConnected; - _clientSessionsManager.ClientDisconnected -= OnClientDisconnected; - } - _clientSessionsManager = null; } } - private void OnClientAccepted(object sender, MqttServerAdapterClientAcceptedEventArgs eventArgs) + internal void OnClientConnected(ConnectedMqttClient client) { - eventArgs.SessionTask = Task.Run(async () => await _clientSessionsManager.RunClientSessionAsync(eventArgs.Client, _cancellationTokenSource.Token), _cancellationTokenSource.Token); + if (client == null) throw new ArgumentNullException(nameof(client)); + + _logger.Info("Client '{0}': Connected.", client.ClientId); + ClientConnected?.Invoke(this, new MqttClientConnectedEventArgs(client)); } - private void OnClientConnected(object sender, MqttClientConnectedEventArgs eventArgs) + internal void OnClientDisconnected(ConnectedMqttClient client) { - _logger.Info("Client '{0}': Connected.", eventArgs.Client.ClientId); - ClientConnected?.Invoke(this, eventArgs); + if (client == null) throw new ArgumentNullException(nameof(client)); + + _logger.Info("Client '{0}': Disconnected.", client.ClientId); + ClientDisconnected?.Invoke(this, new MqttClientDisconnectedEventArgs(client)); } - private void OnClientDisconnected(object sender, MqttClientDisconnectedEventArgs eventArgs) + internal void OnApplicationMessageReceived(string clientId, MqttApplicationMessage applicationMessage) { - _logger.Info("Client '{0}': Disconnected.", eventArgs.Client.ClientId); - ClientDisconnected?.Invoke(this, eventArgs); + if (applicationMessage == null) throw new ArgumentNullException(nameof(applicationMessage)); + + ApplicationMessageReceived?.Invoke(this, new MqttApplicationMessageReceivedEventArgs(clientId, applicationMessage)); } - private void OnApplicationMessageReceived(object sender, MqttApplicationMessageReceivedEventArgs e) + private void OnClientAccepted(object sender, MqttServerAdapterClientAcceptedEventArgs eventArgs) { - ApplicationMessageReceived?.Invoke(this, e); + eventArgs.SessionTask = Task.Run( + async () => await _clientSessionsManager.RunClientSessionAsync(eventArgs.Client, _cancellationTokenSource.Token).ConfigureAwait(false), + _cancellationTokenSource.Token); } } } diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttSubscriptionInterceptorContext.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttSubscriptionInterceptorContext.cs index e05dd21..07b94bb 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttSubscriptionInterceptorContext.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttSubscriptionInterceptorContext.cs @@ -1,17 +1,19 @@ -namespace MQTTnet.Server +using System; + +namespace MQTTnet.Server { public class MqttSubscriptionInterceptorContext { public MqttSubscriptionInterceptorContext(string clientId, TopicFilter topicFilter) { ClientId = clientId; - TopicFilter = topicFilter; + TopicFilter = topicFilter ?? throw new ArgumentNullException(nameof(topicFilter)); } public string ClientId { get; } public TopicFilter TopicFilter { get; } - + public bool AcceptSubscription { get; set; } = true; public bool CloseConnection { get; set; } diff --git a/Frameworks/MQTTnet.NetStandard/TopicFilter.cs b/Frameworks/MQTTnet.NetStandard/TopicFilter.cs index b82fc71..da126d6 100644 --- a/Frameworks/MQTTnet.NetStandard/TopicFilter.cs +++ b/Frameworks/MQTTnet.NetStandard/TopicFilter.cs @@ -4,7 +4,7 @@ namespace MQTTnet { public sealed class TopicFilter { - public TopicFilter(string topic, MqttQualityOfServiceLevel qualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce) + public TopicFilter(string topic, MqttQualityOfServiceLevel qualityOfServiceLevel) { Topic = topic; QualityOfServiceLevel = qualityOfServiceLevel; diff --git a/MQTTnet.sln b/MQTTnet.sln index ceaa04f..cece21c 100644 --- a/MQTTnet.sln +++ b/MQTTnet.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.27004.2009 +VisualStudioVersion = 15.0.27004.2010 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.Core.Tests", "Tests\MQTTnet.Core.Tests\MQTTnet.Core.Tests.csproj", "{A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}" EndProject @@ -33,6 +33,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.TestApp.AspNetCore2 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.AspNetCore", "Frameworks\MQTTnet.AspnetCore\MQTTnet.AspNetCore.csproj", "{F10C4060-F7EE-4A83-919F-FF723E72F94A}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Extensions", "Extensions", "{12816BCC-AF9E-44A9-9AE5-C246AF2A0587}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.Extensions.Rpc", "Extensions\MQTTnet.Extensions.Rpc\MQTTnet.Extensions.Rpc.csproj", "{C444E9C8-95FA-430E-9126-274129DE16CD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -147,6 +151,22 @@ Global {F10C4060-F7EE-4A83-919F-FF723E72F94A}.Release|x64.Build.0 = Release|Any CPU {F10C4060-F7EE-4A83-919F-FF723E72F94A}.Release|x86.ActiveCfg = Release|Any CPU {F10C4060-F7EE-4A83-919F-FF723E72F94A}.Release|x86.Build.0 = Release|Any CPU + {C444E9C8-95FA-430E-9126-274129DE16CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C444E9C8-95FA-430E-9126-274129DE16CD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C444E9C8-95FA-430E-9126-274129DE16CD}.Debug|ARM.ActiveCfg = Debug|Any CPU + {C444E9C8-95FA-430E-9126-274129DE16CD}.Debug|ARM.Build.0 = Debug|Any CPU + {C444E9C8-95FA-430E-9126-274129DE16CD}.Debug|x64.ActiveCfg = Debug|Any CPU + {C444E9C8-95FA-430E-9126-274129DE16CD}.Debug|x64.Build.0 = Debug|Any CPU + {C444E9C8-95FA-430E-9126-274129DE16CD}.Debug|x86.ActiveCfg = Debug|Any CPU + {C444E9C8-95FA-430E-9126-274129DE16CD}.Debug|x86.Build.0 = Debug|Any CPU + {C444E9C8-95FA-430E-9126-274129DE16CD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C444E9C8-95FA-430E-9126-274129DE16CD}.Release|Any CPU.Build.0 = Release|Any CPU + {C444E9C8-95FA-430E-9126-274129DE16CD}.Release|ARM.ActiveCfg = Release|Any CPU + {C444E9C8-95FA-430E-9126-274129DE16CD}.Release|ARM.Build.0 = Release|Any CPU + {C444E9C8-95FA-430E-9126-274129DE16CD}.Release|x64.ActiveCfg = Release|Any CPU + {C444E9C8-95FA-430E-9126-274129DE16CD}.Release|x64.Build.0 = Release|Any CPU + {C444E9C8-95FA-430E-9126-274129DE16CD}.Release|x86.ActiveCfg = Release|Any CPU + {C444E9C8-95FA-430E-9126-274129DE16CD}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -158,6 +178,7 @@ Global {3D283AAD-AAA8-4339-8394-52F80B6304DB} = {9248C2E1-B9D6-40BF-81EC-86004D7765B4} {C6FF8AEA-0855-41EC-A1F3-AC262225BAB9} = {9248C2E1-B9D6-40BF-81EC-86004D7765B4} {F10C4060-F7EE-4A83-919F-FF723E72F94A} = {32A630A7-2598-41D7-B625-204CD906F5FB} + {C444E9C8-95FA-430E-9126-274129DE16CD} = {12816BCC-AF9E-44A9-9AE5-C246AF2A0587} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {07536672-5CBC-4BE3-ACE0-708A431A7894} diff --git a/Tests/MQTTnet.Core.Tests/MqttPacketSerializerTests.cs b/Tests/MQTTnet.Core.Tests/MqttPacketSerializerTests.cs index 25c9352..9f51b86 100644 --- a/Tests/MQTTnet.Core.Tests/MqttPacketSerializerTests.cs +++ b/Tests/MQTTnet.Core.Tests/MqttPacketSerializerTests.cs @@ -4,7 +4,6 @@ using System.IO; using System.Text; using System.Threading; using Microsoft.VisualStudio.TestTools.UnitTesting; -using MQTTnet.Adapter; using MQTTnet.Packets; using MQTTnet.Protocol; using MQTTnet.Serializer; @@ -410,7 +409,7 @@ namespace MQTTnet.Core.Tests using (var bodyStream = new MemoryStream(Join(buffer1), (int)headerStream.Position, header.BodyLength)) { - var deserializedPacket = serializer.Deserialize(new ReceivedMqttPacket(header, bodyStream)); + var deserializedPacket = serializer.Deserialize(header, bodyStream.ToArray()); var buffer2 = serializer.Serialize(deserializedPacket); Assert.AreEqual(expectedBase64Value, Convert.ToBase64String(Join(buffer2))); diff --git a/Tests/MQTTnet.Core.Tests/MqttServerTests.cs b/Tests/MQTTnet.Core.Tests/MqttServerTests.cs index f1c8ff0..5081dfc 100644 --- a/Tests/MQTTnet.Core.Tests/MqttServerTests.cs +++ b/Tests/MQTTnet.Core.Tests/MqttServerTests.cs @@ -62,7 +62,7 @@ namespace MQTTnet.Core.Tests var c2 = await serverAdapter.ConnectTestClient(s, "c2", willMessage); c1.ApplicationMessageReceived += (_, __) => receivedMessagesCount++; - await c1.SubscribeAsync(new TopicFilter("#")); + await c1.SubscribeAsync(new TopicFilterBuilder().WithTopic("#").Build()); await c2.DisconnectAsync(); @@ -167,7 +167,7 @@ namespace MQTTnet.Core.Tests var c2 = await serverAdapter.ConnectTestClient(s, "c2"); c2.ApplicationMessageReceived += (_, __) => receivedMessagesCount++; - await c2.SubscribeAsync(new TopicFilter("retained")); + await c2.SubscribeAsync(new TopicFilterBuilder().WithTopic("retained").Build()); await Task.Delay(500); } @@ -199,7 +199,7 @@ namespace MQTTnet.Core.Tests var c2 = await serverAdapter.ConnectTestClient(s, "c2"); c2.ApplicationMessageReceived += (_, __) => receivedMessagesCount++; - await c2.SubscribeAsync(new TopicFilter("retained")); + await c2.SubscribeAsync(new TopicFilterBuilder().WithTopic("retained").Build()); await Task.Delay(500); } @@ -277,7 +277,7 @@ namespace MQTTnet.Core.Tests var c2 = await serverAdapter.ConnectTestClient(s, "c2"); c2.ApplicationMessageReceived += (_, __) => receivedMessagesCount++; - await c2.SubscribeAsync(new TopicFilter("retained")); + await c2.SubscribeAsync(new TopicFilterBuilder().WithTopic("retained").Build()); await Task.Delay(500); } diff --git a/Tests/MQTTnet.Core.Tests/MqttSubscriptionsManagerTests.cs b/Tests/MQTTnet.Core.Tests/MqttSubscriptionsManagerTests.cs index b6b68dc..50acd61 100644 --- a/Tests/MQTTnet.Core.Tests/MqttSubscriptionsManagerTests.cs +++ b/Tests/MQTTnet.Core.Tests/MqttSubscriptionsManagerTests.cs @@ -14,9 +14,9 @@ namespace MQTTnet.Core.Tests var sm = new MqttClientSubscriptionsManager(new MqttServerOptions()); var sp = new MqttSubscribePacket(); - sp.TopicFilters.Add(new TopicFilter("A/B/C")); + sp.TopicFilters.Add(new TopicFilterBuilder().WithTopic("A/B/C").Build()); - sm.Subscribe(sp, ""); + sm.SubscribeAsync(sp, "").Wait(); var pp = new MqttApplicationMessage { @@ -24,7 +24,52 @@ namespace MQTTnet.Core.Tests QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce }; - Assert.IsTrue(sm.CheckSubscriptions(pp).IsSubscribed); + var result = sm.CheckSubscriptionsAsync(pp).Result; + Assert.IsTrue(result.IsSubscribed); + Assert.AreEqual(result.QualityOfServiceLevel, MqttQualityOfServiceLevel.AtMostOnce); + } + + [TestMethod] + public void MqttSubscriptionsManager_SubscribeDifferentQoSSuccess() + { + var sm = new MqttClientSubscriptionsManager(new MqttServerOptions()); + + var sp = new MqttSubscribePacket(); + sp.TopicFilters.Add(new TopicFilter("A/B/C", MqttQualityOfServiceLevel.AtMostOnce)); + + sm.SubscribeAsync(sp, "").Wait(); + + var pp = new MqttApplicationMessage + { + Topic = "A/B/C", + QualityOfServiceLevel = MqttQualityOfServiceLevel.ExactlyOnce + }; + + var result = sm.CheckSubscriptionsAsync(pp).Result; + Assert.IsTrue(result.IsSubscribed); + Assert.AreEqual(result.QualityOfServiceLevel, MqttQualityOfServiceLevel.AtMostOnce); + } + + [TestMethod] + public void MqttSubscriptionsManager_SubscribeTwoTimesSuccess() + { + var sm = new MqttClientSubscriptionsManager(new MqttServerOptions()); + + var sp = new MqttSubscribePacket(); + sp.TopicFilters.Add(new TopicFilter("#", MqttQualityOfServiceLevel.AtMostOnce)); + sp.TopicFilters.Add(new TopicFilter("A/B/C", MqttQualityOfServiceLevel.AtLeastOnce)); + + sm.SubscribeAsync(sp, "").Wait(); + + var pp = new MqttApplicationMessage + { + Topic = "A/B/C", + QualityOfServiceLevel = MqttQualityOfServiceLevel.ExactlyOnce + }; + + var result = sm.CheckSubscriptionsAsync(pp).Result; + Assert.IsTrue(result.IsSubscribed); + Assert.AreEqual(result.QualityOfServiceLevel, MqttQualityOfServiceLevel.AtLeastOnce); } [TestMethod] @@ -33,9 +78,9 @@ namespace MQTTnet.Core.Tests var sm = new MqttClientSubscriptionsManager(new MqttServerOptions()); var sp = new MqttSubscribePacket(); - sp.TopicFilters.Add(new TopicFilter("A/B/C")); + sp.TopicFilters.Add(new TopicFilterBuilder().WithTopic("A/B/C").Build()); - sm.Subscribe(sp, ""); + sm.SubscribeAsync(sp, "").Wait(); var pp = new MqttApplicationMessage { @@ -43,7 +88,7 @@ namespace MQTTnet.Core.Tests QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce }; - Assert.IsFalse(sm.CheckSubscriptions(pp).IsSubscribed); + Assert.IsFalse(sm.CheckSubscriptionsAsync(pp).Result.IsSubscribed); } [TestMethod] @@ -52,9 +97,9 @@ namespace MQTTnet.Core.Tests var sm = new MqttClientSubscriptionsManager(new MqttServerOptions()); var sp = new MqttSubscribePacket(); - sp.TopicFilters.Add(new TopicFilter("A/B/C")); + sp.TopicFilters.Add(new TopicFilterBuilder().WithTopic("A/B/C").Build()); - sm.Subscribe(sp, ""); + sm.SubscribeAsync(sp, "").Wait(); var pp = new MqttApplicationMessage { @@ -62,13 +107,13 @@ namespace MQTTnet.Core.Tests QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce }; - Assert.IsTrue(sm.CheckSubscriptions(pp).IsSubscribed); + Assert.IsTrue(sm.CheckSubscriptionsAsync(pp).Result.IsSubscribed); var up = new MqttUnsubscribePacket(); up.TopicFilters.Add("A/B/C"); - sm.Unsubscribe(up); + sm.UnsubscribeAsync(up).Wait(); - Assert.IsFalse(sm.CheckSubscriptions(pp).IsSubscribed); + Assert.IsFalse(sm.CheckSubscriptionsAsync(pp).Result.IsSubscribed); } } } diff --git a/Tests/MQTTnet.TestApp.NetCore/ClientTest.cs b/Tests/MQTTnet.TestApp.NetCore/ClientTest.cs index 09788cc..dd4a1bc 100644 --- a/Tests/MQTTnet.TestApp.NetCore/ClientTest.cs +++ b/Tests/MQTTnet.TestApp.NetCore/ClientTest.cs @@ -2,6 +2,7 @@ using System.Text; using System.Threading.Tasks; using MQTTnet.Client; +using MQTTnet.Protocol; namespace MQTTnet.TestApp.NetCore { @@ -17,7 +18,8 @@ namespace MQTTnet.TestApp.NetCore CleanSession = true, ChannelOptions = new MqttClientTcpOptions { - Server = "localhost" + //Server = "localhost", + Server = "192.168.1.174" }, //ChannelOptions = new MqttClientWebSocketOptions //{ @@ -78,6 +80,8 @@ namespace MQTTnet.TestApp.NetCore { Console.ReadLine(); + await client.SubscribeAsync(new TopicFilter("test", MqttQualityOfServiceLevel.AtMostOnce)); + var applicationMessage = new MqttApplicationMessageBuilder() .WithTopic("A/B/C") .WithPayload("Hello World") diff --git a/Tests/MQTTnet.TestApp.NetCore/MQTTnet.TestApp.NetCore.csproj b/Tests/MQTTnet.TestApp.NetCore/MQTTnet.TestApp.NetCore.csproj index 8f25448..1784cc0 100644 --- a/Tests/MQTTnet.TestApp.NetCore/MQTTnet.TestApp.NetCore.csproj +++ b/Tests/MQTTnet.TestApp.NetCore/MQTTnet.TestApp.NetCore.csproj @@ -6,6 +6,10 @@ netcoreapp2.0;net452;net461 + + RELEASE;NETCOREAPP2_0 + + diff --git a/Tests/MQTTnet.TestApp.NetCore/PerformanceTest.cs b/Tests/MQTTnet.TestApp.NetCore/PerformanceTest.cs index 1c72b06..5f2e5ad 100644 --- a/Tests/MQTTnet.TestApp.NetCore/PerformanceTest.cs +++ b/Tests/MQTTnet.TestApp.NetCore/PerformanceTest.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; @@ -64,9 +63,17 @@ namespace MQTTnet.TestApp.NetCore sentMessagesCount++; } - Console.WriteLine($"Sending {sentMessagesCount} messages per second."); - + Console.WriteLine($"Sending {sentMessagesCount} messages per second. #1"); + + sentMessagesCount = 0; stopwatch.Restart(); + while (stopwatch.ElapsedMilliseconds < 1000) + { + await client.PublishAsync(messages).ConfigureAwait(false); + sentMessagesCount++; + } + + Console.WriteLine($"Sending {sentMessagesCount} messages per second. #2"); var testMessageCount = 10000; for (var i = 0; i < testMessageCount; i++) @@ -141,8 +148,8 @@ namespace MQTTnet.TestApp.NetCore { var mqttServer = new MqttFactory().CreateMqttServer(); - var msgs = 0; - var stopwatch = Stopwatch.StartNew(); + ////var msgs = 0; + ////var stopwatch = Stopwatch.StartNew(); ////mqttServer.ApplicationMessageReceived += (sender, args) => ////{ //// msgs++; diff --git a/Tests/MQTTnet.TestApp.NetCore/ServerTest.cs b/Tests/MQTTnet.TestApp.NetCore/ServerTest.cs index 8f89176..bd8b4ef 100644 --- a/Tests/MQTTnet.TestApp.NetCore/ServerTest.cs +++ b/Tests/MQTTnet.TestApp.NetCore/ServerTest.cs @@ -29,6 +29,7 @@ namespace MQTTnet.TestApp.NetCore }, Storage = new RetainedMessageHandler(), + ApplicationMessageInterceptor = context => { if (MqttTopicFilterComparer.IsMatch(context.ApplicationMessage.Topic, "/myTopic/WithTimestamp/#")) @@ -67,18 +68,29 @@ namespace MQTTnet.TestApp.NetCore mqttServer.ApplicationMessageReceived += (s, e) => { MqttNetConsoleLogger.PrintToConsole( - $"'{e.ClientId}' reported '{e.ApplicationMessage.Topic}' > '{Encoding.UTF8.GetString(e.ApplicationMessage.Payload)}'", + $"'{e.ClientId}' reported '{e.ApplicationMessage.Topic}' > '{Encoding.UTF8.GetString(e.ApplicationMessage.Payload ?? new byte[0])}'", ConsoleColor.Magenta); }; options.ApplicationMessageInterceptor = c => { - var content = JObject.Parse(Encoding.UTF8.GetString(c.ApplicationMessage.Payload)); - var timestampProperty = content.Property("timestamp"); - if (timestampProperty != null && timestampProperty.Value.Type == JTokenType.Null) + if (c.ApplicationMessage.Payload == null || c.ApplicationMessage.Payload.Length == 0) + { + return; + } + + try + { + var content = JObject.Parse(Encoding.UTF8.GetString(c.ApplicationMessage.Payload)); + var timestampProperty = content.Property("timestamp"); + if (timestampProperty != null && timestampProperty.Value.Type == JTokenType.Null) + { + timestampProperty.Value = DateTime.Now.ToString("O"); + c.ApplicationMessage.Payload = Encoding.UTF8.GetBytes(content.ToString()); + } + } + catch (Exception e) { - timestampProperty.Value = DateTime.Now.ToString("O"); - c.ApplicationMessage.Payload = Encoding.UTF8.GetBytes(content.ToString()); } }; diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/MQTTnet.TestApp.UniversalWindows.csproj b/Tests/MQTTnet.TestApp.UniversalWindows/MQTTnet.TestApp.UniversalWindows.csproj index 4445af3..5636dd2 100644 --- a/Tests/MQTTnet.TestApp.UniversalWindows/MQTTnet.TestApp.UniversalWindows.csproj +++ b/Tests/MQTTnet.TestApp.UniversalWindows/MQTTnet.TestApp.UniversalWindows.csproj @@ -127,6 +127,10 @@ + + {c444e9c8-95fa-430e-9126-274129de16cd} + MQTTnet.Extensions.Rpc + {3587e506-55a2-4eb3-99c7-dc01e42d25d2} MQTTnet.NetStandard diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml b/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml index 43b26c7..cf05888 100644 --- a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml +++ b/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml @@ -65,6 +65,40 @@ + + + Method: + + + Payload: + + + Text + Base64 + + + QoS: + + 0 (At most once) + 1 (At least once) + 2 (Exactly once) + + + Responses: + + + + + + + + + + + + + + Topic: @@ -86,7 +120,7 @@ - + @@ -101,7 +135,7 @@ Persist retained messages in JSON format Clear previously retained messages on startup - + diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs b/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs index 00c6ffa..bbd6474 100644 --- a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs +++ b/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs @@ -7,6 +7,8 @@ using Windows.UI.Core; using Windows.UI.Xaml; using MQTTnet.Client; using MQTTnet.Diagnostics; +using MQTTnet.Exceptions; +using MQTTnet.Extensions.Rpc; using MQTTnet.Implementations; using MQTTnet.ManagedClient; using MQTTnet.Protocol; @@ -245,6 +247,95 @@ namespace MQTTnet.TestApp.UniversalWindows // This code is for the Wiki at GitHub! // ReSharper disable once UnusedMember.Local + + private async void StartServer(object sender, RoutedEventArgs e) + { + if (_mqttServer != null) + { + return; + } + + JsonServerStorage storage = null; + if (ServerPersistRetainedMessages.IsChecked == true) + { + storage = new JsonServerStorage(); + + if (ServerClearRetainedMessages.IsChecked == true) + { + storage.Clear(); + } + } + + _mqttServer = new MqttFactory().CreateMqttServer(); + + var options = new MqttServerOptions(); + options.DefaultEndpointOptions.Port = int.Parse(ServerPort.Text); + options.Storage = storage; + + await _mqttServer.StartAsync(options); + } + + private async void StopServer(object sender, RoutedEventArgs e) + { + if (_mqttServer == null) + { + return; + } + + await _mqttServer.StopAsync(); + _mqttServer = null; + } + + private void ClearReceivedMessages(object sender, RoutedEventArgs e) + { + ReceivedMessages.Items.Clear(); + } + + private async void ExecuteRpc(object sender, RoutedEventArgs e) + { + var qos = MqttQualityOfServiceLevel.AtMostOnce; + if (RpcQoS1.IsChecked == true) + { + qos = MqttQualityOfServiceLevel.AtLeastOnce; + } + + if (RpcQoS2.IsChecked == true) + { + qos = MqttQualityOfServiceLevel.ExactlyOnce; + } + + var payload = new byte[0]; + if (RpcText.IsChecked == true) + { + payload = Encoding.UTF8.GetBytes(RpcPayload.Text); + } + + if (RpcBase64.IsChecked == true) + { + payload = Convert.FromBase64String(RpcPayload.Text); + } + + + try + { + var rpcClient = new MqttRpcClient(_mqttClient); + await rpcClient.EnableAsync(); + var response = await rpcClient.ExecuteAsync(TimeSpan.FromSeconds(5), RpcMethod.Text, payload, qos); + await rpcClient.DisableAsync(); + + RpcResponses.Items.Add(RpcMethod.Text + " >>> " + Encoding.UTF8.GetString(response)); + } + catch (MqttCommunicationTimedOutException) + { + RpcResponses.Items.Add(RpcMethod.Text + " >>> [TIMEOUT]"); + } + } + + private void ClearRpcResponses(object sender, RoutedEventArgs e) + { + RpcResponses.Items.Clear(); + } + private async Task WikiCode() { { @@ -293,9 +384,9 @@ namespace MQTTnet.TestApp.UniversalWindows { // Use secure TCP connection. var options = new MqttClientOptionsBuilder() - .WithTcpServer("broker.hivemq.com") - .WithTls() - .Build(); + .WithTcpServer("broker.hivemq.com") + .WithTls() + .Build(); } { @@ -480,48 +571,5 @@ namespace MQTTnet.TestApp.UniversalWindows } } - - private async void StartServer(object sender, RoutedEventArgs e) - { - if (_mqttServer != null) - { - return; - } - - JsonServerStorage storage = null; - if (ServerPersistRetainedMessages.IsChecked == true) - { - storage = new JsonServerStorage(); - - if (ServerClearRetainedMessages.IsChecked == true) - { - storage.Clear(); - } - } - - _mqttServer = new MqttFactory().CreateMqttServer(); - - var options = new MqttServerOptions(); - options.DefaultEndpointOptions.Port = int.Parse(ServerPort.Text); - options.Storage = storage; - - await _mqttServer.StartAsync(options); - } - - private async void StopServer(object sender, RoutedEventArgs e) - { - if (_mqttServer == null) - { - return; - } - - await _mqttServer.StopAsync(); - _mqttServer = null; - } - - private void ClearReceivedMessages(object sender, RoutedEventArgs e) - { - ReceivedMessages.Items.Clear(); - } } } From 644e9484890bd1bf21868deebd70707fcbc9fbec Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Mon, 4 Dec 2017 13:52:14 +0100 Subject: [PATCH 10/22] Fix keep alive checks in server --- Build/MQTTnet.nuspec | 1 + .../MqttWebSocketServerAdapter.cs | 2 +- .../MQTTnet.NetStandard/Client/MqttClient.cs | 7 +- .../Server/MqttClientPendingMessagesQueue.cs | 36 +++++---- .../Server/MqttClientSession.cs | 77 +++++++++++++++---- .../Server/MqttClientSessionsManager.cs | 6 +- .../MQTTnet.NetStandard/Server/MqttServer.cs | 1 - .../MainPage.xaml | 4 +- .../MainPage.xaml.cs | 3 +- 9 files changed, 98 insertions(+), 39 deletions(-) diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec index 302b128..ab982c0 100644 --- a/Build/MQTTnet.nuspec +++ b/Build/MQTTnet.nuspec @@ -22,6 +22,7 @@ * [Server] Added packet statistics for the connected clients. * [Server] Fixed a security issue which sends retained packages to a failed subscription. * [Server] Fixed the response (MaximumQoS) of a subscription (Thanks to @redbeans2017). +* [Server] The keep alive timeouts are now checked for every client (Thanks to @RainerMueller82). Copyright Christian Kratky 2016-2017 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 diff --git a/Frameworks/MQTTnet.AspnetCore/MqttWebSocketServerAdapter.cs b/Frameworks/MQTTnet.AspnetCore/MqttWebSocketServerAdapter.cs index a2ca627..c84b9be 100644 --- a/Frameworks/MQTTnet.AspnetCore/MqttWebSocketServerAdapter.cs +++ b/Frameworks/MQTTnet.AspnetCore/MqttWebSocketServerAdapter.cs @@ -8,7 +8,7 @@ using MQTTnet.Server; namespace MQTTnet.AspNetCore { - public class MqttWebSocketServerAdapter : IMqttServerAdapter, IDisposable + public sealed class MqttWebSocketServerAdapter : IMqttServerAdapter, IDisposable { public event EventHandler ClientAccepted; diff --git a/Frameworks/MQTTnet.NetStandard/Client/MqttClient.cs b/Frameworks/MQTTnet.NetStandard/Client/MqttClient.cs index b765870..b5592e0 100644 --- a/Frameworks/MQTTnet.NetStandard/Client/MqttClient.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/MqttClient.cs @@ -347,13 +347,8 @@ namespace MQTTnet.Client { while (!cancellationToken.IsCancellationRequested) { - await Task.Delay(_options.KeepAlivePeriod, cancellationToken).ConfigureAwait(false); - if (cancellationToken.IsCancellationRequested) - { - return; - } - await SendAndReceiveAsync(new MqttPingReqPacket()).ConfigureAwait(false); + await Task.Delay(_options.KeepAlivePeriod, cancellationToken).ConfigureAwait(false); } } catch (OperationCanceledException) diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttClientPendingMessagesQueue.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientPendingMessagesQueue.cs index a64dfbf..2048d52 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttClientPendingMessagesQueue.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientPendingMessagesQueue.cs @@ -10,9 +10,9 @@ using MQTTnet.Protocol; namespace MQTTnet.Server { - public sealed class MqttClientPendingMessagesQueue + public sealed class MqttClientPendingMessagesQueue : IDisposable { - private readonly BlockingCollection _pendingPublishPackets = new BlockingCollection(); + private readonly BlockingCollection _queue = new BlockingCollection(); private readonly IMqttServerOptions _options; private readonly MqttClientSession _session; private readonly IMqttNetLogger _logger; @@ -33,24 +33,24 @@ namespace MQTTnet.Server return; } - Task.Run(async () => await SendPendingPublishPacketsAsync(adapter, cancellationToken), cancellationToken).ConfigureAwait(false); + Task.Run(async () => await SendQueuedPacketsAsync(adapter, cancellationToken), cancellationToken).ConfigureAwait(false); } - public void Enqueue(MqttPublishPacket publishPacket) + public void Enqueue(MqttBasePacket packet) { - if (publishPacket == null) throw new ArgumentNullException(nameof(publishPacket)); + if (packet == null) throw new ArgumentNullException(nameof(packet)); - _pendingPublishPackets.Add(publishPacket); + _queue.Add(packet); _logger.Trace("Enqueued packet (ClientId: {0}).", _session.ClientId); } - private async Task SendPendingPublishPacketsAsync(IMqttChannelAdapter adapter, CancellationToken cancellationToken) + private async Task SendQueuedPacketsAsync(IMqttChannelAdapter adapter, CancellationToken cancellationToken) { try { while (!cancellationToken.IsCancellationRequested) { - await SendPendingPublishPacketAsync(adapter, cancellationToken); + await SendQueuedPacketAsync(adapter, cancellationToken); } } catch (OperationCanceledException) @@ -62,12 +62,12 @@ namespace MQTTnet.Server } } - private async Task SendPendingPublishPacketAsync(IMqttChannelAdapter adapter, CancellationToken cancellationToken) + private async Task SendQueuedPacketAsync(IMqttChannelAdapter adapter, CancellationToken cancellationToken) { - MqttPublishPacket packet = null; + MqttBasePacket packet = null; try { - packet = _pendingPublishPackets.Take(cancellationToken); + packet = _queue.Take(cancellationToken); await adapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, packet).ConfigureAwait(false); _logger.Trace("Enqueued packet sent (ClientId: {0}).", _session.ClientId); @@ -90,14 +90,22 @@ namespace MQTTnet.Server _logger.Error(exception, "Sending publish packet failed (ClientId: {0}).", _session.ClientId); } - if (packet != null && packet.QualityOfServiceLevel > MqttQualityOfServiceLevel.AtMostOnce) + if (packet is MqttPublishPacket publishPacket) { - packet.Dup = true; - _pendingPublishPackets.Add(packet, CancellationToken.None); + if (publishPacket.QualityOfServiceLevel > MqttQualityOfServiceLevel.AtMostOnce) + { + publishPacket.Dup = true; + _queue.Add(packet, CancellationToken.None); + } } await _session.StopAsync(); } } + + public void Dispose() + { + _queue?.Dispose(); + } } } diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs index 8f7199a..a321d93 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs @@ -12,7 +12,7 @@ using MQTTnet.Serializer; namespace MQTTnet.Server { - public sealed class MqttClientSession + public sealed class MqttClientSession : IDisposable { private readonly Stopwatch _lastPacketReceivedTracker = Stopwatch.StartNew(); private readonly Stopwatch _lastNonKeepAlivePacketReceivedTracker = Stopwatch.StartNew(); @@ -57,22 +57,29 @@ namespace MQTTnet.Server public bool IsConnected => _adapter != null; - public async Task RunAsync(MqttApplicationMessage willMessage, IMqttChannelAdapter adapter) + public async Task RunAsync(MqttConnectPacket connectPacket, IMqttChannelAdapter adapter) { + if (connectPacket == null) throw new ArgumentNullException(nameof(connectPacket)); if (adapter == null) throw new ArgumentNullException(nameof(adapter)); try { - _lastPacketReceivedTracker.Restart(); - _lastNonKeepAlivePacketReceivedTracker.Restart(); - var cancellationTokenSource = new CancellationTokenSource(); - _willMessage = willMessage; + _willMessage = connectPacket.WillMessage; _adapter = adapter; _cancellationTokenSource = cancellationTokenSource; _pendingMessagesQueue.Start(adapter, cancellationTokenSource.Token); + + _lastPacketReceivedTracker.Restart(); + _lastNonKeepAlivePacketReceivedTracker.Restart(); + + if (connectPacket.KeepAlivePeriod > 0) + { + StartCheckingKeepAliveTimeout(TimeSpan.FromSeconds(connectPacket.KeepAlivePeriod), cancellationTokenSource.Token); + } + await ReceivePacketsAsync(adapter, cancellationTokenSource.Token).ConfigureAwait(false); } catch (OperationCanceledException) @@ -136,6 +143,12 @@ namespace MQTTnet.Server _pendingMessagesQueue.Enqueue(publishPacket); } + public void Dispose() + { + _pendingMessagesQueue?.Dispose(); + _cancellationTokenSource?.Dispose(); + } + private async Task ReceivePacketsAsync(IMqttChannelAdapter adapter, CancellationToken cancellationToken) { try @@ -143,6 +156,14 @@ namespace MQTTnet.Server while (!cancellationToken.IsCancellationRequested) { var packet = await adapter.ReceivePacketAsync(TimeSpan.Zero, cancellationToken).ConfigureAwait(false); + + _lastPacketReceivedTracker.Restart(); + + if (!(packet is MqttPingReqPacket)) + { + _lastNonKeepAlivePacketReceivedTracker.Restart(); + } + await ProcessReceivedPacketAsync(adapter, packet, cancellationToken).ConfigureAwait(false); } } @@ -163,13 +184,6 @@ namespace MQTTnet.Server private Task ProcessReceivedPacketAsync(IMqttChannelAdapter adapter, MqttBasePacket packet, CancellationToken cancellationToken) { - _lastPacketReceivedTracker.Restart(); - - if (!(packet is MqttPingReqPacket)) - { - _lastNonKeepAlivePacketReceivedTracker.Restart(); - } - if (packet is MqttPublishPacket publishPacket) { return HandleIncomingPublishPacketAsync(adapter, publishPacket, cancellationToken); @@ -292,5 +306,42 @@ namespace MQTTnet.Server var response = new MqttPubCompPacket { PacketIdentifier = pubRelPacket.PacketIdentifier }; return adapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, response); } + + private void StartCheckingKeepAliveTimeout(TimeSpan keepAlivePeriod, CancellationToken cancellationToken) + { + Task.Run( + async () => await CheckKeepAliveTimeoutAsync(keepAlivePeriod, cancellationToken).ConfigureAwait(false) + , cancellationToken); + } + + private async Task CheckKeepAliveTimeoutAsync(TimeSpan keepAlivePeriod, CancellationToken cancellationToken) + { + try + { + while (!cancellationToken.IsCancellationRequested) + { + // Values described here: [MQTT-3.1.2-24]. + if (_lastPacketReceivedTracker.Elapsed.TotalSeconds > keepAlivePeriod.TotalSeconds * 1.5D) + { + _logger.Warning("Client '{0}': Did not receive any packet or keep alive signal.", ClientId); + await StopAsync(); + return; + } + + await Task.Delay(keepAlivePeriod, cancellationToken); + } + } + catch (OperationCanceledException) + { + } + catch (Exception exception) + { + _logger.Error(exception, "Client '{0}': Unhandled exception while checking keep alive timeouts.", ClientId); + } + finally + { + _logger.Trace("Client {0}: Stopped checking keep alive timeout.", ClientId); + } + } } } diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs index 739f964..7b4d6d1 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs @@ -70,7 +70,7 @@ namespace MQTTnet.Server ProtocolVersion = clientAdapter.PacketSerializer.ProtocolVersion }); - await clientSession.Session.RunAsync(connectPacket.WillMessage, clientAdapter).ConfigureAwait(false); + await clientSession.Session.RunAsync(connectPacket, clientAdapter).ConfigureAwait(false); } catch (Exception exception) { @@ -210,9 +210,11 @@ namespace MQTTnet.Server if (isSessionPresent) { if (connectPacket.CleanSession) - { + { _sessions.Remove(connectPacket.ClientId); + await clientSession.StopAsync().ConfigureAwait(false); + clientSession.Dispose(); clientSession = null; _logger.Trace("Stopped existing session of client '{0}'.", connectPacket.ClientId); diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttServer.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttServer.cs index 888dd42..461842f 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttServer.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttServer.cs @@ -71,7 +71,6 @@ namespace MQTTnet.Server } _logger.Info("Started."); - Started?.Invoke(this, new MqttServerStartedEventArgs()); } diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml b/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml index cf05888..939061b 100644 --- a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml +++ b/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml @@ -27,7 +27,9 @@ Clean session: - + Keep alive interval: + + TCP WS diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs b/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs index bbd6474..ec42bac 100644 --- a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs +++ b/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs @@ -103,7 +103,8 @@ namespace MQTTnet.TestApp.UniversalWindows }; options.CleanSession = CleanSession.IsChecked == true; - + options.KeepAlivePeriod = TimeSpan.FromSeconds(double.Parse(KeepAliveInterval.Text)); + try { if (_mqttClient != null) From 2cb1c544f5dfb24d38b10f93ade1fe031441f349 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Mon, 4 Dec 2017 22:40:44 +0100 Subject: [PATCH 11/22] Add extension method for subscriptions --- Build/MQTTnet.Extensions.Rpc.nuspec | 47 +++++++++++++++++++ Build/build.ps1 | 10 ++++ .../MQTTnet.Extensions.Rpc/MqttRpcClient.cs | 2 +- .../MQTTnet.Extensions.Rpc/SampleCCode.c | 1 + .../Client/MqttClientExtensions.cs | 9 ++++ .../MainPage.xaml | 2 + .../MainPage.xaml.cs | 1 + 7 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 Build/MQTTnet.Extensions.Rpc.nuspec create mode 100644 Extensions/MQTTnet.Extensions.Rpc/SampleCCode.c diff --git a/Build/MQTTnet.Extensions.Rpc.nuspec b/Build/MQTTnet.Extensions.Rpc.nuspec new file mode 100644 index 0000000..ec09c1d --- /dev/null +++ b/Build/MQTTnet.Extensions.Rpc.nuspec @@ -0,0 +1,47 @@ + + + + MQTTnet.Extensions.Rpc + 2.6.0 + Christian Kratky + Christian Kratky + https://github.com/chkr1011/MQTTnet/blob/master/LICENSE + https://github.com/chkr1011/MQTTnet + https://raw.githubusercontent.com/chkr1011/MQTTnet/master/Images/Logo_128x128.png + false + This is a extension library which allows executing synchronous device calls including a response using MQTTnet. + * Initial version. + + Copyright Christian Kratky 2016-2017 + 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 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Build/build.ps1 b/Build/build.ps1 index 09eabf2..2b4ee5f 100644 --- a/Build/build.ps1 +++ b/Build/build.ps1 @@ -8,16 +8,26 @@ $path = &$vswhere -latest -products * -requires Microsoft.Component.MSBuild -pro if ($path) { $msbuild = join-path $path 'MSBuild\15.0\Bin\MSBuild.exe' + # Build the core library &$msbuild ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="net452" /p:FileVersion=$assemblyVersion /p:AssemblyVersion=$assemblyVersion /verbosity:m &$msbuild ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="net461" /p:FileVersion=$assemblyVersion /p:AssemblyVersion=$assemblyVersion /verbosity:m &$msbuild ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="netstandard1.3" /p:FileVersion=$assemblyVersion /p:AssemblyVersion=$assemblyVersion /verbosity:m &$msbuild ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="netstandard2.0" /p:FileVersion=$assemblyVersion /p:AssemblyVersion=$assemblyVersion /verbosity:m &$msbuild ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="uap10.0" /p:FileVersion=$assemblyVersion /p:AssemblyVersion=$assemblyVersion /verbosity:m + # Build the ASP.NET Core 2.0 extension &$msbuild ..\Frameworks\MQTTnet.AspNetCore\MQTTnet.AspNetCore.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="netstandard2.0" /p:FileVersion=$assemblyVersion /p:AssemblyVersion=$assemblyVersion /verbosity:m + # Build the RPC extension + &$msbuild ..\Extensions\MQTTnet.Extensions.Rpc\MQTTnet.Extensions.Rpc.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="net452" /p:FileVersion=$assemblyVersion /p:AssemblyVersion=$assemblyVersion /verbosity:m + &$msbuild ..\Extensions\MQTTnet.Extensions.Rpc\MQTTnet.Extensions.Rpc.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="net461" /p:FileVersion=$assemblyVersion /p:AssemblyVersion=$assemblyVersion /verbosity:m + &$msbuild ..\Extensions\MQTTnet.Extensions.Rpc\MQTTnet.Extensions.Rpc.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="netstandard1.3" /p:FileVersion=$assemblyVersion /p:AssemblyVersion=$assemblyVersion /verbosity:m + &$msbuild ..\Extensions\MQTTnet.Extensions.Rpc\MQTTnet.Extensions.Rpc.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="netstandard2.0" /p:FileVersion=$assemblyVersion /p:AssemblyVersion=$assemblyVersion /verbosity:m + &$msbuild ..\Extensions\MQTTnet.Extensions.Rpc\MQTTnet.Extensions.Rpc.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="uap10.0" /p:FileVersion=$assemblyVersion /p:AssemblyVersion=$assemblyVersion /verbosity:m + Remove-Item .\NuGet -Force -Recurse New-Item -ItemType Directory -Force -Path .\NuGet .\NuGet.exe pack MQTTnet.nuspec -Verbosity detailed -Symbols -OutputDir "NuGet" -Version $nugetVersion .\NuGet.exe pack MQTTnet.AspNetCore.nuspec -Verbosity detailed -Symbols -OutputDir "NuGet" -Version $nugetVersion + .\NuGet.exe pack MQTTnet.Extensions.Rpc.nuspec -Verbosity detailed -Symbols -OutputDir "NuGet" -Version $nugetVersion } \ No newline at end of file diff --git a/Extensions/MQTTnet.Extensions.Rpc/MqttRpcClient.cs b/Extensions/MQTTnet.Extensions.Rpc/MqttRpcClient.cs index 6a9d1c1..938fcb4 100644 --- a/Extensions/MQTTnet.Extensions.Rpc/MqttRpcClient.cs +++ b/Extensions/MQTTnet.Extensions.Rpc/MqttRpcClient.cs @@ -9,7 +9,7 @@ namespace MQTTnet.Extensions.Rpc { public sealed class MqttRpcClient : IDisposable { - private const string ResponseTopic = "$RPC/+/+/response"; + private const string ResponseTopic = "$MQTTnet.RPC/+/+/response"; private readonly ConcurrentDictionary> _waitingCalls = new ConcurrentDictionary>(); private readonly IMqttClient _mqttClient; private bool _isEnabled; diff --git a/Extensions/MQTTnet.Extensions.Rpc/SampleCCode.c b/Extensions/MQTTnet.Extensions.Rpc/SampleCCode.c new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Extensions/MQTTnet.Extensions.Rpc/SampleCCode.c @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Frameworks/MQTTnet.NetStandard/Client/MqttClientExtensions.cs b/Frameworks/MQTTnet.NetStandard/Client/MqttClientExtensions.cs index a1a89e3..73f4d40 100644 --- a/Frameworks/MQTTnet.NetStandard/Client/MqttClientExtensions.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/MqttClientExtensions.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using MQTTnet.Protocol; namespace MQTTnet.Client { @@ -15,6 +16,14 @@ namespace MQTTnet.Client return client.SubscribeAsync(topicFilters.ToList()); } + public static Task> SubscribeAsync(this IMqttClient client, string topic, MqttQualityOfServiceLevel qualityOfServiceLevel) + { + if (client == null) throw new ArgumentNullException(nameof(client)); + if (topic == null) throw new ArgumentNullException(nameof(topic)); + + return client.SubscribeAsync(new TopicFilterBuilder().WithTopic(topic).WithQualityOfServiceLevel(qualityOfServiceLevel).Build()); + } + public static Task UnsubscribeAsync(this IMqttClient client, params string[] topicFilters) { if (client == null) throw new ArgumentNullException(nameof(client)); diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml b/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml index 939061b..dcdee00 100644 --- a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml +++ b/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml @@ -19,6 +19,8 @@ Server: + Port: + User: Password: diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs b/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs index ec42bac..a48b7ee 100644 --- a/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs +++ b/Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs @@ -78,6 +78,7 @@ namespace MQTTnet.TestApp.UniversalWindows options.ChannelOptions = new MqttClientTcpOptions { Server = Server.Text, + Port = int.Parse(Port.Text), TlsOptions = tlsOptions }; } From f974dcb647c98ca467057f13cff61f215175d313 Mon Sep 17 00:00:00 2001 From: cvellan <34144841+cvellan@users.noreply.github.com> Date: Tue, 5 Dec 2017 10:13:07 +1100 Subject: [PATCH 12/22] Serialized certificates loaded as X509Certificate2 Instances of X509Certificate2 passed into an MqttClientOptionsBuilder lose data and functionality by being loaded as an X509Certificate. --- .../MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs index ce9dcf6..8fa93ff 100644 --- a/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs +++ b/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs @@ -130,7 +130,7 @@ namespace MQTTnet.Implementations foreach (var certificate in options.TlsOptions.Certificates) { - certificates.Add(new X509Certificate(certificate)); + certificates.Add(new X509Certificate2(certificate)); } return certificates; @@ -155,4 +155,4 @@ namespace MQTTnet.Implementations } } -#endif \ No newline at end of file +#endif From 333fc4c387002539104e16c9ee06bebe06baa531 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Thu, 7 Dec 2017 20:35:29 +0100 Subject: [PATCH 13/22] Fixed an TLS issue in the MqttClientOptionsBuilder; Fix a subscription issue in the managed client. --- .gitignore | 1 + Build/MQTTnet.nuspec | 2 + .../MQTTnet.NetStandard/Client/IMqttClient.cs | 2 +- .../MQTTnet.NetStandard/Client/MqttClient.cs | 7 +- .../Client/MqttClientOptionsBuilder.cs | 6 +- .../ManagedClient/IManagedMqttClient.cs | 2 +- .../ManagedClient/ManagedMqttClient.cs | 80 +++++++++++++------ .../Server/MqttClientSession.cs | 2 +- Frameworks/MQTTnet.NetStandard/TopicFilter.cs | 9 +-- .../ManagedClientTest.cs | 3 +- 10 files changed, 73 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index 7c38d7d..1e47707 100644 --- a/.gitignore +++ b/.gitignore @@ -293,3 +293,4 @@ Build/nuget.exe *.map *codeSigningKey.pfx +/Tests/MQTTnet.TestApp.NetCore/RetainedMessages.json diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec index ab982c0..096c2b1 100644 --- a/Build/MQTTnet.nuspec +++ b/Build/MQTTnet.nuspec @@ -16,6 +16,8 @@ * [Core] Fixed a logging issue when dealing with IOExceptions. * [Core] Fixed a typo in the global logger class (BREAKING CHANGE! Please find new example in Wiki). * [Client] Fixed an issue in _ManagedClient_ which can cause the client to stop when publishing subscriptions. +* [Client] Fixed an issue in _ManagedClient_ which prevents changing the QoS of an existing subscription (BREAKING CHANGE!). +* [Client] Fixed an issue in _MqttClientOptionsBuilder_ which prevents adding TLS options to the client options when calling _Build()_. (Thanks to @cvellan). * [Server] The application message interceptor can now delete any received application message. * [Server] Added a ConnectionValidator context to align with other APIs (BREAKING CHANGE! Please find new example in Wiki). * [Server] Added an interface for the _MqttServerOptions_. diff --git a/Frameworks/MQTTnet.NetStandard/Client/IMqttClient.cs b/Frameworks/MQTTnet.NetStandard/Client/IMqttClient.cs index 0ac2f49..42ca0a4 100644 --- a/Frameworks/MQTTnet.NetStandard/Client/IMqttClient.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/IMqttClient.cs @@ -15,6 +15,6 @@ namespace MQTTnet.Client Task DisconnectAsync(); Task> SubscribeAsync(IEnumerable topicFilters); - Task UnsubscribeAsync(IEnumerable topicFilters); + Task UnsubscribeAsync(IEnumerable topics); } } \ No newline at end of file diff --git a/Frameworks/MQTTnet.NetStandard/Client/MqttClient.cs b/Frameworks/MQTTnet.NetStandard/Client/MqttClient.cs index b5592e0..9625808 100644 --- a/Frameworks/MQTTnet.NetStandard/Client/MqttClient.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/MqttClient.cs @@ -12,7 +12,7 @@ using MQTTnet.Protocol; namespace MQTTnet.Client { - public class MqttClient : IMqttClient + public class MqttClient : IMqttClient, IDisposable { private readonly IMqttClientAdapterFactory _adapterFactory; private readonly MqttPacketDispatcher _packetDispatcher; @@ -180,6 +180,11 @@ namespace MQTTnet.Client } } + public void Dispose() + { + _cancellationTokenSource?.Dispose(); + } + private async Task AuthenticateAsync(MqttApplicationMessage willApplicationMessage) { var connectPacket = new MqttConnectPacket diff --git a/Frameworks/MQTTnet.NetStandard/Client/MqttClientOptionsBuilder.cs b/Frameworks/MQTTnet.NetStandard/Client/MqttClientOptionsBuilder.cs index 079e635..ad766c3 100644 --- a/Frameworks/MQTTnet.NetStandard/Client/MqttClientOptionsBuilder.cs +++ b/Frameworks/MQTTnet.NetStandard/Client/MqttClientOptionsBuilder.cs @@ -119,11 +119,11 @@ namespace MQTTnet.Client if (_tcpOptions != null) { - _options.ChannelOptions = _tcpOptions; + _tcpOptions.TlsOptions = _tlsOptions; } - else + else if (_webSocketOptions != null) { - _options.ChannelOptions = _webSocketOptions; + _webSocketOptions.TlsOptions = _tlsOptions; } } diff --git a/Frameworks/MQTTnet.NetStandard/ManagedClient/IManagedMqttClient.cs b/Frameworks/MQTTnet.NetStandard/ManagedClient/IManagedMqttClient.cs index 41c0ce3..2475959 100644 --- a/Frameworks/MQTTnet.NetStandard/ManagedClient/IManagedMqttClient.cs +++ b/Frameworks/MQTTnet.NetStandard/ManagedClient/IManagedMqttClient.cs @@ -16,6 +16,6 @@ namespace MQTTnet.ManagedClient Task StopAsync(); Task SubscribeAsync(IEnumerable topicFilters); - Task UnsubscribeAsync(IEnumerable topicFilters); + Task UnsubscribeAsync(IEnumerable topics); } } \ No newline at end of file diff --git a/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs index 9b01156..01fa4cd 100644 --- a/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs +++ b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClient.cs @@ -11,10 +11,10 @@ using MQTTnet.Protocol; namespace MQTTnet.ManagedClient { - public class ManagedMqttClient : IManagedMqttClient + public class ManagedMqttClient : IManagedMqttClient, IDisposable { private readonly BlockingCollection _messageQueue = new BlockingCollection(); - private readonly HashSet _subscriptions = new HashSet(); + private readonly Dictionary _subscriptions = new Dictionary(); private readonly SemaphoreSlim _subscriptionsSemaphore = new SemaphoreSlim(1, 1); private readonly IMqttClient _mqttClient; @@ -75,11 +75,8 @@ namespace MQTTnet.ManagedClient public Task StopAsync() { - _connectionCancellationToken?.Cancel(false); - _connectionCancellationToken = null; - - _publishingCancellationToken?.Cancel(false); - _publishingCancellationToken = null; + StopPublishing(); + StopMaintainingConnection(); while (_messageQueue.Any()) { @@ -88,7 +85,7 @@ namespace MQTTnet.ManagedClient return Task.FromResult(0); } - + public async Task PublishAsync(IEnumerable applicationMessages) { if (applicationMessages == null) throw new ArgumentNullException(nameof(applicationMessages)); @@ -113,10 +110,8 @@ namespace MQTTnet.ManagedClient { foreach (var topicFilter in topicFilters) { - if (_subscriptions.Add(topicFilter)) - { - _subscriptionsNotPushed = true; - } + _subscriptions[topicFilter.Topic] = topicFilter.QualityOfServiceLevel; + _subscriptionsNotPushed = true; } } finally @@ -125,14 +120,14 @@ namespace MQTTnet.ManagedClient } } - public async Task UnsubscribeAsync(IEnumerable topicFilters) + public async Task UnsubscribeAsync(IEnumerable topics) { await _subscriptionsSemaphore.WaitAsync().ConfigureAwait(false); try { - foreach (var topicFilter in topicFilters) + foreach (var topic in topics) { - if (_subscriptions.Remove(topicFilter)) + if (_subscriptions.Remove(topic)) { _subscriptionsNotPushed = true; } @@ -144,6 +139,14 @@ namespace MQTTnet.ManagedClient } } + public void Dispose() + { + _messageQueue?.Dispose(); + _subscriptionsSemaphore?.Dispose(); + _connectionCancellationToken?.Dispose(); + _publishingCancellationToken?.Dispose(); + } + private async Task MaintainConnectionAsync(CancellationToken cancellationToken) { try @@ -174,9 +177,7 @@ namespace MQTTnet.ManagedClient var connectionState = await ReconnectIfRequiredAsync().ConfigureAwait(false); if (connectionState == ReconnectionResult.NotConnected) { - _publishingCancellationToken?.Cancel(false); - _publishingCancellationToken = null; - + StopPublishing(); await Task.Delay(_options.AutoReconnectDelay, cancellationToken).ConfigureAwait(false); return; } @@ -185,18 +186,15 @@ namespace MQTTnet.ManagedClient { await PushSubscriptionsAsync().ConfigureAwait(false); - _publishingCancellationToken = new CancellationTokenSource(); - -#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed - Task.Run(async () => await PublishQueuedMessagesAsync(_publishingCancellationToken.Token).ConfigureAwait(false), _publishingCancellationToken.Token).ConfigureAwait(false); -#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed + StartPublishing(); + return; } if (connectionState == ReconnectionResult.StillConnected) { - await Task.Delay(TimeSpan.FromSeconds(1), _connectionCancellationToken.Token).ConfigureAwait(false); + await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false); } } catch (OperationCanceledException) @@ -211,7 +209,7 @@ namespace MQTTnet.ManagedClient _logger.Error(exception, "Unhandled exception while maintaining connection."); } } - + private async Task PublishQueuedMessagesAsync(CancellationToken cancellationToken) { try @@ -279,7 +277,7 @@ namespace MQTTnet.ManagedClient await _subscriptionsSemaphore.WaitAsync().ConfigureAwait(false); try { - subscriptions = _subscriptions.ToList(); + subscriptions = _subscriptions.Select(i => new TopicFilter(i.Key, i.Value)).ToList(); _subscriptionsNotPushed = false; } finally @@ -335,5 +333,35 @@ namespace MQTTnet.ManagedClient { Connected?.Invoke(this, eventArgs); } + + private void StartPublishing() + { + if (_publishingCancellationToken != null) + { + StopPublishing(); + } + + var cts = new CancellationTokenSource(); + + _publishingCancellationToken = cts; + +#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed + Task.Run(async () => await PublishQueuedMessagesAsync(cts.Token).ConfigureAwait(false), cts.Token).ConfigureAwait(false); +#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed + } + + private void StopPublishing() + { + _publishingCancellationToken?.Cancel(false); + _publishingCancellationToken?.Dispose(); + _publishingCancellationToken = null; + } + + private void StopMaintainingConnection() + { + _connectionCancellationToken?.Cancel(false); + _connectionCancellationToken?.Dispose(); + _connectionCancellationToken = null; + } } } diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs index a321d93..9615f86 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSession.cs @@ -232,8 +232,8 @@ namespace MQTTnet.Server private async Task HandleIncomingSubscribePacketAsync(IMqttChannelAdapter adapter, MqttSubscribePacket subscribePacket, CancellationToken cancellationToken) { var subscribeResult = await _subscriptionsManager.SubscribeAsync(subscribePacket, ClientId); - await adapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, subscribeResult.ResponsePacket).ConfigureAwait(false); + if (subscribeResult.CloseConnection) { await adapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, new MqttDisconnectPacket()).ConfigureAwait(false); diff --git a/Frameworks/MQTTnet.NetStandard/TopicFilter.cs b/Frameworks/MQTTnet.NetStandard/TopicFilter.cs index da126d6..1dad73d 100644 --- a/Frameworks/MQTTnet.NetStandard/TopicFilter.cs +++ b/Frameworks/MQTTnet.NetStandard/TopicFilter.cs @@ -10,14 +10,9 @@ namespace MQTTnet QualityOfServiceLevel = qualityOfServiceLevel; } - public string Topic { get; } + public string Topic { get; set; } - public MqttQualityOfServiceLevel QualityOfServiceLevel { get; } - - public override int GetHashCode() - { - return QualityOfServiceLevel.GetHashCode() ^ (Topic ?? string.Empty).GetHashCode(); - } + public MqttQualityOfServiceLevel QualityOfServiceLevel { get; set; } public override string ToString() { diff --git a/Tests/MQTTnet.TestApp.NetCore/ManagedClientTest.cs b/Tests/MQTTnet.TestApp.NetCore/ManagedClientTest.cs index 21d1fdf..e23e994 100644 --- a/Tests/MQTTnet.TestApp.NetCore/ManagedClientTest.cs +++ b/Tests/MQTTnet.TestApp.NetCore/ManagedClientTest.cs @@ -45,7 +45,8 @@ namespace MQTTnet.TestApp.NetCore await managedClient.StartAsync(options); await managedClient.SubscribeAsync(new TopicFilter("xyz", MqttQualityOfServiceLevel.AtMostOnce)); - + await managedClient.SubscribeAsync(new TopicFilter("abc", MqttQualityOfServiceLevel.AtMostOnce)); + await managedClient.PublishAsync(new MqttApplicationMessageBuilder().WithTopic("Step").WithPayload("3").Build()); Console.WriteLine("Managed client started."); From ad8506cc30e70c10d1208327f97564fb2fd68546 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Thu, 7 Dec 2017 20:41:44 +0100 Subject: [PATCH 14/22] Update documents --- Build/MQTTnet.nuspec | 1 + 1 file changed, 1 insertion(+) diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec index 096c2b1..ee3138c 100644 --- a/Build/MQTTnet.nuspec +++ b/Build/MQTTnet.nuspec @@ -15,6 +15,7 @@ * [Core] Performance optimizations. * [Core] Fixed a logging issue when dealing with IOExceptions. * [Core] Fixed a typo in the global logger class (BREAKING CHANGE! Please find new example in Wiki). +* [Client] The certificate for encryption is now loaded as a _X509Certificate2_ which prodives more data (Thanks to @cvellan). * [Client] Fixed an issue in _ManagedClient_ which can cause the client to stop when publishing subscriptions. * [Client] Fixed an issue in _ManagedClient_ which prevents changing the QoS of an existing subscription (BREAKING CHANGE!). * [Client] Fixed an issue in _MqttClientOptionsBuilder_ which prevents adding TLS options to the client options when calling _Build()_. (Thanks to @cvellan). From fb8b60fcccf5d3922ea010dd37ee51aa70e5eb80 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Fri, 8 Dec 2017 21:12:05 +0100 Subject: [PATCH 15/22] Add overload for subscribing. --- Build/MQTTnet.nuspec | 1 + .../ManagedClient/ManagedMqttClientExtensions.cs | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec index ee3138c..e7ed1cd 100644 --- a/Build/MQTTnet.nuspec +++ b/Build/MQTTnet.nuspec @@ -19,6 +19,7 @@ * [Client] Fixed an issue in _ManagedClient_ which can cause the client to stop when publishing subscriptions. * [Client] Fixed an issue in _ManagedClient_ which prevents changing the QoS of an existing subscription (BREAKING CHANGE!). * [Client] Fixed an issue in _MqttClientOptionsBuilder_ which prevents adding TLS options to the client options when calling _Build()_. (Thanks to @cvellan). +* [Client] Added an overload for subscribing at both clients which reduces required code. * [Server] The application message interceptor can now delete any received application message. * [Server] Added a ConnectionValidator context to align with other APIs (BREAKING CHANGE! Please find new example in Wiki). * [Server] Added an interface for the _MqttServerOptions_. diff --git a/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientExtensions.cs b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientExtensions.cs index e134667..d75117a 100644 --- a/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientExtensions.cs +++ b/Frameworks/MQTTnet.NetStandard/ManagedClient/ManagedMqttClientExtensions.cs @@ -1,5 +1,6 @@ using System; using System.Threading.Tasks; +using MQTTnet.Protocol; namespace MQTTnet.ManagedClient { @@ -12,7 +13,15 @@ namespace MQTTnet.ManagedClient return managedClient.SubscribeAsync(topicFilters); } - public static Task UnsubscribeAsync(this IManagedMqttClient managedClient, params TopicFilter[] topicFilters) + public static Task SubscribeAsync(this IManagedMqttClient managedClient, string topic, MqttQualityOfServiceLevel qualityOfServiceLevel) + { + if (managedClient == null) throw new ArgumentNullException(nameof(managedClient)); + if (topic == null) throw new ArgumentNullException(nameof(topic)); + + return managedClient.SubscribeAsync(new TopicFilterBuilder().WithTopic(topic).WithQualityOfServiceLevel(qualityOfServiceLevel).Build()); + } + + public static Task UnsubscribeAsync(this IManagedMqttClient managedClient, params string[] topicFilters) { if (managedClient == null) throw new ArgumentNullException(nameof(managedClient)); From f91d935708f43b486f36623c60579570f2b91a9a Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Mon, 11 Dec 2017 17:10:27 +0100 Subject: [PATCH 16/22] Add the ClientId to the application message interceptor. --- Build/MQTTnet.nuspec | 1 + .../Implementations/MqttServerAdapter.cs | 2 +- .../MqttApplicationMessageInterceptorContext.cs | 8 ++++++++ .../Server/MqttClientSessionsManager.cs | 15 +++++++-------- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec index e7ed1cd..d107461 100644 --- a/Build/MQTTnet.nuspec +++ b/Build/MQTTnet.nuspec @@ -20,6 +20,7 @@ * [Client] Fixed an issue in _ManagedClient_ which prevents changing the QoS of an existing subscription (BREAKING CHANGE!). * [Client] Fixed an issue in _MqttClientOptionsBuilder_ which prevents adding TLS options to the client options when calling _Build()_. (Thanks to @cvellan). * [Client] Added an overload for subscribing at both clients which reduces required code. +* [Client] Added the _ClientId_ to the application message interceptor context. * [Server] The application message interceptor can now delete any received application message. * [Server] Added a ConnectionValidator context to align with other APIs (BREAKING CHANGE! Please find new example in Wiki). * [Server] Added an interface for the _MqttServerOptions_. diff --git a/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs index a0441bc..c991c23 100644 --- a/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs +++ b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs @@ -145,7 +145,7 @@ namespace MQTTnet.Implementations var sslStream = new SslStream(new NetworkStream(clientSocket)); await sslStream.AuthenticateAsServerAsync(_tlsCertificate, false, SslProtocols.Tls12, false).ConfigureAwait(false); - + var clientAdapter = new MqttChannelAdapter(new MqttTcpChannel(clientSocket, sslStream), new MqttPacketSerializer(), _logger); ClientAccepted?.Invoke(this, new MqttServerAdapterClientAcceptedEventArgs(clientAdapter)); } diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttApplicationMessageInterceptorContext.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttApplicationMessageInterceptorContext.cs index e5f8c3f..8074d52 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttApplicationMessageInterceptorContext.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttApplicationMessageInterceptorContext.cs @@ -2,6 +2,14 @@ { public class MqttApplicationMessageInterceptorContext { + public MqttApplicationMessageInterceptorContext(string clientId, MqttApplicationMessage applicationMessage) + { + ClientId = clientId; + ApplicationMessage = applicationMessage; + } + + public string ClientId { get; } + public MqttApplicationMessage ApplicationMessage { get; set; } } } diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs index 7b4d6d1..28dac0d 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs @@ -136,7 +136,7 @@ namespace MQTTnet.Server { try { - applicationMessage = InterceptApplicationMessage(applicationMessage); + applicationMessage = InterceptApplicationMessage(senderClientSession, applicationMessage); if (applicationMessage == null) { return; @@ -168,17 +168,16 @@ namespace MQTTnet.Server } } - private MqttApplicationMessage InterceptApplicationMessage(MqttApplicationMessage applicationMessage) + private MqttApplicationMessage InterceptApplicationMessage(MqttClientSession senderClientSession, MqttApplicationMessage applicationMessage) { if (_options.ApplicationMessageInterceptor == null) { return applicationMessage; } - var interceptorContext = new MqttApplicationMessageInterceptorContext - { - ApplicationMessage = applicationMessage - }; + var interceptorContext = new MqttApplicationMessageInterceptorContext( + senderClientSession.ClientId, + applicationMessage); _options.ApplicationMessageInterceptor(interceptorContext); return interceptorContext.ApplicationMessage; @@ -190,7 +189,7 @@ namespace MQTTnet.Server { return MqttConnectReturnCode.ConnectionAccepted; } - + var context = new MqttConnectionValidatorContext( connectPacket.ClientId, connectPacket.Username, @@ -210,7 +209,7 @@ namespace MQTTnet.Server if (isSessionPresent) { if (connectPacket.CleanSession) - { + { _sessions.Remove(connectPacket.ClientId); await clientSession.StopAsync().ConfigureAwait(false); From 0f54663789b92122ee8def388c315e9a97393786 Mon Sep 17 00:00:00 2001 From: limingru Date: Tue, 12 Dec 2017 17:21:22 +0800 Subject: [PATCH 17/22] fixed: Compile Source Code Occur Errors On Mac Machine --- Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj b/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj index 92920cd..5436ad4 100644 --- a/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj +++ b/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj @@ -1,7 +1,8 @@  - netstandard1.3;netstandard2.0;net452;net461;uap10.0 + netstandard1.3;netstandard2.0;net452;net461;uap10.0 + netstandard1.3;netstandard2.0 MQTTnet MQTTnet False @@ -14,9 +15,9 @@ - true + From e98ff1d6d6afc6ce24b50f022bcbd9baed75254f Mon Sep 17 00:00:00 2001 From: limingru Date: Tue, 12 Dec 2017 17:26:16 +0800 Subject: [PATCH 18/22] uncomment code --- Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj b/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj index 5436ad4..70415cd 100644 --- a/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj +++ b/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj @@ -15,9 +15,9 @@ - + false From f6b38081fcdb84ed94e30944c9637da2f5f734c8 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Tue, 12 Dec 2017 14:30:28 +0100 Subject: [PATCH 19/22] Update documents. --- Build/MQTTnet.nuspec | 1 + 1 file changed, 1 insertion(+) diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec index d107461..c32772b 100644 --- a/Build/MQTTnet.nuspec +++ b/Build/MQTTnet.nuspec @@ -15,6 +15,7 @@ * [Core] Performance optimizations. * [Core] Fixed a logging issue when dealing with IOExceptions. * [Core] Fixed a typo in the global logger class (BREAKING CHANGE! Please find new example in Wiki). +* [Core] Added support for project compilation under macOS (Thanks to @FourOnes). * [Client] The certificate for encryption is now loaded as a _X509Certificate2_ which prodives more data (Thanks to @cvellan). * [Client] Fixed an issue in _ManagedClient_ which can cause the client to stop when publishing subscriptions. * [Client] Fixed an issue in _ManagedClient_ which prevents changing the QoS of an existing subscription (BREAKING CHANGE!). From 44c07c20344a7f7221913c31c7ae6e674b7a8c90 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Thu, 14 Dec 2017 13:12:18 +0100 Subject: [PATCH 20/22] Fix broken ASP.NET Core integration. --- Frameworks/MQTTnet.AspnetCore/MqttHostedServer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Frameworks/MQTTnet.AspnetCore/MqttHostedServer.cs b/Frameworks/MQTTnet.AspnetCore/MqttHostedServer.cs index 7c7d304..8e6761a 100644 --- a/Frameworks/MQTTnet.AspnetCore/MqttHostedServer.cs +++ b/Frameworks/MQTTnet.AspnetCore/MqttHostedServer.cs @@ -11,9 +11,9 @@ namespace MQTTnet.AspNetCore { public class MqttHostedServer : MqttServer, IHostedService { - private readonly MqttServerOptions _options; + private readonly IMqttServerOptions _options; - public MqttHostedServer(MqttServerOptions options, IEnumerable adapters, IMqttNetLogger logger) : base(adapters, logger) + public MqttHostedServer(IMqttServerOptions options, IEnumerable adapters, IMqttNetLogger logger) : base(adapters, logger) { _options = options ?? throw new ArgumentNullException(nameof(options)); } From e0284886b5ea5cc4c6dd2f38ff6fd256e055b687 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Thu, 14 Dec 2017 13:23:12 +0100 Subject: [PATCH 21/22] Added the bound IP address to the server options. --- .../Implementations/MqttServerAdapter.cs | 4 +-- .../Server/IMqttServerOptions.cs | 12 ++++--- .../MqttServerDefaultEndpointOptions.cs | 6 +++- .../Server/MqttServerOptionsBuilder.cs | 33 +++++++++++++++---- .../Server/MqttServerTlsEndpointOptions.cs | 6 +++- 5 files changed, 46 insertions(+), 15 deletions(-) diff --git a/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs index c991c23..b4869ff 100644 --- a/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs +++ b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs @@ -39,7 +39,7 @@ namespace MQTTnet.Implementations if (options.DefaultEndpointOptions.IsEnabled) { _defaultEndpointSocket = new Socket(SocketType.Stream, ProtocolType.Tcp); - _defaultEndpointSocket.Bind(new IPEndPoint(IPAddress.Any, options.GetDefaultEndpointPort())); + _defaultEndpointSocket.Bind(new IPEndPoint(options.DefaultEndpointOptions.BoundIPAddress, options.GetDefaultEndpointPort())); _defaultEndpointSocket.Listen(options.ConnectionBacklog); Task.Run(async () => await AcceptDefaultEndpointConnectionsAsync(_cancellationTokenSource.Token).ConfigureAwait(false), _cancellationTokenSource.Token).ConfigureAwait(false); @@ -59,7 +59,7 @@ namespace MQTTnet.Implementations } _tlsEndpointSocket = new Socket(SocketType.Stream, ProtocolType.Tcp); - _tlsEndpointSocket.Bind(new IPEndPoint(IPAddress.Any, options.GetTlsEndpointPort())); + _tlsEndpointSocket.Bind(new IPEndPoint(options.TlsEndpointOptions.BoundIPAddress, options.GetTlsEndpointPort())); _tlsEndpointSocket.Listen(options.ConnectionBacklog); Task.Run(async () => await AcceptTlsEndpointConnectionsAsync(_cancellationTokenSource.Token).ConfigureAwait(false), _cancellationTokenSource.Token).ConfigureAwait(false); diff --git a/Frameworks/MQTTnet.NetStandard/Server/IMqttServerOptions.cs b/Frameworks/MQTTnet.NetStandard/Server/IMqttServerOptions.cs index 92c1bfb..d89d915 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/IMqttServerOptions.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/IMqttServerOptions.cs @@ -1,16 +1,20 @@ using System; +using System.Net; namespace MQTTnet.Server { public interface IMqttServerOptions { - Action ApplicationMessageInterceptor { get; } int ConnectionBacklog { get; } - Action ConnectionValidator { get; } TimeSpan DefaultCommunicationTimeout { get; } - MqttServerDefaultEndpointOptions DefaultEndpointOptions { get; } - IMqttServerStorage Storage { get; } + + Action ConnectionValidator { get; } Action SubscriptionInterceptor { get; } + Action ApplicationMessageInterceptor { get; } + + MqttServerDefaultEndpointOptions DefaultEndpointOptions { get; } MqttServerTlsEndpointOptions TlsEndpointOptions { get; } + + IMqttServerStorage Storage { get; } } } \ No newline at end of file diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttServerDefaultEndpointOptions.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttServerDefaultEndpointOptions.cs index 6dc21b3..545499b 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttServerDefaultEndpointOptions.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttServerDefaultEndpointOptions.cs @@ -1,9 +1,13 @@ -namespace MQTTnet.Server +using System.Net; + +namespace MQTTnet.Server { public sealed class MqttServerDefaultEndpointOptions { public bool IsEnabled { get; set; } = true; public int? Port { get; set; } + + public IPAddress BoundIPAddress { get; set; } = IPAddress.Any; } } diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttServerOptionsBuilder.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttServerOptionsBuilder.cs index 34f36a9..18b2de2 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttServerOptionsBuilder.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttServerOptionsBuilder.cs @@ -1,4 +1,5 @@ using System; +using System.Net; namespace MQTTnet.Server { @@ -18,33 +19,45 @@ namespace MQTTnet.Server return this; } - public MqttServerOptionsBuilder WithDefaultEndpointPort(int value) + public MqttServerOptionsBuilder WithDefaultEndpoint() { - _options.DefaultEndpointOptions.Port = value; + _options.DefaultEndpointOptions.IsEnabled = true; return this; } - public MqttServerOptionsBuilder WithDefaultEndpoint() + public MqttServerOptionsBuilder WithDefaultEndpointPort(int? value) { - _options.DefaultEndpointOptions.IsEnabled = true; + _options.DefaultEndpointOptions.Port = value; return this; } + public MqttServerOptionsBuilder WithDefaultEndpointBoundIPAddress(IPAddress value) + { + _options.DefaultEndpointOptions.BoundIPAddress = value ?? IPAddress.Any; + return this; + } + public MqttServerOptionsBuilder WithoutDefaultEndpoint() { _options.DefaultEndpointOptions.IsEnabled = false; return this; } - + public MqttServerOptionsBuilder WithEncryptedEndpoint() { _options.TlsEndpointOptions.IsEnabled = true; return this; } - public MqttServerOptionsBuilder WithoutEncryptedEndpoint() + public MqttServerOptionsBuilder WithEncryptedEndpointPort(int? value) { - _options.TlsEndpointOptions.IsEnabled = false; + _options.TlsEndpointOptions.Port = value; + return this; + } + + public MqttServerOptionsBuilder WithEncryptedEndpointBoundIPAddress(IPAddress value) + { + _options.TlsEndpointOptions.BoundIPAddress = value; return this; } @@ -54,6 +67,12 @@ namespace MQTTnet.Server return this; } + public MqttServerOptionsBuilder WithoutEncryptedEndpoint() + { + _options.TlsEndpointOptions.IsEnabled = false; + return this; + } + public MqttServerOptionsBuilder WithStorage(IMqttServerStorage value) { _options.Storage = value; diff --git a/Frameworks/MQTTnet.NetStandard/Server/MqttServerTlsEndpointOptions.cs b/Frameworks/MQTTnet.NetStandard/Server/MqttServerTlsEndpointOptions.cs index 6c90a44..73be93c 100644 --- a/Frameworks/MQTTnet.NetStandard/Server/MqttServerTlsEndpointOptions.cs +++ b/Frameworks/MQTTnet.NetStandard/Server/MqttServerTlsEndpointOptions.cs @@ -1,4 +1,6 @@ -namespace MQTTnet.Server +using System.Net; + +namespace MQTTnet.Server { public sealed class MqttServerTlsEndpointOptions { @@ -7,5 +9,7 @@ public int? Port { get; set; } public byte[] Certificate { get; set; } + + public IPAddress BoundIPAddress { get; set; } = IPAddress.Any; } } From 5ddb6b77e2d16f195141e1a555db036540ead766 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Thu, 14 Dec 2017 13:24:50 +0100 Subject: [PATCH 22/22] Update documentation --- Build/MQTTnet.nuspec | 1 + 1 file changed, 1 insertion(+) diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec index c32772b..8faaf79 100644 --- a/Build/MQTTnet.nuspec +++ b/Build/MQTTnet.nuspec @@ -29,6 +29,7 @@ * [Server] Fixed a security issue which sends retained packages to a failed subscription. * [Server] Fixed the response (MaximumQoS) of a subscription (Thanks to @redbeans2017). * [Server] The keep alive timeouts are now checked for every client (Thanks to @RainerMueller82). +* [Server] The used IP addresses can be specified now (IPAddress.Any as default). Copyright Christian Kratky 2016-2017 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