Android: patch

This commit is contained in:
wwqgtxx
2023-10-23 16:50:43 +08:00
parent 79a29826a4
commit a551d7ebd9
30 changed files with 512 additions and 59 deletions

47
component/dialer/patch.go Normal file
View File

@@ -0,0 +1,47 @@
package dialer
import (
"context"
"net"
"net/netip"
"syscall"
)
type TunnelDialer func(context context.Context, network, address string) (net.Conn, error)
type SocketControl func(network, address string, conn syscall.RawConn) error
var DefaultTunnelDialer TunnelDialer
var DefaultSocketHook SocketControl
func DialTunnelContext(ctx context.Context, network, address string) (net.Conn, error) {
if dialer := DefaultTunnelDialer; dialer != nil {
return dialer(ctx, network, address)
}
return DialContext(ctx, network, address)
}
func dialContextHooked(ctx context.Context, network string, destination netip.Addr, port string) (net.Conn, error) {
dialer := &net.Dialer{
Control: DefaultSocketHook,
}
conn, err := dialer.DialContext(ctx, network, net.JoinHostPort(destination.String(), port))
if err != nil {
return nil, err
}
if t, ok := conn.(*net.TCPConn); ok {
t.SetKeepAlive(false)
}
return conn, nil
}
func listenPacketHooked(ctx context.Context, network, address string) (net.PacketConn, error) {
lc := &net.ListenConfig{
Control: DefaultSocketHook,
}
return lc.ListenPacket(ctx, network, address)
}