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
|
From 9f6f662eeb5d6a1a7fe6544387fc30ada17cb7fe Mon Sep 17 00:00:00 2001
From: Hexhu <i@hexhu.net>
Date: Sun, 14 Jun 2020 07:46:12 -0700
Subject: [PATCH] apply noxunlei patch
diff --git a/libtransmission/handshake.c b/libtransmission/handshake.c
index bab0e2d28..bfad9b124 100644
--- a/libtransmission/handshake.c
+++ b/libtransmission/handshake.c
@@ -271,6 +271,9 @@ static handshake_parse_err_t parseHandshake(tr_handshake* handshake, struct evbu
handshake->havePeerID = true;
dbgmsg(handshake, "peer-id is [%*.*s]", PEER_ID_LEN, PEER_ID_LEN, peer_id);
+ /* Error if the client is banned. */
+ if (tr_peerMgrClientIsBanned(peer_id)) return HANDSHAKE_ENCRYPTION_WRONG;
+
tor = tr_torrentFindFromHash(handshake->session, hash);
if (memcmp(peer_id, tr_torrentGetPeerId(tor), PEER_ID_LEN) == 0)
diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c
index d1239cc16..d2ad0ac57 100644
--- a/libtransmission/peer-mgr.c
+++ b/libtransmission/peer-mgr.c
@@ -2080,7 +2080,7 @@ static bool myHandshakeDoneCB(tr_handshake* handshake, tr_peerIo* io, bool readA
atom->flags |= ADDED_F_UTP_FLAGS;
}
- if ((atom->flags2 & MYFLAG_BANNED) != 0)
+ if (((atom->flags2 & MYFLAG_BANNED) != 0) | tr_peerMgrClientIsBanned(peer_id))
{
tordbg(s, "banned peer %s tried to reconnect", tr_atomAddrStr(atom));
}
@@ -4365,3 +4365,15 @@ static void makeNewPeerConnections(struct tr_peerMgr* mgr, int const max)
tr_free(candidates);
}
+
+bool
+tr_peerMgrClientIsBanned (const uint8_t * peer_id)
+{
+ if (peer_id == NULL) return false;
+ bool banned = false;
+ banned |= !memcmp(peer_id+1, "SD", 2);
+ banned |= !memcmp(peer_id+1, "XL", 2);
+ //if (banned)
+ // tr_logAddNamedError ("Client banned.", "(Client filter)");
+ return banned;
+}
diff --git a/libtransmission/peer-mgr.h b/libtransmission/peer-mgr.h
index 2dd414a97..672d7d4ba 100644
--- a/libtransmission/peer-mgr.h
+++ b/libtransmission/peer-mgr.h
@@ -136,4 +136,7 @@ void tr_peerMgrGotBadPiece(tr_torrent* tor, tr_piece_index_t pieceIndex);
void tr_peerMgrPieceCompleted(tr_torrent* tor, tr_piece_index_t pieceIndex);
+/* Check if the client is banned. XunLei is banned because it never uploads.*/
+bool tr_peerMgrClientIsBanned(const uint8_t* peer_id);
+
/* @} */
--
2.27.0
|