let file shards register against main or so
This commit is contained in:
@@ -5,6 +5,9 @@ namespace MareSynchronosShared.Services;
|
||||
public interface IConfigurationService<T> where T : class, IMareConfiguration
|
||||
{
|
||||
bool IsMain { get; }
|
||||
|
||||
event EventHandler ConfigChangedEvent;
|
||||
|
||||
T1 GetValue<T1>(string key);
|
||||
T1 GetValueOrDefault<T1>(string key, T1 defaultValue);
|
||||
string ToString();
|
||||
|
||||
@@ -22,6 +22,8 @@ public class MareConfigurationServiceClient<T> : IHostedService, IConfigurationS
|
||||
private readonly CancellationTokenSource _updateTaskCts = new();
|
||||
private bool _initialized = false;
|
||||
private readonly HttpClient _httpClient;
|
||||
public event EventHandler ConfigChangedEvent;
|
||||
private IDisposable _onChanged;
|
||||
|
||||
private Uri GetRoute(string key, string value)
|
||||
{
|
||||
@@ -39,6 +41,7 @@ public class MareConfigurationServiceClient<T> : IHostedService, IConfigurationS
|
||||
|
||||
public MareConfigurationServiceClient(ILogger<MareConfigurationServiceClient<T>> logger, IOptionsMonitor<T> config, ServerTokenGenerator serverTokenGenerator)
|
||||
{
|
||||
_onChanged = _config.OnChange((c) => { ConfigChangedEvent?.Invoke(this, EventArgs.Empty); });
|
||||
_config = config;
|
||||
_logger = logger;
|
||||
_serverTokenGenerator = serverTokenGenerator;
|
||||
@@ -184,6 +187,7 @@ public class MareConfigurationServiceClient<T> : IHostedService, IConfigurationS
|
||||
{
|
||||
_updateTaskCts.Cancel();
|
||||
_httpClient.Dispose();
|
||||
_onChanged?.Dispose();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -6,13 +6,18 @@ using System.Text;
|
||||
|
||||
namespace MareSynchronosShared.Services;
|
||||
|
||||
public class MareConfigurationServiceServer<T> : IConfigurationService<T> where T : class, IMareConfiguration
|
||||
public sealed class MareConfigurationServiceServer<T> : IDisposable, IConfigurationService<T> where T : class, IMareConfiguration
|
||||
{
|
||||
private readonly IOptionsMonitor<T> _config;
|
||||
private bool _disposed;
|
||||
|
||||
public bool IsMain => true;
|
||||
public event EventHandler ConfigChangedEvent;
|
||||
private IDisposable _onChanged;
|
||||
|
||||
public MareConfigurationServiceServer(IOptionsMonitor<T> config)
|
||||
{
|
||||
_onChanged = _config.OnChange((c) => { ConfigChangedEvent?.Invoke(this, EventArgs.Empty); });
|
||||
_config = config;
|
||||
}
|
||||
|
||||
@@ -48,4 +53,15 @@ public class MareConfigurationServiceServer<T> : IConfigurationService<T> where
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_onChanged.Dispose();
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
namespace MareSynchronosShared.Utils.Configuration;
|
||||
|
||||
public class CdnShardConfiguration
|
||||
{
|
||||
public List<string> Continents { get; set; }
|
||||
public string FileMatch { get; set; }
|
||||
public Uri CdnFullUrl { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return CdnFullUrl.ToString() + "[" + string.Join(',', Continents) + "] == " + FileMatch;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace MareSynchronosShared.Utils.Configuration;
|
||||
|
||||
public class ShardConfiguration
|
||||
{
|
||||
public List<string> Continents { get; set; }
|
||||
public string FileMatch { get; set; }
|
||||
public Dictionary<string, Uri> RegionUris { get; set; }
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using MareSynchronosShared.Utils;
|
||||
using System.Text;
|
||||
using System.Text;
|
||||
|
||||
namespace MareSynchronosShared.Utils.Configuration;
|
||||
|
||||
@@ -25,8 +24,7 @@ public class StaticFilesServerConfiguration : MareConfigurationBase
|
||||
public double SpeedTestHoursRateLimit { get; set; } = 0.5;
|
||||
[RemoteConfiguration]
|
||||
public Uri CdnFullUrl { get; set; } = null;
|
||||
[RemoteConfiguration]
|
||||
public List<CdnShardConfiguration> CdnShardConfiguration { get; set; } = new();
|
||||
public ShardConfiguration? ShardConfiguration { get; set; } = null;
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
@@ -42,7 +40,6 @@ public class StaticFilesServerConfiguration : MareConfigurationBase
|
||||
sb.AppendLine($"{nameof(CacheDirectory)} => {CacheDirectory}");
|
||||
sb.AppendLine($"{nameof(DownloadQueueSize)} => {DownloadQueueSize}");
|
||||
sb.AppendLine($"{nameof(DownloadQueueReleaseSeconds)} => {DownloadQueueReleaseSeconds}");
|
||||
sb.AppendLine($"{nameof(CdnShardConfiguration)} => {string.Join(", ", CdnShardConfiguration)}");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user