node

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 27 Imported by: 0

Documentation

Index

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 (pm *P2PManager) CheckAndCreateStream(ctx context.Context, h host.Host,
	p peer.AddrInfo)

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) NewPeer

func (pm *P2PManager) NewPeer(peerId peer.ID, s *network.Stream,
	remoteAddr string) (*Peer,
	error)

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 NewPeer

func NewPeer(peerId peer.ID, s *network.Stream, config PeerConfig) (*Peer, error)

func (*Peer) AsyncSendNewBlock

func (p *Peer) AsyncSendNewBlock(block *common.Block)

func (*Peer) AsyncSendNewBlockHash

func (p *Peer) AsyncSendNewBlockHash(blockHash common.Hash)

func (*Peer) AsyncSendTransaction

func (p *Peer) AsyncSendTransaction(tx *common.Transaction)

func (*Peer) AsyncSendTxHash

func (p *Peer) AsyncSendTxHash(txHash common.Hash)

func (*Peer) Handle

func (p *Peer) Handle()

func (*Peer) KnownBlock

func (p *Peer) KnownBlock(blockHash string) bool

func (*Peer) KnownTransaction

func (p *Peer) KnownTransaction(txHash string) bool

func (*Peer) MarkBlock

func (p *Peer) MarkBlock(blockHash string)

func (*Peer) MarkSynced

func (p *Peer) MarkSynced() bool

func (*Peer) MarkTransaction

func (p *Peer) MarkTransaction(txHash string)

func (*Peer) SetMarkSynced

func (p *Peer) SetMarkSynced(v bool)

func (*Peer) Stopped

func (p *Peer) Stopped() bool

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)

func (*TimeSyncer) Start

func (ts *TimeSyncer) Start()

todo: 添加上下文

Jump to

Keyboard shortcuts

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