Documentation ¶
Index ¶
- Constants
- Variables
- func Disconnect(c MsgWriteCloser, err error) (e2 error)
- func PutVarint(buf []byte, n uint) (m byte)
- func Varint(buf []byte) (n uint)
- type AccountBlockCallback
- type AccountBlocks
- type BlockSubscriber
- type Broadcaster
- type Chain
- type Chunk
- type ChunkReader
- type Chunks
- type Code
- type Codec
- type CodecFactory
- type Connector
- type Consensus
- type DownloaderStatus
- type Exception
- type Fetcher
- type FilePoolStatus
- type FileServerStatus
- type GetAccountBlocks
- type GetHashHeightList
- type GetSnapshotBlocks
- type HandshakeMsg
- type HashHeightPoint
- type HashHeightPointList
- type IrreversibleReader
- type MockCodec
- func (m *MockCodec) Address() _net.Addr
- func (m *MockCodec) Close() error
- func (m *MockCodec) ReadMsg() (msg Msg, err error)
- func (m *MockCodec) SetReadTimeout(timeout time.Duration)
- func (m *MockCodec) SetTimeout(timeout time.Duration)
- func (m *MockCodec) SetWriteTimeout(timeout time.Duration)
- func (m *MockCodec) WriteMsg(msg Msg) (err error)
- type Msg
- type MsgId
- type MsgIder
- type MsgReadWriter
- type MsgReader
- type MsgWriteCloser
- type MsgWriter
- type Net
- type NewAccountBlock
- type NewSnapshotBlock
- type NodeInfo
- type Peer
- type PeerError
- type PeerFlag
- type PeerInfo
- type PeerManager
- type Serializable
- type SnapshotBlockCallback
- type SnapshotBlocks
- type Subscriber
- type SyncConnectionStatus
- type SyncDetail
- type SyncState
- type SyncStateCallback
- type SyncStateSubscriber
- type SyncStatus
- type Syncer
- type Verifier
Examples ¶
Constants ¶
const DBDirName = "db"
Variables ¶
Functions ¶
func Disconnect ¶
func Disconnect(c MsgWriteCloser, err error) (e2 error)
Types ¶
type AccountBlockCallback ¶
type AccountBlockCallback = func(addr types.Address, block *ledger.AccountBlock, source types.BlockSource)
AccountBlockCallback will be invoked when receive a block, source mark where the block come from: broadcast, sync or fetch
type AccountBlocks ¶
type AccountBlocks struct { Blocks []*ledger.AccountBlock TTL int32 }
AccountBlocks is batch of account blocks
func (*AccountBlocks) Deserialize ¶
func (a *AccountBlocks) Deserialize(buf []byte) error
func (*AccountBlocks) Serialize ¶
func (a *AccountBlocks) Serialize() ([]byte, error)
func (*AccountBlocks) String ¶
func (a *AccountBlocks) String() string
type BlockSubscriber ¶
type BlockSubscriber interface { // SubscribeAccountBlock return the subId, always larger than 0, use to unsubscribe SubscribeAccountBlock(fn AccountBlockCallback) (subId int) // UnsubscribeAccountBlock if subId is 0, then ignore UnsubscribeAccountBlock(subId int) // SubscribeSnapshotBlock return the subId, always larger than 0, use to unsubscribe SubscribeSnapshotBlock(fn SnapshotBlockCallback) (subId int) // UnsubscribeSnapshotBlock if subId is 0, then ignore UnsubscribeSnapshotBlock(subId int) }
A BlockSubscriber implementation can be subscribed and Unsubscribed, when got chain block, should notify subscribers
type Broadcaster ¶
type Broadcaster interface { BroadcastSnapshotBlock(block *ledger.SnapshotBlock) BroadcastSnapshotBlocks(blocks []*ledger.SnapshotBlock) BroadcastAccountBlock(block *ledger.AccountBlock) BroadcastAccountBlocks(blocks []*ledger.AccountBlock) }
A Broadcaster implementation can send blocks to the peers connected
type Chain ¶
type Chain interface {
// contains filtered or unexported methods
}
type Chunk ¶
type Chunk struct { SnapshotChunks []ledger.SnapshotChunk SnapshotRange [2]*ledger.HashHeight AccountRange map[types.Address][2]*ledger.HashHeight HashMap map[types.Hash]struct{} Source types.BlockSource // contains filtered or unexported fields }
Chunk means a chain chunk, contains snapshot blocks and dependent account blocks, SnapshotRange means the chunk range, the first HashHeight is the prevHash and prevHeight. eg. Chunk is from 101 to 200, SnapshotChunks is [101 ... 200], but SnapshotRange is [100, 200]. AccountRange like SnapshotRange but describe every account chain. HashMap record all blocks hash in Chunk, it can quickly tell if a block is in the chunk.
type Code ¶
type Code = byte
const ( CodeDisconnect Code = 1 CodeHandshake Code = 2 CodeControlFlow Code = 3 CodeHeartBeat Code = 4 CodeGetHashList Code = 25 CodeHashList Code = 26 CodeGetSnapshotBlocks Code = 27 CodeSnapshotBlocks Code = 28 CodeGetAccountBlocks Code = 29 CodeAccountBlocks Code = 30 CodeNewSnapshotBlock Code = 31 CodeNewAccountBlock Code = 32 CodeSyncHandshake Code = 60 CodeSyncHandshakeOK Code = 61 CodeSyncRequest Code = 62 CodeSyncReady Code = 63 CodeException Code = 127 CodeTrace Code = 128 )
type Codec ¶
type Codec interface { MsgReadWriter Close() error SetReadTimeout(timeout time.Duration) SetWriteTimeout(timeout time.Duration) SetTimeout(timeout time.Duration) Address() _net.Addr }
Codec is an transport can encode messages to bytes, transmit bytes, then decode bytes to messages
type Consensus ¶
type DownloaderStatus ¶
type DownloaderStatus struct { Tasks []string `json:"tasks"` Connections []SyncConnectionStatus `json:"connections"` }
type Fetcher ¶
type Fetcher interface { FetchSnapshotBlocks(start types.Hash, count uint64) FetchSnapshotBlocksWithHeight(hash types.Hash, height uint64, count uint64) // FetchAccountBlocks address is optional FetchAccountBlocks(start types.Hash, count uint64, address *types.Address) // FetchAccountBlocksWithHeight add snapshot height FetchAccountBlocksWithHeight(start types.Hash, count uint64, address *types.Address, sHeight uint64) }
A Fetcher implementation can request the wanted blocks to peers
type FilePoolStatus ¶
type FilePoolStatus struct {
Connections []SyncConnectionStatus `json:"connections"`
}
type FileServerStatus ¶
type FileServerStatus struct {
Connections []SyncConnectionStatus `json:"connections"`
}
type GetAccountBlocks ¶
type GetAccountBlocks struct { Address types.Address From ledger.HashHeight Count uint64 Forward bool }
func (*GetAccountBlocks) Deserialize ¶
func (b *GetAccountBlocks) Deserialize(buf []byte) error
func (*GetAccountBlocks) Serialize ¶
func (b *GetAccountBlocks) Serialize() ([]byte, error)
func (*GetAccountBlocks) String ¶
func (b *GetAccountBlocks) String() string
type GetHashHeightList ¶
type GetHashHeightList struct { From []*ledger.HashHeight // from high to low Step uint64 To uint64 }
func (*GetHashHeightList) Deserialize ¶
func (c *GetHashHeightList) Deserialize(data []byte) (err error)
func (*GetHashHeightList) Serialize ¶
func (c *GetHashHeightList) Serialize() ([]byte, error)
type GetSnapshotBlocks ¶
type GetSnapshotBlocks struct { From ledger.HashHeight Count uint64 Forward bool }
func (*GetSnapshotBlocks) Deserialize ¶
func (b *GetSnapshotBlocks) Deserialize(buf []byte) error
func (*GetSnapshotBlocks) Serialize ¶
func (b *GetSnapshotBlocks) Serialize() ([]byte, error)
func (*GetSnapshotBlocks) String ¶
func (b *GetSnapshotBlocks) String() string
type HandshakeMsg ¶
type HandshakeMsg struct { Version int64 NetID int64 Name string ID vnode.NodeID Timestamp int64 Height uint64 Head types.Hash Genesis types.Hash Key ed25519.PublicKey // is producer Token []byte FileAddress []byte PublicAddress []byte }
func (*HandshakeMsg) Deserialize ¶
func (b *HandshakeMsg) Deserialize(data []byte) (err error)
func (*HandshakeMsg) Serialize ¶
func (b *HandshakeMsg) Serialize() (data []byte, err error)
type HashHeightPoint ¶
type HashHeightPoint struct { ledger.HashHeight Size uint64 }
func (*HashHeightPoint) DeProto ¶
func (p *HashHeightPoint) DeProto(pb *vitepb.HashHeightPoint) (err error)
func (*HashHeightPoint) Proto ¶
func (p *HashHeightPoint) Proto() *vitepb.HashHeightPoint
type HashHeightPointList ¶
type HashHeightPointList struct {
Points []*HashHeightPoint // from low to high
}
func (*HashHeightPointList) Deserialize ¶
func (c *HashHeightPointList) Deserialize(data []byte) (err error)
func (*HashHeightPointList) Serialize ¶
func (c *HashHeightPointList) Serialize() ([]byte, error)
type IrreversibleReader ¶
type IrreversibleReader interface {
GetIrreversibleBlock() *ledger.SnapshotBlock
}
type MockCodec ¶
type MockCodec struct {
// contains filtered or unexported fields
}
type Msg ¶
type Net ¶
type Net interface { Syncer Fetcher Broadcaster BlockSubscriber Start() error Stop() error Info() NodeInfo Nodes() []*vnode.Node PeerCount() int PeerKey() ed25519.PrivateKey }
type NewAccountBlock ¶
type NewAccountBlock struct { Block *ledger.AccountBlock TTL int32 }
NewAccountBlock is use to propagate block, stop propagate when TTL is decrease to zero
func (*NewAccountBlock) Deserialize ¶
func (b *NewAccountBlock) Deserialize(buf []byte) error
func (*NewAccountBlock) Serialize ¶
func (b *NewAccountBlock) Serialize() ([]byte, error)
type NewSnapshotBlock ¶
type NewSnapshotBlock struct { Block *ledger.SnapshotBlock TTL int32 }
NewSnapshotBlock is use to propagate block, stop propagate when TTL is decrease to zero
func (*NewSnapshotBlock) Deserialize ¶
func (b *NewSnapshotBlock) Deserialize(buf []byte) error
func (*NewSnapshotBlock) Serialize ¶
func (b *NewSnapshotBlock) Serialize() ([]byte, error)
type NodeInfo ¶
type NodeInfo struct { ID vnode.NodeID `json:"id"` Name string `json:"name"` NetID int `json:"netId"` Version int `json:"version"` Address string `json:"address"` PeerCount int `json:"peerCount"` Peers []PeerInfo `json:"peers"` Height uint64 `json:"height"` Nodes int `json:"nodes"` Latency []int64 `json:"latency"` // [0,1,12,24] BroadCheckFailedRatio float32 `json:"broadCheckFailedRatio"` Server FileServerStatus `json:"server"` }
type Peer ¶
type PeerError ¶
type PeerError byte
const ( PeerNetworkError PeerError = iota // read/write timeout, read/write error PeerDifferentNetwork PeerTooManyPeers PeerTooManySameNetPeers PeerTooManyInboundPeers PeerAlreadyConnected PeerIncompatibleVersion PeerQuitting PeerNotHandshakeMsg PeerInvalidSignature PeerConnectSelf PeerUnknownMessage PeerUnmarshalError PeerNoPermission PeerBanned PeerDifferentGenesis PeerInvalidBlock PeerInvalidMessage PeerResponseTimeout PeerInvalidToken PeerUnknownReason PeerError = 255 )
type PeerInfo ¶
type PeerInfo struct { Id string `json:"id"` Name string `json:"name"` Version int64 `json:"version"` Height uint64 `json:"height"` Address string `json:"address"` Flag PeerFlag `json:"flag"` Superior bool `json:"superior"` Reliable bool `json:"reliable"` CreateAt string `json:"createAt"` ReadQueue int `json:"readQueue"` WriteQueue int `json:"writeQueue"` Peers []string `json:"peers"` }
PeerInfo is for api
type SnapshotBlockCallback ¶
type SnapshotBlockCallback = func(block *ledger.SnapshotBlock, source types.BlockSource)
SnapshotBlockCallback will be invoked when receive a block, source mark where the block come from: broadcast, sync or fetch
type SnapshotBlocks ¶
type SnapshotBlocks struct {
Blocks []*ledger.SnapshotBlock
}
SnapshotBlocks is batch of snapshot blocks
func (*SnapshotBlocks) Deserialize ¶
func (b *SnapshotBlocks) Deserialize(buf []byte) error
func (*SnapshotBlocks) Serialize ¶
func (b *SnapshotBlocks) Serialize() ([]byte, error)
func (*SnapshotBlocks) String ¶
func (b *SnapshotBlocks) String() string
type Subscriber ¶
type Subscriber interface { BlockSubscriber SyncStateSubscriber }
type SyncConnectionStatus ¶
type SyncDetail ¶
type SyncDetail struct { SyncStatus DownloaderStatus Chunks [][2]*ledger.HashHeight `json:"chunks"` Caches interfaces.SegmentList `json:"caches"` }
type SyncState ¶
type SyncState byte
type SyncStateCallback ¶
type SyncStateCallback = func(SyncState)
SyncStateCallback will be invoked when sync state change, the param is state after change
type SyncStateSubscriber ¶
type SyncStateSubscriber interface { // SubscribeSyncStatus return the subId, always larger than 0, use to unsubscribe SubscribeSyncStatus(fn SyncStateCallback) (subId int) // UnsubscribeSyncStatus if subId is 0, then ignore UnsubscribeSyncStatus(subId int) // SyncState return the latest sync state_bak SyncState() SyncState }
type SyncStatus ¶
type Syncer ¶
type Syncer interface { SyncStateSubscriber ChunkReader Status() SyncStatus Detail() SyncDetail }
A Syncer implementation can synchronise blocks to peers
type Verifier ¶
type Verifier interface { VerifyNetSnapshotBlock(block *ledger.SnapshotBlock) error VerifyNetAccountBlock(block *ledger.AccountBlock) error }
Source Files ¶
- block_feed.go
- broadcaster.go
- codec.go
- fetcher.go
- finder.go
- handshaker.go
- interface.go
- message.go
- mock_chain.go
- mock_codec.go
- mock_net.go
- mock_receiver.go
- msghandler.go
- net.go
- peer.go
- peer_error.go
- skeleton.go
- sync_cache_reader.go
- sync_conn.go
- sync_downloader.go
- sync_server.go
- sync_state.go
- syncer.go