Documentation
¶
Overview ¶
Package blobxfer moves file contents between a device and its hub over HTTP, named by their SHA-256 (ADR-0018, docs/specs/sync-protocol.md#blobs): the hub's handler for /sync/blobs/{hash}, and the device's client. Neither end holds a blob in memory, and each checks the hash of what it receives before keeping it.
Index ¶
Constants ¶
const DefaultMaxSize = 1 << 30
DefaultMaxSize is the hub's limit on one blob unless notesd --hub-max-blob sets another: 1 GiB.
Variables ¶
var ErrNotFound = errors.New("blobxfer: the hub has no such blob")
ErrNotFound means the hub has no content for the hash (404).
var ErrTooBig = errors.New("blobxfer: the blob is larger than this device takes")
ErrTooBig is a download longer than the client's MaxSize.
ErrUnauthorized means the hub refused the device token (401): it was revoked, or never valid.
Functions ¶
func Handler ¶
func Handler(store *blobs.Store, maxSize int64, readable func(ctx context.Context, hash string) (bool, error), uploaded func(ctx context.Context, hash string)) http.Handler
Handler serves HEAD, GET and PUT of one blob from store, for requests the hub has already authenticated; it reads the hash with r.PathValue("hash"), so it is mounted on a pattern ending in {hash}. readable reports whether GET and HEAD may hand out a hash: the hub passes store.DB.HasContent. PUT refuses blobs over maxSize. Task card T-0029.
Types ¶
type Client ¶
type Client struct {
// Base is the hub's URL; a blob's URL is Base with "/sync/blobs/<hash>"
// appended to its path.
Base *url.URL
// Token is the device token, sent as "Authorization: Bearer <token>".
Token string
// HTTP sends the requests; nil means http.DefaultClient.
HTTP *http.Client
// Store is the device's blob store.
Store *blobs.Store
// Dir holds partial downloads as <hash>.part, so a broken download
// resumes; it must exist.
Dir string
// MaxSize is the largest blob a download takes before it gives up, so
// a hub cannot fill the device's disk; 0 means DefaultMaxSize.
MaxSize int64
}
Client moves blobs between a device's store and its hub.
func (*Client) Download ¶
Download fetches blob hash from the hub into Store, keeping it only if its content hashes to hash (an error matching blobs.ErrCorrupt otherwise). The bytes arrive in Dir/<hash>.part; when a download breaks, the next attempt asks for the rest with Range, up to 3 attempts in one call, and a later call resumes too. A blob Store already has is not fetched. Task card T-0029.
func (*Client) DownloadAll ¶
DownloadAll downloads each hash, at most 4 at a time, and returns every failure joined (errors.Join), after all have run. Task card T-0029.