dragonfly-api 2.0.133

Canonical location of the Dragonfly API definition
/*
 *     Copyright 2022 The Dragonfly Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

syntax = "proto3";

package dfdaemon.v2;

import "common.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/empty.proto";

// DownloadTaskRequest represents request of DownloadTask.
message DownloadTaskRequest {
  // Download information.
  common.v2.Download download = 1;
}

// DownloadTaskStartedResponse represents task download started response of DownloadTaskResponse.
message DownloadTaskStartedResponse {
  // Task content length.
  uint64 content_length = 1;

  // Range is url range of request. If protocol is http, range
  // is parsed from http header. If other protocol, range comes
  // from download range field.
  optional common.v2.Range range = 2;

  // Task response headers.
  map<string, string> response_header = 3;

  // Need to download pieces.
  repeated common.v2.Piece pieces = 4;
}

// DownloadPieceFinishedResponse represents piece download finished response of DownloadTaskResponse.
message DownloadPieceFinishedResponse {
  // Finished piece of task.
  common.v2.Piece piece = 1;
}

// DownloadTaskResponse represents response of DownloadTask.
message DownloadTaskResponse {
  // Host id.
  string host_id = 1;
  // Task id.
  string task_id = 2;
  // Peer id.
  string peer_id = 3;

  oneof response {
    DownloadTaskStartedResponse download_task_started_response = 4;
    DownloadPieceFinishedResponse download_piece_finished_response = 5;
  }
}

// SyncPiecesRequest represents request of SyncPieces.
message SyncPiecesRequest {
  // Host id.
  string host_id = 1;
  // Task id.
  string task_id = 2;
  // Interested piece numbers.
  repeated uint32 interested_piece_numbers = 3;
}

// SyncPiecesResponse represents response of SyncPieces.
message SyncPiecesResponse {
  // Exist piece number.
  uint32 number = 1;
  // Piece offset.
  uint64 offset = 2;
  // Piece length.
  uint64 length = 3;
}

// DownloadPieceRequest represents request of DownloadPiece.
message DownloadPieceRequest{
  // Host id.
  string host_id = 1;
  // Task id.
  string task_id = 2;
  // Piece number.
  uint32 piece_number = 3;
}

// DownloadPieceResponse represents response of DownloadPieces.
message DownloadPieceResponse {
  // Piece information.
  common.v2.Piece piece = 1;
}

// StatTaskRequest represents request of StatTask.
message StatTaskRequest {
  // Task id.
  string task_id = 1;
}

// DeleteTaskRequest represents request of DeleteTask.
message DeleteTaskRequest {
  // Task id.
  string task_id = 1;
}

// DownloadCacheTaskRequest represents request of DownloadCacheTask.
message DownloadCacheTaskRequest {
  // Host id.
  string host_id = 1;
  // Task id.
  string task_id = 2;
  // Persistent represents whether the cache task is persistent.
  // If the cache task is persistent, the cache peer will
  // not be deleted when dfdaemon runs garbage collection.
  bool persistent = 3;
  // Tag is used to distinguish different cache tasks.
  optional string tag = 4;
  // Application of task.
  optional string application = 5;
  // Task piece length.
  uint64 piece_length = 6;
  // File path to be exported.
  string output_path = 7;
  // Download timeout.
  optional google.protobuf.Duration timeout = 8;
}

// DownloadCacheTaskStartedResponse represents task download started response of DownloadCacheTaskResponse.
message DownloadCacheTaskStartedResponse {}

// DownloadCacheTaskResponse represents response of DownloadCacheTask.
message DownloadCacheTaskResponse {
  // Host id.
  string host_id = 1;
  // Task id.
  string task_id = 2;
  // Peer id.
  string peer_id = 3;

  oneof response {
    DownloadCacheTaskStartedResponse download_cache_task_started_response = 4;
    DownloadPieceFinishedResponse download_piece_finished_response = 5;
  }
}

// UploadCacheTaskRequest represents request of UploadCacheTask.
message UploadCacheTaskRequest {
  // Upload file path of cache task.
  string path = 1;
  // Replica count of the persistent cache task.
  uint64 persistent_replica_count = 2;
  // Tag is used to distinguish different cache tasks.
  optional string tag = 3;
  // Application of task.
  optional string application = 4;
  // Task piece length.
  uint64 piece_length = 5;
  // TTL of the cache task.
  google.protobuf.Duration ttl = 6;
  // Upload timeout.
  optional google.protobuf.Duration timeout = 7;
}

// StatCacheTaskRequest represents request of StatCacheTask.
message StatCacheTaskRequest {
  // Task id.
  string task_id = 1;
}

// DeleteCacheTaskRequest represents request of DeleteCacheTask.
message DeleteCacheTaskRequest {
  // Task id.
  string task_id = 1;
}

// DfdaemonUpload represents upload service of dfdaemon.
service DfdaemonUpload{
  // DownloadTask downloads task from p2p network.
  rpc DownloadTask(DownloadTaskRequest) returns(stream DownloadTaskResponse);

  // SyncPieces syncs piece metadatas from remote peer.
  rpc SyncPieces(SyncPiecesRequest) returns(stream SyncPiecesResponse);

  // DownloadPiece downloads piece from the remote peer.
  rpc DownloadPiece(DownloadPieceRequest)returns(DownloadPieceResponse);

  // DownloadCacheTask downloads cache task from p2p network.
  rpc DownloadCacheTask(DownloadCacheTaskRequest) returns(stream DownloadCacheTaskResponse);

  // StatCacheTask stats cache task information.
  rpc StatCacheTask(StatCacheTaskRequest) returns(common.v2.CacheTask);

  // DeleteCacheTask deletes cache task from p2p network.
  rpc DeleteCacheTask(DeleteCacheTaskRequest) returns(google.protobuf.Empty);
}

// DfdaemonDownload represents download service of dfdaemon.
service DfdaemonDownload{
  // DownloadTask downloads task from p2p network.
  rpc DownloadTask(DownloadTaskRequest) returns(stream DownloadTaskResponse);

  // StatTask stats task information.
  rpc StatTask(StatTaskRequest) returns(common.v2.Task);

  // DeleteTask deletes task from p2p network.
  rpc DeleteTask(DeleteTaskRequest) returns(google.protobuf.Empty);

  // DeleteHost releases host in scheduler.
  rpc DeleteHost(google.protobuf.Empty)returns(google.protobuf.Empty);

  // DownloadCacheTask downloads cache task from p2p network.
  rpc DownloadCacheTask(DownloadCacheTaskRequest) returns(stream DownloadCacheTaskResponse);

  // UploadCacheTask uploads cache task to p2p network.
  rpc UploadCacheTask(UploadCacheTaskRequest) returns(common.v2.CacheTask);

  // StatCacheTask stats cache task information.
  rpc StatCacheTask(StatCacheTaskRequest) returns(common.v2.CacheTask);

  // DeleteCacheTask deletes cache task from p2p network.
  rpc DeleteCacheTask(DeleteCacheTaskRequest) returns(google.protobuf.Empty);
}