mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-20 08:08:26 +00:00
Merge branch 'hardfork' of github.com:oxen-io/session-android into hardfork
This commit is contained in:
commit
7415c728eb
@ -15,7 +15,7 @@ abstract class Message {
|
|||||||
var groupPublicKey: String? = null
|
var groupPublicKey: String? = null
|
||||||
var openGroupServerMessageID: Long? = null
|
var openGroupServerMessageID: Long? = null
|
||||||
|
|
||||||
open val ttl: Long = 2 * 24 * 60 * 60 * 1000
|
open val ttl: Long = 14 * 24 * 60 * 60 * 1000
|
||||||
open val isSelfSendValid: Boolean = false
|
open val isSelfSendValid: Boolean = false
|
||||||
|
|
||||||
// validation
|
// validation
|
||||||
|
@ -19,8 +19,8 @@ class ClosedGroupControlMessage() : ControlMessage() {
|
|||||||
|
|
||||||
override val ttl: Long = run {
|
override val ttl: Long = run {
|
||||||
when (kind) {
|
when (kind) {
|
||||||
is Kind.EncryptionKeyPair -> return@run 4 * 24 * 60 * 60 * 1000
|
is Kind.EncryptionKeyPair -> 14 * 24 * 60 * 60 * 1000
|
||||||
else -> return@run 2 * 24 * 60 * 60 * 1000
|
else -> 14 * 24 * 60 * 60 * 1000
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,6 @@ class ConfigurationMessage(var closedGroups: List<ClosedGroup>, var openGroups:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val ttl: Long = 4 * 24 * 60 * 60 * 1000
|
|
||||||
override val isSelfSendValid: Boolean = true
|
override val isSelfSendValid: Boolean = true
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -30,7 +30,6 @@ import org.session.libsession.messaging.sending_receiving.attachments.Attachment
|
|||||||
import org.session.libsession.messaging.sending_receiving.linkpreview.LinkPreview as SignalLinkPreview
|
import org.session.libsession.messaging.sending_receiving.linkpreview.LinkPreview as SignalLinkPreview
|
||||||
import org.session.libsession.messaging.sending_receiving.quotes.QuoteModel as SignalQuote
|
import org.session.libsession.messaging.sending_receiving.quotes.QuoteModel as SignalQuote
|
||||||
|
|
||||||
|
|
||||||
object MessageSender {
|
object MessageSender {
|
||||||
|
|
||||||
// Error
|
// Error
|
||||||
@ -146,11 +145,10 @@ object MessageSender {
|
|||||||
is Destination.OpenGroup -> throw Error.PreconditionFailure("Destination should not be open groups!")
|
is Destination.OpenGroup -> throw Error.PreconditionFailure("Destination should not be open groups!")
|
||||||
}
|
}
|
||||||
val wrappedMessage = MessageWrapper.wrap(kind, message.sentTimestamp!!, senderPublicKey, ciphertext)
|
val wrappedMessage = MessageWrapper.wrap(kind, message.sentTimestamp!!, senderPublicKey, ciphertext)
|
||||||
// Calculate proof of work
|
// Send the result
|
||||||
if (destination is Destination.Contact && message is VisibleMessage && !isSelfSend) {
|
if (destination is Destination.Contact && message is VisibleMessage && !isSelfSend) {
|
||||||
SnodeConfiguration.shared.broadcaster.broadcast("calculatingPoW", message.sentTimestamp!!)
|
SnodeConfiguration.shared.broadcaster.broadcast("calculatingPoW", message.sentTimestamp!!)
|
||||||
}
|
}
|
||||||
// Send the result
|
|
||||||
val base64EncodedData = Base64.encodeBytes(wrappedMessage)
|
val base64EncodedData = Base64.encodeBytes(wrappedMessage)
|
||||||
val snodeMessage = SnodeMessage(message.recipient!!, base64EncodedData, message.ttl, message.sentTimestamp!!)
|
val snodeMessage = SnodeMessage(message.recipient!!, base64EncodedData, message.ttl, message.sentTimestamp!!)
|
||||||
if (destination is Destination.Contact && message is VisibleMessage && !isSelfSend) {
|
if (destination is Destination.Contact && message is VisibleMessage && !isSelfSend) {
|
||||||
|
@ -12,6 +12,7 @@ import org.session.libsignal.service.loki.api.utilities.HTTP
|
|||||||
import org.session.libsignal.service.loki.database.LokiAPIDatabaseProtocol
|
import org.session.libsignal.service.loki.database.LokiAPIDatabaseProtocol
|
||||||
import org.session.libsignal.service.loki.utilities.Broadcaster
|
import org.session.libsignal.service.loki.utilities.Broadcaster
|
||||||
import org.session.libsignal.service.loki.utilities.prettifiedDescription
|
import org.session.libsignal.service.loki.utilities.prettifiedDescription
|
||||||
|
import org.session.libsignal.service.loki.utilities.removing05PrefixIfNeeded
|
||||||
import org.session.libsignal.service.loki.utilities.retryIfNeeded
|
import org.session.libsignal.service.loki.utilities.retryIfNeeded
|
||||||
import org.session.libsignal.utilities.*
|
import org.session.libsignal.utilities.*
|
||||||
import org.session.libsignal.utilities.logging.Log
|
import org.session.libsignal.utilities.logging.Log
|
||||||
@ -37,16 +38,18 @@ object SnodeAPI {
|
|||||||
|
|
||||||
// use port 4433 if API level can handle network security config and enforce pinned certificates
|
// use port 4433 if API level can handle network security config and enforce pinned certificates
|
||||||
private val seedPort = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) 443 else 4433
|
private val seedPort = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) 443 else 4433
|
||||||
private val seedNodePool: Set<String> = setOf(
|
private val seedNodePool by lazy {
|
||||||
"https://storage.seed1.loki.network:$seedPort",
|
if (useTestnet) {
|
||||||
"https://storage.seed3.loki.network:$seedPort",
|
setOf( "http://public.loki.foundation:38157" )
|
||||||
"https://public.loki.foundation:$seedPort"
|
} else {
|
||||||
)
|
setOf( "https://storage.seed1.loki.network:$seedPort", "https://storage.seed3.loki.network:$seedPort", "https://public.loki.foundation:$seedPort" )
|
||||||
internal val snodeFailureThreshold = 4
|
}
|
||||||
|
}
|
||||||
|
private val snodeFailureThreshold = 4
|
||||||
private val targetSwarmSnodeCount = 2
|
private val targetSwarmSnodeCount = 2
|
||||||
|
|
||||||
private val useOnionRequests = true
|
private val useOnionRequests = true
|
||||||
|
|
||||||
|
internal val useTestnet = false
|
||||||
internal var powDifficulty = 1
|
internal var powDifficulty = 1
|
||||||
|
|
||||||
// Error
|
// Error
|
||||||
@ -164,7 +167,7 @@ object SnodeAPI {
|
|||||||
cachedSwarmCopy.addAll(cachedSwarm)
|
cachedSwarmCopy.addAll(cachedSwarm)
|
||||||
return task { cachedSwarmCopy }
|
return task { cachedSwarmCopy }
|
||||||
} else {
|
} else {
|
||||||
val parameters = mapOf( "pubKey" to publicKey )
|
val parameters = mapOf( "pubKey" to if (useTestnet) publicKey.removing05PrefixIfNeeded() else publicKey )
|
||||||
return getRandomSnode().bind {
|
return getRandomSnode().bind {
|
||||||
invoke(Snode.Method.GetSwarm, it, publicKey, parameters)
|
invoke(Snode.Method.GetSwarm, it, publicKey, parameters)
|
||||||
}.map(sharedContext) {
|
}.map(sharedContext) {
|
||||||
@ -177,7 +180,7 @@ object SnodeAPI {
|
|||||||
|
|
||||||
fun getRawMessages(snode: Snode, publicKey: String): RawResponsePromise {
|
fun getRawMessages(snode: Snode, publicKey: String): RawResponsePromise {
|
||||||
val lastHashValue = database.getLastMessageHashValue(snode, publicKey) ?: ""
|
val lastHashValue = database.getLastMessageHashValue(snode, publicKey) ?: ""
|
||||||
val parameters = mapOf( "pubKey" to publicKey, "lastHash" to lastHashValue )
|
val parameters = mapOf( "pubKey" to if (useTestnet) publicKey.removing05PrefixIfNeeded() else publicKey, "lastHash" to lastHashValue )
|
||||||
return invoke(Snode.Method.GetMessages, snode, publicKey, parameters)
|
return invoke(Snode.Method.GetMessages, snode, publicKey, parameters)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,7 +193,7 @@ object SnodeAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun sendMessage(message: SnodeMessage): Promise<Set<RawResponsePromise>, Exception> {
|
fun sendMessage(message: SnodeMessage): Promise<Set<RawResponsePromise>, Exception> {
|
||||||
val destination = message.recipient
|
val destination = if (useTestnet) message.recipient.removing05PrefixIfNeeded() else message.recipient
|
||||||
return retryIfNeeded(maxRetryCount) {
|
return retryIfNeeded(maxRetryCount) {
|
||||||
getTargetSnodes(destination).map { swarm ->
|
getTargetSnodes(destination).map { swarm ->
|
||||||
swarm.map { snode ->
|
swarm.map { snode ->
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package org.session.libsession.snode
|
package org.session.libsession.snode
|
||||||
|
|
||||||
|
import org.session.libsignal.service.loki.utilities.removing05PrefixIfNeeded
|
||||||
|
|
||||||
data class SnodeMessage(
|
data class SnodeMessage(
|
||||||
// The hex encoded public key of the recipient.
|
// The hex encoded public key of the recipient.
|
||||||
val recipient: String,
|
val recipient: String,
|
||||||
@ -12,7 +14,7 @@ data class SnodeMessage(
|
|||||||
) {
|
) {
|
||||||
internal fun toJSON(): Map<String, String> {
|
internal fun toJSON(): Map<String, String> {
|
||||||
return mutableMapOf(
|
return mutableMapOf(
|
||||||
"pubKey" to recipient,
|
"pubKey" to if (SnodeAPI.useTestnet) recipient.removing05PrefixIfNeeded() else recipient,
|
||||||
"data" to data,
|
"data" to data,
|
||||||
"ttl" to ttl.toString(),
|
"ttl" to ttl.toString(),
|
||||||
"timestamp" to timestamp.toString(),
|
"timestamp" to timestamp.toString(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user