Skip to content

Commit

Permalink
[QUIC] API Update (#49823)
Browse files Browse the repository at this point in the history
* Cherry picked change from scalablecory/msquic-update.

* Enum rename _FLAG --> _FLAGS to follow msquic naming.

* Enums updated

* Updated interop, compilable project.

* Somewhat working update of msquic API

* Post-merge compilation fixes.

* Fixed most of the tests, one turned into ActiveIssue

* Comments.

* Regenerated ref sources.

* Addressed some feedback.

* Added readme.

* QUIC_ADDRESS_FAMILY
  • Loading branch information
ManickaP committed Mar 26, 2021
1 parent 2bdee5b commit 484a807
Show file tree
Hide file tree
Showing 34 changed files with 1,686 additions and 1,682 deletions.
45 changes: 45 additions & 0 deletions src/libraries/System.Net.Quic/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# MsQuic

`System.Net.Quic` depends on [MsQuic](https://github.com/microsoft/msquic), Microsoft, cross-platform, native implementation of the [QUIC](https://datatracker.ietf.org/wg/quic/about/) protocol.
Currently, `System.Net.Quic` depends on [**msquic@cc104e836a5d4a5e0d324bc08b42136d2acac997**](https://github.com/microsoft/msquic/commit/cc104e836a5d4a5e0d324bc08b42136d2acac997) revision.

## Usage

### Build MsQuic

[MsQuic build docs](https://github.com/microsoft/msquic/blob/main/docs/BUILD.md)

> **Note**: At the moment, we're using stub_tls option to bypass OpenSSL/SChannel, since work with certificates is not fully figured out.
#### Linux
Prerequisites:
- build-essential
- cmake
- lttng-ust
- lttng-tools

`dotnet tool install --global`:
- microsoft.logging.clog
- microsoft.logging.clog2text.lttng


Run inside the msquic directory (for **Debug** build with logging on):
```bash
# build msquic in debug with logging and stub tls
rm -rf build
mkdir build
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DQUIC_ENABLE_LOGGING=on -DQUIC_TLS=stub
cd build
cmake --build . --config Debug

# copy msquic into runtime
yes | cp -rf bin/Debug/libmsquic.* <path-to-runtime>/src/libraries/System.Net.Quic/src/
```

#### Windows
Prerequisites:
- Latest [Windows Insider Builds](https://insider.windows.com/en-us/), Insiders Fast build. This is required for SChannel support for QUIC.
- To confirm you have a new enough build, run winver on command line and confirm you version is greater than Version 2004 (OS Build 20145.1000).

TODO

184 changes: 93 additions & 91 deletions src/libraries/System.Net.Quic/ref/System.Net.Quic.cs

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/libraries/System.Net.Quic/src/System.Net.Quic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<Compile Include="System\Net\Quic\Implementations\Mock\*.cs" />
<Compile Include="System\Net\Quic\Implementations\MsQuic\*.cs" />
<Compile Include="System\Net\Quic\Implementations\MsQuic\Internal\*.cs" />
<Compile Include="System\Net\Quic\Interop\*.cs" />
<Compile Include="System\Net\Quic\Implementations\MsQuic\Interop\*.cs" />
</ItemGroup>
<!-- System.Net common -->
<ItemGroup Condition="'$(TargetsAnyOS)' != 'true'">
Expand Down Expand Up @@ -62,11 +62,15 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="msquic.pdb" Condition="Exists('msquic.pdb')">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="libmsquic.so" Condition="Exists('libmsquic.so')">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="msquic.pdb" Condition="Exists('msquic.pdb')">
<Content Include="libmsquic.lttng.so" Condition="Exists('libmsquic.lttng.so')">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ internal override bool Connected
}

// TODO: Should clone the endpoint since it is mutable
internal override IPEndPoint LocalEndPoint => _localEndPoint;
// TODO: could this be made back to non-nullable?
// For inbound we have it immediately, for outbound after connect.
internal override IPEndPoint? LocalEndPoint => _localEndPoint;

// TODO: Should clone the endpoint since it is mutable
internal override EndPoint RemoteEndPoint => _remoteEndPoint!;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,97 +1,62 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Runtime.InteropServices;
using static System.Net.Quic.Implementations.MsQuic.Internal.MsQuicNativeMethods;

namespace System.Net.Quic.Implementations.MsQuic.Internal
{
internal static class MsQuicParameterHelpers
{
internal static unsafe SOCKADDR_INET GetINetParam(MsQuicApi api, IntPtr nativeObject, uint level, uint param)
internal static unsafe SOCKADDR_INET GetINetParam(MsQuicApi api, SafeHandle nativeObject, QUIC_PARAM_LEVEL level, uint param)
{
byte* ptr = stackalloc byte[sizeof(SOCKADDR_INET)];
QuicBuffer buffer = new QuicBuffer
{
Length = (uint)sizeof(SOCKADDR_INET),
Buffer = ptr
};
SOCKADDR_INET value;
uint valueLen = (uint)sizeof(SOCKADDR_INET);

QuicExceptionHelpers.ThrowIfFailed(
api.UnsafeGetParam(nativeObject, level, param, ref buffer),
"Could not get SOCKADDR_INET.");
uint status = api.GetParamDelegate(nativeObject, level, param, ref valueLen, (byte*)&value);
QuicExceptionHelpers.ThrowIfFailed(status, "GetINETParam failed.");
Debug.Assert(valueLen == sizeof(SOCKADDR_INET));

return *(SOCKADDR_INET*)ptr;
return value;
}

internal static unsafe ushort GetUShortParam(MsQuicApi api, IntPtr nativeObject, uint level, uint param)
internal static unsafe ushort GetUShortParam(MsQuicApi api, SafeHandle nativeObject, QUIC_PARAM_LEVEL level, uint param)
{
byte* ptr = stackalloc byte[sizeof(ushort)];
QuicBuffer buffer = new QuicBuffer()
{
Length = sizeof(ushort),
Buffer = ptr
};
ushort value;
uint valueLen = (uint)sizeof(ushort);

QuicExceptionHelpers.ThrowIfFailed(
api.UnsafeGetParam(nativeObject, level, param, ref buffer),
"Could not get ushort.");
uint status = api.GetParamDelegate(nativeObject, level, param, ref valueLen, (byte*)&value);
QuicExceptionHelpers.ThrowIfFailed(status, "GetUShortParam failed.");
Debug.Assert(valueLen == sizeof(ushort));

return *(ushort*)ptr;
return value;
}

internal static unsafe void SetUshortParam(MsQuicApi api, IntPtr nativeObject, uint level, uint param, ushort value)
internal static unsafe void SetUShortParam(MsQuicApi api, SafeHandle nativeObject, QUIC_PARAM_LEVEL level, uint param, ushort value)
{
QuicBuffer buffer = new QuicBuffer()
{
Length = sizeof(ushort),
Buffer = (byte*)&value
};

QuicExceptionHelpers.ThrowIfFailed(
api.UnsafeSetParam(nativeObject, level, param, buffer),
api.SetParamDelegate(nativeObject, level, param, sizeof(ushort), (byte*)&value),
"Could not set ushort.");
}

internal static unsafe ulong GetULongParam(MsQuicApi api, IntPtr nativeObject, uint level, uint param)
internal static unsafe ulong GetULongParam(MsQuicApi api, SafeHandle nativeObject, QUIC_PARAM_LEVEL level, uint param)
{
byte* ptr = stackalloc byte[sizeof(ulong)];
QuicBuffer buffer = new QuicBuffer()
{
Length = sizeof(ulong),
Buffer = ptr
};
ulong value;
uint valueLen = (uint)sizeof(ulong);

QuicExceptionHelpers.ThrowIfFailed(
api.UnsafeGetParam(nativeObject, level, param, ref buffer),
"Could not get ulong.");
uint status = api.GetParamDelegate(nativeObject, level, param, ref valueLen, (byte*)&value);
QuicExceptionHelpers.ThrowIfFailed(status, "GetULongParam failed.");
Debug.Assert(valueLen == sizeof(ulong));

return *(ulong*)ptr;
return value;
}

internal static unsafe void SetULongParam(MsQuicApi api, IntPtr nativeObject, uint level, uint param, ulong value)
internal static unsafe void SetULongParam(MsQuicApi api, SafeHandle nativeObject, QUIC_PARAM_LEVEL level, uint param, ulong value)
{
QuicBuffer buffer = new QuicBuffer()
{
Length = sizeof(ulong),
Buffer = (byte*)&value
};

QuicExceptionHelpers.ThrowIfFailed(
api.UnsafeGetParam(nativeObject, level, param, ref buffer),
api.SetParamDelegate(nativeObject, level, param, sizeof(ulong), (byte*)&value),
"Could not set ulong.");
}

internal static unsafe void SetSecurityConfig(MsQuicApi api, IntPtr nativeObject, uint level, uint param, IntPtr value)
{
QuicBuffer buffer = new QuicBuffer()
{
Length = (uint)sizeof(void*),
Buffer = (byte*)&value
};

QuicExceptionHelpers.ThrowIfFailed(
api.UnsafeSetParam(nativeObject, level, param, buffer),
"Could not set security configuration.");
}
}
}

This file was deleted.

Loading

0 comments on commit 484a807

Please sign in to comment.