From ad5b7b9ba65d7e9509b3f52f2697bdf03b9fcb3e Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 16 Aug 2018 11:16:02 -0700 Subject: [PATCH] add options for disabling the default listen address/transports So, in go-ipfs at least, we *don't* pass the listen addresses into the libp2p constructor. Instead, we specify them later. This option allows us to tell libp2p to not listen by default. --- options.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/options.go b/options.go index a17fc02e89..ee147fa972 100644 --- a/options.go +++ b/options.go @@ -241,3 +241,21 @@ func NATManager(nm config.NATManagerC) Option { return nil } } + +// NoListen will configure libp2p to not listen by default. +// +// This will both clear any configured listen addrs and prevent libp2p from +// applying the default listen address option. +var NoListen = func(cfg *Config) error { + cfg.ListenAddrs = []ma.Multiaddr{} + return nil +} + +// NoTransports will configure libp2p to not enable any transports. +// +// This will both clear any configured transports (specified in prior libp2p +// options) and prevent libp2p from applying the default transports. +var NoTransports = func(cfg *Config) error { + cfg.Transports = []config.TptC{} + return nil +}