mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-10 23:07:59 +00:00
Merge pull request #10523 from Chocobo1/port
Use a randomized port number for the first run
This commit is contained in:
commit
bd493e261e
@ -337,7 +337,7 @@ Session::Session(QObject *parent)
|
|||||||
, m_isAltGlobalSpeedLimitEnabled(BITTORRENT_SESSION_KEY("UseAlternativeGlobalSpeedLimit"), false)
|
, m_isAltGlobalSpeedLimitEnabled(BITTORRENT_SESSION_KEY("UseAlternativeGlobalSpeedLimit"), false)
|
||||||
, m_isBandwidthSchedulerEnabled(BITTORRENT_SESSION_KEY("BandwidthSchedulerEnabled"), false)
|
, m_isBandwidthSchedulerEnabled(BITTORRENT_SESSION_KEY("BandwidthSchedulerEnabled"), false)
|
||||||
, m_saveResumeDataInterval(BITTORRENT_SESSION_KEY("SaveResumeDataInterval"), 60)
|
, m_saveResumeDataInterval(BITTORRENT_SESSION_KEY("SaveResumeDataInterval"), 60)
|
||||||
, m_port(BITTORRENT_SESSION_KEY("Port"), 8999)
|
, m_port(BITTORRENT_SESSION_KEY("Port"), -1)
|
||||||
, m_useRandomPort(BITTORRENT_SESSION_KEY("UseRandomPort"), false)
|
, m_useRandomPort(BITTORRENT_SESSION_KEY("UseRandomPort"), false)
|
||||||
, m_networkInterface(BITTORRENT_SESSION_KEY("Interface"))
|
, m_networkInterface(BITTORRENT_SESSION_KEY("Interface"))
|
||||||
, m_networkInterfaceName(BITTORRENT_SESSION_KEY("InterfaceName"))
|
, m_networkInterfaceName(BITTORRENT_SESSION_KEY("InterfaceName"))
|
||||||
@ -375,6 +375,9 @@ Session::Session(QObject *parent)
|
|||||||
, m_extraLimit(0)
|
, m_extraLimit(0)
|
||||||
, m_recentErroredTorrentsTimer(new QTimer(this))
|
, m_recentErroredTorrentsTimer(new QTimer(this))
|
||||||
{
|
{
|
||||||
|
if (port() < 0)
|
||||||
|
m_port = Utils::Random::rand(1024, 65535);
|
||||||
|
|
||||||
initResumeFolder();
|
initResumeFolder();
|
||||||
|
|
||||||
m_recentErroredTorrentsTimer->setSingleShot(true);
|
m_recentErroredTorrentsTimer->setSingleShot(true);
|
||||||
@ -1146,9 +1149,10 @@ void Session::configure(lt::settings_pack &settingsPack)
|
|||||||
QString chosenIP;
|
QString chosenIP;
|
||||||
#endif
|
#endif
|
||||||
if (m_listenInterfaceChanged) {
|
if (m_listenInterfaceChanged) {
|
||||||
const ushort port = this->port();
|
const int port = useRandomPort() ? 0 : this->port();
|
||||||
const std::pair<int, int> ports(port, port);
|
if (port > 0) // user specified port
|
||||||
settingsPack.set_int(lt::settings_pack::max_retry_port_bind, ports.second - ports.first);
|
settingsPack.set_int(lt::settings_pack::max_retry_port_bind, 0);
|
||||||
|
|
||||||
for (QString ip : getListeningIPs()) {
|
for (QString ip : getListeningIPs()) {
|
||||||
lt::error_code ec;
|
lt::error_code ec;
|
||||||
std::string interfacesStr;
|
std::string interfacesStr;
|
||||||
@ -2537,15 +2541,12 @@ void Session::setSaveResumeDataInterval(const uint value)
|
|||||||
|
|
||||||
int Session::port() const
|
int Session::port() const
|
||||||
{
|
{
|
||||||
static int randomPort = Utils::Random::rand(1024, 65535);
|
|
||||||
if (useRandomPort())
|
|
||||||
return randomPort;
|
|
||||||
return m_port;
|
return m_port;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::setPort(const int port)
|
void Session::setPort(const int port)
|
||||||
{
|
{
|
||||||
if (port != this->port()) {
|
if (port != m_port) {
|
||||||
m_port = port;
|
m_port = port;
|
||||||
configureListeningInterface();
|
configureListeningInterface();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user