fabric源码解读:Peer节点状态

fabric源码解读:Peer节点状态

fabric源码解读:Peer节点状态_第1张图片

源码 fabric/peer/status.go

func statusCmd() *cobra.Command {
	return nodeStatusCmd
}
// peer nodestatus子命令
var nodeStatusCmd = &cobra.Command{
	Use:   "status",
	Short: "Returns status of the node.",
	Long:  `Returns the status of the running node.`,
	RunE: func(cmd *cobra.Command, args []string) error {
		return status()
	},
}

// 节点状态函数
func status() (err error) {
	// 获取admin客户端,根据配置peer.address
	adminClient, err := common.GetAdminClient()
	if err != nil {
		logger.Warningf("%s", err)
		fmt.Println(&pb.ServerStatus{Status: pb.ServerStatus_UNKNOWN})
		return err
	}
   // 获取状态
	status, err := adminClient.GetStatus(context.Background(), &empty.Empty{})
	if err != nil {
		logger.Infof("Error trying to get status from local peer: %s", err)
		err = fmt.Errorf("Error trying to connect to local peer: %s", err)
		fmt.Println(&pb.ServerStatus{Status: pb.ServerStatus_UNKNOWN})
		return err
	}
    // 打印状态
	fmt.Println(status)
	return nil
}

其中 status定义如下

type ServerStatus_StatusCode int32

const (
   ServerStatus_UNDEFINED ServerStatus_StatusCode = 0
   ServerStatus_STARTED   ServerStatus_StatusCode = 1
   ServerStatus_STOPPED   ServerStatus_StatusCode = 2
   ServerStatus_PAUSED    ServerStatus_StatusCode = 3
   ServerStatus_ERROR     ServerStatus_StatusCode = 4
   ServerStatus_UNKNOWN   ServerStatus_StatusCode = 5
)

var ServerStatus_StatusCode_name = map[int32]string{
   0: "UNDEFINED",
   1: "STARTED",
   2: "STOPPED",
   3: "PAUSED",
   4: "ERROR",
   5: "UNKNOWN",
}

你可能感兴趣的:(区块链)