Documentation ¶
Index ¶
- Variables
- type Client
- func (cl *Client) ClearBuffers()
- func (cl *Client) ForgetSubscription(filter string)
- func (cl *Client) Identify(lid string, pk packets.Packet, ac auth.Controller)
- func (cl *Client) Info() events.Client
- func (cl *Client) NextPacketID() uint32
- func (cl *Client) NoteSubscription(filter string, so packets.SubOptions)
- func (cl *Client) Read(packetHandler func(*Client, packets.Packet) error) error
- func (cl *Client) ReadConnectPacket(fh *packets.FixedHeader) (pk packets.Packet, err error)
- func (cl *Client) ReadFixedHeader(fh *packets.FixedHeader) error
- func (cl *Client) ReadPacket(fh *packets.FixedHeader) (pk packets.Packet, err error)
- func (cl *Client) SendInflight(handler func(cl *Client, im *InflightMessage, force bool) error)
- func (cl *Client) Start()
- func (cl *Client) Stop(err error)
- func (cl *Client) StopCause() error
- func (cl *Client) WritePacket(pk packets.Packet) (n int, err error)
- type Clients
- type Inflight
- type InflightCache
- func (i *InflightCache) Delete(key uint16) bool
- func (i *InflightCache) Get(key uint16) (*InflightMessage, bool)
- func (i *InflightCache) GetAll() map[uint16]*InflightMessage
- func (i *InflightCache) Len() int
- func (i *InflightCache) Set(key uint16, in *InflightMessage) bool
- func (i *InflightCache) Walk(cl *Client, handler func(cl *Client, im *InflightMessage, force bool) error)
- type InflightMap
- func (i *InflightMap) Delete(key uint16) bool
- func (i *InflightMap) Get(key uint16) (*InflightMessage, bool)
- func (i *InflightMap) GetAll() map[uint16]*InflightMessage
- func (i *InflightMap) Len() int
- func (i *InflightMap) Set(key uint16, in *InflightMessage) bool
- func (i *InflightMap) Walk(cl *Client, handler func(cl *Client, im *InflightMessage, force bool) error)
- type InflightMessage
- type LWT
- type State
Constants ¶
This section is empty.
Variables ¶
var ( // ErrConnectionClosed is returned when operating on a closed // connection and/or when no error cause has been given. ErrConnectionClosed = errors.New("Connection not open") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { State State // the operational state of the client. LWT LWT // the last will and testament for the client. Inflight Inflight // a map of in-flight qos messages. sync.RWMutex // mutex Username []byte // the username the client authenticated with. AC auth.Controller // an auth controller inherited from the listener. Listener string // the id of the listener the client is connected to. ID string // the client id. R *circ.Reader // a reader for reading incoming bytes. W *circ.Writer // a writer for writing outgoing bytes. Subscriptions map[string]packets.SubOptions // a map of the subscription filters a client maintains. CleanSession bool // indicates if the client expects a clean-session. ProtocolVersion byte // mqtt protocol version, optional value: v3.1 = 3、v3.1.1 = 4、v5.0 = 5 TopicAlias map[uint16]string // key is alias, value is topic, for v5 // contains filtered or unexported fields }
Client contains information about a client known by the broker.
func NewClientStub ¶
NewClientStub returns an instance of Client with basic initializations. This method is typically called by the persistence restoration system.
func (*Client) ClearBuffers ¶
func (cl *Client) ClearBuffers()
ClearBuffers sets the read/write buffers to nil so they can be deallocated automatically when no longer in use.
func (*Client) ForgetSubscription ¶
ForgetSubscription forgests a subscription note for the client.
func (*Client) NextPacketID ¶
NextPacketID returns the next packet id for a client, looping back to 0 if the maximum ID has been reached.
func (*Client) NoteSubscription ¶
func (cl *Client) NoteSubscription(filter string, so packets.SubOptions)
NoteSubscription makes a note of a subscription for the client.
func (*Client) Read ¶
Read loops forever reading new packets from a client connection until an error is encountered (or the connection is closed).
func (*Client) ReadConnectPacket ¶
ReadConnectPacket reads the remaining buffer into an MQTT connect packet.
func (*Client) ReadFixedHeader ¶
func (cl *Client) ReadFixedHeader(fh *packets.FixedHeader) error
ReadFixedHeader reads in the values of the next packet's fixed header.
func (*Client) ReadPacket ¶
ReadPacket reads the remaining buffer into an MQTT packet,not connect packet.
func (*Client) SendInflight ¶
func (cl *Client) SendInflight(handler func(cl *Client, im *InflightMessage, force bool) error)
SendInflight resend all inflight message
func (*Client) Start ¶
func (cl *Client) Start()
Start begins the client goroutines reading and writing packets.
func (*Client) Stop ¶
Stop instructs the client to shut down all processing goroutines and disconnect. A cause error may be passed to identfy the reason for stopping.
type Clients ¶
Clients contains a map of the clients known by the broker.
func (*Clients) GetByListener ¶
GetByListener returns clients matching a listener id.
type Inflight ¶
type Inflight interface { Set(key uint16, in *InflightMessage) bool Get(key uint16) (*InflightMessage, bool) GetAll() map[uint16]*InflightMessage Walk(cl *Client, handler func(cl *Client, im *InflightMessage, force bool) error) Len() int Delete(key uint16) bool }
Inflight is an interface of for storing and manipulating inflight messages
type InflightCache ¶
type InflightCache struct {
// contains filtered or unexported fields
}
InflightCache is a cache of InflightMessage keyed on packet id.
func NewCache ¶
func NewCache(cap uint16) *InflightCache
func (*InflightCache) Delete ¶
func (i *InflightCache) Delete(key uint16) bool
Delete removes an in-flight message from the map. Returns true if the message existed.
func (*InflightCache) Get ¶
func (i *InflightCache) Get(key uint16) (*InflightMessage, bool)
Get returns the value of an in-flight message if it exists.
func (*InflightCache) GetAll ¶
func (i *InflightCache) GetAll() map[uint16]*InflightMessage
GetAll returns all the in-flight messages.
func (*InflightCache) Len ¶
func (i *InflightCache) Len() int
Len returns the size of the in-flight messages map.
func (*InflightCache) Set ¶
func (i *InflightCache) Set(key uint16, in *InflightMessage) bool
Set stores the packet of an Inflight message, keyed on message id. Returns true if the inflight message was new.
func (*InflightCache) Walk ¶
func (i *InflightCache) Walk(cl *Client, handler func(cl *Client, im *InflightMessage, force bool) error)
Walk
type InflightMap ¶
InflightMap is a map of InflightMessage keyed on packet id.
func NewMap ¶
func NewMap(cp int) *InflightMap
func (*InflightMap) Delete ¶
func (i *InflightMap) Delete(key uint16) bool
Delete removes an in-flight message from the map. Returns true if the message existed.
func (*InflightMap) Get ¶
func (i *InflightMap) Get(key uint16) (*InflightMessage, bool)
Get returns the value of an in-flight message if it exists.
func (*InflightMap) GetAll ¶
func (i *InflightMap) GetAll() map[uint16]*InflightMessage
GetAll returns all the in-flight messages.
func (*InflightMap) Len ¶
func (i *InflightMap) Len() int
Len returns the size of the in-flight messages map.
func (*InflightMap) Set ¶
func (i *InflightMap) Set(key uint16, in *InflightMessage) bool
func (*InflightMap) Walk ¶
func (i *InflightMap) Walk(cl *Client, handler func(cl *Client, im *InflightMessage, force bool) error)
Walk
type InflightMessage ¶
type InflightMessage struct { Packet packets.Packet // the packet currently in-flight. Sent int64 // the last time the message was sent (for retries) in unixtime. Resends int // the number of times the message was attempted to be sent. Expiry int64 // the message expiration time in unixtime. }
InflightMessage contains data about a packet which is currently in-flight.
type LWT ¶
type LWT struct { Message []byte // the message that shall be sent when the client disconnects. Topic string // the topic the will message shall be sent to. Qos byte // the quality of service desired. Retain bool // indicates whether the will message should be retained }
LWT contains the last will and testament details for a client connection.