ws

package
v3.30.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package ws provides common interface for Web Socket front end.

Index

Constants

View Source
const (
	// XTime48BitLSBMask is the mask used to extract the lower 48 bits of the XTime.
	XTime48BitLSBMask = 0xFFFFFFFFFFFF
)

Variables

View Source
var DefaultConfig = Config{
	UseTrafficTLSAddress: false,
	WSPingInterval:       30 * time.Second,
	MissedPongThreshold:  2,
	TimeSyncInterval:     200 * time.Second,
	AllowUnauthenticated: false,
}

DefaultConfig contains the default configuration.

Functions

func ConcentratorTimeFromXTime added in v3.22.2

func ConcentratorTimeFromXTime(xTime int64) scheduling.ConcentratorTime

ConcentratorTimeFromXTime constructs the scheduling.ConcentratorTime associated with the provided XTime.

func ConcentratorTimeToXTime added in v3.22.2

func ConcentratorTimeToXTime(id int32, t scheduling.ConcentratorTime) int64

ConcentratorTimeToXTime contructs the XTime associated with the provided session ID and concentrator timestamp. Bytes 0-5 (6 bytes = 48 bits) are used for the timestamp. Bytes 6-8 are returned unmodified to the gateway from the xtime read on the latest uplink.

func GetSessionID added in v3.22.2

func GetSessionID(ctx context.Context) (int32, bool)

GetSessionID returns the session ID.

func GetSessionTimeSync added in v3.22.2

func GetSessionTimeSync(ctx context.Context) (enabled bool, ok bool)

GetSessionTimeSync returns the session time sync.

func New

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

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.

func SessionIDFromXTime added in v3.22.2

func SessionIDFromXTime(xTime int64) int32

SessionIDFromXTime constructs the session ID associated with the provided XTime.

func TimeFromGPSTime added in v3.22.2

func TimeFromGPSTime(t int64) time.Time

TimeFromGPSTime constructs a time.Time from the provided GPS time in microseconds.

func TimeFromUnixSeconds added in v3.22.2

func TimeFromUnixSeconds(tf float64) time.Time

TimeFromUnixSeconds constructs a time.Time from the provided UNIX fractional timestamp.

func TimePtrFromGPSTime added in v3.22.2

func TimePtrFromGPSTime(t int64) *time.Time

TimePtrFromGPSTime constructs a *time.Time from the provided GPS time in microseconds. If the timestamp is 0, this function returns nil.

func TimePtrFromUnixSeconds added in v3.22.2

func TimePtrFromUnixSeconds(tf float64) *time.Time

TimeFromUnixSeconds constructs a *time.Time from the provided UNIX fractional timestamp. If the timestamp is 0, this function returns nil.

func TimePtrFromUpInfo added in v3.22.2

func TimePtrFromUpInfo(gpsTime int64, rxTime float64) *time.Time

TimePtrFromUpInfo contructs a *time.Time from the provided uplink metadata information. The GPS timestamp (microseconds) is used if present, then the RxTime. The function returns nil if both timestamps are unavailable.

func TimePtrToUpInfoTime added in v3.22.2

func TimePtrToUpInfoTime(t *time.Time) (float64, int64)

TimePtrToUpInfoTime constructs the RxTime and GPSTime from the provided *time.Time. If the time is nil, this function returns (0.0, 0).

func TimeToGPSTime added in v3.22.2

func TimeToGPSTime(t time.Time) int64

TimeToGPSTime contructs a GPS timestamp from the provided time.Time.

func TimeToUnixSeconds added in v3.22.2

func TimeToUnixSeconds(t time.Time) float64

TimeToUnixSeconds constructs a UNIX fractional timestamp from the provided time.Time.

func TimestampFromXTime added in v3.22.2

func TimestampFromXTime(xTime int64) uint32

TimestampFromXTime constructs the concentrator timestamp associated with the provided XTime.

func UpdateSessionID added in v3.22.2

func UpdateSessionID(ctx context.Context, id int32)

UpdateSessionID updates the session ID.

func UpdateSessionTimeSync added in v3.22.2

func UpdateSessionTimeSync(ctx context.Context, b bool)

UpdateSessionTimeSync updates the session time sync.

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"`
	MissedPongThreshold  int           `` /* 163-byte string literal not displayed */
	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,
		assertAuth func(context.Context, *ttnpb.GatewayIdentifiers) error,
	) []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, dlTime time.Time) ([]byte, error)
	// TransferTime generates a spurious time transfer message for a particular server time.
	TransferTime(
		ctx context.Context, serverTime time.Time, gpsTime *time.Time, concentratorTime *scheduling.ConcentratorTime,
	) ([]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   any
}

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
Package id6 provides translation functions to the ID6 format.
Package id6 provides translation functions to the ID6 format.

Jump to

Keyboard shortcuts

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