Documentation ¶
Overview ¶
Package detour provides a net.Conn interface to dial another dialer if a site fails to connect directly. It maintains three states of a connection: initial, direct and detoured along with a temporary whitelist across connections. It also add a blocked site to permanent whitelist.
The action taken and state transistion in each phase is as follows: +-------------------------+-----------+-------------+-------------+-------------+-------------+ | | no error | timeout* | conn reset/ | content | other error | | | | | dns hijack | hijack | | +-------------------------+-----------+-------------+-------------+-------------+-------------+ | dial (intial) | noop | detour | detour | n/a | noop | | first read (intial) | direct | detour(buf) | detour(buf) | detour(buf) | noop | | | | add to tl | add to tl | add to tl | | | follow-up read (direct) | direct | add to tl | add to tl | add to tl | noop | | follow-up read (detour) | noop | rm from tl | rm from tl | rm from tl | rm from tl | | close (direct) | noop | n/a | n/a | n/a | n/a | | close (detour) | add to wl | n/a | n/a | n/a | n/a | +-------------------------+-----------+-------------+-------------+-------------+-------------+ | next dial/read(in tl)***| noop | rm from tl | rm from tl | rm from tl | rm from tl | | next close(in tl) | add to wl | n/a | n/a | n/a | n/a | +-------------------------+-----------+-------------+-------------+-------------+-------------+ (buf) = resend buffer tl = temporary whitelist wl = permanent whitelist
- The timeout for first read is firstReadTimeoutToDetour, otherwise it's based on system default or caller supplied deadline.
** DNS hijacking is only checked at dial time. *** Connection is always detoured if the site is in tl or wl.
Index ¶
- func AddToWl(addr string, permanent bool)
- func Dialer(directDialer dialFunc, detourDialer dialFunc) dialFunc
- func DumpWhitelist() (wl []string)
- func ForceWhitelist(addr string)
- func RemoveFromWl(addr string)
- func SetCountry(country string)
- type Conn
- func (dc *Conn) Close() error
- func (dc *Conn) LocalAddr() net.Addr
- func (dc *Conn) Read(b []byte) (n int, err error)
- func (dc *Conn) RemoteAddr() net.Addr
- func (dc *Conn) SetDeadline(t time.Time) error
- func (dc *Conn) SetReadDeadline(t time.Time) error
- func (dc *Conn) SetWriteDeadline(t time.Time) error
- func (dc *Conn) Wrapped() net.Conn
- func (dc *Conn) Write(b []byte) (n int, err error)
- type Detector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddToWl ¶
AddToWl adds a domain to whitelist, all subdomains of this domain are also considered to be in the whitelist.
func Dialer ¶
func Dialer(directDialer dialFunc, detourDialer dialFunc) dialFunc
Dialer returns a function with same signature of net.Dialer.DialContext().
func DumpWhitelist ¶
func DumpWhitelist() (wl []string)
func ForceWhitelist ¶
func ForceWhitelist(addr string)
func RemoveFromWl ¶
func RemoveFromWl(addr string)
func SetCountry ¶
func SetCountry(country string)
SetCountry sets the ISO 3166-1 alpha-2 country code to load country specific detection rules
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
func (*Conn) RemoteAddr ¶
RemoteAddr implements the function from net.Conn
func (*Conn) SetDeadline ¶
SetDeadline implements the function from net.Conn
func (*Conn) SetReadDeadline ¶
SetReadDeadline implements the function from net.Conn
func (*Conn) SetWriteDeadline ¶
SetWriteDeadline implements the function from net.Conn