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

config: fix "Insecure-security" constructor #2810

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,11 @@ func (cfg *Config) NewNode() (host.Host, error) {
return sw
}),
fx.Provide(cfg.newBasicHost),
fx.Provide(func(h *bhost.BasicHost, lifecycle fx.Lifecycle) host.Host {
lifecycle.Append(fx.StartHook(h.Start))
return h
fx.Provide(func(bh *bhost.BasicHost) host.Host {
return bh
}),
fx.Provide(func(h host.Host) peer.ID { return h.ID() }),
fx.Provide(func(h host.Host) crypto.PrivKey { return h.Peerstore().PrivKey(h.ID()) }),
fx.Provide(func(h *swarm.Swarm) peer.ID { return h.LocalPeer() }),
fx.Provide(func(h *swarm.Swarm) crypto.PrivKey { return h.Peerstore().PrivKey(h.LocalPeer()) }),
}
transportOpts, err := cfg.addTransports()
if err != nil {
Expand Down Expand Up @@ -418,6 +417,9 @@ func (cfg *Config) NewNode() (host.Host, error) {

var bh *bhost.BasicHost
fxopts = append(fxopts, fx.Invoke(func(bho *bhost.BasicHost) { bh = bho }))
fxopts = append(fxopts, fx.Invoke(func(h *bhost.BasicHost, lifecycle fx.Lifecycle) {
lifecycle.Append(fx.StartHook(h.Start))
}))

var rh *routed.RoutedHost
if cfg.Routing != nil {
Expand All @@ -430,7 +432,12 @@ func (cfg *Config) NewNode() (host.Host, error) {
}

if err := cfg.addAutoNAT(bh); err != nil {
rh.Close()
app.Stop(context.Background())
if cfg.Routing != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be part of the stop lifecycle, no? Maybe we defer the fix until later

Copy link
Member Author

Choose a reason for hiding this comment

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

wdym? We are not closing the host with the Stop lifecycle hook.

rh.Close()
} else {
bh.Close()
}
return nil, err
}

Expand Down Expand Up @@ -505,6 +512,7 @@ func (cfg *Config) addAutoNAT(h *bhost.BasicHost) error {
return dialer, err

}),
fx.Provide(func(s *swarm.Swarm) peer.ID { return s.LocalPeer() }),
fx.Provide(func() crypto.PrivKey { return autonatPrivKey }),
)
app := fx.New(fxopts...)
Expand Down
15 changes: 15 additions & 0 deletions libp2p_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,21 @@ func TestAutoNATService(t *testing.T) {
h.Close()
}

func TestInsecureConstructor(t *testing.T) {
h, err := New(
EnableNATService(),
NoSecurity,
)
require.NoError(t, err)
h.Close()

h, err = New(
NoSecurity,
)
require.NoError(t, err)
h.Close()
}

func TestDisableIdentifyAddressDiscovery(t *testing.T) {
h, err := New(DisableIdentifyAddressDiscovery())
require.NoError(t, err)
Expand Down
Loading