session

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: Apache-2.0 Imports: 7 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, s *Session) context.Context

NewContext stores Session in context.Context values. It uses pointer to the session so it can be modified by handler.

func Stream

func Stream(ctx context.Context, in, out net.Conn, h Handler, ic Interceptor, cert x509.Certificate) error

Stream starts proxy between client and broker.

Types

type Direction

type Direction int
const (
	Up Direction = iota
	Down
)

type Handler

type Handler interface {
	// Authorization on client `CONNECT`
	// Each of the params are passed by reference, so that it can be changed
	AuthConnect(ctx context.Context) error

	// Authorization on client `PUBLISH`
	// Topic is passed by reference, so that it can be modified
	AuthPublish(ctx context.Context, topic *string, payload *[]byte) error

	// Authorization on client `SUBSCRIBE`
	// Topics are passed by reference, so that they can be modified
	AuthSubscribe(ctx context.Context, topics *[]string) error

	// After client successfully connected
	Connect(ctx context.Context) error

	// After client successfully published
	Publish(ctx context.Context, topic *string, payload *[]byte) error

	// After client successfully subscribed
	Subscribe(ctx context.Context, topics *[]string) error

	// After client unsubscribed
	Unsubscribe(ctx context.Context, topics *[]string) error

	// Disconnect on connection with client lost
	Disconnect(ctx context.Context) error
}

Handler is an interface for mGate hooks.

type Interceptor

type Interceptor interface {
	// Intercept is called on every packet flowing through the Proxy.
	// Packets can be modified before being sent to the broker or the client.
	// If the interceptor returns a non-nil packet, the modified packet is sent.
	// The error indicates unsuccessful interception and mGate is cancelling the packet.
	Intercept(ctx context.Context, pkt packets.ControlPacket, dir Direction) (packets.ControlPacket, error)
}

Interceptor is an interface for mGate intercept hook.

type Session

type Session struct {
	ID       string
	Username string
	Password []byte
	Cert     x509.Certificate
}

Session stores MQTT session data.

func FromContext

func FromContext(ctx context.Context) (*Session, bool)

FromContext retrieves Session from context.Context. Second value indicates if session is present in the context and if it's safe to use it (it's not nil).

Jump to

Keyboard shortcuts

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