區塊鏈教程Fabric1.0原始碼分析PeerBroadcastClient(Broadcas
阿新 • • 發佈:2018-11-07
區塊鏈教程Fabric1.0原始碼分析PeerBroadcastClient(Broadcast客戶端),2018年下半年,區塊鏈行業正逐漸褪去發展之初的浮躁、迴歸理性,表面上看相關人才需求與身價似乎正在回落。但事實上,正是初期泡沫的漸退,讓人們更多的關注點放在了區塊鏈真正的技術之上。
Fabric1.0原始碼筆記之Peer DeliverClient(Deliver客戶端)
1、DeliverClient概述
DeliverClient程式碼分佈如下:
- peer/channel/deliverclient.go,deliverClientIntf介面定義及實現,以及DeliverClient工具函式。
- protos/orderer/ab.pb.go,AtomicBroadcast_DeliverClient介面定義和實現。
2、deliverClientIntf介面定義及實現
2.1、DeliverClient工具函式
//構造deliverClient
func newDeliverClient(conn *grpc.ClientConn, client ab.AtomicBroadcast_DeliverClient, chainID string) *deliverClient
//程式碼在peer/channel/deliverclient.go
2.2、deliverClientIntf介面定義及實現
type deliverClientIntf interface { getSpecifiedBlock(num uint64) (*common.Block, error) getOldestBlock() (*common.Block, error) getNewestBlock() (*common.Block, error) Close() error } type deliverClient struct { conn *grpc.ClientConn client ab.AtomicBroadcast_DeliverClient chainID string } //構造查詢Envelope func seekHelper(chainID string, position *ab.SeekPosition) *common.Envelope //r.client.Send(seekHelper(r.chainID, &ab.SeekPosition{Type: &ab.SeekPosition_Specified{Specified: &ab.SeekSpecified{Number: blockNumber}}})) func (r *deliverClient) seekSpecified(blockNumber uint64) error //r.client.Send(seekHelper(r.chainID, &ab.SeekPosition{Type: &ab.SeekPosition_Oldest{Oldest: &ab.SeekOldest{}}})) func (r *deliverClient) seekOldest() error //return r.client.Send(seekHelper(r.chainID, &ab.SeekPosition{Type: &ab.SeekPosition_Newest{Newest: &ab.SeekNewest{}}})) func (r *deliverClient) seekNewest() error //r.client.Recv()讀取塊 func (r *deliverClient) readBlock() (*common.Block, error) //r.seekSpecified(num)和r.readBlock() func (r *deliverClient) getSpecifiedBlock(num uint64) (*common.Block, error) //r.seekOldest()和r.readBlock() func (r *deliverClient) getOldestBlock() (*common.Block, error) //r.seekNewest()和r.readBlock() func (r *deliverClient) getNewestBlock() (*common.Block, error) //r.conn.Close() func (r *deliverClient) Close() error //cf.DeliverClient.getSpecifiedBlock(0)獲取創世區塊 func getGenesisBlock(cf *ChannelCmdFactory) (*common.Block, error) //程式碼在peer/channel/deliverclient.go
func seekHelper(chainID string, position ab.SeekPosition) common.Envelope程式碼如下:
func seekHelper(chainID string, position *ab.SeekPosition) *common.Envelope {
seekInfo := &ab.SeekInfo{
Start: position,
Stop: position,
Behavior: ab.SeekInfo_BLOCK_UNTIL_READY,
}
msgVersion := int32(0)
epoch := uint64(0)
env, err := utils.CreateSignedEnvelope(common.HeaderType_CONFIG_UPDATE, chainID, localmsp.NewSigner(), seekInfo, msgVersion, epoch)
return env
}
//程式碼在peer/channel/deliverclient.go
感謝關注兄弟連區塊鏈教程分享!