Fixes the Tor leaks for relays and some image content.

This commit is contained in:
Vitor Pamplona
2025-01-04 17:35:34 -05:00
parent 8a8ae4fb8b
commit 6522d74253
3 changed files with 12 additions and 5 deletions

View File

@@ -24,6 +24,7 @@ import android.os.Build
import android.util.Log import android.util.Log
import androidx.compose.runtime.Stable import androidx.compose.runtime.Stable
import coil3.SingletonImageLoader import coil3.SingletonImageLoader
import coil3.annotation.DelicateCoilApi
import coil3.gif.AnimatedImageDecoder import coil3.gif.AnimatedImageDecoder
import coil3.gif.GifDecoder import coil3.gif.GifDecoder
import coil3.network.okhttp.OkHttpNetworkFetcherFactory import coil3.network.okhttp.OkHttpNetworkFetcherFactory
@@ -88,12 +89,13 @@ class ServiceManager(
start() start()
} }
@OptIn(DelicateCoilApi::class)
private fun start() { private fun start() {
Log.d("ServiceManager", "Pre Starting Relay Services $isStarted $account") Log.d("ServiceManager", "Pre Starting Relay Services $isStarted $account")
if (isStarted && account != null) { if (isStarted && account != null) {
return return
} }
Log.d("ServiceManager", "Starting Relay Services") Log.d("ServiceManager", "Starting Relay Services Tor: ${account?.settings?.torSettings?.torType?.value}")
val myAccount = account val myAccount = account
@@ -126,7 +128,7 @@ class ServiceManager(
?.security ?.security
?.filterSpamFromStrangers ?: true ?.filterSpamFromStrangers ?: true
SingletonImageLoader.setSafe { SingletonImageLoader.setUnsafe {
Amethyst.instance Amethyst.instance
.imageLoaderBuilder() .imageLoaderBuilder()
.components { .components {

View File

@@ -132,7 +132,7 @@ class Relay(
lastConnectTentative = TimeUtils.now() lastConnectTentative = TimeUtils.now()
socket = socketBuilder.build(url, false, RelayListener(onConnected)) socket = socketBuilder.build(url, forceProxy, RelayListener(onConnected))
socket?.connect() socket?.connect()
} catch (e: Exception) { } catch (e: Exception) {
if (e is CancellationException) throw e if (e is CancellationException) throw e

View File

@@ -91,7 +91,8 @@ class RelayPool : Relay.Listener {
fun loadRelays(relayList: List<Relay>) { fun loadRelays(relayList: List<Relay>) {
check(relayList.isNotEmpty()) { "Relay list should never be empty" } check(relayList.isNotEmpty()) { "Relay list should never be empty" }
relayList.forEach { addRelay(it) } relayList.forEach { addRelayInner(it) }
updateStatus()
} }
fun unloadRelays() { fun unloadRelays() {
@@ -142,9 +143,13 @@ class RelayPool : Relay.Listener {
} }
fun addRelay(relay: Relay) { fun addRelay(relay: Relay) {
addRelayInner(relay)
updateStatus()
}
private fun addRelayInner(relay: Relay) {
relay.register(this) relay.register(this)
relays += relay relays += relay
updateStatus()
} }
fun removeRelay(relay: Relay) { fun removeRelay(relay: Relay) {