lotus/node/impl/net/protect.go

36 lines
728 B
Go
Raw Normal View History

2022-02-03 16:24:49 +00:00
package net
import (
"context"
"github.com/libp2p/go-libp2p-core/peer"
)
const apiProtectTag = "api"
func (a *NetAPI) NetProtectAdd(ctx context.Context, peers []peer.ID) error {
for _, p := range peers {
a.Host.ConnManager().Protect(p, apiProtectTag)
}
return nil
}
func (a *NetAPI) NetProtectRemove(ctx context.Context, peers []peer.ID) error {
for _, p := range peers {
a.Host.ConnManager().Unprotect(p, apiProtectTag)
}
return nil
}
func (a *NetAPI) NetProtectList(ctx context.Context) (result []peer.ID, err error) {
for _, conn := range a.Host.Network().Conns() {
if a.Host.ConnManager().IsProtected(conn.RemotePeer(), apiProtectTag) {
result = append(result, conn.RemotePeer())
}
}
return
}