multicode

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KEEP_ALIVE_RESOLUTION = 4
	RELIABLE_CHANNEL_ID   = byte(0)
	UNRELIABLE_CHANNEL_ID = byte(1)
)
View Source
const (
	MAX_PACKET_HEADER_BYTES = 10
	FRAGMENT_HEADER_BYTES   = 6
	NULL_SEQUENCE           = uint32(0xFFFFFFFF)
)
View Source
const FRAGMENT_SIZE = 1024
View Source
const MAX_CLIENTS = 1024

Not a true connection limit, only used to initialise/allocate various buffer and data structure sizes.

Variables

View Source
var ErrClientInstanceClosed = errors.New("client instance closed")
View Source
var ErrClientInstanceNotConnected = errors.New("client instance not connected")
View Source
var ErrClientInstanceSendBufferFull = errors.New("client instance reliable send buffer full")
View Source
var ErrClientInstanceUnreliableDataTooLarge = errors.New("client instance unreliable data too large")
View Source
var ErrReliablePacketControllerPacketDataTooLarge = errors.New("reliable packet controller packet data too large")
View Source
var ErrValueOutOfRange = errors.New("variable length value out of range")

Functions

func GetVariableLengthBytes

func GetVariableLengthBytes(val uint16) (int, error)

func PacketMaxValues

func PacketMaxValues(maxPacketSizeBytes int64) (int, int, error)

func ReadFragmentHeader

func ReadFragmentHeader(packetBuffer []byte, offset, bufferLength, maxFragments, fragmentSize int) (int, int, int, int, uint16, uint16, uint32, byte, error)

func ReadPacketHeader

func ReadPacketHeader(packetBuffer []byte, offset, bufferLength int) (int, byte, uint16, uint16, uint32, error)

func ReadVariableLengthUint16

func ReadVariableLengthUint16(rw *ByteArrayReaderWriter) (uint16, error)

func SequenceGreaterThan

func SequenceGreaterThan(s1, s2 uint16) bool

func SequenceLessThan

func SequenceLessThan(s1, s2 uint16) bool

func WriteAckPacket

func WriteAckPacket(packetBuffer []byte, channelID byte, ack uint16, ackBits uint32) int

func WritePacketHeader

func WritePacketHeader(packetBuffer []byte, channelID byte, sequence uint16, ack uint16, ackBits uint32) int

func WriteVariableLengthUint16

func WriteVariableLengthUint16(val uint16, rw *ByteArrayReaderWriter) error

Types

type BufferedPacket

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

func (*BufferedPacket) Resize

func (b *BufferedPacket) Resize(size int)

type ByteArrayReaderWriter

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

func NewByteArrayReaderWriter

func NewByteArrayReaderWriter(data []byte) *ByteArrayReaderWriter

TODO Cache and reuse?

func (*ByteArrayReaderWriter) ReadBuffer

func (s *ByteArrayReaderWriter) ReadBuffer(buf []byte, length int) error

func (*ByteArrayReaderWriter) ReadByte

func (s *ByteArrayReaderWriter) ReadByte() (byte, error)

func (*ByteArrayReaderWriter) ReadUint16

func (s *ByteArrayReaderWriter) ReadUint16() (uint16, error)

func (*ByteArrayReaderWriter) SeekRead

func (s *ByteArrayReaderWriter) SeekRead(offset int) int

Reset the read position in the stream to the given offset relative to the beginning of the stream.

func (*ByteArrayReaderWriter) SeekWrite

func (s *ByteArrayReaderWriter) SeekWrite(offset int) int

Reset the read position in the stream to the given offset relative to the beginning of the stream.

func (*ByteArrayReaderWriter) WriteBuffer

func (s *ByteArrayReaderWriter) WriteBuffer(buf []byte, length int)

func (*ByteArrayReaderWriter) WriteByte

func (s *ByteArrayReaderWriter) WriteByte(b byte)

func (*ByteArrayReaderWriter) WriteUint16

func (s *ByteArrayReaderWriter) WriteUint16(u uint16)

type ClientInstance

type ClientInstance struct {
	sync.Mutex

	Address *net.UDPAddr

	ExpiresAt  int64
	UserData   []byte
	ProtocolId uint64
	// contains filtered or unexported fields
}

func NewClientInstance

func NewClientInstance(logger *zap.Logger, addr *net.UDPAddr, serverConn *NetcodeConn, closeClientFn func(*ClientInstance, bool), expiry uint64, protocolId uint64, timeoutMs int64, sendKey []byte, recvKey []byte, maxPacketSize int, maxPacketFragments int) *ClientInstance

func (*ClientInstance) Close

func (c *ClientInstance) Close(sendDisconnect bool)

func (*ClientInstance) IsConnected

func (c *ClientInstance) IsConnected() bool

func (*ClientInstance) Read

func (c *ClientInstance) Read() ([]byte, bool, error)

An external routine is expected to continuously call this, otherwise no input attributed to this client instance will be processed.

func (*ClientInstance) Send

func (c *ClientInstance) Send(payloadData []byte, reliable bool) error

NOTE: Only for payload data packets, other protocol-level messages MUST be sent through other functions.

type FragmentReassemblyPacketData

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

func NewFragmentReassemblyPacketData

func NewFragmentReassemblyPacketData() *FragmentReassemblyPacketData

func (*FragmentReassemblyPacketData) Clear

func (d *FragmentReassemblyPacketData) Clear()

func (*FragmentReassemblyPacketData) StoreFragmentData

func (d *FragmentReassemblyPacketData) StoreFragmentData(channelID byte, sequence uint16, ack uint16, ackBits uint32, fragmentID int, fragmentSize int, fragmentData []byte, fragmentBytes int)

type NetcodeConn

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

func NewNetcodeConn

func NewNetcodeConn(logger *zap.Logger, recvSize int, sendSize int, recvHandlerFn func(data *NetcodeData)) *NetcodeConn

func (*NetcodeConn) Close

func (c *NetcodeConn) Close() error

func (*NetcodeConn) Listen

func (c *NetcodeConn) Listen(address *net.UDPAddr) error

func (*NetcodeConn) WriteTo

func (c *NetcodeConn) WriteTo(b []byte, to *net.UDPAddr) (int, error)

type NetcodeData

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

type PacketSet

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

type ReceivedPacketData

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

type ReliablePacketController

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

func NewReliablePacketController

func NewReliablePacketController(maxPacketSize int, maxPacketFragments int) *ReliablePacketController

func (*ReliablePacketController) ReceivePacket

func (r *ReliablePacketController) ReceivePacket(time int64, packetData []byte, bufferLength int) (uint16, []byte, int, []uint16, error)

func (*ReliablePacketController) SendAck

func (r *ReliablePacketController) SendAck(channelID byte) ([]byte, int)

func (*ReliablePacketController) SendPacket

func (r *ReliablePacketController) SendPacket(time int64, packetData []byte, length int, channelID byte) (uint16, [][]byte, []int, error)

func (*ReliablePacketController) Update

func (r *ReliablePacketController) Update()

type SentPacketData

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

type SequenceBufferOutgoing

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

func NewSequenceBufferOutgoing

func NewSequenceBufferOutgoing(bufferSize int) *SequenceBufferOutgoing

func (*SequenceBufferOutgoing) Find

func (s *SequenceBufferOutgoing) Find(sequence uint16) *PacketSet

func (*SequenceBufferOutgoing) Insert

func (s *SequenceBufferOutgoing) Insert(sequence uint16) *PacketSet

func (*SequenceBufferOutgoing) RemoveEntries

func (s *SequenceBufferOutgoing) RemoveEntries(startSequence, finishSequence int32)

type SequenceBufferPacket

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

func NewSequenceBufferPacket

func NewSequenceBufferPacket(bufferSize int) *SequenceBufferPacket

func (*SequenceBufferPacket) Exists

func (s *SequenceBufferPacket) Exists(sequence uint16) bool

func (*SequenceBufferPacket) Find

func (s *SequenceBufferPacket) Find(sequence uint16) *BufferedPacket

func (*SequenceBufferPacket) Insert

func (s *SequenceBufferPacket) Insert(sequence uint16) *BufferedPacket

func (*SequenceBufferPacket) Remove

func (s *SequenceBufferPacket) Remove(sequence uint16)

func (*SequenceBufferPacket) RemoveEntries

func (s *SequenceBufferPacket) RemoveEntries(startSequence, finishSequence int32)

type SequenceBufferReassembly

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

func NewSequenceBufferReassembly

func NewSequenceBufferReassembly(bufferSize int) *SequenceBufferReassembly

func (*SequenceBufferReassembly) Find

func (*SequenceBufferReassembly) Insert

func (*SequenceBufferReassembly) Remove

func (s *SequenceBufferReassembly) Remove(sequence uint16)

func (*SequenceBufferReassembly) RemoveEntries

func (s *SequenceBufferReassembly) RemoveEntries(startSequence, finishSequence int32)

type SequenceBufferReceived

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

func NewSequenceBufferReceived

func NewSequenceBufferReceived(bufferSize int) *SequenceBufferReceived

func (*SequenceBufferReceived) Exists

func (s *SequenceBufferReceived) Exists(sequence uint16) bool

func (*SequenceBufferReceived) Find

func (*SequenceBufferReceived) GenerateAckBits

func (s *SequenceBufferReceived) GenerateAckBits() (uint16, uint32)

func (*SequenceBufferReceived) Insert

func (s *SequenceBufferReceived) Insert(sequence uint16) *ReceivedPacketData

func (*SequenceBufferReceived) RemoveEntries

func (s *SequenceBufferReceived) RemoveEntries(startSequence, finishSequence int32)

func (*SequenceBufferReceived) TestInsert

func (s *SequenceBufferReceived) TestInsert(sequence uint16) bool

type SequenceBufferSent

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

func NewSequenceBufferSent

func NewSequenceBufferSent(bufferSize int) *SequenceBufferSent

func (*SequenceBufferSent) Find

func (s *SequenceBufferSent) Find(sequence uint16) *SentPacketData

func (*SequenceBufferSent) Insert

func (s *SequenceBufferSent) Insert(sequence uint16) *SentPacketData

func (*SequenceBufferSent) RemoveEntries

func (s *SequenceBufferSent) RemoveEntries(startSequence, finishSequence int32)

type Server

type Server struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewServer

func NewServer(logger *zap.Logger, listenAddr, publicAddr *net.UDPAddr, privateKey []byte, protocolId uint64, maxPacketSizeBytes int64, onConnect func(*ClientInstance), timeoutMs int64) (*Server, error)

func (*Server) Listen

func (s *Server) Listen() error

func (*Server) Stop

func (s *Server) Stop()

Jump to

Keyboard shortcuts

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