#! /bin/sh /usr/share/dpatch/dpatch-run ## 10_timtuckerfixes.dpatch by Micah Anderson ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: No description. @DPATCH@ --- bittornado.orig/BitTornado/BT1/Connecter.py +++ bittornado/BitTornado/BT1/Connecter.py @@ -46,6 +46,7 @@ self.outqueue = [] self.partial_message = None self.download = None + self.upload = None self.send_choke_queued = False self.just_unchoked = None --- bittornado.orig/BitTornado/BT1/Encrypter.py +++ bittornado/BitTornado/BT1/Encrypter.py @@ -28,22 +28,11 @@ def tobinary16(i): return chr((i >> 8) & 0xFF) + chr(i & 0xFF) -hexchars = '0123456789ABCDEF' -hexmap = [] -for i in xrange(256): - hexmap.append(hexchars[(i&0xF0)/16]+hexchars[i&0x0F]) - -def tohex(s): - r = [] - for c in s: - r.append(hexmap[ord(c)]) - return ''.join(r) - def make_readable(s): if not s: return '' if quote(s).find('%') >= 0: - return tohex(s) + return b2a_hex(s).upper() return '"'+s+'"' --- bittornado.orig/BitTornado/BT1/Storage.py +++ bittornado/BitTornado/BT1/Storage.py @@ -285,20 +285,24 @@ for file, pos, end in self._intervals(pos, amount): if DEBUG: print 'reading '+file+' from '+str(pos)+' to '+str(end) - self.lock.acquire() - h = self._get_file_handle(file, False) - if flush_first and self.whandles.has_key(file): - h.flush() - fsync(h) - h.seek(pos) - while pos < end: - length = min(end-pos, MAXREADSIZE) - data = h.read(length) - if len(data) != length: - raise IOError('error reading data from '+file) - r.append(data) - pos += length - self.lock.release() + try: + self.lock.acquire() + h = self._get_file_handle(file, False) + if flush_first and self.whandles.has_key(file): + h.flush() + fsync(h) + h.seek(pos) + while pos < end: + length = min(end-pos, MAXREADSIZE) + data = h.read(length) + if len(data) != length: + raise IOError('error reading data from '+file) + r.append(data) + pos += length + self.lock.release() + except: + self.lock.release() + raise IOError('error reading data from '+ file) return r def write(self, pos, s): --- bittornado.orig/BitTornado/BT1/StreamCheck.py +++ bittornado/BitTornado/BT1/StreamCheck.py @@ -22,20 +22,8 @@ def toint(s): return long(b2a_hex(s), 16) -def tobinary(i): - return (chr(i >> 24) + chr((i >> 16) & 0xFF) + - chr((i >> 8) & 0xFF) + chr(i & 0xFF)) - -hexchars = '0123456789ABCDEF' -hexmap = [] -for i in xrange(256): - hexmap.append(hexchars[(i&0xF0)/16]+hexchars[i&0x0F]) - def tohex(s): - r = [] - for c in s: - r.append(hexmap[ord(c)]) - return ''.join(r) + return b2a_hex(s).upper() def make_readable(s): if not s: @@ -44,9 +32,6 @@ return tohex(s) return '"'+s+'"' -def toint(s): - return long(b2a_hex(s), 16) - # header, reserved, download id, my id, [length, message] streamno = 0 --- bittornado.orig/BitTornado/ConfigDir.py +++ bittornado/BitTornado/ConfigDir.py @@ -9,6 +9,8 @@ import sys,os from time import time, strftime +from binascii import b2a_hex as tohex, a2b_hex as unhex + try: True except: @@ -23,23 +25,6 @@ DIRNAME = '.'+product_name -hexchars = '0123456789abcdef' -hexmap = [] -revmap = {} -for i in xrange(256): - x = hexchars[(i&0xF0)/16]+hexchars[i&0x0F] - hexmap.append(x) - revmap[x] = chr(i) - -def tohex(s): - r = [] - for c in s: - r.append(hexmap[ord(c)]) - return ''.join(r) - -def unhex(s): - r = [ revmap[s[x:x+2]] for x in xrange(0, len(s), 2) ] - return ''.join(r) def copyfile(oldpath, newpath): # simple file copy, all in RAM try: --- bittornado.orig/BitTornado/RawServer.py +++ bittornado/BitTornado/RawServer.py @@ -71,11 +71,13 @@ return self.excflag def _add_task(self, func, delay, id = None): - assert float(delay) >= 0 + if delay < 0: + delay = 0 insort(self.funcs, (clock() + delay, func, id)) def add_task(self, func, delay = 0, id = None): - assert float(delay) >= 0 + if delay < 0: + delay = 0 self.externally_added.append((func, delay, id)) def scan_for_timeouts(self): --- bittornado.orig/BitTornado/clock.py +++ bittornado/BitTornado/clock.py @@ -1,9 +1,10 @@ # Written by John Hoffman # see LICENSE.txt for license information -from time import * import sys +from time import time + _MAXFORWARD = 100 _FUDGE = 1 @@ -24,4 +25,6 @@ if sys.platform != 'win32': _RTIME = RelativeTime() def clock(): - return _RTIME.get_time() \ No newline at end of file + return _RTIME.get_time() +else: + from time import clock --- bittornado.orig/BitTornado/download_bt1.py +++ bittornado/BitTornado/download_bt1.py @@ -846,17 +846,11 @@ self.rerequest.announce(3) # rerequest automatically if paused for >60 seconds def set_super_seed(self): - try: - self.superseedflag.set() - def s(self = self): - if self.finflag.isSet(): - self._set_super_seed() - self.rawserver.add_task(s) - except AttributeError: - pass + self.superseedflag.set() + self.rawserver.add_task(self._set_super_seed) def _set_super_seed(self): - if not self.super_seeding_active: + if not self.super_seeding_active and self.finflag.isSet(): self.super_seeding_active = True self.errorfunc(' ** SUPER-SEED OPERATION ACTIVE **\n' + ' please set Max uploads so each peer gets 6-8 kB/s') --- bittornado.orig/BitTornado/launchmanycore.py +++ bittornado/BitTornado/launchmanycore.py @@ -194,20 +194,27 @@ self.rawserver.add_task(self.scan, 0) self.rawserver.add_task(self.stats, 0) + self.start() + except: + data = StringIO() + print_exc(file = data) + Output.exception(data.getvalue()) + + def start(self): + try: self.handler.listen_forever() - self.Output.message('shutting down') self.hashcheck_queue = [] for hash in self.torrent_list: self.Output.message('dropped "'+self.torrent_cache[hash]['path']+'"') self.downloads[hash].shutdown() - self.rawserver.shutdown() except: data = StringIO() - print_exc(file = data) - Output.exception(data.getvalue()) + print_exc(file=data) + self.Output.exception(data.getvalue()) + self.rawserver.shutdown() def scan(self): self.rawserver.add_task(self.scan, self.scan_period) @@ -309,6 +316,7 @@ self.torrent_list.append(hash) self.downloads[hash] = d d.start() + return d def saveAs(self, hash, name, saveas, isdir):