mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-15 00:15:15 +08:00
Expose local endpoint in channel adapter (#2213)
* Expose local endpoint * Update release notes
This commit is contained in:
@@ -61,27 +61,6 @@ public sealed class MqttConnectionContext : IMqttChannelAdapter
|
||||
}
|
||||
}
|
||||
|
||||
public EndPoint RemoteEndPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
// mqtt over tcp
|
||||
if (_connection.RemoteEndPoint != null)
|
||||
{
|
||||
return _connection.RemoteEndPoint;
|
||||
}
|
||||
|
||||
// mqtt over websocket
|
||||
var httpFeature = _connection.Features.Get<IHttpConnectionFeature>();
|
||||
if (httpFeature?.RemoteIpAddress != null)
|
||||
{
|
||||
return new IPEndPoint(httpFeature.RemoteIpAddress, httpFeature.RemotePort);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSecureConnection
|
||||
{
|
||||
get
|
||||
@@ -104,8 +83,50 @@ public sealed class MqttConnectionContext : IMqttChannelAdapter
|
||||
}
|
||||
}
|
||||
|
||||
public EndPoint LocalEndPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
// mqtt over tcp
|
||||
if (_connection.LocalEndPoint != null)
|
||||
{
|
||||
return _connection.LocalEndPoint;
|
||||
}
|
||||
|
||||
// mqtt over websocket
|
||||
var httpFeature = _connection.Features.Get<IHttpConnectionFeature>();
|
||||
if (httpFeature?.LocalIpAddress != null)
|
||||
{
|
||||
return new IPEndPoint(httpFeature.LocalIpAddress, httpFeature.LocalPort);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public MqttPacketFormatterAdapter PacketFormatterAdapter { get; }
|
||||
|
||||
public EndPoint RemoteEndPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
// mqtt over tcp
|
||||
if (_connection.RemoteEndPoint != null)
|
||||
{
|
||||
return _connection.RemoteEndPoint;
|
||||
}
|
||||
|
||||
// mqtt over websocket
|
||||
var httpFeature = _connection.Features.Get<IHttpConnectionFeature>();
|
||||
if (httpFeature?.RemoteIpAddress != null)
|
||||
{
|
||||
return new IPEndPoint(httpFeature.RemoteIpAddress, httpFeature.RemotePort);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task ConnectAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
if (_connection is SocketConnection tcp && !tcp.IsConnected)
|
||||
@@ -232,8 +253,8 @@ public sealed class MqttConnectionContext : IMqttChannelAdapter
|
||||
var span = output.GetSpan(buffer.Length);
|
||||
|
||||
buffer.Packet.AsSpan().CopyTo(span);
|
||||
int offset = buffer.Packet.Count;
|
||||
buffer.Payload.CopyTo(destination: span.Slice(offset));
|
||||
var offset = buffer.Packet.Count;
|
||||
buffer.Payload.CopyTo(span.Slice(offset));
|
||||
output.Advance(buffer.Length);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user