packets1

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2022 License: EPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package packets1 implements MQTT-SN version 1.2 packets structs.

Index

Constants

View Source
const (
	AUTH_SUCCESS        uint8 = 0
	AUTH_CONTINUE       uint8 = 0x18
	AUTH_REAUTHENTICATE uint8 = 0x19
)

Authentication reason constants.

View Source
const (
	TIT_REGISTERED uint8 = iota
	TIT_PREDEFINED
	TIT_SHORT
)

TopicID type constants.

View Source
const (
	AUTH_PLAIN = "PLAIN"
)

Auth method constants.

View Source
const MaxPacketLen = 8192

MQTT-SN specification version 1.2, section 5.2.1 defines maximal packet size to be 65535B but pion/udp and pion/dtls use maximal packet size of 8192B. See e.g.: - https://github.com/pion/udp/blob/b66c29020370bbb21647c27cf0b5ac50a18677f7/conn.go#L17 - https://github.com/pion/dtls/blob/3dc563b9aede91561ece5ae14b6ec6edf6fc5eb9/conn.go#L30 An effective MQTT-SN maximal packet size is even a few bytes smaller: for UDP transport: PUBLISH with 8183B-long payload = 8192B total packet length for DTLS transport: PUBLISH with 8146B-long payload = 8155B total packet length (I'm not sure if the DTLS maximal length is affected by the cipher used or not)

The MQTT-SN specification presuppose such packet length limit imposed by the network layer:

Note that because MQTT-SN does not support message fragmentation and reassembly, the maximum message length that could be used in a network is governed by the maximum packet size that is supported by that network, and not by the maximum length that could be encoded by MQTT-SN. [MQTT-SN specification v. 1.2, chapter 5.2.1 Length]

View Source
const MaxPayloadLength = 7168

Because I'm not sure about maximal DTLS header length, we have decided to use this arbitrary "small enough to be safe" maximal payload length.

View Source
const TIT_STRING = uint8(0)

Whole topic string included in the packet (SUBSCRIBE packet only).

Variables

This section is empty.

Functions

func NewPacketWithHeader

func NewPacketWithHeader(h pkts.Header) (pkt pkts.Packet)

NewPacketWithHeader returns a particular packet struct with a given header. The struct type is determined by h.msgType.

func ReadPacket

func ReadPacket(r io.Reader) (pkt pkts.Packet, err error)

ReadPacket reads an MQTT-SN packet from the given io.Reader. BEWARE: The reader must be a "packet reader" - i.e. it must return one whole packet per every Read() call.

Types

type Advertise struct {
	pkts.Header
	// Fields
	GatewayID uint8
	Duration  uint16
}

func NewAdvertise

func NewAdvertise(gatewayID uint8, duration uint16) *Advertise

func (*Advertise) Pack

func (p *Advertise) Pack() ([]byte, error)

func (Advertise) String

func (p Advertise) String() string

func (*Advertise) Unpack

func (p *Advertise) Unpack(buf []byte) error

type Auth

type Auth struct {
	pkts.Header
	// Fields
	Reason uint8
	Method string
	Data   []byte
}

Non-standard extension to allow user/password authentication in MQTT-SN.

Implemented according to the OASIS Open MQTT-SN v. 2.0 draft https://www.oasis-open.org/committees/download.php/68568/mqtt-sn-v2.0-wd09.docx

SASL PLAIN method specification: https://datatracker.ietf.org/doc/html/rfc4616

func NewAuthPlain

func NewAuthPlain(user string, password []byte) *Auth

NewAuthPlain creates a new Auth with "PLAIN" method encoded authentication data.

func (*Auth) DecodePlain

func (p *Auth) DecodePlain() (string, []byte, error)

DecodePlain decodes username and password from AUTH package data encoded using "PLAIN" method.

func (*Auth) Pack

func (p *Auth) Pack() ([]byte, error)

func (Auth) String

func (p Auth) String() string

func (*Auth) Unpack

func (p *Auth) Unpack(buf []byte) error

type Connack

type Connack struct {
	pkts.Header
	// Fields
	ReturnCode ReturnCode
}

func NewConnack

func NewConnack(returnCode ReturnCode) *Connack

func (*Connack) Pack

func (p *Connack) Pack() ([]byte, error)

func (Connack) String

func (p Connack) String() string

func (*Connack) Unpack

func (p *Connack) Unpack(buf []byte) error

type Connect

type Connect struct {
	pkts.Header
	// Flags
	Will         bool
	CleanSession bool
	// Fields
	ProtocolID uint8
	Duration   uint16
	ClientID   []byte
}

func NewConnect

func NewConnect(duration uint16, clientID []byte, will bool, cleanSession bool) *Connect

NOTE: Packet length is initialized in this constructor and recomputed in m.Write().

func (*Connect) Pack

func (p *Connect) Pack() ([]byte, error)

func (Connect) String

func (p Connect) String() string

func (*Connect) Unpack

func (p *Connect) Unpack(buf []byte) error

type Disconnect

type Disconnect struct {
	pkts.Header
	// Fields
	Duration uint16
}

func NewDisconnect

func NewDisconnect(duration uint16) *Disconnect

NOTE: Packet length is initialized in this constructor and recomputed in m.Write().

func (*Disconnect) Pack

func (p *Disconnect) Pack() ([]byte, error)

func (Disconnect) String

func (p Disconnect) String() string

func (*Disconnect) Unpack

func (p *Disconnect) Unpack(buf []byte) error

type GwInfo

type GwInfo struct {
	pkts.Header
	// Fields
	GatewayID      uint8
	GatewayAddress []byte
}

func NewGwInfo

func NewGwInfo(gatewayID uint8, gatewayAddress []byte) *GwInfo

NOTE: Packet length is initialized in this constructor and recomputed in m.Write().

func (*GwInfo) Pack

func (p *GwInfo) Pack() ([]byte, error)

func (GwInfo) String

func (p GwInfo) String() string

func (*GwInfo) Unpack

func (p *GwInfo) Unpack(buf []byte) error

type MessageIDProperty

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

func (*MessageIDProperty) CopyMessageID

func (p *MessageIDProperty) CopyMessageID(m2 PacketWithID)

func (*MessageIDProperty) MessageID

func (p *MessageIDProperty) MessageID() uint16

func (*MessageIDProperty) SetMessageID

func (p *MessageIDProperty) SetMessageID(msgID uint16)

type PacketWithID

type PacketWithID interface {
	MessageID() uint16
	SetMessageID(msgID uint16)
}

PacketWithID is an interface for all packets which include MessageID property.

type Pingreq

type Pingreq struct {
	pkts.Header
	// Fields
	ClientID []byte
}

func NewPingreq

func NewPingreq(clientID []byte) *Pingreq

NOTE: Packet length is initialized in this constructor and recomputed in m.Write().

func (*Pingreq) Pack

func (p *Pingreq) Pack() ([]byte, error)

func (Pingreq) String

func (p Pingreq) String() string

func (*Pingreq) Unpack

func (p *Pingreq) Unpack(buf []byte) error

type Pingresp

type Pingresp struct {
	pkts.Header
}

func NewPingresp

func NewPingresp() *Pingresp

func (*Pingresp) Pack

func (p *Pingresp) Pack() ([]byte, error)

func (Pingresp) String

func (p Pingresp) String() string

func (*Pingresp) Unpack

func (p *Pingresp) Unpack(buf []byte) error

type Puback

type Puback struct {
	pkts.Header
	// Fields
	TopicID uint16
	MessageIDProperty
	ReturnCode ReturnCode
}

func NewPuback

func NewPuback(topicID uint16, returnCode ReturnCode) *Puback

func (*Puback) Pack

func (p *Puback) Pack() ([]byte, error)

func (Puback) String

func (p Puback) String() string

func (*Puback) Unpack

func (p *Puback) Unpack(buf []byte) error

type Pubcomp

type Pubcomp struct {
	pkts.Header
	// Fields
	MessageIDProperty
}

func NewPubcomp

func NewPubcomp() *Pubcomp

func (*Pubcomp) Pack

func (p *Pubcomp) Pack() ([]byte, error)

func (Pubcomp) String

func (p Pubcomp) String() string

func (*Pubcomp) Unpack

func (p *Pubcomp) Unpack(buf []byte) error

type Publish

type Publish struct {
	pkts.Header
	// Flags
	pkts.DUPProperty
	QOS         uint8
	Retain      bool
	TopicIDType uint8
	// Fields
	TopicID uint16
	MessageIDProperty
	Data []byte
}

func NewPublish

func NewPublish(topicID uint16, data []byte, dup bool, qos uint8, retain bool,
	topicIDType uint8) *Publish

NOTE: Packet length is initialized in this constructor and recomputed in m.Write().

func (*Publish) Pack

func (p *Publish) Pack() ([]byte, error)

func (Publish) String

func (p Publish) String() string

func (*Publish) Unpack

func (p *Publish) Unpack(buf []byte) error

type Pubrec

type Pubrec struct {
	pkts.Header
	// Fields
	MessageIDProperty
}

func NewPubrec

func NewPubrec() *Pubrec

func (*Pubrec) Pack

func (p *Pubrec) Pack() ([]byte, error)

func (Pubrec) String

func (p Pubrec) String() string

func (*Pubrec) Unpack

func (p *Pubrec) Unpack(buf []byte) error

type Pubrel

type Pubrel struct {
	pkts.Header
	// Fields
	MessageIDProperty
}

func NewPubrel

func NewPubrel() *Pubrel

func (*Pubrel) Pack

func (p *Pubrel) Pack() ([]byte, error)

func (Pubrel) String

func (p Pubrel) String() string

func (*Pubrel) Unpack

func (p *Pubrel) Unpack(buf []byte) error

type Regack

type Regack struct {
	pkts.Header
	// Fields
	TopicID uint16
	MessageIDProperty
	ReturnCode ReturnCode
}

func NewRegack

func NewRegack(topicID uint16, returnCode ReturnCode) *Regack

func (*Regack) Pack

func (p *Regack) Pack() ([]byte, error)

func (Regack) String

func (p Regack) String() string

func (*Regack) Unpack

func (p *Regack) Unpack(buf []byte) error

type Register

type Register struct {
	pkts.Header
	// Fields
	TopicID uint16
	MessageIDProperty
	TopicName string
}

func NewRegister

func NewRegister(topicID uint16, topicName string) *Register

NOTE: Packet length is initialized in this constructor and recomputed in m.Write().

func (*Register) Pack

func (p *Register) Pack() ([]byte, error)

func (Register) String

func (p Register) String() string

func (*Register) Unpack

func (p *Register) Unpack(buf []byte) error

type ReturnCode

type ReturnCode uint8

Return code constants.

const (
	RC_ACCEPTED ReturnCode = iota
	RC_CONGESTION
	RC_INVALID_TOPIC_ID
	RC_NOT_SUPPORTED
)

func (ReturnCode) String

func (c ReturnCode) String() string

type SearchGw

type SearchGw struct {
	pkts.Header
	// Fields
	Radius uint8
}

func NewSearchGw

func NewSearchGw(radius uint8) *SearchGw

func (*SearchGw) Pack

func (p *SearchGw) Pack() ([]byte, error)

func (SearchGw) String

func (p SearchGw) String() string

func (*SearchGw) Unpack

func (p *SearchGw) Unpack(buf []byte) error

type Suback

type Suback struct {
	pkts.Header
	// Flags
	QOS uint8
	// Fields
	TopicID uint16
	MessageIDProperty
	ReturnCode ReturnCode
}

func NewSuback

func NewSuback(topicID uint16, returnCode ReturnCode, qos uint8) *Suback

func (*Suback) Pack

func (p *Suback) Pack() ([]byte, error)

func (Suback) String

func (p Suback) String() string

func (*Suback) Unpack

func (p *Suback) Unpack(buf []byte) error

type Subscribe

type Subscribe struct {
	pkts.Header
	// Flags
	pkts.DUPProperty
	QOS         uint8
	TopicIDType uint8
	// Fields
	MessageIDProperty
	TopicID   uint16
	TopicName string
}

func NewSubscribe

func NewSubscribe(topicName string, topicID uint16, dup bool, qos uint8, topicIDType uint8) *Subscribe

NOTE: Packet length is initialized in this constructor and recomputed in m.Write().

func (*Subscribe) Pack

func (p *Subscribe) Pack() ([]byte, error)

func (Subscribe) String

func (p Subscribe) String() string

func (*Subscribe) Unpack

func (p *Subscribe) Unpack(buf []byte) error

type Unsuback

type Unsuback struct {
	pkts.Header
	// Fields
	MessageIDProperty
}

func NewUnsuback

func NewUnsuback() *Unsuback

func (*Unsuback) Pack

func (p *Unsuback) Pack() ([]byte, error)

func (Unsuback) String

func (p Unsuback) String() string

func (*Unsuback) Unpack

func (p *Unsuback) Unpack(buf []byte) error

type Unsubscribe

type Unsubscribe struct {
	pkts.Header
	// Flags
	TopicIDType uint8
	// Fields
	MessageIDProperty
	TopicID   uint16
	TopicName string
}

func NewUnsubscribe

func NewUnsubscribe(topicName string, topicID uint16, topicIDType uint8) *Unsubscribe

NOTE: Packet length is initialized in this constructor and recomputed in m.Write().

func (*Unsubscribe) Pack

func (p *Unsubscribe) Pack() ([]byte, error)

func (Unsubscribe) String

func (p Unsubscribe) String() string

func (*Unsubscribe) Unpack

func (p *Unsubscribe) Unpack(buf []byte) error

type WillMsg

type WillMsg struct {
	pkts.Header
	// Fields
	WillMsg []byte
}

func NewWillMsg

func NewWillMsg(willMsg []byte) *WillMsg

NOTE: Packet length is initialized in this constructor and recomputed in m.Write().

func (*WillMsg) Pack

func (p *WillMsg) Pack() ([]byte, error)

func (WillMsg) String

func (p WillMsg) String() string

func (*WillMsg) Unpack

func (p *WillMsg) Unpack(buf []byte) error

type WillMsgReq

type WillMsgReq struct {
	pkts.Header
}

func NewWillMsgReq

func NewWillMsgReq() *WillMsgReq

func (*WillMsgReq) Pack

func (p *WillMsgReq) Pack() ([]byte, error)

func (WillMsgReq) String

func (p WillMsgReq) String() string

func (*WillMsgReq) Unpack

func (p *WillMsgReq) Unpack(buf []byte) error

type WillMsgResp

type WillMsgResp struct {
	pkts.Header
	// Fields
	ReturnCode ReturnCode
}

func NewWillMsgResp

func NewWillMsgResp(returnCode ReturnCode) *WillMsgResp

func (*WillMsgResp) Pack

func (p *WillMsgResp) Pack() ([]byte, error)

func (WillMsgResp) String

func (p WillMsgResp) String() string

func (*WillMsgResp) Unpack

func (p *WillMsgResp) Unpack(buf []byte) error

type WillMsgUpd

type WillMsgUpd struct {
	pkts.Header
	// Fields
	WillMsg []byte
}

func NewWillMsgUpd

func NewWillMsgUpd(willMsg []byte) *WillMsgUpd

NOTE: Packet length is initialized in this constructor and recomputed in m.Write().

func (*WillMsgUpd) Pack

func (p *WillMsgUpd) Pack() ([]byte, error)

func (WillMsgUpd) String

func (p WillMsgUpd) String() string

func (*WillMsgUpd) Unpack

func (p *WillMsgUpd) Unpack(buf []byte) error

type WillTopic

type WillTopic struct {
	pkts.Header
	// Flags
	QOS    uint8
	Retain bool
	// Fields
	WillTopic string
}

func NewWillTopic

func NewWillTopic(willTopic string, qos uint8, retain bool) *WillTopic

NOTE: Packet length is initialized in this constructor and recomputed in m.Write().

func (*WillTopic) Pack

func (p *WillTopic) Pack() ([]byte, error)

func (WillTopic) String

func (p WillTopic) String() string

func (*WillTopic) Unpack

func (p *WillTopic) Unpack(buf []byte) error

type WillTopicReq

type WillTopicReq struct {
	pkts.Header
}

func NewWillTopicReq

func NewWillTopicReq() *WillTopicReq

func (*WillTopicReq) Pack

func (p *WillTopicReq) Pack() ([]byte, error)

func (WillTopicReq) String

func (p WillTopicReq) String() string

func (*WillTopicReq) Unpack

func (p *WillTopicReq) Unpack(buf []byte) error

type WillTopicResp

type WillTopicResp struct {
	pkts.Header
	// Fields
	ReturnCode ReturnCode
}

func NewWillTopicResp

func NewWillTopicResp(returnCode ReturnCode) *WillTopicResp

func (*WillTopicResp) Pack

func (p *WillTopicResp) Pack() ([]byte, error)

func (WillTopicResp) String

func (p WillTopicResp) String() string

func (*WillTopicResp) Unpack

func (p *WillTopicResp) Unpack(buf []byte) error

type WillTopicUpd

type WillTopicUpd struct {
	pkts.Header
	// Flags
	QOS    uint8
	Retain bool
	// Fields
	WillTopic string
}

func NewWillTopicUpd

func NewWillTopicUpd(willTopic string, qos uint8, retain bool) *WillTopicUpd

NOTE: Packet length is initialized in this constructor and recomputed in m.Write().

func (*WillTopicUpd) Pack

func (p *WillTopicUpd) Pack() ([]byte, error)

func (WillTopicUpd) String

func (p WillTopicUpd) String() string

func (*WillTopicUpd) Unpack

func (p *WillTopicUpd) Unpack(buf []byte) error

Jump to

Keyboard shortcuts

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