Expand description
Bitswap 1.2.0 (and 1.1.0, 1.0.0): the message, and the two decisions Rust makes about it
before or after the model — which wanted blocks the model’s content actually is
(answer_wants), and which received blocks are the ones that were asked for
(accept_blocks). In both, a block’s identity is its hash, computed here.
A Bitswap message is one uvarint-length-prefixed protobuf on a stream the sender opened; answers travel on a stream the answerer opens. Every count and size a peer announces is bounded before anything is collected for it.
Structs§
- Answer
- What to send back for one wantlist.
- Block
- One received block: the CID its prefix and bytes name (the bytes hashed here), and the bytes. A 1.0.0 block carries no prefix and is read as CIDv0 dag-pb.
- Entry
- Message
- Received
- What a received message is worth reporting.
- Supplied
- A block the model offered: its bytes as they will travel, and the CID it claimed, if any.
- WantSet
- Wants a dialler has outstanding, keyed by the block they name (codec and digest, so a v0 and a v1 want for one block are one want), with the text the model asked by.
Enums§
- Format
- The form a supplied block’s content takes on the wire.
- Version
- Which message format a protocol id speaks.
- Want
Type
Constants§
- BITSWAP_
100 - BITSWAP_
110 - BITSWAP_
120 - BITSWAP_
LEGACY - MAX_
MESSAGE - A Bitswap message is at most this long (boxo’s own
MessageSizeMax). - MAX_
MESSAGE_ FIELDS - Top-level fields (blocks, presences) one message may carry.
- MAX_
OUTGOING - What NetGet packs into one outgoing message, leaving room for framing.
- MAX_
OUTSTANDING_ WANTS - Outstanding wants one connection may hold.
- MAX_
SUPPLIED_ BLOCKS - Blocks the model may supply in one answer.
- MAX_
WANTLIST_ ENTRIES - Wantlist entries one message may carry.
- PROTOCOLS
- Every Bitswap protocol id NetGet accepts, newest first (the order it proposes them).
Functions§
- accept_
blocks - Keep only the blocks that are what was asked for. A block’s CID is computed from its own bytes, so a block whose bytes were altered names a different CID, which nothing wanted; it is refused, never reported.
- answer_
wants - Match the model’s blocks to the wants. A want is satisfied only by a block whose codec and sha2-256 digest are the wanted CID’s — computed from the bytes, never taken from the model. A supplied block that claims a CID its bytes do not hash to is refused. A want-have is answered with the block itself (Bitswap allows it, and it spares the model a second question whose answer has to hash the same). Wants left unsatisfied are answered DONT_HAVE where the peer asked for that.
- decode
- Decode one Bitswap message. Malformed protobuf, too many entries or fields, and a block
over
ipfs::MAX_BLOCKrefuse the whole message. - encode
- Encode a message in the format
versionspeaks: 1.0.0 carries raw blocks (CIDv0 only) and no presences; 1.1.0 carries prefixed blocks and no presences; 1.2.0 carries both. - is_
bitswap - split
- Split an answer into messages no longer than
MAX_OUTGOINGeach.