Exemplo n.º 1
0
 def recv_node_request(self, data, peer):
     s = StringIO.StringIO(data.split(BTMessage.MSG_REQUEST_NODES)[1])
     sha256 = util.deser_uint256(s)
     level = ord(s.read(1))
     index = util.deser_varint(s)
     generations = ord(s.read(1))
     flags = util.deser_varint(s)
     debuglog('btnet', "peer %s wants h=%s l=%i i=%i g=%i f=%i" % (str(peer), util.ser_uint256(sha256)[::-1].encode('hex'), level, index, generations, flags))
     # fixme: maybe add choke/throttle checks here?
     self.send_nodes(peer, sha256, level, index, generations, flags)
Exemplo n.º 2
0
 def recv_node_request(self, data, peer):
     s = StringIO.StringIO(data.split(BTMessage.MSG_REQUEST_NODES)[1])
     sha256 = util.deser_uint256(s)
     level = ord(s.read(1))
     index = util.deser_varint(s)
     generations = ord(s.read(1))
     flags = util.deser_varint(s)
     debuglog(
         'btnet', "peer %s wants h=%s l=%i i=%i g=%i f=%i" %
         (str(peer), util.ser_uint256(sha256)[::-1].encode('hex'), level,
          index, generations, flags))
     # fixme: maybe add choke/throttle checks here?
     self.send_nodes(peer, sha256, level, index, generations, flags)
Exemplo n.º 3
0
    def recv_nodes(self, data, peer):
        s = StringIO.StringIO(data.split(BTMessage.MSG_RUN)[1])
        sha256 = util.deser_uint256(s)
        level = ord(s.read(1))
        index = util.deser_varint(s)
        generations = ord(s.read(1))
        length = util.deser_varint(s)
        flags = util.deser_varint(s)
        if flags: raise NotImplementedError
        run = [s.read(32) for i in range(length)]
        result = self.merkles[sha256].checkaddrun(level, index, generations, length, run)

        if not result:
            print "Failed to add from peer=%s: l=%i i=%i g=%i h=%s" % (str(peer), level, index, generations, util.ser_uint256(sha256)[::-1].encode('hex'))
            debuglog('btnet', "Failed to add from peer=%s: l=%i i=%i g=%i h=%s" % (str(peer), level, index, generations, util.ser_uint256(sha256)[::-1].encode('hex')))
        else:
            self.maybe_update_peers(sha256)
Exemplo n.º 4
0
 def recv_txcount_proof(self, data, peer):
     print "received txcount proof from %s" % `peer`
     s = StringIO.StringIO(data.split(BTMessage.MSG_TXCOUNT_PROOF)[1])
     sha256 = util.deser_uint256(s)
     txcount = util.deser_varint(s)
     levels, hashcount, path = 0, 1, txcount-1
     while path:
         hashcount += path & 1
         levels += 1
         path = path >> 1
     print "txcount proof received: %i, %i, %i " % (levels, hashcount, txcount)
     hashes = [s.read(32) for i in range(hashcount)]
     self.merkles[sha256].checktxcountproof(txcount, hashes)
Exemplo n.º 5
0
    def recv_nodes(self, data, peer):
        s = StringIO.StringIO(data.split(BTMessage.MSG_RUN)[1])
        sha256 = util.deser_uint256(s)
        level = ord(s.read(1))
        index = util.deser_varint(s)
        generations = ord(s.read(1))
        length = util.deser_varint(s)
        flags = util.deser_varint(s)
        if flags: raise NotImplementedError
        run = [s.read(32) for i in range(length)]
        result = self.merkles[sha256].checkaddrun(level, index, generations,
                                                  length, run)

        if not result:
            print "Failed to add from peer=%s: l=%i i=%i g=%i h=%s" % (
                str(peer), level, index, generations,
                util.ser_uint256(sha256)[::-1].encode('hex'))
            debuglog(
                'btnet', "Failed to add from peer=%s: l=%i i=%i g=%i h=%s" %
                (str(peer), level, index, generations,
                 util.ser_uint256(sha256)[::-1].encode('hex')))
        else:
            self.maybe_update_peers(sha256)
Exemplo n.º 6
0
 def recv_txcount_proof(self, data, peer):
     print "received txcount proof from %s" % ` peer `
     s = StringIO.StringIO(data.split(BTMessage.MSG_TXCOUNT_PROOF)[1])
     sha256 = util.deser_uint256(s)
     txcount = util.deser_varint(s)
     levels, hashcount, path = 0, 1, txcount - 1
     while path:
         hashcount += path & 1
         levels += 1
         path = path >> 1
     print "txcount proof received: %i, %i, %i " % (levels, hashcount,
                                                    txcount)
     hashes = [s.read(32) for i in range(hashcount)]
     self.merkles[sha256].checktxcountproof(txcount, hashes)
Exemplo n.º 7
0
 def recv_multiple(self, data, addr):
     s = StringIO.StringIO(data.split(BTMessage.MSG_MULTIPLE, 1)[1])
     count = util.deser_varint(s)
     for i in range(count):
         msg_length = util.deser_varint(s)
         self.process_message(s.read(msg_length), addr)
Exemplo n.º 8
0
 def recv_multiple(self, data, addr):
     s = StringIO.StringIO(data.split(BTMessage.MSG_MULTIPLE, 1)[1])
     count = util.deser_varint(s)
     for i in range(count):
         msg_length = util.deser_varint(s)
         self.process_message(s.read(msg_length), addr)