Skip to content

The only downloader you need. 下载器的集大成者。

fix(bt): 修正 libtorrent session 默认值导致的下载性能问题

XiaoYouChRa24b0da43dfd
diff --git a/features/bittorrent_pack/config.py b/features/bittorrent_pack/config.py
index b1f91eff..e91ec448 100644
--- a/features/bittorrent_pack/config.py
+++ b/features/bittorrent_pack/config.py
@@ -38,7 +38,7 @@ class BitTorrentConfig(PackConfig):
maxConnections = RangeConfigItem("BitTorrent", "ConnectionsLimit", 500, RangeValidator(20, 2000))
maxUploadSpeed = RangeConfigItem("BitTorrent", "UploadRateLimit", 0, RangeValidator(0, 1024 * 1024 * 100))
listenPort = RangeConfigItem("BitTorrent", "ListenPort", 0, RangeValidator(0, 65535))
- metadataTimeout = RangeConfigItem("BitTorrent", "MetadataTimeout", 30, RangeValidator(5, 300))
+ metadataTimeout = RangeConfigItem("BitTorrent", "MetadataTimeout", 60, RangeValidator(5, 300))
enableSequentialDownload = ConfigItem("BitTorrent", "SequentialDownload", False, BoolValidator())
storageMode = OptionsConfigItem(
"BitTorrent", "StorageMode", "sparse", OptionsValidator(["sparse", "allocate"]),
diff --git a/features/bittorrent_pack/session.py b/features/bittorrent_pack/session.py
index eb96f7cf..d4f3fcc3 100644
--- a/features/bittorrent_pack/session.py
+++ b/features/bittorrent_pack/session.py
@@ -27,9 +27,13 @@ DHT_BOOTSTRAP_NODES = (
ALERT_MASK = (
lt.alert.category_t.error_notification
+ | lt.alert.category_t.peer_notification
| lt.alert.category_t.port_mapping_notification
| lt.alert.category_t.storage_notification
+ | lt.alert.category_t.tracker_notification
| lt.alert.category_t.status_notification
+ | lt.alert.category_t.dht_notification
+ | lt.alert.category_t.performance_warning
)
DHT_STATE_FILE = "bt_dht_state.dat"
@@ -279,6 +283,11 @@ class BTSession(QObject):
"dht_bootstrap_nodes": DHT_BOOTSTRAP_NODES,
"announce_to_all_trackers": True,
"announce_to_all_tiers": True,
+ "active_downloads": -1,
+ "active_seeds": -1,
+ "active_limit": -1,
+ "active_checking": -1,
+ "mixed_mode_algorithm": int(lt.bandwidth_mixed_algo_t.prefer_tcp),
"enable_upnp": True,
"enable_natpmp": True,
"alert_mask": ALERT_MASK,
@@ -400,6 +409,10 @@ class BTSession(QObject):
await asyncio.sleep(1)
def _routeAlert(self, alert) -> None:
+ if isinstance(alert, lt.performance_alert):
+ logger.warning("BitTorrent 性能警告: {}", alert.message())
+ return
+
if not hasattr(alert, "handle"):
return