예제 #1
0
        /// <summary>
        /// Begins an asynchronous request for a remote host connection.
        /// </summary>
        /// <param name="host">The host address to connect to.</param>
        /// <param name="port">The port number to connect to.</param>
        /// <param name="callback">The <see cref="T:System.AsyncCallback" /> delegate.</param>
        /// <param name="state">An object that contains state information for this request.</param>
        /// <returns>
        /// An <see cref="T:System.IAsyncResult" /> that references the asynchronous connection.
        /// </returns>
        public new IAsyncResult BeginConnect(string host, int port, AsyncCallback callback, object state)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            connectCallback = callback;

            if (proxyAddress == null || proxyPort == -1)
            {
                return(BeginDNSResolve(host, port, callback, state));
            }
            else
            {
                processor   = new Socks5Processor(this);
                asyncResult = processor.BeginProcessing(host, port, OnConnectionEstablished);

                return(asyncResult);
            }
        }
예제 #2
0
        /// <summary>
        /// Begins an asynchronous request for a remote host connection.
        /// </summary>
        /// <param name="remoteEP">An <see cref="T:System.Net.EndPoint" /> that represents the remote host.</param>
        /// <param name="callback">The <see cref="T:System.AsyncCallback" /> delegate.</param>
        /// <param name="state">An object that contains state information for this request.</param>
        /// <returns>
        /// An <see cref="T:System.IAsyncResult" /> that references the asynchronous connection.
        /// </returns>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        ///   <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        ///   <IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        ///   <IPermission class="System.Net.SocketPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        /// </PermissionSet>
        public new IAsyncResult BeginConnect(EndPoint remoteEP, AsyncCallback callback, object state)
        {
            if (remoteEP == null)
            {
                throw new ArgumentNullException("remoteEP");
            }
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            if (proxyAddress == null || proxyPort == -1)
            {
                return(base.BeginConnect(remoteEP, callback, state));
            }
            else
            {
                connectCallback = callback;

                processor   = new Socks5Processor(this);
                asyncResult = processor.BeginProcessing((IPEndPoint)remoteEP, OnConnectionEstablished);

                return(asyncResult);
            }
        }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ForwardSocket"/> class.
 /// </summary>
 /// <param name="client">The client hosting the proxy connection.</param>
 public ForwardSocket(Client client) : base(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
 {
     this.asyncResult     = null;
     this.client          = client;
     this.connectCallback = null;
     this.processor       = null;
     this.proxyAddress    = null;
     this.proxyPort       = -1;
 }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Socks5Processor"/> class.
 /// </summary>
 /// <param name="socket">The socket which is connected to the proxy network.</param>
 public Socks5Processor(ForwardSocket socket)
 {
     this.asyncResult = new Socks5AsyncResult();
     this.buffer      = new byte[512];
     this.endAddress  = null;
     this.endPoint    = null;
     this.endPort     = 0;
     this.finalLength = 0;
     this.socket      = socket;
 }
예제 #5
0
        /// <summary>
        /// Establishes a connection to a remote host.
        /// </summary>
        /// <param name="remoteEP">An <see cref="T:System.Net.EndPoint" /> that represents the remote device.</param>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        ///   <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        ///   <IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        ///   <IPermission class="System.Net.SocketPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        /// </PermissionSet>
        public new void Connect(EndPoint remoteEP)
        {
            if (remoteEP == null)
            {
                throw new ArgumentNullException("remoteEP");
            }

            if (proxyAddress == null || proxyPort == -1)
            {
                base.Connect(remoteEP);
            }
            else
            {
                processor   = new Socks5Processor(this);
                asyncResult = processor.BeginProcessing((IPEndPoint)remoteEP, OnConnectionEstablished);
                asyncResult.AsyncWaitHandle.WaitOne();
            }
        }
예제 #6
0
        /// <summary>
        /// Begins an asynchronous request to resolve the DNS information for a host.
        /// </summary>
        /// <param name="host">The host address to resolve.</param>
        /// <param name="port">The port number of the associated host.</param>
        /// <returns>An <see cref="T:System.IAsyncResult" /> that references the asynchronous request.</returns>
        private IAsyncResult BeginDNSResolve(string host, int port, AsyncCallback callback, object state)
        {
            DNSResolveState dnsState;

            try
            {
                dnsState          = new DNSResolveState();
                dnsState.Callback = callback;
                dnsState.Host     = host;
                dnsState.Port     = port;
                dnsState.State    = state;

                asyncResult = new Socks5AsyncResult();

                Dns.BeginGetHostEntry(host, OnDnsGetHostEntry, dnsState);

                return(asyncResult);
            }
            catch (Exception exception)
            {
                throw new TorException("The forwarding socket failed to resolve a host address", exception);
            }
        }