Log all messages instead of printing
This commit is contained in:
parent
1a1eeb6547
commit
ad1c959ead
@ -92,7 +92,7 @@ final class DeviceManager {
|
|||||||
|
|
||||||
// Check if a full message has already been received
|
// Check if a full message has already been received
|
||||||
if let receivedMessageData, receivedMessageData.count == SignedMessage.size {
|
if let receivedMessageData, receivedMessageData.count == SignedMessage.size {
|
||||||
printAndFlush("[INFO] Full message from socket collected early")
|
log("[INFO] Full message from socket collected early")
|
||||||
self.receivedMessageData = nil
|
self.receivedMessageData = nil
|
||||||
return receivedMessageData
|
return receivedMessageData
|
||||||
}
|
}
|
||||||
@ -101,14 +101,14 @@ final class DeviceManager {
|
|||||||
self.requestInProgress = continuation
|
self.requestInProgress = continuation
|
||||||
}
|
}
|
||||||
await updateMessageCountMetric()
|
await updateMessageCountMetric()
|
||||||
printAndFlush("[INFO] Message completed")
|
log("[INFO] Message completed")
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
private func startTimeoutForDeviceRequest(on eventLoop: EventLoop) {
|
private func startTimeoutForDeviceRequest(on eventLoop: EventLoop) {
|
||||||
eventLoop.scheduleTask(in: .seconds(deviceTimeout)) { [weak self] in
|
eventLoop.scheduleTask(in: .seconds(deviceTimeout)) { [weak self] in
|
||||||
guard let self else {
|
guard let self else {
|
||||||
print("[INFO] Message completed")
|
log("[INFO] No reference to self after timeout of message")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.resumeDeviceRequest(with: .deviceTimedOut)
|
self.resumeDeviceRequest(with: .deviceTimedOut)
|
||||||
@ -117,7 +117,7 @@ final class DeviceManager {
|
|||||||
|
|
||||||
private func resumeDeviceRequest(with data: Data) {
|
private func resumeDeviceRequest(with data: Data) {
|
||||||
guard let receivedMessageData else {
|
guard let receivedMessageData else {
|
||||||
printAndFlush("[WARN] Received \(data.count) bytes after message completion")
|
log("[WARN] Received \(data.count) bytes after message completion")
|
||||||
self.requestInProgress = nil
|
self.requestInProgress = nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -129,12 +129,12 @@ final class DeviceManager {
|
|||||||
}
|
}
|
||||||
self.receivedMessageData = nil
|
self.receivedMessageData = nil
|
||||||
guard let requestInProgress else {
|
guard let requestInProgress else {
|
||||||
printAndFlush("[WARN] Received \(newData.count) bytes, but no continuation to resume")
|
log("[WARN] Received \(newData.count) bytes, but no continuation to resume")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.requestInProgress = nil
|
self.requestInProgress = nil
|
||||||
guard newData.count == SignedMessage.size else {
|
guard newData.count == SignedMessage.size else {
|
||||||
printAndFlush("[WARN] Received \(newData.count) bytes, expected \(SignedMessage.size) for a message.")
|
log("[WARN] Received \(newData.count) bytes, expected \(SignedMessage.size) for a message.")
|
||||||
requestInProgress.resume(throwing: MessageResult.invalidMessageSizeFromDevice)
|
requestInProgress.resume(throwing: MessageResult.invalidMessageSizeFromDevice)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -143,13 +143,13 @@ final class DeviceManager {
|
|||||||
|
|
||||||
private func resumeDeviceRequest(with result: MessageResult) {
|
private func resumeDeviceRequest(with result: MessageResult) {
|
||||||
guard let receivedMessageData else {
|
guard let receivedMessageData else {
|
||||||
printAndFlush("[WARN] Result after message completed: \(result)")
|
log("[WARN] Result after message completed: \(result)")
|
||||||
self.requestInProgress = nil
|
self.requestInProgress = nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.receivedMessageData = nil
|
self.receivedMessageData = nil
|
||||||
guard let requestInProgress else {
|
guard let requestInProgress else {
|
||||||
printAndFlush("[WARN] Request in progress (\(receivedMessageData.count) bytes), but no continuation found for result: \(result)")
|
log("[WARN] Request in progress (\(receivedMessageData.count) bytes), but no continuation found for result: \(result)")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.requestInProgress = nil
|
self.requestInProgress = nil
|
||||||
@ -163,13 +163,13 @@ final class DeviceManager {
|
|||||||
|
|
||||||
func processDeviceResponse(_ buffer: ByteBuffer) {
|
func processDeviceResponse(_ buffer: ByteBuffer) {
|
||||||
guard let data = buffer.getData(at: 0, length: buffer.readableBytes) else {
|
guard let data = buffer.getData(at: 0, length: buffer.readableBytes) else {
|
||||||
print("Failed to get data buffer received from device")
|
log("Failed to get data buffer received from device")
|
||||||
self.resumeDeviceRequest(with: .invalidMessageSizeFromDevice)
|
self.resumeDeviceRequest(with: .invalidMessageSizeFromDevice)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
guard data.count == SignedMessage.size else {
|
guard data.count == SignedMessage.size else {
|
||||||
print("Invalid size of device message: \(data.count)")
|
log("Invalid size of device message: \(data.count)")
|
||||||
self.resumeDeviceRequest(with: .invalidMessageSizeFromDevice)
|
self.resumeDeviceRequest(with: .invalidMessageSizeFromDevice)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -205,7 +205,7 @@ final class DeviceManager {
|
|||||||
try? await socket.close()
|
try? await socket.close()
|
||||||
|
|
||||||
guard let self else {
|
guard let self else {
|
||||||
print("[WARN] No reference to self to handle text over socket")
|
log("[WARN] No reference to self to handle text over socket")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.didCloseDeviceSocket()
|
self.didCloseDeviceSocket()
|
||||||
@ -213,7 +213,7 @@ final class DeviceManager {
|
|||||||
|
|
||||||
socket.onBinary { [weak self] _, data in
|
socket.onBinary { [weak self] _, data in
|
||||||
guard let self else {
|
guard let self else {
|
||||||
print("[WARN] No reference to self to process binary data on socket")
|
log("[WARN] No reference to self to process binary data on socket")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.processDeviceResponse(data)
|
self.processDeviceResponse(data)
|
||||||
@ -221,7 +221,7 @@ final class DeviceManager {
|
|||||||
|
|
||||||
socket.onClose.whenComplete { [weak self] _ in
|
socket.onClose.whenComplete { [weak self] _ in
|
||||||
guard let self else {
|
guard let self else {
|
||||||
print("[WARN] No reference to self to handle socket closing")
|
log("[WARN] No reference to self to handle socket closing")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.didCloseDeviceSocket()
|
self.didCloseDeviceSocket()
|
||||||
|
Loading…
Reference in New Issue
Block a user