Skip to content

Commit

Permalink
Merge pull request #11781 from FranciscoPombal/piece_extent_affinity
Browse files Browse the repository at this point in the history
Add piece_extent_affinity to AdvancedSettings
  • Loading branch information
Chocobo1 committed Jan 14, 2020
2 parents 990e451 + ed96a07 commit 146e821
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/base/bittorrent/session.cpp
Expand Up @@ -383,6 +383,7 @@ Session::Session(QObject *parent)
#else
, m_coalesceReadWriteEnabled(BITTORRENT_SESSION_KEY("CoalesceReadWrite"), false)
#endif
, m_usePieceExtentAffinity(BITTORRENT_SESSION_KEY("PieceExtentAffinity"), false)
, m_isSuggestMode(BITTORRENT_SESSION_KEY("SuggestMode"), false)
, m_sendBufferWatermark(BITTORRENT_SESSION_KEY("SendBufferWatermark"), 500)
, m_sendBufferLowWatermark(BITTORRENT_SESSION_KEY("SendBufferLowWatermark"), 10)
Expand Down Expand Up @@ -1322,6 +1323,10 @@ void Session::loadLTSettings(lt::settings_pack &settingsPack)
settingsPack.set_bool(lt::settings_pack::coalesce_reads, isCoalesceReadWriteEnabled());
settingsPack.set_bool(lt::settings_pack::coalesce_writes, isCoalesceReadWriteEnabled());

#if (LIBTORRENT_VERSION_NUM >= 10202)
settingsPack.set_bool(lt::settings_pack::piece_extent_affinity, usePieceExtentAffinity());
#endif

settingsPack.set_int(lt::settings_pack::suggest_mode, isSuggestModeEnabled()
? lt::settings_pack::suggest_read_cache : lt::settings_pack::no_piece_suggestions);

Expand Down Expand Up @@ -3249,6 +3254,19 @@ bool Session::isSuggestModeEnabled() const
return m_isSuggestMode;
}

bool Session::usePieceExtentAffinity() const
{
return m_usePieceExtentAffinity;
}

void Session::setPieceExtentAffinity(const bool enabled)
{
if (enabled == m_usePieceExtentAffinity) return;

m_usePieceExtentAffinity = enabled;
configureDeferred();
}

void Session::setSuggestMode(const bool mode)
{
if (mode == m_isSuggestMode) return;
Expand Down
3 changes: 3 additions & 0 deletions src/base/bittorrent/session.h
Expand Up @@ -337,6 +337,8 @@ namespace BitTorrent
void setUseOSCache(bool use);
bool isCoalesceReadWriteEnabled() const;
void setCoalesceReadWriteEnabled(bool enabled);
bool usePieceExtentAffinity() const;
void setPieceExtentAffinity(bool enabled);
bool isSuggestModeEnabled() const;
void setSuggestMode(bool mode);
int sendBufferWatermark() const;
Expand Down Expand Up @@ -612,6 +614,7 @@ namespace BitTorrent
CachedSettingValue<int> m_diskCacheTTL;
CachedSettingValue<bool> m_useOSCache;
CachedSettingValue<bool> m_coalesceReadWriteEnabled;
CachedSettingValue<bool> m_usePieceExtentAffinity;
CachedSettingValue<bool> m_isSuggestMode;
CachedSettingValue<int> m_sendBufferWatermark;
CachedSettingValue<int> m_sendBufferLowWatermark;
Expand Down
12 changes: 12 additions & 0 deletions src/gui/advancedsettings.cpp
Expand Up @@ -96,6 +96,9 @@ enum AdvSettingsRows
DISK_CACHE_TTL,
OS_CACHE,
COALESCE_RW,
#if (LIBTORRENT_VERSION_NUM >= 10202)
PIECE_EXTENT_AFFINITY,
#endif
SUGGEST_MODE,
SEND_BUF_WATERMARK,
SEND_BUF_LOW_WATERMARK,
Expand Down Expand Up @@ -189,6 +192,10 @@ void AdvancedSettings::saveAdvancedSettings()
session->setUseOSCache(m_checkBoxOsCache.isChecked());
// Coalesce reads & writes
session->setCoalesceReadWriteEnabled(m_checkBoxCoalesceRW.isChecked());
#if (LIBTORRENT_VERSION_NUM >= 10202)
// Piece extent affinity
session->setPieceExtentAffinity(m_checkBoxPieceExtentAffinity.isChecked());
#endif
// Suggest mode
session->setSuggestMode(m_checkBoxSuggestMode.isChecked());
// Send buffer watermark
Expand Down Expand Up @@ -427,6 +434,11 @@ void AdvancedSettings::loadAdvancedSettings()
m_checkBoxCoalesceRW.setChecked(session->isCoalesceReadWriteEnabled());
addRow(COALESCE_RW, (tr("Coalesce reads & writes") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#coalesce_reads", "(?)"))
, &m_checkBoxCoalesceRW);
#if (LIBTORRENT_VERSION_NUM >= 10202)
// Piece extent affinity
m_checkBoxPieceExtentAffinity.setChecked(session->usePieceExtentAffinity());
addRow(PIECE_EXTENT_AFFINITY, (tr("Use piece extent affinity") + ' ' + makeLink("https://libtorrent.org/single-page-ref.html#piece_extent_affinity", "(?)")), &m_checkBoxPieceExtentAffinity);
#endif
// Suggest mode
m_checkBoxSuggestMode.setChecked(session->isSuggestModeEnabled());
addRow(SUGGEST_MODE, (tr("Send upload piece suggestions") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#suggest_mode", "(?)"))
Expand Down
2 changes: 1 addition & 1 deletion src/gui/advancedsettings.h
Expand Up @@ -64,7 +64,7 @@ private slots:
QCheckBox m_checkBoxOsCache, m_checkBoxRecheckCompleted, m_checkBoxResolveCountries, m_checkBoxResolveHosts, m_checkBoxSuperSeeding,
m_checkBoxProgramNotifications, m_checkBoxTorrentAddedNotifications, m_checkBoxTrackerFavicon, m_checkBoxTrackerStatus,
m_checkBoxConfirmTorrentRecheck, m_checkBoxConfirmRemoveAllTags, m_checkBoxAnnounceAllTrackers, m_checkBoxAnnounceAllTiers,
m_checkBoxMultiConnectionsPerIp, m_checkBoxSuggestMode, m_checkBoxCoalesceRW, m_checkBoxSpeedWidgetEnabled;
m_checkBoxMultiConnectionsPerIp, m_checkBoxPieceExtentAffinity, m_checkBoxSuggestMode, m_checkBoxCoalesceRW, m_checkBoxSpeedWidgetEnabled;
QComboBox m_comboBoxInterface, m_comboBoxInterfaceAddress, m_comboBoxUtpMixedMode, m_comboBoxChokingAlgorithm, m_comboBoxSeedChokingAlgorithm;
QLineEdit m_lineEditAnnounceIP;

Expand Down
5 changes: 5 additions & 0 deletions src/webui/api/appcontroller.cpp
Expand Up @@ -281,6 +281,8 @@ void AppController::preferencesAction()
data["enable_os_cache"] = session->useOSCache();
// Coalesce reads & writes
data["enable_coalesce_read_write"] = session->isCoalesceReadWriteEnabled();
// Piece Extent Affinity
data["enable_piece_extent_affinity"] = session->usePieceExtentAffinity();
// Suggest mode
data["enable_upload_suggestions"] = session->isSuggestModeEnabled();
// Send buffer watermark
Expand Down Expand Up @@ -688,6 +690,9 @@ void AppController::setPreferencesAction()
// Coalesce reads & writes
if (hasKey("enable_coalesce_read_write"))
session->setCoalesceReadWriteEnabled(it.value().toBool());
// Piece extent affinity
if (hasKey("enable_piece_extent_affinity"))
session->setPieceExtentAffinity(it.value().toBool());
// Suggest mode
if (hasKey("enable_upload_suggestions"))
session->setSuggestMode(it.value().toBool());
Expand Down
10 changes: 10 additions & 0 deletions src/webui/www/private/views/preferences.html
Expand Up @@ -926,6 +926,14 @@
<input type="checkbox" id="coalesceReadsAndWrites" />
</td>
</tr>
<tr>
<td>
<label for="pieceExtentAffinity">QBT_TR(Use piece extent affinity (requires libtorrent >= 1.2.2):)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://libtorrent.org/single-page-ref.html#piece_extent_affinity" target="_blank">(?)</a></label>
</td>
<td>
<input type="checkbox" id="pieceExtentAffinity" />
</td>
</tr>
<tr>
<td>
<label for="sendUploadPieceSuggestions">QBT_TR(Send upload piece suggestions:)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/reference-Settings.html#suggest_mode" target="_blank">(?)</a></label>
Expand Down Expand Up @@ -1748,6 +1756,7 @@
$('diskCacheExpiryInterval').setProperty('value', pref.disk_cache_ttl);
$('enableOSCache').setProperty('checked', pref.enable_os_cache);
$('coalesceReadsAndWrites').setProperty('checked', pref.enable_coalesce_read_write);
$('pieceExtentAffinity').setProperty('checked', pref.enable_piece_extent_affinity);
$('sendUploadPieceSuggestions').setProperty('checked', pref.enable_upload_suggestions);
$('sendBufferWatermark').setProperty('value', pref.send_buffer_watermark);
$('sendBufferLowWatermark').setProperty('value', pref.send_buffer_low_watermark);
Expand Down Expand Up @@ -2113,6 +2122,7 @@
settings.set('disk_cache_ttl', $('diskCacheExpiryInterval').getProperty('value'));
settings.set('enable_os_cache', $('enableOSCache').getProperty('checked'));
settings.set('enable_coalesce_read_write', $('coalesceReadsAndWrites').getProperty('checked'));
settings.set('enable_piece_extent_affinity', $('pieceExtentAffinity').getProperty('checked'));
settings.set('enable_upload_suggestions', $('sendUploadPieceSuggestions').getProperty('checked'));
settings.set('send_buffer_watermark', $('sendBufferWatermark').getProperty('value'));
settings.set('send_buffer_low_watermark', $('sendBufferLowWatermark').getProperty('value'));
Expand Down

0 comments on commit 146e821

Please sign in to comment.