mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-28 20:45:17 +00:00
feat: add raw requests for modifying expiry and getting expiries
This commit is contained in:
parent
edb5ff09e9
commit
378601afa5
@ -218,6 +218,23 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
|||||||
.onEach(globalSearchViewModel::postQuery)
|
.onEach(globalSearchViewModel::postQuery)
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
// launch(IO) {
|
||||||
|
// val publicKey = TextSecurePreferences.getLocalNumber(this@HomeActivity) ?: return@launch
|
||||||
|
// // do a expire
|
||||||
|
// try {
|
||||||
|
// val promise = SnodeAPI.alterTtl(
|
||||||
|
// listOf(
|
||||||
|
// "message hashes"
|
||||||
|
// ),
|
||||||
|
// some long in the future,
|
||||||
|
// publicKey
|
||||||
|
// )
|
||||||
|
// val result = promise.get()
|
||||||
|
// Log.d("TTL", "ttl result: $result")
|
||||||
|
// } catch (e: Exception) {
|
||||||
|
// Log.e("TTL", "Expiry didn't work", e)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
// Get group results and display them
|
// Get group results and display them
|
||||||
launch {
|
launch {
|
||||||
globalSearchViewModel.result.collect { result ->
|
globalSearchViewModel.result.collect { result ->
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.session.libsession.messaging.sending_receiving.pollers
|
package org.session.libsession.messaging.sending_receiving.pollers
|
||||||
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import nl.komponents.kovenant.Deferred
|
import nl.komponents.kovenant.Deferred
|
||||||
import nl.komponents.kovenant.Promise
|
import nl.komponents.kovenant.Promise
|
||||||
@ -30,6 +31,7 @@ class Poller(private val configFactory: ConfigFactoryProtocol) {
|
|||||||
private var hasStarted: Boolean = false
|
private var hasStarted: Boolean = false
|
||||||
private val usedSnodes: MutableSet<Snode> = mutableSetOf()
|
private val usedSnodes: MutableSet<Snode> = mutableSetOf()
|
||||||
var isCaughtUp = false
|
var isCaughtUp = false
|
||||||
|
var configPollingJob: Job? = null
|
||||||
|
|
||||||
// region Settings
|
// region Settings
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -383,6 +383,7 @@ object SnodeAPI {
|
|||||||
userEd25519KeyPair.secretKey.asBytes
|
userEd25519KeyPair.secretKey.asBytes
|
||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
Log.e("Loki", "Signing data failed with user secret key", e)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
params["timestamp"] = timestamp
|
params["timestamp"] = timestamp
|
||||||
@ -404,6 +405,77 @@ object SnodeAPI {
|
|||||||
return invoke(Snode.Method.Batch, snode, parameters, publicKey)
|
return invoke(Snode.Method.Batch, snode, parameters, publicKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getExpiries(messageHashes: List<String>, publicKey: String) : RawResponsePromise {
|
||||||
|
val userEd25519KeyPair = MessagingModuleConfiguration.shared.getUserED25519KeyPair() ?: return Promise.ofFail(NullPointerException("No user key pair"))
|
||||||
|
return retryIfNeeded(maxRetryCount) {
|
||||||
|
val timestamp = System.currentTimeMillis() + clockOffset
|
||||||
|
val params = mutableMapOf(
|
||||||
|
"pubkey" to publicKey,
|
||||||
|
"messages" to messageHashes,
|
||||||
|
"timestamp" to timestamp
|
||||||
|
)
|
||||||
|
val signData = "${Snode.Method.GetExpiries.rawValue}$timestamp${messageHashes.joinToString(separator = "")}".toByteArray()
|
||||||
|
|
||||||
|
val ed25519PublicKey = userEd25519KeyPair.publicKey.asHexString
|
||||||
|
val signature = ByteArray(Sign.BYTES)
|
||||||
|
try {
|
||||||
|
sodium.cryptoSignDetached(
|
||||||
|
signature,
|
||||||
|
signData,
|
||||||
|
signData.size.toLong(),
|
||||||
|
userEd25519KeyPair.secretKey.asBytes
|
||||||
|
)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("Loki", "Signing data failed with user secret key", e)
|
||||||
|
return@retryIfNeeded Promise.ofFail(e)
|
||||||
|
}
|
||||||
|
params["pubkey_ed25519"] = ed25519PublicKey
|
||||||
|
params["signature"] = Base64.encodeBytes(signature)
|
||||||
|
getSingleTargetSnode(publicKey).bind { snode ->
|
||||||
|
invoke(Snode.Method.GetExpiries, snode, params, publicKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun alterTtl(messageHashes: List<String>, newExpiry: Long, publicKey: String, extend: Boolean = false, shorten: Boolean = false): RawResponsePromise {
|
||||||
|
val userEd25519KeyPair = MessagingModuleConfiguration.shared.getUserED25519KeyPair() ?: return Promise.ofFail(NullPointerException("No user key pair"))
|
||||||
|
return retryIfNeeded(maxRetryCount) {
|
||||||
|
val params = mutableMapOf(
|
||||||
|
"expiry" to newExpiry,
|
||||||
|
"messages" to messageHashes,
|
||||||
|
)
|
||||||
|
if (extend) {
|
||||||
|
params["extend"] = true
|
||||||
|
} else if (shorten) {
|
||||||
|
params["shorten"] = true
|
||||||
|
}
|
||||||
|
val shortenOrExtend = if (extend) "extend" else if (shorten) "shorten" else ""
|
||||||
|
|
||||||
|
val signData = "${Snode.Method.Expire.rawValue}$shortenOrExtend$newExpiry${messageHashes.joinToString(separator = "")}".toByteArray()
|
||||||
|
|
||||||
|
val ed25519PublicKey = userEd25519KeyPair.publicKey.asHexString
|
||||||
|
val signature = ByteArray(Sign.BYTES)
|
||||||
|
try {
|
||||||
|
sodium.cryptoSignDetached(
|
||||||
|
signature,
|
||||||
|
signData,
|
||||||
|
signData.size.toLong(),
|
||||||
|
userEd25519KeyPair.secretKey.asBytes
|
||||||
|
)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("Loki", "Signing data failed with user secret key", e)
|
||||||
|
return@retryIfNeeded Promise.ofFail(e)
|
||||||
|
}
|
||||||
|
params["pubkey"] = publicKey
|
||||||
|
params["pubkey_ed25519"] = ed25519PublicKey
|
||||||
|
params["signature"] = Base64.encodeBytes(signature)
|
||||||
|
|
||||||
|
getSingleTargetSnode(publicKey).bind { snode ->
|
||||||
|
invoke(Snode.Method.Expire, snode, params, publicKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getMessages(publicKey: String): MessageListPromise {
|
fun getMessages(publicKey: String): MessageListPromise {
|
||||||
return retryIfNeeded(maxRetryCount) {
|
return retryIfNeeded(maxRetryCount) {
|
||||||
getSingleTargetSnode(publicKey).bind { snode ->
|
getSingleTargetSnode(publicKey).bind { snode ->
|
||||||
|
@ -11,7 +11,9 @@ class Snode(val address: String, val port: Int, val publicKeySet: KeySet?) {
|
|||||||
OxenDaemonRPCCall("oxend_request"),
|
OxenDaemonRPCCall("oxend_request"),
|
||||||
Info("info"),
|
Info("info"),
|
||||||
DeleteAll("delete_all"),
|
DeleteAll("delete_all"),
|
||||||
Batch("batch")
|
Batch("batch"),
|
||||||
|
Expire("expire"),
|
||||||
|
GetExpiries("get_expiries")
|
||||||
}
|
}
|
||||||
|
|
||||||
data class KeySet(val ed25519Key: String, val x25519Key: String)
|
data class KeySet(val ed25519Key: String, val x25519Key: String)
|
||||||
|
Loading…
Reference in New Issue
Block a user