Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions Sources/SwiftNetwork/Protocols/Frame.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand All @@ -297,21 +301,27 @@ 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
}

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
}

Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions Sources/SwiftNetwork/Protocols/IPProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftNetwork/QUIC/Packet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 15 additions & 5 deletions Sources/SwiftNetwork/QUIC/QUICConnectionID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<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
Expand All @@ -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 {
Expand All @@ -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..<min(size, QUICConnectionID.maximumSize)])
Expand Down
2 changes: 2 additions & 0 deletions Sources/SwiftNetwork/QUIC/StreamSendBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ struct StreamSendBuffer: ~Copyable {
// currentSendOffset is at bytes we no longer have, they're already ACKd?
// Could be re-ordering problem?
let _storageStartOffset = storageStartOffset
#if !DisableErrorLogging
Logger.proto.error(
"currentSendOffset \(currentSendOffset) is out of date, storageStartOffset \(_storageStartOffset)"
)
#endif
return 0
}
return offsetPastLastByte - currentSendOffset
Expand Down