cservmgr

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2022 License: Apache-2.0, MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Opts

type Opts struct {
	// The datastore path of the piece serving manager.
	Path string
}

Opts is the options for piece serving manager.

type PieceServingManager

type PieceServingManager interface {
	// Serve is used to serve a piece.
	//
	// @input - context, piece id, currency id, price-per-byte.
	//
	// @output - error.
	Serve(ctx context.Context, id cid.Cid, currencyID byte, ppb *big.Int) error

	// Stop is used to stop serving a piece.
	//
	// @input - context, piece id, currency id.
	//
	// @output - error.
	Stop(ctx context.Context, id cid.Cid, currencyID byte) error

	// Inspect is used to inspect a piece serving state.
	//
	// @input - context, piece id, currency id.
	//
	// @output - if served, price-per-byte, error.
	Inspect(ctx context.Context, id cid.Cid, currencyID byte) (bool, *big.Int, error)

	// ListPieceIDs lists all pieces.
	//
	// @input - context.
	//
	// @output - piece id chan out, error chan out.
	ListPieceIDs(ctx context.Context) (<-chan cid.Cid, <-chan error)

	// ListCurrencyIDs lists all currencies.
	//
	// @input - context, piece id.
	//
	// @output - currency chan out, error chan out.
	ListCurrencyIDs(ctx context.Context, id cid.Cid) (<-chan byte, <-chan error)

	// RegisterPublishHook adds a hook function to call when a new serving presents.
	//
	// @input - hook function.
	RegisterPublishFunc(hook func(cid.Cid))

	// DeregisterPublishHook deregister the hook function.
	DeregisterPublishHook()
}

PieceServingManager is the interface for a manager that manages all served pieces.

type PieceServingManagerImpl

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

PieceServingManagerImpl is the implementation of the PieceServingManager interface.

func NewPieceServingManager

func NewPieceServingManager(ctx context.Context, opts Opts) (*PieceServingManagerImpl, error)

NewPieceServingManager creates a new PieceServingManager.

@input - context, options.

@output - piece serving manager, error.

func (*PieceServingManagerImpl) DeregisterPublishHook

func (s *PieceServingManagerImpl) DeregisterPublishHook()

DeregisterPublishHook deregister the hook function.

func (*PieceServingManagerImpl) Inspect

func (s *PieceServingManagerImpl) Inspect(ctx context.Context, id cid.Cid, currencyID byte) (bool, *big.Int, error)

Inspect is used to inspect a piece serving state.

@input - context, piece id, currency id.

@output - if served, price-per-byte, error.

func (*PieceServingManagerImpl) ListCurrencyIDs

func (s *PieceServingManagerImpl) ListCurrencyIDs(ctx context.Context, id cid.Cid) (<-chan byte, <-chan error)

ListCurrencyIDs lists all currencies.

@input - context, piece id.

@output - currency chan out, error chan out.

func (*PieceServingManagerImpl) ListPieceIDs

func (s *PieceServingManagerImpl) ListPieceIDs(ctx context.Context) (<-chan cid.Cid, <-chan error)

ListPieceIDs lists all pieces.

@input - context.

@output - piece id chan out, error chan out.

func (*PieceServingManagerImpl) RegisterPublishFunc

func (s *PieceServingManagerImpl) RegisterPublishFunc(hook func(cid.Cid))

RegisterPublishHook adds a hook function to call when a new serving presents.

@input - hook function.

func (*PieceServingManagerImpl) Serve

func (s *PieceServingManagerImpl) Serve(ctx context.Context, id cid.Cid, currencyID byte, ppb *big.Int) error

Serve is used to serve a piece.

@input - context, piece id, currency id, price-per-byte.

@output - error.

func (*PieceServingManagerImpl) Shutdown

func (s *PieceServingManagerImpl) Shutdown()

Shutdown safely shuts down the component.

func (*PieceServingManagerImpl) Stop

func (s *PieceServingManagerImpl) Stop(ctx context.Context, id cid.Cid, currencyID byte) error

Stop is used to stop serving a piece.

@input - context, piece id, currency id.

@output - error.

Jump to

Keyboard shortcuts

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