From 4f4831a82b234ee072c8b568856ed6d5204f47e2 Mon Sep 17 00:00:00 2001 From: Yat Ho Date: Mon, 1 Apr 2024 12:41:01 +0800 Subject: [PATCH] code review: explicitly list all states to start discovering from --- libtransmission/port-forwarding-natpmp.cc | 5 +++-- libtransmission/port-forwarding-upnp.cc | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libtransmission/port-forwarding-natpmp.cc b/libtransmission/port-forwarding-natpmp.cc index 7aead765a..7d4d0054c 100644 --- a/libtransmission/port-forwarding-natpmp.cc +++ b/libtransmission/port-forwarding-natpmp.cc @@ -96,7 +96,7 @@ tr_natpmp::PulseResult tr_natpmp::pulse(tr_port local_port, bool is_enabled) } } - if (state_ <= State::Err && is_mapped_ && (!is_enabled || local_port_ != local_port)) + if ((state_ == State::Idle || state_ == State::Err) && is_mapped_ && (!is_enabled || local_port_ != local_port)) { state_ = State::SendUnmap; } @@ -140,7 +140,8 @@ tr_natpmp::PulseResult tr_natpmp::pulse(tr_port local_port, bool is_enabled) } } - if (state_ <= State::Err && (is_mapped_ ? tr_time() >= renew_time_ : is_enabled && has_discovered_)) + if ((state_ == State::Idle || state_ == State::Err) && + (is_mapped_ ? tr_time() >= renew_time_ : is_enabled && has_discovered_)) { state_ = State::SendMap; } diff --git a/libtransmission/port-forwarding-upnp.cc b/libtransmission/port-forwarding-upnp.cc index 820dde2b8..65ab5f473 100644 --- a/libtransmission/port-forwarding-upnp.cc +++ b/libtransmission/port-forwarding-upnp.cc @@ -306,7 +306,7 @@ tr_port_forwarding_state tr_upnpPulse( freeUPNPDevlist(devlist); } - if (handle->state <= UpnpState::Failed && handle->isMapped && + if ((handle->state == UpnpState::Idle || handle->state == UpnpState::Failed) && handle->isMapped && (!is_enabled || handle->advertised_port != advertised_port || handle->local_port != local_port)) { handle->state = UpnpState::WillUnmap; @@ -339,7 +339,7 @@ tr_port_forwarding_state tr_upnpPulse( handle->local_port = {}; } - if (handle->state <= UpnpState::Failed && is_enabled && !handle->isMapped) + if ((handle->state == UpnpState::Idle || handle->state == UpnpState::Failed) && is_enabled && !handle->isMapped) { handle->state = UpnpState::WillMap; }