mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 13:27:17 +01:00
resend relay messages
This commit is contained in:
parent
ba41f7107d
commit
5466983b36
|
@ -174,36 +174,38 @@ namespace transport
|
||||||
// create nonce
|
// create nonce
|
||||||
uint32_t nonce;
|
uint32_t nonce;
|
||||||
RAND_bytes ((uint8_t *)&nonce, 4);
|
RAND_bytes ((uint8_t *)&nonce, 4);
|
||||||
auto ts = i2p::util::GetSecondsSinceEpoch ();
|
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
||||||
// payload
|
// payload
|
||||||
uint8_t payload[SSU2_MAX_PACKET_SIZE];
|
auto packet = m_Server.GetSentPacketsPool ().AcquireShared ();
|
||||||
size_t payloadSize = 0;
|
uint8_t * payload = packet->payload;
|
||||||
payload[0] = eSSU2BlkRelayRequest;
|
payload[0] = eSSU2BlkRelayRequest;
|
||||||
payload[3] = 0; // flag
|
payload[3] = 0; // flag
|
||||||
htobe32buf (payload + 4, nonce);
|
htobe32buf (payload + 4, nonce);
|
||||||
htobe32buf (payload + 8, relayTag);
|
htobe32buf (payload + 8, relayTag);
|
||||||
htobe32buf (payload + 12, ts);
|
htobe32buf (payload + 12, ts/1000);
|
||||||
payload[16] = 2; // ver
|
payload[16] = 2; // ver
|
||||||
size_t asz = CreateEndpoint (payload + 18, m_MaxPayloadSize - 18, boost::asio::ip::udp::endpoint (localAddress->host, localAddress->port));
|
size_t asz = CreateEndpoint (payload + 18, m_MaxPayloadSize - 18, boost::asio::ip::udp::endpoint (localAddress->host, localAddress->port));
|
||||||
if (!asz) return false;
|
if (!asz) return false;
|
||||||
payload[17] = asz;
|
payload[17] = asz;
|
||||||
payloadSize += asz + 18;
|
packet->payloadSize = asz + 18;
|
||||||
SignedData s;
|
SignedData s;
|
||||||
s.Insert ((const uint8_t *)"RelayRequestData", 16); // prologue
|
s.Insert ((const uint8_t *)"RelayRequestData", 16); // prologue
|
||||||
s.Insert (GetRemoteIdentity ()->GetIdentHash (), 32); // bhash
|
s.Insert (GetRemoteIdentity ()->GetIdentHash (), 32); // bhash
|
||||||
s.Insert (session->GetRemoteIdentity ()->GetIdentHash (), 32); // chash
|
s.Insert (session->GetRemoteIdentity ()->GetIdentHash (), 32); // chash
|
||||||
s.Insert (payload + 4, 14 + asz); // nonce, relay tag, timestamp, ver, asz and Alice's endpoint
|
s.Insert (payload + 4, 14 + asz); // nonce, relay tag, timestamp, ver, asz and Alice's endpoint
|
||||||
s.Sign (i2p::context.GetPrivateKeys (), payload + payloadSize);
|
s.Sign (i2p::context.GetPrivateKeys (), payload + packet->payloadSize);
|
||||||
payloadSize += i2p::context.GetIdentity ()->GetSignatureLen ();
|
packet->payloadSize += i2p::context.GetIdentity ()->GetSignatureLen ();
|
||||||
htobe16buf (payload + 1, payloadSize - 3); // size
|
htobe16buf (payload + 1, packet->payloadSize - 3); // size
|
||||||
payloadSize += CreatePaddingBlock (payload + payloadSize, m_MaxPayloadSize - payloadSize);
|
packet->payloadSize += CreatePaddingBlock (payload + packet->payloadSize, m_MaxPayloadSize - packet->payloadSize);
|
||||||
// send
|
// send
|
||||||
m_RelaySessions.emplace (nonce, std::make_pair (session, ts));
|
m_RelaySessions.emplace (nonce, std::make_pair (session, ts/1000));
|
||||||
session->m_SourceConnID = htobe64 (((uint64_t)nonce << 32) | nonce);
|
session->m_SourceConnID = htobe64 (((uint64_t)nonce << 32) | nonce);
|
||||||
session->m_DestConnID = ~session->m_SourceConnID;
|
session->m_DestConnID = ~session->m_SourceConnID;
|
||||||
m_Server.AddSession (session);
|
m_Server.AddSession (session);
|
||||||
SendData (payload, payloadSize);
|
int32_t packetNum = SendData (packet->payload, packet->payloadSize);
|
||||||
|
packet->sendTime = ts;
|
||||||
|
m_SentPackets.emplace (packetNum, packet);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1945,27 +1947,31 @@ namespace transport
|
||||||
SendData (payload, payloadSize);
|
SendData (payload, payloadSize);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
auto mts = i2p::util::GetMillisecondsSinceEpoch ();
|
||||||
session->m_RelaySessions.emplace (bufbe32toh (buf + 1), // nonce
|
session->m_RelaySessions.emplace (bufbe32toh (buf + 1), // nonce
|
||||||
std::make_pair (shared_from_this (), i2p::util::GetSecondsSinceEpoch ()) );
|
std::make_pair (shared_from_this (), mts/1000) );
|
||||||
|
|
||||||
// send relay intro to Charlie
|
// send relay intro to Charlie
|
||||||
auto r = i2p::data::netdb.FindRouter (GetRemoteIdentity ()->GetIdentHash ()); // Alice's RI
|
auto r = i2p::data::netdb.FindRouter (GetRemoteIdentity ()->GetIdentHash ()); // Alice's RI
|
||||||
if (r && (r->IsUnreachable () || !i2p::data::netdb.PopulateRouterInfoBuffer (r))) r = nullptr;
|
if (r && (r->IsUnreachable () || !i2p::data::netdb.PopulateRouterInfoBuffer (r))) r = nullptr;
|
||||||
if (!r) LogPrint (eLogWarning, "SSU2: RelayRequest Alice's router info not found");
|
if (!r) LogPrint (eLogWarning, "SSU2: RelayRequest Alice's router info not found");
|
||||||
|
|
||||||
uint8_t payload[SSU2_MAX_PACKET_SIZE];
|
auto packet = m_Server.GetSentPacketsPool ().AcquireShared ();
|
||||||
size_t payloadSize = r ? CreateRouterInfoBlock (payload, m_MaxPayloadSize - len - 32, r) : 0;
|
packet->payloadSize = r ? CreateRouterInfoBlock (packet->payload, m_MaxPayloadSize - len - 32, r) : 0;
|
||||||
if (!payloadSize && r)
|
if (!packet->payloadSize && r)
|
||||||
session->SendFragmentedMessage (CreateDatabaseStoreMsg (r));
|
session->SendFragmentedMessage (CreateDatabaseStoreMsg (r));
|
||||||
payloadSize += CreateRelayIntroBlock (payload + payloadSize, m_MaxPayloadSize - payloadSize, buf + 1, len -1);
|
packet->payloadSize += CreateRelayIntroBlock (packet->payload + packet->payloadSize, m_MaxPayloadSize - packet->payloadSize, buf + 1, len -1);
|
||||||
if (payloadSize < m_MaxPayloadSize)
|
if (packet->payloadSize < m_MaxPayloadSize)
|
||||||
payloadSize += CreatePaddingBlock (payload + payloadSize, m_MaxPayloadSize - payloadSize);
|
packet->payloadSize += CreatePaddingBlock (packet->payload + packet->payloadSize, m_MaxPayloadSize - packet->payloadSize);
|
||||||
session->SendData (payload, payloadSize);
|
uint32_t packetNum = session->SendData (packet->payload, packet->payloadSize);
|
||||||
|
packet->sendTime = mts;
|
||||||
|
session->m_SentPackets.emplace (packetNum, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSU2Session::HandleRelayIntro (const uint8_t * buf, size_t len, int attempts)
|
void SSU2Session::HandleRelayIntro (const uint8_t * buf, size_t len, int attempts)
|
||||||
{
|
{
|
||||||
// we are Charlie
|
// we are Charlie
|
||||||
|
auto mts = i2p::util::GetMillisecondsSinceEpoch ();
|
||||||
SSU2RelayResponseCode code = eSSU2RelayResponseCodeAccept;
|
SSU2RelayResponseCode code = eSSU2RelayResponseCodeAccept;
|
||||||
uint64_t token = 0;
|
uint64_t token = 0;
|
||||||
bool isV4 = false;
|
bool isV4 = false;
|
||||||
|
@ -1993,7 +1999,7 @@ namespace transport
|
||||||
token = m_Server.GetIncomingToken (ep);
|
token = m_Server.GetIncomingToken (ep);
|
||||||
isV4 = ep.address ().is_v4 ();
|
isV4 = ep.address ().is_v4 ();
|
||||||
SendHolePunch (bufbe32toh (buf + 33), ep, addr->i, token);
|
SendHolePunch (bufbe32toh (buf + 33), ep, addr->i, token);
|
||||||
m_Server.AddConnectedRecently (ep, i2p::util::GetSecondsSinceEpoch ());
|
m_Server.AddConnectedRecently (ep, mts/1000);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -2038,11 +2044,13 @@ namespace transport
|
||||||
code = eSSU2RelayResponseCodeCharlieAliceIsUnknown;
|
code = eSSU2RelayResponseCodeCharlieAliceIsUnknown;
|
||||||
}
|
}
|
||||||
// send relay response to Bob
|
// send relay response to Bob
|
||||||
uint8_t payload[SSU2_MAX_PACKET_SIZE];
|
auto packet = m_Server.GetSentPacketsPool ().AcquireShared ();
|
||||||
size_t payloadSize = CreateRelayResponseBlock (payload, m_MaxPayloadSize,
|
packet->payloadSize = CreateRelayResponseBlock (packet->payload, m_MaxPayloadSize,
|
||||||
code, bufbe32toh (buf + 33), token, isV4);
|
code, bufbe32toh (buf + 33), token, isV4);
|
||||||
payloadSize += CreatePaddingBlock (payload + payloadSize, m_MaxPayloadSize - payloadSize);
|
packet->payloadSize += CreatePaddingBlock (packet->payload + packet->payloadSize, m_MaxPayloadSize - packet->payloadSize);
|
||||||
SendData (payload, payloadSize);
|
uint32_t packetNum = SendData (packet->payload, packet->payloadSize);
|
||||||
|
packet->sendTime = mts;
|
||||||
|
m_SentPackets.emplace (packetNum, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSU2Session::HandleRelayResponse (const uint8_t * buf, size_t len)
|
void SSU2Session::HandleRelayResponse (const uint8_t * buf, size_t len)
|
||||||
|
|
Loading…
Reference in a new issue