Skip to content

Commit

Permalink
Add profilling logs
Browse files Browse the repository at this point in the history
  • Loading branch information
sdsantos committed Sep 21, 2023
1 parent 2152e28 commit 83dbd53
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/src/main/java/tech/relaycorp/awaladroid/GatewayClientImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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()
Expand All @@ -141,6 +151,7 @@ internal constructor(
}
interactor.unbind()
cont.resume(replyMessage.data.getByteArray("auth")!!)
logger.log(Level.INFO, "preRegister DONE")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -244,6 +248,7 @@ internal constructor(
)

try {
logger.log(Level.INFO, "First saveIdentityKey")
context.privateKeyStore.saveIdentityKey(
keyPair.private,
)
Expand All @@ -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,
Expand All @@ -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
}

Expand Down

0 comments on commit 83dbd53

Please sign in to comment.