mirror of
https://github.com/ehang-io/nps.git
synced 2026-10-28 02:42:13 +08:00
Bug修复+流量限制+带宽限制
This commit is contained in:
+17
-5
@@ -3,6 +3,7 @@ package server
|
||||
import (
|
||||
"bufio"
|
||||
"github.com/cnlh/easyProxy/utils"
|
||||
"github.com/pkg/errors"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
@@ -13,11 +14,19 @@ type process func(c *utils.Conn, s *TunnelModeServer) error
|
||||
|
||||
//tcp隧道模式
|
||||
func ProcessTunnel(c *utils.Conn, s *TunnelModeServer) error {
|
||||
if !s.ResetConfig() {
|
||||
c.Close()
|
||||
return errors.New("流量超出")
|
||||
}
|
||||
return s.dealClient(c, s.config, s.task.Target, "", nil)
|
||||
}
|
||||
|
||||
//http代理模式
|
||||
func ProcessHttp(c *utils.Conn, s *TunnelModeServer) error {
|
||||
if !s.ResetConfig() {
|
||||
c.Close()
|
||||
return errors.New("流量超出")
|
||||
}
|
||||
method, addr, rb, err, r := c.GetHost()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
@@ -49,9 +58,12 @@ func ProcessHost(c *utils.Conn, s *TunnelModeServer) error {
|
||||
log.Printf("the host %s is not found !", r.Host)
|
||||
break
|
||||
}
|
||||
|
||||
//流量限制
|
||||
if host.Client.Flow.FlowLimit > 0 && (host.Client.Flow.FlowLimit<<20) < (host.Client.Flow.ExportFlow+host.Client.Flow.InletFlow) {
|
||||
break
|
||||
}
|
||||
host.Client.Cnf.CompressDecode, host.Client.Cnf.CompressEncode = utils.GetCompressType(host.Client.Cnf.Compress)
|
||||
|
||||
//权限控制
|
||||
if err = s.auth(r, c, host.Client.Cnf.U, host.Client.Cnf.P); err != nil {
|
||||
break
|
||||
}
|
||||
@@ -65,7 +77,7 @@ func ProcessHost(c *utils.Conn, s *TunnelModeServer) error {
|
||||
} else {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
out, _ := utils.Relay(c.Conn, link.Conn, host.Client.Cnf.CompressDecode, host.Client.Cnf.Crypt, host.Client.Cnf.Mux)
|
||||
out, _ := utils.Relay(c.Conn, link.Conn, host.Client.Cnf.CompressDecode, host.Client.Cnf.Crypt, host.Client.Cnf.Mux, host.Client.Rate)
|
||||
wg.Done()
|
||||
s.FlowAddHost(host, 0, out)
|
||||
}()
|
||||
@@ -79,13 +91,13 @@ func ProcessHost(c *utils.Conn, s *TunnelModeServer) error {
|
||||
break
|
||||
}
|
||||
s.FlowAddHost(host, int64(len(b)), 0)
|
||||
if _, err := link.WriteTo(b, host.Client.Cnf.CompressEncode, host.Client.Cnf.Crypt); err != nil {
|
||||
if _, err := link.WriteTo(b, host.Client.Cnf.CompressEncode, host.Client.Cnf.Crypt, host.Client.Rate); err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
wg.Wait()
|
||||
if host != nil && host.Client.Cnf != nil && host.Client.Cnf.Mux && link != nil {
|
||||
link.WriteTo([]byte(utils.IO_EOF), host.Client.Cnf.CompressEncode, host.Client.Cnf.Crypt)
|
||||
link.WriteTo([]byte(utils.IO_EOF), host.Client.Cnf.CompressEncode, host.Client.Cnf.Crypt, host.Client.Rate)
|
||||
s.bridge.ReturnTunnel(link, host.Client.Id)
|
||||
} else if link != nil {
|
||||
link.Close()
|
||||
|
||||
Reference in New Issue
Block a user