chore: rebuild add adapter/inbound.Addition to simply Listener.New apis

This commit is contained in:
wwqgtxx
2022-12-05 00:20:50 +08:00
parent c7f83d3ff1
commit 2e22c712af
30 changed files with 290 additions and 225 deletions

View File

@ -9,12 +9,15 @@ import (
"github.com/Dreamacro/clash/transport/socks5"
)
func NewSocketWithInfos(target socks5.Addr, conn net.Conn, source C.Type, inName, specialRules string) *context.ConnContext {
// NewSocket receive TCP inbound and return ConnContext
func NewSocket(target socks5.Addr, conn net.Conn, source C.Type, additions ...Addition) *context.ConnContext {
metadata := parseSocksAddr(target)
metadata.NetWork = C.TCP
metadata.Type = source
metadata.SpecialRules = specialRules
metadata.InName = inName
for _, addition := range additions {
addition.Apply(metadata)
}
remoteAddr := conn.RemoteAddr()
// Filter when net.Addr interface is nil
@ -36,11 +39,6 @@ func NewSocketWithInfos(target socks5.Addr, conn net.Conn, source C.Type, inName
return context.NewConnContext(conn, metadata)
}
// NewSocket receive TCP inbound and return ConnContext
func NewSocket(target socks5.Addr, conn net.Conn, source C.Type) *context.ConnContext {
return NewSocketWithInfos(target, conn, source, "", "")
}
func NewInner(conn net.Conn, dst string, host string) *context.ConnContext {
metadata := &C.Metadata{}
metadata.NetWork = C.TCP