chore: decrease goroutine used in core tunnel

This commit is contained in:
wwqgtxx
2023-09-28 18:59:31 +08:00
parent 21fb5f75b8
commit e0458a8fde
42 changed files with 252 additions and 269 deletions

View File

@ -30,7 +30,7 @@ func (l *Listener) Close() error {
return l.listener.Close()
}
func New(addr string, in chan<- C.ConnContext, additions ...inbound.Addition) (*Listener, error) {
func New(addr string, tunnel C.Tunnel, additions ...inbound.Addition) (*Listener, error) {
if len(additions) == 0 {
additions = []inbound.Addition{
inbound.WithInName("DEFAULT-REDIR"),
@ -55,18 +55,19 @@ func New(addr string, in chan<- C.ConnContext, additions ...inbound.Addition) (*
}
continue
}
go handleRedir(c, in, additions...)
go handleRedir(c, tunnel, additions...)
}
}()
return rl, nil
}
func handleRedir(conn net.Conn, in chan<- C.ConnContext, additions ...inbound.Addition) {
func handleRedir(conn net.Conn, tunnel C.Tunnel, additions ...inbound.Addition) {
target, err := parserPacket(conn)
if err != nil {
conn.Close()
return
}
N.TCPKeepAlive(conn)
in <- inbound.NewSocket(target, conn, C.REDIR, additions...)
tunnel.HandleTCPConn(inbound.NewSocket(target, conn, C.REDIR, additions...))
}