mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 03:37:49 +02:00
remove streaming bans
This commit is contained in:
parent
a9b64893d8
commit
83932a6f02
4 changed files with 3 additions and 110 deletions
|
@ -904,10 +904,7 @@ namespace stream
|
|||
m_Owner (owner), m_LocalPort (localPort), m_Gzip (gzip),
|
||||
m_LastIncomingReceiveStreamID (0),
|
||||
m_PendingIncomingTimer (m_Owner->GetService ()),
|
||||
m_ConnTrackTimer(m_Owner->GetService()),
|
||||
m_ConnsPerMinute(DEFAULT_MAX_CONNS_PER_MIN),
|
||||
m_LastBanClear(i2p::util::GetMillisecondsSinceEpoch()),
|
||||
m_EnableDrop(false)
|
||||
m_ConnTrackTimer(m_Owner->GetService())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -923,7 +920,6 @@ namespace stream
|
|||
|
||||
void StreamingDestination::Start ()
|
||||
{
|
||||
ScheduleConnTrack();
|
||||
}
|
||||
|
||||
void StreamingDestination::Stop ()
|
||||
|
@ -971,17 +967,7 @@ namespace stream
|
|||
auto incomingStream = CreateNewIncomingStream ();
|
||||
incomingStream->HandleNextPacket (packet); // SYN
|
||||
auto ident = incomingStream->GetRemoteIdentity();
|
||||
if(ident && m_EnableDrop)
|
||||
{
|
||||
auto ih = ident->GetIdentHash();
|
||||
if(DropNewStream(ih))
|
||||
{
|
||||
// drop
|
||||
LogPrint(eLogWarning, "Streaming: Dropping connection, too many inbound streams from ", ih.ToBase32());
|
||||
incomingStream->Terminate();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_LastIncomingReceiveStreamID = receiveStreamID;
|
||||
|
||||
// handle saved packets if any
|
||||
|
@ -1176,63 +1162,5 @@ namespace stream
|
|||
return msg;
|
||||
}
|
||||
|
||||
void StreamingDestination::SetMaxConnsPerMinute(const uint32_t conns)
|
||||
{
|
||||
m_EnableDrop = conns > 0;
|
||||
m_ConnsPerMinute = conns;
|
||||
LogPrint(eLogDebug, "Streaming: Set max conns per minute per destination to ", conns);
|
||||
}
|
||||
|
||||
bool StreamingDestination::DropNewStream(const i2p::data::IdentHash & ih)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_ConnsMutex);
|
||||
if (m_Banned.size() > MAX_BANNED_CONNS) return true; // overload
|
||||
auto end = std::end(m_Banned);
|
||||
if ( std::find(std::begin(m_Banned), end, ih) != end) return true; // already banned
|
||||
auto itr = m_Conns.find(ih);
|
||||
if (itr == m_Conns.end())
|
||||
m_Conns[ih] = 0;
|
||||
|
||||
m_Conns[ih] += 1;
|
||||
|
||||
bool ban = m_Conns[ih] >= m_ConnsPerMinute;
|
||||
if (ban)
|
||||
{
|
||||
m_Banned.push_back(ih);
|
||||
m_Conns.erase(ih);
|
||||
LogPrint(eLogWarning, "Streaming: ban ", ih.ToBase32());
|
||||
}
|
||||
return ban;
|
||||
}
|
||||
|
||||
void StreamingDestination::HandleConnTrack(const boost::system::error_code& ecode)
|
||||
{
|
||||
if (ecode != boost::asio::error::operation_aborted)
|
||||
{
|
||||
{ // acquire lock
|
||||
std::lock_guard<std::mutex> lock(m_ConnsMutex);
|
||||
// clear conn tracking
|
||||
m_Conns.clear();
|
||||
// check for ban clear
|
||||
auto ts = i2p::util::GetMillisecondsSinceEpoch();
|
||||
if (ts - m_LastBanClear >= DEFAULT_BAN_INTERVAL)
|
||||
{
|
||||
// clear bans
|
||||
m_Banned.clear();
|
||||
m_LastBanClear = ts;
|
||||
}
|
||||
}
|
||||
// reschedule timer
|
||||
ScheduleConnTrack();
|
||||
}
|
||||
}
|
||||
|
||||
void StreamingDestination::ScheduleConnTrack()
|
||||
{
|
||||
m_ConnTrackTimer.expires_from_now (boost::posix_time::seconds(60));
|
||||
m_ConnTrackTimer.async_wait (
|
||||
std::bind (&StreamingDestination::HandleConnTrack,
|
||||
shared_from_this (), std::placeholders::_1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue