MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / ThreadControl

Method ThreadControl

src/torcontrol.cpp:390–433  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

388}
389
390void TorController::ThreadControl()
391{
392 LogDebug(BCLog::TOR, "Entering Tor control thread");
393
394 while (!m_interrupt) {
395 // Try to connect if not connected already
396 if (!m_conn.IsConnected()) {
397 LogDebug(BCLog::TOR, "Attempting to connect to Tor control port %s", m_tor_control_center);
398
399 if (!m_conn.Connect(m_tor_control_center)) {
400 LogWarning("tor: Initiating connection to Tor control port %s failed", m_tor_control_center);
401 if (!m_reconnect) {
402 break;
403 }
404 // Wait before retrying with exponential backoff
405 LogDebug(BCLog::TOR, "Retrying in %.1f seconds", m_reconnect_timeout.count());
406 if (!m_interrupt.sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(m_reconnect_timeout))) {
407 break;
408 }
409 m_reconnect_timeout = std::min(m_reconnect_timeout * RECONNECT_TIMEOUT_EXP, RECONNECT_TIMEOUT_MAX);
410 continue;
411 }
412 // Successfully connected, reset timeout and trigger connected callback
413 m_reconnect_timeout = RECONNECT_TIMEOUT_START;
414 connected_cb(m_conn);
415 }
416 // Wait for data with a timeout
417 if (!m_conn.WaitForData(std::chrono::seconds(1))) {
418 // Check if still connected
419 if (!m_conn.IsConnected()) {
420 LogDebug(BCLog::TOR, "Lost connection to Tor control port");
421 disconnected_cb(m_conn);
422 continue;
423 }
424 // Just a timeout, continue waiting
425 continue;
426 }
427 // Process incoming data
428 if (!m_conn.ReceiveAndProcess()) {
429 disconnected_cb(m_conn);
430 }
431 }
432 LogDebug(BCLog::TOR, "Exited Tor control thread");
433}
434
435void TorController::get_socks_cb(TorControlConnection& _conn, const TorControlReply& reply)
436{

Callers

nothing calls this directly

Calls 6

countMethod · 0.80
WaitForDataMethod · 0.80
ReceiveAndProcessMethod · 0.80
IsConnectedMethod · 0.45
ConnectMethod · 0.45
sleep_forMethod · 0.45

Tested by

no test coverage detected