streaming

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 21 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

Index

Constants

View Source
const (
	HandlerPrefix = "/blobs/"
	ReadinessPath = "/artifact-streaming/readyz"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type LocalRangeStore

type LocalRangeStore interface {
	OpenRange(ctx context.Context, d digest.Digest, requested httprange.Range) (io.ReadCloser, int64, error)
}

type MetricsHooks

type MetricsHooks struct {
	OnRequest   func(source, outcome string, duration time.Duration, bytes int64)
	OnFirstByte func(source string, duration time.Duration)
	OnInflight  func(source string, delta int)
	OnReject    func(reason string)
}

type Options

type Options struct {
	URLPolicy              URLPolicy
	ResolveCanonicalOrigin func(OriginURL) (OriginURL, bool)

	// PeerLookupTimeout, PeerAttemptTimeout, and MaxPeerAttempts use defaults when zero.
	PeerLookupTimeout  time.Duration
	PeerAttemptTimeout time.Duration
	MaxPeerAttempts    int

	SelfPeerID   ifaces.NodeID
	StartupGated bool
	Logger       *slog.Logger
	Metrics      MetricsHooks

	// Cache, when set, absorbs reads no larger than MaxCachedRangeBytes.
	// OverlayBD index reads are tiny and every node wants the same ones, so
	// caching them is what lets peers answer instead of origin.
	Cache               RangeCache
	MaxCachedRangeBytes int64
	// OnCached announces that this node can now serve ranges of d. Peers
	// discover range sources the same way they discover complete blobs, so
	// without this a cached range stays invisible to the swarm.
	OnCached func(d digest.Digest)
}

type OriginClient

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

OriginClient fetches exact ranges from validated signed origin URLs.

func NewOriginClient

func NewOriginClient(policy URLPolicy, options ...OriginOption) *OriginClient

NewOriginClient constructs a client with independent origin concurrency.

func (*OriginClient) FetchRange

func (c *OriginClient) FetchRange(ctx context.Context, origin OriginURL, requested httprange.Range) (io.ReadCloser, int64, string, error)

FetchRange fetches exactly requested from origin and returns the complete object size reported by Content-Range.

type OriginOption added in v0.26.0

type OriginOption func(*OriginClient)

func WithOriginTransferMetrics added in v0.26.0

func WithOriginTransferMetrics(bytes func(int64), activity func(int)) OriginOption

WithOriginTransferMetrics observes actual range bytes and active origin reads.

type OriginRangeFetcher

type OriginRangeFetcher interface {
	FetchRange(ctx context.Context, origin OriginURL, requested httprange.Range) (io.ReadCloser, int64, string, error)
}

type OriginStatusError

type OriginStatusError struct {
	StatusCode int
	RetryAfter time.Duration
}

OriginStatusError reports a non-206 response from the signed origin.

func (*OriginStatusError) Error

func (e *OriginStatusError) Error() string

type OriginURL

type OriginURL struct {
	Raw       string
	Digest    digest.Digest
	Canonical bool
}

OriginURL is a validated origin capability extracted from an OverlayBD request. Raw is retained for the outbound request and must never be logged.

func OriginURLFromRequest

func OriginURLFromRequest(r *http.Request, policy URLPolicy) (OriginURL, error)

OriginURLFromRequest reconstructs and validates the URL embedded by OverlayBD after /blobs/. RequestURI is used so signed query bytes are not decoded and re-encoded.

func ParseOriginURL

func ParseOriginURL(raw string, policy URLPolicy) (OriginURL, error)

ParseOriginURL validates a raw absolute origin URL and extracts its blob digest without rewriting the signed query.

type PeerRangeFetcher

type PeerRangeFetcher interface {
	FetchRangeFromPeer(ctx context.Context, peerAddr string, d digest.Digest, requested httprange.Range) (io.ReadCloser, int64, string, error)
}

type ProviderDiscovery

type ProviderDiscovery interface {
	FindProviders(ctx context.Context, d digest.Digest) ([]ifaces.Provider, error)
}

type RangeCache

type RangeCache interface {
	OpenRange(ctx context.Context, d digest.Digest, requested httprange.Range) (io.ReadCloser, int64, error)
	// Put returns rangecache.ErrFull without consuming r when admission is refused.
	Put(d digest.Digest, total, start int64, r io.Reader) (int64, error)
}

RangeCache retains ranges fetched from peers or origin so the next reader - local or remote - does not have to leave the node for them.

type Server

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

Server serves OverlayBD's node-local range proxy contract.

func NewServer

func NewServer(local LocalRangeStore, discovery ProviderDiscovery, peer PeerRangeFetcher, origin OriginRangeFetcher, opts Options) (*Server, error)

func (*Server) Drain

func (s *Server) Drain()

Drain prevents new reads while allowing the shared HTTP server to finish active handlers.

func (*Server) MarkReady

func (s *Server) MarkReady()

MarkReady releases the sticky startup gate.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type URLPolicy

type URLPolicy struct {
	AllowedHostSuffixes []string
	AllowHTTP           bool
}

URLPolicy limits signed-origin requests to operator-approved HTTPS hosts.

func (URLPolicy) ValidateURL

func (p URLPolicy) ValidateURL(u *url.URL) error

ValidateURL validates scheme and host without requiring the URL to carry a digest. Redirect targets use this narrower check.

Jump to

Keyboard shortcuts

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