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 errors.go contains programmatically-testable error strings ¶
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 is a generated protocol buffer package.
Package notelib notehub.proto are the protocol definitions for notebox-notehub comms ¶
It is generated from these files:
notehub.proto
It has these top-level messages:
NotehubPB
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
- func BulkDecodeEntry(context *BulkTemplateContext, i int) (body map[string]interface{}, payload []byte, when int64, where int64)
- func Checkpoint() (err error)
- func CreateNotebox(endpointID string, boxStorage string) (err error)
- func DebugSet(which string, value string)
- func Delete(boxStorage string) (err error)
- func ErrorContains(err error, errKeyword string) bool
- func ErrorResponse(err error) (response []byte)
- func ErrorString(err error) string
- func FileCleanName(filename string) string
- func FileDefaultStorageObject() string
- func FileSetHandler(newfio *Fileio)
- func FileSetStorageLocation(root string)
- func FileStorageObject(containerName string) string
- func GetNotecardSecureElementRootCertificateAsPEM() (cert []byte)
- func HubDiscover(deviceUID string, deviceSN string, productUID string) (hubSessionTicket string, hubEndpointID string, appUID string, ...)
- func HubErrorResponse(session *HubSessionContext, errorMessage string) (result []byte)
- func HubRequest(session *HubSessionContext, content []byte, event EventFunc, ...) (result []byte, err error)
- func HubSetDeviceNotifications(fn GetNotificationFunc)
- func HubSetDiscover(fn DiscoverFunc)
- func HubSetNoteboxInit(fn NoteboxInitFunc)
- func HubSetReadFile(fn ReadFileFunc)
- func HubSetSignal(fn SignalFunc)
- func HubSetWebRequest(fn WebRequestFunc)
- func Merge(localNote *note.Note, incomingNote *note.Note) note.Note
- func NotefileAttributesFromID(notefileID string) (isQueue bool, syncToHub bool, syncFromHub bool, secure bool, reserved bool, ...)
- func OLCFromINT64(code int64) (olc string)
- func OLCToINT64(olc string) (result int64)
- func Printf(format string, args ...interface{})
- func RegisterTLSSupport()
- func TLSSupport() bool
- func TimeZoneNameToNumber(name string) int
- func TimeZoneNumberToCountry(num int) string
- func TimeZoneNumberToName(num int) string
- func WireBarsFromSession(session *HubSessionContext) (rat string, bars uint32)
- func WireExtractSessionContext(wire []byte, session *HubSessionContext) (err error)
- func WireReadRequest(conn net.Conn, waitIndefinitely bool) (bytesRead uint32, request []byte, err error)
- type BulkBody
- type BulkTemplateContext
- type DiscoverFunc
- type DiscoverInfo
- type EventFunc
- type Fileio
- type FileioCreateFunc
- type FileioDeleteFunc
- type FileioExistsFunc
- type FileioReadJSONFunc
- type FileioWriteJSONFunc
- type GetNotificationFunc
- type HubSessionContext
- type HubSessionEvent
- type Notebox
- func (box *Notebox) AddNote(endpointID string, notefileID string, noteID string, note note.Note) (err error)
- func (box *Notebox) AddNotefile(notefileID string, notefileInfo *note.NotefileInfo) error
- func (box *Notebox) CheckpointNotefile(notefileID string) (err error)
- func (box *Notebox) ClearAllTrackers(endpointID string) (err error)
- func (box *Notebox) Close() (err error)
- func (box *Notebox) CreateNotefile(isQueue bool) Notefile
- func (box *Notebox) DeleteNote(endpointID string, notefileID string, noteID string) (err error)
- func (box *Notebox) DeleteNotefile(notefileID string) (err error)
- func (box *Notebox) EndpointID() string
- func (box *Notebox) GetChangedNotefiles(endpointID string) (changedNotefiles []string, err error)
- func (box *Notebox) GetChanges(endpointID string, maxBatchSize int) (file Notefile, numChanges int, totalChanges int, since int64, until int64, ...)
- func (box *Notebox) GetEventInfo() (deviceUID string, deviceSN string, productUID string)
- func (box *Notebox) GetNote(notefileID string, noteID string) (note note.Note, err error)
- func (box *Notebox) GetNotefileInfo(notefileID string) (notefileInfo note.NotefileInfo, err error)
- func (box *Notebox) MergeNotebox(fromBoxfile Notefile) (err error)
- func (box *Notebox) Notefile() (notefile *Notefile)
- func (box *Notebox) NotefileExists(notefileID string) (present bool)
- func (box *Notebox) Notefiles(includeTombstones bool) (notefiles []string, err error)
- func (box *Notebox) OpenNotefile(notefileID string) (iOpenfile *OpenNotefile, notefile *Notefile, err error)
- func (box *Notebox) Request(endpointID string, reqJSON []byte) (rspJSON []byte)
- func (box *Notebox) SetDiscoveryService(hubLocationService string, hubAppUID string) error
- func (box *Notebox) SetEventInfo(deviceUID string, deviceSN string, productUID string, appUID string, ...) error
- func (box *Notebox) SetNotefileInfo(notefileID string, notefileInfo note.NotefileInfo) (err error)
- func (box *Notebox) UpdateChangeTracker(endpointID string, since int64, until int64) error
- func (box *Notebox) UpdateNote(endpointID string, notefileID string, noteID string, note note.Note) (err error)
- type NoteboxInitFunc
- type Notefile
- func (nf *Notefile) AddNote(endpointID string, noteID string, xnote note.Note) (err error)
- func (nf *Notefile) AddTracker(trackerID string) error
- func (nf *Notefile) AreChanges(trackerID string) (areChanges bool, err error)
- func (nf *Notefile) ClearTracker(trackerID string) error
- func (nf *Notefile) Close()
- func (nf *Notefile) CountNotes(includeTombstones bool) (count int)
- func (nf *Notefile) DeleteNote(endpointID string, noteID string) error
- func (nf *Notefile) DeleteTracker(trackerID string) error
- func (nf *Notefile) GetChanges(endpointID string, maxBatchSize int) (chgfile Notefile, numChanges int, totalChanges int, since int64, until int64, ...)
- func (nf *Notefile) GetNote(noteID string) (xnote note.Note, err error)
- func (nf *Notefile) GetTrackers() []string
- func (nf *Notefile) Info() (info note.NotefileInfo)
- func (nf *Notefile) InternalizePayload(xp []byte) (err error)
- func (nf *Notefile) IsTracker(trackerID string) (isTracker bool)
- func (nf *Notefile) MergeNotefile(fromNotefile Notefile) error
- func (nf *Notefile) Modified() int
- func (nf *Notefile) NewNoteID(endpointID string) string
- func (nf *Notefile) NoteIDs(includeTombstones bool) (noteIDs []string)
- func (nf *Notefile) Notefile() (notefileID string)
- func (nf *Notefile) PurgeTombstones(localEndpointID string) (err error)
- func (nf *Notefile) SetEventInfo(deviceUID string, deviceSN string, productUID string, appUID string, ...) error
- func (nf *Notefile) UpdateChangeTracker(endpointID string, since int64, until int64) (err error)
- func (nf *Notefile) UpdateNote(endpointID string, noteID string, xnote note.Note) error
- type NotehubPB
- func (*NotehubPB) Descriptor() ([]byte, []int)
- func (m *NotehubPB) GetBytes1() int64
- func (m *NotehubPB) GetBytes2() int64
- func (m *NotehubPB) GetBytes3() int64
- func (m *NotehubPB) GetBytes4() int64
- func (m *NotehubPB) GetCellID() string
- func (m *NotehubPB) GetDevelopment() bool
- func (m *NotehubPB) GetDeviceEndpointID() string
- func (m *NotehubPB) GetDeviceSN() string
- func (m *NotehubPB) GetDeviceUID() string
- func (m *NotehubPB) GetError() string
- func (m *NotehubPB) GetHubEndpointID() string
- func (m *NotehubPB) GetHubSessionHandler() string
- func (m *NotehubPB) GetHubSessionTicket() string
- func (m *NotehubPB) GetHubSessionTicketExpiresTimeSec() int64
- func (m *NotehubPB) GetHubTimeNs() int64
- func (m *NotehubPB) GetMaxChanges() int64
- func (m *NotehubPB) GetMessageType() string
- func (m *NotehubPB) GetNoteID() string
- func (m *NotehubPB) GetNotefileID() string
- func (m *NotehubPB) GetNotefileIDs() string
- func (m *NotehubPB) GetNotificationSession() bool
- func (m *NotehubPB) GetProductUID() string
- func (m *NotehubPB) GetSessionIDMismatch() bool
- func (m *NotehubPB) GetSessionIDNext() int64
- func (m *NotehubPB) GetSessionIDPrev() int64
- func (m *NotehubPB) GetSince() int64
- func (m *NotehubPB) GetTemp100() int32
- func (m *NotehubPB) GetUntil() int64
- func (m *NotehubPB) GetUsageProvisioned() int64
- func (m *NotehubPB) GetUsageRcvdBytes() uint32
- func (m *NotehubPB) GetUsageRcvdNotes() uint32
- func (m *NotehubPB) GetUsageSentBytes() uint32
- func (m *NotehubPB) GetUsageSentNotes() uint32
- func (m *NotehubPB) GetUsageTCPSessions() uint32
- func (m *NotehubPB) GetUsageTLSSessions() uint32
- func (m *NotehubPB) GetVersion() int64
- func (m *NotehubPB) GetVoltage100() int32
- func (*NotehubPB) ProtoMessage()
- func (m *NotehubPB) Reset()
- func (m *NotehubPB) String() string
- type OpenNotefile
- type ReadFileFunc
- type SignalFunc
- type TimeZoneNames
- type Tracker
- type WebRequestFunc
Constants ¶
const BulkNoteFormatV1 = 0x00000001
BulkNoteFormatV1 is the first and only version
const ErrAuth = "{auth}"
ErrAuth (golint)
const ErrClosed = "{closed}"
ErrClosed (golint)
const ErrDeviceNotFound = "{device-noexist}"
ErrDeviceNotFound (golint)
const ErrFileNoExist = "{file-noexist}"
ErrFileNoExist (golint)
const ErrHubNoHandler = "{no-handler}"
ErrHubNoHandler (golint)
const ErrIdle = "{idle}"
ErrIdle (golint)
const ErrNoteExists = "{note-exists}"
ErrNoteExists (golint)
const ErrNoteNoExist = "{note-noexist}"
ErrNoteNoExist (golint)
const ErrNotefileExists = "{notefile-exists}"
ErrNotefileExists (golint)
const ErrNotefileInUse = "{notefile-in-use}"
ErrNotefileInUse (golint)
const ErrNotefileName = "{notefile-bad-name}"
ErrNotefileName (golint)
const ErrNotefileNoExist = "{notefile-noexist}"
ErrNotefileNoExist (golint)
const ErrNotefileQueueDisallowed = "{notefile-queue-disallowed}"
ErrNotefileQueueDisallowed (golint)
const ErrProductNotFound = "{product-noexist}"
ErrProductNotFound (golint)
const ErrTicket = "{ticket}"
ErrTicket (golint)
const ErrTimeout = "{timeout}"
ErrTimeout (golint)
const ErrTrackerExists = "{tracker-exists}"
ErrTrackerExists (golint)
const ErrTrackerNoExist = "{tracker-noexist}"
ErrTrackerNoExist (golint)
const ErrTransportConnectFailure = "{connect-failure}"
ErrTransportConnectFailure (golint)
const ErrTransportConnected = "{connected}"
ErrTransportConnected (golint)
const ErrTransportConnectedClosed = "{connected-closed}"
ErrTransportConnectedClosed (golint)
const ErrTransportConnecting = "{connecting}"
ErrTransportConnecting (golint)
const ErrTransportDisconnected = "{disconnected}"
ErrTransportDisconnected (golint)
const ErrTransportWaitData = "{wait-data}"
ErrTransportWaitData (golint)
const ErrTransportWaitGateway = "{wait-gateway}"
ErrTransportWaitGateway (golint)
const ErrTransportWaitModule = "{wait-module}"
ErrTransportWaitModule (golint)
const ErrTransportWaitService = "{wait-service}"
ErrTransportWaitService (golint)
const HTTPUserAgent = "notes"
HTTPUserAgent is the HTTP user agent for all our uses of HTTP
const ReservedIDDelimiter = ","
ReservedIDDelimiter is used to separate lists of noteIDs, notefileIDs, endpointIDs, thus is invalid in names
Variables ¶
This section is empty.
Functions ¶
func BulkDecodeEntry ¶
func BulkDecodeEntry(context *BulkTemplateContext, i int) (body map[string]interface{}, payload []byte, when int64, where int64)
BulkDecodeEntry extract a JSON object from the binary
func Checkpoint ¶ added in v0.1.13
func Checkpoint() (err error)
Checkpoint all noteboxes and purge closed noteboxes
func CreateNotebox ¶
CreateNotebox creates a notebox on this endpoint
func ErrorContains ¶
ErrorContains tests to see if an error contains an error keyword that we might expect
func ErrorResponse ¶
ErrorResponse creates a simple JSON response given an error
func ErrorString ¶
ErrorString safely returns a string from any error, returning "" for nil
func FileCleanName ¶ added in v0.1.5
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 ¶
FileStorageObject gives a deterministic storage object name from two components
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 HubDiscover ¶
func HubDiscover(deviceUID string, deviceSN string, productUID string) (hubSessionTicket string, hubEndpointID string, appUID 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 HubErrorResponse ¶ added in v0.2.4
func HubErrorResponse(session *HubSessionContext, 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(session *HubSessionContext, content []byte, event EventFunc, context interface{}) (result []byte, 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 HubSetNoteboxInit ¶
func HubSetNoteboxInit(fn NoteboxInitFunc)
HubSetNoteboxInit sets the global notebox function to update env vars
func HubSetWebRequest ¶
func HubSetWebRequest(fn WebRequestFunc)
HubSetWebRequest sets the web request function
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 OLCFromINT64 ¶
OLCFromINT64 converts a 64-bit OLC code into a string
func OLCToINT64 ¶
OLCToINT64 converts an OLC string into a 64-bit code
func Printf ¶
func Printf(format string, args ...interface{})
Printf is an externally-callable version of same, for server use so it doesn't get held up writing to console
func RegisterTLSSupport ¶
func RegisterTLSSupport()
RegisterTLSSupport 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
TimeZoneNameToNumber converts a timezone number to a name
func TimeZoneNumberToCountry ¶ added in v0.2.3
TimeZoneNumberToCountry retrieves the country from the name
func TimeZoneNumberToName ¶ added in v0.2.3
TimeZoneNumberToName converts a timezone name to a number
func WireBarsFromSession ¶ added in v0.2.5
func WireBarsFromSession(session *HubSessionContext) (rat string, bars uint32)
WireBarsFromSession extracts device's perception of the number of bars of signal from a session
func WireExtractSessionContext ¶
func WireExtractSessionContext(wire []byte, session *HubSessionContext) (err error)
WireExtractSessionContext extracts session context from the wire message
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 {
Template string
TemplatePayloadLen int
TemplatePayloadOffset int
TemplateFlagsOffset int
Payload []byte
PayloadEntries int
PayloadEntryLength int
}
BulkTemplateContext is the context for the bulk template
func BulkDecodeTemplate ¶
func BulkDecodeTemplate(templateBodyJSON []byte, compressedPayload []byte) (context BulkTemplateContext, entries int, err error)
BulkDecodeTemplate decodes the template
type DiscoverFunc ¶
type DiscoverFunc func(edgeUID string, deviceSN string, productUID string, hostname 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
HubDeviceStorageObject string
HubDeviceAppUID string
HubTimeNs int64
HubSessionTicketExpiresTimeNs int64
HubCert []byte
}
DiscoverInfo is the information returned by DiscoverFunc
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 ¶
FileioCreateFunc creates a file
type FileioDeleteFunc ¶
FileioDeleteFunc deletes a file
type FileioExistsFunc ¶
FileioExistsFunc checks for file existence
type FileioReadJSONFunc ¶
FileioReadJSONFunc reads a JSON file
type FileioWriteJSONFunc ¶
FileioWriteJSONFunc writes a JSON file
type GetNotificationFunc ¶
type GetNotificationFunc func(deviceUID string, productUID string) (notifications []string, err error)
GetNotificationFunc retrieves hub notifications to be sent to client
type HubSessionContext ¶
type HubSessionContext struct {
Active bool
Secure bool
Terminated bool
Discovery bool
Notification bool
BeganSec int
DeviceUID string
DeviceSN string
ProductUID string
DeviceEndpointID string
HubEndpointID string
HubSessionTicket string
Transactions int
EventQ *chan HubSessionEvent
LatestUpdated bool
Latest *map[string]note.Event
RouteInfo map[string]interface{}
// Fields that are useful when logged in a session log
Session note.DeviceSession
// Cached Where info, used by event processing for efficiency
CachedWhereLat float64
CachedWhereLon float64
CachedWhereLocation string
CachedWhereCountry string
CachedWhereTimeZone string
}
HubSessionContext are the fields that are coordinated between the client and the server for the duration of an open session. The "Active" flag is true if the client believes that the service is actively maintaining it in parallel, and vice-versa on the service side.
type HubSessionEvent ¶
type HubSessionEvent struct {
Session HubSessionContext
Local bool
File Notefile
Event note.Event
Exit bool
}
HubSessionEvent is an event queue entry, containing everything necessary to process an event
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(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 ¶
OpenNotebox opens a local notebox into memory.
func (*Notebox) AddNote ¶
func (box *Notebox) AddNote(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) AddNotefile ¶
func (box *Notebox) AddNotefile(notefileID string, notefileInfo *note.NotefileInfo) error
AddNotefile adds a new notefile to the notebox, and return "nil" if it already exists
func (*Notebox) CheckpointNotefile ¶
CheckpointNotefile checkpoints an open Notefile to storage
func (*Notebox) ClearAllTrackers ¶
ClearAllTrackers deletes all trackers for this endpoint in order to force a resync of all files
func (*Notebox) Close ¶
Close releases a notebox, but leaves it in-memory with a 0 refcount for low-overhead re-open
func (*Notebox) CreateNotefile ¶
CreateNotefile creates a new Notefile in-memory, which will ultimately be added to this Notebox
func (*Notebox) DeleteNote ¶
DeleteNote deletes an existing note from notefile
func (*Notebox) DeleteNotefile ¶
DeleteNotefile deletes a closed Notefile, and releases its storage.
func (*Notebox) EndpointID ¶
EndpointID gets the notebox's endpoint ID
func (*Notebox) GetChangedNotefiles ¶
GetChangedNotefiles determines, for a given tracker, if there are changes in any notebox and, if so, for which ones.
func (*Notebox) GetChanges ¶
func (box *Notebox) GetChanges(endpointID string, maxBatchSize int) (file Notefile, numChanges int, totalChanges int, since int64, until int64, err error)
GetChanges retrieves the next batch of changes being tracked
func (*Notebox) GetEventInfo ¶
GetEventInfo retrieves the info
func (*Notebox) GetNotefileInfo ¶
func (box *Notebox) GetNotefileInfo(notefileID string) (notefileInfo note.NotefileInfo, err error)
GetNotefileInfo retrieves info about a specific notefile
func (*Notebox) MergeNotebox ¶
MergeNotebox takes a "changes" Notefile from box.GetChanges, and integrates those changes into the current notebox.
func (*Notebox) Notefile ¶
Notefile get the pointer to the notefile associated with the notebox, so that we can use standard Notefile methods to synchronize the Notebox.
func (*Notebox) NotefileExists ¶ added in v0.1.10
NotefileExists returns true if notefile exists
func (*Notebox) OpenNotefile ¶
func (box *Notebox) OpenNotefile(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) SetDiscoveryService ¶
SetDiscoveryService establishes hub context so that we may auto-connect during sync
func (*Notebox) SetEventInfo ¶
func (box *Notebox) SetEventInfo(deviceUID string, deviceSN string, productUID string, appUID string, iFn EventFunc, iCtx interface{}) error
SetEventInfo establishes default information used for change notification on notefiles opened in the box
func (*Notebox) SetNotefileInfo ¶
func (box *Notebox) SetNotefileInfo(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 ¶
UpdateChangeTracker updates the tracker once changes have been processed
type NoteboxInitFunc ¶
NoteboxInitFunc is the func to initialize the notebox at the start of a session
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 ¶
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 ¶
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) AddTracker ¶
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) AreChanges ¶
AreChanges determines whether or not there are any changes pending for this endpoint
func (*Notefile) ClearTracker ¶
ClearTracker clears the change count in a tracker
func (*Notefile) CountNotes ¶
CountNotes returns the count of notes within this notefile
func (*Notefile) DeleteNote ¶
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 ¶
DeleteTracker deletes an existing tracker
func (*Notefile) GetChanges ¶
func (nf *Notefile) GetChanges(endpointID string, maxBatchSize int) (chgfile Notefile, numChanges int, totalChanges int, since int64, until int64, err error)
GetChanges retrieves the next batch of changes being tracked, initializing a new tracker if necessary.
func (*Notefile) GetTrackers ¶
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 ¶
InternalizePayload populates the Payload field inside a set of notes in a notefile from an external source
func (*Notefile) MergeNotefile ¶
MergeNotefile combines/merges the entire contents of one Notefile into another
func (*Notefile) Modified ¶
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) PurgeTombstones ¶
PurgeTombstones purges tombstones that are no longer needed by trackers
func (*Notefile) SetEventInfo ¶
func (nf *Notefile) SetEventInfo(deviceUID string, deviceSN string, productUID string, appUID string, fn EventFunc, fnctx interface{}) error
SetEventInfo supplies information used for change notification
func (*Notefile) UpdateChangeTracker ¶
UpdateChangeTracker updates the tracker and purges tombstones after changes have been committed
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"`
Development *bool `protobuf:"varint,37,opt,name=Development" json:"Development,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (*NotehubPB) Descriptor ¶
func (*NotehubPB) GetDevelopment ¶ added in v0.1.10
func (*NotehubPB) GetDeviceEndpointID ¶
func (*NotehubPB) GetDeviceSN ¶
func (*NotehubPB) GetDeviceUID ¶
func (*NotehubPB) GetHubEndpointID ¶
func (*NotehubPB) GetHubSessionHandler ¶
func (*NotehubPB) GetHubSessionTicket ¶
func (*NotehubPB) GetHubSessionTicketExpiresTimeSec ¶
func (*NotehubPB) GetHubTimeNs ¶
func (*NotehubPB) GetMaxChanges ¶
func (*NotehubPB) GetMessageType ¶
func (*NotehubPB) GetNotefileID ¶
func (*NotehubPB) GetNotefileIDs ¶
func (*NotehubPB) GetNotificationSession ¶
func (*NotehubPB) GetProductUID ¶
func (*NotehubPB) GetSessionIDMismatch ¶
func (*NotehubPB) GetSessionIDNext ¶
func (*NotehubPB) GetSessionIDPrev ¶
func (*NotehubPB) GetTemp100 ¶
func (*NotehubPB) GetUsageProvisioned ¶
func (*NotehubPB) GetUsageRcvdBytes ¶
func (*NotehubPB) GetUsageRcvdNotes ¶
func (*NotehubPB) GetUsageSentBytes ¶
func (*NotehubPB) GetUsageSentNotes ¶
func (*NotehubPB) GetUsageTCPSessions ¶
func (*NotehubPB) GetUsageTLSSessions ¶
func (*NotehubPB) GetVersion ¶
func (*NotehubPB) GetVoltage100 ¶
func (*NotehubPB) ProtoMessage ¶
func (*NotehubPB) ProtoMessage()
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() (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 ReadFileFunc ¶
type ReadFileFunc func(appUID string, filetype string, key string, offset int32, length int32, compress bool, getInfo bool) (body []byte, payload []byte, err error)
ReadFileFunc is the func to read a byte range from the named file
type SignalFunc ¶
type SignalFunc func(deviceUID string, bodyJSON []byte, payloadJSON []byte, session *HubSessionContext) (err error)
SignalFunc performs a web request on behalf of a device
type TimeZoneNames ¶ added in v0.2.3
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 WebRequestFunc ¶
type WebRequestFunc func(deviceUID string, productUID string, alias string, reqtype string, target string, bodyJSON []byte, payloadJSON []byte, session *HubSessionContext) (rspstatuscode int, rspBodyJSON []byte, rspPayloadJSON []byte, err error)
WebRequestFunc performs a web request on behalf of a device