Documentation
¶
Overview ¶
Package bitswap is Lantern's Bitswap client.
Phase 10 (V1.2 swarm-native fetch) replaced the original Phase 2 stub with a real boxo/bitswap client wired against the Lantern libp2p host. The package still exposes the Stub type for backward compatibility with older Phase 2 demos and unit tests in net/combined.
Production usage:
hc, _ := llibp2p.New(ctx, llibp2p.HostConfig{...})
bs, _ := bitswap.New(ctx, bitswap.Config{
Host: hc.H,
ProviderFinder: hc.DHT(), // optional; when nil broadcasts to connected peers
PreferredPeers: beaconPeers, // optional; warm-pool of beacon multiaddrs
})
// bs satisfies state/hamt.BlockGetter:
rawBlock, err := bs.Get(ctx, someCID)
Trust model: every block returned is hashed by net/combined.Fetcher before being trusted. Peers cannot lie undetected; the worst they can do is refuse to serve.
No CGo; depends only on github.com/ipfs/boxo and github.com/libp2p/go-libp2p.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrStub = errors.New("net/bitswap: stub (no Filecoin Bitswap peers wired yet, see B8)")
ErrStub is the canonical "Bitswap path not yet wired" error.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is Lantern's Bitswap client. It satisfies state/hamt.BlockGetter (the .Get(ctx, cid) ([]byte, error) shape).
func (*Client) Get ¶
Get fetches the block by CID using a two-stage deadline: try preferred peers fast, escalate to full swarm, then give up. Returns the raw block bytes. The caller is responsible for verifying CID == hash(bytes); net/combined.Fetcher does this for production callers.
func (*Client) GetMany ¶
GetMany is a convenience batch lookup. It opens a single session so the HAMT walk-style "N sequential CIDs" pattern shares a warm peer pool.
func (*Client) NewSession ¶
NewSession returns a Bitswap session — useful for HAMT-walk style fetch patterns where successive lookups share a warm peer pool.
type Config ¶
type Config struct {
// Host is the libp2p host Bitswap rides on top of. Required.
Host host.Host
// ProviderFinder optionally feeds Bitswap with provider hints. When
// nil (no DHT wired), Bitswap broadcasts WANT-HAVE to its connected
// peer set, which is sufficient when preferred peers are explicitly
// connected.
ProviderFinder routing.ContentDiscovery
// PreferredPeers is the list of always-keep-connected peers tried
// first. Beacon nodes (Phase 10 Part C) live here.
PreferredPeers []peer.AddrInfo
// FastDeadline is how long to wait for preferred peers before
// escalating to the full swarm. Default 1.5s.
FastDeadline time.Duration
// FullDeadline is the total deadline applied when no per-call
// timeout is set. Default 5s.
FullDeadline time.Duration
// ProtocolPrefix namespaces the bitswap libp2p protocol IDs. Filecoin
// nodes (Lotus/Forest) serve bitswap under "/chain" (i.e.
// /chain/ipfs/bitswap/1.2.0), NOT the boxo default "/ipfs/bitswap/...".
// Set this to build.BitswapProtocolPrefix() ("/chain") to exchange
// blocks with the Filecoin swarm. Empty => boxo default (IPFS), which
// will NOT find blocks on the Filecoin network. lantern#50.
ProtocolPrefix string
}
Config controls Bitswap wiring. All fields optional except Host.