mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2026-10-05 20:57:48 +00:00
set DHT datagram receiver after datagram destionation initializtion. Save nodes from ping and get_peers queires
This commit is contained in:
@@ -631,19 +631,18 @@ namespace torrents
|
||||
void TorrentsDHT::HandlePingQuery (const i2p::data::IdentHash& fromIdent, uint16_t fromPort,
|
||||
std::string_view transactionID, const NodeID& nodeID)
|
||||
{
|
||||
LogPrint (eLogDebug, "TorrentsDHT: Ping query msg received");
|
||||
if (m_Nodes.emplace (nodeID, std::make_shared<Node> (nodeID, fromIdent, fromPort)).second)
|
||||
m_RoutingTable->AddNode (nodeID);
|
||||
LogPrint (eLogDebug, "TorrentsDHT: Ping query msg received from ", fromIdent.ToBase64 ());
|
||||
m_Nodes.emplace (nodeID, std::make_shared<Node> (nodeID, fromIdent, fromPort));
|
||||
m_RoutingTable->AddNode (nodeID);
|
||||
SendPingResponse (transactionID, fromIdent, fromPort + 1); // to rport
|
||||
}
|
||||
|
||||
void TorrentsDHT::HandleGetPeersQuery (const i2p::data::IdentHash& fromIdent, uint16_t fromPort,
|
||||
std::string_view transactionID, const NodeID& nodeID, const Torrent::InfoHash& infoHash)
|
||||
{
|
||||
LogPrint (eLogDebug, "TorrentsDHT: Get peers query msg received");
|
||||
LogPrint (eLogDebug, "TorrentsDHT: Get peers query msg received from ", fromIdent.ToBase64 ());
|
||||
auto [nodesIt, inserted] = m_Nodes.emplace (nodeID, std::make_shared<Node> (nodeID, fromIdent, fromPort));
|
||||
if (inserted)
|
||||
m_RoutingTable->AddNode (nodeID);
|
||||
m_RoutingTable->AddNode (nodeID);
|
||||
|
||||
std::shared_ptr<DHTTorrent> torrent;
|
||||
auto it = m_Torrents.find (infoHash);
|
||||
|
||||
@@ -66,13 +66,12 @@ namespace torrents
|
||||
{
|
||||
i2p::client::I2PService::Start ();
|
||||
m_DiskIOService.Start ();
|
||||
if (m_DHT) m_DHT->Start ();
|
||||
|
||||
auto dgramDest = GetLocalDestination ()->CreateDatagramDestination (true, i2p::datagram::eDatagramV1); // V1 for DHT
|
||||
if (dgramDest)
|
||||
dgramDest->SetRawReceiver (std::bind (&TorrentsTunnel::HandleRecvFromI2PRaw,
|
||||
std::static_pointer_cast<TorrentsTunnel>(shared_from_this ()),
|
||||
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
|
||||
if (m_DHT) m_DHT->Start ();
|
||||
|
||||
Accept ();
|
||||
|
||||
@@ -92,6 +91,7 @@ namespace torrents
|
||||
|
||||
void TorrentsTunnel::Stop ()
|
||||
{
|
||||
if (m_DHT) m_DHT->Stop ();
|
||||
auto localDestination = GetLocalDestination ();
|
||||
if (localDestination)
|
||||
{
|
||||
@@ -107,7 +107,6 @@ namespace torrents
|
||||
for (auto it: m_Torrents)
|
||||
StopTorrent (it.second);
|
||||
m_Torrents.clear ();
|
||||
if (m_DHT) m_DHT->Stop ();
|
||||
m_DiskIOService.Stop ();
|
||||
i2p::client::I2PService::ClearHandlers (); // close connections
|
||||
i2p::client::I2PService::Stop ();
|
||||
|
||||
Reference in New Issue
Block a user