bitswap

package
v0.18.0-rc22 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2024 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fetch

func Fetch(
	ctx context.Context,
	exchg exchange.Interface,
	root *share.AxisRoots,
	blks []Block,
	opts ...FetchOption,
) error

Fetch fetches and populates given Blocks using Fetcher wrapping Bitswap.

Validates Block against the given AxisRoots and skips Blocks that are already populated. Gracefully synchronize identical Blocks requested simultaneously. Blocks until either context is canceled or all Blocks are fetched and populated.

func ListActiveFetches

func ListActiveFetches() (keys []cid.Cid)

ListActiveFetches lists ongoing fetches. Useful for debugging.

func NewClient

func NewClient(
	ctx context.Context,
	net network.BitSwapNetwork,
	bstore blockstore.Blockstore,
) *client.Client

NewClient constructs a Bitswap client with parameters optimized for Shwap protocol composition. Meant to be used by Full and Light nodes.

func NewNetwork

func NewNetwork(host host.Host, prefix protocol.ID) network.BitSwapNetwork

NewNetwork constructs Bitswap network for Shwap protocol composition.

func NewServer

func NewServer(
	ctx context.Context,
	net network.BitSwapNetwork,
	bstore blockstore.Blockstore,
) *server.Server

NewServer construct a Bitswap server with parameters optimized for Shwap protocol composition. Meant to be used by Full nodes.

Types

type AccessorGetter

type AccessorGetter interface {
	// GetByHeight returns an Accessor by its height.
	GetByHeight(ctx context.Context, height uint64) (eds.AccessorStreamer, error)
	// HasByHeight reports whether an Accessor for the height exists.
	HasByHeight(ctx context.Context, height uint64) (bool, error)
}

AccessorGetter abstracts storage system that indexes and manages multiple eds.AccessorGetter by network height.

type Bitswap

type Bitswap struct {
	*client.Client
	*server.Server
}

func New

func (*Bitswap) Close

func (bs *Bitswap) Close() error

func (*Bitswap) NotifyNewBlocks

func (bs *Bitswap) NotifyNewBlocks(ctx context.Context, blks ...blocks.Block) error

type Block

type Block interface {
	// CID returns Shwap ID of the Block formatted as CID.
	CID() cid.Cid
	// Height reports the Height of the Shwap container behind the Block.
	Height() uint64

	// Populate fills up the Block with the Shwap container getting it out of the EDS
	// Accessor.
	Populate(context.Context, eds.Accessor) error
	// Marshal serializes bytes of the Shwap Container the Block holds.
	// MUST exclude the Shwap ID.
	Marshal() ([]byte, error)
	// UnmarshalFn returns closure that unmarshal the Block with the Shwap container.
	// Unmarshalling involves data validation against the given AxisRoots.
	UnmarshalFn(*share.AxisRoots) UnmarshalFn
}

Block represents Bitswap compatible generalization over Shwap containers. All Shwap containers must have a registered wrapper implementing the interface in order to be compatible with Bitswap. NOTE: This is not a Blockchain block, but an IPFS/Bitswap block.

func EmptyBlock

func EmptyBlock(cid cid.Cid) (Block, error)

EmptyBlock constructs an empty Block with type in the given CID.

type Blockstore

type Blockstore struct {
	Getter AccessorGetter
}

Blockstore implements generalized Bitswap compatible storage over Shwap containers that operates with Block and accesses data through AccessorGetter.

func (*Blockstore) AllKeysChan

func (b *Blockstore) AllKeysChan(context.Context) (<-chan cid.Cid, error)

func (*Blockstore) DeleteBlock

func (b *Blockstore) DeleteBlock(context.Context, cid.Cid) error

func (*Blockstore) Get

func (b *Blockstore) Get(ctx context.Context, cid cid.Cid) (blocks.Block, error)

func (*Blockstore) GetSize

func (b *Blockstore) GetSize(ctx context.Context, cid cid.Cid) (int, error)

func (*Blockstore) Has

func (b *Blockstore) Has(ctx context.Context, cid cid.Cid) (bool, error)

func (*Blockstore) HashOnRead

func (b *Blockstore) HashOnRead(bool)

func (*Blockstore) Put

func (*Blockstore) PutMany

func (b *Blockstore) PutMany(context.Context, []blocks.Block) error

type FetchOption

type FetchOption func(*fetchOptions)

func WithFetcher

func WithFetcher(session exchange.Fetcher) FetchOption

WithFetcher instructs Fetch to use the given Fetcher. Useful for reusable Fetcher sessions.

func WithStore

func WithStore(store blockstore.Blockstore) FetchOption

WithStore instructs Fetch to store all the fetched Blocks into the given Blockstore.

type Getter

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

Getter implements share.Getter.

func NewGetter

func NewGetter(
	exchange exchange.SessionExchange,
	bstore blockstore.Blockstore,
	availWndw pruner.AvailabilityWindow,
) *Getter

NewGetter constructs a new Getter.

func (*Getter) GetEDS

GetEDS uses RowBlock and Fetch to get half of the first EDS quadrant(ODS) and recomputes the whole EDS from it. We fetch the ODS or Q1 to ensure better compatibility with archival nodes that only store ODS and do not recompute other quadrants.

func (*Getter) GetShare

func (g *Getter) GetShare(
	ctx context.Context,
	hdr *header.ExtendedHeader,
	row, col int,
) (share.Share, error)

GetShare uses [GetShare] to fetch and verify single share by the given coordinates.

func (*Getter) GetShares

func (g *Getter) GetShares(
	ctx context.Context,
	hdr *header.ExtendedHeader,
	rowIdxs, colIdxs []int,
) ([]share.Share, error)

GetShares uses SampleBlock and Fetch to get and verify samples for given coordinates. TODO(@Wondertan): Rework API to get coordinates as a single param to make it ergonomic.

func (*Getter) GetSharesByNamespace

func (g *Getter) GetSharesByNamespace(
	ctx context.Context,
	hdr *header.ExtendedHeader,
	ns share.Namespace,
) (shwap.NamespaceData, error)

GetSharesByNamespace uses RowNamespaceDataBlock and Fetch to get all the data by the given namespace. If data spans over multiple rows, the request is split into parallel RowNamespaceDataID requests per each row and then assembled back into NamespaceData.

func (*Getter) Start

func (g *Getter) Start()

Start kicks off internal fetching sessions.

We keep Bitswap sessions for the whole Getter lifespan:

  • Sessions retain useful heuristics about peers, like TTFB
  • Sessions prefer peers that previously served us related content.

So reusing session is expected to improve fetching performance.

There are two sessions for archival and available data, so archival node peers aren't mixed with regular full node peers.

func (*Getter) Stop

func (g *Getter) Stop()

Stop shuts down Getter's internal fetching session.

type RowBlock

type RowBlock struct {
	ID shwap.RowID

	Container shwap.Row
}

RowBlock is a Bitswap compatible block for Shwap's Row container.

func EmptyRowBlockFromCID

func EmptyRowBlockFromCID(cid cid.Cid) (*RowBlock, error)

EmptyRowBlockFromCID constructs an empty RowBlock out of the CID.

func NewEmptyRowBlock

func NewEmptyRowBlock(height uint64, rowIdx, edsSize int) (*RowBlock, error)

NewEmptyRowBlock constructs a new empty RowBlock.

func (*RowBlock) CID

func (rb *RowBlock) CID() cid.Cid

func (*RowBlock) Height

func (rb *RowBlock) Height() uint64

func (*RowBlock) Marshal

func (rb *RowBlock) Marshal() ([]byte, error)

func (*RowBlock) Populate

func (rb *RowBlock) Populate(ctx context.Context, eds eds.Accessor) error

func (*RowBlock) UnmarshalFn

func (rb *RowBlock) UnmarshalFn(root *share.AxisRoots) UnmarshalFn

type RowNamespaceDataBlock

type RowNamespaceDataBlock struct {
	ID shwap.RowNamespaceDataID

	Container shwap.RowNamespaceData
}

RowNamespaceDataBlock is a Bitswap compatible block for Shwap's RowNamespaceData container.

func EmptyRowNamespaceDataBlockFromCID

func EmptyRowNamespaceDataBlockFromCID(cid cid.Cid) (*RowNamespaceDataBlock, error)

EmptyRowNamespaceDataBlockFromCID constructs an empty RowNamespaceDataBlock out of the CID.

func NewEmptyRowNamespaceDataBlock

func NewEmptyRowNamespaceDataBlock(
	height uint64,
	rowIdx int,
	namespace share.Namespace,
	edsSize int,
) (*RowNamespaceDataBlock, error)

NewEmptyRowNamespaceDataBlock constructs a new empty RowNamespaceDataBlock.

func (*RowNamespaceDataBlock) CID

func (rndb *RowNamespaceDataBlock) CID() cid.Cid

func (*RowNamespaceDataBlock) Height

func (rndb *RowNamespaceDataBlock) Height() uint64

func (*RowNamespaceDataBlock) Marshal

func (rndb *RowNamespaceDataBlock) Marshal() ([]byte, error)

func (*RowNamespaceDataBlock) Populate

func (rndb *RowNamespaceDataBlock) Populate(ctx context.Context, eds eds.Accessor) error

func (*RowNamespaceDataBlock) UnmarshalFn

func (rndb *RowNamespaceDataBlock) UnmarshalFn(root *share.AxisRoots) UnmarshalFn

type SampleBlock

type SampleBlock struct {
	ID        shwap.SampleID
	Container shwap.Sample
}

SampleBlock is a Bitswap compatible block for Shwap's Sample container.

func EmptySampleBlockFromCID

func EmptySampleBlockFromCID(cid cid.Cid) (*SampleBlock, error)

EmptySampleBlockFromCID constructs an empty SampleBlock out of the CID.

func NewEmptySampleBlock

func NewEmptySampleBlock(height uint64, rowIdx, colIdx, edsSize int) (*SampleBlock, error)

NewEmptySampleBlock constructs a new empty SampleBlock.

func (*SampleBlock) CID

func (sb *SampleBlock) CID() cid.Cid

func (*SampleBlock) Height

func (sb *SampleBlock) Height() uint64

func (*SampleBlock) Marshal

func (sb *SampleBlock) Marshal() ([]byte, error)

func (*SampleBlock) Populate

func (sb *SampleBlock) Populate(ctx context.Context, eds eds.Accessor) error

func (*SampleBlock) UnmarshalFn

func (sb *SampleBlock) UnmarshalFn(root *share.AxisRoots) UnmarshalFn

type UnmarshalFn

type UnmarshalFn func(container, id []byte) error

UnmarshalFn is a closure produced by a Block that unmarshalls and validates the given serialized bytes of a Shwap container with ID and populates the Block with it on success.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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