feat: update ForwardTCP method signature and usage in SOCKS5 server

This commit is contained in:
SunBK201 2025-10-28 16:05:15 +08:00
parent 0424611bc7
commit f5572ac638
2 changed files with 5 additions and 4 deletions

View File

@ -13,6 +13,7 @@ import (
type Server interface { type Server interface {
Start() error Start() error
HandleClient(net.Conn) HandleClient(net.Conn)
ForwardTCP(client, target net.Conn, destAddr string)
} }
func NewServer(cfg *config.Config, rw *rewrite.Rewriter) (Server, error) { func NewServer(cfg *config.Config, rw *rewrite.Rewriter) (Server, error) {

View File

@ -97,7 +97,7 @@ func (s *Server) HandleClient(client net.Conn) {
_ = client.Close() _ = client.Close()
return return
} }
s.forwardTCP(client, target, destAddrPort) s.ForwardTCP(client, target, destAddrPort)
} }
// socks5Auth performs a minimal "no-auth" negotiation. // socks5Auth performs a minimal "no-auth" negotiation.
@ -206,15 +206,15 @@ func (s *Server) socks5Connect(client net.Conn, destAddrPort string) (net.Conn,
return target, nil return target, nil
} }
// forwardTCP proxies traffic in both directions. // ForwardTCP proxies traffic in both directions.
// target->client uses raw copy. // target->client uses raw copy.
// client->target is processed by the rewriter (or raw if cached). // client->target is processed by the rewriter (or raw if cached).
func (s *Server) forwardTCP(client, target net.Conn, destAddrPort string) { func (s *Server) ForwardTCP(client, target net.Conn, destAddr string) {
// Server -> Client (raw) // Server -> Client (raw)
go utils.CopyHalf(client, target) go utils.CopyHalf(client, target)
// Client -> Server (rewriter) // Client -> Server (rewriter)
go utils.ProxyHalf(target, client, s.rw, destAddrPort) go utils.ProxyHalf(target, client, s.rw, destAddr)
} }
// handleUDPAssociate handles a UDP ASSOCIATE request by creating a UDP relay socket. // handleUDPAssociate handles a UDP ASSOCIATE request by creating a UDP relay socket.