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

refactor: examples/discovery-mechanisms #498

Merged

Conversation

vasco-santos
Copy link
Member

@vasco-santos vasco-santos commented Dec 9, 2019

This PR refactors the discovery-mechanisms example to the refactored async js-libp2p.

Needs:

@vasco-santos vasco-santos changed the title refactor: examples discovery mechanisms refactor: examples/discovery-mechanisms Dec 9, 2019
@vasco-santos vasco-santos force-pushed the refactor/examples-discovery-mechanisms branch from 1f004e3 to 07f0e97 Compare December 10, 2019 14:51
@jacobheun jacobheun force-pushed the refactor/async-await branch from 374ceb4 to 45f4702 Compare December 12, 2019 09:30
@vasco-santos vasco-santos force-pushed the refactor/examples-discovery-mechanisms branch from 07f0e97 to cc46973 Compare December 16, 2019 09:38
@vasco-santos vasco-santos force-pushed the refactor/examples-discovery-mechanisms branch from cc46973 to 980ae89 Compare December 16, 2019 09:50
@vasco-santos vasco-santos requested review from jacobheun and removed request for jacobheun December 16, 2019 09:52
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.

Just some minor things, otherwise it looks good. I ran it without any issues.

},
config: {
peerDiscovery: {
bootstrap: {
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be the mdns config, it's using bootstrap.

// picking any protocol) in order to get a full Connection. The Peer Discovery
// doesn't make any decisions for you.
node.dial(peer, () => {})
})
Copy link
Contributor

Choose a reason for hiding this comment

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

autoDial is true by default, we should remove this block.

})
node.start(cb)
const peerInfo = await PeerInfo.create()
peerInfo.multiaddrs.add('/ip4/0.0.0.0/tcp/0')
Copy link
Contributor

Choose a reason for hiding this comment

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

We could let Libp2p.create create the PeerInfo and then just do libp2p.peerInfo.multiaddrs.add('/ip4/0.0.0.0/tcp/0') after we create the node.

}
;(async () => {
const peerInfo = await PeerInfo.create()
peerInfo.multiaddrs.add('/ip4/0.0.0.0/tcp/0')
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here as below, let Libp2p.create make the PeerInfo.

@vasco-santos vasco-santos force-pushed the refactor/examples-discovery-mechanisms branch from 8b729b5 to 609bd10 Compare December 17, 2019 12:01
Co-Authored-By: Jacob Heun <jacobheun@gmail.com>
@vasco-santos vasco-santos force-pushed the refactor/examples-discovery-mechanisms branch from 609bd10 to 0535ecf Compare December 17, 2019 12:06
@vasco-santos vasco-santos requested a review from jacobheun January 2, 2020 08:50
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.

Two minor things, otherwise this looks good.

// Once the dial is complete, this event is emitted.
node.on('peer:connect', (peer) => {
console.log('Connection established to:', peer.id.toB58String())
})
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add the peer:connect event listener back, I think it got accidentally removed.

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 thought you suggested to remove it because of being kind of redundant, since should dial is true by default libp2p/js-libp2p#498/files#r358312128. But yeah, let's put it back, I also think we can double check this

vasco-santos and others added 2 commits January 2, 2020 22:46
Co-Authored-By: Jacob Heun <jacobheun@gmail.com>
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 f182f5b into refactor/async-await Jan 6, 2020
@jacobheun jacobheun deleted the refactor/examples-discovery-mechanisms branch January 6, 2020 17:01
jacobheun added a commit that referenced this pull request Jan 24, 2020
* refactor: examples-discovery-mechanisms

* chore: apply suggestions from code review

Co-Authored-By: Jacob Heun <jacobheun@gmail.com>

* chore: suggestion interval

Co-Authored-By: Jacob Heun <jacobheun@gmail.com>

* chore: add peer connected event

Co-authored-by: Jacob Heun <jacobheun@gmail.com>
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