#! /bin/sh /usr/share/dpatch/dpatch-run ## 19_fix_tracker_return_all.dpatch by Cameron Dale ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: Stop the tracker from returning all torrents' peers in every request. @DPATCH@ --- bittornado.orig/BitTornado/BT1/track.py +++ bittornado/BitTornado/BT1/track.py @@ -267,10 +267,9 @@ l4,l4 = [ip,port] nopeerid ''' if config['compact_reqd']: - x = 3 + self.cache_default_len = 3 else: - x = 5 - self.cache_default = [({},{}) for i in xrange(x)] + self.cache_default_len = 5 for infohash, ds in self.downloads.items(): self.seedcount[infohash] = 0 for x,y in ds.items(): @@ -590,6 +589,8 @@ return None + def cache_default(self): + return [({},{}) for i in xrange(self.cache_default_len)] def add_data(self, infohash, event, ip, paramslist): peers = self.downloads.setdefault(infohash, {}) @@ -751,7 +752,7 @@ cache = self.cached_t.setdefault(infohash, None) if ( not cache or len(cache[1]) < rsize or cache[0] + self.config['min_time_between_cache_refreshes'] < clock() ): - bc = self.becache.setdefault(infohash,self.cache_default) + bc = self.becache.setdefault(infohash,self.cache_default()) cache = [ clock(), bc[0][0].values() + bc[0][1].values() ] self.cached_t[infohash] = cache shuffle(cache[1]) @@ -766,7 +767,7 @@ data['peers'] = [] return data - bc = self.becache.setdefault(infohash,self.cache_default) + bc = self.becache.setdefault(infohash,self.cache_default()) len_l = len(bc[2][0]) len_s = len(bc[2][1]) if not (len_l+len_s): # caches are empty! @@ -958,7 +959,7 @@ def natcheckOK(self, infohash, peerid, ip, port, peer): seed = not peer['left'] - bc = self.becache.setdefault(infohash,self.cache_default) + bc = self.becache.setdefault(infohash,self.cache_default()) cp = compact_peer_info(ip, port) reqc = peer['requirecrypto'] bc[2][seed][peerid] = (cp,chr(reqc))