feat: add snode method delete_all with data class for params, refactoring ClearAllDataDialog.kt to handle async requests better and prevent ANR

This commit is contained in:
Harris
2021-06-17 18:29:05 +10:00
parent ac4b576abe
commit 11f64a1d1a
4 changed files with 102 additions and 9 deletions

View File

@@ -6,7 +6,6 @@ import android.os.Build
import com.goterl.lazysodium.LazySodiumAndroid
import com.goterl.lazysodium.SodiumAndroid
import com.goterl.lazysodium.exceptions.SodiumException
import com.goterl.lazysodium.interfaces.AEAD
import com.goterl.lazysodium.interfaces.GenericHash
import com.goterl.lazysodium.interfaces.PwHash
import com.goterl.lazysodium.interfaces.SecretBox
@@ -298,6 +297,30 @@ object SnodeAPI {
}
}
/** Deletes all messages owned by the given pubkey on this SN and broadcasts the delete request to
* all other swarm members.
* Returns dict of:
* - "swarms" dict mapping ed25519 pubkeys (in hex) of swarm members to dict values of:
* - "failed" and other failure keys -- see `recursive`.
* - "deleted": hashes of deleted messages.
* - "signature": signature of ( PUBKEY_HEX || TIMESTAMP || DELETEDHASH[0] || ... || DELETEDHASH[N] ), signed
* by the node's ed25519 pubkey.
*/
fun deleteAllMessages(deleteMessage: SnodeDeleteMessage): Promise<Set<RawResponsePromise>, Exception> {
// considerations: timestamp off in retrying logic, not being able to re-sign with latest timestamp? do we just not retry this as it will be synchronous
val destination = if (useTestnet) deleteMessage.pubKey.removing05PrefixIfNeeded() else deleteMessage.pubKey
return retryIfNeeded(maxRetryCount) {
getTargetSnodes(destination).map { swarm ->
swarm.map { snode ->
val parameters = deleteMessage.toJSON()
retryIfNeeded(maxRetryCount) {
invoke(Snode.Method.DeleteAll, snode, destination, parameters)
}
}.toSet()
}
}
}
// Parsing
private fun parseSnodes(rawResponse: Any): List<Snode> {
val json = rawResponse as? Map<*, *>

View File

@@ -0,0 +1,30 @@
package org.session.libsession.snode
import org.session.libsignal.utilities.removing05PrefixIfNeeded
data class SnodeDeleteMessage(
/**
* The hex encoded public key of the user.
*/
val pubKey: String,
/**
* The timestamp at which this request was initiated, in milliseconds since unix epoch.
* Must be within Must be within ±60s of the current time.
* (For clients it is recommended to retrieve a timestamp via `info` first, to avoid client time sync issues).
*/
val timestamp: Long,
/**
* an Ed25519 signature of ( "delete_all" || timestamp ), signed by the ed25519
*/
val signature: String,
) {
internal fun toJSON(): Map<String, String> {
return mapOf(
"pubkey" to if (SnodeAPI.useTestnet) pubKey.removing05PrefixIfNeeded() else pubKey,
"timestamp" to timestamp.toString(),
"signature" to signature
)
}
}