From 83dbd535fb16394e4eabb757570e96dfa1e973a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Santos?= Date: Thu, 21 Sep 2023 12:47:21 +0200 Subject: [PATCH] Add profilling logs --- .../tech/relaycorp/awaladroid/GatewayClientImpl.kt | 13 ++++++++++++- .../awaladroid/endpoint/FirstPartyEndpoint.kt | 9 +++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/GatewayClientImpl.kt b/lib/src/main/java/tech/relaycorp/awaladroid/GatewayClientImpl.kt index aaa1dbff..79513127 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/GatewayClientImpl.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/GatewayClientImpl.kt @@ -93,14 +93,20 @@ internal constructor( internal suspend fun registerEndpoint(keyPair: KeyPair): PrivateNodeRegistration = withContext(coroutineContext) { try { + logger.log(Level.INFO, "preRegister") val preAuthSerialized = preRegister() + logger.log(Level.INFO, "PrivateNodeRegistrationRequest serialize") val request = PrivateNodeRegistrationRequest(keyPair.public, preAuthSerialized) val requestSerialized = request.serialize(keyPair.private) + logger.log(Level.INFO, "bind") bind() return@withContext pdcClientBuilder().use { - it.registerNode(requestSerialized) + logger.log(Level.INFO, "registerNode") + it.registerNode(requestSerialized).also { + logger.log(Level.INFO, "gateway registerEndpoint DONE") + } } } catch (exp: ServiceInteractor.BindFailedException) { throw RegistrationFailedException("Failed binding to gateway", exp) @@ -121,7 +127,9 @@ internal constructor( GatewayProtocolException::class, ) private suspend fun preRegister(): ByteArray { + logger.log(Level.INFO, "preRegister serviceInteractorBuilder") val interactor = serviceInteractorBuilder().apply { + logger.log(Level.INFO, "preRegister bind") bind( Awala.GATEWAY_PRE_REGISTER_ACTION, Awala.GATEWAY_PACKAGE, @@ -130,7 +138,9 @@ internal constructor( } return suspendCoroutine { cont -> + logger.log(Level.INFO, "preRegister Message.obtain") val request = android.os.Message.obtain(null, PREREGISTRATION_REQUEST) + logger.log(Level.INFO, "preRegister sendMessage") interactor.sendMessage(request) { replyMessage -> if (replyMessage.what != REGISTRATION_AUTHORIZATION) { interactor.unbind() @@ -141,6 +151,7 @@ internal constructor( } interactor.unbind() cont.resume(replyMessage.data.getByteArray("auth")!!) + logger.log(Level.INFO, "preRegister DONE") } } } diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/FirstPartyEndpoint.kt b/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/FirstPartyEndpoint.kt index 840dc776..d8dd3f94 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/FirstPartyEndpoint.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/FirstPartyEndpoint.kt @@ -232,10 +232,14 @@ internal constructor( SetupPendingException::class, ) public suspend fun register(): FirstPartyEndpoint { + logger.log(Level.INFO, "First getContextOrThrow") val context = Awala.getContextOrThrow() + logger.log(Level.INFO, "First generateRSAKeyPair") val keyPair = generateRSAKeyPair() + logger.log(Level.INFO, "First gatewayClient.registerEndpoint") val registration = context.gatewayClient.registerEndpoint(keyPair) + logger.log(Level.INFO, "First FirstPartyEndpoint") val endpoint = FirstPartyEndpoint( keyPair.private, registration.privateNodeCertificate, @@ -244,6 +248,7 @@ internal constructor( ) try { + logger.log(Level.INFO, "First saveIdentityKey") context.privateKeyStore.saveIdentityKey( keyPair.private, ) @@ -253,6 +258,7 @@ internal constructor( val gatewayId = registration.gatewayCertificate.subjectId try { + logger.log(Level.INFO, "First certificateStore.save") context.certificateStore.save( CertificationPath( registration.privateNodeCertificate, @@ -264,13 +270,16 @@ internal constructor( throw PersistenceException("Failed to save certificate", exc) } + logger.log(Level.INFO, "First gatewayId.set") context.storage.gatewayId.set( endpoint.nodeId, gatewayId, ) + logger.log(Level.INFO, "First internetAddress.set") context.storage.internetAddress.set(registration.gatewayInternetAddress) + logger.log(Level.INFO, "First DONE") return endpoint }