Documentation ¶
Overview ¶
Provides leaky buffer, based on the example in Effective Go.
Index ¶
- Constants
- Variables
- func BuildPacket(typ uint8, data ...string) []byte
- func BuildPacketData(data ...string) []byte
- func CloseConn(conn *net.Conn)
- func ConnectHost(hostAndPort string, timeout int) (conn net.Conn, err error)
- func ConnectKCPHost(hostAndPort string, config kcpcfg.KCPConfigArgs) (conn net.Conn, err error)
- func GetAllInterfaceAddr() ([]net.IP, error)
- func GetKCPBlock(method, key string) (block kcp.BlockCrypt)
- func HTTPGet(URL string, timeout int) (err error)
- func HttpGet(URL string, timeout int, host ...string) (body []byte, code int, err error)
- func InsertProxyHeaders(head []byte, headers string) []byte
- func IoBind(dst io.ReadWriteCloser, src io.ReadWriteCloser, fn func(err interface{}), ...)
- func IsHTTP(head []byte) bool
- func IsIternalIP(domainOrIP string) bool
- func IsSocks5(head []byte) bool
- func Keygen() (err error)
- func NewCompConn(conn net.Conn) net.Conn
- func PathExists(_path string) bool
- func RandInt(strLen int) int64
- func RandString(strlen int) string
- func ReadData(r io.Reader) (data string, err error)
- func ReadPacket(r io.Reader, typ *uint8, data ...*string) (err error)
- func ReadPacketData(r io.Reader, data ...*string) (err error)
- func ReadUDPPacket(_reader io.Reader) (srcAddr string, packet []byte, err error)
- func RemoveProxyHeaders(head []byte) []byte
- func SubBytes(bytes []byte, start, end int) []byte
- func SubStr(str string, start, end int) string
- func TlsBytes(cert, key string) (certBytes, keyBytes []byte, err error)
- func TlsConnect(host string, port, timeout int, certBytes, keyBytes, caCertBytes []byte) (conn tls.Conn, err error)
- func TlsConnectHost(host string, timeout int, certBytes, keyBytes, caCertBytes []byte) (conn tls.Conn, err error)
- func UDPPacket(srcAddr string, packet []byte) []byte
- func Uniqueid() string
- type BasicAuth
- func (ba *BasicAuth) Add(userpassArr []string) (n int)
- func (ba *BasicAuth) AddFromFile(file string) (n int, err error)
- func (ba *BasicAuth) Check(userpass string, ip, target string) (ok bool)
- func (ba *BasicAuth) CheckUserPass(user, pass, ip, target string) (ok bool)
- func (ba *BasicAuth) SetAuthURL(URL string, code, timeout, retry int)
- func (ba *BasicAuth) Total() (n int)
- type BufferedConn
- type Checker
- type CheckerItem
- type ClientKeyRouter
- type CompStream
- func (c *CompStream) Close() error
- func (c *CompStream) LocalAddr() net.Addr
- func (c *CompStream) Read(p []byte) (n int, err error)
- func (c *CompStream) RemoteAddr() net.Addr
- func (c *CompStream) SetDeadline(t time.Time) error
- func (c *CompStream) SetReadDeadline(t time.Time) error
- func (c *CompStream) SetWriteDeadline(t time.Time) error
- func (c *CompStream) Write(p []byte) (n int, err error)
- type ConcurrentMap
- func (m ConcurrentMap) Count() int
- func (m ConcurrentMap) Get(key string) (interface{}, bool)
- func (m ConcurrentMap) GetShard(key string) *ConcurrentMapShared
- func (m ConcurrentMap) Has(key string) bool
- func (m ConcurrentMap) IsEmpty() bool
- func (m ConcurrentMap) Items() map[string]interface{}
- func (m ConcurrentMap) Iter() <-chan Tupledeprecated
- func (m ConcurrentMap) IterBuffered() <-chan Tuple
- func (m ConcurrentMap) IterCb(fn IterCb)
- func (m ConcurrentMap) Keys() []string
- func (m ConcurrentMap) MSet(data map[string]interface{})
- func (m ConcurrentMap) MarshalJSON() ([]byte, error)
- func (m ConcurrentMap) Pop(key string) (v interface{}, exists bool)
- func (m ConcurrentMap) Remove(key string)
- func (m ConcurrentMap) Set(key string, value interface{})
- func (m ConcurrentMap) SetIfAbsent(key string, value interface{}) bool
- func (m ConcurrentMap) Upsert(key string, value interface{}, cb UpsertCb) (res interface{})
- type ConcurrentMapShared
- type ConnManager
- type DomainResolver
- type DomainResolverItem
- type HTTPRequest
- type IterCb
- type LeakyBuf
- type OutConn
- type Reader
- type ServerChannel
- func (sc *ServerChannel) ListenKCP(config kcpcfg.KCPConfigArgs, fn func(conn net.Conn), log *logger.Logger) (err error)
- func (sc *ServerChannel) ListenTCP(fn func(conn net.Conn)) (err error)
- func (sc *ServerChannel) ListenTls(certBytes, keyBytes, caCertBytes []byte, fn func(conn net.Conn)) (err error)
- func (sc *ServerChannel) ListenUDP(fn func(packet []byte, localAddr, srcAddr *net.UDPAddr)) (err error)
- func (sc *ServerChannel) SetErrAcceptHandler(fn func(err error))
- type Tuple
- type UpsertCb
- type Writer
Constants ¶
const LeakyBufSize = 2048 // data.len(2) + hmacsha1(10) + data(4096)
Variables ¶
var LeakyBuffer = NewLeakyBuf(maxNBuf, LeakyBufSize)
var SHARD_COUNT = 32
Functions ¶
func BuildPacket ¶
func BuildPacketData ¶
func ConnectKCPHost ¶
func GetAllInterfaceAddr ¶
func GetKCPBlock ¶
func GetKCPBlock(method, key string) (block kcp.BlockCrypt)
func InsertProxyHeaders ¶
func IoBind ¶
func IoBind(dst io.ReadWriteCloser, src io.ReadWriteCloser, fn func(err interface{}), log *logger.Logger)
func IsIternalIP ¶
func PathExists ¶
func RandString ¶
func ReadUDPPacket ¶
func RemoveProxyHeaders ¶
func TlsConnect ¶
func TlsConnectHost ¶
Types ¶
type BasicAuth ¶
type BasicAuth struct {
// contains filtered or unexported fields
}
func NewBasicAuth ¶
func NewBasicAuth(dns *DomainResolver, log *logger.Logger) BasicAuth
func (*BasicAuth) CheckUserPass ¶
func (*BasicAuth) SetAuthURL ¶
type BufferedConn ¶
type BufferedConn struct { net.Conn // So that most methods are embedded // contains filtered or unexported fields }
func NewBufferedConn ¶
func NewBufferedConn(c net.Conn) BufferedConn
func NewBufferedConnSize ¶
func NewBufferedConnSize(c net.Conn, n int) BufferedConn
func (BufferedConn) Buffered ¶
func (b BufferedConn) Buffered() int
func (BufferedConn) ReadByte ¶
func (b BufferedConn) ReadByte() (byte, error)
func (BufferedConn) UnreadByte ¶
func (b BufferedConn) UnreadByte() error
type Checker ¶
type Checker struct {
// contains filtered or unexported fields
}
func NewChecker ¶
func NewChecker(timeout int, interval int64, blockedFile, directFile string, log *logger.Logger) Checker
NewChecker args: timeout : tcp timeout milliseconds ,connect to host interval: recheck domain interval seconds
type CheckerItem ¶
type ClientKeyRouter ¶
type ClientKeyRouter struct {
// contains filtered or unexported fields
}
func NewClientKeyRouter ¶
func NewClientKeyRouter(ctrl *ConcurrentMap, size int) ClientKeyRouter
func (*ClientKeyRouter) GetKey ¶
func (c *ClientKeyRouter) GetKey() string
type CompStream ¶
func NewCompStream ¶
func NewCompStream(conn net.Conn) *CompStream
func (*CompStream) Close ¶
func (c *CompStream) Close() error
func (*CompStream) LocalAddr ¶
func (c *CompStream) LocalAddr() net.Addr
func (*CompStream) RemoteAddr ¶
func (c *CompStream) RemoteAddr() net.Addr
func (*CompStream) SetDeadline ¶
func (c *CompStream) SetDeadline(t time.Time) error
func (*CompStream) SetReadDeadline ¶
func (c *CompStream) SetReadDeadline(t time.Time) error
func (*CompStream) SetWriteDeadline ¶
func (c *CompStream) SetWriteDeadline(t time.Time) error
type ConcurrentMap ¶
type ConcurrentMap []*ConcurrentMapShared
A "thread" safe map of type string:Anything. To avoid lock bottlenecks this map is dived to several (SHARD_COUNT) map shards.
func (ConcurrentMap) Count ¶
func (m ConcurrentMap) Count() int
Returns the number of elements within the map.
func (ConcurrentMap) Get ¶
func (m ConcurrentMap) Get(key string) (interface{}, bool)
Retrieves an element from map under given key.
func (ConcurrentMap) GetShard ¶
func (m ConcurrentMap) GetShard(key string) *ConcurrentMapShared
Returns shard under given key
func (ConcurrentMap) Has ¶
func (m ConcurrentMap) Has(key string) bool
Looks up an item under specified key
func (ConcurrentMap) Items ¶
func (m ConcurrentMap) Items() map[string]interface{}
Returns all items as map[string]interface{}
func (ConcurrentMap) Iter
deprecated
func (m ConcurrentMap) Iter() <-chan Tuple
Returns an iterator which could be used in a for range loop.
Deprecated: using IterBuffered() will get a better performence
func (ConcurrentMap) IterBuffered ¶
func (m ConcurrentMap) IterBuffered() <-chan Tuple
Returns a buffered iterator which could be used in a for range loop.
func (ConcurrentMap) IterCb ¶
func (m ConcurrentMap) IterCb(fn IterCb)
Callback based iterator, cheapest way to read all elements in a map.
func (ConcurrentMap) MSet ¶
func (m ConcurrentMap) MSet(data map[string]interface{})
func (ConcurrentMap) MarshalJSON ¶
func (m ConcurrentMap) MarshalJSON() ([]byte, error)
Reviles ConcurrentMap "private" variables to json marshal.
func (ConcurrentMap) Pop ¶
func (m ConcurrentMap) Pop(key string) (v interface{}, exists bool)
Removes an element from the map and returns it
func (ConcurrentMap) Remove ¶
func (m ConcurrentMap) Remove(key string)
Removes an element from the map.
func (ConcurrentMap) Set ¶
func (m ConcurrentMap) Set(key string, value interface{})
Sets the given value under the specified key.
func (ConcurrentMap) SetIfAbsent ¶
func (m ConcurrentMap) SetIfAbsent(key string, value interface{}) bool
Sets the given value under the specified key if no value was associated with it.
func (ConcurrentMap) Upsert ¶
func (m ConcurrentMap) Upsert(key string, value interface{}, cb UpsertCb) (res interface{})
Insert or Update - updates existing element or inserts a new one using UpsertCb
type ConcurrentMapShared ¶
type ConcurrentMapShared struct { // contains filtered or unexported fields }
A "thread" safe string to anything map.
type ConnManager ¶
type ConnManager struct {
// contains filtered or unexported fields
}
func NewConnManager ¶
func NewConnManager(log *logger.Logger) ConnManager
func (*ConnManager) Remove ¶
func (cm *ConnManager) Remove(key string)
func (*ConnManager) RemoveAll ¶
func (cm *ConnManager) RemoveAll()
func (*ConnManager) RemoveOne ¶
func (cm *ConnManager) RemoveOne(key string, ID string)
type DomainResolver ¶
type DomainResolver struct {
// contains filtered or unexported fields
}
func NewDomainResolver ¶
func NewDomainResolver(dnsAddrress string, ttl int, log *logger.Logger) DomainResolver
func (*DomainResolver) MustResolve ¶
func (a *DomainResolver) MustResolve(address string) (ip string)
func (*DomainResolver) PrintData ¶
func (a *DomainResolver) PrintData()
type DomainResolverItem ¶
type DomainResolverItem struct {
// contains filtered or unexported fields
}
type HTTPRequest ¶
type HTTPRequest struct { HeadBuf []byte Host string Method string URL string // contains filtered or unexported fields }
func NewHTTPRequest ¶
func (*HTTPRequest) BasicAuth ¶
func (req *HTTPRequest) BasicAuth() (err error)
func (*HTTPRequest) GetAuthDataStr ¶
func (req *HTTPRequest) GetAuthDataStr() (basicInfo string, err error)
func (*HTTPRequest) HTTP ¶
func (req *HTTPRequest) HTTP() (err error)
func (*HTTPRequest) HTTPS ¶
func (req *HTTPRequest) HTTPS() (err error)
func (*HTTPRequest) HTTPSReply ¶
func (req *HTTPRequest) HTTPSReply() (err error)
func (*HTTPRequest) IsHTTPS ¶
func (req *HTTPRequest) IsHTTPS() bool
type IterCb ¶
type IterCb func(key string, v interface{})
Iterator callback,called for every key,value found in maps. RLock is held for all calls for a given shard therefore callback sess consistent view of a shard, but not across the shards
type LeakyBuf ¶
type LeakyBuf struct {
// contains filtered or unexported fields
}
func NewLeakyBuf ¶
NewLeakyBuf creates a leaky buffer which can hold at most n buffer, each with bufSize bytes.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
func NewReaderWithContext ¶
NewReaderWithContext returns a reader that implements io.Reader with rate limiting.
func (*Reader) SetRateLimit ¶
SetRateLimit sets rate limit (bytes/sec) to the reader.
type ServerChannel ¶
type ServerChannel struct { Listener *net.Listener UDPListener *net.UDPConn // contains filtered or unexported fields }
func NewServerChannel ¶
func NewServerChannel(ip string, port int, log *logger.Logger) ServerChannel
func NewServerChannelHost ¶
func NewServerChannelHost(host string, log *logger.Logger) ServerChannel
func (*ServerChannel) ListenKCP ¶
func (sc *ServerChannel) ListenKCP(config kcpcfg.KCPConfigArgs, fn func(conn net.Conn), log *logger.Logger) (err error)
func (*ServerChannel) ListenTCP ¶
func (sc *ServerChannel) ListenTCP(fn func(conn net.Conn)) (err error)
func (*ServerChannel) ListenTls ¶
func (sc *ServerChannel) ListenTls(certBytes, keyBytes, caCertBytes []byte, fn func(conn net.Conn)) (err error)
func (*ServerChannel) ListenUDP ¶
func (sc *ServerChannel) ListenUDP(fn func(packet []byte, localAddr, srcAddr *net.UDPAddr)) (err error)
func (*ServerChannel) SetErrAcceptHandler ¶
func (sc *ServerChannel) SetErrAcceptHandler(fn func(err error))
type Tuple ¶
type Tuple struct { Key string Val interface{} }
Used by the Iter & IterBuffered functions to wrap two variables together over a channel,
type UpsertCb ¶
type UpsertCb func(exist bool, valueInMap interface{}, newValue interface{}) interface{}
Callback to return new element to be inserted into the map It is called while lock is held, therefore it MUST NOT try to access other keys in same map, as it can lead to deadlock since Go sync.RWLock is not reentrant
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
func NewWriterWithContext ¶
NewWriterWithContext returns a writer that implements io.Writer with rate limiting.
func (*Writer) SetRateLimit ¶
SetRateLimit sets rate limit (bytes/sec) to the writer.