Changeset View
Changeset View
Standalone View
Standalone View
src/torcontrol.cpp
Show First 20 Lines • Show All 480 Lines • ▼ Show 20 Lines | |||||
void TorController::auth_cb(TorControlConnection &_conn, | void TorController::auth_cb(TorControlConnection &_conn, | ||||
const TorControlReply &reply) { | const TorControlReply &reply) { | ||||
if (reply.code == 250) { | if (reply.code == 250) { | ||||
LogPrint(BCLog::TOR, "tor: Authentication successful\n"); | LogPrint(BCLog::TOR, "tor: Authentication successful\n"); | ||||
// Now that we know Tor is running setup the proxy for onion addresses | // Now that we know Tor is running setup the proxy for onion addresses | ||||
// if -onion isn't set to something else. | // if -onion isn't set to something else. | ||||
if (GetArg("-onion", "") == "") { | if (gArgs.GetArg("-onion", "") == "") { | ||||
CService resolved(LookupNumeric("127.0.0.1", 9050)); | CService resolved(LookupNumeric("127.0.0.1", 9050)); | ||||
proxyType addrOnion = proxyType(resolved, true); | proxyType addrOnion = proxyType(resolved, true); | ||||
SetProxy(NET_TOR, addrOnion); | SetProxy(NET_TOR, addrOnion); | ||||
SetLimited(NET_TOR, false); | SetLimited(NET_TOR, false); | ||||
} | } | ||||
// Finally - now create the service | // Finally - now create the service | ||||
// No private key, generate one | // No private key, generate one | ||||
▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | if (reply.code == 250) { | ||||
s); | s); | ||||
} | } | ||||
// Prefer NULL, otherwise SAFECOOKIE. If a password is provided, use | // Prefer NULL, otherwise SAFECOOKIE. If a password is provided, use | ||||
// HASHEDPASSWORD | // HASHEDPASSWORD | ||||
/* Authentication: | /* Authentication: | ||||
* cookie: hex-encoded ~/.tor/control_auth_cookie | * cookie: hex-encoded ~/.tor/control_auth_cookie | ||||
* password: "password" | * password: "password" | ||||
*/ | */ | ||||
std::string torpassword = GetArg("-torpassword", ""); | std::string torpassword = gArgs.GetArg("-torpassword", ""); | ||||
if (!torpassword.empty()) { | if (!torpassword.empty()) { | ||||
if (methods.count("HASHEDPASSWORD")) { | if (methods.count("HASHEDPASSWORD")) { | ||||
LogPrint(BCLog::TOR, | LogPrint(BCLog::TOR, | ||||
"tor: Using HASHEDPASSWORD authentication\n"); | "tor: Using HASHEDPASSWORD authentication\n"); | ||||
boost::replace_all(torpassword, "\"", "\\\""); | boost::replace_all(torpassword, "\"", "\\\""); | ||||
_conn.Command( | _conn.Command( | ||||
"AUTHENTICATE \"" + torpassword + "\"", | "AUTHENTICATE \"" + torpassword + "\"", | ||||
boost::bind(&TorController::auth_cb, this, _1, _2)); | boost::bind(&TorController::auth_cb, this, _1, _2)); | ||||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | void TorController::reconnect_cb(evutil_socket_t fd, short what, void *arg) { | ||||
self->Reconnect(); | self->Reconnect(); | ||||
} | } | ||||
/****** Thread ********/ | /****** Thread ********/ | ||||
struct event_base *base; | struct event_base *base; | ||||
boost::thread torControlThread; | boost::thread torControlThread; | ||||
static void TorControlThread() { | static void TorControlThread() { | ||||
TorController ctrl(base, GetArg("-torcontrol", DEFAULT_TOR_CONTROL)); | TorController ctrl(base, gArgs.GetArg("-torcontrol", DEFAULT_TOR_CONTROL)); | ||||
event_base_dispatch(base); | event_base_dispatch(base); | ||||
} | } | ||||
void StartTorControl(boost::thread_group &threadGroup, CScheduler &scheduler) { | void StartTorControl(boost::thread_group &threadGroup, CScheduler &scheduler) { | ||||
assert(!base); | assert(!base); | ||||
#ifdef WIN32 | #ifdef WIN32 | ||||
evthread_use_windows_threads(); | evthread_use_windows_threads(); | ||||
Show All 27 Lines |