ws

package
v3.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2021 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	UseTrafficTLSAddress: false,
	WSPingInterval:       30 * time.Second,

	TimeSyncInterval:     200 * time.Second,
	AllowUnauthenticated: false,
}

DefaultConfig contains the default configuration.

Functions

func New

func New(ctx context.Context, server io.Server, formatter Formatter, cfg Config) *echo.Echo

New creates a new WebSocket frontend.

func NewContextWithSession

func NewContextWithSession(ctx context.Context, session *Session) context.Context

NewContextWithSession returns a new context with the session.

Types

type Config

type Config struct {
	UseTrafficTLSAddress bool          `name:"use-traffic-tls-address" description:"Use WSS for the traffic address regardless of the TLS setting"`
	WSPingInterval       time.Duration `name:"ws-ping-interval" description:"Interval to send WS ping messages"`
	TimeSyncInterval     time.Duration `name:"time-sync-interval" description:"Interval to send time transfer messages"`
	AllowUnauthenticated bool          `name:"allow-unauthenticated" description:"Allow unauthenticated connections"`
}

Config defines the LoRa Basics Station configuration of the Gateway Server.

type Endpoints

type Endpoints struct {
	ConnectionInfo string
	Traffic        string
}

Endpoints contains the connection endpoints for the protocol

type Formatter

type Formatter interface {
	// Endpoints fetches the connection endpoints for the protocol.
	Endpoints() Endpoints
	// HandleConnectionInfo handles connection information requests from web socket based protocols.
	// This function returns a byte stream that contains connection information (ex: scheme, host, port etc) or an error if applicable.
	HandleConnectionInfo(ctx context.Context, raw []byte, server io.Server, serverInfo ServerInfo, receivedAt time.Time) []byte
	// HandleUp handles upstream messages from web socket based gateways.
	// This function optionally returns a byte stream to be sent as response to the upstream message.
	HandleUp(ctx context.Context, raw []byte, ids ttnpb.GatewayIdentifiers, conn *io.Connection, receivedAt time.Time) ([]byte, error)
	// FromDownlink generates a downlink byte stream that can be sent over the WS connection.
	FromDownlink(ctx context.Context, down ttnpb.DownlinkMessage, bandID string, concentratorTime scheduling.ConcentratorTime, dlTime time.Time) ([]byte, error)
	// TransferTime generates a spurious time transfer message for a particular server time.
	TransferTime(ctx context.Context, t time.Time, conn *io.Connection) ([]byte, error)
}

Formatter abstracts messages to/from websocket based gateways.

type ServerInfo

type ServerInfo struct {
	Scheme  string
	Address string
}

ServerInfo contains information on the WebSocket server.

type Session

type Session struct {
	DataMu sync.RWMutex
	Data   interface{}
}

Session contains the session state for a single gateway.

func SessionFromContext

func SessionFromContext(ctx context.Context) *Session

SessionFromContext returns a new session from the context. The session value can be modified by the caller.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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