Documentation
¶
Index ¶
- func ClearSocketProtector()
- func DialProtected(network, address string) (net.Conn, error)
- func DialProtectedContext(ctx context.Context, network, address string) (net.Conn, error)
- func DialUDPProtected(network string, laddr, raddr *net.UDPAddr) (*net.UDPConn, error)
- func GetProtectedDialer() net.Dialer
- func IsProtectorSet() bool
- func SetSocketProtector(protector SocketProtector)
- type CachedResolver
- type SocketProtector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClearSocketProtector ¶ added in v0.3.5
func ClearSocketProtector()
ClearSocketProtector clears the global socket protector. This should only be used for testing or when shutting down.
func DialProtected ¶ added in v0.3.5
DialProtected dials to the address using the protected dialer (no context).
func DialProtectedContext ¶ added in v0.3.5
DialProtectedContext dials to the address using the protected dialer. This is the main entry point for all protected network connections.
func DialUDPProtected ¶ added in v0.3.5
DialUDPProtected creates a protected UDP connection. This is specifically for MTP and other UDP-based protocols.
func GetProtectedDialer ¶ added in v0.3.5
GetProtectedDialer returns the global protected dialer. If no protector is set, returns a standard net.Dialer.
func IsProtectorSet ¶ added in v0.3.5
func IsProtectorSet() bool
IsProtectorSet returns true if a socket protector has been configured. This can be used to check if running under Android VpnService.
func SetSocketProtector ¶ added in v0.3.5
func SetSocketProtector(protector SocketProtector)
SetSocketProtector sets the global socket protector callback. This should be called by the Android app before making any network connections. The protector function will be called with the socket fd before each dial.
Types ¶
type CachedResolver ¶
type CachedResolver struct {
// contains filtered or unexported fields
}
CachedResolver provides DNS resolution with an in-memory cache and custom upstream DNS.
func NewCachedResolver ¶
func NewCachedResolver(nameserver string, ttl time.Duration) *CachedResolver
NewCachedResolver creates a new resolver. If nameserver is empty, it uses the system default. Example nameserver: "1.1.1.1:53"
func (*CachedResolver) DialContext ¶
func (r *CachedResolver) DialContext(ctx context.Context, network, address string) (net.Conn, error)
DialContext acts like net.DialContext but uses the cache for DNS resolution. It resolves the hostname and dials the first available IP. Uses protected dialer when running under Android VpnService.
func (*CachedResolver) ResolveIPAddr ¶
ResolveIPAddr caches and resolves a host to its IP addresses.
func (*CachedResolver) ResolveUDPAddr ¶
func (r *CachedResolver) ResolveUDPAddr(network, address string) (*net.UDPAddr, error)
ResolveUDPAddr acts like net.ResolveUDPAddr but uses the cache.
type SocketProtector ¶ added in v0.3.5
SocketProtector is a callback function that protects a socket file descriptor. On Android, this should call VpnService.protect(fd). Returns true if protection was successful, false otherwise.