Skip to content
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

Initial port of MsQuic transport #15375

Merged
merged 24 commits into from
Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eng/ProjectReferences.props
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Server.Kestrel.Core" ProjectPath="$(RepoRoot)src\Servers\Kestrel\Core\src\Microsoft.AspNetCore.Server.Kestrel.Core.csproj" RefProjectPath="$(RepoRoot)src\Servers\Kestrel\Core\ref\Microsoft.AspNetCore.Server.Kestrel.Core.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Server.Kestrel" ProjectPath="$(RepoRoot)src\Servers\Kestrel\Kestrel\src\Microsoft.AspNetCore.Server.Kestrel.csproj" RefProjectPath="$(RepoRoot)src\Servers\Kestrel\Kestrel\ref\Microsoft.AspNetCore.Server.Kestrel.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv" ProjectPath="$(RepoRoot)src\Servers\Kestrel\Transport.Libuv\src\Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj" RefProjectPath="$(RepoRoot)src\Servers\Kestrel\Transport.Libuv\ref\Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Server.Kestrel.Transport.MsQuic" ProjectPath="$(RepoRoot)src\Servers\Kestrel\Transport.MsQuic\src\Microsoft.AspNetCore.Server.Kestrel.Transport.MsQuic.csproj" RefProjectPath="$(RepoRoot)src\Servers\Kestrel\Transport.MsQuic\ref\Microsoft.AspNetCore.Server.Kestrel.Transport.MsQuic.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets" ProjectPath="$(RepoRoot)src\Servers\Kestrel\Transport.Sockets\src\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj" RefProjectPath="$(RepoRoot)src\Servers\Kestrel\Transport.Sockets\ref\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Authentication.Certificate" ProjectPath="$(RepoRoot)src\Security\Authentication\Certificate\src\Microsoft.AspNetCore.Authentication.Certificate.csproj" RefProjectPath="$(RepoRoot)src\Security\Authentication\Certificate\ref\Microsoft.AspNetCore.Authentication.Certificate.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Authentication.Cookies" ProjectPath="$(RepoRoot)src\Security\Authentication\Cookies\src\Microsoft.AspNetCore.Authentication.Cookies.csproj" RefProjectPath="$(RepoRoot)src\Security\Authentication\Cookies\ref\Microsoft.AspNetCore.Authentication.Cookies.csproj" />
Expand Down
15 changes: 15 additions & 0 deletions src/Servers/Kestrel/Kestrel.sln
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.WebUti
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "http2cat", "samples\http2cat\http2cat.csproj", "{3D6821F5-F242-4828-8DDE-89488E85512D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Transport.MsQuic", "Transport.MsQuic\src\Microsoft.AspNetCore.Server.Kestrel.Transport.MsQuic.csproj", "{1BC94F37-AF61-4641-A80A-EC32A15C5344}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -466,6 +468,18 @@ Global
{3D6821F5-F242-4828-8DDE-89488E85512D}.Release|x64.Build.0 = Release|Any CPU
{3D6821F5-F242-4828-8DDE-89488E85512D}.Release|x86.ActiveCfg = Release|Any CPU
{3D6821F5-F242-4828-8DDE-89488E85512D}.Release|x86.Build.0 = Release|Any CPU
{1BC94F37-AF61-4641-A80A-EC32A15C5344}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1BC94F37-AF61-4641-A80A-EC32A15C5344}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1BC94F37-AF61-4641-A80A-EC32A15C5344}.Debug|x64.ActiveCfg = Debug|Any CPU
{1BC94F37-AF61-4641-A80A-EC32A15C5344}.Debug|x64.Build.0 = Debug|Any CPU
{1BC94F37-AF61-4641-A80A-EC32A15C5344}.Debug|x86.ActiveCfg = Debug|Any CPU
{1BC94F37-AF61-4641-A80A-EC32A15C5344}.Debug|x86.Build.0 = Debug|Any CPU
{1BC94F37-AF61-4641-A80A-EC32A15C5344}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1BC94F37-AF61-4641-A80A-EC32A15C5344}.Release|Any CPU.Build.0 = Release|Any CPU
{1BC94F37-AF61-4641-A80A-EC32A15C5344}.Release|x64.ActiveCfg = Release|Any CPU
{1BC94F37-AF61-4641-A80A-EC32A15C5344}.Release|x64.Build.0 = Release|Any CPU
{1BC94F37-AF61-4641-A80A-EC32A15C5344}.Release|x86.ActiveCfg = Release|Any CPU
{1BC94F37-AF61-4641-A80A-EC32A15C5344}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -503,6 +517,7 @@ Global
{E0AD50A3-2518-4060-8BB9-5649B04B3A6D} = {F0A1281A-B512-49D2-8362-21EE32B3674F}
{EE45763C-753D-4228-8E5D-A71F8BDB3D89} = {F0A1281A-B512-49D2-8362-21EE32B3674F}
{3D6821F5-F242-4828-8DDE-89488E85512D} = {F826BA61-60A9-45B6-AF29-FD1A6E313EF0}
{1BC94F37-AF61-4641-A80A-EC32A15C5344} = {2B456D08-F72B-4EB8-B663-B6D78FC04BF8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {48207B50-7D05-4B10-B585-890FE0F4FCE1}
Expand Down
10 changes: 10 additions & 0 deletions src/Servers/Kestrel/Transport.MsQuic/README.md
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.
jkotalik marked this conversation as resolved.
Show resolved Hide resolved

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.
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>
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 src/Servers/Kestrel/Transport.MsQuic/src/Internal/MsQuicApi.cs
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;
}
}
}
Loading