Commit 85b84cbb authored by 神楽坂玲奈's avatar 神楽坂玲奈

not work

parent 4e468ca6
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "railgun-routing-server",
"version": "0.0.1", "version": "0.0.1",
"dependencies": { "dependencies": {
"lodash": "^4.17.21" "lodash": "^4.17.21"
......
...@@ -93,7 +93,6 @@ export class Router { ...@@ -93,7 +93,6 @@ export class Router {
update(socket: Socket) { update(socket: Socket) {
const changedVia: Record<number, number> = {}; const changedVia: Record<number, number> = {};
const changedPlan: Record<number, number> = {};
const metric: Record<number, number> = {}; const metric: Record<number, number> = {};
for (const to of Router.all.filter(r => r.id !== this.id)) { for (const to of Router.all.filter(r => r.id !== this.id)) {
// 计算最优下一跳 // 计算最优下一跳
...@@ -113,12 +112,19 @@ export class Router { ...@@ -113,12 +112,19 @@ export class Router {
} }
} }
const changedPlan: Record<number, number | null> = {};
for (const plan of plans.filter(plan => !plan.routers.includes(this.id))) { for (const plan of plans.filter(plan => !plan.routers.includes(this.id))) {
const currentPlan = this.plan[plan.id]; const currentPlan = this.plan[plan.id];
const bestPlan = _.minBy(plan.routers, to => metric[to])!; const currentMetric =
if (currentPlan !== bestPlan) { const items = plan.routers.map(to => [to, metric[to]]);
const [bestPlan, bestMetric] = _.minBy(items, ([t, m]) => m)!;
if (bestMetric === Infinity) {
changedPlan[plan.id] = null;
} else {
changedPlan[plan.id] = bestPlan; changedPlan[plan.id] = bestPlan;
} }
} }
if (!_.isEmpty(changedVia) || !_.isEmpty(changedPlan)) { if (!_.isEmpty(changedVia) || !_.isEmpty(changedPlan)) {
......
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