Version: v0.0.0-...-fbf2e05 Latest Latest

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

Go to latest
Published: Aug 11, 2021 License: BSD-3-Clause Imports: 28 Imported by: 0


Retrieval Manager

This module manages a trustless transfer of bytes between 2 parties. It is based on go-fil-markets implementation but does not require unsealing as the blocks are not sealed in storage sectors but ready to be delivered.

Basic flow

  1. Client calls stateMachines.begin with a new deal id and initial deal state

  2. Client sends an EventOpen to the state machine

  3. The state machine moves to StatusNew deal sending a deal Proposal voucher and a data transfer pull request.

  4. The Provider receives the voucher, runs some validation and sends back a response stating if they accept or not.

  5. If the deal status is accepted, the client will get or create a new channel adding the funds in anticipation of the whole transfer costs.

  6. The Client state machine will block until the payment channel is confirmed on chain

  7. Once the channel address is returned the state machine will call the payment manager to allocate and return a new lane number

  8. Meanwhile the provider resumes the data transfer and starts sending blocks until the given payment interval is reached and will request a payment to continue.

  9. The Client will create a new voucher for the requested payment, sign it and send to the provider. The provider will validate the voucher and if accepted send the next amount of bytes.




This section is empty.


This section is empty.


func DecodeNode

func DecodeNode(defnode *cbg.Deferred) (ipld.Node, error)

DecodeNode validates and computes a decoded ipld.Node selector from the provided cbor-encoded selector TODO: ipld sub module

func TransportConfigurer

func TransportConfigurer(thisPeer peer.ID, storeGetter StoreGetter) datatransfer.TransportConfigurer

TransportConfigurer configurers the graphsync transport to use a custom blockstore per deal


type Client

type Client struct {
	// contains filtered or unexported fields

Client wraps all the client operations

func (*Client) Retrieve

func (c *Client) Retrieve(
	ctx context.Context,
	root cid.Cid,
	params deal.Params,
	totalFunds abi.TokenAmount,
	sender peer.ID,
	clientAddr address.Address,
	providerAddr address.Address,
	storeID *multistore.StoreID,
) (deal.ID, error)

Retrieve content

func (*Client) SubscribeToEvents

func (c *Client) SubscribeToEvents(subscriber client.Subscriber) Unsubscribe

SubscribeToEvents to listen to transfer state changes on the client side

func (*Client) TryRestartInsufficientFunds

func (c *Client) TryRestartInsufficientFunds(chAddr address.Address) error

TryRestartInsufficientFunds attempts to restart any deals stuck in the insufficient funds state after funds are added to a given payment channel

type Manager

type Manager interface {
	Client() *Client
	Provider() *Provider

Manager handles all retrieval operations both as client and provider

func New

func New(
	ctx context.Context,
	ms *multistore.MultiStore,
	ds datastore.Batching,
	pay payments.Manager,
	dt datatransfer.Manager,
	offers OfferManager,
	self peer.ID,
) (Manager, error)

New creates a new retrieval instance

type OfferManager

type OfferManager interface {
	SetOfferForCid(cid.Cid, deal.Offer) error
	GetOfferForCid(cid.Cid) deal.Offer

OfferManager organizes and stores offers for authorizing retrieval deals

type Provider

type Provider struct {
	// contains filtered or unexported fields

Provider wraps all the provider operations

func (*Provider) SubscribeToEvents

func (p *Provider) SubscribeToEvents(subscriber provider.Subscriber) Unsubscribe

SubscribeToEvents to listen to transfer state changes on the provider side

type ProviderRequestValidator

type ProviderRequestValidator struct {
	// contains filtered or unexported fields

ProviderRequestValidator validates incoming requests for the Retrieval Provider

func NewProviderRequestValidator

func NewProviderRequestValidator(env ValidationEnvironment) *ProviderRequestValidator

NewProviderRequestValidator returns a new instance of the ProviderRequestValidator

func (*ProviderRequestValidator) ValidatePull

func (rv *ProviderRequestValidator) ValidatePull(isRestart bool, chid datatransfer.ChannelID, receiver peer.ID, voucher datatransfer.Voucher, baseCid cid.Cid, selector ipld.Node) (datatransfer.VoucherResult, error)

ValidatePull validates a pull request received from the peer that will receive data

func (*ProviderRequestValidator) ValidatePush

func (rv *ProviderRequestValidator) ValidatePush(isRestart bool, chid datatransfer.ChannelID, sender peer.ID, voucher datatransfer.Voucher, baseCid cid.Cid, selector ipld.Node) (datatransfer.VoucherResult, error)

ValidatePush validates a push request received from the peer that will send data

type ProviderRevalidator

type ProviderRevalidator struct {
	// contains filtered or unexported fields

ProviderRevalidator defines data transfer revalidation logic in the context of a provider for a retrieval deal

func NewProviderRevalidator

func NewProviderRevalidator(env RevalidatorEnvironment) *ProviderRevalidator

NewProviderRevalidator returns a new instance of a ProviderRevalidator

func (*ProviderRevalidator) OnComplete

OnComplete is called to make a final request for revalidation -- often for the purpose of settlement. if VoucherResult is non nil, the request will enter a settlement phase awaiting a final update

func (*ProviderRevalidator) OnPullDataSent

func (pr *ProviderRevalidator) OnPullDataSent(chid datatransfer.ChannelID, additionalBytesSent uint64) (bool, datatransfer.VoucherResult, error)

OnPullDataSent is called on the responder side when more bytes are sent for a given pull request. It should return a VoucherResult + ErrPause to request revalidation or nil to continue uninterrupted, other errors will terminate the request

func (*ProviderRevalidator) OnPushDataReceived

func (pr *ProviderRevalidator) OnPushDataReceived(chid datatransfer.ChannelID, additionalBytesReceived uint64) (bool, datatransfer.VoucherResult, error)

OnPushDataReceived is called on the responder side when more bytes are received for a given push request. It should return a VoucherResult + ErrPause to request revalidation or nil to continue uninterrupted, other errors will terminate the request

func (*ProviderRevalidator) Revalidate

Revalidate revalidates a request with a new voucher

func (*ProviderRevalidator) TrackChannel

func (pr *ProviderRevalidator) TrackChannel(d deal.ProviderState)

TrackChannel indicates a retrieval deal tracked by this provider. It associates a given channel ID with a retrieval deal, so that checks run for data sent on the channel

func (*ProviderRevalidator) UntrackChannel

func (pr *ProviderRevalidator) UntrackChannel(d deal.ProviderState)

UntrackChannel indicates a retrieval deal is finish and no longer is tracked by this provider

type Retrieval

type Retrieval struct {
	// contains filtered or unexported fields

Retrieval manager implementation

func (*Retrieval) Client

func (r *Retrieval) Client() *Client

Client to access our Retriever implementation

func (*Retrieval) Provider

func (r *Retrieval) Provider() *Provider

Provider to access our Provider implementation

type RevalidatorEnvironment

type RevalidatorEnvironment interface {
	Payments() payments.Manager
	SendEvent(dealID deal.ProviderDealIdentifier, evt provider.Event, args ...interface{}) error
	Get(dealID deal.ProviderDealIdentifier) (deal.ProviderState, error)

RevalidatorEnvironment are the dependencies needed to build the logic of revalidation -- essentially, access to the node at statemachines

type StoreConfigurableTransport

type StoreConfigurableTransport interface {
	UseStore(datatransfer.ChannelID, ipld.Loader, ipld.Storer) error

StoreConfigurableTransport defines the methods needed to configure a data transfer transport use a unique store for a given request

type StoreGetter

type StoreGetter interface {
	Get(otherPeer peer.ID, dealID deal.ID) (*multistore.Store, error)

StoreGetter retrieves the store for a given proposal cid

type StoreIDGetter

type StoreIDGetter interface {
	GetStoreID(cid.Cid) (multistore.StoreID, error)

StoreIDGetter is an interface required for finding the store associated with the content to provide

type Unsubscribe

type Unsubscribe func()

Unsubscribe is a function that unsubscribes a subscriber for either the client or the provider

func SettlePaymentChannels

func SettlePaymentChannels(ctx context.Context, pay payments.Manager, pro *Provider) Unsubscribe

SettlePaymentChannels subscribes to provider deals and tries to settle payments after any transfer gets into a final state

type ValidationEnvironment

type ValidationEnvironment interface {
	// CheckDealParams verifies the given deal params are acceptable
	CheckDealParams(deal.ProviderState) error
	// StateMachines returns the FSM Group to begin tracking with
	BeginTracking(pds deal.ProviderState) error
	// NextStoreID allocates a store for this deal
	NextStoreID() (multistore.StoreID, error)
	// GetStoreID gets an existing store for this deal
	GetStoreID(cid.Cid) (multistore.StoreID, error)

ValidationEnvironment contains the dependencies needed to validate deals


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL