mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-12-02 13:26:47 +00:00
chore: reduce interface differences between gVisor and mipstack
This commit is contained in:
1 parent
7ff65441be
commit
09b0ff3c52
3 files changed
+7
-25
No files matched your search
@@ -176,11 +176,6 @@ type ipStack interface {
|
||||
Close() error
|
||||
}
|
||||
|
||||
// gVisorIPStack adapts sing-wireguard's stack device socket signatures.
|
||||
type gVisorIPStack struct {
|
||||
wireguard.Device
|
||||
}
|
||||
|
||||
type zeroTierOrbit struct {
|
||||
world uint64
|
||||
seed ZT.Address
|
||||
@@ -230,7 +225,7 @@ func newIPStack(option IPStackOption, localAddresses []netip.Prefix, mtu uint32)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &gVisorIPStack{Device: device}, nil
|
||||
return device, nil
|
||||
case ipStackMips:
|
||||
return mipstack.New(mipstack.Config{
|
||||
LocalAddresses: localAddresses,
|
||||
@@ -242,18 +237,8 @@ func newIPStack(option IPStackOption, localAddresses []netip.Prefix, mtu uint32)
|
||||
}
|
||||
}
|
||||
|
||||
// DialTCP opens one active TCP connection through gVisor.
|
||||
func (s *gVisorIPStack) DialTCP(ctx context.Context, network string, _ netip.AddrPort, destination netip.AddrPort) (net.Conn, error) {
|
||||
return s.DialContext(ctx, network, M.SocksaddrFromNetIP(destination))
|
||||
}
|
||||
|
||||
// ListenUDP opens one unconnected UDP socket through gVisor.
|
||||
func (s *gVisorIPStack) ListenUDP(ctx context.Context, _ string, local netip.AddrPort) (net.PacketConn, error) {
|
||||
return s.ListenPacket(ctx, M.SocksaddrFromNetIP(local))
|
||||
}
|
||||
|
||||
var _ ipStack = (*mipstack.Stack)(nil)
|
||||
var _ ipStack = (*gVisorIPStack)(nil)
|
||||
var _ ipStack = (wireguard.Device)(nil)
|
||||
|
||||
func (c *zeroTierPacketConn) WriteTo(packet []byte, destination net.Addr) (int, error) {
|
||||
address := M.SocksaddrFromNet(destination).Unwrap()
|
||||
@@ -1319,11 +1304,8 @@ func (z *ZeroTier) ListenPacketContext(ctx context.Context, metadata *C.Metadata
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
localAddress := netip.IPv4Unspecified()
|
||||
if metadata.DstIP.Is6() {
|
||||
localAddress = netip.IPv6Unspecified()
|
||||
}
|
||||
packetConn, err := device.ListenUDP(ctx, "udp", netip.AddrPortFrom(localAddress, 0))
|
||||
// The ipStack contract guarantees that a generic UDP wildcard supports both address families.
|
||||
packetConn, err := device.ListenUDP(ctx, "udp", netip.AddrPort{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ require (
|
||||
github.com/metacubex/sing-shadowsocks2 v0.2.7
|
||||
github.com/metacubex/sing-tun v0.4.21
|
||||
github.com/metacubex/sing-vmess v0.2.5
|
||||
github.com/metacubex/sing-wireguard v0.0.0-20260520151737-7e7c7c1b854c
|
||||
github.com/metacubex/sing-wireguard v0.0.0-20260804133520-b873d2f3e751
|
||||
github.com/metacubex/smux v0.0.0-20260105030934-d0c8756d3141
|
||||
github.com/metacubex/ssh v0.1.0
|
||||
github.com/metacubex/tailscale v0.0.0-20260727131202-3748fbaa292c
|
||||
|
||||
@@ -166,8 +166,8 @@ github.com/metacubex/sing-tun v0.4.21 h1:MjbPYytM240VH70lO182v2Sg/JthMmx6R6z6E2f
|
||||
github.com/metacubex/sing-tun v0.4.21/go.mod h1:g4I/JNplDBhXLF+aQWgFbhNeJPSXQOWS9HvLeNvkgeA=
|
||||
github.com/metacubex/sing-vmess v0.2.5 h1:m9Zt5I27lB9fmLMZfism9sH2LcnAfShZfwSkf6/KJoE=
|
||||
github.com/metacubex/sing-vmess v0.2.5/go.mod h1:AwtlzUgf8COe9tRYAKqWZ+leDH7p5U98a0ZUpYehl8Q=
|
||||
github.com/metacubex/sing-wireguard v0.0.0-20260520151737-7e7c7c1b854c h1:tH9FuQW357zp2xAGzkoZTGpNGMVmEFZov0iV5M2S5ew=
|
||||
github.com/metacubex/sing-wireguard v0.0.0-20260520151737-7e7c7c1b854c/go.mod h1:eQZDJTx+IH3k4mXqaOJ3VJ9h9ZqOl60F7TLi5wAU51Q=
|
||||
github.com/metacubex/sing-wireguard v0.0.0-20260804133520-b873d2f3e751 h1:7W3Xb1V3PFYLdLCq+0XqB/+gT1Vk/tU/ZO5CzWtrVBA=
|
||||
github.com/metacubex/sing-wireguard v0.0.0-20260804133520-b873d2f3e751/go.mod h1:eQZDJTx+IH3k4mXqaOJ3VJ9h9ZqOl60F7TLi5wAU51Q=
|
||||
github.com/metacubex/smux v0.0.0-20260105030934-d0c8756d3141 h1:DK2l6m2Fc85H2BhiAPgbJygiWhesPlfGmF+9Vw6ARdk=
|
||||
github.com/metacubex/smux v0.0.0-20260105030934-d0c8756d3141/go.mod h1:/yI4OiGOSn0SURhZdJF3CbtPg3nwK700bG8TZLMBvAg=
|
||||
github.com/metacubex/ssh v0.1.0 h1:iGfr99qk/eMHzUnQ/0bTxXT8+8SWqLSHBWDHoAhngzw=
|
||||
|
||||
Reference in new issue
Block a user