Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

feat: compatibility with go-libp2p-mdns - option 2 #81

Closed
wants to merge 11 commits into from

Conversation

alanshaw
Copy link
Member

@alanshaw alanshaw commented Apr 9, 2019

This PR simply sends out a multicast "response" on an interval in a format that go-libp2p-mdns expects. This works because go-libp2p sends a multicast query every 5 seconds and waits for responses to come in. Although they ideally should be sent unicast, go-libp2p still accepts multicast responses.

Note this allows go-libp2p to discover js-libp2p nodes but not the other way around.

alanshaw and others added 10 commits April 8, 2019 16:13
This PR adds a compatibility class that allows a js-libp2p node to find a go-libp2p node (and vice versa) over MDNS.

It's implemented as a separate class so the two differing implementations do not get confused.

I've verified this is working correctly by running a go-ipfs and js-ipfs node with no boostrap nodes (and no other discovery methods) and verifying they find each other.

TODO:

* [ ] Add tests!

Some tips if you want to try this out:

* After you've run `ipfs init`, remember to remove the bootstrap nodes from the config file (`~/.ipfs/config`) of each node before you start up
* Use `ipfs log level mdns debug` for some go-ipfs mdns logs
* You can use the following script (after `npm link`ing this branch) to start a js-ipfs node with no bootstrap nodes and no discovery modules other than MDNS:

```js
const IPFS = require('ipfs')
const MDNS = require('libp2p-mdns')
const TCP = require('libp2p-tcp')

const ipfs = new IPFS({
  repo: '/tmp/ipfs-mdns',
  config: {
    Bootstrap: []
  },
  libp2p: {
    modules: {
      peerDiscovery: [MDNS],
      transport: [TCP]
    }
  }
})

ipfs.on('ready', async () => {
  console.log('ipfs is ready')
  console.log('My Peer ID:', (await ipfs.id()).id)
  setInterval(async () => {
    const peers = await ipfs.swarm.peers()
    console.log(peers.length, 'peers:')
    peers.forEach(p => console.log(p.peer.toB58String()))
  }, 10000)
})
```

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
Co-Authored-By: alanshaw <alan.shaw@protocol.ai>
License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
@ghost ghost assigned alanshaw Apr 9, 2019
@ghost ghost added the status/in-progress In progress label Apr 9, 2019
License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
@alanshaw alanshaw requested a review from jacobheun April 9, 2019 15:00
@alanshaw alanshaw closed this Apr 10, 2019
@ghost ghost removed the status/in-progress In progress label Apr 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants