Skip to content

Commit

Permalink
chore: add error for cal nil model (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeylichang authored May 24, 2023
1 parent 4cab53f commit 23e849b
Showing 1 changed file with 65 additions and 47 deletions.
112 changes: 65 additions & 47 deletions core/module/null_modular.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package module

import (
"context"
"errors"
"io"

"github.com/bnb-chain/greenfield-storage-provider/base/types/gfspp2p"
Expand All @@ -10,6 +11,10 @@ import (
storagetypes "github.com/bnb-chain/greenfield/x/storage/types"
)

var (
ErrNilModular = errors.New("call nil module, please check again")
)

var _ Modular = (*NullModular)(nil)
var _ Approver = (*NullModular)(nil)
var _ Uploader = (*NullModular)(nil)
Expand All @@ -24,66 +29,74 @@ func (*NullModular) Stop(context.Context) error { return nil }
func (*NullModular) ReserveResource(context.Context, *rcmgr.ScopeStat) (rcmgr.ResourceScopeSpan, error) {
return &rcmgr.NullScope{}, nil
}

func (*NullModular) ReleaseResource(context.Context, rcmgr.ResourceScopeSpan) {}
func (*NullModular) QueryTasks(ctx context.Context, keyPrefix task.TKey) ([]task.Task, error) {
return nil, nil
return nil, ErrNilModular
}
func (*NullModular) ReleaseResource(context.Context, rcmgr.ResourceScopeSpan) {}
func (*NullModular) PreCreateBucketApproval(context.Context, task.ApprovalCreateBucketTask) error {
return nil
return ErrNilModular
}
func (*NullModular) HandleCreateBucketApprovalTask(context.Context, task.ApprovalCreateBucketTask) (bool, error) {
return false, nil
return false, ErrNilModular
}
func (*NullModular) PostCreateBucketApproval(context.Context, task.ApprovalCreateBucketTask) {}
func (*NullModular) PreCreateObjectApproval(context.Context, task.ApprovalCreateObjectTask) error {
return nil
return ErrNilModular
}
func (*NullModular) HandleCreateObjectApprovalTask(context.Context, task.ApprovalCreateObjectTask) (bool, error) {
return false, nil
return false, ErrNilModular
}
func (*NullModular) PostCreateObjectApproval(context.Context, task.ApprovalCreateObjectTask) {}
func (*NullModular) PreReplicatePieceApproval(context.Context, task.ApprovalReplicatePieceTask) error {
return nil
return ErrNilModular
}
func (*NullModular) HandleReplicatePieceApproval(context.Context, task.ApprovalReplicatePieceTask) (bool, error) {
return false, nil
return false, ErrNilModular
}
func (*NullModular) PostReplicatePieceApproval(context.Context, task.ApprovalReplicatePieceTask) {}
func (*NullModular) PreUploadObject(ctx context.Context, task task.UploadObjectTask) error {
return nil
return ErrNilModular
}
func (*NullModular) HandleUploadObjectTask(ctx context.Context, task task.UploadObjectTask, stream io.Reader) error {
return nil
}
func (*NullModular) PostUploadObject(ctx context.Context, task task.UploadObjectTask) {}
func (*NullModular) DispatchTask(context.Context, rcmgr.Limit) (task.Task, error) { return nil, nil }
func (*NullModular) QueryTask(context.Context, task.TKey) (task.Task, error) { return nil, nil }
func (*NullModular) DispatchTask(context.Context, rcmgr.Limit) (task.Task, error) {
return nil, ErrNilModular
}
func (*NullModular) QueryTask(context.Context, task.TKey) (task.Task, error) {
return nil, ErrNilModular
}
func (*NullModular) HandleCreateUploadObjectTask(context.Context, task.UploadObjectTask) error {
return nil
return ErrNilModular
}
func (*NullModular) HandleDoneUploadObjectTask(context.Context, task.UploadObjectTask) error {
return nil
return ErrNilModular
}

func (*NullModular) HandleReplicatePieceTask(context.Context, task.ReplicatePieceTask) error {
return nil
return ErrNilModular
}
func (*NullModular) HandleSealObjectTask(context.Context, task.SealObjectTask) error {
return ErrNilModular
}
func (*NullModular) HandleReceivePieceTask(context.Context, task.ReceivePieceTask) error {
return ErrNilModular
}
func (*NullModular) HandleGCObjectTask(context.Context, task.GCObjectTask) error {
return ErrNilModular
}
func (*NullModular) HandleSealObjectTask(context.Context, task.SealObjectTask) error { return nil }
func (*NullModular) HandleReceivePieceTask(context.Context, task.ReceivePieceTask) error { return nil }
func (*NullModular) HandleGCObjectTask(context.Context, task.GCObjectTask) error { return nil }
func (*NullModular) HandleGCZombiePieceTask(context.Context, task.GCZombiePieceTask) error {
return nil
return ErrNilModular
}
func (*NullModular) HandleGCMetaTask(context.Context, task.GCMetaTask) error { return nil }
func (*NullModular) HandleGCMetaTask(context.Context, task.GCMetaTask) error { return ErrNilModular }
func (*NullModular) HandleDownloadObjectTask(context.Context, task.DownloadObjectTask) error {
return nil
return ErrNilModular
}
func (*NullModular) HandleChallengePieceTask(context.Context, task.ChallengePieceTask) error {
return nil
return ErrNilModular
}
func (*NullModular) VerifyAuthorize(context.Context, AuthOpType, string, string, string) (bool, error) {
return false, nil
return false, ErrNilModular
}

var _ TaskExecutor = (*NilModular)(nil)
Expand All @@ -99,56 +112,61 @@ func (*NilModular) Stop(context.Context) error { return nil }
func (*NilModular) ReserveResource(context.Context, *rcmgr.ScopeStat) (rcmgr.ResourceScopeSpan, error) {
return &rcmgr.NullScope{}, nil
}

func (*NilModular) ReleaseResource(context.Context, rcmgr.ResourceScopeSpan) {}
func (*NilModular) QueryTasks(ctx context.Context, keyPrefix task.TKey) ([]task.Task, error) {
return nil, nil
return nil, ErrNilModular
}
func (*NilModular) PreDownloadObject(context.Context, task.DownloadObjectTask) error {
return ErrNilModular
}
func (*NilModular) ReleaseResource(context.Context, rcmgr.ResourceScopeSpan) {}
func (*NilModular) PreDownloadObject(context.Context, task.DownloadObjectTask) error { return nil }
func (*NilModular) HandleDownloadObjectTask(context.Context, task.DownloadObjectTask) ([]byte, error) {
return nil, nil
return nil, ErrNilModular
}
func (*NilModular) PostDownloadObject(context.Context, task.DownloadObjectTask) {}
func (*NilModular) PreChallengePiece(context.Context, task.ChallengePieceTask) error {
return ErrNilModular
}
func (*NilModular) PostDownloadObject(context.Context, task.DownloadObjectTask) {}
func (*NilModular) PreChallengePiece(context.Context, task.ChallengePieceTask) error { return nil }
func (*NilModular) HandleChallengePiece(context.Context, task.ChallengePieceTask) ([]byte, [][]byte, []byte, error) {
return nil, nil, nil, nil
return nil, nil, nil, ErrNilModular
}
func (*NilModular) AskTask(context.Context, rcmgr.Limit) {}
func (*NilModular) PostChallengePiece(context.Context, task.ChallengePieceTask) {}
func (*NilModular) ReportTask(context.Context, task.Task) error { return nil }
func (*NilModular) ReportTask(context.Context, task.Task) error { return ErrNilModular }
func (*NilModular) HandleReplicatePieceTask(context.Context, task.ReplicatePieceTask) {}
func (*NilModular) HandleSealObjectTask(context.Context, task.SealObjectTask) {}
func (*NilModular) HandleReceivePieceTask(context.Context, task.ReceivePieceTask) {}
func (*NilModular) HandleGCObjectTask(context.Context, task.GCObjectTask) {}
func (*NilModular) HandleGCZombiePieceTask(context.Context, task.GCZombiePieceTask) {}
func (*NilModular) HandleGCMetaTask(context.Context, task.GCMetaTask) {}
func (*NilModular) HandleReplicatePieceApproval(context.Context, task.ApprovalReplicatePieceTask, int32, int32, int64) ([]task.ApprovalReplicatePieceTask, error) {
return nil, nil
return nil, ErrNilModular
}
func (*NilModular) HandleQueryBootstrap(context.Context) ([]string, error) { return nil, nil }
func (*NilModular) HandleQueryBootstrap(context.Context) ([]string, error) { return nil, ErrNilModular }

func (*NilModular) SignCreateBucketApproval(context.Context, *storagetypes.MsgCreateBucket) ([]byte, error) {
return nil, nil
return nil, ErrNilModular
}
func (*NilModular) SignCreateObjectApproval(context.Context, *storagetypes.MsgCreateObject) ([]byte, error) {
return nil, nil
return nil, ErrNilModular
}
func (*NilModular) SignReplicatePieceApproval(context.Context, task.ApprovalReplicatePieceTask) ([]byte, error) {
return nil, nil
return nil, ErrNilModular
}
func (*NilModular) SignReceivePieceTask(context.Context, task.ReceivePieceTask) ([]byte, error) {
return nil, nil
return nil, ErrNilModular
}
func (*NilModular) SignIntegrityHash(ctx context.Context, objectID uint64, hash [][]byte) ([]byte, []byte, error) {
return nil, nil, nil
return nil, nil, ErrNilModular
}
func (*NilModular) SignP2PPingMsg(context.Context, *gfspp2p.GfSpPing) ([]byte, error) {
return nil, nil
return nil, ErrNilModular
}
func (*NilModular) SignP2PPongMsg(context.Context, *gfspp2p.GfSpPong) ([]byte, error) {
return nil, nil
return nil, ErrNilModular
}
func (*NilModular) SealObject(context.Context, *storagetypes.MsgSealObject) error {
return ErrNilModular
}
func (*NilModular) SealObject(context.Context, *storagetypes.MsgSealObject) error { return nil }

var _ Receiver = (*NullReceiveModular)(nil)

Expand All @@ -160,13 +178,13 @@ func (*NullReceiveModular) Stop(context.Context) error { return nil }
func (*NullReceiveModular) ReserveResource(context.Context, *rcmgr.ScopeStat) (rcmgr.ResourceScopeSpan, error) {
return &rcmgr.NullScope{}, nil
}
func (*NullReceiveModular) ReleaseResource(context.Context, rcmgr.ResourceScopeSpan) {}
func (*NullReceiveModular) QueryTasks(ctx context.Context, keyPrefix task.TKey) ([]task.Task, error) {
return nil, nil
return nil, ErrNilModular
}
func (*NullReceiveModular) ReleaseResource(context.Context, rcmgr.ResourceScopeSpan) {}
func (*NullReceiveModular) HandleReceivePieceTask(context.Context, task.ReceivePieceTask, []byte) error {
return nil
return ErrNilModular
}
func (*NullReceiveModular) HandleDoneReceivePieceTask(context.Context, task.ReceivePieceTask) ([]byte, []byte, error) {
return nil, nil, nil
return nil, nil, ErrNilModular
}

0 comments on commit 23e849b

Please sign in to comment.