persistence

package
v1.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	KSubscription = "sub"
	KServerInfo   = "srv"
	KRetained     = "ret"
	KInflight     = "ifm"
	KClient       = "cl"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	ID       string // the storage key.
	ClientID string // the id of the client.
	T        string // the type of the stored data.
	Listener string // the last known listener id for the client
	Username []byte // the username the client authenticated with.
	LWT      LWT    // the last-will-and-testament message for the client.
}

Client contains client data that can be persistently stored.

type FixedHeader

type FixedHeader struct {
	Type      byte // the type of the packet (PUBLISH, SUBSCRIBE, etc) from bits 7 - 4 (byte 1).
	Dup       bool // indicates if the packet was already sent at an earlier time.
	Qos       byte // indicates the quality of service expected.
	Retain    bool // whether the message should be retained.
	Remaining int  // the number of remaining bytes in the payload.
}

FixedHeader contains the fixed header properties of a message.

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 details about a clients LWT payload.

type Message

type Message struct {
	ID          string      // the storage key.
	T           string      // the type of the stored data.
	Client      string      // the id of the client who sent the message (if inflight).
	FixedHeader FixedHeader // the header properties of the message.
	PacketID    uint16      // the unique id of the packet (if inflight).
	TopicName   string      // the topic the message was sent to (if retained).
	Payload     []byte      // the message payload (if retained).
	Sent        int64       // the last time the message was sent (for retries) in unixtime (if inflight).
	Resends     int         // the number of times the message was attempted to be sent (if inflight).
}

Message contains the details of a retained or inflight message.

type MockStore

type MockStore struct {
	FailOpen bool            // error on open.
	Closed   bool            // indicate mock store is closed.
	Opened   bool            // indicate mock store is open.
	Fail     map[string]bool // issue errors for different methods.
}

MockStore is a mock storage backend for testing.

func (*MockStore) Close

func (s *MockStore) Close()

Close closes the storage instance.

func (*MockStore) DeleteClient

func (s *MockStore) DeleteClient(id string) error

DeleteClient deletes a client from the persistent store.

func (*MockStore) DeleteInflight

func (s *MockStore) DeleteInflight(id string) error

DeleteInflight deletes an inflight message from the persistent store.

func (*MockStore) DeleteRetained

func (s *MockStore) DeleteRetained(id string) error

DeleteRetained deletes a retained message from the persistent store.

func (*MockStore) DeleteSubscription

func (s *MockStore) DeleteSubscription(id string) error

DeleteSubscription deletes a subscription from the persistent store.

func (*MockStore) Open

func (s *MockStore) Open() error

Open opens the storage instance.

func (*MockStore) ReadClients

func (s *MockStore) ReadClients() (v []Client, err error)

ReadClients loads the clients from the storage instance.

func (*MockStore) ReadInflight

func (s *MockStore) ReadInflight() (v []Message, err error)

ReadInflight loads the inflight messages from the storage instance.

func (*MockStore) ReadRetained

func (s *MockStore) ReadRetained() (v []Message, err error)

ReadRetained loads the retained messages from the storage instance.

func (*MockStore) ReadServerInfo

func (s *MockStore) ReadServerInfo() (v ServerInfo, err error)

ReadServerInfo loads the server info from the storage instance.

func (*MockStore) ReadSubscriptions

func (s *MockStore) ReadSubscriptions() (v []Subscription, err error)

ReadSubscriptions loads the subscriptions from the storage instance.

func (*MockStore) WriteClient

func (s *MockStore) WriteClient(v Client) error

WriteClient writes a single client to the storage instance.

func (*MockStore) WriteInflight

func (s *MockStore) WriteInflight(v Message) error

WriteInFlight writes a single InFlight message to the storage instance.

func (*MockStore) WriteRetained

func (s *MockStore) WriteRetained(v Message) error

WriteRetained writes a single retained message to the storage instance.

func (*MockStore) WriteServerInfo

func (s *MockStore) WriteServerInfo(v ServerInfo) error

WriteServerInfo writes server info to the storage instance.

func (*MockStore) WriteSubscription

func (s *MockStore) WriteSubscription(v Subscription) error

WriteSubscription writes a single subscription to the storage instance.

type ServerInfo

type ServerInfo struct {
	system.Info        // embed the system info struct.
	ID          string // the storage key.
}

ServerInfo contains information and statistics about the server.

type Store

type Store interface {
	Open() error
	Close()
	WriteSubscription(v Subscription) error
	WriteClient(v Client) error
	WriteInflight(v Message) error
	WriteServerInfo(v ServerInfo) error
	WriteRetained(v Message) error

	DeleteSubscription(id string) error
	DeleteClient(id string) error
	DeleteInflight(id string) error
	DeleteRetained(id string) error

	ReadSubscriptions() (v []Subscription, err error)
	ReadInflight() (v []Message, err error)
	ReadRetained() (v []Message, err error)
	ReadClients() (v []Client, err error)
	ReadServerInfo() (v ServerInfo, err error)
}

Store is an interface which details a persistent storage connector.

type Subscription

type Subscription struct {
	ID     string // the storage key.
	T      string // the type of the stored data.
	Client string // the id of the client who the subscription belongs to.
	Filter string // the topic filter being subscribed to.
	QoS    byte   // the desired QoS byte.
}

Subscription contains the details of a topic filter subscription.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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