@aws-sdk/util-dns 3.972.15 → 3.972.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist-cjs/index.js CHANGED
@@ -1,27 +1,266 @@
1
- 'use strict';
1
+ const { HostAddressType } = require("@aws-sdk/types");
2
+ const { promises, V4MAPPED, ALL } = require("dns");
2
3
 
3
- var HostResolver = require('./HostResolver');
4
- var NodeDnsLookupHostResolver = require('./NodeDnsLookupHostResolver');
4
+ class HostAddressEntryCollection {
5
+ data = [];
6
+ get length() {
7
+ return this.data.length;
8
+ }
9
+ cycle(collection) {
10
+ if (this.data.length === 0) {
11
+ throw new Error("Cannot cycle an empty collection");
12
+ }
13
+ const entry = this.data.shift();
14
+ (collection || this).append(entry);
15
+ return entry;
16
+ }
17
+ append(entry) {
18
+ this.data.push(entry);
19
+ }
20
+ remove(entry) {
21
+ if (this.length === 0) {
22
+ throw new Error("Cannot remove from an empty collection");
23
+ }
24
+ const index = this.data.findIndex((e) => e.address === entry.address);
25
+ const removedEntry = this.data[index];
26
+ this.data.splice(index, 1);
27
+ return removedEntry;
28
+ }
29
+ [Symbol.iterator]() {
30
+ return this.data[Symbol.iterator]();
31
+ }
32
+ }
5
33
 
34
+ class HostEntry {
35
+ aaaaRecords;
36
+ aRecords;
37
+ failedAaaaRecords;
38
+ failedARecords;
39
+ nextTimestampToUpdateMs;
40
+ constructor(nextTimestampToProcessMs) {
41
+ this.aaaaRecords = new HostAddressEntryCollection();
42
+ this.aRecords = new HostAddressEntryCollection();
43
+ this.failedAaaaRecords = new HostAddressEntryCollection();
44
+ this.failedARecords = new HostAddressEntryCollection();
45
+ this.nextTimestampToUpdateMs = nextTimestampToProcessMs;
46
+ }
47
+ updateRecords(addresses, expirationTtlMs) {
48
+ this.nextTimestampToUpdateMs = expirationTtlMs;
49
+ const addressesToAppend = [];
50
+ for (const freshAddress of addresses) {
51
+ const hostAddressEntry = this.findAddress(freshAddress);
52
+ if (hostAddressEntry !== undefined) {
53
+ hostAddressEntry.expirationTtlMs = expirationTtlMs;
54
+ continue;
55
+ }
56
+ addressesToAppend.push(freshAddress);
57
+ }
58
+ for (const addressToAppend of addressesToAppend) {
59
+ const hostAddressEntry = this.findAddress(addressToAppend);
60
+ if (hostAddressEntry !== undefined) {
61
+ continue;
62
+ }
63
+ const successRecords = this.getGoodRecords(addressToAppend);
64
+ successRecords.append(Object.assign(addressToAppend, {
65
+ expirationTtlMs,
66
+ }));
67
+ }
68
+ }
69
+ processRecords() {
70
+ this.processRecordsAddressType(this.aRecords, this.failedARecords);
71
+ this.processRecordsAddressType(this.aaaaRecords, this.failedAaaaRecords);
72
+ }
73
+ failAddressInRecords(address) {
74
+ const successRecords = this.getGoodRecords(address);
75
+ const failedRecords = this.getFailedRecords(address);
76
+ const recordsToRemove = [];
77
+ for (const hostAddressEntry of successRecords) {
78
+ if (hostAddressEntry.address === address.address) {
79
+ recordsToRemove.push(hostAddressEntry);
80
+ failedRecords.append(hostAddressEntry);
81
+ }
82
+ }
83
+ for (const recordToRemove of recordsToRemove) {
84
+ successRecords.remove(recordToRemove);
85
+ }
86
+ }
87
+ findAddress(address) {
88
+ const successRecords = this.getGoodRecords(address);
89
+ for (const hostAddressEntry of successRecords) {
90
+ if (address.address === hostAddressEntry.address) {
91
+ return hostAddressEntry;
92
+ }
93
+ }
94
+ const failedRecords = this.getFailedRecords(address);
95
+ for (const hostAddressEntry of failedRecords) {
96
+ if (address.address === hostAddressEntry.address) {
97
+ return hostAddressEntry;
98
+ }
99
+ }
100
+ return undefined;
101
+ }
102
+ processRecordsAddressType(successRecords, failedRecords) {
103
+ const successRecordsToRemove = [];
104
+ let successIndex = 0;
105
+ for (const hostAddressEntry of successRecords) {
106
+ if (successIndex === successRecords.length - 1) {
107
+ break;
108
+ }
109
+ if (Date.now() >= hostAddressEntry.expirationTtlMs) {
110
+ successRecordsToRemove.push(hostAddressEntry);
111
+ }
112
+ successIndex++;
113
+ }
114
+ for (const recordToRemove of successRecordsToRemove) {
115
+ successRecords.remove(recordToRemove);
116
+ }
117
+ const failedRecordsToRemove = [];
118
+ let failedIndex = 0;
119
+ for (const hostAddressEntry of failedRecords) {
120
+ if (failedIndex === failedRecords.length - 1) {
121
+ break;
122
+ }
123
+ if (Date.now() >= hostAddressEntry.expirationTtlMs) {
124
+ failedRecordsToRemove.push(hostAddressEntry);
125
+ }
126
+ failedIndex++;
127
+ }
128
+ for (const recordToRemove of failedRecordsToRemove) {
129
+ failedRecords.remove(recordToRemove);
130
+ }
131
+ if (successRecords.length === 0) {
132
+ let hostAddressEntryToPromote = undefined;
133
+ for (const hostAddressEntry of failedRecords) {
134
+ if (Date.now() >= hostAddressEntry.expirationTtlMs) {
135
+ continue;
136
+ }
137
+ hostAddressEntryToPromote = hostAddressEntry;
138
+ break;
139
+ }
140
+ if (hostAddressEntryToPromote !== undefined) {
141
+ failedRecords.remove(hostAddressEntryToPromote);
142
+ successRecords.append(hostAddressEntryToPromote);
143
+ }
144
+ }
145
+ }
146
+ getGoodRecords(address) {
147
+ return address.addressType === HostAddressType.AAAA ? this.aaaaRecords : this.aRecords;
148
+ }
149
+ getFailedRecords(address) {
150
+ return address.addressType === HostAddressType.AAAA ? this.failedAaaaRecords : this.failedARecords;
151
+ }
152
+ }
6
153
 
154
+ class HostEntryTable {
155
+ map;
156
+ constructor() {
157
+ this.map = new Map();
158
+ }
159
+ set(args, addresses, nextTimestampToProcessMs) {
160
+ const hostEntry = new HostEntry(nextTimestampToProcessMs);
161
+ hostEntry.updateRecords(addresses, nextTimestampToProcessMs);
162
+ this.map.set(args.hostName, hostEntry);
163
+ }
164
+ get(hostName) {
165
+ return this.map.get(hostName);
166
+ }
167
+ delete(hostName) {
168
+ this.map.delete(hostName);
169
+ }
170
+ clear() {
171
+ this.map.clear();
172
+ }
173
+ get size() {
174
+ return this.map.size;
175
+ }
176
+ }
7
177
 
8
- Object.prototype.hasOwnProperty.call(HostResolver, '__proto__') &&
9
- !Object.prototype.hasOwnProperty.call(exports, '__proto__') &&
10
- Object.defineProperty(exports, '__proto__', {
11
- enumerable: true,
12
- value: HostResolver['__proto__']
13
- });
178
+ const NODE_DNS_FAMILY_TO_HOST_ADDRESS_TYPE = {
179
+ 4: HostAddressType.A,
180
+ 6: HostAddressType.AAAA,
181
+ };
182
+ const DNS_LOOKUP_OPTIONS = {
183
+ all: true,
184
+ hints: V4MAPPED | ALL,
185
+ verbatim: true,
186
+ };
187
+ class NodeDnsLookupHostResolver {
188
+ static DEFAULT_TTL_MS = 30_000;
189
+ static createDefaultCacheProvider = () => new HostEntryTable();
190
+ static DEFAULT_NODE_DNS_LOOKUP = promises.lookup;
191
+ ttlMs;
192
+ cache;
193
+ nodeDnsLookup;
194
+ constructor({ ttlMs = NodeDnsLookupHostResolver.DEFAULT_TTL_MS, cache = NodeDnsLookupHostResolver.createDefaultCacheProvider(), nodeDnsLookup = NodeDnsLookupHostResolver.DEFAULT_NODE_DNS_LOOKUP, } = {}) {
195
+ this.ttlMs = ttlMs;
196
+ this.cache = cache;
197
+ this.nodeDnsLookup = nodeDnsLookup;
198
+ }
199
+ async resolveAddress(args) {
200
+ const possibleHostEntry = this.cache.get(args.hostName);
201
+ const newNextTimestampToUpdateMs = Date.now() + this.ttlMs;
202
+ if (possibleHostEntry === undefined) {
203
+ const addresses = await this.nodeDnsLookupResolveAddress(args);
204
+ this.cache.set(args, addresses, newNextTimestampToUpdateMs);
205
+ }
206
+ const hostEntry = this.cache.get(args.hostName);
207
+ if (possibleHostEntry !== undefined && Date.now() >= hostEntry.nextTimestampToUpdateMs) {
208
+ try {
209
+ const addresses = await this.nodeDnsLookupResolveAddress(args);
210
+ hostEntry.updateRecords(addresses, newNextTimestampToUpdateMs);
211
+ }
212
+ catch (error) {
213
+ console.error(`Could not update DNS address cache for "${args.hostName}": ${error}`);
214
+ }
215
+ }
216
+ hostEntry.processRecords();
217
+ const result = [];
218
+ if (hostEntry.aRecords.length > 0) {
219
+ result.push(hostEntry.aRecords.cycle());
220
+ }
221
+ if (hostEntry.aaaaRecords.length > 0) {
222
+ result.push(hostEntry.aaaaRecords.cycle());
223
+ }
224
+ if (result.length === 0) {
225
+ throw new Error(`Could not resolve addresses for "${args.hostName}"`);
226
+ }
227
+ return result;
228
+ }
229
+ reportFailureOnAddress(addr) {
230
+ const hostEntry = this.cache.get(addr.hostName);
231
+ if (hostEntry === undefined) {
232
+ throw new Error(`Could not find cached host name "${addr.hostName}"`);
233
+ }
234
+ hostEntry.failAddressInRecords(addr);
235
+ }
236
+ purgeCache(args) {
237
+ if (args?.hostName) {
238
+ this.cache.delete(args.hostName);
239
+ }
240
+ else {
241
+ this.cache.clear();
242
+ }
243
+ }
244
+ async nodeDnsLookupResolveAddress(args) {
245
+ const addresses = [];
246
+ const ipEntries = await this.nodeDnsLookup(args.hostName, DNS_LOOKUP_OPTIONS);
247
+ for (const { address, family } of ipEntries) {
248
+ const addressType = NODE_DNS_FAMILY_TO_HOST_ADDRESS_TYPE[family];
249
+ if (addressType === undefined) {
250
+ throw new Error(`dns.lookup() Node DNS family \`${family}\` is not supported`);
251
+ }
252
+ addresses.push({
253
+ addressType,
254
+ address,
255
+ hostName: args.hostName,
256
+ service: args.service,
257
+ });
258
+ }
259
+ return addresses;
260
+ }
261
+ }
14
262
 
15
- Object.keys(HostResolver).forEach(function (k) {
16
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = HostResolver[k];
17
- });
18
- Object.prototype.hasOwnProperty.call(NodeDnsLookupHostResolver, '__proto__') &&
19
- !Object.prototype.hasOwnProperty.call(exports, '__proto__') &&
20
- Object.defineProperty(exports, '__proto__', {
21
- enumerable: true,
22
- value: NodeDnsLookupHostResolver['__proto__']
23
- });
263
+ const HostResolver = NodeDnsLookupHostResolver;
24
264
 
25
- Object.keys(NodeDnsLookupHostResolver).forEach(function (k) {
26
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = NodeDnsLookupHostResolver[k];
27
- });
265
+ exports.HostResolver = HostResolver;
266
+ exports.NodeDnsLookupHostResolver = NodeDnsLookupHostResolver;
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@aws-sdk/util-dns",
3
- "version": "3.972.15",
3
+ "version": "3.972.17",
4
4
  "description": "Implementations of DNS host resolvers.",
5
5
  "main": "./dist-cjs/index.js",
6
6
  "module": "./dist-es/index.js",
7
7
  "scripts": {
8
8
  "build": "concurrently 'yarn:build:types' 'yarn:build:es' && yarn build:cjs",
9
9
  "build:cjs": "node ../../scripts/compilation/inline",
10
- "build:es": "tsc -p tsconfig.es.json",
10
+ "build:es": "premove dist-es && tsc -p tsconfig.es.json",
11
11
  "build:include:deps": "yarn g:turbo run build -F=\"$npm_package_name\"",
12
- "build:types": "tsc -p tsconfig.types.json",
12
+ "build:types": "premove dist-types && tsc -p tsconfig.types.json",
13
13
  "build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
14
- "clean": "premove dist-cjs dist-es dist-types tsconfig.cjs.tsbuildinfo tsconfig.es.tsbuildinfo tsconfig.types.tsbuildinfo",
14
+ "clean": "premove dist-cjs dist-es dist-types",
15
15
  "test": "yarn g:vitest run && yarn test:browser",
16
16
  "test:watch": "yarn g:vitest watch",
17
17
  "test:browser": "yarn g:vitest run -c vitest.config.browser.mts",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "license": "Apache-2.0",
29
29
  "dependencies": {
30
- "@aws-sdk/types": "^3.973.12",
30
+ "@aws-sdk/types": "^3.973.14",
31
31
  "tslib": "^2.6.2"
32
32
  },
33
33
  "devDependencies": {
@@ -66,9 +66,6 @@
66
66
  "react-native": {
67
67
  "./dist-es/index": "./dist-es/index.browser",
68
68
  "./dist-es/HostResolver": "./dist-es/HostResolver.browser",
69
- "./dist-es/NodeDnsLookupHostResolver": false,
70
- "./dist-cjs/index": "./dist-cjs/index.browser",
71
- "./dist-cjs/HostResolver": "./dist-cjs/HostResolver.browser",
72
- "./dist-cjs/NodeDnsLookupHostResolver": false
69
+ "./dist-es/NodeDnsLookupHostResolver": false
73
70
  }
74
71
  }
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HostResolver = void 0;
4
- class HostResolver {
5
- async resolveAddress(args) {
6
- return [];
7
- }
8
- reportFailureOnAddress(addr) { }
9
- purgeCache(args) { }
10
- }
11
- exports.HostResolver = HostResolver;
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HostResolver = void 0;
4
- const NodeDnsLookupHostResolver_1 = require("./NodeDnsLookupHostResolver");
5
- exports.HostResolver = NodeDnsLookupHostResolver_1.NodeDnsLookupHostResolver;
@@ -1,91 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NodeDnsLookupHostResolver = void 0;
4
- const types_1 = require("@aws-sdk/types");
5
- const dns_1 = require("dns");
6
- const HostEntryTable_1 = require("./util/HostEntryTable");
7
- const NODE_DNS_FAMILY_TO_HOST_ADDRESS_TYPE = {
8
- 4: types_1.HostAddressType.A,
9
- 6: types_1.HostAddressType.AAAA,
10
- };
11
- const DNS_LOOKUP_OPTIONS = {
12
- all: true,
13
- hints: dns_1.V4MAPPED | dns_1.ALL,
14
- verbatim: true,
15
- };
16
- class NodeDnsLookupHostResolver {
17
- static DEFAULT_TTL_MS = 30_000;
18
- static createDefaultCacheProvider = () => new HostEntryTable_1.HostEntryTable();
19
- static DEFAULT_NODE_DNS_LOOKUP = dns_1.promises.lookup;
20
- ttlMs;
21
- cache;
22
- nodeDnsLookup;
23
- constructor({ ttlMs = NodeDnsLookupHostResolver.DEFAULT_TTL_MS, cache = NodeDnsLookupHostResolver.createDefaultCacheProvider(), nodeDnsLookup = NodeDnsLookupHostResolver.DEFAULT_NODE_DNS_LOOKUP, } = {}) {
24
- this.ttlMs = ttlMs;
25
- this.cache = cache;
26
- this.nodeDnsLookup = nodeDnsLookup;
27
- }
28
- async resolveAddress(args) {
29
- const possibleHostEntry = this.cache.get(args.hostName);
30
- const newNextTimestampToUpdateMs = Date.now() + this.ttlMs;
31
- if (possibleHostEntry === undefined) {
32
- const addresses = await this.nodeDnsLookupResolveAddress(args);
33
- this.cache.set(args, addresses, newNextTimestampToUpdateMs);
34
- }
35
- const hostEntry = this.cache.get(args.hostName);
36
- if (possibleHostEntry !== undefined && Date.now() >= hostEntry.nextTimestampToUpdateMs) {
37
- try {
38
- const addresses = await this.nodeDnsLookupResolveAddress(args);
39
- hostEntry.updateRecords(addresses, newNextTimestampToUpdateMs);
40
- }
41
- catch (error) {
42
- console.error(`Could not update DNS address cache for "${args.hostName}": ${error}`);
43
- }
44
- }
45
- hostEntry.processRecords();
46
- const result = [];
47
- if (hostEntry.aRecords.length > 0) {
48
- result.push(hostEntry.aRecords.cycle());
49
- }
50
- if (hostEntry.aaaaRecords.length > 0) {
51
- result.push(hostEntry.aaaaRecords.cycle());
52
- }
53
- if (result.length === 0) {
54
- throw new Error(`Could not resolve addresses for "${args.hostName}"`);
55
- }
56
- return result;
57
- }
58
- reportFailureOnAddress(addr) {
59
- const hostEntry = this.cache.get(addr.hostName);
60
- if (hostEntry === undefined) {
61
- throw new Error(`Could not find cached host name "${addr.hostName}"`);
62
- }
63
- hostEntry.failAddressInRecords(addr);
64
- }
65
- purgeCache(args) {
66
- if (args?.hostName) {
67
- this.cache.delete(args.hostName);
68
- }
69
- else {
70
- this.cache.clear();
71
- }
72
- }
73
- async nodeDnsLookupResolveAddress(args) {
74
- const addresses = [];
75
- const ipEntries = await this.nodeDnsLookup(args.hostName, DNS_LOOKUP_OPTIONS);
76
- for (const { address, family } of ipEntries) {
77
- const addressType = NODE_DNS_FAMILY_TO_HOST_ADDRESS_TYPE[family];
78
- if (addressType === undefined) {
79
- throw new Error(`dns.lookup() Node DNS family \`${family}\` is not supported`);
80
- }
81
- addresses.push({
82
- addressType,
83
- address,
84
- hostName: args.hostName,
85
- service: args.service,
86
- });
87
- }
88
- return addresses;
89
- }
90
- }
91
- exports.NodeDnsLookupHostResolver = NodeDnsLookupHostResolver;
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NodeDnsResolveHostResolver = void 0;
4
- const types_1 = require("@aws-sdk/types");
5
- const dns_1 = require("dns");
6
- class NodeDnsResolveHostResolver {
7
- async resolveAddress(args) {
8
- const addresses = [];
9
- const ipV4Addresses = await dns_1.promises.resolve4(args.hostName);
10
- for (const address of ipV4Addresses) {
11
- addresses.push({
12
- addressType: types_1.HostAddressType.A,
13
- address,
14
- hostName: args.hostName,
15
- service: args.service,
16
- });
17
- }
18
- const ipV6Addresses = await dns_1.promises.resolve6(args.hostName);
19
- for (const address of ipV6Addresses) {
20
- addresses.push({
21
- addressType: types_1.HostAddressType.AAAA,
22
- address,
23
- hostName: args.hostName,
24
- service: args.service,
25
- });
26
- }
27
- return addresses;
28
- }
29
- reportFailureOnAddress(addr) {
30
- throw new Error("reportFailureOnAddress(addr) is not implemented");
31
- }
32
- purgeCache(args) {
33
- throw new Error("purgeCache(args?) is not implemented");
34
- }
35
- }
36
- exports.NodeDnsResolveHostResolver = NodeDnsResolveHostResolver;
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./HostResolver"), exports);
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HostAddressEntryCollection = void 0;
4
- class HostAddressEntryCollection {
5
- data = [];
6
- get length() {
7
- return this.data.length;
8
- }
9
- cycle(collection) {
10
- if (this.data.length === 0) {
11
- throw new Error("Cannot cycle an empty collection");
12
- }
13
- const entry = this.data.shift();
14
- (collection || this).append(entry);
15
- return entry;
16
- }
17
- append(entry) {
18
- this.data.push(entry);
19
- }
20
- remove(entry) {
21
- if (this.length === 0) {
22
- throw new Error("Cannot remove from an empty collection");
23
- }
24
- const index = this.data.findIndex((e) => e.address === entry.address);
25
- const removedEntry = this.data[index];
26
- this.data.splice(index, 1);
27
- return removedEntry;
28
- }
29
- [Symbol.iterator]() {
30
- return this.data[Symbol.iterator]();
31
- }
32
- }
33
- exports.HostAddressEntryCollection = HostAddressEntryCollection;
@@ -1,125 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HostEntry = void 0;
4
- const types_1 = require("@aws-sdk/types");
5
- const HostAddressEntryCollection_1 = require("./HostAddressEntryCollection");
6
- class HostEntry {
7
- aaaaRecords;
8
- aRecords;
9
- failedAaaaRecords;
10
- failedARecords;
11
- nextTimestampToUpdateMs;
12
- constructor(nextTimestampToProcessMs) {
13
- this.aaaaRecords = new HostAddressEntryCollection_1.HostAddressEntryCollection();
14
- this.aRecords = new HostAddressEntryCollection_1.HostAddressEntryCollection();
15
- this.failedAaaaRecords = new HostAddressEntryCollection_1.HostAddressEntryCollection();
16
- this.failedARecords = new HostAddressEntryCollection_1.HostAddressEntryCollection();
17
- this.nextTimestampToUpdateMs = nextTimestampToProcessMs;
18
- }
19
- updateRecords(addresses, expirationTtlMs) {
20
- this.nextTimestampToUpdateMs = expirationTtlMs;
21
- const addressesToAppend = [];
22
- for (const freshAddress of addresses) {
23
- const hostAddressEntry = this.findAddress(freshAddress);
24
- if (hostAddressEntry !== undefined) {
25
- hostAddressEntry.expirationTtlMs = expirationTtlMs;
26
- continue;
27
- }
28
- addressesToAppend.push(freshAddress);
29
- }
30
- for (const addressToAppend of addressesToAppend) {
31
- const hostAddressEntry = this.findAddress(addressToAppend);
32
- if (hostAddressEntry !== undefined) {
33
- continue;
34
- }
35
- const successRecords = this.getGoodRecords(addressToAppend);
36
- successRecords.append(Object.assign(addressToAppend, {
37
- expirationTtlMs,
38
- }));
39
- }
40
- }
41
- processRecords() {
42
- this.processRecordsAddressType(this.aRecords, this.failedARecords);
43
- this.processRecordsAddressType(this.aaaaRecords, this.failedAaaaRecords);
44
- }
45
- failAddressInRecords(address) {
46
- const successRecords = this.getGoodRecords(address);
47
- const failedRecords = this.getFailedRecords(address);
48
- const recordsToRemove = [];
49
- for (const hostAddressEntry of successRecords) {
50
- if (hostAddressEntry.address === address.address) {
51
- recordsToRemove.push(hostAddressEntry);
52
- failedRecords.append(hostAddressEntry);
53
- }
54
- }
55
- for (const recordToRemove of recordsToRemove) {
56
- successRecords.remove(recordToRemove);
57
- }
58
- }
59
- findAddress(address) {
60
- const successRecords = this.getGoodRecords(address);
61
- for (const hostAddressEntry of successRecords) {
62
- if (address.address === hostAddressEntry.address) {
63
- return hostAddressEntry;
64
- }
65
- }
66
- const failedRecords = this.getFailedRecords(address);
67
- for (const hostAddressEntry of failedRecords) {
68
- if (address.address === hostAddressEntry.address) {
69
- return hostAddressEntry;
70
- }
71
- }
72
- return undefined;
73
- }
74
- processRecordsAddressType(successRecords, failedRecords) {
75
- const successRecordsToRemove = [];
76
- let successIndex = 0;
77
- for (const hostAddressEntry of successRecords) {
78
- if (successIndex === successRecords.length - 1) {
79
- break;
80
- }
81
- if (Date.now() >= hostAddressEntry.expirationTtlMs) {
82
- successRecordsToRemove.push(hostAddressEntry);
83
- }
84
- successIndex++;
85
- }
86
- for (const recordToRemove of successRecordsToRemove) {
87
- successRecords.remove(recordToRemove);
88
- }
89
- const failedRecordsToRemove = [];
90
- let failedIndex = 0;
91
- for (const hostAddressEntry of failedRecords) {
92
- if (failedIndex === failedRecords.length - 1) {
93
- break;
94
- }
95
- if (Date.now() >= hostAddressEntry.expirationTtlMs) {
96
- failedRecordsToRemove.push(hostAddressEntry);
97
- }
98
- failedIndex++;
99
- }
100
- for (const recordToRemove of failedRecordsToRemove) {
101
- failedRecords.remove(recordToRemove);
102
- }
103
- if (successRecords.length === 0) {
104
- let hostAddressEntryToPromote = undefined;
105
- for (const hostAddressEntry of failedRecords) {
106
- if (Date.now() >= hostAddressEntry.expirationTtlMs) {
107
- continue;
108
- }
109
- hostAddressEntryToPromote = hostAddressEntry;
110
- break;
111
- }
112
- if (hostAddressEntryToPromote !== undefined) {
113
- failedRecords.remove(hostAddressEntryToPromote);
114
- successRecords.append(hostAddressEntryToPromote);
115
- }
116
- }
117
- }
118
- getGoodRecords(address) {
119
- return address.addressType === types_1.HostAddressType.AAAA ? this.aaaaRecords : this.aRecords;
120
- }
121
- getFailedRecords(address) {
122
- return address.addressType === types_1.HostAddressType.AAAA ? this.failedAaaaRecords : this.failedARecords;
123
- }
124
- }
125
- exports.HostEntry = HostEntry;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HostEntryTable = void 0;
4
- const HostEntry_1 = require("./HostEntry");
5
- class HostEntryTable {
6
- map;
7
- constructor() {
8
- this.map = new Map();
9
- }
10
- set(args, addresses, nextTimestampToProcessMs) {
11
- const hostEntry = new HostEntry_1.HostEntry(nextTimestampToProcessMs);
12
- hostEntry.updateRecords(addresses, nextTimestampToProcessMs);
13
- this.map.set(args.hostName, hostEntry);
14
- }
15
- get(hostName) {
16
- return this.map.get(hostName);
17
- }
18
- delete(hostName) {
19
- this.map.delete(hostName);
20
- }
21
- clear() {
22
- this.map.clear();
23
- }
24
- get size() {
25
- return this.map.size;
26
- }
27
- }
28
- exports.HostEntryTable = HostEntryTable;