mirror of https://github.com/dragonflyoss/api.git
186 lines
5.7 KiB
Protocol Buffer
186 lines
5.7 KiB
Protocol Buffer
/*
|
|
* 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 common;
|
|
|
|
import "validate/validate.proto";
|
|
|
|
option go_package = "d7y.io/api/pkg/apis/common/v1";
|
|
|
|
enum Code{
|
|
X_UNSPECIFIED = 0;
|
|
// success code 200-299
|
|
Success = 200;
|
|
// framework can not find server node
|
|
ServerUnavailable = 500;
|
|
|
|
// common response error 1000-1999
|
|
// client can be migrated to another scheduler/CDN
|
|
ResourceLacked = 1000;
|
|
BackToSourceAborted = 1001;
|
|
BadRequest = 1400;
|
|
PeerTaskNotFound = 1404;
|
|
UnknownError = 1500;
|
|
RequestTimeOut = 1504;
|
|
|
|
// client response error 4000-4999
|
|
ClientError = 4000;
|
|
ClientPieceRequestFail = 4001; // get piece task from other peer error
|
|
ClientScheduleTimeout = 4002; // wait scheduler response timeout
|
|
ClientContextCanceled = 4003;
|
|
ClientWaitPieceReady = 4004; // when target peer downloads from source slowly, should wait
|
|
ClientPieceDownloadFail = 4005;
|
|
ClientRequestLimitFail = 4006;
|
|
ClientConnectionError = 4007;
|
|
ClientBackSourceError = 4008;
|
|
ClientPieceNotFound = 4404;
|
|
|
|
// scheduler response error 5000-5999
|
|
SchedError = 5000;
|
|
SchedNeedBackSource = 5001; // client should try to download from source
|
|
SchedPeerGone = 5002; // client should disconnect from scheduler
|
|
SchedPeerNotFound = 5004; // peer not found in scheduler
|
|
SchedPeerPieceResultReportFail = 5005; // report piece
|
|
SchedTaskStatusError = 5006; // task status is fail
|
|
|
|
// cdnsystem response error 6000-6999
|
|
CDNTaskRegistryFail = 6001;
|
|
CDNTaskNotFound = 6404;
|
|
|
|
// manager response error 7000-7999
|
|
InvalidResourceType = 7001;
|
|
}
|
|
|
|
enum PieceStyle{
|
|
PLAIN = 0;
|
|
}
|
|
|
|
enum SizeScope{
|
|
// size > one piece size
|
|
NORMAL = 0;
|
|
// 128 byte < size <= one piece size and be plain type
|
|
SMALL = 1;
|
|
// size <= 128 byte and be plain type
|
|
TINY = 2;
|
|
}
|
|
|
|
// Pattern represents pattern of task.
|
|
enum Pattern{
|
|
// Default pattern, scheduler will use all p2p node
|
|
// include dfdaemon and seed peers.
|
|
P2P = 0;
|
|
|
|
// Seed peer pattern, scheduler will use only seed peers.
|
|
SEED_PEER = 1;
|
|
|
|
// Source pattern, scheduler will say back source
|
|
// when there is no available peer in p2p.
|
|
SOURCE = 2;
|
|
}
|
|
|
|
// TaskType represents type of task.
|
|
enum TaskType{
|
|
// Normal is normal type of task,
|
|
// normal task is a normal p2p task.
|
|
Normal = 0;
|
|
|
|
// DfCache is dfcache type of task,
|
|
// dfcache task is a cache task, and the task url is fake url.
|
|
// It can only be used for caching and cannot be downloaded back to source.
|
|
DfCache = 1;
|
|
|
|
// DfStore is dfstore type of task,
|
|
// dfstore task is a persistent task in backend.
|
|
DfStore = 2;
|
|
}
|
|
|
|
message GrpcDfError {
|
|
Code code = 1;
|
|
string message = 2;
|
|
}
|
|
|
|
// UrlMeta describes url meta info.
|
|
message UrlMeta{
|
|
// digest checks integrity of url content, for example md5:xxx or sha256:yyy
|
|
string digest = 1 [(validate.rules).string = {pattern: "^(md5)|(sha256):[A-Fa-f0-9]+$", ignore_empty:true}];
|
|
// url tag identifies different task for same url, conflict with digest
|
|
string tag = 2;
|
|
// content range for url
|
|
string range = 3 [(validate.rules).string = {pattern: "^[0-9]+-[0-9]*$", ignore_empty:true}];
|
|
// filter url used to generate task id
|
|
string filter = 4;
|
|
// other url header infos
|
|
map<string, string> header = 5;
|
|
}
|
|
|
|
message HostLoad{
|
|
// cpu usage
|
|
float cpu_ratio = 1 [(validate.rules).float = {gte: 0, lte: 1}];
|
|
// memory usage
|
|
float mem_ratio = 2 [(validate.rules).float = {gte: 0, lte: 1}];
|
|
// disk space usage
|
|
float disk_ratio = 3 [(validate.rules).float = {gte: 0, lte: 1}];
|
|
}
|
|
|
|
message PieceTaskRequest{
|
|
string task_id = 1 [(validate.rules).string.min_len = 1];
|
|
string src_pid = 2 [(validate.rules).string.min_len = 1];
|
|
string dst_pid = 3 [(validate.rules).string.min_len = 1];
|
|
// piece number
|
|
uint32 start_num = 4 [(validate.rules).uint32.gte = 0];
|
|
// expected piece count, limit = 0 represent request pieces as many shards as possible
|
|
uint32 limit = 5 [(validate.rules).uint32.gte = 0];
|
|
}
|
|
|
|
message PieceInfo{
|
|
// piece_num < 0 represent start report piece flag
|
|
int32 piece_num = 1;
|
|
uint64 range_start = 2 [(validate.rules).uint64.gte = 0];
|
|
uint32 range_size = 3 [(validate.rules).uint32.gte = 0];
|
|
string piece_md5 = 4 [(validate.rules).string = {pattern:"([a-f\\d]{32}|[A-F\\d]{32}|[a-f\\d]{16}|[A-F\\d]{16})", ignore_empty:true}];
|
|
uint64 piece_offset = 5 [(validate.rules).uint64.gte = 0];
|
|
base.PieceStyle piece_style = 6;
|
|
// total time(millisecond) consumed
|
|
uint64 download_cost = 7 [(validate.rules).uint64.gte = 0];
|
|
}
|
|
|
|
message ExtendAttribute{
|
|
// task response header, eg: HTTP Response Header
|
|
map<string, string> header = 1;
|
|
// task response code, eg: HTTP Status Code
|
|
int32 status_code = 2;
|
|
// task response status, eg: HTTP Status
|
|
string status = 3;
|
|
}
|
|
|
|
message PiecePacket{
|
|
string task_id = 2 [(validate.rules).string.min_len = 1];
|
|
string dst_pid = 3 [(validate.rules).string.min_len = 1];
|
|
// ip:port
|
|
string dst_addr = 4 [(validate.rules).string.min_len = 1];
|
|
repeated PieceInfo piece_infos = 5;
|
|
// total piece count for url, total_piece represent total piece is unknown
|
|
int32 total_piece = 6;
|
|
// content_length < 0 represent content length is unknown
|
|
int64 content_length = 7;
|
|
// sha256 code of all piece md5
|
|
string piece_md5_sign = 8;
|
|
// task extend attribute
|
|
ExtendAttribute extend_attribute = 9;
|
|
}
|