Documentation
¶
Overview ¶
Package dial is the single path from an address to a connected socket, directly or through an HTTP or SOCKS5 proxy, and to a UDP socket for QUIC, directly or through a SOCKS5 UDP association. Every step honours the context and its deadline (decision 0010); no other package opens connections.
Index ¶
- Constants
- func Credentials(p *url.URL) string
- type Dialer
- func (d *Dialer) Challenged(p *url.URL, h http.Header) bool
- func (d *Dialer) CheckProxy(p *url.URL) error
- func (d *Dialer) Dial(ctx context.Context, addr string) (net.Conn, error)
- func (d *Dialer) DialProxy(ctx context.Context, p *url.URL) (net.Conn, error)
- func (d *Dialer) DialVia(ctx context.Context, p *url.URL, addr string) (net.Conn, error)
- func (d *Dialer) ForwardAuthorization(p *url.URL) string
- func (d *Dialer) ListenUDP(ctx context.Context, host string, port uint16) (net.PacketConn, netip.AddrPort, error)
- func (d *Dialer) ListenUDPVia(ctx context.Context, p *url.URL, host string, port uint16) (net.PacketConn, netip.AddrPort, error)
- func (d *Dialer) UDPRefused(p *url.URL) bool
- type ProxyError
Constants ¶
const ( SchemeHTTP = "http" SchemeSOCKS5 = "socks5" SchemeSOCKS5H = "socks5h" )
Supported proxy URL schemes.
const DefaultHTTP3ReadBufferSize = 1 << 20
DefaultHTTP3ReadBufferSize is the receive buffer a QUIC socket asks for by default: Chrome's (kQuicSocketReceiveBufferSize, net/quic/ quic_context.h, set on every QUIC socket it opens).
Variables ¶
This section is empty.
Functions ¶
func Credentials ¶
Credentials returns p's Basic Proxy-Authorization value, or "".
Types ¶
type Dialer ¶
type Dialer struct {
// Timeout bounds the connect (through a proxy: to the proxy, and the
// proxy's handshake), on top of the context's deadline.
Timeout time.Duration
// DialContext, when set, opens the connection (to the proxy, when
// there is one) instead of net.Dialer; Timeout still bounds it.
DialContext func(ctx context.Context, network, addr string) (net.Conn, error)
// Resolver looks host names up for net.Dialer; nil uses
// net.DefaultResolver. DialContext does its own lookups.
Resolver *net.Resolver
// Proxy is how the profile's browser talks to proxies; nil (not
// measured) makes proxies an error.
Proxy *profile.Proxy
// UserAgent is the profile's, which CONNECT requests carry.
UserAgent string
// BrowserAuth gives an HTTP proxy the URL's credentials as Proxy's
// ConnectCredentials and ForwardCredentials say, after its 407.
// Otherwise they go from the first request, placed as Proxy places
// them unasked (ConnectAuth, ForwardAuth): only the proxy sees the
// difference (decision 0039).
BrowserAuth bool
// HTTP3ReadBufferSize is the receive buffer a QUIC socket asks for
// (SetReadBuffer; the OS may grant less): zero asks for
// DefaultHTTP3ReadBufferSize, negative leaves the OS's default (see
// setReadBuffer).
HTTP3ReadBufferSize int
// contains filtered or unexported fields
}
Dialer opens TCP connections, directly or through a proxy, and UDP sockets for QUIC. It is the one place connections start.
func (*Dialer) Challenged ¶
Challenged records that p asked for credentials (a 407 with header h) on a plain-HTTP request, and reports whether they can be given: p has them and asks for Basic.
func (*Dialer) CheckProxy ¶
CheckProxy reports whether p is a proxy URL the dialer can use. The engine checks that the profile describes the proxy protocol.
func (*Dialer) Dial ¶
Dial connects to addr ("host:port"). It honours ctx's cancellation and deadline.
func (*Dialer) DialProxy ¶
DialProxy connects to the proxy p itself, for plain-HTTP requests sent to it whole. A failure is a *ProxyError.
func (*Dialer) DialVia ¶
DialVia connects to addr through the proxy p: an HTTP proxy's CONNECT tunnel or a SOCKS5 connection, as the profile's browser asks for them. A failure before the tunnel is up is a *ProxyError.
func (*Dialer) ForwardAuthorization ¶
ForwardAuthorization returns the Proxy-Authorization a plain-HTTP request to p carries unasked, or "": p's credentials from the first request, or with BrowserAuth once p has asked or where the profile always sends them.
func (*Dialer) ListenUDP ¶
func (d *Dialer) ListenUDP(ctx context.Context, host string, port uint16) (net.PacketConn, netip.AddrPort, error)
ListenUDP resolves host with Resolver and opens a UDP socket for a QUIC connection to its first address at port, returned with the socket. It honours ctx, bounded by Timeout. The socket asks for the receive buffer HTTP3ReadBufferSize says and keeps what the OS grants.
func (*Dialer) ListenUDPVia ¶
func (d *Dialer) ListenUDPVia(ctx context.Context, p *url.URL, host string, port uint16) (net.PacketConn, netip.AddrPort, error)
ListenUDPVia opens a SOCKS5 UDP association through p (a socks5 or socks5h proxy) for a QUIC connection to host at port, and returns it with the peer address its datagrams are reported from: host's address when host is an IP address, else the unspecified IPv4 address (the proxy resolves the name, as for its TCP connections, and host never goes to Resolver). The association authenticates as DialVia does and lives as long as its control connection (proxy.Association). A failure is a *ProxyError; a refusal of UDP ASSOCIATE is remembered (UDPRefused). It honours ctx, bounded by Timeout; the socket asks for the receive buffer HTTP3ReadBufferSize says, as ListenUDP's does.
type ProxyError ¶
type ProxyError struct {
// Proxy is the proxy's URL, credentials included.
Proxy *url.URL
// StatusCode and Header are the proxy's answer, if any.
StatusCode int
Header http.Header
Err error
}
ProxyError is a failure to reach a proxy or open a tunnel through it (connect, non-2xx CONNECT, SOCKS5 refusal, deadline). The root package turns it into mimicry.ProxyError.
func (*ProxyError) Error ¶
func (e *ProxyError) Error() string
func (*ProxyError) Unwrap ¶
func (e *ProxyError) Unwrap() error