@@ -81,12 +81,12 @@ class TorControlConnection
81
81
82
82
/* *
83
83
* Connect to a Tor control port.
84
- * target is address of the form host:port.
84
+ * tor_control_center is address of the form host:port.
85
85
* connected is the handler that is called when connection is successfully established.
86
86
* disconnected is a handler that is called when the connection is broken.
87
87
* Return true on success.
88
88
*/
89
- bool Connect (const std::string &target , const ConnectionCB& connected, const ConnectionCB& disconnected);
89
+ bool Connect (const std::string& tor_control_center , const ConnectionCB& connected, const ConnectionCB& disconnected);
90
90
91
91
/* *
92
92
* Disconnect from Tor control port.
@@ -193,16 +193,16 @@ void TorControlConnection::eventcb(struct bufferevent *bev, short what, void *ct
193
193
}
194
194
}
195
195
196
- bool TorControlConnection::Connect (const std::string &target , const ConnectionCB& _connected, const ConnectionCB& _disconnected)
196
+ bool TorControlConnection::Connect (const std::string& tor_control_center , const ConnectionCB& _connected, const ConnectionCB& _disconnected)
197
197
{
198
198
if (b_conn)
199
199
Disconnect ();
200
- // Parse target address:port
200
+ // Parse tor_control_center address:port
201
201
struct sockaddr_storage connect_to_addr;
202
202
int connect_to_addrlen = sizeof (connect_to_addr);
203
- if (evutil_parse_sockaddr_port (target .c_str (),
203
+ if (evutil_parse_sockaddr_port (tor_control_center .c_str (),
204
204
(struct sockaddr *)&connect_to_addr, &connect_to_addrlen)<0 ) {
205
- LogPrintf (" tor: Error parsing socket address %s\n " , target );
205
+ LogPrintf (" tor: Error parsing socket address %s\n " , tor_control_center );
206
206
return false ;
207
207
}
208
208
@@ -215,9 +215,9 @@ bool TorControlConnection::Connect(const std::string &target, const ConnectionCB
215
215
this ->connected = _connected;
216
216
this ->disconnected = _disconnected;
217
217
218
- // Finally, connect to target
218
+ // Finally, connect to tor_control_center
219
219
if (bufferevent_socket_connect (b_conn, (struct sockaddr *)&connect_to_addr, connect_to_addrlen) < 0 ) {
220
- LogPrintf (" tor: Error connecting to address %s\n " , target );
220
+ LogPrintf (" tor: Error connecting to address %s\n " , tor_control_center );
221
221
return false ;
222
222
}
223
223
return true ;
@@ -410,7 +410,7 @@ static bool WriteBinaryFile(const fs::path &filename, const std::string &data)
410
410
class TorController
411
411
{
412
412
public:
413
- TorController (struct event_base * base, const std::string& target );
413
+ TorController (struct event_base * base, const std::string& tor_control_center );
414
414
~TorController ();
415
415
416
416
/* * Get name of file to store private key in */
@@ -420,7 +420,7 @@ class TorController
420
420
void Reconnect ();
421
421
private:
422
422
struct event_base * base;
423
- std::string target ;
423
+ const std::string m_tor_control_center ;
424
424
TorControlConnection conn;
425
425
std::string private_key;
426
426
std::string service_id;
@@ -450,18 +450,18 @@ class TorController
450
450
static void reconnect_cb (evutil_socket_t fd, short what, void *arg);
451
451
};
452
452
453
- TorController::TorController (struct event_base * _base, const std::string& _target ):
453
+ TorController::TorController (struct event_base * _base, const std::string& tor_control_center ):
454
454
base(_base),
455
- target(_target ), conn(base), reconnect(true ), reconnect_ev(0 ),
455
+ m_tor_control_center(tor_control_center ), conn(base), reconnect(true ), reconnect_ev(0 ),
456
456
reconnect_timeout(RECONNECT_TIMEOUT_START)
457
457
{
458
458
reconnect_ev = event_new (base, -1 , 0 , reconnect_cb, this );
459
459
if (!reconnect_ev)
460
460
LogPrintf (" tor: Failed to create event for reconnection: out of memory?\n " );
461
461
// Start connection attempts immediately
462
- if (!conn.Connect (_target , std::bind (&TorController::connected_cb, this , std::placeholders::_1),
462
+ if (!conn.Connect (m_tor_control_center , std::bind (&TorController::connected_cb, this , std::placeholders::_1),
463
463
std::bind (&TorController::disconnected_cb, this , std::placeholders::_1) )) {
464
- LogPrintf (" tor: Initiating connection to Tor control port %s failed\n " , _target );
464
+ LogPrintf (" tor: Initiating connection to Tor control port %s failed\n " , m_tor_control_center );
465
465
}
466
466
// Read service private key if cached
467
467
std::pair<bool ,std::string> pkf = ReadBinaryFile (GetPrivateKeyFile ());
@@ -696,7 +696,7 @@ void TorController::disconnected_cb(TorControlConnection& _conn)
696
696
if (!reconnect)
697
697
return ;
698
698
699
- LogPrint (BCLog::TOR, " tor: Not connected to Tor control port %s, trying to reconnect\n " , target );
699
+ LogPrint (BCLog::TOR, " tor: Not connected to Tor control port %s, trying to reconnect\n " , m_tor_control_center );
700
700
701
701
// Single-shot timer for reconnect. Use exponential backoff.
702
702
struct timeval time = MillisToTimeval (int64_t (reconnect_timeout * 1000.0 ));
@@ -710,9 +710,9 @@ void TorController::Reconnect()
710
710
/* Try to reconnect and reestablish if we get booted - for example, Tor
711
711
* may be restarting.
712
712
*/
713
- if (!conn.Connect (target , std::bind (&TorController::connected_cb, this , std::placeholders::_1),
713
+ if (!conn.Connect (m_tor_control_center , std::bind (&TorController::connected_cb, this , std::placeholders::_1),
714
714
std::bind (&TorController::disconnected_cb, this , std::placeholders::_1) )) {
715
- LogPrintf (" tor: Re-initiating connection to Tor control port %s failed\n " , target );
715
+ LogPrintf (" tor: Re-initiating connection to Tor control port %s failed\n " , m_tor_control_center );
716
716
}
717
717
}
718
718
0 commit comments