-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use Fx to start and stop the host, swarm, autorelay and quicreuse (#2118
) * config: refactor AutoNAT construction into separate method * config: use a lifecycle hook to start listening on swarm addresses * use Fx to construct the host * add a test for constructing a routed host * use Fx hooks to start the host * config: use Fx lifecycle hooks to start AutoRelay and for PeerRouting * basichost: don't close the swarm The swarm is not constructed by the basic host, thus is shouldn't be closed by it. * config: use Fx hook to close the quicreuse connection manager * test for goroutine leaks when starting/stopping fx To do this, I've had to move a few leaky tests into a separate package. I've filed a bug for the AutoNAT issue (#2743) but the "error on startup" issue is going to require some pretty invasive changes (we need to construct _then_ start). * go fmt * Ignore one more top function * Typo * Ignore any not top --------- Co-authored-by: Sukun <sukunrt@gmail.com> Co-authored-by: Steven Allen <steven@stebalien.com> Co-authored-by: Marco Munizaga <git@marcopolo.io>
- Loading branch information
1 parent
39242a4
commit 9d149fa
Showing
10 changed files
with
243 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package config | ||
|
||
import ( | ||
"context" | ||
|
||
basichost "github.com/libp2p/go-libp2p/p2p/host/basic" | ||
routed "github.com/libp2p/go-libp2p/p2p/host/routed" | ||
|
||
"go.uber.org/fx" | ||
) | ||
|
||
type closableBasicHost struct { | ||
*fx.App | ||
*basichost.BasicHost | ||
} | ||
|
||
func (h *closableBasicHost) Close() error { | ||
_ = h.App.Stop(context.Background()) | ||
return h.BasicHost.Close() | ||
} | ||
|
||
type closableRoutedHost struct { | ||
*fx.App | ||
*routed.RoutedHost | ||
} | ||
|
||
func (h *closableRoutedHost) Close() error { | ||
_ = h.App.Stop(context.Background()) | ||
return h.RoutedHost.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Tests that leak goroutines for various reasons. Mostly because libp2p node shutdown logic doesn't run if we fail to construct the node. |
Oops, something went wrong.