From 3c3f6c25f1761c3b7b284cc0b757798b13b21a84 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Thu, 6 May 2021 15:46:22 +1000 Subject: [PATCH] Fix various bugs --- app/build.gradle | 2 +- .../database/helpers/SQLCipherOpenHelper.java | 10 ++++++++++ .../securesms/loki/database/LokiAPIDatabase.kt | 4 ++-- .../securesms/loki/protocol/MultiDeviceProtocol.kt | 2 +- .../main/java/org/session/libsession/snode/SnodeAPI.kt | 3 ++- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f7e122af7..c4c06a84c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -158,7 +158,7 @@ dependencies { testImplementation 'org.robolectric:shadows-multidex:4.2' } -def canonicalVersionCode = 154 +def canonicalVersionCode = 156 def canonicalVersionName = "1.10.0" def postFixSize = 10 diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java b/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java index dc7a0f7ee..ae8a72f17 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java @@ -55,6 +55,7 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper { private static final int lokiV21 = 42; private static final int lokiV22 = 43; private static final int lokiV23 = 44; + private static final int lokiV24 = 45; // Loki - onUpgrade(...) must be updated to use Loki version numbers if Signal makes any database changes private static final int DATABASE_VERSION = lokiV23; @@ -281,6 +282,15 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper { db.execSQL(LokiMessageDatabase.getUpdateMessageMappingTable()); } + if (oldVersion < lokiV24) { + String swarmTable = LokiAPIDatabase.Companion.getSwarmTable(); + String snodePoolTable = LokiAPIDatabase.Companion.getSnodePoolTable(); + db.execSQL("DROP TABLE " + swarmTable); + db.execSQL("DROP TABLE " + snodePoolTable); + db.execSQL(LokiAPIDatabase.getCreateSnodePoolTableCommand()); + db.execSQL(LokiAPIDatabase.getCreateSwarmTableCommand()); + } + db.setTransactionSuccessful(); } finally { db.endTransaction(); diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiAPIDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiAPIDatabase.kt index 53075bdae..bc53e1534 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiAPIDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiAPIDatabase.kt @@ -27,7 +27,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database( private val timestamp = "timestamp" private val snode = "snode" // Snode pool - private val snodePoolTable = "loki_snode_pool_cache" + public val snodePoolTable = "loki_snode_pool_cache" private val dummyKey = "dummy_key" private val snodePool = "snode_pool_key" @JvmStatic val createSnodePoolTableCommand = "CREATE TABLE $snodePoolTable ($dummyKey TEXT PRIMARY KEY, $snodePool TEXT);" @@ -36,7 +36,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database( private val indexPath = "index_path" @JvmStatic val createOnionRequestPathTableCommand = "CREATE TABLE $onionRequestPathTable ($indexPath TEXT PRIMARY KEY, $snode TEXT);" // Swarms - private val swarmTable = "loki_api_swarm_cache" + public val swarmTable = "loki_api_swarm_cache" private val swarmPublicKey = "hex_encoded_public_key" private val swarm = "swarm" @JvmStatic val createSwarmTableCommand = "CREATE TABLE $swarmTable ($swarmPublicKey TEXT PRIMARY KEY, $swarm TEXT);" diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/MultiDeviceProtocol.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/MultiDeviceProtocol.kt index f25833902..c7ba42ecf 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/MultiDeviceProtocol.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/MultiDeviceProtocol.kt @@ -17,7 +17,7 @@ object MultiDeviceProtocol { val userPublicKey = TextSecurePreferences.getLocalNumber(context) ?: return val lastSyncTime = TextSecurePreferences.getLastConfigurationSyncTime(context) val now = System.currentTimeMillis() - if (now - lastSyncTime < 2 * 24 * 60 * 60 * 1000) return + if (now - lastSyncTime < 7 * 24 * 60 * 60 * 1000) return val contacts = ContactUtilities.getAllContacts(context).filter { recipient -> !recipient.isBlocked && !recipient.name.isNullOrEmpty() && !recipient.isLocalNumber && recipient.address.serialize().isNotEmpty() }.map { recipient -> 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 e7bd5ce9e..a5094a63e 100644 --- a/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt +++ b/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt @@ -33,7 +33,7 @@ object SnodeAPI { // Settings private val maxRetryCount = 6 - private val minimumSnodePoolCount = 24 + private val minimumSnodePoolCount = 12 private val minimumSwarmSnodeCount = 2 // Use port 4433 if the API level can handle the network security configuration and enforce pinned certificates private val seedNodePort = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) 443 else 4433 @@ -92,6 +92,7 @@ object SnodeAPI { "method" to "get_n_service_nodes", "params" to mapOf( "active_only" to true, + "limit" to 256, "fields" to mapOf( "public_ip" to true, "storage_port" to true, "pubkey_x25519" to true, "pubkey_ed25519" to true ) ) )