Documentation ¶
Index ¶
- Constants
- Variables
- func Connect(host string, port, timeout int) (conn net.Conn, err error)
- func ConnectHost(hostAndPort string, timeout int) (conn net.Conn, err error)
- func Decode(reader *bufio.Reader) (msg message, err error)
- func Encode(data interface{}) (msg []byte, err error)
- func FileGetContents(file string) (content string, err error)
- func GetAllInterfaceAddr() ([]net.IP, error)
- func GetCSTypeString(cstype int) string
- func GetClientCert() []byte
- func GetClientKey() []byte
- func GetClusterHost(url, token, typ string) (addr string, err error)
- func GetProtocolString(protocol int) string
- func GetRootCert() []byte
- func GetServerCert() []byte
- func GetServerKey() []byte
- func HttpGet(URL string) (body []byte, code int, err error)
- func HttpGetNotInternal(URL string) (body []byte, code int, err error)
- func HttpPost(URL string, data map[string]string, header map[string]string) (body []byte, code int, err error)
- func HttpPostNotInternal(URL string, data map[string]string, header map[string]string) (body []byte, code int, err error)
- func HttpPostRaw(URL, postParamsString string, header map[string]string, isInternal bool) (body []byte, code int, err error)
- func InArray(val interface{}, array interface{}) (exists bool, index int)
- func IoBind(dst io.ReadWriter, src io.ReadWriter, fn func(err error), ...)
- func IsChina(country string) bool
- func ListenTls(ip string, port int) (ln *net.Listener, err error)
- func Md5(str string) string
- func PathExists(_path string) bool
- func ReadUDPPacket(conn *tls.Conn) (srcAddr string, packet []byte, err error)
- func Response(channel *MessageChannel, success bool, msg string) (err error)
- func TlsConnect(host string, port, timeout int) (conn tls.Conn, err error)
- func TlsConnectHost(host string, timeout int) (conn tls.Conn, err error)
- func UDPPacket(srcAddr string, packet []byte) []byte
- func UrlArgs(url, args string) string
- type Author
- 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 Encrypt
- func (encrypt *Encrypt) Base64Decode(str string) (string, error)
- func (encrypt *Encrypt) Base64DecodeBytes(str string) ([]byte, error)
- func (encrypt *Encrypt) Base64Encode(str string) string
- func (encrypt *Encrypt) Base64EncodeBytes(bytes []byte) []byte
- func (encrypt *Encrypt) Md5Encode(str string) string
- type IterCb
- type MessageChannel
- func (mc *MessageChannel) CloseConn() (err error)
- func (mc *MessageChannel) DoServe(errfn func(err error))
- func (mc *MessageChannel) LocalAddr() net.Addr
- func (mc *MessageChannel) Ping() (id string, err error)
- func (mc *MessageChannel) Pong(id string) (err error)
- func (mc *MessageChannel) Read(msg interface{}) (err error)
- func (mc *MessageChannel) ReadTimeout(msg interface{}, timeout int) (err error)
- func (mc *MessageChannel) RegMsg(msgType int, msg interface{}, fn msgCallback, fns ...msgCallback)
- func (mc *MessageChannel) RemoteAddr() net.Addr
- func (mc *MessageChannel) SetMsgErrorHandler(fn func(channel *MessageChannel, rawMsg interface{}, err error))
- func (mc *MessageChannel) Write(msg interface{}) (err error)
- type Msg
- type MsgClientOpenConnection
- type MsgLogin
- type MsgPing
- type MsgPong
- type MsgResponse
- type MsgServerClosePort
- type MsgServerOpenPort
- type MsgServerStatusPort
- type Reader
- type ServerChannel
- func (sc *ServerChannel) ListenTCP(fn func(channel MessageChannel, conn net.Conn)) (err error)
- func (sc *ServerChannel) ListenTls(fn func(channel MessageChannel, 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 TrafficStatistics
- type TrafficTotal
- type Tuple
- type UpsertCb
- type Writer
Constants ¶
const ( TUNNEL_PROTOCOL_TCP TUNNEL_PROTOCOL_UDP CSTYPE_SERVER CSTYPE_CLIENT MSG_CLIENT_OPEN_CONNECTION MSG_SERVER_OPEN_PORT MSG_SERVER_CLOSE_PORT MSG_SERVER_STATUS_PORT MSG_RESPONSE STATUS_SUCCESS STATUS_FAIL MSG_TYPE_LOGIN MSG_TYPE_PING MSG_TYPE_PONG CS_CLIENT uint8 = 1 CS_SERVER uint8 = 2 )
const (
BASE_64_TABLE = "1234567890poiuytreqwasdfghjklmnbvcxzQWERTYUIOPLKJHGFDSAZXCVBNM-_"
)
const (
DES_KEY_HOSTPORT = "3j49d723"
)
Variables ¶
var SHARD_COUNT = 32
Functions ¶
func FileGetContents ¶
fileGetContents
func GetAllInterfaceAddr ¶
func GetCSTypeString ¶
func GetClientCert ¶
func GetClientCert() []byte
func GetClientKey ¶
func GetClientKey() []byte
func GetClusterHost ¶
func GetProtocolString ¶
func GetRootCert ¶
func GetRootCert() []byte
func GetServerCert ¶
func GetServerCert() []byte
func GetServerKey ¶
func GetServerKey() []byte
func HttpPostNotInternal ¶
func HttpPostRaw ¶
func IoBind ¶
func IoBind(dst io.ReadWriter, src io.ReadWriter, fn func(err error), cfn func(count int, isPositive bool), bytesPreSec float64)
func PathExists ¶
Types ¶
type Author ¶
type Author struct { Conn *tls.Conn Channel MessageChannel // contains filtered or unexported fields }
func (*Author) DoControlAuth ¶
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 Encrypt ¶
type Encrypt struct{}
func NewEncrypt ¶
func NewEncrypt() *Encrypt
func (*Encrypt) Base64Decode ¶
base64 解密
func (*Encrypt) Base64DecodeBytes ¶
base64 解密
func (*Encrypt) Base64EncodeBytes ¶
base64 加密
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 MessageChannel ¶
type MessageChannel struct { ConnectionID uint64 Conn *net.Conn // contains filtered or unexported fields }
func NewMessageChannel ¶
func NewMessageChannel(conn *net.Conn) MessageChannel
func NewMessageChannelTls ¶
func NewMessageChannelTls(conn *tls.Conn) MessageChannel
func (*MessageChannel) CloseConn ¶
func (mc *MessageChannel) CloseConn() (err error)
func (*MessageChannel) DoServe ¶
func (mc *MessageChannel) DoServe(errfn func(err error))
func (*MessageChannel) LocalAddr ¶
func (mc *MessageChannel) LocalAddr() net.Addr
func (*MessageChannel) Ping ¶
func (mc *MessageChannel) Ping() (id string, err error)
func (*MessageChannel) Pong ¶
func (mc *MessageChannel) Pong(id string) (err error)
func (*MessageChannel) Read ¶
func (mc *MessageChannel) Read(msg interface{}) (err error)
func (*MessageChannel) ReadTimeout ¶
func (mc *MessageChannel) ReadTimeout(msg interface{}, timeout int) (err error)
func (*MessageChannel) RegMsg ¶
func (mc *MessageChannel) RegMsg(msgType int, msg interface{}, fn msgCallback, fns ...msgCallback)
func (*MessageChannel) RemoteAddr ¶
func (mc *MessageChannel) RemoteAddr() net.Addr
func (*MessageChannel) SetMsgErrorHandler ¶
func (mc *MessageChannel) SetMsgErrorHandler(fn func(channel *MessageChannel, rawMsg interface{}, err error))
func (*MessageChannel) Write ¶
func (mc *MessageChannel) Write(msg interface{}) (err error)
type MsgClientOpenConnection ¶
type MsgLogin ¶
func (*MsgLogin) CSTypeString ¶
type MsgResponse ¶
func (*MsgResponse) IsSuccess ¶
func (m *MsgResponse) IsSuccess() bool
type MsgServerClosePort ¶
type MsgServerOpenPort ¶
func (*MsgServerOpenPort) ProtocolString ¶
func (m *MsgServerOpenPort) ProtocolString() string
type MsgServerStatusPort ¶
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) ServerChannel
func (*ServerChannel) ListenTCP ¶
func (sc *ServerChannel) ListenTCP(fn func(channel MessageChannel, conn net.Conn)) (err error)
func (*ServerChannel) ListenTls ¶
func (sc *ServerChannel) ListenTls(fn func(channel MessageChannel, 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 TrafficStatistics ¶
type TrafficStatistics struct { Total TrafficTotal `json="total"` Traffic map[string]map[string]uint64 `json="traffic"` }
type TrafficTotal ¶
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.