Add LoginLimiter to cross-process semaphores

This commit is contained in:
JustArchi
2020-05-20 23:09:27 +02:00
parent 88bb631eea
commit 2b16198f22
2 changed files with 6 additions and 5 deletions

View File

@@ -62,6 +62,7 @@ namespace ArchiSteamFarm {
internal static ICrossProcessSemaphore GiftsSemaphore { get; private set; }
internal static ICrossProcessSemaphore InventorySemaphore { get; private set; }
internal static ICrossProcessSemaphore LoginRateLimitingSemaphore { get; private set; }
internal static ICrossProcessSemaphore LoginSemaphore { get; private set; }
internal static ImmutableDictionary<string, (ICrossProcessSemaphore RateLimitingSemaphore, SemaphoreSlim OpenConnectionsSemaphore)> WebLimitingSemaphores { get; private set; }
private static readonly SemaphoreSlim UpdateSemaphore = new SemaphoreSlim(1, 1);
@@ -147,6 +148,7 @@ namespace ArchiSteamFarm {
GiftsSemaphore ??= OS.CreateCrossProcessSemaphore(nameof(GiftsSemaphore) + webProxyText);
InventorySemaphore ??= OS.CreateCrossProcessSemaphore(nameof(InventorySemaphore) + webProxyText);
LoginRateLimitingSemaphore ??= OS.CreateCrossProcessSemaphore(nameof(LoginRateLimitingSemaphore) + webProxyText);
LoginSemaphore ??= OS.CreateCrossProcessSemaphore(nameof(LoginSemaphore) + webProxyText);
WebLimitingSemaphores ??= new Dictionary<string, (ICrossProcessSemaphore RateLimitingSemaphore, SemaphoreSlim OpenConnectionsSemaphore)>(4, StringComparer.OrdinalIgnoreCase) {
{ nameof(ArchiWebHandler), (OS.CreateCrossProcessSemaphore(nameof(ArchiWebHandler) + webProxyText), new SemaphoreSlim(WebBrowser.MaxConnections, WebBrowser.MaxConnections)) },

View File

@@ -62,7 +62,6 @@ namespace ArchiSteamFarm {
internal static EOSType OSType { get; private set; } = EOSType.Unknown;
private static readonly SemaphoreSlim BotsSemaphore = new SemaphoreSlim(1, 1);
private static readonly SemaphoreSlim LoginSemaphore = new SemaphoreSlim(1, 1);
[JsonIgnore]
[PublicAPI]
@@ -1938,8 +1937,8 @@ namespace ArchiSteamFarm {
}
private static async Task LimitLoginRequestsAsync() {
if (ASF.LoginRateLimitingSemaphore == null) {
ASF.ArchiLogger.LogNullError(nameof(ASF.LoginRateLimitingSemaphore));
if ((ASF.LoginSemaphore == null) || (ASF.LoginRateLimitingSemaphore == null)) {
ASF.ArchiLogger.LogNullError(nameof(ASF.LoginSemaphore) + " || " + nameof(ASF.LoginRateLimitingSemaphore));
return;
}
@@ -1951,7 +1950,7 @@ namespace ArchiSteamFarm {
return;
}
await LoginSemaphore.WaitAsync().ConfigureAwait(false);
await ASF.LoginSemaphore.WaitAsync().ConfigureAwait(false);
try {
await ASF.LoginRateLimitingSemaphore.WaitAsync().ConfigureAwait(false);
@@ -1960,7 +1959,7 @@ namespace ArchiSteamFarm {
Utilities.InBackground(
async () => {
await Task.Delay(ASF.GlobalConfig.LoginLimiterDelay * 1000).ConfigureAwait(false);
LoginSemaphore.Release();
ASF.LoginSemaphore.Release();
}
);
}