Example #1
0
    def subtest_connect2downloader(self):
        
        print >> sys.stderr,"test: verifier: Connecting to seeder to check bitfield"
        
        infohash = self.tdef.get_infohash()
        s = BTConnection('localhost',self.mylistenport,user_infohash=infohash)
        s.read_handshake_medium_rare()
        
        try:
            s.s.settimeout(10.0)
            resp = s.recv()
            self.assert_(len(resp) > 0)
            print >> sys.stderr,"test: verifier: Got message",getMessageName(resp[0])
            self.assert_(resp[0] == EXTEND)
            resp = s.recv()
            self.assert_(len(resp) > 0)
            print >> sys.stderr,"test: verifier: Got 2nd message",getMessageName(resp[0])
            self.assert_(resp[0] == BITFIELD)
            b = Bitfield(self.npieces,resp[1:])
            print >> sys.stderr,"test: verifier: Bitfield is",`b.toboollist()`

            b2 = Bitfield(self.npieces)
            b2[0] = True
            msg = BITFIELD+b2.tostring()
            s.send(msg)
            
            time.sleep(5)
            
        except socket.timeout:
            print >> sys.stderr,"test: verifier: Timeout, peer didn't reply"
            self.assert_(False)
        s.close()
 def subtest_is_seeding(self):
     infohash = self.tdef.get_infohash()
     s = BTConnection('localhost',self.hisport,user_infohash=infohash)
     s.read_handshake_medium_rare()
     
     s.send(CHOKE)
     try:
         s.s.settimeout(10.0)
         resp = s.recv()
         self.assert_(len(resp) > 0)
         self.assert_(resp[0] == EXTEND)
     except socket.timeout:
         print >> sys.stderr,"test: Timeout, peer didn't reply"
         self.assert_(False)
     s.close()
Example #3
0
    def subtest_connect2downloader(self):

        print >> sys.stderr, "test: verifier: Connecting to seeder to check bitfield"

        infohash = self.tdef.get_infohash()
        s = BTConnection('localhost',
                         self.mylistenport,
                         user_infohash=infohash)
        s.read_handshake_medium_rare()

        try:
            s.s.settimeout(10.0)
            resp = s.recv()
            self.assert_(len(resp) > 0)
            print >> sys.stderr, "test: verifier: Got message", getMessageName(
                resp[0])
            self.assert_(resp[0] == EXTEND)
            resp = s.recv()
            self.assert_(len(resp) > 0)
            print >> sys.stderr, "test: verifier: Got 2nd message", getMessageName(
                resp[0])
            self.assert_(resp[0] == BITFIELD)
            b = Bitfield(self.npieces, resp[1:])
            print >> sys.stderr, "test: verifier: Bitfield is", ` b.toboollist(
            ) `

            b2 = Bitfield(self.npieces)
            b2[0] = True
            msg = BITFIELD + b2.tostring()
            s.send(msg)

            time.sleep(5)

        except socket.timeout:
            print >> sys.stderr, "test: verifier: Timeout, peer didn't reply"
            self.assert_(False)
        s.close()