-
-
Save msg7086/95279bbe12febe28671ad84c70724d85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 7cefa89585e6f00c34b5dd5c18d23db96115bdf8 Mon Sep 17 00:00:00 2001 | |
From: | |
Date: Tue, 5 May 2015 21:41:02 -0700 | |
Subject: [PATCH] Add Client Filter | |
--- | |
debian/changelog | 6 ++++++ | |
debian/control | 2 +- | |
libtransmission/Makefile.am | 2 ++ | |
libtransmission/client_filter.c | 26 ++++++++++++++++++++++++++ | |
libtransmission/client_filter.h | 26 ++++++++++++++++++++++++++ | |
libtransmission/handshake.c | 4 ++++ | |
libtransmission/peer-mgr.c | 5 +++++ | |
7 files changed, 70 insertions(+), 1 deletion(-) | |
create mode 100644 libtransmission/client_filter.c | |
create mode 100644 libtransmission/client_filter.h | |
diff --git a/libtransmission/Makefile.am b/libtransmission/Makefile.am | |
index f91769a..6cfd39e 100644 | |
--- a/libtransmission/Makefile.am | |
+++ b/libtransmission/Makefile.am | |
@@ -26,6 +26,7 @@ libtransmission_a_SOURCES = \ | |
blocklist.c \ | |
cache.c \ | |
clients.c \ | |
+ client_filter.c \ | |
completion.c \ | |
ConvertUTF.c \ | |
crypto.c \ | |
@@ -112,6 +113,7 @@ noinst_HEADERS = \ | |
blocklist.h \ | |
cache.h \ | |
clients.h \ | |
+ client_filter.h \ | |
ConvertUTF.h \ | |
crypto.h \ | |
crypto-utils.h \ | |
diff --git a/libtransmission/client_filter.c b/libtransmission/client_filter.c | |
new file mode 100644 | |
index 0000000..f0f9bcb | |
--- /dev/null | |
+++ b/libtransmission/client_filter.c | |
@@ -0,0 +1,26 @@ | |
+/* | |
+ * This file Copyright (C) - | |
+ * | |
+ * This file is licensed by the GPL version 2. Works owned by the | |
+ * Transmission project are granted a special exemption to clause 2 (b) | |
+ * so that the bulk of its code can remain under the MIT license. | |
+ * This exemption does not extend to derived works not owned by | |
+ * the Transmission project. | |
+ * | |
+ */ | |
+ | |
+#include <string.h> | |
+#include "transmission.h" | |
+#include "client_filter.h" | |
+#include "log.h" | |
+ | |
+bool | |
+client_banned (const uint8_t * peer_id) | |
+{ | |
+ 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/client_filter.h b/libtransmission/client_filter.h | |
new file mode 100644 | |
index 0000000..2c7aec3 | |
--- /dev/null | |
+++ b/libtransmission/client_filter.h | |
@@ -0,0 +1,26 @@ | |
+/* | |
+ * This file Copyright (C) - | |
+ * | |
+ * This file is licensed by the GPL version 2. Works owned by the | |
+ * Transmission project are granted a special exemption to clause 2 (b) | |
+ * so that the bulk of its code can remain under the MIT license. | |
+ * This exemption does not extend to derived works not owned by | |
+ * the Transmission project. | |
+ * | |
+ */ | |
+ | |
+#ifndef __TRANSMISSION__ | |
+ #error only libtransmission should #include this header. | |
+#endif | |
+ | |
+#ifndef TR_CLIENT_FILTER_H | |
+#define TR_CLIENT_FILTER_H | |
+ | |
+/** | |
+ * @brief Check if the client shall be banned based on peer_id | |
+ * @ingroup utils | |
+ */ | |
+bool | |
+client_banned (const uint8_t * peer_id); | |
+ | |
+#endif | |
diff --git a/libtransmission/handshake.c b/libtransmission/handshake.c | |
index 4367fbb..dcf2621 100644 | |
--- a/libtransmission/handshake.c | |
+++ b/libtransmission/handshake.c | |
@@ -25,6 +25,7 @@ | |
#include "torrent.h" | |
#include "tr-dht.h" | |
#include "utils.h" | |
+#include "client_filter.h" | |
/* enable LibTransmission extension protocol */ | |
#define ENABLE_LTEP * / | |
@@ -282,6 +283,9 @@ parseHandshake (tr_handshake * handshake, | |
handshake->havePeerID = true; | |
dbgmsg (handshake, "peer-id is [%*.*s]", PEER_ID_LEN, PEER_ID_LEN, peer_id); | |
+ if (client_banned(peer_id)) | |
+ return HANDSHAKE_BAD_TORRENT; | |
+ | |
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..5ba38fd 100644 | |
--- a/libtransmission/peer-mgr.c | |
+++ b/libtransmission/peer-mgr.c | |
@@ -38,6 +38,7 @@ | |
#include "tr-utp.h" | |
#include "utils.h" | |
#include "webseed.h" | |
+#include "client_filter.h" | |
enum | |
{ | |
@@ -2024,6 +2025,10 @@ myHandshakeDoneCB (tr_handshake * handshake, | |
else if (tr_peerIoIsIncoming (io) && (getPeerCount (s) >= getMaxPeerCount (s->tor))) | |
{ | |
} | |
+ else if (client_banned(peer_id)) | |
+ { | |
+ atom->flags2 |= MYFLAG_BANNED; | |
+ } | |
else | |
{ | |
tr_peer * peer = atom->peer; | |
-- | |
2.7.4.1.g5468f9e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment