mirror of
https://github.com/ehang-io/nps.git
synced 2025-09-02 11:56:53 +00:00
Code optimization
This commit is contained in:
@@ -64,17 +64,19 @@ func (s *BaseServer) auth(r *http.Request, c *conn.Conn, u, p string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *BaseServer) checkFlow() error {
|
||||
if s.task.Client.Flow.FlowLimit > 0 && (s.task.Client.Flow.FlowLimit<<20) < (s.task.Client.Flow.ExportFlow+s.task.Client.Flow.InletFlow) {
|
||||
func (s *BaseServer) CheckFlowAndConnNum(client *file.Client) error {
|
||||
if client.Flow.FlowLimit > 0 && (client.Flow.FlowLimit<<20) < (client.Flow.ExportFlow+client.Flow.InletFlow) {
|
||||
return errors.New("Traffic exceeded")
|
||||
}
|
||||
if !client.GetConn() {
|
||||
return errors.New("Connections exceed the current client limit")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//与客户端建立通道
|
||||
func (s *BaseServer) DealClient(c *conn.Conn, client *file.Client, addr string, rb []byte, tp string) error {
|
||||
func (s *BaseServer) DealClient(c *conn.Conn, client *file.Client, addr string, rb []byte, tp string, f func()) error {
|
||||
link := conn.NewLink(tp, addr, client.Cnf.Crypt, client.Cnf.Compress, c.Conn.RemoteAddr().String())
|
||||
|
||||
if target, err := s.bridge.SendLinkInfo(client.Id, link, c.Conn.RemoteAddr().String(), s.task); err != nil {
|
||||
logs.Warn("task id %d get connection from client id %d error %s", s.task.Id, client.Id, err.Error())
|
||||
c.Close()
|
||||
@@ -84,9 +86,11 @@ func (s *BaseServer) DealClient(c *conn.Conn, client *file.Client, addr string,
|
||||
//HTTP proxy crypt or compress
|
||||
conn.GetConn(target, link.Crypt, link.Compress, client.Rate, true).Write(rb)
|
||||
}
|
||||
if f != nil {
|
||||
f()
|
||||
}
|
||||
conn.CopyWaitGroup(target, c.Conn, link.Crypt, link.Compress, client.Rate, s.task.Flow, true)
|
||||
}
|
||||
|
||||
client.AddConn()
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user