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

39 Commits

Author SHA1 Message Date
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
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
71b4e1c613 Use correct value for messageSizes in SendmmsgInplacePacketBatchWriter
Summary: `messageSizes` is supposed to be the number of iovecs in each message, and not the length of the iovec. This was causing crashes in Edgeray (T215909454).

Reviewed By: jbeshay

Differential Revision: D70129535

fbshipit-source-id: 6d79e6ac0789402674e753297984b3691d371338
2025-02-25 08:40:14 -08:00
598b6f245d Make a SendmmsgGSOInplacePacketBatchWriter
Summary: The `SendmmsgGSOInplacePacketBatchWriter` is equivalent to the `SendmmsgGSOPacketBatchWriter`, except that it operates on the in-place buffer.

Reviewed By: jbeshay

Differential Revision: D69410775

fbshipit-source-id: 32782f9797e7e2354cbafabf956985b96900f59b
2025-02-13 00:14:48 -08:00
c6d19083df Make a SendmmsgInplacePacketBatchWriter
Summary: See title.

Reviewed By: mjoras

Differential Revision: D69073543

fbshipit-source-id: 11f8a376909df9ae2bc7560cac09a1d2f431acaa
2025-02-10 16:28:00 -08:00
69d9467c0c Move SendmmsgPacketBatchWriter to sendmsg with iovecs
Summary: I'm switching the usages of `writem` to use iovecs instead of IOBufs.

Reviewed By: kvtsoy

Differential Revision: D68857701

fbshipit-source-id: 96461aac85f39da9b85e16f2927b4539e712e5cb
2025-01-30 14:51:03 -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
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
a84708be4b Less direct Buf access in BufAccessor
Summary:
**Context**
The `BufAccessor` is used to access a contiguous section of memory. Right now, it works with a `Buf` under the hood.

**Overall plan**
The plan is to change the `BufAccessor` to use a `uint8_t*` instead. Since we're using section of contiguous memory, there's no need to use a chained buffer abstraction here. This'll move us closer to deprecating the usage `folly::IOBuf`.

**What this diff is doing**
Most use cases of the `BufAccessor` look like the following:
```
auto buf = bufAccessor.obtain();
// Do something with buf, like calling trimEnd
bufAccessor.release(buf)
```
I'm adding APIs to the `BufAccessor` so that there's no need to `obtain()` and `release()` the `Buf`. We'd instead just call an API on the `BufAccessor`, which would call that same API on the underlying `folly::IOBuf`. Later on, we'll change the `BufAccessor` to use a `uint8_t*` under the hood.

I'm currently leaving in the `obtain()`, `release()`, and `buf()` APIs because Fizz and the AsyncUDPSocket expect `folly::IOBuf` as inputs in many of their APIs. Once those callsites are migrated off `folly::IOBuf`, we can remove these APIs.

Reviewed By: mjoras

Differential Revision: D60973166

fbshipit-source-id: 52aa3541d0c4878c7ee8525d70ac280508b61e24
2024-08-09 14:35:39 -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
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
cc9ccc8f99 Remove ThreadLocalBatchWriter
Summary: Remove ThreadLocalBatchWriter since it's not being used.

Reviewed By: mjoras

Differential Revision: D50809221

fbshipit-source-id: 3754e64320518165654217b1e368429c69a944c5
2023-11-07 14:51:15 -08:00
ad3dd0ec01 Cleanup and modularize receive path, improve timestamp support [7/x]
Summary:
This diff:
- Adds `QuicAsyncUDPSocketWrapperImpl` and changes existing instantiatons of `QuicAsyncUDPSocketWrapper` to instead instantiate `QuicAsyncUDPSocketWrapperImpl`. In follow up diffs, pure virtual functions will be added to `QuicAsyncUDPSocketWrapper` and implemented in `QuicAsyncUDPSocketWrapperImpl`. See D48717388 for more information.

--

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: jbeshay, mjoras

Differential Revision: D48717592

fbshipit-source-id: e21368f5c1f3b37608fc1c88617e96b93a02f6e0
2023-09-21 07:57:58 -07:00
a1445434b0 Cleanup and modularize receive path, improve timestamp support [5/x]
Summary:
This diff changes `QuicAsyncUDPSocketWrapper` so that it is an abstraction layer that inherits from `QuicAsyncUDPSocketType`, instead of simply being a container with aliases.
- Key changes in `QuicAsyncUDPSocketWrapper.h`, the rest of the updates switch us from using `QuicAsyncUDPSocketType` to `QuicAsyncUDPSocketWrapper`.
- It's difficult to mock the UDP socket today given that we expose the entire `folly::AsyncUDPSocket` type to the higher layers of the QUIC stack. This complicates testing and emulation because any mock / fake has to implement low level primitives like `recvmmsg`, and because the `folly::AsyncUDPSocket` interface can change over time.
- Pure virtual functions will be defined in `QuicAsyncUDPSocketWrapper` in a follow up diff to start creating an interface between the higher layers of the mvfst QUIC stack and the UDP socket, and this interface will abstract away lower layer details such as `cmsgs` and `io_vec`, and instead focus on populating higher layer structures such as `NetworkData` and `ReceivedPacket` (D48714615). This will make it easier for us to mock or fake the UDP socket.

This diff relies on changes to `folly::MockAsyncUDPSocket` introduced in D48717389.

--

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: jbeshay, hanidamlaj

Differential Revision: D48717388

fbshipit-source-id: 4f34182a69ab1e619e454da19e357a6a2ee2b9ab
2023-09-21 07:57:58 -07:00
df49cb664f Always call writeGSO
Summary: There's no need to call write when there's only one packet, since write just wraps writeGSO. This simplifies the use of options and will allow for setting a TXTIME when there's only one packet to send.

Reviewed By: kvtsoy

Differential Revision: D48526018

fbshipit-source-id: d934ddce8d3a35febb58ff253fc7a9bed3ef975c
2023-08-21 16:13:38 -07:00
d47d381da9 Use WriteOptions instead of a single int to allow for txTime setting too
Summary: Use WriteOptions instead of a single int to allow for txTime setting too

Reviewed By: mjoras

Differential Revision: D48218906

fbshipit-source-id: 00a1d4905b54ec0614860f9cdd8b58c9d6e6ef9a
2023-08-16 13:19:12 -07:00
15a619fccf Add SinglePacketInplaceBatchWriter
Summary:
The new writer will use a single IOBuf for in-place writes via a
accessor.

Reviewed By: jbeshay, mjoras

Differential Revision: D47648606

fbshipit-source-id: c6094eb3445587337f8a03e203aeadb2954f76b1
2023-07-27 17:00:41 -07:00
2b0d0b2f2b Separate batch writer into multiple modules
Summary: Separate batch writer into multiple modules

Reviewed By: hanidamlaj, mjoras

Differential Revision: D47112819

fbshipit-source-id: f6b4fd64ab99541f1923ae9c432e5a1fb0986fef
2023-07-13 18:39:45 -07:00
4a0dd1e2a4 QuicAsyncUDPSocketWrapper
Reviewed By: jbeshay

Differential Revision: D46379200

fbshipit-source-id: f6a7c1cf68108872e05e6fd8adb7f00aae22b2ed
2023-07-11 15:21:15 -07:00
c6d9731247 Switch to chained memory data path if GSO is not supported
Summary:
Check for GSO support once before the first write, cache the value and use it throughout the conn lifetime.
If GSO is not supported, ensure we use chained memory write path.

Reviewed By: mjoras

Differential Revision: D40240513

fbshipit-source-id: b699b4633246f3c15d2be7b39580686e44c2aab3
2022-10-11 14:43:12 -07:00
e27b107c6a use gmock 1.10 instead of 1.8
Summary: See D34622171 for details

Differential Revision: D34688142

fbshipit-source-id: ec0c3fdd92723629e0c484388b9ae24436780cf9
2022-03-07 20:03:35 -08:00
7f2f302f96 Revert D34351084: Migrate from googletest 1.8 to googletest 1.10
Differential Revision:
D34351084 (715dec85be)

Original commit changeset: 939b3985ab63

Original Phabricator Diff: D34351084 (715dec85be)

fbshipit-source-id: 2fd17e0ccd9d1f1d643f4a372d84cb95f5add1f8
2022-03-03 04:41:46 -08:00
715dec85be Migrate from googletest 1.8 to googletest 1.10 (#67)
Summary:
X-link: https://github.com/facebookincubator/hsthrift/pull/67

Updating `googletest` from `1.8.0` to `1.10.0`

Reviewed By: mzlee, igorsugak, luciang, meyering, r-barnes

Differential Revision: D34351084

fbshipit-source-id: 939b3985ab63a06b6d511ec8711c2d5863bdfea8
2022-03-03 03:46:03 -08:00
00e67c1bf9 mvfst License Header Update
Reviewed By: lnicco

Differential Revision: D33587012

fbshipit-source-id: 972eb440f0156c9c04aa6e8787561b18295c1a97
2022-01-18 13:56:12 -08:00
2660a288b3 Update Company Name
Summary: - as title

Reviewed By: lnicco

Differential Revision: D33513410

fbshipit-source-id: 282b6f512cf83b9abb7990402661135b658f7bd1
2022-01-13 12:07:48 -08:00
a92dfc18eb Pass FizzServerContext using FizzServerQuicHandshakeContext (#165)
Summary:
This remove one more fizz specific element from the common API

Depends on https://github.com/facebookincubator/mvfst/issues/162

Pull Request resolved: https://github.com/facebookincubator/mvfst/pull/165

Reviewed By: yangchi

Differential Revision: D23637314

Pulled By: xttjsn

fbshipit-source-id: a3436510accc37687f6e3ea770fd120fa314ecdc
2020-09-14 13:08:46 -07:00
04c63839e4 Start splitting the fizz specific parts of the server (#160)
Summary:
This is following a similar pattern than what was done for the client side.

Pull Request resolved: https://github.com/facebookincubator/mvfst/pull/160

Reviewed By: yangchi

Differential Revision: D23560951

Pulled By: xttjsn

fbshipit-source-id: 351417cbfa3230112fff4c4de59b307f88389cf6
2020-09-08 17:17:47 -07:00
c47c3cf5c6 Revert PMTU and size-enforced packet builder
Differential Revision: D23283619

fbshipit-source-id: b7fe31871dad5711016234a2d10ae84edc4fd24c
2020-08-22 16:55:54 -07:00
4762cfb927 Introduce PMTU as a variable
Summary:
First step towards d6d. Semantically we need to separate the old `udpSendPacketLen` into `peerMaxPacketSize` as well as `currPMTU`. The former is directly tied to the peer's max_packet_size transport parameter whereas the second is controlled by d6d. To get the actual udp mss, call `conn_->getUdpSendPacketLen()`, which will use the minimum of the two if d6d is enabled, otherwise it will fallback to use `peerMaxPacketSize` only.

During processClientInitialParams and processServerInitialParams, we no longer need to check whether `canIgnorePathMTU` is set because that logic is moved to `setUdpSendPacketLen`. If d6d is enabled, we set both `peerMaxPacketSize` and `currPMTU` to `packetSize` because receiving an initial packet of size x indicates both that the peer accepts x-sized packet and that the PMTU is at least x.

Many call sites and tests are changed.

Faebook:
For now, d6d is considered enabled if `canIgnorePathMTU==false` and `turnoffPMTUD==true`. Down the road, from semantic & practical POV at least one of them should be renamed to something like `enableD6D`, since enabling d6d implies turning off PMTUD and that we should not ignore PMTU. We can keep one for the sake of testing.

Reviewed By: mjoras

Differential Revision: D22049806

fbshipit-source-id: 7a9b30b7e2519c132101509be56a9e63b803dc93
2020-08-17 16:15:24 -07:00
a7dc8cb4f7 Log an error when we write a packet larger than limit
Summary: as title

Reviewed By: bschlinker

Differential Revision: D22542572

fbshipit-source-id: 4f53a1c916b22e33f183208efb671c1d0883309c
2020-07-15 11:19:10 -07:00
9554a67c73 add a check for Quic inplace writer for the remaining buffer size
Summary:
as title. Instead of checking against the packet size limit, this
leaves a 10 bytes room since we have a bug that writes out packets that's
slightly larger than udpSendPacketLen. Most of such packet will be 1-2 bytes
larger than original packets.

Reviewed By: mjoras

Differential Revision: D21642386

fbshipit-source-id: 6ca68d48828cb7f8ee692e0d5f452f5389a56bfd
2020-05-26 12:47:44 -07:00
ddf49f4d26 Use MockAsyncUDPSocket for Quic inplace batch writer tests
Summary:
To make sure the  writer maker function actually return the Inplace
writer

Reviewed By: lnicco

Differential Revision: D21613419

fbshipit-source-id: da7e59b43785b13fd91cc1a737db87af7dfb1c8f
2020-05-17 09:57:16 -07:00
7022459fb0 Quic Inplace batch writer checks either packet size limit or next packet size
Summary: as title

Reviewed By: mjoras

Differential Revision: D21429917

fbshipit-source-id: 5be997bfd75cfab89c3d9289a31b0efab69a80fc
2020-05-12 07:04:56 -07:00
014d50aa41 Quic socket write for the inplace buffer writing
Summary: as title

Reviewed By: mjoras

Differential Revision: D21211414

fbshipit-source-id: 5c4b8a747457e3f21da77541a35da1af1b1ac6e4
2020-05-05 09:53:07 -07:00
55443f2b16 Add support for thread local batch writers
Summary: Add support for thread local batch writers

Reviewed By: mjoras

Differential Revision: D21004810

fbshipit-source-id: 907a25f95afeab78fdc7e83cbab87b4f51adc3d3
2020-04-23 18:39:09 -07:00
655fef6a95 Add SendmmsgGSOPacketBatchWriter
Summary: Add SendmmsgGSOPacketBatchWriter

Reviewed By: mjoras

Differential Revision: D19529123

fbshipit-source-id: 15d2e591f91574bae0e33fd92094c24482246ee7
2020-01-28 12:44:46 -08:00
50d4939e9e Initial commit of mvfst 2019-04-22 23:42:46 -07:00