Commit b70fb018 authored by 神楽坂玲奈's avatar 神楽坂玲奈

fix

parent 4be39a45
Pipeline #15923 passed with stages
in 37 seconds
......@@ -40,20 +40,21 @@ export class Peer implements PeerMessage, PeerQuality, RouterConfig {
}
// 全新或者 seq 比已知略大。
const time = Date.now();
const step = data.seq - this.seq;
const delay = Date.now() - data.time;
const delay = time - data.time;
this.reliability = (this.reliability * (config.timeout - step)) / config.timeout + 1 / config.timeout;
this.delay = (this.delay * (config.timeout - 1)) / config.timeout + delay / config.timeout;
this.seq = data.seq;
this.time = data.time;
this.time = time;
}
update(time: number): PeerQuality {
if (this.reliability > 0) {
// 有几个包没到
const step = Math.floor((time - this.time + this.delay - config.interval) / config.interval);
const step = Math.floor((time - this.time) / config.interval);
if (step > config.timeout) {
this.reset();
}
......
......@@ -44,7 +44,7 @@ export class Server {
ack: this.ack,
peers: Object.fromEntries(peers.map(peer => [peer.id, peer.update(self.time)]))
};
// console.log(message);
console.log(message);
socket.send(JSON.stringify(message), config.server_port, config.server_address);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment