mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
i2p: log errors properly according to their severity
Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
This commit is contained in:
parent
a7bc9b76e7
commit
3d3a83fab2
2 changed files with 9 additions and 23 deletions
24
src/i2p.cpp
24
src/i2p.cpp
|
@ -146,7 +146,7 @@ bool Session::Listen(Connection& conn)
|
||||||
conn.sock = StreamAccept();
|
conn.sock = StreamAccept();
|
||||||
return true;
|
return true;
|
||||||
} catch (const std::runtime_error& e) {
|
} catch (const std::runtime_error& e) {
|
||||||
Log("Error listening: %s", e.what());
|
LogPrintLevel(BCLog::I2P, BCLog::Level::Error, "Couldn't listen: %s\n", e.what());
|
||||||
CheckControlSock();
|
CheckControlSock();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -202,7 +202,7 @@ bool Session::Accept(Connection& conn)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log("Error accepting%s: %s", disconnect ? " (will close the session)" : "", errmsg);
|
LogPrintLevel(BCLog::I2P, BCLog::Level::Debug, "Error accepting%s: %s\n", disconnect ? " (will close the session)" : "", errmsg);
|
||||||
if (disconnect) {
|
if (disconnect) {
|
||||||
LOCK(m_mutex);
|
LOCK(m_mutex);
|
||||||
Disconnect();
|
Disconnect();
|
||||||
|
@ -217,7 +217,7 @@ bool Session::Connect(const CService& to, Connection& conn, bool& proxy_error)
|
||||||
// Refuse connecting to arbitrary ports. We don't specify any destination port to the SAM proxy
|
// Refuse connecting to arbitrary ports. We don't specify any destination port to the SAM proxy
|
||||||
// when connecting (SAM 3.1 does not use ports) and it forces/defaults it to I2P_SAM31_PORT.
|
// when connecting (SAM 3.1 does not use ports) and it forces/defaults it to I2P_SAM31_PORT.
|
||||||
if (to.GetPort() != I2P_SAM31_PORT) {
|
if (to.GetPort() != I2P_SAM31_PORT) {
|
||||||
Log("Error connecting to %s, connection refused due to arbitrary port %s", to.ToStringAddrPort(), to.GetPort());
|
LogPrintLevel(BCLog::I2P, BCLog::Level::Debug, "Error connecting to %s, connection refused due to arbitrary port %s\n", to.ToStringAddrPort(), to.GetPort());
|
||||||
proxy_error = false;
|
proxy_error = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -265,7 +265,7 @@ bool Session::Connect(const CService& to, Connection& conn, bool& proxy_error)
|
||||||
|
|
||||||
throw std::runtime_error(strprintf("\"%s\"", connect_reply.full));
|
throw std::runtime_error(strprintf("\"%s\"", connect_reply.full));
|
||||||
} catch (const std::runtime_error& e) {
|
} catch (const std::runtime_error& e) {
|
||||||
Log("Error connecting to %s: %s", to.ToStringAddrPort(), e.what());
|
LogPrintLevel(BCLog::I2P, BCLog::Level::Debug, "Error connecting to %s: %s\n", to.ToStringAddrPort(), e.what());
|
||||||
CheckControlSock();
|
CheckControlSock();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -283,12 +283,6 @@ std::string Session::Reply::Get(const std::string& key) const
|
||||||
return pos->second.value();
|
return pos->second.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Args>
|
|
||||||
void Session::Log(const std::string& fmt, const Args&... args) const
|
|
||||||
{
|
|
||||||
LogPrint(BCLog::I2P, "%s\n", tfm::format(fmt, args...));
|
|
||||||
}
|
|
||||||
|
|
||||||
Session::Reply Session::SendRequestAndGetReply(const Sock& sock,
|
Session::Reply Session::SendRequestAndGetReply(const Sock& sock,
|
||||||
const std::string& request,
|
const std::string& request,
|
||||||
bool check_result_ok) const
|
bool check_result_ok) const
|
||||||
|
@ -344,7 +338,7 @@ void Session::CheckControlSock()
|
||||||
|
|
||||||
std::string errmsg;
|
std::string errmsg;
|
||||||
if (m_control_sock && !m_control_sock->IsConnected(errmsg)) {
|
if (m_control_sock && !m_control_sock->IsConnected(errmsg)) {
|
||||||
Log("Control socket error: %s", errmsg);
|
LogPrintLevel(BCLog::I2P, BCLog::Level::Debug, "Control socket error: %s\n", errmsg);
|
||||||
Disconnect();
|
Disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -414,7 +408,7 @@ void Session::CreateIfNotCreatedAlready()
|
||||||
const auto session_type = m_transient ? "transient" : "persistent";
|
const auto session_type = m_transient ? "transient" : "persistent";
|
||||||
const auto session_id = GetRandHash().GetHex().substr(0, 10); // full is overkill, too verbose in the logs
|
const auto session_id = GetRandHash().GetHex().substr(0, 10); // full is overkill, too verbose in the logs
|
||||||
|
|
||||||
Log("Creating %s SAM session %s with %s", session_type, session_id, m_control_host.ToString());
|
LogPrintLevel(BCLog::I2P, BCLog::Level::Debug, "Creating %s SAM session %s with %s\n", session_type, session_id, m_control_host.ToString());
|
||||||
|
|
||||||
auto sock = Hello();
|
auto sock = Hello();
|
||||||
|
|
||||||
|
@ -451,7 +445,7 @@ void Session::CreateIfNotCreatedAlready()
|
||||||
m_session_id = session_id;
|
m_session_id = session_id;
|
||||||
m_control_sock = std::move(sock);
|
m_control_sock = std::move(sock);
|
||||||
|
|
||||||
Log("%s SAM session %s created, my address=%s",
|
LogPrintLevel(BCLog::I2P, BCLog::Level::Info, "%s SAM session %s created, my address=%s\n",
|
||||||
Capitalize(session_type),
|
Capitalize(session_type),
|
||||||
m_session_id,
|
m_session_id,
|
||||||
m_my_addr.ToStringAddrPort());
|
m_my_addr.ToStringAddrPort());
|
||||||
|
@ -482,9 +476,9 @@ void Session::Disconnect()
|
||||||
{
|
{
|
||||||
if (m_control_sock) {
|
if (m_control_sock) {
|
||||||
if (m_session_id.empty()) {
|
if (m_session_id.empty()) {
|
||||||
Log("Destroying incomplete SAM session");
|
LogPrintLevel(BCLog::I2P, BCLog::Level::Info, "Destroying incomplete SAM session\n");
|
||||||
} else {
|
} else {
|
||||||
Log("Destroying SAM session %s", m_session_id);
|
LogPrintLevel(BCLog::I2P, BCLog::Level::Info, "Destroying SAM session %s\n", m_session_id);
|
||||||
}
|
}
|
||||||
m_control_sock.reset();
|
m_control_sock.reset();
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,14 +156,6 @@ private:
|
||||||
std::string Get(const std::string& key) const;
|
std::string Get(const std::string& key) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Log a message in the `BCLog::I2P` category.
|
|
||||||
* @param[in] fmt printf(3)-like format string.
|
|
||||||
* @param[in] args printf(3)-like arguments that correspond to `fmt`.
|
|
||||||
*/
|
|
||||||
template <typename... Args>
|
|
||||||
void Log(const std::string& fmt, const Args&... args) const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send request and get a reply from the SAM proxy.
|
* Send request and get a reply from the SAM proxy.
|
||||||
* @param[in] sock A socket that is connected to the SAM proxy.
|
* @param[in] sock A socket that is connected to the SAM proxy.
|
||||||
|
|
Loading…
Add table
Reference in a new issue