private void OnConnect(IAsyncResult ar, HandShakeComplete ProtocolComplete, string host, int port) { try { Server.EndConnect(ar); } catch (Exception e) { ProtocolComplete(e); return; } try { byte[] command = ConnectCommand(host, port); Server.BeginSend(command, 0, command.Length, SocketFlags.None, delegate(IAsyncResult ar2) { this.OnSent(ar2, ProtocolComplete); }, Server); } catch (Exception e) { ProtocolComplete(e); } }
private void OnSent(IAsyncResult ar, HandShakeComplete ProtocolComplete) { try { Server.EndSend(ar); } catch (Exception e) { ProtocolComplete(e); return; } try { byte[] buffer = new byte[4096]; // 4K ought to be enough for anyone int received = 0; Server.BeginReceive(buffer, received, buffer.Length - received, SocketFlags.None, delegate(IAsyncResult ar2) { this.OnReceive(ar2, ProtocolComplete, buffer, received); }, Server); } catch (Exception e) { ProtocolComplete(e); } }
/// <summary> /// Starts negotiating asynchronously with a SOCKS proxy server. /// </summary> /// <param name="remoteEP">An IPEndPoint that represents the remote device.</param> /// <param name="callback">The method to call when the connection has been established.</param> /// <param name="proxyEndPoint">The IPEndPoint of the SOCKS proxy server.</param> /// <returns>An IAsyncProxyResult that references the asynchronous connection.</returns> public override IAsyncProxyResult BeginNegotiate(IPEndPoint remoteEP, HandShakeComplete callback, IPEndPoint proxyEndPoint) { ProtocolComplete = callback; Buffer = GetEndPointBytes(remoteEP); Server.BeginConnect(proxyEndPoint, new AsyncCallback(this.OnConnect), Server); AsyncResult = new IAsyncProxyResult(); return(AsyncResult); }
/// <summary> /// Starts negotiating asynchronously with a SOCKS proxy server. /// </summary> /// <param name="host">The remote server to connect to.</param> /// <param name="port">The remote port to connect to.</param> /// <param name="callback">The method to call when the connection has been established.</param> /// <param name="proxyEndPoint">The IPEndPoint of the SOCKS proxy server.</param> /// <returns>An IAsyncProxyResult that references the asynchronous connection.</returns> public override AsyncSocksResult BeginNegotiate(string host, int port, HandShakeComplete callback, IPEndPoint proxyEndPoint) { handShakeComplete = callback; Buffer = GetHostPortBytes(host, port); Server.BeginConnect(proxyEndPoint, OnConnect, Server); AsyncResult = new AsyncSocksResult(); return(AsyncResult); }
/// <summary> /// Starts negotiating asynchronously with a SOCKS proxy server. /// </summary> /// <param name="remoteEndPoint">An IPEndPoint that represents the remote device.</param> /// <param name="callback">The method to call when the connection has been established.</param> /// <param name="proxyEndPoint">The IPEndPoint of the SOCKS proxy server.</param> /// <returns>An IAsyncProxyResult that references the asynchronous connection.</returns> public override AsyncSocksResult BeginNegotiate(IPEndPoint remoteEndPoint, HandShakeComplete callback, IPEndPoint proxyEndPoint) { handShakeComplete = callback; Buffer = GetEndPointBytes(remoteEndPoint); Server.BeginConnect(proxyEndPoint, OnConnect, Server); AsyncResult = new AsyncSocksResult(); return(AsyncResult); }
public override IAsyncProxyResult BeginNegotiate(IPEndPoint remoteEP, HandShakeComplete callback, IPEndPoint proxyEndPoint) { ProtocolComplete = callback; base.Buffer = method_1(remoteEP); base.Server.BeginConnect(proxyEndPoint, method_3, base.Server); base.AsyncResult = new IAsyncProxyResult(null); return(base.AsyncResult); }
public override IAsyncProxyResult BeginNegotiate(string host, int port, HandShakeComplete callback, IPEndPoint proxyEndPoint) { ProtocolComplete = callback; BdyqsvugsT(method_1(host, port)); base.Server.BeginConnect(proxyEndPoint, method_4, base.Server); base.AsyncResult = new IAsyncProxyResult(null); return(base.AsyncResult); }
/// <summary> /// Starts negotiating asynchronously with a SOCKS proxy server. /// </summary> /// <param name="host">The remote server to connect to.</param> /// <param name="port">The remote port to connect to.</param> /// <param name="callback">The method to call when the connection has been established.</param> /// <param name="proxyEndPoint">The IPEndPoint of the SOCKS proxy server.</param> /// <returns>An IAsyncProxyResult that references the asynchronous connection.</returns> public override IAsyncProxyResult BeginNegotiate(string host, int port, HandShakeComplete callback, IPEndPoint proxyEndPoint) { ProtocolComplete = callback; Buffer = GetHostPortBytes(host, port); Server.BeginConnect(proxyEndPoint, new AsyncCallback(this.OnConnect), Server); AsyncResult = new IAsyncProxyResult(); return(AsyncResult); }
/// <summary> /// Starts negotiating asynchronously with a SOCKS proxy server. /// </summary> /// <param name="remoteEP">An IPEndPoint that represents the remote device.</param> /// <param name="callback">The method to call when the connection has been established.</param> /// <param name="proxyEndPoint">The IPEndPoint of the SOCKS proxy server.</param> /// <returns>An IAsyncProxyResult that references the asynchronous connection.</returns> public override IAsyncProxyResult BeginNegotiate(IPEndPoint remoteEP, HandShakeComplete callback, IPEndPoint proxyEndPoint) { ProtocolComplete = callback; Buffer = GetEndPointBytes(remoteEP); Server.BeginConnect(proxyEndPoint, new AsyncCallback(this.OnConnect), Server); AsyncResult = new IAsyncProxyResult(); return AsyncResult; }
/// <summary> /// Starts negotiating asynchronously with a SOCKS proxy server. /// </summary> /// <param name="host">The remote server to connect to.</param> /// <param name="port">The remote port to connect to.</param> /// <param name="callback">The method to call when the connection has been established.</param> /// <param name="proxyEndPoint">The IPEndPoint of the SOCKS proxy server.</param> /// <returns>An IAsyncProxyResult that references the asynchronous connection.</returns> public override IAsyncProxyResult BeginNegotiate(string host, int port, HandShakeComplete callback, IPEndPoint proxyEndPoint) { ProtocolComplete = callback; Buffer = GetHostPortBytes(host, port); Server.BeginConnect(proxyEndPoint, new AsyncCallback(this.OnConnect), Server); AsyncResult = new IAsyncProxyResult(); return AsyncResult; }
/// <summary> /// Begins an asynchronous request to resolve a DNS host name or IP address in dotted-quad notation to an IPAddress instance. /// </summary> /// <param name="host">The host to resolve.</param> /// <param name="callback">The method to call when the hostname has been resolved.</param> /// <returns>An IAsyncResult instance that references the asynchronous request.</returns> /// <exception cref="SocketException">There was an error while trying to resolve the host.</exception> internal IAsyncProxyResult BeginDns(string host, HandShakeComplete callback) { try { Dns.BeginGetHostEntry(host, new AsyncCallback(this.OnResolved), this); return(new IAsyncProxyResult()); } catch { throw new SocketException(); } }
/// <summary> /// Starts the asynchronous authentication process. /// </summary> /// <param name="callback">The method to call when the authentication is complete.</param> public override void BeginAuthenticate(HandShakeComplete callback) { int length = GetAuthenticationLength(); Buffer = ArrayPool <byte> .Shared.Rent(length); GetAuthenticationBytes(Buffer); CallBack = callback; Server.BeginSend(Buffer, 0, length, SocketFlags.None, this.OnSent, Server); }
/// <summary> /// Starts negotiating asynchronously with the SOCKS server. /// </summary> /// <param name="remoteEP">An IPEndPoint that represents the remote device.</param> /// <param name="callback">The method to call when the negotiation is complete.</param> /// <param name="proxyEndPoint">The IPEndPoint of the SOCKS proxy server.</param> /// <returns>An IAsyncProxyResult that references the asynchronous connection.</returns> public override AsyncProxyResult BeginNegotiate(IPEndPoint remoteEP, HandShakeComplete callback, IPEndPoint proxyEndPoint, object state) { ProtocolComplete = callback; HandShake = GetEndPointBytes(remoteEP); Server.BeginConnect(proxyEndPoint, OnConnect, Server); AsyncResult = new AsyncProxyResult(); AsyncResult.Init(state); return(AsyncResult); }
/// <summary> /// Starts negotiating asynchronously with the SOCKS server. /// </summary> /// <param name="host">The host to connect to.</param> /// <param name="port">The port to connect to.</param> /// <param name="callback">The method to call when the negotiation is complete.</param> /// <param name="proxyEndPoint">The IPEndPoint of the SOCKS proxy server.</param> /// <param name="state"></param> /// <returns>An IAsyncProxyResult that references the asynchronous connection.</returns> public override AsyncProxyResult BeginNegotiate(string host, int port, HandShakeComplete callback, IPEndPoint proxyEndPoint, object state) { ProtocolComplete = callback; HandShake = GetHostPortBytes(host, port); Server.BeginConnect(proxyEndPoint, OnConnect, Server); AsyncResult = new AsyncProxyResult(); AsyncResult.Init(state); return(AsyncResult); }
/// <summary> /// Starts the asynchronous authentication process. /// </summary> /// <param name="callback">The method to call when the authentication is complete.</param> public override void BeginAuthenticate(HandShakeComplete callback) { CallBack = callback; Server.BeginSend(GetAuthenticationBytes(), 0, 3 + Username.Length + Password.Length, SocketFlags.None, OnSent, Server); return; }
public override IAsyncProxyResult BeginNegotiate(string host, int port, HandShakeComplete callback, IPEndPoint proxyEndPoint) { // ProtocolComplete = callback; // Buffer = GetHostPortBytes(host, port); Server.BeginConnect(proxyEndPoint, delegate(IAsyncResult ar) { this.OnConnect(ar, callback, host, port); }, Server); IAsyncProxyResult AsyncResult = new IAsyncProxyResult(); return AsyncResult; }
/// <summary> /// Starts negotiating asynchronously with a SOCKS proxy server. /// </summary> /// <param name="host">The remote server to connect to.</param> /// <param name="port">The remote port to connect to.</param> /// <param name="callback">The method to call when the connection has been established.</param> /// <param name="proxyEndPoint">The IPEndPoint of the SOCKS proxy server.</param> /// <param name="state">The state.</param> /// <returns>An IAsyncProxyResult that references the asynchronous connection.</returns> public override IAsyncProxyResult BeginNegotiate(string host, int port, HandShakeComplete callback, IPEndPoint proxyEndPoint, object state) { ProtocolComplete = callback; Buffer = ArrayPool <byte> .Shared.Rent(10 + Username.Length + host.Length); BufferCount = GetHostPortBytes(host, port, Buffer); Server.BeginConnect(proxyEndPoint, OnConnect, Server); AsyncResult = new IAsyncProxyResult(state); return(AsyncResult); }
/// <summary> /// Starts negotiating asynchronously with a SOCKS proxy server. /// </summary> /// <param name="remoteEP">An IPEndPoint that represents the remote device.</param> /// <param name="callback">The method to call when the connection has been established.</param> /// <param name="proxyEndPoint">The IPEndPoint of the SOCKS proxy server.</param> /// <param name="state">The state.</param> /// <returns>An IAsyncProxyResult that references the asynchronous connection.</returns> public override IAsyncProxyResult BeginNegotiate(IPEndPoint remoteEP, HandShakeComplete callback, IPEndPoint proxyEndPoint, object state) { ProtocolComplete = callback; Buffer = ArrayPool <byte> .Shared.Rent(9 + Username.Length); BufferCount = GetEndPointBytes(remoteEP, Buffer); Server.BeginConnect(proxyEndPoint, OnConnect, Server); AsyncResult = new IAsyncProxyResult(state); return(AsyncResult); }
/// <summary> /// Begins an asynchronous request to resolve a DNS host name or IP address in dotted-quad notation to an IPAddress instance. /// </summary> /// <param name="host">The host to resolve.</param> /// <param name="callback">The method to call when the hostname has been resolved.</param> /// <returns>An IAsyncResult instance that references the asynchronous request.</returns> /// <exception cref="SocketException">There was an error while trying to resolve the host.</exception> internal AsyncSocksResult BeginDns(string host, HandShakeComplete callback) { try { Dns.BeginGetHostEntry(host, OnResolved, this); return(new AsyncSocksResult()); } catch { throw new SocketException(); } }
public override IAsyncProxyResult BeginNegotiate(string host, int port, HandShakeComplete callback, IPEndPoint proxyEndPoint) { // ProtocolComplete = callback; // Buffer = GetHostPortBytes(host, port); Server.BeginConnect(proxyEndPoint, delegate(IAsyncResult ar) { this.OnConnect(ar, callback, host, port); }, Server); IAsyncProxyResult AsyncResult = new IAsyncProxyResult(); return(AsyncResult); }
internal IAsyncProxyResult BeginDns(string host, HandShakeComplete callback) { try { Dns.BeginGetHostEntry(host, method_0, this); return(new IAsyncProxyResult(null)); } catch { throw new SocketException(); } }
/// <summary> /// Starts negotiating asynchronously with the SOCKS server. /// </summary> /// <param name="remoteEP">An IPEndPoint that represents the remote device.</param> /// <param name="callback">The method to call when the negotiation is complete.</param> /// <param name="proxyEndPoint">The IPEndPoint of the SOCKS proxy server.</param> /// <param name="state">The state.</param> /// <returns>An IAsyncProxyResult that references the asynchronous connection.</returns> public override IAsyncProxyResult BeginNegotiate(IPEndPoint remoteEP, HandShakeComplete callback, IPEndPoint proxyEndPoint, object state) { ProtocolComplete = callback; Buffer = ArrayPool <byte> .Shared.Rent(Math.Max(258, 13 + Username.Length + Password.Length)); // first {ConnectOffset} bytes are reserved for authentication _handShakeLength = GetEndPointBytes(remoteEP, Buffer.AsMemory(ConnectOffset)); Server.BeginConnect(proxyEndPoint, this.OnConnect, Server); AsyncResult = new IAsyncProxyResult(state); return(AsyncResult); }
internal IAsyncProxyResult BeginDns(string host, HandShakeComplete callback) { try { #pragma warning disable 0618 Dns.BeginResolve(host, new AsyncCallback(OnResolved), this); return(new IAsyncProxyResult()); } catch { throw new SocketException(); } }
private void OnReceive(IAsyncResult ar, HandShakeComplete ProtocolComplete, byte[] buffer, int received) { try { int newlyReceived = Server.EndReceive(ar); if (newlyReceived <= 0) { ProtocolComplete(new SocketException()); return; } received += newlyReceived; if (ResponseReady(buffer, received)) { // end of the header ParseResponse(buffer, received); // if no exception was thrown, then.. ProtocolComplete(null); } else if (received == buffer.Length) { throw new ProxyException("Unexpected HTTP proxy response"); } else { Server.BeginReceive(buffer, received, buffer.Length - received, SocketFlags.None, delegate(IAsyncResult ar2) { this.OnReceive(ar2, ProtocolComplete, buffer, received); }, Server); } } catch (Exception e) { ProtocolComplete(e); } }
public abstract void BeginAuthenticate(HandShakeComplete callback);
/// <summary> /// Starts negotiating asynchronously with a SOCKS proxy server. /// </summary> /// <param name="host">The remote server to connect to.</param> /// <param name="port">The remote port to connect to.</param> /// <param name="callback">The method to call when the connection has been established.</param> /// <param name="proxyEndPoint">The IPEndPoint of the SOCKS proxy server.</param> /// <returns>An IAsyncProxyResult that references the asynchronous connection.</returns> public abstract IAsyncProxyResult BeginNegotiate(string host, int port, HandShakeComplete callback, IPEndPoint proxyEndPoint);
/// <summary> /// Starts negotiating asynchronously with a SOCKS proxy server. /// </summary> /// <param name="remoteEP">An IPEndPoint that represents the remote device. </param> /// <param name="callback">The method to call when the connection has been established.</param> /// <param name="proxyEndPoint">The IPEndPoint of the SOCKS proxy server.</param> /// <returns>An IAsyncProxyResult that references the asynchronous connection.</returns> public abstract IAsyncProxyResult BeginNegotiate(IPEndPoint remoteEP, HandShakeComplete callback, IPEndPoint proxyEndPoint);
/// <summary> /// Begins an asynchronous request to resolve a DNS host name or IP address in dotted-quad notation to an IPAddress instance. /// </summary> /// <param name="host">The host to resolve.</param> /// <param name="callback">The method to call when the hostname has been resolved.</param> /// <returns>An IAsyncResult instance that references the asynchronous request.</returns> /// <exception cref="SocketException">There was an error while trying to resolve the host.</exception> internal IAsyncProxyResult BeginDns(string host, HandShakeComplete callback) { try { Dns.BeginResolve(host, new AsyncCallback(this.OnResolved), this); return new IAsyncProxyResult(); } catch { throw new SocketException(); } }
/// <summary> /// Starts the asynchronous authentication process. /// </summary> /// <param name="callback">The method to call when the authentication is complete.</param> public void BeginAuthenticate(HandShakeComplete callback) { _callBack = callback; Endpoint.BeginSend(GetAuthenticationBytes(), 0, 3 + Username.Length + Password.Length, SocketFlags.None, OnSent, Endpoint); }
/// <summary> /// Starts the asynchronous authentication process. /// </summary> /// <param name="callback">The method to call when the authentication is complete.</param> public override void BeginAuthenticate(HandShakeComplete callback) { CallBack = callback; Server.BeginSend(GetAuthenticationBytes(), 0, GetAuthenticationLength(), SocketFlags.None, new AsyncCallback(this.OnSent), Server); return; }
/// <summary> /// Authenticates the user asynchronously. /// </summary> /// <param name="callback">The method to call when the authentication is complete.</param> /// <remarks>This method immediately calls the callback method.</remarks> public override void BeginAuthenticate(HandShakeComplete callback) { callback(null); }
public override IAsyncProxyResult BeginNegotiate(IPEndPoint remoteEP, HandShakeComplete callback, IPEndPoint proxyEndPoint) { return(BeginNegotiate(remoteEP.Address.ToString(), remoteEP.Port, callback, proxyEndPoint)); }
/// <summary> /// Starts negotiating asynchronously with the SOCKS server. /// </summary> /// <param name="remoteEP">An IPEndPoint that represents the remote device.</param> /// <param name="callback">The method to call when the negotiation is complete.</param> /// <param name="proxyEndPoint">The IPEndPoint of the SOCKS proxy server.</param> /// <returns>An IAsyncProxyResult that references the asynchronous connection.</returns> public override IAsyncProxyResult BeginNegotiate(IPEndPoint remoteEP, HandShakeComplete callback, IPEndPoint proxyEndPoint) { throw new NotSupportedException(); }
/// <summary> /// Starts the asynchronous authentication process. /// </summary> /// <param name="callback">The method to call when the authentication is complete.</param> public override void BeginAuthenticate(HandShakeComplete callback) { this.CallBack = callback; this.Server.BeginSend(this.GetAuthenticationBytes(), 0, 3 + this.Username.Length + this.Password.Length, SocketFlags.None, new AsyncCallback(this.OnSent), this.Server); }
/// <summary> /// Starts the asynchronous authentication process. /// </summary> /// <param name="callback">The method to call when the authentication is complete.</param> public override void BeginAuthenticate(HandShakeComplete callback) { CallBack = callback; Server.BeginSend(GetAuthenticationBytes(), 0, 3 + Username.Length + Password.Length, SocketFlags.None, new AsyncCallback(this.OnSent), Server); return; }
public override void BeginAuthenticate(HandShakeComplete callback) { CallBack = callback; base.Server.BeginSend(method_0(), 0, method_1(), SocketFlags.None, method_2, base.Server); }
/// <summary> /// Authenticates the user asynchronously. /// </summary> /// <param name="callback">The method to call when the authentication is complete.</param> /// <exception cref="ProxyException">Authentication with the proxy server failed.</exception> /// <exception cref="ProtocolViolationException">The proxy server uses an invalid protocol.</exception> /// <exception cref="SocketException">An operating system error occurs while accessing the Socket.</exception> /// <exception cref="ObjectDisposedException">The Socket has been closed.</exception> public abstract void BeginAuthenticate(HandShakeComplete callback);
public override IAsyncProxyResult BeginNegotiate(IPEndPoint remoteEP, HandShakeComplete callback, IPEndPoint proxyEndPoint) { return BeginNegotiate(remoteEP.Address.ToString(), remoteEP.Port, callback, proxyEndPoint); }