Verified Commit 0169eb52 authored by Sean Coughlin's avatar Sean Coughlin

Merge pull request #1041

a9436437 NTCP: add ban list lock (oneiric)
parents b95798c6 a9436437
Pipeline #44697815 passed with stage
in 7 minutes and 18 seconds
......@@ -100,6 +100,7 @@ void NTCPServer::HandleAccept(
auto ep = conn->GetSocket().remote_endpoint(ec);
if (!ec) {
LOG(debug) << "NTCPServer: connected from " << ep;
std::unique_lock<std::mutex> l(m_BanListMutex);
auto it = m_BanList.find(ep.address());
if (it != m_BanList.end()) {
std::uint32_t ts = kovri::core::GetSecondsSinceEpoch();
......@@ -112,6 +113,7 @@ void NTCPServer::HandleAccept(
m_BanList.erase(it);
}
}
l.unlock();
if (conn)
conn->ServerLogin();
} else {
......@@ -144,6 +146,7 @@ void NTCPServer::HandleAcceptV6(
auto ep = conn->GetSocket().remote_endpoint(ec);
if (!ec) {
LOG(debug) << "NTCPServer: V6 connected from " << ep;
std::unique_lock<std::mutex> l(m_BanListMutex);
auto it = m_BanList.find(ep.address());
if (it != m_BanList.end()) {
std::uint32_t ts = kovri::core::GetSecondsSinceEpoch();
......@@ -156,6 +159,7 @@ void NTCPServer::HandleAcceptV6(
m_BanList.erase(it);
}
}
l.unlock();
if (conn)
conn->ServerLogin();
} else {
......@@ -258,11 +262,12 @@ std::shared_ptr<NTCPSession> NTCPServer::FindNTCPSession(
void NTCPServer::Ban(
const std::shared_ptr<NTCPSession>& session) {
std::uint32_t ts = kovri::core::GetSecondsSinceEpoch();
m_BanList[session->GetRemoteEndpoint().address()] =
ts + GetType(NTCPTimeoutLength::BanExpiration);
LOG(warning)
<< "NTCPServer:" << session->GetFormattedSessionInfo() << "has been banned for "
<< GetType(NTCPTimeoutLength::BanExpiration) << " seconds";
std::unique_lock<std::mutex> l(m_BanListMutex);
m_BanList[session->GetRemoteEndpoint().address()] =
ts + GetType(NTCPTimeoutLength::BanExpiration);
}
void NTCPServer::Stop() {
......
......@@ -109,6 +109,7 @@ class NTCPServer {
std::map<kovri::core::IdentHash, std::shared_ptr<NTCPSession>> m_NTCPSessions;
// IP -> ban expiration time in seconds
std::mutex m_BanListMutex;
std::map<boost::asio::ip::address, std::uint32_t> m_BanList;
public:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment