-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make AniDB rate limiting configurable
Make the AniDB rate limiting configurable and tweak the defaults (again) to be less preservative for HTTP. Also cached the values per rate limiter (UDP and HTTP) and added cache invalidation when the settings has been saved to re-apply the (potentially) updated settings onto the locally cached values.
- Loading branch information
Showing
5 changed files
with
149 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Shoko.Plugin.Abstractions; | ||
|
||
using ISettingsProvider = Shoko.Server.Settings.ISettingsProvider; | ||
|
||
namespace Shoko.Server.Providers.AniDB.HTTP; | ||
|
||
public class HttpRateLimiter : AniDBRateLimiter | ||
{ | ||
protected override int ShortDelay { get; init; } = 2_000; | ||
protected override int LongDelay { get; init; } = 30_000; | ||
protected override long ShortPeriod { get; init; } = 10_000; | ||
protected override long ResetPeriod { get; init; } = 120_000; | ||
|
||
public HttpRateLimiter(ILogger<HttpRateLimiter> logger) : base(logger) | ||
{ | ||
} | ||
public HttpRateLimiter(ILogger<HttpRateLimiter> logger, ISettingsProvider settingsProvider, IShokoEventHandler eventHandler) | ||
: base(logger, settingsProvider, eventHandler, s => s.AniDb.HTTPRateLimit) { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Shoko.Plugin.Abstractions; | ||
|
||
using ISettingsProvider = Shoko.Server.Settings.ISettingsProvider; | ||
|
||
namespace Shoko.Server.Providers.AniDB.UDP; | ||
|
||
public class UDPRateLimiter : AniDBRateLimiter | ||
{ | ||
protected override int ShortDelay { get; init; } = 2_000; | ||
protected override int LongDelay { get; init; } = 6_000; | ||
protected override long ShortPeriod { get; init; } = 10_000; | ||
protected override long ResetPeriod { get; init; } = 120_000; | ||
|
||
public UDPRateLimiter(ILogger<UDPRateLimiter> logger) : base(logger) | ||
{ | ||
} | ||
public UDPRateLimiter(ILogger<UDPRateLimiter> logger, ISettingsProvider settingsProvider, IShokoEventHandler eventHandler) | ||
: base(logger, settingsProvider, eventHandler, s => s.AniDb.UDPRateLimit) { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Shoko.Server.Settings; | ||
|
||
/// <summary> | ||
/// Settings for rate limiting the Anidb provider. | ||
/// </summary> | ||
public class AnidbRateLimitSettings | ||
{ | ||
/// <summary> | ||
/// Base rate in seconds for request and the multipliers. | ||
/// </summary> | ||
[Range(2, 1000)] | ||
public int BaseRateInSeconds { get; set; } = 2; | ||
|
||
/// <summary> | ||
/// Slow rate multiplier applied to the <seealso cref="BaseRateInSeconds"/>. | ||
/// </summary> | ||
[Range(2, 1000)] | ||
public int SlowRateMultiplier { get; set; } = 3; | ||
|
||
/// <summary> | ||
/// Slow rate period multiplier applied to the <seealso cref="BaseRateInSeconds"/>. | ||
/// </summary> | ||
[Range(2, 1000)] | ||
public int SlowRatePeriodMultiplier { get; set; } = 5; | ||
|
||
/// <summary> | ||
/// Reset period multiplier applied to the <seealso cref="BaseRateInSeconds"/>. | ||
/// </summary> | ||
[Range(2, 1000)] | ||
public int ResetPeriodMultiplier { get; set; } = 60; | ||
} |