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

Add Support for resolving DNS using search list for host-name loopkup. #19548

Closed
wants to merge 1 commit into from

Conversation

Manicqin
Copy link

@Manicqin Manicqin commented Mar 23, 2018

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), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

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
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Mar 23, 2018
@Manicqin
Copy link
Author

Manicqin commented Mar 23, 2018

Hi, How I can I write tests for the added feature.

v8::String::NewFromUtf8(env()->isolate(),
field.c_str(),
v8::NewStringType::kNormal).ToLocalChecked());
}
Copy link
Member

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;
Copy link
Member

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;
}
Copy link
Member

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

Copy link
Author

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?

Copy link
Author

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?

Copy link
Member

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.
Copy link
Contributor

@vsemozhetbyt vsemozhetbyt Mar 23, 2018

Choose a reason for hiding this comment

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

Nits:

  1. dns -> DNS.
  2. In docs, we wrap lines after 80 characters at most. Otherwise, there will be doc linting error.

Copy link
Member

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

The same)

@vsemozhetbyt vsemozhetbyt added dns Issues and PRs related to the dns subsystem. semver-minor PRs that contain new features and should be released in the next minor version. labels Mar 23, 2018
@@ -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
Copy link
Member

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

@Trott
Copy link
Member

Trott commented Mar 23, 2018

Hi, @Manicqin! Welcome and thanks for the PR!

@BridgeAR
Copy link
Member

@Manicqin would you be so kind and try to address the comments? If you need any help / advice, please let me know.

@Manicqin
Copy link
Author

Manicqin commented May 1, 2018

@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).

@bnoordhuis
Copy link
Member

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.)

@Manicqin
Copy link
Author

Hi.

I'm terribly sorry but I wont be able to address this issue.

@bnoordhuis
Copy link
Member

I'm afraid this PR has bitrotted. I'll close it out but let me know if you want to pick it up again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. dns Issues and PRs related to the dns subsystem. lib / src Issues and PRs related to general changes in the lib or src directory. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No DNS Search Domain support in C-Ares calls
6 participants