- Notifications
You must be signed in to change notification settings - Fork3
fix: various fixes for tunnel startup to work#14
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
5 commits Select commitHold shift + click to select a range
990a970
fix: various fixes for tunnel startup to work
deansheather07d0892
PR comments
deansheather667cdaa
Merge branch 'main' into dean/debug-client
deansheather4eacfea
fixup! Merge branch 'main' into dean/debug-client
deansheather0f5410a
fixup! Merge branch 'main' into dean/debug-client
deansheatherFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
18 changes: 18 additions & 0 deletionsCoder.Desktop.sln
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
21 changes: 2 additions & 19 deletionsCoder.Desktop.sln.DotSettings
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
45 changes: 45 additions & 0 deletionsTests.Vpn.Service/packages.lock.json
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
128 changes: 128 additions & 0 deletionsVpn.DebugClient/Program.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,128 @@ | ||
using System.IO.Pipes; | ||
using Coder.Desktop.Vpn.Proto; | ||
namespace Coder.Desktop.Vpn.DebugClient; | ||
public static class Program | ||
{ | ||
private static Speaker<ClientMessage, ServiceMessage>? _speaker; | ||
private static string? _coderUrl; | ||
private static string? _apiToken; | ||
public static void Main() | ||
{ | ||
Console.WriteLine("Type 'exit' to exit the program"); | ||
Console.WriteLine("Type 'connect' to connect to the service"); | ||
Console.WriteLine("Type 'disconnect' to disconnect from the service"); | ||
Console.WriteLine("Type 'configure' to set the parameters"); | ||
Console.WriteLine("Type 'start' to send a start command with the current parameters"); | ||
Console.WriteLine("Type 'stop' to send a stop command"); | ||
while (true) | ||
{ | ||
Console.Write("> "); | ||
var input = Console.ReadLine()?.Trim(); | ||
try | ||
{ | ||
switch (input) | ||
{ | ||
case "exit": | ||
return; | ||
case "connect": | ||
Connect(); | ||
break; | ||
case "disconnect": | ||
Disconnect(); | ||
break; | ||
case "configure": | ||
Configure(); | ||
break; | ||
case "start": | ||
Start(); | ||
break; | ||
case "stop": | ||
Stop(); | ||
break; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine($"Error: {ex}"); | ||
} | ||
} | ||
} | ||
private static void Connect() | ||
{ | ||
var client = new NamedPipeClientStream(".", "Coder.Desktop.Vpn", PipeDirection.InOut, PipeOptions.Asynchronous); | ||
client.Connect(); | ||
Console.WriteLine("Connected to named pipe."); | ||
_speaker = new Speaker<ClientMessage, ServiceMessage>(client); | ||
_speaker.Receive += message => { Console.WriteLine($"Received({message.Message.MsgCase}: {message.Message}"); }; | ||
_speaker.Error += exception => | ||
{ | ||
Console.WriteLine($"Error: {exception}"); | ||
Disconnect(); | ||
}; | ||
_speaker.StartAsync().Wait(); | ||
Console.WriteLine("Speaker started."); | ||
} | ||
private static void Disconnect() | ||
{ | ||
_speaker?.DisposeAsync().AsTask().Wait(); | ||
_speaker = null; | ||
Console.WriteLine("Disconnected from named pipe"); | ||
} | ||
private static void Configure() | ||
{ | ||
Console.Write("Coder URL: "); | ||
_coderUrl = Console.ReadLine()?.Trim(); | ||
Console.Write("API Token: "); | ||
_apiToken = Console.ReadLine()?.Trim(); | ||
} | ||
private static void Start() | ||
{ | ||
if (_speaker is null) | ||
{ | ||
Console.WriteLine("Not connected to Coder.Desktop.Vpn."); | ||
return; | ||
} | ||
var message = new ClientMessage | ||
{ | ||
Start = new StartRequest | ||
{ | ||
CoderUrl = _coderUrl, | ||
ApiToken = _apiToken, | ||
}, | ||
}; | ||
Console.WriteLine("Sending start message..."); | ||
var sendTask = _speaker.SendRequestAwaitReply(message).AsTask(); | ||
Console.WriteLine("Start message sent, awaiting reply."); | ||
sendTask.Wait(); | ||
Console.WriteLine($"Received reply: {sendTask.Result.Message}"); | ||
} | ||
private static void Stop() | ||
{ | ||
if (_speaker is null) | ||
{ | ||
Console.WriteLine("Not connected to Coder.Desktop.Vpn."); | ||
return; | ||
} | ||
var message = new ClientMessage | ||
{ | ||
Stop = new StopRequest(), | ||
}; | ||
Console.WriteLine("Sending stop message..."); | ||
var sendTask = _speaker.SendRequestAwaitReply(message); | ||
Console.WriteLine("Stop message sent, awaiting reply."); | ||
var reply = sendTask.AsTask().Result; | ||
Console.WriteLine($"Received reply: {reply.Message}"); | ||
} | ||
} |
17 changes: 17 additions & 0 deletionsVpn.DebugClient/Vpn.DebugClient.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,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<RootNamespace>Coder.Desktop.Vpn.DebugClient</RootNamespace> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Vpn\Vpn.csproj"/> | ||
<ProjectReference Include="..\Vpn.Proto\Vpn.Proto.csproj"/> | ||
</ItemGroup> | ||
</Project> |
30 changes: 30 additions & 0 deletionsVpn.DebugClient/packages.lock.json
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,30 @@ | ||
{ | ||
"version": 1, | ||
"dependencies": { | ||
"net8.0": { | ||
"Google.Protobuf": { | ||
"type": "Transitive", | ||
"resolved": "3.29.3", | ||
"contentHash": "t7nZFFUFwigCwZ+nIXHDLweXvwIpsOXi+P7J7smPT/QjI3EKxnCzTQOhBqyEh6XEzc/pNH+bCFOOSjatrPt6Tw==" | ||
}, | ||
"System.IO.Pipelines": { | ||
"type": "Transitive", | ||
"resolved": "9.0.1", | ||
"contentHash": "uXf5o8eV/gtzDQY4lGROLFMWQvcViKcF8o4Q6KpIOjloAQXrnscQSu6gTxYJMHuNJnh7szIF9AzkaEq+zDLoEg==" | ||
}, | ||
"vpn": { | ||
"type": "Project", | ||
"dependencies": { | ||
"System.IO.Pipelines": "[9.0.1, )", | ||
"Vpn.Proto": "[1.0.0, )" | ||
} | ||
}, | ||
"vpn.proto": { | ||
"type": "Project", | ||
"dependencies": { | ||
"Google.Protobuf": "[3.29.3, )" | ||
} | ||
} | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletionsVpn.Service/Create-Service.ps1
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,35 @@ | ||
# Elevate to administrator | ||
if (-not ([Security.Principal.WindowsPrincipal]([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { | ||
Write-Host "Elevating script to run as administrator..." | ||
Start-Process powershell.exe -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$($MyInvocation.MyCommand.Path)`"" -Verb RunAs | ||
exit | ||
} | ||
$name = "Coder Desktop (Debug)" | ||
$binaryPath = Join-Path -Path $PSScriptRoot -ChildPath "bin/Debug/net8.0-windows/Vpn.Service.exe" | ||
try { | ||
Write-Host "Creating service..." | ||
New-Service -Name $name -BinaryPathName "`"$binaryPath`"" -DisplayName $name -StartupType Automatic | ||
$sddl = & sc.exe sdshow $name | ||
if (-not $sddl) { | ||
throw "Failed to retrieve security descriptor for service '$name'" | ||
} | ||
Write-Host "Current security descriptor: '$sddl'" | ||
$sddl = $sddl.Trim() -replace "D:", "D:(A;;RPWP;;;WD)" # allow everyone to start, stop, pause, and query the service | ||
Write-Host "Setting security descriptor: '$sddl'" | ||
& sc.exe sdset $name $sddl | ||
Write-Host "Starting service..." | ||
Start-Service -Name $name | ||
if ((Get-Service -Name $name -ErrorAction Stop).Status -ne "Running") { | ||
throw "Service '$name' is not running" | ||
} | ||
Write-Host "Service '$name' created and started successfully" | ||
} catch { | ||
Write-Host $_ -ForegroundColor Red | ||
Write-Host "Press Return to exit..." | ||
Read-Host | ||
} |
18 changes: 18 additions & 0 deletionsVpn.Service/Delete-Service.ps1
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,18 @@ | ||
# Elevate to administrator | ||
if (-not ([Security.Principal.WindowsPrincipal]([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { | ||
Write-Host "Elevating script to run as administrator..." | ||
Start-Process powershell.exe -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$($MyInvocation.MyCommand.Path)`"" -Verb RunAs | ||
exit | ||
} | ||
$name = "Coder Desktop (Debug)" | ||
try { | ||
Stop-Service -Name $name -Force -ErrorAction SilentlyContinue | ||
sc.exe delete $name | ||
Write-Host "Service '$name' deleted" | ||
} catch { | ||
Write-Host $_ -ForegroundColor Red | ||
Write-Host "Press Return to exit..." | ||
Read-Host | ||
} |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
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.