diff --git a/libtransmission/torrent-metainfo.cc b/libtransmission/torrent-metainfo.cc index 49afdf6b4..c92c7423d 100644 --- a/libtransmission/torrent-metainfo.cc +++ b/libtransmission/torrent-metainfo.cc @@ -382,6 +382,21 @@ struct MetainfoHandler final : public transmission::benc::BasicHandler(std::data(tm_.info_hash_))); + tm_.info_hash_str_ = tr_sha1_to_string(tm_.info_hash_); + tm_.has_magnet_info_hash_ = true; + } + } else if ( pathIs(ChecksumKey) || // pathIs(ErrCallbackKey) || // @@ -495,6 +510,12 @@ private: bool finish(Context const& context) { + // Support Transmission <= 3.0 magnets stored in torrent format. + if (tm_.has_magnet_info_hash_) + { + return true; + } + // bittorrent 1.0 spec // http://bittorrent.org/beps/bep_0003.html // @@ -544,6 +565,7 @@ private: static constexpr std::string_view CreatedByKey = "created by"sv; static constexpr std::string_view CreatedByUtf8Key = "created by.utf-8"sv; static constexpr std::string_view CreationDateKey = "creation date"sv; + static constexpr std::string_view DisplayNameKey = "display-name"sv; static constexpr std::string_view DurationKey = "duration"sv; static constexpr std::string_view Ed2kKey = "ed2k"sv; static constexpr std::string_view EncodedRateKey = "encoded rate"sv; @@ -558,6 +580,7 @@ private: static constexpr std::string_view HeightKey = "height"sv; static constexpr std::string_view HttpSeedsKey = "httpseeds"sv; static constexpr std::string_view InfoKey = "info"sv; + static constexpr std::string_view InfoHashKey = "info_hash"sv; static constexpr std::string_view LengthKey = "length"sv; static constexpr std::string_view LibtorrentResumeKey = "libtorrent_resume"sv; static constexpr std::string_view LocaleKey = "locale"sv; diff --git a/libtransmission/torrent-metainfo.h b/libtransmission/torrent-metainfo.h index 55ca6b406..6aec4a629 100644 --- a/libtransmission/torrent-metainfo.h +++ b/libtransmission/torrent-metainfo.h @@ -243,6 +243,7 @@ private: // Used when loading piece checksums on demand. uint64_t pieces_offset_ = 0; + bool has_magnet_info_hash_ = false; bool is_private_ = false; bool is_v2_ = false; }; diff --git a/tests/libtransmission/assets/gimp-2.10.32-1-arm64.dmg.torrent b/tests/libtransmission/assets/gimp-2.10.32-1-arm64.dmg.torrent new file mode 100644 index 000000000..8a0e61717 --- /dev/null +++ b/tests/libtransmission/assets/gimp-2.10.32-1-arm64.dmg.torrent @@ -0,0 +1 @@ +d13:announce-listll42:udp://tracker.opentrackr.org:1337/announceel43:udp://tracker.coppersurfer.tk:6969/announceel49:udp://tracker.leechers-paradise.org:6969/announceel44:udp://tracker.openbittorrent.com:80/announceel40:https://ashrise.com:443/phoenix/announceee11:magnet-infod12:display-name24:gimp-2.10.32-1-arm64.dmg9:info_hash20:ÀG¸u˜ðôºå­ôÉúiÒËe8:url-listl49:https://ftp.acc.umu.se/pub/gimp/gimp/v2.10/macos/56:https://ftp.cc.uoc.gr/mirrors/gimp/pub/gimp/v2.10/macos/41:https://ftp.fau.de/gimp/gimp/v2.10/macos/57:https://ftp.gwdg.de/pub/grafik/gimp-org/gimp/v2.10/macos/58:https://ftp.icm.edu.pl/pub/graphics/gimp/gimp/v2.10/macos/57:https://ftp.kr.freebsd.org/pub/gimp/pub/gimp/v2.10/macos/53:https://ftp.lysator.liu.se/pub/gimp/gimp/v2.10/macos/62:https://ftp.snt.utwente.nl/pub/software/gimp/gimp/v2.10/macos/46:https://gimp.astra.in.ua/pub/gimp/v2.10/macos/46:https://gimp.ip-connect.info/gimp/v2.10/macos/47:https://gimp.ip-connect.vn.ua/gimp/v2.10/macos/47:https://mirror.dogado.de/gimp/gimp/v2.10/macos/53:https://mirror.edgeuno.net/gimp/pub/gimp/v2.10/macos/46:https://mirror.fcix.net/gimp/gimp/v2.10/macos/53:https://mirror.freedif.org/gimp/pub/gimp/v2.10/macos/54:https://mirror.kumi.systems/gimp/pub/gimp/v2.10/macos/48:https://mirror.metanet.ch/gimp/gimp/v2.10/macos/48:https://mirror.nju.edu.cn/gimp/gimp/v2.10/macos/46:https://mirror.surf/gimp/pub/gimp/v2.10/macos/45:https://mirror.umd.edu/gimp/gimp/v2.10/macos/70:https://mirror2.sandyriver.net/pub/software/gimp/pub/gimp/v2.10/macos/53:https://mirrors.dotsrc.org/gimp/pub/gimp/v2.10/macos/59:https://mirrors.gethosted.online/gimp/pub/gimp/v2.10/macos/59:https://mirrors.ocf.berkeley.edu/gimp/pub/gimp/v2.10/macos/65:https://mirrors.ukfast.co.uk/sites/gimp.org/pub/gimp/v2.10/macos/51:https://mirrors.xmission.com/gimp/gimp/v2.10/macos/52:https://paducahix.mm.fcix.net/gimp/gimp/v2.10/macos/50:https://www-ftp.lip6.fr/pub/gimp/gimp/v2.10/macos/48:https://www.gimp.ca/mirror/pub/gimp/v2.10/macos/70:https://www.mirrorservice.org/sites/ftp.gimp.org/pub/gimp/v2.10/macos/71:https://www.nic.funet.fi/pub/mirrors/ftp.gimp.org/pub/gimp/v2.10/macos/43:https://download.gimp.org/gimp/v2.10/macos/ee \ No newline at end of file diff --git a/tests/libtransmission/torrent-metainfo-test.cc b/tests/libtransmission/torrent-metainfo-test.cc index 48c1a9137..2f69cea21 100644 --- a/tests/libtransmission/torrent-metainfo-test.cc +++ b/tests/libtransmission/torrent-metainfo-test.cc @@ -219,6 +219,14 @@ TEST_F(TorrentMetainfoTest, ctorSaveContents) tr_ctorFree(ctor); } +TEST_F(TorrentMetainfoTest, magnetInfoHash) +{ + // compatibility with magnet torrents created by Transmission <= 3.0 + auto const src_filename = tr_pathbuf{ LIBTRANSMISSION_TEST_ASSETS_DIR, "/gimp-2.10.32-1-arm64.dmg.torrent"sv }; + auto tm = tr_torrent_metainfo{}; + EXPECT_TRUE(tm.parseTorrentFile(src_filename)); +} + TEST_F(TorrentMetainfoTest, HoffmanStyleWebseeds) { auto const src_filename = tr_pathbuf{ LIBTRANSMISSION_TEST_ASSETS_DIR, "/debian-11.2.0-amd64-DVD-1.iso.torrent"sv };