Refactor
This commit is contained in:
parent
c838711e3e
commit
12648a2028
21 changed files with 269 additions and 138 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@
|
||||||
**/obj/
|
**/obj/
|
||||||
**/bin/
|
**/bin/
|
||||||
out/
|
out/
|
||||||
|
**.pem
|
||||||
|
|
|
@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nyangate", "src\Nyangate\Ny
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nyangate.Lib", "src\Nyangate.Lib\Nyangate.Lib.csproj", "{273954D9-C2DC-430F-A62D-DD55B908BA6C}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nyangate.Lib", "src\Nyangate.Lib\Nyangate.Lib.csproj", "{273954D9-C2DC-430F-A62D-DD55B908BA6C}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Femsci.Nyangate.Client", "src\Femsci.Nyangate.Client\Femsci.Nyangate.Client.csproj", "{70C92E14-613E-4808-85A1-0F38ABD3AB52}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
@ -40,11 +42,16 @@ Global
|
||||||
{273954D9-C2DC-430F-A62D-DD55B908BA6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{273954D9-C2DC-430F-A62D-DD55B908BA6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{273954D9-C2DC-430F-A62D-DD55B908BA6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{273954D9-C2DC-430F-A62D-DD55B908BA6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{273954D9-C2DC-430F-A62D-DD55B908BA6C}.Release|Any CPU.Build.0 = Release|Any CPU
|
{273954D9-C2DC-430F-A62D-DD55B908BA6C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{70C92E14-613E-4808-85A1-0F38ABD3AB52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{70C92E14-613E-4808-85A1-0F38ABD3AB52}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{70C92E14-613E-4808-85A1-0F38ABD3AB52}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{70C92E14-613E-4808-85A1-0F38ABD3AB52}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(NestedProjects) = preSolution
|
GlobalSection(NestedProjects) = preSolution
|
||||||
{65ADE5CC-F1ED-4D18-A64E-7C4C625334D7} = {9B32EA6C-F2D3-4A38-99FC-0C5F522B338A}
|
{65ADE5CC-F1ED-4D18-A64E-7C4C625334D7} = {9B32EA6C-F2D3-4A38-99FC-0C5F522B338A}
|
||||||
{8CCADE0F-436B-4CF0-A885-CEE0F96121D4} = {D389138A-1E17-4AFE-A0C8-D71DA9C2967B}
|
{8CCADE0F-436B-4CF0-A885-CEE0F96121D4} = {D389138A-1E17-4AFE-A0C8-D71DA9C2967B}
|
||||||
{D1171FEB-30A7-4D0B-B1AF-2DF5857E25A1} = {D389138A-1E17-4AFE-A0C8-D71DA9C2967B}
|
{D1171FEB-30A7-4D0B-B1AF-2DF5857E25A1} = {D389138A-1E17-4AFE-A0C8-D71DA9C2967B}
|
||||||
{273954D9-C2DC-430F-A62D-DD55B908BA6C} = {D389138A-1E17-4AFE-A0C8-D71DA9C2967B}
|
{273954D9-C2DC-430F-A62D-DD55B908BA6C} = {D389138A-1E17-4AFE-A0C8-D71DA9C2967B}
|
||||||
|
{70C92E14-613E-4808-85A1-0F38ABD3AB52} = {D389138A-1E17-4AFE-A0C8-D71DA9C2967B}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|
52
main.key.pem
52
main.key.pem
|
@ -1,52 +0,0 @@
|
||||||
-----BEGIN PRIVATE KEY-----
|
|
||||||
MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQC3E4kHER70RYZh
|
|
||||||
mDNB8f2ae+hPBUxU+Ag+mizg9hgW8l5esKK3AgCPRkKZPg96S+r/lEfifg06W2lI
|
|
||||||
ReMzWCFu3xij9bnLliq5AY7vicrodCFAFP6LHSX0zfEq9lm/wfxHoUsdPRjQgfPl
|
|
||||||
1XQGMBezO1Pa0W9gM5dkfP6B6Gn19nZOiokprhbZq+ExYvi/85o/jxaZb/jarqwM
|
|
||||||
ipu9D5O8BAowVGsNIqh4LzA3W46HYEW/QUiysDk+EaUWcP0aY1hbkdkCLRGaJBV2
|
|
||||||
Wrpptm531V7+fL1KlPv7dc/ZCMTvfuVFuQQud9ApOjXt4d8Ua/zbJRjQ8ibORIGi
|
|
||||||
O5mDjB/jh2maXlGJdimskZWKvF5OQxU5Le2cUDjvlTHQyhL3FLHDOccmkND7s0yi
|
|
||||||
jFBIOTUpjlwGoB3KZICm0AvSMkEyDzeGQGkYTHq3MSgiUfiyQYqhXge5IGWKGTy4
|
|
||||||
txX82lbj1OHxMdWvnmVlnBcKZrwmBakV314XUSyY8bNDNFR6K6cGlbAO8YqNZnqP
|
|
||||||
FdH/Y4Kh8o9A4w6RarxNdmJXRduDopcUlOKxkHafALqGorNq50bG4GduiDAxosGq
|
|
||||||
p+d2txY72kmEQwijDo4RSEQi+ZSXwHwcVe7505F3FHI1CV0QFTt6s350uuEiNs7Q
|
|
||||||
trJEchCB7qaOKKQskXQgcRUvi/kY4QIDAQABAoICAATAGjw5fTkpVkv5LpQOkfIS
|
|
||||||
ptHZV1Bde90IPAuxrgkHJKRKSvwSvnIJSKZMWztlHbfAVLPNiZVE+MK7G8LF5b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AZYI5KMRFwtyRcGDHd9BJJQdfkRrNgb1H+QArIl+JnOEf+YoQE1x/GPKYQSv
|
|
||||||
fJtJau1v5WkynXdITrq1ysOV5qKqaxU4ixHxU45oJsaOqNns+yrymjxtHXxoIzFw
|
|
||||||
AQKCAQEAl+lN5sz5T1ZSmgq6U9wO3cUm+ZMzXfIEA/DHZAR+JqakPVqFYHMLcCkj
|
|
||||||
/ZK+8h++S2mMDI9jpCMSlc2FP7zddDS6VAYkkYtvXvqMTTN5fS7uluCsCssnrsaY
|
|
||||||
csg2iDOU8+Utmlk0m+UhaTrSRWRCqNg/LvO051y0HyeUbClrz/412yHpOQmU1cw5
|
|
||||||
Gnp2QRNBfTYmdMO+ldmhmFj94+u+1gqPN6LF6rpB7PR+g2YgbvCJgS5FIWfHNzB8
|
|
||||||
yO+VrXHUNUgLWDzSBACNJAx1PmzI8nLoKsoW0UGaYCgCpcj3UGqQmPAhEQ3Luo7I
|
|
||||||
A6a/XxsG5QEM+okhljJX1TmpmsjsiA==
|
|
||||||
-----END PRIVATE KEY-----
|
|
29
main.pem
29
main.pem
|
@ -1,29 +0,0 @@
|
||||||
-----BEGIN CERTIFICATE-----
|
|
||||||
MIIFAzCCAuugAwIBAgIUSSnKwcDCcz5MhNWZ/eV+uhBap6kwDQYJKoZIhvcNAQEL
|
|
||||||
BQAwETEPMA0GA1UEAwwGTllBTkVUMB4XDTIzMDMyODEwMzMxM1oXDTI0MDMyNzEw
|
|
||||||
MzMxM1owETEPMA0GA1UEAwwGTllBTkVUMIICIjANBgkqhkiG9w0BAQEFAAOCAg8A
|
|
||||||
MIICCgKCAgEAtxOJBxEe9EWGYZgzQfH9mnvoTwVMVPgIPpos4PYYFvJeXrCitwIA
|
|
||||||
j0ZCmT4Pekvq/5RH4n4NOltpSEXjM1ghbt8Yo/W5y5YquQGO74nK6HQhQBT+ix0l
|
|
||||||
9M3xKvZZv8H8R6FLHT0Y0IHz5dV0BjAXsztT2tFvYDOXZHz+gehp9fZ2ToqJ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k7rMiMpxKvzaHmk/9F6xD
|
|
||||||
HrOrJHCSv5vTxsPTHsfgGa2D8eNg7qK8rySEbzOiMw2CgT6peQMlDTvQbSCE4E/q
|
|
||||||
7g5rOc4GSFOd6C6HMP18BGBFNW3iGwrB7I3s+sonLzEesKlG9JnmQTTIC0bnZjzl
|
|
||||||
5RDkpaQjawBkU0jVYx7//2Fmj7SplLCuAj54LHTh1bhk8kduEi7qX2TmaTJboVX2
|
|
||||||
J1JB3OhEOkaJ4rd+u3LED6sbkO8TWNsI7/Vyz3gbfB5E/nop8jibpoZ67LI1Yjf4
|
|
||||||
eior7k6HOJ7uisnCp3n69aVkUd0FEEVEXr1+LcNt2V5iR24jhs76XSLYqsUwVdU/
|
|
||||||
6zfPt1qT//7MS/KZNU69oJzstqkprXRkelc0SoBB+BY4oWUIvSXR
|
|
||||||
-----END CERTIFICATE-----
|
|
30
src/Femsci.Nyangate.Client/Client.cs
Normal file
30
src/Femsci.Nyangate.Client/Client.cs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
namespace Femsci.Nyangate.Client;
|
||||||
|
|
||||||
|
public static class Client
|
||||||
|
{
|
||||||
|
public static IServiceCollection AddNyangate(this IServiceCollection c, Action<NyangateClientOptions> options)
|
||||||
|
{
|
||||||
|
NyangateClientOptions opts = new();
|
||||||
|
options.Invoke(opts);
|
||||||
|
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IApplicationBuilder UseNyangate(this IApplicationBuilder b)
|
||||||
|
{
|
||||||
|
b.UseMiddleware<ProxyMiddleware>();
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class NyangateClientOptions
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
14
src/Femsci.Nyangate.Client/Femsci.Nyangate.Client.csproj
Normal file
14
src/Femsci.Nyangate.Client/Femsci.Nyangate.Client.csproj
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
43
src/Femsci.Nyangate.Client/ProxyMiddleware.cs
Normal file
43
src/Femsci.Nyangate.Client/ProxyMiddleware.cs
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.Extensions.Primitives;
|
||||||
|
|
||||||
|
namespace Femsci.Nyangate.Client;
|
||||||
|
|
||||||
|
public class ProxyMiddleware
|
||||||
|
{
|
||||||
|
private readonly RequestDelegate _next;
|
||||||
|
|
||||||
|
public ProxyMiddleware(RequestDelegate next)
|
||||||
|
{
|
||||||
|
_next = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task InvokeAsync(HttpContext ctx)
|
||||||
|
{
|
||||||
|
if (!ctx.Request.Headers.TryGetValue("Forwarded", out StringValues header))
|
||||||
|
{
|
||||||
|
await _next(ctx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve 'Forwarded' header
|
||||||
|
|
||||||
|
var values = header.ToDictionary(s => s[..s.IndexOf('=')], s => s[(s.IndexOf('=') + 1)..]);
|
||||||
|
|
||||||
|
IPAddress remote = IPAddress.Parse(values["for"]);
|
||||||
|
IPAddress proxy = IPAddress.Parse(values["by"]);
|
||||||
|
ctx.Request.Scheme = values["proto"];
|
||||||
|
|
||||||
|
ctx.Connection.RemoteIpAddress = remote;
|
||||||
|
ctx.Items["proxy"] = proxy;
|
||||||
|
|
||||||
|
await _next(ctx);
|
||||||
|
|
||||||
|
// Code to execute after calling the next middleware component.
|
||||||
|
}
|
||||||
|
}
|
50
src/Nyangate.Lib/Collections/FixedSizeQueue.cs
Normal file
50
src/Nyangate.Lib/Collections/FixedSizeQueue.cs
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Nyangate.Lib.Collections;
|
||||||
|
|
||||||
|
public class FixedSizedQueue<T> : IEnumerable<T>, IReadOnlyCollection<T>
|
||||||
|
{
|
||||||
|
public FixedSizedQueue(int size)
|
||||||
|
{
|
||||||
|
Size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Size { get; private init; }
|
||||||
|
|
||||||
|
public int Count => _queue.Count;
|
||||||
|
|
||||||
|
public bool IsReadOnly => false;
|
||||||
|
|
||||||
|
private readonly ConcurrentQueue<T> _queue = new();
|
||||||
|
|
||||||
|
public void Enqueue(T obj)
|
||||||
|
{
|
||||||
|
_queue.Enqueue(obj);
|
||||||
|
while (_queue.Count > Size)
|
||||||
|
{
|
||||||
|
_queue.TryDequeue(out _);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TryDequeue([MaybeNullWhen(false)] out T t)
|
||||||
|
{
|
||||||
|
return _queue.TryDequeue(out t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerator<T> GetEnumerator()
|
||||||
|
{
|
||||||
|
return _queue.GetEnumerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
|
{
|
||||||
|
return _queue.GetEnumerator();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
6
src/Nyangate.Lib/Data/BalancingStrategy.cs
Normal file
6
src/Nyangate.Lib/Data/BalancingStrategy.cs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
namespace Nyangate.Lib.Data;
|
||||||
|
|
||||||
|
public enum BalancingStrategy
|
||||||
|
{
|
||||||
|
RoundRobin
|
||||||
|
}
|
11
src/Nyangate.Lib/Data/ServiceInstance.cs
Normal file
11
src/Nyangate.Lib/Data/ServiceInstance.cs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Nyangate.Lib.Data;
|
||||||
|
|
||||||
|
public class ServiceInstance
|
||||||
|
{
|
||||||
|
public required string Name { get; set; }
|
||||||
|
}
|
13
src/Nyangate.Lib/Data/WebService.cs
Normal file
13
src/Nyangate.Lib/Data/WebService.cs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Nyangate.Lib.Data;
|
||||||
|
|
||||||
|
public class WebService
|
||||||
|
{
|
||||||
|
public BalancingStrategy BalancingStrategy { get; set; }
|
||||||
|
public List<ServiceInstance> ServiceInstances { get; set; } = new();
|
||||||
|
private int _counter = 0;
|
||||||
|
}
|
18
src/Nyangate/Controllers/RouteController.cs
Normal file
18
src/Nyangate/Controllers/RouteController.cs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Nyangate.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("/api/route")]
|
||||||
|
public class RouteController : ControllerBase
|
||||||
|
{
|
||||||
|
[HttpGet("meow")]
|
||||||
|
public async Task<IActionResult> Meow()
|
||||||
|
{
|
||||||
|
return Ok("nya");
|
||||||
|
}
|
||||||
|
}
|
33
src/Nyangate/Middleware/HostSelector.cs
Normal file
33
src/Nyangate/Middleware/HostSelector.cs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
using Nyangate.Lib.Data;
|
||||||
|
using Nyangate.Services;
|
||||||
|
|
||||||
|
namespace Nyangate.Middleware;
|
||||||
|
|
||||||
|
public class HostSelector
|
||||||
|
{
|
||||||
|
private readonly RequestDelegate _next;
|
||||||
|
private readonly RoutingMap _map;
|
||||||
|
|
||||||
|
public HostSelector(RequestDelegate next, RoutingMap map)
|
||||||
|
{
|
||||||
|
_next = next;
|
||||||
|
_map = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task Invoke(HttpContext ctx)
|
||||||
|
{
|
||||||
|
var host = _map.Get(ctx.Request.Host.Host);
|
||||||
|
|
||||||
|
if (host is null)
|
||||||
|
{
|
||||||
|
ctx.Response.StatusCode = 404;
|
||||||
|
await ctx.Response.WriteAsync("meowless~");
|
||||||
|
await ctx.Response.CompleteAsync();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Features[typeof(ServerHost)] = host;
|
||||||
|
|
||||||
|
await _next.Invoke(ctx);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,17 +0,0 @@
|
||||||
namespace Nyangate.Middleware;
|
|
||||||
|
|
||||||
public class IDSFilter
|
|
||||||
{
|
|
||||||
private readonly RequestDelegate _next;
|
|
||||||
|
|
||||||
public IDSFilter(RequestDelegate next)
|
|
||||||
{
|
|
||||||
_next = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task Invoke(HttpContext ctx)
|
|
||||||
{
|
|
||||||
//do smth
|
|
||||||
await _next.Invoke(ctx);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
namespace Nyangate.Middleware;
|
|
||||||
|
|
||||||
public class IPFilter
|
|
||||||
{
|
|
||||||
private readonly RequestDelegate _next;
|
|
||||||
|
|
||||||
public IPFilter(RequestDelegate next)
|
|
||||||
{
|
|
||||||
_next = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task Invoke(HttpContext ctx)
|
|
||||||
{
|
|
||||||
//do smth
|
|
||||||
await _next.Invoke(ctx);
|
|
||||||
}
|
|
||||||
}
|
|
23
src/Nyangate/Middleware/Logger.cs
Normal file
23
src/Nyangate/Middleware/Logger.cs
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Nyangate.Middleware;
|
||||||
|
|
||||||
|
public class Logger
|
||||||
|
{
|
||||||
|
private readonly RequestDelegate _next;
|
||||||
|
|
||||||
|
public Logger(RequestDelegate next)
|
||||||
|
{
|
||||||
|
_next = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task Invoke(HttpContext ctx)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ctx.ToString());
|
||||||
|
await _next.Invoke(ctx);
|
||||||
|
Console.WriteLine(ctx.ToString());
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
builder.Services.AddSingleton<ServerCertificateRegistry>();
|
builder.Services.AddSingleton<ServerCertificateRegistry>();
|
||||||
builder.Services.AddSingleton<RoutingMap>();
|
builder.Services.AddSingleton<RoutingMap>();
|
||||||
|
builder.Services.AddControllers();
|
||||||
|
|
||||||
//TODO: Replace with DI
|
//TODO: Replace with DI
|
||||||
var certs = new ServerCertificateRegistry();
|
var certs = new ServerCertificateRegistry();
|
||||||
|
@ -25,11 +26,11 @@ builder.WebHost.UseKestrel(o =>
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
app.UseMiddleware<Logger>();
|
||||||
|
app.UseMiddleware<HostSelector>();
|
||||||
app.UseMiddleware<Authenticator>();
|
app.UseMiddleware<Authenticator>();
|
||||||
app.UseMiddleware<Filter>();
|
app.UseMiddleware<Filter>();
|
||||||
app.UseMiddleware<IPFilter>();
|
|
||||||
app.UseMiddleware<IDSFilter>();
|
|
||||||
app.UseMiddleware<Annotator>();
|
app.UseMiddleware<Annotator>();
|
||||||
app.UseMiddleware<Nyangate.Middleware.Router>();
|
app.UseMiddleware<Router>();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|
|
@ -11,6 +11,7 @@ public class BlacklistRegistry
|
||||||
|
|
||||||
public async Task<bool> IsBlacklisted(HttpContext ctx)
|
public async Task<bool> IsBlacklisted(HttpContext ctx)
|
||||||
{
|
{
|
||||||
|
await Task.Yield();
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +1,31 @@
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
|
||||||
namespace Nyangate.Services;
|
namespace Nyangate.Services;
|
||||||
|
|
||||||
public class RateLimitService
|
public class RateLimitService
|
||||||
{
|
{
|
||||||
public async Task<bool> IsRateLimited(IPAddress addr, bool update = true)
|
private readonly ConcurrentDictionary<IPAddress, int> _actionList = new();
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<bool> IsRateLimited(HttpContext ctx, bool update = true)
|
public async Task<bool> IsRateLimited(HttpContext ctx, bool update = true)
|
||||||
{
|
{
|
||||||
|
IPAddress addr = ctx.Connection.RemoteIpAddress!;
|
||||||
|
int actions = _actionList.GetValueOrDefault(addr, 0);
|
||||||
|
|
||||||
|
if (update)
|
||||||
|
{
|
||||||
|
await UpdateActivity(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateActivity(HttpContext ctx)
|
public async Task UpdateActivity(HttpContext ctx)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
IPAddress addr = ctx.Connection.RemoteIpAddress!;
|
||||||
}
|
|
||||||
|
|
||||||
public async Task UpdateActivity(IPAddress addr)
|
_actionList.AddOrUpdate(addr, (_) => 0, (_, i) => i + 1);
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
await Task.Yield();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,16 +6,6 @@ public class RoutingMap
|
||||||
{
|
{
|
||||||
public RoutingMap()
|
public RoutingMap()
|
||||||
{
|
{
|
||||||
_hosts.Add("meow", new()
|
|
||||||
{
|
|
||||||
Hostname = "meow",
|
|
||||||
Route = new()
|
|
||||||
{
|
|
||||||
UsesTls = false,
|
|
||||||
Port = 8888,
|
|
||||||
Route = new("localhost")
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly Dictionary<string, ServerHost> _hosts = new();
|
private readonly Dictionary<string, ServerHost> _hosts = new();
|
||||||
|
|
|
@ -6,7 +6,7 @@ public class ServerCertificateRegistry
|
||||||
{
|
{
|
||||||
public ServerCertificateRegistry()
|
public ServerCertificateRegistry()
|
||||||
{
|
{
|
||||||
_main = X509Certificate2.CreateFromPemFile("/home/nya/Dev/csharp/nyangate/main.pem", "/home/nya/Dev/csharp/nyangate/main.key.pem");
|
_main = X509Certificate2.CreateFromPemFile("../../main.pem", "../../main.key.pem");
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly Dictionary<string, X509Certificate2> _registry = new();
|
private readonly Dictionary<string, X509Certificate2> _registry = new();
|
||||||
|
|
Loading…
Reference in a new issue