move some stuff around, pray
This commit is contained in:
		| @@ -33,11 +33,11 @@ services: | |||||||
|     image: darkarchon/mare-synchronos-server:latest |     image: darkarchon/mare-synchronos-server:latest | ||||||
|     restart: on-failure |     restart: on-failure | ||||||
|     environment: |     environment: | ||||||
|       MareSynchronos__CdnFullUrl: "${DEV_MARE_CDNURL}" |       MareSynchronos__CdnFullUrl: "http://darkarchon.internet-box.ch:9999" | ||||||
|       MareSynchronos__CdnShardConfiguration__0__CdnFullUrl: "${DEV_MARE_CDNURL}" |       MareSynchronos__CdnShardConfiguration__0__CdnFullUrl: "${DEV_MARE_CDNURL}" | ||||||
|       MareSynchronos__CdnShardConfiguration__0__FileMatch: "^[01234567]" |       MareSynchronos__CdnShardConfiguration__0__FileMatch: "^[012345678]" | ||||||
|       MareSynchronos__CdnShardConfiguration__1__CdnFullUrl: "${DEV_MARE_CDNURL2}" |       MareSynchronos__CdnShardConfiguration__1__CdnFullUrl: "${DEV_MARE_CDNURL2}" | ||||||
|       MareSynchronos__CdnShardConfiguration__1__FileMatch: "^[89ABCDEF]" |       MareSynchronos__CdnShardConfiguration__1__FileMatch: "^[789ABCDEF]" | ||||||
|     volumes: |     volumes: | ||||||
|       - ../config/sharded/server-shard-main.json:/opt/MareSynchronosServer/appsettings.json |       - ../config/sharded/server-shard-main.json:/opt/MareSynchronosServer/appsettings.json | ||||||
|       - ../log/server-shard-main/:/opt/MareSynchronosServer/logs/:rw |       - ../log/server-shard-main/:/opt/MareSynchronosServer/logs/:rw | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| using System.Security.Claims; | using System.Security.Claims; | ||||||
| using System.Security.Cryptography; | using System.Security.Cryptography; | ||||||
|  | using System.Text.RegularExpressions; | ||||||
| using Google.Protobuf; | using Google.Protobuf; | ||||||
| using Grpc.Core; | using Grpc.Core; | ||||||
| using MareSynchronos.API; | using MareSynchronos.API; | ||||||
| @@ -53,13 +54,13 @@ public partial class MareHub | |||||||
|  |  | ||||||
|         var cacheFile = await _dbContext.Files.AsNoTracking().Where(f => hashes.Contains(f.Hash)).AsNoTracking().Select(k => new { k.Hash, k.Size }).AsNoTracking().ToListAsync().ConfigureAwait(false); |         var cacheFile = await _dbContext.Files.AsNoTracking().Where(f => hashes.Contains(f.Hash)).AsNoTracking().Select(k => new { k.Hash, k.Size }).AsNoTracking().ToListAsync().ConfigureAwait(false); | ||||||
|  |  | ||||||
|         var shardConfig = _configurationService.GetValueOrDefault(nameof(ServerConfiguration.CdnShardConfiguration), new List<CdnShardConfiguration>()); |         var shardConfig = new List<CdnShardConfiguration>(_configurationService.GetValueOrDefault(nameof(ServerConfiguration.CdnShardConfiguration), new List<CdnShardConfiguration>())); | ||||||
|  |  | ||||||
|         foreach (var file in cacheFile) |         foreach (var file in cacheFile) | ||||||
|         { |         { | ||||||
|             var forbiddenFile = forbiddenFiles.SingleOrDefault(f => string.Equals(f.Hash, file.Hash, StringComparison.OrdinalIgnoreCase)); |             var forbiddenFile = forbiddenFiles.SingleOrDefault(f => string.Equals(f.Hash, file.Hash, StringComparison.OrdinalIgnoreCase)); | ||||||
|  |  | ||||||
|             var matchedShardConfig = shardConfig.OrderBy(g => Guid.NewGuid()).FirstOrDefault(f => f.FileMatchRegex.Match(file.Hash).Success); |             var matchedShardConfig = shardConfig.OrderBy(g => Guid.NewGuid()).FirstOrDefault(f => new Regex(f.FileMatch).IsMatch(file.Hash)); | ||||||
|             var baseUrl = matchedShardConfig?.CdnFullUrl ?? _mainCdnFullUrl; |             var baseUrl = matchedShardConfig?.CdnFullUrl ?? _mainCdnFullUrl; | ||||||
|  |  | ||||||
|             response.Add(new DownloadFileDto |             response.Add(new DownloadFileDto | ||||||
|   | |||||||
| @@ -28,7 +28,7 @@ public partial class MareHub : Hub<IMareHub>, IMareHub | |||||||
|     private readonly int _maxExistingGroupsByUser; |     private readonly int _maxExistingGroupsByUser; | ||||||
|     private readonly int _maxJoinedGroupsByUser; |     private readonly int _maxJoinedGroupsByUser; | ||||||
|     private readonly int _maxGroupUserCount; |     private readonly int _maxGroupUserCount; | ||||||
|     private IConfigurationService<ServerConfiguration> _configurationService; |     private readonly IConfigurationService<ServerConfiguration> _configurationService; | ||||||
|  |  | ||||||
|     public MareHub(MareMetrics mareMetrics, FileService.FileServiceClient fileServiceClient, |     public MareHub(MareMetrics mareMetrics, FileService.FileServiceClient fileServiceClient, | ||||||
|         MareDbContext mareDbContext, ILogger<MareHub> logger, SystemInfoService systemInfoService, |         MareDbContext mareDbContext, ILogger<MareHub> logger, SystemInfoService systemInfoService, | ||||||
|   | |||||||
| @@ -10,15 +10,12 @@ using System.Globalization; | |||||||
| using System.Reflection; | using System.Reflection; | ||||||
| using System.Text; | using System.Text; | ||||||
| using System.Text.Json; | using System.Text.Json; | ||||||
| using System.Text.RegularExpressions; |  | ||||||
| using static MareSynchronosShared.Protos.ConfigurationService; | using static MareSynchronosShared.Protos.ConfigurationService; | ||||||
|  |  | ||||||
| namespace MareSynchronosShared.Services; | namespace MareSynchronosShared.Services; | ||||||
|  |  | ||||||
| public class MareConfigurationServiceClient<T> : IHostedService, IConfigurationService<T> where T : class, IMareConfiguration | public class MareConfigurationServiceClient<T> : IHostedService, IConfigurationService<T> where T : class, IMareConfiguration | ||||||
| { | { | ||||||
|     internal record RemoteCachedEntry(object Value, DateTime Inserted); |  | ||||||
|  |  | ||||||
|     private readonly T _config; |     private readonly T _config; | ||||||
|     private readonly ConcurrentDictionary<string, object> _cachedRemoteProperties = new(StringComparer.Ordinal); |     private readonly ConcurrentDictionary<string, object> _cachedRemoteProperties = new(StringComparer.Ordinal); | ||||||
|     private readonly ILogger<MareConfigurationServiceClient<T>> _logger; |     private readonly ILogger<MareConfigurationServiceClient<T>> _logger; | ||||||
| @@ -121,10 +118,10 @@ public class MareConfigurationServiceClient<T> : IHostedService, IConfigurationS | |||||||
|                 var properties = _config.GetType().GetProperties(); |                 var properties = _config.GetType().GetProperties(); | ||||||
|                 foreach (var prop in properties) |                 foreach (var prop in properties) | ||||||
|                 { |                 { | ||||||
|                     _logger.LogInformation("Checking Property " + prop.Name); |  | ||||||
|                     try |                     try | ||||||
|                     { |                     { | ||||||
|                         if (!prop.GetCustomAttributes(typeof(RemoteConfigurationAttribute), true).Any()) continue; |                         if (!prop.GetCustomAttributes(typeof(RemoteConfigurationAttribute), true).Any()) continue; | ||||||
|  |                         _logger.LogInformation("Checking Property " + prop.Name); | ||||||
|                         var mi = GetType().GetMethod(nameof(GetValueFromGrpc), BindingFlags.NonPublic | BindingFlags.Instance).MakeGenericMethod(prop.PropertyType); |                         var mi = GetType().GetMethod(nameof(GetValueFromGrpc), BindingFlags.NonPublic | BindingFlags.Instance).MakeGenericMethod(prop.PropertyType); | ||||||
|                         var defaultValue = prop.PropertyType.IsValueType ? Activator.CreateInstance(prop.PropertyType) : null; |                         var defaultValue = prop.PropertyType.IsValueType ? Activator.CreateInstance(prop.PropertyType) : null; | ||||||
|                         var task = (Task)mi.Invoke(this, new[] { _configurationServiceClient, prop.Name, defaultValue }); |                         var task = (Task)mi.Invoke(this, new[] { _configurationServiceClient, prop.Name, defaultValue }); | ||||||
| @@ -136,6 +133,7 @@ public class MareConfigurationServiceClient<T> : IHostedService, IConfigurationS | |||||||
|                         if (resultValue != defaultValue) |                         if (resultValue != defaultValue) | ||||||
|                         { |                         { | ||||||
|                             _cachedRemoteProperties[prop.Name] = resultValue; |                             _cachedRemoteProperties[prop.Name] = resultValue; | ||||||
|  |                             _logger.LogInformation(prop.Name + " is now " + resultValue.ToString()); | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                     catch (Exception ex) |                     catch (Exception ex) | ||||||
| @@ -147,16 +145,17 @@ public class MareConfigurationServiceClient<T> : IHostedService, IConfigurationS | |||||||
|                 if (!_initialized) |                 if (!_initialized) | ||||||
|                 { |                 { | ||||||
|                     _initialized = true; |                     _initialized = true; | ||||||
|                     _logger.LogInformation("Finished initial getting properties from GRPC"); |  | ||||||
|                     _logger.LogInformation(ToString()); |  | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|  |                 _logger.LogInformation("Saved properties from GRPC are now:"); | ||||||
|  |                 _logger.LogInformation(ToString()); | ||||||
|             } |             } | ||||||
|             catch (Exception ex) |             catch (Exception ex) | ||||||
|             { |             { | ||||||
|                 _logger.LogError(ex, "Failure getting or updating properties from GRPC, retrying in 30min"); |                 _logger.LogError(ex, "Failure getting or updating properties from GRPC, retrying in 30min"); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             await Task.Delay(TimeSpan.FromMinutes(30), ct).ConfigureAwait(false); |             await Task.Delay(TimeSpan.FromMinutes(1), ct).ConfigureAwait(false); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -6,8 +6,6 @@ namespace MareSynchronosShared.Utils; | |||||||
| public class CdnShardConfiguration | public class CdnShardConfiguration | ||||||
| { | { | ||||||
|     public string FileMatch { get; set; } |     public string FileMatch { get; set; } | ||||||
|     [JsonIgnore] |  | ||||||
|     public Regex FileMatchRegex => new Regex(FileMatch); |  | ||||||
|     public Uri CdnFullUrl { get; set; } |     public Uri CdnFullUrl { get; set; } | ||||||
|  |  | ||||||
|     public override string ToString() |     public override string ToString() | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 rootdarkarchon
					rootdarkarchon