Good point! I do not know why I chose lowercase since it also violates the coding style. Maybe it was like that before and I left it as it is even though I touched those lines and the callers.
0commit 486db14b9ce13a90b69f69dafb59d3d8932498f7 (HEAD -> fuzz_connman)
1Parent: 0802398e749c5e16fa7085cd87c91a31bbe043bd
2Author: Vasil Dimov <vd@FreeBSD.org>
3AuthorDate: Tue Sep 2 13:40:35 2025 +0200
4Commit: Vasil Dimov <vd@FreeBSD.org>
5CommitDate: Tue Sep 2 13:40:35 2025 +0200
6gpg: Signature made Tue Sep 2 13:42:45 2025 CEST
7gpg: using RSA key E64D8D45614DB07545D9CCC154DF06F64B55CBBF
8gpg: Good signature from "Vasil Dimov <vd@myforest.net>" [ultimate]
9gpg: aka "Vasil Dimov <vd@FreeBSD.org>" [ultimate]
10gpg: aka "Vasil Dimov <vasild@gmail.com>" [ultimate]
11
12
13 util: Uppercase methods of CThreadInterrupt
14
15 Rename
16
17 `CThreadInterrupt::interrupted()` -> `CThreadInterrupt::Interrupted()`
18 `CThreadInterrupt::reset()` -> `CThreadInterrupt::Reset()`
19 `CThreadInterrupt::sleep_for()` -> `CThreadInterrupt::SleepFor()`
20
21 for consistency with the coding style and to avoid confusing the
22 `reset()` method of `CThreadInterrupt` with the `reset()` methods of
23 smart pointers.
24
25diff --git a/src/i2p.cpp b/src/i2p.cpp
26index 80f3bde4cf..2ebd0b8c45 100644
27--- a/src/i2p.cpp
28+++ b/src/i2p.cpp
29@@ -159,13 +159,13 @@ bool Session::Accept(Connection& conn)
30 {
31 AssertLockNotHeld(m_mutex);
32
33 std::string errmsg;
34 bool disconnect{false};
35
36- while (!m_interrupt->interrupted()) {
37+ while (!m_interrupt->Interrupted()) {
38 Sock::Event occurred;
39 if (!conn.sock->Wait(MAX_WAIT_FOR_IO, Sock::RECV, &occurred)) {
40 errmsg = "wait on socket failed";
41 break;
42 }
43
44@@ -202,13 +202,13 @@ bool Session::Accept(Connection& conn)
45
46 conn.peer = CService(peer_addr, I2P_SAM31_PORT);
47
48 return true;
49 }
50
51- if (m_interrupt->interrupted()) {
52+ if (m_interrupt->Interrupted()) {
53 LogPrintLevel(BCLog::I2P, BCLog::Level::Debug, "Accept was interrupted\n");
54 } else {
55 LogPrintLevel(BCLog::I2P, BCLog::Level::Debug, "Error accepting%s: %s\n", disconnect ? " (will close the session)" : "", errmsg);
56 }
57 if (disconnect) {
58 LOCK(m_mutex);
59diff --git a/src/index/base.cpp b/src/index/base.cpp
60index 5767116ce5..cd36967ac6 100644
61--- a/src/index/base.cpp
62+++ b/src/index/base.cpp
63@@ -83,13 +83,13 @@ BaseIndex::~BaseIndex()
64
65 bool BaseIndex::Init()
66 {
67 AssertLockNotHeld(cs_main);
68
69 // May need reset if index is being restarted.
70- m_interrupt.reset();
71+ m_interrupt.Reset();
72
73 // m_chainstate member gives indexing code access to node internals. It is
74 // removed in followup [#24230](/bitcoin-bitcoin/24230/)
75 m_chainstate = WITH_LOCK(::cs_main,
76 return &m_chain->context()->chainman->GetChainstateForIndexing());
77 // Register to validation interface before setting the 'm_synced' flag, so that
78diff --git a/src/mapport.cpp b/src/mapport.cpp
79index 83105f51fd..4d2f1f1957 100644
80--- a/src/mapport.cpp
81+++ b/src/mapport.cpp
82@@ -110,23 +110,23 @@ static void ProcessPCP()
83 }
84 // RFC6887 11.2.1 recommends that clients send their first renewal packet at a time chosen with uniform random
85 // distribution in the range 1/2 to 5/8 of expiration time.
86 std::chrono::seconds sleep_time_min(actual_lifetime / 2);
87 std::chrono::seconds sleep_time_max(actual_lifetime * 5 / 8);
88 sleep_time = sleep_time_min + FastRandomContext().randrange<std::chrono::milliseconds>(sleep_time_max - sleep_time_min);
89- } while (ret && g_mapport_interrupt.sleep_for(sleep_time));
90+ } while (ret && g_mapport_interrupt.SleepFor(sleep_time));
91
92 // We don't delete the mappings when the thread is interrupted because this would add additional complexity, so
93 // we rather just choose a fairly short expiry time.
94 }
95
96 static void ThreadMapPort()
97 {
98 do {
99 ProcessPCP();
100- } while (g_mapport_interrupt.sleep_for(PORT_MAPPING_RETRY_PERIOD));
101+ } while (g_mapport_interrupt.SleepFor(PORT_MAPPING_RETRY_PERIOD));
102 }
103
104 void StartThreadMapPort()
105 {
106 if (!g_mapport_thread.joinable()) {
107 assert(!g_mapport_interrupt);
108@@ -152,9 +152,9 @@ void InterruptMapPort()
109 }
110
111 void StopMapPort()
112 {
113 if (g_mapport_thread.joinable()) {
114 g_mapport_thread.join();
115- g_mapport_interrupt.reset();
116+ g_mapport_interrupt.Reset();
117 }
118 }
119diff --git a/src/net.cpp b/src/net.cpp
120index 85c25543d3..ee34b09ebd 100644
121--- a/src/net.cpp
122+++ b/src/net.cpp
123@@ -2091,13 +2091,13 @@ void CConnman::SocketHandler()
124 // Check for the readiness of the already connected sockets and the
125 // listening sockets in one call ("readiness" as in poll(2) or
126 // select(2)). If none are ready, wait for a short while and return
127 // empty sets.
128 events_per_sock = GenerateWaitSockets(snap.Nodes());
129 if (events_per_sock.empty() || !events_per_sock.begin()->first->WaitMany(timeout, events_per_sock)) {
130- m_interrupt_net->sleep_for(timeout);
131+ m_interrupt_net->SleepFor(timeout);
132 }
133
134 // Service (send/receive) each of the already connected nodes.
135 SocketHandlerConnected(snap.Nodes(), events_per_sock);
136 }
137
138@@ -2108,13 +2108,13 @@ void CConnman::SocketHandler()
139 void CConnman::SocketHandlerConnected(const std::vector<CNode*>& nodes,
140 const Sock::EventsPerSock& events_per_sock)
141 {
142 AssertLockNotHeld(m_total_bytes_sent_mutex);
143
144 for (CNode* pnode : nodes) {
145- if (m_interrupt_net->interrupted()) {
146+ if (m_interrupt_net->Interrupted()) {
147 return;
148 }
149
150 //
151 // Receive
152 //
153@@ -2205,13 +2205,13 @@ void CConnman::SocketHandlerConnected(const std::vector<CNode*>& nodes,
154 }
155 }
156
157 void CConnman::SocketHandlerListening(const Sock::EventsPerSock& events_per_sock)
158 {
159 for (const ListenSocket& listen_socket : vhListenSocket) {
160- if (m_interrupt_net->interrupted()) {
161+ if (m_interrupt_net->Interrupted()) {
162 return;
163 }
164 const auto it = events_per_sock.find(listen_socket.sock);
165 if (it != events_per_sock.end() && it->second.occurred & Sock::RECV) {
166 AcceptConnection(listen_socket);
167 }
168@@ -2219,13 +2219,13 @@ void CConnman::SocketHandlerListening(const Sock::EventsPerSock& events_per_sock
169 }
170
171 void CConnman::ThreadSocketHandler()
172 {
173 AssertLockNotHeld(m_total_bytes_sent_mutex);
174
175- while (!m_interrupt_net->interrupted()) {
176+ while (!m_interrupt_net->Interrupted()) {
177 DisconnectNodes();
178 NotifyNumConnectionsChanged();
179 SocketHandler();
180 }
181 }
182
183@@ -2243,14 +2243,14 @@ void CConnman::ThreadDNSAddressSeed()
184 int outbound_connection_count = 0;
185
186 if (!gArgs.GetArgs("-seednode").empty()) {
187 auto start = NodeClock::now();
188 constexpr std::chrono::seconds SEEDNODE_TIMEOUT = 30s;
189 LogPrintf("-seednode enabled. Trying the provided seeds for %d seconds before defaulting to the dnsseeds.\n", SEEDNODE_TIMEOUT.count());
190- while (!m_interrupt_net->interrupted()) {
191- if (!m_interrupt_net->sleep_for(500ms)) {
192+ while (!m_interrupt_net->Interrupted()) {
193+ if (!m_interrupt_net->SleepFor(500ms)) {
194 return;
195 }
196
197 // Abort if we have spent enough time without reaching our target.
198 // Giving seed nodes 30 seconds so this does not become a race against fixedseeds (which triggers after 1 min)
199 if (NodeClock::now() > start + SEEDNODE_TIMEOUT) {
200@@ -2307,13 +2307,13 @@ void CConnman::ThreadDNSAddressSeed()
201 std::chrono::seconds to_wait = seeds_wait_time;
202 while (to_wait.count() > 0) {
203 // if sleeping for the MANY_PEERS interval, wake up
204 // early to see if we have enough peers and can stop
205 // this thread entirely freeing up its resources
206 std::chrono::seconds w = std::min(DNSSEEDS_DELAY_FEW_PEERS, to_wait);
207- if (!m_interrupt_net->sleep_for(w)) return;
208+ if (!m_interrupt_net->SleepFor(w)) return;
209 to_wait -= w;
210
211 if (GetFullOutboundConnCount() >= SEED_OUTBOUND_CONNECTION_THRESHOLD) {
212 if (found > 0) {
213 LogPrintf("%d addresses found from DNS seeds\n", found);
214 LogPrintf("P2P peers available. Finished DNS seeding.\n");
215@@ -2323,19 +2323,19 @@ void CConnman::ThreadDNSAddressSeed()
216 return;
217 }
218 }
219 }
220 }
221
222- if (m_interrupt_net->interrupted()) return;
223+ if (m_interrupt_net->Interrupted()) return;
224
225 // hold off on querying seeds if P2P network deactivated
226 if (!fNetworkActive) {
227 LogPrintf("Waiting for network to be reactivated before querying DNS seeds.\n");
228 do {
229- if (!m_interrupt_net->sleep_for(1s)) return;
230+ if (!m_interrupt_net->SleepFor(1s)) return;
231 } while (!fNetworkActive);
232 }
233
234 LogPrintf("Loading addresses from DNS seed %s\n", seed);
235 // If -proxy is in use, we make an ADDR_FETCH connection to the DNS resolved peer address
236 // for the base dns seed domain in chainparams
237@@ -2524,18 +2524,18 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, std
238 for (const std::string& strAddr : connect)
239 {
240 CAddress addr(CService(), NODE_NONE);
241 OpenNetworkConnection(addr, false, {}, strAddr.c_str(), ConnectionType::MANUAL, /*use_v2transport=*/use_v2transport);
242 for (int i = 0; i < 10 && i < nLoop; i++)
243 {
244- if (!m_interrupt_net->sleep_for(500ms)) {
245+ if (!m_interrupt_net->SleepFor(500ms)) {
246 return;
247 }
248 }
249 }
250- if (!m_interrupt_net->sleep_for(500ms)) {
251+ if (!m_interrupt_net->SleepFor(500ms)) {
252 return;
253 }
254 PerformReconnections();
255 }
256 }
257
258@@ -2555,13 +2555,13 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, std
259 constexpr std::chrono::seconds ADD_NEXT_SEEDNODE = 10s;
260
261 if (!add_fixed_seeds) {
262 LogPrintf("Fixed seeds are disabled\n");
263 }
264
265- while (!m_interrupt_net->interrupted()) {
266+ while (!m_interrupt_net->Interrupted()) {
267 if (add_addr_fetch) {
268 add_addr_fetch = false;
269 const auto& seed{SpanPopBack(seed_nodes)};
270 AddAddrFetch(seed);
271
272 if (addrman.Size() == 0) {
273@@ -2570,20 +2570,20 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, std
274 LogInfo("Couldn't connect to peers from addrman after %d seconds. Adding seednode (%s) to addrfetch\n", ADD_NEXT_SEEDNODE.count(), seed);
275 }
276 }
277
278 ProcessAddrFetch();
279
280- if (!m_interrupt_net->sleep_for(500ms)) {
281+ if (!m_interrupt_net->SleepFor(500ms)) {
282 return;
283 }
284
285 PerformReconnections();
286
287 CountingSemaphoreGrant<> grant(*semOutbound);
288- if (m_interrupt_net->interrupted()) {
289+ if (m_interrupt_net->Interrupted()) {
290 return;
291 }
292
293 const std::unordered_set<Network> fixed_seed_networks{GetReachableEmptyNetworks()};
294 if (add_fixed_seeds && !fixed_seed_networks.empty()) {
295 // When the node starts with an empty peers.dat, there are a few other sources of peers before
296@@ -2753,13 +2753,13 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, std
297 addrman.ResolveCollisions();
298
299 const auto current_time{NodeClock::now()};
300 int nTries = 0;
301 const auto reachable_nets{g_reachable_nets.All()};
302
303- while (!m_interrupt_net->interrupted()) {
304+ while (!m_interrupt_net->Interrupted()) {
305 if (anchor && !m_anchors.empty()) {
306 const CAddress addr = m_anchors.back();
307 m_anchors.pop_back();
308 if (!addr.IsValid() || IsLocal(addr) || !g_reachable_nets.Contains(addr) ||
309 !m_msgproc->HasAllDesirableServiceFlags(addr.nServices) ||
310 outbound_ipv46_peer_netgroups.count(m_netgroupman.GetGroup(addr))) continue;
311@@ -2855,13 +2855,13 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, std
312 break;
313 }
314
315 if (addrConnect.IsValid()) {
316 if (fFeeler) {
317 // Add small amount of random noise before connection to avoid synchronization.
318- if (!m_interrupt_net->sleep_for(rng.rand_uniform_duration<CThreadInterrupt::Clock>(FEELER_SLEEP_WINDOW))) {
319+ if (!m_interrupt_net->SleepFor(rng.rand_uniform_duration<CThreadInterrupt::Clock>(FEELER_SLEEP_WINDOW))) {
320 return;
321 }
322 LogDebug(BCLog::NET, "Making feeler connection to %s\n", addrConnect.ToStringAddrPort());
323 }
324
325 if (preferred_net != std::nullopt) LogDebug(BCLog::NET, "Making network specific connection to %s on %s.\n", addrConnect.ToStringAddrPort(), GetNetworkName(preferred_net.value()));
326@@ -2966,19 +2966,19 @@ void CConnman::ThreadOpenAddedConnections()
327 // the addednodeinfo state might change.
328 break;
329 }
330 tried = true;
331 CAddress addr(CService(), NODE_NONE);
332 OpenNetworkConnection(addr, false, std::move(grant), info.m_params.m_added_node.c_str(), ConnectionType::MANUAL, info.m_params.m_use_v2transport);
333- if (!m_interrupt_net->sleep_for(500ms)) return;
334+ if (!m_interrupt_net->SleepFor(500ms)) return;
335 grant = CountingSemaphoreGrant<>(*semAddnode, /*fTry=*/true);
336 }
337 // See if any reconnections are desired.
338 PerformReconnections();
339 // Retry every 60 seconds if a connection was attempted, otherwise two seconds
340- if (!m_interrupt_net->sleep_for(tried ? 60s : 2s)) {
341+ if (!m_interrupt_net->SleepFor(tried ? 60s : 2s)) {
342 return;
343 }
344 }
345 }
346
347 // if successful, this moves the passed grant to the constructed node
348@@ -2987,13 +2987,13 @@ void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
349 AssertLockNotHeld(m_unused_i2p_sessions_mutex);
350 assert(conn_type != ConnectionType::INBOUND);
351
352 //
353 // Initiate outbound network connection
354 //
355- if (m_interrupt_net->interrupted()) {
356+ if (m_interrupt_net->Interrupted()) {
357 return;
358 }
359 if (!fNetworkActive) {
360 return;
361 }
362 if (!pszDest) {
363@@ -3075,19 +3075,19 @@ void CConnman::ThreadI2PAcceptIncoming()
364 auto err_wait = err_wait_begin;
365
366 bool advertising_listen_addr = false;
367 i2p::Connection conn;
368
369 auto SleepOnFailure = [&]() {
370- m_interrupt_net->sleep_for(err_wait);
371+ m_interrupt_net->SleepFor(err_wait);
372 if (err_wait < err_wait_cap) {
373 err_wait += 1s;
374 }
375 };
376
377- while (!m_interrupt_net->interrupted()) {
378+ while (!m_interrupt_net->Interrupted()) {
379
380 if (!m_i2p_sam_session->Listen(conn)) {
381 if (advertising_listen_addr && conn.me.IsValid()) {
382 RemoveLocal(conn.me);
383 advertising_listen_addr = false;
384 }
385@@ -3347,13 +3347,13 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
386 }
387
388 //
389 // Start threads
390 //
391 assert(m_msgproc);
392- m_interrupt_net->reset();
393+ m_interrupt_net->Reset();
394 flagInterruptMsgProc = false;
395
396 {
397 LOCK(mutexMsgProc);
398 fMsgProcWake = false;
399 }
400diff --git a/src/test/fuzz/util/threadinterrupt.cpp b/src/test/fuzz/util/threadinterrupt.cpp
401index 5dd87e0588..5e23402447 100644
402--- a/src/test/fuzz/util/threadinterrupt.cpp
403+++ b/src/test/fuzz/util/threadinterrupt.cpp
404@@ -7,16 +7,16 @@
405
406 FuzzedThreadInterrupt::FuzzedThreadInterrupt(FuzzedDataProvider& fuzzed_data_provider)
407 : m_fuzzed_data_provider{fuzzed_data_provider}
408 {
409 }
410
411-bool FuzzedThreadInterrupt::interrupted() const
412+bool FuzzedThreadInterrupt::Interrupted() const
413 {
414 return m_fuzzed_data_provider.ConsumeBool();
415 }
416
417-bool FuzzedThreadInterrupt::sleep_for(Clock::duration)
418+bool FuzzedThreadInterrupt::SleepFor(Clock::duration)
419 {
420 SetMockTime(ConsumeTime(m_fuzzed_data_provider)); // Time could go backwards.
421 return m_fuzzed_data_provider.ConsumeBool();
422 }
423diff --git a/src/test/fuzz/util/threadinterrupt.h b/src/test/fuzz/util/threadinterrupt.h
424index d56aefd919..71ce2ddd3f 100644
425--- a/src/test/fuzz/util/threadinterrupt.h
426+++ b/src/test/fuzz/util/threadinterrupt.h
427@@ -15,14 +15,14 @@
428 */
429 class FuzzedThreadInterrupt : public CThreadInterrupt
430 {
431 public:
432 explicit FuzzedThreadInterrupt(FuzzedDataProvider& fuzzed_data_provider);
433
434- virtual bool interrupted() const override;
435- virtual bool sleep_for(Clock::duration) override;
436+ virtual bool Interrupted() const override;
437+ virtual bool SleepFor(Clock::duration) override;
438
439 private:
440 FuzzedDataProvider& m_fuzzed_data_provider;
441 };
442
443 [[nodiscard]] inline std::shared_ptr<CThreadInterrupt> ConsumeThreadInterrupt(FuzzedDataProvider& fuzzed_data_provider)
444diff --git a/src/util/threadinterrupt.cpp b/src/util/threadinterrupt.cpp
445index aaa9e831a9..8402181cf0 100644
446--- a/src/util/threadinterrupt.cpp
447+++ b/src/util/threadinterrupt.cpp
448@@ -6,23 +6,23 @@
449 #include <util/threadinterrupt.h>
450
451 #include <sync.h>
452
453 CThreadInterrupt::CThreadInterrupt() : flag(false) {}
454
455-bool CThreadInterrupt::interrupted() const
456+bool CThreadInterrupt::Interrupted() const
457 {
458 return flag.load(std::memory_order_acquire);
459 }
460
461 CThreadInterrupt::operator bool() const
462 {
463- return interrupted();
464+ return Interrupted();
465 }
466
467-void CThreadInterrupt::reset()
468+void CThreadInterrupt::Reset()
469 {
470 flag.store(false, std::memory_order_release);
471 }
472
473 void CThreadInterrupt::operator()()
474 {
475@@ -30,11 +30,11 @@ void CThreadInterrupt::operator()()
476 LOCK(mut);
477 flag.store(true, std::memory_order_release);
478 }
479 cond.notify_all();
480 }
481
482-bool CThreadInterrupt::sleep_for(Clock::duration rel_time)
483+bool CThreadInterrupt::SleepFor(Clock::duration rel_time)
484 {
485 WAIT_LOCK(mut, lock);
486 return !cond.wait_for(lock, rel_time, [this]() { return flag.load(std::memory_order_acquire); });
487 }
488diff --git a/src/util/threadinterrupt.h b/src/util/threadinterrupt.h
489index 8b393c26df..e11ff1881b 100644
490--- a/src/util/threadinterrupt.h
491+++ b/src/util/threadinterrupt.h
492@@ -30,27 +30,27 @@ public:
493
494 CThreadInterrupt();
495
496 virtual ~CThreadInterrupt() = default;
497
498 /// Return true if `operator()()` has been called.
499- virtual bool interrupted() const;
500+ virtual bool Interrupted() const;
501
502 /// An alias for `interrupted()`.
503 virtual explicit operator bool() const;
504
505 /// Interrupt any sleeps. After this `interrupted()` will return `true`.
506 virtual void operator()() EXCLUSIVE_LOCKS_REQUIRED(!mut);
507
508 /// Reset to an non-interrupted state.
509- virtual void reset();
510+ virtual void Reset();
511
512 /// Sleep for the given duration.
513 /// [@retval](/bitcoin-bitcoin/contributor/retval/) true The time passed.
514 /// [@retval](/bitcoin-bitcoin/contributor/retval/) false The sleep was interrupted.
515- virtual bool sleep_for(Clock::duration rel_time) EXCLUSIVE_LOCKS_REQUIRED(!mut);
516+ virtual bool SleepFor(Clock::duration rel_time) EXCLUSIVE_LOCKS_REQUIRED(!mut);
517
518 private:
519 std::condition_variable cond;
520 Mutex mut;
521 std::atomic<bool> flag;
522 };