Skip to content

Commit

Permalink
Replace Xirsys' local region urls with the global (recommended) one
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed Oct 31, 2023
1 parent d5ac099 commit 3822e5a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class XirsysSessionHandler(
) : SessionHandler {
companion object {
const val SERVER_NAME = "xirsys.com"

private val regionalUriRegex = Regex(pattern = "(?<protocol>\\w+):[\\w-]+\\.xirsys\\.com(?<query>.*)")
private val regionalUriReplace = "\${protocol}://global.xirsys.net\${query}"
fun normalizeAndReplaceUriWithGlobal(regionalUri: String) =
regionalUriRegex.replace(input = regionalUri, replacement = regionalUriReplace)
}

private val xirsysClient: XirsysClient = RestClientBuilder.newBuilder()
Expand Down Expand Up @@ -103,7 +108,7 @@ class XirsysSessionHandler(
// A sample response looks like "stun:fr-turn1.xirsys.com"
// The java URI class fails to read host and port due to the missing // after the :
// Thus we "normalize" the uri, even though it is technically valid
url.replaceFirst(":", "://")
normalizeAndReplaceUriWithGlobal(url)
},
),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.faforever.icebreaker.service.xirsys

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class XirsysSessionHandlerTest {
@Test
fun `it should replace xirsys urls with global one and normalize the protocol`() {
val input = "stun:fr-turn1.xirsys.com"

val result = XirsysSessionHandler.normalizeAndReplaceUriWithGlobal(input)

assertEquals("stun://global.xirsys.net", result)
}
}

0 comments on commit 3822e5a

Please sign in to comment.