mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-25 11:05:25 +00:00
feat: add in more config factory for volatile
This commit is contained in:
parent
f7c5953f5d
commit
28e5794624
@ -1,6 +1,7 @@
|
|||||||
package org.thoughtcrime.securesms.dependencies
|
package org.thoughtcrime.securesms.dependencies
|
||||||
|
|
||||||
import network.loki.messenger.libsession_util.Contacts
|
import network.loki.messenger.libsession_util.Contacts
|
||||||
|
import network.loki.messenger.libsession_util.ConversationVolatileConfig
|
||||||
import network.loki.messenger.libsession_util.UserProfile
|
import network.loki.messenger.libsession_util.UserProfile
|
||||||
import org.session.libsession.utilities.ConfigFactoryProtocol
|
import org.session.libsession.utilities.ConfigFactoryProtocol
|
||||||
import org.session.libsignal.protos.SignalServiceProtos.SharedConfigMessage
|
import org.session.libsignal.protos.SignalServiceProtos.SharedConfigMessage
|
||||||
@ -12,16 +13,20 @@ class ConfigFactory(private val configDatabase: ConfigDatabase, private val mayb
|
|||||||
fun keyPairChanged() { // this should only happen restoring or clearing data
|
fun keyPairChanged() { // this should only happen restoring or clearing data
|
||||||
_userConfig?.free()
|
_userConfig?.free()
|
||||||
_contacts?.free()
|
_contacts?.free()
|
||||||
|
_convoVolatileConfig?.free()
|
||||||
_userConfig = null
|
_userConfig = null
|
||||||
_contacts = null
|
_contacts = null
|
||||||
|
_convoVolatileConfig = null
|
||||||
}
|
}
|
||||||
|
|
||||||
private val userLock = Object()
|
private val userLock = Object()
|
||||||
private var _userConfig: UserProfile? = null
|
private var _userConfig: UserProfile? = null
|
||||||
private val contactLock = Object()
|
private val contactLock = Object()
|
||||||
private var _contacts: Contacts? = null
|
private var _contacts: Contacts? = null
|
||||||
|
private val convoVolatileLock = Object()
|
||||||
|
private var _convoVolatileConfig: ConversationVolatileConfig? = null
|
||||||
|
|
||||||
override val userConfig: UserProfile? = synchronized(userLock) {
|
override val user: UserProfile? = synchronized(userLock) {
|
||||||
if (_userConfig == null) {
|
if (_userConfig == null) {
|
||||||
val (secretKey, publicKey) = maybeGetUserInfo() ?: return@synchronized null
|
val (secretKey, publicKey) = maybeGetUserInfo() ?: return@synchronized null
|
||||||
val userDump = configDatabase.retrieveConfig(SharedConfigMessage.Kind.USER_PROFILE.name, publicKey)
|
val userDump = configDatabase.retrieveConfig(SharedConfigMessage.Kind.USER_PROFILE.name, publicKey)
|
||||||
@ -47,9 +52,22 @@ class ConfigFactory(private val configDatabase: ConfigDatabase, private val mayb
|
|||||||
_contacts
|
_contacts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override val convoVolatile: ConversationVolatileConfig? = synchronized(convoVolatileLock) {
|
||||||
|
if (_convoVolatileConfig == null) {
|
||||||
|
val (secretKey, publicKey) = maybeGetUserInfo() ?: return@synchronized null
|
||||||
|
val convoDump = configDatabase.retrieveConfig(SharedConfigMessage.Kind.CONVO_INFO_VOLATILE.name, publicKey)
|
||||||
|
_convoVolatileConfig = if (convoDump != null) {
|
||||||
|
ConversationVolatileConfig.newInstance(secretKey, convoDump)
|
||||||
|
} else {
|
||||||
|
ConversationVolatileConfig.newInstance(secretKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_convoVolatileConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun saveUserConfigDump() {
|
override fun saveUserConfigDump() {
|
||||||
val dumped = userConfig?.dump() ?: return
|
val dumped = user?.dump() ?: return
|
||||||
val (_, publicKey) = maybeGetUserInfo() ?: return
|
val (_, publicKey) = maybeGetUserInfo() ?: return
|
||||||
configDatabase.storeConfig(SharedConfigMessage.Kind.USER_PROFILE.name, publicKey, dumped)
|
configDatabase.storeConfig(SharedConfigMessage.Kind.USER_PROFILE.name, publicKey, dumped)
|
||||||
}
|
}
|
||||||
@ -60,4 +78,9 @@ class ConfigFactory(private val configDatabase: ConfigDatabase, private val mayb
|
|||||||
configDatabase.storeConfig(SharedConfigMessage.Kind.CONTACTS.name, publicKey, dumped)
|
configDatabase.storeConfig(SharedConfigMessage.Kind.CONTACTS.name, publicKey, dumped)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun saveConvoVolatileConfigDump() {
|
||||||
|
val dumped = convoVolatile?.dump() ?: return
|
||||||
|
val (_, publicKey) = maybeGetUserInfo() ?: return
|
||||||
|
configDatabase.storeConfig(SharedConfigMessage.Kind.CONVO_INFO_VOLATILE.name, publicKey, dumped)
|
||||||
|
}
|
||||||
}
|
}
|
@ -17,7 +17,7 @@ import org.session.libsession.snode.RawResponse
|
|||||||
import org.session.libsession.snode.SnodeAPI
|
import org.session.libsession.snode.SnodeAPI
|
||||||
import org.session.libsession.snode.SnodeModule
|
import org.session.libsession.snode.SnodeModule
|
||||||
import org.session.libsession.utilities.ConfigFactoryProtocol
|
import org.session.libsession.utilities.ConfigFactoryProtocol
|
||||||
import org.session.libsignal.protos.SignalServiceProtos
|
import org.session.libsignal.utilities.JsonUtil
|
||||||
import org.session.libsignal.utilities.Log
|
import org.session.libsignal.utilities.Log
|
||||||
import org.session.libsignal.utilities.Snode
|
import org.session.libsignal.utilities.Snode
|
||||||
import java.security.SecureRandom
|
import java.security.SecureRandom
|
||||||
@ -104,10 +104,30 @@ class Poller(private val configFactory: ConfigFactoryProtocol) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processUserConfig(rawMessages: List<Pair<SignalServiceProtos.Envelope, String?>>) {
|
private fun processPersonalMessages(snode: Snode, rawMessages: RawResponse) {
|
||||||
|
val messages = SnodeAPI.parseRawMessagesResponse(rawMessages, snode, userPublicKey)
|
||||||
|
val parameters = messages.map { (envelope, serverHash) ->
|
||||||
|
MessageReceiveParameters(envelope.toByteArray(), serverHash = serverHash)
|
||||||
|
}
|
||||||
|
parameters.chunked(BatchMessageReceiveJob.BATCH_DEFAULT_NUMBER).forEach { chunk ->
|
||||||
|
val job = BatchMessageReceiveJob(chunk)
|
||||||
|
JobQueue.shared.add(job)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun processUserConfig(snode: Snode, rawMessages: RawResponse) {
|
||||||
|
SnodeAPI.parseRawMessagesResponse(rawMessages, snode, userPublicKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun processContactsConfig(snode: Snode, rawMessages: RawResponse) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun processConvoVolatileConfig(snode: Snode, rawMessages: RawResponse) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun poll(snode: Snode, deferred: Deferred<Unit, Exception>): Promise<Unit, Exception> {
|
private fun poll(snode: Snode, deferred: Deferred<Unit, Exception>): Promise<Unit, Exception> {
|
||||||
if (!hasStarted) { return Promise.ofFail(PromiseCanceledException()) }
|
if (!hasStarted) { return Promise.ofFail(PromiseCanceledException()) }
|
||||||
return task {
|
return task {
|
||||||
@ -116,7 +136,7 @@ class Poller(private val configFactory: ConfigFactoryProtocol) {
|
|||||||
// get messages
|
// get messages
|
||||||
SnodeAPI.buildAuthenticatedRetrieveBatchRequest(snode, userPublicKey),
|
SnodeAPI.buildAuthenticatedRetrieveBatchRequest(snode, userPublicKey),
|
||||||
// get user config namespace
|
// get user config namespace
|
||||||
configFactory.userConfig?.let { currentUserConfig ->
|
configFactory.user?.let { currentUserConfig ->
|
||||||
SnodeAPI.buildAuthenticatedRetrieveBatchRequest(
|
SnodeAPI.buildAuthenticatedRetrieveBatchRequest(
|
||||||
snode,
|
snode,
|
||||||
userPublicKey,
|
userPublicKey,
|
||||||
@ -130,6 +150,13 @@ class Poller(private val configFactory: ConfigFactoryProtocol) {
|
|||||||
userPublicKey,
|
userPublicKey,
|
||||||
currentContacts.configNamespace()
|
currentContacts.configNamespace()
|
||||||
)
|
)
|
||||||
|
},
|
||||||
|
// get the latest convo info volatile
|
||||||
|
configFactory.convoVolatile?.let { currentConvoVolatile ->
|
||||||
|
SnodeAPI.buildAuthenticatedRetrieveBatchRequest(
|
||||||
|
snode, userPublicKey,
|
||||||
|
currentConvoVolatile.configNamespace()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -138,15 +165,7 @@ class Poller(private val configFactory: ConfigFactoryProtocol) {
|
|||||||
if (deferred.promise.isDone()) {
|
if (deferred.promise.isDone()) {
|
||||||
return@bind Promise.ofSuccess(Unit)
|
return@bind Promise.ofSuccess(Unit)
|
||||||
} else {
|
} else {
|
||||||
val messageResponse = (rawResponses["results"] as List<*>).first() as RawResponse
|
Log.d("Loki-DBG", JsonUtil.toJson(rawResponses))
|
||||||
val messages = SnodeAPI.parseRawMessagesResponse(messageResponse, snode, userPublicKey)
|
|
||||||
val parameters = messages.map { (envelope, serverHash) ->
|
|
||||||
MessageReceiveParameters(envelope.toByteArray(), serverHash = serverHash)
|
|
||||||
}
|
|
||||||
parameters.chunked(BatchMessageReceiveJob.BATCH_DEFAULT_NUMBER).forEach { chunk ->
|
|
||||||
val job = BatchMessageReceiveJob(chunk)
|
|
||||||
JobQueue.shared.add(job)
|
|
||||||
}
|
|
||||||
|
|
||||||
poll(snode, deferred)
|
poll(snode, deferred)
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
package org.session.libsession.utilities
|
package org.session.libsession.utilities
|
||||||
|
|
||||||
import network.loki.messenger.libsession_util.Contacts
|
import network.loki.messenger.libsession_util.Contacts
|
||||||
|
import network.loki.messenger.libsession_util.ConversationVolatileConfig
|
||||||
import network.loki.messenger.libsession_util.UserProfile
|
import network.loki.messenger.libsession_util.UserProfile
|
||||||
|
|
||||||
interface ConfigFactoryProtocol {
|
interface ConfigFactoryProtocol {
|
||||||
val userConfig: UserProfile?
|
val user: UserProfile?
|
||||||
val contacts: Contacts?
|
val contacts: Contacts?
|
||||||
|
val convoVolatile: ConversationVolatileConfig?
|
||||||
fun saveUserConfigDump()
|
fun saveUserConfigDump()
|
||||||
fun saveContactConfigDump()
|
fun saveContactConfigDump()
|
||||||
|
fun saveConvoVolatileConfigDump()
|
||||||
}
|
}
|
@ -243,8 +243,8 @@ message SharedConfigMessage {
|
|||||||
enum Kind {
|
enum Kind {
|
||||||
USER_PROFILE = 1;
|
USER_PROFILE = 1;
|
||||||
CONTACTS = 2;
|
CONTACTS = 2;
|
||||||
CONVERSATION_INFO = 3;
|
CONVO_INFO_VOLATILE = 3;
|
||||||
LEGACY_CLOSED_GROUPS = 4;
|
GROUPS = 4;
|
||||||
CLOSED_GROUP_INFO = 5;
|
CLOSED_GROUP_INFO = 5;
|
||||||
CLOSED_GROUP_MEMBERS = 6;
|
CLOSED_GROUP_MEMBERS = 6;
|
||||||
ENCRYPTION_KEYS = 7;
|
ENCRYPTION_KEYS = 7;
|
||||||
|
@ -22582,13 +22582,13 @@ public final class SignalServiceProtos {
|
|||||||
*/
|
*/
|
||||||
CONTACTS(1, 2),
|
CONTACTS(1, 2),
|
||||||
/**
|
/**
|
||||||
* <code>CONVERSATION_INFO = 3;</code>
|
* <code>CONVO_INFO_VOLATILE = 3;</code>
|
||||||
*/
|
*/
|
||||||
CONVERSATION_INFO(2, 3),
|
CONVO_INFO_VOLATILE(2, 3),
|
||||||
/**
|
/**
|
||||||
* <code>LEGACY_CLOSED_GROUPS = 4;</code>
|
* <code>GROUPS = 4;</code>
|
||||||
*/
|
*/
|
||||||
LEGACY_CLOSED_GROUPS(3, 4),
|
GROUPS(3, 4),
|
||||||
/**
|
/**
|
||||||
* <code>CLOSED_GROUP_INFO = 5;</code>
|
* <code>CLOSED_GROUP_INFO = 5;</code>
|
||||||
*/
|
*/
|
||||||
@ -22612,13 +22612,13 @@ public final class SignalServiceProtos {
|
|||||||
*/
|
*/
|
||||||
public static final int CONTACTS_VALUE = 2;
|
public static final int CONTACTS_VALUE = 2;
|
||||||
/**
|
/**
|
||||||
* <code>CONVERSATION_INFO = 3;</code>
|
* <code>CONVO_INFO_VOLATILE = 3;</code>
|
||||||
*/
|
*/
|
||||||
public static final int CONVERSATION_INFO_VALUE = 3;
|
public static final int CONVO_INFO_VOLATILE_VALUE = 3;
|
||||||
/**
|
/**
|
||||||
* <code>LEGACY_CLOSED_GROUPS = 4;</code>
|
* <code>GROUPS = 4;</code>
|
||||||
*/
|
*/
|
||||||
public static final int LEGACY_CLOSED_GROUPS_VALUE = 4;
|
public static final int GROUPS_VALUE = 4;
|
||||||
/**
|
/**
|
||||||
* <code>CLOSED_GROUP_INFO = 5;</code>
|
* <code>CLOSED_GROUP_INFO = 5;</code>
|
||||||
*/
|
*/
|
||||||
@ -22639,8 +22639,8 @@ public final class SignalServiceProtos {
|
|||||||
switch (value) {
|
switch (value) {
|
||||||
case 1: return USER_PROFILE;
|
case 1: return USER_PROFILE;
|
||||||
case 2: return CONTACTS;
|
case 2: return CONTACTS;
|
||||||
case 3: return CONVERSATION_INFO;
|
case 3: return CONVO_INFO_VOLATILE;
|
||||||
case 4: return LEGACY_CLOSED_GROUPS;
|
case 4: return GROUPS;
|
||||||
case 5: return CLOSED_GROUP_INFO;
|
case 5: return CLOSED_GROUP_INFO;
|
||||||
case 6: return CLOSED_GROUP_MEMBERS;
|
case 6: return CLOSED_GROUP_MEMBERS;
|
||||||
case 7: return ENCRYPTION_KEYS;
|
case 7: return ENCRYPTION_KEYS;
|
||||||
@ -27227,30 +27227,30 @@ public final class SignalServiceProtos {
|
|||||||
"d\030\006 \001(\010\022\024\n\014didApproveMe\030\007 \001(\010\"y\n\026Message" +
|
"d\030\006 \001(\010\022\024\n\014didApproveMe\030\007 \001(\010\"y\n\026Message" +
|
||||||
"RequestResponse\022\022\n\nisApproved\030\001 \002(\010\022\022\n\np" +
|
"RequestResponse\022\022\n\nisApproved\030\001 \002(\010\022\022\n\np" +
|
||||||
"rofileKey\030\002 \001(\014\0227\n\007profile\030\003 \001(\0132&.signa" +
|
"rofileKey\030\002 \001(\014\0227\n\007profile\030\003 \001(\0132&.signa" +
|
||||||
"lservice.DataMessage.LokiProfile\"\211\002\n\023Sha" +
|
"lservice.DataMessage.LokiProfile\"\375\001\n\023Sha" +
|
||||||
"redConfigMessage\0225\n\004kind\030\001 \002(\0162\'.signals" +
|
"redConfigMessage\0225\n\004kind\030\001 \002(\0162\'.signals" +
|
||||||
"ervice.SharedConfigMessage.Kind\022\r\n\005seqno" +
|
"ervice.SharedConfigMessage.Kind\022\r\n\005seqno" +
|
||||||
"\030\002 \002(\003\022\014\n\004data\030\003 \002(\014\"\235\001\n\004Kind\022\020\n\014USER_PR",
|
"\030\002 \002(\003\022\014\n\004data\030\003 \002(\014\"\221\001\n\004Kind\022\020\n\014USER_PR",
|
||||||
"OFILE\020\001\022\014\n\010CONTACTS\020\002\022\025\n\021CONVERSATION_IN" +
|
"OFILE\020\001\022\014\n\010CONTACTS\020\002\022\027\n\023CONVO_INFO_VOLA" +
|
||||||
"FO\020\003\022\030\n\024LEGACY_CLOSED_GROUPS\020\004\022\025\n\021CLOSED" +
|
"TILE\020\003\022\n\n\006GROUPS\020\004\022\025\n\021CLOSED_GROUP_INFO\020" +
|
||||||
"_GROUP_INFO\020\005\022\030\n\024CLOSED_GROUP_MEMBERS\020\006\022" +
|
"\005\022\030\n\024CLOSED_GROUP_MEMBERS\020\006\022\023\n\017ENCRYPTIO" +
|
||||||
"\023\n\017ENCRYPTION_KEYS\020\007\"u\n\016ReceiptMessage\0220" +
|
"N_KEYS\020\007\"u\n\016ReceiptMessage\0220\n\004type\030\001 \002(\016" +
|
||||||
"\n\004type\030\001 \002(\0162\".signalservice.ReceiptMess" +
|
"2\".signalservice.ReceiptMessage.Type\022\021\n\t" +
|
||||||
"age.Type\022\021\n\ttimestamp\030\002 \003(\004\"\036\n\004Type\022\014\n\010D" +
|
"timestamp\030\002 \003(\004\"\036\n\004Type\022\014\n\010DELIVERY\020\000\022\010\n" +
|
||||||
"ELIVERY\020\000\022\010\n\004READ\020\001\"\354\001\n\021AttachmentPointe" +
|
"\004READ\020\001\"\354\001\n\021AttachmentPointer\022\n\n\002id\030\001 \002(" +
|
||||||
"r\022\n\n\002id\030\001 \002(\006\022\023\n\013contentType\030\002 \001(\t\022\013\n\003ke" +
|
"\006\022\023\n\013contentType\030\002 \001(\t\022\013\n\003key\030\003 \001(\014\022\014\n\004s" +
|
||||||
"y\030\003 \001(\014\022\014\n\004size\030\004 \001(\r\022\021\n\tthumbnail\030\005 \001(\014" +
|
"ize\030\004 \001(\r\022\021\n\tthumbnail\030\005 \001(\014\022\016\n\006digest\030\006" +
|
||||||
"\022\016\n\006digest\030\006 \001(\014\022\020\n\010fileName\030\007 \001(\t\022\r\n\005fl",
|
" \001(\014\022\020\n\010fileName\030\007 \001(\t\022\r\n\005flags\030\010 \001(\r\022\r\n",
|
||||||
"ags\030\010 \001(\r\022\r\n\005width\030\t \001(\r\022\016\n\006height\030\n \001(\r" +
|
"\005width\030\t \001(\r\022\016\n\006height\030\n \001(\r\022\017\n\007caption\030" +
|
||||||
"\022\017\n\007caption\030\013 \001(\t\022\013\n\003url\030e \001(\t\"\032\n\005Flags\022" +
|
"\013 \001(\t\022\013\n\003url\030e \001(\t\"\032\n\005Flags\022\021\n\rVOICE_MES" +
|
||||||
"\021\n\rVOICE_MESSAGE\020\001\"\365\001\n\014GroupContext\022\n\n\002i" +
|
"SAGE\020\001\"\365\001\n\014GroupContext\022\n\n\002id\030\001 \001(\014\022.\n\004t" +
|
||||||
"d\030\001 \001(\014\022.\n\004type\030\002 \001(\0162 .signalservice.Gr" +
|
"ype\030\002 \001(\0162 .signalservice.GroupContext.T" +
|
||||||
"oupContext.Type\022\014\n\004name\030\003 \001(\t\022\017\n\007members" +
|
"ype\022\014\n\004name\030\003 \001(\t\022\017\n\007members\030\004 \003(\t\0220\n\006av" +
|
||||||
"\030\004 \003(\t\0220\n\006avatar\030\005 \001(\0132 .signalservice.A" +
|
"atar\030\005 \001(\0132 .signalservice.AttachmentPoi" +
|
||||||
"ttachmentPointer\022\016\n\006admins\030\006 \003(\t\"H\n\004Type" +
|
"nter\022\016\n\006admins\030\006 \003(\t\"H\n\004Type\022\013\n\007UNKNOWN\020" +
|
||||||
"\022\013\n\007UNKNOWN\020\000\022\n\n\006UPDATE\020\001\022\013\n\007DELIVER\020\002\022\010" +
|
"\000\022\n\n\006UPDATE\020\001\022\013\n\007DELIVER\020\002\022\010\n\004QUIT\020\003\022\020\n\014" +
|
||||||
"\n\004QUIT\020\003\022\020\n\014REQUEST_INFO\020\004B3\n\034org.sessio" +
|
"REQUEST_INFO\020\004B3\n\034org.session.libsignal." +
|
||||||
"n.libsignal.protosB\023SignalServiceProtos"
|
"protosB\023SignalServiceProtos"
|
||||||
};
|
};
|
||||||
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
|
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
|
||||||
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
|
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
|
||||||
|
Loading…
Reference in New Issue
Block a user