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

new delay measure

parent c435d3a3
Pipeline #15930 passed with stages
in 40 seconds
......@@ -30,6 +30,7 @@ export class Peer implements PeerMessage, PeerQuality, RouterConfig {
this.reliability = 0;
this.seq = 0;
this.time = 0;
this.history = [];
}
onMessage(data: PeerMessage) {
......@@ -37,6 +38,7 @@ export class Peer implements PeerMessage, PeerQuality, RouterConfig {
if (data.seq === 0 || data.seq < this.seq - config.timeout || data.seq > this.seq + config.timeout) {
// 收到 seq = 0 或 seq 与之前差距较大,就 reset
this.reset();
this.seq = data.seq - 1;
} else if (data.seq <= this.seq) {
// 收到 seq 比已知略小的,忽略
return;
......@@ -47,14 +49,12 @@ export class Peer implements PeerMessage, PeerQuality, RouterConfig {
const step = data.seq - this.seq;
const delay = time - data.time;
for (let i = 0; i < config.timeout - step - 1; i++) {
for (let i = 0; i < step - 1; i++) {
this.history.push(undefined);
}
this.history.push(delay);
this.history.splice(0, this.history.length - config.timeout);
console.log(this.history.length)
const history = this.history.filter(s => s !== undefined);
this.reliability = history.length / config.timeout;
......
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