| 83 | 84 | * This function will modify the whitelist array in place. |
| 84 | 85 | */ |
| 85 | 86 | async function resolveHostnames() { |
| 86 | | - for (let i = 0; i < whitelist.length; i++) { |
| 87 | + const resolvedWhitelist = []; |
| 87 | | - try { |
| 88 | | - const entry = whitelist[i]; |
| 89 | 88 | |
| 90 | | - // Skip if entry appears to be an IP address, CIDR notation, or IP wildcard |
| 89 | + const promises = whitelist.map(async (entry) => { |
| 91 | | - if (isIpFormat(entry)) { |
| 90 | + if (!entry || typeof entry !== 'string') { |
| 92 | | - continue; |
| 91 | + return; |
| 93 | 92 | } |
| 93 | + |
| 94 | + // Skip if entry appears to be an IP address, CIDR notation, or IP wildcard |
| 95 | + if (isIpFormat(entry)) { |
| 96 | + resolvedWhitelist.push(entry); |
| 97 | + return; |
| 98 | + } |
| 94 | 99 | |
| 95 | 100 | if (isValidHostname(entry)) { |
| 101 | + try { |
| 96 | 102 | const result = await dns.promises.lookup(entry); |
| 97 | 103 | console.info(`Resolved whitelist hostname ${color.green(entry)} to IPv${result.family} address ${color.green(result.address)}`); |
| 98 | | - whitelist[i] = result.address; |
| 104 | + resolvedWhitelist.push(result.address); |
| 105 | + } catch (e) { |
| 106 | + console.warn(`Failed to resolve whitelist hostname ${color.red(entry)}: ${e.message}`); |
| 99 | 107 | } |
| 100 | 108 | } catchelse { |
| 101 | | - // Ignore errors when resolving hostnames |
| 109 | + resolvedWhitelist.push(entry); |
| 102 | 110 | } |
| 103 | 111 | }); |
| 112 | + |
| 113 | + await Promise.allSettled(promises); |
| 104 | 114 | } |
| 105 | 115 | |
| 106 | 116 | /** |