Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log blobber #1473

Open
wants to merge 4 commits into
base: staging
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handler
import (
"context"
"errors"
"fmt"
"net/http"

"github.com/0chain/gosdk/constants"
Expand Down Expand Up @@ -33,7 +34,7 @@ func (cmd *DeleteFileCommand) GetPath() string {
// IsValidated validate request.
func (cmd *DeleteFileCommand) IsValidated(ctx context.Context, req *http.Request, allocationObj *allocation.Allocation, clientID string) error {
if allocationObj.OwnerID != clientID && allocationObj.RepairerID != clientID {
return common.NewError("invalid_operation", "Operation needs to be performed by the owner or the payer of the allocation")
return common.NewError("invalid_operation", fmt.Sprintf("Operation needs to be performed by the owner or the payer of the allocation %s : client %s", allocationObj.ID, clientID))
}

path, ok := common.GetField(req, "path")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (cmd *UpdateFileCommand) GetPath() string {
// IsValidated validate request.
func (cmd *UpdateFileCommand) IsValidated(ctx context.Context, req *http.Request, allocationObj *allocation.Allocation, clientID string) error {
if allocationObj.OwnerID != clientID && allocationObj.RepairerID != clientID {
return common.NewError("invalid_operation", "Operation needs to be performed by the owner or the payer of the allocation")
return common.NewError("invalid_operation", fmt.Sprintf("Operation needs to be performed by the owner or the payer of the allocation %s : client %s", allocationObj.ID, clientID))
}

uploadMetaString := req.FormValue(UploadMeta)
Expand Down Expand Up @@ -171,7 +171,7 @@ func (cmd *UpdateFileCommand) ProcessContent(ctx context.Context, allocationObj
}

if allocationObj.BlobberSizeUsed+allocationSize > allocationObj.BlobberSize {
return result, common.NewError("max_allocation_size", "Max size reached for the allocation with this blobber")
return result, common.NewError("max_allocation_size", fmt.Sprintf("Max size reached for the allocation with this blobber : %d < %d", allocationObj.BlobberSize, allocationObj.BlobberSizeUsed+allocationSize))
}

return result, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (cmd *UploadFileCommand) GetPath() string {
// IsValidated validate request.
func (cmd *UploadFileCommand) IsValidated(ctx context.Context, req *http.Request, allocationObj *allocation.Allocation, clientID string) error {
if allocationObj.OwnerID != clientID && allocationObj.RepairerID != clientID {
return common.NewError("invalid_operation", "Operation needs to be performed by the owner or the payer of the allocation")
return common.NewError("invalid_operation", fmt.Sprintf("Operation needs to be performed by the owner or the payer of the allocation %s : client %s", allocationObj.ID, clientID))
}

fileChanger := &allocation.UploadFileChanger{}
Expand Down Expand Up @@ -187,7 +187,7 @@ func (cmd *UploadFileCommand) ProcessContent(ctx context.Context, allocationObj
}

if allocationObj.BlobberSizeUsed+allocationSize > allocationObj.BlobberSize {
return result, common.NewError("max_allocation_size", "Max size reached for the allocation with this blobber")
return result, common.NewError("max_allocation_size", fmt.Sprintf("Max size reached for the allocation with this blobber : %d < %d", allocationObj.BlobberSize, allocationObj.BlobberSizeUsed+allocationSize))
}

return result, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ func (fsh *StorageHandler) CreateConnection(ctx context.Context, r *http.Request
}

if allocationObj.OwnerID != clientID && allocationObj.RepairerID != clientID {
return nil, common.NewError("invalid_operation", "Operation needs to be performed by the owner or the payer of the allocation")
return nil, common.NewError("invalid_operation", fmt.Sprintf("Operation needs to be performed by the owner or the payer of the allocation %s : client %s", allocationObj.ID, clientID))
}

valid, err := verifySignatureFromRequest(allocationTx, r.Header.Get(common.ClientSignatureHeader), r.Header.Get(common.ClientSignatureHeaderV2), allocationObj.OwnerPublicKey)
Expand Down Expand Up @@ -756,7 +756,7 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b

if allocationObj.BlobberSizeUsed+connectionObj.Size > allocationObj.BlobberSize {
return nil, common.NewError("max_allocation_size",
"Max size reached for the allocation with this blobber")
fmt.Sprintf("Max size reached for the allocation with this blobber : %d < %d", allocationObj.BlobberSize, allocationObj.BlobberSizeUsed+connectionObj.Size))
}

if latestWriteMarkerEntity != nil && latestWriteMarkerEntity.WM.ChainSize+connectionObj.Size != writeMarker.ChainSize {
Expand Down Expand Up @@ -1245,7 +1245,7 @@ func (fsh *StorageHandler) CreateDir(ctx context.Context, r *http.Request) (*all
allocationID := allocationObj.ID

if clientID == "" {
return nil, common.NewError("invalid_operation", "Operation needs to be performed by the owner or the payer of the allocation")
return nil, common.NewError("invalid_operation", fmt.Sprintf("Operation needs to be performed by the owner or the payer of the allocation %s : client %s", allocationObj.ID, clientID))
}

dirPath := r.FormValue("dir_path")
Expand Down Expand Up @@ -1288,7 +1288,7 @@ func (fsh *StorageHandler) CreateDir(ctx context.Context, r *http.Request) (*all
}

if clientID != allocationObj.OwnerID {
return nil, common.NewError("invalid_operation", "Operation needs to be performed by the owner or the payer of the allocation")
return nil, common.NewError("invalid_operation", fmt.Sprintf("Operation needs to be performed by the owner or the payer of the allocation %s : client %s", allocationObj.ID, clientID))
}

if err := validateParentPathType(ctx, allocationID, dirPath); err != nil {
Expand Down Expand Up @@ -1341,7 +1341,7 @@ func (fsh *StorageHandler) WriteFile(ctx context.Context, r *http.Request) (*all
return nil, common.NewError("invalid_parameters", "Invalid connection id passed")
}
if clientID == "" {
return nil, common.NewError("invalid_operation", "Operation needs to be performed by the owner or the payer of the allocation")
return nil, common.NewError("invalid_operation", fmt.Sprintf("Operation needs to be performed by the owner or the payer of the allocation %s : client %s", allocationID, clientID))
}
if ok := CheckBlacklist(clientID); ok {
return nil, common.NewError("blacklisted_client", "Client is blacklisted: "+clientID)
Expand All @@ -1361,7 +1361,7 @@ func (fsh *StorageHandler) WriteFile(ctx context.Context, r *http.Request) (*all
}

if allocationObj.OwnerID != clientID && allocationObj.RepairerID != clientID {
return nil, common.NewError("invalid_operation", "Operation needs to be performed by the owner or the payer of the allocation")
return nil, common.NewError("invalid_operation", fmt.Sprintf("Operation needs to be performed by the owner or the payer of the allocation %s : client %s", allocationObj.ID, clientID))
}

elapsedAllocation := time.Since(st)
Expand Down
Loading