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
* Operation will time out in TimeoutToDetour in initial state, but at system default or caller supplied deadline for other states; ** DNS hijack is only checked at dial time. *** Connection is always detoured if the site is in tl or wl.
Index ¶
- Variables
- func AddToWl(addr string, permanent bool)
- func Dialer(d 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) Write(b []byte) (n int, err error)
- type Detector
Constants ¶
This section is empty.
Variables ¶
var DirectAddrCh chan string = make(chan string)
if DirectAddrCh is set, when a direct connection is closed without any error, the connection's remote address (in host:port format) will be send to it
var TimeoutToDetour = 3 * time.Second
if dial or read exceeded this timeout, we consider switch to detour The value depends on OS and browser and defaults to 3s For Windows XP, find TcpMaxConnectRetransmissions in http://support2.microsoft.com/default.aspx?scid=kb;en-us;314053
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(d dialFunc) dialFunc
Dialer returns a function with same signature of net.Dialer.Dial().
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