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
6f983932
Commit
6f983932
authored
Aug 27, 2025
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow -c config.json
parent
1f97c198
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
6 deletions
+39
-6
entrypoint.sh
entrypoint.sh
+19
-4
src/main.rs
src/main.rs
+20
-2
No files found.
entrypoint.sh
View file @
6f983932
#!/bin/bash
#!/bin/bash
pid
=
0
pid
=
0
down
=
$(
echo
"
$1
"
| jq
-r
'.routers | .[].down'
)
downs
=()
if
[
"
${
1
:-}
"
=
"-c"
]
||
[
"
${
1
:-}
"
=
"--config"
]
;
then
config_file
=
"
$2
"
# 从文件直接 cat 管道给 jq
while
IFS
=
read
-r
d
;
do
downs+
=(
"
$d
"
)
done
< <
(
cat
"
$config_file
"
| jq
-r
'.routers[].down'
)
else
# 直接把参数当作 JSON 字符串传给 jq,不存到变量
while
IFS
=
read
-r
d
;
do
downs+
=(
"
$d
"
)
done
< <
(
printf
'%s'
"
$1
"
| jq
-r
'.routers[].down'
)
fi
echo
"
$down
"
echo
"
$down
"
run_stop
()
{
run_stop
()
{
signalCode
=
$1
signalCode
=
$1
if
[
-n
"
$down
"
]
;
then
for
down
in
"
${
downs
[@]
}
"
;
do
eval
"
$down
"
"
$down
"
fi
done
if
[
$pid
-ne
0
]
;
then
if
[
$pid
-ne
0
]
;
then
kill
"-
$signalCode
"
"
$pid
"
kill
"-
$signalCode
"
"
$pid
"
wait
"
$pid
"
wait
"
$pid
"
...
...
src/main.rs
View file @
6f983932
mod
router
;
mod
router
;
use
crate
::
router
::{
Router
,
RouterReader
,
RouterWriter
,
SECRET_LENGTH
};
use
crate
::
router
::{
Router
,
RouterReader
,
RouterWriter
};
use
std
::
collections
::
HashMap
;
use
std
::
collections
::
HashMap
;
use
std
::
env
;
use
std
::
env
;
use
std
::
error
::
Error
;
use
std
::
error
::
Error
;
...
@@ -40,10 +40,28 @@ use crossbeam_utils::thread;
...
@@ -40,10 +40,28 @@ use crossbeam_utils::thread;
use
grouping_by
::
GroupingBy
;
use
grouping_by
::
GroupingBy
;
use
pnet
::
packet
::
ipv4
::
Ipv4Packet
;
use
pnet
::
packet
::
ipv4
::
Ipv4Packet
;
use
socket2
::
Socket
;
use
socket2
::
Socket
;
use
std
::
fs
;
fn
main
()
->
Result
<
(),
Box
<
dyn
Error
>>
{
fn
main
()
->
Result
<
(),
Box
<
dyn
Error
>>
{
println!
(
"Init"
);
println!
(
"Init"
);
let
config
:
Config
=
serde_json
::
from_str
(
env
::
args
()
.nth
(
1
)
.ok_or
(
"need param"
)
?
.as_str
())
?
;
let
args
:
Vec
<
String
>
=
env
::
args
()
.collect
();
if
args
.len
()
<
2
{
return
Err
(
"need JSON string or -c <config.json>"
.into
());
}
let
config
:
Config
;
if
args
[
1
]
==
"-c"
||
args
[
1
]
==
"--config"
{
// 从文件读
if
args
.len
()
<
3
{
return
Err
(
"missing value for -c/--config"
.into
());
}
let
data
=
fs
::
read_to_string
(
&
args
[
2
])
?
;
config
=
serde_json
::
from_str
(
&
data
)
?
;
}
else
{
// 当作 JSON 字符串解析
config
=
serde_json
::
from_str
(
&
args
[
1
])
?
;
}
println!
(
"Read config"
);
println!
(
"Read config"
);
let
mut
sockets
:
HashMap
<
u16
,
Arc
<
Socket
>>
=
HashMap
::
new
();
let
mut
sockets
:
HashMap
<
u16
,
Arc
<
Socket
>>
=
HashMap
::
new
();
println!
(
"Ready"
);
println!
(
"Ready"
);
...
...
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