From a7ee7d5badb352e3ebdc4f3df79cbf831fdedc51 Mon Sep 17 00:00:00 2001 From: Thomas Zeitlhofer Date: Thu, 20 Aug 2020 14:11:44 +0200 Subject: [PATCH 1/3] Renew turnserver credentials when ttl runs out The previous implementation caches the turnserver response indefinitely. This breaks VoIP calls as soon as the ttl of the received turnserver credentials runs out. So, take care to renew the turnserver credentials by allowing the cache to expire. Fixes: d8cf44fdc901 ("Simple cache of turn server response") Signed-off-by: Thomas Zeitlhofer --- .../call/DefaultCallSignalingService.kt | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/DefaultCallSignalingService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/DefaultCallSignalingService.kt index 0c1a129733..8e8bbfa691 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/DefaultCallSignalingService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/DefaultCallSignalingService.kt @@ -58,18 +58,32 @@ internal class DefaultCallSignalingService @Inject constructor( private val activeCalls = mutableListOf() - private var cachedTurnServerResponse: TurnServerResponse? = null + private var cachedTurnServerResponse = object { + + private val MIN_TTL = 60 + + private val now = { System.currentTimeMillis() / 1000 } + + private var expiresAt: Long = 0 + + var data: TurnServerResponse? = null + get() = if (expiresAt > now()) field else null + set(value) { + expiresAt = now() + (value?.ttl ?: 0) - MIN_TTL + field = value + } + } override fun getTurnServer(callback: MatrixCallback): Cancelable { - if (cachedTurnServerResponse != null) { - cachedTurnServerResponse?.let { callback.onSuccess(it) } + if (cachedTurnServerResponse.data != null) { + cachedTurnServerResponse.data?.let { callback.onSuccess(it) } return NoOpCancellable } return turnServerTask .configureWith(GetTurnServerTask.Params) { this.callback = object : MatrixCallback { override fun onSuccess(data: TurnServerResponse) { - cachedTurnServerResponse = data + cachedTurnServerResponse.data = data callback.onSuccess(data) } From bd1a0361be3a601d2b1e279d4ea9d50fd4d65c5b Mon Sep 17 00:00:00 2001 From: Thomas Zeitlhofer Date: Thu, 20 Aug 2020 19:30:08 +0200 Subject: [PATCH 2/3] Changelog entry for turnserver related fix Signed-off-by: Thomas Zeitlhofer --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 700badc801..9fc309e192 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -25,6 +25,7 @@ Bugfix 🐛: - Failed to build unique file (#1954) - Highlighted Event when opening a permalink from another room (#1033) - A Kick appears has "someone has made no change" (#1959) + - Renew turnserver credentials when ttl runs out Translations 🗣: - Add PlayStore description resources in the Triple-T format, to let Weblate handle them From a732d8856bdab7edc6090e906b6e2390f7b9adf7 Mon Sep 17 00:00:00 2001 From: Thomas Zeitlhofer Date: Fri, 21 Aug 2020 14:28:18 +0200 Subject: [PATCH 3/3] change var -> val according to review comment Signed-off-by: Thomas Zeitlhofer --- .../sdk/internal/session/call/DefaultCallSignalingService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/DefaultCallSignalingService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/DefaultCallSignalingService.kt index 8e8bbfa691..6a17f0e925 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/DefaultCallSignalingService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/DefaultCallSignalingService.kt @@ -58,7 +58,7 @@ internal class DefaultCallSignalingService @Inject constructor( private val activeCalls = mutableListOf() - private var cachedTurnServerResponse = object { + private val cachedTurnServerResponse = object { private val MIN_TTL = 60