-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46f589b
commit 05b016b
Showing
20 changed files
with
747 additions
and
1,216 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { lookup } from "node:dns/promises"; | ||
import { | ||
ALL, | ||
BADFAMILY, | ||
CANCELLED, | ||
CONNREFUSED, | ||
NODATA, | ||
NOMEM, | ||
NONAME, | ||
NOTFOUND, | ||
REFUSED, | ||
SERVFAIL, | ||
TIMEOUT, | ||
V4MAPPED, | ||
} from "node:dns"; | ||
import { ipv4ToTuple, ipv6ToTuple } from "../nodejs/sockets/socket-common.js"; | ||
|
||
const dnsLookupOptions = { | ||
verbatim: true, | ||
all: true, | ||
hints: V4MAPPED | ALL, | ||
}; | ||
|
||
export function socketResolveAddress(hostname) { | ||
return lookup(hostname, dnsLookupOptions).then( | ||
(addresses) => { | ||
return addresses.map(({ address, family }) => { | ||
[ | ||
{ | ||
tag: "ipv" + family, | ||
val: (family === 4 ? ipv4ToTuple : ipv6ToTuple)(address), | ||
}, | ||
]; | ||
}); | ||
}, | ||
(err) => { | ||
switch (err.code) { | ||
// TODO: verify these more carefully | ||
case NODATA: | ||
case BADFAMILY: | ||
case NONAME: | ||
case NOTFOUND: | ||
throw "name-unresolvable"; | ||
case TIMEOUT: | ||
case REFUSED: | ||
case CONNREFUSED: | ||
case SERVFAIL: | ||
case NOMEM: | ||
case CANCELLED: | ||
throw "temporary-resolver-failure"; | ||
default: | ||
throw "permanent-resolver-failure"; | ||
} | ||
} | ||
); | ||
} | ||
|
||
export function convertSocketError(err) { | ||
switch (err?.code) { | ||
case "EBADF": | ||
return "invalid-state"; | ||
} | ||
process._rawDebug(err); | ||
return "unknown"; | ||
} |
Oops, something went wrong.