Skip to content

Commit

Permalink
Additional QuicConnectionOptions (#94211)
Browse files Browse the repository at this point in the history
* [API Proposal]: Additional QuicConnectionOptions

* Comment change

* Reflect latest API review

* Use HandshakeTimeout

* Use Connect timeout on client as well

* Code review feedback

* Cancel ServerOptionsCallback when client closes connection

* Code review feedback
  • Loading branch information
rzikm authored Nov 29, 2023
1 parent c089092 commit 563664e
Show file tree
Hide file tree
Showing 11 changed files with 548 additions and 56 deletions.
13 changes: 12 additions & 1 deletion src/libraries/System.Net.Quic/ref/System.Net.Quic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public abstract partial class QuicConnectionOptions
internal QuicConnectionOptions() { }
public long DefaultCloseErrorCode { get { throw null; } set { } }
public long DefaultStreamErrorCode { get { throw null; } set { } }
public System.TimeSpan HandshakeTimeout { get { throw null; } set { } }
public System.TimeSpan IdleTimeout { get { throw null; } set { } }
public System.Net.Quic.QuicReceiveWindowSizes InitialReceiveWindowSizes { get { throw null; } set { } }
public System.TimeSpan KeepAliveInterval { get { throw null; } set { } }
public int MaxInboundBidirectionalStreams { get { throw null; } set { } }
public int MaxInboundUnidirectionalStreams { get { throw null; } set { } }
}
Expand All @@ -64,8 +67,8 @@ public sealed partial class QuicException : System.IO.IOException
{
public QuicException(System.Net.Quic.QuicError error, long? applicationErrorCode, string message) { }
public long? ApplicationErrorCode { get { throw null; } }
public long? TransportErrorCode { get { throw null; } }
public System.Net.Quic.QuicError QuicError { get { throw null; } }
public long? TransportErrorCode { get { throw null; } }
}
public sealed partial class QuicListener : System.IAsyncDisposable
{
Expand All @@ -85,6 +88,14 @@ public QuicListenerOptions() { }
public int ListenBacklog { get { throw null; } set { } }
public System.Net.IPEndPoint ListenEndPoint { get { throw null; } set { } }
}
public sealed partial class QuicReceiveWindowSizes
{
public QuicReceiveWindowSizes() { }
public int Connection { get { throw null; } set { } }
public int LocallyInitiatedBidirectionalStream { get { throw null; } set { } }
public int RemotelyInitiatedBidirectionalStream { get { throw null; } set { } }
public int UnidirectionalStream { get { throw null; } set { } }
}
public sealed partial class QuicServerConnectionOptions : System.Net.Quic.QuicConnectionOptions
{
public QuicServerConnectionOptions() { }
Expand Down
1 change: 1 addition & 0 deletions src/libraries/System.Net.Quic/src/ExcludeApiList.PNSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ P:System.Net.Quic.QuicConnection.IsSupported
P:System.Net.Quic.QuicListener.IsSupported
C:System.Net.Quic.QuicListenerOptions
C:System.Net.Quic.QuicConnectionOptions
C:System.Net.Quic.QuicReceiveWindowSizes
C:System.Net.Quic.QuicClientConnectionOptions
C:System.Net.Quic.QuicServerConnectionOptions
5 changes: 4 additions & 1 deletion src/libraries/System.Net.Quic/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@
<value>Writing is not allowed on stream.</value>
</data>
<data name="net_quic_in_range" xml:space="preserve">
<value>'{0}'' should be within [0, {1}) range.</value>
<value>'{0}' should be within [0, {1}) range.</value>
</data>
<data name="net_quic_power_of_2" xml:space="preserve">
<value>'{0}' must be a power of 2.</value>
</data>
<data name="net_quic_not_null_listener" xml:space="preserve">
<value>'{0}' must be specified to start the listener.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static MsQuicApi()

if (version < s_minMsQuicVersion)
{
NotSupportedReason = $"Incompatible MsQuic library version '{version}', expecting higher than '{s_minMsQuicVersion}'.";
NotSupportedReason = $"Incompatible MsQuic library version '{version}', expecting higher than '{s_minMsQuicVersion}'.";
if (NetEventSource.Log.IsEnabled())
{
NetEventSource.Info(null, NotSupportedReason);
Expand All @@ -178,7 +178,7 @@ static MsQuicApi()
// Implies windows platform, check TLS1.3 availability
if (!IsWindowsVersionSupported())
{
NotSupportedReason = $"Current Windows version ({Environment.OSVersion}) is not supported by QUIC. Minimal supported version is {s_minWindowsVersion}.";
NotSupportedReason = $"Current Windows version ({Environment.OSVersion}) is not supported by QUIC. Minimal supported version is {s_minWindowsVersion}.";
if (NetEventSource.Log.IsEnabled())
{
NetEventSource.Info(null, NotSupportedReason);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,47 @@ private static unsafe MsQuicSafeHandle Create(QuicConnectionOptions options, QUI
#pragma warning restore SYSLIB0040

QUIC_SETTINGS settings = default(QUIC_SETTINGS);

settings.IsSet.PeerUnidiStreamCount = 1;
settings.PeerUnidiStreamCount = (ushort)options.MaxInboundUnidirectionalStreams;

settings.IsSet.PeerBidiStreamCount = 1;
settings.PeerBidiStreamCount = (ushort)options.MaxInboundBidirectionalStreams;

if (options.IdleTimeout != TimeSpan.Zero)
{
settings.IsSet.IdleTimeoutMs = 1;
settings.IdleTimeoutMs = options.IdleTimeout != Timeout.InfiniteTimeSpan ? (ulong)options.IdleTimeout.TotalMilliseconds : 0;
settings.IdleTimeoutMs = options.IdleTimeout != Timeout.InfiniteTimeSpan
? (ulong)options.IdleTimeout.TotalMilliseconds
: 0; // 0 disables the timeout
}

if (options.KeepAliveInterval != TimeSpan.Zero)
{
settings.IsSet.KeepAliveIntervalMs = 1;
settings.KeepAliveIntervalMs = options.KeepAliveInterval != Timeout.InfiniteTimeSpan
? (uint)options.KeepAliveInterval.TotalMilliseconds
: 0; // 0 disables the keepalive
}

settings.IsSet.ConnFlowControlWindow = 1;
settings.ConnFlowControlWindow = (uint)(options._initialRecieveWindowSizes?.Connection ?? QuicDefaults.DefaultConnectionMaxData);

settings.IsSet.StreamRecvWindowBidiLocalDefault = 1;
settings.StreamRecvWindowBidiLocalDefault = (uint)(options._initialRecieveWindowSizes?.LocallyInitiatedBidirectionalStream ?? QuicDefaults.DefaultStreamMaxData);

settings.IsSet.StreamRecvWindowBidiRemoteDefault = 1;
settings.StreamRecvWindowBidiRemoteDefault = (uint)(options._initialRecieveWindowSizes?.RemotelyInitiatedBidirectionalStream ?? QuicDefaults.DefaultStreamMaxData);

settings.IsSet.StreamRecvWindowUnidiDefault = 1;
settings.StreamRecvWindowUnidiDefault = (uint)(options._initialRecieveWindowSizes?.UnidirectionalStream ?? QuicDefaults.DefaultStreamMaxData);

if (options.HandshakeTimeout != TimeSpan.Zero)
{
settings.IsSet.HandshakeIdleTimeoutMs = 1;
settings.HandshakeIdleTimeoutMs = options.HandshakeTimeout != Timeout.InfiniteTimeSpan
? (ulong)options.HandshakeTimeout.TotalMilliseconds
: 0; // 0 disables the timeout
}

QUIC_HANDLE* handle;
Expand Down
Loading

0 comments on commit 563664e

Please sign in to comment.