notelib

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2025 License: AGPL-3.0, AGPL-3.0 Imports: 42 Imported by: 0

Documentation

Overview

Package notelib cert.go contains certificates

Package notelib config.go is where package-wide constants and vars are defined

Package notelib debug.go contains things that assist in debugging

Package notelib discover.go is the notehub discovery handling support

Package notelib err.go contains things that assist in error handling

Package notelib file.go is a 'storage driver' for a standard hierarchical file system

Package notelib fileio.go is the lowest level I/O driver underlying the file transport

Package notelib hubreq.go is the service-side complement to the Notehub client-side package

Package notelib notefile.go handles management and sync of collections of individual notes

Package notelib notebox.go deals with the handling of the sync'ed container of a set of related notefiles

Package notelib notefile.go handles management and sync of collections of individual notes

Package notelib notehub-defs contains device-hub RPC protocol definitions

Package notelib notelib.go has certain internal definitions, placed here so that they parallel the clang version.

Package notelib storage.go is the class definition for storage drivers

Package notelib wire.go handles all conversions between the RPC's req/rsp structure and compressed on-wire formats

Index

Constants

View Source
const (
	BulkNoteFormatOriginal = 1 // Original format
	BulkNoteFormatFlex     = 2 // Different 'where', 'string', and 'payload' handling
	BulkNoteFormatFlexNano = 3 // Same as Flex but omits Where/When
)

Bulk note formats

View Source
const ChaCha20Poly1305AuthTagLen = 16
View Source
const ChaCha20Poly1305AuthTagPlaintext = "notecard <3 notehub"
View Source
const ChaCha20Poly1305IvLen = 12
View Source
const ChaCha20Poly1305KeyLen = 32
View Source
const CidNone = byte(0) // Zero bytes

Type of connection ID present in the packet

View Source
const CidRandom = byte(1) // CidRandomLen bytes
View Source
const CidRandomLen = 6
View Source
const ErrInvalidNaNValue = float16Error("float16: invalid NaN value, expected IEEE 754 NaN")

ErrInvalidNaNValue indicates a NaN was not received.

View Source
const HTTPUserAgent = "BluesNotehub/1.0"

HTTPUserAgent is the HTTP user agent for all our uses of HTTP

View Source
const InvalidTime = int64(0xffffffff)

Define an invalid time so that we force a history to be added with a 0 time. (see packet.go and elsewhere)

View Source
const LogPeriodSuppressSecs = 2

Default timewarn period used for suppressing LogInfo entirely

View Source
const MportChangesDownlink = 250
View Source
const MportEchoDownlink = 253
View Source
const MportInvalid = 0

Message ports for packet handling

View Source
const MportMoreDownlink = 252
View Source
const MportMultiportUplink = 254 // Enum of <port><datalen><data>
View Source
const MportMultiportUplinkDownlink = 255 // Same but with a guaranteed response formatted the same way
View Source
const MportSysNotefileEnv = (MportSysNotefileFirst + 0)
View Source
const MportSysNotefileFirst = 101
View Source
const MportSysNotefileLast = 125
View Source
const MportTimeDownlink = 251
View Source
const MportUserNotefileFirst = 1
View Source
const MportUserNotefileLast = 100
View Source
const MportUserSysNotefileFirst = 126
View Source
const MportUserSysNotefileLast = 150
View Source
const NotecardPowerCharging = uint32(0x00000001)
View Source
const NotecardPowerPrimary = uint32(0x00000004)
View Source
const NotecardPowerUsb = uint32(0x00000002)
View Source
const PV1 = "pv1"

After trying AES GCM and struggling with block size and tag size constraints, and after then consulting with the folks at WolfSSL, we arrived at using the ChaCha20 stream cipher (thus eliminating block constraints) along with the Poly1305 MAC for integrity and authentication.

View Source
const PV1EncrAlg = "chacha20-poly1305"
View Source
const PacketFlagCompressed = 0x40
View Source
const PacketFlagDownlinksPending = 0x20
View Source
const PacketFlagEncrypted = 0x80
View Source
const PacketFlagSpare1 = 0x10
View Source
const PacketTypeMask = 0x0f

Packet type is split - a nibble of flags and a nibble of Connection ID type

View Source
const ReservedIDDelimiter = ","

ReservedIDDelimiter is used to separate lists of noteIDs, notefileIDs, endpointIDs, thus is invalid in names

View Source
const TemplateFlagClearAfterSync = 0x00000001
View Source
const UdpCidType = CidRandom
View Source
const UdpMaxMtu = 548 // Minimum internet datagram is 576, IPv4 header is 20, UDP header is 8
View Source
const UdpMinMtu = 256 // Below this, we really wouldn't have enough room for any user data to speak of

Default MTU

View Source
const UdpMtu = UdpMinMtu
View Source
const UdpPs = "udp:"

Supported packet service types. Except for UDP, where there is no ID, The appropriate ID for that service type is appended. For example, it might be the IMEI, IMSI, ICCID, or vendor-proprietary ID of the unit

Variables

View Source
var (
	AutoCheckpointSeconds = 5 * 60
	AutoPurgeSeconds      = 120 * 60
	CheckpointSilently    = true
)

Checkpoint timing. Note that we only purge on a longer basis than writes because as of 2024-08-29 I changed the session close code to purge closed notefiles from the in-memory cache whenever the session closes. The only remaining function of the AutoPurge is to remove closed notefiles from memory for continuous sessions. Because this will cause active notefiles to be immediately re-opened, we don't want to do it too often.

View Source
var (
	DebugEvent = true
)

Debugging details

View Source
var ErrCorrupt = errors.New("smazz: corrupt input")

ErrCorrupt reports that the input is invalid.

View Source
var File_notehub_proto protoreflect.FileDescriptor
View Source
var SmazzCodeDefault = [254]string{}/* 254 elements not displayed */

Codebook for smaz compatibility

View Source
var SmazzCodeTemplate = [254]string{}/* 253 elements not displayed */

Codebook optimized for JSON templates

Functions

func Checkpoint added in v0.1.13

func Checkpoint(ctx context.Context) (err error)

Checkpoint all noteboxes and purge noteboxes that have been sitting unused for the autopurge interval

func CheckpointNoteboxIfNeeded added in v1.7.0

func CheckpointNoteboxIfNeeded(ctx context.Context, localEndpointID string, boxLocalStorage string) error

CheckpointNoteboxIfNeeded checkpoints a notebox if it's open, purging closed files from the cache

func CreateNotebox

func CreateNotebox(ctx context.Context, endpointID string, boxStorage string) (err error)

CreateNotebox creates a notebox on this endpoint

func DebugSet

func DebugSet(which string, value string)

DebugSet sets the debug variable

func Delete

func Delete(ctx context.Context, boxStorage string) (err error)

Delete deletes a closed Notebox, and releases its storage.

func ErrorContains

func ErrorContains(err error, errKeyword string) bool

ErrorContains tests to see if an error contains an error keyword that we might expect

func ErrorResponse

func ErrorResponse(err error) (response []byte)

ErrorResponse creates a simple JSON response given an error

func ErrorString

func ErrorString(err error) string

ErrorString safely returns a string from any error, returning "" for nil

func FileCleanName added in v0.1.5

func FileCleanName(filename string) string

FileCleanName generates a clean filename with correct extension from a filename input

func FileDefaultStorageObject

func FileDefaultStorageObject() string

FileDefaultStorageObject gives a deterministic storage object name from two components

func FileSetHandler

func FileSetHandler(newfio *Fileio)

FileSetHandler sets an alternate file I/O package

func FileSetStorageLocation

func FileSetStorageLocation(root string)

FileSetStorageLocation sets the root location for storage

func FileStorageObject

func FileStorageObject(containerName string) string

FileStorageObject gives a deterministic storage object name from two components

func FixCorruptJSON added in v1.7.3

func FixCorruptJSON(corruptData string) (string, error)

FixCorruptJSON attempts to fix single-character corruptions in JSON data It tries replacing each character with valid JSON structure characters and returns the first successful parse

func FixCorruptJSONVerbose added in v1.7.3

func FixCorruptJSONVerbose(corruptData string) (fixed string, changeDescription string, err error)

FixCorruptJSONVerbose is like FixCorruptJSON but returns details about what was fixed

func GenerateEventUid added in v1.7.3

func GenerateEventUid(event *note.Event) string

Generate a UUID for an event in a way that will allow detection of duplicates of "user data"

func GetNotecardSecureElementRootCertificateAsPEM

func GetNotecardSecureElementRootCertificateAsPEM() (cert []byte)

GetNotecardSecureElementRootCertificateAsPEM is the ST Microelectronics root certificate used to generate the certificate embedded in every Notecard's STSAFE-A100 secure element at point of chip manufacture.

func HubCheckpointRequest added in v1.7.0

func HubCheckpointRequest() (message []byte, err error)

Make a checkpoint request

func HubDiscover

func HubDiscover(deviceUID string, deviceSN string, productUID string, appUID string) (hubEndpointID string, retAppUID string, deviceStorageObject string, err error)

HubDiscover ensures that we've read the local server's discover info, and return the Hub's Endpoint ID

func HubDiscoverSessionTicket added in v1.7.3

func HubDiscoverSessionTicket(deviceUID string, deviceSN string, productUID string, appUID string) (hubSessionTicket string, err error)

HubDiscoverSessionTicket gets the session ticket for a session

func HubErrorResponse added in v0.2.4

func HubErrorResponse(ctx context.Context, session *HubSession, errorMessage string) (result []byte)

HubErrorResponse creates an error response message to be sent to the client device, and terminates the session so that no further requests can be processed.

func HubRequest

func HubRequest(ctx context.Context, content []byte, event EventFunc, session *HubSession) (reqtype string, result []byte, suppress bool, err error)

HubRequest creates a request message from a map of arguments, given an optional context parameter for fields that are shared across requests that happen within a single session. The return arguments should be interpreted as follows: - if err is returned, do not return a reply to the remote requestor - if err is nil, always send result back to request

func HubSetDeviceNotifications

func HubSetDeviceNotifications(fn GetNotificationFunc)

HubSetDeviceNotifications sets the hub notification

func HubSetDiscover

func HubSetDiscover(fn DiscoverFunc)

HubSetDiscover sets the global discovery function

func HubSetReadFile

func HubSetReadFile(fn ReadFileFunc)

HubSetReadFile sets the read file func

func HubSetSignal

func HubSetSignal(fn SignalFunc)

HubSetSignal sets the web request function

func HubSetUpdateEnvironment added in v1.7.0

func HubSetUpdateEnvironment(ctx context.Context, fn NoteboxUpdateEnvFunc)

HubSetUpdateEnvironment sets the global notebox function to update env vars

func HubSetWebRequest

func HubSetWebRequest(fn WebRequestFunc)

HubSetWebRequest sets the web request function

func InitDeviceSession added in v1.7.3

func InitDeviceSession(sess *note.DeviceSession, handlerAddr string, sessType SessionType) time.Time

func InitLogging added in v1.7.0

func InitLogging(
	debugFunc LogFunc,
	infoFunc LogFunc,
	warnFunc LogFunc,
	errorFunc LogFunc,
	timerBeginFn LogTimerBeginFunc,
	timerEndFn LogTimerEndFunc)

func LogInfoBumpTrace added in v1.7.3

func LogInfoBumpTrace(prev *time.Time) (duration time.Duration)

LogInfoBumpTrace bumps a trace interval

func LogInfoPeriodReset added in v1.7.3

func LogInfoPeriodReset(period *LogPeriod)

LogInfoPeriodReset ensures that the very next period log does a trace

func LogInfoPeriodically added in v1.7.3

func LogInfoPeriodically(ctx context.Context, period *LogPeriod, msg string, v ...interface{})

LogInfoPeriodically writes an unstructured log message with the INFO level but only periodically

func Merge

func Merge(localNote *note.Note, incomingNote *note.Note) note.Note

Merge the contents of two Notes

func NameFromUUID added in v1.7.3

func NameFromUUID(uid string) (name string)

NewUNameFromUID returns a name from a UUID

func NewUUID added in v1.7.3

func NewUUID() (randstr string)

NewUUID returns a new UUID

func NoteboxNotefileDescByPort added in v1.7.3

func NoteboxNotefileDescByPort(allInfo []note.NotefileDesc, port uint16) (info note.NotefileDesc, present bool)

NoteboxNotefileDescByPort gets info about all notefiles in a notebox. Note that for determinism in the case where someone accidentally creates two notefiles with the same port, this method relies upon the fact that NoteboxNotefileDesc() returns the notefiles in alphabetized sort order. (The notecard DOES try to keep devs from assigning the same port to multiple notefiles, however this can happen by: a) add notefiles "a.qi port 1" b) sync c) factory reset notecard and quickly do a hub.set mode:off to keep it from syncing d) add notefiles "b.qi port 1" e) set hub.set mode:periodic and sync At the end of this, because a.qi comes back from the notehub, and b.qi goes up to the notehub, there are two notefiles with the same port number.

func NotefileAttributesFromID

func NotefileAttributesFromID(notefileID string) (isQueue bool, syncToHub bool, syncFromHub bool, secure bool, reserved bool, err error)

NotefileAttributesFromID extracts attributes implied by the notefileID

func NotefileIDIsReserved added in v0.2.7

func NotefileIDIsReserved(notefileID string) bool

NotefileIDIsReserved returns true if the notefileID is reserved

func NotefileIDIsReservedWithExceptions added in v0.4.2

func NotefileIDIsReservedWithExceptions(notefileID string) bool

NotefileIDIsReservedWithExceptions returns true if the notefileID is reserved

func OLC32ToOLC64 added in v1.7.3

func OLC32ToOLC64(x int64) int64

func OLC40ToOLC64 added in v1.7.3

func OLC40ToOLC64(x int64) int64

func OLC48ToOLC64 added in v1.7.3

func OLC48ToOLC64(x int64) int64

func OLC56ToOLC64 added in v1.7.3

func OLC56ToOLC64(x int64) int64

Simple expansion functions - just shift back

func OLC64ToOLC32 added in v1.7.3

func OLC64ToOLC32(x int64) int64

func OLC64ToOLC40 added in v1.7.3

func OLC64ToOLC40(x int64) int64

func OLC64ToOLC48 added in v1.7.3

func OLC64ToOLC48(x int64) int64

func OLC64ToOLC56 added in v1.7.3

func OLC64ToOLC56(x int64) int64

Simple truncation functions - just remove bytes

func OLCFromINT64

func OLCFromINT64(code int64) (olc string)

OLCFromINT64 converts a 64-bit OLC code into a string (assumes 8 bytes)

func OLCFromINT64Bytes added in v1.7.3

func OLCFromINT64Bytes(code int64, byteCount int) (olc string)

OLCFromINT64Bytes converts a truncated OLC code into a valid OLC string byteCount indicates how many bytes were actually stored (4, 5, 6, 7, or 8)

func OLCToINT64

func OLCToINT64(olc string) (result int64)

OLCToINT64 converts an OLC string into a 64-bit code

func PacketHeaderFromWire added in v1.7.1

func PacketHeaderFromWire(wire []byte) (cid []byte, packetFlags byte, dataOffset int, err error)

packetHeaderFromWire extracts the connection ID from the wire format

func PayloadToString added in v1.7.3

func PayloadToString(payload []byte) string

Convert payload to a string

func Purge added in v0.3.6

func Purge(ctx context.Context) error

Purge checkpoints all noteboxes and force a purge of notefiles

func SetTLSSupport added in v1.7.1

func SetTLSSupport(enabled bool)

SetTLSSupport tells the discover module that we do support TLS

func TLSSupport

func TLSSupport() bool

TLSSupport tells the discover module that we do support TLS

func TimeZoneNameToNumber added in v0.2.3

func TimeZoneNameToNumber(name string) int

TimeZoneNameToNumber converts a timezone number to a name

func TimeZoneNumberToCountry added in v0.2.3

func TimeZoneNumberToCountry(num int) string

TimeZoneNumberToCountry retrieves the country from the name

func TimeZoneNumberToName added in v0.2.3

func TimeZoneNumberToName(num int) string

TimeZoneNumberToName converts a timezone name to a number

func TruncateErrorString added in v1.7.3

func TruncateErrorString(errstr string, maxchars int) string

Truncate an error string, moving errors to the front if it's too long

func TryFixWithContext added in v1.7.3

func TryFixWithContext(corruptData string) (string, error)

TryFixWithContext attempts to fix JSON using context clues This is a more intelligent version that looks for patterns

func WireBarsFromSession added in v0.2.5

func WireBarsFromSession(session *note.DeviceSession) (rat string, bars uint32)

WireBarsFromSession extracts device's perception of the number of bars of signal from a session

func WireExtractSessionContext

func WireExtractSessionContext(ctx context.Context, wire []byte, session *HubSession) (suppressResponse bool, err error)

WireExtractSessionContext extracts session context from the wire message

func WireExtractSessionTowerLocationContext added in v1.7.4

func WireExtractSessionTowerLocationContext(ctx context.Context, wire []byte, session *HubSession) (towerChanged bool, err error)

WireExtractSessionTowerLocationContext extracts cell tower location fields from a wire-format request. This function can be called on any transaction to update tower location context. It returns towerChanged=true if the cell tower (mcc/mnc/lac/cellid) has changed. If the CellID field is not present in the request, the session structure is not modified.

func WireReadRequest

func WireReadRequest(ctx context.Context, conn net.Conn, waitIndefinitely bool) (bytesRead uint32, request []byte, err error)

WireReadRequest reads a message from the specified reader

Types

type BulkBody

type BulkBody struct {
	// The format of the encoded binary note
	NoteFormat uint32 `json:"format,omitempty"`
	// The JSON of the Note template for this notefile.	 Note that we keep this in text form because
	// the order of the fields is relevant to the binary encoding derived from the JSON, and the various
	// encoders/decoders in the data processing pipeline won't retain field order.
	NoteTemplate           string `json:"template_body,omitempty"`
	NoteTemplatePayloadLen int    `json:"template_payload,omitempty"`
}

BulkBody is the bulk data note body

type BulkTemplateContext

type BulkTemplateContext struct {
	NoteFormat uint32
	Template   string
	Bin        []byte
	BinLen     int
	// Used while parsing a record
	BinOffset   int
	BinUnderrun bool
	// Fields only valid for BulkNoteFormatOriginal
	ORIGTemplatePayloadLen    int
	ORIGTemplatePayloadOffset int
	ORIGTemplateFlagsOffset   int

	MaxArrayLength uint16
	// contains filtered or unexported fields
}

BulkTemplateContext is the context for the bulk template

func BulkDecodeTemplate

func BulkDecodeTemplate(templateBodyJSON []byte, compressedPayload []byte) (tmplContext BulkTemplateContext, err error)

BulkDecodeTemplate sets up a context for decoding by taking the template and a binary buffer to be decoded

func BulkEncodeTemplate added in v1.7.0

func BulkEncodeTemplate(templateBodyJSON []byte) (context BulkTemplateContext, err error)

BulkEncodeTemplate sets up a context for encoding by taking the template and preparing a binary output buffer

func (*BulkTemplateContext) BulkDecodeNextEntry added in v1.7.0

func (tmplContext *BulkTemplateContext) BulkDecodeNextEntry() (body map[string]interface{}, payload []byte, when int64, wherewhen int64, olc string, noteID string, success bool)

BulkDecodeNextEntry extract a JSON object from the binary. Note that both 'when' and 'wherewhen' returned in standard unix epoch seconds (not in nanoseconds)

func (*BulkTemplateContext) BulkEncodeNextEntry added in v1.7.0

func (tmplContext *BulkTemplateContext) BulkEncodeNextEntry(body map[string]interface{}, payload []byte, when int64, wherewhen int64, currentLocOLC string, noteID string, noOmitEmpty bool) (output []byte, err error)

BulkEncodeNextEntry encodes a JSON object using the template in the supplied contxt

BULK_NOTEFORMAT_FLEX and BULK_NOTEFORMAT_NANOFLEX

uint8 header containing BULKFLAGS
uint16 header containing variableLengthOffset
If BULKFLAGS is not NANO, int64 CombinedWhen (the merger of 'when' and 'whereWhen')
If BULKFLAGS is not NANO, int64 WhereOLC64 (positive if validly parsed, else negative if parsing error)
N*[binary records as defined by template, with counted text strings encoded as uint16:len uint8[len] ]
(beginning of variable-length data)
If BULKFLAGS indicates it is present, [payloadLen] [payload]
If BULKFLAGS indicates it is present, [flagsLen] [flags]
If BULKFLAGS indicates it is present, [olclen] [olc]

type DiscoverFunc

type DiscoverFunc func(edgeUID string, deviceSN string, productUID string, appUID string, needHandlerInfo bool, hostname string, packetHandlerVersion string) (info DiscoverInfo, err error)

DiscoverFunc is the func to retrieve discovery info for this server

type DiscoverInfo

type DiscoverInfo struct {
	HubEndpointID                 string
	HubSessionHandler             string
	HubSessionTicket              string
	HubPacketHandler              string
	HubDeviceStorageObject        string
	HubDeviceAppUID               string
	HubTimeNs                     int64
	HubSessionTicketExpiresTimeNs int64
	HubCert                       []byte
}

DiscoverInfo is the information returned by DiscoverFunc

type EventFunc

type EventFunc func(ctx context.Context, sess *HubSession, local bool, data *note.Event) (err error)

EventFunc is the func to get called whenever there is a note add/update/delete

type Fileio

type Fileio struct {
	Exists    FileioExistsFunc
	Create    FileioCreateFunc
	Delete    FileioDeleteFunc
	ReadJSON  FileioReadJSONFunc
	WriteJSON FileioWriteJSONFunc
}

Fileio defines a set of functions for alternative file I/O

type FileioCreateFunc

type FileioCreateFunc func(ctx context.Context, path string) (err error)

FileioCreateFunc creates a file

type FileioDeleteFunc

type FileioDeleteFunc func(ctx context.Context, path string) (err error)

FileioDeleteFunc deletes a file

type FileioExistsFunc

type FileioExistsFunc func(ctx context.Context, path string) (exists bool, err error)

FileioExistsFunc checks for file existence

type FileioReadJSONFunc

type FileioReadJSONFunc func(ctx context.Context, path string) (data []byte, err error)

FileioReadJSONFunc reads a JSON file

type FileioWriteJSONFunc

type FileioWriteJSONFunc func(ctx context.Context, path string, data []byte) (err error)

FileioWriteJSONFunc writes a JSON file

type Float16 added in v0.3.5

type Float16 uint16

Float16 represents IEEE 754 half-precision floating-point numbers (binary16).

func FromNaN32ps added in v0.3.5

func FromNaN32ps(nan float32) (Float16, error)

FromNaN32ps converts nan to IEEE binary16 NaN while preserving both signaling and payload. Unlike Fromfloat32(), which can only return qNaN because it sets quiet bit = 1, this can return both sNaN and qNaN. If the result is infinity (sNaN with empty payload), then the lowest bit of payload is set to make the result a NaN. Returns ErrInvalidNaNValue and 0x7c01 (sNaN) if nan isn't IEEE 754 NaN. This function was kept simple to be able to inline.

func Frombits added in v0.3.5

func Frombits(u16 uint16) Float16

Frombits returns the float16 number corresponding to the IEEE 754 binary16 representation u16, with the sign bit of u16 and the result in the same bit position. Frombits(Bits(x)) == x.

func Fromfloat32 added in v0.3.5

func Fromfloat32(f32 float32) Float16

Fromfloat32 returns a Float16 value converted from f32. Conversion uses IEEE default rounding (nearest int, with ties to even).

func Inf added in v0.3.5

func Inf(sign int) Float16

Inf returns a Float16 with an infinity value with the specified sign. A sign >= returns positive infinity. A sign < 0 returns negative infinity.

func NaN added in v0.3.5

func NaN() Float16

NaN returns a Float16 of IEEE 754 binary16 not-a-number (NaN). Returned NaN value 0x7e01 has all exponent bits = 1 with the first and last bits = 1 in the significand. This is consistent with Go's 64-bit math.NaN(). Canonical CBOR in RFC 7049 uses 0x7e00.

func (Float16) Bits added in v0.3.5

func (f Float16) Bits() uint16

Bits returns the IEEE 754 binary16 representation of f, with the sign bit of f and the result in the same bit position. Bits(Frombits(x)) == x.

func (Float16) Float32 added in v0.3.5

func (f Float16) Float32() float32

Float32 returns a float32 converted from f (Float16). This is a lossless conversion.

func (Float16) IsFinite added in v0.3.5

func (f Float16) IsFinite() bool

IsFinite returns true if f is neither infinite nor NaN.

func (Float16) IsInf added in v0.3.5

func (f Float16) IsInf(sign int) bool

IsInf reports whether f is an infinity (inf). A sign > 0 reports whether f is positive inf. A sign < 0 reports whether f is negative inf. A sign == 0 reports whether f is either inf.

func (Float16) IsNaN added in v0.3.5

func (f Float16) IsNaN() bool

IsNaN reports whether f is an IEEE 754 binary16 “not-a-number” value.

func (Float16) IsNormal added in v0.3.5

func (f Float16) IsNormal() bool

IsNormal returns true if f is neither zero, infinite, subnormal, or NaN.

func (Float16) IsQuietNaN added in v0.3.5

func (f Float16) IsQuietNaN() bool

IsQuietNaN reports whether f is a quiet (non-signaling) IEEE 754 binary16 “not-a-number” value.

func (Float16) Signbit added in v0.3.5

func (f Float16) Signbit() bool

Signbit reports whether f is negative or negative zero.

func (Float16) String added in v0.3.5

func (f Float16) String() string

String satisfies the fmt.Stringer interface.

type GetNotificationFunc

type GetNotificationFunc func(ctx context.Context, deviceEndpointID string, session *HubSession, eventFn EventFunc) (notifications []string)

GetNotificationFunc retrieves hub notifications to be sent to client

type HubSession added in v1.7.1

type HubSession struct {
	// These is all the fields sent from the notecard and decoded in wire.go
	Discovery          bool
	Notification       bool
	DeviceSKU          string
	DeviceOrderingCode string
	DeviceFirmware     int64
	DevicePIN          string
	DeviceEndpointID   string
	HubEndpointID      string
	HubSessionTicket   string
	FactoryResetID     string
	Session            note.DeviceSession

	// Information about the current session
	SessionStart time.Time
	AppUID       string
	Active       bool
	Terminated   bool
	Transactions int

	// Used for hubreq.go to retain inter-transaction state
	Notefiles         []string
	NotefilesUpdated  bool
	PendingWebPayload []byte
	DeviceMonitorID   int64
	BinTemplateCrc16  uint16
	BinTemplateJSON   []byte

	// For websocket I/O
	SocketTransmit   func(ctx context.Context, session *HubSession, data []byte) error
	SocketQuit       chan struct{}
	SocketClose      func()
	SocketUsageBytes uint64
	SocketUsageTime  int64
	SocketActiveTime int64

	// This field is used for any hub implementation to attach
	// data specific to that implementation
	Hub interface{}
}

func NewHubSession added in v1.7.1

func NewHubSession(handlerAddr string, secure bool) HubSession

func (HubSession) LogDebug added in v1.7.1

func (session HubSession) LogDebug(ctx context.Context, format string, args ...interface{})

func (HubSession) LogError added in v1.7.1

func (session HubSession) LogError(ctx context.Context, format string, args ...interface{})

func (HubSession) LogInfo added in v1.7.1

func (session HubSession) LogInfo(ctx context.Context, format string, args ...interface{})

func (HubSession) LogWarn added in v1.7.1

func (session HubSession) LogWarn(ctx context.Context, format string, args ...interface{})

type LogFunc added in v1.7.1

type LogFunc func(ctx context.Context, msg string, v ...interface{})

type LogPeriod added in v1.7.3

type LogPeriod struct {
	LastLog    time.Time
	PeriodSecs int
}

PeriodicInfo is a struct that enables information to be displayed only periodically, for 'sampled' tracing purposes, rather than on a continuous basis

type LogTimerBeginFunc added in v1.7.3

type LogTimerBeginFunc func(ctx context.Context, key string) string

type LogTimerEndFunc added in v1.7.3

type LogTimerEndFunc func(ctx context.Context, key string)

type Node added in v1.7.0

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

A Node represents a logical vertex in the trie structure.

func (*Node) Terminal added in v1.7.0

func (n *Node) Terminal() bool

Terminal indicates whether n is terminal in the trie (that is, whether the path from the root to n represents an element in the set). For instance, if the root node is terminal, then []byte{} is in the trie.

func (*Node) Val added in v1.7.0

func (n *Node) Val() int

Val gives the value associated with this node. It panics if n is not terminal.

func (*Node) Walk added in v1.7.0

func (n *Node) Walk(c byte) *Node

Walk returns the node reached along edge c, if one exists. If node doesn't exist we return nil

type Notebox

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

Notebox is the in-memory data structure for an open notebox

func OpenEndpointNotebox

func OpenEndpointNotebox(ctx context.Context, localEndpointID string, boxLocalStorage string, create bool) (box *Notebox, err error)

OpenEndpointNotebox opens - creating if necessary - a notebox in File storage for an endpoint

func OpenNotebox

func OpenNotebox(ctx context.Context, localEndpointID string, boxLocalStorage string) (notebox *Notebox, err error)

OpenNotebox opens a local notebox into memory.

func (*Notebox) AddNote

func (box *Notebox) AddNote(ctx context.Context, ei *NotefileEventInfo, endpointID string, notefileID string, noteID string, note note.Note) (err error)

AddNote adds a new note to a notefile, which is a VERY common operation

func (*Notebox) AddNoteWithHistory added in v1.7.1

func (box *Notebox) AddNoteWithHistory(ctx context.Context, ei *NotefileEventInfo, endpointID string, notefileID string, noteID string, note note.Note) (err error)

AddNoteWithHistory adds a new note to a notefile, with history supplied

func (*Notebox) AddNotefile

func (box *Notebox) AddNotefile(ctx context.Context, notefileID string, notefileInfo *note.NotefileInfo) error

AddNotefile adds a new notefile to the notebox, and return "nil" if it already exists

func (*Notebox) Checkpoint added in v1.7.0

func (box *Notebox) Checkpoint(ctx context.Context) (err error)

Checkpoint a notebox

func (*Notebox) CheckpointNotefile

func (box *Notebox) CheckpointNotefile(ctx context.Context, notefileID string) (err error)

CheckpointNotefile checkpoints an open Notefile to storage

func (*Notebox) CheckpointPurge added in v1.7.3

func (box *Notebox) CheckpointPurge(ctx context.Context) (err error)

Checkpoint a notebox and purge closed/cached files from memory

func (*Notebox) ClearAllTrackers

func (box *Notebox) ClearAllTrackers(ctx context.Context, endpointID string)

ClearAllTrackers deletes all trackers for this endpoint in order to force a resync of all files

func (*Notebox) Close

func (box *Notebox) Close(ctx context.Context) (err error)

Close releases a notebox, but leaves it in-memory with a 0 refcount for low-overhead re-open

func (*Notebox) ConvertToJSON

func (box *Notebox) ConvertToJSON(fIndent bool) (output []byte, err error)

ConvertToJSON serializes/marshals the in-memory Notebox into a JSON buffer

func (*Notebox) CreateNotefile

func (box *Notebox) CreateNotefile(isQueue bool) *Notefile

CreateNotefile creates a new Notefile in-memory, which will ultimately be added to this Notebox

func (*Notebox) DeleteNote

func (box *Notebox) DeleteNote(ctx context.Context, ei *NotefileEventInfo, endpointID string, notefileID string, noteID string) (err error)

DeleteNote deletes an existing note from notefile

func (*Notebox) DeleteNotefile

func (box *Notebox) DeleteNotefile(ctx context.Context, notefileID string) (err error)

DeleteNotefile deletes a closed Notefile, and releases its storage.

func (*Notebox) EndpointID

func (box *Notebox) EndpointID() string

EndpointID gets the notebox's endpoint ID

func (*Notebox) GetChangedNotefiles

func (box *Notebox) GetChangedNotefiles(ctx context.Context, endpointID string) (changedNotefiles []string)

GetChangedNotefiles determines, for a given tracker, if there are changes in any notebox and, if so, for which ones. NOTE that after significant performance measurement in Aug 2024 it became clear that this method would be far, far more efficient if we would design a box.OpenNotefiles() method that returns a vector of notefiles after doing a single app DB query of all of them to get their contents, using a new storage.readNotefiles() method. If and when we're looking to improve performance this would be a great addition, specifically because the msgNoteboxSummary transaction is done at the beginning of each and every sync and thus is inherently a hotspot.

func (*Notebox) GetChanges

func (box *Notebox) GetChanges(endpointID string, maxBatchSize int) (file *Notefile, numChanges int, totalChanges int, totalNotes int, since int64, until int64, err error)

GetChanges retrieves the next batch of changes being tracked

func (*Notebox) GetNote

func (box *Notebox) GetNote(ctx context.Context, notefileID string, noteID string) (note note.Note, err error)

GetNote gets a note from a notefile

func (*Notebox) GetNotefileInfo

func (box *Notebox) GetNotefileInfo(notefileID string) (notefileInfo note.NotefileInfo, err error)

GetNotefileInfo retrieves info about a specific notefile

func (*Notebox) MergeNotebox

func (box *Notebox) MergeNotebox(ctx context.Context, fromBoxfile *Notefile) (err error)

MergeNotebox takes a "changes" Notefile from box.GetChanges, and integrates those changes into the current notebox. NOTE that the "fromBoxFile" should be assumed to be modified and then freed by this method, so the caller must not retain any references.

func (*Notebox) NoteboxNotefileDesc added in v1.7.3

func (box *Notebox) NoteboxNotefileDesc() (allInfo []note.NotefileDesc)

NoteboxNotefileDesc gets info about all notefiles in a notebox

func (*Notebox) Notefile

func (box *Notebox) Notefile() *Notefile

Notefile gets the pointer to the notefile associated with the notebox

func (*Notebox) NotefileExists added in v0.1.10

func (box *Notebox) NotefileExists(notefileID string) (present bool)

NotefileExists returns true if notefile exists and is not deleted

func (*Notebox) Notefiles

func (box *Notebox) Notefiles(includeTombstones bool) (notefiles []string)

Notefiles gets a list of all openable notefiles in the current boxfile

func (*Notebox) OpenNotefile

func (box *Notebox) OpenNotefile(ctx context.Context, notefileID string) (iOpenfile *OpenNotefile, notefile *Notefile, err error)

OpenNotefile opens a notefile, reading it from storage and bumping its refcount. As such, you MUST pair this with a call to CloseNotefile. Note that this function must work for the "" NotefileID (when opening the notebox "|" instance), so don't add a check that would prohibit this.

func (*Notebox) Openfile added in v1.7.0

func (box *Notebox) Openfile() *OpenNotefile

OpenNotefile gets the pointer to the openfile associated with the notebox

func (*Notebox) Request

func (box *Notebox) Request(ctx context.Context, ei *NotefileEventInfo, endpointID string, reqJSON []byte) (rspJSON []byte)

Request performs a local operation using the JSON API

func (*Notebox) SetNotefileInfo

func (box *Notebox) SetNotefileInfo(ctx context.Context, notefileID string, notefileInfo note.NotefileInfo) (err error)

SetNotefileInfo sets the info about a notefile that is allowed to be changed after notefile creation

func (*Notebox) UpdateChangeTracker

func (box *Notebox) UpdateChangeTracker(endpointID string, since int64, until int64) error

UpdateChangeTracker updates the tracker once changes have been processed

func (*Notebox) UpdateNote

func (box *Notebox) UpdateNote(ctx context.Context, ei *NotefileEventInfo, endpointID string, notefileID string, noteID string, note note.Note) (err error)

UpdateNote updates an existing note from notefile

type NoteboxInstance added in v0.2.6

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

NoteboxInstance is the in-memory data structure for an open notebox

type NoteboxUpdateEnvFunc added in v1.7.0

type NoteboxUpdateEnvFunc func(ctx context.Context, ei *NotefileEventInfo, box *Notebox, deviceUID string, appUID string, updateFeeds bool) (err error)

NoteboxUpdateEnvFunc is the func to update environment variables for a device

type Notefile

type Notefile struct {
	Queue    bool                 `json:"Q,omitempty"`
	Notes    map[string]note.Note `json:"N,omitempty"`
	Trackers map[string]Tracker   `json:"T,omitempty"`
	Change   int64                `json:"C,omitempty"`
	// contains filtered or unexported fields
}

Notefile is The outermost data structure of a Notefile JSON object, containing a set of notes that may be synchronized.

func CreateNotefile

func CreateNotefile(isQueue bool) *Notefile

CreateNotefile instantiates and initializes a new Notefile, and prepares it so that notes may be added on behalf of the specified endpoint. The ID of that endpoint may be changed at any time and is merely an affordance so that we don't need to put the endpointID onto every Note call.

func (*Notefile) AddNote

func (nf *Notefile) AddNote(ctx context.Context, ei *NotefileEventInfo, endpointID string, noteID string, xnote note.Note) (newNoteID string, err error)

AddNote adds a newly-created Note to a Notefile. After the note is added to the Notefile, it should no longer be used because its contents is copied into the Notefile. If a unique ID for this note isn't supplied, one is generated. Note that if this is a queue, AddNote adds the newly-created note in a pre-deleted state. This is quite useful for notefiles that are being "tracked", because after all trackers receive it, they will undelete it and thus it will be present everywhere except the source. This is an intentional asymmetry in synchronization that is primarily useful when sending "to hub" or "from hub". By convention, sent notes should be deleted after they have been processed by the recipient(s).

func (*Notefile) AddNoteWithHistory added in v1.7.0

func (nf *Notefile) AddNoteWithHistory(ctx context.Context, ei *NotefileEventInfo, endpointID string, noteID string, xnote note.Note) (newNoteID string, err error)

AddNoteWithHistory is same as AddNote, but it retains history

func (*Notefile) AddTracker

func (nf *Notefile) AddTracker(trackerID string) error

AddTracker creates an object that will be used for performing incremental queries against the notefile. Do NOT create trackers that won't actively be used, because deletion tombstones will remain in the Notefile for as long as necessary by the oldest pending tracker. In other words, delete trackers when not in use.

func (*Notefile) AllNotes added in v1.7.0

func (nf *Notefile) AllNotes(includeTombstones bool) (notes map[string]note.Note)

Notes retrieves a duplicate list of all Notes in the notefile

func (*Notefile) AreChanges

func (nf *Notefile) AreChanges(trackerID string) (areChanges bool, err error)

AreChanges determines whether or not there are any changes pending for this endpoint

func (*Notefile) ClearTracker

func (nf *Notefile) ClearTracker(trackerID string)

ClearTracker clears the change count in a tracker

func (*Notefile) Close

func (nf *Notefile) Close()

Close closes and frees the Notefile

func (*Notefile) ConvertToJSON

func (nf *Notefile) ConvertToJSON(indent bool) (output []byte, err error)

ConvertToJSON serializes/marshals the in-memory Notefile into a JSON buffer

func (*Notefile) CountNotes

func (nf *Notefile) CountNotes(includeTombstones bool) (count int)

CountNotes returns the count of notes within this notefile

func (*Notefile) DeleteNote

func (nf *Notefile) DeleteNote(ctx context.Context, ei *NotefileEventInfo, endpointID string, noteID string) error

DeleteNote sets the deleted flag on an existing note from in a Notefile, marking it so that it will be purged at a later time when safe to do so from a synchronization perspective.

func (*Notefile) DeleteTracker

func (nf *Notefile) DeleteTracker(trackerID string) error

DeleteTracker deletes an existing tracker

func (*Notefile) GetChanges

func (nf *Notefile) GetChanges(endpointID string, includeTombstones bool, maxBatchSize int) (chgfile *Notefile, numChanges int, totalChanges int, totalNotes int, since int64, until int64, err error)

GetChanges retrieves the next batch of changes being tracked, initializing a new tracker if necessary.

func (*Notefile) GetLeastRecentNoteID added in v0.2.7

func (nf *Notefile) GetLeastRecentNoteID() (noteID string, err error)

GetLeastRecentNoteID enumerates and returns the first logical note to dequeue

func (*Notefile) GetMostRecentNoteID added in v1.7.3

func (nf *Notefile) GetMostRecentNoteID() (mostRecentNoteID string, mostRecentWhen int64, err error)

GetMostRecentNote enumerates and returns the most recent note in the notefile. If there are notes in the notefile but all their when's are zero, an arbitrary note will be returned.

func (*Notefile) GetNote

func (nf *Notefile) GetNote(noteID string) (xnote note.Note, err error)

GetNote retrieves a copy of a note from a Notefile, by ID

func (*Notefile) GetTrackers

func (nf *Notefile) GetTrackers() []string

GetTrackers gets a list of the trackers for a given notefile

func (*Notefile) Info

func (nf *Notefile) Info() (info note.NotefileInfo)

Info returns the notefileinfo as it was when this notefile was opened

func (*Notefile) InternalizePayload

func (nf *Notefile) InternalizePayload(xp []byte) (err error)

InternalizePayload populates the Payload field inside a set of notes in a notefile from an external source

func (*Notefile) IsTracker

func (nf *Notefile) IsTracker(trackerID string) (isTracker bool)

IsTracker returns TRUE if there's a tracker present, else false

func (*Notefile) MarkAsModified added in v1.7.0

func (nf *Notefile) MarkAsModified(reason string)

Mark the notefile as modified

func (*Notefile) MergeNotefile

func (nf *Notefile) MergeNotefile(ctx context.Context, ei *NotefileEventInfo, fromNotefile *Notefile) error

MergeNotefile combines/merges the entire contents of one Notefile into another

func (*Notefile) Modified

func (nf *Notefile) Modified() int

Modified returns the number of times this has been modified in-memory since being opened. Note that this is not persistent, and is intended to be used for checkpointing.

func (*Notefile) NewNoteID

func (nf *Notefile) NewNoteID(endpointID string) string

NewNoteID Generates a new unique Note ID

func (*Notefile) NoteIDs

func (nf *Notefile) NoteIDs(includeTombstones bool) (noteIDs []string)

NoteIDs retrieves the list of all Note IDs in the notefile

func (*Notefile) Notefile

func (nf *Notefile) Notefile() (notefileID string)

Notefile returns the notefileID for this notefile

func (*Notefile) PurgeTombstones

func (nf *Notefile) PurgeTombstones(ignoreEndpointID string)

PurgeTombstones purges tombstones that are no longer needed by trackers

func (*Notefile) ResolveNoteConflicts

func (nf *Notefile) ResolveNoteConflicts(endpointID string, noteID string, xnote note.Note) error

ResolveNoteConflicts resolves all conflicts that are pending for a Note in a Notefile

func (*Notefile) SetNoteWhen added in v1.7.0

func (nf *Notefile) SetNoteWhen(noteID string, when int64) (success bool)

Set the 'when' date on a note immediately AFTER it has been added/updated

func (*Notefile) UpdateChangeTracker

func (nf *Notefile) UpdateChangeTracker(endpointID string, since int64, until int64) (err error)

UpdateChangeTracker updates the tracker and purges tombstones after changes have been committed

func (*Notefile) UpdateNote

func (nf *Notefile) UpdateNote(ctx context.Context, ei *NotefileEventInfo, endpointID string, noteID string, xnote note.Note) error

UpdateNote updates an existing note within a Notefile, as well as updating all its history and conflict metadata as appropriate.

type NotefileEventInfo added in v1.7.4

type NotefileEventInfo struct {
	DeviceUID  string      // The deviceUID being dealt with at the time of the event setup
	DeviceSN   string      // The deviceSN being dealt with at the time of the event setup
	ProductUID string      // The productUID being dealt with at the time of the event setup
	AppUID     string      // The appUID being dealt with at the time of the event setup
	Transport  string      // The transport being dealt with at the time of the event setup
	Fn         EventFunc   // The function to call when eventing of a change
	Session    *HubSession // An argument to be passed to the event call
}

Event info to be used for note changes

func EventInfo added in v1.7.4

func EventInfo(deviceUID string, deviceSN string, productUID string, appUID string, transport string, eventFn EventFunc, session *HubSession) (ei *NotefileEventInfo)

EventInfo establishes default information used for change notification on notefiles opened in the box

type NotehubPB

type NotehubPB struct {
	Version                        *int64   `protobuf:"varint,1,opt,name=Version" json:"Version,omitempty"`
	MessageType                    *string  `protobuf:"bytes,2,opt,name=MessageType" json:"MessageType,omitempty"`
	Error                          *string  `protobuf:"bytes,3,opt,name=Error" json:"Error,omitempty"`
	DeviceUID                      *string  `protobuf:"bytes,4,opt,name=DeviceUID" json:"DeviceUID,omitempty"`
	DeviceEndpointID               *string  `protobuf:"bytes,5,opt,name=DeviceEndpointID" json:"DeviceEndpointID,omitempty"`
	HubTimeNs                      *int64   `protobuf:"varint,6,opt,name=HubTimeNs" json:"HubTimeNs,omitempty"`
	HubEndpointID                  *string  `protobuf:"bytes,7,opt,name=HubEndpointID" json:"HubEndpointID,omitempty"`
	HubSessionTicket               *string  `protobuf:"bytes,8,opt,name=HubSessionTicket" json:"HubSessionTicket,omitempty"`
	HubSessionHandler              *string  `protobuf:"bytes,9,opt,name=HubSessionHandler" json:"HubSessionHandler,omitempty"`
	HubSessionTicketExpiresTimeSec *int64   `protobuf:"varint,10,opt,name=HubSessionTicketExpiresTimeSec" json:"HubSessionTicketExpiresTimeSec,omitempty"`
	NotefileID                     *string  `protobuf:"bytes,11,opt,name=NotefileID" json:"NotefileID,omitempty"`
	NotefileIDs                    *string  `protobuf:"bytes,12,opt,name=NotefileIDs" json:"NotefileIDs,omitempty"`
	Since                          *int64   `protobuf:"varint,13,opt,name=Since" json:"Since,omitempty"`
	Until                          *int64   `protobuf:"varint,14,opt,name=Until" json:"Until,omitempty"`
	MaxChanges                     *int64   `protobuf:"varint,15,opt,name=MaxChanges" json:"MaxChanges,omitempty"`
	DeviceSN                       *string  `protobuf:"bytes,16,opt,name=DeviceSN" json:"DeviceSN,omitempty"`
	NoteID                         *string  `protobuf:"bytes,17,opt,name=NoteID" json:"NoteID,omitempty"`
	SessionIDPrev                  *int64   `protobuf:"varint,18,opt,name=SessionIDPrev" json:"SessionIDPrev,omitempty"`
	SessionIDNext                  *int64   `protobuf:"varint,19,opt,name=SessionIDNext" json:"SessionIDNext,omitempty"`
	SessionIDMismatch              *bool    `protobuf:"varint,20,opt,name=SessionIDMismatch" json:"SessionIDMismatch,omitempty"`
	Bytes1                         *int64   `protobuf:"varint,21,opt,name=Bytes1" json:"Bytes1,omitempty"`
	Bytes2                         *int64   `protobuf:"varint,22,opt,name=Bytes2" json:"Bytes2,omitempty"`
	Bytes3                         *int64   `protobuf:"varint,23,opt,name=Bytes3" json:"Bytes3,omitempty"`
	Bytes4                         *int64   `protobuf:"varint,24,opt,name=Bytes4" json:"Bytes4,omitempty"`
	ProductUID                     *string  `protobuf:"bytes,25,opt,name=ProductUID" json:"ProductUID,omitempty"`
	UsageProvisioned               *int64   `protobuf:"varint,26,opt,name=UsageProvisioned" json:"UsageProvisioned,omitempty"`
	UsageRcvdBytes                 *uint32  `protobuf:"varint,27,opt,name=UsageRcvdBytes" json:"UsageRcvdBytes,omitempty"`
	UsageSentBytes                 *uint32  `protobuf:"varint,28,opt,name=UsageSentBytes" json:"UsageSentBytes,omitempty"`
	UsageTCPSessions               *uint32  `protobuf:"varint,29,opt,name=UsageTCPSessions" json:"UsageTCPSessions,omitempty"`
	UsageTLSSessions               *uint32  `protobuf:"varint,30,opt,name=UsageTLSSessions" json:"UsageTLSSessions,omitempty"`
	UsageRcvdNotes                 *uint32  `protobuf:"varint,31,opt,name=UsageRcvdNotes" json:"UsageRcvdNotes,omitempty"`
	UsageSentNotes                 *uint32  `protobuf:"varint,32,opt,name=UsageSentNotes" json:"UsageSentNotes,omitempty"`
	CellID                         *string  `protobuf:"bytes,33,opt,name=CellID" json:"CellID,omitempty"`
	NotificationSession            *bool    `protobuf:"varint,34,opt,name=NotificationSession" json:"NotificationSession,omitempty"`
	Voltage100                     *int32   `protobuf:"varint,35,opt,name=Voltage100" json:"Voltage100,omitempty"`
	Temp100                        *int32   `protobuf:"varint,36,opt,name=Temp100" json:"Temp100,omitempty"`
	ContinuousSession              *bool    `protobuf:"varint,37,opt,name=ContinuousSession" json:"ContinuousSession,omitempty"`
	MotionSecs                     *int64   `protobuf:"varint,38,opt,name=MotionSecs" json:"MotionSecs,omitempty"`
	MotionOrientation              *string  `protobuf:"bytes,39,opt,name=MotionOrientation" json:"MotionOrientation,omitempty"`
	SessionTrigger                 *string  `protobuf:"bytes,40,opt,name=SessionTrigger" json:"SessionTrigger,omitempty"`
	Voltage1000                    *int32   `protobuf:"varint,41,opt,name=Voltage1000" json:"Voltage1000,omitempty"`
	Temp1000                       *int32   `protobuf:"varint,42,opt,name=Temp1000" json:"Temp1000,omitempty"`
	HubSessionFactoryResetID       *string  `protobuf:"bytes,43,opt,name=HubSessionFactoryResetID" json:"HubSessionFactoryResetID,omitempty"`
	HighPowerSecsTotal             *uint32  `protobuf:"varint,44,opt,name=HighPowerSecsTotal" json:"HighPowerSecsTotal,omitempty"`
	HighPowerSecsData              *uint32  `protobuf:"varint,45,opt,name=HighPowerSecsData" json:"HighPowerSecsData,omitempty"`
	HighPowerSecsGPS               *uint32  `protobuf:"varint,46,opt,name=HighPowerSecsGPS" json:"HighPowerSecsGPS,omitempty"`
	HighPowerCyclesTotal           *uint32  `protobuf:"varint,47,opt,name=HighPowerCyclesTotal" json:"HighPowerCyclesTotal,omitempty"`
	HighPowerCyclesData            *uint32  `protobuf:"varint,48,opt,name=HighPowerCyclesData" json:"HighPowerCyclesData,omitempty"`
	HighPowerCyclesGPS             *uint32  `protobuf:"varint,49,opt,name=HighPowerCyclesGPS" json:"HighPowerCyclesGPS,omitempty"`
	DeviceSKU                      *string  `protobuf:"bytes,50,opt,name=DeviceSKU" json:"DeviceSKU,omitempty"`
	DeviceFirmware                 *int64   `protobuf:"varint,51,opt,name=DeviceFirmware" json:"DeviceFirmware,omitempty"`
	DevicePIN                      *string  `protobuf:"bytes,52,opt,name=DevicePIN" json:"DevicePIN,omitempty"`
	DeviceOrderingCode             *string  `protobuf:"bytes,53,opt,name=DeviceOrderingCode" json:"DeviceOrderingCode,omitempty"`
	UsageRcvdBytesSecondary        *uint32  `protobuf:"varint,54,opt,name=UsageRcvdBytesSecondary" json:"UsageRcvdBytesSecondary,omitempty"`
	UsageSentBytesSecondary        *uint32  `protobuf:"varint,55,opt,name=UsageSentBytesSecondary" json:"UsageSentBytesSecondary,omitempty"`
	SuppressResponse               *bool    `protobuf:"varint,56,opt,name=SuppressResponse" json:"SuppressResponse,omitempty"`
	Where                          *string  `protobuf:"bytes,57,opt,name=Where" json:"Where,omitempty"`
	WhereWhen                      *int64   `protobuf:"varint,58,opt,name=WhereWhen" json:"WhereWhen,omitempty"`
	HubPacketHandler               *string  `protobuf:"bytes,59,opt,name=HubPacketHandler" json:"HubPacketHandler,omitempty"`
	PowerSource                    *uint32  `protobuf:"varint,60,opt,name=PowerSource" json:"PowerSource,omitempty"`
	PowerMahUsed                   *float64 `protobuf:"fixed64,61,opt,name=PowerMahUsed" json:"PowerMahUsed,omitempty"`
	PenaltySecs                    *uint32  `protobuf:"varint,62,opt,name=PenaltySecs" json:"PenaltySecs,omitempty"`
	FailedConnects                 *uint32  `protobuf:"varint,63,opt,name=FailedConnects" json:"FailedConnects,omitempty"`
	SocketAlias                    *string  `protobuf:"bytes,64,opt,name=SocketAlias" json:"SocketAlias,omitempty"`
	// contains filtered or unexported fields
}

func (*NotehubPB) Descriptor deprecated

func (*NotehubPB) Descriptor() ([]byte, []int)

Deprecated: Use NotehubPB.ProtoReflect.Descriptor instead.

func (*NotehubPB) GetBytes1

func (x *NotehubPB) GetBytes1() int64

func (*NotehubPB) GetBytes2

func (x *NotehubPB) GetBytes2() int64

func (*NotehubPB) GetBytes3

func (x *NotehubPB) GetBytes3() int64

func (*NotehubPB) GetBytes4

func (x *NotehubPB) GetBytes4() int64

func (*NotehubPB) GetCellID

func (x *NotehubPB) GetCellID() string

func (*NotehubPB) GetContinuousSession added in v0.2.7

func (x *NotehubPB) GetContinuousSession() bool

func (*NotehubPB) GetDeviceEndpointID

func (x *NotehubPB) GetDeviceEndpointID() string

func (*NotehubPB) GetDeviceFirmware added in v1.7.0

func (x *NotehubPB) GetDeviceFirmware() int64

func (*NotehubPB) GetDeviceOrderingCode added in v1.7.0

func (x *NotehubPB) GetDeviceOrderingCode() string

func (*NotehubPB) GetDevicePIN added in v1.7.0

func (x *NotehubPB) GetDevicePIN() string

func (*NotehubPB) GetDeviceSKU added in v1.7.0

func (x *NotehubPB) GetDeviceSKU() string

func (*NotehubPB) GetDeviceSN

func (x *NotehubPB) GetDeviceSN() string

func (*NotehubPB) GetDeviceUID

func (x *NotehubPB) GetDeviceUID() string

func (*NotehubPB) GetError

func (x *NotehubPB) GetError() string

func (*NotehubPB) GetFailedConnects added in v1.7.3

func (x *NotehubPB) GetFailedConnects() uint32

func (*NotehubPB) GetHighPowerCyclesData added in v1.7.0

func (x *NotehubPB) GetHighPowerCyclesData() uint32

func (*NotehubPB) GetHighPowerCyclesGPS added in v1.7.0

func (x *NotehubPB) GetHighPowerCyclesGPS() uint32

func (*NotehubPB) GetHighPowerCyclesTotal added in v1.7.0

func (x *NotehubPB) GetHighPowerCyclesTotal() uint32

func (*NotehubPB) GetHighPowerSecsData added in v1.7.0

func (x *NotehubPB) GetHighPowerSecsData() uint32

func (*NotehubPB) GetHighPowerSecsGPS added in v1.7.0

func (x *NotehubPB) GetHighPowerSecsGPS() uint32

func (*NotehubPB) GetHighPowerSecsTotal added in v1.7.0

func (x *NotehubPB) GetHighPowerSecsTotal() uint32

func (*NotehubPB) GetHubEndpointID

func (x *NotehubPB) GetHubEndpointID() string

func (*NotehubPB) GetHubPacketHandler added in v1.7.1

func (x *NotehubPB) GetHubPacketHandler() string

func (*NotehubPB) GetHubSessionFactoryResetID added in v1.7.0

func (x *NotehubPB) GetHubSessionFactoryResetID() string

func (*NotehubPB) GetHubSessionHandler

func (x *NotehubPB) GetHubSessionHandler() string

func (*NotehubPB) GetHubSessionTicket

func (x *NotehubPB) GetHubSessionTicket() string

func (*NotehubPB) GetHubSessionTicketExpiresTimeSec

func (x *NotehubPB) GetHubSessionTicketExpiresTimeSec() int64

func (*NotehubPB) GetHubTimeNs

func (x *NotehubPB) GetHubTimeNs() int64

func (*NotehubPB) GetMaxChanges

func (x *NotehubPB) GetMaxChanges() int64

func (*NotehubPB) GetMessageType

func (x *NotehubPB) GetMessageType() string

func (*NotehubPB) GetMotionOrientation added in v0.3.7

func (x *NotehubPB) GetMotionOrientation() string

func (*NotehubPB) GetMotionSecs added in v0.3.7

func (x *NotehubPB) GetMotionSecs() int64

func (*NotehubPB) GetNoteID

func (x *NotehubPB) GetNoteID() string

func (*NotehubPB) GetNotefileID

func (x *NotehubPB) GetNotefileID() string

func (*NotehubPB) GetNotefileIDs

func (x *NotehubPB) GetNotefileIDs() string

func (*NotehubPB) GetNotificationSession

func (x *NotehubPB) GetNotificationSession() bool

func (*NotehubPB) GetPenaltySecs added in v1.7.3

func (x *NotehubPB) GetPenaltySecs() uint32

func (*NotehubPB) GetPowerMahUsed added in v1.7.3

func (x *NotehubPB) GetPowerMahUsed() float64

func (*NotehubPB) GetPowerSource added in v1.7.3

func (x *NotehubPB) GetPowerSource() uint32

func (*NotehubPB) GetProductUID

func (x *NotehubPB) GetProductUID() string

func (*NotehubPB) GetSessionIDMismatch

func (x *NotehubPB) GetSessionIDMismatch() bool

func (*NotehubPB) GetSessionIDNext

func (x *NotehubPB) GetSessionIDNext() int64

func (*NotehubPB) GetSessionIDPrev

func (x *NotehubPB) GetSessionIDPrev() int64

func (*NotehubPB) GetSessionTrigger added in v0.3.9

func (x *NotehubPB) GetSessionTrigger() string

func (*NotehubPB) GetSince

func (x *NotehubPB) GetSince() int64

func (*NotehubPB) GetSocketAlias added in v1.7.3

func (x *NotehubPB) GetSocketAlias() string

func (*NotehubPB) GetSuppressResponse added in v1.7.0

func (x *NotehubPB) GetSuppressResponse() bool

func (*NotehubPB) GetTemp100

func (x *NotehubPB) GetTemp100() int32

func (*NotehubPB) GetTemp1000 added in v1.7.0

func (x *NotehubPB) GetTemp1000() int32

func (*NotehubPB) GetUntil

func (x *NotehubPB) GetUntil() int64

func (*NotehubPB) GetUsageProvisioned

func (x *NotehubPB) GetUsageProvisioned() int64

func (*NotehubPB) GetUsageRcvdBytes

func (x *NotehubPB) GetUsageRcvdBytes() uint32

func (*NotehubPB) GetUsageRcvdBytesSecondary added in v1.7.0

func (x *NotehubPB) GetUsageRcvdBytesSecondary() uint32

func (*NotehubPB) GetUsageRcvdNotes

func (x *NotehubPB) GetUsageRcvdNotes() uint32

func (*NotehubPB) GetUsageSentBytes

func (x *NotehubPB) GetUsageSentBytes() uint32

func (*NotehubPB) GetUsageSentBytesSecondary added in v1.7.0

func (x *NotehubPB) GetUsageSentBytesSecondary() uint32

func (*NotehubPB) GetUsageSentNotes

func (x *NotehubPB) GetUsageSentNotes() uint32

func (*NotehubPB) GetUsageTCPSessions

func (x *NotehubPB) GetUsageTCPSessions() uint32

func (*NotehubPB) GetUsageTLSSessions

func (x *NotehubPB) GetUsageTLSSessions() uint32

func (*NotehubPB) GetVersion

func (x *NotehubPB) GetVersion() int64

func (*NotehubPB) GetVoltage100

func (x *NotehubPB) GetVoltage100() int32

func (*NotehubPB) GetVoltage1000 added in v1.7.0

func (x *NotehubPB) GetVoltage1000() int32

func (*NotehubPB) GetWhere added in v1.7.0

func (x *NotehubPB) GetWhere() string

func (*NotehubPB) GetWhereWhen added in v1.7.0

func (x *NotehubPB) GetWhereWhen() int64

func (*NotehubPB) ProtoMessage

func (*NotehubPB) ProtoMessage()

func (*NotehubPB) ProtoReflect added in v1.7.0

func (x *NotehubPB) ProtoReflect() protoreflect.Message

func (*NotehubPB) Reset

func (x *NotehubPB) Reset()

func (*NotehubPB) String

func (x *NotehubPB) String() string

type OpenNotefile

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

OpenNotefile is the in-memory data structure for an open notefile

func (*OpenNotefile) Close

func (openfile *OpenNotefile) Close(ctx context.Context) (err error)

Close closes an open Notefile, decrementing its refcount and making it available for purging from memory if this is the last reference.

type Packet added in v1.7.1

type Packet struct {
	ConnectionID []byte
	MessagePort  uint8
	Data         []byte
}

Decoded packet

type PacketHandler added in v1.7.1

type PacketHandler struct {
	// Uploaded by Notecard when packet service is requested, and these are the
	// parameters used when decoding packets from the notecard AND used when
	// encoding packets to be sent back to the notecard.
	Notecard PacketHandlerNotecard `json:"notecard,omitempty"`

	// Set by Notehub by policy when handler is issued
	Notehub PacketHandlerNotehub `json:"notehub,omitempty"`
}

Packet handler information

func (*PacketHandler) PacketFromWire added in v1.7.1

func (h *PacketHandler) PacketFromWire(wire []byte) (msg Packet, err error)

PacketFromWire converts a request from wire format

func (*PacketHandler) PacketMaxDownlinkData added in v1.7.3

func (h *PacketHandler) PacketMaxDownlinkData(encrypted bool) (length int)

PacketMaxDownlinkData returns the largest amount of data allowed

func (*PacketHandler) PacketMaxUplinkData added in v1.7.3

func (h *PacketHandler) PacketMaxUplinkData(encrypted bool) (length int)

PacketMaxUplinkData returns the largest amount of data allowed

func (*PacketHandler) PacketToWire added in v1.7.1

func (h *PacketHandler) PacketToWire(payload Packet, secureData bool, downlinksPending bool) (msg []byte, err error)

PacketToWire converts a Packet to wire format, which is wholly little-endian See notehub-defs.go for binary wire format of PB payload

type PacketHandlerNotecard added in v1.7.1

type PacketHandlerNotecard struct {
	PacketService     string `json:"service,omitempty"`
	PacketCidType     byte   `json:"cid_type,omitempty"`
	PacketDownlinkMtu uint   `json:"packet_mtu,omitempty"`
	PacketUplinkMtu   uint   `json:"packet_mtu_uplink,omitempty"`
	EncrAlg           string `json:"alg,omitempty"`
	EncrKey           []byte `json:"key,omitempty"`
}

Note that if PacketUplinkMtu is 0, it is assumed to be the same as PacketDownlinkMtu

type PacketHandlerNotehub added in v1.7.1

type PacketHandlerNotehub struct {
	// The Notehub generates a unique connection ID for every NTN device.  It
	// is always assigned, and for certain NTN transports (such as UDP) it is
	// carried 'in-band' in the packet contents, while for other transports
	// (such as skylo) it is never carrierd on-the-wire.
	CidType byte   `json:"cid_type,omitempty"` // CID_RANDOM
	Cid     []byte `json:"cid,omitempty"`      // Random connection ID
	// The Notehub can optionally tell the notecard to override the standard
	// encryption for .dbs/.qos/.qis files, either forcing it to be ON or OFF
	MustEncrypt bool `json:"encrall,omitempty"`
	MayEncrypt  bool `json:"encr,omitempty"`
	// Specifically used by the notecard/notehub when the transport is UDP
	UdpMtu      uint   `json:"mtu,omitempty"`
	UdpIpV4     string `json:"ipv4,omitempty"`
	UdpIpV4Port string `json:"ipv4port,omitempty"`
	UdpPolicy   string `json:"comms,omitempty"`
}

type Precision added in v0.3.5

type Precision int

Precision indicates whether the conversion to Float16 is exact, subnormal without dropped bits, inexact, underflow, or overflow.

const (

	// PrecisionExact is for non-subnormals that don't drop bits during conversion.
	// All of these can round-trip.  Should always convert to float16.
	PrecisionExact Precision = iota

	// PrecisionUnknown is for subnormals that don't drop bits during conversion but
	// not all of these can round-trip so precision is unknown without more effort.
	// Only 2046 of these can round-trip and the rest cannot round-trip.
	PrecisionUnknown

	// PrecisionInexact is for dropped significand bits and cannot round-trip.
	// Some of these are subnormals. Cannot round-trip float32->float16->float32.
	PrecisionInexact

	// PrecisionUnderflow is for Underflows. Cannot round-trip float32->float16->float32.
	PrecisionUnderflow

	// PrecisionOverflow is for Overflows. Cannot round-trip float32->float16->float32.
	PrecisionOverflow
)

func PrecisionFromfloat32 added in v0.3.5

func PrecisionFromfloat32(f32 float32) Precision

PrecisionFromfloat32 returns Precision without performing the conversion. Conversions from both Infinity and NaN values will always report PrecisionExact even if NaN payload or NaN-Quiet-Bit is lost. This function is kept simple to allow inlining and run < 0.5 ns/op, to serve as a fast filter.

type ReadFileFunc

type ReadFileFunc func(ctx context.Context, appUID string, filetype notehub.UploadType, key string, offset int32, length int32, compress bool) (body notehub.UploadMetadata, payload []byte, err error)

ReadFileFunc is the func to read a byte range from the named file

type SessionType added in v1.7.4

type SessionType int

SessionType enumerates the type of session

const (
	SessionTypeTCP SessionType = iota
	SessionTypeTLS
	SessionTypePacket
	SessionTypeWebhook
)

type SignalFunc

type SignalFunc func(deviceUID string, bodyJSON []byte, payload []byte, session *HubSession) (err error)

SignalFunc performs a web request on behalf of a device

type SmazzContext added in v1.7.0

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

func Smazz added in v1.7.0

func Smazz(table [254]string) (ctx *SmazzContext)

func (*SmazzContext) Decode added in v1.7.0

func (ctx *SmazzContext) Decode(dst, src []byte) ([]byte, error)

Decode returns the decoded form of src. The returned slice may be a sub-slice of dst if dst was large enough to hold the entire decoded block. Otherwise, a newly allocated slice will be returned. It is valid to pass a nil dst.

func (*SmazzContext) Encode added in v1.7.0

func (ctx *SmazzContext) Encode(dst, src []byte) ([]byte, error)

Encode returns the encoded form of src. The returned slice may be a sub-slice of dst if dst was large enough to hold the entire encoded block. Otherwise, a newly allocated slice will be returned. It is valid to pass a nil dst.

func (*SmazzContext) Invalid added in v1.7.0

func (ctx *SmazzContext) Invalid(src []byte) bool

See if a buffer is known NOT to be Smazz-encoded

type TimeZoneNames added in v0.2.3

type TimeZoneNames struct {
	Name string
	ID   int
}

TimeZoneNames is the struct for the table below

type Tracker

type Tracker struct {
	Change    int64 `json:"c,omitempty"`
	SessionID int64 `json:"i,omitempty"`
	Optimize  bool  `json:"o,omitempty"`
}

Tracker is the structure maintained on a per-endpoint basis. When created, the Active flag being false indicates that any GetChanges will return ALL notes in the file. Only after the tracking entity has received all notes at least once can it then switch into "Optimize" mode. When Optimizing, a tracking entity will not receive its own uploaded changes - thus preventing "loopback". (Loopback is not harmful per se, but it is suboptimal from a bandwidth perspective.)

type Trie added in v1.7.0

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

A Trie is a a prefix tree.

func (*Trie) Get added in v1.7.0

func (t *Trie) Get(k []byte) (v int, ok bool)

Get the value corresponding to k in t, if any.

func (*Trie) Put added in v1.7.0

func (t *Trie) Put(k []byte, v int) bool

Put inserts the mapping k -> v into the Trie, overwriting any previous value. It returns true if the element was not previously in t.

func (*Trie) Root added in v1.7.0

func (t *Trie) Root() *Node

Root returns the root node of a Trie. A valid Trie (i.e., constructed with New), always has a non-nil root node.

type WebRequestFunc

type WebRequestFunc func(ctx context.Context, sess *HubSession, deviceUID string, productUID string, alias string, reqtype string, reqcontent string, reqoffset int, reqmaxbytes int, target string, reqwhen int64, bodyJSON []byte, payload []byte) (rspstatuscode int, rspheader map[string][]string, rspBodyJSON []byte, rspPayloadJSON []byte, err error)

WebRequestFunc performs a web request on behalf of a device

Jump to

Keyboard shortcuts

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