mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-07-17 05:11:05 +03:00
Remove unused fakeip packet conn
This commit is contained in:
2
go.mod
2
go.mod
@@ -26,7 +26,7 @@ require (
|
|||||||
github.com/sagernet/gvisor v0.0.0-20231209105102-8d27a30e436e
|
github.com/sagernet/gvisor v0.0.0-20231209105102-8d27a30e436e
|
||||||
github.com/sagernet/quic-go v0.40.1
|
github.com/sagernet/quic-go v0.40.1
|
||||||
github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691
|
github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691
|
||||||
github.com/sagernet/sing v0.4.0-beta.12
|
github.com/sagernet/sing v0.4.0-beta.14
|
||||||
github.com/sagernet/sing-dns v0.1.14
|
github.com/sagernet/sing-dns v0.1.14
|
||||||
github.com/sagernet/sing-mux v0.2.0
|
github.com/sagernet/sing-mux v0.2.0
|
||||||
github.com/sagernet/sing-quic v0.1.11
|
github.com/sagernet/sing-quic v0.1.11
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -106,8 +106,8 @@ github.com/sagernet/quic-go v0.40.1/go.mod h1:CcKTpzTAISxrM4PA5M20/wYuz9Tj6Tx4Dw
|
|||||||
github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691 h1:5Th31OC6yj8byLGkEnIYp6grlXfo1QYUfiYFGjewIdc=
|
github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691 h1:5Th31OC6yj8byLGkEnIYp6grlXfo1QYUfiYFGjewIdc=
|
||||||
github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691/go.mod h1:B8lp4WkQ1PwNnrVMM6KyuFR20pU8jYBD+A4EhJovEXU=
|
github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691/go.mod h1:B8lp4WkQ1PwNnrVMM6KyuFR20pU8jYBD+A4EhJovEXU=
|
||||||
github.com/sagernet/sing v0.2.18/go.mod h1:OL6k2F0vHmEzXz2KW19qQzu172FDgSbUSODylighuVo=
|
github.com/sagernet/sing v0.2.18/go.mod h1:OL6k2F0vHmEzXz2KW19qQzu172FDgSbUSODylighuVo=
|
||||||
github.com/sagernet/sing v0.4.0-beta.12 h1:f0f8DBPNf91NoAnJWm25LjPy/rC6u0R/nWIsGysl1cc=
|
github.com/sagernet/sing v0.4.0-beta.14 h1:9I1gWUUOguwfjv1KVdSNZFXARMSk5RsUHH49C2E9GIc=
|
||||||
github.com/sagernet/sing v0.4.0-beta.12/go.mod h1:+60H3Cm91RnL9dpVGWDPHt0zTQImO9Vfqt9a4rSambI=
|
github.com/sagernet/sing v0.4.0-beta.14/go.mod h1:+60H3Cm91RnL9dpVGWDPHt0zTQImO9Vfqt9a4rSambI=
|
||||||
github.com/sagernet/sing-dns v0.1.14 h1:kxE/Ik3jMXmD3sXsdt9MgrNzLFWt64mghV+MQqzyf40=
|
github.com/sagernet/sing-dns v0.1.14 h1:kxE/Ik3jMXmD3sXsdt9MgrNzLFWt64mghV+MQqzyf40=
|
||||||
github.com/sagernet/sing-dns v0.1.14/go.mod h1:AA+vZMNovuPN5i/sPnfF6756Nq94nzb5nXodMWbta5w=
|
github.com/sagernet/sing-dns v0.1.14/go.mod h1:AA+vZMNovuPN5i/sPnfF6756Nq94nzb5nXodMWbta5w=
|
||||||
github.com/sagernet/sing-mux v0.2.0 h1:4C+vd8HztJCWNYfufvgL49xaOoOHXty2+EAjnzN3IYo=
|
github.com/sagernet/sing-mux v0.2.0 h1:4C+vd8HztJCWNYfufvgL49xaOoOHXty2+EAjnzN3IYo=
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
package fakeip
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/sagernet/sing/common/buf"
|
|
||||||
M "github.com/sagernet/sing/common/metadata"
|
|
||||||
N "github.com/sagernet/sing/common/network"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ N.PacketConn = (*NATPacketConn)(nil)
|
|
||||||
|
|
||||||
type NATPacketConn struct {
|
|
||||||
N.PacketConn
|
|
||||||
origin M.Socksaddr
|
|
||||||
destination M.Socksaddr
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewNATPacketConn(conn N.PacketConn, origin M.Socksaddr, destination M.Socksaddr) *NATPacketConn {
|
|
||||||
return &NATPacketConn{
|
|
||||||
PacketConn: conn,
|
|
||||||
origin: socksaddrWithoutPort(origin),
|
|
||||||
destination: socksaddrWithoutPort(destination),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *NATPacketConn) ReadPacket(buffer *buf.Buffer) (destination M.Socksaddr, err error) {
|
|
||||||
destination, err = c.PacketConn.ReadPacket(buffer)
|
|
||||||
if socksaddrWithoutPort(destination) == c.origin {
|
|
||||||
destination = M.Socksaddr{
|
|
||||||
Addr: c.destination.Addr,
|
|
||||||
Fqdn: c.destination.Fqdn,
|
|
||||||
Port: destination.Port,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *NATPacketConn) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error {
|
|
||||||
if socksaddrWithoutPort(destination) == c.destination {
|
|
||||||
destination = M.Socksaddr{
|
|
||||||
Addr: c.origin.Addr,
|
|
||||||
Fqdn: c.origin.Fqdn,
|
|
||||||
Port: destination.Port,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return c.PacketConn.WritePacket(buffer, destination)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *NATPacketConn) Upstream() any {
|
|
||||||
return c.PacketConn
|
|
||||||
}
|
|
||||||
|
|
||||||
func socksaddrWithoutPort(destination M.Socksaddr) M.Socksaddr {
|
|
||||||
destination.Port = 0
|
|
||||||
return destination
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
package fakeip
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/sagernet/sing/common/buf"
|
|
||||||
"github.com/sagernet/sing/common/bufio"
|
|
||||||
M "github.com/sagernet/sing/common/metadata"
|
|
||||||
N "github.com/sagernet/sing/common/network"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (c *NATPacketConn) CreatePacketReadWaiter() (N.PacketReadWaiter, bool) {
|
|
||||||
waiter, created := bufio.CreatePacketReadWaiter(c.PacketConn)
|
|
||||||
if !created {
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
return &waitNATPacketConn{c, waiter}, true
|
|
||||||
}
|
|
||||||
|
|
||||||
type waitNATPacketConn struct {
|
|
||||||
*NATPacketConn
|
|
||||||
readWaiter N.PacketReadWaiter
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *waitNATPacketConn) InitializeReadWaiter(options N.ReadWaitOptions) (needCopy bool) {
|
|
||||||
return c.readWaiter.InitializeReadWaiter(options)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *waitNATPacketConn) WaitReadPacket() (buffer *buf.Buffer, destination M.Socksaddr, err error) {
|
|
||||||
buffer, destination, err = c.readWaiter.WaitReadPacket()
|
|
||||||
if err == nil && socksaddrWithoutPort(destination) == c.origin {
|
|
||||||
destination = M.Socksaddr{
|
|
||||||
Addr: c.destination.Addr,
|
|
||||||
Fqdn: c.destination.Fqdn,
|
|
||||||
Port: destination.Port,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user