nvm
This commit is contained in:
parent
97bd0999d3
commit
96dbf70777
4 changed files with 21 additions and 53 deletions
|
|
@ -53,5 +53,4 @@ namespace LightReflectiveMirror.LoadBalancing
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum LRMRegions { Any, NorthAmerica, SouthAmerica, Europe, Asia, Africa, Oceania }
|
public enum LRMRegions { Any, NorthAmerica, SouthAmerica, Europe, Asia, Africa, Oceania }
|
||||||
public enum LRMServerOpCode { Clear, Cache };
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ namespace LightReflectiveMirror.LoadBalancing
|
||||||
[RestResource]
|
[RestResource]
|
||||||
public partial class Endpoint
|
public partial class Endpoint
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sent from an LRM server node
|
/// Sent from an LRM server node
|
||||||
/// adds it to the list if authenticated.
|
/// adds it to the list if authenticated.
|
||||||
|
|
@ -74,7 +75,7 @@ namespace LightReflectiveMirror.LoadBalancing
|
||||||
if (!string.IsNullOrEmpty(auth) && auth == Program.conf.AuthKey)
|
if (!string.IsNullOrEmpty(auth) && auth == Program.conf.AuthKey)
|
||||||
{
|
{
|
||||||
var relays = Program.instance.availableRelayServers.ToList();
|
var relays = Program.instance.availableRelayServers.ToList();
|
||||||
PerformActionToAllServers(LRMServerOpCode.Clear);
|
ClearAllServersLists();
|
||||||
List<Room> requestedRooms;
|
List<Room> requestedRooms;
|
||||||
|
|
||||||
for (int i = 0; i < relays.Count; i++)
|
for (int i = 0; i < relays.Count; i++)
|
||||||
|
|
@ -105,7 +106,7 @@ namespace LightReflectiveMirror.LoadBalancing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PerformActionToAllServers(LRMServerOpCode.Cache);
|
CacheAllServers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,45 +1,29 @@
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace LightReflectiveMirror.LoadBalancing
|
namespace LightReflectiveMirror.LoadBalancing
|
||||||
{
|
{
|
||||||
public partial class Endpoint
|
public partial class Endpoint
|
||||||
{
|
{
|
||||||
/// <summary>
|
void CacheAllServers()
|
||||||
/// We can write all server operations in here,
|
|
||||||
/// to make it more clean.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="operation"></param>
|
|
||||||
/// <param name="onComplete"></param>
|
|
||||||
public static void PerformActionToAllServers(LRMServerOpCode operation, Action onComplete = null)
|
|
||||||
{
|
{
|
||||||
switch (operation)
|
allCachedServers = JsonConvert.SerializeObject(_allServers);
|
||||||
|
NorthAmericaCachedServers = JsonConvert.SerializeObject(_northAmericaServers);
|
||||||
|
SouthAmericaCachedServers = JsonConvert.SerializeObject(_southAmericaServers);
|
||||||
|
EuropeCachedServers = JsonConvert.SerializeObject(_europeServers);
|
||||||
|
AsiaCachedServers = JsonConvert.SerializeObject(_asiaServers);
|
||||||
|
AfricaCachedServers = JsonConvert.SerializeObject(_africaServers);
|
||||||
|
OceaniaCachedServers = JsonConvert.SerializeObject(_oceaniaServers);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClearAllServersLists()
|
||||||
{
|
{
|
||||||
case LRMServerOpCode.Clear:
|
_northAmericaServers.Clear();
|
||||||
for (int i = 0; i < _allServersToPerformActionOn.Count; i++)
|
_southAmericaServers.Clear();
|
||||||
_allServersToPerformActionOn[i].Item1.Clear();
|
_europeServers.Clear();
|
||||||
break;
|
_asiaServers.Clear();
|
||||||
|
_africaServers.Clear();
|
||||||
// Removes the old cached string and reserialzes the new one
|
_oceaniaServers.Clear();
|
||||||
case LRMServerOpCode.Cache:
|
_allServers.Clear();
|
||||||
for (int i = 0; i < _allServersToPerformActionOn.Count; i++)
|
|
||||||
{
|
|
||||||
var tuple = _allServersToPerformActionOn[i];
|
|
||||||
var serializedData = JsonConvert.SerializeObject(_allServersToPerformActionOn[i].Item1);
|
|
||||||
|
|
||||||
_allServersToPerformActionOn.Remove(tuple);
|
|
||||||
_allServersToPerformActionOn.Add(new Tuple<List<Room>, string>(tuple.Item1, serializedData));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,22 +24,6 @@ namespace LightReflectiveMirror.LoadBalancing
|
||||||
private static List<Room> _oceaniaServers = new();
|
private static List<Room> _oceaniaServers = new();
|
||||||
private static List<Room> _allServers = new();
|
private static List<Room> _allServers = new();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This holds all the servers. It's a bit confusing,
|
|
||||||
/// but basically if we have a container for them then we
|
|
||||||
/// can shorten up methods that involve operations with all of them.
|
|
||||||
/// </summary>
|
|
||||||
private static List<Tuple<List<Room>, string>> _allServersToPerformActionOn = new()
|
|
||||||
{
|
|
||||||
new Tuple<List<Room>, string>(_northAmericaServers, NorthAmericaCachedServers),
|
|
||||||
new Tuple<List<Room>, string>(_southAmericaServers, SouthAmericaCachedServers),
|
|
||||||
new Tuple<List<Room>, string>(_europeServers, EuropeCachedServers),
|
|
||||||
new Tuple<List<Room>, string>(_africaServers, AfricaCachedServers),
|
|
||||||
new Tuple<List<Room>, string>(_asiaServers, AsiaCachedServers),
|
|
||||||
new Tuple<List<Room>, string>(_oceaniaServers, OceaniaCachedServers),
|
|
||||||
new Tuple<List<Room>, string>(_allServers, allCachedServers),
|
|
||||||
};
|
|
||||||
|
|
||||||
private LoadBalancerStats _stats
|
private LoadBalancerStats _stats
|
||||||
{
|
{
|
||||||
get => new()
|
get => new()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue