Documentation
¶
Overview ¶
Package engine implements the private encrypted replication protocol.
Index ¶
- Constants
- Variables
- func CheckKey(k FolderKey, check []byte) error
- func DecodeWire(r io.Reader, v any) error
- func KeyCheck(k FolderKey, folder string) []byte
- func LoadIndex(db *sql.DB, fn func(IndexEntry) error) error
- func NormalizePath(s string) (string, error)
- func OpenContent(w io.Writer, r io.Reader, k FolderKey, folder, blob, pid string) error
- func PathID(k FolderKey, folder, p string) (string, error)
- func ReadSnapshot(r io.Reader, folder string, version uint64, fn func(Row) error) (horizon uint64, err error)
- func SealContent(w io.Writer, r io.Reader, k FolderKey, folder, blob, pid string) error
- func SealMetadata(k FolderKey, folder, pid string, m FileMetadata) ([]byte, error)
- func SealedSize(n int64) int64
- type Account
- type Authenticator
- type BlobStore
- type BlobURLStore
- type Client
- type ConflictError
- type Delta
- type DirectoryBlobStore
- func (b *DirectoryBlobStore) Close() error
- func (b *DirectoryBlobStore) Delete(ctx context.Context, f, id string) error
- func (b *DirectoryBlobStore) Open(ctx context.Context, f, id string) (io.ReadCloser, error)
- func (b *DirectoryBlobStore) Put(ctx context.Context, f, id string, r io.Reader) (int64, error)
- func (b *DirectoryBlobStore) Size(ctx context.Context, f, id string) (int64, error)
- type Entry
- type Event
- type FetchResult
- type FileMetadata
- type Folder
- type FolderChallenge
- type FolderKey
- type FolderRecord
- type FolderSpec
- type Garbage
- type HTTPClient
- func (c *HTTPClient) CancelUpload(x context.Context, id, tid string) error
- func (c *HTTPClient) Changes(x context.Context, id string, v uint64) (Delta, error)
- func (c *HTTPClient) Commit(x context.Context, id string, m []Mutation) (Delta, error)
- func (c *HTTPClient) CreateFolder(x context.Context, v FolderSpec) (Folder, error)
- func (c *HTTPClient) DeleteFolder(x context.Context, id string) error
- func (c *HTTPClient) Download(x context.Context, id, blob string) (io.ReadCloser, error)
- func (c *HTTPClient) DownloadURLs(ctx context.Context, folder string, blobs []string) ([]string, error)
- func (c *HTTPClient) GetFolder(x context.Context, id string) (Folder, error)
- func (c *HTTPClient) Grant(x context.Context, id string, p Principal, r Role) error
- func (c *HTTPClient) ListFolders(x context.Context) ([]Folder, error)
- func (c *HTTPClient) PrepareFolder(ctx context.Context) (FolderChallenge, error)
- func (c *HTTPClient) Reserve(x context.Context, id string, r UploadRequest) (Ticket, error)
- func (c *HTTPClient) Revoke(x context.Context, id string, p Principal) error
- func (c *HTTPClient) SetLimits(x context.Context, id string, l Limits) error
- func (c *HTTPClient) Snapshot(ctx context.Context, folder string) (uint64, string, error)
- func (c *HTTPClient) Upload(x context.Context, id string, t Ticket, body io.Reader) error
- func (c *HTTPClient) Wait(x context.Context, id string, v uint64) (uint64, error)
- type InProcessClient
- func (c *InProcessClient) CancelUpload(x context.Context, id, tid string) error
- func (c *InProcessClient) Changes(x context.Context, id string, v uint64) (Delta, error)
- func (c *InProcessClient) Commit(x context.Context, id string, m []Mutation) (Delta, error)
- func (c *InProcessClient) CreateFolder(x context.Context, v FolderSpec) (Folder, error)
- func (c *InProcessClient) DeleteFolder(x context.Context, id string) error
- func (c *InProcessClient) Download(x context.Context, id, blob string) (io.ReadCloser, error)
- func (c *InProcessClient) DownloadURLs(ctx context.Context, id string, blobs []string) ([]string, error)
- func (c *InProcessClient) GetFolder(x context.Context, id string) (Folder, error)
- func (c *InProcessClient) Grant(x context.Context, id string, p Principal, r Role) error
- func (c *InProcessClient) ListFolders(x context.Context) ([]Folder, error)
- func (c *InProcessClient) PrepareFolder(ctx context.Context) (FolderChallenge, error)
- func (c *InProcessClient) Reserve(x context.Context, id string, r UploadRequest) (Ticket, error)
- func (c *InProcessClient) Revoke(x context.Context, id string, p Principal) error
- func (c *InProcessClient) SetLimits(x context.Context, id string, l Limits) error
- func (c *InProcessClient) Snapshot(x context.Context, id string) (uint64, string, error)
- func (c *InProcessClient) Upload(x context.Context, id string, t Ticket, r io.Reader) error
- func (c *InProcessClient) Wait(x context.Context, id string, v uint64) (uint64, error)
- type IndexEntry
- type LimitError
- type Limits
- type LocalFile
- type MemoryBlobStore
- func (b *MemoryBlobStore) Delete(ctx context.Context, f, id string) error
- func (b *MemoryBlobStore) Open(ctx context.Context, f, id string) (io.ReadCloser, error)
- func (b *MemoryBlobStore) Put(ctx context.Context, f, id string, r io.Reader) (int64, error)
- func (b *MemoryBlobStore) Size(ctx context.Context, f, id string) (int64, error)
- type MetaStore
- type Metadata
- type Mutation
- type NotificationSource
- type Notifications
- type Options
- type PostgresMetaStore
- type Principal
- type QuarantinedRow
- type Quota
- type QuotaFunc
- type QuotaPolicy
- type Rejection
- type Replica
- func (r *Replica) Close() error
- func (r *Replica) Entries(patterns ...string) ([]Entry, error)
- func (r *Replica) Fetch(ctx context.Context, patterns ...string) (FetchResult, error)
- func (r *Replica) Remember(v IndexEntry)
- func (r *Replica) RetryRejected()
- func (r *Replica) ScanLocal() (map[string]LocalFile, error)
- func (r *Replica) Status() Status
- func (r *Replica) Sync(ctx context.Context) error
- type Role
- type Row
- type SQLiteMetaStore
- type Scope
- type Server
- func (s *Server) CancelUpload(ctx context.Context, p Principal, id, tid string) error
- func (s *Server) Changes(ctx context.Context, p Principal, id string, after uint64) (Delta, error)
- func (s *Server) ChangesPage(ctx context.Context, p Principal, id string, after, until uint64, page string) (Delta, error)
- func (s *Server) Client(p Principal) *InProcessClient
- func (s *Server) CollectGarbage(ctx context.Context) error
- func (s *Server) Commit(ctx context.Context, p Principal, id string, mut []Mutation) (Delta, error)
- func (s *Server) CompactTombstones(ctx context.Context) error
- func (s *Server) CreateFolder(ctx context.Context, p Principal, spec FolderSpec) (Folder, error)
- func (s *Server) DeleteFolder(ctx context.Context, p Principal, id string) error
- func (s *Server) Download(ctx context.Context, p Principal, id, blob string) (io.ReadCloser, error)
- func (s *Server) DownloadURLs(ctx context.Context, p Principal, id string, blobs []string) ([]string, error)
- func (s *Server) GetFolder(ctx context.Context, p Principal, id string) (Folder, error)
- func (s *Server) Grant(ctx context.Context, p Principal, id string, grantee Principal, role Role) error
- func (s *Server) Handler(auth Authenticator) http.Handler
- func (s *Server) ListFolders(ctx context.Context, p Principal) ([]Folder, error)
- func (s *Server) PrepareFolder(ctx context.Context, p Principal) (FolderChallenge, error)
- func (s *Server) RecoverUploads(ctx context.Context) error
- func (s *Server) Reserve(ctx context.Context, p Principal, id string, r UploadRequest) (Ticket, error)
- func (s *Server) Revoke(ctx context.Context, p Principal, id string, grantee Principal) error
- func (s *Server) Run(ctx context.Context, interval time.Duration) error
- func (s *Server) RunGC(ctx context.Context, interval time.Duration) error
- func (s *Server) SetLimits(ctx context.Context, p Principal, id string, l Limits) error
- func (s *Server) SetMaxWaitsPerPrincipal(n int)
- func (s *Server) Snapshot(ctx context.Context, p Principal, id string) (uint64, string, error)
- func (s *Server) Subscribe(ctx context.Context, p Principal, id string, after uint64) (<-chan Event, error)
- func (s *Server) Upload(ctx context.Context, p Principal, id string, provided Ticket, r io.Reader) error
- func (s *Server) Wait(ctx context.Context, p Principal, id string, after uint64) (uint64, error)
- type Status
- type Ticket
- type UploadRequest
- type Usage
- type WireRequest
Constants ¶
const ( MaxSnapshotRows = 1 << 23 MaxSnapshotBytes = 2 << 30 )
Decoder bounds. A snapshot is untrusted input from the authority or a URL.
const ChunkSize = 64 * 1024
const MaxGrants = 256
const MaxRequestBytes int64 = 1 << 50
const RowCost int64 = 256
const SnapshotBlobID = "snapshot"
SnapshotBlobID is the fixed blob key of a folder's packed snapshot. It is not a hex blob id, so no ticket or row can name it: Download, DownloadURLs and Upload stay denied for it. BlobStores must accept it alongside hex ids.
Variables ¶
var ( ErrWaitLimit = errors.New("too many outstanding waits; retry later") ErrDenied = errors.New("not found or access denied") ErrBusy = errors.New("path has an active upload") ErrExpired = errors.New("upload reservation expired") ErrQuota = errors.New("owner quota limit") ErrConflict = errors.New("version conflict") ErrInvalid = errors.New("invalid request") ErrKey = errors.New("incorrect folder key") ErrIntegrity = errors.New("encrypted data integrity failure") )
Functions ¶
func LoadIndex ¶ added in v0.4.0
func LoadIndex(db *sql.DB, fn func(IndexEntry) error) error
LoadIndex reads a replica's index.sqlite for diagnostics and tests. It validates exactly as attaching does.
func NormalizePath ¶
NormalizePath accepts portable, relative UTF-8 paths. It rejects rather than cleans traversal.
func OpenContent ¶
OpenContent only promises integrity on successful return. Callers must stage output before publishing it.
func ReadSnapshot ¶ added in v0.4.0
func ReadSnapshot(r io.Reader, folder string, version uint64, fn func(Row) error) (horizon uint64, err error)
ReadSnapshot streams a packed snapshot's rows to fn in path order. The header must name folder and version exactly; every row must be live, at or below version, and the stream must end exactly after its counted trailer. Rows are not authenticated here: their sealed metadata still needs OpenMetadata like rows from Changes. Errors from r pass through; framing and bound violations are ErrIntegrity.
func SealContent ¶
func SealMetadata ¶
func SealMetadata(k FolderKey, folder, pid string, m FileMetadata) ([]byte, error)
func SealedSize ¶
SealedSize includes the authenticated final empty chunk, even for an empty file.
Types ¶
type Account ¶
type Account struct{ Bytes, Rows, Folders int64 }
Account is a durable quota counter, updated with the selected folder delta.
type BlobStore ¶
type BlobStore interface {
Put(context.Context, string, string, io.Reader) (int64, error)
Open(context.Context, string, string) (io.ReadCloser, error)
Size(context.Context, string, string) (int64, error)
Delete(context.Context, string, string) error
}
BlobStore must create immutable objects, report actual stored sizes, and honor context cancellation. Objects are identified by server-generated folder/blob IDs. A presigned implementation can implement the same contract without an SDK here.
type BlobURLStore ¶ added in v0.4.0
type BlobURLStore interface {
DownloadURL(ctx context.Context, folder, id string, ttl time.Duration) (string, error)
}
BlobURLStore is the optional BlobStore extension for direct downloads.
type Client ¶
type Client interface {
PrepareFolder(context.Context) (FolderChallenge, error)
CreateFolder(context.Context, FolderSpec) (Folder, error)
Grant(context.Context, string, Principal, Role) error
Revoke(context.Context, string, Principal) error
DeleteFolder(context.Context, string) error
SetLimits(context.Context, string, Limits) error
ListFolders(context.Context) ([]Folder, error)
GetFolder(context.Context, string) (Folder, error)
Reserve(context.Context, string, UploadRequest) (Ticket, error)
Upload(context.Context, string, Ticket, io.Reader) error
CancelUpload(context.Context, string, string) error
Commit(context.Context, string, []Mutation) (Delta, error)
Changes(context.Context, string, uint64) (Delta, error)
Download(context.Context, string, string) (io.ReadCloser, error)
DownloadURLs(context.Context, string, []string) ([]string, error)
// Snapshot returns a packed snapshot's version and a short-lived bearer
// URL, or zero and "" when none is offered. Decode it with ReadSnapshot.
Snapshot(context.Context, string) (uint64, string, error)
Wait(context.Context, string, uint64) (uint64, error)
}
Client is an authenticated transport. Server authorization is independent of transport.
type ConflictError ¶
type ConflictError struct{ Paths []string }
ConflictError identifies only the paths whose bases are stale.
func (*ConflictError) Error ¶
func (e *ConflictError) Error() string
func (*ConflictError) Unwrap ¶
func (e *ConflictError) Unwrap() error
type Delta ¶
type DirectoryBlobStore ¶
type DirectoryBlobStore struct {
// contains filtered or unexported fields
}
func OpenDirectoryBlobStore ¶
func OpenDirectoryBlobStore(dir string) (*DirectoryBlobStore, error)
func (*DirectoryBlobStore) Close ¶
func (b *DirectoryBlobStore) Close() error
func (*DirectoryBlobStore) Delete ¶
func (b *DirectoryBlobStore) Delete(ctx context.Context, f, id string) error
func (*DirectoryBlobStore) Open ¶
func (b *DirectoryBlobStore) Open(ctx context.Context, f, id string) (io.ReadCloser, error)
type Entry ¶ added in v0.4.0
Entry is one path the replica tracks, read from local state without the network.
type FetchResult ¶ added in v0.4.0
type FetchResult struct {
// Fetched lists the placeholders this call downloaded; Bytes is their plaintext size.
Fetched []string
Bytes int64
// Present counts matched files that were already downloaded.
Present int
// Unmatched lists patterns that matched no tracked file.
Unmatched []string
Failed []Rejection
}
FetchResult reports one Fetch.
type FileMetadata ¶
func OpenMetadata ¶
func OpenMetadata(k FolderKey, folder string, row Row) (FileMetadata, error)
type Folder ¶
type Folder struct {
ID string
Owner Principal
Name, Description string
Limits Limits
KeyCheck []byte
Version uint64
Horizon uint64
Usage Usage
Role Role
}
func CreateFolder ¶
CreateFolder computes the salted check only after the authority names the folder. The key remains in this client helper for both transports.
type FolderChallenge ¶
type FolderRecord ¶
type FolderSpec ¶
type HTTPClient ¶
type HTTPClient struct {
BaseURL string
HTTP *http.Client
Headers http.Header
MaxResponseBytes int64
}
HTTPClient carries caller-provided authentication headers. Use HTTPS outside local tests.
func NewHTTPClient ¶
func NewHTTPClient(base string, headers http.Header) *HTTPClient
func (*HTTPClient) CancelUpload ¶
func (c *HTTPClient) CancelUpload(x context.Context, id, tid string) error
func (*HTTPClient) CreateFolder ¶
func (c *HTTPClient) CreateFolder(x context.Context, v FolderSpec) (Folder, error)
func (*HTTPClient) DeleteFolder ¶
func (c *HTTPClient) DeleteFolder(x context.Context, id string) error
func (*HTTPClient) Download ¶
func (c *HTTPClient) Download(x context.Context, id, blob string) (io.ReadCloser, error)
func (*HTTPClient) DownloadURLs ¶ added in v0.4.0
func (*HTTPClient) ListFolders ¶
func (c *HTTPClient) ListFolders(x context.Context) ([]Folder, error)
func (*HTTPClient) PrepareFolder ¶
func (c *HTTPClient) PrepareFolder(ctx context.Context) (FolderChallenge, error)
func (*HTTPClient) Reserve ¶
func (c *HTTPClient) Reserve(x context.Context, id string, r UploadRequest) (Ticket, error)
type InProcessClient ¶
func (*InProcessClient) CancelUpload ¶
func (c *InProcessClient) CancelUpload(x context.Context, id, tid string) error
func (*InProcessClient) CreateFolder ¶
func (c *InProcessClient) CreateFolder(x context.Context, v FolderSpec) (Folder, error)
func (*InProcessClient) DeleteFolder ¶
func (c *InProcessClient) DeleteFolder(x context.Context, id string) error
func (*InProcessClient) Download ¶
func (c *InProcessClient) Download(x context.Context, id, blob string) (io.ReadCloser, error)
func (*InProcessClient) DownloadURLs ¶ added in v0.4.0
func (*InProcessClient) ListFolders ¶
func (c *InProcessClient) ListFolders(x context.Context) ([]Folder, error)
func (*InProcessClient) PrepareFolder ¶
func (c *InProcessClient) PrepareFolder(ctx context.Context) (FolderChallenge, error)
func (*InProcessClient) Reserve ¶
func (c *InProcessClient) Reserve(x context.Context, id string, r UploadRequest) (Ticket, error)
type IndexEntry ¶
type IndexEntry struct {
Path, Local string
Hash [32]byte
Blob [16]byte
Version uint64
Size int64
Dev, Inode uint64
Mode uint32
Placeholder, RemoteOnly, Deleted, Awaiting, Directory bool
}
IndexEntry contains only authenticated local state, never sealed metadata. Path and Local share their string storage unless a case collision needs an alias.
type LimitError ¶
func (*LimitError) Error ¶
func (e *LimitError) Error() string
type MemoryBlobStore ¶
type MemoryBlobStore struct {
// contains filtered or unexported fields
}
func NewMemoryBlobStore ¶
func NewMemoryBlobStore() *MemoryBlobStore
func (*MemoryBlobStore) Delete ¶
func (b *MemoryBlobStore) Delete(ctx context.Context, f, id string) error
func (*MemoryBlobStore) Open ¶
func (b *MemoryBlobStore) Open(ctx context.Context, f, id string) (io.ReadCloser, error)
type MetaStore ¶
MetaStore serializes transactions across all server instances sharing it. A callback's error rolls back every change. Implementations must never expose state after a callback. For writes, load scoped records and owner Accounts, call Metadata.Prepare, then the callback and Metadata.Finish; persist changes atomically. With Paths selected, Files contains only those rows and FileUsage is the full cache. ReadOnly scopes use an independent snapshot and never persist the callback. Private account totals must not require account-wide rows.
type Metadata ¶
type Metadata struct {
Folders map[string]FolderRecord
Files map[string]map[string]Row
Tickets map[string]Ticket
Garbage map[string]Garbage
Accounts map[string]Account
// contains filtered or unexported fields
}
type NotificationSource ¶
type NotificationSource interface{ Notifications() *Notifications }
Authorities opening the same SQLite database in this process share wakes. The embedder must route cross-process notifications through its transport; external stores can provide NotificationSource for that purpose.
type Notifications ¶
type Notifications = notifications
Notifications is the process-local folder wake hub used by a metadata store.
func NewNotifications ¶
func NewNotifications() *Notifications
NewNotifications creates a hub shared by authorities using an external store.
type Options ¶
type Options struct {
Name, StateDir string
Debounce, RescanInterval, RetryInterval time.Duration
Ignore []string
Manual bool
// Moved reports that dir is the attached root renamed on the same volume.
Moved bool
// OnDemand keeps undownloaded files as empty, unreadable placeholders.
OnDemand bool
// Downloads bounds concurrent blob downloads; zero selects 8.
Downloads int
// MaxPlaceholders (default 20,000, breadth first) and MaxFolderPlaceholders
// (default 1,000 direct entries) bound placeholders; past either, a folder collapses.
MaxPlaceholders, MaxFolderPlaceholders int
// GuideName and Guide write a local-only guide at the root and in collapsed folders.
GuideName, Guide string
}
type PostgresMetaStore ¶ added in v0.2.0
type PostgresMetaStore struct {
// contains filtered or unexported fields
}
PostgresMetaStore is a MetaStore backed by one Postgres schema. Several processes may open the same schema. The caller owns db and must open it with the pgx stdlib driver (driver name "pgx"). Close does not close db. The pool must allow at least three connections: one stays on LISTEN and two remain for transactions. Unlimited (MaxOpenConnections 0) is accepted. Garbage collection claims a lease row and does not hold a pooled connection.
func OpenPostgresMetaStore ¶ added in v0.2.0
func OpenPostgresMetaStore(ctx context.Context, db *sql.DB, schema string) (*PostgresMetaStore, error)
OpenPostgresMetaStore creates schema when it is missing and starts the cross-process listener. An empty schema name uses "drivesync". schema must be a lowercase identifier. There is no migration path: the tables are the prototype shape and are created with IF NOT EXISTS. db must allow at least three connections. See PostgresMetaStore.
func (*PostgresMetaStore) Close ¶ added in v0.2.0
func (s *PostgresMetaStore) Close() error
func (*PostgresMetaStore) Notifications ¶ added in v0.2.0
func (s *PostgresMetaStore) Notifications() *Notifications
func (*PostgresMetaStore) Transaction ¶ added in v0.2.0
type QuarantinedRow ¶
type QuotaPolicy ¶
Zero limits mean unlimited; negative values are invalid. Bytes are sealed bytes.
type Replica ¶
type Replica struct {
// contains filtered or unexported fields
}
func (*Replica) Fetch ¶ added in v0.4.0
Fetch claims paths under syncMu, transfers without it, then validates the index version and inode again under the lock before publishing plaintext.
func (*Replica) Remember ¶
func (r *Replica) Remember(v IndexEntry)
func (*Replica) RetryRejected ¶
func (r *Replica) RetryRejected()
type SQLiteMetaStore ¶
type SQLiteMetaStore struct {
// contains filtered or unexported fields
}
SQLiteMetaStore stores one durable SQL row per folder, file and reservation.
func OpenSQLiteMetaStore ¶
func OpenSQLiteMetaStore(name string) (*SQLiteMetaStore, error)
func (*SQLiteMetaStore) Close ¶
func (s *SQLiteMetaStore) Close() error
func (*SQLiteMetaStore) Notifications ¶
func (s *SQLiteMetaStore) Notifications() *Notifications
func (*SQLiteMetaStore) Transaction ¶
type Scope ¶
type Scope struct {
TicketPaths []string
Principal Principal
Folder string
Create bool
GC bool
NoFiles bool
ReadOnly bool
Paths []string
Tickets []string
Garbage []string
Write bool
Owner bool
}
Scope describes the records needed by a metadata transaction. Folder operations select only Folder and its primary owner counter; an empty Folder lists visible definitions or creates one. GC is an explicit maintenance scope. A nonnil Paths selects only those file rows (empty means none); nil loads all unless NoFiles/GC is set. ReadOnly callbacks are read snapshots without accounting updates or a writer lock.
type Server ¶
type Server struct {
Meta MetaStore
Blobs BlobStore
Quotas QuotaPolicy
ReservationTTL time.Duration
Now func() time.Time
TombstoneTTL time.Duration
// SnapshotRows is the live-row count at which Snapshot offers a packed
// snapshot. Zero selects 1,000; negative disables snapshots.
SnapshotRows int
// contains filtered or unexported fields
}
func (*Server) CancelUpload ¶
func (*Server) ChangesPage ¶
func (s *Server) ChangesPage(ctx context.Context, p Principal, id string, after, until uint64, page string) (Delta, error)
ChangesPage returns at most 512 rows. The continuation carries the initial full/incremental decision and horizon; compaction cannot switch modes mid-pull. Full pages use path order so concurrent updates remain in the current set.
func (*Server) Client ¶
func (s *Server) Client(p Principal) *InProcessClient
func (*Server) CollectGarbage ¶
CollectGarbage expires tickets and durably queues and collects obsolete blobs. Run periodically even when no clients are active. Failed deletions remain charged.
func (*Server) CompactTombstones ¶
CompactTombstones selects on the read pool and retires bounded path batches.
func (*Server) CreateFolder ¶
func (*Server) DeleteFolder ¶
func (*Server) DownloadURLs ¶ added in v0.4.0
func (s *Server) DownloadURLs(ctx context.Context, p Principal, id string, blobs []string) ([]string, error)
DownloadURLs authorizes the entire request before issuing bearer URLs.
func (*Server) ListFolders ¶
func (*Server) PrepareFolder ¶
The stateless, principal-bound challenge keeps IDs authority-generated, without exposing an existence oracle or retaining unauthenticated drafts.
func (*Server) RecoverUploads ¶
RecoverUploads retires interrupted publications. A writing ticket records the publishing authority and a lease that is renewed while bytes flow. This authority retires its own ticket once that publication ends. Another authority retires it only after the lease expires. SQLite is one process per database file and uses the same rule.
func (*Server) Run ¶
Run recovers interrupted publications, then performs background collection and compaction. Postgres authorities share one schema: each pass claims the maintenance lease or skips. An in-flight upload is not a reason to wait. This process's publication is visible through wakes.live, and another authority's lease stays charged until it expires. SQLite remains one process per database file.
func (*Server) RunGC ¶
RunGC runs maintenance in a background worker owned by the embedder. Start it once per authority and cancel its context before closing stores.
func (*Server) SetMaxWaitsPerPrincipal ¶ added in v0.3.0
SetMaxWaitsPerPrincipal raises or lowers the long-poll cap for every principal on this authority. Zero restores the default.
func (*Server) Snapshot ¶ added in v0.4.0
Snapshot returns a short-lived URL for the folder's packed snapshot and the version it describes. Zero and an empty URL mean none is offered: the folder is small, the blob store cannot sign URLs, or building or signing failed. The snapshot may be older than the folder; read Changes after Version.
func (*Server) Subscribe ¶
func (s *Server) Subscribe(ctx context.Context, p Principal, id string, after uint64) (<-chan Event, error)
Subscribe closes after cancellation or revocation, with a terminal error event.
type Ticket ¶
type Ticket struct {
AuthEpoch string
SessionID string
ID, FolderID, BlobID, PathID string
Principal Principal
BaseVersion uint64
SealedSize, ReservedBytes, ReservedFiles int64
ReservedRows int64
Expires time.Time
Uploaded bool
Writing bool
// Writer is the process publishing this ticket. Lease is when that claim
// expires. Recovery and garbage collection treat a writing ticket as live
// until Lease, including across processes. A zero Lease is already expired.
Writer string
Lease time.Time
}
type UploadRequest ¶
type UploadRequest struct {
// SessionID identifies one replica state directory (random 128-bit hex).
// Only the same principal/session can replace its previous ticket; empty or
// different sessions get ErrBusy. This is contention control, not a grant.
SessionID string
PathID string
BaseVersion uint64
SealedSize int64
MetadataBytes int64
}
type Usage ¶
type Usage struct{ Bytes, Files, Rows, Reserved, ReservedFiles, ReservedRows, GarbageRows int64 }
type WireRequest ¶
Source Files
¶
- accounting.go
- collapsed.go
- compaction.go
- creation.go
- crypto.go
- dialect.go
- directory_scan.go
- download.go
- exact_reader.go
- guide.go
- http.go
- index_entry.go
- index_store.go
- lock_unix.go
- maintenance.go
- move.go
- notifications.go
- ondemand.go
- pagination.go
- placeholder.go
- postgres.go
- pull_index.go
- reconcile.go
- rename_linux.go
- rename_unix.go
- replica.go
- root.go
- scan_hash.go
- scan_hash_linux.go
- scan_hash_unix.go
- server.go
- snapshot.go
- snapshot_client.go
- store.go
- transfer.go
- types.go
- unicode.go
- watcher_linux.go