Commit 39df9053 authored by 神楽坂玲奈's avatar 神楽坂玲奈

new delay measure

parent 930e68a7
......@@ -7,6 +7,10 @@
"": {
"name": "railgun-routing-client",
"version": "0.0.1",
"dependencies": {
"@types/lodash-es": "^4.17.6",
"lodash-es": "^4.17.21"
},
"devDependencies": {
"@types/node": "^16.6.1",
"ts-node": "^10.2.0",
......@@ -58,6 +62,19 @@
"integrity": "sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==",
"dev": true
},
"node_modules/@types/lodash": {
"version": "4.14.184",
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.184.tgz",
"integrity": "sha512-RoZphVtHbxPZizt4IcILciSWiC6dcn+eZ8oX9IWEYfDMcocdd42f7NPI6fQj+6zI8y4E0L7gu2pcZKLGTRaV9Q=="
},
"node_modules/@types/lodash-es": {
"version": "4.17.6",
"resolved": "https://registry.npmjs.org/@types/lodash-es/-/lodash-es-4.17.6.tgz",
"integrity": "sha512-R+zTeVUKDdfoRxpAryaQNRKk3105Rrgx2CFRClIgRGaqDTdjsm8h6IYA8ir584W3ePzkZfst5xIgDwYrlh9HLg==",
"dependencies": {
"@types/lodash": "*"
}
},
"node_modules/@types/node": {
"version": "16.6.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.6.1.tgz",
......@@ -106,6 +123,11 @@
"node": ">=0.3.1"
}
},
"node_modules/lodash-es": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.21.tgz",
"integrity": "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw=="
},
"node_modules/make-error": {
"version": "1.3.6",
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz",
......@@ -219,6 +241,19 @@
"integrity": "sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==",
"dev": true
},
"@types/lodash": {
"version": "4.14.184",
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.184.tgz",
"integrity": "sha512-RoZphVtHbxPZizt4IcILciSWiC6dcn+eZ8oX9IWEYfDMcocdd42f7NPI6fQj+6zI8y4E0L7gu2pcZKLGTRaV9Q=="
},
"@types/lodash-es": {
"version": "4.17.6",
"resolved": "https://registry.npmjs.org/@types/lodash-es/-/lodash-es-4.17.6.tgz",
"integrity": "sha512-R+zTeVUKDdfoRxpAryaQNRKk3105Rrgx2CFRClIgRGaqDTdjsm8h6IYA8ir584W3ePzkZfst5xIgDwYrlh9HLg==",
"requires": {
"@types/lodash": "*"
}
},
"@types/node": {
"version": "16.6.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.6.1.tgz",
......@@ -255,6 +290,11 @@
"integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==",
"dev": true
},
"lodash-es": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.21.tgz",
"integrity": "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw=="
},
"make-error": {
"version": "1.3.6",
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz",
......
......@@ -9,5 +9,9 @@
"@types/node": "^16.6.1",
"ts-node": "^10.2.0",
"typescript": "^4.3.5"
},
"dependencies": {
"@types/lodash-es": "^4.17.6",
"lodash-es": "^4.17.21"
}
}
import * as _ from 'lodash-es';
import config from '../config/config.json';
import { PeerMessage, PeerQuality } from '../protocol';
......@@ -18,6 +19,8 @@ export class Peer implements PeerMessage, PeerQuality, RouterConfig {
seq: number = 0;
time: number = 0;
history: (number | undefined)[] = [];
constructor(config: RouterConfig) {
Object.assign(this, config);
}
......@@ -44,8 +47,18 @@ export class Peer implements PeerMessage, PeerQuality, RouterConfig {
const step = data.seq - this.seq;
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;
for (let i = 0; i < config.timeout - 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;
this.delay = _.mean(history) || 0;
this.seq = data.seq;
this.time = time;
......
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