Here it is

-- 
And that's my crabbing done for the day.  Got it out of the way early, 
now I have the rest of the afternoon to sniff fragrant tea-roses or 
strangle cute bunnies or something.   -- Michael Devore
GnuPG Key Fingerprint 86 F5 81 A5 D4 2E 1F 1C      http://gnupg.org
No more sea shells:  Daniel's Weblog    http://cshore.wordpress.com
diff -Naur bittorrent-3.4.2-11-pristine/BitTorrent/download.py bittorrent-3.4.2/BitTorrent/download.py
--- bittorrent-3.4.2-11-pristine/BitTorrent/download.py	2004-04-02 23:10:45.000000000 -0500
+++ bittorrent-3.4.2/BitTorrent/download.py	2008-05-23 03:34:17.000000000 -0400
@@ -92,6 +92,10 @@
         "the number of uploads to fill out to with extra optimistic unchokes"),
     ('report_hash_failures', 0,
         "whether to inform the user that hash failures occur. They're non-fatal."),
+    ('min_outgoing_port', 1024,
+        "lowest port to which we are willing to connect"),
+    ('max_outgoing_port', 65535,
+        "highest port to which we are willing to connect"),
     ]
 
 def download(params, filefunc, statusfunc, finfunc, errorfunc, doneflag, cols, pathFunc = None, paramfunc = None, spewflag = Event()):
@@ -242,6 +246,13 @@
         errorfunc("Couldn't listen - " + str(e))
         return
 
+    if config['min_outgoing_port'] < 1024 or config['max_outgoing_port'] > 65535:
+        errorfunc("We can only connect to peers using ports between 1024 and 65535")
+        return
+    if config['min_outgoing_port'] > config['max_outgoing_port']:
+        errorfunc("max_outgoing_port less than min_outgoing_port; can't connect")
+        return
+
     choker = Choker(config['max_uploads'], rawserver.add_task, finflag.isSet, 
         config['min_uploads'])
     upmeasure = Measure(config['max_rate_period'], 
@@ -277,7 +288,7 @@
         upmeasure.get_total, downmeasure.get_total, listen_port, 
         config['ip'], myid, infohash, config['http_timeout'], errorfunc, 
         config['max_initiate'], doneflag, upmeasure.get_rate, downmeasure.get_rate,
-        encoder.ever_got_incoming)
+        encoder.ever_got_incoming, config['min_outgoing_port'], config['max_outgoing_port'])
     if config['spew']:
         spewflag.set()
     DownloaderFeedback(choker, rawserver.add_task, statusfunc, 
diff -Naur bittorrent-3.4.2-11-pristine/BitTorrent/Rerequester.py bittorrent-3.4.2/BitTorrent/Rerequester.py
--- bittorrent-3.4.2-11-pristine/BitTorrent/Rerequester.py	2004-04-02 23:10:45.000000000 -0500
+++ bittorrent-3.4.2/BitTorrent/Rerequester.py	2008-05-23 03:33:51.000000000 -0400
@@ -14,7 +14,7 @@
     def __init__(self, url, interval, sched, howmany, minpeers, 
             connect, externalsched, amount_left, up, down,
             port, ip, myid, infohash, timeout, errorfunc, maxpeers, doneflag,
-            upratefunc, downratefunc, ever_got_incoming):
+            upratefunc, downratefunc, ever_got_incoming, min_outgoing, max_outgoing):
         self.url = ('%s?info_hash=%s&peer_id=%s&port=%s&key=%s' %
             (url, quote(infohash), quote(myid), str(port),
             b2a_hex(''.join([chr(randrange(256)) for i in xrange(4)]))))
@@ -41,6 +41,8 @@
         self.ever_got_incoming = ever_got_incoming
         self.last_failed = True
         self.last_time = 0
+        self.min_outgoing = min_outgoing
+        self.max_outgoing = max_outgoing
 
     def c(self):
         self.sched(self.c, self.interval)
@@ -116,10 +118,12 @@
                     for x in xrange(0, len(p), 6):
                         ip = '.'.join([str(ord(i)) for i in p[x:x+4]])
                         port = (ord(p[x+4]) << 8) | ord(p[x+5])
-                        peers.append((ip, port, None))
+                        if port >= min_outgoing and port <= max_outgoing:
+                            peers.append((ip, port, None))
                 else:
                     for x in p:
-                        peers.append((x['ip'], x['port'], x.get('peer id')))
+                        if x['port'] >= min_outgoing and x['port'] <= max_outgoing:
+                            peers.append((x['ip'], x['port'], x.get('peer id')))
                 ps = len(peers) + self.howmany()
                 if ps < self.maxpeers:
                     if self.doneflag.isSet():
diff -Naur bittorrent-3.4.2-11-pristine/debian/changelog bittorrent-3.4.2/debian/changelog
--- bittorrent-3.4.2-11-pristine/debian/changelog	2008-05-22 21:58:42.000000000 -0400
+++ bittorrent-3.4.2/debian/changelog	2008-05-23 03:30:48.000000000 -0400
@@ -1,3 +1,10 @@
+bittorrent (3.4.2-11.1~dfd2) unstable; urgency=low
+
+  * Add outgoing port range limiting in order to play well with strict 
+    firewalls.  Closes: #481276
+
+ -- Daniel Dickinson <[EMAIL PROTECTED]>  Fri, 23 May 2008 03:29:15 -0500
+
 bittorrent (3.4.2-11) unstable; urgency=low
 
   * Add LSB logging functionality. (thanks David!) Closes: #384724

Attachment: signature.asc
Description: PGP signature



Reply via email to