Documentation
¶
Overview ¶
Package challenge is bweb's serving challenge (docs/spec.md section 7): a handful of ordinary reads of a site at a server's advertised address, each held to what the challenger's own store says the object is. The store is a bstore reader that proves every answer before it gives it (for a publisher, its own gateway), so what a sample is compared with is the site's proven content.
A challenger makes one Challenge per site (New, from the site's record, or the struct itself), calls Prepare once, and then Run once per server, with the URL of that server's advertisement (siterec.Advertisement.URL). bweb's hosting race and any other program that audits a site's servers run the same code.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoKeys = errors.New("the site's bucket holds no object to sample")
ErrNoKeys is a site whose bucket holds no object a path answers: there is nothing to sample.
Functions ¶
func NewClient ¶
NewClient is the HTTP client a challenge reads with: a redirect is read as the answer it is, and, unless private, a loopback, private, link-local, shared, reserved or NAT64 address is refused before anything is sent.
func PublicAddr ¶ added in v0.7.0
PublicAddr reports an address NewClient(false) dials: not loopback, private, link-local, multicast, unspecified, shared, reserved for protocols or benchmarking, or NAT64. A caller with a client of its own (a dialer pinned to one address, say) holds its addresses to the same rule with it.
Types ¶
type Answer ¶
type Answer struct {
Status int
Header http.Header // Content-Type, Content-Length, ETag, Last-Modified, Content-Range, Accept-Ranges
Root string // the object's closure root, hex, when the store names it
Body io.ReadCloser
}
Answer is a store's answer to one read. Body is never nil; the caller closes it. A Body that is an io.WriterTo is written by it: the store fetches and checks as it writes, and an error from it before its first byte means the read failed with nothing sent.
type Challenge ¶
type Challenge struct {
Ref Reference
Bucket string // the bucket's S3 name at the store
Host string // the site's host name a sample asks for
Index string // the index document
Error string // the error document's key, or empty
// Samples is how many reads a challenge makes, the directory and
// absent-key reads among them.
Samples int
// FirstByte is the most a sample's first byte may take, from the
// request to the first byte of the answer.
FirstByte time.Duration
// Private allows a server at a loopback, private or link-local
// address. Off, such an address is refused before anything is sent: an
// advertisement is anyone's, and its URL must not point a challenger
// at its own network.
Private bool
// Budget is the most one server's challenge may take; zero is a bound
// from the reads and the first-byte bound (budget).
Budget time.Duration
// Client is the HTTP client samples are read with; nil is NewClient
// with Private. A client of the caller's own is used as it is: Private
// then has no effect, and the client's own dialer, timeouts and
// redirect policy apply.
Client *http.Client
// contains filtered or unexported fields
}
Challenge is one site's serving challenge, run against any number of servers.
func New ¶
func New(ref Reference, site *siterec.Site, samples int, firstByte time.Duration) (*Challenge, error)
New is the challenge of a site's record: its bucket, its first host name, its index and error documents. samples is how many reads it makes and firstByte the bound on each one's first byte (a race takes both from its terms, siterec.Terms CheckC and FirstByte).
func (*Challenge) Prepare ¶
Prepare reads the site's keys from the store. It is called once, before any server is challenged, so every server is sampled from the same keys.
func (*Challenge) Run ¶
Run challenges the server at base, an advertisement's URL: the directory path and an absent key once each when there is room for them, and drawn keys for the rest. It needs Prepare. A sample the challenger itself could not judge (its store did not answer) is an error, not a failure: the server is not blamed for it.
type Reference ¶
type Reference interface {
// List answers a page of the bucket's objects in key order, after the
// key given, and whether there are more.
List(ctx context.Context, bucket, after string) ([]Object, bool, error)
// Read reads one object (its headers alone with head), with the
// request's Range and conditional headers in cond.
Read(ctx context.Context, bucket, key string, head bool, cond http.Header) (*Answer, error)
}
Reference is where a challenger reads what a site's objects are: its own store. bweb's store (a bstore gateway, over S3 or in process) is one.