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:
jubb 2021-05-12 10:43:17 +10:00
parent 8439d57115
commit 9f09977160
8 changed files with 13 additions and 4 deletions

View File

@ -23,7 +23,6 @@ class SessionProtocolImpl(private val context: Context) : SessionProtocol {
override fun decrypt(ciphertext: ByteArray, x25519KeyPair: ECKeyPair): Pair<ByteArray, String> {
val recipientX25519PrivateKey = x25519KeyPair.privateKey.serialize()
val recipientX25519PublicKey = Hex.fromStringCondensed(x25519KeyPair.hexEncodedPublicKey.removing05PrefixIfNeeded())
Log.d("Test", "recipientX25519PublicKey: $recipientX25519PublicKey")
val signatureSize = Sign.BYTES
val ed25519PublicKeySize = Sign.PUBLICKEYBYTES

View File

@ -135,6 +135,7 @@ class AttachmentUploadJob(val attachmentID: Long, val threadID: String, val mess
override fun create(data: Data): AttachmentUploadJob {
val serializedMessage = data.getByteArray(KEY_MESSAGE)
val kryo = Kryo()
kryo.isRegistrationRequired = false
val input = Input(serializedMessage)
val message: Message = kryo.readObject(input, Message::class.java)
input.close()

View File

@ -11,6 +11,7 @@ interface Job {
// Keys used for database storage
private val KEY_ID = "id"
private val KEY_FAILURE_COUNT = "failure_count"
internal const val MAX_BUFFER_SIZE = 1_000_000 // bytes
}
fun execute()

View File

@ -50,6 +50,7 @@ class JobQueue : JobDelegate {
private fun Job.canExecuteParallel(): Boolean {
return this.javaClass in arrayOf(
MessageSendJob::class.java,
AttachmentUploadJob::class.java,
AttachmentDownloadJob::class.java
)

View File

@ -4,6 +4,7 @@ import com.esotericsoftware.kryo.Kryo
import com.esotericsoftware.kryo.io.Input
import com.esotericsoftware.kryo.io.Output
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.Message
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 {
val kryo = Kryo()
kryo.isRegistrationRequired = false
val output = Output(ByteArray(4096), 10_000_000)
val output = Output(ByteArray(4096), MAX_BUFFER_SIZE)
kryo.writeClassAndObject(output, message)
output.close()
val serializedMessage = output.toBytes()
@ -102,7 +103,13 @@ class MessageSendJob(val message: Message, val destination: Destination) : Job {
val serializedMessage = data.getByteArray(KEY_MESSAGE)
val serializedDestination = data.getByteArray(KEY_DESTINATION)
val kryo = Kryo()
kryo.isRegistrationRequired = false
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
input.close()
input = Input(serializedDestination)

View File

@ -80,6 +80,7 @@ class NotifyPNServerJob(val message: SnodeMessage) : Job {
override fun create(data: Data): NotifyPNServerJob {
val serializedMessage = data.getByteArray(KEY_MESSAGE)
val kryo = Kryo()
kryo.isRegistrationRequired = false
val input = Input(serializedMessage)
val message: SnodeMessage = kryo.readObject(input, SnodeMessage::class.java)
input.close()

View File

@ -1,7 +1,6 @@
package org.session.libsession.messaging.sending_receiving
import android.text.TextUtils
import okhttp3.HttpUrl
import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsession.messaging.jobs.AttachmentDownloadJob
import org.session.libsession.messaging.jobs.JobQueue

View File

@ -92,7 +92,7 @@ object SnodeAPI {
"method" to "get_n_service_nodes",
"params" to mapOf(
"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 )
)
)