mirror of
https://github.com/transmission/transmission
synced 2024-12-22 07:42:37 +00:00
refactor: add handshake fire_timer() instead of overloading fire_done() (#6966)
This commit is contained in:
parent
b3912fa1a5
commit
5c714a5599
2 changed files with 9 additions and 3 deletions
|
@ -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<tr_peerIo> 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 }
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
|
||||
///
|
||||
|
||||
|
|
Loading…
Reference in a new issue