dart_libp2p_bitswap 2.0.0
dart_libp2p_bitswap: ^2.0.0 copied to clipboard
An implementation of the Bitswap 1.2.0 block exchange protocol for dart_libp2p.
2.0.0 #
Breaking changes:
- Requires
dart_libp2p^4.12.0 (was ^1.0.0). IBlockStoreis renamed toBlockStore.Bitswapno longer takespeerEventsStream; it subscribes tohost.eventBusitself.- Construction has no side effects. Call
await bitswap.start()before use;wantBlocks/getBlockthrowStateErrorif not started or afterstop(). - Unsolicited blocks (not on the local wantlist) are discarded instead of stored.
getBlocktakes an optionaltimeout(defaultBitswapOptions.getBlockTimeout, 30s). It returnsnullonly on timeout or cancellation; other errors propagate.stop()fails pendinggetBlockcalls withStateError, and stops rebroadcasts and queued replies before its first await, so nothing more is sent while it runs.- The library logs via
package:loggingand no longer prints.
New:
BitswapOptions(getBlockTimeout,rebroadcastInterval),Bitswap.cancelWants.- Blocks hashed with sha3-224/256/384/512, keccak-256/512, blake2b-256/512, blake3 (1–128-byte digests) or identity (up to 128 bytes) are verified and accepted, in addition to sha2-256/512.
- A runnable two-node example (
example/dart_libp2p_bitswap_example.dart). - Optional
SizedBlockStore(getSize), which lets Bitswap size blocks without reading them. With one, responses carrypendingBytes(bytes still queued for the peer, counted as boxo does). ReceivedpendingBytesis ignored, as in boxo. Bitswap.notifyNewBlockfor blocks the application stores itself: serves peers waiting for it and completes local wants.- Bitswap 1.2.0 want strategy:
WANT_BLOCKto one peer andWANT_HAVEto the rest, withsendDontHave; onDONT_HAVEor disconnect,WANT_BLOCKmoves to a peer that saidHAVE. - Outstanding wants are rebroadcast periodically, reaching peers that connect after the want was made.
- Later wants to a peer are sent as deltas; only the first message carries
full.
Fixes:
- CIDv0 blocks from peers (including go-bitswap) are now accepted.
- Sends to a peer are serialised over one stream, preserving order; a failed write on a reused stream is retried once.
- An outgoing stream the remote closes or resets is dropped as soon as that is seen, so the next send opens a fresh stream instead of first failing a write.
- Inbound messages over 4 MiB are rejected; responses are split to stay under 4 MiB.
- Peers sending
WANT_HAVEget aHAVEpresence instead of the block, or the block itself when it is at mostBitswapOptions.wantHaveReplaceSizebytes (default 1024, as in boxo). - The wantlist is sent on connect only to peers that speak Bitswap, rather than to every connected peer.
- Serving is bounded and fair: at most
maxWantsPerPeerwants per peer (default 1024); peers take turns of up toserveBytesPerTurn(default 1 MiB), highest priority first; serving no longer blocks the peer's read loop; a CANCEL received while a block is being read stops it being sent. - Concurrent
getBlockcalls share one want; one caller timing out no longer abandons it for others, and an abandoned want is cancelled with peers.
1.0.0 #
- Initial version.