ProxyConnector
Represents a connector that uses a proxy server to establish a connection to a given SSH
endpoint.
using System;
using System.Net;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
namespace Renci.SshNet.Connection
{
internal abstract class ProxyConnector : ConnectorBase
{
protected ProxyConnector(ISocketFactory socketFactory)
: base(socketFactory)
{
}
protected abstract void HandleProxyConnect(IConnectionInfo connectionInfo, Socket socket);
[AsyncStateMachine(typeof(<HandleProxyConnectAsync>d__2))]
protected virtual Task HandleProxyConnectAsync(IConnectionInfo connectionInfo, Socket socket, CancellationToken cancellationToken)
{
<HandleProxyConnectAsync>d__2 stateMachine = default(<HandleProxyConnectAsync>d__2);
stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create();
stateMachine.<>4__this = this;
stateMachine.connectionInfo = connectionInfo;
stateMachine.socket = socket;
stateMachine.cancellationToken = cancellationToken;
stateMachine.<>1__state = -1;
stateMachine.<>t__builder.Start(ref stateMachine);
return stateMachine.<>t__builder.Task;
}
public override Socket Connect(IConnectionInfo connectionInfo)
{
Socket socket = SocketConnect(new DnsEndPoint(connectionInfo.ProxyHost, connectionInfo.ProxyPort), connectionInfo.Timeout);
try {
HandleProxyConnect(connectionInfo, socket);
return socket;
} catch (Exception) {
socket.Shutdown(SocketShutdown.Both);
socket.Dispose();
throw;
}
}
[AsyncStateMachine(typeof(<ConnectAsync>d__4))]
public override Task<Socket> ConnectAsync(IConnectionInfo connectionInfo, CancellationToken cancellationToken)
{
<ConnectAsync>d__4 stateMachine = default(<ConnectAsync>d__4);
stateMachine.<>t__builder = AsyncTaskMethodBuilder<Socket>.Create();
stateMachine.<>4__this = this;
stateMachine.connectionInfo = connectionInfo;
stateMachine.cancellationToken = cancellationToken;
stateMachine.<>1__state = -1;
stateMachine.<>t__builder.Start(ref stateMachine);
return stateMachine.<>t__builder.Task;
}
}
}