requestvalidation

package
v1.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2021 License: Apache-2.0, MIT Imports: 11 Imported by: 0

Documentation

Overview

Package requestvalidation implements a request validator for the data transfer module to validate data transfer requests for storage deals

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrWrongVoucherType means the voucher was not the correct type can validate against
	ErrWrongVoucherType = errors.New("cannot validate voucher type")

	// ErrNoPushAccepted just means clients do not accept pushes for storage deals
	ErrNoPushAccepted = errors.New("client should not receive data for a storage deal")

	// ErrNoPullAccepted just means providers do not accept pulls for storage deals
	ErrNoPullAccepted = errors.New("provider should not send data for a storage deal")

	// ErrNoDeal means no active deal was found for this vouchers proposal cid
	ErrNoDeal = errors.New("no deal found for this proposal")

	// ErrWrongPeer means that the other peer for this data transfer request does not match
	// the other peer for the deal
	ErrWrongPeer = errors.New("data Transfer peer id and Deal peer id do not match")

	// ErrWrongPiece means that the pieceref for this data transfer request does not match
	// the one specified in the deal
	ErrWrongPiece = errors.New("base CID for deal does not match CID for piece")

	// ErrInacceptableDealState means the deal for this transfer is not in a deal state
	// where transfer can be performed
	ErrInacceptableDealState = errors.New("deal is not in a state where deals are accepted")

	// DataTransferStates are the states in which it would make sense to actually start a data transfer
	// We accept deals even in the StorageDealTransferring state too as we could also also receive a data transfer restart request
	DataTransferStates = []storagemarket.StorageDealStatus{storagemarket.StorageDealValidating, storagemarket.StorageDealWaitingForData, storagemarket.StorageDealUnknown,
		storagemarket.StorageDealTransferring, storagemarket.StorageDealProviderTransferAwaitRestart}
)

Functions

func ValidatePull

func ValidatePull(
	deals PullDeals,
	receiver peer.ID,
	voucher datatransfer.Voucher,
	baseCid cid.Cid,
	Selector ipld.Node) error

ValidatePull validates a pull request received from the peer that will receive data Will succeed only if: - voucher has correct type - voucher references an active deal - referenced deal matches the receiver (miner) - referenced deal matches the given base CID - referenced deal is in an acceptable state

func ValidatePush

func ValidatePush(
	deals PushDeals,
	sender peer.ID,
	voucher datatransfer.Voucher,
	baseCid cid.Cid,
	Selector ipld.Node) error

ValidatePush validates a push request received from the peer that will send data Will succeed only if: - voucher has correct type - voucher references an active deal - referenced deal matches the client - referenced deal matches the given base CID - referenced deal is in an acceptable state

Types

type PullDeals

type PullDeals interface {
	Get(cid.Cid) (storagemarket.ClientDeal, error)
}

PullDeals gets deal states for Pull validations

type PushDeals

type PushDeals interface {
	Get(cid.Cid) (storagemarket.MinerDeal, error)
}

PushDeals gets deal states for Push validations

type StorageDataTransferVoucher

type StorageDataTransferVoucher struct {
	Proposal cid.Cid
}

StorageDataTransferVoucher is the voucher type for data transfers used by the storage market

func (*StorageDataTransferVoucher) MarshalCBOR

func (t *StorageDataTransferVoucher) MarshalCBOR(w io.Writer) error

func (*StorageDataTransferVoucher) Type

Type is the unique string identifier for a StorageDataTransferVoucher

func (*StorageDataTransferVoucher) UnmarshalCBOR

func (t *StorageDataTransferVoucher) UnmarshalCBOR(r io.Reader) error

type UnifiedRequestValidator

type UnifiedRequestValidator struct {
	// contains filtered or unexported fields
}

UnifiedRequestValidator is a data transfer request validator that validates StorageDataTransferVoucher from the given state store It can be made to only accept push requests (Provider) or pull requests (Client) by passing nil for the statestore value for pushes or pulls

func NewUnifiedRequestValidator

func NewUnifiedRequestValidator(pushDeals PushDeals, pullDeals PullDeals) *UnifiedRequestValidator

NewUnifiedRequestValidator returns a new instance of UnifiedRequestValidator

func (*UnifiedRequestValidator) SetPullDeals

func (v *UnifiedRequestValidator) SetPullDeals(pullDeals PullDeals)

SetPullDeals sets the store to look up pull deals with

func (*UnifiedRequestValidator) SetPushDeals

func (v *UnifiedRequestValidator) SetPushDeals(pushDeals PushDeals)

SetPushDeals sets the store to look up push deals with

func (*UnifiedRequestValidator) ValidatePull

func (v *UnifiedRequestValidator) ValidatePull(receiver peer.ID, voucher datatransfer.Voucher, baseCid cid.Cid, selector ipld.Node) (datatransfer.VoucherResult, error)

ValidatePull implements the ValidatePull method of a data transfer request validator. If no pullStore exists, it rejects the request Otherwise, it calls the ValidatePull function to validate the deal

func (*UnifiedRequestValidator) ValidatePush

func (v *UnifiedRequestValidator) ValidatePush(sender peer.ID, voucher datatransfer.Voucher, baseCid cid.Cid, selector ipld.Node) (datatransfer.VoucherResult, error)

ValidatePush implements the ValidatePush method of a data transfer request validator. If no pushStore exists, it rejects the request Otherwise, it calls the ValidatePush function to validate the deal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL