Added EndPoint RemoteEndPoint {get;} property to channel (#2111)

* Added EndPoint RemoteEndPoint{get;} property

* Reformat code

* Reformat code

---------

Co-authored-by: christian <6939810+chkr1011@users.noreply.github.com>
This commit is contained in:
老九
2024-12-02 11:52:24 +01:00
committed by GitHub
co-authored by christian
parent ef5b6c9b32
commit 8089c6bdbc
20 changed files with 91 additions and 55 deletions
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks;
@@ -18,7 +19,8 @@ public interface IMqttChannelAdapter : IDisposable
long BytesSent { get; }
X509Certificate2 ClientCertificate { get; }
string Endpoint { get; }
EndPoint RemoteEndPoint { get; }
bool IsSecureConnection { get; }
+2 -1
View File
@@ -5,6 +5,7 @@
using System;
using System.Buffers;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
@@ -51,7 +52,7 @@ public sealed class MqttChannelAdapter : Disposable, IMqttChannelAdapter
public X509Certificate2 ClientCertificate => _channel.ClientCertificate;
public string Endpoint => _channel.Endpoint;
public EndPoint RemoteEndPoint => _channel.RemoteEndPoint;
public bool IsSecureConnection => _channel.IsSecureConnection;
+2 -1
View File
@@ -4,6 +4,7 @@
using System;
using System.Buffers;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks;
@@ -13,7 +14,7 @@ namespace MQTTnet.Channel;
public interface IMqttChannel : IDisposable
{
X509Certificate2 ClientCertificate { get; }
string Endpoint { get; }
EndPoint RemoteEndPoint { get; }
bool IsSecureConnection { get; }
@@ -37,11 +37,11 @@ namespace MQTTnet.Implementations
IsSecureConnection = clientOptions.ChannelOptions?.TlsOptions?.UseTls == true;
}
public MqttTcpChannel(Stream stream, string endpoint, X509Certificate2 clientCertificate) : this()
public MqttTcpChannel(Stream stream, EndPoint remoteEndPoint, X509Certificate2 clientCertificate) : this()
{
_stream = stream ?? throw new ArgumentNullException(nameof(stream));
Endpoint = endpoint;
RemoteEndPoint = remoteEndPoint;
IsSecureConnection = stream is SslStream;
ClientCertificate = clientCertificate;
@@ -49,7 +49,7 @@ namespace MQTTnet.Implementations
public X509Certificate2 ClientCertificate { get; }
public string Endpoint { get; private set; }
public EndPoint RemoteEndPoint { get; private set; }
public bool IsSecureConnection { get; }
@@ -175,7 +175,7 @@ namespace MQTTnet.Implementations
_stream = networkStream;
}
Endpoint = socket.RemoteEndPoint?.ToString();
RemoteEndPoint = socket.RemoteEndPoint;
}
catch (Exception)
{
@@ -26,18 +26,18 @@ namespace MQTTnet.Implementations
_options = options ?? throw new ArgumentNullException(nameof(options));
}
public MqttWebSocketChannel(WebSocket webSocket, string endpoint, bool isSecureConnection, X509Certificate2 clientCertificate)
public MqttWebSocketChannel(WebSocket webSocket, EndPoint remoteEndPoint, bool isSecureConnection, X509Certificate2 clientCertificate)
{
_webSocket = webSocket ?? throw new ArgumentNullException(nameof(webSocket));
Endpoint = endpoint;
RemoteEndPoint = remoteEndPoint;
IsSecureConnection = isSecureConnection;
ClientCertificate = clientCertificate;
}
public X509Certificate2 ClientCertificate { get; }
public string Endpoint { get; }
public EndPoint RemoteEndPoint { get; }
public bool IsSecureConnection { get; private set; }