From 1c7841333abd911f7a64d0a5fff663e0d0c4f76c Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Thu, 25 May 2023 13:24:24 +1000 Subject: [PATCH] fix: add max size and maybe fix the non-200 sub requests for batches (for 421s in particular) --- .../sending_receiving/pollers/Poller.kt | 5 +++-- .../org/session/libsession/snode/SnodeAPI.kt | 20 +++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt index 4a9ffb31c8..e5ea6bca9c 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt @@ -171,7 +171,7 @@ class Poller(private val configFactory: ConfigFactoryProtocol, debounceTimer: Ti runBlocking(Dispatchers.IO) { val requestSparseArray = SparseArray() // get messages - SnodeAPI.buildAuthenticatedRetrieveBatchRequest(snode, userPublicKey)!!.also { personalMessages -> + SnodeAPI.buildAuthenticatedRetrieveBatchRequest(snode, userPublicKey, maxSize = -2)!!.also { personalMessages -> // namespaces here should always be set requestSparseArray[personalMessages.namespace!!] = personalMessages } @@ -181,7 +181,8 @@ class Poller(private val configFactory: ConfigFactoryProtocol, debounceTimer: Ti hashesToExtend += config.currentHashes() SnodeAPI.buildAuthenticatedRetrieveBatchRequest( snode, userPublicKey, - config.configNamespace() + config.configNamespace(), + maxSize = -8 ) }.forEach { request -> // namespaces here should always be set 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 a6cc9147ec..54d1780989 100644 --- a/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt +++ b/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt @@ -453,7 +453,7 @@ object SnodeAPI { ) } - fun buildAuthenticatedRetrieveBatchRequest(snode: Snode, publicKey: String, namespace: Int = 0): SnodeBatchRequestInfo? { + fun buildAuthenticatedRetrieveBatchRequest(snode: Snode, publicKey: String, namespace: Int = 0, maxSize: Int? = null): SnodeBatchRequestInfo? { val lastHashValue = database.getLastMessageHashValue(snode, publicKey, namespace) ?: "" val params = mutableMapOf( "pubkey" to publicKey, @@ -486,6 +486,9 @@ object SnodeAPI { if (namespace != 0) { params["namespace"] = namespace } + if (maxSize != null) { + params["max_size"] = maxSize + } return SnodeBatchRequestInfo( Snode.Method.Retrieve.rawValue, params, @@ -511,7 +514,20 @@ object SnodeAPI { val parameters = mutableMapOf( "requests" to requests ) - return invoke(if (sequence) Snode.Method.Sequence else Snode.Method.Batch, snode, parameters, publicKey) + return invoke(if (sequence) Snode.Method.Sequence else Snode.Method.Batch, snode, parameters, publicKey).success { rawResponses -> + val responseList = (rawResponses["results"] as List) + responseList.forEachIndexed { index, response -> + if (response["code"] as? Int != 200) { + Log.w("Loki", "response code was not 200") + handleSnodeError( + response["code"] as? Int ?: 0, + response, + snode, + publicKey + ) + } + } + } } fun getExpiries(messageHashes: List, publicKey: String) : RawResponsePromise {