add configuration and storage

This commit is contained in:
Ryan ZHAO 2020-12-02 16:38:30 +11:00
parent c1f84732ad
commit da71fdfe44
4 changed files with 122 additions and 0 deletions

View File

@ -0,0 +1,22 @@
package org.session.libsession.messaging
import org.session.libsignal.libsignal.loki.SessionResetProtocol
import org.session.libsignal.libsignal.state.*
import org.session.libsignal.metadata.certificate.CertificateValidator
import org.session.libsignal.service.loki.protocol.closedgroups.SharedSenderKeysDatabaseProtocol
class Configuration(val storage: StorageProtocol, val signalStorage: SignalProtocolStore, val sskDatabase: SharedSenderKeysDatabaseProtocol, val sessionResetImp: SessionResetProtocol, val certificateValidator: CertificateValidator) {
companion object {
lateinit var shared: Configuration
fun configure(storage: StorageProtocol,
signalStorage: SignalProtocolStore,
sskDatabase: SharedSenderKeysDatabaseProtocol,
sessionResetImp: SessionResetProtocol,
certificateValidator: CertificateValidator
) {
if (Companion::shared.isInitialized) { return }
shared = Configuration(storage, signalStorage, sskDatabase, sessionResetImp, certificateValidator)
}
}
}

View File

@ -0,0 +1,71 @@
package org.session.libsession.messaging
import org.session.libsession.messaging.jobs.AttachmentUploadJob
import org.session.libsession.messaging.jobs.Job
import org.session.libsession.messaging.jobs.MessageSendJob
import org.session.libsession.messaging.opengroups.OpenGroup
import org.session.libsignal.libsignal.ecc.ECKeyPair
import org.session.libsignal.libsignal.ecc.ECPrivateKey
interface StorageProtocol {
// General
fun getUserPublicKey(): String?
fun getUserKeyPair(): ECKeyPair?
fun getUserDisplayName(): String?
fun getUserProfileKey(): ByteArray?
fun getUserProfilePictureURL(): String?
// Shared Sender Keys
fun getClosedGroupPrivateKey(publicKey: String): ECPrivateKey?
fun isClosedGroup(publicKey: String): Boolean
// Jobs
fun persist(job: Job)
fun markJobAsSucceeded(job: Job)
fun markJobAsFailed(job: Job)
fun getAllPendingJobs(type: String): List<Job>
fun getAttachmentUploadJob(attachmentID: String): AttachmentUploadJob?
fun getMessageSendJob(messageSendJobID: String): MessageSendJob?
fun resumeMessageSendJobIfNeeded(messageSendJobID: String)
fun isJobCanceled(job: Job): Boolean
// Authorization
fun getAuthToken(server: String): String?
fun setAuthToken(server: String, newValue: String?)
fun removeAuthToken(server: String)
// Open Groups
fun getOpenGroup(threadID: String): OpenGroup?
fun getThreadID(openGroupID: String): String?
// Open Group Public Keys
fun getOpenGroupPublicKey(server: String): String?
fun setOpenGroupPublicKey(server: String, newValue: String)
// Last Message Server ID
fun getLastMessageServerID(group: Long, server: String): Long?
fun setLastMessageServerID(group: Long, server: String, newValue: Long)
fun removeLastMessageServerID(group: Long, server: String)
// Last Deletion Server ID
fun getLastDeletionServerID(group: Long, server: String): Long?
fun setLastDeletionServerID(group: Long, server: String, newValue: Long)
fun removeLastDeletionServerID(group: Long, server: String)
// Open Group Metadata
fun setUserCount(group: Long, server: String, newValue: Int)
fun setOpenGroupProfilePictureURL(group: Long, server: String, newValue: String)
fun getOpenGroupProfilePictureURL(group: Long, server: String): String?
fun updateTitle(groupID: String, newValue: String)
fun updateProfilePicture(groupID: String, newValue: ByteArray)
fun getSessionRequestSentTimestamp(publicKey: String): Long?
fun setSessionRequestSentTimestamp(publicKey: String, newValue: Long)
fun getSessionRequestProcessedTimestamp(publicKey: String): Long?
fun setSessionRequestProcessedTimestamp(publicKey: String, newValue: Long)
}

View File

@ -0,0 +1,14 @@
package org.session.libsession.snode
import org.session.libsignal.service.loki.utilities.Broadcaster
class Configuration(val storage: SnodeStorageProtocol, val broadcaster: Broadcaster) {
companion object {
lateinit var shared: Configuration
fun configure(storage: SnodeStorageProtocol, broadcaster: Broadcaster) {
if (Companion::shared.isInitialized) { return }
shared = Configuration(storage, broadcaster)
}
}
}

View File

@ -0,0 +1,15 @@
package org.session.libsession.snode
interface SnodeStorageProtocol {
fun getSnodePool(): Set<Snode>
fun setSnodePool(newValue: Set<Snode>)
fun getOnionRequestPaths(): List<List<Snode>>
fun clearOnionRequestPaths()
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>)
}