Close group poller issue

This commit is contained in:
SessionHero01 2024-10-08 14:51:28 +11:00
parent 999ce6e413
commit 966b8e0d7f
No known key found for this signature in database
2 changed files with 36 additions and 3 deletions

View File

@ -59,12 +59,12 @@ class ClosedGroupPoller(
job = scope.launch(executor) { job = scope.launch(executor) {
while (isActive) { while (isActive) {
try { try {
val swarmNodes = SnodeAPI.getSwarm(closedGroupSessionId.hexString).await().toMutableSet() val swarmNodes = SnodeAPI.fetchSwarmNodes(closedGroupSessionId.hexString).toMutableSet()
var currentSnode: Snode? = null var currentSnode: Snode? = null
while (isActive) { while (isActive) {
if (currentSnode == null) { if (currentSnode == null) {
check(swarmNodes.isNotEmpty()) { "No swarm nodes found" } check(swarmNodes.isNotEmpty()) { "No more swarm nodes found" }
Log.d(TAG, "No current snode, getting a new one. Remaining in pool = ${swarmNodes.size - 1}") Log.d(TAG, "No current snode, getting a new one. Remaining in pool = ${swarmNodes.size - 1}")
currentSnode = swarmNodes.random() currentSnode = swarmNodes.random()
swarmNodes.remove(currentSnode) swarmNodes.remove(currentSnode)

View File

@ -312,6 +312,23 @@ object SnodeAPI {
database.setSwarm(publicKey, it) database.setSwarm(publicKey, it)
} }
/**
* Fetch swarm nodes for the specific public key.
*
* Note: this differs from [getSwarm] in that it doesn't store the swarm nodes in the database.
* This always fetches from network.
*/
suspend fun fetchSwarmNodes(publicKey: String): List<Snode> {
val randomNode = getRandomSnode().await()
val response = invoke(
method = Snode.Method.GetSwarm,
snode = randomNode, parameters = buildMap { this["pubKey"] = publicKey },
publicKey = publicKey
).await()
return parseSnodes(response)
}
/** /**
* Build parameters required to call authenticated storage API. * Build parameters required to call authenticated storage API.
@ -706,8 +723,24 @@ object SnodeAPI {
parameters = mapOf("requests" to requests), parameters = mapOf("requests" to requests),
responseClass = BatchResponse::class.java, responseClass = BatchResponse::class.java,
publicKey = publicKey publicKey = publicKey
).also { resp ->
// If there's a unsuccessful response, go through specific logic to handle
// potential snode errors.
val firstError = resp.results.firstOrNull { !it.isSuccessful }
if (firstError != null) {
handleSnodeError(
statusCode = firstError.code,
json = if (firstError.body.isObject) {
JsonUtil.fromJson(firstError.body, Map::class.java)
} else {
null
},
snode = snode,
publicKey = publicKey
) )
} }
}
}
fun getExpiries( fun getExpiries(
messageHashes: List<String>, messageHashes: List<String>,