detour

package
v0.0.0-...-8b1022e Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2016 License: Apache-2.0, Apache-2.0 Imports: 10 Imported by: 0

README

See GoDoc

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

Constants

This section is empty.

Variables

View Source
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

View Source
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

func AddToWl(addr string, permanent bool)

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) Close

func (dc *Conn) Close() error

Close() implements the function from net.Conn

func (*Conn) LocalAddr

func (dc *Conn) LocalAddr() net.Addr

LocalAddr() implements the function from net.Conn

func (*Conn) Read

func (dc *Conn) Read(b []byte) (n int, err error)

Read() implements the function from net.Conn

func (*Conn) RemoteAddr

func (dc *Conn) RemoteAddr() net.Addr

RemoteAddr() implements the function from net.Conn

func (*Conn) SetDeadline

func (dc *Conn) SetDeadline(t time.Time) error

SetDeadline() implements the function from net.Conn

func (*Conn) SetReadDeadline

func (dc *Conn) SetReadDeadline(t time.Time) error

SetReadDeadline() implements the function from net.Conn

func (*Conn) SetWriteDeadline

func (dc *Conn) SetWriteDeadline(t time.Time) error

SetWriteDeadline() implements the function from net.Conn

func (*Conn) Write

func (dc *Conn) Write(b []byte) (n int, err error)

Write() implements the function from net.Conn

type Detector

type Detector struct {
	DNSPoisoned        func(net.Conn) bool
	TamperingSuspected func(error) bool
	FakeResponse       func([]byte) bool
}

Detector is just a set of rules to check if a site is potentially blocked or not

Directories

Path Synopsis
package main provides a simple proxy program that uses detour, useful for performance testing.
package main provides a simple proxy program that uses detour, useful for performance testing.

Jump to

Keyboard shortcuts

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