-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Initial port of MsQuic transport #15375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
790512f
Code port
jkotalik 7118d77
Features
jkotalik 74005c5
Remove copy task for now
jkotalik b91dfdc
ref assemblies
jkotalik d94e916
project reference
jkotalik c1106d5
Feedback and sample
jkotalik 9e8f3dd
Just the API for now
jkotalik 9a3de3f
oops
jkotalik 2b30243
Internals
jkotalik a3df14d
ref assemblies
jkotalik 0c8e585
Some feedback
jkotalik 30df2d6
different enums for different platforms
jkotalik 4ab3bad
New constants file
jkotalik 2169112
New file
jkotalik 142b36e
Remove translation
jkotalik f27e1b0
layout to remove warning
jkotalik 366f9e8
Update locations
jkotalik 55d73ac
Update refs
jkotalik bf67055
Update enums
jkotalik 5ee9554
Feedback
jkotalik 6b00048
Ideas
jkotalik 445153a
Feedback
jkotalik 002b42f
Update src/Servers/Kestrel/Transport.MsQuic/src/Internal/MsQuicStatus…
jkotalik a274fa0
Update src/Servers/Kestrel/Transport.MsQuic/src/Internal/MsQuicConsta…
jkotalik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## Using MsQuic on Windows | ||
|
||
### Setup pre-requisites | ||
|
||
1. Update machine to the latest Windows Insiders build (build number 19010 or later). This is required for TLS 1.3 support. | ||
2. Copy msquic.dll and msquic.pdb to this directory and uncomment the copy task in Microsoft.AspNetCore.Server.Kestrel.Transport.MsQuic.csproj. This will copy the msquic.dll into any built project. | ||
|
||
For external contributors, msquic.dll isn't available publicly yet. See https://github.com/aspnet/Announcements/issues/393. | ||
|
||
Credit to Diwakar Mantha and the Kaizala team for the MsQuic interop code. |
13 changes: 13 additions & 0 deletions
13
.../Kestrel/Transport.MsQuic/ref/Microsoft.AspNetCore.Server.Kestrel.Transport.MsQuic.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- This file is automatically generated. --> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>$(DefaultNetCoreTargetFramework)</TargetFrameworks> | ||
</PropertyGroup> | ||
<ItemGroup Condition="'$(TargetFramework)' == '$(DefaultNetCoreTargetFramework)'"> | ||
<Compile Include="Microsoft.AspNetCore.Server.Kestrel.Transport.MsQuic.netcoreapp.cs" /> | ||
<Reference Include="Microsoft.AspNetCore.Hosting.Abstractions" /> | ||
<Reference Include="Microsoft.AspNetCore.Connections.Abstractions" /> | ||
<Reference Include="Microsoft.Extensions.Logging.Abstractions" /> | ||
<Reference Include="Microsoft.Extensions.Options" /> | ||
</ItemGroup> | ||
</Project> |
3 changes: 3 additions & 0 deletions
3
...l/Transport.MsQuic/ref/Microsoft.AspNetCore.Server.Kestrel.Transport.MsQuic.netcoreapp.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
186 changes: 186 additions & 0 deletions
186
src/Servers/Kestrel/Transport.MsQuic/src/Internal/MsQuicApi.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.MsQuic.Internal | ||
{ | ||
internal class MsQuicApi : IDisposable | ||
{ | ||
private bool _disposed = false; | ||
|
||
private IntPtr _registrationContext; | ||
|
||
internal unsafe MsQuicApi() | ||
{ | ||
var status = (uint)MsQuicNativeMethods.MsQuicOpen(version: 1, out var registration); | ||
MsQuicStatusException.ThrowIfFailed(status); | ||
|
||
NativeRegistration = *registration; | ||
|
||
RegistrationOpenDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.RegistrationOpenDelegate>( | ||
NativeRegistration.RegistrationOpen); | ||
RegistrationCloseDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.RegistrationCloseDelegate>( | ||
NativeRegistration.RegistrationClose); | ||
|
||
SecConfigCreateDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.SecConfigCreateDelegate>( | ||
NativeRegistration.SecConfigCreate); | ||
SecConfigDeleteDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.SecConfigDeleteDelegate>( | ||
NativeRegistration.SecConfigDelete); | ||
|
||
SessionOpenDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.SessionOpenDelegate>( | ||
NativeRegistration.SessionOpen); | ||
SessionCloseDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.SessionCloseDelegate>( | ||
NativeRegistration.SessionClose); | ||
SessionShutdownDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.SessionShutdownDelegate>( | ||
NativeRegistration.SessionShutdown); | ||
|
||
ListenerOpenDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.ListenerOpenDelegate>( | ||
NativeRegistration.ListenerOpen); | ||
ListenerCloseDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.ListenerCloseDelegate>( | ||
NativeRegistration.ListenerClose); | ||
ListenerStartDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.ListenerStartDelegate>( | ||
NativeRegistration.ListenerStart); | ||
ListenerStopDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.ListenerStopDelegate>( | ||
NativeRegistration.ListenerStop); | ||
|
||
ConnectionOpenDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.ConnectionOpenDelegate>( | ||
NativeRegistration.ConnectionOpen); | ||
ConnectionCloseDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.ConnectionCloseDelegate>( | ||
NativeRegistration.ConnectionClose); | ||
ConnectionShutdownDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.ConnectionShutdownDelegate>( | ||
NativeRegistration.ConnectionShutdown); | ||
ConnectionStartDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.ConnectionStartDelegate>( | ||
NativeRegistration.ConnectionStart); | ||
|
||
StreamOpenDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.StreamOpenDelegate>( | ||
NativeRegistration.StreamOpen); | ||
StreamCloseDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.StreamCloseDelegate>( | ||
NativeRegistration.StreamClose); | ||
StreamStartDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.StreamStartDelegate>( | ||
NativeRegistration.StreamStart); | ||
StreamShutdownDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.StreamShutdownDelegate>( | ||
NativeRegistration.StreamShutdown); | ||
StreamSendDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.StreamSendDelegate>( | ||
NativeRegistration.StreamSend); | ||
|
||
SetContextDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.SetContextDelegate>( | ||
NativeRegistration.SetContext); | ||
GetContextDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.GetContextDelegate>( | ||
NativeRegistration.GetContext); | ||
SetCallbackHandlerDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.SetCallbackHandlerDelegate>( | ||
NativeRegistration.SetCallbackHandler); | ||
|
||
SetParamDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.SetParamDelegate>( | ||
NativeRegistration.SetParam); | ||
GetParamDelegate = | ||
Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.GetParamDelegate>( | ||
NativeRegistration.GetParam); | ||
} | ||
|
||
internal MsQuicNativeMethods.NativeApi NativeRegistration { get; private set; } | ||
|
||
internal MsQuicNativeMethods.RegistrationOpenDelegate RegistrationOpenDelegate { get; private set; } | ||
internal MsQuicNativeMethods.RegistrationCloseDelegate RegistrationCloseDelegate { get; private set; } | ||
|
||
internal MsQuicNativeMethods.SecConfigCreateDelegate SecConfigCreateDelegate { get; private set; } | ||
internal MsQuicNativeMethods.SecConfigCreateCompleteDelegate SecConfigCreateCompleteDelegate { get; private set; } | ||
internal MsQuicNativeMethods.SecConfigDeleteDelegate SecConfigDeleteDelegate { get; private set; } | ||
|
||
internal MsQuicNativeMethods.SessionOpenDelegate SessionOpenDelegate { get; private set; } | ||
internal MsQuicNativeMethods.SessionCloseDelegate SessionCloseDelegate { get; private set; } | ||
internal MsQuicNativeMethods.SessionShutdownDelegate SessionShutdownDelegate { get; private set; } | ||
|
||
internal MsQuicNativeMethods.ListenerOpenDelegate ListenerOpenDelegate { get; private set; } | ||
internal MsQuicNativeMethods.ListenerCloseDelegate ListenerCloseDelegate { get; private set; } | ||
internal MsQuicNativeMethods.ListenerStartDelegate ListenerStartDelegate { get; private set; } | ||
internal MsQuicNativeMethods.ListenerStopDelegate ListenerStopDelegate { get; private set; } | ||
|
||
internal MsQuicNativeMethods.ConnectionOpenDelegate ConnectionOpenDelegate { get; private set; } | ||
internal MsQuicNativeMethods.ConnectionCloseDelegate ConnectionCloseDelegate { get; private set; } | ||
internal MsQuicNativeMethods.ConnectionShutdownDelegate ConnectionShutdownDelegate { get; private set; } | ||
internal MsQuicNativeMethods.ConnectionStartDelegate ConnectionStartDelegate { get; private set; } | ||
|
||
internal MsQuicNativeMethods.StreamOpenDelegate StreamOpenDelegate { get; private set; } | ||
internal MsQuicNativeMethods.StreamCloseDelegate StreamCloseDelegate { get; private set; } | ||
internal MsQuicNativeMethods.StreamStartDelegate StreamStartDelegate { get; private set; } | ||
internal MsQuicNativeMethods.StreamShutdownDelegate StreamShutdownDelegate { get; private set; } | ||
internal MsQuicNativeMethods.StreamSendDelegate StreamSendDelegate { get; private set; } | ||
internal MsQuicNativeMethods.StreamReceiveCompleteDelegate StreamReceiveComplete { get; private set; } | ||
|
||
internal MsQuicNativeMethods.SetContextDelegate SetContextDelegate { get; private set; } | ||
internal MsQuicNativeMethods.GetContextDelegate GetContextDelegate { get; private set; } | ||
internal MsQuicNativeMethods.SetCallbackHandlerDelegate SetCallbackHandlerDelegate { get; private set; } | ||
|
||
internal MsQuicNativeMethods.SetParamDelegate SetParamDelegate { get; private set; } | ||
internal MsQuicNativeMethods.GetParamDelegate GetParamDelegate { get; private set; } | ||
|
||
internal void RegistrationOpen(byte[] name) | ||
{ | ||
MsQuicStatusException.ThrowIfFailed(RegistrationOpenDelegate(name, out var ctx)); | ||
_registrationContext = ctx; | ||
} | ||
|
||
internal unsafe uint UnsafeSetParam( | ||
IntPtr Handle, | ||
uint Level, | ||
uint Param, | ||
MsQuicNativeMethods.QuicBuffer Buffer) | ||
{ | ||
return SetParamDelegate( | ||
Handle, | ||
Level, | ||
Param, | ||
Buffer.Length, | ||
Buffer.Buffer); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Dispose(disposing: true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
~MsQuicApi() | ||
{ | ||
Dispose(disposing: false); | ||
} | ||
|
||
private void Dispose(bool disposing) | ||
{ | ||
if (_disposed) | ||
{ | ||
return; | ||
} | ||
|
||
RegistrationCloseDelegate?.Invoke(_registrationContext); | ||
|
||
_disposed = true; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.