-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
91 additions
and
12 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
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,60 @@ | ||
package node | ||
|
||
import "github.com/libp2p/go-libp2p" | ||
|
||
// XXX: | ||
// This is a slightly re-adaptation of | ||
// https://github.com/libp2p/go-libp2p/blob/0c7ce330810603728f9be66d998450d0fbfb8df7/defaults.go#L113 | ||
// as the fallback usually is totally fine, currently, when RSM is enabled a panic happens randomly. | ||
// As a workaround, disable RSM from fallback configs, while keep all the rest intact in the hope | ||
// to drop this with libp2p.FallbackDefaults | ||
var defaults = []struct { | ||
fallback func(cfg *libp2p.Config) bool | ||
opt libp2p.Option | ||
}{ | ||
{ | ||
fallback: func(cfg *libp2p.Config) bool { return cfg.Transports == nil && cfg.ListenAddrs == nil }, | ||
opt: libp2p.DefaultListenAddrs, | ||
}, | ||
{ | ||
fallback: func(cfg *libp2p.Config) bool { return cfg.Transports == nil }, | ||
opt: libp2p.DefaultTransports, | ||
}, | ||
{ | ||
fallback: func(cfg *libp2p.Config) bool { return cfg.Muxers == nil }, | ||
opt: libp2p.DefaultMuxers, | ||
}, | ||
{ | ||
fallback: func(cfg *libp2p.Config) bool { return !cfg.Insecure && cfg.SecurityTransports == nil }, | ||
opt: libp2p.DefaultSecurity, | ||
}, | ||
{ | ||
fallback: func(cfg *libp2p.Config) bool { return cfg.PeerKey == nil }, | ||
opt: libp2p.RandomIdentity, | ||
}, | ||
{ | ||
fallback: func(cfg *libp2p.Config) bool { return cfg.Peerstore == nil }, | ||
opt: libp2p.DefaultPeerstore, | ||
}, | ||
{ | ||
fallback: func(cfg *libp2p.Config) bool { return !cfg.RelayCustom }, | ||
opt: libp2p.DefaultEnableRelay, | ||
}, | ||
|
||
{ | ||
fallback: func(cfg *libp2p.Config) bool { return cfg.ConnManager == nil }, | ||
opt: libp2p.DefaultConnectionManager, | ||
}, | ||
} | ||
|
||
var fallbackDefaults libp2p.Option = func(cfg *libp2p.Config) error { | ||
for _, def := range defaults { | ||
if !def.fallback(cfg) { | ||
continue | ||
} | ||
if err := cfg.Apply(def.opt); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |