Skip to content

Commit

Permalink
feat: Relax the health checks for STUN
Browse files Browse the repository at this point in the history
By default only fail when there is no valid address for ICE. Put the
option to require STUN behind a flag.
  • Loading branch information
bgrozev committed Dec 20, 2023
1 parent 719465d commit e4d5501
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.jitsi.health.HealthChecker
import org.jitsi.health.Result
import org.jitsi.videobridge.health.config.HealthConfig.Companion.config
import org.jitsi.videobridge.ice.Harvesters
import java.net.InetAddress

class JvbHealthChecker : HealthCheckService {
private val healthChecker = HealthChecker(
Expand All @@ -36,7 +37,10 @@ class JvbHealthChecker : HealthCheckService {
fun stop() = healthChecker.stop()

private fun check(): Result {
if (MappingCandidateHarvesters.stunDiscoveryFailed) {
if (config.requireValidAddress && !hasValidAddress()) {
return Result(success = false, message = "No valid IP addresses available for harvesting.")
}
if (config.requireStun && MappingCandidateHarvesters.stunDiscoveryFailed) {
return Result(success = false, message = "Address discovery through STUN failed")
}
if (!Harvesters.isHealthy()) {
Expand All @@ -48,6 +52,20 @@ class JvbHealthChecker : HealthCheckService {
return Result(success = true)
}

private fun InetAddress.isValid(): Boolean {
return !this.isSiteLocalAddress && !this.isLinkLocalAddress && !this.isLoopbackAddress
}

private fun hasValidAddress(): Boolean {
if (Harvesters.singlePortHarvesters.any { it.localAddress.address.isValid() }) {
return true
}
if (MappingCandidateHarvesters.getHarvesters().any { it.mask?.address?.isValid() == true }) {
return true
}
return false
}

override val result: Result
get() = healthChecker.result
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ class HealthConfig private constructor() {
"videobridge.health.sticky-failures".from(JitsiConfig.newConfig)
}

val requireStun: Boolean by config {
"videobridge.health.require-stun".from(JitsiConfig.newConfig)
}

val requireValidAddress: Boolean by config {
"videobridge.health.require-valid-address".from(JitsiConfig.newConfig)
}

companion object {
@JvmField
val config = HealthConfig()
Expand Down
8 changes: 8 additions & 0 deletions jvb/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ videobridge {
# (i.e. once the bridge becomes unhealthy, it will never
# go back to a healthy state)
sticky-failures = false

# If enabled, health checks fail when there are no valid addresses available for ICE. Here "valid" means not
# site local, link local or loopback.
require-valid-address = true

# If enabled, health checks will fail when a STUN mapping harvester is configured, but fails to get a mapping (even
# if there is a valid address available through other mappings or locally).
require-stun = false
}
ep-connection-status {
# How long we'll wait for an endpoint to *start* sending
Expand Down

0 comments on commit e4d5501

Please sign in to comment.