Added a try catch to HandlePacket.

This commit is contained in:
Koen J 2024-11-18 14:28:56 +01:00
parent 73b048d4c5
commit 0e64fa8d4c
2 changed files with 26 additions and 26 deletions

View file

@ -121,32 +121,32 @@ class SyncSession : IAuthorizable {
}
fun handlePacket(socketSession: SyncSocketSession, opcode: UByte, subOpcode: UByte, data: ByteBuffer) {
Logger.i(TAG, "Handle packet (opcode: ${opcode}, subOpcode: ${subOpcode}, data.length: ${data.remaining()})")
when (opcode) {
Opcode.NOTIFY_AUTHORIZED.value -> {
_remoteAuthorized = true
checkAuthorized()
}
Opcode.NOTIFY_UNAUTHORIZED.value -> {
_remoteAuthorized = false
_onUnauthorized(this)
}
//TODO: Handle any kind of packet (that is not necessarily authorized)
}
if (!isAuthorized) {
return
}
if (opcode != Opcode.DATA.value) {
Logger.w(TAG, "Unknown opcode received: (opcode = ${opcode}, subOpcode = ${subOpcode})}")
return
}
Logger.i(TAG, "Received (opcode = ${opcode}, subOpcode = ${subOpcode}) (${data.remaining()} bytes)")
//TODO: Abstract this out
try {
Logger.i(TAG, "Handle packet (opcode: ${opcode}, subOpcode: ${subOpcode}, data.length: ${data.remaining()})")
when (opcode) {
Opcode.NOTIFY_AUTHORIZED.value -> {
_remoteAuthorized = true
checkAuthorized()
}
Opcode.NOTIFY_UNAUTHORIZED.value -> {
_remoteAuthorized = false
_onUnauthorized(this)
}
//TODO: Handle any kind of packet (that is not necessarily authorized)
}
if (!isAuthorized) {
return
}
if (opcode != Opcode.DATA.value) {
Logger.w(TAG, "Unknown opcode received: (opcode = ${opcode}, subOpcode = ${subOpcode})}")
return
}
Logger.i(TAG, "Received (opcode = ${opcode}, subOpcode = ${subOpcode}) (${data.remaining()} bytes)")
//TODO: Abstract this out
when (subOpcode) {
GJSyncOpcodes.sendToDevices -> {
StateApp.instance.scopeOrNull?.launch(Dispatchers.Main) {

View file

@ -274,7 +274,7 @@ class SyncSocketSession {
_sendBuffer.asUByteArray()[4] = opcode
_sendBuffer.asUByteArray()[5] = subOpcode
//Logger.i(TAG, "Encrypting message (size = ${HEADER_SIZE})")
//Logger.i(TAG, "Encrypting message (opcode = ${opcode}, subOpcode = ${subOpcode}, size = ${HEADER_SIZE})")
val len = _cipherStatePair!!.sender.encryptWithAd(null, _sendBuffer, 0, _sendBufferEncrypted, 0, HEADER_SIZE)
//Logger.i(TAG, "Sending encrypted message (size = ${len})")