From 17054fc35a137530fab919df7b06b90298e0a88f Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Tue, 28 Apr 2026 14:45:14 -0400 Subject: [PATCH] Links the Tor okhttpclient with nests --- .../loggedIn/nests/room/lifecycle/NestViewModelFactory.kt | 3 ++- .../com/vitorpamplona/nestsclient/OkHttpNestsClient.kt | 4 ++-- .../nestsclient/OkHttpNestsClientRateLimitTest.kt | 6 +++--- .../nestsclient/interop/NostrNestsAuthFailureInteropTest.kt | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/nests/room/lifecycle/NestViewModelFactory.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/nests/room/lifecycle/NestViewModelFactory.kt index 7017d0125..3b662fed4 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/nests/room/lifecycle/NestViewModelFactory.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/nests/room/lifecycle/NestViewModelFactory.kt @@ -22,6 +22,7 @@ package com.vitorpamplona.amethyst.ui.screen.loggedIn.nests.room.lifecycle import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider +import com.vitorpamplona.amethyst.Amethyst import com.vitorpamplona.amethyst.commons.viewmodels.NestViewModel import com.vitorpamplona.nestsclient.NestsRoomConfig import com.vitorpamplona.nestsclient.OkHttpNestsClient @@ -46,7 +47,7 @@ internal class NestViewModelFactory( @Suppress("UNCHECKED_CAST") override fun create(modelClass: Class): T = NestViewModel( - httpClient = OkHttpNestsClient(), + httpClient = OkHttpNestsClient(Amethyst.instance.roleBasedHttpClientBuilder::okHttpClientForVideo), transport = QuicWebTransportFactory(), decoderFactory = { MediaCodecOpusDecoder() }, playerFactory = { AudioTrackPlayer() }, diff --git a/nestsClient/src/jvmAndroid/kotlin/com/vitorpamplona/nestsclient/OkHttpNestsClient.kt b/nestsClient/src/jvmAndroid/kotlin/com/vitorpamplona/nestsclient/OkHttpNestsClient.kt index e497d1a75..3482f7a2e 100644 --- a/nestsClient/src/jvmAndroid/kotlin/com/vitorpamplona/nestsclient/OkHttpNestsClient.kt +++ b/nestsClient/src/jvmAndroid/kotlin/com/vitorpamplona/nestsclient/OkHttpNestsClient.kt @@ -43,7 +43,7 @@ import kotlin.math.min * the process; the default constructor creates a dedicated client. */ class OkHttpNestsClient( - private val http: OkHttpClient = OkHttpClient(), + private val httpClient: (String) -> OkHttpClient, ) : NestsClient { override suspend fun mintToken( room: NestsRoomConfig, @@ -142,7 +142,7 @@ class OkHttpNestsClient( val request = buildRequest() val response: Response = try { - http.newCall(request).execute() + httpClient(url).newCall(request).execute() } catch (e: SocketException) { transportError = e if (++transportAttempts >= MAX_TRANSPORT_RETRIES) throw NestsException("Failed to reach $url", e) diff --git a/nestsClient/src/jvmTest/kotlin/com/vitorpamplona/nestsclient/OkHttpNestsClientRateLimitTest.kt b/nestsClient/src/jvmTest/kotlin/com/vitorpamplona/nestsclient/OkHttpNestsClientRateLimitTest.kt index a0d89599c..e5375623a 100644 --- a/nestsClient/src/jvmTest/kotlin/com/vitorpamplona/nestsclient/OkHttpNestsClientRateLimitTest.kt +++ b/nestsClient/src/jvmTest/kotlin/com/vitorpamplona/nestsclient/OkHttpNestsClientRateLimitTest.kt @@ -99,7 +99,7 @@ class OkHttpNestsClientRateLimitTest { server.enqueue(success(token = "T1")) try { - val client = OkHttpNestsClient(http = OkHttpClient()) + val client = OkHttpNestsClient(httpClient = { OkHttpClient() }) val token = client.mintToken( room = roomConfig(server.baseUrl), @@ -122,7 +122,7 @@ class OkHttpNestsClientRateLimitTest { repeat(MAX_RATE_LIMIT_RETRIES + 2) { server.enqueue(rateLimited(retryAfterSeconds = 0)) } try { - val client = OkHttpNestsClient(http = OkHttpClient()) + val client = OkHttpNestsClient(httpClient = { OkHttpClient() }) val ex = assertFailsWith { client.mintToken( @@ -149,7 +149,7 @@ class OkHttpNestsClientRateLimitTest { server.enqueue(StubResponse(401, "Unauthorized", body = "{\"error\":\"bad sig\"}")) try { - val client = OkHttpNestsClient(http = OkHttpClient()) + val client = OkHttpNestsClient(httpClient = { OkHttpClient() }) val ex = assertFailsWith { client.mintToken( diff --git a/nestsClient/src/jvmTest/kotlin/com/vitorpamplona/nestsclient/interop/NostrNestsAuthFailureInteropTest.kt b/nestsClient/src/jvmTest/kotlin/com/vitorpamplona/nestsclient/interop/NostrNestsAuthFailureInteropTest.kt index 9a82180b7..59f15d10d 100644 --- a/nestsClient/src/jvmTest/kotlin/com/vitorpamplona/nestsclient/interop/NostrNestsAuthFailureInteropTest.kt +++ b/nestsClient/src/jvmTest/kotlin/com/vitorpamplona/nestsclient/interop/NostrNestsAuthFailureInteropTest.kt @@ -140,7 +140,7 @@ class NostrNestsAuthFailureInteropTest { // Per moq-auth's regex /^nests\/\d+:[0-9a-f]{64}:[a-zA-Z0-9._-]+$/ // — uppercase pubkey hex doesn't match the `[0-9a-f]` class. val signer = NostrSignerInternal(KeyPair()) - val client = OkHttpNestsClient(http = http) + val client = OkHttpNestsClient(httpClient = { http }) val room = NestsRoomConfig( authBaseUrl = harness.authBaseUrl, @@ -171,7 +171,7 @@ class NostrNestsAuthFailureInteropTest { // with `put: []`. Lock that in so a future // hostlist gate doesn't sneak in unnoticed. val signer = NostrSignerInternal(KeyPair()) - val client = OkHttpNestsClient(http = http) + val client = OkHttpNestsClient(httpClient = { http }) val room = NestsRoomConfig( authBaseUrl = harness.authBaseUrl,