@@ -66,6 +66,9 @@ type Store interface {
6666
6767 // Status returns the ban status for a given IP network.
6868 Status (* net.IPNet ) (Status , error )
69+
70+ // UnbanIPNet removes the ban imposed on the specified peer.
71+ UnbanIPNet (ipNet * net.IPNet ) error
6972}
7073
7174// NewStore returns a Store backed by a database.
@@ -136,6 +139,38 @@ func (s *banStore) BanIPNet(ipNet *net.IPNet, reason Reason, duration time.Durat
136139 })
137140}
138141
142+ // UnbanIPNet removes a ban record for the IP network within the store.
143+ func (s * banStore ) UnbanIPNet (ipNet * net.IPNet ) error {
144+ err := walletdb .Update (s .db , func (tx walletdb.ReadWriteTx ) error {
145+ banStore := tx .ReadWriteBucket (banStoreBucket )
146+ if banStore == nil {
147+ return ErrCorruptedStore
148+ }
149+
150+ banIndex := banStore .NestedReadWriteBucket (banBucket )
151+ if banIndex == nil {
152+ return ErrCorruptedStore
153+ }
154+
155+ reasonIndex := banStore .NestedReadWriteBucket (reasonBucket )
156+ if reasonIndex == nil {
157+ return ErrCorruptedStore
158+ }
159+
160+ var ipNetBuf bytes.Buffer
161+ if err := encodeIPNet (& ipNetBuf , ipNet ); err != nil {
162+ return fmt .Errorf ("unable to encode %v: %v" , ipNet ,
163+ err )
164+ }
165+
166+ k := ipNetBuf .Bytes ()
167+
168+ return removeBannedIPNet (banIndex , reasonIndex , k )
169+ })
170+
171+ return err
172+ }
173+
139174// addBannedIPNet adds an entry to the ban store for the given IP network.
140175func addBannedIPNet (banIndex , reasonIndex walletdb.ReadWriteBucket ,
141176 ipNetKey []byte , reason Reason , duration time.Duration ) error {
0 commit comments