Skip to main content

Module ipfs

Module ipfs 

Source
Expand description

The IPFS data model, minimally: multihashes (sha2-256 only), CIDv0 and CIDv1 in binary and text (base58btc, and base32 as b…), the raw and dag-pb codecs, and UnixFS nodes.

A block’s CID is always computed here from its bytes. Nothing a peer or the model says about a block’s identity is taken on trust: a block is sent, or reported, only when its bytes hash to the CID it is sent or reported under.

Protobuf nesting is fixed by the schema (PBNode → PBLink, PBNode.Data → UnixFS Data); no decoder here recurses, so a peer cannot buy stack depth.

Structs§

Cid
A content identifier: version, codec and a sha2-256 digest. Other hash functions are not representable, so a CID naming one is refused at parse time.
Described
What a block looks like to whoever receives it: its codec, and for dag-pb its UnixFS meaning and links.
Link
A dag-pb link: the child’s CID, its name in a directory, and the size of its subtree.
PbNode
A decoded dag-pb node.
UnixFs
What a UnixFS node says about itself.

Constants§

DAG_PB
Multicodec dag-pb: a protobuf PBNode, the codec UnixFS is written in.
MAX_BLOCK
A block is at most this long (Bitswap’s own limit, which Kubo enforces too).
MAX_CID_TEXT
A CID in text is at most this long; a sha2-256 CIDv1 in base32 is 59 characters.
MAX_LINKS
Links one dag-pb node may carry before it is refused (Kubo writes at most 174 per file node and 1024-ish per directory shard).
RAW
Multicodec raw: the block is the bytes.
SHA2_256
Multihash sha2-256, 32-byte digests.

Functions§

base32_decode
base32_encode
RFC 4648 base32, lower case, no padding (multibase b).
cids_for_digest
Every CID text a sha2-256 digest can stand for, in the two codecs NetGet knows: what a DHT key (a bare multihash) may mean.
codec_name
Why a CID is not one NetGet can serve or verify.
decode_pb_node
decode_unixfs
describe
encode_pb_node
The canonical dag-pb encoding: every link (field 2) before the data (field 1).
encode_unixfs
UnixFS Data: Type, Data, filesize, blocksizes, in field order as go-unixfs writes them.
multihash_bytes
parse_multihash
A multihash’s digest, refusing every function but sha2-256 with 32-byte output.
sha256
sha2-256 multihash of data: the 34 bytes 0x12 0x20 ‖ digest.
unixfs_file_block
A single-block UnixFS file holding content, as ipfs add writes a file no larger than its chunk size when it does not use raw leaves.