def client_request(message, packet): global serve_path filename = message.decode("utf-8") if filename in list_files(): try: # If we have the requested file, we'll # read it and pack it as a resource RNS.log("Client requested \"" + filename + "\"") file = open(os.path.join(serve_path, filename), "rb") file_resource = RNS.Resource(file, packet.link, callback=resource_sending_concluded) file_resource.filename = filename except Exception as e: # If somethign went wrong, we close # the link RNS.log("Error while reading file \"" + filename + "\"", RNS.LOG_ERROR) packet.link.teardown() raise e else: # If we don't have it, we close the link RNS.log("Client requested an unknown file") packet.link.teardown()
def __as_resource(self): if not self.packed: self.pack() if not self.__delivery_destination: raise ValueError( "Can't synthesize resource for LXMF message before delivery destination is known" ) if not self.__delivery_destination.type == RNS.Destination.LINK: raise TypeError( "Tried to synthesize resource for LXMF message on a delivery destination that was not a link" ) if not self.__delivery_destination.status == RNS.Link.ACTIVE: raise ConnectionError( "Tried to synthesize resource for LXMF message on a link that was not active" ) self.progress = 0.0 return RNS.Resource(self.packed, self.__delivery_destination, callback=self.__resource_concluded, progress_callback=self.__update_transfer_progress)