16
16
BanMan::BanMan (fs::path ban_file, CClientUIInterface* client_interface, int64_t default_ban_time)
17
17
: m_client_interface(client_interface), m_ban_db(std::move(ban_file)), m_default_ban_time(default_ban_time)
18
18
{
19
+ LoadBanlist ();
20
+ DumpBanlist ();
21
+ }
22
+
23
+ BanMan::~BanMan ()
24
+ {
25
+ DumpBanlist ();
26
+ }
27
+
28
+ void BanMan::LoadBanlist ()
29
+ {
30
+ LOCK (m_cs_banned);
31
+
19
32
if (m_client_interface) m_client_interface->InitMessage (_ (" Loading banlist…" ).translated );
20
33
21
34
int64_t n_start = GetTimeMillis ();
@@ -29,13 +42,6 @@ BanMan::BanMan(fs::path ban_file, CClientUIInterface* client_interface, int64_t
29
42
m_banned = {};
30
43
m_is_dirty = true ;
31
44
}
32
-
33
- DumpBanlist ();
34
- }
35
-
36
- BanMan::~BanMan ()
37
- {
38
- DumpBanlist ();
39
45
}
40
46
41
47
void BanMan::DumpBanlist ()
@@ -183,23 +189,24 @@ void BanMan::GetBanned(banmap_t& banmap)
183
189
184
190
void BanMan::SweepBanned ()
185
191
{
192
+ AssertLockHeld (m_cs_banned);
193
+
186
194
int64_t now = GetTime ();
187
195
bool notify_ui = false ;
188
- {
189
- LOCK (m_cs_banned);
190
- banmap_t ::iterator it = m_banned.begin ();
191
- while (it != m_banned.end ()) {
192
- CSubNet sub_net = (*it).first ;
193
- CBanEntry ban_entry = (*it).second ;
194
- if (!sub_net.IsValid () || now > ban_entry.nBanUntil ) {
195
- m_banned.erase (it++);
196
- m_is_dirty = true ;
197
- notify_ui = true ;
198
- LogPrint (BCLog::NET, " Removed banned node address/subnet: %s\n " , sub_net.ToString ());
199
- } else
200
- ++it;
196
+ banmap_t ::iterator it = m_banned.begin ();
197
+ while (it != m_banned.end ()) {
198
+ CSubNet sub_net = (*it).first ;
199
+ CBanEntry ban_entry = (*it).second ;
200
+ if (!sub_net.IsValid () || now > ban_entry.nBanUntil ) {
201
+ m_banned.erase (it++);
202
+ m_is_dirty = true ;
203
+ notify_ui = true ;
204
+ LogPrint (BCLog::NET, " Removed banned node address/subnet: %s\n " , sub_net.ToString ());
205
+ } else {
206
+ ++it;
201
207
}
202
208
}
209
+
203
210
// update UI
204
211
if (notify_ui && m_client_interface) {
205
212
m_client_interface->BannedListChanged ();
0 commit comments