Tweak to snode filtering

This commit is contained in:
ThomasSession 2024-07-23 17:19:16 +10:00
parent 2644e7c11a
commit af9f581f18

View File

@ -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
}