From 2c624b4e8236b41bc71340aa013d2e04e6076fb7 Mon Sep 17 00:00:00 2001 From: agnosticdev Date: Sat, 13 Jun 2026 12:20:46 -0700 Subject: [PATCH 1/3] Fix QUICTransfer --- Sources/Tools/QUICTransfer/main.swift | 71 ++++++++++++++------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/Sources/Tools/QUICTransfer/main.swift b/Sources/Tools/QUICTransfer/main.swift index f1e32fc..3c20b0c 100644 --- a/Sources/Tools/QUICTransfer/main.swift +++ b/Sources/Tools/QUICTransfer/main.swift @@ -224,44 +224,49 @@ final class QUICTransfer { maximumBurst: 10 ) } - // Transfer all of the data - for _ in 0..= sendSize { + index += 1 + group.leave() + // Finish here + runNextIteration(iterationIndex + 1, readDataSize: 0) + } else { + runNextIteration(iterationIndex, readDataSize: totalRead) } } - index += 1 - group.leave() } - clientInput.stop() - clientInput.teardown() - serverInput.stop() - serverInput.teardown() - group.leave() + runNextIteration(0, readDataSize: 0) } group.wait() print("Completed \(index) / \(iterations) transfers") From 0bfbc1296b2ebd5ce667a19d8aa6ec6e74906f36 Mon Sep 17 00:00:00 2001 From: agnosticdev Date: Mon, 15 Jun 2026 14:45:55 -0700 Subject: [PATCH 2/3] agnosticdev/FixQUICTransfer: Adopt BridgeDatagramProtocol in QUICTransfer --- Sources/Tools/QUICTransfer/main.swift | 182 ++++++++++++++++---------- 1 file changed, 114 insertions(+), 68 deletions(-) diff --git a/Sources/Tools/QUICTransfer/main.swift b/Sources/Tools/QUICTransfer/main.swift index 3c20b0c..7929f3c 100644 --- a/Sources/Tools/QUICTransfer/main.swift +++ b/Sources/Tools/QUICTransfer/main.swift @@ -43,9 +43,16 @@ final class QUICTransfer { let NSEC_PER_MSEC = UInt64(Duration.milliseconds(1) / Duration.nanoseconds(1)) var serverSigningKey = P256.Signing.PrivateKey() - func run(iterations: Int, loggingHandle: LoggingHandle, group: DispatchGroup, sendSize: Int) -> Double { - let ipv4Client = Endpoint(address: IPv4Address(localIPv4Address)!, port: 0) - let ipv4Server = Endpoint(address: IPv4Address(remoteIPv4Address)!, port: 0) + func run(iterations: Int, + loggingHandle: LoggingHandle, + group: DispatchGroup, + sendSize: Int, + linkDelay: NetworkDuration = .zero) -> Double { + let ipv4Client = Endpoint(address: IPv4Address(localIPv4Address)!, port: 1234) + let ipv4Server = Endpoint(address: IPv4Address(remoteIPv4Address)!, port: 2345) + var clientStream: StreamUpperHarness? = nil + var clientInput: NewStreamFlowHarness? = nil + var serverInput: NewStreamFlowHarness? = nil // Create a random payload to send back and forth var payload = [UInt8](repeating: 0, count: sendSize) payload = (0..= sendSize { + group.leave() + } + group.wait() + + guard let serverStream else { + return 0 + } + + group.enter() + context.async { + var serverReadDataSizeForIteration = 0 + var serverReadCompletion: ((Bool) -> Void)? = nil + serverReadCompletion = { _ in + let readBytes = serverStream.readAndDrop() + if readBytes > 0 { + serverReadDataSizeForIteration += readBytes + totalReadSize += readBytes + } + if serverReadDataSizeForIteration >= payload.count { + serverReadCompletion = nil index += 1 group.leave() - // Finish here - runNextIteration(iterationIndex + 1, readDataSize: 0) } else { - runNextIteration(iterationIndex, readDataSize: totalRead) + serverStream.waitForInboundDataAvailable(completion: serverReadCompletion!) } } + serverStream.waitForInboundDataAvailable(completion: serverReadCompletion!) } - runNextIteration(0, readDataSize: 0) + group.wait() + } + + group.enter() + context.async { + clientStream.stop() + clientInput.stop() + clientInput.teardown() + serverInput.stop() + serverInput.teardown() + group.leave() } group.wait() + print("Completed \(index) / \(iterations) transfers") // Short circuit and return 0 if index does not match iterations if index != iterations { @@ -286,6 +321,7 @@ final class QUICTransfer { var iterations = 10000 // 5gb total (if 500000 sendSize) var loggingHandler: LoggingHandle = LoggingHandle(loggingType: .none) var sendSize = 500000 // 500kb +var linkDelay = NetworkDuration.zero var arguments = CommandLine.arguments.dropFirst(0) if arguments.contains("-iterations"), let index = arguments.firstIndex(of: "-iterations") @@ -315,6 +351,15 @@ if arguments.contains("-size"), } } } +if arguments.contains("-link-delay-ms"), + let index = arguments.firstIndex(of: "-link-delay-ms") +{ + if arguments.count >= (index + 2) { + if let linkDelayOption = Int(arguments[index + 1]) { + linkDelay = .milliseconds(linkDelayOption) + } + } +} // Create and run the transfers let quicTransfer = QUICTransfer() @@ -324,7 +369,8 @@ let totalTime = quicTransfer.run( iterations: iterations, loggingHandle: loggingHandler, group: group, - sendSize: sendSize + sendSize: sendSize, + linkDelay: linkDelay ) if totalTime > 0 { print("Finished all (\(iterations)) transfers in \(totalTime) seconds") From 7fbd2cf46a30335414690da221275cebb797ec07 Mon Sep 17 00:00:00 2001 From: agnosticdev Date: Mon, 15 Jun 2026 14:46:43 -0700 Subject: [PATCH 3/3] agnosticdev/FixQUICTransfer: Adopt BridgeDatagramProtocol in QUICTransfer --- Sources/Tools/QUICTransfer/main.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Sources/Tools/QUICTransfer/main.swift b/Sources/Tools/QUICTransfer/main.swift index 7929f3c..cdf35dc 100644 --- a/Sources/Tools/QUICTransfer/main.swift +++ b/Sources/Tools/QUICTransfer/main.swift @@ -43,11 +43,13 @@ final class QUICTransfer { let NSEC_PER_MSEC = UInt64(Duration.milliseconds(1) / Duration.nanoseconds(1)) var serverSigningKey = P256.Signing.PrivateKey() - func run(iterations: Int, - loggingHandle: LoggingHandle, - group: DispatchGroup, - sendSize: Int, - linkDelay: NetworkDuration = .zero) -> Double { + func run( + iterations: Int, + loggingHandle: LoggingHandle, + group: DispatchGroup, + sendSize: Int, + linkDelay: NetworkDuration = .zero + ) -> Double { let ipv4Client = Endpoint(address: IPv4Address(localIPv4Address)!, port: 1234) let ipv4Server = Endpoint(address: IPv4Address(remoteIPv4Address)!, port: 2345) var clientStream: StreamUpperHarness? = nil