소스 검색

fix udp nil && add version display on web

刘河 5 년 전
부모
커밋
08f7c1844a
10개의 변경된 파일52개의 추가작업 그리고 19개의 파일을 삭제
  1. 22 12
      bridge/bridge.go
  2. 1 1
      client/client.go
  3. 4 1
      client/control.go
  4. 1 0
      client/local.go
  5. 1 0
      lib/file/obj.go
  6. 2 2
      lib/version/version.go
  7. 1 1
      server/proxy/socks5.go
  8. 4 1
      server/server.go
  9. 5 0
      web/views/client/list.html
  10. 11 1
      web/views/index/index.html

+ 22 - 12
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()

+ 1 - 1
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)
 	}

+ 4 - 1
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)

+ 1 - 0
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

+ 1 - 0
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
 }
 

+ 2 - 2
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"
 }

+ 1 - 1
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())

+ 4 - 1
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()

+ 5 - 0
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',//标题

+ 11 - 1
web/views/index/index.html

@@ -142,6 +142,16 @@
                                 </div>
                             </div>
                         </li>
+                        <li class="list-group-item ">
+                            <div class="row">
+                                <div class="col-sm-6">
+                                    <strong>服务端版本</strong>
+                                </div>
+                                <div class="col-sm-6 text-right">
+                                    <strong>{{.data.version}}</strong>
+                                </div>
+                            </div>
+                        </li>
                     </ul>
                 </div>
             </div>
@@ -754,4 +764,4 @@
         this.myChart7.resize();
     });
 
-</script>
+</script>