def update_peer_addresses(self, peer_addresses): # FIXME: Probably will be refactored self.peer_addresses = peer_addresses known_peers = qrl_pb2.KnownPeers() known_peers.peers.extend([qrl_pb2.Peer(ip=p) for p in self.peer_addresses]) with open(self.peers_path, "wb") as outfile: outfile.write(known_peers.SerializeToString())
def GetKnownPeers(self, request: qrl_pb2.GetKnownPeersReq, context) -> qrl_pb2.GetKnownPeersResp: logger.debug("[QRLNode] GetPeers") known_peers = qrl_pb2.KnownPeers() known_peers.peers.extend( [qrl_pb2.Peer(ip=p) for p in self.node.peer_addresses]) return qrl_pb2.GetKnownPeersResp(known_peers=known_peers)
def GetKnownPeers(self, request: qrl_pb2.GetKnownPeersReq, context) \ -> qrl_pb2.GetKnownPeersResp: try: known_peers = qrl_pb2.KnownPeers() known_peers.peers.extend( [qrl_pb2.Peer(ip=p) for p in self.qrlnode.peer_addresses]) return qrl_pb2.GetKnownPeersResp(known_peers=known_peers) except Exception as e: context.set_code(StatusCode.unknown) context.set_details(str(e)) return None
def load_peer_addresses(self): try: if os.path.isfile(self.peers_path): logger.info('Opening peers.qrl') with open(self.peers_path, 'rb') as infile: known_peers = qrl_pb2.KnownPeers() known_peers.ParseFromString(infile.read()) self.peer_addresses = [peer.ip for peer in known_peers.peers] return except Exception as e: logger.warning("Error loading peers") logger.info('Creating peers.qrl') # Ensure the data path exists config.create_path(config.user.data_path) self.update_peer_addresses(config.user.peer_list) logger.info('Known Peers: %s', self.peer_addresses)