Skip to main content

Module bitswap

Module bitswap 

Source
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.
WantType

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_BLOCK refuse the whole message.
encode
Encode a message in the format version speaks: 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_OUTGOING each.