Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
deansheather merged 5 commits intomainfromdean/debug-client
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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
18 changes: 18 additions & 0 deletionsCoder.Desktop.sln
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoderSdk", "CoderSdk\CoderS
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "App", "App\App.csproj", "{800C7E2D-0D86-4554-9903-B879DA6FA2CE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vpn.DebugClient", "Vpn.DebugClient\Vpn.DebugClient.csproj", "{1BBFDF88-B25F-4C07-99C2-30DA384DB730}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand DownExpand Up@@ -167,6 +169,22 @@ Global
{800C7E2D-0D86-4554-9903-B879DA6FA2CE}.Release|x86.ActiveCfg = Release|x86
{800C7E2D-0D86-4554-9903-B879DA6FA2CE}.Release|x86.Build.0 = Release|x86
{800C7E2D-0D86-4554-9903-B879DA6FA2CE}.Release|x86.Deploy.0 = Release|x86
{1BBFDF88-B25F-4C07-99C2-30DA384DB730}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1BBFDF88-B25F-4C07-99C2-30DA384DB730}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1BBFDF88-B25F-4C07-99C2-30DA384DB730}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{1BBFDF88-B25F-4C07-99C2-30DA384DB730}.Debug|ARM64.Build.0 = Debug|Any CPU
{1BBFDF88-B25F-4C07-99C2-30DA384DB730}.Debug|x64.ActiveCfg = Debug|Any CPU
{1BBFDF88-B25F-4C07-99C2-30DA384DB730}.Debug|x64.Build.0 = Debug|Any CPU
{1BBFDF88-B25F-4C07-99C2-30DA384DB730}.Debug|x86.ActiveCfg = Debug|Any CPU
{1BBFDF88-B25F-4C07-99C2-30DA384DB730}.Debug|x86.Build.0 = Debug|Any CPU
{1BBFDF88-B25F-4C07-99C2-30DA384DB730}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1BBFDF88-B25F-4C07-99C2-30DA384DB730}.Release|Any CPU.Build.0 = Release|Any CPU
{1BBFDF88-B25F-4C07-99C2-30DA384DB730}.Release|ARM64.ActiveCfg = Release|Any CPU
{1BBFDF88-B25F-4C07-99C2-30DA384DB730}.Release|ARM64.Build.0 = Release|Any CPU
{1BBFDF88-B25F-4C07-99C2-30DA384DB730}.Release|x64.ActiveCfg = Release|Any CPU
{1BBFDF88-B25F-4C07-99C2-30DA384DB730}.Release|x64.Build.0 = Release|Any CPU
{1BBFDF88-B25F-4C07-99C2-30DA384DB730}.Release|x86.ActiveCfg = Release|Any CPU
{1BBFDF88-B25F-4C07-99C2-30DA384DB730}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
21 changes: 2 additions & 19 deletionsCoder.Desktop.sln.DotSettings
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,7 +30,7 @@
</HasMember>
</And>
</TypePattern.Match>

<Entry DisplayName="Fields">
<Entry.Match>
<And>
Expand DownExpand Up@@ -144,10 +144,6 @@
<Kind Is="Delegate" />
</And>
</Entry.Match>

<Entry.SortBy>
<Name />
</Entry.SortBy>
</Entry>

<Entry DisplayName="Public Enums" Priority="100">
Expand All@@ -157,10 +153,6 @@
<Kind Is="Enum" />
</And>
</Entry.Match>

<Entry.SortBy>
<Name />
</Entry.SortBy>
</Entry>

<Entry DisplayName="Static Fields and Constants">
Expand DownExpand Up@@ -193,21 +185,12 @@
</Not>
</And>
</Entry.Match>

<Entry.SortBy>
<Readonly />
<Name />
</Entry.SortBy>
</Entry>

<Entry DisplayName="Events">
<Entry.Match>
<Kind Is="Event" />
</Entry.Match>

<Entry.SortBy>
<Name />
</Entry.SortBy>
</Entry>

<Entry DisplayName="Constructors">
Expand DownExpand Up@@ -256,4 +239,4 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=codervpn/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=hkey/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=replyable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=serdes/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/UserDictionary/Words/=serdes/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
45 changes: 45 additions & 0 deletionsTests.Vpn.Service/packages.lock.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -383,6 +383,48 @@
"Microsoft.Extensions.Primitives": "5.0.1"
}
},
"Serilog": {
"type": "Transitive",
"resolved": "4.2.0",
"contentHash": "gmoWVOvKgbME8TYR+gwMf7osROiWAURterc6Rt2dQyX7wtjZYpqFiA/pY6ztjGQKKV62GGCyOcmtP1UKMHgSmA=="
},
"Serilog.Extensions.Hosting": {
"type": "Transitive",
"resolved": "9.0.0",
"contentHash": "u2TRxuxbjvTAldQn7uaAwePkWxTHIqlgjelekBtilAGL5sYyF3+65NWctN4UrwwGLsDC7c3Vz3HnOlu+PcoxXg==",
"dependencies": {
"Microsoft.Extensions.DependencyInjection.Abstractions": "9.0.0",
"Microsoft.Extensions.Hosting.Abstractions": "9.0.0",
"Microsoft.Extensions.Logging.Abstractions": "9.0.0",
"Serilog": "4.2.0",
"Serilog.Extensions.Logging": "9.0.0"
}
},
"Serilog.Extensions.Logging": {
"type": "Transitive",
"resolved": "9.0.0",
"contentHash": "NwSSYqPJeKNzl5AuXVHpGbr6PkZJFlNa14CdIebVjK3k/76kYj/mz5kiTRNVSsSaxM8kAIa1kpy/qyT9E4npRQ==",
"dependencies": {
"Microsoft.Extensions.Logging": "9.0.0",
"Serilog": "4.2.0"
}
},
"Serilog.Sinks.Console": {
"type": "Transitive",
"resolved": "6.0.0",
"contentHash": "fQGWqVMClCP2yEyTXPIinSr5c+CBGUvBybPxjAGcf7ctDhadFhrQw03Mv8rJ07/wR5PDfFjewf2LimvXCDzpbA==",
"dependencies": {
"Serilog": "4.0.0"
}
},
"Serilog.Sinks.File": {
"type": "Transitive",
"resolved": "6.0.0",
"contentHash": "lxjg89Y8gJMmFxVkbZ+qDgjl+T4yC5F7WSLTvA+5q0R04tfKVLRL/EHpYoJ/MEQd2EeCKDuylBIVnAYMotmh2A==",
"dependencies": {
"Serilog": "4.0.0"
}
},
"System.Diagnostics.DiagnosticSource": {
"type": "Transitive",
"resolved": "9.0.1",
Expand DownExpand Up@@ -450,6 +492,9 @@
"Microsoft.Extensions.Options.DataAnnotations": "[9.0.1, )",
"Microsoft.Security.Extensions": "[1.3.0, )",
"Semver": "[3.0.0, )",
"Serilog.Extensions.Hosting": "[9.0.0, )",
"Serilog.Sinks.Console": "[6.0.0, )",
"Serilog.Sinks.File": "[6.0.0, )",
"Vpn": "[1.0.0, )"
}
}
Expand Down
128 changes: 128 additions & 0 deletionsVpn.DebugClient/Program.cs
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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
}
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp