Add rate limiter

This commit is contained in:
Ben Adrian Sarmiento
2024-07-12 14:00:10 +02:00
parent fded8ee8aa
commit fbc431b82b
7 changed files with 116 additions and 54 deletions

View File

@@ -57,8 +57,10 @@ func MainApp(configPath string) {
proxyURL = os.Getenv("PROXY")
}
repoClient4 := http.NewHTTPClient("", 0, 1, false, []string{}, proxyURL, log.Named("network_test"))
repoClient6 := http.NewHTTPClient("", 0, 1, true, []string{}, proxyURL, log.Named("network_test"))
dummyLimiter := http.NewRateLimiter(1000)
repoClient4 := http.NewHTTPClient("", 0, 1, false, []string{}, proxyURL, dummyLimiter, log.Named("network_test"))
repoClient6 := http.NewHTTPClient("", 0, 1, true, []string{}, proxyURL, dummyLimiter, log.Named("network_test"))
repo := http.NewIPRepository(repoClient4, repoClient6, "", log.Named("network_test"))
var hosts []string
@@ -79,6 +81,8 @@ func MainApp(configPath string) {
}
}
rateLimiter := http.NewRateLimiter(config.GetAPIRateLimitPerSecond())
apiClient := http.NewHTTPClient(
config.GetToken(),
config.GetRetriesUntilFailed(), // default retries = 2
@@ -86,6 +90,7 @@ func MainApp(configPath string) {
false, // no need for ipv6 support
[]string{}, // no optimal hosts needed
proxyURL,
rateLimiter,
log.Named("api_client"),
)
@@ -96,6 +101,7 @@ func MainApp(configPath string) {
false, // no need for ipv6 support
[]string{}, // no optimal hosts needed
proxyURL,
rateLimiter,
log.Named("unrestrict_client"),
)
@@ -106,6 +112,7 @@ func MainApp(configPath string) {
config.ShouldForceIPv6(),
hosts,
proxyURL,
rateLimiter,
log.Named("download_client"),
)
@@ -120,11 +127,14 @@ func MainApp(configPath string) {
}
defer workerPool.Release()
torrentsRateLimiter := http.NewRateLimiter(config.GetTorrentsRateLimitPerSecond())
rd := realdebrid.NewRealDebrid(
apiClient,
unrestrictClient,
downloadClient,
workerPool,
torrentsRateLimiter,
config,
log.Named("realdebrid"),
)