Esempio n. 1
0
 def _test_tlookup(self,httpseedlist):
     t = TorrentDef()
     fn = os.path.join(os.getcwd(),"file.wmv")
     t.add_content(fn)
     t.set_tracker(self.session.get_internal_tracker_url())
     t.set_urllist(httpseedlist)
     t.finalize()
     wantdata = bencode(t.get_metainfo())
     
     self.session.add_to_internal_tracker(t)
     #time.sleep(30)
     
     (scheme, netloc, path, pars, query, fragment) = urlparse.urlparse(self.session.get_internal_tracker_url())
     urlprefix = scheme+'://'+netloc+'/tlookup?'
     for httpseed in httpseedlist:
         quoted = urllib.quote(httpseed)
         url = urlprefix+quoted
         #url = "http://www.cs.vu.nl/~arno/index.html"
         print >>sys.stderr,time.asctime(),'-', "test: Asking tracker for",url
         # F*ing BitTornado/Python crap: using normal urlopen here results in
         # an infinitely hanging read (even if read(1024))
         conn = urlopen(url)
         gotdata = conn.read()
         print >>sys.stderr,time.asctime(),'-', "test: Tracker sent",len(gotdata)
         conn.close()
         self.assertEquals(wantdata,gotdata)
Esempio n. 2
0
 def check_http_presence(self,hexinfohash,present):
     print >> sys.stderr,time.asctime(),'-', "test: infohash is",hexinfohash
     url = 'http://127.0.0.1:'+str(self.session.get_listen_port())+'/'
     print >> sys.stderr,time.asctime(),'-', "test: tracker lives at",url
     f = urlopen(url)
     data = f.read()
     f.close()
     
     # WARNING: this test depends on the output of the tracker. If that
     # is changed, also change this.
     print >> sys.stderr,time.asctime(),'-', "test: tracker returned:",data
     if present:
         self.assert_(data.find(hexinfohash) != -1)
     else:
         self.assert_(data.find(hexinfohash) == -1)
Esempio n. 3
0
    def _rerequest_single(self, t, s, l, callback):
        try:        
            closer = [None]
            def timedout(self = self, l = l, closer = closer):
                if self.lock.trip(l):
                    self.errorcodes['troublecode'] = 'Problem connecting to tracker - timeout exceeded'
                    self.lock.unwait(l)
                try:
                    closer[0]()
                except:
                    pass
                    
            self.externalsched(timedout, self.timeout)

            err = None
            try:
                if DEBUG:
                    print >>sys.stderr,time.asctime(),'-', "Rerequest tracker:"
                    print >>sys.stderr,time.asctime(),'-', t+s
                h = urlopen(t+s)
                closer[0] = h.close
                data = h.read()
            except (IOError, error), e:
                err = 'Problem connecting to tracker - ' + str(e)
                if DEBUG:
                    print_exc()
            except:
                err = 'Problem connecting to tracker'
                if DEBUG:
                    print_exc()
                    
                    
            #if DEBUG:
            #    print >>sys.stderr,time.asctime(),'-', "rerequest: Got data",data
                    
            try:
                h.close()
            except:
                pass
            if err:        
                if self.lock.trip(l):
                    self.errorcodes['troublecode'] = err
                    self.lock.unwait(l)
                return

            if not data:
                if self.lock.trip(l):
                    self.errorcodes['troublecode'] = 'no data from tracker'
                    self.lock.unwait(l)
                return
            
            try:
                r = bdecode(data, sloppy=1)
                if DEBUG:
                    print >>sys.stderr,time.asctime(),'-', "Rerequester: Tracker returns:", r
                check_peers(r)
                
                #print >>sys.stderr,time.asctime(),'-', "Rerequester: Tracker returns, post check done"
                
            except ValueError, e:
                if DEBUG:
                    print_exc()
                if self.lock.trip(l):
                    self.errorcodes['bad_data'] = 'bad data from tracker - ' + str(e)
                    self.lock.unwait(l)
                return
Esempio n. 4
0
    def _rerequest_single(self, t, s, l, callback):
        try:
            closer = [None]

            def timedout(self=self, l=l, closer=closer):
                if self.lock.trip(l):
                    self.errorcodes[
                        'troublecode'] = 'Problem connecting to tracker - timeout exceeded'
                    self.lock.unwait(l)
                try:
                    closer[0]()
                except:
                    pass

            self.externalsched(timedout, self.timeout)

            err = None
            try:
                if DEBUG:
                    print >> sys.stderr, "Rerequest tracker:"
                    print >> sys.stderr, t + s
                h = urlopen(t + s)
                closer[0] = h.close
                data = h.read()
            except (IOError, error), e:
                err = 'Problem connecting to tracker - ' + str(e)
                if DEBUG:
                    print_exc()
            except:
                err = 'Problem connecting to tracker'
                if DEBUG:
                    print_exc()

            #if DEBUG:
            #    print >>sys.stderr,"rerequest: Got data",data

            try:
                h.close()
            except:
                pass
            if err:
                if self.lock.trip(l):
                    self.errorcodes['troublecode'] = err
                    self.lock.unwait(l)
                return

            if not data:
                if self.lock.trip(l):
                    self.errorcodes['troublecode'] = 'no data from tracker'
                    self.lock.unwait(l)
                return

            try:
                r = bdecode(data, sloppy=1)
                if DEBUG:
                    print >> sys.stderr, "Rerequester: Tracker returns:", r
                check_peers(r)

                #print >>sys.stderr,"Rerequester: Tracker returns, post check done"

            except ValueError, e:
                if DEBUG:
                    print_exc()
                if self.lock.trip(l):
                    self.errorcodes[
                        'bad_data'] = 'bad data from tracker - ' + str(e)
                    self.lock.unwait(l)
                return