Documentation ¶
Index ¶
- Variables
- func BoolToByte(b bool) *byte
- func Byte(b byte) *byte
- func Uint16(u uint16) *uint16
- func Uint32(u uint32) *uint32
- type Auth
- type AuthProperties
- type AuthResponse
- type Auther
- type CPContext
- type Client
- func (c *Client) Authenticate(ctx context.Context, a *Auth) (*AuthResponse, error)
- func (c *Client) Close()
- func (c *Client) Connect(ctx context.Context, cp *Connect) (*Connack, error)
- func (c *Client) Disconnect(ctx context.Context, d *Disconnect) error
- func (c *Client) Done() <-chan struct{}
- func (c *Client) IsAlive() bool
- func (c *Client) Publish(ctx context.Context, p *Publish) (_ *PublishResponse, err error)
- func (c *Client) Shutdown(ctx context.Context)
- func (c *Client) Subscribe(ctx context.Context, s *Subscribe) (*Suback, error)
- func (c *Client) Unsubscribe(ctx context.Context, u *Unsubscribe) (*Unsuback, error)
- type ClientConfig
- type CommsProperties
- type Connack
- type ConnackProperties
- type Connect
- type ConnectProperties
- type Disconnect
- type DisconnectProperties
- type LogEntry
- type LogLevel
- type MIDService
- type MIDs
- type MemoryPersistence
- func (m *MemoryPersistence) All() []packets.ControlPacket
- func (m *MemoryPersistence) Close()
- func (m *MemoryPersistence) Delete(id uint16)
- func (m *MemoryPersistence) Get(id uint16) packets.ControlPacket
- func (m *MemoryPersistence) Open()
- func (m *MemoryPersistence) Put(id uint16, cp packets.ControlPacket)
- func (m *MemoryPersistence) Reset()
- type Persistence
- type Publish
- type PublishDoneTrace
- type PublishProperties
- type PublishResponse
- type PublishResponseProperties
- type PublishStartTrace
- type RecvDoneTrace
- type RecvStartTrace
- type Router
- type RouterFunc
- type SendDoneTrace
- type SendStartTrace
- type Suback
- type SubackProperties
- type Subscribe
- type SubscribeOptions
- type SubscribeProperties
- type Trace
- type Unsuback
- type UnsubackProperties
- type Unsubscribe
- type UnsubscribeProperties
- type WillMessage
- type WillProperties
Constants ¶
This section is empty.
Variables ¶
var ( DefaultKeepAlive = 60 * time.Second DefaultShutdownTimeout = 10 * time.Second DefaultPacketTimeout = 10 * time.Second )
var ( ErrClosed = fmt.Errorf("paho: client closed") ErrTimeout = fmt.Errorf("paho: request timeout") )
var ErrNoMoreIDs = errors.New("no more packet ids available.")
ErrNoMoreIDs is an error returned when there are no more available packet IDs.
Functions ¶
func BoolToByte ¶
BoolToByte is a helper function that take a bool and returns a pointer to a byte of value 1 if true or 0 if false
func Byte ¶
Byte is a helper function that take a byte and returns a pointer to a byte of that value
Types ¶
type Auth ¶
type Auth struct { Properties *AuthProperties ReasonCode byte }
Auth is a representation of the MQTT Auth packet
func AuthFromPacketAuth ¶
AuthFromPacketAuth takes a packets library Auth and returns a paho library Auth
func (*Auth) InitProperties ¶
func (a *Auth) InitProperties(p *packets.Properties)
InitProperties is a function that takes a lower level Properties struct and completes the properties of the Auth on which it is called
type AuthProperties ¶
type AuthProperties struct { AuthData []byte AuthMethod string ReasonString string User map[string]string }
AuthProperties is a struct of the properties that can be set for a Auth packet
type AuthResponse ¶
type AuthResponse struct { Properties *AuthProperties ReasonCode byte Success bool }
AuthResponse is a represenation of the response to an Auth packet
func AuthResponseFromPacketAuth ¶
func AuthResponseFromPacketAuth(a *packets.Auth) *AuthResponse
AuthResponseFromPacketAuth takes a packets library Auth and returns a paho library AuthResponse
func AuthResponseFromPacketDisconnect ¶
func AuthResponseFromPacketDisconnect(d *packets.Disconnect) *AuthResponse
AuthResponseFromPacketDisconnect takes a packets library Disconnect and returns a paho library AuthResponse
type Auther ¶
Auther is the interface for something that implements the extended authentication flows in MQTT v5.
type CPContext ¶
type CPContext struct { Context context.Context Return chan packets.ControlPacket }
CPContext is the struct that is used to return responses to ControlPackets that have them, eg: the suback to a subscribe. The response packet is send down the Return channel and the Context is used to track timeouts.
type Client ¶
type Client struct { ClientConfig // contains filtered or unexported fields }
Client is the struct representing an MQTT client
func NewClient ¶
func NewClient(conf ClientConfig) *Client
NewClient is used to create a new default instance of an MQTT client. It returns a pointer to the new client instance. The default client uses the provided MessageID and StandardRouter implementations, and a noop Persistence. These should be replaced if desired before the client is connected. client.Conn *MUST* be set to an already connected net.Conn before Connect() is called.
func (*Client) Authenticate ¶
Authenticate is used to initiate a reauthentication of credentials with the server. This function sends the initial Auth packet to start the reauthentication then relies on the client AuthHandler managing any further requests from the server until either a successful Auth packet is passed back, or a Disconnect is received.
func (*Client) Connect ¶
Connect is used to connect the client to a server. It presumes that the Client instance already has a working network connection. The function takes a pre-prepared Connect packet, and uses that to establish an MQTT connection. Assuming the connection completes successfully the rest of the client is initiated and the Connack returned. Otherwise the failure Connack (if there is one) is returned along with an error indicating the reason for the failure to connect.
func (*Client) Disconnect ¶
func (c *Client) Disconnect(ctx context.Context, d *Disconnect) error
Disconnect is used to send a Disconnect packet to the MQTT server Whether or not the attempt to send the Disconnect packet fails (and if it does this function returns any error) the network connection is .
func (*Client) Publish ¶
Publish is used to send a publication to the MQTT server. It is passed a pre-prepared Publish packet and blocks waiting for the appropriate response, or for the timeout to fire. Any response message is returned from the function, along with any errors.
func (*Client) Subscribe ¶
Subscribe is used to send a Subscription request to the MQTT server. It is passed a pre-prepared Subscribe packet and blocks waiting for a response Suback, or for the timeout to fire. Any response Suback is returned from the function, along with any errors.
func (*Client) Unsubscribe ¶
Unsubscribe is used to send an Unsubscribe request to the MQTT server. It is passed a pre-prepared Unsubscribe packet and blocks waiting for a response Unsuback, or for the timeout to fire. Any response Unsuback is returned from the function, along with any errors.
type ClientConfig ¶
type ClientConfig struct { Conn net.Conn MIDs MIDService AuthHandler Auther Router Router Persistence Persistence PacketTimeout time.Duration ShutdownTimeout time.Duration Trace Trace Logger func(context.Context, LogEntry) OnClose func() }
ClientConfig are the user configurable options for the client, an instance of this struct is passed into NewClient(), not all options are required to be set, defaults are provided for Persistence, MIDs, PacketTimeout and Router.
type CommsProperties ¶
type CommsProperties struct { MaximumPacketSize uint32 ReceiveMaximum uint16 TopicAliasMaximum uint16 MaximumQoS byte RetainAvailable bool WildcardSubAvailable bool SubIDAvailable bool }
CommsProperties is a struct of the communication properties that may be set by the server in the Connack and that the client needs to be aware of for future subscribes/publishes
type Connack ¶
type Connack struct { Properties *ConnackProperties ReasonCode byte SessionPresent bool }
Connack is a representation of the MQTT Connack packet
func ConnackFromPacketConnack ¶
ConnackFromPacketConnack takes a packets library Connack and returns a paho library Connack
func (*Connack) InitProperties ¶
func (c *Connack) InitProperties(p *packets.Properties)
InitProperties is a function that takes a lower level Properties struct and completes the properties of the Connack on which it is called
type ConnackProperties ¶
type ConnackProperties struct { AuthData []byte AuthMethod string ResponseInfo string ServerReference string ReasonString string AssignedClientID string MaximumPacketSize *uint32 ReceiveMaximum *uint16 TopicAliasMaximum *uint16 ServerKeepAlive *uint16 MaximumQoS *byte User map[string]string WildcardSubAvailable bool SubIDAvailable bool RetainAvailable bool }
ConnackProperties is a struct of the properties that can be set for a Connack packet
type Connect ¶
type Connect struct { Password []byte Username string ClientID string Properties *ConnectProperties WillMessage *WillMessage WillProperties *WillProperties KeepAlive uint16 CleanStart bool UsernameFlag bool PasswordFlag bool }
Connect is a representation of the MQTT Connect packet
func ConnectFromPacketConnect ¶
ConnectFromPacketConnect takes a packets library Connect and returns a paho library Connect
func (*Connect) InitProperties ¶
func (c *Connect) InitProperties(p *packets.Properties)
InitProperties is a function that takes a lower level Properties struct and completes the properties of the Connect on which it is called
func (*Connect) InitWillProperties ¶
func (c *Connect) InitWillProperties(p *packets.Properties)
InitWillProperties is a function that takes a lower level Properties struct and completes the properties of the Will in the Connect on which it is called
type ConnectProperties ¶
type ConnectProperties struct { AuthData []byte AuthMethod string SessionExpiryInterval *uint32 WillDelayInterval *uint32 ReceiveMaximum *uint16 TopicAliasMaximum *uint16 MaximumQOS *byte MaximumPacketSize *uint32 User map[string]string RequestProblemInfo bool RequestResponseInfo bool }
ConnectProperties is a struct of the properties that can be set for a Connect packet
type Disconnect ¶
type Disconnect struct { Properties *DisconnectProperties ReasonCode byte }
Disconnect is a representation of the MQTT Disconnect packet
func DisconnectFromPacketDisconnect ¶
func DisconnectFromPacketDisconnect(p *packets.Disconnect) *Disconnect
DisconnectFromPacketDisconnect takes a packets library Disconnect and returns a paho library Disconnect
func (*Disconnect) InitProperties ¶
func (d *Disconnect) InitProperties(p *packets.Properties)
InitProperties is a function that takes a lower level Properties struct and completes the properties of the Disconnect on which it is called
func (*Disconnect) Packet ¶
func (d *Disconnect) Packet() *packets.Disconnect
Packet returns a packets library Disconnect from the paho Disconnect on which it is called
type DisconnectProperties ¶
type DisconnectProperties struct { ServerReference string ReasonString string SessionExpiryInterval *uint32 User map[string]string }
DisconnectProperties is a struct of the properties that can be set for a Disconnect packet
type LogEntry ¶
type LogEntry struct { Level LogLevel Message string Error error ControlPacket *packets.ControlPacket }
type MIDService ¶
type MIDService interface { Request(*CPContext) (uint16, error) Get(uint16) *CPContext Free(uint16) Clear() }
MIDService defines the interface for a struct that handles the relationship between message ids and CPContexts Request() takes a *CPContext and returns a uint16 that is the messageid that should be used by the code that called Request() Get() takes a uint16 that is a messageid and returns the matching *CPContext that the MIDService has associated with that messageid Free() takes a uint16 that is a messageid and instructs the MIDService to mark that messageid as available for reuse Clear() resets the internal state of the MIDService
type MIDs ¶
MIDs is the default MIDService provided by this library. It uses a map of uint16 to *CPContext to track responses to messages with a messageid
func (*MIDs) Clear ¶
func (m *MIDs) Clear()
Clear is the library provided MIDService's implementation of the required interface function()
func (*MIDs) Free ¶
Free is the library provided MIDService's implementation of the required interface function()
type MemoryPersistence ¶
MemoryPersistence is an implementation of a Persistence that stores the ControlPackets in memory using a map
func (*MemoryPersistence) All ¶
func (m *MemoryPersistence) All() []packets.ControlPacket
All is the library provided MemoryPersistence's implementation of the required interface function()
func (*MemoryPersistence) Close ¶
func (m *MemoryPersistence) Close()
Close is the library provided MemoryPersistence's implementation of the required interface function()
func (*MemoryPersistence) Delete ¶
func (m *MemoryPersistence) Delete(id uint16)
Delete is the library provided MemoryPersistence's implementation of the required interface function()
func (*MemoryPersistence) Get ¶
func (m *MemoryPersistence) Get(id uint16) packets.ControlPacket
Get is the library provided MemoryPersistence's implementation of the required interface function()
func (*MemoryPersistence) Open ¶
func (m *MemoryPersistence) Open()
Open is the library provided MemoryPersistence's implementation of the required interface function()
func (*MemoryPersistence) Put ¶
func (m *MemoryPersistence) Put(id uint16, cp packets.ControlPacket)
Put is the library provided MemoryPersistence's implementation of the required interface function()
func (*MemoryPersistence) Reset ¶
func (m *MemoryPersistence) Reset()
Reset is the library provided MemoryPersistence's implementation of the required interface function()
type Persistence ¶
type Persistence interface { Open() Put(uint16, packets.ControlPacket) Get(uint16) packets.ControlPacket All() []packets.ControlPacket Delete(uint16) Close() Reset() }
Persistence is an interface of the functions for a struct that is used to persist ControlPackets. Open() is an initialiser to prepare the Persistence for use Put() takes a uint16 which is a messageid and a ControlPacket to persist against that messageid Get() takes a uint16 which is a messageid and returns the persisted ControlPacket from the Persistence for that messageid All() returns a slice of all ControlPackets persisted Delete() takes a uint16 which is a messageid and deletes the associated stored ControlPacket from the Persistence Close() closes the Persistence Reset() clears the Persistence and prepares it to be reused
type Publish ¶
type Publish struct { QoS byte Retain bool Topic string Properties *PublishProperties Payload []byte }
Publish is a reporesentation of the MQTT Publish packet
func (*Publish) InitProperties ¶
func (p *Publish) InitProperties(prop *packets.Properties)
InitProperties is a function that takes a lower level Properties struct and completes the properties of the Publish on which it is called
type PublishDoneTrace ¶
type PublishDoneTrace struct {
Error error
}
type PublishProperties ¶
type PublishProperties struct { CorrelationData []byte ContentType string ResponseTopic string PayloadFormat *byte MessageExpiry *uint32 SubscriptionIdentifier *uint32 TopicAlias *uint16 User map[string]string }
PublishProperties is a struct of the properties that can be set for a Publish packet
type PublishResponse ¶
type PublishResponse struct { Properties *PublishResponseProperties ReasonCode byte }
PublishResponse is a generic representation of a response to a QoS1 or QoS2 Publish
func PublishResponseFromPuback ¶
func PublishResponseFromPuback(pa *packets.Puback) *PublishResponse
PublishResponseFromPuback takes a packets library Puback and returns a paho library PublishResponse
func PublishResponseFromPubcomp ¶
func PublishResponseFromPubcomp(pc *packets.Pubcomp) *PublishResponse
PublishResponseFromPubcomp takes a packets library Pubcomp and returns a paho library PublishResponse
func PublishResponseFromPubrec ¶
func PublishResponseFromPubrec(pr *packets.Pubrec) *PublishResponse
PublishResponseFromPubrec takes a packets library Pubrec and returns a paho library PublishResponse
type PublishResponseProperties ¶
PublishResponseProperties is the properties associated with a response to a QoS1 or QoS2 Publish
type PublishStartTrace ¶
type PublishStartTrace struct { Packet *packets.Publish OnDone func(context.Context, PublishDoneTrace) }
type RecvDoneTrace ¶
type RecvDoneTrace struct { Packet interface{} PacketType packets.PacketType Error error }
type RecvStartTrace ¶
type RecvStartTrace struct {
OnDone func(context.Context, RecvDoneTrace)
}
type Router ¶
Router is an interface that capable of handling publish packets.
NOTE: its a Router responsibility to deal with concurrent packets processing (if needed).
type RouterFunc ¶
RouterFunc is an adapter to allow the use of ordinary functions as Router.
type SendDoneTrace ¶
type SendDoneTrace struct {
Error error
}
type SendStartTrace ¶
type SendStartTrace struct { Packet interface{} PacketType packets.PacketType OnDone func(context.Context, SendDoneTrace) }
type Suback ¶
type Suback struct { Properties *SubackProperties Reasons []byte }
Suback is a representation of an MQTT suback packet
func SubackFromPacketSuback ¶
SubackFromPacketSuback takes a packets library Suback and returns a paho library Suback
type SubackProperties ¶
SubackProperties is a struct of the properties that can be set for a Suback packet
type Subscribe ¶
type Subscribe struct { Properties *SubscribeProperties Subscriptions map[string]SubscribeOptions }
Subscribe is a representation of a MQTT subscribe packet
func (*Subscribe) InitProperties ¶
func (s *Subscribe) InitProperties(prop *packets.Properties)
InitProperties is a function that takes a packet library Properties struct and completes the properties of the Subscribe on which it is called
func (*Subscribe) Packet ¶
Packet returns a packets library Subscribe from the paho Subscribe on which it is called
func (*Subscribe) PacketSubOptionsFromSubscribeOptions ¶
func (s *Subscribe) PacketSubOptionsFromSubscribeOptions() map[string]packets.SubOptions
PacketSubOptionsFromSubscribeOptions returns a map of string to packet library SubOptions for the paho Subscribe on which it is called
type SubscribeOptions ¶
SubscribeOptions is the struct representing the options for a subscription
type SubscribeProperties ¶
SubscribeProperties is a struct of the properties that can be set for a Subscribe packet
type Trace ¶
type Trace struct { OnSend func(context.Context, *SendStartTrace) OnRecv func(context.Context, *RecvStartTrace) OnPublish func(context.Context, *PublishStartTrace) }
type Unsuback ¶
type Unsuback struct { Reasons []byte Properties *UnsubackProperties }
Unsuback is a representation of an MQTT Unsuback packet
func UnsubackFromPacketUnsuback ¶
UnsubackFromPacketUnsuback takes a packets library Unsuback and returns a paho library Unsuback
type UnsubackProperties ¶
UnsubackProperties is a struct of the properties that can be set for a Unsuback packet
type Unsubscribe ¶
type Unsubscribe struct { Topics []string Properties *UnsubscribeProperties }
Unsubscribe is a representation of an MQTT unsubscribe packet
func (*Unsubscribe) Packet ¶
func (u *Unsubscribe) Packet() *packets.Unsubscribe
Packet returns a packets library Unsubscribe from the paho Unsubscribe on which it is called
type UnsubscribeProperties ¶
UnsubscribeProperties is a struct of the properties that can be set for a Unsubscribe packet
type WillMessage ¶
WillMessage is a representation of the LWT message that can be sent with the Connect packet