-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Rework the listening IP/interface selection code #11592
Rework the listening IP/interface selection code #11592
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.
Some quick reviews.. no need to wait for my review completion if you want to force push/update.
eef4043
to
d6b4c3f
Compare
Guys, I think I addressed all your comments so far. Take a look at the new commit. |
This comment has been minimized.
This comment has been minimized.
src/base/utils/net.cpp
Outdated
// as scope id. Furthermore, QHostAddress doesn't have any convenient method to | ||
// affect this, so we jump through hoops here. | ||
if (addr.protocol() != QAbstractSocket::IPv6Protocol) | ||
return addr; |
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.
canonicalIPv6Addr shouldn't return non-IPv6 address!
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.
So return a null QHostAddress?
d6b4c3f
to
91efdf4
Compare
In this push, I addressed almost all the comments, apart 2 from glassez. |
91efdf4
to
7d3a76c
Compare
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.
No more comments from me.
Also I noticed this patch: arvidn/libtorrent#4166
If that patch could simplify our work here, it might be worth to add some #if
conditionals to the relevant code.
src/base/utils/net.cpp
Outdated
// as scope id. Furthermore, QHostAddress doesn't have any convenient method to | ||
// affect this, so we jump through hoops here. | ||
if (addr.protocol() != QAbstractSocket::IPv6Protocol) | ||
return {}; |
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 applying this function to IPv4 address isn't valid "use case" you should prevent it in any way (at least add an appropriate assertion). Otherwise it may allow logically incorrect code.
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.
I am confused. How do I prevent it in any way?
And won't the assertion work only in debug?
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.
How do I prevent it in any way?
You can throw RuntimeError...
Or you can modify it to be valid for any IP (and rename it to canonicalIPAddr
).
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.
Or even it can return IPv6 representstion of IPv4... unless I am wrong it is possible.
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.
QHostAddress::toIPv6Address() seems to do the job. So it becomes:
if (addr.protocol() != QAbstractSocket::IPv6Protocol)
return {addr.toIPv6Address()};
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.
And also apply all remaining modifications.
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.
Or it already in "canonical" form?
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.
Or it already in "canonical" form?
It can't be, because at this point it is IPv4.
If you mean below, there is no way to know beforehand. So we convert unconditionally.
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.
I would implement another variant instead. I mean canonicalIPAddr
that returns IP of the same type as its argument.
BTW, we can use it unconditionally since it always returns valid result.
I think I addressed everything and I did some furhter refactor. Due to that I implemented it as a separate temporary commit. It will be easier for you to see what I changed. |
The missing part is the webui code itself. @Chocobo1 will you be able to plug in the correct js/html changes? |
Currently I'm low on free time to write code unfortunately. |
Isn't empty string treated as "any IP" by app core? Then it should be used here as well. |
96cb7cc
to
f375eef
Compare
Now the webui receives an empty string to mean all addresses, I also changed how the GUI populates the comboboxes to match the logic of the WebUI comboboxes. And I probably changed other things here and there. So forgive me but please take another look at the whole thing. |
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.
only some minor things left, overall it's looking good.
On another note, I just noticed that we do a lot of // ifaceAddr is of type QHostAddres
functionThatTakesQString(ifaceAddr.isNull() ? QString {} : ifaceAddr.toString()); But I realize that we can collapse it to: functionThatTakesQString(ifaceAddr.toString()); I'll make the changes later (only code affected by me). |
f375eef
to
3c4067c
Compare
3c4067c
to
8200ef6
Compare
Closes #11632 |
@glassez do you approve? |
I would still change canonicalIPv6Addr to suggested canonicalIPAddr form. But you can ignore this opinion. |
IMO, I don't want to give the impression that the function can be used with IPv4. (Yes, it will work but it shouldn't be used for IPv4). |
You cannot forbid it since function accepts generic host address (function name isn't enough, there can be use case when parameter is bypassed unchecked). You either can break it at runtime (throw an exception) or change it to be valid (have a meaning) for any kind of host address. |
No, I meant that it is discouraged through the function name. Thank you all for the reviewing. |
This introduced the tracker not working bug in v 4.2.1 |
@sledgehammer999 @glassez @Chocobo1 Not sure if this warrants any changes/additions to the code introduced in this PR, but I thought I should give the heads-up. |
Closes #11561
It started as a simple fix for #11561. But as I dug deeper I fixed more and more things. And it became a full blown refactor.
With this PR:
All IPv4 Addresses
andAll IPv6 Addresses
.0.0.0.0
.PS: I am not very good with choosing variable/function names.