Merge pull request #63 from loki-project/proxy

Snode proxy
This commit is contained in:
gmbnt 2020-01-28 10:19:07 +11:00 committed by GitHub
commit 299d81f4dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 4 deletions

View File

@ -66,9 +66,13 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
val database = databaseHelper.readableDatabase
return database.get(swarmCache, "${Companion.hexEncodedPublicKey} = ?", wrap(hexEncodedPublicKey)) { cursor ->
val swarmAsString = cursor.getString(cursor.getColumnIndexOrThrow(swarm))
swarmAsString.split(", ").map { targetAsString ->
val components = targetAsString.split("?port=")
LokiAPITarget(components[0], components[1].toInt())
swarmAsString.split(", ").mapNotNull { targetAsString ->
val components = targetAsString.split("-")
val address = components[0]
val port = components.getOrNull(1)?.toIntOrNull() ?: return@mapNotNull null
val idKey = components.getOrNull(2) ?: return@mapNotNull null
val encryptionKey = components.getOrNull(3)?: return@mapNotNull null
LokiAPITarget(address, port, LokiAPITarget.KeySet(idKey, encryptionKey))
}
}?.toSet()
}
@ -76,7 +80,12 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
override fun setSwarmCache(hexEncodedPublicKey: String, newValue: Set<LokiAPITarget>) {
val database = databaseHelper.writableDatabase
val swarmAsString = newValue.joinToString(", ") { target ->
"${target.address}?port=${target.port}"
var string = "${target.address}-${target.port}"
val keySet = target.publicKeySet
if (keySet != null) {
string += "-${keySet.idKey}-${keySet.encryptionKey}"
}
string
}
val row = wrap(mapOf( Companion.hexEncodedPublicKey to hexEncodedPublicKey, swarm to swarmAsString ))
database.insertOrUpdate(swarmCache, row, "${Companion.hexEncodedPublicKey} = ?", wrap(hexEncodedPublicKey))

View File

@ -129,6 +129,7 @@ class RegisterActivity : BaseActionBarActivity() {
IdentityKeyUtil.getIdentityKeyPair(this).publicKey, IdentityDatabase.VerifiedStatus.VERIFIED,
true, System.currentTimeMillis(), true)
TextSecurePreferences.setLocalNumber(this, userHexEncodedPublicKey)
TextSecurePreferences.setHasViewedSeed(this, false)
val intent = Intent(this, DisplayNameActivity::class.java)
push(intent)
}

View File

@ -87,6 +87,7 @@ class RestoreActivity : BaseActionBarActivity() {
IdentityKeyUtil.getIdentityKeyPair(this).publicKey, IdentityDatabase.VerifiedStatus.VERIFIED,
true, System.currentTimeMillis(), true)
TextSecurePreferences.setLocalNumber(this, userHexEncodedPublicKey)
TextSecurePreferences.setHasViewedSeed(this, true)
val intent = Intent(this, DisplayNameActivity::class.java)
push(intent)
} catch (e: Exception) {