| | | 1 | | // Copyright (c) ZeroC, Inc. |
| | | 2 | | |
| | | 3 | | using IceRpc.Transports.Quic; |
| | | 4 | | using IceRpc.Transports.Slic; |
| | | 5 | | using IceRpc.Transports.Tcp; |
| | | 6 | | using System.Net.Security; |
| | | 7 | | using System.Runtime.Versioning; |
| | | 8 | | |
| | | 9 | | namespace IceRpc.Transports.Internal; |
| | | 10 | | |
| | | 11 | | /// <summary>Implements <see cref="IMultiplexedClientTransport" /> using two multiplexed transports: QUIC and |
| | | 12 | | /// Slic over TCP.</summary> |
| | | 13 | | internal class DefaultMultiplexedClientTransport : IMultiplexedClientTransport |
| | | 14 | | { |
| | | 15 | | /// <inheritdoc/> |
| | 11 | 16 | | public string DefaultName => _quicTransport.DefaultName; |
| | | 17 | | |
| | | 18 | | /// <inheritdoc/> |
| | 0 | 19 | | public bool IsSslRequired(string? transportName) => Resolve(transportName).IsSslRequired(transportName); |
| | | 20 | | |
| | | 21 | | internal static DefaultMultiplexedClientTransport Instance |
| | | 22 | | { |
| | | 23 | | get |
| | 24 | 24 | | { |
| | 24 | 25 | | if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsWindows()) |
| | 24 | 26 | | { |
| | 24 | 27 | | return _instance; |
| | | 28 | | } |
| | 0 | 29 | | throw new PlatformNotSupportedException( |
| | 0 | 30 | | "The default multiplexed client transport, QUIC, is only available on Linux, macOS, and Windows."); |
| | 24 | 31 | | } |
| | | 32 | | } |
| | | 33 | | |
| | | 34 | | [SupportedOSPlatform("linux")] |
| | | 35 | | [SupportedOSPlatform("macos")] |
| | | 36 | | [SupportedOSPlatform("windows")] |
| | 4 | 37 | | private static readonly DefaultMultiplexedClientTransport _instance = new(); |
| | | 38 | | |
| | | 39 | | private readonly IMultiplexedClientTransport _quicTransport; |
| | 4 | 40 | | private readonly IMultiplexedClientTransport _tcpTransport = new SlicClientTransport(new TcpClientTransport()); |
| | | 41 | | |
| | | 42 | | /// <inheritdoc/> |
| | | 43 | | public IMultiplexedConnection CreateConnection( |
| | | 44 | | TransportAddress transportAddress, |
| | | 45 | | MultiplexedConnectionOptions options, |
| | | 46 | | SslClientAuthenticationOptions? clientAuthenticationOptions) => |
| | 5 | 47 | | Resolve(transportAddress.TransportName).CreateConnection( |
| | 5 | 48 | | transportAddress, |
| | 5 | 49 | | options, |
| | 5 | 50 | | clientAuthenticationOptions); |
| | | 51 | | |
| | | 52 | | [SupportedOSPlatform("linux")] |
| | | 53 | | [SupportedOSPlatform("macos")] |
| | | 54 | | [SupportedOSPlatform("windows")] |
| | 8 | 55 | | private DefaultMultiplexedClientTransport() => _quicTransport = new QuicClientTransport(); |
| | | 56 | | |
| | | 57 | | private IMultiplexedClientTransport Resolve(string? transportName) => |
| | 5 | 58 | | transportName switch |
| | 5 | 59 | | { |
| | 0 | 60 | | null => _quicTransport, |
| | 4 | 61 | | "quic" => _quicTransport, |
| | 1 | 62 | | "tcp" => _tcpTransport, |
| | 0 | 63 | | _ => throw new NotSupportedException( |
| | 0 | 64 | | $"The default multiplexed client transport does not support transport '{transportName}'.") |
| | 5 | 65 | | }; |
| | | 66 | | } |