Documentation
¶
Overview ¶
Package drivesync shares encrypted folders through ordinary local directories. Create a folder with a name and a key, then attach it wherever files are needed.
Index ¶
- Variables
- type Authenticator
- type BlobStore
- type BlobURLStore
- type Client
- func (c *Client) CreateFolder(ctx context.Context, spec FolderSpec, key FolderKey) (Folder, error)
- func (c *Client) DeleteFolder(ctx context.Context, id string) error
- func (c *Client) GetFolder(ctx context.Context, id string) (Folder, error)
- func (c *Client) Grant(ctx context.Context, id string, p Principal, role Role) error
- func (c *Client) ListFolders(ctx context.Context) ([]Folder, error)
- func (c *Client) Revoke(ctx context.Context, id string, p Principal) error
- func (c *Client) SetLimits(ctx context.Context, id string, limits Limits) error
- type DirectoryBlobStore
- func (b *DirectoryBlobStore) Close() error
- func (b *DirectoryBlobStore) Delete(ctx context.Context, folder, id string) error
- func (b *DirectoryBlobStore) Open(ctx context.Context, folder, id string) (io.ReadCloser, error)
- func (b *DirectoryBlobStore) Put(ctx context.Context, folder, id string, r io.Reader) (int64, error)
- func (b *DirectoryBlobStore) Size(ctx context.Context, folder, id string) (int64, error)
- type Entry
- type FetchResult
- type Folder
- type FolderKey
- type FolderSpec
- type LimitError
- type Limits
- type MemoryBlobStore
- func (b *MemoryBlobStore) Delete(ctx context.Context, folder, id string) error
- func (b *MemoryBlobStore) Open(ctx context.Context, folder, id string) (io.ReadCloser, error)
- func (b *MemoryBlobStore) Put(ctx context.Context, folder, id string, r io.Reader) (int64, error)
- func (b *MemoryBlobStore) Size(ctx context.Context, folder, id string) (int64, error)
- type MetaStore
- type Options
- type Principal
- type Quota
- type QuotaFunc
- type QuotaPolicy
- type Rejection
- type Replica
- type Role
- type Server
- type ServerOptions
- type Status
- type Usage
Constants ¶
This section is empty.
Variables ¶
var ( ErrDenied = engine.ErrDenied ErrBusy = engine.ErrBusy ErrExpired = engine.ErrExpired ErrQuota = engine.ErrQuota ErrConflict = engine.ErrConflict ErrInvalid = engine.ErrInvalid ErrKey = engine.ErrKey ErrIntegrity = engine.ErrIntegrity ErrWaitLimit = engine.ErrWaitLimit )
Functions ¶
This section is empty.
Types ¶
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 holds immutable sealed blobs. Keys are authority-generated IDs. Put streams bytes, Size reports actual stored bytes, and Delete is idempotent (os.ErrNotExist is also accepted). Implementations must honor cancellation. Put must publish only after clean EOF; a reader error must discard staging. Besides hexadecimal blob IDs, stores must accept the reserved key "snapshot" for a folder's replaceable packed file list. The authority deletes it before replacement; it is derived data and is excluded from quota.
type BlobURLStore ¶ added in v0.4.0
type BlobURLStore interface {
DownloadURL(ctx context.Context, folder, id string, ttl time.Duration) (string, error)
}
BlobURLStore is an optional BlobStore extension. When the authority's store implements it, an authorized download answers with a URL valid for ttl that the replica fetches directly, so blob bytes skip the authority. The URL is a bearer capability for one sealed blob: it must name only that blob, expire, and never appear in errors or logs. Implementations also sign the reserved key "snapshot" for packed file lists.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client manages folders through HTTP or an authenticated in-process authority. Its replication and encryption protocol is private to the library.
func NewHTTPClient ¶
NewHTTPClient connects to an authority. Use HTTPS outside local tests.
func NewHTTPClientWithClient ¶ added in v0.4.1
NewHTTPClientWithClient is NewHTTPClient sending authority requests through client, such as one whose transport adds credentials that rotate. Blob transfers to presigned URLs never use it, so those credentials stay off blob hosts. A nil client behaves as NewHTTPClient.
func (*Client) CreateFolder ¶
CreateFolder computes the key check locally; the key is never sent to the authority. Keep it securely and supply the same key to every attachment.
type DirectoryBlobStore ¶
type DirectoryBlobStore struct {
// contains filtered or unexported fields
}
DirectoryBlobStore streams sealed bytes to a durable local directory.
func OpenDirectoryBlobStore ¶
func OpenDirectoryBlobStore(path string) (*DirectoryBlobStore, error)
func (*DirectoryBlobStore) Close ¶
func (b *DirectoryBlobStore) Close() error
func (*DirectoryBlobStore) Delete ¶
func (b *DirectoryBlobStore) Delete(ctx context.Context, folder, id string) error
func (*DirectoryBlobStore) Open ¶
func (b *DirectoryBlobStore) Open(ctx context.Context, folder, id string) (io.ReadCloser, error)
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 FolderKey ¶
type FolderKey [32]byte
func NewFolderKey ¶
func NewFolderKey() FolderKey
func ParseFolderKey ¶
ParseFolderKey imports a 64-character hex encoding of a random 256-bit key. Passphrases and hashes of passphrases are not suitable folder keys.
type FolderSpec ¶
type LimitError ¶
type LimitError struct {
Limit string
Maximum, Requested int64
// contains filtered or unexported fields
}
LimitError identifies a folder limit that rejected an operation.
func (*LimitError) Error ¶
func (e *LimitError) Error() string
func (*LimitError) Unwrap ¶
func (e *LimitError) Unwrap() error
type Limits ¶
type Limits struct{ MaxFileBytes, MaxTotalBytes, MaxFiles, MaxRows int64 }
Limits bounds sealed bytes, live entries and retained rows. Zero is unlimited except MaxRows, which selects a bounded safety budget. Sharing requires explicit positive byte, row and file caps. Bytes include encryption and metadata overhead.
type MemoryBlobStore ¶
type MemoryBlobStore struct {
// contains filtered or unexported fields
}
MemoryBlobStore is useful for tests and small in-process deployments.
func NewMemoryBlobStore ¶
func NewMemoryBlobStore() *MemoryBlobStore
func (*MemoryBlobStore) Delete ¶
func (b *MemoryBlobStore) Delete(ctx context.Context, folder, id string) error
func (*MemoryBlobStore) Open ¶
func (b *MemoryBlobStore) Open(ctx context.Context, folder, id string) (io.ReadCloser, error)
type MetaStore ¶
type MetaStore struct {
// contains filtered or unexported fields
}
MetaStore is the authority metadata store. Metadata storage is concrete because a custom transaction interface would expose private replication/accounting records. BlobStore and QuotaPolicy remain the pluggable extension points.
func OpenPostgresMetaStore ¶ added in v0.2.0
OpenPostgresMetaStore uses db, which the caller owns and must open with the pgx stdlib driver (driver name "pgx"). schema is created when missing; an empty schema name uses "drivesync". Close does not close db. Several authority processes may share one schema. db must allow at least three connections: one stays on LISTEN and two remain for transactions. A limit of one or two is rejected; unlimited (zero) is accepted. Garbage collection claims a lease row in the schema (a holder id and an expiry, renewed during the pass) and does not hold a pooled connection. A frozen holder stops blocking after the lease expires.
func OpenSQLiteMetaStore ¶
type Options ¶
type Options struct {
Name, StateDir string
Debounce, RescanInterval, RetryInterval time.Duration
Ignore []string
Manual bool
// Moved tells Attach this directory is the same root renamed on the same
// volume. A matching marker token and inode keep the replica index.
Moved bool
// OnDemand lists every remote file but downloads one only when Fetch asks
// for it. Until then the file is an empty placeholder with no permissions,
// so opening it fails instead of reading wrong bytes. Downloaded files stay
// downloaded and sync both ways.
OnDemand bool
// Downloads bounds concurrent blob downloads; zero selects 8.
Downloads int
// MaxPlaceholders bounds the placeholders an on-demand replica creates,
// breadth first; zero selects 20,000. MaxFolderPlaceholders bounds one
// folder's direct placeholders; zero selects 1,000. A folder past either
// limit is collapsed: its contents stay listed in the index and its guide,
// and Fetch still downloads them.
MaxPlaceholders, MaxFolderPlaceholders int
// GuideName and Guide, when both are set on an on-demand replica, write a
// local-only file named GuideName at the root and in each collapsed folder:
// Guide followed by that folder's entries not downloaded here. It never syncs.
GuideName, Guide string
}
Options configures a local replica. StateDir must be dedicated and outside all synced trees; its default is a folder/root directory in the user's cache. Manual disables automatic sync; Sync remains available explicitly.
type Principal ¶
type Principal struct{ Tenant, Subject string }
Principal is an opaque identity supplied by the embedding authenticator.
type Quota ¶
type Quota struct{ MaxTotalBytes, MaxFolders, MaxFileBytes, MaxFiles int64 }
Quota is an owner's plan. MaxFiles bounds retained rows across their folders.
type Replica ¶
type Replica struct {
// contains filtered or unexported fields
}
Replica keeps an encrypted folder in an ordinary local directory.
func Attach ¶
func Attach(ctx context.Context, c *Client, id string, key FolderKey, dir string, opts Options) (*Replica, error)
Attach uses ctx for setup. The replica remains active until Close.
func (*Replica) Entries ¶ added in v0.4.0
Entries lists tracked paths from local state, without the network. A pattern is an exact path, a folder (its whole subtree), or a glob with * ? [] and **. No patterns lists everything. Results are sorted by path.
func (*Replica) Fetch ¶ added in v0.4.0
Fetch downloads the on-demand placeholders matching patterns in parallel and returns once they are ordinary files. Downloaded files stay downloaded.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server authorizes every operation independently of transport authentication.
func (*Server) Run ¶
Run recovers interrupted uploads and maintains expired reservations, garbage and tombstones until ctx is cancelled. SQLite metadata is one authority process per database file. Postgres metadata can be shared: an upload lease is renewed while bytes flow, and recovery retires only an expired lease. Cancel and join Run before closing the stores.
type ServerOptions ¶
type ServerOptions struct {
Quotas QuotaPolicy
ReservationTTL, TombstoneTTL, GCInterval time.Duration
Clock func() time.Time
// MaxWaitsPerPrincipal caps concurrent long-polls for one principal.
// Zero keeps the default of 256. Embedders that share one principal
// across many clients set this higher.
MaxWaitsPerPrincipal int
// SnapshotRows is the live-row count at which a folder whose blob store
// signs URLs offers new replicas a packed snapshot. Zero selects 1,000;
// negative disables snapshots.
SnapshotRows int
}
ServerOptions configures authority policy and maintenance before serving. Zero TTLs select defaults: five-minute reservations and 30-day tombstones. A negative TombstoneTTL disables compaction. GCInterval defaults to one second.
type Status ¶
type Status struct {
PendingUpBytes, PendingDownBytes int64
Conflicts []string
Rejected []Rejection
Quarantined []string
LastSync time.Time
Errors []string
// Placeholders counts on-demand files not downloaded here, and
// PlaceholderBytes their plaintext size.
Placeholders, PlaceholderBytes int64
}
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
drivesync
command
drivesync is a small manual-testing CLI.
|
drivesync is a small manual-testing CLI. |
|
internal
|
|
|
embedpg
Package embedpg starts one embedded Postgres per process for tests.
|
Package embedpg starts one embedded Postgres per process for tests. |
|
engine
Package engine implements the private encrypted replication protocol.
|
Package engine implements the private encrypted replication protocol. |
|
testkit
Package testkit opens the metadata store selected by DRIVESYNC_STORE.
|
Package testkit opens the metadata store selected by DRIVESYNC_STORE. |