clients

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	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.

	sync.RWMutex

	ID            string               // the client id.
	AC            auth.Controller      // an auth controller inherited from the listener.
	Subscriptions topics.Subscriptions // a map of the subscription filters a client maintains.
	Listener      string               // the id of the listener the client is connected to.
	Inflight      Inflight             // a map of in-flight qos messages.
	Username      []byte               // the username the client authenticated with.

	LWT LWT // the last will and testament for the client.
	// contains filtered or unexported fields
}

Client contains information about a client known by the broker.

func NewClient

func NewClient(c net.Conn, r *circ.Reader, w *circ.Writer, s *system.Info) *Client

NewClient returns a new instance of Client.

func NewClientStub

func NewClientStub(s *system.Info) *Client

NewClientStub returns an instance of Client with basic initializations. This method is typically called by the persistence restoration system.

func (*Client) ForgetSubscription

func (cl *Client) ForgetSubscription(filter string)

ForgetSubscription forgests a subscription note for the client.

func (*Client) Identify

func (cl *Client) Identify(lid string, pk packets.Packet, ac auth.Controller)

Identify sets the identification values of a client instance.

func (*Client) NextPacketID

func (cl *Client) NextPacketID() uint32

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, qos byte)

NoteSubscription makes a note of a subscription for the client.

func (*Client) Read

func (cl *Client) Read(h func(*Client, packets.Packet) error) error

Read reads new packets from a client connection

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

func (cl *Client) ReadPacket(fh *packets.FixedHeader) (pk packets.Packet, err error)

ReadPacket reads the remaining buffer into an MQTT packet.

func (*Client) Start

func (cl *Client) Start()

Start begins the client goroutines reading and writing packets.

func (*Client) Stop

func (cl *Client) Stop()

Stop instructs the client to shut down all processing goroutines and disconnect.

func (*Client) WritePacket

func (cl *Client) WritePacket(pk packets.Packet) (n int, err error)

WritePacket encodes and writes a packet to the client.

type Clients

type Clients struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Clients contains a map of the clients known by the broker.

func New

func New() *Clients

New returns an instance of Clients.

func (*Clients) Add

func (cl *Clients) Add(val *Client)

Add adds a new client to the clients map, keyed on client id.

func (*Clients) Delete

func (cl *Clients) Delete(id string)

Delete removes a client from the internal map.

func (*Clients) Get

func (cl *Clients) Get(id string) (*Client, bool)

Get returns the value of a client if it exists.

func (*Clients) GetByListener

func (cl *Clients) GetByListener(id string) []*Client

GetByListener returns clients matching a listener id.

func (*Clients) Len

func (cl *Clients) Len() int

Len returns the length of the clients map.

type Inflight

type Inflight struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Inflight is a map of InflightMessage keyed on packet id.

func (*Inflight) Delete

func (i *Inflight) Delete(key uint16) bool

Delete removes an in-flight message from the map. Returns true if the message existed.

func (*Inflight) Get

func (i *Inflight) Get(key uint16) (InflightMessage, bool)

Get returns the value of an in-flight message if it exists.

func (*Inflight) GetAll

func (i *Inflight) GetAll() map[uint16]InflightMessage

GetAll returns all the in-flight messages.

func (*Inflight) Len

func (i *Inflight) Len() int

Len returns the size of the in-flight messages map.

func (*Inflight) Set

func (i *Inflight) 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.

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.
}

InflightMessage contains data about a packet which is currently in-flight.

type LWT

type LWT struct {
	Topic   string // the topic the will message shall be sent to.
	Message []byte // the message that shall be sent when the client disconnects.
	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.

type State

type State struct {
	Done int64 // atomic counter which indicates that the client has closed.
	// contains filtered or unexported fields
}

State tracks the state of the client.

Jump to

Keyboard shortcuts

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