Skip to content

Commit

Permalink
Export max size of parcel payload
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarea committed Oct 28, 2023
1 parent 0fc0c44 commit 88dc6da
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
14 changes: 13 additions & 1 deletion lib/src/main/java/tech/relaycorp/awaladroid/messaging/Message.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
package tech.relaycorp.awaladroid.messaging

import tech.relaycorp.relaynet.ramf.RAMFMessage

/**
* A service message.
*/
public abstract class Message
public abstract class Message {
public companion object {
private const val PESSIMISTIC_CMS_ENVELOPEDDATA_OVERHEAD_OCTETS = 1024

/**
* The maximum size of the content of a message.
*/
public const val MAX_CONTENT_SIZE: Int =
RAMFMessage.MAX_PAYLOAD_LENGTH - PESSIMISTIC_CMS_ENVELOPEDDATA_OVERHEAD_OCTETS
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ private constructor(
/**
* Create an outgoing service message (but don't send it).
*
* @param type The type of the message (e.g., "application/vnd.relaynet.ping-v1.ping").
* @param type The type of the message (e.g., "application/vnd.awala.ping-v1.ping").
* @param content The contents of the service message.
* @param senderEndpoint The endpoint used to send the message.
* @param recipientEndpoint The endpoint that will receive the message.
* @param parcelExpiryDate The date when the parcel should expire.
* @param parcelId The id of the parcel.
*/
@Throws(InvalidMessageException::class)
public suspend fun build(
type: String,
content: ByteArray,
Expand All @@ -71,6 +72,7 @@ private constructor(
}
}

@Throws(InvalidMessageException::class)
private suspend fun buildParcel(
serviceMessageType: String,
serviceMessageContent: ByteArray,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package tech.relaycorp.awaladroid.messaging

import org.junit.Assert
import org.junit.Test
import tech.relaycorp.relaynet.ramf.RAMFMessage

public class MessageTest {
@Test
public fun maxContentSize() {
val expectedMax = RAMFMessage.MAX_PAYLOAD_LENGTH - 1024

Assert.assertEquals(Message.MAX_CONTENT_SIZE, expectedMax)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import kotlin.math.abs
import kotlin.random.Random

internal class OutgoingMessageTest : MockContextTestCase() {

@Test
fun build_creationDate() = runTest {
val channel = createEndpointChannel(RecipientAddressType.PRIVATE)
Expand Down

0 comments on commit 88dc6da

Please sign in to comment.