mirror of
https://github.com/facebookincubator/mvfst.git
synced 2025-11-25 15:43:13 +03:00
Cleanup and modularize receive path, improve timestamp support [10/x]
Summary: This diff makes the fields in `NetworkData` private so that they can only be manipulated via accessors. - This will be used in a subsequent diff to make it possible to populate a new `ReceivedPacket::Timings` structure in each `ReceivedPacket` held by a `NetworkData` object with the timing information currently held in `NetworkData.` - These accessors are temporary and being used to split up the stack, so relying on existing tests to provide coverage instead of adding new tests here. -- 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 Differential Revision: D48724715 fbshipit-source-id: 0230ea3feea525fa15b908161f444f4f6d9d4b39
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d1f042b967
commit
cb10ddf0ce
@@ -590,7 +590,7 @@ void QuicServerWorker::forwardNetworkData(
|
||||
"Forwarding packet with unknown connId version from client={} to another process, routingInfo={}",
|
||||
client.describe(),
|
||||
logRoutingInfo(routingData.destinationConnId));
|
||||
auto recvTime = networkData.receiveTimePoint;
|
||||
auto recvTime = networkData.getReceiveTimePoint();
|
||||
takeoverPktHandler_.forwardPacketToAnotherServer(
|
||||
client, std::move(networkData).moveAllData(), recvTime);
|
||||
QUIC_STATS(statsCallback_, onPacketForwarded);
|
||||
@@ -795,7 +795,7 @@ void QuicServerWorker::dispatchPacketData(
|
||||
"Forwarding packet from client={} to another process, routingInfo={}",
|
||||
client.describe(),
|
||||
logRoutingInfo(dstConnId));
|
||||
auto recvTime = networkData.receiveTimePoint;
|
||||
auto recvTime = networkData.getReceiveTimePoint();
|
||||
takeoverPktHandler_.forwardPacketToAnotherServer(
|
||||
client, std::move(networkData).moveAllData(), recvTime);
|
||||
QUIC_STATS(statsCallback_, onPacketForwarded);
|
||||
@@ -879,7 +879,7 @@ void QuicServerWorker::dispatchPacketData(
|
||||
// This could be a new connection, add it in the map
|
||||
// verify that the initial packet is at least min initial bytes
|
||||
// to avoid amplification attacks. Also check CID sizes.
|
||||
if (networkData.totalData < kMinInitialPacketSize ||
|
||||
if (networkData.getTotalData() < kMinInitialPacketSize ||
|
||||
!isValidConnIdLength(dstConnId)) {
|
||||
// Don't even attempt to forward the packet, just drop it.
|
||||
VLOG(3) << "Dropping small initial packet from client=" << client;
|
||||
@@ -889,7 +889,7 @@ void QuicServerWorker::dispatchPacketData(
|
||||
|
||||
// If there is a token present, decrypt it (could be either a retry
|
||||
// token or a new token)
|
||||
folly::io::Cursor cursor(networkData.packets.front().buf.get());
|
||||
folly::io::Cursor cursor(networkData.getPackets().front().buf.get());
|
||||
auto maybeEncryptedToken = maybeGetEncryptedToken(cursor);
|
||||
bool hasTokenSecret = transportSettings_.retryTokenSecret.hasValue();
|
||||
|
||||
@@ -914,7 +914,7 @@ void QuicServerWorker::dispatchPacketData(
|
||||
// send a retry packet back to the client
|
||||
if (!isValidRetryToken &&
|
||||
((newConnRateLimiter_ &&
|
||||
newConnRateLimiter_->check(networkData.receiveTimePoint)) ||
|
||||
newConnRateLimiter_->check(networkData.getReceiveTimePoint())) ||
|
||||
(unfinishedHandshakeLimitFn_.has_value() &&
|
||||
globalUnfinishedHandshakes >= (*unfinishedHandshakeLimitFn_)()))) {
|
||||
QUIC_STATS(statsCallback_, onConnectionRateLimited);
|
||||
@@ -948,7 +948,7 @@ void QuicServerWorker::sendResetPacket(
|
||||
// Only send resets in response to short header packets.
|
||||
return;
|
||||
}
|
||||
auto packetSize = networkData.totalData;
|
||||
auto packetSize = networkData.getTotalData();
|
||||
auto resetSize = std::min<uint16_t>(packetSize, kDefaultMaxUDPPayload);
|
||||
// Per the spec, less than 43 we should respond with packet size - 1.
|
||||
if (packetSize < 43) {
|
||||
|
||||
Reference in New Issue
Block a user