detour

package module
v0.0.0-...-d3106a6 Latest Latest
Warning

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

Go to latest
Published: May 3, 2023 License: Apache-2.0 Imports: 11 Imported by: 39

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

  • 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

Constants

This section is empty.

Variables

This section is empty.

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(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) 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) Wrapped

func (dc *Conn) Wrapped() net.Conn

Wrapped exposes the underlying connection.

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