Skip to content

Commit

Permalink
Make allowHost, allowReflexive and allowRelay configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackYps committed Sep 6, 2023
1 parent 008b5ea commit e1e636a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
11 changes: 10 additions & 1 deletion kia-cli/src/main/kotlin/com/faforever/ice/KiaApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,17 @@ class KiaApplication : Callable<Int> {
)
private var telemetryServer: String = ""

@Option(names = ["--allow-host"], description = ["???"])
private var allowHost: Boolean = true

@Option(names = ["--allow-reflexive"], description = ["???"])
private var allowReflexive: Boolean = true

@Option(names = ["--allow-relay"], description = ["???"])
private var allowRelay: Boolean = true

override fun call(): Int {
val iceOptions = IceOptions(userId, userName, gameId, forceRelay, lobbyPort, gpgnetPort, telemetryServer)
val iceOptions = IceOptions(userId, userName, gameId, forceRelay, lobbyPort, gpgnetPort, telemetryServer, allowHost, allowReflexive, allowRelay)
logger.info { "Starting ICE adapter with options: $iceOptions" }
val iceAdapter = IceAdapter(iceOptions, emptyList(), {})
iceAdapter.start()
Expand Down
4 changes: 2 additions & 2 deletions kia-lib/src/main/kotlin/com/faforever/ice/IceAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class IceAdapter(
logger.debug { "joinGame: remotePlayerLogin=$remotePlayerLogin, remotePlayerId=$remotePlayerId" }

val remotePeerOrchestrator = RemotePeerOrchestrator(
localPlayerId = iceOptions.userId,
iceOptions = iceOptions,
remotePlayerId = remotePlayerId,
localOffer = false,
coturnServers = coturnServers,
Expand All @@ -83,7 +83,7 @@ class IceAdapter(
logger.debug { "connectToPeer: remotePlayerLogin=$remotePlayerLogin, remotePlayerId=$remotePlayerId" }

val remotePeerOrchestrator = RemotePeerOrchestrator(
localPlayerId = iceOptions.userId,
iceOptions = iceOptions,
remotePlayerId = remotePlayerId,
localOffer = offer,
coturnServers = coturnServers,
Expand Down
3 changes: 3 additions & 0 deletions kia-lib/src/main/kotlin/com/faforever/ice/IceOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ data class IceOptions(
val lobbyPort: Int,
val gpgnetPort: Int,
val telemetryServer: String,
val allowHost: Boolean,
val allowReflexive: Boolean,
val allowRelay: Boolean,
)
11 changes: 6 additions & 5 deletions kia-lib/src/main/kotlin/com/faforever/ice/ice4j/AgentWrapper.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.faforever.ice.ice4j

import com.faforever.ice.IceOptions
import com.faforever.ice.peering.CoturnServer
import dev.failsafe.Failsafe
import dev.failsafe.Timeout
Expand All @@ -18,7 +19,7 @@ import java.time.Duration
private val logger = KotlinLogging.logger {}

class AgentWrapper(
private val localPlayerId: Int,
private val iceOptions: IceOptions,
private val remotePlayerId: Int,
private val localOffer: Boolean,
private val coturnServers: List<CoturnServer>,
Expand Down Expand Up @@ -104,13 +105,13 @@ class AgentWrapper(
}

val candidates = CandidateUtil.packCandidates(
sourceId = localPlayerId,
sourceId = iceOptions.userId,
destinationId = remotePlayerId,
agent = agent!!,
component = it.result,
allowHost = true, // TODO: Make configurable
allowReflexive = true, // TODO: Make configurable
allowRelay = true, // TODO: Make configurable
allowHost = iceOptions.allowHost,
allowReflexive = iceOptions.allowReflexive,
allowRelay = iceOptions.allowRelay,
)
onCandidatesGathered(candidates)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.faforever.ice.peering

import com.faforever.ice.IceOptions
import com.faforever.ice.ice4j.AgentWrapper
import com.faforever.ice.ice4j.CandidatesMessage
import com.faforever.ice.ice4j.IceState
Expand All @@ -17,7 +18,7 @@ import java.util.concurrent.TimeUnit
private val logger = KotlinLogging.logger {}

class RemotePeerOrchestrator(
private val localPlayerId: Int,
private val iceOptions: IceOptions,
private val remotePlayerId: Int,
private val localOffer: Boolean,
private val coturnServers: List<CoturnServer>,
Expand Down Expand Up @@ -56,7 +57,7 @@ class RemotePeerOrchestrator(
udpSocketBridge = UdpSocketBridge(toRemoteQueue::put, "player-$remotePlayerId")
.apply { start() }
agent = AgentWrapper(
localPlayerId = localPlayerId,
iceOptions = iceOptions,
remotePlayerId = remotePlayerId,
localOffer = localOffer,
coturnServers = coturnServers,
Expand Down
6 changes: 6 additions & 0 deletions kia-lib/src/test/kotlin/com/faforever/ice/IceAdapterIT.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class IceAdapterIT {
5001,
5002,
"telemetryServer",
true,
true,
true,
),
coturnServers = coturnServers,
candidatesTestForwarder::onCandidatesFromA1,
Expand All @@ -51,6 +54,9 @@ class IceAdapterIT {
6001,
6002,
"telemetryServer",
true,
true,
true,
),
coturnServers = coturnServers,
candidatesTestForwarder::onCandidatesFromA2,
Expand Down

0 comments on commit e1e636a

Please sign in to comment.