Documentation
¶
Index ¶
- Constants
- Variables
- func NewThreadSafeConn(c net.Conn) net.Conn
- func ValidateID(p byte, i byte) bool
- type Auth
- type Connack
- type Connect
- type ControlPacket
- type Disconnect
- type FixedHeader
- type Packet
- type Pingreq
- type Pingresp
- type Properties
- type Puback
- type Pubcomp
- type Publish
- func (p *Publish) Buffers() net.Buffers
- func (p *Publish) SetIdentifier(packetID uint16)
- func (p *Publish) String() string
- func (p *Publish) ToControlPacket() *ControlPacket
- func (s *Publish) Type() byte
- func (p *Publish) Unpack(r *bytes.Buffer, protocolVersion *byte) error
- func (p *Publish) WriteTo(w io.Writer) (int64, error)
- type Pubrec
- type Pubrel
- type SubOptions
- type Suback
- type Subscribe
- type Unsuback
- type Unsubscribe
- func (u *Unsubscribe) Buffers() net.Buffers
- func (u *Unsubscribe) SetIdentifier(packetID uint16)
- func (u *Unsubscribe) String() string
- func (s *Unsubscribe) Type() byte
- func (u *Unsubscribe) Unpack(r *bytes.Buffer, protocolVersion *byte) error
- func (u *Unsubscribe) WriteTo(w io.Writer) (int64, error)
- type User
Constants ¶
const ( AuthSuccess = 0x00 AuthContinueAuthentication = 0x18 AuthReauthenticate = 0x19 )
AuthSuccess is the return code for successful authentication
const ( ConnackSuccess = 0x00 ConnackUnspecifiedError = 0x80 ConnackMalformedPacket = 0x81 ConnackProtocolError = 0x82 ConnackImplementationSpecificError = 0x83 ConnackUnsupportedProtocolVersion = 0x84 ConnackInvalidClientID = 0x85 ConnackBadUsernameOrPassword = 0x86 ConnackNotAuthorized = 0x87 ConnackServerBusy = 0x89 ConnackBanned = 0x8A ConnackBadAuthenticationMethod = 0x8C ConnackTopicNameInvalid = 0x90 ConnackPacketTooLarge = 0x95 ConnackQuotaExceeded = 0x97 ConnackPayloadFormatInvalid = 0x99 ConnackRetainNotSupported = 0x9A ConnackQoSNotSupported = 0x9B ConnackUseAnotherServer = 0x9C ConnackServerMoved = 0x9D ConnackConnectionRateExceeded = 0x9F )
const ( DisconnectNormalDisconnection = 0x00 DisconnectDisconnectWithWillMessage = 0x04 DisconnectUnspecifiedError = 0x80 DisconnectMalformedPacket = 0x81 DisconnectProtocolError = 0x82 DisconnectImplementationSpecificError = 0x83 DisconnectNotAuthorized = 0x87 DisconnectServerBusy = 0x89 DisconnectServerShuttingDown = 0x8B DisconnectKeepAliveTimeout = 0x8D DisconnectSessionTakenOver = 0x8E DisconnectTopicFilterInvalid = 0x8F DisconnectTopicNameInvalid = 0x90 DisconnectReceiveMaximumExceeded = 0x93 DisconnectTopicAliasInvalid = 0x94 DisconnectPacketTooLarge = 0x95 DisconnectMessageRateTooHigh = 0x96 DisconnectQuotaExceeded = 0x97 DisconnectAdministrativeAction = 0x98 DisconnectPayloadFormatInvalid = 0x99 DisconnectRetainNotSupported = 0x9A DisconnectQoSNotSupported = 0x9B DisconnectUseAnotherServer = 0x9C DisconnectServerMoved = 0x9D DisconnectConnectionRateExceeded = 0x9F DisconnectMaximumConnectTime = 0xA0 DisconnectSubscriptionIdentifiersNotSupported = 0xA1 DisconnectWildcardSubscriptionsNotSupported = 0xA2 )
DisconnectNormalDisconnection, etc are the list of valid disconnection reason codes.
const ( CONNECT byte CONNACK PUBLISH PUBACK PUBREC PUBREL PUBCOMP SUBSCRIBE SUBACK UNSUBSCRIBE UNSUBACK PINGREQ PINGRESP DISCONNECT AUTH )
The following consts are the packet type number for each of the different control packets in MQTT
const ( MQTT_3 = 3 MQTT_3_1_1 = 4 MQTT_5 = 5 )
const ( PropPayloadFormat byte = 1 PropMessageExpiry byte = 2 PropContentType byte = 3 PropResponseTopic byte = 8 PropCorrelationData byte = 9 PropSubscriptionIdentifier byte = 11 PropSessionExpiryInterval byte = 17 PropAssignedClientID byte = 18 PropServerKeepAlive byte = 19 PropAuthMethod byte = 21 PropAuthData byte = 22 PropRequestProblemInfo byte = 23 PropWillDelayInterval byte = 24 PropRequestResponseInfo byte = 25 PropResponseInfo byte = 26 PropServerReference byte = 28 PropReasonString byte = 31 PropReceiveMaximum byte = 33 PropTopicAliasMaximum byte = 34 PropTopicAlias byte = 35 PropMaximumQOS byte = 36 PropRetainAvailable byte = 37 PropUser byte = 38 PropMaximumPacketSize byte = 39 PropWildcardSubAvailable byte = 40 PropSubIDAvailable byte = 41 )
PropPayloadFormat, etc are the list of property codes for the MQTT packet properties
const ( PubackSuccess = 0x00 PubackNoMatchingSubscribers = 0x10 PubackUnspecifiedError = 0x80 PubackImplementationSpecificError = 0x83 PubackNotAuthorized = 0x87 PubackTopicNameInvalid = 0x90 PubackPacketIdentifierInUse = 0x91 PubackQuotaExceeded = 0x97 PubackPayloadFormatInvalid = 0x99 )
PubackSuccess, etc are the list of valid puback reason codes.
const ( PubcompSuccess = 0x00 PubcompPacketIdentifierNotFound = 0x92 )
PubcompSuccess, etc are the list of valid pubcomp reason codes.
const ( PubrecSuccess = 0x00 PubrecNoMatchingSubscribers = 0x10 PubrecUnspecifiedError = 0x80 PubrecImplementationSpecificError = 0x83 PubrecNotAuthorized = 0x87 PubrecTopicNameInvalid = 0x90 PubrecPacketIdentifierInUse = 0x91 PubrecQuotaExceeded = 0x97 PubrecPayloadFormatInvalid = 0x99 )
PubrecSuccess, etc are the list of valid Pubrec reason codes
const ( SubackGrantedQoS0 = 0x00 SubackGrantedQoS1 = 0x01 SubackGrantedQoS2 = 0x02 SubackUnspecifiederror = 0x80 SubackImplementationspecificerror = 0x83 SubackTopicFilterinvalid = 0x8F SubackPacketIdentifierinuse = 0x91 SubackQuotaexceeded = 0x97 SubackSubscriptionIdentifiersnotsupported = 0xA1 SubackWildcardsubscriptionsnotsupported = 0xA2 )
SubackGrantedQoS0, etc are the list of valid suback reason codes.
const ( UnsubackSuccess = 0x00 UnsubackNoSubscriptionFound = 0x11 UnsubackUnspecifiedError = 0x80 UnsubackImplementationSpecificError = 0x83 UnsubackNotAuthorized = 0x87 UnsubackTopicFilterInvalid = 0x8F UnsubackPacketIdentifierInUse = 0x91 )
UnsubackSuccess, etc are the list of valid unsuback reason codes.
Variables ¶
var ValidProperties = map[byte]map[byte]struct{}{ PropPayloadFormat: {CONNECT: {}, PUBLISH: {}}, PropMessageExpiry: {CONNECT: {}, PUBLISH: {}}, PropContentType: {CONNECT: {}, PUBLISH: {}}, PropResponseTopic: {CONNECT: {}, PUBLISH: {}}, PropCorrelationData: {CONNECT: {}, PUBLISH: {}}, PropTopicAlias: {PUBLISH: {}}, PropSubscriptionIdentifier: {PUBLISH: {}, SUBSCRIBE: {}}, PropSessionExpiryInterval: {CONNECT: {}, CONNACK: {}, DISCONNECT: {}}, PropAssignedClientID: {CONNACK: {}}, PropServerKeepAlive: {CONNACK: {}}, PropWildcardSubAvailable: {CONNACK: {}}, PropSubIDAvailable: {CONNACK: {}}, PropSharedSubAvailable: {CONNACK: {}}, PropRetainAvailable: {CONNACK: {}}, PropResponseInfo: {CONNACK: {}}, PropAuthMethod: {CONNECT: {}, CONNACK: {}, AUTH: {}}, PropAuthData: {CONNECT: {}, CONNACK: {}, AUTH: {}}, PropRequestProblemInfo: {CONNECT: {}}, PropWillDelayInterval: {CONNECT: {}}, PropRequestResponseInfo: {CONNECT: {}}, PropServerReference: {CONNACK: {}, DISCONNECT: {}}, PropReasonString: {CONNACK: {}, PUBACK: {}, PUBREC: {}, PUBREL: {}, PUBCOMP: {}, SUBACK: {}, UNSUBACK: {}, DISCONNECT: {}, AUTH: {}}, PropReceiveMaximum: {CONNECT: {}, CONNACK: {}}, PropTopicAliasMaximum: {CONNECT: {}, CONNACK: {}}, PropMaximumQOS: {CONNACK: {}}, PropMaximumPacketSize: {CONNECT: {}, CONNACK: {}}, PropUser: {CONNECT: {}, CONNACK: {}, PUBLISH: {}, PUBACK: {}, PUBREC: {}, PUBREL: {}, PUBCOMP: {}, SUBSCRIBE: {}, UNSUBSCRIBE: {}, SUBACK: {}, UNSUBACK: {}, DISCONNECT: {}, AUTH: {}}, }
ValidProperties is a map of the various properties and the PacketTypes that property is valid for. A CONNECT packet has own properties, but may also include a separate set of Will Properties. Currently, `CONNECT` covers both sets, this may lead to some invalid properties being accepted (this may be fixed in the future).
Functions ¶
func NewThreadSafeConn ¶
NewThreadSafeConn wraps net.Conn with a mutex. ControlPacket uses it in WriteTo method to ensure parallel writes are thread-Safe.
func ValidateID ¶
ValidateID takes a PacketType and a property name and returns a boolean indicating if that property is valid for that PacketType
Types ¶
type Auth ¶
type Auth struct {
Properties *Properties
ReasonCode byte
}
Auth is the Variable Header definition for a Auth control packet
func (*Auth) Buffers ¶
Buffers is the implementation of the interface required function for a packet
type Connack ¶
type Connack struct {
Properties *Properties
ReasonCode byte
SessionPresent bool
}
Connack is the Variable Header definition for a connack control packet
func (*Connack) Buffers ¶
Buffers is the implementation of the interface required function for a packet
type Connect ¶
type Connect struct {
WillMessage []byte
Password []byte
Username string
ProtocolName string
ClientID string
WillTopic string
Properties *Properties
WillProperties *Properties
KeepAlive uint16
ProtocolVersion byte
WillQOS byte
PasswordFlag bool
UsernameFlag bool
WillRetain bool
WillFlag bool
CleanStart bool
}
Connect is the Variable Header definition for a connect control packet
func (*Connect) Buffers ¶
Buffers is the implementation of the interface required function for a packet
func (*Connect) PackFlags ¶
PackFlags takes the Connect flags and packs them into the single byte representation used on the wire by MQTT
func (*Connect) Unpack ¶
Unpack is the implementation of the interface required function for a packet
func (*Connect) UnpackFlags ¶
UnpackFlags takes the wire byte representing the connect options flags and fills out the appropriate variables in the struct
type ControlPacket ¶
type ControlPacket struct {
Content Packet
FixedHeader
}
ControlPacket is the definition of a control packet
func GetProtocolVersion ¶ added in v0.1.3
func GetProtocolVersion(r io.Reader) (*ControlPacket, byte, error)
func NewControlPacket ¶
func NewControlPacket(t byte) *ControlPacket
NewControlPacket takes a packetType and returns a pointer to a ControlPacket where the VariableHeader field is a pointer to an instance of a VariableHeader definition for that packetType
func ReadPacket ¶
func ReadPacket(r io.Reader, args ...byte) (*ControlPacket, error)
ReadPacket reads a control packet from a io.Reader and returns a completed struct with the appropriate data
func (*ControlPacket) PacketID ¶
func (c *ControlPacket) PacketID() uint16
PacketID is a helper function that returns the value of the PacketID field from any kind of mqtt packet in the Content element
func (*ControlPacket) PacketType ¶
func (c *ControlPacket) PacketType() string
PacketType returns the packet type as a string
func (*ControlPacket) String ¶
func (c *ControlPacket) String() string
String implements fmt.Stringer (mainly for debugging purposes)
type Disconnect ¶
type Disconnect struct {
Properties *Properties
ReasonCode byte
}
Disconnect is the Variable Header definition for a Disconnect control packet
func (*Disconnect) Buffers ¶
func (d *Disconnect) Buffers() net.Buffers
Buffers is the implementation of the interface required function for a packet
func (*Disconnect) Reason ¶
func (d *Disconnect) Reason() string
Reason returns a string representation of the meaning of the ReasonCode
func (*Disconnect) String ¶
func (d *Disconnect) String() string
type FixedHeader ¶
FixedHeader is the definition of a control packet fixed header
type Packet ¶
type Packet interface {
Unpack(*bytes.Buffer, *byte) error
Buffers() net.Buffers
WriteTo(io.Writer) (int64, error)
}
Packet is the interface defining the unique parts of a controlpacket
type Pingreq ¶
type Pingreq struct{}
Pingreq is the Variable Header definition for a Pingreq control packet
func (*Pingreq) Buffers ¶
Buffers is the implementation of the interface required function for a packet
type Pingresp ¶
type Pingresp struct{}
Pingresp is the Variable Header definition for a Pingresp control packet
func (*Pingresp) Buffers ¶
Buffers is the implementation of the interface required function for a packet
type Properties ¶
type Properties struct {
// PayloadFormat indicates the format of the payload of the message
// 0 is unspecified bytes
// 1 is UTF8 encoded character data
PayloadFormat *byte
// MessageExpiry is the lifetime of the message in seconds
MessageExpiry *uint32
// ContentType is a UTF8 string describing the content of the message
// for example it could be a MIME type
ContentType string
// ResponseTopic is a UTF8 string indicating the topic name to which any
// response to this message should be sent
ResponseTopic string
// CorrelationData is binary data used to associate future response
// messages with the original request message
CorrelationData []byte
// SubscriptionIdentifier is an identifier of the subscription to which
// the Publish matched
SubscriptionIdentifier *int
// SessionExpiryInterval is the time in seconds after a client disconnects
// that the server should retain the session information (subscriptions etc)
SessionExpiryInterval *uint32
// AssignedClientID is the server assigned client identifier in the case
// that a client connected without specifying a clientID the server
// generates one and returns it in the Connack
AssignedClientID string
// ServerKeepAlive allows the server to specify in the Connack packet
// the time in seconds to be used as the keep alive value
ServerKeepAlive *uint16
// AuthMethod is a UTF8 string containing the name of the authentication
// method to be used for extended authentication
AuthMethod string
// AuthData is binary data containing authentication data
AuthData []byte
// RequestProblemInfo is used by the Client to indicate to the server to
// include the Reason String and/or User Properties in case of failures
RequestProblemInfo *byte
// WillDelayInterval is the number of seconds the server waits after the
// point at which it would otherwise send the will message before sending
// it. The client reconnecting before that time expires causes the server
// to cancel sending the will
WillDelayInterval *uint32
// RequestResponseInfo is used by the Client to request the Server provide
// Response Information in the Connack
RequestResponseInfo *byte
// ResponseInfo is a UTF8 encoded string that can be used as the basis for
// createing a Response Topic. The way in which the Client creates a
// Response Topic from the Response Information is not defined. A common
// use of this is to pass a globally unique portion of the topic tree which
// is reserved for this Client for at least the lifetime of its Session. This
// often cannot just be a random name as both the requesting Client and the
// responding Client need to be authorized to use it. It is normal to use this
// as the root of a topic tree for a particular Client. For the Server to
// return this information, it normally needs to be correctly configured.
// Using this mechanism allows this configuration to be done once in the
// Server rather than in each Client
ResponseInfo string
// ServerReference is a UTF8 string indicating another server the client
// can use
ServerReference string
// ReasonString is a UTF8 string representing the reason associated with
// this response, intended to be human readable for diagnostic purposes
ReasonString string
// ReceiveMaximum is the maximum number of QOS1 & 2 messages allowed to be
// 'inflight' (not having received a PUBACK/PUBCOMP response for)
ReceiveMaximum *uint16
// TopicAliasMaximum is the highest value permitted as a Topic Alias
TopicAliasMaximum *uint16
// TopicAlias is used in place of the topic string to reduce the size of
// packets for repeated messages on a topic
TopicAlias *uint16
// MaximumQOS is the highest QOS level permitted for a Publish
MaximumQOS *byte
// RetainAvailable indicates whether the server supports messages with the
// retain flag set
RetainAvailable *byte
// User is a slice of user provided properties (key and value)
User []User
// MaximumPacketSize allows the client or server to specify the maximum packet
// size in bytes that they support
MaximumPacketSize *uint32
// WildcardSubAvailable indicates whether wildcard subscriptions are permitted
WildcardSubAvailable *byte
// SubIDAvailable indicates whether subscription identifiers are supported
SubIDAvailable *byte
SharedSubAvailable *byte
}
Properties is a struct representing the all the described properties allowed by the MQTT protocol, determining the validity of a property relvative to the packettype it was received in is provided by the ValidateID function
func (*Properties) Pack ¶
func (i *Properties) Pack(p byte) []byte
Pack takes all the defined properties for an Properties and produces a slice of bytes representing the wire format for the information
func (*Properties) PackBuf ¶
func (i *Properties) PackBuf(p byte) *bytes.Buffer
PackBuf will create a bytes.Buffer of the packed properties, it will only pack the properties appropriate to the packet type p even though other properties may exist, it will silently ignore them
func (*Properties) String ¶
func (p *Properties) String() string
type Puback ¶
type Puback struct {
Properties *Properties
PacketID uint16
ReasonCode byte
}
Puback is the Variable Header definition for a Puback control packet
func (*Puback) Buffers ¶
Buffers is the implementation of the interface required function for a packet
type Pubcomp ¶
type Pubcomp struct {
Properties *Properties
PacketID uint16
ReasonCode byte
}
Pubcomp is the Variable Header definition for a Pubcomp control packet
func (*Pubcomp) Buffers ¶
Buffers is the implementation of the interface required function for a packet
type Publish ¶
type Publish struct {
Payload []byte
Topic string
Properties *Properties
PacketID uint16
QoS byte
Duplicate bool
Retain bool
}
Publish is the Variable Header definition for a publish control packet
func (*Publish) Buffers ¶
Buffers is the implementation of the interface required function for a packet
func (*Publish) SetIdentifier ¶
SetIdentifier sets the packet identifier
func (*Publish) ToControlPacket ¶
func (p *Publish) ToControlPacket() *ControlPacket
ToControlPacket returns the packet as a ControlPacket
type Pubrec ¶
type Pubrec struct {
Properties *Properties
PacketID uint16
ReasonCode byte
}
Pubrec is the Variable Header definition for a Pubrec control packet
func (*Pubrec) Buffers ¶
Buffers is the implementation of the interface required function for a packet
func (*Pubrec) ToControlPacket ¶
func (p *Pubrec) ToControlPacket() *ControlPacket
ToControlPacket returns the packet as a ControlPacket
type Pubrel ¶
type Pubrel struct {
Properties *Properties
PacketID uint16
ReasonCode byte
}
Pubrel is the Variable Header definition for a Pubrel control packet
func (*Pubrel) Buffers ¶
Buffers is the implementation of the interface required function for a packet
type SubOptions ¶
type SubOptions struct {
Topic string
QoS byte
RetainHandling byte
NoLocal bool
RetainAsPublished bool
}
SubOptions is the struct representing the options for a subscription
func (*SubOptions) Pack ¶
func (s *SubOptions) Pack() byte
Pack is the implementation of the interface required function for a packet Note that this does not pack the topic
type Suback ¶
type Suback struct {
Properties *Properties
Reasons []byte
PacketID uint16
}
Suback is the Variable Header definition for a Suback control packet
func (*Suback) Buffers ¶
Buffers is the implementation of the interface required function for a packet
type Subscribe ¶
type Subscribe struct {
Properties *Properties
Subscriptions []SubOptions
PacketID uint16
}
Subscribe is the Variable Header definition for a Subscribe control packet
func (*Subscribe) Buffers ¶
Buffers is the implementation of the interface required function for a packet
func (*Subscribe) SetIdentifier ¶
SetIdentifier sets the packet identifier
type Unsuback ¶
type Unsuback struct {
Reasons []byte
Properties *Properties
PacketID uint16
}
Unsuback is the Variable Header definition for a Unsuback control packet
func (*Unsuback) Buffers ¶
Buffers is the implementation of the interface required function for a packet
type Unsubscribe ¶
type Unsubscribe struct {
Topics []string
Properties *Properties
PacketID uint16
}
Unsubscribe is the Variable Header definition for a Unsubscribe control packet
func (*Unsubscribe) Buffers ¶
func (u *Unsubscribe) Buffers() net.Buffers
Buffers is the implementation of the interface required function for a packet
func (*Unsubscribe) SetIdentifier ¶
func (u *Unsubscribe) SetIdentifier(packetID uint16)
SetIdentifier sets the packet identifier
func (*Unsubscribe) String ¶
func (u *Unsubscribe) String() string