server

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: MIT Imports: 43 Imported by: 0

Documentation

Overview

Package server is a generated GoMock package.

Package server is a generated GoMock package.

Package server is a generated GoMock package.

Package server is a generated GoMock package.

Package server is a generated GoMock package.

Package server is a generated GoMock package.

Package server is a generated GoMock package.

Index

Constants

View Source
const (
	Connecting = iota
	Connected
)

Client status

Variables

View Source
var (
	ErrConnectTimeOut = errors.New("connect time out")
)

Error

View Source
var (
	// ErrInvalWsMsgType [MQTT-6.0.0-1]
	ErrInvalWsMsgType = errors.New("invalid websocket message type")
)

Functions

func LoggerWithField

func LoggerWithField(fields ...zap.Field) *zap.Logger

LoggerWithField release fields to a new logger. Plugins can use this method to release plugin name field.

func New

func New(opts ...Options) *server

New returns a gmqtt server instance with the given options

func RegisterPersistenceFactory

func RegisterPersistenceFactory(name string, new NewPersistence)

func RegisterPlugin

func RegisterPlugin(name string, new NewPlugin)

func RegisterTopicAliasMgrFactory

func RegisterTopicAliasMgrFactory(name string, new NewTopicAliasManager)

Types

type APIRegistrar

type APIRegistrar interface {
	// RegisterHTTPHandler registers the handler to all http servers.
	RegisterHTTPHandler(fn HTTPHandler) error
	// RegisterService registers a service and its implementation to all gRPC servers.
	RegisterService(desc *grpc.ServiceDesc, impl interface{})
}

APIRegistrar is the registrar for all gRPC servers and HTTP servers. It provides the ability for plugins to register gRPC and HTTP handler.

type AuthOptions

type AuthOptions struct {
	// SessionExpiry is session expired time in seconds.
	SessionExpiry uint32
	// ReceiveMax limits the number of QoS 1 and QoS 2 publications that the server is willing to process concurrently for the client.
	// If the client version is v5, this value will be set into  Receive Maximum property in CONNACK packet.
	// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901083
	ReceiveMax uint16
	// MaximumQoS is the highest QOS level permitted for a Publish.
	MaximumQoS uint8
	// MaxPacketSize is the maximum packet size that the server is willing to accept from the client.
	// If the client version is v5, this value will be set into Receive Maximum property in CONNACK packet.
	// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901086
	MaxPacketSize uint32
	// TopicAliasMax indicates the highest value that the server will accept as a Topic Alias sent by the client.
	// The server uses this value to limit the number of Topic Aliases that it is willing to hold on this connection.
	// This option only affect v5 client.
	// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901088
	TopicAliasMax uint16
	// RetainAvailable indicates whether the server supports retained messages.
	// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901085
	RetainAvailable bool
	// WildcardSubAvailable indicates whether the server supports Wildcard Subscriptions.
	// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901091
	WildcardSubAvailable bool
	// SubIDAvailable indicates whether the server supports Subscription Identifiers.
	// This option only affect v5 client.
	// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901092
	SubIDAvailable bool
	// SharedSubAvailable indicates whether the server supports Shared Subscriptions.
	// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901093
	SharedSubAvailable bool
	// KeepAlive is the keep alive time assigned by the server.
	// This option only affect v5 client.
	// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901094
	KeepAlive uint16
	// UserProperties is be used to provide additional information to the client.
	// This option only affect v5 client.
	// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901090
	UserProperties []*packets.UserProperty
	// AssignedClientID allows the server to assign a client id for the client.
	// It will override the client id in the connect packet.
	AssignedClientID []byte
	// ResponseInfo is used as the basis for creating a Response Topic.
	// This option only affect v5 client.
	// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901095
	ResponseInfo []byte
	// MaxInflight limits the number of QoS 1 and QoS 2 publications that the client is willing to process concurrently.
	MaxInflight uint16
}

AuthOptions provides several options which controls how the server interacts with the client. The default value of these options is defined in the configuration file.

type AuthRequest

type AuthRequest struct {
	Auth    *packets.Auth
	Options *AuthOptions
}

type AuthResponse

type AuthResponse struct {
	// Continue indicate that whether more authentication data is needed.
	Continue bool
	// AuthData is the auth data property of the auth packet.
	AuthData []byte
}

ReAuthResponse is the response of the OnAuth hook.

type Client

type Client interface {
	// ClientOptions return a reference of ClientOptions. Do not edit.
	// This is mainly used in hooks.
	ClientOptions() *ClientOptions
	// SessionInfo return a reference of session information of the client. Do not edit.
	// Session info will be available after the client has passed OnSessionCreated or OnSessionResume.
	SessionInfo() *gmqtt.Session
	// Version return the protocol version of the used client.
	Version() packets.Version
	// ConnectedAt returns the connected time
	ConnectedAt() time.Time
	// Connection returns the raw net.Conn
	Connection() net.Conn
	// Close closes the client connection.
	Close()
	// Disconnect sends a disconnect packet to client, it is use to close v5 client.
	Disconnect(disconnect *packets.Disconnect)
}

Client represent a mqtt client.

type ClientIterateFn

type ClientIterateFn = func(client Client) bool

ClientIterateFn is the callback function used by ClientService.IterateClient Return false means to stop the iteration.

type ClientOptions

type ClientOptions struct {
	// ClientID is the client id for the client.
	ClientID string
	// Username is the username for the client.
	Username string
	// KeepAlive is the keep alive time in seconds for the client.
	// The server will close the client if no there is no packet has been received for 1.5 times the KeepAlive time.
	KeepAlive uint16
	// SessionExpiry is the session expiry interval in seconds.
	// If the client version is v5, this value will be set into CONNACK Session Expiry Interval property.
	// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901082
	SessionExpiry uint32
	// MaxInflight limits the number of QoS 1 and QoS 2 publications that the client is willing to process concurrently.
	// For v3 client, it is default to config.MQTT.MaxInflight.
	// For v5 client, it is the minimum of config.MQTT.MaxInflight and Receive Maximum property in CONNECT packet.
	MaxInflight uint16
	// ReceiveMax limits the number of QoS 1 and QoS 2 publications that the server is willing to process concurrently for the Client.
	// If the client version is v5, this value will be set into Receive Maximum property in CONNACK packet.
	// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901083
	ReceiveMax uint16
	// ClientMaxPacketSize is the maximum packet size that the client is willing to accept.
	// The server will drop the packet if it exceeds ClientMaxPacketSize.
	// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901050
	ClientMaxPacketSize uint32
	// ServerMaxPacketSize is the maximum packet size that the server is willing to accept from the client.
	// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901086
	ServerMaxPacketSize uint32
	// ClientTopicAliasMax is highest value that the client will accept as a Topic Alias sent by the server.
	// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901051
	ClientTopicAliasMax uint16
	// ServerTopicAliasMax is highest value that the server will accept as a Topic Alias sent by the client.
	// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901088
	ServerTopicAliasMax uint16
	// RequestProblemInfo is the value to indicate whether the Reason String or User Properties should be sent in the case of failures.
	// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901053
	RequestProblemInfo bool
	// UserProperties is the user properties provided by the client.
	// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901090
	UserProperties []*packets.UserProperty
	// WildcardSubAvailable indicates whether the client is permitted to send retained messages.
	// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901091
	RetainAvailable bool
	// WildcardSubAvailable indicates whether the client is permitted to subscribe Wildcard Subscriptions.
	// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901091
	WildcardSubAvailable bool
	// SubIDAvailable indicates whether the client is permitted to set Subscription Identifiers.
	// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901092
	SubIDAvailable bool
	// SharedSubAvailable indicates whether the client is permitted to subscribe Shared Subscriptions.
	// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901093
	SharedSubAvailable bool
	// AuthMethod is the auth method send by the client.
	// Only MQTT v5 client can set this value.
	// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901055
	AuthMethod []byte
}

ClientOptions is the options which controls how the server interacts with the client. It will be set after the client has connected.

type ClientService

type ClientService interface {
	IterateSession(fn session.IterateFn) error
	GetSession(clientID string) (*gmqtt.Session, error)
	GetClient(clientID string) Client
	IterateClient(fn ClientIterateFn)
	TerminateSession(clientID string)
}

ClientService provides the ability to query and close clients.

type ClientStats

type ClientStats struct {
	PacketStats       PacketStats
	MessageStats      MessageStats
	SubscriptionStats subscription.Stats
}

ClientStats is the statistic information of one client.

func (ClientStats) GetDroppedTotal

func (c ClientStats) GetDroppedTotal() uint64

type ConnectRequest

type ConnectRequest struct {
	// Connect is the CONNECT packet.It is immutable, do not edit.
	Connect *packets.Connect
	// Options represents the setting which will be applied to the current client if auth success.
	// Caller can edit this property to change the setting.
	Options *AuthOptions
}

ConnectRequest represents a connect request made by a CONNECT packet.

type ConnectionStats

type ConnectionStats struct {
	ConnectedTotal      uint64
	DisconnectedTotal   uint64
	SessionCreatedTotal uint64
	SessionTerminated   struct {
		TakenOver uint64
		Expired   uint64
		Normal    uint64
	}
	// ActiveCurrent is the number of used active session.
	ActiveCurrent uint64
	// InactiveCurrent is the number of used inactive session.
	InactiveCurrent uint64
}

ConnectionStats provides the statistics of client connections.

type DeliveryMode

type DeliveryMode = string
const (
	Overlap  DeliveryMode = "overlap"
	OnlyOnce DeliveryMode = "onlyonce"
)

type DroppedTotal

type DroppedTotal struct {
	Internal             uint64
	ExceedsMaxPacketSize uint64
	QueueFull            uint64
	Expired              uint64
	InflightExpired      uint64
}

type EnhancedAuthResponse

type EnhancedAuthResponse struct {
	Continue bool
	OnAuth   OnAuth
	AuthData []byte
}

type GlobalStats

type GlobalStats struct {
	ConnectionStats   ConnectionStats
	PacketStats       PacketStats
	MessageStats      MessageStats
	SubscriptionStats subscription.Stats
}

GlobalStats is the collection of global statistics.

type HTTPHandler

type HTTPHandler = func(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error)

HTTPHandler is the http handler defined by gRPC-gateway.

type HookWrapper

type HookWrapper struct {
	OnBasicAuthWrapper         OnBasicAuthWrapper
	OnEnhancedAuthWrapper      OnEnhancedAuthWrapper
	OnConnectedWrapper         OnConnectedWrapper
	OnReAuthWrapper            OnReAuthWrapper
	OnSessionCreatedWrapper    OnSessionCreatedWrapper
	OnSessionResumedWrapper    OnSessionResumedWrapper
	OnSessionTerminatedWrapper OnSessionTerminatedWrapper
	OnSubscribeWrapper         OnSubscribeWrapper
	OnSubscribedWrapper        OnSubscribedWrapper
	OnUnsubscribeWrapper       OnUnsubscribeWrapper
	OnUnsubscribedWrapper      OnUnsubscribedWrapper
	OnMsgArrivedWrapper        OnMsgArrivedWrapper
	OnMsgDroppedWrapper        OnMsgDroppedWrapper
	OnDeliveredWrapper         OnDeliveredWrapper
	OnClosedWrapper            OnClosedWrapper
	OnAcceptWrapper            OnAcceptWrapper
	OnStopWrapper              OnStopWrapper
	OnWillPublishWrapper       OnWillPublishWrapper
	OnWillPublishedWrapper     OnWillPublishedWrapper
}

HookWrapper groups all hook wrappers function

type MessageQosStats

type MessageQosStats struct {
	DroppedTotal  DroppedTotal
	ReceivedTotal uint64
	SentTotal     uint64
}

func (*MessageQosStats) GetDroppedTotal

func (m *MessageQosStats) GetDroppedTotal() uint64

type MessageStats

type MessageStats struct {
	Qos0            MessageQosStats
	Qos1            MessageQosStats
	Qos2            MessageQosStats
	InflightCurrent uint64
	QueuedCurrent   uint64
}

MessageStats represents the statistics of PUBLISH in, separated by QOS.

func (*MessageStats) GetDroppedTotal

func (m *MessageStats) GetDroppedTotal() uint64

type MockClient

type MockClient struct {
	// contains filtered or unexported fields
}

MockClient is a mock of Client interface

func NewMockClient

func NewMockClient(ctrl *gomock.Controller) *MockClient

NewMockClient creates a new mock instance

func (*MockClient) ClientOptions

func (m *MockClient) ClientOptions() *ClientOptions

ClientOptions mocks base method

func (*MockClient) Close

func (m *MockClient) Close()

Close mocks base method

func (*MockClient) ConnectedAt

func (m *MockClient) ConnectedAt() time.Time

ConnectedAt mocks base method

func (*MockClient) Connection

func (m *MockClient) Connection() net.Conn

Connection mocks base method

func (*MockClient) Disconnect

func (m *MockClient) Disconnect(disconnect *packets.Disconnect)

Disconnect mocks base method

func (*MockClient) EXPECT

func (m *MockClient) EXPECT() *MockClientMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockClient) SessionInfo

func (m *MockClient) SessionInfo() *gmqtt.Session

SessionInfo mocks base method

func (*MockClient) Version

func (m *MockClient) Version() packets.Version

Version mocks base method

type MockClientMockRecorder

type MockClientMockRecorder struct {
	// contains filtered or unexported fields
}

MockClientMockRecorder is the mock recorder for MockClient

func (*MockClientMockRecorder) ClientOptions

func (mr *MockClientMockRecorder) ClientOptions() *gomock.Call

ClientOptions indicates an expected call of ClientOptions

func (*MockClientMockRecorder) Close

func (mr *MockClientMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close

func (*MockClientMockRecorder) ConnectedAt

func (mr *MockClientMockRecorder) ConnectedAt() *gomock.Call

ConnectedAt indicates an expected call of ConnectedAt

func (*MockClientMockRecorder) Connection

func (mr *MockClientMockRecorder) Connection() *gomock.Call

Connection indicates an expected call of Connection

func (*MockClientMockRecorder) Disconnect

func (mr *MockClientMockRecorder) Disconnect(disconnect interface{}) *gomock.Call

Disconnect indicates an expected call of Disconnect

func (*MockClientMockRecorder) SessionInfo

func (mr *MockClientMockRecorder) SessionInfo() *gomock.Call

SessionInfo indicates an expected call of SessionInfo

func (*MockClientMockRecorder) Version

func (mr *MockClientMockRecorder) Version() *gomock.Call

Version indicates an expected call of Version

type MockClientService

type MockClientService struct {
	// contains filtered or unexported fields
}

MockClientService is a mock of ClientService interface

func NewMockClientService

func NewMockClientService(ctrl *gomock.Controller) *MockClientService

NewMockClientService creates a new mock instance

func (*MockClientService) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockClientService) GetClient

func (m *MockClientService) GetClient(clientID string) Client

GetClient mocks base method

func (*MockClientService) GetSession

func (m *MockClientService) GetSession(clientID string) (*gmqtt.Session, error)

GetSession mocks base method

func (*MockClientService) IterateClient

func (m *MockClientService) IterateClient(fn ClientIterateFn)

IterateClient mocks base method

func (*MockClientService) IterateSession

func (m *MockClientService) IterateSession(fn session.IterateFn) error

IterateSession mocks base method

func (*MockClientService) TerminateSession

func (m *MockClientService) TerminateSession(clientID string)

TerminateSession mocks base method

type MockClientServiceMockRecorder

type MockClientServiceMockRecorder struct {
	// contains filtered or unexported fields
}

MockClientServiceMockRecorder is the mock recorder for MockClientService

func (*MockClientServiceMockRecorder) GetClient

func (mr *MockClientServiceMockRecorder) GetClient(clientID interface{}) *gomock.Call

GetClient indicates an expected call of GetClient

func (*MockClientServiceMockRecorder) GetSession

func (mr *MockClientServiceMockRecorder) GetSession(clientID interface{}) *gomock.Call

GetSession indicates an expected call of GetSession

func (*MockClientServiceMockRecorder) IterateClient

func (mr *MockClientServiceMockRecorder) IterateClient(fn interface{}) *gomock.Call

IterateClient indicates an expected call of IterateClient

func (*MockClientServiceMockRecorder) IterateSession

func (mr *MockClientServiceMockRecorder) IterateSession(fn interface{}) *gomock.Call

IterateSession indicates an expected call of IterateSession

func (*MockClientServiceMockRecorder) TerminateSession

func (mr *MockClientServiceMockRecorder) TerminateSession(clientID interface{}) *gomock.Call

TerminateSession indicates an expected call of TerminateSession

type MockPersistence

type MockPersistence struct {
	// contains filtered or unexported fields
}

MockPersistence is a mock of Persistence interface

func NewMockPersistence

func NewMockPersistence(ctrl *gomock.Controller) *MockPersistence

NewMockPersistence creates a new mock instance

func (*MockPersistence) Close

func (m *MockPersistence) Close() error

Close mocks base method

func (*MockPersistence) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockPersistence) NewQueueStore

func (m *MockPersistence) NewQueueStore(config config.Config, defaultNotifier queue.Notifier, clientID string) (queue.Store, error)

NewQueueStore mocks base method

func (*MockPersistence) NewSessionStore

func (m *MockPersistence) NewSessionStore(config config.Config) (session.Store, error)

NewSessionStore mocks base method

func (*MockPersistence) NewSubscriptionStore

func (m *MockPersistence) NewSubscriptionStore(config config.Config) (subscription.Store, error)

NewSubscriptionStore mocks base method

func (*MockPersistence) NewUnackStore

func (m *MockPersistence) NewUnackStore(config config.Config, clientID string) (unack.Store, error)

NewUnackStore mocks base method

func (*MockPersistence) Open

func (m *MockPersistence) Open() error

Open mocks base method

type MockPersistenceMockRecorder

type MockPersistenceMockRecorder struct {
	// contains filtered or unexported fields
}

MockPersistenceMockRecorder is the mock recorder for MockPersistence

func (*MockPersistenceMockRecorder) Close

Close indicates an expected call of Close

func (*MockPersistenceMockRecorder) NewQueueStore

func (mr *MockPersistenceMockRecorder) NewQueueStore(config, defaultNotifier, clientID interface{}) *gomock.Call

NewQueueStore indicates an expected call of NewQueueStore

func (*MockPersistenceMockRecorder) NewSessionStore

func (mr *MockPersistenceMockRecorder) NewSessionStore(config interface{}) *gomock.Call

NewSessionStore indicates an expected call of NewSessionStore

func (*MockPersistenceMockRecorder) NewSubscriptionStore

func (mr *MockPersistenceMockRecorder) NewSubscriptionStore(config interface{}) *gomock.Call

NewSubscriptionStore indicates an expected call of NewSubscriptionStore

func (*MockPersistenceMockRecorder) NewUnackStore

func (mr *MockPersistenceMockRecorder) NewUnackStore(config, clientID interface{}) *gomock.Call

NewUnackStore indicates an expected call of NewUnackStore

func (*MockPersistenceMockRecorder) Open

Open indicates an expected call of Open

type MockPlugin

type MockPlugin struct {
	// contains filtered or unexported fields
}

MockPlugin is a mock of Plugin interface

func NewMockPlugin

func NewMockPlugin(ctrl *gomock.Controller) *MockPlugin

NewMockPlugin creates a new mock instance

func (*MockPlugin) EXPECT

func (m *MockPlugin) EXPECT() *MockPluginMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockPlugin) HookWrapper

func (m *MockPlugin) HookWrapper() HookWrapper

HookWrapper mocks base method

func (*MockPlugin) Load

func (m *MockPlugin) Load(service Server) error

Load mocks base method

func (*MockPlugin) Name

func (m *MockPlugin) Name() string

Name mocks base method

func (*MockPlugin) Unload

func (m *MockPlugin) Unload() error

Unload mocks base method

type MockPluginMockRecorder

type MockPluginMockRecorder struct {
	// contains filtered or unexported fields
}

MockPluginMockRecorder is the mock recorder for MockPlugin

func (*MockPluginMockRecorder) HookWrapper

func (mr *MockPluginMockRecorder) HookWrapper() *gomock.Call

HookWrapper indicates an expected call of HookWrapper

func (*MockPluginMockRecorder) Load

func (mr *MockPluginMockRecorder) Load(service interface{}) *gomock.Call

Load indicates an expected call of Load

func (*MockPluginMockRecorder) Name

func (mr *MockPluginMockRecorder) Name() *gomock.Call

Name indicates an expected call of Name

func (*MockPluginMockRecorder) Unload

func (mr *MockPluginMockRecorder) Unload() *gomock.Call

Unload indicates an expected call of Unload

type MockPublisher

type MockPublisher struct {
	// contains filtered or unexported fields
}

MockPublisher is a mock of Publisher interface

func NewMockPublisher

func NewMockPublisher(ctrl *gomock.Controller) *MockPublisher

NewMockPublisher creates a new mock instance

func (*MockPublisher) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockPublisher) Publish

func (m *MockPublisher) Publish(message *gmqtt.Message)

Publish mocks base method

type MockPublisherMockRecorder

type MockPublisherMockRecorder struct {
	// contains filtered or unexported fields
}

MockPublisherMockRecorder is the mock recorder for MockPublisher

func (*MockPublisherMockRecorder) Publish

func (mr *MockPublisherMockRecorder) Publish(message interface{}) *gomock.Call

Publish indicates an expected call of Publish

type MockRetainedService

type MockRetainedService struct {
	// contains filtered or unexported fields
}

MockRetainedService is a mock of RetainedService interface

func NewMockRetainedService

func NewMockRetainedService(ctrl *gomock.Controller) *MockRetainedService

NewMockRetainedService creates a new mock instance

func (*MockRetainedService) AddOrReplace

func (m *MockRetainedService) AddOrReplace(message *gmqtt.Message)

AddOrReplace mocks base method

func (*MockRetainedService) ClearAll

func (m *MockRetainedService) ClearAll()

ClearAll mocks base method

func (*MockRetainedService) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockRetainedService) GetMatchedMessages

func (m *MockRetainedService) GetMatchedMessages(topicFilter string) []*gmqtt.Message

GetMatchedMessages mocks base method

func (*MockRetainedService) GetRetainedMessage

func (m *MockRetainedService) GetRetainedMessage(topicName string) *gmqtt.Message

GetRetainedMessage mocks base method

func (*MockRetainedService) Iterate

func (m *MockRetainedService) Iterate(fn retained.IterateFn)

Iterate mocks base method

func (*MockRetainedService) Remove

func (m *MockRetainedService) Remove(topicName string)

Remove mocks base method

type MockRetainedServiceMockRecorder

type MockRetainedServiceMockRecorder struct {
	// contains filtered or unexported fields
}

MockRetainedServiceMockRecorder is the mock recorder for MockRetainedService

func (*MockRetainedServiceMockRecorder) AddOrReplace

func (mr *MockRetainedServiceMockRecorder) AddOrReplace(message interface{}) *gomock.Call

AddOrReplace indicates an expected call of AddOrReplace

func (*MockRetainedServiceMockRecorder) ClearAll

ClearAll indicates an expected call of ClearAll

func (*MockRetainedServiceMockRecorder) GetMatchedMessages

func (mr *MockRetainedServiceMockRecorder) GetMatchedMessages(topicFilter interface{}) *gomock.Call

GetMatchedMessages indicates an expected call of GetMatchedMessages

func (*MockRetainedServiceMockRecorder) GetRetainedMessage

func (mr *MockRetainedServiceMockRecorder) GetRetainedMessage(topicName interface{}) *gomock.Call

GetRetainedMessage indicates an expected call of GetRetainedMessage

func (*MockRetainedServiceMockRecorder) Iterate

func (mr *MockRetainedServiceMockRecorder) Iterate(fn interface{}) *gomock.Call

Iterate indicates an expected call of Iterate

func (*MockRetainedServiceMockRecorder) Remove

func (mr *MockRetainedServiceMockRecorder) Remove(topicName interface{}) *gomock.Call

Remove indicates an expected call of Remove

type MockServer

type MockServer struct {
	// contains filtered or unexported fields
}

MockServer is a mock of Server interface

func NewMockServer

func NewMockServer(ctrl *gomock.Controller) *MockServer

NewMockServer creates a new mock instance

func (*MockServer) APIRegistrar

func (m *MockServer) APIRegistrar() APIRegistrar

APIRegistrar mocks base method

func (*MockServer) ApplyConfig

func (m *MockServer) ApplyConfig(config config.Config)

ApplyConfig mocks base method

func (*MockServer) ClientService

func (m *MockServer) ClientService() ClientService

ClientService mocks base method

func (*MockServer) EXPECT

func (m *MockServer) EXPECT() *MockServerMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockServer) GetConfig

func (m *MockServer) GetConfig() config.Config

GetConfig mocks base method

func (*MockServer) Plugins

func (m *MockServer) Plugins() []Plugin

Plugins mocks base method

func (*MockServer) Publisher

func (m *MockServer) Publisher() Publisher

Publisher mocks base method

func (*MockServer) RetainedService

func (m *MockServer) RetainedService() RetainedService

RetainedService mocks base method

func (*MockServer) StatsManager

func (m *MockServer) StatsManager() StatsReader

StatsManager mocks base method

func (*MockServer) Stop

func (m *MockServer) Stop(ctx context.Context) error

Stop mocks base method

func (*MockServer) SubscriptionService

func (m *MockServer) SubscriptionService() SubscriptionService

SubscriptionService mocks base method

type MockServerMockRecorder

type MockServerMockRecorder struct {
	// contains filtered or unexported fields
}

MockServerMockRecorder is the mock recorder for MockServer

func (*MockServerMockRecorder) APIRegistrar

func (mr *MockServerMockRecorder) APIRegistrar() *gomock.Call

APIRegistrar indicates an expected call of APIRegistrar

func (*MockServerMockRecorder) ApplyConfig

func (mr *MockServerMockRecorder) ApplyConfig(config interface{}) *gomock.Call

ApplyConfig indicates an expected call of ApplyConfig

func (*MockServerMockRecorder) ClientService

func (mr *MockServerMockRecorder) ClientService() *gomock.Call

ClientService indicates an expected call of ClientService

func (*MockServerMockRecorder) GetConfig

func (mr *MockServerMockRecorder) GetConfig() *gomock.Call

GetConfig indicates an expected call of GetConfig

func (*MockServerMockRecorder) Plugins

func (mr *MockServerMockRecorder) Plugins() *gomock.Call

Plugins indicates an expected call of Plugins

func (*MockServerMockRecorder) Publisher

func (mr *MockServerMockRecorder) Publisher() *gomock.Call

Publisher indicates an expected call of Publisher

func (*MockServerMockRecorder) RetainedService

func (mr *MockServerMockRecorder) RetainedService() *gomock.Call

RetainedService indicates an expected call of RetainedService

func (*MockServerMockRecorder) StatsManager

func (mr *MockServerMockRecorder) StatsManager() *gomock.Call

StatsManager indicates an expected call of StatsManager

func (*MockServerMockRecorder) Stop

func (mr *MockServerMockRecorder) Stop(ctx interface{}) *gomock.Call

Stop indicates an expected call of Stop

func (*MockServerMockRecorder) SubscriptionService

func (mr *MockServerMockRecorder) SubscriptionService() *gomock.Call

SubscriptionService indicates an expected call of SubscriptionService

type MockStatsReader

type MockStatsReader struct {
	// contains filtered or unexported fields
}

MockStatsReader is a mock of StatsReader interface

func NewMockStatsReader

func NewMockStatsReader(ctrl *gomock.Controller) *MockStatsReader

NewMockStatsReader creates a new mock instance

func (*MockStatsReader) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockStatsReader) GetClientStats

func (m *MockStatsReader) GetClientStats(clientID string) (ClientStats, bool)

GetClientStats mocks base method

func (*MockStatsReader) GetGlobalStats

func (m *MockStatsReader) GetGlobalStats() GlobalStats

GetGlobalStats mocks base method

type MockStatsReaderMockRecorder

type MockStatsReaderMockRecorder struct {
	// contains filtered or unexported fields
}

MockStatsReaderMockRecorder is the mock recorder for MockStatsReader

func (*MockStatsReaderMockRecorder) GetClientStats

func (mr *MockStatsReaderMockRecorder) GetClientStats(clientID interface{}) *gomock.Call

GetClientStats indicates an expected call of GetClientStats

func (*MockStatsReaderMockRecorder) GetGlobalStats

func (mr *MockStatsReaderMockRecorder) GetGlobalStats() *gomock.Call

GetGlobalStats indicates an expected call of GetGlobalStats

type MockSubscriptionService

type MockSubscriptionService struct {
	// contains filtered or unexported fields
}

MockSubscriptionService is a mock of SubscriptionService interface

func NewMockSubscriptionService

func NewMockSubscriptionService(ctrl *gomock.Controller) *MockSubscriptionService

NewMockSubscriptionService creates a new mock instance

func (*MockSubscriptionService) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockSubscriptionService) GetClientStats

func (m *MockSubscriptionService) GetClientStats(clientID string) (subscription.Stats, error)

GetClientStats mocks base method

func (*MockSubscriptionService) GetStats

GetStats mocks base method

func (*MockSubscriptionService) Iterate

Iterate mocks base method

func (*MockSubscriptionService) Subscribe

func (m *MockSubscriptionService) Subscribe(clientID string, subscriptions ...*gmqtt.Subscription) (subscription.SubscribeResult, error)

Subscribe mocks base method

func (*MockSubscriptionService) Unsubscribe

func (m *MockSubscriptionService) Unsubscribe(clientID string, topics ...string) error

Unsubscribe mocks base method

func (*MockSubscriptionService) UnsubscribeAll

func (m *MockSubscriptionService) UnsubscribeAll(clientID string) error

UnsubscribeAll mocks base method

type MockSubscriptionServiceMockRecorder

type MockSubscriptionServiceMockRecorder struct {
	// contains filtered or unexported fields
}

MockSubscriptionServiceMockRecorder is the mock recorder for MockSubscriptionService

func (*MockSubscriptionServiceMockRecorder) GetClientStats

func (mr *MockSubscriptionServiceMockRecorder) GetClientStats(clientID interface{}) *gomock.Call

GetClientStats indicates an expected call of GetClientStats

func (*MockSubscriptionServiceMockRecorder) GetStats

GetStats indicates an expected call of GetStats

func (*MockSubscriptionServiceMockRecorder) Iterate

func (mr *MockSubscriptionServiceMockRecorder) Iterate(fn, options interface{}) *gomock.Call

Iterate indicates an expected call of Iterate

func (*MockSubscriptionServiceMockRecorder) Subscribe

func (mr *MockSubscriptionServiceMockRecorder) Subscribe(clientID interface{}, subscriptions ...interface{}) *gomock.Call

Subscribe indicates an expected call of Subscribe

func (*MockSubscriptionServiceMockRecorder) Unsubscribe

func (mr *MockSubscriptionServiceMockRecorder) Unsubscribe(clientID interface{}, topics ...interface{}) *gomock.Call

Unsubscribe indicates an expected call of Unsubscribe

func (*MockSubscriptionServiceMockRecorder) UnsubscribeAll

func (mr *MockSubscriptionServiceMockRecorder) UnsubscribeAll(clientID interface{}) *gomock.Call

UnsubscribeAll indicates an expected call of UnsubscribeAll

type MockTopicAliasManager

type MockTopicAliasManager struct {
	// contains filtered or unexported fields
}

MockTopicAliasManager is a mock of TopicAliasManager interface

func NewMockTopicAliasManager

func NewMockTopicAliasManager(ctrl *gomock.Controller) *MockTopicAliasManager

NewMockTopicAliasManager creates a new mock instance

func (*MockTopicAliasManager) Check

func (m *MockTopicAliasManager) Check(publish *packets.Publish) (uint16, bool)

Check mocks base method

func (*MockTopicAliasManager) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

type MockTopicAliasManagerMockRecorder

type MockTopicAliasManagerMockRecorder struct {
	// contains filtered or unexported fields
}

MockTopicAliasManagerMockRecorder is the mock recorder for MockTopicAliasManager

func (*MockTopicAliasManagerMockRecorder) Check

func (mr *MockTopicAliasManagerMockRecorder) Check(publish interface{}) *gomock.Call

Check indicates an expected call of Check

type MsgArrivedRequest

type MsgArrivedRequest struct {
	// Publish is the origin MQTT PUBLISH packet, it is immutable. DO NOT EDIT.
	Publish *packets.Publish
	// Message is the message that is going to be passed to topic match process.
	// The caller can modify it.
	Message *gmqtt.Message
	// IterationOptions provides the the ability to change the options of topic matching process.
	// In most of cases, you don't need to modify it.
	// The default value is:
	// 	subscription.IterationOptions{
	//		Type:      subscription.TypeAll,
	//		MatchType: subscription.MatchFilter,
	//		TopicName: msg.Topic,
	//	}
	// The user of this field is the federation plugin.
	// It will change the Type from subscription.TypeAll to subscription.subscription.TypeAll ^ subscription.TypeShared
	// that will prevent publishing the shared message to local client.
	IterationOptions subscription.IterationOptions
}

MsgArrivedRequest is the input param for OnMsgArrived hook.

func (*MsgArrivedRequest) Drop

func (m *MsgArrivedRequest) Drop()

Drop drops the message, so the message will not be delivered to any clients.

type NewPersistence

type NewPersistence func(config config.Config) (Persistence, error)

type NewPlugin

type NewPlugin func(config config.Config) (Plugin, error)

NewPlugin is the constructor of a plugin.

type NewTopicAliasManager

type NewTopicAliasManager func(config config.Config, maxAlias uint16, clientID string) TopicAliasManager

type OnAccept

type OnAccept func(ctx context.Context, conn net.Conn) bool

OnAccept will be called after a new connection established in TCP server. If returns false, the connection will be close directly.

type OnAcceptWrapper

type OnAcceptWrapper func(OnAccept) OnAccept

type OnAuth

type OnAuth func(ctx context.Context, client Client, req *AuthRequest) (*AuthResponse, error)

type OnAuthWrapper

type OnAuthWrapper func(OnAuth) OnAuth

type OnBasicAuth

type OnBasicAuth func(ctx context.Context, client Client, req *ConnectRequest) (err error)

OnBasicAuth will be called when receive v311 connect packet or v5 connect packet with empty auth method property.

type OnBasicAuthWrapper

type OnBasicAuthWrapper func(OnBasicAuth) OnBasicAuth

type OnClosed

type OnClosed func(ctx context.Context, client Client, err error)

OnClosed will be called after the tcp connection of the client has been closed

type OnClosedWrapper

type OnClosedWrapper func(OnClosed) OnClosed

type OnConnected

type OnConnected func(ctx context.Context, client Client)

OnConnected will be called when a mqtt client connect successfully.

type OnConnectedWrapper

type OnConnectedWrapper func(OnConnected) OnConnected

type OnDelivered

type OnDelivered func(ctx context.Context, client Client, msg *gmqtt.Message)

OnDelivered will be called when publishing a message to a client.

type OnDeliveredWrapper

type OnDeliveredWrapper func(OnDelivered) OnDelivered

type OnEnhancedAuth

type OnEnhancedAuth func(ctx context.Context, client Client, req *ConnectRequest) (resp *EnhancedAuthResponse, err error)

OnEnhancedAuth will be called when receive v5 connect packet with auth method property.

type OnEnhancedAuthWrapper

type OnEnhancedAuthWrapper func(OnEnhancedAuth) OnEnhancedAuth

type OnMsgArrived

type OnMsgArrived func(ctx context.Context, client Client, req *MsgArrivedRequest) error

OnMsgArrived will be called when receive a Publish packets.It provides the ability to modify the message before topic match process. The return error is for V5 client to provide additional information for diagnostics and will be ignored if the version of used client is V3. If the returned error type is *codes.Error, the code, reason string and user property will be set into the ack packet(puback for qos1, and pubrel for qos2); otherwise, the code,reason string will be set to 0x80 and error.Error().

type OnMsgArrivedWrapper

type OnMsgArrivedWrapper func(OnMsgArrived) OnMsgArrived

type OnMsgDropped

type OnMsgDropped func(ctx context.Context, clientID string, msg *gmqtt.Message, err error)

OnMsgDropped will be called after the Msg dropped. The err indicates the reason of dropping. See: persistence/queue/error.go

type OnMsgDroppedWrapper

type OnMsgDroppedWrapper func(OnMsgDropped) OnMsgDropped

type OnReAuth

type OnReAuth func(ctx context.Context, client Client, auth *packets.Auth) (*AuthResponse, error)

type OnReAuthWrapper

type OnReAuthWrapper func(OnReAuth) OnReAuth

type OnSessionCreated

type OnSessionCreated func(ctx context.Context, client Client)

OnSessionCreated will be called when new session created.

type OnSessionCreatedWrapper

type OnSessionCreatedWrapper func(OnSessionCreated) OnSessionCreated

type OnSessionResumed

type OnSessionResumed func(ctx context.Context, client Client)

OnSessionResumed will be called when session resumed.

type OnSessionResumedWrapper

type OnSessionResumedWrapper func(OnSessionResumed) OnSessionResumed

type OnSessionTerminated

type OnSessionTerminated func(ctx context.Context, clientID string, reason SessionTerminatedReason)

OnSessionTerminated will be called when session has been terminated.

type OnSessionTerminatedWrapper

type OnSessionTerminatedWrapper func(OnSessionTerminated) OnSessionTerminated

type OnStop

type OnStop func(ctx context.Context)

OnStop will be called on server.Stop()

type OnStopWrapper

type OnStopWrapper func(OnStop) OnStop

type OnSubscribe

type OnSubscribe func(ctx context.Context, client Client, req *SubscribeRequest) error

OnSubscribe will be called when receive a SUBSCRIBE packet. It provides the ability to modify and authorize the subscriptions. If return an error, the returned error will override the error set in SubscribeRequest.

type OnSubscribeWrapper

type OnSubscribeWrapper func(OnSubscribe) OnSubscribe

type OnSubscribed

type OnSubscribed func(ctx context.Context, client Client, subscription *gmqtt.Subscription)

OnSubscribed will be called after the topic subscribe successfully

type OnSubscribedWrapper

type OnSubscribedWrapper func(OnSubscribed) OnSubscribed

type OnUnsubscribe

type OnUnsubscribe func(ctx context.Context, client Client, req *UnsubscribeRequest) error

OnUnsubscribe will be called when receive a UNSUBSCRIBE packet. User can use this function to modify and authorize unsubscription. If return an error, the returned error will override the error set in UnsubscribeRequest.

type OnUnsubscribeWrapper

type OnUnsubscribeWrapper func(OnUnsubscribe) OnUnsubscribe

type OnUnsubscribed

type OnUnsubscribed func(ctx context.Context, client Client, topicName string)

OnUnsubscribed will be called after the topic has been unsubscribed

type OnUnsubscribedWrapper

type OnUnsubscribedWrapper func(OnUnsubscribed) OnUnsubscribed

type OnWillPublish

type OnWillPublish func(ctx context.Context, clientID string, req *WillMsgRequest)

OnWillPublish will be called before the client with the given clientID sending the will message. It provides the ability to modify the message before sending.

type OnWillPublishWrapper

type OnWillPublishWrapper func(OnWillPublish) OnWillPublish

type OnWillPublished

type OnWillPublished func(ctx context.Context, clientID string, msg *gmqtt.Message)

OnWillPublished will be called after the will message has been sent by the client. The msg param is immutable, DO NOT EDIT.

type OnWillPublishedWrapper

type OnWillPublishedWrapper func(OnWillPublished) OnWillPublished

type Options

type Options func(srv *server)

func WithConfig

func WithConfig(config config.Config) Options

WithConfig set the config of the server

func WithHook

func WithHook(hooks Hooks) Options

WithHook set hooks of the server. Notice: WithPlugin() will overwrite hooks.

func WithLogger

func WithLogger(logger *zap.Logger) Options

func WithPlugin

func WithPlugin(plugin ...Plugin) Options

WithPlugin set plugin(s) of the server.

func WithRetainedStore

func WithRetainedStore(store retained.Store) Options

WithRetainedStore set retained db of the server. Notice: WithRetainedStore(s) will overwrite retainedDB.

func WithTCPListener

func WithTCPListener(lns ...net.Listener) Options

WithTCPListener set tcp listener(s) of the server. Default listen on :1883.

func WithWebsocketServer

func WithWebsocketServer(ws ...*WsServer) Options

WithWebsocketServer set websocket server(s) of the server.

type PacketBytes

type PacketBytes struct {
	Auth        uint64
	Connect     uint64
	Connack     uint64
	Disconnect  uint64
	Pingreq     uint64
	Pingresp    uint64
	Puback      uint64
	Pubcomp     uint64
	Publish     uint64
	Pubrec      uint64
	Pubrel      uint64
	Suback      uint64
	Subscribe   uint64
	Unsuback    uint64
	Unsubscribe uint64
	Total       uint64
}

PacketBytes represents total bytes of each in type have been received or sent.

type PacketCount

type PacketCount = PacketBytes

PacketCount represents total number of each in type have been received or sent.

type PacketStats

type PacketStats struct {
	BytesReceived PacketBytes
	ReceivedTotal PacketCount
	BytesSent     PacketBytes
	SentTotal     PacketCount
}

PacketStats represents the statistics of MQTT Packet.

type Persistence

type Persistence interface {
	Open() error
	NewQueueStore(config config.Config, defaultNotifier queue.Notifier, clientID string) (queue.Store, error)
	NewSubscriptionStore(config config.Config) (subscription.Store, error)
	NewSessionStore(config config.Config) (session.Store, error)
	NewUnackStore(config config.Config, clientID string) (unack.Store, error)
	Close() error
}

type Plugin

type Plugin interface {
	// Load will be called in server.Run(). If return error, the server will panic.
	Load(service Server) error
	// Unload will be called when the server is shutdown, the return error is only for logging
	Unload() error
	// HookWrapper returns all hook wrappers that used by the plugin.
	// Return a empty wrapper  if the plugin does not need any hooks
	HookWrapper() HookWrapper
	// Name return the plugin name
	Name() string
}

Plugin is the interface need to be implemented for every plugins.

type Publisher

type Publisher interface {
	// Publish Publish a message to broker.
	// Calling this method will not trigger OnMsgArrived hook.
	Publish(message *gmqtt.Message)
}

Publisher provides the ability to Publish messages to the broker.

type RetainedService

type RetainedService interface {
	retained.Store
}

RetainedService providers the ability to query and add/delete retained messages.

type Server

type Server interface {
	// Publisher returns the Publisher
	Publisher() Publisher
	// GetConfig returns the config of the server
	GetConfig() config.Config
	// StatsManager returns StatsReader
	StatsManager() StatsReader
	// Stop stop the server gracefully
	Stop(ctx context.Context) error
	// ApplyConfig will replace the config of the server
	ApplyConfig(config config.Config)

	ClientService() ClientService

	SubscriptionService() SubscriptionService

	RetainedService() RetainedService
	// Plugins returns all enabled plugins
	Plugins() []Plugin
	APIRegistrar() APIRegistrar
}

Server interface represents a mqtt server instance.

type SessionTerminatedReason

type SessionTerminatedReason byte
const (
	NormalTermination SessionTerminatedReason = iota
	TakenOverTermination
	ExpiredTermination
)

type StatsReader

type StatsReader interface {
	// GetGlobalStats returns the server statistics.
	GetGlobalStats() GlobalStats
	// GetClientStats returns the client statistics for the given client id
	GetClientStats(clientID string) (sts ClientStats, exist bool)
}

StatsReader interface provides the ability to access the statistics of the server

type SubscribeRequest

type SubscribeRequest struct {
	// Subscribe is the SUBSCRIBE packet. It is immutable, do not edit.
	Subscribe *packets.Subscribe
	// Subscriptions wraps all subscriptions by the full topic name.
	// You can modify the value of the map to edit the subscription. But must not change the length of the map.
	Subscriptions map[string]*struct {
		// Sub is the subscription.
		Sub *gmqtt.Subscription
		// Error indicates whether to allow the subscription.
		// Return nil means it is allow to make the subscription.
		// Return an error means it is not allow to make the subscription.
		// It is recommended to use *codes.Error if you want to disallow the subscription. e.g:&codes.Error{Code:codes.NotAuthorized}
		// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901178
		Error error
	}
	// ID is the subscription id, this value will override the id of subscriptions in Subscriptions.Sub.
	// This field take no effect on v3 client.
	ID uint32
}

SubscribeRequest represents the subscribe request made by a SUBSCRIBE packet.

func (*SubscribeRequest) GrantQoS

func (s *SubscribeRequest) GrantQoS(topicName string, qos packets.QoS) *SubscribeRequest

GrantQoS grants the qos to the subscription for the given topic name.

func (*SubscribeRequest) Reject

func (s *SubscribeRequest) Reject(topicName string, err error)

Reject rejects the subscription for the given topic name.

func (*SubscribeRequest) SetID

SetID sets the subscription id for the subscriptions

type SubscriptionService

type SubscriptionService interface {
	// Subscribe adds subscriptions to a specific client.
	// Notice:
	// This method will succeed even if the client is not exists, the subscriptions
	// will affect the new client with the client id.
	Subscribe(clientID string, subscriptions ...*gmqtt.Subscription) (rs subscription.SubscribeResult, err error)
	// Unsubscribe removes subscriptions of a specific client.
	Unsubscribe(clientID string, topics ...string) error
	// UnsubscribeAll removes all subscriptions of a specific client.
	UnsubscribeAll(clientID string) error
	// Iterate iterates all subscriptions. The callback is called once for each subscription.
	// If callback return false, the iteration will be stopped.
	// Notice:
	// The results are not sorted in any way, no ordering of any kind is guaranteed.
	// This method will walk through all subscriptions,
	// so it is a very expensive operation. Do not call it frequently.
	Iterate(fn subscription.IterateFn, options subscription.IterationOptions)
	subscription.StatsReader
}

SubscriptionService providers the ability to query and add/delete subscriptions.

type TopicAliasManager

type TopicAliasManager interface {
	// Check return the alias number and whether the alias exist.
	// For examples:
	// If the Publish alias exist and the manager decides to use the alias, it return the alias number and true.
	// If the Publish alias exist, but the manager decides not to use alias, it return 0 and true.
	// If the Publish alias not exist and the manager decides to assign a new alias, it return the new alias and false.
	// If the Publish alias not exist, but the manager decides not to assign alias, it return the 0 and false.
	Check(publish *packets.Publish) (alias uint16, exist bool)
}

TopicAliasManager manage the topic alias for a V5 client. see topicalias/fifo for more details.

type UnsubscribeRequest

type UnsubscribeRequest struct {
	// Unsubscribe is the UNSUBSCRIBE packet. It is immutable, do not edit.
	Unsubscribe *packets.Unsubscribe
	// Unsubs groups all unsubscribe topic by the full topic name.
	// You can modify the value of the map to edit the unsubscribe topic. But you cannot change the length of the map.
	Unsubs map[string]*struct {
		// TopicName is the topic that is going to unsubscribe.
		TopicName string
		// Error indicates whether to allow the unsubscription.
		// Return nil means it is allow to unsubscribe the topic.
		// Return an error means it is not allow to unsubscribe the topic.
		// It is recommended to use *codes.Error if you want to disallow the unsubscription. e.g:&codes.Error{Code:codes.NotAuthorized}
		// See: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901194
		Error error
	}
}

UnsubscribeRequest is the input param for OnSubscribed hook.

func (*UnsubscribeRequest) Reject

func (u *UnsubscribeRequest) Reject(topicName string, err error)

Reject rejects the subscription for the given topic name.

type WillMsgRequest

type WillMsgRequest struct {
	// Message is the message that is going to send.
	// The caller can edit this field to modify the will message.
	// If nil, the broker will drop the message.
	Message *gmqtt.Message
	// IterationOptions is the same as MsgArrivedRequest.IterationOptions,
	// see MsgArrivedRequest for details
	IterationOptions subscription.IterationOptions
}

WillMsgRequest is the input param for OnWillPublish hook.

func (*WillMsgRequest) Drop

func (w *WillMsgRequest) Drop()

Drop drops the will message, so the message will not be delivered to any clients.

type WsServer

type WsServer struct {
	Server   *http.Server
	Path     string // Url path
	CertFile string //TLS configration
	KeyFile  string //TLS configration
}

WsServer is used to build websocket server

Jump to

Keyboard shortcuts

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