diff --git a/Sources/SwiftNetwork/Protocols/Frame.swift b/Sources/SwiftNetwork/Protocols/Frame.swift index 16b5017..ff31fca 100644 --- a/Sources/SwiftNetwork/Protocols/Frame.swift +++ b/Sources/SwiftNetwork/Protocols/Frame.swift @@ -268,7 +268,9 @@ public struct Frame: ~Copyable { public mutating func claim(fromStart: Int, fromEnd: Int = 0, adjustSingleIPAggregate: Bool = true) -> Bool { if adjustSingleIPAggregate && isSingleIPAggregate { guard fromEnd == 0 else { - Logger.proto.fault("Trying to claim at the end \(fromEnd) bytes from a single-IP aggregate") + #if !DisableErrorLogging + Logger.proto.error("Trying to claim at the end \(fromEnd) bytes from a single-IP aggregate") + #endif return false } aggregateBufferLength -= fromStart @@ -278,9 +280,11 @@ public struct Frame: ~Copyable { let newEnd = endOffset + fromEnd guard newStart <= effectiveBufferLength - newEnd else { let effectiveLength = effectiveBufferLength + #if !DisableErrorLogging Logger.proto.error( "Claiming bytes failed because start (\(newStart)) is beyond end (\(effectiveLength) - \(newEnd))" ) + #endif return false } @@ -297,7 +301,9 @@ public struct Frame: ~Copyable { public mutating func unclaim(fromStart: Int, fromEnd: Int = 0, adjustSingleIPAggregate: Bool = true) -> Bool { if adjustSingleIPAggregate && isSingleIPAggregate { guard fromEnd == 0 else { - Logger.proto.fault("Trying to unclaim at the end \(fromEnd) bytes from a single-IP aggregate") + #if !DisableErrorLogging + Logger.proto.error("Trying to unclaim at the end \(fromEnd) bytes from a single-IP aggregate") + #endif return false } aggregateBufferLength += fromStart @@ -305,13 +311,17 @@ public struct Frame: ~Copyable { guard fromStart <= startOffset else { let startOffset = startOffset + #if !DisableErrorLogging Logger.proto.error("Frame cannot unclaim \(fromStart) start bytes (has \(startOffset) left)") + #endif return false } guard fromEnd <= endOffset else { let endOffset = endOffset + #if !DisableErrorLogging Logger.proto.error("Frame cannot unclaim \(fromEnd) end bytes (has \(endOffset) left)") + #endif return false } @@ -581,7 +591,9 @@ public struct Frame: ~Copyable { return } guard newValue < 64 else { - Logger.proto.fault("Cannot set DSCP value of \(newValue)") + #if !DisableErrorLogging + Logger.proto.error("Cannot set DSCP value of \(newValue)") + #endif return } if ipPacketValues == nil { diff --git a/Sources/SwiftNetwork/Protocols/IPProtocol.swift b/Sources/SwiftNetwork/Protocols/IPProtocol.swift index 735d188..209668c 100644 --- a/Sources/SwiftNetwork/Protocols/IPProtocol.swift +++ b/Sources/SwiftNetwork/Protocols/IPProtocol.swift @@ -914,7 +914,9 @@ public struct IPProtocol: NetworkProtocol { try write.uint16(value) } if !checksumResult.isValid { + #if !DisableErrorLogging Logger.proto.error("Serializing IPv4 checksum failed with result: \(checksumResult)") + #endif } } @@ -992,7 +994,9 @@ public struct IPProtocol: NetworkProtocol { try write.uint32(remoteAddressValue) } guard result.isValid else { + #if !DisableErrorLogging Logger.proto.error("Serializing IPv4 fragment failed with result: \(result)") + #endif fragmentFrame.finalize(success: false) fragmentationSucceeded = false break @@ -1016,7 +1020,9 @@ public struct IPProtocol: NetworkProtocol { self.setChecksumValue(frame: &fragmentFrame, value: checksumValue) } } catch { + #if !DisableErrorLogging Logger.proto.error("Failed to compute IPv4 fragment checksum") + #endif fragmentFrame.finalize(success: false) fragmentationSucceeded = false break @@ -1051,7 +1057,9 @@ public struct IPProtocol: NetworkProtocol { try write.uint32(remoteAddressValue) } if !result.isValid { + #if !DisableErrorLogging Logger.proto.error("Serializing IPv4 packet failed with result: \(result)") + #endif frame.finalize(success: false) return .removeFrameAndContinue } @@ -1077,7 +1085,9 @@ public struct IPProtocol: NetworkProtocol { } } } catch { + #if !DisableErrorLogging Logger.proto.error("Failed to finalize IP checksum") + #endif frame.finalize(success: false) return .removeFrameAndContinue } diff --git a/Sources/SwiftNetwork/QUIC/Packet.swift b/Sources/SwiftNetwork/QUIC/Packet.swift index 575d233..af8bb52 100644 --- a/Sources/SwiftNetwork/QUIC/Packet.swift +++ b/Sources/SwiftNetwork/QUIC/Packet.swift @@ -308,18 +308,22 @@ struct Packet: ~Copyable { var overrideSentNumberSize: EncodedPacketNumber.Size? { get { if let _overrideSentNumberSize { + #if !DisableErrorLogging Logger.proto.error( "WARNING: Reading overrideSentNumberSize only be used for unit testing!" ) + #endif return _overrideSentNumberSize } return nil } set(newValue) { if let newValue { + #if !DisableErrorLogging Logger.proto.error( "WARNING: Setting overrideSentNumberSize only be used for unit testing!" ) + #endif _overrideSentNumberSize = newValue } else { _overrideSentNumberSize = nil diff --git a/Sources/SwiftNetwork/QUIC/QUICConnectionID.swift b/Sources/SwiftNetwork/QUIC/QUICConnectionID.swift index dcfe864..9a438c0 100644 --- a/Sources/SwiftNetwork/QUIC/QUICConnectionID.swift +++ b/Sources/SwiftNetwork/QUIC/QUICConnectionID.swift @@ -88,8 +88,10 @@ public struct QUICConnectionID: Sendable, Equatable, CustomStringConvertible { // Creates a QUICConnectionID from an array. public init?(_ connectionID: [UInt8]) { guard connectionID.count <= QUICConnectionID.maximumSize else { + #if !DisableErrorLogging let connectionIDCount = connectionID.count - Logger.proto.fault("Invalid QUICConnectionID length \(connectionIDCount)") + Logger.proto.error("Invalid QUICConnectionID length \(connectionIDCount)") + #endif return nil } actualLength = connectionID.count @@ -101,15 +103,19 @@ public struct QUICConnectionID: Sendable, Equatable, CustomStringConvertible { if size <= QUICConnectionID.maximumSize { actualLength = size } else { - Logger.proto.fault("Invalid QUICConnectionID length \(size)") + #if !DisableErrorLogging + Logger.proto.error("Invalid QUICConnectionID length \(size)") + #endif actualLength = QUICConnectionID.maximumSize } } public init?(_ connectionID: Span) { guard connectionID.count <= QUICConnectionID.maximumSize else { + #if !DisableErrorLogging let connectionIDCount = connectionID.count - Logger.proto.fault("Invalid QUICConnectionID length \(connectionIDCount)") + Logger.proto.error("Invalid QUICConnectionID length \(connectionIDCount)") + #endif return nil } actualLength = connectionID.count @@ -120,7 +126,9 @@ public struct QUICConnectionID: Sendable, Equatable, CustomStringConvertible { public init(_ size: Int) { var size = size if size > QUICConnectionID.maximumSize { - Logger.proto.fault("Invalid QUICConnectionID length \(size)") + #if !DisableErrorLogging + Logger.proto.error("Invalid QUICConnectionID length \(size)") + #endif size = QUICConnectionID.maximumSize } if size != 0 && size < 4 { @@ -133,7 +141,9 @@ public struct QUICConnectionID: Sendable, Equatable, CustomStringConvertible { // Creates a QUICConnectionID from a buffer with a specific size. init?(_ buffer: [UInt8], size: Int) { guard size <= QUICConnectionID.maximumSize, buffer.count >= size else { - Logger.proto.fault("Invalid QUICConnectionID length \(size)") + #if !DisableErrorLogging + Logger.proto.error("Invalid QUICConnectionID length \(size)") + #endif return nil } let cidBytes = Array(buffer[0..