Documentation
¶
Index ¶
Constants ¶
const ( DefaultKeepaliveInterval = time.Second * 10 DefaultReadTimeout = time.Minute DefaultWriteTimeout = time.Minute )
const ProtocolId = 0xF2
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
type ProtocolMessage ¶
type ProtocolMessage struct {
Id ProtocolMessageID
Data []byte
}
ProtocolMessage represents a single message sent over the wire.
func NewProtocolMessage ¶
func NewProtocolMessage(id ProtocolMessageID, data []byte) ProtocolMessage
func (ProtocolMessage) Serialize ¶
func (p ProtocolMessage) Serialize() []byte
Serialize the message into a byte slice.
type ProtocolMessageBuffer ¶
type ProtocolMessageBuffer struct {
// contains filtered or unexported fields
}
ProtocolMessageBuffer
The protocol message buffer is used to buffer incoming messages. Given that TCP is a stream protocol, incoming bytes are buffered until we have a full message. Once a full message is received, it is parsed and emitted on the message channel of the buffer.
func NewProtocolMessageBuffer ¶
func NewProtocolMessageBuffer() *ProtocolMessageBuffer
func (*ProtocolMessageBuffer) Add ¶
func (pmb *ProtocolMessageBuffer) Add(b []byte, processNow bool) error
Add bytes to the buffer. The flag processNow indicates whether the buffer should be processed immediately. If false, the buffer will be only processed by calling ProcessBytes() manually. A possible use case is to accumulate multiple messages into a single buffer before processing them, or to have a concurrent message buffer that processes messages in the background. If true will process the bytes immediately. Note that this will panic if ProcessBytes() is called concurrently.
func (*ProtocolMessageBuffer) ProcessBytes ¶
func (pmb *ProtocolMessageBuffer) ProcessBytes() error
ProcessBytes processes all buffered bytes. This function will block until all bytes have been processed. It will panic if called concurrently.
type ProtocolMessageBufferState ¶
type ProtocolMessageBufferState byte
ProtocolMessageBufferState represents the state of the message buffer, used to parse incoming messages.
const ( PMBNeutral ProtocolMessageBufferState = iota PMBId PMBDataLength PMBData )
type ProtocolMessageID ¶
type ProtocolMessageID byte
const ( IdHandshake ProtocolMessageID = 0x00 IdHandshakeAck ProtocolMessageID = 0x01 IdKeepAlive ProtocolMessageID = 0x02 IdDataMessage ProtocolMessageID = 0x03 IdClose ProtocolMessageID = 0x04 )
type ProtocolSession ¶
type ProtocolSession struct {
// contains filtered or unexported fields
}
type SessionSide ¶
type SessionSide bool
SessionSide represents the side of the connection. Used in the handshake and in keepalive messages.
const ( Server SessionSide = true Client SessionSide = false )
type SessionState ¶
type SessionState byte
SessionState represents the state of a protocol session, primarily used in the handshake.
const ( SessionStateNew SessionState = iota // Initial state, no handshake sent yet SessionStateHandshakeSent // Handshake sent, waiting for handshake ack SessionStateConnected // Server: Handshake ack sent, client: Handshake ack received SessionStateClosed // Connection closed )