From 43e72550f9d0223e415874631c978884c7c88e4d Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Mon, 18 Sep 2023 12:24:06 +1000 Subject: [PATCH] refactor: fixing compile issues and namespace references throughout. figuring out config sig and base issues --- .../securesms/ApplicationContext.java | 5 +- .../securesms/database/Storage.kt | 14 ++-- .../securesms/dependencies/ConfigFactory.kt | 5 +- libsession-util/src/main/cpp/config_base.h | 4 +- libsession-util/src/main/cpp/group_keys.cpp | 12 ++- libsession-util/src/main/cpp/util.h | 2 +- .../loki/messenger/libsession_util/Config.kt | 5 +- .../libsession/database/StorageProtocol.kt | 4 +- .../messaging/jobs/ConfigurationSyncJob.kt | 73 ++++++++----------- .../sending_receiving/MessageSender.kt | 6 +- .../pollers/ClosedGroupPoller.kt | 8 +- .../pollers/LegacyClosedGroupPollerV2.kt | 14 ++-- .../sending_receiving/pollers/Poller.kt | 14 ++-- .../org/session/libsession/snode/SnodeAPI.kt | 4 +- .../utilities/ConfigFactoryProtocol.kt | 5 +- 15 files changed, 86 insertions(+), 89 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java index 17ce42660f..8ff6ad863a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java +++ b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java @@ -32,6 +32,7 @@ import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.ProcessLifecycleOwner; import org.conscrypt.Conscrypt; +import org.jetbrains.annotations.NotNull; import org.session.libsession.avatars.AvatarHelper; import org.session.libsession.database.MessageDataProvider; import org.session.libsession.messaging.MessagingModuleConfiguration; @@ -111,7 +112,7 @@ import dagger.hilt.android.HiltAndroidApp; import kotlin.Unit; import kotlinx.coroutines.Job; import network.loki.messenger.BuildConfig; -import network.loki.messenger.libsession_util.ConfigBase; +import network.loki.messenger.libsession_util.Config; import network.loki.messenger.libsession_util.UserProfile; /** @@ -199,7 +200,7 @@ public class ApplicationContext extends Application implements DefaultLifecycleO } @Override - public void notifyUpdates(@NonNull ConfigBase forConfigObject) { + public void notifyUpdates(@NotNull Config forConfigObject) { // forward to the config factory / storage ig if (forConfigObject instanceof UserProfile && !textSecurePreferences.getConfigurationMessageSynced()) { textSecurePreferences.setConfigurationMessageSynced(true); diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt index a2e5ed549a..ea37d3f49d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -2,7 +2,7 @@ package org.thoughtcrime.securesms.database import android.content.Context import android.net.Uri -import network.loki.messenger.libsession_util.ConfigBase +import network.loki.messenger.libsession_util.Config import network.loki.messenger.libsession_util.ConfigBase.Companion.PRIORITY_HIDDEN import network.loki.messenger.libsession_util.ConfigBase.Companion.PRIORITY_PINNED import network.loki.messenger.libsession_util.ConfigBase.Companion.PRIORITY_VISIBLE @@ -462,7 +462,7 @@ open class Storage( return DatabaseComponent.get(context).lokiAPIDatabase().getAuthToken(id) } - override fun notifyConfigUpdates(forConfigObject: ConfigBase) { + override fun notifyConfigUpdates(forConfigObject: Config) { notifyUpdates(forConfigObject) } @@ -478,14 +478,14 @@ open class Storage( return configFactory.user?.getCommunityMessageRequests() == true } - private fun notifyUpdates(forConfigObject: ConfigBase) { + private fun notifyUpdates(forConfigObject: Config) { when (forConfigObject) { is UserProfile -> updateUser(forConfigObject) is Contacts -> updateContacts(forConfigObject) is ConversationVolatileConfig -> updateConvoVolatile(forConfigObject) is UserGroupsConfig -> updateUserGroups(forConfigObject) is GroupInfoConfig -> updateGroupInfo(forConfigObject) - // is GroupKeysConfig -> updateGroupKeys(forConfigObject) + is GroupKeysConfig -> updateGroupKeys(forConfigObject) is GroupMembersConfig -> updateGroupMembers(forConfigObject) } } @@ -959,7 +959,7 @@ open class Storage( groupCreationTimestamp ) val keysBatchInfo = SnodeAPI.buildAuthenticatedStoreBatchInfo( - GroupKeysConfig.storageNamespace(), + GroupKeysConfig.namespace(), keysSnodeMessage, adminKey ) @@ -972,7 +972,7 @@ open class Storage( groupCreationTimestamp ) val infoBatchInfo = SnodeAPI.buildAuthenticatedStoreBatchInfo( - groupInfo.configNamespace(), + groupInfo.namespace(), infoSnodeMessage, adminKey ) @@ -985,7 +985,7 @@ open class Storage( groupCreationTimestamp ) val memberBatchInfo = SnodeAPI.buildAuthenticatedStoreBatchInfo( - groupMembers.configNamespace(), + groupMembers.namespace(), memberSnodeMessage, adminKey ) diff --git a/app/src/main/java/org/thoughtcrime/securesms/dependencies/ConfigFactory.kt b/app/src/main/java/org/thoughtcrime/securesms/dependencies/ConfigFactory.kt index bdab987582..2ece21c0bc 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/dependencies/ConfigFactory.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/dependencies/ConfigFactory.kt @@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.dependencies import android.content.Context import android.os.Trace +import network.loki.messenger.libsession_util.Config import network.loki.messenger.libsession_util.ConfigBase import network.loki.messenger.libsession_util.Contacts import network.loki.messenger.libsession_util.ConversationVolatileConfig @@ -276,7 +277,7 @@ class ConfigFactory( ) } - override fun persist(forConfigObject: ConfigBase, timestamp: Long) { + override fun persist(forConfigObject: Config, timestamp: Long) { try { listeners.forEach { listener -> listener.notifyUpdates(forConfigObject) @@ -355,6 +356,6 @@ class ConfigFactory( ) { val pubKey = groupInfo.id().hexString() val timestamp = SnodeAPI.nowWithOffset - configDatabase.storeGroupConfigs(pubKey, groupKeys.keyDump(), groupInfo.dump(), groupMembers.dump(), timestamp) + configDatabase.storeGroupConfigs(pubKey, groupKeys.dump(), groupInfo.dump(), groupMembers.dump(), timestamp) } } \ No newline at end of file diff --git a/libsession-util/src/main/cpp/config_base.h b/libsession-util/src/main/cpp/config_base.h index 786ecef073..3f6e6ceba8 100644 --- a/libsession-util/src/main/cpp/config_base.h +++ b/libsession-util/src/main/cpp/config_base.h @@ -26,8 +26,8 @@ inline std::pair extractHashAndData(JNIEnv *env, } inline session::config::ConfigSig* ptrToConfigSig(JNIEnv* env, jobject obj) { - jclass baseClass = env->FindClass("network/loki/messenger/libsession_util/ConfigSig"); - jfieldID pointerField = env->GetFieldID(baseClass, "pointer", "J"); + jclass sigClass = env->FindClass("network/loki/messenger/libsession_util/ConfigSig"); + jfieldID pointerField = env->GetFieldID(sigClass, "pointer", "J"); return (session::config::ConfigSig*) env->GetLongField(obj, pointerField); } diff --git a/libsession-util/src/main/cpp/group_keys.cpp b/libsession-util/src/main/cpp/group_keys.cpp index 9ad1644fd4..ffbbefc7a5 100644 --- a/libsession-util/src/main/cpp/group_keys.cpp +++ b/libsession-util/src/main/cpp/group_keys.cpp @@ -96,6 +96,14 @@ Java_network_loki_messenger_libsession_1util_GroupKeysConfig_needsRekey(JNIEnv * return keys->needs_rekey(); } +extern "C" +JNIEXPORT jboolean JNICALL +Java_network_loki_messenger_libsession_1util_GroupKeysConfig_needsDump(JNIEnv *env, jobject thiz) { + std::lock_guard lock{util::util_mutex_}; + auto keys = ptrToKeys(env, thiz); + return keys->needs_dump(); +} + extern "C" JNIEXPORT jbyteArray JNICALL Java_network_loki_messenger_libsession_1util_GroupKeysConfig_pendingKey(JNIEnv *env, jobject thiz) { @@ -138,7 +146,7 @@ Java_network_loki_messenger_libsession_1util_GroupKeysConfig_rekey(JNIEnv *env, extern "C" JNIEXPORT jbyteArray JNICALL -Java_network_loki_messenger_libsession_1util_GroupKeysConfig_keyDump(JNIEnv *env, jobject thiz) { +Java_network_loki_messenger_libsession_1util_GroupKeysConfig_dump(JNIEnv *env, jobject thiz) { auto keys = ptrToKeys(env, thiz); auto dump = keys->dump(); auto byte_array = util::bytes_from_ustring(env, dump); @@ -189,4 +197,4 @@ Java_network_loki_messenger_libsession_1util_GroupKeysConfig_keys(JNIEnv *env, j env->CallObjectMethod(our_stack, push, key_bytes); } return our_stack; -} \ No newline at end of file +} diff --git a/libsession-util/src/main/cpp/util.h b/libsession-util/src/main/cpp/util.h index c177ae86a0..a87b6c5619 100644 --- a/libsession-util/src/main/cpp/util.h +++ b/libsession-util/src/main/cpp/util.h @@ -13,7 +13,7 @@ #include "session/config/expiring.hpp" #include -#define LOG_TAG "libsession-jni" +#define LOG_TAG "libsession-jni" #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) #define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__) #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) diff --git a/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt b/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt index beef1b0c0d..3c2c9e9c32 100644 --- a/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt +++ b/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt @@ -292,7 +292,7 @@ class GroupMembersConfig(pointer: Long): ConfigBase(pointer), Closeable { } } -sealed class ConfigSig(pointer: Long) : Config(pointer) +abstract class ConfigSig(pointer: Long) : Config(pointer) class GroupKeysConfig(pointer: Long): ConfigSig(pointer) { companion object { @@ -312,7 +312,8 @@ class GroupKeysConfig(pointer: Long): ConfigSig(pointer) { override fun namespace() = Namespace.ENCRYPTION_KEYS() external fun groupKeys(): Stack - external fun keyDump(): ByteArray + external fun needsDump(): Boolean + external fun dump(): ByteArray external fun loadKey(message: ByteArray, hash: String, timestampMs: Long, diff --git a/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt b/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt index 1d5f99c6d6..344de217a2 100644 --- a/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt +++ b/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt @@ -2,7 +2,7 @@ package org.session.libsession.database import android.content.Context import android.net.Uri -import network.loki.messenger.libsession_util.ConfigBase +import network.loki.messenger.libsession_util.Config import org.session.libsession.messaging.BlindedIdMapping import org.session.libsession.messaging.calls.CallMessageType import org.session.libsession.messaging.contacts.Contact @@ -237,7 +237,7 @@ interface StorageProtocol { fun blockedContacts(): List // Shared configs - fun notifyConfigUpdates(forConfigObject: ConfigBase) + fun notifyConfigUpdates(forConfigObject: Config) fun conversationInConfig(publicKey: String?, groupPublicKey: String?, openGroupId: String?, visibleOnly: Boolean): Boolean fun canPerformConfigChange(variant: String, publicKey: String, changeTimestampMs: Long): Boolean fun isCheckingCommunityRequests(): Boolean diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/ConfigurationSyncJob.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/ConfigurationSyncJob.kt index 3047f359d1..b5306a181e 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/ConfigurationSyncJob.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/ConfigurationSyncJob.kt @@ -1,20 +1,20 @@ package org.session.libsession.messaging.jobs +import network.loki.messenger.libsession_util.Config import network.loki.messenger.libsession_util.ConfigBase -import network.loki.messenger.libsession_util.ConfigBase.Companion.protoKindFor import nl.komponents.kovenant.functional.bind import org.session.libsession.messaging.MessagingModuleConfiguration import org.session.libsession.messaging.messages.Destination -import org.session.libsession.messaging.messages.control.SharedConfigurationMessage -import org.session.libsession.messaging.sending_receiving.MessageSender import org.session.libsession.messaging.utilities.Data import org.session.libsession.snode.RawResponse import org.session.libsession.snode.SnodeAPI import org.session.libsession.snode.SnodeAPI.SnodeBatchRequestInfo -import org.session.libsession.utilities.TextSecurePreferences +import org.session.libsession.utilities.ConfigFactoryProtocol import org.session.libsignal.utilities.Log import java.util.concurrent.atomic.AtomicBoolean -typealias ConfigPair = List> + +class InvalidDestination: Exception("Trying to push configs somewhere other than our swarm or a closed group") +class InvalidContactDestination: Exception("Trying to push to non-user config swarm") // only contact (self) and closed group destinations will be supported data class ConfigurationSyncJob(val destination: Destination): Job { @@ -26,61 +26,47 @@ data class ConfigurationSyncJob(val destination: Destination): Job { val shouldRunAgain = AtomicBoolean(false) - data class SyncInformation(val configs: ConfigPair, val toDelete: List) + data class ConfigMessageInformation(val batch: SnodeBatchRequestInfo, val config: Config, val seqNo: Long?) // seqNo will be null for keys type + data class SyncInformation(val configs: List, val toDelete: List) + + private fun destinationConfigs(delegate: JobDelegate, configFactoryProtocol: ConfigFactoryProtocol): SyncInformation { + TODO() + } override suspend fun execute(dispatcherName: String) { val storage = MessagingModuleConfiguration.shared.storage - val forcedConfig = TextSecurePreferences.hasForcedNewConfig(MessagingModuleConfiguration.shared.context) - val currentTime = SnodeAPI.nowWithOffset val userPublicKey = storage.getUserPublicKey() val delegate = delegate ?: return Log.e("ConfigurationSyncJob", "No Delegate") - if ((destination is Destination.Contact && destination.publicKey != userPublicKey)) { - Log.w(TAG, "No need to run config sync job, TODO") - return delegate.handleJobSucceeded(this, dispatcherName) + if (destination is Destination.Contact && destination.publicKey != userPublicKey) { + return delegate.handleJobFailedPermanently(this, dispatcherName, InvalidContactDestination()) + } else if (destination !is Destination.ClosedGroup) { + return delegate.handleJobFailedPermanently(this, dispatcherName, InvalidDestination()) } // configFactory singleton instance will come in handy for modifying hashes and fetching configs for namespace etc val configFactory = MessagingModuleConfiguration.shared.configFactory + // **** start user **** // get latest states, filter out configs that don't need push val configsRequiringPush = configFactory.getUserConfigs().filter { config -> config.needsPush() } // don't run anything if we don't need to push anything if (configsRequiringPush.isEmpty()) return delegate.handleJobSucceeded(this, dispatcherName) - // need to get the current hashes before we call `push()` - val toDeleteHashes = mutableListOf() - + // **** end user **** // allow null results here so the list index matches configsRequiringPush val sentTimestamp: Long = SnodeAPI.nowWithOffset - val batchObjects: List?> = configsRequiringPush.map { config -> - val (data, seqNo, obsoleteHashes) = config.push() - toDeleteHashes += obsoleteHashes - SharedConfigurationMessage(config.protoKindFor(), data, seqNo) to config - }.map { (message, config) -> - // return a list of batch request objects - val snodeMessage = MessageSender.buildWrappedMessageToSnode(destination, message, true) - val authenticated = SnodeAPI.buildAuthenticatedStoreBatchInfo( - config.configNamespace(), - snodeMessage - ) ?: return@map null // this entry will be null otherwise - message to authenticated // to keep track of seqNo for calling confirmPushed later - } + val (batchObjects, toDeleteHashes) = destinationConfigs(delegate, configFactory) val toDeleteRequest = toDeleteHashes.let { toDeleteFromAllNamespaces -> if (toDeleteFromAllNamespaces.isEmpty()) null else SnodeAPI.buildAuthenticatedDeleteBatchInfo(destination.destinationPublicKey(), toDeleteFromAllNamespaces) } - if (batchObjects.any { it == null }) { - // stop running here, something like a signing error occurred - return delegate.handleJobFailedPermanently(this, dispatcherName, NullPointerException("One or more requests had a null batch request info")) - } - val allRequests = mutableListOf() - allRequests += batchObjects.requireNoNulls().map { (_, request) -> request } + allRequests += batchObjects.map { (request) -> request } // add in the deletion if we have any hashes if (toDeleteRequest != null) { allRequests += toDeleteRequest @@ -118,23 +104,26 @@ data class ConfigurationSyncJob(val destination: Destination): Job { } ?: emptySet() // at this point responseList index should line up with configsRequiringPush index - configsRequiringPush.forEachIndexed { index, config -> - val (toPushMessage, _) = batchObjects[index]!! + batchObjects.forEachIndexed { index, (message, config, seqNo) -> val response = responseList[index] val responseBody = response["body"] as? RawResponse val insertHash = responseBody?.get("hash") as? String ?: run { - Log.w(TAG, "No hash returned for the configuration in namespace ${config.configNamespace()}") + Log.w(TAG, "No hash returned for the configuration in namespace ${config.namespace()}") return@forEachIndexed } Log.d(TAG, "Hash ${insertHash.take(4)} returned from store request for new config") // confirm pushed seqno - val thisSeqNo = toPushMessage.seqNo - config.confirmPushed(thisSeqNo, insertHash) + if (config is ConfigBase) { + seqNo?.let { + config.confirmPushed(it, insertHash) + } + } + Log.d(TAG, "Successfully removed the deleted hashes from ${config.javaClass.simpleName}") // dump and write config after successful - if (config.needsDump()) { // usually this will be true? - configFactory.persist(config, toPushMessage.sentTimestamp ?: sentTimestamp) + if (config is ConfigBase && config.needsDump()) { // usually this will be true? + configFactory.persist(config, (message.params["timestamp"] as String).toLong()) } } } catch (e: Exception) { @@ -152,10 +141,6 @@ data class ConfigurationSyncJob(val destination: Destination): Job { val userEdKeyPair = MessagingModuleConfiguration.shared.getUserED25519KeyPair() } - private fun syncGroupConfigs(delegate: JobDelegate) { - - } - fun Destination.destinationPublicKey(): String = when (this) { is Destination.Contact -> publicKey is Destination.ClosedGroup -> publicKey diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt index 716c57a2fe..f440abb315 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt @@ -197,10 +197,10 @@ object MessageSender { val forkInfo = SnodeAPI.forkInfo val namespaces: List = when { destination is Destination.LegacyClosedGroup - && forkInfo.defaultRequiresAuth() -> listOf(Namespace.UNAUTHENTICATED_CLOSED_GROUP) + && forkInfo.defaultRequiresAuth() -> listOf(Namespace.UNAUTHENTICATED_CLOSED_GROUP()) destination is Destination.LegacyClosedGroup - && forkInfo.hasNamespaces() -> listOf(Namespace.UNAUTHENTICATED_CLOSED_GROUP, Namespace.DEFAULT) - else -> listOf(Namespace.DEFAULT) + && forkInfo.hasNamespaces() -> listOf(Namespace.UNAUTHENTICATED_CLOSED_GROUP(), Namespace.DEFAULT()) + else -> listOf(Namespace.DEFAULT()) } namespaces.map { namespace -> if (destination is Destination.ClosedGroup) { diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/ClosedGroupPoller.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/ClosedGroupPoller.kt index 12283ef481..024f37065e 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/ClosedGroupPoller.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/ClosedGroupPoller.kt @@ -104,28 +104,28 @@ class ClosedGroupPoller(private val executor: CoroutineScope, val messagePoll = SnodeAPI.buildAuthenticatedRetrieveBatchRequest( snode, closedGroupSessionId.hexString(), - Namespace.DEFAULT, + Namespace.DEFAULT(), maxSize = null, group.signingKey() ) ?: return null val infoPoll = SnodeAPI.buildAuthenticatedRetrieveBatchRequest( snode, closedGroupSessionId.hexString(), - info.configNamespace(), + info.namespace(), maxSize = null, group.signingKey() ) ?: return null val membersPoll = SnodeAPI.buildAuthenticatedRetrieveBatchRequest( snode, closedGroupSessionId.hexString(), - members.configNamespace(), + members.namespace(), maxSize = null, group.signingKey() ) ?: return null val keysPoll = SnodeAPI.buildAuthenticatedRetrieveBatchRequest( snode, closedGroupSessionId.hexString(), - GroupKeysConfig.storageNamespace(), + keys.namespace(), maxSize = null, group.signingKey() ) ?: return null diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/LegacyClosedGroupPollerV2.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/LegacyClosedGroupPollerV2.kt index e79ae79961..c9a272640e 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/LegacyClosedGroupPollerV2.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/LegacyClosedGroupPollerV2.kt @@ -108,13 +108,13 @@ class LegacyClosedGroupPollerV2 { if (!isPolling(groupPublicKey)) { throw PollingCanceledException() } val currentForkInfo = SnodeAPI.forkInfo when { - currentForkInfo.defaultRequiresAuth() -> SnodeAPI.getRawMessages(snode, groupPublicKey, requiresAuth = false, namespace = Namespace.UNAUTHENTICATED_CLOSED_GROUP) - .map { SnodeAPI.parseRawMessagesResponse(it, snode, groupPublicKey, Namespace.UNAUTHENTICATED_CLOSED_GROUP) } + currentForkInfo.defaultRequiresAuth() -> SnodeAPI.getRawMessages(snode, groupPublicKey, requiresAuth = false, namespace = Namespace.UNAUTHENTICATED_CLOSED_GROUP()) + .map { SnodeAPI.parseRawMessagesResponse(it, snode, groupPublicKey, Namespace.UNAUTHENTICATED_CLOSED_GROUP()) } currentForkInfo.hasNamespaces() -> task { - val unAuthed = SnodeAPI.getRawMessages(snode, groupPublicKey, requiresAuth = false, namespace = Namespace.UNAUTHENTICATED_CLOSED_GROUP) - .map { SnodeAPI.parseRawMessagesResponse(it, snode, groupPublicKey, Namespace.UNAUTHENTICATED_CLOSED_GROUP) } - val default = SnodeAPI.getRawMessages(snode, groupPublicKey, requiresAuth = false, namespace = Namespace.DEFAULT) - .map { SnodeAPI.parseRawMessagesResponse(it, snode, groupPublicKey, Namespace.DEFAULT) } + val unAuthed = SnodeAPI.getRawMessages(snode, groupPublicKey, requiresAuth = false, namespace = Namespace.UNAUTHENTICATED_CLOSED_GROUP()) + .map { SnodeAPI.parseRawMessagesResponse(it, snode, groupPublicKey, Namespace.UNAUTHENTICATED_CLOSED_GROUP()) } + val default = SnodeAPI.getRawMessages(snode, groupPublicKey, requiresAuth = false, namespace = Namespace.DEFAULT()) + .map { SnodeAPI.parseRawMessagesResponse(it, snode, groupPublicKey, Namespace.DEFAULT()) } val unAuthedResult = unAuthed.get() val defaultResult = default.get() val format = DateFormat.getTimeInstance() @@ -123,7 +123,7 @@ class LegacyClosedGroupPollerV2 { } unAuthedResult + defaultResult } - else -> SnodeAPI.getRawMessages(snode, groupPublicKey, requiresAuth = false, namespace = Namespace.DEFAULT) + else -> SnodeAPI.getRawMessages(snode, groupPublicKey, requiresAuth = false, namespace = Namespace.DEFAULT()) .map { SnodeAPI.parseRawMessagesResponse(it, snode, groupPublicKey) } } } diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt index f069398b21..a901fd1415 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt @@ -180,7 +180,7 @@ class Poller(private val configFactory: ConfigFactoryProtocol, debounceTimer: Ti hashesToExtend += config.currentHashes() SnodeAPI.buildAuthenticatedRetrieveBatchRequest( snode, userPublicKey, - config.configNamespace(), + config.namespace(), maxSize = -8 ) }.forEach { request -> @@ -211,10 +211,10 @@ class Poller(private val configFactory: ConfigFactoryProtocol, debounceTimer: Ti // in case we had null configs, the array won't be fully populated // index of the sparse array key iterator should be the request index, with the key being the namespace listOfNotNull( - configFactory.user?.configNamespace(), - configFactory.contacts?.configNamespace(), - configFactory.userGroups?.configNamespace(), - configFactory.convoVolatile?.configNamespace() + configFactory.user?.namespace(), + configFactory.contacts?.namespace(), + configFactory.userGroups?.namespace(), + configFactory.convoVolatile?.namespace() ).map { it to requestSparseArray.indexOfKey(it) }.filter { (_, i) -> i >= 0 }.forEach { (key, requestIndex) -> @@ -228,7 +228,7 @@ class Poller(private val configFactory: ConfigFactoryProtocol, debounceTimer: Ti Log.e("Loki", "Batch sub-request didn't contain a body") return@forEach } - if (key == Namespace.DEFAULT) { + if (key == Namespace.DEFAULT()) { return@forEach // continue, skip default namespace } else { when (ConfigBase.kindFor(key)) { @@ -242,7 +242,7 @@ class Poller(private val configFactory: ConfigFactoryProtocol, debounceTimer: Ti } // the first response will be the personal messages (we want these to be processed after config messages) - val personalResponseIndex = requestSparseArray.indexOfKey(Namespace.DEFAULT) + val personalResponseIndex = requestSparseArray.indexOfKey(Namespace.DEFAULT()) if (personalResponseIndex >= 0) { responseList.getOrNull(personalResponseIndex)?.let { rawResponse -> if (rawResponse["code"] as? Int != 200) { diff --git a/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt b/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt index 7ef0a29ddb..e67df22d6d 100644 --- a/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt +++ b/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt @@ -793,14 +793,14 @@ object SnodeAPI { retryIfNeeded(maxRetryCount) { getNetworkTime(snode).bind { (_, timestamp) -> val signature = ByteArray(Sign.BYTES) - val verificationData = (Snode.Method.DeleteAll.rawValue + Namespace.ALL + timestamp.toString()).toByteArray() + val verificationData = (Snode.Method.DeleteAll.rawValue + Namespace.ALL() + timestamp.toString()).toByteArray() sodium.cryptoSignDetached(signature, verificationData, verificationData.size.toLong(), userED25519KeyPair.secretKey.asBytes) val deleteMessageParams = mapOf( "pubkey" to userPublicKey, "pubkey_ed25519" to userED25519KeyPair.publicKey.asHexString, "timestamp" to timestamp, "signature" to Base64.encodeBytes(signature), - "namespace" to Namespace.ALL, + "namespace" to Namespace.ALL(), ) invoke(Snode.Method.DeleteAll, snode, deleteMessageParams, userPublicKey).map { rawResponse -> parseDeletions(userPublicKey, timestamp, rawResponse) diff --git a/libsession/src/main/java/org/session/libsession/utilities/ConfigFactoryProtocol.kt b/libsession/src/main/java/org/session/libsession/utilities/ConfigFactoryProtocol.kt index a3f3631e27..6fa3dacf3d 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/ConfigFactoryProtocol.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/ConfigFactoryProtocol.kt @@ -1,5 +1,6 @@ package org.session.libsession.utilities +import network.loki.messenger.libsession_util.Config import network.loki.messenger.libsession_util.ConfigBase import network.loki.messenger.libsession_util.Contacts import network.loki.messenger.libsession_util.ConversationVolatileConfig @@ -21,7 +22,7 @@ interface ConfigFactoryProtocol { fun getGroupKeysConfig(groupSessionId: SessionId): GroupKeysConfig? fun getUserConfigs(): List - fun persist(forConfigObject: ConfigBase, timestamp: Long) + fun persist(forConfigObject: Config, timestamp: Long) fun conversationInConfig(publicKey: String?, groupPublicKey: String?, openGroupId: String?, visibleOnly: Boolean): Boolean fun canPerformChange(variant: String, publicKey: String, changeTimestampMs: Long): Boolean @@ -33,5 +34,5 @@ interface ConfigFactoryProtocol { } interface ConfigFactoryUpdateListener { - fun notifyUpdates(forConfigObject: ConfigBase) + fun notifyUpdates(forConfigObject: Config) } \ No newline at end of file