allow specifying some protected peers in the config file
This commit is contained in:
@@ -63,9 +63,17 @@ func genLibp2pKey() (crypto.PrivKey, error) {
|
||||
|
||||
// Misc options
|
||||
|
||||
func ConnectionManager(low, high int, grace time.Duration) func() (opts Libp2pOpts, err error) {
|
||||
return func() (opts Libp2pOpts, err error) {
|
||||
func ConnectionManager(low, high int, grace time.Duration, protected []string) func() (opts Libp2pOpts, err error) {
|
||||
return func() (Libp2pOpts, error) {
|
||||
cm := connmgr.NewConnManager(low, high, grace)
|
||||
for _, p := range protected {
|
||||
pid, err := peer.IDFromString(p)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to parse peer ID in protected peers array: %w", err)
|
||||
}
|
||||
|
||||
cm.Protect(pid, "config-prot")
|
||||
}
|
||||
opts.Opts = append(opts.Opts, libp2p.ConnectionManager(cm))
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user