listcache

package
v0.3.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package listcache keeps whole-library listings encoded on disk, so a protocol whose clients download a library in one response (Xtream's get_vod_streams) streams a file instead of reading, authorizing, signing and encoding the library again.

A listing fills a slot (what it lists, for whom, under which origin) and is stamped with its State: an exact stamp of every input but catalogue content, the catalogue generation it was read at, and whether the viewer's policy judges titles on their facts. A listing is served only to a request with the same stamp. Catalogue writes are bounded staleness: a listing read before one is served for up to Stale, and rebuilt behind the response, unless its policy is Judged; then the write retires it at once.

With no servable listing a request follows a build as it is written: the one in flight for its slot when that build reads what the request must see, otherwise one it starts. A follower receives bytes as the build writes them, so it never waits longer than encoding the library itself.

Listings are stamped with a process's generations and none outlives it: the directory is emptied when a store opens, and its size is capped.

Index

Constants

View Source
const (
	// Stale is the longest a listing is served after it was read.
	Stale = 30 * time.Minute
	// Revalidate is the age, or a catalogue write, after which a served
	// listing is rebuilt behind the response.
	Revalidate = 2 * time.Minute
	// RenewEvery is how often a listing's artwork is re-armed for one
	// credential. Image grants live ten minutes.
	RenewEvery = 4 * time.Minute
	// Idle drops a listing nobody fetched for this long.
	Idle = 24 * time.Hour
)

Variables

This section is empty.

Functions

func RenewImages

func RenewImages(ctx context.Context, e *Entry, renewer frontend.ImagePageRenewer, credential string, device frontend.Device) error

RenewImages re-arms e's artwork for credential and device.

Types

type Entry

type Entry struct {
	// contains filtered or unexported fields
}

Entry is one listing: written by its build, then served until it is retired. Its files are removed once it is retired and nobody reads them.

func (*Entry) KeepImages

func (e *Entry) KeepImages(items []frontend.ImageBatchItem) error

KeepImages records one page's signed artwork beside the listing, so its image URLs can be re-armed for another credential, or once the grants SignPage issued expire. Pages may be signed concurrently.

func (*Entry) Write

func (e *Entry) Write(p []byte) (int, error)

Write appends to the listing body and wakes its followers.

type Request

type Request struct {
	Slot  string
	State State
	// Owner names the requesting credential (its device). A listing's
	// artwork is renewed for each owner at most once per RenewEvery.
	Owner string
	// Build encodes the listing as this request would, writing its body to
	// the entry and its artwork with KeepImages. It runs at most once,
	// after the request may have returned, under a context of its own.
	Build func(context.Context, *Entry) error
	// Renew re-arms a listing's artwork for Owner. Nil skips it.
	Renew func(context.Context, *Entry) error
}

Request is one list request.

type State

type State struct {
	// Stamp covers every input but catalogue content: equal stamps mean
	// the same policy, library and encoding.
	Stamp string
	// Catalog is the catalogue generation; Judged makes it exact.
	Catalog uint64
	Judged  bool
	At      time.Time
}

State is what a listing was read under, or what a request needs.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is one frontend's listings.

func New

func New(dir string) *Store

New opens a store in dir, emptying it. It returns nil, and callers encode every listing, when dir is empty or unusable.

func (*Store) Busy

func (s *Store) Busy() int

Busy counts builds, compressions and Go work in flight.

func (*Store) Close

func (s *Store) Close()

Close stops builds and waits for the store's background work.

func (*Store) Go

func (s *Store) Go(fn func(context.Context))

Go runs fn behind a response, counted in Busy and stopped by Close.

func (*Store) Now

func (s *Store) Now() time.Time

Now is the store's clock, for request states.

func (*Store) Prepare

func (s *Store) Prepare(req Request)

Prepare builds req's listing behind the response when no fresh listing or matching build exists and the slot's last speculative build was fetched (or is a day old).

func (*Store) Serve

func (s *Store) Serve(w http.ResponseWriter, r *http.Request, req Request) bool

Serve answers req from a listing, or by following its build. It reports false, having written nothing, when the store cannot; the caller then encodes the listing itself.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL