Add Server-Side Download Queue (#21)

* test add queueing to file service

* further adjustments to download queueing

* add check for whether the request is still in the queue to CheckQueue

* forcefully release slot if download didn't finish in 15s

* actually cancel the delay task

* add metrics and refactor some of the request queue service

* refactor pathing

* reuse httpclient

* add queue request dto to requestfile, enqueue users immediately if a slot is available

* change startup to include all controllers

* update server pathing

* update pathing, again

* several adjustments to auth, banning, jwt server tokens, renaming, authorization

* update api I guess

* adjust automated banning of charaident and reg

* generate jwt on servers for internal authentication

* remove mvcextensions

Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
This commit is contained in:
rootdarkarchon
2023-01-11 12:22:22 +01:00
committed by GitHub
parent db2d0451ca
commit 42b15cb6b7
38 changed files with 1116 additions and 98 deletions

View File

@@ -5,6 +5,8 @@ using MareSynchronosShared.Metrics;
using MareSynchronosShared.Protos;
using MareSynchronosShared.Services;
using MareSynchronosShared.Utils;
using MareSynchronosStaticFilesServer.Services;
using MareSynchronosStaticFilesServer.Utils;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Server.Kestrel.Core;
@@ -41,8 +43,6 @@ public class Startup
var mareConfig = Configuration.GetRequiredSection("MareSynchronos");
services.AddControllers();
services.AddSingleton(m => new MareMetrics(m.GetService<ILogger<MareMetrics>>(), new List<string>
{
}, new List<string>
@@ -52,10 +52,13 @@ public class Startup
MetricsAPI.GaugeFilesUniquePastDay,
MetricsAPI.GaugeFilesUniquePastDaySize,
MetricsAPI.GaugeFilesUniquePastHour,
MetricsAPI.GaugeFilesUniquePastHourSize
MetricsAPI.GaugeFilesUniquePastHourSize,
MetricsAPI.GaugeCurrentDownloads,
MetricsAPI.GaugeDownloadQueue,
}));
services.AddSingleton<CachedFileProvider>();
services.AddSingleton<FileStatisticsService>();
services.AddSingleton<RequestFileStreamResultFactory>();
services.AddHostedService(m => m.GetService<FileStatisticsService>());
services.AddHostedService<FileCleanupService>();
@@ -119,7 +122,11 @@ public class Startup
o.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer();
services.AddAuthorization(options => options.FallbackPolicy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build());
services.AddAuthorization(options =>
{
options.FallbackPolicy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();
options.AddPolicy("Internal", new AuthorizationPolicyBuilder().RequireClaim(MareClaimTypes.Internal, "true").Build());
});
if (_isMain)
{
@@ -148,9 +155,15 @@ public class Startup
p.GetRequiredService<GrpcClientFactory>(), "MainServer")
);
services.AddSingleton<ServerTokenGenerator>();
services.AddSingleton<RequestQueueService>();
services.AddHostedService(p => p.GetService<RequestQueueService>());
services.AddControllers();
services.AddHostedService(p => (MareConfigurationServiceClient<MareConfigurationAuthBase>)p.GetService<IConfigurationService<MareConfigurationAuthBase>>());
services.AddHealthChecks();
services.AddControllers();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)