Skip to content

Commit

Permalink
Introduce 1s timeout between conflict detection and reannouncing
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Sep 20, 2020
1 parent 8ef7efa commit b94c2bc
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Responder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export class Responder implements PacketHandler {
});
}

private republishService(service: CiaoService, callback: PublishCallback): Promise<void> {
private republishService(service: CiaoService, callback: PublishCallback, delayAnnounce = false): Promise<void> {
if (service.serviceState !== ServiceState.ANNOUNCED && service.serviceState !== ServiceState.ANNOUNCING) {
throw new Error("Can't unpublish a service which isn't announced yet. Received " + service.serviceState + " for service " + service.getFQDN());
}
Expand All @@ -245,7 +245,12 @@ export class Responder implements PacketHandler {
service.serviceState = ServiceState.UNANNOUNCED; // the service is now considered unannounced

// and now we basically just announce the service by doing probing and the announce step
return this.advertiseService(service, callback);
if (delayAnnounce) {
return PromiseTimeout(1000)
.then(() => this.advertiseService(service, callback));
} else {
return this.advertiseService(service, callback);
}
}

private unpublishService(service: CiaoService, callback?: UnpublishCallback): Promise<void> {
Expand Down Expand Up @@ -662,7 +667,7 @@ export class Responder implements PacketHandler {
// if this should ever happen in reality, whe might want to introduce a more sophisticated recovery
// for situations where it makes sense
}
});
}, true);
}
}
}
Expand Down Expand Up @@ -712,7 +717,7 @@ export class Responder implements PacketHandler {
const txt = service.getTXT();

if (txt.length !== txtRecord.txt.length) { // length differs, can't be the same data
debug("[%s] Noticed conflicting record on the network. TXT with differing data: %s", service.getFQDN());
debug("[%s] Noticed conflicting record on the network. TXT with differing data length", service.getFQDN());
return true;
}

Expand All @@ -721,7 +726,7 @@ export class Responder implements PacketHandler {
const buffer1 = txtRecord.txt[i];

if (buffer0.length !== buffer1.length || buffer0.toString("hex") !== buffer1.toString("hex")) {
debug("[%s] Noticed conflicting record on the network. TXT with differing data: %s", service.getFQDN());
debug("[%s] Noticed conflicting record on the network. TXT with differing data.", service.getFQDN());
return true;
}
}
Expand Down

0 comments on commit b94c2bc

Please sign in to comment.