// 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.
using System.Net.Sockets;
namespace MQTTnet.Extensions.Socks5;
///
/// Options for the SOCKS5 stream provider (RFC 1928 / RFC 1929).
/// A new provider can be constructed from these options via
/// .
///
public sealed class Socks5ProxyOptions
{
///
/// The SOCKS5 proxy host name or IP literal. Must be set.
///
public string Host { get; set; }
///
/// The SOCKS5 proxy port. Defaults to 1080.
///
public int Port { get; set; } = 1080;
///
/// The user name used for the username/password authentication sub-negotiation (RFC 1929).
/// When null or empty, the client will only offer the "no authentication" method.
///
public string Username { get; set; }
///
/// The password (raw bytes per RFC 1929) used for the username/password authentication
/// sub-negotiation. Must be 1..255 bytes when is set.
///
public byte[] Password { get; set; }
///
/// When true (the default) the broker hostname is forwarded to the proxy as a
/// SOCKS5 DOMAINNAME address type, so DNS resolution happens at the proxy
/// (typical when the broker is behind the proxy in a private network).
/// When false, the hostname is resolved locally before sending the CONNECT request
/// and an IPv4 / IPv6 address type is used.
///
public bool ResolveDnsRemotely { get; set; } = true;
///
/// The maximum time allowed for the full SOCKS5 handshake (TCP connect to proxy + greeting
/// + optional auth + CONNECT). The handshake will be cancelled and a
/// will be thrown when this elapses.
/// Defaults to 30 seconds.
///
public TimeSpan HandshakeTimeout { get; set; } = TimeSpan.FromSeconds(30);
///
/// Address family preference for the socket connecting to the proxy and for local DNS
/// resolution when is false.
///
public AddressFamily AddressFamily { get; set; } = AddressFamily.Unspecified;
public override string ToString()
{
return $"{Host}:{Port}";
}
}