diff --git a/CHANGELOG.md b/CHANGELOG.md index 14f8608..d26b6d6 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [2020-06-16] Reworked graceful shutdown [@carbotaniuman]. - [2020-06-16] Changed log level of response timings to INFO by [@lflare]. - [2020-06-16] api/pastStats no longer called on load of WebUI (this shouldn't affect hits/misses), will be reimplemented later [@RedMatriz]. +- [2020-06-17] Revamped configuration & units by [@lflare]. ### Deprecated diff --git a/src/main/java/mdnet/base/Main.java b/src/main/java/mdnet/base/Main.java index 3b71ca5..1945d54 100644 --- a/src/main/java/mdnet/base/Main.java +++ b/src/main/java/mdnet/base/Main.java @@ -74,7 +74,7 @@ public class Main { dieWithError("Config Error: Invalid port number"); } - if (settings.getMaxCacheSizeMib() < 1024) { + if (settings.getMaxCacheSizeInMebibytes() < 1024) { dieWithError("Config Error: Invalid max cache size, must be >= 1024 MiB (1GiB)"); } @@ -82,11 +82,11 @@ public class Main { dieWithError("Config Error: Invalid number of threads, must be >= 4"); } - if (settings.getMaxBandwidthMibPerHour() < 0) { + if (settings.getMaxMebibytesPerHour() < 0) { dieWithError("Config Error: Max bandwidth must be >= 0"); } - if (settings.getMaxBurstRateKibPerSecond() < 0) { + if (settings.getMaxKilobitsPerSecond() < 0) { dieWithError("Config Error: Max burst rate must be >= 0"); } diff --git a/src/main/java/mdnet/base/MangaDexClient.java b/src/main/java/mdnet/base/MangaDexClient.java index d83160e..68acd64 100644 --- a/src/main/java/mdnet/base/MangaDexClient.java +++ b/src/main/java/mdnet/base/MangaDexClient.java @@ -58,7 +58,7 @@ public class MangaDexClient { try { cache = DiskLruCache.open(new File("cache"), 1, 1, - clientSettings.getMaxCacheSizeMib() * 1024 * 1024 /* MiB to bytes */); + clientSettings.getMaxCacheSizeInMebibytes() * 1024 * 1024 /* MiB to bytes */); DiskLruCache.Snapshot snapshot = cache.get("statistics"); if (snapshot != null) { @@ -165,8 +165,8 @@ public class MangaDexClient { } long currentBytesSent = statistics.get().getBytesSent() - lastBytesSent; - if (clientSettings.getMaxBandwidthMibPerHour() != 0 - && clientSettings.getMaxBandwidthMibPerHour() * 1024 * 1024 /* MiB to bytes */ < currentBytesSent) { + if (clientSettings.getMaxMebibytesPerHour() != 0 + && clientSettings.getMaxMebibytesPerHour() * 1024 * 1024 /* MiB to bytes */ < currentBytesSent) { if (LOGGER.isInfoEnabled()) { LOGGER.info("Shutting down server as hourly bandwidth limit reached"); } diff --git a/src/main/java/mdnet/base/ServerHandler.java b/src/main/java/mdnet/base/ServerHandler.java index 090543e..7271e9e 100644 --- a/src/main/java/mdnet/base/ServerHandler.java +++ b/src/main/java/mdnet/base/ServerHandler.java @@ -41,8 +41,8 @@ public class ServerHandler { HashMap params = new HashMap<>(); params.put("secret", settings.getClientSecret()); params.put("port", settings.getClientPort()); - params.put("disk_space", settings.getMaxCacheSizeMib() * 1024 * 1024 /* MiB to bytes */); - params.put("network_speed", settings.getMaxBurstRateKibPerSecond() * 1024 /* KiB to bytes */); + params.put("disk_space", settings.getMaxCacheSizeInMebibytes() * 1024 * 1024 /* MiB to bytes */); + params.put("network_speed", settings.getMaxKilobitsPerSecond() * 1000 * 8 /* Kbps to bytes */); params.put("build_version", Constants.CLIENT_BUILD); HttpResponse response = Unirest.post(SERVER_ADDRESS + "ping") @@ -65,8 +65,8 @@ public class ServerHandler { HashMap params = new HashMap<>(); params.put("secret", settings.getClientSecret()); params.put("port", settings.getClientPort()); - params.put("disk_space", settings.getMaxCacheSizeMib() * 1024 * 1024 /* MiB to bytes */); - params.put("network_speed", settings.getMaxBurstRateKibPerSecond() * 1024 /* KiB to bytes */); + params.put("disk_space", settings.getMaxCacheSizeInMebibytes() * 1024 * 1024 /* MiB to bytes */); + params.put("network_speed", settings.getMaxKilobitsPerSecond() * 1000 * 8 /* Kbps to bytes */); params.put("build_version", Constants.CLIENT_BUILD); params.put("tls_created_at", old.getTls().getCreatedAt()); diff --git a/src/main/kotlin/mdnet/base/Netty.kt b/src/main/kotlin/mdnet/base/Netty.kt index b8d089d..fe07b16 100644 --- a/src/main/kotlin/mdnet/base/Netty.kt +++ b/src/main/kotlin/mdnet/base/Netty.kt @@ -46,7 +46,7 @@ class Netty(private val tls: ServerSettings.TlsCert, private val clientSettings: private lateinit var address: InetSocketAddress private val burstLimiter = object : GlobalTrafficShapingHandler( - workerGroup, 1024L * clientSettings.maxBurstRateKibPerSecond, 0, 50) { + workerGroup, clientSettings.maxKilobitsPerSecond * 1000L, 0, 50) { override fun doAccounting(counter: TrafficCounter) { statistics.getAndUpdate { it.copy(bytesSent = it.bytesSent + counter.cumulativeWrittenBytes()) diff --git a/src/main/kotlin/mdnet/base/settings/ClientSettings.kt b/src/main/kotlin/mdnet/base/settings/ClientSettings.kt index a1207f4..20431c0 100644 --- a/src/main/kotlin/mdnet/base/settings/ClientSettings.kt +++ b/src/main/kotlin/mdnet/base/settings/ClientSettings.kt @@ -4,9 +4,9 @@ import com.google.gson.annotations.SerializedName import dev.afanasev.sekret.Secret data class ClientSettings( - @field:SerializedName("max_cache_size_mib") val maxCacheSizeMib: Long = 20480, - @field:SerializedName("max_bandwidth_mib_per_hour") val maxBandwidthMibPerHour: Long = 0, - @field:SerializedName("max_burst_rate_kib_per_second") val maxBurstRateKibPerSecond: Long = 0, + @field:SerializedName("max_cache_size_in_mebibytes") val maxCacheSizeInMebibytes: Long = 20480, + @field:SerializedName("max_mebibytes_per_hour") val maxMebibytesPerHour: Long = 0, + @field:SerializedName("max_kilobits_per_second") val maxKilobitsPerSecond: Long = 0, @field:SerializedName("client_hostname") val clientHostname: String = "0.0.0.0", @field:SerializedName("client_port") val clientPort: Int = 443, @field:Secret @field:SerializedName("client_secret") val clientSecret: String = "PASTE-YOUR-SECRET-HERE",