| 306 | } |
| 307 | |
| 308 | TorController::TorController(struct event_base* _base, const std::string& tor_control_center, const CService& target): |
| 309 | base(_base), |
| 310 | m_tor_control_center(tor_control_center), conn(base), reconnect(true), reconnect_ev(0), |
| 311 | reconnect_timeout(RECONNECT_TIMEOUT_START), |
| 312 | m_target(target) |
| 313 | { |
| 314 | reconnect_ev = event_new(base, -1, 0, reconnect_cb, this); |
| 315 | if (!reconnect_ev) |
| 316 | LogPrintf("tor: Failed to create event for reconnection: out of memory?\n"); |
| 317 | // Start connection attempts immediately |
| 318 | if (!conn.Connect(m_tor_control_center, std::bind(&TorController::connected_cb, this, std::placeholders::_1), |
| 319 | std::bind(&TorController::disconnected_cb, this, std::placeholders::_1) )) { |
| 320 | LogPrintf("tor: Initiating connection to Tor control port %s failed\n", m_tor_control_center); |
| 321 | } |
| 322 | // Read service private key if cached |
| 323 | std::pair<bool,std::string> pkf = ReadBinaryFile(GetPrivateKeyFile()); |
| 324 | if (pkf.first) { |
| 325 | LogPrint(BCLog::TOR, "tor: Reading cached private key from %s\n", fs::PathToString(GetPrivateKeyFile())); |
| 326 | private_key = pkf.second; |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | TorController::~TorController() |
| 331 | { |
nothing calls this directly
no test coverage detected