-
Notifications
You must be signed in to change notification settings - Fork 12
Conversation
Extract service implementation from go-libp2p-autonat
gx publish 1.0.1
gx publish 1.0.2
gx publish 1.0.3
gx publish 1.0.4
gx publish 1.0.7
gx publish 1.0.8
gx publish 1.0.12
…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
I think this is a mistake; it was done separately precisely to avoid the dependency dance. |
Separating the motivation and the mechanics of dependencies: 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:
|
svc.go
Outdated
ctx context.Context | ||
h host.Host | ||
dialer network.Dialer | ||
dialerStore peerstore.Peerstore |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(or network.Network
)
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
@vyzo the context here is:
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 |
08fc45f
to
f1cd6ba
Compare
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 { |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
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:
background
goroutines into a single primary event loop