feat: add config level blocklist support

This commit is contained in:
Derrick Hammer 2024-03-09 13:12:22 -05:00
parent 42fa773b52
commit 438e76dfb8
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 12 additions and 1 deletions

View File

@ -21,7 +21,8 @@ type P2PConfig struct {
}
type PeersConfig struct {
Initial []string `mapstructure:"initial"`
Initial []string `mapstructure:"initial"`
Blocklist []string `mapstructure:"blocklist"`
}
type HTTPAPIConfig struct {

View File

@ -134,6 +134,16 @@ func (p *P2PServiceDefault) Init(ctx context.Context) error {
p.bucket = bucket
p.inited = true
for _, peer := range p.Config().P2P.Peers.Blocklist {
_, err := encoding.DecodeNodeId(peer)
if err != nil {
return err
}
p.incomingPeerBlockList.Put(peer, true)
p.outgoingPeerBlocklist.Put(peer, true)
}
return nil
}
func (p *P2PServiceDefault) ConnectToNode(connectionUris []*url.URL, retry uint, fromPeer net.Peer) error {