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
74a8dc13
Commit
74a8dc13
authored
Aug 31, 2022
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
plan, not work
parent
95846ae4
Pipeline
#16308
passed with stages
in 51 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
58 additions
and
91 deletions
+58
-91
.gitignore
.gitignore
+1
-0
config/plans.json
config/plans.json
+0
-9
config/routers.json
config/routers.json
+0
-46
protocol.ts
protocol.ts
+1
-1
src/RouteWriter.ts
src/RouteWriter.ts
+17
-13
src/Router.ts
src/Router.ts
+26
-9
src/Server.ts
src/Server.ts
+6
-6
src/main.ts
src/main.ts
+7
-7
No files found.
.gitignore
View file @
74a8dc13
/.idea/
/node_modules/
/import/
config/plans.json
deleted
100644 → 0
View file @
95846ae4
[
{
"id"
:
3
,
"routers"
:
[
1
,
3
]
}
]
config/routers.json
deleted
100644 → 0
View file @
95846ae4
[
{
"id"
:
1
,
"interface"
:
"mc-yangtze"
,
"address"
:
"10.198.0.1"
,
"subnets"
:
[]},
{
"id"
:
3
,
"interface"
:
"mc-south"
,
"address"
:
"10.198.0.3"
,
"subnets"
:
[]},
{
"id"
:
4
,
"interface"
:
"mc-ayane"
,
"address"
:
"10.198.0.4"
,
"subnets"
:
[]},
{
"id"
:
5
,
"interface"
:
"mc-satori"
,
"address"
:
"10.198.0.5"
,
"subnets"
:
[]},
{
"id"
:
6
,
"interface"
:
"mc-koishi"
,
"address"
:
"10.198.0.6"
,
"subnets"
:
[]},
{
"id"
:
7
,
"interface"
:
"mc-fractal"
,
"address"
:
"10.198.0.7"
,
"subnets"
:
[]},
{
"id"
:
8
,
"interface"
:
"mc-nanahira"
,
"address"
:
"10.198.0.22"
,
"subnets"
:
[]},
{
"id"
:
9
,
"interface"
:
"mc-marcia"
,
"address"
:
"10.198.0.9"
,
"subnets"
:
[]},
{
"id"
:
10
,
"interface"
:
"mc-anillc"
,
"address"
:
"10.198.0.10"
,
"subnets"
:
[]},
{
"id"
:
11
,
"interface"
:
"mc-crest"
,
"address"
:
"10.198.0.15"
,
"subnets"
:
[]},
{
"id"
:
12
,
"interface"
:
"mc-hk-hkg-alql2"
,
"address"
:
"10.198.0.12"
,
"subnets"
:
[]},
{
"id"
:
13
,
"interface"
:
"mc-hk-hkg-alql3"
,
"address"
:
"10.198.0.20"
,
"subnets"
:
[]},
{
"id"
:
14
,
"interface"
:
"mc-frog"
,
"address"
:
"10.198.0.8"
,
"subnets"
:
[]},
{
"id"
:
15
,
"interface"
:
"mc-ailizijiang"
,
"address"
:
"10.198.0.41"
,
"subnets"
:
[]},
{
"id"
:
16
,
"interface"
:
"mc-kano"
,
"address"
:
"10.198.0.14"
,
"subnets"
:
[]},
{
"id"
:
17
,
"interface"
:
"mc-ge-muc-uma"
,
"address"
:
"10.198.0.18"
,
"subnets"
:
[]},
{
"id"
:
18
,
"interface"
:
"mc-sakuya"
,
"address"
:
"10.198.0.16"
,
"subnets"
:
[]},
{
"id"
:
19
,
"interface"
:
"mc-monika"
,
"address"
:
"10.198.0.21"
,
"subnets"
:
[]},
{
"id"
:
24
,
"interface"
:
"mc-palm"
,
"address"
:
"10.198.0.34"
,
"subnets"
:
[]},
{
"id"
:
25
,
"interface"
:
"mc-pekunicom"
,
"address"
:
"10.198.0.40"
,
"subnets"
:
[]},
{
"id"
:
26
,
"interface"
:
"mc-jue"
,
"address"
:
"10.198.0.32"
,
"subnets"
:
[]},
{
"id"
:
28
,
"interface"
:
"mc-bluebird"
,
"address"
:
"10.198.0.36"
,
"subnets"
:
[]},
{
"id"
:
29
,
"interface"
:
"mc-chikaanna"
,
"address"
:
"10.198.0.35"
,
"subnets"
:
[]},
{
"id"
:
30
,
"interface"
:
"mc-cain"
,
"address"
:
"10.198.0.17"
,
"subnets"
:
[]},
{
"id"
:
32
,
"interface"
:
"mc-hime"
,
"address"
:
"10.198.0.25"
,
"subnets"
:
[]},
{
"id"
:
33
,
"interface"
:
"mc-shirayuki"
,
"address"
:
"10.198.0.28"
,
"subnets"
:
[]},
{
"id"
:
35
,
"interface"
:
"mc-whitelight"
,
"address"
:
"10.198.0.42"
,
"subnets"
:
[]},
{
"id"
:
37
,
"interface"
:
"mc-nekoyuki"
,
"address"
:
"10.198.0.37"
,
"subnets"
:
[]},
{
"id"
:
38
,
"interface"
:
"mc-rossa"
,
"address"
:
"10.198.0.38"
,
"subnets"
:
[]},
{
"id"
:
39
,
"interface"
:
"mc-tsan"
,
"address"
:
"10.198.0.39"
,
"subnets"
:
[]},
{
"id"
:
40
,
"interface"
:
"mc-budingocg"
,
"address"
:
"10.198.0.13"
,
"subnets"
:
[]},
{
"id"
:
41
,
"interface"
:
"mc-hlsj-vpn-3"
,
"address"
:
"10.198.0.53"
,
"subnets"
:
[]},
{
"id"
:
42
,
"interface"
:
"mc-kino-enter"
,
"address"
:
"10.198.0.23"
,
"subnets"
:
[]},
{
"id"
:
44
,
"interface"
:
"mc-tx-sha-xs"
,
"address"
:
"10.198.0.44"
,
"subnets"
:
[]},
{
"id"
:
45
,
"interface"
:
"mc-tx-sha-hd"
,
"address"
:
"10.198.0.45"
,
"subnets"
:
[]},
{
"id"
:
46
,
"interface"
:
"mc-tx-pek-wl"
,
"address"
:
"10.198.0.46"
,
"subnets"
:
[]},
{
"id"
:
47
,
"interface"
:
"mc-tx-can-hr"
,
"address"
:
"10.198.0.47"
,
"subnets"
:
[]},
{
"id"
:
48
,
"interface"
:
"mc-tx-can-qiao"
,
"address"
:
"10.198.0.48"
,
"subnets"
:
[]},
{
"id"
:
49
,
"interface"
:
"mc-tx-sha-saku"
,
"address"
:
"10.198.0.49"
,
"subnets"
:
[]},
{
"id"
:
63
,
"interface"
:
"mc-kr-chu-cain1"
,
"address"
:
"10.198.0.26"
,
"subnets"
:
[]},
{
"id"
:
64
,
"interface"
:
"mc-kr-chu-cain2"
,
"address"
:
"10.198.0.27"
,
"subnets"
:
[]},
{
"id"
:
65
,
"interface"
:
"mc-kr-chu-caina"
,
"address"
:
"10.198.0.29"
,
"subnets"
:
[]},
{
"id"
:
100
,
"interface"
:
"mc-mini"
,
"address"
:
"10.198.0.100"
,
"subnets"
:
[]},
{
"id"
:
101
,
"interface"
:
"mc-genz"
,
"address"
:
"10.198.0.101"
,
"subnets"
:
[]}
]
\ No newline at end of file
protocol.ts
View file @
74a8dc13
...
...
@@ -17,7 +17,7 @@ export interface Report {
export
interface
Change
{
seq
:
number
,
via
:
Record
<
number
,
number
>
,
//
plan: Record<number, number>
plan
:
Record
<
number
,
number
>
}
// 路由器向路由器发送的消息
...
...
src/RouteWriter.ts
View file @
74a8dc13
import
config
from
'
../config/config.json
'
;
import
routers
from
'
../config/routers.json
'
;
import
plans
from
'
../config/plans.json
'
;
import
{
parseInt
}
from
'
lodash
'
;
import
{
Router
}
from
'
./Router
'
;
import
child_process
from
'
child_process
'
;
export
class
RouteWriter
{
...
...
@@ -10,26 +11,29 @@ export class RouteWriter {
static
plan
=
new
Map
<
number
,
number
>
();
static
reset
()
{
console
.
log
(
"
reset
"
);
console
.
log
(
'
reset
'
);
const
self
=
Router
.
all
.
find
(
r
=>
r
.
id
===
this
.
id
);
this
.
input
.
push
(
`route flush table
${
config
.
table
}
proto
${
config
.
proto
}
`
);
for
(
const
peer
of
routers
.
filter
((
r
)
=>
r
.
id
!==
this
.
id
&&
r
.
interface
))
{
for
(
const
peer
of
Router
.
all
.
filter
((
r
)
=>
r
.
id
!==
this
.
id
))
{
this
.
setVia
(
peer
.
id
,
peer
.
id
);
}
for
(
const
plan
of
plans
.
filter
(
plan
=>
!
plan
.
routers
.
includes
(
this
.
id
)))
{
this
.
setPlan
(
plan
.
id
,
this
.
id
);
for
(
const
[
_groupId
,
groupRouters
]
of
Object
.
entries
(
Router
.
groups
).
filter
(([
_
,
g
])
=>
!
g
.
includes
(
self
)))
{
const
groupId
=
parseInt
(
_groupId
);
this
.
setPlan
(
groupId
,
this
.
id
);
}
}
static
setVia
(
toId
:
number
,
viaId
:
number
)
{
this
.
via
.
set
(
toId
,
viaId
);
const
to
=
routers
.
find
(
r
=>
r
.
id
===
toId
);
const
via
=
routers
.
find
(
r
=>
r
.
id
===
viaId
);
const
to
=
Router
.
all
.
find
(
r
=>
r
.
id
===
toId
);
const
via
=
Router
.
all
.
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
}
`
);
this
.
input
.
push
(
`route replace
${
address
}
via
${
via
.
linkAddress
}
table
${
config
.
table
}
proto
${
config
.
proto
}
`
);
}
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
}
`
);
this
.
input
.
push
(
`route replace default
via
${
via
.
linkAddress
}
table
${
table
}
proto
${
config
.
proto
}
`
);
}
}
}
...
...
@@ -41,8 +45,8 @@ export class RouteWriter {
this
.
input
.
push
(
`route flush 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
}
`
);
const
via
=
Router
.
all
.
find
(
r
=>
r
.
id
===
viaId
);
this
.
input
.
push
(
`route replace default
via
${
via
.
linkAddress
}
table
${
table
}
proto
${
config
.
proto
}
`
);
}
}
...
...
@@ -51,7 +55,7 @@ export class RouteWriter {
// 可能改成异步的会更好点?
const
input
=
this
.
input
.
join
(
'
\n
'
);
console
.
log
(
input
);
//
child_process.execFileSync('ip', ['-batch', '-'], { input });
child_process
.
execFileSync
(
'
ip
'
,
[
'
-batch
'
,
'
-
'
],
{
input
});
this
.
input
=
[];
}
}
src/
Pe
er.ts
→
src/
Rout
er.ts
View file @
74a8dc13
import
*
as
_
from
'
lodash
'
;
import
config
from
'
../config/config.json
'
;
import
{
Hello
,
PeerQuality
}
from
'
../protocol
'
;
import
routers
from
'
../import/data/Router.json
'
;
import
{
GatewayGroup
}
from
'
../import/scripts/GatewayGroup
'
;
import
gatewayGroups
from
'
../import/data/GatewayGroup.json
'
;
import
subnets
from
'
../import/data/Subnet.json
'
;
export
interface
RouterConfig
{
id
:
number
;
address
:
string
;
subnets
:
string
[];
}
export
class
Router
implements
Hello
,
PeerQuality
{
static
all
:
Router
[]
=
routers
.
filter
(
r
=>
r
.
id
!==
parseInt
(
process
.
env
.
RAILGUN_ID
)).
map
(
r
=>
new
Router
(
r
.
id
,
r
));
static
groups
:
Record
<
number
,
Router
[]
>
;
export
class
Peer
implements
Hello
,
PeerQuality
,
RouterConfig
{
id
:
number
;
address
:
string
;
linkAddress
:
string
;
subnets
:
string
[];
delay
:
number
=
0
;
...
...
@@ -21,8 +22,10 @@ export class Peer implements Hello, PeerQuality, RouterConfig {
history
:
(
number
|
undefined
)[]
=
[];
constructor
(
config
:
RouterConfig
)
{
Object
.
assign
(
this
,
config
);
constructor
(
public
id
:
number
,
r
:
any
)
{
this
.
address
=
r
.
address
;
this
.
linkAddress
=
`10.200.
${
id
}
.
${
parseInt
(
process
.
env
.
RAILGUN_ID
)}
`
;
this
.
subnets
=
subnets
.
filter
(
s
=>
r
.
name
).
map
(
s
=>
s
.
subnet
);
}
reset
()
{
...
...
@@ -88,3 +91,17 @@ export class Peer implements Hello, PeerQuality, RouterConfig {
};
}
}
function
groupRouters
(
g
:
GatewayGroup
):
Router
[]
{
return
_
.
uniq
(
g
.
locationPrefix
.
flatMap
((
p
)
=>
routers
.
filter
((
r
)
=>
r
.
location
.
startsWith
(
p
)))
.
concat
(
routers
.
filter
((
r
)
=>
g
.
includeRouters
.
includes
(
r
.
name
)))
.
filter
((
r
)
=>
!
g
.
excludeRouters
.
includes
(
r
.
name
))
.
map
((
r
)
=>
Router
.
all
.
find
((
r1
)
=>
r1
.
id
===
r
.
id
)
!
)
.
concat
(
gatewayGroups
.
filter
((
g1
)
=>
g
.
children
.
includes
(
g1
.
name
)).
flatMap
((
c
)
=>
groupRouters
(
c
)))
);
}
Router
.
groups
=
Object
.
fromEntries
(
gatewayGroups
.
map
((
g
)
=>
[
g
.
id
,
groupRouters
(
g
)]));
console
.
log
(
Router
.
groups
);
src/Server.ts
View file @
74a8dc13
...
...
@@ -3,7 +3,7 @@ import { Socket } from 'dgram';
import
config
from
'
../config/config.json
'
;
import
{
RouteWriter
}
from
'
./RouteWriter
'
;
import
{
Peer
}
from
'
./Pe
er
'
;
import
{
Router
}
from
'
./Rout
er
'
;
import
{
Change
,
Hello
,
Report
}
from
'
../protocol
'
;
export
class
Server
{
...
...
@@ -23,9 +23,9 @@ export class Server {
for
(
const
[
to
,
via
]
of
Object
.
entries
(
message
.
via
))
{
RouteWriter
.
setVia
(
parseInt
(
to
),
via
);
}
//
for (const [plan, to] of Object.entries(message.plan)) {
//
RouteWriter.setVia(parseInt(plan), to);
//
}
for
(
const
[
plan
,
to
]
of
Object
.
entries
(
message
.
plan
))
{
RouteWriter
.
setVia
(
parseInt
(
plan
),
to
);
}
RouteWriter
.
commit
();
this
.
ack
++
;
...
...
@@ -37,11 +37,11 @@ export class Server {
socket
.
send
(
JSON
.
stringify
(
response
),
config
.
server_port
,
config
.
server_address
);
}
update
(
socket
:
Socket
,
self
:
Hello
,
peers
:
Peer
[]
)
{
update
(
socket
:
Socket
,
self
:
Hello
)
{
const
message
:
Report
=
{
id
:
self
.
id
,
ack
:
this
.
ack
,
peers
:
Object
.
fromEntries
(
peers
.
map
(
peer
=>
[
peer
.
id
,
peer
.
update
(
self
.
time
)]))
peers
:
Object
.
fromEntries
(
Router
.
all
.
map
(
peer
=>
[
peer
.
id
,
peer
.
update
(
self
.
time
)]))
};
socket
.
send
(
JSON
.
stringify
(
message
),
config
.
server_port
,
config
.
server_address
);
}
...
...
src/main.ts
View file @
74a8dc13
import
dgram
from
'
dgram
'
;
import
assert
from
'
assert
'
;
import
config
from
'
../config/config.json
'
;
import
routers
from
'
../config/routers.json
'
;
import
{
Server
}
from
'
./Server
'
;
import
{
Peer
}
from
'
./Pe
er
'
;
import
{
Router
}
from
'
./Rout
er
'
;
import
{
Change
,
Hello
}
from
'
../protocol
'
;
import
routers
from
'
../import/data/Router.json
'
;
const
self
:
Hello
=
{
id
:
parseInt
(
process
.
env
.
RAILGUN_ID
),
seq
:
0
,
time
:
0
};
const
server
=
new
Server
();
const
peers
=
routers
.
filter
(
r
=>
r
.
id
!==
self
.
id
&&
r
.
interface
).
map
(
r
=>
new
Peer
(
r
));
const
socket
=
dgram
.
createSocket
(
'
udp4
'
)
...
...
@@ -26,7 +26,7 @@ const socket = dgram
// from client
const
message
:
Hello
=
JSON
.
parse
(
msg
.
toString
());
assert
(
message
.
id
);
const
peer
=
peers
.
find
(
p
=>
p
.
id
===
message
.
id
);
const
peer
=
Router
.
all
.
find
(
p
=>
p
.
id
===
message
.
id
);
// assert(peer && rinfo.address === `10.200.${self.id}.${peer.id}` && rinfo.port === config.port);
peer
.
onMessage
(
message
);
}
...
...
@@ -40,9 +40,9 @@ socket.bind(config.port);
setInterval
(()
=>
{
self
.
time
=
Date
.
now
();
const
message
=
JSON
.
stringify
(
self
);
for
(
const
peer
of
peers
)
{
socket
.
send
(
message
,
config
.
port
,
`10.200.
${
peer
.
id
}
.
${
self
.
id
}
`
);
for
(
const
peer
of
Router
.
all
)
{
socket
.
send
(
message
,
config
.
port
,
peer
.
linkAddress
);
}
server
.
update
(
socket
,
self
,
peers
);
server
.
update
(
socket
,
self
);
self
.
seq
++
;
},
config
.
interval
);
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