Example #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_(isinstance(hisohlist, ListType))
            for oh in hisohlist:
                self.assert_(isinstance(oh, ListType))
                self.assert_(len(oh) == 2)
                self.assert_(isinstance(oh[0], IntType))
                self.assert_(isinstance(oh[1], StringType))

            hisohlist.sort()
            print >> sys.stderr, "test: good_request: check_hashpiece", repr(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
Example #2
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_(isinstance(hisohlist, ListType))
            for oh in hisohlist:
                self.assert_(isinstance(oh, ListType))
                self.assert_(len(oh) == 2)
                self.assert_(isinstance(oh[0], IntType))
                self.assert_(isinstance(oh[1], StringType))

            hisohlist.sort()
            print >> sys.stderr, "test: good_request: check_hashpiece", repr(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
Example #3
0
 def check_request(self, data):
     index = toint(data[1:5])
     begin = toint(data[5:9])
     length = toint(data[9:])
     return (index, begin, length)
Example #4
0
 def check_request(self, data):
     index = toint(data[1:5])
     begin = toint(data[5:9])
     length = toint(data[9:])
     return (index, begin, length)
Example #5
0
 def read_len(self, s):
     l = toint(s)
     # if l > self.Encoder.max_len:
     #     return None
     # if DEBUG: print >> sys.stderr, "waiting for", l, "bytes"
     return l, self.read_message
Example #6
0
 def read_len(self, s):
     l = toint(s)
     if l > self.handler.get_max_len():
         return None
     return l, self.read_message
Example #7
0
 def read_len(self, s):
     l = toint(s)
     if l > self.handler.get_max_len():
         return None
     return l, self.read_message
 def read_len(self, s):
     l = toint(s)
     # if l > self.Encoder.max_len:
     #     return None
     # if DEBUG: print >> sys.stderr, "waiting for", l, "bytes"
     return l, self.read_message