@@ -295,7 +295,7 @@ namespace torrents
295295 return len;
296296 }
297297
298- std::string Torrent::GetHexStraingInfoHash () const
298+ std::string Torrent::GetHexStringInfoHash () const
299299 {
300300 std::string infoHash;
301301 BIGNUM * bn = BN_bin2bn (m_InfoHash.data (), SHA_DIGEST_LENGTH , nullptr );
@@ -313,7 +313,7 @@ namespace torrents
313313 {
314314 i2p::http::HTTPReq req;
315315 req.parse (m_Announce);
316- req.AddHeader (" info_hash" , GetHexStraingInfoHash ());
316+ req.AddHeader (" info_hash" , GetHexStringInfoHash ());
317317 return req;
318318 }
319319
@@ -336,32 +336,14 @@ namespace torrents
336336 size_t Torrent::ParsePeers (std::string_view buf)
337337 {
338338 m_Peers.clear ();
339- return ParseList (buf, std::bind (&Torrent::ParsePeer, this , std::placeholders::_1));
340- }
341-
342- size_t Torrent::ParsePeer (std::string_view buf)
343- {
344- std::string peerID;
345- std::shared_ptr<const i2p::client::Address> addr;
346- size_t ret = ParseDictionary (buf, [&peerID, &addr](std::string_view key, std::string_view buf)->size_t
347- {
348- if (key == " id" ) // peer_id
349- {
350- auto [id, l] = ExtractByteString (buf);
351- if (l) peerID = id;
352- return l;
353- }
354- else if (key == " ip" ) // address
355- {
356- auto [address, l] = ExtractByteString (buf);
357- if (l) addr = i2p::client::context.GetAddressBook ().GetAddress (address);
358- return l;
359- }
360- return 0 ;
361- });
362- if (ret && addr)
363- m_Peers.emplace_back (std::pair{ peerID, addr });
364- return ret;
339+ auto [hashes, len] = ExtractByteString (buf);
340+ while (!hashes.empty ())
341+ {
342+ m_Peers.emplace_back (std::make_shared<const i2p::client::Address>(
343+ i2p::data::IdentHash ((const uint8_t *)hashes.substr (0 , SHA256_DIGEST_LENGTH ).data ())));
344+ hashes = hashes.substr (SHA256_DIGEST_LENGTH );
345+ }
346+ return len;
365347 }
366348
367349 PeerConnection::PeerConnection (i2p::client::I2PService * owner, std::shared_ptr<i2p::stream::Stream> stream):
@@ -745,12 +727,12 @@ namespace torrents
745727 return ;
746728 }
747729 req.AddHeader (" peer_id" , m_PeerID);
748- req.AddHeader (" ip" , GetLocalDestination ()->GetIdentHash (). ToBase32 () + " .b32.i2p " );
730+ req.AddHeader (" ip" , GetLocalDestination ()->GetIdentity ()-> ToBase64 ());
749731 req.AddHeader (" port" , std::to_string (6881 ));
732+ req.AddHeader (" compact" , " 1" );
750733 req.AddHeader (" uploaded" , " 0" ); // TODO
751734 req.AddHeader (" downloaded" , " 0" ); // TODO
752735 req.AddHeader (" left" , " 1" ); // TODO
753- req.AddHeader (" compact" , " 1" ); // TODO
754736 req.AddHeader (" numwant" , " 0" ); // TODO
755737 CreateStream ([this , req, torrent](std::shared_ptr<i2p::stream::Stream> stream)
756738 {
0 commit comments