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 <amaka013@gmail.com>
  • Loading branch information
Chinwendu20 committed Aug 22, 2023
1 parent 1334925 commit a68a32b
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 @@ -1081,6 +1081,33 @@ func (s *ChainService) BanPeer(addr string, reason banman.Reason) error {
return s.banStore.BanIPNet(ipNet, reason, BanDuration)
}

// UnbanPeer connects and unbans 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 a68a32b

Please sign in to comment.