Documentation
¶
Index ¶
- Constants
- Variables
- type AccountblockCallback
- type Broadcaster
- type Chain
- type Config
- type Fetcher
- type Filter
- type MsgHandler
- type MsgIder
- type Net
- type NodeInfo
- type Peer
- type PeerInfo
- type Receiver
- type Request
- type SnapshotBlockCallback
- type Subscriber
- type SyncState
- type SyncStateCallback
- type SyncStateFeed
- type SyncStatus
- type Syncer
- type Task
- type Verifier
- type ViteCmd
Constants ¶
View Source
const CmdSet = 2
View Source
const DefaultPort uint16 = 8484
View Source
const Vite = "vite"
@section Cmd
Variables ¶
View Source
var NULL_ADDRESS = types.Address{}
Functions ¶
This section is empty.
Types ¶
type AccountblockCallback ¶
type AccountblockCallback = func(addr types.Address, block *ledger.AccountBlock, source types.BlockSource)
type Broadcaster ¶
type Broadcaster interface {
BroadcastSnapshotBlock(block *ledger.SnapshotBlock)
BroadcastSnapshotBlocks(blocks []*ledger.SnapshotBlock)
BroadcastAccountBlock(block *ledger.AccountBlock)
BroadcastAccountBlocks(blocks []*ledger.AccountBlock)
}
@section Broadcaster
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)
// single
GetSnapshotBlockByHeight(height uint64) (*ledger.SnapshotBlock, error)
GetSnapshotBlockByHash(hash *types.Hash) (*ledger.SnapshotBlock, error)
// batcher
GetSnapshotBlocksByHash(origin *types.Hash, count uint64, forward, content bool) ([]*ledger.SnapshotBlock, error)
GetSnapshotBlocksByHeight(height, count uint64, forward, content bool) ([]*ledger.SnapshotBlock, error)
// single
GetAccountBlockByHash(blockHash *types.Hash) (*ledger.AccountBlock, error)
GetAccountBlockByHeight(addr *types.Address, height uint64) (*ledger.AccountBlock, error)
// batcher
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)
GetLatestSnapshotBlock() *ledger.SnapshotBlock
GetGenesisSnapshotBlock() *ledger.SnapshotBlock
Compressor() *compress.Compressor
}
all query include from block
type Fetcher ¶
type Fetcher interface {
FetchSnapshotBlocks(start types.Hash, count uint64)
// address is optional
FetchAccountBlocks(start types.Hash, count uint64, address *types.Address)
// add snapshot height
FetchAccountBlocksWithHeight(start types.Hash, count uint64, address *types.Address, sHeight uint64)
}
@section Broadcaster
type MsgHandler ¶
type Net ¶
type Net interface {
Syncer
Fetcher
Broadcaster
Receiver
Protocols() []*p2p.Protocol
Start(svr p2p.Server) error
Stop()
Info() *NodeInfo
Tasks() []*Task
AddPlugin(plugin p2p.Plugin)
}
@section Net
type Peer ¶
type Peer interface {
RemoteAddr() *net2.TCPAddr
FileAddress() *net2.TCPAddr
SetHead(head types.Hash, height uint64)
SeeBlock(hash types.Hash)
SendSnapshotBlocks(bs []*ledger.SnapshotBlock, msgId uint64) (err error)
SendAccountBlocks(bs []*ledger.AccountBlock, msgId uint64) (err error)
SendNewSnapshotBlock(b *ledger.SnapshotBlock) (err error)
SendNewAccountBlock(b *ledger.AccountBlock) (err error)
Send(code ViteCmd, msgId uint64, payload p2p.Serializable) (err error)
Report(err error)
ID() string
Height() uint64
Disconnect(reason p2p.DiscReason)
}
@section Peer for protocol handle, not p2p Peer. var errPeerTermed = errors.New("peer has been terminated")
type PeerInfo ¶
type PeerInfo struct {
ID string `json:"id"`
Addr string `json:"addr"`
Head string `json:"head"`
Height uint64 `json:"height"`
// MsgReceived uint64 `json:"msgReceived"`
// MsgHandled uint64 `json:"msgHandled"`
// MsgSend uint64 `json:"msgSend"`
// MsgDiscarded uint64 `json:"msgDiscarded"`
// MsgReceivedDetail map[string]uint64 `json:"msgReceived"`
// MsgDiscardedDetail map[string]uint64 `json:"msgDiscarded"`
// MsgHandledDetail map[string]uint64 `json:"msgHandledDetail"`
// MsgSendDetail map[string]uint64 `json:"msgSendDetail"`
Created string `json:"created"`
}
type Receiver ¶
type Receiver interface {
ReceiveSnapshotBlock(block *ledger.SnapshotBlock, sender Peer) (err error)
ReceiveAccountBlock(block *ledger.AccountBlock, sender Peer) (err error)
ReceiveSnapshotBlocks(blocks []*ledger.SnapshotBlock, sender Peer) (err error)
ReceiveAccountBlocks(blocks []*ledger.AccountBlock, sender Peer) (err error)
ReceiveNewSnapshotBlock(block *ledger.SnapshotBlock, sender Peer) (err error)
ReceiveNewAccountBlock(block *ledger.AccountBlock, sender Peer) (err error)
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)
// contains filtered or unexported methods
}
@section Receiver
type SnapshotBlockCallback ¶
type SnapshotBlockCallback = func(block *ledger.SnapshotBlock, source types.BlockSource)
@section Subscriber
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)
SyncState() SyncState
}
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 SyncStatus ¶
type Syncer ¶
type Syncer interface {
Status() *SyncStatus
SubscribeSyncStatus(fn SyncStateCallback) (subId int)
UnsubscribeSyncStatus(subId int)
SyncState() SyncState
}
@section Syncer
type Verifier ¶
type Verifier interface {
//VerifyforP2P(block *ledger.AccountBlock) bool
VerifyNetSb(block *ledger.SnapshotBlock) error
VerifyNetAb(block *ledger.AccountBlock) error
}
type ViteCmd ¶
const ( HandshakeCode ViteCmd = 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 NewAccountBlockCode ExceptionCode = 127 )
Source Files
¶
Click to show internal directories.
Click to hide internal directories.