當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ReceivedMessage.Respond方法代碼示例

本文整理匯總了Golang中github.com/hyperledger/fabric/gossip/comm.ReceivedMessage.Respond方法的典型用法代碼示例。如果您正苦於以下問題:Golang ReceivedMessage.Respond方法的具體用法?Golang ReceivedMessage.Respond怎麽用?Golang ReceivedMessage.Respond使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/hyperledger/fabric/gossip/comm.ReceivedMessage的用法示例。


在下文中一共展示了ReceivedMessage.Respond方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: handleStateRequest

func (s *GossipStateProviderImpl) handleStateRequest(msg comm.ReceivedMessage) {
	request := msg.GetGossipMessage().GetStateRequest()
	response := &proto.RemoteStateResponse{Payloads: make([]*proto.Payload, 0)}
	for _, seqNum := range request.SeqNums {
		s.logger.Debug("Reading block ", seqNum, " from the committer service")
		blocks := s.committer.GetBlocks([]uint64{seqNum})

		if blocks == nil || len(blocks) < 1 {
			s.logger.Errorf("Wasn't able to read block with sequence number %d from ledger, skipping....", seqNum)
			continue
		}

		blockBytes, err := pb.Marshal(blocks[0])
		if err != nil {
			s.logger.Errorf("Could not marshal block: %s", err)
		}

		if err != nil {
			s.logger.Errorf("Could not calculate hash of block: %s", err)
		}

		response.Payloads = append(response.Payloads, &proto.Payload{
			SeqNum: seqNum,
			Data:   blockBytes,
			// TODO: Check hash generation for given block from the ledger
			Hash: "",
		})
	}
	// Sending back response with missing blocks
	msg.Respond(&proto.GossipMessage{
		Content: &proto.GossipMessage_StateResponse{response},
	})
}
開發者ID:hyperledger,項目名稱:fabric,代碼行數:33,代碼來源:state.go


注:本文中的github.com/hyperledger/fabric/gossip/comm.ReceivedMessage.Respond方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。