Skip to content

Commit

Permalink
neutrino: Added new method to ChainService, UnBanPeer
Browse files Browse the repository at this point in the history
Signed-off-by: Ononiwu Maureen <[email protected]>
  • Loading branch information
Chinwendu20 committed May 22, 2023
1 parent 4ba9a15 commit 3680695
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions neutrino.go
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,33 @@ func (s *ChainService) BanPeer(addr string, reason banman.Reason) error {
return s.banStore.BanIPNet(ipNet, reason, BanDuration)
}

// UnBanPeer connects and unban's a previously banned peer.
func (s *ChainService) UnBanPeer(addr string) error {
log.Warnf("UnBanning peer %v", addr)

defer func() error {
if sp := s.PeerByAddr(addr); sp != nil {
tcpAddr, err := s.addrStringToNetAddr(addr)
if err != nil {
return err
}
s.connManager.Connect(&connmgr.ConnReq{
Addr: tcpAddr,
Permanent: true,
})
return nil
}
return errors.New("Peer is nil")
}()

ipNet, err := banman.ParseIPNet(addr, nil)
if err != nil {
return fmt.Errorf("unable to parse IP network for peer %v: %v",
addr, err)
}
return s.banStore.UnBanIPNet(ipNet)
}

// IsBanned returns true if the peer is banned, and false otherwise.
func (s *ChainService) IsBanned(addr string) bool {
ipNet, err := banman.ParseIPNet(addr, nil)
Expand Down

0 comments on commit 3680695

Please sign in to comment.