Skip to content

Commit

Permalink
QUIC: Change constructor overloads for passing QuicImplementationProv…
Browse files Browse the repository at this point in the history
…ider (dotnet#42542)

* change constructor overloads for passing QuicImplementationProvider

* add and use QuicImplementationProviders.Default

* Update src/System.Net.Quic/src/System/Net/Quic/QuicImplementationProviders.cs

Co-Authored-By: Stephen Toub <[email protected]>
  • Loading branch information
geoffkizer and stephentoub authored Nov 12, 2019
1 parent 08f186e commit 460c422
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/System.Net.Quic/ref/System.Net.Quic.Temporary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ namespace System.Net.Quic
{
public sealed partial class QuicConnection : System.IDisposable
{
public QuicConnection(IPEndPoint remoteEndPoint, System.Net.Security.SslClientAuthenticationOptions sslClientAuthenticationOptions, IPEndPoint localEndPoint = null, System.Net.Quic.Implementations.QuicImplementationProvider implementationProvider = null) { }
public QuicConnection(System.Net.Quic.Implementations.QuicImplementationProvider implementationProvider, IPEndPoint remoteEndPoint, System.Net.Security.SslClientAuthenticationOptions sslClientAuthenticationOptions, IPEndPoint localEndPoint = null) { }
}
public sealed partial class QuicListener : IDisposable
{
public QuicListener(IPEndPoint listenEndPoint, System.Net.Security.SslServerAuthenticationOptions sslServerAuthenticationOptions, System.Net.Quic.Implementations.QuicImplementationProvider implementationProvider = null) { }
public QuicListener(System.Net.Quic.Implementations.QuicImplementationProvider implementationProvider, IPEndPoint listenEndPoint, System.Net.Security.SslServerAuthenticationOptions sslServerAuthenticationOptions) { }
}
public static class QuicImplementationProviders
{
public static System.Net.Quic.Implementations.QuicImplementationProvider Mock { get { throw null; } }

public static System.Net.Quic.Implementations.QuicImplementationProvider Default { get { throw null; } }
}
}
namespace System.Net.Quic.Implementations
Expand Down
4 changes: 2 additions & 2 deletions src/System.Net.Quic/src/System/Net/Quic/QuicConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public sealed class QuicConnection : IDisposable
/// <param name="sslClientAuthenticationOptions">TLS options</param>
/// <param name="localEndPoint">The local endpoint to connect from.</param>
public QuicConnection(IPEndPoint remoteEndPoint, SslClientAuthenticationOptions sslClientAuthenticationOptions, IPEndPoint localEndPoint = null)
: this(remoteEndPoint, sslClientAuthenticationOptions, localEndPoint, implementationProvider: null)
: this(QuicImplementationProviders.Default, remoteEndPoint, sslClientAuthenticationOptions, localEndPoint)
{
}

// !!! TEMPORARY: Remove "implementationProvider" before shipping
public QuicConnection(IPEndPoint remoteEndPoint, SslClientAuthenticationOptions sslClientAuthenticationOptions, IPEndPoint localEndPoint = null, QuicImplementationProvider implementationProvider = null)
public QuicConnection(QuicImplementationProvider implementationProvider, IPEndPoint remoteEndPoint, SslClientAuthenticationOptions sslClientAuthenticationOptions, IPEndPoint localEndPoint = null)
{
_provider = implementationProvider.CreateConnection(remoteEndPoint, sslClientAuthenticationOptions, localEndPoint);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ namespace System.Net.Quic
public static class QuicImplementationProviders
{
public static Implementations.QuicImplementationProvider Mock { get; } = new Implementations.Mock.MockImplementationProvider();

public static Implementations.QuicImplementationProvider Default => Mock;
}
}
4 changes: 2 additions & 2 deletions src/System.Net.Quic/src/System/Net/Quic/QuicListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public sealed class QuicListener : IDisposable
/// <param name="listenEndPoint">The local endpoint to listen on.</param>
/// <param name="sslServerAuthenticationOptions">TLS options for the listener.</param>
public QuicListener(IPEndPoint listenEndPoint, SslServerAuthenticationOptions sslServerAuthenticationOptions)
: this(listenEndPoint, sslServerAuthenticationOptions, implementationProvider: null)
: this(QuicImplementationProviders.Default, listenEndPoint, sslServerAuthenticationOptions)
{
}

// !!! TEMPORARY: Remove "implementationProvider" before shipping
public QuicListener(IPEndPoint listenEndPoint, SslServerAuthenticationOptions sslServerAuthenticationOptions, QuicImplementationProvider implementationProvider = null)
public QuicListener(QuicImplementationProvider implementationProvider, IPEndPoint listenEndPoint, SslServerAuthenticationOptions sslServerAuthenticationOptions)
{
_provider = implementationProvider.CreateListener(listenEndPoint, sslServerAuthenticationOptions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public class QuicConnectionTests
[Fact]
public async Task BasicTest()
{
using (QuicListener listener = new QuicListener(new IPEndPoint(IPAddress.Loopback, 0), sslServerAuthenticationOptions: null, implementationProvider: QuicImplementationProviders.Mock))
using (QuicListener listener = new QuicListener(QuicImplementationProviders.Mock, new IPEndPoint(IPAddress.Loopback, 0), sslServerAuthenticationOptions: null))
{
IPEndPoint listenEndPoint = listener.ListenEndPoint;

await Task.WhenAll(
Task.Run(async () =>
{
// Client code
using (QuicConnection connection = new QuicConnection(listenEndPoint, sslClientAuthenticationOptions: null, implementationProvider: QuicImplementationProviders.Mock))
using (QuicConnection connection = new QuicConnection(QuicImplementationProviders.Mock, listenEndPoint, sslClientAuthenticationOptions: null))
{
await connection.ConnectAsync();
using (QuicStream stream = connection.OpenBidirectionalStream())
Expand Down Expand Up @@ -55,11 +55,11 @@ await Task.WhenAll(
[Fact]
public async Task TestStreams()
{
using (QuicListener listener = new QuicListener(new IPEndPoint(IPAddress.Loopback, 0), sslServerAuthenticationOptions: null, implementationProvider: QuicImplementationProviders.Mock))
using (QuicListener listener = new QuicListener(QuicImplementationProviders.Mock, new IPEndPoint(IPAddress.Loopback, 0), sslServerAuthenticationOptions: null))
{
IPEndPoint listenEndPoint = listener.ListenEndPoint;

using (QuicConnection clientConnection = new QuicConnection(listenEndPoint, sslClientAuthenticationOptions: null, implementationProvider: QuicImplementationProviders.Mock))
using (QuicConnection clientConnection = new QuicConnection(QuicImplementationProviders.Mock, listenEndPoint, sslClientAuthenticationOptions: null))
{
Assert.False(clientConnection.Connected);
Assert.Equal(listenEndPoint, clientConnection.RemoteEndPoint);
Expand Down

0 comments on commit 460c422

Please sign in to comment.