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

use a different set of default transports when PSK is enabled #1921

Merged
merged 1 commit into from
Dec 2, 2022
Merged
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
15 changes: 14 additions & 1 deletion defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ var DefaultTransports = ChainOptions(
Transport(ws.New),
)

// DefaultPrivateTransports are the default libp2p transports when a PSK is supplied.
//
// Use this option when you want to *extend* the set of transports used by
// libp2p instead of replacing them.
var DefaultPrivateTransports = ChainOptions(
Transport(tcp.NewTCPTransport),
Transport(ws.New),
)

// DefaultPeerstore configures libp2p to use the default peerstore.
var DefaultPeerstore Option = func(cfg *Config) error {
ps, err := pstoremem.NewPeerstore()
Expand Down Expand Up @@ -135,9 +144,13 @@ var defaults = []struct {
opt: DefaultListenAddrs,
},
{
fallback: func(cfg *Config) bool { return cfg.Transports == nil },
fallback: func(cfg *Config) bool { return cfg.Transports == nil && cfg.PSK == nil },
opt: DefaultTransports,
},
{
fallback: func(cfg *Config) bool { return cfg.Transports == nil && cfg.PSK != nil },
opt: DefaultPrivateTransports,
},
{
fallback: func(cfg *Config) bool { return cfg.Muxers == nil },
opt: DefaultMuxers,
Expand Down