broker

package
v0.0.0-...-034e3cd Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2021 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PUB acl status
	PUB = 1
	// SUB acl status
	SUB = 2
)
View Source
const (
	// MessagePoolNum number of message per pool
	MessagePoolNum = 1024
	// MessagePoolMessageNum number
	MessagePoolMessageNum = 1024
)
View Source
const (
	// Connected status
	Connected = 1
	// Disconnected status
	Disconnected = 2
)
View Source
const (
	// AcceptMinSleep is the minimum acceptable sleep times on temporary errors.
	AcceptMinSleep = 100 * time.Millisecond
	// AcceptMaxSleep is the maximum acceptable sleep times on temporary errors
	AcceptMaxSleep = 10 * time.Second
	// DefaultRouteConnect Route solicitation intervals.
	DefaultRouteConnect = 5 * time.Second
	// DefaultTLSTimeout timeout of tls
	DefaultTLSTimeout = 5 * time.Second
)
View Source
const (
	// CONNECT 1
	CONNECT = uint8(iota + 1)
	// CONNACK 2
	CONNACK
	// PUBLISH 3
	PUBLISH
	// PUBACK 4
	PUBACK
	// PUBREC 5
	PUBREC
	// PUBREL 6
	PUBREL
	// PUBCOMP 7
	PUBCOMP
	// SUBSCRIBE 8
	SUBSCRIBE
	// SUBACK 9
	SUBACK
	// UNSUBSCRIBE 10
	UNSUBSCRIBE
	// UNSUBACK 11
	UNSUBACK
	// PINGREQ 12
	PINGREQ
	// PINGRESP 13
	PINGRESP
	// DISCONNECT 14
	DISCONNECT
)
View Source
const (
	// QosAtMostOnce 0
	QosAtMostOnce byte = iota
	// QosAtLeastOnce 1
	QosAtLeastOnce
	// QosExactlyOnce 2
	QosExactlyOnce
	// QosFailure fail value
	QosFailure = 0x80
)
View Source
const (
	// CLIENT is an end user.
	CLIENT = 0
)

Variables

View Source
var DefaultConfig = &Config{
	Worker: 4096,
	Host:   "0.0.0.0",
	Port:   "1883",
	ACL:    false,
}

DefaultConfig create default config

View Source
var (
	// DisconnectdPacket Disconnected packet
	DisconnectdPacket = packets.NewControlPacket(packets.Disconnect).(*packets.DisconnectPacket)
)

Functions

func GenUniqueID

func GenUniqueID() string

GenUniqueID generate uid

func NewTLSConfig

func NewTLSConfig(tlsInfo TLSInfo) (*tls.Config, error)

NewTLSConfig create TLS config from TLS info

func ProcessMessage

func ProcessMessage(msg *Message)

ProcessMessage process a received message

Types

type Broker

type Broker struct {
	ACLConfig *acl.Config
	// contains filtered or unexported fields
}

Broker struct of broker

func NewBroker

func NewBroker(config *Config) (*Broker, error)

NewBroker create a new broker

func (*Broker) OnlineOfflineNotification

func (b *Broker) OnlineOfflineNotification(clientID string, online bool)

OnlineOfflineNotification send msg

func (*Broker) PublishMessage

func (b *Broker) PublishMessage(packet *packets.PublishPacket)

PublishMessage publish message

func (*Broker) Start

func (b *Broker) Start()

Start start all listener from broker

func (*Broker) StartClientListening

func (b *Broker) StartClientListening(TLS bool)

StartClientListening start listening client Start a TCP listener & TLS TCP listener, on port specified by config

func (*Broker) StartWebsocketListening

func (b *Broker) StartWebsocketListening()

StartWebsocketListening Start ws

func (*Broker) SubmitWork

func (b *Broker) SubmitWork(clientID string, msg *Message)

SubmitWork pass to broker a clientid & message

type Config

type Config struct {
	Worker  int     `json:"workerNum"`
	Host    string  `json:"host"`
	Port    string  `json:"port"`
	TLSHost string  `json:"tlsHost"`
	TLSPort string  `json:"tlsPort"`
	WsPath  string  `json:"wsPath"`
	WsPort  string  `json:"wsPort"`
	WsTLS   bool    `json:"wsTLS"`
	TLSInfo TLSInfo `json:"tlsInfo"`
	ACL     bool    `json:"acl"`
	ACLConf string  `json:"aclConf"`
	Debug   bool    `json:"-"`
}

Config hold config parameters json fmt

func ConfigureConfig

func ConfigureConfig(args []string) (*Config, error)

ConfigureConfig create config

func LoadConfig

func LoadConfig(filename string) (*Config, error)

LoadConfig load from string(filename) and return a config

type Message

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

Message struct that contain client & message

type TLSInfo

type TLSInfo struct {
	Verify   bool   `json:"verify"`
	CaFile   string `json:"caFile"`
	CertFile string `json:"certFile"`
	KeyFile  string `json:"keyFile"`
}

TLSInfo struct hold TLS info

Jump to

Keyboard shortcuts

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