Documentation
¶
Index ¶
- Constants
- func CopyBuffer(b []byte) []byte
- func CopyBuffers(bufs [][]byte) []byte
- func GenTLSClientHello(b []byte, serverName string, sessionID []byte, sessionTicket []byte) int
- func GenTLSServerHello(b []byte, l int, sessionID []byte) int
- func GetBuf(n int) []byte
- func GetIvLen(method string) int
- func GetRandomBytes(len int) []byte
- func HttpProxyTo(w http.ResponseWriter, r *http.Request, target string)
- func IsAEAD(method string) bool
- func IsValidHTTPMethod(m string) bool
- func ListenSubUDP(network, address string) (net.Listener, error)
- func ListenSubUDPWithConn(conn net.PacketConn) (net.Listener, error)
- func ListenSubUDPWithConnAndCtx(conn net.PacketConn, ctx *UDPServerCtx) (net.Listener, error)
- func ListenSubUDPWithCtx(network, address string, ctx *UDPServerCtx) (net.Listener, error)
- func NewUDPListener(address string) (conn *net.UDPConn, err error)
- func PipeForUDPServer(c1, c2 net.Conn, ctx *UDPServerCtx)
- func PipeUDPOverTCP(udpconn net.Conn, tcpconn net.Conn, bufpool *sync.Pool, timeout time.Duration, ...)
- func PprofEnabled() bool
- func PutBuf(b []byte)
- func PutCipherBlock(b *CipherBlock)
- func PutRandomBytes(b []byte)
- func RunProfileHTTPServer(addr string)
- func SliceToString(b []byte) (s string)
- func SplitHostAndPort(hostport string) (host string, port int, err error)
- func SplitIPAndPort(ipport string) (ip net.IP, port int, err error)
- func StringToSlice(s string) (b []byte)
- type AEADDecryptCipherStream
- type AEADEncryptCipherStream
- type AddrCtx
- type AsyncRunner
- type AtomicFlag
- type CheckCallback
- type CipherBlock
- type CipherStream
- func NewAESGCMDecrypter(key []byte, ivLen int) (CipherStream, error)
- func NewAESGCMEncrypter(key, iv []byte) (CipherStream, error)
- func NewChacha20Poly1305Decrypter(key []byte, ivLen int) (CipherStream, error)
- func NewChacha20Poly1305Encrypter(key, iv []byte) (CipherStream, error)
- func NewDecrypter(method, password string) (dec CipherStream, err error)
- func NewEncrypter(method, password string) (enc CipherStream, err error)
- func NewPlainDecrypter(_ []byte, _ int) (CipherStream, error)
- func NewPlainEncrypter(_, _ []byte) (CipherStream, error)
- type ClientHelloMsg
- type Conn
- type CopyConn
- type CurveID
- type DeleteCallback
- type Die
- type DomainRoot
- type DupConn
- type ExitCleaner
- type Expires
- type Extension
- type FecConn
- type HTTPHeaderParser
- func (p *HTTPHeaderParser) Delete(key []byte) (ok bool)
- func (p *HTTPHeaderParser) Encode(b []byte) (n int, err error)
- func (p *HTTPHeaderParser) GetBuf() []byte
- func (p *HTTPHeaderParser) GetFirstLine() (line []byte, err error)
- func (p *HTTPHeaderParser) GetFirstLine1() ([]byte, error)
- func (p *HTTPHeaderParser) GetFirstLine2() ([]byte, error)
- func (p *HTTPHeaderParser) GetFirstLine3() ([]byte, error)
- func (p *HTTPHeaderParser) HeaderLen() int
- func (p *HTTPHeaderParser) Load(key []byte) (values [][]byte, ok bool)
- func (p *HTTPHeaderParser) Ok() bool
- func (p *HTTPHeaderParser) Read(b []byte) (ok bool, err error)
- func (p *HTTPHeaderParser) Reset()
- func (p *HTTPHeaderParser) Store(key []byte, value []byte) (ok bool)
- func (p *HTTPHeaderParser) StoreFirstline1(b []byte) (ok bool)
- func (p *HTTPHeaderParser) StoreFirstline2(b []byte) (ok bool)
- func (p *HTTPHeaderParser) StoreFirstline3(b []byte) (ok bool)
- type IPTree
- type LRU
- func (lru *LRU) Add(key, value interface{})
- func (lru *LRU) Delete(key interface{}) (value interface{}, ok bool)
- func (lru *LRU) DeleteOldest() (key, value interface{}, ok bool)
- func (lru *LRU) Has(key interface{}) (ok bool)
- func (lru *LRU) Length() int
- func (lru *LRU) Load(key interface{}) (value interface{}, ok bool)
- type Lock
- type Locker
- type PlainCipherStream
- type RWLock
- type RWLocker
- type RandomDropConn
- type RateLogConn
- type ServerHelloMsg
- type SliceConn
- type SubConn
- func (conn *SubConn) Close() error
- func (conn *SubConn) Read(b []byte) (n int, err error)
- func (conn *SubConn) RemoteAddr() net.Addr
- func (conn *SubConn) SetReadDeadline(t time.Time) error
- func (conn *SubConn) Write(b []byte) (n int, err error)
- func (conn *SubConn) WriteBuffers(bufs [][]byte) (n int, err error)
- type SubUDPListener
- type UDPConn
- type UDPServerCtx
- type UtilsConn
Constants ¶
const ( VersionSSL30 = 0x0300 VersionTLS10 = 0x0301 VersionTLS11 = 0x0302 VersionTLS12 = 0x0303 )
const CipherBlockLen = 8192
Variables ¶
This section is empty.
Functions ¶
func CopyBuffer ¶
func CopyBuffers ¶
func GenTLSClientHello ¶
func GenTLSServerHello ¶
GenTLSServerHello generate tls server hello for simple-obfs note: the function don't check the length of buffer
func GetRandomBytes ¶
func HttpProxyTo ¶
func HttpProxyTo(w http.ResponseWriter, r *http.Request, target string)
func IsValidHTTPMethod ¶
IsValidHTTPMethod indicates whether m is a valid http method
func ListenSubUDP ¶
ListenSubUDP returns net.Listener
func ListenSubUDPWithConn ¶
func ListenSubUDPWithConn(conn net.PacketConn) (net.Listener, error)
ListenSubUDPWithConn returns net.Listener
func ListenSubUDPWithConnAndCtx ¶
func ListenSubUDPWithConnAndCtx(conn net.PacketConn, ctx *UDPServerCtx) (net.Listener, error)
ListenSubUDPWithConnAndCtx returns net.Listener
func ListenSubUDPWithCtx ¶
func ListenSubUDPWithCtx(network, address string, ctx *UDPServerCtx) (net.Listener, error)
ListenSubUDPWithCtx returns net.Listener
func NewUDPListener ¶
NewUDPListener simplely calls the net.ListenUDP and create a udp listener
func PipeForUDPServer ¶
func PipeForUDPServer(c1, c2 net.Conn, ctx *UDPServerCtx)
PipeForUDPServer is a simple pipe loop for udp server
func PipeUDPOverTCP ¶
func PutCipherBlock ¶
func PutCipherBlock(b *CipherBlock)
func PutRandomBytes ¶
func PutRandomBytes(b []byte)
func SliceToString ¶
func StringToSlice ¶
Types ¶
type AEADDecryptCipherStream ¶
type AEADDecryptCipherStream struct {
// contains filtered or unexported fields
}
type AEADEncryptCipherStream ¶
type AEADEncryptCipherStream struct {
// contains filtered or unexported fields
}
type AsyncRunner ¶
type AsyncRunner struct {
// contains filtered or unexported fields
}
func (*AsyncRunner) Run ¶
func (a *AsyncRunner) Run(f func())
type AtomicFlag ¶
type AtomicFlag uint32
AtomicFlag is an atomic flag(or boolean)
func (*AtomicFlag) Set ¶
func (a *AtomicFlag) Set(flag bool) bool
Set sets the atomic flag to flag and returns old value
type CheckCallback ¶
type CheckCallback func(key, value interface{}) (ok bool)
CheckCallback is used to check if a key can be deleted the key won't be deleted if it returns true
type CipherBlock ¶
type CipherBlock struct {
// contains filtered or unexported fields
}
func GetCipherBlock ¶
func GetCipherBlock() *CipherBlock
type CipherStream ¶
type CipherStream interface { io.ReadWriter GetIV() []byte }
func NewAESGCMDecrypter ¶
func NewAESGCMDecrypter(key []byte, ivLen int) (CipherStream, error)
func NewAESGCMEncrypter ¶
func NewAESGCMEncrypter(key, iv []byte) (CipherStream, error)
func NewChacha20Poly1305Decrypter ¶
func NewChacha20Poly1305Decrypter(key []byte, ivLen int) (CipherStream, error)
func NewChacha20Poly1305Encrypter ¶
func NewChacha20Poly1305Encrypter(key, iv []byte) (CipherStream, error)
func NewDecrypter ¶
func NewDecrypter(method, password string) (dec CipherStream, err error)
func NewEncrypter ¶
func NewEncrypter(method, password string) (enc CipherStream, err error)
func NewPlainDecrypter ¶
func NewPlainDecrypter(_ []byte, _ int) (CipherStream, error)
func NewPlainEncrypter ¶
func NewPlainEncrypter(_, _ []byte) (CipherStream, error)
type ClientHelloMsg ¶
type ClientHelloMsg struct { Raw []byte Vers uint16 Random []byte SessionId []byte CipherSuites []uint16 CompressionMethods []uint8 NextProtoNeg bool ServerName string OcspStapling bool Scts bool SupportedCurves []CurveID SupportedPoints []uint8 TicketSupported bool SessionTicket []uint8 SignatureAndHashes []signatureAndHash SecureRenegotiation []byte SecureRenegotiationSupported bool AlpnProtocols []string }
func ParseTLSClientHelloMsg ¶
func ParseTLSClientHelloMsg(b []byte) (ok bool, n int, msg *ClientHelloMsg)
ParseTLSClientHelloMsg scan the buffer and try to parse TLS Client Hello Message ok returns false if it's not tls hello msg
func (*ClientHelloMsg) Marshal ¶
func (m *ClientHelloMsg) Marshal() []byte
func (*ClientHelloMsg) Unmarshal ¶
func (m *ClientHelloMsg) Unmarshal(data []byte) bool
type Conn ¶
Conn represents a net.Conn that implement WriteBuffers method WriteBuffers can write serveral buffers at a time
type CurveID ¶
type CurveID uint16
CurveID is the type of a TLS identifier for an elliptic curve. See http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-8
type DeleteCallback ¶
type DeleteCallback func(key, value interface{})
DeleteCallback is called when a key is deleting
type DomainRoot ¶
type DomainRoot struct {
// contains filtered or unexported fields
}
DomainRoot is a simple trie tree
func NewDomainRoot ¶
func NewDomainRoot() *DomainRoot
NewDomainRoot returns a new domainroot and init it
func (*DomainRoot) Get ¶
func (root *DomainRoot) Get() (hosts []string)
func (*DomainRoot) Put ¶
func (root *DomainRoot) Put(host string)
Put put a new host into domainroot
func (*DomainRoot) Test ¶
func (root *DomainRoot) Test(host string) bool
type ExitCleaner ¶
type ExitCleaner struct {
// contains filtered or unexported fields
}
func (*ExitCleaner) Delete ¶
func (c *ExitCleaner) Delete(index int) func()
func (*ExitCleaner) Exit ¶
func (c *ExitCleaner) Exit()
func (*ExitCleaner) Push ¶
func (c *ExitCleaner) Push(f func()) int
type HTTPHeaderParser ¶
type HTTPHeaderParser struct {
// contains filtered or unexported fields
}
HTTPHeaderParser is a parser for http request and reply header
func NewHTTPHeaderParser ¶
func NewHTTPHeaderParser(buf []byte) *HTTPHeaderParser
NewHTTPHeaderParser new a http parser
func (*HTTPHeaderParser) Delete ¶
func (p *HTTPHeaderParser) Delete(key []byte) (ok bool)
Delete deletes a key-value pair from http headers
func (*HTTPHeaderParser) Encode ¶
func (p *HTTPHeaderParser) Encode(b []byte) (n int, err error)
Encode encodes the http message to a byte buffer
func (*HTTPHeaderParser) GetBuf ¶
func (p *HTTPHeaderParser) GetBuf() []byte
GetBuf return the buffer of parser
func (*HTTPHeaderParser) GetFirstLine ¶
func (p *HTTPHeaderParser) GetFirstLine() (line []byte, err error)
GetFirstLine returns the first line of http request or reply
func (*HTTPHeaderParser) GetFirstLine1 ¶
func (p *HTTPHeaderParser) GetFirstLine1() ([]byte, error)
GetFirstLine1 returns the first string in the first line
func (*HTTPHeaderParser) GetFirstLine2 ¶
func (p *HTTPHeaderParser) GetFirstLine2() ([]byte, error)
GetFirstLine2 returns the second string in the first line
func (*HTTPHeaderParser) GetFirstLine3 ¶
func (p *HTTPHeaderParser) GetFirstLine3() ([]byte, error)
GetFirstLine3 returns the third string in the first line
func (*HTTPHeaderParser) HeaderLen ¶
func (p *HTTPHeaderParser) HeaderLen() int
HeaderLen returns the hteader length of http message
func (*HTTPHeaderParser) Load ¶
func (p *HTTPHeaderParser) Load(key []byte) (values [][]byte, ok bool)
Load returns the values in the http headers, or nil if no key is present.The OK indicates whether key-value was found in the headers
func (*HTTPHeaderParser) Ok ¶
func (p *HTTPHeaderParser) Ok() bool
func (*HTTPHeaderParser) Read ¶
func (p *HTTPHeaderParser) Read(b []byte) (ok bool, err error)
Read scan the bytes in buffer, ok == true if read a full http-header, err != nil if error occurs
func (*HTTPHeaderParser) Reset ¶
func (p *HTTPHeaderParser) Reset()
Reset reset the state of http header parser
func (*HTTPHeaderParser) Store ¶
func (p *HTTPHeaderParser) Store(key []byte, value []byte) (ok bool)
Store appends a key-value pair to the headers
func (*HTTPHeaderParser) StoreFirstline1 ¶
func (p *HTTPHeaderParser) StoreFirstline1(b []byte) (ok bool)
StoreFirstline1 store the first string of http first line
func (*HTTPHeaderParser) StoreFirstline2 ¶
func (p *HTTPHeaderParser) StoreFirstline2(b []byte) (ok bool)
StoreFirstline2 store the first string of http first line
func (*HTTPHeaderParser) StoreFirstline3 ¶
func (p *HTTPHeaderParser) StoreFirstline3(b []byte) (ok bool)
StoreFirstline3 store the first string of http first line
type IPTree ¶
type IPTree struct {
// contains filtered or unexported fields
}
IPTree implements radix tree for IP tree
func (*IPTree) InsertIPNet ¶
InsertIPNet inserts an ipnet to the tree, eg: 127.0.0.1/24
type LRU ¶
type LRU struct {
// contains filtered or unexported fields
}
LRU implements a simple and thread-safe LRU cache
func NewLRU ¶
func NewLRU(maxlen int, onCheck CheckCallback, onDelete DeleteCallback) *LRU
NewLRU init a new lru
func (*LRU) Add ¶
func (lru *LRU) Add(key, value interface{})
Add inserts new key and value into the lru
func (*LRU) DeleteOldest ¶
DeleteOldest deletes the oldest entry from cache returns its key, value and if delete is successful
type PlainCipherStream ¶
type PlainCipherStream struct {
// contains filtered or unexported fields
}
func (*PlainCipherStream) GetIV ¶
func (p *PlainCipherStream) GetIV() []byte
type RWLock ¶
func (*RWLock) RunInRLock ¶
func (l *RWLock) RunInRLock(f func())
type RandomDropConn ¶
func NewRandomDropConn ¶
func NewRandomDropConn(conn net.Conn, dropRate int) *RandomDropConn
type RateLogConn ¶
func NewRateLogConn ¶
func NewRateLogConn(conn net.Conn, name string) *RateLogConn
func (*RateLogConn) Close ¶
func (conn *RateLogConn) Close() error
func (*RateLogConn) GetAndClearNRW ¶
func (conn *RateLogConn) GetAndClearNRW() (int, int)
type ServerHelloMsg ¶
type ServerHelloMsg struct { Raw []byte Vers uint16 Random []byte SessionId []byte CipherSuite uint16 CompressionMethod uint8 NextProtoNeg bool NextProtos []string OcspStapling bool Scts [][]byte TicketSupported bool SecureRenegotiation []byte SecureRenegotiationSupported bool AlpnProtocol string OtherExtensions []Extension }
func ParseTLSServerHelloMsg ¶
func ParseTLSServerHelloMsg(b []byte) (ok bool, n int, msg *ServerHelloMsg)
ParseTLSServerHelloMsg scan the buffer and try to parse TLS ServerHello Message ok returns false if it's not tls server hello msg
func (*ServerHelloMsg) Marshal ¶
func (m *ServerHelloMsg) Marshal() []byte
func (*ServerHelloMsg) Unmarshal ¶
func (m *ServerHelloMsg) Unmarshal(data []byte) bool
type SubConn ¶
type SubConn struct { net.PacketConn // contains filtered or unexported fields }
SubConn is the child connection of a net.PacketConn
func (*SubConn) RemoteAddr ¶
RemoteAddr return the address of peer
func (*SubConn) SetReadDeadline ¶
SetReadDeadline set the dealdine of read
type SubUDPListener ¶
type SubUDPListener struct {
// contains filtered or unexported fields
}
SubUDPListener implements net.Listener and acts like tcp net.Listener
func (*SubUDPListener) Accept ¶
func (listener *SubUDPListener) Accept() (net.Conn, error)
Accept accepts a new net.Conn from listner
func (*SubUDPListener) AcceptSub ¶
func (listener *SubUDPListener) AcceptSub() (*SubConn, error)
AcceptSub accepts a new subconn from listner
func (*SubUDPListener) Addr ¶
func (listener *SubUDPListener) Addr() net.Addr
Addr returns the local address of underlying packet connection
func (*SubUDPListener) Close ¶
func (listener *SubUDPListener) Close() error
Close close listener and destroy everything
type UDPConn ¶
type UDPConn interface { // Read reads data from the connection. // Read can be made to time out and return an Error with Timeout() == true // after a fixed time limit; see SetDeadline and SetReadDeadline. Read(b []byte) (n int, err error) // Write writes data to the connection. // Write can be made to time out and return an Error with Timeout() == true // after a fixed time limit; see SetDeadline and SetWriteDeadline. Write(b []byte) (n int, err error) // Close closes the connection. // Any blocked Read or Write operations will be unblocked and return errors. Close() error // LocalAddr returns the local network address. LocalAddr() net.Addr // RemoteAddr returns the remote network address. RemoteAddr() net.Addr // SetDeadline sets the read and write deadlines associated // with the connection. It is equivalent to calling both // SetReadDeadline and SetWriteDeadline. // // A deadline is an absolute time after which I/O operations // fail with a timeout (see type Error) instead of // blocking. The deadline applies to all future and pending // I/O, not just the immediately following call to Read or // Write. After a deadline has been exceeded, the connection // can be refreshed by setting a deadline in the future. // // An idle timeout can be implemented by repeatedly extending // the deadline after successful Read or Write calls. // // A zero value for t means I/O operations will not time out. SetDeadline(t time.Time) error // SetReadDeadline sets the deadline for future Read calls // and any currently-blocked Read call. // A zero value for t means Read will not time out. SetReadDeadline(t time.Time) error // SetWriteDeadline sets the deadline for future Write calls // and any currently-blocked Write call. // Even if write times out, it may return n > 0, indicating that // some of the data was successfully written. // A zero value for t means Write will not time out. SetWriteDeadline(t time.Time) error // ReadFrom reads a packet from the connection, // copying the payload into b. It returns the number of // bytes copied into b and the return address that // was on the packet. // ReadFrom can be made to time out and return // an Error with Timeout() == true after a fixed time limit; // see SetDeadline and SetReadDeadline. ReadFrom(b []byte) (n int, addr net.Addr, err error) // WriteTo writes a packet with payload b to addr. // WriteTo can be made to time out and return // an Error with Timeout() == true after a fixed time limit; // see SetDeadline and SetWriteDeadline. // On packet-oriented connections, write timeouts are rare. WriteTo(b []byte, addr net.Addr) (n int, err error) }
UDPConn is the union set of net.Conn and net.PacketConn
type UDPServerCtx ¶
UDPServerCtx is the control centor of the udp server
func (*UDPServerCtx) RunUDPServer ¶
func (ctx *UDPServerCtx) RunUDPServer(conn net.PacketConn, create func(*SubConn) (net.Conn, net.Conn, error))
RunUDPServer runs the udp server