Understanding file exchange

files
go-ipfs
#1

Hello all.

I’m working on a “simple” IPFS implementation (from scratch) for the Elixir language. My goal for now is to be able to get a file from IPFS. I made good progress already and I’m able to get back a list of providers for a particular CID.

The last step for me is to download the file from this list of peers. But how to achieve this is not clear. My current understanding is that I need to get back all the blocks of the file (to have something similar to the ipfs ls command) and then use the bitswap protocol to get these blocks.

When I connect to one of the bootstrap node, I can see that it exposes some protocols through mplex:

/floodsub/1.0.0
/ipfs/bitswap/1.1.0
/ipfs/id/1.0.0
/ipfs/kad/1.0.0
/libp2p/circuit/relay/0.1.0

I used the kad protocol to discover peers that can provide a file, I think that I need bitswap to get back the blocks I want, but how do I get back the blocks of a file ? I think I understand the merkle dag thing, but I can’t find how to ask a node the merkle dag of a CID.

To get here I spent a lot of time in the go code but there is so much abstractions everywhere !! A little help would be great :blush: