def start_transfer_op(self, op): logging.debug("Remote RPC: calling StartTransfer on '%s'" % (self.display_hostname)) start_time = GLib.get_monotonic_time() op.progress_tracker = transfers.OpProgressTracker(op) op.current_progress_report = None receiver = transfers.FileReceiver(op) op.set_status(OpStatus.TRANSFERRING) op.file_iterator = self.stub.StartTransfer( warp_pb2.OpInfo(timestamp=op.start_time, ident=self.local_ident, readable_name=util.get_hostname(), use_compression=op.use_compression and prefs.use_compression())) def report_receive_error(error): op.set_error(error) try: # If we leave an io stream open, it locks the location. For instance, # if this was a mounted location, we wouldn't be able to terminate until # we closed warp. if receiver.current_stream != None: receiver.current_stream.close() except GLib.Error: pass logging.critical("An error occurred receiving data from %s: %s" % (op.sender, op.error_msg)) op.set_status(OpStatus.FAILED) op.stop_transfer() try: for data in op.file_iterator: receiver.receive_data(data) except grpc.RpcError: if op.file_iterator.code() == grpc.StatusCode.CANCELLED: op.file_iterator = None return else: report_receive_error(op.file_iterator) return except Exception as e: report_receive_error(e) return op.file_iterator = None receiver.receive_finished() logging.debug("Remote: receipt of %s files (%s) finished in %s" % \ (op.total_count, GLib.format_size(op.total_size),\ util.precise_format_time_span(GLib.get_monotonic_time() - start_time))) op.set_status(OpStatus.FINISHED)
def __init__(self, peers, service_name, app_nick, app_ip, save_location): super(WarpServer, self).__init__() self.app_ip = app_ip self.service_name = service_name self.port = prefs.get_port() self.peer_list = peers self.file_receiver = transfers.FileReceiver(save_location) self.set_prefs(app_nick, save_location) self.permission_requests = [] self.serve_forever()