combined

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: Apache-2.0, MIT Imports: 7 Imported by: 0

Documentation

Overview

Package combined wires multiple BlockGetters into a single fall-through chain: cache → bitswap → HTTP gateway. Successful fetches from upstream sources are written back into the local cache.

This is the BlockGetter the state accessor takes in production.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	hamt.BlockGetter
	Put(c cid.Cid, raw []byte) cid.Cid
}

Cache is the local-cache half of a combined fetcher. It must support CID-keyed reads and writes. The state/cache package satisfies this in production; tests use hamt.MemBlockStore.

type Fetcher

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

Fetcher wires Cache + N Sources into the standard cache-first fallback chain. Sources are tried in order; the first successful CID-matching response wins. Successful responses are written into Cache.

func New

func New(cache Cache, sources ...Source) *Fetcher

New constructs a Fetcher.

func (*Fetcher) AddSource

func (f *Fetcher) AddSource(s Source, prepend bool)

AddSource appends a block source at runtime (thread-safe). Used by the embedded daemon to mount the libp2p Bitswap source once the host is up (lantern#50): on calibration the gateway+glif sources both point at Glif, so without a p2p source a bridge-off daemon has no non-Glif way to fetch message/receipt blocks. prepend=true puts it ahead of existing sources (so p2p is tried before the HTTP fallbacks). Idempotent on Name.

func (*Fetcher) Get

func (f *Fetcher) Get(ctx context.Context, c cid.Cid) ([]byte, error)

Get implements hamt.BlockGetter. Cache-first; then race-tier sources in parallel; then sequential fallback sources. The first CID-matching response wins, is cached, and the rest are abandoned via ctx cancel.

Issue #3: racing the gateway against Bitswap cuts cold-block latency from "5s Bitswap timeout + gateway fetch" to "gateway fetch (~100ms) OR Bitswap fast deadline", whichever fires first. State-tree walks that previously took 30s+ now complete in low single seconds.

func (*Fetcher) Stats

func (f *Fetcher) Stats() map[string]uint64

Stats returns a snapshot of fetch counters by source.

type Source

type Source struct {
	Name    string
	Getter  hamt.BlockGetter
	Timeout time.Duration
	Race    bool
}

Source is any networked BlockGetter (Bitswap, HTTP gateway).

Race=true sources are fired in parallel; the first successful response wins and the rest are abandoned. Race=false sources are tried sequentially AFTER all Race sources have failed.

Use Race=true for fast, low-cost alternative paths to the same blocks (e.g. our HTTP gateway and Bitswap both serve cold IPLD blocks). Use Race=false for last-resort fallbacks with different semantics or cost (e.g. Glif RPC, which is a public service and has a fee structure).

Jump to

Keyboard shortcuts

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