From c12096705f0d534900dcf1a0c5b229000e35bcbe Mon Sep 17 00:00:00 2001
From: Christian <6939810+chkr1011@users.noreply.github.com>
Date: Tue, 6 Feb 2024 17:37:07 +0100
Subject: [PATCH] 1908 support unix domain sockets (#1919)
* Add support for custom endpoints
Add overlaods etc. to allow for passing other endpoint implementations
* Extend publich broker test to also probe with different protocol versions
* Fix UWP build
* Update ReleaseNotes.md
---
.github/workflows/ReleaseNotes.md | 1 +
MQTTnet.sln.DotSettings | 1 +
.../MqttConnectionContextTest.cs | 1 -
.../MqttClientConnectionContextFactory.cs | 4 +-
.../{TcpConnection.cs => SocketConnection.cs} | 33 +++++------
.../MqttConnectionContext.cs | 4 +-
.../MQTTnet.Benchmarks/TcpPipesBenchmark.cs | 4 +-
Source/MQTTnet.TestApp/ClientTest.cs | 3 +-
Source/MQTTnet.TestApp/MQTTnet.TestApp.csproj | 1 +
Source/MQTTnet.TestApp/ManagedClientTest.cs | 3 +-
Source/MQTTnet.TestApp/PerformanceTest.cs | 17 +++---
Source/MQTTnet.TestApp/PublicBrokerTest.cs | 55 +++++++++++--------
.../Options/MqttClientOptionsBuilder.cs | 49 +++++++++++++++--
.../Client/Options/MqttClientTcpOptions.cs | 24 ++++----
.../Options/MqttClientTcpOptionsExtensions.cs | 23 --------
.../Implementations/CrossPlatformSocket.cs | 19 ++++---
.../Implementations/MqttTcpChannel.Uwp.cs | 18 +++++-
.../MQTTnet/Implementations/MqttTcpChannel.cs | 9 ++-
Source/MQTTnet/Protocol/MqttPorts.cs | 13 +++++
19 files changed, 172 insertions(+), 110 deletions(-)
rename Source/MQTTnet.AspnetCore/Client/Tcp/{TcpConnection.cs => SocketConnection.cs} (91%)
delete mode 100644 Source/MQTTnet/Client/Options/MqttClientTcpOptionsExtensions.cs
create mode 100644 Source/MQTTnet/Protocol/MqttPorts.cs
diff --git a/.github/workflows/ReleaseNotes.md b/.github/workflows/ReleaseNotes.md
index e04b0b0d..ff28cadd 100644
--- a/.github/workflows/ReleaseNotes.md
+++ b/.github/workflows/ReleaseNotes.md
@@ -1,3 +1,4 @@
+* [Client] Exposed the _EndPoint_ type to support other endpoint types (like Unix Domain Sockets) in client options (#1919).
* [Server] Added new events for delivered and dropped messages (#1866, thanks to @kallayj).
* [Server] The server will no longer treat a client which is receiving a large payload as alive. The packet must be received completely within the keep alive boundaries (BREAKING CHANGE!, #1883).
* [Server] Fixed "service not registered" exception in ASP.NET integration (#1889).
diff --git a/MQTTnet.sln.DotSettings b/MQTTnet.sln.DotSettings
index 813b5520..b12b2985 100644
--- a/MQTTnet.sln.DotSettings
+++ b/MQTTnet.sln.DotSettings
@@ -230,6 +230,7 @@
Licensed to the .NET Foundation under one or more agreements.
The .NET Foundation licenses this file to you under the MIT license.
See the LICENSE file in the project root for more information.
+ True
True
True
True
diff --git a/Source/MQTTnet.AspNetCore.Tests/MqttConnectionContextTest.cs b/Source/MQTTnet.AspNetCore.Tests/MqttConnectionContextTest.cs
index e24074d4..003e6190 100644
--- a/Source/MQTTnet.AspNetCore.Tests/MqttConnectionContextTest.cs
+++ b/Source/MQTTnet.AspNetCore.Tests/MqttConnectionContextTest.cs
@@ -48,7 +48,6 @@ namespace MQTTnet.AspNetCore.Tests
{
var mockup = new ConnectionHandlerMockup();
-
using (var host = new WebHostBuilder().UseKestrel(kestrel => kestrel.ListenLocalhost(1883, listener => listener.Use((ctx, next) => mockup.OnConnectedAsync(ctx))))
.UseStartup()
.ConfigureServices(
diff --git a/Source/MQTTnet.AspnetCore/Client/MqttClientConnectionContextFactory.cs b/Source/MQTTnet.AspnetCore/Client/MqttClientConnectionContextFactory.cs
index f8e38f4e..7afd3e21 100644
--- a/Source/MQTTnet.AspnetCore/Client/MqttClientConnectionContextFactory.cs
+++ b/Source/MQTTnet.AspnetCore/Client/MqttClientConnectionContextFactory.cs
@@ -6,7 +6,6 @@ using MQTTnet.Adapter;
using MQTTnet.AspNetCore.Client.Tcp;
using MQTTnet.Formatter;
using System;
-using System.Net;
using MQTTnet.Client;
using MQTTnet.Diagnostics;
@@ -22,8 +21,7 @@ namespace MQTTnet.AspNetCore.Client
{
case MqttClientTcpOptions tcpOptions:
{
- var endpoint = new DnsEndPoint(tcpOptions.Server, tcpOptions.GetPort());
- var tcpConnection = new TcpConnection(endpoint);
+ var tcpConnection = new SocketConnection(tcpOptions.RemoteEndpoint);
var formatter = new MqttPacketFormatterAdapter(options.ProtocolVersion, new MqttBufferWriter(4096, 65535));
return new MqttConnectionContext(formatter, tcpConnection);
diff --git a/Source/MQTTnet.AspnetCore/Client/Tcp/TcpConnection.cs b/Source/MQTTnet.AspnetCore/Client/Tcp/SocketConnection.cs
similarity index 91%
rename from Source/MQTTnet.AspnetCore/Client/Tcp/TcpConnection.cs
rename to Source/MQTTnet.AspnetCore/Client/Tcp/SocketConnection.cs
index c3a6227a..8fb19914 100644
--- a/Source/MQTTnet.AspnetCore/Client/Tcp/TcpConnection.cs
+++ b/Source/MQTTnet.AspnetCore/Client/Tcp/SocketConnection.cs
@@ -15,15 +15,15 @@ using System.Threading.Tasks;
namespace MQTTnet.AspNetCore.Client.Tcp
{
- public class TcpConnection : ConnectionContext
+ public sealed class SocketConnection : ConnectionContext
{
- private volatile bool _aborted;
- private readonly EndPoint _endPoint;
- private SocketSender _sender;
- private SocketReceiver _receiver;
+ volatile bool _aborted;
+ readonly EndPoint _endPoint;
+ SocketSender _sender;
+ SocketReceiver _receiver;
- private Socket _socket;
- private IDuplexPipe _application;
+ Socket _socket;
+ IDuplexPipe _application;
public bool IsConnected { get; private set; }
public override string ConnectionId { get; set; }
@@ -31,12 +31,12 @@ namespace MQTTnet.AspNetCore.Client.Tcp
public override IDictionary