Explore the docs
·
View Demo
·
Report Bug
·
Request Feature/Example
- Table of Contents
- About The Project
- Getting Started
- Usage
- Documentation
- Contributing
- Want to hack on IPFS?
- Read the docs
- Look into other examples to learn how to spawn a Helia node in Node.js and in the Browser
- Visit https://dweb-primer.ipfs.io to learn about IPFS and the concepts that underpin it
- Head over to https://proto.school to take interactive tutorials that cover core IPFS APIs
- Check out https://docs.ipfs.io for tips, how-tos and more
- See https://blog.ipfs.io for news and more
- Need help? Please ask 'How do I?' questions on https://discuss.ipfs.io
Make sure you have installed all of the following prerequisites on your development machine:
- Git - Download & Install Git. OSX and Linux machines typically have this already installed.
- Node.js - Download & Install Node.js and the npm package manager.
> npm install
# then in one terminal
> npm run server
# in another terminal
> npm run client
To run the test
npm run test
You should see all of the output from the server and client nodes, and the test should pass.
This example shows how you can use mdns to connect two nodes. Either server/client node can be run first.
Both scripts (src/server.js & src/client.js) will create a helia node. Once the client discovers the server it will open a connection on a custom protocol. The server will send a CID which the client will use to fetch some data from the server. The client will tell the server it has fetched the data and then both will shut down.
Note: No WAN functionality is enabled, so only nodes on your local network can help with peer-discovery, and only nodes on your local network can be discovered as the code currently stands.. If you want to enable connecting to nodes outside of your WAN, you will need to connect to a bootstrap node and add the kadDHT
service from @libp2p/kad-dht
.
When you run these two scripts, the general flow works like this:
- Each node starts up and will broadcast their presence using mDNS
- When the client node discovers the server, it will open a protocol stream to the server
- The server node will send the CID the server node is providing to the client.
- The client node will request the content for that CID via
heliaDagCbor.get(CID.parse(msg))
- Once the content is received, the client will send an
ACK
message to the server and close the stream. - The server node will receive the
ACK
message and close the stream. - The server and client will then both shut down
Both scripts should be able to be run in any order, and the flow should work as expected. You can run npm run test
to check this. The test will fail if the test runs for more than 10 seconds, or errors, but this failure mode is dependent upon the timeout
command currently.
Some things to try:
- See if you can get ping/pong messages working without the nodes shutting down
- Run the server node from one computer on your local network, and the client node from another computer on your local network
- Try removing the shutdown code from the scripts, and see if you can get multiple clients to connect
- See if you can get the server to respond with a list of CIDs in it's blockstore, and have the client choose which one to request
- See if you can connect to bootstrap nodes with one of your nodes, and use the other node as a LAN only node.
For more examples, please refer to the Documentation
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the IPFS Project
- Create your Feature Branch (
git checkout -b feature/amazing-feature
) - Commit your Changes (
git commit -a -m 'feat: add some amazing feature'
) - Push to the Branch (
git push origin feature/amazing-feature
) - Open a Pull Request
The IPFS implementation in JavaScript needs your help! There are a few things you can do right now to help out:
Read the Code of Conduct and JavaScript Contributing Guidelines.
- Check out existing issues The issue list has many that are marked as 'help wanted' or 'difficulty:easy' which make great starting points for development, many of which can be tackled with no prior IPFS knowledge
- Look at the Helia Roadmap This are the high priority items being worked on right now
- Perform code reviews More eyes will help a. speed the project along b. ensure quality, and c. reduce possible future bugs
- Add tests. There can never be enough tests