Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility for datagrams to be dropped when not able to send #4320

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8f40f35
Added possibility for datagrams to be dropped when not able to send
May 23, 2024
03dceb1
Switch from not insert into queue if not empty to cancel all outstand…
May 29, 2024
b010939
Ran dotnet script
iiztp May 30, 2024
efb718a
Removed copies from clipboard I made when comitting...
May 30, 2024
ba30093
Modified for comments
May 30, 2024
f658311
Test if alg works now
iiztp May 30, 2024
1528319
style
nibanks May 30, 2024
084c172
It works now, but sometimes segfault, didn't went further
May 31, 2024
bbb2bf4
Merge because I didn't pulled before modifying..
May 31, 2024
9aeaab5
Inspired from previous work
May 31, 2024
9386e84
Doc + Modif flag hex because I'm bad at hex
May 31, 2024
1b20bac
I didn't save the file for the doc ;-;
May 31, 2024
928501f
Update datagram.c
iiztp May 31, 2024
ad9457f
Update datagram.c
iiztp May 31, 2024
5706fd9
Update datagram.c
iiztp May 31, 2024
d6835df
Merge branch 'microsoft:main' into main
iiztp Jun 1, 2024
e5e67b9
Test that crashes because ?
Jun 19, 2024
0e9041f
Merge branch 'main' of https://github.com/iiztp/msquic
Jun 19, 2024
2d7355e
Found out why core dumped
Jun 19, 2024
ce0d31e
Update src/test/lib/DatagramTest.cpp
iiztp Jun 19, 2024
86e903a
Revert changes of submodule
Jun 19, 2024
fbc659d
Merge branch 'main' into main
iiztp Jun 20, 2024
ffc798a
Merge branch 'microsoft:main' into main
iiztp Jul 17, 2024
4afc187
Merge branch 'microsoft:main' into main
iiztp Aug 14, 2024
62458da
Merge branch 'microsoft:main' into main
iiztp Sep 17, 2024
d8d4627
Merge branch 'microsoft:main' into main
iiztp Oct 26, 2024
90f03e0
Update DocFx after documentation changes.
Oct 26, 2024
6f716c2
Removed msquicdocs
iiztp Oct 28, 2024
cf0c4c2
Merge branch 'microsoft:main' into main
iiztp Jan 5, 2025
ea47e31
Update DocFx after documentation changes.
Jan 5, 2025
b52bf36
Added test for dropping datagrams
iiztp Jan 5, 2025
a3a08a4
Resolving comments
iiztp Jan 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion docs/api/DatagramSend.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,36 @@ QUIC_STATUS

# Parameters

**TODO**
`Connection`

The current established connection.

`Buffers`

An array of `QUIC_BUFFER` structs that each contain a pointer and length to app data to send on the stream. This may be `NULL` **only** if `BufferCount` is zero.

`BufferCount`

The number of `QUIC_BUFFER` structs in the `Buffers` array. This may be zero.

`Flags`

The set of flags that controls the behavior of `DatagramSend`:

Value | Meaning
--- | ---
**QUIC_SEND_FLAG_NONE**<br>0 | No special behavior. Data is not allowed in 0-RTT by default.
**QUIC_SEND_FLAG_ALLOW_0_RTT**<br>1 | Indicates that the data is allowed to be sent in 0-RTT (if available). Makes no guarantee the data will be sent in 0-RTT. Additionally, even if 0-RTT keys are available the data may end up being sent in 1-RTT for multiple reasons.
**QUIC_SEND_FLAG_START**<br>2 | **Unused and ignored** for `DatagramSend`
**QUIC_SEND_FLAG_FIN**<br>4 | **Unused and ignored** for `DatagramSend`
**QUIC_SEND_FLAG_DGRAM_PRIORITY**<br>8 | Sets a priority to ensure a datagram is sent before others.
**QUIC_SEND_FLAG_DELAY_SEND**<br>16 | **Unused and ignored** for `DatagramSend`
**QUIC_SEND_FLAG_CANCEL_ON_LOSS**<br>32 | **Unused and ignored** for `DatagramSend`
**QUIC_SEND_FLAG_CANCEL_ON_BLOCKED**<br>64 | Allows MsQuic to drop frames when all the data that could be sent has been flushed out, but there are still some frames remaining in the queue.

`ClientSendContext`

The app context pointer (possibly null) to be associated with the send.

# Return Value

Expand Down
1 change: 1 addition & 0 deletions docs/api/StreamSend.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Value | Meaning
**QUIC_SEND_FLAG_DGRAM_PRIORITY**<br>8 | **Unused and ignored** for `StreamSend`
**QUIC_SEND_FLAG_DELAY_SEND**<br>16 | Provides a hint to MsQuic to indicate the data does not need to be sent immediately, likely because more is soon to follow.
**QUIC_SEND_FLAG_CANCEL_ON_LOSS**<br>32 | Informs MsQuic to irreversibly mark the associated stream to be canceled when packet loss has been detected on it. I.e., all sends on a given stream are subject to this behavior from the moment the flag has been supplied for the first time.
**QUIC_SEND_FLAG_CANCEL_ON_BLOCKED**<br>64 | **Unused and ignored** for `StreamSend` for now

`ClientSendContext`

Expand Down
31 changes: 31 additions & 0 deletions src/core/datagram.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,3 +588,34 @@

return TRUE;
}

_IRQL_requires_max_(PASSIVE_LEVEL)
void
QuicDatagramCancelBlocked(
_In_ QUIC_CONNECTION* Connection
)
{
QUIC_DATAGRAM* Datagram = &Connection->Datagram;
QUIC_SEND_REQUEST** SendQueue = &Datagram->SendQueue;
while (*SendQueue != NULL) {
if ((*SendQueue)->Flags & QUIC_SEND_FLAG_CANCEL_ON_BLOCKED) {
QUIC_SEND_REQUEST* SendRequest = *SendQueue;
if (Datagram->PrioritySendQueueTail == &SendRequest->Next) {
Datagram->PrioritySendQueueTail = SendQueue;

Check warning on line 604 in src/core/datagram.c

View check run for this annotation

Codecov / codecov/patch

src/core/datagram.c#L604

Added line #L604 was not covered by tests
}
*SendQueue = SendRequest->Next;
QuicDatagramCancelSend(Connection, SendRequest);
} else {
SendQueue = &((*SendQueue)->Next);
}
}
Datagram->SendQueueTail = SendQueue;

if (Datagram->SendQueue != NULL) {
QuicSendSetSendFlag(&Connection->Send, QUIC_CONN_SEND_FLAG_DATAGRAM);
} else {
QuicSendClearSendFlag(&Connection->Send, QUIC_CONN_SEND_FLAG_DATAGRAM);
}

QuicDatagramValidate(Datagram);
}
6 changes: 6 additions & 0 deletions src/core/datagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,9 @@ QuicDatagramProcessFrame(
const uint8_t * const Buffer,
_Inout_ uint16_t* Offset
);

_IRQL_requires_max_(PASSIVE_LEVEL)
void
QuicDatagramCancelBlocked(
_In_ QUIC_CONNECTION* Connection
);
5 changes: 5 additions & 0 deletions src/core/send.c
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,11 @@ QuicSendFlush(
//QuicConnUpdatePeerPacketTolerance(Connection, Builder.TotalCountDatagrams);
}

//
// Clears the SendQueue list of not sent packets if the flag is applied
//
QuicDatagramCancelBlocked(Connection);

return Result != QUIC_SEND_INCOMPLETE;
}
#pragma warning(pop)
Expand Down
1 change: 1 addition & 0 deletions src/cs/lib/msquic_generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ internal enum QUIC_SEND_FLAGS
DELAY_SEND = 0x0010,
CANCEL_ON_LOSS = 0x0020,
PRIORITY_WORK = 0x0040,
CANCEL_ON_BLOCKED = 0x0080,
}

internal enum QUIC_DATAGRAM_SEND_STATE
Expand Down
1 change: 1 addition & 0 deletions src/inc/msquic.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ typedef enum QUIC_SEND_FLAGS {
QUIC_SEND_FLAG_DELAY_SEND = 0x0010, // Indicates the send should be delayed because more will be queued soon.
QUIC_SEND_FLAG_CANCEL_ON_LOSS = 0x0020, // Indicates that a stream is to be cancelled when packet loss is detected.
QUIC_SEND_FLAG_PRIORITY_WORK = 0x0040, // Higher priority than other connection work.
QUIC_SEND_FLAG_CANCEL_ON_BLOCKED = 0x0080, // Indicates that a frame should be dropped when it can't be sent immediately.
} QUIC_SEND_FLAGS;

DEFINE_ENUM_FLAG_OPERATORS(QUIC_SEND_FLAGS)
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/trace/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ One of the built-in capabilities of WPA is the ability to analyze CPU trace info
### Linux
Linux perf command is one of the way to collect such information.
```sh
# on Linux
# on Linux (kernel > 5.10)
sudo apt-get install -y linux-perf
# on Linux (kernel <= 5.10)
sudo apt-get install -y linux-tools-`uname -r`
# use your own options
perf record -a -g -F 10 -o out.perf.data
Expand Down
18 changes: 18 additions & 0 deletions src/test/lib/DatagramTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ QuicTestDatagramSend(
TEST_TRUE(ServerConfiguration.IsValid());

uint8_t RawBuffer[] = "datagram";
uint8_t RawBigBuffer[1100] = {0};
QUIC_BUFFER DatagramBuffer = { sizeof(RawBuffer), RawBuffer };
QUIC_BUFFER BigBuffer = { sizeof(RawBigBuffer), RawBigBuffer };

SelectiveLossHelper LossHelper;

Expand Down Expand Up @@ -255,6 +257,22 @@ QuicTestDatagramSend(
TEST_TRUE(Client.GetDatagramsSuspectLost() > InitialLostCount);
CxPlatSleep(100);
#endif
for (int i = 0; i < 20; i++) {
iiztp marked this conversation as resolved.
Show resolved Hide resolved
TEST_QUIC_SUCCEEDED(
MsQuic->DatagramSend(
Client.GetConnection(),
&BigBuffer,
1,
(i%2 == 0) ? QUIC_SEND_FLAG_CANCEL_ON_BLOCKED : QUIC_SEND_FLAG_NONE,
nullptr));
}

Tries = 0;
while (Client.GetDatagramsCanceled() == 0 && ++Tries < 10) {
CxPlatSleep(100);
}

TEST_NOT_EQUAL(0, Client.GetDatagramsCanceled());

Client.Shutdown(QUIC_CONNECTION_SHUTDOWN_FLAG_NONE, QUIC_TEST_NO_ERROR);
if (!Client.WaitForShutdownComplete()) {
Expand Down
Loading