network

package
v0.3.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

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

func DialProtected(network, address string) (net.Conn, error)

DialProtected dials to the address using the protected dialer (no context).

func DialProtectedContext added in v0.3.5

func DialProtectedContext(ctx context.Context, network, address string) (net.Conn, error)

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

func DialUDPProtected(network string, laddr, raddr *net.UDPAddr) (*net.UDPConn, error)

DialUDPProtected creates a protected UDP connection. This is specifically for MTP and other UDP-based protocols.

func GetProtectedDialer added in v0.3.5

func GetProtectedDialer() net.Dialer

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

func (r *CachedResolver) ResolveIPAddr(ctx context.Context, host string) ([]net.IPAddr, error)

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

type SocketProtector func(fd int) bool

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL