Compare commits

...

10 Commits

Author SHA1 Message Date
Yat Ho 74ad24b410 refactor: remove `UpnpState::Failed` 2024-04-24 10:04:06 +08:00
Yat Ho 9dfc4bbfde fix: recover from failed UPnP discovery 2024-04-24 10:04:06 +08:00
Yat Ho 4f4831a82b code review: explicitly list all states to start discovering from 2024-04-24 10:04:06 +08:00
Yat Ho effc776e1a chore: housekeeping 2024-04-24 10:04:06 +08:00
Yat Ho 1a5671efbd feat: allow natpmp to recover from errors 2024-04-24 10:04:06 +08:00
Yat Ho 62c8062bba feat: allow upnp to recover from errors 2024-04-24 10:04:06 +08:00
Pooyan Khanjankhani 821a6816ef
doc: fix typo (#6790) 2024-04-21 18:21:17 -05:00
Dzmitry Neviadomski ef18816b7f
Fix code style script path in CONTRIBUTING.md (#6787)
Signed-off-by: Dzmitry Neviadomski <nevack.d@gmail.com>
2024-04-21 07:36:13 -05:00
Dzmitry Neviadomski 0e25584e78
Make std::hash specialization for tr_socket_address a struct (#6788)
To be in line with std::hash declaration

See https://en.cppreference.com/w/cpp/utility/hash

Signed-off-by: Dzmitry Neviadomski <nevack.d@gmail.com>
2024-04-20 21:01:47 -05:00
Dzmitry Neviadomski bd0b74fccb
Use std::declval instead of nullptr cast trick (#6785)
Signed-off-by: Dzmitry Neviadomski <nevack.d@gmail.com>
2024-04-15 15:18:43 -05:00
6 changed files with 14 additions and 24 deletions

View File

@ -41,7 +41,7 @@ On macOS, Transmission is usually built with Xcode. Everywhere else, it's CMake
- Prefer `enum class` over `enum` - Prefer `enum class` over `enum`
- Prefer new-style headers, e.g. `<cstring>` over `<string.h>` - Prefer new-style headers, e.g. `<cstring>` over `<string.h>`
- Fix any warnings in new code before merging - Fix any warnings in new code before merging
- Run `./code-style.sh` on your code to ensure the whole codebase has consistent indentation. - Run `./code_style.sh` on your code to ensure the whole codebase has consistent indentation.
Note that Transmission existed in C for over a decade and those idioms don't change overnight. "Follow the C++ core guidelines" can be difficult when working with older code, and the maintainers will understand that when reviewing your PRs. :smiley: Note that Transmission existed in C for over a decade and those idioms don't change overnight. "Follow the C++ core guidelines" can be difficult when working with older code, and the maintainers will understand that when reviewing your PRs. :smiley:

View File

@ -404,7 +404,7 @@ struct tr_socket_address
}; };
template<> template<>
class std::hash<tr_socket_address> struct std::hash<tr_socket_address>
{ {
public: public:
std::size_t operator()(tr_socket_address const& socket_address) const noexcept std::size_t operator()(tr_socket_address const& socket_address) const noexcept

View File

@ -140,16 +140,10 @@ tr_natpmp::PulseResult tr_natpmp::pulse(tr_port local_port, bool is_enabled)
} }
} }
if (state_ == State::Idle) if ((state_ == State::Idle || state_ == State::Err) &&
(is_mapped_ ? tr_time() >= renew_time_ : is_enabled && has_discovered_))
{ {
if (is_enabled && !is_mapped_ && has_discovered_) state_ = State::SendMap;
{
state_ = State::SendMap;
}
else if (is_mapped_ && tr_time() >= renew_time_)
{
state_ = State::SendMap;
}
} }
if (state_ == State::SendMap && canSendCommand()) if (state_ == State::SendMap && canSendCommand())

View File

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

View File

@ -74,7 +74,7 @@ auto constexpr TrUnixSocketPrefix = "unix:"sv;
#ifdef _WIN32 #ifdef _WIN32
auto inline constexpr TrUnixAddrStrLen = size_t{ INET6_ADDRSTRLEN }; auto inline constexpr TrUnixAddrStrLen = size_t{ INET6_ADDRSTRLEN };
#else #else
auto inline constexpr TrUnixAddrStrLen = size_t{ sizeof(((struct sockaddr_un*)nullptr)->sun_path) + auto inline constexpr TrUnixAddrStrLen = size_t{ sizeof(std::declval<struct sockaddr_un>().sun_path) +
std::size(TrUnixSocketPrefix) }; std::size(TrUnixSocketPrefix) };
#endif #endif

View File

@ -150,7 +150,7 @@ Get a file list for the current torrent(s)
.It Fl g Fl -get Ar all | file-index | files .It Fl g Fl -get Ar all | file-index | files
Mark file(s) for download. Mark file(s) for download.
.Ar all .Ar all
marks all all of the torrent's files for downloading, marks all of the torrent's files for downloading,
.Ar file-index .Ar file-index
adds a single file to the download list, and adds a single file to the download list, and
.Ar files .Ar files