Skip to content

Commit

Permalink
fix(Message): Only make parcelId available in OutgoingMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarea committed Mar 10, 2021
1 parent 9455af4 commit aad9ffa
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ import tech.relaycorp.relaynet.wrappers.cms.EnvelopedDataException
* @property ack The function to call as soon as the message has been processed.
*/
public class IncomingMessage internal constructor(
parcelId: ParcelId,
public val type: String,
public val content: ByteArray,
public val senderEndpoint: ThirdPartyEndpoint,
public val recipientEndpoint: FirstPartyEndpoint,
public val ack: suspend () -> Unit
) : Message(parcelId) {
) : Message() {

internal companion object {
@Throws(
Expand All @@ -52,7 +51,6 @@ public class IncomingMessage internal constructor(

val serviceMessage = parcel.unwrapPayload(recipientEndpoint.keyPair.private)
return IncomingMessage(
parcelId = ParcelId(parcel.id),
type = serviceMessage.type,
content = serviceMessage.content,
senderEndpoint = sender,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@ package tech.relaycorp.relaydroid.messaging

/**
* A service message.
*
* @property parcelId The parcel id.
*/
public abstract class Message internal constructor(public val parcelId: ParcelId)
public abstract class Message
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ import tech.relaycorp.relaynet.wrappers.x509.Certificate
* @property senderEndpoint The first-party endpoint that created the message.
* @property recipientEndpoint The third-party endpoint that should receive the message.
* @property parcelExpiryDate The expiry date of the parcel.
* @property parcelId The parcel id.
*/
public class OutgoingMessage
private constructor(
public val senderEndpoint: FirstPartyEndpoint,
public val recipientEndpoint: ThirdPartyEndpoint,
public val parcelExpiryDate: ZonedDateTime = maxExpiryDate(),
parcelId: ParcelId,
public val parcelId: ParcelId,
internal val parcelCreationDate: ZonedDateTime = ZonedDateTime.now()
) : Message(parcelId) {
) : Message() {

internal lateinit var parcel: Parcel
private set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,5 @@ internal class IncomingMessageTest {
assertEquals(PDACertPath.PRIVATE_ENDPOINT, message.recipientEndpoint.identityCertificate)
assertEquals(serviceMessage.type, message.type)
assertArrayEquals(serviceMessage.content, message.content)
assertEquals(parcel.id, message.parcelId.value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ internal class ReceiveMessagesTest {
assertTrue(pdcClient.wasClosed)
assertTrue(collectParcelsCall.wasCalled)
assertEquals(1, messages.size)
assertEquals(parcel.id, messages.first().parcelId.value)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package tech.relaycorp.relaydroid.test

import java.util.UUID
import tech.relaycorp.relaydroid.messaging.IncomingMessage
import tech.relaycorp.relaydroid.messaging.OutgoingMessage
import tech.relaycorp.relaydroid.messaging.ParcelId
import tech.relaycorp.relaynet.messages.payloads.ServiceMessage
import tech.relaycorp.relaynet.ramf.RecipientAddressType

Expand All @@ -18,7 +16,6 @@ internal object MessageFactory {
)

fun buildIncoming() = IncomingMessage(
parcelId = ParcelId(UUID.randomUUID().toString()),
type = serviceMessage.type,
content = serviceMessage.content,
senderEndpoint = ThirdPartyEndpointFactory.buildPublic(),
Expand Down

0 comments on commit aad9ffa

Please sign in to comment.