def test_serialization(self): inv = CInv(type=1) stream = _BytesIO() inv.stream_serialize(stream) serialized = _BytesIO(stream.getvalue()) deserialized = CInv.stream_deserialize(serialized) assert deserialized.typemap[deserialized.type] == "Squeak" assert deserialized == inv
def _send_reply_invs(self, locator): for interest in locator.vInterested: squeak_hashes = self._get_local_squeaks(interest) secret_key_hashes = self._get_local_secret_keys(interest) squeak_invs = [ CInv(type=MSG_SQUEAK, hash=squeak_hash) for squeak_hash in squeak_hashes] secret_key_invs = [ CInv(type=MSG_SECRET_KEY, hash=squeak_hash) for squeak_hash in secret_key_hashes] invs = squeak_invs + secret_key_invs if invs: inv_msg = msg_inv(inv=invs) self.peer.send_msg(inv_msg)
def test_download_hash_initiate(download_hash, squeak_hash): broadcast_fn = mock.Mock() download_hash.initiate_download(broadcast_fn) expected_msg = msg_getdata(inv=[CInv(type=1, hash=squeak_hash)]) broadcast_fn.assert_called_once_with(expected_msg)
def get_download_msg(self) -> MsgSerializable: invs = [ CInv(type=1, hash=self.squeak_hash) ] return msg_getdata( inv=invs, )
def forward_secret_key(self, squeak): logger.debug("Forward new secret key for hash: {!r}".format( get_hash(squeak).hex(), )) for peer in self.network_manager.get_connected_peers(): if peer.is_remote_subscribed(squeak): logger.debug("Forwarding to peer: {}".format(peer, )) squeak_hash = get_hash(squeak) inv = CInv(type=MSG_SECRET_KEY, hash=squeak_hash) inv_msg = msg_inv(inv=[inv]) peer.send_msg(inv_msg) logger.debug("Finished checking peers to forward.")
def request_offers(self, squeak_hash: bytes): logger.info("Requesting offers for squeak: {}".format( squeak_hash.hex(), )) invs = [CInv(type=2, hash=squeak_hash)] getdata_msg = msg_getdata(inv=invs) self.broadcast_msg(getdata_msg)