Block Thunder from connecting to transmission-daemon on DebianTransmission is using a weird indent..
Patch
Patched upon transmission-daemon 2.94-1.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 --- a/libtransmission/peer-mgr.c 2018-01-01 00:00:00.000000000 +0000+++ b/libtransmission/peer-mgr.c 2018-01-01 00:00:00.000000000 +0000@@ -1939,6 +1939,19 @@ 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@@ -2036,18 +2049,25 @@ 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;+ 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); - 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));+ } } } }
Install dependencies
1 apt install autotools-dev intltool libcurl4-gnutls-dev libevent-dev libglib2.0-dev libminiupnpc-dev libnatpmp-dev libssl-dev libsystemd-dev zlib1g-dev
Build & Install
Be sure to stop transmission-daemon.service
before installing the patched one.
Extract tarballs from debian:
1 for i in ./*; do tar -xf $i; done;
Apply patches from debian:
1 for i in ../debian/patches/*.patch; do patch -p1 < $i; done;
Make & install.
1234 ./configuremake -j4cp daemon/transmission-daemon /usr/bin/strip /usr/bin/transmission-daemon
Transmission is using a weird indent..
Patch
Patched upon transmission-daemon 2.94-1.
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 | --- a/libtransmission/peer-mgr.c 2018-01-01 00:00:00.000000000 +0000 +++ b/libtransmission/peer-mgr.c 2018-01-01 00:00:00.000000000 +0000 @@ -1939,6 +1939,19 @@ 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 @@ -2036,18 +2049,25 @@ 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; + 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); - 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)); + } } } } |
Install dependencies
1 | apt install autotools-dev intltool libcurl4-gnutls-dev libevent-dev libglib2.0-dev libminiupnpc-dev libnatpmp-dev libssl-dev libsystemd-dev zlib1g-dev |
Build & Install
Be sure to stop transmission-daemon.service
before installing the patched one.
Extract tarballs from debian:
1 | for i in ./*; do tar -xf $i; done; |
Apply patches from debian:
1 | for i in ../debian/patches/*.patch; do patch -p1 < $i; done; |
Make & install.
1 2 3 4 | ./configure make -j4 cp daemon/transmission-daemon /usr/bin/ strip /usr/bin/transmission-daemon |
1 thought on “Block Thunder from connecting to transmission-daemon on Debian”