package packet
import "github.com/Diarkis/diarkis/packet"
Index
- func BoolToBytes(val bool) []byte
- func BytesListToBytes(list [][]byte) []byte
- func BytesToBool(bytes []byte) bool
- func BytesToBytesList(bytes []byte) [][]byte
- func BytesToBytesListMin(bytes []byte) [][]byte
- func BytesToFloat64(bytes []byte) float64
- func BytesToFloat64Map(bytes []byte) map[string]float64
- func BytesToStringList(bytes []byte) []string
- func CreateHolePunchingPacket(uid string, syn bool, ack bool, hook func([]byte) []byte) ([]byte, error)
- func CreateP2PInternalPacket(flags *P2PInternalFlags, payload []byte, hook func([]byte) []byte) ([]byte, error)
- func CreateP2PPacket(flag uint8, seq uint32, payload []byte) ([]byte, error)
- func CreatePingReplyPacket(sid []byte) ([]byte, error)
- func CreatePingTryPacket(sid []byte) ([]byte, error)
- func Float64MapToBytes(m map[string]float64) []byte
- func Float64ToBytes(v float64) []byte
- func PackChatHistory(packedChatHistory [][]byte) []byte
- func PackChatMessage(senderID string, timestamp int64, message string) []byte
- func StringListToBytes(list []string) []byte
- type P2PInternalFlags
- type P2PPacket
- type ReliableFlag
- type UDPHeader
Functions
func BoolToBytes
func BoolToBytes(val bool) []byte
BoolToBytes converts bool to bytes
func BytesListToBytes
func BytesListToBytes(list [][]byte) []byte
BytesListToBytes converts an array of byte array to byte array
func BytesToBool
func BytesToBool(bytes []byte) bool
BytesToBool converts bytes to bool
func BytesToBytesList
func BytesToBytesList(bytes []byte) [][]byte
BytesToBytesList converts a byte array to an array of byte array
func BytesToBytesListMin
func BytesToBytesListMin(bytes []byte) [][]byte
BytesToBytesListMin converts a byte array to an array of byte array(used by state sync)
func BytesToFloat64
func BytesToFloat64(bytes []byte) float64
BytesToFloat64 converts a byte array to a float64
func BytesToFloat64Map
func BytesToFloat64Map(bytes []byte) map[string]float64
BytesToFloat64Map converts a byte array to a map[string]float64
func BytesToStringList
func BytesToStringList(bytes []byte) []string
BytesToStringList Converts a byte array to an array of strings
func CreateHolePunchingPacket
func CreateHolePunchingPacket(uid string, syn bool, ack bool, hook func([]byte) []byte) ([]byte, error)
CreateHolePunchingPacket creates a P2P packet for hole punching The hook function is used to modify the payload before sending. (primarily for encryption)
func CreateP2PInternalPacket
func CreateP2PInternalPacket(flags *P2PInternalFlags, payload []byte, hook func([]byte) []byte) ([]byte, error)
CreateP2PInternalPacket creates a P2P packet which is not handled by Application
func CreateP2PPacket
func CreateP2PPacket(flag uint8, seq uint32, payload []byte) ([]byte, error)
CreateP2PPacket creates a P2P packet
func CreatePingReplyPacket
func CreatePingReplyPacket(sid []byte) ([]byte, error)
CreatePingReplyPacket creates a P2P packet for connectivity check reply
func CreatePingTryPacket
func CreatePingTryPacket(sid []byte) ([]byte, error)
CreatePingTryPacket creates a P2P packet for connectivity check
func Float64MapToBytes
func Float64MapToBytes(m map[string]float64) []byte
Float64MapToBytes converts a map[string]float64 to a byte array
func Float64ToBytes
func Float64ToBytes(v float64) []byte
Float64ToBytes converts a float64 to a byte array
func PackChatHistory
func PackChatHistory(packedChatHistory [][]byte) []byte
PackChatHistory creates a byte array of list of chat data packed by PackChatMessage
func PackChatMessage
func PackChatMessage(senderID string, timestamp int64, message string) []byte
PackChatMessage creates a chat message data byte array
func StringListToBytes
func StringListToBytes(list []string) []byte
StringListToBytes Converts an array of strings to byte array
Types
type P2PInternalFlags
type P2PInternalFlags struct { HolePunchAck bool HolePunchSyn bool Fin bool KeepAlive bool }
P2PInternalFlags is the flags for P2PInternalPacket mainly for hole punching
func ParseP2PInternalFlags
func ParseP2PInternalFlags(packet []byte) *P2PInternalFlags
ParseP2PInternalFlags parses the flags from a P2P internal packet
func (*P2PInternalFlags) String
func (flags *P2PInternalFlags) String() string
type P2PPacket
type P2PPacket struct { IsInternal bool IsPingTry bool IsPingReply bool IsSplit bool UDPHeader *UDPHeader Flags *P2PInternalFlags Payload []byte }
P2PPacket is a parsed structure of a P2P packet
func ParseP2PPacket
func ParseP2PPacket(packet []byte, hook func([]byte) []byte) (*P2PPacket, bool)
ParseP2PPacket checks if the byte array is a P2P packet. If it is, it parses a P2P packet into the flags and the payload The hook function is used to modify the payload before parsing. (primarily for decryption) We need to decrypt at this point because internal flags are inside the encrypted payload We cannot decrypt split packets here as the split is done after encryption so we need to try decrypting in the later process again
type ReliableFlag
type ReliableFlag uint8
ReliableFlag is a flag for UDP packets that indicates the reliability of the packet
const ( // Unreliable is a flag for UDP packets that we do not guarantee delivery and order Unreliable ReliableFlag = iota // Reliable is a flag for RUDP packets that we guarantee delivery but not order Reliable // ReliableOrdered is a flag for RUDP packets that we guarantee delivery and order ReliableOrdered )
func (ReliableFlag) String
func (r ReliableFlag) String() string
String returns the string representation of the ReliableFlag
type UDPHeader
type UDPHeader struct { Flag uint8 Seq uint32 }
UDPHeader UDP packet protocol header