Where is the DAG stored in IPFS?

Where is the DAG stored in IPFS?
If I get the root hash of a file, how do I get the hash of the subblocks of the file from the network?
Is the DAG of the file stored in DHT? Or is the DAG stored in the physical location of the file?

The root hash points to a meta block that contain the list.

The classical blocks looks kinda like this :

{
  "link":[
    "Qmaaa",
    "Qmbbb",
    "Qmccc",
  ],
  "data": null
}

This would be classified as a root because it has some links to subblocks.
You can also chain them, if a root link an other root then it just works as you expect and IPFS keeps expending.

hi !Jorropo,Thanks for your reply!But I have a question.Where is this Meta Block stored? DHT? Or is it stored in a physical location of a file?

It’s an extra block that is stored in the block store like any other block.

Let’s assume you add a 1Mib file with raw leaves. The default chunker will break that into 4 256Kib chunks that are just purely your bytes.
Then a fifth block is created with no data and list the 4 other leaves. We call that block the root and his CID is the CID that is returned to you.

Then when someone download that file, IPFS first download this block using bitswap (it first search for peers in the DHT that register themself as hosting that CID then broadcast : “I want to download Qmfoo pls !”) then your node send Qmfoo, then the other node parse Qmfoo and realise that there is 4 other blocks and download thoses.

By default they are stored with flatfs in ~/.ipfs/blocks/... with a directory and name depending of the hash.

1 Like

I see. Thank you very much