Skip to content

Commit

Permalink
Start writing to the ICE transport as soon as we have any validated p…
Browse files Browse the repository at this point in the history
…air.
  • Loading branch information
JonathanLennox authored and bgrozev committed Oct 1, 2024
1 parent 8ec0b62 commit 2b3f078
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
5 changes: 4 additions & 1 deletion jvb/src/main/kotlin/org/jitsi/videobridge/Endpoint.kt
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ class Endpoint @JvmOverloads constructor(
}
}
iceTransport.eventHandler = object : IceTransport.EventHandler {
override fun connected() {
override fun writeable() {
logger.info("ICE connected")
transceiver.setOutgoingPacketHandler(object : PacketHandler {
override fun processPacket(packetInfo: PacketInfo) {
Expand All @@ -431,6 +431,9 @@ class Endpoint @JvmOverloads constructor(
TaskPools.IO_POOL.execute(dtlsTransport::startDtlsHandshake)
}

override fun connected() {
}

override fun failed() {
}

Expand Down
4 changes: 3 additions & 1 deletion jvb/src/main/kotlin/org/jitsi/videobridge/relay/Relay.kt
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ class Relay @JvmOverloads constructor(
}
}
iceTransport.eventHandler = object : IceTransport.EventHandler {
override fun connected() {
override fun writeable() {
logger.info("ICE connected")
transceiver.setOutgoingPacketHandler(object : PacketHandler {
override fun processPacket(packetInfo: PacketInfo) {
Expand All @@ -395,6 +395,8 @@ class Relay @JvmOverloads constructor(
TaskPools.IO_POOL.execute(dtlsTransport::startDtlsHandshake)
}

override fun connected() {}

override fun failed() {}

override fun consentUpdated(time: Instant) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ class IceTransport @JvmOverloads constructor(
@JvmField
var eventHandler: EventHandler? = null

/**
* Whether or not it is possible to write to this [IceTransport].
*
* This happens as soon as any candidate pair is validated, and happens (usually) before iceConnected.
*/
private val iceWriteable = AtomicBoolean(false)

/**
* Whether or not this [IceTransport] has connected.
*/
Expand All @@ -106,6 +113,8 @@ class IceTransport @JvmOverloads constructor(

fun hasFailed(): Boolean = iceFailed.get()

fun isWriteable(): Boolean = iceWriteable.get()

fun isConnected(): Boolean = iceConnected.get()

/**
Expand Down Expand Up @@ -282,6 +291,7 @@ class IceTransport @JvmOverloads constructor(
put("nominationStrategy", IceConfig.config.nominationStrategy.toString())
put("advertisePrivateCandidates", IceConfig.config.advertisePrivateCandidates)
put("closed", !running.get())
put("iceWriteable", iceWriteable.get())
put("iceConnected", iceConnected.get())
put("iceFailed", iceFailed.get())
putAll(packetStats.toJson())
Expand Down Expand Up @@ -400,7 +410,11 @@ class IceTransport @JvmOverloads constructor(
}

private fun iceStreamPairChanged(ev: PropertyChangeEvent) {
if (IceMediaStream.PROPERTY_PAIR_CONSENT_FRESHNESS_CHANGED == ev.propertyName) {
if (IceMediaStream.PROPERTY_PAIR_VALIDATED == ev.propertyName) {
if (iceWriteable.compareAndSet(false, true)) {
eventHandler?.writeable()
}
} else if (IceMediaStream.PROPERTY_PAIR_CONSENT_FRESHNESS_CHANGED == ev.propertyName) {
/* TODO: Currently ice4j only triggers this event for the selected
* pair, but should we double-check the pair anyway?
*/
Expand Down Expand Up @@ -464,6 +478,11 @@ class IceTransport @JvmOverloads constructor(
}

interface EventHandler {
/**
* Notify the event handler that it is possible to write to the ICE stack
*/
fun writeable()

/**
* Notify the event handler that ICE connected successfully
*/
Expand Down

0 comments on commit 2b3f078

Please sign in to comment.