Documentation ¶
Index ¶
- Constants
- Variables
- func NewPeerSet() *peerSet
- type AccountblockCallback
- type Broadcaster
- type Chain
- type Config
- type Fetcher
- type Filter
- type MsgHandler
- type Net
- func (n *Net) AddHandler(handler MsgHandler)
- func (n *Net) BroadcastAccountBlock(addr types.Address, block *ledger.AccountBlock)
- func (n *Net) BroadcastAccountBlocks(addr types.Address, blocks []*ledger.AccountBlock)
- func (n *Net) BroadcastSnapshotBlock(block *ledger.SnapshotBlock)
- func (n *Net) FetchAccountBlocks(start types.Hash, count uint64, address *types.Address)
- func (n *Net) FetchSnapshotBlocks(start uint64, count uint64, hash *types.Hash)
- func (n *Net) HandlePeer(p *Peer) error
- func (n *Net) Status() *NetStatus
- func (n *Net) Stop()
- func (n *Net) SubscribeAccountBlock(fn AccountblockCallback) (subId int)
- func (n *Net) SubscribeSnapshotBlock(fn SnapshotBlockCallback) (subId int)
- func (n *Net) SubscribeSyncStatus(fn func(SyncState)) (subId int)
- func (n *Net) SyncState() SyncState
- func (n *Net) Syncing() bool
- func (n *Net) UnsubscribeAccountBlock(subId int)
- func (n *Net) UnsubscribeSnapshotBlock(subId int)
- func (n *Net) UnsubscribeSyncStatus(subId int)
- type NetStatus
- type Peer
- func (p *Peer) FileAddress() *net.TCPAddr
- func (p *Peer) Handshake(our *message.HandShake) error
- func (p *Peer) Info() *PeerInfo
- func (p *Peer) ReadHandshake() (their *message.HandShake, err error)
- func (p *Peer) SeeBlock(hash types.Hash)
- func (p *Peer) Send(code cmd, msgId uint64, payload p2p.Serializable) error
- func (p *Peer) SendAccountBlocks(s *message.AccountBlocks, msgId uint64) (err error)
- func (p *Peer) SendNewSnapshotBlock(b *ledger.SnapshotBlock) (err error)
- func (p *Peer) SendSnapshotBlocks(bs []*ledger.SnapshotBlock, msgId uint64) (err error)
- func (p *Peer) SendSubLedger(s *message.SubLedger, msgId uint64) (err error)
- func (p *Peer) SetHead(head types.Hash, height uint64)
- type PeerInfo
- type Peers
- type Receiver
- type Request
- type RequestPool
- type SnapshotBlockCallback
- type Subscriber
- type SyncState
- type SyncStateCallback
- type SyncStateFeed
- type Verifier
Constants ¶
View Source
const ( HandshakeCode cmd = iota StatusCode ForkCode // tell peer it has forked, use for respond GetSnapshotBlocksCode GetSubLedgerCode GetSnapshotBlocksCode // get snapshotblocks without content GetSnapshotBlocksContentCode GetFullSnapshotBlocksCode // get snapshotblocks with content GetSnapshotBlocksByHashCode // a batch of hash GetSnapshotBlocksContentByHashCode GetFullSnapshotBlocksByHashCode GetAccountBlocksCode // query single AccountChain GetMultiAccountBlocksCode // query multi AccountChain GetAccountBlocksByHashCode // query accountBlocks by hashList GetFilesCode GetChunkCode SubLedgerCode FileListCode SnapshotBlocksCode SnapshotBlocksContentCode FullSnapshotBlocksCode AccountBlocksCode NewSnapshotBlockCode ExceptionCode = 127 )
View Source
const CmdSet = 2
View Source
const CmdSetName = "vite"
@section Cmd
View Source
const INIT_ID uint64 = 1
@section requestPool
Variables ¶
View Source
var NULL_ADDRESS = types.Address{}
Functions ¶
func NewPeerSet ¶
func NewPeerSet() *peerSet
Types ¶
type AccountblockCallback ¶
type AccountblockCallback func(addr types.Address, block *ledger.AccountBlock)
type Broadcaster ¶
type Broadcaster interface { BroadcastSnapshotBlock(block *ledger.SnapshotBlock) BroadcastAccountBlock(addr types.Address, block *ledger.AccountBlock) BroadcastAccountBlocks(addr types.Address, blocks []*ledger.AccountBlock) }
type Chain ¶
type Chain interface { // the second return value mean chunk befor/after file GetSubLedgerByHeight(start, count uint64, forward bool) ([]*ledger.CompressedFileMeta, [][2]uint64) GetSubLedgerByHash(origin *types.Hash, count uint64, forward bool) ([]*ledger.CompressedFileMeta, [][2]uint64, error) // query chunk GetConfirmSubLedger(start, end uint64) ([]*ledger.SnapshotBlock, map[types.Address][]*ledger.AccountBlock, error) GetSnapshotBlocksByHash(origin *types.Hash, count uint64, forward, content bool) ([]*ledger.SnapshotBlock, error) GetSnapshotBlocksByHeight(height, count uint64, forward, content bool) ([]*ledger.SnapshotBlock, error) GetAccountBlocksByHash(addr types.Address, origin *types.Hash, count uint64, forward bool) ([]*ledger.AccountBlock, error) GetAccountBlocksByHeight(addr types.Address, start, count uint64, forward bool) ([]*ledger.AccountBlock, error) GetAccountBlockByHash(blockHash *types.Hash) (*ledger.AccountBlock, error) GetAccountBlockByHeight(addr *types.Address, height uint64) (*ledger.AccountBlock, error) GetLatestSnapshotBlock() *ledger.SnapshotBlock GetGenesisSnapshotBlock() *ledger.SnapshotBlock Compressor() *compress.Compressor }
all query include from block
type MsgHandler ¶
type Net ¶
type Net struct { *Config Protocols []*p2p.Protocol // mount to p2p.Server // contains filtered or unexported fields }
func (*Net) AddHandler ¶
func (n *Net) AddHandler(handler MsgHandler)
func (*Net) BroadcastAccountBlock ¶
func (n *Net) BroadcastAccountBlock(addr types.Address, block *ledger.AccountBlock)
func (*Net) BroadcastAccountBlocks ¶
func (n *Net) BroadcastAccountBlocks(addr types.Address, blocks []*ledger.AccountBlock)
func (*Net) BroadcastSnapshotBlock ¶
func (n *Net) BroadcastSnapshotBlock(block *ledger.SnapshotBlock)
func (*Net) FetchAccountBlocks ¶
func (*Net) FetchSnapshotBlocks ¶
func (*Net) HandlePeer ¶
will be called by p2p.Server, run as goroutine
func (*Net) SubscribeAccountBlock ¶
func (n *Net) SubscribeAccountBlock(fn AccountblockCallback) (subId int)
func (*Net) SubscribeSnapshotBlock ¶
func (n *Net) SubscribeSnapshotBlock(fn SnapshotBlockCallback) (subId int)
func (*Net) SubscribeSyncStatus ¶
func (*Net) UnsubscribeAccountBlock ¶
func (*Net) UnsubscribeSnapshotBlock ¶
func (*Net) UnsubscribeSyncStatus ¶
type Peer ¶
type Peer struct { *p2p.Peer ID string CmdSet uint64 // which cmdSet it belongs KnownBlocks *cuckoofilter.CuckooFilter Log log15.Logger // contains filtered or unexported fields }
func (*Peer) FileAddress ¶
func (*Peer) SendAccountBlocks ¶
func (p *Peer) SendAccountBlocks(s *message.AccountBlocks, msgId uint64) (err error)
func (*Peer) SendNewSnapshotBlock ¶
func (p *Peer) SendNewSnapshotBlock(b *ledger.SnapshotBlock) (err error)
func (*Peer) SendSnapshotBlocks ¶
func (p *Peer) SendSnapshotBlocks(bs []*ledger.SnapshotBlock, msgId uint64) (err error)
func (*Peer) SendSubLedger ¶
response
type Receiver ¶
type Receiver interface { ReceiveSnapshotBlocks(blocks []*ledger.SnapshotBlock) ReceiveAccountBlocks(mblocks map[types.Address][]*ledger.AccountBlock) ReceiveNewSnapshotBlock(block *ledger.SnapshotBlock) }
type RequestPool ¶
type SnapshotBlockCallback ¶
type SnapshotBlockCallback func(block *ledger.SnapshotBlock)
type Subscriber ¶
type Subscriber interface { // return the subId, use to unsubscibe // subId is always larger than 0 SubscribeAccountBlock(fn AccountblockCallback) (subId int) // if subId is 0, then ignore UnsubscribeAccountBlock(subId int) // return the subId, use to unsubscibe // subId is always larger than 0 SubscribeSnapshotBlock(fn SnapshotBlockCallback) (subId int) // if subId is 0, then ignore UnsubscribeSnapshotBlock(subId int) // return the subId, use to unsubscibe // subId is always larger than 0 SubscribeSyncStatus(fn SyncStateCallback) (subId int) // if subId is 0, then ignore UnsubscribeSyncStatus(subId int) }
type SyncStateCallback ¶
type SyncStateCallback func(SyncState)
type SyncStateFeed ¶
type SyncStateFeed struct {
// contains filtered or unexported fields
}
func (*SyncStateFeed) Notify ¶
func (s *SyncStateFeed) Notify(st SyncState)
func (*SyncStateFeed) Sub ¶
func (s *SyncStateFeed) Sub(fn SyncStateCallback) int
func (*SyncStateFeed) Unsub ¶
func (s *SyncStateFeed) Unsub(subId int)
type Verifier ¶
type Verifier interface {
VerifyforP2P(block *ledger.AccountBlock) bool
}
Source Files ¶
Click to show internal directories.
Click to hide internal directories.