mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
Optimise SnodeAPI further
This commit is contained in:
parent
c1d40cdbe7
commit
3c8302f7a4
@ -455,7 +455,7 @@ object SnodeAPI {
|
||||
val hashes = messageHashes.takeIf { it.size != 1 } ?: (messageHashes + "///////////////////////////////////////////") // TODO remove this when bug is fixed on nodes.
|
||||
return retryIfNeeded(maxRetryCount) {
|
||||
val timestamp = System.currentTimeMillis() + clockOffset
|
||||
val signData = "${Snode.Method.GetExpiries.rawValue}$timestamp${hashes.joinToString(separator = "")}".toByteArray()
|
||||
val signData = sequenceOf(Snode.Method.GetExpiries.rawValue).plus(timestamp.toString()).plus(hashes).toByteArray()
|
||||
|
||||
val ed25519PublicKey = userEd25519KeyPair.publicKey.asHexString
|
||||
val signature = try {
|
||||
@ -499,7 +499,7 @@ object SnodeAPI {
|
||||
|
||||
val shortenOrExtend = if (extend) "extend" else if (shorten) "shorten" else ""
|
||||
|
||||
val signData = "${Snode.Method.Expire.rawValue}$shortenOrExtend$newExpiry${messageHashes.joinToString(separator = "")}".toByteArray()
|
||||
val signData = sequenceOf(Snode.Method.Expire.rawValue).plus(shortenOrExtend).plus(newExpiry.toString()).plus(messageHashes).toByteArray()
|
||||
|
||||
val signature = try {
|
||||
signAndEncode(signData, userEd25519KeyPair)
|
||||
@ -633,7 +633,7 @@ object SnodeAPI {
|
||||
getSingleTargetSnode(userPublicKey).bind { snode ->
|
||||
retryIfNeeded(maxRetryCount) {
|
||||
getNetworkTime(snode).bind { (_, timestamp) ->
|
||||
val verificationData = (Snode.Method.DeleteAll.rawValue + Namespace.ALL + timestamp.toString()).toByteArray()
|
||||
val verificationData = sequenceOf(Snode.Method.DeleteAll.rawValue, Namespace.ALL, timestamp.toString()).toByteArray()
|
||||
val deleteMessageParams = buildMap {
|
||||
this["pubkey"] = userPublicKey
|
||||
this["pubkey_ed25519"] = userED25519KeyPair.publicKey.asHexString
|
||||
@ -722,9 +722,8 @@ object SnodeAPI {
|
||||
if (newFailureCount >= snodeFailureThreshold) {
|
||||
Log.d("Loki", "Failure threshold reached for: $snode; dropping it.")
|
||||
publicKey?.let { dropSnodeFromSwarmIfNeeded(snode, it) }
|
||||
snodePool -= snode
|
||||
Log.d("Loki", "Snode pool count: ${snodePool.count()}.")
|
||||
snodeFailureCount.remove(snode)
|
||||
snodePool = (snodePool - snode).also { Log.d("Loki", "Snode pool count: ${it.count()}.") }
|
||||
snodeFailureCount -= snode
|
||||
}
|
||||
}
|
||||
when (statusCode) {
|
||||
|
@ -52,6 +52,8 @@ class Snode(val address: String, val port: Int, val publicKeySet: KeySet?, val v
|
||||
fun Version(value: String) = CACHE.getOrElse(value) {
|
||||
Snode.Version(value)
|
||||
}
|
||||
|
||||
fun Version(parts: List<Int>) = Version(parts.joinToString("."))
|
||||
}
|
||||
|
||||
@JvmInline
|
||||
@ -66,14 +68,12 @@ class Snode(val address: String, val port: Int, val publicKeySet: KeySet?, val v
|
||||
}
|
||||
}
|
||||
|
||||
constructor(parts: List<Int>): this(
|
||||
internal constructor(parts: List<Int>): this(
|
||||
parts.asSequence()
|
||||
.map { it.toByte().toULong() }
|
||||
.foldToVersionAsULong()
|
||||
)
|
||||
|
||||
constructor(value: Int): this(value.toULong())
|
||||
|
||||
internal constructor(value: String): this(
|
||||
value.splitToSequence(".")
|
||||
.map { it.toULongOrNull() ?: 0UL }
|
||||
|
Loading…
x
Reference in New Issue
Block a user