store incoming tokens for follow on announce_peer

This commit is contained in:
orignal committed 2026-10-09 22:24:25 -04:00
1 parent 822e4ed718
commit ca007dc57d
2 files changed
+29 -1

No files matched your search

+28 -1
View File
@@ -719,6 +719,7 @@ namespace torrents
}
uint64_t token = m_Tunnel.GetLocalDestination () ? m_Tunnel.GetLocalDestination ()->GetRng ()() : 1;
torrent->AddIncomingGetPeerNode (token, from);
m_IncomingTokens.emplace (token, std::make_pair(from, i2p::util::GetMonotonicSeconds ()));
if (torrent->HasPeers ())
SendGetPeersResponse (transactionID, torrent, token, fromIdent, fromPort + 1); // to rport
@@ -788,7 +789,23 @@ namespace torrents
LogPrint (eLogInfo, "TorrentsDHT: Announce peer token not found");
}
else
LogPrint (eLogInfo, "TorrentsDHT: Torrent for announce not found");
{
auto it = m_IncomingTokens.find (token);
if (it != m_IncomingTokens.end ())
{
auto node = it->second.first;
auto torrent = std::make_shared<DHTTorrent>();
torrent->AddIncomingGetPeerNode (token, node);
torrent->AddPeer (node->peer);
m_Torrents.emplace (infoHash, torrent);
SendResponseMsg (CreateDictionary ({
{ "id", CreateByteString (std::string_view ((const char *)m_NodeID.data (), m_NodeID.size ())) },
}),
transactionID, node->peer, node->port + 1); // to rport
}
else
LogPrint (eLogInfo, "TorrentsDHT: Token for announce not found");
}
}
void TorrentsDHT::HandleResponse (std::string_view transactionID, const NodeID& nodeID,
@@ -1181,6 +1198,16 @@ namespace torrents
it++;
}
}
{
auto it = m_IncomingTokens.begin ();
while (it != m_IncomingTokens.end ())
{
if (ts > it->second.second + DHT_INCOMING_GET_PEERS_TOKEN_EXPIRATION_TIME)
it = m_IncomingTokens.erase (it);
else
it++;
}
}
ScheduleDHTExpirationCheck ();
}
}
+1
View File
@@ -304,6 +304,7 @@ namespace torrents
NodeID m_NodeID;
std::unique_ptr<RoutingTable> m_RoutingTable;
std::map<NodeID, uint64_t> m_HeardFrom; // nodeid -> time in monotonic seconds
std::unordered_map<uint64_t, std::pair<std::shared_ptr<Node>, uint64_t> > m_IncomingTokens; // token ->(node, time in monotonic second)
// transactionID -> (ident, port, query, request info, time in monotonic seconds)
std::unordered_map<uint16_t, std::tuple<i2p::data::IdentHash, uint16_t, KRPCQuery, std::shared_ptr<RequestInfo>, uint64_t > > m_Queries;
std::map<Torrent::InfoHash, std::shared_ptr<DHTTorrent> > m_Torrents;