def _on_data(self):
    'Try to read P2P messages from the recv buffer.\n\n        This method reads data from the buffer in a loop. It deserializes,\n        parses and verifies the P2P header, then passes the P2P payload to\n        the on_message callback for processing.'
    try:
        while True:
            if (len(self.recvbuf) < 4):
                return
            if (self.recvbuf[:4] != MAGIC_BYTES[self.network]):
                raise ValueError(('got garbage %s' % repr(self.recvbuf)))
            if (len(self.recvbuf) < (((4 + 12) + 4) + 4)):
                return
            command = self.recvbuf[4:(4 + 12)].split(b'\x00', 1)[0]
            msglen = struct.unpack('<i', self.recvbuf[(4 + 12):((4 + 12) + 4)])[0]
            checksum = self.recvbuf[((4 + 12) + 4):(((4 + 12) + 4) + 4)]
            if (len(self.recvbuf) < ((((4 + 12) + 4) + 4) + msglen)):
                return
            msg = self.recvbuf[(((4 + 12) + 4) + 4):((((4 + 12) + 4) + 4) + msglen)]
            th = sha256(msg)
            h = sha256(th)
            if (checksum != h[:4]):
                raise ValueError(('got bad checksum ' + repr(self.recvbuf)))
            self.recvbuf = self.recvbuf[((((4 + 12) + 4) + 4) + msglen):]
            if (command not in MESSAGEMAP):
                raise ValueError(("Received unknown command from %s:%d: '%s' %s" % (self.dstaddr, self.dstport, command, repr(msg))))
            f = BytesIO(msg)
            t = MESSAGEMAP[command]()
            t.deserialize(f)
            self._log_message('receive', t)
            self.on_message(t)
    except Exception as e:
        logger.exception('Error reading message:', repr(e))
        raise
Try to read P2P messages from the recv buffer.

This method reads data from the buffer in a loop. It deserializes,
parses and verifies the P2P header, then passes the P2P payload to
the on_message callback for processing.
def _on_data(self):
    'Try to read P2P messages from the recv buffer.\n\n        This method reads data from the buffer in a loop. It deserializes,\n        parses and verifies the P2P header, then passes the P2P payload to\n        the on_message callback for processing.'
    try:
        while True:
            if (len(self.recvbuf) < 4):
                return
            if (self.recvbuf[:4] != MAGIC_BYTES[self.network]):
                raise ValueError(('got garbage %s' % repr(self.recvbuf)))
            if (len(self.recvbuf) < (((4 + 12) + 4) + 4)):
                return
            command = self.recvbuf[4:(4 + 12)].split(b'\x00', 1)[0]
            msglen = struct.unpack('<i', self.recvbuf[(4 + 12):((4 + 12) + 4)])[0]
            checksum = self.recvbuf[((4 + 12) + 4):(((4 + 12) + 4) + 4)]
            if (len(self.recvbuf) < ((((4 + 12) + 4) + 4) + msglen)):
                return
            msg = self.recvbuf[(((4 + 12) + 4) + 4):((((4 + 12) + 4) + 4) + msglen)]
            th = sha256(msg)
            h = sha256(th)
            if (checksum != h[:4]):
                raise ValueError(('got bad checksum ' + repr(self.recvbuf)))
            self.recvbuf = self.recvbuf[((((4 + 12) + 4) + 4) + msglen):]
            if (command not in MESSAGEMAP):
                raise ValueError(("Received unknown command from %s:%d: '%s' %s" % (self.dstaddr, self.dstport, command, repr(msg))))
            f = BytesIO(msg)
            t = MESSAGEMAP[command]()
            t.deserialize(f)
            self._log_message('receive', t)
            self.on_message(t)
    except Exception as e:
        logger.exception('Error reading message:', repr(e))
        raise