def __init__(self,
remote: Node,
privkey: datatypes.PrivateKey,
reader: asyncio.StreamReader,
writer: asyncio.StreamWriter,
aes_secret: bytes,
mac_secret: bytes,
egress_mac: sha3.keccak_256,
ingress_mac: sha3.keccak_256,
chaindb: BaseChainDB,
network_id: int,
received_msg_callback: Optional[_ReceivedMsgCallbackType] = None
) -> None:
self._finished = asyncio.Event()
self._pending_replies = {} # type: Dict[int, Callable[[protocol._DecodedMsgType], None]]
self.remote = remote
self.privkey = privkey
self.reader = reader
self.writer = writer
self.base_protocol = P2PProtocol(self)
self.chaindb = chaindb
self.network_id = network_id
self.received_msg_callback = received_msg_callback
# The sub protocols that have been enabled for this peer; will be populated when
# we receive the initial hello msg.
self.enabled_sub_protocols = [] # type: List[protocol.Protocol]
self.egress_mac = egress_mac
self.ingress_mac = ingress_mac
# FIXME: Yes, the encryption is insecure, see: https://github.com/ethereum/devp2p/issues/32
iv = b"\x00" * 16
aes_cipher = Cipher(algorithms.AES(aes_secret), modes.CTR(iv), default_backend())
self.aes_enc = aes_cipher.encryptor()
self.aes_dec = aes_cipher.decryptor()
mac_cipher = Cipher(algorithms.AES(mac_secret), modes.ECB(), default_backend())
self.mac_enc = mac_cipher.encryptor().update
评论列表
文章目录