Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: auto relay example #795

Merged
merged 5 commits into from
Nov 20, 2020
Merged

chore: auto relay example #795

merged 5 commits into from
Nov 20, 2020

Conversation

vasco-santos
Copy link
Member

@vasco-santos vasco-santos commented Nov 2, 2020

This PR adds an example to use libp2p's auto relay.

With it, I added a setup to run the examples in CI, inspired by js-ipfs older test setup pre lerna migration ipfs/js-ipfs#2528

Needs:

  • guidelines for what's next?
  • tests

@vasco-santos vasco-santos force-pushed the chore/auto-relay-example branch 4 times, most recently from 65a7aaf to dfceafb Compare November 5, 2020 14:49
@vasco-santos vasco-santos marked this pull request as ready for review November 6, 2020 15:52
@vasco-santos vasco-santos force-pushed the chore/auto-relay-example branch 2 times, most recently from 0f68e5d to 6850cd2 Compare November 9, 2020 14:11
Copy link
Contributor

@jacobheun jacobheun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once all the code is updated we should make sure to update the code shown in the readme so it matches properly.

examples/auto-relay/README.md Outdated Show resolved Hide resolved
examples/auto-relay/README.md Outdated Show resolved Hide resolved
node.multiaddrs.forEach((ma) => console.log(`${ma.toString()}/p2p/${node.peerId.toB58String()}`))
```

The Relay HOP advertise functionality is **NOT** required to be enabled. However, if you are interested in advertising on the network that this node is available to be used as a HOP Relay you can enable it.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with this example is that the node has no way of actually advertising. A content router has to be included for this to work. I would disable it for this example and mention here that a router is required. Ideally this should link to available routers so we can just update that section with Rendezvous is ready.

examples/auto-relay/README.md Show resolved Hide resolved
/ip4/192.168.1.120/tcp/61592/ws/p2p/QmWDn2LY8nannvSWJzruUYoLZ4vV83vfCBwd8DipvdgQc3
```

TODO: Docker Image with a repo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should create a simple Docker Image with relay and HOP enabled to enable people to easily deploy Relays. I will remove this from now, while I think in the best solution to also include the announce addresses logic

Comment on lines 133 to 136
Node started: QmerrWofKF358JE6gv3z74cEAyL7z1KqhuUoVfGEynqjRm
connected to the HOP relay
Listening on:
/ip4/192.168.1.120/tcp/61592/ws/p2p/QmWDn2LY8nannvSWJzruUYoLZ4vV83vfCBwd8DipvdgQc3/p2p-circuit/p2p/QmerrWofKF358JE6gv3z74cEAyL7z1KqhuUoVfGEynqjRm
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider cleaning the logging up a bit to be a bit clearer, something like:

Suggested change
Node started: QmerrWofKF358JE6gv3z74cEAyL7z1KqhuUoVfGEynqjRm
connected to the HOP relay
Listening on:
/ip4/192.168.1.120/tcp/61592/ws/p2p/QmWDn2LY8nannvSWJzruUYoLZ4vV83vfCBwd8DipvdgQc3/p2p-circuit/p2p/QmerrWofKF358JE6gv3z74cEAyL7z1KqhuUoVfGEynqjRm
Node started with id QmerrWofKF358JE6gv3z74cEAyL7z1KqhuUoVfGEynqjRm
Connected to the HOP relay QmWDn2LY8nannvSWJzruUYoLZ4vV83vfCBwd8DipvdgQc3
Advertising with a relay address of /ip4/192.168.1.120/tcp/61592/ws/p2p/QmWDn2LY8nannvSWJzruUYoLZ4vV83vfCBwd8DipvdgQc3/p2p-circuit/p2p/QmerrWofKF358JE6gv3z74cEAyL7z1KqhuUoVfGEynqjRm

await node.dial(relayAddr)

// Wait for connection and relay to be bind for the example purpose
await pWaitFor(() => node.multiaddrs.length > 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of pWaitFor perhaps it would be best to listen on the Peer Store for our own address change. This also ensures we're only using libp2p deps in this example.

console.log('connected to the HOP relay')
console.log('Listening on:')
node.multiaddrs.forEach((ma) => console.log(`${ma.toString()}/p2p/${node.peerId.toB58String()}`))
})()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: instead of a self executing anonymous function it might be helpful to put these in a function like main and then execute that. Same for the other files.

@@ -0,0 +1,27 @@
'use strict'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of other-node perhaps we should use the same format as other examples: dialer, listener?

},
addresses: {
listen: ['/ip4/0.0.0.0/tcp/0/ws']
// announceFilter: TODO check production section
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What production section?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed, it was the What's next section where I mention that the announceAddrs should be changed for production

node.peerStore.on('change:multiaddrs', ({ peerId }) => {
// Updated self multiaddrs?
if (peerId.equals(node.peerId)) {
resolve()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe get rid of the promise logic and just put the console logs here? This event listener never gets cleaned up and can throw an error if our addresses change again and call resolve on the already resolved promise.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that makes a lot of sense! thanks

Copy link
Contributor

@jacobheun jacobheun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jacobheun jacobheun merged commit b5e38de into 0.30.x Nov 20, 2020
@jacobheun jacobheun deleted the chore/auto-relay-example branch November 20, 2020 14:18
vasco-santos added a commit that referenced this pull request Dec 10, 2020
* chore: auto relay example

* chore: update examples to use process arguments

* chore: add test setup for node tests and test for auto-relay

* chore: apply suggestions from code review

* chore: do not use promise for multiaddrs event on example
vasco-santos added a commit that referenced this pull request Dec 16, 2020
* chore: auto relay example

* chore: update examples to use process arguments

* chore: add test setup for node tests and test for auto-relay

* chore: apply suggestions from code review

* chore: do not use promise for multiaddrs event on example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants