Skip to content

Commit

Permalink
feat: do not auto-disconnect when a known seed initiates a connection…
Browse files Browse the repository at this point in the history
… and we are seeding (transmission#5756)
  • Loading branch information
ckerr committed Jul 8, 2023
1 parent 8e822a3 commit 8169d52
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 27 deletions.
8 changes: 0 additions & 8 deletions libtransmission/handshake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -521,16 +521,8 @@ ReadState tr_handshake::read_crypto_provide(tr_peerIo* peer_io)

if (auto const info = mediator_->torrent_from_obfuscated(obfuscated_hash); info)
{
bool const client_is_seed = info->is_done;
bool const peer_is_seed = mediator_->is_peer_known_seed(info->id, peer_io->socket_address());
tr_logAddTraceHand(this, fmt::format("got INCOMING connection's encrypted handshake for torrent [{}]", info->id));
peer_io->set_torrent_hash(info->info_hash);

if (client_is_seed && peer_is_seed)
{
tr_logAddTraceHand(this, "another seed tried to reconnect to us!");
return done(false);
}
}
else
{
Expand Down
2 changes: 0 additions & 2 deletions libtransmission/handshake.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ class tr_handshake
[[nodiscard]] virtual libtransmission::TimerMaker& timer_maker() = 0;
[[nodiscard]] virtual bool allows_dht() const = 0;
[[nodiscard]] virtual bool allows_tcp() const = 0;
[[nodiscard]] virtual bool is_peer_known_seed(tr_torrent_id_t tor_id, tr_socket_address const& socket_address)
const = 0;
[[nodiscard]] virtual size_t pad(void* setme, size_t max_bytes) const = 0;
[[nodiscard]] virtual DH::private_key_bigend_t private_key() const
{
Expand Down
10 changes: 0 additions & 10 deletions libtransmission/peer-mgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ class HandshakeMediator final : public tr_handshake::Mediator
}
}

[[nodiscard]] bool is_peer_known_seed(tr_torrent_id_t tor_id, tr_socket_address const& socket_address) const override;

[[nodiscard]] libtransmission::TimerMaker& timer_maker() override
{
return session_.timerMaker();
Expand Down Expand Up @@ -2547,11 +2545,3 @@ void tr_peerMgr::make_new_peer_connections()
// remove the N candidates that we just consumed
candidates.resize(std::size(candidates) - n_this_pass);
}

// ---

bool HandshakeMediator::is_peer_known_seed(tr_torrent_id_t tor_id, tr_socket_address const& socket_address) const
{
auto const* const tor = session_.torrents().get(tor_id);
return tor != nullptr && tor->swarm != nullptr && tor->swarm->peer_is_a_seed(socket_address);
}
7 changes: 0 additions & 7 deletions tests/libtransmission/handshake-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,6 @@ class HandshakeTest : public SessionTest
return true;
}

[[nodiscard]] bool is_peer_known_seed(
tr_torrent_id_t /*tor_id*/,
std::pair<tr_address, tr_port> const& /*socket_address*/) const override
{
return false;
}

[[nodiscard]] size_t pad(void* setme, [[maybe_unused]] size_t maxlen) const override
{
TR_ASSERT(maxlen > 10);
Expand Down

0 comments on commit 8169d52

Please sign in to comment.