Skip to content
Draft
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
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
22 changes: 22 additions & 0 deletions Daemon/Peer.Daemon.Linux/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:8.0-preview AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:8.0-preview AS build
WORKDIR /src
COPY ["Peer.Daemon/Peer.Daemon.Linux.csproj", "Peer.Daemon/"]
RUN dotnet restore "Peer.Daemon/Peer.Daemon.Linux.csproj"
COPY . .
WORKDIR "/src/Peer.Daemon"
RUN dotnet build "Peer.Daemon.Linux.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Peer.Daemon.Linux.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Peer.Daemon.Linux.dll"]
34 changes: 34 additions & 0 deletions Daemon/Peer.Daemon.Linux/Peer.Daemon.Linux.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You like this?

<Nullable>enable</Nullable>
<UserSecretsId>a72c40e5-9101-4d72-a095-e1834bf03f06</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release'">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be worth using configurations more liberally so dockerfiles, workflows, etc. could just pass configurations and the meanings could be contained in a propertygroup like this.

<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>true</PublishTrimmed>
<TrimMode>copyused</TrimMode>
<InvariantGlobalization>true</InvariantGlobalization>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<UseAppHost>True</UseAppHost>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0-rc.1.23419.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Server\Peer.Server\Peer.Server.csproj" />
</ItemGroup>

</Project>
28 changes: 28 additions & 0 deletions Daemon/Peer.Daemon.Linux/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Peer.Server;

namespace Peer.Daemon.Linux
{
internal class Program
{
private const string _socketPath = "/var/run/peerless/peerless.sock";
static async Task Main()
{
Directory.CreateDirectory(Directory.GetParent(_socketPath)!.FullName);
File.Delete(_socketPath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this blow up an already running instance if a second one were started? I wonder if it would better to be aggressive about cleanup and fail to start if the socket is already open? I bet there's prior art about this somewhere.


var app = ServerBuilder.CreateHost(cfg =>
{
cfg.WebHost.UseKestrel(kestrel =>
{
kestrel.ListenUnixSocket(_socketPath, opts =>
{
opts.Protocols = HttpProtocols.Http2;
});
});
});

await app.RunAsync();
}
}
}
Comment on lines +4 to +28
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
namespace Peer.Daemon.Linux
{
internal class Program
{
private const string _socketPath = "/var/run/peerless/peerless.sock";
static async Task Main()
{
Directory.CreateDirectory(Directory.GetParent(_socketPath)!.FullName);
File.Delete(_socketPath);
var app = ServerBuilder.CreateHost(cfg =>
{
cfg.WebHost.UseKestrel(kestrel =>
{
kestrel.ListenUnixSocket(_socketPath, opts =>
{
opts.Protocols = HttpProtocols.Http2;
});
});
});
await app.RunAsync();
}
}
}
namespace Peer.Daemon.Linux;
internal class Program
{
private const string _socketPath = "/var/run/peerless/peerless.sock";
static async Task Main()
{
Directory.CreateDirectory(Directory.GetParent(_socketPath)!.FullName);
File.Delete(_socketPath);
var app = ServerBuilder.CreateHost(cfg =>
{
cfg.WebHost.UseKestrel(kestrel =>
{
kestrel.ListenUnixSocket(_socketPath, opts =>
{
opts.Protocols = HttpProtocols.Http2;
});
});
});
await app.RunAsync();
}
}

18 changes: 18 additions & 0 deletions Daemon/Peer.Daemon.Linux/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"profiles": {
"Peer.Daemon.Linux": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:59768;http://localhost:59769"
},
"Docker": {
"commandName": "Docker",
"launchBrowser": false,
"publishAllPorts": true,
"useSSL": false
}
}
}
22 changes: 22 additions & 0 deletions Daemon/Peer.Daemon.Windows/Peer.Daemon.Windows.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release'">
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>true</PublishTrimmed>
<TrimMode>copyused</TrimMode>
<InvariantGlobalization>true</InvariantGlobalization>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<UseAppHost>True</UseAppHost>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Server\Peer.Server\Peer.Server.csproj" />
</ItemGroup>

</Project>
23 changes: 23 additions & 0 deletions Daemon/Peer.Daemon.Windows/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Peer.Server;

namespace Peer.Daemon.Windows;

public class Program
{
public async static Task Main(string[] args)
{
var app = ServerBuilder.CreateHost(builder =>
{
builder.WebHost.UseKestrel(x =>
{
x.ListenNamedPipe("peerless", opts =>
{
opts.Protocols = HttpProtocols.Http2;
});
});
});

await app.RunAsync();
}
}
12 changes: 12 additions & 0 deletions Daemon/Peer.Daemon.Windows/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
8 changes: 8 additions & 0 deletions Daemon/Peer.Daemon.Windows/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Trace"
}
}
}
9 changes: 9 additions & 0 deletions Daemon/Peer.Daemon.Windows/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
24 changes: 24 additions & 0 deletions Geas/Geas.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Grpc.Net.Client" Version="2.57.0" />
<PackageReference Include="Grpc.Tools" Version="2.58.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Google.Protobuf" Version="3.24.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Server\Peer.Grpc\Peer.Grpc.csproj" />
</ItemGroup>
</Project>
62 changes: 62 additions & 0 deletions Geas/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.IO.Pipes;
using System.Security.Principal;
using Grpc.Net.Client;
using Peerless;

namespace Geas;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nerd


internal class Program
{
public string[] _commands = { "prs" };
public string[] _modes = { "unix", "windows" };
static async Task Main(string[] args)
{
var factory = new NamedPipeConnectionFactory("peerless");

var handler = new SocketsHttpHandler()
{
ConnectCallback = factory.ConnectAsync
};

var channel = GrpcChannel.ForAddress("http://pipe:/peerless", new GrpcChannelOptions
{
HttpHandler = handler
});

var client = new PullRequestGrpcService.PullRequestGrpcServiceClient(channel);
var res = client.GetPullRequest(new GetPullRequestRequest { Id = 1 });
await Console.Out.WriteLineAsync($"Found: {res.Value.Id}");
}
}

public class NamedPipeConnectionFactory
{
private readonly string _pipeName;

public NamedPipeConnectionFactory(string pipeName)
{
_pipeName = pipeName;
}

public async ValueTask<Stream> ConnectAsync(SocketsHttpConnectionContext _,
CancellationToken cancellationToken = default)
{
var clientStream = new NamedPipeClientStream(
serverName: ".",
pipeName: _pipeName,
direction: PipeDirection.InOut,
options: PipeOptions.WriteThrough | PipeOptions.Asynchronous,
impersonationLevel: TokenImpersonationLevel.Anonymous);

try
{
await clientStream.ConnectAsync(cancellationToken).ConfigureAwait(false);
return clientStream;
}
catch
{
clientStream.Dispose();
throw;
}
}
}
8 changes: 0 additions & 8 deletions Peer.Domain/Commands/FindError.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Peer.Domain/Commands/ShowArguments.cs

This file was deleted.

13 changes: 6 additions & 7 deletions Peer.Domain/Configuration/RegistrationError.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
namespace Peer.Domain.Configuration
namespace Peer.Domain.Configuration;

public enum RegistrationError
{
public enum RegistrationError
{
Fire,
ProviderMismatch,
BadConfig,
}
Fire,
ProviderMismatch,
BadConfig,
}
3 changes: 0 additions & 3 deletions Peer.Domain/Exceptions/FetchException.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Runtime.Serialization;

namespace Peer.Domain.Exceptions
{
Expand All @@ -10,7 +9,5 @@ public FetchException() { }
public FetchException(string? message) : base(message) { }

public FetchException(string? message, Exception? innerException) : base(message, innerException) { }

protected FetchException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
}
1 change: 0 additions & 1 deletion Peer.Domain/Exceptions/UnreachableException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public UnreachableException()
}

protected UnreachableException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
Expand Down
18 changes: 11 additions & 7 deletions Peer.Domain/IPullRequestService.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Peer.Domain.Commands;
using wimm.Secundatives;

namespace Peer.Domain
namespace Peer.Domain;

public interface IPullRequestService
{
IAsyncEnumerable<PullRequest> FetchAllPullRequests(CancellationToken token = default);
Task<Result<PullRequest, FindError>> FindSingleByPartial(PartialIdentifier partial, CancellationToken token = default);
}

public enum FindError
{
public interface IPullRequestService
{
IAsyncEnumerable<PullRequest> FetchAllPullRequests(CancellationToken token = default);
Task<Result<PullRequest, FindError>> FindSingleByPartial(PartialIdentifier partial, CancellationToken token = default);
}
AmbiguousMatch,
NotFound
}
Loading