You are not logged in.

#1 2020-05-31 09:02:57

hexhu
Member
Registered: 2019-11-10
Posts: 4

PKGBUILD review request: transmission-noxunlei

Hi All,

I have been looking for transmission that offers client-based blocking, and I created
a simple patch on libtransmission that naively rejects peer handshake from well-known
leecher clients (for now, just XunLei). PKGBUILD is based on extra/transmission.

The motivation: Xunlei (aka Thunder) is a well-known leecher in much of the P2P world.
As a download-only tool, it supports both eMule and BitTorrent protocols. Almost all of its
seeding is done with a proprietary protocol among Xunlei clients only.
For the company behind Xunlei (Thunder), see en.wikipedia.org/wiki/Xunlei

The current transmission blocklist is purely by IP:
github.com/transmission/transmission/wiki/Blocklists

Following github.com/transmission/transmission/issues/735, I created a patch (see below).

There is a similar package already in AUR, but for qbittorrent:
aur.archlinux.org/packages/qbittorrent-enhanced-git/

Future plan:
1. Merge github.com/transmission/transmission/pull/1062 for full-featured client-based blocking.
2. upgrade to transmission 3.00

Please let me know if there are any issues.

PKGBUILD:

# Maintainer : Hexhu <i at hexhu.net>
# Contributor : Tom Gundersen <teg at jklm.no>
# Contributor : Ionut Biru <ibiru at archlinux.org>

pkgbase=transmission-noxunlei
pkgname=(transmission-noxunlei-cli transmission-noxunlei-gtk transmission-noxunlei-qt)
pkgver=2.94
pkgrel=1
arch=(x86_64)
url="http://www.transmissionbt.com/"
license=(MIT)
makedepends=(gtk3 intltool curl qt5-base libevent systemd qt5-tools)
source=(https://github.com/transmission/transmission-releases/raw/master/transmission-${pkgver}.tar.xz
ban-xunlei.patch
transmission-2.90-libsystemd.patch
transmission-noxunlei-cli.sysusers
transmission-noxunlei-cli.tmpfiles)
sha256sums=('SKIP'
'a4c38c31b0826fb9ab5ff8786f79f5d48f0c74b0f1ed53ecf781fcfe75d1c0a4'
'9f8f4bb532e0e46776dbd90e75557364f495ec95896ee35900ea222d69bda411'
'641310fb0590d40e00bea1b5b9c843953ab78edf019109f276be9c6a7bdaf5b2'
'1266032bb07e47d6bcdc7dabd74df2557cc466c33bf983a5881316a4cc098451')

prepare() {
ln -sf transmission-$pkgver $pkgbase-$pkgver
cd $pkgbase-$pkgver
patch -Np1 -i "$srcdir/transmission-2.90-libsystemd.patch"

# Ban Xunlei (Thunder) downloader as described in blog.zscself.com/posts/66b00f02/
patch -Np1 -i "$srcdir/ban-xunlei.patch"

rm -f m4/glib-gettext.m4
autoreconf -fi

sed -i '/^Icon=/ s/$/-qt/' qt/transmission-qt.desktop
}

build() {
cd $pkgbase-$pkgver
./configure --prefix=/usr
make

cd qt
qmake qtr.pro \
DEFINES+=TRANSLATIONS_DIR=\\\\\\\"/usr/share/transmission-qt/translations\\\\\\\"
make
lrelease translations/*.ts
}

package_transmission-noxunlei-cli() {
pkgdesc='Fast, easy, and free BitTorrent client (CLI tools, daemon and web client), patched to ban Xunlei (a well-known leecher client)'
depends=(curl libevent systemd)
conflicts=(transmission-cli)
provides=(transmission-cli)

cd $pkgbase-$pkgver

for dir in daemon cli web utils; do
make -C "$dir" DESTDIR="$pkgdir" install
done

install -Dm644 daemon/transmission-daemon.service \
"$pkgdir/usr/lib/systemd/system/transmission.service"
install -Dm644 COPYING "$pkgdir/usr/share/licenses/transmission-cli/COPYING"

install -Dm644 "$srcdir/$pkgname.sysusers" \
"$pkgdir/usr/lib/sysusers.d/transmission.conf"
install -Dm644 "$srcdir/$pkgname.tmpfiles" \
"$pkgdir/usr/lib/tmpfiles.d/transmission.conf"
}

package_transmission-noxunlei-gtk() {
pkgdesc='Fast, easy, and free BitTorrent client (GTK+ GUI), patched to ban Xunlei (a well-known leecher client)'
depends=(curl libevent gtk3 desktop-file-utils hicolor-icon-theme)
optdepends=('libnotify: Desktop notification support'
'transmission-cli: daemon and web support')
provides=(transmission-gtk)
conflicts=(transmission-gtk)

cd $pkgbase-$pkgver

make -C gtk DESTDIR="$pkgdir" install
make -C po DESTDIR="$pkgdir" install
install -Dm644 COPYING "$pkgdir/usr/share/licenses/transmission-gtk/COPYING"
}

package_transmission-noxunlei-qt() {
pkgdesc='Fast, easy, and free BitTorrent client (Qt GUI), patched to ban Xunlei (a well-known leecher client)'
depends=(curl qt5-base libevent)
optdepends=('transmission-cli: daemon and web support')
provides=(transmission-qt)
conflicts=(transmission-qt)

cd $pkgbase-$pkgver

make -C qt INSTALL_ROOT="$pkgdir"/usr install
install -Dm644 -t "$pkgdir/usr/share/transmission-qt/translations" \
qt/translations/*.qm

install -Dm644 COPYING "$pkgdir/usr/share/licenses/transmission-qt/COPYING"
install -Dm644 qt/icons/transmission.png \
"$pkgdir/usr/share/pixmaps/transmission-qt.png"
install -Dm644 qt/transmission-qt.desktop \
"$pkgdir/usr/share/applications/transmission-qt.desktop"
}

ban-xunlei.patch:

diff --git a/libtransmission/handshake.c b/libtransmission/handshake.c
index 8dc08d3..15702e0 100644
--- a/libtransmission/handshake.c
+++ b/libtransmission/handshake.c
@@ -282,6 +282,9 @@ parseHandshake (tr_handshake * handshake,
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))
{
diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c
index 30e9036..f6a249d 100644
--- a/libtransmission/peer-mgr.c
+++ b/libtransmission/peer-mgr.c
@@ -2016,7 +2016,7 @@ myHandshakeDoneCB (tr_handshake * handshake,
if (io->utp_socket)
atom->flags |= ADDED_F_UTP_FLAGS;

- if (atom->flags2 & MYFLAG_BANNED)
+ if ((atom->flags2 & MYFLAG_BANNED) | tr_peerMgrClientIsBanned(peer_id))
{
tordbg (s, "banned peer %s tried to reconnect",
tr_atomAddrStr (atom));
@@ -4082,3 +4082,15 @@ makeNewPeerConnections (struct tr_peerMgr * mgr, const int 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 5ee45ae..5d64914 100644
--- a/libtransmission/peer-mgr.h
+++ b/libtransmission/peer-mgr.h
@@ -184,7 +184,8 @@ void tr_peerMgrGotBadPiece (tr_torrent * tor,
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);

Offline

Board footer

Powered by FluxBB