refactor: remove `UpnpState::Failed`

This commit is contained in:
Yat Ho 2024-04-06 10:11:14 +08:00
parent 9dfc4bbfde
commit 74ad24b410
1 changed files with 4 additions and 8 deletions

View File

@ -39,7 +39,6 @@ namespace
enum class UpnpState : uint8_t
{
Idle,
Failed,
WillDiscover, // next action is upnpDiscover()
Discovering, // currently making blocking upnpDiscover() call in a worker thread
WillMap, // next action is UPNP_AddPortMapping()
@ -58,9 +57,7 @@ struct tr_upnp
~tr_upnp()
{
TR_ASSERT(!isMapped);
TR_ASSERT(
state == UpnpState::Idle || state == UpnpState::Failed || state == UpnpState::WillDiscover ||
state == UpnpState::Discovering);
TR_ASSERT(state == UpnpState::Idle || state == UpnpState::WillDiscover || state == UpnpState::Discovering);
FreeUPNPUrls(&urls);
}
@ -306,7 +303,7 @@ tr_port_forwarding_state tr_upnpPulse(
freeUPNPDevlist(devlist);
}
if ((handle->state == UpnpState::Idle || handle->state == UpnpState::Failed) && handle->isMapped &&
if (handle->state == UpnpState::Idle && handle->isMapped &&
(!is_enabled || handle->advertised_port != advertised_port || handle->local_port != local_port))
{
handle->state = UpnpState::WillUnmap;
@ -339,7 +336,7 @@ tr_port_forwarding_state tr_upnpPulse(
handle->local_port = {};
}
if ((handle->state == UpnpState::Idle || handle->state == UpnpState::Failed) && is_enabled && !handle->isMapped)
if (handle->state == UpnpState::Idle && is_enabled && !handle->isMapped)
{
handle->state = UpnpState::WillMap;
}
@ -376,15 +373,14 @@ tr_port_forwarding_state tr_upnpPulse(
fmt::arg("advertised_port", advertised_port.host())));
handle->advertised_port = advertised_port;
handle->local_port = local_port;
handle->state = UpnpState::Idle;
}
else
{
tr_logAddInfo(_("If your router supports UPnP, please make sure UPnP is enabled!"));
handle->advertised_port = {};
handle->local_port = {};
handle->state = UpnpState::Failed;
}
handle->state = UpnpState::Idle;
}
return port_fwd_state(handle->state, handle->isMapped);