Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Merge Autonat-svc #54

Merged
merged 93 commits into from
Mar 18, 2020
Merged

Merge Autonat-svc #54

merged 93 commits into from
Mar 18, 2020

Conversation

willscott
Copy link
Contributor

@willscott willscott commented Mar 13, 2020

This PR subsumes the go-libp2p-autonat-svc repository into this one.

It builds on #53 to expose both through functional arguments.
The only functional change is that the dialer used by the autonat-svc is constructed in a bit more tricky of a way to avoid a dependency on go-libp2p.

Note: This PR is structured to import the history from autonat-svc. The final 4 commits are the new changes: https://github.com/libp2p/go-libp2p-autonat/pull/54/files/62f42d93464d523fccc59bb7740975301d7bc1c7..dd12f0a09f839cec420686c40e8161b0a0b0158e

Known remaining work:

  • Combine the service and client's background goroutines into a single primary event loop
  • Pass over external interface for which constructors / methods should no longer be public

Stebalien and others added 18 commits February 25, 2020 22:54
…ibp2p/go-libp2p-core-0.3.1

Bump github.com/libp2p/go-libp2p-core from 0.3.0 to 0.3.1
use ip.Equal for comparison
add test on jitter
simplify addrToIP
remove global request limit when forced on.
Bumps [github.com/libp2p/go-libp2p-core](https://github.com/libp2p/go-libp2p-core) from 0.3.1 to 0.4.0.
- [Release notes](https://github.com/libp2p/go-libp2p-core/releases)
- [Commits](libp2p/go-libp2p-core@v0.3.1...v0.4.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
…ibp2p/go-libp2p-core-0.4.0

Bump github.com/libp2p/go-libp2p-core from 0.3.1 to 0.4.0
Limiting autonat service responses/startup
@vyzo
Copy link
Contributor

vyzo commented Mar 13, 2020

I think this is a mistake; it was done separately precisely to avoid the dependency dance.

@willscott
Copy link
Contributor Author

I think this is a mistake; it was done separately precisely to avoid the dependency dance.

Separating the motivation and the mechanics of dependencies:
I think the main motivations are
(1) less chance of two versions getting out of sync and
(2) It seems like it would be nice for the consumer to say "i would like an autonat subsystem" in a relatively succinct way and have things work.

The current split between the client - which is itself of interest to the DHT and autorelay, and the service that is outside of the libp2p Host isn't the same pattern as network / routing / discovery, and is a bit of an odd interface.

In terms of dependency resolution:

  • providing an option at creation for the consumer to directly choose a dialer to be used mostly removes the only dependency the service has currently on the upper libp2p repo. The rest of the dance is newDialerFromHost. I think we could arguably simplify this to just attempt the default TCP transport and error if anything else is used without an appropriate dialer passed in.

options.go Outdated Show resolved Hide resolved
svc.go Outdated Show resolved Hide resolved
proto.go Show resolved Hide resolved
svc.go Outdated
ctx context.Context
h host.Host
dialer network.Dialer
dialerStore peerstore.Peerstore
Copy link
Member

Choose a reason for hiding this comment

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

We should just use the one one the host.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, now I see. We still don't need the separate peerstore if we use the network.Network interface.

svc.go Outdated
dialer host.Host
ctx context.Context
h host.Host
dialer network.Dialer
Copy link
Member

Choose a reason for hiding this comment

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

These interfaces are a bit wonky and need to be refactored. Let's just use a host.

Copy link
Member

Choose a reason for hiding this comment

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

(or network.Network)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

went with just a network.Dialer, since the dialer interface includes .Peerstore.

Copy link
Member

Choose a reason for hiding this comment

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

network.Network embeds the network.Dialer interface.

@Stebalien
Copy link
Member

@vyzo the context here is:

  1. The two repos are annoying to keep in sync.
  2. Importantly, the service depends on events from the client to determine if it should even turn on in the first place. Otherwise, two nodes behind the same NAT could decide that they're both publicly reachable.

@willscott

So, this is a bit nasty. What if we made the host a required constructor argument (for non-client services)?

We can put tests in a separate autonat_test package and let that package import go-libp2p (circular module dependencies are fine).

@willscott willscott force-pushed the feat/merged branch 2 times, most recently from 08fc45f to f1cd6ba Compare March 16, 2020 22:12
options.go Outdated
// are "its own". Useful for testing, or for more exotic port-forwarding
// scenarios where the host may be listening on different ports than it wants
// to externally advertise or verify connectability on.
func WithAddresses(addrFunc GetAddrs) Option {
func AddressGuesser(addrFunc AddrFunc) Option {
Copy link
Member

Choose a reason for hiding this comment

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

Hm. I now hate myself, that was a bad suggestion. Can you think of a better alternative?

// default network/dialer of the host passed to `New`, as the NAT system will need to
// make parallel connections, and as such will modify both the associated peerstore
// and terminate connections of this dialer. The dialer provided
// should be compatible (TCP/UDP) however with the transports of the libp2p network.
Copy link
Member

Choose a reason for hiding this comment

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

This isn't strictly speaking necessary. Ideally, the dialer would support dialing all available transports.

func EnableService(dialer network.Network, forceServer bool) Option {
return func(c *config) error {
if dialer == c.host.Network() || dialer.Peerstore() == c.host.Peerstore() {
return errors.New("dialer should not be that of the host")
Copy link
Member

Choose a reason for hiding this comment

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

👍

@@ -236,6 +255,9 @@ func (as *AmbientAutoNAT) recordObservation(observation autoNATResult) {
// we are flipping our NATStatus, so confidence drops to 0
as.confidence = 0
as.status.Store(observation)
if as.serviceCancel != nil {
as.serviceCancel()
Copy link
Member

Choose a reason for hiding this comment

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

nit: might as well have as.serviceCancel = nil.

@@ -252,13 +274,16 @@ func (as *AmbientAutoNAT) recordObservation(observation autoNATResult) {
log.Debugf("NAT status is unknown")
as.status.Store(autoNATResult{network.ReachabilityUnknown, nil})
if currentStatus.Reachability != network.ReachabilityUnknown {
if as.serviceCancel != nil {
as.serviceCancel()
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

@willscott willscott merged commit 4a4a0ff into master Mar 18, 2020
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.

7 participants