Documentation ¶
Overview ¶
Package fetch contains mechanism to fetch data from remote peers
Index ¶
- Constants
- type Config
- type ErrCouldNotSend
- type Fetch
- func (f *Fetch) AddDB(hint Hint, db database.Database)
- func (f *Fetch) FetchRequestHandler(data []byte) []byte
- func (f *Fetch) GetHash(hash types.Hash32, h Hint, validateHash bool) chan HashDataPromiseResult
- func (f *Fetch) GetHashes(hashes []types.Hash32, hint Hint, validateHash bool) map[types.Hash32]chan HashDataPromiseResult
- func (f *Fetch) Start()
- func (f *Fetch) Stop()
- type Fetcher
- type HashDataPromiseResult
- type Hint
- type MessageNetwork
Constants ¶
const ( // Low will perform batched calls Low priority = 0 // High will call fetch immediately High priority = 1 )
Message priority constants
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { BatchTimeout int // in seconds MaxRetiresForPeer int BatchSize int RequestTimeout int // in seconds }
Config is the configuration file of 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 (*Fetch) AddDB ¶
AddDB adds a DB with corresponding hint all network peersProvider will be able to query this DB
func (*Fetch) FetchRequestHandler ¶
FetchRequestHandler handles requests for sync from peersProvider, and basically reads data from database and puts it in a response batch
func (*Fetch) GetHash ¶
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
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 }
Fetcher is the general interface of the fetching unit, capable of requesting bytes that corresponds to a hash from other remote peers.
type HashDataPromiseResult ¶
HashDataPromiseResult is the result strict when requesting data corresponding to the Hash
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(requestTimeOut int, net service.Service, protocol string, log log.Log) *MessageNetwork
NewMessageNetwork creates a new instance of the fetch network server
func (MessageNetwork) GetRandomPeer ¶
func (f MessageNetwork) GetRandomPeer() p2ppeers.Peer
GetRandomPeer returns a random peer from current peer list