summarylogtreecommitdiffstats
path: root/ban-xunlei.patch
blob: 288e89698dd1a0bcd7a4912f01ba27cafdfd20fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
diff --git a/libtransmission/handshake.cc b/libtransmission/handshake.cc
index 6be04586c..8cbaf6edf 100644
--- a/libtransmission/handshake.cc
+++ b/libtransmission/handshake.cc
@@ -20,6 +20,7 @@
 #include "handshake.h"
 #include "log.h"
 #include "peer-io.h"
+#include "peer-mgr.h"
 #include "timer.h"
 #include "tr-assert.h"
 #include "tr-buffer.h"
@@ -110,6 +111,9 @@ tr_handshake::ParseResult tr_handshake::parse_handshake(tr_peerIo* peer_io)
         return ParseResult::PeerIsSelf;
     }
 
+    /* bans leetch-only clients */
+    if (tr_peerMgrClientIsBanned(peer_id)) return ParseResult::PeerIsLeetcher;
+
     return ParseResult::Ok;
 }
 
diff --git a/libtransmission/handshake.h b/libtransmission/handshake.h
index c9b6582c4..2d0769b1e 100644
--- a/libtransmission/handshake.h
+++ b/libtransmission/handshake.h
@@ -80,6 +80,7 @@ private:
         EncryptionWrong,
         BadTorrent,
         PeerIsSelf,
+        PeerIsLeetcher,
     };
 
     enum class State
diff --git a/libtransmission/peer-mgr.cc b/libtransmission/peer-mgr.cc
index f17577647..75c78b80a 100644
--- a/libtransmission/peer-mgr.cc
+++ b/libtransmission/peer-mgr.cc
@@ -828,7 +828,7 @@ void tr_peerMgrSetUtpFailed(tr_torrent* tor, tr_address const& addr, bool failed
  * REQUESTS
  *
  * There are two data structures associated with managing block requests:
- * 
+ *
  * 1. tr_swarm::active_requests, an opaque class that tracks what requests
  *    we currently have, i.e. which blocks and from which peers.
  *    This is used for cancelling requests that have been waiting
@@ -968,6 +968,24 @@ void tr_peerMgrPieceCompleted(tr_torrent* tor, tr_piece_index_t p)
     tor->set_needs_completeness_check();
 }
 
+bool tr_peerMgrClientIsBanned(const tr_peer_id_t& peer_id_arr)
+{
+    const char* peer_id = peer_id_arr.data();
+    bool banned = peer_id_arr.empty();
+    // Names like '-DL3760-', '-FD51YC-', '-XL0012-', ...
+    banned |= !memcmp(peer_id, "-BN", 3);
+    banned |= !memcmp(peer_id, "-DL", 3);
+    banned |= !memcmp(peer_id, "-FD", 3);
+    banned |= !memcmp(peer_id, "-QD", 3);
+    banned |= !memcmp(peer_id, "-SD", 3);
+    banned |= !memcmp(peer_id, "-XF", 3);
+    banned |= !memcmp(peer_id, "-XL", 3);
+    banned |= !memcmp(peer_id, "Xunlei", 6);
+    banned |= !memcmp(peer_id, "Thunder", 7);
+    banned |= !memcmp(peer_id, "QQDownload", 10);
+    return banned;
+}
+
 namespace
 {
 namespace handshake_helpers
@@ -1058,6 +1076,10 @@ void create_bit_torrent_peer(tr_torrent* tor, std::shared_ptr<tr_peerIo> io, str
             atom->flags2 &= ~MyflagUnreachable;
         }
 
+        if (!result.peer_id.has_value()) {
+            tr_logAddDebugSwarm(s, fmt::format("Warning: peer with no peer id (IP: {}) tried to reconnect", atom->display_name()));
+        }
+
         /* In principle, this flag specifies whether the peer groks µTP,
            not whether it's currently connected over µTP. */
         if (result.io->is_utp())
@@ -1069,6 +1091,10 @@ void create_bit_torrent_peer(tr_torrent* tor, std::shared_ptr<tr_peerIo> io, str
         {
             tr_logAddTraceSwarm(s, fmt::format("banned peer {} tried to reconnect", atom->display_name()));
         }
+        else if (result.peer_id.has_value() && tr_peerMgrClientIsBanned(result.peer_id.value()))
+        {
+            tr_logAddDebugSwarm(s, fmt::format("banned leetch-only peer (peer_id: {}, IP: {}) tried to connect", result.peer_id.value().data(), atom->display_name()));
+        }
         else if (result.io->is_incoming() && s->peerCount() >= s->tor->peerLimit())
         {
             /* too many peers already */
diff --git a/libtransmission/peer-mgr.h b/libtransmission/peer-mgr.h
index 4566e685b..25d106b33 100644
--- a/libtransmission/peer-mgr.h
+++ b/libtransmission/peer-mgr.h
@@ -222,4 +222,7 @@ void tr_peerMgrGotBadPiece(tr_torrent* tor, tr_piece_index_t piece_index);
 
 void tr_peerMgrPieceCompleted(tr_torrent* tor, tr_piece_index_t pieceIndex);
 
+/* Check if the client is banned. XunLei is banned because it is leetch-only (never uploads). */
+bool tr_peerMgrClientIsBanned(const tr_peer_id_t& peer_id);
+
 /* @} */