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 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 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.
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 (*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 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
}
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.
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
}
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.
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. |