From bb4278c5dfd3addc820ce81acd5a24607fc8d506 Mon Sep 17 00:00:00 2001 From: Oleg <97077423+RobotSail@users.noreply.github.com> Date: Mon, 28 Nov 2022 12:37:02 -0500 Subject: [PATCH] new default option for when PSK is present Signed-off-by: Oleg <97077423+RobotSail@users.noreply.github.com> --- defaults.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/defaults.go b/defaults.go index c36c760ccc..b628d64379 100644 --- a/defaults.go +++ b/defaults.go @@ -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() @@ -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,