| 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); |
| 80 | |
| 81 | try { |
| 82 | this.#timer ??= Timer.repeat(() => this.#task(), 1000); |
| 83 | |
| 84 | this.#socket ??= new (this.#UDP.io)({ |
| 85 | target: this, |
| 86 | onReadable: function(count) { |
| 87 | while (count--) |
| 88 | this.target.#receive(this.read()); |
| 89 | } |
| 90 | }); |
| 91 | |
| 92 | if (request.id) { |
| 93 | const servers = this.#servers; |
| 94 | this.#socket.write(packet.build(), servers[request.state % servers.length], 53); |
| 95 | } |
| 96 | else |
| 97 | this.#socket.write(packet.build(), "224.0.0.251", 5353); |
| 98 | } |
| 99 | catch { |
| 100 | if (!this.#timer) { |
| 101 | this.#remove(request); |
| 102 | request.onError?.call(this, request.host); |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | #receive(buffer) { |
| 107 | const packet = new Parser(buffer); |
| 108 | const question = packet.question(0); |