chore: decrease direct depend on the sing package

This commit is contained in:
wwqgtxx
2023-01-16 10:50:31 +08:00
parent 643fdd0bce
commit 50832aab47
10 changed files with 108 additions and 73 deletions

View File

@ -7,12 +7,11 @@ import (
"net"
"strings"
N "github.com/Dreamacro/clash/common/net"
"github.com/Dreamacro/clash/component/dialer"
C "github.com/Dreamacro/clash/constant"
"github.com/gofrs/uuid"
"github.com/sagernet/sing/common/bufio"
"github.com/sagernet/sing/common/network"
)
type Base struct {
@ -169,7 +168,7 @@ func NewBase(opt BaseOption) *Base {
}
type conn struct {
network.ExtendedConn
N.ExtendedConn
chain C.Chain
actualRemoteDestination string
}
@ -189,14 +188,14 @@ func (c *conn) AppendToChains(a C.ProxyAdapter) {
}
func (c *conn) Upstream() any {
if wrapper, ok := c.ExtendedConn.(*bufio.ExtendedConnWrapper); ok {
if wrapper, ok := c.ExtendedConn.(*N.ExtendedConnWrapper); ok {
return wrapper.Conn
}
return c.ExtendedConn
}
func NewConn(c net.Conn, a C.ProxyAdapter) C.Conn {
return &conn{bufio.NewExtendedConn(c), []string{a.Name()}, parseRemoteDestination(a.Addr())}
return &conn{N.NewExtendedConn(c), []string{a.Name()}, parseRemoteDestination(a.Addr())}
}
type packetConn struct {

View File

@ -8,14 +8,13 @@ import (
"net/http"
"strconv"
N "github.com/Dreamacro/clash/common/net"
"github.com/Dreamacro/clash/component/dialer"
tlsC "github.com/Dreamacro/clash/component/tls"
C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/transport/gun"
"github.com/Dreamacro/clash/transport/trojan"
"github.com/Dreamacro/clash/transport/vless"
"github.com/sagernet/sing/common/bufio"
)
type Trojan struct {
@ -97,7 +96,7 @@ func (t *Trojan) StreamConn(c net.Conn, metadata *C.Metadata) (net.Conn, error)
return c, err
}
err = t.instance.WriteHeader(c, trojan.CommandTCP, serializesSocksAddr(metadata))
return bufio.NewExtendedConn(c), err
return N.NewExtendedConn(c), err
}
// DialContext implements C.ProxyAdapter