-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement adaptive relay #23
Comments
Here's a working example of registering + delivering parcels + collecting parcels from a public gateway: import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.take
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Test
import tech.relaycorp.relaynet.bindings.pdc.Signer
import tech.relaycorp.relaynet.bindings.pdc.StreamingMode
import tech.relaycorp.relaynet.issueEndpointCertificate
import tech.relaycorp.relaynet.issueParcelDeliveryAuthorization
import tech.relaycorp.relaynet.messages.Parcel
import tech.relaycorp.relaynet.messages.control.PrivateNodeRegistrationRequest
import tech.relaycorp.relaynet.wrappers.generateRSAKeyPair
import kotlin.test.assertEquals
class RealTest {
private val localGatewayPort = 8082
@Test
fun test_connection(): Unit = runBlocking {
val privateGatewayKeyPair = generateRSAKeyPair()
val client = PoWebClient.initLocal(localGatewayPort) // <-- TODO: Replace with `initRemote()`
client.use {
val registrationRequest = client.preRegisterNode(privateGatewayKeyPair.public)
val registration =
client.registerNode(registrationRequest.serialize(privateGatewayKeyPair.private))
val recipientKeyPair = generateRSAKeyPair()
val recipientCertificate = issueEndpointCertificate(
recipientKeyPair.public,
privateGatewayKeyPair.private,
registration.privateNodeCertificate.expiryDate,
registration.privateNodeCertificate,
registration.privateNodeCertificate.startDate
)
val senderKeyPair = generateRSAKeyPair()
val senderCertificate = issueParcelDeliveryAuthorization(
senderKeyPair.public,
recipientKeyPair.private,
recipientCertificate.expiryDate,
recipientCertificate,
recipientCertificate.startDate
)
val parcel = Parcel(
recipientCertificate.subjectPrivateAddress,
ByteArray(0),
senderCertificate,
senderCertificateChain = setOf(
recipientCertificate,
registration.privateNodeCertificate
)
)
val privateGatewaySigner =
Signer(registration.privateNodeCertificate, privateGatewayKeyPair.private)
client.deliverParcel(
parcel.serialize(senderKeyPair.private),
privateGatewaySigner
)
delay(3_000)
val parcelsCollected = client.collectParcels(
arrayOf(privateGatewaySigner),
StreamingMode.KeepAlive
).map {
it.ack()
it.deserializeAndValidateParcel()
}.take(1).toList()
assertEquals(1, parcelsCollected.size)
assertEquals(parcel.id, parcelsCollected.first().id)
}
}
} And here's the documentation on how to write unit tests with a mock client: https://github.com/relaycorp/relaynet-jvm-testing#mock-pdc-client |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Per https://specs.relaynet.link/RS-017
See also: AwalaApp/specs#68
The text was updated successfully, but these errors were encountered: