common

package
v0.0.0-...-cb17a1d Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2016 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MsgTypeReq        = 1
	MsgTypeUdpPing    = 2
	MsgTypeUdpPong    = 3
	MsgTypeAddrReq    = 4
	MsgTypeAddrResp   = 5
	MsgTypeHandshake  = 6
	MsgTypeP2pPing    = 7
	MsgTypeP2pPong    = 8
	MsgTypeRegResp    = 9
	MsgTypeP2pTest    = 10
	MsgTypeIPChange   = 11
	MsgTypeUdpValid   = 12
	MsgTypeDoShake    = 13
	MsgTypeTcpPing    = 14
	MsgTypeTcpPong    = 15
	MsgTypeAssistReg  = 16
	MsgTypeAssistResp = 17
	MsgTypeAssPing    = 18
	MsgTypeAssPong    = 19
	MsgTypeClientQuit = 20

	MsgTypeIkcp   = 100
	MsgTypeSyn    = 101
	MsgTypeSynOk  = 102
	MsgTypeSynErr = 103
	MsgTypeFin    = 104
	MsgTypeData   = 105

	MsgHdrSize     = 8
	KindListen     = "listen"
	MessageSeqSize = 128
	MsgSizeSmall   = 1024
	MsgSizeBig     = 2600
	EncryptSize    = 16
	MsgCtlSize     = 16
	MsgXor         = 0x9C

	UdpPongTypeTwoServer = 0
	UdpPongTypeFromAss   = 1
	UdpPongTypeOneServer = 3

	TcpTickCount          = 20
	TcpTimeoutSecCount    = 3 * TcpTickCount
	TcpTimeoutSec         = time.Second * TcpTimeoutSecCount
	TcpAssPingSec         = time.Second * TcpTickCount
	TcpAssReadLoopSec     = TcpTimeoutSec
	TcpAssWriteLoopSec    = time.Second * TcpTickCount
	TcpClientPingSec      = time.Second * TcpTickCount
	TcpClientReadLoopSec  = TcpTimeoutSec
	TcpClientWriteLoopSec = time.Second * TcpTickCount
	UdpP2pPingTick        = 5
	UdpP2pPingSec         = time.Second * UdpP2pPingTick
	UdpP2pPingTimeout     = time.Second * UdpP2pPingTick * 2
	UdpP2pPingClose       = UdpP2pPingTimeout * 3

	AssPass = ""
)

Variables

View Source
var (
	ErrFinished          = errors.New("killable: finished")
	ErrTargetDying       = errors.New("killable: targetDying")
	ErrPromiseEmpty      = errors.New("promise: emptyFuture")
	ErrPromiseNotResolve = errors.New("promise: notResolve")
	ErrPromiseResolving  = errors.New("promise: resolving")
	ErrPromisePDying     = errors.New("promise: parentDying")
)
View Source
var (
	ErrMsgRegExists    = errors.New("message: registNameExists")
	ErrMsgRegNotFound  = errors.New("message: registNameNotFound")
	ErrMsgWrite        = errors.New("message: writeMessageError")
	ErrMsgRead         = errors.New("message: readMessageError")
	ErrMsgSpaceExit    = errors.New("message: spaceExit")
	ErrMsgKilled       = errors.New("message: killedByOther")
	ErrMsgRealEmpty    = errors.New("message: empty real")
	ErrMsgNotSupport   = errors.New("message: notSupport")
	ErrMsgNone         = errors.New("message: none")
	ErrMsgShakeTimeout = errors.New("message: shakeTimeout")
	ErrMsgPanic        = errors.New("message: Panic")
)

Functions

func FixHash

func FixHash(b []byte) []byte

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

func Info

func Info(format string, v ...interface{})

func MsgPoolInit

func MsgPoolInit()

func SetLevel

func SetLevel(l int)

func UnpackUdp

func UnpackUdp(msg *Msg, uBuf []byte) error

func Warn

func Warn(format string, v ...interface{})

func WriteTcpMsg

func WriteTcpMsg(c net.Conn, m *Msg) error

func WriteTcpReal

func WriteTcpReal(seq uint16, typ uint8, from uint8, lport uint16, o interface{}, c net.Conn) error

func WriteUdpConnOnly

func WriteUdpConnOnly(block cipher.Block, iv []byte, data []byte, dest *net.UDPAddr, udpConn *net.UDPConn) error

write ikcp data

func WriteUdpMsg

func WriteUdpMsg(block cipher.Block, iv []byte, m *Msg, dest *net.UDPAddr, udpConn *net.UDPConn) error

func WriteUdpMsgServer

func WriteUdpMsgServer(m *Msg, addr *net.UDPAddr, udpConn *net.UDPConn) error

Types

type Future

type Future struct {
	Resp chan *FutureResp
	Task PromiseTask
	Arg  interface{}
	F    FutureCallback
}

type FutureCallback

type FutureCallback func(in *Future, arg interface{}) *FutureResp

type FutureChainFunction

type FutureChainFunction func(pt PromiseTask, arg interface{}) (PromiseTask, interface{}, error)

type FutureResp

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

type Msg

type Msg struct {
	Hdr MsgHdr

	Real interface{}
	V    interface{}
	// contains filtered or unexported fields
}

FIXME: origin CANOT makeSlice

func NewMsg

func NewMsg(bsize int) *Msg

func ReadTcpMsg

func ReadTcpMsg(c net.Conn) (*Msg, error)

func (*Msg) Dup

func (m *Msg) Dup() *Msg

func (*Msg) Free

func (m *Msg) Free()

func (*Msg) GetOrigin

func (m *Msg) GetOrigin() *bytes.Buffer

func (*Msg) GetReal

func (m *Msg) GetReal() interface{}

TODO what if nil

func (*Msg) ResetBuffer

func (m *Msg) ResetBuffer(bsize int)

Ignore the prefix buffer and request a new. Caution for this func, should only use one time at first !!!

type MsgAssistReg

type MsgAssistReg struct {
	Addr string
	Pass string
}

type MsgBuf

type MsgBuf struct {
	Start int
	Size  int
	Type  int
	// contains filtered or unexported fields
}

func NewMsgBuf

func NewMsgBuf() *MsgBuf

func (*MsgBuf) Dup

func (mb *MsgBuf) Dup() *MsgBuf

func (*MsgBuf) Free

func (mb *MsgBuf) Free()

func (*MsgBuf) GetBuf

func (mb *MsgBuf) GetBuf() []byte

func (*MsgBuf) GetReal

func (mb *MsgBuf) GetReal() []byte

type MsgClientQuit

type MsgClientQuit struct {
	ClientId int
}

type MsgHandshake

type MsgHandshake struct {
	//Sendto addr, only choose by request side
	RAddr  string
	Choose string
	Cands  []string
}

type MsgHdr

type MsgHdr struct {
	Type uint8
	Addr uint8
	Port uint16
	Len  uint16
	Seq  uint16
}

type MsgHook

type MsgHook struct {
	Seq  int
	Resp chan *Msg
}

func NewMsgHook

func NewMsgHook(c MsgHooker, seq int) *MsgHook

func (*MsgHook) Wait

func (mhook *MsgHook) Wait(c MsgHooker, killed <-chan struct{}, timesec time.Duration) (*Msg, error)

Have to free the msg

type MsgHooker

type MsgHooker interface {
	HookAdd() chan *MsgHook
	HookDel() chan int
	Dying() <-chan struct{}
}

type MsgP2pPing

type MsgP2pPing struct {
	From int
}

type MsgP2pPong

type MsgP2pPong struct {
	From int
}

type MsgPool

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

type MsgReg

type MsgReg struct {
	Name  string
	Pass  string
	Kind  string
	Items []TunnelItem
	Iv    string
}

type MsgRegResp

type MsgRegResp struct {
	ClientId int
	IP       string
	Items    []TunnelItem
	Iv       string
	Status   string
}

type MsgReqAddr

type MsgReqAddr struct {
	From      int
	To        int
	FromPub   string
	FromPub2  string
	FromAddrs []string
	ToPub     string
	ToPub2    string
	Addrs     []string
}

NewHandshake, send from tcp channel

type MsgTcpPong

type MsgTcpPong struct {
}

type MsgUdpPong

type MsgUdpPong struct {
	Type     int
	Space    string
	ClientId int
	Addr     string
	Alter    string
	Random   int
}

type Promise

type Promise struct {
	killable.Killable
	// contains filtered or unexported fields
}

Not real promise but like promise

func NewPromise

func NewPromise(parent killable.Killable) *Promise

func (*Promise) Dying

func (p *Promise) Dying() <-chan struct{}

func (*Promise) GetValue

func (p *Promise) GetValue() (interface{}, error)

func (*Promise) PDying

func (p *Promise) PDying() <-chan struct{}

func (*Promise) Resolve

func (p *Promise) Resolve(pt PromiseTask, v interface{}) *Promise

func (*Promise) Run

func (p *Promise) Run() error

func (*Promise) Then

func (p *Promise) Then(f FutureChainFunction) *Promise

type PromiseTask

type PromiseTask interface {
	killable.Killable
	Calls() chan *Future
}

type TunnelItem

type TunnelItem struct {
	ProxyAddr string
	LocalAddr string
}

Jump to

Keyboard shortcuts

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