Make I2P session options configurable

PR #19079.
Closes #18980.
This commit is contained in:
Vort 2023-06-06 08:35:40 +03:00 committed by GitHub
parent 2e87e6e0df
commit ff5d02bcf2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 125 additions and 1 deletions

View file

@ -271,6 +271,14 @@ namespace BitTorrent
virtual void setI2PPort(int port) = 0;
virtual bool I2PMixedMode() const = 0;
virtual void setI2PMixedMode(bool enabled) = 0;
virtual int I2PInboundQuantity() const = 0;
virtual void setI2PInboundQuantity(int value) = 0;
virtual int I2POutboundQuantity() const = 0;
virtual void setI2POutboundQuantity(int value) = 0;
virtual int I2PInboundLength() const = 0;
virtual void setI2PInboundLength(int value) = 0;
virtual int I2POutboundLength() const = 0;
virtual void setI2POutboundLength(int value) = 0;
virtual bool isProxyPeerConnectionsEnabled() const = 0;
virtual void setProxyPeerConnectionsEnabled(bool enabled) = 0;
virtual ChokingAlgorithm chokingAlgorithm() const = 0;

View file

@ -528,6 +528,10 @@ SessionImpl::SessionImpl(QObject *parent)
, m_I2PAddress {BITTORRENT_SESSION_KEY(u"I2P/Address"_qs), u"127.0.0.1"_qs}
, m_I2PPort {BITTORRENT_SESSION_KEY(u"I2P/Port"_qs), 7656}
, m_I2PMixedMode {BITTORRENT_SESSION_KEY(u"I2P/MixedMode"_qs), false}
, m_I2PInboundQuantity {BITTORRENT_SESSION_KEY(u"I2P/InboundQuantity"_qs), 3}
, m_I2POutboundQuantity {BITTORRENT_SESSION_KEY(u"I2P/OutboundQuantity"_qs), 3}
, m_I2PInboundLength {BITTORRENT_SESSION_KEY(u"I2P/InboundLength"_qs), 3}
, m_I2POutboundLength {BITTORRENT_SESSION_KEY(u"I2P/OutboundLength"_qs), 3}
, m_seedingLimitTimer {new QTimer(this)}
, m_resumeDataTimer {new QTimer(this)}
, m_ioThread {new QThread}
@ -1678,6 +1682,14 @@ lt::settings_pack SessionImpl::loadLTSettings() const
settingsPack.set_bool(lt::settings_pack::allow_i2p_mixed, false);
}
#ifdef QBT_USES_LIBTORRENT2
// I2P session options
settingsPack.set_int(lt::settings_pack::i2p_inbound_quantity, I2PInboundQuantity());
settingsPack.set_int(lt::settings_pack::i2p_outbound_quantity, I2POutboundQuantity());
settingsPack.set_int(lt::settings_pack::i2p_inbound_length, I2PInboundLength());
settingsPack.set_int(lt::settings_pack::i2p_outbound_length, I2POutboundLength());
#endif
// proxy
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::none);
if (Preferences::instance()->useProxyForBT())
@ -3640,6 +3652,62 @@ void SessionImpl::setI2PMixedMode(const bool enabled)
}
}
int SessionImpl::I2PInboundQuantity() const
{
return m_I2PInboundQuantity;
}
void SessionImpl::setI2PInboundQuantity(const int value)
{
if (value == m_I2PInboundQuantity)
return;
m_I2PInboundQuantity = value;
configureDeferred();
}
int SessionImpl::I2POutboundQuantity() const
{
return m_I2POutboundQuantity;
}
void SessionImpl::setI2POutboundQuantity(const int value)
{
if (value == m_I2POutboundQuantity)
return;
m_I2POutboundQuantity = value;
configureDeferred();
}
int SessionImpl::I2PInboundLength() const
{
return m_I2PInboundLength;
}
void SessionImpl::setI2PInboundLength(const int value)
{
if (value == m_I2PInboundLength)
return;
m_I2PInboundLength = value;
configureDeferred();
}
int SessionImpl::I2POutboundLength() const
{
return m_I2POutboundLength;
}
void SessionImpl::setI2POutboundLength(const int value)
{
if (value == m_I2POutboundLength)
return;
m_I2POutboundLength = value;
configureDeferred();
}
bool SessionImpl::isProxyPeerConnectionsEnabled() const
{
return m_isProxyPeerConnectionsEnabled;

View file

@ -250,6 +250,14 @@ namespace BitTorrent
void setI2PPort(int port) override;
bool I2PMixedMode() const override;
void setI2PMixedMode(bool enabled) override;
int I2PInboundQuantity() const override;
void setI2PInboundQuantity(int value) override;
int I2POutboundQuantity() const override;
void setI2POutboundQuantity(int value) override;
int I2PInboundLength() const override;
void setI2PInboundLength(int value) override;
int I2POutboundLength() const override;
void setI2POutboundLength(int value) override;
bool isProxyPeerConnectionsEnabled() const override;
void setProxyPeerConnectionsEnabled(bool enabled) override;
ChokingAlgorithm chokingAlgorithm() const override;
@ -699,6 +707,10 @@ namespace BitTorrent
CachedSettingValue<QString> m_I2PAddress;
CachedSettingValue<int> m_I2PPort;
CachedSettingValue<bool> m_I2PMixedMode;
CachedSettingValue<int> m_I2PInboundQuantity;
CachedSettingValue<int> m_I2POutboundQuantity;
CachedSettingValue<int> m_I2PInboundLength;
CachedSettingValue<int> m_I2POutboundLength;
bool m_isRestored = false;

View file

@ -153,6 +153,12 @@ namespace
PEER_TURNOVER_CUTOFF,
PEER_TURNOVER_INTERVAL,
REQUEST_QUEUE_SIZE,
#ifdef QBT_USES_LIBTORRENT2
I2P_INBOUND_QUANTITY,
I2P_OUTBOUND_QUANTITY,
I2P_INBOUND_LENGTH,
I2P_OUTBOUND_LENGTH,
#endif
ROW_COUNT
};
@ -319,6 +325,13 @@ void AdvancedSettings::saveAdvancedSettings() const
session->setPeerTurnoverInterval(m_spinBoxPeerTurnoverInterval.value());
// Maximum outstanding requests to a single peer
session->setRequestQueueSize(m_spinBoxRequestQueueSize.value());
#ifdef QBT_USES_LIBTORRENT2
// I2P session options
session->setI2PInboundQuantity(m_spinBoxI2PInboundQuantity.value());
session->setI2POutboundQuantity(m_spinBoxI2POutboundQuantity.value());
session->setI2PInboundLength(m_spinBoxI2PInboundLength.value());
session->setI2POutboundLength(m_spinBoxI2POutboundLength.value());
#endif
}
#ifndef QBT_USES_LIBTORRENT2
@ -826,6 +839,28 @@ void AdvancedSettings::loadAdvancedSettings()
m_spinBoxRequestQueueSize.setValue(session->requestQueueSize());
addRow(REQUEST_QUEUE_SIZE, (tr("Maximum outstanding requests to a single peer") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#max_out_request_queue", u"(?)"))
, &m_spinBoxRequestQueueSize);
#ifdef QBT_USES_LIBTORRENT2
m_spinBoxI2PInboundQuantity.setMinimum(1);
m_spinBoxI2PInboundQuantity.setMaximum(16);
m_spinBoxI2PInboundQuantity.setValue(session->I2PInboundQuantity());
addRow(I2P_INBOUND_QUANTITY, (tr("I2P inbound quantity") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#i2p_inbound_quantity", u"(?)"))
, &m_spinBoxI2PInboundQuantity);
m_spinBoxI2POutboundQuantity.setMinimum(1);
m_spinBoxI2POutboundQuantity.setMaximum(16);
m_spinBoxI2POutboundQuantity.setValue(session->I2POutboundQuantity());
addRow(I2P_OUTBOUND_QUANTITY, (tr("I2P outbound quantity") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#i2p_outbound_quantity", u"(?)"))
, &m_spinBoxI2POutboundQuantity);
m_spinBoxI2PInboundLength.setMinimum(0);
m_spinBoxI2PInboundLength.setMaximum(7);
m_spinBoxI2PInboundLength.setValue(session->I2PInboundLength());
addRow(I2P_INBOUND_LENGTH, (tr("I2P inbound length") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#i2p_inbound_length", u"(?)"))
, &m_spinBoxI2PInboundLength);
m_spinBoxI2POutboundLength.setMinimum(0);
m_spinBoxI2POutboundLength.setMaximum(7);
m_spinBoxI2POutboundLength.setValue(session->I2POutboundLength());
addRow(I2P_OUTBOUND_LENGTH, (tr("I2P outbound length") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#i2p_outbound_length", u"(?)"))
, &m_spinBoxI2POutboundLength);
#endif
}
template <typename T>

View file

@ -85,7 +85,8 @@ private:
QCheckBox m_checkBoxCoalesceRW;
#else
QComboBox m_comboBoxDiskIOType;
QSpinBox m_spinBoxMemoryWorkingSetLimit, m_spinBoxHashingThreads;
QSpinBox m_spinBoxMemoryWorkingSetLimit, m_spinBoxHashingThreads,
m_spinBoxI2PInboundQuantity, m_spinBoxI2POutboundQuantity, m_spinBoxI2PInboundLength, m_spinBoxI2POutboundLength;
#endif
// OS dependent settings