feat(proxy)!: убрать TCP-режим проброса и bond
Бэкенд на сервере теперь только UDP (WireGuard/AmneziaWG): выпилены -mode/-bond из конфига ядра, control.sh, share-ссылки и UI. hasRunArgs определяется по obf_profile - сервер отдаёт его всегда, когда параметры запуска нашлись.
This commit is contained in:
1 parent
429affa0a1
commit
215156ea44
32 files changed
+65
-235
No files matched your search
@@ -9,8 +9,6 @@ data class ClientConfig(
|
||||
val useUdp: Boolean = false,
|
||||
val manualCaptcha: Boolean = false,
|
||||
val localPort: String = DEFAULT_LOCAL_PORT,
|
||||
val tcpForward: Boolean = false,
|
||||
val bond: Boolean = false,
|
||||
val debugMode: Boolean = false,
|
||||
val useCarrierDns: Boolean = true,
|
||||
val dnsMode: String = DnsMode.AUTO,
|
||||
|
||||
@@ -29,7 +29,7 @@ data class CoreConfigJson(
|
||||
data class Turn(val n: Int, val transport: String, val host: String, val port: String)
|
||||
|
||||
@Serializable
|
||||
data class Proxy(val mode: String, val bond: Boolean, val listen: String)
|
||||
data class Proxy(val listen: String)
|
||||
|
||||
@Serializable
|
||||
data class Vk(
|
||||
@@ -57,8 +57,6 @@ data class CoreConfigJson(
|
||||
|
||||
const val TRANSPORT_TCP = "tcp"
|
||||
const val TRANSPORT_UDP = "udp"
|
||||
const val PROXY_MODE_TCP = "tcp"
|
||||
const val PROXY_MODE_UDP = "udp"
|
||||
const val TUNNEL_MODE_NONE = "none"
|
||||
const val TUNNEL_MODE_WG = "wg"
|
||||
const val PLATFORM_MOBILE = "mobile"
|
||||
@@ -104,11 +102,6 @@ fun ClientConfig.toCoreJson(
|
||||
port = "",
|
||||
),
|
||||
proxy = CoreConfigJson.Proxy(
|
||||
// Ядро поднимает туннель только поверх udp; UI тоже гасит выбор tcp.
|
||||
mode = if (tcpForward && !wireGuardActive) CoreConfigJson.PROXY_MODE_TCP
|
||||
else CoreConfigJson.PROXY_MODE_UDP,
|
||||
// bond работает только в tcp-режиме.
|
||||
bond = tcpForward && !wireGuardActive && bond,
|
||||
// В туннельном режиме порт не биндится (ядро берёт in-memory pipe),
|
||||
// но валидацию проходит и нужен прокси-режиму.
|
||||
listen = localPort,
|
||||
|
||||
@@ -14,7 +14,6 @@ data class ProbeData(
|
||||
val version: String? = null,
|
||||
@SerialName("bin_sha256") val binSha256: String? = null,
|
||||
val running: Boolean = false,
|
||||
val mode: String? = null,
|
||||
val obf: String? = null,
|
||||
val runtime: String = "",
|
||||
val euid: Int = -1,
|
||||
@@ -63,7 +62,6 @@ data class WgSetupInfo(
|
||||
@Serializable
|
||||
data class ShareInfoData(
|
||||
@SerialName("wg_backend") val wgBackend: Boolean = false,
|
||||
val mode: String = "",
|
||||
@SerialName("obf_profile") val obfProfile: String = "",
|
||||
@SerialName("obf_key") val obfKey: String = "",
|
||||
)
|
||||
|
||||
@@ -52,9 +52,6 @@ internal object ServerJson {
|
||||
put("useUdp", p.client.useUdp)
|
||||
put("manualCaptcha", p.client.manualCaptcha)
|
||||
put("localPort", p.client.localPort)
|
||||
put("tcpForward", p.client.tcpForward)
|
||||
put("bond", p.client.bond)
|
||||
|
||||
put("debugMode", p.client.debugMode)
|
||||
put("useCarrierDns", p.client.useCarrierDns)
|
||||
put("dnsMode", p.client.dnsMode)
|
||||
@@ -108,9 +105,6 @@ internal object ServerJson {
|
||||
useUdp = cliO.optBoolean("useUdp", false),
|
||||
manualCaptcha = cliO.optBoolean("manualCaptcha", false),
|
||||
localPort = cliO.optString("localPort", ClientConfig.DEFAULT_LOCAL_PORT),
|
||||
tcpForward = cliO.optBoolean("tcpForward", false),
|
||||
bond = cliO.optBoolean("bond", false),
|
||||
|
||||
debugMode = cliO.optBoolean("debugMode", false),
|
||||
useCarrierDns = cliO.optBoolean("useCarrierDns", true),
|
||||
dnsMode = cliO.optString("dnsMode", DnsMode.AUTO).let {
|
||||
|
||||
@@ -11,8 +11,6 @@ data class FreeturnLink(
|
||||
val provider: String,
|
||||
val peer: String,
|
||||
val transport: String = "",
|
||||
val mode: String = "",
|
||||
val bond: Boolean = false,
|
||||
val obfProfile: String = "",
|
||||
val obfKey: String = "",
|
||||
val n: Int = 0,
|
||||
@@ -31,8 +29,6 @@ data class FreeturnLink(
|
||||
sb.field("provider", jsonString(provider))
|
||||
sb.field("peer", jsonString(peer))
|
||||
if (transport.isNotEmpty()) sb.field("transport", jsonString(transport))
|
||||
if (mode.isNotEmpty()) sb.field("mode", jsonString(mode))
|
||||
if (bond) sb.field("bond", "true")
|
||||
if (obfProfile.isNotEmpty() && obfProfile != "none") {
|
||||
sb.field("obf", jsonString(obfProfile))
|
||||
sb.field("key", jsonString(obfKey))
|
||||
@@ -74,8 +70,6 @@ data class FreeturnLink(
|
||||
provider = provider,
|
||||
peer = peer,
|
||||
transport = o.optString("transport"),
|
||||
mode = o.optString("mode"),
|
||||
bond = o.optBoolean("bond", false),
|
||||
obfProfile = o.optString("obf"),
|
||||
obfKey = o.optString("key"),
|
||||
n = o.optInt("n", 0),
|
||||
|
||||
@@ -5,13 +5,12 @@ package com.freeturn.app.data.share
|
||||
* Используется вместо локального [com.freeturn.app.data.server.ServerOpts] для точности.
|
||||
*/
|
||||
data class ShareInfo(
|
||||
/** Режим бэкенда: "udp" | "tcp". Пусто = сервер не запускался из приложения. */
|
||||
val mode: String = "",
|
||||
/** Пусто = сервер не запускался из приложения; при живых args хотя бы "none". */
|
||||
val obfProfile: String = "",
|
||||
val obfKey: String = "",
|
||||
/** Есть WG-conf в /etc/wireguard -> шарим VPN-доступ (peer-add). Иначе - прокси. */
|
||||
val wgBackend: Boolean = false
|
||||
) {
|
||||
/** run.args найден - серверным значениям можно верить. */
|
||||
val hasRunArgs: Boolean get() = mode.isNotEmpty()
|
||||
val hasRunArgs: Boolean get() = obfProfile.isNotEmpty()
|
||||
}
|
||||
@@ -16,15 +16,12 @@ object ShareLinkBuilder {
|
||||
wgConf: String?,
|
||||
clientId: String = ""
|
||||
): String {
|
||||
val tcpMode = if (info.hasRunArgs) info.mode == "tcp" else server.client.tcpForward
|
||||
val obfProfile = if (info.hasRunArgs) info.obfProfile else server.opts.obfProfile
|
||||
val obfKey = if (info.hasRunArgs) info.obfKey else server.opts.obfKey
|
||||
return FreeturnLink(
|
||||
provider = server.client.provider,
|
||||
peer = server.client.serverAddress,
|
||||
transport = if (server.client.useUdp) "udp" else "",
|
||||
mode = if (tcpMode) "tcp" else "",
|
||||
bond = tcpMode && server.client.bond,
|
||||
obfProfile = if (ObfProfile.isValidKey(obfKey)) obfProfile else "",
|
||||
obfKey = if (ObfProfile.isValidKey(obfKey)) obfKey else "",
|
||||
n = server.client.threads,
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.freeturn.app.data.share
|
||||
|
||||
import com.freeturn.app.data.control.ShareListData
|
||||
|
||||
/** Гость из allowlist без WG-пира (`share-list` clients): tcp/Xray-бэкенд. */
|
||||
/** Гость из allowlist без WG-пира (`share-list` clients): свой бэкенд на стороне гостя. */
|
||||
data class SharedClient(
|
||||
val clientId: String,
|
||||
/** Имя = comment в clients.json. */
|
||||
|
||||
@@ -13,7 +13,6 @@ sealed class ServerState {
|
||||
data class Known(
|
||||
val installed: Boolean,
|
||||
val running: Boolean,
|
||||
val tcpMode: Boolean? = null,
|
||||
val obfProfile: String? = null,
|
||||
val version: String? = null
|
||||
) : ServerState()
|
||||
|
||||
@@ -39,11 +39,9 @@ class ProxyOrchestrator(
|
||||
return
|
||||
}
|
||||
val opts = prefs.serverOptsFlow.first()
|
||||
val tcpMode = prefs.clientConfigFlow.first().tcpForward
|
||||
sshRepository.stopServer()
|
||||
sshRepository.startServer(
|
||||
listen = l, connect = c,
|
||||
tcpMode = tcpMode,
|
||||
obfProfile = if (opts.obfEnabled) opts.obfProfile else "none",
|
||||
obfKey = if (opts.obfEnabled) opts.obfKey else "",
|
||||
clientId = prefs.ownClientId()
|
||||
|
||||
@@ -49,7 +49,6 @@ sealed class ServerCommand {
|
||||
add("start")
|
||||
add("--listen=${opts.listen}")
|
||||
add("--connect=${opts.connect}")
|
||||
if (opts.tcpMode) add("--mode=tcp")
|
||||
if (opts.obfProfile != "none" && opts.obfKey.isNotBlank()) {
|
||||
add("--obf-profile=${opts.obfProfile}")
|
||||
add("--obf-key=${opts.obfKey}")
|
||||
@@ -86,7 +85,6 @@ sealed class ServerCommand {
|
||||
data class ServerStartOptions(
|
||||
val listen: String,
|
||||
val connect: String,
|
||||
val tcpMode: Boolean = false,
|
||||
val obfProfile: String = "none",
|
||||
val obfKey: String = "",
|
||||
val clientId: String = ""
|
||||
|
||||
@@ -31,7 +31,7 @@ class ShareRepository(context: Context, ssh: SSHManager) {
|
||||
suspend fun shareInfo(cfg: SshConfig): Result<ShareInfo> =
|
||||
control.run(cfg, ServerCommand.ShareInfo)
|
||||
.requireData<ShareInfoData>()
|
||||
.map { ShareInfo(it.mode, it.obfProfile, it.obfKey, it.wgBackend) }
|
||||
.map { ShareInfo(it.obfProfile, it.obfKey, it.wgBackend) }
|
||||
|
||||
suspend fun addPeer(
|
||||
cfg: SshConfig,
|
||||
|
||||
@@ -149,7 +149,6 @@ class SshRepository(
|
||||
_serverState.value = ServerState.Known(
|
||||
installed = d.installed,
|
||||
running = d.running,
|
||||
tcpMode = if (d.running) d.mode == "tcp" else null,
|
||||
obfProfile = if (d.running) d.obf else null,
|
||||
version = d.version
|
||||
)
|
||||
@@ -185,7 +184,6 @@ class SshRepository(
|
||||
suspend fun startServer(
|
||||
listen: String,
|
||||
connect: String,
|
||||
tcpMode: Boolean = false,
|
||||
obfProfile: String = "none",
|
||||
obfKey: String = "",
|
||||
clientId: String = ""
|
||||
@@ -200,7 +198,6 @@ class SshRepository(
|
||||
ServerStartOptions(
|
||||
listen = listen,
|
||||
connect = connect,
|
||||
tcpMode = tcpMode,
|
||||
obfProfile = obfProfile,
|
||||
obfKey = obfKey,
|
||||
clientId = clientId
|
||||
|
||||
@@ -14,15 +14,13 @@ import com.freeturn.app.ui.components.SectionLabel
|
||||
import com.freeturn.app.ui.components.SettingsCard
|
||||
import com.freeturn.app.ui.components.SettingsControlLabel
|
||||
import com.freeturn.app.ui.components.SettingsFieldSlot
|
||||
import com.freeturn.app.ui.components.SettingsGroup
|
||||
import com.freeturn.app.ui.components.SettingsGroupItem
|
||||
import com.freeturn.app.ui.components.SettingsRowDivider
|
||||
import com.freeturn.app.ui.components.SettingsSwitchRow
|
||||
import com.freeturn.app.ui.util.redact
|
||||
|
||||
/**
|
||||
* "Дополнительно": транспорт TURN (tcp/udp, ортогонален режиму туннеля), сегментированная
|
||||
* группа свитчей (капча + bond - bond только в TCP-режиме), альтернативный TURN-узел.
|
||||
* "Дополнительно": транспорт TURN (tcp/udp, ортогонален режиму туннеля), ручная капча,
|
||||
* альтернативный TURN-узел.
|
||||
*/
|
||||
@Composable
|
||||
internal fun AdvancedSection(
|
||||
@@ -30,9 +28,6 @@ internal fun AdvancedSection(
|
||||
onUseUdp: (Boolean) -> Unit,
|
||||
manualCaptcha: Boolean,
|
||||
onManualCaptcha: (Boolean) -> Unit,
|
||||
showBond: Boolean,
|
||||
bond: Boolean,
|
||||
onBond: (Boolean) -> Unit,
|
||||
magicSwitch: Boolean,
|
||||
onMagicSwitch: (Boolean) -> Unit,
|
||||
magicTurn: String,
|
||||
@@ -62,28 +57,13 @@ internal fun AdvancedSection(
|
||||
}
|
||||
}
|
||||
|
||||
// Капча + Bond - сегментированная группа свитчей.
|
||||
// Bond - client-only флаг (сервер детектит сам), только в TCP-режиме.
|
||||
val toggleCount = if (showBond) 2 else 1
|
||||
SettingsGroup {
|
||||
SettingsGroupItem(0, toggleCount) {
|
||||
SettingsSwitchRow(
|
||||
title = stringResource(R.string.manual_captcha),
|
||||
subtitle = stringResource(R.string.manual_captcha_desc),
|
||||
checked = manualCaptcha,
|
||||
onCheckedChange = onManualCaptcha
|
||||
)
|
||||
}
|
||||
if (showBond) {
|
||||
SettingsGroupItem(1, toggleCount) {
|
||||
SettingsSwitchRow(
|
||||
title = stringResource(R.string.client_bond),
|
||||
subtitle = stringResource(R.string.client_bond_desc),
|
||||
checked = bond,
|
||||
onCheckedChange = onBond
|
||||
)
|
||||
}
|
||||
}
|
||||
SettingsCard {
|
||||
SettingsSwitchRow(
|
||||
title = stringResource(R.string.manual_captcha),
|
||||
subtitle = stringResource(R.string.manual_captcha_desc),
|
||||
checked = manualCaptcha,
|
||||
onCheckedChange = onManualCaptcha
|
||||
)
|
||||
}
|
||||
|
||||
// Альтернативный TURN-узел - свитч + адрес (раскрывается при включении).
|
||||
|
||||
@@ -61,15 +61,12 @@ fun ClientSetupScreen(
|
||||
val snapshot by settingsViewModel.serversSnapshot.collectAsStateWithLifecycle()
|
||||
val activeClient by settingsViewModel.clientConfig.collectAsStateWithLifecycle()
|
||||
val sshConfig by serverViewModel.sshConfig.collectAsStateWithLifecycle()
|
||||
val serverState by serverViewModel.serverState.collectAsStateWithLifecycle()
|
||||
val activeProxyListen by settingsViewModel.proxyListen.collectAsStateWithLifecycle()
|
||||
val privacyMode by settingsViewModel.privacyMode.collectAsStateWithLifecycle()
|
||||
|
||||
// Источник данных: конкретный сервер по id либо активный.
|
||||
val server = serverId?.let { id -> snapshot.list.firstOrNull { it.id == id } }
|
||||
val saved = server?.client ?: activeClient
|
||||
// Активный сервер рулит живым рантаймом, неактивный - только хранилищем.
|
||||
val isActive = serverId == null || serverId == snapshot.activeId
|
||||
val effSshIp = server?.ssh?.ip ?: sshConfig.ip
|
||||
val effProxyListen = server?.proxyListen ?: activeProxyListen
|
||||
|
||||
@@ -82,12 +79,6 @@ fun ClientSetupScreen(
|
||||
}
|
||||
}
|
||||
|
||||
val serverKnown = serverState as? com.freeturn.app.domain.ServerState.Known
|
||||
// TCP-форвард: реальное состояние из probe (если запущен) или сохранённое.
|
||||
val syncOn = saved.syncServerSwitches
|
||||
val effectiveTcpForward = if (isActive && syncOn && serverKnown?.running == true)
|
||||
serverKnown.tcpMode ?: saved.tcpForward else saved.tcpForward
|
||||
|
||||
val context = LocalContext.current
|
||||
|
||||
// remember (не rememberSaveable), чтобы не восстанавливать stale-поля из bundle.
|
||||
@@ -223,10 +214,6 @@ fun ClientSetupScreen(
|
||||
},
|
||||
manualCaptcha = saved.manualCaptcha,
|
||||
onManualCaptcha = { v -> clientEdit { it.copy(manualCaptcha = v) } },
|
||||
showBond = effectiveTcpForward,
|
||||
bond = saved.bond,
|
||||
// bond триггерит рестарт прокси только у активного; иначе пишем данные.
|
||||
onBond = { v -> if (isActive) settingsViewModel.setBond(v) else clientEdit { it.copy(bond = v) } },
|
||||
magicSwitch = saved.magicSwitch,
|
||||
onMagicSwitch = { v -> clientEdit { it.copy(magicSwitch = v) } },
|
||||
magicTurn = magicTurn,
|
||||
|
||||
+2
-7
@@ -98,7 +98,6 @@ fun ServerManagementScreen(
|
||||
}
|
||||
var proxyListenPort by rememberSaveable(savedListen) { mutableStateOf(savedListen.substringAfterLast(":", "56000")) }
|
||||
var proxyConnect by rememberSaveable(savedConnect) { mutableStateOf(savedConnect) }
|
||||
var tcpDraft by rememberSaveable(effClient.tcpForward) { mutableStateOf(effClient.tcpForward) }
|
||||
var obfDraft by rememberSaveable(effServer.obfProfile) { mutableStateOf(effServer.obfProfile) }
|
||||
var keyDraft by rememberSaveable(effServer.obfKey) { mutableStateOf(effServer.obfKey) }
|
||||
|
||||
@@ -114,7 +113,6 @@ fun ServerManagementScreen(
|
||||
val listenFull = "${proxyListenIp.ifBlank { "0.0.0.0" }}:$proxyListenPort"
|
||||
val proxyDirty = listenFull != savedListen || proxyConnect != savedConnect
|
||||
val configDirty = proxyDirty ||
|
||||
tcpDraft != effClient.tcpForward ||
|
||||
obfDraft != effServer.obfProfile ||
|
||||
keyDraft != effServer.obfKey
|
||||
val keyOkForApply = obfDraft == ObfProfile.NONE || keyDraft.isBlank() ||
|
||||
@@ -127,10 +125,10 @@ fun ServerManagementScreen(
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||
// Активный - apply в живой рантайм (один рестарт). Неактивный - пишем только снимок сервера.
|
||||
if (isActive) {
|
||||
settingsViewModel.applyServerConfig(listenFull, proxyConnect, tcpDraft, obfDraft, keyDraft)
|
||||
settingsViewModel.applyServerConfig(listenFull, proxyConnect, obfDraft, keyDraft)
|
||||
} else {
|
||||
// !isActive ⇒ serverId != null (см. isActive выше) - smart cast.
|
||||
settingsViewModel.updateServerConfig(serverId, listenFull, proxyConnect, tcpDraft, obfDraft, keyDraft)
|
||||
settingsViewModel.updateServerConfig(serverId, listenFull, proxyConnect, obfDraft, keyDraft)
|
||||
}
|
||||
onBack()
|
||||
}
|
||||
@@ -282,9 +280,6 @@ fun ServerManagementScreen(
|
||||
// Гейт общий со входом в экран (ServerDetailScreen) - serverSettingsAvailable.
|
||||
if (serverSettingsAvailable(isConnected, syncOn)) {
|
||||
ServerSyncCard(
|
||||
tcp = tcpDraft,
|
||||
onTcp = { HapticUtil.perform(context, HapticUtil.Pattern.TOGGLE_ON); tcpDraft = it },
|
||||
tcpBlocked = effClient.wireGuardActive,
|
||||
obfProfile = obfDraft,
|
||||
onObfProfile = { HapticUtil.perform(context, HapticUtil.Pattern.TOGGLE_ON); obfDraft = it },
|
||||
keyDraft = keyDraft,
|
||||
|
||||
@@ -12,9 +12,6 @@ import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.SegmentedButton
|
||||
import androidx.compose.material3.SegmentedButtonDefaults
|
||||
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -35,15 +32,12 @@ import com.freeturn.app.ui.components.SettingsRowDivider
|
||||
import com.freeturn.app.ui.util.redact
|
||||
|
||||
/**
|
||||
* Синхронные серверные настройки (apply-модель): проброс UDP/TCP, профиль обфускации и
|
||||
* obf-ключ (черновик). Регенерация/копирование ключа - через колбэки; рестарт случается
|
||||
* Синхронные серверные настройки (apply-модель): профиль обфускации и obf-ключ
|
||||
* (черновик). Регенерация/копирование ключа - через колбэки; рестарт случается
|
||||
* по общей кнопке "Применить" на экране.
|
||||
*/
|
||||
@Composable
|
||||
internal fun ServerSyncCard(
|
||||
tcp: Boolean,
|
||||
onTcp: (Boolean) -> Unit,
|
||||
tcpBlocked: Boolean,
|
||||
obfProfile: String,
|
||||
onObfProfile: (String) -> Unit,
|
||||
keyDraft: String,
|
||||
@@ -55,28 +49,6 @@ internal fun ServerSyncCard(
|
||||
) {
|
||||
SectionLabel(stringResource(R.string.server_sync_section))
|
||||
SettingsCard {
|
||||
// Проброс: UDP / TCP.
|
||||
SettingsFieldSlot {
|
||||
SettingsControlLabel(stringResource(R.string.tcp_forward_mode))
|
||||
SingleChoiceSegmentedButtonRow(modifier = Modifier.fillMaxWidth()) {
|
||||
SegmentedButton(
|
||||
selected = !tcp,
|
||||
onClick = { onTcp(false) },
|
||||
shape = SegmentedButtonDefaults.itemShape(index = 0, count = 2)
|
||||
) { Text(stringResource(R.string.udp)) }
|
||||
SegmentedButton(
|
||||
selected = tcp,
|
||||
onClick = { onTcp(true) },
|
||||
// Ядро поднимает туннель только поверх udp-проброса.
|
||||
enabled = !tcpBlocked,
|
||||
shape = SegmentedButtonDefaults.itemShape(index = 1, count = 2)
|
||||
) { Text(stringResource(R.string.tcp)) }
|
||||
}
|
||||
if (tcpBlocked) {
|
||||
SettingsControlLabel(stringResource(R.string.tcp_blocked_by_tunnel))
|
||||
}
|
||||
}
|
||||
SettingsRowDivider()
|
||||
// Профиль обфускации.
|
||||
SettingsFieldSlot {
|
||||
SettingsControlLabel(stringResource(R.string.obf_profile_title))
|
||||
|
||||
@@ -285,7 +285,6 @@ private fun serverCommandLine(server: Server, privacy: Boolean): String {
|
||||
val opts = ServerStartOptions(
|
||||
listen = server.proxyListen,
|
||||
connect = server.proxyConnect,
|
||||
tcpMode = server.client.tcpForward,
|
||||
obfProfile = if (server.opts.obfEnabled) server.opts.obfProfile else ObfProfile.NONE,
|
||||
obfKey = if (server.opts.obfEnabled) server.opts.obfKey else ""
|
||||
)
|
||||
|
||||
@@ -207,33 +207,6 @@ fun SetupConfigStep(
|
||||
}
|
||||
} else {
|
||||
SettingsFieldSlot {
|
||||
SingleChoiceSegmentedButtonRow(modifier = Modifier.fillMaxWidth()) {
|
||||
SegmentedButton(
|
||||
selected = !draft.backendTcp,
|
||||
onClick = {
|
||||
if (draft.backendTcp) {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.TOGGLE_ON)
|
||||
onDraftChange(draft.copy(backendTcp = false))
|
||||
}
|
||||
},
|
||||
shape = SegmentedButtonDefaults.itemShape(index = 0, count = 2)
|
||||
) { Text(stringResource(R.string.udp)) }
|
||||
SegmentedButton(
|
||||
selected = draft.backendTcp,
|
||||
onClick = {
|
||||
if (!draft.backendTcp) {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.TOGGLE_ON)
|
||||
onDraftChange(draft.copy(backendTcp = true))
|
||||
}
|
||||
},
|
||||
shape = SegmentedButtonDefaults.itemShape(index = 1, count = 2)
|
||||
) { Text(stringResource(R.string.tcp)) }
|
||||
}
|
||||
Text(
|
||||
stringResource(R.string.setup_backend_protocol_desc),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
BackendPortField(draft, showErrors, onDraftChange)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ sealed interface ServerHubState {
|
||||
data class Online(
|
||||
val running: Boolean,
|
||||
val installed: Boolean,
|
||||
val tcpMode: Boolean?,
|
||||
val obfProfile: String?,
|
||||
val version: String?,
|
||||
val sshIp: String
|
||||
|
||||
@@ -69,7 +69,6 @@ data class SetupConfigDraft(
|
||||
val wgCustomConf: Boolean = false,
|
||||
val wgConfText: String = "",
|
||||
val backendPort: String = "",
|
||||
val backendTcp: Boolean = false,
|
||||
val vkLink: String = ""
|
||||
)
|
||||
|
||||
@@ -100,10 +99,7 @@ data class SetupUiState(
|
||||
val config: SetupConfigDraft = SetupConfigDraft(),
|
||||
val install: SetupInstallState? = null
|
||||
) {
|
||||
/**
|
||||
* Внешний порт совпал с UDP-портом бэкенда на том же хосте - оба бинда
|
||||
* конфликтуют. TCP-бэкенд (Xray/sing-box) с UDP-listen не пересекается.
|
||||
*/
|
||||
/** Внешний порт совпал с портом бэкенда на том же хосте - оба бинда конфликтуют. */
|
||||
val portsClash: Boolean
|
||||
get() {
|
||||
val listen = config.listenPort.toIntOrNull() ?: return false
|
||||
@@ -111,8 +107,7 @@ data class SetupUiState(
|
||||
config.vpnMode && config.wgCustomConf -> config.backendPort.toIntOrNull()
|
||||
config.vpnMode && wgDetectedPort == null -> config.wgPort.toIntOrNull()
|
||||
config.vpnMode -> wgDetectedPort
|
||||
!config.backendTcp -> config.backendPort.toIntOrNull()
|
||||
else -> null
|
||||
else -> config.backendPort.toIntOrNull()
|
||||
}
|
||||
return backend != null && backend == listen
|
||||
}
|
||||
@@ -295,7 +290,6 @@ class ServerSetupViewModel(
|
||||
ServerStartOptions(
|
||||
listen = "0.0.0.0:${c.listenPort}",
|
||||
connect = "127.0.0.1:$backendPort",
|
||||
tcpMode = !c.vpnMode && c.backendTcp,
|
||||
obfProfile = c.obfProfile,
|
||||
obfKey = if (obfOn) obfKey else "",
|
||||
// Авторизация по allowlist с первого запуска: владелец сидится
|
||||
@@ -344,7 +338,6 @@ class ServerSetupViewModel(
|
||||
client = ClientConfig(
|
||||
serverAddress = "${cfg.ip}:${c.listenPort}",
|
||||
vkLink = c.vkLink.trim(),
|
||||
tcpForward = !c.vpnMode && c.backendTcp,
|
||||
tunnelTransport = if (c.vpnMode && !wgClientConf.isNullOrBlank())
|
||||
TunnelTransport.WIREGUARD else TunnelTransport.NONE,
|
||||
wireGuardConfig = wgClientConf.orEmpty()
|
||||
|
||||
@@ -52,7 +52,6 @@ class ServerViewModel(
|
||||
ServerHubState.Online(
|
||||
running = server.running,
|
||||
installed = server.installed,
|
||||
tcpMode = server.tcpMode,
|
||||
obfProfile = server.obfProfile,
|
||||
version = server.version,
|
||||
sshIp = ssh.ip
|
||||
@@ -114,11 +113,9 @@ class ServerViewModel(
|
||||
sshRepository.updateServerState(ServerState.Error("Неверный формат адреса (ожидается host:port)"))
|
||||
return@launch
|
||||
}
|
||||
val tcpMode = prefs.clientConfigFlow.first().tcpForward
|
||||
val opts = prefs.serverOptsFlow.first()
|
||||
sshRepository.startServer(
|
||||
listen = l, connect = c,
|
||||
tcpMode = tcpMode,
|
||||
obfProfile = if (opts.obfEnabled) opts.obfProfile else "none",
|
||||
obfKey = if (opts.obfEnabled) opts.obfKey else "",
|
||||
clientId = prefs.ownClientId()
|
||||
|
||||
@@ -259,15 +259,6 @@ class SettingsViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
fun setBond(enabled: Boolean) {
|
||||
viewModelScope.launch {
|
||||
val changed = prefs.updateActiveServer {
|
||||
it.copy(client = it.client.copy(bond = enabled))
|
||||
}
|
||||
if (changed) orchestrator.restartProxyIfRunning()
|
||||
}
|
||||
}
|
||||
|
||||
fun setActiveVkLink(link: String) {
|
||||
viewModelScope.launch {
|
||||
prefs.updateActiveServer {
|
||||
@@ -301,7 +292,6 @@ class SettingsViewModel(
|
||||
fun applyServerConfig(
|
||||
listen: String,
|
||||
connect: String,
|
||||
tcpForward: Boolean,
|
||||
obfProfile: String,
|
||||
obfKey: String
|
||||
) {
|
||||
@@ -317,7 +307,6 @@ class SettingsViewModel(
|
||||
s.copy(
|
||||
proxyListen = listen,
|
||||
proxyConnect = connect,
|
||||
client = s.client.copy(tcpForward = tcpForward),
|
||||
opts = s.opts.copy(obfProfile = obfProfile, obfKey = effKey)
|
||||
)
|
||||
}
|
||||
@@ -337,7 +326,6 @@ class SettingsViewModel(
|
||||
id: String,
|
||||
listen: String,
|
||||
connect: String,
|
||||
tcpForward: Boolean,
|
||||
obfProfile: String,
|
||||
obfKey: String
|
||||
) {
|
||||
@@ -351,7 +339,6 @@ class SettingsViewModel(
|
||||
target.copy(
|
||||
proxyListen = listen,
|
||||
proxyConnect = connect,
|
||||
client = target.client.copy(tcpForward = tcpForward),
|
||||
opts = target.opts.copy(obfProfile = obfProfile, obfKey = effKey)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -120,8 +120,6 @@ class ImportViewModel(
|
||||
serverAddress = link.peer,
|
||||
vkLink = st.vkLink.trim(),
|
||||
provider = link.provider,
|
||||
tcpForward = link.mode == "tcp",
|
||||
bond = link.bond,
|
||||
useUdp = link.transport == "udp",
|
||||
threads = link.n.takeIf { it > 0 } ?: ClientConfig.DEFAULT_THREADS,
|
||||
streamsPerCred = link.streamsPerCred.takeIf { it > 0 }
|
||||
|
||||
@@ -114,7 +114,7 @@
|
||||
<string name="setup_checking_ssh_desc">Проверка окружения сервера</string>
|
||||
<string name="setup_mode_section">Режим работы</string>
|
||||
<string name="setup_mode_vpn_desc">Поднимем WireGuard на сервере - весь трафик устройства пойдёт через туннель.</string>
|
||||
<string name="setup_mode_proxy_desc">Прокси перенаправляет трафик на ваш бэкенд на сервере: Xray или WireGuard.</string>
|
||||
<string name="setup_mode_proxy_desc">Прокси перенаправляет трафик на ваш UDP-бэкенд на сервере: WireGuard или AmneziaWG.</string>
|
||||
<string name="setup_wg_found">WireGuard найден</string>
|
||||
<string name="setup_wg_found_desc">Порт %1$d станет бэкендом. Для этого устройства добавится отдельный пир - конфиг подставится сам.</string>
|
||||
<string name="setup_wg_missing">WireGuard не найден</string>
|
||||
@@ -128,7 +128,6 @@
|
||||
<string name="setup_port_roll">Сгенерировать порт</string>
|
||||
<string name="setup_backend_port_label">Порт бэкенда</string>
|
||||
<string name="setup_backend_port_desc">Локальный порт вашего VPN/бэкенда на сервере (127.0.0.1)</string>
|
||||
<string name="setup_backend_protocol_desc">UDP - WireGuard/AmneziaWG, TCP - Xray</string>
|
||||
<string name="setup_turn_section">TURN-прокси</string>
|
||||
<string name="setup_listen_port_desc">Внешний UDP-порт сервера, случайный из диапазона 56000–56999</string>
|
||||
<string name="setup_obf_hint_rtpopus">Трафик маскируется под голосовой звонок. Ключ сгенерируется и подставится автоматически.</string>
|
||||
@@ -203,9 +202,6 @@
|
||||
<string name="streams_per_cred_recommendation">Сколько TURN-потоков обслуживает один VK-аккаунт</string>
|
||||
<string name="streams_per_cred_format">Потоков на аккаунт: %1$d</string>
|
||||
|
||||
<string name="tcp_forward_mode">Режим</string>
|
||||
<string name="client_bond">Bond (стрипинг TCP)</string>
|
||||
<string name="client_bond_desc">Распределяет TCP по smux-сессиям. Только в TCP-режиме.</string>
|
||||
<string name="obf_profile_title">Обфускация</string>
|
||||
<string name="obf_none">Выкл</string>
|
||||
<string name="obf_rtpopus">rtpopus</string>
|
||||
@@ -251,7 +247,7 @@
|
||||
<string name="listen_ip_desc">IP-адрес, который прослушивает сервер. 0.0.0.0 - все интерфейсы. Укажите конкретный WAN IP, если на хосте несколько адресов.</string>
|
||||
<string name="turn_client_address">Адрес TURN-клиента</string>
|
||||
<string name="turn_client_placeholder">127.0.0.1:40537</string>
|
||||
<string name="turn_client_desc">Локальный WireGuard/Xray-клиент на стороне сервера</string>
|
||||
<string name="turn_client_desc">Локальный WireGuard-бэкенд на стороне сервера</string>
|
||||
<string name="server_install">Установить</string>
|
||||
<string name="server_update">Обновить</string>
|
||||
<string name="server_obf_key_label">Obf-ключ (64 hex)</string>
|
||||
@@ -324,7 +320,6 @@
|
||||
<string name="notif_proxy_connect_error">Ошибка подключения</string>
|
||||
<string name="notif_proxy_wireguard_error">Ошибка WireGuard</string>
|
||||
<string name="notif_proxy_vpn_permission">Нужно разрешение VPN - откройте приложение</string>
|
||||
<string name="tcp_blocked_by_tunnel">Туннель работает только поверх UDP-проброса</string>
|
||||
|
||||
<!-- CaptchaWebViewDialog -->
|
||||
<string name="captcha_title">Проверка VK</string>
|
||||
@@ -526,6 +521,6 @@
|
||||
<!-- О проекте -->
|
||||
<string name="settings_about">О проекте</string>
|
||||
<string name="settings_about_desc">Версия, описание и ссылки</string>
|
||||
<string name="about_description">Free Turn проксирует WireGuard и Xray-трафик через публичные TURN-сервера. Открытый исходный код и никакой телеметрии: все настройки хранятся только на вашем устройстве.</string>
|
||||
<string name="about_description">Free Turn проксирует WireGuard-трафик через публичные TURN-сервера. Открытый исходный код и никакой телеметрии: все настройки хранятся только на вашем устройстве.</string>
|
||||
<string name="about_links">Ссылки</string>
|
||||
</resources>
|
||||
@@ -43,27 +43,22 @@ class CoreConfigJsonTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun tunnelForcesUdpProxyMode() {
|
||||
fun tunnelCarriesWgConfig() {
|
||||
val wg = base.copy(
|
||||
tcpForward = true,
|
||||
bond = true,
|
||||
tunnelTransport = TunnelTransport.WIREGUARD,
|
||||
wireGuardConfig = "[Interface]\nAddress = 10.8.0.2/32\n",
|
||||
)
|
||||
val proxy = parse(wg)["proxy"]!!.jsonObject
|
||||
assertEquals("udp", proxy["mode"]!!.jsonPrimitive.content)
|
||||
assertEquals(false, proxy["bond"]!!.jsonPrimitive.content.toBoolean())
|
||||
|
||||
val tunnel = parse(wg)["tunnel"]!!.jsonObject
|
||||
assertEquals("wg", tunnel["mode"]!!.jsonPrimitive.content)
|
||||
assertEquals(ClientConfig.WG_MTU, tunnel["mtu"]!!.jsonPrimitive.content.toInt())
|
||||
}
|
||||
|
||||
// Лишний ключ в proxy валит старт ядра (DisallowUnknownFields), а не тест схемы.
|
||||
@Test
|
||||
fun tcpModeKeepsBondWithoutTunnel() {
|
||||
val proxy = parse(base.copy(tcpForward = true, bond = true))["proxy"]!!.jsonObject
|
||||
assertEquals("tcp", proxy["mode"]!!.jsonPrimitive.content)
|
||||
assertEquals(true, proxy["bond"]!!.jsonPrimitive.content.toBoolean())
|
||||
fun proxyHasOnlyListen() {
|
||||
val proxy = parse(base.copy(localPort = "127.0.0.1:9001"))["proxy"]!!.jsonObject
|
||||
assertEquals(setOf("listen"), proxy.keys)
|
||||
assertEquals("127.0.0.1:9001", proxy["listen"]!!.jsonPrimitive.content)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -36,7 +36,7 @@ class FreeturnLinkTest {
|
||||
@Test
|
||||
fun `golden typical - encode matches Go field order and omitempty`() {
|
||||
// Эталон: байт-в-байт вывод Go json.Marshal(wire) для типового конфига.
|
||||
val goldenJson = """{"v":1,"provider":"vk","peer":"1.2.3.4:56000","mode":"udp",""" +
|
||||
val goldenJson = """{"v":1,"provider":"vk","peer":"1.2.3.4:56000","transport":"udp",""" +
|
||||
""""obf":"rtpopus","key":"d823fa01cb3e0609b67322f7cf984c4ee2e4ce2e294936fc24ef38c9e59f4799","name":"Papa"}"""
|
||||
val golden = "freeturn://" + Base64.getUrlEncoder().withoutPadding()
|
||||
.encodeToString(goldenJson.toByteArray(Charsets.UTF_8))
|
||||
@@ -44,7 +44,7 @@ class FreeturnLinkTest {
|
||||
val link = FreeturnLink(
|
||||
provider = "vk",
|
||||
peer = "1.2.3.4:56000",
|
||||
mode = "udp",
|
||||
transport = "udp",
|
||||
obfProfile = "rtpopus",
|
||||
obfKey = "d823fa01cb3e0609b67322f7cf984c4ee2e4ce2e294936fc24ef38c9e59f4799",
|
||||
name = "Papa"
|
||||
@@ -58,8 +58,6 @@ class FreeturnLinkTest {
|
||||
provider = "vk",
|
||||
peer = "example.com:56000",
|
||||
transport = "udp",
|
||||
mode = "tcp",
|
||||
bond = true,
|
||||
obfProfile = "rtpopus",
|
||||
obfKey = "00".repeat(32),
|
||||
n = 10,
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.freeturn.app.data.config.ClientConfig
|
||||
import com.freeturn.app.data.server.Server
|
||||
import com.freeturn.app.data.server.ServerOpts
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class ShareLinkBuilderTest {
|
||||
@@ -12,16 +11,12 @@ class ShareLinkBuilderTest {
|
||||
private val key = "ab".repeat(32)
|
||||
|
||||
private fun server(
|
||||
tcpForward: Boolean = false,
|
||||
bond: Boolean = false,
|
||||
useUdp: Boolean = false,
|
||||
opts: ServerOpts = ServerOpts()
|
||||
) = Server(
|
||||
name = "Мой сервер",
|
||||
client = ClientConfig(
|
||||
serverAddress = "1.2.3.4:56000",
|
||||
tcpForward = tcpForward,
|
||||
bond = bond,
|
||||
useUdp = useUdp
|
||||
),
|
||||
opts = opts
|
||||
@@ -29,26 +24,34 @@ class ShareLinkBuilderTest {
|
||||
|
||||
@Test
|
||||
fun `server run args take priority over local opts`() {
|
||||
val srv = server(tcpForward = true, opts = ServerOpts("rtpopus", "ff".repeat(32)))
|
||||
val info = ShareInfo(mode = "udp", obfProfile = "rtpopus", obfKey = key, wgBackend = true)
|
||||
val srv = server(opts = ServerOpts("rtpopus", "ff".repeat(32)))
|
||||
val info = ShareInfo(obfProfile = "rtpopus", obfKey = key, wgBackend = true)
|
||||
val link = FreeturnLink.parse(ShareLinkBuilder.build(srv, info, "Гость", null)).getOrThrow()
|
||||
assertEquals("", link.mode) // сервер реально в udp, не локальный tcpForward
|
||||
assertEquals(key, link.obfKey) // ключ с сервера, не локальный
|
||||
assertEquals("Гость", link.name)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `fallback to local opts when server never started`() {
|
||||
val srv = server(tcpForward = true, bond = true, opts = ServerOpts("rtpopus", key))
|
||||
val srv = server(opts = ServerOpts("rtpopus", key))
|
||||
val link = FreeturnLink.parse(
|
||||
ShareLinkBuilder.build(srv, ShareInfo(), "u", null)
|
||||
).getOrThrow()
|
||||
assertEquals("tcp", link.mode)
|
||||
assertTrue(link.bond)
|
||||
assertEquals("rtpopus", link.obfProfile)
|
||||
assertEquals(key, link.obfKey)
|
||||
}
|
||||
|
||||
// Сервер стартовал без обфускации - локальные opts всё равно не подмешиваем.
|
||||
@Test
|
||||
fun `started server without obf wins over local opts`() {
|
||||
val srv = server(opts = ServerOpts("rtpopus", key))
|
||||
val link = FreeturnLink.parse(
|
||||
ShareLinkBuilder.build(srv, ShareInfo(obfProfile = "none"), "u", null)
|
||||
).getOrThrow()
|
||||
assertEquals("", link.obfProfile)
|
||||
assertEquals("", link.obfKey)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `invalid obf key is dropped`() {
|
||||
val srv = server(opts = ServerOpts("rtpopus", "короткий"))
|
||||
@@ -77,10 +80,8 @@ class ShareLinkBuilderTest {
|
||||
|
||||
@Test
|
||||
fun `proxy share has no wg field`() {
|
||||
val raw = ShareLinkBuilder.build(server(), ShareInfo(mode = "tcp"), "u", null)
|
||||
val link = FreeturnLink.parse(raw).getOrThrow()
|
||||
assertEquals("", link.wgConf)
|
||||
assertEquals("tcp", link.mode)
|
||||
val raw = ShareLinkBuilder.build(server(), ShareInfo(obfProfile = "none"), "u", null)
|
||||
assertEquals("", FreeturnLink.parse(raw).getOrThrow().wgConf)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user