|
| 1 | +<p align="center"> |
| 2 | + <a href="https://github.com/ipfs/helia" title="Helia"> |
| 3 | + <img src="https://raw.githubusercontent.com/ipfs/helia/main/assets/helia.png" alt="Helia logo" width="300" /> |
| 4 | + </a> |
| 5 | +</p> |
| 6 | + |
| 7 | +<h3 align="center"><b>Helia LAN discovery</b></h3> |
| 8 | + |
| 9 | +<p align="center"> |
| 10 | + <img src="https://raw.githubusercontent.com/jlord/forkngo/gh-pages/badges/cobalt.png" width="200"> |
| 11 | + <br> |
| 12 | + <a href="https://ipfs.github.io/helia/modules/helia.html">Explore the docs</a> |
| 13 | + · |
| 14 | + <a href="https://codesandbox.io/p/sandbox/infallible-haibt-e3lcd4">View Demo</a> |
| 15 | + · |
| 16 | + <a href="https://github.com/ipfs-examples/helia-examples/issues">Report Bug</a> |
| 17 | + · |
| 18 | + <a href="https://github.com/ipfs-examples/helia-examples/issues">Request Feature/Example</a> |
| 19 | +</p> |
| 20 | + |
| 21 | +## Table of Contents |
| 22 | + |
| 23 | +- [Table of Contents](#table-of-contents) |
| 24 | +- [About The Project](#about-the-project) |
| 25 | +- [Getting Started](#getting-started) |
| 26 | + - [Prerequisites](#prerequisites) |
| 27 | + - [Installation and Running example](#installation-and-running-example) |
| 28 | +- [Usage](#usage) |
| 29 | +- [Documentation](#documentation) |
| 30 | +- [Contributing](#contributing) |
| 31 | +- [Want to hack on IPFS?](#want-to-hack-on-ipfs) |
| 32 | + |
| 33 | +## About The Project |
| 34 | + |
| 35 | +- Read the [docs](https://ipfs.github.io/helia/modules/helia.html) |
| 36 | +- Look into other [examples](https://github.com/ipfs-examples/helia-examples) to learn how to spawn a Helia node in Node.js and in the Browser |
| 37 | +- Visit https://dweb-primer.ipfs.io to learn about IPFS and the concepts that underpin it |
| 38 | +- Head over to https://proto.school to take interactive tutorials that cover core IPFS APIs |
| 39 | +- Check out https://docs.ipfs.io for tips, how-tos and more |
| 40 | +- See https://blog.ipfs.io for news and more |
| 41 | +- Need help? Please ask 'How do I?' questions on https://discuss.ipfs.io |
| 42 | + |
| 43 | +## Getting Started |
| 44 | + |
| 45 | +### Prerequisites |
| 46 | + |
| 47 | +Make sure you have installed all of the following prerequisites on your development machine: |
| 48 | + |
| 49 | +- Git - [Download & Install Git](https://git-scm.com/downloads). OSX and Linux machines typically have this already installed. |
| 50 | +- Node.js - [Download & Install Node.js](https://nodejs.org/en/download/) and the npm package manager. |
| 51 | + |
| 52 | +### Installation and Running example |
| 53 | + |
| 54 | +```console |
| 55 | +> npm install |
| 56 | + |
| 57 | +# then in one terminal |
| 58 | +> npm run server |
| 59 | + |
| 60 | +# in another terminal |
| 61 | +> npm run client |
| 62 | +``` |
| 63 | + |
| 64 | +To run the test |
| 65 | + |
| 66 | +```console |
| 67 | +npm run test |
| 68 | +``` |
| 69 | + |
| 70 | +You should see all of the output from the server and client nodes, and the test should pass. |
| 71 | + |
| 72 | +## Usage |
| 73 | + |
| 74 | +This example shows how you can use mdns to connect two nodes. Either server/client node can be run first. |
| 75 | + |
| 76 | +Both scripts (src/server.js & src/client.js) will create a helia node, and subscribe to a known pubsub topic, and shut each other down (for ease of testing). |
| 77 | + |
| 78 | +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. |
| 79 | + |
| 80 | +### General flow |
| 81 | + |
| 82 | +When you run these two scripts, the general flow works like this: |
| 83 | + |
| 84 | +1. Each node subscribes to the known pubsub topic. |
| 85 | +1. When the client node detects a subscription change on the pubsub topic, it will send a `wut-CID` message to the server node. |
| 86 | +1. The server node will respond to the `wut-CID` message with the string representation of a CID the server node is providing. |
| 87 | +1. The client node will request the content for that CID via `heliaDagCbor.get(CID.parse(msg))` |
| 88 | +1. Once the content is received, the client will publish a `done` message to the pubsub topic. |
| 89 | +1. The server node will detect the `done` message, and respond with a `done-ACK` message. |
| 90 | +1. The client node will detect the `done-ACK` message, respond with a `done-ACK` message of it's own, and shutdown after a timeout (to allow for the message to be sent) |
| 91 | +1. The server node will detect the `done-ACK` message, and shutdown immediately. |
| 92 | + |
| 93 | +### Testing |
| 94 | + |
| 95 | +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. |
| 96 | + |
| 97 | +### Further exploration of this example |
| 98 | + |
| 99 | +Some things to try: |
| 100 | + |
| 101 | +1. See if you can get ping/pong messages working without the nodes shutting down |
| 102 | +1. Run the server node from one computer on your local network, and the client node from another computer on your local network |
| 103 | +1. Try removing the shutdown code from the scripts, and see if you can get multiple clients to connect |
| 104 | +1. 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 |
| 105 | +1. See if you can connect to bootstrap nodes with one of your nodes, and use the other node as a LAN only node. |
| 106 | + |
| 107 | + |
| 108 | +_For more examples, please refer to the [Documentation](#documentation)_ |
| 109 | + |
| 110 | +## Documentation |
| 111 | + |
| 112 | +- [IPFS Primer](https://dweb-primer.ipfs.io/) |
| 113 | +- [IPFS Docs](https://docs.ipfs.io/) |
| 114 | +- [Tutorials](https://proto.school) |
| 115 | +- [More examples](https://github.com/ipfs-examples/helia-examples) |
| 116 | +- [API - Helia](https://ipfs.github.io/helia/modules/helia.html) |
| 117 | +- [API - @helia/unixfs](https://ipfs.github.io/helia-unixfs/modules/helia.html) |
| 118 | + |
| 119 | +## Contributing |
| 120 | + |
| 121 | +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**. |
| 122 | + |
| 123 | +1. Fork the IPFS Project |
| 124 | +2. Create your Feature Branch (`git checkout -b feature/amazing-feature`) |
| 125 | +3. Commit your Changes (`git commit -a -m 'feat: add some amazing feature'`) |
| 126 | +4. Push to the Branch (`git push origin feature/amazing-feature`) |
| 127 | +5. Open a Pull Request |
| 128 | + |
| 129 | +## Want to hack on IPFS? |
| 130 | + |
| 131 | +[](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md) |
| 132 | + |
| 133 | +The IPFS implementation in JavaScript needs your help! There are a few things you can do right now to help out: |
| 134 | + |
| 135 | +Read the [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md) and [JavaScript Contributing Guidelines](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md). |
| 136 | + |
| 137 | +- **Check out existing issues** The [issue list](https://github.com/ipfs/helia/issues) has many that are marked as ['help wanted'](https://github.com/ipfs/helia/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22help+wanted%22) or ['difficulty:easy'](https://github.com/ipfs/helia/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Adifficulty%3Aeasy) which make great starting points for development, many of which can be tackled with no prior IPFS knowledge |
| 138 | +- **Look at the [Helia Roadmap](https://github.com/ipfs/helia/blob/main/ROADMAP.md)** This are the high priority items being worked on right now |
| 139 | +- **Perform code reviews** More eyes will help |
| 140 | + a. speed the project along |
| 141 | + b. ensure quality, and |
| 142 | + c. reduce possible future bugs |
| 143 | +- **Add tests**. There can never be enough tests |
| 144 | + |
| 145 | +[cid]: https://docs.ipfs.tech/concepts/content-addressing "Content Identifier" |
| 146 | +[Uint8Array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array |
| 147 | +[libp2p]: https://libp2p.io |
0 commit comments