mirror of
https://github.com/transmission/transmission
synced 2024-12-22 07:42:37 +00:00
fix: calculate size of one hash line in lpd correctly (#7136)
This commit is contained in:
parent
32cfd712d0
commit
45f5a19950
1 changed files with 27 additions and 31 deletions
|
@ -568,15 +568,16 @@ private:
|
|||
};
|
||||
std::sort(std::begin(torrents), std::end(torrents), TorrentComparator);
|
||||
|
||||
// cram in as many as will fit in a message
|
||||
auto baseline_size = size_t{};
|
||||
auto const next_announce_after = now + TorrentAnnounceIntervalSec;
|
||||
for (ipp_t ipp = 0; ipp < NUM_TR_AF_INET_TYPES; ++ipp)
|
||||
{
|
||||
baseline_size = std::max(
|
||||
baseline_size,
|
||||
std::size(makeAnnounceMsg(static_cast<tr_address_type>(ipp), cookie_, mediator_.port(), {})));
|
||||
}
|
||||
auto const size_per_hash = std::size(torrents.front().info_hash_str);
|
||||
auto const ip_protocol = static_cast<tr_address_type>(ipp);
|
||||
|
||||
// cram in as many as will fit in a message
|
||||
auto const baseline_size = std::size(makeAnnounceMsg(ip_protocol, cookie_, mediator_.port(), {}));
|
||||
auto const size_with_one = std::size(
|
||||
makeAnnounceMsg(ip_protocol, cookie_, mediator_.port(), { torrents.front().info_hash_str }));
|
||||
auto const size_per_hash = size_with_one - baseline_size;
|
||||
auto const max_torrents_per_announce = (MaxDatagramLength - baseline_size) / size_per_hash;
|
||||
auto const torrents_this_announce = std::min(std::size(torrents), max_torrents_per_announce);
|
||||
auto info_hash_strings = std::vector<std::string_view>{};
|
||||
|
@ -587,22 +588,17 @@ private:
|
|||
std::back_inserter(info_hash_strings),
|
||||
[](auto const& tor) { return tor.info_hash_str; });
|
||||
|
||||
auto success = false;
|
||||
for (ipp_t ipp = 0; ipp < NUM_TR_AF_INET_TYPES; ++ipp)
|
||||
if (!sendAnnounce(static_cast<tr_address_type>(ipp), info_hash_strings))
|
||||
{
|
||||
success |= sendAnnounce(static_cast<tr_address_type>(ipp), info_hash_strings);
|
||||
}
|
||||
if (!success)
|
||||
{
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
auto const next_announce_after = now + TorrentAnnounceIntervalSec;
|
||||
for (auto const& info_hash_string : info_hash_strings)
|
||||
{
|
||||
mediator_.setNextAnnounceTime(info_hash_string, next_announce_after);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dosUpkeep()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue