mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 08:00:38 +03:00
select Charlie based on Alice's address type
This commit is contained in:
parent
ba078f3ff5
commit
3d1a7f173c
27
SSU.cpp
27
SSU.cpp
@ -459,8 +459,31 @@ namespace transport
|
|||||||
return GetRandomV4Session (
|
return GetRandomV4Session (
|
||||||
[excluded](std::shared_ptr<SSUSession> session)->bool
|
[excluded](std::shared_ptr<SSUSession> session)->bool
|
||||||
{
|
{
|
||||||
return session->GetState () == eSessionStateEstablished && !session->IsV6 () &&
|
return session->GetState () == eSessionStateEstablished && session != excluded;
|
||||||
session != excluded;
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Filter>
|
||||||
|
std::shared_ptr<SSUSession> SSUServer::GetRandomV6Session (Filter filter) // v6 only
|
||||||
|
{
|
||||||
|
std::vector<std::shared_ptr<SSUSession> > filteredSessions;
|
||||||
|
for (auto s :m_SessionsV6)
|
||||||
|
if (filter (s.second)) filteredSessions.push_back (s.second);
|
||||||
|
if (filteredSessions.size () > 0)
|
||||||
|
{
|
||||||
|
auto ind = rand () % filteredSessions.size ();
|
||||||
|
return filteredSessions[ind];
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<SSUSession> SSUServer::GetRandomEstablishedV6Session (std::shared_ptr<const SSUSession> excluded) // v6 only
|
||||||
|
{
|
||||||
|
return GetRandomV6Session (
|
||||||
|
[excluded](std::shared_ptr<SSUSession> session)->bool
|
||||||
|
{
|
||||||
|
return session->GetState () == eSessionStateEstablished && session != excluded;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
3
SSU.h
3
SSU.h
@ -48,6 +48,7 @@ namespace transport
|
|||||||
std::shared_ptr<SSUSession> FindSession (std::shared_ptr<const i2p::data::RouterInfo> router) const;
|
std::shared_ptr<SSUSession> FindSession (std::shared_ptr<const i2p::data::RouterInfo> router) const;
|
||||||
std::shared_ptr<SSUSession> FindSession (const boost::asio::ip::udp::endpoint& e) const;
|
std::shared_ptr<SSUSession> FindSession (const boost::asio::ip::udp::endpoint& e) const;
|
||||||
std::shared_ptr<SSUSession> GetRandomEstablishedV4Session (std::shared_ptr<const SSUSession> excluded);
|
std::shared_ptr<SSUSession> GetRandomEstablishedV4Session (std::shared_ptr<const SSUSession> excluded);
|
||||||
|
std::shared_ptr<SSUSession> GetRandomEstablishedV6Session (std::shared_ptr<const SSUSession> excluded);
|
||||||
void DeleteSession (std::shared_ptr<SSUSession> session);
|
void DeleteSession (std::shared_ptr<SSUSession> session);
|
||||||
void DeleteAllSessions ();
|
void DeleteAllSessions ();
|
||||||
|
|
||||||
@ -79,6 +80,8 @@ namespace transport
|
|||||||
void CreateSessionThroughIntroducer (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest = false);
|
void CreateSessionThroughIntroducer (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest = false);
|
||||||
template<typename Filter>
|
template<typename Filter>
|
||||||
std::shared_ptr<SSUSession> GetRandomV4Session (Filter filter);
|
std::shared_ptr<SSUSession> GetRandomV4Session (Filter filter);
|
||||||
|
template<typename Filter>
|
||||||
|
std::shared_ptr<SSUSession> GetRandomV6Session (Filter filter);
|
||||||
|
|
||||||
std::set<SSUSession *> FindIntroducers (int maxNumIntroducers);
|
std::set<SSUSession *> FindIntroducers (int maxNumIntroducers);
|
||||||
void ScheduleIntroducersUpdateTimer ();
|
void ScheduleIntroducersUpdateTimer ();
|
||||||
|
@ -1016,7 +1016,7 @@ namespace transport
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "SSU: peer test from Alice. We are Bob");
|
LogPrint (eLogDebug, "SSU: peer test from Alice. We are Bob");
|
||||||
auto session = m_Server.GetRandomEstablishedV4Session (shared_from_this ()); // Charlie, TODO: implement v6 support
|
auto session = senderEndpoint.address ().is_v4 () ? m_Server.GetRandomEstablishedV4Session (shared_from_this ()) : m_Server.GetRandomEstablishedV6Session (shared_from_this ()); // Charlie
|
||||||
if (session)
|
if (session)
|
||||||
{
|
{
|
||||||
m_Server.NewPeerTest (nonce, ePeerTestParticipantBob, shared_from_this ());
|
m_Server.NewPeerTest (nonce, ePeerTestParticipantBob, shared_from_this ());
|
||||||
|
Loading…
Reference in New Issue
Block a user