Skip to content

Commit

Permalink
use a different set of default transports when PSK is enabled (#1921)
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg <97077423+RobotSail@users.noreply.github.com>

Signed-off-by: Oleg <97077423+RobotSail@users.noreply.github.com>
  • Loading branch information
RobotSail authored Dec 2, 2022
1 parent 1c8eaab commit 2cc4de5
Showing 1 changed file with 14 additions and 1 deletion.
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 @@ -129,9 +138,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

0 comments on commit 2cc4de5

Please sign in to comment.