-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
Add Support for resolving DNS using search list for host-name loopkup. #19548
Conversation
lib: dns.js - passing the search field form the options object to QueryReqWrap object. src: base_object.h - added GetField function to read fields from the persistent object (persistent QueryReqWrap object). cares_wrap.cc - added a AresSearch function. - QueryAWrap (resolve4) and QueryAaaaWrap (resolve6) utilizes the AresSearch when options.search is true. doc/api: added search option to the resolve4 and resolve6 documentation Fixes: nodejs#17850
Hi, How I can I write tests for the added feature. |
v8::String::NewFromUtf8(env()->isolate(), | ||
field.c_str(), | ||
v8::NewStringType::kNormal).ToLocalChecked()); | ||
} |
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.
Can you drop this method? There is no reason for it to live on BaseObject.
@@ -1360,7 +1368,20 @@ class QueryAWrap: public QueryWrap { | |||
} | |||
|
|||
int Send(const char* name) override { | |||
AresQuery(name, ns_c_in, ns_t_a); | |||
auto prop_value = GetField("search"); | |||
bool bSearch = false; |
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.
Style: no hungarian, just (e.g.) search
.
} else { | ||
AresQuery(name, ns_c_in, ns_t_a); | ||
} | ||
|
||
return 0; | ||
} |
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.
Rather than looking up properties this is arguably better handled by making QueryWrap
a template that takes a function pointer:
template <void (*F)(const char*, int, int)>
class BaseWrap {
// ...
void AresQuery(const char* name, int dnsclass, int type) {
channel_->EnsureServers();
F(channel_->cares_channel(), name, dnsclass, type, Callback,
static_cast<void*>(this));
}
// ...
};
using QueryWrap = BaseWrap<ares_query>;
using SearchWrap = BaseWrap<ares_search>;
And then do the same to QueryAWrap
and QueryAaaaWrap
:
template <typename BaseT>
class BaseAWrap: public BaseT {
// ... - no changes needed to body
};
using QueryAWrap = BaseAWrap<QueryWrap>;
using SearchAWrap = BaseAWrap<SearchWrap>;
// Repeat for QueryAaaaWrap
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 problem I'll make the changes.
A couple of Qs.
-
What is the guideline when handling code on both C++ and JS, should I try to make most of the changes on the JS side?
-
Where will I dispatch the correct object according to the search option?
If it's in the lib side (Javascript) then I'll need to direct the resolve4 and resolve6 mapping in the resolveMap (dns.js:240) to a new js function that will call the correct object, Is that correct?
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 can I Test the feature?
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.
Re: resolveMap, that's correct.
Re: testing: I don't know. It depends too much on the configuration of the system, I think.
@@ -285,6 +285,9 @@ changes: | |||
When `true`, the callback receives an array of | |||
`{ address: '1.2.3.4', ttl: 60 }` objects rather than an array of strings, | |||
with the TTL expressed in seconds. | |||
- `search` {boolean} Resolve the DNS using the local domain name or the search | |||
list for host-name lookup. | |||
When `true`, the resolve will use the search list which can create extra dns queries. |
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.
Nits:
dns
->DNS
.- In docs, we wrap lines after 80 characters at most. Otherwise, there will be doc linting error.
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 resolve will use
-> the resolver will use
? Or the resolve will use
-> the hostname will be resolved with
@@ -310,6 +313,9 @@ changes: | |||
When `true`, the callback receives an array of | |||
`{ address: '0:1:2:3:4:5:6:7', ttl: 60 }` objects rather than an array of | |||
strings, with the TTL expressed in seconds. | |||
- `search` {boolean} Resolve the DNS using the local domain name or the search | |||
list for host-name lookup. | |||
When `true`, the resolve will use the search list which can create extra dns queries. |
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 same)
@@ -285,6 +285,9 @@ changes: | |||
When `true`, the callback receives an array of | |||
`{ address: '1.2.3.4', ttl: 60 }` objects rather than an array of strings, | |||
with the TTL expressed in seconds. | |||
- `search` {boolean} Resolve the DNS using the local domain name or the search |
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.
Resolve the DNS using
-> Resolve the hostname
Hi, @Manicqin! Welcome and thanks for the PR! |
@Manicqin would you be so kind and try to address the comments? If you need any help / advice, please let me know. |
@BridgeAR Hi sorry I had some work overload, I'll will try to resubmit by the weekend. I have a couple of questions but currently the main one is: will it be ok if I split the cares_wrap.cc file into multiple files, where the cares_wrap.cc will handle the module interface and add cares_query_wrap cpp and header files that will handle the classes that are being used by the module (BaseWrap, QueryWrap implementors, etc). |
I don't quite follow why that is necessary. The change I suggested isn't so big that breaking up cares_wrap.cc is needed, it's just some minor refactoring to make behavior pluggable. (And it's just one way of doing it, a template + traits is another. But I digress.) |
Hi. I'm terribly sorry but I wont be able to address this issue. |
I'm afraid this PR has bitrotted. I'll close it out but let me know if you want to pick it up again. |
lib: dns.js - passing the search field form the options object to
QueryReqWrap object.
src:
base_object.h - added GetField function to read fields from the
persistent object (persistent QueryReqWrap object).
cares_wrap.cc - added a AresSearch function.
- QueryAWrap (resolve4) and QueryAaaaWrap (resolve6)
utilizes the AresSearch when options.search is true.
doc/api: added search option to the resolve4 and resolve6 documentation
Fixes: #17850
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes