Package: bittornado
Version: 0.3.18-8
Followup-For: Bug #475643

An update to the previous patch.  This now works for btlaunchmany too.

-- System Information:
Debian Release: 5.0
  APT prefers stable
  APT policy: (750, 'stable'), (700, 'testing'), (600, 'unstable'), (550, 
'experimental')
Architecture: i386 (i686)

Kernel: Linux 2.6.26-1-686 (SMP w/1 CPU core)
Locale: LANG=en_ZA, LC_CTYPE=en_ZA (charmap=ISO-8859-1)
Shell: /bin/sh linked to /bin/bash

Versions of packages bittornado depends on:
ii  python                        2.5.2-3    An interactive high-level object-o
ii  python-support                0.8.4      automated rebuilding support for P

Versions of packages bittornado recommends:
ii  mime-support             3.44-1          MIME files 'mime.types' & 'mailcap
ii  python-crypto            2.0.1+dfsg1-2.3 cryptographic algorithms and proto

Versions of packages bittornado suggests:
pn  bittornado-gui                <none>     (no description available)
pn  python-psyco                  <none>     (no description available)

-- no debconf information
diff -ru BitTornado.orig/BT1/Encrypter.py BitTornado/BT1/Encrypter.py
--- BitTornado.orig/BT1/Encrypter.py	2009-01-13 12:20:20.000000000 +0200
+++ BitTornado/BT1/Encrypter.py	2009-01-13 12:00:05.000000000 +0200
@@ -574,7 +574,7 @@
             if self.config['security'] and ip != 'unknown' and ip == dns[0]:
                 return True
         try:
-            c = self.raw_server.start_connection(dns)
+            c = self.raw_server.start_connection(dns, bind = self.config['bind'])
             con = Connection(self, c, id, encrypted = encrypted)
             self.connections[c] = con
             c.set_handler(con)
diff -ru BitTornado.orig/RawServer.py BitTornado/RawServer.py
--- BitTornado.orig/RawServer.py	2009-01-13 12:20:19.000000000 +0200
+++ BitTornado/RawServer.py	2009-01-13 11:59:15.000000000 +0200
@@ -93,11 +93,11 @@
         return self.sockethandler.find_and_bind(minport, maxport, bind, reuse,
                                  ipv6_socket_style, upnp, randomizer)
 
-    def start_connection_raw(self, dns, socktype, handler = None):
-        return self.sockethandler.start_connection_raw(dns, socktype, handler)
+    def start_connection_raw(self, dns, socktype, handler = None, bind = None):
+        return self.sockethandler.start_connection_raw(dns, socktype, handler, bind=bind)
 
-    def start_connection(self, dns, handler = None, randomize = False):
-        return self.sockethandler.start_connection(dns, handler, randomize)
+    def start_connection(self, dns, handler = None, randomize = False, bind = None):
+        return self.sockethandler.start_connection(dns, handler, randomize, bind=bind)
 
     def get_stats(self):
         return self.sockethandler.get_stats()
diff -ru BitTornado.orig/ServerPortHandler.py BitTornado/ServerPortHandler.py
--- BitTornado.orig/ServerPortHandler.py	2006-12-21 18:55:42.000000000 +0200
+++ BitTornado/ServerPortHandler.py	2009-01-13 11:58:28.000000000 +0200
@@ -56,10 +56,10 @@
 #    def bind(self, port, bind = '', reuse = False):
 #        pass    # not handled here
         
-    def start_connection(self, dns, handler = None):
+    def start_connection(self, dns, handler = None, bind = None):
         if not handler:
             handler = self.handler
-        c = self.rawserver.start_connection(dns, handler)
+        c = self.rawserver.start_connection(dns, handler, bind=bind)
         return c
 
 #    def listen_forever(self, handler):
diff -ru BitTornado.orig/SocketHandler.py BitTornado/SocketHandler.py
--- BitTornado.orig/SocketHandler.py	2009-01-13 12:20:20.000000000 +0200
+++ BitTornado/SocketHandler.py	2009-01-13 12:00:24.000000000 +0200
@@ -232,10 +232,21 @@
         self.handler = handler
 
 
-    def start_connection_raw(self, dns, socktype = socket.AF_INET, handler = None):
+    def start_connection_raw(self, dns, socktype = socket.AF_INET, handler = None, bind = None):
         if handler is None:
             handler = self.handler
         sock = socket.socket(socktype, socket.SOCK_STREAM)
+        if bind:
+            addrinfos = []
+            bind = bind.split(',')
+            for addr in bind:
+                if sys.version_info < (2,2):
+                    addrinfos.append((socket.AF_INET, None, None, None, (addr, 0)))
+                else:
+                    addrinfos.extend(socket.getaddrinfo(addr, 0,
+                                               socktype, socket.SOCK_STREAM))
+            addrinfo = addrinfos[0]
+            sock.bind(addrinfo[4])
         sock.setblocking(0)
         try:
             sock.connect_ex(dns)
@@ -249,11 +260,11 @@
         return s
 
 
-    def start_connection(self, dns, handler = None, randomize = False):
+    def start_connection(self, dns, handler = None, randomize = False, bind = None):
         if handler is None:
             handler = self.handler
         if sys.version_info < (2,2):
-            s = self.start_connection_raw(dns,socket.AF_INET,handler)
+            s = self.start_connection_raw(dns,socket.AF_INET,handler,bind)
         else:
             if self.ipv6_enable:
                 socktype = socket.AF_UNSPEC
@@ -270,7 +281,7 @@
                 shuffle(addrinfos)
             for addrinfo in addrinfos:
                 try:
-                    s = self.start_connection_raw(addrinfo[4],addrinfo[0],handler)
+                    s = self.start_connection_raw(addrinfo[4],addrinfo[0],handler,bind)
                     break
                 except:
                     pass

Reply via email to