session

package
v2.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Publish   = "pub"
	Subscribe = "sub"
)

all permit actions

Variables

View Source
var (
	ErrConnectionRefuse                          = errors.New("connection refuse on server side")
	ErrSessionClientAlreadyClosed                = errors.New("session client is already closed")
	ErrSessionClientAlreadyConnecting            = errors.New("session client is already connected")
	ErrSessionClientPacketUnexpected             = errors.New("session client received unexpected packet")
	ErrSessionClientPacketIDConflict             = errors.New("packet id conflict, to acknowledge old packet")
	ErrSessionClientPacketNotFound               = errors.New("packet id is not found")
	ErrSessionClientIDInvalid                    = errors.New("client ID is invalid")
	ErrSessionProtocolVersionInvalid             = errors.New("protocol version is invalid")
	ErrSessionUsernameNotSet                     = errors.New("username is not set")
	ErrSessionUsernameNotPermitted               = errors.New("username or password is not permitted")
	ErrSessionCertificateCommonNameNotFound      = errors.New("certificate common name is not found")
	ErrSessionCertificateCommonNameNotPermitted  = errors.New("certificate common name is not permitted")
	ErrSessionMessageQosNotSupported             = errors.New("message QOS is not supported")
	ErrSessionMessageTopicInvalid                = errors.New("message topic is invalid")
	ErrSessionMessageTopicNotPermitted           = errors.New("message topic is not permitted")
	ErrSessionMessagePayloadSizeExceedsLimit     = errors.New("message payload exceeds the max limit")
	ErrSessionWillMessageQosNotSupported         = errors.New("will QoS is not supported")
	ErrSessionWillMessageTopicInvalid            = errors.New("will topic is invalid")
	ErrSessionWillMessageTopicNotPermitted       = errors.New("will topic is not permitted")
	ErrSessionWillMessagePayloadSizeExceedsLimit = errors.New("will message payload exceeds the max limit")
	ErrSessionSubscribePayloadEmpty              = errors.New("subscribe payload can't be empty")
	ErrSessionManagerClosed                      = errors.New("manager has closed")
)

all errors

Functions

This section is empty.

Types

type Authenticator

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

Authenticator authenticator

func NewAuthenticator

func NewAuthenticator(principals []Principal) *Authenticator

NewAuthenticator creates a new Authenticator

func (*Authenticator) AuthenticateAccount

func (a *Authenticator) AuthenticateAccount(username, password string) *Authorizer

AuthenticateAccount authenticates client account, then return authorizer if pass

func (*Authenticator) AuthenticateCertificate

func (a *Authenticator) AuthenticateCertificate(commonName string) *Authorizer

AuthenticateCertificate authenticates client certificate, then return authorizer if pass

type Authorizer

type Authorizer struct {
	*mqtt.Trie
}

Authorizer checks topic permission

func NewAuthorizer

func NewAuthorizer() *Authorizer

NewAuthorizer create a new authorizer

func (*Authorizer) Authorize

func (p *Authorizer) Authorize(action, topic string) bool

Authorize auth action

type Client

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

Client the client of MQTT

type Config

type Config struct {
	SessionConfig `yaml:"session,omitempty" json:"session,omitempty"`
	Principals    []Principal `yaml:"principals,omitempty" json:"principals,omitempty" validate:"principals"`
}

Config session config

type Info

type Info struct {
	ID            string              `json:"id,omitempty"`
	WillMessage   *mqtt.Message       `json:"will,omitempty"`
	Subscriptions map[string]mqtt.QOS `json:"subs,omitempty"`
	CleanSession  bool                `json:"-"`
}

Info session information

func (*Info) String

func (i *Info) String() string

type Manager

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

Manager the manager of sessions

func NewManager

func NewManager(cfg Config) (m *Manager, err error)

NewManager create a new session manager

func (*Manager) Close

func (m *Manager) Close() error

Close close

func (*Manager) Handle

func (m *Manager) Handle(conn mqtt.Connection, anonymous bool)

Handle the connection handler to create a new MQTT client

type Permission

type Permission struct {
	Action  string   `yaml:"action" json:"action" validate:"regexp=^(p|s)ub$"`
	Permits []string `yaml:"permit,flow" json:"permit,flow"`
}

Permission Permission

type Persistence

type Persistence struct {
	Store store.Conf   `yaml:"store,omitempty" json:"store,omitempty"`
	Queue queue.Config `yaml:"queue,omitempty" json:"queue,omitempty"`
}

type Principal

type Principal struct {
	Username    string       `yaml:"username" json:"username"`
	Password    string       `yaml:"password" json:"password"`
	Permissions []Permission `yaml:"permissions" json:"permissions"`
}

Principal Principal

type Session

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

Session session of a client

func (*Session) ID added in v2.2.3

func (s *Session) ID() string

ID id

func (*Session) Push

func (s *Session) Push(e *common.Event) error

Push pushes source message to session queue

type SessionConfig

type SessionConfig struct {
	MaxClients              int           `yaml:"maxClients,omitempty" json:"maxClients,omitempty"`
	MaxMessagePayloadSize   utils.Size    `yaml:"maxMessagePayloadSize,omitempty" json:"maxMessagePayloadSize,omitempty" default:"32768" validate:"min=1,max=268435455"` // max size of message payload is (256MB - 1)
	MaxInflightQOS0Messages int           `yaml:"maxInflightQOS0Messages" json:"maxInflightQOS0Messages" default:"100" validate:"min=1"`
	MaxInflightQOS1Messages int           `yaml:"maxInflightQOS1Messages" json:"maxInflightQOS1Messages" default:"20" validate:"min=1"`
	ResendInterval          time.Duration `yaml:"resendInterval" json:"resendInterval" default:"20s"`
	Persistence             Persistence   `yaml:"persistence,omitempty" json:"persistence,omitempty"`
	SysTopics               []string      `yaml:"sysTopics,omitempty" json:"sysTopics,omitempty" default:"[\"$link\"]"`
}

SessionConfig session config without principals

Jump to

Keyboard shortcuts

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