check

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package check is bweb's loopback checker, bweb check (docs/check.md): a small HTTP service on the node's own loopback that answers whether servers serve a site, for a program on the same node that must decide which addresses to hand out for it (bdns's renderer). Each verdict is the serving challenge (package challenge) run by this node itself, against the site's proven content read through the node's bstore gateway. A verdict from another node is never taken.

GET /v1/check challenges exact addresses of a site; GET /v1/advertised challenges the servers advertising it, each at the addresses its URL resolves to. Verdicts are kept a short time (at most 60 s).

Index

Constants

View Source
const (
	// MaxCache is the longest a verdict stands.
	MaxCache = 60 * time.Second
)

Bounds. Fixed, not configured: they keep an answer inside the renderer's own 30 s timeout.

Variables

This section is empty.

Functions

func Listen

func Listen(addr string) (net.Listener, error)

Listen listens on addr, a loopback address and a port, and refuses any other: the checker answers its own node only. The address bound is held to the same rule.

Types

type Answer

type Answer struct {
	Site    string   `json:"site"`
	Servers []Server `json:"servers"`
}

Answer is the body of a 200.

type Checker

type Checker struct {
	// Ref is where a challenge reads the site's content: the node's bstore
	// gateway (web.S3Store).
	Ref challenge.Reference
	// Headers proves a site token's and an advertisement's block.
	Headers chaintracker.ChainTracker
	// Lookup asks the engine's ls_bweb a question.
	Lookup func(ctx context.Context, query map[string]string) ([]lookup.Output, error)
	// Resolve answers the addresses a host name resolves to; nil is the
	// system's resolver.
	Resolve func(ctx context.Context, host string) ([]string, error)
	// Token, when set, is the bearer token every request must carry.
	Token string

	// Engine and AskTTL keep the engine carrying each checked site's
	// topics, one ask a site (bweb-check-<site>); a zero AskTTL asks
	// nothing. Keep is web.KeepAsking unless set.
	Engine string
	AskTTL time.Duration
	Keep   func(ctx context.Context, a *engineask.Asker, after <-chan struct{}) <-chan struct{}

	// CacheTTL is how long a verdict stands, at most MaxCache.
	CacheTTL time.Duration
	// MaxChecks bounds the challenges run at once, MaxAddrs the addresses
	// of one /v1/check, MaxServers the entries one /v1/advertised
	// challenges.
	MaxChecks, MaxAddrs, MaxServers int
	// Samples and FirstByte are each challenge's reads and the bound on a
	// read's first byte.
	Samples   int
	FirstByte time.Duration
	// Private are the ranges a challenge may dial although they are not
	// public addresses (challenge.PublicAddr).
	Private []*net.IPNet

	Now     func() time.Time
	Logf    func(format string, args ...any)
	Metrics *Metrics
	// contains filtered or unexported fields
}

Checker answers the checker's two requests. Set the fields, then serve Handler and call Run.

func (*Checker) Handler

func (c *Checker) Handler() http.Handler

Handler serves GET /v1/check and GET /v1/advertised.

func (*Checker) Run

func (c *Checker) Run(ctx context.Context)

Run keeps the checker's state trimmed until ctx ends: verdicts and resolutions past their time, the asks of sites nobody has asked about for an ask's lifetime, and unknown sites whose ask has run its lifetime. The asks it keeps alive end with ctx.

type Metrics

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

Metrics are the checker's counters. Every method is safe on a nil Metrics.

By the USE method: utilization (challenges in flight against their bound), saturation (the wait for a challenge slot), errors (answers by status, 503s, challenges by result).

func NewMetrics

func NewMetrics(reg prometheus.Registerer) *Metrics

NewMetrics registers the checker's metrics with reg.

type Server

type Server struct {
	Address string `json:"address"`
	Port    int    `json:"port"`
	URL     string `json:"url"`
	Pass    bool   `json:"pass"`
	// Unjudged is a verdict the checker could not make for this address
	// (its own store failed during the challenge, or the challenge ran out
	// of the checker's time): Pass is false, and nothing is kept.
	Unjudged bool   `json:"unjudged"`
	Checked  string `json:"checked"`
	Samples  int    `json:"samples"`
	Passed   int    `json:"passed"`
	Reason   string `json:"reason"`
}

Server is one server's verdict, as an answer lists it.

Jump to

Keyboard shortcuts

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