Skip to content

Get two helia nodes to connect on LAN without supplying address

Notifications You must be signed in to change notification settings

ipfs-examples/helia-lan-discovery

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Helia logo

Helia LAN discovery


Explore the docs · View Demo · Report Bug · Request Feature/Example

Table of Contents

About The Project

Getting Started

Prerequisites

Make sure you have installed all of the following prerequisites on your development machine:

Installation and Running example

> 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.

Usage

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.

General flow

When you run these two scripts, the general flow works like this:

  1. Each node starts up and will broadcast their presence using mDNS
  2. When the client node discovers the server, it will open a protocol stream to the server
  3. The server node will send the CID the server node is providing to the client.
  4. The client node will request the content for that CID via heliaDagCbor.get(CID.parse(msg))
  5. Once the content is received, the client will send an ACK message to the server and close the stream.
  6. The server node will receive the ACK message and close the stream.
  7. The server and client will then both shut down

Testing

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.

Further exploration of this example

Some things to try:

  1. See if you can get ping/pong messages working without the nodes shutting down
  2. Run the server node from one computer on your local network, and the client node from another computer on your local network
  3. Try removing the shutdown code from the scripts, and see if you can get multiple clients to connect
  4. 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
  5. 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

Documentation

Contributing

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.

  1. Fork the IPFS Project
  2. Create your Feature Branch (git checkout -b feature/amazing-feature)
  3. Commit your Changes (git commit -a -m 'feat: add some amazing feature')
  4. Push to the Branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Want to hack on IPFS?

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

About

Get two helia nodes to connect on LAN without supplying address

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •