Documentation ¶
Overview ¶
Package model contains the data model for the Horde internals
Index ¶
- Constants
- Variables
- func FieldNames(v FieldMask) []string
- func ValidInviteCode(code string) bool
- type APN
- type Allocation
- type AuthMethod
- type CoAPMetaData
- type Collection
- type CollectionFirmwareMetadata
- type CollectionKey
- type DataMessage
- type Device
- type DeviceFirmwareMetadata
- type DeviceFirmwareState
- type DeviceKey
- type DeviceNetworkMetadata
- type DownstreamMessage
- type ErrorMessage
- type FieldMask
- type FieldMaskParameters
- type Firmware
- type FirmwareConfig
- type FirmwareKey
- type FirmwareManagementSetting
- type FirmwareUse
- type Invite
- type Member
- type MessageKey
- type MessageTransport
- type NAS
- type NASRanges
- type Output
- type OutputConfig
- type OutputKey
- type OutputLogEntry
- type OutputStatus
- type RoleID
- type TagMapData
- type Tags
- type Team
- type TeamKey
- type Token
- type UDPMetaData
- type User
- type UserKey
Constants ¶
const ( DisabledManagement = FirmwareManagementSetting(' ') CollectionManagement = FirmwareManagementSetting('c') DeviceManagement = FirmwareManagementSetting('d') )
The various firmware management settings.
const ( // UDPTransport is upstream UDP UDPTransport = MessageTransport(0) // CoAPTransport is uses CaAP and is sent unsolicited to the device, ie // it's not part of a GET request from the device. CoAPTransport = MessageTransport(1) // CoAPPullTransport is CoAP but the client pulls the message. This is // is useful if you want a device to retrieve the CoAP messages itself // f.e. when there's power saving modes running or you can't run a full // blown CoAP server on the device. CoAPPullTransport = MessageTransport(2) // UDPPullTransport sends the UDP message in response when the client has // sent an upstream message. This can be useful if the device is in some // kind of power save mode and you want to schedule a message for later // There is no guarantee *when* the message will be delivered UDPPullTransport = MessageTransport(3) UnknownTransport = MessageTransport(999) )
Note that iota might be tempting here but the transport is persisted so the order of the transports should not matter.
const ( Unknown = DeviceFirmwareState(' ') // Unknown state Current = DeviceFirmwareState('c') // The firmware is current. This is the default state Initializing = DeviceFirmwareState('i') // The firmware update has started Pending = DeviceFirmwareState('p') // A firmware update is pending Downloading = DeviceFirmwareState('d') // Firmware is downloading to the device Completed = DeviceFirmwareState('u') // Device has downloaded and written the firmware UpdateFailed = DeviceFirmwareState('f') // Update operation has failed TimedOut = DeviceFirmwareState('t') // Update timed out Reverted = DeviceFirmwareState('r') // Device was updated but did not report the updated version )
Firmware states for devices
const ( // IMSIMask is the mask bit for the IMSI field on devices (b0001) IMSIMask = FieldMask(1) << iota // IMEIMask is the mask bit for the IMEI field on devices (b0010) IMEIMask // LocationMask is the mask bit for locations on devices (b0100) LocationMask // MSISDNMask is the mask bit for the MSISDNs on devices (b1000). This isn't // currently in use but for political reasons (tm) it is included. MSISDNMask )
Variables ¶
var ( // AdminRole is the administrator role, ie with full access AdminRole = RoleID(1) // MemberRole is the member role, ie a member without administrative privileges MemberRole = RoleID(0) )
Functions ¶
func FieldNames ¶
FieldNames returns the bits that are set as an array of strings. The list contains human-readable names
func ValidInviteCode ¶
ValidInviteCode checks if the code is valid
Types ¶
type Allocation ¶
Allocation represents an IP allocation
type AuthMethod ¶
type AuthMethod int
AuthMethod is an enum for authentication methods
const ( // AuthNone is "no auth method" AuthNone AuthMethod = iota // AuthGitHub is for GitHub authentication AuthGitHub // AuthConnectID is for CONNECT ID authentication AuthConnectID // AuthInternal is internal users. These are created through the management // API and have no external authentication. These users have a single API // token and nothing else. AuthInternal // AuthToken is token authentication AuthToken )
func (AuthMethod) Login ¶
func (a AuthMethod) Login() bool
Login returns true if the user is authenticated via some sort of login, ie not via tokens or internal methods. Some API resources will need regular logins (like the token management bits, managing tokens via tokens introduces corner cases and potential security risks so we require a logged-in user to manage the tokens)
type CoAPMetaData ¶
CoAPMetaData holds metadata for messages received on the CoAP interface
type Collection ¶
type Collection struct { ID CollectionKey TeamID TeamKey FieldMask FieldMask Firmware CollectionFirmwareMetadata Tags }
Collection is a collection of devices. The name might be a bit generic but we have only *one* type of collection in the system -- the one with devices.
type CollectionFirmwareMetadata ¶
type CollectionFirmwareMetadata struct { CurrentFirmwareID FirmwareKey TargetFirmwareID FirmwareKey Management FirmwareManagementSetting }
CollectionFirmwareMetadata is the firmware settings for the collections. If the management is set to disabled or device the version fields will be ignored.
func NewCollectionFirmwareMetadata ¶
func NewCollectionFirmwareMetadata() CollectionFirmwareMetadata
NewCollectionFirmwareMetadata creates a new empty metadata setting
type CollectionKey ¶
type CollectionKey storageKey
CollectionKey is the identifer for Collection instances
func NewCollectionKeyFromString ¶
func NewCollectionKeyFromString(id string) (CollectionKey, error)
NewCollectionKeyFromString creates a new CollectionKey from a string
func (CollectionKey) String ¶
func (c CollectionKey) String() string
String returns the string representation of the key
type DataMessage ¶
type DataMessage struct { Device Device Received time.Time Payload []byte Transport MessageTransport UDP UDPMetaData CoAP CoAPMetaData }
DataMessage is the type for messages passed to and from devices. Final content is TBD.
func NewDataMessage ¶
func NewDataMessage(device Device, payload []byte, transport MessageTransport, udp UDPMetaData, coap CoAPMetaData) DataMessage
NewDataMessage creates a new DataMessage instance.
type Device ¶
type Device struct { ID DeviceKey IMSI int64 IMEI int64 CollectionID CollectionKey Network DeviceNetworkMetadata Firmware DeviceFirmwareMetadata Tags }
Device is the entity that represent actual NB-IoT devices.
type DeviceFirmwareMetadata ¶
type DeviceFirmwareMetadata struct { CurrentFirmwareID FirmwareKey // The current firmware version installed. 0 if it isn't set or is unknown TargetFirmwareID FirmwareKey // The desired version of the firmware for the device. It might be the same as the current version FirmwareVersion string // From the device information resource SerialNumber string // From the device information resource ModelNumber string // From the device information resource Manufacturer string // From the device information resource State DeviceFirmwareState StateMessage string }
DeviceFirmwareMetadata contains internal metadata about devices. The information is for internal housekeeping mostly and *might* be relevant for devices. The information is pulled from the LwM2M responses from the device.
type DeviceFirmwareState ¶
type DeviceFirmwareState rune
DeviceFirmwareState is the state for the firmware update cycle. If the device is in the TimedOut or Rollback state it won't be updated. The state is changed to "pending" whenever the target firmware id is set on the device
func (DeviceFirmwareState) IsError ¶
func (d DeviceFirmwareState) IsError() bool
IsError returns true if the firmware state represents an error
func (DeviceFirmwareState) String ¶
func (d DeviceFirmwareState) String() string
type DeviceKey ¶
type DeviceKey storageKey
DeviceKey is the identifier for Device instances
func NewDeviceKeyFromString ¶
NewDeviceKeyFromString creates a new DeviceKey from a string representation
type DeviceNetworkMetadata ¶
type DeviceNetworkMetadata struct { AllocatedIP string AllocatedAt time.Time CellID int64 ApnID int NasID int }
DeviceNetworkMetadata is the current state of the device.
type DownstreamMessage ¶
type DownstreamMessage struct { ID MessageKey // ID of message ApnID int // APN ID (may be invalid if the message is cached by the core service) NasID int // APN ID IMSI int64 // IMSI for destination device Transport MessageTransport // Transport to use Port int // Port number to use (UDP or CoAP) Path string // Path (CoAP) Payload []byte // Payload of message }
DownstreamMessage is a downstream message; ie a message that should be sent to devices.
type ErrorMessage ¶
ErrorMessage is error messages for end users. These are ideally a part of the entities package elsewhere since it *strictly* isn't a part of the model package but it is used in several other packages as well.
The error messages are presented as a JSON with field names and messages, ie a regular map.
type FieldMask ¶
type FieldMask uint
FieldMask is the field masking bit used to mask fields
type FieldMaskParameters ¶
type FieldMaskParameters struct { Forced string `param:"desc=Read-only field mask for device fields"` Default string `param:"desc=Default field mask for device fields;default=location"` }
FieldMaskParameters contains the system configuration for the field masks; system defaults and edit mask. The edit mask sets the allowed edits, in practice making the field mask read only for certain fields.
The EditMask field has bits set for all fields that must be masked, ie if set to 0xFFFF all fields will be masked and the API clients are unable to modfiy the mask
func (*FieldMaskParameters) DefaultFields ¶
func (f *FieldMaskParameters) DefaultFields() FieldMask
DefaultFields returns the default field mask
func (*FieldMaskParameters) ForcedFields ¶
func (f *FieldMaskParameters) ForcedFields() FieldMask
ForcedFields returns the field mask for forced fields
func (*FieldMaskParameters) Valid ¶
func (f *FieldMaskParameters) Valid() error
Valid validates the forced and default field masks. The default field mask must be equal or more restrictive than the forced field mask.
type Firmware ¶
type Firmware struct { ID FirmwareKey // Image ID Version string // Unique for collection Filename string // Original file name - for informational purposes only Length int // Size of image (in bytes) SHA256 string // SHA256 checksum of image. Computed when uploading. 64 hex characters (and 32 byte) Created time.Time // Time the image was created CollectionID CollectionKey Tags }
Firmware is the metadata for a firmware image. Most fields are immutable, except the TeamID and Tags.
type FirmwareConfig ¶
type FirmwareConfig struct { Management FirmwareManagementSetting CollectionCurrentVersion FirmwareKey CollectionTargetVersion FirmwareKey DeviceCurrentVersion FirmwareKey DeviceTargetVersion FirmwareKey }
FirmwareConfig is a meta-type for firmware config; the fields are gathered into one type for convenience.
func (*FirmwareConfig) CurrentVersion ¶
func (f *FirmwareConfig) CurrentVersion() FirmwareKey
CurrentVersion returns the currently running firmware version (or the one it should be running right now)
func (*FirmwareConfig) NeedsUpgrade ¶
func (f *FirmwareConfig) NeedsUpgrade() bool
NeedsUpgrade returns true if the firmware should be upgraded
func (*FirmwareConfig) TargetVersion ¶
func (f *FirmwareConfig) TargetVersion() FirmwareKey
TargetVersion runs the target firmware version
type FirmwareKey ¶
type FirmwareKey storageKey
FirmwareKey is the identifier for firmware images
func NewFirmwareKeyFromString ¶
func NewFirmwareKeyFromString(id string) (FirmwareKey, error)
NewFirmwareKeyFromString converts a string into a FirmwareKey
func (FirmwareKey) String ¶
func (f FirmwareKey) String() string
type FirmwareManagementSetting ¶
type FirmwareManagementSetting rune
FirmwareManagementSetting is the firmware management setting for the collection
type FirmwareUse ¶
type FirmwareUse struct { FirmwareID FirmwareKey Current []DeviceKey Targeted []DeviceKey }
FirmwareUse shows the firmware images in use for a collection
type MessageKey ¶
type MessageKey storageKey
MessageKey is an identifier for messages
func NewMessageKeyFromString ¶
func NewMessageKeyFromString(id string) (MessageKey, error)
NewMessageKeyFromString creates a new MessageKey from a string
func (MessageKey) String ¶
func (m MessageKey) String() string
String returns the string representation of the message ID
type MessageTransport ¶
type MessageTransport int
MessageTransport is the transport for (upstream) messages
func MessageTransportFromString ¶
func MessageTransportFromString(s string) MessageTransport
MessageTransportFromString returns the MessageTransport type that matches. If nothing matches the unknown transport type is returned
func (MessageTransport) String ¶
func (m MessageTransport) String() string
String returns the string representation of the transport
type NAS ¶
type NAS struct { ID int Identifier string CIDR string ApnID int // contains filtered or unexported fields }
NAS represents a NAS with a range.
type NASRanges ¶
NASRanges is a helper struct to hold both APN ID and a collection of NAS IDs. This represents a *single* APN and not all available APNs TODO(stalehd): Remove this when ingres listeners are completed.
func NewNASRanges ¶
NewNASRanges creates a new NASRanges instance
type Output ¶
type Output struct { ID OutputKey Type string Config OutputConfig CollectionID CollectionKey Enabled bool CollectionFieldMask FieldMask Tags }
Output is data streams from outputs. Note that the CollectionFieldMask is not a field on the output table but for simplicity's sake this is retrieved with the rest of the output object.
type OutputConfig ¶
type OutputConfig map[string]interface{}
OutputConfig is a map of configuration values
func NewOutputConfig ¶
func NewOutputConfig() OutputConfig
NewOutputConfig creates a new output configuration
func (OutputConfig) HasParameterOfType ¶
HasParameterOfType checks if the parameter exists and if type type is correct
func (*OutputConfig) Scan ¶
func (o *OutputConfig) Scan(src interface{}) error
Scan implements the sql.Scanner interface (to read from db fields). This makes it possible to write to and from the "tags" field in sql drivers
type OutputKey ¶
type OutputKey storageKey
OutputKey is the identifier for outputs
func NewOutputKeyFromString ¶
NewOutputKeyFromString creates a new OutputKey from a string representation
type OutputLogEntry ¶
OutputLogEntry is the log entries received from the outputs. Each output has a circular buffer with the 10 latest messages from the output. If there's multiple log messages with the same message repeated it will just have the Repeated field increased. Log entries are used by the end used to diagnose the output so the error messages should make sense for end users.
type OutputStatus ¶
OutputStatus is used to report the internal state of the forwarder.
type RoleID ¶
type RoleID uint8
RoleID is a single role.
func NewRoleIDFromString ¶
NewRoleIDFromString converts a string into a role ID
type TagMapData ¶
TagMapData is the tag types
func (*TagMapData) Scan ¶
func (t *TagMapData) Scan(src interface{}) error
Scan implements the sql.Scanner interface (to read from db fields). This makes it possible to write to and from the "tags" field in sql drivers
type Tags ¶
type Tags struct {
TagMap TagMapData
}
Tags are user-selectable attributes for entities.
func (*Tags) GetTag ¶
GetTag returns the value of the property. If it doesnt't exist it will return a blank string
func (*Tags) IsValidTag ¶
IsValidTag checks if the name/value combination is valid
type Team ¶
The Team type is a group of users
func (*Team) GetMember ¶
GetMember returns the member with the specified user ID. An empty member entity is returned if the member doesn't exist.
func (*Team) IsMember ¶
IsMember returns true if the specified user ID is a member of the team. Not thread safe.
func (*Team) RemoveMember ¶
RemoveMember removes the user from the member list
func (*Team) UpdateMember ¶
UpdateMember updates a member's role if the user exists
type TeamKey ¶
type TeamKey storageKey
TeamKey is the ID for the team type
func NewTeamKeyFromString ¶
NewTeamKeyFromString parses a key as a string
type Token ¶
Token is access tokens for the REST API
func (*Token) GenerateToken ¶
GenerateToken generates a new token. Note that this will overwrite the existing token
type UDPMetaData ¶
UDPMetaData holds metadata for messages received via UDP
type User ¶
type User struct { ID UserKey // User ID Email string // Always set for GH users Phone string // Not used by GH Name string // Name of user ExternalID string // Identifier for CONNECT ID users Deleted bool // Deleted flag. Not used ATM VerifiedEmail bool // Always true for GH users, possibly false for CONNECT ID users VerifiedPhone bool // Always false for GH users AvatarURL string // Avatar URL (GH only; TD does not support avatars) PrivateTeamID TeamKey // The private team for the user AuthType AuthMethod }
User is the struct representing system users.