Patch for blocking Thunder in transmission 3.00I wrote a blog about blocking Thunder in tranmission-daemon 2.94.
The patch does not apply cleanly on Transmission 3.00, so I update it here:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 --- a/libtransmission/peer-mgr.c 2021-08-31 03:10:20.435836776 +0800+++ b/libtransmission/peer-mgr.c 2021-08-31 03:14:31.268153266 +0800@@ -2007,6 +2007,21 @@ tr_peerMsgsUpdateActive(msgs, TR_DOWN); } +static bool isUserAgentBad(const char* ua)+{+ static const char* blacklist[] = {"Thunder", "Xunlei"};+ int i;++ for (i = 0; i != sizeof(blacklist) / sizeof(blacklist[0]); ++i) {+ // Performs bad, honestly.+ if (!strncmp(blacklist[i], ua, strlen(blacklist[i]))) {+ return true;+ }+ }+ return false;+}++ /* FIXME: this is kind of a mess. */ static bool myHandshakeDoneCB(tr_handshake* handshake, tr_peerIo* io, bool readAnythingFromPeer, bool isConnected, uint8_t const* peer_id, void* vmanager)@@ -2100,21 +2115,29 @@ tr_quark client; tr_peerIo* io; char buf[128];+ const char* ua = ""; if (peer_id != NULL) {- client = tr_quark_new(tr_clientForId(buf, sizeof(buf), peer_id), TR_BAD_SIZE);+ client = tr_quark_new((ua = tr_clientForId(buf, sizeof(buf), peer_id)), TR_BAD_SIZE); } else { client = TR_KEY_NONE; } - io = tr_handshakeStealIO(handshake); /* this steals its refcount too, which is balanced by our unref in peerDelete() */- tr_peerIoSetParent(io, &s->tor->bandwidth);- createBitTorrentPeer(s->tor, io, atom, client);+ if (!isUserAgentBad(ua))+ {+ io = tr_handshakeStealIO(handshake); /* this steals its refcount too, which is balanced by our unref in peerDelete() */+ tr_peerIoSetParent(io, &s->tor->bandwidth);+ createBitTorrentPeer(s->tor, io, atom, client); - success = true;+ success = true;+ }+ else+ {+ tr_logAddDebug("Bad user agent \"%s\" (peer %s) tried to connect to us", ua, tr_atomAddrStr(atom));+ } } } }
The rest instructions are the same as the previous post.
I wrote a blog about blocking Thunder in tranmission-daemon 2.94.
The patch does not apply cleanly on Transmission 3.00, so I update it here:
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 | --- a/libtransmission/peer-mgr.c 2021-08-31 03:10:20.435836776 +0800 +++ b/libtransmission/peer-mgr.c 2021-08-31 03:14:31.268153266 +0800 @@ -2007,6 +2007,21 @@ tr_peerMsgsUpdateActive(msgs, TR_DOWN); } +static bool isUserAgentBad(const char* ua) +{ + static const char* blacklist[] = {"Thunder", "Xunlei"}; + int i; + + for (i = 0; i != sizeof(blacklist) / sizeof(blacklist[0]); ++i) { + // Performs bad, honestly. + if (!strncmp(blacklist[i], ua, strlen(blacklist[i]))) { + return true; + } + } + return false; +} + + /* FIXME: this is kind of a mess. */ static bool myHandshakeDoneCB(tr_handshake* handshake, tr_peerIo* io, bool readAnythingFromPeer, bool isConnected, uint8_t const* peer_id, void* vmanager) @@ -2100,21 +2115,29 @@ tr_quark client; tr_peerIo* io; char buf[128]; + const char* ua = ""; if (peer_id != NULL) { - client = tr_quark_new(tr_clientForId(buf, sizeof(buf), peer_id), TR_BAD_SIZE); + client = tr_quark_new((ua = tr_clientForId(buf, sizeof(buf), peer_id)), TR_BAD_SIZE); } else { client = TR_KEY_NONE; } - io = tr_handshakeStealIO(handshake); /* this steals its refcount too, which is balanced by our unref in peerDelete() */ - tr_peerIoSetParent(io, &s->tor->bandwidth); - createBitTorrentPeer(s->tor, io, atom, client); + if (!isUserAgentBad(ua)) + { + io = tr_handshakeStealIO(handshake); /* this steals its refcount too, which is balanced by our unref in peerDelete() */ + tr_peerIoSetParent(io, &s->tor->bandwidth); + createBitTorrentPeer(s->tor, io, atom, client); - success = true; + success = true; + } + else + { + tr_logAddDebug("Bad user agent \"%s\" (peer %s) tried to connect to us", ua, tr_atomAddrStr(atom)); + } } } } |
The rest instructions are the same as the previous post.