clients

package
v0.0.0-...-476ffd2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 topics.Subscriptions // a map of the subscription filters a client maintains.

	CleanSession bool // indicates if the client expects a clean-session.
	// 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) 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) Conn

func (cl *Client) Conn() net.Conn

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) Info

func (cl *Client) Info() events.Client

Info returns an event-version of a client, containing minimal information.

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(packetHandler func(*Client, packets.Packet) error) error

Read loops forever reading new packets from a client connection until an error is encountered (or the connection is closed).

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(err error)

Stop instructs the client to shut down all processing goroutines and disconnect. A cause error may be passed to identfy the reason for stopping.

func (*Client) StopCause

func (cl *Client) StopCause() error

StopCause returns the reason the client connection was stopped, if any.

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) GetAll

func (cl *Clients) GetAll() map[string]*Client

GetAll returns all the clients.

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) ClearExpired

func (i *Inflight) ClearExpired(expiry int64) int64

ClearExpired deletes any inflight messages that have remained longer than the servers InflightTTL duration. Returns number of deleted inflights.

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.
	Created int64          // the unix timestamp when the inflight message was created.
	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 {
	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.

type State

type State struct {
	Done uint32 // 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