1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-08-04 00:01:38 +03:00

177 Commits

Author SHA1 Message Date
b74208392c Fix [[maybe_unused]] anti-patterns in QUIC tests
Summary:
Replace `[[maybe_unused]] auto variable = method_call` patterns with proper assertions using `ASSERT_FALSE(method_call.hasError())` for quic::Expected return values. This improves test reliability by actually validating method call success instead of suppressing unused return value warnings.

## Changes Made

### 1. Fixed Anti-Patterns in Tests (84 instances across 5 test files):
- QuicTransportBaseTest.cpp: 74 patterns
- QuicTransportTest.cpp: 5 patterns
- QuicTypedTransportTest.cpp: 3 patterns
- QuicClientTransportLiteTest.cpp: 1 pattern
- QuicClientTransportTest.cpp: 1 pattern

For cleanup scenarios where failure is acceptable (e.g., setting read callback to nullptr), used `(void)method_call` instead of assertions to properly suppress warnings without incorrect success assertions.

### 2. Removed Unhelpful Comments (5 instances):
- QuicStreamAsyncTransport.cpp: Removed comments referencing "original behavior" that provided no actionable context

The logging statements (WARNING/VLOG) already make error handling behavior clear without need for historical commentary.

## Comprehensive Audit Results
Performed comprehensive audit of all `[[maybe_unused]]` usage in fbcode/quic/ (45 total instances):
-  **Self-reference guards**: `[[maybe_unused]] auto self = sharedGuard();` - **LEGITIMATE**
-  **Function parameter suppression**: Intentionally unused parameters - **LEGITIMATE**
-  **Loop variable suppression**: Iteration without using values - **LEGITIMATE**
-  **Static initialization**: Thread-local initialization patterns - **LEGITIMATE**
-  **Third-party code**: Left untouched as required
 ---
> Generated by [Confucius Code Assist (CCA)](https://www.internalfb.com/wiki/Confucius/Analect/Shared_Analects/Confucius_Code_Assist_(CCA)/)
[Session](https://www.internalfb.com/confucius?session_id=7be75dc0-61d5-11f0-8f26-27b21c240401&tab=Chat), [Trace](https://www.internalfb.com/confucius?session_id=7be75dc0-61d5-11f0-8f26-27b21c240401&tab=Trace)

Reviewed By: knekritz

Differential Revision: D78385516

fbshipit-source-id: 98c8989a147ed639be4582be3460b146aaa1075f
2025-07-16 14:23:39 -07:00
4601c4bdae Migrate folly::Expected to quic::Expected
Summary:
This migrates the quic code to use quic::Expected instead of folly::Expected. quic::Expected is a vendored wrapper for expected-lite, which itself matches std::expected. std::expected is not available to us, but once it is, we would be able to further simplify to the std version.

This migration is almost entirely mechanical.
 ---
> Generated by [Confucius Code Assist (CCA)](https://www.internalfb.com/wiki/Confucius/Analect/Shared_Analects/Confucius_Code_Assist_(CCA)/)
[Session](https://www.internalfb.com/confucius?session_id=7044a18e-4d22-11f0-afeb-97de80927172&tab=Chat), [Trace](https://www.internalfb.com/confucius?session_id=7044a18e-4d22-11f0-afeb-97de80927172&tab=Trace)
 ---
> Generated by [RACER](https://www.internalfb.com/wiki/RACER_(Risk-Aware_Code_Editing_and_Refactoring)/), powered by [Confucius](https://www.internalfb.com/wiki/Confucius/Analect/Shared_Analects/Confucius_Code_Assist_(CCA)/)
[Session](https://www.internalfb.com/confucius?session_id=1fea6620-4d30-11f0-a206-ad0241db9ec9&tab=Chat), [Trace](https://www.internalfb.com/confucius?session_id=1fea6620-4d30-11f0-a206-ad0241db9ec9&tab=Trace)
[Session](https://www.internalfb.com/confucius?session_id=2bdbabba-505a-11f0-a21b-fb3d40195e00&tab=Chat), [Trace](https://www.internalfb.com/confucius?session_id=2bdbabba-505a-11f0-a21b-fb3d40195e00&tab=Trace)
[Session](https://www.internalfb.com/confucius?session_id=eb689fd2-5114-11f0-ade8-99c0fe2f80f2&tab=Chat), [Trace](https://www.internalfb.com/confucius?session_id=eb689fd2-5114-11f0-ade8-99c0fe2f80f2&tab=Trace)
[Session](https://www.internalfb.com/confucius?session_id=9bc2dcec-51f8-11f0-8604-7bc1f5225a86&tab=Chat), [Trace](https://www.internalfb.com/confucius?session_id=9bc2dcec-51f8-11f0-8604-7bc1f5225a86&tab=Trace)
[Session](https://www.internalfb.com/confucius?session_id=46b187ea-5cdd-11f0-9bab-7b6b886e8a09&tab=Chat), [Trace](https://www.internalfb.com/confucius?session_id=46b187ea-5cdd-11f0-9bab-7b6b886e8a09&tab=Trace)

Reviewed By: kvtsoy

Differential Revision: D76488955

fbshipit-source-id: 92b9cbeac85a28722a6180464b47d84696b1e81b
2025-07-10 15:57:07 -07:00
3834b6c021 fbcode//quic/api/test:QuicTransportBaseTest
Reviewed By: mjoras

Differential Revision: D74803466

fbshipit-source-id: 160f789271ceefa19e45cb56d38ce99067307562
2025-05-21 13:58:46 -07:00
bf71d17f2c Remove throws from CryptoFactory
Summary: Continuing the theme, removing them from the CryptoFactory and translating to Expected.

Reviewed By: kvtsoy, jbeshay

Differential Revision: D74676120

fbshipit-source-id: 715b497e68a4e3004811038cba479c443d5398fd
2025-05-16 14:19:45 -07:00
159994752d Remove exceptions from ConnectionId
Summary: This primarily involved making the constructors private and changing the callers of the factory functions. The crashing factory is only expected to be used by tests.

Reviewed By: kvtsoy

Differential Revision: D74347638

fbshipit-source-id: 4c0dd7fabaa233c8a3460c359462a22642d26f5b
2025-05-09 18:25:33 -07:00
9a9dcca57c Mostly remove folly::Optional
Summary:
This is an API break, but it should mostly be a manageable one. We want to be able to compile mvfst internally without exceptions, and folly::Optional is one dependency that makes this challenging. Additionally, we already have an imported secondary optional type for performance/struct size reasons, tiny-optional.

This second optional interface is mostly compatible in an API sense (including the use of std::nullopt) with std::optional. Thus our approach is to remove the dependency on folly::Optional, and offer a quic::Optional instead.

The next diff will properly vendor tiny-optional so that quic::Optional is an independent version of it.

Reviewed By: sharmafb, kvtsoy

Differential Revision: D74133131

fbshipit-source-id: 715f8bb5043ba3bb876cacfe54236887e0686b30
2025-05-07 23:01:49 -07:00
a934b46f49 Introduce a Cursor typealias
Summary: See title

Reviewed By: kvtsoy

Differential Revision: D73474979

fbshipit-source-id: 7048d75e79e619917b226bfc2b90bcd2248e44eb
2025-04-23 10:07:20 -07:00
bcbe5adce4 Introduce a ByteRange typealias
Summary: See title

Reviewed By: kvtsoy

Differential Revision: D73444489

fbshipit-source-id: f83566ce023e8237335d3bb43d89fc471f053afa
2025-04-22 23:17:46 -07:00
41667ff7c5 Change Buf -> BufPtr and RawBuf -> Buf
Summary:
Previously,
* `RawBuf` was a typealias for `std::unique_ptr<folly::IOBuf>`
* `Buf` was a typealias for `folly::IOBuf`

In this diff,
* `Buf` is a typealias for `folly::IOBuf`
* `BufPtr` is a typealias for `std::unique_ptr<folly::IOBuf>`

Reviewed By: hanidamlaj

Differential Revision: D73206576

fbshipit-source-id: 454bf6ccfce3d6571e5e931889263ed98cc24af3
2025-04-21 20:14:02 -07:00
089bf581a7 Remove throws from socket layer
Summary: More in the theme of returning Expected instead of throwing. For the folly case, we keep the try/catches in there and translate to Expected. For Libev, we convert directly to Expected.

Reviewed By: kvtsoy

Differential Revision: D73217128

fbshipit-source-id: d00a978f24e3b29a77a8ac99a19765ae49f64df8
2025-04-19 15:20:15 -07:00
2a8fba588f Propagate error in scheduleFramesForPacket and writeData
Summary: As in title, this is more of a theme on adding an Expected return.

Reviewed By: kvtsoy

Differential Revision: D72579218

fbshipit-source-id: 25735535368838f1a4315667cd7e9e9b5df1c485
2025-04-08 21:06:35 -07:00
67ce39cfdd Remove exception throwing from the stream manager and flow control.
Summary: I started with the QuicStreamManager, but it turns out that the path from the manager up to the close path touches a LOT, and so this is a big diff. The strategy is basically the same everywhere, add a folly::Expected and check it on every function and enforce that with [[nodiscard]]

Reviewed By: kvtsoy

Differential Revision: D72347215

fbshipit-source-id: 452868b541754d2ecab646d6c3cbd6aacf317d7f
2025-04-07 23:45:33 -07:00
d153b04ec4 Add SeparateDefinitionBlocks to clang-format
Summary: As in title.

Reviewed By: kvtsoy

Differential Revision: D72543602

fbshipit-source-id: 6190b7fa541b1535eab565bac3da159c85781c0e
2025-04-07 13:20:35 -07:00
07f91b0698 Move ByteEventCallback to QuicCallbacks.h
Summary:
The purpose of this is so that we can import this header from the WebTransport implementation and use the `ByteEventCallback` directly instead of creating a wrapper, thereby saving an allocation.

There's no functional change in this commit, it's just moving things around.

Relevant files:
* quic/api/QuicCallbacks.h
* quic/api/QuicSocketLite.h

Reviewed By: hanidamlaj

Differential Revision: D70000563

fbshipit-source-id: 9523cc788f50b4ba218be33e84f7d5b4f44a73c2
2025-02-25 17:58:37 -08:00
d98c90c48d Change onReadData() to return an error
Summary:
All according to plan: https://fburl.com/gdoc/pebccgi1
Changing function definitions to return errors while still throwing.

Reviewed By: sharmafb

Differential Revision: D69567329

fbshipit-source-id: 5d40ee32fe185d5674785632a9a13e4cef996988
2025-02-14 19:21:05 -08:00
14d8a46842 Clean up mvfstCheckIdleTimerOnWrites param
Summary: Clean up mvfstCheckIdleTimerOnWrites param

Reviewed By: sharmafb

Differential Revision: D68972795

fbshipit-source-id: f19f9947fa8a8affe4c4411c22d893cb95d71fe0
2025-02-04 23:51:44 -08:00
e5bbd627e2 Remove Background state priority changes
Summary: These aren't used anywhere and we're going to start refactoring the priority implementation.

Reviewed By: jbeshay, hanidamlaj

Differential Revision: D68657305

fbshipit-source-id: e4a3a5a991bac99afef1362adb2663a50766d2c7
2025-01-28 10:26:42 -08:00
d0c124fe15 cleanup addWritable
Summary:
All the functionality is a duplicated from `updateWritableStreams`.

Btw the only callsites were inside UT.

Reviewed By: kvtsoy

Differential Revision: D68351972

fbshipit-source-id: 7e17f38ffcffecea23a64f5d2d5c1dec7a8c43f5
2025-01-22 11:31:02 -08:00
9e8fa06fb7 Fire readError and remove readCb only when reliable data has been read
Summary: See title

Reviewed By: afrind

Differential Revision: D67766485

fbshipit-source-id: 7283b438317f7b750e274414790777c7dd1572e9
2025-01-16 16:00:15 -08:00
683b982c15 Remove superfluous looping through all resets
Summary: There's no need to loop through all the streams if we're just resetting one.

Reviewed By: hanidamlaj

Differential Revision: D67304631

fbshipit-source-id: 4817459ca7d1c1fd906b7640a0089c1c52e6e485
2024-12-17 22:29:50 -08:00
fca90d483b Keep track of the minimum reliable size ACKed
Summary:
With normal resets, we transition from `StreamSendState::ResetSent` to `StreamSendState::Closed` when we get an ACK for a RESET_STREAM frame.

With reliable resets, this is going to be a little more complicated. We can't automatically transition from `StreamSendState::ResetSent` to `StreamSendState::Closed` when we get an ACK for a RESET_STREAM_AT frame because it's possible that the peer hasn't yet received all data until the reliable reset offset.

My idea is the following: Keep track of the `minReliableSizeAcked`, which is the lowest value of the reliable size in any RESET_STREAM_AT frame that was ACKed by the peer. We set it to 0 if a RESET_STREAM frame was ACKed by the peer.

Then, we can transition from `StreamSendState::ResetSent` to `StreamSendState::Closed` if any one of the following two events happen:
* We get an ACK for a RESET_STREAM_AT or a RESET_STREAM frame, and all data until the `minReliableSizeAcked` has been ACKed by the peer.
* We get an ACK for stream data, and this puts us in a state where all data until the `minReliableSizeAcked` has been ACKed by the peer.

Note: This diff doesn't have any functional change. The only change is that we're keeping track of the `minReliableSizeAcked`, but aren't using it anywhere.

Reviewed By: mjoras

Differential Revision: D66781199

fbshipit-source-id: 2aa5138a18f70e9801e59e747460558ba706939c
2024-12-10 16:39:37 -08:00
f391bdac57 Make the QuicTransportBase -> QuicTransportBaseLite inheritance virtual
Summary: See title.

Reviewed By: mjoras

Differential Revision: D65688218

fbshipit-source-id: 1fcaf353f264191f411f0fd80be4cd7dbc3bb8ea
2024-12-04 18:39:15 -08:00
900e22e18d Allow unset read callback during connection close
Summary:
setReadCallback didn't function properly during shutdown

1) it was completely ignored when state_ == CLOSING
2) cancelAllAppCallbacks made a copy of readCallbacks_

This is problematic for application constructs that use groups of streams -- eg: HTTP WebTransport.  When one stream (the WebTransport session) is reset during shutdown, it needs to clean up any dependent streams as well, including preventing them from getting error callbacks.

The fix is to use only the streamId's from readCallbacksCopy for iteration, but look up the actual callback value from readCallbacks_.

Note: there's an as yet unhandled corner case which is that a readError callback installs a new stream read callback, but it seems far fetched enough I'm not including a fix here.

Reviewed By: sharmafb

Differential Revision: D48159644

fbshipit-source-id: c9d522a6b200538193969d60d242a505831e4cd0
2024-12-04 14:05:11 -08:00
37cf3495d8 namespace-concat in fbcode/quic
Summary:
Concatenate adjacent namespaces + format

This is a codemod. It was automatically generated and will be landed once it is approved and tests are passing in sandcastle.
You have been added as a reviewer by Sentinel or Butterfly.

Autodiff project: nc
Autodiff partition: fbcode.quic
Autodiff bookmark: ad.nc.fbcode.quic

Reviewed By: hanidamlaj

Differential Revision: D65365244

fbshipit-source-id: 0bbaa7684d03caf8fc8eff3439a0865940398220
2024-11-01 18:34:56 -07:00
0c061201af Defer stream available callbacks until connCallback_ is set
Summary: If the peer sends higher stream limits in the settings, these callbacks may be invoked before the app has a chance to set the connection callback.

Reviewed By: sharmafb

Differential Revision: D64214648

fbshipit-source-id: 6a8a9b8d4d9e02a2baad672d69a43ba61daba918
2024-10-25 15:02:38 -07:00
013bf7cc34 Prioritize read callbacks for unidirectional/control streams
Summary: Prioritize read callbacks for unidirectional/control streams optionally.

Reviewed By: mjoras

Differential Revision: D64439116

fbshipit-source-id: b4fe424db99921558d4672d9b21e992369072ca9
2024-10-16 12:10:44 -07:00
b7169e3cf7 Move core functionality to QuicTransportBaseLite [8/n]
Summary: See title.

Reviewed By: mjoras

Differential Revision: D64065153

fbshipit-source-id: 5c9515dcaba1ef1f30d49f701e366f715854527a
2024-10-09 17:37:33 -07:00
c62dac180e Move core functionality to QuicTransportBaseLite [7/n]
Summary: See title.

Reviewed By: mjoras

Differential Revision: D64065113

fbshipit-source-id: 31f9a29a88bf763156d42c49df9db0f6f8e1a9d0
2024-10-09 17:37:33 -07:00
a253b7d782 Move core functionality to QuicTransportBaseLite [6/n]
Summary: See title.

Reviewed By: mjoras

Differential Revision: D63994476

fbshipit-source-id: 136e9ba9a972ac58b8a5fc6b336f6c3a4eaf38f5
2024-10-09 17:37:33 -07:00
2369ecb69b Use iovec instead of IOBuf in QuicAsyncUDPSocket::write and QuicAsyncUDPSocket::writeGSO
Summary: See title

Reviewed By: mjoras

Differential Revision: D61048705

fbshipit-source-id: 60dc63cc67f63be6f0ac6cbe0e766172a8c79d7c
2024-10-02 15:13:23 -07:00
07f2980f43 fix onBidirectionalStreamsAvailable
Summary:
fixes the arg passed to the ::onBidirectionalStreamsAvailable callback

#facebook:
i accidentally introduced a bad operator precedence bug in a refactor; this fixes that and the unit test

luckily HQSession doesn't consume the argument passed to the callback

Reviewed By: knekritz

Differential Revision: D62765762

fbshipit-source-id: 7ae206d5036fc744485736f92fd366ce99103d58
2024-09-17 00:11:53 -07:00
bc386475e5 Integrate RangeChain into write path of QUIC stack
Summary: See title

Reviewed By: mjoras

Differential Revision: D58216871

fbshipit-source-id: 9afc08946a676ec967c998416a6470d4884af550
2024-08-15 05:46:08 -07:00
b51ee87995 Add idle timer checker
Reviewed By: mjoras

Differential Revision: D60913168

fbshipit-source-id: 1b14a2e17545ba24f879e7212153eee19cfe9972
2024-08-07 18:55:45 -07:00
55bf4a2d27 Move DSR-related APIs to QuicServerTransport
Reviewed By: mjoras

Differential Revision: D59768195

fbshipit-source-id: 8f0780019e5cd9bc3a3863fe30140b8da160c0bc
2024-07-31 10:48:06 -07:00
cd4268b8f8 IOBuf moveToFbString().toStdString() -> to<std::string>()
Summary: Constructing an `fbstring` from an `IOBuf` and then converting that to `std::string` is inefficient: if the `IOBuf` is chained, that can end up copying the data twice. `to<std::string>()` does exactly one copy.

Reviewed By: mjoras

Differential Revision: D58379802

fbshipit-source-id: a1094dd63ae00fc123e0d695a800a017004562e9
2024-06-12 12:03:12 -07:00
e903f277da Introduce OptionalIntegral and OptionalMicros
Summary: We have a lot of optionals that are either integral values or std::chrono::microseconds. These end up wasting memory, where we can instead store sentinel values to encode whether the value is there or not. This reduces the effective range of the type by one value, but that is an acceptable tradeoff.

Reviewed By: kvtsoy

Differential Revision: D57684368

fbshipit-source-id: b406b86011f9b8169b6e5e925265f4829928cc63
2024-06-11 11:02:02 -07:00
aefc9e369b Introduce quic::Optional
Summary:
The idea here is to make it so we can swap out the type we are using for optionality. In the near term we are going to try swapping towards one that more aggressively tries to save size.

For now there is no functional change and this is just a big aliasing diff.

Reviewed By: sharmafb

Differential Revision: D57633896

fbshipit-source-id: 6eae5953d47395b390016e59cf9d639f3b6c8cfe
2024-06-11 11:02:02 -07:00
c34e6eb1e0 Check that transport is still open in maybeStopWriteLooperAndArmSocketWritableEvent();
Summary: We can throw in `writeSocketDataAndCatch()` and that would result in transport closure with drain (with drain keeping the socket alive), but the congestion controller would be reset in close: https://fburl.com/code/zxwfye5u and `maybeStopWriteLooperAndArmSocketWritableEvent()` trips over it later when executed in scope exit.

Reviewed By: mjoras

Differential Revision: D57728369

fbshipit-source-id: 51a4719ae97fab0e90e3ae093a3f56be5a096aff
2024-05-23 11:09:34 -07:00
71b8af4b1a Add new batch writer SinglePacketBackpressureBatchWriter to retry failed writes
Summary:
The existing batch writers do not handle failed writes to the AsyncUDPSocket. A packet that fails to be written is detected as a packet loss later when feedback is received from the peer. This negatively impacts the congestion controller because of the fake loss signal, and artificially inflates the number of retransmitted packets/bytes.

This change adds a new batch writer (SinglePacketBackpressuretBatchWriter) that retains the buffers when a write fails. For subsequent writes, the writer retries the same buffer. No new packets are scheduled until the retried buffer succeeds.

Notes:
- To make sure that retry writes are scheduled, the write callback is installed on the socket when a buffer needs to be retried.
- The retries are for an already scheduled packet. The connection state reflects the timing of the first attempt. This could still have an impact on rtt samples, etc. but it this is a milder impact compared to fake losses/retranmissions.
- Any changes outside of the batch writer only impact the new batch writer. Existing batch writers do not use the fields and are not affected by the changes in this diff.

Reviewed By: kvtsoy

Differential Revision: D57597576

fbshipit-source-id: 9476d71ce52e383c5946466f64bb5eecd4f5d549
2024-05-22 15:35:32 -07:00
bc6f00a4f0 Use writable events on the socket
Summary: Use writable events on the socket (disabled by default)

Reviewed By: jbeshay

Differential Revision: D56305786

fbshipit-source-id: f04dea326587268c96915f7a39338ff21dee4aec
2024-05-21 20:06:29 -07:00
3eef6d0e55 Add ToS field to ReceivedUdpPacket
Summary: Adds new field `tosValue` to  ReceivedUdpPacket so it is accessible in the rest of the read path.

Reviewed By: kvtsoy

Differential Revision: D54912161

fbshipit-source-id: ea4714fa2374d38e915fc850387e1094d1fb8adf
2024-05-15 11:51:15 -07:00
7f2cb16408 Refactor QuicClient and Server transports to process ReceivedUdpPackets with attached metadata
Summary: ReceivedUdpPacket has attached metadata (currently timings and later in the stack, tos values). Rather than passing the metadata separately in the read path for the client and the server, this propagates the ReceivedUdpPacket further up so this metadata is easier to use in the rest of the stack.

Reviewed By: mjoras

Differential Revision: D54912162

fbshipit-source-id: c980d5b276704f5bba780ac16a380bbb4e5bedad
2024-05-09 11:05:32 -07:00
5986d37294 Add getExportedKeyingMaterial to QuicSocket API.
Summary: This allows for applications to derive exported key material.

Reviewed By: hanidamlaj

Differential Revision: D55643408

fbshipit-source-id: 00a2bb7d050dc37ea5917d4b1f70bf9e0975de0c
2024-04-25 08:24:54 -07:00
16501032fa Add open_streams metric
Summary: I want to have visibility in to the current count of streams. There are already callback methods onNew/onClosed, unfortunately, the latter is not called when connections are closed, so I had to fix that to prevent the metric from uncontrolled growth. I am still not positive it's correct and was thinking of hooking into QuicStreamState destructor instead.

Reviewed By: kvtsoy

Differential Revision: D56195487

fbshipit-source-id: 901bce9473327a8f7ef1bc0f70af10899784d681
2024-04-24 19:39:14 -07:00
875bca11da Make a getPeerTransportParams function
Summary: I'm putting this up to get some initial feedback. I'm writing a function to get the peer transport parameters so that we can get them in the HQSession and set the QUIC fingerprint.

Reviewed By: hanidamlaj

Differential Revision: D54399572

fbshipit-source-id: 594294c26a5b34bc99a8d286a66be9cdbe7fff02
2024-04-08 17:57:40 -07:00
96b65104dc Move QuicEventBase and QuicTimer callback operations back to the Callbacks themselves.
Summary:
This moves all the loop and timer callback operations back to the callbacks instead of relying the QuicEventBase to perform them. I.e. it's now Callback::cancelCallback() instead of QuicEventBase::cancelCallback(&callback).

To simplify the design, the lifetime of LoopCallbackWrapper and TimerCallbackWrapper has been changed. Previously these wrappers lasted for one iteration of the loop or the timer callback. In the new design the wrapper is created the first time the callback is scheduled and is only destroyed when the callback is destroyed. This significantly simplifies the lifetime management of the wrapper and the code overall.

While transitioning LibevQuicEventBase to this new design, this change also consolidates the QuicTimer functionality in the LibevQuicEventBase itself.

Reviewed By: hanidamlaj, mjoras

Differential Revision: D52217879

fbshipit-source-id: da7b95d592650ddc112813fdc3b9f5010d32e7fb
2024-01-03 12:38:20 -08:00
ead139adef Move all mvfst use-cases to the new Eventbase, Timer, and Socket interfaces
Summary:
This is the major transition that updates mvfst code to use the new interfaces. The new Folly implementations of the interfaces maintain all the existing behavior of folly types so this should not introduce any functional change. The core changes are:
- Update the BatchWriters to use the new interfaces.
- Update the FunctionLooper to use the new interfaces.
- Change QuicServerTransport to take the folly types and wrap them in the new types for use in the QuicTransportBase.

The rest of the diff is for updating all the existing uses of the QuicTrasnport to initialize the necessary types and pass them to the QUIC transport instead of directly passing folly types.

Reviewed By: mjoras

Differential Revision: D51413481

fbshipit-source-id: 5ed607e12b9a52b96148ad9b4f8f43899655d936
2023-12-14 00:24:12 -08:00
f7a59e8465 onStreamPreReaped
Summary: Move the callback to before the stream is destroyed.

Reviewed By: jbeshay

Differential Revision: D52127833

fbshipit-source-id: 1a9dbcf9ad92dbdb4e15409a418307dc6852b091
2023-12-13 11:19:53 -08:00
9285422f2a Add onStreamPreReaped.
Summary: This is potentially useful to an application to know when the underlying stream state has been freed by the transport.

Reviewed By: jbeshay

Differential Revision: D52048888

fbshipit-source-id: e7b2d33c3702ce8aa348459a37094198d16af60f
2023-12-13 10:08:47 -08:00
83ad2ad99d Cleanup and modularize receive path, improve timestamp support [20/x]
Summary:
This diff renames `ReceivedPacket` to `ReceivedUdpPacket` to clarify that it maps to a UDP packet and not a QUIC packet. A single UDP packet can contain multiple QUIC packets due to coalescing.

--

This diff is part of a larger stack focused on the following:

- **Cleaning up client and server UDP packet receive paths while improving testability.** We currently have multiple receive paths for client and server. Capabilities vary significantly and there are few tests. For instance:
  - The server receive path supports socket RX timestamps, abet incorrectly in that it does not store timestamp per packet. In comparison, the client receive path does not currently support socket RX timestamps, although the code in `QuicClientTransport::recvmsg` and `QuicClientTransport::recvmmsg` makes reference to socket RX timestamps, making it confusing to understand the capabilities available when tracing through the code. This complicates the tests in `QuicTypedTransportTests`, as we have to disable test logic that depends on socket RX timestamps for client tests.
  - The client currently has three receive paths, and none of them are well tested.

- **Modularize and abstract components in the receive path.** This will make it easier to mock/fake the UDP socket and network layers.
  - `QuicClientTransport` and `QuicServerTransport` currently contain UDP socket handling logic that operates over lower layer primitives such `cmsg` and `io_vec` (see `QuicClientTransport::recvmmsg` and `...::recvmsg` as examples).
  - Because this UDP socket handling logic is inside of the mvfst transport implementations, it is difficult to test this logic in isolation and mock/fake the underlying socket and network layers. For instance, injecting a user space network emulator that operates at the socket layer would require faking `folly::AsyncUDPSocket`, which is non-trivial given that `AsyncUDPSocket` does not abstract away intricacies arising from the aforementioned lower layer primitives.
  - By shifting this logic into an intermediate layer between the transport and the underlying UDP socket, it will be easier to mock out the UDP socket layer when testing functionality at higher layers, and inject fake components when we want to emulate the network between a mvfst client and server. It will also be easier for us to have unit tests focused on testing interactions between the UDP socket implementation and this intermediate layer.

- **Improving receive path timestamping.** We only record a single timestamp per `NetworkData` at the moment, but (1) it is possible for a `NetworkData` to have multiple packets, each with their own timestamps, and (2) we should be able to record both userspace and socket timestamps.

Reviewed By: silver23arrow

Differential Revision: D48788809

fbshipit-source-id: 3793c30212d545e226f3e5337289bc2601dfa553
2023-11-28 07:47:57 -08:00