gateway

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: Apache-2.0 Imports: 34 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")
	ErrServiceNotAvailable          = fmt.Errorf("service not available")
	ErrAlreadyExists                = fmt.Errorf("already exists")
	ErrInvalidConfig                = errors.New("invalid gateway store config")
	ErrInvalidGatewayID             = errors.New("invalid gateway id")
	ErrGatewayRegistryConfigMissing = errors.New("gateway ThingsIX registry config missing")
	ErrTooManySyncRequests          = errors.New("too fast gateway sync request")
)
View Source
var (
	// ErrRecordingUnknownGatewaysDisabled is thrown when recorded unknown
	// gateways are retrieved when this functionality is disabled.
	ErrRecordingUnknownGatewaysDisabled = fmt.Errorf("record unknown gateways disabled")
)
View Source
var GatewayRegistryABI = GatewayRegistryMetaData.ABI

GatewayRegistryABI is the input ABI used to generate the binding from. Deprecated: Use GatewayRegistryMetaData.ABI instead.

View Source
var GatewayRegistryMetaData = &bind.MetaData{
	ABI: "[{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"id\",\"type\":\"bytes32\"}],\"name\":\"gateways\",\"outputs\":[{\"components\":[{\"internalType\":\"bytes32\",\"name\":\"publicKey\",\"type\":\"bytes32\"},{\"internalType\":\"uint8\",\"name\":\"version\",\"type\":\"uint8\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"antennaGain\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"frequencyPlan\",\"type\":\"uint8\"},{\"internalType\":\"int64\",\"name\":\"location\",\"type\":\"int64\"},{\"internalType\":\"uint8\",\"name\":\"altitude\",\"type\":\"uint8\"}],\"internalType\":\"structIGatewayRegistry.Gateway\",\"name\":\"\",\"type\":\"tuple\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]",
}

GatewayRegistryMetaData contains all meta data concerning the GatewayRegistry contract.

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, registry ThingsIXRegistry, defaultFreqPlan frequency_plan.BandName) (*pgStore, error)

NewPostgresStore returns a gateway store that uses a postgresql backend.

func NewYamlFileStore added in v1.0.3

func NewYamlFileStore(ctx context.Context, path string, registry ThingsIXRegistry, defaultFreqPlan frequency_plan.BandName) (*yamlFileStore, error)

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 Collector added in v1.0.4

type Collector struct {
	Gateways []*Gateway
}

func (*Collector) Do added in v1.0.4

func (c *Collector) Do(gw *Gateway) bool

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 `json:"localId"`
	// NetId is the gateway id as used in the communication between the
	// forwarder and the ThingsIX network.
	NetworkID lorawan.EUI64 `json:"networkId"`
	// PrivateKey is the gateways private key
	PrivateKey *ecdsa.PrivateKey `json:"-"`
	// PublicKey is the gateways public key from which the ThingsIX is derived.
	PublicKey *ecdsa.PublicKey `json:"-"`
	// PublicKeyBytes
	PublicKeyBytes []byte `json:"-"`
	// 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 `json:"gatewayId"`
	// Owner is the gateways owner if the gateway is onboarded in ThingsIX. If
	// nil the gateway is in the store but it is not onboarded in the ThingsIX
	// gateway registry.
	Owner *common.Address `json:"owner,omitempty"`
	// Version can be freely set when importing the gateway in the store. If nil
	// it means the gateway is in the store but it is not onboarded in the
	// ThingsIX gateway registry. ThingsIX doesn't use this value.
	Version *uint8 `json:"version,omitempty"`
	// Details set by the gateway owner. Can be empty when the details are not
	// set or the details are not yet retrieved.
	Details *GatewayDetails `json:"details,omitempty"`
}

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 NewOnboardedGateway added in v1.0.4

func NewOnboardedGateway(LocalID lorawan.EUI64, priv *ecdsa.PrivateKey, owner common.Address, version uint8) (*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.

func (Gateway) Onboarded added in v1.0.4

func (gw Gateway) Onboarded() bool

Onboarded returns an indication if the gateway is onboarded.

func (Gateway) OwnerBytes added in v1.0.4

func (gw Gateway) OwnerBytes() []byte

OwnerBytes returns the owner bytes or if the gateway isn't onboarded the zero address bytes.

type GatewayDetails added in v1.0.4

type GatewayDetails struct {
	AntennaGain *string `json:"antennaGain,omitempty"`
	Band        *string `json:"band,omitempty"`
	Location    *string `json:"location,omitempty"`
	Altitude    *uint16 `json:"altitude,omitempty"`
}

Details are available after the owner set gateway details

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 GatewayRegistry added in v1.0.4

type GatewayRegistry struct {
	GatewayRegistryCaller     // Read-only binding to the contract
	GatewayRegistryTransactor // Write-only binding to the contract
	GatewayRegistryFilterer   // Log filterer for contract events
}

GatewayRegistry is an auto generated Go binding around an Ethereum contract.

func NewGatewayRegistry added in v1.0.4

func NewGatewayRegistry(address common.Address, backend bind.ContractBackend) (*GatewayRegistry, error)

NewGatewayRegistry creates a new instance of GatewayRegistry, bound to a specific deployed contract.

type GatewayRegistryCaller added in v1.0.4

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

GatewayRegistryCaller is an auto generated read-only Go binding around an Ethereum contract.

func NewGatewayRegistryCaller added in v1.0.4

func NewGatewayRegistryCaller(address common.Address, caller bind.ContractCaller) (*GatewayRegistryCaller, error)

NewGatewayRegistryCaller creates a new read-only instance of GatewayRegistry, bound to a specific deployed contract.

func (*GatewayRegistryCaller) Gateways added in v1.0.4

func (_GatewayRegistry *GatewayRegistryCaller) Gateways(opts *bind.CallOpts, id [32]byte) (Struct0, error)

Gateways is a free data retrieval call binding the contract method 0xfbe336ff.

Solidity: function gateways(bytes32 id) view returns((bytes32,uint8,address,uint8,uint8,int64,uint8))

type GatewayRegistryCallerRaw added in v1.0.4

type GatewayRegistryCallerRaw struct {
	Contract *GatewayRegistryCaller // Generic read-only contract binding to access the raw methods on
}

GatewayRegistryCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.

func (*GatewayRegistryCallerRaw) Call added in v1.0.4

func (_GatewayRegistry *GatewayRegistryCallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error

Call invokes the (constant) contract method with params as input values and sets the output to result. The result type might be a single field for simple returns, a slice of interfaces for anonymous returns and a struct for named returns.

type GatewayRegistryCallerSession added in v1.0.4

type GatewayRegistryCallerSession struct {
	Contract *GatewayRegistryCaller // Generic contract caller binding to set the session for
	CallOpts bind.CallOpts          // Call options to use throughout this session
}

GatewayRegistryCallerSession is an auto generated read-only Go binding around an Ethereum contract, with pre-set call options.

func (*GatewayRegistryCallerSession) Gateways added in v1.0.4

func (_GatewayRegistry *GatewayRegistryCallerSession) Gateways(id [32]byte) (Struct0, error)

Gateways is a free data retrieval call binding the contract method 0xfbe336ff.

Solidity: function gateways(bytes32 id) view returns((bytes32,uint8,address,uint8,uint8,int64,uint8))

type GatewayRegistryFilterer added in v1.0.4

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

GatewayRegistryFilterer is an auto generated log filtering Go binding around an Ethereum contract events.

func NewGatewayRegistryFilterer added in v1.0.4

func NewGatewayRegistryFilterer(address common.Address, filterer bind.ContractFilterer) (*GatewayRegistryFilterer, error)

NewGatewayRegistryFilterer creates a new log filterer instance of GatewayRegistry, bound to a specific deployed contract.

type GatewayRegistryRaw added in v1.0.4

type GatewayRegistryRaw struct {
	Contract *GatewayRegistry // Generic contract binding to access the raw methods on
}

GatewayRegistryRaw is an auto generated low-level Go binding around an Ethereum contract.

func (*GatewayRegistryRaw) Call added in v1.0.4

func (_GatewayRegistry *GatewayRegistryRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error

Call invokes the (constant) contract method with params as input values and sets the output to result. The result type might be a single field for simple returns, a slice of interfaces for anonymous returns and a struct for named returns.

func (*GatewayRegistryRaw) Transact added in v1.0.4

func (_GatewayRegistry *GatewayRegistryRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error)

Transact invokes the (paid) contract method with params as input values.

func (*GatewayRegistryRaw) Transfer added in v1.0.4

func (_GatewayRegistry *GatewayRegistryRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error)

Transfer initiates a plain transaction to move funds to the contract, calling its default method if one is available.

type GatewayRegistrySession added in v1.0.4

type GatewayRegistrySession struct {
	Contract     *GatewayRegistry  // Generic contract binding to set the session for
	CallOpts     bind.CallOpts     // Call options to use throughout this session
	TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
}

GatewayRegistrySession is an auto generated Go binding around an Ethereum contract, with pre-set call and transact options.

func (*GatewayRegistrySession) Gateways added in v1.0.4

func (_GatewayRegistry *GatewayRegistrySession) Gateways(id [32]byte) (Struct0, error)

Gateways is a free data retrieval call binding the contract method 0xfbe336ff.

Solidity: function gateways(bytes32 id) view returns((bytes32,uint8,address,uint8,uint8,int64,uint8))

type GatewayRegistryTransactor added in v1.0.4

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

GatewayRegistryTransactor is an auto generated write-only Go binding around an Ethereum contract.

func NewGatewayRegistryTransactor added in v1.0.4

func NewGatewayRegistryTransactor(address common.Address, transactor bind.ContractTransactor) (*GatewayRegistryTransactor, error)

NewGatewayRegistryTransactor creates a new write-only instance of GatewayRegistry, bound to a specific deployed contract.

type GatewayRegistryTransactorRaw added in v1.0.4

type GatewayRegistryTransactorRaw struct {
	Contract *GatewayRegistryTransactor // Generic write-only contract binding to access the raw methods on
}

GatewayRegistryTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.

func (*GatewayRegistryTransactorRaw) Transact added in v1.0.4

func (_GatewayRegistry *GatewayRegistryTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error)

Transact invokes the (paid) contract method with params as input values.

func (*GatewayRegistryTransactorRaw) Transfer added in v1.0.4

func (_GatewayRegistry *GatewayRegistryTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error)

Transfer initiates a plain transaction to move funds to the contract, calling its default method if one is available.

type GatewayRegistryTransactorSession added in v1.0.4

type GatewayRegistryTransactorSession struct {
	Contract     *GatewayRegistryTransactor // Generic contract transactor binding to set the session for
	TransactOpts bind.TransactOpts          // Transaction auth options to use throughout this session
}

GatewayRegistryTransactorSession is an auto generated write-only Go binding around an Ethereum contract, with pre-set transact options.

type GatewayStore added in v1.0.3

type GatewayStore interface {
	// Run the background tasks in the store until the given ctx expires.
	Run(ctx context.Context)

	// 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)

	// SyncGatewayByLocalID syncs the gateway identified by the given local id
	// and returns it after sync.
	SyncGatewayByLocalID(ctx context.Context, localID lorawan.EUI64, force bool) (*Gateway, error)

	// UniqueGatewayBands returns the flattened set of frequency plans for all
	// gateways in the store.
	UniqueGatewayBands() UniqueGatewayBands

	// DefaultFrequencyPlan returns the default frequency plan if set through
	// the configuration. If not it returns Invalid.
	DefaultFrequencyPlan() frequency_plan.BandName
}

func NewGatewayStore added in v1.0.3

func NewGatewayStore(ctx context.Context, storeCfg *StoreConfig, registryCfg *RegistrySyncConfig) (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 GatewayThingsIXAPI added in v1.0.4

type GatewayThingsIXAPI struct {
	// Endpoint holds the ThingsIX API endpoint to retrieve gateway info
	Endpoint string
	// contains filtered or unexported fields
}

func (*GatewayThingsIXAPI) GatewayDetails added in v1.0.4

func (sync *GatewayThingsIXAPI) GatewayDetails(ctx context.Context, gatewayID ThingsIxID, force bool) (common.Address, uint8, *GatewayDetails, error)

type GatewayThingsIXSmartContract added in v1.0.4

type GatewayThingsIXSmartContract struct {
	// Endpoint is the RPC endpoint for the blockchain node
	Endpoint string
	// Confirmations holds the block confirmations
	Confirmations uint64
	// Addr holds the gateway registry address
	Addr common.Address
}

func (*GatewayThingsIXSmartContract) GatewayDetails added in v1.0.4

func (sync *GatewayThingsIXSmartContract) GatewayDetails(ctx context.Context, gatewayID ThingsIxID, force bool) (common.Address, uint8, *GatewayDetails, error)

type RecordedUnknownGateway added in v1.0.4

type RecordedUnknownGateway struct {
	LocalID lorawan.EUI64 `gorm:"primaryKey;column:local_id" yaml:"local_id" json:"localId"`
	// FirstSeen holds the unix time stamp when the gateway was first seen.
	// Can be nill for old recorded gateways.
	FirstSeen *int64 `yaml:"first_seen" json:"firstSeen,omitempty"`
}

func (*RecordedUnknownGateway) UnmarshalYAML added in v1.0.4

func (unkn *RecordedUnknownGateway) UnmarshalYAML(unmarshal func(interface{}) error) error

type RegistrySyncAPIConfig added in v1.0.4

type RegistrySyncAPIConfig struct {
	Endpoint string `mapstructure:"endpoint"`
}

RegistrySyncAPIConfig retrieve gateway information from the ThingsIX gateway registry through the HTTP API.

type RegistrySyncConfig added in v1.0.4

type RegistrySyncConfig struct {
	ThingsIxApi RegistrySyncAPIConfig      `mapstructure:"thingsix_api"`
	OnChain     *RegistrySyncOnChainConfig `mapstructure:"on_chain"`
}

RegistrySyncConfig describes how gateway information is retrieved from the ThingsIX gateway registry.

type RegistrySyncOnChainConfig added in v1.0.4

type RegistrySyncOnChainConfig struct {
	Endpoint     string
	Confirmation uint64
	ChainID      uint64
	Address      common.Address `mapstructure:"address"`
}

RegistrySyncOnChainConfig retrieve gateway information from the ThingsIX gateway registry from the smart contract.

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"`

	// DefaultGatewayFrequencyPlan contains if valid a default frequency plan
	// that is used for gateways that are not fully onboarded.
	DefaultGatewayFrequencyPlan frequency_plan.BandName `mapstructure:"default_frequency_plan"`

	// 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 Struct0 added in v1.0.4

type Struct0 struct {
	PublicKey     [32]byte
	Version       uint8
	Owner         common.Address
	AntennaGain   uint8
	FrequencyPlan uint8
	Location      int64
	Altitude      uint8
}

Struct0 is an auto generated low-level Go binding around an user-defined struct.

type ThingsIXRegistry added in v1.0.4

type ThingsIXRegistry interface {
	// GatewayDetails retrieves gateway details from the ThingsIX registry.
	// Depending on the implementation it can use a cache, set force=true to
	// disable this cache and force a new request.
	GatewayDetails(ctx context.Context, gatewayID ThingsIxID, force bool) (common.Address, uint8, *GatewayDetails, error)
}

ThingsIXRegistry provides access to ThingsIX gateway registry.

func NewThingsIXGatewayRegistry added in v1.0.4

func NewThingsIXGatewayRegistry(cfg *RegistrySyncConfig) (ThingsIXRegistry, error)

NewThingsIXGatewayRegistry builds a new ThingsIX gateway registry client.

type ThingsIxID added in v1.0.3

type ThingsIxID [32]byte

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

func (ThingsIxID) MarshalText added in v1.0.4

func (tid ThingsIxID) MarshalText() ([]byte, error)

func (ThingsIxID) String added in v1.0.3

func (id ThingsIxID) String() string

func (*ThingsIxID) UnmarshalText added in v1.0.4

func (tid *ThingsIxID) UnmarshalText(raw []byte) error

type UniqueGatewayBands added in v1.0.8

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

UniqueGatewayBands represents the unique set of frequency plans/bands

func (UniqueGatewayBands) ContainsBand added in v1.0.8

func (u UniqueGatewayBands) ContainsBand(band frequency_plan.BandName) bool

func (UniqueGatewayBands) ContainsFrequencyPlan added in v1.0.8

func (u UniqueGatewayBands) ContainsFrequencyPlan(plan frequency_plan.BlockchainFrequencyPlan) bool

type UnknownGatewayLogger added in v1.0.4

type UnknownGatewayLogger interface {
	Record(localID lorawan.EUI64) error
	Recorded() ([]*RecordedUnknownGateway, error)
}

func NewUnknownGatewayLogger added in v1.0.4

func NewUnknownGatewayLogger(cfg *ForwarderGatewayRecordUnknownConfig) UnknownGatewayLogger

NewUnknownGatewayLogger returns a callback that can be used to record gateways their local id to a source defined in the given cfg. This is used to record unknown gateways that connected to the backend. These can be verified later and if required imported into the gateway store and registered on ThingsIX.

Jump to

Keyboard shortcuts

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