Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
T
tun
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
tun
Commits
2c15b777
Commit
2c15b777
authored
Apr 14, 2020
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update gateway compare
parent
6319628e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
17 deletions
+36
-17
src/inventory.ts
src/inventory.ts
+36
-17
No files found.
src/inventory.ts
View file @
2c15b777
...
...
@@ -19,9 +19,9 @@ class InventoryBuilder {
return
(
await
util
.
promisify
(
parse
)(
data
,
{
columns
:
true
,
cast
:
true
})).
filter
(
h
=>
h
.
id
);
}
async
loadGateways
()
{
async
loadGateways
()
{
let
gateways
=
await
this
.
load
(
'
gateways
'
);
for
(
let
gateway
of
gateways
)
{
for
(
let
gateway
of
gateways
)
{
if
(
!
gateway
.
dev_or_via
.
length
)
continue
;
gateway
.
isTun
=
!
gateway
.
dev_or_via
.
match
(
/^
(\d{1,3}\.){1,3}\d{1,3}
$/
);
...
...
@@ -46,21 +46,21 @@ class InventoryBuilder {
return
fs
.
promises
.
writeFile
(
'
result/inventory.yaml
'
,
result
);
}
async
loadUtilities
(
hosts
)
{
async
loadUtilities
(
hosts
)
{
const
raw_utility
=
_
.
keyBy
(
await
this
.
load
(
'
configurations
'
),
'
key
'
);
let
route_plans
=
await
this
.
load
(
'
route tables
'
);
this
.
route_lists
=
YAML
.
parse
(
fs
.
readFileSync
(
path
.
join
(
'
lists
'
,
'
result.yaml
'
),
"
utf8
"
));
for
(
let
plan
of
route_plans
)
{
for
(
let
plan
of
route_plans
)
{
plan
.
name
=
plan
.
list
+
"
_
"
+
plan
.
gateway
.
replace
(
/-/g
,
"
_
"
).
split
(
"
.
"
)[
0
]
//plan.list = JSON.parse(JSON.stringify(this.route_lists[plan.list]));
plan
.
gatewayAddress
=
hosts
[
plan
.
gateway
].
address
;
}
// 所有内网网段
this
.
route_lists
.
mycard
=
[
"
10.198.0.0/16
"
,
"
10.200.0.0/15
"
];
for
(
const
h
in
this
.
hosts
)
{
for
(
const
h
in
this
.
hosts
)
{
const
host
=
this
.
hosts
[
h
]
for
(
const
c
of
host
.
subnets
.
split
(
"
,
"
))
{
if
(
!
c
.
length
)
{
for
(
const
c
of
host
.
subnets
.
split
(
"
,
"
))
{
if
(
!
c
.
length
)
{
continue
;
}
this
.
route_lists
.
mycard
.
push
(
c
);
...
...
@@ -73,10 +73,10 @@ class InventoryBuilder {
route_list_names
:
Object
.
keys
(
this
.
route_lists
),
route_plans
};
for
(
let
col
in
raw_utility
)
{
for
(
let
col
in
raw_utility
)
{
vars
[
col
]
=
raw_utility
[
col
].
value
;
}
return
vars
;
}
host_vars
(
host
)
{
...
...
@@ -174,20 +174,39 @@ class InventoryBuilder {
};
}
// frps还是frpc的积分,NAT越有利分越高
gatewayCompareScore
(
gateway
:
any
):
number
{
let
score
:
number
=
0xff
-
gateway
.
id
;
const
ipv4Score
=
({
"
static
"
:
2
,
"
dynamic
"
:
1
})[
gateway
.
ipv4
]
||
0
;
score
|=
ipv4Score
<<
12
;
const
ipv4NatScore
=
({
"
ports
"
:
0
,
"
dmz
"
:
1
})[
gateway
.
ipv4_nat
]
||
2
;
score
|=
ipv4NatScore
<<
10
;
const
globalSSHScore
=
({
"
globalssh
"
:
1
})[
gateway
.
ssh
]
||
0
;
score
|=
globalSSHScore
<<
13
;
return
score
;
}
// true: 本地做 server,false: 远端做server
// 如果都不能做,抛异常
// 两个参数对调返回的结果必须相反
gatewayCompare
(
localGateway
:
any
,
remoteGateway
:
any
):
boolean
{
// 两边至少一个有IPv4地址才能连
assert
(
localGateway
.
ipv4
!==
''
||
remoteGateway
.
ipv4
!==
''
);
// 如果都static,就让列表中更靠前的做s
if
(
localGateway
.
ipv4
==
remoteGateway
.
ipv4
)
{
return
localGateway
.
id
<
remoteGateway
.
id
;
}
else
if
(
localGateway
.
ipv4
===
'
static
'
||
remoteGateway
.
ipv4
===
'
static
'
)
{
return
localGateway
.
ipv4
===
'
static
'
;
}
else
{
return
localGateway
.
ipv4
===
'
dynamic
'
;
}
// 两边必须相反
assert
(
this
.
gatewayCompareScore
(
localGateway
)
!==
this
.
gatewayCompareScore
(
remoteGateway
));
// 两边只有一边是GlobalSSH的,GlobalSSH做s
// 只有一边有static的,就static做s
// 如果都static,那么没有NAT的或者dmz的做s
// 如果都还相同,就让列表中更靠前的做s
return
this
.
gatewayCompareScore
(
localGateway
)
>
this
.
gatewayCompareScore
(
remoteGateway
);
}
async
wgPublickey
(
privateKey
)
{
...
...
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