1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-07-30 14:43:05 +03:00

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
This commit is contained in:
Aman Sharma
2024-08-09 14:35:39 -07:00
committed by Facebook GitHub Bot
parent 9216eed3d8
commit a84708be4b
16 changed files with 166 additions and 133 deletions

View File

@ -14,6 +14,7 @@
#include <quic/codec/QuicPacketBuilder.h>
#include <quic/codec/QuicWriteCodec.h>
#include <quic/codec/Types.h>
#include <quic/common/BufAccessor.h>
#include <quic/flowcontrol/QuicFlowController.h>
#include <quic/happyeyeballs/QuicHappyEyeballsFunctions.h>
@ -231,14 +232,11 @@ DataPathResult continuousMemoryBuildScheduleEncrypt(
IOBufQuicBatch& ioBufBatch,
const Aead& aead,
const PacketNumberCipher& headerCipher) {
auto buf = connection.bufAccessor->obtain();
auto prevSize = buf->length();
connection.bufAccessor->release(std::move(buf));
auto prevSize = connection.bufAccessor->length();
auto rollbackBuf = [&]() {
auto buf = connection.bufAccessor->obtain();
buf->trimEnd(buf->length() - prevSize);
connection.bufAccessor->release(std::move(buf));
connection.bufAccessor->trimEnd(
connection.bufAccessor->length() - prevSize);
};
// It's the scheduler's job to invoke encode header
@ -272,16 +270,17 @@ DataPathResult continuousMemoryBuildScheduleEncrypt(
}
CHECK(!packet->header.isChained());
auto headerLen = packet->header.length();
buf = connection.bufAccessor->obtain();
CHECK(
packet->body.data() > buf->data() && packet->body.tail() <= buf->tail());
packet->body.data() > connection.bufAccessor->data() &&
packet->body.tail() <= connection.bufAccessor->tail());
CHECK(
packet->header.data() >= buf->data() &&
packet->header.tail() < buf->tail());
packet->header.data() >= connection.bufAccessor->data() &&
packet->header.tail() < connection.bufAccessor->tail());
// Trim off everything before the current packet, and the header length, so
// buf's data starts from the body part of buf.
buf->trimStart(prevSize + headerLen);
connection.bufAccessor->trimStart(prevSize + headerLen);
// buf and packetBuf is actually the same.
auto buf = connection.bufAccessor->obtain();
auto packetBuf =
aead.inplaceEncrypt(std::move(buf), &packet->header, packetNum);
CHECK(packetBuf->headroom() == headerLen + prevSize);
@ -1627,9 +1626,9 @@ WriteQuicDataResult writeConnectionDataToSocket(
if (connection.transportSettings.dataPathType ==
DataPathType::ContinuousMemory) {
CHECK(connection.bufAccessor->ownsBuffer());
auto buf = connection.bufAccessor->obtain();
CHECK(buf->length() == 0 && buf->headroom() == 0);
connection.bufAccessor->release(std::move(buf));
CHECK(
connection.bufAccessor->length() == 0 &&
connection.bufAccessor->headroom() == 0);
}
return {ioBufBatch.getPktSent(), 0, bytesWritten};
}