Skip to content

Commit 0345f9f

Browse files
committed
feat:Add a new resource to support CacheTask
- Added a new resource: standardcache, which is used to support CacheTask. - Added RPC calls for DownloadCacheTask. - Added a function to create CacheTask ID based on URL. Signed-off-by: fu220 <2863318196@qq.com>
1 parent 02b719a commit 0345f9f

25 files changed

+8944
-0
lines changed

pkg/idgen/task_id.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,19 @@ func TaskIDV2ByContent(content string) string {
191191
func PersistentCacheTaskIDByContent(content string) string {
192192
return pkgdigest.SHA256FromStrings(content)
193193
}
194+
195+
// CacheTaskIDV2ByURLBased generates v2 version of cache task id by url based.
196+
func CacheTaskIDV2ByURLBased(url string, pieceLength *uint64, tag, application string, filteredQueryParams []string) string {
197+
url, err := neturl.FilterQueryParams(url, filteredQueryParams)
198+
if err != nil {
199+
url = ""
200+
}
201+
202+
params := []string{url, tag, application}
203+
if pieceLength != nil {
204+
params = append(params, strconv.FormatUint(*pieceLength, 10))
205+
}
206+
207+
params = append(params, commonv2.TaskType_CACHE.String())
208+
return pkgdigest.SHA256FromStrings(params...)
209+
}

pkg/rpc/dfdaemon/client/client_v2.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ type V2 interface {
104104
// DeletePersistentCacheTask deletes persistent cache task from p2p network.
105105
DeletePersistentCacheTask(context.Context, *dfdaemonv2.DeletePersistentCacheTaskRequest, ...grpc.CallOption) error
106106

107+
// DownloadCacheTask downloads cache task from p2p network.
108+
DownloadCacheTask(context.Context, string, *dfdaemonv2.DownloadCacheTaskRequest, ...grpc.CallOption) (dfdaemonv2.DfdaemonUpload_DownloadCacheTaskClient, error)
109+
107110
// Close tears down the ClientConn and all underlying connections.
108111
Close() error
109112
}
@@ -196,6 +199,15 @@ func (v *v2) DeletePersistentCacheTask(ctx context.Context, req *dfdaemonv2.Dele
196199
return err
197200
}
198201

202+
// DownloadCacheTask downloads cache task from p2p network.
203+
func (v *v2) DownloadCacheTask(ctx context.Context, taskID string, req *dfdaemonv2.DownloadCacheTaskRequest, opts ...grpc.CallOption) (dfdaemonv2.DfdaemonUpload_DownloadCacheTaskClient, error) {
204+
return v.DfdaemonUploadClient.DownloadCacheTask(
205+
context.WithValue(ctx, pkgbalancer.ContextKey, taskID),
206+
req,
207+
opts...,
208+
)
209+
}
210+
199211
// ListTaskEntries lists task entries from p2p network.
200212
func (v *v2) ListTaskEntries(ctx context.Context, req *dfdaemonv2.ListTaskEntriesRequest, opts ...grpc.CallOption) (*dfdaemonv2.ListTaskEntriesResponse, error) {
201213
ctx, cancel := context.WithTimeout(ctx, contextTimeout)

0 commit comments

Comments
 (0)