Skip to content

Commit 7fef30e

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 be4e3ec commit 7fef30e

25 files changed

+8554
-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
@@ -101,6 +101,9 @@ type V2 interface {
101101
// DeletePersistentCacheTask deletes persistent cache task from p2p network.
102102
DeletePersistentCacheTask(context.Context, *dfdaemonv2.DeletePersistentCacheTaskRequest, ...grpc.CallOption) error
103103

104+
// DownloadCacheTask downloads cache task from p2p network.
105+
DownloadCacheTask(context.Context, string, *dfdaemonv2.DownloadCacheTaskRequest, ...grpc.CallOption) (dfdaemonv2.DfdaemonUpload_DownloadCacheTaskClient, error)
106+
104107
// Close tears down the ClientConn and all underlying connections.
105108
Close() error
106109
}
@@ -192,3 +195,12 @@ func (v *v2) DeletePersistentCacheTask(ctx context.Context, req *dfdaemonv2.Dele
192195
_, err := v.DfdaemonUploadClient.DeletePersistentCacheTask(ctx, req, opts...)
193196
return err
194197
}
198+
199+
// DownloadCacheTask downloads cache task from p2p network.
200+
func (v *v2) DownloadCacheTask(ctx context.Context, taskID string, req *dfdaemonv2.DownloadCacheTaskRequest, opts ...grpc.CallOption) (dfdaemonv2.DfdaemonUpload_DownloadCacheTaskClient, error) {
201+
return v.DfdaemonUploadClient.DownloadCacheTask(
202+
context.WithValue(ctx, pkgbalancer.ContextKey, taskID),
203+
req,
204+
opts...,
205+
)
206+
}

0 commit comments

Comments
 (0)