Files
MQTTnet/Source/MQTTnet/Exceptions/MqttProxyException.cs
T
Alexander KöpkeandCopilot 68da92fd4b Add support for pluggable stream provider to enable SOCKS5 proxies (#2251)
* Add SOCKS5 proxy support via pluggable stream provider

Introduces MQTTnet.Extensions.Socks5, enabling SOCKS5 proxy support for MQTTnet TCP transport. Adds IMqttClientStreamProvider interface, Socks5StreamProvider implementation, and related configuration options. Updates MqttTcpChannel to support stream providers and TLS layering. Includes unit tests with a fake SOCKS5 server and usage samples. Solution and project references updated accordingly.

* Add SOCKS5 options validation for invalid configurations

* Tighten SOCKS5 RFC compliance checks

---------

Co-authored-by: Copilot <Copilot@users.noreply.github.com>
2026-06-18 17:51:52 +02:00

40 lines
1.6 KiB
C#

// 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.
namespace MQTTnet.Exceptions;
/// <summary>
/// Thrown when an <see cref="MQTTnet.Channel.IMqttClientStreamProvider"/> fails while
/// establishing the stream to the broker (proxy unreachable, authentication failure,
/// destination unreachable, protocol violation, ...).
/// Inherits from <see cref="MqttCommunicationException"/> so existing connect/reconnect
/// handling continues to work; callers that care about the specific reason can branch on
/// <see cref="ErrorCode"/>.
/// </summary>
public sealed class MqttProxyException : MqttCommunicationException
{
public MqttProxyException(MqttProxyErrorCode errorCode, string message, string proxyAddress = null, Exception innerException = null)
: base(BuildMessage(errorCode, message, proxyAddress), innerException)
{
ErrorCode = errorCode;
ProxyAddress = proxyAddress;
}
/// <summary>Gets the categorized error reason.</summary>
public MqttProxyErrorCode ErrorCode { get; }
/// <summary>Gets the proxy address (host:port) associated with the failure, if known.</summary>
public string ProxyAddress { get; }
static string BuildMessage(MqttProxyErrorCode errorCode, string message, string proxyAddress)
{
if (string.IsNullOrEmpty(proxyAddress))
{
return $"Proxy error '{errorCode}': {message}";
}
return $"Proxy '{proxyAddress}' error '{errorCode}': {message}";
}
}