...

Package packet

import "github.com/Diarkis/diarkis/packet"
Overview
Index

Overview ▾

Index ▾

Constants
Variables
func BytesListToBytes(list [][]byte) []byte
func BytesToBytesList(bytes []byte) [][]byte
func BytesToStringList(bytes []byte) []string
func CreatePushPacket(version uint8, commandID uint16, payload []byte) []byte
func CreateReconnectPayload(addr string) []byte
func CreateRequestPacket(version uint8, commandID uint16, payload []byte) []byte
func CreateResponsePacket(version uint8, commandID uint16, status uint8, payload []byte) []byte
func CreateSecureRequestPayload(sid []byte, key []byte, iv []byte, mackey []byte, payload []byte) ([]byte, error)
func CreateSecureResponsePayload(key []byte, iv []byte, mackey []byte, payload []byte) ([]byte, error)
func CreateSplitPacket(id uint16, bytes []byte, splitSize int) [][]byte
func CreateUDPPacket(flag uint8, seq uint32, packet []byte) ([]byte, error)
func GetSidFromPayload(payload []byte) ([]byte, []byte)
func GetSplitPacketID(bytes []byte) uint16
func IsInvalidPacketErr(err error) bool
func IsPushPacket(status uint8) bool
func IsSplitPacket(bytes []byte) bool
func ParseReconnectPayload(payload []byte) string
func ParseUDPPacket(packet []byte) (uint8, uint32, []byte, error)
func StringListToBytes(list []string) []byte
type RequestHeader
type RequestPacket
    func ParseRequestPacket(packet []byte) (*RequestPacket, int, error)
type ResponseHeader
type ResponsePacket
    func ParseResponsePacket(packet []byte) (*ResponsePacket, int, error)
type SplitPacket
    func NewSplitPacket(bytes []byte) *SplitPacket
    func (sp *SplitPacket) Add(bytes []byte) error
    func (sp *SplitPacket) ConsumeBytes() ([]byte, bool)

Constants

HeaderSize Size of the packet header

const HeaderSize int = 10

StatusBad response status

const StatusBad uint8 = 0x01

StatusOk response status

const StatusOk uint8 = 0x00

StatusPush response status of push

const StatusPush uint8 = 0xff

UDPProtoHeaderSize Size of the UDP packet protocol header

const UDPProtoHeaderSize int = 4

Variables

RUDPProtoAck RUDP packet protocol header flag for RUDP ack this flag indicates that the packet is to be treated as the ack packet of dat packet reception

var RUDPProtoAck uint8 = 0x4

RUDPProtoDat RUDP packet protocol header flag for RUDP data this flag indicates that the packet is to be treated as the data packet carrying the actual data payload after syn packet

var RUDPProtoDat uint8 = 0x3

RUDPProtoEack RUDP packet protocol header flag for RUDP eack this flag indicates that the packet is to be trated as the eack of rst packet

var RUDPProtoEack uint8 = 0x6

RUDPProtoFin UDP packet protocol header flag for RUDP fin this flag indicates that the packet is to be treated as the fin packet of RUDP to end RUDP communication

var RUDPProtoFin uint8 = 0x7

RUDPProtoRst RUDP packet protocol header flag for RUDP rst this flag indicates that the packet is to be treated as the retry of dat packet

var RUDPProtoRst uint8 = 0x5

RUDPProtoSyn RUDP packet protocol header flag for RUDP initial syn this flag indicates that the packet is to be treated as the initial URUDP seq synchronization packet

var RUDPProtoSyn uint8 = 0x2

UDPProto UDP packet protocol header flag for UDP this flag indicates the packet is to be treated as a plain UDP packet

var UDPProto uint8 = 0x1

func BytesListToBytes

func BytesListToBytes(list [][]byte) []byte

BytesListToBytes converts an array of byte array to byte array

func BytesToBytesList

func BytesToBytesList(bytes []byte) [][]byte

BytesToBytesList converts a byte array to an array of byte array

func BytesToStringList

func BytesToStringList(bytes []byte) []string

BytesToStringList Converts a byte array to an array of strings

func CreatePushPacket

func CreatePushPacket(version uint8, commandID uint16, payload []byte) []byte

CreatePushPacket Creates a push packet

func CreateReconnectPayload

func CreateReconnectPayload(addr string) []byte

CreateReconnectPayload Creates a payload to instruct the client to reconnect

func CreateRequestPacket

func CreateRequestPacket(version uint8, commandID uint16, payload []byte) []byte

CreateRequestPacket Creates a request packet

func CreateResponsePacket

func CreateResponsePacket(version uint8, commandID uint16, status uint8, payload []byte) []byte

CreateResponsePacket Creates a response packet - by giving StatusPush as status, it creates a push packet

func CreateSecureRequestPayload

func CreateSecureRequestPayload(sid []byte, key []byte, iv []byte, mackey []byte, payload []byte) ([]byte, error)

CreateSecureRequestPayload Creates an encrypted request packet payload

func CreateSecureResponsePayload

func CreateSecureResponsePayload(key []byte, iv []byte, mackey []byte, payload []byte) ([]byte, error)

CreateSecureResponsePayload Creates an encrypted response packet payload

func CreateSplitPacket

func CreateSplitPacket(id uint16, bytes []byte, splitSize int) [][]byte

CreateSplitPacket creates an array of split packets

func CreateUDPPacket

func CreateUDPPacket(flag uint8, seq uint32, packet []byte) ([]byte, error)

CreateUDPPacket Creates a UDP packet from the byte array created by CreateRequestPacket(), CreateResponsePacket(), and CreatePushPacket()

func GetSidFromPayload

func GetSidFromPayload(payload []byte) ([]byte, []byte)

GetSidFromPayload Returns sid (session ID) and encrypted payload from the given payload

func GetSplitPacketID

func GetSplitPacketID(bytes []byte) uint16

GetSplitPacketID returns the ID of split packet

func IsInvalidPacketErr

func IsInvalidPacketErr(err error) bool

IsInvalidPacketErr Returns true if the given error is an invalid packet error

func IsPushPacket

func IsPushPacket(status uint8) bool

IsPushPacket Returns true if the given packet status is a push packet

func IsSplitPacket

func IsSplitPacket(bytes []byte) bool

IsSplitPacket returns true if the evaluated bytes is a split packet chunk

func ParseReconnectPayload

func ParseReconnectPayload(payload []byte) string

ParseReconnectPayload converts the given payload to reconnect address

func ParseUDPPacket

func ParseUDPPacket(packet []byte) (uint8, uint32, []byte, error)

ParseUDPPacket Parses a packet created by CreateUDPPacket()

func StringListToBytes

func StringListToBytes(list []string) []byte

StringListToBytes Converts an array of strings to byte array

type RequestHeader

RequestHeader Request header data structure

type RequestHeader struct {
    Version     uint8
    CommandID   uint16
    PayloadSize uint32
}

type RequestPacket

RequestPacket Request packet data structure

type RequestPacket struct {
    Header  *RequestHeader
    Payload []byte
}

func ParseRequestPacket

func ParseRequestPacket(packet []byte) (*RequestPacket, int, error)

ParseRequestPacket Parses a request packet

type ResponseHeader

ResponseHeader Response header data structure

type ResponseHeader struct {
    Version     uint8
    CommandID   uint16
    PayloadSize uint32
    Status      uint8
}

type ResponsePacket

ResponsePacket Response packet data structure

type ResponsePacket struct {
    Header  *ResponseHeader
    Payload []byte
    Push    bool
}

func ParseResponsePacket

func ParseResponsePacket(packet []byte) (*ResponsePacket, int, error)

ParseResponsePacket Parses a response packet

type SplitPacket

SplitPacket a packet that are split into smaller chunks

type SplitPacket struct {
    ID uint16

    sync.RWMutex
    // contains filtered or unexported fields
}

func NewSplitPacket

func NewSplitPacket(bytes []byte) *SplitPacket

NewSplitPacket creates a split packet receiver

func (*SplitPacket) Add

func (sp *SplitPacket) Add(bytes []byte) error

Add adds split packet chunk to split packet receiver

func (*SplitPacket) ConsumeBytes

func (sp *SplitPacket) ConsumeBytes() ([]byte, bool)

ConsumeBytes returns the reconstructed split bytes