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
4 changes: 2 additions & 2 deletions Sources/SwiftNetwork/Protocols/QUICConnectionProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public struct QUICConnectionProtocol: NetworkProtocol {
public var enableL4S: Bool?

internal var _maxUDPPayloadSize: UInt16 = UInt16.max
var maxUDPPayloadSize: UInt16 {
public var maxUDPPayloadSize: UInt16 {
get { self._maxUDPPayloadSize }
set { self._maxUDPPayloadSize = newValue }
}
Expand All @@ -235,7 +235,7 @@ public struct QUICConnectionProtocol: NetworkProtocol {
}

internal var _initialPacketSize: UInt16 = 0
var initialPacketSize: UInt16 {
public var initialPacketSize: UInt16 {
get { self._initialPacketSize }
set { self._initialPacketSize = newValue }
}
Expand Down
31 changes: 28 additions & 3 deletions Sources/SwiftNetwork/QUIC/QUICConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,14 @@ public final class QUICConnection: ManyToManyApplicationStreamProtocol,
pmtudIgnoreCost = protocolOptions.quicConnectionOptions.pmtudIgnoreCost
pmtudInterval = protocolOptions.quicConnectionOptions.pmtudUpdateInterval

// RFC 9000 - 14.1. Initial Datagram Size
// Datagrams containing Initial packets MAY exceed 1200 bytes if the sender
// believes that the network path and peer both support the size that it chooses
let requestedInitialPacketSize = Int(protocolOptions.quicConnectionOptions.initialPacketSize)
if requestedInitialPacketSize > Constants.initialMSS {
initialMSS = requestedInitialPacketSize
}

pacingEnabled = protocolOptions.quicConnectionOptions.enablePacing

testSendingShortPackets =
Expand Down Expand Up @@ -4540,6 +4548,13 @@ public final class QUICConnection: ManyToManyApplicationStreamProtocol,
log.debug(
"Remote max datagram size \(remoteMaxDatagramFrameSize)"
)
// A flow opened before the peer's transport parameters sized itself
// against a limit of 0, so recompute now that the limit is known.
if let path = currentPath {
applyToAllSecondaryFlows { datagramFlow in
datagramFlow.updateUsableDatagramFrameSize(connection: self, path: path)
}
}
}
guard let remoteTPMaxDatagramFrameSize else {
self.remoteMaxDatagramFrameSize = 0
Expand Down Expand Up @@ -5213,6 +5228,7 @@ extension QUICConnection {
self.applicationCloseError = QUICApplicationError(frame.errorCode, frame.reason)
receivedApplicationClose = true
}
log.info("received APPLICATION_CLOSE code: \(frame.errorCode), reason: '\(frame.reason)'")
close()
return true
}
Expand All @@ -5222,6 +5238,7 @@ extension QUICConnection {
self.closeError = QUICTransportError(frame.errorCode, frame.reason)
receivedConnectionClose = true
}
log.info("received CONNECTION_CLOSE code: \(frame.errorCode), reason: '\(frame.reason)'")
close()
return true
}
Expand Down Expand Up @@ -5853,13 +5870,21 @@ extension QUICConnection {
logPrefixer: logPrefixer
)
multiplexedSecondaryFlows[newFlowIdentifier] = newFlow
deliverNewInboundSecondaryFlowEvent(newFlow.reference)

newFlow.log.debug("Created inbound datagram flow for \(newFlowIdentifier)")

withCurrentPath { path in
newFlow.updateUsableDatagramFrameSize(connection: self, path: path)
}
let datagramMetadata = QUICProtocol.metadata()
datagramMetadata.perProtocolMetadata?.datagramFlowID = newFlow.flowID
datagramMetadata.perProtocolMetadata?.isDatagramFlow = true
datagramMetadata.perProtocolMetadata?.usableDatagramFrameSize = UInt16(newFlow.usableDatagramSize)
datagramMetadata.perProtocolMetadata?.quicConnectionMetadata = self.connectionMetadata
secondaryInboundFlowLinkage.deliverNewInboundFlowEvent(
reference,
flowReference: newFlow.reference,
flowMetadata: datagramMetadata
)
newFlow.log.debug("Created inbound datagram flow for \(newFlowIdentifier)")

matchingFlowIdentifier = newFlowIdentifier
}
Expand Down
11 changes: 11 additions & 0 deletions Tests/SwiftNetworkTests/SwiftNetworkQUICHarnessTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,17 @@ final class SwiftNetworkQUICHarnessTests: NetTestCase {
QUICTestHarness().runQUICTest(datagram: true, blockSize: 1000, blockCount: 10)
}

func testQUICDatagramWithLargeInitialPacketSize() {
let clientOptions = QUICProtocol.options()
clientOptions.connectionOptions.initialPacketSize = 1400
Comment thread
agnosticdev marked this conversation as resolved.
QUICTestHarness().runQUICTest(
datagram: true,
blockSize: 1000,
blockCount: 10,
clientOptions: clientOptions
)
}

func testQUICDatagramRemoteMaxDatagramFrameSize() {
QUICTestHarness().runQUICTest(
datagram: true,
Expand Down
Loading