예제 #1
0
        // Constructor for outbound connections
        internal MockConnection(EndPoint?remoteEndPoint, SslClientAuthenticationOptions?sslClientAuthenticationOptions, IPEndPoint?localEndPoint = null, int maxUnidirectionalStreams = 100, int maxBidirectionalStreams = 100)
        {
            if (remoteEndPoint is null)
            {
                throw new ArgumentNullException(nameof(remoteEndPoint));
            }

            IPEndPoint ipEndPoint = GetIPEndPoint(remoteEndPoint);

            if (ipEndPoint.Address != IPAddress.Loopback)
            {
                throw new ArgumentException("Expected loopback address", nameof(remoteEndPoint));
            }

            _isClient       = true;
            _remoteEndPoint = ipEndPoint;
            _localEndPoint  = new IPEndPoint(IPAddress.Loopback, 0);
            _sslClientAuthenticationOptions   = sslClientAuthenticationOptions;
            _nextOutboundBidirectionalStream  = 0;
            _nextOutboundUnidirectionalStream = 2;
            _maxUnidirectionalStreams         = maxUnidirectionalStreams;
            _maxBidirectionalStreams          = maxBidirectionalStreams;

            // _state is not initialized until ConnectAsync
        }
예제 #2
0
        internal MockConnection(EndPoint?remoteEndPoint, SslClientAuthenticationOptions?sslClientAuthenticationOptions, IPEndPoint?localEndPoint = null)
        {
            _remoteEndPoint = remoteEndPoint;
            _localEndPoint  = localEndPoint;

            _isClient = true;
            _nextOutboundBidirectionalStream  = 0;
            _nextOutboundUnidirectionalStream = 2;
        }
        internal override Task <HttpConnection> CreateTestClientAsync(ConnectionFactory connectionFactory, EndPoint endPoint)
        {
            IConnectionProperties?properties = CreateConnectProperties();

            SslClientAuthenticationOptions?sslOptions = null;

            properties?.TryGetProperty(SslConnectionFactory.SslClientAuthenticationOptionsPropertyKey, out sslOptions);

            return(Task.FromResult <HttpConnection>(new PooledHttpConnection(connectionFactory, endPoint, sslOptions)));
        }
예제 #4
0
 public DnsEndPointWithProperties(string host, int port, SslClientAuthenticationOptions?sslOptions)
     : base(host, port)
 {
     SslOptions = sslOptions;
 }
예제 #5
0
        public static async ValueTask <QuicConnection> ConnectQuicAsync(string host, int port, SslClientAuthenticationOptions?clientAuthenticationOptions, CancellationToken cancellationToken)
        {
            IPAddress[] addresses = await Dns.GetHostAddressesAsync(host).ConfigureAwait(false);

            Exception?lastException = null;

            foreach (IPAddress address in addresses)
            {
                QuicConnection con = new QuicConnection(new IPEndPoint(address, port), clientAuthenticationOptions);
                try
                {
                    await con.ConnectAsync(cancellationToken).ConfigureAwait(false);

                    return(con);
                }
                // TODO: it would be great to catch a specific exception here... QUIC implementation dependent.
                catch (Exception ex) when(!(ex is OperationCanceledException))
                {
                    con.Dispose();
                    lastException = ex;
                }
            }

            if (lastException != null)
            {
                throw CreateWrappedException(lastException, cancellationToken);
            }

            // TODO: find correct exception to throw here.
            throw new HttpRequestException("No host found.");
        }
예제 #6
0
 // !!! TEMPORARY: Remove or make internal before shipping
 public QuicConnection(QuicImplementationProvider implementationProvider, EndPoint remoteEndPoint, SslClientAuthenticationOptions?sslClientAuthenticationOptions, IPEndPoint?localEndPoint = null)
     : this(implementationProvider, new QuicClientConnectionOptions() { RemoteEndPoint = remoteEndPoint, ClientAuthenticationOptions = sslClientAuthenticationOptions, LocalEndPoint = localEndPoint })
 {
 }
예제 #7
0
 /// <summary>
 /// Create an outbound QUIC connection.
 /// </summary>
 /// <param name="remoteEndPoint">The remote endpoint to connect to.</param>
 /// <param name="sslClientAuthenticationOptions">TLS options</param>
 /// <param name="localEndPoint">The local endpoint to connect from.</param>
 public QuicConnection(EndPoint remoteEndPoint, SslClientAuthenticationOptions?sslClientAuthenticationOptions, IPEndPoint?localEndPoint = null)
     : this(QuicImplementationProviders.Default, remoteEndPoint, sslClientAuthenticationOptions, localEndPoint)
 {
 }