@@ -53,6 +53,9 @@ const std::string DEFAULT_TOR_CONTROL = "127.0.0.1:" + ToString(DEFAULT_TOR_CONT
53
53
static const int TOR_COOKIE_SIZE = 32 ;
54
54
/* * Size of client/server nonce for SAFECOOKIE */
55
55
static const int TOR_NONCE_SIZE = 32 ;
56
+ /* * Tor control reply code. Ref: https://spec.torproject.org/control-spec/replies.html */
57
+ static const int TOR_REPLY_OK = 250 ;
58
+ static const int TOR_REPLY_UNRECOGNIZED = 510 ;
56
59
/* * For computing serverHash in SAFECOOKIE */
57
60
static const std::string TOR_SAFE_SERVERKEY = " Tor safe cookie authentication server-to-controller hash" ;
58
61
/* * For computing clientHash in SAFECOOKIE */
@@ -357,7 +360,7 @@ void TorController::get_socks_cb(TorControlConnection& _conn, const TorControlRe
357
360
{
358
361
// NOTE: We can only get here if -onion is unset
359
362
std::string socks_location;
360
- if (reply.code == 250 ) {
363
+ if (reply.code == TOR_REPLY_OK ) {
361
364
for (const auto & line : reply.lines ) {
362
365
if (line.starts_with (" net/listeners/socks=" )) {
363
366
const std::string port_list_str = line.substr (20 );
@@ -382,7 +385,7 @@ void TorController::get_socks_cb(TorControlConnection& _conn, const TorControlRe
382
385
} else {
383
386
LogPrintf (" tor: Get SOCKS port command returned nothing\n " );
384
387
}
385
- } else if (reply.code == 510 ) { // 510 Unrecognized command
388
+ } else if (reply.code == TOR_REPLY_UNRECOGNIZED ) {
386
389
LogPrintf (" tor: Get SOCKS port command failed with unrecognized command (You probably should upgrade Tor)\n " );
387
390
} else {
388
391
LogPrintf (" tor: Get SOCKS port command failed; error code %d\n " , reply.code );
@@ -422,7 +425,7 @@ void TorController::get_socks_cb(TorControlConnection& _conn, const TorControlRe
422
425
423
426
void TorController::add_onion_cb (TorControlConnection& _conn, const TorControlReply& reply)
424
427
{
425
- if (reply.code == 250 ) {
428
+ if (reply.code == TOR_REPLY_OK ) {
426
429
LogDebug (BCLog::TOR, " ADD_ONION successful\n " );
427
430
for (const std::string &s : reply.lines ) {
428
431
std::map<std::string,std::string> m = ParseTorReplyMapping (s);
@@ -448,7 +451,7 @@ void TorController::add_onion_cb(TorControlConnection& _conn, const TorControlRe
448
451
}
449
452
AddLocal (service, LOCAL_MANUAL);
450
453
// ... onion requested - keep connection open
451
- } else if (reply.code == 510 ) { // 510 Unrecognized command
454
+ } else if (reply.code == TOR_REPLY_UNRECOGNIZED ) {
452
455
LogPrintf (" tor: Add onion failed with unrecognized command (You probably need to upgrade Tor)\n " );
453
456
} else {
454
457
LogPrintf (" tor: Add onion failed; error code %d\n " , reply.code );
@@ -457,7 +460,7 @@ void TorController::add_onion_cb(TorControlConnection& _conn, const TorControlRe
457
460
458
461
void TorController::auth_cb (TorControlConnection& _conn, const TorControlReply& reply)
459
462
{
460
- if (reply.code == 250 ) {
463
+ if (reply.code == TOR_REPLY_OK ) {
461
464
LogDebug (BCLog::TOR, " Authentication successful\n " );
462
465
463
466
// Now that we know Tor is running setup the proxy for onion addresses
@@ -508,7 +511,7 @@ static std::vector<uint8_t> ComputeResponse(const std::string &key, const std::v
508
511
509
512
void TorController::authchallenge_cb (TorControlConnection& _conn, const TorControlReply& reply)
510
513
{
511
- if (reply.code == 250 ) {
514
+ if (reply.code == TOR_REPLY_OK ) {
512
515
LogDebug (BCLog::TOR, " SAFECOOKIE authentication challenge successful\n " );
513
516
std::pair<std::string,std::string> l = SplitTorReplyLine (reply.lines [0 ]);
514
517
if (l.first == " AUTHCHALLENGE" ) {
@@ -543,7 +546,7 @@ void TorController::authchallenge_cb(TorControlConnection& _conn, const TorContr
543
546
544
547
void TorController::protocolinfo_cb (TorControlConnection& _conn, const TorControlReply& reply)
545
548
{
546
- if (reply.code == 250 ) {
549
+ if (reply.code == TOR_REPLY_OK ) {
547
550
std::set<std::string> methods;
548
551
std::string cookiefile;
549
552
/*
0 commit comments