Interface IProxyClient
- Namespace
- VpnHood.Net.Proxies
- Assembly
- VpnHood.Net.Proxies.dll
Opens TCP connections to destinations through a proxy server.
public interface IProxyClient
Remarks
One instance can serve many connections at once; run one operation at a time on each connection. When the exchange with the proxy fails, the method closes the TcpClient it was given. When an argument is rejected, the connection may be left open: the caller still owns it and disposes it.
Properties
ProxyEndPoint
Gets the address and port of the proxy server.
IPEndPoint ProxyEndPoint { get; }
Property Value
Methods
CheckConnectionAsync(TcpClient, CancellationToken)
Connects to the proxy to see whether it works, without asking for a tunnel.
Task CheckConnectionAsync(TcpClient tcpClient, CancellationToken cancellationToken)
Parameters
tcpClientTcpClientA connection that is not connected yet. When the check fails, it is closed.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that represents the asynchronous operation. It completes when the check passes.
Remarks
How much is checked depends on the protocol: a SOCKS5 client also negotiates the authentication, an HTTPS client completes the TLS handshake, and a SOCKS4 or plain HTTP client only opens the TCP connection. A SOCKS or plain HTTP client can then open a tunnel on the checked connection; an HTTPS client keeps no TLS session from the check, so its tunnel needs a new connection.
Exceptions
- ArgumentNullException
tcpClientis null.- ArgumentException
For SOCKS5, a credential in the options exceeds 255 bytes in UTF-8.
- AuthenticationException
The TLS handshake with an HTTPS proxy failed.
- UnauthorizedAccessException
A SOCKS5 proxy requires credentials the options lack, refused them, or accepts none of the offered methods.
- ProtocolViolationException
A SOCKS5 proxy's answer is not SOCKS5.
- NotSupportedException
A SOCKS5 proxy chose an authentication method the client lacks.
- EndOfStreamException
A SOCKS5 proxy closed the connection before its answer was complete.
- SocketException
The connection to the proxy failed.
- OperationCanceledException
cancellationTokenwas canceled.
ConnectAsync(TcpClient, IPEndPoint, CancellationToken)
Opens a tunnel through the proxy to an IP endpoint.
Task ConnectAsync(TcpClient tcpClient, IPEndPoint destination, CancellationToken cancellationToken)
Parameters
tcpClientTcpClientThe connection to use. When it is not connected, it is connected to ProxyEndPoint first. When the task completes, it carries the tunnel; when the exchange with the proxy fails, it is closed.
destinationIPEndPointThe destination's address and port.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that represents the asynchronous operation. It completes when the tunnel is open.
Exceptions
- ArgumentNullException
tcpClientordestinationis null.- ArgumentException
For SOCKS5, a credential in the options exceeds 255 bytes in UTF-8.
- ArgumentOutOfRangeException
For HTTP and SOCKS4, the destination's port is zero.
- ProxyClientException
The proxy refused the request or answered in a way the client cannot use, or, for SOCKS4, the destination is an IPv6 address; SocketErrorCode tells why.
- AuthenticationException
The TLS handshake with an HTTPS proxy failed.
- UnauthorizedAccessException
A SOCKS5 proxy requires credentials the options lack, refused them, or accepts none of the offered methods.
- ProtocolViolationException
A SOCKS5 proxy's answer is not SOCKS5.
- NotSupportedException
A SOCKS5 proxy chose an authentication method the client lacks, or answered with an unknown address type.
- TimeoutException
An HTTP proxy did not answer within 30 seconds.
- IOException
An HTTP proxy closed the connection before its answer was complete.
- EndOfStreamException
A SOCKS proxy closed the connection before its answer was complete.
- SocketException
The connection to the proxy failed.
- OperationCanceledException
cancellationTokenwas canceled.
ConnectAsync(TcpClient, string, int, CancellationToken)
Opens a tunnel through the proxy to a host, given by name or IP address.
Task ConnectAsync(TcpClient tcpClient, string host, int port, CancellationToken cancellationToken)
Parameters
tcpClientTcpClientThe connection to use. When it is not connected, it is connected to ProxyEndPoint first. When the task completes, it carries the tunnel; when the exchange with the proxy fails, it is closed.
hoststringThe destination's host name or IP address literal.
portintThe destination's port, from 1 to 65535.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that represents the asynchronous operation. It completes when the tunnel is open.
Exceptions
- ArgumentNullException
tcpClientorhostis null.- ArgumentException
hostis empty or white space; for SOCKS5, it or a credential in the options exceeds 255 bytes in UTF-8.- ArgumentOutOfRangeException
portis less than 1 or greater than 65535.- ProxyClientException
The proxy refused the request or answered in a way the client cannot use, or, for SOCKS4, the destination is an IPv6 address; SocketErrorCode tells why.
- AuthenticationException
The TLS handshake with an HTTPS proxy failed.
- UnauthorizedAccessException
A SOCKS5 proxy requires credentials the options lack, refused them, or accepts none of the offered methods.
- ProtocolViolationException
A SOCKS5 proxy's answer is not SOCKS5.
- NotSupportedException
A SOCKS5 proxy chose an authentication method the client lacks, or answered with an unknown address type.
- TimeoutException
An HTTP proxy did not answer within 30 seconds.
- IOException
An HTTP proxy closed the connection before its answer was complete.
- EndOfStreamException
A SOCKS proxy closed the connection before its answer was complete.
- SocketException
The connection to the proxy failed.
- OperationCanceledException
cancellationTokenwas canceled.