mirror of
https://github.com/libp2p/go-libp2p.git
synced 2025-10-15 12:42:26 +08:00
enable relay by default in New
This commit is contained in:
20
options.go
20
options.go
@@ -201,15 +201,25 @@ func AddrsFactory(factory config.AddrsFactory) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// EnableRelay configures libp2p to enable the relay transport.
|
||||
// EnableRelay configures libp2p to enable the relay transport with configuration options.
|
||||
func EnableRelay(options ...circuit.RelayOpt) Option {
|
||||
return func(cfg *Config) error {
|
||||
cfg.RelayCustom = true
|
||||
cfg.Relay = true
|
||||
cfg.RelayOpts = options
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// DisableRelay configures libp2p to disable the relay transport
|
||||
func DisableRelay() Option {
|
||||
return func(cfg *Config) error {
|
||||
cfg.RelayCustom = true
|
||||
cfg.Relay = false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// FilterAddresses configures libp2p to never dial nor accept connections from
|
||||
// the given addresses.
|
||||
func FilterAddresses(addrs ...*net.IPNet) Option {
|
||||
@@ -245,9 +255,15 @@ func NATManager(nm config.NATManagerC) Option {
|
||||
// NoListenAddrs 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.
|
||||
// applying the default listen address option. It also disables relay, unless the
|
||||
// user explicitly specifies with an option, as the transport creates an implicit
|
||||
// listen address that would make the node diable through any relay it was connected to.
|
||||
var NoListenAddrs = func(cfg *Config) error {
|
||||
cfg.ListenAddrs = []ma.Multiaddr{}
|
||||
if !cfg.RelayCustom {
|
||||
cfg.RelayCustom = true
|
||||
cfg.Relay = false
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user