Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start writing to the ICE transport as soon as we have any validated pair. #2226

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -430,7 +430,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 @@ -442,6 +442,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 @@ -391,7 +391,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 @@ -403,6 +403,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 @@ -264,6 +273,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 @@ -375,7 +385,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 @@ -439,6 +453,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
Loading