Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
800 changes: 514 additions & 286 deletions code/go/0chain.net/blobbercore/blobbergrpc/blobber.pb.go

Large diffs are not rendered by default.

115 changes: 115 additions & 0 deletions code/go/0chain.net/blobbercore/blobbergrpc/blobber.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions code/go/0chain.net/blobbercore/blobbergrpc/blobber_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions code/go/0chain.net/blobbercore/blobbergrpc/proto/blobber.proto
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ service Blobber {
};
}

rpc CopyObject(CopyObjectRequest) returns (CopyObjectResponse) {
option (google.api.http) = {
post: "/v2/file/copy/{allocation}"
body: "*"
};
}

rpc Collaborator(CollaboratorRequest) returns (CollaboratorResponse) {
option (google.api.http) = {
post: "/v2/file/collaborator/{allocation}"
Expand Down Expand Up @@ -261,6 +268,24 @@ message UpdateObjectAttributesResponse {
int64 who_pays_for_reads = 1;
}

message CopyObjectRequest {
string allocation = 1;
string path = 2;
string path_hash = 3;
string connection_id = 4;
string dest = 5;
}
message CopyObjectResponse {
string filename = 1;
int64 size = 2;
string content_hash = 3;
string merkle_root = 4;
//UploadLength indicates the size of the entire upload in bytes. The value MUST be a non-negative integer.
int64 upload_length = 5;
//Upload-Offset indicates a byte offset within a resource. The value MUST be a non-negative integer.
int64 upload_offset = 6;
}

message Allocation {
string ID = 1;
string Tx = 2;
Expand Down
14 changes: 12 additions & 2 deletions code/go/0chain.net/blobbercore/convert/responseHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,19 @@ func CollaboratorResponse(response *blobbergrpc.CollaboratorResponse) interface{
return nil
}

func UpdateObjectAttributesResponseHandler(
updateAttributesResponse *blobbergrpc.UpdateObjectAttributesResponse) *blobberHTTP.UpdateObjectAttributesResponse {
func UpdateObjectAttributesResponseHandler(updateAttributesResponse *blobbergrpc.UpdateObjectAttributesResponse) *blobberHTTP.UpdateObjectAttributesResponse {
return &blobberHTTP.UpdateObjectAttributesResponse{
WhoPaysForReads: common.WhoPays(updateAttributesResponse.WhoPaysForReads),
}
}

func CopyObjectResponseHandler(copyObjectResponse *blobbergrpc.CopyObjectResponse) *blobberHTTP.UploadResult {
return &blobberHTTP.UploadResult{
Filename: copyObjectResponse.Filename,
Size: copyObjectResponse.Size,
Hash: copyObjectResponse.ContentHash,
MerkleRoot: copyObjectResponse.MerkleRoot,
UploadLength: copyObjectResponse.UploadLength,
UploadOffset: copyObjectResponse.UploadOffset,
}
}
25 changes: 17 additions & 8 deletions code/go/0chain.net/blobbercore/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func SetupHandlers(r *mux.Router) {
r.HandleFunc("/v1/file/upload/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithConnection(UploadHandler))))
r.HandleFunc("/v1/file/download/{allocation}", common.UserRateLimit(common.ToByteStream(WithConnection(DownloadHandler))))
r.HandleFunc("/v1/file/rename/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithConnection(RenameHandler))))
r.HandleFunc("/v1/file/copy/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithConnection(CopyHandler))))
r.HandleFunc("/v1/file/attributes/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithConnection(UpdateAttributesHandler(svc))))).Methods(http.MethodPost)
r.HandleFunc("/v1/file/copy/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithConnection(CopyHandler(svc))))).Methods(http.MethodPost)

r.HandleFunc("/v1/connection/commit/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithConnection(CommitHandler(svc))))).Methods("POST")
r.HandleFunc("/v1/file/commitmetatxn/{allocation}", common.UserRateLimit(common.ToJSONResponse(WithConnection(CommitMetaTxnHandler(svc))))).Methods(http.MethodPost)
Expand Down Expand Up @@ -316,14 +316,23 @@ func RenameHandler(ctx context.Context, r *http.Request) (interface{}, error) {
return response, nil
}

func CopyHandler(ctx context.Context, r *http.Request) (interface{}, error) {
ctx = setupHandlerContext(ctx, r)
response, err := storageHandler.CopyObject(ctx, r)
if err != nil {
return nil, err
}
func CopyHandler(svc *blobberGRPCService) func(ctx context.Context, r *http.Request) (interface{}, error) {
return func(ctx context.Context, r *http.Request) (interface{}, error) {
ctx = setupHandlerGRPCContext(ctx, r)

return response, nil
copyObjResponse, err := svc.CopyObject(ctx, &blobbergrpc.CopyObjectRequest{
Allocation: mux.Vars(r)["allocation"],
Path: r.FormValue("path"),
PathHash: r.FormValue("path_hash"),
ConnectionId: r.FormValue("connection_id"),
Dest: r.FormValue("dest"),
})
if err != nil {
return nil, err
}

return convert.CopyObjectResponseHandler(copyObjResponse), nil
}
}

/*UploadHandler is the handler to respond to upload requests fro clients*/
Expand Down
2 changes: 1 addition & 1 deletion code/go/0chain.net/blobbercore/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func setupHandlers() (*mux.Router, map[string]string) {
cName := "Copy"
router.HandleFunc(cPath, common.UserRateLimit(
common.ToJSONResponse(
WithReadOnlyConnection(CopyHandler),
WithReadOnlyConnection(CopyHandler(svc)),
),
),
).Name(cName)
Expand Down
2 changes: 1 addition & 1 deletion code/go/0chain.net/blobbercore/handler/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type StorageHandlerI interface {

// PackageHandler is an interface for all static functions that may need to be mocked
type PackageHandler interface {
GetReference(ctx context.Context, allocationID string, newPath string) (*reference.Ref, error)
GetReferenceLookup(ctx context.Context, allocationID string, path string) string
GetReferenceFromLookupHash(ctx context.Context, allocationID string, path_hash string) (*reference.Ref, error)
GetCommitMetaTxns(ctx context.Context, refID int64) ([]reference.CommitMetaTxn, error)
Expand All @@ -47,7 +48,6 @@ type PackageHandler interface {
GetObjectTree(ctx context.Context, allocationID string, path string) (*reference.Ref, error)
VerifyMarker(wm *writemarker.WriteMarkerEntity, ctx context.Context, sa *allocation.Allocation, co *allocation.AllocationChangeCollector) error
ApplyChanges(connectionObj *allocation.AllocationChangeCollector, ctx context.Context, allocationRoot string) error
GetReference(ctx context.Context, allocationID string, path string) (*reference.Ref, error)
UpdateAllocationAndCommitChanges(ctx context.Context, writemarkerObj *writemarker.WriteMarkerEntity, connectionObj *allocation.AllocationChangeCollector, allocationObj *allocation.Allocation, allocationRoot string) error
}

Expand Down
Loading