Documentation
¶
Overview ¶
Package protocol defines the sotot source protocol, version 1: the JSON messages a source sends to the sotot daemon over a WebSocket, and the daemon's replies.
A source is a separate program that watches something (a GitHub account, a bills spreadsheet, a chat service) and publishes the things that need its user's attention. See docs/source-protocol.md for the full contract; this package is its Go form.
Index ¶
Constants ¶
const ( MaxMessageBytes = 8 << 20 MaxThings = 10000 // per source MaxIDBytes = 256 MaxTitleBytes = 1024 MaxBodyBytes = 16 << 10 MaxURLBytes = 4096 MaxKindBytes = 64 MaxTags = 32 MaxTagBytes = 64 MaxValidSeconds = 10 * 366 * 24 * 60 * 60 // ten years MaxErrorBytes = 1024 MaxSummaryBytes = 64 SnapshotDeadline = 30 * time.Second // to send the first snapshot after connecting )
Limits on messages and things. A message violating them is rejected.
const ( PriorityLow = "low" PriorityHigh = "high" // PriorityUrgent is for things that need attention right now, like // a message from family. Displays make it hard to miss: the TV view // shows it as a pulsing banner. Use it sparingly. PriorityUrgent = "urgent" )
Thing priorities. The empty string means normal.
const ( // From sources: TypeSnapshot = "snapshot" // a source's complete set of things TypeDelta = "delta" // changes to the set TypeRefresh = "refresh" // renews validity without changing things // From the daemon: TypeAck = "ack" // a data message was accepted TypeError = "error" // a message was rejected; the daemon then closes )
Message types.
const Path = "/sotot/v1/source"
Path is the HTTP path of the source WebSocket endpoint, version 1.
const TunnelPort = 80
TunnelPort is the TCP port, inside the tailcat tunnel, on which the daemon serves Path.
Variables ¶
This section is empty.
Functions ¶
func ParseSourceMessage ¶
ParseSourceMessage decodes and validates a message from a source, returning a *Snapshot, *Delta, or *Refresh. It checks each message on its own; sequencing and limits on the resulting set are the daemon's job.
func ValidateSummary ¶
ValidateSummary reports whether s is a valid source summary: short, printable, one line.
Types ¶
type Ack ¶
type Ack struct {
Type string `json:"type"` // "ack"
Seq int64 `json:"seq"`
ReceivedAt time.Time `json:"received_at"`
ExpiresAt time.Time `json:"expires_at"`
}
Ack acknowledges that the daemon accepted and applied the data message with the same Seq. It means accepted, not durably written to disk.
type Delta ¶
type Delta struct {
Type string `json:"type"` // "delta"
Seq int64 `json:"seq"`
Upsert []Thing `json:"upsert,omitempty"`
Remove []string `json:"remove,omitempty"`
// ValidForSeconds, if set, renews the validity of the whole
// resulting set. If absent, the expiry is unchanged.
ValidForSeconds *int64 `json:"valid_for_seconds,omitempty"`
// Summary, if set, replaces the source's summary (see Snapshot).
Summary *string `json:"summary,omitempty"`
}
Delta atomically upserts and removes things. An upsert replaces the whole thing; it's not a field patch.
type Error ¶
type Error struct {
Type string `json:"type"` // "error"
Seq int64 `json:"seq,omitempty"`
Message string `json:"message"`
}
Error reports why the daemon rejected a message. The daemon closes the connection after sending it; the source should reconnect and send a fresh snapshot.
type Refresh ¶
type Refresh struct {
Type string `json:"type"` // "refresh"
Seq int64 `json:"seq"`
ValidForSeconds *int64 `json:"valid_for_seconds"`
}
Refresh renews the validity of the current set without changing it.
type Snapshot ¶
type Snapshot struct {
Type string `json:"type"` // "snapshot"
Seq int64 `json:"seq"`
// ValidForSeconds is how long the data stays fresh after the source
// disconnects, counted from when the daemon accepts the message.
// Required; zero means stale as soon as the source disconnects.
ValidForSeconds *int64 `json:"valid_for_seconds"`
Things []Thing `json:"things"`
// Summary is an optional very short description of the source's
// state, such as "15 domains", shown in place of "Connected" on the
// dashboard. A snapshot without it clears any previous summary.
Summary string `json:"summary,omitempty"`
}
Snapshot replaces the source's entire set of things. It must be the first message on each connection.
type Thing ¶
type Thing struct {
// ID is unique within the source and must stay the same across
// reconnects and source restarts. It is opaque to sotot.
ID string `json:"id"`
// Title is a short human-readable description. Required.
Title string `json:"title"`
// Body is optional plain-text context. It is never rendered as HTML.
Body string `json:"body,omitempty"`
// URL is an optional http or https link to the thing itself or the
// page for acting on it.
URL string `json:"url,omitempty"`
// Kind is an optional descriptive category such as "pull_request",
// "meeting", "bill", or "message".
Kind string `json:"kind,omitempty"`
// AttentionAt is when the source thinks attention should begin. If
// it's in the future, the thing doesn't need attention yet: it's
// upcoming (a renewal months off), which the browser dashboard lists
// separately and the TV doesn't show. It becomes an ordinary thing
// when the time comes, without the source republishing it.
AttentionAt *time.Time `json:"attention_at,omitempty"`
// StartsAt and EndsAt bound a timed event.
StartsAt *time.Time `json:"starts_at,omitempty"`
EndsAt *time.Time `json:"ends_at,omitempty"`
// DueAt is a deadline instant. For a deadline that's only a date,
// use Date instead.
DueAt *time.Time `json:"due_at,omitempty"`
// Date, in YYYY-MM-DD form, is the day of a date-only obligation or
// all-day event. It's not an instant: it's interpreted in TimeZone,
// which is required with Date.
Date string `json:"date,omitempty"`
TimeZone string `json:"time_zone,omitempty"`
// Tags are optional descriptive labels with no built-in meaning.
Tags []string `json:"tags,omitempty"`
// Priority is how pressing the source thinks the thing is:
// PriorityLow, PriorityHigh, PriorityUrgent, or empty for normal. A
// source may raise it over time, e.g. as a deadline approaches.
Priority string `json:"priority,omitempty"`
}
Thing is something that needs attention: a PR to review, a bill to pay, a message to answer. Its identity is the pair (source ID, ID).