mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-12 01:10:36 +00:00
abb4da9cbd
[peermgr] - Add request cache with tests - Add requestCache to peermgr - refactored peer manager tests - Added blockInfo struct, to allow sorting on the blockIndex - added helper methods for cache, pickItem, pickFirstItem, removeHash, findHash and refactored tests - renamed requestcache to blockcache - refactored peer manager to use block cache for block requests *only* - added blockCallPeer function to handle block requests only - refactored onDisconnect to add back any pending peer requests that the disconnected peer did not complete into the peer manager queue [peermgr/server] - Modify onBlock handler in server, to send peermgr a BlockInfo struct [peermgr/syncmgr/server] - Modified blockIndex in BlockInfo to be uint32 and not uint64 - RequestBlocks in syncmgr now takes an index along with the hash - modified syncmgr code to pass index along with hash in all methods
47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
package syncmgr
|
|
|
|
import (
|
|
"github.com/CityOfZion/neo-go/pkg/wire/payload"
|
|
"github.com/CityOfZion/neo-go/pkg/wire/util"
|
|
)
|
|
|
|
// Config is the configuration file for the sync manager
|
|
type Config struct {
|
|
|
|
// Chain functions
|
|
ProcessBlock func(block payload.Block) error
|
|
ProcessHeaders func(hdrs []*payload.BlockBase) error
|
|
|
|
// RequestHeaders will send a getHeaders request
|
|
// with the hash passed in as a parameter
|
|
RequestHeaders func(hash util.Uint256) error
|
|
|
|
//RequestBlock will send a getdata request for the block
|
|
// with the hash passed as a parameter
|
|
RequestBlock func(hash util.Uint256, index uint32) error
|
|
|
|
// GetNextBlockHash returns the block hash of the header infront of thr block
|
|
// at the tip of this nodes chain. This assumes that the node is not in sync
|
|
GetNextBlockHash func() (util.Uint256, error)
|
|
|
|
// GetBestBlockHash gets the block hash of the last saved block.
|
|
GetBestBlockHash func() (util.Uint256, error)
|
|
|
|
// AskForNewBlocks will send out a message to the network
|
|
// asking for new blocks
|
|
AskForNewBlocks func()
|
|
|
|
// FetchHeadersAgain is called when a peer has provided headers that have not
|
|
// validated properly. We pass in the hash of the first header
|
|
FetchHeadersAgain func(util.Uint256) error
|
|
|
|
// FetchHeadersAgain is called when a peer has provided a block that has not
|
|
// validated properly. We pass in the hash of the block
|
|
FetchBlockAgain func(util.Uint256) error
|
|
}
|
|
|
|
// SyncPeer represents a peer on the network
|
|
// that this node can sync with
|
|
type SyncPeer interface {
|
|
Height() uint32
|
|
}
|