async def _receive_requests(self, channel, mode, ids): self.logger.info( f'receive_requests_start_{mode} {ids} | receiving requests from {channel.peer_id}' ) data = await channel.read() requests_received = pickle.loads(data) printable_requests = [[pretty_hash(H) for H in local_info] for local_info in requests_received] self.logger.info( f'receive_requests_done_{mode} {ids} | received requests {printable_requests} ({len(data)} bytes) ' f'from {channel.peer_id}') return requests_received
async def _send_requests(self, to_send, channel, mode, ids): self.logger.info( f'send_requests_start_{mode} {ids} | Sending requests to {channel.peer_id}' ) data = pickle.dumps(to_send) self.logger.info( f'send_requests_wait_{mode} {ids} | writing requests to {channel.peer_id}' ) await channel.write(data) printable_requests = [[pretty_hash(H) for H in local_info] for local_info in to_send] self.logger.info( f'send_requests_done_{mode} {ids} | sent requests {printable_requests} ({len(data)} bytes) ' f'to {channel.peer_id}')
async def _receive_poset_info(self, channel, mode, ids): data = await channel.read() if ids is None: ids = self._new_sync_id(channel.peer_id) self.logger.info( f'receive_poset_{mode} {ids} | Receiving info about heights from {channel.peer_id}' ) info = pickle.loads(data) printable_heights = [[(h, pretty_hash(H)) for (h, H) in local_info] for local_info in info] self.logger.info( f'receive_poset_{mode} {ids} | Got heights {printable_heights} ({len(data)} bytes) ' f'from {channel.peer_id}') return info, ids
async def _send_poset_info(self, channel, mode, ids): self.logger.info( f'send_poset_{mode} {ids} | sending info about heights to {channel.peer_id}' ) to_send = poset_info(self.process.poset) data = pickle.dumps(to_send) self.logger.info( f'send_poset_wait_{mode} {ids} | writing info about heights to {channel.peer_id}' ) await channel.write(data) printable_heights = [[(h, pretty_hash(H)) for (h, H) in local_info] for local_info in to_send] self.logger.info( f'send_poset_done_{mode} {ids} | sent heights {printable_heights} ({len(data)} bytes) ' f'to {channel.peer_id}')
def dehash_parents(poset, U): ''' Substitute units from the poset for hashes in U's parent list and set the height field. To be called on units received from the network. :param Poset poset: the poset where U is supposed to end up in :param Unit U: the unit with hashes instead of parents ''' if not all(p in poset.units for p in U.parents): strangers = [pretty_hash(parent_hash) for parent_hash in U.parents if parent_hash not in poset.units] logger = logging.getLogger(consts.LOGGER_NAME) logger.error(f'dehash_parents {poset.process_id} | Parents {strangers} not found in the poset for {U.short_name()}') assert False, 'Attempting to fix parents but parents not present in poset' U.parents = [poset.units[p] for p in U.parents] U.height = U.parents[0].height+1 if U.parents else 0