Browse Source

fix udp nil && add version display on web

刘河 5 years ago
parent
commit
08f7c1844a

+ 22 - 12
bridge/bridge.go

@@ -27,14 +27,16 @@ type Client struct {
 	tunnel    *mux.Mux
 	tunnel    *mux.Mux
 	signal    *conn.Conn
 	signal    *conn.Conn
 	file      *mux.Mux
 	file      *mux.Mux
+	Version   string
 	retryTime int // it will be add 1 when ping not ok until to 3 will close the client
 	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{
 	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
 		return
 	}
 	}
 	//version check
 	//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())
 		logs.Info("The client %s version does not match", c.Conn.RemoteAddr())
 		c.Close()
 		c.Close()
 		return
 		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
 	//write server version to client
 	c.Write([]byte(crypt.Md5(version.GetVersion())))
 	c.Write([]byte(crypt.Md5(version.GetVersion())))
 	c.SetReadDeadlineBySecond(5)
 	c.SetReadDeadlineBySecond(5)
 	var buf []byte
 	var buf []byte
-	var err error
 	//get vKey from client
 	//get vKey from client
 	if buf, err = c.GetShortContent(32); err != nil {
 	if buf, err = c.GetShortContent(32); err != nil {
 		c.Close()
 		c.Close()
@@ -191,7 +200,7 @@ func (s *Bridge) cliProcess(c *conn.Conn) {
 		s.verifySuccess(c)
 		s.verifySuccess(c)
 	}
 	}
 	if flag, err := c.ReadFlag(); err == nil {
 	if flag, err := c.ReadFlag(); err == nil {
-		s.typeDeal(flag, c, id)
+		s.typeDeal(flag, c, id, string(vs))
 	} else {
 	} else {
 		logs.Warn(err, flag)
 		logs.Warn(err, flag)
 	}
 	}
@@ -214,7 +223,7 @@ func (s *Bridge) DelClient(id int) {
 }
 }
 
 
 //use different
 //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)
 	isPub := file.GetDb().IsPubClient(id)
 	switch typeVal {
 	switch typeVal {
 	case common.WORK_MAIN:
 	case common.WORK_MAIN:
@@ -223,17 +232,18 @@ func (s *Bridge) typeDeal(typeVal string, c *conn.Conn, id int) {
 			return
 			return
 		}
 		}
 		//the vKey connect by another ,close the client of before
 		//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 {
 			if v.(*Client).signal != nil {
 				v.(*Client).signal.WriteClose()
 				v.(*Client).signal.WriteClose()
 			}
 			}
 			v.(*Client).signal = c
 			v.(*Client).signal = c
+			v.(*Client).Version = vs
 		}
 		}
 		go s.GetHealthFromClient(id, c)
 		go s.GetHealthFromClient(id, c)
 		logs.Info("clientId %d connection succeeded, address:%s ", id, c.Conn.RemoteAddr())
 		logs.Info("clientId %d connection succeeded, address:%s ", id, c.Conn.RemoteAddr())
 	case common.WORK_CHAN:
 	case common.WORK_CHAN:
 		muxConn := mux.NewMux(c.Conn, s.tunnelType)
 		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
 			v.(*Client).tunnel = muxConn
 		}
 		}
 	case common.WORK_CONFIG:
 	case common.WORK_CONFIG:
@@ -254,7 +264,7 @@ func (s *Bridge) typeDeal(typeVal string, c *conn.Conn, id int) {
 		}
 		}
 	case common.WORK_FILE:
 	case common.WORK_FILE:
 		muxConn := mux.NewMux(c.Conn, s.tunnelType)
 		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
 			v.(*Client).file = muxConn
 		}
 		}
 	case common.WORK_P2P:
 	case common.WORK_P2P:
@@ -419,7 +429,7 @@ loop:
 				}
 				}
 				c.WriteAddOk()
 				c.WriteAddOk()
 				c.Write([]byte(client.VerifyKey))
 				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:
 		case common.NEW_HOST:
 			h, err := c.GetHostInfo()
 			h, err := c.GetHostInfo()

+ 1 - 1
client/client.go

@@ -190,7 +190,7 @@ func (s *TRPClient) handleChan(src net.Conn) {
 		}
 		}
 		return
 		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)
 		logs.Trace("new %s connection with the goal of %s, remote address:%s", lk.ConnType, lk.Host, lk.RemoteAddr)
 		s.handleUdp(src)
 		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 {
 	if _, err := c.Write([]byte(common.CONN_TEST)); err != nil {
 		return nil, err
 		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
 		return nil, err
 	}
 	}
 	b, err := c.GetShortContent(32)
 	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 {
 	if udpConn == nil {
 		logs.Notice("new conn, P2P can not penetrate successfully, traffic will be transferred through the server")
 		logs.Notice("new conn, P2P can not penetrate successfully, traffic will be transferred through the server")
 		handleSecret(localTcpConn, config, l)
 		handleSecret(localTcpConn, config, l)
+		return
 	}
 	}
 	logs.Trace("start trying to connect with the server")
 	logs.Trace("start trying to connect with the server")
 	//TODO just support compress now because there is not tls file in client packages
 	//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
 	WebPassword     string     //the password of web login
 	ConfigConnAllow bool       //is allow connected by config file
 	ConfigConnAllow bool       //is allow connected by config file
 	MaxTunnelNum    int
 	MaxTunnelNum    int
+	Version         string
 	sync.RWMutex
 	sync.RWMutex
 }
 }
 
 

+ 2 - 2
lib/version/version.go

@@ -1,8 +1,8 @@
 package version
 package version
 
 
-const VERSION = "0.24.0"
+const VERSION = "0.24.3"
 
 
 // Compulsory minimum version, Minimum downward compatibility to this version
 // Compulsory minimum version, Minimum downward compatibility to this version
 func GetVersion() string {
 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))
 	s.sendUdpReply(c, reply, succeeded, common.GetServerIpByClientIp(c.RemoteAddr().(*net.TCPAddr).IP))
 	defer reply.Close()
 	defer reply.Close()
 	// new a tunnel to client
 	// 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)
 	target, err := s.bridge.SendLinkInfo(s.task.Client.Id, link, s.task)
 	if err != nil {
 	if err != nil {
 		logs.Warn("get connection from client id %d  error %s", s.task.Client.Id, err.Error())
 		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 (
 import (
 	"errors"
 	"errors"
+	"github.com/cnlh/nps/lib/version"
 	"math"
 	"math"
 	"os"
 	"os"
 	"strconv"
 	"strconv"
@@ -271,8 +272,9 @@ func GetClientList(start, length int, search, sort, order string, clientId int)
 func dealClientData() {
 func dealClientData() {
 	file.GetDb().JsonDb.Clients.Range(func(key, value interface{}) bool {
 	file.GetDb().JsonDb.Clients.Range(func(key, value interface{}) bool {
 		v := value.(*file.Client)
 		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.IsConnect = true
+			v.Version = vv.(*bridge.Client).Version
 		} else {
 		} else {
 			v.IsConnect = false
 			v.IsConnect = false
 		}
 		}
@@ -338,6 +340,7 @@ func DelClientConnect(clientId int) {
 
 
 func GetDashboardData() map[string]interface{} {
 func GetDashboardData() map[string]interface{} {
 	data := make(map[string]interface{})
 	data := make(map[string]interface{})
+	data["version"] = version.VERSION
 	data["hostCount"] = common.GeSynctMapLen(file.GetDb().JsonDb.Hosts)
 	data["hostCount"] = common.GeSynctMapLen(file.GetDb().JsonDb.Hosts)
 	data["clientCount"] = common.GeSynctMapLen(file.GetDb().JsonDb.Clients) - 1 //Remove the public key client
 	data["clientCount"] = common.GeSynctMapLen(file.GetDb().JsonDb.Clients) - 1 //Remove the public key client
 	dealClientData()
 	dealClientData()

+ 5 - 0
web/views/client/list.html

@@ -150,6 +150,11 @@
                 title: 'remark',//标题
                 title: 'remark',//标题
                 visible: true,//false表示不显示
                 visible: true,//false表示不显示
             },
             },
+            {
+                field: 'Version',//域值
+                title: 'version',//标题
+                visible: true,//false表示不显示
+            },
             {
             {
                 field: 'VerifyKey',//域值
                 field: 'VerifyKey',//域值
                 title: 'vkey',//标题
                 title: 'vkey',//标题

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

@@ -142,6 +142,16 @@
                                 </div>
                                 </div>
                             </div>
                             </div>
                         </li>
                         </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>
                     </ul>
                 </div>
                 </div>
             </div>
             </div>
@@ -754,4 +764,4 @@
         this.myChart7.resize();
         this.myChart7.resize();
     });
     });
 
 
-</script>
+</script>