proxy

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2022 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//socks5 error code
	ERR                 byte = 1
	ERR_RULE            byte = 2
	ERR_NET             byte = 3
	ERR_DST             byte = 4
	ERR_DST_REFUSE      byte = 5
	ERR_TTL_EXPIRED     byte = 6
	ERR_COMMAND_UNKNOWN byte = 7
	ERR_ADDR_TYPE       byte = 8

	ERR_REPEAT_ID    byte = 9
	ERR_CONN_TIMEOUT byte = 10
	ERR_DIAL_TIMEOUT byte = 11
	ERR_DST_RESET    byte = 12
	ERR_FORCE_CLOSE  byte = 13
	ERR_ABORT        byte = 14

	ERR_TIMEOUT         byte = 16
	ERR_INVALID_ADDR    byte = 17
	ERR_UNKNOWN_NETWORK byte = 18
	ERR_DNS             byte = 19
	ERR_DNS_CONFIG      byte = 20
	ERR_REFUSE          byte = 21
	ERR_ADDR            byte = 22
	ERR_SRC_ABORT       byte = 23
	ERR_DST_TIMEOUT     byte = 24
	ERR_DST_DOWN        byte = 25
	ERR_DST_UNREACH     byte = 26
	ERR_RESET           byte = 27
	ERR_READ_TIMEOUT    byte = 28
	ERR_CLOSED          byte = 29
	ERR_DST_ABORT       byte = 30
	ERR_UNKNOWN         byte = 50
)
View Source
const (
	CONNECT   byte = 1
	ASSOCIATE byte = 3
	UDP       byte = 5 //udp relay
	DNS       byte = 6 //dns query

	SERVICE_START byte = 1
	SERVICE_STOP  byte = 2
	SERVICE_DATA  byte = 3
	SERVICE_ERROR byte = 4
	SERVICE_FATAL byte = 5
	SERVICE_STAT  byte = 6

	TUNNEL_OPEN   byte = 1
	TUNNEL_SENT   byte = 2
	TUNNEL_RECIVE byte = 3
	TUNNEL_CLOSE  byte = 4
	TUNNEL_Error  byte = 5

	TunnelEvent_MAX int = 300
)

Variables

View Source
var Break_Time int64 = 5 * 1000
View Source
var CopyBuffers = sync.Pool{
	New: func() interface{} {
		buf := make([]byte, 8096)
		return &buf
	},
}
View Source
var Copy_Read_Loop_Max = Copy_Read_Timeout / 45
View Source
var Copy_Read_Timeout int = 5 * 60 //second
View Source
var DefaultFilter = &defautFilter{filter: EmptyFilter}
View Source
var EmptyFilter = &filter{}
View Source
var ErrTags = map[string]byte{
	"established connection was aborted":            ERR_SRC_ABORT,
	"connection was forcibly closed by the remote ": ERR_DST_ABORT,
	"connected host has failed to respond":          ERR_DST_TIMEOUT,
	"broken pipe":                                   ERR_RESET,
}
View Source
var ErrTip = map[byte]string{
	ERR:                 "proxy server error",
	ERR_RULE:            "proxy server rule refuse",
	ERR_NET:             "use of closed network connection",
	ERR_DST_UNREACH:     "The server is unreachable",
	ERR_DST_REFUSE:      "The remote host actively refused the attempt to connect to it",
	ERR_TTL_EXPIRED:     "TTL expired",
	ERR_COMMAND_UNKNOWN: "command not supported",
	ERR_ADDR_TYPE:       "address type not supported",
	ERR_REPEAT_ID:       "repeat stream id",
	ERR_DIAL_TIMEOUT:    "dial dst i/o timeout",
	ERR_DST_RESET:       "reset by peer",
	ERR_CONN_TIMEOUT:    "forcibly closed by the remote host",
	ERR_FORCE_CLOSE:     "forcibly closed by proxy",
	ERR_ABORT:           "aborted by your host software",

	ERR_DST_TIMEOUT:     "The connection failed due to an error or timeout",
	ERR_TIMEOUT:         "net timeout",
	ERR_INVALID_ADDR:    "invalid error",
	ERR_UNKNOWN_NETWORK: "unknown network",
	ERR_DNS:             "dns error",
	ERR_DNS_CONFIG:      "dns config error",
	ERR_REFUSE:          "connection refuse",
	ERR_RESET:           "reset by peer",
	ERR_ADDR:            "addr error",
	ERR_SRC_ABORT:       "aborted by the software in your host machine, possibly because of timeout or protocol error",
	ERR_DST_ABORT:       "forcibly closed by the remote host",
	ERR_DST_DOWN:        "The server is temporarily or permanently unreachable",
	ERR_READ_TIMEOUT:    "read timeout",
	ERR_CLOSED:          "use of closed network connection",
	ERR_UNKNOWN:         "unknown error",
}
View Source
var Err_Manually_Close = fmt.Errorf("forceibly closed manually")
View Source
var GOOGLE = xnet.DomainToAddr("google.com", 443)
View Source
var Header_TimeOut int64 = 10 * 1000

Functions

func CancelLocalServiceEvent

func CancelLocalServiceEvent(id string)

func CancelLocalTunnelEvent

func CancelLocalTunnelEvent(id string)

func CancelRemoteServiceEvent

func CancelRemoteServiceEvent(id string)

func CancelRemoteTunnelEvent

func CancelRemoteTunnelEvent(id string)

func CheckDohClients

func CheckDohClients(isDirect bool, clients []*DohClient, domain string)

func CheckDohs

func CheckDohs(isDirect bool, dohs []*xnet.Doh, domain string, notify event.Notify)

func CheckPoints

func CheckPoints(points []*xnet.Point, notify event.Notify)

func ClearLocalTunnels

func ClearLocalTunnels()

func CloseLocalTunnel

func CloseLocalTunnel(id string)

func Copy added in v0.9.3

func Copy(dst net.Conn, src net.Conn, ctx context.Context, sendOrReceive bool) (written int64, er error, ew error)

func DialNetAddr

func DialNetAddr(point *xnet.Point, addr xnet.Addr) (net.Conn, error)

func DialPeerAddr

func DialPeerAddr(point *xnet.Point, addr xnet.Addr) (net.Conn, error)

func DnsLocalQuery

func DnsLocalQuery(b []byte) (p []byte)

func DnsMustQuery

func DnsMustQuery(b []byte) (p []byte)

func DnsRemoteQuery

func DnsRemoteQuery(b []byte) (p []byte)

func DohQuery

func DohQuery(b []byte, isDirect bool) (p []byte, err error)

func GetErrorCode

func GetErrorCode(err error) (code byte)

func GetErrorCodeFromTags added in v0.9.3

func GetErrorCodeFromTags(err error) (code byte)

func InitDoh

func InitDoh()

func LocalDo

func LocalDo(tunnel *Tunnel) (err error)

func OrderPoints

func OrderPoints()

func ParseQueryDomain

func ParseQueryDomain(b []byte) (domain string)

func RegProtocol

func RegProtocol(name string, p *Protocol) error

func SortDohClients

func SortDohClients(clients []*DohClient)

func StartLocal

func StartLocal()

func StartRemote

func StartRemote()

func StopLocal

func StopLocal()

func StopRemote

func StopRemote()

func SubLocalServiceEvent

func SubLocalServiceEvent(s event.Stream) string

func SubLocalTunnelEvent

func SubLocalTunnelEvent(s event.Stream) string

func SubRemoteServiceEvent

func SubRemoteServiceEvent(s event.Stream) string

func SubRemoteTunnelEvent

func SubRemoteTunnelEvent(s event.Stream) string

Types

type Create

type Create func(p *Proto) Peer

type DialAddr

type DialAddr func(point *xnet.Point, addr xnet.Addr) (net.Conn, error)

type Dialer

type Dialer interface {
	Open(t *Tunnel) error
}

dial remote peer open a tunnel for target address

type Do

type Do func(t *Tunnel) (err error)

type DohClient

type DohClient struct {
	*xnet.Doh
	Latency int
	// contains filtered or unexported fields
}

func NewDohClient

func NewDohClient(doh *xnet.Doh) (client *DohClient, err error)

func (DohClient) Close

func (d DohClient) Close() (err error)

func (*DohClient) Do

func (d *DohClient) Do(req *http.Request, isDirect bool) (rsp *http.Response, err error)

always http2

func (DohClient) NewGetRequest

func (d DohClient) NewGetRequest(b []byte) (req *http.Request, err error)

func (DohClient) NewPostRequest

func (d DohClient) NewPostRequest(b []byte) (req *http.Request, err error)

func (*DohClient) Query

func (d *DohClient) Query(b []byte, isDirect bool) (p []byte, err error)

type FatalError added in v0.9.3

type FatalError struct {
	// contains filtered or unexported fields
}

func NewFatalError added in v0.9.3

func NewFatalError(s string) FatalError

func (FatalError) Error added in v0.9.3

func (e FatalError) Error() string

type Filter

type Filter interface {
	BeforeDial(t *Tunnel, err error) error
	AfterDial(t *Tunnel, err error) error
	BeforeSend(t *Tunnel) error
	AfterSend(t *Tunnel) error
	BeforeReceive(t *Tunnel) error
	AfterReceive(t *Tunnel) error
}

protocol filter

type Peer

type Peer interface {
	xnet.IDCode
	Dialer
	Filter
	io.Closer
	transport.Handler
	ServiceEventNotifier
	TunnelEventNotifier
	GetProto() *Proto
	Stat() *PointStat
	ClearConn()
}

type PointStat

type PointStat struct {
	Id          string
	Code        string
	Name        string
	Transport   string
	Protocol    string
	ConnCount   int
	StreamCount int
	IsDirect    bool
}

func NewPointStat

func NewPointStat(p *Proto, connCount, streamCount int) *PointStat

type Proto

type Proto struct {
	*xnet.Point
	Filter
	Do Do
	DialAddr
	ServiceEventNotifier
	TunnelEventNotifier
	IsDirect bool
	// contains filtered or unexported fields
}

all proxy protocol proto implement

func NewLocalProto

func NewLocalProto(point *xnet.Point) (*Proto, error)

func NewRemoteProto

func NewRemoteProto(point *xnet.Point) (*Proto, error)

func (*Proto) ClearConn added in v0.9.2

func (p *Proto) ClearConn()

func (*Proto) Close

func (p *Proto) Close() error

func (*Proto) GetProto

func (p *Proto) GetProto() *Proto

func (*Proto) Handle

func (p *Proto) Handle(conn net.Conn)

func (*Proto) NewTunnel

func (p *Proto) NewTunnel(id string, src net.Conn, method byte, addr xnet.Addr) *Tunnel

func (*Proto) Open

func (p *Proto) Open(t *Tunnel) error

func (*Proto) ReadFull added in v0.9.3

func (p *Proto) ReadFull(r io.Reader, b []byte) (n int, err error)

func (*Proto) Stat

func (p *Proto) Stat() *PointStat

type Protocol

type Protocol struct {
	Name     string
	LocalFn  Create
	RemoteFn Create
}

func GetProtocol

func GetProtocol(name string) (ptc *Protocol, err error)

type ServiceEventNotifier

type ServiceEventNotifier interface {
	OnStart()
	OnStop(err error)
	OnError(err error)
	OnFatal(err error)
	SubServiceEvent(s event.Stream) string
	CancelServiceEvent(id string)
}

event type: start|close|error|fatal|data|stat

type Stat

type Stat struct {
	ConnCount   int
	StreamCount int
	Points      []*PointStat
}

func LocalStat

func LocalStat() *Stat

type Tunnel

type Tunnel struct {
	Id           string
	Method       byte
	Addr         xnet.Addr
	Src          net.Conn
	Dst          net.Conn
	SrcPeer      Peer
	DstPeer      Peer
	StartTime    int64
	OpenDuration int64
	Sent         int64
	SentDuration int64
	Received     int64
	RecvDuration int64
	CloseTime    int64
	PassMode     byte
	Connected    bool
	AutoTry      bool
	Multiple     bool
	Error        error
	Closed       bool
	SendDone     bool
	RecvDone     bool
	WriteSrcErr  error
	ReadSrcErr   error
	WriteDstErr  error
	ReadDstErr   error
	TunnelEventNotifier
	// contains filtered or unexported fields
}

func (*Tunnel) AddError

func (t *Tunnel) AddError(err error)

func (*Tunnel) Close

func (t *Tunnel) Close()

func (*Tunnel) CloseWithError

func (t *Tunnel) CloseWithError(err error)

func (*Tunnel) IsLocal

func (t *Tunnel) IsLocal() bool

func (*Tunnel) Release added in v0.9.4

func (t *Tunnel) Release(err error) bool

type TunnelData

type TunnelData map[string]interface{}

func LocalStatTunnel

func LocalStatTunnel() []*TunnelData

func NewTunnelData

func NewTunnelData(t *Tunnel) *TunnelData

type TunnelEvent

type TunnelEvent struct {
	Type      byte
	Id        string
	Bytes     int64
	Duration  int64
	Error     string
	Timestamp int64
}

func NewTunnelEvent

func NewTunnelEvent(t *Tunnel) *TunnelEvent

type TunnelEventNotifier

type TunnelEventNotifier interface {
	OnTunnelOpen(t *Tunnel)
	OnTunnelClose(t *Tunnel)
	OnTunnelSent(t *Tunnel)
	OnTunnelReceived(t *Tunnel)
	SubTunnelEvent(s event.Stream) string
	CancelTunnelEvent(id string)
}

event type: open|close|send|receive

type WriteTimeOutError added in v0.9.3

type WriteTimeOutError error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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