Exemplo n.º 1
0
    def check_hashpiece(self,resp):
        """ Merkle BEP style """
        print >>sys.stderr,"test: good_request: check_hashpiece"
        self.assert_(resp[0] == EXTEND)
        self.assert_(resp[1] == HASHPIECE)
        index = toint(resp[2:2+4])
        begin = toint(resp[6:6+4])
        ohlen = toint(resp[10:10+4])
        print >>sys.stderr,"test: good_request: check_hashpiece",index,begin,ohlen
        bohlist = resp[14:14+ohlen]
        hisohlist = bdecode(bohlist)
        hischunk = resp[14+ohlen:]
        
        if begin == 0:
            self.assert_(type(hisohlist) == ListType)
            for oh in hisohlist:
                self.assert_(type(oh) == ListType)
                self.assert_(len(oh) == 2)
                self.assert_(type(oh[0]) == IntType)
                self.assert_(type(oh[1]) == StringType)
            
            hisohlist.sort()
            print >>sys.stderr,"test: good_request: check_hashpiece",`hisohlist`
            myohlist = self.tree.get_hashes_for_piece(index)
            myohlist.sort()
            
            self.assert_(len(hisohlist) == len(myohlist))
            for i in range(0,len(hisohlist)):
                hisoh = hisohlist[i]
                myoh = myohlist[i]
                self.assert_(hisoh == myoh)
        else:
            self.assert_(len(hisohlist) == 0)
        
        mylength = self.get_chunk_length(index,begin)
        mychunk = self.read_chunk(index,begin,mylength)
        
        self.assert_(hischunk == mychunk)

        return index == self.numpieces-1 and mylength != 2 ** 14
 def check_request(self, data, pieces):
     piece = toint(data[0:4])
     self.assert_(piece in pieces)
 def check_request(self,data):
     piece = toint(data[0:4])
     self.assert_(piece == 1)        
Exemplo n.º 4
0
 def read_len(self, s):
     l = toint(s)
     # if l > self.Encoder.max_len:
     #     return None
     # if DEBUG: print >> sys.stderr, time.asctime(),'-', "waiting for", l, "bytes"
     return l, self.read_message
Exemplo n.º 5
0
 def check_request(self, data, pieces):
     piece = toint(data[0:4])
     self.assert_(piece in pieces)
Exemplo n.º 6
0
 def read_len(self, s):
     l = toint(s)
     if l > self.Encoder.max_len:
         return None
     return l, self.read_message
Exemplo n.º 7
0
 def read_len(self, s):
     l = toint(s)
     if l > self.handler.get_max_len():
         return None
     return l, self.read_message
Exemplo n.º 8
0
 def read_len(self, s):
     l = toint(s)
     if l > self.handler.get_max_len():
         return None
     return l, self.read_message
Exemplo n.º 9
0
 def read_len(self, s):
     l = toint(s)
     if l > self.Encoder.max_len:
         return None
     return l, self.read_message
Exemplo n.º 10
0
 def check_request(self,data):
     index = toint(data[1:5])
     begin = toint(data[5:9])
     length = toint(data[9:])
     return (index,begin,length)