Browse Source

handle RelayIntro

pull/1752/head
orignal 2 years ago
parent
commit
e10ca637da
  1. 48
      libi2pd/SSU2.cpp
  2. 2
      libi2pd/SSU2.h

48
libi2pd/SSU2.cpp

@ -853,6 +853,8 @@ namespace transport @@ -853,6 +853,8 @@ namespace transport
}
break;
case eSSU2BlkRelayTag:
LogPrint (eLogDebug, "SSU2: RelayTag");
m_RelayTag = bufbe32toh (buf + offset);
break;
case eSSU2BlkNewToken:
{
@ -1026,8 +1028,8 @@ namespace transport @@ -1026,8 +1028,8 @@ namespace transport
s.Insert (session->GetRemoteIdentity ()->GetIdentHash (), 32); // chash
s.Insert (buf + 1, 14); // nonce, relay tag, timestamp, ver, asz
uint8_t asz = buf[14];
s.Insert (buf + 15, asz + 2); // Alice IP, Alice Port
if (!s.Verify (GetRemoteIdentity (), buf + 17 + asz))
s.Insert (buf + 15, asz); // Alice Port, Alice IP
if (!s.Verify (GetRemoteIdentity (), buf + 15 + asz))
{
LogPrint (eLogWarning, "SSU2: RelayRequest signature verification failed");
return; // TODO: send relay response
@ -1040,6 +1042,29 @@ namespace transport @@ -1040,6 +1042,29 @@ namespace transport
session->SendData (payload, payloadSize);
}
void SSU2Session::HandleRelayIntro (const uint8_t * buf, size_t len)
{
// we are Charlie
SignedData s;
s.Insert ((const uint8_t *)"RelayRequestData", 16); // prologue
s.Insert (GetRemoteIdentity ()->GetIdentHash (), 32); // bhash
s.Insert (i2p::context.GetIdentHash (), 32); // chash
s.Insert (buf + 33, 14); // nonce, relay tag, timestamp, ver, asz
uint8_t asz = buf[46];
s.Insert (buf + 47, asz); // Alice Port, Alice IP
if (!s.Verify (GetRemoteIdentity (), buf + 47 + asz))
{
LogPrint (eLogWarning, "SSU2: RelayIntro signature verification failed");
return; // TODO: send relay response
}
// TODO: send RelayResponse to Bob
boost::asio::ip::udp::endpoint ep;
if (ExtractEndpoint (buf + 47, asz, ep))
m_Server.SendHolePunch (ep);
}
bool SSU2Session::ExtractEndpoint (const uint8_t * buf, size_t size, boost::asio::ip::udp::endpoint& ep)
{
if (size < 2) return false;
@ -1580,7 +1605,10 @@ namespace transport @@ -1580,7 +1605,10 @@ namespace transport
m_SocketV6.send_to (bufs, to, 0, ec);
else
m_SocketV4.send_to (bufs, to, 0, ec);
if (!ec)
i2p::transport::transports.UpdateSentBytes (headerLen + payloadLen);
else
LogPrint (eLogError, "SSU2: Send exception: ", ec.message (), " to ", to);
}
void SSU2Server::Send (const uint8_t * header, size_t headerLen, const uint8_t * headerX, size_t headerXLen,
@ -1597,7 +1625,23 @@ namespace transport @@ -1597,7 +1625,23 @@ namespace transport
m_SocketV6.send_to (bufs, to, 0, ec);
else
m_SocketV4.send_to (bufs, to, 0, ec);
if (!ec)
i2p::transport::transports.UpdateSentBytes (headerLen + headerXLen + payloadLen);
else
LogPrint (eLogError, "SSU2: Send exception: ", ec.message (), " to ", to);
}
void SSU2Server::SendHolePunch (const boost::asio::ip::udp::endpoint& to)
{
boost::system::error_code ec;
if (to.address ().is_v6 ())
m_SocketV6.send_to (boost::asio::buffer ((uint8_t *)nullptr, 0), to, 0, ec);
else
m_SocketV4.send_to (boost::asio::buffer ((uint8_t *)nullptr, 0), to, 0, ec);
if (ec)
LogPrint (eLogError, "SSU2: Send exception: ", ec.message (), " to ", to);
}
bool SSU2Server::CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router,

2
libi2pd/SSU2.h

@ -186,6 +186,7 @@ namespace transport @@ -186,6 +186,7 @@ namespace transport
void HandleFollowOnFragment (const uint8_t * buf, size_t len);
bool ConcatOutOfSequenceFragments (std::shared_ptr<SSU2IncompleteMessage> m); // true if message complete
void HandleRelayRequest (const uint8_t * buf, size_t len);
void HandleRelayIntro (const uint8_t * buf, size_t len);
size_t CreateAddressBlock (const boost::asio::ip::udp::endpoint& ep, uint8_t * buf, size_t len);
size_t CreateAckBlock (uint8_t * buf, size_t len);
@ -257,6 +258,7 @@ namespace transport @@ -257,6 +258,7 @@ namespace transport
const boost::asio::ip::udp::endpoint& to);
void Send (const uint8_t * header, size_t headerLen, const uint8_t * headerX, size_t headerXLen,
const uint8_t * payload, size_t payloadLen, const boost::asio::ip::udp::endpoint& to);
void SendHolePunch (const boost::asio::ip::udp::endpoint& to);
bool CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router,
std::shared_ptr<const i2p::data::RouterInfo::Address> address);

Loading…
Cancel
Save