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: auto relay network query #749

Merged
merged 7 commits into from
Oct 9, 2020
Merged

Conversation

vasco-santos
Copy link
Member

@vasco-santos vasco-santos commented Sep 11, 2020

This PR add to the auto-relay ambient discovery, the ability to query the network for providers of the hop relay service. This will be performed if there are not enough peers connected/known with that capability.

The concept of the libp2p discovery serviced is added here (still not formally, but will be once we integrate rendezvous).

The Circuit was decoupled into two parts, the Circuit Transport and the Relay Service. This decoupling is important, so that we have lifecycle methods (start and stop for the relay). These methods will be used for calling the discovery.advertise similarly to go-libp2p's relay implementation, as well as to future active relay service network query on start.

The advertise options were added with the same defaults as go

Needs:

@vasco-santos vasco-santos force-pushed the feat/auto-relay-network-query branch 2 times, most recently from baf0ff0 to 6bbd819 Compare September 15, 2020 07:56
@vasco-santos vasco-santos force-pushed the feat/auto-relay-network-query branch 2 times, most recently from 7073965 to 26648a5 Compare September 17, 2020 08:14
return
}

remoteMultiaddr = remoteAddrs[0].multiaddr
Copy link
Member Author

@vasco-santos vasco-santos Sep 17, 2020

Choose a reason for hiding this comment

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

While there is no support for signed peer records via delegate nodes (HTTP API), we need to fallback here

Copy link
Contributor

Choose a reason for hiding this comment

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

This address selection logic isn't great. If we don't have a certified record we might just be taking their private address if it's first (which I am concerned could be pretty common). The known public relays won't have this problem because they don't advertise private addresses, but we should be doing some level of sorting here to get the "best" address

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 added a sorter. In follow up PRs, I will add the support for custom sort function for dial and custom filter for announce. Then, it will be bubbled up to here. But I wanted to keep things simple in this PR

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.

I like the separation of the circuit transport file 👍

test/relay/auto-relay.node.js Outdated Show resolved Hide resolved
src/circuit/auto-relay.js Outdated Show resolved Hide resolved
// Try to find relays to hop on the network
try {
const cid = await namespaceToCid(RELAY_RENDEZVOUS_NS)
for await (const provider of this._libp2p.contentRouting.findProviders(cid)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't have support to do this right now, but it would be great to actually prioritize the results of this based on latency of the connection. Worth adding an issue for a future enhancement here I think

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that would be good! I can create an issue for that. We should get that after the libp2p.discovery API, also with the rendezvous

Copy link
Member Author

Choose a reason for hiding this comment

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

src/circuit/constants.js Show resolved Hide resolved
src/circuit/index.js Show resolved Hide resolved
src/circuit/index.js Outdated Show resolved Hide resolved
src/circuit/index.js Outdated Show resolved Hide resolved
@vasco-santos vasco-santos force-pushed the feat/auto-relay-network-query branch from 26648a5 to 8060470 Compare September 23, 2020 13:43
@vasco-santos vasco-santos force-pushed the feat/auto-relay-network-query branch 4 times, most recently from 2f00f6c to 3a119dc Compare September 25, 2020 15:29
@vasco-santos vasco-santos force-pushed the feat/auto-relay-network-query branch from 3a119dc to 6abea77 Compare September 25, 2020 15:42
@vasco-santos vasco-santos marked this pull request as ready for review September 25, 2020 15:44
@vasco-santos vasco-santos force-pushed the feat/auto-relay-network-query branch from 6abea77 to 57a07f1 Compare September 25, 2020 16:04
doc/CONFIGURATION.md Outdated Show resolved Hide resolved
doc/CONFIGURATION.md Outdated Show resolved Hide resolved
return
}

remoteMultiaddr = remoteAddrs[0].multiaddr
Copy link
Contributor

Choose a reason for hiding this comment

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

This address selection logic isn't great. If we don't have a certified record we might just be taking their private address if it's first (which I am concerned could be pretty common). The known public relays won't have this problem because they don't advertise private addresses, but we should be doing some level of sorting here to get the "best" address

src/circuit/index.js Outdated Show resolved Hide resolved
src/circuit/index.js Outdated Show resolved Hide resolved
src/config.js Outdated Show resolved Hide resolved
@vasco-santos vasco-santos force-pushed the feat/auto-relay-network-query branch from 51e9e95 to 8147383 Compare October 7, 2020 15:58
@vasco-santos vasco-santos requested a review from jacobheun October 8, 2020 09:10
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.

Last couple things otherwise this looks good

src/circuit/auto-relay.js Outdated Show resolved Hide resolved
@vasco-santos vasco-santos requested a review from jacobheun October 8, 2020 18:17
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, I'll leave the rebase/squash in your hands in case there are other branches you have based on this one.

@vasco-santos vasco-santos merged commit 46e94d7 into 0.30.x Oct 9, 2020
@vasco-santos vasco-santos deleted the feat/auto-relay-network-query branch October 9, 2020 13:20
@vasco-santos vasco-santos restored the feat/auto-relay-network-query branch October 9, 2020 13:20
@vasco-santos vasco-santos deleted the feat/auto-relay-network-query branch October 9, 2020 13:20
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