Ping constructor option, enabled by default
This commit is contained in:
parent
0fa1c25479
commit
1056fa8119
|
@ -56,6 +56,9 @@ type Config struct {
|
|||
NATManager NATManagerC
|
||||
Peerstore pstore.Peerstore
|
||||
Reporter metrics.Reporter
|
||||
|
||||
PingCustom bool
|
||||
Ping bool
|
||||
}
|
||||
|
||||
// NewNode constructs a new libp2p Host from the Config.
|
||||
|
@ -102,6 +105,7 @@ func (cfg *Config) NewNode(ctx context.Context) (host.Host, error) {
|
|||
ConnManager: cfg.ConnManager,
|
||||
AddrsFactory: cfg.AddrsFactory,
|
||||
NATManager: cfg.NATManager,
|
||||
EnablePing: cfg.Ping,
|
||||
})
|
||||
if err != nil {
|
||||
swrm.Close()
|
||||
|
|
|
@ -75,6 +75,11 @@ var DefaultEnableRelay = func(cfg *Config) error {
|
|||
return cfg.Apply(EnableRelay())
|
||||
}
|
||||
|
||||
// DefaultEnablePing enables the ping service by default
|
||||
var DefaultEnablePing = func(cfg *Config) error {
|
||||
return cfg.Apply(Ping(true))
|
||||
}
|
||||
|
||||
// Complete list of default options and when to fallback on them.
|
||||
//
|
||||
// Please *DON'T* specify default options any other way. Putting this all here
|
||||
|
@ -111,6 +116,10 @@ var defaults = []struct {
|
|||
fallback: func(cfg *Config) bool { return !cfg.RelayCustom },
|
||||
opt: DefaultEnableRelay,
|
||||
},
|
||||
{
|
||||
fallback: func(cfg *Config) bool { return !cfg.PingCustom },
|
||||
opt: DefaultEnablePing,
|
||||
},
|
||||
}
|
||||
|
||||
// Defaults configures libp2p to use the default options. Can be combined with
|
||||
|
|
|
@ -252,6 +252,15 @@ func NATManager(nm config.NATManagerC) Option {
|
|||
}
|
||||
}
|
||||
|
||||
// Ping will configure libp2p to support the ping service; enable by default.
|
||||
func Ping(enable bool) Option {
|
||||
return func(cfg *Config) error {
|
||||
cfg.PingCustom = true
|
||||
cfg.Ping = enable
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// NoListenAddrs will configure libp2p to not listen by default.
|
||||
//
|
||||
// This will both clear any configured listen addrs and prevent libp2p from
|
||||
|
|
Loading…
Reference in New Issue