Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public async Task WaitForClientDisconnectAsync(bool refuseNewRequests = true)
}
}

// The client's control stream should throw QuicConnectionAbortedException, indicating that it was
// The client's control stream should throw QuicError.ConnectionAborted, indicating that it was
// aborted because the connection was closed (and was not explicitly closed or aborted prior to the connection being closed)
QuicException ex = await Assert.ThrowsAsync<QuicException>(async () => await _inboundControlStream.ReadFrameAsync());
Assert.Equal(QuicError.ConnectionAborted, ex.QuicError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ private static void ReturnMemory(in StreamChunk chunk)

public void OnFatalException(Exception e)
{
if (e is QuicConnectionAbortedException abortedException && abortedException.ErrorCode == 0)
if (e is QuicException qe && qe.QuicError == QuicError.ConnectionAborted && abortedException.ErrorCode == 0)
{
_deliverableChannel.Writer.TryComplete(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public MockTls(ManagedQuicConnection connection, QuicClientConnectionOptions opt
WriteLevel = EncryptionLevel.Initial;
}

public MockTls(ManagedQuicConnection connection, QuicListenerOptions options, TransportParameters localTransportParams)
public MockTls(ManagedQuicConnection connection, QuicServerConnectionOptions options, TransportParameters localTransportParams)
: this(connection, localTransportParams, options.ServerAuthenticationOptions?.ApplicationProtocols)
{
WriteLevel = EncryptionLevel.Initial;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal sealed class MockTlsFactory : TlsFactory
internal override ITls CreateClient(ManagedQuicConnection connection, QuicClientConnectionOptions options,
TransportParameters localTransportParams) => new MockTls(connection, options, localTransportParams);

internal override ITls CreateServer(ManagedQuicConnection connection, QuicListenerOptions options,
internal override ITls CreateServer(ManagedQuicConnection connection, QuicServerConnectionOptions options,
TransportParameters localTransportParams) => new MockTls(connection, options, localTransportParams);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ internal OpenSslTls(ManagedQuicConnection connection, QuicClientConnectionOption
options.ClientAuthenticationOptions?.LocalCertificateSelectionCallback;
}

internal OpenSslTls(ManagedQuicConnection connection, QuicListenerOptions options, TransportParameters localTransportParameters)
internal OpenSslTls(ManagedQuicConnection connection, QuicServerConnectionOptions options, TransportParameters localTransportParameters)
: this(connection,
true,
localTransportParameters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal sealed class OpenSslTlsFactory : TlsFactory
internal override ITls CreateClient(ManagedQuicConnection connection, QuicClientConnectionOptions options,
TransportParameters localTransportParams) => new OpenSslTls(connection, options, localTransportParams);

internal override ITls CreateServer(ManagedQuicConnection connection, QuicListenerOptions options,
internal override ITls CreateServer(ManagedQuicConnection connection, QuicServerConnectionOptions options,
TransportParameters localTransportParams) => new OpenSslTls(connection, options, localTransportParams);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal abstract class TlsFactory
internal abstract ITls CreateClient(ManagedQuicConnection connection, QuicClientConnectionOptions options,
TransportParameters localTransportParams);

internal abstract ITls CreateServer(ManagedQuicConnection connection, QuicListenerOptions options,
internal abstract ITls CreateServer(ManagedQuicConnection connection, QuicServerConnectionOptions options,
TransportParameters localTransportParams);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,7 @@ private static TransportParameters Create(long maxBidiStreams, long maxUniStream
};
}

internal static TransportParameters FromClientConnectionOptions(QuicClientConnectionOptions options)
{
return Create(options.MaxBidirectionalStreams, options.MaxUnidirectionalStreams, options.IdleTimeout);
}

internal static TransportParameters FromListenerOptions(QuicListenerOptions options)
internal static TransportParameters FromConnectionOptions(QuicConnectionOptions options)
{
return Create(options.MaxBidirectionalStreams, options.MaxUnidirectionalStreams, options.IdleTimeout);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace System.Net.Quic.Implementations.Managed
{
public sealed partial class ManagedQuicConnection : QuicConnectionProvider
public sealed partial class ManagedQuicConnection : IAsyncDisposable
{
// This limit should ensure that if we can fit at least an ack frame into the packet,
private const int RequiredAllowanceForSending = 2 * ConnectionId.MaximumLength + 40;
Expand Down Expand Up @@ -225,14 +225,14 @@ internal void Ping()
internal EndPoint UnsafeRemoteEndPoint => _remoteEndpoint;

// client constructor
public ManagedQuicConnection(QuicClientConnectionOptions options, TlsFactory tlsFactory)
internal ManagedQuicConnection(QuicClientConnectionOptions options, TlsFactory tlsFactory)
{
IsServer = false;
_remoteEndpoint = options.RemoteEndPoint!;

_socketContext = new SingleConnectionSocketContext(options.LocalEndPoint, _remoteEndpoint, this)
.ConnectionContext;
_localTransportParameters = TransportParameters.FromClientConnectionOptions(options);
_localTransportParameters = TransportParameters.FromConnectionOptions(options);
Tls = tlsFactory.CreateClient(this, options, _localTransportParameters);

// init random connection ids for the client
Expand All @@ -252,13 +252,13 @@ public ManagedQuicConnection(QuicClientConnectionOptions options, TlsFactory tls
}

// server constructor
public ManagedQuicConnection(QuicListenerOptions options, QuicConnectionContext socketContext,
internal ManagedQuicConnection(QuicServerConnectionOptions options, QuicConnectionContext socketContext,
EndPoint remoteEndpoint, ReadOnlySpan<byte> odcid, TlsFactory tlsFactory)
{
IsServer = true;
_socketContext = socketContext;
_remoteEndpoint = remoteEndpoint;
_localTransportParameters = TransportParameters.FromListenerOptions(options);
_localTransportParameters = TransportParameters.FromConnectionOptions(options);

Tls = tlsFactory.CreateServer(this, options, _localTransportParameters);
_trace = InitTrace(IsServer, odcid);
Expand Down Expand Up @@ -297,12 +297,12 @@ private void CoreInit()
/// <summary>
/// Connection ID used by this endpoint to identify packets for this connection.
/// </summary>
public ConnectionId? SourceConnectionId { get; private set; }
internal ConnectionId? SourceConnectionId { get; private set; }

/// <summary>
/// Connection ID used by the peer to identify packets for this connection.
/// </summary>
public ConnectionId? DestinationConnectionId { get; private set; }
internal ConnectionId? DestinationConnectionId { get; private set; }

/// <summary>
/// Sets new socket context that will from now on service the connection.
Expand Down Expand Up @@ -607,7 +607,7 @@ internal ValueTask DisposeAsync(long errorCode)
if (!Connected)
{
// abandon connection attempt
_connectTcs.TryCompleteException(new QuicConnectionAbortedException(errorCode));
_connectTcs.TryCompleteException(new QuicException(QuicError.ConnectionAborted, errorCode));
_closeTcs.TryComplete();
return default;
}
Expand All @@ -626,18 +626,11 @@ internal ValueTask DisposeAsync(long errorCode)
return _closeTcs.GetTask();
}

internal ValueTask DisposeAsync()
public ValueTask DisposeAsync()
{
return DisposeAsync((long)TransportErrorCode.NoError);
}

public override void Dispose()
{
// TODO-RZ: I don't like this, but there does not seem to be a better way, unless we just want to do
// fire-and-forget
DisposeAsync().AsTask().ConfigureAwait(false).GetAwaiter().GetResult();
}

private void SetEncryptionSecrets(EncryptionLevel level, TlsCipherSuite algorithm,
ReadOnlySpan<byte> readSecret, ReadOnlySpan<byte> writeSecret)
{
Expand Down Expand Up @@ -704,14 +697,13 @@ private enum ProcessPacketResult

#region Public API

internal override bool Connected => HandshakeConfirmed;

internal override IPEndPoint LocalEndPoint => _socketContext.LocalEndPoint;
public IPEndPoint LocalEndPoint => _socketContext.LocalEndPoint;

// TODO-RZ: create a defensive copy of the endpoint
internal override EndPoint RemoteEndPoint => _remoteEndpoint;
public EndPoint RemoteEndPoint => _remoteEndpoint;

internal override ValueTask ConnectAsync(CancellationToken cancellationToken = default)
internal ValueTask ConnectAsync(CancellationToken cancellationToken = default)
{
ThrowIfDisposed();
ThrowIfError();
Expand All @@ -724,39 +716,15 @@ internal override ValueTask ConnectAsync(CancellationToken cancellationToken = d
return _connectTcs.GetTask();
}

internal async override ValueTask<QuicStreamProvider> OpenUnidirectionalStreamAsync(CancellationToken cancellationToken = default)
{
ThrowIfDisposed();
ThrowIfError();

return await OpenStream(true, cancellationToken).ConfigureAwait(false);
}

internal async override ValueTask<QuicStreamProvider> OpenBidirectionalStreamAsync(CancellationToken cancellationToken = default)
{
ThrowIfDisposed();
ThrowIfError();

return await OpenStream(false, cancellationToken).ConfigureAwait(false);
}

internal override int GetRemoteAvailableUnidirectionalStreamCount()
{
ThrowIfDisposed();
ThrowIfError();

return checked((int)_sendLimits.MaxStreamsUni);
}

internal override int GetRemoteAvailableBidirectionalStreamCount()
public async ValueTask<ManagedQuicStream> OpenOutboundStreamAsync(QuicStreamType type, CancellationToken cancellationToken = default)
{
ThrowIfDisposed();
ThrowIfError();

return checked((int)_sendLimits.MaxStreamsBidi);
return await OpenStream(type == QuicStreamType.Unidirectional, cancellationToken).ConfigureAwait(false);
}

internal override async ValueTask<QuicStreamProvider> AcceptStreamAsync(CancellationToken cancellationToken = default)
public async ValueTask<ManagedQuicStream> AcceptInboundStreamAsync(CancellationToken cancellationToken = default)
{
ThrowIfDisposed();
ThrowIfError();
Expand All @@ -771,7 +739,7 @@ internal override async ValueTask<QuicStreamProvider> AcceptStreamAsync(Cancella
}
}

internal override SslApplicationProtocol NegotiatedApplicationProtocol
public SslApplicationProtocol NegotiatedApplicationProtocol
{
get
{
Expand All @@ -780,9 +748,9 @@ internal override SslApplicationProtocol NegotiatedApplicationProtocol
}
}

internal override X509Certificate? RemoteCertificate => throw new NotImplementedException();
public X509Certificate? RemoteCertificate => throw new NotImplementedException();

internal override ValueTask CloseAsync(long errorCode, CancellationToken cancellationToken = default)
public ValueTask CloseAsync(long errorCode, CancellationToken cancellationToken = default)
{
return DisposeAsync(errorCode);
}
Expand Down Expand Up @@ -928,12 +896,9 @@ private QuicException MakeOperationAbortedException()
: new QuicOperationAbortedException(); // initiated by us
}

private static QuicConnectionAbortedException MakeConnectionAbortedException(QuicError error)
private static QuicException MakeConnectionAbortedException(QuicError error)
{
return error.ReasonPhrase != null
// TODO-RZ: We should probably format reason phrase into the exception message
? new QuicConnectionAbortedException(error.ReasonPhrase, (long)error.ErrorCode)
: new QuicConnectionAbortedException((long)error.ErrorCode);
return new QuicException(QuicError.ConnectionAborted, (long)error.ErrorCode, error.ReasonPhrase);
}

internal void OnSocketContextException(Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace System.Net.Quic.Implementations.Managed
{
internal sealed class ManagedQuicStream : QuicStreamProvider
public sealed class ManagedQuicStream
{
/// <summary>
/// Node to the linked list of all flushable streams. Should be accessed only by the <see cref="StreamCollection"/> class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<Compile Include="..\..\src\Resources\*.cs" />
<Compile Include="..\..\src\System\Net\Quic\QuicClientConnectionOptions.cs" />
<Compile Include="..\..\src\System\Net\Quic\QuicConnection.cs" />
<Compile Include="..\..\src\System\Net\Quic\QuicConnectionAbortedException.cs" />
<Compile Include="..\..\src\System\Net\Quic\QuicException.cs" />
<Compile Include="..\..\src\System\Net\Quic\QuicListener.cs" />
<Compile Include="..\..\src\System\Net\Quic\QuicListenerOptions.cs" />
Expand Down