With IPFS, why need libp2p?

I have read some online posts and document about IPFS. My understanding of IPFS is that IPFS is a content addressed distributed file system storing chunk of files on peers on the network. Then I came across libp2p which is confusing me a little bit. My understanding is that libp2p is a library allowing a node device do something (connecting, communicating and such) with peers on IPFS network. My question is that if I can use IPFS to manage files with its CID, then why do I need to use libp2p for the same purpose? Is libp2p providing more fine-tuned way to do the same as IPFS node does?

libp2p is used for 2 thing, dht (finding other peer and who host the file without any central server (replacing tracker in torrent)) and contacting people, IPFS doesn’t deal with tcp, udp, … so if a new thing is out it should be simpler to add it to IPFS (since nothing is needed in IPFS). (Security and multiplexing (talking of multiple thing over a signle connection)) is handled by libp2p.

Shortly IPFS and IPLD is the file part, libp2p is the network part.

1 Like

Thanks for the info. If I want to create a IPFS node programmatically, then libp2p should do it, shouldn’t it?

So programmatically I would call IPFS api for breaking up file and CID and libp2p for anything about sending the file chunks to peers for storage.

No, IPFS would call libp2p by it self, I’m not even sure if you can create programmatically an IPFS nodes with a custom libp2p one yet.

To continue comparison, sending a mail programmatically you just call your mail server through its API and the mail server does the SMTP stuff it self.

Hi,

you have an example on how to create an IPFS node programatically:

The underlying libp2p host is used to setup a few libp2p services as needed by IPFS to do what IPFS does, so there is no need to do things with it and the IPFS APIs offer all the IPFS functionality. Now, if you wanted to add additional p2p services or functionalities you would maybe need to interact with the libp2p host directly (I’m pretty sure some method exposes it).

Also, https://github.com/hsanjuan/ipfs-lite allows to create a simpler programmatic “node” (stripped down of much functionality) and explicitally asks you to pass the libp2p host you want to use.

For examples on how to create libp2p hosts etc, there is: https://github.com/libp2p/go-libp2p-examples

(I’m assuming we are talking about go-implementations. The Javascript side of things should be similar though).

Hector, Jorropo,

Thank you for the info and they are helpful. I use Javascript if I can. I am new to both IPFS and libp2p and some of my questions may be obvious to you guys.

Absolutly no problem, I think the docs should be reworked, they seems very good when knowing how evrythings works but I remember having trouble when starting with it.

Docs are being rewrote and there will be a new version soon (2 or 3 weeks). You can see a preview here: