fetch

package
v0.2.0-rc5 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2021 License: MIT Imports: 14 Imported by: 1

Documentation

Overview

Package fetch contains mechanism to fetch Data from remote peers

Index

Constants

View Source
const (
	// Low will perform batched calls
	Low priority = 0
	// High will call fetch immediately
	High priority = 1
)

Message priority constants

Variables

View Source
var ErrExceedMaxRetries = errors.New("fetch failed after max retries for request")

ErrExceedMaxRetries is returned when MaxRetriesForRequest attempts has been made to fetch data for a hash and failed

Functions

func GetRandomPeer

func GetRandomPeer(peers []peers.Peer) peers.Peer

GetRandomPeer returns a random peer from current peer list

Types

type Config

type Config struct {
	BatchTimeout         int // in milliseconds
	MaxRetriesForPeer    int
	BatchSize            int
	RequestTimeout       int // in seconds
	MaxRetriesForRequest int
}

Config is the configuration file of the Fetch component

func DefaultConfig added in v1.0.0

func DefaultConfig() Config

DefaultConfig is the default config for the fetch component

type ErrCouldNotSend

type ErrCouldNotSend error

ErrCouldNotSend is a special type of error indicating fetch could not be done because message could not be sent to peers

type Fetch

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

Fetch is the main struct that contains network peers and logic to batch and dispatch hash fetch requests

func NewFetch

func NewFetch(ctx context.Context, cfg Config, network service.Service, logger log.Log) *Fetch

NewFetch creates a new Fetch struct

func (*Fetch) AddDB

func (f *Fetch) AddDB(hint Hint, db database.Getter)

AddDB adds a DB with corresponding hint all network peersProvider will be able to query this DB

func (*Fetch) FetchRequestHandler

func (f *Fetch) FetchRequestHandler(ctx context.Context, data []byte) ([]byte, error)

FetchRequestHandler handles requests for sync from peersProvider, and basically reads Data from database and puts it in a response batch

func (*Fetch) GetHash

func (f *Fetch) GetHash(hash types.Hash32, h Hint, validateHash bool) chan HashDataPromiseResult

GetHash is the regular buffered call to get a specific hash, using provided hash, h as hint the receiving end will know where to look for the hash, this function returns HashDataPromiseResult channel that will hold Data received or error

func (*Fetch) GetHashes

func (f *Fetch) GetHashes(hashes []types.Hash32, hint Hint, validateHash bool) map[types.Hash32]chan HashDataPromiseResult

GetHashes gets a list of hashes to be fetched and will return a map of hashes and their respective promise channels

func (*Fetch) Start

func (f *Fetch) Start()

Start starts handling fetch requests

func (*Fetch) Stop

func (f *Fetch) Stop()

Stop stops handling fetch requests

type Fetcher

type Fetcher interface {
	GetHash(hash types.Hash32, h Hint, validateHash bool) chan HashDataPromiseResult
	GetHashes(hash []types.Hash32, hint Hint, validateHash bool) map[types.Hash32]chan HashDataPromiseResult
	AddDB(hint Hint, db database.Getter)
	Stop()
	Start()
}

Fetcher is the general interface of the fetching unit, capable of requesting bytes that corresponds to a hash from other remote peers.

type HashDataPromiseResult

type HashDataPromiseResult struct {
	Err     error
	Hash    types.Hash32
	Data    []byte
	IsLocal bool
}

HashDataPromiseResult is the result strict when requesting Data corresponding to the Hash

type Hint

type Hint string

Hint marks which DB should be queried for a certain provided hash

const (
	BlockDB Hint = "blocksDB"
	ATXDB   Hint = "ATXDB"
	TXDB    Hint = "TXDB"
	POETDB  Hint = "POETDB"
	IVDB    Hint = "IVDB"
	TBDB    Hint = "TBDB"
)

DB hints per DB

type MessageNetwork

type MessageNetwork struct {
	*server.MessageServer

	log.Log
	// contains filtered or unexported fields
}

MessageNetwork is a network interface that allows fetch to communicate with other nodes with 'fetch servers'

func NewMessageNetwork

func NewMessageNetwork(ctx context.Context, requestTimeOut int, net service.Service, protocol string, log log.Log) *MessageNetwork

NewMessageNetwork creates a new instance of the fetch network server

func (MessageNetwork) Close

func (mn MessageNetwork) Close()

Close closes the message network

func (MessageNetwork) GetPeers

func (mn MessageNetwork) GetPeers() []peers.Peer

GetPeers return active peers

Jump to

Keyboard shortcuts

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