Ejemplo n.º 1
0
 def msg_handler(self, peer: BasePeer, cmd: protocol.Command,
                 announcement: protocol._DecodedMsgType) -> None:
     """The callback passed to BasePeer, called for every incoming message."""
     peer = cast(LESPeer, peer)
     if isinstance(cmd, (les.Announce, les.Status)):
         head_info = cmd.as_head_info(announcement)
         self._latest_head_info[peer] = head_info
         self._announcement_queue.put_nowait((peer, head_info))
Ejemplo n.º 2
0
 def process_sub_proto_handshake(
         self, cmd: protocol.Command, msg: protocol._DecodedMsgType) -> None:
     if not isinstance(cmd, (les.Status, les.StatusV2)):
         self.disconnect(DisconnectReason.other)
         raise HandshakeFailure(
             "Expected a LES Status msg, got {}, disconnecting".format(cmd))
     msg = cast(Dict[str, Any], msg)
     if msg['networkId'] != self.network_id:
         self.disconnect(DisconnectReason.other)
         raise HandshakeFailure(
             "{} network ({}) does not match ours ({}), disconnecting".format(
                 self, msg['networkId'], self.network_id))
     if msg['genesisHash'] != self.genesis.hash:
         self.disconnect(DisconnectReason.other)
         raise HandshakeFailure(
             "{} genesis ({}) does not match ours ({}), disconnecting".format(
                 self, encode_hex(msg['genesisHash']), self.genesis.hex_hash))
     # TODO: Disconnect if the remote doesn't serve headers.
     self.head_info = cmd.as_head_info(msg)