< Summary

Information
Class: IceRpc.Transports.Quic.QuicClientTransport
Assembly: IceRpc.Transports.Quic
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.Transports.Quic/QuicClientTransport.cs
Tag: 275_13775359185
Line coverage
81%
Covered lines: 36
Uncovered lines: 8
Coverable lines: 44
Total lines: 81
Line coverage: 81.8%
Branch coverage
70%
Covered branches: 14
Total branches: 20
Branch coverage: 70%
Method coverage
80%
Covered methods: 4
Total methods: 5
Method coverage: 80%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Name()100%11100%
.ctor(...)100%11100%
.ctor()100%210%
CreateConnection(...)70%20.912086.84%
CheckParams(...)100%11100%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.Transports.Quic/QuicClientTransport.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using IceRpc.Transports.Quic.Internal;
 4using System.Net;
 5using System.Net.Quic;
 6using System.Net.Security;
 7
 8namespace IceRpc.Transports.Quic;
 9
 10/// <summary>Implements <see cref="IMultiplexedClientTransport"/> using QUIC.</summary>
 11public class QuicClientTransport : IMultiplexedClientTransport
 12{
 13    /// <inheritdoc/>
 23514    public string Name => "quic";
 15
 16    private readonly QuicClientTransportOptions _quicTransportOptions;
 17
 18    /// <summary>Constructs a QUIC client transport.</summary>
 19    /// <param name="options">The options to configure the QUIC client transport.</param>
 47020    public QuicClientTransport(QuicClientTransportOptions options) => _quicTransportOptions = options;
 21
 22    /// <summary>Constructs a QUIC client transport.</summary>
 23    public QuicClientTransport()
 024        : this(new QuicClientTransportOptions())
 025    {
 026    }
 27
 28    /// <inheritdoc/>
 29    public IMultiplexedConnection CreateConnection(
 30        ServerAddress serverAddress,
 31        MultiplexedConnectionOptions options,
 32        SslClientAuthenticationOptions? clientAuthenticationOptions)
 23533    {
 23534        if (!QuicConnection.IsSupported)
 035        {
 036            throw new NotSupportedException("The Quic client transport is not supported on this platform.");
 37        }
 38
 23539        if ((serverAddress.Transport is string transport && transport != Name) || !CheckParams(serverAddress))
 240        {
 241            throw new ArgumentException(
 242                $"The server address '{serverAddress}' contains parameters that are not valid for the Quic client transp
 243                nameof(serverAddress));
 44        }
 45
 23346        if (serverAddress.Transport is null)
 047        {
 048            serverAddress = serverAddress with { Transport = Name };
 049        }
 50
 23351        clientAuthenticationOptions = clientAuthenticationOptions?.Clone() ?? new();
 23352        clientAuthenticationOptions.TargetHost ??= serverAddress.Host;
 23353        clientAuthenticationOptions.ApplicationProtocols ??= new List<SslApplicationProtocol> // Mandatory with Quic
 23354        {
 23355            new SslApplicationProtocol(serverAddress.Protocol.Name)
 23356        };
 57
 23358        EndPoint endpoint = IPAddress.TryParse(serverAddress.Host, out IPAddress? ipAddress) ?
 23359            new IPEndPoint(ipAddress, serverAddress.Port) :
 23360            new DnsEndPoint(serverAddress.Host, serverAddress.Port);
 61
 23362        var quicClientOptions = new QuicClientConnectionOptions
 23363        {
 23364            ClientAuthenticationOptions = clientAuthenticationOptions,
 23365            DefaultCloseErrorCode = (int)MultiplexedConnectionCloseError.Aborted,
 23366            DefaultStreamErrorCode = 0,
 23367            IdleTimeout = _quicTransportOptions.IdleTimeout,
 23368#if NET9_0_OR_GREATER
 23369            KeepAliveInterval = _quicTransportOptions.KeepAliveInterval,
 23370#endif
 23371            LocalEndPoint = _quicTransportOptions.LocalNetworkAddress,
 23372            RemoteEndPoint = endpoint,
 23373            MaxInboundBidirectionalStreams = options.MaxBidirectionalStreams,
 23374            MaxInboundUnidirectionalStreams = options.MaxUnidirectionalStreams
 23375        };
 76
 23377        return new QuicMultiplexedClientConnection(options, quicClientOptions);
 23378    }
 79
 23580    private static bool CheckParams(ServerAddress serverAddress) => serverAddress.Params.Count == 0;
 81}