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

fix

parent 0fbb4dce
Pipeline #15915 passed with stages
in 44 seconds
......@@ -50,13 +50,13 @@ export class Peer implements PeerMessage, PeerQuality, RouterConfig {
this.time = data.time;
}
update(): PeerQuality {
update(time: number): PeerQuality {
if (this.reliability === 0) {
return;
}
// 有几个包没到
const step = Math.floor((Date.now() - this.time + this.delay - config.interval) / config.interval);
const step = Math.floor((time - this.time + this.delay - config.interval) / config.interval);
if (step > config.timeout) {
this.reset();
}
......
......@@ -42,7 +42,7 @@ export class Server {
const message: UploadMessage = {
id: self.id,
ack: this.ack,
peers: Object.fromEntries(peers.map(peer => [peer.id, peer.update()]))
peers: Object.fromEntries(peers.map(peer => [peer.id, peer.update(self.time)]))
};
// console.log(message);
socket.send(JSON.stringify(message), config.server_port, config.server_address);
......
......@@ -38,6 +38,7 @@ const socket = dgram
socket.bind(config.port);
setInterval(() => {
self.time = Date.now();
const message = JSON.stringify(self);
for (const peer of peers) {
socket.send(message, config.port, `10.200.${peer.id}.${self.id}`);
......
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