whitelist fixes, grpc stream fixes
This commit is contained in:
@@ -42,13 +42,13 @@ public class Startup
|
||||
|
||||
services.Configure<IpRateLimitOptions>(Configuration.GetSection("IpRateLimiting"));
|
||||
services.Configure<IpRateLimitPolicies>(Configuration.GetSection("IpRateLimitPolicies"));
|
||||
services.AddTransient(_ => Configuration);
|
||||
|
||||
services.AddMemoryCache();
|
||||
services.AddInMemoryRateLimiting();
|
||||
|
||||
services.AddSingleton<SystemInfoService, SystemInfoService>();
|
||||
services.AddSingleton<IUserIdProvider, IdBasedUserIdProvider>();
|
||||
services.AddTransient(_ => Configuration);
|
||||
|
||||
var mareConfig = Configuration.GetRequiredSection("MareSynchronos");
|
||||
|
||||
@@ -65,6 +65,12 @@ public class Startup
|
||||
}
|
||||
};
|
||||
|
||||
var noRetryConfig = new MethodConfig
|
||||
{
|
||||
Names = { MethodName.Default },
|
||||
RetryPolicy = null
|
||||
};
|
||||
|
||||
services.AddSingleton(new MareMetrics(new List<string>
|
||||
{
|
||||
MetricsAPI.CounterInitializedConnections,
|
||||
@@ -89,7 +95,7 @@ public class Startup
|
||||
c.Address = new Uri(mareConfig.GetValue<string>("ServiceAddress"));
|
||||
}).ConfigureChannel(c =>
|
||||
{
|
||||
c.ServiceConfig = new ServiceConfig { MethodConfigs = { defaultMethodConfig } };
|
||||
c.ServiceConfig = new ServiceConfig { MethodConfigs = { noRetryConfig } };
|
||||
c.HttpHandler = new SocketsHttpHandler()
|
||||
{
|
||||
EnableMultipleHttp2Connections = true
|
||||
@@ -107,7 +113,7 @@ public class Startup
|
||||
c.Address = new Uri(mareConfig.GetValue<string>("ServiceAddress"));
|
||||
}).ConfigureChannel(c =>
|
||||
{
|
||||
c.ServiceConfig = new ServiceConfig { MethodConfigs = { defaultMethodConfig } };
|
||||
c.ServiceConfig = new ServiceConfig { MethodConfigs = { noRetryConfig } };
|
||||
c.HttpHandler = new SocketsHttpHandler()
|
||||
{
|
||||
EnableMultipleHttp2Connections = true
|
||||
|
||||
@@ -176,7 +176,13 @@ public class SecretKeyAuthenticationHandler
|
||||
this.metrics = metrics;
|
||||
var config = configuration.GetRequiredSection("MareSynchronos");
|
||||
_failedAttemptsForTempBan = config.GetValue<int>("FailedAuthForTempBan", 5);
|
||||
logger.LogInformation("FailedAuthForTempBan: {num}", _failedAttemptsForTempBan);
|
||||
_tempBanMinutes = config.GetValue<int>("TempBanDurationInMinutes", 30);
|
||||
_whitelistedIps = config.GetValue<List<string>>("WhitelistedIps", new List<string>());
|
||||
logger.LogInformation("TempBanMinutes: {num}", _tempBanMinutes);
|
||||
_whitelistedIps = config.GetSection("WhitelistedIps").Get<List<string>>();
|
||||
foreach (var ip in _whitelistedIps)
|
||||
{
|
||||
logger.LogInformation("Whitelisted IP: " + ip);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,7 @@ internal class IdentityService : IdentificationService.IdentificationServiceBase
|
||||
_handler.RegisterServerForQueue(server.ServerId);
|
||||
_logger.LogInformation("Registered Server " + server.ServerId + " input stream");
|
||||
|
||||
while (await requestStream.MoveNext().ConfigureAwait(false))
|
||||
while (await requestStream.MoveNext(context.CancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
var cur = requestStream.Current.IdentChange;
|
||||
if (cur == null) throw new System.Exception("Expected client ident change");
|
||||
|
||||
@@ -44,11 +44,11 @@ public class Startup
|
||||
MetricsAPI.GaugeUsersRegistered
|
||||
}));
|
||||
|
||||
services.AddTransient(_ => Configuration);
|
||||
services.AddSingleton<SecretKeyAuthenticationHandler>();
|
||||
services.AddSingleton<DiscordBotServices>();
|
||||
services.AddSingleton<IdentityHandler>();
|
||||
services.AddSingleton<CleanupService>();
|
||||
services.AddTransient(_ => Configuration);
|
||||
services.AddHostedService(provider => provider.GetService<CleanupService>());
|
||||
services.AddHostedService<DiscordBot>();
|
||||
services.AddGrpc();
|
||||
|
||||
@@ -39,15 +39,16 @@ public abstract class GrpcBaseService : IHostedService, IDisposable
|
||||
|
||||
private async Task RestartStreams()
|
||||
{
|
||||
_streamCts?.Cancel();
|
||||
_streamCts?.Dispose();
|
||||
_streamCts = new();
|
||||
if (!GrpcIsFaulty)
|
||||
{
|
||||
_streamCts?.Cancel();
|
||||
_streamCts?.Dispose();
|
||||
_streamCts = new();
|
||||
var token = _streamCts.Token;
|
||||
try
|
||||
{
|
||||
await PreStartStream().ConfigureAwait(false);
|
||||
await StartStream(_streamCts.Token).ConfigureAwait(false);
|
||||
await StartStream(token).ConfigureAwait(false);
|
||||
await PostStartStream().ConfigureAwait(false);
|
||||
}
|
||||
catch
|
||||
@@ -74,7 +75,11 @@ public abstract class GrpcBaseService : IHostedService, IDisposable
|
||||
{
|
||||
await CheckFaultStateAndRestore().ConfigureAwait(false);
|
||||
}
|
||||
catch { SetGrpcFaulty(); }
|
||||
catch
|
||||
{
|
||||
SetGrpcFaulty();
|
||||
await Task.Delay(5000, ct).ConfigureAwait(false);
|
||||
}
|
||||
await Task.Delay(250).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -83,10 +88,10 @@ public abstract class GrpcBaseService : IHostedService, IDisposable
|
||||
{
|
||||
if (GrpcIsFaulty)
|
||||
{
|
||||
GrpcIsFaulty = false;
|
||||
await RestartStreams().ConfigureAwait(false);
|
||||
await OnGrpcRestore().ConfigureAwait(false);
|
||||
_logger.LogInformation("GRPC connection is restored");
|
||||
GrpcIsFaulty = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user