(message, value, address, port)
| 312 | } |
| 313 | |
| 314 | callback(message, value, address, port) { |
| 315 | const packet = new Parser(this.read(ArrayBuffer)) |
| 316 | let response = new Array(2); |
| 317 | |
| 318 | // dumpPacket(packet, address); |
| 319 | |
| 320 | if (packet.answers || packet.additionals) |
| 321 | this.scanPacket(packet, address); |
| 322 | |
| 323 | if (this.probing) { |
| 324 | if (this.probing < 0) return; |
| 325 | |
| 326 | for (let i = 0; i < packet.questions; i++) { |
| 327 | const question = packet.question(i); |
| 328 | if (DNS.RR.ANY !== question.qtype) |
| 329 | continue; |
| 330 | if ((this.hostNameLower !== question.qname[0].toLowerCase()) || (2 !== question.qname.length) || (LOCAL !== question.qname[1].toLowerCase())) |
| 331 | continue; |
| 332 | |
| 333 | trace(`probe tie-break with ${address}\n`); |
| 334 | for (let j = 0; j < packet.authorities; j++) { |
| 335 | const authority = packet.authority(j); |
| 336 | if (DNS.RR.A !== authority.qtype) |
| 337 | continue; |
| 338 | if ((this.hostNameLower !== authority.qname[0].toLowerCase()) || (2 !== authority.qname.length) || (LOCAL !== authority.qname[1].toLowerCase())) |
| 339 | continue; |
| 340 | const rdata = authority.rdata.split("."); |
| 341 | const ip = Net.get("IP", address).split("."); |
| 342 | trace(` compare ${rdata} with ${ip}\n`); |
| 343 | for (let k = 0; k < 4; k++) { |
| 344 | if (parseInt(ip[k]) < parseInt(rdata[k])) { |
| 345 | trace(` we lose\n`); |
| 346 | this.probing = -1000; // try again in one second |
| 347 | return; |
| 348 | } |
| 349 | } |
| 350 | trace(` we win\n`); // we are lexicographically same or later, so can ignore |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | return; |
| 355 | } |
| 356 | |
| 357 | if (packet.flags & 0x8000) |
| 358 | return; |
| 359 | |
| 360 | for (let h = 0, length = this.services.length ? this.services.length : 1; h < length; h++) { // always at least one pass, to pick up service-indepdent qtypes |
| 361 | const service = this.services[h]; |
| 362 | let mask = [0, 0]; |
| 363 | |
| 364 | for (let i = 0; i < packet.questions; i++) { |
| 365 | const question = packet.question(i); |
| 366 | const name = question.qname; |
| 367 | for (let j = 0; j < name.length; j++) |
| 368 | name[j] = name[j].toLowerCase(); |
| 369 | |
| 370 | switch (question.qtype) { |
| 371 | case DNS.RR.A: |
no test coverage detected