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