(options)
| 47 | this.#socket = this.#servers = this.#timer = this.#UDP = undefined; |
| 48 | } |
| 49 | resolve(options) { |
| 50 | let {onResolved, onError, host} = options; |
| 51 | if (!host || (!onResolved && !onError) || !this.#UDP) |
| 52 | throw new Error; |
| 53 | |
| 54 | host = host.toString(); |
| 55 | if ("localhost" === host) |
| 56 | host = "127.0.0.1"; |
| 57 | |
| 58 | const parts = host.split("."); |
| 59 | let isAddress = 4 === parts.length; |
| 60 | if (isAddress) { |
| 61 | for (let i = 0; i < 4; i++) { |
| 62 | if (parseInt(parts[i]) != parts[i]) |
| 63 | isAddress = false; |
| 64 | } |
| 65 | } |
| 66 | const request = { |
| 67 | state: 0, |
| 68 | id: host.endsWith(".local") ? 0 : ((Math.random() * 65535) | 1), //@@ collision |
| 69 | host, |
| 70 | onResolved, |
| 71 | onError, |
| 72 | isAddress |
| 73 | } |
| 74 | this.#requests.push(request); |
| 75 | this.#timer ??= Timer.set(() => this.#task(), 0, 1000); |
| 76 | } |
| 77 | #send(request) { |
| 78 | const packet = new Serializer({query: true, recursionDesired: true, opcode: DNS.OPCODE.QUERY, id: request.id}); |
| 79 | packet.add(DNS.SECTION.QUESTION, request.host, DNS.RR.A, DNS.CLASS.IN); |
no test coverage detected