From 6907f02ea628b395afff4a2c119c0bafbdce8613 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Tue, 8 Oct 2024 14:36:08 +0100 Subject: [PATCH] android, desktop: additional options for transport isolation mode (#4994) * android, desktop: additional options for transport isolation mode * small changes --------- Co-authored-by: Avently <7953703+avently@users.noreply.github.com> --- .../UserSettings/AdvancedNetworkSettings.swift | 18 ++++++++++++------ apps/ios/SimpleXChat/APITypes.swift | 8 ++++++-- apps/ios/SimpleXChat/AppGroup.swift | 4 ++-- .../chat/simplex/common/model/SimpleXAPI.kt | 7 +++++-- .../usersettings/AdvancedNetworkSettings.kt | 2 +- .../views/usersettings/NetworkAndServers.kt | 16 +++++++++++----- .../commonMain/resources/MR/base/strings.xml | 4 ++++ 7 files changed, 41 insertions(+), 18 deletions(-) diff --git a/apps/ios/Shared/Views/UserSettings/AdvancedNetworkSettings.swift b/apps/ios/Shared/Views/UserSettings/AdvancedNetworkSettings.swift index 9884c6e877..754ca3cf6b 100644 --- a/apps/ios/Shared/Views/UserSettings/AdvancedNetworkSettings.swift +++ b/apps/ios/Shared/Views/UserSettings/AdvancedNetworkSettings.swift @@ -196,11 +196,14 @@ struct AdvancedNetworkSettings: View { if developerTools { Section { Picker("Transport isolation", selection: $netCfg.sessionMode) { - ForEach(TransportSessionMode.values, id: \.self) { Text($0.text) } + let modes = TransportSessionMode.values.contains(netCfg.sessionMode) + ? TransportSessionMode.values + : TransportSessionMode.values + [netCfg.sessionMode] + ForEach(modes, id: \.self) { Text($0.text) } } .frame(height: 36) } footer: { - Text(sessionModeInfo(netCfg.sessionMode)) + sessionModeInfo(netCfg.sessionMode) .foregroundColor(theme.colors.secondary) } } @@ -353,10 +356,13 @@ struct AdvancedNetworkSettings: View { } } - private func sessionModeInfo(_ mode: TransportSessionMode) -> LocalizedStringKey { - switch mode { - case .user: return "A separate TCP connection will be used **for each chat profile you have in the app**." - case .entity: return "A separate TCP connection will be used **for each contact and group member**.\n**Please note**: if you have many connections, your battery and traffic consumption can be substantially higher and some connections may fail." + private func sessionModeInfo(_ mode: TransportSessionMode) -> Text { + let userMode = Text("A separate TCP connection will be used **for each chat profile you have in the app**.") + return switch mode { + case .user: userMode + case .session: userMode + Text("\n") + Text("New SOCKS credentials will be used every time you start the app.") + case .server: userMode + Text("\n") + Text("New SOCKS credentials will be used for each server.") + case .entity: Text("A separate TCP connection will be used **for each contact and group member**.\n**Please note**: if you have many connections, your battery and traffic consumption can be substantially higher and some connections may fail.") } } diff --git a/apps/ios/SimpleXChat/APITypes.swift b/apps/ios/SimpleXChat/APITypes.swift index ef7bb34947..bff150f58f 100644 --- a/apps/ios/SimpleXChat/APITypes.swift +++ b/apps/ios/SimpleXChat/APITypes.swift @@ -1491,18 +1491,22 @@ public enum OnionHosts: String, Identifiable { public enum TransportSessionMode: String, Codable, Identifiable { case user + case session + case server case entity public var text: LocalizedStringKey { switch self { - case .user: return "User profile" + case .user: return "Chat profile" + case .session: return "App session" + case .server: return "Server" case .entity: return "Connection" } } public var id: TransportSessionMode { self } - public static let values: [TransportSessionMode] = [.user, .entity] + public static let values: [TransportSessionMode] = [.user, .session, .server, .entity] } public struct KeepAliveOpts: Codable, Equatable { diff --git a/apps/ios/SimpleXChat/AppGroup.swift b/apps/ios/SimpleXChat/AppGroup.swift index f07d0b5737..afbcff2bf3 100644 --- a/apps/ios/SimpleXChat/AppGroup.swift +++ b/apps/ios/SimpleXChat/AppGroup.swift @@ -67,7 +67,7 @@ public func registerGroupDefaults() { GROUP_DEFAULT_NTF_ENABLE_LOCAL: false, GROUP_DEFAULT_NTF_ENABLE_PERIODIC: false, GROUP_DEFAULT_NETWORK_USE_ONION_HOSTS: OnionHosts.no.rawValue, - GROUP_DEFAULT_NETWORK_SESSION_MODE: TransportSessionMode.user.rawValue, + GROUP_DEFAULT_NETWORK_SESSION_MODE: TransportSessionMode.session.rawValue, GROUP_DEFAULT_NETWORK_SMP_PROXY_MODE: SMPProxyMode.unknown.rawValue, GROUP_DEFAULT_NETWORK_SMP_PROXY_FALLBACK: SMPProxyFallback.allowProtected.rawValue, GROUP_DEFAULT_NETWORK_TCP_CONNECT_TIMEOUT: NetCfg.defaults.tcpConnectTimeout, @@ -232,7 +232,7 @@ public let networkUseOnionHostsGroupDefault = EnumDefault( public let networkSessionModeGroupDefault = EnumDefault( defaults: groupDefaults, forKey: GROUP_DEFAULT_NETWORK_SESSION_MODE, - withDefault: .user + withDefault: .session ) public let networkSMPProxyModeGroupDefault = EnumDefault( diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt index 2e98d0bc89..eec7a0f30d 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt @@ -3654,7 +3654,7 @@ data class NetCfg( val socksMode: SocksMode = SocksMode.Always, val hostMode: HostMode = HostMode.OnionViaSocks, val requiredHostMode: Boolean = false, - val sessionMode: TransportSessionMode = TransportSessionMode.User, + val sessionMode: TransportSessionMode = TransportSessionMode.default, val smpProxyMode: SMPProxyMode = SMPProxyMode.Unknown, val smpProxyFallback: SMPProxyFallback = SMPProxyFallback.AllowProtected, val smpWebPort: Boolean = false, @@ -3781,10 +3781,13 @@ enum class SMPProxyFallback { @Serializable enum class TransportSessionMode { @SerialName("user") User, + @SerialName("session") Session, + @SerialName("server") Server, @SerialName("entity") Entity; companion object { - val default = User + val default = Session + val safeValues = arrayOf(User, Session, Server) } } diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/AdvancedNetworkSettings.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/AdvancedNetworkSettings.kt index 6dc0f74df3..35e0a3c6d8 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/AdvancedNetworkSettings.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/AdvancedNetworkSettings.kt @@ -218,7 +218,7 @@ fun ModalData.AdvancedNetworkSettingsView(showModal: (ModalData.() -> Unit) -> U SectionDividerSpaced(maxTopPadding = true) } - if (currentRemoteHost == null && developerTools) { + if (currentRemoteHost == null) { SectionView(stringResource(MR.strings.network_session_mode_transport_isolation).uppercase()) { SessionModePicker(sessionMode, showModal, updateSessionMode) } diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/NetworkAndServers.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/NetworkAndServers.kt index 5272353c20..dc3def3884 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/NetworkAndServers.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/NetworkAndServers.kt @@ -164,9 +164,7 @@ fun NetworkAndServersView() { val showCustomModal = { it: @Composable (close: () -> Unit) -> Unit -> ModalManager.fullscreen.showCustomModal { close -> it(close) }} UseSocksProxySwitch(networkUseSocksProxy, toggleSocksProxy) SettingsActionItem(painterResource(MR.images.ic_settings_ethernet), stringResource(MR.strings.network_socks_proxy_settings), { showCustomModal { SocksProxySettings(networkUseSocksProxy.value, networkProxy, onionHosts, sessionMode.value, true, it) } }) - if (developerTools) { - SessionModePicker(sessionMode, showModal, updateSessionMode) - } + SessionModePicker(sessionMode, showModal, updateSessionMode) } @Composable @@ -458,9 +456,17 @@ fun SessionModePicker( ) { val density = LocalDensity.current val values = remember { - TransportSessionMode.values().map { + val safeModes = TransportSessionMode.safeValues + val modes: Array = + if (appPrefs.developerTools.get()) TransportSessionMode.values() + else if (safeModes.contains(sessionMode.value)) safeModes + else safeModes + sessionMode.value + modes.map { + val userModeDescr: AnnotatedString = escapedHtmlToAnnotatedString(generalGetString(MR.strings.network_session_mode_user_description), density) when (it) { - TransportSessionMode.User -> ValueTitleDesc(TransportSessionMode.User, generalGetString(MR.strings.network_session_mode_user), escapedHtmlToAnnotatedString(generalGetString(MR.strings.network_session_mode_user_description), density)) + TransportSessionMode.User -> ValueTitleDesc(TransportSessionMode.User, generalGetString(MR.strings.network_session_mode_user), userModeDescr) + TransportSessionMode.Session -> ValueTitleDesc(TransportSessionMode.Session, generalGetString(MR.strings.network_session_mode_session), userModeDescr + AnnotatedString("\n") + escapedHtmlToAnnotatedString(generalGetString(MR.strings.network_session_mode_session_description), density)) + TransportSessionMode.Server -> ValueTitleDesc(TransportSessionMode.Server, generalGetString(MR.strings.network_session_mode_server), userModeDescr + AnnotatedString("\n") + escapedHtmlToAnnotatedString(generalGetString(MR.strings.network_session_mode_server_description), density)) TransportSessionMode.Entity -> ValueTitleDesc(TransportSessionMode.Entity, generalGetString(MR.strings.network_session_mode_entity), escapedHtmlToAnnotatedString(generalGetString(MR.strings.network_session_mode_entity_description), density)) } } diff --git a/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml b/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml index 6ab9a268bd..c344382423 100644 --- a/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml +++ b/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml @@ -811,8 +811,12 @@ Onion hosts will be required for connection.\nPlease note: you will not be able to connect to the servers without .onion address. Transport isolation Chat profile + App session + Server Connection for each chat profile you have in the app.]]> + New SOCKS credentials will be used every time you start the app. + New SOCKS credentials will be used for each server. for each contact and group member.\nPlease note: if you have many connections, your battery and traffic consumption can be substantially higher and some connections may fail.]]> Update transport isolation mode? Use .onion hosts to No if SOCKS proxy does not support them.]]>