netsync

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2018 License: AGPL-3.0 Imports: 25 Imported by: 8 modules, 11 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	BlockRequestByte   = byte(0x10)
	BlockResponseByte  = byte(0x11)
	StatusRequestByte  = byte(0x20)
	StatusResponseByte = byte(0x21)
	NewTransactionByte = byte(0x30)
	NewMineBlockByte   = byte(0x40)
)

protocol msg

View Source
const (
	// BlockchainChannel is a channel for blocks and status updates
	BlockchainChannel = byte(0x40)
)

Variables

View Source
var (
	//ErrProtocolHandshakeTimeout peers handshake timeout
	ErrProtocolHandshakeTimeout = errors.New("Protocol handshake timeout")
)

Functions

This section is empty.

Types

type BlockRequestMessage

type BlockRequestMessage struct {
	Height  uint64
	RawHash [32]byte
}

BlockRequestMessage request blocks from remote peers by height/hash

func (*BlockRequestMessage) GetHash

func (m *BlockRequestMessage) GetHash() *bc.Hash

GetHash get hash

func (*BlockRequestMessage) String

func (m *BlockRequestMessage) String() string

String convert msg to string

type BlockResponseMessage

type BlockResponseMessage struct {
	RawBlock []byte
}

BlockResponseMessage response get block msg

func NewBlockResponseMessage

func NewBlockResponseMessage(block *types.Block) (*BlockResponseMessage, error)

NewBlockResponseMessage construct bock response msg

func (*BlockResponseMessage) GetBlock

func (m *BlockResponseMessage) GetBlock() *types.Block

GetBlock get block from msg

func (*BlockResponseMessage) String

func (m *BlockResponseMessage) String() string

String convert msg to string

type BlockchainMessage

type BlockchainMessage interface{}

BlockchainMessage is a generic message for this reactor.

func DecodeMessage

func DecodeMessage(bz []byte) (msgType byte, msg BlockchainMessage, err error)

DecodeMessage decode msg

type Fetcher

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

Fetcher is responsible for accumulating block announcements from various peers and scheduling them for retrieval.

func NewFetcher

func NewFetcher(chain *core.Chain, sw *p2p.Switch, peers *peerSet) *Fetcher

NewFetcher New creates a block fetcher to retrieve blocks of the new mined.

func (*Fetcher) Enqueue

func (f *Fetcher) Enqueue(peer string, block *types.Block) error

Enqueue tries to fill gaps the the fetcher's future import queue.

func (*Fetcher) Start

func (f *Fetcher) Start()

Start boots up the announcement based synchroniser, accepting and processing hash notifications and block fetches until termination requested.

func (*Fetcher) Stop

func (f *Fetcher) Stop()

Stop terminates the announcement based synchroniser, canceling all pending operations.

type MineBlockMessage

type MineBlockMessage struct {
	RawBlock []byte
}

MineBlockMessage new mined block msg

func NewMinedBlockMessage

func NewMinedBlockMessage(block *types.Block) (*MineBlockMessage, error)

NewMinedBlockMessage construct new mined block msg

func (*MineBlockMessage) GetMineBlock

func (m *MineBlockMessage) GetMineBlock() (*types.Block, error)

GetMineBlock get mine block from msg

func (*MineBlockMessage) String

func (m *MineBlockMessage) String() string

String convert msg to string

type ProtocolReactor

type ProtocolReactor struct {
	p2p.BaseReactor
	// contains filtered or unexported fields
}

ProtocolReactor handles new coming protocol message.

func NewProtocolReactor

func NewProtocolReactor(chain *protocol.Chain, txPool *protocol.TxPool, sw *p2p.Switch, blockPeer *blockKeeper, fetcher *Fetcher, peers *peerSet, newPeerCh chan struct{}, txSyncCh chan *txsync, quitReqBlockCh chan *string) *ProtocolReactor

NewProtocolReactor returns the reactor of whole blockchain.

func (*ProtocolReactor) AddPeer

func (pr *ProtocolReactor) AddPeer(peer *p2p.Peer) error

AddPeer implements Reactor by sending our state to peer.

func (*ProtocolReactor) GetChannels

func (pr *ProtocolReactor) GetChannels() []*p2p.ChannelDescriptor

GetChannels implements Reactor

func (*ProtocolReactor) OnStart

func (pr *ProtocolReactor) OnStart() error

OnStart implements BaseService

func (*ProtocolReactor) OnStop

func (pr *ProtocolReactor) OnStop()

OnStop implements BaseService

func (*ProtocolReactor) Receive

func (pr *ProtocolReactor) Receive(chID byte, src *p2p.Peer, msgBytes []byte)

Receive implements Reactor by handling 4 types of messages (look below).

func (*ProtocolReactor) RemovePeer

func (pr *ProtocolReactor) RemovePeer(peer *p2p.Peer, reason interface{})

RemovePeer implements Reactor by removing peer from the pool.

type Response

type Response struct {
	Status string      `json:"status,omitempty"`
	Msg    string      `json:"msg,omitempty"`
	Data   interface{} `json:"data,omitempty"`
}

Response describes the response standard.

type StatusRequestMessage

type StatusRequestMessage struct{}

StatusRequestMessage status request msg

func (*StatusRequestMessage) String

func (m *StatusRequestMessage) String() string

String

type StatusResponseMessage

type StatusResponseMessage struct {
	Height  uint64
	RawHash [32]byte
}

StatusResponseMessage get status response msg

func NewStatusResponseMessage

func NewStatusResponseMessage(blockHeader *types.BlockHeader) *StatusResponseMessage

NewStatusResponseMessage construct get status response msg

func (*StatusResponseMessage) GetHash

func (m *StatusResponseMessage) GetHash() *bc.Hash

GetHash get hash from msg

func (*StatusResponseMessage) String

func (m *StatusResponseMessage) String() string

String convert msg to string

type SyncManager

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

SyncManager Sync Manager is responsible for the business layer information synchronization

func NewSyncManager

func NewSyncManager(config *cfg.Config, chain *core.Chain, txPool *core.TxPool, newBlockCh chan *bc.Hash) (*SyncManager, error)

NewSyncManager create a sync manager

func (*SyncManager) BlockKeeper

func (sm *SyncManager) BlockKeeper() *blockKeeper

BlockKeeper get block keeper

func (*SyncManager) DialSeeds

func (sm *SyncManager) DialSeeds(seeds []string) error

DialSeeds dial seed peers

func (*SyncManager) NodeInfo

func (sm *SyncManager) NodeInfo() *p2p.NodeInfo

NodeInfo get P2P peer node info

func (*SyncManager) Peers

func (sm *SyncManager) Peers() *peerSet

Peers get sync manager peer set

func (*SyncManager) Start

func (sm *SyncManager) Start()

Start start sync manager service

func (*SyncManager) Stop

func (sm *SyncManager) Stop()

Stop stop sync manager

func (*SyncManager) Switch

func (sm *SyncManager) Switch() *p2p.Switch

Switch get sync manager switch

type TransactionNotifyMessage

type TransactionNotifyMessage struct {
	RawTx []byte
}

TransactionNotifyMessage notify new tx msg

func NewTransactionNotifyMessage

func NewTransactionNotifyMessage(tx *types.Tx) (*TransactionNotifyMessage, error)

NewTransactionNotifyMessage construct notify new tx msg

func (*TransactionNotifyMessage) GetTransaction

func (m *TransactionNotifyMessage) GetTransaction() (*types.Tx, error)

GetTransaction get tx from msg

func (*TransactionNotifyMessage) String

func (m *TransactionNotifyMessage) String() string

String

Jump to

Keyboard shortcuts

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