def _restore_state(self): def decode_line(line): hashtext = line[:40] try: infohash = hashtext.decode('hex') except: raise BTFailure("Invalid state file contents") if len(infohash) != 20: raise BTFailure("Invalid state file contents") try: path = os.path.join(self.config['data_dir'], 'metainfo', hashtext) f = file(path, 'rb') data = f.read() f.close() except Exception, e: try: f.close() except: pass self.global_error("ERROR", "Error reading file %s (%s), \ cannot restore state completely" % (path, str(e))) return None if infohash in self.torrents: raise BTFailure("Invalid state file (duplicate entry)") t = Torrent(infohash) self.torrents[infohash] = t try: t.metainfo = ConvertedMetainfo(bdecode(data)) except Exception, e: self.global_error("ERROR", "Corrupt data in "+path+ " , cannot restore torrent ("+str(e)+")") return None
def _restore_state(self): def decode_line(line): hashtext = line[:40] try: infohash = hashtext.decode('hex') except: raise BTFailure("Invalid state file contents") if len(infohash) != 20: raise BTFailure("Invalid state file contents") try: path = os.path.join(self.config['data_dir'], 'metainfo', hashtext) f = file(path, 'rb') data = f.read() f.close() except Exception, e: try: f.close() except: pass self.global_error( "ERROR", "Error reading file %s (%s), \ cannot restore state completely" % (path, str(e))) return None if infohash in self.torrents: raise BTFailure("Invalid state file (duplicate entry)") t = Torrent(infohash) self.torrents[infohash] = t try: t.metainfo = ConvertedMetainfo(bdecode(data)) except Exception, e: self.global_error( "ERROR", "Corrupt data in " + path + " , cannot restore torrent (" + str(e) + ")") return None
def run(self, scrwin): def reread(): self.multitorrent.schedule(0, self.reread_config) self.d = CursesDisplayer(scrwin, self.errlist, self.doneflag, reread) try: self.multitorrent = Multitorrent(self.config, self.doneflag) # raises BTFailure if bad metainfo = ConvertedMetainfo(bdecode(self.metainfo)) torrent_name = metainfo.name_fs if config['save_as']: if config['save_in']: raise BTFailure('You cannot specify both --save_as and ' '--save_in') saveas = config['save_as'] elif config['save_in']: saveas = os.path.join(config['save_in'], torrent_name) else: saveas = torrent_name self.d.set_torrent_values(metainfo.name, os.path.abspath(saveas), metainfo.file_size, len(metainfo.hashes)) self.torrent = self.multitorrent.start_torrent(metainfo, self.config, self, saveas) except BTFailure, e: errlist.append(str(e)) return
def run(self, scrwin): def reread(): self.multitorrent.schedule(0, self.reread_config) self.d = CursesDisplayer(scrwin, self.errlist, self.doneflag, reread) try: self.multitorrent = Multitorrent(self.config, self.doneflag) # raises BTFailure if bad metainfo = ConvertedMetainfo(bdecode(self.metainfo)) torrent_name = metainfo.name_fs if config['save_as']: if config['save_in']: raise BTFailure('You cannot specify both --save_as and ' '--save_in') saveas = config['save_as'] elif config['save_in']: saveas = os.path.join(config['save_in'], torrent_name) else: saveas = torrent_name self.d.set_torrent_values(metainfo.name, os.path.abspath(saveas), metainfo.file_size, len(metainfo.hashes)) self.torrent = self.multitorrent.start_torrent( metainfo, self.config, self, saveas) except BTFailure, e: errlist.append(str(e)) return
def start_new_torrent(self, data): t = Torrent() try: t.metainfo = ConvertedMetainfo(bdecode(data)) except Exception, e: self.global_error("ERROR", "This is not a valid torrent file. (%s)" % str(e)) return
def start_new_torrent(self, data): t = Torrent() try: t.metainfo = ConvertedMetainfo(bdecode(data)) except Exception, e: self.global_error( "ERROR", "This is not a valid torrent file. (%s)" % str(e)) return
def anomosify(data, announce="https://tracker.anomos.info:5555/announce"): r = bdecode(data) if 'announce-list' in r: for a, l in enumerate(r['announce-list']): if a == 0: r['announce-list'][a] = announce else: del r['announce-list'][a:] r['announce'] = announce r['anon'] = '1' return bencode(r)
def anomosify(data, announce="https://tracker.anomos.info:5555/announce"): r = bdecode(data) if 'announce-list' in r: for a,l in enumerate(r['announce-list']): if a == 0: r['announce-list'][a] = announce else: del r['announce-list'][a:] r['announce'] = announce r['anon'] = '1' return bencode(r)
def _postrequest(self, data=None, errormsg=None): self.current_started = None self.last_time = bttime() if errormsg is not None: log.warning(errormsg) self._fail() return try: # Here's where we receive/decrypt data from the tracker r = bdecode(data) check_peers(r) except BTFailure, e: if data != '': log.error('bad data from tracker - ' + str(e)) self._fail() return
def run(self): self.d = HeadlessDisplayer(self.doneflag) try: self.multitorrent = Multitorrent(self.config, self.doneflag) # raises BTFailure if bad metainfo = ConvertedMetainfo(bdecode(self.metainfo)) torrent_name = metainfo.name_fs if config['save_as']: if config['save_in']: raise BTFailure('You cannot specify both --save_as and ' '--save_in') saveas = config['save_as'] elif config['save_in']: saveas = os.path.join(config['save_in'], torrent_name) else: saveas = torrent_name self.d.set_torrent_values(metainfo.name, os.path.abspath(saveas), metainfo.file_size, len(metainfo.hashes)) self.torrent = self.multitorrent.start_torrent(metainfo, self.config, self, saveas) except BTFailure, e: print str(e) return
self.spath = "/scrape" if not self.https: log.warning("Warning: Will not connect to non HTTPS server") return try: if self.proxy_url: h = ProxyHTTPSConnection(self.proxy_url, \ username=self.proxy_username, \ password=self.proxy_password, \ ssl_context=self.ssl_ctx) s = "https://%s:%d%s%s" % (self.url, self.remote_port, self.spath, query) h.putrequest('GET', s) else: #No proxy url, use normal connection h = HTTPSConnection(self.url, self.remote_port, ssl_context=self.ssl_ctx) h.putrequest('GET', self.spath+query) h.endheaders() resp = h.getresponse() data = resp.read() resp.close() h.close() h = None # urllib2 can raise various crap that doesn't have a common base # exception class especially when proxies are used, at least # ValueError and stuff from httplib except Exception, g: def f(r='Problem connecting to ' + self.url + ': ' + str(g)): self._postrequest(errormsg=r) return bdecode(data)
to_add.sort() for p in to_add: # then, parse new and changed torrents new_file = new_files[p] v = new_file[0] if new_file[1] in new_parsed: # duplicate if p not in blocked or files[p][0] != v: errfunc('**warning** ' + p + ' is a duplicate torrent for ' + new_parsed[new_file[1]]['path']) new_blocked[p] = None continue if NOISY: errfunc('adding ' + p) try: ff = open(p, 'rb') d = bdecode(ff.read()) check_message(d) h = hashlib.sha1(bencode(d['info'])).digest() new_file[1] = h if new_parsed.has_key(h): errfunc('**warning** ' + p + ' is a duplicate torrent for ' + new_parsed[h]['path']) new_blocked[p] = None continue a = {} a['path'] = p f = os.path.basename(p) a['file'] = f i = d['info'] l = 0
# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # Written by Henry 'Pi' James and Bram Cohen from sys import argv from Anomos.bencode import bencode, bdecode if len(argv) < 3: print '%s http://new.uri:port/announce file1.torrent file2.torrent' % argv[ 0] print exit(2) # common exit code for syntax error for f in argv[2:]: h = open(f, 'rb') metainfo = bdecode(h.read()) h.close() if metainfo['announce'] != argv[1]: print 'old announce for %s: %s' % (f, metainfo['announce']) metainfo['announce'] = argv[1] h = open(f, 'wb') h.write(bencode(metainfo)) h.close()
to_add.sort() for p in to_add: # then, parse new and changed torrents new_file = new_files[p] v = new_file[0] if new_file[1] in new_parsed: # duplicate if p not in blocked or files[p][0] != v: errfunc('**warning** '+ p + ' is a duplicate torrent for ' + new_parsed[new_file[1]]['path']) new_blocked[p] = None continue if NOISY: errfunc('adding '+p) try: ff = open(p, 'rb') d = bdecode(ff.read()) check_message(d) h = hashlib.sha1(bencode(d['info'])).digest() new_file[1] = h if new_parsed.has_key(h): errfunc('**warning** '+ p + ' is a duplicate torrent for '+new_parsed[h]['path']) new_blocked[p] = None continue a = {} a['path'] = p f = os.path.basename(p) a['file'] = f i = d['info'] l = 0
# (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # Written by Henry 'Pi' James and Bram Cohen from sys import argv from Anomos.bencode import bencode, bdecode if len(argv) < 3: print '%s http://new.uri:port/announce file1.torrent file2.torrent' % argv[0] print exit(2) # common exit code for syntax error for f in argv[2:]: h = open(f, 'rb') metainfo = bdecode(h.read()) h.close() if metainfo['announce'] != argv[1]: print 'old announce for %s: %s' % (f, metainfo['announce']) metainfo['announce'] = argv[1] h = open(f, 'wb') h.write(bencode(metainfo)) h.close()