From 8b4b264992a096540c22c118c12b08df3e1b2ddd Mon Sep 17 00:00:00 2001 From: jubb Date: Tue, 29 Jun 2021 14:20:52 +1000 Subject: [PATCH] fix: 421 errors not being handled properly by sendOnionRequest and prevent retrying with stale swarm data, no longer crash with large NotifyPNServerJob.kt payload in Kryo deserialization --- .../libsession/messaging/jobs/NotifyPNServerJob.kt | 3 ++- .../java/org/session/libsession/snode/OnionRequestAPI.kt | 9 +++++---- .../main/java/org/session/libsession/snode/SnodeAPI.kt | 4 +--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/NotifyPNServerJob.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/NotifyPNServerJob.kt index 5b3225b117..90262fc358 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/NotifyPNServerJob.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/NotifyPNServerJob.kt @@ -7,6 +7,7 @@ import nl.komponents.kovenant.functional.map import okhttp3.MediaType import okhttp3.Request import okhttp3.RequestBody +import org.session.libsession.messaging.jobs.Job.Companion.MAX_BUFFER_SIZE import org.session.libsession.messaging.sending_receiving.notifications.PushNotificationAPI import org.session.libsession.messaging.utilities.Data @@ -64,7 +65,7 @@ class NotifyPNServerJob(val message: SnodeMessage) : Job { val kryo = Kryo() kryo.isRegistrationRequired = false val serializedMessage = ByteArray(4096) - val output = Output(serializedMessage) + val output = Output(serializedMessage, MAX_BUFFER_SIZE) kryo.writeObject(output, message) output.close() return Data.Builder() diff --git a/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt b/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt index a188b4a5a8..775b4ff24c 100644 --- a/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt +++ b/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt @@ -433,11 +433,12 @@ object OnionRequestAPI { internal fun sendOnionRequest(method: Snode.Method, parameters: Map<*, *>, snode: Snode, publicKey: String? = null): Promise, Exception> { val payload = mapOf( "method" to method.rawValue, "params" to parameters ) return sendOnionRequest(Destination.Snode(snode), payload).recover { exception -> - val httpRequestFailedException = exception as? HTTP.HTTPRequestFailedException - if (httpRequestFailedException != null) { - val error = SnodeAPI.handleSnodeError(httpRequestFailedException.statusCode, httpRequestFailedException.json, snode, publicKey) - if (error != null) { throw error } + val error = when (exception) { + is HTTP.HTTPRequestFailedException -> SnodeAPI.handleSnodeError(exception.statusCode, exception.json, snode, publicKey) + is HTTPRequestFailedAtDestinationException -> SnodeAPI.handleSnodeError(exception.statusCode, exception.json, snode, publicKey) + else -> null } + if (error != null) { throw error } throw exception } } diff --git a/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt b/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt index 281bd906e7..bec77506eb 100644 --- a/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt +++ b/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt @@ -290,9 +290,7 @@ object SnodeAPI { getTargetSnodes(destination).map { swarm -> swarm.map { snode -> val parameters = message.toJSON() - retryIfNeeded(maxRetryCount) { - invoke(Snode.Method.SendMessage, snode, destination, parameters) - } + invoke(Snode.Method.SendMessage, snode, destination, parameters) }.toSet() } }