Exemple #1
0
        public async Task <TorSocks5Client> EstablishTcpConnectionAsync(string host, int port, bool isolateStream = true, CancellationToken cancel = default)
        {
            host = Guard.NotNullOrEmptyOrWhitespace(nameof(host), host, true);
            Guard.MinimumAndNotNull(nameof(port), port, 0);

            var client = new TorSocks5Client(TorSocks5EndPoint);

            try
            {
                await client.ConnectAsync().ConfigureAwait(false);

                cancel.ThrowIfCancellationRequested();
                await client.HandshakeAsync(isolateStream).ConfigureAwait(false);

                cancel.ThrowIfCancellationRequested();
                await client.ConnectToDestinationAsync(host, port).ConfigureAwait(false);

                cancel.ThrowIfCancellationRequested();
                return(client);
            }
            catch (OperationCanceledException)
            {
                client?.Dispose();
                throw;
            }
        }
Exemple #2
0
        /// <param name="identity">Isolates streams by identity.</param>
        public async Task <TorSocks5Client> EstablishTcpConnectionAsync(IPEndPoint destination, string identity, CancellationToken cancel = default)
        {
            identity = Guard.NotNullOrEmptyOrWhitespace(nameof(identity), identity, trim: true);
            Guard.NotNull(nameof(destination), destination);

            var client = new TorSocks5Client(TorSocks5EndPoint);

            try
            {
                await client.ConnectAsync().ConfigureAwait(false);

                cancel.ThrowIfCancellationRequested();
                await client.HandshakeAsync(identity).ConfigureAwait(false);

                cancel.ThrowIfCancellationRequested();
                await client.ConnectToDestinationAsync(destination).ConfigureAwait(false);

                cancel.ThrowIfCancellationRequested();
                return(client);
            }
            catch (OperationCanceledException)
            {
                client?.Dispose();
                throw;
            }
        }
Exemple #3
0
        public async Task <TorSocks5Client> EstablishTcpConnectionAsync(IPEndPoint destination, bool isolateStream = true, CancellationToken cancel = default)
        {
            Guard.NotNull(nameof(destination), destination);

            var client = new TorSocks5Client(TorSocks5EndPoint);

            try
            {
                await client.ConnectAsync().ConfigureAwait(false);

                cancel.ThrowIfCancellationRequested();
                await client.HandshakeAsync(isolateStream).ConfigureAwait(false);

                cancel.ThrowIfCancellationRequested();
                await client.ConnectToDestinationAsync(destination).ConfigureAwait(false);

                cancel.ThrowIfCancellationRequested();
                return(client);
            }
            catch (OperationCanceledException)
            {
                client?.Dispose();
                throw;
            }
        }
Exemple #4
0
        public async Task <TorSocks5Client> EstablishTcpConnectionAsync(IPEndPoint destination, bool isolateStream = true)
        {
            Guard.NotNull(nameof(destination), destination);

            var client = new TorSocks5Client(TorSocks5EndPoint);
            await client.ConnectAsync();

            await client.HandshakeAsync(isolateStream);

            await client.ConnectToDestinationAsync(destination);

            return(client);
        }
Exemple #5
0
        public async Task <TorSocks5Client> EstablishTcpConnectionAsync(string host, int port, bool isolateStream = true)
        {
            host = Guard.NotNullOrEmptyOrWhitespace(nameof(host), host, true);
            Guard.MinimumAndNotNull(nameof(port), port, 0);

            var client = new TorSocks5Client(TorSocks5EndPoint);
            await client.ConnectAsync();

            await client.HandshakeAsync(isolateStream);

            await client.ConnectToDestinationAsync(host, port);

            return(client);
        }
Exemple #6
0
        /// <param name="identity">Isolates streams by identity.</param>
        public async Task <TorSocks5Client> EstablishTcpConnectionAsync(IPEndPoint destination, string identity)
        {
            identity = Guard.NotNullOrEmptyOrWhitespace(nameof(identity), identity, trim: true);
            Guard.NotNull(nameof(destination), destination);

            var client = new TorSocks5Client(TorSocks5EndPoint);
            await client.ConnectAsync();

            await client.HandshakeAsync(identity);

            await client.ConnectToDestinationAsync(destination);

            return(client);
        }