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

pull/620/head
jubb 3 years ago
parent 7e114fc2ac
commit 8b4b264992

@ -7,6 +7,7 @@ import nl.komponents.kovenant.functional.map
import okhttp3.MediaType import okhttp3.MediaType
import okhttp3.Request import okhttp3.Request
import okhttp3.RequestBody 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.sending_receiving.notifications.PushNotificationAPI
import org.session.libsession.messaging.utilities.Data import org.session.libsession.messaging.utilities.Data
@ -64,7 +65,7 @@ class NotifyPNServerJob(val message: SnodeMessage) : Job {
val kryo = Kryo() val kryo = Kryo()
kryo.isRegistrationRequired = false kryo.isRegistrationRequired = false
val serializedMessage = ByteArray(4096) val serializedMessage = ByteArray(4096)
val output = Output(serializedMessage) val output = Output(serializedMessage, MAX_BUFFER_SIZE)
kryo.writeObject(output, message) kryo.writeObject(output, message)
output.close() output.close()
return Data.Builder() return Data.Builder()

@ -433,11 +433,12 @@ object OnionRequestAPI {
internal fun sendOnionRequest(method: Snode.Method, parameters: Map<*, *>, snode: Snode, publicKey: String? = null): Promise<Map<*, *>, Exception> { internal fun sendOnionRequest(method: Snode.Method, parameters: Map<*, *>, snode: Snode, publicKey: String? = null): Promise<Map<*, *>, Exception> {
val payload = mapOf( "method" to method.rawValue, "params" to parameters ) val payload = mapOf( "method" to method.rawValue, "params" to parameters )
return sendOnionRequest(Destination.Snode(snode), payload).recover { exception -> return sendOnionRequest(Destination.Snode(snode), payload).recover { exception ->
val httpRequestFailedException = exception as? HTTP.HTTPRequestFailedException val error = when (exception) {
if (httpRequestFailedException != null) { is HTTP.HTTPRequestFailedException -> SnodeAPI.handleSnodeError(exception.statusCode, exception.json, snode, publicKey)
val error = SnodeAPI.handleSnodeError(httpRequestFailedException.statusCode, httpRequestFailedException.json, snode, publicKey) is HTTPRequestFailedAtDestinationException -> SnodeAPI.handleSnodeError(exception.statusCode, exception.json, snode, publicKey)
if (error != null) { throw error } else -> null
} }
if (error != null) { throw error }
throw exception throw exception
} }
} }

@ -290,9 +290,7 @@ object SnodeAPI {
getTargetSnodes(destination).map { swarm -> getTargetSnodes(destination).map { swarm ->
swarm.map { snode -> swarm.map { snode ->
val parameters = message.toJSON() val parameters = message.toJSON()
retryIfNeeded(maxRetryCount) { invoke(Snode.Method.SendMessage, snode, destination, parameters)
invoke(Snode.Method.SendMessage, snode, destination, parameters)
}
}.toSet() }.toSet()
} }
} }

Loading…
Cancel
Save