gateway

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrStoreNotExists   = fmt.Errorf("gateway store doesn't exists")
	ErrNotFound         = fmt.Errorf("not found")
	ErrAlreadyExists    = fmt.Errorf("already exists")
	ErrInvalidConfig    = errors.New("invalid gateway store config")
	ErrInvalidGatewayID = errors.New("invalid gateway id")
)

Functions

func BytesToGatewayID

func BytesToGatewayID(id []byte) (lorawan.EUI64, error)

func GatewayNetworkIDFromPrivateKey added in v1.0.3

func GatewayNetworkIDFromPrivateKey(priv *ecdsa.PrivateKey) lorawan.EUI64

func GatewayPublicKeyToID

func GatewayPublicKeyToID(pubKey []byte) (lorawan.EUI64, error)

func NewPostgresStore added in v1.0.3

func NewPostgresStore(ctx context.Context, refreshInterval *time.Duration) (*pgStore, error)

NewPostgresStore returns a gateway store that uses a postgresql backend.

func NewPostgresStoreWithFilterer added in v1.0.3

func NewPostgresStoreWithFilterer(ctx context.Context, refreshInterval *time.Duration, filterer GatewayFiltererFunc) (*pgStore, error)

NewPostgresStore returns a gateway store that uses a postgresql backend and only imports gateways into the store for which the given filterer passes.

func NewYamlFileStore added in v1.0.3

func NewYamlFileStore(ctx context.Context, path string, refreshInterval *time.Duration) (*yamlFileStore, error)

func NewYamlFileStoreWithFilterer added in v1.0.3

func NewYamlFileStoreWithFilterer(ctx context.Context, path string, refreshInterval *time.Duration, filterer GatewayFiltererFunc) (*yamlFileStore, error)

func NoGatewayFilterer added in v1.0.3

func NoGatewayFilterer(gw *Gateway) bool

NoFilterer doesn't filter.

func SignPlainBatchOnboardMessage

func SignPlainBatchOnboardMessage(chainID *big.Int, contract common.Address, owner common.Address, version uint8, gw *Gateway) ([]byte, error)

SignPlainBatchOnboardMessage signs a gateway onboard message for the PlainBatchGatewayOnboarder smart contract

Types

type Config

type Config struct {
	BlockChain struct {
		Endpoint      string
		ChainID       uint64
		Confirmations uint64
	} `mapstructure:"blockchain"`
}

type ForwarderGatewayRecordUnknownConfig added in v1.0.3

type ForwarderGatewayRecordUnknownConfig struct {
	// File points to a file on the local file system where unknown gateways
	// that connect are recorded.
	File string

	// Postgresql if non nil indicates that unknown gateways must be recorded to
	// a postgresql database.
	Postgresql *bool `mapstructure:"postgresql"`
}

type Gateway

type Gateway struct {
	// LocalID is the gateway ID as used in the communication between gateway
	// and ThingsIX forwarder and is usually derived from the gateways hardware.
	LocalID lorawan.EUI64
	// NetId is the gateway id as used in the communication between the
	// forwarder and the ThingsIX network.
	NetworkID lorawan.EUI64
	// PrivateKey is the gateways private key
	PrivateKey *ecdsa.PrivateKey
	// PublicKey is the gateways public key from which the ThingsIX is derived.
	PublicKey *ecdsa.PublicKey
	// PublicKeyBytes
	PublicKeyBytes []byte
	// ThingsIxID is the gateway id as used when onboarding the gateway in
	// ThingsIX. It is the gateways public key without the `0x02` prefix.
	ThingsIxID ThingsIxID
	// Owner is the gateways owner if the gateway is onboarded in ThingsIX. If
	// nil it means the gateway is in the store but it is not onboarded in
	// ThingsIX (yet).
	Owner common.Address
}

Gateway represents a ThingsIX gateway

func GenerateNewGateway

func GenerateNewGateway(localID lorawan.EUI64) (*Gateway, error)

func NewGateway

func NewGateway(LocalID lorawan.EUI64, priv *ecdsa.PrivateKey) (*Gateway, error)

func (*Gateway) Address

func (gw *Gateway) Address() common.Address

func (Gateway) CompressedPubKeyBytes

func (gw Gateway) CompressedPubKeyBytes() []byte

CompressedPubKeyBytes returns the compressed public key with 0x02 prefix

func (Gateway) ID

func (gw Gateway) ID() ThingsIxID

ID is the identifier as which the gateway is registered in the gateway registry.

type GatewayFiltererFunc added in v1.0.3

type GatewayFiltererFunc func(gw *Gateway) bool

GatewayFiltererFunc is used by gateway stores to filter out gateways that are not (yet) suitable. For instance if these gateways have not yet been onboarded. If the gateway must be added to the in-memory gateway store and traffic must be exchanged between gateways and the ThingsIX network the filterer must return true for the given gw.

type GatewayRanger added in v1.0.3

type GatewayRanger interface {
	Do(*Gateway) bool
}

type GatewayRangerFunc added in v1.0.3

type GatewayRangerFunc func(*Gateway) bool

func (GatewayRangerFunc) Do added in v1.0.3

func (fn GatewayRangerFunc) Do(gw *Gateway) bool

type GatewayStore added in v1.0.3

type GatewayStore interface {
	// Count returns the number of gateways in the store.
	Count() int

	// Range calls fn sequentially for each gateway present in the store.
	// If fn returns false, range stops the iteration.
	Range(GatewayRanger)

	// ByLocalID returns the gateway identified by the given local id.
	// If not found ErrNotFound is returned.
	ByLocalID(localID lorawan.EUI64) (*Gateway, error)

	// Returns the gateway identified by the given local id as string.
	// If not found ErrNotFound is returned.
	ByLocalIDString(id string) (*Gateway, error)

	// ContainsByLocalID returns an indication if there is gateway in the store
	// that is identified by the given local id.
	ContainsByLocalID(localID lorawan.EUI64) bool

	// ByNetworkID returns the gateway identified by the given network id.
	// If not found ErrNotFound is returned.
	ByNetworkID(netID lorawan.EUI64) (*Gateway, error)

	// ByNetworkIDString returns the gateway identified by the given network id
	// as string. If not found ErrNotFound is returned.
	ByNetworkIDString(id string) (*Gateway, error)

	// ContainsByNetID returns an indication if there is gateway in the store
	// that is identified by the given network id.
	ContainsByNetID(netID lorawan.EUI64) bool

	// ByThingsIxID returns the gateway identified by the given ThingsIX id.
	// If not found ErrNotFound is returned.
	ByThingsIxID(id ThingsIxID) (*Gateway, error)

	// Add creates a net gateway record based on the given localID and key and
	// adds it to the store.
	Add(ctx context.Context, localID lorawan.EUI64, key *ecdsa.PrivateKey) (*Gateway, error)
}

func NewGatewayStore added in v1.0.3

func NewGatewayStore(ctx context.Context, cfg *StoreConfig) (GatewayStore, error)

NewGatewayStore returns a gateway store that was configured in the given cfg.

type GatewayStoreType added in v1.0.3

type GatewayStoreType uint
const (
	NoGatewayStoreType GatewayStoreType = iota
	YamlFileGatewayStore
	PostgresqlGatewayStore
)

type StoreConfig added in v1.0.3

type StoreConfig struct {
	// RefreshInterval indicates how often the gateway store is reloaded from
	// the backend store. If this is a nil ptr hot reloads are disabled.
	RefreshInterval *time.Duration `mapstructure:"refresh"`

	// YamlStorePath indicates that gateways are stored in a
	// YAML based file store located on the local file system.
	// Only data for gateways in the store is forwarded.
	YamlStorePath *string `mapstructure:"file"`

	// Use a PGSQL database to store gateways.
	Postgresql *bool `mapstructure:"postgresql"`
}

func (StoreConfig) Type added in v1.0.3

func (sc StoreConfig) Type() GatewayStoreType

type ThingsIxID added in v1.0.3

type ThingsIxID [32]byte

ThingsIxID is the gateways public key without the leading `0x02`.

func (ThingsIxID) String added in v1.0.3

func (id ThingsIxID) String() string

Jump to

Keyboard shortcuts

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