From 35bea84a76e571fc79c8eae7ee1a02a087de3aee Mon Sep 17 00:00:00 2001 From: Tony Hsieh Date: Tue, 20 Aug 2024 13:22:26 +0800 Subject: [PATCH] v240820 1. "lProgressCheckBoundarySize" is changed from 50MB to 30MB 2. Ban the clients: "FlashGet", "Unknown *", "GT *" 3. Ban the clients of the same network (ex: 223.241.234.*, [240e:660:150c:*]) if there are >= 5 clients of this network connected to the same torrent --- qBittorrentBlockXunlei/Program.cs | 42 ++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/qBittorrentBlockXunlei/Program.cs b/qBittorrentBlockXunlei/Program.cs index 242eb44..e330f00 100644 --- a/qBittorrentBlockXunlei/Program.cs +++ b/qBittorrentBlockXunlei/Program.cs @@ -16,7 +16,7 @@ internal class Program static double dLoopIntervalSeconds = 10; // 進度檢查單位 (bytes) - static readonly long lProgressCheckBoundarySize = 50 * 1024 * 1024; + static readonly long lProgressCheckBoundarySize = 30 * 1024 * 1024; static readonly Encoding eOutput = Console.OutputEncoding; @@ -47,7 +47,7 @@ internal class Program static readonly string sTotalSizeFieldText = "\"total_size\":"; static readonly string sPieceSizeFieldText = "\"piece_size\":"; - static readonly List lsLeechClients = new List() { "-XL", "Xunlei", "XunLei", "7.", "aria2", "Xfplay", "dandanplay", "FDM", "go.torrent", "Mozilla", "github.com/anacrolix/torrent (devel) (anacrolix/torrent unknown)", "dt/torrent/", "Taipei-Torrent dev", "trafficConsume", "hp/torrent/", "BitComet 1.92", "BitComet 1.98", "xm/torrent/" }; + static readonly List lsLeechClients = new List() { "-XL", "Xunlei", "XunLei", "7.", "aria2", "Xfplay", "dandanplay", "FDM", "go.torrent", "Mozilla", "github.com/anacrolix/torrent (devel) (anacrolix/torrent unknown)", "dt/torrent/", "Taipei-Torrent dev", "trafficConsume", "hp/torrent/", "BitComet 1.92", "BitComet 1.98", "xm/torrent/", "flashget", "FlashGet", "Unknown", "GT" }; static readonly List lsAncientClients = new List() { "TorrentStorm", "Azureus 1.", "Azureus 2.", "Azureus 3.", "Deluge 0.", "Deluge 1.0", "Deluge 1.1", "qBittorrent 0.", "qBittorrent 1.", "qBittorrent 2.", "Transmission 0.", "Transmission 1." }; static void CCEHandler(object sender, ConsoleCancelEventArgs args) @@ -61,7 +61,7 @@ static void CCEHandler(object sender, ConsoleCancelEventArgs args) static async Task Main(string[] args) { - Console.Title = "qBittorrentBlockXunlei v240706"; + Console.Title = "qBittorrentBlockXunlei v240820"; Console.OutputEncoding = Encoding.UTF8; Console.CancelKeyPress += new ConsoleCancelEventHandler(CCEHandler); @@ -290,6 +290,9 @@ static async Task Main(string[] args) dTorrentPeerProgresses[sTorrentHash] = new Dictionary(); Dictionary dPeerProgresses = dTorrentPeerProgresses[sTorrentHash]; + Dictionary> dPeerNetworks = new Dictionary>(); + Dictionary dPeerToClients = new Dictionary(); + peersBody = await client.GetStringAsync(sTargetServer + sSync_torrentPeers + sTorrentHash); iPeersStartIndex = peersBody.IndexOf(sPeersObjectText); @@ -350,6 +353,24 @@ static async Task Main(string[] args) // 判斷是否要 ban 該 peer bool bBanPeer = false; + // 判斷 peer 所屬的 network + { + char cIpGroupSeparator = '.'; + string sNetwork = sPeer; + if (sPeer.StartsWith("[::ffff:")) + sNetwork = sNetwork.Substring("[::ffff:".Length); + else if (sPeer[0] == '[') + cIpGroupSeparator = ':'; + int Iindex = 0; + for (int i = 0; i < 3; ++i) + Iindex = sNetwork.IndexOf(cIpGroupSeparator, Iindex) + 1; + sNetwork = sNetwork.Substring(0, Iindex); + if (!dPeerNetworks.ContainsKey(sNetwork)) + dPeerNetworks[sNetwork] = new HashSet(); + dPeerNetworks[sNetwork].Add(sPeer); + dPeerToClients[sPeer] = sClient; + } + // 對方回報的進度是 0 或 對方未曾上傳過 if ((dmProgress == 0) || ((lDownloaded == 0) && (dmProgress != 1))) { @@ -426,6 +447,21 @@ static async Task Main(string[] args) sbBanPeers.Append(sPeer + "|"); } + foreach (string sNetwork in new List(dPeerNetworks.Keys)) + { + // 同一 network 下有 >= 5 個不同 IP 連線 + if (dPeerNetworks[sNetwork].Count >= 5) + { + foreach (string sPeer in dPeerNetworks[sNetwork]) + { + Console.WriteLine("Banned - Same Network Clients: " + dPeerToClients[sPeer] + ", " + sPeer); + sbBanPeers.Append(sPeer + "|"); + } + } + dPeerNetworks[sNetwork].Clear(); + } + dPeerNetworks.Clear(); + // 某些情況下,有可能 "種子實際大小 = -1",移除種子相關紀錄,待下一輪重新檢測 if (dTorrentSizes[sTorrentHash] <= 0) {