mirror of
https://github.com/ehang-io/nps.git
synced 2025-09-01 10:56:53 +00:00
New functions
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
"errors"
|
||||
"github.com/cnlh/nps/lib/common"
|
||||
"github.com/cnlh/nps/lib/config"
|
||||
"github.com/cnlh/nps/lib/crypt"
|
||||
"github.com/cnlh/nps/lib/file"
|
||||
"github.com/cnlh/nps/lib/pool"
|
||||
"github.com/cnlh/nps/lib/rate"
|
||||
@@ -347,7 +346,7 @@ func (s *Conn) GetConfigInfo() (c *file.Client, err error) {
|
||||
return
|
||||
} else {
|
||||
arr := strings.Split(string(b), common.CONN_DATA_SEQ)
|
||||
c = file.NewClient(crypt.GetRandomString(16), true, false)
|
||||
c = file.NewClient("", true, false)
|
||||
c.Cnf.U = arr[0]
|
||||
c.Cnf.P = arr[1]
|
||||
c.Cnf.Crypt = common.GetBoolByStr(arr[2])
|
||||
|
@@ -35,6 +35,7 @@ type Link struct {
|
||||
MsgCh chan []byte
|
||||
MsgConn *Conn
|
||||
StatusCh chan bool
|
||||
FinishUse bool
|
||||
}
|
||||
|
||||
func NewLink(id int, connType string, host string, en, de int, crypt bool, c *Conn, flow *file.Flow, udpListener *net.UDPConn, rate *rate.Rate, UdpRemoteAddr *net.UDPAddr) *Link {
|
||||
@@ -61,6 +62,7 @@ func (s *Link) Run(flow bool) {
|
||||
select {
|
||||
case content := <-s.MsgCh:
|
||||
if len(content) == len(common.IO_EOF) && string(content) == common.IO_EOF {
|
||||
s.FinishUse = true
|
||||
if s.Conn != nil {
|
||||
s.Conn.Close()
|
||||
}
|
||||
@@ -81,8 +83,8 @@ func (s *Link) Run(flow bool) {
|
||||
return
|
||||
}
|
||||
s.MsgConn.WriteWriteSuccess(s.Id)
|
||||
pool.PutBufPoolCopy(content)
|
||||
}
|
||||
pool.PutBufPoolCopy(content)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
@@ -372,7 +372,19 @@ func (s *Csv) DelClient(id int) error {
|
||||
return errors.New("不存在")
|
||||
}
|
||||
|
||||
func (s *Csv) NewClient(c *Client) {
|
||||
func (s *Csv) NewClient(c *Client) error {
|
||||
var isNotSet bool
|
||||
reset:
|
||||
if c.VerifyKey == "" || isNotSet {
|
||||
isNotSet = true
|
||||
c.VerifyKey = crypt.GetRandomString(16)
|
||||
}
|
||||
if !s.VerifyVkey(c.VerifyKey, c.id) {
|
||||
if isNotSet {
|
||||
goto reset
|
||||
}
|
||||
return errors.New("Vkey duplicate, please reset")
|
||||
}
|
||||
if c.Id == 0 {
|
||||
c.Id = s.GetClientId()
|
||||
}
|
||||
@@ -383,6 +395,16 @@ func (s *Csv) NewClient(c *Client) {
|
||||
defer s.Unlock()
|
||||
s.Clients = append(s.Clients, c)
|
||||
s.StoreClientsToCsv()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Csv) VerifyVkey(vkey string, id int) bool {
|
||||
for _, v := range s.Clients {
|
||||
if v.VerifyKey == vkey && v.Id != id {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *Csv) GetClientId() int {
|
||||
|
@@ -2,6 +2,7 @@ package file
|
||||
|
||||
import (
|
||||
"github.com/cnlh/nps/lib/rate"
|
||||
"math"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
@@ -60,6 +61,9 @@ func NewClient(vKey string, noStore bool, noDisplay bool) *Client {
|
||||
func (s *Client) GetId() int {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
if s.id == math.MaxInt32 {
|
||||
s.id = 0
|
||||
}
|
||||
s.id++
|
||||
return s.id
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package version
|
||||
|
||||
const VERSION = "0.0.16"
|
||||
const VERSION_OK = "vrok"
|
||||
|
||||
func GetVersion() string {
|
||||
return VERSION
|
||||
|
Reference in New Issue
Block a user