fix: change Arti SOCKS proxy default port to 17392 and retry on busy port
Change default port from 19050 to 17392 to avoid conflicts with other Tor-using apps. When binding fails (address in use), increment the port and retry up to 10 times before giving up. https://claude.ai/code/session_01JEzjceY3ZaCHz5kL4DsKic
This commit is contained in:
@@ -98,5 +98,5 @@ class TorManager(
|
|||||||
|
|
||||||
fun isSocksReady() = status.value is TorServiceStatus.Active
|
fun isSocksReady() = status.value is TorServiceStatus.Active
|
||||||
|
|
||||||
fun socksPort(): Int = (status.value as? TorServiceStatus.Active)?.port ?: 19050
|
fun socksPort(): Int = (status.value as? TorServiceStatus.Active)?.port ?: 17392
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ import kotlinx.coroutines.withContext
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
||||||
private const val DEFAULT_SOCKS_PORT = 19050
|
private const val DEFAULT_SOCKS_PORT = 17392
|
||||||
|
private const val MAX_PORT_RETRIES = 10
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages the Arti Tor client via custom JNI bindings.
|
* Manages the Arti Tor client via custom JNI bindings.
|
||||||
@@ -46,7 +47,7 @@ private const val DEFAULT_SOCKS_PORT = 19050
|
|||||||
class TorService(
|
class TorService(
|
||||||
val context: Context,
|
val context: Context,
|
||||||
) {
|
) {
|
||||||
private val socksPort = DEFAULT_SOCKS_PORT
|
private var socksPort = DEFAULT_SOCKS_PORT
|
||||||
private val initialized = AtomicBoolean(false)
|
private val initialized = AtomicBoolean(false)
|
||||||
private val proxyRunning = AtomicBoolean(false)
|
private val proxyRunning = AtomicBoolean(false)
|
||||||
|
|
||||||
@@ -101,10 +102,22 @@ class TorService(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the SOCKS proxy (can be called multiple times safely)
|
// Start the SOCKS proxy, retrying on next port if address is in use
|
||||||
val proxyResult = ArtiNative.startSocksProxy(socksPort)
|
var port = socksPort
|
||||||
if (proxyResult != 0) {
|
var started = false
|
||||||
Log.e("TorService") { "Failed to start SOCKS proxy: error $proxyResult" }
|
for (attempt in 0 until MAX_PORT_RETRIES) {
|
||||||
|
val proxyResult = ArtiNative.startSocksProxy(port)
|
||||||
|
if (proxyResult == 0) {
|
||||||
|
socksPort = port
|
||||||
|
started = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
Log.w("TorService") { "Port $port in use, trying ${port + 1}" }
|
||||||
|
port++
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!started) {
|
||||||
|
Log.e("TorService") { "Failed to start SOCKS proxy after $MAX_PORT_RETRIES attempts" }
|
||||||
_status.value = TorServiceStatus.Off
|
_status.value = TorServiceStatus.Off
|
||||||
return@withContext
|
return@withContext
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user