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
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;