Dragonfly2

Форк
0
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

17
package storage
18

19
import (
20
	"io"
21

22
	commonv1 "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

28
type persistentMetadata struct {
29
	StoreStrategy string                  `json:"storeStrategy"`
30
	TaskID        string                  `json:"taskID"`
31
	TaskMeta      map[string]string       `json:"taskMeta"`
32
	ContentLength int64                   `json:"contentLength"`
33
	TotalPieces   int32                   `json:"totalPieces"`
34
	PeerID        string                  `json:"peerID"`
35
	Pieces        map[int32]PieceMetadata `json:"pieces"`
36
	PieceMd5Sign  string                  `json:"pieceMd5Sign"`
37
	DataFilePath  string                  `json:"dataFilePath"`
38
	Done          bool                    `json:"done"`
39
	Header        *source.Header          `json:"header"`
40
}
41

42
type PeerTaskMetadata struct {
43
	PeerID string `json:"peerID,omitempty"`
44
	TaskID string `json:"taskID,omitempty"`
45
}
46

47
type PieceMetadata struct {
48
	Num    int32               `json:"num,omitempty"`
49
	Md5    string              `json:"md5,omitempty"`
50
	Offset uint64              `json:"offset,omitempty"`
51
	Range  http.Range          `json:"range,omitempty"`
52
	Style  commonv1.PieceStyle `json:"style,omitempty"`
53
	// time(nanosecond) consumed
54
	Cost uint64 `json:"cost,omitempty"`
55
}
56

57
type CommonTaskRequest struct {
58
	PeerID      string `json:"peerID,omitempty"`
59
	TaskID      string `json:"taskID,omitempty"`
60
	Destination string
61
}
62

63
type RegisterTaskRequest struct {
64
	PeerTaskMetadata
65
	DesiredLocation string
66
	ContentLength   int64
67
	TotalPieces     int32
68
	PieceMd5Sign    string
69
}
70

71
type WritePieceRequest struct {
72
	PeerTaskMetadata
73
	PieceMetadata
74
	UnknownLength bool
75
	Reader        io.Reader
76
	// NeedGenMetadata is used after the last piece in back source case
77
	NeedGenMetadata func(n int64) (total int32, contentLength int64, gen bool)
78
}
79

80
type StoreRequest struct {
81
	CommonTaskRequest
82
	MetadataOnly bool
83
	// StoreDataOnly stands save file only without save metadata, used in reuse cases
84
	StoreDataOnly bool
85
	TotalPieces   int32
86
	// OriginalOffset stands keep original offset in the target file, if the target file is not original file, return error
87
	OriginalOffset bool
88
}
89

90
type ReadPieceRequest struct {
91
	PeerTaskMetadata
92
	PieceMetadata
93
}
94

95
type ReadAllPiecesRequest struct {
96
	PeerTaskMetadata
97
	Range *http.Range
98
}
99

100
type RegisterSubTaskRequest struct {
101
	Parent  PeerTaskMetadata
102
	SubTask PeerTaskMetadata
103
	Range   *http.Range
104
}
105

106
type UpdateTaskRequest struct {
107
	PeerTaskMetadata
108
	ContentLength int64
109
	TotalPieces   int32
110
	PieceMd5Sign  string
111
	Header        *source.Header
112
}
113

114
type ReusePeerTask struct {
115
	PeerTaskMetadata
116
	ContentLength int64
117
	TotalPieces   int32
118
	PieceMd5Sign  string
119
	Header        *source.Header
120
	Storage       TaskStorageDriver
121
}
122

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.