-
Notifications
You must be signed in to change notification settings - Fork 225
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
Client: Add SRV-based virtual hosting support #2930
Conversation
|
||
bool NetworkUtil::ParseNetworkAddressWithSrvDiscovery ( QString strAddress, CHostAddress& HostAddress, bool bEnableIPv6 ) | ||
{ | ||
// Try SRV-based discovery 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.
Trying SRV first is the saner behavior. It comes at the cost that everyone has to do the SRV lookup and wait for the (possibly empty) reply.
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.
Agreed. The DNS server should fail fairly fast if the entry isn't there. At worst it should double the lookup time.
This moves the host elaborate and reusable host name lookup logic to its own ParseNetworkAddressName method. Co-authored-by: Peter L Jones <peter@drealm.info>
b5ceddd
to
be70a6d
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.
Could you please #ifndef the code? I think some "raw jamulus" people might not want this feature (although it's small)
be70a6d
to
4ccd0b4
Compare
Done now ( |
As soon as the DNS records are propagated (and I didn't make a mistake in the format), I can test this. |
Ok. Tested ok. |
// This is not nice and blocks the UI, but is similar to what | ||
// the regular resolve function does as well. | ||
QTime dieTime = QTime::currentTime().addMSecs ( DNS_SRV_RESOLVE_TIMEOUT_MS ); | ||
while ( QTime::currentTime() < dieTime && !dns->isFinished() ) |
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 a fan of busy waiting (even if it's limited). Isn't there any blocking function or something like a signal?
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.
You're asking for a Qt equivalent of AA/AAAA lookup for SRV names? (I'd guess all the Qt AA/AAAA lookup does is something very like this.)
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.
Isn't there any blocking function
The existing code path uses QHostInfo::fromName, which is a blocking function. I haven't found any equivalent for SRV lookups.
or something like a signal?
The QDnsLookup
, which I've used here, is supposed to be used via signals. However, this requires -- as far as I can see -- an inversion of the control flow as the existing logic relies on blocking. Even when that refactoring is done, new questions come up: How should the UI behave? Currently it blocks. If it continues to stay responsive during lookup, we would need some other kind of indicator, so that's kind of a rabbit hole. Not saying that it shouldn't be done, but rather that it's a larger refactoring which I didn't want to do as part of this PR.
In short: That's the best and least intrusive way I've found. If someone finds a better way, I'm certainly open to it. :)
src/util.cpp
Outdated
{ | ||
// RFC2782 says that "." indicates that the service is not available. | ||
// (Qt strips the trailing dot, which is why we check for empty string | ||
// as well) |
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.
Does this mean we might have two dots? (When and why) is this valid? Why don't we check just for the empty string?
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.
The code basically covers both what the RFC states plus what I've practically observed during testing on Linux. As I haven't tested all other platforms or different DNS implementations, I'd go with this duplicate check -- it's about the failure path anyway. It might be sufficient to check for the empty string, but it would be some effort to prove, I guess?
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.
At least add a comment here that the dot check might not be needed.
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.
Done
When connecting to host names without port (e.g. example.org), the client will now perform an SRV lookup to _jamulus._udp.example.org. If this lookup returns exactly one result, the result is used to select the actual target address/port. If the lookup does not return a usable result, the regular connect logic kicks in (A lookup, default port). Related: https://github.com/orgs/jamulussoftware/discussions/1772
4ccd0b4
to
ed18ad6
Compare
I still don't feel comfortable with the dot/empty string workaround. The Qt docs don't seem to give much insight. Why does the dot get removed? |
Qt uses the OS' libresolv on *nix (usually glibc). glibc has logic to remove a leading dot, which also covers names consisting only of a dot. Finding that this is (potentially) platform-specific behavior confirms that it is a good idea to handle both cases, IMO. |
Hmm ok. Approving and merging then. |
Dropped needs documentation as the next-release page is up to date: https://github.com/jamulussoftware/jamuluswebsite/blob/next-release/wiki/en/Unregistered-Servers.md#dns-srv-record-support |
Short description of changes
Internal: Refactor NetworkUtil::ParseNetworkAddress
This moves the host elaborate and reusable host name lookup logic to its own ParseNetworkAddressName method.
Client: Add SRV-based virtual hosting support
When connecting to host names without port (e.g. example.org), the client will now perform an SRV lookup to _jamulus._udp.example.org. If this lookup returns exactly one result, the result is used to select the actual target address/port.
If the lookup does not return a usable result, the regular connect logic kicks in (A lookup, default port).
CHANGELOG: Client: Add SRV-based virtual hosting support
Context: Fixes an issue?
Related: https://github.com/orgs/jamulussoftware/discussions/1772
Does this change need documentation? What needs to be documented and how?
Website, Server administration
Status of this Pull Request
Ready for testing/discussion.
What is missing until this pull request can be merged?
Ready for testing/discussion.
Checklist