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

Modify uTP selective ACKs to conform to BEP #7071

Closed
wants to merge 1 commit into from
Closed

Modify uTP selective ACKs to conform to BEP #7071

wants to merge 1 commit into from

Conversation

thrnz
Copy link
Contributor

@thrnz thrnz commented Sep 12, 2022

The size of libtorrent's uTP selective ACK payload appears to be rounded up to the nearest byte, however BEP 29 defines it as 'a bitmask of at least 32 bits, in multiples of 32 bits.'

This potential change conforms to the BEP by rounding up to the nearest 4 byte multiple. Note that sack is the SACK payload size in bytes (ie len from the BEP which 'must be at least 4, and in multiples of 4').

I'm not sure if this is actually an issue in practice at all, or if there are any clients out there in the wild that might have issues receiving SACKs that don't strictly conform.

See #7068

@arvidn
Copy link
Owner

arvidn commented Sep 15, 2022

uTorrent always send exactly 4 bytes: https://github.com/bittorrent/libutp/blob/master/utp_internal.cpp#L815
this is where it parses incoming SACK fields (also called EACK in uTorrent): https://github.com/bittorrent/libutp/blob/master/utp_internal.cpp#L1441

As far as I can tell, it doesn't require the SACK bitfield to be a multiple of 4 bytes.

@@ -139,7 +139,7 @@ TORRENT_TEST(utp_pmtud)
TEST_EQUAL(metric(cnt, "utp.utp_packets_in"), 593);
TEST_EQUAL(metric(cnt, "utp.utp_payload_pkts_in"), 66);

TEST_EQUAL(metric(cnt, "utp.utp_packets_out"), 603);
TEST_EQUAL(metric(cnt, "utp.utp_packets_out"), 602);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not clear to me why this change would result in one less packet to be sent. If anything, a larger SACK header would eat into the size of the payload that would fit in the packet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd only updated that packet count in order to see if the other tests would still pass, which they seem to do.

I'm yet to work out why that particular test has one less packet, but that was my first thought as well - with the extra 3 bytes possible in the header, if anything it should be the other way round.

Copy link
Contributor Author

@thrnz thrnz Sep 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might be an issue when picking up a Nagled packet with a SACK already attached if the sack size has increased since it was held back. It appears to keep the old size, rather than growing it if needed. It looks like an existing issue that just happened to trigger on that one test with this PR compared to without.

In this case, the unpatched version misses out on acking a packet (the 1 byte SACK payload needs to grow to hold 9 bits in this case but doesn't), while the patched version already has enough padding to grow (although it will be an issue growing a Nagled SACK from 32-33 bits). As a result, the unpatched version sends an extra ack packet later on to catch up.

When comparing utp debug logfiles of the failing test using this PR against those without they appear to diverge right after that happens.

Hopefully if that gets fixed, then that test will pass without needing to update the packet count.

Copy link

@ValeZAA ValeZAA Nov 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you attach the two pcap files: one with 603 packets, one with 602?

@stale
Copy link

stale bot commented Dec 26, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 26, 2022
@stale stale bot closed this Jan 22, 2023
@ValeZAA
Copy link

ValeZAA commented Jun 5, 2023

uTorrent always send exactly 4 bytes:

Are you sure this is indeed code used by mutorrent? Also it is not like it is not full of bugs. Will this break compatibility with mutorrent?

@ValeZAA
Copy link

ValeZAA commented Jun 13, 2023

Why is this bot closing stale pull requests and issues? That is not serious.

@ValeZAA
Copy link

ValeZAA commented Nov 3, 2024

I just realised that BEP 29 was written by @arvidn probably by reading utorrent open source parts. So that means it is just a typo. Errata not possible in BEP?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants