| 339 | } |
| 340 | |
| 341 | void TorController::add_onion_cb(TorControlConnection& _conn, const TorControlReply& reply) |
| 342 | { |
| 343 | if (reply.code == 250) { |
| 344 | LogPrint(BCLog::TOR, "tor: ADD_ONION successful\n"); |
| 345 | for (const std::string &s : reply.lines) { |
| 346 | std::map<std::string,std::string> m = ParseTorReplyMapping(s); |
| 347 | std::map<std::string,std::string>::iterator i; |
| 348 | if ((i = m.find("ServiceID")) != m.end()) |
| 349 | service_id = i->second; |
| 350 | if ((i = m.find("PrivateKey")) != m.end()) |
| 351 | private_key = i->second; |
| 352 | } |
| 353 | if (service_id.empty()) { |
| 354 | LogPrintf("tor: Error parsing ADD_ONION parameters:\n"); |
| 355 | for (const std::string &s : reply.lines) { |
| 356 | LogPrintf(" %s\n", SanitizeString(s)); |
| 357 | } |
| 358 | return; |
| 359 | } |
| 360 | service = LookupNumeric(std::string(service_id+".onion"), Params().GetDefaultPort()); |
| 361 | LogPrintf("tor: Got service ID %s, advertising service %s\n", service_id, service.ToString()); |
| 362 | if (WriteBinaryFile(GetPrivateKeyFile(), private_key)) { |
| 363 | LogPrint(BCLog::TOR, "tor: Cached service private key to %s\n", fs::PathToString(GetPrivateKeyFile())); |
| 364 | } else { |
| 365 | LogPrintf("tor: Error writing service private key to %s\n", fs::PathToString(GetPrivateKeyFile())); |
| 366 | } |
| 367 | AddLocal(service, LOCAL_MANUAL); |
| 368 | // ... onion requested - keep connection open |
| 369 | } else if (reply.code == 510) { // 510 Unrecognized command |
| 370 | LogPrintf("tor: Add onion failed with unrecognized command (You probably need to upgrade Tor)\n"); |
| 371 | } else { |
| 372 | LogPrintf("tor: Add onion failed; error code %d\n", reply.code); |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | void TorController::auth_cb(TorControlConnection& _conn, const TorControlReply& reply) |
| 377 | { |