tunnel

package
v0.11.2770-beta Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2015 License: MIT Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DT_PING_INTERVAL = 90
	RETRY_INTERVAL   = time.Second * 5
	REST_INTERVAL    = RETRY_INTERVAL
)
View Source
const (
	CLT_CLOSED  int32 = -1
	CLT_WORKING int32 = 0
	CLT_PENDING int32 = 1
)
View Source
const (
	SER_KEY_TYPE         = "deblocus/SERVER-PRIVATEKEY"
	USER_CREDENTIAL_TYPE = "deblocus/CLIENT-CREDENTIAL"
	WORD_d5p             = "D5P"
	WORD_provider        = "Provider"
	SIZE_UNIT            = "BKMG"
)
View Source
const (
	IPV4        byte = 1
	DOMAIN      byte = 3
	IPV6        byte = 4
	S5_VER      byte = 5
	AUTH_FAILED byte = 0xff
	TYPE_NEW    byte = 0xfb
	TYPE_DAT    byte = 0xf1
)
View Source
const (
	GENERAL_SO_TIMEOUT = 10 * time.Second
	TUN_PARAMS_LEN     = 32

	DP_LEN1    = 256
	DP_P2I     = 256 + 8
	DP_MOD     = 65536
	TIME_STEP  = 60 // seconds
	TIME_ERROR = 1  // minutes

	REQ_PROT_UNKNOWN    = 1
	REQ_PROT_SOCKS5     = 2
	REQ_PROT_HTTP       = 3
	REQ_PROT_HTTP_T     = 4
	NULL                = ""
	CRLF                = "\r\n"
	IDENTITY_SEP        = "\x00"
	HTTP_PROXY_VER_LINE = "HTTP/1.1 200 Connection established"
	HTTP_PROXY_AGENT    = "Proxy-Agent: "
)
View Source
const (
	// frame action 8bit
	FRAME_ACTION_CLOSE         uint8 = 0x0
	FRAME_ACTION_CLOSE_R             = 0x1
	FRAME_ACTION_CLOSE_W             = 0x2
	FRAME_ACTION_OPEN                = 0x10
	FRAME_ACTION_OPEN_Y              = 0x11
	FRAME_ACTION_OPEN_N              = 0x12
	FRAME_ACTION_OPEN_DENIED         = 0x13
	FRAME_ACTION_SLOWDOWN            = 0x20
	FRAME_ACTION_DATA                = 0x21
	FRAME_ACTION_PING                = 0x30
	FRAME_ACTION_PONG                = 0x31
	FRAME_ACTION_TOKENS              = 0x40
	FRAME_ACTION_TOKEN_REQUEST       = 0x41
	FRAME_ACTION_TOKEN_REPLY         = 0x42
	FRAME_ACTION_DNS_REQUEST         = 0x51
	FRAME_ACTION_DNS_REPLY           = 0x52
)
View Source
const (
	FAST_OPEN              = true
	FAST_OPEN_BUF_MAX_SIZE = 1 << 13 // 8k
)
View Source
const (
	WAITING_OPEN_TIMEOUT = time.Second * 30
	READ_TMO_IN_FASTOPEN = time.Millisecond * 1500
	FRAME_HEADER_LEN     = 5
	FRAME_MAX_LEN        = 0xffff
	MUX_PENDING_CLOSE    = -1
	MUX_CLOSED           = -2
)
View Source
const (
	// idle error type
	ERR_PING_TIMEOUT = 0xe
	ERR_NEW_PING     = 0xf
	ERR_UNKNOWN      = 0x0
)
View Source
const (
	TCP_CLOSE_R uint32 = 1
	TCP_CLOSE_W uint32 = 1 << 1
	TCP_CLOSED  uint32 = TCP_CLOSE_R | TCP_CLOSE_W
)
View Source
const (
	// close code
	CLOSED_FORCE = iota
	CLOSED_WRITE
	CLOSED_BY_ERR
)
View Source
const (
	GENERATE_TOKEN_NUM = 4
	TOKENS_FLOOR       = 2
	PARALLEL_TUN_QTY   = 2
	TKSZ               = sha1.Size
)
View Source
const (
	Bye = syscall.Signal(0xfffb8e)
)
View Source
const (
	TICKER_INTERVAL = time.Second * 15
)

Variables

View Source
var (
	ZERO_TIME  = time.Time{}
	SIZEOF_INT int
)
View Source
var (
	FILE_NOT_FOUND          = exception.NewW("File not found")
	FILE_EXISTS             = exception.NewW("File is already exists")
	INVALID_D5P_FRAGMENT    = exception.NewW("Invalid d5p fragment")
	INVALID_D5C_FILE        = exception.NewW("Invalid d5c file format")
	INVALID_D5S_FILE        = exception.NewW("Invalid d5s file format")
	UNRECOGNIZED_SYMBOLS    = exception.NewW("Unrecognized symbols")
	UNRECOGNIZED_DIRECTIVES = exception.NewW("Unrecognized directives")
	LOCAL_BIND_ERROR        = exception.NewW("Local bind error")
	CONF_MISS               = exception.NewW("Missed config")
	CONF_ERROR              = exception.NewW("Error config")
)
View Source
var (
	// for main package injection
	VERSION    uint32
	VER_STRING string
	DEBUG      bool
)
View Source
var (
	// socks5 exceptions
	INVALID_SOCKS5_HEADER  = exception.New(0xff, "Invalid socks5 header")
	INVALID_SOCKS5_REQUEST = exception.New(0x07, "Invalid socks5 request")
	GENERAL_FAILURE        = exception.New(0x01, "General failure")
	HOST_UNREACHABLE       = exception.New(0x04, "Host is unreachable")
)
View Source
var (
	// D5 exceptions
	INVALID_D5PARAMS     = exception.NewW("Invalid D5Params")
	D5SER_UNREACHABLE    = exception.NewW("D5Server is unreachable")
	VALIDATION_FAILED    = exception.NewW("Validation failed")
	NEGOTIATION_FAILED   = exception.NewW("Negotiation failed")
	DATATUN_SESSION      = exception.NewW("DT")
	INCONSISTENT_HASH    = exception.NewW("Inconsistent hash")
	INCOMPATIBLE_VERSION = exception.NewW("Incompatible version")
	UNRECOGNIZED_REQ     = exception.NewW("Unrecognized Request")
)
View Source
var (
	UNSUPPORTED_CIPHER = exception.NewW("Unsupported cipher")
)

Functions

func CreateClientConfig

func CreateClientConfig(file string, d5s *D5ServConf, user string) (e error)

public for external throws

func DetectFile

func DetectFile(isServ bool) (string, bool)

func DetectRunAsServ

func DetectRunAsServ() bool

func GenerateD5sTemplate

func GenerateD5sTemplate(file string, rsaParam string) (e error)

func GetAvailableCipher

func GetAvailableCipher(wants string) (*cipherDecr, error)

func IdentifierOf

func IdentifierOf(con net.Conn) string

func IsNotExist

func IsNotExist(file string) bool

func IsTimeout

func IsTimeout(e error) bool

func IsValidHost

func IsValidHost(hostport string) (ok bool, err error)

func NewIdler

func NewIdler(interval int, isClient bool) *idler

func NewPushbackInputStream

func NewPushbackInputStream(conn net.Conn) *pushbackInputStream

func NewSemaphore

func NewSemaphore(timeoutResult bool) *semaphore

func ReadFullByLen

func ReadFullByLen(len_inByte int, reader io.Reader) (buf []byte, err error)

len_inByte: first segment length of bytes, enum: 1,2,4

func SafeClose

func SafeClose(conn net.Conn)

func SubstringBefore

func SubstringBefore(str, sep string) string

func SubstringLastBefore

func SubstringLastBefore(str, sep string) string

func ThrowErr

func ThrowErr(e interface{})

func ThrowIf

func ThrowIf(condition bool, e interface{})

Types

type CipherFactory

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

func NewCipherFactory

func NewCipherFactory(name string, secret []byte) *CipherFactory

func (*CipherFactory) InitCipher

func (c *CipherFactory) InitCipher(iv []byte) *XORCipherKit

type Client

type Client struct {
	State int32
	// contains filtered or unexported fields
}

func NewClient

func NewClient(d5c *D5ClientConf, dhKey crypto.DHKE) *Client

func (*Client) ClientServe

func (c *Client) ClientServe(conn net.Conn)

func (*Client) Close

func (t *Client) Close()

func (*Client) IsReady

func (t *Client) IsReady() bool

func (*Client) StartTun

func (c *Client) StartTun(mustRestart bool)

func (*Client) Stats

func (t *Client) Stats() string

type Conn

type Conn struct {
	net.Conn
	// contains filtered or unexported fields
}

func NewConn

func NewConn(conn net.Conn, cipher cipherKit) *Conn

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) CloseRead

func (c *Conn) CloseRead()

func (*Conn) CloseWrite

func (c *Conn) CloseWrite()

func (*Conn) Read

func (c *Conn) Read(b []byte) (int, error)

func (*Conn) SetSockOpt

func (c *Conn) SetSockOpt(disableDeadline, keepAlive, noDelay int8)

bool: disableDeadline int8: minutes of KeepAlivePeriod, zero to disable bool: noDelay

func (*Conn) Update

func (c *Conn) Update()

func (*Conn) Write

func (c *Conn) Write(b []byte) (int, error)

type ConnPool

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

func NewConnPool

func NewConnPool() *ConnPool

func (*ConnPool) Len

func (h *ConnPool) Len() int

func (*ConnPool) Push

func (h *ConnPool) Push(x *Conn)

func (*ConnPool) Remove

func (h *ConnPool) Remove(c *Conn) bool

func (*ConnPool) Select

func (h *ConnPool) Select() *Conn

type D5ClientConf

type D5ClientConf struct {
	Listen     string `importable:":9009"`
	Verbose    int    `importable:"1"`
	ListenAddr *net.TCPAddr
	// contains filtered or unexported fields
}

client config definitions

func Parse_d5c_file

func Parse_d5c_file(path string) *D5ClientConf

public for external

type D5Params

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

d5p

func NewD5Params

func NewD5Params(uri string) (*D5Params, error)

without rsaKey field

func (*D5Params) RemoteName

func (d *D5Params) RemoteName() string

type D5ServConf

type D5ServConf struct {
	Listen     string `importable:":9008"`
	Auth       string `importable:"file://_USER_PASS_FILE_PATH_"`
	Cipher     string `importable:"AES128CFB"`
	ServerName string `importable:"SERVER_NAME"`
	Verbose    int    `importable:"1"`
	DenyDest   string `importable:"OFF"`
	AuthSys    auth.AuthSys
	ListenAddr *net.TCPAddr
	// contains filtered or unexported fields
}

Server config definitions

func Parse_d5s_file

func Parse_d5s_file(path string) *D5ServConf

public for external

type FieldDescriptor

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

type Filterable

type Filterable interface {
	Filter(host string) bool
}

filter interface ,eg. GeoFilter

type ImportableFieldDesc

type ImportableFieldDesc map[string]*FieldDescriptor

type NullCipherKit

type NullCipherKit byte

type RSAKeyPair

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

func GenerateRSAKeyPair

func GenerateRSAKeyPair(keyBits int) *RSAKeyPair

func (*RSAKeyPair) BlockSize

func (k *RSAKeyPair) BlockSize() int

max length of encryption

func (*RSAKeyPair) Decrypt

func (k *RSAKeyPair) Decrypt(src []byte) (plain []byte, err error)

single block decrypt

func (*RSAKeyPair) Encrypt

func (k *RSAKeyPair) Encrypt(src []byte) (enc []byte, err error)

single block encrypt RSA1024-OAEP_sha1: msg.length <= 86byte RSA2048-OAEP_sha1: msg.length <= 214byte

func (*RSAKeyPair) SharedKey

func (k *RSAKeyPair) SharedKey() []byte

type Server

type Server struct {
	*D5ServConf
	// contains filtered or unexported fields
}

Server

func NewServer

func NewServer(d5s *D5ServConf, dhKey crypto.DHKE) *Server

func (*Server) Close

func (t *Server) Close()

implement Close()

func (*Server) Stats

func (t *Server) Stats() string

implement Stats()

func (*Server) TunnelServe

func (t *Server) TunnelServe(raw *net.TCPConn)

type Session

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

Session

func NewSession

func NewSession(tun *Conn, cf *CipherFactory, n *dbcSerNego) *Session

func (*Session) DataTunServe

func (t *Session) DataTunServe(fconn *Conn, isNewSession bool)

type SessionContainer

type SessionContainer map[string]*Session

type SessionMgr

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

SessionMgr

func NewSessionMgr

func NewSessionMgr() *SessionMgr

type TSPriority

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

type XORCipherKit

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

Jump to

Keyboard shortcuts

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