diff --git a/libtransmission/handshake.cc b/libtransmission/handshake.cc index 0bc8e9ceb..99cd1c67a 100644 --- a/libtransmission/handshake.cc +++ b/libtransmission/handshake.cc @@ -782,6 +782,7 @@ uint32_t tr_handshake::crypto_provide() const noexcept bool tr_handshake::fire_done(bool is_connected) { + peer_io_->clear_callbacks(); maybe_recycle_dh(); if (!on_done_) @@ -798,6 +799,12 @@ bool tr_handshake::fire_done(bool is_connected) return (cb)(Result{ peer_io_, peer_id_, have_read_anything_from_peer_, is_connected }); } +void tr_handshake::fire_timer() +{ + tr_logAddTraceHand(this, "timer expired"); + fire_done(false); +} + std::string_view tr_handshake::state_string(State state) noexcept { switch (state) @@ -834,7 +841,7 @@ std::string_view tr_handshake::state_string(State state) noexcept tr_handshake::tr_handshake(Mediator* mediator, std::shared_ptr peer_io, tr_encryption_mode mode, DoneFunc on_done) : on_done_{ std::move(on_done) } , peer_io_{ std::move(peer_io) } - , timeout_timer_{ mediator->timer_maker().create([this]() { fire_done(false); }) } + , timeout_timer_{ mediator->timer_maker().create([this]() { fire_timer(); }) } , mediator_{ mediator } , encryption_mode_{ mode } { diff --git a/libtransmission/handshake.h b/libtransmission/handshake.h index 4dc55d15a..b73c3994d 100644 --- a/libtransmission/handshake.h +++ b/libtransmission/handshake.h @@ -133,8 +133,6 @@ private: ReadState done(bool is_connected) { - peer_io_->clear_callbacks(); - // The responding client of a handshake usually starts sending BT messages immediately after // the handshake, so we need to return ReadState::Break to ensure those messages are processed. return fire_done(is_connected) ? ReadState::Break : ReadState::Err; @@ -192,6 +190,7 @@ private: [[nodiscard]] static uint32_t get_crypto_select(tr_encryption_mode encryption_mode, uint32_t crypto_provide) noexcept; bool fire_done(bool is_connected); + void fire_timer(); ///