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>
This commit is contained in:
Evgeny
2024-10-08 14:36:08 +01:00
committed by GitHub
parent c6ece8afdd
commit 6907f02ea6
7 changed files with 41 additions and 18 deletions
@@ -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.")
}
}
+6 -2
View File
@@ -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 {
+2 -2
View File
@@ -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<OnionHosts>(
public let networkSessionModeGroupDefault = EnumDefault<TransportSessionMode>(
defaults: groupDefaults,
forKey: GROUP_DEFAULT_NETWORK_SESSION_MODE,
withDefault: .user
withDefault: .session
)
public let networkSMPProxyModeGroupDefault = EnumDefault<SMPProxyMode>(
@@ -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)
}
}
@@ -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)
}
@@ -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<TransportSessionMode> =
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))
}
}
@@ -811,8 +811,12 @@
<string name="network_use_onion_hosts_required_desc">Onion hosts will be required for connection.\nPlease note: you will not be able to connect to the servers without .onion address.</string>
<string name="network_session_mode_transport_isolation">Transport isolation</string>
<string name="network_session_mode_user">Chat profile</string>
<string name="network_session_mode_session">App session</string>
<string name="network_session_mode_server">Server</string>
<string name="network_session_mode_entity">Connection</string>
<string name="network_session_mode_user_description"><![CDATA[A separate TCP connection (and SOCKS credential) will be used <b>for each chat profile you have in the app</b>.]]></string>
<string name="network_session_mode_session_description">New SOCKS credentials will be used every time you start the app.</string>
<string name="network_session_mode_server_description">New SOCKS credentials will be used for each server.</string>
<string name="network_session_mode_entity_description"><![CDATA[A separate TCP connection (and SOCKS credential) will be used <b>for each contact and group member</b>.\n<b>Please note</b>: if you have many connections, your battery and traffic consumption can be substantially higher and some connections may fail.]]></string>
<string name="update_network_session_mode_question">Update transport isolation mode?</string>
<string name="disable_onion_hosts_when_not_supported"><![CDATA[Set <i>Use .onion hosts</i> to No if SOCKS proxy does not support them.]]></string>