Skip to content

Commit

Permalink
Split coturn port into STUN/TURN/UDP/TCP
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed Feb 24, 2025
1 parent f0cc48f commit eba652b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ data class CoturnServerEntity(
val id: Long,
val region: String,
val host: String,
val port: Int,
val stunPort: Int?,
val turnUdpPort: Int?,
val turnTcpPort: Int?,
val turnsTcpPort: Int?,
val presharedKey: String,
val contactEmail: String,
val active: Boolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.faforever.icebreaker.service.coturn

import com.faforever.icebreaker.config.FafProperties
import com.faforever.icebreaker.persistence.CoturnServerEntity
import com.faforever.icebreaker.persistence.CoturnServerRepository
import com.faforever.icebreaker.security.getUserId
import com.faforever.icebreaker.service.Server
Expand Down Expand Up @@ -50,7 +51,7 @@ class CoturnSessionHandler(
id = it.host,
username = tokenName,
credential = tokenSecret,
urls = buildUrls(hostName = it.host, port = it.port),
urls = buildUrls(coturnServer = it),
)
}

Expand All @@ -75,11 +76,26 @@ class CoturnSessionHandler(
}

private fun buildUrls(
hostName: String,
port: Int,
) = listOf(
"stun://$hostName:$port",
"turn://$hostName:$port?transport=udp",
"turn://$hostName:$port?transport=tcp",
)
coturnServer: CoturnServerEntity,
): List<String> {
val result = mutableListOf<String>()

if (coturnServer.stunPort != null) {
result.add("stun://${coturnServer.host}:${coturnServer.stunPort}")
}

if (coturnServer.turnUdpPort != null) {
result.add("turn://${coturnServer.host}:${coturnServer.turnUdpPort}?transport=udp")
}

if (coturnServer.turnTcpPort != null) {
result.add("turn://${coturnServer.host}:${coturnServer.turnTcpPort}?transport=tcp")
}

if (coturnServer.turnsTcpPort != null) {
result.add("turns://${coturnServer.host}:${coturnServer.turnsTcpPort}?transport=tcp")
}

return result
}
}
10 changes: 10 additions & 0 deletions src/main/resources/db/migration/V1.1.0__split_coturn_port.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
drop index unique_host_port on coturn_servers;

alter table coturn_servers
drop column port;

alter table coturn_servers
add stun_port mediumint default 3478 null after host,
add turn_udp_port mediumint default 3478 null after stun_port,
add turn_tcp_port mediumint default 3478 null after turn_udp_port,
add turns_tcp_port mediumint default null null after turn_tcp_port;

0 comments on commit eba652b

Please sign in to comment.