fix(tor): remove broken runtime reconnect, add evictConnections
Remove the LaunchedEffect/scope.launch reconnect code that didn't work (relay subscriptions lost after disconnect+connect cycle). Tor toggle will use app rebuild via key() instead (next commit). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -500,26 +500,6 @@ fun App(
|
||||
}
|
||||
val relayManager = remember(httpClient) { DesktopRelayConnectionManager(httpClient) }
|
||||
|
||||
// Reconnect relays on Tor state transitions (ON→proxy, OFF→direct)
|
||||
LaunchedEffect(torManager, relayManager) {
|
||||
var previousStatus: com.vitorpamplona.amethyst.commons.tor.TorServiceStatus? = null
|
||||
torManager.status.collect { status ->
|
||||
val changed = previousStatus != null && previousStatus != status
|
||||
// Reconnect on meaningful transitions: Active (proxy ready) or Off (switch to direct)
|
||||
val isTransition =
|
||||
changed &&
|
||||
(
|
||||
status is com.vitorpamplona.amethyst.commons.tor.TorServiceStatus.Active ||
|
||||
status is com.vitorpamplona.amethyst.commons.tor.TorServiceStatus.Off
|
||||
)
|
||||
if (isTransition) {
|
||||
kotlinx.coroutines.delay(500) // Brief delay for client state to propagate
|
||||
relayManager.client.reconnect(onlyIfChanged = false, ignoreRetryDelays = true)
|
||||
}
|
||||
previousStatus = status
|
||||
}
|
||||
}
|
||||
|
||||
// Subscriptions coordinator — uses default relay URLs for metadata indexing.
|
||||
// Feed subscriptions (inside MainContent) drive actual relay pool connections.
|
||||
val subscriptionsCoordinator =
|
||||
|
||||
+6
-1
@@ -56,7 +56,12 @@ class DesktopHttpClient(
|
||||
/** Returns true if user expects Tor routing (INTERNAL or EXTERNAL mode). */
|
||||
fun isTorExpected(): Boolean = torTypeProvider() != TorType.OFF
|
||||
|
||||
private val sharedConnectionPool = ConnectionPool()
|
||||
val sharedConnectionPool = ConnectionPool()
|
||||
|
||||
/** Evict all idle connections — call on Tor state change to kill stale direct/proxy connections. */
|
||||
fun evictConnections() {
|
||||
sharedConnectionPool.evictAll()
|
||||
}
|
||||
|
||||
private val directClient: OkHttpClient by lazy {
|
||||
OkHttpClient
|
||||
|
||||
Reference in New Issue
Block a user