mirror of
https://github.com/ehang-io/nps.git
synced 2025-09-03 11:16:31 +00:00
add custom client disconnect timeout option, close #485
This commit is contained in:
@@ -21,23 +21,24 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
serverAddr = flag.String("server", "", "Server addr (ip:port)")
|
||||
configPath = flag.String("config", "", "Configuration file path")
|
||||
verifyKey = flag.String("vkey", "", "Authentication key")
|
||||
logType = flag.String("log", "stdout", "Log output mode(stdout|file)")
|
||||
connType = flag.String("type", "tcp", "Connection type with the server(kcp|tcp)")
|
||||
proxyUrl = flag.String("proxy", "", "proxy socks5 url(eg:socks5://111:222@127.0.0.1:9007)")
|
||||
logLevel = flag.String("log_level", "7", "log level 0~7")
|
||||
registerTime = flag.Int("time", 2, "register time long /h")
|
||||
localPort = flag.Int("local_port", 2000, "p2p local port")
|
||||
password = flag.String("password", "", "p2p password flag")
|
||||
target = flag.String("target", "", "p2p target")
|
||||
localType = flag.String("local_type", "p2p", "p2p target")
|
||||
logPath = flag.String("log_path", "", "npc log path")
|
||||
debug = flag.Bool("debug", true, "npc debug")
|
||||
pprofAddr = flag.String("pprof", "", "PProf debug addr (ip:port)")
|
||||
stunAddr = flag.String("stun_addr", "stun.stunprotocol.org:3478", "stun server address (eg:stun.stunprotocol.org:3478)")
|
||||
ver = flag.Bool("version", false, "show current version")
|
||||
serverAddr = flag.String("server", "", "Server addr (ip:port)")
|
||||
configPath = flag.String("config", "", "Configuration file path")
|
||||
verifyKey = flag.String("vkey", "", "Authentication key")
|
||||
logType = flag.String("log", "stdout", "Log output mode(stdout|file)")
|
||||
connType = flag.String("type", "tcp", "Connection type with the server(kcp|tcp)")
|
||||
proxyUrl = flag.String("proxy", "", "proxy socks5 url(eg:socks5://111:222@127.0.0.1:9007)")
|
||||
logLevel = flag.String("log_level", "7", "log level 0~7")
|
||||
registerTime = flag.Int("time", 2, "register time long /h")
|
||||
localPort = flag.Int("local_port", 2000, "p2p local port")
|
||||
password = flag.String("password", "", "p2p password flag")
|
||||
target = flag.String("target", "", "p2p target")
|
||||
localType = flag.String("local_type", "p2p", "p2p target")
|
||||
logPath = flag.String("log_path", "", "npc log path")
|
||||
debug = flag.Bool("debug", true, "npc debug")
|
||||
pprofAddr = flag.String("pprof", "", "PProf debug addr (ip:port)")
|
||||
stunAddr = flag.String("stun_addr", "stun.stunprotocol.org:3478", "stun server address (eg:stun.stunprotocol.org:3478)")
|
||||
ver = flag.Bool("version", false, "show current version")
|
||||
disconnectTime = flag.Int("disconnect_timeout", 60, "not receiving check packet times, until timeout will disconnect the client")
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -231,7 +232,7 @@ func run() {
|
||||
if *verifyKey != "" && *serverAddr != "" && *configPath == "" {
|
||||
go func() {
|
||||
for {
|
||||
client.NewRPClient(*serverAddr, *verifyKey, *connType, *proxyUrl, nil).Start()
|
||||
client.NewRPClient(*serverAddr, *verifyKey, *connType, *proxyUrl, nil, *disconnectTime).Start()
|
||||
logs.Info("It will be reconnected in five seconds")
|
||||
time.Sleep(time.Second * 5)
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ func StartClientByVerifyKey(serverAddr, verifyKey, connType, proxyUrl *C.char) i
|
||||
if cl != nil {
|
||||
cl.Close()
|
||||
}
|
||||
cl = client.NewRPClient(C.GoString(serverAddr), C.GoString(verifyKey), C.GoString(connType), C.GoString(proxyUrl), nil)
|
||||
cl = client.NewRPClient(C.GoString(serverAddr), C.GoString(verifyKey), C.GoString(connType), C.GoString(proxyUrl), nil, 60)
|
||||
go func() {
|
||||
cl.Start()
|
||||
return
|
||||
|
@@ -205,5 +205,9 @@ func run() {
|
||||
crypt.InitTls()
|
||||
tool.InitAllowPort()
|
||||
tool.StartSystemInfo()
|
||||
go server.StartNewServer(bridgePort, task, beego.AppConfig.String("bridge_type"))
|
||||
timeout, err := beego.AppConfig.Int("disconnect_timeout")
|
||||
if err != nil {
|
||||
timeout = 60
|
||||
}
|
||||
go server.StartNewServer(bridgePort, task, beego.AppConfig.String("bridge_type"), timeout)
|
||||
}
|
||||
|
Reference in New Issue
Block a user