客户端(Hyperledger ComposerNode SDK)连接Fabric网络的配置文件解析
Posted Fabric技术分享
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了客户端(Hyperledger ComposerNode SDK)连接Fabric网络的配置文件解析相关的知识,希望对你有一定的参考价值。
前言
在本文中,我们将为客户端((例如Hyperledger Composer、Node SDK)创建一个连接配置文件,用于连接Hyperledger Fabric网络。该配置文件指定了连接Hyperledger Fabric网络所需的全部信息,例如所有Hyperledger Fabric网络组件的主机名和端口。
当时环境
Hyperledger Composer 0.19.7
Hyperledger Fabrc 1.1
配置文件解析
1、name、x-type、version
文件头信息
{
// 配置文件的名字,后续会用到
"name": "byfn-network",
// 区块链网络类型 (这里对应 Hyperledger Fabric v1.1)
"x-type": "hlfv1",
// 配置文件 格式化版本
"version": "1.0.0",
2、channels
这部分描述已经存在的channel信息,每个channle
包含哪些orderer
、peer
。其中peer
部分又定义了其角色属性:
属性名 | 类型 | 描述 |
---|---|---|
endorsingPeer | boolean | endorsingPeer 可选的。这个peer节点可能会被发送交易提案进行背书。前提是该节点必须安装链码。该应用程序还可以使用此属性来决定发送链代码安装时请求的对象。默认值:true |
chaincodeQuery | boolean | chaincodeQuery 可选的。这个peer节点可能会被发送交易提议只进行查询。前提是该节点必须安装链码。该应用程序还可以使用此属性来决定发送链代码安装时请求的对象。默认值:true |
ledgerQuery | boolean | ledgerQuery 可选的。可以向该peer发送不需要链接码的查询的提议,如queryBlock(),queryTransaction()等。默认值:true |
eventSource | boolean | eventSource 可选的。这个是事件监听器注册的目标,所有的peer都可以生产事件,但通常只需要连接一个。默认值:true |
"channels": {
// 链接哪个channel,channel中又包含哪些信息
"mychannel": {
// 包含的orderer
"orderers": [
"orderer.example.com"
],
// 包含的节点信息(可以为每个节点分配不同的功能角色)
"peers": {
"peer0.org1.example.com": {
// 背书节点
"endorsingPeer": true,
// 链码查询节点
"chaincodeQuery": true,
// 事件源节点
"eventSource": true
},
"peer1.org1.example.com": {
"endorsingPeer": true,
"chaincodeQuery": true,
"eventSource": true
},
"peer0.org2.example.com": {
"endorsingPeer": true,
"chaincodeQuery": true,
"eventSource": true
},
"peer1.org2.example.com": {
"endorsingPeer": true,
"chaincodeQuery": true,
"eventSource": true
}
}
}
},
3、organizations
这里我们描述的是peer的所有者(org),他们的证书机构是谁,使用哪个MSP ID。
// Fabric中的组织信息
"organizations": {
// 5.1 org1组织
"Org1": {
// 使用的msp
"mspid": "Org1MSP",
// 包含哪几个节点
"peers": [
"peer0.org1.example.com",
"peer1.org1.example.com"
],
// 使用哪个证书机构
"certificateAuthorities": [
"ca.org1.example.com"
]
},
"Org2": {
"mspid": "Org2MSP",
"peers": [
"peer0.org2.example.com",
"peer1.org2.example.com"
],
"certificateAuthorities": [
"ca.org2.example.com"
]
}
},
4、orderers
我们必须指定我们要连接的Hyperledger Fabric中所有orderder节点的主机名和端口。orderers对象可以包含多个orderder节点。如果您有多个orderder节点,则应将其全部添加进来。
// Fabric中的orderer节点信息
"orderers": {
"orderer.example.com": {
"url": "grpcs://localhost:7050",
"grpcOptions": {
"ssl-target-name-override": "orderer.example.com"
},
"tlsCACerts": {
"pem": "ORDERER_CA_CERT"
}
}
},
5、peers
我们必须指定Hyperledger Fabric网络中所有peer节点的主机名和端口,他们可能会被其他地方引用,如channle
,organizations
等部分
// Fabric中所有peer节点详细信息
"peers": {
//7.1 peer0节点
"peer0.org1.example.com": {
// 节点地址
"url": "grpcs://localhost:7051",
// 监听节点事件地址
"eventUrl": "grpcs://localhost:7053",
// 使用grpc交互时本节点的host name
"grpcOptions": {
"ssl-target-name-override": "peer0.org1.example.com"
},
// tls为true时 需要用到这个证书
"tlsCACerts": {
"pem": "ORG1_CA_CERT"
}
},
"peer1.org1.example.com": {
"url": "grpcs://localhost:8051",
"eventUrl": "grpcs://localhost:8053",
"grpcOptions": {
"ssl-target-name-override": "peer1.org1.example.com"
},
"tlsCACerts": {
"pem": "ORG1_CA_CERT"
}
},
"peer0.org2.example.com": {
"url": "grpcs://localhost:9051",
"eventUrl": "grpcs://localhost:9053",
"grpcOptions": {
"ssl-target-name-override": "peer0.org2.example.com"
},
"tlsCACerts": {
"pem": "ORG2_CA_CERT"
}
},
"peer1.org2.example.com": {
"url": "grpcs://localhost:10051",
"eventUrl": "grpcs://localhost:10053",
"grpcOptions": {
"ssl-target-name-override": "peer1.org2.example.com"
},
"tlsCACerts": {
"pem": "ORG2_CA_CERT"
}
}
},
6、certificateAuthorities
我们必须在Hyperledger Fabric网络中指定证书颁发机构(CA)的主机名和端口,以便用于注册现有用户和注册新用户。
// Fabric中证书机构信息
"certificateAuthorities": {
// 组织1的证书机构( 节点地址 节点名称 )
"ca.org1.example.com": {
"url": "https://localhost:7054",
"caName": "ca-org1",
"httpOptions": {
"verify": false
}
},
"ca.org2.example.com": {
"url": "https://localhost:8054",
"caName": "ca-org2",
"httpOptions": {
"verify": false
}
}
}
7、client
客户端部分是必需要定义的。客户端应用程序(例如Hyperledger Composer、Node SDK)代表谁来和Fabric来交互,同时你可以定义超时选项。
// 定义客户端(代表哪个组织和Fabric来交互)
"client": {
// 这里client代表组织1和链交互
"organization": "Org1",
// 定义连接超时时间(如果这里不定义,默认超时时间为45秒)
"connection": {
"timeout": {
"peer": {
"endorser": "300",
"eventHub": "300",
"eventReg": "300"
},
"orderer": "300"
}
}
}
附上完整的配置文件
具体业务具体对待,下面只是示例文件
{
"name": "byfn-network",
"x-type": "hlfv1",
"version": "1.0.0",
"client": {
"organization": "Org1",
"connection": {
"timeout": {
"peer": {
"endorser": "300",
"eventHub": "300",
"eventReg": "300"
},
"orderer": "300"
}
}
},
"channels": {
"mychannel": {
"orderers": [
"orderer.example.com"
],
"peers": {
"peer0.org1.example.com": {
"endorsingPeer": true,
"chaincodeQuery": true,
"eventSource": true
},
"peer1.org1.example.com": {
"endorsingPeer": true,
"chaincodeQuery": true,
"eventSource": true
},
"peer0.org2.example.com": {
"endorsingPeer": true,
"chaincodeQuery": true,
"eventSource": true
},
"peer1.org2.example.com": {
"endorsingPeer": true,
"chaincodeQuery": true,
"eventSource": true
}
}
}
},
"organizations": {
"Org1": {
"mspid": "Org1MSP",
"peers": [
"peer0.org1.example.com",
"peer1.org1.example.com"
],
"certificateAuthorities": [
"ca.org1.example.com"
]
},
"Org2": {
"mspid": "Org2MSP",
"peers": [
"peer0.org2.example.com",
"peer1.org2.example.com"
],
"certificateAuthorities": [
"ca.org2.example.com"
]
}
},
"orderers": {
"orderer.example.com": {
"url": "grpcs://localhost:7050",
"grpcOptions": {
"ssl-target-name-override": "orderer.example.com"
},
"tlsCACerts": {
"pem": "INSERT_ORDERER_CA_CERT"
}
}
},
"peers": {
"peer0.org1.example.com": {
"url": "grpcs://localhost:7051",
"eventUrl": "grpcs://localhost:7053",
"grpcOptions": {
"ssl-target-name-override": "peer0.org1.example.com"
},
"tlsCACerts": {
"pem": "INSERT_ORG1_CA_CERT"
}
},
"peer1.org1.example.com": {
"url": "grpcs://localhost:8051",
"eventUrl": "grpcs://localhost:8053",
"grpcOptions": {
"ssl-target-name-override": "peer1.org1.example.com"
},
"tlsCACerts": {
"pem": "INSERT_ORG1_CA_CERT"
}
},
"peer0.org2.example.com": {
"url": "grpcs://localhost:9051",
"eventUrl": "grpcs://localhost:9053",
"grpcOptions": {
"ssl-target-name-override": "peer0.org2.example.com"
},
"tlsCACerts": {
"pem": "INSERT_ORG2_CA_CERT"
}
},
"peer1.org2.example.com": {
"url": "grpcs://localhost:10051",
"eventUrl": "grpcs://localhost:10053",
"grpcOptions": {
"ssl-target-name-override": "peer1.org2.example.com"
},
"tlsCACerts": {
"pem": "INSERT_ORG2_CA_CERT"
}
}
},
"certificateAuthorities": {
"ca.org1.example.com": {
"url": "https://localhost:7054",
"caName": "ca-org1",
"httpOptions": {
"verify": false
}
},
"ca.org2.example.com": {
"url": "https://localhost:8054",
"caName": "ca-org2",
"httpOptions": {
"verify": false
}
}
}
}
以上是关于客户端(Hyperledger ComposerNode SDK)连接Fabric网络的配置文件解析的主要内容,如果未能解决你的问题,请参考以下文章