Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
R
railgun-routing-server
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
railgun-routing-server
Commits
85b84cbb
Commit
85b84cbb
authored
Aug 20, 2021
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
not work
parent
4e468ca6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
3 deletions
+10
-3
package-lock.json
package-lock.json
+1
-0
src/Router.ts
src/Router.ts
+9
-3
No files found.
package-lock.json
View file @
85b84cbb
...
...
@@ -5,6 +5,7 @@
"requires"
:
true
,
"packages"
:
{
""
:
{
"name"
:
"railgun-routing-server"
,
"version"
:
"0.0.1"
,
"dependencies"
:
{
"lodash"
:
"^4.17.21"
...
...
src/Router.ts
View file @
85b84cbb
...
...
@@ -93,7 +93,6 @@ export class Router {
update
(
socket
:
Socket
)
{
const
changedVia
:
Record
<
number
,
number
>
=
{};
const
changedPlan
:
Record
<
number
,
number
>
=
{};
const
metric
:
Record
<
number
,
number
>
=
{};
for
(
const
to
of
Router
.
all
.
filter
(
r
=>
r
.
id
!==
this
.
id
))
{
// 计算最优下一跳
...
...
@@ -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
)))
{
const
currentPlan
=
this
.
plan
[
plan
.
id
];
const
bestPlan
=
_
.
minBy
(
plan
.
routers
,
to
=>
metric
[
to
])
!
;
if
(
currentPlan
!==
bestPlan
)
{
const
currentMetric
=
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
;
}
}
if
(
!
_
.
isEmpty
(
changedVia
)
||
!
_
.
isEmpty
(
changedPlan
))
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment