| | | 1 | | // Copyright (c) ZeroC, Inc. |
| | | 2 | | |
| | | 3 | | using IceRpc.Transports.Quic.Internal; |
| | | 4 | | using System.Net.Quic; |
| | | 5 | | using System.Net.Security; |
| | | 6 | | using System.Runtime.Versioning; |
| | | 7 | | |
| | | 8 | | namespace IceRpc.Transports.Quic; |
| | | 9 | | |
| | | 10 | | /// <summary>Implements <see cref="IMultiplexedServerTransport"/> using QUIC.</summary> |
| | | 11 | | [SupportedOSPlatform("linux")] |
| | | 12 | | [SupportedOSPlatform("macos")] |
| | | 13 | | [SupportedOSPlatform("windows")] |
| | | 14 | | public class QuicServerTransport : IMultiplexedServerTransport |
| | | 15 | | { |
| | | 16 | | /// <inheritdoc/> |
| | 124 | 17 | | public string Name => "quic"; |
| | | 18 | | |
| | | 19 | | private readonly QuicServerTransportOptions _quicOptions; |
| | | 20 | | |
| | | 21 | | /// <summary>Constructs a QUIC server transport.</summary> |
| | | 22 | | /// <param name="options">The options to configure the transport.</param> |
| | 248 | 23 | | public QuicServerTransport(QuicServerTransportOptions options) => _quicOptions = options; |
| | | 24 | | |
| | | 25 | | /// <summary>Constructs a QUIC server transport.</summary> |
| | | 26 | | public QuicServerTransport() |
| | 1 | 27 | | : this(new QuicServerTransportOptions()) |
| | 1 | 28 | | { |
| | 1 | 29 | | } |
| | | 30 | | |
| | | 31 | | /// <inheritdoc/> |
| | | 32 | | public IListener<IMultiplexedConnection> Listen( |
| | | 33 | | ServerAddress serverAddress, |
| | | 34 | | MultiplexedConnectionOptions options, |
| | | 35 | | SslServerAuthenticationOptions? serverAuthenticationOptions) |
| | 124 | 36 | | { |
| | 124 | 37 | | if (!QuicListener.IsSupported) |
| | 0 | 38 | | { |
| | 0 | 39 | | throw new NotSupportedException( |
| | 0 | 40 | | "The QUIC server transport is not available on this system. Please review the Platform Dependencies for |
| | | 41 | | } |
| | | 42 | | |
| | 124 | 43 | | if ((serverAddress.Transport is string transport && transport != Name) || serverAddress.Params.Count > 0) |
| | 1 | 44 | | { |
| | 1 | 45 | | throw new ArgumentException( |
| | 1 | 46 | | $"The server address '{serverAddress}' contains parameters that are not valid for the QUIC server transp |
| | 1 | 47 | | nameof(serverAddress)); |
| | | 48 | | } |
| | | 49 | | |
| | 123 | 50 | | if (serverAuthenticationOptions is null) |
| | 0 | 51 | | { |
| | 0 | 52 | | throw new ArgumentNullException( |
| | 0 | 53 | | nameof(serverAuthenticationOptions), |
| | 0 | 54 | | "The QUIC server transport requires the SSL server authentication options to be set."); |
| | | 55 | | } |
| | | 56 | | |
| | 123 | 57 | | if (serverAddress.Transport is null) |
| | 122 | 58 | | { |
| | 122 | 59 | | serverAddress = serverAddress with { Transport = Name }; |
| | 122 | 60 | | } |
| | | 61 | | |
| | 123 | 62 | | return new QuicMultiplexedListener(serverAddress, options, _quicOptions, serverAuthenticationOptions); |
| | 122 | 63 | | } |
| | | 64 | | } |