Dragonfly2
121 строка · 3.3 Кб
1/*
2* Copyright 2020 The Dragonfly Authors
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*/
16
17package storage
18
19import (
20"io"
21
22commonv1 "d7y.io/api/v2/pkg/apis/common/v1"
23
24"d7y.io/dragonfly/v2/pkg/net/http"
25"d7y.io/dragonfly/v2/pkg/source"
26)
27
28type persistentMetadata struct {
29StoreStrategy string `json:"storeStrategy"`
30TaskID string `json:"taskID"`
31TaskMeta map[string]string `json:"taskMeta"`
32ContentLength int64 `json:"contentLength"`
33TotalPieces int32 `json:"totalPieces"`
34PeerID string `json:"peerID"`
35Pieces map[int32]PieceMetadata `json:"pieces"`
36PieceMd5Sign string `json:"pieceMd5Sign"`
37DataFilePath string `json:"dataFilePath"`
38Done bool `json:"done"`
39Header *source.Header `json:"header"`
40}
41
42type PeerTaskMetadata struct {
43PeerID string `json:"peerID,omitempty"`
44TaskID string `json:"taskID,omitempty"`
45}
46
47type PieceMetadata struct {
48Num int32 `json:"num,omitempty"`
49Md5 string `json:"md5,omitempty"`
50Offset uint64 `json:"offset,omitempty"`
51Range http.Range `json:"range,omitempty"`
52Style commonv1.PieceStyle `json:"style,omitempty"`
53// time(nanosecond) consumed
54Cost uint64 `json:"cost,omitempty"`
55}
56
57type CommonTaskRequest struct {
58PeerID string `json:"peerID,omitempty"`
59TaskID string `json:"taskID,omitempty"`
60Destination string
61}
62
63type RegisterTaskRequest struct {
64PeerTaskMetadata
65DesiredLocation string
66ContentLength int64
67TotalPieces int32
68PieceMd5Sign string
69}
70
71type WritePieceRequest struct {
72PeerTaskMetadata
73PieceMetadata
74UnknownLength bool
75Reader io.Reader
76// NeedGenMetadata is used after the last piece in back source case
77NeedGenMetadata func(n int64) (total int32, contentLength int64, gen bool)
78}
79
80type StoreRequest struct {
81CommonTaskRequest
82MetadataOnly bool
83// StoreDataOnly stands save file only without save metadata, used in reuse cases
84StoreDataOnly bool
85TotalPieces int32
86// OriginalOffset stands keep original offset in the target file, if the target file is not original file, return error
87OriginalOffset bool
88}
89
90type ReadPieceRequest struct {
91PeerTaskMetadata
92PieceMetadata
93}
94
95type ReadAllPiecesRequest struct {
96PeerTaskMetadata
97Range *http.Range
98}
99
100type RegisterSubTaskRequest struct {
101Parent PeerTaskMetadata
102SubTask PeerTaskMetadata
103Range *http.Range
104}
105
106type UpdateTaskRequest struct {
107PeerTaskMetadata
108ContentLength int64
109TotalPieces int32
110PieceMd5Sign string
111Header *source.Header
112}
113
114type ReusePeerTask struct {
115PeerTaskMetadata
116ContentLength int64
117TotalPieces int32
118PieceMd5Sign string
119Header *source.Header
120Storage TaskStorageDriver
121}
122