-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
refactor: Replace ToS with DSCP #2564
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is FTBFS on a few platforms, e.g. here on FreeBSD: https://trtc.mikedld.com/buildConfiguration/Transmission_Sanity_FreeBSDAmd64cyassl/170967?showRootCauses=true&expandBuildProblemsSection=true&expandBuildChangesSection=true&showLog=170967_963_628.1051
Also, please use code_style.sh (which calls clang-format) to format the code
Thanks!
I'll guess it broke on FreeBSD because
When I ran |
Yikes, OK don't sweat the code_style then -- different clang-format versions can give different outputs and I can re-run it after this PR gets merged. But if you are using clang-format (12, 13, or 14) and the only issue is that it's breaking macros in new code, you could try wrapping them in // clang-format off
...
// clang-format on |
The 'Sanity' CI is still failing on the BSDs. Please LMK if you can't see the build logs when logging in as a guest to the CI box |
Zzzz of course, I amended the commit without staging the change. Hopefully it will go through this time |
Using clang-format 13 here, the line it complains about is the |
IP TOS was superseeded by DSCP in RFC 2474 (December 1998).
/* | ||
* Definitions for DiffServ Codepoints as per RFCs 2474, 3246, 4594 & 8622. | ||
* Not all are guaranteed to be defined in <netinet/ip.h> so we keep a copy of the DSCP values. | ||
*/ | ||
#ifndef IPTOS_DSCP_AF11 | ||
#define IPTOS_DSCP_AF11 0x28 | ||
#define IPTOS_DSCP_AF12 0x30 | ||
#define IPTOS_DSCP_AF13 0x38 | ||
#define IPTOS_DSCP_AF21 0x48 | ||
#define IPTOS_DSCP_AF22 0x50 | ||
#define IPTOS_DSCP_AF23 0x58 | ||
#define IPTOS_DSCP_AF31 0x68 | ||
#define IPTOS_DSCP_AF32 0x70 | ||
#define IPTOS_DSCP_AF33 0x78 | ||
#define IPTOS_DSCP_AF41 0x88 | ||
#define IPTOS_DSCP_AF42 0x90 | ||
#define IPTOS_DSCP_AF43 0x98 | ||
#define IPTOS_DSCP_EF 0xb8 | ||
#endif | ||
|
||
#ifndef IPTOS_DSCP_CS0 | ||
#define IPTOS_DSCP_CS0 0x00 | ||
#define IPTOS_DSCP_CS1 0x20 | ||
#define IPTOS_DSCP_CS2 0x40 | ||
#define IPTOS_DSCP_CS3 0x60 | ||
#define IPTOS_DSCP_CS4 0x80 | ||
#define IPTOS_DSCP_CS5 0xa0 | ||
#define IPTOS_DSCP_CS6 0xc0 | ||
#define IPTOS_DSCP_CS7 0xe0 | ||
#endif | ||
|
||
#ifndef IPTOS_DSCP_EF | ||
#define IPTOS_DSCP_EF 0xb8 | ||
#endif | ||
|
||
#ifndef IPTOS_DSCP_LE | ||
#define IPTOS_DSCP_LE 0x04 | ||
#endif | ||
|
||
const std::map<const std::string, int> DSCPvalues { | ||
{ "none", INT_MAX }, // CS0 has value 0 but we want 'none' to mean OS default | ||
{ "", INT_MAX }, // an alias to 'none' | ||
{ "af11", IPTOS_DSCP_AF11 }, | ||
{ "af12", IPTOS_DSCP_AF12 }, | ||
{ "af13", IPTOS_DSCP_AF13 }, | ||
{ "af21", IPTOS_DSCP_AF21 }, | ||
{ "af22", IPTOS_DSCP_AF22 }, | ||
{ "af23", IPTOS_DSCP_AF23 }, | ||
{ "af31", IPTOS_DSCP_AF31 }, | ||
{ "af32", IPTOS_DSCP_AF32 }, | ||
{ "af33", IPTOS_DSCP_AF33 }, | ||
{ "af41", IPTOS_DSCP_AF41 }, | ||
{ "af42", IPTOS_DSCP_AF42 }, | ||
{ "af43", IPTOS_DSCP_AF43 }, | ||
{ "cs0", IPTOS_DSCP_CS0 }, | ||
{ "cs1", IPTOS_DSCP_CS1 }, | ||
{ "cs2", IPTOS_DSCP_CS2 }, | ||
{ "cs3", IPTOS_DSCP_CS3 }, | ||
{ "cs4", IPTOS_DSCP_CS4 }, | ||
{ "cs5", IPTOS_DSCP_CS5 }, | ||
{ "cs6", IPTOS_DSCP_CS6 }, | ||
{ "cs7", IPTOS_DSCP_CS7 }, | ||
{ "ef", IPTOS_DSCP_EF }, | ||
{ "le", IPTOS_DSCP_LE } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This exposes an unnecessary amount of implementation info into the header.
Maybe just declare a couple of accessor functions, e.g.
std::optional<int> tr_netDscpGetValue(std::string_view name);
std::optional<std::string_view> tr_netDscpGetName(int value);
...and then move all the rest of this into net.cc
#define IPTOS_DSCP_LE 0x04 | ||
#endif | ||
|
||
const std::map<const std::string, int> DSCPvalues { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are all known at compile-time so there's no need to have a std::map or std::string which both require heap allocation. This should be a constexpr std::array<std::pair<std::string_view, int>, N>
that we could sort at compile time and then bsearch.
Though TBH this will probably only be called a handful of times per session; linear search would also be fine
#ifndef IPTOS_DSCP_CS0 | ||
#define IPTOS_DSCP_CS0 0x00 | ||
#define IPTOS_DSCP_CS1 0x20 | ||
#define IPTOS_DSCP_CS2 0x40 | ||
#define IPTOS_DSCP_CS3 0x60 | ||
#define IPTOS_DSCP_CS4 0x80 | ||
#define IPTOS_DSCP_CS5 0xa0 | ||
#define IPTOS_DSCP_CS6 0xc0 | ||
#define IPTOS_DSCP_CS7 0xe0 | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the DSCP_AF_ and DSCP_CS values are known and never going to change, maybe just make them constexpr ints e.g. static constexpr int TR_IPTOS_DSCP_CS4 = 0x80;
so that we never have to worry about header conflicts?
#include <string_view> | ||
|
||
#include "utils.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed in this header?
@@ -9,15 +9,22 @@ | |||
#endif | |||
|
|||
#include <cstddef> // size_t | |||
#include <climits> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed in this header?
for (auto it = DSCPvalues.begin(); it != DSCPvalues.end(); ++it) | ||
if (it->second == value) | ||
return it->first; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider find_if or
for (auto const& [name, val] : DSCPvalues)
{
if (val == value)
{
return name;
}
}
Hi @ckerr, thanks for the detailed review though I'm afraid I can't improve this PR much further, at least not without learning C++ the right way (you could almost say this PR was hammered together using a search engine and some rudimentary C knowledge). |
OK. Please leave it up for a bit and I'll create a followup PR |
@dgcampea do you have any thoughs on #2594 ? I've kept the same settings.json names and command-line arguments that exist in Transmission 3.0 so that existing settings won't break, but they now support the DSCP class names as well as the older ToS names, and the default for new users is a DSCP class name. If you have feedback, let's continue this in 2594 |
IP TOS was superseeded by DSCP in RFC 2474 (December 1998).
I've tested with wireshark and I can confirm that the DSCP options are applied (transmission-daemon).
It also passed
make test
.