fix: generate peer-id on launch (#5233)

This commit is contained in:
Charles Kerr 2023-03-15 20:53:48 -05:00 committed by GitHub
parent 2a57b17031
commit 5cc3bf8a97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 17 additions and 57 deletions

View File

@ -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.

View File

@ -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];

View File

@ -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;

View File

@ -18,7 +18,7 @@ using namespace std::literals;
namespace
{
auto constexpr MyStatic = std::array<std::string_view, 402>{ ""sv,
auto constexpr MyStatic = std::array<std::string_view, 401>{ ""sv,
"activeTorrentCount"sv,
"activity-date"sv,
"activityDate"sv,
@ -217,7 +217,6 @@ auto constexpr MyStatic = std::array<std::string_view, 402>{ ""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,

View File

@ -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,

View File

@ -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") \

View File

@ -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_)

View File

@ -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);

View File

@ -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);