segment

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package segment serves documents to readers a few pages at a time, each segment sealed for a key pair the reader makes for that one request (docs/spec.md §3.6, docs/design.md §3.30). A reader that forgets its private key after opening the segment leaves nothing that opens it: what was sent stays sealed even if the server's keys, the TLS keys or the reader's session are taken later.

The request is a POST of a JSON Request; the answer is the single-file form of the segment of Handler.Pages pages that holds the page asked for, sealed for the request's key (bdf.NewECDHLock). @bdfkit/core's SegmentLoader is the reader's side.

Index

Constants

View Source
const Pages = 10

Pages is the number of pages of a segment unless Handler.Pages says.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	// Open returns the document a request is for, once it has checked that
	// the reader may read it (the application's own login and rights). An
	// error that is a *StatusError answers with its status, fs.ErrNotExist
	// 404, fs.ErrPermission 403, others 500.
	Open func(r *http.Request) (*bdf.Reader, error)
	// Allow, if set, is asked before a segment is sent, for rules on pages
	// (a sample of the first pages, how fast pages are read). Its error
	// answers as one of Open does.
	Allow func(r *http.Request, s bdf.Segment) error
	// Pages is the number of pages of a segment (0: Pages).
	Pages int
	// Log, if set, is given the errors answered with 500.
	Log func(r *http.Request, err error)
}

Handler answers requests for segments.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Request

type Request struct {
	// Key is the reader's public key for this request: an uncompressed
	// P-256 point (65 bytes, base64 in JSON).
	Key []byte `json:"key"`
	// View and Page name a page (0-based) the segment is to hold; an empty
	// View is the document's first view.
	View string `json:"view,omitempty"`
	Page int    `json:"page"`
	// Have lists the pages the reader holds from earlier segments, whose
	// parts are left out.
	Have []bdf.Segment `json:"have,omitempty"`
}

Request is the JSON body of a request for a segment.

type StatusError

type StatusError struct {
	Status int
	Err    error
}

StatusError is an error of Handler.Open or Handler.Allow that answers with an HTTP status of its own: 401 for a reader who is not logged in, 429 for one who reads too fast.

func (*StatusError) Error

func (e *StatusError) Error() string

func (*StatusError) Unwrap

func (e *StatusError) Unwrap() error

Jump to

Keyboard shortcuts

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