Namespace retrieval and storage with auth (#880)

* feat: add migration and fork info for upcoming auth and closed group retrieval updates

* feat: add closed group poller calls and include namespace to parse raw messages function

* feat: add DB upgrades and queries for namespaces

* fix: fix the polling for post-HF signatures and group messages

* fix: realise we need a compound key for namespaces in received hashes, test explicitly setting namespace

* feat: add setForkInfo implementation

* refactor: include default fork info command on create, refactor migration to use new table since we can't add constraints in alter for PK, replace `lastHash` with `last_hash` in case that fixes paging

* refactor: include namespace and use when statement for closed group polling

* refactor: revert to main net

* refactor: use namespace constants

* refactor: revert to testnet and log the poll result

* fix: use or to log either poller

* fix: revert to default network and add more logging, only set the latest fork info if it is an increment

* build: update minor version

* refactor: use single target snode and namespace list for message sending

* fix: link previews and expiring messages in closed groups
This commit is contained in:
Harris
2022-05-18 10:20:57 +10:00
committed by GitHub
parent 7fc3599c25
commit 00f06ab034
14 changed files with 325 additions and 125 deletions

View File

@@ -1,8 +1,9 @@
package org.session.libsignal.database
import org.session.libsignal.crypto.ecc.ECKeyPair
import org.session.libsignal.utilities.ForkInfo
import org.session.libsignal.utilities.Snode
import java.util.*
import java.util.Date
interface LokiAPIDatabaseProtocol {
@@ -13,10 +14,10 @@ interface LokiAPIDatabaseProtocol {
fun setOnionRequestPaths(newValue: List<List<Snode>>)
fun getSwarm(publicKey: String): Set<Snode>?
fun setSwarm(publicKey: String, newValue: Set<Snode>)
fun getLastMessageHashValue(snode: Snode, publicKey: String): String?
fun setLastMessageHashValue(snode: Snode, publicKey: String, newValue: String)
fun getReceivedMessageHashValues(publicKey: String): Set<String>?
fun setReceivedMessageHashValues(publicKey: String, newValue: Set<String>)
fun getLastMessageHashValue(snode: Snode, publicKey: String, namespace: Int): String?
fun setLastMessageHashValue(snode: Snode, publicKey: String, newValue: String, namespace: Int)
fun getReceivedMessageHashValues(publicKey: String, namespace: Int): Set<String>?
fun setReceivedMessageHashValues(publicKey: String, newValue: Set<String>, namespace: Int)
fun getAuthToken(server: String): String?
fun setAuthToken(server: String, newValue: String?)
fun setUserCount(group: Long, server: String, newValue: Int)
@@ -33,4 +34,7 @@ interface LokiAPIDatabaseProtocol {
fun getClosedGroupEncryptionKeyPairs(groupPublicKey: String): List<ECKeyPair>
fun getLatestClosedGroupEncryptionKeyPair(groupPublicKey: String): ECKeyPair?
fun isClosedGroup(groupPublicKey: String): Boolean
fun getForkInfo(): ForkInfo
fun setForkInfo(forkInfo: ForkInfo)
}

View File

@@ -0,0 +1,20 @@
package org.session.libsignal.utilities
data class ForkInfo(val hf: Int, val sf: Int) {
companion object {
const val DEFAULT_HF = 18
const val DEFAULT_SF = 1
val DEFAULT = ForkInfo(DEFAULT_HF, DEFAULT_SF)
val baseTable = arrayOf(10,100,1000,10000,100000)
}
operator fun compareTo(other: ForkInfo): Int {
val base = baseTable.first { it > sf && it > other.sf }
return (hf*base - other.hf*base) + (sf - other.sf)
}
}
// add info here for when various features are active
fun ForkInfo.hasNamespaces() = hf >= 19
fun ForkInfo.defaultRequiresAuth() = hf >= 19 && sf >= 1

View File

@@ -0,0 +1,7 @@
package org.session.libsignal.utilities
object Namespace {
const val DEFAULT = 0
const val UNAUTHENTICATED_CLOSED_GROUP = -10
const val CONFIGURATION = 5
}