diff --git a/Makefile b/Makefile index dc1cdf24d..ba3dd4b74 100644 --- a/Makefile +++ b/Makefile @@ -7,4 +7,4 @@ lint: golangci-lint run --timeout 2m0s; integration-tests: - go test ./... -args integration; \ No newline at end of file + sudo go test ./... -args integration; diff --git a/code/go/0chain.net/blobbercore/convert/convert.go b/code/go/0chain.net/blobbercore/convert/convert.go index 1e600464f..4670703cd 100644 --- a/code/go/0chain.net/blobbercore/convert/convert.go +++ b/code/go/0chain.net/blobbercore/convert/convert.go @@ -7,6 +7,7 @@ import ( "github.com/0chain/blobber/code/go/0chain.net/blobbercore/readmarker" "mime/multipart" "net/http" + "strings" "time" "github.com/0chain/blobber/code/go/0chain.net/blobbercore/allocation" @@ -480,3 +481,59 @@ func WriteFileGRPCToHTTP(req *blobbergrpc.UploadFileRequest) (*http.Request, err return r, nil } + +func DownloadFileGRPCToHTTP(req *blobbergrpc.DownloadFileRequest) (*http.Request, error) { + body := bytes.NewBuffer([]byte{}) + writer := multipart.NewWriter(body) + + err := writer.WriteField("path", req.Path) + if err != nil { + return nil, err + } + + err = writer.WriteField("path_hash", req.PathHash) + if err != nil { + return nil, err + } + + err = writer.WriteField("rx_pay", req.RxPay) + if err != nil { + return nil, err + } + + err = writer.WriteField("block_num", req.BlockNum) + if err != nil { + return nil, err + } + + err = writer.WriteField("num_blocks", req.NumBlocks) + if err != nil { + return nil, err + } + + err = writer.WriteField("read_marker", req.ReadMarker) + if err != nil { + return nil, err + } + + err = writer.WriteField("auth_token", req.AuthToken) + if err != nil { + return nil, err + } + + err = writer.WriteField("content", req.Content) + if err != nil { + return nil, err + } + + writer.Close() + + r, err := http.NewRequest("POST", "", strings.NewReader(body.String())) + if err != nil { + return nil, err + } + + r.Header.Set("Content-Type", writer.FormDataContentType()) + + return r, nil +} diff --git a/code/go/0chain.net/blobbercore/convert/responseHandler.go b/code/go/0chain.net/blobbercore/convert/responseHandler.go index b19893369..800bee170 100644 --- a/code/go/0chain.net/blobbercore/convert/responseHandler.go +++ b/code/go/0chain.net/blobbercore/convert/responseHandler.go @@ -3,7 +3,6 @@ package convert import ( "context" "encoding/json" - "github.com/0chain/blobber/code/go/0chain.net/core/common" stats2 "github.com/0chain/blobber/code/go/0chain.net/blobbercore/stats" @@ -182,11 +181,12 @@ func CollaboratorResponseCreator(r interface{}) *blobbergrpc.CollaboratorRespons } func UpdateObjectAttributesResponseCreator(r interface{}) *blobbergrpc.UpdateObjectAttributesResponse { - if r != nil { + if r == nil { return nil } httpResp, _ := r.(*reference.Attributes) + return &blobbergrpc.UpdateObjectAttributesResponse{WhoPaysForReads: int64(httpResp.WhoPaysForReads)} } @@ -376,14 +376,22 @@ func DownloadFileResponseCreator(r interface{}) *blobbergrpc.DownloadFileRespons return nil } - httpResp, _ := r.(*blobberHTTP.DownloadResponse) - return &blobbergrpc.DownloadFileResponse{ - Success: httpResp.Success, - Data: httpResp.Data, - AllocationId: httpResp.AllocationID, - Path: httpResp.Path, - LatestRm: ReadMarkerToReadMarkerGRPC(httpResp.LatestRM), + switch httpResp := r.(type) { + case []byte: + return &blobbergrpc.DownloadFileResponse{ + Data: httpResp, + } + case *blobberHTTP.DownloadResponse: + return &blobbergrpc.DownloadFileResponse{ + Success: httpResp.Success, + Data: httpResp.Data, + AllocationId: httpResp.AllocationID, + Path: httpResp.Path, + LatestRm: ReadMarkerToReadMarkerGRPC(httpResp.LatestRM), + } } + + return nil } func UploadFileResponseCreator(r interface{}) *blobbergrpc.UploadFileResponse { diff --git a/code/go/0chain.net/blobbercore/handler/grpc_handler_helper_unit_test.go b/code/go/0chain.net/blobbercore/handler/grpc_handler_helper_unit_test.go index e86adbc77..af5063f49 100644 --- a/code/go/0chain.net/blobbercore/handler/grpc_handler_helper_unit_test.go +++ b/code/go/0chain.net/blobbercore/handler/grpc_handler_helper_unit_test.go @@ -545,6 +545,254 @@ VALUES return nil } +func (c *TestDataController) AddAttributesTestData(allocationTx, pubkey, clientId string) error { + var err error + var tx *sql.Tx + defer func() { + if err != nil { + if tx != nil { + errRollback := tx.Rollback() + if errRollback != nil { + log.Println(errRollback) + } + } + } + }() + + db, err := c.db.DB() + if err != nil { + return err + } + + tx, err = db.BeginTx(context.Background(), &sql.TxOptions{}) + if err != nil { + return err + } + + expTime := time.Now().Add(time.Hour * 100000).UnixNano() + + _, err = tx.Exec(` +INSERT INTO allocations (id, tx, owner_id, owner_public_key, expiration_date, payer_id, blobber_size, allocation_root) +VALUES ('exampleId' ,'` + allocationTx + `','` + clientId + `','` + pubkey + `',` + fmt.Sprint(expTime) + `,'examplePayerId', 99999999, '/'); +`) + if err != nil { + return err + } + + _, err = tx.Exec(` +INSERT INTO allocation_connections (connection_id, allocation_id, client_id, size, status) +VALUES ('connection_id' ,'exampleId','` + clientId + `', 1337, 1); +`) + if err != nil { + return err + } + + _, err = tx.Exec(` +INSERT INTO reference_objects (id, allocation_id, path_hash,lookup_hash,type,name,path,hash,custom_meta,content_hash,merkle_root,actual_file_hash,mimetype,write_marker,thumbnail_hash, actual_thumbnail_hash, parent_path) +VALUES +(1234,'exampleId','exampleId:examplePath','exampleId:examplePath','d','root','/','someHash','customMeta','contentHash','merkleRoot','actualFileHash','mimetype','writeMarker','thumbnailHash','actualThumbnailHash','/'), +(123,'exampleId','exampleId:examplePath','exampleId:examplePath','f','some_file','/some_file','someHash','customMeta','contentHash','merkleRoot','actualFileHash','mimetype','writeMarker','thumbnailHash','actualThumbnailHash','/'); +`) + if err != nil { + return err + } + + err = tx.Commit() + if err != nil { + return err + } + + return nil +} + +func (c *TestDataController) AddCopyObjectData(allocationTx, pubkey, clientId string) error { + var err error + var tx *sql.Tx + defer func() { + if err != nil { + if tx != nil { + errRollback := tx.Rollback() + if errRollback != nil { + log.Println(errRollback) + } + } + } + }() + + db, err := c.db.DB() + if err != nil { + return err + } + + tx, err = db.BeginTx(context.Background(), &sql.TxOptions{}) + if err != nil { + return err + } + + expTime := time.Now().Add(time.Hour * 100000).UnixNano() + + _, err = tx.Exec(` +INSERT INTO allocations (id, tx, owner_id, owner_public_key, expiration_date, payer_id, blobber_size, allocation_root) +VALUES ('exampleId' ,'` + allocationTx + `','` + clientId + `','` + pubkey + `',` + fmt.Sprint(expTime) + `,'examplePayerId', 99999999, '/'); +`) + if err != nil { + return err + } + + _, err = tx.Exec(` +INSERT INTO allocation_connections (connection_id, allocation_id, client_id, size, status) +VALUES ('connection_id' ,'exampleId','` + clientId + `', 1337, 1); +`) + if err != nil { + return err + } + + _, err = tx.Exec(` +INSERT INTO reference_objects (id, allocation_id, path_hash,lookup_hash,type,name,path,hash,custom_meta,content_hash,merkle_root,actual_file_hash,mimetype,write_marker,thumbnail_hash, actual_thumbnail_hash, parent_path) +VALUES +(1234,'exampleId','exampleId:examplePath','exampleId:examplePath','d','root','/copy','someHash','customMeta','contentHash','merkleRoot','actualFileHash','mimetype','writeMarker','thumbnailHash','actualThumbnailHash','/'), +(123,'exampleId','exampleId:examplePath','exampleId:examplePath','f','some_file','/some_file','someHash','customMeta','contentHash','merkleRoot','actualFileHash','mimetype','writeMarker','thumbnailHash','actualThumbnailHash','/'); +`) + if err != nil { + return err + } + + err = tx.Commit() + if err != nil { + return err + } + + return nil +} + +func (c *TestDataController) AddRenameTestData(allocationTx, pubkey, clientId string) error { + var err error + var tx *sql.Tx + defer func() { + if err != nil { + if tx != nil { + errRollback := tx.Rollback() + if errRollback != nil { + log.Println(errRollback) + } + } + } + }() + + db, err := c.db.DB() + if err != nil { + return err + } + + tx, err = db.BeginTx(context.Background(), &sql.TxOptions{}) + if err != nil { + return err + } + + expTime := time.Now().Add(time.Hour * 100000).UnixNano() + + _, err = tx.Exec(` +INSERT INTO allocations (id, tx, owner_id, owner_public_key, expiration_date, payer_id, blobber_size, allocation_root) +VALUES ('exampleId' ,'` + allocationTx + `','` + clientId + `','` + pubkey + `',` + fmt.Sprint(expTime) + `,'examplePayerId', 99999999, '/'); +`) + if err != nil { + return err + } + + _, err = tx.Exec(` +INSERT INTO allocation_connections (connection_id, allocation_id, client_id, size, status) +VALUES ('connection_id' ,'exampleId','` + clientId + `', 1337, 1); +`) + if err != nil { + return err + } + + _, err = tx.Exec(` +INSERT INTO reference_objects (id, allocation_id, path_hash,lookup_hash,type,name,path,hash,custom_meta,content_hash,merkle_root,actual_file_hash,mimetype,write_marker,thumbnail_hash, actual_thumbnail_hash, parent_path) +VALUES +(1234,'exampleId','exampleId:examplePath','exampleId:examplePath','d','root','/','someHash','customMeta','contentHash','merkleRoot','actualFileHash','mimetype','writeMarker','thumbnailHash','actualThumbnailHash','/'), +(123,'exampleId','exampleId:examplePath','exampleId:examplePath','f','some_file','/some_file','someHash','customMeta','contentHash','merkleRoot','actualFileHash','mimetype','writeMarker','thumbnailHash','actualThumbnailHash','/'); +`) + if err != nil { + return err + } + + err = tx.Commit() + if err != nil { + return err + } + + return nil +} + +func (c *TestDataController) AddDownloadTestData(allocationTx, pubkey, clientId, wmSig string, now common.Timestamp) error { + var err error + var tx *sql.Tx + defer func() { + if err != nil { + if tx != nil { + errRollback := tx.Rollback() + if errRollback != nil { + log.Println(errRollback) + } + } + } + }() + + db, err := c.db.DB() + if err != nil { + return err + } + + tx, err = db.BeginTx(context.Background(), &sql.TxOptions{}) + if err != nil { + return err + } + + expTime := time.Now().Add(time.Hour * 100000).UnixNano() + + _, err = tx.Exec(` +INSERT INTO allocations (id, tx, owner_id, owner_public_key, expiration_date, payer_id, blobber_size, allocation_root) +VALUES ('exampleId' ,'` + allocationTx + `','` + clientId + `','` + pubkey + `',` + fmt.Sprint(expTime) + `,'examplePayerId', 99999999, '/'); +`) + if err != nil { + return err + } + + _, err = tx.Exec(` +INSERT INTO allocation_connections (connection_id, allocation_id, client_id, size, status) +VALUES ('connection_id' ,'exampleId','` + clientId + `', 1337, 1); +`) + if err != nil { + return err + } + + _, err = tx.Exec(` +INSERT INTO allocation_changes (id, connection_id, operation, size, input) +VALUES (1 ,'connection_id','rename', 1200, '{"allocation_id":"exampleId","path":"/some_file","new_name":"new_name"}'); +`) + if err != nil { + return err + } + + _, err = tx.Exec(` +INSERT INTO reference_objects (id, allocation_id, path_hash,lookup_hash,type,name,path,hash,custom_meta,content_hash,merkle_root,actual_file_hash,mimetype,write_marker,thumbnail_hash, actual_thumbnail_hash, parent_path) +VALUES +(1234,'exampleId','exampleId:examplePath','exampleId:examplePath','d','root','/','someHash','customMeta','contentHash','merkleRoot','actualFileHash','mimetype','writeMarker','thumbnailHash','actualThumbnailHash','/'), +(123,'exampleId','exampleId:examplePath','exampleId:examplePath','f','some_file','/some_file','someHash','customMeta','tmpMonWenMyFile','merkleRoot','actualFileHash','mimetype','writeMarker','thumbnailHash','actualThumbnailHash','/'); +`) + if err != nil { + return err + } + + err = tx.Commit() + if err != nil { + return err + } + + return nil +} + func (c *TestDataController) AddUploadTestData(allocationTx, pubkey, clientId string) error { var err error var tx *sql.Tx diff --git a/code/go/0chain.net/blobbercore/handler/grpc_handler_integration_test.go b/code/go/0chain.net/blobbercore/handler/grpc_handler_integration_test.go index 767f2db50..401f2717b 100644 --- a/code/go/0chain.net/blobbercore/handler/grpc_handler_integration_test.go +++ b/code/go/0chain.net/blobbercore/handler/grpc_handler_integration_test.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "github.com/0chain/blobber/code/go/0chain.net/blobbercore/allocation" + "github.com/0chain/blobber/code/go/0chain.net/blobbercore/readmarker" "io" "log" "math/rand" @@ -908,6 +909,390 @@ func TestBlobberGRPCService_IntegrationTest(t *testing.T) { } }) + t.Run("TestUpdateAttributes", func(t *testing.T) { + allocationTx := randString(32) + + pubKey, _, signScheme := GeneratePubPrivateKey(t) + clientSignature, _ := signScheme.Sign(encryption.Hash(allocationTx)) + pubKeyBytes, _ := hex.DecodeString(pubKey) + clientId := encryption.Hash(pubKeyBytes) + + if err := tdController.ClearDatabase(); err != nil { + t.Fatal(err) + } + if err := tdController.AddAttributesTestData(allocationTx, pubKey, clientId); err != nil { + t.Fatal(err) + } + + attr := &reference.Attributes{WhoPaysForReads: common.WhoPays3rdParty} + attrBytes, err := json.Marshal(attr) + if err != nil { + t.Fatal(err) + } + + testCases := []struct { + name string + context metadata.MD + input *blobbergrpc.UpdateObjectAttributesRequest + expectedMessage int + expectingError bool + }{ + { + name: "Success", + context: metadata.New(map[string]string{ + common.ClientHeader: clientId, + common.ClientSignatureHeader: clientSignature, + common.ClientKeyHeader: pubKey, + }), + input: &blobbergrpc.UpdateObjectAttributesRequest{ + Allocation: allocationTx, + Path: "/some_file", + PathHash: "exampleId:examplePath", + ConnectionId: "connection_id", + Attributes: string(attrBytes), + }, + expectedMessage: int(attr.WhoPaysForReads), + expectingError: false, + }, + { + name: "Fail", + context: metadata.New(map[string]string{ + common.ClientHeader: clientId, + common.ClientSignatureHeader: clientSignature, + common.ClientKeyHeader: pubKey, + }), + input: &blobbergrpc.UpdateObjectAttributesRequest{ + Allocation: "", + Path: "", + PathHash: "", + ConnectionId: "", + Attributes: "", + }, + expectedMessage: 0, + expectingError: true, + }, + } + + for _, tc := range testCases { + ctx := context.Background() + ctx = metadata.NewOutgoingContext(ctx, tc.context) + response, err := blobberClient.UpdateObjectAttributes(ctx, tc.input) + if err != nil { + if !tc.expectingError { + t.Fatal(err) + } + + continue + } + + if tc.expectingError { + t.Fatal("expected error") + } + + if response.GetWhoPaysForReads() != int64(tc.expectedMessage) { + t.Fatal("failed!") + } + } + }) + + t.Run("TestCopyObject", func(t *testing.T) { + allocationTx := randString(32) + + pubKey, _, signScheme := GeneratePubPrivateKey(t) + clientSignature, _ := signScheme.Sign(encryption.Hash(allocationTx)) + pubKeyBytes, _ := hex.DecodeString(pubKey) + clientId := encryption.Hash(pubKeyBytes) + + if err := tdController.ClearDatabase(); err != nil { + t.Fatal(err) + } + if err := tdController.AddCopyObjectData(allocationTx, pubKey, clientId); err != nil { + t.Fatal(err) + } + + testCases := []struct { + name string + context metadata.MD + input *blobbergrpc.CopyObjectRequest + expectedMessage string + expectingError bool + }{ + { + name: "Success", + context: metadata.New(map[string]string{ + common.ClientHeader: clientId, + common.ClientSignatureHeader: clientSignature, + common.ClientKeyHeader: pubKey, + }), + input: &blobbergrpc.CopyObjectRequest{ + Allocation: allocationTx, + Path: "/some_file", + PathHash: "exampleId:examplePath", + ConnectionId: "connection_id", + Dest: "/copy", + }, + expectedMessage: "some_file", + expectingError: false, + }, + { + name: "Fail", + context: metadata.New(map[string]string{ + common.ClientHeader: clientId, + common.ClientSignatureHeader: clientSignature, + common.ClientKeyHeader: pubKey, + }), + input: &blobbergrpc.CopyObjectRequest{ + Allocation: "", + Path: "", + PathHash: "", + ConnectionId: "", + Dest: "", + }, + expectedMessage: "", + expectingError: true, + }, + } + + for _, tc := range testCases { + ctx := context.Background() + ctx = metadata.NewOutgoingContext(ctx, tc.context) + response, err := blobberClient.CopyObject(ctx, tc.input) + if err != nil { + if !tc.expectingError { + t.Fatal(err) + } + + continue + } + + if tc.expectingError { + t.Fatal("expected error") + } + + if response.GetFilename() != tc.expectedMessage { + t.Fatal("failed!") + } + } + }) + + t.Run("TestRenameObject", func(t *testing.T) { + allocationTx := randString(32) + + pubKey, _, signScheme := GeneratePubPrivateKey(t) + clientSignature, _ := signScheme.Sign(encryption.Hash(allocationTx)) + pubKeyBytes, _ := hex.DecodeString(pubKey) + clientId := encryption.Hash(pubKeyBytes) + + if err := tdController.ClearDatabase(); err != nil { + t.Fatal(err) + } + if err := tdController.AddRenameTestData(allocationTx, pubKey, clientId); err != nil { + t.Fatal(err) + } + + testCases := []struct { + name string + context metadata.MD + input *blobbergrpc.RenameObjectRequest + expectedMessage string + expectingError bool + }{ + { + name: "Success", + context: metadata.New(map[string]string{ + common.ClientHeader: clientId, + common.ClientSignatureHeader: clientSignature, + common.ClientKeyHeader: pubKey, + }), + input: &blobbergrpc.RenameObjectRequest{ + Allocation: allocationTx, + Path: "/some_file", + PathHash: "exampleId:examplePath", + ConnectionId: "connection_id", + NewName: "some_new_file", + }, + expectedMessage: "some_new_file", + expectingError: false, + }, + { + name: "Fail", + context: metadata.New(map[string]string{ + common.ClientHeader: clientId, + common.ClientSignatureHeader: clientSignature, + common.ClientKeyHeader: pubKey, + }), + input: &blobbergrpc.RenameObjectRequest{ + Allocation: "", + Path: "", + PathHash: "", + ConnectionId: "", + NewName: "", + }, + expectedMessage: "", + expectingError: true, + }, + } + + for _, tc := range testCases { + ctx := context.Background() + ctx = metadata.NewOutgoingContext(ctx, tc.context) + response, err := blobberClient.RenameObject(ctx, tc.input) + if err != nil { + if !tc.expectingError { + t.Fatal(err) + } + + continue + } + + if tc.expectingError { + t.Fatal("expected error") + } + + if response.GetFilename() != tc.expectedMessage { + t.Fatal("failed!") + } + } + }) + + t.Run("TestDownload", func(t *testing.T) { + allocationTx := randString(32) + + root, _ := os.Getwd() + path := strings.Split(root, `code`) + + err = os.MkdirAll(path[0]+`docker.local/blobber1/files/files/exa/mpl/eId/objects/tmp/Mon/Wen`, os.ModePerm) + if err != nil { + t.Fatal(err) + } + defer func() { + err := os.RemoveAll(path[0] + `docker.local/blobber1/files/files/exa/mpl/eId/objects/tmp/Mon`) + if err != nil { + t.Fatal(err) + } + }() + + f, err := os.Create(path[0] + `docker.local/blobber1/files/files/exa/mpl/eId/objects/tmp/Mon/Wen/MyFile`) + if err != nil { + t.Fatal(err) + } + defer f.Close() + + file, err := os.Open(root + "/grpc_handler_integration_test.go") + if err != nil { + t.Fatal(err) + } + defer file.Close() + + _, err = io.Copy(f, file) + if err != nil { + t.Fatal(err) + } + + pubKey, _, signScheme := GeneratePubPrivateKey(t) + clientSignature, _ := signScheme.Sign(encryption.Hash(allocationTx)) + pubKeyBytes, _ := hex.DecodeString(pubKey) + clientId := encryption.Hash(pubKeyBytes) + now := common.Timestamp(time.Now().Unix()) + allocationId := `exampleId` + + if err := tdController.ClearDatabase(); err != nil { + t.Fatal(err) + } + + blobberPubKey := "de52c0a51872d5d2ec04dbc15a6f0696cba22657b80520e1d070e72de64c9b04e19ce3223cae3c743a20184158457582ffe9c369ca9218c04bfe83a26a62d88d" + blobberPubKeyBytes, _ := hex.DecodeString(blobberPubKey) + + rm := readmarker.ReadMarker{ + BlobberID: encryption.Hash(blobberPubKeyBytes), + AllocationID: allocationId, + ClientPublicKey: pubKey, + ClientID: clientId, + OwnerID: clientId, + Timestamp: now, + //ReadCounter: 1337, + } + + rmSig, err := signScheme.Sign(encryption.Hash(rm.GetHashData())) + if err != nil { + t.Fatal(err) + } + rm.Signature = rmSig + + rmString, err := json.Marshal(rm) + if err != nil { + t.Fatal(err) + } + + if err := tdController.AddDownloadTestData(allocationTx, pubKey, clientId, rmSig, now); err != nil { + t.Fatal(err) + } + + testCases := []struct { + name string + context metadata.MD + input *blobbergrpc.DownloadFileRequest + expectedMessage string + expectingError bool + }{ + { + name: "Success", + context: metadata.New(map[string]string{ + common.ClientHeader: clientId, + common.ClientSignatureHeader: clientSignature, + common.ClientKeyHeader: pubKey, + }), + input: &blobbergrpc.DownloadFileRequest{ + Allocation: allocationTx, + Path: "/some_file", + PathHash: "exampleId:examplePath", + ReadMarker: string(rmString), + BlockNum: "1", + }, + expectedMessage: "some_new_file", + expectingError: false, + }, + { + name: "Fail", + context: metadata.New(map[string]string{ + common.ClientHeader: clientId, + common.ClientSignatureHeader: clientSignature, + common.ClientKeyHeader: pubKey, + }), + input: &blobbergrpc.DownloadFileRequest{ + Allocation: "", + Path: "", + PathHash: "", + RxPay: "", + BlockNum: "", + NumBlocks: "", + ReadMarker: "", + AuthToken: "", + Content: "", + }, + expectedMessage: "", + expectingError: true, + }, + } + + for _, tc := range testCases { + ctx := context.Background() + ctx = metadata.NewOutgoingContext(ctx, tc.context) + _, err := blobberClient.DownloadFile(ctx, tc.input) + if err != nil { + if !tc.expectingError { + t.Fatal(err) + } + + continue + } + + if tc.expectingError { + t.Fatal("expected error") + } + } + }) + t.Run("TestUpload", func(t *testing.T) { allocationTx := randString(32) diff --git a/code/go/0chain.net/blobbercore/handler/object_operation_grpc_handler.go b/code/go/0chain.net/blobbercore/handler/object_operation_grpc_handler.go index ad697f1ce..69fe5afd5 100644 --- a/code/go/0chain.net/blobbercore/handler/object_operation_grpc_handler.go +++ b/code/go/0chain.net/blobbercore/handler/object_operation_grpc_handler.go @@ -71,23 +71,12 @@ func (b *blobberGRPCService) RenameObject(ctx context.Context, req *blobbergrpc. } func (b *blobberGRPCService) DownloadFile(ctx context.Context, req *blobbergrpc.DownloadFileRequest) (*blobbergrpc.DownloadFileResponse, error) { - - r, err := http.NewRequest("POST", "", nil) + r, err := convert.DownloadFileGRPCToHTTP(req) if err != nil { return nil, err } httpRequestWithMetaData(r, GetGRPCMetaDataFromCtx(ctx), req.Allocation) - r.Form = map[string][]string{ - "path": {req.Path}, - "path_hash": {req.PathHash}, - "rx_pay": {req.RxPay}, - "block_num": {req.BlockNum}, - "num_blocks": {req.NumBlocks}, - "read_marker": {req.ReadMarker}, - "auth_token": {req.AuthToken}, - "content": {req.AuthToken}, - } resp, err := DownloadHandler(ctx, r) if err != nil { diff --git a/code/go/0chain.net/blobbercore/handler/object_operation_handler.go b/code/go/0chain.net/blobbercore/handler/object_operation_handler.go index 7ccc89fe3..ec91938a0 100644 --- a/code/go/0chain.net/blobbercore/handler/object_operation_handler.go +++ b/code/go/0chain.net/blobbercore/handler/object_operation_handler.go @@ -5,7 +5,6 @@ import ( "encoding/hex" "encoding/json" "errors" - "github.com/0chain/blobber/code/go/0chain.net/blobbercore/blobberHTTP" "net/http"