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
cca4bb54
Commit
cca4bb54
authored
Feb 09, 2020
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
scripts
parent
595e28d9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
13 deletions
+20
-13
src/inventory.ts
src/inventory.ts
+20
-13
No files found.
src/inventory.ts
View file @
cca4bb54
...
@@ -24,9 +24,9 @@ class InventoryBuilder {
...
@@ -24,9 +24,9 @@ class InventoryBuilder {
for
(
const
host
of
Object
.
values
(
this
.
hosts
))
{
for
(
const
host
of
Object
.
values
(
this
.
hosts
))
{
host
.
wgPublickey
=
await
this
.
wgPublickey
(
host
.
wgPrivateKey
);
host
.
wgPublickey
=
await
this
.
wgPublickey
(
host
.
wgPrivateKey
);
}
}
console
.
log
(
Object
.
values
(
this
.
hosts
));
//
console.log(Object.values(this.hosts));
const
hosts
=
Object
.
fromEntries
(
Object
.
values
(
this
.
hosts
).
map
(
h
=>
[
h
.
host
,
this
.
host_vars
(
h
)]));
const
hosts
=
Object
.
fromEntries
(
Object
.
values
(
this
.
hosts
).
map
(
h
=>
[
h
.
host
,
this
.
host_vars
(
h
)]));
console
.
log
(
hosts
);
//
console.log(hosts);
const
result
=
YAML
.
stringify
({
wg
:
{
hosts
}
});
const
result
=
YAML
.
stringify
({
wg
:
{
hosts
}
});
return
fs
.
promises
.
writeFile
(
'
result/inventory.yaml
'
,
result
);
return
fs
.
promises
.
writeFile
(
'
result/inventory.yaml
'
,
result
);
}
}
...
@@ -39,11 +39,11 @@ class InventoryBuilder {
...
@@ -39,11 +39,11 @@ class InventoryBuilder {
const
from
=
this
.
hosts
[
h
][
host
.
name
];
const
from
=
this
.
hosts
[
h
][
host
.
name
];
if
(
from
&&
to
)
{
if
(
from
&&
to
)
{
// 非对称连接
// 非对称连接
connections
.
push
(
this
.
parse_connection
(
host
,
this
.
hosts
[
h
],
to
,
false
,
host
.
id
>
this
.
hosts
[
h
].
id
));
connections
.
push
(
this
.
parse_connection
(
host
,
this
.
hosts
[
h
],
to
,
false
,
true
));
connections
.
push
(
this
.
parse_connection
(
host
,
this
.
hosts
[
h
],
from
,
false
,
host
.
id
<
this
.
hosts
[
h
].
id
));
connections
.
push
(
this
.
parse_connection
(
host
,
this
.
hosts
[
h
],
from
,
true
,
false
));
}
else
if
(
from
||
to
)
{
}
else
if
(
from
||
to
)
{
// 对称连接
// 对称连接
connections
.
push
(
this
.
parse_connection
(
host
,
this
.
hosts
[
h
],
from
||
to
,
!!
to
));
connections
.
push
(
this
.
parse_connection
(
host
,
this
.
hosts
[
h
],
from
||
to
,
true
,
true
));
}
}
// 不连接
// 不连接
}
}
...
@@ -58,23 +58,30 @@ class InventoryBuilder {
...
@@ -58,23 +58,30 @@ class InventoryBuilder {
};
};
}
}
parse_connection
(
local
:
any
,
remote
:
any
,
connstr
:
string
,
mirror
=
false
,
inbound
=
false
)
{
parse_connection
(
local
:
any
,
remote
:
any
,
connstr
:
string
,
inbound
:
boolean
,
outbound
:
boolean
)
{
const
leftbottom
=
local
.
id
>
remote
.
id
;
// true 条目位于左下,false 条目位于右上
const
cis
=
!
(
!
leftbottom
&&
inbound
&&
outbound
);
// true 无需翻转,false 需要翻转。
const
primary
=
leftbottom
?
outbound
:
inbound
;
// true 使用 peerAddress、port, false 使用peerAddress2、port2
if
(
local
.
name
===
'
hk-hkg-alql2
'
&&
remote
.
name
===
'
halozy
'
)
{
console
.
log
(
primary
);
}
const
[
_metric
,
protocol
,
_params
]
=
connstr
.
split
(
'
,
'
);
const
[
_metric
,
protocol
,
_params
]
=
connstr
.
split
(
'
,
'
);
const
metric
=
parseInt
(
_metric
);
const
metric
=
parseInt
(
_metric
);
const
params
=
Object
.
fromEntries
(
new
URLSearchParams
(
_params
).
entries
());
const
params
=
Object
.
fromEntries
(
new
URLSearchParams
(
_params
).
entries
());
const
name
=
inbound
?
`
${
remote
.
name
}
-in`
:
remote
.
name
;
const
name
=
`mc
${
!
outbound
?
'
i
'
:
'
-
'
}${
remote
.
name
}
`
;
const
localGatewayName
=
(
mirror
?
params
.
rif
:
params
.
l
if
)
||
params
.
if
;
const
localGatewayName
=
(
cis
?
params
.
lif
:
params
.
r
if
)
||
params
.
if
;
const
localGateway
=
localGatewayName
?
this
.
gateways
[
local
.
name
][
localGatewayName
]
:
undefined
;
const
localGateway
=
localGatewayName
?
this
.
gateways
[
local
.
name
][
localGatewayName
]
:
undefined
;
const
localGatewayMark
=
localGatewayName
?
localGateway
.
mark
:
undefined
;
const
localGatewayMark
=
localGatewayName
?
localGateway
.
mark
:
undefined
;
const
remoteGatewayName
=
(
mirror
?
params
.
lif
:
params
.
r
if
)
||
params
.
if
;
const
remoteGatewayName
=
(
cis
?
params
.
rif
:
params
.
l
if
)
||
params
.
if
;
const
remoteGateway
=
remoteGatewayName
?
this
.
gateways
[
remote
.
name
][
remoteGatewayName
]
:
_
.
find
(
this
.
gateways
[
remote
.
name
]);
const
remoteGateway
=
remoteGatewayName
?
this
.
gateways
[
remote
.
name
][
remoteGatewayName
]
:
_
.
find
(
this
.
gateways
[
remote
.
name
]);
const
remoteAddress
=
remoteGateway
.
address
;
const
remoteAddress
=
remoteGateway
.
address
;
const
remoteMark
=
remote
.
mark
;
const
remoteMark
=
remote
.
mark
;
const
localPort
=
inbound
?
remote
.
port2
:
remote
.
port
;
const
localPort
=
primary
?
remote
.
port
:
remote
.
port2
;
const
remotePort
=
inbound
?
local
.
port2
:
local
.
port
;
const
remotePort
=
primary
?
local
.
port
:
local
.
port2
;
const
wgPublicKey
=
remote
.
wgPublickey
;
const
wgPublicKey
=
remote
.
wgPublickey
;
const
localPeerAddress
=
inbound
?
local
.
peerAddress2
:
local
.
peerAddress
;
const
localPeerAddress
=
primary
?
local
.
peerAddress
:
local
.
peerAddress2
;
const
remotePeerAddress
=
inbound
?
remote
.
peerAddress2
:
remote
.
peerAddress
;
const
remotePeerAddress
=
primary
?
remote
.
peerAddress
:
remote
.
peerAddress2
;
return
{
return
{
name
,
name
,
metric
,
metric
,
...
...
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