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

feat: initial implementation #1

Merged
merged 13 commits into from
Mar 31, 2020
Merged

feat: initial implementation #1

merged 13 commits into from
Mar 31, 2020

Conversation

jacobheun
Copy link
Contributor

@jacobheun jacobheun commented Mar 28, 2020

This creates a libp2p PeerDiscovery compliant module that leverages Pubsub to discover other peers across the pubsub mesh. The intention is to allow browser peers (and other peers) to connect to discover one another through a mutual pubsub network.

For browser nodes, this could mean connecting to a relay server on startup. If the relay server is also subscribed to the discovery topic, it would cause all connected peers to discover one another when a peer joins the pubsub topic.

TODO

Caveats

Currently libp2p isn't passing itself to the discovery modules when it instantiates them. This should be a trivial addition to libp2p though and is entirely reasonable to do.

Prior Art

@codecov-io
Copy link

codecov-io commented Mar 28, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@d7111aa). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master       #1   +/-   ##
=========================================
  Coverage          ?   96.29%           
=========================================
  Files             ?        2           
  Lines             ?       54           
  Branches          ?        0           
=========================================
  Hits              ?       52           
  Misses            ?        2           
  Partials          ?        0           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d7111aa...ea3fe0b. Read the comment docs.

@jacobheun
Copy link
Contributor Author

@vasco-santos @mkg20001 still need to do some cleanup but this is the general thought for a discovery service coupled with a relay server to replace stardust/websocket-star. I am planning to work on a relay server repo tomorrow and do some integration testing with this, but wanted to share out my initial draft of this. Planning to have a working version of this by Monday and get some RCs/examples out some time this week.

Copy link
Member

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

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

@jacobheun I made a first pass through this PR

I will make a second pass once we have the relay server

src/index.js Show resolved Hide resolved
src/index.js Show resolved Hide resolved
src/index.js Show resolved Hide resolved
@jacobheun jacobheun marked this pull request as ready for review March 31, 2020 12:34
Copy link
Member

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

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

Just small details missing

It is worth noting that this module does not include any message signing for queries. The reason for this is that libp2p-pubsub supports message signing and enables it by default, which means the message you received has been verified to be from the originator, so we can trust that the peer information we have received is indeed from the peer who owns it. This doesn't mean the peer can't falsify its own records, but this module isn't currently concerned with that scenario.

## Usage

Copy link
Member

Choose a reason for hiding this comment

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

Should we add a Usage example? or would you prefer to create an issue and get it done on a follow up PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll create an issue for a followup PR. I think this should mostly be a reference to the libp2p configuration documentation with a list of available options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tracking at #2, the rest of the suggestions have been applied/fixed.

package.json Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
@jacobheun jacobheun merged commit d6f7a31 into master Mar 31, 2020
@jacobheun jacobheun deleted the feat/initial branch March 31, 2020 13:40

const protons = require('protons')
const schema = `
message Query {
Copy link
Member

Choose a reason for hiding this comment

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

Just wondering why there's a query, queryresponse.

We're not really querying that way. We're just brodcasting.

Also is the query id being used?

Over pubsub we can't do request/response anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot to add the actual response code working on that now but got distracted with some other things. In reality, nothing is actually using the id at the moment, but the response will include it. We could potentially just drop the id as pubsub should give us enough information around the message if we wanted to do any abuse checking in the future.

Just wondering why there's a query, queryresponse.

We need more than just a broadcast, because we need other peers to respond in order to find out about them if they've been on the network.

Copy link
Member

Choose a reason for hiding this comment

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

We need more than just a broadcast, because we need other peers to respond in order to find out about them if they've been on the network.

If we brodcast every X seconds, shouldn't that be enough?

If not, how do you imagine doing request/responses on pubsub? This sounds more like something rendezvous protocol should do and this should be just a "simpler version of it" then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pushed up the code in https://github.com/libp2p/js-libp2p-pubsub-peer-discovery/pull/4/files to show the current process.

If we broadcast every X seconds, shouldn't that be enough?

We could. Right now, whenever you get a Query you publish your response, similar to MDNS. So it's like a solicited broadcast. The interval based broadcast could run unnecessarily often, but it's also more resistant to bad peers spam broadcasting and causing a flood of responses... so yeah, you're right, we should just make this an interval broadcast.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The major downside to the interval is that there will be a delay in us learning about all of the peers. If the interval is say, 10seconds, and we join at the start of a new interval, it will take 10 seconds for us to discover all peers. This is a pretty minor downside though, especially since we are working on persistent peer store support.

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.

4 participants