Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
R
railgun-routing-client
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-client
Commits
577c4141
You need to sign in or sign up before continuing.
Commit
577c4141
authored
Aug 21, 2021
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test
parent
dbc63c7f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
11 deletions
+33
-11
config/plans.json
config/plans.json
+9
-0
src/RouteWriter.ts
src/RouteWriter.ts
+23
-10
src/Server.ts
src/Server.ts
+1
-1
No files found.
config/plans.json
0 → 100644
View file @
577c4141
[
{
"id"
:
3
,
"routers"
:
[
1
,
3
]
}
]
src/RouteWriter.ts
View file @
577c4141
import
config
from
'
../config/config.json
'
;
import
routers
from
'
../config/routers.json
'
;
import
plans
from
'
../config/plans.json
'
;
import
child_process
from
'
child_process
'
;
export
class
RouteWriter
{
static
id
=
parseInt
(
process
.
env
.
RAILGUN_ID
);
static
input
:
string
[]
=
[];
static
via
:
Record
<
number
,
number
>
=
{}
;
static
plan
:
Record
<
number
,
number
>
=
{}
;
static
via
=
new
Map
<
number
,
number
>
()
;
static
plan
=
new
Map
<
number
,
number
>
()
;
static
reset
()
{
this
.
input
.
push
(
`route flush table
${
config
.
table
}
proto
${
config
.
proto
}
`
);
for
(
const
peer
of
routers
.
filter
((
r
)
=>
r
.
id
!==
parseInt
(
process
.
env
.
RAILGUN_ID
)
&&
r
.
interface
))
{
this
.
set
(
peer
.
id
,
peer
.
id
);
for
(
const
peer
of
routers
.
filter
((
r
)
=>
r
.
id
!==
this
.
id
&&
r
.
interface
))
{
this
.
setVia
(
peer
.
id
,
peer
.
id
);
}
for
(
const
plan
of
plans
.
filter
(
plan
=>
!
plan
.
routers
.
includes
(
this
.
id
)))
{
this
.
setPlan
(
plan
.
id
,
this
.
id
);
}
}
static
set
(
toId
:
number
,
viaId
:
number
)
{
static
set
Via
(
toId
:
number
,
viaId
:
number
)
{
console
.
log
(
toId
,
viaId
);
this
.
via
.
set
(
toId
,
viaId
);
const
to
=
routers
.
find
(
r
=>
r
.
id
===
toId
);
const
via
=
routers
.
find
(
r
=>
r
.
id
===
viaId
);
for
(
const
address
of
[
to
.
address
,
...
to
.
subnets
])
{
this
.
input
.
push
(
`route replace
${
address
}
dev
${
via
.
interface
}
table
${
config
.
table
}
proto
${
config
.
proto
}
`
);
}
for
(
const
[
table
,
to
]
of
Object
.
entries
(
RouteWriter
.
plan
))
{
for
(
const
[
table
,
to
]
of
this
.
plan
.
entries
(
))
{
if
(
to
===
toId
)
{
this
.
input
.
push
(
`route replace default dev
${
via
.
interface
}
table
${
table
}
proto
${
config
.
proto
}
`
);
}
...
...
@@ -29,13 +35,20 @@ export class RouteWriter {
}
static
setPlan
(
table
:
number
,
toId
:
number
)
{
console
.
log
(
table
,
viaId
);
console
.
log
(
table
,
toId
);
this
.
plan
.
set
(
table
,
toId
);
if
(
toId
===
this
.
id
)
{
this
.
input
.
push
(
`route del default table
${
table
}
proto
${
config
.
proto
}
`
);
}
else
{
const
viaId
=
this
.
via
.
get
(
toId
);
const
via
=
routers
.
find
(
r
=>
r
.
id
===
viaId
);
this
.
input
.
push
(
`route replace default dev
${
via
.
interface
}
table
${
table
}
proto
${
config
.
proto
}
`
);
}
}
static
commit
()
{
// 可能改成异步的会更好点
// 可能改成异步的会更好点
?
child_process
.
execFileSync
(
'
ip
'
,
[
'
-batch
'
,
'
-
'
],
{
input
:
this
.
input
.
join
(
'
\n
'
)
});
this
.
input
=
[];
}
...
...
src/Server.ts
View file @
577c4141
...
...
@@ -19,7 +19,7 @@ export class Server {
}
for
(
const
[
to
,
via
]
of
Object
.
entries
(
message
.
via
))
{
RouteWriter
.
set
(
parseInt
(
to
),
via
);
RouteWriter
.
set
Via
(
parseInt
(
to
),
via
);
}
RouteWriter
.
commit
();
this
.
ack
=
message
.
seq
+
1
;
...
...
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