server

package
v0.0.0-...-cfba5c7 Latest Latest
Warning

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

Go to latest
Published: May 2, 2018 License: Apache-2.0 Imports: 17 Imported by: 5

Documentation

Overview

Package server contains the structs used in the pipeline and associated types.

Index

Constants

View Source
const (
	DefaultGatewayPort     = 8000
	DefaultHTTPPort        = 8080
	DefaultDebugPort       = 8081
	DefaultNetworkID       = 0
	DefaultMA              = "00-09-09"
	DefaultConnectHost     = "connect.staging.telenordigital.com"
	DefaultConnectClientID = "telenordigital-connectexample-web"
	DefaultLogLevel        = 0
	DefaultMaxConns        = 200
	DefaultIdleConns       = 100
	DefaultConnLifetime    = 10 * time.Minute
)

This is the default configuration

Variables

View Source
var (
	// ErrInvalidTransport is returned when the transport config is invalid (or unknown)
	ErrInvalidTransport = errors.New("invalid transport config")

	// ErrNotFound is returned when the output can't be found
	ErrNotFound = errors.New("output not found")
)

Functions

This section is empty.

Types

type AppOutputManager

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

AppOutputManager is a memory-backed list of outputs. This includes all app outputs for the instance. The list of dispatchers are keyed on application EUI and output EUI.

func NewAppOutputManager

func NewAppOutputManager(router router) *AppOutputManager

NewAppOutputManager builds a new output manager.

func (*AppOutputManager) Add

func (m *AppOutputManager) Add(op *model.AppOutput) error

Add adds a new app output

func (*AppOutputManager) GetStatusAndLogs

func (m *AppOutputManager) GetStatusAndLogs(op *model.AppOutput) (string, *MemoryLogger, error)

GetStatusAndLogs returns the status and logs for the specified app output

func (*AppOutputManager) LoadOutputs

func (m *AppOutputManager) LoadOutputs(opstorage outputStorage)

LoadOutputs loads and starts all outputs from the storage

func (*AppOutputManager) Remove

func (m *AppOutputManager) Remove(op *model.AppOutput) error

Remove removes the output and stops it

func (*AppOutputManager) Shutdown

func (m *AppOutputManager) Shutdown()

Shutdown closes all running message dispatchers

func (*AppOutputManager) Update

func (m *AppOutputManager) Update(op *model.AppOutput) error

Update updates and restarts the app output

type Configuration

type Configuration struct {
	GatewayPort           int
	HTTPServerPort        int
	NetworkID             uint   // The network ID that this instance handles. The default is 0
	MA                    string // String representation of MA
	DBConnectionString    string
	PrintSchema           bool
	Syslog                bool
	DisableGatewayChecks  bool
	ConnectHost           string
	ConnectClientID       string
	ConnectRedirectLogin  string
	ConnectRedirectLogout string
	ConnectPassword       string
	DisableAuth           bool
	ConnectLoginTarget    string
	ConnectLogoutTarget   string
	TLSCertFile           string
	TLSKeyFile            string
	UseSecureCookie       bool
	LogLevel              uint
	PlainLog              bool // Fancy stderr logs with emojis and colors
	MemoryDB              bool
	OnlyLoopback          bool // use only loopback adapter - for testing
	ProfilingEndpoint     bool // Turn on profiling endpoint - for testing
	RuntimeTrace          bool // Turn on runtime trace - for testing
	MemoryMinLatencyMs    int
	MemoryMaxLatencyMs    int
	DebugPort             int // Debug port - 0 for random, default 8081
	DBMaxConnections      int
	DBIdleConnections     int
	DBConnLifetime        time.Duration
	ACMECert              bool   // AutoCert via Let's Encrypt
	ACMEHost              string // AutoCert hostname
	ACMESecretDir         string
}

Configuration holds the configuration for the system

func NewDefaultConfig

func NewDefaultConfig() *Configuration

NewDefaultConfig returns the default configuration. Note that this configuration isn't valid right out of the box; a storage backend must be selected.

func NewMemoryNoAuthConfig

func NewMemoryNoAuthConfig() *Configuration

NewMemoryNoAuthConfig returns a configuration with no authentication and memory-backed storage. This is a valid configuration.

func (*Configuration) RootMA

func (cfg *Configuration) RootMA() protocol.MA

RootMA returns the MA to use as the base MA for EUIs. The configuration is assumed to be valid at this point. If there's an error converting the MA it will panic.

func (*Configuration) Validate

func (cfg *Configuration) Validate() error

Validate checks the configuration for inconsistencies and errors. This function logs the warnings using the logger package as well.

type Context

type Context struct {
	Storage       *storage.Storage    // The storage layer
	Terminator    chan bool           // Terminator channel. Throw something on this to terminate the processes.
	FrameOutput   *FrameOutputBuffer  // Device aggregator instance. Common instance for processors.
	Config        *Configuration      // Main configuration
	KeyGenerator  *KeyGenerator       // Key generator for server
	GwEventRouter *pubsub.EventRouter // Router for GW events
	AppRouter     *pubsub.EventRouter // Router for app data
	AppOutput     *AppOutputManager
}

Context is the request/response context. It is passed along with the packets in various states.

type FrameContext

type FrameContext struct {
	Device         model.Device      // The decoded Device. Nil if it haven't been decoded yet.
	Application    model.Application // The decoded application. Nil if it haven't been resolved yet.
	GatewayContext GatewayPacket     // Context for gateway'
}

FrameContext is the context for each frame received (frequency, encoding, data rate rx1 offset and so on)

type FrameOutputBuffer

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

FrameOutputBuffer buffers the payload (as bytes) and MAC commands that should be transmitted to the end-device in the next frame(s). If the payload or MAC commands doesn't fit into one frame it will be split into multiple parts.

func NewFrameOutputBuffer

func NewFrameOutputBuffer() FrameOutputBuffer

NewFrameOutputBuffer creates a new FrameOutputBuffer instance.

func (*FrameOutputBuffer) AddMACCommand

func (d *FrameOutputBuffer) AddMACCommand(deviceEUI protocol.EUI, cmd protocol.MACCommand) error

AddMACCommand adds a new MAC command to the device aggregator. Returns error if there is no more room for MAC commands. The MAC Command will be sent as soon as possible. BUG(stalehd): Does not keep track of the mac command length

func (*FrameOutputBuffer) GetPHYPayloadForDevice

func (d *FrameOutputBuffer) GetPHYPayloadForDevice(device *model.Device, context *FrameContext) (protocol.PHYPayload, error)

GetPHYPayloadForDevice retrieves the next PHYPayload item for the device. If there's no data available for the device an error is returned. Note that this might not pull all of the data for the device. BUG(stalehd): Uses fixed max length for payload

func (*FrameOutputBuffer) SetJoinAcceptPayload

func (d *FrameOutputBuffer) SetJoinAcceptPayload(deviceEUI protocol.EUI, payload protocol.JoinAcceptPayload)

SetJoinAcceptPayload sets the JoinAccept payload that should be sent to the device.

func (*FrameOutputBuffer) SetMessageAckFlag

func (d *FrameOutputBuffer) SetMessageAckFlag(deviceEUI protocol.EUI, ackFlag bool)

SetMessageAckFlag sets the message acknowledgement flag. If the flag is set a message will be sent to the device at the earliest opportunity, regardless if there's payload or MAC frames to be sent.

func (*FrameOutputBuffer) SetPayload

func (d *FrameOutputBuffer) SetPayload(deviceEUI protocol.EUI, payload []byte, port uint8, ack bool)

SetPayload sets (or overwrites) the existing payload. An error is returned if the payload can't be set.

type GatewayContext

type GatewayContext struct {
	GatewayEUI      protocol.EUI // The reported EUI
	GatewayHost     string       // The originating host
	GatewayPort     int          // The originating port
	GatewayClock    uint32       // Clock ticks reported by gateway
	ProtocolVersion uint8        // Protocol version (wrt packet forwarder)
}

GatewayContext - metadata for gateway; used when responding

type GatewayPacket

type GatewayPacket struct {
	RawMessage   []byte
	Radio        RadioContext
	Gateway      GatewayContext
	ReceivedAt   time.Time
	SectionTimer monitoring.Timer
	InTimer      monitoring.Timer // processing from gw -> scheduler, waiting for send
	OutTimer     monitoring.Timer // processing from scheduler -> gw, sending
	Deadline     float64          // Send deadline for packet (in seconds)
}

GatewayPacket contains a byte buffer plus radio statistics.

type KeyGenerator

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

KeyGenerator generates unique application and device EUIs with the help of a MA, NetID and a storage-backed sequence. If the backend is down it will retry forever until the new sequence can be created. If the backend isn't responding and the allocated block is used the ID generator will block until a new block is allocated.

func NewEUIKeyGenerator

func NewEUIKeyGenerator(ma protocol.MA, netID uint32, keyStorage storage.KeySequenceStorage) (KeyGenerator, error)

NewEUIKeyGenerator creates a new KeyGenerator instance

func (*KeyGenerator) NewAppEUI

func (k *KeyGenerator) NewAppEUI() (protocol.EUI, error)

NewAppEUI creates a new application EUI. This call might block if the storage backend is down. The returned EUI will always be a valid EUI but if the error field is set it won't be unique.

func (*KeyGenerator) NewDeviceEUI

func (k *KeyGenerator) NewDeviceEUI() (protocol.EUI, error)

NewDeviceEUI creates a new device EUI. This call might block if the storage backend is down. The returned EUI will always be a valid EUI but if the error field is set it won't be unique.

func (*KeyGenerator) NewID

func (k *KeyGenerator) NewID(identifier string) uint64

NewID creates a new generic ID. This call might block if the storage backend is down. The returned EUI will always be a valid EUI but if the error field is set it won't be unique.

func (*KeyGenerator) NewOutputEUI

func (k *KeyGenerator) NewOutputEUI() (protocol.EUI, error)

NewOutputEUI generates a new EUI for an output. It uses the same scope as application EUIs.

type LoRaMessage

type LoRaMessage struct {
	Payload      protocol.PHYPayload // PHYPayload decoded from GatewayPacket bytes.
	FrameContext FrameContext        // Frame context; set for each frame that arrives
}

LoRaMessage contains the decoded LoRa message

type LogEntry

type LogEntry struct {
	Timestamp time.Time
	Message   string
}

LogEntry is a single log entry for outputs

func NewLogEntry

func NewLogEntry(message string) LogEntry

NewLogEntry creates a new log entry

func (*LogEntry) IsValid

func (l *LogEntry) IsValid() bool

IsValid returns true if the message is valid

func (*LogEntry) TimeString

func (l *LogEntry) TimeString() string

TimeString converts the timestamp into a time string

type MemoryLogger

type MemoryLogger struct {
	Entries []LogEntry
	// contains filtered or unexported fields
}

MemoryLogger logs events to a circular buffer

func NewMemoryLogger

func NewMemoryLogger() MemoryLogger

NewMemoryLogger creates a new memory logger

func (*MemoryLogger) Append

func (m *MemoryLogger) Append(newEntry LogEntry)

Append appends a new log item to the log

func (*MemoryLogger) Items

func (m *MemoryLogger) Items() []LogEntry

Items returns the list of items

type PayloadMessage

type PayloadMessage struct {
	Payload      []byte                // Unencrypted from the PHYPayload struct
	Device       model.Device          // The device that the payload was received from (or will be sent to)
	Application  model.Application     // The device's application.
	MACCommands  []protocol.MACCommand // MAC Commands received from/sent to the device
	FrameContext FrameContext          // The context the packet is received in
}

PayloadMessage contains the decrypted and verified payload

type RadioContext

type RadioContext struct {
	Channel   uint8              // The channel used
	RFChain   uint8              // The RF chain the packet was received on
	Frequency float32            // Frequency - set by GW IF
	DataRate  string             // DataRate (f.e. "SF7BW125") - set by GW IF
	Band      band.FrequencyPlan // Band used
	RX1Delay  uint8              // RX1Delay - set during decoding
	RX2Delay  uint8              // RX2Delay - set during decoding
	RSSI      int32              // RSSI for device - set by GW IF
	SNR       float32            // SNR for device - set by GW IF
}

RadioContext - metadata for radio stats and settings

Notes

Bugs

  • Does not keep track of the mac command length

  • Uses fixed max length for payload

Jump to

Keyboard shortcuts

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