mirror of
https://github.com/ehang-io/nps.git
synced 2025-09-03 04:26:53 +00:00
add custom client disconnect timeout option, close #485
This commit is contained in:
@@ -41,28 +41,30 @@ func NewClient(t, f *nps_mux.Mux, s *conn.Conn, vs string) *Client {
|
||||
}
|
||||
|
||||
type Bridge struct {
|
||||
TunnelPort int //通信隧道端口
|
||||
Client sync.Map
|
||||
Register sync.Map
|
||||
tunnelType string //bridge type kcp or tcp
|
||||
OpenTask chan *file.Tunnel
|
||||
CloseTask chan *file.Tunnel
|
||||
CloseClient chan int
|
||||
SecretChan chan *conn.Secret
|
||||
ipVerify bool
|
||||
runList sync.Map //map[int]interface{}
|
||||
TunnelPort int //通信隧道端口
|
||||
Client sync.Map
|
||||
Register sync.Map
|
||||
tunnelType string //bridge type kcp or tcp
|
||||
OpenTask chan *file.Tunnel
|
||||
CloseTask chan *file.Tunnel
|
||||
CloseClient chan int
|
||||
SecretChan chan *conn.Secret
|
||||
ipVerify bool
|
||||
runList sync.Map //map[int]interface{}
|
||||
disconnectTime int
|
||||
}
|
||||
|
||||
func NewTunnel(tunnelPort int, tunnelType string, ipVerify bool, runList sync.Map) *Bridge {
|
||||
func NewTunnel(tunnelPort int, tunnelType string, ipVerify bool, runList sync.Map, disconnectTime int) *Bridge {
|
||||
return &Bridge{
|
||||
TunnelPort: tunnelPort,
|
||||
tunnelType: tunnelType,
|
||||
OpenTask: make(chan *file.Tunnel),
|
||||
CloseTask: make(chan *file.Tunnel),
|
||||
CloseClient: make(chan int),
|
||||
SecretChan: make(chan *conn.Secret),
|
||||
ipVerify: ipVerify,
|
||||
runList: runList,
|
||||
TunnelPort: tunnelPort,
|
||||
tunnelType: tunnelType,
|
||||
OpenTask: make(chan *file.Tunnel),
|
||||
CloseTask: make(chan *file.Tunnel),
|
||||
CloseClient: make(chan int),
|
||||
SecretChan: make(chan *conn.Secret),
|
||||
ipVerify: ipVerify,
|
||||
runList: runList,
|
||||
disconnectTime: disconnectTime,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,7 +244,7 @@ func (s *Bridge) typeDeal(typeVal string, c *conn.Conn, id int, vs string) {
|
||||
go s.GetHealthFromClient(id, c)
|
||||
logs.Info("clientId %d connection succeeded, address:%s ", id, c.Conn.RemoteAddr())
|
||||
case common.WORK_CHAN:
|
||||
muxConn := nps_mux.NewMux(c.Conn, s.tunnelType)
|
||||
muxConn := nps_mux.NewMux(c.Conn, s.tunnelType, s.disconnectTime)
|
||||
if v, ok := s.Client.LoadOrStore(id, NewClient(muxConn, nil, nil, vs)); ok {
|
||||
v.(*Client).tunnel = muxConn
|
||||
}
|
||||
@@ -263,7 +265,7 @@ func (s *Bridge) typeDeal(typeVal string, c *conn.Conn, id int, vs string) {
|
||||
logs.Error("secret error, failed to match the key successfully")
|
||||
}
|
||||
case common.WORK_FILE:
|
||||
muxConn := nps_mux.NewMux(c.Conn, s.tunnelType)
|
||||
muxConn := nps_mux.NewMux(c.Conn, s.tunnelType, s.disconnectTime)
|
||||
if v, ok := s.Client.LoadOrStore(id, NewClient(nil, muxConn, nil, vs)); ok {
|
||||
v.(*Client).file = muxConn
|
||||
}
|
||||
|
Reference in New Issue
Block a user