diff --git a/docs/Editing-Configuration-Files.md b/docs/Editing-Configuration-Files.md index 41fabcd20..bc025dcf4 100644 --- a/docs/Editing-Configuration-Files.md +++ b/docs/Editing-Configuration-Files.md @@ -95,7 +95,6 @@ Here is a sample of the three basic types: respectively Boolean, Number and Stri * **bind-address-ipv4:** String (default = "0.0.0.0") Where to listen for peer connections. * **bind-address-ipv6:** String (default = "::") Where to listen for peer connections. * **peer-congestion-algorithm:** String. This is documented on https://www.pps.jussieu.fr/~jch/software/bittorrent/tcp-congestion-control.html. - * **peer-id-ttl-hours:** Number (default = 6) Recycle the peer id used for public torrents after N hours of use. * **peer-limit-global:** Number (default = 240) * **peer-limit-per-torrent:** Number (default = 60) * **peer-socket-tos:** String (default = "default") Set the [Type-Of-Service (TOS)](https://en.wikipedia.org/wiki/Type_of_Service) parameter for outgoing TCP packets. Possible values are "default", "lowcost", "throughput", "lowdelay" and "reliability". The value "lowcost" is recommended if you're using a smart router, and shouldn't harm in any case. diff --git a/libtransmission/announcer.cc b/libtransmission/announcer.cc index 8155efb0f..65f7491e2 100644 --- a/libtransmission/announcer.cc +++ b/libtransmission/announcer.cc @@ -910,7 +910,7 @@ void on_announce_error(tr_tier* tier, char const* err, tr_announce_event e) req.announce_url = current_tracker->announce_url; req.tracker_id = current_tracker->tracker_id; req.info_hash = tor->infoHash(); - req.peer_id = tr_torrentGetPeerId(tor); + req.peer_id = tor->peer_id(); req.up = tier->byteCounts[TR_ANN_UP]; req.down = tier->byteCounts[TR_ANN_DOWN]; req.corrupt = tier->byteCounts[TR_ANN_CORRUPT]; diff --git a/libtransmission/peer-mgr.cc b/libtransmission/peer-mgr.cc index 4f2a7ca4e..3b3e4b165 100644 --- a/libtransmission/peer-mgr.cc +++ b/libtransmission/peer-mgr.cc @@ -75,7 +75,7 @@ private: auto info = TorrentInfo{}; info.info_hash = tor->infoHash(); - info.client_peer_id = tr_torrentGetPeerId(tor); + info.client_peer_id = tor->peer_id(); info.id = tor->id(); info.is_done = tor->isDone(); return info; diff --git a/libtransmission/quark.cc b/libtransmission/quark.cc index 6f975d34c..cd0d5f5a6 100644 --- a/libtransmission/quark.cc +++ b/libtransmission/quark.cc @@ -18,7 +18,7 @@ using namespace std::literals; namespace { -auto constexpr MyStatic = std::array{ ""sv, +auto constexpr MyStatic = std::array{ ""sv, "activeTorrentCount"sv, "activity-date"sv, "activityDate"sv, @@ -217,7 +217,6 @@ auto constexpr MyStatic = std::array{ ""sv, "paused"sv, "pausedTorrentCount"sv, "peer-congestion-algorithm"sv, - "peer-id-ttl-hours"sv, "peer-limit"sv, "peer-limit-global"sv, "peer-limit-per-torrent"sv, diff --git a/libtransmission/quark.h b/libtransmission/quark.h index 56375c066..eb9fdb098 100644 --- a/libtransmission/quark.h +++ b/libtransmission/quark.h @@ -220,7 +220,6 @@ enum TR_KEY_paused, TR_KEY_pausedTorrentCount, TR_KEY_peer_congestion_algorithm, - TR_KEY_peer_id_ttl_hours, TR_KEY_peer_limit, TR_KEY_peer_limit_global, TR_KEY_peer_limit_per_torrent, diff --git a/libtransmission/session-settings.h b/libtransmission/session-settings.h index d98ac801e..871ed8d57 100644 --- a/libtransmission/session-settings.h +++ b/libtransmission/session-settings.h @@ -37,7 +37,6 @@ struct tr_variant; V(TR_KEY_lpd_enabled, lpd_enabled, bool, true, "") \ V(TR_KEY_message_level, log_level, tr_log_level, TR_LOG_INFO, "") \ V(TR_KEY_peer_congestion_algorithm, peer_congestion_algorithm, std::string, "", "") \ - V(TR_KEY_peer_id_ttl_hours, peer_id_ttl_hours, size_t, 6U, "") \ V(TR_KEY_peer_limit_global, peer_limit_global, size_t, TR_DEFAULT_PEER_LIMIT_GLOBAL, "") \ V(TR_KEY_peer_limit_per_torrent, peer_limit_per_torrent, size_t, TR_DEFAULT_PEER_LIMIT_TORRENT, "") \ V(TR_KEY_peer_port, peer_port, tr_port, tr_port::fromHost(TR_DEFAULT_PEER_PORT), "The local machine's incoming peer port") \ diff --git a/libtransmission/session.h b/libtransmission/session.h index d2c8a7f8e..ca8e64e51 100644 --- a/libtransmission/session.h +++ b/libtransmission/session.h @@ -822,11 +822,6 @@ public: return settings_.ratio_limit; } - [[nodiscard]] constexpr auto peerIdTTLHours() const noexcept - { - return settings_.peer_id_ttl_hours; - } - void verifyRemove(tr_torrent* tor) { if (verifier_) diff --git a/libtransmission/torrent.cc b/libtransmission/torrent.cc index 50b146e50..73a817265 100644 --- a/libtransmission/torrent.cc +++ b/libtransmission/torrent.cc @@ -167,18 +167,6 @@ void tr_torrentClearError(tr_torrent* tor) tor->error_string.clear(); } -constexpr void tr_torrentUnsetPeerId(tr_torrent* tor) -{ - // triggers a rebuild next time tr_torrentGetPeerId() is called - tor->peer_id_ = {}; -} - -int peerIdTTL(tr_torrent const* tor) -{ - auto const ctime = tor->peer_id_creation_time_; - return ctime == 0 ? 0 : (int)difftime(ctime + tor->session->peerIdTTLHours() * 3600, tr_time()); -} - /* returns true if the seed ratio applies -- * it applies if the torrent's a seed AND it has a seed ratio set */ bool tr_torrentGetSeedRatioBytes(tr_torrent const* tor, uint64_t* setme_left, uint64_t* setme_goal) @@ -216,20 +204,6 @@ bool tr_torrentIsSeedRatioDone(tr_torrent const* tor) } } // namespace -tr_peer_id_t const& tr_torrentGetPeerId(tr_torrent* tor) -{ - bool const needs_new_peer_id = tor->peer_id_[0] == '\0' || // doesn't have one - (tor->isPublic() && (peerIdTTL(tor) <= 0)); // has one but it's expired - - if (needs_new_peer_id) - { - tor->peer_id_ = tr_peerIdInit(); - tor->peer_id_creation_time_ = tr_time(); - } - - return tor->peer_id_; -} - // --- PER-TORRENT UL / DL SPEEDS void tr_torrentSetSpeedLimit_KBps(tr_torrent* tor, tr_direction dir, tr_kilobytes_per_second_t kilo_per_second) @@ -875,12 +849,6 @@ void torrentStart(tr_torrent* tor, torrent_start_opts opts) tor->setRatioMode(TR_RATIOLIMIT_UNLIMITED); } - /* corresponds to the peer_id sent as a tracker request parameter. - * one tracker admin says: "When the same torrent is opened and - * closed and opened again without quitting Transmission ... - * change the peerid. It would help sometimes if a stopped event - * was missed to ensure that we didn't think someone was cheating. */ - tr_torrentUnsetPeerId(tor); tor->isRunning = true; tor->setDirty(); tor->session->runInSessionThread(torrentStartImpl, tor); diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index 126bf9a40..4c75daabb 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -779,6 +779,11 @@ public: return announce_key_; } + [[nodiscard]] constexpr tr_peer_id_t const& peer_id() const noexcept + { + return peer_id_; + } + // should be called when done modifying the torrent's announce list. void on_announce_list_changed() { @@ -814,15 +819,6 @@ public: tr_sha1_digest_t obfuscated_hash = {}; - /* If the initiator of the connection receives a handshake in which the - * peer_id does not match the expected peerid, then the initiator is - * expected to drop the connection. Note that the initiator presumably - * received the peer information from the tracker, which includes the - * peer_id that was registered by the peer. The peer_id from the tracker - * and in the handshake are expected to match. - */ - tr_peer_id_t peer_id_ = {}; - tr_session* session = nullptr; tr_torrent_announcer* torrent_announcer = nullptr; @@ -834,8 +830,6 @@ public: * other peers */ struct tr_incomplete_metadata* incompleteMetadata = nullptr; - time_t peer_id_creation_time_ = 0; - time_t lpdAnnounceAt = 0; time_t activityDate = 0; @@ -936,6 +930,15 @@ private: } } + /* If the initiator of the connection receives a handshake in which the + * peer_id does not match the expected peerid, then the initiator is + * expected to drop the connection. Note that the initiator presumably + * received the peer information from the tracker, which includes the + * peer_id that was registered by the peer. The peer_id from the tracker + * and in the handshake are expected to match. + */ + tr_peer_id_t peer_id_ = tr_peerIdInit(); + tr_verify_state verify_state_ = TR_VERIFY_NONE; float verify_progress_ = -1; @@ -959,8 +962,6 @@ constexpr bool tr_isTorrent(tr_torrent const* tor) */ void tr_torrentGotBlock(tr_torrent* tor, tr_block_index_t block); -tr_peer_id_t const& tr_torrentGetPeerId(tr_torrent* tor); - tr_torrent_metainfo tr_ctorStealMetainfo(tr_ctor* ctor); bool tr_ctorSetMetainfoFromFile(tr_ctor* ctor, std::string_view filename, tr_error** error = nullptr);