From e420c1127567437d969f02fc8920eaabf5f8220c Mon Sep 17 00:00:00 2001 From: Ononiwu Maureen Date: Wed, 19 Apr 2023 18:58:25 +0100 Subject: [PATCH] neutrino: Added UnbanPeer method to ChainService Signed-off-by: Ononiwu Maureen --- neutrino.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/neutrino.go b/neutrino.go index 7ee45edd0..387db8b10 100644 --- a/neutrino.go +++ b/neutrino.go @@ -1081,6 +1081,24 @@ 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, parmanent bool) error { + log.Infof("UnBanning peer %v", addr) + + ipNet, err := banman.ParseIPNet(addr, nil) + if err != nil { + return fmt.Errorf("unable to parse IP network for peer %v: %v", + addr, err) + } + + err = s.banStore.UnbanIPNet(ipNet) + if err != nil { + return fmt.Errorf("unable to unban peer: %v", err) + } + + return s.ConnectNode(addr, parmanent) +} + // IsBanned returns true if the peer is banned, and false otherwise. func (s *ChainService) IsBanned(addr string) bool { ipNet, err := banman.ParseIPNet(addr, nil)