Skip to content

Commit

Permalink
torcontrol: Use fs::path instead of std::string for private key path
Browse files Browse the repository at this point in the history
  • Loading branch information
laanwj authored and str4d committed Oct 22, 2020
1 parent c0603a9 commit 532a0c5
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/torcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ static std::map<std::string,std::string> ParseTorReplyMapping(const std::string
* @param maxsize Puts a maximum size limit on the file that is read. If the file is larger than this, truncated data
* (with len > maxsize) will be returned.
*/
static std::pair<bool,std::string> ReadBinaryFile(const std::string &filename, size_t maxsize=std::numeric_limits<size_t>::max())
static std::pair<bool,std::string> ReadBinaryFile(const fs::path &filename, size_t maxsize=std::numeric_limits<size_t>::max())
{
FILE *f = fopen(filename.c_str(), "rb");
FILE *f = fsbridge::fopen(filename, "rb");
if (f == NULL)
return std::make_pair(false,"");
std::string retval;
Expand All @@ -392,9 +392,9 @@ static std::pair<bool,std::string> ReadBinaryFile(const std::string &filename, s
/** Write contents of std::string to a file.
* @return true on success.
*/
static bool WriteBinaryFile(const std::string &filename, const std::string &data)
static bool WriteBinaryFile(const fs::path &filename, const std::string &data)
{
FILE *f = fopen(filename.c_str(), "wb");
FILE *f = fsbridge::fopen(filename, "wb");
if (f == NULL)
return false;
if (fwrite(data.data(), 1, data.size(), f) != data.size()) {
Expand All @@ -417,7 +417,7 @@ class TorController
~TorController();

/** Get name for file to store private key in */
std::string GetPrivateKeyFile();
fs::path GetPrivateKeyFile();

/** Reconnect, after getting disconnected */
void Reconnect();
Expand Down Expand Up @@ -469,7 +469,7 @@ TorController::TorController(struct event_base* baseIn, const std::string& targe
// Read service private key if cached
std::pair<bool,std::string> pkf = ReadBinaryFile(GetPrivateKeyFile());
if (pkf.first) {
LogPrint("tor", "tor: Reading cached private key from %s\n", GetPrivateKeyFile());
LogPrint("tor", "tor: Reading cached private key from %s\n", GetPrivateKeyFile().string());
private_key = pkf.second;
}
}
Expand Down Expand Up @@ -508,9 +508,9 @@ void TorController::add_onion_cb(TorControlConnection& conn, const TorControlRep
service = CService(service_id+".onion", GetListenPort(), false);
LogPrintf("tor: Got service ID %s, advertizing service %s\n", service_id, service.ToString());
if (WriteBinaryFile(GetPrivateKeyFile(), private_key)) {
LogPrint("tor", "tor: Cached service private key to %s\n", GetPrivateKeyFile());
LogPrint("tor", "tor: Cached service private key to %s\n", GetPrivateKeyFile().string());
} else {
LogPrintf("tor: Error writing service private key to %s\n", GetPrivateKeyFile());
LogPrintf("tor: Error writing service private key to %s\n", GetPrivateKeyFile().string());
}
AddLocal(service, LOCAL_MANUAL);
// ... onion requested - keep connection open
Expand Down Expand Up @@ -720,9 +720,9 @@ void TorController::Reconnect()
}
}

std::string TorController::GetPrivateKeyFile()
fs::path TorController::GetPrivateKeyFile()
{
return (GetDataDir() / "onion_private_key").string();
return GetDataDir() / "onion_private_key";
}

void TorController::reconnect_cb(evutil_socket_t fd, short what, void *arg)
Expand Down

0 comments on commit 532a0c5

Please sign in to comment.