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 ()
@@ -173,23 +179,24 @@ void BanMan::GetBanned(banmap_t& banmap)
173
179
174
180
void BanMan::SweepBanned ()
175
181
{
182
+ AssertLockHeld (m_cs_banned);
183
+
176
184
int64_t now = GetTime ();
177
185
bool notify_ui = false ;
178
- {
179
- LOCK (m_cs_banned);
180
- banmap_t ::iterator it = m_banned.begin ();
181
- while (it != m_banned.end ()) {
182
- CSubNet sub_net = (*it).first ;
183
- CBanEntry ban_entry = (*it).second ;
184
- if (!sub_net.IsValid () || now > ban_entry.nBanUntil ) {
185
- m_banned.erase (it++);
186
- m_is_dirty = true ;
187
- notify_ui = true ;
188
- LogPrint (BCLog::NET, " Removed banned node address/subnet: %s\n " , sub_net.ToString ());
189
- } else
190
- ++it;
186
+ banmap_t ::iterator it = m_banned.begin ();
187
+ while (it != m_banned.end ()) {
188
+ CSubNet sub_net = (*it).first ;
189
+ CBanEntry ban_entry = (*it).second ;
190
+ if (!sub_net.IsValid () || now > ban_entry.nBanUntil ) {
191
+ m_banned.erase (it++);
192
+ m_is_dirty = true ;
193
+ notify_ui = true ;
194
+ LogPrint (BCLog::NET, " Removed banned node address/subnet: %s\n " , sub_net.ToString ());
195
+ } else {
196
+ ++it;
191
197
}
192
198
}
199
+
193
200
// update UI
194
201
if (notify_ui && m_client_interface) {
195
202
m_client_interface->BannedListChanged ();
0 commit comments