bundle

package
v0.0.0-...-4bf2d94 Latest Latest
Warning

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

Go to latest
Published: May 29, 2018 License: MIT Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRNG = NewCryptoRng()
View Source
var ErrAllFibersLost = errors.New("all fibers lost")
View Source
var ErrConnectionTimeout = errors.New("connection timeout")
View Source
var ErrDuplicatedBundle = errors.New("duplicated bundle")
View Source
var ErrHandshakeFailed = errors.New("handshake failed")
View Source
var ErrIllegalPacket = errors.New("packet is illegal")

ErrIllegalPacket is returned when an illegal packet is received.

View Source
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 LogDebug

func LogDebug(a ...interface{})

LogDebug prints info

func LogInfo

func LogInfo(a ...interface{})

LogInfo prints info

func SetGlobalResend

func SetGlobalResend(duration time.Duration)

func SetGlobalTimeout

func SetGlobalTimeout(duration time.Duration)

func ShortHash

func ShortHash(msg []byte) string

ShortHash returns a short hash string of message. It starts with "sh" and hex form of hash.

Types

type BundleCollection

type BundleCollection struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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 CryptoRng

type CryptoRng struct {
}

func NewCryptoRng

func NewCryptoRng() *CryptoRng

func (*CryptoRng) Int16

func (c *CryptoRng) Int16() int16

func (*CryptoRng) Int32

func (c *CryptoRng) Int32() int32

func (*CryptoRng) Int64

func (c *CryptoRng) Int64() int64

func (*CryptoRng) Read

func (c *CryptoRng) Read(buf []byte) int

func (*CryptoRng) Uint16

func (c *CryptoRng) Uint16() uint16

func (*CryptoRng) Uint32

func (c *CryptoRng) Uint32() uint32

func (*CryptoRng) Uint64

func (c *CryptoRng) Uint64() uint64

type Endpoint

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

func NewEndpoint

func NewEndpoint(bufferLen uint32, endpointType string, addr string, password string) *Endpoint

func (*Endpoint) AddConnection

func (ep *Endpoint) AddConnection()

func (*Endpoint) CreateConnection

func (ep *Endpoint) CreateConnection(numberOfConnections int)

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)

func (*Endpoint) Write

func (ep *Endpoint) Write(id uint32, message []byte)

type Fiber

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

func NewFiber

func NewFiber(conn io.ReadWriteCloser, encryptor CryptoIO, bundle *FiberBundle) *Fiber

func (*Fiber) Close

func (fb *Fiber) Close(err error)

func (*Fiber) IsClosed

func (fb *Fiber) IsClosed() bool

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 FuncDataReceived func(id uint32, message []byte)

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)

type KDF

type KDF interface {
	Generate(password string, salt string, bit int) []byte
}

KDF is an interface for key derivation function. Number of iterations is fixed.

type SimpleKDF

type SimpleKDF struct {
}

SimpleKDF is a simple and casual KDF.

func (SimpleKDF) Generate

func (SimpleKDF) Generate(password string, salt string, bit int) []byte

Generate accepts password, salt, and number of bits (must be not larger than 512 and divided by 8) and returns a key.

Jump to

Keyboard shortcuts

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