| | | 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/> |
| | 7 | 17 | | public string DefaultName => "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> |
| | 246 | 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 | | TransportAddress transportAddress, |
| | | 34 | | MultiplexedConnectionOptions options, |
| | | 35 | | SslServerAuthenticationOptions? serverAuthenticationOptions) |
| | 127 | 36 | | { |
| | 127 | 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 | | |
| | 127 | 43 | | if (transportAddress.TransportName is string name && name != DefaultName) |
| | 0 | 44 | | { |
| | 0 | 45 | | throw new NotSupportedException($"The QUIC server transport does not support transport '{name}'."); |
| | | 46 | | } |
| | | 47 | | |
| | 127 | 48 | | if (transportAddress.Params.Count > 0) |
| | 1 | 49 | | { |
| | 1 | 50 | | throw new ArgumentException( |
| | 1 | 51 | | "The transport address contains parameters that are not valid for the QUIC server transport.", |
| | 1 | 52 | | nameof(transportAddress)); |
| | | 53 | | } |
| | | 54 | | |
| | 126 | 55 | | if (serverAuthenticationOptions is null) |
| | 0 | 56 | | { |
| | 0 | 57 | | throw new ArgumentNullException( |
| | 0 | 58 | | nameof(serverAuthenticationOptions), |
| | 0 | 59 | | "The QUIC server transport requires the SSL server authentication options to be set."); |
| | | 60 | | } |
| | | 61 | | |
| | 126 | 62 | | if (serverAuthenticationOptions.ApplicationProtocols |
| | 126 | 63 | | is not List<SslApplicationProtocol> applicationProtocols || applicationProtocols.Count == 0) |
| | 0 | 64 | | { |
| | 0 | 65 | | throw new ArgumentException( |
| | 0 | 66 | | "The QUIC server transport requires ApplicationProtocols to be set in the SSL server authentication opti |
| | 0 | 67 | | nameof(serverAuthenticationOptions)); |
| | | 68 | | } |
| | | 69 | | |
| | 126 | 70 | | return new QuicMultiplexedListener(transportAddress, options, _quicOptions, serverAuthenticationOptions); |
| | 125 | 71 | | } |
| | | 72 | | } |