From 08f7c1844abf4bb9bc7616a645a22deb0dba9dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B2=B3?= Date: Wed, 4 Dec 2019 01:28:26 +0800 Subject: [PATCH] fix udp nil && add version display on web --- bridge/bridge.go | 34 ++++++++++++++++++++++------------ client/client.go | 2 +- client/control.go | 5 ++++- client/local.go | 1 + lib/file/obj.go | 1 + lib/version/version.go | 4 ++-- server/proxy/socks5.go | 2 +- server/server.go | 5 ++++- web/views/client/list.html | 5 +++++ web/views/index/index.html | 12 +++++++++++- 10 files changed, 52 insertions(+), 19 deletions(-) diff --git a/bridge/bridge.go b/bridge/bridge.go index ea5c282..7894b66 100755 --- a/bridge/bridge.go +++ b/bridge/bridge.go @@ -27,14 +27,16 @@ type Client struct { tunnel *mux.Mux signal *conn.Conn file *mux.Mux + Version string retryTime int // it will be add 1 when ping not ok until to 3 will close the client } -func NewClient(t, f *mux.Mux, s *conn.Conn) *Client { +func NewClient(t, f *mux.Mux, s *conn.Conn, vs string) *Client { return &Client{ - signal: s, - tunnel: t, - file: f, + signal: s, + tunnel: t, + file: f, + Version: vs, } } @@ -166,16 +168,23 @@ func (s *Bridge) cliProcess(c *conn.Conn) { return } //version check - if b, err := c.GetShortContent(32); err != nil || string(b) != crypt.Md5(version.GetVersion()) { + if b, err := c.GetShortLenContent(); err != nil || string(b) != version.GetVersion() { logs.Info("The client %s version does not match", c.Conn.RemoteAddr()) c.Close() return } + //version get + var vs []byte + var err error + if vs, err = c.GetShortLenContent(); err != nil { + logs.Info("get client %s version error", err.Error()) + c.Close() + return + } //write server version to client c.Write([]byte(crypt.Md5(version.GetVersion()))) c.SetReadDeadlineBySecond(5) var buf []byte - var err error //get vKey from client if buf, err = c.GetShortContent(32); err != nil { c.Close() @@ -191,7 +200,7 @@ func (s *Bridge) cliProcess(c *conn.Conn) { s.verifySuccess(c) } if flag, err := c.ReadFlag(); err == nil { - s.typeDeal(flag, c, id) + s.typeDeal(flag, c, id, string(vs)) } else { logs.Warn(err, flag) } @@ -214,7 +223,7 @@ func (s *Bridge) DelClient(id int) { } //use different -func (s *Bridge) typeDeal(typeVal string, c *conn.Conn, id int) { +func (s *Bridge) typeDeal(typeVal string, c *conn.Conn, id int, vs string) { isPub := file.GetDb().IsPubClient(id) switch typeVal { case common.WORK_MAIN: @@ -223,17 +232,18 @@ func (s *Bridge) typeDeal(typeVal string, c *conn.Conn, id int) { return } //the vKey connect by another ,close the client of before - if v, ok := s.Client.LoadOrStore(id, NewClient(nil, nil, c)); ok { + if v, ok := s.Client.LoadOrStore(id, NewClient(nil, nil, c, vs)); ok { if v.(*Client).signal != nil { v.(*Client).signal.WriteClose() } v.(*Client).signal = c + v.(*Client).Version = vs } go s.GetHealthFromClient(id, c) logs.Info("clientId %d connection succeeded, address:%s ", id, c.Conn.RemoteAddr()) case common.WORK_CHAN: muxConn := mux.NewMux(c.Conn, s.tunnelType) - if v, ok := s.Client.LoadOrStore(id, NewClient(muxConn, nil, nil)); ok { + if v, ok := s.Client.LoadOrStore(id, NewClient(muxConn, nil, nil, vs)); ok { v.(*Client).tunnel = muxConn } case common.WORK_CONFIG: @@ -254,7 +264,7 @@ func (s *Bridge) typeDeal(typeVal string, c *conn.Conn, id int) { } case common.WORK_FILE: muxConn := mux.NewMux(c.Conn, s.tunnelType) - if v, ok := s.Client.LoadOrStore(id, NewClient(nil, muxConn, nil)); ok { + if v, ok := s.Client.LoadOrStore(id, NewClient(nil, muxConn, nil, vs)); ok { v.(*Client).file = muxConn } case common.WORK_P2P: @@ -419,7 +429,7 @@ loop: } c.WriteAddOk() c.Write([]byte(client.VerifyKey)) - s.Client.Store(client.Id, NewClient(nil, nil, nil)) + s.Client.Store(client.Id, NewClient(nil, nil, nil, "")) } case common.NEW_HOST: h, err := c.GetHostInfo() diff --git a/client/client.go b/client/client.go index a48907e..ac300ff 100755 --- a/client/client.go +++ b/client/client.go @@ -190,7 +190,7 @@ func (s *TRPClient) handleChan(src net.Conn) { } return } - if lk.ConnType == "udp" { + if lk.ConnType == "udp5" { logs.Trace("new %s connection with the goal of %s, remote address:%s", lk.ConnType, lk.Host, lk.RemoteAddr) s.handleUdp(src) } diff --git a/client/control.go b/client/control.go index 5589d11..faf0fcb 100644 --- a/client/control.go +++ b/client/control.go @@ -220,7 +220,10 @@ func NewConn(tp string, vkey string, server string, connType string, proxyUrl st if _, err := c.Write([]byte(common.CONN_TEST)); err != nil { return nil, err } - if _, err := c.Write([]byte(crypt.Md5(version.GetVersion()))); err != nil { + if err := c.WriteLenContent([]byte(version.GetVersion())); err != nil { + return nil, err + } + if err := c.WriteLenContent([]byte(version.VERSION)); err != nil { return nil, err } b, err := c.GetShortContent(32) diff --git a/client/local.go b/client/local.go index 06057ca..a66f9c0 100644 --- a/client/local.go +++ b/client/local.go @@ -158,6 +158,7 @@ func handleP2PVisitor(localTcpConn net.Conn, config *config.CommonConfig, l *con if udpConn == nil { logs.Notice("new conn, P2P can not penetrate successfully, traffic will be transferred through the server") handleSecret(localTcpConn, config, l) + return } logs.Trace("start trying to connect with the server") //TODO just support compress now because there is not tls file in client packages diff --git a/lib/file/obj.go b/lib/file/obj.go index 15dea37..36c783b 100644 --- a/lib/file/obj.go +++ b/lib/file/obj.go @@ -50,6 +50,7 @@ type Client struct { WebPassword string //the password of web login ConfigConnAllow bool //is allow connected by config file MaxTunnelNum int + Version string sync.RWMutex } diff --git a/lib/version/version.go b/lib/version/version.go index 1f14ef1..0f395a8 100644 --- a/lib/version/version.go +++ b/lib/version/version.go @@ -1,8 +1,8 @@ package version -const VERSION = "0.24.0" +const VERSION = "0.24.3" // Compulsory minimum version, Minimum downward compatibility to this version func GetVersion() string { - return "0.24.0" + return "0.24.3" } diff --git a/server/proxy/socks5.go b/server/proxy/socks5.go index 603d1e4..dd27dfd 100755 --- a/server/proxy/socks5.go +++ b/server/proxy/socks5.go @@ -216,7 +216,7 @@ func (s *Sock5ModeServer) handleUDP(c net.Conn) { s.sendUdpReply(c, reply, succeeded, common.GetServerIpByClientIp(c.RemoteAddr().(*net.TCPAddr).IP)) defer reply.Close() // new a tunnel to client - link := conn.NewLink("udp", "", s.task.Client.Cnf.Crypt, s.task.Client.Cnf.Compress, c.RemoteAddr().String(), false) + link := conn.NewLink("udp5", "", s.task.Client.Cnf.Crypt, s.task.Client.Cnf.Compress, c.RemoteAddr().String(), false) target, err := s.bridge.SendLinkInfo(s.task.Client.Id, link, s.task) if err != nil { logs.Warn("get connection from client id %d error %s", s.task.Client.Id, err.Error()) diff --git a/server/server.go b/server/server.go index 911fde5..5335a40 100644 --- a/server/server.go +++ b/server/server.go @@ -2,6 +2,7 @@ package server import ( "errors" + "github.com/cnlh/nps/lib/version" "math" "os" "strconv" @@ -271,8 +272,9 @@ func GetClientList(start, length int, search, sort, order string, clientId int) func dealClientData() { file.GetDb().JsonDb.Clients.Range(func(key, value interface{}) bool { v := value.(*file.Client) - if _, ok := Bridge.Client.Load(v.Id); ok { + if vv, ok := Bridge.Client.Load(v.Id); ok { v.IsConnect = true + v.Version = vv.(*bridge.Client).Version } else { v.IsConnect = false } @@ -338,6 +340,7 @@ func DelClientConnect(clientId int) { func GetDashboardData() map[string]interface{} { data := make(map[string]interface{}) + data["version"] = version.VERSION data["hostCount"] = common.GeSynctMapLen(file.GetDb().JsonDb.Hosts) data["clientCount"] = common.GeSynctMapLen(file.GetDb().JsonDb.Clients) - 1 //Remove the public key client dealClientData() diff --git a/web/views/client/list.html b/web/views/client/list.html index 60a4fc6..d0d3e6f 100755 --- a/web/views/client/list.html +++ b/web/views/client/list.html @@ -150,6 +150,11 @@ title: 'remark',//标题 visible: true,//false表示不显示 }, + { + field: 'Version',//域值 + title: 'version',//标题 + visible: true,//false表示不显示 + }, { field: 'VerifyKey',//域值 title: 'vkey',//标题 diff --git a/web/views/index/index.html b/web/views/index/index.html index d331443..2d86939 100755 --- a/web/views/index/index.html +++ b/web/views/index/index.html @@ -142,6 +142,16 @@ +
  • +
    +
    + 服务端版本 +
    +
    + {{.data.version}} +
    +
    +
  • @@ -754,4 +764,4 @@ this.myChart7.resize(); }); - \ No newline at end of file +