Skip to content

Commit

Permalink
Tweak bridge selection. (#883)
Browse files Browse the repository at this point in the history
Match all requirements before filtering by preferences.

Fix warning text when there are no bridges at all.

Co-authored-by: James A <[email protected]>
  • Loading branch information
jqdrqgnq and jqdrqgnq authored Feb 24, 2022
1 parent 99c221f commit f14ca1c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/main/kotlin/org/jitsi/jicofo/bridge/BridgeSelector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,25 @@ class BridgeSelector @JvmOverloads constructor(
prioritizedBridges.sort()

var candidateBridges = prioritizedBridges.filter { it.isOperational }.toList()
if (candidateBridges.isEmpty()) {
logger.warn("There are no operational bridges.")
return null
}

if (v != null) {
candidateBridges = candidateBridges.filter { it.version == v }
if (candidateBridges.isEmpty()) {
logger.warn("There are no bridges with the required version: $v")
return null
}
}
if (candidateBridges.isEmpty()) {
logger.warn("There are no bridges with the required version: $v")
return null

if (ColibriConfig.config.enableColibri2) {
candidateBridges = candidateBridges.filter { it.supportsColibri2() }
if (candidateBridges.isEmpty()) {
logger.warn("There are no bridges with colibri2 support.")
return null
}
}

// If there are active bridges, prefer those.
Expand All @@ -195,14 +208,6 @@ class BridgeSelector @JvmOverloads constructor(
if (!runningBridges.isEmpty())
candidateBridges = runningBridges

if (ColibriConfig.config.enableColibri2) {
candidateBridges = candidateBridges.filter { it.supportsColibri2() }
if (candidateBridges.isEmpty()) {
logger.warn("There are no bridges with colibri2 support.")
return null
}
}

return bridgeSelectionStrategy.select(
candidateBridges,
conferenceBridges,
Expand Down
3 changes: 3 additions & 0 deletions src/test/kotlin/org/jitsi/jicofo/bridge/BridgeSelectorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ class BridgeSelectorTest : ShouldSpec() {

val jvb2 = selector.addJvbAddress(jid2).apply { setStats(stress = 0.9) }
selector.selectBridge() shouldBe jvb2

jvb2.setStats(stress = 0.9, gracefulShutdown = true)
selector.selectBridge() shouldBe jvb2
}
context("Lost bridges stats") {
val selector = BridgeSelector(clock)
Expand Down

0 comments on commit f14ca1c

Please sign in to comment.