mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-25 11:05:25 +00:00
Close group poller issue
This commit is contained in:
parent
999ce6e413
commit
966b8e0d7f
@ -59,12 +59,12 @@ class ClosedGroupPoller(
|
||||
job = scope.launch(executor) {
|
||||
while (isActive) {
|
||||
try {
|
||||
val swarmNodes = SnodeAPI.getSwarm(closedGroupSessionId.hexString).await().toMutableSet()
|
||||
val swarmNodes = SnodeAPI.fetchSwarmNodes(closedGroupSessionId.hexString).toMutableSet()
|
||||
var currentSnode: Snode? = null
|
||||
|
||||
while (isActive) {
|
||||
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}")
|
||||
currentSnode = swarmNodes.random()
|
||||
swarmNodes.remove(currentSnode)
|
||||
|
@ -312,6 +312,23 @@ object SnodeAPI {
|
||||
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.
|
||||
@ -706,7 +723,23 @@ object SnodeAPI {
|
||||
parameters = mapOf("requests" to requests),
|
||||
responseClass = BatchResponse::class.java,
|
||||
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(
|
||||
|
Loading…
Reference in New Issue
Block a user