GetRandomEstablishedSession
This commit is contained in:
24
SSU.cpp
24
SSU.cpp
@@ -1058,6 +1058,30 @@ namespace ssu
|
|||||||
}
|
}
|
||||||
m_Sessions.clear ();
|
m_Sessions.clear ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Filter>
|
||||||
|
SSUSession * SSUServer::GetRandomSession (Filter filter)
|
||||||
|
{
|
||||||
|
std::vector<SSUSession *> filteredSessions;
|
||||||
|
for (auto s :m_Sessions)
|
||||||
|
if (filter (s.second)) filteredSessions.push_back (s.second);
|
||||||
|
if (filteredSessions.size () > 0)
|
||||||
|
{
|
||||||
|
auto ind = i2p::context.GetRandomNumberGenerator ().GenerateWord32 (0, filteredSessions.size ()-1);
|
||||||
|
return filteredSessions[ind];
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSUSession * SSUServer::GetRandomEstablishedSession ()
|
||||||
|
{
|
||||||
|
return GetRandomSession (
|
||||||
|
[](SSUSession * session)->bool
|
||||||
|
{
|
||||||
|
return session->GetState () == eSessionStateEstablished;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
SSU.h
4
SSU.h
@@ -147,6 +147,7 @@ namespace ssu
|
|||||||
SSUSession * GetSession (const i2p::data::RouterInfo * router, bool peerTest = false);
|
SSUSession * GetSession (const i2p::data::RouterInfo * router, bool peerTest = false);
|
||||||
SSUSession * FindSession (const i2p::data::RouterInfo * router);
|
SSUSession * FindSession (const i2p::data::RouterInfo * router);
|
||||||
SSUSession * FindSession (const boost::asio::ip::udp::endpoint& e);
|
SSUSession * FindSession (const boost::asio::ip::udp::endpoint& e);
|
||||||
|
SSUSession * GetRandomEstablishedSession ();
|
||||||
void DeleteSession (SSUSession * session);
|
void DeleteSession (SSUSession * session);
|
||||||
void DeleteAllSessions ();
|
void DeleteAllSessions ();
|
||||||
|
|
||||||
@@ -162,6 +163,9 @@ namespace ssu
|
|||||||
void Receive ();
|
void Receive ();
|
||||||
void HandleReceivedFrom (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
void HandleReceivedFrom (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
||||||
|
|
||||||
|
template<typename Filter>
|
||||||
|
SSUSession * GetRandomSession (Filter filter);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool m_IsRunning;
|
bool m_IsRunning;
|
||||||
|
Reference in New Issue
Block a user