Documentation
¶
Overview ¶
Package hub is notesd's hub role (ADR-0005, ADR-0016, docs/specs/sync-protocol.md): the HTTP endpoints devices sync through (pairing, the /sync WebSocket, blobs), the token check that guards them, the log domain devices call, and the hub domain for the hub's own local clients. Pushes become writes through the vaults' actors (vault.Vault.Push), so the hub merges with the same write path as every local writer.
Index ¶
- Constants
- func CheckURL(raw string) (*url.URL, error)
- func Proof(key []byte, hubID, url, nonce string) string
- func SameURL(a, b string) bool
- func TokenHash(token string) string
- func TokenKey(token string) []byte
- func WithPeer(ctx context.Context, p Peer) context.Context
- type Config
- type Hub
- type Peer
- type Relocation
- type RelocationRequest
Constants ¶
const DeviceOrigin = "notesd://device"
DeviceOrigin is the only Origin a request to the hub may carry: a device sends it on its WebSocket (golang.org/x/net/websocket requires one), and no browser page can have it (docs/specs/sync-protocol.md, Endpoints).
const NonceSize = 32
NonceSize is the bytes of a relocation nonce; it travels as 43 base64url characters, unpadded.
Variables ¶
This section is empty.
Functions ¶
func CheckURL ¶
CheckURL accepts a hub URL whose scheme is https, or http on loopback (ADR-0016), and returns it without a trailing '/' and with its host in lower case, so URLs that SameURL calls the same are equal strings.
func Proof ¶
Proof is a relocation proof: HMAC-SHA256, keyed with the 32 bytes of the SHA-256 of the device's token, of "frostnotes relocate\n" + hub ID + "\n" + url + "\n" + nonce, in unpadded base64url. The hub computes it from the hash it keeps; the device from its own token (TokenKey).
func SameURL ¶
SameURL reports whether two hub URLs are the same: scheme and host compared without case, the path exactly, a trailing '/' ignored.
Types ¶
type Config ¶
type Config struct {
DB *store.DB
Blobs *blobs.Store
Vaults *vault.Manager
RPC *rpcserver.Server
Log *slog.Logger // [discard]
Now func() time.Time // [time.Now]
// Listen is the address notesd --hub serves, for hub.status; "" when
// the hub serves none.
Listen string
// MaxBlob is the largest blob a device may upload [blobxfer.DefaultMaxSize].
MaxBlob int64
// Crash, when set, is asked after a push is applied and recorded and
// before its answer ("pushed"); true drops the device's connection
// instead of answering, as a crash or a lost link would. The simulation
// sets it (ADR-0020).
Crash func(point string) bool
}
Config is what the hub needs. Zero fields take the defaults in brackets.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub serves devices. Its router, set with SetRouter, serves their WebSocket connections as caller device.
func (*Hub) Log ¶
func (h *Hub) Log() api.LogService
Log returns the log domain, for paired devices.
func (*Hub) Service ¶
func (h *Hub) Service() api.HubService
Service returns the hub domain, for the hub's own local clients.
type Peer ¶
Peer is the node a request came from as a listener in front of the hub saw it (lodge's Lodge-* headers): Name is shown beside a pending pairing, to tell pairings apart, and Key, its node ID, bounds how many pairings one node may have waiting. Neither admits anything (docs/specs/lodge-app.md#device).
type Relocation ¶
type Relocation struct {
Hub string `json:"hub"`
URL string `json:"url"`
Proof string `json:"proof"`
}
Relocation is POST /sync/hub's answer.
type RelocationRequest ¶
RelocationRequest is POST /sync/hub's body.