Documentation
¶
Overview ¶
Package storelink is a runtime's connection to the store (internal/filestore, docs/hub/store.md): the hub's when the machine belongs to a hub that keeps one, otherwise a store inside this process, SQLite and a folder in the data folder. The model is the same either way: revisions in a database, contents by sha256, the folders on the machine a working copy. A store inside the process is the one a hub connected later takes over (docs/hub/store.md).
Index ¶
- Constants
- Variables
- func Decide(o Options) (string, string)
- func Handler(h http.Handler) http.RoundTripper
- func HubHasStore(ctx context.Context, hc *http.Client, base string) error
- func RequestSession(ctx context.Context, hc *http.Client, m Machine, now time.Time) (hubproto.StoreSession, error)
- type Link
- func (l *Link) Client(collection string) *filesync.Client
- func (l *Link) Close()
- func (l *Link) Embedded() *filestore.Server
- func (l *Link) HeadUnder(collection, rel string) (int64, error)
- func (l *Link) Kind() string
- func (l *Link) MachineID() string
- func (l *Link) Person(ctx context.Context) (string, error)
- func (l *Link) PushNow(ctx context.Context, collection, rel string) error
- func (l *Link) Ready(ctx context.Context, recheck time.Duration) error
- func (l *Link) Report(ctx context.Context, rep hubproto.MigrationReport) (hubproto.MigrationAnswer, error)
- func (l *Link) Sends(collection, top string) bool
- func (l *Link) Serves(ctx context.Context, collection string) (bool, error)
- func (l *Link) Sidebar(ctx context.Context, side hubproto.MigrationSidebar) (hubproto.MigrationSidebarAnswer, error)
- func (l *Link) SyncFolder(ctx context.Context, collection string, root func() string)
- func (l *Link) SyncProfile(ctx context.Context, p Profile)
- type Machine
- type Options
- type Profile
Constants ¶
const ( // ModeAuto: the hub's store for a hub's machine whose hub has one; none for a runtime paired with a cluster's // agent (that cluster keeps its own data); a store inside the process for a runtime on its own. ModeAuto = "auto" // ModeHub: only the hub's store; a machine that is not a hub's, or a hub without one, syncs nothing. ModeHub = "hub" // ModeEmbedded: the store inside the process, whatever else there is. ModeEmbedded = "embedded" // ModeOff: nothing syncs; the runtime keeps its data as it always did. ModeOff = "off" )
Modes of RUNTIME_STORE.
const ( KindHub = "hub" KindEmbedded = "embedded" )
Kind of link.
const DefaultProfileState = ".local/state/profile-sync"
DefaultProfileState is the profile sync's state folder under HOME when the runtime names none (RUNTIME_PROFILE_STATE_DIR).
Variables ¶
var ErrNoJournal = errors.New("the hub keeps no journal of the move")
ErrNoJournal is a store that keeps no journal of the move of the machine's data (docs/migrations): the store inside the runtime, or a hub of an older version.
var ErrNoSidebar = errors.New("the hub keeps no sidebar")
ErrNoSidebar is a hub that keeps no sidebar of the machine's person (its history is off, or it is older).
var ErrNotConnected = errors.New("the hub gave this machine no store session")
ErrNotConnected: the hub refuses this machine a store session (401, 403 or 423): it is not in a space of the hub yet (or was removed or switched off), or its clock is off. It is not a fault to repeat every few seconds: the session asks the hub again with growing pauses, and the loops that wait for the store wait for the connection (Link.Ready).
var ErrNotSyncing = errors.New("the collection is not being synced now")
ErrNotSyncing: no sync of the collection runs now (the store is not linked yet, or another runtime syncs the folder).
Functions ¶
func Handler ¶
func Handler(h http.Handler) http.RoundTripper
Handler is a transport that answers every request with h inside the process: the store inside the runtime is spoken to over the same API as the hub's, without a socket.
func HubHasStore ¶
HubHasStore asks the hub's GET /api/capabilities whether it keeps a store. errNoStore when it answers without one.
Types ¶
type Link ¶
type Link struct {
// contains filtered or unexported fields
}
Link is where the runtime's collections live.
func (*Link) Embedded ¶
Embedded is the store inside the process, nil for the hub's (backup and the move into a hub reach it here).
func (*Link) HeadUnder ¶
HeadUnder is the newest revision of the store the synced folder holds under rel (filesync.Agent.HeadUnder).
func (*Link) MachineID ¶
MachineID is the hub's id of this machine, "" for a store inside the process.
func (*Link) Person ¶
Person is the name the hub gives this machine's person in the apps collection (hubproto.StoreSession.Person); "" for a store inside the runtime or a hub that names nobody.
func (*Link) PushNow ¶
PushNow sends what changed under rel of a synced folder to the store at once, ahead of the watcher and the periodic rescan: a project the page had to open from the machine is in the store for the next look.
func (*Link) Ready ¶
Ready waits until the store answers that it is there: at once for the store inside the process; for the hub's, once its capabilities list the store. A hub without one is asked again every recheck, since it may be upgraded.
func (*Link) Report ¶
func (l *Link) Report(ctx context.Context, rep hubproto.MigrationReport) (hubproto.MigrationAnswer, error)
Report tells the hub's journal how the move of this machine's data goes (hubproto.MigrationReport) and returns what a person asked of it since. It goes with the store session; a refused session is asked again once.
func (*Link) Sends ¶
Sends says whether the files of a top folder of the synced collection may go to the store now: the store does not hold, or lists the folder. No sync running yet, a hub's collection sends nothing; another store sends.
func (*Link) Serves ¶
Serves says whether the hub opens a collection to this machine (hubproto.StoreSession.Collections): an older hub does not know the newer kinds. A store inside the process serves every kind it knows.
func (*Link) Sidebar ¶
func (l *Link) Sidebar(ctx context.Context, side hubproto.MigrationSidebar) (hubproto.MigrationSidebarAnswer, error)
Sidebar merges this machine's projects and favorites into its person's sidebar on the hub (hubproto.MigrationSidebar).
func (*Link) SyncFolder ¶
SyncFolder keeps the folder root() names in step with a collection until ctx ends. The folder is asked again every minute: a library that moved (another workspace) is synced from where it is now, with a state of its own.
type Machine ¶
type Machine struct {
ID string
DialURL string
Key ed25519.PrivateKey
}
Machine is a hub's machine as its machine.json names it: who it is, where it dials and the key it proves itself with.
type Options ¶
type Options struct {
DataDir string
Mode string
// Machine is the hub's machine this runtime runs on; nil for none.
Machine *Machine
// Paired: the runtime is one end of a pair with a cluster's agent (AGENT_SECRET_FILE, AGENT_CLUSTER_URL) and not a
// hub's machine.
Paired bool
// Name is the machine's name in what a lost write leaves behind.
Name string
// a time, and a file the store stops showing this machine stays there for the others.
Shared func(dir string) bool
// DB and Blobs name the drivers of a store inside the runtime (RUNTIME_STORE_DB, RUNTIME_STORE_BLOBS):
// postgres://… or sqlite:///folder, and file:///folder or s3://…; empty is SQLite and blobs in store/ of the data
// folder.
DB string
Blobs string
// HTTP is the client to the hub; nil for a plain one.
HTTP *http.Client
Log *slog.Logger
Now func() time.Time
}
Options is what a runtime knows about where it runs.
type Profile ¶
type Profile struct {
Home string
// State is the HOME-relative folder the sync keeps its staging, the edits that lost and its lock in: never synced
// ("" = DefaultProfileState).
State string
Codec *filesync.ProfileCodec
OnApplied func(rel string)
}
Profile is how a person's Claude profile syncs with its room in the hub (filestore.Profile): HOME is the folder, the codec seals with the room key, OnApplied hears every file another machine brought.