dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.26k stars 4.73k forks source link

[API Proposal]: [QUIC] QuicProvider #70424

Closed ManickaP closed 2 years ago

ManickaP commented 2 years ago

Background and motivation

API design for exposing static QuicProvider to the public. MsQuic, the underlying implementation for System.Net.Quic, doesn't support all platforms .NET does, e.g.: Win 11+. So we need a static way to check whether QUIC is supported or not. QuicProvider class is based on QuicImplementationProvider we had in 6.0.

Apart from IsSupported, we're also putting methods for connection and listener creation here.

API Proposal

public static class QuicProvider
{
    public bool IsSupported { get; }
    public static ValueTask<QuicListener> CreateListenerAsync(QuicListenerOptions options, CancellationToken cancellationToken = default);
    public static ValueTask<QuicConnection> CreateConnectionAsync(QuicClientConnectionOptions options, CancellationToken cancellationToken = default);
}

API Usage

if (QuicProvider.IsSupported)
{
    // QuicListenerOptions in https://github.com/dotnet/runtime/issues/67560
    // Listener will be already listening for incoming connections when returned.
    var listener = await QuicProvider.CreateListenerAsync(listenerOptions);
}
if (QuicProvider.IsSupported)
{
    // QuicClientConnectionOptions in https://github.com/dotnet/runtime/issues/68902
    // Connection will be already connected when returned.
    var connection = await QuicProvider.CreateConnectionAsync(connectionOptions);
}

Alternative Designs

Not having QuicProvider at all. Then, moving IsSupported to either QuicListener, QuicConnection or QuicStream and providing static CreateAsync methods on QuicListener and QuicConnection.

Risks

As I'll state with all QUIC APIs. We might consider making all of these PreviewFeature. Not to deter user from using it, but to give us flexibility to tune the API shape based on customer feedback. We don't have many users now and we're mostly making these APIs based on what Kestrel needs, our limited experience with System.Net.Quic and my meager experiments with other QUIC implementations.

cc: @JamesNK @Tratcher @wfurt @CarnaViire @rzikm

ghost commented 2 years ago

Tagging subscribers to this area: @dotnet/ncl See info in area-owners.md if you want to be subscribed.

Issue Details
### Background and motivation API design for exposing static `QuicProvider` to the public. MsQuic, the underlying implementation for System.Net.Quic, doesn't support all platforms .NET does, e.g.: Win 11+. So we need a static way to check whether QUIC is supported or not. `QuicProvider` class is based on `QuicImplementationProvider` we had in 6.0. Apart from `IsSupported`, we're also putting methods for connection and listener creation here. ### API Proposal ```csharp public static class QuicProvider { public bool IsSupported { get; } public static ValueTask CreateListenerAsync(QuicListenerOptions options, CancellationToken cancellationToken = default); public static ValueTask CreateConnectionAsync(QuicClientConnectionOptions options, CancellationToken cancellationToken = default); } ``` ### API Usage ```csharp if (QuicProvider.IsSupported) { // QuicListenerOptions in https://github.com/dotnet/runtime/issues/67560 // Listener will be already listening for incoming connections when returned. var listener = await QuicProvider.CreateListenerAsync(listenerOptions); } if (QuicProvider.IsSupported) { // QuicClientConnectionOptions in https://github.com/dotnet/runtime/issues/68902 // Connection will be already connected when returned. var connection = await QuicProvider.CreateConnectionAsync(connectionOptions); } ``` ### Alternative Designs Not having `QuicProvider` at all. Then, moving `IsSupported` to either `QuicListener`, `QuicConnection` or `QuicStream` and providing static `CreateAsync` methods on `QuicListener` and `QuicConnection`. ### Risks As I'll state with all QUIC APIs. We might consider making all of these PreviewFeature. Not to deter user from using it, but to give us flexibility to tune the API shape based on customer feedback. We don't have many users now and we're mostly making these APIs based on what Kestrel needs, our limited experience with System.Net.Quic and my meager experiments with other QUIC implementations. cc: @JamesNK @Tratcher @wfurt @CarnaViire @rzikm
Author: ManickaP
Assignees: -
Labels: `api-suggestion`, `area-System.Net.Quic`
Milestone: -
ManickaP commented 2 years ago

Draft PR https://github.com/dotnet/runtime/pull/70421

terrajobst commented 2 years ago

Video

namespace System.Net.Quic;

public static class QuicProvider
{
    public static bool IsSupported { get; }
    public static ValueTask<QuicListener> CreateListenerAsync(QuicListenerOptions options, CancellationToken cancellationToken = default);
    public static ValueTask<QuicConnection> CreateConnectionAsync(QuicClientConnectionOptions options, CancellationToken cancellationToken = default);
}
ManickaP commented 2 years ago

https://github.com/dotnet/runtime/pull/70421