mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
refactor: remove registration required for job serialization and test logs, don't try to read class object if the message send class is not of expected type
This commit is contained in:
parent
8439d57115
commit
9f09977160
@ -23,7 +23,6 @@ class SessionProtocolImpl(private val context: Context) : SessionProtocol {
|
|||||||
override fun decrypt(ciphertext: ByteArray, x25519KeyPair: ECKeyPair): Pair<ByteArray, String> {
|
override fun decrypt(ciphertext: ByteArray, x25519KeyPair: ECKeyPair): Pair<ByteArray, String> {
|
||||||
val recipientX25519PrivateKey = x25519KeyPair.privateKey.serialize()
|
val recipientX25519PrivateKey = x25519KeyPair.privateKey.serialize()
|
||||||
val recipientX25519PublicKey = Hex.fromStringCondensed(x25519KeyPair.hexEncodedPublicKey.removing05PrefixIfNeeded())
|
val recipientX25519PublicKey = Hex.fromStringCondensed(x25519KeyPair.hexEncodedPublicKey.removing05PrefixIfNeeded())
|
||||||
Log.d("Test", "recipientX25519PublicKey: $recipientX25519PublicKey")
|
|
||||||
val signatureSize = Sign.BYTES
|
val signatureSize = Sign.BYTES
|
||||||
val ed25519PublicKeySize = Sign.PUBLICKEYBYTES
|
val ed25519PublicKeySize = Sign.PUBLICKEYBYTES
|
||||||
|
|
||||||
|
@ -135,6 +135,7 @@ class AttachmentUploadJob(val attachmentID: Long, val threadID: String, val mess
|
|||||||
override fun create(data: Data): AttachmentUploadJob {
|
override fun create(data: Data): AttachmentUploadJob {
|
||||||
val serializedMessage = data.getByteArray(KEY_MESSAGE)
|
val serializedMessage = data.getByteArray(KEY_MESSAGE)
|
||||||
val kryo = Kryo()
|
val kryo = Kryo()
|
||||||
|
kryo.isRegistrationRequired = false
|
||||||
val input = Input(serializedMessage)
|
val input = Input(serializedMessage)
|
||||||
val message: Message = kryo.readObject(input, Message::class.java)
|
val message: Message = kryo.readObject(input, Message::class.java)
|
||||||
input.close()
|
input.close()
|
||||||
|
@ -11,6 +11,7 @@ interface Job {
|
|||||||
// Keys used for database storage
|
// Keys used for database storage
|
||||||
private val KEY_ID = "id"
|
private val KEY_ID = "id"
|
||||||
private val KEY_FAILURE_COUNT = "failure_count"
|
private val KEY_FAILURE_COUNT = "failure_count"
|
||||||
|
internal const val MAX_BUFFER_SIZE = 1_000_000 // bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
fun execute()
|
fun execute()
|
||||||
|
@ -50,6 +50,7 @@ class JobQueue : JobDelegate {
|
|||||||
|
|
||||||
private fun Job.canExecuteParallel(): Boolean {
|
private fun Job.canExecuteParallel(): Boolean {
|
||||||
return this.javaClass in arrayOf(
|
return this.javaClass in arrayOf(
|
||||||
|
MessageSendJob::class.java,
|
||||||
AttachmentUploadJob::class.java,
|
AttachmentUploadJob::class.java,
|
||||||
AttachmentDownloadJob::class.java
|
AttachmentDownloadJob::class.java
|
||||||
)
|
)
|
||||||
|
@ -4,6 +4,7 @@ import com.esotericsoftware.kryo.Kryo
|
|||||||
import com.esotericsoftware.kryo.io.Input
|
import com.esotericsoftware.kryo.io.Input
|
||||||
import com.esotericsoftware.kryo.io.Output
|
import com.esotericsoftware.kryo.io.Output
|
||||||
import org.session.libsession.messaging.MessagingModuleConfiguration
|
import org.session.libsession.messaging.MessagingModuleConfiguration
|
||||||
|
import org.session.libsession.messaging.jobs.Job.Companion.MAX_BUFFER_SIZE
|
||||||
import org.session.libsession.messaging.messages.Destination
|
import org.session.libsession.messaging.messages.Destination
|
||||||
import org.session.libsession.messaging.messages.Message
|
import org.session.libsession.messaging.messages.Message
|
||||||
import org.session.libsession.messaging.messages.visible.VisibleMessage
|
import org.session.libsession.messaging.messages.visible.VisibleMessage
|
||||||
@ -79,7 +80,7 @@ class MessageSendJob(val message: Message, val destination: Destination) : Job {
|
|||||||
override fun serialize(): Data {
|
override fun serialize(): Data {
|
||||||
val kryo = Kryo()
|
val kryo = Kryo()
|
||||||
kryo.isRegistrationRequired = false
|
kryo.isRegistrationRequired = false
|
||||||
val output = Output(ByteArray(4096), 10_000_000)
|
val output = Output(ByteArray(4096), MAX_BUFFER_SIZE)
|
||||||
kryo.writeClassAndObject(output, message)
|
kryo.writeClassAndObject(output, message)
|
||||||
output.close()
|
output.close()
|
||||||
val serializedMessage = output.toBytes()
|
val serializedMessage = output.toBytes()
|
||||||
@ -102,7 +103,13 @@ class MessageSendJob(val message: Message, val destination: Destination) : Job {
|
|||||||
val serializedMessage = data.getByteArray(KEY_MESSAGE)
|
val serializedMessage = data.getByteArray(KEY_MESSAGE)
|
||||||
val serializedDestination = data.getByteArray(KEY_DESTINATION)
|
val serializedDestination = data.getByteArray(KEY_DESTINATION)
|
||||||
val kryo = Kryo()
|
val kryo = Kryo()
|
||||||
|
kryo.isRegistrationRequired = false
|
||||||
var input = Input(serializedMessage)
|
var input = Input(serializedMessage)
|
||||||
|
val messageClass = kryo.readClass(input)
|
||||||
|
if (messageClass == null || !Message::class.java.isAssignableFrom(messageClass.type)) {
|
||||||
|
// if the message class doesn't exist or it doesn't implement `Message` parent class
|
||||||
|
throw Exception("deserialized messageClass was ${messageClass.type}")
|
||||||
|
}
|
||||||
val message = kryo.readClassAndObject(input) as Message
|
val message = kryo.readClassAndObject(input) as Message
|
||||||
input.close()
|
input.close()
|
||||||
input = Input(serializedDestination)
|
input = Input(serializedDestination)
|
||||||
|
@ -80,6 +80,7 @@ class NotifyPNServerJob(val message: SnodeMessage) : Job {
|
|||||||
override fun create(data: Data): NotifyPNServerJob {
|
override fun create(data: Data): NotifyPNServerJob {
|
||||||
val serializedMessage = data.getByteArray(KEY_MESSAGE)
|
val serializedMessage = data.getByteArray(KEY_MESSAGE)
|
||||||
val kryo = Kryo()
|
val kryo = Kryo()
|
||||||
|
kryo.isRegistrationRequired = false
|
||||||
val input = Input(serializedMessage)
|
val input = Input(serializedMessage)
|
||||||
val message: SnodeMessage = kryo.readObject(input, SnodeMessage::class.java)
|
val message: SnodeMessage = kryo.readObject(input, SnodeMessage::class.java)
|
||||||
input.close()
|
input.close()
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package org.session.libsession.messaging.sending_receiving
|
package org.session.libsession.messaging.sending_receiving
|
||||||
|
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import okhttp3.HttpUrl
|
|
||||||
import org.session.libsession.messaging.MessagingModuleConfiguration
|
import org.session.libsession.messaging.MessagingModuleConfiguration
|
||||||
import org.session.libsession.messaging.jobs.AttachmentDownloadJob
|
import org.session.libsession.messaging.jobs.AttachmentDownloadJob
|
||||||
import org.session.libsession.messaging.jobs.JobQueue
|
import org.session.libsession.messaging.jobs.JobQueue
|
||||||
|
@ -92,7 +92,7 @@ object SnodeAPI {
|
|||||||
"method" to "get_n_service_nodes",
|
"method" to "get_n_service_nodes",
|
||||||
"params" to mapOf(
|
"params" to mapOf(
|
||||||
"active_only" to true,
|
"active_only" to true,
|
||||||
"limit" to 256,
|
// "limit" to 256,
|
||||||
"fields" to mapOf( "public_ip" to true, "storage_port" to true, "pubkey_x25519" to true, "pubkey_ed25519" to true )
|
"fields" to mapOf( "public_ip" to true, "storage_port" to true, "pubkey_x25519" to true, "pubkey_ed25519" to true )
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user