listeners

package
v0.0.0-...-fe63319 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidMessage indicates that a message payload was not valid.
	ErrInvalidMessage = errors.New("message type not binary")
)

Functions

func MockCloser

func MockCloser(id string)

MockCloser is a function signature which can be used in testing.

func MockEstablisher

func MockEstablisher(id string, c net.Conn, ac auth.Controller) error

MockEstablisher is a function signature which can be used in testing.

Types

type CloseFunc

type CloseFunc func(id string)

CloseFunc is a callback function for closing all listener clients.

type Config

type Config struct {
	// Auth controller containing auth and ACL logic for
	// allowing or denying access to the server and topics.
	Auth auth.Controller

	// TLS certficates and settings for the connection.
	//
	// Deprecated: Prefer exposing the tls.Config directly for greater flexibility.
	// Please use TLSConfig instead.
	TLS *TLS

	// TLSConfig is a tls.Config configuration to be used with the listener.
	// See examples folder for basic and mutual-tls use.
	TLSConfig *tls.Config
}

Config contains configuration values for a listener.

type EstablishFunc

type EstablishFunc func(id string, c net.Conn, ac auth.Controller) error

EstablishFunc is a callback function for establishing new clients.

type HTTPStats

type HTTPStats struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

HTTPStats is a listener for presenting the server $SYS stats on a JSON http endpoint.

func NewHTTPStats

func NewHTTPStats(id, address string) *HTTPStats

NewHTTPStats initialises and returns a new HTTP listener, listening on an address.

func (*HTTPStats) Close

func (l *HTTPStats) Close(closeClients CloseFunc)

Close closes the listener and any client connections.

func (*HTTPStats) ID

func (l *HTTPStats) ID() string

ID returns the id of the listener.

func (*HTTPStats) Listen

func (l *HTTPStats) Listen(s *system.Info) error

Listen starts listening on the listener's network address.

func (*HTTPStats) Serve

func (l *HTTPStats) Serve(establish EstablishFunc)

Serve starts listening for new connections and serving responses.

func (*HTTPStats) SetConfig

func (l *HTTPStats) SetConfig(config *Config)

SetConfig sets the configuration values for the listener config.

type Listener

type Listener interface {
	SetConfig(*Config)           // set the listener config.
	Listen(s *system.Info) error // open the network address.
	Serve(EstablishFunc)         // starting actively listening for new connections.
	ID() string                  // return the id of the listener.
	Close(CloseFunc)             // stop and close the listener.
}

Listener is an interface for network listeners. A network listener listens for incoming client connections and adds them to the server.

type Listeners

type Listeners struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Listeners contains the network listeners for the broker.

func New

func New(s *system.Info) *Listeners

New returns a new instance of Listeners.

func (*Listeners) Add

func (l *Listeners) Add(val Listener)

Add adds a new listener to the listeners map, keyed on id.

func (*Listeners) Close

func (l *Listeners) Close(id string, closer CloseFunc)

Close stops a listener from the internal map.

func (*Listeners) CloseAll

func (l *Listeners) CloseAll(closer CloseFunc)

CloseAll iterates and closes all registered listeners.

func (*Listeners) Delete

func (l *Listeners) Delete(id string)

Delete removes a listener from the internal map.

func (*Listeners) Get

func (l *Listeners) Get(id string) (Listener, bool)

Get returns the value of a listener if it exists.

func (*Listeners) Len

func (l *Listeners) Len() int

Len returns the length of the listeners map.

func (*Listeners) Serve

func (l *Listeners) Serve(id string, establisher EstablishFunc)

Serve starts a listener serving from the internal map.

func (*Listeners) ServeAll

func (l *Listeners) ServeAll(establisher EstablishFunc)

ServeAll starts all listeners serving from the internal map.

type MockListener

type MockListener struct {
	sync.RWMutex

	Config *Config // configuration for the listener.

	Serving   bool // indicate the listener is serving.
	Listening bool // indiciate the listener is listening.
	ErrListen bool // throw an error on listen.
	// contains filtered or unexported fields
}

MockListener is a mock listener for establishing client connections.

func NewMockListener

func NewMockListener(id, address string) *MockListener

NewMockListener returns a new instance of MockListener

func (*MockListener) Close

func (l *MockListener) Close(closer CloseFunc)

Close closes the mock listener.

func (*MockListener) ID

func (l *MockListener) ID() string

ID returns the id of the mock listener.

func (*MockListener) IsListening

func (l *MockListener) IsListening() bool

IsListening indicates whether the mock listener is listening.

func (*MockListener) IsServing

func (l *MockListener) IsServing() bool

IsServing indicates whether the mock listener is serving.

func (*MockListener) Listen

func (l *MockListener) Listen(s *system.Info) error

Listen begins listening for incoming traffic.

func (*MockListener) Serve

func (l *MockListener) Serve(establisher EstablishFunc)

Serve serves the mock listener.

func (*MockListener) SetConfig

func (l *MockListener) SetConfig(config *Config)

SetConfig sets the configuration values of the mock listener.

type TCP

type TCP struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

TCP is a listener for establishing client connections on basic TCP protocol.

func NewTCP

func NewTCP(id, address string) *TCP

NewTCP initialises and returns a new TCP listener, listening on an address.

func (*TCP) Close

func (l *TCP) Close(closeClients CloseFunc)

Close closes the listener and any client connections.

func (*TCP) ID

func (l *TCP) ID() string

ID returns the id of the listener.

func (*TCP) Listen

func (l *TCP) Listen(s *system.Info) error

Listen starts listening on the listener's network address.

func (*TCP) Serve

func (l *TCP) Serve(establish EstablishFunc)

Serve starts waiting for new TCP connections, and calls the establish connection callback for any received.

func (*TCP) SetConfig

func (l *TCP) SetConfig(config *Config)

SetConfig sets the configuration values for the listener config.

type TLS deprecated

type TLS struct {
	Certificate []byte // the body of a public certificate.
	PrivateKey  []byte // the body of a private key.
}

TLS contains the TLS certificates and settings for the listener connection.

Deprecated: Prefer exposing the tls.Config directly for greater flexibility. Please use TLSConfig instead.

type Websocket

type Websocket struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Websocket is a listener for establishing websocket connections.

func NewWebsocket

func NewWebsocket(id, address string) *Websocket

NewWebsocket initialises and returns a new Websocket listener, listening on an address.

func (*Websocket) Close

func (l *Websocket) Close(closeClients CloseFunc)

Close closes the listener and any client connections.

func (*Websocket) ID

func (l *Websocket) ID() string

ID returns the id of the listener.

func (*Websocket) Listen

func (l *Websocket) Listen(s *system.Info) error

Listen starts listening on the listener's network address.

func (*Websocket) Serve

func (l *Websocket) Serve(establish EstablishFunc)

Serve starts waiting for new Websocket connections, and calls the connection establishment callback for any received.

func (*Websocket) SetConfig

func (l *Websocket) SetConfig(config *Config)

SetConfig sets the configuration values for the listener config.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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