mirror of
https://github.com/ehang-io/nps.git
synced 2025-09-02 03:16:53 +00:00
File mode|pubVkey optimization
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/cnlh/nps/lib/common"
|
||||
"github.com/cnlh/nps/lib/conn"
|
||||
"github.com/cnlh/nps/lib/file"
|
||||
"github.com/cnlh/nps/vender/github.com/astaxie/beego/logs"
|
||||
"net"
|
||||
"net/http"
|
||||
"sync"
|
||||
@@ -74,13 +75,17 @@ func (s *BaseServer) checkFlow() error {
|
||||
func (s *BaseServer) DealClient(c *conn.Conn, addr string, rb []byte, tp string) error {
|
||||
link := conn.NewLink(tp, addr, s.task.Client.Cnf.Crypt, s.task.Client.Cnf.Compress, c.Conn.RemoteAddr().String())
|
||||
|
||||
if target, err := s.bridge.SendLinkInfo(s.task.Client.Id, link, c.Conn.RemoteAddr().String()); err != nil {
|
||||
if target, err := s.bridge.SendLinkInfo(s.task.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, s.task.Client.Id, err.Error())
|
||||
c.Close()
|
||||
return err
|
||||
} else {
|
||||
if rb != nil {
|
||||
target.Write(rb)
|
||||
}
|
||||
conn.CopyWaitGroup(target, c, link.Crypt, link.Compress, s.task.Client.Rate, s.task.Client.Flow)
|
||||
}
|
||||
|
||||
|
||||
s.task.Client.AddConn()
|
||||
return nil
|
||||
}
|
||||
|
@@ -147,7 +147,7 @@ func (s *httpServer) process(c *conn.Conn, r *http.Request) {
|
||||
break
|
||||
}
|
||||
lk := conn.NewLink(common.CONN_TCP, host.Target, host.Client.Cnf.Crypt, host.Client.Cnf.Compress, r.RemoteAddr)
|
||||
if target, err = s.bridge.SendLinkInfo(host.Client.Id, lk, c.Conn.RemoteAddr().String()); err != nil {
|
||||
if target, err = s.bridge.SendLinkInfo(host.Client.Id, lk, c.Conn.RemoteAddr().String(), nil); err != nil {
|
||||
logs.Notice("connect to target %s error %s", lk.Host, err)
|
||||
break
|
||||
}
|
||||
|
@@ -144,7 +144,7 @@ func (s *Sock5ModeServer) doConnect(c net.Conn, command uint8) {
|
||||
//s.DealClient(conn.NewConn(c), addr, nil, ltype)
|
||||
link := conn.NewLink(ltype, addr, s.task.Client.Cnf.Crypt, s.task.Client.Cnf.Compress, c.RemoteAddr().String())
|
||||
|
||||
if target, err := s.bridge.SendLinkInfo(s.task.Client.Id, link, c.RemoteAddr().String()); err != nil {
|
||||
if target, err := s.bridge.SendLinkInfo(s.task.Client.Id, link, c.RemoteAddr().String(),s.task); err != nil {
|
||||
c.Close()
|
||||
return
|
||||
} else {
|
||||
|
@@ -50,7 +50,7 @@ func (s *UdpModeServer) process(addr *net.UDPAddr, data []byte) {
|
||||
if err := s.checkFlow(); err != nil {
|
||||
return
|
||||
}
|
||||
if target, err := s.bridge.SendLinkInfo(s.task.Client.Id, link, addr.String()); err != nil {
|
||||
if target, err := s.bridge.SendLinkInfo(s.task.Client.Id, link, addr.String(), s.task); err != nil {
|
||||
return
|
||||
} else {
|
||||
s.task.Flow.Add(int64(len(data)), 0)
|
||||
|
@@ -79,7 +79,7 @@ func DealBridgeTask() {
|
||||
func StartNewServer(bridgePort int, cnf *file.Tunnel, bridgeType string) {
|
||||
Bridge = bridge.NewTunnel(bridgePort, bridgeType, common.GetBoolByStr(beego.AppConfig.String("ipLimit")), RunList)
|
||||
if err := Bridge.StartTunnel(); err != nil {
|
||||
logs.Error("服务端开启失败", err)
|
||||
logs.Error("start server bridge error", err)
|
||||
os.Exit(0)
|
||||
} else {
|
||||
logs.Info("Server startup, the bridge type is %s, the bridge port is %d", bridgeType, bridgePort)
|
||||
@@ -103,7 +103,7 @@ func StartNewServer(bridgePort int, cnf *file.Tunnel, bridgeType string) {
|
||||
func NewMode(Bridge *bridge.Bridge, c *file.Tunnel) proxy.Service {
|
||||
var service proxy.Service
|
||||
switch c.Mode {
|
||||
case "tcp":
|
||||
case "tcp", "file":
|
||||
service = proxy.NewTunnelModeServer(proxy.ProcessTunnel, Bridge, c)
|
||||
case "socks5":
|
||||
service = proxy.NewSock5ModeServer(Bridge, c)
|
||||
@@ -134,6 +134,7 @@ func StopServer(id int) error {
|
||||
if err := svr.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
logs.Info("stop server id %d", id)
|
||||
}
|
||||
if t, err := file.GetCsvDb().GetTask(id); err != nil {
|
||||
return err
|
||||
@@ -144,7 +145,7 @@ func StopServer(id int) error {
|
||||
delete(RunList, id)
|
||||
return nil
|
||||
}
|
||||
return errors.New("未在运行中")
|
||||
return errors.New("task is not running")
|
||||
}
|
||||
|
||||
//add task
|
||||
|
Reference in New Issue
Block a user