mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-11 14:57:45 +00:00

committed by
Anton Chekulaev

parent
3cb7d2169d
commit
48adb63fb7
@@ -11,6 +11,7 @@ import org.session.libsignal.service.loki.database.LokiAPIDatabaseProtocol
|
||||
import org.session.libsignal.service.loki.utilities.getRandomElement
|
||||
import org.session.libsignal.service.loki.utilities.prettifiedDescription
|
||||
import java.security.SecureRandom
|
||||
import java.util.*
|
||||
|
||||
class SwarmAPI private constructor(private val database: LokiAPIDatabaseProtocol) {
|
||||
internal var snodeFailureCount: MutableMap<Snode, Int> = mutableMapOf()
|
||||
@@ -46,7 +47,12 @@ class SwarmAPI private constructor(private val database: LokiAPIDatabaseProtocol
|
||||
// region Swarm API
|
||||
internal fun getRandomSnode(): Promise<Snode, Exception> {
|
||||
val snodePool = this.snodePool
|
||||
if (snodePool.count() < minimumSnodePoolCount) {
|
||||
val lastRefreshDate = database.getLastSnodePoolRefreshDate()
|
||||
val now = Date()
|
||||
val needsRefresh = (snodePool.count() < minimumSnodePoolCount) || lastRefreshDate == null || (now.time - lastRefreshDate.time) > 24 * 60 * 60 * 1000
|
||||
if (needsRefresh) {
|
||||
database.setLastSnodePoolRefreshDate(now)
|
||||
|
||||
val target = seedNodePool.random()
|
||||
val url = "$target/json_rpc"
|
||||
Log.d("Loki", "Populating snode pool using: $target.")
|
||||
|
@@ -2,6 +2,7 @@ package org.session.libsignal.service.loki.database
|
||||
|
||||
import org.session.libsignal.service.loki.api.Snode
|
||||
import org.session.libsignal.service.loki.protocol.shelved.multidevice.DeviceLink
|
||||
import java.util.*
|
||||
|
||||
interface LokiAPIDatabaseProtocol {
|
||||
|
||||
@@ -31,6 +32,9 @@ interface LokiAPIDatabaseProtocol {
|
||||
fun setOpenGroupPublicKey(server: String, newValue: String)
|
||||
fun setOpenGroupProfilePictureURL(group: Long, server: String, newValue: String)
|
||||
fun getOpenGroupProfilePictureURL(group: Long, server: String): String?
|
||||
fun getLastSnodePoolRefreshDate(): Date?
|
||||
fun setLastSnodePoolRefreshDate(newValue: Date)
|
||||
|
||||
|
||||
// region Deprecated
|
||||
fun getDeviceLinks(publicKey: String): Set<DeviceLink>
|
||||
|
Reference in New Issue
Block a user