task

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2023 License: Apache-2.0, MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Content

type Content struct {
	CID string `bson:"cid"`
}

type ErrorCode

type ErrorCode string
const (
	ErrorCodeNone                  ErrorCode = ""
	InvalidPeerID                  ErrorCode = "invalid_peerid"
	NoValidMultiAddrs              ErrorCode = "no_valid_multiaddrs"
	CannotConnect                  ErrorCode = "cannot_connect"
	NotFound                       ErrorCode = "not_found"
	RetrievalFailure               ErrorCode = "retrieval_failure"
	ProtocolNotSupported           ErrorCode = "protocol_not_supported"
	Timeout                        ErrorCode = "timeout"
	DealRejectedPricePerByteTooLow ErrorCode = "deal_rejected_price_per_byte_too_low"
	DealRejectedUnsealPriceTooLow  ErrorCode = "deal_rejected_unseal_price_too_low"
	Throttled                      ErrorCode = "throttled"
	NoAccess                       ErrorCode = "no_access"
	UnderMaintenance               ErrorCode = "under_maintenance"
	NotOnline                      ErrorCode = "not_online"
	UnconfirmedBlockTransfer       ErrorCode = "unconfirmed_block_transfer"
	CIDCodecNotSupported           ErrorCode = "cid_codec_not_supported"
	ResponseRejected               ErrorCode = "response_rejected"
	DealStateMissing               ErrorCode = "deal_state_missing"
)

type ModuleName

type ModuleName string
const (
	Stub      ModuleName = "stub"
	GraphSync ModuleName = "graphsync"
	HTTP      ModuleName = "http"
	Bitswap   ModuleName = "bitswap"
)

type Provider

type Provider struct {
	// In case of attempting retrieval from any miner, this field will be empty
	ID         string   `bson:"id"`
	PeerID     string   `bson:"peer_id,omitempty"`
	Multiaddrs []string `bson:"multiaddrs,omitempty"`
	City       string   `bson:"city,omitempty"`
	Region     string   `bson:"region,omitempty"`
	Country    string   `bson:"country,omitempty"`
	Continent  string   `bson:"continent,omitempty"`
}

func (Provider) GetPeerAddr

func (p Provider) GetPeerAddr() (peer.AddrInfo, error)

type Result

type Result struct {
	Task
	Retriever Retriever       `bson:"retriever"`
	Result    RetrievalResult `bson:"result"`
	CreatedAt time.Time       `bson:"created_at"`
}

type RetrievalResult

type RetrievalResult struct {
	Success      bool          `bson:"success"`
	ErrorCode    ErrorCode     `bson:"error_code,omitempty"`
	ErrorMessage string        `bson:"error_message,omitempty"`
	TTFB         time.Duration `bson:"ttfb,omitempty"`
	Speed        float64       `bson:"speed,omitempty"`
	Duration     time.Duration `bson:"duration,omitempty"`
	Downloaded   int64         `bson:"downloaded,omitempty"`
}

func NewErrorRetrievalResult

func NewErrorRetrievalResult(code ErrorCode, err error) *RetrievalResult

func NewErrorRetrievalResultWithErrorResolution

func NewErrorRetrievalResultWithErrorResolution(code ErrorCode, err error) *RetrievalResult

func NewSuccessfulRetrievalResult

func NewSuccessfulRetrievalResult(ttfb time.Duration, downloaded int64, duration time.Duration) *RetrievalResult

type Retriever

type Retriever struct {
	PublicIP  string  `bson:"ip"`
	City      string  `bson:"city"`
	Region    string  `bson:"region"`
	Country   string  `bson:"country"`
	Continent string  `bson:"continent"`
	ASN       string  `bson:"asn"`
	ISP       string  `bson:"isp"`
	Latitude  float32 `bson:"lat"`
	Longitude float32 `bson:"long"`
}

type Task

type Task struct {
	Requester string            `bson:"requester"`
	Module    ModuleName        `bson:"module"`
	Metadata  map[string]string `bson:"metadata,omitempty"`
	Provider  Provider          `bson:"provider"`
	Content   Content           `bson:"content"`
	Timeout   time.Duration     `bson:"timeout,omitempty"`
	CreatedAt time.Time         `bson:"created_at"`
}

type Worker

type Worker interface {
	DoWork(task Task) (*RetrievalResult, error)
}

type WorkerProcess

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

func NewTaskWorkerProcess

func NewTaskWorkerProcess(
	ctx context.Context,
	module ModuleName,
	worker Worker) (*WorkerProcess, error)

func (WorkerProcess) Close

func (t WorkerProcess) Close()

func (WorkerProcess) Poll

func (t WorkerProcess) Poll(ctx context.Context) error

Jump to

Keyboard shortcuts

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