Documentation ¶
Index ¶
- Constants
- func GetLogicClock() int64
- type BlockSyncer
- type BlockSyncerConfig
- type P2PManager
- func (pm *P2PManager) AddTransaction(tx *common.Transaction)
- func (pm *P2PManager) CheckAndCreateStream(ctx context.Context, h host.Host, p peer.AddrInfo)
- func (pm *P2PManager) Discover(ctx context.Context, h host.Host, dht *dht.IpfsDHT, rendezvous string)
- func (pm *P2PManager) GetBlockChain() *core.BlockChain
- func (pm *P2PManager) GetConnectNodeInfo() (string, []string)
- func (pm *P2PManager) HandleStream(s network.Stream)
- func (pm *P2PManager) NewPeer(peerId peer.ID, s *network.Stream, remoteAddr string) (*Peer, error)
- func (pm *P2PManager) SetSynced()
- func (pm *P2PManager) StatusMessage() *p2p.SyncStatusMsg
- func (pm *P2PManager) Synced() bool
- func (pm *P2PManager) TransactionUDP()
- func (pm *P2PManager) UDPGossipBroadcast(tx *common.Transaction)
- type P2PManagerConfig
- type Peer
- func (p *Peer) AsyncSendNewBlock(block *common.Block)
- func (p *Peer) AsyncSendNewBlockHash(blockHash common.Hash)
- func (p *Peer) AsyncSendTransaction(tx *common.Transaction)
- func (p *Peer) AsyncSendTxHash(txHash common.Hash)
- func (p *Peer) Handle()
- func (p *Peer) KnownBlock(blockHash string) bool
- func (p *Peer) KnownTransaction(txHash string) bool
- func (p *Peer) MarkBlock(blockHash string)
- func (p *Peer) MarkSynced() bool
- func (p *Peer) MarkTransaction(txHash string)
- func (p *Peer) SetMarkSynced(v bool)
- func (p *Peer) Stopped() bool
- type PeerConfig
- type SyncStatus
- type TimeSyncer
Constants ¶
View Source
const ( NetworkRendezvous = "chronos" TxGossipTopic = "/chronos/1.0.1/transactions" BlockGossipTopic = "/chronos/1.0.1/blocks" ProtocolId = protocol.ID("/chronos/1.0.0/p2p") TxProtocolId = protocol.ID("/chronos/1.0.0/transaction") )
Variables ¶
This section is empty.
Functions ¶
func GetLogicClock ¶
func GetLogicClock() int64
Types ¶
type BlockSyncer ¶
type BlockSyncer struct {
// contains filtered or unexported fields
}
func NewBlockSyncer ¶
func NewBlockSyncer(config *BlockSyncerConfig) *BlockSyncer
func (*BlockSyncer) AddPeer ¶
func (bs *BlockSyncer) AddPeer(p *Peer)
func (*BlockSyncer) Start ¶
func (bs *BlockSyncer) Start()
type BlockSyncerConfig ¶
type BlockSyncerConfig struct {
Chain *core.BlockChain
}
type P2PManager ¶
type P2PManager struct {
// contains filtered or unexported fields
}
func GetP2PManager ¶
func GetP2PManager() *P2PManager
func NewP2PManager ¶
func NewP2PManager(config *P2PManagerConfig) (*P2PManager, error)
func (*P2PManager) AddTransaction ¶
func (pm *P2PManager) AddTransaction(tx *common.Transaction)
AddTransaction 仅用于测试
func (*P2PManager) CheckAndCreateStream ¶
func (*P2PManager) Discover ¶
func (pm *P2PManager) Discover(ctx context.Context, h host.Host, dht *dht.IpfsDHT, rendezvous string)
Discover 基于 kademlia 协议发现其他节点
func (*P2PManager) GetBlockChain ¶
func (pm *P2PManager) GetBlockChain() *core.BlockChain
func (*P2PManager) GetConnectNodeInfo ¶
func (pm *P2PManager) GetConnectNodeInfo() (string, []string)
func (*P2PManager) HandleStream ¶
func (pm *P2PManager) HandleStream(s network.Stream)
HandleStream 用于在收到对端连接时候处理 stream, 在这里构建 peer 用于通信
func (*P2PManager) SetSynced ¶
func (pm *P2PManager) SetSynced()
func (*P2PManager) StatusMessage ¶
func (pm *P2PManager) StatusMessage() *p2p.SyncStatusMsg
StatusMessage 生成同步信息给对端
func (*P2PManager) Synced ¶
func (pm *P2PManager) Synced() bool
func (*P2PManager) TransactionUDP ¶
func (pm *P2PManager) TransactionUDP()
TransactionUDP 计划使用的交易广播独立网络,
func (*P2PManager) UDPGossipBroadcast ¶
func (pm *P2PManager) UDPGossipBroadcast(tx *common.Transaction)
type P2PManagerConfig ¶
type P2PManagerConfig struct { TxPool *core.TxPool // 交易池实例 Chain *core.BlockChain // 区块链实例 Genesis bool // 是否创世节点 InitialDelta int64 // 初始时间偏移,仅仅用于进行时间同步测试 }
P2PManagerConfig P2PManager 的实例化配置信息
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
func (*Peer) AsyncSendNewBlock ¶
func (*Peer) AsyncSendNewBlockHash ¶
func (*Peer) AsyncSendTransaction ¶
func (p *Peer) AsyncSendTransaction(tx *common.Transaction)
func (*Peer) AsyncSendTxHash ¶
func (*Peer) KnownBlock ¶
func (*Peer) KnownTransaction ¶
func (*Peer) MarkSynced ¶
func (*Peer) MarkTransaction ¶
func (*Peer) SetMarkSynced ¶
type PeerConfig ¶
type PeerConfig struct {
// contains filtered or unexported fields
}
type SyncStatus ¶
type SyncStatus int8
const ( INITIAL SyncStatus = 1 SYNCED SyncStatus = 2 CONFIRMING SyncStatus = 3 )
type TimeSyncer ¶
type TimeSyncer struct {
// contains filtered or unexported fields
}
func NewTimeSyncer ¶
func NewTimeSyncer(genesis bool, delta int64) *TimeSyncer
func (*TimeSyncer) GetLogicClock ¶
func (ts *TimeSyncer) GetLogicClock() int64
GetLogicClock 计算逻辑时钟 = 物理时钟 + 网络误差
func (*TimeSyncer) ProcessSyncRequest ¶
func (ts *TimeSyncer) ProcessSyncRequest(msg *p2p.TimeSyncMsg, p *Peer)
ProcessSyncRequest 处理时间同步请求消息
func (*TimeSyncer) ProcessSyncRespond ¶
func (ts *TimeSyncer) ProcessSyncRespond(msg *p2p.TimeSyncMsg, p *Peer)
Click to show internal directories.
Click to hide internal directories.