mirror of
https://github.com/ehang-io/nps.git
synced 2025-08-31 17:56:56 +00:00
New functions
This commit is contained in:
@@ -38,6 +38,7 @@ func NewRPClient(svraddr string, vKey string, bridgeConnType string, proxyUrl st
|
||||
|
||||
//start
|
||||
func (s *TRPClient) Start() {
|
||||
go s.linkCleanSession()
|
||||
retry:
|
||||
c, err := NewConn(s.bridgeConnType, s.vKey, s.svrAddr, common.WORK_MAIN, s.proxyUrl)
|
||||
if err != nil {
|
||||
@@ -129,7 +130,6 @@ func (s *TRPClient) linkProcess(link *conn.Link, c *conn.Conn) {
|
||||
}
|
||||
pool.PutBufPoolCopy(buf)
|
||||
s.Lock()
|
||||
//TODO 删除map
|
||||
s.Unlock()
|
||||
}
|
||||
|
||||
@@ -188,3 +188,19 @@ func (s *TRPClient) dealChan() {
|
||||
}()
|
||||
<-s.stop
|
||||
}
|
||||
|
||||
func (s *TRPClient) linkCleanSession() {
|
||||
ticker := time.NewTicker(time.Minute * 5)
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
s.Lock()
|
||||
for _, v := range s.linkMap {
|
||||
if v.FinishUse {
|
||||
delete(s.linkMap, v.Id)
|
||||
}
|
||||
}
|
||||
s.Unlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"github.com/cnlh/nps/lib/common"
|
||||
"github.com/cnlh/nps/lib/config"
|
||||
@@ -54,6 +53,9 @@ func GetTaskStatus(path string) {
|
||||
}
|
||||
for _, v := range cnf.Tasks {
|
||||
ports := common.GetPorts(v.Ports)
|
||||
if v.Mode == "secretServer" {
|
||||
ports = append(ports, 0)
|
||||
}
|
||||
for _, vv := range ports {
|
||||
var remark string
|
||||
if len(ports) > 1 {
|
||||
@@ -102,6 +104,10 @@ re:
|
||||
logs.Error(err)
|
||||
goto re
|
||||
}
|
||||
if !c.GetAddStatus() {
|
||||
logs.Error(errAdd)
|
||||
goto re
|
||||
}
|
||||
var b []byte
|
||||
if b, err = c.ReadLen(16); err != nil {
|
||||
logs.Error(err)
|
||||
@@ -109,11 +115,6 @@ re:
|
||||
} else {
|
||||
ioutil.WriteFile(filepath.Join(common.GetTmpPath(), "npc_vkey.txt"), []byte(string(b)), 0600)
|
||||
}
|
||||
if !c.GetAddStatus() {
|
||||
logs.Error(errAdd)
|
||||
goto re
|
||||
}
|
||||
|
||||
for _, v := range cnf.Hosts {
|
||||
if _, err := c.SendHostInfo(v); err != nil {
|
||||
logs.Error(err)
|
||||
@@ -171,15 +172,13 @@ func NewConn(tp string, vkey string, server string, connType string, proxyUrl st
|
||||
return nil, err
|
||||
}
|
||||
c := conn.NewConn(connection)
|
||||
if b, err := c.ReadLen(32); err != nil {
|
||||
if _, err := c.Write([]byte(crypt.Md5(version.GetVersion()))); err != nil {
|
||||
logs.Error(err)
|
||||
os.Exit(0)
|
||||
} else if crypt.Md5(version.GetVersion()) != string(b) {
|
||||
}
|
||||
if b, err := c.ReadLen(32); err != nil || crypt.Md5(version.GetVersion()) != string(b) {
|
||||
logs.Error("The client does not match the server version. The current version of the client is", version.GetVersion())
|
||||
os.Exit(0)
|
||||
} else if binary.Write(c, binary.LittleEndian, []byte(version.VERSION_OK)); err != nil {
|
||||
logs.Error(err)
|
||||
os.Exit(0)
|
||||
}
|
||||
if _, err := c.Write([]byte(common.Getverifyval(vkey))); err != nil {
|
||||
logs.Error(err)
|
||||
|
Reference in New Issue
Block a user