| 512 | if tie... |
| 513 | */ |
| 514 | probe() { |
| 515 | this.probing = 1; |
| 516 | this.probeAttempt = 1; |
| 517 | trace(`probe for ${this.hostName}\n`); |
| 518 | this.client(MDNS.hostName, ""); |
| 519 | this.probeTimer = Timer.repeat(id => { |
| 520 | if (this.probing < 0) { |
| 521 | let hostName = this.client(MDNS.retry, this.hostName); |
| 522 | if (hostName) { |
| 523 | if ("string" == typeof hostName) { |
| 524 | this.hostName = hostName; |
| 525 | this.hostNameLower = hostName.toLowerCase() |
| 526 | this.probeAttempt = 1; |
| 527 | } |
| 528 | else { |
| 529 | Timer.clear(id); |
| 530 | delete this.probeTimer; |
| 531 | // delete this.probing; |
| 532 | delete this.probeAttempt; |
| 533 | delete this.hostName; // no hostName claimed, no longer probing |
| 534 | delete this.hostNameLower; |
| 535 | this.client(MDNS.error); |
| 536 | return; |
| 537 | } |
| 538 | } |
| 539 | else { |
| 540 | if (this.probeAttempt > 2) { |
| 541 | hostName = this.hostName.split("-"); |
| 542 | hostName.pop(); |
| 543 | this.hostName = hostName.join("-"); |
| 544 | } |
| 545 | if (this.probeAttempt >= 2) |
| 546 | this.hostName += "-" + this.probeAttempt; |
| 547 | this.hostNameLower = this.hostName.toLowerCase(); |
| 548 | } |
| 549 | Timer.schedule(id, -this.probing, 250); |
| 550 | this.probing = 1; |
| 551 | trace(`re-probe for ${this.hostName}\n`); |
| 552 | } |
| 553 | if (4 === this.probing) { |
| 554 | trace(`probe claimed ${this.hostName}\n`); |
| 555 | |
| 556 | Timer.clear(id); |
| 557 | delete this.probeTimer; |
| 558 | delete this.probing; |
| 559 | delete this.probeAttempt; |
| 560 | |
| 561 | this.client(MDNS.hostName, this.hostName); |
| 562 | |
| 563 | return; |
| 564 | } |
| 565 | |
| 566 | trace(`probe ${this.probing}\n`); |
| 567 | const reply = new Serializer({query: true, opcode: DNS.OPCODE.QUERY, authoritative: true}); |
| 568 | reply.add(DNS.SECTION.QUESTION, this.hostName + "." + LOCAL, DNS.RR.ANY, DNS.CLASS.IN | MDNS.UNICAST); // question for DNS.RR.A, unicast response requested |
| 569 | reply.add(DNS.SECTION.ANSWER, this.hostName + "." + LOCAL, DNS.RR.A, DNS.CLASS.IN | MDNS.FLUSH, 120, Net.get("IP")); // authoritative answer for DNS.RR.A |
| 570 | this.write(MDNS.IP, MDNS.PORT, reply.build()); |
| 571 | this.probing += 1; |