allow specifying some protected peers in the config file

This commit is contained in:
whyrusleeping
2019-12-16 21:37:31 -08:00
parent 4ace1fe436
commit eb4077b1af
3 changed files with 16 additions and 5 deletions
+10 -2
View File
@@ -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
}