Documentation ¶
Index ¶
- Constants
- Variables
- func HashPacket(p *Packet, preSharedKey []byte) []byte
- func IsRequestCmd(c byte) bool
- func IsResponseCmd(c byte) bool
- func IsTcpOnlyCmd(c byte) bool
- func PadRight(in *[]byte, finalSize int) *[]byte
- func Uint32FromBytes(fourBytes []byte) uint32
- func Uint32ToBytes(u uint32) []byte
- func Uint64FromBytes(eightBytes []byte) uint64
- func Uint64ToBytes(u uint64) []byte
- type Packet
Constants ¶
const ( PacketSize = 1500 NamespaceSize = 64 DataValueSize = 1419 CmdCount byte = 'C' CmdPut byte = 'P' CmdPutReplicate byte = 'R' CmdCountNamespace byte = 'N' CmdCountServer byte = 'S' CmdTCPOnlyKeys byte = 'K' CmdTCPOnlyValues byte = 'V' CmdTCPOnlyStore byte = 'T' CmdTCPOnlyRetrieve byte = 'I' // ResError is a Cmd ResError byte = 'E' )
Variables ¶
var ( ErrInvalidPacketSizeTooSmall = errors.New("bad packet: too small, size must be 1500 bytes") ErrInvalidPacketSizeTooLarge = errors.New("bad packet: too large, size must be 1500 bytes") ErrInvalidCommandByte = errors.New("bad packet: invalid command byte") ErrProtocolSpace1 = errors.New("bad packet: expected space 1") ErrProtocolSpace2 = errors.New("bad packet: expected space 1") ErrProtocolSpace3 = errors.New("bad packet: expected space 3") ErrBadHash = errors.New("auth failed: packet hash invalid") ErrBadOutputSize = errors.New("wrong data size during packet construction") )
var StopSymbol = []byte("\n.\n")
Functions ¶
func HashPacket ¶
HashPacket returns an 8 byte slice
func IsRequestCmd ¶
IsRequestCmd indicates if the server should accept this as a command
func IsResponseCmd ¶
IsResponseCmd indicates if the client should accept this as a command
func IsTcpOnlyCmd ¶ added in v0.5.1
func PadRight ¶ added in v0.5.1
PadRight adds char space to make buffer reach desired size. If `in` is larger than `finalSize`, nothing happens.
func Uint32FromBytes ¶
func Uint64FromBytes ¶
Types ¶
type Packet ¶
type Packet struct { Command byte HashBytes []byte // fixed 8 byte number Hash uint64 // fixed 8 byte number MessageIDBytes []byte // fixed 4 byte number MessageID uint32 // fixed 4 byte number Namespace []byte // fixed 64 byte string DataValue []byte // fixed 1419 byte string RequestClient *net.TCPConn }
func NewPacket ¶
NewPacket is a friendlier way to construct a packet and will provide conversions inline
func NewPacketFromParts ¶
func ParsePacket ¶
ParsePacket parses a packet like:
[Command char][space][xxhash of pre shared key + id + ns + data][space][Message ID uint32][space][Namespace 64 bytes][space][data remaining bytes]
The MTU of 1500 is the maximum allowed packet size. That means the data key can only be 1419 bytes max.
The goal here is fast and simple tracking of expirable keys, so the trade off is that the keys have limited length.
An invalid packet may still be returned it can be parsed partially, in which case error will not be nil. If a packet is way too small, the pointer will be nil.
func (*Packet) Bytes ¶
Bytes formats the packet for transport. If the outputted size is wrong for UDP, it will return the packet an allow the client to perhaps truncate.