mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 12:24:19 +00:00
handle peer test messages 4 and 5
This commit is contained in:
parent
47460d86b2
commit
cbcee5fb45
@ -905,6 +905,21 @@ namespace data
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<const RouterInfo::Address> RouterInfo::GetSSU2Address (bool v4) const
|
||||||
|
{
|
||||||
|
if (v4)
|
||||||
|
{
|
||||||
|
if (m_SupportedTransports & eSSU2V4)
|
||||||
|
return GetSSU2V4Address ();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (m_SupportedTransports & eSSU2V6)
|
||||||
|
return GetSSU2V6Address ();
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename Filter>
|
template<typename Filter>
|
||||||
std::shared_ptr<const RouterInfo::Address> RouterInfo::GetAddress (Filter filter) const
|
std::shared_ptr<const RouterInfo::Address> RouterInfo::GetAddress (Filter filter) const
|
||||||
{
|
{
|
||||||
|
@ -193,6 +193,7 @@ namespace data
|
|||||||
std::shared_ptr<const Address> GetYggdrasilAddress () const;
|
std::shared_ptr<const Address> GetYggdrasilAddress () const;
|
||||||
std::shared_ptr<const Address> GetSSU2V4Address () const;
|
std::shared_ptr<const Address> GetSSU2V4Address () const;
|
||||||
std::shared_ptr<const Address> GetSSU2V6Address () const;
|
std::shared_ptr<const Address> GetSSU2V6Address () const;
|
||||||
|
std::shared_ptr<const Address> GetSSU2Address (bool v4) const;
|
||||||
|
|
||||||
void AddSSUAddress (const char * host, int port, const uint8_t * key, int mtu = 0);
|
void AddSSUAddress (const char * host, int port, const uint8_t * key, int mtu = 0);
|
||||||
void AddNTCP2Address (const uint8_t * staticKey, const uint8_t * iv,
|
void AddNTCP2Address (const uint8_t * staticKey, const uint8_t * iv,
|
||||||
|
@ -1361,13 +1361,13 @@ namespace transport
|
|||||||
boost::asio::ip::udp::endpoint ep;
|
boost::asio::ip::udp::endpoint ep;
|
||||||
std::shared_ptr<const i2p::data::RouterInfo::Address> addr;
|
std::shared_ptr<const i2p::data::RouterInfo::Address> addr;
|
||||||
if (ExtractEndpoint (buf + 44, len - 44, ep))
|
if (ExtractEndpoint (buf + 44, len - 44, ep))
|
||||||
addr = ep.address ().is_v4 () ? r->GetSSU2V4Address () : r->GetSSU2V6Address ();
|
addr = r->GetSSU2Address (ep.address ().is_v4 ());
|
||||||
if (addr)
|
if (addr)
|
||||||
{
|
{
|
||||||
// TODO: compare ep with addr
|
|
||||||
// send msg 5 to Alice
|
// send msg 5 to Alice
|
||||||
auto session = std::make_shared<SSU2Session> (m_Server, r, addr);
|
auto session = std::make_shared<SSU2Session> (m_Server, r, addr);
|
||||||
session->SetState (eSSU2SessionStatePeerTest);
|
session->SetState (eSSU2SessionStatePeerTest);
|
||||||
|
session->m_RemoteEndpoint = ep; // might be different
|
||||||
session->m_DestConnID = htobe64 (((uint64_t)nonce << 32) | nonce);
|
session->m_DestConnID = htobe64 (((uint64_t)nonce << 32) | nonce);
|
||||||
session->m_SourceConnID = ~session->m_SourceConnID;
|
session->m_SourceConnID = ~session->m_SourceConnID;
|
||||||
m_Server.AddSession (session);
|
m_Server.AddSession (session);
|
||||||
@ -1417,7 +1417,14 @@ namespace transport
|
|||||||
auto it = m_PeerTests.find (nonce);
|
auto it = m_PeerTests.find (nonce);
|
||||||
if (it != m_PeerTests.end ())
|
if (it != m_PeerTests.end ())
|
||||||
{
|
{
|
||||||
// TODO: update Charlie's session RouterInfo
|
auto r = i2p::data::netdb.FindRouter (buf + 3); // find Charlie
|
||||||
|
if (r && it->second.first)
|
||||||
|
{
|
||||||
|
it->second.first->SetRemoteIdentity (r->GetIdentity ());
|
||||||
|
auto addr = r->GetSSU2Address (m_Address->IsV4 ());
|
||||||
|
if (addr)
|
||||||
|
it->second.first->m_Address = addr;
|
||||||
|
}
|
||||||
m_PeerTests.erase (it);
|
m_PeerTests.erase (it);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1425,10 +1432,22 @@ namespace transport
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 5: // Alice from Charlie 1
|
case 5: // Alice from Charlie 1
|
||||||
if (htobe64 (((uint64_t)nonce << 32) | nonce) != m_SourceConnID)
|
if (htobe64 (((uint64_t)nonce << 32) | nonce) == m_SourceConnID)
|
||||||
|
{
|
||||||
|
if (m_Address)
|
||||||
|
SendPeerTest (6, buf + 3, len - 3, m_Address->i);
|
||||||
|
else
|
||||||
|
// TODO: we should wait for msg 4
|
||||||
|
LogPrint (eLogWarning, "SSU2: Unknown addrees for peer test 5");
|
||||||
|
}
|
||||||
|
else
|
||||||
LogPrint (eLogWarning, "SSU2: Peer test 5 nonce mismatch ", nonce);
|
LogPrint (eLogWarning, "SSU2: Peer test 5 nonce mismatch ", nonce);
|
||||||
break;
|
break;
|
||||||
case 6: // Charlie from Alice
|
case 6: // Charlie from Alice
|
||||||
|
if (m_Address)
|
||||||
|
SendPeerTest (7, buf + 3, len - 3, m_Address->i);
|
||||||
|
else
|
||||||
|
LogPrint (eLogWarning, "SSU2: Unknown addrees for peer test 6");
|
||||||
m_Server.RemoveSession (~htobe64 (((uint64_t)nonce << 32) | nonce));
|
m_Server.RemoveSession (~htobe64 (((uint64_t)nonce << 32) | nonce));
|
||||||
break;
|
break;
|
||||||
case 7: // Alice from Charlie 2
|
case 7: // Alice from Charlie 2
|
||||||
@ -1490,12 +1509,7 @@ namespace transport
|
|||||||
std::shared_ptr<const i2p::data::RouterInfo::Address> SSU2Session::FindLocalAddress () const
|
std::shared_ptr<const i2p::data::RouterInfo::Address> SSU2Session::FindLocalAddress () const
|
||||||
{
|
{
|
||||||
if (m_Address)
|
if (m_Address)
|
||||||
{
|
return i2p::context.GetRouterInfo ().GetSSU2Address (m_Address->IsV4 ());
|
||||||
if (m_Address->IsV4 ())
|
|
||||||
return i2p::context.GetRouterInfo ().GetSSU2V4Address ();
|
|
||||||
if (m_Address->IsV6 ())
|
|
||||||
return i2p::context.GetRouterInfo ().GetSSU2V6Address ();
|
|
||||||
}
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user