Skip to content

Commit

Permalink
feat: Relax the health checks for STUN (#2077)
Browse files Browse the repository at this point in the history
* feat: Relax the health checks for STUN

By default only fail when there is no valid address for ICE. Put the
option to require STUN behind a flag.

* chore: Bump ice4j.
  • Loading branch information
bgrozev authored Dec 21, 2023
1 parent 719465d commit e41cad1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ice4j</artifactId>
<version>3.0-66-g1c60acc</version>
<version>3.0-68-gd289f12</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down

0 comments on commit e41cad1

Please sign in to comment.