From af9f581f18396fbde42415fe05993b50ecc8ce7e Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Tue, 23 Jul 2024 17:19:16 +1000 Subject: [PATCH] Tweak to snode filtering --- .../org/session/libsession/snode/OnionRequestAPI.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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 b9fcdab50c..fb3522969b 100644 --- a/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt +++ b/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt @@ -194,16 +194,18 @@ object OnionRequestAPI { val result = listOf( guardSnode ) + (0 until (pathSize - 1)).mapIndexed() { index, _ -> var pathSnode = unusedSnodes.getRandomElement() - // we want to make sure the last node in the path is above version 2.8.0 + // For the last node: We need to make sure the version is >= 2.8.0 // to help with an issue that will disappear once the nodes are all updated if(index == pathSize - 2) { - // because we are now grabbing the whole node pool there should always - // be a node that is above version 2.8.0 - while(Util.compareVersions(pathSnode.version, "2.8.0") < 0) { - pathSnode = unusedSnodes.getRandomElement() + val suitableSnodes = unusedSnodes.filter { Util.compareVersions(it.version, "2.8.0") >= 0 } + pathSnode = if (suitableSnodes.isNotEmpty()) { + suitableSnodes.random() + } else { + throw InsufficientSnodesException() } } + // remove the snode from the unused list and return it unusedSnodes = unusedSnodes.minus(pathSnode) pathSnode }