diff --git a/adapter/outbound/patch.go b/adapter/outbound/patch.go deleted file mode 100644 index 1a52f191..00000000 --- a/adapter/outbound/patch.go +++ /dev/null @@ -1,7 +0,0 @@ -package outbound - -import "net" - -func (c *conn) RawConn() (net.Conn, bool) { - return c.ExtendedConn, true -} diff --git a/common/net/patch.go b/common/net/patch.go deleted file mode 100644 index 512ec1bd..00000000 --- a/common/net/patch.go +++ /dev/null @@ -1,11 +0,0 @@ -package net - -import "net" - -func (c *BufferedConn) RawConn() (net.Conn, bool) { - if c.r.Buffered() == 0 { - return c.ExtendedConn, true - } - - return nil, false -} diff --git a/constant/patch.go b/constant/patch.go deleted file mode 100644 index 3b5daa4c..00000000 --- a/constant/patch.go +++ /dev/null @@ -1,11 +0,0 @@ -package constant - -import "net" - -type WrappedConn interface { - RawConn() (net.Conn, bool) -} - -type WrappedPacketConn interface { - RawPacketConn() (net.PacketConn, bool) -} diff --git a/context/patch.go b/context/patch.go deleted file mode 100644 index 39471a2b..00000000 --- a/context/patch.go +++ /dev/null @@ -1,7 +0,0 @@ -package context - -import "net" - -func (c *ConnContext) RawConn() (net.Conn, bool) { - return c.conn, true -} diff --git a/tunnel/connection.go b/tunnel/connection.go index 475e05fd..9fc4f405 100644 --- a/tunnel/connection.go +++ b/tunnel/connection.go @@ -83,11 +83,5 @@ func closeAllLocalCoon(lAddr string) { } func handleSocket(ctx C.ConnContext, outbound net.Conn) { - left := unwrap(ctx.Conn()) - right := unwrap(outbound) - - if relayHijack(left, right) { - return - } N.Relay(ctx.Conn(), outbound) } diff --git a/tunnel/patch.go b/tunnel/patch.go deleted file mode 100644 index f4021544..00000000 --- a/tunnel/patch.go +++ /dev/null @@ -1,73 +0,0 @@ -package tunnel - -import ( - "net" - - C "github.com/Dreamacro/clash/constant" -) - -func relayHijack(left net.Conn, right net.Conn) bool { - var l *net.TCPConn - var r *net.TCPConn - var ok bool - - if l, ok = left.(*net.TCPConn); !ok { - return false - } - - if r, ok = right.(*net.TCPConn); !ok { - return false - } - - closed := make(chan struct{}) - - go func() { - defer close(closed) - - r.ReadFrom(l) - r.Close() - }() - - l.ReadFrom(r) - l.Close() - - <-closed - - return true -} - -func unwrap(conn net.Conn) net.Conn { - r := conn - - for { - w, ok := r.(C.WrappedConn) - if !ok { - break - } - rc, ok := w.RawConn() - if !ok { - break - } - r = rc - } - - return r -} - -func unwrapPacket(conn net.PacketConn) net.PacketConn { - r := conn - - for { - w, ok := r.(C.WrappedPacketConn) - if !ok { - break - } - rc, ok := w.RawPacketConn() - if !ok { - break - } - r = rc - } - - return r -} diff --git a/tunnel/statistic/patch.go b/tunnel/statistic/patch.go index 9768bde4..c1e345fd 100644 --- a/tunnel/statistic/patch.go +++ b/tunnel/statistic/patch.go @@ -1,25 +1,5 @@ package statistic -import ( - "net" -) - func (m *Manager) Total() (up, down int64) { return m.uploadTotal.Load(), m.downloadTotal.Load() } - -func (tt *tcpTracker) RawConn() (net.Conn, bool) { - if tt.Chain.Last() == "DIRECT" { - return tt.Conn, true - } - - return nil, false -} - -func (ut *udpTracker) RawPacketConn() (net.PacketConn, bool) { - if ut.Chain.Last() == "DIRECT" { - return ut.PacketConn, true - } - - return nil, false -}