11package bridge
22
33import (
4+ "ehang.io/nps-mux"
45 "encoding/binary"
56 "errors"
67 "fmt"
@@ -15,7 +16,6 @@ import (
1516 "ehang.io/nps/lib/conn"
1617 "ehang.io/nps/lib/crypt"
1718 "ehang.io/nps/lib/file"
18- "ehang.io/nps/lib/mux"
1919 "ehang.io/nps/lib/version"
2020 "ehang.io/nps/server/connection"
2121 "ehang.io/nps/server/tool"
@@ -24,14 +24,14 @@ import (
2424)
2525
2626type Client struct {
27- tunnel * mux .Mux
27+ tunnel * nps_mux .Mux
2828 signal * conn.Conn
29- file * mux .Mux
29+ file * nps_mux .Mux
3030 Version string
3131 retryTime int // it will be add 1 when ping not ok until to 3 will close the client
3232}
3333
34- func NewClient (t , f * mux .Mux , s * conn.Conn , vs string ) * Client {
34+ func NewClient (t , f * nps_mux .Mux , s * conn.Conn , vs string ) * Client {
3535 return & Client {
3636 signal : s ,
3737 tunnel : t ,
@@ -50,10 +50,10 @@ type Bridge struct {
5050 CloseClient chan int
5151 SecretChan chan * conn.Secret
5252 ipVerify bool
53- runList map [int ]interface {}
53+ runList sync. Map // map[int]interface{}
5454}
5555
56- func NewTunnel (tunnelPort int , tunnelType string , ipVerify bool , runList map [ int ] interface {} ) * Bridge {
56+ func NewTunnel (tunnelPort int , tunnelType string , ipVerify bool , runList sync. Map ) * Bridge {
5757 return & Bridge {
5858 TunnelPort : tunnelPort ,
5959 tunnelType : tunnelType ,
@@ -242,7 +242,7 @@ func (s *Bridge) typeDeal(typeVal string, c *conn.Conn, id int, vs string) {
242242 go s .GetHealthFromClient (id , c )
243243 logs .Info ("clientId %d connection succeeded, address:%s " , id , c .Conn .RemoteAddr ())
244244 case common .WORK_CHAN :
245- muxConn := mux .NewMux (c .Conn , s .tunnelType )
245+ muxConn := nps_mux .NewMux (c .Conn , s .tunnelType )
246246 if v , ok := s .Client .LoadOrStore (id , NewClient (muxConn , nil , nil , vs )); ok {
247247 v .(* Client ).tunnel = muxConn
248248 }
@@ -263,7 +263,7 @@ func (s *Bridge) typeDeal(typeVal string, c *conn.Conn, id int, vs string) {
263263 logs .Error ("secret error, failed to match the key successfully" )
264264 }
265265 case common .WORK_FILE :
266- muxConn := mux .NewMux (c .Conn , s .tunnelType )
266+ muxConn := nps_mux .NewMux (c .Conn , s .tunnelType )
267267 if v , ok := s .Client .LoadOrStore (id , NewClient (nil , muxConn , nil , vs )); ok {
268268 v .(* Client ).file = muxConn
269269 }
@@ -321,7 +321,7 @@ func (s *Bridge) SendLinkInfo(clientId int, link *conn.Link, t *file.Tunnel) (ta
321321 }
322322 }
323323 }
324- var tunnel * mux .Mux
324+ var tunnel * nps_mux .Mux
325325 if t != nil && t .Mode == "file" {
326326 tunnel = v .(* Client ).file
327327 } else {
@@ -407,7 +407,8 @@ loop:
407407 })
408408 file .GetDb ().JsonDb .Tasks .Range (func (key , value interface {}) bool {
409409 v := value .(* file.Tunnel )
410- if _ , ok := s .runList [v .Id ]; ok && v .Client .Id == id {
410+ //if _, ok := s.runList[v.Id]; ok && v.Client.Id == id {
411+ if _ , ok := s .runList .Load (v .Id ); ok && v .Client .Id == id {
411412 str += v .Remark + common .CONN_DATA_SEQ
412413 }
413414 return true
0 commit comments