| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -108,6 +108,8 @@ Create a new resolver. | |||
| 108 | 108 | * `options` {Object} | |
| 109 | 109 | * `timeout` {integer} Query timeout in milliseconds, or `-1` to use the | |
| 110 | 110 | default timeout. | |
| 111 | + * `tries` {integer} The number of tries the resolver will try contacting | ||
| 112 | + each name server before giving up, `4` by default. | ||
| 111 | 113 | ||
| 112 | 114 | ### `resolver.cancel()` | |
| 113 | 115 | <!-- YAML | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,6 +12,7 @@ const { | |||
| 12 | 12 | Resolver: CallbackResolver, | |
| 13 | 13 | validateHints, | |
| 14 | 14 | validateTimeout, | |
| 15 | + validateTries, | ||
| 15 | 16 | emitInvalidHostnameWarning, | |
| 16 | 17 | getDefaultVerbatim, | |
| 17 | 18 | } = require('internal/dns/utils'); | |
@@ -216,7 +217,8 @@ const resolveMap = ObjectCreate(null); | |||
| 216 | 217 | class Resolver { | |
| 217 | 218 | constructor(options = undefined) { | |
| 218 | 219 | const timeout = validateTimeout(options); | |
| 219 | - this._handle = new ChannelWrap(timeout); | ||
| 220 | + const tries = validateTries(options); | ||
| 221 | + this._handle = new ChannelWrap(timeout, tries); | ||
| 220 | 222 | } | |
| 221 | 223 | } | |
| 222 | 224 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,11 +43,18 @@ function validateTimeout(options) { | |||
| 43 | 43 | return timeout; | |
| 44 | 44 | } | |
| 45 | 45 | ||
| 46 | + function validateTries(options) { | ||
| 47 | + const { tries = 4 } = { ...options }; | ||
| 48 | + validateInt32(tries, 'options.tries', 1, 2 ** 31 - 1); | ||
| 49 | + return tries; | ||
| 50 | + } | ||
| 51 | + | ||
| 46 | 52 | // Resolver instances correspond 1:1 to c-ares channels. | |
| 47 | 53 | class Resolver { | |
| 48 | 54 | constructor(options = undefined) { | |
| 49 | 55 | const timeout = validateTimeout(options); | |
| 50 | - this._handle = new ChannelWrap(timeout); | ||
| 56 | + const tries = validateTries(options); | ||
| 57 | + this._handle = new ChannelWrap(timeout, tries); | ||
| 51 | 58 | } | |
| 52 | 59 | ||
| 53 | 60 | cancel() { | |
@@ -211,6 +218,7 @@ module.exports = { | |||
| 211 | 218 | setDefaultResolver, | |
| 212 | 219 | validateHints, | |
| 213 | 220 | validateTimeout, | |
| 221 | + validateTries, | ||
| 214 | 222 | Resolver, | |
| 215 | 223 | emitInvalidHostnameWarning, | |
| 216 | 224 | getDefaultVerbatim, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -631,9 +631,14 @@ int ParseSoaReply( | |||
| 631 | 631 | } | |
| 632 | 632 | } // anonymous namespace | |
| 633 | 633 | ||
| 634 | - ChannelWrap::ChannelWrap(Environment* env, Local<Object> object, int timeout) | ||
| 634 | + ChannelWrap::ChannelWrap( | ||
| 635 | + Environment* env, | ||
| 636 | + Local<Object> object, | ||
| 637 | + int timeout, | ||
| 638 | + int tries) | ||
| 635 | 639 | : AsyncWrap(env, object, PROVIDER_DNSCHANNEL), | |
| 636 | - timeout_(timeout) { | ||
| 640 | + timeout_(timeout), | ||
| 641 | + tries_(tries) { | ||
| 637 | 642 | MakeWeak(); | |
| 638 | 643 | ||
| 639 | 644 | Setup(); | |
@@ -647,11 +652,13 @@ void ChannelWrap::MemoryInfo(MemoryTracker* tracker) const { | |||
| 647 | 652 | ||
| 648 | 653 | void ChannelWrap::New(const FunctionCallbackInfo<Value>& args) { | |
| 649 | 654 | CHECK(args.IsConstructCall()); | |
| 650 | - CHECK_EQ(args.Length(), 1); | ||
| 655 | + CHECK_EQ(args.Length(), 2); | ||
| 651 | 656 | CHECK(args[0]->IsInt32()); | |
| 657 | + CHECK(args[1]->IsInt32()); | ||
| 652 | 658 | const int timeout = args[0].As<Int32>()->Value(); | |
| 659 | + const int tries = args[1].As<Int32>()->Value(); | ||
| 653 | 660 | Environment* env = Environment::GetCurrent(args); | |
| 654 | - new ChannelWrap(env, args.This(), timeout); | ||
| 661 | + new ChannelWrap(env, args.This(), timeout, tries); | ||
| 655 | 662 | } | |
| 656 | 663 | ||
| 657 | 664 | GetAddrInfoReqWrap::GetAddrInfoReqWrap( | |
@@ -704,6 +711,7 @@ void ChannelWrap::Setup() { | |||
| 704 | 711 | options.sock_state_cb = ares_sockstate_cb; | |
| 705 | 712 | options.sock_state_cb_data = this; | |
| 706 | 713 | options.timeout = timeout_; | |
| 714 | + options.tries = tries_; | ||
| 707 | 715 | ||
| 708 | 716 | int r; | |
| 709 | 717 | if (!library_inited_) { | |
@@ -717,7 +725,8 @@ void ChannelWrap::Setup() { | |||
| 717 | 725 | ||
| 718 | 726 | /* We do the call to ares_init_option for caller. */ | |
| 719 | 727 | const int optmask = | |
| 720 | - ARES_OPT_FLAGS | ARES_OPT_TIMEOUTMS | ARES_OPT_SOCK_STATE_CB; | ||
| 728 | + ARES_OPT_FLAGS | ARES_OPT_TIMEOUTMS | | ||
| 729 | + ARES_OPT_SOCK_STATE_CB | ARES_OPT_TRIES; | ||
| 721 | 730 | r = ares_init_options(&channel_, &options, optmask); | |
| 722 | 731 | ||
| 723 | 732 | if (r != ARES_SUCCESS) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -147,7 +147,11 @@ struct NodeAresTask final : public MemoryRetainer { | |||
| 147 | 147 | ||
| 148 | 148 | class ChannelWrap final : public AsyncWrap { | |
| 149 | 149 | public: | |
| 150 | - ChannelWrap(Environment* env, v8::Local<v8::Object> object, int timeout); | ||
| 150 | + ChannelWrap( | ||
| 151 | + Environment* env, | ||
| 152 | + v8::Local<v8::Object> object, | ||
| 153 | + int timeout, | ||
| 154 | + int tries); | ||
| 151 | 155 | ~ChannelWrap() override; | |
| 152 | 156 | ||
| 153 | 157 | static void New(const v8::FunctionCallbackInfo<v8::Value>& args); | |
@@ -181,6 +185,7 @@ class ChannelWrap final : public AsyncWrap { | |||
| 181 | 185 | bool is_servers_default_ = true; | |
| 182 | 186 | bool library_inited_ = false; | |
| 183 | 187 | int timeout_; | |
| 188 | + int tries_; | ||
| 184 | 189 | int active_query_count_ = 0; | |
| 185 | 190 | NodeAresTask::List task_list_; | |
| 186 | 191 | }; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments