Esempio n. 1
0
    def handle_sub_proto_msg(self, cmd: Command, msg: _DecodedMsgType) -> None:
        if isinstance(cmd, Announce):
            self.head_info = cmd.as_head_info(msg)
            self.head_td = self.head_info.total_difficulty
            self.head_hash = self.head_info.block_hash

        super().handle_sub_proto_msg(cmd, msg)
Esempio n. 2
0
 async def process_sub_proto_handshake(
         self, cmd: protocol.Command, msg: protocol._DecodedMsgType) -> None:
     if not isinstance(cmd, (les.Status, les.StatusV2)):
         self.disconnect(DisconnectReason.subprotocol_error)
         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.useless_peer)
         raise HandshakeFailure(
             "{} network ({}) does not match ours ({}), disconnecting".format(
                 self, msg['networkId'], self.network_id))
     genesis = await self.genesis
     if msg['genesisHash'] != genesis.hash:
         self.disconnect(DisconnectReason.useless_peer)
         raise HandshakeFailure(
             "{} genesis ({}) does not match ours ({}), disconnecting".format(
                 self, encode_hex(msg['genesisHash']), genesis.hex_hash))
     # TODO: Disconnect if the remote doesn't serve headers.
     self.head_info = cmd.as_head_info(msg)
Esempio n. 3
0
 async 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))
     genesis = await self.genesis
     if msg['genesisHash'] != genesis.hash:
         self.disconnect(DisconnectReason.other)
         raise HandshakeFailure(
             "{} genesis ({}) does not match ours ({}), disconnecting".format(
                 self, encode_hex(msg['genesisHash']), genesis.hex_hash))
     # TODO: Disconnect if the remote doesn't serve headers.
     self.head_info = cmd.as_head_info(msg)