Clearing the snode and onion request dbs on launch

This commit is contained in:
ThomasSession 2024-07-23 15:34:46 +10:00
parent 6b55e37cda
commit 5809a428d6
6 changed files with 33 additions and 0 deletions

View File

@ -214,6 +214,17 @@ public class ApplicationContext extends Application implements DefaultLifecycleO
DatabaseModule.init(this); DatabaseModule.init(this);
MessagingModuleConfiguration.configure(this); MessagingModuleConfiguration.configure(this);
super.onCreate(); super.onCreate();
// we need to clear the snode and onionrequest databases once on first launch
// in order to apply a patch that adds a version number to the Snode objects.
if(!TextSecurePreferences.hasAppliedPatchSnodeVersion(this)) {
ThreadUtils.queue(() -> {
lokiAPIDatabase.clearSnodePool();
lokiAPIDatabase.clearOnionRequestPaths();
TextSecurePreferences.setHasAppliedPatchSnodeVersion(this, true);
});
}
messagingModuleConfiguration = new MessagingModuleConfiguration( messagingModuleConfiguration = new MessagingModuleConfiguration(
this, this,
storage, storage,

View File

@ -255,6 +255,11 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
return result return result
} }
override fun clearSnodePool() {
val database = databaseHelper.writableDatabase
database.delete(snodePoolTable, null, null)
}
override fun clearOnionRequestPaths() { override fun clearOnionRequestPaths() {
val database = databaseHelper.writableDatabase val database = databaseHelper.writableDatabase
fun delete(indexPath: String) { fun delete(indexPath: String) {

View File

@ -50,6 +50,8 @@ object OnionRequestAPI {
get() { get() {
val paths = _paths.get() val paths = _paths.get()
Log.d("", "***** Getting ONION from database: ${paths?.count()}")
if (paths != null) { return paths } if (paths != null) { return paths }
// Storing this in an atomic variable as it was causing a number of background // Storing this in an atomic variable as it was causing a number of background

View File

@ -153,6 +153,8 @@ object SnodeAPI {
internal fun getRandomSnode(): Promise<Snode, Exception> { internal fun getRandomSnode(): Promise<Snode, Exception> {
val snodePool = this.snodePool val snodePool = this.snodePool
Log.d("", "***** Getting snode pool from database: ${snodePool.count()}")
if (snodePool.count() < minimumSnodePoolCount) { if (snodePool.count() < minimumSnodePoolCount) {
val target = seedNodePool.random() val target = seedNodePool.random()
val url = "$target/json_rpc" val url = "$target/json_rpc"

View File

@ -292,6 +292,8 @@ interface TextSecurePreferences {
const val ALLOW_MESSAGE_REQUESTS = "libsession.ALLOW_MESSAGE_REQUESTS" const val ALLOW_MESSAGE_REQUESTS = "libsession.ALLOW_MESSAGE_REQUESTS"
const val PATCH_SNODE_VERSION_2024_07_23 = "libsession.patch_snode_version_2024_07_23"
@JvmStatic @JvmStatic
fun getLastConfigurationSyncTime(context: Context): Long { fun getLastConfigurationSyncTime(context: Context): Long {
return getLongPreference(context, LAST_CONFIGURATION_SYNC_TIME, 0) return getLongPreference(context, LAST_CONFIGURATION_SYNC_TIME, 0)
@ -1013,6 +1015,16 @@ interface TextSecurePreferences {
fun clearAll(context: Context) { fun clearAll(context: Context) {
getDefaultSharedPreferences(context).edit().clear().commit() getDefaultSharedPreferences(context).edit().clear().commit()
} }
@JvmStatic
fun hasAppliedPatchSnodeVersion(context: Context): Boolean {
return getBooleanPreference(context, PATCH_SNODE_VERSION_2024_07_23, false)
}
@JvmStatic
fun setHasAppliedPatchSnodeVersion(context: Context, applied: Boolean) {
setBooleanPreference(context, PATCH_SNODE_VERSION_2024_07_23, applied)
}
} }
} }

View File

@ -10,6 +10,7 @@ interface LokiAPIDatabaseProtocol {
fun getSnodePool(): Set<Snode> fun getSnodePool(): Set<Snode>
fun setSnodePool(newValue: Set<Snode>) fun setSnodePool(newValue: Set<Snode>)
fun getOnionRequestPaths(): List<List<Snode>> fun getOnionRequestPaths(): List<List<Snode>>
fun clearSnodePool()
fun clearOnionRequestPaths() fun clearOnionRequestPaths()
fun setOnionRequestPaths(newValue: List<List<Snode>>) fun setOnionRequestPaths(newValue: List<List<Snode>>)
fun getSwarm(publicKey: String): Set<Snode>? fun getSwarm(publicKey: String): Set<Snode>?