Network configuration

The first step in writing middleware is collecting all the configuration information necessary to identify and connect to the various elements of the network we created and launched in the previous section. It is useful, especially when writing code in JavaScript, to express such configurations in JSON format. In our sample code, the config.json file serves this purpose. This file contains the description of a network, whose attributes are contained in the trade-network object. Each property of this object describes the configuration of each unique organization that is part of the network, except for a property called the orderer, which simply refers to the orderer node. (Note: this is sufficient for our simple network containing just one orderer node.) Let's examine what must be specified in each organization's description by taking the Exporterorg property as an example:

"exporterorg": {
"name": "peerExporterOrg",
"mspid": "ExporterOrgMSP",
"ca": {
"url": "https://localhost:7054",
"name": "ca-exporterorg"
},
"peer1": {
"requests": "grpcs://localhost:7051",
"events": "grpcs://localhost:7053",
"server-hostname": "peer0.exporterorg.trade.com",
"tls_cacerts": "../network/crypto-config/peerOrganizations/exporterorg.trade.com/peers/peer0.exporterorg.trade.com/msp/tlscacerts/tlsca.exporterorg.trade.com-cert.pem"
}
},

The mspid value must match the one specified in network/configtx.yaml for our middleware to be compatible with the channel artefacts and cryptographic material created for the network. The name and port information for the CA must match what was specified in network/docker-compose-e2e.yaml. Since we have just one peer in each organization, we name it peer for convenience, though one can easily define a different schema for a multi-peer organization setup. Note that the peer exports services for peer requests as well as for event subscriptions, and the ports match those exposed in network/base/docker-compose-base.yaml. The server-hostname must also match that specified in both configtx.yaml and the docker-compose configurations. As our network elements connect using TLS, the path to the peer's TLS certificate must also be specified here.

Lastly, if you compare the preceding schema snippet with the configurations of the other organizations, you will notice that the ports listed exactly matches those exposed in the docker-compose configurations. For example, the peers in the exporter, importer, carrier, and regulator organizations listen for requests on ports 7051, 8051, 9051, and 10051, respectively. The hostnames in the URLs simply refer to localhost, as that is where all our network element's containers are running.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset