define maxAttemptsRatio instead of maxAttempts

This commit is contained in:
hrj 2022-04-05 10:13:58 +05:30
parent a4df7a346d
commit 8df6039a7d
3 changed files with 8 additions and 5 deletions

View File

@ -26,7 +26,7 @@ object AttributesEnum extends Enumeration {
val PLAYGROUND_ENABLED: Value = Value("playgroundEnabled")
val CORS_HEADER: Value = Value("corsHeader")
val CONFIG: Value = Value("config")
val MAX_ATTEMPTS: Value = Value("maxAttempts")
val MAX_ATTEMPTS_RATIO: Value = Value("maxAttemptsRatio")
}
object ResultEnum extends Enumeration {

View File

@ -51,7 +51,7 @@ class Config(configFilePath: String) {
val threadDelay: Int = configFields.threadDelayInt.getOrElse(2)
val playgroundEnabled: Boolean = configFields.playgroundEnabledBool.getOrElse(true)
val corsHeader: String = configFields.corsHeader.getOrElse("")
val maxAttempts: Int = configFields.maxAttemptsInt.getOrElse(10)
val maxAttempts: Int = Math.max(1, (configFields.maxAttemptsRatioFloat.getOrElse(0.01f) * bufferCount).toInt)
private val captchaConfigJson = (configJson \ "captchas")
val captchaConfigTransform: JValue = captchaConfigJson transformField { case JField("config", JObject(config)) =>
@ -74,7 +74,7 @@ class Config(configFilePath: String) {
(AttributesEnum.THREAD_DELAY.toString -> 2) ~
(AttributesEnum.PLAYGROUND_ENABLED.toString -> true) ~
(AttributesEnum.CORS_HEADER.toString -> "") ~
(AttributesEnum.MAX_ATTEMPTS.toString -> 10) ~
(AttributesEnum.MAX_ATTEMPTS_RATIO.toString -> 0.01f) ~
("captchas" -> List(
(
(AttributesEnum.NAME.toString -> "FilterChallenge") ~

View File

@ -28,17 +28,20 @@ case class ConfigField(
threadDelay: Option[Integer],
playgroundEnabled: Option[java.lang.Boolean],
corsHeader: Option[String],
maxAttempts: Option[Integer]
maxAttemptsRatio: Option[java.lang.Float]
) {
lazy val portInt: Option[Int] = mapInt(port)
lazy val bufferCountInt: Option[Int] = mapInt(bufferCount)
lazy val seedInt: Option[Int] = mapInt(seed)
lazy val captchaExpiryTimeLimitInt: Option[Int] = mapInt(captchaExpiryTimeLimit)
lazy val threadDelayInt: Option[Int] = mapInt(threadDelay)
lazy val maxAttemptsInt: Option[Int] = mapInt(maxAttempts)
lazy val maxAttemptsRatioFloat: Option[Float] = mapFloat(maxAttemptsRatio)
lazy val playgroundEnabledBool: Option[Boolean] = playgroundEnabled.map(_ || true)
private def mapInt(x: Option[Integer]): Option[Int] = {
x.map(_ + 0)
}
private def mapFloat(x: Option[java.lang.Float]): Option[Float] = {
x.map(_ + 0.0f)
}
}