github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/network/blob_service.go (about)

     1  package network
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  
     7  	"github.com/ipfs/go-cid"
     8  
     9  	"github.com/onflow/flow-go/module/blobs"
    10  	"github.com/onflow/flow-go/module/component"
    11  )
    12  
    13  // BlobGetter is the common interface shared between blobservice sessions and
    14  // the blobservice.
    15  type BlobGetter interface {
    16  	// GetBlob gets the requested blob.
    17  	GetBlob(ctx context.Context, c cid.Cid) (blobs.Blob, error)
    18  
    19  	// GetBlobs does a batch request for the given cids, returning blobs as
    20  	// they are found, in no particular order.
    21  	//
    22  	// It may not be able to find all requested blobs (or the context may
    23  	// be canceled). In that case, it will close the channel early. It is up
    24  	// to the consumer to detect this situation and keep track which blobs
    25  	// it has received and which it hasn't.
    26  	GetBlobs(ctx context.Context, ks []cid.Cid) <-chan blobs.Blob
    27  }
    28  
    29  // BlobService is a hybrid blob datastore. It stores data in a local
    30  // datastore and may retrieve data from a remote Exchange.
    31  // It uses an internal `datastore.Datastore` instance to store values.
    32  type BlobService interface {
    33  	component.Component
    34  	BlobGetter
    35  
    36  	// AddBlob puts a given blob to the underlying datastore
    37  	AddBlob(ctx context.Context, b blobs.Blob) error
    38  
    39  	// AddBlobs adds a slice of blobs at the same time using batching
    40  	// capabilities of the underlying datastore whenever possible.
    41  	AddBlobs(ctx context.Context, bs []blobs.Blob) error
    42  
    43  	// DeleteBlob deletes the given blob from the blobservice.
    44  	DeleteBlob(ctx context.Context, c cid.Cid) error
    45  
    46  	// GetSession creates a new session that allows for controlled exchange of wantlists to decrease the bandwidth overhead.
    47  	GetSession(ctx context.Context) BlobGetter
    48  
    49  	// TriggerReprovide updates the BlobService's provider entries in the DHT
    50  	TriggerReprovide(ctx context.Context) error
    51  }
    52  
    53  type BlobServiceOption func(BlobService)
    54  
    55  var ErrBlobNotFound = errors.New("blobservice: key not found")