Documentation ¶
Index ¶
- Variables
- func LogDebug(a ...interface{})
- func LogInfo(a ...interface{})
- func SetGlobalResend(duration time.Duration)
- func SetGlobalTimeout(duration time.Duration)
- func ShortHash(msg []byte) string
- type BundleCollection
- type CedarCryptoIO
- type CryptoIO
- type CryptoRng
- type Endpoint
- func (ep *Endpoint) AddConnection()
- func (ep *Endpoint) CreateConnection(numberOfConnections int)
- func (ep *Endpoint) ServerStart()
- func (ep *Endpoint) SetOnBundleLost(f FuncBundleLost)
- func (ep *Endpoint) SetOnFiberLost(f FuncFiberLost)
- func (ep *Endpoint) SetOnReceived(f FuncDataReceived)
- func (ep *Endpoint) Write(id uint32, message []byte)
- type Fiber
- type FiberBundle
- func (bd *FiberBundle) Close(err error)
- func (bd *FiberBundle) FiberClosed(fb *Fiber)
- func (bd *FiberBundle) FiberCreated(fb *Fiber)
- func (bd *FiberBundle) GetFiberToWrite() *Fiber
- func (bd *FiberBundle) GetSize() int
- func (bd *FiberBundle) IsClosed() bool
- func (bd *FiberBundle) PacketReceived(pkt *FiberPacket)
- func (bd *FiberBundle) SendMessage(msg []byte) error
- func (bd *FiberBundle) SetOnBundleLost(f FuncBundleLost)
- func (bd *FiberBundle) SetOnFiberLost(f FuncFiberLost)
- func (bd *FiberBundle) SetOnReceived(f FuncDataReceived)
- type FiberPacket
- type FuncBundleLost
- type FuncDataReceived
- type FuncFiberLost
- type HandshakeResult
- type Handshaker
- type KDF
- type SimpleKDF
Constants ¶
This section is empty.
Variables ¶
var DefaultRNG = NewCryptoRng()
var ErrAllFibersLost = errors.New("all fibers lost")
var ErrConnectionTimeout = errors.New("connection timeout")
var ErrDuplicatedBundle = errors.New("duplicated bundle")
var ErrHandshakeFailed = errors.New("handshake failed")
var ErrIllegalPacket = errors.New("packet is illegal")
ErrIllegalPacket is returned when an illegal packet is received.
var GlobalConnectionTimeout = defaultTimeout
GlobalConnectionTimeout is timeout for a connection. This connection would be closed if any read/write operation did not return after this timeout, or if connection did not get any packet in this period of time.
Functions ¶
func SetGlobalResend ¶
func SetGlobalTimeout ¶
Types ¶
type BundleCollection ¶
func NewBundleCollection ¶
func NewBundleCollection() *BundleCollection
func (*BundleCollection) AddBundle ¶
func (bc *BundleCollection) AddBundle(bd *FiberBundle) error
func (*BundleCollection) GetBundle ¶
func (bc *BundleCollection) GetBundle(id uint32) *FiberBundle
func (*BundleCollection) GetMain ¶
func (bc *BundleCollection) GetMain() *FiberBundle
func (*BundleCollection) HasID ¶
func (bc *BundleCollection) HasID(id uint32) bool
func (*BundleCollection) HasMain ¶
func (bc *BundleCollection) HasMain() bool
type CedarCryptoIO ¶
type CedarCryptoIO struct {
// contains filtered or unexported fields
}
CedarCryptoIO is CryptoIO for Cedar.
func NewCedarCryptoIO ¶
func NewCedarCryptoIO(password string) *CedarCryptoIO
NewCedarCryptoIO create a new CedarCryptoIO.
func (CedarCryptoIO) ReadPacket ¶
func (ce CedarCryptoIO) ReadPacket(conn io.ReadWriter) ([]byte, error)
ReadPacket reads a packet of encrypted message from conn. It returns the []byte got and error. When any error occur, the []byte returned is nil.
func (*CedarCryptoIO) SetKey ¶
func (ce *CedarCryptoIO) SetKey(password string)
SetKey sets password for CedarCryptoIO.
func (CedarCryptoIO) WritePacket ¶
func (ce CedarCryptoIO) WritePacket(conn io.ReadWriter, msg []byte) (int, error)
WritePacket writes a block of encrypted message to conn. It returns the size actually wrote (larger than len(msg)) and error.
type CryptoIO ¶
type CryptoIO interface { WritePacket(conn io.ReadWriter, msg []byte) (int, error) ReadPacket(conn io.ReadWriter) ([]byte, error) SetKey(password string) }
CryptoIO is an interface for crypto-writing/reading on a stream.
type Endpoint ¶
type Endpoint struct {
// contains filtered or unexported fields
}
func NewEndpoint ¶
func (*Endpoint) AddConnection ¶
func (ep *Endpoint) AddConnection()
func (*Endpoint) CreateConnection ¶
func (*Endpoint) ServerStart ¶
func (ep *Endpoint) ServerStart()
ServerStart is a endless loop, keep accepting connections
func (*Endpoint) SetOnBundleLost ¶
func (ep *Endpoint) SetOnBundleLost(f FuncBundleLost)
func (*Endpoint) SetOnFiberLost ¶
func (ep *Endpoint) SetOnFiberLost(f FuncFiberLost)
func (*Endpoint) SetOnReceived ¶
func (ep *Endpoint) SetOnReceived(f FuncDataReceived)
type Fiber ¶
type Fiber struct {
// contains filtered or unexported fields
}
func NewFiber ¶
func NewFiber(conn io.ReadWriteCloser, encryptor CryptoIO, bundle *FiberBundle) *Fiber
type FiberBundle ¶
type FiberBundle struct {
// contains filtered or unexported fields
}
func NewFiberBundle ¶
func NewFiberBundle(bufferLen uint32, bundleType string, hsr *HandshakeResult) *FiberBundle
func (*FiberBundle) Close ¶
func (bd *FiberBundle) Close(err error)
func (*FiberBundle) FiberClosed ¶
func (bd *FiberBundle) FiberClosed(fb *Fiber)
FiberClosed is called to notify the bundle that a new fiber closed.
func (*FiberBundle) FiberCreated ¶
func (bd *FiberBundle) FiberCreated(fb *Fiber)
FiberCreated is called to notify the bundle that a new fiber created.
func (*FiberBundle) GetFiberToWrite ¶
func (bd *FiberBundle) GetFiberToWrite() *Fiber
GetFiberToWrite gets a Fiber to write on, for sending message. By design, this function is not thread safe.
func (*FiberBundle) GetSize ¶
func (bd *FiberBundle) GetSize() int
func (*FiberBundle) IsClosed ¶
func (bd *FiberBundle) IsClosed() bool
func (*FiberBundle) PacketReceived ¶
func (bd *FiberBundle) PacketReceived(pkt *FiberPacket)
PacketReceived is called to notify the bundle that a new data packet received.
func (*FiberBundle) SendMessage ¶
func (bd *FiberBundle) SendMessage(msg []byte) error
func (*FiberBundle) SetOnBundleLost ¶
func (bd *FiberBundle) SetOnBundleLost(f FuncBundleLost)
func (*FiberBundle) SetOnFiberLost ¶
func (bd *FiberBundle) SetOnFiberLost(f FuncFiberLost)
func (*FiberBundle) SetOnReceived ¶
func (bd *FiberBundle) SetOnReceived(f FuncDataReceived)
type FiberPacket ¶
type FiberPacket struct {
// contains filtered or unexported fields
}
type FuncBundleLost ¶
type FuncBundleLost func(id uint32)
type FuncDataReceived ¶
type FuncFiberLost ¶
type FuncFiberLost func(id uint32)
type HandshakeResult ¶
type HandshakeResult struct {
// contains filtered or unexported fields
}
type Handshaker ¶
type Handshaker struct {
// contains filtered or unexported fields
}
Handshaker manages the handshakes. It accepts a handshake packet from server's side, and also sends handshake packet from client.
func NewHandshaker ¶
func NewHandshaker(encryptor CryptoIO, bundles *BundleCollection) *Handshaker
func (*Handshaker) ConfirmHandshake ¶
func (hs *Handshaker) ConfirmHandshake(conn io.ReadWriteCloser) (HandshakeResult, error)
func (*Handshaker) RequestAddToBundle ¶
func (hs *Handshaker) RequestAddToBundle(conn io.ReadWriteCloser, id uint32) (HandshakeResult, error)
func (*Handshaker) RequestNewBundle ¶
func (hs *Handshaker) RequestNewBundle(conn io.ReadWriteCloser) (HandshakeResult, error)