Skip to content

Commit

Permalink
Remove hardcoded endpoint (#4657)
Browse files Browse the repository at this point in the history
* Remove string hardcoding

* delete MsQuicTool

* delete pipeline which runs MsQuicTool

* Revert "delete pipeline which runs MsQuicTool"

This reverts commit 1264b21.

* Revert "delete MsQuicTool"

This reverts commit dfa4d72.

* DomainName as command line parameter
  • Loading branch information
ami-GS authored Nov 19, 2024
1 parent 434e533 commit f6b6e01
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ jobs:
dotnet-version: 6.0.x
- name: Run Lang Interop
shell: pwsh
run: scripts/DotNetTest.ps1 -Config Debug -Arch ${{ matrix.vec.arch }} -Tls ${{ matrix.vec.tls }}
run: scripts/DotNetTest.ps1 -Config Debug -Arch ${{ matrix.vec.arch }} -Tls ${{ matrix.vec.tls }} -DomainName "google.com"
7 changes: 5 additions & 2 deletions scripts/DotNetTest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ param (
[string]$Tls = "",

[Parameter(Mandatory = $false)]
[string]$ExtraArtifactDir = ""
[string]$ExtraArtifactDir = "",

[Parameter(Mandatory = $true)]
[string]$DomainName = ""
)

Set-StrictMode -Version 'Latest'
Expand All @@ -43,4 +46,4 @@ if ($IsWindows) {
$RootDir = Split-Path $PSScriptRoot -Parent

dotnet build (Join-Path $RootDir src cs)
dotnet run --project (Join-Path $RootDir src cs tool) -- (Join-Path $RootArtifactDir $LibName)
dotnet run --project (Join-Path $RootDir src cs tool) -- $DomainName (Join-Path $RootArtifactDir $LibName)
26 changes: 23 additions & 3 deletions src/cs/tool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,32 @@ static unsafe void Main(string[] args)
{
// This code lets us pass in an argument of where to search for the library at.
// Very helpful for testing
if (args.Length > 0)
if (args.Length == 0)
{
Console.WriteLine("Usage: MsQuicTool <DomainName> [PathToMsQuic]");
return;
}

string DomainName = args[0];

if (string.IsNullOrWhiteSpace(DomainName))
{
Console.WriteLine("DomainName cannot be empty.");
return;
}

if (DomainName.Length > 253)
{
Console.WriteLine("DomainName is too long.");
return;
}

if (args.Length > 1)
{
NativeLibrary.SetDllImportResolver(typeof(MsQuic).Assembly, (libraryName, assembly, searchPath) =>
{
if (libraryName != "msquic") return IntPtr.Zero;
if (NativeLibrary.TryLoad(args[0], out var ptr))
if (NativeLibrary.TryLoad(args[1], out var ptr))
{
return ptr;
}
Expand Down Expand Up @@ -55,7 +75,7 @@ static unsafe void Main(string[] args)
MsQuic.ThrowIfFailure(ApiTable->ConfigurationLoadCredential(configuration, &config));
MsQuic.ThrowIfFailure(ApiTable->ConnectionOpen(registration, &NativeCallback, ApiTable, &connection));
sbyte* google = stackalloc sbyte[50];
int written = Encoding.UTF8.GetBytes("google.com", new Span<byte>(google, 50));
int written = Encoding.UTF8.GetBytes(DomainName, new Span<byte>(google, 50));
google[written] = 0;
MsQuic.ThrowIfFailure(ApiTable->ConnectionStart(connection, configuration, 0, google, 443));
Thread.Sleep(1000);
Expand Down

0 comments on commit f6b6e01

Please sign in to comment.