log: Use LogWarning for non-critical logs

As per doc/developer-notes#logging, LogWarning should be used for severe
problems that do not warrant shutting down the node
This commit is contained in:
MarcoFalke
2025-11-26 17:13:09 +01:00
parent fa0018d011
commit fa45a1503e
23 changed files with 116 additions and 115 deletions

View File

@@ -125,7 +125,7 @@ void TorControlConnection::readcb(struct bufferevent *bev, void *ctx)
// Do this after evbuffer_readln to make sure all full lines have been
// removed from the buffer. Everything left is an incomplete line.
if (evbuffer_get_length(input) > MAX_LINE_LENGTH) {
LogPrintf("tor: Disconnecting because MAX_LINE_LENGTH exceeded\n");
LogWarning("tor: Disconnecting because MAX_LINE_LENGTH exceeded");
self->Disconnect();
}
}
@@ -155,14 +155,14 @@ bool TorControlConnection::Connect(const std::string& tor_control_center, const
const std::optional<CService> control_service{Lookup(tor_control_center, DEFAULT_TOR_CONTROL_PORT, fNameLookup)};
if (!control_service.has_value()) {
LogPrintf("tor: Failed to look up control center %s\n", tor_control_center);
LogWarning("tor: Failed to look up control center %s", tor_control_center);
return false;
}
struct sockaddr_storage control_address;
socklen_t control_address_len = sizeof(control_address);
if (!control_service.value().GetSockAddr(reinterpret_cast<struct sockaddr*>(&control_address), &control_address_len)) {
LogPrintf("tor: Error parsing socket address %s\n", tor_control_center);
LogWarning("tor: Error parsing socket address %s", tor_control_center);
return false;
}
@@ -178,7 +178,7 @@ bool TorControlConnection::Connect(const std::string& tor_control_center, const
// Finally, connect to tor_control_center
if (bufferevent_socket_connect(b_conn, reinterpret_cast<struct sockaddr*>(&control_address), control_address_len) < 0) {
LogPrintf("tor: Error connecting to address %s\n", tor_control_center);
LogWarning("tor: Error connecting to address %s", tor_control_center);
return false;
}
return true;
@@ -330,11 +330,11 @@ TorController::TorController(struct event_base* _base, const std::string& tor_co
{
reconnect_ev = event_new(base, -1, 0, reconnect_cb, this);
if (!reconnect_ev)
LogPrintf("tor: Failed to create event for reconnection: out of memory?\n");
LogWarning("tor: Failed to create event for reconnection: out of memory?");
// Start connection attempts immediately
if (!conn.Connect(m_tor_control_center, std::bind(&TorController::connected_cb, this, std::placeholders::_1),
std::bind(&TorController::disconnected_cb, this, std::placeholders::_1) )) {
LogPrintf("tor: Initiating connection to Tor control port %s failed\n", m_tor_control_center);
LogWarning("tor: Initiating connection to Tor control port %s failed", m_tor_control_center);
}
// Read service private key if cached
std::pair<bool,std::string> pkf = ReadBinaryFile(GetPrivateKeyFile());
@@ -382,12 +382,12 @@ void TorController::get_socks_cb(TorControlConnection& _conn, const TorControlRe
if (!socks_location.empty()) {
LogDebug(BCLog::TOR, "Get SOCKS port command yielded %s\n", socks_location);
} else {
LogPrintf("tor: Get SOCKS port command returned nothing\n");
LogWarning("tor: Get SOCKS port command returned nothing");
}
} else if (reply.code == TOR_REPLY_UNRECOGNIZED) {
LogPrintf("tor: Get SOCKS port command failed with unrecognized command (You probably should upgrade Tor)\n");
LogWarning("tor: Get SOCKS port command failed with unrecognized command (You probably should upgrade Tor)");
} else {
LogPrintf("tor: Get SOCKS port command failed; error code %d\n", reply.code);
LogWarning("tor: Get SOCKS port command failed; error code %d", reply.code);
}
CService resolved;
@@ -439,9 +439,9 @@ void TorController::add_onion_cb(TorControlConnection& _conn, const TorControlRe
private_key = i->second;
}
if (service_id.empty()) {
LogPrintf("tor: Error parsing ADD_ONION parameters:\n");
LogWarning("tor: Error parsing ADD_ONION parameters:");
for (const std::string &s : reply.lines) {
LogPrintf(" %s\n", SanitizeString(s));
LogWarning(" %s", SanitizeString(s));
}
return;
}
@@ -450,14 +450,14 @@ void TorController::add_onion_cb(TorControlConnection& _conn, const TorControlRe
if (WriteBinaryFile(GetPrivateKeyFile(), private_key)) {
LogDebug(BCLog::TOR, "Cached service private key to %s\n", fs::PathToString(GetPrivateKeyFile()));
} else {
LogPrintf("tor: Error writing service private key to %s\n", fs::PathToString(GetPrivateKeyFile()));
LogWarning("tor: Error writing service private key to %s", fs::PathToString(GetPrivateKeyFile()));
}
AddLocal(service, LOCAL_MANUAL);
// ... onion requested - keep connection open
} else if (reply.code == TOR_REPLY_UNRECOGNIZED) {
LogPrintf("tor: Add onion failed with unrecognized command (You probably need to upgrade Tor)\n");
LogWarning("tor: Add onion failed with unrecognized command (You probably need to upgrade Tor)");
} else {
LogPrintf("tor: Add onion failed; error code %d\n", reply.code);
LogWarning("tor: Add onion failed; error code %d", reply.code);
}
}
@@ -481,7 +481,7 @@ void TorController::auth_cb(TorControlConnection& _conn, const TorControlReply&
_conn.Command(strprintf("ADD_ONION %s Port=%i,%s", private_key, Params().GetDefaultPort(), m_target.ToStringAddrPort()),
std::bind(&TorController::add_onion_cb, this, std::placeholders::_1, std::placeholders::_2));
} else {
LogPrintf("tor: Authentication failed\n");
LogWarning("tor: Authentication failed");
}
}
@@ -520,30 +520,30 @@ void TorController::authchallenge_cb(TorControlConnection& _conn, const TorContr
if (l.first == "AUTHCHALLENGE") {
std::map<std::string,std::string> m = ParseTorReplyMapping(l.second);
if (m.empty()) {
LogPrintf("tor: Error parsing AUTHCHALLENGE parameters: %s\n", SanitizeString(l.second));
LogWarning("tor: Error parsing AUTHCHALLENGE parameters: %s", SanitizeString(l.second));
return;
}
std::vector<uint8_t> serverHash = ParseHex(m["SERVERHASH"]);
std::vector<uint8_t> serverNonce = ParseHex(m["SERVERNONCE"]);
LogDebug(BCLog::TOR, "AUTHCHALLENGE ServerHash %s ServerNonce %s\n", HexStr(serverHash), HexStr(serverNonce));
if (serverNonce.size() != 32) {
LogPrintf("tor: ServerNonce is not 32 bytes, as required by spec\n");
LogWarning("tor: ServerNonce is not 32 bytes, as required by spec");
return;
}
std::vector<uint8_t> computedServerHash = ComputeResponse(TOR_SAFE_SERVERKEY, cookie, clientNonce, serverNonce);
if (computedServerHash != serverHash) {
LogPrintf("tor: ServerHash %s does not match expected ServerHash %s\n", HexStr(serverHash), HexStr(computedServerHash));
LogWarning("tor: ServerHash %s does not match expected ServerHash %s", HexStr(serverHash), HexStr(computedServerHash));
return;
}
std::vector<uint8_t> computedClientHash = ComputeResponse(TOR_SAFE_CLIENTKEY, cookie, clientNonce, serverNonce);
_conn.Command("AUTHENTICATE " + HexStr(computedClientHash), std::bind(&TorController::auth_cb, this, std::placeholders::_1, std::placeholders::_2));
} else {
LogPrintf("tor: Invalid reply to AUTHCHALLENGE\n");
LogWarning("tor: Invalid reply to AUTHCHALLENGE");
}
} else {
LogPrintf("tor: SAFECOOKIE authentication challenge failed\n");
LogWarning("tor: SAFECOOKIE authentication challenge failed");
}
}
@@ -591,7 +591,7 @@ void TorController::protocolinfo_cb(TorControlConnection& _conn, const TorContro
ReplaceAll(torpassword, "\"", "\\\"");
_conn.Command("AUTHENTICATE \"" + torpassword + "\"", std::bind(&TorController::auth_cb, this, std::placeholders::_1, std::placeholders::_2));
} else {
LogPrintf("tor: Password provided with -torpassword, but HASHEDPASSWORD authentication is not available\n");
LogWarning("tor: Password provided with -torpassword, but HASHEDPASSWORD authentication is not available");
}
} else if (methods.count("NULL")) {
LogDebug(BCLog::TOR, "Using NULL authentication\n");
@@ -608,18 +608,18 @@ void TorController::protocolinfo_cb(TorControlConnection& _conn, const TorContro
_conn.Command("AUTHCHALLENGE SAFECOOKIE " + HexStr(clientNonce), std::bind(&TorController::authchallenge_cb, this, std::placeholders::_1, std::placeholders::_2));
} else {
if (status_cookie.first) {
LogPrintf("tor: Authentication cookie %s is not exactly %i bytes, as is required by the spec\n", cookiefile, TOR_COOKIE_SIZE);
LogWarning("tor: Authentication cookie %s is not exactly %i bytes, as is required by the spec", cookiefile, TOR_COOKIE_SIZE);
} else {
LogPrintf("tor: Authentication cookie %s could not be opened (check permissions)\n", cookiefile);
LogWarning("tor: Authentication cookie %s could not be opened (check permissions)", cookiefile);
}
}
} else if (methods.count("HASHEDPASSWORD")) {
LogPrintf("tor: The only supported authentication mechanism left is password, but no password provided with -torpassword\n");
LogWarning("tor: The only supported authentication mechanism left is password, but no password provided with -torpassword");
} else {
LogPrintf("tor: No supported authentication method\n");
LogWarning("tor: No supported authentication method");
}
} else {
LogPrintf("tor: Requesting protocol info failed\n");
LogWarning("tor: Requesting protocol info failed");
}
}
@@ -628,7 +628,7 @@ void TorController::connected_cb(TorControlConnection& _conn)
reconnect_timeout = RECONNECT_TIMEOUT_START;
// First send a PROTOCOLINFO command to figure out what authentication is expected
if (!_conn.Command("PROTOCOLINFO 1", std::bind(&TorController::protocolinfo_cb, this, std::placeholders::_1, std::placeholders::_2)))
LogPrintf("tor: Error sending initial protocolinfo command\n");
LogWarning("tor: Error sending initial protocolinfo command");
}
void TorController::disconnected_cb(TorControlConnection& _conn)
@@ -658,7 +658,7 @@ void TorController::Reconnect()
*/
if (!conn.Connect(m_tor_control_center, std::bind(&TorController::connected_cb, this, std::placeholders::_1),
std::bind(&TorController::disconnected_cb, this, std::placeholders::_1) )) {
LogPrintf("tor: Re-initiating connection to Tor control port %s failed\n", m_tor_control_center);
LogWarning("tor: Re-initiating connection to Tor control port %s failed", m_tor_control_center);
}
}
@@ -694,7 +694,7 @@ void StartTorControl(CService onion_service_target)
#endif
gBase = event_base_new();
if (!gBase) {
LogPrintf("tor: Unable to create event_base\n");
LogWarning("tor: Unable to create event_base");
return;
}