lotus/node/impl/net/protect.go

36 lines
728 B
Go
Raw Permalink Normal View History

2022-02-03 16:24:49 +00:00
package net
import (
"context"
2022-08-25 18:20:41 +00:00
"github.com/libp2p/go-libp2p/core/peer"
2022-02-03 16:24:49 +00:00
)
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
}