From 71ad8f2fd1eb4c8cd80313c686739f5dfacee57b Mon Sep 17 00:00:00 2001
From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com>
Date: Thu, 11 Jul 2024 21:44:31 +0400
Subject: [PATCH] multiplatform: check temporary proxy error (#4442)
* android: check temporary proxy error
* version error
* errors
---
.../chat/simplex/common/model/SimpleXAPI.kt | 110 ++++++++++++++++++
.../commonMain/resources/MR/base/strings.xml | 4 +
2 files changed, 114 insertions(+)
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 7633b0c808..07d3451d86 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
@@ -1809,6 +1809,80 @@ object ChatController {
)
true
}
+ r is CR.ChatCmdError && r.chatError is ChatError.ChatErrorAgent
+ && r.chatError.agentError is AgentErrorType.BROKER
+ && r.chatError.agentError.brokerErr is BrokerErrorType.HOST -> {
+ AlertManager.shared.showAlertMsg(
+ generalGetString(MR.strings.connection_error),
+ String.format(generalGetString(MR.strings.network_error_broker_host_desc), serverHostname(r.chatError.agentError.brokerAddress))
+ )
+ true
+ }
+ r is CR.ChatCmdError && r.chatError is ChatError.ChatErrorAgent
+ && r.chatError.agentError is AgentErrorType.BROKER
+ && r.chatError.agentError.brokerErr is BrokerErrorType.TRANSPORT
+ && r.chatError.agentError.brokerErr.transportErr is SMPTransportError.Version -> {
+ AlertManager.shared.showAlertMsg(
+ generalGetString(MR.strings.connection_error),
+ String.format(generalGetString(MR.strings.network_error_broker_version_desc), serverHostname(r.chatError.agentError.brokerAddress))
+ )
+ true
+ }
+ r is CR.ChatCmdError && r.chatError is ChatError.ChatErrorAgent
+ && r.chatError.agentError is AgentErrorType.SMP
+ && r.chatError.agentError.smpErr is SMPErrorType.PROXY ->
+ proxyErrorAlert(r.chatError.agentError.smpErr.proxyErr)
+ r is CR.ChatCmdError && r.chatError is ChatError.ChatErrorAgent
+ && r.chatError.agentError is AgentErrorType.PROXY
+ && r.chatError.agentError.proxyErr is ProxyClientError.ProxyProtocolError
+ && r.chatError.agentError.proxyErr.protocolErr is SMPErrorType.PROXY ->
+ proxyErrorAlert(r.chatError.agentError.proxyErr.protocolErr.proxyErr)
+ else -> false
+ }
+ }
+
+ private fun proxyErrorAlert(pe: ProxyError): Boolean {
+ return when {
+ pe is ProxyError.BROKER
+ && pe.brokerErr is BrokerErrorType.TIMEOUT -> {
+ AlertManager.shared.showAlertMsg(
+ generalGetString(MR.strings.private_routing_error),
+ generalGetString(MR.strings.please_try_later)
+ )
+ true
+ }
+ pe is ProxyError.BROKER
+ && pe.brokerErr is BrokerErrorType.NETWORK -> {
+ AlertManager.shared.showAlertMsg(
+ generalGetString(MR.strings.private_routing_error),
+ generalGetString(MR.strings.please_try_later)
+ )
+ true
+ }
+ pe is ProxyError.NO_SESSION -> {
+ AlertManager.shared.showAlertMsg(
+ generalGetString(MR.strings.private_routing_error),
+ generalGetString(MR.strings.please_try_later)
+ )
+ true
+ }
+ pe is ProxyError.BROKER
+ && pe.brokerErr is BrokerErrorType.HOST -> {
+ AlertManager.shared.showAlertMsg(
+ generalGetString(MR.strings.private_routing_error),
+ generalGetString(MR.strings.srv_error_host)
+ )
+ true
+ }
+ pe is ProxyError.BROKER
+ && pe.brokerErr is BrokerErrorType.TRANSPORT
+ && pe.brokerErr.transportErr is SMPTransportError.Version -> {
+ AlertManager.shared.showAlertMsg(
+ generalGetString(MR.strings.private_routing_error),
+ generalGetString(MR.strings.srv_error_version)
+ )
+ true
+ }
else -> false
}
}
@@ -5500,6 +5574,7 @@ sealed class AgentErrorType {
is SMP -> "SMP ${smpErr.string}"
// is NTF -> "NTF ${ntfErr.string}"
is XFTP -> "XFTP ${xftpErr.string}"
+ is PROXY -> "PROXY $proxyServer $relayServer ${proxyErr.string}"
is RCP -> "RCP ${rcpErr.string}"
is BROKER -> "BROKER ${brokerErr.string}"
is AGENT -> "AGENT ${agentErr.string}"
@@ -5512,6 +5587,7 @@ sealed class AgentErrorType {
@Serializable @SerialName("SMP") class SMP(val smpErr: SMPErrorType): AgentErrorType()
// @Serializable @SerialName("NTF") class NTF(val ntfErr: SMPErrorType): AgentErrorType()
@Serializable @SerialName("XFTP") class XFTP(val xftpErr: XFTPErrorType): AgentErrorType()
+ @Serializable @SerialName("PROXY") class PROXY(val proxyServer: String, val relayServer: String, val proxyErr: ProxyClientError): AgentErrorType()
@Serializable @SerialName("RCP") class RCP(val rcpErr: RCErrorType): AgentErrorType()
@Serializable @SerialName("BROKER") class BROKER(val brokerAddress: String, val brokerErr: BrokerErrorType): AgentErrorType()
@Serializable @SerialName("AGENT") class AGENT(val agentErr: SMPAgentError): AgentErrorType()
@@ -5576,22 +5652,42 @@ sealed class SMPErrorType {
is BLOCK -> "BLOCK"
is SESSION -> "SESSION"
is CMD -> "CMD ${cmdErr.string}"
+ is PROXY -> "PROXY ${proxyErr.string}"
is AUTH -> "AUTH"
+ is CRYPTO -> "CRYPTO"
is QUOTA -> "QUOTA"
is NO_MSG -> "NO_MSG"
is LARGE_MSG -> "LARGE_MSG"
+ is EXPIRED -> "EXPIRED"
is INTERNAL -> "INTERNAL"
}
@Serializable @SerialName("BLOCK") class BLOCK: SMPErrorType()
@Serializable @SerialName("SESSION") class SESSION: SMPErrorType()
@Serializable @SerialName("CMD") class CMD(val cmdErr: ProtocolCommandError): SMPErrorType()
+ @Serializable @SerialName("PROXY") class PROXY(val proxyErr: ProxyError): SMPErrorType()
@Serializable @SerialName("AUTH") class AUTH: SMPErrorType()
+ @Serializable @SerialName("CRYPTO") class CRYPTO: SMPErrorType()
@Serializable @SerialName("QUOTA") class QUOTA: SMPErrorType()
@Serializable @SerialName("NO_MSG") class NO_MSG: SMPErrorType()
@Serializable @SerialName("LARGE_MSG") class LARGE_MSG: SMPErrorType()
+ @Serializable @SerialName("EXPIRED") class EXPIRED: SMPErrorType()
@Serializable @SerialName("INTERNAL") class INTERNAL: SMPErrorType()
}
+@Serializable
+sealed class ProxyError {
+ val string: String get() = when (this) {
+ is PROTOCOL -> "PROTOCOL ${protocolErr.string}"
+ is BROKER -> "BROKER ${brokerErr.string}"
+ is BASIC_AUTH -> "BASIC_AUTH"
+ is NO_SESSION -> "NO_SESSION"
+ }
+ @Serializable @SerialName("PROTOCOL") class PROTOCOL(val protocolErr: SMPErrorType): ProxyError()
+ @Serializable @SerialName("BROKER") class BROKER(val brokerErr: BrokerErrorType): ProxyError()
+ @Serializable @SerialName("BASIC_AUTH") class BASIC_AUTH: ProxyError()
+ @Serializable @SerialName("NO_SESSION") class NO_SESSION: ProxyError()
+}
+
@Serializable
sealed class ProtocolCommandError {
val string: String get() = when (this) {
@@ -5614,12 +5710,14 @@ sealed class ProtocolCommandError {
sealed class SMPTransportError {
val string: String get() = when (this) {
is BadBlock -> "badBlock"
+ is Version -> "version"
is LargeMsg -> "largeMsg"
is BadSession -> "badSession"
is NoServerAuth -> "noServerAuth"
is Handshake -> "handshake ${handshakeErr.string}"
}
@Serializable @SerialName("badBlock") class BadBlock: SMPTransportError()
+ @Serializable @SerialName("version") class Version: SMPTransportError()
@Serializable @SerialName("largeMsg") class LargeMsg: SMPTransportError()
@Serializable @SerialName("badSession") class BadSession: SMPTransportError()
@Serializable @SerialName("noServerAuth") class NoServerAuth: SMPTransportError()
@@ -5692,6 +5790,18 @@ sealed class XFTPErrorType {
@Serializable @SerialName("INTERNAL") object INTERNAL: XFTPErrorType()
}
+@Serializable
+sealed class ProxyClientError {
+ val string: String get() = when (this) {
+ is ProxyProtocolError -> "ProxyProtocolError $protocolErr"
+ is ProxyUnexpectedResponse -> "ProxyUnexpectedResponse $responseStr"
+ is ProxyResponseError -> "ProxyResponseError $responseErr"
+ }
+ @Serializable @SerialName("protocolError") class ProxyProtocolError(val protocolErr: SMPErrorType): ProxyClientError()
+ @Serializable @SerialName("unexpectedResponse") class ProxyUnexpectedResponse(val responseStr: String): ProxyClientError()
+ @Serializable @SerialName("responseError") class ProxyResponseError(val responseErr: SMPErrorType): ProxyClientError()
+}
+
@Serializable
sealed class RCErrorType {
val string: String get() = when (this) {
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 e2d10ae5ae..8b6e4d8e06 100644
--- a/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml
+++ b/apps/multiplatform/common/src/commonMain/resources/MR/base/strings.xml
@@ -112,6 +112,10 @@
Connection timeout
Connection error
Please check your network connection with %1$s and try again.
+ Server address is incompatible with network settings: %1$s.
+ Server version is incompatible with your app: %1$s.
+ Private routing error
+ Please try later.
Error sending message
Error creating message
Error loading details